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