90762c24242cd9e419faec3eda763b2df2c6d410
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / Soft / Lib / utils / ardrone_gen_ids.c
1 #include <utils/ardrone_gen_ids.h>
2 #include <utils/ardrone_crc_32.h>
3 #include <string.h>
4 #include <stdio.h>
5
6 #include <stdlib.h>
7 #include <time.h>
8
9 void
10 ardrone_gen_appid (const char *appName, const char *sdkVersion, char appId [9], char *appDesc, int descLen)
11 {
12 #define _BUFFER_SIZE 512
13   char appNamePlusSdk [_BUFFER_SIZE] = {0};
14   snprintf (appNamePlusSdk, _BUFFER_SIZE, "%s:%s", appName, sdkVersion);
15 #undef _BUFFER_SIZE
16   uint32_t binaryId = ardrone_crc_32 ((uint8_t *)appNamePlusSdk, strlen (appNamePlusSdk));
17   snprintf (appId, 9, "%08x", binaryId);
18   appId [8] = '\0';
19   strncpy (appDesc, appName, descLen);
20 }
21
22 void
23 ardrone_gen_usrid (const char *usrName, char usrId [9], char *usrDesc, int descLen)
24 {
25   uint32_t binaryId = ardrone_crc_32 ((uint8_t *)usrName, strlen (usrName));
26   snprintf (usrId, 9, "%08x", binaryId);
27   usrId [8] = '\0';
28   strncpy (usrDesc, usrName, descLen);
29 }
30
31 void
32 ardrone_gen_sessionid (char sessId [9], char *sessDesc, int descLen)
33 {
34   static int runOnce = 1;
35   if (1 == runOnce)
36     {
37       srand (time (NULL));
38       runOnce = 0;
39     }
40   uint32_t binaryId = (uint32_t)rand ();
41   binaryId = (0 != binaryId) ? binaryId : 1u;
42   snprintf (sessId, 9, "%08x", binaryId);
43   sessId [8] = '\0';
44   snprintf (sessDesc, descLen, "Session %s", sessId);
45 }