Skip to content

Commit

Permalink
fix on data types
Browse files Browse the repository at this point in the history
  • Loading branch information
walterwootz committed Feb 16, 2024
1 parent 18b6da7 commit bd4f83b
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions lib/commonBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,13 @@ function parseMessage(message) {
parsedMessage = message.toString(16);
}
config.getLogger().debug(context, 'stringMessage: [%s] parsedMessage: [%s]', stringMessage, parsedMessage);
messageArray = [];
if (Array.isArray(parsedMessage)) {
messageArray = parsedMessage;
} else {
messageArray.push(parsedMessage);
}

/* istanbul ignore if */
if (parsedMessageError) {
config.getLogger().error(context, 'MEASURES-003: Impossible to handle malformed message: %s', message);
}
config.getLogger().debug(context, 'parserMessage array: %s', messageArray);
return messageArray;
return parsedMessage;
}

/**
Expand All @@ -95,20 +89,6 @@ function guessType(attribute, device) {
return constants.DEFAULT_ATTRIBUTE_TYPE;
}

function extractAttributes(device, current) {
const values = [];
for (const k in current) {
if (current.hasOwnProperty(k)) {
values.push({
name: k,
type: guessType(k, device),
value: current[k]
});
}
}
return values;
}

/* istanbul ignore next */
function sendConfigurationToDevice(device, apiKey, deviceId, results, callback) {
transportSelector.applyFunctionFromBinding([apiKey, deviceId, results], 'sendConfigurationToDevice', device.transport || config.getConfig().defaultTransport, callback);
Expand Down Expand Up @@ -158,7 +138,7 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
{
name: attribute,
type: messageType,
value: messageType === constants.OPCUA_NGSI_BINDING_STRING ? JSON.stringify(parsedMessage) : parsedMessage[0]
value: parsedMessage
}
];
config.getLogger().debug(context, 'values updates [%s]', JSON.stringify(values));
Expand Down Expand Up @@ -302,5 +282,4 @@ function opcuaMessageHandler(deviceId, mapping, variableValue, timestamp) {

exports.opcuaMessageHandler = opcuaMessageHandler;
exports.messageHandler = messageHandler;
exports.extractAttributes = extractAttributes;
exports.guessType = guessType;

0 comments on commit bd4f83b

Please sign in to comment.