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