-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonexample.cpp
105 lines (101 loc) · 3.66 KB
/
jsonexample.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
93
94
95
96
97
98
99
100
101
102
103
104
105
//#include "external/include/json.hpp"
//#include <stdio.h>
#include "simulatorExchangeSender.hpp"
#include <iostream>
// void printbits(uint8_t byte){
// printf("%d%d%d%d%d%d%d%d",
// (byte >> 7) & 1,
// (byte >> 6) & 1,
// (byte >> 5) & 1,
// (byte >> 4) & 1,
// (byte >> 3) & 1,
// (byte >> 2) & 1,
// (byte >> 1) & 1,
// (byte >> 0) & 1);
// }
// void valcopy(uint32_t val, uint8_t *buf, int startbit, int endbit){
// int bitpos = startbit;
// // Check for pointless input
// if(startbit > endbit)
// return;
// // This loop copies the bits from val to the right location in buf with
// bit
// // precision.
// do{
// // window of 8 bits.
// uint8_t source_byte = (val >> std::max((endbit - bitpos - 7), 0)) &
// 0xff; uint8_t dest_byte = buf[bitpos / 8];
// // mask for zeroing out the old bits that are replaced, while leaving
// the rest unchanged. uint8_t dest_byte_mask = 0xff ^ ((1 << (8 - bitpos % 8))
// - 1);
// // corner case: last window is smaller, so align it to byte-begin and
// shrink the mask if(endbit - bitpos < 8){ dest_byte_mask |= ((1 << (7 -
// (endbit % 8))) - 1); source_byte = source_byte << (7 - (endbit - bitpos));
// }
// // align source to bit start offset
// source_byte = source_byte >> (bitpos % 8);
// // mask to protect old bits in buf that should not be changed.
// // This doesn't hurt, but reduces the damage when we did
// // something wrong with the source_byte.
// uint8_t source_byte_mask = ~dest_byte_mask;
// // printf("%x ", source_byte);
// // printbits(dest_byte_mask);
// // printf(" ");
// // printbits(source_byte_mask);
// // printf("\n");
// buf[bitpos / 8] = (dest_byte & dest_byte_mask) | (source_byte &
// source_byte_mask);
// // increment to byte boundary
// bitpos = (bitpos / 8 + 1) * 8;
// } while(bitpos <= endbit);
// }
int main(int argc, char **argv) {
// nlohmann::json j = nlohmann::json::parse("{\"keyy\": [1,2,3]}");
// std::cout << j["key"].is_null() << j["keyy"].is_null();
// uint8_t buf[16] = { 0 };
// valcopy(0xfffffeff, buf, 9, 38);
// valcopy(0x00000001, buf, 47, 47);
// for(int i = 0; i < 16; i++){
// printbits(buf[i]);
// printf(" ");
// }
// printf("\n");
// std::string s = j["key"];
// std::cout << s;
if (argc < 2) {
printf("provide tdf please!\n");
return 1;
}
std::string s(argv[1]);
sepreference::SimulatorExchangeSender::init(s);
std::string key("IndLzb1000");
std::string key2("speed");
// sepreference::SimulatorExchangeSender::updateValue(key, 1);
// std::this_thread::sleep_for(std::chrono::seconds(5));
// sepreference::SimulatorExchangeSender::updateValue(key, 3);
// std::this_thread::sleep_for(std::chrono::seconds(5));
// sepreference::SimulatorExchangeSender::updateValue(key, 0);
// std::this_thread::sleep_for(std::chrono::seconds(5));
sepreference::SimulatorExchangeSender::allowSending(true);
sepreference::SimulatorExchangeSender::allowSending(false);
while (0) {
float val = 0;
std::string uk;
std::cout << "key\n";
fflush(stdin);
std::cin >> uk;
std::cout << "value\n";
std::cin >> val;
fflush(stdout);
sepreference::SimulatorExchangeSender::updateValue(uk, val);
fflush(stdout);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
// float val = 0;
// std::this_thread::sleep_for(std::chrono::seconds(1));
// while(val < 200){
// val += 0.5;
// sepreference::SimulatorExchangeSender::updateValue(key2, val);
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
// }
}