Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 2334 → Rev 2335

/MKLiveView/v1.0/Source/MainWindow.xaml.cs
697,7 → 697,19
{
MainMap.Markers.Remove(home);
}
void _clearMapMarkers(Type markerType)
{
for (int k = 0; k < MainMap.Markers.Count;)
{
GMapMarker p = MainMap.Markers[k];
if (p.GetType() == markerType | p.Shape.GetType() == markerType)
MainMap.Markers.Remove(p);
else
k++;
}
 
}
 
// access mode
private void comboBoxMode_DropDownClosed(object sender, EventArgs e)
{
1655,7 → 1667,7
}
if (_bVoiceSatFixPlay && !_bVoiceSatFixActive)
{
Thread th = new Thread(() => _mediaPlayer("Voice\\CriticalBattery.mp3"));
Thread th = new Thread(() => _mediaPlayer("Voice\\SatFixLost.mp3"));
th.Start();
_bVoiceSatFixActive = true;
}
1839,7 → 1851,8
});
Dispatcher.Invoke(() => dgvWP.Items.Refresh());
Dispatcher.Invoke(() => _iWPIndex = data[1]);
wpList.Add(new PointLatLng((double)dr[3], (double)dr[4]));
if ((int)dr[1] == 0)
wpList.Add(new PointLatLng((double)dr[3], (double)dr[4]));
if (data[1] == data[0])
{
_bGetWP = false;
2086,11 → 2099,15
}
void _getWP()
{
int iTimeout = 0;
_bGetWPCount = true;
_getpWP(1); //get the itemscount of wp
while (_bGetWPCount)
Thread.Sleep(100);
if (_iWPCount > 0)
while (_bGetWPCount & iTimeout < _iWPTimeout * 5)
{
Thread.Sleep(10);
iTimeout++;
}
if (_iWPCount > 0 & !_bGetWPCount)
_getWPList();
}
void _getWPList()
2110,6 → 2127,7
}
void _sendWPList()
{
int iTimeout = 0;
if (serialPortCtrl.Port.IsOpen)
{
byte[] bData = new byte[30];
2120,78 → 2138,95
serialStream.Write(bytes, 0, bytes.Length);
 
_iWPCount = -1;
while (_iWPCount == -1)
while (_iWPCount == -1 & iTimeout < _iWPTimeout * 5)
{
Thread.Sleep(10);
iTimeout++;
}
Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
 
int iVal;
double dVal;
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ",";
for (int i = 0; i < dtWaypoints.Rows.Count; i++)
if (_iWPCount > -1)
{
//longitude
dVal = Convert.ToDouble(dtWaypoints.Rows[i][4], nfi);
iVal = (int)(dVal * Math.Pow(10, 7));
bData[0] = (byte)(iVal & 0xff);
bData[1] = (byte)((iVal >> 8) & 0xff);
bData[2] = (byte)((iVal >> 16) & 0xff);
bData[3] = (byte)(iVal >> 24);
//latitude
dVal = Convert.ToDouble(dtWaypoints.Rows[i][3], nfi);
iVal = (int)(dVal * Math.Pow(10, 7));
bData[4] = (byte)(iVal & 0xff);
bData[5] = (byte)((iVal >> 8) & 0xff);
bData[6] = (byte)((iVal >> 16) & 0xff);
bData[7] = (byte)(iVal >> 24);
//altitude
dVal = Convert.ToDouble(dtWaypoints.Rows[i][5], nfi);
iVal = (int)(dVal * 10);
bData[8] = (byte)(iVal & 0xff);
bData[9] = (byte)((iVal >> 8) & 0xff);
bData[10] = (byte)((iVal >> 16) & 0xff);
bData[11] = (byte)(iVal >> 24);
//Status 'NEWDATA'
bData[12] = 1;
//heading
iVal = Convert.ToInt16(dtWaypoints.Rows[i][6]);
bData[13] = (byte)(iVal & 0xff);
bData[14] = (byte)((iVal >> 8) & 0xff);
//ToleranceRadius
bData[15] = Convert.ToByte(dtWaypoints.Rows[i][9]);
//HoldTime
bData[16] = Convert.ToByte(dtWaypoints.Rows[i][10]);
//Event_Flag
bData[17] = Convert.ToByte(dtWaypoints.Rows[i][13]);
//Index
bData[18] = Convert.ToByte((int)dtWaypoints.Rows[i][0]);
//Type
bData[19] = Convert.ToByte(dtWaypoints.Rows[i][1]);
//WP_EventChannelValue
bData[20] = Convert.ToByte(dtWaypoints.Rows[i][14]);
//AltitudeRate
bData[21] = Convert.ToByte(dtWaypoints.Rows[i][8]);
//Speed
bData[22] = Convert.ToByte(dtWaypoints.Rows[i][7]);
//CamAngle
bData[23] = (byte)Convert.ToInt16(dtWaypoints.Rows[i][12]);
//Name
byte[] name = ASCIIEncoding.ASCII.GetBytes((string)dtWaypoints.Rows[i][2]);
bData[24] = name.Length > 0 ? name[0] : (byte)0;
bData[25] = name.Length > 1 ? name[1] : (byte)0;
bData[26] = name.Length > 2 ? name[2] : (byte)0;
bData[27] = name.Length > 3 ? name[3] : (byte)0;
//Autotrigger
bData[28] = Convert.ToByte(dtWaypoints.Rows[i][11]);
 
bytes = FlightControllerMessage.CreateMessage('w', 2, bData);
serialStream.Write(bytes, 0, bytes.Length);
int iVal;
double dVal;
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ",";
for (int i = 0; i < dtWaypoints.Rows.Count; i++)
{
//longitude
dVal = Convert.ToDouble(dtWaypoints.Rows[i][4], nfi);
iVal = (int)(dVal * Math.Pow(10, 7));
bData[0] = (byte)(iVal & 0xff);
bData[1] = (byte)((iVal >> 8) & 0xff);
bData[2] = (byte)((iVal >> 16) & 0xff);
bData[3] = (byte)(iVal >> 24);
//latitude
dVal = Convert.ToDouble(dtWaypoints.Rows[i][3], nfi);
iVal = (int)(dVal * Math.Pow(10, 7));
bData[4] = (byte)(iVal & 0xff);
bData[5] = (byte)((iVal >> 8) & 0xff);
bData[6] = (byte)((iVal >> 16) & 0xff);
bData[7] = (byte)(iVal >> 24);
//altitude
dVal = Convert.ToDouble(dtWaypoints.Rows[i][5], nfi);
iVal = (int)(dVal * 10);
bData[8] = (byte)(iVal & 0xff);
bData[9] = (byte)((iVal >> 8) & 0xff);
bData[10] = (byte)((iVal >> 16) & 0xff);
bData[11] = (byte)(iVal >> 24);
//Status 'NEWDATA'
bData[12] = 1;
//heading
iVal = Convert.ToInt16(dtWaypoints.Rows[i][6]);
bData[13] = (byte)(iVal & 0xff);
bData[14] = (byte)((iVal >> 8) & 0xff);
//ToleranceRadius
bData[15] = Convert.ToByte(dtWaypoints.Rows[i][9]);
//HoldTime
bData[16] = Convert.ToByte(dtWaypoints.Rows[i][10]);
//Event_Flag
bData[17] = Convert.ToByte(dtWaypoints.Rows[i][13]);
//Index
bData[18] = Convert.ToByte((int)dtWaypoints.Rows[i][0]);
//Type
bData[19] = Convert.ToByte(dtWaypoints.Rows[i][1]);
//WP_EventChannelValue
bData[20] = Convert.ToByte(dtWaypoints.Rows[i][14]);
//AltitudeRate
bData[21] = Convert.ToByte(dtWaypoints.Rows[i][8]);
//Speed
bData[22] = Convert.ToByte(dtWaypoints.Rows[i][7]);
//CamAngle
bData[23] = (byte)Convert.ToInt16(dtWaypoints.Rows[i][12]);
//Name
byte[] name = ASCIIEncoding.ASCII.GetBytes((string)dtWaypoints.Rows[i][2]);
bData[24] = name.Length > 0 ? name[0] : (byte)0;
bData[25] = name.Length > 1 ? name[1] : (byte)0;
bData[26] = name.Length > 2 ? name[2] : (byte)0;
bData[27] = name.Length > 3 ? name[3] : (byte)0;
//Autotrigger
bData[28] = Convert.ToByte(dtWaypoints.Rows[i][11]);
 
_iWPCount = -1;
while (_iWPCount == -1)
Thread.Sleep(10);
Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
bytes = FlightControllerMessage.CreateMessage('w', 2, bData);
serialStream.Write(bytes, 0, bytes.Length);
 
_iWPCount = -1;
iTimeout = 0;
while (_iWPCount == -1 & iTimeout < _iWPTimeout * 5)
{
Thread.Sleep(10);
iTimeout++;
}
if (_iWPCount == -1)
{
Log(LogMsgType.Error, "Timeout while sending list!");
break;
}
Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
}
}
else
Log(LogMsgType.Error, "Timeout while sending list!");
}
else
Log(LogMsgType.Error, "NOT CONNECTED!");
2977,7 → 3012,20
{
_readWPLFile();
}
private void btnClearWPList_Click(object sender, RoutedEventArgs e)
{
_clearMapMarkers(typeof(CustomMarkerWP));
wpList.Clear();
if (mRouteWP != null)
MainMap.Markers.Remove(mRouteWP);
dtWaypoints.Rows.Clear();
Dispatcher.Invoke(() => dgvWP.Items.Refresh());
Dispatcher.Invoke(() => lblWPIndex.Content = 0);
Dispatcher.Invoke(() => lblWPCount.Content = 0);
Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m");
}
#endregion WP
 
#region GPX
private void checkBoxGPXLog_Click(object sender, RoutedEventArgs e)
{
3056,18 → 3104,7
{
_clearMapMarkers(typeof(GMapRoute));
}
void _clearMapMarkers(Type markerType)
{
for (int k = 0; k < MainMap.Markers.Count;)
{
GMapMarker p = MainMap.Markers[k];
if (p.GetType() == markerType | p.Shape.GetType() == markerType)
MainMap.Markers.Remove(p);
else
k++;
}
 
}
void _loadGPXLog()
{