add do_fft_flag with uplink config and downlink command. tested ok

This commit is contained in:
Yunhorn 2024-02-23 17:52:06 +08:00
parent 0ceaae5baa
commit fba4492fe3
5 changed files with 40 additions and 21 deletions

View File

@ -47,7 +47,7 @@ extern "C" {
/**
* @brief Verbose level for all trace logs
*/
#define VERBOSE_LEVEL VLEVEL_OFF
#define VERBOSE_LEVEL VLEVEL_H
/**
* @brief Enable trace logs
@ -75,7 +75,7 @@ extern "C" {
* @brief Enable/Disable MCU Debugger pins (dbg serial wires)
* @note by HW serial wires are ON by default, need to put them OFF to save power
*/
#define DEBUGGER_ENABLED 0
#define DEBUGGER_ENABLED 1
/**
* @brief Disable Low Power mode

View File

@ -74,7 +74,7 @@
#define STS_MODE_COLOR_CMD_LEN 5U
#define YUNHORN_STS_M7_NVM_CFG_SIZE 3U
#define YUNHORN_STS_M7_CFG_CMD_SIZE 9U
#define YUNHORN_STS_M7_CFG_CMD_SIZE 10U
#define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U
#define YUNHORN_STS_AC_CODE_SIZE 20U

View File

@ -42,7 +42,7 @@ extern TIM_HandleTypeDef htim2;
extern I2C_HandleTypeDef MOTION_SENSOR_I2C_HANDLE;
volatile STS_M7_SensorDataTypeDef sts_m7_sensorData;
volatile STS_MOTION_SENSOR_Event_Status_t sts_m7_event_status;
extern volatile uint8_t mems_int1_detected, link_wakeup, link_sleep;
extern volatile uint8_t mems_int1_detected, link_wakeup, link_sleep, do_fft_flag;
volatile uint32_t event_start_time, event_stop_time, vibration_duration, sensor_data_ready;
#endif /* (YUNHORN_STS_PRD) &&(YUNHORN_STS_PRD == 1) */
@ -125,7 +125,7 @@ void STS_MOTION_SENSOR_Prepare_Send_Data()
// APP_LOG(TS_ON, VLEVEL_M, "\r\n--- %d times sampled\r\n", get_value_count);
sts_m7_sensorData.vibration_on_off = (uint8_t)0x01;
sts_m7_sensorData.vibration_duration = (uint8_t)vibration_duration;
if (do_fft_flag !=0) {
sts_m7_sensorData.vb_x_freq = (uint16_t)(ft_x/get_value_count);
sts_m7_sensorData.vb_y_freq = (uint16_t)(ft_y/get_value_count);
sts_m7_sensorData.vb_z_freq = (uint16_t)(ft_z/get_value_count);
@ -133,7 +133,7 @@ void STS_MOTION_SENSOR_Prepare_Send_Data()
sts_m7_sensorData.vb_x_rms = (float)(spectrumPeak_x/get_value_count);
sts_m7_sensorData.vb_y_rms = (float)(spectrumPeak_y/get_value_count);
sts_m7_sensorData.vb_z_rms = (float)(spectrumPeak_z/get_value_count);
}
//sts_m7_sensorData.battery_mV = GetBatteryLevel();
//
@ -217,16 +217,19 @@ void STS_MOTION_SENSOR_WakeUp_Process(void)
if (event_status.WakeUpStatus != 0U)
{
STS_MOTION_SENSOR_After_Wake_Up(); // for 1st wakeup value
STS_MOTION_SENSOR_Init_Send_Data();
if (do_fft_flag != 0) {
for (uint8_t ccc=0; ccc < 3; ccc++) {
STS_MOTION_SENSOR_GetValue();
}
}
}
if (event_status.SleepStatus != 0U)
{

View File

@ -34,7 +34,7 @@ extern uint32_t freq_at_spectrumPeak_x,freq_at_spectrumPeak_y,freq_at_spectrumP
extern uint32_t bin_at_spectrumPeak_x,bin_at_spectrumPeak_y,bin_at_spectrumPeak_z;
extern volatile uint16_t TIM2_Counter, ggx,ggy,ggz;
volatile uint8_t act_threshold=6, inact_threshold=3, inact_duration=3;
volatile uint8_t act_threshold=6, inact_threshold=3, inact_duration=3, do_fft_flag=0;
extern I2C_HandleTypeDef MOTION_SENSOR_I2C_HANDLE;
extern TIM_HandleTypeDef htim2;
/******************************************************************************/
@ -249,8 +249,14 @@ void ADXL345_Init_Motion_Detection(void)
ADXL345_SetRegisterValue(ADXL345_REG_INT_ENABLE, val);
// val=0x08; // POWER ON FOR MEASURE ONLY
//if (do_fft_flag !=0)
//{
val=0x38; // POWER ON FOR MEASURE,LINK,AUTO_SLEEP MODE (*** STEP 3 )
//} else {
// val=0x90; // Power ON for LINK, AUTO_SLEEP MODE, NO MEASURE
//}
//val=0x18; // POWER ON FOR MEASURE,AUTO_SLEEP MODE (*** STEP 3 )
ADXL345_SetRegisterValue(ADXL345_REG_POWER_CTL, val);
ADXL345_GetRegisterValue(ADXL345_REG_INT_SOURCE); //////////////////////////////////////////
@ -722,8 +728,9 @@ void Do_FFT(void)
void Process_FFT_and_Amplitude(void)
{
char outbuf[128]="";
if (do_fft_flag !=0) {
Do_FFT();
}
//
// sprintf(outbuf,"\r\nSpectrum Peak: X=%.2f, Y=%.2f, Z=%.2f\r\n",

View File

@ -64,7 +64,7 @@ volatile uint32_t HeartBeatPeriodicity = 3600000; //unit ms
#ifdef YUNHORN_STS_M7_ENABLED
extern volatile uint8_t sensor_data_ready;
extern volatile STS_M7_SensorDataTypeDef sts_m7_sensorData;
extern volatile uint8_t act_threshold, inact_threshold, inact_duration;
extern volatile uint8_t act_threshold, inact_threshold, inact_duration, do_fft_flag;
#endif
char outbuf[64]="";
/* USER CODE END EV */
@ -507,7 +507,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
#if defined(USE_STM32WLE5)
case MEMS_EXTI2_Pin:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n(3) Vibration Sensor EXTI 2 Event \r\n"); //YUNHORN_STS_TODO
//APP_LOG(TS_OFF, VLEVEL_M, "\r\n(3) Vibration Sensor EXTI 2 Event \r\n"); //YUNHORN_STS_TODO
break;
#endif
@ -760,10 +760,14 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_RESERVE01]; //service mask
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN]; //length of following cfg value
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN+1];
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN+2];
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN+3];
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN+4];
for (uint8_t j=0; j <= cfg_in_nvm[NVM_LEN]; j++) {
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_LEN+j]);
}
// for (uint8_t j=0; j < 4; j++) {
// outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_LEN+j]);
// }
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
//APP_LOG(TS_OFF, VLEVEL_H, "###### YUNHORN Report Config in NVM [ %10x ] \r\n", outbuf);
@ -875,11 +879,12 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
if (mems_ver == sts_version) { // Firmware version or Variation of MEMS/component
if (tlv_buf_size == CFG_CMD_PARAMETER_SIZE) { //Validation check
act_threshold = (uint8_t) (tlv_buf[i++]-0x30)*10; // "P 1 0 0 8" -> 0*10
act_threshold += (tlv_buf[i++]-0x30); // "P 1 0 0 8" -> 0*10 + 8
act_threshold += (uint8_t) (tlv_buf[i++]-0x30); // "P 1 0 0 8" -> 0*10 + 8
inact_threshold = (uint8_t) (tlv_buf[i++]-0x30)*10; // "P 1 0 0 8 0 4" -> 0*10
inact_threshold += (tlv_buf[i++]-0x30); // "P 1 0 0 8 0 4" -> 0*10 + 4
inact_threshold += (uint8_t) (tlv_buf[i++]-0x30); // "P 1 0 0 8 0 4" -> 0*10 + 4
inact_duration = (uint8_t) (tlv_buf[i++]-0x30)*10; // "P 1 0 0 8 0 4 0 3" -> 0*10
inact_duration += (uint8_t) (tlv_buf[i++]-0x30); // "P 1 0 0 8 0 4 0 3" -> 0*10+3
do_fft_flag = (uint8_t) (tlv_buf[i++]-0x30); // "P 1 0 0 8 0 4 0 3 1" fft flag
if (act_threshold <= inact_threshold)
act_threshold += 2;
@ -896,6 +901,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
outbuf[i++] = (uint8_t) act_threshold;
outbuf[i++] = (uint8_t) inact_threshold;
outbuf[i++] = (uint8_t) inact_duration;
outbuf[i++] = (uint8_t) do_fft_flag;
// Step 2: Save valid config to NVM
sts_cfg_nvm.mtmcode1 = sts_mtmcode1;
@ -907,6 +913,8 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
sts_cfg_nvm.p[0] = (uint8_t) act_threshold;
sts_cfg_nvm.p[1] = (uint8_t) inact_threshold;
sts_cfg_nvm.p[2] = (uint8_t) inact_duration;
sts_cfg_nvm.p[3] = (uint8_t) do_fft_flag;
OnStoreSTSCFGContextRequest();
@ -1700,6 +1708,7 @@ void OnRestoreSTSCFGContextProcess(void)
act_threshold = sts_cfg_nvm.p[0];
inact_threshold = sts_cfg_nvm.p[1];
inact_duration = sts_cfg_nvm.p[2];
do_fft_flag = sts_cfg_nvm.p[3];
STS_MOTION_SENSOR_ACT_INACT_DURATION_Init();
}