Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2054 → Rev 2055

/branches/dongfang_FC_rewrite/uart0.c
25,7 → 25,9
 
#define FALSE 0
#define TRUE 1
//int8_t test __attribute__ ((section (".noinit")));
 
uint8_t requestedDebugLabel = 255;
 
uint8_t request_verInfo = FALSE;
uint8_t request_externalControl = FALSE;
uint8_t request_display = FALSE;
32,11 → 34,26
uint8_t request_display1 = FALSE;
uint8_t request_debugData = FALSE;
uint8_t request_data3D = FALSE;
uint8_t request_debugLabel = 255;
uint8_t request_PPMChannels = FALSE;
uint8_t request_motorTest = FALSE;
uint8_t request_variables = FALSE;
uint8_t request_OSD = FALSE;
 
/*
#define request_verInfo (1<<0)
#define request_externalControl (1<<1)
#define request_display (1<<3)
#define request_display1 (1<<4)
#define request_debugData (1<<5)
#define request_data3D (1<<6)
#define request_PPMChannels (1<<7)
#define request_motorTest (1<<8)
#define request_variables (1<<9)
#define request_OSD (1<<10)
*/
 
//uint16_t request = 0;
 
uint8_t displayLine = 0;
 
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
59,8 → 76,10
 
uint16_t debugData_timer;
uint16_t data3D_timer;
uint16_t OSD_timer;
uint16_t debugData_interval = 0; // in 1ms
uint16_t data3D_interval = 0; // in 1ms
uint16_t OSD_interval = 0;
 
#ifdef USE_DIRECT_GPS
int16_t toMk3MagTimer;
75,17 → 94,17
"GyroPitch ",
"GyroRoll ",
"GyroYaw ", //5
"AccPitch ",
"AccRoll ",
"AccZ ",
"AccPitch (angle)",
"AccRoll (angle) ", //10
"GPS sat ",
"mag hdng ",
"Pitch Term ",
"Roll Term ",
"Yaw Term ", //15
"Throttle Term ",
"PitchTerm ",
"RollTerm ",
"ThrottleTerm ",
"YawTerm ",
"M1 ", //10
"M2 ",
"M3 ",
"M4 ",
"pdpart ",
"control ", //15
"ipart ",
"ControlAct/10 ",
"RC Qual ",
"heightTrottleIn ",
96,9 → 115,9
"HeightPdThrottle",
"HeightIdThrottle", //25
"HeightDdThrottle",
"HeadingInDegrees",
"0 ",
"1 ",
"Yaw Limit / 100 ",
"HeadingError/100",
"PD Yaw ",
"2 ", //30
"3 "
};
181,6 → 200,10
versionInfo.protoMajor = VERSION_SERIAL_MAJOR;
versionInfo.protoMinor = VERSION_SERIAL_MINOR;
 
for (uint8_t i=0; i<32; i++) {
debugOut.analog[i] = i;
}
 
// restore global interrupt flags
SREG = sreg;
}
267,7 → 290,7
}
 
// --------------------------------------------------------------------------
void Addchecksum(uint16_t datalen) {
void addChecksum(uint16_t datalen) {
uint16_t tmpchecksum = 0, i;
for (i = 0; i < datalen; i++) {
tmpchecksum += txd_buffer[i];
393,11 → 416,11
txd_buffer[pt++] = '=' + (c & 0x3f);
}
va_end(ap);
Addchecksum(pt); // add checksum after data block and initates the transmission
addChecksum(pt); // add checksum after data block and initates the transmission
}
 
// --------------------------------------------------------------------------
void Decode64(void) {
void decode64(void) {
uint8_t a, b, c, d;
uint8_t x, y, z;
uint8_t ptrIn = 3;
441,7 → 464,7
if (!rxd_buffer_locked)
return;
uint8_t tempchar[3];
Decode64(); // decode data block in rxd_buffer
decode64(); // decode data block in rxd_buffer
 
switch (rxd_buffer[1] - 'a') {
 
532,9 → 555,9
default: // any Slave Address
switch (rxd_buffer[2]) {
case 'a':// request for labels of the analog debug outputs
request_debugLabel = pRxData[0];
if (request_debugLabel > 31)
request_debugLabel = 31;
requestedDebugLabel = pRxData[0];
if (requestedDebugLabel > 31)
requestedDebugLabel = 31;
break;
 
case 'b': // submit extern control
555,6 → 578,12
request_display1 = TRUE;
break;
 
case 'o':// request for OSD data (FC style)
OSD_interval = (uint16_t) pRxData[0] * 10;
if (OSD_interval > 0)
request_OSD = TRUE;
break;
case 'v': // request for version and board release
request_verInfo = TRUE;
break;
631,12 → 660,12
request_display1 = FALSE;
}
 
if (request_debugLabel != 0xFF) { // Texte f�r die Analogdaten
if (requestedDebugLabel != 0xFF && txd_complete) { // Texte f�r die Analogdaten
uint8_t label[16]; // local sram buffer
memcpy_P(label, ANALOG_LABEL[request_debugLabel], 16); // read lable from flash to sram buffer
sendOutData('A', FC_ADDRESS, 2, (uint8_t *) &request_debugLabel,
sizeof(request_debugLabel), label, 16);
request_debugLabel = 0xFF;
memcpy_P(label, ANALOG_LABEL[requestedDebugLabel], 16); // read lable from flash to sram buffer
sendOutData('A', FC_ADDRESS, 2, (uint8_t *) &requestedDebugLabel,
sizeof(requestedDebugLabel), label, 16);
requestedDebugLabel = 0xFF;
}
 
if (confirmFrame && txd_complete) { // Datensatz ohne checksum best�tigen
651,12 → 680,11
request_debugData = FALSE;
}
 
if (((data3D_interval && checkDelay(data3D_timer)) || request_data3D)
&& txd_complete) {
if (((data3D_interval && checkDelay(data3D_timer)) || request_data3D) && txd_complete) {
sendOutData('C', FC_ADDRESS, 1, (uint8_t *) &data3D, sizeof(data3D));
data3D.anglePitch = (int16_t) (attitude[PITCH] / (GYRO_DEG_FACTOR_PITCHROLL/10)); // convert to multiple of 0.1°
data3D.angleRoll = (int16_t) (attitude[ROLL] / (GYRO_DEG_FACTOR_PITCHROLL/10)); // convert to multiple of 0.1°
data3D.heading = (int16_t) (heading / (GYRO_DEG_FACTOR_YAW/10)); // convert to multiple of 0.1°
data3D.anglePitch = (int16_t) (attitude[PITCH] / (GYRO_DEG_FACTOR_PITCHROLL/10)); // convert to multiple of 0.1 deg
data3D.angleRoll = (int16_t) (attitude[ROLL] / (GYRO_DEG_FACTOR_PITCHROLL/10)); // convert to multiple of 0.1 deg
data3D.heading = (int16_t) (heading / (GYRO_DEG_FACTOR_YAW/10)); // convert to multiple of 0.1 deg
data3D_timer = setDelay(data3D_interval);
request_data3D = FALSE;
}
695,4 → 723,14
sendOutData('X', FC_ADDRESS, 1, (uint8_t *) &variables, sizeof(variables));
request_variables = FALSE;
}
 
if (((OSD_interval && checkDelay(OSD_timer)) || request_OSD) && txd_complete) {
int32_t height = analog_getHeight();
data3D.anglePitch = (int16_t) (attitude[PITCH] / (GYRO_DEG_FACTOR_PITCHROLL/10)); // convert to multiple of 0.1 deg
data3D.angleRoll = (int16_t) (attitude[ROLL] / (GYRO_DEG_FACTOR_PITCHROLL/10)); // convert to multiple of 0.1 deg
data3D.heading = (int16_t) (heading / (GYRO_DEG_FACTOR_YAW/10)); // convert to multiple of 0.1 deg
sendOutData('O', FC_ADDRESS, 4, (uint8_t*)&data3D, sizeof(data3D), (uint8_t*)&GPSInfo, sizeof(GPSInfo), (uint8_t*)&height, sizeof(height), (uint8_t*)UBat, sizeof(UBat));
OSD_timer = setDelay(OSD_interval);
request_OSD = FALSE;
}
}