Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Käppler
ampel-firmware
Commits
96d9138d
Commit
96d9138d
authored
Apr 16, 2021
by
Eric Duminil
Browse files
Ugly, but kinda working
parent
8b8e62f6
Changes
1
Show whitespace changes
Inline
Side-by-side
ampel-firmware/sensor_commands.cpp
View file @
96d9138d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
sensor_commands
{
namespace
sensor_commands
{
const
uint8_t
MAX_CALLBACKS
=
20
;
const
uint8_t
MAX_CALLBACKS
=
20
;
const
uint8_t
MAX_COMMAND_SIZE
=
30
;
uint8_t
callbacks_count
=
0
;
uint8_t
callbacks_count
=
0
;
// A callback contains both a function and a pointer to arbitrary data
// A callback contains both a function and a pointer to arbitrary data
...
@@ -30,25 +31,20 @@ namespace sensor_commands {
...
@@ -30,25 +31,20 @@ namespace sensor_commands {
return
!
strncmp
(
a
,
b
,
strlen
(
b
));
return
!
strncmp
(
a
,
b
,
strlen
(
b
));
}
}
bool
parseCommand
(
const
char
*
c
,
char
*
fname
,
long
*
param
)
{
bool
parseCommand
(
const
char
*
command
,
char
*
function_name
,
long
&
parameter
)
{
return
0
;
char
split_command
[
MAX_COMMAND_SIZE
];
}
strlcpy
(
split_command
,
command
,
MAX_COMMAND_SIZE
);
void
run
(
const
char
*
c
)
{
char
command
[
30
];
char
*
function_name
;
long
parameter
;
parseCommand
(
c
,
function_name
,
&
parameter
);
strlcpy
(
command
,
c
,
30
);
Serial
.
print
(
F
(
"Received : '"
));
Serial
.
print
(
F
(
"Received : '"
));
Serial
.
print
(
command
);
Serial
.
print
(
command
);
Serial
.
println
(
"'"
);
Serial
.
println
(
"'"
);
char
*
arg
;
char
*
arg
;
function_name
=
strtok
(
command
,
" "
);
char
*
part1
;
if
(
!
function_name
)
{
part1
=
strtok
(
split_command
,
" "
);
if
(
!
part1
)
{
// Empty string
// Empty string
return
;
return
1
;
}
}
strlcpy
(
function_name
,
part1
,
MAX_COMMAND_SIZE
);
arg
=
strtok
(
NULL
,
" "
);
arg
=
strtok
(
NULL
,
" "
);
if
(
arg
)
{
if
(
arg
)
{
char
*
end
;
char
*
end
;
...
@@ -60,6 +56,15 @@ namespace sensor_commands {
...
@@ -60,6 +56,15 @@ namespace sensor_commands {
}
else
{
}
else
{
parameter
=
-
9999
;
parameter
=
-
9999
;
}
}
return
0
;
}
void
run
(
const
char
*
command
)
{
char
function_name
[
MAX_COMMAND_SIZE
];
long
parameter
;
if
(
parseCommand
(
command
,
function_name
,
parameter
))
{
return
;
}
Serial
.
print
(
"Command : '"
);
Serial
.
print
(
"Command : '"
);
Serial
.
print
(
function_name
);
Serial
.
print
(
function_name
);
Serial
.
print
(
"'. Parameter : "
);
Serial
.
print
(
"'. Parameter : "
);
...
@@ -67,7 +72,7 @@ namespace sensor_commands {
...
@@ -67,7 +72,7 @@ namespace sensor_commands {
// Test all the callbacks.
// Test all the callbacks.
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
if
(
startsWith
(
command
,
callbacks
[
i
].
name
))
{
if
(
startsWith
(
function_name
,
callbacks
[
i
].
name
))
{
Serial
.
print
(
"OHHHH YES!!!"
);
Serial
.
print
(
"OHHHH YES!!!"
);
}
}
Serial
.
print
(
"Trying '"
);
Serial
.
print
(
"Trying '"
);
...
...
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