LoRa_Miun_Lib

Dependents:   Smart_Miun

Committer:
biwa1400
Date:
Wed Oct 11 10:17:10 2017 +0000
Revision:
3:8849166ce7e5
20171011;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
biwa1400 3:8849166ce7e5 1 /**
biwa1400 3:8849166ce7e5 2 * @file LoRa.h
biwa1400 3:8849166ce7e5 3 * @brief Application call
biwa1400 3:8849166ce7e5 4 * @author Bin Wang
biwa1400 3:8849166ce7e5 5 * @version 1.0
biwa1400 3:8849166ce7e5 6 */
biwa1400 3:8849166ce7e5 7
biwa1400 3:8849166ce7e5 8 #ifndef MIUN_LORA_H
biwa1400 3:8849166ce7e5 9 #define MIUN_LORA_H
biwa1400 3:8849166ce7e5 10
biwa1400 3:8849166ce7e5 11 #include "mDot.h"
biwa1400 3:8849166ce7e5 12 #include "mDotEvent.h"
biwa1400 3:8849166ce7e5 13
biwa1400 3:8849166ce7e5 14
biwa1400 3:8849166ce7e5 15 namespace MIUN
biwa1400 3:8849166ce7e5 16 {
biwa1400 3:8849166ce7e5 17
biwa1400 3:8849166ce7e5 18 class LoRa;
biwa1400 3:8849166ce7e5 19
biwa1400 3:8849166ce7e5 20 class MacCommandEvent : public mDotEvent
biwa1400 3:8849166ce7e5 21 {
biwa1400 3:8849166ce7e5 22 /*** CommandType ***/
biwa1400 3:8849166ce7e5 23 private:
biwa1400 3:8849166ce7e5 24 enum CommmandType
biwa1400 3:8849166ce7e5 25 {
biwa1400 3:8849166ce7e5 26 decreaseSF = 0x80,
biwa1400 3:8849166ce7e5 27 increaseSF = 0x81,
biwa1400 3:8849166ce7e5 28 changeSleepTime = 0x82,
biwa1400 3:8849166ce7e5 29 };
biwa1400 3:8849166ce7e5 30
biwa1400 3:8849166ce7e5 31 enum CommmandType_length
biwa1400 3:8849166ce7e5 32 {
biwa1400 3:8849166ce7e5 33 decreaseSF_length = 1,
biwa1400 3:8849166ce7e5 34 increaseSF_length = 1,
biwa1400 3:8849166ce7e5 35 changeSleepTime_length = 5,
biwa1400 3:8849166ce7e5 36 };
biwa1400 3:8849166ce7e5 37
biwa1400 3:8849166ce7e5 38
biwa1400 3:8849166ce7e5 39
biwa1400 3:8849166ce7e5 40 private:
biwa1400 3:8849166ce7e5 41 LoRa& loraHandle;
biwa1400 3:8849166ce7e5 42 public:
biwa1400 3:8849166ce7e5 43 MacCommandEvent(LoRa& loraHandle);
biwa1400 3:8849166ce7e5 44
biwa1400 3:8849166ce7e5 45 virtual ~MacCommandEvent() {}
biwa1400 3:8849166ce7e5 46
biwa1400 3:8849166ce7e5 47 virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot);
biwa1400 3:8849166ce7e5 48
biwa1400 3:8849166ce7e5 49 virtual uint8_t MeasureBattery();
biwa1400 3:8849166ce7e5 50
biwa1400 3:8849166ce7e5 51 private:
biwa1400 3:8849166ce7e5 52 void processSFDecrease(uint8_t *payload);
biwa1400 3:8849166ce7e5 53 void processSFIncrease(uint8_t *payload);
biwa1400 3:8849166ce7e5 54 void processChangeSleepTm(uint8_t *macCommand);
biwa1400 3:8849166ce7e5 55 void processqueryBatteryLevel(uint8_t *macCommand);
biwa1400 3:8849166ce7e5 56
biwa1400 3:8849166ce7e5 57 void sendCommand (uint8_t* command, int commandLength);
biwa1400 3:8849166ce7e5 58 };
biwa1400 3:8849166ce7e5 59
biwa1400 3:8849166ce7e5 60 class LoRa
biwa1400 3:8849166ce7e5 61 {
biwa1400 3:8849166ce7e5 62 /*** Parameters ***/
biwa1400 3:8849166ce7e5 63 private:
biwa1400 3:8849166ce7e5 64 uint8_t rejoinTimes;
biwa1400 3:8849166ce7e5 65 uint8_t retransTimes;
biwa1400 3:8849166ce7e5 66 uint8_t installSF;
biwa1400 3:8849166ce7e5 67 uint32_t sleepTime;
biwa1400 3:8849166ce7e5 68 uint32_t defaultSleepTime;
biwa1400 3:8849166ce7e5 69
biwa1400 3:8849166ce7e5 70 int receivePort;
biwa1400 3:8849166ce7e5 71
biwa1400 3:8849166ce7e5 72 uint8_t batteryLevel;
biwa1400 3:8849166ce7e5 73
biwa1400 3:8849166ce7e5 74 /*** component ***/
biwa1400 3:8849166ce7e5 75 private:
biwa1400 3:8849166ce7e5 76 mDot* dot;
biwa1400 3:8849166ce7e5 77 MacCommandEvent macCommandEvent;
biwa1400 3:8849166ce7e5 78
biwa1400 3:8849166ce7e5 79 /*** constructor ***/
biwa1400 3:8849166ce7e5 80 public:
biwa1400 3:8849166ce7e5 81 LoRa();
biwa1400 3:8849166ce7e5 82
biwa1400 3:8849166ce7e5 83 /*** Handle Functins ***/
biwa1400 3:8849166ce7e5 84
biwa1400 3:8849166ce7e5 85 public:
biwa1400 3:8849166ce7e5 86 /*** Information ***/
biwa1400 3:8849166ce7e5 87 void showInfo();
biwa1400 3:8849166ce7e5 88
biwa1400 3:8849166ce7e5 89 /*** sleep ***/
biwa1400 3:8849166ce7e5 90 void sleep();
biwa1400 3:8849166ce7e5 91 void sleep(const uint32_t& interval_s);
biwa1400 3:8849166ce7e5 92 void sleepWaitingNextFreeChannel();
biwa1400 3:8849166ce7e5 93
biwa1400 3:8849166ce7e5 94 /*** Network ***/
biwa1400 3:8849166ce7e5 95 bool joinNetwork ();
biwa1400 3:8849166ce7e5 96 bool send_basic(std::string input_data);
biwa1400 3:8849166ce7e5 97 bool send(std::string input_data, int port);
biwa1400 3:8849166ce7e5 98 std::string receive(int* port);
biwa1400 3:8849166ce7e5 99
biwa1400 3:8849166ce7e5 100 /*** check ***/
biwa1400 3:8849166ce7e5 101 bool checkSleepTime(uint32_t sleepTime);
biwa1400 3:8849166ce7e5 102
biwa1400 3:8849166ce7e5 103 /*** Setting ***/
biwa1400 3:8849166ce7e5 104 void reset();
biwa1400 3:8849166ce7e5 105
biwa1400 3:8849166ce7e5 106 void networkConfig(std::string network_name,
biwa1400 3:8849166ce7e5 107 std::string network_passphrase,
biwa1400 3:8849166ce7e5 108 uint8_t retransTimes,
biwa1400 3:8849166ce7e5 109 uint8_t joinDelay,
biwa1400 3:8849166ce7e5 110 bool ADR,
biwa1400 3:8849166ce7e5 111 uint8_t sf); // Include reset and setting save.
biwa1400 3:8849166ce7e5 112
biwa1400 3:8849166ce7e5 113 /*** getting ***/
biwa1400 3:8849166ce7e5 114
biwa1400 3:8849166ce7e5 115
biwa1400 3:8849166ce7e5 116 /*** Setting ***/
biwa1400 3:8849166ce7e5 117 public:
biwa1400 3:8849166ce7e5 118
biwa1400 3:8849166ce7e5 119 void setBatteryLevel(uint8_t batteryLevel);
biwa1400 3:8849166ce7e5 120
biwa1400 3:8849166ce7e5 121 void setFPending(bool isPending);
biwa1400 3:8849166ce7e5 122
biwa1400 3:8849166ce7e5 123 void setDefaultSleepTime(uint32_t inSleepTime);
biwa1400 3:8849166ce7e5 124
biwa1400 3:8849166ce7e5 125 void setSleepTime(uint32_t inSleepTime);
biwa1400 3:8849166ce7e5 126
biwa1400 3:8849166ce7e5 127 bool increaseSF();
biwa1400 3:8849166ce7e5 128
biwa1400 3:8849166ce7e5 129 bool decreaseSF();
biwa1400 3:8849166ce7e5 130
biwa1400 3:8849166ce7e5 131 void resetSF();
biwa1400 3:8849166ce7e5 132
biwa1400 3:8849166ce7e5 133 void changeSF(const uint8_t& sf);
biwa1400 3:8849166ce7e5 134
biwa1400 3:8849166ce7e5 135 void changeAdaptSF(bool adaptSF);
biwa1400 3:8849166ce7e5 136
biwa1400 3:8849166ce7e5 137 void changeModeToAUTO_OTA();
biwa1400 3:8849166ce7e5 138
biwa1400 3:8849166ce7e5 139 void changeNetworkName(const std::string& network_name);
biwa1400 3:8849166ce7e5 140
biwa1400 3:8849166ce7e5 141 void changePassword(const std::string& networkKey);
biwa1400 3:8849166ce7e5 142
biwa1400 3:8849166ce7e5 143 void changeAck(const uint8_t& retries);
biwa1400 3:8849166ce7e5 144
biwa1400 3:8849166ce7e5 145 void changeJoinDelay(uint8_t joinDelay);
biwa1400 3:8849166ce7e5 146
biwa1400 3:8849166ce7e5 147 void changePublicNetwork(bool isPublicNetwork);
biwa1400 3:8849166ce7e5 148
biwa1400 3:8849166ce7e5 149 /*** Save & get***/
biwa1400 3:8849166ce7e5 150 private:
biwa1400 3:8849166ce7e5 151 void saveSetting();
biwa1400 3:8849166ce7e5 152 /*
biwa1400 3:8849166ce7e5 153 void saveSleepTime(uint32_t sleepTime);
biwa1400 3:8849166ce7e5 154 uint32_t readSleepTime();
biwa1400 3:8849166ce7e5 155 */
biwa1400 3:8849166ce7e5 156
biwa1400 3:8849166ce7e5 157
biwa1400 3:8849166ce7e5 158 /*** Get ***/
biwa1400 3:8849166ce7e5 159 public:
biwa1400 3:8849166ce7e5 160 mDot& getHandler();
biwa1400 3:8849166ce7e5 161
biwa1400 3:8849166ce7e5 162 /*** Private Functions ***/
biwa1400 3:8849166ce7e5 163 private:
biwa1400 3:8849166ce7e5 164 bool tryConnectNet();
biwa1400 3:8849166ce7e5 165
biwa1400 3:8849166ce7e5 166 friend class MacCommandEvent;
biwa1400 3:8849166ce7e5 167 };
biwa1400 3:8849166ce7e5 168
biwa1400 3:8849166ce7e5 169
biwa1400 3:8849166ce7e5 170
biwa1400 3:8849166ce7e5 171
biwa1400 3:8849166ce7e5 172
biwa1400 3:8849166ce7e5 173 } // CLOSE NAMESPACE
biwa1400 3:8849166ce7e5 174
biwa1400 3:8849166ce7e5 175
biwa1400 3:8849166ce7e5 176
biwa1400 3:8849166ce7e5 177 #endif