yy1717
2020-11-25 1baa8f7baa336ce7e78d4b8389a351526cb8c673
lib/src/main/cpp/rtk_platform/platform.cpp
@@ -30,6 +30,8 @@
#define DEBUG(fmt, args...)     LOGD("<platform> <%s>: " fmt, __func__, ##args)
using namespace std;
struct platformSocket {
    char domain_name[32];
    int port;
@@ -86,6 +88,10 @@
static struct gpsBrief gbf;
static struct rtkBrief rbf;
static bool btEnable = false, btConnected = false;
static char btAddr[64] = {0};
static char *btPin = NULL;
static void AddEvnet(uint32_t event, const uint8_t *data, int length);
static struct event_t * FetchEvent(void);
@@ -575,25 +581,47 @@
        }
    }
    if (events & BLUETOOTH_STATUS_EVT) {
        DEBUG("BLUETOOTH_STATUS_EVT %d", data[0]);
        DEBUG("BLUETOOTH_STATUS_EVT");
        uint8_t sta;
        if (data[0] == 3) {
        if (length == 128) {
            MA_SendBlueStatus((char *)data, (char *)data+64, 3);
            sta = 3;
        } else if (length == 64) {
            MA_SendBlueStatus(NULL, (char *)data, 3);
            sta = 3;
        } else {
            MA_SendBlueStatus(NULL, NULL, data[0]);
            sta = data[0];
        }
        if (sta == 3) {
            // Connected
            btConnected = true;
            ParseMcuInit();
            ConfigRTKModuleLater();
            PlayTTS("蓝牙连接", NULL);
        } else if (data[0] == 2) {
        } else if (sta == 2) {
            // Disconnect
            btConnected = false;
            PlayTTS("蓝牙断开", NULL);
        } else if (data[0] == 1) {
        } else if (sta == 1) {
            // Open
            ConnectToBluetooth("00:1B:35:16:20:4A", "3800");
            btEnable = true;
            if (strlen(btAddr) > 0) {
                ConnectToBluetooth(btAddr, NULL);
            }
//            ConnectToBluetooth("00:1B:35:16:20:4A", "5516");
//            ConnectToBluetooth("00:1B:35:16:20:4A", "3800");``
//            ConnectToBluetooth("00:1D:43:9A:E0:79", "1900");
//            ConnectToBluetooth("DESKTOP-IE9V7U8", "0000");
            PlayTTS("蓝牙启动", NULL);
        } else {
            // Close
            btEnable = false;
            btConnected = false;
            PlayTTS("蓝牙关闭", NULL);
        }
    }
@@ -815,3 +843,26 @@
        memcpy(defaultMcuRom.rom, rom, length);
    }
}
void SetRemoteBluetooth(const char *name, const char *addr)
{
    strcpy(btAddr, addr);
    if (btConnected) {
        DisconnectBluetooth();
    }
    /*string csname = name;
    if (csname != NULL) {
        if (csname.find("AKS3A_TEST") != string::npos) {
            btPin = "1111";
        } else if (csname.find("AKS3A_") != string::npos && csname.size() >= 8) {
            int a = stoi(csname.substr(csname.size()-8, 4));
            int b = stoi(csname.substr(csname.size()-4, 4));
        }
    }*/
    if (btEnable) {
        ConnectToBluetooth(addr, NULL);
    }
}