Communication::Command refactored out of Communication
parent
6284223650
commit
d27b516894
|
|
@ -6,6 +6,7 @@
|
|||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "communication/include/command.h"
|
||||
#include "communication/include/messagedecoder.h"
|
||||
#include "communication/include/packetizer.h"
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ bool Communication::sendPacket(std::vector<uint8_t>& bytes) {
|
|||
return impl->write(Communication::packetWrap(bytes));
|
||||
}
|
||||
|
||||
bool Communication::sendCommand(Communication::Command cmd, std::vector<uint8_t> arguments) {
|
||||
bool Communication::sendCommand(Command cmd, std::vector<uint8_t> arguments) {
|
||||
std::vector<uint8_t> bytes;
|
||||
bytes.push_back((uint8_t)cmd);
|
||||
for(auto& b : arguments)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef __COMMAND_H_
|
||||
#define __COMMAND_H_
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
enum class Command : uint8_t {
|
||||
EnableNetworkCommunication = 0x07,
|
||||
RequestSerialNumber = 0xA1,
|
||||
SetSettings = 0xA4, // Previously known as RED_CMD_SET_BAUD_REQ, follow up with SaveSettings to write to EEPROM
|
||||
GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ
|
||||
SaveSettings = 0xA6
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#define __COMMUNICATION_H_
|
||||
|
||||
#include "communication/include/icommunication.h"
|
||||
#include "communication/include/command.h"
|
||||
#include "communication/include/network.h"
|
||||
#include "communication/include/messagecallback.h"
|
||||
#include <memory>
|
||||
|
|
@ -28,13 +29,6 @@ public:
|
|||
std::vector<uint8_t>& packetWrap(std::vector<uint8_t>& data, bool addChecksum = true);
|
||||
bool sendPacket(std::vector<uint8_t>& bytes);
|
||||
|
||||
enum class Command : uint8_t {
|
||||
EnableNetworkCommunication = 0x07,
|
||||
RequestSerialNumber = 0xA1,
|
||||
SetSettings = 0xA4, // Previously known as RED_CMD_SET_BAUD_REQ, follow up with SaveSettings to write to EEPROM
|
||||
GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ
|
||||
SaveSettings = 0xA6
|
||||
};
|
||||
virtual bool sendCommand(Command cmd, bool boolean) { return sendCommand(cmd, std::vector<uint8_t>({ (uint8_t)boolean })); }
|
||||
virtual bool sendCommand(Command cmd, std::vector<uint8_t> arguments = {});
|
||||
bool getSettingsSync(std::vector<uint8_t>& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "communication/include/communication.h"
|
||||
#include "communication/include/icommunication.h"
|
||||
#include "communication/include/command.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ public:
|
|||
MultiChannelCommunication(std::shared_ptr<ICommunication> com) : Communication(com) {}
|
||||
void spawnThreads();
|
||||
void joinThreads();
|
||||
bool sendCommand(Communication::Command cmd, std::vector<uint8_t> arguments);
|
||||
bool sendCommand(Command cmd, std::vector<uint8_t> arguments);
|
||||
|
||||
protected:
|
||||
bool preprocessPacket(std::deque<uint8_t>& usbReadFifo);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "communication/include/multichannelcommunication.h"
|
||||
#include "communication/include/command.h"
|
||||
#include "communication/include/messagedecoder.h"
|
||||
#include "communication/include/packetizer.h"
|
||||
#include <iostream>
|
||||
|
|
@ -15,7 +16,7 @@ void MultiChannelCommunication::joinThreads() {
|
|||
mainChannelReadThread.join();
|
||||
}
|
||||
|
||||
bool MultiChannelCommunication::sendCommand(Communication::Command cmd, std::vector<uint8_t> arguments) {
|
||||
bool MultiChannelCommunication::sendCommand(Command cmd, std::vector<uint8_t> arguments) {
|
||||
std::vector<uint8_t> bytes;
|
||||
bytes.push_back((uint8_t)cmd);
|
||||
for(auto& b : arguments)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "include/device.h"
|
||||
#include "communication/include/messagecallback.h"
|
||||
#include "communication/include/command.h"
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
|
@ -138,20 +138,17 @@ bool Device::close() {
|
|||
}
|
||||
|
||||
bool Device::goOnline() {
|
||||
std::string serial;
|
||||
while(!com->getSerialNumberSync(serial)) {
|
||||
std::cout << "Serial number not here yet" << std::endl;
|
||||
}
|
||||
|
||||
if(!com->sendCommand(Communication::Command::EnableNetworkCommunication, true))
|
||||
if(!com->sendCommand(Command::EnableNetworkCommunication, true))
|
||||
return false;
|
||||
|
||||
// if(!com->sendCommand(Communication::Command::RequestSerialNumber))
|
||||
// return false;
|
||||
|
||||
return online = true;
|
||||
online = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device::goOffline() {
|
||||
return com->sendCommand(Communication::Command::EnableNetworkCommunication, false);
|
||||
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
||||
return false;
|
||||
|
||||
online = false;
|
||||
return true;
|
||||
}
|
||||
Loading…
Reference in New Issue