@citrineos/reporting
Version:
The reporting module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.
79 lines • 4.17 kB
JavaScript
;
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceModelService = void 0;
const base_1 = require("@citrineos/base");
class DeviceModelService {
constructor(deviceModelRepository) {
this._deviceModelRepository = deviceModelRepository;
}
/**
* Fetches the ItemsPerMessage attribute from the device model.
* Returns null if no such attribute exists.
* @param stationId Charging station identifier.
* @returns ItemsPerMessage as a number or null if no such attribute exists.
*/
getItemsPerMessageByComponentAndVariableInstanceAndStationId(componentName, variableInstance, stationId) {
return __awaiter(this, void 0, void 0, function* () {
const itemsPerMessageAttributes = yield this._deviceModelRepository.readAllByQuerystring({
stationId: stationId,
component_name: componentName,
variable_name: 'ItemsPerMessage',
variable_instance: variableInstance,
type: base_1.OCPP2_0_1.AttributeEnumType.Actual,
});
if (itemsPerMessageAttributes.length === 0) {
return null;
}
else {
// It is possible for itemsPerMessageAttributes.length > 1 if component instances or evses
// are associated with alternate options. That structure is not supported by this logic, and that
// structure is a violation of Part 2 - Specification of OCPP 2.0.1.
return Number(itemsPerMessageAttributes[0].value);
}
});
}
/**
* Fetches the BytesPerMessage attribute from the device model.
* Returns null if no such attribute exists.
* It is possible for there to be multiple BytesPerMessage attributes if component instances or evses
* are associated with alternate options. That structure is not supported by this logic, and that
* structure is a violation of Part 2 - Specification of OCPP 2.0.1.
* In that case, the first attribute will be returned.
* @param stationId Charging station identifier.
* @returns BytesPerMessage as a number or null if no such attribute exists.
*/
getBytesPerMessageByComponentAndVariableInstanceAndStationId(componentName, variableInstance, stationId) {
return __awaiter(this, void 0, void 0, function* () {
const bytesPerMessageAttributes = yield this._deviceModelRepository.readAllByQuerystring({
stationId: stationId,
component_name: componentName,
variable_name: 'BytesPerMessage',
variable_instance: variableInstance,
type: base_1.OCPP2_0_1.AttributeEnumType.Actual,
});
if (bytesPerMessageAttributes.length === 0) {
return null;
}
else {
// It is possible for bytesPerMessageAttributes.length > 1 if component instances or evses
// are associated with alternate options. That structure is not supported by this logic, and that
// structure is a violation of Part 2 - Specification of OCPP 2.0.1.
return Number(bytesPerMessageAttributes[0].value);
}
});
}
}
exports.DeviceModelService = DeviceModelService;
//# sourceMappingURL=services.js.map