diff --git a/TestComm/app/src/main/cpp/SensorsProtocol.cpp b/TestComm/app/src/main/cpp/SensorsProtocol.cpp index f862bd3b..349dbcd9 100644 --- a/TestComm/app/src/main/cpp/SensorsProtocol.cpp +++ b/TestComm/app/src/main/cpp/SensorsProtocol.cpp @@ -770,7 +770,7 @@ void Gm_InitSerialComm_Test() devparam[0].IsNoInsta = 1; //devparam[0].PowerPort = 2; //devparam[0].devaddr = 4; - devparam[0].devaddr = 2; + devparam[0].devaddr = 10; devparam[1].ProtocolIdx = WEATHER_PROTOCOL; devparam[1].baudrate = B9600; @@ -781,7 +781,7 @@ void Gm_InitSerialComm_Test() devparam[1].IsNoInsta = 1; //devparam[1].PowerPort = 14; //devparam[1].devaddr = 1; - devparam[1].devaddr = 13; + devparam[1].devaddr = 2; devparam[2].ProtocolIdx = RALLY_PROTOCOL; devparam[2].baudrate = B9600; @@ -1036,7 +1036,7 @@ void Gm_InitSerialComm() if(0 == devparam[i].IsNoInsta) sprintf(szbuf, "没有启用!;"); else - sprintf(szbuf, "已启用!;"); + sprintf(szbuf, "已启用!;"); LOGI("%s", szbuf); } #endif @@ -1201,13 +1201,15 @@ void GM_StartSerialComm() for(;;) { usleep(10); - LOGW("polltime=%ldms", get_msec()-polltime); + //LOGW("polltime=%ldms", get_msec()-polltime); polltime = get_msec(); if(GM_SerialTimer() < 0) { //LOGE("12V state=%d", getInt(CMD_SET_12V_EN_STATE)); LOGV("退出采样流程!"); - break; + sleep(15); + GM_StartSerialComm(); + //break; } } return; @@ -1223,10 +1225,11 @@ void GM_StartSerialCameraPhoto(BYTE channel, int cmdidx) srdt.RephotographCnt = 0; FindDevUseSerialCommNo(); +#if 0 //sprintf(szbuf, "sampling=%02X !", srdt.sampling); //DebugStringPrintf(szbuf, strlen(szbuf), 1); - if(0 == srdt.selfflag) - srdt.selfflag = 1; + //if(0 == srdt.selfflag) + // srdt.selfflag = 1; //Gm_OpenSerialPower(); //Gm_OpenSensorsPower(); //if(0x00 == srdt.sampling) @@ -1240,6 +1243,7 @@ void GM_StartSerialCameraPhoto(BYTE channel, int cmdidx) } if(0x01 == (srdt.sampling & 0x01)) flag = 0; +#endif // 初始化串口使用状态 for(i=0; i MAX_SERIAL_DEV_NUM)) + if((devno<0) || (devno > MAX_SERIAL_DEV_NUM)) { return; } - pPortParam = &serialport[devparam[commid].commid]; + pPortParam = &serialport[devparam[devno].commid]; for(i=0; im_au8RecvBuf, pPortParam->m_iRecvLen) == TRUE) { - ShxyProtocolDataProcess(commid); + ShxyProtocolDataProcess(devno); pPortParam->m_iRevStatus = 0; pPortParam->RevCmdFlag = 1; } @@ -2563,7 +2565,7 @@ int CheckShxyProtocolLpcError( u_char* msg, int len ) /********************************************************************************* 上海欣影传感器协议数据处理 **********************************************************************************/ -void ShxyProtocolDataProcess( int commid) +void ShxyProtocolDataProcess( int devno) { float fvalue, fcorvalue, *fvalua, frnb/*, fwind*/; WORD uDevAddr; @@ -2573,13 +2575,13 @@ void ShxyProtocolDataProcess( int commid) SIO_PARAM_SERIAL_DEF *curserial; char szbuf[64]; - pPortParam = &srdt.ms_dev[commid]; - curserial = &serialport[devparam[commid].commid]; + pPortParam = &srdt.ms_dev[devno]; + curserial = &serialport[devparam[devno].commid]; //取出装置地址,开始处理地址+++ if(0x02 == curserial->m_au8RecvBuf[5]) { - devparam[commid].devaddr = curserial->m_au8RecvBuf[4]; + devparam[devno].devaddr = curserial->m_au8RecvBuf[4]; return; } @@ -2613,7 +2615,7 @@ void ShxyProtocolDataProcess( int commid) slantpntmsg[aipnt][0].AiState = 1; //if ((gDisSunRain & 0x20) == 0x20) { - sprintf(szbuf, "倾角ID:%d slantangle X=%0.3f ", devparam[commid].devaddr, fvalue); + sprintf(szbuf, "倾角ID:%d slantangle X=%0.3f ", devparam[devno].devaddr, fvalue); LOGV("%s", szbuf); } //XslantSec[aipnt][srdt.SectimesamplingCnt[0]] = (short)slantpntmsg[aipnt][0].EuValue; @@ -2676,10 +2678,15 @@ void ShxyProtocolDataProcess( int commid) if((fvalue < -40) ||(fvalue > 85)) { frnb = (GeneratingRandomNumber()%101-50)/1000.0; + pPortParam->aiValue[0].EuValue *= (1+frnb); weatherpntmsg[0].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; + } + pPortParam->aiValue[0].AiState = 1; weatherpntmsg[0].AiState = 1; //g_SelfTest.SensorsFault |= (0x01); //if ((gDisSunRain & 0x80) == 0x80) @@ -2692,10 +2699,15 @@ void ShxyProtocolDataProcess( int commid) if((fvalue < 550) ||(fvalue > 1060)) { frnb = (GeneratingRandomNumber()%41-20)/10000.0; + pPortParam->aiValue[5].EuValue *= (1+frnb); weatherpntmsg[5].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; + } + pPortParam->aiValue[5].AiState = 1; weatherpntmsg[5].AiState = 1; //g_SelfTest.SensorsFault |= (0x10); //if ((gDisSunRain & 0x80) == 0x80) @@ -2708,10 +2720,15 @@ void ShxyProtocolDataProcess( int commid) if((fvalue < 0) ||(fvalue > 100)) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; + pPortParam->aiValue[1].EuValue *= (1+frnb); weatherpntmsg[1].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; + } + pPortParam->aiValue[1].AiState = 1; weatherpntmsg[1].AiState = 1; //g_SelfTest.SensorsFault |= (0x02); //if ((gDisSunRain & 0x80) == 0x80) @@ -2728,10 +2745,15 @@ void ShxyProtocolDataProcess( int commid) if((fvalue/1000 < 0) ||(fvalue/1000 > 80)) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; + pPortParam->aiValue[2].EuValue *= (1+frnb); weatherpntmsg[2].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; + } + pPortParam->aiValue[2].AiState = 1; weatherpntmsg[2].AiState = 1; //g_SelfTest.SensorsFault |= (0x04); //if ((gDisSunRain & 0x10) == 0x10) @@ -2748,10 +2770,15 @@ void ShxyProtocolDataProcess( int commid) if((fvalue/1000 < 0) ||(fvalue/1000 > 359.99)) { frnb = (GeneratingRandomNumber()%41-20)/1000.0; + pPortParam->aiValue[3].EuValue *= (1+frnb); weatherpntmsg[3].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; + } + pPortParam->aiValue[3].AiState = 1; weatherpntmsg[3].AiState = 1; //g_SelfTest.SensorsFault |= (0x08); //if ((gDisSunRain & 0x10) == 0x10) @@ -2777,56 +2804,58 @@ void ShxyProtocolDataProcess( int commid) else { #endif - pPortParam->recvdatacnt++; - if(pPortParam->recvdatacnt < 2) - break; - //g_SelfTest.SensorsFault |= (0x040<recvdatacnt++; + if(pPortParam->recvdatacnt < 2) + break; + + pPortParam->aiValue[0].EuValue = fvalue*pPortParam->aiValue[0].AiParam.fFactor\ + +pPortParam->aiValue[0].AiParam.EuValueDelta; + //rallypntmsg[aipnt][0].EuValue = fvalue*rallypntmsg[aipnt][0].AiParam.fFactor\ + // +rallypntmsg[aipnt][0].AiParam.EuValueDelta; + pPortParam->aiValue[0].AiState = 1; + //rallypntmsg[aipnt][0].AiState = 1; + sprintf(szbuf, "地址%d拉力:%0.3fKg ", devparam[devno].devaddr, fvalue); + LOGV("%s", szbuf); //} break; case 9: /*倾角传感器X轴倾角*/ if((fvalue < -59) ||(fvalue > 59)) { frnb = (GeneratingRandomNumber()%101-50)/1000.0; - slantpntmsg[aipnt][0].EuValue *= (1+frnb); + pPortParam->aiValue[0].EuValue *= (1+frnb); + //slantpntmsg[aipnt][0].EuValue *= (1+frnb); } else - slantpntmsg[aipnt][0].EuValue = fvalue*slantpntmsg[aipnt][0].AiParam.fFactor\ - +slantpntmsg[aipnt][0].AiParam.EuValueDelta; - slantpntmsg[aipnt][0].AiState = 1; - //if ((gDisSunRain & 0x20) == 0x20) { - sprintf(szbuf, "倾角ID:%d slantangle X=%0.3f ", devparam[commid].devaddr, fvalue); - LOGV("%s", szbuf); + pPortParam->aiValue[0].EuValue = fvalue*pPortParam->aiValue[0].AiParam.fFactor\ + +pPortParam->aiValue[0].AiParam.EuValueDelta; + //slantpntmsg[aipnt][0].EuValue = fvalue*slantpntmsg[aipnt][0].AiParam.fFactor\ + //+slantpntmsg[aipnt][0].AiParam.EuValueDelta; } + pPortParam->aiValue[0].AiState = 1; + //slantpntmsg[aipnt][0].AiState = 1; + sprintf(szbuf, "倾角ID:%d slantangle X=%0.3f ", devparam[devno].devaddr, fvalue); + LOGV("%s", szbuf); break; case 10: /*倾角传感器Y轴倾角*/ - { sprintf(szbuf, "Y =%0.3f ", fvalue); LOGV("%s", szbuf); - } + if((fvalue < -59) ||(fvalue > 59)) { frnb = (GeneratingRandomNumber()%101-50)/1000.0; + pPortParam->aiValue[1].EuValue *= (1+frnb); slantpntmsg[aipnt][1].EuValue *= (1+frnb); } else - slantpntmsg[aipnt][1].EuValue = fvalue*slantpntmsg[aipnt][1].AiParam.fFactor\ - +slantpntmsg[aipnt][1].AiParam.EuValueDelta; - slantpntmsg[aipnt][1].AiState = 1; + { + pPortParam->aiValue[1].EuValue = fvalue*pPortParam->aiValue[1].AiParam.fFactor\ + +pPortParam->aiValue[1].AiParam.EuValueDelta; + //slantpntmsg[aipnt][1].EuValue = fvalue*slantpntmsg[aipnt][1].AiParam.fFactor\ + // +slantpntmsg[aipnt][1].AiParam.EuValueDelta; + } + pPortParam->aiValue[1].AiState = 1; + //slantpntmsg[aipnt][1].AiState = 1; break; #if 0 case 11: /*测温球导线温度*/ diff --git a/TestComm/app/src/main/cpp/SensorsProtocol.h b/TestComm/app/src/main/cpp/SensorsProtocol.h index 9a4d9469..f8596d17 100644 --- a/TestComm/app/src/main/cpp/SensorsProtocol.h +++ b/TestComm/app/src/main/cpp/SensorsProtocol.h @@ -35,7 +35,8 @@ typedef unsigned char BYTE; #define IOT_PARAM_READ 0xAF #define MAX_SERIAL_DEV_NUM 25 /* 最大接串口传感器数量*/ -#define MAX_SERIAL_PORT_NUM 3 /* 最大串口数量*/ +#define MAX_SERIAL_PORT_NUM 3 +#define MAX_DEV_VALUE_NUM 12 /* 一台装置最大的采样值数量*/ #define WEATHER_PROTOCOL 1 /* 温湿度协议序号*/ #define WIND_PROTOCOL 2 /* 风速风向协议序号*/ @@ -143,7 +144,7 @@ typedef struct char stopbit[8]; /* 停止位*/ char parity; /* 校验位*/ char pathname[64]; /* 串口文件名及路径*/ - int commid; /* 串口序号*/ + int commid; /* 串口序号 注意:从0开始*/ u_char ProtocolIdx; /* 规约索引,大于 0*/ int devaddr; /* 装置使用的地址*/ u_char IsNoInsta; /* 装置没有安装或者已经坏了(1:正常, 0:无效,坏了或没有安装)*/ @@ -222,6 +223,7 @@ typedef struct u_char SameTypeDevIdx; /* 相同类型装置顺序排列序号(从0开始)*/ int iRecvTime; /* 最近一次收到数据的绝对时间*/ u_char uOpenPowerFlag; /* 传感器上电标志(0:不需要打开; 1:需要打开)*/ + AI_DEF aiValue[MAX_DEV_VALUE_NUM]; /* 传感器采样值*/ } SERIAL_DEV_DEF; //串口相关装置所有参数集中定义 diff --git a/TestComm/app/src/main/cpp/native-lib.cpp b/TestComm/app/src/main/cpp/native-lib.cpp index 0b571354..49cd91eb 100644 --- a/TestComm/app/src/main/cpp/native-lib.cpp +++ b/TestComm/app/src/main/cpp/native-lib.cpp @@ -633,7 +633,7 @@ Java_com_xinyingpower_testcomm_MainActivity_stringFromJNI( extern "C" JNIEXPORT jstring JNICALL Java_com_xinyingpower_testcomm_MainActivity_testSpi( JNIEnv* env, - jobject /* this */, jint port) { + jobject /* this */, jint port,jstring ss) { //testSpi(); SpiLIb a; unsigned char newkey[32]={0xaf,0x0c,0xa9,0x40,0x1f,0xe6,0xee,0x0f,0x4c, diff --git a/TestComm/app/src/main/java/com/xinyingpower/testcomm/MainActivity.java b/TestComm/app/src/main/java/com/xinyingpower/testcomm/MainActivity.java index e731c731..c52091db 100644 --- a/TestComm/app/src/main/java/com/xinyingpower/testcomm/MainActivity.java +++ b/TestComm/app/src/main/java/com/xinyingpower/testcomm/MainActivity.java @@ -1,5 +1,6 @@ package com.xinyingpower.testcomm; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; @@ -18,6 +19,7 @@ public class MainActivity extends AppCompatActivity { private ActivityMainBinding binding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -32,8 +34,10 @@ public class MainActivity extends AppCompatActivity { binding.btnSpi.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - String str = testSpi(0); - binding.sampleText.setText(str); + String s = binding.edtTEXT.getText().toString(); + Integer integer = Integer.valueOf(s); + String str = testSpi(integer,"ghghghh"); + binding.sampleText.setText(s); } }); @@ -48,12 +52,11 @@ public class MainActivity extends AppCompatActivity { } - /** * A native method that is implemented by the 'testcomm' native library, * which is packaged with this application. */ public native String stringFromJNI(); - public native String testSpi(int port); + public native String testSpi(int port,String ss); } \ No newline at end of file diff --git a/TestComm/app/src/main/res/layout/activity_main.xml b/TestComm/app/src/main/res/layout/activity_main.xml index 458f1c53..4f8a7657 100644 --- a/TestComm/app/src/main/res/layout/activity_main.xml +++ b/TestComm/app/src/main/res/layout/activity_main.xml @@ -24,5 +24,14 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + \ No newline at end of file