refine for output format

This commit is contained in:
Yunhorn 2023-12-28 19:06:01 +08:00
parent 9b5392ccef
commit ee78e4d1e8
4 changed files with 183 additions and 91 deletions

View File

@ -249,6 +249,7 @@ typedef struct
float maxTemp; /* 0-120 C */
float minTemp; /* 0-120 C */
float centerTemp; /* 0-120 C */
float averageTempInner; /* 0-120 C */
uint8_t spot_cnt; /* 0-20 max of v_water_cnt h_water_cnt */
uint8_t spillage_level; /* 0-99%, out of 768 dots */
uint8_t v_water_cnt;

View File

@ -44,7 +44,7 @@ uint32_t sts_hmac_verify(void)
ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code));
hmac_result.ac_pass = (ret == 0x0)?1U:0U;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nHMAC Verify Success = %u \r\n", hmac_result.ac_pass);
APP_LOG(TS_OFF, VLEVEL_L, "\r\nHMAC Verify Success = %u \r\n", hmac_result.ac_pass);
return ret;
}

View File

@ -60,10 +60,12 @@ extern volatile int sts_tof_distance_data[MAX_TOF_COUNT];
volatile uint32_t SamplingPeriodicity = 1000; //unit ms
volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms
volatile uint8_t STS_LoRa_WAN_Joined = 0;
#ifdef STS_TMG
extern volatile uint8_t waterTempThreshold;
extern volatile uint8_t normalPeopleTemp;
extern volatile uint8_t normalWaterTemp;
extern volatile uint8_t humanTempThreshold;
extern volatile uint8_t averageTempThreshold;
extern volatile uint8_t emmisivityThreshold;
#endif
volatile uint8_t heart_beat_timer =0;
char outbuf[128]="";
@ -812,8 +814,9 @@ static void SendTxData(void)
STS_OO_SensorDataTypeDef oo_data;
#endif
UTIL_TIMER_Time_t nextTxIn = 0;
AppData.Port = LORAWAN_USER_APP_PORT;
//if (LmHandlerIsBusy() == false)
if (LmHandlerIsBusy() == false)
{
uint8_t i = 0;
//MX_TOF_Process();
@ -853,22 +856,23 @@ static void SendTxData(void)
//APP_LOG(TS_ON, VLEVEL_L, "\r\nDistance = %d mm, VBAT=%d%%\r\n", r0_data.distance_mm, r0_data.battery_Pct);
AppData.Port = LORAWAN_USER_APP_PORT;
#ifdef ROCTEC_R5
#else
//#ifdef ROCTEC_R5
i = 0;
AppData.Buffer[i++] = AppLedStateOn;
AppData.Buffer[i++] = (uint8_t)(0xFF & sts_mtmcode1); //mtmcode1; //#02
AppData.Buffer[i++] = (uint8_t)(0xFF & sts_mtmcode2); //mtmcode2; //#03
AppData.Buffer[i++] = (uint8_t)(0xFF & sts_hardware_ver); //hardware_Ver; //#04
AppData.Buffer[i++] = (uint8_t)(0xFF & (99*batteryLevel/254)); //#05
#endif
//#endif
if (heart_beat_timer != 0U)
{
heart_beat_timer = 0U;
AppData.Port = LORAWAN_USER_HTBT_PORT; //LORAWAN_USER_APP_PORT+1;
AppData.Buffer[0] = AppLedStateOn|0x80;
i = 0;
AppData.Buffer[i++] = AppLedStateOn|0x80;
AppData.Buffer[i++] = (uint8_t)(0xFF & (99*batteryLevel/254)); //#05
#ifdef ROCTEC_R5
AppData.Buffer[i++] = AppLedStateOn;
AppData.Buffer[i++] = (uint8_t)(r0_data.battery_Pct);
@ -876,6 +880,7 @@ static void SendTxData(void)
} else if ((upload_message_timer !=0U)||(sensor_data_ready!=0U)) //sensor_data_ready for manual push button-1 trigger)
{
AppData.Port = LORAWAN_USER_APP_PORT;
sensor_data_ready =0;
upload_message_timer =0;
#ifdef ROCTEC_R5
@ -910,7 +915,9 @@ static void SendTxData(void)
#ifdef STS_TMG
AppData.Buffer[i++] = (uint8_t)(14)&0xff; //#length of following bytes
AppData.Buffer[i++] = (uint8_t)(m1a_data.waterSpillCount)&0xff; //#01
APP_LOG(TS_OFF, VLEVEL_L, "\r\n------------- SPOT_CNT =%d \r\n", (m1a_data.spot_cnt));
AppData.Buffer[i++] = (uint8_t)(m1a_data.spot_cnt)&0xff; //#01
AppData.Buffer[i++] = (uint8_t)(m1a_data.spillage_level)&0xff; //#02
AppData.Buffer[i++] = (uint8_t)(m1a_data.order[0])&0xff; //#03 non zero value is valid
@ -938,7 +945,11 @@ static void SendTxData(void)
}
AppData.BufferSize = (sts_service_mask >1?0:i);
APP_LOG(TS_OFF, VLEVEL_L, "xxxxxxxxxxxxxxxxxxxx before service mask assign APPDATA.PORT = %3d \r\n", AppData.Port);
AppData.BufferSize = (sts_service_mask == 0? i : 0);
APP_LOG(TS_OFF, VLEVEL_L, "xxxxxxxxxxxxxxxxxxxx after servce mask assign APPDATA.PORT = %3d \r\n", AppData.Port);
if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET))
{
@ -948,6 +959,8 @@ static void SendTxData(void)
#endif
}
APP_LOG(TS_OFF, VLEVEL_L, "xxxxxxxxxxxxxxxxxxxx before LmHandleSend APPDATA.PORT = %3d \r\n", AppData.Port);
status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
if (LORAMAC_HANDLER_SUCCESS == status)
{
@ -1025,18 +1038,18 @@ static void OnTxData(LmHandlerTxParams_t *params)
#endif
UTIL_TIMER_Start(&TxLedTimer);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n###### ========== MCPS-Confirm =============\r\n"); //YUNHORN TODO was VLEVEL_M
APP_LOG(TS_OFF, VLEVEL_M, "###### U/L FRAME:%04d | PORT:%d | DR:%d | PWR:%d", params->UplinkCounter, //YUNHORN TODO was VLEVEL_M
APP_LOG(TS_OFF, VLEVEL_L, "\r\n###### ========== MCPS-Confirm =============\r\n"); //YUNHORN TODO was VLEVEL_M
APP_LOG(TS_OFF, VLEVEL_L, "###### U/L FRAME:%04d | PORT:%d | DR:%d | PWR:%d", params->UplinkCounter, //YUNHORN TODO was VLEVEL_M
params->AppData.Port, params->Datarate, params->TxPower);
APP_LOG(TS_OFF, VLEVEL_M, " | MSG TYPE:");
APP_LOG(TS_OFF, VLEVEL_L, " | MSG TYPE:");
if (params->MsgType == LORAMAC_HANDLER_CONFIRMED_MSG)
{
APP_LOG(TS_OFF, VLEVEL_M, "CONFIRMED [%s]\r\n", (params->AckReceived != 0) ? "ACK" : "NACK");
APP_LOG(TS_OFF, VLEVEL_L, "CONFIRMED [%s]\r\n", (params->AckReceived != 0) ? "ACK" : "NACK");
}
else
{
APP_LOG(TS_OFF, VLEVEL_M, "UNCONFIRMED\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "UNCONFIRMED\r\n");
}
}
}
@ -1084,7 +1097,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
OnTxPeriodicityChanged(TxPeriodicity); TO-DO XXXXX
*/
APP_LOG(TS_OFF, VLEVEL_M,"\r\n STS_LoRa_WAN_Joined = %s \r\n", (STS_LoRa_WAN_Joined == 1)?"ABP":"OTAA");
APP_LOG(TS_OFF, VLEVEL_L,"\r\n STS_LoRa_WAN_Joined = %s \r\n", (STS_LoRa_WAN_Joined == 1)?"ABP":"OTAA");
}
else
{
@ -1381,7 +1394,7 @@ static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
/* USER CODE BEGIN OnTxPeriodicityChanged_2 */
APP_LOG(TS_OFF, VLEVEL_M,"**************** HeartBeatPeriodicity Changed to: %u (ms)\r\n", HeartBeatPeriodicity );
APP_LOG(TS_OFF, VLEVEL_L,"**************** HeartBeatPeriodicity Changed to: %u (ms)\r\n", HeartBeatPeriodicity );
/* USER CODE END OnTxPeriodicityChanged_2 */
}
@ -1532,13 +1545,13 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
} else if ((char)tlv_buf[CFG_CMD3] == 'S') { // Self Function Testing "YZS"
i=0;
memset(outbuf,0x30,sizeof(outbuf));
memset(outbuf,0x0,sizeof(outbuf));
STS_SENSOR_Function_Test_Process();
HAL_Delay(5000);
i=21;
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
} else if ((char)tlv_buf[CFG_CMD3] == 'C') { // Lora-WAN Class "YZC" LORAWAN CLASS A/B/C
@ -1550,7 +1563,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) sts_mtmcode2;
outbuf[i++] = (uint8_t) sts_version;
outbuf[i++] = (uint8_t) (0x41+ deviceClass); //translate to 'A','B','C'
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
} else if ((char)tlv_buf[CFG_CMD3] == 'D') { // Distance Measure "YZD"
i=0;
outbuf[i++] = (uint8_t) 'Y';
@ -1561,7 +1574,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
STS_SENSOR_Distance_Test_Process();
i=0;
memset(outbuf,0x30, sizeof(outbuf));
memset(outbuf,0x0, sizeof(outbuf));
outbuf[i++] = (uint8_t)'D';
outbuf[i++] = (uint8_t)sts_mtmcode1;
outbuf[i++] = (uint8_t)sts_mtmcode2;
@ -1590,7 +1603,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[2])%100)&0xff;
#endif
#endif
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
}
@ -1604,7 +1617,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) 'Y';
outbuf[i++] = (uint8_t) 'M';
outbuf[i++] = (uint8_t) (sts_service_mask+0x30);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
APP_LOG(TS_OFF, VLEVEL_L, ">>>>>>>>>>>>>>>>>>>>> Mask = [ %02x ] \r\n", sts_service_mask);
OnStoreSTSCFGContextRequest();
#ifdef YUNHORN_STS_O6_ENABLED
@ -1625,7 +1638,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) MajorVer;
outbuf[i++] = (uint8_t) MinorVer;
outbuf[i++] = (uint8_t) SubMinorVer;
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
//APP_LOG(TS_OFF, VLEVEL_L, "###### YUNHORN Report Version [ %X ] \r\n", outbuf);
}
else
@ -1634,7 +1647,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
uint8_t cfg_in_nvm[YUNHORN_STS_MAX_NVM_CFG_SIZE]="";
OnRestoreSTSCFGContextRequest((uint8_t *)cfg_in_nvm);
i=0;
memset(outbuf,0x30, sizeof(outbuf));
memset(outbuf,0x0, sizeof(outbuf));
outbuf[i++] = (uint8_t) 'C';
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM1]; //MTM Code
@ -1653,7 +1666,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
for (uint8_t j=0; j < cfg_in_nvm[NVM_LEN]; j++) {
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_CFG_START+j]);
}
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
}
break;
@ -1667,7 +1680,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
} else {
STS_SENSOR_Upload_Config_Invalid_Message();
}
@ -1681,7 +1694,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
} else {
STS_SENSOR_Upload_Config_Invalid_Message();
}
@ -1694,7 +1707,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
} else {
STS_SENSOR_Upload_Config_Invalid_Message();
}
@ -1723,7 +1736,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD4];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5];
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
// Save config to NVM
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
@ -1769,7 +1782,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD4];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5];
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
// Save config to NVM
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
@ -1810,10 +1823,11 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
mems_ver = (uint8_t)(tlv_buf[CFG_CMD3]-0x30);
uint8_t j=0;
if (mems_ver == sts_version)
{ // Firmware version or Variation of MEMS/component
#ifdef YUNHORN_STS_O6_ENABLED
uint8_t j=0;
if (tlv_buf_size >= CFG_CMD_TOF_SIMPLE_SIZE)
{
//Validation check
@ -1865,6 +1879,7 @@ P # # A # #
'W': Water threshold
'A': Average Temperature
'H': Human Body Temperature
'E': EMMISIVITY Threshold
+ -------- MSB OF PARAMETER
+ ------ LSB OF PARAMTER
@ -1874,40 +1889,54 @@ P # # A # #
{
//Validation check
invalid_flag = 0;
if (tlv_buf[CFG_CMD4] == 'W') {
if ((tlv_buf[CFG_CMD5]>='0')&&(tlv_buf[CFG_CMD6]<='9')&&(tlv_buf[CFG_CMD5]>='0')&&(tlv_buf[CFG_CMD5]<='9')) {
//volatile uint8_t waterTempThreshold=15, normalWaterTemp=25;
waterTempThreshold = (tlv_buf[CFG_CMD5]-0x30)*10+(tlv_buf[CFG_CMD6]-0x30);
} else {
invalid_flag = 1;
}
}
for (j =0; j < CFG_CMD_TMG_SIZE; j++)
if ((tlv_buf[CFG_CMD5]>='0')&&(tlv_buf[CFG_CMD5]<='9')&&(tlv_buf[CFG_CMD6]>='0')&&(tlv_buf[CFG_CMD6]<='9'))
{
sts_cfg_nvm.p[j] = (uint8_t)((tlv_buf[CFG_CMD4+j] - 0x30)&0xff);
APP_LOG(TS_OFF,VLEVEL_H,"\r\n tlv_buf %d = %02x cfg->p[%d]=%02x \r\n",
j,tlv_buf[CFG_CMD4+j], j, sts_cfg_nvm.p[j]);
uint8_t cmdValue = (tlv_buf[CFG_CMD5]-0x30)*10+(tlv_buf[CFG_CMD6]-0x30);
switch (tlv_buf[CFG_CMD4])
{
case 'A':
averageTempThreshold = cmdValue;
break;
case 'E':
emmisivityThreshold = cmdValue;
break;
case 'H':
humanTempThreshold = cmdValue;
break;
case 'W':
//volatile uint8_t waterTempThreshold=15, normalWaterTemp=25;
waterTempThreshold = cmdValue;
break;
default:
invalid_flag = 1;
break;
}
uint8_t j=0;
sts_cfg_nvm.p[j++] = (uint8_t)'A';
sts_cfg_nvm.p[j++] = (uint8_t)(averageTempThreshold)&0xFF;
sts_cfg_nvm.p[j++] = (uint8_t)'E';
sts_cfg_nvm.p[j++] = (uint8_t)(emmisivityThreshold)&0xFF;
sts_cfg_nvm.p[j++] = (uint8_t)'H';
sts_cfg_nvm.p[j++] = (uint8_t)(humanTempThreshold)&0xFF;
sts_cfg_nvm.p[j++] = (uint8_t)'W';
sts_cfg_nvm.p[j++] = (uint8_t)(waterTempThreshold)&0xFF;
//STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE();
STS_SENSOR_NVM_CFG_SIMPLE();
i=0; // Step 1: Prepare status update message
outbuf[i++] = (char) 'P';
outbuf[i++] = sts_mtmcode1;
outbuf[i++] = sts_mtmcode2;
outbuf[i++] = sts_version;
outbuf[i++] = sts_hardware_ver;
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD4];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5];
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD6];
APP_LOG(TS_OFF, VLEVEL_L, "###### CFG Received =%s Cmd=%02x Value=%2d\r\n",(char*)outbuf, tlv_buf[CFG_CMD4], cmdValue);
for (j=0; j < CFG_CMD_TMG_SIZE; j++)
{
outbuf[i++] = (uint8_t)(sts_cfg_nvm.p[j]+0x30)&0xff;
}
APP_LOG(TS_OFF, VLEVEL_H, "###### RSS Simple CFG=%s\r\n",*outbuf);
// Step 2: Save valid config to NVM
sts_cfg_nvm.mtmcode1 = sts_mtmcode1;
@ -1916,10 +1945,11 @@ P # # A # #
sts_cfg_nvm.hardware_ver = sts_hardware_ver;
sts_cfg_nvm.work_mode = sts_work_mode;
sts_cfg_nvm.sts_service_mask = sts_service_mask;
sts_cfg_nvm.length = CFG_CMD_TMG_SIZE;
sts_cfg_nvm.length = j;
OnStoreSTSCFGContextRequest();
}
}
#endif
// Invalid parameters
@ -1931,7 +1961,7 @@ P # # A # #
}
// Step 3: Upload status update message
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char *)outbuf);
}
@ -1993,8 +2023,10 @@ P # # A # #
void STS_SENSOR_Upload_Config_Invalid_Message(void)
{
APP_LOG(TS_OFF, VLEVEL_L, "xxxxxxxxxxxxxxxxxxxx Invalid Message APPDATA.PORT = %3d \r\n", AppData.Port);
if (sts_service_mask == STS_SERVICE_MASK_L0)
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 5, "PVXXX");
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 5, (char*)"PVXXX");
}
static void STS_YUNHORN_RFAC_HANDLE_PROCESS(void)
@ -2009,6 +2041,8 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char
LmHandlerErrorStatus_t status = LORAMAC_HANDLER_ERROR;
UTIL_TIMER_Time_t nextTxIn = 0;
APP_LOG(TS_OFF, VLEVEL_L, "xxxxxxxxxxxxxxxxxxxx Upload Message APPDATA.PORT = %3d \r\n", AppData.Port);
if (LmHandlerIsBusy() == false)
{
@ -2049,6 +2083,8 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char
UTIL_TIMER_SetPeriod(&TxTimer, MAX(nextTxIn, TxPeriodicity));
UTIL_TIMER_Start(&TxTimer);
}
APP_LOG(TS_OFF, VLEVEL_L, "xxxxxxxxxxxxxxxxxxxx APPDATA.PORT = %3d \r\n", AppData.Port);
}
@ -2080,6 +2116,7 @@ void OnStoreSTSCFGContextRequest(void)
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold;
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_reserve;
nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold;
if ((sts_cfg_nvm.ac[0]!=0x0) && (sts_cfg_nvm.ac[19]!=0x0)) {
for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) {
nvm_store_value[i++] = (sts_cfg_nvm.ac[j]);
@ -2188,6 +2225,9 @@ void OnRestoreSTSCFGContextProcess(void)
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
APP_LOG(TS_OFF, VLEVEL_L, "\r\n ================ STS SERVICE MASK --1 = %d \r\n", sts_service_mask);
if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))
{
//OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
@ -2214,6 +2254,22 @@ void OnRestoreSTSCFGContextProcess(void)
sts_work_mode = sts_cfg_nvm.work_mode;
sts_service_mask = sts_cfg_nvm.sts_service_mask;
APP_LOG(TS_OFF, VLEVEL_L, "\r\n ================ STS SERVICE MASK --2 = %d \r\n", sts_service_mask);
#ifdef STS_TMG
/*
volatile uint8_t averageTempThreshold;
volatile uint8_t emmisivityThreshold= (EMMISIVITY*100); // 96/100 = 0.96f
volatile uint8_t humanTempThreshold = 32;
volatile uint8_t waterTempThreshold=15; //15/10= 1.5 C
*/
averageTempThreshold = (float) sts_cfg_nvm.p[1];
emmisivityThreshold = (float) sts_cfg_nvm.p[3];
humanTempThreshold = (float) sts_cfg_nvm.p[5];
waterTempThreshold = (float) sts_cfg_nvm.p[7];
#endif
#ifdef YUNHORN_STS_O6_ENABLED
sts_lamp_bar_color = STS_GREEN;
sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10;

View File

@ -6,6 +6,8 @@
#include "sys_app.h"
#include "yunhorn_sts_sensors.h"
//#include "bmp.h"
#define FPS_HALF_HZ 0x00
#define FPS1HZ 0x01
#define FPS2HZ 0x02
#define FPS4HZ 0x03
#define FPS8HZ 0x04
@ -13,21 +15,31 @@
#define FPS32HZ 0x06
#define MLX90640_ADDR 0x33
#define RefreshRate FPS2HZ
#define EMMISIVITY 0.95f
#define RefreshRate FPS_HALF_HZ //FPS1HZ //was FPS2HZ
#define EMMISIVITY 0.96f //water Emisivity=0.96, human body == 0.92f
#define TA_SHIFT 8 //Default shift for MLX90640 in open air
paramsMLX90640 mlx90640;
static uint16_t eeMLX90640[832];
int status;
volatile uint8_t draw_legend_once=0, normalPeopleTemp=32, blackOutTag=0;
volatile uint8_t waterTempThreshold=15, normalWaterTemp=25;
volatile uint8_t draw_legend_once=0, blackOutTag=0;
// The following be stored in NVM
volatile uint8_t averageTempThreshold;
volatile uint8_t emmisivityThreshold= (EMMISIVITY*100); // 96/100 = 0.96f
volatile uint8_t humanTempThreshold = 32;
volatile uint8_t waterTempThreshold=15; //15/10= 1.5 C
// The Above be stored in NVM
volatile uint8_t normalWaterTemp=25; // 25 C
volatile uint8_t detectCycle=0, v_water_cnt=0,h_water_cnt=0, spot_cnt=0;
// start with some initial colors
volatile float minTemp = -20.0f;
volatile float maxTemp = 120.0f;
volatile float centerTemp=0.0f;
volatile float averageTemp=0.0f;
volatile float averageTempInner=0.0f;
volatile uint16_t waterSpillCount=0;
extern volatile uint8_t sensor_data_ready;
char tempBuffer[256];
@ -55,17 +67,18 @@ static void readTempValues(void);
static void bubbleSort(uint8_t arr[], uint8_t len, uint8_t order[]);
extern LCD_DrawPropTypeDef DrawProp;
/*
static uint16_t TempToColor(float val)
{
/*
pass in value and figure out R G B
several published ways to do this I basically graphed R G B and developed simple linear equations
again a 5-6-5 color display will not need accurate temp to R G B color calculation
equations based on
http://web-tech.ga-usa.com/2012/05/creating-a-custom-hot-to-cold-temperature-color-gradient-for-use-with-rrdtool/index.html
//pass in value and figure out R G B
//several published ways to do this I basically graphed R G B and developed simple linear equations
//again a 5-6-5 color display will not need accurate temp to R G B color calculation
//equations based on
//http://web-tech.ga-usa.com/2012/05/creating-a-custom-hot-to-cold-temperature-color-gradient-for-use-with-rrdtool/index.html
*/
red = constrain(255.0f / (c - b) * val - ((b * 255.0f) / (c - b)), 0, 255);
@ -95,25 +108,35 @@ static uint16_t TempToColor(float val)
// use the displays color mapping function to get 5-6-5 color palette (R=5 bits, G=6 bits, B-5 bits)
return BSP_LCD_GetColor565(red, green, blue);
}
*/
static void setTempScale(void) {
minTemp = 255;
maxTemp = 0;
averageTemp =0.0f;
averageTempInner =0.0f;
float sumtemp=0.0f;
float sumtempinner=0.0f;
for (i = 0; i < 768; i++)
{
//averageTemp += tempValues[i];
sumtemp += tempValues[i];
if (((uint8_t)(i/32) > 1)&& ((uint8_t)(i/32) <22) && ((uint8_t)(i%32) >1) && ((uint8_t)(i%32) <30))
{
sumtempinner += (float)tempValues[i];
}
minTemp = (float)min(minTemp, tempValues[i]);
maxTemp = (float)max(maxTemp, tempValues[i]);
}
//averageTemp /= 768;
averageTemp = sumtemp / (float)768.0;
averageTempInner = sumtempinner / (float)560.0; //28*20 inner round area
centerTemp = (float) ((tempValues[383 - 16] + tempValues[383 - 15] + tempValues[384 + 15] + tempValues[384 + 16]) / 4);
if (maxTemp > normalPeopleTemp)
if (maxTemp > (float)humanTempThreshold)
{
blackOutTag = 1;
} else {
@ -148,7 +171,7 @@ static void drawLegend(void)
for (ii = minTemp; ii < maxTemp; ii += inc) {
BSP_LCD_DrawVLine(8+ + j++, 260, 20, TempToColor(ii));
}
#endif
//BSP_LCD_FillRect(0,240,240, 320, LCD_COLOR_BLACK);
BSP_LCD_Clear(LCD_COLOR_BLACK);
draw_legend_once =1;
@ -167,8 +190,9 @@ static void drawLegend(void)
memset(tempBuffer,0,sizeof(tempBuffer));
sprintf(tempBuffer,(char *)" F10.MWC#1.Z#1");
BSP_LCD_DisplayStringAt(22, 15,(uint8_t *)tempBuffer,LEFT_MODE,LCD_COLOR_DARKBLUE);
#endif
}
#if 1
#if 0
BSP_LCD_SetFont(&Font16);
DrawProp.BackColor = LCD_COLOR_BLACK;
memset(tempBuffer,0,sizeof(tempBuffer));
@ -193,10 +217,10 @@ static void drawMeasurement(void ) {
centerTemp = (tempValues[383 - 16] + tempValues[383 - 15] + tempValues[384 + 15] + tempValues[384 + 16]) / 4;
#if 0
BSP_LCD_SetFont(&Font16);
#endif
memset(tempBuffer,0,sizeof(tempBuffer));
sprintf(tempBuffer,(char *)"%2d", (uint8_t)max(v_water_cnt, h_water_cnt));
#if 0
BSP_LCD_DisplayStringAt(ST7789V_LCD_PIXEL_WIDTH-60, 15,(uint8_t *)tempBuffer,LEFT_MODE,LCD_COLOR_YELLOW);
#endif
APP_LOG(TS_OFF, VLEVEL_M, "WaterSpillCount= %s\r\n",tempBuffer);
@ -291,7 +315,9 @@ static void readTempValues(void)
float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
MLX90640_CalculateTo(mlx90640Frame, &mlx90640, EMMISIVITY, tr, tempValues);
//MLX90640_CalculateTo(mlx90640Frame, &mlx90640, EMMISIVITY, tr, tempValues);
MLX90640_CalculateTo(mlx90640Frame, &mlx90640, (float)(emmisivityThreshold/100.0), tr, tempValues);
}
}
void blackOutFilter(void)
@ -358,46 +384,55 @@ void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
{
m1a_data->waterSpillCount = waterSpillCount;
m1a_data->spillage_level = (uint8_t)(waterSpillCount*99/80); //((ROW-2)*(COL-2))); // (24-4) * (32 -4) minus edge dots
m1a_data->spillage_level = (uint8_t)(waterSpillCount*99/560.0); //((ROW-2)*(COL-2))); // (24-4) * (32 -4) minus edge dots
m1a_data->averageTemp = averageTemp;
m1a_data->averageTempInner = averageTempInner;
m1a_data->centerTemp = centerTemp;
m1a_data->minTemp = minTemp;
m1a_data->maxTemp = maxTemp;
m1a_data->v_water_cnt = v_water_cnt;
m1a_data->h_water_cnt = h_water_cnt;
m1a_data->spot_cnt = max(v_water_cnt, h_water_cnt);
memset((void*)m1a_data->order, 0x0, sizeof(m1a_data->order));
m1a_data->spot_cnt = spot_cnt; //max(v_water_cnt, h_water_cnt);
// APP_LOG(TS_OFF, VLEVEL_L,"spill_cnt=%d, V_cnt=%d H_cnt=%d, Spot_cnt=%d \r\n", waterSpillCount, v_water_cnt, h_water_cnt, m1a_data->spot_cnt);
//memcpy((void *)m1a_data->waterSpillMatrix,(const void *) zoneMask,sizeof(zoneMask));
uint8_t i=0;
if (spot_cnt != 0) {
//bubbleSort((uint8_t*)upMask, (ROW/3)*(COL/3), (uint8_t*)order);
bubbleSort((void *)upMask, 80, (void *)order);
if (waterSpillCount != 0) {
bubbleSort((uint8_t*)upMask, (ROW/3)*(COL/3), (uint8_t*)order);
for (i= spot_cnt; i< 80;i++) {
order[i] = 0;
}
} else {
for (uint8_t i= waterSpillCount; i<80;i++) {
for (i= 0; i< 80;i++) {
order[i] = 0;
}
}
// memset((void*)m1a_data->order, 0x0, sizeof(m1a_data->order));
memcpy((void *)m1a_data->order, (const void *)order, sizeof(order));
//memset(order + m1a_data->spot_cnt, 0x0, sizeof(tempBuffer)-m1a_data->spot_cnt); // fill non-spot position to zero
memset(tempBuffer,0,sizeof(tempBuffer));
sprintf(tempBuffer,(char *)"\r\n## Read Sensor Spot CNT=%4d (areas) \r\n## V_cnt=%2d (lane) H_cnt=%2d (lane) \r\n## Spillage Level =%2.2f%% \r\n## averageTemp=%2.2f C centerTemp=%2.2f C MinTemp=%2.2f C maxTemp=%2.2f C \r\n",
m1a_data->waterSpillCount, v_water_cnt, h_water_cnt, (float)(m1a_data->spillage_level), (float)averageTemp, (float)centerTemp, (float)minTemp, (float)maxTemp);
sprintf(tempBuffer,(char *)"\r\n## Read Sensor Spot CNT=%4d (areas) \r\n## V_cnt=%2d (lane) H_cnt=%2d (lane) \r\n## Spillage Level =%2.2f%% \r\n## averageTempInner=%2.2f C averageTemp=%2.2f C centerTemp=%2.2f C MinTemp=%2.2f C maxTemp=%2.2f C \r\n ######## Gap_Average= %2.2f Gap_Inner = %2.2f \r\n",
m1a_data->waterSpillCount, v_water_cnt, h_water_cnt, (float)(m1a_data->spillage_level), (float)averageTempInner, (float)averageTemp, (float)centerTemp, (float)minTemp, (float)maxTemp, (float)(averageTemp - minTemp),(float)(averageTempInner - minTemp));
APP_LOG(TS_OFF, VLEVEL_L,(char *)tempBuffer);
if (m1a_data->waterSpillCount !=0 )
if (m1a_data->spot_cnt !=0 )
{
for (uint8_t i=0; i< 4; i++) {
memset(tempBuffer,0,sizeof(tempBuffer));
sprintf(tempBuffer, (char *) " Top {%1d} =order =%2u X=%2u : Y=%2u \r\n", i, order[i],
(uint8_t)(order[i]%(COL/3)), (uint8_t)(order[i]/(COL/3)));
(uint8_t)(order[i]%(10)), (uint8_t)(order[i]/10));
APP_LOG(TS_OFF, VLEVEL_L,(char *)tempBuffer);
}
}