7 while (c !=
'\n' && c != EOF)
14 char *returnPosition = NULL;
16 if(fgets(msg, length, stream) != NULL)
19 returnPosition = strchr(msg,
'\n');
21 if(returnPosition != NULL)
22 *returnPosition =
'\0';
35 void format(
unsigned char * msg,
unsigned long v,
int l)
41 msg[l - i] = v >> (8 * (i - 1));
42 v -= (v >> (8 * (i - 1))) << (8 * (i - 1));
47 unsigned long long int split(
const unsigned char *msg,
int begin,
int end)
49 unsigned long long int ret;
50 int i, offset_b = 8 - (begin % 8), offset_e = end % 8, and_b = (1 << offset_b) - 1,
51 and_e = ((1 << offset_e) - 1) << (8 - offset_e), l = (end - begin + 7) / 8,
54 ret = msg[start] & and_b;
56 for(i = 1 ; i < l ; i++)
59 ret += msg[i + start] & and_b;
63 ret += msg[i + start] & and_e;
68 void split(
const unsigned char *msg,
int begin,
int end,
char *out)
72 for(i = begin ; i < end ; i++)
73 out[i - begin] = msg[i];
76 void read_opts(
const unsigned char *msg,
int nOptions,
bool *opts)
80 for(i = 0 ; i < nOptions ; i++)
81 opts[i] = msg[(i / 8) + 1] & (1 << (7 - (i % 8)));
89 void print_hexa(
const unsigned char *msg,
int l, FILE *stream)
94 for(i = 0 ; i < l ; i++){
96 fprintf(stream,
"0%X", msg[i]);
98 fprintf(stream,
"%X", msg[i]);
99 if(!((i + 1) %
OCTET))
100 fprintf(stream,
" ");
102 fprintf(stream,
"\n");
109 QByteArray ret, hexByte;
110 QDataStream ds(&ret, QIODevice::WriteOnly);
114 for(i = 0 ; i < src.size() ; i += 2)
118 for(j = 0 ; j < 2 ; j++)
119 hexByte.append(src[i + j]);
120 hex = hexByte.toInt(NULL, 16);
127 QByteArray
split(QByteArray src,
int begin,
int end)
130 int i, n = end - begin;
132 for(i = 0 ; i < n ; i++)
133 ret += src[i + begin];
180 (b.
buf[i/8] & (1 << (((((i/8)+1)*8)-1)-i)))? s +=
"true, ":s +=
"false, ";
181 (b.
buf[i/8] & (1 << (((((i/8)+1)*8)-1)-i)))? s +=
"true":s +=
"false";
188 long value = cfg_opt_getnint(opt, cfg_opt_size(opt) - 1);
191 cfg_error(cfg,
"integer option '%s' must be positive in section '%s'",
192 opt->name, cfg->name);
201 bs.
size = (nbits + 7) / 8;
203 bs.
buf = (u_int8_t*) calloc(bs.
size, 1);
204 for(
int i=0; i<nbits; i++)
206 bs.
buf[i/8] |= cfg_getnbool(cfg, opt_name, i) << (7 - (i % 8));
213 int L = l / 10000000;
215 quint64 ret = 2 * M_PI * (cos(L / (180 / M_PI)) *
EARTH_RADIUS);
220 unsigned int diameter(
long begin,
long end, quint64 circ)
222 unsigned int tmp = abs(end - begin);
228 double dist(qint32 x1, qint32 y1, qint32 x2, qint32 y2)
233 return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
236 double f(
long x,
long y,
double lengthA,
double lengthB,
e_shape shape)
245 return 1-pow((x/lengthA),2)-pow((y/lengthA),2);
250 if(lengthA != 0 && lengthB != 0)
252 longueur = 1-pow((x/lengthA),2);
253 largeur = 1-pow((y/lengthB),2);
254 return longueur<largeur?longueur:largeur;
260 if(lengthA != 0 && lengthB != 0)
261 return 1-((x/lengthA)*(x/lengthA))-((y/lengthB)*(y/lengthB));
272 int g(
double dist_r,
double dist_f,
double dist_fr,
int angleThreshold)
274 double FSR = acos((pow(dist_r, 2) + pow(dist_f, 2) - pow(dist_fr, 2)) / (2*dist_r*dist_f));
Usefull functions and declarations.
void print_hexa(const unsigned char *msg, int l, FILE *stream)
print_hexa Print a byte array.
int validate_unsigned_int(cfg_t *cfg, cfg_opt_t *opt)
validate_unsigned_int Check if an option is an unsigned int
void read_opts(const unsigned char *msg, int nOptions, bool *opts)
unsigned long long int split(const unsigned char *msg, int begin, int end)
split Extract number from byte array.
QByteArray hexa2bin(QByteArray src)
QString printBitString(BIT_STRING_t b)
printBitString Print a BIT_STRING into a QString.
int g(double dist_r, double dist_f, double dist_fr, int angleThreshold)
g Compute the g function.
unsigned int diameter(long begin, long end, quint64 circ)
diameter Compute the distance between two point on the same latitude.
double dist(qint32 x1, qint32 y1, qint32 x2, qint32 y2)
dist This function calculate the euclidian distance between two points ([x1, y1], [x2...
double f(long x, long y, double lengthA, double lengthB, e_shape shape)
f Compute the f function.
void empty_buffer(FILE *stream)
void clear_string(char *s, int n)
e_shape
The e_shape enum defines the shapes type.
bool read_stdin(char *msg, int length, FILE *stream)
quint64 circAtLat(long l)
circAtLat Compute the circumference at a latitude.
#define itsGnDefaultMaxCommunicationRange
BIT_STRING_t makeBitString(int nbits, cfg_t *cfg, const char *opt_name)
makeBitString Generate a BIT_STRING from configuration.
void format(unsigned char *msg, unsigned long v, int l)
format Format a number in byte array.