From 9623775bc335594e54fb27af7af9e25346d9c2a1 Mon Sep 17 00:00:00 2001 From: robot9706 Date: Fri, 9 Oct 2020 17:57:40 +0200 Subject: [PATCH] Config client MAC --- headphone_power_receiver/main.c | 18 +++++++++++++----- taskbar_app/BatteryIndicator/Program.cs | 11 +++++++++++ taskbar_app/BatteryIndicator/config.json | 3 ++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/headphone_power_receiver/main.c b/headphone_power_receiver/main.c index b8eef84..8766569 100644 --- a/headphone_power_receiver/main.c +++ b/headphone_power_receiver/main.c @@ -20,10 +20,9 @@ #define DEADBEEF 0xDEADBEEF -#define CLIENT_MAC 0x7E, 0x92, 0xC2, 0xFB, 0x54, 0xC6 - static ble_gap_scan_params_t scan_parameters; +static uint8_t clientMac[6]; static bool sendData = false; // Flag to signal when to send data static void scan_start(void) @@ -55,9 +54,8 @@ static void ble_evt_dispatch(ble_evt_t * p_ble_evt) if (sendData) { const ble_gap_addr_t * const peer_addr = &p_gap_evt->params.adv_report.peer_addr; - const uint8_t checkAddress[6] = { CLIENT_MAC }; - - if (memcmp(peer_addr->addr, checkAddress, 6) == 0) + + if (memcmp(peer_addr->addr, clientMac, 6) == 0) { uart_put(DATA_HEADER); uart_put(p_gap_evt->params.adv_report.dlen); @@ -123,6 +121,16 @@ int main(void) switch (uart_read()) { case COMMAND_ENABLE: + + while (uart_available() < 6) + { + // Wait for MAC + } + + for (int x = 0; x < 6; x++) + { + clientMac[x] = uart_read(); + } sendData = true; break; case COMMAND_DISABLE: diff --git a/taskbar_app/BatteryIndicator/Program.cs b/taskbar_app/BatteryIndicator/Program.cs index 617ee8a..b0bd09e 100644 --- a/taskbar_app/BatteryIndicator/Program.cs +++ b/taskbar_app/BatteryIndicator/Program.cs @@ -64,6 +64,8 @@ static class Program private static DateTime lastCommunication; + private static byte[] clientMac; + [STAThread] static void Main() { @@ -71,6 +73,11 @@ static void Main() { Config config = JsonConvert.DeserializeObject(File.ReadAllText("config.json")); + clientMac = config.ClientMac.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + .Select(x => x.Trim()) + .Select(x => Convert.ToByte(x, 16)) + .ToArray(); + notifyIcon = new NotifyIcon(); notifyIcon.Icon = Resources.battery_unknown; @@ -165,6 +172,7 @@ static void Threa_IconHelper() static void Thread_SerialRead() { serialPort.Write(new byte[] { 0xAF }, 0, 1); // Begin command + serialPort.Write(clientMac, 0, clientMac.Length); // Source MAC serialPort.BaseStream.Flush(); while (true) @@ -235,5 +243,8 @@ class Config [JsonProperty("baud")] public int Baud { get; private set; } + + [JsonProperty("client_mac")] + public string ClientMac { get; private set; } } } diff --git a/taskbar_app/BatteryIndicator/config.json b/taskbar_app/BatteryIndicator/config.json index f3c14cf..5e63ef2 100644 --- a/taskbar_app/BatteryIndicator/config.json +++ b/taskbar_app/BatteryIndicator/config.json @@ -1,4 +1,5 @@ { "port": "COM9", - "baud": 115200 + "baud": 115200, + "client_mac": "0x7E, 0x92, 0xC2, 0xFB, 0x54, 0xC6" } \ No newline at end of file