chod_01.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include <inttypes.h>
  5. #include "../../status.h"
  6. int init(void * param)
  7. {
  8. param = param;
  9. return 0;
  10. }
  11. typedef struct chod_01_t
  12. {
  13. uint8_t checksum __attribute__ ((packed));
  14. uint8_t event __attribute__ ((packed));
  15. uint8_t bi __attribute__ ((packed));
  16. uint8_t key __attribute__ ((packed));
  17. uint8_t status __attribute__ ((packed));
  18. uint16_t id __attribute__ ((packed));
  19. uint8_t retranslation __attribute__ ((packed));
  20. uint8_t separator __attribute__ ((packed));
  21. uint8_t year __attribute__ ((packed));
  22. uint8_t month __attribute__ ((packed));
  23. uint8_t day __attribute__ ((packed));
  24. uint8_t hour __attribute__ ((packed));
  25. uint8_t min __attribute__ ((packed));
  26. uint8_t sec __attribute__ ((packed));
  27. uint8_t delimiter __attribute__ ((packed));
  28. } chod_01_t;
  29. #define ONOFF 7
  30. #define ALARM 6
  31. #define CC 5
  32. #define ALT_ALARM 4
  33. #define BATT_FAULT 3
  34. #define CONN_LOST 2
  35. #define POWER_FAULT 1
  36. #define GEN_FAULT 0
  37. unsigned int process(unsigned char * data, unsigned int length, unsigned long long int * id, time_t * tm, unsigned int * status, unsigned char * result, unsigned int * pbb_status, unsigned int * data_type)
  38. {
  39. struct chod_01_t * chod_01;
  40. struct tm t;
  41. if (length != 16)
  42. {
  43. printf("Chod_01: Bad length %d\n", length);
  44. return 0;
  45. }
  46. chod_01 = (struct chod_01_t *)data;
  47. printf("Chod_01: status 0x%02X\n", chod_01->status);
  48. chod_01->id -= 0x2020;
  49. t.tm_year = chod_01->year - 0x30 + 100;
  50. t.tm_mon = chod_01->month - 0x30 - 1;
  51. t.tm_mday = chod_01->day - 0x30;
  52. t.tm_hour = chod_01->hour - 0x30;
  53. t.tm_min = chod_01->min - 0x30;
  54. t.tm_sec = chod_01->sec - 0x30;
  55. printf("Chod_01: %d, on %04d-%02d-%02d %02d:%02d:%02d\n", chod_01->id, t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
  56. *id = chod_01->id;
  57. *tm = mktime(&t);
  58. *status= chod_01->status;
  59. *pbb_status = PBB_OFF;
  60. *data_type = PBB_NONE;
  61. if ((chod_01->status & (1 << ONOFF)) || ((chod_01->status & (1 << ALARM)) && (chod_01->status & (1 << CC))))
  62. *pbb_status = PBB_ON;
  63. if (chod_01->status & 0x0F)
  64. *pbb_status = PBB_ERROR;
  65. sprintf(result, "'%d','%d','%d','%d'", chod_01->status, chod_01->bi, chod_01->key, chod_01->event);
  66. return 4;
  67. }