Utility library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas thermostat_fan_demo--fan mtsas ... more
NOTE: MTS-Utils has moved to GitHub. This version will not be updated. For updates, go to the GitHub version.
Revision 15:ae12624eb600, committed 2017-03-21
- Comitter:
- Mike Fiore
- Date:
- Tue Mar 21 15:26:50 2017 -0500
- Parent:
- 14:1d88cf5266c8
- Commit message:
- update from git revision 37b619a6e4e6e3b49b64c402429cdd8710d960a6
Changed in this revision
--- a/MTSLog.h Wed Sep 09 11:59:59 2015 -0500
+++ b/MTSLog.h Tue Mar 21 15:26:50 2017 -0500
@@ -1,19 +1,35 @@
#ifndef MTSLOG_H
#define MTSLOG_H
+#include <string>
+
+inline const char* className(const std::string& prettyFunction)
+{
+ size_t colons = prettyFunction.find_last_of("::");
+ if (colons == std::string::npos)
+ return "";
+ size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
+ size_t end = colons - begin;
+
+ return prettyFunction.substr(begin,end).c_str();
+}
+
+#define __CLASSNAME__ className(__PRETTY_FUNCTION__)
+
+
#ifdef MTS_DEBUG
#define logFatal(format, ...) \
- mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
+ mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
#define logError(format, ...) \
- mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__)
+ mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__)
#define logWarning(format, ...) \
- mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__)
+ mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__)
#define logInfo(format, ...) \
- mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::INFO_LABEL, ##__VA_ARGS__)
+ mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::INFO_LABEL, ##__VA_ARGS__)
#define logDebug(format, ...) \
- mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
+ mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
#define logTrace(format, ...) \
- mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__)
+ mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__)
#else
#define logFatal(format, ...) \
mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "[%s] " format "\r\n", mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
--- a/MTSText.cpp Wed Sep 09 11:59:59 2015 -0500
+++ b/MTSText.cpp Tue Mar 21 15:26:50 2017 -0500
@@ -69,24 +69,34 @@
return std::string(buff);
}
-std::string Text::bin2hexString(const std::vector<uint8_t>& data, const char* delim, bool leadingZeros) {
- uint8_t data_arr[data.size()];
+std::string Text::bin2hexString(const std::vector<uint8_t>& data, const char* delim, bool leadingZeros, bool bytePadding) {
+ std::string ret;
+ uint8_t *data_arr = new uint8_t[data.size()];
- for (int i = 0; i < data.size(); i++)
+ for (size_t i = 0; i < data.size(); i++)
data_arr[i] = data[i];
- return bin2hexString(data_arr, data.size(), delim, leadingZeros);
+ ret = bin2hexString(data_arr, data.size(), delim, leadingZeros, bytePadding);
+
+ delete[] data_arr;
+
+ return ret;
}
-std::string Text::bin2hexString(const uint8_t* data, const uint32_t len, const char* delim, bool leadingZeros) {
+std::string Text::bin2hexString(const uint8_t* data, const uint32_t len, const char* delim, bool leadingZeros, bool bytePadding) {
std::string str;
- char buf[32];
char lead[] = "0x";
+ char buf[5];
for (uint32_t i = 0; i < len; i++) {
if (leadingZeros)
str.append(lead);
- snprintf(buf, sizeof(buf), "%02x", data[i]);
+
+ if (bytePadding)
+ snprintf(buf, sizeof(buf), "%02x", data[i]);
+ else
+ snprintf(buf, sizeof(buf), "%x", data[i]);
+
str.append(buf, strlen(buf));
if (i < len - 1)
str.append(delim);
--- a/MTSText.h Wed Sep 09 11:59:59 2015 -0500
+++ b/MTSText.h Tue Mar 21 15:26:50 2017 -0500
@@ -55,9 +55,9 @@
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 std::vector<uint8_t>& data, const char* delim = "", bool leadingZeros = false, bool bytePadding = true);
- static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false);
+ static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false, bool bytePadding = true);
static std::string bin2base64(const std::vector<uint8_t>& data);
--- a/Utils.h Wed Sep 09 11:59:59 2015 -0500
+++ b/Utils.h Tue Mar 21 15:26:50 2017 -0500
@@ -20,7 +20,7 @@
* @param relationalOperator a RelationalOperator enumeration.
* @returns the enumeration name as a string.
*/
-static std::string getRelationalOperatorNames(RelationalOperator relationalOperator)
+static inline std::string getRelationalOperatorNames(RelationalOperator relationalOperator)
{
switch(relationalOperator) {
case GREATER: