Hi
Firstly I want to say thank you - this just works for producing packet wave forms that is enabling me to debug my receiver all at the 5V level at my desk...
I could not see any way to output the 28 speed step, so thought I would ask here, is there another branch (or fork) with it already supported?
For my work I have created two new "setThrottle" functions with the corresponding serial calls, using the letters 'y' and 'u'. These were not used and chosen as they are the next ones along on a keyboard.
Is this be the place to contribute to? Is there a more recent head? Would this be desired as a PR?
I've checked these outputs using a Saleae Logic with the DCCAnalyser plugin from: https://github.com/ejbergdk/DCCAnalyzer.git and they match the ECoS ESU Command Station.
I'll drop my code here should is be useful to anyone else / review (I'm not a SW engineer):
- Edit to PacketRegister.h
void setThrottle14(char *) volatile;
void setThrottle28(char *) volatile;
- Edit to SerialCommand.cpp
case 'y': // <y REGISTER CAB SPEED DIRECTION>
mRegs->setThrottle14(com+1);
break;
case 'u': // <u REGISTER CAB SPEED DIRECTION>
mRegs->setThrottle28(com+1);
break;
- Edit to PacketRegister.cpp
void RegisterList::setThrottle14(char *s) volatile{
byte b[5]; // save space for checksum byte
int nReg;
int cab;
int tSpeed;
int tDirection;
byte nB=0;
if(sscanf(s,"%d %d %d %d",&nReg,&cab,&tSpeed,&tDirection)!=4)
return;
if(nReg<1 || nReg>maxNumRegs)
return;
if(cab>127)
b[nB++]=highByte(cab) | 0xC0; // convert train number into a two-byte address
b[nB++]=lowByte(cab);
if(tSpeed>=15) // Over speed
return;
if(tSpeed>=0) // 01DCSSSS D=direction, C=0, fix for no fractions
b[nB++]=tSpeed+(tSpeed>0)+tDirection*32+64; // max speed is 14, but speed codes range from 2-15 (0=stop, 1=emergency stop)
else{
b[nB++]=1+64; // 1 = Emergency stop + Bit 6 is always 1.
tSpeed=0;
}
loadPacket(nReg,b,nB,0,1);
INTERFACE.print("<Y");
INTERFACE.print(nReg); INTERFACE.print(" ");
INTERFACE.print(tSpeed); INTERFACE.print(" ");
INTERFACE.print(tDirection);
INTERFACE.print(">");
speedTable[nReg]=tDirection==1?tSpeed:-tSpeed;
} // RegisterList::setThrottle14()
///////////////////////////////////////////////////////////////////////////////
void RegisterList::setThrottle28(char *s) volatile{
byte b[5]; // save space for checksum byte
int nReg;
int cab;
int tSpeed;
int tDirection;
int regSpeed=0;
byte nB=0;
if(sscanf(s,"%d %d %d %d",&nReg,&cab,&tSpeed,&tDirection)!=4)
return;
if(nReg<1 || nReg>maxNumRegs)
return;
if(cab>127)
b[nB++]=highByte(cab) | 0xC0; // convert train number into a two-byte address
b[nB++]=lowByte(cab);
if(tSpeed>=29) // Over speed
return;
if(tSpeed>=0){ // 01DCSSSS D=direction, C=LSB. Take tSpeed add 3 then shift>>1 rotating LSB to Bit 4.
regSpeed = tSpeed + 3*(tSpeed>0);
regSpeed |= ((regSpeed & 1) << 5);
b[nB++]=(regSpeed>>1)+tDirection*32+64; // max speed is 28, but speed codes range from 4-28 (0=stop, 1=emergency stop)
}
else{
b[nB++]=1+64; // 1 = Emergency stop + Bit 6 is always 1.
tSpeed=0;
}
loadPacket(nReg,b,nB,0,1);
INTERFACE.print("<U");
INTERFACE.print(nReg); INTERFACE.print(" ");
INTERFACE.print(tSpeed); INTERFACE.print(" ");
INTERFACE.print(tDirection);
// INTERFACE.print("....RegSpeed...="); INTERFACE.print(regSpeed>>1);
INTERFACE.print(">");
speedTable[nReg]=tDirection==1?tSpeed:-tSpeed;
} // RegisterList::setThrottle28()
Hi
Firstly I want to say thank you - this just works for producing packet wave forms that is enabling me to debug my receiver all at the 5V level at my desk...
I could not see any way to output the 28 speed step, so thought I would ask here, is there another branch (or fork) with it already supported?
For my work I have created two new "setThrottle" functions with the corresponding serial calls, using the letters 'y' and 'u'. These were not used and chosen as they are the next ones along on a keyboard.
Is this be the place to contribute to? Is there a more recent head? Would this be desired as a PR?
I've checked these outputs using a Saleae Logic with the DCCAnalyser plugin from: https://github.com/ejbergdk/DCCAnalyzer.git and they match the ECoS ESU Command Station.
I'll drop my code here should is be useful to anyone else / review (I'm not a SW engineer):