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-12-21 15:45:41 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       133585 : MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
      41       133585 :     of.openTag(SUMO_TAG_TIMESTEP).writeAttr(SUMO_ATTR_TIME, time2string(timestep));
      42       133585 :     of.setPrecision(precision);
      43              : 
      44       133585 :     MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
      45              :     MSVehicleControl::constVehIt it = vc.loadedVehBegin();
      46              :     MSVehicleControl::constVehIt end = vc.loadedVehEnd();
      47       460784 :     for (; it != end; ++it) {
      48       327199 :         const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
      49              : 
      50       327199 :         if (!(veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())) {
      51         1303 :             continue;
      52              :         }
      53              : 
      54       325896 :         if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
      55       325896 :             MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
      56       325896 :             if (batteryToExport->getMaximumBatteryCapacity() > 0) {
      57              :                 // Open Row
      58       325896 :                 of.openTag(SUMO_TAG_VEHICLE);
      59              :                 // Write ID
      60              :                 of.writeAttr(SUMO_ATTR_ID, veh->getID());
      61              :                 // Write consum
      62       325896 :                 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
      63              :                 // Write total consumption
      64       325896 :                 of.writeAttr(SUMO_ATTR_TOTALENERGYCONSUMED, batteryToExport->getTotalConsumption());
      65              :                 // Write total regeneration
      66       325896 :                 of.writeAttr(SUMO_ATTR_TOTALENERGYREGENERATED, batteryToExport->getTotalRegenerated());
      67              :                 // Write Actual battery capacity
      68       325896 :                 of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, batteryToExport->getActualBatteryCapacity());
      69              :                 // Write Maximum battery capacity
      70       325896 :                 of.writeAttr(SUMO_ATTR_MAXIMUMBATTERYCAPACITY, batteryToExport->getMaximumBatteryCapacity());
      71              :                 // Write Charging Station ID
      72       325896 :                 of.writeAttr(SUMO_ATTR_CHARGINGSTATIONID, batteryToExport->getChargingStationID());
      73              :                 // Write Charge charged in the Battery
      74       325896 :                 of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
      75              :                 // Write ChargeInTransit
      76       325896 :                 if (batteryToExport->isChargingInTransit()) {
      77         2214 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDINTRANSIT, batteryToExport->getEnergyCharged());
      78              :                 } else {
      79       649578 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDINTRANSIT, 0.00);
      80              :                 }
      81              :                 // Write ChargingStopped
      82       325896 :                 if (batteryToExport->isChargingStopped()) {
      83        55064 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDSTOPPED, batteryToExport->getEnergyCharged());
      84              :                 } else {
      85       596728 :                     of.writeAttr(SUMO_ATTR_ENERGYCHARGEDSTOPPED, 0.00);
      86              :                 }
      87              :                 // Write Speed
      88       325896 :                 of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
      89              :                 // Write Acceleration
      90       325896 :                 of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration());
      91              : 
      92       325896 :                 Position pos = veh->getPosition();
      93       325896 :                 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
      94       325896 :                 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
      95              : 
      96              :                 // Write Lane ID / edge ID
      97       325896 :                 if (MSGlobals::gUseMesoSim) {
      98        67602 :                     of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
      99              :                 } else {
     100       258294 :                     of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
     101              :                 }
     102              :                 // Write vehicle position in the lane
     103       325896 :                 of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane());
     104              :                 // Write Time stopped (In all cases)
     105       325896 :                 of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
     106              :                 // Close Row
     107       651792 :                 of.closeTag();
     108              :             }
     109              :         }
     110              :     }
     111       133585 :     of.closeTag();
     112       133585 : }
        

Generated by: LCOV version 2.0-1