Fahad Mirza
/
Nucleo_HXC900
A demo application for HXC900 LoRaWAN module using Nucleo-L053R8.
Diff: LoRa/hxc_client.c
- Revision:
- 15:2860c960d2ff
- Parent:
- 5:53302861bfea
- Child:
- 18:24c232951ff8
--- a/LoRa/hxc_client.c Tue Jul 24 02:51:20 2018 +0000 +++ b/LoRa/hxc_client.c Wed Jul 25 17:38:48 2018 +0000 @@ -11,7 +11,7 @@ * File : hxc_client.c * Author : Fahad (Haxiot) * Version : V1.0.0 - * Modified: 15-February-2018 + * Modified: 15-July-2018 * Brief : HXC AT command API ****************************************************************************** * @attention @@ -57,9 +57,7 @@ #include "time_server.h" #include "hw_gpio.h" -/* External variables --------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ - // Type definition for return code analysis typedef char* AtErrorStr_t; @@ -70,8 +68,8 @@ eAtStatus_t RetCode; }sAtRetCode_t; + /* Private functions ---------------------------------------------------------*/ - static uint16_t at_cmd_format(ATGroup_t at_group, ATCmd_t Cmd, const void *ptr); static uint16_t at_set_cmd_format(ATCmd_t Cmd, const void *ptr); static eAtStatus_t at_cmd_send(uint16_t len); @@ -79,6 +77,7 @@ static eAtStatus_t at_cmd_responseAnalysing(const char *ReturnResp); static uint16_t at_cmd_vprintf(const char *format, ...); + /* Private macro -------------------------------------------------------------*/ #define AT_VPRINTF(...) at_cmd_vprintf(__VA_ARGS__) #define AT_VSSCANF(...) tiny_sscanf(__VA_ARGS__) @@ -171,24 +170,23 @@ static uint16_t Offset = 0; // Write position needed for LoRa_AT_Cmd_Buff[] during AT_SET -/* Has to be the largest of the response - * not only for return code but also for - * return value e.g. KEY. +/* Has to be the largest of the response. + * Not only for return code but also for + * return value e.g. APPKEY. */ static char response[DATA_RX_MAX_BUFF_SIZE]; /* Exported functions ------------------------------------------------------- */ -/******************************************************************** - * Brief : Configures HXC UART interface, Reset Pin - * Param : None - * Retval : AT_OK in case of success - * AT_UART_LINK_ERROR in case of UART init failure -*********************************************************************/ +/******************************************************************************* + * @Brief : Configures HXC UART interface, Reset Pin + * @Param : None + * @Return : AT_OK in case of success + * AT_UART_LINK_ERROR in case of UART init failure +*******************************************************************************/ eAtStatus_t Modem_Init( void ) { - // ToDO: hardware initialization should be out of this library if (HW_UART_Modem_Init(BAUD_RATE) == false) { return AT_UART_LINK_ERROR; @@ -206,24 +204,24 @@ } -/******************************************************************** - * @brief Deinitialize modem UART interface. - * @param None - * @retval None -*********************************************************************/ +/******************************************************************************* + * @Brief : Deinitialize modem UART interface. + * @Param : None + * @Return : None +*******************************************************************************/ void Modem_IO_DeInit( void ) { HW_UART_Modem_DeInit(); } -/******************************************************************** - * @brief Handle the AT cmd following their Group type - * @param at_group AT group (control, set , get) - * Cmd AT command - * pdata pointer to the IN/OUT buffer - * @retval module status - ********************************************************************/ +/******************************************************************************* + * @Brief : Handle the AT cmd following their Group type + * @Param : at_group AT group (control, set , get) + * Cmd AT command + * pdata pointer to the IN/OUT buffer + * @Return : Module status + ******************************************************************************/ eAtStatus_t Modem_AT_Cmd(ATGroup_t at_group, ATCmd_t atCmd, void *pdata ) { eAtStatus_t atStatus = AT_END_ERROR; @@ -231,6 +229,7 @@ // Reset At_cmd buffer for each transmission memset1((uint8_t *)LoRa_AT_Cmd_Buff, 0x00, sizeof(LoRa_AT_Cmd_Buff)); + /* Reset the UART circular buffer for each transmission to make sure * the responses we will get are for the current AT cmd. */ HW_UART_ResetBuffer(); @@ -240,8 +239,8 @@ if(atCmdLen == 0) { /* - * You are trying to use a command behavior that HXC Client doesn't support. - * Check manual for possible AT command behaviors. + * You are trying to use a command behavior that HXC Client doesn't + * support. Check manual for possible AT command behaviors. */ return AT_CMD_ERROR; } @@ -269,13 +268,13 @@ } -/******************************************************************** - * Brief : format the cmd in order to be send - * Param : at_group - the behavior of AT cmd - * Cmd - AT command - * ptr - generic pointer to the IN/OUT buffer - * Retval: length of the formated frame to be send - ********************************************************************/ +/******************************************************************************* + * @Brief : Format the cmd in order to be send + * @Param : at_group - the behavior of AT cmd + * Cmd - AT command + * ptr - generic pointer to the IN/OUT buffer + * @Return: Length of the formated frame to be send + ******************************************************************************/ static uint16_t at_cmd_format(ATGroup_t at_group, ATCmd_t Cmd, const void *ptr) { uint16_t len = 0; /*length of the formated command*/ @@ -307,12 +306,12 @@ } -/******************************************************************** - * Brief : format the at set cmd - * Param : Cmd - AT command - * ptr - generic pointer to the IN/OUT buffer - * Retval: length of the formated frame to be send - ********************************************************************/ +/******************************************************************************* + * @Brief : Format the at set cmd + * @Param : Cmd - AT command + * ptr - generic pointer to the IN/OUT buffer + * @Return: Length of the formated frame to be send + ******************************************************************************/ static uint16_t at_set_cmd_format(ATCmd_t Cmd, const void *ptr) { uint32_t value; /*for 32_02X and 32_D*/ @@ -364,7 +363,7 @@ Offset += AT_VPRINTF("%s", eui); break; } - case AT_RX1DL: /* could be unsigned format - need to be analyze */ + case AT_RX1DL: case AT_RX2DL: case AT_JN1DL: case AT_JN2DL: @@ -412,11 +411,11 @@ } -/******************************************************************** - * Brief : This function sends an AT cmd to the slave device - * Param : len - length of the AT cmd to be sent - * Retval: eAtStatus_t return code -*********************************************************************/ +/******************************************************************************* + * @Brief : This function sends an AT cmd to the slave device + * @Param : len - length of the AT cmd to be sent + * @Return: eAtStatus_t return code +*******************************************************************************/ static eAtStatus_t at_cmd_send(uint16_t len) { /*transmit the command from master to slave*/ @@ -429,11 +428,11 @@ } -/******************************************************************** - * Brief : This function receives response from the slave device - * Param : pdata - pointer to the value returned by the slave - * Retval: return code coming from slave -*********************************************************************/ +/******************************************************************************* + * @Brief : This function receives response from the slave device + * @Param : pdata - pointer to the value returned by the slave + * @Return: Return code coming from HXC slave +*******************************************************************************/ static eAtStatus_t at_cmd_receive(void *pdata) { bool ResponseComplete = false; @@ -460,7 +459,7 @@ response[i++] = HW_UART_Modem_GetNewChar(); // Wait up to line feed marker - if (response[i - 1] == '\n') // ToDo: potential infinite loop, need a timeout. + if (response[i - 1] == '\n') { // Last two bytes are <CR><LF>, set CR as NULL byte. response[i - 2] = '\0'; @@ -497,16 +496,16 @@ } } // End while(ResponseComplete != true) - HW_UART_Modem_Ready(); /* to be checked since was validated with previous */ - return RetCode; /* version of HAL .. there was not Rx field state */ + HW_UART_Modem_Ready(); + return RetCode; } -/******************************************************************** - * Brief : Analyze the response received by the device - * Param : response: pointer to the received response - * Retval: eAtStatus_t error type -*********************************************************************/ +/******************************************************************************* + * @Brief : Analyze the response received by the device + * @Param : response: pointer to the received response + * @Return: eAtStatus_t error type +*******************************************************************************/ static eAtStatus_t at_cmd_responseAnalysing(const char *ReturnResp) { int i; @@ -523,11 +522,11 @@ } -/******************************************************************** - * Brief : format the AT frame to be sent to the modem (slave) - * Param : pointer to the format string - * Retval: len of the string to be sent -*********************************************************************/ +/******************************************************************************* + * @Brief : Format the AT frame to be sent to the modem (slave) + * @Param : Pointer to the format string + * @Return: Length of the string to be sent +*******************************************************************************/ uint16_t at_cmd_vprintf(const char *format, ...) { va_list args; @@ -542,11 +541,11 @@ return len; } -/******************************************************************** - * @brief Reset the HXC client modem using HXC RESET pin - * @param None - * @retval module status - ********************************************************************/ +/******************************************************************************* + * @Brief : Reset the HXC client modem using HXC RESET pin + * @Param : None + * @Return : Module status + ******************************************************************************/ eAtStatus_t Modem_HardReset(void) { HW_GPIO_Write(HXC_RESET_PORT, HXC_RESET_PIN, GPIO_PIN_RESET); @@ -557,11 +556,11 @@ return at_cmd_receive(NULL); } -/******************************************************************** - * @brief Check if any downlink packet is received - * @param None - * @retval TRUE or FALSE - ********************************************************************/ +/******************************************************************************* + * @Brief : Check if any downlink packet is received + * @Param : None + * @Return: TRUE or FALSE + ******************************************************************************/ bool Modem_IsNewDataReceived(void) { if(HW_UART_Modem_IsNewCharReceived() == false)