required mdot library updated

Dependents:   mDot_SPI_slave

Fork of libmDot-mbed5 by MultiTech

Files at this revision

API Documentation at this revision

Comitter:
Mike Fiore
Date:
Mon Aug 17 16:18:29 2015 -0500
Parent:
6:390fc83d588d
Child:
8:b43d82da7009
Commit message:
update to version 0.0.7

Changed in this revision

MTSLog.h Show annotated file Show diff for this revision Revisions of this file
MTSText.h Show annotated file Show diff for this revision Revisions of this file
libmDot.ar Show annotated file Show diff for this revision Revisions of this file
mDot.h Show annotated file Show diff for this revision Revisions of this file
--- a/MTSLog.h	Thu Jul 16 16:41:08 2015 -0500
+++ b/MTSLog.h	Mon Aug 17 16:18:29 2015 -0500
@@ -10,30 +10,30 @@
 
 #ifdef MTS_DEBUG
 #define logFatal(format, ...) \
-    MTSLog::printMessage(MTSLog::FATAL_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, MTSLog::FATAL_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
 #define logError(format, ...) \
-    MTSLog::printMessage(MTSLog::ERROR_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, MTSLog::ERROR_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__)
 #define logWarning(format, ...) \
-    MTSLog::printMessage(MTSLog::WARNING_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, MTSLog::WARNING_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__)
 #define logInfo(format, ...) \
-    MTSLog::printMessage(MTSLog::INFO_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, MTSLog::INFO_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::INFO_LABEL, ##__VA_ARGS__)
 #define logDebug(format, ...) \
-    MTSLog::printMessage(MTSLog::DEBUG_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
 #define logTrace(format, ...) \
-    MTSLog::printMessage(MTSLog::TRACE_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, MTSLog::TRACE_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__)
 #else
 #define logFatal(format, ...) \
-    MTSLog::printMessage(MTSLog::FATAL_LEVEL, "[%s] " format "\r\n", MTSLog::FATAL_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "[%s] " format "\r\n", mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
 #define logError(format, ...) \
-    MTSLog::printMessage(MTSLog::ERROR_LEVEL, "[%s] " format "\r\n", MTSLog::ERROR_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "[%s] " format "\r\n", mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__)
 #define logWarning(format, ...) \
-    MTSLog::printMessage(MTSLog::WARNING_LEVEL, "[%s] " format "\r\n", MTSLog::WARNING_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "[%s] " format "\r\n", mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__)
 #define logInfo(format, ...) \
-    MTSLog::printMessage(MTSLog::INFO_LEVEL, "[%s] " format "\r\n", MTSLog::INFO_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "[%s] " format "\r\n", mts::MTSLog::INFO_LABEL, ##__VA_ARGS__)
 #define logDebug(format, ...) \
-    MTSLog::printMessage(MTSLog::DEBUG_LEVEL, "[%s] " format "\r\n", MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "[%s] " format "\r\n", mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
 #define logTrace(format, ...) \
-    MTSLog::printMessage(MTSLog::TRACE_LEVEL, "[%s] " format "\r\n", MTSLog::TRACE_LABEL, ##__VA_ARGS__)
+    mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "[%s] " format "\r\n", mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__)
 #endif
 
 namespace mts {
--- a/MTSText.h	Thu Jul 16 16:41:08 2015 -0500
+++ b/MTSText.h	Mon Aug 17 16:18:29 2015 -0500
@@ -5,80 +5,86 @@
  * See LICENSE file for license information
  ***********************************************/
 
-#ifndef MTSTEXT_H
-#define MTSTEXT_H
-
-#include <string>
-#include <vector>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-namespace mts
-{
-
-/** This class contains a number of static methods for manipulating strings and other
-* text data.
-*/
-class Text
-{
-public:
-    /** This static method can be used to pull out a string at the next line break. A
-    * break can either be a newline '\n', carriage return '\r' or both.
-    *
-    * @param source the source string to look for the line break on.
-    * @param start the start postion within the string to begin looking for the line
-    * break.
-    * @param cursor this value will be updated with the index for the next available character
-    * after the line break. If a line break is not found returns -1.
-    * @returns the string beginning with the start index up to including the line breaks.
-    */
-    static std::string getLine(const std::string& source, const size_t& start, size_t& cursor);
-
-    /** This is a static method for splitting strings using a delimeter value.
-    *
-    * @param str the string to try and split.
-    * @param delimiter the delimeter value to split on as a character.
-    * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible.
-    * The default is 0.
-    * @returns an ordered vector of strings conatining the splits of the original string.
-    */
-    static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0);
-
-    /** This is a static method for splitting strings using a delimeter value.
-    *
-    * @param str the string to try and split.
-    * @param delimiter the delimeter value to split on as a string.
-    * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible.
-    * The default is 0.
-    * @returns an ordered vector of strings conatining the splits of the original string.
-    */
-    static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0);
-    
-    static std::string readString(char* index, int length);
-
-    static std::string toUpper(const std::string str);
-
-    std::string float2String(double val, int precision);
-
-    static std::string bin2hexString(const std::vector<uint8_t>& data, const char* delim = "", bool leadingZeros = false);
+#ifndef MTSTEXT_H
+#define MTSTEXT_H
+
+#include <string>
+#include <vector>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+namespace mts
+{
+
+/** This class contains a number of static methods for manipulating strings and other
+* text data.
+*/
+class Text
+{
+public:
+    /** This static method can be used to pull out a string at the next line break. A
+    * break can either be a newline '\n', carriage return '\r' or both.
+    *
+    * @param source the source string to look for the line break on.
+    * @param start the start postion within the string to begin looking for the line
+    * break.
+    * @param cursor this value will be updated with the index for the next available character
+    * after the line break. If a line break is not found returns -1.
+    * @returns the string beginning with the start index up to including the line breaks.
+    */
+    static std::string getLine(const std::string& source, const size_t& start, size_t& cursor);
 
-    static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false);
+    /** This is a static method for splitting strings using a delimeter value.
+    *
+    * @param str the string to try and split.
+    * @param delimiter the delimeter value to split on as a character.
+    * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible.
+    * The default is 0.
+    * @returns an ordered vector of strings conatining the splits of the original string.
+    */
+    static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0);
+
+    /** This is a static method for splitting strings using a delimeter value.
+    *
+    * @param str the string to try and split.
+    * @param delimiter the delimeter value to split on as a string.
+    * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible.
+    * The default is 0.
+    * @returns an ordered vector of strings conatining the splits of the original string.
+    */
+    static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0);
+    
+    static std::string readString(char* index, int length);
+
+    static std::string toUpper(const std::string str);
+
+    static std::string float2String(double val, int precision);
+
+    static std::string bin2hexString(const std::vector<uint8_t>& data, const char* delim = "", bool leadingZeros = false);
+
+    static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false);
+
+    static std::string bin2base64(const std::vector<uint8_t>& data);
+
+    static std::string bin2base64(const uint8_t* data, size_t size);
+
+    static bool base642bin(const std::string in, std::vector<uint8_t>& out);
 
     static void ltrim(std::string& str, const char* args);
 
     static void rtrim(std::string& str, const char* args);
 
     static void trim(std::string& str, const char* args);
-
-private:
-    // Safety for class with only static methods
-    Text();
-    Text(const Text& other);
-    Text& operator=(const Text& other);
-};
-
-}
-
-#endif
+
+private:
+    // Safety for class with only static methods
+    Text();
+    Text(const Text& other);
+    Text& operator=(const Text& other);
+};
+
+}
+
+#endif
Binary file libmDot.ar has changed
--- a/mDot.h	Thu Jul 16 16:41:08 2015 -0500
+++ b/mDot.h	Mon Aug 17 16:18:29 2015 -0500
@@ -1,4 +1,10 @@
-// TODO: add license header
+/************************************************
+ * MultiTech MTDOT Library
+ * Copyright (c) 2015 MultiTech Systems
+ *
+ * See LICENSE file for license information
+ ***********************************************/
+
 
 #ifndef MDOT_H
 #define MDOT_H
@@ -14,7 +20,6 @@
 class LoRaMac;
 class MdotRadio;
 
-
 class mDot {
 
     private:
@@ -51,6 +56,11 @@
         mDot(const mDot&);
         mDot& operator=(const mDot&);
 
+        uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
+        void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
+
+        void wakeup();
+
         static mDot* _instance;
 
         LoRaMac* _mac;
@@ -67,6 +77,9 @@
         PinName _activity_led_pin;
         bool _activity_led_external;
         uint16_t _linkFailCount;
+        uint8_t _class;
+        InterruptIn* _wakeup;
+        PinName _wakeup_pin;
 
         typedef enum {
             OFF, ON, BLINK,
@@ -75,6 +88,16 @@
     public:
 
         typedef enum {
+            FM_APPEND = (1 << 0),
+            FM_TRUNC = (1 << 1),
+            FM_CREAT = (1 << 2),
+            FM_RDONLY = (1 << 3),
+            FM_WRONLY = (1 << 4),
+            FM_RDWR = (FM_RDONLY | FM_WRONLY),
+            FM_DIRECT = (1 << 5)
+        } FileMode;
+
+        typedef enum {
             MDOT_OK = 0,
             MDOT_INVALID_PARAM = -1,
             MDOT_TX_ERROR = -2,
@@ -115,6 +138,16 @@
             LSB, MSB
         };
 
+        enum wakeup_mode {
+            RTC_ALARM, INTERRUPT
+        };
+
+        typedef struct {
+                int16_t fd;
+                char name[30];
+                uint32_t size;
+        } mdot_file;
+
         typedef struct {
                 uint32_t Up;
                 uint32_t Down;
@@ -589,7 +622,6 @@
          */
         int32_t recv(std::vector<uint8_t>& data);
 
-        void openRxWindow(uint32_t timeout);
 
         /** Ping
          * status will be MDOT_OK if ping succeeded
@@ -607,12 +639,34 @@
          */
         std::string getLastError();
 
+        /** Go to sleep
+         * @param interval the number of seconds to sleep before waking up if wakeup_mode == RTC_ALARM, else ignored
+         * @param wakeup_mode RTC_ALARM, INTERRUPT
+         *      if RTC_ALARM the real time clock is configured to wake the device up after the specified interval
+         *      if INTERRUPT the device will wake up on the rising edge of the interrupt pin
+         * @param deepsleep if true go into deep sleep mode (lowest power, all memory and registers are lost, peripherals turned off)
+         *                  else go into sleep mode (low power, memory and registers are maintained, peripherals stay on)
+         *
+         * ** CURRENTLY ONLY DEEPSLEEP MODE IS AVAILABLE **
+         *
+         * in sleep mode, the device can be woken up on any of the XBEE pins or by the RTC alarm
+         * in deepsleep mode, the device can only be woken up using the WKUP pin (PA0, XBEE_DIO7) or by the RTC alarm
+         */
+        void sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true);
+
+        /** Set wake pin
+         * @param pin the pin to use to wake the device from sleep mode
+         */
+        void setWakePin(const PinName& pin);
+
+        /** Get wake pin
+         * @returns the pin to use to wake the device from sleep mode
+         */
+        PinName getWakePin();
+
         /******************************************
          * THESE FEATURES ARE NOT FULLY IMPLEMENTED
          *****************************************/
-        void sleep();
-        void wakeup();
-
         // get/set adaptive data rate
         // configure data rates and power levels based on signal to noise information from gateway
         // true == adaptive data rate is on
@@ -624,7 +678,7 @@
          * The following functions are only used by the AT command application and
          * should not be used by standard applications consuming the mDot library
          ************************************************************************/
-        
+
         // set/get configured baud rate for command port
         // only for use in conjunction with AT interface
         // set function returns MDOT_OK if success
@@ -683,24 +737,115 @@
         // get/set serial wake interval
         // valid values are 2 s - INT_MAX (2147483647) s
         // set function returns MDOT_OK if success
-        int32_t setSerialWakeInterval(const uint32_t& interval);
-        uint32_t getSerialWakeInterval();
+        int32_t setWakeInterval(const uint32_t& interval);
+        uint32_t getWakeInterval();
 
         // get/set serial wake delay
         // valid values are 2 ms - INT_MAX (2147483647) ms
         // set function returns MDOT_OK if success
-        int32_t setSerialWakeDelay(const uint32_t& delay);
-        uint32_t getSerialWakeDelay();
+        int32_t setWakeDelay(const uint32_t& delay);
+        uint32_t getWakeDelay();
 
         // get/set serial receive timeout
         // valid values are 0 ms - 65000 ms
         // set function returns MDOT_OK if success
-        int32_t setSerialReceiveTimeout(const uint16_t& timeout);
-        uint16_t getSerialReceiveTimeout();
+        int32_t setWakeTimeout(const uint16_t& timeout);
+        uint16_t getWakeTimeout();
+
+        // get/set serial wake mode
+        // valid values are INTERRUPT or RTC_ALARM
+        // set function returns MDOT_OK if success
+        int32_t setWakeMode(const uint8_t& delay);
+        uint8_t getWakeMode();
+
+        // Save user file data to flash
+        // file - name of file max 30 chars
+        // data - data of file
+        // size - size of file
+        bool saveUserFile(const char* file, void* data, uint32_t size);
+
+        // Append user file data to flash
+        // file - name of file max 30 chars
+        // data - data of file
+        // size - size of file
+        bool appendUserFile(const char* file, void* data, uint32_t size);
+
+        // Read user file data from flash
+        // file - name of file max 30 chars
+        // data - data of file
+        // size - size of file
+        bool readUserFile(const char* file, void* data, uint32_t size);
+
+        // Move a user file in flash
+        // file     - name of file
+        // new_name - new name of file
+        bool moveUserFile(const char* file, const char* new_name);
+
+        // Delete user file data from flash
+        // file - name of file max 30 chars
+        bool deleteUserFile(const char* file);
+
+        // Open user file in flash, max of 4 files open concurrently
+        // file - name of file max 30 chars
+        // mode - combination of FM_APPEND | FM_TRUNC | FM_CREAT |
+        //                       FM_RDONLY | FM_WRONLY | FM_RDWR | FM_DIRECT
+        // returns - mdot_file struct, fd field will be a negative value if file could not be opened
+        mDot::mdot_file openUserFile(const char* file, int mode);
+
+        // Seek an open file
+        // file - mdot file struct
+        // offset - offset in bytes
+        // whence - where offset is based SEEK_SET, SEEK_CUR, SEEK_END
+        bool seekUserFile(mDot::mdot_file& file, size_t offset, int whence);
+
+        // Read bytes from open file
+        // file - mdot file struct
+        // data - mem location to store data
+        // length - number of bytes to read
+        // returns - number of bytes written
+        int readUserFile(mDot::mdot_file& file, void* data, size_t length);
+
+        // Write bytes to open file
+        // file - mdot file struct
+        // data - data to write
+        // length - number of bytes to write
+        // returns - number of bytes written
+        int writeUserFile(mDot::mdot_file& file, void* data, size_t length);
+
+        // Close open file
+        // file - mdot file struct
+        bool closeUserFile(mDot::mdot_file& file);
+
+        // List user files stored in flash
+        std::vector<mDot::mdot_file> listUserFiles();
+
+        // Move file into the firmware upgrade path to be flashed on next boot
+        // file - name of file
+        bool moveUserFileToFirmwareUpgrade(const char* file);
+
+        // get current statistics
+        // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks
+        mdot_stats getStats();
+
+        // reset statistics
+        // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks
+        void resetStats();
+
+        // Convert pin number 2-8 to pin name DIO2-DI8
+        static PinName pinNum2Name(uint8_t num);
+
+        // Convert pin name DIO2-DI8 to pin number 2-8
+        static uint8_t pinName2Num(PinName name);
+
+        // Convert pin name DIO2-DI8 to string
+        static std::string pinName2Str(PinName name);
+
 
         uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
 
         // MTS_RADIO_DEBUG_COMMANDS
+
+        void openRxWindow(uint32_t timeout, uint8_t bandwidth = 0);
         void sendContinuous();
         int32_t setDeviceId(const std::vector<uint8_t>& id);
         int32_t setFrequencyBand(const uint8_t& band);
@@ -710,9 +855,21 @@
         std::map<uint8_t, uint8_t> dumpRegisters();
         void eraseFlash();
 
-        mdot_stats getStats();
-        void resetStats();
+
+        // deprecated - use setWakeInterval
+        int32_t setSerialWakeInterval(const uint32_t& interval);
+        // deprecated - use getWakeInterval
+        uint32_t getSerialWakeInterval();
 
+        // deprecated - use setWakeDelay
+        int32_t setSerialWakeDelay(const uint32_t& delay);
+        // deprecated - use setWakeDelay
+        uint32_t getSerialWakeDelay();
+
+        // deprecated - use setWakeTimeout
+        int32_t setSerialReceiveTimeout(const uint16_t& timeout);
+        // deprecated - use getWakeTimeout
+        uint16_t getSerialReceiveTimeout();
 
     private:
         mdot_stats _stats;