Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Logic to Generate timestamp from odeReceivedAt #77

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package us.dot.its.jpo.geojsonconverter.converter.bsm;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -34,7 +37,7 @@ public void init(ProcessorContext arg0) { }
/**
* Transform an ODE BSM POJO to Processed BSM POJO.
*
* @param rawKey - Void type because ODE topics have no specified key
* @param rawKey - Void type because ODE topics have no specified key
* @param rawBsm - The raw POJO
* @return A key value pair: the key a RsuLogKey containing the RSU IP address or the BSM log file name
*/
Expand Down Expand Up @@ -108,8 +111,11 @@ public ProcessedBsm<Point> createProcessedBsm(OdeBsmMetadata metadata, OdeBsmPay

processedBsmValidationMessages.add(object);
}

ZonedDateTime odeDate = Instant.parse(metadata.getOdeReceivedAt()).atZone(ZoneId.of("UTC"));

processedBsm.setValidationMessages(processedBsmValidationMessages);
processedBsm.setTimeStamp(ZonedDateTime.now(ZoneOffset.UTC));
processedBsm.setTimeStamp(generateOffsetUTCTimestamp(odeDate, payload.getBsm().getCoreData().getSecMark()));

return processedBsm;
}
Expand Down Expand Up @@ -154,4 +160,39 @@ public BsmFeature<Point> createBsmFeature(OdeBsmPayload payload) {

return new BsmFeature<Point>(null, bsmPoint, bsmProps);
}

public ZonedDateTime generateOffsetUTCTimestamp(ZonedDateTime odeReceivedAt, Integer secMark){
try {
if (secMark != null){
int millis = (int)(secMark % 1000);
int seconds = (int)(secMark / 1000);
ZonedDateTime date = odeReceivedAt;
if(secMark == 65535){

// Return UTC time zero if the Zoned Date time is marked as unknown, UTC time zero chosen so that a null value can represent an empty field in the BSM. But 65535, can represent an intentionally unidentified field.
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneId.of("UTC"));

}else{
// If we are within 10 seconds of the next minute, and the timeMark is a large number, it probably means that the time rolled over before reception.
// In this case, subtract a minute from the odeReceivedAt so that the true time represents the minute in the past.
if(odeReceivedAt.getSecond() < 10 && secMark > 50000){
date = date.minusMinutes(1);
}

date = date.withSecond(seconds);
date = date.withNano(0);
date = date.plus(millis, ChronoUnit.MILLIS);
return date;
}


} else {
return null;
}
} catch (Exception e) {
String errMsg = String.format("Failed to generateOffsetUTCTimestamp - BSMProcessedJsonConverter. Message: %s", e.getMessage());
logger.error(errMsg, e);
return null;
}
}
}
Loading