|
|
@ -19,12 +19,15 @@
|
|
|
|
#include <asm/termbits.h>
|
|
|
|
#include <asm/termbits.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "GPIOControl.h"
|
|
|
|
#include "GPIOControl.h"
|
|
|
|
#include "serialComm.h"
|
|
|
|
#include "SerialComm.h"
|
|
|
|
#include "SensorsProtocol.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "SensorsProtocol.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <AndroidHelper.h>
|
|
|
|
|
|
|
|
#include <Client/SensorsProtocol.h>
|
|
|
|
//#include "Eint.h"
|
|
|
|
//#include "Eint.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
SIO_PARAM_SERIAL_DEF serialport[MAX_SERIAL_PORT_NUM];
|
|
|
|
SIO_PARAM_SERIAL_DEF serialport[MAX_SERIAL_PORT_NUM];
|
|
|
|
SERIAL_PARAM devparam[MAX_SERIAL_DEV_NUM];
|
|
|
|
SERIAL_PARAM devparam[MAX_SERIAL_DEV_NUM];
|
|
|
|
SRDT_DEF srdt;
|
|
|
|
SRDT_DEF srdt;
|
|
|
@ -93,7 +96,7 @@ static void setCam3V3Enable(bool enabled)
|
|
|
|
static void PortDataProcess(void)
|
|
|
|
static void PortDataProcess(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/;
|
|
|
|
float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/;
|
|
|
|
//WORD uDevAddr;
|
|
|
|
//uint16_t uDevAddr;
|
|
|
|
unsigned char cmdidx;
|
|
|
|
unsigned char cmdidx;
|
|
|
|
int i, j, aipnt, datanum;
|
|
|
|
int i, j, aipnt, datanum;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
@ -203,7 +206,7 @@ static void PortDataProcess( void )
|
|
|
|
static void RecvData(u_char *buf, int len)// 规约读数据处理
|
|
|
|
static void RecvData(u_char *buf, int len)// 规约读数据处理
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, ictime;
|
|
|
|
int i, ictime;
|
|
|
|
//WORD crc, check;
|
|
|
|
//uint16_t crc, check;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
|
|
|
|
|
|
|
|
pPortParam = &serialport;
|
|
|
|
pPortParam = &serialport;
|
|
|
@ -304,12 +307,12 @@ static void RecvData(u_char *buf, int len)// 规约读数据处理
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static LONG get_msec(void )
|
|
|
|
static int64_t get_msec(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
LONG time_in_msec = tv.tv_sec * 1000 + tv.tv_usec/1000;
|
|
|
|
int64_t time_in_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
|
|
|
|
|
|
|
|
return time_in_msec;
|
|
|
|
return time_in_msec;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -319,7 +322,7 @@ static int weather_comm(SERIAL_PARAM weatherport)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
int fd = -1;
|
|
|
|
int len, i, ret, icnt = 0;
|
|
|
|
int len, i, ret, icnt = 0;
|
|
|
|
LONG ictime, iruntime, isendtime, irecvtime;
|
|
|
|
int64_t ictime, iruntime, isendtime, irecvtime;
|
|
|
|
unsigned char sendbuf[] = { 0x68,0x00,0x00,0x68,0x01,0x09,0x0a,0x16 };
|
|
|
|
unsigned char sendbuf[] = { 0x68,0x00,0x00,0x68,0x01,0x09,0x0a,0x16 };
|
|
|
|
char recvbuf[256], szbuf[512];
|
|
|
|
char recvbuf[256], szbuf[512];
|
|
|
|
//char serial_description[] = "/dev/ttyS0";
|
|
|
|
//char serial_description[] = "/dev/ttyS0";
|
|
|
@ -400,7 +403,8 @@ static int weather_comm(SERIAL_PARAM weatherport)
|
|
|
|
if (len < 0) {
|
|
|
|
if (len < 0) {
|
|
|
|
LOGE("write data error \n");
|
|
|
|
LOGE("write data error \n");
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
memset(szbuf, 0, sizeof(szbuf));
|
|
|
|
memset(szbuf, 0, sizeof(szbuf));
|
|
|
|
sprintf(szbuf, "Send:");
|
|
|
|
sprintf(szbuf, "Send:");
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
@ -470,7 +474,7 @@ int serial_port_comm()
|
|
|
|
//struct timeval tv;
|
|
|
|
//struct timeval tv;
|
|
|
|
|
|
|
|
|
|
|
|
//gettimeofday(&tv, NULL);
|
|
|
|
//gettimeofday(&tv, NULL);
|
|
|
|
//LONG time_in_microseconds = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
//int64_t time_in_microseconds = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
|
|
|
|
|
|
|
|
//LOGE("Current time in microseconds: %ld\n", time_in_microseconds);
|
|
|
|
//LOGE("Current time in microseconds: %ld\n", time_in_microseconds);
|
|
|
|
|
|
|
|
|
|
|
@ -529,10 +533,10 @@ static speed_t getBaudrate(unsigned int baudrate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static LONG get_msec()
|
|
|
|
static int64_t get_msec()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
struct timeval tv;
|
|
|
|
LONG time_in_msec=0;
|
|
|
|
int64_t time_in_msec = 0;
|
|
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
time_in_msec = tv.tv_sec;
|
|
|
|
time_in_msec = tv.tv_sec;
|
|
|
@ -703,22 +707,22 @@ void BytestreamLOG(int commid, char* describe, u_char* buf, int len, char flag)
|
|
|
|
switch (flag)
|
|
|
|
switch (flag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 'E':
|
|
|
|
case 'E':
|
|
|
|
LOGE("%s", szbuf);
|
|
|
|
ALOGE("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
case 'I':
|
|
|
|
LOGI("%s", szbuf);
|
|
|
|
ALOGI("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'D':
|
|
|
|
LOGD("%s", szbuf);
|
|
|
|
ALOGD("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
case 'V':
|
|
|
|
LOGV("%s", szbuf);
|
|
|
|
ALOGI("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
case 'W':
|
|
|
|
LOGW("%s", szbuf);
|
|
|
|
ALOGW("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
LOGI("%s", szbuf);
|
|
|
|
ALOGI("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -767,13 +771,13 @@ void Gm_CloseSerialPort()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
/*******************************************************************************
|
|
|
|
函数名称: int GM_SerialComSend(const BYTE * cSendBuf, DWORD nSendLen, int commid)
|
|
|
|
函数名称: int GM_SerialComSend(const uint8_t * cSendBuf, uint32_t nSendLen, int commid)
|
|
|
|
功能说明:串口发送数据 返回实际发送的字节数
|
|
|
|
功能说明:串口发送数据 返回实际发送的字节数
|
|
|
|
输入参数:
|
|
|
|
输入参数:
|
|
|
|
输出参数:
|
|
|
|
输出参数:
|
|
|
|
其它说明:
|
|
|
|
其它说明:
|
|
|
|
*********************************************************************************/
|
|
|
|
*********************************************************************************/
|
|
|
|
int GM_SerialComSend(unsigned char * cSendBuf, LONG nSendLen, int commid)
|
|
|
|
int GM_SerialComSend(unsigned char * cSendBuf, size_t nSendLen, int commid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
int i, len;
|
|
|
|
char szbuf[512];
|
|
|
|
char szbuf[512];
|
|
|
@ -1077,8 +1081,9 @@ void Gm_InitSerialComm(SENSOR_PARAM *sensorParam, char *filedir)
|
|
|
|
if (NULL == filedir)
|
|
|
|
if (NULL == filedir)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
memset(srdt.filedir, 0, sizeof(srdt.filedir));
|
|
|
|
memset(srdt.filedir, 0, sizeof(srdt.filedir));
|
|
|
|
memmove(srdt.filedir, filedir, MIN(sizeof(srdt.filedir), strlen(filedir)));
|
|
|
|
memmove(srdt.filedir, filedir, std::min(sizeof(srdt.filedir), strlen(filedir)));
|
|
|
|
FindDevUseSerialCommNo();
|
|
|
|
FindDevUseSerialCommNo();
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#if 0
|
|
|
|
//Collect_sensor_data();
|
|
|
|
//Collect_sensor_data();
|
|
|
|
//#else
|
|
|
|
//#else
|
|
|
@ -1258,7 +1263,7 @@ void GM_StartSerialComm()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, j, commid;
|
|
|
|
int i, j, commid;
|
|
|
|
char szbuf[64], logbuf[128];
|
|
|
|
char szbuf[64], logbuf[128];
|
|
|
|
//LONG polltime=0;
|
|
|
|
//int64_t polltime=0;
|
|
|
|
|
|
|
|
|
|
|
|
// 此处不能对轮询设备标识清零,否则如果先起摄像机,就会导致poll乱掉
|
|
|
|
// 此处不能对轮询设备标识清零,否则如果先起摄像机,就会导致poll乱掉
|
|
|
|
//memset((void*)srdt.curdevidx, 0, sizeof(srdt.curdevidx));
|
|
|
|
//memset((void*)srdt.curdevidx, 0, sizeof(srdt.curdevidx));
|
|
|
@ -1407,7 +1412,7 @@ void GM_StartSerialComm()
|
|
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
#if 1
|
|
|
|
// 启动使用串口拍照
|
|
|
|
// 启动使用串口拍照
|
|
|
|
void GM_StartSerialCameraPhoto(BYTE channel, int cmdidx)
|
|
|
|
void GM_StartSerialCameraPhoto(uint8_t channel, int cmdidx)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, flag = 0;
|
|
|
|
int i, flag = 0;
|
|
|
|
char szbuf[128], logbuf[128];
|
|
|
|
char szbuf[128], logbuf[128];
|
|
|
@ -1613,7 +1618,7 @@ void GM_IsCloseSensors()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int i, j;
|
|
|
|
char buf[256];
|
|
|
|
char buf[256];
|
|
|
|
LONG lctime;
|
|
|
|
int64_t lctime;
|
|
|
|
|
|
|
|
|
|
|
|
lctime = get_msec();
|
|
|
|
lctime = get_msec();
|
|
|
|
for (i = 0; i < MAX_SERIAL_DEV_NUM; i++)
|
|
|
|
for (i = 0; i < MAX_SERIAL_DEV_NUM; i++)
|
|
|
@ -1768,22 +1773,22 @@ void DebugLog(int commid, char *szbuf, char flag)
|
|
|
|
switch (flag)
|
|
|
|
switch (flag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 'E':
|
|
|
|
case 'E':
|
|
|
|
LOGE("%s", szbuf);
|
|
|
|
ALOGE("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
case 'I':
|
|
|
|
LOGI("%s", szbuf);
|
|
|
|
ALOGI("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'D':
|
|
|
|
LOGD("%s", szbuf);
|
|
|
|
ALOGD("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
case 'V':
|
|
|
|
LOGV("%s", szbuf);
|
|
|
|
ALOGI("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
case 'W':
|
|
|
|
LOGW("%s", szbuf);
|
|
|
|
ALOGW("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
LOGI("%s", szbuf);
|
|
|
|
ALOGI("%s", szbuf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1992,8 +1997,8 @@ void CameraPhotoPortDataProcess( int devno)
|
|
|
|
SIO_PARAM_SERIAL_DEF *curserial;
|
|
|
|
SIO_PARAM_SERIAL_DEF *curserial;
|
|
|
|
int img_file_size, packetnum, iNo, packsize, i = 0, presetno, iphototime, pidx;
|
|
|
|
int img_file_size, packetnum, iNo, packsize, i = 0, presetno, iphototime, pidx;
|
|
|
|
char szbuf[128];
|
|
|
|
char szbuf[128];
|
|
|
|
WORD uDevAddr;
|
|
|
|
uint16_t uDevAddr;
|
|
|
|
BYTE cmdidx, recvend;
|
|
|
|
uint8_t cmdidx, recvend;
|
|
|
|
|
|
|
|
|
|
|
|
pPortParam = &srdt.ms_dev[devno];
|
|
|
|
pPortParam = &srdt.ms_dev[devno];
|
|
|
|
curserial = &serialport[devparam[devno].commid];
|
|
|
|
curserial = &serialport[devparam[devno].commid];
|
|
|
@ -2189,7 +2194,7 @@ void SendCmdFormPollCmdBuf( int port )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
char buf[128];
|
|
|
|
int len, ret;
|
|
|
|
int len, ret;
|
|
|
|
LONG lctime;
|
|
|
|
int64_t lctime;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
|
|
|
|
|
|
|
|
pPortParam = &serialport[port];
|
|
|
|
pPortParam = &serialport[port];
|
|
|
@ -2329,10 +2334,10 @@ void ClearCmdFormPollCmdBuf(int port)
|
|
|
|
int FindNextCameraPhotoCommand(int devidx)
|
|
|
|
int FindNextCameraPhotoCommand(int devidx)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int imagesize = 3, cmdno;
|
|
|
|
int imagesize = 3, cmdno;
|
|
|
|
BYTE channel, imagequality=90, presetno;
|
|
|
|
uint8_t channel, imagequality = 90, presetno;
|
|
|
|
WORD packetsize;
|
|
|
|
uint16_t packetsize;
|
|
|
|
LONG lcurtime;
|
|
|
|
int64_t lcurtime;
|
|
|
|
BYTE cmdidx=0x10;
|
|
|
|
uint8_t cmdidx = 0x10;
|
|
|
|
char szbuf[128];
|
|
|
|
char szbuf[128];
|
|
|
|
|
|
|
|
|
|
|
|
//如果命令缓冲区仍有命令,则退出本函数
|
|
|
|
//如果命令缓冲区仍有命令,则退出本函数
|
|
|
@ -2377,7 +2382,7 @@ int FindNextCameraPhotoCommand(int devidx)
|
|
|
|
memset(szbuf, 0, sizeof(szbuf));
|
|
|
|
memset(szbuf, 0, sizeof(szbuf));
|
|
|
|
sprintf(szbuf, "time=%lldms", lcurtime - srdt.ms_dev[devidx].FirstCmdTimeCnt);
|
|
|
|
sprintf(szbuf, "time=%lldms", lcurtime - srdt.ms_dev[devidx].FirstCmdTimeCnt);
|
|
|
|
DebugLog(devparam[devidx].commid, szbuf, 'I');
|
|
|
|
DebugLog(devparam[devidx].commid, szbuf, 'I');
|
|
|
|
packetsize = (WORD)MAX_PHOTO_FRAME_LEN;
|
|
|
|
packetsize = (uint16_t)MAX_PHOTO_FRAME_LEN;
|
|
|
|
srdt.sendphotocmdcnt++;
|
|
|
|
srdt.sendphotocmdcnt++;
|
|
|
|
srdt.imagepacketnum = 0;
|
|
|
|
srdt.imagepacketnum = 0;
|
|
|
|
srdt.errorPhotoNoCnt = 0;
|
|
|
|
srdt.errorPhotoNoCnt = 0;
|
|
|
@ -2428,7 +2433,7 @@ int FindNextCameraPhotoCommand(int devidx)
|
|
|
|
|
|
|
|
|
|
|
|
case 10003: /* 读取历史图片(15H)*/
|
|
|
|
case 10003: /* 读取历史图片(15H)*/
|
|
|
|
cmdidx = 0x15;
|
|
|
|
cmdidx = 0x15;
|
|
|
|
packetsize = (WORD)MAX_PHOTO_FRAME_LEN;
|
|
|
|
packetsize = (uint16_t)MAX_PHOTO_FRAME_LEN;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 10005: /* 关闭功能*/
|
|
|
|
case 10005: /* 关闭功能*/
|
|
|
@ -2551,7 +2556,7 @@ int FindNextCameraPhotoCommand(int devidx)
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
imagesize = 0xFF;
|
|
|
|
imagesize = 0xFF;
|
|
|
|
packetsize = (WORD)srdt.ms_dev[devidx].SerialCmdidx;
|
|
|
|
packetsize = (uint16_t)srdt.ms_dev[devidx].SerialCmdidx;
|
|
|
|
cmdidx = 0x11;
|
|
|
|
cmdidx = 0x11;
|
|
|
|
#if 0
|
|
|
|
#if 0
|
|
|
|
if (0 == srdt.IsSleep)
|
|
|
|
if (0 == srdt.IsSleep)
|
|
|
@ -2578,7 +2583,7 @@ int FindNextCameraPhotoCommand(int devidx)
|
|
|
|
/*********************************************************************************
|
|
|
|
/*********************************************************************************
|
|
|
|
生成 CameraPhoto命令
|
|
|
|
生成 CameraPhoto命令
|
|
|
|
**********************************************************************************/
|
|
|
|
**********************************************************************************/
|
|
|
|
void MakeCameraPhotoCommand( int portno, BYTE cmdidx, int OneParam, WORD TwoParam, BYTE Threep, int phototime )
|
|
|
|
void MakeCameraPhotoCommand(int portno, uint8_t cmdidx, int OneParam, uint16_t TwoParam, uint8_t Threep, int phototime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, icurtime;
|
|
|
|
int i, icurtime;
|
|
|
|
u_char *sendbuf;
|
|
|
|
u_char *sendbuf;
|
|
|
@ -2591,10 +2596,10 @@ void MakeCameraPhotoCommand( int portno, BYTE cmdidx, int OneParam, WORD TwoPara
|
|
|
|
sendbuf[i++] = 0x00; /* 强制等待时间*/
|
|
|
|
sendbuf[i++] = 0x00; /* 强制等待时间*/
|
|
|
|
sendbuf[i++] = 0x00; /* 强制等待时间*/
|
|
|
|
sendbuf[i++] = 0x00; /* 强制等待时间*/
|
|
|
|
sendbuf[i++] = 0x68; /* 起始字符*/
|
|
|
|
sendbuf[i++] = 0x68; /* 起始字符*/
|
|
|
|
sendbuf[i++] = (BYTE)0x00; /* length */
|
|
|
|
sendbuf[i++] = (uint8_t)0x00; /* length */
|
|
|
|
sendbuf[i++] = (BYTE)0x00; /* length */
|
|
|
|
sendbuf[i++] = (uint8_t)0x00; /* length */
|
|
|
|
sendbuf[i++] = 0x68; /* 起始字符*/
|
|
|
|
sendbuf[i++] = 0x68; /* 起始字符*/
|
|
|
|
sendbuf[i++] = (BYTE)devparam[portno].devaddr;/* 传感器地址*/
|
|
|
|
sendbuf[i++] = (uint8_t)devparam[portno].devaddr;/* 传感器地址*/
|
|
|
|
sendbuf[i++] = cmdidx; /* 命令字*/
|
|
|
|
sendbuf[i++] = cmdidx; /* 命令字*/
|
|
|
|
switch (cmdidx)
|
|
|
|
switch (cmdidx)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -2605,7 +2610,7 @@ void MakeCameraPhotoCommand( int portno, BYTE cmdidx, int OneParam, WORD TwoPara
|
|
|
|
sendbuf[i++] = 0x00; /* 波特率*/
|
|
|
|
sendbuf[i++] = 0x00; /* 波特率*/
|
|
|
|
sendbuf[i++] = 0x00;
|
|
|
|
sendbuf[i++] = 0x00;
|
|
|
|
sendbuf[i++] = 0x00;
|
|
|
|
sendbuf[i++] = 0x00;
|
|
|
|
sendbuf[i++] = (BYTE)OneParam;
|
|
|
|
sendbuf[i++] = (uint8_t)OneParam;
|
|
|
|
sendbuf[i++] = 0x08; /* 数据位*/
|
|
|
|
sendbuf[i++] = 0x08; /* 数据位*/
|
|
|
|
sendbuf[i++] = 0x00; /* 校验位*/
|
|
|
|
sendbuf[i++] = 0x00; /* 校验位*/
|
|
|
|
sendbuf[i++] = 0x01; /* 停止位*/
|
|
|
|
sendbuf[i++] = 0x01; /* 停止位*/
|
|
|
@ -2634,20 +2639,20 @@ void MakeCameraPhotoCommand( int portno, BYTE cmdidx, int OneParam, WORD TwoPara
|
|
|
|
sendbuf[i++] = LOBYTE(HIWORD(OneParam));
|
|
|
|
sendbuf[i++] = LOBYTE(HIWORD(OneParam));
|
|
|
|
sendbuf[i++] = HIBYTE(LOWORD(OneParam));
|
|
|
|
sendbuf[i++] = HIBYTE(LOWORD(OneParam));
|
|
|
|
sendbuf[i++] = LOBYTE(LOWORD(OneParam));
|
|
|
|
sendbuf[i++] = LOBYTE(LOWORD(OneParam));
|
|
|
|
sendbuf[i++] = (BYTE)TwoParam; /* 是否需要保存*/
|
|
|
|
sendbuf[i++] = (uint8_t)TwoParam; /* 是否需要保存*/
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendbuf[i] = CalLpc((u_char *)&sendbuf[6], i - 6);
|
|
|
|
sendbuf[i] = CalLpc((u_char *)&sendbuf[6], i - 6);
|
|
|
|
i += 1;
|
|
|
|
i += 1;
|
|
|
|
sendbuf[i++] = 0x16; /* 信息尾*/
|
|
|
|
sendbuf[i++] = 0x16; /* 信息尾*/
|
|
|
|
sendbuf[3] = (BYTE)((i-10)>>8);
|
|
|
|
sendbuf[3] = (uint8_t)((i - 10) >> 8);
|
|
|
|
sendbuf[4] = (BYTE)(i-10);
|
|
|
|
sendbuf[4] = (uint8_t)(i - 10);
|
|
|
|
serialport[devparam[portno].commid].cmdlen = i;
|
|
|
|
serialport[devparam[portno].commid].cmdlen = i;
|
|
|
|
//return;
|
|
|
|
//return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 准备发送云台指令
|
|
|
|
// 准备发送云台指令
|
|
|
|
int Gm_CtrlPtzCmd(u_char channel, DWORD ptzcmd)
|
|
|
|
int Gm_CtrlPtzCmd(u_char channel, uint32_t ptzcmd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
char szbuf[64];
|
|
|
|
char szbuf[64];
|
|
|
@ -2777,21 +2782,21 @@ int Gm_Camera_Timer()
|
|
|
|
/********************************************************************************
|
|
|
|
/********************************************************************************
|
|
|
|
* 生成 PELCO_P 命令 *
|
|
|
|
* 生成 PELCO_P 命令 *
|
|
|
|
*********************************************************************************/
|
|
|
|
*********************************************************************************/
|
|
|
|
void Gm_SendPelco_pCommand( DWORD cmdtype)
|
|
|
|
void Gm_SendPelco_pCommand(uint32_t cmdtype)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int len;
|
|
|
|
BYTE commandbuf[32];
|
|
|
|
uint8_t commandbuf[32];
|
|
|
|
char buf[128];
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
len = 0;
|
|
|
|
commandbuf[len++] = (BYTE)0xA0;
|
|
|
|
commandbuf[len++] = (uint8_t)0xA0;
|
|
|
|
commandbuf[len++] = (BYTE)devparam[srdt.usecameradevidx].devaddr;
|
|
|
|
commandbuf[len++] = (uint8_t)devparam[srdt.usecameradevidx].devaddr;
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype>>24);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype >> 24);
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype>>16);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype >> 16);
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype>>8);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype >> 8);
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype);
|
|
|
|
commandbuf[len++] = (BYTE)0xAF;
|
|
|
|
commandbuf[len++] = (uint8_t)0xAF;
|
|
|
|
commandbuf[len] = (BYTE)Gm_Pelco_pXORCheck(commandbuf, len);
|
|
|
|
commandbuf[len] = (uint8_t)Gm_Pelco_pXORCheck(commandbuf, len);
|
|
|
|
len++;
|
|
|
|
len++;
|
|
|
|
serialport[srdt.camerauseserial].cmdlen = len;
|
|
|
|
serialport[srdt.camerauseserial].cmdlen = len;
|
|
|
|
Gm_SetSerialPortParam(srdt.camerauseserial);
|
|
|
|
Gm_SetSerialPortParam(srdt.camerauseserial);
|
|
|
@ -2812,10 +2817,10 @@ void Gm_SendPelco_pCommand( DWORD cmdtype)
|
|
|
|
ClearCmdFormPollCmdBuf(srdt.camerauseserial);
|
|
|
|
ClearCmdFormPollCmdBuf(srdt.camerauseserial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BYTE Gm_Pelco_pXORCheck( BYTE *msg, int len )
|
|
|
|
uint8_t Gm_Pelco_pXORCheck(uint8_t *msg, int len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
BYTE checkvalue=0;
|
|
|
|
uint8_t checkvalue = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
if (len <= 0)
|
|
|
|
return checkvalue;
|
|
|
|
return checkvalue;
|
|
|
@ -2828,21 +2833,21 @@ BYTE Gm_Pelco_pXORCheck( BYTE *msg, int len )
|
|
|
|
/********************************************************************************
|
|
|
|
/********************************************************************************
|
|
|
|
* 生成 PELCO_D 命令 *
|
|
|
|
* 生成 PELCO_D 命令 *
|
|
|
|
*********************************************************************************/
|
|
|
|
*********************************************************************************/
|
|
|
|
void Gm_SendPelco_DCommand( DWORD cmdtype)
|
|
|
|
void Gm_SendPelco_DCommand(uint32_t cmdtype)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int len;
|
|
|
|
BYTE commandbuf[32];
|
|
|
|
uint8_t commandbuf[32];
|
|
|
|
char buf[128];
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
len = 0;
|
|
|
|
#if 1 /* Pelco_D*/
|
|
|
|
#if 1 /* Pelco_D*/
|
|
|
|
commandbuf[len++] = (BYTE)0xFF;
|
|
|
|
commandbuf[len++] = (uint8_t)0xFF;
|
|
|
|
commandbuf[len++] = (BYTE)devparam[srdt.usecameradevidx].devaddr;
|
|
|
|
commandbuf[len++] = (uint8_t)devparam[srdt.usecameradevidx].devaddr;
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype>>24);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype >> 24);
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype>>16);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype >> 16);
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype>>8);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype >> 8);
|
|
|
|
commandbuf[len++] = (BYTE)(cmdtype);
|
|
|
|
commandbuf[len++] = (uint8_t)(cmdtype);
|
|
|
|
commandbuf[len] = (BYTE)Gm_Pelco_DCheck(commandbuf, len);
|
|
|
|
commandbuf[len] = (uint8_t)Gm_Pelco_DCheck(commandbuf, len);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
len++;
|
|
|
|
len++;
|
|
|
|
serialport[srdt.camerauseserial].cmdlen = len;
|
|
|
|
serialport[srdt.camerauseserial].cmdlen = len;
|
|
|
@ -2864,10 +2869,10 @@ void Gm_SendPelco_DCommand( DWORD cmdtype)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 计算Pelco_D校验
|
|
|
|
// 计算Pelco_D校验
|
|
|
|
BYTE Gm_Pelco_DCheck( BYTE *msg, int len )
|
|
|
|
uint8_t Gm_Pelco_DCheck(uint8_t *msg, int len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
BYTE checkvalue=0;
|
|
|
|
uint8_t checkvalue = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
if (len <= 0)
|
|
|
|
return checkvalue;
|
|
|
|
return checkvalue;
|
|
|
@ -2912,7 +2917,7 @@ int FindNextShxyProtocolCommand( int devidx )
|
|
|
|
/*********************************************************************************
|
|
|
|
/*********************************************************************************
|
|
|
|
生成下发命令
|
|
|
|
生成下发命令
|
|
|
|
**********************************************************************************/
|
|
|
|
**********************************************************************************/
|
|
|
|
void MakeShxyProtocolPollCommand(int portno, BYTE 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;
|
|
|
@ -2928,10 +2933,10 @@ void MakeShxyProtocolPollCommand(int portno, BYTE cmdidx)
|
|
|
|
sendbuf[i++] = 0x00; // 强制等待时间
|
|
|
|
sendbuf[i++] = 0x00; // 强制等待时间
|
|
|
|
sendbuf[i++] = 0x00; //
|
|
|
|
sendbuf[i++] = 0x00; //
|
|
|
|
sendbuf[i++] = 0x68; // 起始字符
|
|
|
|
sendbuf[i++] = 0x68; // 起始字符
|
|
|
|
sendbuf[i++] = (BYTE)0x00; // length
|
|
|
|
sendbuf[i++] = (uint8_t)0x00; // length
|
|
|
|
sendbuf[i++] = (BYTE)0x00; // length
|
|
|
|
sendbuf[i++] = (uint8_t)0x00; // length
|
|
|
|
sendbuf[i++] = 0x68;
|
|
|
|
sendbuf[i++] = 0x68;
|
|
|
|
sendbuf[i++] = (BYTE)devparam[portno].devaddr; // 传感器地址
|
|
|
|
sendbuf[i++] = (uint8_t)devparam[portno].devaddr; // 传感器地址
|
|
|
|
sendbuf[i++] = cmdidx; // 命令信息0x06
|
|
|
|
sendbuf[i++] = cmdidx; // 命令信息0x06
|
|
|
|
switch (cmdidx)
|
|
|
|
switch (cmdidx)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -2979,7 +2984,7 @@ unsigned char CalLpc(unsigned char *msg, int len)
|
|
|
|
void ShxyProtocolRecvData(int devno, u_char *buf, int len)// 规约读数据处理
|
|
|
|
void ShxyProtocolRecvData(int devno, u_char *buf, int len)// 规约读数据处理
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, ictime;
|
|
|
|
int i, ictime;
|
|
|
|
//WORD crc, check;
|
|
|
|
//uint16_t crc, check;
|
|
|
|
//SERIAL_DEV_DEF *pPortParam;
|
|
|
|
//SERIAL_DEV_DEF *pPortParam;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
SIO_PARAM_SERIAL_DEF *pPortParam;
|
|
|
|
|
|
|
|
|
|
|
@ -3034,7 +3039,7 @@ void ShxyProtocolRecvData(int devno, u_char *buf, int len)// 规约读数据处
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(CheckShxyProtocolLpcError(pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen) == TRUE)
|
|
|
|
if (CheckShxyProtocolLpcError(pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen) == 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ShxyProtocolDataProcess(devno);
|
|
|
|
ShxyProtocolDataProcess(devno);
|
|
|
|
pPortParam->m_iRevStatus = 0;
|
|
|
|
pPortParam->m_iRevStatus = 0;
|
|
|
@ -3078,7 +3083,7 @@ void ShxyProtocolRecvData(int devno, u_char *buf, int len)// 规约读数据处
|
|
|
|
//********************************************************************************
|
|
|
|
//********************************************************************************
|
|
|
|
int CheckShxyProtocolLpcError(u_char* msg, int len)
|
|
|
|
int CheckShxyProtocolLpcError(u_char* msg, int len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int bRetval = FALSE;
|
|
|
|
int bRetval = 0;
|
|
|
|
int iCheckLen;
|
|
|
|
int iCheckLen;
|
|
|
|
|
|
|
|
|
|
|
|
if (0x68 == msg[0])
|
|
|
|
if (0x68 == msg[0])
|
|
|
@ -3092,7 +3097,7 @@ int CheckShxyProtocolLpcError( u_char* msg, int len )
|
|
|
|
iCheckLen = msg[1];
|
|
|
|
iCheckLen = msg[1];
|
|
|
|
if (CalLpc(&msg[4], iCheckLen + 2) != msg[len - 2])
|
|
|
|
if (CalLpc(&msg[4], iCheckLen + 2) != msg[len - 2])
|
|
|
|
return bRetval;
|
|
|
|
return bRetval;
|
|
|
|
bRetval = TRUE;
|
|
|
|
bRetval = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRetval;
|
|
|
|
return bRetval;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -3103,8 +3108,8 @@ int CheckShxyProtocolLpcError( u_char* msg, int len )
|
|
|
|
void ShxyProtocolDataProcess(int devno)
|
|
|
|
void ShxyProtocolDataProcess(int devno)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/;
|
|
|
|
float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/;
|
|
|
|
WORD uDevAddr;
|
|
|
|
uint16_t uDevAddr;
|
|
|
|
BYTE cmdidx;
|
|
|
|
uint8_t cmdidx;
|
|
|
|
int i, j, aipnt, datanum;
|
|
|
|
int i, j, aipnt, datanum;
|
|
|
|
SERIAL_DEV_DEF *pPortParam;
|
|
|
|
SERIAL_DEV_DEF *pPortParam;
|
|
|
|
SIO_PARAM_SERIAL_DEF *curserial;
|
|
|
|
SIO_PARAM_SERIAL_DEF *curserial;
|
|
|
@ -3136,10 +3141,10 @@ void ShxyProtocolDataProcess( int devno)
|
|
|
|
// ++++++++++++++++++++++++++++
|
|
|
|
// ++++++++++++++++++++++++++++
|
|
|
|
//g_SelfTest.SensorsFault |= (0x800<<aipnt);
|
|
|
|
//g_SelfTest.SensorsFault |= (0x800<<aipnt);
|
|
|
|
|
|
|
|
|
|
|
|
*(BYTE*)fvalua = curserial->m_au8RecvBuf[9];
|
|
|
|
*(uint8_t*)fvalua = curserial->m_au8RecvBuf[9];
|
|
|
|
*((BYTE*)fvalua+1) = curserial->m_au8RecvBuf[8];
|
|
|
|
*((uint8_t*)fvalua + 1) = curserial->m_au8RecvBuf[8];
|
|
|
|
*((BYTE*)fvalua+2) = curserial->m_au8RecvBuf[7];
|
|
|
|
*((uint8_t*)fvalua + 2) = curserial->m_au8RecvBuf[7];
|
|
|
|
*((BYTE*)fvalua+3) = curserial->m_au8RecvBuf[6];
|
|
|
|
*((uint8_t*)fvalua + 3) = curserial->m_au8RecvBuf[6];
|
|
|
|
if ((fvalue < -59) || (fvalue > 59))
|
|
|
|
if ((fvalue < -59) || (fvalue > 59))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
frnb = (GeneratingRandomNumber() % 101 - 50) / 1000.0;
|
|
|
|
frnb = (GeneratingRandomNumber() % 101 - 50) / 1000.0;
|
|
|
@ -3159,10 +3164,10 @@ void ShxyProtocolDataProcess( int devno)
|
|
|
|
//XslantSec[aipnt][srdt.SectimesamplingCnt[0]] = (short)slantpntmsg[aipnt][0].EuValue;
|
|
|
|
//XslantSec[aipnt][srdt.SectimesamplingCnt[0]] = (short)slantpntmsg[aipnt][0].EuValue;
|
|
|
|
//srdt.SectimesamplingCnt[0] += 1;
|
|
|
|
//srdt.SectimesamplingCnt[0] += 1;
|
|
|
|
|
|
|
|
|
|
|
|
*(BYTE*)fvalua = curserial->m_au8RecvBuf[13];
|
|
|
|
*(uint8_t*)fvalua = curserial->m_au8RecvBuf[13];
|
|
|
|
*((BYTE*)fvalua+1) = curserial->m_au8RecvBuf[12];
|
|
|
|
*((uint8_t*)fvalua + 1) = curserial->m_au8RecvBuf[12];
|
|
|
|
*((BYTE*)fvalua+2) = curserial->m_au8RecvBuf[11];
|
|
|
|
*((uint8_t*)fvalua + 2) = curserial->m_au8RecvBuf[11];
|
|
|
|
*((BYTE*)fvalua+3) = curserial->m_au8RecvBuf[10];
|
|
|
|
*((uint8_t*)fvalua + 3) = curserial->m_au8RecvBuf[10];
|
|
|
|
//if ((gDisSunRain & 0x20) == 0x20)
|
|
|
|
//if ((gDisSunRain & 0x20) == 0x20)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sprintf(szbuf, "%sY =%0.3f ", szbuf, fvalue);
|
|
|
|
sprintf(szbuf, "%sY =%0.3f ", szbuf, fvalue);
|
|
|
@ -3194,10 +3199,10 @@ void ShxyProtocolDataProcess( int devno)
|
|
|
|
+ (curserial->m_au8RecvBuf[j + 3] << 8) + curserial->m_au8RecvBuf[j + 4];
|
|
|
|
+ (curserial->m_au8RecvBuf[j + 3] << 8) + curserial->m_au8RecvBuf[j + 4];
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*(BYTE*)fvalua = curserial->m_au8RecvBuf[j+4];
|
|
|
|
*(uint8_t*)fvalua = curserial->m_au8RecvBuf[j + 4];
|
|
|
|
*((BYTE*)fvalua+1) = curserial->m_au8RecvBuf[j+3];
|
|
|
|
*((uint8_t*)fvalua + 1) = curserial->m_au8RecvBuf[j + 3];
|
|
|
|
*((BYTE*)fvalua+2) = curserial->m_au8RecvBuf[j+2];
|
|
|
|
*((uint8_t*)fvalua + 2) = curserial->m_au8RecvBuf[j + 2];
|
|
|
|
*((BYTE*)fvalua+3) = curserial->m_au8RecvBuf[j+1];
|
|
|
|
*((uint8_t*)fvalua + 3) = curserial->m_au8RecvBuf[j + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (curserial->m_au8RecvBuf[j])
|
|
|
|
switch (curserial->m_au8RecvBuf[j])
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -3489,7 +3494,7 @@ 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((DWORD)ictime);
|
|
|
|
srand((uint32_t)ictime);
|
|
|
|
randomdate = rand();
|
|
|
|
randomdate = rand();
|
|
|
|
return randomdate;
|
|
|
|
return randomdate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|