Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jannis Rieger
firmware
Commits
2eac5586
Commit
2eac5586
authored
Aug 22, 2019
by
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
epicardium/ble/ble_main.c
View file @
2eac5586
...
...
@@ -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
;
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment