[Positioning] Read new timestamp format from CSV

This commit is contained in:
Matteo Cypriani 2011-03-16 11:33:55 +01:00
parent cbd2ba3ca1
commit 38769efbf0
5 changed files with 67 additions and 3 deletions

View File

@ -45,6 +45,50 @@ bool CSVFileReader::next_line()
}
bool CSVFileReader::read_timestamp(Timestamp &t)
{
string timestamp_str ;
uint_fast32_t time_s, time_ns ;
if (! read_field(timestamp_str))
return false ;
tokenizer<escaped_list_separator<char> >
tok(timestamp_str, escaped_list_separator<char>('\\', '.', '\"')) ;
tokenizer<escaped_list_separator<char> >::const_iterator
tok_iter = tok.begin() ;
if (tok_iter == tok.end())
return false ;
try
{
time_s = lexical_cast<uint_fast32_t>(*tok_iter) ;
}
catch (bad_lexical_cast &e)
{
print_error_cast() ;
return false ;
}
++tok_iter ;
if (tok_iter == tok.end())
return false ;
try
{
time_ns = lexical_cast<uint_fast32_t>(*tok_iter) ;
}
catch (bad_lexical_cast &e)
{
print_error_cast() ;
return false ;
}
t = Timestamp(time_s, time_ns) ;
return true ;
}
bool CSVFileReader::read_point3d(Point3D &p)
{
float coord[3] ;

View File

@ -4,6 +4,7 @@
class Point3D ;
#include "textfilereader.hh"
#include "timestamp.hh"
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
@ -36,6 +37,8 @@ public:
bool next_line(void) ;
/// Read the next field of the current line
template<class T> bool read_field(T &field) ;
/// Read the next field that should be a Timestamp
bool read_timestamp(Timestamp &t) ;
/// Read the next 3 fields that should form a Point3D
bool read_point3d(Point3D &p) ;
//@}

View File

@ -44,14 +44,14 @@ const Request& InputCSV::get_next_request()
current_request->set_mobile(&mobile) ;
// Read Timestamp field
uint64_t timestamp_ms ;
if (! file.read_field(timestamp_ms))
Timestamp timestamp ;
if (! file.read_timestamp(timestamp))
{
// Wrong number of fields: blank current request
current_request->clear() ;
return *current_request ;
}
current_request->set_time_sent(Timestamp(timestamp_ms)) ;
current_request->set_time_sent(timestamp) ;
// Read position fields
float pos[3] ;

View File

@ -19,6 +19,13 @@ Timestamp::Timestamp(const struct timespec &source)
}
Timestamp::Timestamp(const uint_fast32_t source_s,
const uint_fast32_t source_ns)
{
set(source_s, source_ns) ;
}
Timestamp::Timestamp(const uint64_t source)
{
set(source) ;
@ -41,6 +48,14 @@ inline void Timestamp::set(const struct timespec &source)
}
inline void Timestamp::set(const uint_fast32_t source_s,
const uint_fast32_t source_ns)
{
timestamp.tv_sec = source_s ;
timestamp.tv_nsec = source_ns ;
}
inline void Timestamp::set(const uint64_t source_ms)
{
timestamp.tv_sec = source_ms / 1000 ;

View File

@ -19,6 +19,7 @@ protected:
/** @name Internal accessors */
//@{
void set(const struct timespec &source) ;
void set(const uint_fast32_t source_s, const uint_fast32_t source_ns) ;
/// Initialises the Timestamp with a value in milliseconds (deprecated)
void set(const uint64_t source_ms) ;
//@}
@ -42,6 +43,7 @@ protected:
public:
Timestamp(void) ;
Timestamp(const struct timespec &source) ;
Timestamp(const uint_fast32_t source_s, const uint_fast32_t source_ns) ;
/// Constructs a Timsestamp from a value in milliseconds (deprecated)
Timestamp(const uint64_t source) ;
Timestamp(const Timestamp &source) ;