ChimeraTK-DeviceAccess  03.18.00
RebotProtocol1.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
4 #include "RebotProtocol1.h"
5 
6 #include "Connection.h"
8 
9 namespace ChimeraTK {
10  using namespace Rebot;
11 
12  RebotProtocol1::RebotProtocol1(boost::shared_ptr<Connection>& tcpCommunicator)
13  : RebotProtocol0(tcpCommunicator), _lastSendTime(std::chrono::steady_clock::now()) {
14  // Setting the time stamp to now() is sufficient in precision.
15  // We know that the server has just replied to the hello before this class was
16  // created.
17  }
18 
19  void RebotProtocol1::read(uint32_t addressInBytes, int32_t* data, size_t sizeInBytes) {
20  // locking is happening in the backend
21  // check for isOpen() is happening in the backend which does the bookkeeping
22 
23  RegisterInfo registerInfo(addressInBytes, sizeInBytes);
24  // Resolution of timing is sufficient if we set the timestamp here
25  // We just send one read request at the beginning.
27  fetchFromRebotServer(registerInfo.addressInWords, registerInfo.nWords, data);
28  }
29 
30  void RebotProtocol1::write(uint32_t addressInBytes, int32_t const* data, size_t sizeInBytes) {
31  RegisterInfo registerInfo(addressInBytes, sizeInBytes);
32  std::vector<uint32_t> writeCommandPacket;
33  writeCommandPacket.push_back(MULTI_WORD_WRITE);
34  writeCommandPacket.push_back(registerInfo.addressInWords);
35  writeCommandPacket.push_back(registerInfo.nWords);
36  for(unsigned int i = 0; i < registerInfo.nWords; ++i) {
37  writeCommandPacket.push_back(data[i]);
38  }
39  // Again we timestamp here. Technically the comminucator might send muptilple
40  // packets, but it is sufficient to reemember that we triggered it here.
42  _tcpCommunicator->write(writeCommandPacket);
43  // FIXME: this returns std::vector<int32_t> of length 1. Do error handling!
44  (void)_tcpCommunicator->read(1);
45  }
46 
48  _tcpCommunicator->write(std::vector<uint32_t>({HELLO_TOKEN, MAGIC_WORD, CLIENT_PROTOCOL_VERSION}));
49  // don't evaluate. The other side is sending an error anyway in this protocol
50  // version
51  _tcpCommunicator->read(3);
52  }
53 
54 } // namespace ChimeraTK
ChimeraTK::RebotProtocol0::_tcpCommunicator
boost::shared_ptr< Rebot::Connection > _tcpCommunicator
Definition: RebotProtocol0.h:33
ChimeraTK::RebotProtocol0
Definition: RebotProtocol0.h:16
ChimeraTK::RebotProtocol1::_lastSendTime
std::chrono::time_point< std::chrono::steady_clock > _lastSendTime
No need to make it atomic (time_points cannot be because they are not trivially copyable).
Definition: RebotProtocol1.h:24
ChimeraTK::testable_rebot_sleep::now
boost::chrono::steady_clock::time_point now()
Definition: testableRebotSleep.cc:7
RebotProtocol1.h
ChimeraTK::RebotProtocol1::write
virtual void write(uint32_t addressInBytes, int32_t const *data, size_t sizeInBytes) override
Definition: RebotProtocol1.cc:30
ChimeraTK::RebotProtocol1::RebotProtocol1
RebotProtocol1(boost::shared_ptr< Rebot::Connection > &tcpCommunicator)
Definition: RebotProtocol1.cc:12
ChimeraTK::RebotProtocol0::RegisterInfo
Definition: RebotProtocol0.h:24
Connection.h
ChimeraTK::RebotProtocol0::fetchFromRebotServer
void fetchFromRebotServer(uint32_t wordAddress, uint32_t numberOfWords, int32_t *dataLocation) const
Definition: RebotProtocol0.cc:66
ChimeraTK::RebotProtocol1::read
virtual void read(uint32_t addressInBytes, int32_t *data, size_t sizeInBytes) override
Definition: RebotProtocol1.cc:19
ChimeraTK::RebotProtocol1::sendHeartbeat
virtual void sendHeartbeat() override
Definition: RebotProtocol1.cc:47
ChimeraTK::RebotProtocol0::RegisterInfo::nWords
uint32_t nWords
Definition: RebotProtocol0.h:26
ChimeraTK::RebotProtocol0::RegisterInfo::addressInWords
uint32_t addressInWords
Definition: RebotProtocol0.h:25
ChimeraTK
Definition: DummyBackend.h:16
RebotProtocolDefinitions.h