From f2166403813aee2c9a92aaeec1e72fb2f8d07338 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 May 2025 17:20:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=97=A5=E5=BF=97=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=96=B9=E4=BE=BF=E9=97=AE=E9=A2=98=E6=8E=92?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/SensorsProtocol.cpp | 722 ++++++++++----------------- app/src/main/cpp/SensorsProtocol.h | 2 +- 2 files changed, 274 insertions(+), 450 deletions(-) diff --git a/app/src/main/cpp/SensorsProtocol.cpp b/app/src/main/cpp/SensorsProtocol.cpp index 91e1e7f5..dd896aa2 100644 --- a/app/src/main/cpp/SensorsProtocol.cpp +++ b/app/src/main/cpp/SensorsProtocol.cpp @@ -8,7 +8,6 @@ #include #include #include -//#include #include #include #include @@ -25,7 +24,6 @@ #include "AndroidHelper.h" #include "SensorsProtocol.h" -//#include "Eint.h" #include pthread_mutex_t serial_mutex = PTHREAD_MUTEX_INITIALIZER; // 定义一个互斥锁 @@ -93,6 +91,154 @@ static int64_t get_msec() return time_in_msec; } + +void DebugLog(int commid, char flag, const char* format, ...) +{ + va_list argptr; + va_start(argptr, format); + + auto len = vsnprintf(NULL, 0, format, argptr); + if (len < 0) + { + va_end(argptr); + return; + } + + char* szbuf = new char[len + 1]; + szbuf[len] = 0; + len = std::vsnprintf(szbuf, len + 1, format, argptr); + va_end(argptr); + if (len < 0) + { + delete[] szbuf; + return; + } + + SaveLogTofile(commid, szbuf); +#ifndef NDEBUG + switch (flag) + { + case 'E': + ALOGE("%s", szbuf); + break; + case 'I': + ALOGI("%s", szbuf); + break; + case 'D': + ALOGD("%s", szbuf); + break; + case 'V': + ALOGI("%s", szbuf); + break; + case 'W': + ALOGW("%s", szbuf); + break; + default: + ALOGI("%s", szbuf); + break; + } +#endif + + delete[] szbuf; +} + +int SaveLogTofile(int commid, const char *szbuf) +{ + int status; + time_t now; + char filename[512], filedir[512], buf[128]; + FILE *fp = NULL; + struct tm t0; + struct timeval tv; + + if (NULL == szbuf) + return -1; + + now = time(NULL); + localtime_r(&now, &t0); + gettimeofday(&tv, NULL); + + memset(filedir, 0, sizeof(filedir)); + if(logPath != NULL) + strcpy(filedir, logPath); + + if (access(filedir, 0) == 0) + ;//LOGI("文件路径已经存在!"); + else + { + status = mkdir(filedir, S_IRWXU | S_IRWXG | S_IRWXO); + if (status < 0) + return -1; + } + // 写入文件到sdcard + memset(filename, 0, sizeof(filename)); + sprintf(filename, "%sCOM%dlog-%04d-%02d-%02d.txt", filedir, commid + 1, t0.tm_year + 1900, t0.tm_mon + 1, t0.tm_mday); + fp = fopen(filename, "a+"); + if (NULL == fp) + return -1; + memset(buf, 0, sizeof(buf)); + sprintf(buf, "%d-%02d-%02d %02d:%02d:%02d-%03d ", t0.tm_year + 1900, t0.tm_mon + 1, t0.tm_mday, t0.tm_hour, t0.tm_min, t0.tm_sec, (int)(tv.tv_usec / 1000)); + fwrite(buf, 1, strlen(buf), fp); + fwrite(szbuf, 1, strlen(szbuf), fp); + memset(buf, 0, sizeof(buf)); + strcpy(buf, "\n"); + fwrite(buf, 1, strlen(buf), fp); + + fclose(fp); + return 1; +} + +int SaveImageDataTofile(SIO_PARAM_SERIAL_DEF *curserial) +{ + u_char *image = NULL, *tempphoto = NULL; + int i, status; + size_t len; + // char filename[512]; + FILE *fp = NULL; + + image = (u_char*)malloc(curserial->image.imagelen); + if (NULL == image) + return -1; + tempphoto = image; + for (i = 0; i < curserial->image.imagenum; ++i) { + memmove(tempphoto, &curserial->image.buf[i], (size_t)curserial->image.ilen[i]); + tempphoto += (size_t)curserial->image.ilen[i]; + } + + // memset(szbuf, 0, sizeof(szbuf)); + //memset(filedir, 0, sizeof(filedir)); + //sprintf(filedir, "/sdcard/photo/"); + + if (access(srdt.filedir, 0) == 0) + { + // DebugLog(0, 'I', "文件路径%s已经存在!", srdt.filedir); + DebugLog(0, 'I', "文件路径%s已经存在!", srdt.filedir); + } + else + { + status = mkdir(srdt.filedir, S_IRWXU | S_IRWXG | S_IRWXO); + if (status < 0) + return -1; + } + // 写入文件到sdcard + memset(curserial->image.photoname, 0, sizeof(curserial->image.photoname)); + sprintf(curserial->image.photoname, "%s1-%d-%d.jpg", srdt.filedir, curserial->image.presetno, curserial->image.phototime); + fp = fopen(curserial->image.photoname, "wb+"); + if (NULL == fp) + return -1; + len = fwrite(image, 1, curserial->image.imagelen, fp); + fclose(fp); + free(image); + image = NULL; + if (len < curserial->image.imagelen) + return -1; + else + { + DebugLog(0, 'I', "写入图片文件%s成功!", curserial->image.photoname); + return 1; + } +} + /* 打开串口电源 */ @@ -179,28 +325,23 @@ void BytestreamLOG(int commid, char* describe, u_char* buf, int len, char flag) void Gm_OpenSerialPort(int devidx) { int fd = -1; - char szbuf[512]; if ((devidx < 0) || (devidx >= MAX_SERIAL_DEV_NUM)) return; - memset(szbuf, 0, sizeof(szbuf)); if (serialport[devparam[devidx].commid].fd <= 0) { fd = ::open(devparam[devidx].pathname, O_RDWR | O_NDELAY); if (fd < 0) { - sprintf(szbuf, "装置%d 打开串口%d %s失败!fd=%d", devidx+1, devparam[devidx].commid+1, devparam[devidx].pathname, fd); - DebugLog(devparam[devidx].commid, szbuf, 'E'); + DebugLog(devparam[devidx].commid, 'E', "装置%d 打开串口%d %s失败!fd=%d", devidx+1, devparam[devidx].commid+1, devparam[devidx].pathname, fd); return; } - sprintf(szbuf, "装置%d 打开串口%d %s成功!fd=%d", devidx + 1, devparam[devidx].commid + 1, devparam[devidx].pathname, fd); - DebugLog(devparam[devidx].commid, szbuf, 'I'); + DebugLog(devparam[devidx].commid, 'I', "装置%d 打开串口%d %s成功!fd=%d", devidx + 1, devparam[devidx].commid + 1, devparam[devidx].pathname, fd); serialport[devparam[devidx].commid].fd = fd; Gm_SetSerialPortParam(devparam[devidx].commid); return; } - sprintf(szbuf, "装置%d 串口%d %s已经打开!fd=%d", devidx + 1, devparam[devidx].commid + 1, devparam[devidx].pathname, serialport[devparam[devidx].commid].fd); - DebugLog(devparam[devidx].commid, szbuf, 'I'); + DebugLog(devparam[devidx].commid, 'I', "装置%d 串口%d %s已经打开!fd=%d", devidx + 1, devparam[devidx].commid + 1, devparam[devidx].pathname, serialport[devparam[devidx].commid].fd); } // 关闭串口通讯 @@ -239,8 +380,7 @@ int GM_SerialComSend(unsigned char * cSendBuf, size_t nSendLen, int commid) //isendtime = get_msec(); if (len < 0) { - sprintf(szbuf, "write data error "); - DebugLog(commid, szbuf, 'E'); + DebugLog(commid, 'E', "write data error "); return -1; } else if (len > 0) @@ -261,8 +401,7 @@ int Gm_SetSerialPortParam(int commid) if (ret < 0) { memset(szbuf, 0, sizeof(szbuf)); - sprintf(szbuf, "串口%d 波特率等参数设置错误!", commid + 1); - DebugLog(commid, szbuf, 'E'); + DebugLog(commid, 'E', "串口%d 波特率等参数设置错误!", commid + 1); return -1; } return ret; @@ -533,8 +672,7 @@ void Gm_InitSerialComm(SENSOR_PARAM *sensorParam, const char *filedir,const char sprintf(szbuf, "%s", "没有启用!;"); else { - sprintf(szbuf, "%s 已启用!;", szbuf); - DebugLog(8, szbuf, 'I'); + DebugLog(8, 'I', "%s 已启用!;", szbuf); } } if (NULL == filedir) @@ -786,8 +924,7 @@ void GM_StartSerialComm() { srdt.ms_dev[i].aiValue[j].AiState = SER_STARTSAMPLE; weatherpntmsg[j].AiState = SER_STARTSAMPLE; - sprintf(logbuf, "init weather_state%d=%d", j, weatherpntmsg[j].AiState); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "init weather_state%d=%d", j, weatherpntmsg[j].AiState); } break; case RALLY_PROTOCOL: /* 拉力*/ @@ -808,8 +945,7 @@ void GM_StartSerialComm() { srdt.ms_dev[i].aiValue[j].AiState = SER_STARTSAMPLE; weatherpntmsg[j].AiState = SER_STARTSAMPLE; - sprintf(logbuf, "init weather_state%d=%d", j, weatherpntmsg[j].AiState); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "init weather_state%d=%d", j, weatherpntmsg[j].AiState); } break; case SLANT_PROTOCOL: /* 倾角*/ @@ -839,14 +975,13 @@ void GM_StartSerialComm() memset(logbuf, 0, sizeof(logbuf)); if (1 == srdt.ms_dev[i].IsNeedSerial) { - sprintf(logbuf, "装置%d, IsNoInsta=%d, 类型:%s", i + 1, devparam[i].IsNoInsta, szbuf); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "装置%d, IsNoInsta=%d, 类型:%s", i + 1, devparam[i].IsNoInsta, szbuf); Gm_OpenSensorsPower(); Gm_OpenSerialPort(i); } } - DebugLog(8, "启动数据采样!", 'I'); + DebugLog(8, 'I', "启动数据采样!"); /* 直接使用循环进行采样处理*/ //polltime = get_msec(); for (;;) @@ -856,7 +991,7 @@ void GM_StartSerialComm() //polltime = get_msec(); if (GM_SerialTimer() < 0) { - DebugLog(8, "退出采样流程!", 'V'); + DebugLog(8, 'V', "退出采样流程!"); sleep(5); //GM_StartSerialComm(); break; @@ -973,8 +1108,7 @@ void GM_IsCloseSensors() { srdt.ms_dev[i].IsNeedSerial = 0; // 关闭传感器电源 - sprintf(buf, "读取装置%d数据%0.3f秒,关闭装置%d电源!", i + 1, (get_msec() - srdt.ms_dev[i].FirstCmdTimeCnt) / 1000.0, i + 1); - DebugLog(devparam[i].commid, buf, 'I'); + DebugLog(devparam[i].commid, 'I', "读取装置%d数据%0.3f秒,关闭装置%d电源!", i + 1, (get_msec() - srdt.ms_dev[i].FirstCmdTimeCnt) / 1000.0, i + 1); for (j = 0; j < MAX_DEV_VALUE_NUM; j++) { if (SER_STARTSAMPLE == srdt.ms_dev[i].aiValue[j].AiState) @@ -990,8 +1124,7 @@ void GM_IsCloseSensors() weatherpntmsg[j].AiState = SER_SAMPLEFAIL; else if (SER_SAMPLE == weatherpntmsg[j].AiState) weatherpntmsg[j].AiState = SAMPLINGSUCCESS; - sprintf(buf, "over weather_state%d=%d", j, weatherpntmsg[j].AiState); - DebugLog(8, buf, 'I'); + DebugLog(8, 'I', "over weather_state%d=%d", j, weatherpntmsg[j].AiState); } } } @@ -1006,8 +1139,7 @@ void GM_IsCloseSensors() else if (PHOTO_SAVE_SUCC == srdt.ms_dev[i].image.state) srdt.ms_dev[i].image.state = SAMPLINGSUCCESS; srdt.ms_dev[i].IsNeedSerial = 0; - sprintf(buf, "通道%d摄像机使用完毕!可以关闭摄像机电源!", devparam[i].CameraChannel); - DebugLog(devparam[i].commid, buf, 'I'); + DebugLog(devparam[i].commid, 'I', "通道%d摄像机使用完毕!可以关闭摄像机电源!", devparam[i].CameraChannel); } break; } @@ -1075,8 +1207,7 @@ int GM_CloseTimer() //Gm_CloseSensorsPower(); for (j = 1; j < MAX_SERIAL_PORT_NUM; j++) ClearCmdFormPollCmdBuf(j); - sprintf(buf, "%s", "关闭串口定时器!"); - DebugLog(8, buf, 'I'); + DebugLog(8, 'I', "%s", "关闭串口定时器!"); return -1; } } @@ -1085,7 +1216,6 @@ void SerialDataProcess(int devidx, u_char *buf, int len) { switch (devparam[devidx].ProtocolIdx) { - case WEATHER_PROTOCOL: /* 气象*/ case RALLY_PROTOCOL: /* 拉力*/ case WIND_PROTOCOL: /* 风速风向*/ @@ -1102,133 +1232,6 @@ void SerialDataProcess(int devidx, u_char *buf, int len) } } -void DebugLog(int commid, const char *szbuf, char flag) -{ - if (NULL == szbuf) - return; - SaveLogTofile(commid, szbuf); - switch (flag) - { - case 'E': - ALOGE("%s", szbuf); - break; - case 'I': - ALOGI("%s", szbuf); - break; - case 'D': - ALOGD("%s", szbuf); - break; - case 'V': - ALOGI("%s", szbuf); - break; - case 'W': - ALOGW("%s", szbuf); - break; - default: - ALOGI("%s", szbuf); - break; - } -} - -int SaveLogTofile(int commid, const char *szbuf) -{ - int status; - time_t now; - char filename[512], filedir[512], buf[128]; - FILE *fp = NULL; - struct tm t0; - struct timeval tv; - - if (NULL == szbuf) - return -1; - - now = time(NULL); - localtime_r(&now, &t0); - gettimeofday(&tv, NULL); - - memset(filedir, 0, sizeof(filedir)); - if(logPath != NULL) - strcpy(filedir, logPath); - - if (access(filedir, 0) == 0) - ;//LOGI("文件路径已经存在!"); - else - { - status = mkdir(filedir, S_IRWXU | S_IRWXG | S_IRWXO); - if (status < 0) - return -1; - } - // 写入文件到sdcard - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%sCOM%dlog-%04d-%02d-%02d.txt", filedir, commid + 1, t0.tm_year + 1900, t0.tm_mon + 1, t0.tm_mday); - fp = fopen(filename, "a+"); - if (NULL == fp) - return -1; - memset(buf, 0, sizeof(buf)); - sprintf(buf, "%d-%d-%d %d:%d:%d-%d ", t0.tm_year + 1900, t0.tm_mon + 1, t0.tm_mday, t0.tm_hour, t0.tm_min, t0.tm_sec, (int)(tv.tv_usec / 1000)); - fwrite(buf, 1, strlen(buf), fp); - fwrite(szbuf, 1, strlen(szbuf), fp); - memset(buf, 0, sizeof(buf)); - strcpy(buf, "\n"); - fwrite(buf, 1, strlen(buf), fp); - - fclose(fp); - return 1; -} - -int SaveImageDataTofile(SIO_PARAM_SERIAL_DEF *curserial) -{ - u_char *image = NULL, *tempphoto = NULL; - int i, status; - size_t len; - char filename[512]/*, filedir[512]*/, szbuf[128]; - FILE *fp = NULL; - - image = (u_char*)malloc(curserial->image.imagelen); - if (NULL == image) - return -1; - tempphoto = image; - for (i = 0; i < curserial->image.imagenum; ++i) { - memmove(tempphoto, &curserial->image.buf[i], (size_t)curserial->image.ilen[i]); - tempphoto += (size_t)curserial->image.ilen[i]; - } - - memset(szbuf, 0, sizeof(szbuf)); - //memset(filedir, 0, sizeof(filedir)); - //sprintf(filedir, "/sdcard/photo/"); - - if (access(srdt.filedir, 0) == 0) - { - sprintf(szbuf, "文件路径%s已经存在!", srdt.filedir); - DebugLog(0, szbuf, 'I'); - } - else - { - status = mkdir(srdt.filedir, S_IRWXU | S_IRWXG | S_IRWXO); - if (status < 0) - return -1; - } - // 写入文件到sdcard - memset(curserial->image.photoname, 0, sizeof(curserial->image.photoname)); - sprintf(curserial->image.photoname, "%s1-%d-%d.jpg", srdt.filedir, curserial->image.presetno, curserial->image.phototime); - fp = fopen(curserial->image.photoname, "wb+"); - if (NULL == fp) - return -1; - len = fwrite(image, 1, curserial->image.imagelen, fp); - fclose(fp); - free(image); - image = NULL; - if (len < curserial->image.imagelen) - return -1; - else - { - memset(szbuf, 0, sizeof(szbuf)); - sprintf(szbuf, "写入图片文件%s成功!", curserial->image.photoname); - DebugLog(0, szbuf, 'I'); - return 1; - } -} - /******************************************************************* * 读 摄像机 数据 * *******************************************************************/ @@ -1325,7 +1328,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) int img_file_size, packetnum, iNo, packsize, i = 0, j = 0, presetno, iphototime, pidx; int datanum; float fvalue; - char szbuf[128]; + // char szbuf[128]; uint16_t uDevAddr, datalen=0; uint8_t cmdidx, recvend; @@ -1341,7 +1344,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) datalen = rtumsg.MsgData[1]*256+rtumsg.MsgData[2]; if (uDevAddr != curserial->cameraaddr) return; - memset(szbuf, 0, sizeof(szbuf)); + // memset(szbuf, 0, sizeof(szbuf)); switch (cmdidx) { case 0x10: /* 拍照应答*/ @@ -1351,8 +1354,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) if (srdt.RephotographCnt > 2) { curserial->SerialCmdidx = -1; - sprintf(szbuf, "因摄像机重拍%u次均未成功!结束拍照!", (uint32_t)srdt.RephotographCnt); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "因摄像机重拍%u次均未成功!结束拍照!", (uint32_t)srdt.RephotographCnt); } break; } @@ -1367,8 +1369,8 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) curserial->image.imagelen = img_file_size; curserial->image.imagenum = packetnum; srdt.historyimagenum[0] = rtumsg.MsgData[i + 7] + (rtumsg.MsgData[i + 6] << 8); - sprintf(szbuf, "有%d张历史图片!", srdt.historyimagenum[0]); - DebugLog(0, szbuf, 'V'); + DebugLog(0, 'V', "有%d张历史图片!", srdt.historyimagenum[0]); + presetno = (int)rtumsg.MsgData[i + 8]; curserial->image.presetno = presetno; curserial->image.state = SER_SAMPLE; @@ -1388,8 +1390,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) packsize = rtumsg.MsgData[i + 3] + rtumsg.MsgData[i + 2] * 256; memmove(&curserial->image.buf[iNo - 1], &rtumsg.MsgData[i + 4], packsize); curserial->image.ilen[iNo - 1] = packsize; - sprintf(szbuf, "收到第%d(总%d包)包长=%d", iNo, curserial->image.imagenum, packsize); - DebugLog(0, szbuf, 'V'); + DebugLog(0, 'V', "收到第%d(总%d包)包长=%d", iNo, curserial->image.imagenum, packsize); curserial->RevCmdFlag = 1; curserial->FirstCmdTimeCnt = get_msec(); if (iNo == curserial->SerialCmdidx) @@ -1442,9 +1443,8 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) break; } srdt.errorPhotoNoCnt++; - sprintf(szbuf, "问询第%d包图片摄像机应答第%d包,连续错误%d次!", - curserial->SerialCmdidx, iNo, (uint32_t)srdt.errorPhotoNoCnt); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "问询第%d包图片摄像机应答第%d包,连续错误%d次!", + curserial->SerialCmdidx, iNo, (uint32_t)srdt.errorPhotoNoCnt); if (srdt.errorPhotoNoCnt > 5) { curserial->SerialCmdidx = 0; @@ -1452,27 +1452,23 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) if (srdt.RephotographCnt > 2) { curserial->SerialCmdidx = -1; - sprintf(szbuf, "因摄像机重拍%d次均未成功!结束拍照!", (uint32_t)srdt.RephotographCnt); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "因摄像机重拍%d次均未成功!结束拍照!", (uint32_t)srdt.RephotographCnt); } } break; case 0x03: - //sprintf(szbuf, "设置波特率%d成功", curserial->baud); - //DebugLog(devparam[devno].commid, szbuf, 'D'); curserial->SerialCmdidx = srdt.iLastGetPhotoNo; srdt.iLastGetPhotoNo = -1; curserial->RevCmdFlag = 1; curserial->FirstCmdTimeCnt = get_msec(); break; case 0xA0: - sprintf(szbuf, "云台收到关电通知响应!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台收到关电通知响应!"); curserial->SerialCmdidx = -1; break; case 0x08: datanum = curserial->m_au8RecvBuf[6]; - memset(szbuf, 0, sizeof(szbuf)); + // memset(szbuf, 0, sizeof(szbuf)); for (i = 0, j = 7; (i < datanum) && (j < 6 + datalen); i++, j += 5) { fvalue = (curserial->m_au8RecvBuf[j + 1] << 24) + (curserial->m_au8RecvBuf[j + 2] << 16) @@ -1486,43 +1482,38 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) { case 1: // 自检 if (0 == curserial->ptz_state.ptz_status) - sprintf(szbuf, "云台自检结束!"); + DebugLog(0, 'I', "云台自检结束!"); else if (0 < curserial->ptz_state.ptz_status) - sprintf(szbuf, "云台正在自检!"); + DebugLog(0, 'I', "云台正在自检!"); else - sprintf(szbuf, "云台自检发生错误!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台自检发生错误!"); break; case 2: // 调用预置点 if (0 == curserial->ptz_state.ptz_status) - sprintf(szbuf, "调用预置位结束,云台处于所调预置位!"); + DebugLog(0, 'I', "调用预置位结束,云台处于所调预置位!"); else if (0 < curserial->ptz_state.ptz_status) - sprintf(szbuf, "调用预置位,云台正在前往所调预置位位置!"); + DebugLog(0, 'I', "调用预置位,云台正在前往所调预置位位置!"); else if (2 == (curserial->ptz_state.ptz_status & 0x0f)) - sprintf(szbuf, "调用预置位时,机芯电源未打开!"); + DebugLog(0, 'I', "调用预置位时,机芯电源未打开!"); else - sprintf(szbuf, "调用预置位时,发生了错误,未正确执行!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "调用预置位时,发生了错误,未正确执行!"); break; case 3: // 一般状态 if (0 == curserial->ptz_state.ptz_status) - sprintf(szbuf, "云台处于静止状态!"); + DebugLog(0, 'I', "云台处于静止状态!"); else if (0 < curserial->ptz_state.ptz_status) - sprintf(szbuf, "云台正在运动!"); + DebugLog(0, 'I', "云台正在运动!"); else - sprintf(szbuf, "云台发生错误!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台发生错误!"); break; default: - sprintf(szbuf, "未知错误,云台应答错误!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "未知错误,云台应答错误!"); break; } break; case 201: /* 云台预置点*/ curserial->ptz_state.presetno = (curserial->m_au8RecvBuf[j + 3] << 8) + curserial->m_au8RecvBuf[j + 4]; - sprintf(szbuf, "云台预置点号=%u", (uint32_t)curserial->ptz_state.presetno); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台预置点号=%u", (uint32_t)curserial->ptz_state.presetno); break; case 202: /* 云台坐标*/ fvalue = (uint16_t)((curserial->m_au8RecvBuf[j + 1] << 8) + (curserial->m_au8RecvBuf[j + 2])); @@ -1539,8 +1530,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) if(fvalue > 180) fvalue -= 360; curserial->ptz_state.y_coordinate = fvalue; - sprintf(szbuf, "云台坐标水平(X)=%0.2f°, 垂直(Y)=%0.2f°", curserial->ptz_state.x_coordinate, curserial->ptz_state.y_coordinate); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台坐标水平(X)=%0.2f°, 垂直(Y)=%0.2f°", curserial->ptz_state.x_coordinate, curserial->ptz_state.y_coordinate); break; } } @@ -1550,8 +1540,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) if (0xFF == rtumsg.MsgData[6]) { curserial->SerialCmdidx = -1; - strcpy(szbuf, "没有历史图片!结束读取图片!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "没有历史图片!结束读取图片!"); break; } i = 6; @@ -1567,8 +1556,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) srdt.historyimagenum[0] = rtumsg.MsgData[i + 7] + (rtumsg.MsgData[i + 6] << 8); presetno = rtumsg.MsgData[i + 8]; curserial->image.presetno = presetno; - sprintf(szbuf, "读取历史图片,还有%d张历史图片!", srdt.historyimagenum[0]); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "读取历史图片,还有%d张历史图片!", srdt.historyimagenum[0]); curserial->RevCmdFlag = 1; curserial->SerialCmdidx = 1; srdt.sendphotocmdcnt = 0; @@ -1577,8 +1565,7 @@ void CameraPhotoPortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) if (0xFF == rtumsg.MsgData[10]) { curserial->SerialCmdidx = -1; - strcpy(szbuf, "摄像机图片保存失败!"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "摄像机图片保存失败!"); } curserial->SerialCmdidx = -1; if (0 == rtumsg.MsgData[10]) @@ -1690,16 +1677,13 @@ void SendCmdFormPollCmdBuf(int port) len = GM_SerialComSend(&pPortParam->PollCmd[2], pPortParam->cmdlen - 2, port); if (len < 1) { - sprintf(buf, "串口%d, 发送命令失败! fd = %d", port + 1, serialport[port].fd); - DebugLog(port, buf, 'E'); + DebugLog(port, 'E', "串口%d, 发送命令失败! fd = %d", port + 1, serialport[port].fd); } else { - sprintf(buf, "发送串口%d 装置%d命令:", port + 1, srdt.curdevidx[port] + 1); BytestreamLOG(port, buf, &pPortParam->PollCmd[2], len, 'D'); - sprintf(buf, "sendtimeconst= %lld", (long long)(lctime - pPortParam->lsendtime)); - DebugLog(port, buf, 'W'); + DebugLog(port, 'W', "sendtimeconst= %lld", (long long)(lctime - pPortParam->lsendtime)); pPortParam->lsendtime = lctime; } pPortParam->SendCmdFlag = 1; @@ -1801,13 +1785,11 @@ int FindNextCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam) if (lcurtime - pPortParam->FirstCmdTimeCnt > 35 * 1000) { pPortParam->SerialCmdidx = -1; - strcpy(szbuf, "串口摄像机未接或故障!结束拍照!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "串口摄像机未接或故障!结束拍照!"); return -1; } memset(szbuf, 0, sizeof(szbuf)); - sprintf(szbuf, "time=%lld ms", (long long)(lcurtime - pPortParam->FirstCmdTimeCnt)); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "time=%lld ms", (long long)(lcurtime - pPortParam->FirstCmdTimeCnt)); packetsize = (uint16_t)MAX_PHOTO_FRAME_LEN; srdt.sendphotocmdcnt++; srdt.imagepacketnum = 0; @@ -1830,8 +1812,7 @@ int FindNextCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam) imagesize = 0x09; break; default: - sprintf(szbuf, "设置串口摄像机参数时,配置参数错误!退出设置!"); - DebugLog(devparam[devidx].commid, szbuf, 'I'); + DebugLog(devparam[devidx].commid, 'I', "设置串口摄像机参数时,配置参数错误!退出设置!"); pPortParam->SerialCmdidx = srdt.iLastGetPhotoNo; srdt.iLastGetPhotoNo = -1; return -1; @@ -1840,8 +1821,7 @@ int FindNextCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam) if (lcurtime - pPortParam->FirstCmdTimeCnt > 15 * 1000) { pPortParam->SerialCmdidx = -1; - sprintf(szbuf, "设置串口摄像机参数时,15秒未收到摄像机应答!退出设置!"); - DebugLog(devparam[devidx].commid, szbuf, 'I'); + DebugLog(devparam[devidx].commid, 'I', "设置串口摄像机参数时,15秒未收到摄像机应答!退出设置!"); return -1; } cmdidx = 0x03; @@ -1987,33 +1967,27 @@ int FindNextCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam) { pPortParam->SerialCmdidx = -2; pPortParam->sendptzstatecmd = 0; - strcpy(szbuf, "云台未接或故障!结束通知!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台未接或故障!结束通知!"); return -1; } MakePtzStateQueryCommand(pPortParam, cmdidx); return 1; case QUERY_PTZ_STATE: /* 查询云台状态信息*/ - //::memset(szbuf, 0, sizeof(szbuf)); - //sprintf(szbuf, "下发命令sendptzstatecmd=%d!", pPortParam->sendptzstatecmd); - //DebugLog(0, szbuf, 'I'); + //DebugLog(0, 'I', "下发命令sendptzstatecmd=%d!", pPortParam->sendptzstatecmd); //if (pPortParam->sendptzstatecmd > 0) #if 1 if (pPortParam->sendptzstatecmd == 0) { pPortParam->sendptzstatecmd++; cmdidx = 0x08; - //::memset(szbuf, 0, sizeof(szbuf)); - //sprintf(szbuf, "下发命令sendptzstatecmd=%d!", pPortParam->sendptzstatecmd); - //DebugLog(0, szbuf, 'I'); + //DebugLog(0, 'I', "下发命令sendptzstatecmd=%d!", pPortParam->sendptzstatecmd); } else #endif { pPortParam->SerialCmdidx = -2; pPortParam->sendptzstatecmd = 0; - strcpy(szbuf, "云台未接或故障!结束查询!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "云台未接或故障!结束查询!"); return -1; } //pPortParam->sendptzstatecmd++; @@ -2035,15 +2009,12 @@ int FindNextCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam) if (lcurtime - pPortParam->FirstCmdTimeCnt > 35 * 1000) { pPortParam->SerialCmdidx = -1; - sprintf(szbuf, "读取第%u包图片数据35秒未收到!结束拍照!", (uint32_t)packetsize); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "读取第%u包图片数据35秒未收到!结束拍照!", (uint32_t)packetsize); return -1; } break; } - //::memset(szbuf, 0, sizeof(szbuf)); - //strcpy(szbuf, "make:sendptzstatecmd"); - //DebugLog(0, szbuf, 'I'); + //DebugLog(0, 'I', "make:sendptzstatecmd"); MakeCameraPhotoCommand(pPortParam, cmdidx, imagesize, packetsize, imagequality, srdt.sendphototime); return 1; @@ -2056,13 +2027,10 @@ void MakeCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam, uint8_t cmdidx, in { int i, icurtime; u_char *sendbuf; - char szbuf[128]; sendbuf = pPortParam->PollCmd; - ::memset(szbuf, 0, sizeof(szbuf)); - strcpy(szbuf, "make:sendptzstatecmd start!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "make:sendptzstatecmd start!"); //return; icurtime = phototime; i = 0; @@ -2124,14 +2092,9 @@ void MakeCameraPhotoCommand(SIO_PARAM_SERIAL_DEF *pPortParam, uint8_t cmdidx, in sendbuf[4] = (uint8_t)(i - 10); pPortParam->cmdlen = i; #if 1 - //::memset(szbuf, 0, sizeof(szbuf)); - //strcpy(szbuf, "make over!"); - //DebugLog(0, szbuf, 'I'); if(0x08 == cmdidx) { - ::memset(szbuf, 0, sizeof(szbuf)); - strcpy(szbuf, "生成查询云台位置命令!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "生成查询云台位置命令!"); } #endif //return; @@ -2148,9 +2111,7 @@ void MakePtzStateQueryCommand(SIO_PARAM_SERIAL_DEF *pPortParam, uint8_t cmdidx) sendbuf = pPortParam->PollCmd; - //::memset(szbuf, 0, sizeof(szbuf)); - //strcpy(szbuf, "make:sendptzstatecmd start!"); - //DebugLog(0, szbuf, 'I'); + //DebugLog(0, 'I', "make:sendptzstatecmd start!"); i = 0; sendbuf[i++] = 0x00; /* 强制等待时间*/ sendbuf[i++] = 0x00; /* 强制等待时间*/ @@ -2167,14 +2128,10 @@ void MakePtzStateQueryCommand(SIO_PARAM_SERIAL_DEF *pPortParam, uint8_t cmdidx) sendbuf[4] = (uint8_t)(i - 10); pPortParam->cmdlen = i; #if 0 - //::memset(szbuf, 0, sizeof(szbuf)); - //strcpy(szbuf, "make over!"); - //DebugLog(0, szbuf, 'I'); + //DebugLog(0, 'I', "make over!"); if(0x08 == cmdidx) { - ::memset(szbuf, 0, sizeof(szbuf)); - strcpy(szbuf, "生成查询云台位置命令!"); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "生成查询云台位置命令!"); } #endif //return; @@ -2336,7 +2293,7 @@ void Gm_SendPelco_pCommand(uint32_t cmdtype) len = GM_SerialComSend(commandbuf, len, srdt.camerauseserial); if (len < 1) { - DebugLog(srdt.camerauseserial, "发送Pelco_p命令失败", 'E'); + DebugLog(srdt.camerauseserial, 'E', "发送Pelco_p命令失败"); } else { @@ -2385,7 +2342,7 @@ void Gm_SendPelco_DCommand(SIO_PARAM_SERIAL_DEF *pPortParam, uint32_t cmdtype) len = GM_CameraComSend(commandbuf, len, pPortParam->fd); if (len < 1) { - DebugLog(0, "发送Pelco_D命令失败", 'E'); + DebugLog(0, 'E', "发送Pelco_D命令失败"); } else { @@ -2695,8 +2652,7 @@ void ShxyProtocolDataProcess(int devno) //slantpntmsg[aipnt][0].AiState = 1; //if ((gDisSunRain & 0x20) == 0x20) { - sprintf(szbuf, "倾角ID:%d slantangle X=%0.3f ", devparam[devno].devaddr, fvalue); - //DebugLog(devparam[devno].commid, szbuf, 'V'); + // DebugLog(devparam[devno].commid, 'V', "倾角ID:%d slantangle X=%0.3f ", devparam[devno].devaddr, fvalue); } //XslantSec[aipnt][srdt.SectimesamplingCnt[0]] = (short)slantpntmsg[aipnt][0].EuValue; //srdt.SectimesamplingCnt[0] += 1; @@ -2707,8 +2663,7 @@ void ShxyProtocolDataProcess(int devno) *((uint8_t*)fvalua + 3) = curserial->m_au8RecvBuf[10]; //if ((gDisSunRain & 0x20) == 0x20) { - sprintf(szbuf, "%sY =%0.3f ", szbuf, fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "%sY =%0.3f ", szbuf, fvalue); } if ((fvalue < -59) || (fvalue > 59)) { @@ -2763,8 +2718,7 @@ void ShxyProtocolDataProcess(int devno) //g_SelfTest.SensorsFault |= (0x01); //if ((gDisSunRain & 0x80) == 0x80) { - sprintf(szbuf, "ID:%d 温度:%0.3f ", devparam[devno].devaddr, fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "ID:%d 温度:%0.3f ", devparam[devno].devaddr, fvalue); } break; case 2: /*气压*/ @@ -2786,8 +2740,7 @@ void ShxyProtocolDataProcess(int devno) //g_SelfTest.SensorsFault |= (0x10); //if ((gDisSunRain & 0x80) == 0x80) { - sprintf(szbuf, "气压:%0.3f ", fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "气压:%0.3f ", fvalue); } break; case 3: /*湿度*/ @@ -2809,8 +2762,7 @@ void ShxyProtocolDataProcess(int devno) //g_SelfTest.SensorsFault |= (0x02); //if ((gDisSunRain & 0x80) == 0x80) { - sprintf(szbuf, "湿度:%0.3f ", fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "湿度:%0.3f ", fvalue); } break; case 4: /*雨量*/ @@ -2830,8 +2782,7 @@ void ShxyProtocolDataProcess(int devno) //g_SelfTest.SensorsFault |= (0x02); //if ((gDisSunRain & 0x80) == 0x80) { - sprintf(szbuf, "雨量:%0.3f ", fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "雨量:%0.3f ", fvalue); } break; case 5: /*日照*/ @@ -2849,8 +2800,7 @@ void ShxyProtocolDataProcess(int devno) pPortParam->aiValue[OpticalRadiationNo].AiState = SER_SAMPLE; weatherpntmsg[OpticalRadiationNo].AiState = SER_SAMPLE; { - sprintf(szbuf, "日照:%0.3f ", fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "日照:%0.3f ", fvalue); } break; case 6: /*风速*/ @@ -2894,8 +2844,7 @@ void ShxyProtocolDataProcess(int devno) //g_SelfTest.SensorsFault |= (0x08); //if ((gDisSunRain & 0x10) == 0x10) { - sprintf(szbuf, "%s 风向:%0.3f ", szbuf, fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "%s 风向:%0.3f ", szbuf, fvalue); } break; case 8: /*拉力*/ @@ -2909,8 +2858,7 @@ void ShxyProtocolDataProcess(int devno) // +rallypntmsg[aipnt][0].AiParam.EuValueDelta; pPortParam->aiValue[0].AiState = SER_SAMPLE; //rallypntmsg[aipnt][0].AiState = 1; - sprintf(szbuf, "地址%d拉力:%0.3fKg ", devparam[devno].devaddr, fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "地址%d拉力:%0.3fKg ", devparam[devno].devaddr, fvalue); //} break; case 9: /*倾角传感器X轴倾角*/ @@ -2929,11 +2877,10 @@ void ShxyProtocolDataProcess(int devno) } pPortParam->aiValue[0].AiState = SER_SAMPLE; //slantpntmsg[aipnt][0].AiState = 1; - sprintf(szbuf, "倾角ID:%d slantangle X=%0.3f ", devparam[devno].devaddr, fvalue); + DebugLog(devparam[devno].commid, 'V', "倾角ID:%d slantangle X=%0.3f ", devparam[devno].devaddr, fvalue); break; case 10: /*倾角传感器Y轴倾角*/ - sprintf(szbuf, "%s Y =%0.3f ", szbuf, fvalue); - DebugLog(devparam[devno].commid, szbuf, 'V'); + DebugLog(devparam[devno].commid, 'V', "%s Y =%0.3f ", szbuf, fvalue); if ((fvalue < -59) || (fvalue > 59)) { @@ -2953,54 +2900,6 @@ void ShxyProtocolDataProcess(int devno) } } -void delete_old_files(const char *path, int days) -{ - struct stat file_stat; - struct tm *file_tm; - time_t now = time(NULL); - DIR *dir = opendir(path); - struct dirent *entry; - char szbuf[1024]; - char fullpath[256]; - - memset(szbuf, 0, sizeof(szbuf)); - if (!dir) - { - sprintf(szbuf, "delete_old_files opendir %s error ", path); - DebugLog(8, szbuf, 'E'); - return; - } - - while ((entry = readdir(dir))) - { - memset(szbuf, 0, sizeof(szbuf)); - if (entry->d_type == DT_REG) - { // 只处理普通文件 - snprintf(fullpath, sizeof(fullpath), "%s/%s", path, entry->d_name); - - if (stat(fullpath, &file_stat) == -1) - { - perror("stat"); - strcpy(szbuf, "stat"); - DebugLog(8, szbuf, 'E'); - continue; - } - - localtime_r(&(file_stat.st_mtime), file_tm); - //file_tm = localtime(&(file_stat.st_mtime)); - - if (difftime(now, mktime(file_tm)) > days * 24 * 60 * 60) - { - if (unlink(fullpath) == -1) - { // 删除文件 - perror("unlink"); - } - } - } - } - - closedir(dir); -} /********************************************************************************* 把16进制和10进制ASCII字符串转换成int整数 *********************************************************************************/ @@ -3101,16 +3000,14 @@ void Collect_sensor_data() } #endif #if 1 - pthread_mutex_lock(&serial_mutex); // 加锁 + static int ideletefile = 0; - char logbuf[64]; time_t now; struct tm t0; // const char *path = logPath; // 指定目录路径 // int days = 15; // 删除15天前的log文件 - sprintf(logbuf, "进入程序时间:%lld, ideletefile=%d", get_msec(), ideletefile); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "进入程序时间:%lld, ideletefile=%d", get_msec(), ideletefile); // now = time(NULL); // localtime_r(&now, &t0); @@ -3122,6 +3019,7 @@ void Collect_sensor_data() // if (0 < t0.tm_hour) // ideletefile = 0; #endif + pthread_mutex_lock(&serial_mutex); // 加锁 GM_StartSerialComm(); pthread_mutex_unlock(&serial_mutex); // 解锁 } @@ -3129,14 +3027,11 @@ void Collect_sensor_data() int Gm_SetCameraSerialPortParam(int fd, unsigned int baud) { int ret; - char szbuf[128]; ret = set_port_attr(fd, baud, 8, 1, 'n', 0, 0);/*9600 8n1 */ if (ret < 0) { - memset(szbuf, 0, sizeof(szbuf)); - strcpy(szbuf, "摄像机串口波特率等参数设置错误!"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "摄像机串口波特率等参数设置错误!"); return -1; } return ret; @@ -3145,42 +3040,34 @@ int Gm_SetCameraSerialPortParam(int fd, unsigned int baud) int Gm_OpenCameraSerial(SIO_PARAM_SERIAL_DEF *pPortParam, const char *serfile, unsigned int baud) { int fd = -1; - char szbuf[512]; unsigned int serbaud; - memset(szbuf, 0, sizeof(szbuf)); if (pPortParam->fd <= 0) { fd = ::open(serfile, O_RDWR | O_NDELAY); if (fd < 0) { - sprintf(szbuf, "摄像机串口%s打开失败!fd=%d", serfile, fd); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "摄像机串口%s打开失败!fd=%d", serfile, fd); return -1; } - sprintf(szbuf, "摄像机打开串口%s成功!fd=%d 波特率:%d", serfile, fd, baud); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "摄像机打开串口%s成功!fd=%d 波特率:%d", serfile, fd, baud); pPortParam->fd = fd; serbaud = getBaudrate(baud); Gm_SetCameraSerialPortParam(fd, serbaud); return 0; } - sprintf(szbuf, "摄像机串口%s已经打开!fd=%d", serfile, pPortParam->fd); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "摄像机串口%s已经打开!fd=%d", serfile, pPortParam->fd); return 0; } int GM_CameraComSend(unsigned char * cSendBuf, size_t nSendLen, int fd) { int i, len; - char szbuf[512]; - memset(szbuf, 0, sizeof(szbuf)); len = write(fd, cSendBuf, (size_t)nSendLen);/* 向串囗发送字符串 */ if (len < 0) { - strcpy(szbuf, "write data error "); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "write data error "); return -1; } else if (len > 0) @@ -3208,8 +3095,7 @@ void SendCameraCmdFormPollCmdBuf(SIO_PARAM_SERIAL_DEF *pPortParam) if (pPortParam->SendCmdFlag && (pPortParam->RevCmdFlag == 0)) { //pPortParam->RetryTimeCnt++; - //strcpy(szbuf, "1-send"); - //DebugLog(0, szbuf, 'E'); + //DebugLog(0, 'E', "1-send"); if ((lctime - pPortParam->RetryTimeCnt > 3 * pPortParam->RetryTime) || (lctime - pPortParam->RetryTimeCnt < 0)) { @@ -3236,8 +3122,7 @@ void SendCameraCmdFormPollCmdBuf(SIO_PARAM_SERIAL_DEF *pPortParam) if (pPortParam->SendCmdFlag && pPortParam->RevCmdFlag) { - //strcpy(szbuf, "2-send"); - //DebugLog(0, szbuf, 'E'); + //DebugLog(0, 'E', "2-send"); // 清除当前命令 ClearCameraCmdFormPollCmdBuf(pPortParam); } @@ -3274,16 +3159,13 @@ void SendCameraCmdFormPollCmdBuf(SIO_PARAM_SERIAL_DEF *pPortParam) len = GM_CameraComSend(&pPortParam->PollCmd[2], pPortParam->cmdlen - 2, pPortParam->fd); if (len < 1) { - strcpy(buf, "摄像机串口, 发送命令失败!"); - DebugLog(0, buf, 'E'); + DebugLog(0, 'E', "摄像机串口, 发送命令失败!"); } else { - strcpy(buf, "摄像机串口命令:"); BytestreamLOG(0, buf, &pPortParam->PollCmd[2], len, 'D'); - sprintf(buf, "sendtimeconst= %lld", (long long)(lctime - pPortParam->lsendtime)); - DebugLog(0, buf, 'W'); + DebugLog(0, 'W', "sendtimeconst= %lld", (long long)(lctime - pPortParam->lsendtime)); pPortParam->lsendtime = lctime; } pPortParam->SendCmdFlag = 1; @@ -3319,19 +3201,16 @@ void Gm_FindCameraCommand(SIO_PARAM_SERIAL_DEF *pPortParam) int GM_IsCloseCamera(SIO_PARAM_SERIAL_DEF *pPortParam) { int i, j; - char buf[256]; int64_t lctime; lctime = get_msec(); - memset(buf, 0, sizeof(buf)); if (0 > pPortParam->SerialCmdidx) { if ((SER_STARTSAMPLE == pPortParam->image.state) || (SER_SAMPLE == pPortParam->image.state)) pPortParam->image.state = SER_SAMPLEFAIL; else if (PHOTO_SAVE_SUCC == pPortParam->image.state) pPortParam->image.state = PHOTO_SAVE_SUCC; - strcpy(buf, "摄像机使用完毕!可以关闭摄像机电源!"); - DebugLog(0, buf, 'I'); + DebugLog(0, 'I', "摄像机使用完毕!可以关闭摄像机电源!"); memset(&serialport[0].image, 0, sizeof(PHOTO_DEF)); memmove((void *)&serialport[0].image, (void*)&pPortParam->image, sizeof(PHOTO_DEF)); if(pPortParam->fd >= 0) @@ -3433,8 +3312,7 @@ int GM_StartSerialCameraPhoto(int phototime, unsigned char channel, int cmdidx, //flag = 1; //if (1 == srdt.ms_dev[i].IsNeedSerial) //{ - //sprintf(logbuf, "装置%d, IsNoInsta=%d, 类型:%s", i + 1, devparam[i].IsNoInsta, szbuf); - //DebugLog(8, logbuf, 'I'); + //DebugLog(8, 'I', "装置%d, IsNoInsta=%d, 类型:%s", i + 1, devparam[i].IsNoInsta, szbuf); //Gm_OpenSensorsPower(); //Gm_OpenCameraSerial(&cameraport); //} @@ -3452,8 +3330,7 @@ int GM_StartSerialCameraPhoto(int phototime, unsigned char channel, int cmdidx, if (0x00 == flag) { - sprintf(szbuf, "摄像机启动串口定时器!"); - DebugLog(8, szbuf, 'I'); + DebugLog(0, 'I', "摄像机启动串口定时器!"); for (;;) { usleep(10); @@ -3461,7 +3338,7 @@ int GM_StartSerialCameraPhoto(int phototime, unsigned char channel, int cmdidx, //polltime = get_msec(); if (GM_CameraSerialTimer(cameraport) < 0) { - DebugLog(8, "退出操作摄像机流程!", 'V'); + DebugLog(8, 'V', "退出操作摄像机流程!"); //sleep(3); break; } @@ -3478,8 +3355,8 @@ int GM_StartSerialCameraPhoto(int phototime, unsigned char channel, int cmdidx, int CameraPhotoCmd(int phototime, unsigned char channel, int cmdidx, unsigned char bImageSize, unsigned char presetno, const char *serfile, unsigned int baud, int addr) { + int flag = 0; pthread_mutex_lock(&camera_mutex); - int flag = 0; srdt.bImageSize = bImageSize; srdt.presetno = presetno; @@ -3492,7 +3369,7 @@ int CameraPhotoCmd(int phototime, unsigned char channel, int cmdidx, unsigned ch int QueryPtzState(PTZ_STATE *ptz_state, int cmdidx, const char *serfile, unsigned int baud, int addr) { int flag = 0; - char szbuf[128], logbuf[128]; + char logbuf[128]; SIO_PARAM_SERIAL_DEF *cameraport=NULL; if(NULL == ptz_state) @@ -3522,7 +3399,6 @@ int QueryPtzState(PTZ_STATE *ptz_state, int cmdidx, const char *serfile, unsign flag = Gm_OpenCameraSerial(cameraport, serfile, baud); #if 1 - memset(szbuf, 0, sizeof(szbuf)); srdt.iLastGetPhotoNo = -1; cameraport->SerialCmdidx = cmdidx; cameraport->FirstCmdTimeCnt = get_msec(); @@ -3541,11 +3417,8 @@ int QueryPtzState(PTZ_STATE *ptz_state, int cmdidx, const char *serfile, unsign if (0x00 == flag) { - ::memset(szbuf, 0, sizeof(szbuf)); - strcpy(szbuf, "云台状态查询启动串口定时器!"); - DebugLog(8, szbuf, 'I'); - //sprintf(szbuf, "下发命令sendptzstatecmd=%d!", cameraport->sendptzstatecmd); - //DebugLog(0, szbuf, 'I'); + DebugLog(8, 'I', "云台状态查询启动串口定时器!"); + //DebugLog(0, 'I', "下发命令sendptzstatecmd=%d!", cameraport->sendptzstatecmd); for (;;) { usleep(10); @@ -3554,7 +3427,7 @@ int QueryPtzState(PTZ_STATE *ptz_state, int cmdidx, const char *serfile, unsign flag = GM_CameraSerialTimer(cameraport); if (flag < 0) { - DebugLog(8, "退出查询云台状态流程!", 'V'); + DebugLog(8, 'V', "退出查询云台状态流程!"); memmove((void*)ptz_state, &cameraport->ptz_state, sizeof(PTZ_STATE)); if(flag == -2) flag = -1; @@ -3576,14 +3449,12 @@ int QueryPtzState(PTZ_STATE *ptz_state, int cmdidx, const char *serfile, unsign int Query_BDGNSS_Data(BD_GNSS_DATA *BD_data, int samptime, const char *serfile, unsigned int baud) { - pthread_mutex_lock(&bd_mutex); int flag = 0; - char szbuf[128], logbuf[128]; - SIO_PARAM_SERIAL_DEF *cameraport=NULL; + char logbuf[128]; + SIO_PARAM_SERIAL_DEF *cameraport = NULL; if(NULL == BD_data) { - pthread_mutex_unlock(&bd_mutex); return -1; } if(samptime < 5) @@ -3600,10 +3471,10 @@ int Query_BDGNSS_Data(BD_GNSS_DATA *BD_data, int samptime, const char *serfile, memset(cameraport->m_au8RecvBuf, 0, RECVDATA_MAXLENTH); // 接收数据缓存区 ClearCameraCmdFormPollCmdBuf(cameraport); + pthread_mutex_lock(&bd_mutex); flag = Gm_OpenCameraSerial(cameraport, serfile, baud); #if 1 - memset(szbuf, 0, sizeof(szbuf)); srdt.iLastGetPhotoNo = -1; cameraport->SerialCmdidx = -1; cameraport->FirstCmdTimeCnt = get_msec(); @@ -3615,13 +3486,13 @@ int Query_BDGNSS_Data(BD_GNSS_DATA *BD_data, int samptime, const char *serfile, free(cameraport); cameraport = NULL; } + pthread_mutex_unlock(&bd_mutex); // 解锁 return -1; } if (0x00 == flag) { - sprintf(szbuf, "北斗定位数据查询启动串口定时器!"); - DebugLog(8, szbuf, 'I'); + DebugLog(8, 'I', "北斗定位数据查询启动串口定时器!"); for (;;) { usleep(10); @@ -3630,7 +3501,7 @@ int Query_BDGNSS_Data(BD_GNSS_DATA *BD_data, int samptime, const char *serfile, flag = GM_BdSerialTimer(cameraport); if(get_msec() - cameraport->FirstCmdTimeCnt > samptime*1000) { - DebugLog(8, "退出查询北斗定位数据流程!", 'V'); + DebugLog(8, 'V', "退出查询北斗定位数据流程!"); memmove((void*)BD_data, &cameraport->bd_data, sizeof(BD_GNSS_DATA)); break; } @@ -3657,7 +3528,6 @@ void GM_BdSerialComRecv(SIO_PARAM_SERIAL_DEF *pPortParam) { int i, recvlen; u_char recvbuf[RECVDATA_MAXLENTH]; - char buf[RECVDATA_MAXLENTH+256]; int64_t t0, t1; t0 = get_msec(); @@ -3681,8 +3551,7 @@ void GM_BdSerialComRecv(SIO_PARAM_SERIAL_DEF *pPortParam) if (recvlen < 1) return; #if 1 - sprintf(buf, "收到BD, %d字节数据:%s", recvlen, recvbuf); - DebugLog(0, (char*)recvbuf, 'I'); + DebugLog(0, 'I', "收到BD, %d字节数据:%s", recvlen, recvbuf); #endif BdRecvData(pPortParam, recvbuf, recvlen); @@ -3816,16 +3685,14 @@ void BD_NMEA0183_PortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) {"$GPTXT",NULL},/* 用于天线状态检测*/ };/* irows*/ int i=0, irows; - char szbuf[512]; //char *cmd=NULL, *sourestr=NULL; //RTUMSG rtumsg; if(NULL == curserial) return; irows = sizeof(bd_nmea0183_call)/sizeof(BD_NMEA0183_PROC_FUNC); - memset(szbuf, 0, sizeof(szbuf)); - //sprintf(szbuf, "rows = %d", irows); - DebugLog(0, (char*)curserial->m_au8RecvBuf, 'I'); + + DebugLog(0, 'I', (char*)curserial->m_au8RecvBuf); #if 0 memset((void*)rtumsg.MsgData, 0, sizeof(rtumsg.MsgData)); @@ -3835,16 +3702,14 @@ void BD_NMEA0183_PortDataProcess(SIO_PARAM_SERIAL_DEF *curserial) cmd = (char *)rtumsg.MsgData; sourestr = strstr((char *)rtumsg.MsgData, ","); *sourestr = 0; - sprintf(szbuf, "cmd_len = %d, cmd:%s", strlen(cmd), cmd); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "cmd_len = %d, cmd:%s", strlen(cmd), cmd); #endif for(i=0; im_au8RecvBuf, bd_nmea0183_call[i].cmd_name)) { - sprintf(szbuf, "cmd_name[%d]:%s", i, bd_nmea0183_call[i].cmd_name); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "cmd_name[%d]:%s", i, bd_nmea0183_call[i].cmd_name); if(NULL != bd_nmea0183_call[i].recv_process) bd_nmea0183_call[i].recv_process(curserial); break; @@ -3918,12 +3783,10 @@ int BD_get_BDRMC_data(SIO_PARAM_SERIAL_DEF *curserial) ::memset(buffer, 0, sizeof(buffer)); // 使用 strftime 格式化时间 strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &curserial->bd_data.UTC_time); - DebugLog(0, (char*)buffer, 'I'); + DebugLog(0, 'I', (const char*)buffer); - ::sprintf(buffer, "ms:%d lat=%f ulat=%c", curserial->bd_data.ms_time, curserial->bd_data.lat, curserial->bd_data.uLat); - DebugLog(0, (char*)buffer, 'I'); - ::sprintf(buffer, "lon=%f ulon=%c, status=%c", curserial->bd_data.lon, curserial->bd_data.uLon, curserial->bd_data.status); - DebugLog(0, (char*)buffer, 'I'); + DebugLog(0, 'I', "ms:%d lat=%f ulat=%c", curserial->bd_data.ms_time, curserial->bd_data.lat, curserial->bd_data.uLat); + DebugLog(0, 'I', "lon=%f ulon=%c, status=%c", curserial->bd_data.lon, curserial->bd_data.uLon, curserial->bd_data.status); // 释放内存 for (int i = 0; i < total_fields; ++i) free(result[i]); @@ -3937,7 +3800,6 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) int max_fields, field_count = 0; char **fields = NULL, **new_fields = NULL, **result = NULL; char *copy = NULL, *p = NULL; - char szbuf[128]; if(NULL == str) return NULL; @@ -3946,11 +3808,9 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) // 创建可修改的副本 copy = strdup(str); - memset(szbuf, 0, sizeof(szbuf)); if (!copy) { - sprintf(szbuf, "内存分配失败\n"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "内存分配失败\n"); return NULL; } @@ -3959,8 +3819,7 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) fields = (char**)malloc(max_fields * sizeof(char *)); if (!fields) { free(copy); - sprintf(szbuf, "fields 内存分配失败\n"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "fields 内存分配失败\n"); return NULL; } @@ -3982,8 +3841,7 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) if (!new_fields) { free(fields); free(copy); - sprintf(szbuf, "new_fields 内存分配失败\n"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "new_fields 内存分配失败\n"); return NULL; } fields = new_fields; @@ -4000,8 +3858,7 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) { free(fields); free(copy); - sprintf(szbuf, "result 内存分配失败\n"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "result 内存分配失败\n"); return NULL; } @@ -4013,8 +3870,7 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) free(result); free(fields); free(copy); - sprintf(szbuf, "result 字段复制失败\n"); - DebugLog(0, szbuf, 'E'); + DebugLog(0, 'E', "result 字段复制失败\n"); return NULL; } } @@ -4022,8 +3878,7 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) // 输出结果到日志 for (int i = 0; i < *total_fields; ++i) { - sprintf(szbuf, "字段 %2d: %s\n", i + 1, result[i]); - DebugLog(0, szbuf, 'I'); + DebugLog(0, 'I', "字段 %2d: %s\n", i + 1, result[i]); } // 释放内存 @@ -4041,7 +3896,7 @@ char** BD_NMEA0183_SplitString(char *str, int *total_fields) int GetWeatherData(Data_DEF *data, int datano) { int i; - char logbuf[512], szbuf[128]; + char szbuf[32]; if (NULL == data) return -1; @@ -4077,8 +3932,7 @@ int GetWeatherData(Data_DEF *data, int datano) sprintf(szbuf, "未知"); break; } - sprintf(logbuf, "data_state=%d, %svalue=%0.3f", data->AiState, szbuf,data->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, %svalue=%0.3f", data->AiState, szbuf,data->EuValue); if ((SER_SAMPLEFAIL == data->AiState) || (SAMPLINGSUCCESS == data->AiState)) { weatherpntmsg[datano].AiState = SER_IDLE; @@ -4089,14 +3943,11 @@ int GetWeatherData(Data_DEF *data, int datano) int GetAirTempData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[AirTempNo].EuValue; airt->AiState = weatherpntmsg[AirTempNo].AiState; - sprintf(logbuf, "data_state=%d, 温度value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 温度value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[AirTempNo].AiState = SER_IDLE; @@ -4107,14 +3958,11 @@ int GetAirTempData(Data_DEF *airt) int GetHumidityData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[HumidityNo].EuValue; airt->AiState = weatherpntmsg[HumidityNo].AiState; - sprintf(logbuf, "data_state=%d, 湿度value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 湿度value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[HumidityNo].AiState = SER_IDLE; @@ -4125,14 +3973,11 @@ int GetHumidityData(Data_DEF *airt) int GetWindSpeedData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[WindSpeedNo].EuValue; airt->AiState = weatherpntmsg[WindSpeedNo].AiState; - sprintf(logbuf, "data_state=%d, 风速value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 风速value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[WindSpeedNo].AiState = SER_IDLE; @@ -4143,14 +3988,11 @@ int GetWindSpeedData(Data_DEF *airt) int GetWindDirectionData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[WindDirectionNo].EuValue; airt->AiState = weatherpntmsg[WindDirectionNo].AiState; - sprintf(logbuf, "data_state=%d, 风向value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 风向value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[WindDirectionNo].AiState = SER_IDLE; @@ -4161,14 +4003,11 @@ int GetWindDirectionData(Data_DEF *airt) int GetRainfallData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[RainfallNo].EuValue; airt->AiState = weatherpntmsg[RainfallNo].AiState; - sprintf(logbuf, "data_state=%d, 雨量value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 雨量value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[RainfallNo].AiState = SER_IDLE; @@ -4179,14 +4018,11 @@ int GetRainfallData(Data_DEF *airt) int GetAtmosData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[AtmosNo].EuValue; airt->AiState = weatherpntmsg[AtmosNo].AiState; - sprintf(logbuf, "data_state=%d, 大气压value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 大气压value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[AtmosNo].AiState = SER_IDLE; @@ -4197,14 +4033,11 @@ int GetAtmosData(Data_DEF *airt) int GetOpticalRadiationData(Data_DEF *airt) { - char logbuf[512]; - if (NULL == airt) return -1; airt->EuValue = weatherpntmsg[OpticalRadiationNo].EuValue; airt->AiState = weatherpntmsg[OpticalRadiationNo].AiState; - sprintf(logbuf, "data_state=%d, 日照value=%0.3f", airt->AiState, airt->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "data_state=%d, 日照value=%0.3f", airt->AiState, airt->EuValue); if ((SER_SAMPLEFAIL == airt->AiState) || (SAMPLINGSUCCESS == airt->AiState)) { weatherpntmsg[OpticalRadiationNo].AiState = SER_IDLE; @@ -4215,8 +4048,6 @@ int GetOpticalRadiationData(Data_DEF *airt) int GetPullValue(int devno, Data_DEF *data) { - char logbuf[512]; - if (NULL == data) return -1; if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno)) @@ -4225,8 +4056,7 @@ int GetPullValue(int devno, Data_DEF *data) return -1; data->EuValue = srdt.ms_dev[devno].aiValue[0].EuValue; data->AiState = srdt.ms_dev[devno].aiValue[0].AiState; - sprintf(logbuf, "装置%d, ID=%d, data_state=%d, 拉力value=%0.3f", devno + 1, devparam[devno].devaddr, data->AiState, data->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "装置%d, ID=%d, data_state=%d, 拉力value=%0.3f", devno + 1, devparam[devno].devaddr, data->AiState, data->EuValue); if ((SER_SAMPLEFAIL == data->AiState) || (SAMPLINGSUCCESS == data->AiState)) { srdt.ms_dev[devno].aiValue[0].AiState = SER_IDLE; @@ -4237,8 +4067,6 @@ int GetPullValue(int devno, Data_DEF *data) int GetAngleValue(int devno, Data_DEF *data, int Xy) { - char logbuf[512]; - if (NULL == data) return -1; if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno)) @@ -4250,8 +4078,7 @@ int GetAngleValue(int devno, Data_DEF *data, int Xy) data->EuValue = srdt.ms_dev[devno].aiValue[Xy].EuValue; data->AiState = srdt.ms_dev[devno].aiValue[Xy].AiState; - sprintf(logbuf, "装置%d, ID=%d, data_state=%d, 倾角value[%d]=%0.3f", devno + 1, devparam[devno].devaddr, data->AiState, Xy, data->EuValue); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "装置%d, ID=%d, data_state=%d, 倾角value[%d]=%0.3f", devno + 1, devparam[devno].devaddr, data->AiState, Xy, data->EuValue); if ((SER_SAMPLEFAIL == data->AiState) || (SAMPLINGSUCCESS == data->AiState)) { srdt.ms_dev[devno].aiValue[Xy].AiState = SER_IDLE; @@ -4262,8 +4089,6 @@ int GetAngleValue(int devno, Data_DEF *data, int Xy) int GetImage(int devno, IMAGE_DEF *photo) { - char logbuf[512]; - if (NULL == photo) return -1; photo->presetno = serialport[0].image.presetno; @@ -4273,8 +4098,7 @@ int GetImage(int devno, IMAGE_DEF *photo) photo->imagelen = serialport[0].image.imagelen; photo->state = serialport[0].image.state; - sprintf(logbuf, "装置%d, image_state=%d, 预置点:%d,拍照时间:%d, pic_name:%s", devno + 1, photo->state, photo->presetno, photo->phototime, photo->photoname); - DebugLog(8, logbuf, 'I'); + DebugLog(8, 'I', "装置%d, image_state=%d, 预置点:%d,拍照时间:%d, pic_name:%s", devno + 1, photo->state, photo->presetno, photo->phototime, photo->photoname); if ((SER_SAMPLEFAIL == photo->state) || (PHOTO_SAVE_SUCC == photo->state)) { serialport[0].image.state = SER_IDLE; diff --git a/app/src/main/cpp/SensorsProtocol.h b/app/src/main/cpp/SensorsProtocol.h index 0d7633ee..f2e745b7 100644 --- a/app/src/main/cpp/SensorsProtocol.h +++ b/app/src/main/cpp/SensorsProtocol.h @@ -392,7 +392,7 @@ void Gm_OpenSerialPort(int devidx); // 关闭串口通讯 void Gm_CloseSerialPort(); -void DebugLog(int commid, const char *szbuf, char flag); +void DBG_LOG(int commid, char flag, const char* format, ...); int SaveLogTofile(int commid, const char *szbuf); // 功能说明:串口发送数据 返回实际发送的字节数 int GM_SerialComSend(const unsigned char * cSendBuf, size_t nSendLen, int commid);