A demo application for HXC900 LoRaWAN module using Nucleo-L053R8.

Dependencies:   mbed

Committer:
fahadmirza
Date:
Thu Jan 24 23:45:12 2019 +0000
Revision:
39:cb0e5a76ab15
Parent:
38:e082379b1946
Doxygen style header

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fahadmirza 38:e082379b1946 1 /**
fahadmirza 38:e082379b1946 2 ******************************************************************************
fahadmirza 39:cb0e5a76ab15 3 * @file hxc_client.h
fahadmirza 39:cb0e5a76ab15 4 * @author Fahad Mirza (Haxiot)
fahadmirza 39:cb0e5a76ab15 5 * @version V1.0.0
fahadmirza 39:cb0e5a76ab15 6 * @modified 24-Jan-2019
fahadmirza 39:cb0e5a76ab15 7 * @brief Header for driver hxc_client.c module
fahadmirza 0:a0c5877bd360 8 ******************************************************************************
fahadmirza 0:a0c5877bd360 9 * @attention
fahadmirza 0:a0c5877bd360 10 *
fahadmirza 38:e082379b1946 11 * _ _ _____ _______
fahadmirza 38:e082379b1946 12 * | | | | |_ _| |__ __|
fahadmirza 38:e082379b1946 13 * | |__| | __ ___ __ | | ___ | |
fahadmirza 38:e082379b1946 14 * | __ |/ _` \ \/ / | | / _ \| |
fahadmirza 38:e082379b1946 15 * | | | | (_| |> < _| || (_) | |
fahadmirza 38:e082379b1946 16 * |_| |_|\__,_/_/\_\_____\___/|_|
fahadmirza 38:e082379b1946 17 * (C)2017 HaxIoT
fahadmirza 0:a0c5877bd360 18 * <h2><center>&copy; COPYRIGHT(c) 2017 Haxiot</center></h2>
fahadmirza 0:a0c5877bd360 19 *
fahadmirza 0:a0c5877bd360 20 * Redistribution and use in source and binary forms, with or without modification,
fahadmirza 0:a0c5877bd360 21 * are permitted provided that the following conditions are met:
fahadmirza 0:a0c5877bd360 22 * 1. Redistributions of source code must retain the above copyright notice,
fahadmirza 0:a0c5877bd360 23 * this list of conditions and the following disclaimer.
fahadmirza 0:a0c5877bd360 24 * 2. Redistributions in binary form must reproduce the above copyright notice,
fahadmirza 0:a0c5877bd360 25 * this list of conditions and the following disclaimer in the documentation
fahadmirza 0:a0c5877bd360 26 * and/or other materials provided with the distribution.
fahadmirza 0:a0c5877bd360 27 * 3. Neither the name of Haxiot nor the names of its contributors
fahadmirza 0:a0c5877bd360 28 * may be used to endorse or promote products derived from this software
fahadmirza 0:a0c5877bd360 29 * without specific prior written permission.
fahadmirza 0:a0c5877bd360 30 *
fahadmirza 0:a0c5877bd360 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fahadmirza 0:a0c5877bd360 32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fahadmirza 0:a0c5877bd360 33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
fahadmirza 0:a0c5877bd360 34 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
fahadmirza 0:a0c5877bd360 35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
fahadmirza 0:a0c5877bd360 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
fahadmirza 0:a0c5877bd360 37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
fahadmirza 0:a0c5877bd360 38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
fahadmirza 0:a0c5877bd360 39 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
fahadmirza 0:a0c5877bd360 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
fahadmirza 0:a0c5877bd360 41 *
fahadmirza 0:a0c5877bd360 42 ******************************************************************************
fahadmirza 0:a0c5877bd360 43 */
fahadmirza 0:a0c5877bd360 44
fahadmirza 0:a0c5877bd360 45 /* Define to prevent recursive inclusion -------------------------------------*/
fahadmirza 0:a0c5877bd360 46 #ifndef __HXC_CLIENT__
fahadmirza 0:a0c5877bd360 47 #define __HXC_CLIENT__
fahadmirza 0:a0c5877bd360 48
fahadmirza 0:a0c5877bd360 49 #ifdef __cplusplus
fahadmirza 0:a0c5877bd360 50 extern "C" {
fahadmirza 0:a0c5877bd360 51 #endif
fahadmirza 0:a0c5877bd360 52
fahadmirza 0:a0c5877bd360 53
fahadmirza 0:a0c5877bd360 54 /* Includes ------------------------------------------------------------------*/
fahadmirza 0:a0c5877bd360 55 #include<stdint.h>
fahadmirza 0:a0c5877bd360 56 #include<stdbool.h>
fahadmirza 0:a0c5877bd360 57
fahadmirza 0:a0c5877bd360 58 /* Typedefs ------------------------------------------------------------------*/
fahadmirza 0:a0c5877bd360 59 /*
fahadmirza 0:a0c5877bd360 60 * AT Command statuses, in direct relationship with AT_RetCode static array
fahadmirza 0:a0c5877bd360 61 */
fahadmirza 0:a0c5877bd360 62 typedef enum eAtStatus
fahadmirza 0:a0c5877bd360 63 {
fahadmirza 0:a0c5877bd360 64 AT_OK = 0,
fahadmirza 0:a0c5877bd360 65 AT_ERROR,
fahadmirza 0:a0c5877bd360 66 AT_PARAM_ERROR,
fahadmirza 0:a0c5877bd360 67 AT_BUSY_ERROR,
fahadmirza 0:a0c5877bd360 68 AT_PARAM_OVERFLOW,
fahadmirza 0:a0c5877bd360 69 AT_INVALID_MODE,
fahadmirza 0:a0c5877bd360 70 AT_NO_NET_JOINED,
fahadmirza 0:a0c5877bd360 71 AT_PAYLOAD_SIZE_ERROR,
fahadmirza 0:a0c5877bd360 72 AT_END_ERROR,
fahadmirza 0:a0c5877bd360 73 AT_CMD_ERROR,
fahadmirza 0:a0c5877bd360 74 AT_UART_LINK_ERROR, // Return code to notify error during UART Tx/Rx/Config
fahadmirza 15:2860c960d2ff 75 AT_TIMEOUT,
fahadmirza 0:a0c5877bd360 76 } eAtStatus_t;
fahadmirza 0:a0c5877bd360 77
fahadmirza 0:a0c5877bd360 78 /*
fahadmirza 0:a0c5877bd360 79 * AT Command Index.
fahadmirza 0:a0c5877bd360 80 * In direct relationship with "CmdTab" static array in atcmd.c
fahadmirza 0:a0c5877bd360 81 */
fahadmirza 0:a0c5877bd360 82 typedef enum ATCmd
fahadmirza 0:a0c5877bd360 83 {
fahadmirza 0:a0c5877bd360 84 AT,
fahadmirza 0:a0c5877bd360 85 AT_RESET,
fahadmirza 0:a0c5877bd360 86 AT_FD,
fahadmirza 0:a0c5877bd360 87 AT_DEVEUI,
fahadmirza 0:a0c5877bd360 88 AT_DEVADR,
fahadmirza 0:a0c5877bd360 89 AT_APPKEY,
fahadmirza 0:a0c5877bd360 90 AT_NWKSKEY,
fahadmirza 0:a0c5877bd360 91 AT_APPSKEY,
fahadmirza 0:a0c5877bd360 92 AT_APPEUI,
fahadmirza 0:a0c5877bd360 93 AT_ADR,
fahadmirza 0:a0c5877bd360 94 AT_TXP,
fahadmirza 0:a0c5877bd360 95 AT_DR,
fahadmirza 0:a0c5877bd360 96 AT_DCS,
fahadmirza 0:a0c5877bd360 97 AT_PNM,
fahadmirza 0:a0c5877bd360 98 AT_RX2WND,
fahadmirza 0:a0c5877bd360 99 AT_RX1DL,
fahadmirza 0:a0c5877bd360 100 AT_RX2DL,
fahadmirza 0:a0c5877bd360 101 AT_JN1DL,
fahadmirza 0:a0c5877bd360 102 AT_JN2DL,
fahadmirza 0:a0c5877bd360 103 AT_NJM,
fahadmirza 0:a0c5877bd360 104 AT_NWKID,
fahadmirza 0:a0c5877bd360 105 AT_FCU,
fahadmirza 0:a0c5877bd360 106 AT_FCD,
fahadmirza 0:a0c5877bd360 107 AT_CLASS,
fahadmirza 0:a0c5877bd360 108 AT_CH,
fahadmirza 0:a0c5877bd360 109 AT_JOIN,
fahadmirza 0:a0c5877bd360 110 AT_NJS,
fahadmirza 0:a0c5877bd360 111 AT_SENDB,
fahadmirza 0:a0c5877bd360 112 AT_SEND,
fahadmirza 0:a0c5877bd360 113 AT_RECVB,
fahadmirza 0:a0c5877bd360 114 AT_CFS,
fahadmirza 0:a0c5877bd360 115 AT_SNR,
fahadmirza 0:a0c5877bd360 116 AT_RSSI,
fahadmirza 0:a0c5877bd360 117 AT_MODE,
fahadmirza 0:a0c5877bd360 118 AT_RFCFG,
fahadmirza 0:a0c5877bd360 119 AT_TXCW,
fahadmirza 0:a0c5877bd360 120 AT_TX,
fahadmirza 0:a0c5877bd360 121 AT_RX,
fahadmirza 0:a0c5877bd360 122 AT_BAT,
fahadmirza 0:a0c5877bd360 123 AT_VER,
fahadmirza 0:a0c5877bd360 124 AT_END
fahadmirza 0:a0c5877bd360 125 } ATCmd_t;
fahadmirza 0:a0c5877bd360 126
fahadmirza 0:a0c5877bd360 127 // AT command behaviors
fahadmirza 0:a0c5877bd360 128 typedef enum ATGroup
fahadmirza 0:a0c5877bd360 129 {
fahadmirza 0:a0c5877bd360 130 AT_CTRL = 0,
fahadmirza 0:a0c5877bd360 131 AT_SET,
fahadmirza 0:a0c5877bd360 132 AT_GET,
fahadmirza 0:a0c5877bd360 133 AT_TEST,
fahadmirza 0:a0c5877bd360 134 }ATGroup_t;
fahadmirza 0:a0c5877bd360 135
fahadmirza 0:a0c5877bd360 136 // Type definition for SEND command
fahadmirza 0:a0c5877bd360 137 typedef struct sSendDataString
fahadmirza 0:a0c5877bd360 138 {
fahadmirza 0:a0c5877bd360 139 char *Buffer;
fahadmirza 0:a0c5877bd360 140 uint8_t Port;
fahadmirza 0:a0c5877bd360 141 uint8_t Ack;
fahadmirza 0:a0c5877bd360 142 }sSendDataString_t;
fahadmirza 0:a0c5877bd360 143
fahadmirza 0:a0c5877bd360 144 // Type definition for SENDB command
fahadmirza 0:a0c5877bd360 145 typedef struct sSendDataBinary
fahadmirza 0:a0c5877bd360 146 {
fahadmirza 0:a0c5877bd360 147 uint8_t *Buffer;
fahadmirza 0:a0c5877bd360 148 uint8_t DataSize;
fahadmirza 0:a0c5877bd360 149 uint8_t Port;
fahadmirza 0:a0c5877bd360 150 uint8_t Ack;
fahadmirza 0:a0c5877bd360 151 }sSendDataBinary_t;
fahadmirza 0:a0c5877bd360 152
fahadmirza 0:a0c5877bd360 153 // Type definition for received data
fahadmirza 0:a0c5877bd360 154 typedef struct sRecvDataBinary
fahadmirza 0:a0c5877bd360 155 {
fahadmirza 0:a0c5877bd360 156 uint8_t *Buffer;
fahadmirza 0:a0c5877bd360 157 uint32_t DataSize;
fahadmirza 0:a0c5877bd360 158 uint8_t Port;
fahadmirza 0:a0c5877bd360 159 uint8_t Ack;
fahadmirza 0:a0c5877bd360 160 }sRecvDataBinary_t;
fahadmirza 0:a0c5877bd360 161
fahadmirza 0:a0c5877bd360 162
fahadmirza 0:a0c5877bd360 163 /* Exported functions ------------------------------------------------------- */
fahadmirza 0:a0c5877bd360 164
fahadmirza 0:a0c5877bd360 165 /********************************************************************
fahadmirza 0:a0c5877bd360 166 * @brief Configures modem UART interface and Reset GPIO
fahadmirza 0:a0c5877bd360 167 * @param None
fahadmirza 0:a0c5877bd360 168 * @retval AT_OK in case of success
fahadmirza 0:a0c5877bd360 169 * @retval AT_UART_LINK_ERROR in case of failure
fahadmirza 0:a0c5877bd360 170 *********************************************************************/
fahadmirza 0:a0c5877bd360 171 eAtStatus_t Modem_Init( void ) ;
fahadmirza 0:a0c5877bd360 172
fahadmirza 0:a0c5877bd360 173 /********************************************************************
fahadmirza 0:a0c5877bd360 174 * @brief Deinitialize modem UART interface.
fahadmirza 0:a0c5877bd360 175 * @param None
fahadmirza 0:a0c5877bd360 176 * @retval None
fahadmirza 0:a0c5877bd360 177 *********************************************************************/
fahadmirza 0:a0c5877bd360 178 void Modem_IO_DeInit( void ) ;
fahadmirza 0:a0c5877bd360 179
fahadmirza 0:a0c5877bd360 180 /********************************************************************
fahadmirza 0:a0c5877bd360 181 * @brief Handle the AT cmd following their Group type
fahadmirza 0:a0c5877bd360 182 * @param at_group AT group [control, set , get)
fahadmirza 0:a0c5877bd360 183 * Cmd AT command
fahadmirza 0:a0c5877bd360 184 * pdata pointer to the IN/OUT buffer
fahadmirza 0:a0c5877bd360 185 * @retval module status
fahadmirza 0:a0c5877bd360 186 ********************************************************************/
fahadmirza 0:a0c5877bd360 187 eAtStatus_t Modem_AT_Cmd(ATGroup_t at_group, ATCmd_t Cmd, void *pdata);
fahadmirza 0:a0c5877bd360 188
fahadmirza 0:a0c5877bd360 189 /********************************************************************
fahadmirza 0:a0c5877bd360 190 * @brief Reset the HXC client modem using HXC RESET pin
fahadmirza 0:a0c5877bd360 191 * @param None
fahadmirza 0:a0c5877bd360 192 * @retval module status
fahadmirza 0:a0c5877bd360 193 ********************************************************************/
fahadmirza 0:a0c5877bd360 194 eAtStatus_t Modem_HardReset(void);
fahadmirza 0:a0c5877bd360 195
fahadmirza 0:a0c5877bd360 196 /********************************************************************
fahadmirza 0:a0c5877bd360 197 * @brief Check if any downlink packet is received
fahadmirza 0:a0c5877bd360 198 * @param None
fahadmirza 0:a0c5877bd360 199 * @retval TRUE or FALSE
fahadmirza 0:a0c5877bd360 200 ********************************************************************/
fahadmirza 0:a0c5877bd360 201 bool Modem_IsNewDataReceived(void);
fahadmirza 0:a0c5877bd360 202
fahadmirza 32:2d0678039a09 203 char* Modem_GetResponseBuffer(void);
fahadmirza 0:a0c5877bd360 204
fahadmirza 0:a0c5877bd360 205
fahadmirza 0:a0c5877bd360 206 #ifdef __cplusplus
fahadmirza 0:a0c5877bd360 207 }
fahadmirza 0:a0c5877bd360 208 #endif
fahadmirza 0:a0c5877bd360 209
fahadmirza 0:a0c5877bd360 210 #endif /* __HXC_CLIENT__ */
fahadmirza 0:a0c5877bd360 211
fahadmirza 0:a0c5877bd360 212 /************************ (C) COPYRIGHT Haxiot *****END OF FILE****/
fahadmirza 0:a0c5877bd360 213