RM2_1 #2

Merged
sundp merged 208 commits from RM2_1 into master 2024-09-13 09:16:14 +08:00
7 changed files with 129 additions and 96 deletions
Showing only changes of commit a3a07035d7 - Show all commits

View File

@ -60,7 +60,7 @@ void Error_Handler(void);
#define RTC_N_PREDIV_S 10
#define RTC_PREDIV_S ((1<<RTC_N_PREDIV_S)-1)
#define RTC_PREDIV_A ((1<<(15-RTC_N_PREDIV_S))-1)
//#if defined(STM32WL55xx)
#if defined(STM32WL55xx)
#define LED1_Pin GPIO_PIN_15
#define LED1_GPIO_Port GPIOB
#define LED2_Pin GPIO_PIN_9
@ -71,7 +71,13 @@ void Error_Handler(void);
#define PROB2_GPIO_Port GPIOB
#define PROB1_Pin GPIO_PIN_12
#define PROB1_GPIO_Port GPIOB
//#endif
#endif
#define LED1_Pin GPIO_PIN_2
#define LED1_GPIO_Port GPIOB
#define LED1_ON HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET )
#define LED1_OFF HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET)
#define MEMS_POWER_Pin GPIO_PIN_4 // PMU_ENABLE
#define MEMS_POWER_GPIO_Port GPIOB // PMU_ENABLE

View File

@ -600,7 +600,7 @@ void STS_SENSOR_MEMS_Reset(uint8_t cnt);
void STS_PRESENCE_SENSOR_NVM_CFG(void);
void STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE(void);
void STS_PRESENCE_SENSOR_Read(STS_OO_SensorStatusDataTypeDef *o6_data);
void STS_PRESENCE_SENSOR_Prepare_Send_Data(void);
void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *sensor_data);
void STS_PRESENCE_SENSOR_Init(void);
void STS_PRESENCE_SENSOR_RSS_Init(void);
@ -615,7 +615,7 @@ void STS_FallDetection_LampBarProcess(void);
void STS_YunhornCheckStandardDeviation(void);
void STS_SENSOR_Upload_Config_Invalid_Message(void);
void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char *appDataBuffer);
void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8_t *appDataBuffer);
void STS_SENSOR_Auto_Responder_Process(uint8_t tlv_ver,uint8_t tlv_type, uint8_t tlv_length, uint8_t *tlv_content);
uint8_t STS_SENSOR_MEMS_Get_ID(uint8_t *devID);

View File

@ -50,12 +50,13 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|PROB2_Pin|PROB1_Pin
|LED3_Pin, GPIO_PIN_RESET);
//HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|PROB2_Pin|PROB1_Pin|LED3_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, LED1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, A111_CS_N_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : PBPin PBPin PBPin */
GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin|LED3_Pin;
GPIO_InitStruct.Pin = LED1_Pin; //|LED2_Pin|LED3_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

View File

@ -99,7 +99,7 @@ int main(void)
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
LED1_ON;
MX_LoRaWAN_Init();
//STS_Lamp_Bar_Self_Test_Simple();

View File

@ -40,7 +40,7 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm;
extern volatile uint8_t sts_ac_code[20];
volatile uint8_t sts_service_mask;
volatile uint32_t rfac_timer;
volatile uint8_t sensor_data_ready;
volatile uint8_t sensor_data_ready=0;
extern volatile uint8_t sts_reed_hall_result;
volatile uint8_t last_sts_reed_hall_result;
@ -80,7 +80,7 @@ volatile uint8_t sts_reed_hall_changed_flag = 0;
extern volatile uint8_t sts_reed_hall_result;
volatile uint8_t sts_water_leakage_result=0;
volatile uint8_t sts_water_leakage_changed_flag=0;
extern volatile uint8_t sensor_data_ready;
//extern volatile uint8_t sensor_data_ready;
#ifdef YUNHORN_STS_R4_ENABLED
volatile STS_R0_SensorDataTypeDef r4_data;
#endif
@ -524,37 +524,37 @@ void STS_PRESENCE_SENSOR_Init_Send_Data(void)
sensor_data_ready = 0;
}
void STS_PRESENCE_SENSOR_Prepare_Send_Data(void)
void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *sensor_data)
{
sts_o7_sensorData.lamp_bar_color = sts_lamp_bar_color;
sts_o7_sensorData.workmode = sts_work_mode;
sts_o7_sensorData.state_sensor1_on_off = HALL1_STATE;//sts_hall1_read; //sts_hsts_reed_hall_result; // sts_hall1_read
sts_o7_sensorData.state_sensor2_on_off = sts_rss_result;
sts_o7_sensorData.state_sensor3_on_off = HALL2_STATE;//sts_hall2_read; //sts_emergency_button_pushed; //sts_hall2_read
sts_o7_sensorData.state_sensor4_on_off = sts_rss_2nd_result;
sensor_data->lamp_bar_color = sts_lamp_bar_color;
sensor_data->workmode = sts_work_mode;
sensor_data->state_sensor1_on_off = HALL1_STATE;//sts_hall1_read; //sts_hsts_reed_hall_result; // sts_hall1_read
sensor_data->state_sensor2_on_off = sts_rss_result;
sensor_data->state_sensor3_on_off = HALL2_STATE;//sts_hall2_read; //sts_emergency_button_pushed; //sts_hall2_read
sensor_data->state_sensor4_on_off = sts_rss_2nd_result;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nPrepare Upload Message............\r\n");
if (sts_rss_result == STS_RESULT_MOTION)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......STS_RESULT MOTION............\r\n");
sts_o7_sensorData.rss_presence_distance = (uint16_t)(sts_presence_rss_distance)&0xFFFF;
sts_o7_sensorData.rss_presence_score = (uint16_t)(sts_presence_rss_score)&0xFFFF;
sensor_data->rss_presence_distance = (uint16_t)(sts_presence_rss_distance)&0xFFFF;
sensor_data->rss_presence_score = (uint16_t)(sts_presence_rss_score)&0xFFFF;
// uint8_t sts_unconcious_state;
// uint16_t sts_unconcious_threshold, sts_unconcious_threshold_duration;
} else {
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......STS_NO MOTION............\r\n");
sts_o7_sensorData.rss_presence_distance = 0x0;
sts_o7_sensorData.rss_presence_score = 0x0;
sensor_data->rss_presence_distance = 0x0;
sensor_data->rss_presence_score = 0x0;
}
sts_o7_sensorData.unconcious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONCIOUS)? 1:0;
sensor_data->unconcious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONCIOUS)? 1:0;
sts_o7_sensorData.fall_state = sts_fall_rising_detected_result;
sensor_data->fall_state = sts_fall_rising_detected_result;
if (sts_fall_rising_detected_result != STS_PRESENCE_NONE)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......FALL RISING DETECTION RESULT: %25s............\r\n",sts_presence_fall_detection_message[sts_fall_rising_detected_result] );
sts_o7_sensorData.fall_speed = (uint8_t)sts_fall_rising_pattern_factor1;
sts_o7_sensorData.fall_gravity = (uint8_t)sts_roc_acc_standard_variance;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......FALL RISING DETECTION RESULT: %25s............\r\n",(char*)sts_presence_fall_detection_message[sts_fall_rising_detected_result] );
sensor_data->fall_speed = (uint8_t)sts_fall_rising_pattern_factor1;
sensor_data->fall_gravity = (uint8_t)sts_roc_acc_standard_variance;
}
// For occupancy over time process
@ -569,8 +569,8 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(void)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......OVER STAY............\r\n");
sts_occupancy_overtime_state = 1U;
sts_o7_sensorData.overtime = sts_occupancy_overtime_state;
sts_o7_sensorData.over_stay_duration = check_time_tmp;
sensor_data->overtime = sts_occupancy_overtime_state;
sensor_data->over_stay_duration = check_time_tmp;
sts_status_color = STS_RED_BLUE;
sts_lamp_bar_color = STS_RED_BLUE;
@ -581,7 +581,7 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(void)
//{
// sts_occupancy_overtime_state = 0U;
// }
sensor_data_ready = 1;
}

View File

@ -66,7 +66,7 @@ volatile uint8_t STS_LoRa_WAN_Joined = 0;
volatile uint8_t mems_int1_detected = 0;
volatile uint8_t upload_message_timer=0;
volatile uint8_t heart_beat_timer =0;
char outbuf[128]="";
uint8_t outbuf[128]={0x0};
volatile sts_cfg_nvm_t sts_cfg_nvm = {
sts_mtmcode1,
sts_mtmcode2,
@ -597,8 +597,9 @@ void LoRaWAN_Init(void)
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), UTIL_SEQ_RFU, STS_YunhornSTSEventRFAC_Process);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), UTIL_SEQ_RFU, STS_YunhornSTSEventP1_Process);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), UTIL_SEQ_RFU, STS_YunhornSTSEventP2_Process);
#if 1
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP3), UTIL_SEQ_RFU, STS_YunhornSTSEventP3_Process);
#if 0
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), UTIL_SEQ_RFU, STS_YunhornSTSEventP4_Process);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP6), UTIL_SEQ_RFU, STS_YunhornSTSEventP6_Process);
@ -705,8 +706,9 @@ static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
if (params != NULL)
{
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); /* LED_BLUE */
#endif
UTIL_TIMER_Start(&RxLedTimer);
if (params->IsMcpsIndication)
@ -751,7 +753,7 @@ static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
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, (uint8_t *)outbuf);
break;
case LORAWAN_USER_APP_PORT:
@ -761,12 +763,16 @@ static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
if (AppLedStateOn == RESET)
{
APP_LOG(TS_OFF, VLEVEL_H, "LED OFF\r\n");
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_RED */
#endif
}
else
{
APP_LOG(TS_OFF, VLEVEL_H, "LED ON\r\n");
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); /* LED_RED */
#endif
}
}
break;
@ -801,19 +807,17 @@ static void SendTxData(void)
/* USER CODE BEGIN SendTxData_1 */
LmHandlerErrorStatus_t status = LORAMAC_HANDLER_ERROR;
uint8_t batteryLevel = GetBatteryLevel();
//uint16_t batteryLevelmV = SYS_GetBatteryLevel();
//sensor_t sensor_data;
STS_OO_SensorStatusDataTypeDef sensorData;
UTIL_TIMER_Time_t nextTxIn = 0;
uint8_t i = 0;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n\n SendTxData Enter \r\n\n");
//if (LmHandlerIsBusy() == false)
if (LmHandlerIsBusy() == false)
{
uint32_t i = 0;
STS_PRESENCE_SENSOR_Prepare_Send_Data(&sensorData);
AppData.Port = LORAWAN_USER_APP_PORT;
//AppData.Buffer[i++] = AppLedStateOn; //#01
STS_PRESENCE_SENSOR_Prepare_Send_Data();
if ((heart_beat_timer != 0L)) // sensor data OVERWRITE heart-beat message, 2024-05-12
{
@ -823,66 +827,72 @@ static void SendTxData(void)
AppData.Buffer[i++] = (uint8_t)(99*batteryLevel/254)&0xff; //#05
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n\n SendTxData Enter Heart-Beat \r\n\n");
} else if ((upload_message_timer != 0U)||(sensor_data_ready!= 0U)) //sensor_data_ready for manual push button-1 trigger)
} else if ((sensor_data_ready!= 0U)) //sensor_data_ready for manual push button-1 trigger)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n\n SendTxData Enter Sensor Data Ready \r\n\n");
sensor_data_ready =0;
AppData.Buffer[i++] = AppLedStateOn|0x80; // ************ MUST KEEP IT HERE, NON-ZERO ******
//AppData.Buffer[i++] = AppLedStateOn;
AppData.Buffer[i++] = (uint8_t)(sensorData.lamp_bar_color)&0xff; //01
AppData.Buffer[i++] = (uint8_t)(sensorData.workmode)&0xff; //02 WORK MODE
//STS_PRESENCE_SENSOR_Prepare_Send_Data();
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.lamp_bar_color)&0xff; //01
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.workmode)&0xff; //02 WORK MODE
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.state_sensor4_on_off)&0xff; //06 Sensor head #4 status
AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor1_on_off)&0xff; //03 Sensor head #1 status
AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor2_on_off)&0xff; //04 Sensor head #2 status
AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor3_on_off)&0xff; //05 Sensor head #3 status
AppData.Buffer[i++] = (uint8_t)(sensorData.state_sensor4_on_off)&0xff; //06 Sensor head #4 status
#if 1
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.rss_presence_distance>>8)&0xff; //07 MSB distance
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.rss_presence_distance)&0xff; //08 LSB distance
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.rss_presence_score>>8)&0xff; //09 MSB score
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.rss_presence_score)&0xff; //10 LSB score
AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_distance>>8)&0xff; //07 MSB distance
AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_distance)&0xff; //08 LSB distance
AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_score>>8)&0xff; //09 MSB score
AppData.Buffer[i++] = (uint8_t)(sensorData.rss_presence_score)&0xff; //10 LSB score
#endif
#if 1
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.unconcious_state)&0xff; //11 unconcious state detected or not
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.fall_state)&0xff; //12 fall detected or not
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.overtime)&0xff; //13 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.over_stay_duration>>8)&0xff; //13 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sts_o7_sensorData.over_stay_duration)&0xff; //13 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.unconcious_state)&0xff; //11 unconcious state detected or not
AppData.Buffer[i++] = (uint8_t)(sensorData.fall_state)&0xff; //12 fall detected or not
AppData.Buffer[i++] = (uint8_t)(sensorData.overtime)&0xff; //13 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration>>8)&0xff; //14 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //15 occupancy over time or not
#endif
#if 1
APP_LOG(TS_OFF, VLEVEL_L,
"\r\n######| Color | Mode |\r\n######| %4s | %5s |\r\n",(char *)sts_lamp_color_code[(uint8_t)(AppData.Buffer[0])], (char*)sts_work_mode_code[AppData.Buffer[1]]);
"\r\n######| Color | Mode |\r\n######| %4s | %5s |\r\n",(char *)sts_lamp_color_code[sensorData.lamp_bar_color], (char*)sts_work_mode_code[sensorData.workmode]);
APP_LOG(TS_OFF, VLEVEL_L,
"\r\n######| S1-DoorOpen | S2-Motion | S3-No_Emergency | S4 |Distance(mm) | MotionScore| Unconcious | Over_Stay| Fall Detected|"
"\r\n######| %1d | %1d | %1d | %1d | %04d | %04d | %1d | %1d | %1d |\r\n",
AppData.Buffer[2], AppData.Buffer[3],AppData.Buffer[4], AppData.Buffer[5],
(uint16_t)sts_o7_sensorData.rss_presence_distance,(uint16_t)sts_o7_sensorData.rss_presence_score,
sts_o7_sensorData.unconcious_state, sts_o7_sensorData.unconcious_duration, sts_o7_sensorData.fall_state );
sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off, sensorData.state_sensor4_on_off,
(uint16_t)sensorData.rss_presence_distance,(uint16_t)sensorData.rss_presence_score,
sensorData.unconcious_state, sensorData.unconcious_duration, sensorData.fall_state );
#endif
}
if ((LmHandlerParams.ActiveRegion == LORAMAC_REGION_US915) || (LmHandlerParams.ActiveRegion == LORAMAC_REGION_AU915)
|| (LmHandlerParams.ActiveRegion == LORAMAC_REGION_AS923))
{
// ORIGIN CODE OF 4 ZERO APPENDED
}
AppData.BufferSize = (sts_service_mask > STS_SERVICE_MASK_L1? 0:i);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n\n\n** ** AppData.PORT =%3d ** ** AppData.BufferSize=%3d ** Count Size=%3d\r\n", AppData.Port, AppData.BufferSize, i);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n\n\n**AppData.PORT =%3d **AppData.BufferSize=%3d \r\n**Count Size=%3d\r\n", AppData.Port, AppData.BufferSize, i);
//AppData.BufferSize = (sts_service_mask > STS_SERVICE_MASK_L1? 0:i);
if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET))
{
UTIL_TIMER_Stop(&JoinLedTimer);
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_RED */
#endif
LED1_ON;
}
status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
if (LORAMAC_HANDLER_SUCCESS == status)
{
LED1_ON;
APP_LOG(TS_ON, VLEVEL_L, "SEND REQUEST\r\n");
LED1_OFF;
}
else if (LORAMAC_HANDLER_DUTYCYCLE_RESTRICTED == status)
{
@ -935,17 +945,23 @@ static void OnTxTimerEvent(void *context)
/* USER CODE BEGIN PrFD_LedEvents */
static void OnTxTimerLedEvent(void *context)
{
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET); /* LED_GREEN */
#endif
}
static void OnRxTimerLedEvent(void *context)
{
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); /* LED_BLUE */
#endif
}
static void OnJoinTimerLedEvent(void *context)
{
#ifndef STM32WLE5xx
HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin); /* LED_RED */
#endif
if ((sts_work_mode != STS_WIRED_MODE))
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP3), CFG_SEQ_Prio_0);
}
@ -962,21 +978,23 @@ static void OnTxData(LmHandlerTxParams_t *params)
/* Process Tx event only if its a mcps response to prevent some internal events (mlme) */
if (params->IsMcpsConfirm != 0)
{
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); /* LED_GREEN */
#endif
UTIL_TIMER_Start(&TxLedTimer);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n###### ========== MCPS-Confirm =============\r\n");
APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:%04d | PORT:%d | DR:%d | PWR:%d", params->UplinkCounter,
APP_LOG(TS_OFF, VLEVEL_M, "###### U/L FRAME:%04d | PORT:%d | DR:%d | PWR:%d", params->UplinkCounter,
params->AppData.Port, params->Datarate, params->TxPower);
APP_LOG(TS_OFF, VLEVEL_H, " | MSG TYPE:");
APP_LOG(TS_OFF, VLEVEL_M, " | MSG TYPE:");
if (params->MsgType == LORAMAC_HANDLER_CONFIRMED_MSG)
{
APP_LOG(TS_OFF, VLEVEL_H, "CONFIRMED [%s]\r\n", (params->AckReceived != 0) ? "ACK" : "NACK");
APP_LOG(TS_OFF, VLEVEL_M, "CONFIRMED [%s]\r\n", (params->AckReceived != 0) ? "ACK" : "NACK");
}
else
{
APP_LOG(TS_OFF, VLEVEL_H, "UNCONFIRMED\r\n");
APP_LOG(TS_OFF, VLEVEL_M, "UNCONFIRMED\r\n");
}
}
}
@ -991,8 +1009,9 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
if (joinParams->Status == LORAMAC_HANDLER_SUCCESS)
{
UTIL_TIMER_Stop(&JoinLedTimer);
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_RED */
#endif
APP_LOG(TS_OFF, VLEVEL_M, "\r\n###### = JOINED = ");
if (joinParams->Mode == ACTIVATION_TYPE_ABP)
{
@ -1016,6 +1035,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:JOIN | DR:%d | PWR:%d\r\n", joinParams->Datarate, joinParams->TxPower);
}
heart_beat_timer = 1;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
/* USER CODE END OnJoinRequest_1 */
}
@ -1144,9 +1164,11 @@ static void OnSystemReset(void)
static void StopJoin(void)
{
/* USER CODE BEGIN StopJoin_1 */
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); /* LED_BLUE */
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); /* LED_GREEN */
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); /* LED_RED */
#endif
/* USER CODE END StopJoin_1 */
UTIL_TIMER_Stop(&TxTimer);
@ -1188,9 +1210,11 @@ static void OnStopJoinTimerEvent(void *context)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0);
}
/* USER CODE BEGIN OnStopJoinTimerEvent_Last */
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); /* LED_BLUE */
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET); /* LED_GREEN */
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_RED */
#endif
/* USER CODE END OnStopJoinTimerEvent_Last */
}
@ -1474,7 +1498,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
if ((char)tlv_buf[CFG_CMD3] == 'H') { //BOARD SOFT RESET, REVIVE "YZH"
//BOARD REVIVE
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 20, "!YunHorn STS Revive!");
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 20, (uint8_t*)"!YunHorn STS Revive!");
HAL_Delay(5000);
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Yunhorn STS Node Revive ... \r\n");
HAL_Delay(3000);
@ -1486,7 +1510,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
//outbuf[i++] = (uint8_t) 'Y';
//outbuf[i++] = (uint8_t) 'Z';
//outbuf[i++] = (uint8_t) 'S';
//STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
//STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
i=0;
@ -1494,7 +1518,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
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, (uint8_t *)outbuf);
} else if ((char)tlv_buf[CFG_CMD3] == 'C') { // Lora-WAN Class "YZC" LORAWAN CLASS A/B/C
@ -1506,13 +1530,13 @@ 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, (uint8_t *)outbuf);
} else if ((char)tlv_buf[CFG_CMD3] == 'D') { // Distance Measure "YZD"
i=0;
outbuf[i++] = (uint8_t) 'Y';
outbuf[i++] = (uint8_t) 'Z';
outbuf[i++] = (uint8_t) 'D';
//STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
//STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
STS_SENSOR_Distance_Test_Process();
@ -1549,7 +1573,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
#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, (uint8_t *)outbuf);
}
@ -1564,7 +1588,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, (uint8_t *)outbuf);
APP_LOG(TS_OFF, VLEVEL_L, ">>>>>>>>>>>>>>>>>>>>> Mask = [ %02x ] \r\n", sts_service_mask);
OnStoreSTSCFGContextRequest();
if (sts_service_mask != STS_SERVICE_MASK_L0) STS_Lamp_Bar_Set_Dark();
@ -1584,8 +1608,8 @@ 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);
APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Report Version [ %10x ] \r\n", outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
APP_LOG(TS_OFF, VLEVEL_M, "###### YUNHORN Report Version [ %10x ] \r\n", (char *)outbuf);
}
else
if ((char)tlv_buf[CFG_CMD3] == 'C') { // "YVC" REPORT NVM STORED CONFIG PARAMETERS "YVC"
@ -1612,7 +1636,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, (uint8_t *)outbuf);
}
break;
@ -1626,7 +1650,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, (uint8_t *)outbuf);
} else {
STS_SENSOR_Upload_Config_Invalid_Message();
}
@ -1640,7 +1664,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, (uint8_t *)outbuf);
} else {
STS_SENSOR_Upload_Config_Invalid_Message();
}
@ -1653,7 +1677,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, (uint8_t *)outbuf);
} else {
STS_SENSOR_Upload_Config_Invalid_Message();
}
@ -1682,7 +1706,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, (uint8_t *)outbuf);
// Save config to NVM
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
@ -1728,7 +1752,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, (uint8_t *)outbuf);
// Save config to NVM
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
@ -1964,7 +1988,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
} else {
// 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, (uint8_t *)outbuf);
}
}
@ -2020,7 +2044,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
for (uint8_t j=0; j <(tlv_buf_size) ; j++) {
outbuf[i++] = (uint8_t) tlv_buf[j];
}
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
}
@ -2029,7 +2053,7 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size)
void STS_SENSOR_Upload_Config_Invalid_Message(void)
{
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, (uint8_t*)"PVXXX");
}
static void STS_YUNHORN_RFAC_HANDLE_PROCESS(void)
@ -2039,7 +2063,7 @@ static void STS_YUNHORN_RFAC_HANDLE_PROCESS(void)
}
void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char *appDataBuffer)
void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8_t *appDataBuffer)
{
LmHandlerErrorStatus_t status = LORAMAC_HANDLER_ERROR;
UTIL_TIMER_Time_t nextTxIn = 0;
@ -2047,10 +2071,10 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char
if (LmHandlerIsBusy() == false)
{
//for (uint8_t i=0;i<appBufferSize; i++) {
// AppData.Buffer[i] = appDataBuffer[i];
// }
UTIL_MEM_cpy_8(AppData.Buffer, appDataBuffer, appBufferSize);
for (uint8_t i=0; i<appBufferSize; i++) {
AppData.Buffer[i] = appDataBuffer[i];
}
//UTIL_MEM_cpy_8(AppData.Buffer, appDataBuffer, appBufferSize);
AppData.Port = appDataPort;
AppData.BufferSize = (sts_service_mask >1 ?0:appBufferSize);
@ -2060,7 +2084,9 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char
if ((JoinLedTimer.IsRunning) && (LmHandlerJoinStatus() == LORAMAC_HANDLER_SET))
{
UTIL_TIMER_Stop(&JoinLedTimer);
#ifndef STM32WLE5xx
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_RED */
#endif
}
status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
@ -2360,7 +2386,7 @@ void STS_SENSOR_Function_Test_Process(void)
memset((void*)outbuf,0x0, sizeof(outbuf));
memcpy((void*)outbuf, tstbuf, i);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (char*)outbuf);
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t*)outbuf);
}

Binary file not shown.