CARLA
CarlaRecorderPlatformTime.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
8 #include "CarlaRecorder.h"
9 #include "CarlaRecorderHelpers.h"
10 
12 {
13  RecorderStartTime = std::chrono::system_clock::now();
14 }
16 {
17  auto CurrentTime = std::chrono::system_clock::now();
18  auto diff = std::chrono::duration_cast<std::chrono::microseconds>
19  (CurrentTime-RecorderStartTime).count();
20  Time = diff/1000000.0;
21 }
22 
23 void CarlaRecorderPlatformTime::Read(std::istream &InFile)
24 {
25  ReadValue<double>(InFile, this->Time);
26 }
27 
28 void CarlaRecorderPlatformTime::Write(std::ostream &OutFile)
29 {
30  // write the packet id
31  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::PlatformTime));
32 
33  // write packet size
34  uint32_t Total = sizeof(double);
35  WriteValue<uint32_t>(OutFile, Total);
36 
37  WriteValue<double>(OutFile, this->Time);
38 }
std::chrono::time_point< std::chrono::system_clock > RecorderStartTime
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)