Advertisement
Guest User

Untitled

a guest
May 6th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.44 KB | None | 0 0
  1. public void incoming(Byte[] pack)
  2. {
  3.     /////////////////////////////////////////////////
  4.     ///     Receive incoming waypoints/control status
  5.     /////////////////////////////////////////////////
  6.     int count;
  7.  
  8.     Byte[] opCode = new Byte[2];
  9.     Byte[] latitude = new Byte[8];
  10.     Byte[] longitude = new Byte[8];
  11.     Byte[] altitude = new Byte[8];
  12.     Byte[] status = new Byte[2];
  13.     Byte[] duration = new Byte[2];
  14.    
  15.     Int16 val;
  16.     double lat;
  17.     double lon;
  18.     double alt;
  19.     Int16 sta;
  20.     Int16 dur;
  21.  
  22.     opCode[0] = pack[0];
  23.     opCode[1] = pack[1];
  24.     val = BitConverter.ToInt16(opCode, 0);
  25.  
  26.     switch (val)
  27.     {
  28.         case GNC:
  29.             UpdateContRec("ONLINE");                    
  30.             break;
  31.  
  32.         case REQ:
  33.             if(MessageBox.Show("Do you want to relinquish control?",
  34.                 "Cockpit Client", MessageBoxButtons.YesNo)== DialogResult.Yes)
  35.             {
  36.                 UpdateContRel("OFFLINE");
  37.                 response = serverSend.sendPacket(packet.buildPacket(REL));                        
  38.             }
  39.             break;
  40.  
  41.         case ADD:
  42.  
  43.             count = waypointManager.Rows.Count;
  44.             for (int i = 0; i < (count - 1); i++)
  45.             {
  46.                 UpdateRemWP(0);
  47.                 UpdateRemCombo(0);
  48.             }
  49.  
  50.             for (int i = 0; val == (Int16)2; i++)
  51.             {
  52.                 opCode[0] = pack[0 + (32 * (i+1))];
  53.                 opCode[1] = pack[1 + (32 * (i+1))];
  54.  
  55.                 latitude[0] = pack[4 + (32 * i)];
  56.                 latitude[1] = pack[5 + (32 * i)];
  57.                 latitude[2] = pack[6 + (32 * i)];
  58.                 latitude[3] = pack[7 + (32 * i)];
  59.                 latitude[4] = pack[8 + (32 * i)];
  60.                 latitude[5] = pack[9 + (32 * i)];
  61.                 latitude[6] = pack[10 + (32 * i)];
  62.                 latitude[7] = pack[11 + (32 * i)];
  63.  
  64.                 longitude[0] = pack[12 + (32 * i)];
  65.                 longitude[1] = pack[13 + (32 * i)];
  66.                 longitude[2] = pack[14 + (32 * i)];
  67.                 longitude[3] = pack[15 + (32 * i)];
  68.                 longitude[4] = pack[16 + (32 * i)];
  69.                 longitude[5] = pack[17 + (32 * i)];
  70.                 longitude[6] = pack[18 + (32 * i)];
  71.                 longitude[7] = pack[19 + (32 * i)];
  72.  
  73.                 altitude[0] = pack[20 + (32 * i)];
  74.                 altitude[1] = pack[21 + (32 * i)];
  75.                 altitude[2] = pack[22 + (32 * i)];
  76.                 altitude[3] = pack[23 + (32 * i)];
  77.                 altitude[4] = pack[24 + (32 * i)];
  78.                 altitude[5] = pack[25 + (32 * i)];
  79.                 altitude[6] = pack[26 + (32 * i)];
  80.                 altitude[7] = pack[27 + (32 * i)];
  81.  
  82.                 status[0] = pack[28 + (32 * i)];
  83.                 status[1] = pack[29 + (32 * i)];
  84.  
  85.                 duration[0] = pack[30 + (32 * i)];
  86.                 duration[1] = pack[31 + (32 * i)];
  87.  
  88.                 val = BitConverter.ToInt16(opCode, 0);
  89.                 lat = BitConverter.ToDouble(latitude, 0);
  90.                 lon = BitConverter.ToDouble(longitude, 0);
  91.                 alt = BitConverter.ToDouble(altitude, 0);
  92.                 sta = BitConverter.ToInt16(status, 0);
  93.                 dur = BitConverter.ToInt16(duration, 0);
  94.  
  95.                 if (alt != 0)
  96.                 {
  97.                     UpdateCombo(Convert.ToString(i));
  98.  
  99.                     DataGridViewRow row = new DataGridViewRow();
  100.                     row.CreateCells(waypointManager);
  101.  
  102.                     row.Cells[0].Value = Convert.ToString(i);
  103.                     row.Cells[1].Value = lat + " : " + lon;
  104.                     row.Cells[2].Value = Convert.ToString(alt);
  105.                     if (sta == 1)
  106.                     {
  107.                         row.Cells[3].Value = "Hover";
  108.                         row.Cells[4].Value = Convert.ToString(dur);
  109.                     }
  110.                     else if (sta == 0)
  111.                     {
  112.                         row.Cells[3].Value = "Flyby";
  113.                         row.Cells[4].Value = "N/A";
  114.                     }
  115.  
  116.                     UpdateWP(row);
  117.                 }
  118.             }
  119.  
  120.             break;
  121.  
  122.         case REM:
  123.  
  124.             count = waypointManager.Rows.Count;
  125.             for (int i = 0; i < (count - 1); i++)
  126.             {
  127.                 UpdateRemWP(0);
  128.                 UpdateRemCombo(0);
  129.             }
  130.  
  131.             for (int i = 0; val == (Int16)2; i++)
  132.             {
  133.                 opCode[0] = pack[0 + (32 * (i + 1))];
  134.                 opCode[1] = pack[1 + (32 * (i + 1))];
  135.  
  136.                 latitude[0] = pack[4 + (32 * i)];
  137.                 latitude[1] = pack[5 + (32 * i)];
  138.                 latitude[2] = pack[6 + (32 * i)];
  139.                 latitude[3] = pack[7 + (32 * i)];
  140.                 latitude[4] = pack[8 + (32 * i)];
  141.                 latitude[5] = pack[9 + (32 * i)];
  142.                 latitude[6] = pack[10 + (32 * i)];
  143.                 latitude[7] = pack[11 + (32 * i)];
  144.  
  145.                 longitude[0] = pack[12 + (32 * i)];
  146.                 longitude[1] = pack[13 + (32 * i)];
  147.                 longitude[2] = pack[14 + (32 * i)];
  148.                 longitude[3] = pack[15 + (32 * i)];
  149.                 longitude[4] = pack[16 + (32 * i)];
  150.                 longitude[5] = pack[17 + (32 * i)];
  151.                 longitude[6] = pack[18 + (32 * i)];
  152.                 longitude[7] = pack[19 + (32 * i)];
  153.  
  154.                 altitude[0] = pack[20 + (32 * i)];
  155.                 altitude[1] = pack[21 + (32 * i)];
  156.                 altitude[2] = pack[22 + (32 * i)];
  157.                 altitude[3] = pack[23 + (32 * i)];
  158.                 altitude[4] = pack[24 + (32 * i)];
  159.                 altitude[5] = pack[25 + (32 * i)];
  160.                 altitude[6] = pack[26 + (32 * i)];
  161.                 altitude[7] = pack[27 + (32 * i)];
  162.  
  163.                 status[0] = pack[28 + (32 * i)];
  164.                 status[1] = pack[29 + (32 * i)];
  165.  
  166.                 duration[0] = pack[30 + (32 * i)];
  167.                 duration[1] = pack[31 + (32 * i)];
  168.  
  169.                 val = BitConverter.ToInt16(opCode, 0);
  170.                 lat = BitConverter.ToDouble(latitude, 0);
  171.                 lon = BitConverter.ToDouble(longitude, 0);
  172.                 alt = BitConverter.ToDouble(altitude, 0);
  173.                 sta = BitConverter.ToInt16(status, 0);
  174.                 dur = BitConverter.ToInt16(duration, 0);
  175.  
  176.                 if (alt != 0)
  177.                 {
  178.                     UpdateCombo(Convert.ToString(i));
  179.  
  180.                     DataGridViewRow row = new DataGridViewRow();
  181.                     row.CreateCells(waypointManager);
  182.  
  183.                     row.Cells[0].Value = Convert.ToString(i);
  184.                     row.Cells[1].Value = lat + " : " + lon;
  185.                     row.Cells[2].Value = Convert.ToString(alt);
  186.                     if (sta == 1)
  187.                     {
  188.                         row.Cells[3].Value = "Hover";
  189.                         row.Cells[4].Value = Convert.ToString(dur);
  190.                     }
  191.                     else if (sta == 0)
  192.                     {
  193.                         row.Cells[3].Value = "Flyby";
  194.                         row.Cells[4].Value = "N/A";
  195.                     }
  196.  
  197.                     UpdateWP(row);
  198.                 }
  199.             }
  200.  
  201.             break;
  202.  
  203.         default:
  204.             break;
  205.     }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement