Skip to content

Commit

Permalink
added basic impl for encode tests thru GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
damico committed Jan 2, 2024
1 parent e29281f commit 2342348
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 24 deletions.
84 changes: 71 additions & 13 deletions src/main/java/org/jdamico/javax25/GuiApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,32 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.DefaultCaret;

import org.jdamico.javax25.ax25.Afsk1200Modulator;
import org.jdamico.javax25.ax25.Packet;
import org.jdamico.javax25.soundcard.Soundcard;

public class GuiApp extends JPanel implements ActionListener {

private JTextArea textArea = new JTextArea(40, 80);
private JComboBox devicesComboBox = null;
private JTextField inputPacketField;
private JTextField callsign;
private JTextField destination;
private JTextField digipath;


private JComboBox inputDevicesComboBox = null;
private JComboBox outputDevicesComboBox = null;
private JButton decodeBtn = null;
private JButton resetBtn = null;
private JButton sendBtn = null;
private JLabel audioLevelLabel = null;
private JLabel audioLevelValue = null;
private Thread guiDecoderThread;
public static Soundcard sc = null;
public static Afsk1200Modulator mod = null;

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
Expand All @@ -42,16 +55,25 @@ public GuiApp() {
super(new BorderLayout());

JPanel northPanel = new JPanel(); // **** to hold buttons
JPanel southPanel = new JPanel(); // **** to hold buttons

List<String> lst = Soundcard.getInputDevicesLst();
String[] deviceArray = new String[lst.size()];
for (int i = 0; i < deviceArray.length; i++) {
deviceArray[i] = lst.get(i);
String[] inputDeviceArray = new String[lst.size()];
for (int i = 0; i < inputDeviceArray.length; i++) {
inputDeviceArray[i] = lst.get(i);
}
inputDevicesComboBox = new JComboBox(inputDeviceArray);
northPanel.add(inputDevicesComboBox);

lst = Soundcard.getOutputDevicesLst();
String[] outputDeviceArray = new String[lst.size()];
for (int i = 0; i < outputDeviceArray.length; i++) {
outputDeviceArray[i] = lst.get(i);
}
devicesComboBox = new JComboBox(deviceArray);
northPanel.add(devicesComboBox);
outputDevicesComboBox = new JComboBox(outputDeviceArray);
northPanel.add(outputDevicesComboBox);

decodeBtn = new JButton("Decode Audio");
decodeBtn = new JButton("Open Audio Interface");
decodeBtn.addActionListener(this);
northPanel.add(decodeBtn);

Expand All @@ -64,16 +86,50 @@ public GuiApp() {
public void actionPerformed(ActionEvent arg0) {
Soundcard.running = false;
guiDecoderThread.interrupt();
devicesComboBox.setEnabled(true);
inputDevicesComboBox.setEnabled(true);
decodeBtn.setEnabled(true);
resetBtn.setEnabled(false);
}
});

resetBtn.setEnabled(false);

inputPacketField = new JTextField(40);
callsign = new JTextField(6);
digipath = new JTextField(8);
destination = new JTextField(5);
southPanel.add(callsign);
southPanel.add(digipath);
southPanel.add(destination);
southPanel.add(inputPacketField);
northPanel.add(resetBtn);

Soundcard.enumerate();



sendBtn = new JButton("Send Packet");
sendBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {

//PU2LVM-13 APRS @141244z2332.53S/04645.51W_131/003g004t067r000p000P000b10142h70Test ARISS,WIDE2-1

Packet packet = new Packet("APRS",
"PU2LVM",
new String[] {"WIDE1-1", "WIDE2-2"},
Packet.AX25_CONTROL_APRS,
Packet.AX25_PROTOCOL_NO_LAYER_3,
"@141244z2332.53S/04645.51W_131/003g004t067r000p000P000b10142h70Test".getBytes());

System.out.println(packet);
mod.prepareToTransmit(packet);
sc.transmit();
}
});
southPanel.add(sendBtn);

audioLevelLabel = new JLabel("Audio Level: ");
northPanel.add(audioLevelLabel);

Expand All @@ -82,6 +138,7 @@ public void actionPerformed(ActionEvent arg0) {
northPanel.add(audioLevelValue);

add(northPanel, BorderLayout.PAGE_START);
add(southPanel, BorderLayout.AFTER_LAST_LINE);

DefaultCaret caret = (DefaultCaret) textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
Expand Down Expand Up @@ -112,18 +169,19 @@ private static void createAndShowGUI() {

@Override
public void actionPerformed(ActionEvent arg0) {
decode();
openAudionInterfaceAndDecode();

}

private void decode() {
private void openAudionInterfaceAndDecode() {
decodeBtn.setEnabled(false);
devicesComboBox.setEnabled(false);
inputDevicesComboBox.setEnabled(false);
resetBtn.setEnabled(true);
String input = (String) devicesComboBox.getSelectedItem();
String input = (String) inputDevicesComboBox.getSelectedItem();
String output = (String) outputDevicesComboBox.getSelectedItem();
Soundcard.jTextArea = textArea;
Soundcard.audioLevelValue = audioLevelValue;
guiDecoderThread = new GuiDecoderThread(input);
guiDecoderThread = new GuiDecoderThread(input, output);
guiDecoderThread.start();
}

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/jdamico/javax25/GuiDecoderThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

public class GuiDecoderThread extends Thread {
private String input;
public GuiDecoderThread(String input) {
private String output;
public GuiDecoderThread(String input, String output) {
this.input = input;
this.output = output;

}

public void run() {
Expand All @@ -19,21 +22,17 @@ public void run() {
int rate = 48000;

PacketHandlerImpl t = new PacketHandlerImpl();
Afsk1200Modulator mod = null;
PacketDemodulator multi = null;
try {
multi = new Afsk1200MultiDemodulator(rate,t);
mod = new Afsk1200Modulator(rate);
GuiApp.mod = new Afsk1200Modulator(rate);
} catch (Exception e) {
System.out.println("Exception trying to create an Afsk1200 object: "+e.getMessage());
}


/*** preparing to generate or capture audio packets ***/

//String input = p.getProperty("input", null);
String output = null;

int buffer_size = -1;
try {
// our default is 100ms
Expand All @@ -42,19 +41,19 @@ public void run() {
System.err.println("Exception parsing buffersize "+e.toString());
}

Soundcard sc = new Soundcard(rate,input,output,buffer_size,multi,mod);
GuiApp.sc = new Soundcard(rate,input,output,buffer_size,multi,GuiApp.mod);



sc.displayAudioLevel();
GuiApp.sc.displayAudioLevel();


/*** listen for incoming packets ***/

if (input != null) {
System.out.printf("Listening for packets\n");
//sc.openSoundInput(input);
sc.receive();
GuiApp.sc.receive();
}else {
System.err.println("Input is null!");
}
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/org/jdamico/javax25/soundcard/Soundcard.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public static void enumerate() {

for (Mixer.Info mi: mis) {
String name = mi.getName();
//System.out.println(" "+mi.getName()+": "+mi.getVendor()+": "+mi.getDescription());
//System.out.println(" "+mi.getName());
System.out.println(" "+mi.getName()+": "+mi.getVendor()+": "+mi.getDescription());
System.out.println(" "+mi.getName());

Line.Info[] lis;
lis = AudioSystem.getMixer(mi).getSourceLineInfo();
Expand Down Expand Up @@ -300,5 +300,24 @@ private void openSoundOutput(String mixer) {
}
}

public static List<String> getOutputDevicesLst() {
List<String> lst = new ArrayList<>();
Mixer.Info[] mis = AudioSystem.getMixerInfo();

for (Mixer.Info mi: mis) {
String name = mi.getName();
Line.Info[] lis;
lis = AudioSystem.getMixer(mi).getSourceLineInfo();
for (Line.Info li: lis) {
if (SourceDataLine.class.equals(li.getLineClass())) {
lst.add(name);

}

}
}
return lst;
}


}

0 comments on commit 2342348

Please sign in to comment.