#ifndef DEVICE_H_ #define DEVICE_H_ #include "Fpga.h" #include "General.h" #include "Utility.h" #include "Version.h" #include /* ceil */ class Mtac15Fpga; class Device { private: bool isRoot; rapidjson::Document capabilities; rapidjson::Document ethSwitch; rapidjson::Document deviceInfo; static const std::vector apIdentifiers; rapidjson::Document accessoryCards; rapidjson::Value accessoryCard; rapidjson::Document::AllocatorType &alloc = deviceInfo.GetAllocator(); rapidjson::Document::AllocatorType &acAlloc = accessoryCards.GetAllocator(); static std::map capabilityList; static std::map ethSwitchList; static std::map deviceInfoList; static std::vector dInputs; static std::vector dOutputs; static const std::regex apFilters; static const std::regex serialModeFilter; static const std::regex storeFilters; static const std::regex showFilters; static const std::regex mtcdt3HwVersionFilters; static const std::regex iotRtrVersionFilters; static const std::regex mtrFilters; const unsigned int accessoryCardsListSize = 7; class AccessoryCard { protected: Device &device; std::regex name; public: AccessoryCard(Device &d, const std::regex Name); virtual void AddToDeviceInfo(const std::string Port, const std::string ProductID); const std::regex GetName(); }; class LoraCard : public AccessoryCard { protected: std::string spiPath; uint8_t fpgaVersion; public: LoraCard(Device &d, const std::regex Name); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Lora03Card : public LoraCard { private: std::string spiPath1261; uint8_t tmp102; public: Lora03Card(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Lora10Card : public LoraCard { public: Lora10Card(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Lora15Card : public LoraCard { private: Lora15Card(); void *spi_target_ptr = NULL; const char pin_high = '1'; const char pin_low = '0'; public: Lora15Card(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Lora21Card : public LoraCard { private: std::string cmdFpgaVersion; public: Lora21Card(Device &d); Lora21Card(Device &d, const std::regex Name); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Lora21ExtCard : public Lora21Card { private: std::string cmdFpgaVersion2; public: Lora21ExtCard(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Lora2G4Card : public LoraCard { public: Lora2G4Card(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Gpiob : public AccessoryCard { public: Gpiob(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class Mfser : public AccessoryCard { public: Mfser(Device &d); void AddToDeviceInfo(const std::string Port, const std::string ProductID); }; class gpio_request { private: struct gpiod_request_config *request_config; struct gpiod_line_config *line_config; struct gpiod_line_settings *settings; struct gpiod_line_request *line_request; // Result of creating a request struct gpiod_chip *chip; unsigned int rq_offset; struct gpiod_chip *gpiod_ctxless_find_line(Device *device, std::string name, unsigned int *r_offset); public: struct gpiod_line_request *request(); unsigned int offset(); gpio_request(Device *device, const std::string name); ~gpio_request(); }; std::vector> accessoryCardsList; public: Device(); void getSystemTreeJson(const char *dir_name); void init(); bool isAccessoryCard(const char *d_name, const char *dir_name); bool isValidDirectory(const struct dirent *entry, std::string fullPath, const char *d_name); void load(); void logInfo(std::string info); void logError(std::string info); void json(); void mapFileToCapability(); void mapFirmware(); void mapMacAddress2(); void printDir(const std::string dir_name, std::vector &results); void printJson(); void printVersion(std::string name); void printUsage(std::string program); void show(std::string program); void showTrigger(std::string name); void sortAccessoryCards(); void store(std::string name, std::string value); void storeTrigger(std::string name, std::string value); void storeOutputStateToNonvolatile(const std::string& name, const std::string& value); void Verbose(bool val); bool Verbose(); void writeJson(const rapidjson::Document &json, const std::string &file); bool readJson(rapidjson::Document &json, const std::string &file); void simpleError(std::string msg, int error, int exitval); }; #endif /* DEVICE_H_ */