ChimeraTK-DeviceAccess  03.18.00
DummyProtocol1.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 "DummyProtocol1.h"
5 
6 #include "RebotDummyServer.h"
7 
8 #include <boost/asio.hpp>
9 
10 namespace ChimeraTK {
11 
13  : DummyProtocol0(parent), _nextAddressInWords(0), _nWordsLeft(0) {}
14 
15  void DummyProtocol1::multiWordRead(std::vector<uint32_t>& buffer) {
17  }
18 
19  void DummyProtocol1::hello(std::vector<uint32_t>& /*buffer*/) {
20  // currently there is no check that the buffer is correct
21  // from protocol 2 magic work will be checked, and maybe client version
22 
24  }
25 
26  uint32_t DummyProtocol1::multiWordWrite(std::vector<uint32_t>& buffer) {
27  uint32_t addressInWords = buffer.at(1);
28  uint64_t addressInBytes = addressInWords * 4;
29  uint32_t nWordsTotal = buffer.at(2);
30 
31  if((buffer.size() - 3) < nWordsTotal) {
32  uint32_t nWordsInThisBuffer = buffer.size() - 3;
33  _nWordsLeft = nWordsTotal - nWordsInThisBuffer;
34  _nextAddressInWords = addressInWords + nWordsInThisBuffer;
35 
36  _parent._registerSpace->write(
37  BAR, addressInBytes, reinterpret_cast<int32_t*>(&(buffer.at(3))), 4 * nWordsInThisBuffer);
39  }
40  else { // all words in this buffer
41 
42  _parent._registerSpace->write(BAR, addressInBytes, reinterpret_cast<int32_t*>(&(buffer.at(3))), 4 * nWordsTotal);
43 
46  }
47  }
48 
49  uint32_t DummyProtocol1::continueMultiWordWrite(std::vector<uint32_t>& buffer) {
50  if(buffer.size() < _nWordsLeft) {
51  uint32_t nWordsInThisBuffer = buffer.size();
52 
53  _parent._registerSpace->write(BAR, static_cast<uint64_t>(_nextAddressInWords * 4),
54  reinterpret_cast<int32_t*>(buffer.data()), 4 * nWordsInThisBuffer);
55 
56  _nWordsLeft -= nWordsInThisBuffer;
57  _nextAddressInWords += nWordsInThisBuffer;
58 
60  }
61  else { // all words in this buffer
62 
63  _parent._registerSpace->write(BAR, static_cast<uint64_t>(_nextAddressInWords * 4),
64  reinterpret_cast<int32_t*>(buffer.data()), 4 * _nWordsLeft);
65 
67  _nWordsLeft = 0;
68 
71  }
72  }
73 
74 } // namespace ChimeraTK
RebotDummyServer.h
ChimeraTK::RebotDummySession
Definition: RebotDummyServer.h:24
ChimeraTK::RebotDummySession::_registerSpace
std::shared_ptr< DummyBackend > _registerSpace
Definition: RebotDummyServer.h:62
ChimeraTK::DummyProtocol0::_parent
RebotDummySession & _parent
Definition: DummyProtocol0.h:25
ChimeraTK::DummyProtocol1::_nextAddressInWords
uint32_t _nextAddressInWords
Definition: DummyProtocol1.h:28
DummyProtocol1.h
ChimeraTK::DummyProtocol1::hello
void hello(std::vector< uint32_t > &buffer) override
First protocol version that implements hello.
Definition: DummyProtocol1.cc:19
ChimeraTK::DummyProtocol0
Only put commands which don't exist in all versions, or behave differently.
Definition: DummyProtocol0.h:12
ChimeraTK::RebotDummySession::sendSingleWord
void sendSingleWord(int32_t response)
Definition: RebotDummyServer.cc:158
ChimeraTK::RebotDummySession::HELLO
static const uint32_t HELLO
Definition: RebotDummyServer.h:46
ChimeraTK::DummyProtocol1::multiWordRead
void multiWordRead(std::vector< uint32_t > &buffer) override
The multi word read is not limited in the size any more.
Definition: DummyProtocol1.cc:15
ChimeraTK::RebotDummySession::INSIDE_MULTI_WORD_WRITE
static const uint32_t INSIDE_MULTI_WORD_WRITE
Definition: RebotDummyServer.h:53
ChimeraTK::DummyProtocol1::_nWordsLeft
uint32_t _nWordsLeft
Definition: DummyProtocol1.h:29
ChimeraTK::DummyProtocol1::DummyProtocol1
DummyProtocol1(RebotDummySession &parent)
Definition: DummyProtocol1.cc:12
ChimeraTK::DummyProtocol1::multiWordWrite
uint32_t multiWordWrite(std::vector< uint32_t > &buffer) override
First protocol version that implements hello.
Definition: DummyProtocol1.cc:26
ChimeraTK::RebotDummySession::WRITE_SUCCESS_INDICATION
static const int32_t WRITE_SUCCESS_INDICATION
Definition: RebotDummyServer.h:38
ChimeraTK::DummyProtocol1::protocolVersion
uint32_t protocolVersion() const override
implement this for EVERY protocol version
Definition: DummyProtocol1.h:25
ChimeraTK::RebotDummySession::ACCEPT_NEW_COMMAND
static const uint32_t ACCEPT_NEW_COMMAND
Definition: RebotDummyServer.h:51
ChimeraTK::RebotDummySession::write
void write(std::vector< uint32_t > data)
Definition: RebotDummyServer.cc:152
ChimeraTK::DummyProtocol1::continueMultiWordWrite
uint32_t continueMultiWordWrite(std::vector< uint32_t > &buffer) override
Definition: DummyProtocol1.cc:49
ChimeraTK::DummyProtocol1::BAR
static const uint64_t BAR
Definition: DummyProtocol1.h:31
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::RebotDummySession::readRegisterAndSendData
void readRegisterAndSendData(std::vector< uint32_t > &buffer)
Definition: RebotDummyServer.cc:132
ChimeraTK::RebotDummySession::REBOT_MAGIC_WORD
static const uint32_t REBOT_MAGIC_WORD
Definition: RebotDummyServer.h:48