Skip to content

Commit

Permalink
Third party packets handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Jul 3, 2023
1 parent ef7f4a8 commit 2c7e3e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.TimerTask;

import com.radio.codec2talkie.R;
import com.radio.codec2talkie.protocol.aprs.tools.AprsIsData;
import com.radio.codec2talkie.protocol.message.TextMessage;
import com.radio.codec2talkie.storage.log.LogItem;
import com.radio.codec2talkie.storage.log.LogItemRepository;
Expand Down Expand Up @@ -375,17 +376,25 @@ protected void onProtocolTxError() {
}
};

void storeLogData(String logData, boolean isTransmit) {
// TODO, parse through aprs data
String[] callsignData = logData.split(">");
if (callsignData.length >= 2) {
private void storeLogData(String logData, boolean isTransmit) {
AprsIsData aprsIsData = AprsIsData.fromString(logData);
if (aprsIsData != null) {
LogItem logItem = new LogItem();
logItem.setTimestampEpoch(System.currentTimeMillis());
logItem.setSrcCallsign(callsignData[0]);
logItem.setLogLine(logData);
logItem.setIsTransmit(isTransmit);
logItem.setSrcCallsign(aprsIsData.src);
logItem.setLogLine(logData);
_logItemRepository.insertLogItem(logItem);
_stationItemRepository.upsertStationItem(logItem.toStationItem());
if (aprsIsData.hasThirdParty()) {
LogItem logItemThirdParty = new LogItem();
logItemThirdParty.setTimestampEpoch(System.currentTimeMillis());
logItemThirdParty.setIsTransmit(isTransmit);
logItemThirdParty.setSrcCallsign(aprsIsData.thirdParty.src);
logItemThirdParty.setLogLine(aprsIsData.thirdParty.convertToString(true));
_logItemRepository.insertLogItem(logItemThirdParty);
_stationItemRepository.upsertStationItem(logItemThirdParty.toStationItem());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void sendData(String src, String dst, String path, byte[] data) throws IO
if (_isSelfEnabled) {
AprsIsData aprsIsData = new AprsIsData(src, dst, path, new String(data));
synchronized (_toAprsIsQueue) {
String rawData = aprsIsData.toString() + "\n";
String rawData = aprsIsData.convertToString(false) + "\n";
_toAprsIsQueue.put(rawData.getBytes());
}
}
Expand All @@ -152,7 +152,7 @@ private boolean isEligibleForTxGate(AprsIsData aprsIsData) {
private byte[] thirdPartyWrap(AprsIsData aprsIsData) {
// wrap into third party, https://aprs-is.net/IGateDetails.aspx
aprsIsData.digipath = "TCPIP," + _callsign + "*";
String txData = "}" + aprsIsData.toString();
String txData = "}" + aprsIsData.convertToString(false);
return txData.getBytes();
}

Expand Down Expand Up @@ -208,7 +208,7 @@ protected void onReceiveData(String src, String dst, String path, byte[] data) {
if (aprsIsData.hasThirdParty()) {
aprsIsData = aprsIsData.thirdParty;
}
String rawData = aprsIsData.toString() + "\n";
String rawData = aprsIsData.convertToString(false) + "\n";
synchronized (_toAprsIsQueue) {
_toAprsIsQueue.put(rawData.getBytes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public boolean hasThirdParty() {
}

@NonNull
public String toString() {
public String convertToString(boolean useRawPath) {
String result = src + ">";
if (dst != null && dst.length() > 0)
result += dst;
if (digipath != null && digipath.length() > 0)
if (useRawPath && rawDigipath != null && rawDigipath.length() > 0)
result += "," + rawDigipath;
else if (digipath != null && digipath.length() > 0)
result += "," + digipath;
result += ":" + data;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public void bind(long timestamp, String srcCallsign, String text, boolean isTran
DateTools.epochToIso8601(timestamp),
isTransmitting ? "→" : "←",
srcCallsign));
_logItemViewMessage.setText(TextTools.addZeroWidthSpaces(text));
if (text != null)
_logItemViewMessage.setText(TextTools.addZeroWidthSpaces(text));
}

static LogItemHolder create(ViewGroup parent, boolean isClickable) {
Expand Down

0 comments on commit 2c7e3e8

Please sign in to comment.