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