-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsbd.cpp
92 lines (67 loc) · 2.06 KB
/
bsbd.cpp
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
#include <string>
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
#include <boost/program_options.hpp>
#include <mqtt/async_client.h>
#include "bus.h"
#include "message.h"
#include "vtype.h"
#include "AddressMap.h"
#include "mqtt.h"
#include "config.h"
namespace po = boost::program_options;
using json = nlohmann::json;
void messageformat_parse(json& messageformat) {
for(auto& mtype : messageformat["messages"]) {
if (!mtype.contains("type")) {
std::cerr << "Need type" << std::endl;
exit(-1);
}
std::string type=mtype["type"].get<std::string>();
std::string name=mtype["name"].get<std::string>();
uint32_t address=std::stoul(mtype["address"].get<std::string>(), nullptr, 16);
VT::Default *vt;
try {
vt=vtmap.at(type);
} catch (std::out_of_range& e) {
std::cerr << "Unknown public value type " << type << std::endl;
exit(-1);
}
Address *aptr=new Address(address, vt, name);
addressmap.add(aptr);
}
}
void messageformat_parse(std::string filename) {
std::ifstream file(filename);
json messageformat=json::parse(file);
//messageformat_value_type_parse(messageformat);
messageformat_parse(messageformat);
}
int main(int argc, char **argv) {
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("config,i", po::value<std::string>()->required(), "Config file")
;
po::variables_map vm;
try {
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
} catch(const boost::program_options::error& e) {
std::cerr << "Error: " << e.what() << "\n";
std::cout << desc << std::endl;
exit(-1);
}
std::ifstream configstream(vm["config"].as<std::string>());
json config=json::parse(configstream);
messageformat_parse(config["messageformat"].get<std::string>());
std::vector<Bus> busses;
auto mqttconfig=config["mqtt"].get<config::mqtt>();
auto mqtt=MQTT(mqttconfig);
for(auto &busconfigjson : config["busses"]) {
auto busconfig=busconfigjson.get<config::bus>();
Bus newbus(busconfig);
}
std::cout << config.dump() << std::endl;
}