2011-09-08 22:31:32 -03:00
using System ;
using System.Collections.Generic ;
using System.Windows.Forms ;
using System.Net ;
using System.IO ;
using System.Text ;
2012-01-15 05:00:50 -04:00
using System.Threading ;
2012-02-26 19:13:23 -04:00
using log4net ;
using log4net.Config ;
2011-09-08 22:31:32 -03:00
namespace ArdupilotMega
{
static class Program
{
2012-02-26 19:13:23 -04:00
private static readonly ILog log = LogManager . GetLogger ( "Program" ) ;
2011-09-08 22:31:32 -03:00
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main ( )
{
2012-03-03 03:42:41 -04:00
Application . EnableVisualStyles ( ) ;
XmlConfigurator . Configure ( ) ;
log . Info ( "******************* Logging Configured *******************" ) ;
Application . SetCompatibleTextRenderingDefault ( false ) ;
2011-09-08 22:31:32 -03:00
2012-02-26 19:13:23 -04:00
Application . ThreadException + = Application_ThreadException ;
2011-09-08 22:31:32 -03:00
2012-07-16 10:37:35 -03:00
Application . Idle + = Application_Idle ;
2011-11-08 09:22:07 -04:00
2012-03-09 11:18:12 -04:00
int wt = 0 , ct = 0 ;
ThreadPool . GetMaxThreads ( out wt , out ct ) ;
log . Info ( "Max Threads: " + wt ) ;
2012-03-01 09:27:03 -04:00
2012-03-09 11:18:12 -04:00
//MagCalib.ProcessLog();
2012-03-01 09:27:03 -04:00
2011-11-19 20:17:17 -04:00
//MessageBox.Show("NOTE: This version may break advanced mission scripting");
2011-11-18 10:33:44 -04:00
2012-01-09 20:16:10 -04:00
//Common.linearRegression();
2012-05-13 07:56:42 -03:00
//Console.WriteLine(srtm.getAltitude(-35.115676879882812, 117.94178754638671,20));
2012-06-04 06:56:46 -03:00
/ *
Arduino . ArduinoSTK comport = new Arduino . ArduinoSTK ( ) ;
2012-05-13 07:56:42 -03:00
2012-06-04 06:56:46 -03:00
comport . PortName = "com4" ;
comport . BaudRate = 57600 ;
comport . Open ( ) ;
comport . connectAP ( ) ;
comport . sync ( ) ;
comport . sync ( ) ;
Console . WriteLine ( comport . getChipType ( 0 ) ) ;
Console . WriteLine ( comport . getChipType ( 1 ) ) ;
Console . WriteLine ( comport . getChipType ( 2 ) ) ;
Console . ReadLine ( ) ;
return ;
* /
2012-07-05 20:27:42 -03:00
char [ ] line = "testtesttesttesttest" . ToCharArray ( ) ;
Delta . delta_encode ( ref line ) ;
Delta . delta_decode ( ref line ) ;
2012-04-30 07:48:52 -03:00
if ( System . Diagnostics . Debugger . IsAttached )
{
// testing
2012-05-03 01:40:50 -03:00
// Utilities.ParameterMetaDataParser.GetParameterInformation();
2012-04-30 07:48:52 -03:00
}
2011-12-17 05:22:40 -04:00
try
{
2012-02-26 19:13:23 -04:00
Thread . CurrentThread . Name = "Base Thread" ;
2012-02-17 05:09:27 -04:00
2012-01-15 05:00:50 -04:00
Application . Run ( new MainV2 ( ) ) ;
2011-12-17 05:22:40 -04:00
}
2012-02-26 19:13:23 -04:00
catch ( Exception ex )
{
log . Fatal ( "Fatal app exception" , ex ) ;
Console . WriteLine ( ex . ToString ( ) ) ;
2012-04-11 20:52:57 -03:00
Console . ReadLine ( ) ;
2012-02-26 19:13:23 -04:00
}
2011-09-08 22:31:32 -03:00
}
2011-11-08 09:22:07 -04:00
static void Application_Idle ( object sender , EventArgs e )
{
2012-07-16 10:37:35 -03:00
//System.Threading.Thread.Sleep(10);
//Console.Write("Idle\n");
System . Threading . Thread . Sleep ( 20 ) ;
Application . DoEvents ( ) ;
2011-11-08 09:22:07 -04:00
}
2011-09-08 22:31:32 -03:00
static void Application_ThreadException ( object sender , System . Threading . ThreadExceptionEventArgs e )
{
Exception ex = e . Exception ;
2012-02-29 09:19:54 -04:00
log . Debug ( ex . ToString ( ) ) ;
2011-09-08 22:31:32 -03:00
if ( ex . Message = = "The port is closed." ) {
2012-03-09 11:18:12 -04:00
CustomMessageBox . Show ( "Serial connection has been lost" ) ;
2011-09-08 22:31:32 -03:00
return ;
}
if ( ex . Message = = "A device attached to the system is not functioning." )
{
2012-03-09 11:18:12 -04:00
CustomMessageBox . Show ( "Serial connection has been lost" ) ;
2011-09-08 22:31:32 -03:00
return ;
}
if ( e . Exception . GetType ( ) = = typeof ( MissingMethodException ) )
{
2012-03-09 11:18:12 -04:00
CustomMessageBox . Show ( "Please Update - Some older library dlls are causing problems\n" + e . Exception . Message ) ;
2011-09-08 22:31:32 -03:00
return ;
}
if ( e . Exception . GetType ( ) = = typeof ( ObjectDisposedException ) | | e . Exception . GetType ( ) = = typeof ( InvalidOperationException ) ) // something is trying to update while the form, is closing.
{
return ; // ignore
}
if ( e . Exception . GetType ( ) = = typeof ( FileNotFoundException ) | | e . Exception . GetType ( ) = = typeof ( BadImageFormatException ) ) // i get alot of error from people who click the exe from inside a zip file.
{
2012-07-12 11:06:22 -03:00
CustomMessageBox . Show ( "You are missing some DLL's. Please extract the zip file somewhere. OR Use the update feature from the menu " + e . Exception . ToString ( ) ) ;
// return;
2011-09-08 22:31:32 -03:00
}
2012-03-09 11:18:12 -04:00
DialogResult dr = CustomMessageBox . Show ( "An error has occurred\n" + ex . ToString ( ) + "\n\nReport this Error???" , "Send Error" , MessageBoxButtons . YesNo ) ;
2011-09-08 22:31:32 -03:00
if ( DialogResult . Yes = = dr )
{
try
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest . Create ( "http://vps.oborne.me/mail.php" ) ;
request . Timeout = 10000 ; // 10 sec
// Set the Method property of the request to POST.
request . Method = "POST" ;
// Create POST data and convert it to a byte array.
string postData = "message=" + Environment . OSVersion . VersionString + " " + System . Reflection . Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) + " " + Application . ProductVersion + " Exception " + ex . ToString ( ) . Replace ( '&' , ' ' ) . Replace ( '=' , ' ' ) + " Stack: " + ex . StackTrace . ToString ( ) . Replace ( '&' , ' ' ) . Replace ( '=' , ' ' ) ;
byte [ ] byteArray = Encoding . ASCII . GetBytes ( postData ) ;
// Set the ContentType property of the WebRequest.
request . ContentType = "application/x-www-form-urlencoded" ;
// Set the ContentLength property of the WebRequest.
request . ContentLength = byteArray . Length ;
// Get the request stream.
Stream dataStream = request . GetRequestStream ( ) ;
// Write the data to the request stream.
dataStream . Write ( byteArray , 0 , byteArray . Length ) ;
// Close the Stream object.
dataStream . Close ( ) ;
// Get the response.
WebResponse response = request . GetResponse ( ) ;
// Display the status.
Console . WriteLine ( ( ( HttpWebResponse ) response ) . StatusDescription ) ;
// Get the stream containing content returned by the server.
dataStream = response . GetResponseStream ( ) ;
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader ( dataStream ) ;
// Read the content.
string responseFromServer = reader . ReadToEnd ( ) ;
// Display the content.
Console . WriteLine ( responseFromServer ) ;
// Clean up the streams.
reader . Close ( ) ;
dataStream . Close ( ) ;
response . Close ( ) ;
}
2012-02-26 19:13:23 -04:00
catch
{
2012-03-09 11:18:12 -04:00
CustomMessageBox . Show ( "Error sending Error report!! Youre most likerly are not on the internet" ) ;
2012-02-26 19:13:23 -04:00
}
2011-09-08 22:31:32 -03:00
}
}
}
}