Newer
Older
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.josast.AX25.AX25Frame;
import org.josast.AX25.KissData;
import org.josast.AX25.KissFrame;
private SoundModemConfiguration smConfiguration = null;
private Socket skt = null;
private InputStream in = null;
private boolean open = false;
private int bufferSize = 1024;
private Path filepath;
* Initialise connection to soundmodem application with default value
smConfiguration = new SoundModemConfiguration("defaultConfigFile.ini");
* Initialise connection to soundmodem application with configuration
public SoundModemClient(final SoundModemConfiguration smConfig) {
* Initialise connection to soundmodem application with configuration file
smConfiguration = new SoundModemConfiguration(filename);
openSocket();
skt = new Socket(smConfiguration.getSmIPadress(), smConfiguration.getSmPort());
in = skt.getInputStream();
open = true;
} catch (IOException e) {
log.log(Level.SEVERE, "create stream " + e.toString());
}
}
private void initialiseFile() {
if (smConfiguration.isSmGenerateBinarieFile()) {
Path path = Paths.get(smConfiguration.getSmBinarieOutputDirectory());
// if directory exists?
if (!Files.exists(path)) {
try {
Files.createDirectories(path);
} catch (IOException e) {
log.log(Level.SEVERE, "cannot create outpout directorie " + e.toString());
}
}
String creationdate = "";
if (smConfiguration.isSmBinarieFilePrefixDate()) {
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd-HHmmss");
Date aujourdhui = new Date();
creationdate = formater.format(aujourdhui) + "-";
filepath = Paths.get(smConfiguration.getSmBinarieOutputDirectory() + "\\" + creationdate
+ smConfiguration.getSmBinarieOutputFile());
byte[] temp = new byte[] {};
try {
Files.write(filepath, temp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
nbbyteread = in.read(cbuf);
} catch (IOException e) {
log.log(Level.SEVERE, "Error Read data " + e.toString());
try {
in.close();
} catch (IOException e1) {
log.log(Level.SEVERE, "Closing " + e1.toString());
}
byte[] temp = Arrays.copyOf(cbuf, nbbyteread);
if (smConfiguration.isSmGenerateBinarieFile()) {
try {
Files.write(filepath, temp, StandardOpenOption.APPEND);
} catch (IOException e) {
log.severe(e.toString());
}
return Arrays.copyOf(cbuf, nbbyteread);
} else {
log.severe("Connection not open, return null");
return null;
try {
return in.read(cbuf);
} catch (IOException e) {
log.log(Level.SEVERE, "Error Read data " + e.toString());
try {
in.close();
} catch (IOException e1) {
log.log(Level.SEVERE, "Closing " + e1.toString());
}
}
return 0;
public AX25Frame decode(final byte[] frame, final int nb) {
KissData kissData = kf.extactMessage(frame, nb);
// if (type==kf.AX25)
// {
AX25Frame ax = new AX25Frame();
ax.decodeAX25Frame(kissData.getData(), kissData.getSize());
System.out.println(kissData.toString());
System.out.println(ax.toString());
return ax;
try {
in.close();
} catch (IOException e1) {
log.log(Level.SEVERE, "Closing " + e1.toString());
}
}
kiss k = new kiss(temp);
try {
temp = k.toRaw();
} catch (KissException e) {
log.log(Level.SEVERE, "Extract Raw data " + e.toString());
}
return temp;
log.severe("Buffer read null, return null");
return null;
}