/*
 * Copyright (c) 2023 OpenLuat & AirM2M
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


//fskv空间可以用程序区内空余空间，也可以使用fdb的空间（不能和老的kv兼容了）

#if  0

#include "common_api.h"

#include "luat_rtos.h"
#include "luat_debug.h"
#include "luat_mem.h"
#include "luat_fskv.h"

#include "sr_shell.h"


static int _HzFskvTest(int argc, char *argv[])
{
	int ret = 0;
	char value[128] = {0};
	char value2[128] = {0};

	ret = luat_fskv_init();


	LUAT_DEBUG_PRINT("luat_kv demo,ret=%d",ret);

	// 设置一个key-value
	// key 最大长度是   64
	// value 最大长度是 4096

	// 设置方式, \0结尾的数据,直接来
	ret = luat_fskv_set("my123", "123", strlen("123"));
	LUAT_DEBUG_PRINT("kv_set my123 ret %d", ret);
	memset(value, 0x21, 32);
	ret = luat_fskv_set("my456", value, 32);
	LUAT_DEBUG_PRINT("kv_set my456 ret %d", ret);

	ret = luat_fskv_get("my123", value, 32);
	LUAT_DEBUG_PRINT("kv_get ret %d", ret);
	if (ret > 0) {
		value[ret] = 0x00;
		LUAT_DEBUG_PRINT("kv read value %s", value);
		// 写进入的值应该等于写出的值
		if (memcmp("123", value, strlen("123"))) {
			LUAT_DEBUG_PRINT("kv value NOT match");
		}
	}
	else {
		// 前面的逻辑写入字符串"123", 获取时肯定大于0,除非底层出错了
		LUAT_DEBUG_PRINT("kv read failed");
	}

	for(ret = 0; ret < 128; ret++)
	{
		value2[ret] = ret;
	}
	ret = luat_fskv_set("hextest", value2, 128);
	ret = luat_fskv_get("hextest", value, 128);

	if (memcmp(value, value2, 128))
	{
		LUAT_DEBUG_PRINT("测试失败");
	}

	// 清空整个kv数据, 慎用
	// 这里只是演示有这个API, 并非使用后要调用该API
//	luat_fskv_clear();
	
}
SR_SHELL_CMD_EXPORT(hzFskv, _HzFskvTest);

#endif


