10 #include "controlwebsocketclient.h"
11 #include "datamessage.h"
12 #include "eventmessage.h"
13 #include "logresult.h"
15 std::vector<VehicleInfoDefine> vehicleinfolist;
16 int maxstandarddatacount = 1;
17 int maxcustomdatacount = 0;
19 int testdatanum = maxstandarddatacount + maxcustomdatacount;
22 std::string vicproperty;
23 std::string dbusproperty;
29 int SetDataOpt(DataOpt *opt, int idx, T value) {
30 memcpy(opt->status + idx, &value, sizeof(value));
34 int main(int argc, char *argv[]) {
36 std::string configpath = "/etc/ambd/AMBformat.conf";
38 while ((ret = getopt(argc, argv, "c:i:n:s:")) != -1) {
41 configpath = std::string(optarg);
44 retstr = std::string(optarg);
45 interspace = std::stoi(retstr);
48 retstr = std::string(optarg);
49 maxcustomdatacount = std::stoi(retstr);
50 testdatanum = maxstandarddatacount + maxcustomdatacount;
53 retstr = std::string(optarg);
54 maxstandarddatacount = std::stoi(retstr);
55 testdatanum = maxstandarddatacount + maxcustomdatacount;
62 ifstream fin("standardvehicleinfo.txt");
64 std::vector<std::string> standardvehicleinfolist;
67 standardvehicleinfolist.push_back(str);
71 if (!config.readConfig(configpath)) {
72 std::cerr << "Can't read VIC-Plugin config file." << std::endl;
75 PortInfo portinfo = config.getPort();
77 ControlWebsocketClient stddataws, customdataws;
78 if (!stddataws.initialize("ws://127.0.0.1", portinfo.standard.dataPort, "standarddatamessage-only")) {
79 std::cerr << "Can't connect standarddatamessage-only." << std::endl;
82 if (!customdataws.initialize("ws://127.0.0.1", portinfo.custom.dataPort, "customdatamessage-only")) {
83 std::cerr << "Can't connect customdatamessage-only." << std::endl;
87 vehicleinfolist =config.getVehicleInfoConfig();
88 auto itr_end = vehicleinfolist.end();
92 enum ClientType cltype = CLIENT_VIC;
93 enum CommandType cotype = CMDTYPE_SET;
95 struct TestData testdata[testdatanum];
97 int standarddatacount = 0;
98 int customdatacount = 0;
100 for (int i = 0; i < 10; i++) {
102 customdataws.service();
107 for (auto itr = vehicleinfolist.begin(); itr != itr_end && datacount < testdatanum; itr++) {
108 if ((*itr).status.size() > 1) {
111 auto itr2_end = (*itr).status.end();
112 if (std::find(standardvehicleinfolist.begin(), standardvehicleinfolist.end(), std::string((*itr).KeyEventType)) != standardvehicleinfolist.end()) {
113 if (standarddatacount >= maxstandarddatacount) {
116 testdata[datacount].vicproperty = std::string((*itr).KeyEventType);
117 testdata[datacount].isstd = true;
118 for (auto itr2 = (*itr).status.begin(); itr2 != itr2_end; itr2++) {
119 testdata[datacount].dbusproperty = std::string((*itr2).dbusPropertyName);
120 testdata[datacount].type = (*itr2).type;
126 if (customdatacount >= maxcustomdatacount) {
129 testdata[datacount].vicproperty = std::string((*itr).KeyEventType);
130 testdata[datacount].isstd = false;
131 for (auto itr2 = (*itr).status.begin(); itr2 != itr2_end; itr2++) {
132 testdata[datacount].dbusproperty = std::string((*itr2).dbusPropertyName);
133 testdata[datacount].type = (*itr2).type;
140 struct timeval starttv, endtv;
141 for (int i = 0; i < 100; i++) {
142 gettimeofday(&starttv, NULL);
143 for (int j = 0; j < testdatanum; j++) {
144 switch (testdata[j].type) {
147 idx = SetDataOpt(&dopt, 0, i);
148 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, i++);
152 static double d = 0.0;
153 idx = SetDataOpt(&dopt, 0, d);
154 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, d);
160 idx = SetDataOpt(&dopt, 0, c);
161 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, c++);
165 static int16_t i16 = 0;
166 idx = SetDataOpt(&dopt, 0, i16);
167 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, i16++);
171 static uint16_t ui16 = 0;
172 idx = SetDataOpt(&dopt, 0, ui16);
173 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, ui16++);
177 static uint32_t ui32 = 0;
178 idx = SetDataOpt(&dopt, 0, ui32);
179 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, ui32++);
183 static int64_t i64 = 0;
184 idx = SetDataOpt(&dopt, 0, i64);
185 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, i64++);
189 static uint64_t ui64 = 0;
190 idx = SetDataOpt(&dopt, 0, ui64);
191 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, ui64++);
195 static bool b = true;
196 idx = SetDataOpt(&dopt, 0, b);
197 logger.PutOut(cltype, cotype, testdata[j].dbusproperty, b);
205 gettimeofday(&tv, NULL);
206 if (testdata[j].isstd) {
207 stddataws.send(datamsg.encode(const_cast<char*>(testdata[j].vicproperty.c_str()), tv, dopt), StandardMessage::KEYEVENTTYPESIZE + sizeof(timeval) + sizeof(int) + idx);
210 customdataws.send(datamsg.encode(const_cast<char*>(testdata[j].vicproperty.c_str()), tv, dopt), StandardMessage::KEYEVENTTYPESIZE + sizeof(timeval) + sizeof(int) + idx);
215 customdataws.service();
216 gettimeofday(&endtv, NULL);
217 //std::cerr << "End - Start = " << ((endtv.tv_sec - starttv.tv_sec) * 1000 * 1000 + (endtv.tv_usec - starttv.tv_usec)) << std::endl;
218 usleep(interspace * 1000 - ((endtv.tv_sec - starttv.tv_sec) * 1000 * 1000 + (endtv.tv_usec - starttv.tv_usec)));