LCOV - code coverage report
Current view: top level - src/microsim/output - MSBatteryExport.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 38 38
Test Date: 2024-11-20 15:55:46 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MSBatteryExport.cpp
      15              : /// @author  Mario Krumnow
      16              : /// @author  Tamas Kurczveil
      17              : /// @author  Pablo Alvarez Lopez
      18              : /// @date    20-12-13
      19              : ///
      20              : // Realises dumping Battery Data
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <microsim/MSEdgeControl.h>
      25              : #include <microsim/MSEdge.h>
      26              : #include <microsim/MSLane.h>
      27              : #include <microsim/MSGlobals.h>
      28              : #include <utils/iodevices/OutputDevice.h>
      29              : #include <microsim/MSNet.h>
      30              : #include <microsim/MSVehicle.h>
      31              : #include <microsim/MSVehicleControl.h>
      32              : #include <microsim/devices/MSDevice_Battery.h>
      33              : #include "MSBatteryExport.h"
      34              : 
      35              : 
      36              : // ===========================================================================
      37              : // method definitions
      38              : // ===========================================================================
      39              : void
      40       126795 : MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
      41       126795 :     of.openTag(SUMO_TAG_TIMESTEP).writeAttr(SUMO_ATTR_TIME, time2string(timestep));
      42       126795 :     of.setPrecision(precision);
      43              : 
      44       126795 :     MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
      45              :     MSVehicleControl::constVehIt it = vc.loadedVehBegin();
      46              :     MSVehicleControl::constVehIt end = vc.loadedVehEnd();
      47       443822 :     for (; it != end; ++it) {
      48       317027 :         const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
      49              : 
      50       317027 :         if (!(veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())) {
      51         1278 :             continue;
      52              :         }
      53              : 
      54       315749 :         if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
      55       315749 :             MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
      56       315749 :             if (batteryToExport->getMaximumBatteryCapacity() > 0) {
      57              :                 // Open Row
      58       315749 :                 of.openTag(SUMO_TAG_VEHICLE);
      59              :                 // Write ID
      60              :                 of.writeAttr(SUMO_ATTR_ID, veh->getID());
      61              :                 // Write consum
      62       315749 :                 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
      63              :                 // Write total consumption
      64       315749 :                 of.writeAttr(SUMO_ATTR_TOTALENERGYCONSUMED, batteryToExport->getTotalConsumption());
      65              :                 // Write total regeneration
      66       315749 :                 of.writeAttr(SUMO_ATTR_TOTALENERGYREGENERATED, batteryToExport->getTotalRegenerated());
      67              :                 // Write Actual battery capacity
      68       315749 :                 of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, batteryToExport->getActualBatteryCapacity());
      69              :                 // Write Maximum battery capacity
      70       315749 :                 of.writeAttr(SUMO_ATTR_MAXIMUMBATTERYCAPACITY, batteryToExport->getMaximumBatteryCapacity());
      71              :                 // Write Charging Station ID
      72       315749 :                 of.writeAttr(SUMO_ATTR_CHARGINGSTATIONID, batteryToExport->getChargingStationID());
      73              :                 // Write Charge charged in the Battery
      74       315749 :                 of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
      75              :                 // Write ChargeInTransit
      76       315749 :                 if (batteryToExport->isChargingInTransit()) {
      77         2206 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDINTRANSIT, batteryToExport->getEnergyCharged());
      78              :                 } else {
      79       629292 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDINTRANSIT, 0.00);
      80              :                 }
      81              :                 // Write ChargingStopped
      82       315749 :                 if (batteryToExport->isChargingStopped()) {
      83        51024 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDSTOPPED, batteryToExport->getEnergyCharged());
      84              :                 } else {
      85       580474 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDSTOPPED, 0.00);
      86              :                 }
      87              :                 // Write Speed
      88       315749 :                 of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
      89              :                 // Write Acceleration
      90       315749 :                 of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration());
      91              : 
      92       315749 :                 Position pos = veh->getPosition();
      93       315749 :                 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
      94       315749 :                 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
      95              : 
      96              :                 // Write Lane ID / edge ID
      97       315749 :                 if (MSGlobals::gUseMesoSim) {
      98        66992 :                     of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
      99              :                 } else {
     100       248757 :                     of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
     101              :                 }
     102              :                 // Write vehicle position in the lane
     103       315749 :                 of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane());
     104              :                 // Write Time stopped (In all cases)
     105       315749 :                 of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
     106              :                 // Close Row
     107       631498 :                 of.closeTag();
     108              :             }
     109              :         }
     110              :     }
     111       126795 :     of.closeTag();
     112       126795 : }
        

Generated by: LCOV version 2.0-1