Skip to content

Commit

Permalink
updates for rx tim message processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael7371 committed Sep 26, 2023
1 parent acf570b commit 92cd295
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PayloadParser extends LogFileParser {

private static Logger logger = LoggerFactory.getLogger(PayloadParser.class);

private static final String BSM_START_FLAG = "0014"; // these bytes indicate
private static final String BSM_START_FLAG = "001f"; // these bytes indicate
// start of BSM payload
private static final int HEADER_MINIMUM_SIZE = 20; // WSMP headers are at
// least 20 bytes long
Expand Down Expand Up @@ -108,7 +108,6 @@ public void writeTo(OutputStream os) throws IOException {
public byte[] removeHeader(byte[] packet) {
String hexPacket = HexUtils.toHexString(packet);

logger.debug("RemoveHeader recordType: " + recordType);
int startIndex = hexPacket.indexOf(BSM_START_FLAG);
if (startIndex == 0) {
logger.debug("Message is raw BSM with no headers.");
Expand All @@ -121,6 +120,8 @@ public byte[] removeHeader(byte[] packet) {
} else {
// We likely found a message with a header, look past the first 20
// bytes for the start of the BSM
logger.debug("Found payload start at: " + startIndex);
logger.debug("Payload hex: " + hexPacket);
int trueStartIndex = HEADER_MINIMUM_SIZE
+ hexPacket.substring(HEADER_MINIMUM_SIZE, hexPacket.length()).indexOf(BSM_START_FLAG);
hexPacket = hexPacket.substring(trueStartIndex, hexPacket.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import us.dot.its.jpo.ode.model.OdeBsmMetadata.BsmSource;
import us.dot.its.jpo.ode.model.RxSource;

public class RxMsgFileParser extends LogFileParser {
Expand All @@ -46,40 +47,47 @@ public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws F
ParserStatus status;
try {
status = super.parseFile(bis, fileName);
logger.debug("RxMsgFileParser start");
if (status != ParserStatus.COMPLETE)
return status;

// parse rxSource
if (getStep() == 1) {
logger.debug("RxMsgFileParser step 1");
status = parseStep(bis, RX_SOURCE_LENGTH);
if (status != ParserStatus.COMPLETE)
return status;
try {
setRxSource(RxSource.values()[readBuffer[0]]);
setRxSource(readBuffer[0]);
} catch (Exception e) {
logger.debug("exception");
setRxSource(RxSource.UNKNOWN);
}
}

if (getStep() == 2) {
logger.debug("RxMsgFileParser step 2");
status = nextStep(bis, fileName, locationParser);
if (status != ParserStatus.COMPLETE)
return status;
}

if (getStep() == 3) {
logger.debug("RxMsgFileParser step 3");
status = nextStep(bis, fileName, timeParser);
if (status != ParserStatus.COMPLETE)
return status;
}

if (getStep() == 4) {
logger.debug("RxMsgFileParser step 4");
status = nextStep(bis, fileName, secResCodeParser);
if (status != ParserStatus.COMPLETE)
return status;
}

if (getStep() == 5) {
logger.debug("RxMsgFileParser step 5");
status = nextStep(bis, fileName, payloadParser);
if (status != ParserStatus.COMPLETE)
return status;
Expand All @@ -101,12 +109,19 @@ public RxSource getRxSource() {
}

public void setRxSource(RxSource rxSource) {
logger.debug("rxSourceOrdinal value: " + rxSource);
this.rxSource = rxSource;
}

public void setRxSource(int rxSourceOrdinal) {
try {
setRxSource(RxSource.values()[rxSourceOrdinal]);
if (rxSourceOrdinal != 10){
logger.debug("rxSourceOrdinal value: " + rxSourceOrdinal);
setRxSource(RxSource.values()[rxSourceOrdinal]);
} else {
logger.debug("Removing newline character");
setStep(1);
}
} catch (Exception e) {
logger.error("Invalid RxSource: {}. Valid values are {}: ",
rxSourceOrdinal, RxSource.values());
Expand Down

0 comments on commit 92cd295

Please sign in to comment.