This commit is contained in:
Yunhorn 2024-09-18 15:55:21 +08:00
parent 1378c71212
commit 770ba611dd
3 changed files with 101 additions and 25 deletions

View File

@ -169,7 +169,7 @@ typedef struct sts_cfg_nvm {
uint8_t alarm_parameter05; uint8_t alarm_parameter05;
uint8_t alarm_mute_reset_timer_in_10sec; //60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec uint8_t alarm_mute_reset_timer_in_10sec; //60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec
uint8_t alarm_lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE uint8_t alarm_lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
uint8_t occupancy_overtime_threshold_in_10min; // 0 - 9 0disable, 1-9 occupy over time threshold * 10 min uint8_t occupancy_overtime_threshold_in_10min; // 0 - 9 0disable, 1-9 occupy over time threshold * 10 min
uint8_t motionless_duration_threshold_in_min; // 10(0x0A) min (2 min.) motionless_duration_threshold_in_min uint8_t motionless_duration_threshold_in_min; // 10(0x0A) min (2 min.) motionless_duration_threshold_in_min
uint8_t unconscious_or_motionless_level_threshold; // 0 - 9 motion level *128 uint8_t unconscious_or_motionless_level_threshold; // 0 - 9 motion level *128

View File

@ -39,7 +39,59 @@
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "app_tof.h" #include "app_tof.h"
volatile sts_cfg_nvm_t sts_cfg_nvm={0x0}; volatile sts_cfg_nvm_t sts_cfg_nvm = {
sts_mtmcode1,
sts_mtmcode2,
sts_version,
sts_hardware_ver,
0x05, //Regular TxPeriodicity interval
'M', //Uplink data interval unit, for heart-beat uplink
0x01, //Heart-beat interval or Sampling interval
'S', //Sampling sensor interval unit, for real-time sensing of MEMS
0x04, // dual mode=4, uni_mode =5
0x00, // sts service mask
0x00, //sts_ioc_mask
0x20, //32 bytes, below start of p[0] 20 BYTES AND 12 BYTES FALL DOWN CFG
{ // below 20 bytes
0x08, //start_m [8]*0.1 meter =0.8
0x19, //lenght_m 0x19=[25]*0.1=2.5f meter
0x0F, //threshold 0X0F=[15]*0.1=1.5f
0x28, //receiver gain 0x28 =[40]*0.01=0.40f max 99=0x63
0x04, //profile [4]=4
0x0A, //rate tracking 0x0A=10= 10U
0x41, //rate presence 0x41=65= 65U
0x3F, //hwaas 0x3F=63 =63U
0x00, //nbr removed pc [0]=0
0x05, //inter frame deviation time const 0x05=[5]*0.1=0.5f
0x0A, //inter frame fast cutoff 0x0A=[10] = 10U
0x01, //inter frame slow cutoff,0x01=1[1]*0.01=0.01f
0x00, //intra frame time const [0]=0 Lower to reduce sensitivity, higher to increase sensitivity
0x0A, //intra frame weight, 0x00=[0]*0.1=0.0F 0x0A=10, 10*0.1=1 FOR FAST MOVEMENT TRACKING FALL DETECTION
0x05, //output time const 0x05=[5]*0.1=0.5
0x02, //downsampling factor [2]=2
0x03, //power saving mode ACTIVE [3] = 3U
0x00, //reserve --P[17]
0x00, //reserve --P[18]
0x00, //reserve --P[19]
}, // above 20 bytes
0x00, //reserve2
0x00, //reserve3
0x20, //sensor install height in 10 cm, default 32*10=320cm, 3.2meter
0x00, //reserve5 alarm_parameter05
0x06, //reserve6 alarm_mute_or_reset_expire_timer_in_10sec, 60 seconds
0x23, //reserve7 alarm Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
0x03, //reserve8 occupancy over time threshold 3*10 = 30 minutes
0x09, //reserve8 motionless_duration_threshold_in_min+1, normal: 10 min(0x0A) Minutes (2 min.) 1-9== 2-10min
0x09, //unconscious threshold * 128, 0-9, 9*128=1280 motion level
0x01, //fall_detection_acc_threshold = *10 acceleration measure
0x03, //fall detection_depth_threshold *10cm
0x03, //falldown_confirm_threshold_in_10sec, 0x3=30 sec default
// below 20 bytes for RFAC code
{0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0}
};
volatile uint8_t sts_ac_code[20]={0x0}; volatile uint8_t sts_ac_code[20]={0x0};
volatile uint8_t sts_service_mask=STS_SERVICE_MASK_L0; volatile uint8_t sts_service_mask=STS_SERVICE_MASK_L0;
volatile uint8_t sts_work_mode=4; volatile uint8_t sts_work_mode=4;
@ -861,7 +913,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
break; break;
case 'D': /* "YZD": Distance/Install height Measure */ case 'D': /* "YZD": Distance/Install height Measure */
STS_SENSOR_Distance_Test_Process(); STS_SENSOR_Distance_Test_Process();
sts_cfg_nvm.sensor_install_height_in_10cm = sts_sensor_install_height/10; //in 10 cm sts_cfg_nvm.sensor_install_height_in_10cm = sts_sensor_install_height/100; //in 10 cm, say 4500mm=450cm=45 dm
APP_LOG(TS_OFF, VLEVEL_M, "\n STS CFG NVM -> SENSOR INSTALL HEIGHT STORED = %d CM\n", sts_cfg_nvm.sensor_install_height_in_10cm); APP_LOG(TS_OFF, VLEVEL_M, "\n STS CFG NVM -> SENSOR INSTALL HEIGHT STORED = %d CM\n", sts_cfg_nvm.sensor_install_height_in_10cm);
OnStoreSTSCFGContextRequest(); OnStoreSTSCFGContextRequest();
i = 0; i = 0;
@ -871,9 +923,14 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
outbuf[i++] = (uint8_t)sts_version; outbuf[i++] = (uint8_t)sts_version;
outbuf[i++] = (uint8_t)sts_hardware_ver; outbuf[i++] = (uint8_t)sts_hardware_ver;
outbuf[i++] = (uint8_t)(99*((GetBatteryLevel()/254)&0xff)); outbuf[i++] = (uint8_t)(99*((GetBatteryLevel()/254)&0xff));
outbuf[i++] = (uint8_t)(4); //four bytes for distance
#ifdef VL53LX #ifdef VL53LX
outbuf[i++] = (uint8_t)(sts_sensor_install_height>>8)&0xFF; outbuf[i++] = (uint8_t)(sts_sensor_install_height/1000+0x30)&0xff;
outbuf[i++] = (uint8_t)(sts_sensor_install_height)&0xFF; outbuf[i++] = (uint8_t)((sts_sensor_install_height/100)%10+0x30)&0xff;
outbuf[i++] = (uint8_t)((sts_sensor_install_height/10)%10+0x30)&0xff;
outbuf[i++] = (uint8_t)((sts_sensor_install_height/1)%10+0x30)&0xff;
//outbuf[i++] = (uint8_t)(sts_sensor_install_height>>8)&0xFF;
//outbuf[i++] = (uint8_t)(sts_sensor_install_height)&0xFF;
#endif #endif
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
@ -907,20 +964,21 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
outbuf[i++] = (uint8_t) MajorVer; outbuf[i++] = (uint8_t) MajorVer;
outbuf[i++] = (uint8_t) MinorVer; outbuf[i++] = (uint8_t) MinorVer;
outbuf[i++] = (uint8_t) SubMinorVer; outbuf[i++] = (uint8_t) SubMinorVer;
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
break; break;
case 'C': case 'C':
uint8_t cfg_in_nvm[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0}; uint8_t cfg_in_nvm[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0};
OnRestoreSTSCFGContextRequest((uint8_t *)cfg_in_nvm); OnRestoreSTSCFGContextRequest((void*)&cfg_in_nvm);
i=0; i=0;
#if 0
outbuf[i++] = (uint8_t) 'C'; outbuf[i++] = (uint8_t) 'C';
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM1]; //MTM Code outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM1]; //MTM Code
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM2]; //MTM Code outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM2]; //MTM Code
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_VER]; //STS Version outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_VER]; //STS Version
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_HWV]; //STS Version outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_HWV]; //STS Version
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_PERIODICITY]); //UPLINK Periodicity outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_PERIODICITY]; //UPLINK Periodicity
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_UNIT]; //UPLINK Periodicity unit outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_UNIT]; //UPLINK Periodicity unit
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_SAMPLING]); //Heart-beat or SAMPLING Periodicity outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SAMPLING]; //Heart-beat or SAMPLING Periodicity
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_S_UNIT]; //Heart-beat or SAMPLING Periodicity unit outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_S_UNIT]; //Heart-beat or SAMPLING Periodicity unit
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_WORK_MODE]; // STS WORK MODE outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_WORK_MODE]; // STS WORK MODE
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SERVICE_MASK]; //service mask outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SERVICE_MASK]; //service mask
@ -930,6 +988,9 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
for (uint8_t j=0; j < cfg_in_nvm[NVM_LEN]; j++) { for (uint8_t j=0; j < cfg_in_nvm[NVM_LEN]; j++) {
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_CFG_START+j]); outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_CFG_START+j]);
} }
#endif
UTIL_MEM_cpy_8(outbuf, cfg_in_nvm,44);
i=44;
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
break; break;
@ -1273,7 +1334,7 @@ void OnStoreSTSCFGContextRequest(void)
{ {
/* USER CODE BEGIN OnStoreContextRequest_1 */ /* USER CODE BEGIN OnStoreContextRequest_1 */
uint8_t nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0}; uint8_t nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0},i=0,j=0;
#if 1 #if 1
sts_cfg_nvm.length = STS_NVM_CFG_SIZE; sts_cfg_nvm.length = STS_NVM_CFG_SIZE;
nvm_store_value[i++] = sts_cfg_nvm.mtmcode1; nvm_store_value[i++] = sts_cfg_nvm.mtmcode1;
@ -1287,22 +1348,35 @@ void OnStoreSTSCFGContextRequest(void)
nvm_store_value[i++] = sts_cfg_nvm.work_mode; nvm_store_value[i++] = sts_cfg_nvm.work_mode;
nvm_store_value[i++] = sts_cfg_nvm.sts_service_mask; nvm_store_value[i++] = sts_cfg_nvm.sts_service_mask;
nvm_store_value[i++] = sts_cfg_nvm.sts_ioc_mask; nvm_store_value[i++] = sts_cfg_nvm.sts_ioc_mask;
nvm_store_value[i++] = (uint8_t) STS_NVM_CFG_SIZE; //sts_cfg_nvm.length; nvm_store_value[i++] = (uint8_t) STS_CFG_PCFG_SIZE; //sts_cfg_nvm.length;
#endif
for (j = 0; j < STS_CFG_PCFG_SIZE; j++) { for (j = 0; j < STS_CFG_PCFG_SIZE; j++) {
nvm_store_value[i++] = (sts_cfg_nvm.p[j]); nvm_store_value[i++] = (sts_cfg_nvm.p[j]);
} }
#if 1
nvm_store_value[i++] = sts_cfg_nvm.reserve02;
nvm_store_value[i++] = sts_cfg_nvm.reserve03;
nvm_store_value[i++] = sts_cfg_nvm.sensor_install_height_in_10cm;
nvm_store_value[i++] = sts_cfg_nvm.alarm_parameter05;
nvm_store_value[i++] = sts_cfg_nvm.alarm_mute_reset_timer_in_10sec;
nvm_store_value[i++] = sts_cfg_nvm.alarm_lamp_bar_flashing_color;
nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold_in_10min;
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_acc_threshold; nvm_store_value[i++] = sts_cfg_nvm.fall_detection_acc_threshold;
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold; nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold;
nvm_store_value[i++] = sts_cfg_nvm.fall_confirm_threshold_in_10sec; nvm_store_value[i++] = sts_cfg_nvm.fall_confirm_threshold_in_10sec;
nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold; nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold_in_10min;
#endif
if ((sts_cfg_nvm.ac[0]!=0x0) && (sts_cfg_nvm.ac[19]!=0x0)) { if ((sts_cfg_nvm.ac[0]!=0x0) && (sts_cfg_nvm.ac[19]!=0x0)) {
for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) { for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) {
nvm_store_value[i++] = (sts_cfg_nvm.ac[j]); nvm_store_value[i++] = (sts_cfg_nvm.ac[j]);
} }
} }
#endif
/* USER CODE END OnStoreContextRequest_1 */ /* USER CODE END OnStoreContextRequest_1 */
/* store nvm in flash */ /* store nvm in flash */
@ -1487,7 +1561,6 @@ void STS_SENSOR_MEMS_Get_ID(uint16_t *devID)
void STS_SENSOR_Function_Test_Process(void) void STS_SENSOR_Function_Test_Process(void)
{ {
char tstbuf[128] =""; uint8_t i=0; char tstbuf[128] =""; uint8_t i=0;
uint8_t count = 0;
tstbuf[i++] = (uint8_t) 'S'; tstbuf[i++] = (uint8_t) 'S';
tstbuf[i++] = (uint8_t) sts_mtmcode1; tstbuf[i++] = (uint8_t) sts_mtmcode1;
@ -1496,18 +1569,21 @@ void STS_SENSOR_Function_Test_Process(void)
tstbuf[i++] = (uint8_t) sts_hardware_ver; tstbuf[i++] = (uint8_t) sts_hardware_ver;
tstbuf[i++] = (uint8_t) (99*GetBatteryLevel()/254)&0xff; tstbuf[i++] = (uint8_t) (99*GetBatteryLevel()/254)&0xff;
#ifdef STS_P2
STS_SENSOR_MEMS_Get_ID(&sensor_id); STS_SENSOR_MEMS_Get_ID(&sensor_id);
if (((sensor_id & 0xff)== 0xCC) && (((sensor_id >>8) & 0xFF)==0xEA)) if (((sensor_id & 0xff)!= 0xCC) || (((sensor_id >>8) & 0xFF)!=0xEA)) // no VL53LX found
count = 1;
if (count ==0)
{ {
tstbuf[i++] = (uint8_t) 'X'; // Slave MEMS Not Avaliable tstbuf[i++] = (uint8_t) 'X'; // Slave MEMS Not Avaliable
} } else
else
{ {
//tstbuf[i++] = (uint8_t) (count*2+1)&0xff; //length of following data STS_SENSOR_Distance_Test_Process();
APP_LOG(TS_OFF, VLEVEL_M, "\nSensor Install Height =%4d mm\n", sts_sensor_install_height);
tstbuf[i++] = (uint8_t) (2+1)&0xff; //length of following data
tstbuf[i++] = (uint8_t) (sts_sensor_install_height>>8)&0xff; // MSB of sensor height
tstbuf[i++] = (uint8_t) (sts_sensor_install_height)&0xff; // LSB of sensor height
}
#endif
#ifdef YUNHORN_STS_O6_ENABLED #ifdef YUNHORN_STS_O6_ENABLED
tstbuf[i++] = (uint8_t)20; //length of following data tstbuf[i++] = (uint8_t)20; //length of following data
uint8_t self_test_result[10]={0,0,0,0,0, 0,0,0,0,0}; uint8_t self_test_result[10]={0,0,0,0,0, 0,0,0,0,0};
@ -1545,9 +1621,9 @@ void STS_SENSOR_Function_Test_Process(void)
#endif #endif
#endif #endif
}
memset((void*)outbuf,0x0,sizeof(outbuf)); UTIL_MEM_set_8((void*)outbuf,0x0,sizeof(outbuf));
memcpy((void*)outbuf, tstbuf, i); UTIL_MEM_cpy_8((void*)outbuf, tstbuf, i);
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);

View File

@ -120,7 +120,7 @@ uint8_t IsInterruptDetected(uint16_t dev)
void STS_TOF_VL53LX_Range_Process(uint8_t range_mode, uint16_t *range_distance) void STS_TOF_VL53LX_Range_Process(uint8_t range_mode, uint16_t *range_distance)
{ {
//uint8_t vl53lx_model = STS_TOF_VL53L1X; //uint8_t vl53lx_model = STS_TOF_VL53L1X;
uint8_t range_mode = STS_TOF_SHORT_RANGE; //uint8_t range_mode = STS_TOF_SHORT_RANGE;
uint16_t i_distance_measured = 0; uint16_t i_distance_measured = 0;
uint16_t i_distance_threshold_mm = 800; uint16_t i_distance_threshold_mm = 800;
uint16_t i_inter_measurement_ms=100, i_macro_timing=33; uint16_t i_inter_measurement_ms=100, i_macro_timing=33;