w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RlinkCommandList.cpp
Go to the documentation of this file.
1// $Id: RlinkCommandList.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-23 1091 1.4.2 AddWblk(): add move version
8// 2018-12-07 1077 1.4.1 SetLastExpectBlock: add move versions
9// 2018-12-01 1076 1.4 use unique_ptr
10// 2018-10-28 1062 1.3.3 replace boost/foreach
11// 2018-09-16 1047 1.3.2 coverity fixup (uninitialized scalar)
12// 2017-04-02 865 1.3.1 Dump(): add detail arg
13// 2015-04-02 661 1.3 expect logic: add SetLastExpect methods
14// 2014-11-23 606 1.2 new rlink v4 iface
15// 2014-08-02 576 1.1 rename LastExpect->SetLastExpect
16// 2013-05-06 495 1.0.3 add RlinkContext to Print() args
17// 2013-02-03 481 1.0.2 use Rexception
18// 2011-04-25 380 1.0.1 use boost/foreach
19// 2011-03-05 366 1.0 Initial version
20// 2011-01-15 355 0.1 First draft
21// ---------------------------------------------------------------------------
22
27#include <string>
28
29#include "RlinkCommandList.hpp"
30
32#include "librtools/RosFill.hpp"
34
35using namespace std;
36
42// all method definitions in namespace Retro
43namespace Retro {
44
45//------------------------------------------+-----------------------------------
47
49 : fList(),
50 fLaboIndex(-1)
51{
52 fList.reserve(16); // should prevent most re-alloc's
53}
54
55//------------------------------------------+-----------------------------------
57
59 : fList(),
60 fLaboIndex(-1)
61{
62 operator=(rhs);
63}
64
65//------------------------------------------+-----------------------------------
67
69{}
70
71//------------------------------------------+-----------------------------------
73
75{
76 size_t ind = fList.size();
77 fList.push_back(move(upcmd));
78 return ind;
79}
80
81//------------------------------------------+-----------------------------------
83
85{
86 return AddCommand(cmd_uptr_t(new RlinkCommand(cmd)));
87}
88
89//------------------------------------------+-----------------------------------
91
93{
94 size_t ind = fList.size();
95 for (auto& upcmd: clist.fList) AddCommand(*upcmd);
96 return ind;
97}
98
99//------------------------------------------+-----------------------------------
101
102size_t RlinkCommandList::AddRreg(uint16_t addr)
103{
104 cmd_uptr_t upcmd(new RlinkCommand());
105 upcmd->CmdRreg(addr);
106 return AddCommand(move(upcmd));
107}
108
109//------------------------------------------+-----------------------------------
111
112size_t RlinkCommandList::AddRblk(uint16_t addr, size_t size)
113{
114 cmd_uptr_t upcmd(new RlinkCommand());
115 upcmd->CmdRblk(addr, size);
116 return AddCommand(move(upcmd));
117}
118
119//------------------------------------------+-----------------------------------
121
122size_t RlinkCommandList::AddRblk(uint16_t addr, uint16_t* block, size_t size)
123{
124 cmd_uptr_t upcmd(new RlinkCommand());
125 upcmd->CmdRblk(addr, block, size);
126 return AddCommand(move(upcmd));
127}
128
129//------------------------------------------+-----------------------------------
131
132size_t RlinkCommandList::AddWreg(uint16_t addr, uint16_t data)
133{
134 cmd_uptr_t upcmd(new RlinkCommand());
135 upcmd->CmdWreg(addr, data);
136 return AddCommand(move(upcmd));
137}
138
139//------------------------------------------+-----------------------------------
141
142size_t RlinkCommandList::AddWblk(uint16_t addr,
143 const std::vector<uint16_t>& block)
144{
145 cmd_uptr_t upcmd(new RlinkCommand());
146 upcmd->CmdWblk(addr, block);
147 return AddCommand(move(upcmd));
148}
149
150//------------------------------------------+-----------------------------------
152
153size_t RlinkCommandList::AddWblk(uint16_t addr, std::vector<uint16_t>&& block)
154{
155 cmd_uptr_t upcmd(new RlinkCommand());
156 upcmd->CmdWblk(addr, move(block));
157 return AddCommand(move(upcmd));
158}
159
160//------------------------------------------+-----------------------------------
162
163size_t RlinkCommandList::AddWblk(uint16_t addr, const uint16_t* block,
164 size_t size)
165{
166 cmd_uptr_t upcmd(new RlinkCommand());
167 upcmd->CmdWblk(addr, block, size);
168 return AddCommand(move(upcmd));
169}
170
171//------------------------------------------+-----------------------------------
173
175{
176 cmd_uptr_t upcmd(new RlinkCommand());
177 upcmd->CmdLabo();
178 return AddCommand(move(upcmd));
179}
180
181//------------------------------------------+-----------------------------------
183
185{
186 cmd_uptr_t upcmd(new RlinkCommand());
187 upcmd->CmdAttn();
188 return AddCommand(move(upcmd));
189}
190
191//------------------------------------------+-----------------------------------
193
194size_t RlinkCommandList::AddInit(uint16_t addr, uint16_t data)
195{
196 cmd_uptr_t upcmd(new RlinkCommand());
197 upcmd->CmdInit(addr, data);
198 return AddCommand(move(upcmd));
199}
200
201//------------------------------------------+-----------------------------------
203
204void RlinkCommandList::SetLastExpectStatus(uint8_t stat, uint8_t statmsk)
205{
206 if (fList.empty())
207 throw Rexception("RlinkCommandList::SetLastExpectStatus()",
208 "Bad state: list empty");
209 fList.back()->SetExpectStatus(stat, statmsk);
210 return;
211}
212
213//------------------------------------------+-----------------------------------
215
216void RlinkCommandList::SetLastExpectData(uint16_t data, uint16_t datamsk)
217{
218 if (fList.empty())
219 throw Rexception("RlinkCommandList::SetLastExpectData()",
220 "Bad state: list empty");
221 RlinkCommand& cmd = *fList.back();
222 cmd.EnsureExpect().SetData(data, datamsk);
223 return;
224}
225
226//------------------------------------------+-----------------------------------
228
230{
231 if (fList.empty())
232 throw Rexception("RlinkCommandList::SetLastExpectDone()",
233 "Bad state: list empty");
234 RlinkCommand& cmd = *fList.back();
235 cmd.EnsureExpect().SetDone(done);
236 return;
237}
238
239//------------------------------------------+-----------------------------------
241
242void RlinkCommandList::SetLastExpectBlock(const std::vector<uint16_t>& block)
243{
244 if (fList.empty())
245 throw Rexception("RlinkCommandList::SetLastExpectBlock()",
246 "Bad state: list empty");
247 RlinkCommand& cmd = *fList.back();
248 cmd.EnsureExpect().SetBlock(block);
249 return;
250}
251
252//------------------------------------------+-----------------------------------
254
255void RlinkCommandList::SetLastExpectBlock(std::vector<uint16_t>&& block)
256{
257 if (fList.empty())
258 throw Rexception("RlinkCommandList::SetLastExpectBlock()",
259 "Bad state: list empty");
260 RlinkCommand& cmd = *fList.back();
261 cmd.EnsureExpect().SetBlock(move(block));
262 return;
263}
264
265//------------------------------------------+-----------------------------------
267
268void RlinkCommandList::SetLastExpectBlock(const std::vector<uint16_t>& block,
269 const std::vector<uint16_t>& blockmsk)
270{
271 if (fList.empty())
272 throw Rexception("RlinkCommandList::SetLastExpectBlock()",
273 "Bad state: list empty");
274 RlinkCommand& cmd = *fList.back();
275 cmd.EnsureExpect().SetBlock(block, blockmsk);
276 return;
277}
278
279//------------------------------------------+-----------------------------------
281
282void RlinkCommandList::SetLastExpectBlock(std::vector<uint16_t>&& block,
283 std::vector<uint16_t>&& blockmsk)
284{
285 if (fList.empty())
286 throw Rexception("RlinkCommandList::SetLastExpectBlock()",
287 "Bad state: list empty");
288 RlinkCommand& cmd = *fList.back();
289 cmd.EnsureExpect().SetBlock(move(block), move(blockmsk));
290 return;
291}
292
293//------------------------------------------+-----------------------------------
295
297{
298 if (fList.empty())
299 throw Rexception("RlinkCommandList::SetLastExpect()",
300 "Bad state: list empty");
301 fList.back()->SetExpect(move(upexp));
302 return;
303}
304
305//------------------------------------------+-----------------------------------
307
309{
310 fList.clear();
311 fLaboIndex = -1;
312 return;
313}
314
315//------------------------------------------+-----------------------------------
317
318void RlinkCommandList::Print(std::ostream& os,
319 const RlinkAddrMap* pamap, size_t abase,
320 size_t dbase, size_t sbase) const
321{
322 for (auto& upcmd: fList) upcmd->Print(os, pamap, abase, dbase, sbase);
323 return;
324}
325
326//------------------------------------------+-----------------------------------
328
329void RlinkCommandList::Dump(std::ostream& os, int ind, const char* text,
330 int detail) const
331{
332 RosFill bl(ind);
333 os << bl << (text?text:"--") << "RlinkCommandList @ " << this << endl;
334
335 os << bl << " fLaboIndex: " << fLaboIndex << endl;
336 for (size_t i=0; i<Size(); i++) {
337 if (detail >= 0) { // full dump
338 string pref("fList[");
339 pref << RosPrintf(i) << RosPrintf("]: ");
340 fList[i]->Dump(os, ind+2, pref.c_str());
341 } else { // compact dump
342 os << bl << " [" << RosPrintf(i,"d",2) << "]: "
343 << fList[i]->CommandInfo() << endl;
344 }
345 }
346
347 return;
348}
349
350//------------------------------------------+-----------------------------------
352
355{
356 if (&rhs == this) return *this;
357
358 fList.clear();
359 for (auto& upcmd: rhs.fList) AddCommand(*upcmd);
360 fLaboIndex = rhs.fLaboIndex;
361 return *this;
362}
363
364//------------------------------------------+-----------------------------------
366
368{
369 return *fList.at(ind);
370}
371
372//------------------------------------------+-----------------------------------
374
376{
377 return *fList.at(ind);
378}
379
380} // end namespace Retro
FIXME_docs.
Definition: Rexception.hpp:29
void SetDone(uint16_t done, bool check=true)
FIXME_docs.
void SetBlock(const std::vector< uint16_t > &block)
FIXME_docs.
void SetData(uint16_t data, uint16_t datamsk=0)
FIXME_docs.
size_t AddWreg(uint16_t addr, uint16_t data)
FIXME_docs.
size_t AddCommand(cmd_uptr_t &&upcmd)
FIXME_docs.
RlinkCommandList & operator=(const RlinkCommandList &rhs)
FIXME_docs.
int fLaboIndex
index of active labo (-1 if no)
size_t AddAttn()
FIXME_docs.
size_t Size() const
FIXME_docs.
size_t AddInit(uint16_t addr, uint16_t data)
FIXME_docs.
size_t AddRblk(uint16_t addr, size_t size)
FIXME_docs.
RlinkCommandList()
Default constructor.
void SetLastExpectStatus(uint8_t stat, uint8_t statmsk=0xff)
FIXME_docs.
void SetLastExpectBlock(const std::vector< uint16_t > &block)
FIXME_docs.
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
size_t AddWblk(uint16_t addr, const std::vector< uint16_t > &block)
FIXME_docs.
RlinkCommand & operator[](size_t ind)
FIXME_docs.
size_t AddRreg(uint16_t addr)
FIXME_docs.
std::unique_ptr< RlinkCommand > cmd_uptr_t
void Print(std::ostream &os, const RlinkAddrMap *pamap=0, size_t abase=16, size_t dbase=16, size_t sbase=16) const
FIXME_docs.
std::vector< cmd_uptr_t > fList
vector of commands
void SetLastExpectDone(uint16_t done)
FIXME_docs.
void SetLastExpect(exp_uptr_t &&upexp)
FIXME_docs.
std::unique_ptr< RlinkCommandExpect > exp_uptr_t
void SetLastExpectData(uint16_t data, uint16_t datamsk=0xffff)
FIXME_docs.
size_t AddLabo()
FIXME_docs.
RlinkCommandExpect & EnsureExpect()
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