add compress

This commit is contained in:
zhangsheng 2024-11-08 17:59:27 +08:00
parent f37e64edfd
commit 6b81060391
2 changed files with 26 additions and 9 deletions

View File

@ -23,7 +23,7 @@ enum InteractiveCommand {
WAVE_Z = 7, // 只从传感器发出 WAVE_Z = 7, // 只从传感器发出
REVIVE_DURATION = 8, // 复活时长 REVIVE_DURATION = 8, // 复活时长
CONFIG = 9, // 配置 只从无线网关发出 CONFIG = 9, // 配置 只从无线网关发出
CONFIG_INF2 = 10, // 配置 只从无线网关发出 CONFIG_INF2 = 10, // 配置 只从无线网关发出 测点名称,测点编号
DEVICE_INF2 = 11, // 测点名称,测点编号 DEVICE_INF2 = 11, // 测点名称,测点编号
UPGRADE = 12, // 升级, 升级给这条信息 UPGRADE = 12, // 升级, 升级给这条信息
SIGNAL_STRENGTH = 13, // 信号强度 SIGNAL_STRENGTH = 13, // 信号强度

View File

@ -68,7 +68,7 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) {
zlog_info(zct, "thisindex = %d", thisindex); zlog_info(zct, "thisindex = %d", thisindex);
FILE* pFile = NULL; FILE* pFile = NULL;
char* buffer = NULL; unsigned char* buffer = NULL;
int thisSize = 0; int thisSize = 0;
DataNodeUpdateFile = "/opt/DataNode/" + strFileName; DataNodeUpdateFile = "/opt/DataNode/" + strFileName;
zlog_info(zct, "strFileName = %s", DataNodeUpdateFile.c_str()); zlog_info(zct, "strFileName = %s", DataNodeUpdateFile.c_str());
@ -80,11 +80,20 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) {
++thisSize; ++thisSize;
} }
rewind(pFile); rewind(pFile);
buffer = (char*)malloc(thisSize); buffer = (unsigned char*)malloc(thisSize);
fread(buffer, sizeof(char), thisSize, pFile); fread(buffer, sizeof(char), thisSize, pFile);
fclose(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 Data[12] = {0x00};
unsigned char size[4] = {0x00}; unsigned char size[4] = {0x00};
zlog_info(zct, "thisSize = %d", thisSize); zlog_info(zct, "thisSize = %d", thisSize);
@ -96,11 +105,18 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) {
Data[4] = UINT16_LOW(shortAdd); Data[4] = UINT16_LOW(shortAdd);
Data[5] = 0x20; Data[5] = 0x20;
Data[6] = 0x00; Data[6] = 0x00;
int2bytes(thisSize, size, 4); if (compress == 1)
Data[7] = size[3]; {
Data[8] = size[2]; int2bytes(new_len, size, 4);
Data[9] = size[1]; }else{
Data[10] = size[0]; int2bytes(thisSize, size, 4);
}
Data[13] = size[3];
Data[14] = size[2];
Data[15] = size[1];
Data[16] = size[0];
unsigned char tmp = 0x00; unsigned char tmp = 0x00;
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
tmp += Data[i]; tmp += Data[i];
@ -116,6 +132,7 @@ bool Uart::ReadUpdatePackge(unsigned short shortAdd) {
} }
std::string strTime = GetLocalTimeWithMs(); std::string strTime = GetLocalTimeWithMs();
zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str()); zlog_info(zct, "ReadUpdatePackge strTime = %s", strTime.c_str());
free(buffer);
return true; return true;
} }