Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. //my structure
  2. typedef struct MyData_s
  3. {
  4.     uint8_t  SPP_buffer[BUF_SIZE];
  5.     uint8_t  UART_buffer[BUF_SIZE];
  6.     uint32_t SPP_len;
  7.     uint32_t UART_len;
  8.     uint8_t  SPP_got_packet;
  9.     uint8_t  UART_got_packet;
  10.     bool     SPP_conn; // TRUE: spp connected
  11. }MyData_t;
  12. MyData_t MyData;
  13.  
  14. // SPP callback
  15. static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
  16. {
  17.     ...
  18.     case ESP_SPP_CLOSE_EVT:
  19.         ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT"); // when client disconnects
  20.         MyData.SPP_conn = false;
  21.         break;
  22.        
  23.     case ESP_SPP_SRV_OPEN_EVT:
  24.         ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT"); // client connected
  25.         FlowMeterData.SPP_conn = true;
  26.         break;
  27.        
  28.     case ESP_SPP_DATA_IND_EVT:
  29.         ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT len=%d handle=%d", param->data_ind.len, param->data_ind.handle);
  30.         if (param->data_ind.len < 1023)
  31.         {
  32.             // this part tranferring data fom SPP to UART (at this stage only fills the proper buffer, later it will be handled)
  33.             memcpy(MyData.SPP_Buf,param->data_ind.data, (size_t)param->data_ind.len);
  34.             MyData.SPP_len = param->data_ind.len;
  35.             MyData.SPP_got_packet = true;
  36.            
  37.             // And this part works ONLY if I send something via SPP (I need independence sending)
  38.             if(MyData.UART_got_packet == true)
  39.             {
  40.                esp_spp_write(param->write.handle, MyData.UART_len, MyData.UART_buffer);
  41.                MyData.UART_got_packet = false;
  42.             }
  43.         }
  44.     ...
  45. }
  46.  
  47. // My function that should write data from UART to SPP outside spp callbacks
  48. void SPP_to_UART_write(esp_spp_cb_param_t param)
  49. {
  50.     esp_spp_write(param.write.handle, MyData.UART_len, MyData.UART_buffer);
  51. }
  52.  
  53. //Main
  54. void app_main()
  55. {
  56.     ...  
  57.     // maybe like this?
  58.     esp_spp_cb_param_t my_param;
  59.     my_param.write.handle = ???; // 129 ?
  60.    
  61.     SPP_to_UART_write(my_param)
  62.     ...
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement