User Tools

Site Tools


projects:aa4rdemonstrator:externalprotocol

AA4R-Controller-Server Protocol

The communication between the Server and the Controller uses UDP.

  1. The server sends a SYN Message to the controller
  2. The controller answeres with a SYN-ACK message
  3. the server responds with an ACK

Now the connection is established. Every 5 seconds a PING Message will be send by the server and responded with a PONG Message by the controller. If three pong messages get lost, the connection is assumed to be lost and the server starts to send SYN Messages again.

All messages by the server contain a timestamp, which is used to set the time of the controller.

The data messages by the controller can contain serveral sensor readings. The format is as follows:

0                 8           16                     48
| Msg Type = 0x11 | Entity ID | Controller Timestamp | 

Followed by the sensor readings:

0           16            24      40                                         56      
| Sensor ID | Sensor Type | Value | (Controller Timestamp - Value Timestamp) |

If the following sensor reading is by the same sensor, the following format is used:

| 0xFF | Value Diff | Time Diff |

The value and time difference encoding is described by the following code (see Method newMessage in the file cometos_v6/src/medic/MedicBuffer.cc):

int16_t valueDiff = sensorBuffer[0]->value - lastValue;
uint16_t tD = sensorBuffer[0]->timeStamp - lastTimeStamp;
 
uint16_t vD;
if (valueDiff < 0) {
    messageBuffer[currentSize][pos] = 0x40;
    vD = -(valueDiff + 1);
} else {
    messageBuffer[currentSize][pos] = 0;
    vD = valueDiff;
}
 
if (vD > 63) {
    vD -= 64;
    messageBuffer[currentSize][pos++] |= 0x80 | ((vD >> 8) & 0x3F);
    messageBuffer[currentSize][pos++] = vD;
} else {
    messageBuffer[currentSize][pos++] |= (vD & 0x3F);
}
 
if (tD > 127) {
    tD -= 128;
    messageBuffer[currentSize][pos++] = 0x80 | ((tD >> 8) & 0x7F);
    messageBuffer[currentSize][pos++] = tD;
} else {
    messageBuffer[currentSize][pos++] = tD & 0x7F;
}
projects/aa4rdemonstrator/externalprotocol.txt · Last modified: 2015/07/10 11:31 by ti5mr