ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
10namespace 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
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
static const int32_t WRITE_SUCCESS_INDICATION
static const uint32_t INSIDE_MULTI_WORD_WRITE
static const uint32_t ACCEPT_NEW_COMMAND
static const uint32_t HELLO
void sendSingleWord(int32_t response)
void readRegisterAndSendData(std::vector< uint32_t > &buffer)
void write(std::vector< uint32_t > data)
std::shared_ptr< DummyBackend > _registerSpace
static const uint32_t REBOT_MAGIC_WORD
Only put commands which don't exist in all versions, or behave differently.
RebotDummySession & _parent
uint32_t multiWordWrite(std::vector< uint32_t > &buffer) override
First protocol version that implements hello.
uint32_t protocolVersion() const override
implement this for EVERY protocol version
static const uint64_t BAR
void multiWordRead(std::vector< uint32_t > &buffer) override
The multi word read is not limited in the size any more.
void hello(std::vector< uint32_t > &buffer) override
First protocol version that implements hello.
uint32_t continueMultiWordWrite(std::vector< uint32_t > &buffer) override
DummyProtocol1(RebotDummySession &parent)