minor changes

This commit is contained in:
Yunhorn 2024-04-09 13:12:17 +08:00
parent 745bc39aff
commit c71f80de81
7 changed files with 59 additions and 69 deletions

View File

@ -58,7 +58,7 @@
extern RTC_HandleTypeDef hrtc; extern RTC_HandleTypeDef hrtc;
extern SUBGHZ_HandleTypeDef hsubghz; extern SUBGHZ_HandleTypeDef hsubghz;
extern DMA_HandleTypeDef hdma_usart2_tx; extern DMA_HandleTypeDef hdma_usart2_tx;
extern DMA_HandleTypeDef hdma_usart2_rx;
extern UART_HandleTypeDef huart2; extern UART_HandleTypeDef huart2;
/* USER CODE BEGIN EV */ /* USER CODE BEGIN EV */
extern DMA_HandleTypeDef hdma_spi1_rx; extern DMA_HandleTypeDef hdma_spi1_rx;
@ -305,7 +305,7 @@ void DMA1_Channel6_IRQHandler(void)
/* USER CODE BEGIN DMA1_Channel6_IRQn 0 */ /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */
/* USER CODE END DMA1_Channel6_IRQn 0 */ /* USER CODE END DMA1_Channel6_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart2_rx);
/* USER CODE BEGIN DMA1_Channel6_IRQn 1 */ /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */
/* USER CODE END DMA1_Channel6_IRQn 1 */ /* USER CODE END DMA1_Channel6_IRQn 1 */

View File

@ -34,7 +34,6 @@ hmac_result_t hmac_result;
uint32_t sts_hmac_verify(void) uint32_t sts_hmac_verify(void)
{ {
uint8_t i=0;
uint8_t uid[8]=""; uint8_t uid[8]="";
uint32_t ret=0; uint32_t ret=0;
hmac_result.ac_pass = 60; hmac_result.ac_pass = 60;
@ -42,22 +41,13 @@ uint32_t sts_hmac_verify(void)
GetUniqueId(uid); GetUniqueId(uid);
ret = sts_hmac_sha1((const uint8_t *) mKey, sizeof(mKey), (const uint8_t*)(uid+4), 4, &hmac_result); ret = sts_hmac_sha1((const uint8_t *) mKey, sizeof(mKey), (const uint8_t*)(uid+4), 4, &hmac_result);
for (i=0;i<sizeof(Computed_Tag_SHA1); i++) {
APP_LOG(TS_OFF,VLEVEL_H,"0x%02x ", hmac_result.hmac_tag[i]);
}
ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code)); ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code));
if (ret != 0) hmac_result.ac_pass = (ret == 0x0)?1U:0U;
{
hmac_result.ac_pass =0U; APP_LOG(TS_OFF, VLEVEL_M, "\r\nHMAC Verify Success = %u \r\n", hmac_result.ac_pass);
APP_LOG(TS_OFF, VLEVEL_H, "\r\nHMAC Verify Error \r\n");
} else
{
ret = 0;
hmac_result.ac_pass = 1U;
APP_LOG(TS_OFF, VLEVEL_H, "\r\nHMAC Verify Success\r\n");
}
return ret; return ret;
} }

View File

@ -26,7 +26,7 @@
UART_HandleTypeDef huart2; UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart2_tx; DMA_HandleTypeDef hdma_usart2_tx;
DMA_HandleTypeDef hdma_usart2_rx;
/* USART2 init function */ /* USART2 init function */
@ -55,7 +55,7 @@ void MX_USART2_UART_Init(void)
{ {
Error_Handler(); Error_Handler();
} }
/*
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
@ -68,7 +68,7 @@ void MX_USART2_UART_Init(void)
{ {
Error_Handler(); Error_Handler();
} }
*/
/* USER CODE BEGIN USART2_Init 2 */ /* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */ /* USER CODE END USART2_Init 2 */
@ -112,28 +112,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART2 DMA Init */ /* USART2 DMA Init */
/* USART2_RX Init */
hdma_usart2_rx.Instance = DMA1_Channel6;
hdma_usart2_rx.Init.Request = DMA_REQUEST_USART2_RX;
hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart2_rx.Init.Mode = DMA_NORMAL;
hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK)
{
Error_Handler();
}
#ifdef STM32WL55xx
if (HAL_DMA_ConfigChannelAttributes(&hdma_usart2_rx, DMA_CHANNEL_NPRIV) != HAL_OK)
{
Error_Handler();
}
#endif
__HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx);
/* USART2_TX Init */ /* USART2_TX Init */
hdma_usart2_tx.Instance = DMA1_Channel7; hdma_usart2_tx.Instance = DMA1_Channel7;
hdma_usart2_tx.Init.Request = DMA_REQUEST_USART2_TX; hdma_usart2_tx.Init.Request = DMA_REQUEST_USART2_TX;
@ -157,7 +135,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
__HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx);
/* USART2 interrupt Init */ /* USART2 interrupt Init */
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); HAL_NVIC_SetPriority(USART2_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn); HAL_NVIC_EnableIRQ(USART2_IRQn);
/* USER CODE BEGIN USART2_MspInit 1 */ /* USER CODE BEGIN USART2_MspInit 1 */
@ -183,7 +161,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
HAL_GPIO_DeInit(GPIOA, USARTx_RX_Pin|USARTx_TX_Pin); HAL_GPIO_DeInit(GPIOA, USARTx_RX_Pin|USARTx_TX_Pin);
/* USART2 DMA DeInit */ /* USART2 DMA DeInit */
HAL_DMA_DeInit(uartHandle->hdmarx);
HAL_DMA_DeInit(uartHandle->hdmatx); HAL_DMA_DeInit(uartHandle->hdmatx);
/* USART2 interrupt Deinit */ /* USART2 interrupt Deinit */

View File

@ -127,7 +127,7 @@ UTIL_ADV_TRACE_Status_t vcom_DeInit(void)
/* ##-3- Disable the NVIC for DMA ########################################### */ /* ##-3- Disable the NVIC for DMA ########################################### */
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
HAL_NVIC_DisableIRQ(DMA1_Channel5_IRQn); HAL_NVIC_DisableIRQ(DMA1_Channel7_IRQn);
return UTIL_ADV_TRACE_OK; return UTIL_ADV_TRACE_OK;
/* USER CODE END 1 */ /* USER CODE END 1 */

View File

@ -136,7 +136,7 @@ void STS_YunhornSTSEventRFAC_Process(void)
void STS_FallDetection_LampBarProcess(void) void STS_FallDetection_LampBarProcess(void)
{ {
uint8_t buf[32]={0x0}; char buf[32]={0x0};
uint8_t i=0; uint8_t i=0;
switch (sts_fall_rising_detected_result) switch (sts_fall_rising_detected_result)
{ {
@ -182,7 +182,7 @@ void STS_FallDetection_LampBarProcess(void)
APP_LOG(TS_OFF, VLEVEL_L, "\r\n <<<<<<<<<<<<<< Fall Rise state=%d, send buf size = %d \r\n", APP_LOG(TS_OFF, VLEVEL_L, "\r\n <<<<<<<<<<<<<< Fall Rise state=%d, send buf size = %d \r\n",
sts_fall_rising_detected_result, i ) sts_fall_rising_detected_result, i )
STS_SENSOR_Upload_Message((LORAWAN_USER_APP_PORT+2), i, (char*)buf); STS_SENSOR_Upload_Message((LORAWAN_USER_APP_PORT+2), i, buf);
sts_fall_rising_detected_result = STS_PRESENCE_NONE; sts_fall_rising_detected_result = STS_PRESENCE_NONE;
@ -463,7 +463,7 @@ uint8_t STS_SENSOR_MEMS_Get_ID(uint8_t *devID)
{ {
uint8_t scanned_id[2] = {0x0,0x0}; uint8_t scanned_id[2] = {0x0,0x0};
#ifdef YUNHORN_STS_O6_ENABLED #ifdef YUNHORN_STS_O7_ENABLED
if (hal_test_spi_read_chipid(scanned_id)) if (hal_test_spi_read_chipid(scanned_id))
{ {
devID[0] = scanned_id[0]; devID[0] = scanned_id[0];

View File

@ -322,6 +322,12 @@ static void OnJoinTimerLedEvent(void *context);
static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context); static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context);
/**
* @brief Yunhorn STS Heart Beat Periodicity Chagne function
* @param duration of periodicty in ms (1/1000 sec)
*/
static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity);
/** /**
* @brief Yunhorn STS AC Code handle Process * @brief Yunhorn STS AC Code handle Process
* @param void * @param void
@ -441,6 +447,10 @@ static UTIL_TIMER_Object_t YunhornSTSRSSWakeUpTimer;
* @brief Timer to handle the YunHorn STS Sensor Sampling Process * @brief Timer to handle the YunHorn STS Sensor Sampling Process
*/ */
//static UTIL_TIMER_Object_t YunhornSTSSamplingCheckTimer; //static UTIL_TIMER_Object_t YunhornSTSSamplingCheckTimer;
/**
* @brief Timer to handle the YunHorn STS Sensor Heart Beat Process
*/
static UTIL_TIMER_Object_t YunhornSTSHeartBeatTimer;
/* USER CODE END PV */ /* USER CODE END PV */
@ -654,6 +664,16 @@ static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
break; break;
} }
} }
DeviceClass_t deviceClass = CLASS_A;
LmHandlerGetCurrentClass( &deviceClass );
uint8_t i=0;
outbuf[i++] = (uint8_t) 'L';
outbuf[i++] = (uint8_t) sts_mtmcode1;
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);
break; break;
case LORAWAN_USER_APP_PORT: case LORAWAN_USER_APP_PORT:
if (appData->BufferSize == 1) if (appData->BufferSize == 1)
@ -984,8 +1004,9 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
STS_LoRa_WAN_Joined = (uint8_t) joinParams->Mode; STS_LoRa_WAN_Joined = (uint8_t) joinParams->Mode;
//APP_LOG(TS_OFF, VLEVEL_M,"\r\n STS_LoRa_WAN_Joined = %d \r\n", STS_LoRa_WAN_Joined); OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
OnTxPeriodicityChanged(TxPeriodicity);
APP_LOG(TS_OFF, VLEVEL_L,"\r\n STS_LoRa_WAN_Joined = %s \r\n", (STS_LoRa_WAN_Joined == 1)?"ABP":"OTAA");
} }
else else
{ {
@ -994,6 +1015,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); APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:JOIN | DR:%d | PWR:%d\r\n", joinParams->Datarate, joinParams->TxPower);
} }
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
/* USER CODE END OnJoinRequest_1 */ /* USER CODE END OnJoinRequest_1 */
} }
@ -1253,33 +1275,34 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context)
} }
/** /**
* @brief Yunhorn STS Sensor Heart Beat Timer callback function * @brief Yunhorn STS Sensor Live Heart Beat Periodicity/interval Change callback function
* @param context ptr of STS Sampling Check context * @param context ptr of STS Live Heart Beat context
*/ * YL x x x
/* * */
static void OnYunhornSTSHeartBeatTimerEvent(void *context)
static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
{ {
if (STS_LoRa_WAN_Joined ) /* USER CODE BEGIN OnTxPeriodicityChanged_1 */
/* USER CODE END OnTxPeriodicityChanged_1 */
HeartBeatPeriodicity = periodicity;
if (HeartBeatPeriodicity == 0)
{ {
/* Revert to application default periodicity */
heart_beat_timer = 1; HeartBeatPeriodicity = 10*APP_TX_DUTYCYCLE;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
if (sts_ac_code[0]==0x0) {
// RFAC Challenge
if (rfac_timer < (STS_BURN_IN_RFAC+3)) {
rfac_timer ++;
}
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
} }
/* Update timer periodicity */
UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer);
UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, HeartBeatPeriodicity);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
} /* USER CODE BEGIN OnTxPeriodicityChanged_2 */
APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity Changed to: %u (ms)\r\n", HeartBeatPeriodicity );
/* 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

Binary file not shown.