proto.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <inttypes.h>
  2. #include <lib/flipper_format/flipper_format_i.h>
  3. #include <furi/core/string.h>
  4. #include <lib/subghz/registry.h>
  5. #include <lib/subghz/protocols/base.h>
  6. #include "app_buffer.h"
  7. #define TAG "PROTOVIEW-protocol"
  8. const SubGhzProtocol subghz_protocol_protoview;
  9. /* The feed() method puts data in the RawSamples global (protected by
  10. * a mutex). */
  11. extern RawSamplesBuffer *RawSamples;
  12. /* This is totally dummy: we just define the decoder base for the async
  13. * system to work but we don't really use it if not to collect raw
  14. * data via the feed() method. */
  15. typedef struct SubGhzProtocolDecoderprotoview {
  16. SubGhzProtocolDecoderBase base;
  17. } SubGhzProtocolDecoderprotoview;
  18. void* subghz_protocol_decoder_protoview_alloc(SubGhzEnvironment* environment) {
  19. UNUSED(environment);
  20. SubGhzProtocolDecoderprotoview* instance =
  21. malloc(sizeof(SubGhzProtocolDecoderprotoview));
  22. instance->base.protocol = &subghz_protocol_protoview;
  23. return instance;
  24. }
  25. void subghz_protocol_decoder_protoview_free(void* context) {
  26. furi_assert(context);
  27. SubGhzProtocolDecoderprotoview* instance = context;
  28. free(instance);
  29. }
  30. void subghz_protocol_decoder_protoview_reset(void* context) {
  31. furi_assert(context);
  32. }
  33. /* That's the only thig we really use of the protocol decoder
  34. * implementation. */
  35. void subghz_protocol_decoder_protoview_feed(void* context, bool level, uint32_t duration) {
  36. furi_assert(context);
  37. UNUSED(context);
  38. /* Add data to the circular buffer. */
  39. raw_samples_add(RawSamples, level, duration);
  40. // FURI_LOG_E(TAG, "FEED: %d %d", (int)level, (int)duration);
  41. return;
  42. }
  43. /* The only scope of this method is to avoid duplicated messages in the
  44. * Subghz history, which we don't use. */
  45. uint8_t subghz_protocol_decoder_protoview_get_hash_data(void* context) {
  46. furi_assert(context);
  47. return 123;
  48. }
  49. bool subghz_protocol_decoder_protoview_serialize(
  50. void* context,
  51. FlipperFormat* flipper_format,
  52. SubGhzRadioPreset* preset)
  53. {
  54. UNUSED(context);
  55. UNUSED(flipper_format);
  56. UNUSED(preset);
  57. return false;
  58. }
  59. bool subghz_protocol_decoder_protoview_deserialize(void* context, FlipperFormat* flipper_format)
  60. {
  61. UNUSED(context);
  62. UNUSED(flipper_format);
  63. return false;
  64. }
  65. void subhz_protocol_decoder_protoview_get_string(void* context, FuriString* output)
  66. {
  67. furi_assert(context);
  68. furi_string_cat_printf(output, "Protoview");
  69. }
  70. const SubGhzProtocolDecoder subghz_protocol_protoview_decoder = {
  71. .alloc = subghz_protocol_decoder_protoview_alloc,
  72. .free = subghz_protocol_decoder_protoview_free,
  73. .reset = subghz_protocol_decoder_protoview_reset,
  74. .feed = subghz_protocol_decoder_protoview_feed,
  75. .get_hash_data = subghz_protocol_decoder_protoview_get_hash_data,
  76. .serialize = subghz_protocol_decoder_protoview_serialize,
  77. .deserialize = subghz_protocol_decoder_protoview_deserialize,
  78. .get_string = subhz_protocol_decoder_protoview_get_string,
  79. };
  80. const SubGhzProtocol subghz_protocol_protoview = {
  81. .name = "Protoview",
  82. .type = SubGhzProtocolTypeStatic,
  83. .flag = SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
  84. .decoder = &subghz_protocol_protoview_decoder,
  85. };
  86. const SubGhzProtocol* protoview_protocol_registry_items[] = {
  87. &subghz_protocol_protoview,
  88. };
  89. const SubGhzProtocolRegistry protoview_protocol_registry = {
  90. .items = protoview_protocol_registry_items,
  91. .size = COUNT_OF(protoview_protocol_registry_items)
  92. };