Skip to content

Internal Communication

vstarlinger edited this page Aug 28, 2017 · 2 revisions

The internal communication of the ground station is based on the Observer Pattern.

Class objects can register to receive updates from various components. In particular from the MailReceiver, SerialComm and MainController classes. Following the interfaces of these classes are described with examples of how to implement an observer.

MainController

To register for updates of the MailReceiver the following line of code must be called:

MainController.getInstance().addDataUpdateListener(new UpdateListener());

The parameter that is passed to the MailReceiver must implement the DataUpdateListener interface. Which has a update (MessageController msg, USOCEvent e) method and always requires a MessageController and a USOCEvent.

USOCEvent

USOCEvents are used to transfer information internally between classes. All Events that are used must extend USOCEvent. USOCEvent has only one required field which is the DataSource dataSource field. DataSource is an enum with the following values and defines where the event comes from. This is necessary in order for listeners to determine how they should handle the data.

public enum DataSource {
    SERIAL,
    MAIL,
    FILE,
    ALL;
}

Examples of how the DataUpdateListener update method can be implemented can be found in the controller classes for the GUI. Here the update method of the LogPanelController is shown:

    @Override
    public void updateData(MessageController msgController, USOCEvent ue) {
        if (ue instanceof MailEvent) {
            MailEvent e = (MailEvent) ue;
            String s = "";
            for (Address from : e.getFrom()) {
                s += "," + from.toString();
            }
            //Setting label texts
            iridiumLastFrom.setText(s.substring(1));
            iridiumLastSubject.setText(e.getSubject());
            iridiumLastFilename.setText(e.getFilename());
            iridiumLastTimestamp.setText(new Date(e.getTimeStampGmail()).toString());
            iridiumTextArea.setText(msgController.getData().toString());
        } else if (ue instanceof SerialEvent) {
            serialTextArea.setText(((SerialEvent)ue).getMsg());
        } else if (ue instanceof ErrorEvent) {
            if (DataSource.MAIL == ue.getDataSource()) {
                iridiumTextArea.setText(((ErrorEvent) ue).getErrorMessage());
            } else if (DataSource.SERIAL == ue.getDataSource()) {
                serialTextArea.setText(((ErrorEvent) ue).getErrorMessage());
            }
        } else {
            serialTextArea.setText(msgController.getData().toString());
            iridiumTextArea.setText(msgController.getData().toString());
        }
    }

MailReceiver

To register for updates of the MailReceiver the following line of code must be called:

MailReceiver.getInstance().addMailUpdateListener(new MailListener());

The parameter that is passed to the MailReceiver must implement the MailUpdateListener interface. Which has the following methods:

mailUpdated (MailEvent e)

This is called when a new Iridium message was received. A MailEvent contains the content of the mail as String as well as information about the mail itself (Sender, subject, time stamp, file name).

An example of how this can be used can be found in the MainController class:

        @Override
        public void mailUpdated(MailEvent e) {
            MainController.getInstance().getMessageController().addSBD340Message(e.getText());
            MainController.getInstance().updateListeners(e);
        }

error (String msg)

This is called if an error concerning the connection to the mail server occurred. The String msg contains a message describing the error.

An example of how this can be used can be found in the MainController class:

        @Override
        public void error(String msg) {
            MainController.getInstance().updateListeners(new ErrorEvent(msg, DataSource.MAIL));
            LogSaver.saveIridium(msg);
        }

SerialComm

To register for updates of the SerialComm the following line of code must be called:

SerialComm.getInstance().addSerialListener(new RXListener());

The parameter that is passed to the SerialComm must implement the SerialListener interface. Which has the following methods:

messageReceived (SerialEvent e)

This is called when a new message is received via the specified serial port. A SerialEvent contains the content of the message as String as well as information about the serial interface (port and time stamp).

An example of how this can be used can be found in the MainController class:

        @Override
        public void messageReceived(final SerialEvent e) {
            MainController.getInstance().getMessageController().addSBD340Message(e.getMsg());
            MainController.getInstance().updateListeners(e);
        }

error (String msg)

This is called if an error concerning the serial connection occurred. The String msg contains a message describing the error.

An example of how this can be used can be found in the MainController class:

        @Override
        public void error(String msg) {
            MainController.getInstance().updateListeners(new ErrorEvent(msg, DataSource.SERIAL));
            LogSaver.saveDownlink(msg, false);
        }

Clone this wiki locally