Skip to content
Controler.java 64.9 KiB
Newer Older
xtof's avatar
xtof committed
package org.josast.UVSQsatDecoder;


import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileWriter;
xtof's avatar
xtof committed
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
xtof's avatar
xtof committed
import java.util.logging.Logger;

import javax.imageio.ImageIO;


import org.josast.ModuleSoundModem.SoundModemConfiguration;
import org.josast.SIDS.Station;
import org.josast.UVSQsatDecoder.util.LogFile;
import org.josast.javafx.AlertHelper;
import org.josast.propertyHttp.ConfigHttp;
xtof's avatar
xtof committed
import org.josast.uvsqsat.Frame;
import org.josast.uvsqsat.generated.Uvsqsat.AntsHk;
xtof's avatar
xtof committed
import org.josast.uvsqsat.generated.Uvsqsat.Beacon;
import org.josast.uvsqsat.generated.Uvsqsat.IepsHkStatus;
import org.josast.uvsqsat.generated.Uvsqsat.ImtqHk;
import org.josast.uvsqsat.generated.Uvsqsat.MainboardAllScience;
import org.josast.uvsqsat.generated.Uvsqsat.MainboardHk;
import org.josast.uvsqsat.generated.Uvsqsat.ObcHk;
import org.josast.uvsqsat.generated.Uvsqsat.ObcStatus;
import org.josast.uvsqsat.generated.Uvsqsat.TrxvurxHk;
import org.josast.uvsqsat.generated.Uvsqsat.TrxvutxHk;
xtof's avatar
xtof committed
import org.josast.uvsqsat.generated.Uvsqsat.UiFrame;
xtof's avatar
xtof committed

import javafx.application.Platform;
import javafx.concurrent.WorkerStateEvent;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
xtof's avatar
xtof committed
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
xtof's avatar
xtof committed
import javafx.stage.Stage;
import javafx.stage.Window;


public class Controler {
	
	private static Logger appLogger = Logger.getLogger("AmsatLogger");
	private int delayRefresh = 6; // toute les 6 heures 
xtof's avatar
xtof committed

xtof's avatar
xtof committed
    private LogFile logfile = null;
    private static final String LINE_SEPARATOR = "\r\n";
    private static final int STATE_INIT = 0;
    private static final int STATE_START = 1;
    protected static final int STATE_STOP = 2;
    private static final int STATE_SAVE = 3;
    
// 
	private Ax25Display ax25display = new Ax25Display();
	private DisplayUVSQsat displayUVSQsat = new DisplayUVSQsat();
    ModelReceivedData receivedFrame = new ModelReceivedData();
    private TaskSoundmodemTCP task;
    private SendSIDS SendSIDSSatnogs;
    private SendSIDS SendSIDSMVPAmsat;
    private String imgAmsat = "logoAmsat.png";
    private String imgSatellite = "OIP.jpg";
    Station station = new Station();
    Configuration conf = Configuration.getInstance();
    private String version = "0.6";
xtof's avatar
xtof committed
// main variable
	@FXML
	private TextArea DecodedData;
    @FXML
    private Label LabelFrame;
    @FXML
    private Label LabelInformation;
    @FXML
    private Button ButtonStart;
    @FXML
    private Button ButtonStop;
    @FXML
    private Button ButtonSave;
    
    @FXML
    private Button ButtonSaveConfiguration;
    
    
    @FXML
    private Label labelStatus;
    @FXML
    private TextArea TexAreaLog;
    @FXML
    private TextField TextFieldCallsign;
    @FXML
    private TextField TextFieldLatitude;
    @FXML
    private TextField TextFieldLongitude;

    @FXML
	private CheckBox CheckboxAmsatFDatabase;
    @FXML
    private CheckBox CheckBoxSatNogs;    
    @FXML
    private TextField TextFieldSIDSEntrysat;
    @FXML
    private TextField TextFieldSIDSSatnogs;

    @FXML
    private TextField FieldIP;
    @FXML
    private TextField FieldPort;
    
    @FXML
    private ImageView ImageViewAMSAT;

    @FXML
    private ImageView imageViewSatellite;
    
    
    @FXML 
    private WebView WebViewInfo;
    
    @FXML
    private VBox VboxInfo;
// 
@FXML
private TextField tfDateCurrent;

@FXML
private TextField tfFrameSid;

@FXML
private TextField tfFrameName;

private Stage primaryStage = null;

// Add generated FXML variable 
xtof's avatar
xtof committed
@FXML
private TextField tfsideAAntsTemperatureRaw;
@FXML
private TextField tfsideAAntsDeploymentStatusRaw;
@FXML
private TextField tfsideAAntsUptimeRaw;
@FXML
private TextField tfsideADeploymentCountAntenna1Raw;
@FXML
private TextField tfsideADeploymentCountAntenna2Raw;
@FXML
private TextField tfsideADeploymentCountAntenna3Raw;
@FXML
private TextField tfsideADeploymentCountAntenna4Raw;
@FXML
private TextField tfsideADeploymentTimeAntenna1Raw;
@FXML
private TextField tfsideADeploymentTimeAntenna2Raw;
@FXML
private TextField tfsideADeploymentTimeAntenna3Raw;
@FXML
private TextField tfsideADeploymentTimeAntenna4Raw;
@FXML
private TextField tfsideBAntsTemperatureRaw;
@FXML
private TextField tfsideBAntsDeploymentStatusRaw;
@FXML
private TextField tfsideBAntsUptimeRaw;
@FXML
private TextField tfsideBDeploymentCountAntenna1Raw;
@FXML
private TextField tfsideBDeploymentCountAntenna2Raw;
@FXML
private TextField tfsideBDeploymentCountAntenna3Raw;
@FXML
private TextField tfsideBDeploymentCountAntenna4Raw;
@FXML
private TextField tfsideBDeploymentTimeAntenna1Raw;
@FXML
private TextField tfsideBDeploymentTimeAntenna2Raw;
@FXML
private TextField tfsideBDeploymentTimeAntenna3Raw;
@FXML
private TextField tfsideBDeploymentTimeAntenna4Raw;

// beacon

@FXML
private TextField tfswModeRaw;
@FXML
private TextField tfresetOrderRaw;
@FXML
private TextField tfformatSdcardOrderRaw;
@FXML
private TextField tfnbTcPingSinceFirstStartRaw;

// IEPS HK
xtof's avatar
xtof committed

@FXML
private TextField tfhKStidRaw;
@FXML
private TextField tfhKIvidRaw;
@FXML
private TextField tfhKRcRaw;
@FXML
private TextField tfhKBidRaw;
@FXML
private TextField tfhKCmderrRaw;
@FXML
private TextField tfhKStatRaw;
@FXML
private TextField tfvoltBrdSupRawV;
@FXML
private TextField tftempRawT;
@FXML
private TextField tfvDistInputRawV;
@FXML
private TextField tfiDistInputRawMa;
@FXML
private TextField tfpDistInputRawMw;
xtof's avatar
xtof committed
@FXML
private TextField tfvBattInputRawV;
xtof's avatar
xtof committed
@FXML
private TextField tfiBattInputRawMa;
@FXML
private TextField tfpBattInputRawMw;
@FXML
private TextField tfstatObcOnRaw;
@FXML
private TextField tfstatObcOcfRaw;
@FXML
private TextField tfbatStatRaw;
@FXML
private TextField tfbatTemp2RawT;
@FXML
private TextField tfvoltVd0Raw;
@FXML
private TextField tfvoltVd1Raw;
@FXML
private TextField tfvoltVd2Raw;
@FXML
xtof's avatar
xtof committed
private TextField tfvObc00V;
@FXML
private TextField tfiObc00Ma;
@FXML
private TextField tfpObc00Mw;
@FXML
private TextField tfvObc01V;
@FXML
private TextField tfiObc01Ma;
@FXML
private TextField tfpObc01Mw;
@FXML
private TextField tfvObc02V;
@FXML
private TextField tfiObc02Ma;
@FXML
private TextField tfpObc02Mw;
@FXML
private TextField tfvObc03V;
@FXML
private TextField tfiObc03Ma;
@FXML
private TextField tfpObc03Mw;
@FXML
private TextField tfvObc05V;
@FXML
private TextField tfiObc05Ma;
@FXML
private TextField tfpObc05Mw;
@FXML
private TextField tfvObc06V;
@FXML
private TextField tfiObc06Ma;
@FXML
private TextField tfpObc06Mw;
@FXML
private TextField tfcc1Byte;
@FXML
private TextField tfcc2Byte;
@FXML
private TextField tfcc3Byte;
@FXML
private TextField tfstatusStidRaw;
@FXML
private TextField tfstatusIvidRaw;
@FXML
private TextField tfstatusRcRaw;
@FXML
private TextField tfstatusBidRaw;
@FXML
private TextField tfstatusCmderrRaw;
@FXML
private TextField tfstatusStatRaw;
@FXML
private TextField tfmodeRaw;
@FXML
private TextField tfconfRaw;
@FXML
private TextField tfresetCauseRaw;
@FXML
private TextField tfuptimeRaw;
@FXML
private TextField tferrorRaw;
@FXML
private TextField tfrcCntPwronRaw;
@FXML
private TextField tfrcCntWdgRaw;
@FXML
private TextField tfrcCntCmdRaw;
@FXML
private TextField tfrcCntMcuRaw;
@FXML
private TextField tfrcCntEmlopoRaw;
@FXML
private TextField tfprevcmdElapsedRaw;

xtof's avatar
xtof committed
@FXML
private TextField tfdigitaleVoltageV;
@FXML
private TextField tfanalogVoltageV;
@FXML
private TextField tfdigitalCurrentRaw;
@FXML
private TextField tfanalogCurrentRaw;
@FXML
private TextField tfmeasureCoilXCurrentMa;
@FXML
private TextField tfmeasureCoilYCurrentMa;
@FXML
private TextField tfmeasureCoilZCurrentMa;
@FXML
private TextField tfmeasureCoilXTemperatureC;
@FXML
private TextField tfmeasureCoilYTemperatureC;
@FXML
private TextField tfmeasureCoilZTemperatureC;
@FXML
private TextField tfmcuTemperatureC;
@FXML
private TextField tfimtqSystemStateModeRaw;
@FXML
private TextField tfimtqSystemStateErrorRaw;
@FXML
private TextField tfimtqSystemStateConfigurationRaw;
@FXML
private TextField tfimtqSystemStateUptimeRaw;

// Mainboard ALL Science
xtof's avatar
xtof committed

@FXML
private TextField tfmainboardScienceTimeRaw;
@FXML
private TextField tfteachWearOnRaw;
xtof's avatar
xtof committed
@FXML
private TextField tffrequenceOfAcquisitionsRaw;
@FXML
private TextField tfgainRaw;
@FXML
private TextField tfnumberOfAcquisitionCommandedRaw;
@FXML
private TextField tfnumberOfRealAcquisitionRaw;
xtof's avatar
xtof committed
@FXML
private TextField tfhkPlus5vRaw;
xtof's avatar
xtof committed
@FXML
private TextField tfhkMinus5vRaw;
@FXML
private TextField tfhkMinus5vPolarRaw;
@FXML
private TextField tfhkTempAdcRaw;
@FXML
private TextField tfhkFeePlusXVrefRaw;
@FXML
private TextField tfhkFeeMinusXVrefRaw;
@FXML
private TextField tfhkFeePlusYVrefRaw;
@FXML
private TextField tfhkFeeMinusYVrefRaw;
xtof's avatar
xtof committed
@FXML
private TextField tffeePlusXErs1SignalRaw;
@FXML
private TextField tffeePlusXErs1TemperatureRaw;
@FXML
private TextField tffeePlusXErs2SignalRaw;
@FXML
private TextField tffeePlusXErs2TemperatureRaw;
@FXML
private TextField tffeePlusXErs3SignalRaw;
@FXML
private TextField tffeePlusXErs3TemperatureRaw;
@FXML
private TextField tffeePlusXUvsSignalRaw;
@FXML
private TextField tffeeMinusXErs1SignalRaw;
@FXML
private TextField tffeeMinusXErs1TemperatureRaw;
@FXML
private TextField tffeeMinusXErs2SignalRaw;
@FXML
private TextField tffeeMinusXErs2TemperatureRaw;
@FXML
private TextField tffeeMinusXErs3SignalRaw;
@FXML
private TextField tffeeMinusXErs3TemperatureRaw;
@FXML
private TextField tffeeMinusXUvsSignalRaw;
@FXML
private TextField tffeePlusYErs1SignalRaw;
@FXML
private TextField tffeePlusYErs1TemperatureRaw;
@FXML
private TextField tffeePlusYErs2SignalRaw;
@FXML
private TextField tffeePlusYErs2TemperatureRaw;
@FXML
private TextField tffeePlusYErs3SignalRaw;
@FXML
private TextField tffeePlusYErs3TemperatureRaw;
@FXML
private TextField tffeePlusYUvsSignalRaw;
@FXML
private TextField tffeeMinusYErs1SignalRaw;
@FXML
private TextField tffeeMinusYErs1TemperatureRaw;
@FXML
private TextField tffeeMinusYErs2SignalRaw;
@FXML
private TextField tffeeMinusYErs2TemperatureRaw;
@FXML
private TextField tffeeMinusYErs3SignalRaw;
@FXML
private TextField tffeeMinusYErs3TemperatureRaw;
@FXML
private TextField tffeeMinusYUvsSignalRaw;
@FXML
private TextField tfteachwearAccXRaw;
@FXML
private TextField tfteachwearAccYRaw;
@FXML
private TextField tfteachwearAccZRaw;
@FXML
private TextField tfteachwearDegCRaw;
@FXML
private TextField tfteachwearGyroXRaw;
@FXML
private TextField tfteachwearGyroYRaw;
@FXML
private TextField tfteachwearGyroZRaw;
@FXML
private TextField tfteachwearMagnXRaw;
@FXML
private TextField tfteachwearMagnYRaw;
@FXML
private TextField tfteachwearMagnZRaw;
@FXML
private TextField tfteachwearStateRaw;
@FXML
private TextField tfteachwearResetReasonRaw;
@FXML
private TextField tfteachwearCRCRaw;
@FXML
private TextField tfnbTmSinceFirstStartRaw;
xtof's avatar
xtof committed

// Mainboard HK
xtof's avatar
xtof committed

@FXML
private TextField tfmainboardHKTimeRaw;
@FXML
private TextField tfhkPlus5VRaw;
@FXML
private TextField tfhkMinus5VRaw;
@FXML
private TextField tfhkMinusPolarRaw;
@FXML
private TextField tfhkTempADCRaw;
//@FXML
//private TextField tfhkFeePlusXVrefRaw;
//@FXML
//private TextField tfhkFeeMinusXVrefRaw;
//@FXML
//private TextField tfhkFeePlusYVrefRaw;
//@FXML
//private TextField tfhkFeeMinusYVrefRaw;
xtof's avatar
xtof committed

xtof's avatar
xtof committed

@FXML
private TextField tfdummyRaw;
//@FXML
//private TextField tfspiCommandStatusRaw;
xtof's avatar
xtof committed
@FXML
private TextField tfsupervisorEnableStatusRaw;
@FXML
private TextField tfsupervisorUptimeRaw;
@FXML
private TextField tfiobcResetCountRaw;
@FXML
private TextField tfiobcUptimeRaw;
@FXML
xtof's avatar
xtof committed
private TextField tfiobcMeasureTemperatureRaw;
@FXML
private TextField tfiobcMeasure3v3InRaw;
xtof's avatar
xtof committed
@FXML
private TextField tfiobcMeasure3v3Raw;
@FXML
private TextField tfiobcMeasure2vReferenceRaw;
@FXML
private TextField tfiobcMeasure1v8Raw;
@FXML
private TextField tfiobcMeasure1v0Raw;
@FXML
private TextField tfiobcMeasureCurrent3v3Raw;
@FXML
private TextField tfiobcMeasureCurrent1v8Raw;
@FXML
private TextField tfiobcMeasureCurrent1v0Raw;
@FXML
private TextField tfiobcMeasureVoltRtcRaw;
@FXML
private TextField tfiobcAdcUpdateFlagRaw;
@FXML
private TextField tfiobcCrc8Raw;
@FXML
private TextField tfphotodiode1Raw;
@FXML
private TextField tfphotodiode2Raw;
@FXML
private TextField tfphotodiode3Raw;
@FXML
private TextField tfphotodiode4Raw;
@FXML
private TextField tfphotodiode5Raw;
@FXML
private TextField tfphotodiode6Raw;
@FXML
private TextField tfpanelTemperature1C;
@FXML
private TextField tfpanelTemperature2C;
@FXML
private TextField tfpanelTemperature3C;
@FXML
private TextField tfpanelTemperature4C;
@FXML
private TextField tfpanelTemperature5C;
@FXML
private TextField tfpanelTemperature6C;

xtof's avatar
xtof committed

@FXML
private TextField tfdummydummy;
@FXML
private TextField tfspiCommandStatusRaw;
xtof's avatar
xtof committed
@FXML
private TextField tfsupervisorIndexOfSubsystemRaw;
@FXML
private TextField tfsupervisorMajorVersionRaw;
@FXML
private TextField tfsupervisorMinorVersionRaw;
@FXML
private TextField tfsupervisorPatchVersionRaw;
@FXML
private TextField tfsupervisorGitHeadVersionRaw;
@FXML
private TextField tfsupervisorSerialNumberRaw;
@FXML
private TextField tfcompilationInformationByte;
@FXML
private TextField tfclockSpeedRaw;
@FXML
private TextField tfcodeTypeRaw;
@FXML
private TextField tfcrc8Raw;
@FXML
private TextField tfswMmodeRaw;
@FXML
private TextField tflastResetReasonRaw;
@FXML
private TextField tfreservedRaw;
@FXML
private TextField tfnbResetRaw;
@FXML
private TextField tfreserved2Raw;
@FXML
private TextField tfdeployAntennasSystemRaw;
//@FXML
//private TextField tfnbTmSinceFirstStartRaw;
xtof's avatar
xtof committed
@FXML
private TextField tfnbTcSinceFirstStartRaw;
@FXML
private TextField tfnbBadTcSinceFirstStartRaw;
@FXML
private TextField tfnbTmInSdcardRaw;
@FXML
private TextField tfsdcardStatusRaw;
@FXML
private TextField tfsdcardLastErrorRaw;
@FXML
private TextField tfoldTimeTMInSdcardRaw;
@FXML
private TextField tfnewTimeTMInSdcardRaw;
xtof's avatar
xtof committed
@FXML
private TextField tftrxvurxInstantaneousReceivedSignalDopplerHz;
@FXML
private TextField tftrxvurxInstantaneousReceivedSignalStrengthDbm;
@FXML
private TextField tftrxvurxSupplyVoltageV;
@FXML
private TextField tftrxvurxTotalSupplyCurrentMa;
@FXML
private TextField tftrxvurxTransmitterCurrentMa;
@FXML
private TextField tftrxvurxReceiverCurrentMa;
@FXML
private TextField tftrxvurxPowerAmplifierCurrentMa;
@FXML
private TextField tftrxvurxPowerAmplifierTemperatureC;
@FXML
private TextField tftrxvurxLocalOscillatorTemperatureC;
@FXML
private TextField tftrxvurxZeroPaddingRaw;
@FXML
xtof's avatar
xtof committed
private TextField tftrxvuRxUptimeRaw;

xtof's avatar
xtof committed
@FXML
private TextField tftrxvutxInstantaneousRfReflectedPowerFromTransmitterPortMw;
@FXML
private TextField tftrxvutxInstantaneousRfForwardPowerFromTransmitterPortMw;
@FXML
private TextField tftrxvutxSupplyVoltageV;
@FXML
private TextField tftrxvutxTotalSupplyCurrentMa;
@FXML
private TextField tftrxvutxTransmitterCurrentMa;
@FXML
private TextField tftrxvutxReceiverCurrentMa;
@FXML
private TextField tftrxvutxPowerAmplifierCurrentMa;
@FXML
private TextField tftrxvutxPowerAmplifierTemperatureC;
@FXML
private TextField tftrxvutxLocalOscillatorTemperatureC;
@FXML
private TextField tftrxvutxZeroPaddingRaw;
@FXML
private TextField tftrxvuTxUptimeRaw;
@FXML
private TextField tftrxvuTxStateRaw;

@FXML 
private Tab TabDataSream;
@FXML 
private Tab infoTab;
xtof's avatar
xtof committed

ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
private ScheduledFuture<?> scheduledFuture = null;
xtof's avatar
xtof committed


private void setupDataStream ()
{
	
	ReceivedData decodedData = receivedFrame.getLastReceivedData();
	if (decodedData != null) {
	DecodedData.clear();
    ax25display.setdata(decodedData);
    if (ax25display.GetCallsignFrom().contains("LATMOS")) {
			displayUVSQsat.setData(decodedData);
			Frame frame = displayUVSQsat.getFrame();
			if (frame !=null)
				{
				DecodedData.appendText(displayUVSQsat.getData());
				}
				else 
				{		
					DecodedData.appendText(ax25display.getDisplay());
				}	 
				// release memory 
				frame=null;
			}else 
			{
				DecodedData.appendText(ax25display.getDisplay());
			}
	   }
	else 
	{
		DecodedData.setText("No Value to display");
	}
}


@FXML 
	private void  HandleTabDataSreamChange()
	{
	
	 Platform.runLater(new Runnable() {
         @Override
         public void run() {
        	 if(TabDataSream.isSelected())
        	 setupDataStream();
         }});
	
	}

xtof's avatar
xtof committed
    private void HandleIP(ActionEvent event)
    {
        
    }
    
        @FXML
    private void HandlePort(ActionEvent event)
    {
        
    }

        @FXML
        private void handleStart(ActionEvent event) {

            manageStatusinformation("Connected to modem", "Connection to modem");
            manageStateMMI(STATE_START);

            // TODO : to improve
            SoundModemConfiguration smc = new SoundModemConfiguration("configuration.ini");
xtof's avatar
xtof committed
            smc.setSmIPadress(FieldIP.getText());
            smc.setSmPort(Integer.parseInt(FieldPort.getText()));

            if (task == null) {
                receivedFrame
                        .addPropertyChangeListener(new PropertyChangeListener() {
                            @Override
                            public void propertyChange(PropertyChangeEvent evt) {
                            	
                            	// final ; 
                      //   final   ReceivedData decodedData = receivedFrame.getLastReceivedData();
xtof's avatar
xtof committed
                                Platform.runLater(new Runnable() {
                                    @Override
                                    public void run() {
                                    	 ReceivedData decodedData = receivedFrame.getLastReceivedData();
                                    	
xtof's avatar
xtof committed
                                        try {

;
        									
                                            if (decodedData != null) {
                                            	
            									updateFrame(receivedFrame.getNumberFrame());
            									ax25display.setdata(decodedData);
xtof's avatar
xtof committed

        										if (ax25display.GetCallsignFrom().contains("LATMOS")) {
        											
        											SendSids(decodedData);      											
xtof's avatar
xtof committed
        											displayUVSQsat.setData(decodedData);
xtof's avatar
xtof committed
        											Frame frame = displayUVSQsat.getFrame();
        											if (frame !=null)
        											{
xtof's avatar
xtof committed
        											String date = displayUVSQsat.getFrame().getPacketSecondaryHeader().getTime();
        											tfDateCurrent.setText(date);
        											int sid =  displayUVSQsat.getFrame().getSid();
        											tfFrameSid.setText(""+sid);
        											if(TabDataSream.isSelected()) // append le texte uniquement si visible
        											{
xtof's avatar
xtof committed
        											DecodedData.appendText(displayUVSQsat.getData());
        											displayUvsqsat(sid,(UiFrame) displayUVSQsat.getFrame().getUiFrame());
        											
        											//release memory
        											
        											date=null;
xtof's avatar
xtof committed
        											}
        											else 
        											{
        												displayLog( "Frame not reconized");
                    									ax25display.setdata(decodedData);
                    									displayLog(decodedData.toString());
                										DecodedData.appendText(ax25display.getDisplay());
        											}
        												 
        											// release memory 
        											frame=null;
        										}else 
        										{
                									ax25display.setdata(decodedData);
                									displayLog(decodedData.toString());
            									//	DecodedData.appendText(ax25display.getDisplay());
xtof's avatar
xtof committed
        										}


                                            } else {
                                                displayLog(
                                                        "received frame  : null");
                                            }
xtof's avatar
xtof committed
                                        } catch (Exception e) {
                                            displayLog("Run - error");
                                            displayLog(e.toString());
                                            e.printStackTrace();
                                        }
                                        decodedData = null;
xtof's avatar
xtof committed
                                    }

xtof's avatar
xtof committed
                                });
                            }

                        }

                        );

            }
            task = new TaskSoundmodemTCP(smc, receivedFrame);

            task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {

                @Override
                public void handle(WorkerStateEvent event) {
                    // La tache s'est correctement terminee.
                    manageStatusinformation("KISS TCP CONNECTION FAILED",
                            "KISS TCP DISCONNECTED");
                    manageStateMMI(STATE_STOP);

                }

            });

            task.setOnFailed(new EventHandler<WorkerStateEvent>() {

                @Override
                public void handle(WorkerStateEvent event) {
                    // La tache s'est correctement terminee.
                    manageStatusinformation("KISS TCP CONNECTION FAILED",
                            "KISS TCP DISCONNECTED - Connection failed");
                    displayLog(event.toString());
                    displayLog(event.getSource().toString());
                    manageStateMMI(STATE_STOP);
                }

            });

            Thread backgroundThread = new Thread(task);
            backgroundThread.setDaemon(true);
            backgroundThread.start();

        }
            @FXML
    private void handleStop(ActionEvent event)
    {
                manageStateMMI(STATE_STOP);
                task.arreter();
                manageStatusinformation("Stop received data",
                        "Stop task to receive telemetrie");
        
    }
             @FXML
    private void handleSave(ActionEvent event)
    {
                 manageStateMMI(STATE_SAVE);
                 manageStatusinformation("save data", "save Telemetry in file");
                 saveDataFile();
                 manageStatusinformation("Data Saved", "Telemetry Data saved in file");
xtof's avatar
xtof committed
    }
xtof's avatar
xtof committed
     private void HandleSaveConfiguration(ActionEvent event) {

             String erreurmsg = null;
             String Callsign = null;

             if (TextFieldCallsign.getText().isEmpty()) {
                 erreurmsg += "please enter a CallSign \r\n";
             } else {
                 Callsign = TextFieldCallsign.getText();
             }

             String Latitude = TextFieldLatitude.getText();
             String Longitude = TextFieldLongitude.getText();

             if (station.checkLatitude(Latitude) == false) {
                 erreurmsg += "Wrong format for Latitude : XX.XXE/W \r\n";
             }

             if (station.checkLongitude(Longitude) == false) {
                 erreurmsg += "Wrong format for Longitude : XX.XXS/N \r\n";
             }
             if (erreurmsg != null) {
                 Window owner = ButtonSaveConfiguration.getScene().getWindow();
                 AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Form Error!",
                         erreurmsg);
                 return;
             }

             station.setCallsign(Callsign);
             station.setLatitude(Latitude);
             station.setLongitude(Longitude);

             conf.setCallsign(Callsign);
             conf.setLatitude(Latitude);
             conf.setLongitude(Longitude);

             conf.setSIDSAMSATSource(TextFieldSIDSEntrysat.getText());
             conf.setSIDSSatnogsSource(TextFieldSIDSSatnogs.getText());
             conf.setSoundModemIP(FieldIP.getText());
             conf.setSoundModemPort(FieldPort.getText());

             Station StationSatnogs = new Station(conf.getSIDSSatnogsSource(),
                     station.getLongitude(), station.getLatitude());
             Station StationEntry = new Station(conf.getSIDSAMSATSource(),
                     station.getLongitude(), station.getLatitude());

             if (CheckboxAmsatFDatabase.isSelected() == true) {
                 conf.setSIDSAMSAT("1");
                 SendSIDSMVPAmsat = new SendSIDS(StationEntry, conf.getNorad(),
                         conf.getSIDSAMSATUrl());
             } else {
                 conf.setSIDSAMSAT("0");

             }

             if (CheckBoxSatNogs.isSelected() == true) {
                 conf.setSIDSSatnogs("1");
                 SendSIDSSatnogs = new SendSIDS(StationSatnogs, conf.getNorad(),
                         conf.getSIDSSatnogsURL());
             } else {
                 conf.setSIDSSatnogs("0");
             }

             conf.save();
             manageStatusinformation("Configuration Saved", "Configuration Saved");

         }

     
     public void updateDistantconfiguration ()
     {
	        String ver;
	        String message;
	        int NoradIdConf = conf.getNorad();
	        
	        ConfigHttp c = new ConfigHttp("http://site.amsat-f.org/download/117652/");
	        if (c.isConnected()) {
	            ver = c.GetProperty("UVSQSatDecoder");
	            message = c.GetProperty("Message");
	            String noradid =  c.GetProperty("NoradID");
	      
	            if(noradid!=null)
	            {
	            NoradIdConf = Integer
	                    .parseUnsignedInt(c.GetProperty("NoradID").trim());
	            
	            }
	        } else {
	            ver = version;
	            message = "not connected to internet";
	        }
	        if (NoradIdConf != 0)
	        {
	            // ID norad attribué - mise à jours du logiciel 
	            if (NoradIdConf != conf.getNorad()) {
	                conf.setNorad(NoradIdConf);
	                conf.save();
	                SendSIDSSatnogs.setNorad(NoradIdConf);
	                SendSIDSMVPAmsat.setNorad(NoradIdConf);
	                displayLog("Norad ID updated  ");
	            }
	        }
	        final String erreurmsg;

	        if (ver.equals(version) == false) {
	            erreurmsg = message + " New version " + ver + " available ! ";