69using namespace std::placeholders;
107 for (
size_t i=0; i<8; i++) {
146 fSets.
Add<
const string&> (
"logfile",
182 if (!
Obj().Open(path, emsg))
return args.
Quit(emsg);
196 if (!
Obj().IsOpen())
return args.
Quit(
"-E: port not open");
207 if (!
Obj().IsOpen())
return args.
Quit(
"-E: port not open");
208 if (
Obj().LinkInitDone())
return args.
Quit(
"-E: already initialized");
210 if (!
Obj().LinkInit(emsg))
return args.
Quit(emsg);
219 static RtclNameSet optset(
"-rreg|-rblk|-wreg|-wblk|-labo|-attn|-init|"
220 "-edata|-edone|-estat|"
221 "-estaterr|-estatnak|-estattout|"
222 "-print|-dump|-rlist");
224 Tcl_Interp* interp = args.
Interp();
230 vector<string> vardata;
231 vector<string> varstat;
236 while (args.
NextOpt(opt, optset)) {
238 size_t lsize = clist.
Size();
239 if (opt ==
"-rreg") {
245 }
else if (opt ==
"-rblk") {
248 if (!args.
GetArg(
"bsize", bsize, 1,
Obj().BlockSizeMax()))
return kERR;
251 clist.
AddRblk(addr,
size_t(bsize));
253 }
else if (opt ==
"-wreg") {
260 }
else if (opt ==
"-wblk") {
261 vector<uint16_t> block;
263 if (!args.
GetArg(
"data", block, 1,
Obj().BlockSizeMax()))
return kERR;
265 clist.
AddWblk(addr, move(block));
267 }
else if (opt ==
"-labo") {
272 }
else if (opt ==
"-attn") {
277 }
else if (opt ==
"-init") {
284 }
else if (opt ==
"-edata") {
287 vector<uint16_t> data;
288 vector<uint16_t> mask;
289 size_t bsize = clist[lsize-1].BlockSize();
290 if (!args.
GetArg(
"data", data, 0, bsize))
return kERR;
291 if (!args.
GetArg(
"??mask", mask, 0, bsize))
return kERR;
295 uint16_t mask=0xffff;
297 if (!args.
GetArg(
"??mask", mask))
return kERR;
301 }
else if (opt ==
"-edone") {
305 uint8_t cmd = clist[lsize-1].Command();
310 return args.
Quit(
"-E: -edone allowed only after -rblk,-wblk");
313 }
else if (opt ==
"-estat") {
318 if (!args.
GetArg(
"??mask", mask))
return kERR;
321 }
else if (opt ==
"-estaterr" ||
322 opt ==
"-estatnak" ||
323 opt ==
"-estattout") {
334 }
else if (opt ==
"-print") {
336 if (!args.
GetArg(
"??varRes", varprint))
return kERR;
337 }
else if (opt ==
"-dump") {
339 if (!args.
GetArg(
"??varRes", vardump))
return kERR;
340 }
else if (opt ==
"-rlist") {
342 if (!args.
GetArg(
"??varRes", varlist))
return kERR;
348 if (varprint ==
"-") nact += 1;
349 if (vardump ==
"-") nact += 1;
350 if (varlist ==
"-") nact += 1;
353 "-E: more that one of -print,-dump,-rlist without target variable found");
356 if (clist.
Size() == 0)
return kOK;
360 if (!
Obj().Exec(clist, emsg))
return args.
Quit(emsg);
362 for (
size_t icmd=0; icmd<clist.
Size(); icmd++) {
365 if (icmd<vardata.size() && !vardata[icmd].empty()) {
367 vector<uint16_t> retstat;
373 pres = Tcl_NewIntObj(
int(cmd.
Data()));
382 if (icmd<varstat.size() && !varstat[icmd].empty()) {
388 if (!varprint.empty()) {
390 clist.
Print(sos, &
Obj().AddrMap(),
Obj().LogBaseAddr(),
391 Obj().LogBaseData(),
Obj().LogBaseStat());
396 if (!vardump.empty()) {
403 if (!varlist.empty()) {
404 RtclOPtr prlist(Tcl_NewListObj(0,
nullptr));
405 for (
size_t icmd=0; icmd<clist.
Size(); icmd++) {
408 RtclOPtr pres(Tcl_NewListObj(0,
nullptr));
410 Tcl_ListObjAppendElement(
nullptr, pres,
411 Tcl_NewIntObj(
int(cmd.
Request())));
412 Tcl_ListObjAppendElement(
nullptr, pres, Tcl_NewIntObj(
int(cmd.
Flags())));
413 Tcl_ListObjAppendElement(
nullptr, pres, Tcl_NewIntObj(
int(cmd.
Status())));
419 Tcl_ListObjAppendElement(
nullptr, pres,
420 Tcl_NewIntObj(
int(cmd.
Data())));
424 Tcl_ListObjAppendElement(
nullptr, pres,
428 Tcl_ListObjAppendElement(
nullptr, prlist, pres);
441 static RtclNameSet optset(
"-name|-testname|-testaddr|-insert|-erase|"
450 if (args.
NextOpt(opt, optset)) {
451 if (opt ==
"-name") {
455 if(addrmap.
Find(addr, tstname)) {
462 }
else if (opt ==
"-testname") {
467 bool found = addrmap.
Find(name, tstaddr);
469 if (tstaddr != addr) found =
false;
473 }
else if (opt ==
"-testaddr") {
479 }
else if (opt ==
"-insert") {
485 if (Tcl_GetIntFromObj(
nullptr, args[args.
NDone()-1], &tstint) ==
kOK)
486 return args.
Quit(
string(
"-E: name should not look like an int but '")+
490 if (addrmap.
Find(name, tstaddr))
491 return args.
Quit(
string(
"-E: mapping already defined for '")+name+
"'");
492 if (addrmap.
Find(addr, tstname))
493 return args.
Quit(
string(
"-E: mapping already defined for address '") +
497 }
else if (opt ==
"-erase") {
500 if (!
Obj().AddrMapErase(name))
501 return args.
Quit(
string(
"-E: no mapping defined for '") + name +
"'");
503 }
else if (opt ==
"-clear") {
507 }
else if (opt ==
"-print") {
519 if(addrmap.
Find(name, tstaddr)) {
522 return args.
Quit(
string(
"-E: no mapping defined for '") + name +
"'");
526 RtclOPtr plist(Tcl_NewListObj(0,
nullptr));
527 const auto amap = addrmap.
Amap();
528 for (
auto& o: amap) {
530 tpair[0] = Tcl_NewIntObj(o.first);
531 tpair[1] = Tcl_NewStringObj(o.second.c_str(),o.second.length());
532 Tcl_ListObjAppendElement(
nullptr, plist, Tcl_NewListObj(2, tpair));
551 while (args.
NextOpt(opt, optset)) {
552 if (opt ==
"-clear") fclr =
true;
553 if (opt ==
"-increment") finc =
true;
571 if (!args.
GetArg(
"tout", dtout, 0.0))
return kERR;
572 if (!args.
GetArg(
"??varApat", rvn_apat))
return kERR;
581 if (rvn_apat.length()) {
583 Tcl_NewIntObj(
int(apat))))
return kERR;
587 return args.
Quit(emsg);
588 }
else if (irc == -1) {
589 if (
Obj().PrintLevel() >= 1) {
591 lmsg <<
"-- wtlam to=" <<
RosPrintf(dtout,
"f", 0,3)
592 <<
" FAIL timeout" << endl;
599 if (
Obj().PrintLevel() >= 3) {
601 lmsg <<
"-- wtlam apat=" <<
RosPrintf(apat,
"x0",4);
603 lmsg <<
" to=0 harvest only";
605 lmsg <<
" to=" <<
RosPrintf(dtout,
"f", 0,3)
606 <<
" T=" <<
RosPrintf(
double(twait),
"f", 0,3);
608 lmsg <<
" OK" << endl;
620 static RtclNameSet optset(
"-rlmon|-rlbmon|-rbmon|-sbcntl|-sbdata");
627 if (args.
NextOpt(opt, optset)) {
628 if (opt ==
"-rlmon") {
629 if (!args.
GetArg(
"val", data, 1))
return kERR;
632 if (!
Obj().SndOob(0x00, (addr<<8)+data, emsg))
return args.
Quit(emsg);
634 }
else if (opt ==
"-rlbmon") {
635 if (!args.
GetArg(
"val", data, 1))
return kERR;
638 if (!
Obj().SndOob(0x00, (addr<<8)+data, emsg))
return args.
Quit(emsg);
640 }
else if (opt ==
"-rbmon") {
641 if (!args.
GetArg(
"val", data, 1))
return kERR;
644 if (!
Obj().SndOob(0x00, (addr<<8)+data, emsg))
return args.
Quit(emsg);
646 }
else if (opt ==
"-sbcntl") {
647 if (!args.
GetArg(
"bit", addr, 15))
return kERR;
648 if (!args.
GetArg(
"val", data, 1))
return kERR;
650 if (!
Obj().SndOob(0x00, (addr<<8)+data, emsg))
return args.
Quit(emsg);
652 }
else if (opt ==
"-sbdata") {
653 if (!args.
GetArg(
"bit", addr, 0x0ff))
return kERR;
656 if (!
Obj().SndOob(addr, data, emsg))
return args.
Quit(emsg);
660 "-E: missing option, one of -rlmon,-rbmon,-sbcntl,-sbdata");
671 if (!(
Obj().HasPort() &&
672 Obj().Port().IsOpen()))
return args.
Quit(
"-E: port not open");
681 if (!(
Obj().HasPort() &&
682 Obj().Port().IsOpen()))
return args.
Quit(
"-E: port not open");
694 if (!(
Obj().HasPort() &&
695 Obj().Port().IsOpen()))
return args.
Quit(
"-E: port not open");
709 if (
Obj().HasPort()) {
720 static RtclNameSet optset(
"-bare|-info|-warn|-error|-fatal");
724 while (args.
NextOpt(opt, optset)) {
725 if (opt ==
"-bare") fbare =
true;
726 if (opt ==
"-info") tag =
'I';
727 if (opt ==
"-warn") tag =
'W';
728 if (opt ==
"-error") tag =
'E';
729 if (opt ==
"-fatal") tag =
'F';
736 if (
Obj().PrintLevel() != 0 ||
737 Obj().DumpLevel() != 0 ||
738 Obj().TraceLevel() != 0) {
771 Obj().
Dump(sos, 0,
"", detail);
782 lock_guard<RlinkConnect> lock(
Obj());
792 lock_guard<RlinkConnect> lock(
Obj());
804 sos <<
"print base: " <<
"addr " <<
RosPrintf(
Obj().LogBaseAddr(),
"d", 2)
806 <<
" stat " <<
RosPrintf(
Obj().LogBaseStat(),
"d", 2) << endl;
825 if (Tcl_GetIntFromObj(
nullptr, pobj, &tstint) ==
kOK) {
826 if (tstint >= 0 && tstint <= 0xffff) {
827 addr = uint16_t(tstint);
830 "' for 'addr' out of range 0...0xffff",
nullptr);
835 string name(Tcl_GetString(pobj));
837 if (
Obj().AddrMap().Find(name, tstaddr)) {
841 Tcl_GetString(pobj),
"'",
nullptr);
854 std::vector<std::string>& varname)
856 while (varname.size() < nind+1) varname.push_back(
string());
858 if (!args.
GetArg(argname, name))
return false;
861 if (isdigit(c) || c==
'+' || c==
'-' ) {
862 args.
AppendResult(
"-E: invalid variable name '", name.c_str(),
863 "': looks like a number",
nullptr);
868 varname[nind] = name;
878 if (!args.
Config(
"??base", tmp, 16, 2))
return false;
879 if (tmp != base && tmp != 2 && tmp !=8 && tmp != 16) {
880 args.
AppendResult(
"-E: base must be 2, 8, or 16, found '",
894 if (clist.
Size() == 0) {
896 "not allowed on empty command list",
nullptr);
const amap_t & Amap() const
FIXME_docs.
bool Find(const std::string &name, uint16_t &addr) const
FIXME_docs.
void Print(std::ostream &os, int ind=0) const
FIXME_docs.
size_t AddWreg(uint16_t addr, uint16_t data)
FIXME_docs.
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.
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.
size_t AddRreg(uint16_t addr)
FIXME_docs.
void Print(std::ostream &os, const RlinkAddrMap *pamap=0, size_t abase=16, size_t dbase=16, size_t sbase=16) const
FIXME_docs.
void SetLastExpectDone(uint16_t done)
FIXME_docs.
void SetLastExpectData(uint16_t data, uint16_t datamsk=0xffff)
FIXME_docs.
size_t AddLabo()
FIXME_docs.
uint16_t Data() const
FIXME_docs.
uint8_t Request() const
FIXME_docs.
static const uint8_t kCmdRblk
command code read block
static const uint8_t kStat_M_RbErr
stat: rberr flag set
uint8_t Status() const
FIXME_docs.
static const char * CommandName(uint8_t cmd)
FIXME_docs.
const std::vector< uint16_t > & Block() const
FIXME_docs.
static const uint8_t kStat_M_RbNak
stat: rbnak flag set
static const uint8_t kStat_M_RbTout
stat: rbtout flag set
uint8_t Command() const
FIXME_docs.
static const uint8_t kCmdRreg
command code read register
uint32_t Flags() const
FIXME_docs.
size_t BlockDone() const
FIXME_docs.
static const uint8_t kCmdAttn
command code get attention
static const uint8_t kCmdLabo
command code list abort
static const uint8_t kCmdWblk
command code write block
void SetTimeout(const Rtime &timeout)
FIXME_docs.
void AddrMapClear()
FIXME_docs.
int WaitAttn(const Rtime &timeout, Rtime &twait, uint16_t &apat, RerrMsg &emsg)
Wait for an attention notify.
void SetLogFileName(const std::string &name)
FIXME_docs.
uint32_t LogBaseData() const
FIXME_docs.
void SetLogBaseAddr(uint32_t base)
FIXME_docs.
uint32_t LogBaseAddr() const
FIXME_docs.
bool AddrMapInsert(const std::string &name, uint16_t addr)
FIXME_docs.
static const uint16_t kSBCNTL_V_RLMON
SBCNTL: rlmon enable bit.
uint32_t SysId() const
FIXME_docs.
void SetLogBaseStat(uint32_t base)
FIXME_docs.
uint32_t PrintLevel() const
FIXME_docs.
size_t RbufSize() const
FIXME_docs.
const Rtime & Timeout() const
FIXME_docs.
void SetDumpLevel(uint32_t lvl)
FIXME_docs.
RlogFile & LogFile() const
FIXME_docs.
uint32_t LogBaseStat() const
FIXME_docs.
void Print(std::ostream &os) const
FIXME_docs.
RlinkContext & Context()
FIXME_docs.
static const uint16_t kSBCNTL_V_RLBMON
SBCNTL: rlbmon enable bit.
static const uint16_t kSBCNTL_V_RBMON
SBCNTL: rbmon enable bit.
size_t BlockSizeMax() const
FIXME_docs.
bool IsOpen() const
FIXME_docs.
uint32_t DumpLevel() const
FIXME_docs.
void SetLogBaseData(uint32_t base)
FIXME_docs.
uint32_t TraceLevel() const
FIXME_docs.
RlinkPort & Port()
FIXME_docs.
void SetPrintLevel(uint32_t lvl)
FIXME_docs.
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
size_t BlockSizePrudent() const
FIXME_docs.
bool HasRbmon() const
FIXME_docs.
uint32_t UsrAcc() const
FIXME_docs.
const RlinkAddrMap & AddrMap() const
FIXME_docs.
void SetTraceLevel(uint32_t lvl)
FIXME_docs.
bool LinkInitDone() const
FIXME_docs.
const std::string & LogFileName() const
FIXME_docs.
void SetStatusMask(uint8_t statmsk)
FIXME_docs.
void IncErrorCount(size_t inc=1)
FIXME_docs.
uint8_t StatusValue() const
FIXME_docs.
bool StatusIsChecked() const
FIXME_docs.
void ClearErrorCount()
FIXME_docs.
uint8_t StatusMask() const
FIXME_docs.
void SetStatusValue(uint8_t stat)
FIXME_docs.
const RparseUrl & Url() const
FIXME_docs.
const std::string & Name() const
FIXME_docs.
void Write(const std::string &str, char tag=0)
FIXME_docs.
const std::string & Url() const
FIXME_docs.
bool NextOpt(std::string &val)
FIXME_docs.
const char * PeekArgString(int rind) const
FIXME_docs.
void AppendResultLines(const std::string &str)
FIXME_docs.
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
bool Config(const char *name, std::string &val)
FIXME_docs.
void AppendResult(const char *str,...)
FIXME_docs.
bool OptValid() const
FIXME_docs.
int Quit(const std::string &str)
FIXME_docs.
void SetResult(const std::string &str)
FIXME_docs.
size_t NOptMiss() const
FIXME_docs.
size_t NDone() const
FIXME_docs.
Tcl_Interp * Interp() const
FIXME_docs.
bool AllDone()
FIXME_docs.
void AddMeth(const std::string &name, methfo_t &&methfo)
FIXME_docs.
bool GetArgsDump(RtclArgs &args, int &detail)
FIXME_docs.
int M_get(RtclArgs &args)
FIXME_docs.
void Add(const std::string &name, get_uptr_t &&upget)
FIXME_docs.
Implemenation (inline) of RtclOPtr.
Implemenation (all inline) of class RtclProxyOwned.
RlinkConnect & Obj()
FIXME_docs.
int M_set(RtclArgs &args)
FIXME_docs.
int M_print(RtclArgs &args)
FIXME_docs.
int M_wtlam(RtclArgs &args)
FIXME_docs.
bool GetAddr(RtclArgs &args, uint16_t &addr)
FIXME_docs.
int M_close(RtclArgs &args)
FIXME_docs.
int M_open(RtclArgs &args)
FIXME_docs.
int M_rawrblk(RtclArgs &args)
FIXME_docs.
int M_exec(RtclArgs &args)
FIXME_docs.
~RtclRlinkConnect()
Destructor.
bool ConfigBase(RtclArgs &args, uint32_t &base)
FIXME_docs.
int M_dump(RtclArgs &args)
FIXME_docs.
int M_oob(RtclArgs &args)
FIXME_docs.
RtclRlinkConnect(Tcl_Interp *interp, const char *name)
Default constructor.
bool ClistNonEmpty(RtclArgs &args, const RlinkCommandList &clist)
FIXME_docs.
int M_log(RtclArgs &args)
FIXME_docs.
bool GetVarName(RtclArgs &args, const char *argname, size_t nind, std::vector< std::string > &varname)
FIXME_docs.
int M_get(RtclArgs &args)
FIXME_docs.
int M_rawwblk(RtclArgs &args)
FIXME_docs.
int M_init(RtclArgs &args)
FIXME_docs.
int M_default(RtclArgs &args)
FIXME_docs.
int M_stats(RtclArgs &args)
FIXME_docs.
int M_rawread(RtclArgs &args)
FIXME_docs.
int M_errcnt(RtclArgs &args)
FIXME_docs.
int M_amap(RtclArgs &args)
FIXME_docs.
static int DoRawWblk(RtclArgs &args, RlinkPort &port)
FIXME_docs.
static int DoRawRblk(RtclArgs &args, RlinkPort &port, size_t &errcnt)
FIXME_docs.
static int DoRawRead(RtclArgs &args, RlinkPort &port)
FIXME_docs.
void Add(const std::string &name, set_uptr_t &&upset)
FIXME_docs.
int M_set(RtclArgs &args)
FIXME_docs.
static bool Exec(RtclArgs &args, const Context &cntx, Rstats &stats)
FIXME_docs.
static bool GetArgs(RtclArgs &args, Context &cntx)
FIXME_docs.
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.
bool SetVarOrResult(Tcl_Interp *interp, const std::string &varname, Tcl_Obj *pobj)
Tcl_Obj * NewLinesObj(const std::string &str)
bool SetVar(Tcl_Interp *interp, const std::string &varname, Tcl_Obj *pobj)
Tcl_Obj * NewListIntObj(const uint8_t *data, size_t size)
Declaration of class ReventLoop.