ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
9namespace 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.
26 _lastSendTime = std::chrono::steady_clock::now();
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.
41 _lastSendTime = std::chrono::steady_clock::now();
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
STL namespace.
void fetchFromRebotServer(uint32_t wordAddress, uint32_t numberOfWords, int32_t *dataLocation) const
boost::shared_ptr< Rebot::Connection > _tcpCommunicator
RebotProtocol1(boost::shared_ptr< Rebot::Connection > &tcpCommunicator)
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).
virtual void read(uint32_t addressInBytes, int32_t *data, size_t sizeInBytes) override
virtual void sendHeartbeat() override
virtual void write(uint32_t addressInBytes, int32_t const *data, size_t sizeInBytes) override