Subversion Repositories FlightCtrl

Rev

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

Rev 2165 Rev 2174
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
 
111
 
112
 
112
 
113
 
113
 
114
 
114
 
115
       
115
       
116
#ifdef WITH_FULL_ANALOG_TEXT            ///  MartinW main.h means no memsave
116
#ifdef WITH_FULL_ANALOG_TEXT            ///  MartinW main.h means no memsave
117
#warning : "### with  normal ANALOG_TEXT[32][16] ###"
117
#warning : "### with  normal ANALOG_TEXT[32][16] ###"
118
       
118
       
119
const unsigned char ANALOG_TEXT[32][16] PROGMEM =
119
const unsigned char ANALOG_TEXT[32][16] PROGMEM =
120
{
120
{
121
   //1234567890123456
121
   //1234567890123456
122
    "AngleNick       ", //0
122
    "AngleNick       ", //0
123
    "AngleRoll       ",
123
    "AngleRoll       ",
124
    "AccNick         ",
124
    "AccNick         ",
125
    "AccRoll         ",
125
    "AccRoll         ",
126
    "YawGyro         ",
126
    "YawGyro         ",
127
    "Height Value    ", //5
127
    "Height Value    ", //5
128
    "AccZ            ",
128
    "AccZ            ",
129
    "Gas             ",
129
    "Gas             ",
130
    "Compass Value   ",
130
    "Compass Value   ",
131
    "Voltage [0.1V]  ",
131
    "Voltage [0.1V]  ",
132
    "Receiver Level  ", //10
132
    "Receiver Level  ", //10
133
    "Gyro Compass    ",
133
    "Gyro Compass    ",
134
    "Motor 1         ",
134
    "Motor 1         ",
135
    "Motor 2         ",
135
    "Motor 2         ",
136
    "Motor 3         ",
136
    "Motor 3         ",
137
    "Motor 4         ", //15
137
    "Motor 4         ", //15
138
    "PAN-Cos         ",//MartinR
138
    "PAN-Cos         ",//MartinR
139
    "PAN-Sin         ",//MartinR
139
    "PAN-Sin         ",//MartinR
140
    "PAN-Servo       ",//MartinR
140
    "PAN-Servo       ",//MartinR
141
    "Servo-Roll      ",//MartinR
141
    "Servo-Roll      ",//MartinR
142
    "Servo-Nick      ", //20
142
    "Servo-Nick      ", //20
143
    "Hovergas        ",
143
    "Hovergas        ",
144
    "Current [0.1A]  ",
144
    "Current [0.1A]  ",
145
    "Capacity [mAh]  ",
145
    "Capacity [mAh]  ",
146
    "Hight Setpoint  ",
146
    "Hight Setpoint  ",
147
    "Motor 7         ", //25 ///
147
    "FC_StatusFlags  ", //25 ///MartinR
148
    "Motor 8         ",///
148
    "FC_StatusFlags2 ",///MartinR
149
    "Compass Setpoint",
149
    "Compass Setpoint",
150
    "I2C-Error       ",
150
    "I2C-Error       ",
151
    "BL Limit        ",
151
    "BL Limit        ",
152
    "GPS_Nick        ", //30
152
    "GPS_Nick        ", //30
153
    "GPS_Roll        "
153
    "GPS_Roll        "
154
};     
154
};     
155
       
155
       
156
#else
156
#else
157
#warning : "### with  reduced ANALOG_TEXT[32][13] ###"  
157
#warning : "### with  reduced ANALOG_TEXT[32][13] ###"  
158
const unsigned char ANALOG_TEXT[32][13] PROGMEM =
158
const unsigned char ANALOG_TEXT[32][13] PROGMEM =
159
{
159
{
160
   //1234567890123456
160
   //1234567890123456
161
    "AngleNick    ", //0
161
    "AngleNick    ", //0
162
    "AngleRoll    ",
162
    "AngleRoll    ",
163
    "AccNick      ",
163
    "AccNick      ",
164
    "AccRoll      ",
164
    "AccRoll      ",
165
    "YawGyro      ",
165
    "YawGyro      ",
166
    "Height Value ", //5
166
    "Height Value ", //5
167
    "AccZ         ",
167
    "AccZ         ",
168
    "Gas          ",
168
    "Gas          ",
169
    "Compass Value",
169
    "Compass Value",
170
    "Voltage[0.1V]",
170
    "Voltage[0.1V]",
171
    "ReceiverLevel", //10
171
    "ReceiverLevel", //10
172
    "Gyro Compass ",
172
    "Gyro Compass ",
173
    "Motor 1      ",
173
    "Motor 1      ",
174
    "Motor 2      ",
174
    "Motor 2      ",
175
    "Motor 3      ",
175
    "Motor 3      ",
176
    "Motor 4      ", //15
176
    "Motor 4      ", //15
177
    "PAN-cos      ",//MartinR
177
    "PAN-cos      ",//MartinR
178
    "PAN-sin      ",//MartinR
178
    "PAN-sin      ",//MartinR
179
    "PAN-Servo    ",//MartinR
179
    "PAN-Servo    ",//MartinR
180
    "Servo-Roll   ",//MartinR
180
    "Servo-Roll   ",//MartinR
181
    "Servo-Nick   ", //20
181
    "Servo-Nick   ", //20
182
    "Hovergas     ",
182
    "Hovergas     ",
183
    "Current[0.1A]",
183
    "Current[0.1A]",
184
    "Capacity[mAh]",
184
    "Capacity[mAh]",
185
    "Hight Setp   ",
185
    "Hight Setp   ",
186
    "Motor 8      ", //25 ///
186
    "FC_Flags     ", //25 ///MartinR
187
    "Motor 9      ",///
187
    "FC_Flags2    ",///MartinR
188
    "Compass Setp ",
188
    "Compass Setp ",
189
    "I2C-Error    ",
189
    "I2C-Error    ",
190
    "BL Limit     ",
190
    "BL Limit     ",
191
    "GPS_Nick     ", //30
191
    "GPS_Nick     ", //30
192
    "GPS_Roll     "
192
    "GPS_Roll     "
193
};      
193
};      
194
       
194
       
195
       
195
       
196
#endif
196
#endif
197
 
197
 
198
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
198
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199
//++ Sende-Part der Datenübertragung
199
//++ Sende-Part der Datenübertragung
200
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
201
ISR(USART0_TX_vect)
201
ISR(USART0_TX_vect)
202
{
202
{
203
 static unsigned int ptr = 0;
203
 static unsigned int ptr = 0;
204
 unsigned char tmp_tx;
204
 unsigned char tmp_tx;
205
 
205
 
206
 if(!UebertragungAbgeschlossen)
206
 if(!UebertragungAbgeschlossen)
207
  {
207
  {
208
   ptr++;                    // die [0] wurde schon gesendet
208
   ptr++;                    // die [0] wurde schon gesendet
209
   tmp_tx = TxdBuffer[ptr];
209
   tmp_tx = TxdBuffer[ptr];
210
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
210
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
211
    {
211
    {
212
     ptr = 0;
212
     ptr = 0;
213
     UebertragungAbgeschlossen = 1;
213
     UebertragungAbgeschlossen = 1;
214
    }
214
    }
215
   UDR0 = tmp_tx;
215
   UDR0 = tmp_tx;
216
  }
216
  }
217
  else ptr = 0;
217
  else ptr = 0;
218
}
218
}
219
 
219
 
220
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
221
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
221
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
222
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
222
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
223
ISR(USART0_RX_vect)
223
ISR(USART0_RX_vect)
224
{
224
{
225
 static unsigned int crc;
225
 static unsigned int crc;
226
 static unsigned char crc1,crc2,buf_ptr;
226
 static unsigned char crc1,crc2,buf_ptr;
227
 static unsigned char UartState = 0;
227
 static unsigned char UartState = 0;
228
 unsigned char CrcOkay = 0;
228
 unsigned char CrcOkay = 0;
229
 
229
 
230
 if (ReceiverUpdateModeActive == 1) {   UDR1 = UDR0; return; }          // 1 = Update      
230
 if (ReceiverUpdateModeActive == 1) {   UDR1 = UDR0; return; }          // 1 = Update      
231
 if (ReceiverUpdateModeActive == 2) {   RxdBuffer[0] = UDR0; return; }  // 2 = JetiBox-Simulation 
231
 if (ReceiverUpdateModeActive == 2) {   RxdBuffer[0] = UDR0; return; }  // 2 = JetiBox-Simulation 
232
 
232
 
233
 SioTmp = UDR0;
233
 SioTmp = UDR0;
234
 
234
 
235
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
235
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
236
 if(SioTmp == '\r' && UartState == 2)
236
 if(SioTmp == '\r' && UartState == 2)
237
  {
237
  {
238
   UartState = 0;
238
   UartState = 0;
239
   crc -= RxdBuffer[buf_ptr-2];
239
   crc -= RxdBuffer[buf_ptr-2];
240
   crc -= RxdBuffer[buf_ptr-1];
240
   crc -= RxdBuffer[buf_ptr-1];
241
   crc %= 4096;
241
   crc %= 4096;
242
   crc1 = '=' + crc / 64;
242
   crc1 = '=' + crc / 64;
243
   crc2 = '=' + crc % 64;
243
   crc2 = '=' + crc % 64;
244
   CrcOkay = 0;
244
   CrcOkay = 0;
245
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
245
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
246
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
246
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
247
    {
247
    {
248
     NeuerDatensatzEmpfangen = 1;
248
     NeuerDatensatzEmpfangen = 1;
249
         AnzahlEmpfangsBytes = buf_ptr + 1;
249
         AnzahlEmpfangsBytes = buf_ptr + 1;
250
     RxdBuffer[buf_ptr] = '\r';
250
     RxdBuffer[buf_ptr] = '\r';
251
         if(RxdBuffer[2] == 'R')
251
         if(RxdBuffer[2] == 'R')
252
          {
252
          {
253
         
253
         
254
#ifdef WITH_MKTOOL_Display                      ///  MartinW main.h
254
#ifdef WITH_MKTOOL_Display                      ///  MartinW main.h
255
#warning : "### with  MKTool Display ###"
255
#warning : "### with  MKTool Display ###"
256
           LcdClear();
256
           LcdClear();
257
#endif
257
#endif
258
 
258
 
259
           wdt_enable(WDTO_250MS); // Reset-Commando
259
           wdt_enable(WDTO_250MS); // Reset-Commando
260
           ServoActive = 0;
260
           ServoActive = 0;
261
          }
261
          }
262
 
262
 
263
        }
263
        }
264
  }
264
  }
265
  else
265
  else
266
  switch(UartState)
266
  switch(UartState)
267
  {
267
  {
268
   case 0:
268
   case 0:
269
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
269
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
270
                  buf_ptr = 0;
270
                  buf_ptr = 0;
271
                  RxdBuffer[buf_ptr++] = SioTmp;
271
                  RxdBuffer[buf_ptr++] = SioTmp;
272
                  crc = SioTmp;
272
                  crc = SioTmp;
273
          break;
273
          break;
274
   case 1: // Adresse auswerten
274
   case 1: // Adresse auswerten
275
                  UartState++;
275
                  UartState++;
276
                  RxdBuffer[buf_ptr++] = SioTmp;
276
                  RxdBuffer[buf_ptr++] = SioTmp;
277
                  crc += SioTmp;
277
                  crc += SioTmp;
278
                  break;
278
                  break;
279
   case 2: //  Eingangsdaten sammeln
279
   case 2: //  Eingangsdaten sammeln
280
                  RxdBuffer[buf_ptr] = SioTmp;
280
                  RxdBuffer[buf_ptr] = SioTmp;
281
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
281
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
282
                  else UartState = 0;
282
                  else UartState = 0;
283
                  crc += SioTmp;
283
                  crc += SioTmp;
284
                  break;
284
                  break;
285
   default:
285
   default:
286
          UartState = 0;
286
          UartState = 0;
287
          break;
287
          break;
288
  }
288
  }
289
}
289
}
290
 
290
 
291
 
291
 
292
// --------------------------------------------------------------------------
292
// --------------------------------------------------------------------------
293
void AddCRC(unsigned int wieviele)
293
void AddCRC(unsigned int wieviele)
294
{
294
{
295
 unsigned int tmpCRC = 0,i;
295
 unsigned int tmpCRC = 0,i;
296
 for(i = 0; i < wieviele;i++)
296
 for(i = 0; i < wieviele;i++)
297
  {
297
  {
298
   tmpCRC += TxdBuffer[i];
298
   tmpCRC += TxdBuffer[i];
299
  }
299
  }
300
   tmpCRC %= 4096;
300
   tmpCRC %= 4096;
301
   TxdBuffer[i++] = '=' + tmpCRC / 64;
301
   TxdBuffer[i++] = '=' + tmpCRC / 64;
302
   TxdBuffer[i++] = '=' + tmpCRC % 64;
302
   TxdBuffer[i++] = '=' + tmpCRC % 64;
303
   TxdBuffer[i++] = '\r';
303
   TxdBuffer[i++] = '\r';
304
  UebertragungAbgeschlossen = 0;
304
  UebertragungAbgeschlossen = 0;
305
  UDR0 = TxdBuffer[0];
305
  UDR0 = TxdBuffer[0];
306
}
306
}
307
 
307
 
308
 
308
 
309
 
309
 
310
// --------------------------------------------------------------------------
310
// --------------------------------------------------------------------------
311
void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len)
311
void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len)
312
{
312
{
313
 va_list ap;
313
 va_list ap;
314
 unsigned int pt = 0;
314
 unsigned int pt = 0;
315
 unsigned char a,b,c;
315
 unsigned char a,b,c;
316
 unsigned char ptr = 0;
316
 unsigned char ptr = 0;
317
 
317
 
318
 unsigned char *snd = 0;
318
 unsigned char *snd = 0;
319
 int len = 0;
319
 int len = 0;
320
 
320
 
321
 TxdBuffer[pt++] = '#';                         // Startzeichen
321
 TxdBuffer[pt++] = '#';                         // Startzeichen
322
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
322
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
323
 TxdBuffer[pt++] = cmd;                         // Commando
323
 TxdBuffer[pt++] = cmd;                         // Commando
324
 
324
 
325
 va_start(ap, BufferAnzahl);
325
 va_start(ap, BufferAnzahl);
326
 if(BufferAnzahl)
326
 if(BufferAnzahl)
327
 {
327
 {
328
                snd = va_arg(ap, unsigned char*);
328
                snd = va_arg(ap, unsigned char*);
329
                len = va_arg(ap, int);
329
                len = va_arg(ap, int);
330
                ptr = 0;
330
                ptr = 0;
331
                BufferAnzahl--;
331
                BufferAnzahl--;
332
 }
332
 }
333
 while(len)
333
 while(len)
334
  {
334
  {
335
        if(len)
335
        if(len)
336
        {
336
        {
337
           a = snd[ptr++];
337
           a = snd[ptr++];
338
           len--;
338
           len--;
339
           if((!len) && BufferAnzahl)
339
           if((!len) && BufferAnzahl)
340
                {
340
                {
341
                        snd = va_arg(ap, unsigned char*);
341
                        snd = va_arg(ap, unsigned char*);
342
                        len = va_arg(ap, int);
342
                        len = va_arg(ap, int);
343
                        ptr = 0;
343
                        ptr = 0;
344
                        BufferAnzahl--;
344
                        BufferAnzahl--;
345
                }
345
                }
346
        }
346
        }
347
        else a = 0;
347
        else a = 0;
348
        if(len)
348
        if(len)
349
        {
349
        {
350
                b = snd[ptr++];
350
                b = snd[ptr++];
351
                len--;
351
                len--;
352
                if((!len) && BufferAnzahl)
352
                if((!len) && BufferAnzahl)
353
                {
353
                {
354
                        snd = va_arg(ap, unsigned char*);
354
                        snd = va_arg(ap, unsigned char*);
355
                        len = va_arg(ap, int);
355
                        len = va_arg(ap, int);
356
                        ptr = 0;
356
                        ptr = 0;
357
                        BufferAnzahl--;
357
                        BufferAnzahl--;
358
                }
358
                }
359
        }
359
        }
360
        else b = 0;
360
        else b = 0;
361
        if(len)
361
        if(len)
362
        {
362
        {
363
                c = snd[ptr++];
363
                c = snd[ptr++];
364
                len--;
364
                len--;
365
                if((!len) && BufferAnzahl)
365
                if((!len) && BufferAnzahl)
366
                {
366
                {
367
                        snd = va_arg(ap, unsigned char*);
367
                        snd = va_arg(ap, unsigned char*);
368
                        len = va_arg(ap, int);
368
                        len = va_arg(ap, int);
369
                        ptr = 0;
369
                        ptr = 0;
370
                        BufferAnzahl--;
370
                        BufferAnzahl--;
371
                }
371
                }
372
        }
372
        }
373
        else c = 0;
373
        else c = 0;
374
   TxdBuffer[pt++] = '=' + (a >> 2);
374
   TxdBuffer[pt++] = '=' + (a >> 2);
375
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
375
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
376
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
376
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
377
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
377
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
378
  }
378
  }
379
 va_end(ap);
379
 va_end(ap);
380
 AddCRC(pt);
380
 AddCRC(pt);
381
}
381
}
382
 
382
 
383
// --------------------------------------------------------------------------
383
// --------------------------------------------------------------------------
384
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
384
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
385
{
385
{
386
 unsigned char a,b,c,d;
386
 unsigned char a,b,c,d;
387
 unsigned char x,y,z;
387
 unsigned char x,y,z;
388
 unsigned char ptrIn = 3; // start at begin of data block
388
 unsigned char ptrIn = 3; // start at begin of data block
389
 unsigned char ptrOut = 3;
389
 unsigned char ptrOut = 3;
390
 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.
390
 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
 
391
 
392
 while(len)
392
 while(len)
393
  {
393
  {
394
   a = RxdBuffer[ptrIn++] - '=';
394
   a = RxdBuffer[ptrIn++] - '=';
395
   b = RxdBuffer[ptrIn++] - '=';
395
   b = RxdBuffer[ptrIn++] - '=';
396
   c = RxdBuffer[ptrIn++] - '=';
396
   c = RxdBuffer[ptrIn++] - '=';
397
   d = RxdBuffer[ptrIn++] - '=';
397
   d = RxdBuffer[ptrIn++] - '=';
398
 
398
 
399
   x = (a << 2) | (b >> 4);
399
   x = (a << 2) | (b >> 4);
400
   y = ((b & 0x0f) << 4) | (c >> 2);
400
   y = ((b & 0x0f) << 4) | (c >> 2);
401
   z = ((c & 0x03) << 6) | d;
401
   z = ((c & 0x03) << 6) | d;
402
 
402
 
403
   if(len--) RxdBuffer[ptrOut++] = x; else break;
403
   if(len--) RxdBuffer[ptrOut++] = x; else break;
404
   if(len--) RxdBuffer[ptrOut++] = y; else break;
404
   if(len--) RxdBuffer[ptrOut++] = y; else break;
405
   if(len--) RxdBuffer[ptrOut++] = z;   else break;
405
   if(len--) RxdBuffer[ptrOut++] = z;   else break;
406
  }
406
  }
407
        pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte
407
        pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte
408
        RxDataLen = ptrOut - 3;  // wie viele Bytes wurden dekodiert?
408
        RxDataLen = ptrOut - 3;  // wie viele Bytes wurden dekodiert?
409
 
409
 
410
}
410
}
411
 
411
 
412
// --------------------------------------------------------------------------
412
// --------------------------------------------------------------------------
413
void BearbeiteRxDaten(void)
413
void BearbeiteRxDaten(void)
414
{
414
{
415
 if(!NeuerDatensatzEmpfangen) return;
415
 if(!NeuerDatensatzEmpfangen) return;
416
 
416
 
417
        unsigned char tempchar1, tempchar2;
417
        unsigned char tempchar1, tempchar2;
418
        Decode64(); // dekodiere datenblock im Empfangsbuffer
418
        Decode64(); // dekodiere datenblock im Empfangsbuffer
419
        switch(RxdBuffer[1]-'a') // check for Slave Address
419
        switch(RxdBuffer[1]-'a') // check for Slave Address
420
        {
420
        {
421
                case FC_ADDRESS: // FC special commands
421
                case FC_ADDRESS: // FC special commands
422
                switch(RxdBuffer[2])
422
                switch(RxdBuffer[2])
423
                {
423
                {
424
                        case 'K':// Kompasswert
424
                        case 'K':// Kompasswert
425
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
425
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
426
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
426
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
427
                                        break;
427
                                        break;
428
                        case 't':// Motortest
428
                        case 't':// Motortest
429
                                if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
429
                                if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
430
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
430
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
431
                                        PC_MotortestActive = 240;
431
                                        PC_MotortestActive = 240;
432
                                        //while(!UebertragungAbgeschlossen);
432
                                        //while(!UebertragungAbgeschlossen);
433
                                        //SendOutData('T', MeineSlaveAdresse, 0);
433
                                        //SendOutData('T', MeineSlaveAdresse, 0);
434
                                        PcZugriff = 255;
434
                                        PcZugriff = 255;
435
                                        break;
435
                                        break;
436
 
436
 
437
                        case 'n':// "Get Mixer
437
                        case 'n':// "Get Mixer
438
                                        while(!UebertragungAbgeschlossen);
438
                                        while(!UebertragungAbgeschlossen);
439
                    SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1);
439
                    SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1);
440
                                        Debug("Mixer lesen");
440
                                        Debug("Mixer lesen");
441
                                        break;
441
                                        break;
442
 
442
 
443
                        case 'm':// "Write Mixer
443
                        case 'm':// "Write Mixer
444
                    if(pRxData[0] == EEMIXER_REVISION)
444
                    if(pRxData[0] == EEMIXER_REVISION)
445
                                        {
445
                                        {
446
                       memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1);
446
                       memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1);
447
                       MixerTable_WriteToEEProm();
447
                       MixerTable_WriteToEEProm();
448
                                           tempchar1 = 1;
448
                                           tempchar1 = 1;
449
                                           VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER;
449
                                           VersionInfo.HardwareError[1] &= ~FC_ERROR1_MIXER;
450
                                        }
450
                                        }
451
                    else
451
                    else
452
                    {
452
                    {
453
                                                tempchar1 = 0;
453
                                                tempchar1 = 0;
454
                                        }
454
                                        }
455
                                        while(!UebertragungAbgeschlossen);
455
                                        while(!UebertragungAbgeschlossen);
456
                                        SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
456
                                        SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
457
                                        break;
457
                                        break;
458
 
458
 
459
                        case 'p': // get PPM Channels
459
                        case 'p': // get PPM Channels
460
                                        GetPPMChannelAnforderung = 1;
460
                                        GetPPMChannelAnforderung = 1;
461
                                        PcZugriff = 255;
461
                                        PcZugriff = 255;
462
                                        break;
462
                                        break;
463
 
463
 
464
                        case 'q':// "Get"-Anforderung für Settings
464
                        case 'q':// "Get"-Anforderung für Settings
465
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
465
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
466
                                        if((10 <= pRxData[0]) && (pRxData[0] < 20))
466
                                        if((10 <= pRxData[0]) && (pRxData[0] < 20))
467
                                        {
467
                                        {
468
                                                tempchar1 = pRxData[0] - 10;
468
                                                tempchar1 = pRxData[0] - 10;
469
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
469
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
470
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
470
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
471
                                                SetDefaultParameter(tempchar1, 1);
471
                                                SetDefaultParameter(tempchar1, 1);
472
                                        }
472
                                        }
473
                                        else if((20 <= pRxData[0]) && (pRxData[0] < 30))
473
                                        else if((20 <= pRxData[0]) && (pRxData[0] < 30))
474
                                        {
474
                                        {
475
                                                tempchar1 = pRxData[0] - 20;
475
                                                tempchar1 = pRxData[0] - 20;
476
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
476
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
477
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
477
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
478
                                                SetDefaultParameter(tempchar1, 0);
478
                                                SetDefaultParameter(tempchar1, 0);
479
                                        }
479
                                        }
480
                                        else
480
                                        else
481
                                        {
481
                                        {
482
                                                tempchar1 = pRxData[0];
482
                                                tempchar1 = pRxData[0];
483
                                                if(tempchar1 == 0xFF)
483
                                                if(tempchar1 == 0xFF)
484
                                                {
484
                                                {
485
                                                        tempchar1 = GetActiveParamSet();
485
                                                        tempchar1 = GetActiveParamSet();
486
                                                }
486
                                                }
487
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
487
                                                if(tempchar1< 1) tempchar1 = 1; // limit to 1
488
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
488
                                                else if(tempchar1 > 5) tempchar1 = 5; // limit to 5
489
                                                // load requested parameter set
489
                                                // load requested parameter set
490
                                                ParamSet_ReadFromEEProm(tempchar1);
490
                                                ParamSet_ReadFromEEProm(tempchar1);
491
                                        }
491
                                        }
492
                                        while(!UebertragungAbgeschlossen);
492
                                        while(!UebertragungAbgeschlossen);
493
                                        SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1);
493
                                        SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1);
494
                                        Debug("Lese Setting %d", tempchar1);
494
                                        Debug("Lese Setting %d", tempchar1);
495
 
495
 
496
                                        break;
496
                                        break;
497
 
497
 
498
                        case 's': // Parametersatz speichern
498
                        case 's': // Parametersatz speichern
499
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range
499
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION) && MotorenEin == 0) // check for setting to be in range
500
                                        {
500
                                        {
501
                                                memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1);
501
                                                memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1);
502
                                                ParamSet_WriteToEEProm(pRxData[0]);
502
                                                ParamSet_WriteToEEProm(pRxData[0]);
503
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
503
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
504
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
504
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
505
                                                tempchar1 = GetActiveParamSet();
505
                                                tempchar1 = GetActiveParamSet();
506
                                        }
506
                                        }
507
                                        else
507
                                        else
508
                                        {
508
                                        {
509
                                                tempchar1 = 0; // mark in response an invlid setting
509
                                                tempchar1 = 0; // mark in response an invlid setting
510
                                        }
510
                                        }
511
                                        while(!UebertragungAbgeschlossen);
511
                                        while(!UebertragungAbgeschlossen);
512
                                        SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
512
                                        SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
513
                                        if(!MotorenEin) Piep(tempchar1,110);
513
                                        if(!MotorenEin) Piep(tempchar1,110);
514
                                        LipoDetection(0);
514
                                        LipoDetection(0);
515
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
515
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
516
                                        break;
516
                                        break;
517
                        case 'f': // auf anderen Parametersatz umschalten
517
                        case 'f': // auf anderen Parametersatz umschalten
518
                                if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]);
518
                                if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]);
519
                                        tempchar1 = GetActiveParamSet();
519
                                        tempchar1 = GetActiveParamSet();
520
                                        while(!UebertragungAbgeschlossen);
520
                                        while(!UebertragungAbgeschlossen);
521
                                        SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
521
                                        SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
522
                                        if(!MotorenEin) Piep(tempchar1,110);
522
                                        if(!MotorenEin) Piep(tempchar1,110);
523
                                        LipoDetection(0);
523
                                        LipoDetection(0);
524
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
524
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
525
                                        break;
525
                                        break;
526
                        case 'y':// serial Potis
526
                        case 'y':// serial Potis
527
                                        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];
527
                                        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[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];
528
                                        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[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];
529
                                        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
                                        break;
530
                                        break;
531
 
531
 
532
                        case 'u': // request BL parameter
532
                        case 'u': // request BL parameter
533
                                Debug("Reading BL %d", pRxData[0]);
533
                                Debug("Reading BL %d", pRxData[0]);
534
                                // try to read BL configuration
534
                                // try to read BL configuration
535
                                tempchar2 = I2C_ReadBLConfig(pRxData[0]);
535
                                tempchar2 = I2C_ReadBLConfig(pRxData[0]);
536
                                if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
536
                                if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
537
                                else tempchar1 = 0;
537
                                else tempchar1 = 0;
538
                                while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
538
                                while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
539
                                SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t));
539
                                SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t));
540
                                break;
540
                                break;
541
 
541
 
542
                        case 'w': // write BL parameter
542
                        case 'w': // write BL parameter
543
                                Debug("Writing BL %d", pRxData[0]);
543
                                Debug("Writing BL %d", pRxData[0]);
544
                                if(RxDataLen >= 1+sizeof(BLConfig_t))
544
                                if(RxDataLen >= 1+sizeof(BLConfig_t))
545
                                {
545
                                {
546
                                        memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t));
546
                                        memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t));
547
                                        tempchar2 = I2C_WriteBLConfig(pRxData[0]);
547
                                        tempchar2 = I2C_WriteBLConfig(pRxData[0]);
548
                                        if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
548
                                        if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
549
                                        else tempchar1 = 0; // indicate error
549
                                        else tempchar1 = 0; // indicate error
550
                                        while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
550
                                        while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
551
                                        SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2));
551
                                        SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2));
552
                                }
552
                                }
553
                                break;
553
                                break;
554
                        case 'j':
554
                        case 'j':
555
                                if(MotorenEin) break;
555
                                if(MotorenEin) break;
556
                       
556
                       
557
#ifdef WITH_JETI_SIMULATION             ///  MartinW main.h means no memsave
557
#ifdef WITH_JETI_SIMULATION             ///  MartinW main.h means no memsave
558
#warning : "### with  jeti update command ###"
558
#warning : "### with  jeti update command ###"
559
       
559
       
560
 
560
 
561
 
561
 
562
                                tempchar1 = LIBFC_GetCPUType();
562
                                tempchar1 = LIBFC_GetCPUType();
563
                                if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P))
563
                                if((tempchar1 == CPU_ATMEGA644P) || (tempchar1 == CPU_ATMEGA1284P))
564
                                {
564
                                {
565
                                        uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1);
565
                                        uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 38400L) - 1);
566
 
566
 
567
                                        cli();
567
                                        cli();
568
 
568
 
569
                                        // UART0 & UART1 disable RX and TX-Interrupt
569
                                        // UART0 & UART1 disable RX and TX-Interrupt
570
                                        UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0));
570
                                        UCSR0B &= ~((1 << RXCIE0)|(1 << TXCIE0));
571
                                        UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1));
571
                                        UCSR1B &= ~((1 << RXCIE1)|(1 << TXCIE1));
572
 
572
 
573
                                        // UART0 & UART1 disable receiver and transmitter
573
                                        // UART0 & UART1 disable receiver and transmitter
574
                                        UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0));
574
                                        UCSR0B &= ~((1 << TXEN0) | (1 << RXEN0));
575
                                        UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1));
575
                                        UCSR1B &= ~((1 << TXEN1) | (1 << RXEN1));
576
 
576
 
577
                                        // UART0 & UART1 flush receive buffer explicit
577
                                        // UART0 & UART1 flush receive buffer explicit
578
                                        while ( UCSR1A & (1<<RXC1) ) UDR1;
578
                                        while ( UCSR1A & (1<<RXC1) ) UDR1;
579
                                        while ( UCSR0A & (1<<RXC0) ) UDR0;
579
                                        while ( UCSR0A & (1<<RXC0) ) UDR0;
580
 
580
 
581
 
581
 
582
                                        if(pRxData[0] == 1) ReceiverUpdateModeActive = 2;
582
                                        if(pRxData[0] == 1) ReceiverUpdateModeActive = 2;
583
                                        else
583
                                        else
584
                                        {           // Jeti or HoTT update
584
                                        {           // Jeti or HoTT update
585
//#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
585
//#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
586
                                                if(pRxData[0] == 100)   ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1);  // HoTT
586
                                                if(pRxData[0] == 100)   ubrr = (uint16_t) ((uint32_t) F_CPU/ (8 * 19200L) - 1);  // HoTT
587
//#endif
587
//#endif
588
                                                ReceiverUpdateModeActive = 1;
588
                                                ReceiverUpdateModeActive = 1;
589
                                                // UART0 & UART1 set baudrate
589
                                                // UART0 & UART1 set baudrate
590
                                                UBRR1H = (uint8_t)(ubrr>>8);
590
                                                UBRR1H = (uint8_t)(ubrr>>8);
591
                                                UBRR1L = (uint8_t)ubrr;
591
                                                UBRR1L = (uint8_t)ubrr;
592
                                                UBRR0H = UBRR1H;
592
                                                UBRR0H = UBRR1H;
593
                                                UBRR0L = UBRR1L;
593
                                                UBRR0L = UBRR1L;
594
                                                // UART1 no parity
594
                                                // UART1 no parity
595
                                                UCSR1C &= ~(1 << UPM11);
595
                                                UCSR1C &= ~(1 << UPM11);
596
                                                UCSR1C &= ~(1 << UPM10);
596
                                                UCSR1C &= ~(1 << UPM10);
597
                                                // UART1 8-bit
597
                                                // UART1 8-bit
598
                                                UCSR1B &= ~(1 << UCSZ12);
598
                                                UCSR1B &= ~(1 << UCSZ12);
599
                                                UCSR1C |= (1 << UCSZ11);
599
                                                UCSR1C |= (1 << UCSZ11);
600
                                                UCSR1C |= (1 << UCSZ10);
600
                                                UCSR1C |= (1 << UCSZ10);
601
                                        }
601
                                        }
602
                                        // UART0 & UART1 1 stop bit
602
                                        // UART0 & UART1 1 stop bit
603
                                        UCSR1C &= ~(1 << USBS1);
603
                                        UCSR1C &= ~(1 << USBS1);
604
                                        UCSR0C &= ~(1 << USBS0);
604
                                        UCSR0C &= ~(1 << USBS0);
605
                                        // UART1 clear 9th bit
605
                                        // UART1 clear 9th bit
606
                                        UCSR1B &= ~(1<<TXB81);
606
                                        UCSR1B &= ~(1<<TXB81);
607
                                        // enable receiver and transmitter for UART0 and UART1
607
                                        // enable receiver and transmitter for UART0 and UART1
608
                                        UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
608
                                        UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
609
                                        UCSR1B |= (1 << TXEN1) | (1 << RXEN1);
609
                                        UCSR1B |= (1 << TXEN1) | (1 << RXEN1);
610
                                        // enable RX-Interrupt for UART0 and UART1
610
                                        // enable RX-Interrupt for UART0 and UART1
611
                                        UCSR0B |= (1 << RXCIE0);
611
                                        UCSR0B |= (1 << RXCIE0);
612
                                        UCSR1B |= (1 << RXCIE1);
612
                                        UCSR1B |= (1 << RXCIE1);
613
                                        // disable other Interrupts
613
                                        // disable other Interrupts
614
                                        TIMSK0 = 0;
614
                                        TIMSK0 = 0;
615
                                        TIMSK1 = 0;
615
                                        TIMSK1 = 0;
616
                                        TIMSK2 = 0;
616
                                        TIMSK2 = 0;
617
 
617
 
618
                                        sei();
618
                                        sei();
619
                                }
619
                                }
620
                               
620
                               
621
#else
621
#else
622
#warning : "### without  jeti update command ###"       
622
#warning : "### without  jeti update command ###"       
623
 
623
 
624
#endif
624
#endif
625
                                break;
625
                                break;
626
 
626
 
627
                } // case FC_ADDRESS:
627
                } // case FC_ADDRESS:
628
 
628
 
629
                default: // any Slave Address
629
                default: // any Slave Address
630
 
630
 
631
                switch(RxdBuffer[2])
631
                switch(RxdBuffer[2])
632
                {
632
                {
633
                        // 't' comand placed here only for compatibility to BL
633
                        // 't' comand placed here only for compatibility to BL
634
                        case 't':// Motortest
634
                        case 't':// Motortest
635
                                if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
635
                                if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
636
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
636
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
637
                                        while(!UebertragungAbgeschlossen);
637
                                        while(!UebertragungAbgeschlossen);
638
                                        SendOutData('T', MeineSlaveAdresse, 0);
638
                                        SendOutData('T', MeineSlaveAdresse, 0);
639
                                        PC_MotortestActive = 250;
639
                                        PC_MotortestActive = 250;
640
                                        PcZugriff = 255;
640
                                        PcZugriff = 255;
641
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
641
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
642
                                        break;
642
                                        break;
643
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
643
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
644
                        case 'K':// Kompasswert
644
                        case 'K':// Kompasswert
645
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
645
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
646
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
646
//                                      KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
647
                                        break;
647
                                        break;
648
                        case 'a':// Texte der Analogwerte
648
                        case 'a':// Texte der Analogwerte
649
                                        DebugTextAnforderung = pRxData[0];
649
                                        DebugTextAnforderung = pRxData[0];
650
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
650
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
651
                                        PcZugriff = 255;
651
                                        PcZugriff = 255;
652
                                        break;
652
                                        break;
653
                        case 'b':
653
                        case 'b':
654
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
654
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
655
                                        ConfirmFrame = ExternControl.Frame;
655
                                        ConfirmFrame = ExternControl.Frame;
656
                                        PcZugriff = 255;
656
                                        PcZugriff = 255;
657
                                        break;
657
                                        break;
658
                        case 'c': // Poll the 3D-Data
658
                        case 'c': // Poll the 3D-Data
659
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
659
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
660
                                        Intervall3D = pRxData[0] * 10;
660
                                        Intervall3D = pRxData[0] * 10;
661
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
661
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
662
                                        break;
662
                                        break;
663
                        case 'd': // Poll the debug data
663
                        case 'd': // Poll the debug data
664
                                        PcZugriff = 255;
664
                                        PcZugriff = 255;
665
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
665
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
666
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
666
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
667
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
667
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
668
                                        break;
668
                                        break;
669
 
669
 
670
                        case 'h':// x-1 Displayzeilen
670
                        case 'h':// x-1 Displayzeilen
671
                       
671
                       
672
#ifdef WITH_MKTOOL_Display                                                              /// MartinW memorysave
672
#ifdef WITH_MKTOOL_Display                                                              /// MartinW memorysave
673
#warning : "### with  MKTool Display ###"
673
#warning : "### with  MKTool Display ###"
674
 
674
 
675
                                        PcZugriff = 255;
675
                                        PcZugriff = 255;
676
                                if((pRxData[0] & 0x80) == 0x00) // old format
676
                                if((pRxData[0] & 0x80) == 0x00) // old format
677
                                        {
677
                                        {
678
                                                DisplayLine = 2;
678
                                                DisplayLine = 2;
679
                                                Display_Interval = 0;
679
                                                Display_Interval = 0;
680
                                        }
680
                                        }
681
                                        else // new format
681
                                        else // new format
682
                                        {
682
                                        {
683
                                                RemoteKeys |= ~pRxData[0];
683
                                                RemoteKeys |= ~pRxData[0];
684
                                                Display_Interval = (unsigned int)pRxData[1] * 10;
684
                                                Display_Interval = (unsigned int)pRxData[1] * 10;
685
                                                DisplayLine = 4;
685
                                                DisplayLine = 4;
686
                                                AboTimeOut = SetDelay(ABO_TIMEOUT);
686
                                                AboTimeOut = SetDelay(ABO_TIMEOUT);
687
                                        }
687
                                        }
688
                                        DebugDisplayAnforderung = 1;
688
                                        DebugDisplayAnforderung = 1;
689
                                        break;
689
                                        break;
690
 
690
 
691
                        case 'l':// x-1 Displayzeilen
691
                        case 'l':// x-1 Displayzeilen
692
                                PcZugriff = 255;
692
                                PcZugriff = 255;
693
                                        MenuePunkt = pRxData[0];
693
                                        MenuePunkt = pRxData[0];
694
                                        DebugDisplayAnforderung1 = 1;
694
                                        DebugDisplayAnforderung1 = 1;
695
                                       
695
                                       
696
#endif
696
#endif
697
                                        break;
697
                                        break;
698
                        case 'v': // Version-Anforderung und Ausbaustufe
698
                        case 'v': // Version-Anforderung und Ausbaustufe
699
                                        GetVersionAnforderung = 1;
699
                                        GetVersionAnforderung = 1;
700
                                        break;
700
                                        break;
701
 
701
 
702
                        case 'g'://
702
                        case 'g'://
703
                                        GetExternalControl = 1;
703
                                        GetExternalControl = 1;
704
                                        break;
704
                                        break;
705
 
705
 
706
                        default:
706
                        default:
707
                                //unsupported command received
707
                                //unsupported command received
708
                                break;
708
                                break;
709
                }
709
                }
710
                break; // default:
710
                break; // default:
711
        }
711
        }
712
        NeuerDatensatzEmpfangen = 0;
712
        NeuerDatensatzEmpfangen = 0;
713
        pRxData = 0;
713
        pRxData = 0;
714
        RxDataLen = 0;
714
        RxDataLen = 0;
715
}
715
}
716
 
716
 
717
//############################################################################
717
//############################################################################
718
//Routine für die Serielle Ausgabe
718
//Routine für die Serielle Ausgabe
719
void uart_putchar (char c)
719
void uart_putchar (char c)
720
//############################################################################
720
//############################################################################
721
{
721
{
722
        //Warten solange bis Zeichen gesendet wurde
722
        //Warten solange bis Zeichen gesendet wurde
723
        loop_until_bit_is_set(UCSR0A, UDRE0);
723
        loop_until_bit_is_set(UCSR0A, UDRE0);
724
        //Ausgabe des Zeichens
724
        //Ausgabe des Zeichens
725
        UDR0 = c;
725
        UDR0 = c;
726
}
726
}
727
 
727
 
728
 
728
 
729
//############################################################################
729
//############################################################################
730
//INstallation der Seriellen Schnittstelle
730
//INstallation der Seriellen Schnittstelle
731
void UART_Init (void)
731
void UART_Init (void)
732
//############################################################################
732
//############################################################################
733
{
733
{
734
        unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1);
734
        unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1);
735
 
735
 
736
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
736
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
737
        UCSR0B = (1 << TXEN0) | (1 << RXEN0);
737
        UCSR0B = (1 << TXEN0) | (1 << RXEN0);
738
    // UART Double Speed (U2X)
738
    // UART Double Speed (U2X)
739
        UCSR0A |= (1 << U2X0);
739
        UCSR0A |= (1 << U2X0);
740
        // RX-Interrupt Freigabe
740
        // RX-Interrupt Freigabe
741
        UCSR0B |= (1 << RXCIE0);
741
        UCSR0B |= (1 << RXCIE0);
742
        // TX-Interrupt Freigabe
742
        // TX-Interrupt Freigabe
743
        UCSR0B |= (1 << TXCIE0);
743
        UCSR0B |= (1 << TXCIE0);
744
        // USART0 Baud Rate Register
744
        // USART0 Baud Rate Register
745
        // set clock divider
745
        // set clock divider
746
        UBRR0H = (uint8_t)(ubrr >> 8);
746
        UBRR0H = (uint8_t)(ubrr >> 8);
747
        UBRR0L = (uint8_t)ubrr;
747
        UBRR0L = (uint8_t)ubrr;
748
 
748
 
749
        Debug_Timer = SetDelay(DebugDataIntervall);
749
        Debug_Timer = SetDelay(DebugDataIntervall);
750
        Kompass_Timer = SetDelay(220);
750
        Kompass_Timer = SetDelay(220);
751
 
751
 
752
        VersionInfo.SWMajor = VERSION_MAJOR;
752
        VersionInfo.SWMajor = VERSION_MAJOR;
753
        VersionInfo.SWMinor = VERSION_MINOR;
753
        VersionInfo.SWMinor = VERSION_MINOR;
754
        VersionInfo.SWPatch = VERSION_PATCH;
754
        VersionInfo.SWPatch = VERSION_PATCH;
755
        VersionInfo.ProtoMajor  = VERSION_SERIAL_MAJOR;
755
        VersionInfo.ProtoMajor  = VERSION_SERIAL_MAJOR;
756
        VersionInfo.ProtoMinor  = VERSION_SERIAL_MINOR;
756
        VersionInfo.ProtoMinor  = VERSION_SERIAL_MINOR;
757
 
757
 
758
        pRxData = 0;
758
        pRxData = 0;
759
        RxDataLen = 0;
759
        RxDataLen = 0;
760
}
760
}
761
 
761
 
762
//---------------------------------------------------------------------------------------------
762
//---------------------------------------------------------------------------------------------
763
void DatenUebertragung(void)
763
void DatenUebertragung(void)
764
{
764
{
765
        if(!UebertragungAbgeschlossen) return;
765
        if(!UebertragungAbgeschlossen) return;
766
 
766
 
767
        if(CheckDelay(AboTimeOut))
767
        if(CheckDelay(AboTimeOut))
768
        {
768
        {
769
                Display_Interval = 0;
769
                Display_Interval = 0;
770
                DebugDataIntervall = 0;
770
                DebugDataIntervall = 0;
771
                Intervall3D = 0;
771
                Intervall3D = 0;
772
        }
772
        }
773
 
773
 
774
#ifdef WITH_MKTOOL_Display      //main.h
774
#ifdef WITH_MKTOOL_Display      //main.h
775
#warning : "### with  MKTool Display ###"
775
#warning : "### with  MKTool Display ###"
776
 
776
 
777
        if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen)
777
        if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen)
778
        {
778
        {
779
                if(DisplayLine > 3)// new format
779
                if(DisplayLine > 3)// new format
780
                {
780
                {
781
                        Menu();
781
                        Menu();
782
                        SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
782
                        SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
783
                }
783
                }
784
                else // old format
784
                else // old format
785
                {
785
                {
786
                        LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!");
786
                        LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!");
787
                        SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20);
787
                        SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20);
788
                        if(DisplayLine++ > 3) DisplayLine = 0;
788
                        if(DisplayLine++ > 3) DisplayLine = 0;
789
                }
789
                }
790
                Display_Timer = SetDelay(Display_Interval);
790
                Display_Timer = SetDelay(Display_Interval);
791
                DebugDisplayAnforderung = 0;
791
                DebugDisplayAnforderung = 0;
792
        }
792
        }
793
        if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
793
        if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
794
        {
794
        {
795
                Menu();
795
                Menu();
796
                SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
796
                SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
797
                DebugDisplayAnforderung1 = 0;
797
                DebugDisplayAnforderung1 = 0;
798
        }
798
        }
799
       
799
       
800
#endif
800
#endif
801
 
801
 
802
        if(GetVersionAnforderung && UebertragungAbgeschlossen)
802
        if(GetVersionAnforderung && UebertragungAbgeschlossen)
803
        {
803
        {
804
                SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
804
                SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
805
                GetVersionAnforderung = 0;
805
                GetVersionAnforderung = 0;
806
                Debug_OK("Version gesendet");
806
                Debug_OK("Version gesendet");
807
        }
807
        }
808
 
808
 
809
        if(GetExternalControl && UebertragungAbgeschlossen)           // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
809
        if(GetExternalControl && UebertragungAbgeschlossen)           // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
810
        {
810
        {
811
                SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl));
811
                SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl));
812
                GetExternalControl = 0;
812
                GetExternalControl = 0;
813
        }
813
        }
814
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)
814
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)
815
         {
815
         {
816
                  WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
816
                  WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
817
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
817
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
818
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
818
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
819
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
819
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
820
          SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
820
          SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
821
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
821
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
822
          Kompass_Timer = SetDelay(99);
822
          Kompass_Timer = SetDelay(99);
823
         }
823
         }
824
    if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
824
    if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
825
         {
825
         {
826
                  CopyDebugValues();
826
                  CopyDebugValues();
827
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
827
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
828
          DebugDataAnforderung = 0;
828
          DebugDataAnforderung = 0;
829
          if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall);
829
          if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall);
830
         }
830
         }
831
    if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen)
831
    if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen)
832
         {
832
         {
833
                  Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
833
                  Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
834
                  Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
834
                  Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
835
          Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR);
835
          Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR);
836
                  Data3D.Centroid[0] = SummeNick >> 9;
836
                  Data3D.Centroid[0] = SummeNick >> 9;
837
                  Data3D.Centroid[1] = SummeRoll >> 9;
837
                  Data3D.Centroid[1] = SummeRoll >> 9;
838
                  Data3D.Centroid[2] = Mess_Integral_Gier >> 9;
838
                  Data3D.Centroid[2] = Mess_Integral_Gier >> 9;
839
          SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D));
839
          SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D));
840
          Timer3D = SetDelay(Intervall3D);
840
          Timer3D = SetDelay(Intervall3D);
841
         }
841
         }
842
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
842
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
843
     {
843
     {
844
         
844
         
845
         
845
         
846
         
846
         
847
         #ifdef WITH_FULL_ANALOG_TEXT                   ///  MartinW main.h means no memsave
847
         #ifdef WITH_FULL_ANALOG_TEXT                   ///  MartinW main.h means no memsave
848
#warning : "### with  normal ANALOG_TEXT[32][16] ###"
848
#warning : "### with  normal ANALOG_TEXT[32][16] ###"
849
                unsigned char label[16]; // local sram buffer
849
                unsigned char label[16]; // local sram buffer
850
                memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra
850
                memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra
851
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); 
851
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); 
852
 
852
 
853
#else
853
#else
854
#warning : "### with  reduced ANALOG_TEXT[32][13] ###"  
854
#warning : "### with  reduced ANALOG_TEXT[32][13] ###"  
855
       
855
       
856
                unsigned char label[16]="                "; // local sram buffer ///MartinW; for MKTool, needs 32 bytes
856
                unsigned char label[16]="                "; // local sram buffer ///MartinW; for MKTool, needs 32 bytes
857
          memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 13); // read lable from flash to sra
857
          memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 13); // read lable from flash to sra
858
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16);
858
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16);
859
#endif
859
#endif
860
         
860
         
861
         
861
         
862
         
862
         
863
      DebugTextAnforderung = 255;
863
      DebugTextAnforderung = 255;
864
         }
864
         }
865
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
865
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
866
         {
866
         {
867
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
867
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
868
        ConfirmFrame = 0;
868
        ConfirmFrame = 0;
869
     }
869
     }
870
 
870
 
871
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
871
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
872
     {
872
     {
873
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
873
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
874
                 GetPPMChannelAnforderung = 0;
874
                 GetPPMChannelAnforderung = 0;
875
         }
875
         }
876
 
876
 
877
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
877
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
878
     if(SendDebugOutput && UebertragungAbgeschlossen)
878
     if(SendDebugOutput && UebertragungAbgeschlossen)
879
     {
879
     {
880
                 SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug));
880
                 SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug));
881
                 SendDebugOutput = 0;
881
                 SendDebugOutput = 0;
882
         }
882
         }
883
#endif
883
#endif
884
 
884
 
885
}
885
}
886
 
886
 
887
 
887
 
888
 
888