📄 inioper.c
字号:
//__write(ff_handle,tmp_buf1, 12);
}*/
//site_prop
ret = ConfigGetKey(cfghandle, "SITE_INFO", "SITE_TYPE", buf);
if (ret == CFG_OK)
{
//系统编号
g_site_conf.site_type = atoi(buf);
}
/*ret = ConfigGetKey(cfghandle, "SITE_INFO", "SITE_NAME", buf);
if (ret == CFG_OK)
{
//监测点名称
strcpy(g_site_conf.site_name, buf);
}*/
ret = ConfigGetKey(cfghandle, "SITE_INFO", "AREA_ID", buf);
if (ret == CFG_OK)
{
//AREA_ID
g_site_conf.area_id = atoi(buf);
}
ret = ConfigGetKey(cfghandle, "SITE_INFO", "CORP_ID", buf);
if (ret == CFG_OK)
{
//企业ID
g_site_conf.corp_id = atoi(buf);
}
ret = ConfigGetKey(cfghandle, "SITE_INFO", "SITE_ID", buf);
if (ret == CFG_OK)
{
//站点ID
g_site_conf.site_id = atoi(buf);
}
ret = ConfigGetKey(cfghandle, "SITE_INFO", "TIMEOUT", buf);
if (ret == CFG_OK)
{
//超时时间
g_site_conf.site_timeout = atoi(buf);
}
ret = ConfigGetKey(cfghandle, "SITE_INFO", "TIMEOUT_RECONNECT", buf);
if (ret == CFG_OK)
{
//超时次数
g_site_conf.site_timeout_reconnect = atoi(buf);
}
//COM PORT属性
for (i = 0; i < 5; i++)
{
strncpy(tmpbuf, "COM", 3);
tmpbuf[3] = (unsigned char)(i + 1 + 0x30);
tmpbuf[4] = '\0';
strncat(tmpbuf, "_INFO", 5);
ret = ConfigGetKey(cfghandle, "COM_PORT_PROP", tmpbuf, buf);
if (ret == CFG_OK)
{
//串口设置
ret = getcsvlen(buf);
g_site_conf_extend.com_port[i].port_num = i;//端口号
g_site_conf_extend.com_port[i].flgUsed = TRUE;
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 0));
g_site_conf_extend.com_port[i].baud = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 1));
g_site_conf_extend.com_port[i].flgChk = atoi(tmpbuf);//奇偶校验 0-无,1-奇,2-偶
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 2));
g_site_conf_extend.com_port[i].databits = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 3));
g_site_conf_extend.com_port[i].stopbits = atoi(tmpbuf);
g_site_conf_extend.com_port[i].timeout_ticks = 0;
g_site_conf_extend.com_port[i].timeout_calflg = FALSE;//是否开始记数
}
}
//流量设置
ret = ConfigGetKey(cfghandle, "FLUX_PARAM", "FLUX_SET", buf);
if (ret == CFG_OK)
{
ret = getcsvlen(buf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 0));
g_site_conf_extend.flux_param.FLUX_SET = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 1));
g_site_conf_extend.flux_param.GUTTER_TYPE = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 2));
g_site_conf_extend.flux_param.GUTTER_NO = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 3));
g_site_conf_extend.flux_param.GUTTER_HIGH = atof(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 4));
g_site_conf_extend.flux_param.sleeptime = atoi(tmpbuf);
}
//[DEV_PROP]
ret = ConfigGetKey(cfghandle, "DEV_PROP", "DEV_NUM", buf);
if (ret == CFG_OK)
{
//超时时间
g_site_conf_extend.devinfonum = atoi(buf);
}
for (i = 0; i < g_site_conf_extend.devinfonum; i++)
{
strncpy(tmpbuf, "DEV", 3);
tmpbuf[3] = (unsigned char)(i + 1 + 0x30 );
tmpbuf[4] = '\0';
strncat(tmpbuf, "_INFO", 5);
ret = ConfigGetKey(cfghandle, "DEV_PROP", tmpbuf, buf);
if (ret == CFG_OK)
{
//设备信息设置
ret = getcsvlen(buf);
g_site_conf_extend.devinfo[i].flgUsed = TRUE;
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 0));
g_site_conf_extend.devinfo[i].dev_id = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 1));
g_site_conf_extend.devinfo[i].flgCanControl = atoi(tmpbuf);//是否受控
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 2));
strncpy(g_site_conf_extend.devinfo[i].support_p_id, tmpbuf, 3);//支持的污染物
if (strcmp(g_site_conf_extend.devinfo[i].support_p_id, P_CODE_INSTANT) == 0)
g_site_conf_extend.devsnap.bHasFlow = TRUE;
if (strcmp(g_site_conf_extend.devinfo[i].support_p_id, P_CODE_PH) == 0)
g_site_conf_extend.devsnap.bHasPH = TRUE;
if (strcmp(g_site_conf_extend.devinfo[i].support_p_id, P_CODE_COD) == 0)
g_site_conf_extend.devsnap.bHasCOD = TRUE;
if (strcmp(g_site_conf_extend.devinfo[i].support_p_id, P_CODE_MOTOR) == 0)
g_site_conf_extend.devsnap.bHasMotor = TRUE;
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 3));
g_site_conf_extend.devinfo[i].interfacetype = atoi(tmpbuf);//接口类型0-AD,1-COM,2-DI,3-DO
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 4));
g_site_conf_extend.devinfo[i].portnum = (BYTE)atoi(tmpbuf);//端口号
}
}
//Pollutant map
ret = ConfigGetKey(cfghandle, "POLLUTANT_MAP", "SUPPORT_NUM", buf);
if (ret == CFG_OK)
{
//支持污染物数量
g_site_conf_extend.pollutantnum = atoi(buf);
}
for (i = 0; i < g_site_conf_extend.pollutantnum; i++)
{
strcpy(tmpbuf, "POLLUTANT");
tmpbuf[9] = (unsigned char)(i + 1 + 0x30);
tmpbuf[10] = '\0';
ret = ConfigGetKey(cfghandle, "POLLUTANT_MAP", tmpbuf, buf);
if (ret == CFG_OK)
{
ret = getcsvlen(buf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 0));
strncpy(g_site_conf_extend.pollutant[i].p_id, tmpbuf, 3);
g_site_conf_extend.pollutant[i].flgUsed = TRUE;
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 1));
g_site_conf_extend.pollutant[i].unit = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 2));
g_site_conf_extend.pollutant[i].p_name = atoi(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 3));
g_site_conf_extend.pollutant[i].p_alarmup = atof(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 4));
g_site_conf_extend.pollutant[i].p_alarmdown = atof(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 5));
g_site_conf_extend.pollutant[i].p_up = atof(tmpbuf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 6));
g_site_conf_extend.pollutant[i].p_down = atof(tmpbuf);
}
}
//本地IP地址
ret = ConfigGetKey(cfghandle, "NET_ INFO", "LOCALIP", buf);
if (ret == CFG_OK)
{
ret = getcsvlen(buf);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 0)); //得到IP
ret = getcsvlendot(tmpbuf);
for (i = 0; i < 4; i++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '.', i)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.netcfg.localip[i] = (int)strtoint(tmppbuf, vv);
}
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 1)); //得到mask
ret = getcsvlendot(tmpbuf);
for (i = 0; i < 4; i++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '.', i)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.netcfg.mask[i] = (int)strtoint(tmppbuf, vv);
}
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 2)); //gate
ret = getcsvlendot(tmpbuf);
for (i = 0; i < 4; i++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '.', i)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.netcfg.gate[i] = (int)strtoint(tmppbuf, vv);
}
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 3)); //mac
ret = getcsvlendot(tmpbuf);
for (i = 0; i < 6; i++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '-', i)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.netcfg.arp_addr[i] = (int)hexstrtoint(tmppbuf);
}
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 4)); //dns1
ret = getcsvlendot(tmpbuf);
for (i = 0; i < 4; i++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '.', i)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.netcfg.dns1[i] = (int)strtoint(tmppbuf, vv);
}
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 5)); //dns2
ret = getcsvlendot(tmpbuf);
for (i = 0; i < 4; i++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '.', i)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.netcfg.dns2[i] = (int)strtoint(tmppbuf, vv);
}
}
//中心设置
ret = ConfigGetKey(cfghandle, "REMOTE_COMM_INFO", "CENTER_NUM", buf);
if (ret == CFG_OK)
{
//支持中心数量
g_site_conf_extend.center_num = atoi(buf);
}
for (i = 0; i < g_site_conf_extend.center_num; i++)
{
strncpy(tmpbuf, "CENTER_SET", 10);
tmpbuf[10] = (unsigned char)(i + 1 + 0x30);
tmpbuf[11] = '\0';
ret = ConfigGetKey(cfghandle, "REMOTE_COMM_INFO", tmpbuf, buf);
if (ret == CFG_OK)
{
ret = getcsvlen(buf);
g_site_conf_extend.center[i].REMOTE_COMM_TYPE = (BYTE)strtoint(pickcsvdata(buf, ret, ';', ',', 0), 1);
g_site_conf_extend.center[i].flgUsed = TRUE;
g_site_conf_extend.center[i].REMOTE_COMM_PROTOCOL = (BYTE)strtoint(pickcsvdata(buf, ret, ';', ',', 1), 1);
strcpy(tmpbuf, pickcsvdata(buf, ret, ';', ',', 2)); //得到mask
ret = getcsvlen(tmpbuf);
for (j = 0; j < 4; j++)
{
strcpy(tmppbuf, pickcsvdata(tmpbuf, ret, ',', '.', j)); //得到IP的第i段
vv = strlen(tmppbuf);
g_site_conf_extend.center[i].CENTER_IP[j] = (int)strtoint(tmppbuf, vv);
}
}
}
//........
__fclose(cfghandle);
}
/************************************************************************************************
* 取出CSV格式内的字符串
* @param unsigned char *buf 原串
* @param analysechar 分隔符号
* @param pos 取第n个分隔符号后的字串
* @return unsigned char * 返回的字符串
**************************************************************************************************/
unsigned char * pickcsvdata(unsigned char *buf, unsigned int len, unsigned char endchar, unsigned char analysechar, unsigned int pos)
{
unsigned char bu[30];
unsigned int i, count, iStart, iEnd;
iStart = iEnd = count = 0;
//len = 30;//strlen(buf);
for (i = 0; i < len; i++)
{
if ((buf[i] == analysechar) || (buf[i] == endchar))
{
if (pos == 0)
{
iStart = 0;
iEnd = i;
break;
}
else if (i == len - 1)
{
iEnd = i;
break;
}
else
{
if (count == pos - 1)
iStart = i + 1;
if (count == pos)
{
iEnd = i;
break;
}
}
count++;
}
}
//if (i == len)
// iEnd = len - 1;
if (iStart < iEnd)
{
strncpy((char*)&bu[0], (char*)&buf[iStart], iEnd - iStart);
bu[iEnd - iStart] = '\0';
}
else
bu[0] = '\0';
return &bu[0];
}
//把长为len的ASCII数字字符串转成数字,例如"918"变味918
long strtoint(unsigned char *buf, unsigned int len)
{
long Temp = 0;
long dd = 1;
int j;
for (j = 1; j < len; j++)
dd *= 10;
for (j = 0;j < len; j++){
Temp = Temp + (buf[j] - 0x30) * dd;
dd = dd / 10;
}
return Temp;
}
//将int转换为n位十进制ASCII字符串
void inttoasc(int Data, unsigned char *uData, int len){
long Div;
unsigned char i;
Div = 100;
for (i = 0; i < 3; i++){
uData[(len - 1) - i] = (Data / Div) + 0x30;
Data = Data % Div;
Div = Div/10;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -