Skip to content
Commits on Source (2)
...@@ -16,145 +16,144 @@ import org.exolab.castor.xml.Unmarshaller; ...@@ -16,145 +16,144 @@ import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException; import org.exolab.castor.xml.ValidationException;
/** /**
* *
* <b>Description : This class allows to load and save data on a XML file. The castor API is used for the data binding. * <b>Description : This class allows to load and sav data on a XML file. The
* The default name for the file is the name of the class with ".xml" for the extension</b> * castor API is used for the data binding. The default name for the file is the
* name of the class with ".xml" for the extension</b> <br>
* need a specific library : org.exolab.castor.xml <br>
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox <br>
* The aim of the project is to create a set of tools for amateur satellite
* purpose. All this tools could be used together to create specific software.
* <br> * <b>JOSAST</b> project is managed by AVMDTI
* need a specific library : org.exolab.castor.xml * (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) <br>
* <br> * This software is an open source software. Please read the <b><i>JOSAST
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox * licence</b></i><BR>
* <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software. * (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <p>for more information contact <a href="mailto:josast@avmdti.org">josast@avmdti.org</a></p>
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0
* <p><b><i> Source Update </b></i></p>
* <br> Version : date : name : comments
* <br> V1 : 3 mars 2004 : C. Mercier : create file
* <br> V2 : 01 mai 2019 : C. Mercier : Change log system
* <p> * <p>
* for more information contact
* <a href="mailto:josast@avmdti.org">josast@avmdti.org</a>
* </p>
*
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0
* <p>
* <b><i> Source Update </b></i>
* </p>
* <br>
* Version : date : name : comments <br>
* V1 : 3 mars 2004 : C. Mercier : create file <br>
* V2 : 01 mai 2019 : C. Mercier : Change log system
* <p>
*/ */
public abstract class AbstractDataBinding implements Serializable { public abstract class AbstractDataBinding implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 8410353753997330889L; private static final long serialVersionUID = 8410353753997330889L;
transient private String folder =".\\"; private transient String folder = ".\\";
private Logger log = Logger.getLogger("AmsatLogger"); private Logger log = Logger.getLogger("AmsatLogger");
/** /**
* This method read data from the file. The method return an object. * This method read data from the file. The method return an object.
* *
* @return object. * @return object.
*/ */
public Object load() { public Object load() {
String fileName = folder + "\\"+ this.getClass().getName() + ".xml"; String fileName = folder + "\\" + this.getClass().getName() + ".xml";
Object o = null; Object o = null;
Reader reader = null; Reader reader = null;
File f = new File(fileName); File f = new File(fileName);
if (f.exists() ) if (f.exists()) {
{ try {
try { reader = new FileReader(fileName);
reader = new FileReader(fileName); } catch (FileNotFoundException e) {
} catch (FileNotFoundException e) { e.printStackTrace();
e.printStackTrace(); }
} try {
try { o = Unmarshaller.unmarshal(this.getClass(), reader);
o = Unmarshaller.unmarshal(this.getClass(), reader); } catch (MarshalException e) {
} catch (MarshalException e) { e.printStackTrace();
e.printStackTrace(); } catch (ValidationException e1) {
} catch (ValidationException e1) { e1.printStackTrace();
e1.printStackTrace(); }
} try {
try { reader.close();
reader.close(); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace();
}
} } else {
} log.warning("file not found");
else }
{
log.warning("file not found"); return o;
} }
return o; /**
} * This method save all parameters of the class in an XML file.
*/
public void save() {
/** String fileName = folder + "\\" + this.getClass().getName() + ".xml";
* This method save all parameters of the class in an XML file. File file = new File(fileName);
*/ Writer writer = null;
public void save() { try {
String fileName = folder + "\\"+ this.getClass().getName() + ".xml"; writer = new FileWriter(file);
File file = new File(fileName); } catch (IOException e) {
Writer writer = null; e.printStackTrace();
try { }
writer = new FileWriter(file); try {
} catch (IOException e) { Marshaller.marshal(this, writer);
e.printStackTrace(); } catch (MarshalException | ValidationException e) {
}
try { e.printStackTrace();
Marshaller.marshal(this, writer); }
} catch (MarshalException|ValidationException e) { try {
writer.close();
e.printStackTrace(); } catch (IOException e) {
} e.printStackTrace();
try { }
writer.close(); log.info("file : " + file.getAbsoluteFile());
} catch (IOException e) {
e.printStackTrace(); }
}
log.info("file : " + file.getAbsoluteFile()); /**
* This method returns true if a configuration file already exist.
} * @return true if the configuration file exist.
*/
/** public boolean isExist() {
* This method returns true if a configuration file already exist. String FileName = folder + "\\" + this.getClass().getName() + ".xml";
* File f = new File(FileName);
* @return true if the configuration file exist. return f.exists();
*/ }
public boolean isExist() {
String FileName = folder + "\\"+this.getClass().getName() + ".xml"; /**
File f = new File(FileName); * return the folder where the configuration file is read or save
return f.exists(); *
} * @return
*/
public String getFolder() {
/** return folder;
* return the folder where the configuration file is read or save }
* @return
*/ /**
public String getFolder() { * set the folder where the configuration file is read or save. If the
return folder; * folder do not exist, the folder is created.
} *
* @param folder
* @return true if the folder exist else folder is not accessible
/** */
* set the folder where the configuration file is read or save. public boolean setFolder(final String folder) {
* If the folder do not exist, the folder is created. this.folder = folder;
* @param folder File f = new File(folder);
* @return true if the folder exist else folder is not accessible boolean value = true;
*/ if (!f.exists()) {
public boolean setFolder(String folder) { value = f.mkdir();
this.folder = folder; }
File f = new File(folder); return value;
boolean value=true; }
if (!f.exists())
{
value = f.mkdir();
}
return value;
}
} }
/** /**
* *
* <b>Description : used for demonstration to the config package. * <b>Description : used for demonstration to the config package.
* see main to understand how to used the AbstactDataBinding. </b> * see main to understand how to used the AbstactDataBinding. </b>
* <br> * <br>
*
*
* <p>Projet : JOSAST <BR> * <p>Projet : JOSAST <BR>
*
* <br> * <br>
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox * <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox
* <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software. * <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software.
* <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
...@@ -16,7 +13,7 @@ ...@@ -16,7 +13,7 @@
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a> * @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0 * @version 1.0
* <p><b><i> Source Update </b></i></p> * <p><b><i> Source Update </b></i></p>
* <br> Version : date : name : comments * <br> Version : date : name : comments
* <br> V1 : 3 mars 2004 : C. Mercier : create file * <br> V1 : 3 mars 2004 : C. Mercier : create file
* <p> * <p>
*/ */
...@@ -26,14 +23,12 @@ import java.io.File; ...@@ -26,14 +23,12 @@ import java.io.File;
import java.util.Vector; import java.util.Vector;
/** /**
* *
* <b>Description : </b> * <b>Description : </b>
* * <p>Projet : JOSAST <br>
* *
* <p>Projet : JOSAST <BR>
*
* <br> * <br>
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox * <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox
* <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software. * <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software.
* <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
...@@ -41,7 +36,7 @@ import java.util.Vector; ...@@ -41,7 +36,7 @@ import java.util.Vector;
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a> * @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0 * @version 1.0
* <p><b><i> Source Update </b></i></p> * <p><b><i> Source Update </b></i></p>
* <br> Version : date : name : comments * <br> Version : date : name : comments
* <br> V1 : 3 mars 2004 : C. Mercier : create file * <br> V1 : 3 mars 2004 : C. Mercier : create file
* <br> V2 : 01 mai 2019 : C. Mercier : Change log system * <br> V2 : 01 mai 2019 : C. Mercier : Change log system
* <p> * <p>
...@@ -55,53 +50,43 @@ public class ConfigurationdataBindingDemo extends AbstractDataBinding { ...@@ -55,53 +50,43 @@ public class ConfigurationdataBindingDemo extends AbstractDataBinding {
private String name = null; private String name = null;
private Vector<String> V = new Vector<String>(); private Vector<String> V = new Vector<String>();
private String directory = new String("C:\\temp"); private String directory = new String("C:\\temp");
private ConfigurationdataBindingDemo() {
private ConfigurationdataBindingDemo()
{
} }
/** /**
* This method return an instance of the class. * This method return an instance of the class.
* If the configuration file exist, the function return an object from the configuration file * If the configuration file exist, the function return an object from the configuration file
* else the function return a default object. * else the function return a default object.
* @return an instance of the class. * @return an instance of the class.
*/ */
public static ConfigurationdataBindingDemo getInstance() public static ConfigurationdataBindingDemo getInstance() {
{
// create a default object // create a default object
ConfigurationdataBindingDemo t = new ConfigurationdataBindingDemo(); ConfigurationdataBindingDemo t = new ConfigurationdataBindingDemo();
// test if the file exist // test if the file exist
// TODO : A REVOIR // TODO : A REVOIR
File f = new File(t.getDirectory()); File f = new File(t.getDirectory());
if (!f.exists()) if (!f.exists()) {
{
f.mkdir(); f.mkdir();
} }
t.setFolder(t.getDirectory()); t.setFolder(t.getDirectory());
if (t.isExist()) if (t.isExist()) {
{
// load the object // load the object
t = (ConfigurationdataBindingDemo) t.load(); t = (ConfigurationdataBindingDemo) t.load();
} }
// return the object // return the object
return t; return t;
} }
/**
/**
* display Vector data and also name of the class and version. <br> * display Vector data and also name of the class and version. <br>
*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
public String toString() public String toString() {
{ return this.V.toString() + name + version;
return this.V.toString()+name+version;
} }
/** /**
* @return field name. * @return field name.
*/ */
...@@ -125,35 +110,33 @@ public static ConfigurationdataBindingDemo getInstance() ...@@ -125,35 +110,33 @@ public static ConfigurationdataBindingDemo getInstance()
/** /**
* set field name. * set field name.
* * @param string
* @param string
*/ */
public void setName(String string) { public void setName(final String string) {
name = string; name = string;
} }
/** /**
* set a vector * set a vector
* *
* @param vector * @param vector
*/ */
public void setV(Vector<String> vector) { public void setV(final Vector<String> vector) {
V = vector; V = vector;
} }
/** /**
* set version. * set version.
* *
* @param d * @param d
*/ */
public void setVersion(double d) { public void setVersion(final double d) {
version = d; version = d;
} }
public void setDirectory(String directory) {
public void setDirectory(final String directory) {
this.directory = directory; this.directory = directory;
} }
...@@ -161,35 +144,31 @@ public static ConfigurationdataBindingDemo getInstance() ...@@ -161,35 +144,31 @@ public static ConfigurationdataBindingDemo getInstance()
public String getDirectory() { public String getDirectory() {
return directory; return directory;
} }
/** /**
* D�monstration : * D�monstration :
* - cr�ation d'un objet * - cr�ation d'un objet
* - modification des param�tres de l'objet * - modification des param�tres de l'objet
* - sauvegarde * - sauvegarde
* - lecture * - lecture
* * @param messages non utilis�
*
* @param Strings non utilis�
*/ */
public static void main(String[] Strings) public static void main(String[] arg) {
{
Vector<String> v = new Vector<String>(); Vector<String> v = new Vector<String>();
v.add("�lement 1"); v.add("�lement 1");
v.add("�l�ment 2"); v.add("�l�ment 2");
v.add("�l�ment 3"); v.add("�l�ment 3");
ConfigurationdataBindingDemo t = getInstance(); ConfigurationdataBindingDemo t = getInstance();
System.out.println("First Load" + t);
System.out.println("First Load"+t);
t.setName("d�monstration du fichier"); t.setName("d�monstration du fichier");
t.setVersion(1.3); t.setVersion(1.3);
t.setV(v); t.setV(v);
System.out.println("avant sauvegarde"+t); System.out.println("avant sauvegarde" + t);
t.save(); t.save();
t=new ConfigurationdataBindingDemo(); t = new ConfigurationdataBindingDemo();
System.out.println("a la cr�ation"+t); System.out.println("a la cr�ation" + t);
t = (ConfigurationdataBindingDemo)t.load(); t = (ConfigurationdataBindingDemo) t.load();
System.out.println("apr�s sauvegarde"+t); System.out.println("apr�s sauvegarde" + t);
} }
......
...@@ -8,169 +8,161 @@ import java.io.IOException; ...@@ -8,169 +8,161 @@ import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* *
* <b>Description : This class allows to save data in a configuration file.</b> * <b>Description : This class allows to save data in a configuration file.</b>
* <br> * <br>
* for the JOSAST project the org.josast.config.databinding is prefered to this package for storing data. * for the JOSAST project the org.josast.config.databinding is prefered to this
* * package for storing data.
* *
* <p>Projet : JOSAST <BR> * <p>
* * Projet : JOSAST <BR>
*
* <br> * <br>
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox * <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox <br>
* <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software. * The aim of the project is to create a set of tools for amateur satellite
* <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * purpose. All this tools could be used together to create specific software.
* <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <b>JOSAST</b> project is managed by AVMDTI
* <p>for more information contact <a href="mailto:josast@avmdti.org">josast@avmdti.org</a></p> * (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) <br>
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a> * This software is an open source software. Please read the <b><i>JOSAST
* @version 1.0 * licence</b></i><BR>
* <p><b><i> Source Update </b></i></p> * (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <br> Version : date : name : comments
* <br> V1 : 3 mars 2004 : C. Mercier : create file
* <br> V2 : 01 mai 2019 : C. Mercier : Change log system
* <p> * <p>
* for more information contact
* <a href="mailto:josast@avmdti.org">josast@avmdti.org</a>
* </p>
*
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0
* <p>
* <b><i> Source Update </b></i>
* </p>
* <br>
* Version : date : name : comments <br>
* V1 : 3 mars 2004 : C. Mercier : create file <br>
* V2 : 01 mai 2019 : C. Mercier : Change log system
* <p>
*/ */
public class CONFIG { public class CONFIG {
private static Logger log = Logger.getLogger("AmsatLogger"); private static Logger log = Logger.getLogger("AmsatLogger");
private Properties P = null; private Properties P = null;
private String fileName = "configuration.ini"; private String fileName = "configuration.ini";
/** Constructeur priv� */ /** Constructeur priv� */
private CONFIG() private CONFIG() {
{} }
private String getName() {
private String getName() String path = System.getProperty("user.dir") + "/config";
{ File apath = new File(path);
String path = System.getProperty("user.dir")+"/config";
File apath = new File(path); if (!apath.exists()) {
boolean res = apath.mkdir();
if (!apath.exists()) if (!res) {
{ log.severe("fail to create " + path);
boolean res = apath.mkdir();
if (!res) }
{ }
log.severe("fail to create "+ path); return path + "/" + fileName;
}
}
}
return path+"/"+fileName;
}
/** Holder */ /** Holder */
private static class SingletonHolder private static class SingletonHolder {
{
/** Instance unique non pr�initialis�e */ /** Instance unique non pr�initialis�e */
private final static CONFIG instance = new CONFIG(); private static final CONFIG instance = new CONFIG();
} }
/** Point d'acc�s pour l'instance unique du singleton */ /** Point d'acc�s pour l'instance unique du singleton */
public static CONFIG getInstance() public static CONFIG getInstance() {
{
return SingletonHolder.instance; return SingletonHolder.instance;
} }
public String GetProperty(final String Item) {
public String GetProperty(String Item) { if (P == null) {
try {
if (P==null) P = new Properties();
{ FileInputStream in = new FileInputStream(getName());
try { P.load(in);
P = new Properties(); in.close();
FileInputStream in = new FileInputStream(getName()); } catch (Exception e) {
P.load(in); log.severe("erreur ouverture fichier de configuration"); //$NON-NLS-1$
in.close(); return null;
} catch (Exception e) { }
log.severe ("erreur ouverture fichier de configuration"); //$NON-NLS-1$ }
return null; String S = P.getProperty(Item);
} if (S == null) {
} return null;
String S = P.getProperty(Item); } else {
if (S == null) return S.trim(); // $NON-NLS-1$
{ }
return null; }
}
else /**
{ * Set a property into the file
return S.trim(); //$NON-NLS-1$ *
} *
} * @param Item Item to store
* @param Valeur value to store
/** *
* Set a property into the file */
* public void SetProperty(final String Item, final String Valeur) {
*
* @param Item Item to store if (P == null) {
* @param Valeur value to store
* P = new Properties();
*/ try {
public void SetProperty(String Item, String Valeur) {
FileInputStream in = new FileInputStream(getName());
if (P==null) P.load(in);
{ in.close();
} catch (Exception e2) {
log.severe("Erreur de ouverture du fichier de configuration"); //$NON-NLS-1$
P = new Properties(); e2.printStackTrace();
try { }
}
FileInputStream in = new FileInputStream(getName()); P.put(Item, Valeur); // $NON-NLS-1$
P.load(in);
in.close(); FileOutputStream out = null;
} try {
catch (Exception e2) { out = new FileOutputStream(getName());
log.severe ("Erreur de ouverture du fichier de configuration"); //$NON-NLS-1$ } catch (FileNotFoundException e) {
e2.printStackTrace(); log.severe("erreur cr�ation de fichier");
} e.printStackTrace();
} }
try {
P.put(Item, Valeur); //$NON-NLS-1$ P.store(out, null);
} catch (IOException e1) {
FileOutputStream out=null; log.severe("erreur sauvegarde");
try { e1.printStackTrace();
out = new FileOutputStream(getName()); }
} catch (FileNotFoundException e) { try {
log.severe ("erreur cr�ation de fichier"); out.close();
e.printStackTrace(); } catch (IOException e3) {
} log.severe("erreur de fermeture");
try { e3.printStackTrace();
P.store(out, null); }
} catch (IOException e1) {
log.severe ("erreur sauvegarde"); }
e1.printStackTrace();
} /**
try { * Returns the nomFichier.
out.close(); *
} catch (IOException e3) { * @return String
log.severe ("erreur de fermeture"); */
e3.printStackTrace(); public String getFileName() {
} return fileName;
}
}
/**
/** * Sets the nomFichier.
* Returns the nomFichier. *
* @return String * @param nomfichier The nomFichier to set
*/ */
public String getFileName() { public void setFileName(final String nomfichier) {
return fileName; fileName = nomfichier;
} }
/**
* Sets the nomFichier.
* @param fileName The nomFichier to set
*/
public void setFileName(String nomfichier) {
fileName = nomfichier;
}
} }
/** /**
* *
*/ */
package org.josast.property; package org.josast.property;
...@@ -11,41 +11,35 @@ import java.util.logging.Logger; ...@@ -11,41 +11,35 @@ import java.util.logging.Logger;
* *
*/ */
public abstract class ConfigObject { public abstract class ConfigObject {
private Logger log = Logger.getLogger("AmsatLogger"); private Logger log = Logger.getLogger("AmsatLogger");
private String ConfigFilename=null; private String ConfigFilename = null;
private String fullConfigFilename=null; private String fullConfigFilename = null;
protected CONFIG ConfigFile = CONFIG.getInstance(); protected CONFIG ConfigFile = CONFIG.getInstance();
public ConfigObject () public ConfigObject() {
{
} }
public String getFulFileName() public String getFulFileName() {
{ fullConfigFilename = System.getProperty("user.dir") + "/config";
fullConfigFilename = System.getProperty("user.dir")+"/config";
File apath = new File(fullConfigFilename); File apath = new File(fullConfigFilename);
if (!apath.exists()) if (!apath.exists()) {
{
boolean res = apath.mkdir(); boolean res = apath.mkdir();
if (!res) if (!res) {
{ log.severe("fail to create " + fullConfigFilename);
log.severe("fail to create "+ fullConfigFilename);
} }
} }
return fullConfigFilename; return fullConfigFilename;
} }
/** /**
* @param configFilename Configuration file name * @param configFilename Configuration file name
*/ */
public ConfigObject(String configFilename) { public ConfigObject(final String configFilename) {
super(); super();
ConfigFilename = configFilename; ConfigFilename = configFilename;
ConfigFile.setFileName(configFilename); ConfigFile.setFileName(configFilename);
...@@ -59,8 +53,5 @@ public abstract class ConfigObject { ...@@ -59,8 +53,5 @@ public abstract class ConfigObject {
public String getConfigFilename() { public String getConfigFilename() {
return ConfigFilename; return ConfigFilename;
} }
} }
...@@ -15,95 +15,89 @@ import org.apache.http.impl.client.HttpClientBuilder; ...@@ -15,95 +15,89 @@ import org.apache.http.impl.client.HttpClientBuilder;
/** /**
* @author christophe * @author christophe
* *
* This class read a properties file from an URL. * This class read a properties file from an URL.
* *
* *
*/ */
public class ConfigHttp { public class ConfigHttp {
private static Logger log = Logger.getLogger("AmsatLogger"); private static Logger log = Logger.getLogger("AmsatLogger");
private String url = ""; private String url = "";
private Properties props = new Properties(); private Properties props = new Properties();
private boolean connected = false; private boolean connected = false;
/** /**
* @param url URL of the properties file to read * @param url URL of the properties file to read
*/ */
public ConfigHttp(String url) { public ConfigHttp(final String url) {
super(); super();
this.url = url; this.url = url;
try { try {
loadProperties(); loadProperties();
} catch (Exception e) } catch (Exception e) {
{ log.severe(e.getMessage());
log.severe(e.getMessage()); }
} }
}
/**
/** * Load the properties file and initialise Properties field
* Load the properties file and initialise Properties field */
*/ private void loadProperties() {
private void loadProperties() {
final String USER_AGENT = "Mozilla/5.0";
final String USER_AGENT = "Mozilla/5.0";
HttpClient client = HttpClientBuilder.create().build();
HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(url);
HttpGet request = new HttpGet(url); request.addHeader("User-Agent", USER_AGENT);
request.addHeader("User-Agent", USER_AGENT); HttpResponse response;
HttpResponse response; try {
try { response = client.execute(request);
response = client.execute(request);
BufferedReader rd = new BufferedReader(
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); new InputStreamReader(response.getEntity().getContent()));
props.load(rd); props.load(rd);
connected = true; connected = true;
} catch (ClientProtocolException e) { } catch (ClientProtocolException e) {
log.severe("Error read URL"); log.severe("Error read URL");
} catch (IOException e) { } catch (IOException e) {
log.severe("Error read URL "); log.severe("Error read URL ");
} }
} }
/** /**
* *
* @param Item property name * @param Item property name
* @return property value, null if property not found * @return property value, null if property not found
*/ */
public String GetProperty(String Item) { public String GetProperty(final String Item) {
if (props != null) { if (props != null) {
String S = props.getProperty(Item); String S = props.getProperty(Item);
if (S == null) if (S == null) {
{ return null;
return null; } else {
} return S.trim(); // $NON-NLS-1$
else }
{ }
return S.trim(); // $NON-NLS-1$ return null;
}
} }
return null;
/**
} * @return true if the Property file has been read
*/
/** public boolean isConnected() {
* @return true if the Property file has been read return connected;
*/ }
public boolean isConnected() {
return connected; public static void main(String[] args) {
} ConfigHttp c = new ConfigHttp(
"http://site.amsat-f.org/download/117168/");
System.out.println(c.GetProperty("EntrySatVersion"));
}
public static void main(String[] args) {
ConfigHttp c = new ConfigHttp("http://site.amsat-f.org/download/117168/");
System.out.println(c.GetProperty("EntrySatVersion"));
}
} }
/** /**
* *
* <b>Description : </b> * <b>Description : </b>
* *
* *
* <p>Projet : JOSAST <BR> * <p>Projet : JOSAST <BR>
* *
* <br> * <br>
* <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox * <b>JOSAST</b> : Java Open Source Amateur Satellite Toolbox
* <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software. * <br>The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software.
* <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
* <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) * <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a> * @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0 * @version 1.0
* <p><b><i> Source Update </b></i></p> * <p><b><i> Source Update </b></i></p>
* <br> Version : date : name : comments * <br> Version : date : name : comments
* <br> V1 : 3 mars 2004 : C. Mercier : create file * <br> V1 : 3 mars 2004 : C. Mercier : create file
* <p> * <p>
*/ */
...@@ -28,10 +28,9 @@ import org.josast.config.databinding.AbstractDataBinding; ...@@ -28,10 +28,9 @@ import org.josast.config.databinding.AbstractDataBinding;
public class test extends AbstractDataBinding { public class test extends AbstractDataBinding {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
int toto; private int toto;
Vector<String> V = new Vector<String>(); private Vector<String> V = new Vector<String>();
public test() public test() {
{
V.add("essai"); V.add("essai");
V.add("test"); V.add("test");
} }
...@@ -46,11 +45,10 @@ public class test extends AbstractDataBinding { ...@@ -46,11 +45,10 @@ public class test extends AbstractDataBinding {
/** /**
* @param i * @param i
*/ */
public void setToto(int i) { public void setToto(final int i) {
toto = i; toto = i;
} }
/** /**
* @return * @return
...@@ -62,18 +60,14 @@ public class test extends AbstractDataBinding { ...@@ -62,18 +60,14 @@ public class test extends AbstractDataBinding {
/** /**
* @param vector * @param vector
*/ */
public void setV(Vector<String> vector) { public void setV(final Vector<String> vector) {
V = vector; V = vector;
} }
public static void main(String[] strings) {
public static void main(String[] strings)
{
test t = new test(); test t = new test();
t.setFolder("D:\\temps2"); t.setFolder("D:\\temps2");
t.setToto(4); t.setToto(4);
t.save(); t.save();
} }
......
...@@ -32,127 +32,142 @@ import org.apache.http.ssl.TrustStrategy; ...@@ -32,127 +32,142 @@ import org.apache.http.ssl.TrustStrategy;
* *
*/ */
public class HttpPostSIDS { public class HttpPostSIDS {
private static Logger logger = Logger.getLogger("AmsatLogger"); private static Logger logger = Logger.getLogger("AmsatLogger");
private static String USER_AGENT = "Mozilla/5.0"; private static String USERAGENT = "Mozilla/5.0";
private CloseableHttpClient client = null; private CloseableHttpClient client = null;
private HttpPost post = null; private HttpPost post = null;
private StringBuffer result = null; private StringBuffer result = null;
/** /**
* Create a Http client for sending SIDS data. <br> * Create a Http client for sending SIDS data. <br>
* exemple of URL * exemple of URL
* <li>Satnogs https://db.satnogs.org/api/telemetry/ * <li>Satnogs https://db.satnogs.org/api/telemetry/
* *
* @param url Database http or https adress * @param url Database http or https adress
*/ */
public HttpPostSIDS(String url) { public HttpPostSIDS(final String url) {
client = getCloseableHttpClient(); client = getCloseableHttpClient();
post = new HttpPost(url); post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT); post.setHeader("User-Agent", USERAGENT);
} }
/** /**
* Create a Http client for sending SIDS data. <br> * Create a Http client for sending SIDS data. <br>
* *
* @param url * @param url
* @param token provided by satnogs if * @param token provided by satnogs if
*/ */
public HttpPostSIDS(String url, String token) { public HttpPostSIDS(final String url, final String token) {
client = getCloseableHttpClient(); client = getCloseableHttpClient();
post = new HttpPost(url); post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT); post.setHeader("User-Agent", USERAGENT);
addSatnogsToken(token); addSatnogsToken(token);
} }
public void addSatnogsToken(String token) { public void addSatnogsToken(final String token) {
post.addHeader("Authorization", "Token " + token); post.addHeader("Authorization", "Token " + token);
} }
private CloseableHttpClient getCloseableHttpClient() { private CloseableHttpClient getCloseableHttpClient() {
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
try { try {
httpClient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) httpClient = HttpClients.custom()
.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { .setSSLContext(new SSLContextBuilder()
return true; .loadTrustMaterial(null, new TrustStrategy() {
} public boolean isTrusted(
}).build()).build(); final X509Certificate[] arg0,
} catch (KeyManagementException e) { final String arg1)
logger.severe("KeyManagementException in creating http client instance " + e.toString()); throws CertificateException {
} catch (NoSuchAlgorithmException e) { return true;
logger.severe("NoSuchAlgorithmException in creating http client instance " + e.toString()); }
} catch (KeyStoreException e) { }).build())
logger.severe("KeyStoreException in creating http client instance " + e.toString()); .build();
} } catch (KeyManagementException e) {
return httpClient; logger.severe(
} "KeyManagementException in creating http client instance "
+ e.toString());
/** } catch (NoSuchAlgorithmException e) {
* @param sids logger.severe(
* @return "NoSuchAlgorithmException in creating http client instance "
*/ + e.toString());
public int SendSIDSBasic(SIDSData sids) { } catch (KeyStoreException e) {
// Data preparation logger.severe("KeyStoreException in creating http client instance "
int resultat = 0; + e.toString());
HttpResponse response = null; }
BufferedReader rd = null; return httpClient;
}
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("noradID", "" + sids.getNoradID())); /**
urlParameters.add(new BasicNameValuePair("source", sids.getSource())); * @param sids
urlParameters.add(new BasicNameValuePair("timestamp", sids.getTimestamp())); * @return
urlParameters.add(new BasicNameValuePair("frame", sids.getFrame())); */
urlParameters.add(new BasicNameValuePair("locator", sids.getLocator())); public int SendSIDSBasic(final SIDSData sids) {
urlParameters.add(new BasicNameValuePair("longitude", "" + sids.getLongitude())); // Data preparation
urlParameters.add(new BasicNameValuePair("latitude", "" + sids.getLatitude())); int resultat = 0;
urlParameters.add(new BasicNameValuePair("version", "2.0.2")); HttpResponse response = null;
BufferedReader rd = null;
try {
post.setEntity(new UrlEncodedFormEntity(urlParameters)); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
} catch (UnsupportedEncodingException e) { urlParameters
logger.severe("URL Encoding error" + e); .add(new BasicNameValuePair("noradID", "" + sids.getNoradID()));
urlParameters.add(new BasicNameValuePair("source", sids.getSource()));
} urlParameters
.add(new BasicNameValuePair("timestamp", sids.getTimestamp()));
try { urlParameters.add(new BasicNameValuePair("frame", sids.getFrame()));
response = client.execute(post); urlParameters.add(new BasicNameValuePair("locator", sids.getLocator()));
resultat = response.getStatusLine().getStatusCode(); urlParameters.add(
logger.info("URL Result " + resultat); new BasicNameValuePair("longitude", "" + sids.getLongitude()));
} catch (IOException e) { urlParameters.add(
logger.severe("Cient executon error" + e.toString()); new BasicNameValuePair("latitude", "" + sids.getLatitude()));
} urlParameters.add(new BasicNameValuePair("version", "2.0.2"));
if (response != null) try {
post.setEntity(new UrlEncodedFormEntity(urlParameters));
{ } catch (UnsupportedEncodingException e) {
logger.severe("URL Encoding error" + e);
try {
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); }
} catch (UnsupportedOperationException | IOException e) {
logger.severe("Buffer reader Exception " + e.toString()); try {
} response = client.execute(post);
resultat = response.getStatusLine().getStatusCode();
result = new StringBuffer(); logger.info("URL Result " + resultat);
String line = ""; } catch (IOException e) {
try { logger.severe("Cient executon error" + e.toString());
while ((line = rd.readLine()) != null) { }
result.append(line);
} if (response != null) {
} catch (IOException e) {
logger.severe("Error reading line from server " + e.toString()); try {
} rd = new BufferedReader(new InputStreamReader(
} response.getEntity().getContent()));
return resultat; } catch (UnsupportedOperationException | IOException e) {
logger.severe("Buffer reader Exception " + e.toString());
} }
public StringBuffer getResult() { result = new StringBuffer();
return result; String line = "";
} try {
while ((line = rd.readLine()) != null) {
result.append(line);
}
} catch (IOException e) {
logger.severe(
"Error reading line from server " + e.toString());
}
}
return resultat;
}
public StringBuffer getResult() {
return result;
}
} }
...@@ -4,208 +4,193 @@ import java.text.SimpleDateFormat; ...@@ -4,208 +4,193 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
/**
/** * SIDSdate is a simple class used to store SIDS data information
* SIDSdate is a simple class used to store SIDS data information *
*
* @author Xtophe * @author Xtophe
* *
*/ */
public class SIDSData { public class SIDSData {
final private SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
private final SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
private int noradID; // Norad ID of the spacecraft
private String source = ""; // Callsign or user name of the receiver
private String timestamp; // UTC timestamp (see ISO 8601)
// 2018-01-24T23:42:46Z
private String frame; // The received data, in hexadecimal string (AX.25
// packet with or without KISS 'C0 00 .. C0'.
// Whitespaces optional. C0 00 A9 05 DE ...
private final String locator = "longLat"; // Type of the given receiver's
// location. Currently, only
// 'longLat' is supported. longLat
private String longitude = null; // Longitude of the receiver (WGS84)
// 8.95564E
private String latitude = null; // Latitude of the receiver (WGS84)
// 49.73145N
private int tncPort = 0; // Optional as per SiDS standard specification, but
// not used in PicSat SiDS system 0
private double azimuth = 0.0; // azimuth degree of directionnal antenna (if
// avaiblable) 10.5
private double elevation = 0.0; // elevation degree of directionnal antenna
private int noradID; // Norad ID of the spacecraft // (if avaiblable) 85.0
private String source=""; // Callsign or user name of the receiver private long fDown = 0; // Frequency of the receiver's downlink channel
// during reception (with Doppler), in Hz 435525000
private String timestamp; // UTC timestamp (see ISO 8601) 2018-01-24T23:42:46Z private final String version = "2.0.1";
private String frame; // The received data, in hexadecimal string (AX.25 packet with or without KISS 'C0 00 .. C0'. Whitespaces optional. C0 00 A9 05 DE ... public SIDSData() {
final private String locator = "longLat"; //Type of the given receiver's location. Currently, only 'longLat' is supported. longLat }
private String longitude=null; // Longitude of the receiver (WGS84) 8.95564E /**
* addTelemetryData is used for adding telemetry data with associated
* TimeStamp. The timestamp is formated in correct date format.
*
* @param date Date in local time
* @param inputframe telemetry data
*/
public void setTelemetryData(final Date date, final String inputframe) {
private String latitude=null; //Latitude of the receiver (WGS84) 49.73145N ISO8601DATEFORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
timestamp = ISO8601DATEFORMAT.format(date);
frame = inputframe;
private int tncPort = 0; // Optional as per SiDS standard specification, but not used in PicSat SiDS system 0 }
private double azimuth = 0.0; // azimuth degree of directionnal antenna (if avaiblable) 10.5 public String getLongitude() {
return longitude;
}
private double elevation= 0.0; // elevation degree of directionnal antenna (if avaiblable) 85.0 public void setLongitude(final String longitude) {
this.longitude = longitude;
}
private long fDown = 0; // Frequency of the receiver's downlink channel during reception (with Doppler), in Hz 435525000 public String getLatitude() {
return latitude;
}
final private String version = "2.0.1"; public void setLatitude(final String latitudein) {
this.latitude = latitudein;
}
public int getNoradID() {
return noradID;
}
public void setNoradID(final int noradID) {
this.noradID = noradID;
}
public String getSource() {
return source;
}
public SIDSData ( ) public void setSource(final String source) {
this.source = source;
}
{ public String getTimestamp() {
return timestamp;
}
} public void setTimestamp(final String timestamp) {
this.timestamp = timestamp;
}
public String getFrame() {
/** return frame;
* addTelemetryData is used for adding telemetry data with associated TimeStamp. }
* The timestamp is formated in correct date format.
*
* @param date Date in local time
* @param inputframe telemetry data
*/
public void setTelemetryData ( Date date, String inputframe)
{ public void setFrame(final String frame) {
this.frame = frame;
ISO8601DATEFORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); }
timestamp = ISO8601DATEFORMAT.format(date);
frame=inputframe;
}
public String getLongitude() { public int getTncPort() {
return longitude; return tncPort;
} }
public void setLongitude(String longitude) { public void setTncPort(final int tncPort) {
this.longitude = longitude; this.tncPort = tncPort;
} }
public String getLatitude() { public double getAzimuth() {
return latitude; return azimuth;
} }
public void setLatitude(String latitude) { public void setAzimuth(final double azimuth) {
this.latitude = latitude; this.azimuth = azimuth;
} }
public int getNoradID() { public double getElevation() {
return noradID; return elevation;
} }
public void setNoradID(int noradID) { public void setElevation(final double elevation) {
this.noradID = noradID; this.elevation = elevation;
} }
public String getSource() { public long getfDown() {
return source; return fDown;
} }
public void setSource(String source) { public void setfDown(final long fDown) {
this.source = source; this.fDown = fDown;
} }
public String getTimestamp() { /**
return timestamp; * Set Station information. Fill source, longitude & latitude information.
} *
* @param station
*/
public void setStation(final Station station) {
source = station.getCallsign();
public void setTimestamp(String timestamp) { longitude = station.getLongitude();
this.timestamp = timestamp;
}
public String getFrame() { latitude = station.getLatitude();
return frame;
}
public void setFrame(String frame) { }
this.frame = frame;
}
public int getTncPort() { public String getLocator() {
return tncPort;
}
public void setTncPort(int tncPort) { return locator;
this.tncPort = tncPort; }
}
public double getAzimuth() { public String toStringBasic() {
return azimuth; StringBuilder sb = new StringBuilder();
} sb.append("noradID=");
sb.append(noradID);
sb.append("&source=");
sb.append(source);
sb.append("&timestamp=");
sb.append(timestamp);
sb.append("&frame=");
sb.append(frame);
sb.append("&locator=");
sb.append(locator);
sb.append("&longitude=");
sb.append(longitude);
sb.append("&latitude=");
sb.append(latitude);
sb.append("&version=");
sb.append(version);
public void setAzimuth(double azimuth) { return sb.toString();
this.azimuth = azimuth;
}
public double getElevation() { }
return elevation;
}
public void setElevation(double elevation) {
this.elevation = elevation;
}
public long getfDown() {
return fDown;
}
public void setfDown(long fDown) {
this.fDown = fDown;
}
/**
* Set Station information. Fill source, longitude & latitude information.
* @param station
*/
public void setStation(Station station)
{
source = station.getCallsign();
longitude = station.getLongitude();
latitude = station.getLatitude();
}
public String getLocator() {
return locator;
}
public String toStringBasic()
{
StringBuilder sb = new StringBuilder ();
sb.append("noradID=");
sb.append(noradID);
sb.append("&source=");
sb.append(source);
sb.append("&timestamp=");
sb.append(timestamp);
sb.append("&frame=");
sb.append(frame);
sb.append("&locator=");
sb.append(locator);
sb.append("&longitude=");
sb.append(longitude);
sb.append("&latitude=");
sb.append(latitude);
sb.append("&version=");
sb.append(version);
return sb.toString() ;
}
} }
...@@ -4,60 +4,55 @@ import java.util.regex.Matcher; ...@@ -4,60 +4,55 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Station { public class Station {
private String callsign = "XtopheSwl";
private String callsign="XtopheSwl"; private String longitude = "1.47E";
private String longitude="1.47E"; private String latitude = "43.56N";
private String latitude="43.56N"; public Station(final String callsign, final String longitude, final String latitude) {
super();
public Station(String callsign, String longitude, String latitude) { this.callsign = callsign;
super(); this.longitude = longitude;
this.callsign = callsign; this.latitude = latitude;
this.longitude = longitude;
this.latitude = latitude;
} }
public Station() { public Station() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public String getCallsign() { public String getCallsign() {
return callsign; return callsign;
} }
public void setCallsign(String callsign) { public void setCallsign(final String callsign) {
this.callsign = callsign; this.callsign = callsign;
} }
public String getLongitude() { public String getLongitude() {
return longitude; return longitude;
} }
public void setLongitude(String longitude) { public void setLongitude(final String longitude) {
this.longitude = longitude; this.longitude = longitude;
} }
public String getLatitude() { public String getLatitude() {
return latitude; return latitude;
} }
public void setLatitude(String latitude) { public void setLatitude(final String latitude) {
this.latitude = latitude; this.latitude = latitude;
} }
public boolean checkLatitude (String latitude) public boolean checkLatitude(final String latitude) {
{
Pattern p = Pattern.compile("[\\d]*\\.[\\d]*[N,S]");
Pattern p = Pattern.compile("[\\d]*\\.[\\d]*[N,S]") ; Matcher m = p.matcher(latitude);
Matcher m = p.matcher(latitude) ; return m.matches();
return m.matches() ;
}
} public boolean checkLongitude(final String longitude) {
public boolean checkLongitude (String longitude)
{ Pattern p = Pattern.compile("[\\d]*\\.[\\d]*[E,W]");
Matcher m = p.matcher(longitude);
Pattern p = Pattern.compile("[\\d]*\\.[\\d]*[E,W]") ; return m.matches();
Matcher m = p.matcher(longitude) ;
return m.matches() ; }
}
} }
...@@ -14,92 +14,76 @@ import org.josast.SIDS.Station; ...@@ -14,92 +14,76 @@ import org.josast.SIDS.Station;
public class SendFile { public class SendFile {
SIDSData sids = new SIDSData(); private SIDSData sids = new SIDSData();
BufferedReader lecteurAvecBuffer = null; private BufferedReader lecteurAvecBuffer = null;
String ligne; private String ligne;
public void initSIDS () public void initSIDS() {
{
sids.setStation(new Station());
sids.setStation(new Station()); sids.setNoradID(99990);
sids.setNoradID(99990); }
}
public void openFile(final String file) {
public void OpenFile(String file) try {
{ lecteurAvecBuffer = new BufferedReader(new FileReader(file));
try } catch (FileNotFoundException exc) {
{ System.out.println("Erreur d'ouverture");
lecteurAvecBuffer = new BufferedReader(new FileReader(file)); }
} }
catch(FileNotFoundException exc)
{ public void readFile() {
System.out.println("Erreur d'ouverture"); boolean first = false;
} Date dateref = null;
} try {
while ((ligne = lecteurAvecBuffer.readLine()) != null) {
public void readFile () String[] result1 = ligne.split("=");
{ String[] date = result1[1].split("]");
boolean first = false; String[] trame = result1[2].split("]");
Date dateref=null;
try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
while ((ligne = lecteurAvecBuffer.readLine()) != null) "E MMM dd hh:mm:ss z yyyy", Locale.ENGLISH);
{
System.out
String[] result1=ligne.split("="); .println("date : " + date[0] + " - Trame " + trame[0]);
String[] date = result1[1].split("]"); Date date2 = simpleDateFormat.parse(date[0]);
String[] trame = result1[2].split("]"); if (first == false) {
dateref = date2;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy",Locale.ENGLISH); first = true;
} else {
System.out.println("date : "+date[0]+" - Trame "+trame[0]); System.out.println(
Date date2 = simpleDateFormat.parse(date[0]); (date2.getTime() - dateref.getTime()) / 1000);
if (first==false) }
{ }
dateref=date2;
first = true; } catch (IOException e) {
} // TODO Auto-generated catch block
else e.printStackTrace();
{ } catch (ParseException e) {
System.out.println((date2.getTime() - dateref.getTime())/1000); // TODO Auto-generated catch block
} e.printStackTrace();
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block public void closeFile() {
e.printStackTrace(); try {
} catch (ParseException e) { lecteurAvecBuffer.close();
// TODO Auto-generated catch block } catch (IOException e) {
e.printStackTrace(); // TODO Auto-generated catch block
} e.printStackTrace();
}
} }
public void closeFile() public static void main(String[] argv) throws IOException {
{
try { SendFile sf = new SendFile();
lecteurAvecBuffer.close(); sf.openFile(argv[0]);
} catch (IOException e) { sf.initSIDS();
// TODO Auto-generated catch block sf.readFile();
e.printStackTrace(); sf.closeFile();
}
} }
public static void main(String[] argv) throws IOException
{
SendFile sf = new SendFile();
sf.OpenFile(argv[0]);
sf.initSIDS();
sf.readFile();
sf.closeFile();
}
} }
/** /**
* *
*/ */
package org.josast.SIDS.app; package org.josast.SIDS.app;
...@@ -15,50 +15,43 @@ import org.josast.SIDS.Station; ...@@ -15,50 +15,43 @@ import org.josast.SIDS.Station;
* *
*/ */
public class TestSIDS { public class TestSIDS {
private HttpPostSIDS client=null;
private HttpPostSIDS client = null;
public TestSIDS(final String url) {
super();
client = new HttpPostSIDS(url);
}
public void send(final SIDSData sids) {
int result = client.SendSIDSBasic(sids);
public TestSIDS(String url) { System.out.println("resutats = " + result);
super(); System.out.println("resutats = " + client.getResult());
client = new HttpPostSIDS(url); }
}
/**
public void Send(SIDSData sids) * @param args
{ */
int result = client.SendSIDSBasic(sids); public static void main(String[] args) throws IOException {
System.out.println("resutats = " + result); // String url = "https://db.satnogs.org/api/telemetry/";
System.out.println("resutats = " + client.getResult()); // String url = "https://db-dev.satnogs.org/api/telemetry/";
} // String url = "http://127.0.0.1:9000/echoPost";
/** // String url = "https://amsat.electrolab.fr/SIDS";
* @param args
*/
public static void main(String[] args) throws IOException {
String url = "http:/127.0.0.1:8080/SIDS";
// String url = "https://db.satnogs.org/api/telemetry/"; TestSIDS test = new TestSIDS(url);
// String url = "https://db-dev.satnogs.org/api/telemetry/"; // initialise SIDS data
// String url = "http://127.0.0.1:9000/echoPost";
// String url = "https://amsat.electrolab.fr/SIDS";
String url = "http:/127.0.0.1:8080/SIDS";
TestSIDS test = new TestSIDS(url);
// initialise SIDS data
SIDSData sids = new SIDSData(); SIDSData sids = new SIDSData();
sids.setStation(new Station()); sids.setStation(new Station());
sids.setNoradID(99836); sids.setNoradID(99836);
sids.setTelemetryData(GregorianCalendar.getInstance().getTime(), sids.setTelemetryData(GregorianCalendar.getInstance().getTime(),
"8c6c96a88240e09e9c60648ca46103f0000000000801ca5c0012100319240a0d4b5f0600ff2800002822443e6fb0870d0a24c0"); "8c6c96a88240e09e9c60648ca46103f0000000000801ca5c0012100319240a0d4b5f0600ff2800002822443e6fb0870d0a24c0");
System.out.println(sids.toStringBasic()); System.out.println(sids.toStringBasic());
test.Send(sids); test.send(sids);
} }
} }
...@@ -6,23 +6,22 @@ ...@@ -6,23 +6,22 @@
<parent> <parent>
<groupId>org.josast</groupId> <groupId>org.josast</groupId>
<artifactId>JOSAST-parent</artifactId> <artifactId>JOSAST-parent</artifactId>
<version>0.0.2</version> <version>0.0.2</version>
</parent> </parent>
<artifactId>ModuleSoundModem</artifactId> <artifactId>ModuleSoundModem</artifactId>
<!-- <version>0.0.1-SNAPSHOT</version> -->
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -->
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<plugin.compiler.version>2.3.2</plugin.compiler.version> <plugin.compiler.version>2.3.2</plugin.compiler.version>
<commons-cli.version>1.4 </commons-cli.version>
<kaitai-struct-runtime.version>0.9</kaitai-struct-runtime.version>
</properties> </properties>
...@@ -34,30 +33,22 @@ ...@@ -34,30 +33,22 @@
<artifactId>ModuleConfig</artifactId> <artifactId>ModuleConfig</artifactId>
<version>${josast.version}</version> <version>${josast.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.4</version> <version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/name.valery1707.kaitai/kaitai-maven-plugin -->
<!-- <dependency> -->
<!-- <groupId>name.valery1707.kaitai</groupId> -->
<!-- <artifactId>kaitai-maven-plugin</artifactId> -->
<!-- <version>${kaitai-maven-plugin-version}</version> -->
<!-- </dependency> -->
<!-- https://mvnrepository.com/artifact/io.kaitai/kaitai-struct-runtime --> <!-- https://mvnrepository.com/artifact/io.kaitai/kaitai-struct-runtime -->
<dependency> <dependency>
<groupId>io.kaitai</groupId> <groupId>io.kaitai</groupId>
<artifactId>kaitai-struct-runtime</artifactId> <artifactId>kaitai-struct-runtime</artifactId>
<version>0.8</version> <version>${kaitai-struct-runtime.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
...@@ -66,7 +57,7 @@ ...@@ -66,7 +57,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>make-assembly</id> <!-- this is used for inheritance merges --> <id>make-assembly</id> <!-- this is used for inheritance merges -->
...@@ -75,7 +66,6 @@ ...@@ -75,7 +66,6 @@
<goal>single</goal> <goal>single</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<archive> <archive>
...@@ -89,8 +79,6 @@ ...@@ -89,8 +79,6 @@
<descriptorRef>jar-with-dependencies</descriptorRef> <descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs> </descriptorRefs>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -27,7 +27,7 @@ public class AX25Frame { ...@@ -27,7 +27,7 @@ public class AX25Frame {
byte type; byte type;
@Deprecated @Deprecated
public void decodeAX25Frame (byte[] frame , int lenght) public void decodeAX25Frame(byte[] frame, int lenght)
{ {
int offset = 0; int offset = 0;
rawData=frame; rawData=frame;
...@@ -75,8 +75,7 @@ public void decodeAX25Frame (byte[] frame , int lenght) ...@@ -75,8 +75,7 @@ public void decodeAX25Frame (byte[] frame , int lenght)
Callsign calsign = new Callsign(); Callsign calsign = new Callsign();
char [] val =new char[6]; char [] val =new char[6];
for (int i=0;i<6;i++) for (int i=0;i<6;i++){
{
char c= (char) ((arg0[i+offset] & 0xFF) >>1 & 0x7F); char c= (char) ((arg0[i+offset] & 0xFF) >>1 & 0x7F);
...@@ -88,8 +87,7 @@ public void decodeAX25Frame (byte[] frame , int lenght) ...@@ -88,8 +87,7 @@ public void decodeAX25Frame (byte[] frame , int lenght)
} }
@Deprecated @Deprecated
public Callsign getFromClassign () public Callsign getFromClassign() {
{
return from; return from;
} }
@Deprecated @Deprecated
......
...@@ -5,7 +5,7 @@ public class Callsign { ...@@ -5,7 +5,7 @@ public class Callsign {
private int ssid; private int ssid;
@Deprecated @Deprecated
public Callsign () public Callsign()
{ {
} }
...@@ -31,7 +31,7 @@ public class Callsign { ...@@ -31,7 +31,7 @@ public class Callsign {
public String toString() public String toString()
{ {
return String.valueOf(callsign)+" SSID "+ssid ; return String.valueOf(callsign)+" SSID "+ssid;
} }
@Deprecated @Deprecated
......
...@@ -2,116 +2,116 @@ package org.josast.AX25; ...@@ -2,116 +2,116 @@ package org.josast.AX25;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@Deprecated @Deprecated
public class KissFrame { public class KissFrame {
public static final int AX25 = 0; public static final int AX25 = 0;
public static final int TXDELAY = 1; public static final int TXDELAY = 1;
public static final int P = 2; public static final int P = 2;
public static final int SlotTime = 3; public static final int SlotTime = 3;
public static final int TXtail = 4; public static final int TXtail = 4;
public static final int Fullduplex = 5; public static final int Fullduplex = 5;
public static final int SetHardware = 6; public static final int SetHardware = 6;
public static final int Exit = 255; public static final int Exit = 255;
public static final int unknow = -1; public static final int unknow = -1;
public int cptcontents=0; public int cptcontents = 0;
private Logger log = Logger.getLogger("AmsatLogger"); private Logger log = Logger.getLogger("AmsatLogger");
private byte type; private byte type;
private byte [] contents= new byte[1050]; private byte[] contents = new byte[1050];
@Deprecated @Deprecated
public void setType(byte ax252) { public void setType(byte ax252) {
type = ax252; type = ax252;
} }
@Deprecated
public byte DecodeKissType(byte val) { @Deprecated
public byte DecodeKissType(final byte val) {
switch (val) {
case 0x00: type = AX25; switch (val) {
log.log(Level.INFO, "AX25 type"); case 0x00:
break; type = AX25;
case 0x01: type = TXDELAY; log.log(Level.INFO, "AX25 type");
break; break;
case 0x02: type = P; case 0x01:
break; type = TXDELAY;
case 0x03: type = SlotTime; break;
break; case 0x02:
case 0x04: type = TXtail; type = P;
break; break;
case 0x05: type = Fullduplex; case 0x03:
break; type = SlotTime;
case 0x07: type = SetHardware; break;
break; case 0x04:
case (byte) 0xFF: type = (byte) Exit; type = TXtail;
break; break;
default : type = unknow; case 0x05:
log.log(Level.INFO, "unknow type"); type = Fullduplex;
} break;
case 0x07:
return type; type = SetHardware;
} break;
case (byte) 0xFF:
type = (byte) Exit;
@Deprecated break;
public KissData extactMessage(byte[] frame, int nb ) default:
{ type = unknow;
KissData kissData; log.log(Level.INFO, "unknow type");
}
type=unknow;
return type;
boolean startFrame = false; }
boolean endFrame = false;
int cpt=0; @Deprecated
cptcontents=0; public KissData extactMessage(byte[] frame, int nb) {
KissData kissData;
// detect start frame
while (!startFrame ) type = unknow;
{
if (((byte)frame[cpt++] & 0xFF)== 0xC0) boolean startFrame = false;
{ boolean endFrame = false;
startFrame = true; int cpt = 0;
} cptcontents = 0;
if (cpt==nb)
{ // detect start frame
startFrame = true; while (!startFrame) {
endFrame = true; if (((byte) frame[cpt++] & 0xFF) == 0xC0) {
} startFrame = true;
} }
// identify frame if (cpt == nb) {
type = DecodeKissType ((byte)( frame[cpt++] & 0xFF)); startFrame = true;
endFrame = true;
// Extract data }
while (!endFrame ) }
{ // identify frame
type = DecodeKissType((byte) (frame[cpt++] & 0xFF));
if (((int)frame[cpt] & 0xFF)== 0xDB)
{ // Extract data
cpt++; while (!endFrame) {
}
if (((int)frame[cpt] & 0xFF)== 0xDD) if (((int) frame[cpt] & 0xFF) == 0xDB) {
{ cpt++;
cpt++; }
} if (((int) frame[cpt] & 0xFF) == 0xDD) {
cpt++;
if (((int)frame[cpt] & 0xFF)== 0xC0) }
{
endFrame = true; if (((int) frame[cpt] & 0xFF) == 0xC0) {
} endFrame = true;
contents[cptcontents++] =(byte)(frame[cpt++] & 0xFF); }
contents[cptcontents++] = (byte) (frame[cpt++] & 0xFF);
if (cpt>=nb)
{ if (cpt >= nb) {
endFrame = true; endFrame = true;
} }
} }
kissData = new KissData(contents,cptcontents); kissData = new KissData(contents, cptcontents);
return kissData; return kissData;
} }
} }
...@@ -9,13 +9,13 @@ package org.josast.ModuleSoundModem; ...@@ -9,13 +9,13 @@ package org.josast.ModuleSoundModem;
*/ */
public class KissException extends Exception { public class KissException extends Exception {
/** /**.
* *
*/ */
private static final long serialVersionUID = 7103474292775784017L; private static final long serialVersionUID = 7103474292775784017L;
/** /**.
* *
*/ */
public KissException() { public KissException() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
...@@ -24,7 +24,7 @@ public class KissException extends Exception { ...@@ -24,7 +24,7 @@ public class KissException extends Exception {
/** /**
* @param message * @param message
*/ */
public KissException(String message) { public KissException(final String message) {
super(message); super(message);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
...@@ -32,7 +32,7 @@ public class KissException extends Exception { ...@@ -32,7 +32,7 @@ public class KissException extends Exception {
/** /**
* @param cause * @param cause
*/ */
public KissException(Throwable cause) { public KissException(final Throwable cause) {
super(cause); super(cause);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
...@@ -41,7 +41,7 @@ public class KissException extends Exception { ...@@ -41,7 +41,7 @@ public class KissException extends Exception {
* @param message * @param message
* @param cause * @param cause
*/ */
public KissException(String message, Throwable cause) { public KissException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
...@@ -52,7 +52,7 @@ public class KissException extends Exception { ...@@ -52,7 +52,7 @@ public class KissException extends Exception {
* @param enableSuppression * @param enableSuppression
* @param writableStackTrace * @param writableStackTrace
*/ */
public KissException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { public KissException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
......
...@@ -22,18 +22,17 @@ import org.apache.commons.cli.ParseException; ...@@ -22,18 +22,17 @@ import org.apache.commons.cli.ParseException;
* *
*/ */
public class SoundModemCli { public class SoundModemCli {
private Logger log = Logger.getLogger("AmsatLogger");
private Logger log = Logger.getLogger("AmsatLogger");
private static String version = "0.2"; private static String version = "0.2";
private String configurationfile = "defaultConfigFile.ini"; private String configurationfile = "defaultConfigFile.ini";
/* /*
* Utilisation d'un répertoire par défaut * Utilisation d'un répertoire par défaut
*/ */
private String generateRepository = "SoundModemOuput"; private String generateRepository = "SoundModemOuput";
/** /**
* *
*/ */
public SoundModemCli() { public SoundModemCli() {
...@@ -122,9 +121,9 @@ public class SoundModemCli { ...@@ -122,9 +121,9 @@ public class SoundModemCli {
public void execute() { public void execute() {
// use soudmodem configuration file // use soudmodem configuration file
SoundModemClient sm = new SoundModemClient(configurationfile); SoundModemClient sm = new SoundModemClient(configurationfile);
// tant que connecté à SoundModem => reçoit des trames // tant que connecté à SoundModem => reçoit des trames
int cpt = 0; int cpt = 0;
Path path = Paths.get(generateRepository); Path path = Paths.get(generateRepository);
...@@ -138,15 +137,15 @@ public class SoundModemCli { ...@@ -138,15 +137,15 @@ public class SoundModemCli {
} }
} }
while (true) { while (true) {
byte[] temp = sm.receivedKissData(); byte[] temp = sm.receivedKissData();
try { try {
Files.write(Paths.get(generateRepository + "\\Frame_" + cpt+++".bin"), temp); Files.write(Paths.get(generateRepository + "\\Frame_" + cpt++ + ".bin"), temp);
} catch (IOException e) { } catch (IOException e) {
log.severe(e.toString()); log.severe(e.toString());
} }
...@@ -210,7 +209,7 @@ public class SoundModemCli { ...@@ -210,7 +209,7 @@ public class SoundModemCli {
smc.setGenerateRepository(line.getOptionValue("Generate", "")); smc.setGenerateRepository(line.getOptionValue("Generate", ""));
} }
smc.execute(); smc.execute();
} }
......
...@@ -26,12 +26,11 @@ public class SoundModemClient { ...@@ -26,12 +26,11 @@ public class SoundModemClient {
private InputStream in = null; private InputStream in = null;
private boolean open = false; private boolean open = false;
private int bufferSize = 1024; private int bufferSize = 1024;
private Path filepath; private Path filepath;
/** /**
* Initialise connection to soundmodem application with default value * Initialise connection to soundmodem application with default value
* *
*/ */
public SoundModemClient() { public SoundModemClient() {
...@@ -42,9 +41,9 @@ public class SoundModemClient { ...@@ -42,9 +41,9 @@ public class SoundModemClient {
/** /**
* Initialise connection to soundmodem application with configuration * Initialise connection to soundmodem application with configuration
* *
*/ */
public SoundModemClient(SoundModemConfiguration smConfig) { public SoundModemClient(final SoundModemConfiguration smConfig) {
smConfiguration = smConfig; smConfiguration = smConfig;
openSocket(); openSocket();
...@@ -52,11 +51,11 @@ public class SoundModemClient { ...@@ -52,11 +51,11 @@ public class SoundModemClient {
} }
/** /**.
* Initialise connection to soundmodem application with configuration file * Initialise connection to soundmodem application with configuration file
* *
*/ */
public SoundModemClient(String filename) { public SoundModemClient(final String filename) {
smConfiguration = new SoundModemConfiguration(filename); smConfiguration = new SoundModemConfiguration(filename);
openSocket(); openSocket();
...@@ -112,9 +111,9 @@ public class SoundModemClient { ...@@ -112,9 +111,9 @@ public class SoundModemClient {
} }
/** /**.
* wait bytes from sound modem * wait bytes from sound modem
* *
* @return bytes received in KISS format * @return bytes received in KISS format
*/ */
public byte[] receivedKissData() { public byte[] receivedKissData() {
...@@ -154,7 +153,7 @@ public class SoundModemClient { ...@@ -154,7 +153,7 @@ public class SoundModemClient {
} }
@Deprecated @Deprecated
public int receiveData(byte[] cbuf) { public int receiveData(final byte[] cbuf) {
try { try {
return in.read(cbuf); return in.read(cbuf);
} catch (IOException e) { } catch (IOException e) {
...@@ -172,7 +171,7 @@ public class SoundModemClient { ...@@ -172,7 +171,7 @@ public class SoundModemClient {
} }
@Deprecated @Deprecated
public AX25Frame decode(byte[] frame, int nb) { public AX25Frame decode(final byte[] frame, final int nb) {
KissFrame kf = new KissFrame(); KissFrame kf = new KissFrame();
KissData kissData = kf.extactMessage(frame, nb); KissData kissData = kf.extactMessage(frame, nb);
...@@ -202,10 +201,8 @@ public class SoundModemClient { ...@@ -202,10 +201,8 @@ public class SoundModemClient {
public byte[] receivedRawData() { public byte[] receivedRawData() {
byte[] temp = receivedKissData(); byte[] temp = receivedKissData();
if (temp != null) if (temp != null) {
{
kiss k = new kiss(temp); kiss k = new kiss(temp);
try { try {
temp = k.toRaw(); temp = k.toRaw();
...@@ -213,14 +210,11 @@ public class SoundModemClient { ...@@ -213,14 +210,11 @@ public class SoundModemClient {
log.log(Level.SEVERE, "Extract Raw data " + e.toString()); log.log(Level.SEVERE, "Extract Raw data " + e.toString());
} }
return temp; return temp;
} }
else else {
{
log.severe("Buffer read null, return null"); log.severe("Buffer read null, return null");
return null; return null;
} }
} }
} }
...@@ -9,112 +9,162 @@ import org.josast.property.ConfigObject; ...@@ -9,112 +9,162 @@ import org.josast.property.ConfigObject;
* @author Christophe * @author Christophe
* *
*/ */
/**
* @author christophe
*
*/
/**
* @author christophe
*
*/
/**
* @author christophe
*
*/
/**
* @author christophe
*
*/
/**
* @author christophe
*
*/
/**
* @author christophe
*
*/
public class SoundModemConfiguration extends ConfigObject { public class SoundModemConfiguration extends ConfigObject {
private Logger log = Logger.getLogger("AmsatLogger"); private Logger log = Logger.getLogger("AmsatLogger");
private String smIPadress = "localhost"; /** Default IP Adress. */
private int smPort = 8100; private String smIPadress = "localhost";
private boolean smGenerateBinarieFile = false; /** Default port. */
private String smBinarieOutputFile = "soundmodem.bin"; private int smPort = 8100;
private String smBinarieOutputDirectory = "SoundModemOuput"; private boolean smGenerateBinarieFile = false;
private String smBinarieOutputFile = "soundmodem.bin";
private boolean smBinarieFilePrefixDate = false; private String smBinarieOutputDirectory = "SoundModemOuput";
private boolean smBinarieFilePrefixDate = false;
protected CONFIG ConfigFile = CONFIG.getInstance();
protected CONFIG configFile = CONFIG.getInstance();
public SoundModemConfiguration(String configFilename) {
super(configFilename); /**
// vérifie si la propriété est dans le fichier * @param configFilename
String temp = ConfigFile.GetProperty("smPort"); */
public SoundModemConfiguration(final String configFilename) {
if (temp == null) { super(configFilename);
// config file not initialised // vérifie si la propriété est dans le fichier
initialisePropertiesFile(); String temp = configFile.GetProperty("smPort");
log.severe("properties file not initialised - a file is created with properties with defaults value");
System.out.println("config file does not content required properties \n the file " + configFilename if (temp == null) {
+ " has been set up with properties to configure"); // config file not initialised
initialisePropertiesFile();
} else { log.severe(
initialiseFromProperties(); "properties file not initialised - a file is created with properties with defaults value");
} System.out.println(
"config file does not content required properties \n the file "
} + configFilename
+ " has been set up with properties to configure");
private void initialisePropertiesFile() {
ConfigFile.SetProperty("smIPadress", smIPadress); } else {
ConfigFile.SetProperty("smPort", "" + smPort); initialiseFromProperties();
ConfigFile.SetProperty("smGenerateBinarieFile",""+smGenerateBinarieFile); }
ConfigFile.SetProperty("smBinarieOutputFile",smBinarieOutputFile);
ConfigFile.SetProperty("smBinarieOutputFile",smBinarieOutputDirectory); }
ConfigFile.SetProperty("smBinarieFilePrefixDate",""+smBinarieFilePrefixDate);
private void initialisePropertiesFile() {
} configFile.SetProperty("smIPadress", smIPadress);
configFile.SetProperty("smPort", "" + smPort);
private void initialiseFromProperties() configFile.SetProperty("smGenerateBinarieFile",
{ "" + smGenerateBinarieFile);
smIPadress = ConfigFile.GetProperty("smIPadress"); configFile.SetProperty("smBinarieOutputFile", smBinarieOutputFile);
smPort = Integer.parseInt(ConfigFile.GetProperty("smPort")); configFile.SetProperty("smBinarieOutputFile", smBinarieOutputDirectory);
smGenerateBinarieFile = Boolean.parseBoolean(ConfigFile.GetProperty("smGenerateBinarieFile")); configFile.SetProperty("smBinarieFilePrefixDate",
smBinarieOutputFile = ConfigFile.GetProperty("smBinarieOutputFile"); "" + smBinarieFilePrefixDate);
smBinarieOutputDirectory = ConfigFile.GetProperty("smBinarieOutputDirectory");
smBinarieFilePrefixDate = Boolean.parseBoolean(ConfigFile.GetProperty("smBinarieFilePrefixDate")); }
private void initialiseFromProperties() {
} smIPadress = configFile.GetProperty("smIPadress");
smPort = Integer.parseInt(configFile.GetProperty("smPort"));
public String getSmIPadress() { smGenerateBinarieFile = Boolean
return smIPadress; .parseBoolean(configFile.GetProperty("smGenerateBinarieFile"));
} smBinarieOutputFile = configFile.GetProperty("smBinarieOutputFile");
smBinarieOutputDirectory = configFile
public void setSmIPadress(String iPadress) { .GetProperty("smBinarieOutputDirectory");
smIPadress = iPadress; smBinarieFilePrefixDate = Boolean.parseBoolean(
} configFile.GetProperty("smBinarieFilePrefixDate"));
public int getSmPort() { }
return smPort;
} /**
* @return IP adress
public void setSmPort(int port) { */
this.smPort = port; public String getSmIPadress() {
} return smIPadress;
}
public String toString() {
return smIPadress + ":" + smPort; /**
} * @param iPadress
*/
public boolean isSmGenerateBinarieFile() { public void setSmIPadress(final String iPadress) {
return smGenerateBinarieFile; smIPadress = iPadress;
} }
public void setSmGenerateBinarieFile(boolean smGenerateBinarieFile) { /**
this.smGenerateBinarieFile = smGenerateBinarieFile; * @return Port
} */
public int getSmPort() {
public String getSmBinarieOutputFile() { return smPort;
return smBinarieOutputFile; }
}
public void setSmPort(final int port) {
public void setSmBinarieOutputFile(String smBinarieOutputFile) { this.smPort = port;
this.smBinarieOutputFile = smBinarieOutputFile; }
}
public String toString() {
public boolean isSmBinarieFilePrefixDate() { return smIPadress + ":" + smPort;
return smBinarieFilePrefixDate; }
} /**
* @return GenerateBinarieFile
public void setSmBinarieFilePrefixDate(boolean smBinarieFilePrefixDate) { */
this.smBinarieFilePrefixDate = smBinarieFilePrefixDate; public boolean isSmGenerateBinarieFile() {
} return smGenerateBinarieFile;
}
public String getSmBinarieOutputDirectory() {
return smBinarieOutputDirectory; public void setSmGenerateBinarieFile(final boolean smGenerateBinarieFile) {
} this.smGenerateBinarieFile = smGenerateBinarieFile;
}
public void setSmBinarieOutputDirectory(String smBinarieOutputDirectory) { /**
this.smBinarieOutputDirectory = smBinarieOutputDirectory; * @return BinarieOutputFile
} */
public String getSmBinarieOutputFile() {
return smBinarieOutputFile;
}
public void setSmBinarieOutputFile(final String smBinarieOutputFile) {
this.smBinarieOutputFile = smBinarieOutputFile;
}
/**
* @return BinarieFilePrefixDate
*/
public boolean isSmBinarieFilePrefixDate() {
return smBinarieFilePrefixDate;
}
public void setSmBinarieFilePrefixDate(final boolean smBinarieFilePrefixDate) {
this.smBinarieFilePrefixDate = smBinarieFilePrefixDate;
}
/**
* @return BinarieOutputDirectory
*/
public String getSmBinarieOutputDirectory() {
return smBinarieOutputDirectory;
}
public void setSmBinarieOutputDirectory(final String smBinarieOutputDirectory) {
this.smBinarieOutputDirectory = smBinarieOutputDirectory;
}
} }
...@@ -2,17 +2,14 @@ package org.josast.ModuleSoundModem; ...@@ -2,17 +2,14 @@ package org.josast.ModuleSoundModem;
import java.util.Arrays; import java.util.Arrays;
/** /** manage Kiss frame based on KISS protocol.
* manage Kiss frame based on KISS protocol * @see http://www.ka9q.net/papers/kiss.html
*
* @see http://www.ka9q.net/papers/kiss.html
*
* @author christophe * @author christophe
* *
*/ */
public class kiss { public class kiss {
private static final byte DATA = 0; private static final byte DATA = 0;
private static final byte UNKNOW = (byte) 0xF0; private static final byte UNKNOW = (byte) 0xF0;
...@@ -49,7 +46,7 @@ public class kiss { ...@@ -49,7 +46,7 @@ public class kiss {
public kiss(final byte[] data) { public kiss(final byte[] data) {
kissdata = data; kissdata = data;
} }
public byte getType() { public byte getType() {
return type; return type;
} }
...@@ -57,30 +54,29 @@ public class kiss { ...@@ -57,30 +54,29 @@ public class kiss {
public void setType(byte type) { public void setType(byte type) {
this.type = type; this.type = type;
} }
/** /**
* *
* @return array with data * @return array with data
* @throws KissException * @throws KissException
*/ */
public byte[] toRaw() throws KissException { public byte[] toRaw() throws KissException {
byte[] rawData = null; byte[] rawData = null;
rawData = new byte[kissdata.length]; rawData = new byte[kissdata.length];
// identifie le début de trame // identifie le début de trame
if (kissdata[0] != FEND) { if (kissdata[0] != FEND) {
throw new KissException("FEND (0xC0) value not find at the beginning of the frame "); throw new KissException("FEND (0xC0) value not find at the beginning of the frame ");
} }
// vérifie que la fin de trame est bien identifié // vérifie que la fin de trame est bien identifié
if (kissdata[kissdata.length - 1] != FEND) { if (kissdata[kissdata.length - 1] != FEND) {
throw new KissException("FEND (0xC0) value not find at the end of the frame "); throw new KissException("FEND (0xC0) value not find at the end of the frame ");
} }
// Identifie le type de trame // Identifie le type de trame
switch (kissdata[1]) switch (kissdata[1]) {
{
case 0 : type = DATA; case 0 : type = DATA;
break; break;
case 1 : type = TXDELAY; case 1 : type = TXDELAY;
break; break;
case 2 : type = P; case 2 : type = P;
break; break;
case 3 : type = SLOTTIME; case 3 : type = SLOTTIME;
...@@ -88,16 +84,15 @@ public class kiss { ...@@ -88,16 +84,15 @@ public class kiss {
case 4 : type = TXTAIL; case 4 : type = TXTAIL;
break; break;
case 5 : type = FULLDUPLEX; case 5 : type = FULLDUPLEX;
break; break;
case 6 : type = SETHARDWARE; case 6 : type = SETHARDWARE;
break; break;
case (byte) 0xff: type = RETURN; case (byte) 0xff: type = RETURN;
break; break;
default : type = UNKNOW; default : type = UNKNOW;
} }
int cptraw = 0; int cptraw = 0;
int i = 2; int i = 2;
while (kissdata[i] != FEND) { while (kissdata[i] != FEND) {
...@@ -105,13 +100,11 @@ public class kiss { ...@@ -105,13 +100,11 @@ public class kiss {
rawData[cptraw++] = kissdata[i++]; rawData[cptraw++] = kissdata[i++];
} else { } else {
if (kissdata[i + 1] == TFEND) { if (kissdata[i + 1] == TFEND) {
rawData[cptraw++] = FEND; rawData[cptraw++] = FEND;
i = i + 2; i = i + 2;
} else if (kissdata[i + 1] == TFESC) { } else if (kissdata[i + 1] == TFESC) {
rawData[cptraw++] = FESC; rawData[cptraw++] = FESC;
i = i +2; i = i + 2;
} else { } else {
rawData[cptraw++] = kissdata[i++]; rawData[cptraw++] = kissdata[i++];
} }
......