summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-07 15:50:56 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-07 15:50:56 -0600
commitc4811dd1b73b37b0916803097237acd31f1df98b (patch)
treeb0d73a975fc7e7de8444775440e0b729fa61d0fa
parent68c0c5ed8ad7c733743de1afc5deb9de862d60f3 (diff)
downloadmts-io-sysfs-c4811dd1b73b37b0916803097237acd31f1df98b.tar.gz
mts-io-sysfs-c4811dd1b73b37b0916803097237acd31f1df98b.tar.bz2
mts-io-sysfs-c4811dd1b73b37b0916803097237acd31f1df98b.zip
Refactored accessory cards classes with inheritence, fixed Makefile clean, moved some helper functions to header utility
-rw-r--r--Makefile7
-rw-r--r--build/AccessoryCards/AccessoryCardLora.d86
-rw-r--r--build/AccessoryCards/AccessoryCardLora15.d89
-rw-r--r--build/Device/Device.d92
-rw-r--r--build/MtsIoSysfs.d5
-rw-r--r--include/Device/Device.h69
-rw-r--r--include/General.h2
-rw-r--r--include/Utility/Utility.h56
-rw-r--r--src/AccessoryCards/AccessoryCardLora.cpp22
-rw-r--r--src/AccessoryCards/AcessoryCard.cpp21
-rw-r--r--src/AccessoryCards/Gpiob.cpp25
-rw-r--r--src/AccessoryCards/LoraCard.cpp23
-rw-r--r--src/AccessoryCards/LoraCard15.cpp (renamed from src/AccessoryCards/AccessoryCardLora15.cpp)71
-rw-r--r--src/AccessoryCards/LoraCard21.cpp24
-rw-r--r--src/AccessoryCards/LoraCard21Ext.cpp24
-rw-r--r--src/AccessoryCards/Mfser.cpp29
-rw-r--r--src/Device/Device.cpp94
-rw-r--r--src/MtsIoSysfs.cpp8
-rw-r--r--src/Version.cpp2
19 files changed, 327 insertions, 422 deletions
diff --git a/Makefile b/Makefile
index f6df6d7..2fc0729 100644
--- a/Makefile
+++ b/Makefile
@@ -43,9 +43,8 @@ SOURCES = $(wildcard $(SOURCEDIR)/**/*.cpp)
SOURCES += $(SOURCEDIR)/Version.cpp
OBJS1 = $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
OBJS = $(patsubst $(SOURCEDIR)/%.c,$(BUILDDIR)/%.o,$(OBJS1))
-CPP_DEPPS1 = $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.d,$(SOURCES))
-CPP_DEPPS = $(patsubst $(SOURCEDIR)/%.c,$(BUILDDIR)/%.d,$(CPP_DEPPS1))
-CPP_DEPPS = $(BUILDDIR)/MtsIo.d
+CPP_DEPPS = $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/**/%.d,$(SOURCES))
+CPP_DEPPS += $(BUILDDIR)/MtsIoSysfs.o $(BUILDDIR)/**/*.o $(BUILDDIR)/**/*.d
JS_OBJS = $(BUILDDIR)/Version.o
OUT_DIRS=build/AccessoryCards build/Device
MKDIR_P = mkdir -p
@@ -115,7 +114,7 @@ strip:
$(STRIP) $(BUILDDIR)/mts-io-sysfs
clean:
- -$(RM) $(OBJS) $(CPP_DEPPS) $(BUILDDIR)/mts-io-sysfs $(BUILDDIR)/MtsIoSysfs.o $(BUILDDIR)/AccessoryCards/*.o $(BUILDDIR)/Device/*.o
+ -$(RM) $(OBJS) $(CPP_DEPPS) $(BUILDDIR)/mts-io-sysfs
-@echo ' '
.PHONY: all clean dependents
diff --git a/build/AccessoryCards/AccessoryCardLora.d b/build/AccessoryCards/AccessoryCardLora.d
deleted file mode 100644
index c0f1dfe..0000000
--- a/build/AccessoryCards/AccessoryCardLora.d
+++ /dev/null
@@ -1,86 +0,0 @@
-build/AccessoryCards/AccessoryCardLora.d: \
- src/AccessoryCards/AccessoryCardLora.cpp \
- include/AccessoryCards/AccessoryCardLora.h include/General.h \
- include/rapidjson/document.h include/rapidjson/reader.h \
- include/rapidjson/allocators.h include/rapidjson/rapidjson.h \
- include/rapidjson/stream.h include/rapidjson/encodings.h \
- include/rapidjson/encodedstream.h include/rapidjson/memorystream.h \
- include/rapidjson/internal/meta.h \
- include/rapidjson/internal/../rapidjson.h \
- include/rapidjson/internal/stack.h \
- include/rapidjson/internal/../allocators.h \
- include/rapidjson/internal/swap.h include/rapidjson/internal/strtod.h \
- include/rapidjson/internal/ieee754.h \
- include/rapidjson/internal/biginteger.h \
- include/rapidjson/internal/diyfp.h include/rapidjson/internal/pow10.h \
- include/rapidjson/error/error.h include/rapidjson/error/../rapidjson.h \
- include/rapidjson/internal/strfunc.h \
- include/rapidjson/internal/../stream.h \
- include/rapidjson/internal/../rapidjson.h include/rapidjson/writer.h \
- include/rapidjson/internal/dtoa.h include/rapidjson/internal/itoa.h \
- include/rapidjson/internal/itoa.h include/rapidjson/stringbuffer.h \
- include/rapidjson/stringbuffer.h include/rapidjson/istreamwrapper.h
-
-include/AccessoryCards/AccessoryCardLora.h:
-
-include/General.h:
-
-include/rapidjson/document.h:
-
-include/rapidjson/reader.h:
-
-include/rapidjson/allocators.h:
-
-include/rapidjson/rapidjson.h:
-
-include/rapidjson/stream.h:
-
-include/rapidjson/encodings.h:
-
-include/rapidjson/encodedstream.h:
-
-include/rapidjson/memorystream.h:
-
-include/rapidjson/internal/meta.h:
-
-include/rapidjson/internal/../rapidjson.h:
-
-include/rapidjson/internal/stack.h:
-
-include/rapidjson/internal/../allocators.h:
-
-include/rapidjson/internal/swap.h:
-
-include/rapidjson/internal/strtod.h:
-
-include/rapidjson/internal/ieee754.h:
-
-include/rapidjson/internal/biginteger.h:
-
-include/rapidjson/internal/diyfp.h:
-
-include/rapidjson/internal/pow10.h:
-
-include/rapidjson/error/error.h:
-
-include/rapidjson/error/../rapidjson.h:
-
-include/rapidjson/internal/strfunc.h:
-
-include/rapidjson/internal/../stream.h:
-
-include/rapidjson/internal/../rapidjson.h:
-
-include/rapidjson/writer.h:
-
-include/rapidjson/internal/dtoa.h:
-
-include/rapidjson/internal/itoa.h:
-
-include/rapidjson/internal/itoa.h:
-
-include/rapidjson/stringbuffer.h:
-
-include/rapidjson/stringbuffer.h:
-
-include/rapidjson/istreamwrapper.h:
diff --git a/build/AccessoryCards/AccessoryCardLora15.d b/build/AccessoryCards/AccessoryCardLora15.d
deleted file mode 100644
index 26ee09c..0000000
--- a/build/AccessoryCards/AccessoryCardLora15.d
+++ /dev/null
@@ -1,89 +0,0 @@
-build/AccessoryCards/AccessoryCardLora15.d: \
- src/AccessoryCards/AccessoryCardLora15.cpp \
- include/AccessoryCards/AccessoryCardLora15.h include/General.h \
- include/rapidjson/document.h include/rapidjson/reader.h \
- include/rapidjson/allocators.h include/rapidjson/rapidjson.h \
- include/rapidjson/stream.h include/rapidjson/encodings.h \
- include/rapidjson/encodedstream.h include/rapidjson/memorystream.h \
- include/rapidjson/internal/meta.h \
- include/rapidjson/internal/../rapidjson.h \
- include/rapidjson/internal/stack.h \
- include/rapidjson/internal/../allocators.h \
- include/rapidjson/internal/swap.h include/rapidjson/internal/strtod.h \
- include/rapidjson/internal/ieee754.h \
- include/rapidjson/internal/biginteger.h \
- include/rapidjson/internal/diyfp.h include/rapidjson/internal/pow10.h \
- include/rapidjson/error/error.h include/rapidjson/error/../rapidjson.h \
- include/rapidjson/internal/strfunc.h \
- include/rapidjson/internal/../stream.h \
- include/rapidjson/internal/../rapidjson.h include/rapidjson/writer.h \
- include/rapidjson/internal/dtoa.h include/rapidjson/internal/itoa.h \
- include/rapidjson/internal/itoa.h include/rapidjson/stringbuffer.h \
- include/rapidjson/stringbuffer.h include/rapidjson/istreamwrapper.h \
- include/AccessoryCards/AccessoryCardLora.h
-
-include/AccessoryCards/AccessoryCardLora15.h:
-
-include/General.h:
-
-include/rapidjson/document.h:
-
-include/rapidjson/reader.h:
-
-include/rapidjson/allocators.h:
-
-include/rapidjson/rapidjson.h:
-
-include/rapidjson/stream.h:
-
-include/rapidjson/encodings.h:
-
-include/rapidjson/encodedstream.h:
-
-include/rapidjson/memorystream.h:
-
-include/rapidjson/internal/meta.h:
-
-include/rapidjson/internal/../rapidjson.h:
-
-include/rapidjson/internal/stack.h:
-
-include/rapidjson/internal/../allocators.h:
-
-include/rapidjson/internal/swap.h:
-
-include/rapidjson/internal/strtod.h:
-
-include/rapidjson/internal/ieee754.h:
-
-include/rapidjson/internal/biginteger.h:
-
-include/rapidjson/internal/diyfp.h:
-
-include/rapidjson/internal/pow10.h:
-
-include/rapidjson/error/error.h:
-
-include/rapidjson/error/../rapidjson.h:
-
-include/rapidjson/internal/strfunc.h:
-
-include/rapidjson/internal/../stream.h:
-
-include/rapidjson/internal/../rapidjson.h:
-
-include/rapidjson/writer.h:
-
-include/rapidjson/internal/dtoa.h:
-
-include/rapidjson/internal/itoa.h:
-
-include/rapidjson/internal/itoa.h:
-
-include/rapidjson/stringbuffer.h:
-
-include/rapidjson/stringbuffer.h:
-
-include/rapidjson/istreamwrapper.h:
-
-include/AccessoryCards/AccessoryCardLora.h:
diff --git a/build/Device/Device.d b/build/Device/Device.d
deleted file mode 100644
index 16838e4..0000000
--- a/build/Device/Device.d
+++ /dev/null
@@ -1,92 +0,0 @@
-build/Device/Device.d: src/Device/Device.cpp include/Device/Device.h \
- include/General.h include/rapidjson/document.h \
- include/rapidjson/reader.h include/rapidjson/allocators.h \
- include/rapidjson/rapidjson.h include/rapidjson/stream.h \
- include/rapidjson/encodings.h include/rapidjson/encodedstream.h \
- include/rapidjson/memorystream.h include/rapidjson/internal/meta.h \
- include/rapidjson/internal/../rapidjson.h \
- include/rapidjson/internal/stack.h \
- include/rapidjson/internal/../allocators.h \
- include/rapidjson/internal/swap.h include/rapidjson/internal/strtod.h \
- include/rapidjson/internal/ieee754.h \
- include/rapidjson/internal/biginteger.h \
- include/rapidjson/internal/diyfp.h include/rapidjson/internal/pow10.h \
- include/rapidjson/error/error.h include/rapidjson/error/../rapidjson.h \
- include/rapidjson/internal/strfunc.h \
- include/rapidjson/internal/../stream.h \
- include/rapidjson/internal/../rapidjson.h include/rapidjson/writer.h \
- include/rapidjson/internal/dtoa.h include/rapidjson/internal/itoa.h \
- include/rapidjson/internal/itoa.h include/rapidjson/stringbuffer.h \
- include/rapidjson/stringbuffer.h include/rapidjson/istreamwrapper.h \
- include/Version.h include/AccessoryCards/AccessoryCardLora15.h \
- include/AccessoryCards/AccessoryCardLora.h
-
-include/Device/Device.h:
-
-include/General.h:
-
-include/rapidjson/document.h:
-
-include/rapidjson/reader.h:
-
-include/rapidjson/allocators.h:
-
-include/rapidjson/rapidjson.h:
-
-include/rapidjson/stream.h:
-
-include/rapidjson/encodings.h:
-
-include/rapidjson/encodedstream.h:
-
-include/rapidjson/memorystream.h:
-
-include/rapidjson/internal/meta.h:
-
-include/rapidjson/internal/../rapidjson.h:
-
-include/rapidjson/internal/stack.h:
-
-include/rapidjson/internal/../allocators.h:
-
-include/rapidjson/internal/swap.h:
-
-include/rapidjson/internal/strtod.h:
-
-include/rapidjson/internal/ieee754.h:
-
-include/rapidjson/internal/biginteger.h:
-
-include/rapidjson/internal/diyfp.h:
-
-include/rapidjson/internal/pow10.h:
-
-include/rapidjson/error/error.h:
-
-include/rapidjson/error/../rapidjson.h:
-
-include/rapidjson/internal/strfunc.h:
-
-include/rapidjson/internal/../stream.h:
-
-include/rapidjson/internal/../rapidjson.h:
-
-include/rapidjson/writer.h:
-
-include/rapidjson/internal/dtoa.h:
-
-include/rapidjson/internal/itoa.h:
-
-include/rapidjson/internal/itoa.h:
-
-include/rapidjson/stringbuffer.h:
-
-include/rapidjson/stringbuffer.h:
-
-include/rapidjson/istreamwrapper.h:
-
-include/Version.h:
-
-include/AccessoryCards/AccessoryCardLora15.h:
-
-include/AccessoryCards/AccessoryCardLora.h:
diff --git a/build/MtsIoSysfs.d b/build/MtsIoSysfs.d
index a540f53..48ed255 100644
--- a/build/MtsIoSysfs.d
+++ b/build/MtsIoSysfs.d
@@ -18,7 +18,8 @@ build/MtsIoSysfs.d: src/MtsIoSysfs.cpp include/Device/Device.h \
include/rapidjson/internal/dtoa.h include/rapidjson/internal/itoa.h \
include/rapidjson/internal/itoa.h include/rapidjson/stringbuffer.h \
include/rapidjson/stringbuffer.h include/rapidjson/istreamwrapper.h \
- include/Version.h include/AccessoryCards/AccessoryCardLora15.h \
+ include/Utility/Utility.h include/Version.h \
+ include/AccessoryCards/AccessoryCardLora15.h \
include/AccessoryCards/AccessoryCardLora.h
include/Device/Device.h:
@@ -85,6 +86,8 @@ include/rapidjson/stringbuffer.h:
include/rapidjson/istreamwrapper.h:
+include/Utility/Utility.h:
+
include/Version.h:
include/AccessoryCards/AccessoryCardLora15.h:
diff --git a/include/Device/Device.h b/include/Device/Device.h
index 946221b..aa1d32b 100644
--- a/include/Device/Device.h
+++ b/include/Device/Device.h
@@ -2,6 +2,7 @@
#define DEVICE_H_
#include "General.h"
+#include "Utility.h"
#include "Version.h"
#include "AccessoryCardLora15.h"
@@ -11,17 +12,12 @@ class Device {
bool isRoot;
rapidjson::Document capabilities;
rapidjson::Document deviceInfo;
+ static const std::vector<std::string> apIdentifiers;
rapidjson::Document accessoryCards;
rapidjson::Value accessoryCard;
rapidjson::Document::AllocatorType& alloc = deviceInfo.GetAllocator();
rapidjson::Document::AllocatorType& accessoryCardsAlloc = accessoryCards.GetAllocator();
- static const std::vector<std::string> apIdentifiers;
-
- std::map<std::string, bool> capabilityList = {{"adc", false},{"battery", false},{"bluetooth", false},
- {"cell", false},{"cellWwan", false},{"din", false},{"dout", false},{"externalSerialPort", false},
- {"gpio", false},{"gps", false},{"lora", false},{"loraNetworkServer", false},
- {"nodeRed", false},{"rs232", false},{"rs422", false},{"rs485", false},{"serial", false},
- {"wifi", false}};
+ static std::map<std::string, bool> capabilityList;
std::map<std::string, std::string> deviceInfoList = {{"deviceId", ""},{"hardwareVersion", ""},
{"imei", ""},{"macAddress", "00:00:00:00:00:00"},{"macBluetooth", "00:00:00:00:00:00"},
{"macWifi", "00:00:00:00:00:00"},{"productId", ""},{"uuid", ""},{"vendorId", ""}};
@@ -36,11 +32,58 @@ class Device {
static const std::regex storeFilters;
static const std::regex showFilters;
+
+ class AccessoryCard {
+ protected:
+ Device& device;
+ public:
+ AccessoryCard(Device& d);
+ };
+
+ class LoraCard : public AccessoryCard {
+ protected:
+ std::string spiPath;
+ public:
+ LoraCard(Device& d, const std::string productId, const std::string port);
+ };
+
+ class Lora15Card : public LoraCard {
+ private:
+ void *spi_target_ptr = NULL;
+ uint8_t fpgaVersion = 255;
+ public:
+ Lora15Card(Device& d, const std::string productId, const std::string port);
+ int spiOpen(const char *spidev);
+ int spiRead(uint8_t address, uint8_t *data);
+ int spiClose();
+ };
+
+ class Lora21Card : public LoraCard {
+ private:
+ std::string fpgaVersion;
+ public:
+ Lora21Card(Device& d, const std::string productId, const std::string port);
+ };
+
+ class Lora21ExtCard : public Lora21Card {
+ private:
+ std::string fpgaVersion2;
+ public:
+ Lora21ExtCard(Device& d, const std::string productId, const std::string port);
+ };
+
+ class Gpiob : public AccessoryCard {
+ public:
+ Gpiob(Device& d);
+ };
+
+ class Mfser : public AccessoryCard {
+ public:
+ Mfser(Device& d, const std::string port);
+ };
+
public:
Device();
- void exitHandler(int code);
- bool fileExists(std::string file);
- mode_t fileType(std::string file);
void getSystemTreeJson(const char * dir_name);
void init();
void load();
@@ -53,16 +96,10 @@ class Device {
void printJson();
void printVersion (std::string name);
void printUsage(std::string program);
- void setupLora15(std::string fileData, const char * dir_name);
- void setupLoraG16(std::string fileData, const char * dir_name);
- void setupLoraG64(std::string fileData, const char * dir_name);
- void setupGpiob(std::string fileData, const char * dir_name);
- void setupMfser(std::string fileData, const char * dir_name);
void show(std::string program);
void showTrigger(std::string name);
void store(std::string name, std::string value);
void storeTrigger(std::string name, std::string value);
- std::string toCamelCase(const char * d_name);
void Verbose(bool val);
bool Verbose();
void writeJson();
diff --git a/include/General.h b/include/General.h
index 2ca729a..81f5a3d 100644
--- a/include/General.h
+++ b/include/General.h
@@ -67,7 +67,7 @@ typedef unsigned int uint; //32 bit - even on 64 bit machines
#define READ_ACCESS 0x00
#define SPI_SPEED 8000000
-#define DEVICE_INFO_FILE "/var/run/config/device_info.json"
+#define DEVICE_INFO_FILE "/var/run/config/device_info.json"
#define RESET_SHORT_CMD "reset_short_handler"
#define RESET_LONG_CMD "reset_long_handler"
#define KILL_SIGNAL "kill -l "
diff --git a/include/Utility/Utility.h b/include/Utility/Utility.h
new file mode 100644
index 0000000..062e422
--- /dev/null
+++ b/include/Utility/Utility.h
@@ -0,0 +1,56 @@
+#ifndef UTILITIES_H_
+#define UTILITIES_H_
+
+#include "General.h"
+#include "Version.h"
+
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+inline bool fileExists(std::string file) {
+ struct stat buffer;
+ return (stat (file.c_str(), &buffer) == 0) ? true : false;
+}
+
+inline std::string toCamelCase(const char * d_name) {
+ std::string camelString = strdup(d_name);
+ std::string tempString = "";
+ for (size_t x = 0; x < camelString.length(); x++){
+ if (camelString[x] == '-' || camelString[x] == '_'){
+ tempString = camelString.substr(x + 1, 1);
+ transform(tempString.begin(), tempString.end(), tempString.begin(), toupper);
+ camelString.erase(x, 2);
+ camelString.insert(x, tempString);
+ }
+ }
+ return camelString;
+}
+
+inline void exitHandler(int code) {
+ if (code != 0) {
+ std::cout << "exiting with " << std::to_string(code);
+ }
+ exit(code);
+}
+
+inline mode_t fileType(std::string file) {
+ struct stat buf;
+ stat (file.c_str(), &buf);
+ return buf.st_mode & S_IFMT;
+}
+
+#endif /* UTILITIES_H_ */
diff --git a/src/AccessoryCards/AccessoryCardLora.cpp b/src/AccessoryCards/AccessoryCardLora.cpp
deleted file mode 100644
index 13bbab5..0000000
--- a/src/AccessoryCards/AccessoryCardLora.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "AccessoryCardLora.h"
-
-AccessoryCardLora::AccessoryCardLora(std::string ProductId, std::string Port) {
- port = Port;
- productId = ProductId;
- spiPath = "/dev/spidev0.0";
- if ((productId.find("MTCDT3-") == 0) && (port.back() == '2')) {
- spiPath = "/dev/spidev1.0";
- } else if (productId.find("MTAC-LORA-G") == 0) {
- spiPath = "/dev/spidev32766.2";
- } else if (productId.find("MTAC-LORA-") == 0) {
- if (port.back() == '2') {
- spiPath = "/dev/spidev32765.2";
- } else {
- spiPath = "/dev/spidev32766.2";
- }
- }
-}
-
-std::string AccessoryCardLora::getPath() {
- return spiPath;
-}
diff --git a/src/AccessoryCards/AcessoryCard.cpp b/src/AccessoryCards/AcessoryCard.cpp
new file mode 100644
index 0000000..16589b0
--- /dev/null
+++ b/src/AccessoryCards/AcessoryCard.cpp
@@ -0,0 +1,21 @@
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::AccessoryCard::AccessoryCard(Device& d) : device(d) {
+}
diff --git a/src/AccessoryCards/Gpiob.cpp b/src/AccessoryCards/Gpiob.cpp
new file mode 100644
index 0000000..3a87c8a
--- /dev/null
+++ b/src/AccessoryCards/Gpiob.cpp
@@ -0,0 +1,25 @@
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::Gpiob::Gpiob(Device& d) : AccessoryCard(d) {
+ capabilityList["adc"] = true;
+ capabilityList["din"] = true;
+ capabilityList["dout"] = true;
+ capabilityList["gpio"] = true;
+} \ No newline at end of file
diff --git a/src/AccessoryCards/LoraCard.cpp b/src/AccessoryCards/LoraCard.cpp
new file mode 100644
index 0000000..ba50aa7
--- /dev/null
+++ b/src/AccessoryCards/LoraCard.cpp
@@ -0,0 +1,23 @@
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::LoraCard::LoraCard(Device& d, const std::string productId, const std::string port) : AccessoryCard(d) {
+ spiPath = "/dev/spidev0.0";
+ device.capabilityList["lora"] = true;
+} \ No newline at end of file
diff --git a/src/AccessoryCards/AccessoryCardLora15.cpp b/src/AccessoryCards/LoraCard15.cpp
index ee99622..df5c969 100644
--- a/src/AccessoryCards/AccessoryCardLora15.cpp
+++ b/src/AccessoryCards/LoraCard15.cpp
@@ -1,9 +1,51 @@
-#include "AccessoryCardLora15.h"
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::Lora15Card::Lora15Card(Device& d, const std::string productId, const std::string port) : LoraCard(d, productId, port) {
+ int ret;
+ fpgaVersion = 255;
+ if ((productId.find("MTCDT3-") == 0) && (port.back() == '2')) {
+ spiPath = "/dev/spidev1.0";
+ } else if (productId.find("MTAC-LORA-") == 0) {
+ if (port.back() == '2') {
+ spiPath = "/dev/spidev32765.2";
+ } else {
+ spiPath = "/dev/spidev32766.2";
+ }
+ }
+ ret = spiOpen(spiPath.c_str());
+ if (ret != 0) {
+ printf("Could not open SPI port %s", spiPath.c_str());
+ return;
+ }
+ /* detect if the gateway has an FPGA with SPI mux header support */
+ ret = spiRead(MTAC_FPGA_ADDRESS, &fpgaVersion);
+ if (ret != 0) {
+ printf("Could not read FPGA version");
+ }
-AccessoryCardLora15::AccessoryCardLora15(std::string ProductId, std::string Port) : AccessoryCardLora(ProductId, Port) {
+ spiClose();
+ spi_target_ptr = NULL;
+ device.accessoryCard.AddMember("fpgaVersion", fpgaVersion, device.accessoryCardsAlloc);
}
-int AccessoryCardLora15::spiOpen(const char *spidev) {
+int Device::Lora15Card::spiOpen(const char *spidev) {
int *spi_device = NULL;
int dev;
int a = 0, b = 0;
@@ -70,7 +112,7 @@ int AccessoryCardLora15::spiOpen(const char *spidev) {
spi_target_ptr = (void *)spi_device;
return 0;
}
-int AccessoryCardLora15::spiRead(uint8_t address, uint8_t *data) {
+int Device::Lora15Card::spiRead(uint8_t address, uint8_t *data) {
int spi_device;
uint8_t out_buf[3];
uint8_t in_buf[ARRAY_SIZE(out_buf)];
@@ -104,7 +146,7 @@ int AccessoryCardLora15::spiRead(uint8_t address, uint8_t *data) {
}
}
-int AccessoryCardLora15::spiClose() {
+int Device::Lora15Card::spiClose() {
int spi_device;
int a;
@@ -120,23 +162,4 @@ int AccessoryCardLora15::spiClose() {
} else {
return 0;
}
-}
-
-uint8_t AccessoryCardLora15::getFPGAVersion() {
- int ret;
- uint8_t u = 255;
- ret = spiOpen(getPath().c_str());
- if (ret != 0) {
- printf("Could not open SPI port %s", getPath().c_str());
- return u;
- }
- /* detect if the gateway has an FPGA with SPI mux header support */
- ret = spiRead(MTAC_FPGA_ADDRESS, &u);
- if (ret != 0) {
- printf("Could not read FPGA version");
- }
-
- spiClose();
- spi_target_ptr = NULL;
- return u;
} \ No newline at end of file
diff --git a/src/AccessoryCards/LoraCard21.cpp b/src/AccessoryCards/LoraCard21.cpp
new file mode 100644
index 0000000..70bec11
--- /dev/null
+++ b/src/AccessoryCards/LoraCard21.cpp
@@ -0,0 +1,24 @@
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::Lora21Card::Lora21Card(Device& d, const std::string productId, const std::string port): LoraCard(d, productId, port) {
+ spiPath = "/dev/spidev32766.2";
+ MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
+ device.accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), device.accessoryCardsAlloc);
+} \ No newline at end of file
diff --git a/src/AccessoryCards/LoraCard21Ext.cpp b/src/AccessoryCards/LoraCard21Ext.cpp
new file mode 100644
index 0000000..b7531c7
--- /dev/null
+++ b/src/AccessoryCards/LoraCard21Ext.cpp
@@ -0,0 +1,24 @@
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::Lora21ExtCard::Lora21ExtCard(Device& d, const std::string productId, const std::string port): Lora21Card(d, productId, port) {
+ MTS::System::cmd(LORA_2_1_EXT_FPGA_VERSION, fpgaVersion2);
+ device.accessoryCard.AddMember("fpgaVersion2", std::stoi(fpgaVersion2), device.accessoryCardsAlloc);
+
+} \ No newline at end of file
diff --git a/src/AccessoryCards/Mfser.cpp b/src/AccessoryCards/Mfser.cpp
new file mode 100644
index 0000000..ac6bb26
--- /dev/null
+++ b/src/AccessoryCards/Mfser.cpp
@@ -0,0 +1,29 @@
+/**********************************************************************
+* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
+*
+* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
+* MULTI-TECH SYSTEMS, INC.
+*
+* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
+* INFORMATION AND/OR TRADE SECRET.
+*
+* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
+* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
+* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
+* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
+* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
+*
+***********************************************************************/
+
+#include "Device.h"
+
+Device::Mfser::Mfser(Device& d, const std::string port) : AccessoryCard(d) {
+ capabilityList["rs232"] = true;
+ capabilityList["rs422"] = true;
+ capabilityList["rs485"] = true;
+ capabilityList["serial"] = true;
+ if (!fileExists("/dev/ext_serial") && port.size() > 0) {
+ std::string temp;
+ MTS::System::cmd(std::string("ln -s /dev/ttyAP") + port.back() + " /dev/ext_serial", temp);
+ }
+} \ No newline at end of file
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index 0083ff3..b806f06 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -28,29 +28,17 @@ const std::regex Device::serialModeFilter("(.*)(serial-mode)");
const std::regex Device::storeFilters("(.*)(mac-)(.*)|(.*)(-id)|(uuid)|(.*)(/eui)|(.*)(/cdone)|(.*)(hw-version)|(imei)|(capability)(.*)|(radio-reset-backoff-seconds)|(modalias)|(power)|((subsystem)(.*))|(uevent)|(board-temperature)|(reset)|(led3)|(led-ls)|(usbhd-ps-oc)|(.*)(adc[0-9])|(.*)(din[0-9])|(gpi[0-9])|(gpi[0-9][0-9])");
const std::regex Device::showFilters("(modalias)|(subsystem)|(uevent)");
+std::map<std::string, bool> Device::capabilityList = {{"adc", false},{"battery", false},{"bluetooth", false},
+ {"cell", false},{"cellWwan", false},{"din", false},{"dout", false},{"externalSerialPort", false},
+ {"gpio", false},{"gps", false},{"lora", false},{"loraNetworkServer", false},
+ {"nodeRed", false},{"rs232", false},{"rs422", false},{"rs485", false},{"serial", false},
+ {"wifi", false}};
+
Device::Device() {
isRoot = !getuid();
verbose = false;
}
-void Device::exitHandler(int code) {
- if (code != 0) {
- logError("exiting with " + std::to_string(code));
- }
- exit(code);
-}
-
-bool Device::fileExists(std::string file) {
- struct stat buffer;
- return (stat (file.c_str(), &buffer) == 0) ? true : false;
-}
-
-mode_t Device::fileType(std::string file) {
- struct stat buf;
- stat (file.c_str(), &buf);
- return buf.st_mode & S_IFMT;
-}
-
void Device::getSystemTreeJson(const char * dir_name) {
std::string fullPath = SYSFS_PLATFORM + std::string(dir_name);
DIR * d = opendir (fullPath.c_str());
@@ -81,15 +69,15 @@ void Device::getSystemTreeJson(const char * dir_name) {
}
if (strcmp(d_name, "product-id") == 0) {
if (regex_match(fileData, lora15Filters)) {
- setupLora15(fileData, dir_name);
+ Lora15Card lora15(*this, fileData, dir_name);
} else if (regex_match(fileData, loraG16Filters)) {
- setupLoraG16(fileData, dir_name);
+ Lora21Card lora21(*this, fileData, dir_name);
} else if (regex_match(fileData, loraG64Filters)) {
- setupLoraG64(fileData, dir_name);
+ Lora21ExtCard lora21Ext(*this, fileData, dir_name);
} else if (regex_match(fileData, gpiobFilters)) {
- setupGpiob(fileData, dir_name);
+ Gpiob ppiob(*this);
} else if (regex_match(fileData, mfserFilters)) {
- setupMfser(fileData, dir_name);
+ Mfser msfer(*this, dir_name);
}
}
accessoryCard.AddMember(rapidjson::Value().SetString(toCamelCase(d_name).c_str(), accessoryCardsAlloc), rapidjson::Value().SetString(fileData.c_str(), accessoryCardsAlloc), accessoryCardsAlloc);
@@ -301,48 +289,6 @@ void Device::printUsage(std::string program) {
exitHandler(1);
}
-void Device::setupLora15(std::string fileData, const char * dir_name) {
- capabilityList["lora"] = true;
- AccessoryCardLora15 mSPI(fileData, dir_name);
- mSPI.getFPGAVersion();
- accessoryCard.AddMember("fpgaVersion", mSPI.getFPGAVersion(), accessoryCardsAlloc);
-}
-
-void Device::setupLoraG16(std::string fileData, const char * dir_name) {
- capabilityList["lora"] = true;
- std::string fpgaVersion;
- MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
- accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
-}
-
-void Device::setupLoraG64(std::string fileData, const char * dir_name) {
- capabilityList["lora"] = true;
- std::string fpgaVersion;
- std::string fpgaVersion2;
- MTS::System::cmd(LORA_2_1_FPGA_VERSION, fpgaVersion);
- MTS::System::cmd(LORA_2_1_EXT_FPGA_VERSION, fpgaVersion2);
- accessoryCard.AddMember("fpgaVersion", std::stoi(fpgaVersion), accessoryCardsAlloc);
- accessoryCard.AddMember("fpgaVersion2", std::stoi(fpgaVersion2), accessoryCardsAlloc);
-}
-
-void Device::setupGpiob(std::string fileData, const char * dir_name) {
- capabilityList["adc"] = true;
- capabilityList["din"] = true;
- capabilityList["dout"] = true;
- capabilityList["gpio"] = true;
-}
-
-void Device::setupMfser(std::string fileData, const char * dir_name) {
- capabilityList["rs232"] = true;
- capabilityList["rs422"] = true;
- capabilityList["rs485"] = true;
- capabilityList["serial"] = true;
- if (!fileExists("/dev/ext_serial") && strlen(dir_name) > 0) {
- std::string temp;
- MTS::System::cmd("ln -s /dev/ttyAP" + std::string(dir_name + strlen(dir_name) - 1) + " /dev/ext_serial", temp);
- }
-}
-
void Device::show(std::string name) {
std::string fileData;
int32_t code = MTS::System::readFile(SYSFS_PLATFORM + name, fileData);
@@ -353,7 +299,6 @@ void Device::show(std::string name) {
logError("cat: can't open " + std::string(SYSFS_PLATFORM) + name + ": No such file or directory");
exitHandler(99);
}
-
}
void Device::showTrigger(std::string name) {
@@ -403,21 +348,6 @@ void Device::storeTrigger(std::string name, std::string value) {
}
}
-std::string Device::toCamelCase(const char * d_name) {
- std::string camelString = strdup(d_name);
- std::string tempString = "";
- for (size_t x = 0; x < camelString.length(); x++){
- if (camelString[x] == '-' || camelString[x] == '_'){
- tempString = camelString.substr(x + 1, 1);
- transform(tempString.begin(), tempString.end(), tempString.begin(), toupper);
- camelString.erase(x, 2);
- camelString.insert(x, tempString);
- }
- }
- return camelString;
-}
-
-
void Device::Verbose(const bool val) {
verbose = val;
}
@@ -437,4 +367,4 @@ void Device::writeJson() {
} else {
os << buffer.GetString();
}
-}
+} \ No newline at end of file
diff --git a/src/MtsIoSysfs.cpp b/src/MtsIoSysfs.cpp
index 0c9dc2e..390db47 100644
--- a/src/MtsIoSysfs.cpp
+++ b/src/MtsIoSysfs.cpp
@@ -46,28 +46,28 @@ int main(int argc, char const* const argv[]) {
m.show(argv[i + 1]);
} else {
m.logError("show name");
- m.exitHandler(99);
+ exitHandler(99);
}
} else if (parameter == "show-trigger") {
if (argv[i + 1] && !argv[i + 2]) {
m.showTrigger(std::string(argv[i + 1]));
} else {
m.logError("show-trigger name");
- m.exitHandler(99);
+ exitHandler(99);
}
} else if (parameter == "store") {
if (argv[i + 1] && argv[i + 2] && !argv[i + 3]) {
m.store(std::string(argv[i + 1]), std::string(argv[i + 2]));
} else {
m.logError("store name value");
- m.exitHandler(99);
+ exitHandler(99);
}
} else if (parameter == "store-trigger") {
if (argv[i + 1] && argv[i + 2] && !argv[i + 3]) {
m.storeTrigger(std::string(argv[i + 1]), std::string(argv[i + 2]));
} else {
m.logError("store name value");
- m.exitHandler(99);
+ exitHandler(99);
}
}
}
diff --git a/src/Version.cpp b/src/Version.cpp
index 96d0a2c..0f6d228 100644
--- a/src/Version.cpp
+++ b/src/Version.cpp
@@ -1,4 +1,4 @@
//Pre-Build Auto-Generated Source
#include "Version.h"
-const std::string Version::version("v1.0.0-4-g50a0344");
+const std::string Version::version("v1.0.0-5-g68c0c5e");