|
@ -3,7 +3,7 @@ |
|
|
#include "app_protocols/ble_through/ble_proto_utils.h"
|
|
|
#include "app_protocols/ble_through/ble_proto_utils.h"
|
|
|
using namespace iflytop; |
|
|
using namespace iflytop; |
|
|
|
|
|
|
|
|
#define UART_RX_OVERTIME 100
|
|
|
|
|
|
|
|
|
#define UART_RX_OVERTIME 200
|
|
|
#define TAG "RemoteControler"
|
|
|
#define TAG "RemoteControler"
|
|
|
|
|
|
|
|
|
#define CMD_OVERTIME 500
|
|
|
#define CMD_OVERTIME 500
|
|
@ -35,6 +35,8 @@ void RemoteControlerUpper::initialize() { |
|
|
m_uart = AppHardware::ins()->remoteContolerUart; |
|
|
m_uart = AppHardware::ins()->remoteContolerUart; |
|
|
m_cmdlock.init(); |
|
|
m_cmdlock.init(); |
|
|
zble_proto_utils_init(kzble_master); |
|
|
zble_proto_utils_init(kzble_master); |
|
|
|
|
|
|
|
|
|
|
|
// m_cmdlock
|
|
|
} |
|
|
} |
|
|
void RemoteControlerUpper::regOnReport(on_report_cb_t on_report) { |
|
|
void RemoteControlerUpper::regOnReport(on_report_cb_t on_report) { |
|
|
m_cb[m_ncb] = on_report; |
|
|
m_cb[m_ncb] = on_report; |
|
@ -160,18 +162,18 @@ bool RemoteControlerUpper::txcmd(uint8_t* data, uint32_t len) { |
|
|
ZLOGI(TAG, "txcmd : %s(%d)", zhex2str(data, len), len); |
|
|
ZLOGI(TAG, "txcmd : %s(%d)", zhex2str(data, len), len); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// HAL_UART_Transmit(m_uart, data, len, 100);
|
|
|
|
|
|
HAL_UART_Transmit_DMA(m_uart, data, len); |
|
|
|
|
|
|
|
|
HAL_UART_Transmit(m_uart, data, len, 100); |
|
|
|
|
|
// HAL_UART_Transmit_DMA(m_uart, data, len);
|
|
|
bool suc = ackQueue.receive(&ackcache, CMD_OVERTIME); |
|
|
bool suc = ackQueue.receive(&ackcache, CMD_OVERTIME); |
|
|
if (!suc) { |
|
|
if (!suc) { |
|
|
ZLOGI(TAG, "txcmd failed"); |
|
|
|
|
|
HAL_UART_DMAStop(m_uart); |
|
|
|
|
|
|
|
|
ZLOGI(TAG, "txcmd : %s(%d) fail", zhex2str(data, len), len); |
|
|
|
|
|
// HAL_UART_DMAStop(m_uart);
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
#if DEBUG
|
|
|
#if DEBUG
|
|
|
ZLOGI(TAG, "ack : %s", zhex2str(ackcache.data, ackcache.datalen)); |
|
|
ZLOGI(TAG, "ack : %s", zhex2str(ackcache.data, ackcache.datalen)); |
|
|
#endif
|
|
|
#endif
|
|
|
HAL_UART_DMAStop(m_uart); |
|
|
|
|
|
|
|
|
// HAL_UART_DMAStop(m_uart);
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -233,8 +235,16 @@ bool RemoteControlerUpper::setSlaveInDfuMode() { |
|
|
return suc; |
|
|
return suc; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool RemoteControlerUpper::startScan() { |
|
|
|
|
|
zble_proto_utils_create_cmd_packet(txpacket, kzble_cmd_start_scan, m_index++, NULL, 0); |
|
|
|
|
|
|
|
|
bool RemoteControlerUpper::startScan(const char* slaveName, bool autoConnect) { |
|
|
|
|
|
// typedef struct {
|
|
|
|
|
|
// uint8_t slaveName[20];
|
|
|
|
|
|
// uint8_t autoConnect;
|
|
|
|
|
|
// } zble_start_scan_t;
|
|
|
|
|
|
zble_start_scan_t scanparam = {0}; |
|
|
|
|
|
if (slaveName) strncpy((char*)scanparam.slaveName, slaveName, 20); |
|
|
|
|
|
scanparam.autoConnect = autoConnect; |
|
|
|
|
|
|
|
|
|
|
|
zble_proto_utils_create_cmd_packet(txpacket, kzble_cmd_start_scan, m_index++, (uint8_t*)&scanparam, sizeof(scanparam)); |
|
|
zble_proto_utils_set_packet_to(txpacket, kzble_master); |
|
|
zble_proto_utils_set_packet_to(txpacket, kzble_master); |
|
|
bool suc = txcmd(txbuf, txpacket->packetlen); |
|
|
bool suc = txcmd(txbuf, txpacket->packetlen); |
|
|
return suc; |
|
|
return suc; |
|
|