Skip to content

Commit

Permalink
fix(opcua): set oibus timestamp when server timestamp is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Feb 14, 2025
1 parent 89a9892 commit 452beb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions backend/src/south/south-opcua/south-opcua.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,17 @@ describe('SouthOPCUA', () => {

it('should properly query items', async () => {
const read = jest.fn().mockReturnValue([
{ value: { value: 1, dataType: DataType.Float }, serverTimestamp: new Date(), statusCode: { value: 0 } },
{ value: { value: 2, dataType: DataType.Double }, serverTimestamp: new Date(), statusCode: { value: 0 } },
{ value: { value: 3, dataType: DataType.UInt16 }, serverTimestamp: new Date(), statusCode: { value: 0 } }
{
value: { value: 1, dataType: DataType.Float },
sourceTimestamp: new Date(testData.constants.dates.DATE_1),
statusCode: { value: 0 }
},
{
value: { value: 2, dataType: DataType.Double },
serverTimestamp: new Date(testData.constants.dates.DATE_2),
statusCode: { value: 0 }
},
{ value: { value: 3, dataType: DataType.UInt16 }, statusCode: { value: 0 } }
]);
(nodeOPCUAClient.OPCUAClient.createSession as jest.Mock).mockReturnValue({ read });
south.addContent = jest.fn();
Expand All @@ -650,15 +658,15 @@ describe('SouthOPCUA', () => {
content: [
{
pointId: expectedItemsToRead[0].name,
timestamp: testData.constants.dates.FAKE_NOW,
timestamp: testData.constants.dates.DATE_1,
data: {
value: '1',
quality: JSON.stringify({ value: 0 })
}
},
{
pointId: expectedItemsToRead[1].name,
timestamp: testData.constants.dates.FAKE_NOW,
timestamp: testData.constants.dates.DATE_2,
data: {
value: '2',
quality: JSON.stringify({ value: 0 })
Expand Down
3 changes: 2 additions & 1 deletion backend/src/south/south-opcua/south-opcua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,12 @@ export default class SouthOPCUA
);
}

const defaultTimestamp = DateTime.now().toUTC().toISO();
const values = dataValues.map((dataValue: DataValue, i) => {
const selectedTimestamp = dataValue.sourceTimestamp ?? dataValue.serverTimestamp;
return {
pointId: items[i].name,
timestamp: selectedTimestamp!.toISOString(),
timestamp: selectedTimestamp ? selectedTimestamp.toISOString() : defaultTimestamp,
data: {
value: this.parseOPCUAValue(items[i].name, dataValue.value),
quality: JSON.stringify(dataValue.statusCode)
Expand Down

0 comments on commit 452beb8

Please sign in to comment.