Skip to content

Commit

Permalink
Config client MAC
Browse files Browse the repository at this point in the history
  • Loading branch information
robot9706 committed Oct 9, 2020
1 parent 6dde767 commit 9623775
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
18 changes: 13 additions & 5 deletions headphone_power_receiver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions taskbar_app/BatteryIndicator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,20 @@ static class Program

private static DateTime lastCommunication;

private static byte[] clientMac;

[STAThread]
static void Main()
{
try
{
Config config = JsonConvert.DeserializeObject<Config>(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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -235,5 +243,8 @@ class Config

[JsonProperty("baud")]
public int Baud { get; private set; }

[JsonProperty("client_mac")]
public string ClientMac { get; private set; }
}
}
3 changes: 2 additions & 1 deletion taskbar_app/BatteryIndicator/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"port": "COM9",
"baud": 115200
"baud": 115200,
"client_mac": "0x7E, 0x92, 0xC2, 0xFB, 0x54, 0xC6"
}

0 comments on commit 9623775

Please sign in to comment.