ibutton_key.h 2.2 KB

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