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