Subversion Repositories FlightCtrl

Rev

Rev 2176 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2176 Rev 2177
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// + Software Nutzungsbedingungen (english version: see below)
4
// + Software Nutzungsbedingungen (english version: see below)
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
19
// + des Mitverschuldens offen.
19
// + des Mitverschuldens offen.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
27
// +  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.
27
// +  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.
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Software LICENSING TERMS
29
// + Software LICENSING TERMS
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
32
// + 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 
32
// + 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 
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
34
// + The Software may only be used with the Licensor's products.
34
// + The Software may only be used with the Licensor's products.
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
37
// + agreement shall be the property of the Licensor.
37
// + agreement shall be the property of the Licensor.
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
40
// + The customer shall be responsible for taking reasonable precautions
40
// + The customer shall be responsible for taking reasonable precautions
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
50
// + #### END OF LICENSING TERMS ####
50
// + #### END OF LICENSING TERMS ####
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
#include <stdarg.h>
53
#include <stdarg.h>
54
#include <string.h>
54
#include <string.h>
55
#include <avr/pgmspace.h>
55
#include <avr/pgmspace.h>
56
#include "main.h"
56
#include "main.h"
57
#include "uart.h"
57
#include "uart.h"
58
#include "libfc.h"
58
#include "libfc.h"
59
#include "eeprom.h"
59
#include "eeprom.h"
60
 
60
 
61
#define FC_ADDRESS 1
61
#define FC_ADDRESS 1
62
#define NC_ADDRESS 2
62
#define NC_ADDRESS 2
63
#define MK3MAG_ADDRESS 3
63
#define MK3MAG_ADDRESS 3
64
#define BL_CTRL_ADDRESS 5
64
#define BL_CTRL_ADDRESS 5
65
 
65
 
66
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
66
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
67
#define MAX_SENDE_BUFF     175
67
#define MAX_SENDE_BUFF     175
68
#define MAX_EMPFANGS_BUFF  175
68
#define MAX_EMPFANGS_BUFF  175
69
 
69
 
70
#define BLPARAM_REVISION 1
70
#define BLPARAM_REVISION 1
71
#define MASK_SET_PWM_SCALING            0x01
71
#define MASK_SET_PWM_SCALING            0x01
72
#define MASK_SET_CURRENT_LIMIT          0x02
72
#define MASK_SET_CURRENT_LIMIT          0x02
73
#define MASK_SET_TEMP_LIMIT                     0x04
73
#define MASK_SET_TEMP_LIMIT                     0x04
74
#define MASK_SET_CURRENT_SCALING        0x08
74
#define MASK_SET_CURRENT_SCALING        0x08
75
#define MASK_SET_BITCONFIG                      0x10
75
#define MASK_SET_BITCONFIG                      0x10
76
#define MASK_RESET_CAPCOUNTER           0x20
76
#define MASK_RESET_CAPCOUNTER           0x20
77
#define MASK_SET_DEFAULT_PARAMS         0x40
77
#define MASK_SET_DEFAULT_PARAMS         0x40
78
#define MASK_SET_SAVE_EEPROM            0x80
78
#define MASK_SET_SAVE_EEPROM            0x80
79
 
79
 
80
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
80
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
81
unsigned char DisplayLine = 0;
81
unsigned char DisplayLine = 0;
82
unsigned volatile char SioTmp = 0;
82
unsigned volatile char SioTmp = 0;
83
unsigned volatile char NeuerDatensatzEmpfangen = 0;
83
unsigned volatile char NeuerDatensatzEmpfangen = 0;
84
unsigned volatile char NeueKoordinateEmpfangen = 0;
84
unsigned volatile char NeueKoordinateEmpfangen = 0;
85
unsigned volatile char UebertragungAbgeschlossen = 1;
85
unsigned volatile char UebertragungAbgeschlossen = 1;
86
unsigned volatile char CntCrcError = 0;
86
unsigned volatile char CntCrcError = 0;
87
unsigned volatile char AnzahlEmpfangsBytes = 0;
87
unsigned volatile char AnzahlEmpfangsBytes = 0;
88
unsigned volatile char TxdBuffer[MAX_SENDE_BUFF];
88
unsigned volatile char TxdBuffer[MAX_SENDE_BUFF];
89
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
89
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
90
 
90
 
91
unsigned char *pRxData = 0;
91
unsigned char *pRxData = 0;
92
unsigned char RxDataLen = 0;
92
unsigned char RxDataLen = 0;
93
unsigned volatile char PC_DebugTimeout = 0;
93
unsigned volatile char PC_DebugTimeout = 0;
94
unsigned volatile char PC_MotortestActive = 0;
94
unsigned volatile char PC_MotortestActive = 0;
95
unsigned char DebugTextAnforderung = 255;
95
unsigned char DebugTextAnforderung = 255;
96
 
96
 
97
unsigned char PcZugriff = 100;
97
unsigned char PcZugriff = 100;
98
unsigned char MotorTest[16];
98
unsigned char MotorTest[16];
99
unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl
99
unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl
100
unsigned char ConfirmFrame;
100
unsigned char ConfirmFrame;
101
struct str_DebugOut    DebugOut;
101
struct str_DebugOut    DebugOut;
102
struct str_ExternControl  ExternControl;
102
struct str_ExternControl  ExternControl;
103
struct str_VersionInfo VersionInfo;
103
struct str_VersionInfo VersionInfo;
104
struct str_WinkelOut WinkelOut;
104
struct str_WinkelOut WinkelOut;
105
struct str_Data3D Data3D;
105
struct str_Data3D Data3D;
106
 
106
 
107
int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D;
107
int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D;
108
unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0;
108
unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0;
109
unsigned int AboTimeOut = 0;
109
unsigned int AboTimeOut = 0;
110
unsigned volatile char ReceiverUpdateModeActive = 0; // 1 = Update      2 = JetiBox-Simulation
110
unsigned volatile char ReceiverUpdateModeActive = 0; // 1 = Update      2 = JetiBox-Simulation
-
 
111
 
-
 
112
 
-
 
113
 
-
 
114
 
-
 
115
       
-
 
116
#ifdef WITH_FULL_ANALOG_TEXT            ///  MartinW main.h means no memsave
-
 
117
#warning : "### with  normal ANALOG_TEXT[32][16] ###"
111
 
118
       
112
const unsigned char ANALOG_TEXT[32][16] PROGMEM =
119
const unsigned char ANALOG_TEXT[32][16] PROGMEM =
113
{
120
{
114
   //1234567890123456
121
   //1234567890123456
115
    "AngleNick       ", //0
122
    "AngleNick       ", //0
116
    "AngleRoll       ",
123
    "AngleRoll       ",
117
    "AccNick         ",
124
    "AccNick         ",
118
    "AccRoll         ",
125
    "AccRoll         ",
119
    "YawGyro         ",
126
    "YawGyro         ",
120
    "Height Value    ", //5
127
    "Height Value    ", //5
121
    "AccZ            ",
128
    "AccZ            ",
122
    "Gas             ",
129
    "Gas             ",
123
    "Compass Value   ",
130
    "Compass Value   ",
124
    "Voltage [0.1V]  ",
131
    "Voltage [0.1V]  ",
125
    "Receiver Level  ", //10
132
    "Receiver Level  ", //10
126
    "Gyro Compass    ",
133
    "Gyro Compass    ",
127
    "Motor 1         ",
134
    "Motor 1         ",
128
    "Motor 2         ",
135
    "Motor 2         ",
129
    "Motor 3         ",
136
    "Motor 3         ",
130
    "Motor 4         ", //15
137
    "Motor 4         ", //15
131
    "16              ",
138
    "PAN-Cos         ",//MartinR
132
    "17              ",
139
    "PAN-Sin         ",//MartinR
133
    "18              ",
140
    "PAN-Servo       ",//MartinR
134
    "19              ",
141
    "Servo-Roll      ",//MartinR
135
    "Servo           ", //20
142
    "Servo-Nick      ", //20
136
    "Hovergas        ",
143
    "Hovergas        ",
137
    "Current [0.1A]  ",
144
    "Current [0.1A]  ",
138
    "Capacity [mAh]  ",
145
    "Capacity [mAh]  ",
139
    "Height Setpoint ",
146
    "Hight Setpoint  ",
140
    "25              ", //25
147
    "FC_StatusFlags  ", //25 ///MartinR
141
    "26              ", //"26 CPU OverLoad ",
148
    "FC_StatusFlags2 ",///MartinR
142
    "Compass Setpoint",
149
    "Compass Setpoint",
143
    "I2C-Error       ",
150
    "I2C-Error       ",
144
    "BL Limit        ",
151
    "BL Limit        ",
145
    "GPS_Nick        ", //30
152
    "GPS_Nick        ", //30
146
    "GPS_Roll        "
153
    "GPS_Roll        "
147
};
154
};
148
   
155
   
-
 
156
       
-
 
157
#else
-
 
158
#warning : "### with  reduced ANALOG_TEXT[32][13] ###"  
-
 
159
const unsigned char ANALOG_TEXT[32][13] PROGMEM =
-
 
160
{
-
 
161
   //1234567890123456
-
 
162
    "AngleNick    ", //0
-
 
163
    "AngleRoll    ",
-
 
164
    "AccNick      ",
-
 
165
    "AccRoll      ",
-
 
166
    "YawGyro      ",
-
 
167
    "Height Value ", //5
-
 
168
    "AccZ         ",
-
 
169
    "Gas          ",
-
 
170
    "Compass Value",
-
 
171
    "Voltage[0.1V]",
-
 
172
    "ReceiverLevel", //10
-
 
173
    "Gyro Compass ",
-
 
174
    "Motor 1      ",
-
 
175
    "Motor 2      ",
-
 
176
    "Motor 3      ",
-
 
177
    "Motor 4      ", //15
-
 
178
    "PAN-cos      ",//MartinR
-
 
179
    "PAN-sin      ",//MartinR
-
 
180
    "PAN-Servo    ",//MartinR
-
 
181
    "Servo-Roll   ",//MartinR
-
 
182
    "Servo-Nick   ", //20
-
 
183
    "Hovergas     ",
-
 
184
    "Current[0.1A]",
-
 
185
    "Capacity[mAh]",
-
 
186
    "Hight Setp   ",
-
 
187
    "FC_Flags     ", //25 ///MartinR
-
 
188
    "FC_Flags2    ",///MartinR
-
 
189
    "Compass Setp ",
-
 
190
    "I2C-Error    ",
-
 
191
    "BL Limit     ",
-
 
192
    "GPS_Nick     ", //30
-
 
193
    "GPS_Roll     "
-
 
194
};      
-
 
195
       
-
 
196
       
-
 
197
#endif
149
       
198
 
150
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151
//++ Sende-Part der Datenübertragung
200
//++ Sende-Part der Datenübertragung
152
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
201
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153
ISR(USART0_TX_vect)
202
ISR(USART0_TX_vect)
154
{
203
{
155
 static unsigned int ptr = 0;
204
 static unsigned int ptr = 0;
156
 unsigned char tmp_tx;
205
 unsigned char tmp_tx;
157
 
206
 
158
 if(!UebertragungAbgeschlossen)
207
 if(!UebertragungAbgeschlossen)
159
  {
208
  {
160
   ptr++;                    // die [0] wurde schon gesendet
209
   ptr++;                    // die [0] wurde schon gesendet
161
   tmp_tx = TxdBuffer[ptr];
210
   tmp_tx = TxdBuffer[ptr];
162
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
211
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
163
    {
212
    {
164
     ptr = 0;
213
     ptr = 0;
165
     UebertragungAbgeschlossen = 1;
214
     UebertragungAbgeschlossen = 1;
166
    }
215
    }
167
   UDR0 = tmp_tx;
216
   UDR0 = tmp_tx;
168
  }
217
  }
169
  else ptr = 0;
218
  else ptr = 0;
170
}
219
}
171
 
220
 
172
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
221
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
222
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
174
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
223
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
175
ISR(USART0_RX_vect)
224
ISR(USART0_RX_vect)
176
{
225
{
177
 static unsigned int crc;
226
 static unsigned int crc;
178
 static unsigned char crc1,crc2,buf_ptr;
227
 static unsigned char crc1,crc2,buf_ptr;
179
 static unsigned char UartState = 0;
228
 static unsigned char UartState = 0;
180
 unsigned char CrcOkay = 0;
229
 unsigned char CrcOkay = 0;
181
 
230
 
182
 if (ReceiverUpdateModeActive == 1) {   UDR1 = UDR0; return; }          // 1 = Update      
231
 if (ReceiverUpdateModeActive == 1) {   UDR1 = UDR0; return; }          // 1 = Update      
183
 if (ReceiverUpdateModeActive == 2) {   RxdBuffer[0] = UDR0; return; }  // 2 = JetiBox-Simulation 
232
 if (ReceiverUpdateModeActive == 2) {   RxdBuffer[0] = UDR0; return; }  // 2 = JetiBox-Simulation 
184
 
233
 
185
 SioTmp = UDR0;
234
 SioTmp = UDR0;
186
 
235
 
187
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
236
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
188
 if(SioTmp == '\r' && UartState == 2)
237
 if(SioTmp == '\r' && UartState == 2)
189
  {
238
  {
190
   UartState = 0;
239
   UartState = 0;
191
   crc -= RxdBuffer[buf_ptr-2];
240
   crc -= RxdBuffer[buf_ptr-2];
192
   crc -= RxdBuffer[buf_ptr-1];
241
   crc -= RxdBuffer[buf_ptr-1];
193
   crc %= 4096;
242
   crc %= 4096;
194
   crc1 = '=' + crc / 64;
243
   crc1 = '=' + crc / 64;
195
   crc2 = '=' + crc % 64;
244
   crc2 = '=' + crc % 64;
196
   CrcOkay = 0;
245
   CrcOkay = 0;
197
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
246
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
198
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
247
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
199
    {
248
    {
200
     NeuerDatensatzEmpfangen = 1;
249
     NeuerDatensatzEmpfangen = 1;
201
         AnzahlEmpfangsBytes = buf_ptr + 1;
250
         AnzahlEmpfangsBytes = buf_ptr + 1;
202
     RxdBuffer[buf_ptr] = '\r';
251
     RxdBuffer[buf_ptr] = '\r';
203
         if(RxdBuffer[2] == 'R')
252
         if(RxdBuffer[2] == 'R')
204
          {
253
          {
-
 
254
         
-
 
255
#ifdef WITH_MKTOOL_Display                      ///  MartinW main.h
-
 
256
#warning : "### with  MKTool Display ###"
205
           LcdClear();
257
           LcdClear();
-
 
258
#endif
-
 
259
 
206
           wdt_enable(WDTO_250MS); // Reset-Commando
260
           wdt_enable(WDTO_250MS); // Reset-Commando
207
           ServoActive = 0;
261
           ServoActive = 0;
208
          }
262
          }
209
 
263
 
210
        }
264
        }
211
  }
265
  }
212
  else
266
  else
213
  switch(UartState)
267
  switch(UartState)
214
  {
268
  {
215
   case 0:
269
   case 0:
216
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
270
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
217
                  buf_ptr = 0;
271
                  buf_ptr = 0;
218
                  RxdBuffer[buf_ptr++] = SioTmp;
272
                  RxdBuffer[buf_ptr++] = SioTmp;
219
                  crc = SioTmp;
273
                  crc = SioTmp;
220
          break;
274
          break;
221
   case 1: // Adresse auswerten
275
   case 1: // Adresse auswerten
222
                  UartState++;
276
                  UartState++;
223
                  RxdBuffer[buf_ptr++] = SioTmp;
277
                  RxdBuffer[buf_ptr++] = SioTmp;
224
                  crc += SioTmp;
278
                  crc += SioTmp;
225
                  break;
279
                  break;
226
   case 2: //  Eingangsdaten sammeln
280
   case 2: //  Eingangsdaten sammeln
227
                  RxdBuffer[buf_ptr] = SioTmp;
281
                  RxdBuffer[buf_ptr] = SioTmp;
228
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
282
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
229
                  else UartState = 0;
283
                  else UartState = 0;
230
                  crc += SioTmp;
284
                  crc += SioTmp;
231
                  break;
285
                  break;
232
   default:
286
   default:
233
          UartState = 0;
287
          UartState = 0;
234
          break;
288
          break;
235
  }
289
  }
236
}
290
}
237
 
291
 
238
 
292
 
239
// --------------------------------------------------------------------------
293
// --------------------------------------------------------------------------
240
void AddCRC(unsigned int wieviele)
294
void AddCRC(unsigned int wieviele)
241
{
295
{
242
 unsigned int tmpCRC = 0,i;
296
 unsigned int tmpCRC = 0,i;
243
 for(i = 0; i < wieviele;i++)
297
 for(i = 0; i < wieviele;i++)
244
  {
298
  {
245
   tmpCRC += TxdBuffer[i];
299
   tmpCRC += TxdBuffer[i];
246
  }
300
  }
247
   tmpCRC %= 4096;
301
   tmpCRC %= 4096;
248
   TxdBuffer[i++] = '=' + tmpCRC / 64;
302
   TxdBuffer[i++] = '=' + tmpCRC / 64;
249
   TxdBuffer[i++] = '=' + tmpCRC % 64;
303
   TxdBuffer[i++] = '=' + tmpCRC % 64;
250
   TxdBuffer[i++] = '\r';
304
   TxdBuffer[i++] = '\r';
251
  UebertragungAbgeschlossen = 0;
305
  UebertragungAbgeschlossen = 0;
252
  UDR0 = TxdBuffer[0];
306
  UDR0 = TxdBuffer[0];
253
}
307
}
254
 
308
 
255
 
309
 
256
 
310
 
257
// --------------------------------------------------------------------------
311
// --------------------------------------------------------------------------
258
void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len)
312
void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len)
259
{
313
{
260
 va_list ap;
314
 va_list ap;
261
 unsigned int pt = 0;
315
 unsigned int pt = 0;
262
 unsigned char a,b,c;
316
 unsigned char a,b,c;
263
 unsigned char ptr = 0;
317
 unsigned char ptr = 0;
264
 
318
 
265
 unsigned char *snd = 0;
319
 unsigned char *snd = 0;
266
 int len = 0;
320
 int len = 0;
267
 
321
 
268
 TxdBuffer[pt++] = '#';                         // Startzeichen
322
 TxdBuffer[pt++] = '#';                         // Startzeichen
269
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
323
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
270
 TxdBuffer[pt++] = cmd;                         // Commando
324
 TxdBuffer[pt++] = cmd;                         // Commando
271
 
325
 
272
 va_start(ap, BufferAnzahl);
326
 va_start(ap, BufferAnzahl);
273
 if(BufferAnzahl)
327
 if(BufferAnzahl)
274
 {
328
 {
275
                snd = va_arg(ap, unsigned char*);
329
                snd = va_arg(ap, unsigned char*);
276
                len = va_arg(ap, int);
330
                len = va_arg(ap, int);
277
                ptr = 0;
331
                ptr = 0;
278
                BufferAnzahl--;
332
                BufferAnzahl--;
279
 }
333
 }
280
 while(len)
334
 while(len)
281
  {
335
  {
282
        if(len)
336
        if(len)
283
        {
337
        {
284
           a = snd[ptr++];
338
           a = snd[ptr++];
285
           len--;
339
           len--;
286
           if((!len) && BufferAnzahl)
340
           if((!len) && BufferAnzahl)
287
                {
341
                {
288
                        snd = va_arg(ap, unsigned char*);
342
                        snd = va_arg(ap, unsigned char*);
289
                        len = va_arg(ap, int);
343
                        len = va_arg(ap, int);
290
                        ptr = 0;
344
                        ptr = 0;
291
                        BufferAnzahl--;
345
                        BufferAnzahl--;
292
                }
346
                }
293
        }
347
        }
294
        else a = 0;
348
        else a = 0;
295
        if(len)
349
        if(len)
296
        {
350
        {
297
                b = snd[ptr++];
351
                b = snd[ptr++];
298
                len--;
352
                len--;
299
                if((!len) && BufferAnzahl)
353
                if((!len) && BufferAnzahl)
300
                {
354
                {
301
                        snd = va_arg(ap, unsigned char*);
355
                        snd = va_arg(ap, unsigned char*);
302
                        len = va_arg(ap, int);
356
                        len = va_arg(ap, int);
303
                        ptr = 0;
357
                        ptr = 0;
304
                        BufferAnzahl--;
358
                        BufferAnzahl--;
305
                }
359
                }
306
        }
360
        }
307
        else b = 0;
361
        else b = 0;
308
        if(len)
362
        if(len)
309
        {
363
        {
310
                c = snd[ptr++];
364
                c = snd[ptr++];
311
                len--;
365
                len--;
312
                if((!len) && BufferAnzahl)
366
                if((!len) && BufferAnzahl)
313
                {
367
                {
314
                        snd = va_arg(ap, unsigned char*);
368
                        snd = va_arg(ap, unsigned char*);
315
                        len = va_arg(ap, int);
369
                        len = va_arg(ap, int);
316
                        ptr = 0;
370
                        ptr = 0;
317
                        BufferAnzahl--;
371
                        BufferAnzahl--;
318
                }
372
                }
319
        }
373
        }
320
        else c = 0;
374
        else c = 0;
321
   TxdBuffer[pt++] = '=' + (a >> 2);
375
   TxdBuffer[pt++] = '=' + (a >> 2);
322
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
376
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
323
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
377
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
324
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
378
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
325
  }
379
  }
326
 va_end(ap);
380
 va_end(ap);
327
 AddCRC(pt);
381
 AddCRC(pt);
328
}
382
}
329
 
383
 
330
// --------------------------------------------------------------------------
384
// --------------------------------------------------------------------------
331
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
385
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
332
{
386
{
333
 unsigned char a,b,c,d;
387
 unsigned char a,b,c,d;
334
 unsigned char x,y,z;
388
 unsigned char x,y,z;
335
 unsigned char ptrIn = 3; // start at begin of data block
389
 unsigned char ptrIn = 3; // start at begin of data block
336
 unsigned char ptrOut = 3;
390
 unsigned char ptrOut = 3;
337
 unsigned char len = AnzahlEmpfangsBytes - 6; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers  ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab.
391
 unsigned char len = AnzahlEmpfangsBytes - 6; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers  ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab.
338
 
392
 
339
 while(len)
393
 while(len)
340
  {
394
  {
341
   a = RxdBuffer[ptrIn++] - '=';
395
   a = RxdBuffer[ptrIn++] - '=';
342
   b = RxdBuffer[ptrIn++] - '=';
396
   b = RxdBuffer[ptrIn++] - '=';
343
   c = RxdBuffer[ptrIn++] - '=';
397
   c = RxdBuffer[ptrIn++] - '=';
344
   d = RxdBuffer[ptrIn++] - '=';
398
   d = RxdBuffer[ptrIn++] - '=';
345
 
399
 
346
   x = (a << 2) | (b >> 4);
400
   x = (a << 2) | (b >> 4);
347
   y = ((b & 0x0f) << 4) | (c >> 2);
401
   y = ((b & 0x0f) << 4) | (c >> 2);
348
   z = ((c & 0x03) << 6) | d;
402
   z = ((c & 0x03) << 6) | d;
349
 
403
 
350
   if(len--) RxdBuffer[ptrOut++] = x; else break;
404
   if(len--) RxdBuffer[ptrOut++] = x; else break;
351
   if(len--) RxdBuffer[ptrOut++] = y; else break;
405
   if(len--) RxdBuffer[ptrOut++] = y; else break;
352
   if(len--) RxdBuffer[ptrOut++] = z;   else break;
406
   if(len--) RxdBuffer[ptrOut++] = z;   else break;
353
  }
407
  }
354
        pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte
408
        pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte
355
        RxDataLen = ptrOut - 3;  // wie viele Bytes wurden dekodiert?
409
        RxDataLen = ptrOut - 3;  // wie viele Bytes wurden dekodiert?
356
 
410
 
357
}
411
}
358
 
412
 
359
// --------------------------------------------------------------------------
413
// --------------------------------------------------------------------------
360
void BearbeiteRxDaten(void)
414
void BearbeiteRxDaten(void)
361
{
415
{
362
 if(!NeuerDatensatzEmpfangen) return;
416
 if(!NeuerDatensatzEmpfangen) return;
363
 
417
 
364
        unsigned char tempchar1, tempchar2;
418
        unsigned char tempchar1, tempchar2;
365
        Decode64(); // dekodiere datenblock im Empfangsbuffer
419
        Decode64(); // dekodiere datenblock im Empfangsbuffer
366
        switch(RxdBuffer[1]-'a') // check for Slave Address
420
        switch(RxdBuffer[1]-'a') // check for Slave Address
367
        {
421
        {
368
                case FC_ADDRESS: // FC special commands
422
                case FC_ADDRESS: // FC special commands
369
                switch(RxdBuffer[2])
423
                switch(RxdBuffer[2])
370
                {
424
                {
371
                        case 'K':// Kompasswert
425
                        case 'K':// Kompasswert
372
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
426
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
373
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
427
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
374
                                        break;
428
                                        break;
375
                        case 't':// Motortest
429
                        case 't':// Motortest
376
                                if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
430
                                if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
377
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
431
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
378
                                        PC_MotortestActive = 240;
432
                                        PC_MotortestActive = 240;
379
                                        //while(!UebertragungAbgeschlossen);
433
                                        //while(!UebertragungAbgeschlossen);
380
                                        //SendOutData('T', MeineSlaveAdresse, 0);
434
                                        //SendOutData('T', MeineSlaveAdresse, 0);
381
                                        PcZugriff = 255;
435
                                        PcZugriff = 255;
382
                                        break;
436
                                        break;
383
 
437
 
384
                        case 'n':// "Get Mixer
438
                        case 'n':// "Get Mixer
385
                                        while(!UebertragungAbgeschlossen);
439
                                        while(!UebertragungAbgeschlossen);
386
                    SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1);
440
                    SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1);
387
                                        Debug("Mixer lesen");
441
                                        Debug("Mixer lesen");
388
                                        break;
442
                                        break;
389
 
443
 
390
                        case 'm':// "Write Mixer
444
                        case 'm':// "Write Mixer
391
                    if(pRxData[0] == EEMIXER_REVISION)
445
                    if(pRxData[0] == EEMIXER_REVISION)
392
                                        {
446
                                        {
393
                       memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1);
447
                       memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1);
394
                       MixerTable_WriteToEEProm();
448
                       MixerTable_WriteToEEProm();
395
                                           tempchar1 = 1;
449
                                           tempchar1 = 1;
396
                                           VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER;
450
                                           VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER;
397
                                        }
451
                                        }
398
                    else
452
                    else
399
                    {
453
                    {
400
                                                tempchar1 = 0;
454
                                                tempchar1 = 0;
401
                                        }
455
                                        }
402
                                        while(!UebertragungAbgeschlossen);
456
                                        while(!UebertragungAbgeschlossen);
403
                                        SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
457
                                        SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
404
                                        break;
458
                                        break;
405
 
459
 
406
                        case 'p': // get PPM Channels
460
                        case 'p': // get PPM Channels
407
                                        GetPPMChannelAnforderung = 1;
461
                                        GetPPMChannelAnforderung = 1;
408
                                        PcZugriff = 255;
462
                                        PcZugriff = 255;
409
                                        break;
463
                                        break;
410
 
464
 
411
                        case 'q':// "Get"-Anforderung für Settings
465
                        case 'q':// "Get"-Anforderung für Settings
412
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
466
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
413
                                        if((10 <= pRxData[0]) && (pRxData[0] < 20))
467
                                        if((10 <= pRxData[0]) && (pRxData[0] < 20))
414
                                        {
468
                                        {
415
                                                tempchar1 = pRxData[0] - 10;
469
                                                tempchar1 = pRxData[0] - 10;
416
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
470
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
417
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
471
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
418
                                                SetDefaultParameter(tempchar1, 1);
472
                                                SetDefaultParameter(tempchar1, 1);
419
                                        }
473
                                        }
420
                                        else if((20 <= pRxData[0]) && (pRxData[0] < 30))
474
                                        else if((20 <= pRxData[0]) && (pRxData[0] < 30))
421
                                        {
475
                                        {
422
                                                tempchar1 = pRxData[0] - 20;
476
                                                tempchar1 = pRxData[0] - 20;
423
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
477
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
424
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
478
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
425
                                                SetDefaultParameter(tempchar1, 0);
479
                                                SetDefaultParameter(tempchar1, 0);
426
                                        }
480
                                        }
427
                                        else
481
                                        else
428
                                        {
482
                                        {
429
                                                tempchar1 = pRxData[0];
483
                                                tempchar1 = pRxData[0];
430
                                                if(tempchar1 == 0xFF)
484
                                                if(tempchar1 == 0xFF)
431
                                                {
485
                                                {
432
                                                        tempchar1 = GetActiveParamSet();
486
                                                        tempchar1 = GetActiveParamSet();
433
                                                }
487
                                                }
434
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
488
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
435
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
489
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
436
                                                // load requested parameter set
490
                                                // load requested parameter set
437
                                                ParamSet_ReadFromEEProm(tempchar1);
491
                                                ParamSet_ReadFromEEProm(tempchar1);
438
                                        }
492
                                        }
439
                                        while(!UebertragungAbgeschlossen);
493
                                        while(!UebertragungAbgeschlossen);
440
                                        SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1);
494
                                        SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1);
441
                                        Debug("Lese Setting %d", tempchar1);
495
                                        Debug("Lese Setting %d", tempchar1);
442
 
496
 
443
                                        break;
497
                                        break;
444
 
498
 
445
                        case 's': // Parametersatz speichern
499
                        case 's': // Parametersatz speichern
446
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range
500
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range
447
                                        {
501
                                        {
448
                                                memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1);
502
                                                memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1);
449
                                                ParamSet_WriteToEEProm(pRxData[0]);
503
                                                ParamSet_WriteToEEProm(pRxData[0]);
450
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
504
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
451
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
505
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
452
                                                tempchar1 = GetActiveParamSet();
506
                                                tempchar1 = GetActiveParamSet();
453
                                        }
507
                                        }
454
                                        else
508
                                        else
455
                                        {
509
                                        {
456
                                                tempchar1 = 0; // mark in response an invlid setting
510
                                                tempchar1 = 0; // mark in response an invlid setting
457
                                        }
511
                                        }
458
                                        while(!UebertragungAbgeschlossen);
512
                                        while(!UebertragungAbgeschlossen);
459
                                        SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
513
                                        SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
460
                                        if(!MotorenEin) Piep(tempchar1,110);
514
                                        if(!MotorenEin) Piep(tempchar1,110);
461
                                        LipoDetection(0);
515
                                        LipoDetection(0);
462
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
516
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
463
                                        break;
517
                                        break;
464
                        case 'f': // auf anderen Parametersatz umschalten
518
                        case 'f': // auf anderen Parametersatz umschalten
465
                                if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]);
519
                                if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]);
466
                                        tempchar1 = GetActiveParamSet();
520
                                        tempchar1 = GetActiveParamSet();
467
                                        while(!UebertragungAbgeschlossen);
521
                                        while(!UebertragungAbgeschlossen);
468
                                        SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
522
                                        SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
469
                                        if(!MotorenEin) Piep(tempchar1,110);
523
                                        if(!MotorenEin) Piep(tempchar1,110);
470
                                        LipoDetection(0);
524
                                        LipoDetection(0);
471
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
525
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
472
                                        break;
526
                                        break;
473
                        case 'y':// serial Potis
527
                        case 'y':// serial Potis
474
                                        PPM_in[13] = (signed char) pRxData[0]; PPM_in[14] = (signed char) pRxData[1]; PPM_in[15] = (signed char) pRxData[2]; PPM_in[16] = (signed char) pRxData[3];
528
                                        PPM_in[13] = (signed char) pRxData[0]; PPM_in[14] = (signed char) pRxData[1]; PPM_in[15] = (signed char) pRxData[2]; PPM_in[16] = (signed char) pRxData[3];
475
                                        PPM_in[17] = (signed char) pRxData[4]; PPM_in[18] = (signed char) pRxData[5]; PPM_in[19] = (signed char) pRxData[6]; PPM_in[20] = (signed char) pRxData[7];
529
                                        PPM_in[17] = (signed char) pRxData[4]; PPM_in[18] = (signed char) pRxData[5]; PPM_in[19] = (signed char) pRxData[6]; PPM_in[20] = (signed char) pRxData[7];
476
                                        PPM_in[21] = (signed char) pRxData[8]; PPM_in[22] = (signed char) pRxData[9]; PPM_in[23] = (signed char) pRxData[10]; PPM_in[24] = (signed char) pRxData[11];
530
                                        PPM_in[21] = (signed char) pRxData[8]; PPM_in[22] = (signed char) pRxData[9]; PPM_in[23] = (signed char) pRxData[10]; PPM_in[24] = (signed char) pRxData[11];
477
                                        break;
531
                                        break;
478
 
532
 
479
                        case 'u': // request BL parameter
533
                        case 'u': // request BL parameter
480
                                Debug("Reading BL %d", pRxData[0]);
534
                                Debug("Reading BL %d", pRxData[0]);
481
                                // try to read BL configuration
535
                                // try to read BL configuration
482
                                tempchar2 = I2C_ReadBLConfig(pRxData[0]);
536
                                tempchar2 = I2C_ReadBLConfig(pRxData[0]);
483
                                if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
537
                                if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
484
                                else tempchar1 = 0;
538
                                else tempchar1 = 0;
485
                                while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
539
                                while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
486
                                SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t));
540
                                SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t));
487
                                break;
541
                                break;
488
 
542
 
489
                        case 'w': // write BL parameter
543
                        case 'w': // write BL parameter
490
                                Debug("Writing BL %d", pRxData[0]);
544
                                Debug("Writing BL %d", pRxData[0]);
491
                                if(RxDataLen >= 1+sizeof(BLConfig_t))
545
                                if(RxDataLen >= 1+sizeof(BLConfig_t))
492
                                {
546
                                {
493
                                        memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t));
547
                                        memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t));
494
                                        tempchar2 = I2C_WriteBLConfig(pRxData[0]);
548
                                        tempchar2 = I2C_WriteBLConfig(pRxData[0]);
495
                                        if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
549
                                        if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
496
                                        else tempchar1 = 0; // indicate error
550
                                        else tempchar1 = 0; // indicate error
497
                                        while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
551
                                        while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
498
                                        SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2));
552
                                        SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2));
499
                                }
553
                                }
500
                                break;
554
                                break;
501
                        case 'j':
555
                        case 'j':
502
                                if(MotorenEin) break;
556
                                if(MotorenEin) break;
-
 
557
                       
-
 
558
#ifdef WITH_JETI_SIMULATION             ///  MartinW main.h means no memsave
-
 
559
#warning : "### with  jeti update command ###"
-
 
560
       
-
 
561
 
-
 
562
 
503
                                tempchar1 = LIBFC_GetCPUType();
563
                                tempchar1 = LIBFC_GetCPUType();
504
                                if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P))
564
                                if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P))
505
                                {
565
                                {
506
                                        uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1);
566
                                        uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1);
507
 
567
 
508
                                        cli();
568
                                        cli();
509
 
569
 
510
                                        // UART0 & UART1 disable RX and TX-Interrupt
570
                                        // UART0 & UART1 disable RX and TX-Interrupt
511
                                        UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0));
571
                                        UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0));
512
                                        UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1));
572
                                        UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1));
513
 
573
 
514
                                        // UART0 & UART1 disable receiver and transmitter
574
                                        // UART0 & UART1 disable receiver and transmitter
515
                                        UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0));
575
                                        UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0));
516
                                        UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1));
576
                                        UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1));
517
 
577
 
518
                                        // UART0 & UART1 flush receive buffer explicit
578
                                        // UART0 & UART1 flush receive buffer explicit
519
                                        while ( UCSR1A & (1<<RXC1) ) UDR1;
579
                                        while ( UCSR1A & (1<<RXC1) ) UDR1;
520
                                        while ( UCSR0A & (1<<RXC0) ) UDR0;
580
                                        while ( UCSR0A & (1<<RXC0) ) UDR0;
521
 
581
 
522
 
582
 
523
                                        if(pRxData[0] == 1) ReceiverUpdateModeActive = 2;
583
                                        if(pRxData[0] == 1) ReceiverUpdateModeActive = 2;
524
                                        else
584
                                        else
525
                                        {           // Jeti or HoTT update
585
                                        {           // Jeti or HoTT update
526
//#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
586
//#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
527
                                                if(pRxData[0] == 100)   ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1);  // HoTT
587
                                                if(pRxData[0] == 100)   ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1);  // HoTT
528
//#endif
588
//#endif
529
                                                ReceiverUpdateModeActive = 1;
589
                                                ReceiverUpdateModeActive = 1;
530
                                                // UART0 & UART1 set baudrate
590
                                                // UART0 & UART1 set baudrate
531
                                                UBRR1H = (uint8_t)(ubrr>>8);
591
                                                UBRR1H = (uint8_t)(ubrr>>8);
532
                                                UBRR1L = (uint8_t)ubrr;
592
                                                UBRR1L = (uint8_t)ubrr;
533
                                                UBRR0H = UBRR1H;
593
                                                UBRR0H = UBRR1H;
534
                                                UBRR0L = UBRR1L;
594
                                                UBRR0L = UBRR1L;
535
                                                // UART1 no parity
595
                                                // UART1 no parity
536
                                                UCSR1C &= ~(1 << UPM11);
596
                                                UCSR1C &= ~(1 << UPM11);
537
                                                UCSR1C &= ~(1 << UPM10);
597
                                                UCSR1C &= ~(1 << UPM10);
538
                                                // UART1 8-bit
598
                                                // UART1 8-bit
539
                                                UCSR1B &= ~(1 << UCSZ12);
599
                                                UCSR1B &= ~(1 << UCSZ12);
540
                                                UCSR1C |= (1 << UCSZ11);
600
                                                UCSR1C |= (1 << UCSZ11);
541
                                                UCSR1C |= (1 << UCSZ10);
601
                                                UCSR1C |= (1 << UCSZ10);
542
                                        }
602
                                        }
543
                                        // UART0 & UART1 1 stop bit
603
                                        // UART0 & UART1 1 stop bit
544
                                        UCSR1C &= ~(1 << USBS1);
604
                                        UCSR1C &= ~(1 << USBS1);
545
                                        UCSR0C &= ~(1 << USBS0);
605
                                        UCSR0C &= ~(1 << USBS0);
546
                                        // UART1 clear 9th bit
606
                                        // UART1 clear 9th bit
547
                                        UCSR1B &= ~(1<<TXB81);
607
                                        UCSR1B &= ~(1<<TXB81);
548
                                        // enable receiver and transmitter for UART0 and UART1
608
                                        // enable receiver and transmitter for UART0 and UART1
549
                                        UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
609
                                        UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
550
                                        UCSR1B |= (1 << TXEN1) | (1 << RXEN1);
610
                                        UCSR1B |= (1 << TXEN1) | (1 << RXEN1);
551
                                        // enable RX-Interrupt for UART0 and UART1
611
                                        // enable RX-Interrupt for UART0 and UART1
552
                                        UCSR0B |= (1 << RXCIE0);
612
                                        UCSR0B |= (1 << RXCIE0);
553
                                        UCSR1B |= (1 << RXCIE1);
613
                                        UCSR1B |= (1 << RXCIE1);
554
                                        // disable other Interrupts
614
                                        // disable other Interrupts
555
                                        TIMSK0 = 0;
615
                                        TIMSK0 = 0;
556
                                        TIMSK1 = 0;
616
                                        TIMSK1 = 0;
557
                                        TIMSK2 = 0;
617
                                        TIMSK2 = 0;
558
 
618
 
559
                                        sei();
619
                                        sei();
560
                                }
620
                                }
-
 
621
                               
-
 
622
#else
-
 
623
#warning : "### without  jeti update command ###"       
-
 
624
 
-
 
625
#endif
561
                                break;
626
                                break;
562
 
627
 
563
                } // case FC_ADDRESS:
628
                } // case FC_ADDRESS:
564
 
629
 
565
                default: // any Slave Address
630
                default: // any Slave Address
566
 
631
 
567
                switch(RxdBuffer[2])
632
                switch(RxdBuffer[2])
568
                {
633
                {
569
                        // 't' comand placed here only for compatibility to BL
634
                        // 't' comand placed here only for compatibility to BL
570
                        case 't':// Motortest
635
                        case 't':// Motortest
571
                                if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
636
                                if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
572
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
637
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
573
                                        while(!UebertragungAbgeschlossen);
638
                                        while(!UebertragungAbgeschlossen);
574
                                        SendOutData('T', MeineSlaveAdresse, 0);
639
                                        SendOutData('T', MeineSlaveAdresse, 0);
575
                                        PC_MotortestActive = 250;
640
                                        PC_MotortestActive = 250;
576
                                        PcZugriff = 255;
641
                                        PcZugriff = 255;
577
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
642
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
578
                                        break;
643
                                        break;
579
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
644
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
580
                        case 'K':// Kompasswert
645
                        case 'K':// Kompasswert
581
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
646
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
582
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
647
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
583
                                        break;
648
                                        break;
584
                        case 'a':// Texte der Analogwerte
649
                        case 'a':// Texte der Analogwerte
585
                                        DebugTextAnforderung = pRxData[0];
650
                                        DebugTextAnforderung = pRxData[0];
586
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
651
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
587
                                        PcZugriff = 255;
652
                                        PcZugriff = 255;
588
                                        break;
653
                                        break;
589
                        case 'b':
654
                        case 'b':
590
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
655
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
591
                                        ConfirmFrame = ExternControl.Frame;
656
                                        ConfirmFrame = ExternControl.Frame;
592
                                        PcZugriff = 255;
657
                                        PcZugriff = 255;
593
                                        break;
658
                                        break;
594
                        case 'c': // Poll the 3D-Data
659
                        case 'c': // Poll the 3D-Data
595
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
660
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
596
                                        Intervall3D = pRxData[0] * 10;
661
                                        Intervall3D = pRxData[0] * 10;
597
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
662
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
598
                                        break;
663
                                        break;
599
                        case 'd': // Poll the debug data
664
                        case 'd': // Poll the debug data
600
                                        PcZugriff = 255;
665
                                        PcZugriff = 255;
601
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
666
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
602
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
667
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
603
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
668
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
604
                                        break;
669
                                        break;
605
 
670
 
606
                        case 'h':// x-1 Displayzeilen
671
                        case 'h':// x-1 Displayzeilen
-
 
672
                       
-
 
673
#ifdef WITH_MKTOOL_Display                                                              /// MartinW memorysave
-
 
674
#warning : "### with  MKTool Display ###"
-
 
675
 
607
                                PcZugriff = 255;
676
                                        PcZugriff = 255;
608
                                if((pRxData[0] & 0x80) == 0x00) // old format
677
                                if((pRxData[0] & 0x80) == 0x00) // old format
609
                                        {
678
                                        {
610
                                                DisplayLine = 2;
679
                                                DisplayLine = 2;
611
                                                Display_Interval = 0;
680
                                                Display_Interval = 0;
612
                                        }
681
                                        }
613
                                        else // new format
682
                                        else // new format
614
                                        {
683
                                        {
615
                                                RemoteKeys |= ~pRxData[0];
684
                                                RemoteKeys |= ~pRxData[0];
616
                                                Display_Interval = (unsigned int)pRxData[1] * 10;
685
                                                Display_Interval = (unsigned int)pRxData[1] * 10;
617
                                                DisplayLine = 4;
686
                                                DisplayLine = 4;
618
                                                AboTimeOut = SetDelay(ABO_TIMEOUT);
687
                                                AboTimeOut = SetDelay(ABO_TIMEOUT);
619
                                        }
688
                                        }
620
                                        DebugDisplayAnforderung = 1;
689
                                        DebugDisplayAnforderung = 1;
621
                                        break;
690
                                        break;
622
 
691
 
623
                        case 'l':// x-1 Displayzeilen
692
                        case 'l':// x-1 Displayzeilen
624
                                PcZugriff = 255;
693
                                PcZugriff = 255;
625
                                        MenuePunkt = pRxData[0];
694
                                        MenuePunkt = pRxData[0];
626
                                        DebugDisplayAnforderung1 = 1;
695
                                        DebugDisplayAnforderung1 = 1;
-
 
696
                                       
-
 
697
#endif
627
                                        break;
698
                                        break;
628
                        case 'v': // Version-Anforderung und Ausbaustufe
699
                        case 'v': // Version-Anforderung und Ausbaustufe
629
                                        GetVersionAnforderung = 1;
700
                                        GetVersionAnforderung = 1;
630
                                        break;
701
                                        break;
631
 
702
 
632
                        case 'g'://
703
                        case 'g'://
633
                                        GetExternalControl = 1;
704
                                        GetExternalControl = 1;
634
                                        break;
705
                                        break;
635
 
706
 
636
                        default:
707
                        default:
637
                                //unsupported command received
708
                                //unsupported command received
638
                                break;
709
                                break;
639
                }
710
                }
640
                break; // default:
711
                break; // default:
641
        }
712
        }
642
        NeuerDatensatzEmpfangen = 0;
713
        NeuerDatensatzEmpfangen = 0;
643
        pRxData = 0;
714
        pRxData = 0;
644
        RxDataLen = 0;
715
        RxDataLen = 0;
645
}
716
}
646
 
717
 
647
//############################################################################
718
//############################################################################
648
//Routine für die Serielle Ausgabe
719
//Routine für die Serielle Ausgabe
649
void uart_putchar (char c)
720
void uart_putchar (char c)
650
//############################################################################
721
//############################################################################
651
{
722
{
652
        //Warten solange bis Zeichen gesendet wurde
723
        //Warten solange bis Zeichen gesendet wurde
653
        loop_until_bit_is_set(UCSR0A, UDRE0);
724
        loop_until_bit_is_set(UCSR0A, UDRE0);
654
        //Ausgabe des Zeichens
725
        //Ausgabe des Zeichens
655
        UDR0 = c;
726
        UDR0 = c;
656
}
727
}
657
 
728
 
658
 
729
 
659
//############################################################################
730
//############################################################################
660
//INstallation der Seriellen Schnittstelle
731
//INstallation der Seriellen Schnittstelle
661
void UART_Init (void)
732
void UART_Init (void)
662
//############################################################################
733
//############################################################################
663
{
734
{
664
        unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1);
735
        unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1);
665
 
736
 
666
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
737
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
667
        UCSR0B = (1 << TXEN0) | (1 << RXEN0);
738
        UCSR0B = (1 << TXEN0) | (1 << RXEN0);
668
    // UART Double Speed (U2X)
739
    // UART Double Speed (U2X)
669
        UCSR0A |= (1 << U2X0);
740
        UCSR0A |= (1 << U2X0);
670
        // RX-Interrupt Freigabe
741
        // RX-Interrupt Freigabe
671
        UCSR0B |= (1 << RXCIE0);
742
        UCSR0B |= (1 << RXCIE0);
672
        // TX-Interrupt Freigabe
743
        // TX-Interrupt Freigabe
673
        UCSR0B |= (1 << TXCIE0);
744
        UCSR0B |= (1 << TXCIE0);
674
        // USART0 Baud Rate Register
745
        // USART0 Baud Rate Register
675
        // set clock divider
746
        // set clock divider
676
        UBRR0H = (uint8_t)(ubrr >> 8);
747
        UBRR0H = (uint8_t)(ubrr >> 8);
677
        UBRR0L = (uint8_t)ubrr;
748
        UBRR0L = (uint8_t)ubrr;
678
 
749
 
679
        Debug_Timer = SetDelay(DebugDataIntervall);
750
        Debug_Timer = SetDelay(DebugDataIntervall);
680
        Kompass_Timer = SetDelay(220);
751
        Kompass_Timer = SetDelay(220);
681
 
752
 
682
        VersionInfo.SWMajor = VERSION_MAJOR;
753
        VersionInfo.SWMajor = VERSION_MAJOR;
683
        VersionInfo.SWMinor = VERSION_MINOR;
754
        VersionInfo.SWMinor = VERSION_MINOR;
684
        VersionInfo.SWPatch = VERSION_PATCH;
755
        VersionInfo.SWPatch = VERSION_PATCH;
685
        VersionInfo.ProtoMajor  = VERSION_SERIAL_MAJOR;
756
        VersionInfo.ProtoMajor  = VERSION_SERIAL_MAJOR;
686
        VersionInfo.ProtoMinor  = VERSION_SERIAL_MINOR;
757
        VersionInfo.ProtoMinor  = VERSION_SERIAL_MINOR;
687
 
758
 
688
        pRxData = 0;
759
        pRxData = 0;
689
        RxDataLen = 0;
760
        RxDataLen = 0;
690
}
761
}
691
 
762
 
692
//---------------------------------------------------------------------------------------------
763
//---------------------------------------------------------------------------------------------
693
void DatenUebertragung(void)
764
void DatenUebertragung(void)
694
{
765
{
695
        if(!UebertragungAbgeschlossen) return;
766
        if(!UebertragungAbgeschlossen) return;
696
 
767
 
697
        if(CheckDelay(AboTimeOut))
768
        if(CheckDelay(AboTimeOut))
698
        {
769
        {
699
                Display_Interval = 0;
770
                Display_Interval = 0;
700
                DebugDataIntervall = 0;
771
                DebugDataIntervall = 0;
701
                Intervall3D = 0;
772
                Intervall3D = 0;
702
        }
773
        }
-
 
774
 
-
 
775
#ifdef WITH_MKTOOL_Display      //main.h
-
 
776
#warning : "### with  MKTool Display ###"
703
 
777
 
704
        if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen)
778
        if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen)
705
        {
779
        {
706
                if(DisplayLine > 3)// new format
780
                if(DisplayLine > 3)// new format
707
                {
781
                {
708
                        Menu();
782
                        Menu();
709
                        SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
783
                        SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
710
                }
784
                }
711
                else // old format
785
                else // old format
712
                {
786
                {
713
                        LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!");
787
                        LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!");
714
                        SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20);
788
                        SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20);
715
                        if(DisplayLine++ > 3) DisplayLine = 0;
789
                        if(DisplayLine++ > 3) DisplayLine = 0;
716
                }
790
                }
717
                Display_Timer = SetDelay(Display_Interval);
791
                Display_Timer = SetDelay(Display_Interval);
718
                DebugDisplayAnforderung = 0;
792
                DebugDisplayAnforderung = 0;
719
        }
793
        }
720
        if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
794
        if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
721
        {
795
        {
722
                Menu();
796
                Menu();
723
                SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
797
                SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
724
                DebugDisplayAnforderung1 = 0;
798
                DebugDisplayAnforderung1 = 0;
725
        }
799
        }
-
 
800
       
-
 
801
#endif
-
 
802
 
726
        if(GetVersionAnforderung && UebertragungAbgeschlossen)
803
        if(GetVersionAnforderung && UebertragungAbgeschlossen)
727
        {
804
        {
728
                SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
805
                SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
729
                GetVersionAnforderung = 0;
806
                GetVersionAnforderung = 0;
730
                Debug_OK("Version gesendet");
807
                Debug_OK("Version gesendet");
731
        }
808
        }
732
 
809
 
733
        if(GetExternalControl && UebertragungAbgeschlossen)           // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
810
        if(GetExternalControl && UebertragungAbgeschlossen)           // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
734
        {
811
        {
735
                SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl));
812
                SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl));
736
                GetExternalControl = 0;
813
                GetExternalControl = 0;
737
        }
814
        }
738
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)
815
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)
739
         {
816
         {
740
                  WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
817
                  WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
741
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
818
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
742
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
819
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
743
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
820
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
744
          SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
821
          SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
745
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
822
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
746
          Kompass_Timer = SetDelay(99);
823
          Kompass_Timer = SetDelay(99);
747
         }
824
         }
748
    if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
825
    if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
749
         {
826
         {
750
                  CopyDebugValues();
827
                  CopyDebugValues();
751
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
828
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
752
          DebugDataAnforderung = 0;
829
          DebugDataAnforderung = 0;
753
          if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall);
830
          if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall);
754
         }
831
         }
755
    if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen)
832
    if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen)
756
         {
833
         {
757
                  Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
834
                  Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
758
                  Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
835
                  Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
759
          Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR);
836
          Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR);
760
                  Data3D.Centroid[0] = SummeNick >> 9;
837
                  Data3D.Centroid[0] = SummeNick >> 9;
761
                  Data3D.Centroid[1] = SummeRoll >> 9;
838
                  Data3D.Centroid[1] = SummeRoll >> 9;
762
                  Data3D.Centroid[2] = Mess_Integral_Gier >> 9;
839
                  Data3D.Centroid[2] = Mess_Integral_Gier >> 9;
763
          SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D));
840
          SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D));
764
          Timer3D = SetDelay(Intervall3D);
841
          Timer3D = SetDelay(Intervall3D);
765
         }
842
         }
766
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
843
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
767
     {
844
     {
-
 
845
         
-
 
846
         
-
 
847
         
-
 
848
         #ifdef WITH_FULL_ANALOG_TEXT                   ///  MartinW main.h means no memsave
-
 
849
#warning : "### with  normal ANALOG_TEXT[32][16] ###"
768
                unsigned char label[16]; // local sram buffer
850
                unsigned char label[16]; // local sram buffer
769
                memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra
851
                memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra
-
 
852
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); 
-
 
853
 
-
 
854
#else
-
 
855
#warning : "### with  reduced ANALOG_TEXT[32][13] ###"  
-
 
856
       
-
 
857
                unsigned char label[16]="                "; // local sram buffer ///MartinW; for MKTool, needs 32 bytes
-
 
858
          memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 13); // read lable from flash to sra
770
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16);
859
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16);
-
 
860
#endif
-
 
861
         
-
 
862
         
-
 
863
         
771
      DebugTextAnforderung = 255;
864
      DebugTextAnforderung = 255;
772
         }
865
         }
773
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
866
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
774
         {
867
         {
775
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
868
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
776
        ConfirmFrame = 0;
869
        ConfirmFrame = 0;
777
     }
870
     }
778
 
871
 
779
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
872
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
780
     {
873
     {
781
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
874
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
782
                 GetPPMChannelAnforderung = 0;
875
                 GetPPMChannelAnforderung = 0;
783
         }
876
         }
784
 
877
 
785
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
878
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
786
     if(SendDebugOutput && UebertragungAbgeschlossen)
879
     if(SendDebugOutput && UebertragungAbgeschlossen)
787
     {
880
     {
788
                 SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug));
881
                 SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug));
789
                 SendDebugOutput = 0;
882
                 SendDebugOutput = 0;
790
         }
883
         }
791
#endif
884
#endif
792
 
885
 
793
}
886
}
794
 
887
 
795
 
888
 
796
 
889