-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWorker.cpp
More file actions
95 lines (67 loc) · 1.71 KB
/
MainWorker.cpp
File metadata and controls
95 lines (67 loc) · 1.71 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
#include "MainWorker.h"
#include <thread>
#include <mutex>
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void MainWorker::Start()
{
this->UI_pipeData->Initialization();
this->dataThread = std::thread(&MainWorker::sendData, this);
this->dataThread.detach();
this->distanceThread = std::thread(&MainWorker::sendDistance, this);
this->distanceThread.detach();
CrossSleep(10);
cout << "Every 500 ms the writer sends distance-initiation command" << endl;
cout << "Enter data:\nExample:\"id-123456\" ---> \"1-123456\"" << endl;
uint8_t buffer[256];
int i;
while (1) {
cin >> buffer;
i = 0;
while (buffer[i++] != '\0');
this->UPackData.FCmd = UserPackHL::Command::Data;
this->UPackData.SCmd = buffer[0] & 0x0F;
this->UPackData.TotalSize = i-3;
this->UPackData.Data.assign(&(buffer[2]), &(buffer[i-1]));
this->send_data_fl = true;
}
}
void MainWorker::sendDistance(void)
{
UserPackHL dupack;
dupack.FCmd = UserPackHL::Command::Distance;
dupack.SCmd = UserPackHL::BROADCAST_ID;
dupack.TotalSize = 6;
dupack.Data.resize(dupack.TotalSize);
uint8_t val = 'x';
std::fill(dupack.Data.begin(), dupack.Data.end(), val);
while (1) {
this->mu.lock();
this->UI_pipeData->Write(dupack);
CrossSleep(50);
this->mu.unlock();
CrossSleep(450);
}
}
void MainWorker::sendData(void)
{
while (1) {
if (this->send_data_fl) {
this->mu.lock();
this->UI_pipeData->Write(this->UPackData);
this->mu.unlock();
this->send_data_fl = false;
}
CrossSleep(20);
}
}
MainWorker::MainWorker()
{
this->UI_pipeData = new UserInterface(UserInterface::MODE::OPEN_EXISTING, UserInterface::CONNTYPE::SIMPLEX_WR);
}
MainWorker::~MainWorker()
{
delete this->UI_pipeData;
}