-
Notifications
You must be signed in to change notification settings - Fork 1
/
shm_read.cpp
40 lines (31 loc) · 1.3 KB
/
shm_read.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
#include "shm_buffer.h"
#include "data.pb.h"
#include <malloc.h>
using namespace shm_buffer;
int main()
{
cout << "Hello BufferConsumer1!" << endl;
ShmBuffer testBuffer(BufferConsumer1,6000);
int lastCommand = -1;
while(1)
{
while(testBuffer.isReadyToRead())
{
int size = testBuffer.getBufferSize();
void *buffer = malloc(size);
testBuffer.readData(buffer);
auto msg_received = std::make_shared<data::DataTest>();
msg_received->ParseFromArray(buffer,size);
// cout << "msg_received " << getTime(getTimeStamp()) << " source: " << msg_received->source() << " command: " << msg_received->command() << " param: " << msg_received->param() << " ret: " << msg_received->ret() << " size: " << testBuffer.getBufferSize() << endl;
if(lastCommand != msg_received->command() - 1)
{
cout << "Got Command Error!!! " << getTime(getTimeStamp()) << " lastCommand: " << lastCommand << " Got Command: " << msg_received->command() << endl;
}
lastCommand = msg_received->command();
free(buffer);
}
// cout << "Waiting... " << getTime(getTimeStamp()) << endl;
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
return 0;
}