From 2342348cc8e51f97fc1c06e3983d6372186b211a Mon Sep 17 00:00:00 2001 From: Jose Damico Date: Tue, 2 Jan 2024 17:40:25 -0300 Subject: [PATCH] added basic impl for encode tests thru GUI --- src/main/java/org/jdamico/javax25/GuiApp.java | 84 ++++++++++++++++--- .../org/jdamico/javax25/GuiDecoderThread.java | 17 ++-- .../jdamico/javax25/soundcard/Soundcard.java | 23 ++++- 3 files changed, 100 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/jdamico/javax25/GuiApp.java b/src/main/java/org/jdamico/javax25/GuiApp.java index d9dfa44..a81708a 100644 --- a/src/main/java/org/jdamico/javax25/GuiApp.java +++ b/src/main/java/org/jdamico/javax25/GuiApp.java @@ -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() { @@ -42,16 +55,25 @@ public GuiApp() { super(new BorderLayout()); JPanel northPanel = new JPanel(); // **** to hold buttons + JPanel southPanel = new JPanel(); // **** to hold buttons List 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); @@ -64,7 +86,7 @@ public GuiApp() { public void actionPerformed(ActionEvent arg0) { Soundcard.running = false; guiDecoderThread.interrupt(); - devicesComboBox.setEnabled(true); + inputDevicesComboBox.setEnabled(true); decodeBtn.setEnabled(true); resetBtn.setEnabled(false); } @@ -72,8 +94,42 @@ public void actionPerformed(ActionEvent arg0) { 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); @@ -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); @@ -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(); } diff --git a/src/main/java/org/jdamico/javax25/GuiDecoderThread.java b/src/main/java/org/jdamico/javax25/GuiDecoderThread.java index 3dcd6b5..fd7c369 100644 --- a/src/main/java/org/jdamico/javax25/GuiDecoderThread.java +++ b/src/main/java/org/jdamico/javax25/GuiDecoderThread.java @@ -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() { @@ -19,11 +22,10 @@ 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()); } @@ -31,9 +33,6 @@ public void run() { /*** 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 @@ -42,11 +41,11 @@ 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 ***/ @@ -54,7 +53,7 @@ public void run() { 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!"); } diff --git a/src/main/java/org/jdamico/javax25/soundcard/Soundcard.java b/src/main/java/org/jdamico/javax25/soundcard/Soundcard.java index 55bd455..430d246 100644 --- a/src/main/java/org/jdamico/javax25/soundcard/Soundcard.java +++ b/src/main/java/org/jdamico/javax25/soundcard/Soundcard.java @@ -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(); @@ -300,5 +300,24 @@ private void openSoundOutput(String mixer) { } } + public static List getOutputDevicesLst() { + List 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; + } + }