From 12bfd1d018bd70b7fbbb9c23655af43950307991 Mon Sep 17 00:00:00 2001 From: xtophe Date: Mon, 4 May 2020 18:41:26 +0200 Subject: [PATCH 1/2] feat: add first version of Application Amicalsat HMI Minimum functionality : - HMI frame - connection to sound modem - display data received --- .../org/josast/ApplicationAmicalsat/App.java | 80 +++ .../ApplicationAmicalsat/Configuration.java | 235 ++++++++ .../ApplicationAmicalsat/Controler.java | 529 ++++++++++++++++++ .../ModelReceivedData.java | 87 +++ .../ApplicationAmicalsat/ReceivedData.java | 32 ++ .../josast/ApplicationAmicalsat/SendSIDS.java | 37 ++ .../TaskSoundmodemTCP.java | 83 +++ .../ApplicationAmicalsat/util/LogFile.java | 65 +++ .../java/org/josast/javafx/AlertHelper.java | 28 + .../ApplicationAmicalsat/AmicalSatMessage.txt | 3 + .../ApplicationAmicalsat/Amicalsat.fxml | 175 ++++++ .../josast/ApplicationAmicalsat/Amicalsat.jpg | Bin 0 -> 9879 bytes .../josast/ApplicationAmicalsat/logoAmsat.png | Bin 0 -> 6356 bytes .../org/josast/amicalsat/FactoryConsumer.java | 39 ++ .../org/josast/amicalsat/FrameFactory.java | 271 ++++----- 15 files changed, 1514 insertions(+), 150 deletions(-) create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/App.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Configuration.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Controler.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ModelReceivedData.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ReceivedData.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/SendSIDS.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/TaskSoundmodemTCP.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/util/LogFile.java create mode 100644 ApplicationAmicalsat/src/main/java/org/josast/javafx/AlertHelper.java create mode 100644 ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/AmicalSatMessage.txt create mode 100644 ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/Amicalsat.fxml create mode 100644 ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/Amicalsat.jpg create mode 100644 ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/logoAmsat.png create mode 100644 ModuleAmicalsat/src/main/java/org/josast/amicalsat/FactoryConsumer.java diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/App.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/App.java new file mode 100644 index 00000000..7ddecd24 --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/App.java @@ -0,0 +1,80 @@ +package org.josast.ApplicationAmicalsat; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.File; +import java.io.IOException; +import java.util.logging.FileHandler; +import java.util.logging.Logger; + + + +/** + * JavaFX App + */ +public class App extends Application { + + private static Scene scene; + private static FXMLLoader fxmlLoader; + Logger logger = Logger.getLogger("EntrySatLogger"); + + @Override + public void start(Stage stage) throws IOException { + try { + String path = System.getProperty("user.dir")+"/log"; + File apath = new File(path); + + if (!apath.exists()) + { + if (apath.mkdir() == false) + { + System.err.println("fail to create "+ path); + } + } + FileHandler fh=new FileHandler(path+"/"+"EntrySatLog.txt"); + + logger.addHandler(fh); + + } catch (SecurityException e) { + + e.printStackTrace(); + + } catch (IOException e) { + + e.printStackTrace(); + + } + System.setProperty("glass.accessible.force", "false"); + scene = new Scene(loadFXML("Amicalsat"), 640, 480); + stage.setScene(scene); + + Controler ctrl = fxmlLoader.getController(); + ctrl.setPrimaryStage(stage); + scene.getStylesheets().add("/BasicApplication.css"); + // stage.setScene(scene); + stage.setTitle("Amicalsat Decoder"); + ctrl.initMMI(); + stage.show(); + } + + static void setRoot(String fxml) throws IOException { + scene.setRoot(loadFXML(fxml)); + } + + private static Parent loadFXML(String fxml) throws IOException { + fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); + + + + return fxmlLoader.load(); + } + + public static void main(String[] args) { + launch(); + } + +} \ No newline at end of file diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Configuration.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Configuration.java new file mode 100644 index 00000000..bf4dd257 --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Configuration.java @@ -0,0 +1,235 @@ +/** + * + */ +package org.josast.ApplicationAmicalsat; + +import org.josast.property.CONFIG; + +/** + * Singleton to manage all application parameter + * The default configuration is automaticaly saved in a properties file. + * @author christophe + * + * + */ +public class Configuration { + + + /* + * parameter with default value + */ + private String callsign="Anonymous"; + private String longitude="0.0W"; + private String latitude="0.0N"; + + private String soundModemIP="127.0.0.1"; + private String soundModemPort="8100"; + + private String SIDSEntrySatSource="Anonymous"; + private String SIDSEntryUrl="https://amsat.electrolab.fr/SIDS"; + private String SIDSSatnogsSource="Anonymous"; + private String SIDSSatnogsURL="https://db.satnogs.org/api/telemetry/"; + private String SIDSSatnogs="0"; + private String SIDSEntrySat="1"; + private int Norad=99990; // default value - equivalent to satnogs + private boolean SISD_SatNogs = false; + private boolean SIDS_EntrySat = true; + + + private CONFIG conf = CONFIG.getInstance(); + + public static Configuration getInstance() + { + return SingletonHolder.instance; + } + + public boolean isSISD_SatNogs() { + + return SISD_SatNogs; + } + + public boolean isSIDS_EntrySat() { + return SIDS_EntrySat; + } + + private Configuration() + { + if ( conf.GetProperty("Callsign")!=null) + { + callsign = conf.GetProperty("Callsign"); + latitude = conf.GetProperty("Latitude"); + longitude = conf.GetProperty("Longitude"); + + SIDSEntrySatSource=conf.GetProperty("SIDSEntrySatSource"); + SIDSEntryUrl=conf.GetProperty("SIDSEntryUrl"); + SIDSSatnogsSource=conf.GetProperty("SIDSSatnogsSource"); + SIDSSatnogsURL=conf.GetProperty("SIDSSatnogsURL"); + SIDSSatnogs=conf.GetProperty("SIDSSatnogs"); + SIDSEntrySat=conf.GetProperty("SIDSEntrySat"); + soundModemIP = conf.GetProperty("soundModemIP"); + soundModemPort = conf.GetProperty("soundModemPort"); + Norad = Integer.parseUnsignedInt(conf.GetProperty("NoradID").trim()); + if (SIDSSatnogs.contentEquals("1") ) + { + SISD_SatNogs=true; + } else + { + SISD_SatNogs=false; + } + if (SIDSEntrySat.contentEquals("1") ) + { + SIDS_EntrySat=true; + } else + { + SIDS_EntrySat=false; + } + + } + else // si le fichier n'existe pas, il est créé par défaut + { + save(); + } + + + + } + + + private static class SingletonHolder + { + + private final static Configuration instance = new Configuration(); + } + + + + public String getCallsign() { + return callsign; + } + + public void setCallsign(String callsign) { + this.callsign = callsign; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getSIDSEntrySatSource() { + return SIDSEntrySatSource; + } + + public void setSIDSEntrySatSource(String sIDSEntrySatSource) { + SIDSEntrySatSource = sIDSEntrySatSource; + } + + public String getSIDSEntryUrl() { + return SIDSEntryUrl; + } + + public void setSIDSEntryUrl(String sIDSEntryUrl) { + SIDSEntryUrl = sIDSEntryUrl; + } + + public String getSIDSSatnogsSource() { + return SIDSSatnogsSource; + } + + public void setSIDSSatnogsSource(String sIDSSatnogsSource) { + SIDSSatnogsSource = sIDSSatnogsSource; + } + + public String getSIDSSatnogsURL() { + return SIDSSatnogsURL; + } + + public void setSIDSSatnogsURL(String sIDSSatnogsURL) { + SIDSSatnogsURL = sIDSSatnogsURL; + } + + public String getSIDSSatnogs() { + return SIDSSatnogs; + } + + public void setSIDSSatnogs(String sIDSSatnogs) { + SIDSSatnogs = sIDSSatnogs; + if (SIDSSatnogs.contentEquals("1") ) + { + SISD_SatNogs=true; + } else + { + SISD_SatNogs=false; + } + } + + public String getSIDSEntrySat() { + return SIDSEntrySat; + } + + public void setSIDSEntrySat(String sIDSEntrySat) { + SIDSEntrySat = sIDSEntrySat; + if (SIDSEntrySat.contentEquals("1") ) + { + SIDS_EntrySat=true; + } else + { + SIDS_EntrySat=false; + } + } + + public String getSoundModemIP() { + return soundModemIP; + } + + public void setSoundModemIP(String soundModemIP) { + this.soundModemIP = soundModemIP; + } + + public String getSoundModemPort() { + return soundModemPort; + } + + public void setSoundModemPort(String soundModemPort) { + this.soundModemPort = soundModemPort; + } + + public void save() { + + conf.SetProperty("Callsign",callsign); + conf.SetProperty("Latitude",latitude); + conf.SetProperty("Longitude",longitude); + + conf.SetProperty("SIDSEntrySatSource",this.SIDSEntrySatSource); + conf.SetProperty("SIDSEntryUrl",this.SIDSEntryUrl); + conf.SetProperty("SIDSSatnogsSource",this.SIDSSatnogsSource); + conf.SetProperty("SIDSSatnogsURL",this.SIDSSatnogsURL); + conf.SetProperty("SIDSSatnogs",this.SIDSSatnogs); + conf.SetProperty("SIDSEntrySat",this.SIDSEntrySat); + conf.SetProperty("soundModemPort",this.soundModemPort); + conf.SetProperty("soundModemIP",this.soundModemIP); + conf.SetProperty("NoradID",""+this.Norad); + } + + public int getNorad() { + + return Norad; + } + + public void setNorad(int norad) { + + Norad=norad; + } + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Controler.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Controler.java new file mode 100644 index 00000000..8a9450cc --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/Controler.java @@ -0,0 +1,529 @@ +package org.josast.ApplicationAmicalsat; + +import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Logger; + +import javax.imageio.ImageIO; + +import org.josast.ApplicationAmicalsat.util.LogFile; +import org.josast.ModuleSoundModem.SoundModemConfiguration; +import org.josast.SIDS.Station; +import org.josast.amicalsat.Frame; +import org.josast.javafx.AlertHelper; +import org.josast.propertyHttp.ConfigHttp; + +import javafx.application.Platform; +import javafx.concurrent.WorkerStateEvent; + +import javafx.event.ActionEvent; +import javafx.event.EventHandler; + +//import java.util.logging.Logger; + +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.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.stage.Stage; +import javafx.stage.Window; +import javafx.embed.swing.SwingFXUtils; + +public class Controler { + + 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 Logger appLogger = Logger.getLogger("AmicalSatLogger"); + private String version = "0.1"; + + @FXML + private Button ButtonStart; + @FXML + private Button ButtonStop; + @FXML + private Button ButtonSave; + @FXML + private Label LabelIP; + + @FXML + private Button ButtonFile; + @FXML + private Button ButtonSerial; + @FXML + private Button ButtonKiss; + + @FXML + private TextField FieldIP; + @FXML + private TextField FieldPort; + + @FXML + private Label labelStatus; + @FXML + private Label LabelFrame; + + @FXML + private TextArea DecodedData; + + @FXML + private TextArea TexAreaLog; + + @FXML + private TextField textFieldMode; + + @FXML + private TextField textFieldDate; + + @FXML + private Label LabelInformation; + @FXML + private TextField textFieldbEps33VCurrent; + @FXML + private TextField TextFieldEps5VCurrent; + @FXML + private TextField TextFieldepsBattVcurrent; + @FXML + private TextField TextFieldEpsTemp; + @FXML + private TextField TextFieldTrxTemp; + @FXML + private TextField TextFieldEPSVBAT; + + @FXML + private TextField TFBattTemp; + + @FXML + private ImageView ImageViewAMSAT; + + @FXML + private ImageView imageViewEntrysat; + + @FXML + private TextField TextFieldCallsign; + @FXML + private TextField TextFieldLatitude; + @FXML + private TextField TextFieldLongitude; + + @FXML + private CheckBox CheckbBoxAmicalSat; + @FXML + private CheckBox CheckBoxSatNogs; + + @FXML + private Button ButtonSaveConfiguration; + + @FXML + TextField TextFieldSIDSEntrysat; + @FXML + TextField TextFieldSIDSSatnogs; + + Stage primaryStage = null; + + private String imgAmsat = "logoAmsat.png"; + private String imgAmicalsat = "Amicalsat.jpg"; + + Station station = new Station(); + + ModelReceivedData receivedFrame = new ModelReceivedData(); + Configuration conf = Configuration.getInstance(); + + private TaskSoundmodemTCP task; + private SendSIDS SendSIDSSatnogs; + private SendSIDS SendSIDSEntrysat; + private PrintWriter pw; + private LogFile logfile=null; + + + @FXML + 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.setSIDSEntrySatSource(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.getSIDSEntrySatSource(), station.getLongitude(), station.getLatitude()); + + if (CheckbBoxAmicalSat.isSelected() == true) { + conf.setSIDSEntrySat("1"); + SendSIDSEntrysat = new SendSIDS(StationEntry, conf.getNorad(), conf.getSIDSEntryUrl()); + } else { + conf.setSIDSEntrySat("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"); + + } + + @FXML + private void handleStart(ActionEvent event) { + + + manageStatusinformation("Connected to modem","Connection to modem"); + manageStateMMI(STATE_START); + + // TODO : to improve + SoundModemConfiguration smc = new SoundModemConfiguration("default"); + smc.setSmIPadress(FieldIP.getText()); + smc.setSmPort(Integer.parseInt(FieldPort.getText())); + + + if (task == null) { + receivedFrame.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + final Frame decodedData = receivedFrame.getLastDecodedData(); + if (conf.isSIDS_EntrySat()) { + // Generation SIDS + } + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + + if (decodedData != null) { + displayLog(decodedData.toStringHeader()); + displayLog(decodedData.toString()); + updateFrame(receivedFrame.getNumberFrame()); + + } else { + displayLog("received frame : null"); + } + + } catch (Exception e) { + displayLog("Run - error"); + displayLog(e.toString()); + e.printStackTrace(); + } + + } + + }); + } + + } + + ); + + } + task = new TaskSoundmodemTCP(smc, receivedFrame); + + task.setOnSucceeded(new EventHandler() { + + @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() { + + @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"); + } + + + + @FXML + private void HandleIP(ActionEvent event) { + } + + @FXML + private void HandlePort(ActionEvent event) { + } + + + + public void initMMI() { + + + logfile = new LogFile(); + // initialise le log + // initdisplayLogFile(); + + manageStatusinformation("Initialised","ENTRY SAT - LOG \r\n Initialise application") ; + appLogger.warning("Initialise "); + primaryStage.setTitle("AmicalSat Decoder - " + version); + + station.setCallsign(conf.getCallsign()); + station.setLatitude(conf.getLatitude()); + station.setLongitude(conf.getLongitude()); + + TextFieldCallsign.setText(station.getCallsign()); + TextFieldLatitude.setText(station.getLatitude()); + TextFieldLongitude.setText(station.getLongitude()); + + TextFieldSIDSEntrysat.setText(conf.getSIDSEntrySatSource()); + TextFieldSIDSSatnogs.setText(conf.getSIDSSatnogsSource()); + + + if (conf.isSIDS_EntrySat()) { + CheckbBoxAmicalSat.setSelected(true); + } + if (conf.isSISD_SatNogs()) { + CheckBoxSatNogs.setSelected(true); + } + + displayLog(conf.getSIDSSatnogsURL()); + displayLog(conf.getSIDSEntryUrl()); + displayLog("Initialisation with Properties File Done "); + + BufferedImage bufferedImage1 = null; + BufferedImage bufferedImage2 = null; + + try { + + + bufferedImage1 = ImageIO.read(getClass().getResource((imgAmsat))); + bufferedImage2 = ImageIO.read(getClass().getResource((imgAmicalsat))); + } catch (IOException e) { + + appLogger.severe("Error loading Image resources"); + appLogger.severe(e.toString()); + } + Image imageamsat = SwingFXUtils.toFXImage(bufferedImage1, null); + ImageViewAMSAT.setImage(imageamsat); + Image imgQB = SwingFXUtils.toFXImage(bufferedImage2, null); + imageViewEntrysat.setImage(imgQB); + + + ConfigHttp c = new ConfigHttp("http://site.amsat-f.org/download/117168/"); + String ver; + String message; + int NoradIdConf=conf.getNorad(); + if(c.isConnected()) + { + ver = c.GetProperty("AmicalsatVersion"); + message = c.GetProperty("Message"); + NoradIdConf= Integer.parseUnsignedInt(c.GetProperty("NoradID").trim()); + } + else + { + ver = version; + message = "not connected to internet"; + } + if (NoradIdConf!=conf.getNorad()) + { + conf.setNorad(NoradIdConf); + conf.save(); + displayLog("Norad ID updated "); + } + + manageStateMMI(STATE_INIT); + manageStatusinformation("Application Ready","Application initialised") ; + this.LabelInformation.setText(""); + + // initialise SIDS + + Station StationSatnogs = new Station(conf.getSIDSSatnogsSource(), station.getLongitude(), + station.getLatitude()); + Station StationEntry = new Station(conf.getSIDSEntrySatSource(), station.getLongitude(), station.getLatitude()); + + if (conf.isSISD_SatNogs() == true) { + SendSIDSSatnogs = new SendSIDS(StationSatnogs, conf.getNorad(), conf.getSIDSSatnogsURL()); + } + + if (conf.isSIDS_EntrySat() == true) { + SendSIDSEntrysat = new SendSIDS(StationEntry, conf.getNorad(), conf.getSIDSEntryUrl()); + } + + String erreurmsg = message; + + if (ver.equals(version) == false) { + erreurmsg += " New version " + ver + " available ! "; + + } + this.LabelInformation.setText(erreurmsg); + + } + + public void setPrimaryStage(Stage primaryStage) { + this.primaryStage = primaryStage; + + } + + + /** + * Save telemetry data received in text file. The file is stored in data folder. + */ + public void saveDataFile() { + SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd-HHmmss"); + Date aujourdhui = new Date(); + + // + + String path = System.getProperty("user.dir") + "/data"; + File apath = new File(path); + + if (!apath.exists()) { + if (apath.mkdir() == false) { + appLogger.severe("fail to create " + path); + } + } + + PrintWriter pw = null; + + long NbFrame = receivedFrame.getNumberFrame(); + + try { + pw = new PrintWriter(new FileWriter(path + "/" + formater.format(aujourdhui) + "-tlm-Hexa.txt")); + for (int i = 0; i < NbFrame; i++) { + // pw.write(receivedFrame.getFrame(i)); + pw.write(LINE_SEPARATOR); + } + + pw.flush(); + pw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + private void updateFrame(long nbframe) { + LabelFrame.setText("frame : " + nbframe); + + } + + + private void displayLog(String log) { + + logfile.displayLog(log); + TexAreaLog.appendText(log); + TexAreaLog.appendText("\r\n"); + } + + + + private void manageStateMMI(int state) + { + switch (state) { + case STATE_INIT : + ButtonStop.setDisable(true); + ButtonStart.setDisable(false); + ButtonSave.setDisable(true); + break; + case STATE_START : + ButtonStop.setDisable(false); + ButtonStart.setDisable(true); + ButtonSave.setDisable(false); + break; + case STATE_STOP : + ButtonStop.setDisable(true); + ButtonStart.setDisable(false); + ButtonSave.setDisable(false); + break; + case STATE_SAVE : + ButtonStop.setDisable(true); + ButtonStart.setDisable(false); + ButtonSave.setDisable(true); + break; + + + } + } + + private void manageStatusinformation(String statusMessage, String logMessage) { + labelStatus.setText(statusMessage); + displayLog(logMessage); + + } + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ModelReceivedData.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ModelReceivedData.java new file mode 100644 index 00000000..79ee3717 --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ModelReceivedData.java @@ -0,0 +1,87 @@ +package org.josast.ApplicationAmicalsat; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.Date; +import java.util.Vector; + +import org.josast.amicalsat.FactoryConsumer; +import org.josast.amicalsat.Frame; + + + + +public class ModelReceivedData { + + long numberFrame = 0; + Vector vecRawData = new Vector(); + Vector vecDecodedData= new Vector(); + FactoryConsumer ff = new FactoryConsumer(); + + + private PropertyChangeSupport listenerList = new PropertyChangeSupport(this); + + public void addPropertyChangeListener(PropertyChangeListener listener) { + listenerList.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + listenerList.removePropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + listenerList.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + listenerList.removePropertyChangeListener(propertyName, listener); + } + + public long getNumberFrame() { + return numberFrame; + } + + public ReceivedData getLastReceivedData() { + return vecRawData.lastElement(); + } + + public Frame getLastDecodedData() { + return vecDecodedData.lastElement(); + } + + + + @Deprecated + public void addFrame(int size, byte[] data) { +// long oldNumberFrame = numberFrame; +// numberFrame++; +// try { +// // try to decode +// FrameTlmEntrySat frame = new FrameTlmEntrySat(new ByteBufferKaitaiStream (cbuf) ); +// Ax25Frame ax = frame.frameTlmEntrySat(); +// // System.out.println(ax.ax25Header().srcCallsignRaw().srcCallsignRor().srcCallsign()); +// vect.addElement(frame); +// EntryFrame EntryFrame = new EntryFrame(new Date(), new KissData(cbuf, nb)); +// vecKiss.addElement(EntryFrame); +// +// +// } catch (Exception e) +// { +// e.printStackTrace(); +// } + + } + + public void addFrame(byte[] received) { + long oldNumberFrame = numberFrame; + numberFrame++; + vecRawData.add(new ReceivedData(new Date(),received)); + Frame framereceived = ff.getFrame(received); + vecDecodedData.add(framereceived); + listenerList.firePropertyChange("numberFrame", oldNumberFrame, numberFrame); + + } + + + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ReceivedData.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ReceivedData.java new file mode 100644 index 00000000..c7b81fc9 --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/ReceivedData.java @@ -0,0 +1,32 @@ +package org.josast.ApplicationAmicalsat; + +import java.util.Date; + + +public class ReceivedData { + + private Date time; + private byte [] data; + + public ReceivedData(Date receivedTime, byte [] receivedData) { + super(); + time = receivedTime; + data = receivedData ; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } + + + @Override + public String toString() { + return "Frame [time=" + time + "][ Frame=" + new String(data) + "]"; + } + + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/SendSIDS.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/SendSIDS.java new file mode 100644 index 00000000..e1726406 --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/SendSIDS.java @@ -0,0 +1,37 @@ +package org.josast.ApplicationAmicalsat; + +import org.josast.SIDS.HttpPostSIDS; +import org.josast.SIDS.SIDSData; +import org.josast.SIDS.Station; + +/** + * + * @author christophe + * + */ +public class SendSIDS { + + SIDSData sids = new SIDSData(); + HttpPostSIDS client; + + public SendSIDS ( Station station, int norad, String url) + { + sids.setStation(station); + sids.setNoradID(norad); + client = new HttpPostSIDS(url); + + + } + + public int Send(ReceivedData data) + { + //BasicConfigurator.configure(); + +// sids.setTelemetryData(data.getTime(),data.getFrame().toString()); + System.out.println(sids.toStringBasic()); + int result = client.SendSIDSBasic(sids); + return result; + + } + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/TaskSoundmodemTCP.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/TaskSoundmodemTCP.java new file mode 100644 index 00000000..66af40fb --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/TaskSoundmodemTCP.java @@ -0,0 +1,83 @@ +package org.josast.ApplicationAmicalsat; + +import java.util.logging.Logger; + + +import org.josast.ModuleSoundModem.SoundModemClient; +import org.josast.ModuleSoundModem.SoundModemConfiguration; + +import javafx.concurrent.Task; + +public class TaskSoundmodemTCP extends Task { + + private Logger log = Logger.getLogger("AmicalSatLogger"); + + private volatile boolean running = true; + + SoundModemConfiguration smConfiguration = null; + SoundModemClient smc = null; + ModelReceivedData receivedFrame = null; + + /** + * @param smConfiguration fichier de configuration + * @param receivedFrame Frame Data model + */ + public TaskSoundmodemTCP(SoundModemConfiguration smConfiguration, ModelReceivedData receivedFrame) { + this.smConfiguration = smConfiguration; + smc = new SoundModemClient(smConfiguration); + if (smc.isOpen() == false) { + this.failed(); + } + this.receivedFrame = receivedFrame; + + } + + public TaskSoundmodemTCP(ModelReceivedData receivedFrame) { + + smConfiguration = new SoundModemConfiguration("default"); + smc = new SoundModemClient(smConfiguration); + if (smc.isOpen() == false) { + this.failed(); + } + this.receivedFrame = receivedFrame; + } + + /** + * while the connection is open, the modem is listening. When a frame is received, + * this frame is added to the model + */ + @Override + protected String call() { + try { + + while (running == true) { + byte[] temp = smc.receivedRawData(); + receivedFrame.addFrame(temp); + this.updateValue(receivedFrame.toString()); + + } + } catch (Exception e) { + log.severe("Erreur SoundModem not available"); + log.severe(e.toString()); + this.failed(); + + } + return receivedFrame.toString(); + } + + + + public void arreter() { + + this.running = false; + + } + + public void redemarrer() + { + + this.running = true; + + } + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/util/LogFile.java b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/util/LogFile.java new file mode 100644 index 00000000..d3ae5b5d --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/ApplicationAmicalsat/util/LogFile.java @@ -0,0 +1,65 @@ +/** + * + */ +package org.josast.ApplicationAmicalsat.util; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Logger; + +/** + * @author christophe + * + */ +public class LogFile { + + private Logger appLogger = Logger.getLogger("AmicalSatLogger"); + private PrintWriter pw; + + /** + * + */ + public LogFile() { + // TODO Auto-generated constructor stub + initdisplayLogFile(); + } + + + private void initdisplayLogFile() + { + + + SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd-HHmmss"); + Date aujourdhui = new Date(); + String path = System.getProperty("user.dir") + "/log"; + File apath = new File(path); + + if (!apath.exists()) { + if (apath.mkdir() == false) { + appLogger.severe("fail to create " + path); + } + } + try { + pw = new PrintWriter (new FileWriter(path+"/"+formater.format(aujourdhui)+"-"+".log")); + } catch (IOException e) { + appLogger.severe("erreur creating log file"); + appLogger.severe (e.toString()); + } + } + + public void displayLog(String log) { + if(pw!=null) + { + pw.println(log); + pw.flush(); + } + appLogger.info(log); + + } + + +} diff --git a/ApplicationAmicalsat/src/main/java/org/josast/javafx/AlertHelper.java b/ApplicationAmicalsat/src/main/java/org/josast/javafx/AlertHelper.java new file mode 100644 index 00000000..7f3d20ee --- /dev/null +++ b/ApplicationAmicalsat/src/main/java/org/josast/javafx/AlertHelper.java @@ -0,0 +1,28 @@ +package org.josast.javafx; + +import javafx.scene.control.Alert; +import javafx.stage.Window; + +public class AlertHelper { + + private AlertHelper() + { + + } + /** + * Display a window in order to display a message + * @param alertType Type of alert + * @param owner + * @param title title of the windows + * @param message message to display + */ + public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) { + Alert alert = new Alert(alertType); + alert.setTitle(title); + alert.setHeaderText(null); + alert.setContentText(message); + alert.initOwner(owner); + alert.show(); + } + +} diff --git a/ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/AmicalSatMessage.txt b/ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/AmicalSatMessage.txt new file mode 100644 index 00000000..536b6e2c --- /dev/null +++ b/ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/AmicalSatMessage.txt @@ -0,0 +1,3 @@ +AmicalsatVersion=0.1 +Message= version de test +NoradID=0 \ No newline at end of file diff --git a/ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/Amicalsat.fxml b/ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/Amicalsat.fxml new file mode 100644 index 00000000..2d24f260 --- /dev/null +++ b/ApplicationAmicalsat/src/main/resources/org/josast/ApplicationAmicalsat/Amicalsat.fxml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +