Skip to content

Commit

Permalink
allow time and receiveTime to be optionally passed on raiseNewCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Dec 22, 2023
1 parent 734c0d9 commit 200e233
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface ConditionInfoOptions {
quality?: StatusCode | null;
severity?: UInt16 | null;
retain?: boolean | null;

time?: Date | null;
receiveTime?: Date | null;
}

export interface ConditionInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,14 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {

const branch = this.currentBranch();

const now = new Date();

const currentDefaultDate = new Date();
const time = conditionInfo.time || currentDefaultDate;
const receiveTime = conditionInfo.receiveTime || currentDefaultDate;
// install the eventTimestamp
// set the received Time
branch.setTime(now);
branch.setReceiveTime(now);
branch.setTime(time);
branch.setReceiveTime(receiveTime);

// note : in 1.04 LocalTime property is optional
if (Object.prototype.hasOwnProperty.call(this, "localTime")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ export function utest_condition(test: any): void {

it(
"should be possible to enable and disable a condition using the enable & disable methods" +
" ( as a client would do)",
" ( as a client would do)",
async () => {

try {
const namespace = addressSpace.getOwnNamespace();
const condition = namespace.instantiateCondition(myCustomConditionType, {
Expand Down Expand Up @@ -155,7 +154,6 @@ export function utest_condition(test: any): void {
conditionSource: null,
organizedBy: addressSpace.rootFolder.objects,
conditionOf: addressSpace.rootFolder.objects.server

});
});
it("writing to a master branch (branch0) variable should affect the underlying variable", () => {
Expand Down Expand Up @@ -239,7 +237,7 @@ export function utest_condition(test: any): void {
const condition = namespace.instantiateCondition(myCustomConditionType, {
browseName: "MyCustomCondition2C",
conditionSource: source,
organizedBy: addressSpace.rootFolder.objects,
organizedBy: addressSpace.rootFolder.objects
});

(condition as any).evaluateConditionsAfterEnabled = () => {
Expand All @@ -248,7 +246,7 @@ export function utest_condition(test: any): void {

condition.setEnabledState(true);
condition.getEnabledState().should.eql(true);
condition.getEnabledStateAsString().should.eql("Enabled");
condition.getEnabledStateAsString().should.eql("Enabled");
condition.currentBranch().getEnabledState().should.eql(true);
condition.currentBranch().getEnabledStateAsString().should.eql("Enabled");

Expand Down Expand Up @@ -647,6 +645,60 @@ export function utest_condition(test: any): void {
evtData2["quality"].value.should.eql(StatusCodes.Bad);
});

it("should be possible to pass time and receiveTime to raiseNewCondition", () => {
// in this test we call raiseNewCondition with a time and receiveTime
const namespace = addressSpace.getOwnNamespace();

const condition = namespace.instantiateCondition(myCustomConditionType, {
browseName: "MyCustomConditionABC",
conditionSource: source,
organizedBy: addressSpace.rootFolder.objects
});

(condition as any).evaluateConditionsAfterEnabled = () => {
/* empty */
};

condition.setEnabledState(true);

const spyOnEvent = sinon.spy();
condition.on("event", spyOnEvent);

const time = new Date(Date.UTC(1968, 11, 25)); // Christmas 1968
const receiveTime = new Date(Date.UTC(1969, 0, 1)); // New Year 1969

/* event should be raised when enable state is true */
condition.raiseNewCondition({
message: "Hello Message",
quality: StatusCodes.Good,
retain: true,
severity: 1235,
time,
receiveTime,
});
spyOnEvent.callCount.should.eql(1, "an event should have been raised to signal new Condition State");

condition.retain.readValue().statusCode.should.eql(StatusCodes.Good);
condition.retain.readValue().value.value.should.eql(true);

condition.time.readValue().statusCode.should.eql(StatusCodes.Good);
condition.time.readValue().value.value.should.eql(time);

condition.receiveTime.readValue().statusCode.should.eql(StatusCodes.Good);
condition.receiveTime.readValue().value.value.should.eql(receiveTime);

spyOnEvent.callCount.should.eql(1);

const evtData = spyOnEvent.getCall(0).args[0];
// xx console.log(" EVENT RECEIVED :", evtData.sourceName.readValue().value.value);
// xx console.log(" EVENT ID :", evtData.eventId.readValue().value.value.toString("hex"));

evtData["receiveTime"].value.should.eql(receiveTime, "the receiveTime should have been transmitted");
evtData["time"].value.should.eql(time, "");


});

describe("Condition Branches", () => {
it("should be possible to create several branches of a condition state", () => {
const namespace = addressSpace.getOwnNamespace();
Expand Down

0 comments on commit 200e233

Please sign in to comment.