ibutton_key.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 name
  60. * @param key
  61. * @param name
  62. */
  63. void ibutton_key_set_name(iButtonKey* key, const char* name);
  64. /**
  65. * Get pointer to key name
  66. * @param key
  67. * @return const char*
  68. */
  69. const char* ibutton_key_get_name_p(iButtonKey* key);
  70. /**
  71. * Set key type
  72. * @param key
  73. * @param key_type
  74. */
  75. void ibutton_key_set_type(iButtonKey* key, iButtonKeyType key_type);
  76. /**
  77. * Get key type
  78. * @param key
  79. * @return iButtonKeyType
  80. */
  81. iButtonKeyType ibutton_key_get_type(iButtonKey* key);
  82. /**
  83. * Get type string from key type
  84. * @param key_type
  85. * @return const char*
  86. */
  87. const char* ibutton_key_get_string_by_type(iButtonKeyType key_type);
  88. /**
  89. * Get key type from string
  90. * @param type_string
  91. * @param key_type
  92. * @return bool
  93. */
  94. bool ibutton_key_get_type_by_string(const char* type_string, iButtonKeyType* key_type);
  95. /**
  96. * Get key data size from type
  97. * @param key_type
  98. * @return uint8_t
  99. */
  100. uint8_t ibutton_key_get_size_by_type(iButtonKeyType key_type);
  101. /**
  102. * Get max key size
  103. * @return uint8_t
  104. */
  105. uint8_t ibutton_key_get_max_size();
  106. /**
  107. * Check if CRC for onewire key is valid
  108. * @param key
  109. * @return true
  110. * @return false
  111. */
  112. bool ibutton_key_dallas_crc_is_valid(iButtonKey* key);
  113. /**
  114. * Check if onewire key is a DS1990 key
  115. * @param key
  116. * @return true
  117. * @return false
  118. */
  119. bool ibutton_key_dallas_is_1990_key(iButtonKey* key);
  120. #ifdef __cplusplus
  121. }
  122. #endif