summaryrefslogtreecommitdiff
path: root/include
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 /include
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
Diffstat (limited to 'include')
-rw-r--r--include/Device/Device.h69
-rw-r--r--include/General.h2
-rw-r--r--include/Utility/Utility.h56
3 files changed, 110 insertions, 17 deletions
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_ */