Skip to content
Snippets Groups Projects
Commit 2eac5586 authored by Jannis Rieger's avatar Jannis Rieger
Browse files

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

parent 0608bfdc
No related branches found
No related tags found
No related merge requests found
Pipeline #2896 passed
...@@ -328,6 +328,24 @@ static void bleSetup(bleMsg_t *pMsg) ...@@ -328,6 +328,24 @@ static void bleSetup(bleMsg_t *pMsg)
char buf[32]; char buf[32];
char a, b, c, d, e, f, K; char a, b, c, d, e, f, K;
// 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 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))) if (fs_read_text_file("mac.txt", buf, sizeof(buf)))
{ {
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 (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)
...@@ -340,6 +358,7 @@ static void bleSetup(bleMsg_t *pMsg) ...@@ -340,6 +358,7 @@ static void bleSetup(bleMsg_t *pMsg)
bleScanDataDisc[14] = f; bleScanDataDisc[14] = f;
} }
} }
}
/* set advertising and scan response data for discoverable mode */ /* set advertising and scan response data for discoverable mode */
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(bleAdvDataDisc), (uint8_t *) bleAdvDataDisc); AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(bleAdvDataDisc), (uint8_t *) bleAdvDataDisc);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment