-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimeSyncServer.cpp
76 lines (43 loc) · 1.28 KB
/
TimeSyncServer.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
//rd timer
#include <chrono>
#include <thread>
#include <stdlib.h> //atol
#include <cmath> //lround
#include <iostream> //cout
#include <string.h> //strcomp
#include "TimeSync.h"
#include "DataWriter_Aux2Strings.h"
//this doesn't compile with timesync client
//long timestamp_master;
//
//long stepsCounter = 0;
//long delaySum = 0;
bool SendTimeSyncMessage(Mri::Aux2Strings auxMessage) {
Mri::Aux2Strings m_Message;
std::string s = std::to_string(GetTimestamp());
/*char* p = new char[s.length() + 1];
memcpy(p, s.c_str(), s.length() + 1);*/
m_Message.receiverId =auxMessage.senderId;
m_Message.senderId = THIS_APP_ID;
m_Message.tag =TAG_TIME_SYNC.c_str();
m_Message.str1 = auxMessage.str1;
m_Message.str2 = s.c_str();
int success = writer_global_aux2strings->write(m_Message, DDS::HANDLE_NIL);
if (success != DDS::RETCODE_OK) {
ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: TimeSync send message write returned %d.\n"), success));
}
//sender_clrd.sendMessage(m_Message);
return true;
}
bool ParseAux2StringsServer(Mri::Aux2Strings aux_message)
{
if (aux_message.receiverId!=THIS_APP_ID)
{
return true;
}
if (strcmp(aux_message.tag, TAG_TIME_SYNC.c_str()) == 0 )
{// time synchronization message
SendTimeSyncMessage(aux_message);
}
return true;
}