pocsag_pager_receiver.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include "../pocsag_pager_app_i.h"
  2. #include "../views/pocsag_pager_receiver.h"
  3. static const NotificationSequence subghs_sequence_rx = {
  4. &message_green_255,
  5. &message_vibro_on,
  6. &message_note_c6,
  7. &message_delay_50,
  8. &message_sound_off,
  9. &message_vibro_off,
  10. &message_delay_50,
  11. NULL,
  12. };
  13. static const NotificationSequence subghs_sequence_rx_locked = {
  14. &message_green_255,
  15. &message_display_backlight_on,
  16. &message_vibro_on,
  17. &message_note_c6,
  18. &message_delay_50,
  19. &message_sound_off,
  20. &message_vibro_off,
  21. &message_delay_500,
  22. &message_display_backlight_off,
  23. NULL,
  24. };
  25. static void pocsag_pager_scene_receiver_update_statusbar(void* context) {
  26. POCSAGPagerApp* app = context;
  27. FuriString* history_stat_str;
  28. history_stat_str = furi_string_alloc();
  29. if(!pcsg_history_get_text_space_left(app->txrx->history, history_stat_str)) {
  30. FuriString* frequency_str;
  31. FuriString* modulation_str;
  32. frequency_str = furi_string_alloc();
  33. modulation_str = furi_string_alloc();
  34. pcsg_get_frequency_modulation(app, frequency_str, modulation_str);
  35. pcsg_view_receiver_add_data_statusbar(
  36. app->pcsg_receiver,
  37. furi_string_get_cstr(frequency_str),
  38. furi_string_get_cstr(modulation_str),
  39. furi_string_get_cstr(history_stat_str));
  40. furi_string_free(frequency_str);
  41. furi_string_free(modulation_str);
  42. } else {
  43. pcsg_view_receiver_add_data_statusbar(
  44. app->pcsg_receiver, furi_string_get_cstr(history_stat_str), "", "");
  45. }
  46. furi_string_free(history_stat_str);
  47. }
  48. void pocsag_pager_scene_receiver_callback(PCSGCustomEvent event, void* context) {
  49. furi_assert(context);
  50. POCSAGPagerApp* app = context;
  51. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  52. }
  53. static void pocsag_pager_scene_receiver_add_to_history_callback(
  54. SubGhzReceiver* receiver,
  55. SubGhzProtocolDecoderBase* decoder_base,
  56. void* context) {
  57. furi_assert(context);
  58. POCSAGPagerApp* app = context;
  59. FuriString* str_buff;
  60. str_buff = furi_string_alloc();
  61. if(pcsg_history_add_to_history(app->txrx->history, decoder_base, app->txrx->preset) ==
  62. PCSGHistoryStateAddKeyNewDada) {
  63. furi_string_reset(str_buff);
  64. pcsg_history_get_text_item_menu(
  65. app->txrx->history, str_buff, pcsg_history_get_item(app->txrx->history) - 1);
  66. pcsg_view_receiver_add_item_to_menu(
  67. app->pcsg_receiver,
  68. furi_string_get_cstr(str_buff),
  69. pcsg_history_get_type_protocol(
  70. app->txrx->history, pcsg_history_get_item(app->txrx->history) - 1));
  71. pocsag_pager_scene_receiver_update_statusbar(app);
  72. notification_message(app->notifications, &sequence_blink_green_10);
  73. if(app->lock != PCSGLockOn) {
  74. notification_message(app->notifications, &subghs_sequence_rx);
  75. } else {
  76. notification_message(app->notifications, &subghs_sequence_rx_locked);
  77. }
  78. }
  79. subghz_receiver_reset(receiver);
  80. furi_string_free(str_buff);
  81. app->txrx->rx_key_state = PCSGRxKeyStateAddKey;
  82. }
  83. void pocsag_pager_scene_receiver_on_enter(void* context) {
  84. POCSAGPagerApp* app = context;
  85. FuriString* str_buff;
  86. str_buff = furi_string_alloc();
  87. if(app->txrx->rx_key_state == PCSGRxKeyStateIDLE) {
  88. pcsg_preset_init(app, "FM95", 439987500, NULL, 0);
  89. pcsg_history_reset(app->txrx->history);
  90. app->txrx->rx_key_state = PCSGRxKeyStateStart;
  91. }
  92. pcsg_view_receiver_set_lock(app->pcsg_receiver, app->lock);
  93. pcsg_view_receiver_set_ext_module_state(
  94. app->pcsg_receiver, radio_device_loader_is_external(app->txrx->radio_device));
  95. //Load history to receiver
  96. pcsg_view_receiver_exit(app->pcsg_receiver);
  97. for(uint8_t i = 0; i < pcsg_history_get_item(app->txrx->history); i++) {
  98. furi_string_reset(str_buff);
  99. pcsg_history_get_text_item_menu(app->txrx->history, str_buff, i);
  100. pcsg_view_receiver_add_item_to_menu(
  101. app->pcsg_receiver,
  102. furi_string_get_cstr(str_buff),
  103. pcsg_history_get_type_protocol(app->txrx->history, i));
  104. app->txrx->rx_key_state = PCSGRxKeyStateAddKey;
  105. }
  106. furi_string_free(str_buff);
  107. pocsag_pager_scene_receiver_update_statusbar(app);
  108. pcsg_view_receiver_set_callback(app->pcsg_receiver, pocsag_pager_scene_receiver_callback, app);
  109. subghz_receiver_set_rx_callback(
  110. app->txrx->receiver, pocsag_pager_scene_receiver_add_to_history_callback, app);
  111. if(app->txrx->txrx_state == PCSGTxRxStateRx) {
  112. pcsg_rx_end(app);
  113. };
  114. if((app->txrx->txrx_state == PCSGTxRxStateIDLE) ||
  115. (app->txrx->txrx_state == PCSGTxRxStateSleep)) {
  116. // Start RX
  117. pcsg_begin(
  118. app,
  119. subghz_setting_get_preset_data_by_name(
  120. app->setting, furi_string_get_cstr(app->txrx->preset->name)));
  121. pcsg_rx(app, app->txrx->preset->frequency);
  122. }
  123. pcsg_view_receiver_set_idx_menu(app->pcsg_receiver, app->txrx->idx_menu_chosen);
  124. view_dispatcher_switch_to_view(app->view_dispatcher, POCSAGPagerViewReceiver);
  125. }
  126. bool pocsag_pager_scene_receiver_on_event(void* context, SceneManagerEvent event) {
  127. POCSAGPagerApp* app = context;
  128. bool consumed = false;
  129. if(event.type == SceneManagerEventTypeCustom) {
  130. switch(event.event) {
  131. case PCSGCustomEventViewReceiverBack:
  132. // Stop CC1101 Rx
  133. if(app->txrx->txrx_state == PCSGTxRxStateRx) {
  134. pcsg_rx_end(app);
  135. pcsg_idle(app);
  136. };
  137. app->txrx->hopper_state = PCSGHopperStateOFF;
  138. app->txrx->idx_menu_chosen = 0;
  139. subghz_receiver_set_rx_callback(app->txrx->receiver, NULL, app);
  140. app->txrx->rx_key_state = PCSGRxKeyStateIDLE;
  141. pcsg_preset_init(app, "FM95", 439987500, NULL, 0);
  142. scene_manager_search_and_switch_to_previous_scene(
  143. app->scene_manager, POCSAGPagerSceneStart);
  144. consumed = true;
  145. break;
  146. case PCSGCustomEventViewReceiverOK:
  147. app->txrx->idx_menu_chosen = pcsg_view_receiver_get_idx_menu(app->pcsg_receiver);
  148. scene_manager_next_scene(app->scene_manager, POCSAGPagerSceneReceiverInfo);
  149. consumed = true;
  150. break;
  151. case PCSGCustomEventViewReceiverConfig:
  152. app->txrx->idx_menu_chosen = pcsg_view_receiver_get_idx_menu(app->pcsg_receiver);
  153. scene_manager_next_scene(app->scene_manager, POCSAGPagerSceneReceiverConfig);
  154. consumed = true;
  155. break;
  156. case PCSGCustomEventViewReceiverOffDisplay:
  157. notification_message(app->notifications, &sequence_display_backlight_off);
  158. consumed = true;
  159. break;
  160. case PCSGCustomEventViewReceiverUnlock:
  161. app->lock = PCSGLockOff;
  162. consumed = true;
  163. break;
  164. default:
  165. break;
  166. }
  167. } else if(event.type == SceneManagerEventTypeTick) {
  168. if(app->txrx->hopper_state != PCSGHopperStateOFF) {
  169. pcsg_hopper_update(app);
  170. pocsag_pager_scene_receiver_update_statusbar(app);
  171. }
  172. // Get current RSSI
  173. float rssi = subghz_devices_get_rssi(app->txrx->radio_device);
  174. pcsg_receiver_rssi(app->pcsg_receiver, rssi);
  175. if(app->txrx->txrx_state == PCSGTxRxStateRx) {
  176. notification_message(app->notifications, &sequence_blink_cyan_10);
  177. }
  178. }
  179. return consumed;
  180. }
  181. void pocsag_pager_scene_receiver_on_exit(void* context) {
  182. UNUSED(context);
  183. }