proto.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. We avoid the subghz provided abstractions and put
  35. * the data in our simple abstraction: the RawSamples circular buffer. */
  36. void subghz_protocol_decoder_protoview_feed(void* context, bool level, uint32_t duration) {
  37. furi_assert(context);
  38. UNUSED(context);
  39. /* Add data to the circular buffer. */
  40. raw_samples_add(RawSamples, level, duration);
  41. // FURI_LOG_E(TAG, "FEED: %d %d", (int)level, (int)duration);
  42. return;
  43. }
  44. /* The only scope of this method is to avoid duplicated messages in the
  45. * Subghz history, which we don't use. */
  46. uint8_t subghz_protocol_decoder_protoview_get_hash_data(void* context) {
  47. furi_assert(context);
  48. return 123;
  49. }
  50. /* Not used. */
  51. bool subghz_protocol_decoder_protoview_serialize(
  52. void* context,
  53. FlipperFormat* flipper_format,
  54. SubGhzRadioPreset* preset)
  55. {
  56. UNUSED(context);
  57. UNUSED(flipper_format);
  58. UNUSED(preset);
  59. return false;
  60. }
  61. /* Not used. */
  62. bool subghz_protocol_decoder_protoview_deserialize(void* context, FlipperFormat* flipper_format)
  63. {
  64. UNUSED(context);
  65. UNUSED(flipper_format);
  66. return false;
  67. }
  68. void subhz_protocol_decoder_protoview_get_string(void* context, FuriString* output)
  69. {
  70. furi_assert(context);
  71. furi_string_cat_printf(output, "Protoview");
  72. }
  73. const SubGhzProtocolDecoder subghz_protocol_protoview_decoder = {
  74. .alloc = subghz_protocol_decoder_protoview_alloc,
  75. .free = subghz_protocol_decoder_protoview_free,
  76. .reset = subghz_protocol_decoder_protoview_reset,
  77. .feed = subghz_protocol_decoder_protoview_feed,
  78. .get_hash_data = subghz_protocol_decoder_protoview_get_hash_data,
  79. .serialize = subghz_protocol_decoder_protoview_serialize,
  80. .deserialize = subghz_protocol_decoder_protoview_deserialize,
  81. .get_string = subhz_protocol_decoder_protoview_get_string,
  82. };
  83. /* Well, we don't really target a specific protocol. So let's put flags
  84. * that make sense. */
  85. const SubGhzProtocol subghz_protocol_protoview = {
  86. .name = "Protoview",
  87. .type = SubGhzProtocolTypeStatic,
  88. .flag = SubGhzProtocolFlag_AM | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable,
  89. .decoder = &subghz_protocol_protoview_decoder,
  90. };
  91. /* Our table has just the single dummy protocol we defined for the
  92. * sake of data collection. */
  93. const SubGhzProtocol* protoview_protocol_registry_items[] = {
  94. &subghz_protocol_protoview,
  95. };
  96. const SubGhzProtocolRegistry protoview_protocol_registry = {
  97. .items = protoview_protocol_registry_items,
  98. .size = COUNT_OF(protoview_protocol_registry_items)
  99. };