1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#ifndef DEVICE_H_
#define DEVICE_H_
#include "Fpga.h"
#include "General.h"
#include "Utility.h"
#include "Version.h"
#include <math.h> /* ceil */
class Mtac15Fpga;
class Device {
private:
bool isRoot;
rapidjson::Document capabilities;
rapidjson::Document ethSwitch;
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 &acAlloc = accessoryCards.GetAllocator();
static std::map<std::string, bool> capabilityList;
static std::map<std::string, std::string> ethSwitchList;
static std::map<std::string, std::string> deviceInfoList;
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 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<std::unique_ptr<AccessoryCard>> 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<std::string> &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 Verbose(bool val);
bool Verbose();
void writeJson();
void simpleError(std::string msg, int error, int exitval);
};
#endif /* DEVICE_H_ */
|