Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 417 → Rev 418

/trunk/mkprotocol.c
7,7 → 7,7
// + Software Nutzungsbedingungen (english version: see below)
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18,7 → 18,7
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + des Mitverschuldens offen.
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
32,7 → 32,7
// + Software LICENSING TERMS
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
// + The Software may only be used with the Licensor's products.
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
55,7 → 55,7
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdarg.h>
#include "91x_lib.h"
#include "mkprotocol.h"
#include "mkprotocol.h"
#include "ramfunc.h"
#include "usb.h"
#include "uart1.h"
73,12 → 73,12
 
u8* pdata = NULL;
int len = 0;
 
if(pTxBuff->Locked == TRUE) return(0);
 
// tx-buffer is not in use
// lock the buffer
pTxBuff->Locked = TRUE;
pTxBuff->Locked = TRUE;
pTxBuff->Position = 0;
pTxBuff->pData[pTxBuff->Position++] = '#'; // Start character
pTxBuff->pData[pTxBuff->Position++] = 'a' + Address; // Address (a=0; b=1,...)
179,8 → 179,8
u8 crc1, crc2;
for(i = 0; i < (pRxBuff->Position-3); i++)
{
crc += pRxBuff->pData[i];
}
crc += pRxBuff->pData[i];
}
crc %= 4096;
crc1 = '=' + crc / 64;
crc2 = '=' + crc % 64;
188,8 → 188,8
if((crc1 == pRxBuff->pData[pRxBuff->Position-3]) && (crc2 == pRxBuff->pData[pRxBuff->Position-2]))
{
// checksum is valid
pRxBuff->Position = 0;
pRxBuff->Locked = TRUE; // lock the rxd buffer
pRxBuff->Position = 0;
pRxBuff->Locked = TRUE; // lock the rxd buffer
// if 2nd byte is an 'R' start bootloader
if(pRxBuff->pData[2] == 'R')
{
226,7 → 226,7
{
pSerialMsg->Address = 0;
pSerialMsg->CmdID = ' ';
}
}
}
 
/**************************************************************/
235,10 → 235,11
void MKProtocol_DecodeSerialFrameData(Buffer_t* pRxBuff, SerialMsg_t* pSerialMsg)
{
u8 a,b,c,d;
u8 x,y,z;
u16 ptrIn = 3; // start with first data byte in rx buffer
u16 ptrOut = 3;
u16 len = pRxBuff->DataBytes - 6; // must be a multiple of 4 (3 bytes at begin and 3 bytes at end are no payload )
 
len/=4; // number of 4 byte blocks
while(len)
{
a = pRxBuff->pData[ptrIn++] - '=';
245,15 → 246,10
b = pRxBuff->pData[ptrIn++] - '=';
c = pRxBuff->pData[ptrIn++] - '=';
d = pRxBuff->pData[ptrIn++] - '=';
//if(ptrIn > ReceivedBytes - 3) break;
 
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
 
if(len--) pRxBuff->pData[ptrOut++] = x; else break;
if(len--) pRxBuff->pData[ptrOut++] = y; else break;
if(len--) pRxBuff->pData[ptrOut++] = z; else break;
pRxBuff->pData[ptrOut++] = (a << 2) | (b >> 4);
pRxBuff->pData[ptrOut++] = ((b & 0x0f) << 4) | (c >> 2);
pRxBuff->pData[ptrOut++] = ((c & 0x03) << 6) | d;
}
pSerialMsg->pData = &(pRxBuff->pData[3]);
pSerialMsg->DataLen = ptrOut - 3; // return number of data in bytes