-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforSS.cpp
More file actions
193 lines (168 loc) · 6.09 KB
/
forSS.cpp
File metadata and controls
193 lines (168 loc) · 6.09 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
for (int rounds = 0; rounds < 10; rounds++) {
std::cout << "timing for sensorbuffer map: \n";
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 500; j++) {
bufferMap[names[i]][bufferIndexMap] = result;
bufferIndexMap++;
}
bufferIndexMap = 0;
}
clock_gettime(CLOCK_MONOTONIC, &end);
std::cout << "elapsed time: " << ((end.tv_sec - start.tv_sec) + 1e-9 * (end.tv_nsec - start.tv_nsec)) << "\n";
}
for (int rounds = 0; rounds < 10; rounds++) {
std::cout << "timing for sensorbuffer pair: \n";
clock_gettime(CLOCK_MONOTONIC, &start);
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 500; j++) {
std::pair<char*, double> pair1;
pair1.first = names[i];
pair1.second = result;
bufferPair[bufferIndexPair] = pair1;
bufferIndexPair++;
}
}
bufferIndexPair=0;
clock_gettime(CLOCK_MONOTONIC, &end);
std::cout << "elapsed time: " << ((end.tv_sec - start.tv_sec) + 1e-9 * (end.tv_nsec - start.tv_nsec)) << "\n";
}
std::cout << "timing for sensorbuffer map: \n";
clock_gettime(CLOCK_MONOTONIC, &start);
for (int rounds = 0; rounds < 10; rounds++) {
for (int i = 0; i < bufferIndexPair; i++) {
if (strcmp(bufferPair[i].first, "lat") == 0) {
filteredBuffer[filteredBufferIndex] = bufferPair[i];
filteredBufferIndex++;
}
}
filteredBufferIndex = 0;
}
clock_gettime(CLOCK_MONOTONIC, &end);
timeresult = ((end.tv_sec - start.tv_sec) + 1e-9 * (end.tv_nsec - start.tv_nsec));
std::cout << "elapsed time: " << timeresult << "\n";
std::cout << "gem: " << timeresult / 10 << "\n";
void miq_movement_c::getData(sensorBuffer &buffer, int &amountSamples) {
struct timespec start;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &start);
int ret = NO_ERROR;
// try to open buffer, make file descriptor
/* Attempt to open non blocking the access dev */
int fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
if (fp == -1) { /* TODO: If it isn't there make the node */
ret = -errno;
fprintf(stderr, "Failed to open %s\n", buffer_access);
std::cout << "Failed to open buffer_access on nr" << __LINE__ << "\n";
return;
}
int toread;
struct pollfd pfd = {
.fd = fp,
.events = POLLIN,
};
// NOTE: -1 is blocking wait for event. ) is nonblocking
ret = poll(&pfd, 1, 0);
if (ret < 0) {
// error has take place
ret = -errno;
goto error_close_buffer_access;
} else if (ret == 0) {
// call timed out
goto error_close_buffer_access;
}
toread = buf_len; //4
//scan_size is bytes is channelsize
// read returns amount of bytes
// databytes stored in data
// reads the amount of bytes corresponding to toread *
ssize_t read_size;
read_size = read(fp, data, toread * scan_size);
clock_gettime(CLOCK_MONOTONIC, &now);
printf("Elapsed read bufferfile: %f\n",
(now.tv_sec - start.tv_sec) +
1e-9 * (now.tv_nsec - start.tv_nsec));
}
clock_gettime(CLOCK_MONOTONIC, &start);
gps.getData();
clock_gettime(CLOCK_MONOTONIC, &now);
std::cout << "elapsed: " << (now.tv_sec-start.tv_sec + 1e-9*(now.tv_nsec - start.tv_nsec)) << "\n";
void SecondTimer::main() {
int intervalnano = 1000000000;
struct timespec start;
struct timespec now;
struct timespec timeSpecInterval;
int timeToSleep = 0;
clock_gettime(CLOCK_REALTIME, &start);
while (true) {
clock_gettime(CLOCK_REALTIME, &now);
// check how much time is left before one second passes. Sleep this resting time
timeToSleep = ((intervalnano - ((now.tv_sec - start.tv_sec)*1000000000 + (now.tv_nsec - start.tv_nsec))));
if (timeToSleep > 0 && timeToSleep < intervalnano) {
timeSpecInterval.tv_sec = 0;
timeSpecInterval.tv_nsec = (timeToSleep);
nanosleep(&timeSpecInterval, NULL);
} else {
std::cout << "TimerError: Error!! timing is longer than one second\n";
}
clock_gettime(CLOCK_REALTIME, &start);
for(auto sensor : sensors){
sensor->setSecondFlag();
}
collector.setSecondFlag();
}
}
void SecondTimer::main() {
int intervalnano = 1000000000;
struct timespec start;
struct timespec now;
struct timespec timeSpecInterval;
int timeToSleep = 0;
clock_gettime(CLOCK_REALTIME, &start);
timeSpecInterval.tv_nsec = intervalnano;
while (true) {
clock_gettime(CLOCK_REALTIME, &start);
nanosleep(&timeSpecInterval, NULL);
clock_gettime(CLOCK_REALTIME, &now);
printf("Elapsed %f\n", (now.tv_sec - start.tv_sec) + 1e-9 * (now.tv_nsec - start.tv_nsec));
}
}
int main() {
struct timespec start;
struct timespec now;
struct timespec timeSpecInterval;
timeSpecInterval.tv_sec = 1;
timeSpecInterval.tv_nsec = 0;
while (true) {
clock_gettime(CLOCK_REALTIME, &start);
nanosleep(&timeSpecInterval, NULL);
clock_gettime(CLOCK_REALTIME, &now);
printf("Elapsed nanosleep %f\n", (now.tv_sec - start.tv_sec) +
1e-9 * (now.tv_nsec - start.tv_nsec));
}
}
int main() {
std::cout << " Hello World!\n";
struct timespec start;
struct timespec now;
while (true) {
clock_gettime(CLOCK_REALTIME, &start);
usleep(1000000);
clock_gettime(CLOCK_REALTIME, &now);
printf("Elapsed usleep %f\n", (now.tv_sec - start.tv_sec) +
1e-9 * (now.tv_nsec - start.tv_nsec));
}
}
int main() {
miq_RTU rtu = miq_RTU();
std::cout << " Hello World!\n";
struct timespec start;
struct timespec now;
while (true) {
clock_gettime(CLOCK_REALTIME, &start);
rtu.rtu_usleep(1000000);
clock_gettime(CLOCK_REALTIME, &now);
printf("Elapsed usleep %f\n", (now.tv_sec - start.tv_sec) +
1e-9 * (now.tv_nsec - start.tv_nsec));
}
}