Kashish Haresh Shah
/
HXCClientShield
HXC Client Shield Repository.
LoRa/lora_driver.h@0:bacc6e701fb4, 2021-03-29 (annotated)
- Committer:
- kashish_mbed
- Date:
- Mon Mar 29 15:37:08 2021 +0000
- Revision:
- 0:bacc6e701fb4
- Child:
- 1:d4df183e5c12
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kashish_mbed | 0:bacc6e701fb4 | 1 | /* |
kashish_mbed | 0:bacc6e701fb4 | 2 | _ _ _____ _______ |
kashish_mbed | 0:bacc6e701fb4 | 3 | | | | | |_ _| |__ __| |
kashish_mbed | 0:bacc6e701fb4 | 4 | | |__| | __ ___ __ | | ___ | | |
kashish_mbed | 0:bacc6e701fb4 | 5 | | __ |/ _` \ \/ / | | / _ \| | |
kashish_mbed | 0:bacc6e701fb4 | 6 | | | | | (_| |> < _| || (_) | | |
kashish_mbed | 0:bacc6e701fb4 | 7 | |_| |_|\__,_/_/\_\_____\___/|_| |
kashish_mbed | 0:bacc6e701fb4 | 8 | (C)2017 HaxIoT |
kashish_mbed | 0:bacc6e701fb4 | 9 | */ |
kashish_mbed | 0:bacc6e701fb4 | 10 | /******************************************************************************* |
kashish_mbed | 0:bacc6e701fb4 | 11 | * @File : lora_driver.h |
kashish_mbed | 0:bacc6e701fb4 | 12 | * @Author : Fahad Mirza (Haxiot) |
kashish_mbed | 0:bacc6e701fb4 | 13 | * @Version : V1.0.0 |
kashish_mbed | 0:bacc6e701fb4 | 14 | * @Modified: 18 October, 2018 |
kashish_mbed | 0:bacc6e701fb4 | 15 | * @Brief : Header for driver lora_driver.h module |
kashish_mbed | 0:bacc6e701fb4 | 16 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 17 | * @attention |
kashish_mbed | 0:bacc6e701fb4 | 18 | * |
kashish_mbed | 0:bacc6e701fb4 | 19 | * <h2><center>© COPYRIGHT(c) 2017 Haxiot</center></h2> |
kashish_mbed | 0:bacc6e701fb4 | 20 | * |
kashish_mbed | 0:bacc6e701fb4 | 21 | * Redistribution and use in source and binary forms, with or without modification, |
kashish_mbed | 0:bacc6e701fb4 | 22 | * are permitted provided that the following conditions are met: |
kashish_mbed | 0:bacc6e701fb4 | 23 | * 1. Redistributions of source code must retain the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 24 | * this list of conditions and the following disclaimer. |
kashish_mbed | 0:bacc6e701fb4 | 25 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 26 | * this list of conditions and the following disclaimer in the documentation |
kashish_mbed | 0:bacc6e701fb4 | 27 | * and/or other materials provided with the distribution. |
kashish_mbed | 0:bacc6e701fb4 | 28 | * 3. Neither the name of Haxiot nor the names of its contributors |
kashish_mbed | 0:bacc6e701fb4 | 29 | * may be used to endorse or promote products derived from this software |
kashish_mbed | 0:bacc6e701fb4 | 30 | * without specific prior written permission. |
kashish_mbed | 0:bacc6e701fb4 | 31 | * |
kashish_mbed | 0:bacc6e701fb4 | 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
kashish_mbed | 0:bacc6e701fb4 | 33 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
kashish_mbed | 0:bacc6e701fb4 | 34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
kashish_mbed | 0:bacc6e701fb4 | 35 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
kashish_mbed | 0:bacc6e701fb4 | 36 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
kashish_mbed | 0:bacc6e701fb4 | 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
kashish_mbed | 0:bacc6e701fb4 | 38 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
kashish_mbed | 0:bacc6e701fb4 | 39 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
kashish_mbed | 0:bacc6e701fb4 | 40 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
kashish_mbed | 0:bacc6e701fb4 | 41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
kashish_mbed | 0:bacc6e701fb4 | 42 | * |
kashish_mbed | 0:bacc6e701fb4 | 43 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 44 | */ |
kashish_mbed | 0:bacc6e701fb4 | 45 | |
kashish_mbed | 0:bacc6e701fb4 | 46 | #ifndef __LORA_DRIVER_H |
kashish_mbed | 0:bacc6e701fb4 | 47 | #define __LORA_DRIVER_H |
kashish_mbed | 0:bacc6e701fb4 | 48 | |
kashish_mbed | 0:bacc6e701fb4 | 49 | #ifdef __cplusplus |
kashish_mbed | 0:bacc6e701fb4 | 50 | extern "C" { |
kashish_mbed | 0:bacc6e701fb4 | 51 | #endif |
kashish_mbed | 0:bacc6e701fb4 | 52 | |
kashish_mbed | 0:bacc6e701fb4 | 53 | /* Exported define -----------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 54 | #define MAX_PAYLOAD_SIZE 64U |
kashish_mbed | 0:bacc6e701fb4 | 55 | |
kashish_mbed | 0:bacc6e701fb4 | 56 | /* Exported types ------------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 57 | typedef enum eJoinMode |
kashish_mbed | 0:bacc6e701fb4 | 58 | { |
kashish_mbed | 0:bacc6e701fb4 | 59 | OTAA, |
kashish_mbed | 0:bacc6e701fb4 | 60 | ABP |
kashish_mbed | 0:bacc6e701fb4 | 61 | }eJoinMode_t; |
kashish_mbed | 0:bacc6e701fb4 | 62 | |
kashish_mbed | 0:bacc6e701fb4 | 63 | typedef enum eConfirmationStatus |
kashish_mbed | 0:bacc6e701fb4 | 64 | { |
kashish_mbed | 0:bacc6e701fb4 | 65 | UNCONFIRMED = 0, |
kashish_mbed | 0:bacc6e701fb4 | 66 | CONFIRMED = 1 |
kashish_mbed | 0:bacc6e701fb4 | 67 | }eConfirmationStatus_t; |
kashish_mbed | 0:bacc6e701fb4 | 68 | |
kashish_mbed | 0:bacc6e701fb4 | 69 | typedef enum eAdrStatus |
kashish_mbed | 0:bacc6e701fb4 | 70 | { |
kashish_mbed | 0:bacc6e701fb4 | 71 | ADR_OFF = 0, |
kashish_mbed | 0:bacc6e701fb4 | 72 | ADR_ON |
kashish_mbed | 0:bacc6e701fb4 | 73 | }eAdrStatus_t; |
kashish_mbed | 0:bacc6e701fb4 | 74 | |
kashish_mbed | 0:bacc6e701fb4 | 75 | typedef enum eJoinStatus |
kashish_mbed | 0:bacc6e701fb4 | 76 | { |
kashish_mbed | 0:bacc6e701fb4 | 77 | JOINED, |
kashish_mbed | 0:bacc6e701fb4 | 78 | NOT_JOINED |
kashish_mbed | 0:bacc6e701fb4 | 79 | }eJoinStatus_t; |
kashish_mbed | 0:bacc6e701fb4 | 80 | |
kashish_mbed | 0:bacc6e701fb4 | 81 | // LoRaWAN State Machine states |
kashish_mbed | 0:bacc6e701fb4 | 82 | typedef enum eDevicState |
kashish_mbed | 0:bacc6e701fb4 | 83 | { |
kashish_mbed | 0:bacc6e701fb4 | 84 | CLIENT_INIT, |
kashish_mbed | 0:bacc6e701fb4 | 85 | CLIENT_CONFIG, |
kashish_mbed | 0:bacc6e701fb4 | 86 | CLIENT_JOIN, |
kashish_mbed | 0:bacc6e701fb4 | 87 | CLIENT_SEND, |
kashish_mbed | 0:bacc6e701fb4 | 88 | CLIENT_SLEEP, |
kashish_mbed | 0:bacc6e701fb4 | 89 | CLIENT_DATA_RECEIVED, |
kashish_mbed | 0:bacc6e701fb4 | 90 | CLIENT_JOIN_STATUS_CHECK |
kashish_mbed | 0:bacc6e701fb4 | 91 | } eDeviceState_t; |
kashish_mbed | 0:bacc6e701fb4 | 92 | |
kashish_mbed | 0:bacc6e701fb4 | 93 | typedef struct sLoraConfig |
kashish_mbed | 0:bacc6e701fb4 | 94 | { |
kashish_mbed | 0:bacc6e701fb4 | 95 | eJoinMode_t JoinMode; |
kashish_mbed | 0:bacc6e701fb4 | 96 | eAdrStatus_t AdrStatus; |
kashish_mbed | 0:bacc6e701fb4 | 97 | char Class; |
kashish_mbed | 0:bacc6e701fb4 | 98 | char *DevEui; |
kashish_mbed | 0:bacc6e701fb4 | 99 | char *AppEui; |
kashish_mbed | 0:bacc6e701fb4 | 100 | char *AppKey; |
kashish_mbed | 0:bacc6e701fb4 | 101 | }sLoraConfig_t; |
kashish_mbed | 0:bacc6e701fb4 | 102 | |
kashish_mbed | 0:bacc6e701fb4 | 103 | typedef struct sLoraDriverParam |
kashish_mbed | 0:bacc6e701fb4 | 104 | { |
kashish_mbed | 0:bacc6e701fb4 | 105 | uint32_t UplinkCycle; |
kashish_mbed | 0:bacc6e701fb4 | 106 | // Callbacks |
kashish_mbed | 0:bacc6e701fb4 | 107 | uint8_t (*UplinkHandler)(uint8_t *buffer, uint8_t bufSize, uint8_t *ack, uint8_t *port); |
kashish_mbed | 0:bacc6e701fb4 | 108 | void (*DownlinkHandler)(uint8_t *buffer, uint8_t dataSize, uint8_t ack, uint8_t port); |
kashish_mbed | 0:bacc6e701fb4 | 109 | }sLoraDriverParam_t; |
kashish_mbed | 0:bacc6e701fb4 | 110 | |
kashish_mbed | 0:bacc6e701fb4 | 111 | /* Public functions ----------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 112 | void Lora_init(sLoraConfig_t *loraConfig, sLoraDriverParam_t *loraDriverParam); |
kashish_mbed | 0:bacc6e701fb4 | 113 | void Lora_fsm(void); |
kashish_mbed | 0:bacc6e701fb4 | 114 | uint16_t Lora_getFwVersion(void); |
kashish_mbed | 0:bacc6e701fb4 | 115 | uint8_t Lora_getBatteryLevel(void); |
kashish_mbed | 0:bacc6e701fb4 | 116 | void Lora_updateUplinkRate(uint32_t time_s); |
kashish_mbed | 0:bacc6e701fb4 | 117 | |
kashish_mbed | 0:bacc6e701fb4 | 118 | #ifdef __cplusplus |
kashish_mbed | 0:bacc6e701fb4 | 119 | } |
kashish_mbed | 0:bacc6e701fb4 | 120 | #endif /* __cplusplus */ |
kashish_mbed | 0:bacc6e701fb4 | 121 | |
kashish_mbed | 0:bacc6e701fb4 | 122 | #endif |