diff --git a/uart/uart.hpp b/uart/uart.hpp index e5fff94..eda2f21 100644 --- a/uart/uart.hpp +++ b/uart/uart.hpp @@ -23,7 +23,7 @@ enum InteractiveCommand { WAVE_Z = 7, // 只从传感器发出 REVIVE_DURATION = 8, // 复活时长 CONFIG = 9, // 配置 只从无线网关发出 - CONFIG_INF2 = 10, // 配置 只从无线网关发出 + CONFIG_INF2 = 10, // 配置 只从无线网关发出 测点名称,测点编号 DEVICE_INF2 = 11, // 测点名称,测点编号 UPGRADE = 12, // 升级, 升级给这条信息 SIGNAL_STRENGTH = 13, // 信号强度 diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 73dd203..d737aa5 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -68,7 +68,7 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) { zlog_info(zct, "thisindex = %d", thisindex); FILE* pFile = NULL; - char* buffer = NULL; + unsigned char* buffer = NULL; int thisSize = 0; DataNodeUpdateFile = "/opt/DataNode/" + strFileName; zlog_info(zct, "strFileName = %s", DataNodeUpdateFile.c_str()); @@ -80,11 +80,20 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) { ++thisSize; } rewind(pFile); - buffer = (char*)malloc(thisSize); + buffer = (unsigned char*)malloc(thisSize); fread(buffer, sizeof(char), thisSize, pFile); fclose(pFile); } - int r = lzo1x_1_compress(data, count, outdata, &new_len, NULL); + char outdata[50000]={0}; + long unsigned int new_len = 0, deallen = 0; + int compress = 0; + // int r = lzo1x_1_compress(buffer, thisSize, outdata, &new_len, NULL); + // if (r == LZO_E_OK){ + // if (new_len < thisSize){ + // compress = 1; + // } + // } + unsigned char Data[12] = {0x00}; unsigned char size[4] = {0x00}; zlog_info(zct, "thisSize = %d", thisSize); @@ -96,11 +105,18 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) { Data[4] = UINT16_LOW(shortAdd); Data[5] = 0x20; Data[6] = 0x00; - int2bytes(thisSize, size, 4); - Data[7] = size[3]; - Data[8] = size[2]; - Data[9] = size[1]; - Data[10] = size[0]; + if (compress == 1) + { + int2bytes(new_len, size, 4); + }else{ + int2bytes(thisSize, size, 4); + } + Data[13] = size[3]; + Data[14] = size[2]; + Data[15] = size[1]; + Data[16] = size[0]; + + unsigned char tmp = 0x00; for (int i = 0; i < 11; i++) { tmp += Data[i]; @@ -116,6 +132,7 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) { } std::string strTime = GetLocalTimeWithMs(); zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str()); + free(buffer); return true; }