#include "sr_sunrise.h"

#ifdef SR_USE_KV
//cmd: flash_exmp <offset> 
static int _DbExample(int argc, char *argv[])
{
	int ret = -1,i;	
	static uint8_t deviceKey[16]={0xB8,0xC4,0xF7,0x46,0x5A,0xD2,0x6C,0xE3,0xBC,0x77,0xE8,0x98,0xD9,0x6E,0xA7,0x5C};
	char deviceId[10] = "DEV0001";
	uint8_t rBuf[32]={0};
	
	//初始化
	ret = SR_FdbKvInit();	
	SR_LOG(INFO,"FdbKvInit,ret=%d",ret);

	//读取KV
#if  0
	ret = SR_FdbKvGetBlob("deviceKey",rBuf,sizeof(rBuf)); 
	SR_LOG(INFO,"key1 get,ret=%d :",ret);
	if(ret>0)
	{
		for(i=0;i<ret;i++) SR_LOG(INFO,"0x%02X ",rBuf[i]);
		SR_LOG(INFO,"\r\n");
	}
#endif
	
	//设置KV
	deviceKey[0] += 1;
	ret = SR_FdbKvSetBlob("deviceKey",deviceKey,sizeof(deviceKey));	
	SR_LOG(INFO,"key1 set,ret=%d",ret);
	
	ret = SR_FdbKvSetBlob("deviceId",deviceId,strlen(deviceId));		 	
	SR_LOG(INFO,"key2 set,ret=%d",ret);
	
	//读取KV
	ret = SR_FdbKvGetBlob("deviceKey",rBuf,sizeof(rBuf)); 
	SR_LOG(INFO,"key1 get,ret=%d :",ret);
	if(ret>0)
	{
		for(i=0;i<ret;i++) SR_LOG(INFO,"0x%02X ",rBuf[i]);
		SR_LOG(INFO,"\r\n");
	}

	ret = SR_FdbKvGetBlob("deviceId",rBuf,sizeof(rBuf)); 
	SR_LOG(INFO,"key2 get,ret=%d :",ret);
	if(ret>0)
	{
		for(i=0;i<ret;i++) SR_LOG(INFO,"%c ",rBuf[i]);
		SR_LOG(INFO,"\r\n");
	}

	//删除KV
	SR_FdbKvDeleteBlob("deviceId");

}
SR_SHELL_CMD_EXPORT(db_exmp, _DbExample);

#endif

