wip not good so far

This commit is contained in:
Yunhorn 2024-09-18 20:04:16 +08:00
parent 7c35b1a55e
commit ded38d2cc0
2 changed files with 84 additions and 52 deletions

View File

@ -498,6 +498,9 @@ void LoRaWAN_Init(void)
} }
/* USER CODE BEGIN LoRaWAN_Init_Last */ /* USER CODE BEGIN LoRaWAN_Init_Last */
STS_REBOOT_CONFIG_Init();
#ifdef STS_P2 #ifdef STS_P2
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process); UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process);
@ -988,7 +991,7 @@ static void OnMacProcessNotify(void)
/* USER CODE END OnMacProcessNotify_2 */ /* USER CODE END OnMacProcessNotify_2 */
} }
static void OnTxPeriodicityChanged(uint32_t periodicity) void OnTxPeriodicityChanged(uint32_t periodicity)
{ {
/* USER CODE BEGIN OnTxPeriodicityChanged_1 */ /* USER CODE BEGIN OnTxPeriodicityChanged_1 */
@ -1218,9 +1221,27 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
* @brief Yunhorn STS Heart Beat Periodicity Chagne function * @brief Yunhorn STS Heart Beat Periodicity Chagne function
* @param duration of periodicty in ms (1/1000 sec) * @param duration of periodicty in ms (1/1000 sec)
*/ */
static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
{ {
/* USER CODE BEGIN OnTxPeriodicityChanged_1 */
/* USER CODE END OnTxPeriodicityChanged_1 */
if (periodicity == 0)
{
/* Revert to application default periodicity */
periodicity = 10*APP_TX_DUTYCYCLE; //10*10 000 ms
}
/* Update timer periodicity */
UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer);
UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, periodicity);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
/* USER CODE BEGIN OnTxPeriodicityChanged_2 */
APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 );
/* USER CODE END OnTxPeriodicityChanged_2 */
} }
/* USER CODE BEGIN PrFD_YunhornSTSWakeUpScanTimerEvents */ /* USER CODE BEGIN PrFD_YunhornSTSWakeUpScanTimerEvents */

View File

@ -875,10 +875,6 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
memset((void*)outbuf,0x0, sizeof(outbuf)); memset((void*)outbuf,0x0, sizeof(outbuf));
UTIL_MEM_cpy_8((void*)tlv_buf,(void*)parse_buffer, parse_buffer_size&0x7F); /* 127 BYTES MAX */ UTIL_MEM_cpy_8((void*)tlv_buf,(void*)parse_buffer, parse_buffer_size&0x7F); /* 127 BYTES MAX */
APP_LOG(TS_OFF, VLEVEL_M, "\n Auto_Responder_Parse: \n\t");
for (uint8_t x=0; x<parse_buffer_size; x++)
APP_LOG(TS_OFF, VLEVEL_M, "%02x\t", tlv_buf[x]);;
APP_LOG(TS_OFF, VLEVEL_M, "\n");
switch ((char)tlv_buf[CFG_CMD1]) switch ((char)tlv_buf[CFG_CMD1])
{ /* Begin of switch tlv_buf[CFG_CMD1] */ { /* Begin of switch tlv_buf[CFG_CMD1] */
/* 111111111111111111111111111111111111111111111111111111111111111111111 */ /* 111111111111111111111111111111111111111111111111111111111111111111111 */
@ -892,9 +888,9 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
case 'H': /* "YZH": BOARD SOFT RESET, REVIVE */ case 'H': /* "YZH": BOARD SOFT RESET, REVIVE */
//BOARD REVIVE //BOARD REVIVE
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, 20, (uint8_t *)"!YunHorn STS Revive!"); STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, 20, (uint8_t *)"!YunHorn STS Revive!");
HAL_Delay(5000); HAL_Delay(2000);
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Yunhorn STS Node Revive ... \r\n"); APP_LOG(TS_OFF, VLEVEL_H, "\r\n Yunhorn STS Node Revive ... \r\n");
HAL_Delay(3000); HAL_Delay(2000);
__set_FAULTMASK(1); __set_FAULTMASK(1);
NVIC_SystemReset(); NVIC_SystemReset();
//OnSystemReset(); //OnSystemReset();
@ -1101,17 +1097,18 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
} else if ((char)tlv_buf[CFG_CMD5] == 'H') { } else if ((char)tlv_buf[CFG_CMD5] == 'H') {
periodicity_length *= 3600; periodicity_length *= 3600;
} }
STS_TxPeriod_sec = periodicity_length;
periodicity_length = periodicity_length*1000; //translate to 1000ms=1s periodicity_length = periodicity_length*1000; //translate to 1000ms=1s
//OnTxPeriodicityChanged(TxPeriodicity); //OnTxPeriodicityChanged(periodicity_length);
#if defined(STS_O6)||defined(STS_O7) #if defined(STS_O6)||defined(STS_O7)
HeartBeatPeriodicity = periodicity_length;
OnYunhornSTSHeartBeatPeriodicityChanged(periodicity_length); OnYunhornSTSHeartBeatPeriodicityChanged(periodicity_length);
#endif #endif
// 2024-07-31 // 2024-07-31
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf)); UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,parse_buffer_size); UTIL_MEM_cpy_8((void*)outbuf,(void*)parse_buffer,parse_buffer_size);
i = parse_buffer_size; i = parse_buffer_size;
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);
@ -1147,6 +1144,12 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
heart_beat_or_sampling_periodicity_length *= 3600; heart_beat_or_sampling_periodicity_length *= 3600;
} }
STS_HeartBeatTimerPeriod_sec = heart_beat_or_sampling_periodicity_length;
#ifdef STS_P2
//OnYunhornSTSHeartBeatPeriodicityChanged(heart_beat_or_sampling_periodicity_length*1000);
#endif
#ifdef YUNHORN_STS_E0_ENABLED #ifdef YUNHORN_STS_E0_ENABLED
SamplingPeriodicity = heart_beat_or_sampling_periodicity_length*1000; //translate to 1000ms=1s SamplingPeriodicity = heart_beat_or_sampling_periodicity_length*1000; //translate to 1000ms=1s
OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity); OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity);
@ -1378,15 +1381,30 @@ void OnStoreSTSCFGContextRequest(void)
nvm_store_value[i++] = (sts_cfg_nvm.ac[j]); nvm_store_value[i++] = (sts_cfg_nvm.ac[j]);
} }
} }
for (uint8_t x=0; x< 64; x++)
{
if (x%16 ==0) APP_LOG(TS_OFF, VLEVEL_M, "\n");
APP_LOG(TS_OFF, VLEVEL_M, "%02x ",nvm_store_value[x]);
}
APP_LOG(TS_OFF, VLEVEL_M, "\n STS_CFG_NVM stored to NVM_STORE_VALUE\n");
/* USER CODE END OnStoreContextRequest_1 */ /* USER CODE END OnStoreContextRequest_1 */
/* store nvm in flash */ /* store nvm in flash */
//UTIL_MEM_cpy_8((void*)nvm_store_value, (void *)&sts_cfg_nvm,YUNHORN_STS_MAX_NVM_CFG_SIZE); //UTIL_MEM_cpy_8((void*)nvm_store_value, (void *)&sts_cfg_nvm,YUNHORN_STS_MAX_NVM_CFG_SIZE);
if (FLASH_IF_Erase(STS_CONFIG_NVM_BASE_ADDRESS, FLASH_PAGE_SIZE) == FLASH_IF_OK) if (FLASH_IF_Erase(STS_CONFIG_NVM_BASE_ADDRESS, FLASH_PAGE_SIZE) == FLASH_IF_OK)
{ {
FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE); APP_LOG(TS_OFF, VLEVEL_M, "\n ***********FLASH ERASED ***********\n");
if (FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE) == FLASH_IF_OK)
{
APP_LOG(TS_OFF, VLEVEL_M, "\n +++++++++++ FLASH OK +++++++++++++ \n");
} else {
APP_LOG(TS_OFF, VLEVEL_M, "\n ----------- FLASH ERROR ------------- \n");
}
//FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)&sts_cfg_nvm, YUNHORN_STS_MAX_NVM_CFG_SIZE); //FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)&sts_cfg_nvm, YUNHORN_STS_MAX_NVM_CFG_SIZE);
} else {
APP_LOG(TS_OFF, VLEVEL_M, "\n ***********FLASH NOT ERASED ***********\n");
} }
@ -1413,19 +1431,25 @@ void STS_REBOOT_CONFIG_Init(void)
/* USER CODE BEGIN OnRestoreContextRequest_1 */ /* USER CODE BEGIN OnRestoreContextRequest_1 */
/* USER CODE END OnRestoreContextRequest_1 */ /* USER CODE END OnRestoreContextRequest_1 */
UTIL_MEM_cpy_8(nvm_store_value, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE); //UTIL_MEM_cpy_8((void*)nvm_store_value, (void*)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE);
FLASH_IF_Read((void*)nvm_store_value, (void*)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE);
/* USER CODE BEGIN OnRestoreContextRequest_Last */ /* USER CODE BEGIN OnRestoreContextRequest_Last */
for (uint8_t x=0; x< 64; x++)
{
if (x%16 ==0) APP_LOG(TS_OFF, VLEVEL_M, "\n");
APP_LOG(TS_OFF, VLEVEL_M, "%02x ",nvm_store_value[x]);
}
if ((nvm_store_value[NVM_MTM1] != sts_mtmcode1) || (nvm_store_value[NVM_MTM2] != sts_mtmcode2) || (nvm_store_value[NVM_VER] != sts_version)) if ((nvm_store_value[NVM_MTM1] != sts_mtmcode1) || (nvm_store_value[NVM_MTM2] != sts_mtmcode2) || (nvm_store_value[NVM_VER] != sts_version))
{ {
APP_LOG(TS_OFF, VLEVEL_H, "\r\nInitial Boot with Empty Config, Flash with default config....\r\n"); APP_LOG(TS_OFF, VLEVEL_M, "\r\nInitial Boot with Empty Config, Flash with default config....\r\n");
OnStoreSTSCFGContextRequest(); OnStoreSTSCFGContextRequest();
//UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE); //UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE);
HAL_Delay(1000); HAL_Delay(1000);
NVIC_SystemReset();
} else } else
{ {
#if 0
sts_cfg_nvm.mtmcode1 = (uint8_t)nvm_store_value[NVM_MTM1]; sts_cfg_nvm.mtmcode1 = (uint8_t)nvm_store_value[NVM_MTM1];
sts_cfg_nvm.mtmcode2 = (uint8_t)nvm_store_value[NVM_MTM2]; sts_cfg_nvm.mtmcode2 = (uint8_t)nvm_store_value[NVM_MTM2];
sts_cfg_nvm.version = (uint8_t)nvm_store_value[NVM_VER]; sts_cfg_nvm.version = (uint8_t)nvm_store_value[NVM_VER];
@ -1443,16 +1467,24 @@ void STS_REBOOT_CONFIG_Init(void)
sts_cfg_nvm.p[j] = (uint8_t)nvm_store_value[NVM_CFG_START+j]; sts_cfg_nvm.p[j] = (uint8_t)nvm_store_value[NVM_CFG_START+j];
} }
sts_cfg_nvm.reserve02 =(uint8_t)nvm_store_value[NVM_RESERVE02];
sts_cfg_nvm.reserve03 =(uint8_t)nvm_store_value[NVM_RESERVE03];
sts_cfg_nvm.sensor_install_height_in_10cm =(uint8_t)nvm_store_value[NVM_SENSOR_INSTALL_HEIGHT];
sts_cfg_nvm.alarm_parameter05 =(uint8_t)nvm_store_value[NVM_ALARM_PARAMETER05];
sts_cfg_nvm.alarm_mute_reset_timer_in_10sec = (uint8_t)nvm_store_value[NVM_ALARM_MUTE_RESET_TIMER];
sts_cfg_nvm.alarm_lamp_bar_flashing_color = (uint8_t)nvm_store_value[NVM_ALARM_LAMP_BAR_FLASHING_COLOR];
sts_cfg_nvm.occupancy_overtime_threshold_in_10min = (uint8_t)nvm_store_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD];
sts_cfg_nvm.motionless_duration_threshold_in_min= (uint8_t)nvm_store_value[NVM_MOTIONLESS_DURATION_THRESHOLD];
sts_cfg_nvm.unconscious_or_motionless_level_threshold = (uint8_t)nvm_store_value[NVM_UNCONSCIOUS_LEVEL_THRESHOLD];
sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)nvm_store_value[NVM_FALL_DETECTION_ACC_THRESHOLD]; sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)nvm_store_value[NVM_FALL_DETECTION_ACC_THRESHOLD];
sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)nvm_store_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD]; sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)nvm_store_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD];
sts_cfg_nvm.fall_detection_reserve = (uint8_t)nvm_store_value[NVM_FALL_DETECTION_RESERVE]; sts_cfg_nvm.fall_confirm_threshold_in_10sec = (uint8_t)nvm_store_value[NVM_FALL_CONFIRM_THRESHOLD];
sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)nvm_store_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD];
for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) {
sts_cfg_nvm.ac[j] = (uint8_t)nvm_store_value[NVM_AC_CODE_START +j]; sts_cfg_nvm.ac[j] = (uint8_t)nvm_store_value[NVM_AC_CODE_START +j];
} }
#endif
UTIL_MEM_cpy_8((void*) &sts_cfg_nvm, (void*)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE); //UTIL_MEM_cpy_8((void*) &sts_cfg_nvm, (void*)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE);
} }
OnRestoreSTSCFGContextProcess(); OnRestoreSTSCFGContextProcess();
@ -1487,12 +1519,13 @@ void OnRestoreSTSCFGContextProcess(void)
{ // ensure it's not in production yet { // ensure it's not in production yet
//OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit //OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
//OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); TODO XXXX //OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); TODO XXXX
OnTxPeriodicityChanged(10000); // APP_TX_DUTYCYCLE in msec unit //OnTxPeriodicityChanged(10000); // APP_TX_DUTYCYCLE in msec unit
//TxPeriodicity = APP_TX_DUTYCYCLE;
} else } else
{ {
//OnTxPeriodicityChanged(TxPeriodicity); // in msec unit //OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
OnTxPeriodicityChanged(periodicity*1000); //OnTxPeriodicityChanged(periodicity*1000);
//Heart-beat or Sampling interval //Heart-beat or Sampling interval
sampling_heartbeat_periodicity = (sampling_heartbeat_periodicity > 0)? sampling_heartbeat_periodicity : 1; // in seconds unit sampling_heartbeat_periodicity = (sampling_heartbeat_periodicity > 0)? sampling_heartbeat_periodicity : 1; // in seconds unit
sampling_heartbeat_periodicity = sampling_heartbeat_periodicity*1000; sampling_heartbeat_periodicity = sampling_heartbeat_periodicity*1000;
@ -1695,28 +1728,6 @@ void OnYunhornSTSHeartBeatTimerEvent(void *context)
* YL x x x * YL x x x
* */ * */
void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
{
/* USER CODE BEGIN OnTxPeriodicityChanged_1 */
/* USER CODE END OnTxPeriodicityChanged_1 */
if (periodicity == 0)
{
/* Revert to application default periodicity */
periodicity = 10*APP_TX_DUTYCYCLE; //10*10 000 ms
}
/* Update timer periodicity */
UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer);
UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, periodicity);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
/* USER CODE BEGIN OnTxPeriodicityChanged_2 */
APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 );
/* USER CODE END OnTxPeriodicityChanged_2 */
}
/** /**
* @brief Yunhorn STS Sensor Sampling Periodicity/interval Change callback function * @brief Yunhorn STS Sensor Sampling Periodicity/interval Change callback function