Subversion Repositories NaviCtrl

Rev

Rev 418 | Rev 432 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 418 Rev 430
Line 5... Line 5...
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
Line 30... Line 30...
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + 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
35
// + 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 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
Line 53... Line 53...
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
#include <stdarg.h>
56
#include <stdarg.h>
57
#include "91x_lib.h"
57
#include "91x_lib.h"
58
#include "mkprotocol.h"
58
#include "mkprotocol.h" 
59
#include "ramfunc.h"
59
#include "ramfunc.h"
60
#include "usb.h"
60
#include "usb.h"
61
#include "uart1.h"
61
#include "uart1.h"
Line 62... Line 62...
62
 
62
 
Line 71... Line 71...
71
        u16 ptr = 0;
71
        u16 ptr = 0;
72
        u16 tmpCRC = 0, i;
72
        u16 tmpCRC = 0, i;
Line 73... Line 73...
73
 
73
 
74
        u8* pdata = NULL;
74
        u8* pdata = NULL;
75
        int len = 0;
75
        int len = 0;
76
 
76
       
Line 77... Line 77...
77
        if(pTxBuff->Locked == TRUE) return(0);
77
        if(pTxBuff->Locked == TRUE) return(0);
78
 
78
 
79
        // tx-buffer is not in use
79
        // tx-buffer is not in use
80
        // lock the buffer
80
        // lock the buffer
81
        pTxBuff->Locked = TRUE;
81
        pTxBuff->Locked = TRUE;
82
        pTxBuff->Position = 0;
82
        pTxBuff->Position = 0;
83
        pTxBuff->pData[pTxBuff->Position++] = '#';                          // Start character
83
        pTxBuff->pData[pTxBuff->Position++] = '#';                          // Start character
Line 177... Line 177...
177
                                // calculate checksum from transmitted data
177
                                // calculate checksum from transmitted data
178
                                u16 crc = 0, i;
178
                                u16 crc = 0, i;
179
                                u8 crc1, crc2;
179
                                u8 crc1, crc2;
180
                                for(i = 0; i < (pRxBuff->Position-3); i++)
180
                                for(i = 0; i < (pRxBuff->Position-3); i++)
181
                                {
181
                                {
182
                                        crc +=  pRxBuff->pData[i];
182
                                        crc +=  pRxBuff->pData[i];  
183
                                }
183
                                }              
184
                                crc %= 4096;
184
                                crc %= 4096;
185
                                crc1 = '=' + crc / 64;
185
                                crc1 = '=' + crc / 64;
186
                                crc2 = '=' + crc % 64;
186
                                crc2 = '=' + crc % 64;
187
                                // compare checksum to transmitted checksum bytes
187
                                // compare checksum to transmitted checksum bytes
188
                                if((crc1 == pRxBuff->pData[pRxBuff->Position-3]) && (crc2 == pRxBuff->pData[pRxBuff->Position-2]))
188
                                if((crc1 == pRxBuff->pData[pRxBuff->Position-3]) && (crc2 == pRxBuff->pData[pRxBuff->Position-2]))
189
                                {
189
                                {
190
                                    // checksum is valid
190
                                    // checksum is valid
191
                                        pRxBuff->Position = 0;
191
                                        pRxBuff->Position = 0;                                 
192
                                        pRxBuff->Locked = TRUE;                                     // lock the rxd buffer
192
                                        pRxBuff->Locked = TRUE;                                     // lock the rxd buffer 
193
                                        // if 2nd byte is an 'R' start bootloader
193
                                        // if 2nd byte is an 'R' start bootloader
194
                                        if(pRxBuff->pData[2] == 'R')
194
                                        if(pRxBuff->pData[2] == 'R')
195
                                        {
195
                                        {
196
                                                PowerOff();
196
                                                PowerOff();
197
                                                VIC_DeInit();
197
                                                VIC_DeInit();
Line 224... Line 224...
224
        }
224
        }
225
        else
225
        else
226
        {
226
        {
227
                pSerialMsg->Address = 0;
227
                pSerialMsg->Address = 0;
228
                pSerialMsg->CmdID = ' ';
228
                pSerialMsg->CmdID = ' ';
229
        }
229
        }      
230
}
230
}
Line 231... Line 231...
231
 
231
 
232
/**************************************************************/
232
/**************************************************************/
233
/* Decode data                                                */
233
/* Decode data                                                */
Line 238... Line 238...
238
        u16 ptrIn = 3; // start with first data byte in rx buffer
238
        u16 ptrIn = 3; // start with first data byte in rx buffer
239
        u16 ptrOut = 3;
239
        u16 ptrOut = 3;
240
        u16 len = pRxBuff->DataBytes - 6;        // must be a multiple of 4 (3 bytes at begin and 3 bytes at end are no payload )
240
        u16 len = pRxBuff->DataBytes - 6;        // must be a multiple of 4 (3 bytes at begin and 3 bytes at end are no payload )
Line 241... Line 241...
241
 
241
 
242
        len/=4;   // number of 4 byte blocks
242
        len/=4;   // number of 4 byte blocks
243
        while(len)
243
        while(len--)
244
        {
244
        {
245
                a = pRxBuff->pData[ptrIn++] - '=';
245
                a = pRxBuff->pData[ptrIn++] - '=';
246
                b = pRxBuff->pData[ptrIn++] - '=';
246
                b = pRxBuff->pData[ptrIn++] - '=';
247
                c = pRxBuff->pData[ptrIn++] - '=';
247
                c = pRxBuff->pData[ptrIn++] - '=';
Line 254... Line 254...
254
        pSerialMsg->pData = &(pRxBuff->pData[3]);
254
        pSerialMsg->pData = &(pRxBuff->pData[3]);
255
        pSerialMsg->DataLen = ptrOut - 3;       // return number of data in bytes
255
        pSerialMsg->DataLen = ptrOut - 3;       // return number of data in bytes
256
        pRxBuff->Position = 0;
256
        pRxBuff->Position = 0;
257
        pRxBuff->DataBytes = ptrOut;
257
        pRxBuff->DataBytes = ptrOut;
258
}
258
}
-
 
259
 
-
 
260
/*
-
 
261
void MKProtocol_DecodeSerialFrameData(Buffer_t* pRxBuff, SerialMsg_t* pSerialMsg)
-
 
262
{
-
 
263
        u8 a,b,c,d;
-
 
264
        u8 x,y,z;
-
 
265
        u16 ptrIn = 3; // start with first data byte in rx buffer
-
 
266
        u16 ptrOut = 3;
-
 
267
        u16 len = pRxBuff->DataBytes - 6;        // must be a multiple of 4 (3 bytes at begin and 3 bytes at end are no payload )
-
 
268
        while(len)
-
 
269
        {
-
 
270
                a = pRxBuff->pData[ptrIn++] - '=';
-
 
271
                b = pRxBuff->pData[ptrIn++] - '=';
-
 
272
                c = pRxBuff->pData[ptrIn++] - '=';
-
 
273
                d = pRxBuff->pData[ptrIn++] - '=';
-
 
274
                //if(ptrIn > ReceivedBytes - 3) break;
-
 
275
 
-
 
276
                x = (a << 2) | (b >> 4);
-
 
277
                y = ((b & 0x0f) << 4) | (c >> 2);
-
 
278
                z = ((c & 0x03) << 6) | d;
-
 
279
 
-
 
280
                if(len--) pRxBuff->pData[ptrOut++] = x; else break;
-
 
281
                if(len--) pRxBuff->pData[ptrOut++] = y; else break;
-
 
282
                if(len--) pRxBuff->pData[ptrOut++] = z; else break;
-
 
283
        }
-
 
284
        pSerialMsg->pData = &(pRxBuff->pData[3]);
-
 
285
        pSerialMsg->DataLen = ptrOut - 3;       // return number of data in bytes
-
 
286
        pRxBuff->Position = 0;
-
 
287
        pRxBuff->DataBytes = ptrOut;
-
 
288
}
-
 
289
*/
-
 
290