Technical log entry 2 / 03-11-09

3rd November write Hello code for testing

//update: settled on manual control of UBRR values and defined baud-rate at 2300bps. At 10 bits per frame, gives 230 Bytes per second datarate.

Determine how long it should wait for a hello....

-Write "hello_listen" function in main prototype

Data reception works ok, identification of HELLOCODE working.
Need to write interupt driven architecture for program. Data buffer (of 25 Bytes), checksum, this needs a think.

HELLO_LISTEN can be determined by confirmation of reception of the HELLOCODE in the first cell of the Data buffer.
Need to determine complete architecture of data management first...

PROTOCOL
    -use the same technique as MIDI.

    A COMMAND MSG message will always have bit 7 set (msb) set..
   
    |1|CMD|CUBEID|
e.g.
    |1|HELLO|1|    sends a hello from cube 1
    |1|REPLY|1|    replies to cube 1
    |1|WGDB|CUBEID|    request to write the global database
   
    the WGDB command is followed by data with m.s.b. cleared

    |0|DATA|

25 or so bytes later (size to be determined), the LAST byte is the CHKSUM. The checksum is validated before the global database is updated.

PROXIMITY IDENT
A HELLO is sent from the first cube with its ID
A REPLY is sent from the replying cube confirming its ID

e.g. CUBE 4        CUBE 8
|1|HELLO|4| ->
<-|1|HELLO|4|
   
The handshake should therefore be an echo reply, of whoever initiated the transmission. The cube will wait a pre-defined time based on the cube id to receive a HELLO, otherwise it will sent the HELLO itself.

Pseudo:
   
    int wait_listen(wait time) {        //returns the cube ID, 0 if no reply yet
        listen for a hello
        return the cubeID contained in the hello
    }

    void sendhello(cubeid)

    bool    handshake

    ///
       
    other_cubeid = wait_listen(time_to_sync + myoffset)
    if other_cubeid != 0 then                //got a hello from the other cube
        Sendhello(other_cubeid)                //send an echo reply to it
        handshake = true
    else
        sendhello(my_cubeid)                //didnt get a hello so sendone
        if (wait_listen(time_to_sync + myoffset)=my_cubeid) then            //did I get an echo reply?
            handshake = true
        endif
    endif

    //this process then needs to be repeated to find out the cube ID of the OTHER cube. This is required for the games.
    //Also, this means that updating the global database for THAT PARTICULAR CUBE can be done, rather than sending a the entire database :)

    if (handshake) then
        communicate the global database both ways... same sort of method as abobe
    end if
--------------------------------
WOW, the handshake works...