sb.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <stdint.h>
  6. #include <syslog.h>
  7. #include <stdarg.h>
  8. #include "../../status.h"
  9. static uint8_t status = 0;
  10. int init(void * param)
  11. {
  12. return 0;
  13. }
  14. typedef struct sb_t
  15. {
  16. double lat, lon;
  17. unsigned long long imei;
  18. unsigned char status;
  19. } sb_t;
  20. unsigned int
  21. process(void *lib_data, int socket, unsigned char *data,
  22. unsigned int length, unsigned long long int *id, time_t * tm,
  23. double *result_array, uint64_t * sensors, unsigned int *type)
  24. {
  25. struct sb_t * sb;
  26. unsigned int ret;
  27. /*
  28. if (length != sizeof(sb_t))
  29. {
  30. printf("Sb: Bad length %d\n", length);
  31. return 0;
  32. }
  33. */
  34. ret = 0;
  35. if ((data != NULL) && (length != 0))
  36. {
  37. sb = (struct sb_t *) data;
  38. printf("SB: imei %llu, lat %lf, lon %lf, status %d\n", sb->imei, sb->lat, sb->lon, sb->status);
  39. *id = sb->imei;
  40. *tm = time(NULL);
  41. // *tm = localtime(&t);
  42. result_array[0] = sb->lat;
  43. result_array[1] = sb->lon;
  44. result_array[2] = 0.0;
  45. result_array[3] = 1.0;
  46. result_array[4] = 0;
  47. status = sb->status;
  48. sensors[0] = sensors[1] = sensors[2] = sensors[3] = sensors[4] = 0x10;
  49. *type = VALUES_TYPE_POS;
  50. ret = 5;
  51. }
  52. else
  53. {
  54. if (status == 3)
  55. {
  56. status = 0;
  57. result_array[0] = 1;
  58. sensors[0] = 250010000;
  59. *type = VALUES_TYPE_ALERT;
  60. ret = 1;
  61. }
  62. }
  63. return ret;
  64. }