- this.sendStopTransaction(commandPayload.transactionId, connector);
- }
- }
- return Constants.OCPP_RESPONSE_ACCEPTED;
- }
-
- async sendStartTransaction(connectorID, idTag) {
- try {
- const payload = {
- connectorId: connectorID,
- idTag,
- meterStart: 0,
- timestamp: new Date().toISOString(),
- };
- return await this.sendMessage(Utils.generateUUID(), payload, Constants.OCPP_JSON_CALL_MESSAGE, 'StartTransaction');
- } catch (error) {
- logger.error(this._basicFormatLog() + ' Send start transaction error: ' + error);
- this._resetTransactionOnConnector(connectorID);
- throw error;
- }
- }
- async sendStartTransactionWithTimeout(connectorID, idTag, timeout) {
- setTimeout(() => this.sendStartTransaction(connectorID, idTag), timeout);
- }
-
- async sendStopTransaction(transactionId, connectorID) {
- try {
- const payload = {
- transactionId,
- meterStop: 0,
- timestamp: new Date().toISOString(),
- };
- await this.sendMessage(Utils.generateUUID(), payload, Constants.OCPP_JSON_CALL_MESSAGE, 'StopTransaction');
- logger.info(this._basicFormatLog() + ' Transaction ' + this._connectors[connectorID].transactionId + ' STOPPED on ' + this._stationInfo.name + '#' + connectorID);
- this.sendStatusNotification(connectorID, 'Available');
- } catch (error) {
- logger.error(this._basicFormatLog() + ' Send stop transaction error: ' + error);
- throw error;
- } finally {
- this._resetTransactionOnConnector(connectorID);
- }
- }
-
- // eslint-disable-next-line class-methods-use-this
- async sendMeterValues(connectorID, interval, self) {
- try {
- const sampledValueLcl = {
- timestamp: new Date().toISOString(),
- };
- const meterValuesClone = Utils.cloneJSonDocument(self._getConnector(connectorID).MeterValues);
- if (Array.isArray(meterValuesClone)) {
- sampledValueLcl.sampledValue = meterValuesClone;
- } else {
- sampledValueLcl.sampledValue = [meterValuesClone];
- }
- for (let index = 0; index < sampledValueLcl.sampledValue.length; index++) {
- if (sampledValueLcl.sampledValue[index].measurand && sampledValueLcl.sampledValue[index].measurand === 'SoC') {
- sampledValueLcl.sampledValue[index].value = Utils.getRandomInt(100);
- if (sampledValueLcl.sampledValue[index].value > 100) {
- logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
- sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register' +
- ', value: ' + sampledValueLcl.sampledValue[index].value);
- }
- } else {
- // Persist previous value in connector
- const connector = self._connectors[connectorID];
- let consumption;
- consumption = Utils.getRandomInt(self._stationInfo.maxPower / 3600000 * interval);
- if (connector && connector.lastConsumptionValue >= 0) {
- connector.lastConsumptionValue += consumption;
- } else {
- connector.lastConsumptionValue = 0;
- }
- consumption = Math.round(connector.lastConsumptionValue * 3600 / interval);
- logger.info(self._basicFormatLog() + ' MeterValues: connectorID ' + connectorID + ', transaction ' + connector.transactionId + ', value ' + connector.lastConsumptionValue);
- sampledValueLcl.sampledValue[index].value = connector.lastConsumptionValue;
- if (sampledValueLcl.sampledValue[index].value > (self._stationInfo.maxPower * 3600 / interval) || sampledValueLcl.sampledValue[index].value < 500) {
- logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
- sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register' +
- ', value: ' + sampledValueLcl.sampledValue[index].value + '/' + (self._stationInfo.maxPower * 3600 / interval));
- }
- }