ITS
api.h
Go to the documentation of this file.
1 
5 #ifndef API
6 #define API
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <math.h>
11 #include <BIT_STRING.h>
12 #include <QDataStream>
13 #include <QIODevice>
14 
15 #include <constantes.h>
16 
17 #include <confuse.h>
18 
19 #include <QObject>
20 #include <QFile>
21 
22 #define EARTH_RADIUS 6378137
23 #define LAT2METER 111132
24 
25 #define NEW_LINE 16
26 #define OCTET 4
27 #define zeroPtOneMicroDegreeToMeter 0.0111178
28 
29 #define DEFAULT_VALUE_POSITION 0
30 
31 #define GPS_CONF_LATITUDE "Latitude"
32 #define GPS_CONF_LONGITUDE "Longitude"
33 #define GPS_CONF_ALTITUDE "Altitude"
34 #define GPS_CONF_HEADING "Heading"
35 #define GPS_CONF_SEMI_MAJOR_CONFIDENCE "Semi major confidence"
36 #define GPS_CONF_SEMI_MINOR_CONFIDENCE "Semi minor confidence"
37 #define GPS_CONF_SEMI_MAJOR_ORIENTATION "Semi major orientation"
38 #define GPS_CONF_SPEED "Speed"
39 #define GPS_CONF_TIMESTAMP "Timestamp"
40 
41 #define SWAP16(nb) (nb = (nb << 8) | (nb >> 8))
42 #define SWAP32(nb) (nb = ((nb & 0x000f) << 24) | \
43  ((nb & 0x00f0) << 16) | \
44  ((nb & 0x0f00) >> 8) | \
45  ((nb & 0xf000) >> 24))
46 #define SWAP64(nb) (nb = ((nb & 0x0000000f) << 56) | \
47  ((nb & 0x000000f0) << 48) | \
48  ((nb & 0x00000f00) << 40) | \
49  ((nb & 0x0000f000) << 32) | \
50  ((nb & 0x000f0000) >> 8) | \
51  ((nb & 0x00f00000) >> 24) | \
52  ((nb & 0x0f000000) >> 40) | \
53  ((nb & 0xf0000000) >> 56))
54 
55 //typedef quint8 BYTE;
56 
57 /*
58  * @brief empty_buffer Vide le buffer (utilisé par read_stdin()).
59  * @param stream Le buffer à vider.
60  */
61 //void empty_buffer(FILE *stream);
62 /*
63  * @brief read_stdin Version sécurisé de scanf.
64  * @param msg Le buffer où placer la lecture.
65  * @param length La taille que l'on souhaite lire.
66  * @param stream Le flux où lire (par défaut stdin).
67  * @return true si la lecture a pu se faire, false sinon.
68  */
69 //bool read_stdin(char *msg, int length, FILE* stream = stdin);
78 void format(unsigned char *msg, unsigned long v, int l);
87 unsigned long long int split(const unsigned char *msg, int begin, int end);
96 void split(const unsigned char *msg, int begin, int end, char *out);
97 
98 //QByteArray split(QByteArray src, int begin, int end);
99 /*
100  * @brief read_opts Lis les options présents dans une chaîne de caractères.
101  * @param msg La chaîne pù sont les options.
102  * @param nOptions Le nombre d'options à lire.
103  * @param opts Un tableau de booléens où seront placés les options.
104  */
105 //void read_opts(const unsigned char *msg, int nOptions, bool *opts);
106 /*
107  * @brief clear_string Vide une chaîne de caractères sur un certain nombre d'octets.
108  * @param s La chane à vider.
109  * @param n Le nombre d'octets à vider.
110  */
111 //void clear_string(char* s, int n);
118 void print_hexa(const unsigned char *msg, int l, FILE* stream = stdout);
119 
120 /*
121  * @brief hexa2bin Transforme un QByteArray hexadecimal en binaire
122  * @param src Le QByteArray en hexa
123  * @return Le QByteArray en binaire
124  */
125 //QByteArray hexa2bin(QByteArray src);
126 
127 //struct gpsPosition_t{
128 // qint32 _latitude;
129 // qint32 _longitude;
130 // qint32 _altitude;
131 // quint16 _heading;
132 // quint16 _semiMajorConfidence;
133 // quint16 _semiMinorConfidence;
134 // quint16 _semiMajorOrientation;
135 // quint16 _speed;
136 // quint64 _timestamp;
137 //};
138 
144 QString printBitString(BIT_STRING_t b);
145 
152 int validate_unsigned_int(cfg_t *cfg, cfg_opt_t *opt);
153 
161 BIT_STRING_t makeBitString(int nbits, cfg_t* cfg, const char* opt_name);
162 
168 quint64 circAtLat(long l);
169 
177 unsigned int diameter(long begin, long end, quint64 circ);
178 
187 double dist(qint32 x1, qint32 y1, qint32 x2, qint32 y2);
188 
205 double f(long x, long y, double lengthA, double lengthB, e_shape shape);
206 
220 int g(double dist_r, double dist_f, double dist_fr, int angleThreshold);
221 
222 #endif // API
int validate_unsigned_int(cfg_t *cfg, cfg_opt_t *opt)
validate_unsigned_int Check if an option is an unsigned int
Definition: api.cpp:186
unsigned long long int split(const unsigned char *msg, int begin, int end)
split Extract number from byte array.
Definition: api.cpp:47
double dist(qint32 x1, qint32 y1, qint32 x2, qint32 y2)
dist This function calculate the euclidian distance between two points ([x1, y1], [x2...
Definition: api.cpp:228
void print_hexa(const unsigned char *msg, int l, FILE *stream=stdout)
print_hexa Print a byte array.
Definition: api.cpp:89
QString printBitString(BIT_STRING_t b)
printBitString Print a BIT_STRING into a QString.
Definition: api.cpp:175
BIT_STRING_t makeBitString(int nbits, cfg_t *cfg, const char *opt_name)
makeBitString Generate a BIT_STRING from configuration.
Definition: api.cpp:198
Constantes used everywhere.
int g(double dist_r, double dist_f, double dist_fr, int angleThreshold)
g Compute the g function.
Definition: api.cpp:272
e_shape
The e_shape enum defines the shapes type.
Definition: constantes.h:54
quint64 circAtLat(long l)
circAtLat Compute the circumference at a latitude.
Definition: api.cpp:211
double f(long x, long y, double lengthA, double lengthB, e_shape shape)
f Compute the f function.
Definition: api.cpp:236
unsigned int diameter(long begin, long end, quint64 circ)
diameter Compute the distance between two point on the same latitude.
Definition: api.cpp:220
void format(unsigned char *msg, unsigned long v, int l)
format Format a number in byte array.
Definition: api.cpp:35