owlps/owlps-positioning/libowlps-positioning.cc

99 lines
1.9 KiB
C++

#include "libowlps-positioning.hh"
float round_float(float f, int n)
{
n = (int) pow((double) 10, (double) n) ;
float f_dec = modff(f, &f) ;
f_dec = floor(f_dec * n) / n ;
return f + f_dec ;
}
vector<string> explode(const string &input, const char &sep)
{
vector<string> vs;
string tmp;
unsigned int i;
for (i = 0 ; i < input.size() ; i++)
if (input[i] == sep)
{
vs.push_back(tmp);
tmp.clear();
}
else
{
tmp.push_back(input[i]);
}
vs.push_back(tmp);
tmp.clear();
return vs;
}
vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
{
unsigned int i = 0;
string tmp_field;
vector<string> ret;
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
i++;
}
ret.push_back(tmp_field);
tmp_field.clear();
i++; // go after the ';'
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
i++;
}
ret.push_back(tmp_field);
tmp_field.clear();
i++;
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
i++;
}
ret.push_back(tmp_field);
tmp_field.clear();
i++;
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
i++;
}
ret.push_back(tmp_field);
tmp_field.clear();
i++;
while (i <= buffer_in.size())
{
if ((buffer_in[i] == ';' || i == buffer_in.size()) && !tmp_field.empty()) // Si on est sur un séparateur et que la valeur lue n'est pas vide,
{
ret.push_back(tmp_field) ; // on met la valeur lue dans les valeurs de retour.
tmp_field.clear() ;
}
else // Si on n'est pas sur un séparateur,
tmp_field.push_back(buffer_in[i]) ; // on ajoute le caractère courant à la suite de la valeur lue.
i++ ;
}
return ret;
}
uint64_t timeval_to_ms(const struct timeval &d)
{
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
}