barrygordon
unread,Feb 17, 2012, 7:21:21 PM2/17/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to CommandFusion
The Sony protocol is a "Bitch" to deal with if you want to handle it
correctly for all cases and error syndromes, that is, all possible
ways that a message can be dstroyed or mangled when coming over RS232
from a Sony component and being changed to TCP/IP by a GC-100, iTach
Xeta Server or something similar.
Th first real problem is that there is no EOM (End of message) byte.
Ergo, to know you have a proper valid message have to do a bit of
work. You must detect the start of a message, isolate the message's
byte count which is always the 2nd byte of the message, assemble the
correct number of bytes, and finally validate that the checksum is
correct. Even then there is a small probablility that the message is
still mangled.Think of the case where the byte count itslef is mangled
by line noise.
A message can contain arbitrary bytes (0-225) so things like STX can
appear in the middle of a message.
When a full message has been taken off the line (using the byte count)
you must validate the checksum to ensure you really have a proper
message. This is especially true for long messages such as status
from Blu ray changers where large amounts of data can be pulled.
To complicate matters the message may not come into the iPad in one
chunk, but rathher a few bytes at a time with arbitrary timing between
chunks. After all it (RS232) is an asynchronous protocol which means
that the timing between bytes is arbitrary and not fixed. Also wi-Fi
issues contribute to the timing problem.
The only way to find the byte count in a message is that it is always
preceeded by a STX, however not all bytes that follow a STX bytes are
message byte counts, since an STX can appear at any position in a
message as part of the data. This implies that you must time the
receipt of a message so that some mangled byte count doesn't cause you
to wait for more bytes when none are forthcoming.
To really complicate things, a device like the global cache may not
end up delivering the full message in a single chunk. Lots of things
can cause delays in The GC device between the bytes coming in on the
serial side and leaving on the TCP side. And then there is Wi-fi to
contend with which can add additional delays and noise.
You can use a fairly complicated regex to grab just what you need from
a message in the simple case, especially when it is a response to a
specific command and not an unsolicited broadcast. My approach is to
use the simplest regex I know of (^*) which just delivers everything
from the line into the feedback processing function. My feedback
processing function is a Javascript function which handles all of the
delays, intermittent delivery, noise, etc and produces a validated
message for processing. Pulling the needed data out of a validated
method is driven by the command byte in the message which can then be
used in a switch statement to breakdown the validated message.
The trick is to be able to get a guaranteed valid message at all
times. Yes I know that TCP/IP is a guaranteed delivery protocol
but . . .
I implemented a feedback processor in Javascript using a finite state
machine with three states.
State 1- looking for a new message (STX) \x02 or a NAK \xFE or an ACK
\xFE. The ACK and NAK are valid single byte messages.
State 2- Pulling the message byte count. Always the byte after an STX
byte
State 3- Absorbing bytes until the message byte count has been
satisfied at which time a checksum computation must be perfomed to
validate the message.
I should be done with a complete demo program in a few days. The
program will be extensible, table driven for the most part and include
discovery of Global Cache devices. It will be heavily documented
since I am releasing it as both a teaching tool and a demo of "a way"
of doing things. It is HEAVILY Javascript oriented, but has enough
commentary to allow a beginner to follow it (I hope) The only
restriction is that no part may be used for monetary gain with out my
prior permission.