From 1baa8f7baa336ce7e78d4b8389a351526cb8c673 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期三, 25 十一月 2020 15:10:39 +0800
Subject: [PATCH] 蓝牙密码

---
 lib/src/main/cpp/rtk_platform/platform.cpp |   61 ++++++++++++++++++++++++++++--
 1 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp
index e3e0bb7..e9fe9d8 100644
--- a/lib/src/main/cpp/rtk_platform/platform.cpp
+++ b/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);
+    }
+}

--
Gitblit v1.8.0