Communication among RCX computers


Four RCX Code programs are running on four independent RCX computers. By means of the IR communication the four RCX computers play tones in turn. This is achieved by means of a protocol on top of the IR communication primitives in RCX Code:
Each RCX computer has a unique identity, id = 1,2,3 and 4. The RCX computer with id = 1 starts by sending a message with the value 2. This is interpreted by the RCX computer with id = 2 as a message telling it to play. The computer with id = 2 then sends a message with the value 3 telling the computer with id = 3 to play and so on until the message with the value 1 is sent out by the RCX computer with id = 4. This completes one round.

The programs for the RCX with id = 1 looks as follows:

Private Sub ID1_Click() 'VAR(1) = RCX ID 'VAR(2) = Message Received 'VAR(3) = Next ID PB.BeginOfSub 1 ' SendMessage ( Next ID ) PB.SendPBMessage 0, 3 PB.EndOfSub PB.BeginOfSub 2 ' WaitMessage PB.SetVar 2, 15, 0 ' VAR(2) = PBMessage PB.While 0, 2, 2, 2, 0 ' Wait for PBMessage PB.SetVar 2, 15, 0 PB.EndWhile PB.ClearPBMessage PB.EndOfSub PB.BeginOfTask 0 PB.ClearPBMessage PB.SetVar 1, 2, 1 ' RCX ID = 1 PB.SetVar 3, 2, 2 ' Next ID = 2 PB.PlaySystemSound 2 PB.GoSub 1 ' SendMessage (Next ID) PB.Loop 2, 9 ' Loop 9 times PB.GoSub 2 ' WaitMessage PB.While 0, 2, 3, 0, 1 ' While Message not my RCX ID PB.GoSub 2 ' WaitMessage PB.EndWhile PB.Wait 4, 100 PB.PlayTone 440, 30 PB.GoSub 1 ' SendMessage (Next ID) PB.EndLoop ' EndLoop PB.GoSub 2 ' WaitMessage PB.While 0, 2, 3, 0, 1 ' While Message not my RCX ID PB.GoSub 2 ' WaitMessage PB.EndWhile PB.PlaySystemSound 5 PB.EndOfTask End Sub The programs for the RCX with id=2, id=3 and id=4 are similar except for the id. The id=2 program looks as follows: Private Sub ID2_Click() 'VAR(1) = RCX ID 'VAR(2) = Message Received 'VAR(3) = Next ID PB.BeginOfSub 1 ' SendMessage ( Next ID ) PB.SendPBMessage 0, 3 PB.EndOfSub PB.BeginOfSub 2 ' WaitMessage PB.SetVar 2, 15, 0 ' VAR(2) = PBMessage PB.While 0, 2, 2, 2, 0 ' Wait for PBMessage PB.SetVar 2, 15, 0 PB.EndWhile PB.ClearPBMessage PB.EndOfSub PB.BeginOfTask 0 PB.ClearPBMessage PB.SetVar 1, 2, 2 ' RCX ID = 2 PB.SetVar 3, 2, 3 ' Next ID = 3 PB.Loop 2, 10 ' Loop 10 times PB.GoSub 2 ' WaitMessage PB.While 0, 2, 3, 0, 1 ' While Message not my RCX ID PB.GoSub 2 ' WaitMessage PB.EndWhile ' PB.Wait 4, 100 PB.PlayTone 500, 30 PB.GoSub 1 ' SendMessage (Next ID) PB.EndLoop ' EndLoop PB.EndOfTask End Sub If we remove the PlayTone instruction and only waits for 1/100 sec we have measured the time it takes for 255 rounds in the ring. This is 74 sec. If we subtract the time for waiting ( 0.01*255*4 sec = 10 sec ) the remaining 64 sec are used for RCX computations and IR transmission. This is 64/(255*4) sec/ message = 63 msec/message. We know that the transmission is done asynchronously on a 2400 bit/sec serial communication channel, and that 1 start bit, 1 parity bit and 1 stop bit are used per byte. This gives 11 bits/byte and hence 4.5 msec per byte.

An optimized version of the programs results in a time of 50 sec for 255 rounds. The time per message is then 50 msec/message. With a time per byte of 4.5 msec we obtain that at most 50/4.5 bytes are sent per message. i.e. 11 bytes per message. We know that at least one byte is sent. So either the overhead is large per message or the RCX compution time cannot be ignored.