RCP Protocol question  [✔]

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

RCP Protocol question

Post by Dagnall » 26.12.2018, 15:37

Rob, I would like some help with understanding RCP some more to help with my RCP mouse:viewtopic.php?f=11&t=15570&hilit=rcp+fn

I saw in viewtopic.php?f=87&t=12246 that there were some issues with toggling control functions.
I am experiencing very similar issues: - I am looking at the Function timer attribute as sent by rocrail, and it this is zero, I control the function as a "Toggle switch" otherwise its "Momentary".

I have found that for Momentary switches a simple client command of the following form works as expected. (my loco Id is "Test Board")

Code: Select all

<fn id="Test Board" f5="true"  />
<fn id="Test Board" f5="false"  />
This makes my loco f5 sound. :thumb_up: (I follow immediately with the "false" on release of the press button on my throttle)

But I have difficulty with the "Toggled" commands:
Lights seems to be a special case, and I needed

Code: Select all

<lc id="Test Board" fn="true"  />
to successfully switch the lights.

For example, the command:

Code: Select all

<fn id="Test Board" f9="true"  />
Triggers the change in function state (9) as shown on my Rocview throttle display, BUT does NOT result in the correct commands being sent to the loco.. (for me this is chuffs ON , so immediately starts or stops chuffs on my loco)..

I have done some experimenting with

Code: Select all

<fn fnchanged="9" fnchangedstate="false" id="Test Board"
but it does not seem to work either..

:?: do I need an additional command to add to the <fn ... /fn> sequence to trigger the actual "send to throttle" :?: if I change the fn toggle state using <fn ?

Many thanks
Dagnall

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 26.12.2018, 16:00

Dagnall,

there is no toggle command available, just true/false.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 26.12.2018, 16:28

Rob, thanks,
Yes I understand that, but what I do not understand is why I can send a <fn id="Test Board" f9="true" /> to a momentary function, and it will be accepted, but when I send it to a function where the function timer is 0, ( a toggled function) it is seen and apparently "accepted" by rocview, but no command seems to be sent to the loco..

Is there a "preferred format" to send fn commands to a loco?

Cheers
D

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 26.12.2018, 16:37

Rocweb sends: (Javascript)

Code: Select all

  lc = lcMap[locoSelected];
  if(lc == undefined)
    lc = carMap[locoSelected];
  if( lc == undefined ) return;
  if( FGroup == 1 )
    nr += 14;
  trace("Funtion: " + id + " ("+nr+") for loco " + locoSelected);
  var group = (nr-1)/4+1;
  var fx = parseInt(lc.getAttribute('fx'));
  var mask = 1 << (nr-1);
  var on = fx&mask?"false":"true";
  var cmd = "<fn controlcode=\""+controlCode+"\" slavecode=\""+slaveCode+"\" id=\""+locoSelected+"\" throttleid=\""+throttleid+"\" fnchanged=\""+nr+"\" group=\""+group+"\" f"+nr+"=\""+on+"\"/>"
where controlcode and slavecode are only needed if they are defined in the Rocrail setup.

If your app is acting like a client, it should also evaluate loco function broadcast to be up to date with the server.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 26.12.2018, 19:51

Thanks:
Still a bit confused.. In my tests, my client program sends <fn id="Test Board" f8="true" /> and shortly afterwards,<fn id="Test Board" f8="true" /> and the loco sounds fn8 which has a defined function timer and is a whistle.

But if my client program sends {just} <fn id="Test Board" f9="true" />, the f9 function in the rocview throttle mirrors that it has seen the "true" change of state, but for some reason, the command is not sent on to the loco? -- My client also monitors the info data stream and so mirrors any commands seen. If I command f9 true on the rocview throttle the sounds come on as expected ..but not if I send the command from my client. FYI I see: this on the info channel when I send my <fn command

Code: Select all

<fn id="Test Board" f9="true" server="mqttreader" dir="true" addr="3" secaddr="0" V="15" placing="false" blockenterside="false" blockenterid="" mode="stop" modereason="" resumeauto="false" manual="false" standalone="false" blockid="" destblockid="" fn="true" runtime="31036" mtime="0" rdate="1545829685" mint="0" throttleid="" active="true" waittime="0" scidx="-1" scheduleid="" tourid="" scheduleinithour="0" len="0" weight="0" train="" trainlen="0" trainweight="0" V_realkmh="0" fifotop="false" image="terrier.png" imagenr="0" energypercentage="0" lookupschedule="false" pause="false" consist=""/>
:?: Do I need to do something else to explicitly define the lc and update it?
:?: Should I be using a different command structure?


But when I send <lc id="Test Board" fn="true" /> (which is understood and accepted as the lights on)
I see this on the info channel

Code: Select all

<lc id="Test Board" fn="true" server="mqttreader" dir="true" addr="3" secaddr="0" V="15" placing="false" blockenterside="false" blockenterid="" mode="stop" modereason="" resumeauto="false" manual="false" standalone="false" blockid="" destblockid="" runtime="31128" mtime="0" rdate="1545829685" mint="0" throttleid="" active="true" waittime="0" scidx="-1" scheduleid="" tourid="" scheduleinithour="0" len="0" weight="0" train="" trainlen="0" trainweight="0" V_realkmh="0" fifotop="false" image="terrier.png" imagenr="0" energypercentage="0" lookupschedule="false" pause="false" consist=""/>
<lc id="Test Board" f9="true" /> does not seem to be a valid command

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 27.12.2018, 07:53

Hi Dagnall,

try using the (7)clntcon trace:
https://wiki.rocrail.net/doku.php?id=ro ... le-en#help
Then you can see in which format Rocview/Rocweb/andRoc function commands are sending.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 27.12.2018, 13:37

Thanks, I always need more monitors! :coding:
that console helped me find the issue:
My simple <fn id="Test Board" fn8="false" /> <fn id="Test Board" fn8="true" /> Commands were evaluating as [fn=-1].. (But it was strange that somehow rocrail managed to make the fn sounds sound :? ).

I changed my commands to a more explicit <fn fnchanged="8" fnchangedstate="false" id="Test Board" f8="false" />, and Rocrail sees this and implements it. :D

I had tried {fnchanged=8 fnchangedstate=false} before, but had not included the {f8=false} in the same command string before..Seems its essential!

Many thanks.
I will publish the resultant Throttle in git hub later.

Dagnall

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 10.01.2019, 16:40

Rob, another (Short!) question
:?: in RCP, how do I get Rocrail send me (ALL of!) the states of the Loco functions.
- I get and use the Lcprops message response, and it has some of the data (eg, Fn is "F0" and lights) , but I use some other functions as toggles, and would like to be able to update my throttle's knowledge of these states.
Thanks
D

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 10.01.2019, 16:53

check the fx attribute; Every bit represents a function state.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 10.01.2019, 17:53

FX, yes, I have seen that message with lots of F1 F2 etc responses, but what command do I need to ask Rocrail to send it?
I only got it before by accident (and some exception code :oops: )
is there a 'fxprops' similar to lcprops that takes the id = loconamevariable?
perhaps somethong like this :?: ??

Code: Select all

<fn fxprops id="the_loco_I_need" >

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 10.01.2019, 17:58

this is a <lc/> attribute.
You get this info if your devices did connect and received the loco list. At this time you should synchronise.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 10.01.2019, 18:27

Thanks for quick replies, and sorry I am not understanding your reply..
I send

Code: Select all

<model cmd="lcprops" val="tram"/>

I get the lc attributes for that loco (I believe this is what you mean by 'Synchronizing'? )

Code: Select all

<lc id="tram" prev_id="tram" shortid="10" ... 
But that does not contain the full list of what states the loco functions are in.. I agree it does contain Fn==f0=="lights" status, but not the other function states.
:?: What command (an example would be very helpful! :wink: ) do I need to send to ask Rocrail to send all the lc fx attributes?


D

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 10.01.2019, 18:40

fx is a number like 345. (fx="345")

Code: Select all

Hex 0x0159
Binary 0000 0001 0101 1001
f1=on
f4=on
f5=on
f7=on
f9=on

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: RCP Protocol question

Post by Dagnall » 10.01.2019, 18:56

rjversluis wrote:
10.01.2019, 18:40
fx is a number like 345. (fx="345")

Code: Select all

Hex 0x0159
Binary 0000 0001 0101 1001
f1=on
f4=on
f5=on
f7=on
f9=on
Yes, I understood 'fx',
:?: BUT what command (an example would be VERY helpful! :wink: ) do I need to send to 'rocrail/service/client' to get Rocrail to send me a message via 'rocrail/service/info' that will contain ALL the fn attributes 'f1=on, f2=on f3=off ..' etc of a selected loco :?:

rjversluis
Site Admin
Posts: 41162
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: RCP Protocol question

Post by rjversluis » 10.01.2019, 19:03

if you did sync on startup, you will receive a <funcmd/> event every time a client did modify a function or triggered by action.
There is no way to poll function states. You do not need it because you get informed in case something did change.

Post Reply

Return to “DIY Hardware”