From c4811dd1b73b37b0916803097237acd31f1df98b Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Tue, 7 Jan 2020 15:50:56 -0600 Subject: Refactored accessory cards classes with inheritence, fixed Makefile clean, moved some helper functions to header utility --- include/Device/Device.h | 69 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 16 deletions(-) (limited to 'include/Device') 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 apIdentifiers; rapidjson::Document accessoryCards; rapidjson::Value accessoryCard; rapidjson::Document::AllocatorType& alloc = deviceInfo.GetAllocator(); rapidjson::Document::AllocatorType& accessoryCardsAlloc = accessoryCards.GetAllocator(); - static const std::vector apIdentifiers; - - std::map 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 capabilityList; std::map 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(); -- cgit v1.2.3