|
|
@@ -5,6 +5,8 @@
|
|
|
#include "lock.h"
|
|
|
#include "paras.h"
|
|
|
#include "cascade.h"
|
|
|
+#include "dictionary.h"
|
|
|
+#include "iniparser.h"
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
@@ -25,37 +27,34 @@ enum {
|
|
|
extern GlobalDeviceInfo DFLT_PARAS;
|
|
|
|
|
|
typedef struct {
|
|
|
- int flag;
|
|
|
+ dictionary *dic;
|
|
|
|
|
|
}paras_handle_t;
|
|
|
static paras_handle_t paraHandle={0};
|
|
|
|
|
|
|
|
|
-
|
|
|
+#if 0
|
|
|
static int do_check(void *para)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
#if 1
|
|
|
|
|
|
-#include "dictionary.h"
|
|
|
-#include "iniparser.h"
|
|
|
-
|
|
|
typedef struct {
|
|
|
- int product_id ;//产品ID
|
|
|
- char product_number[16] ;//产品编号
|
|
|
- char product_name[32] ;//产品名称
|
|
|
- char product_status[32] ;//产品状态
|
|
|
- unsigned char product_type ;//产品类型
|
|
|
- unsigned char product_pwr_type ;//电源类型
|
|
|
- char product_version[8] ;//软件版本
|
|
|
- unsigned char product_language ;//多国语言
|
|
|
- unsigned char product_count ;//级联设备数
|
|
|
- unsigned short product_samp_time ;//采集周期 单位ms
|
|
|
- unsigned short product_save_time ;//采集周期 单位ms
|
|
|
+ uint32_t id ;//产品ID
|
|
|
+ uint8_t number[16] ;//产品编号
|
|
|
+ uint8_t name[32] ;//产品名称
|
|
|
+ uint8_t status[32] ;//产品状态
|
|
|
+ uint8_t type ;//产品类型
|
|
|
+ uint8_t pwr_type ;//电源类型
|
|
|
+ uint8_t version[8] ;//软件版本
|
|
|
+ uint8_t language ;//多国语言
|
|
|
+ uint8_t count ;//级联设备数
|
|
|
+ uint8_t samp_time ;//采集周期 单位ms
|
|
|
+ uint8_t save_time ;//采集周期 单位ms
|
|
|
}prod_info_t;
|
|
|
|
|
|
-static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *info)
|
|
|
+static int ini_rw_dev(dictionary *dic, int rw, GlobalDeviceInfo *info)
|
|
|
{
|
|
|
int r=-1,ok=1;
|
|
|
char *p=NULL;
|
|
|
@@ -244,7 +243,7 @@ static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *info)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *info)
|
|
|
+static int ini_rw_modbus(dictionary *dic, int rw, GlobalDeviceInfo *info)
|
|
|
{
|
|
|
int r=-1;
|
|
|
char temp[100];
|
|
|
@@ -318,25 +317,18 @@ static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *info)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int ini_rw_network(int rw, dictionary *dic, GlobalDeviceInfo *info)
|
|
|
-{
|
|
|
- int r=-1;
|
|
|
- char *p=NULL;
|
|
|
- char temp[100];
|
|
|
- char *token=NULL;
|
|
|
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int ini_reset(void)
|
|
|
+static int ini_reset(paras_handle_t *h)
|
|
|
{
|
|
|
int r;
|
|
|
dictionary *dic=NULL;
|
|
|
char *ininame=INI_FILE_NAME;
|
|
|
- char temp[200];
|
|
|
FILE *fp=NULL;
|
|
|
+
|
|
|
+
|
|
|
GlobalDeviceInfo *info=&DFLT_PARAS;
|
|
|
|
|
|
- sys_get_path(temp, ininame);
|
|
|
+
|
|
|
fp = fopen(temp, "w");
|
|
|
if (fp==NULL) {
|
|
|
LOGE("ini_reset, create %s failed\n", ininame);
|
|
|
@@ -355,46 +347,47 @@ static int ini_reset(void)
|
|
|
fprintf(fp, "savetime = %d\n", info->product_save_time);
|
|
|
fclose(fp);
|
|
|
|
|
|
+ if(h->dic) {
|
|
|
+ iniparser_freedict(h->dic);
|
|
|
+ }
|
|
|
+ //h->dic = ini_load(h, info);
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
-static int ini_load(GlobalDeviceInfo *info)
|
|
|
+static dictionary* ini_load(char *path, GlobalDeviceInfo *info)
|
|
|
{
|
|
|
int r=-1;
|
|
|
- char *p=NULL;
|
|
|
- char *ininame=INI_FILE_NAME;
|
|
|
+ char temp[200];
|
|
|
|
|
|
- dictionary *dic=iniparser_load(ininame);
|
|
|
+ dictionary *dic=iniparser_load(path);
|
|
|
if(dic == NULL){
|
|
|
- ini_reset();
|
|
|
- dic = iniparser_load(ininame);
|
|
|
+
|
|
|
+ sys_get_path(temp, ininame);
|
|
|
+
|
|
|
+ ini_reset(h);
|
|
|
+ dic = iniparser_load(path);
|
|
|
if(dic == NULL) {
|
|
|
LOGE("___ iniparser_load failed\n");
|
|
|
- return -1;
|
|
|
+ //return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- r = ini_rw_prod(INI_READ, dic, info);
|
|
|
+ r = ini_rw_dev(dic, INI_READ, info);
|
|
|
if(r) {
|
|
|
- LOGE("___ini_r_prod failed\n");
|
|
|
+ LOGE("___ini_r_dev failed\n");
|
|
|
+ return NULL;
|
|
|
}
|
|
|
- iniparser_freedict(dic);
|
|
|
|
|
|
- return r;
|
|
|
+ return dic;
|
|
|
}
|
|
|
-static int ini_save(GlobalDeviceInfo *info)
|
|
|
+static int ini_save(paras_handle_t *h, GlobalDeviceInfo *info)
|
|
|
{
|
|
|
int r=-1;
|
|
|
char *p=NULL;
|
|
|
char temp[200];
|
|
|
char *ininame=INI_FILE_NAME;
|
|
|
|
|
|
- dictionary *dic=iniparser_load(ininame);
|
|
|
- if(dic == NULL){
|
|
|
- LOGE("___ %s load failed\n", ininame);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- r = ini_rw_prod(INI_WRITE, dic, info);
|
|
|
+ //r = ini_rw_dev(h, INI_WRITE, info);
|
|
|
if(r) {
|
|
|
LOGE("___ini_r_prod failed\n");
|
|
|
goto quit;
|
|
|
@@ -406,11 +399,10 @@ static int ini_save(GlobalDeviceInfo *info)
|
|
|
LOGE("___%s open failed\n", ininame);
|
|
|
goto quit;
|
|
|
}
|
|
|
- iniparser_dump_ini(dic, fp);
|
|
|
- fclose(fp);
|
|
|
+ iniparser_dump_ini(h->dic, fp);
|
|
|
+ fclose(fp); r = 0;
|
|
|
|
|
|
quit:
|
|
|
- iniparser_freedict(dic);
|
|
|
return r;
|
|
|
}
|
|
|
#endif
|
|
|
@@ -424,19 +416,21 @@ static GlobalDeviceInfo *get_dm(void)
|
|
|
|
|
|
int paras_init(void)
|
|
|
{
|
|
|
+ int r=0;
|
|
|
GlobalDeviceInfo *info=get_dm();
|
|
|
paras_handle_t *h=¶Handle;
|
|
|
|
|
|
lock_s_hold(LOCK_ID_PARAS);
|
|
|
- ini_load(info);
|
|
|
+ h->dic = ini_load(INI_FILE_NAME, info);
|
|
|
lock_s_release(LOCK_ID_PARAS);
|
|
|
|
|
|
- return 0;
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
|
|
|
int paras_deinit(void)
|
|
|
{
|
|
|
+ int r;
|
|
|
paras_handle_t *h=¶Handle;
|
|
|
|
|
|
lock_s_hold(LOCK_ID_PARAS);
|
|
|
@@ -447,14 +441,14 @@ int paras_deinit(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
-int paras_load(void)
|
|
|
+int paras_load(char *path)
|
|
|
{
|
|
|
int r=0;
|
|
|
GlobalDeviceInfo *info=get_dm();
|
|
|
paras_handle_t *h=¶Handle;
|
|
|
|
|
|
lock_s_hold(LOCK_ID_PARAS);
|
|
|
- r = ini_load(info);
|
|
|
+ //r = ini_load(path, info);
|
|
|
lock_s_release(LOCK_ID_PARAS);
|
|
|
|
|
|
return r;
|
|
|
@@ -468,8 +462,7 @@ int paras_reset(void)
|
|
|
paras_handle_t *h=¶Handle;
|
|
|
|
|
|
lock_s_hold(LOCK_ID_PARAS);
|
|
|
- ini_reset();
|
|
|
- r = ini_load(info);
|
|
|
+ //ini_reset(h);
|
|
|
lock_s_release(LOCK_ID_PARAS);
|
|
|
|
|
|
return r;
|
|
|
@@ -483,37 +476,14 @@ int paras_save(void)
|
|
|
paras_handle_t *h=¶Handle;
|
|
|
|
|
|
lock_s_hold(LOCK_ID_PARAS);
|
|
|
- //r = ini_save(info);
|
|
|
+ r = ini_save(h, info);
|
|
|
lock_s_release(LOCK_ID_PARAS);
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
|
|
|
-int paras_read(int type, void *data)
|
|
|
-{
|
|
|
- int r=0;
|
|
|
- paras_handle_t *h=¶Handle;
|
|
|
-
|
|
|
- lock_s_hold(LOCK_ID_PARAS);
|
|
|
-
|
|
|
- lock_s_release(LOCK_ID_PARAS);
|
|
|
-
|
|
|
- return r;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-int paras_write(int type, void *data)
|
|
|
-{
|
|
|
- int r=0;
|
|
|
- paras_handle_t *h=¶Handle;
|
|
|
-
|
|
|
- lock_s_hold(LOCK_ID_PARAS);
|
|
|
-
|
|
|
- lock_s_release(LOCK_ID_PARAS);
|
|
|
-
|
|
|
- return r;
|
|
|
-}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|