Skip to content

Commit

Permalink
Update RealTimeTagDPManager for two timestamps
Browse files Browse the repository at this point in the history
This addition creates a ISO 8601 timestamps for
realtime data points and conforms to new
DataPoint constructors.
  • Loading branch information
it-hms committed Aug 9, 2024
1 parent b3b92b6 commit 293b0f6
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import com.hms_networks.americas.sc.extensions.datapoint.DataPointFloat;
import com.hms_networks.americas.sc.extensions.datapoint.DataPointString;
import com.hms_networks.americas.sc.extensions.logging.Logger;
import com.hms_networks.americas.sc.extensions.system.time.SCTimeUnit;
import com.hms_networks.americas.sc.extensions.system.time.SCTimeUtils;
import com.hms_networks.americas.sc.extensions.taginfo.TagInfo;
import com.hms_networks.americas.sc.extensions.taginfo.TagType;
import java.util.ArrayList;
import java.util.Date;

/**
* This class will hold a list of data points for each tag. One instance of the class is made per
Expand Down Expand Up @@ -103,26 +106,35 @@ public void recordCurentTagValue(TagInfo tag) {
TagType tagType = tag.getType();
String tagUnit = tag.getUnit();
int tagID = tag.getId();
final int millisecondsInSeconds = 1000;
String timeStampSeconds = String.valueOf(System.currentTimeMillis() / millisecondsInSeconds);
String timeStampSeconds =
String.valueOf(System.currentTimeMillis() / SCTimeUnit.SECONDS.toMillis(1));
String timestampIso8601 = "";
try {
timestampIso8601 = SCTimeUtils.getIso8601FormattedTimestampForDate(new Date());
} catch (Exception e) {
Logger.LOG_CRITICAL(
"Unable to populate ISO 8601 timestamp for tags due to unexpected Exception.", e);
}
DataPoint data = null;

if (tagControl != null) {
if (tagType == TagType.FLOAT) {
float val = (float) tagControl.getTagValueAsDouble();
data = new DataPointFloat(tagName, tagID, tagUnit, val, timeStampSeconds);
data = new DataPointFloat(tagName, tagID, tagUnit, val, timeStampSeconds, timestampIso8601);
} else if (tagType == TagType.INTEGER) {
int val = tagControl.getTagValueAsInt();
data = new DataPointFloat(tagName, tagID, tagUnit, val, timeStampSeconds);
data = new DataPointFloat(tagName, tagID, tagUnit, val, timeStampSeconds, timestampIso8601);
} else if (tagType == TagType.STRING) {
String val = tagControl.getTagValueAsString();
data = new DataPointString(tagName, tagID, tagUnit, val, timeStampSeconds);
data =
new DataPointString(tagName, tagID, tagUnit, val, timeStampSeconds, timestampIso8601);
} else if (tagType == TagType.BOOLEAN) {
boolean val = (tagControl.getTagValueAsLong() != 0);
data = new DataPointBoolean(tagName, tagID, tagUnit, val, timeStampSeconds);
data =
new DataPointBoolean(tagName, tagID, tagUnit, val, timeStampSeconds, timestampIso8601);
} else if (tagType == TagType.DWORD) {
long val = tagControl.getTagValueAsLong();
data = new DataPointDword(tagName, tagID, tagUnit, val, timeStampSeconds);
data = new DataPointDword(tagName, tagID, tagUnit, val, timeStampSeconds, timestampIso8601);
}
} else {
Logger.LOG_WARN(
Expand Down

0 comments on commit 293b0f6

Please sign in to comment.