w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RlinkCommandExpect.cpp
Go to the documentation of this file.
1// $Id: RlinkCommandExpect.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-21 1090 1.1.3 use constructor delegation
8// 2018-12-18 1089 1.1.2 use c++ style casts
9// 2017-04-07 868 1.1.1 Dump(): add detail arg
10// 2015-04-02 661 1.1 expect logic: remove stat from Expect, invert mask
11// 2011-11-28 434 1.0.1 Dump(): use proper cast for lp64 compatibility
12// 2011-03-12 368 1.0 Initial version
13// 2011-01-15 355 0.1 First draft
14// ---------------------------------------------------------------------------
15
20// debug
21#include <iostream>
22
23#include <algorithm>
24
26
27#include "librtools/RosFill.hpp"
30
31using namespace std;
32
38// all method definitions in namespace Retro
39namespace Retro {
40
41//------------------------------------------+-----------------------------------
43
45 : RlinkCommandExpect(0,0x0)
46{}
47
48//------------------------------------------+-----------------------------------
50
51RlinkCommandExpect::RlinkCommandExpect(uint16_t data, uint16_t datamsk)
52 : fDataVal(data),
53 fDataMsk(datamsk),
54 fBlockVal(),
55 fBlockMsk()
56{}
57
58//------------------------------------------+-----------------------------------
60
61RlinkCommandExpect::RlinkCommandExpect(const std::vector<uint16_t>& block)
62 : fDataVal(0),
63 fDataMsk(0x0),
64 fBlockVal(block),
65 fBlockMsk()
66{}
67
68//------------------------------------------+-----------------------------------
70
71RlinkCommandExpect::RlinkCommandExpect(const std::vector<uint16_t>& block,
72 const std::vector<uint16_t>& blockmsk)
73 : fDataVal(0),
74 fDataMsk(0x0),
75 fBlockVal(block),
76 fBlockMsk(blockmsk)
77{}
78
79//------------------------------------------+-----------------------------------
81
83{}
84
85//------------------------------------------+-----------------------------------
87
88bool RlinkCommandExpect::BlockCheck(size_t ind, uint16_t val) const
89{
90 if (ind >= fBlockVal.size()) return true;
91 uint16_t eval = fBlockVal[ind];
92 uint16_t emsk = (ind < fBlockMsk.size()) ? fBlockMsk[ind] : 0xffff;
93 return (val & emsk) == eval;
94}
95
96//------------------------------------------+-----------------------------------
98
99size_t RlinkCommandExpect::BlockCheck(const uint16_t* pval, size_t size) const
100{
101 size_t nerr = 0;
102 for (size_t i=0; i<size; i++) {
103 if (i >= fBlockVal.size()) break;
104 uint16_t eval = fBlockVal[i];
105 uint16_t emsk = (i < fBlockMsk.size()) ? fBlockMsk[i] : 0xffff;
106 if ((pval[i] & emsk) != eval) nerr += 1;
107 }
108
109 return nerr;
110}
111
112//------------------------------------------+-----------------------------------
114
116{
117 if (ind >= fBlockVal.size()) return false;
118 if (ind >= fBlockMsk.size()) return true;
119 return fBlockMsk[ind] != 0x0;
120}
121
122//------------------------------------------+-----------------------------------
124
125void RlinkCommandExpect::Dump(std::ostream& os, int ind, const char* text,
126 int /*detail*/) const
127{
128 RosFill bl(ind);
129 os << bl << (text?text:"--") << "RlinkCommandExpect @ " << this << endl;
130
131 os << bl << " fDataVal: " << RosPrintBvi(fDataVal,0) << endl;
132 os << bl << " fDataMsk: " << RosPrintBvi(fDataMsk,0) << endl;
133 os << bl << " fBlockVal.size: " << RosPrintf(fBlockVal.size(),"d",3) << endl;
134 os << bl << " fBlockMsk.size: " << RosPrintf(fBlockMsk.size(),"d",3) << endl;
135 if (fBlockVal.size() > 0) {
136 os << bl << " fBlockVal & Msk data: ";
137 size_t width = (fBlockMsk.size()>0) ? 9 : 4;
138 size_t ncol = max(size_t(1), (80-ind-4-5)/(width+1));
139 for (size_t i=0; i< fBlockVal.size(); i++) {
140 if (i%ncol == 0) os << "\n" << bl << " " << RosPrintf(i,"d",3) << ": ";
141
142 os << RosPrintBvi(fBlockVal[i],16);
143 if (fBlockMsk.size()>0) {
144 if (i<fBlockMsk.size() && fBlockMsk[i]!=0xffff) {
145 os << "," << RosPrintBvi(fBlockMsk[i],16);
146 } else {
147 os << " ";
148 }
149 }
150 os << " ";
151 }
152 os << endl;
153 }
154
155 return;
156}
157
158} // end namespace Retro
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
std::vector< uint16_t > fBlockVal
block value
std::vector< uint16_t > fBlockMsk
block mask
bool BlockCheck(size_t ind, uint16_t val) const
FIXME_docs.
RlinkCommandExpect()
Default constructor.
bool BlockIsChecked(size_t ind) const
FIXME_docs.
I/O appicator to generate fill characters.
Definition: RosFill.hpp:24
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Definition: RosPrintf.ipp:38
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47