Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Haufe
firmware
Commits
18cf4287
Commit
18cf4287
authored
5 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(ble): Add error handling to HCI logging
parent
d6ea08a7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/ble/ble.c
+73
-14
73 additions, 14 deletions
epicardium/ble/ble.c
with
73 additions
and
14 deletions
epicardium/ble/ble.c
+
73
−
14
View file @
18cf4287
...
@@ -95,6 +95,7 @@ void WsfPDump(wsfPDumpType_t pdType, uint16_t length, uint8_t *pBuffer)
...
@@ -95,6 +95,7 @@ void WsfPDump(wsfPDumpType_t pdType, uint16_t length, uint8_t *pBuffer)
{
{
uint32_t
direction
;
uint32_t
direction
;
uint8_t
type
;
uint8_t
type
;
int
ret
;
if
(
log_enabled
)
{
if
(
log_enabled
)
{
switch
(
pdType
)
{
switch
(
pdType
)
{
...
@@ -131,11 +132,29 @@ void WsfPDump(wsfPDumpType_t pdType, uint16_t length, uint8_t *pBuffer)
...
@@ -131,11 +132,29 @@ void WsfPDump(wsfPDumpType_t pdType, uint16_t length, uint8_t *pBuffer)
.
timestamp_us_l
=
__htonl
(
timestamp_us
&
0xFFFFFFFF
)
.
timestamp_us_l
=
__htonl
(
timestamp_us
&
0xFFFFFFFF
)
};
};
epic_file_write
(
log_fd
,
&
header
,
sizeof
(
header
));
ret
=
epic_file_write
(
log_fd
,
&
header
,
sizeof
(
header
));
epic_file_write
(
log_fd
,
&
type
,
sizeof
(
type
));
if
(
ret
!=
sizeof
(
header
))
{
epic_file_write
(
log_fd
,
pBuffer
,
length
);
goto
out_err
;
}
ret
=
epic_file_write
(
log_fd
,
&
type
,
sizeof
(
type
));
if
(
ret
!=
sizeof
(
type
))
{
goto
out_err
;
}
ret
=
epic_file_write
(
log_fd
,
pBuffer
,
length
);
if
(
ret
!=
length
)
{
goto
out_err
;
}
log_dirty
=
true
;
log_dirty
=
true
;
}
}
return
;
out_err:
LOG_WARN
(
"ble"
,
"Log file write failed. Logging diabled"
);
log_enabled
=
false
;
}
}
/*************************************************************************************************/
/*************************************************************************************************/
static
void
WsfInit
(
void
)
static
void
WsfInit
(
void
)
...
@@ -319,15 +338,25 @@ static void log_flush(void)
...
@@ -319,15 +338,25 @@ static void log_flush(void)
}
}
}
}
/*************************************************************************************************/
/*************************************************************************************************/
static
void
log_rotate
(
void
)
static
int
log_rotate
(
void
)
{
{
int
i
;
int
i
;
char
filename_old
[
16
];
char
filename_old
[
16
];
char
filename_new
[
16
];
char
filename_new
[
16
];
struct
epic_stat
stat
;
struct
epic_stat
stat
;
int
ret
;
if
(
epic_file_stat
(
"logs/"
,
&
stat
)
!=
0
)
{
epic_file_stat
(
"logs"
,
&
stat
);
epic_file_mkdir
(
"logs"
);
if
(
stat
.
type
==
EPICSTAT_FILE
)
{
return
-
1
;
}
if
(
stat
.
type
==
EPICSTAT_NONE
)
{
ret
=
epic_file_mkdir
(
"logs"
);
if
(
ret
<
0
)
{
return
ret
;
}
}
}
if
(
epic_file_stat
(
"logs/ble9.log"
,
&
stat
)
==
0
)
{
if
(
epic_file_stat
(
"logs/ble9.log"
,
&
stat
)
==
0
)
{
...
@@ -346,6 +375,43 @@ static void log_rotate(void)
...
@@ -346,6 +375,43 @@ static void log_rotate(void)
if
(
epic_file_stat
(
"logs/ble.log"
,
&
stat
)
==
0
)
{
if
(
epic_file_stat
(
"logs/ble.log"
,
&
stat
)
==
0
)
{
epic_file_rename
(
"logs/ble.log"
,
"logs/ble1.log"
);
epic_file_rename
(
"logs/ble.log"
,
"logs/ble1.log"
);
}
}
return
0
;
}
/*************************************************************************************************/
static
void
log_init
(
void
)
{
int
ret
;
log_enabled
=
config_get_boolean_with_default
(
"ble_log_enable"
,
false
);
if
(
!
log_enabled
)
{
return
;
}
LOG_INFO
(
"ble"
,
"Log is enabled"
);
if
(
log_rotate
()
<
0
)
{
log_enabled
=
false
;
LOG_WARN
(
"ble"
,
"Can not rotate logs. Logging disabled."
);
return
;
}
log_fd
=
epic_file_open
(
"logs/ble.log"
,
"w"
);
if
(
log_fd
<
0
)
{
log_enabled
=
false
;
LOG_WARN
(
"ble"
,
"Can not create log file. Logging disabled."
);
return
;
}
ret
=
epic_file_write
(
log_fd
,
log_header
,
sizeof
(
log_header
));
if
(
ret
!=
sizeof
(
log_header
))
{
log_enabled
=
false
;
LOG_WARN
(
"ble"
,
"Can not create log file header. Logging disabled."
);
return
;
}
}
}
/*************************************************************************************************/
/*************************************************************************************************/
void
vBleTask
(
void
*
pvParameters
)
void
vBleTask
(
void
*
pvParameters
)
...
@@ -357,14 +423,7 @@ void vBleTask(void *pvParameters)
...
@@ -357,14 +423,7 @@ void vBleTask(void *pvParameters)
*/
*/
vTaskDelay
(
pdMS_TO_TICKS
(
500
));
vTaskDelay
(
pdMS_TO_TICKS
(
500
));
log_enabled
=
config_get_boolean_with_default
(
"ble_log_enable"
,
false
);
log_init
();
if
(
log_enabled
)
{
LOG_INFO
(
"ble"
,
"Log is enabled"
);
log_rotate
();
log_fd
=
epic_file_open
(
"logs/ble.log"
,
"w"
);
epic_file_write
(
log_fd
,
log_header
,
sizeof
(
log_header
));
}
/* We are going to execute FreeRTOS functions from callbacks
/* We are going to execute FreeRTOS functions from callbacks
* coming from this interrupt. Its priority needs to be
* coming from this interrupt. Its priority needs to be
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment