SRCP service or SRCP command station ?

Moderator: Moderators

SRCP service or SRCP command station ?

Postby sn00zerman » 01.02.2012, 21:17

Hello all,

I'm currently in the progress of building a home-made "commandstation" for my own car-system.
I use an android device, which connects via WIFI to RocRail, and via Bluetooth to my own hardware.

I'm currently strugling with SRCP ...
I did read about the protocol etc, but I'm a bit confused on the RocRail side, because documentation is very limited (in my opinion).

All I want to do, is to "capture" "locomotive-information" (speed and function-buttons) on my android device.

Do I need to use SRCP service, or do I need to add an SCRP command station ?
I actually only need the "info"-channel I think ...
Also, do I need to connect via TCP, or should I use an UDP connection ? (UDP is only possible via SRCP command station I think, because there you can define a remote host, with the SRCP service, this is not possible)

I tried all different things, but I al got was "no connection" or "connection refused". (P.S. I use the Mac-version of RocRail)



Thanks in advance,
Kris
sn00zerman
 

Postby rjversluis » 01.02.2012, 21:30

Hi Kris,

you are building a Command Station so you must configure Rocrail with SRCP as Command Station; The Service is for SRCP Clients.

SRCP does not connect using UDP but TCP/IP.
Your Command Station is the SRCP Server so you must provide a socket in accept mode. (Server socket)

If you select SRCP 0.8 only one connection is needed for commands and info.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBUS - CANGCx ] - [ G: CBUS - CANGCx ]
rjversluis
Site Admin
 

Postby LDG » 01.02.2012, 22:08

Hello Rob,
rjversluis wrote:If you select SRCP 0.8 only one connection is needed for commands and info.
Correction: In SRCP 0.8.3 und 0.8.4 a connection is either in INFO- or COMMAND-mode. This is configured during the inital "Hand Shake" with
Code: Select all
SET CONNECTIONMODE SRCP <MODE>
. You can open multiple (usually 2 per client app) connections to the same server and port.

Regards,
Lothar
LDG
Site Admin
 

Postby LDG » 01.02.2012, 22:15

Hello Kris,

I have some questions because I am not sure how your physical/logical configuration ist :roll:
Which device is the controller (generating and sending the commands) to the car-system ?
Which devices are exchanging commands and responses ?
Which directions (command flow) ?
What about feedbacks from the layout ?

Regards,
Lothar
LDG
Site Admin
 

:-)

Postby sn00zerman » 01.02.2012, 22:31

Hi all again ...

Thanks for the quick response :-)

Here is some more info:

my own device is a "one-direction" system:
- feedback is done via S88, trough my regular P50X commandstation.
(MrDirect) (I have reed-contacts in my street-elements)
- I only need to "intercept" RocRail loc-commands, via SRCP on my android.
Next, my android sends data to a self-made via bluetooth.
This self-made device, converts commands received via bluetooth,
to a RFM12B transmitter. In my vehicles, I have RFM12B receivers.

Actually, my android device acts like a real simple command station,
that translates loco-commands comming from RocRail, to my own
wireless commands to control my vehicles.

So, Actually, I'm only interested in the "info"-channel.
(so, I prefer the 0.7x of SRCP, this will be the easiest way I think)

What I did so far, was:
- create a serversocket in my own application, and make it "listen" on
the info-channel port, but no avail.
- When will the actual "connect" command will be triggered in my
own application ? (e.g. when will rocrail try to make a connection ?)
- Do I need to send something back ? I'm only interested in "SRCP Info" data ...

I also did set SRCP to port 4303 only in the command-definition,
but RocRail "hangs" after this. (while my application is active, listening to incomming commands)

So, any clues left ?

I'm also confused about the command and info mode.
Does "info mode" means: RocRails sends info to my device.
Or do I need "Command mode", and does RocRail send the loc-commands to my device ?

(or maybe a sample in VB or C# or something ? I can surely convert this myself to Android language)

EDIT:
Are you sure I need the SRCP command station ?
Can you explain a bit more what the "SRCP service" does ?
Is there some documentation available for that ?
I managed to connect to the "SRCP service", not the SRCP command station :-)
I get "RocRail 2.0 Rev 3215; SRCP 0.8.4; SRCPOTHER 0.8.3" as a reply :-)
(hmm, finally some communication is going on)
Is there A way to use this service to get the info I need from the locs ?
Or to initiate one command, which gives me a response, every time a loc-speed or function is changed ?
(I'm going to bed now, I shouldn't be behind my PC, I'm currently having Chemo for my HHC treathment)

best regards,
Kris
sn00zerman
 

Re: :-)

Postby LDG » 02.02.2012, 00:53

Hi Kris,
sn00zerman wrote:Are you sure I need the SRCP command station ?
Can you explain a bit more what the "SRCP service" does ?
Is there some documentation available for that ?
I managed to connect to the "SRCP service", not the SRCP command station :-)
I get "RocRail 2.0 Rev 3215; SRCP 0.8.4; SRCPOTHER 0.8.3" as a reply :-)
(hmm, finally some communication is going on)
Is there A way to use this service to get the info I need from the locs ?
Or to initiate one command, which gives me a response, every time a loc-speed or function is changed ?
Documentaion for srcp is available on the official site http://srcpd.sf.net.
You will need an info session to the srcp service. Forget about 0.7x. It is completely outdated and not supported by the srcp service in Rocrail. Version 0.8.4 is current (and small changes for a next version are currently discussed in the newsgroup).
Open a connection (you get the welcome message with the supported srcp versions!), set the version
Code: Select all
SET PROTOCOL SRCP 0.8.4
change to infomode
Code: Select all
SET CONNECTIONMODE SRCP INFO
and start it
Code: Select all
GO
These commands are in "interactive mode" -> they return an answer you should evaluate.
After a successful "GO" you MUST NOT send any further commands on this channel (see specification) but listen permanently for incoming messages sent from the server. The first time power is switched on in Rocrail you should get the whole list of locos, accessories and feedback states :shock: Afterwards you will receive every change of locos (speed, function), accessories and feedbacks from the Rocrail server.

The info channel is working properly with j-man (current svn version) and spdrs60.

I just had problems debugging the info channel with an interactive telnet session. Tomorrow I will have to do some more testing on this issue...

Regards,
Lothar
LDG
Site Admin
 

:-)

Postby sn00zerman » 02.02.2012, 11:19

Did I already said that RocRail is awesome, and you guys do rock ? :-)

I will try it this afternoon, this information seems clear to me, this should get me going ...
I will inform later this evening about my progress.


Thanks again,
Kris
sn00zerman
 

:-(

Postby sn00zerman » 02.02.2012, 16:57

Telnet is indeed a good idea to test this out.

I have an initial communication "up and running":
R:Rocrail 2.0 Rev 3215; SRCP 0.8.4; SRCPOTHER 0.8.3
M:SET PROTOCOL SRCP 0.8.4
R:1328197932.747 200 OK
M:SET CONNECTIONMODE SRCP INFO
R:1328197943.826 202 OK CONNECTIONMODE
M:GO
R:1328197945.286 200 OK GO 1

The lines beginning with R: is what I receive from RocRail
The lines beginning with M: is what I typed

After this, I don't receive any more information.
(not even when turning the power on/off in Rocrail, completely nothing.

As command-station, I have a regular P50X configured within RocRail, but also with an SRCP command station (at the 3 old ports), doesn't do anything :-(
I can even still type something, and the RocRail SRCP service does answer me. (I tried the SET CONNECTIONMODE SRCP INFO again, and I got a response back ...)

So, I think I'm close, but no sigar yet :-)

EDIT 1:
When I type for instance "GET 0 GL 1",
I do see the speed and function-settings of the loc with address 1:
1328198674.654 100 INFO 0 GL 1 1 14 14 0 1 1 1 1
But I'm actually looking for real info mode, so I get this data whenever I change the speed or a function within RocRail.
I also did look trough the SRCP documentation, and couldn't find anything else that needs to be initiated. So, my *big* question now is, is this info-mode not completely OK in RocRail ? (Sorry, I had to ask, lol)

EDIT 2:
I found the following in my trace, whenever I send SET CONNECTIONMODE SRCP INFO

Code: Select all
SRCP Session 1 set to COMMANDMODE
SRCP RESPONSE: 1328200379.428 202 OK CONNECTIONMODE
 for req SET CONNECTIONMODE SRCP INFO
 socket 0x10ba21670


Which is very strange, because in the srcpcon.c I find the following:

Code: Select all
static void __evalRequest(iOSrcpCon srcpcon, __iOSrcpService o, const char* req) {

char rsp[1025] = {'\0'};

struct timeval time;

gettimeofday(&time, NULL);

  if( StrOp.startsWithi( req, "SET CONNECTIONMODE" ) ) {

    if( StrOp.equalsi( req, "SET CONNECTIONMODE SRCP INFO" ) ) {

      o->infomode = True;

    }else {

      o->infomode = False;

    }

    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "SRCP Session %d set to %s", o->id, o->infomode?"INFOMODE":"COMMANDMODE" ) ;

    SocketOp.fmt(o->clntSocket, srcpFmtMsg(202, rsp, time, 0));

    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "SRCP RESPONSE: %s for req %s socket %p", rsp, req, o->clntSocket ) ;

  }



Thanks in advance,
Kris
sn00zerman
 

:-)

Postby sn00zerman » 02.02.2012, 18:27

IT WORKS !

(I made a second post, because my previous was getting to long)
It seems like telnet does send out <cr><lf>, and RocRail does not like this.
Within my own program, everything works now :-)
(i only send a LF after the command)

I do get a list of all locs, whenever I set the "power on" in RocRail.

However, I'm missing one little thing here !
<power on> and <power off> events, don't come trough within the SRCP info.
Is this normal behavior ? I was thinking that all commands should come trough ?


thanks for your help guys,
Kris
sn00zerman
 

Postby LDG » 02.02.2012, 20:25

Hi Kris,

you are right :oops:
I just debugged this and discovered the same result: Additional character at the end of the line and the string comparison fails.

Just replace in rocrail/impl/srcpcon.c line 1627:
Code: Select all
if( StrOp.equalsi( req, "SET CONNECTIONMODE SRCP INFO" ) ) {
with
Code: Select all
if( StrOp.startsWithi( req, "SET CONNECTIONMODE SRCP INFO" ) ) {


@Rob: Please change and fix with next commit
EDIT: @Rob: You have an email with 2 fixes :oops:

POWER ON and POWER OFF should be transmitted to all INFO sessions.

Please put your rocrail.ini and your Planfile into an archive and upload here so I can test with your data.

Thanks for finding a bug :)

I know there is still some things missing in SRCP, but...

Regards,
Lothar
Last edited by LDG on 02.02.2012, 20:42, edited 2 times in total.
LDG
Site Admin
 

:-)

Postby sn00zerman » 02.02.2012, 20:34

Hi Lothar,


Please find included my complete workspace (plan, ini etc ...)
Note that this is just a test-version, my full plan is on my other machine.
If it should matter:
- This machine is an Imac with Lion OSX.
- My other Machine is an Intel-based with the latest Ubuntu Distro on it,
and 4 monitors.

thanks for looking into my issues :-)

I'm currently implementing the SRCP into my own application,
so I guess my cars will be "up and running" within a few days :-)
(I guess I own you guys at least a short movie when everything is up and running, lol)

EDIT:
I did find the cause of my problem ...
- When I set the VCS as my command station, I get the power notifications.
- However, when I set a P50X command station, I don't get the power notifications. I assume this is because there is currently no commandstation connected to this PC.
What if a command-station fails, and you press the "power"button within RocRail, no SRCP client will get this power event delivered ...
Is this normal behavior ? shouldn't the SRCP service send this data, no matter if a command station is attached or not ?

I also found another problem:
Whenever I leave my SRCP client open, and when I close RocRail, the SRCP service still seems to Run.
Because, when I restart RocRail, and try to re-connect to the SRCP via my client, the connection fails.
When I first close my client, and restart rocrail afterwards, everything runs fine the next time.


best regards,
Kris
You do not have the required permissions to view the files attached to this post.
sn00zerman
 

some things missing in SRCP ?

Postby sn00zerman » 03.02.2012, 20:21

Hi all,


Here I am again :-)
While reading the SRCP specs on http://srcpd.sourceforge.net/srcp/,
I noticed some things on page 33 & 34 about the info mode:

Code: Select all
When activating the info mode in a session the DESCRIPTIONS for all buses and all active devices known to the server in their current state are transmitted. Subsequently all changes are sent. If there is a clear default state for some device groups, all devices in this default state SHALL not be transmitted. Optional device groups are only ALLOWED to be given if they are supported.
Simple Railroad Command Protocol
33
Specifics of the device groups during activation of the info mode: FB
All devices with the status 0 are not transmitted. All others are in form of “ 100 INFO <bus> FB <addr> <value> ” .
GA
The individual ports of the devices known to the server are separated and transmitted each with their
last activity in form of “ 100 INFO <bus> GA <addr> <port> <value> ” . GL,SM
All engines moving or standing with an active function are reported. Engines in standstill MUST be reported (as “ 100 INFO <bus> GL <addr> <drivemode> <V> <V_max> <f1> . . <fn> ” or “ 100 INFO <bus> SM <decoderaddress> <type> <1 or more values> ” .) if they have been addressed at least once and not removed by TERM. Likewise changes are reported by INIT. During SM all programming activities are reported. A concluded programming action MUST NOT be sent with new connections.
POWER
The state of the energy supply MUST be given as “ 100 INFO <bus> POWER [ON|OFF]
<freetext> ” .


So, if I understand this correctly, I should get a list of all running locs (or at least, locs with at least one function activated), and the current power-state.

However, I do net get this, when I make an SRCP connection.

I do however get 2 lines, one for bus 0, and what is on that bus, and one line for bus 1, which indicates that GA,GL,FB and power can be found on this bus.

Do I mis-understand the specs, or is this not yet implemented in RocRail ?
This is the only thing that is missing in my software, so that when I make a connection to RocRail SRCP, I need to know what the power-state is (on/off) and which "locs" are "active".

For the rest, everything is yet implemented in my own car-system-software :-)

Thanks guys,
best regards,
Kris
sn00zerman
 

Re: some things missing in SRCP ?

Postby LDG » 03.02.2012, 21:35

Hello Chris,
sn00zerman wrote:Hi all,


Here I am again :-)
While reading the SRCP specs on http://srcpd.sourceforge.net/srcp/,
I noticed some things on page 33 & 34 about the info mode:
...
...

So, if I understand this correctly, I should get a list of all running locs (or at least, locs with at least one function activated), and the current power-state.

However, I do net get this, when I make an SRCP connection.

I do however get 2 lines, one for bus 0, and what is on that bus, and one line for bus 1, which indicates that GA,GL,FB and power can be found on this bus.

Do I mis-understand the specs, or is this not yet implemented in RocRail ?
:shock: You got me. See srcpcon.c line 1640ff . Thats one of the TODOs that are still missing :oops:
I'll try to implement it this weekend, but can't guarantee that :roll:
This is the only thing that is missing in my software, so that when I make a connection to RocRail SRCP, I need to know what the power-state is (on/off) and which "locs" are "active".

For the rest, everything is yet implemented in my own car-system-software :-)

Thanks guys,
best regards,
Kris
Sounds good. I'll do my best to help you :wink:

Regards,
Lothar
LDG
Site Admin
 

Postby sn00zerman » 03.02.2012, 22:00

You are to good for this world :-)

don't worRy, there is no hurry, I need to go to the hospital on Monday for at least 3 days. (Chemo) I will surely wear my rocrail cap, now that I lost all my hair.


P.s. have you also seen my comment about missing srcp info with a non-connected command station?


Have a nice weekend and thanks once again,
Kris
sn00zerman
 

Postby LDG » 04.02.2012, 00:31

Hi Kris,
sn00zerman wrote:I did find the cause of my problem ...
- When I set the VCS as my command station, I get the power notifications.
- However, when I set a P50X command station, I don't get the power notifications. I assume this is because there is currently no commandstation connected to this PC.
What if a command-station fails, and you press the "power"button within RocRail, no SRCP client will get this power event delivered ...
Is this normal behavior ? shouldn't the SRCP service send this data, no matter if a command station is attached or not ?
Power state changes are only reported if they are broadcasted to the "internal services".
sn00zerman wrote:I also found another problem:
Whenever I leave my SRCP client open, and when I close RocRail, the SRCP service still seems to Run.
Because, when I restart RocRail, and try to re-connect to the SRCP via my client, the connection fails.
When I first close my client, and restart rocrail afterwards, everything runs fine the next time.
Unfortunately this is a problem within port management :(
It is the same behaviour with the "original" srcpd.
Whenever I kill my srcp sessions by closing the Rocrail or srcpd-server I have to wait about 1 minute before I can re-use the port. I'm not sure if we can solve this within Rocrail. First closing the client apps should be the preferred method :)

Regards,
Lothar

PS: You have a PM :wink:
LDG
Site Admin
 

Next

Return to srcp