Fahad Mirza
/
Nucleo_HXC900
A demo application for HXC900 LoRaWAN module using Nucleo-L053R8.
LoRa/lora_driver.h@10:19da323c2bc0, 2018-07-18 (annotated)
- Committer:
- fahadmirza
- Date:
- Wed Jul 18 19:51:17 2018 +0000
- Revision:
- 10:19da323c2bc0
- Parent:
- 5:53302861bfea
- Child:
- 15:2860c960d2ff
Application can change DeviceState;; Removed hardcoded ADR status;; Renamed Time Server callbacks;; Local functions are static now;
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 : lora_driver.h |
fahadmirza | 0:a0c5877bd360 | 12 | * Author : Fahad Mirza (Haxiot) |
fahadmirza | 0:a0c5877bd360 | 13 | * Version : V1.0.0 |
fahadmirza | 0:a0c5877bd360 | 14 | * Modified: 13-April-2018 |
fahadmirza | 0:a0c5877bd360 | 15 | * Brief : Header for driver lora_driver.h 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 | #ifndef __LORA_DRIVER_H |
fahadmirza | 0:a0c5877bd360 | 47 | #define __LORA_DRIVER_H |
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 | /* Exported types ------------------------------------------------------------*/ |
fahadmirza | 0:a0c5877bd360 | 54 | typedef enum eJoinMode |
fahadmirza | 0:a0c5877bd360 | 55 | { |
fahadmirza | 0:a0c5877bd360 | 56 | OTAA, |
fahadmirza | 0:a0c5877bd360 | 57 | ABP |
fahadmirza | 0:a0c5877bd360 | 58 | }eJoinMode_t; |
fahadmirza | 0:a0c5877bd360 | 59 | |
fahadmirza | 2:1ef859bc5cd2 | 60 | typedef enum eAdrStatus |
fahadmirza | 2:1ef859bc5cd2 | 61 | { |
fahadmirza | 2:1ef859bc5cd2 | 62 | ADR_OFF = 0, |
fahadmirza | 2:1ef859bc5cd2 | 63 | ADR_ON |
fahadmirza | 2:1ef859bc5cd2 | 64 | }eAdrStatus_t; |
fahadmirza | 2:1ef859bc5cd2 | 65 | |
fahadmirza | 0:a0c5877bd360 | 66 | typedef enum eJoinStatus |
fahadmirza | 0:a0c5877bd360 | 67 | { |
fahadmirza | 0:a0c5877bd360 | 68 | JOINED, |
fahadmirza | 0:a0c5877bd360 | 69 | NOT_JOINED |
fahadmirza | 0:a0c5877bd360 | 70 | }eJoinStatus_t; |
fahadmirza | 0:a0c5877bd360 | 71 | |
fahadmirza | 10:19da323c2bc0 | 72 | // LoRaWAN State Machine states |
fahadmirza | 10:19da323c2bc0 | 73 | typedef enum eDevicState |
fahadmirza | 10:19da323c2bc0 | 74 | { |
fahadmirza | 10:19da323c2bc0 | 75 | DEVICE_INIT, |
fahadmirza | 10:19da323c2bc0 | 76 | DEVICE_CONFIG, |
fahadmirza | 10:19da323c2bc0 | 77 | DEVICE_JOIN, |
fahadmirza | 10:19da323c2bc0 | 78 | DEVICE_SEND, |
fahadmirza | 10:19da323c2bc0 | 79 | SLEEP_DEVICE, |
fahadmirza | 10:19da323c2bc0 | 80 | DEVICE_DATA_RECEIVED, |
fahadmirza | 10:19da323c2bc0 | 81 | DEVICE_JOIN_STATUS_CHECK |
fahadmirza | 10:19da323c2bc0 | 82 | } eDeviceState_t; |
fahadmirza | 10:19da323c2bc0 | 83 | |
fahadmirza | 0:a0c5877bd360 | 84 | typedef struct sLoraConfig |
fahadmirza | 0:a0c5877bd360 | 85 | { |
fahadmirza | 0:a0c5877bd360 | 86 | eJoinMode_t joinMode; |
fahadmirza | 2:1ef859bc5cd2 | 87 | eAdrStatus_t adrStatus; |
fahadmirza | 0:a0c5877bd360 | 88 | char class_; |
fahadmirza | 0:a0c5877bd360 | 89 | char *devEui; |
fahadmirza | 0:a0c5877bd360 | 90 | char *appEui; |
fahadmirza | 0:a0c5877bd360 | 91 | char *appKey; |
fahadmirza | 0:a0c5877bd360 | 92 | }sLoraConfig_t; |
fahadmirza | 0:a0c5877bd360 | 93 | |
fahadmirza | 0:a0c5877bd360 | 94 | typedef struct sLoraDriverParam |
fahadmirza | 0:a0c5877bd360 | 95 | { |
fahadmirza | 0:a0c5877bd360 | 96 | uint32_t SensorMeasureTime; |
fahadmirza | 10:19da323c2bc0 | 97 | // Callbacks |
fahadmirza | 10:19da323c2bc0 | 98 | void (*SendDataHandler)(uint8_t *buffer, uint8_t *dataSize, uint8_t *ack, uint8_t *port); |
fahadmirza | 0:a0c5877bd360 | 99 | void (*ReceiveDataHandler)(uint8_t *buffer, uint8_t dataSize, uint8_t ack, uint8_t port); |
fahadmirza | 0:a0c5877bd360 | 100 | }sLoraDriverParam_t; |
fahadmirza | 0:a0c5877bd360 | 101 | |
fahadmirza | 0:a0c5877bd360 | 102 | /* Public functions ----------------------------------------------------------*/ |
fahadmirza | 0:a0c5877bd360 | 103 | void Lora_init(sLoraConfig_t *loraConfig, sLoraDriverParam_t *loraDriverParam); |
fahadmirza | 0:a0c5877bd360 | 104 | void Lora_fsm(void); |
fahadmirza | 0:a0c5877bd360 | 105 | |
fahadmirza | 10:19da323c2bc0 | 106 | void Lora_ChangeDeviceState(eDeviceState_t newDeviceState); |
fahadmirza | 10:19da323c2bc0 | 107 | |
fahadmirza | 0:a0c5877bd360 | 108 | #ifdef __cplusplus |
fahadmirza | 0:a0c5877bd360 | 109 | } |
fahadmirza | 0:a0c5877bd360 | 110 | #endif /* __cplusplus */ |
fahadmirza | 0:a0c5877bd360 | 111 | |
fahadmirza | 0:a0c5877bd360 | 112 | #endif |