QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue, bool allCards) { switch (attribute) { case AttrTapped: { bool value = avalue == "1"; if (!(!value && allCards && doesntUntap)) setTapped(value); break; } case AttrAttacking: setAttacking(avalue == "1"); break; case AttrFaceDown: setFaceDown(avalue == "1"); break; case AttrColor: setColor(avalue); break; case AttrPT: setPT(avalue); return getPT(); case AttrAnnotation: setAnnotation(avalue); break; case AttrDoesntUntap: setDoesntUntap(avalue == "1"); break; } return avalue; }
void CardItem::processCardInfo(const ServerInfo_Card &info) { counters.clear(); const int counterListSize = info.counter_list_size(); for (int i = 0; i < counterListSize; ++i) { const ServerInfo_CardCounter &counterInfo = info.counter_list(i); counters.insert(counterInfo.id(), counterInfo.value()); } setId(info.id()); setName(QString::fromStdString(info.name())); setAttacking(info.attacking()); setFaceDown(info.face_down()); setPT(QString::fromStdString(info.pt())); setAnnotation(QString::fromStdString(info.annotation())); setColor(QString::fromStdString(info.color())); setTapped(info.tapped()); setDestroyOnZoneChange(info.destroy_on_zone_change()); setDoesntUntap(info.doesnt_untap()); }
static iONode __translate( obj inst, const iONode node ) { iODDXData data = Data((iODDX)inst); iONode rsp = NULL; TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "translating: %s", NodeOp.getName( node ) ); /* System command. */ if( StrOp.equals( NodeOp.getName( node ), wSysCmd.name() ) ) { const char* cmdstr = wSysCmd.getcmd( node ); TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "translating: cmd=%s", cmdstr ); if( StrOp.equals( cmdstr, wSysCmd.stop ) || StrOp.equals( cmdstr, wSysCmd.ebreak ) ) { stop_voltage(inst); } else if( StrOp.equals( cmdstr, wSysCmd.go ) ) { start_voltage(inst); } } /* Signal command. */ else if( StrOp.equals( NodeOp.getName( node ), wSignal.name() ) ) { TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "Signal commands are no longer supported at this level." ); } /* Output command. */ else if( StrOp.equals( NodeOp.getName( node ), wOutput.name() ) ) { int action = StrOp.equals( wOutput.getcmd( node ), wOutput.on ) ? 0x01:0x00; int addr = wOutput.getaddr( node ); int port = wOutput.getport( node ); int gate = wOutput.getgate( node ); if( port == 0 ) AddrOp.fromFADA( addr, &addr, &port, &gate ); else if( addr == 0 && port > 0 ) AddrOp.fromPADA( port, &addr, &port ); TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "co addr=%d port=%d gate=%d action=%d", addr, port, gate, action ); __accessory(inst, addr, port, gate, action, wOutput.getprot( node )); } /* Sensor command. */ else if( StrOp.equals( NodeOp.getName( node ), wFeedback.name() ) ) { int addr = wFeedback.getaddr( node ); Boolean state = wFeedback.isstate( node ); TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "simulate fb addr=%d state=%s", addr, state?"true":"false" ); rsp = (iONode)NodeOp.base.clone( node ); } /* Switch command. */ else if( StrOp.equals( NodeOp.getName( node ), wSwitch.name() ) ) { int error = 0; tDelayedAccCmd *delayedCmd = NULL; int delay = data->swtime; int port = wSwitch.getport1( node ); int addr = wSwitch.getaddr1( node ); int action = 1; int gate = 0; if( port == 0 ) { int l_addr = addr; AddrOp.fromFADA( addr, &addr, &port, &gate ); TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sw FADA addr=%d converted to addr=%d port=%d gate=%d", l_addr, addr, port, gate ); } else if( addr == 0 && port > 0 ) { int l_port = port; AddrOp.fromPADA( port, &addr, &port ); TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sw PADA port=%d converted to addr=%d port=%d gate=%d", l_port, addr, port, gate ); } else { int l_addr = AddrOp.toFADA( addr, port, gate ); TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sw FADA would be addr=%d or addr=%d", l_addr, l_addr+1 ); } gate = StrOp.equals( wSwitch.getcmd( node ), wSwitch.turnout ) ? 0x00:0x01; /* to get two decouples at one address: */ if( StrOp.equals( wSwitch.gettype(node), wSwitch.decoupler ) ) gate = wSwitch.getgate1( node ); if( wSwitch.issinglegate( node ) ) { gate = wSwitch.getgate1( node ); delay = 0; if( StrOp.equals( wSwitch.getcmd( node ), wSwitch.straight ) ) action = 0; } TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sw addr=%d port=%d gate=%d", addr, port, gate ); if( wSwitch.isactdelay( node ) ) delay = wSwitch.getdelay( node ); __accessory(inst, addr, port, gate, action, wSwitch.getprot( node )); if( delay > 0 ) { delayedCmd = (tDelayedAccCmd*)allocMem(sizeof(tDelayedAccCmd)); if (delayedCmd) { delayedCmd->acc_p=wSwitch.getprot( node )[0]; delayedCmd->acc_addr=addr; delayedCmd->acc_port=port; delayedCmd->acc_gate=gate; delayedCmd->action=0; delayedCmd->delay=delay; delayedCmd->busnr=-1; delayedCmd->devicegroup=-1; data->swReset = ThreadOp.inst( NULL, &thr_delayedAccCmd, delayedCmd ); ThreadOp.start( data->swReset ); } } } /* Loc command. */ else if( StrOp.equals( NodeOp.getName( node ), wLoc.name() )|| (( StrOp.equals( NodeOp.getName( node ), wFunCmd.name() ) ) && ( StrOp.equals( wLoc.getprot( node ), wLoc.prot_M ) && data->mm) ) ) { int addr = wLoc.getaddr( node ); int dir = wLoc.isdir( node ); int spcnt = wLoc.getspcnt( node ); int speed = 0; int info = 0; Boolean sw = wLoc.issw( node ); Boolean fn0 = wLoc.isfn( node ); Boolean fn1 = wFunCmd.isf1(node); Boolean fn2 = wFunCmd.isf2(node); Boolean fn3 = wFunCmd.isf3(node); Boolean fn4 = wFunCmd.isf4(node); Boolean fn5 = wFunCmd.isf5(node); Boolean fn6 = wFunCmd.isf6(node); Boolean fn7 = wFunCmd.isf7(node); Boolean fn8 = wFunCmd.isf8(node); int f[29]; MemOp.set(f, 0, 29); f[0] = fn0; f[1] = fn1; f[2] = fn2; f[3] = fn3; f[4] = fn4; f[5] = fn5; f[6] = fn6; f[7] = fn7; f[8] = fn8; if( spcnt > 127 ) spcnt = 127; if( StrOp.equals( wLoc.getV_mode( node ), wLoc.V_mode_percent ) ) speed = (wLoc.getV( node ) * spcnt) / 100; else if( wLoc.getV_max( node ) > 0 ) speed = (wLoc.getV( node ) * spcnt) / wLoc.getV_max( node ); if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_P ) ) { if( data->dcc ) wLoc.setprot( node, wLoc.prot_N ); else wLoc.setprot( node, wLoc.prot_M ); } if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_M ) && data->mm) { int protver = wLoc.getprotver( node ); TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "lc=%d prot=MM%d spd=%d dir=%s lights=%s f1=%s f2=%s f3=%s f4=%s", addr, protver, speed, dir?"forward":"reverse", fn0?"on":"off", fn1?"on":"off", fn2?"on":"off", fn3?"on":"off", fn4?"on":"off" ); switch( protver ) { case 1: comp_maerklin_1(addr, dir, speed, fn0); break; case 2: comp_maerklin_2(addr, dir, speed, fn0, fn1, fn2, fn3, fn4); break; case 3: comp_maerklin_3(addr, dir, speed, fn0, fn1, fn2, fn3, fn4); break; case 4: comp_maerklin_4(addr, dir, speed, fn0, fn1, fn2, fn3, fn4); break; case 5: comp_maerklin_5(addr, dir, speed, fn0, fn1, fn2, fn3, fn4); break; default: comp_maerklin_1(addr, dir, speed, fn0); break; } update_MaerklinPacketPool_Loco_Data(addr, dir, speed, fn0, fn1, fn2, fn3, fn4); } else if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_N ) && data->dcc ) { int rc = 0; TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "lc=%d prot=DCCS/%d spd=%d dir=%s lights=%s f1=%s f2=%s f3=%s f4=%s f5=%s f6=%s f7=%s f8=%s", addr, spcnt, speed, dir?"forward":"reverse", fn0?"on":"off", fn1?"on":"off", fn2?"on":"off", fn3?"on":"off", fn4?"on":"off", fn5?"on":"off", fn6?"on":"off", fn7?"on":"off", fn8?"on":"off" ); if( spcnt >= 127 ) { if( addr > 127 ) rc = comp_nmra_f4b14s128( addr, dir, speed, f); else rc = comp_nmra_f4b7s128( addr, dir, speed, f); } else { if( addr > 127 ) rc = comp_nmra_f4b14s28( addr, dir, speed, f); else rc = comp_nmra_f4b7s28( addr, dir, speed, f); } if( rc != 0 ) { TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "error sending DCC packet" ); } } else if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_L ) && data->dcc ) { int rc = 0; TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "lc=%d prot=DCCL/%d spd=%d dir=%s lights=%s f1=%s f2=%s f3=%s f4=%s f5=%s f6=%s f7=%s f8=%s", addr, spcnt, speed, dir?"forward":"reverse", fn0?"on":"off", fn1?"on":"off", fn2?"on":"off", fn3?"on":"off", fn4?"on":"off", fn5?"on":"off", fn6?"on":"off", fn7?"on":"off", fn8?"on":"off" ); if( spcnt >= 127 ) rc = comp_nmra_f4b14s128( addr, dir, speed, f); else rc = comp_nmra_f4b14s28( addr, dir, speed, f); if( rc != 0 ) { TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "error sending DCC packet" ); } } else { /* default */ TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "unsupported protocol [%s]", wLoc.getprot( node )); } } /* Function command. */ else if( StrOp.equals( NodeOp.getName( node ), wFunCmd.name() ) ) { int addr = wFunCmd.getaddr( node ); int info = 0; Boolean sw = wLoc.issw( node ); int fgroup = wFunCmd.getgroup(node); int f[29]; f[ 0] = wFunCmd.isf0(node); f[ 1] = wFunCmd.isf1(node); f[ 2] = wFunCmd.isf2(node); f[ 3] = wFunCmd.isf3(node); f[ 4] = wFunCmd.isf4(node); f[ 5] = wFunCmd.isf5(node); f[ 6] = wFunCmd.isf6(node); f[ 7] = wFunCmd.isf7(node); f[ 8] = wFunCmd.isf8(node); f[ 9] = wFunCmd.isf9(node); f[10] = wFunCmd.isf10(node); f[11] = wFunCmd.isf11(node); f[12] = wFunCmd.isf12(node); f[13] = wFunCmd.isf13(node); f[14] = wFunCmd.isf14(node); f[15] = wFunCmd.isf15(node); f[16] = wFunCmd.isf16(node); f[17] = wFunCmd.isf17(node); f[18] = wFunCmd.isf18(node); f[19] = wFunCmd.isf19(node); f[20] = wFunCmd.isf20(node); f[21] = wFunCmd.isf21(node); f[22] = wFunCmd.isf22(node); f[23] = wFunCmd.isf23(node); f[24] = wFunCmd.isf24(node); f[25] = wFunCmd.isf25(node); f[26] = wFunCmd.isf26(node); f[27] = wFunCmd.isf27(node); f[28] = wFunCmd.isf28(node); TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "lc=%d lights=%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", addr, f[0] ? "on":"off", f[1] ? "01":"--", f[2] ? "02":"--", f[3] ? "03":"--", f[4] ? "04":"--", f[5] ? "05":"--", f[6] ? "06":"--", f[7] ? "07":"--", f[8] ? "08":"--", f[9] ? "09":"--", f[10] ? "10":"--", f[11] ? "11":"--", f[12] ? "12":"--", f[13] ? "13":"--", f[14] ? "14":"--", f[15] ? "15":"--", f[16] ? "16":"--", f[17] ? "17":"--", f[18] ? "18":"--", f[19] ? "19":"--", f[20] ? "20":"--", f[21] ? "21":"--", f[22] ? "22":"--", f[23] ? "23":"--", f[24] ? "24":"--", f[25] ? "25":"--", f[26] ? "26":"--", f[27] ? "27":"--", f[28] ? "28":"--" ); if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_P ) ) { if( data->dcc ) wLoc.setprot( node, wLoc.prot_N ); else wLoc.setprot( node, wLoc.prot_M ); } if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_N ) ) { if( addr > 127 ) comp_nmra_fb14( addr, fgroup, f); else comp_nmra_fb7( addr, fgroup, f); } else if( StrOp.equals( wLoc.getprot( node ), wLoc.prot_L ) ) { comp_nmra_fb14( addr, fgroup, f); } else { /* default */ TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "unsupported protocol [%s]", wLoc.getprot( node )); } } /* Program command. */ else if( StrOp.equals( NodeOp.getName( node ), wProgram.name() ) ) { Boolean pom = wProgram.ispom( node ); rsp = NodeOp.inst( wProgram.name(), NULL, ELEMENT_NODE ); if( data->iid != NULL ) wProgram.setiid( rsp, data->iid ); wProgram.setcmd( rsp, wProgram.datarsp ); wProgram.setcv( rsp, wProgram.getcv( node ) ); if( wProgram.getcmd( node ) == wProgram.ptstat ) { } else if( wProgram.getcmd( node ) == wProgram.pton ) { /* stop s88 and set D7 high: */ setPT(inst, 1); data->ptflag = 1; rocrail_ddxStateChanged(inst); if (data->powerflag) { stop_voltage(inst); ThreadOp.sleep(100); } } else if( wProgram.getcmd( node ) == wProgram.ptoff ) { /* set D7 low and start s88: */ setPT(inst, 0); data->ptflag = 0; rocrail_ddxStateChanged(inst); } else if( wProgram.getcmd( node ) == wProgram.get && isPT(inst) ) { int cv = wProgram.getcv( node ); int idx = 0; int ack = 0; int value = -1; iONode ddx_ini = wDigInt.getddx( data->ini ); if (data->powerflag) { stop_voltage(inst); ThreadOp.sleep(100); } value = nmragetcvbyte(inst, cv-1); wProgram.setvalue( rsp, value ); } else if( wProgram.getcmd( node ) == wProgram.set && (pom?True:isPT(inst)) ) { int cv = wProgram.getcv( node ); int val = wProgram.getvalue( node ); int ack = 0; if( !pom && data->powerflag ){ stop_voltage(inst); ThreadOp.sleep(100); } ack = protocol_nmra_sm_write_cvbyte(inst, cv-1, val, pom); wProgram.setvalue( rsp, val ); if( ack != 1 && !pom ) wProgram.setvalue( rsp, -1 ); } } return rsp; }