-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamFeeder.cpp
More file actions
65 lines (53 loc) · 1.13 KB
/
streamFeeder.cpp
File metadata and controls
65 lines (53 loc) · 1.13 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
#include <iostream> // for standard I/O
//#include <chrono>
#include <stdio.h> /* printf, fgets */
#include <stdlib.h> /* atoi */
#include <unistd.h>
#include <sys/time.h>
using namespace std;
int main(int argc, const char * argv[]){
int sensorVectorSize;
int maxValue;
int counter = 0;
long int timeNow;
struct timeval now;
if (argc > 2)
{
sensorVectorSize = atoi(argv[1]);
maxValue = atoi(argv[2]);
}
else
{
printf("Too few arguments.");
return 1;
}
usleep(5000000);
while (1)
{
gettimeofday(&now, NULL);
timeNow = (now.tv_sec * 1000000) + now.tv_usec;
for (int i = 1; i <= sensorVectorSize; i++)
{
if (maxValue < 0)
{
int randomNum = rand() % 200 - 99;
cout<<randomNum<<'\t';
}
else if (maxValue == 0)
{
cout<<counter<<'\t';
}
else
{
cout<<float(maxValue/i)<<'\t';
}
}
cout<<endl;
counter++;
gettimeofday(&now, NULL);
timeNow = ((now.tv_sec * 1000000) + now.tv_usec) - timeNow;
if(timeNow < 20000)
usleep(20000 - timeNow);//50 hz
}
return 0;
}