Unterschiede zwischen den Revisionen 24 und 25
Revision 24 vom 23.11.2008 15:23
Größe: 2170
Autor: ligi
Kommentar: using cplusplus parser instead table
Revision 25 vom 23.11.2008 15:28
Größe: 3585
Autor: ligi
Kommentar: embedd sendoutdata and decode64
Gelöschter Text ist auf diese Art markiert. Hinzugefügter Text ist auf diese Art markiert.
Zeile 17: Zeile 17:
 Have a look into the Functions Decode64 and !SendOutData in uart.c of the FC Firmware to see how the Data is encoded and decoded.
 . /!\ ToDo: describe data-format
 Have a look into the Functions Decode64 and !SendOutData in uart.c of the FC Firmware to see how the Data is encoded and decoded:

 {{{#!cplusplus
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
{
 unsigned int pt = 0;
 unsigned char a,b,c;
 unsigned char ptr = 0;

 SendeBuffer[pt++] = '#'; // Start-Byte
 SendeBuffer[pt++] = modul; // Adress
 SendeBuffer[pt++] = cmd; // Command

 while(len)
  {
   if(len) { a = snd[ptr++]; len--;} else a = 0;
   if(len) { b = snd[ptr++]; len--;} else b = 0;
   if(len) { c = snd[ptr++]; len--;} else c = 0;
   SendeBuffer[pt++] = '=' + (a >> 2);
   SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
   SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
   SendeBuffer[pt++] = '=' + ( c & 0x3f);
  }
 AddCRC(pt);
}

void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max)
{
 unsigned char a,b,c,d;
 unsigned char ptr = 0;
 unsigned char x,y,z;
 while(len)
  {
   a = RxdBuffer[ptrIn++] - '=';
   b = RxdBuffer[ptrIn++] - '=';
   c = RxdBuffer[ptrIn++] - '=';
   d = RxdBuffer[ptrIn++] - '=';
   if(ptrIn > max - 2) break; // dont process more data than recieved

   x = (a << 2) | (b >> 4);
   y = ((b & 0x0f) << 4) | (c >> 2);
   z = ((c & 0x03) << 6) | d;

   if(len--) ptrOut[ptr++] = x; else break;
   if(len--) ptrOut[ptr++] = y; else break;
   if(len--) ptrOut[ptr++] = z; else break;
  }

} }}}


  . /!\ ToDo: describe data-format

TableOfContents

Protocol

  • The protocol is based on individual serial data frames that are organized as shown in the following table.

    Start-Byte

    Address-Byte

    ID-Byte

    n Data-Bytes coded

    CRC-Byte1

    CRC-Byte2

    Stop-Byte

    '#'

    variable

    'V','D' etc

    "modified-base64"

    variable

    variable

    '\r'

Commands

  • The Commands based on the dataframes above are listed [:en/SerialCommands:here]

Slave Adresses

  • Since Navi 0.12h FC 0.71f Mag 0.19 there are constant SlaveAdresses:

    Slave-Address

    Part

    1

    FC

    2

    NC

    3

    MK3MAG

Data Format

  • Have a look into the Functions Decode64 and SendOutData in uart.c of the FC Firmware to see how the Data is encoded and decoded:

       1 void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
       2 {
       3  unsigned int pt = 0;
       4  unsigned char a,b,c;
       5  unsigned char ptr = 0;
       6 
       7  SendeBuffer[pt++] = '#';               // Start-Byte
       8  SendeBuffer[pt++] = modul;             // Adress 
       9  SendeBuffer[pt++] = cmd;                // Command
      10 
      11  while(len)
      12   {
      13    if(len) { a = snd[ptr++]; len--;} else a = 0;
      14    if(len) { b = snd[ptr++]; len--;} else b = 0;
      15    if(len) { c = snd[ptr++]; len--;} else c = 0;
      16    SendeBuffer[pt++] = '=' + (a >> 2);
      17    SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
      18    SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
      19    SendeBuffer[pt++] = '=' + ( c & 0x3f);
      20   }
      21  AddCRC(pt);
      22 }
      23 
      24 void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) 
      25 {
      26  unsigned char a,b,c,d;
      27  unsigned char ptr = 0;
      28  unsigned char x,y,z;
      29  while(len)
      30   {
      31    a = RxdBuffer[ptrIn++] - '=';
      32    b = RxdBuffer[ptrIn++] - '=';
      33    c = RxdBuffer[ptrIn++] - '=';
      34    d = RxdBuffer[ptrIn++] - '=';
      35    if(ptrIn > max - 2) break;     // dont process more data than recieved
      36 
      37    x = (a << 2) | (b >> 4);
      38    y = ((b & 0x0f) << 4) | (c >> 2);
      39    z = ((c & 0x03) << 6) | d;
      40 
      41    if(len--) ptrOut[ptr++] = x; else break;
      42    if(len--) ptrOut[ptr++] = y; else break;
      43    if(len--) ptrOut[ptr++] = z; else break;
      44   }
      45 
      46 } 
    
    • /!\ ToDo: describe data-format

Checksum

  •    1 unsigned int tmpCRC = 0; 
       2 for(int i = 0; i <  DataBufferLength;i++)
       3  { 
       4   tmpCRC += DataBuffer[i]; 
       5  }   
       6 tmpCRC %= 4096; 
       7 CRC1 = '=' + tmpCRC / 64; 
       8 CRC2 = '=' + tmpCRC % 64; 
    
  • /!\ ToDo: describe checksum calculation verbaly

Implementations

  • Sometimes its a lot more easy to look at code rather than reather than to look at Specifications/Documentation:
  • uart.c in the Flight-Ctrl Firmware ( C )
  • MKCommunicator.java from ["DUBwise"] ( Java / J2ME )
  • mktool.cpp @ ["QMKGroundStation"] ( C++ )
  • GroundStation ( LabView )

Links