kopia lustrzana https://github.com/sh123/codec2_talkie
Refactoring
rodzic
62e2f6b75d
commit
f819a8a4e7
|
@ -145,11 +145,10 @@ public class Aprs implements Protocol {
|
|||
protected void onReceiveData(String src, String dst, byte[] data) {
|
||||
if (data.length == 0) return;
|
||||
AprsDataType dataType = new AprsDataType((char)data[0]);
|
||||
AprsData aprsData = AprsDataFactory.fromBinary(dst, data);
|
||||
AprsData aprsData = AprsDataFactory.fromBinary(src, dst, data);
|
||||
if (aprsData != null && aprsData.isValid()) {
|
||||
if (dataType.isTextMessage()) {
|
||||
TextMessage textMessage = aprsData.toTextMessage();
|
||||
textMessage.src = src;
|
||||
_parentProtocolCallback.onReceiveTextMessage(textMessage);
|
||||
return;
|
||||
} else if (dataType.isPositionReport()) {
|
||||
|
|
|
@ -8,7 +8,7 @@ public interface AprsData {
|
|||
void fromTextMessage(TextMessage textMessage);
|
||||
Position toPosition();
|
||||
TextMessage toTextMessage();
|
||||
void fromBinary(String dstCallsign, byte[] infoData);
|
||||
void fromBinary(String srcCallsign, String dstCallsign, byte[] infoData);
|
||||
byte[] toBinary();
|
||||
boolean isValid();
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ public class AprsDataFactory {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static AprsData fromBinary(String dstCallsign, byte[] infoData) {
|
||||
public static AprsData fromBinary(String srcCallsign, String dstCallsign, byte[] infoData) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(infoData);
|
||||
AprsDataType dataType = new AprsDataType((char)buffer.get());
|
||||
AprsData aprsData = create(dataType);
|
||||
if (aprsData == null) return null;
|
||||
byte[] data = new byte[buffer.remaining()];
|
||||
buffer.get(data);
|
||||
aprsData.fromBinary(dstCallsign, data);
|
||||
aprsData.fromBinary(srcCallsign, dstCallsign, data);
|
||||
return aprsData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,11 @@ public class AprsDataPositionReport implements AprsData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fromBinary(String dstCallsign, byte[] infoData) {
|
||||
public void fromBinary(String srcCallsign, String dstCallsign, byte[] infoData) {
|
||||
_isValid = false;
|
||||
_position = new Position();
|
||||
_position.srcCallsign = srcCallsign;
|
||||
_position.dstCallsign = dstCallsign;
|
||||
if ((infoData[0] == '/' || infoData[0] == '\\') && fromCompressedBinary(infoData)) {
|
||||
_position.isCompressed = true;
|
||||
_isValid = true;
|
||||
|
|
|
@ -85,16 +85,29 @@ public class AprsDataPositionReportMicE implements AprsData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fromBinary(String dstCallsign, byte[] infoData) {
|
||||
public void fromBinary(String srcCallsign, String dstCallsign, byte[] infoData) {
|
||||
_isValid = false;
|
||||
// TODO, implement fromBinary, needs dst callsign
|
||||
// ByteBuffer buffer = ByteBuffer.wrap(infoData);
|
||||
_position = new Position();
|
||||
_position.srcCallsign = srcCallsign;
|
||||
_position.dstCallsign = dstCallsign;
|
||||
|
||||
// read latitude
|
||||
// read symbol table
|
||||
// _position.latitude =
|
||||
|
||||
// read mic-e message type
|
||||
// _position.status =
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(infoData);
|
||||
|
||||
// read longitude
|
||||
// read symbol
|
||||
// _position.longitude =
|
||||
|
||||
// read course/speed
|
||||
// read altitude (could be anywhere inside the comment)
|
||||
|
||||
// read symbol table
|
||||
// read symbol
|
||||
|
||||
// read comment until the end
|
||||
// _isValid = true;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.nio.ByteBuffer;
|
|||
|
||||
public class AprsDataTextMessage implements AprsData {
|
||||
|
||||
public String srcCallsign;
|
||||
public String dstCallsign;
|
||||
public String textMessage;
|
||||
|
||||
|
@ -32,20 +33,22 @@ public class AprsDataTextMessage implements AprsData {
|
|||
@Override
|
||||
public TextMessage toTextMessage() {
|
||||
TextMessage textMessage = new TextMessage();
|
||||
textMessage.src = this.srcCallsign;
|
||||
textMessage.dst = this.dstCallsign;
|
||||
textMessage.text = this.textMessage;
|
||||
return textMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBinary(String dstCallsign, byte[] infoData) {
|
||||
public void fromBinary(String srcCallsign, String dstCallsign, byte[] infoData) {
|
||||
_isValid = false;
|
||||
if (infoData.length < 10) return;
|
||||
this.srcCallsign = srcCallsign;
|
||||
ByteBuffer buffer = ByteBuffer.wrap(infoData);
|
||||
// callsign, trim ending spaces
|
||||
byte[] callsign = new byte[9];
|
||||
buffer.get(callsign);
|
||||
dstCallsign = new String(callsign).replaceAll("\\s+$", "");
|
||||
this.dstCallsign = new String(callsign).replaceAll("\\s+$", "");
|
||||
// ':' separator
|
||||
byte b = buffer.get();
|
||||
if (b != ':') return;
|
||||
|
|
Ładowanie…
Reference in New Issue