1
0
mirror of https://github.com/JvanKatwijk/javaDab synced 2018-12-22 06:18:52 +01:00
This commit is contained in:
JvanKatwijk
2018-04-07 14:29:55 +02:00
parent 275e3fad2f
commit 9373942260
26 changed files with 270 additions and 149 deletions

BIN
JavaRadio$1$1.class Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,25 +1,91 @@
import javax.swing.*;
import devices.*;
import package_View.*;
import package_Model.*;
import package_Controller.*;
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class JavaRadio {
// ... Create model, view, and controller. They are
// created once here and passed to the parts that
// need them so there is only one copy of each.
public static void main (String[] args) {
/* Create and display the form */
java.awt.EventQueue.invokeLater (new Runnable() {
public void run() {
RadioModel model = new RadioModel (1);
RadioView view = new RadioView (model);
RadioController controller = new RadioController (model,
view, "Band III");
view.setVisible(true);
public static void main (String[] args) {
final Device theDevice = bindDevice ();
if (theDevice. is_nullDevice ()) {
System. out. println ("unable to bind to device");
System. exit (1);
}
});
}
//
final String iniFile =
System. getProperty ("user.home") + "/.javaDab.ini";
Properties savedValues = new Properties ();
File ff = new File (iniFile);
try {
savedValues. load (new FileInputStream (ff));
} catch (IOException ex) {
}
/* Create and display the form */
java.awt.EventQueue.invokeLater (new Runnable() {
final Device tuner = theDevice;
@Override
public void run () {
RadioModel model = new RadioModel (1, tuner);
RadioView view = new RadioView (model);
RadioController controller =
new RadioController (model,
view,
savedValues);
controller. startRadio ();
view.setVisible(true);
view. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
view. addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void
windowClosing(java.awt.event.WindowEvent windowEvent) {
if (JOptionPane.showConfirmDialog (new JFrame (),
"Are you sure to close this window?",
"Really Closing?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) ==
JOptionPane.YES_OPTION){
File f = new File (iniFile);
try (FileOutputStream fo =
new FileOutputStream (f)) {
savedValues. store (fo, "javaDab");
fo. close ();
} catch (Exception ex) { }
}
System.exit(0);
}
});
}
});
}
private static Device bindDevice () {
Device tester;
try {
tester = new airspyDevice (220000000, 90, true);
return tester;
} catch (Exception e) {}
try {
tester = new sdrplayDevice (220000000, 40, true);
return tester;
} catch (Exception e) {}
try {
tester = new rtlsdrDevice (220000000, 90, true);
return tester;
} catch (Exception e) {}
return new nullDevice ();
}
}

Binary file not shown.

View File

@@ -63,13 +63,11 @@ public class airspyDevice implements Device {
public airspyDevice (int frequency,
int gain,
boolean autogain) throws Exception {
System. out. println ("going to load airspy library");
handle = 0;
try {
System. load ("/usr/local/lib/libairspy-wrapper.so");
handle = airspyInit (frequency, gain, autogain);
} catch (Exception e) {}
System. out. println ("airspy returns with " + handle);
if (handle == 0)
throw (new Exception ());
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 650 KiB

After

Width:  |  Height:  |  Size: 552 KiB

View File

@@ -1,23 +1,20 @@
package package_Controller;
import javax. swing. JTable;
import javax. swing. JSlider;
import java.awt.event.*;
import java. util. *;
import java. util. Timer;
import java. util. TimerTask;
import utils.*;
import javax.swing.event.*;
import package_Model.*;
import package_View.*;
public class RadioController implements HelloListener {
public class RadioController implements modelSignals, viewSignals {
// The Controller needs to interact with both the Model and View.
// It "listens" to signals from both and it issues commands to both
private final RadioModel m_model;
private final RadioView m_view;
private List<ProgramData> services = new ArrayList<ProgramData>();
private final List<ProgramData> services = new ArrayList<>();
private int channelNumber;
private final Timer timer;
private TimerTask timerTask;
@@ -27,23 +24,41 @@ public class RadioController implements HelloListener {
private final Textmappers textMapper;
private boolean scanning;
private int serviceCount;
private Properties savedValues;
private int theGain;
//========================================================== constructor
/** Constructor
* @param model
* @param view
* @param band */
public RadioController (RadioModel model,
RadioView view, String band) {
m_model = model;
m_view = view;
* @param savedValues */
public RadioController (RadioModel model,
RadioView view,
Properties savedValues) {
m_model = model;
m_view = view;
this. savedValues = savedValues;
String band = "Band III";
try {
band = savedValues. getProperty ("dabBand", band);
} catch (Exception e) {}
my_bandHandler = new BandHandler (band);
textMapper = new Textmappers ();
channelNumber = 0;
scanning = true;
serviceCount = 0;
timer = new Timer ();
m_model. addServicesListener (this);
}
public void startRadio () {
m_model. addServiceListener (this);
m_view. addServiceListener (this);
String gv;
gv = savedValues. getProperty ("gainValue", "40");
theGain = Integer.parseInt (gv);
m_view. setDeviceGain (theGain);
m_model. setDeviceGain (theGain);
timerTask = new TimerTask () {
@Override
public void run () {
@@ -54,11 +69,6 @@ public class RadioController implements HelloListener {
int tunedFrequency = my_bandHandler. Frequency (channelNumber);
m_model. selectChannel (tunedFrequency, true);
m_view. showScanning (my_bandHandler. channel (channelNumber));
m_view. addGainSliderListener (new ChangeListener () {
public void stateChanged (ChangeEvent evt) {
gainSliderStateChange (evt);
}
});
}
@Override
@@ -71,7 +81,6 @@ public class RadioController implements HelloListener {
m_model. stopChannel ();
channelNumber ++;
if (channelNumber >= my_bandHandler. numberofItems ()) {
System. out. println ("End of trail");
readytoGo ();
return;
}
@@ -85,7 +94,7 @@ public class RadioController implements HelloListener {
int tunedFrequency = my_bandHandler. Frequency (channelNumber);
m_model. selectChannel (tunedFrequency, true);
m_view. showScanning (my_bandHandler. channel (channelNumber));
m_view. setEnsembleName (" ");
m_view. setEnsembleName (" ");
}
@Override
@@ -96,6 +105,7 @@ public class RadioController implements HelloListener {
m_view. newService (s1);
services. add (p);
serviceCount ++;
m_view. showServiceCount (serviceCount);
}
//
// As soon as scanning is complete, we allow selecting a service
@@ -105,35 +115,44 @@ public class RadioController implements HelloListener {
public void readytoGo () {
scanning = false;
m_view. addDeviceTableListener (new MouseAdapter() {
@Override
public void mouseClicked (MouseEvent evt) {
if (evt. getClickCount() > 0) {
int row = m_view. m_serviceTable. table. rowAtPoint (evt. getPoint ());
Object o = m_view. m_serviceTable. table. getValueAt (row, 0);
if (!(o instanceof String))
return;
int sdi = serviceIndex ((String)o);
if (sdi < 0) { // should not happen
System. out. println ("sorry. could not locate " + (String)o);
return;
}
if (javax. swing. SwingUtilities. isRightMouseButton (evt))
show_serviceData (sdi);
else
start_service (sdi);
}
}
});
m_view. showServiceEnabled (serviceCount);
}
@Override
public void tableSelect_withLeft (String serviceName) {
if (scanning)
return;
int sdi = serviceIndex (serviceName);
if (sdi < 0) { // should not happen
System. out. println ("sorry, could not locate " + serviceName);
return;
}
startService (sdi);
}
@Override
public void tableSelect_withRight (String serviceName) {
int sdi = serviceIndex (serviceName);
if (sdi < 0) { // should not happen
System. out. println ("sorry, could not locate " + serviceName);
return;
}
show_serviceData (sdi);
}
@Override
public void gainValue (int val) {
m_model. setDeviceGain (val);
savedValues. setProperty ("gainValue",
Integer. toString (val));
}
private void show_serviceData (int index) {
String serviceName = services. get (index). serviceName;
String channel = services. get (index). channel;
int startAddr = services. get (index). startAddr;
int length = services. get (index). length;
boolean shortForm = services. get (index). shortForm;
int bitRate = services. get (index). bitRate;
int protLevel = services. get (index). protLevel;
String programType = textMapper. getProgramType (
@@ -142,6 +161,7 @@ public class RadioController implements HelloListener {
channel,
startAddr,
length,
shortForm,
bitRate,
protLevel,
programType);
@@ -151,27 +171,28 @@ public class RadioController implements HelloListener {
// tuner is set to the right channel. If it is already, we are done,
// if not then we tune and wait a few moments before starting the
// service
private void start_service (int index) {
private void startService (int index) {
String channel = services. get (index). channel;
int frequency = my_bandHandler. Frequency (channel);
timerTask. cancel ();
if (channel. equals (currentChannel)) {
setService (services. get (index). serviceName);
setService (index);
}
else {
currentChannel = channel;
selectorTask = new TimerTask () {
private final String s = services. get (index). serviceName;
private final int ind = index;
@Override
public void run () {
setService (s);
setService (ind);
}
};
m_view. clear_dynamicLabel ();
m_view. showService ("tuning to channel " + channel);
m_model. selectChannel (frequency, false);
timer. schedule (selectorTask, 5 * 1000);
}
currentChannel = channel;
m_view. showSelectedChannel (currentChannel);
m_view. showService (services. get (index). serviceName);
}
@Override
@@ -214,8 +235,11 @@ public class RadioController implements HelloListener {
m_view. show_motHandling (flag);
}
public void setService (String s) {
m_model. setService (s);
public void setService (int index) {
String serviceName = services. get (index). serviceName;
m_view. showService (serviceName);
m_model. setService (serviceName);
show_serviceData (index);
}
public int serviceIndex (String service) {
@@ -224,13 +248,5 @@ public class RadioController implements HelloListener {
return i;
return -1;
}
private void gainSliderStateChange (ChangeEvent evt) {
int gainValue = ((JSlider)evt. getSource ()). getValue ();
System. out. println
("Value : " + ((JSlider)evt.getSource()).getValue());
m_model. setDeviceGain (gainValue);
m_view. showGain (gainValue);
}
}

Binary file not shown.

View File

@@ -5,12 +5,8 @@ package package_Model;
// It is fully unaware of the GUI. It sends signals to and
// receives commands from the Controller.
import java.awt.event.*;
import devices.*;
import java. util.*;
import java. util. Timer;
import java. util. TimerTask;
import utils.*;
public class RadioModel {
private static final String RADIO = "javaDab";
@@ -20,21 +16,17 @@ public class RadioModel {
private final ficHandler my_ficHandler;
private final PhaseReference my_phaseReference;
private final Reader my_Reader;
private DabBackend my_Backend;
private final DabBackend my_Backend;
private DabProcessor dabProcessor;
private List<HelloListener> listeners = new ArrayList<HelloListener>();
public void addServicesListener (HelloListener service) {
listeners. add (service);
private final List<modelSignals> listener = new ArrayList<>();
public void addServiceListener (modelSignals service) {
listener. add (service);
}
public RadioModel (int Mode) {
public RadioModel (int Mode, Device my_device) {
this. Mode = Mode;
my_device = bindDevice ();
if (my_device. is_nullDevice ()) {
System. out. println ("failure, have to quit");
System. exit (1);
}
this. my_device = my_device;
my_params = new DabParams (Mode);
my_Backend = new DabBackend (my_params, this);
@@ -67,25 +59,6 @@ public class RadioModel {
my_device. stopReader ();
}
//
private Device bindDevice () {
Device tester;
try {
tester = new airspyDevice (220000000, 90, true);
return tester;
} catch (Exception e) {}
try {
tester = new sdrplayDevice (220000000, 40, true);
return tester;
} catch (Exception e) {}
try {
tester = new rtlsdrDevice (220000000, 90, true);
return tester;
} catch (Exception e) {}
return new nullDevice ();
}
public void setDeviceGain (int gainValue) {
my_device. setGain (gainValue);
}
@@ -93,8 +66,8 @@ public class RadioModel {
// This one is called from within the dabProcessor
// in case no DAB signal is found
public void no_signal_found () {
listeners. forEach ((hl) -> {
hl. no_signal_found ();
listener. forEach ((hl) -> {
hl. no_signal_found ();
});
}
@@ -111,25 +84,25 @@ public class RadioModel {
dabProcessor. serviceData (s, p);
if (!p. defined)
return;
listeners.forEach((hl) -> {
listener.forEach((hl) -> {
hl. newService (s, p);
});
}
public void updateEnsembleLabel (String Name, int Sid) {
listeners.forEach((hl) -> {
listener. forEach((hl) -> {
hl. ensembleName (Name, Sid);
});
}
public void show_isStereo (byte b) {
listeners. forEach ((hl) -> {
listener. forEach ((hl) -> {
hl. show_isStereo (b != 0);
});
}
public void show_ficSuccess (int successRate) {
listeners. forEach ((hl) -> {
listener. forEach ((hl) -> {
hl. show_ficSuccess (successRate);
});
}
@@ -138,25 +111,25 @@ public class RadioModel {
}
public void show_Sync (boolean flag) {
listeners.forEach((hl) -> {
listener.forEach((hl) -> {
hl. show_Sync (flag);
});
}
public void show_picture (byte [] data, int subtype, String name) {
listeners.forEach((hl) -> {
listener.forEach((hl) -> {
hl. show_picture (data, subtype, name);
});
}
public void show_dynamicLabel (String s) {
listeners.forEach((hl) -> {
listener.forEach((hl) -> {
hl. show_dynamicLabel (s);
});
}
public void show_motHandling (boolean flag) {
listeners.forEach((hl) -> {
listener.forEach((hl) -> {
hl. show_motHandling (flag);
});
}

View File

@@ -2,9 +2,9 @@
package package_Model;
import utils.*;
public interface HelloListener {
public void newService (String s1, ProgramData p);
public void ensembleName (String s1, int s2);
public interface modelSignals {
public void newService (String s1, ProgramData p);
public void ensembleName (String s1, int s2);
public void no_signal_found ();
public void show_Sync (boolean flag);
public void show_isStereo (boolean b);

BIN
package_View/RadioView$1.class Executable file

Binary file not shown.

BIN
package_View/RadioView$2.class Executable file

Binary file not shown.

Binary file not shown.

View File

@@ -4,7 +4,7 @@ import javax.swing.*;
import java.awt.event.*;
import package_Model.*;
import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.*;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
@@ -14,8 +14,6 @@ import javax. swing. JSlider;
import java. awt. Dimension;
public class RadioView extends JFrame {
//... Constants
private static final String INITIAL_VALUE = "1";
//... Components
private final JLabel m_copyright = new JLabel ("Jan's Radio");
@@ -37,14 +35,18 @@ public class RadioView extends JFrame {
private final JLabel m_channelLabel = new JLabel (" ");
private final JLabel m_serviceCount = new JLabel (" ");
public serviceTable m_serviceTable = new serviceTable ();
private java.util.List<viewSignals> listeners = new ArrayList<>();
public void addServiceListener (viewSignals service) {
listeners. add (service);
}
//======================================================= constructor
/** Constructor
* @param model */
public RadioView (RadioModel model) {
//... Set up the logic
m_copyright. setToolTipText ("Copyright(s) 2018 Jan van Katwijk, \nLazy Chair Computing.");
m_selectedService. setToolTipText ("the name of the selected service");
m_copyright. setToolTipText ("CopyRight J van Katwijk, Lazy chair computing 2018");
m_timesync. setToolTipText ("Green indicates time sync OK");
m_stereo. setToolTipText ("Green indicates transmission is stereo");
@@ -134,8 +136,47 @@ public class RadioView extends JFrame {
this. setTitle("JavaRadio - MVC");
// The window closing event should probably be passed to the
// Controller in a real program, but this is a short example.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m_serviceTable. table. addMouseListener (new MouseAdapter() {
@Override
public void mouseClicked (MouseEvent evt) {
if (evt. getClickCount() > 0) {
int row = m_serviceTable. table. rowAtPoint (evt. getPoint ());
Object o = m_serviceTable. table. getValueAt (row, 0);
if (!(o instanceof String))
return;
if (!javax. swing. SwingUtilities. isRightMouseButton (evt))
tableSelect_withLeft ((String)o);
else
tableSelect_withRight ((String)o);
}
}
});
m_gainSlider.
addChangeListener (new ChangeListener() {
public void
stateChanged(javax. swing.event.ChangeEvent evt) {
int gainValue = ((JSlider)evt. getSource ()). getValue ();
m_gainLabel. setText (Integer. toString (gainValue));
listeners. forEach ((hl) -> {
hl. gainValue (gainValue);
});
}
});
}
private void tableSelect_withLeft (String name) {
listeners.forEach((hl) -> {
hl. tableSelect_withLeft (name);
});
}
private void tableSelect_withRight (String name) {
listeners.forEach((hl) -> {
hl. tableSelect_withRight (name);
});
}
public void set_qualityLabel (JLabel l, int v) {
if (v > 0) {
@@ -164,7 +205,6 @@ public class RadioView extends JFrame {
m_serviceTable. newService (name);
}
public void setEnsembleName (String s) {
m_ensembleName. setText (s);
}
@@ -248,26 +288,46 @@ public class RadioView extends JFrame {
m_selectedService. setText ("please choose a service");
m_selectedService. setBackground (Color. green);
m_selectedService. setOpaque (true);
m_serviceCount. setBackground (Color. green);
m_serviceCount. setOpaque (true);
m_serviceCount. setText (Integer. toString (numofServices));
showServiceCount (numofServices);
}
public void showProgramdata (String serviceName,
String channel,
int startAddr,
int length,
int bitRate,
int protLevel,
String programType) {
JFrame notifier= new JFrame (serviceName);
public void showServiceCount (int numofServices) {
m_serviceCount. setBackground (Color. green);
m_serviceCount. setOpaque (true);
m_serviceCount. setText (Integer. toString (numofServices));
}
JFrame notifier= new JFrame ();
public void showProgramdata (String serviceName,
String channel,
int startAddr,
int length,
boolean shortForm,
int bitRate,
int protLevel,
String programType) {
notifier. setPreferredSize (new Dimension (200, 200));
JPanel main = new JPanel ();
main. setLayout (new BoxLayout (main, BoxLayout. Y_AXIS));
notifier. setTitle (serviceName);
JLabel Label_0 = new JLabel ("channel " + channel);
JLabel Label_1 = new JLabel ("startAddr " + startAddr);
JLabel Label_2 = new JLabel ("length " + length);
JLabel Label_3 = new JLabel ("bitRate " + bitRate);
JLabel Label_4 = new JLabel ("protection " + protLevel);
JLabel Label_1 = new JLabel ("startAddr " + startAddr);
JLabel Label_2 = new JLabel ("length " + length);
JLabel Label_3 = new JLabel ("bitRate " + bitRate);
String protL;
if (!shortForm) {
protL = "EEP ";
protL = protL + ((protLevel & 03) + 1);
if ((protLevel & (1 << 2)) == 0)
protL += "-A";
else
protL += "-B";
}
else {
protL = "UEP " + protLevel;
}
JLabel Label_4 = new JLabel ("protection " + protL);
JLabel Label_5 = new JLabel ("program type " + programType);
main. add (Label_0);
main. add (Label_1);
@@ -322,20 +382,19 @@ public class RadioView extends JFrame {
m_dynamicLabel. setText (s);
}
public void clear_dynamicLabel () {
String s = " ";
m_dynamicLabel. setText (s);
}
public void show_motHandling (boolean flag) {
m_motLabel. setOpaque (true);
m_motLabel. setBackground (flag ? Color. green : Color. red);
}
public void addDeviceTableListener (MouseAdapter ma) {
m_serviceTable. table. addMouseListener (ma);
}
public void addGainSliderListener (ChangeListener mc) {
m_gainSlider. addChangeListener (mc);
}
public void showGain (int gainValue) {
m_gainLabel. setText (Integer. toString (gainValue));
//
// Used to set the initial value
public void setDeviceGain (int v) {
m_gainSlider. setValue (v);
m_gainLabel. setText (Integer. toString (v));
}
}

Binary file not shown.

View File

@@ -23,7 +23,7 @@ public class serviceTable extends JFrame {
add = this. add (new JScrollPane(table));
this. setTitle ("DAB services");
this. setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
// this. setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this. setPreferredSize (new Dimension (100, 200));
this. pack();
this. setVisible (true);

BIN
package_View/viewSignals.class Executable file

Binary file not shown.

9
package_View/viewSignals.java Executable file
View File

@@ -0,0 +1,9 @@
package package_View;
public interface viewSignals {
public void tableSelect_withLeft (String s);
public void tableSelect_withRight (String s);
public void gainValue (int gainValue);
}