uhf_data.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <furi.h>
  2. #include "uhf_data.h"
  3. // #include "uhf_cmd.h"
  4. UHFData* uhf_data_alloc() {
  5. UHFData* uhf_data = (UHFData*)malloc(sizeof(UHFData));
  6. uhf_data->length = 0;
  7. uhf_data->start = false;
  8. uhf_data->end = false;
  9. uhf_data->next = NULL;
  10. return uhf_data;
  11. }
  12. int uhf_data_append(UHFData* uhf_data, uint8_t data) {
  13. if(data == 0xBB) {
  14. uhf_data->start = true;
  15. }
  16. if(!uhf_data->start) return 0;
  17. if(uhf_data->end) return 0;
  18. if(uhf_data->length >= MAX_DATA_SIZE) return 0;
  19. if(data == 0x7E) {
  20. uhf_data->end = true;
  21. }
  22. uhf_data->data[uhf_data->length++] = data;
  23. return 1;
  24. }
  25. void uhf_data_reset(UHFData* uhf_data) {
  26. for(size_t i = 0; i < uhf_data->length; i++) {
  27. uhf_data->data[i] = 0x00;
  28. }
  29. uhf_data->start = false;
  30. uhf_data->end = false;
  31. uhf_data->length = 0;
  32. }
  33. void uhf_data_free(UHFData* uhf_data) {
  34. if(uhf_data != NULL) {
  35. while(uhf_data != NULL) {
  36. UHFData* next = uhf_data->next;
  37. free(uhf_data);
  38. uhf_data = next;
  39. }
  40. }
  41. }
  42. UHFResponseData* uhf_response_data_alloc() {
  43. UHFResponseData* uhf_response_data = (UHFResponseData*)malloc(sizeof(UHFResponseData));
  44. uhf_response_data->data = uhf_data_alloc();
  45. uhf_response_data->size = 0;
  46. return uhf_response_data;
  47. }
  48. UHFData* add_uhf_data_to_uhf_response_data(UHFResponseData* uhf_response_data) {
  49. UHFData* next = uhf_response_data->data;
  50. while(next->next != NULL) {
  51. next = next->next;
  52. }
  53. next->next = uhf_data_alloc();
  54. uhf_response_data->size++;
  55. return next->next;
  56. }
  57. void uhf_response_data_free(UHFResponseData* uhf_response_data) {
  58. uhf_data_free(uhf_response_data->data);
  59. free(uhf_response_data);
  60. }