Matthew 7 months ago
parent a7e4fabe13
commit 2653290682

@ -706,10 +706,7 @@ char Gm_GetSensorsPowerState(int port)
void BytestreamLOG(int commid, char* describe, u_char* buf, int len, char flag) void BytestreamLOG(int commid, char* describe, u_char* buf, int len, char flag)
{ {
int i; int i;
// char szbuf[4096]; char szbuf[4096];
char* szbuf = new char[4096];
std::unique_ptr<char[]> bufptr(szbuf);
memset(szbuf, 0, sizeof(szbuf)); memset(szbuf, 0, sizeof(szbuf));
if (NULL != describe) if (NULL != describe)
@ -746,8 +743,7 @@ void BytestreamLOG(int commid, char* describe, u_char* buf, int len, char flag)
void Gm_OpenSerialPort(int devidx) void Gm_OpenSerialPort(int devidx)
{ {
int fd = -1; int fd = -1;
char* szbuf = new char[512]; char szbuf[512];
std::unique_ptr<char[]> bufptr(szbuf);
if ((devidx < 0) || (devidx >= MAX_SERIAL_DEV_NUM)) if ((devidx < 0) || (devidx >= MAX_SERIAL_DEV_NUM))
return; return;
@ -796,8 +792,7 @@ void Gm_CloseSerialPort()
int GM_SerialComSend(unsigned char * cSendBuf, size_t nSendLen, int commid) int GM_SerialComSend(unsigned char * cSendBuf, size_t nSendLen, int commid)
{ {
int i, len; int i, len;
char* szbuf = new char[512]; char szbuf[512];
std::unique_ptr<char[]> bufptr(szbuf);
memset(szbuf, 0, sizeof(szbuf)); memset(szbuf, 0, sizeof(szbuf));
len = write(serialport[commid].fd, cSendBuf, (size_t)nSendLen);/* 向串囗发送字符串 */ len = write(serialport[commid].fd, cSendBuf, (size_t)nSendLen);/* 向串囗发送字符串 */
@ -1705,9 +1700,7 @@ void GM_IsCloseSensors()
void GM_AllSerialComRecv() void GM_AllSerialComRecv()
{ {
int i, j, recvlen; int i, j, recvlen;
u_char* recvbuf = new u_char[RECVDATA_MAXLENTH]; u_char recvbuf[RECVDATA_MAXLENTH];
std::unique_ptr<u_char[]> recvbufptr(recvbuf);
char buf[256]; char buf[256];
for (j = 0; j < MAX_SERIAL_PORT_NUM; j++) for (j = 0; j < MAX_SERIAL_PORT_NUM; j++)
@ -1739,7 +1732,7 @@ void GM_AllSerialComRecv()
int GM_CloseTimer() int GM_CloseTimer()
{ {
int i, j, iretime; int i, j, iretime;
char buf[32]; char buf[256];
for (i = 0; i < MAX_SERIAL_DEV_NUM; i++) for (i = 0; i < MAX_SERIAL_DEV_NUM; i++)
{ {
@ -1817,17 +1810,7 @@ int SaveLogTofile(int commid, char *szbuf)
{ {
int status; int status;
time_t now; time_t now;
char filename[512], filedir[512], buf[128];
// char filename[512], filedir[512], buf[128];
char* filename = new char[512];
char* filedir = new char[512];
char* buf = new char[128];
std::unique_ptr<char[]> fnptr(filename);
std::unique_ptr<char[]> fdptr(filedir);
std::unique_ptr<char[]> bufptr(buf);
FILE *fp = NULL; FILE *fp = NULL;
struct tm t0; struct tm t0;
struct timeval tv; struct timeval tv;
@ -1873,7 +1856,7 @@ int SaveImageDataTofile(int devno)
u_char *image = NULL, *tempphoto = NULL; u_char *image = NULL, *tempphoto = NULL;
int i, status; int i, status;
size_t len; size_t len;
char szbuf[32]; char filename[512]/*, filedir[512]*/, szbuf[128];
FILE *fp = NULL; FILE *fp = NULL;
SERIAL_DEV_DEF *pPortParam; SERIAL_DEV_DEF *pPortParam;
@ -2725,11 +2708,11 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
//return 1; //return 1;
return Gm_Camera_Timer(); return Gm_Camera_Timer();
//return 1; //return 1;
} }
// 发送转动摄像机云台命令定时器 // 发送转动摄像机云台命令定时器
int Gm_Camera_Timer() int Gm_Camera_Timer()
{ {
char szbuf[128]; char szbuf[128];
if (PELCO_D_PROTOCOL == devparam[srdt.usecameradevidx].ProtocolIdx) if (PELCO_D_PROTOCOL == devparam[srdt.usecameradevidx].ProtocolIdx)
@ -2807,13 +2790,13 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
// srdt.SendStopPtzCmdTimeCnt ++; // srdt.SendStopPtzCmdTimeCnt ++;
//return -1; //return -1;
#endif #endif
} }
/******************************************************************************** /********************************************************************************
* PELCO_P * * PELCO_P *
*********************************************************************************/ *********************************************************************************/
void Gm_SendPelco_pCommand(uint32_t cmdtype) void Gm_SendPelco_pCommand(uint32_t cmdtype)
{ {
int len; int len;
uint8_t commandbuf[32]; uint8_t commandbuf[32];
char buf[128]; char buf[128];
@ -2845,10 +2828,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
BytestreamLOG(srdt.camerauseserial, buf, commandbuf, len, 'D'); BytestreamLOG(srdt.camerauseserial, buf, commandbuf, len, 'D');
} }
ClearCmdFormPollCmdBuf(srdt.camerauseserial); ClearCmdFormPollCmdBuf(srdt.camerauseserial);
} }
uint8_t Gm_Pelco_pXORCheck(uint8_t *msg, int len) uint8_t Gm_Pelco_pXORCheck(uint8_t *msg, int len)
{ {
int i; int i;
uint8_t checkvalue = 0; uint8_t checkvalue = 0;
@ -2858,13 +2841,13 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
for (i = 1; i < len; i++) for (i = 1; i < len; i++)
checkvalue ^= msg[i]; checkvalue ^= msg[i];
return checkvalue; return checkvalue;
} }
/******************************************************************************** /********************************************************************************
* PELCO_D * * PELCO_D *
*********************************************************************************/ *********************************************************************************/
void Gm_SendPelco_DCommand(uint32_t cmdtype) void Gm_SendPelco_DCommand(uint32_t cmdtype)
{ {
int len; int len;
uint8_t commandbuf[32]; uint8_t commandbuf[32];
char buf[128]; char buf[128];
@ -2896,11 +2879,11 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
ClearCmdFormPollCmdBuf(srdt.camerauseserial); ClearCmdFormPollCmdBuf(srdt.camerauseserial);
//serialport[srdt.camerauseserial].ForceWaitCnt = 10; //serialport[srdt.camerauseserial].ForceWaitCnt = 10;
//serialport[srdt.camerauseserial].ForceWaitFlag = 1; //serialport[srdt.camerauseserial].ForceWaitFlag = 1;
} }
// 计算Pelco_D校验 // 计算Pelco_D校验
uint8_t Gm_Pelco_DCheck(uint8_t *msg, int len) uint8_t Gm_Pelco_DCheck(uint8_t *msg, int len)
{ {
int i; int i;
uint8_t checkvalue = 0; uint8_t checkvalue = 0;
@ -2910,13 +2893,13 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
for (i = 1; i < len; i++) for (i = 1; i < len; i++)
checkvalue += msg[i]; checkvalue += msg[i];
return checkvalue; return checkvalue;
} }
/********************************************************************************* /*********************************************************************************
**********************************************************************************/ **********************************************************************************/
int FindNextShxyProtocolCommand(int devidx) int FindNextShxyProtocolCommand(int devidx)
{ {
int cmdno = 0; int cmdno = 0;
//如果命令缓冲区仍有命令,则退出本函数 //如果命令缓冲区仍有命令,则退出本函数
@ -2942,13 +2925,13 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
break; break;
} }
return -1; return -1;
} }
/********************************************************************************* /*********************************************************************************
**********************************************************************************/ **********************************************************************************/
void MakeShxyProtocolPollCommand(int portno, uint8_t cmdidx) void MakeShxyProtocolPollCommand(int portno, uint8_t cmdidx)
{ {
int i, length = 0; int i, length = 0;
int newaddr = 9, baud = 9600, stopbit = 1, parity = 0; int newaddr = 9, baud = 9600, stopbit = 1, parity = 0;
//char buf[128]; //char buf[128];
@ -2996,23 +2979,23 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
sendbuf[4] = length; sendbuf[4] = length;
sendbuf[i++] = 0x16; // 信息尾 sendbuf[i++] = 0x16; // 信息尾
serialport[devparam[portno].commid].cmdlen = i; serialport[devparam[portno].commid].cmdlen = i;
} }
unsigned char CalLpc(unsigned char *msg, int len) unsigned char CalLpc(unsigned char *msg, int len)
{ {
int i; int i;
u_char retval = 0; u_char retval = 0;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
retval += msg[i]; retval += msg[i];
return retval; return retval;
} }
/*************************************************************** /***************************************************************
* * * *
***************************************************************/ ***************************************************************/
void ShxyProtocolRecvData(int devno, u_char *buf, int len)// 规约读数据处理 void ShxyProtocolRecvData(int devno, u_char *buf, int len)// 规约读数据处理
{ {
int i, ictime; int i, ictime;
//uint16_t crc, check; //uint16_t crc, check;
//SERIAL_DEV_DEF *pPortParam; //SERIAL_DEV_DEF *pPortParam;
@ -3106,13 +3089,13 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
break; break;
} }
} }
} }
//******************************************************************************** //********************************************************************************
// 检查检验和是否正确 // 检查检验和是否正确
//******************************************************************************** //********************************************************************************
int CheckShxyProtocolLpcError(u_char* msg, int len) int CheckShxyProtocolLpcError(u_char* msg, int len)
{ {
int bRetval = 0; int bRetval = 0;
int iCheckLen; int iCheckLen;
@ -3130,13 +3113,13 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
bRetval = 1; bRetval = 1;
} }
return bRetval; return bRetval;
} }
/********************************************************************************* /*********************************************************************************
**********************************************************************************/ **********************************************************************************/
void ShxyProtocolDataProcess(int devno) void ShxyProtocolDataProcess(int devno)
{ {
float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/; float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/;
uint16_t uDevAddr; uint16_t uDevAddr;
uint8_t cmdidx; uint8_t cmdidx;
@ -3402,17 +3385,16 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
} }
} }
} }
void delete_old_files(const char *path, int days) void delete_old_files(const char *path, int days)
{ {
struct stat file_stat; struct stat file_stat;
struct tm *file_tm; struct tm *file_tm;
time_t now = time(NULL); time_t now = time(NULL);
DIR *dir = opendir(path); DIR *dir = opendir(path);
struct dirent *entry; struct dirent *entry;
char* szbuf = new char[1024]; char szbuf[1024];
std::unique_ptr<char[]> szbufptr(szbuf);
char fullpath[256]; char fullpath[256];
memset(szbuf, 0, sizeof(szbuf)); memset(szbuf, 0, sizeof(szbuf));
@ -3452,12 +3434,12 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
} }
closedir(dir); closedir(dir);
} }
/********************************************************************************* /*********************************************************************************
1610ASCIIint 1610ASCIIint
*********************************************************************************/ *********************************************************************************/
int ATOI(char *buf) int ATOI(char *buf)
{ {
int i, ilen, iRetVal; int i, ilen, iRetVal;
if (NULL == buf) if (NULL == buf)
@ -3483,10 +3465,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
iRetVal = atoi(buf); iRetVal = atoi(buf);
} }
return iRetVal; return iRetVal;
} }
#if 0 #if 0
// 控制关闭传感器电源 // 控制关闭传感器电源
void Gm_CtrlCloseSensorsPower(int devidx) void Gm_CtrlCloseSensorsPower(int devidx)
{ {
if ((devidx < 0) || (devidx > MAX_SERIAL_DEV_NUM - 1)) if ((devidx < 0) || (devidx > MAX_SERIAL_DEV_NUM - 1))
@ -3520,19 +3502,19 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
} }
#endif #endif
int GeneratingRandomNumber(void) int GeneratingRandomNumber(void)
{ {
int ictime, randomdate; int ictime, randomdate;
/* 生成随机数n-m -> rand()%(m-n+1)+n*/ /* 生成随机数n-m -> rand()%(m-n+1)+n*/
ictime = (int)time(NULL); ictime = (int)time(NULL);
srand((uint32_t)ictime); srand((uint32_t)ictime);
randomdate = rand(); randomdate = rand();
return randomdate; return randomdate;
} }
/* 串口启动接口函数 开始*/ /* 串口启动接口函数 开始*/
void Collect_sensor_data() void Collect_sensor_data()
{ {
#if 0 #if 0
int i; int i;
@ -3570,10 +3552,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
ideletefile = 0; ideletefile = 0;
#endif #endif
GM_StartSerialComm(); GM_StartSerialComm();
} }
void CameraPhotoCmd(int phototime, u_char channel, int cmdidx, u_char bImageSize, u_char presetno) void CameraPhotoCmd(int phototime, u_char channel, int cmdidx, u_char bImageSize, u_char presetno)
{ {
#if 0 #if 0
int i; int i;
//speed_t baudrate; //speed_t baudrate;
@ -3609,12 +3591,12 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
srdt.presetno = presetno; srdt.presetno = presetno;
srdt.sendphototime = phototime; srdt.sendphototime = phototime;
GM_StartSerialCameraPhoto(1, cmdidx); GM_StartSerialCameraPhoto(1, cmdidx);
} }
/* 串口启动接口函数 结束*/ /* 串口启动接口函数 结束*/
/* 数据和图片采集数据返回函数 开始*/ /* 数据和图片采集数据返回函数 开始*/
int GetWeatherData(Data_DEF *data, int datano) int GetWeatherData(Data_DEF *data, int datano)
{ {
int i; int i;
if (NULL == data) if (NULL == data)
@ -3629,10 +3611,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetAirTempData(Data_DEF *airt) int GetAirTempData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[AirTempNo].EuValue; airt->EuValue = weatherpntmsg[AirTempNo].EuValue;
@ -3643,10 +3625,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetHumidityData(Data_DEF *airt) int GetHumidityData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[HumidityNo].EuValue; airt->EuValue = weatherpntmsg[HumidityNo].EuValue;
@ -3657,10 +3639,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetWindSpeedData(Data_DEF *airt) int GetWindSpeedData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[WindSpeedNo].EuValue; airt->EuValue = weatherpntmsg[WindSpeedNo].EuValue;
@ -3671,10 +3653,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetWindDirectionData(Data_DEF *airt) int GetWindDirectionData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[WindDirectionNo].EuValue; airt->EuValue = weatherpntmsg[WindDirectionNo].EuValue;
@ -3685,10 +3667,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetRainfallData(Data_DEF *airt) int GetRainfallData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[RainfallNo].EuValue; airt->EuValue = weatherpntmsg[RainfallNo].EuValue;
@ -3699,10 +3681,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetAtmosData(Data_DEF *airt) int GetAtmosData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[AtmosNo].EuValue; airt->EuValue = weatherpntmsg[AtmosNo].EuValue;
@ -3713,10 +3695,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetOpticalRadiationData(Data_DEF *airt) int GetOpticalRadiationData(Data_DEF *airt)
{ {
if (NULL == airt) if (NULL == airt)
return -1; return -1;
airt->EuValue = weatherpntmsg[OpticalRadiationNo].EuValue; airt->EuValue = weatherpntmsg[OpticalRadiationNo].EuValue;
@ -3727,10 +3709,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetPullValue(int devno, Data_DEF *data) int GetPullValue(int devno, Data_DEF *data)
{ {
if (NULL == data) if (NULL == data)
return -1; return -1;
if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno)) if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno))
@ -3745,10 +3727,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetAngleValue(int devno, Data_DEF *data, int Xy) int GetAngleValue(int devno, Data_DEF *data, int Xy)
{ {
if (NULL == data) if (NULL == data)
return -1; return -1;
if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno)) if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno))
@ -3766,10 +3748,10 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
int GetImage(int devno, IMAGE_DEF *photo) int GetImage(int devno, IMAGE_DEF *photo)
{ {
if (NULL == photo) if (NULL == photo)
return -1; return -1;
if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno)) if ((0 > devno) || (MAX_SERIAL_DEV_NUM < devno))
@ -3788,5 +3770,5 @@ int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
return 2; return 2;
} }
return 1; return 1;
} }
/* 数据和图片采集数据返回函数 结束*/ /* 数据和图片采集数据返回函数 结束*/
Loading…
Cancel
Save