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

Dependencies:   mbed

Committer:
fahadmirza
Date:
Mon Dec 10 19:54:23 2018 +0000
Revision:
31:174c745f921c
Parent:
28:c777d977b252
Child:
32:2d0678039a09
FWversion and battery level are added to the payload from the application layer instead of from the lora driver;

Who changed what in which revision?

UserRevisionLine numberNew 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 22:5b77cf59d630 11 * @File : lora_driver.h
fahadmirza 22:5b77cf59d630 12 * @Author : Fahad Mirza (Haxiot)
fahadmirza 22:5b77cf59d630 13 * @Version : V1.0.0
fahadmirza 22:5b77cf59d630 14 * @Modified: 18 October, 2018
fahadmirza 22:5b77cf59d630 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>&copy; 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 27:517ca3a30ad7 53 /* Exported define -----------------------------------------------------------*/
fahadmirza 27:517ca3a30ad7 54 #define MAX_PAYLOAD_SIZE 64
fahadmirza 27:517ca3a30ad7 55
fahadmirza 0:a0c5877bd360 56 /* Exported types ------------------------------------------------------------*/
fahadmirza 0:a0c5877bd360 57 typedef enum eJoinMode
fahadmirza 0:a0c5877bd360 58 {
fahadmirza 0:a0c5877bd360 59 OTAA,
fahadmirza 0:a0c5877bd360 60 ABP
fahadmirza 0:a0c5877bd360 61 }eJoinMode_t;
fahadmirza 0:a0c5877bd360 62
fahadmirza 22:5b77cf59d630 63 typedef enum eConfirmationStatus
fahadmirza 22:5b77cf59d630 64 {
fahadmirza 22:5b77cf59d630 65 UNCONFIRMED = 0,
fahadmirza 22:5b77cf59d630 66 CONFIRMED = 1
fahadmirza 22:5b77cf59d630 67 }eConfirmationStatus_t;
fahadmirza 22:5b77cf59d630 68
fahadmirza 2:1ef859bc5cd2 69 typedef enum eAdrStatus
fahadmirza 2:1ef859bc5cd2 70 {
fahadmirza 2:1ef859bc5cd2 71 ADR_OFF = 0,
fahadmirza 2:1ef859bc5cd2 72 ADR_ON
fahadmirza 2:1ef859bc5cd2 73 }eAdrStatus_t;
fahadmirza 2:1ef859bc5cd2 74
fahadmirza 0:a0c5877bd360 75 typedef enum eJoinStatus
fahadmirza 0:a0c5877bd360 76 {
fahadmirza 0:a0c5877bd360 77 JOINED,
fahadmirza 0:a0c5877bd360 78 NOT_JOINED
fahadmirza 0:a0c5877bd360 79 }eJoinStatus_t;
fahadmirza 0:a0c5877bd360 80
fahadmirza 10:19da323c2bc0 81 // LoRaWAN State Machine states
fahadmirza 10:19da323c2bc0 82 typedef enum eDevicState
fahadmirza 10:19da323c2bc0 83 {
fahadmirza 26:176e648c03f6 84 CLIENT_INIT,
fahadmirza 26:176e648c03f6 85 CLIENT_CONFIG,
fahadmirza 26:176e648c03f6 86 CLIENT_JOIN,
fahadmirza 26:176e648c03f6 87 CLIENT_SEND,
fahadmirza 26:176e648c03f6 88 CLIENT_SLEEP,
fahadmirza 26:176e648c03f6 89 CLIENT_DATA_RECEIVED,
fahadmirza 26:176e648c03f6 90 CLIENT_JOIN_STATUS_CHECK
fahadmirza 10:19da323c2bc0 91 } eDeviceState_t;
fahadmirza 10:19da323c2bc0 92
fahadmirza 0:a0c5877bd360 93 typedef struct sLoraConfig
fahadmirza 0:a0c5877bd360 94 {
fahadmirza 24:f3b987589609 95 eJoinMode_t JoinMode;
fahadmirza 24:f3b987589609 96 eAdrStatus_t AdrStatus;
fahadmirza 24:f3b987589609 97 char Class;
fahadmirza 24:f3b987589609 98 char *DevEui;
fahadmirza 24:f3b987589609 99 char *AppEui;
fahadmirza 24:f3b987589609 100 char *AppKey;
fahadmirza 0:a0c5877bd360 101 }sLoraConfig_t;
fahadmirza 0:a0c5877bd360 102
fahadmirza 0:a0c5877bd360 103 typedef struct sLoraDriverParam
fahadmirza 0:a0c5877bd360 104 {
fahadmirza 0:a0c5877bd360 105 uint32_t SensorMeasureTime;
fahadmirza 10:19da323c2bc0 106 // Callbacks
fahadmirza 28:c777d977b252 107 uint8_t (*SendDataHandler)(uint8_t *buffer, uint8_t bufSize, uint8_t *ack, uint8_t *port);
fahadmirza 0:a0c5877bd360 108 void (*ReceiveDataHandler)(uint8_t *buffer, uint8_t dataSize, uint8_t ack, uint8_t port);
fahadmirza 0:a0c5877bd360 109 }sLoraDriverParam_t;
fahadmirza 0:a0c5877bd360 110
fahadmirza 0:a0c5877bd360 111 /* Public functions ----------------------------------------------------------*/
fahadmirza 0:a0c5877bd360 112 void Lora_init(sLoraConfig_t *loraConfig, sLoraDriverParam_t *loraDriverParam);
fahadmirza 0:a0c5877bd360 113 void Lora_fsm(void);
fahadmirza 31:174c745f921c 114 uint8_t Lora_getFwVersion(void);
fahadmirza 31:174c745f921c 115 uint8_t Lora_getBatteryLevel(void);
fahadmirza 10:19da323c2bc0 116
fahadmirza 0:a0c5877bd360 117 #ifdef __cplusplus
fahadmirza 0:a0c5877bd360 118 }
fahadmirza 0:a0c5877bd360 119 #endif /* __cplusplus */
fahadmirza 0:a0c5877bd360 120
fahadmirza 0:a0c5877bd360 121 #endif