Commit 2eac5586 authored by Jannis Rieger's avatar Jannis Rieger
Browse files

feat(ble): Read the advertised device name from a file

parent 0608bfdc
Pipeline #2896 passed with stages
in 1 minute and 44 seconds
......@@ -328,16 +328,35 @@ static void bleSetup(bleMsg_t *pMsg)
char buf[32];
char a, b, c, d, e, f, K;
if (fs_read_text_file("mac.txt", buf, sizeof(buf)))
// read the device name from file
int name_length = fs_read_text_file("device_name.txt", buf, sizeof(buf));
// check if the file was present and contained data
if (name_length > 0) {
// truncate name_length to the maximum length a device name can be (bleScanDataDisc[0] - 1)
if (bleScanDataDisc[0] - 1 < name_length)
name_length = bleScanDataDisc[0] - 1;
// now copy the name
memcpy(bleScanDataDisc + 2, buf, name_length);
// if the name is shorter than the maximum device name length
// we pad the rest with spaces
while(name_length < bleScanDataDisc[0] - 1) {
bleScanDataDisc[2 + name_length++] = ' ';
}
}
else
{
if (sscanf(buf, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", &K,&K,&K,&K,&K,&K, &a, &b, &c, &d, &e, &f) == 12)
// if the device_name file was not present use the default name with the mac address
if (fs_read_text_file("mac.txt", buf, sizeof(buf)))
{
bleScanDataDisc[9] = a;
bleScanDataDisc[10] = b;
bleScanDataDisc[11] = c;
bleScanDataDisc[12] = d;
bleScanDataDisc[13] = e;
bleScanDataDisc[14] = f;
if (sscanf(buf, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", &K,&K,&K,&K,&K,&K, &a, &b, &c, &d, &e, &f) == 12)
{
bleScanDataDisc[9] = a;
bleScanDataDisc[10] = b;
bleScanDataDisc[11] = c;
bleScanDataDisc[12] = d;
bleScanDataDisc[13] = e;
bleScanDataDisc[14] = f;
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment