|
|
@ -14,6 +14,7 @@
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <asm/termbits.h>
|
|
|
|
#include <asm/termbits.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <time.h>
|
|
|
@ -853,7 +854,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
//sprintf(devparam[0].stopbit, "1");
|
|
|
|
//sprintf(devparam[0].stopbit, "1");
|
|
|
|
sensorParam[0].stopbit = 1;
|
|
|
|
sensorParam[0].stopbit = 1;
|
|
|
|
sensorParam[0].parity = 'n';
|
|
|
|
sensorParam[0].parity = 'n';
|
|
|
|
sensorParam[0].IsNoInsta = 0;
|
|
|
|
sensorParam[0].IsNoInsta = 1;
|
|
|
|
sensorParam[0].devaddr = 4;
|
|
|
|
sensorParam[0].devaddr = 4;
|
|
|
|
memset(sensorParam[0].pathname, 0, sizeof(sensorParam[0].pathname));
|
|
|
|
memset(sensorParam[0].pathname, 0, sizeof(sensorParam[0].pathname));
|
|
|
|
sprintf(sensorParam[0].pathname, "/dev/ttysWK3");
|
|
|
|
sprintf(sensorParam[0].pathname, "/dev/ttysWK3");
|
|
|
@ -865,7 +866,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
//sprintf(devparam[1].stopbit, "1");
|
|
|
|
//sprintf(devparam[1].stopbit, "1");
|
|
|
|
sensorParam[1].stopbit = 1;
|
|
|
|
sensorParam[1].stopbit = 1;
|
|
|
|
sensorParam[1].parity = 0;
|
|
|
|
sensorParam[1].parity = 0;
|
|
|
|
sensorParam[1].IsNoInsta = 0;
|
|
|
|
sensorParam[1].IsNoInsta = 1;
|
|
|
|
sensorParam[1].devaddr = 1;
|
|
|
|
sensorParam[1].devaddr = 1;
|
|
|
|
memset(sensorParam[1].pathname, 0, sizeof(sensorParam[1].pathname));
|
|
|
|
memset(sensorParam[1].pathname, 0, sizeof(sensorParam[1].pathname));
|
|
|
|
sprintf(sensorParam[1].pathname, "/dev/ttysWK3");
|
|
|
|
sprintf(sensorParam[1].pathname, "/dev/ttysWK3");
|
|
|
@ -877,7 +878,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
//sprintf(devparam[2].stopbit, "1");
|
|
|
|
//sprintf(devparam[2].stopbit, "1");
|
|
|
|
sensorParam[2].stopbit = 1;
|
|
|
|
sensorParam[2].stopbit = 1;
|
|
|
|
sensorParam[2].parity = 0;
|
|
|
|
sensorParam[2].parity = 0;
|
|
|
|
sensorParam[2].IsNoInsta = 0;
|
|
|
|
sensorParam[2].IsNoInsta = 1;
|
|
|
|
//sensorParam[2].PowerPort = 3;
|
|
|
|
//sensorParam[2].PowerPort = 3;
|
|
|
|
//sensorParam[2].devaddr = 13;
|
|
|
|
//sensorParam[2].devaddr = 13;
|
|
|
|
sensorParam[2].devaddr = 13;
|
|
|
|
sensorParam[2].devaddr = 13;
|
|
|
@ -891,7 +892,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
//sprintf(devparam[2].stopbit, "1");
|
|
|
|
//sprintf(devparam[2].stopbit, "1");
|
|
|
|
sensorParam[5].stopbit = 1;
|
|
|
|
sensorParam[5].stopbit = 1;
|
|
|
|
sensorParam[5].parity = 0;
|
|
|
|
sensorParam[5].parity = 0;
|
|
|
|
sensorParam[5].IsNoInsta = 0;
|
|
|
|
sensorParam[5].IsNoInsta = 1;
|
|
|
|
sensorParam[5].devaddr = 10;
|
|
|
|
sensorParam[5].devaddr = 10;
|
|
|
|
memset(sensorParam[5].pathname, 0, sizeof(sensorParam[3].pathname));
|
|
|
|
memset(sensorParam[5].pathname, 0, sizeof(sensorParam[3].pathname));
|
|
|
|
sprintf(sensorParam[5].pathname, "/dev/ttysWK1");
|
|
|
|
sprintf(sensorParam[5].pathname, "/dev/ttysWK1");
|
|
|
@ -903,7 +904,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
//sprintf(devparam[2].stopbit, "1");
|
|
|
|
//sprintf(devparam[2].stopbit, "1");
|
|
|
|
sensorParam[4].stopbit = 1;
|
|
|
|
sensorParam[4].stopbit = 1;
|
|
|
|
sensorParam[4].parity = 0;
|
|
|
|
sensorParam[4].parity = 0;
|
|
|
|
sensorParam[4].IsNoInsta = 0;
|
|
|
|
sensorParam[4].IsNoInsta = 1;
|
|
|
|
//sensorParam[2].PowerPort = 3;
|
|
|
|
//sensorParam[2].PowerPort = 3;
|
|
|
|
//sensorParam[2].devaddr = 13;
|
|
|
|
//sensorParam[2].devaddr = 13;
|
|
|
|
sensorParam[4].devaddr = 12;
|
|
|
|
sensorParam[4].devaddr = 12;
|
|
|
@ -932,7 +933,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
sensorParam[7].stopbit = 1;
|
|
|
|
sensorParam[7].stopbit = 1;
|
|
|
|
sensorParam[7].parity = 0;
|
|
|
|
sensorParam[7].parity = 0;
|
|
|
|
//devparam[13].PowerPort = 4;
|
|
|
|
//devparam[13].PowerPort = 4;
|
|
|
|
sensorParam[7].IsNoInsta = 0;
|
|
|
|
sensorParam[7].IsNoInsta = 1;
|
|
|
|
sensorParam[7].devaddr = 3;
|
|
|
|
sensorParam[7].devaddr = 3;
|
|
|
|
memset(sensorParam[7].pathname, 0, sizeof(sensorParam[7].pathname));
|
|
|
|
memset(sensorParam[7].pathname, 0, sizeof(sensorParam[7].pathname));
|
|
|
|
sprintf(sensorParam[7].pathname, "/dev/ttysWK0");
|
|
|
|
sprintf(sensorParam[7].pathname, "/dev/ttysWK0");
|
|
|
@ -945,7 +946,7 @@ void Gm_InitSerialComm_Test()
|
|
|
|
sensorParam[13].stopbit = 1;
|
|
|
|
sensorParam[13].stopbit = 1;
|
|
|
|
sensorParam[13].parity = 0;
|
|
|
|
sensorParam[13].parity = 0;
|
|
|
|
//devparam[13].PowerPort = 4;
|
|
|
|
//devparam[13].PowerPort = 4;
|
|
|
|
sensorParam[13].IsNoInsta = 0;
|
|
|
|
sensorParam[13].IsNoInsta = 1;
|
|
|
|
sensorParam[13].devaddr = 5;
|
|
|
|
sensorParam[13].devaddr = 5;
|
|
|
|
memset(sensorParam[13].pathname, 0, sizeof(sensorParam[13].pathname));
|
|
|
|
memset(sensorParam[13].pathname, 0, sizeof(sensorParam[13].pathname));
|
|
|
|
sprintf(sensorParam[13].pathname, "/dev/ttysWK0");
|
|
|
|
sprintf(sensorParam[13].pathname, "/dev/ttysWK0");
|
|
|
@ -977,18 +978,18 @@ void Gm_InitSerialComm_Test()
|
|
|
|
sensorParam[3].databit = 8;
|
|
|
|
sensorParam[3].databit = 8;
|
|
|
|
sensorParam[3].stopbit = 1;
|
|
|
|
sensorParam[3].stopbit = 1;
|
|
|
|
sensorParam[3].parity = 0;
|
|
|
|
sensorParam[3].parity = 0;
|
|
|
|
sensorParam[3].IsNoInsta = 0;
|
|
|
|
sensorParam[3].IsNoInsta = 1;
|
|
|
|
//devparam[3].PowerPort = 15;
|
|
|
|
//devparam[3].PowerPort = 15;
|
|
|
|
sensorParam[3].CameraChannel = 1;
|
|
|
|
sensorParam[3].CameraChannel = 1;
|
|
|
|
sensorParam[3].devaddr = 0;
|
|
|
|
sensorParam[3].devaddr = 0;
|
|
|
|
memset(sensorParam[3].pathname, 0, sizeof(sensorParam[3].pathname));
|
|
|
|
memset(sensorParam[3].pathname, 0, sizeof(sensorParam[3].pathname));
|
|
|
|
sprintf(sensorParam[3].pathname, "/dev/ttyS1");
|
|
|
|
sprintf(sensorParam[3].pathname, "/dev/ttyS1");
|
|
|
|
//#endif
|
|
|
|
//#endif
|
|
|
|
Gm_InitSerialComm(sensorParam);
|
|
|
|
Gm_InitSerialComm(sensorParam, "/sdcard/photo/");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化所有串口及所接传感器的配置
|
|
|
|
// 初始化所有串口及所接传感器的配置
|
|
|
|
void Gm_InitSerialComm(SENSOR_PARAM *sensorParam)
|
|
|
|
void Gm_InitSerialComm(SENSOR_PARAM *sensorParam, char *filedir)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
char szbuf[128];
|
|
|
|
char szbuf[128];
|
|
|
@ -1073,6 +1074,10 @@ void Gm_InitSerialComm(SENSOR_PARAM *sensorParam)
|
|
|
|
DebugLog(8, szbuf, 'I');
|
|
|
|
DebugLog(8, szbuf, 'I');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NULL == filedir)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(srdt.filedir, 0, sizeof(srdt.filedir));
|
|
|
|
|
|
|
|
memmove(srdt.filedir, filedir, min(sizeof(srdt.filedir), strlen(filedir)));
|
|
|
|
FindDevUseSerialCommNo();
|
|
|
|
FindDevUseSerialCommNo();
|
|
|
|
#if 0
|
|
|
|
#if 0
|
|
|
|
//Collect_sensor_data();
|
|
|
|
//Collect_sensor_data();
|
|
|
@ -1112,13 +1117,13 @@ void testComm()
|
|
|
|
|
|
|
|
|
|
|
|
//memset(sensorParam, 0, sizeof(sensorParam));
|
|
|
|
//memset(sensorParam, 0, sizeof(sensorParam));
|
|
|
|
Gm_InitSerialComm_Test();
|
|
|
|
Gm_InitSerialComm_Test();
|
|
|
|
|
|
|
|
|
|
|
|
#if COLLECT_DATA
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
for(;;)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
#if COLLECT_DATA
|
|
|
|
|
|
|
|
|
|
|
|
Collect_sensor_data();
|
|
|
|
Collect_sensor_data();
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
for(;;)
|
|
|
|
sleep(15);
|
|
|
|
{
|
|
|
|
|
|
|
|
CameraPhotoCmd(time(NULL), 1, 0, 6, 1);
|
|
|
|
CameraPhotoCmd(time(NULL), 1, 0, 6, 1);
|
|
|
|
sleep(5);
|
|
|
|
sleep(5);
|
|
|
|
|
|
|
|
|
|
|
@ -1141,9 +1146,9 @@ void testComm()
|
|
|
|
sleep(5);
|
|
|
|
sleep(5);
|
|
|
|
CameraPhotoCmd(time(NULL), 1, 0, 6, 1);
|
|
|
|
CameraPhotoCmd(time(NULL), 1, 0, 6, 1);
|
|
|
|
sleep(5);
|
|
|
|
sleep(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
#if 1
|
|
|
|
#if 1
|
|
|
|
//******************** 端口基本信息 ************************
|
|
|
|
//******************** 端口基本信息 ************************
|
|
|
|
/*for(i=0; i<MAX_SERIAL_DEV_NUM; i++)
|
|
|
|
/*for(i=0; i<MAX_SERIAL_DEV_NUM; i++)
|
|
|
@ -1392,7 +1397,7 @@ void GM_StartSerialComm()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//LOGE("12V state=%d", getInt(CMD_SET_12V_EN_STATE));
|
|
|
|
//LOGE("12V state=%d", getInt(CMD_SET_12V_EN_STATE));
|
|
|
|
DebugLog(8, "退出采样流程!", 'V');
|
|
|
|
DebugLog(8, "退出采样流程!", 'V');
|
|
|
|
sleep(15);
|
|
|
|
sleep(5);
|
|
|
|
//GM_StartSerialComm();
|
|
|
|
//GM_StartSerialComm();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1833,7 +1838,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 filename[512], filedir[512], szbuf[128];
|
|
|
|
char filename[512]/*, filedir[512]*/, szbuf[128];
|
|
|
|
FILE *fp=NULL;
|
|
|
|
FILE *fp=NULL;
|
|
|
|
SERIAL_DEV_DEF *pPortParam;
|
|
|
|
SERIAL_DEV_DEF *pPortParam;
|
|
|
|
|
|
|
|
|
|
|
@ -1848,23 +1853,23 @@ int SaveImageDataTofile(int devno)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memset(szbuf, 0, sizeof(szbuf));
|
|
|
|
memset(szbuf, 0, sizeof(szbuf));
|
|
|
|
memset(filedir, 0, sizeof(filedir));
|
|
|
|
//memset(filedir, 0, sizeof(filedir));
|
|
|
|
sprintf(filedir, "/sdcard/photo/");
|
|
|
|
//sprintf(filedir, "/sdcard/photo/");
|
|
|
|
|
|
|
|
|
|
|
|
if(access(filedir, 0)==0)
|
|
|
|
if(access(srdt.filedir, 0)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sprintf(szbuf,"文件路径%s已经存在!", filedir);
|
|
|
|
sprintf(szbuf,"文件路径%s已经存在!", srdt.filedir);
|
|
|
|
DebugLog(devparam[devno].commid, szbuf, 'I');
|
|
|
|
DebugLog(devparam[devno].commid, szbuf, 'I');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
status = mkdir(filedir, S_IRWXU | S_IRWXG | S_IRWXO);
|
|
|
|
status = mkdir(srdt.filedir, S_IRWXU | S_IRWXG | S_IRWXO);
|
|
|
|
if(status < 0)
|
|
|
|
if(status < 0)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 写入文件到sdcard
|
|
|
|
// 写入文件到sdcard
|
|
|
|
memset(pPortParam->image.photoname, 0, sizeof(pPortParam->image.photoname));
|
|
|
|
memset(pPortParam->image.photoname, 0, sizeof(pPortParam->image.photoname));
|
|
|
|
sprintf(pPortParam->image.photoname, "%s%d-%d-%d.jpg", filedir,devparam[devno].CameraChannel, pPortParam->image.presetno, pPortParam->image.phototime);
|
|
|
|
sprintf(pPortParam->image.photoname, "%s%d-%d-%d.jpg", srdt.filedir,devparam[devno].CameraChannel, pPortParam->image.presetno, pPortParam->image.phototime);
|
|
|
|
fp = fopen(pPortParam->image.photoname, "wb+");
|
|
|
|
fp = fopen(pPortParam->image.photoname, "wb+");
|
|
|
|
if(NULL == fp)
|
|
|
|
if(NULL == fp)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
@ -2917,7 +2922,7 @@ void MakeShxyProtocolPollCommand(int portno, BYTE cmdidx)
|
|
|
|
sendbuf = serialport[devparam[portno].commid].PollCmd;
|
|
|
|
sendbuf = serialport[devparam[portno].commid].PollCmd;
|
|
|
|
|
|
|
|
|
|
|
|
/* 测试变量*/
|
|
|
|
/* 测试变量*/
|
|
|
|
cmdidx =2;
|
|
|
|
cmdidx =cmdidx;
|
|
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
i = 0;
|
|
|
|
sendbuf[i++] = 0x00; // 强制等待时间
|
|
|
|
sendbuf[i++] = 0x00; // 强制等待时间
|
|
|
@ -3364,6 +3369,54 @@ 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");
|
|
|
|
|
|
|
|
sprintf(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整数
|
|
|
|
把16进制和10进制ASCII字符串转换成int整数
|
|
|
|
*********************************************************************************/
|
|
|
|
*********************************************************************************/
|
|
|
@ -3462,6 +3515,23 @@ void Collect_sensor_data()
|
|
|
|
devparam[i].CameraChannel = sensorParam[i].CameraChannel;
|
|
|
|
devparam[i].CameraChannel = sensorParam[i].CameraChannel;
|
|
|
|
devparam[i].Phase = sensorParam[i].Phase;
|
|
|
|
devparam[i].Phase = sensorParam[i].Phase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
|
|
static int ideletefile =0;
|
|
|
|
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
struct tm t0;
|
|
|
|
|
|
|
|
const char *path = "/sdcard/log"; // 指定目录路径
|
|
|
|
|
|
|
|
int days = 15; // 删除15天前的log文件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now = time(NULL);
|
|
|
|
|
|
|
|
localtime_r(&now, &t0);
|
|
|
|
|
|
|
|
if((0 == t0.tm_hour) && (0 == ideletefile))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete_old_files(path, days);
|
|
|
|
|
|
|
|
ideletefile++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(0 < t0.tm_hour)
|
|
|
|
|
|
|
|
ideletefile = 0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
GM_StartSerialComm();
|
|
|
|
GM_StartSerialComm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|