Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
149a1b18
Commit
149a1b18
authored
Apr 18, 2021
by
Eric Duminil
Browse files
Sorted commands in log
parent
6b33430b
Pipeline
#2833
passed with stage
in 1 minute and 36 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/sensor_console.cpp
View file @
149a1b18
#include
"sensor_console.h"
namespace
sensor_console
{
const
uint8_t
MAX_C
ALLBACK
S
=
20
;
const
uint8_t
MAX_C
OMMAND
S
=
20
;
const
uint8_t
MAX_COMMAND_SIZE
=
30
;
uint8_t
c
allback
s_count
=
0
;
uint8_t
c
ommand
s_count
=
0
;
struct
C
allback
{
struct
C
ommand
{
const
char
*
name
;
union
{
void
(
*
intFunction
)(
int32_t
);
...
...
@@ -16,30 +16,30 @@ namespace sensor_console {
bool
has_parameter
;
};
C
allback
callbacks
[
MAX_CALLBACK
S
];
C
ommand
commands
[
MAX_COMMAND
S
];
//NOTE: Probably possible to DRY (with templates?)
void
defineCommand
(
const
char
*
name
,
void
(
*
function
)(
void
),
const
char
*
doc
)
{
if
(
c
allback
s_count
<
MAX_C
ALLBACK
S
)
{
c
allbacks
[
callback
s_count
].
name
=
name
;
c
allbacks
[
callback
s_count
].
voidFunction
=
function
;
c
allbacks
[
callback
s_count
].
doc
=
doc
;
c
allbacks
[
callback
s_count
].
has_parameter
=
false
;
c
allback
s_count
++
;
if
(
c
ommand
s_count
<
MAX_C
OMMAND
S
)
{
c
ommands
[
command
s_count
].
name
=
name
;
c
ommands
[
command
s_count
].
voidFunction
=
function
;
c
ommands
[
command
s_count
].
doc
=
doc
;
c
ommands
[
command
s_count
].
has_parameter
=
false
;
c
ommand
s_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many c
allback
s have been defined."
));
Serial
.
println
(
F
(
"Too many c
ommand
s have been defined."
));
}
}
void
defineIntCommand
(
const
char
*
name
,
void
(
*
function
)(
int32_t
),
const
char
*
doc
)
{
if
(
c
allback
s_count
<
MAX_C
ALLBACK
S
)
{
c
allbacks
[
callback
s_count
].
name
=
name
;
c
allbacks
[
callback
s_count
].
intFunction
=
function
;
c
allbacks
[
callback
s_count
].
doc
=
doc
;
c
allbacks
[
callback
s_count
].
has_parameter
=
true
;
c
allback
s_count
++
;
if
(
c
ommand
s_count
<
MAX_C
OMMAND
S
)
{
c
ommands
[
command
s_count
].
name
=
name
;
c
ommands
[
command
s_count
].
intFunction
=
function
;
c
ommands
[
command
s_count
].
doc
=
doc
;
c
ommands
[
command
s_count
].
has_parameter
=
true
;
c
ommand
s_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many c
allback
s have been defined."
));
Serial
.
println
(
F
(
"Too many c
ommand
s have been defined."
));
}
}
...
...
@@ -106,11 +106,18 @@ namespace sensor_console {
}
}
void
listAvailableCallbacks
()
{
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
int
compareName
(
const
void
*
s1
,
const
void
*
s2
)
{
struct
Command
*
c1
=
(
struct
Command
*
)
s1
;
struct
Command
*
c2
=
(
struct
Command
*
)
s2
;
return
strcmp
(
c1
->
name
,
c2
->
name
);
}
void
listAvailableCommands
()
{
qsort
(
commands
,
commands_count
,
sizeof
(
commands
[
0
]),
compareName
);
for
(
uint8_t
i
=
0
;
i
<
commands_count
;
i
++
)
{
Serial
.
print
(
" "
);
Serial
.
print
(
c
allback
s
[
i
].
name
);
Serial
.
print
(
c
allback
s
[
i
].
doc
);
Serial
.
print
(
c
ommand
s
[
i
].
name
);
Serial
.
print
(
c
ommand
s
[
i
].
doc
);
Serial
.
println
(
"."
);
}
led_effects
::
showKITTWheel
(
color
::
red
,
1
);
...
...
@@ -125,23 +132,23 @@ namespace sensor_console {
bool
has_argument
;
has_argument
=
(
parseCommand
(
command
,
function_name
,
argument
)
==
0
);
for
(
uint8_t
i
=
0
;
i
<
c
allback
s_count
;
i
++
)
{
if
(
!
strcmp
(
function_name
,
c
allback
s
[
i
].
name
)
&&
has_argument
==
c
allback
s
[
i
].
has_parameter
)
{
Serial
.
print
(
"Calling : "
);
for
(
uint8_t
i
=
0
;
i
<
c
ommand
s_count
;
i
++
)
{
if
(
!
strcmp
(
function_name
,
c
ommand
s
[
i
].
name
)
&&
has_argument
==
c
ommand
s
[
i
].
has_parameter
)
{
Serial
.
print
(
F
(
"Calling : "
)
)
;
Serial
.
print
(
function_name
);
if
(
has_argument
)
{
Serial
.
print
(
"("
);
Serial
.
print
(
argument
);
Serial
.
println
(
")"
);
c
allback
s
[
i
].
intFunction
(
argument
);
c
ommand
s
[
i
].
intFunction
(
argument
);
}
else
{
Serial
.
println
(
"()"
);
c
allback
s
[
i
].
voidFunction
();
c
ommand
s
[
i
].
voidFunction
();
}
return
;
}
}
Serial
.
println
(
F
(
"Message not supported. Available commands :"
));
listAvailableC
allback
s
();
listAvailableC
ommand
s
();
}
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment