mirror of
https://github.com/whoahq/whoa.git
synced 2026-11-07 15:19:53 +03:00
feat(net): add loop to grunt command processing
This commit is contained in:
2 files changed
+31
-14
No files matched your search
+1
-1
Submodule lib/common updated: 5dce613aeb...9a5e71de22.
+30
-13
@@ -18,23 +18,40 @@ class Grunt::Command {
|
||||
|
||||
template <class T>
|
||||
int32_t Grunt::Command<T>::Process(CDataStore& msg, Command<T>* commands, uint32_t commandCount, T& a4, uint32_t& pos) {
|
||||
uint8_t cmd;
|
||||
msg.Get(cmd);
|
||||
while (true) {
|
||||
if (!msg.Sub8CBBF0(1)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < commandCount; i++) {
|
||||
auto& command = commands[i];
|
||||
uint8_t cmd;
|
||||
msg.Get(cmd);
|
||||
|
||||
if (command.cmd == cmd) {
|
||||
auto callback = command.callback;
|
||||
auto result = (a4.*callback)(msg);
|
||||
|
||||
if (result == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
// TODO
|
||||
return 0;
|
||||
Command<T>* command = nullptr;
|
||||
for (uint32_t i = 0; i < commandCount; i++) {
|
||||
if (commands[i].cmd == cmd) {
|
||||
command = &commands[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!command) {
|
||||
// Bad command received [0x%02X] (unrecognized command)
|
||||
break;
|
||||
}
|
||||
|
||||
auto result = (a4.*command->callback)(msg);
|
||||
|
||||
if (result == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (result == 1) {
|
||||
// Bad command received [0x%02X] (Corrupt)
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == 2) {
|
||||
pos = msg.m_read;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
Reference in new issue
Block a user