You can use the array technique any place you need to enter a binary number in the range of 0-255 into the RussSoundProtocol. You could even use it for constants instead of "\xnn" by writing chr[nn] where nn is a number 0-255. remembering that for all values over 127 the inversion will take place so do not use it for the control characters 0xF0 and 0xF7 if they are really desired. There should be no need to explicitly use the inversion control (0xF1) as that is automatically handled.
As a further tip for clarity you might want to define some constants such as:
SOMbyte="\xF0"; EOMbyte="\xF7"; NULbyte='\x00";. . . as needed fo commonly used constants.
You can then build messages as
msg= SOMbyte+chr[i]+chr[j]+NULbyte+. . .
msg+=chr[checksum(msg)]+EOMbyte
In the above msg is a string variable, i and j are integers in the range 0-255, and checksum is a function that computes and resurns the 7 bit checksum as an integer.
It makes it a lot easier to read and understand. The checksum function would look something like this:
function checksum(a)
{var i; var b=a.length; for(i=0; i < a.length; i++;) { b+=a[i]-0;}; b+=127; return b; }
Last edited by Barry Gordon
on June 30, 2008 15:14.