ibutton_key.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @file ibutton_key.h
  3. *
  4. * iButton key data holder
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define IBUTTON_KEY_DATA_SIZE 8
  12. #define IBUTTON_KEY_NAME_SIZE 22
  13. typedef enum {
  14. iButtonKeyDS1990,
  15. iButtonKeyCyfral,
  16. iButtonKeyMetakom,
  17. } iButtonKeyType;
  18. typedef struct iButtonKey iButtonKey;
  19. /**
  20. * Allocate key
  21. * @return iButtonKey*
  22. */
  23. iButtonKey* ibutton_key_alloc();
  24. /**
  25. * Free key
  26. * @param key
  27. */
  28. void ibutton_key_free(iButtonKey* key);
  29. /**
  30. * Copy key
  31. * @param to
  32. * @param from
  33. */
  34. void ibutton_key_set(iButtonKey* to, const iButtonKey* from);
  35. /**
  36. * Set key data
  37. * @param key
  38. * @param data
  39. * @param data_count
  40. */
  41. void ibutton_key_set_data(iButtonKey* key, uint8_t* data, uint8_t data_count);
  42. /**
  43. * Clear key data
  44. * @param key
  45. */
  46. void ibutton_key_clear_data(iButtonKey* key);
  47. /**
  48. * Get pointer to key data
  49. * @param key
  50. * @return const uint8_t*
  51. */
  52. const uint8_t* ibutton_key_get_data_p(iButtonKey* key);
  53. /**
  54. * Get key data size
  55. * @param key
  56. * @return uint8_t
  57. */
  58. uint8_t ibutton_key_get_data_size(iButtonKey* key);
  59. /**
  60. * Set key type
  61. * @param key
  62. * @param key_type
  63. */
  64. void ibutton_key_set_type(iButtonKey* key, iButtonKeyType key_type);
  65. /**
  66. * Get key type
  67. * @param key
  68. * @return iButtonKeyType
  69. */
  70. iButtonKeyType ibutton_key_get_type(iButtonKey* key);
  71. /**
  72. * Get type string from key type
  73. * @param key_type
  74. * @return const char*
  75. */
  76. const char* ibutton_key_get_string_by_type(iButtonKeyType key_type);
  77. /**
  78. * Get key type from string
  79. * @param type_string
  80. * @param key_type
  81. * @return bool
  82. */
  83. bool ibutton_key_get_type_by_string(const char* type_string, iButtonKeyType* key_type);
  84. /**
  85. * Get key data size from type
  86. * @param key_type
  87. * @return uint8_t
  88. */
  89. uint8_t ibutton_key_get_size_by_type(iButtonKeyType key_type);
  90. /**
  91. * Get max key size
  92. * @return uint8_t
  93. */
  94. uint8_t ibutton_key_get_max_size();
  95. /**
  96. * Check if CRC for onewire key is valid
  97. * @param key
  98. * @return true
  99. * @return false
  100. */
  101. bool ibutton_key_dallas_crc_is_valid(iButtonKey* key);
  102. /**
  103. * Check if onewire key is a DS1990 key
  104. * @param key
  105. * @return true
  106. * @return false
  107. */
  108. bool ibutton_key_dallas_is_1990_key(iButtonKey* key);
  109. #ifdef __cplusplus
  110. }
  111. #endif