|
@ -19,6 +19,7 @@ |
|
|
#define ble_uart_rx_size 128 |
|
|
#define ble_uart_rx_size 128 |
|
|
static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0}; |
|
|
static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0}; |
|
|
static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0}; |
|
|
static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0}; |
|
|
|
|
|
|
|
|
bleuart_t ble_uart_init_struct = { |
|
|
bleuart_t ble_uart_init_struct = { |
|
|
.txbuf = bluetooth_tx_buffer, |
|
|
.txbuf = bluetooth_tx_buffer, |
|
|
.txbufsize = sizeof(bluetooth_tx_buffer), |
|
|
.txbufsize = sizeof(bluetooth_tx_buffer), |
|
@ -32,7 +33,7 @@ bleuart_t ble_uart_init_struct = { |
|
|
motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; |
|
|
motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; |
|
|
|
|
|
|
|
|
void process_setPosition(cJSON *rxjson) { |
|
|
void process_setPosition(cJSON *rxjson) { |
|
|
// { "order": "setPosition", "index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } |
|
|
|
|
|
|
|
|
// { "order": "setPosition", "ble_uart_index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } |
|
|
int index = 0; |
|
|
int index = 0; |
|
|
int speedLevel = 0; |
|
|
int speedLevel = 0; |
|
|
float position = 0; |
|
|
float position = 0; |
|
@ -50,7 +51,7 @@ void process_setPosition(cJSON *rxjson) { |
|
|
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { |
|
|
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { |
|
|
direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); |
|
|
direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); |
|
|
} |
|
|
} |
|
|
motor_run_to_postion(1, position, index); |
|
|
|
|
|
|
|
|
motor_run_to_postion(1, position, 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void processrxjson(cJSON *rxjson) { |
|
|
void processrxjson(cJSON *rxjson) { |
|
@ -62,7 +63,9 @@ void processrxjson(cJSON *rxjson) { |
|
|
|
|
|
|
|
|
if (strcmp(order, "setPosition") == 0) { |
|
|
if (strcmp(order, "setPosition") == 0) { |
|
|
process_setPosition(rxjson); |
|
|
process_setPosition(rxjson); |
|
|
|
|
|
|
|
|
} else if (strcmp(order, "getStatus") == 0) { |
|
|
} else if (strcmp(order, "getStatus") == 0) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -85,8 +88,8 @@ void motor_on_event(motor_event_t event) { |
|
|
uint8_t buffer[128] = {0}; |
|
|
uint8_t buffer[128] = {0}; |
|
|
//组包 |
|
|
//组包 |
|
|
//上报 |
|
|
//上报 |
|
|
//{ "order": "deviceStatusReport", "index": 0, "deviceState": "running", "position":13.9, "deviceException": 0, "deviceExceptionInfo": "", } |
|
|
|
|
|
sprintf((char *)buffer, "{ \"order\": \"receipt\", \"code\": 0, \"info\": \"success\", \"index\": %d }", 0); |
|
|
|
|
|
|
|
|
//{ "order": "deviceStatusReport", "ble_uart_index": 0, "deviceState": "running", "position":13.9, "deviceException": 0, "deviceExceptionInfo": "", } |
|
|
|
|
|
sprintf((char *)buffer, "{ \"order\": \"receipt\", \"code\": 0, \"info\": \"success\", \"index\": %d }", 1); |
|
|
bleuart_notify_send(buffer,sizeof(buffer)); |
|
|
bleuart_notify_send(buffer,sizeof(buffer)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|