Skip to content

Commit

Permalink
Handle auto reply messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Jul 16, 2023
1 parent 1edf1c4 commit 854bd62
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ protected void onReceiveTextMessage(TextMessage textMessage) {
String note = (textMessage.src == null ? "UNK" : textMessage.src) + "→" +
(textMessage.dst == null ? "UNK" : textMessage.dst);
sendStatusUpdate(AppMessage.EV_TEXT_MESSAGE_RECEIVED, note + ": " + textMessage.text);
_messageItemRepository.insertMessageItem(textMessage.toMessageItem(false));
if (textMessage.isAutoReply()) {
// TODO, acknowledge or reject message with the given (src, dst, ackId)
} else {
_messageItemRepository.insertMessageItem(textMessage.toMessageItem(false));
}
Log.i(TAG, "message received: " + textMessage.text);
}

Expand Down Expand Up @@ -342,7 +346,9 @@ protected void onTransmitTextMessage(TextMessage textMessage) {
String note = (textMessage.src == null ? "UNK" : textMessage.src) + "→" +
(textMessage.dst == null ? "UNK" : textMessage.dst);
sendStatusUpdate(AppMessage.EV_TEXT_MESSAGE_TRANSMITTED, note);
_messageItemRepository.insertMessageItem(textMessage.toMessageItem(true));
if (!textMessage.isAutoReply()) {
_messageItemRepository.insertMessageItem(textMessage.toMessageItem(true));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.radio.codec2talkie.storage.message.MessageItem;

import java.util.Locale;

public class TextMessage {
public String src;
public String dst;
Expand All @@ -21,4 +23,20 @@ public MessageItem toMessageItem(boolean isTransmit) {
messageItem.setRetryCnt(0);
return messageItem;
}

public boolean isAck() {
return this.text != null &&
this.text.toLowerCase(Locale.ROOT).equals("ack") &&
this.ackId > 0;
}

public boolean isRej() {
return this.text != null &&
this.text.toLowerCase(Locale.ROOT).equals("rej") &&
this.ackId > 0;
}

public boolean isAutoReply() {
return isAck() || isRej();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.concurrent.Executors;

@androidx.room.Database(
version = 12,
version = 13,
entities = {LogItem.class, MessageItem.class, PositionItem.class, StationItem.class},
exportSchema = false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import androidx.room.Index;
import androidx.room.PrimaryKey;

@Entity(indices = {@Index(value = {"id", "srcCallsign", "ackId"}, unique = true)})
@Entity(indices = {@Index(value = {"id", "srcCallsign", "dstCallsign", "ackId"}, unique = true)})
public class MessageItem {

@PrimaryKey(autoGenerate = true)
Expand Down

0 comments on commit 854bd62

Please sign in to comment.