From 9f47f7fa5c6031bd923ac536d950fc3a824b4a21 Mon Sep 17 00:00:00 2001 From: huyizhong Date: Mon, 1 Jul 2024 11:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=B5=8B=E8=AF=95=EF=BC=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=A1=AC=E4=BB=B6=E9=9C=80=E8=A6=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=E5=8D=8F=E5=8A=A9?= =?UTF-8?q?938=E7=A1=AC=E4=BB=B6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TestComm/app/src/main/cpp/SensorsProtocol.cpp | 39 ++++++++++++------- TestComm/app/src/main/cpp/SensorsProtocol.h | 26 +++++++++++-- TestComm/app/src/main/cpp/WeatherComm.cpp | 10 ++--- TestComm/app/src/main/cpp/WeatherComm.h | 2 +- app/src/main/cpp/SensorsProtocol.cpp | 39 ++++++++++++------- app/src/main/cpp/SensorsProtocol.h | 26 +++++++++++-- 6 files changed, 98 insertions(+), 44 deletions(-) diff --git a/TestComm/app/src/main/cpp/SensorsProtocol.cpp b/TestComm/app/src/main/cpp/SensorsProtocol.cpp index 89d4030c..691345cd 100644 --- a/TestComm/app/src/main/cpp/SensorsProtocol.cpp +++ b/TestComm/app/src/main/cpp/SensorsProtocol.cpp @@ -3082,15 +3082,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%101-50)/1000.0; pPortParam->aiValue[0].EuValue *= (1+frnb); - weatherpntmsg[0].EuValue *= (1+frnb); + weatherpntmsg[AirTempNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[0].EuValue = fvalue*pPortParam->aiValue[0].AiParam.fFactor + pPortParam->aiValue[0].AiParam.EuValueDelta; - weatherpntmsg[0].EuValue = fvalue*weatherpntmsg[0].AiParam.fFactor + weatherpntmsg[0].AiParam.EuValueDelta; + weatherpntmsg[AirTempNo].EuValue = fvalue*weatherpntmsg[AirTempNo].AiParam.fFactor + weatherpntmsg[AirTempNo].AiParam.EuValueDelta; } pPortParam->aiValue[0].AiState = 1; - weatherpntmsg[0].AiState = 1; + weatherpntmsg[AirTempNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x01); //if ((gDisSunRain & 0x80) == 0x80) { @@ -3103,15 +3103,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/10000.0; pPortParam->aiValue[5].EuValue *= (1+frnb); - weatherpntmsg[5].EuValue *= (1+frnb); + weatherpntmsg[AtmosNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[5].EuValue = fvalue*pPortParam->aiValue[5].AiParam.fFactor + pPortParam->aiValue[5].AiParam.EuValueDelta; - weatherpntmsg[5].EuValue = fvalue*weatherpntmsg[5].AiParam.fFactor + weatherpntmsg[5].AiParam.EuValueDelta; + weatherpntmsg[AtmosNo].EuValue = fvalue*weatherpntmsg[AtmosNo].AiParam.fFactor + weatherpntmsg[AtmosNo].AiParam.EuValueDelta; } pPortParam->aiValue[5].AiState = 1; - weatherpntmsg[5].AiState = 1; + weatherpntmsg[AtmosNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x10); //if ((gDisSunRain & 0x80) == 0x80) { @@ -3124,15 +3124,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; pPortParam->aiValue[1].EuValue *= (1+frnb); - weatherpntmsg[1].EuValue *= (1+frnb); + weatherpntmsg[HumidityNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[1].EuValue = fvalue*pPortParam->aiValue[1].AiParam.fFactor + pPortParam->aiValue[1].AiParam.EuValueDelta; - weatherpntmsg[1].EuValue = fvalue*weatherpntmsg[1].AiParam.fFactor + weatherpntmsg[1].AiParam.EuValueDelta; + weatherpntmsg[HumidityNo].EuValue = fvalue*weatherpntmsg[HumidityNo].AiParam.fFactor + weatherpntmsg[HumidityNo].AiParam.EuValueDelta; } pPortParam->aiValue[1].AiState = 1; - weatherpntmsg[1].AiState = 1; + weatherpntmsg[HumidityNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x02); //if ((gDisSunRain & 0x80) == 0x80) { @@ -3149,15 +3149,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; pPortParam->aiValue[2].EuValue *= (1+frnb); - weatherpntmsg[2].EuValue *= (1+frnb); + weatherpntmsg[WindSpeedNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[2].EuValue = fvalue*pPortParam->aiValue[2].AiParam.fFactor + pPortParam->aiValue[2].AiParam.EuValueDelta; - weatherpntmsg[2].EuValue = fvalue*weatherpntmsg[2].AiParam.fFactor + weatherpntmsg[2].AiParam.EuValueDelta; + weatherpntmsg[WindSpeedNo].EuValue = fvalue*weatherpntmsg[WindSpeedNo].AiParam.fFactor + weatherpntmsg[WindSpeedNo].AiParam.EuValueDelta; } pPortParam->aiValue[2].AiState = 1; - weatherpntmsg[2].AiState = 1; + weatherpntmsg[WindSpeedNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x04); //if ((gDisSunRain & 0x10) == 0x10) { @@ -3174,15 +3174,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; pPortParam->aiValue[3].EuValue *= (1+frnb); - weatherpntmsg[3].EuValue *= (1+frnb); + weatherpntmsg[WindDirectionNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[3].EuValue = fvalue*pPortParam->aiValue[3].AiParam.fFactor + pPortParam->aiValue[3].AiParam.EuValueDelta; - weatherpntmsg[3].EuValue = fvalue*weatherpntmsg[3].AiParam.fFactor + weatherpntmsg[3].AiParam.EuValueDelta; + weatherpntmsg[WindDirectionNo].EuValue = fvalue*weatherpntmsg[WindDirectionNo].AiParam.fFactor + weatherpntmsg[WindDirectionNo].AiParam.EuValueDelta; } pPortParam->aiValue[3].AiState = 1; - weatherpntmsg[3].AiState = 1; + weatherpntmsg[WindDirectionNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x08); //if ((gDisSunRain & 0x10) == 0x10) { @@ -3522,4 +3522,13 @@ void CameraPhotoCmd(SENSOR_PARAM *sensorParam, u_char channel, int cmdidx, u_cha GM_StartSerialCameraPhoto(1, cmdidx); } +int GetAirTempData(Data_DEF *airt) +{ + int i; + + if(NULL == airt) + return -1; + airt->EuValue = weatherpntmsg[AirTempNo].EuValue; + airt->AiState = weatherpntmsg[AirTempNo].AiState; +} diff --git a/TestComm/app/src/main/cpp/SensorsProtocol.h b/TestComm/app/src/main/cpp/SensorsProtocol.h index 194bba48..b02ad142 100644 --- a/TestComm/app/src/main/cpp/SensorsProtocol.h +++ b/TestComm/app/src/main/cpp/SensorsProtocol.h @@ -51,6 +51,20 @@ typedef unsigned char BYTE; #define RESERVE5_PROTOCOL 20 /* 备用5协议序号*/ #define INVALID_PROTOCOL 21 /* 无效协议序号*/ +#define AirTempNo 0 /* 空气温度数据存储序号*/ +#define HumidityNo 1 /* 相对湿度数据存储序号*/ +#define WindSpeedNo 2 /* 风速数据存储序号*/ +#define WindDirectionNo 3 /* 风向数据存储序号*/ +#define RainfallNo 4 /* 雨量数据存储序号*/ +#define AtmosNo 5 /* 大气压数据存储序号*/ +#define OpticalRadiationNo 6 /* 日照(光辐射)数据存储序号*/ + +#define Idle 0 /* 传感器处于空闲状态,未启动采样*/ +#define Sample 1 /* 正在采样过程中*/ +#define SamplingEnd 2 /* 采样结束*/ +#define StartSample 3 /* 启动采样*/ +#define SampleFail -1 /* 采样失败,传感器故障或未接*/ + #define WEATHER_DATA_NUM 8 /* 气象数据最大数量(一般最多是6要素)*/ #define RALLY_DATA_NUM 2 /* 拉力数据最大数量(一般是1个)*/ #define SLANTANGLE_DATA_NUM 3 /* 倾角数据最大数量(一般只有X轴和Y轴值)*/ @@ -140,19 +154,23 @@ typedef struct typedef struct { - //float fAiDead; // 数据变化死区(百分系数值,如:设置死区为5%,只需赋值5即可) float fFactor; // 数据系数 float EuValueDelta; // 数据工程值偏移 - //BYTE Polar; // 数据极性(有无符号位) } AI_PARAM; typedef struct { AI_PARAM AiParam; // 数据点配置参数 - BYTE AiState; // 遥测是否有效标识 - float EuValue; // 遥测工程值 + int AiState; // 数据标识(-1:采样失败;0:没有采样;1:正在采样;2:采样结束;3:启动采样;) + float EuValue; // 数据工程值 } AI_DEF; +typedef struct +{ + BYTE AiState; // 数据标识(-1:采样失败;0:没有采样;1:正在采样;2:采样结束;3:启动采样;) + float EuValue; // 数据工程值 +} Data_DEF; + typedef struct { int imagelen; // 整个图片大小 diff --git a/TestComm/app/src/main/cpp/WeatherComm.cpp b/TestComm/app/src/main/cpp/WeatherComm.cpp index 285c55de..ea023ae4 100644 --- a/TestComm/app/src/main/cpp/WeatherComm.cpp +++ b/TestComm/app/src/main/cpp/WeatherComm.cpp @@ -154,7 +154,7 @@ static void setCam3V3Enable(bool enabled) /********************************************************************************* * 气象数据处理 * **********************************************************************************/ -void PortDataProcess( void ) +void PortDataProcess( ) { float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/; //WORD uDevAddr; @@ -505,7 +505,7 @@ static int weather_comm(SERIAL_PARAM weatherport) irecvtime = get_msec(); if((irecvtime-isendtime > 6000) ||(irecvtime - isendtime < 0)) isendtime = irecvtime; - if (irecvtime-isendtime > 500) + if (irecvtime-isendtime > 1500) { LOGE("传感器超过%ld毫秒未应答", irecvtime-isendtime); serialport.RevCmdFlag = 1; @@ -567,10 +567,10 @@ int serial_port_comm() #if 1 memset(portparm.pathname, 0, sizeof(portparm.pathname)); sprintf(portparm.pathname, "/dev/ttyS1"); - //sprintf(portparm.pathname, "/dev/ttysWK3"); + //sprintf(portparm.pathname, "/dev/ttysWK1"); portparm.parity = 'N'; portparm.databit = 8; - portparm.baudrate = B9600; + portparm.baudrate = B38400; memset(portparm.stopbit, 0, sizeof(portparm.stopbit)); sprintf(portparm.stopbit, "1"); #endif @@ -578,7 +578,7 @@ int serial_port_comm() for(;;) { - sleep(10); + sleep(3); weather_comm(portparm); } diff --git a/TestComm/app/src/main/cpp/WeatherComm.h b/TestComm/app/src/main/cpp/WeatherComm.h index 80c47f98..3a9d3119 100644 --- a/TestComm/app/src/main/cpp/WeatherComm.h +++ b/TestComm/app/src/main/cpp/WeatherComm.h @@ -43,7 +43,7 @@ typedef struct char str[MAX_STRING_LEN]; }IOT_PARAM; -void PortDataProcess( void ); +void PortDataProcess( ); int serial_port_comm(); static int weather_comm(SERIAL_PARAM weatherport); int set_port_attr (int fd, int baudrate, int databit, const char *stopbit, char parity, int vtime, int vmin ); diff --git a/app/src/main/cpp/SensorsProtocol.cpp b/app/src/main/cpp/SensorsProtocol.cpp index 89d4030c..691345cd 100644 --- a/app/src/main/cpp/SensorsProtocol.cpp +++ b/app/src/main/cpp/SensorsProtocol.cpp @@ -3082,15 +3082,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%101-50)/1000.0; pPortParam->aiValue[0].EuValue *= (1+frnb); - weatherpntmsg[0].EuValue *= (1+frnb); + weatherpntmsg[AirTempNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[0].EuValue = fvalue*pPortParam->aiValue[0].AiParam.fFactor + pPortParam->aiValue[0].AiParam.EuValueDelta; - weatherpntmsg[0].EuValue = fvalue*weatherpntmsg[0].AiParam.fFactor + weatherpntmsg[0].AiParam.EuValueDelta; + weatherpntmsg[AirTempNo].EuValue = fvalue*weatherpntmsg[AirTempNo].AiParam.fFactor + weatherpntmsg[AirTempNo].AiParam.EuValueDelta; } pPortParam->aiValue[0].AiState = 1; - weatherpntmsg[0].AiState = 1; + weatherpntmsg[AirTempNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x01); //if ((gDisSunRain & 0x80) == 0x80) { @@ -3103,15 +3103,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/10000.0; pPortParam->aiValue[5].EuValue *= (1+frnb); - weatherpntmsg[5].EuValue *= (1+frnb); + weatherpntmsg[AtmosNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[5].EuValue = fvalue*pPortParam->aiValue[5].AiParam.fFactor + pPortParam->aiValue[5].AiParam.EuValueDelta; - weatherpntmsg[5].EuValue = fvalue*weatherpntmsg[5].AiParam.fFactor + weatherpntmsg[5].AiParam.EuValueDelta; + weatherpntmsg[AtmosNo].EuValue = fvalue*weatherpntmsg[AtmosNo].AiParam.fFactor + weatherpntmsg[AtmosNo].AiParam.EuValueDelta; } pPortParam->aiValue[5].AiState = 1; - weatherpntmsg[5].AiState = 1; + weatherpntmsg[AtmosNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x10); //if ((gDisSunRain & 0x80) == 0x80) { @@ -3124,15 +3124,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; pPortParam->aiValue[1].EuValue *= (1+frnb); - weatherpntmsg[1].EuValue *= (1+frnb); + weatherpntmsg[HumidityNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[1].EuValue = fvalue*pPortParam->aiValue[1].AiParam.fFactor + pPortParam->aiValue[1].AiParam.EuValueDelta; - weatherpntmsg[1].EuValue = fvalue*weatherpntmsg[1].AiParam.fFactor + weatherpntmsg[1].AiParam.EuValueDelta; + weatherpntmsg[HumidityNo].EuValue = fvalue*weatherpntmsg[HumidityNo].AiParam.fFactor + weatherpntmsg[HumidityNo].AiParam.EuValueDelta; } pPortParam->aiValue[1].AiState = 1; - weatherpntmsg[1].AiState = 1; + weatherpntmsg[HumidityNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x02); //if ((gDisSunRain & 0x80) == 0x80) { @@ -3149,15 +3149,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; pPortParam->aiValue[2].EuValue *= (1+frnb); - weatherpntmsg[2].EuValue *= (1+frnb); + weatherpntmsg[WindSpeedNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[2].EuValue = fvalue*pPortParam->aiValue[2].AiParam.fFactor + pPortParam->aiValue[2].AiParam.EuValueDelta; - weatherpntmsg[2].EuValue = fvalue*weatherpntmsg[2].AiParam.fFactor + weatherpntmsg[2].AiParam.EuValueDelta; + weatherpntmsg[WindSpeedNo].EuValue = fvalue*weatherpntmsg[WindSpeedNo].AiParam.fFactor + weatherpntmsg[WindSpeedNo].AiParam.EuValueDelta; } pPortParam->aiValue[2].AiState = 1; - weatherpntmsg[2].AiState = 1; + weatherpntmsg[WindSpeedNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x04); //if ((gDisSunRain & 0x10) == 0x10) { @@ -3174,15 +3174,15 @@ void ShxyProtocolDataProcess( int devno) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; pPortParam->aiValue[3].EuValue *= (1+frnb); - weatherpntmsg[3].EuValue *= (1+frnb); + weatherpntmsg[WindDirectionNo].EuValue *= (1+frnb); } else { pPortParam->aiValue[3].EuValue = fvalue*pPortParam->aiValue[3].AiParam.fFactor + pPortParam->aiValue[3].AiParam.EuValueDelta; - weatherpntmsg[3].EuValue = fvalue*weatherpntmsg[3].AiParam.fFactor + weatherpntmsg[3].AiParam.EuValueDelta; + weatherpntmsg[WindDirectionNo].EuValue = fvalue*weatherpntmsg[WindDirectionNo].AiParam.fFactor + weatherpntmsg[WindDirectionNo].AiParam.EuValueDelta; } pPortParam->aiValue[3].AiState = 1; - weatherpntmsg[3].AiState = 1; + weatherpntmsg[WindDirectionNo].AiState = 1; //g_SelfTest.SensorsFault |= (0x08); //if ((gDisSunRain & 0x10) == 0x10) { @@ -3522,4 +3522,13 @@ void CameraPhotoCmd(SENSOR_PARAM *sensorParam, u_char channel, int cmdidx, u_cha GM_StartSerialCameraPhoto(1, cmdidx); } +int GetAirTempData(Data_DEF *airt) +{ + int i; + + if(NULL == airt) + return -1; + airt->EuValue = weatherpntmsg[AirTempNo].EuValue; + airt->AiState = weatherpntmsg[AirTempNo].AiState; +} diff --git a/app/src/main/cpp/SensorsProtocol.h b/app/src/main/cpp/SensorsProtocol.h index 194bba48..b02ad142 100644 --- a/app/src/main/cpp/SensorsProtocol.h +++ b/app/src/main/cpp/SensorsProtocol.h @@ -51,6 +51,20 @@ typedef unsigned char BYTE; #define RESERVE5_PROTOCOL 20 /* 备用5协议序号*/ #define INVALID_PROTOCOL 21 /* 无效协议序号*/ +#define AirTempNo 0 /* 空气温度数据存储序号*/ +#define HumidityNo 1 /* 相对湿度数据存储序号*/ +#define WindSpeedNo 2 /* 风速数据存储序号*/ +#define WindDirectionNo 3 /* 风向数据存储序号*/ +#define RainfallNo 4 /* 雨量数据存储序号*/ +#define AtmosNo 5 /* 大气压数据存储序号*/ +#define OpticalRadiationNo 6 /* 日照(光辐射)数据存储序号*/ + +#define Idle 0 /* 传感器处于空闲状态,未启动采样*/ +#define Sample 1 /* 正在采样过程中*/ +#define SamplingEnd 2 /* 采样结束*/ +#define StartSample 3 /* 启动采样*/ +#define SampleFail -1 /* 采样失败,传感器故障或未接*/ + #define WEATHER_DATA_NUM 8 /* 气象数据最大数量(一般最多是6要素)*/ #define RALLY_DATA_NUM 2 /* 拉力数据最大数量(一般是1个)*/ #define SLANTANGLE_DATA_NUM 3 /* 倾角数据最大数量(一般只有X轴和Y轴值)*/ @@ -140,19 +154,23 @@ typedef struct typedef struct { - //float fAiDead; // 数据变化死区(百分系数值,如:设置死区为5%,只需赋值5即可) float fFactor; // 数据系数 float EuValueDelta; // 数据工程值偏移 - //BYTE Polar; // 数据极性(有无符号位) } AI_PARAM; typedef struct { AI_PARAM AiParam; // 数据点配置参数 - BYTE AiState; // 遥测是否有效标识 - float EuValue; // 遥测工程值 + int AiState; // 数据标识(-1:采样失败;0:没有采样;1:正在采样;2:采样结束;3:启动采样;) + float EuValue; // 数据工程值 } AI_DEF; +typedef struct +{ + BYTE AiState; // 数据标识(-1:采样失败;0:没有采样;1:正在采样;2:采样结束;3:启动采样;) + float EuValue; // 数据工程值 +} Data_DEF; + typedef struct { int imagelen; // 整个图片大小