Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Software Defined Radio
r0tor
Commits
650c8164
Commit
650c8164
authored
Jul 15, 2019
by
markus
Browse files
Refactor command string execution and add return print
parent
2c4a4417
Changes
2
Hide whitespace changes
Inline
Side-by-side
shackremote_arduino/control.cpp
View file @
650c8164
...
...
@@ -51,11 +51,11 @@ void Control::doControl()
Control
::
hamlibError
Control
::
executeCommandString
(
String
*
command_string
,
Communicator
*
communicator
)
{
String
substring
;
String
response
=
""
;
int
lastPos
=
-
1
;
int
newPos
=
0
;
int
dst
=
0
;
while
(
newPos
=
command_string
->
indexOf
(
";"
,
lastPos
+
1
))
{
while
(
(
newPos
=
command_string
->
indexOf
(
";"
,
lastPos
+
1
))
!=
-
1
)
{
substring
=
command_string
->
substring
(
lastPos
+
1
,
newPos
);
lastPos
=
newPos
;
...
...
@@ -68,29 +68,36 @@ Control::hamlibError Control::executeCommandString(String *command_string, Commu
// GNAAAARRR
communicator
->
sendMessage
(
String
(
rotor_
->
getAzimuth
())
+
";"
+
String
(
rotor_
->
getElevation
())
+
";"
);
}
else
if
(
substring
.
startsWith
(
"setaz"
)
)
{
if
(
substring
.
length
()
<
7
)
return
HAMLIB_NOK
;
dst
=
(
int
)
substring
.
substring
(
5
).
toFloat
();
if
(
dst
==
0
&&
substring
.
substring
(
5
)
!=
"0"
)
return
HAMLIB_NOK
;
if
(
dst
<
AZIM_MIN
or
dst
>
AZIM_MAX
)
return
HAMLIB_NOK
;
rotor_
->
setAzimuth
(
dst
);
}
else
if
(
substring
.
startsWith
(
"setel"
)
)
{
if
(
substring
.
length
()
<
7
)
return
HAMLIB_NOK
;
dst
=
(
int
)
substring
.
substring
(
5
).
toFloat
();
if
(
dst
==
0
&&
substring
.
substring
(
5
)
!=
"0"
)
return
HAMLIB_NOK
;
if
(
dst
<
ELEV_MIN
or
dst
>
ELEV_MAX
)
return
HAMLIB_NOK
;
rotor_
->
setElevation
(
dst
);
else
{
if
(
executeActiveCommandSubstring
(
substring
)
==
HAMLIB_OK
)
response
+=
"1"
;
else
response
+=
"0"
;
}
}
if
(
response
!=
""
)
communicator
->
sendMessage
(
response
);
return
HAMLIB_OK
;
}
Control
::
hamlibError
Control
::
executeActiveCommandSubstring
(
String
substring
)
{
Motor
::
motorError
err
;
float
dst
=
0.0
;
if
(
substring
.
startsWith
(
"setaz"
)
||
substring
.
startsWith
(
"setel"
))
{
if
(
substring
.
length
()
<
7
)
return
HAMLIB_NOK
;
dst
=
substring
.
substring
(
5
).
toFloat
();
if
(
dst
==
0
&&
substring
.
substring
(
5
)
!=
"0"
)
return
HAMLIB_NOK
;
if
(
substring
.
startsWith
(
"setaz"
))
err
=
rotor_
->
setAzimuth
(
dst
);
else
err
=
rotor_
->
setElevation
(
dst
);
if
(
err
==
Motor
::
ROT_VAL_OUT_OF_RANGE
)
return
HAMLIB_NOK
;
}
return
HAMLIB_OK
;
}
shackremote_arduino/control.h
View file @
650c8164
...
...
@@ -5,6 +5,7 @@
#include "rotor.h"
#include "serial_communicator.h"
#include "udp_communicator.h"
#include "motor.h"
class
Control
{
...
...
@@ -22,6 +23,7 @@ public:
private:
void
doCommunicate
();
hamlibError
executeCommandString
(
String
*
,
Communicator
*
);
hamlibError
executeActiveCommandSubstring
(
String
);
Rotor
*
rotor_
;
Communicator
*
serial_communicator_
;
...
...
Write
Preview
Markdown
is supported
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