Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 598 → Rev 599

/trunk/uart1.c
100,6 → 100,7
NaviData_Target_t NaviData_Target;
NaviData_Flags_t NaviData_Flags;
NaviData_Tiny_t NaviData_Tiny;
NaviData_Failsafe_t NaviData_Failsafe;
NaviData_t NaviData;
 
u8 UART1_Request_VersionInfo = FALSE;
967,18 → 968,28
}
 
 
u16 TransmitNavigationData(u16 MaxBytesPerSecond) // returns the minumum pause time in ms
u16 TransmitNavigationData(u16 MaxBytesPerSecond, u8 clear) // returns the minumum pause time in ms
{
static u8 state = 0, count_flags = 2, count_target = 3, count_home = 4, count_wp = 5 , count_tiny = 6;
static u16 CRC_Home = 0, CRC_Target = 0, CRC_Flags = 0, CRC_Wp = 0;
u16 pause, sent = 0, crc_home = 0xff, crc_target = 0xff, crc_flags = 0xff, crc_wp = 0xff;
static u8 state = 0, count_flags = 2, count_target = 3, count_home = 4, count_wp = 5 , count_tiny = 6, count_fs = 7;
static u16 CRC_Home = 0, CRC_Target = 0, CRC_Flags = 0, CRC_Wp = 0, CRC_Fs = 0;
u16 pause, sent = 0, crc_home, crc_target, crc_flags, crc_wp, crc_fs;
 
if(clear)
{
state = 0;
CRC_Home++;
CRC_Target++;
CRC_Flags++;
CRC_Wp++;
CRC_Fs++;
return(1);
}
while(!sent)
{
switch(state++)
{
case 0:
case 4:
case 5:
// belegt 35 ASCII-Zeichen
NaviData_Flags.Index = 11;
NaviData_Flags.ActualLongitude = NaviData.CurrentPosition.Longitude;
1003,7 → 1014,7
}
break;
case 1:
case 5:
case 6:
// belegt 43 ASCII-Zeichen
NaviData_Target.Index = 12;
NaviData_Target.ActualLongitude = NaviData.CurrentPosition.Longitude;
1024,7 → 1035,7
}
break;
case 2:
case 6:
case 7:
// belegt 31 ASCII-Zeichen
NaviData_WP.Index = 15;
NaviData_WP.ActualLongitude = NaviData.CurrentPosition.Longitude;
1045,6 → 1056,26
}
break;
case 3:
case 8:
NaviData_Failsafe.Index = 17;
NaviData_Failsafe.ActualLongitude = NaviData.CurrentPosition.Longitude;
NaviData_Failsafe.ActualLatitude = NaviData.CurrentPosition.Latitude;
NaviData_Failsafe.Altimeter = NaviData.Altimeter;
NaviData_Failsafe.GroundSpeed = NaviData.GroundSpeed / 10;
NaviData_Failsafe.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
NaviData_Failsafe.FailsafeLongitude = GPS_FailsafePosition.Longitude;
NaviData_Failsafe.FailsafeLatitude = GPS_FailsafePosition.Latitude;
NaviData_Failsafe.FailsafeAltitude = GPS_FailsafePosition.Altitude;
crc_fs = CRC16((unsigned char*)(&NaviData_Failsafe.FailsafeLongitude), sizeof(NaviData_Failsafe_t) - START_PAYLOAD_DATA); // update crc for the license structure
if((crc_fs != CRC_Fs) || (--count_fs == 0))
{
sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Failsafe, sizeof(NaviData_Failsafe)) + 1;
CRC_Fs = crc_fs;
count_fs = 20*2;
}
break;
case 4:
case 9:
// belegt 43 ASCII-Zeichen
NaviData_Home.Index = 13;
NaviData_Home.ActualLongitude = NaviData.CurrentPosition.Longitude;
1063,7 → 1094,7
count_home = 25;
}
break;
case 7:
case 10:
// belegt 39 ASCII-Zeichen
NaviData_Deviation.Index = 14;
NaviData_Deviation.ActualLongitude = NaviData.CurrentPosition.Longitude;
1081,7 → 1112,7
NaviData_Deviation.SatsInUse = NaviData.SatsInUse;
sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Deviation, sizeof(NaviData_Deviation)) + 1;
break;
case 8:
case 11:
// belegt 43 ASCII-Zeichen
NaviData_Volatile.Index = 16;
NaviData_Volatile.ActualLongitude = NaviData.CurrentPosition.Longitude;
1096,11 → 1127,10
NaviData_Volatile.Heading = NaviData.Heading / 2;
NaviData_Volatile.CompassHeading = NaviData.CompassHeading / 2;
NaviData_Volatile.Gas = NaviData.Gas;
NaviData_Volatile.Gas = NaviData.SetpointAltitude;
NaviData_Volatile.SetpointAltitude = NaviData.SetpointAltitude;
sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Volatile, sizeof(NaviData_Volatile)) + 1;
break;
 
case 9:
case 12:
// belegt 27 ASCII-Zeichen
NaviData_Tiny.Index = 10;
NaviData_Tiny.ActualLongitude = NaviData.CurrentPosition.Longitude;
1146,6 → 1176,7
UART1_MotorData_Interval = 0;
UART1_NaviData_Timer = SetDelay(500);
UART1_AboTimeOut = SetDelay(100);
TransmitNavigationData(0,1); // clear the CRC values
}
/*
#define CHK_MIN_INTERVAL(a,b) {if(a && a < b) a = b;}
1218,6 → 1249,7
else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
{
u16 time = 0;
//UART1_NaviData_MaxBytes = 250;
if(UART1_NaviData_MaxBytes == 0) // Transmit the big NC Data frame
{
NaviData.Errorcode = ErrorCode;
1234,7 → 1266,7
// Wert = 200 -> Sekunden laufen flüssig
// Wert >= 250 -> optimal
//UART1_NaviData_MaxBytes = 250;
time = TransmitNavigationData(UART1_NaviData_MaxBytes);
time = TransmitNavigationData(UART1_NaviData_MaxBytes,0);
if(UART1_NaviData_Interval > time) time = UART1_NaviData_Interval;
UART1_NaviData_Timer = SetDelay(time);
}