MultiTech / libxDot-Custom

Fork of libxDot-dev-mbed5-deprecated by MultiTech

The Connect example can be used as a starting point for an xDot application.

Import programmDot_LoRa_Connect_Example_CUSTOM_AS923

Example configuration of frequencies and datarates for AS923 channel plan.

Change the libmDot-Custom library to libxDot-Custom after importing the above example.

Change the platform for the project to xDot in upper right corner of the compiler page.

Ensure the mbed-os version matches the with the library commit.

Currently the AT Firmware cannot be built online for the xDot.

Creating new channel plans

Copy EU868 or US915 custom channel plan as a starting point

Import librarymDot_Channel_Plans

Channel plans to enable libmDot-Custom

EU868 provides a framework for a DYNAMIC channel plan with duty-cycle limitations

US915 provides a framework for a FIXED channel plan

RADIO_POWERS are measured output in dBm for each radio tx power setting.

Additional MAC Commands can be implemented by overriding the HandleMacCommand function.

Steps

  1. Setup datarates, duty-cycle bands and channels in ChannelPlan_* constructor
  2. Modify GetJoinDatarate and CalculateJoinBackoff to change join datarates and backoff
  3. Customize HandleJoinAccept datarates
  4. Use GetRxWindow(int) to define how the device open Rx window 1 and 2
  5. GetNextChannel will pick a channel from the enabled channel at the current datarate before each TX
Committer:
jreiss
Date:
Wed Jan 18 16:14:14 2017 +0000
Revision:
26:15bf2e4ee3d0
Update to mbed-os 5.3.3; Add appkey and appeui functions; ; Add dwelltime and maxeirp getters/setters; ; KR920: max DR 7; ; AS923: max tx power 36 and maxeirp 20 defaults

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jreiss 26:15bf2e4ee3d0 1 #ifndef MTSCIRCULARBUFFER_H
jreiss 26:15bf2e4ee3d0 2 #define MTSCIRCULARBUFFER_H
jreiss 26:15bf2e4ee3d0 3
jreiss 26:15bf2e4ee3d0 4 #include "Utils.h"
jreiss 26:15bf2e4ee3d0 5
jreiss 26:15bf2e4ee3d0 6 namespace mts
jreiss 26:15bf2e4ee3d0 7 {
jreiss 26:15bf2e4ee3d0 8
jreiss 26:15bf2e4ee3d0 9 /** This class provides a circular byte buffer meant for temporary storage
jreiss 26:15bf2e4ee3d0 10 * during IO transactions. It contains many of the common methods you
jreiss 26:15bf2e4ee3d0 11 * would expect from a circular buffer like read, write, and various
jreiss 26:15bf2e4ee3d0 12 * methods for checking the size or status. It should be noted that
jreiss 26:15bf2e4ee3d0 13 * this class does not include any special code for thread safety like
jreiss 26:15bf2e4ee3d0 14 * a lock. In most cases this is not problematic, but is something
jreiss 26:15bf2e4ee3d0 15 * to be aware of.
jreiss 26:15bf2e4ee3d0 16 */
jreiss 26:15bf2e4ee3d0 17 class MTSCircularBuffer
jreiss 26:15bf2e4ee3d0 18 {
jreiss 26:15bf2e4ee3d0 19 public:
jreiss 26:15bf2e4ee3d0 20 /** Creates an MTSCircularBuffer object with the specified static size.
jreiss 26:15bf2e4ee3d0 21 *
jreiss 26:15bf2e4ee3d0 22 * @prarm bufferSize size of the buffer in bytes.
jreiss 26:15bf2e4ee3d0 23 */
jreiss 26:15bf2e4ee3d0 24 MTSCircularBuffer(int bufferSize);
jreiss 26:15bf2e4ee3d0 25
jreiss 26:15bf2e4ee3d0 26 /** Destructs an MTSCircularBuffer object and frees all related resources.
jreiss 26:15bf2e4ee3d0 27 */
jreiss 26:15bf2e4ee3d0 28 ~MTSCircularBuffer();
jreiss 26:15bf2e4ee3d0 29
jreiss 26:15bf2e4ee3d0 30 /** This method enables bulk reads from the buffer. If more data is
jreiss 26:15bf2e4ee3d0 31 * requested then available it simply returns all remaining data within the
jreiss 26:15bf2e4ee3d0 32 * buffer.
jreiss 26:15bf2e4ee3d0 33 *
jreiss 26:15bf2e4ee3d0 34 * @param data the buffer where data read will be added to.
jreiss 26:15bf2e4ee3d0 35 * @param length the amount of data in bytes to be read into the buffer.
jreiss 26:15bf2e4ee3d0 36 * @returns the total number of bytes that were read.
jreiss 26:15bf2e4ee3d0 37 */
jreiss 26:15bf2e4ee3d0 38 int read(char* data, int length);
jreiss 26:15bf2e4ee3d0 39
jreiss 26:15bf2e4ee3d0 40 /** This method reads a single byte from the buffer.
jreiss 26:15bf2e4ee3d0 41 *
jreiss 26:15bf2e4ee3d0 42 * @param data char where the read byte will be stored.
jreiss 26:15bf2e4ee3d0 43 * @returns 1 if byte is read or 0 if no bytes available.
jreiss 26:15bf2e4ee3d0 44 */
jreiss 26:15bf2e4ee3d0 45 int read(char& data);
jreiss 26:15bf2e4ee3d0 46
jreiss 26:15bf2e4ee3d0 47 /** This method enables bulk writes to the buffer. If more data
jreiss 26:15bf2e4ee3d0 48 * is requested to be written then space available the method writes
jreiss 26:15bf2e4ee3d0 49 * as much data as possible and returns the actual amount written.
jreiss 26:15bf2e4ee3d0 50 *
jreiss 26:15bf2e4ee3d0 51 * @param data the byte array to be written.
jreiss 26:15bf2e4ee3d0 52 * @param length the length of data to be written from the data paramter.
jreiss 26:15bf2e4ee3d0 53 * @returns the number of bytes written to the buffer, which is 0 if
jreiss 26:15bf2e4ee3d0 54 * the buffer is full.
jreiss 26:15bf2e4ee3d0 55 */
jreiss 26:15bf2e4ee3d0 56 int write(const char* data, int length);
jreiss 26:15bf2e4ee3d0 57
jreiss 26:15bf2e4ee3d0 58 /** This method writes a signle byte as a char to the buffer.
jreiss 26:15bf2e4ee3d0 59 *
jreiss 26:15bf2e4ee3d0 60 * @param data the byte to be written as a char.
jreiss 26:15bf2e4ee3d0 61 * @returns 1 if the byte was written or 0 if the buffer was full.
jreiss 26:15bf2e4ee3d0 62 */
jreiss 26:15bf2e4ee3d0 63 int write(char data);
jreiss 26:15bf2e4ee3d0 64
jreiss 26:15bf2e4ee3d0 65 /** This method is used to setup a callback funtion when the buffer reaches
jreiss 26:15bf2e4ee3d0 66 * a certain threshold. The threshold condition is checked after every read
jreiss 26:15bf2e4ee3d0 67 * and write call is completed. The condition is made up of both a threshold
jreiss 26:15bf2e4ee3d0 68 * value and operator. An example that would trigger a callback is if the
jreiss 26:15bf2e4ee3d0 69 * threshold was 10, the operator GREATER, and there were 12 bytes added to an
jreiss 26:15bf2e4ee3d0 70 * empty buffer.
jreiss 26:15bf2e4ee3d0 71 *
jreiss 26:15bf2e4ee3d0 72 * @param tptr a pointer to the object to be called when the condition is met.
jreiss 26:15bf2e4ee3d0 73 * @param mptr a pointer to the function within the object to be called when
jreiss 26:15bf2e4ee3d0 74 * the condition is met.
jreiss 26:15bf2e4ee3d0 75 * @param threshold the value in bytes to be used as part of the condition.
jreiss 26:15bf2e4ee3d0 76 * @param op the operator to be used in conjunction with the threshold
jreiss 26:15bf2e4ee3d0 77 * as part of the condition.
jreiss 26:15bf2e4ee3d0 78 */
jreiss 26:15bf2e4ee3d0 79 template<typename T>
jreiss 26:15bf2e4ee3d0 80 void attach(T *tptr, void( T::*mptr)(void), int threshold, RelationalOperator op) {
jreiss 26:15bf2e4ee3d0 81 _threshold = threshold;
jreiss 26:15bf2e4ee3d0 82 _op = op;
jreiss 26:15bf2e4ee3d0 83 notify.attach(tptr, mptr);
jreiss 26:15bf2e4ee3d0 84 }
jreiss 26:15bf2e4ee3d0 85
jreiss 26:15bf2e4ee3d0 86 /** This method is used to setup a callback funtion when the buffer reaches
jreiss 26:15bf2e4ee3d0 87 * a certain threshold. The threshold condition is checked after every read
jreiss 26:15bf2e4ee3d0 88 * and write call is completed. The condition is made up of both a threshold
jreiss 26:15bf2e4ee3d0 89 * value and operator. An example that would trigger a callback is if the
jreiss 26:15bf2e4ee3d0 90 * threshold was 10, the operator GREATER, and there were 12 bytes added to an
jreiss 26:15bf2e4ee3d0 91 * empty buffer.
jreiss 26:15bf2e4ee3d0 92 *
jreiss 26:15bf2e4ee3d0 93 * @param fptr a pointer to the static function to be called when the condition
jreiss 26:15bf2e4ee3d0 94 * is met.
jreiss 26:15bf2e4ee3d0 95 * @param threshold the value in bytes to be used as part of the condition.
jreiss 26:15bf2e4ee3d0 96 * @param op the operator to be used in conjunction with the threshold
jreiss 26:15bf2e4ee3d0 97 * as part of the condition.
jreiss 26:15bf2e4ee3d0 98 */
jreiss 26:15bf2e4ee3d0 99 void attach(void(*fptr)(void), int threshold, RelationalOperator op) {
jreiss 26:15bf2e4ee3d0 100 _threshold = threshold;
jreiss 26:15bf2e4ee3d0 101 _op = op;
jreiss 26:15bf2e4ee3d0 102 notify.attach(fptr);
jreiss 26:15bf2e4ee3d0 103 }
jreiss 26:15bf2e4ee3d0 104
jreiss 26:15bf2e4ee3d0 105 /** This method returns the size of the storage space currently allocated for
jreiss 26:15bf2e4ee3d0 106 * the buffer. This value is equivalent to the one passed into the constructor.
jreiss 26:15bf2e4ee3d0 107 * This value is equal or greater than the size() of the buffer.
jreiss 26:15bf2e4ee3d0 108 *
jreiss 26:15bf2e4ee3d0 109 * @returns the allocated size of the buffer in bytes.
jreiss 26:15bf2e4ee3d0 110 */
jreiss 26:15bf2e4ee3d0 111 int capacity();
jreiss 26:15bf2e4ee3d0 112
jreiss 26:15bf2e4ee3d0 113 /** This method returns the amount of space left for writing.
jreiss 26:15bf2e4ee3d0 114 *
jreiss 26:15bf2e4ee3d0 115 * @returns numbers of unused bytes in buffer.
jreiss 26:15bf2e4ee3d0 116 */
jreiss 26:15bf2e4ee3d0 117 int remaining();
jreiss 26:15bf2e4ee3d0 118
jreiss 26:15bf2e4ee3d0 119 /** This method returns the number of bytes available for reading.
jreiss 26:15bf2e4ee3d0 120 *
jreiss 26:15bf2e4ee3d0 121 * @returns number of bytes currently in buffer.
jreiss 26:15bf2e4ee3d0 122 */
jreiss 26:15bf2e4ee3d0 123 int size();
jreiss 26:15bf2e4ee3d0 124
jreiss 26:15bf2e4ee3d0 125 /** This method returns whether the buffer is full.
jreiss 26:15bf2e4ee3d0 126 *
jreiss 26:15bf2e4ee3d0 127 * @returns true if full, otherwise false.
jreiss 26:15bf2e4ee3d0 128 */
jreiss 26:15bf2e4ee3d0 129 bool isFull();
jreiss 26:15bf2e4ee3d0 130
jreiss 26:15bf2e4ee3d0 131 /** This method returns whether the buffer is empty.
jreiss 26:15bf2e4ee3d0 132 *
jreiss 26:15bf2e4ee3d0 133 * @returns true if empty, otherwise false.
jreiss 26:15bf2e4ee3d0 134 */
jreiss 26:15bf2e4ee3d0 135 bool isEmpty();
jreiss 26:15bf2e4ee3d0 136
jreiss 26:15bf2e4ee3d0 137 /** This method clears the buffer. This is done through
jreiss 26:15bf2e4ee3d0 138 * setting the internal read and write indexes to the same
jreiss 26:15bf2e4ee3d0 139 * value and is therefore not an expensive operation.
jreiss 26:15bf2e4ee3d0 140 */
jreiss 26:15bf2e4ee3d0 141 void clear();
jreiss 26:15bf2e4ee3d0 142
jreiss 26:15bf2e4ee3d0 143
jreiss 26:15bf2e4ee3d0 144 private:
jreiss 26:15bf2e4ee3d0 145 int bufferSize; // total size of the buffer
jreiss 26:15bf2e4ee3d0 146 char* buffer; // internal byte buffer as a character buffer
jreiss 26:15bf2e4ee3d0 147 int readIndex; // read index for circular buffer
jreiss 26:15bf2e4ee3d0 148 int writeIndex; // write index for circular buffer
jreiss 26:15bf2e4ee3d0 149 int bytes; // available data
jreiss 26:15bf2e4ee3d0 150 FunctionPointer notify; // function pointer used for the internal callback notification
jreiss 26:15bf2e4ee3d0 151 int _threshold; // threshold for the notification
jreiss 26:15bf2e4ee3d0 152 RelationalOperator _op; // operator that determines the direction of the threshold
jreiss 26:15bf2e4ee3d0 153 void checkThreshold(); // private function that checks thresholds and processes notifications
jreiss 26:15bf2e4ee3d0 154 };
jreiss 26:15bf2e4ee3d0 155
jreiss 26:15bf2e4ee3d0 156 }
jreiss 26:15bf2e4ee3d0 157
jreiss 26:15bf2e4ee3d0 158 #endif /* MTSCIRCULARBUFFER_H */
jreiss 26:15bf2e4ee3d0 159