revised decoder and heart-beat keep sync message for O6/T6/L8/O1L

This commit is contained in:
Yunhorn 2025-05-27 12:24:37 +08:00
parent 3f18a075c1
commit ed9899355f
6 changed files with 63 additions and 48 deletions

View File

@ -1878,6 +1878,7 @@ static void OnYunhornSTSSelfFunctionTestStartEvent(void *context)
}
static void OnYunhornSTSHeartBeatTimerEvent(void *context)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Heart beat timer \r\n");
// UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer);
uint8_t appHeartBeatDataPort=2, appHeartBeatBufferSize=2, appHeartBeatDataBuffer[32]={0x0};
@ -1897,7 +1898,6 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
rfac_timer ++;
} else { // normal heart-beat process
#if 1
#ifdef STS_P2
appHeartBeatDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT;
#elif defined(STS_R1)
@ -1914,12 +1914,15 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
appHeartBeatDataPort = YUNHORN_STS_L8_LORA_APP_HTBT_PORT;
#endif
#if defined(L8)||defined(O6)||defined(O2)||defined(O6T)||defined(O1L)||defined(T6) // for keeping sync with webApp for state/lampbar color, in case failure of uplink message
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Keep Sync message for state/lamp bar color with web app\r\n");
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
#else
appHeartBeatBufferSize = 2;
appHeartBeatDataBuffer[0]=(uint8_t)(0x80|AppLedStateOn);
appHeartBeatDataBuffer[1]=(uint8_t)(SYS_GetBatteryLevel()/100); //TODO XXX change to battery level in mV
APP_LOG(TS_OFF, VLEVEL_M, "\n\n HEART-BEAT TIMER = %d\n\n", rfac_timer);
STS_SENSOR_Upload_Message(appHeartBeatDataPort, appHeartBeatBufferSize, (uint8_t*)appHeartBeatDataBuffer);
//APP_LOG(TS_OFF, VLEVEL_M, "\n\n HEART-BEAT TIMER = %d\n\n", rfac_timer);
STS_SENSOR_Upload_Message(appHeartBeatDataPort, appHeartBeatBufferSize, (uint8_t*)appHeartBeatDataBuffer);
#endif
}

View File

@ -186,7 +186,7 @@ volatile uint8_t sensor_data_ready=0;
#if defined(STS_R1)||defined(STS_R5)||defined(STS_R4)||defined(STS_R1D)
volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=30, STS_HeartBeatTimerPeriod_sec=3600;
#elif defined(STS_L8)||defined(STS_P2)||defined(STS_O6T)||defined(STS_T6)||defined(O1L)
volatile uint32_t STS_TOFScanPeriod_msec=5000, STS_TxPeriod_sec=300, STS_HeartBeatTimerPeriod_sec=3600;
volatile uint32_t STS_TOFScanPeriod_msec=5000, STS_TxPeriod_sec=300, STS_HeartBeatTimerPeriod_sec=360;
#endif
//volatile uint8_t sts_pir_state = 0, sts_pir_result=0;
volatile uint8_t last_sts_pir_read=0;

View File

@ -502,6 +502,7 @@ void STS_TOF_L8_Init(void)
{
MX_53L8A1_ThresholdDetection_Init();
MX_53L8A1_ThresholdDetection_Process();
}
void STS_TOF_L8_Process(void)

View File

@ -4,7 +4,7 @@
// - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string)
// The function must return an object, e.g. {"temperature": 22.5}
//
// Yunhorn SmarToilets Sensor R20250522R01
// Yunhorn SmarToilets Sensor R20250527R01
//
function Decode(fPort, data, variables) {
@ -363,29 +363,6 @@ function Decode(fPort, data, variables) {
return { "Yunhorn_SmarToilets_data": data };
}
break;
break;
// STS-O6 occupancy sensor heart-beat
case 18:
//data.led_state=(bytes[0] & 0x7f) === 0 ? "Off" : "On";
data.BoardLED = ((bytes[0] & 0x7F) === 0x01) ? "ON" : "OFF";
//data.battery_level = bytes[1] + " %";
data.battery_level = bytes[1] * 100 + "mV";
return { "Yunhorn_SmarToilets_data": data };
break;
// STS-O7 Fall detection sensor heart-beat
case 20:
break;
// STS-M7 Vibration sensor
case 20:
break;
// STS-R6 Weight Scale Sensor
@ -727,7 +704,7 @@ function Decode(fPort, data, variables) {
data.color_occupy = code2color[bytes[4] - 0x30];
data.color_vacant = code2color[bytes[5] - 0x30];
break;
case 7:
case 7: // 'F'
if (bytes[3] === 0x46) {
// F --- fall down & unconscious detection threshold
data.FALL_acceleration = (bytes[4] == 0x30 ? "Disabled" : ((bytes[4] - 0x30) * 10) + " mg/s2");
@ -738,29 +715,65 @@ function Decode(fPort, data, variables) {
}
break;
case 8:
if (bytes[3] === 0x4f) {
// O -- over stay, onconscious, long stay
data.OMU_Motionless_duration_in_min = (bytes[4] == 0x30 ? "Disabled" : ((bytes[4] - 0x30)) + " Min");
data.OMU_Long_Occupy_duration_in_Min = (bytes[5] == 0x30 ? "Disabled" : ((bytes[5] - 0x30) * 10) + " Min");
data.OMU_Unconcious_Threshold = (bytes[6] == 0x30 ? "Disabled" : ((bytes[6] - 0x30) * 100) + "ml");
data.OMU_Alarm_Mute_Reset_Timer = (bytes[7] == 0x30 ? "Disabled" : ((bytes[7] - 0x30) * 10) + " Seconds");
} else if (bytes[3] === 0x46) {
// F --- fall down & unconscious detection threshold
data.FALL_acceleration = (bytes[4] == 0x30 ? "Disabled" : ((bytes[4] - 0x30) * 10) + " mg/s2");
data.FALL_depth_measure = (bytes[5] == 0x30 ? "Disabled" : ((bytes[5] - 0x30) * 10) + " cm");
data.FALL_confirm_threshold = (bytes[6] == 0x30 ? "Disabled" : ((bytes[6] - 0x30) * 10) + " seconds");
data.FALL_reserved = (bytes[7] == 0x30 ? "Disabled" : ((bytes[6] - 0x30) * 10) + " min");
case 8: // 'G'
switch (bytes[3]) {
case 'G': // 0x4F 'G' -- RSS overstay config
// O -- over stay, unconscious, long stay
data.OMU_Motionless_duration_in_min = (bytes[4] == 0x30 ? "Disabled" : ((bytes[4] - 0x30)) + " Min");
data.OMU_Long_Occupy_duration_in_Min = (bytes[5] == 0x30 ? "Disabled" : ((bytes[5] - 0x30) * 10) + " Min");
data.OMU_Unconcious_Threshold = (bytes[6] == 0x30 ? "Disabled" : ((bytes[6] - 0x30) * 100) + "ml");
data.OMU_Alarm_Mute_Reset_Timer = (bytes[7] == 0x30 ? "Disabled" : ((bytes[7] - 0x30) * 10) + " Seconds");
break;
case 'F': // 0x46 'F' -- RSS fall down cfg
// F --- fall down & unconscious detection threshold
data.FALL_acceleration = (bytes[4] == 0x30 ? "Disabled" : ((bytes[4] - 0x30) * 10) + " mg/s2");
data.FALL_depth_measure = (bytes[5] == 0x30 ? "Disabled" : ((bytes[5] - 0x30) * 10) + " cm");
data.FALL_confirm_threshold = (bytes[6] == 0x30 ? "Disabled" : ((bytes[6] - 0x30) * 10) + " seconds");
data.FALL_reserved = (bytes[7] == 0x30 ? "Disabled" : ((bytes[6] - 0x30) * 10) + " min");
break;
case 'T':
var t_data = (bytes[5]-0x30)*100+(bytes[6]-0x30)*10+(bytes[7]-0x30)*1;
switch (bytes[4]) {
case '1':
data.fallDownL8_CFG_Head_level_treshold_cm = t_data + " cm";
break;
case '2':
data.fallDownL8_CFG_Suspicious_fall_treshold_sec = t_data*15 + " sec";
break;
case '3':
data.fallDownL8_CFG_High_potential_fall_treshold_sec = t_data * 15 + " sec";
break;
case '4':
data.fallDownL8_CFG_Motionless_short_treshold_sec = t_data * 15 + " sec";
break;
case '5':
data.fallDownL8_CFG_Motionless_long_treshold_sec = t_data * 15 + " sec";
break;
case '6':
data.fallDownL8_CFG_Occupancy_overstay_treshold_sec = t_data * 15 + " sec";
break;
case '7':
data.fallDownL8_CFG_Mask_off_height_treshold_cm = t_data + " cm";
break;
case '8':
data.fallDownL8_CFG_Gesture_min_height_treshold_cm = t_data + " cm";
break;
}
break;
}
break;
case 11:
case 11: // RSS RADAR START LENGTH THRESHOLD GAIN
// P 1108201365
data.RSS_SIMPLE_Start = ((bytes[3] - 0x30) * 100 + (bytes[4] - 0x30) * 10) + " cm";
data.RSS_SIMPLE_Length = ((bytes[5] - 0x30) * 100 + (bytes[6] - 0x030) * 10) + " cm";
data.RSS_SIMPLE_Threshold = ((bytes[7] - 0x30) * 1000 + (bytes[8] - 0x30) * 100) + " ml";
data.RSS_SIMPLE_Gain = ((bytes[9] - 0x30) * 10 + (bytes[10] - 0x30)) + " %";
break;
case 33:
case 33: // RSS RADAR FULL CONFIG
// P 11
data.RSS_FULL_Start = ((bytes[3] - 0x30) * 100 + (bytes[4] - 0x30) * 10) + " cm";
data.RSS_FULL_Length = ((bytes[5] - 0x30) * 100 + (bytes[6] - 0x30) * 10) + " cm";
@ -786,9 +799,7 @@ function Decode(fPort, data, variables) {
break;
}
break;
break; // end of 'P' cmd
// CONTROL COMMAND 'R'
case 0x52: