rfid_key.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "rfid_key.h"
  2. #include <furi/check.h>
  3. #include <string.h>
  4. RfidKey::RfidKey() {
  5. clear();
  6. }
  7. RfidKey::~RfidKey() {
  8. }
  9. void RfidKey::set_type(LfrfidKeyType _type) {
  10. type = _type;
  11. }
  12. void RfidKey::set_data(const uint8_t* _data, const uint8_t _data_size) {
  13. furi_assert(_data_size <= data.size());
  14. for(uint8_t i = 0; i < _data_size; i++) {
  15. data[i] = _data[i];
  16. }
  17. }
  18. void RfidKey::set_name(const char* _name) {
  19. strlcpy(name, _name, get_name_length());
  20. }
  21. LfrfidKeyType RfidKey::get_type() {
  22. return type;
  23. }
  24. const uint8_t* RfidKey::get_data() {
  25. return &data[0];
  26. }
  27. const char* RfidKey::get_type_text() {
  28. return lfrfid_key_get_type_string(type);
  29. }
  30. const uint8_t RfidKey::get_type_data_count() {
  31. return lfrfid_key_get_type_data_count(type);
  32. }
  33. char* RfidKey::get_name() {
  34. return name;
  35. }
  36. uint8_t RfidKey::get_name_length() {
  37. return LFRFID_KEY_NAME_SIZE;
  38. }
  39. void RfidKey::clear() {
  40. set_name("");
  41. set_type(LfrfidKeyType::KeyEM4100);
  42. data.fill(0);
  43. }
  44. RfidKey& RfidKey::operator=(const RfidKey& rhs) {
  45. if(this == &rhs) return *this;
  46. set_type(rhs.type);
  47. set_name(rhs.name);
  48. set_data(&rhs.data[0], get_type_data_count());
  49. return *this;
  50. }