Commit d532f914 authored by Ian McInerney's avatar Ian McInerney

Changed to using enums for comms functions

parent 76044bd2
......@@ -52,6 +52,29 @@
#define PID_BUFFER_SIZE 12
// Ports defined for the CRTP protocol
enum CRTPPort {
CRTP_PORT_CONSOLE = 0x00,
CRTP_PORT_PARAM = 0x02,
CRTP_PORT_COMMANDER = 0x03,
CRTP_PORT_MEM = 0x04,
CRTP_PORT_LOG = 0x05,
CRTP_PORT_XYZ_SET = 0x06,
CRTP_PORT_XYZ_POS = 0x07,
CRTP_PORT_CONTROLLER_UPDATE = 0x08,
CRTP_PORT_COMP = 0x09,
CRTP_PORT_PLATFORM = 0x0D,
CRTP_PORT_LINK = 0x0F,
};
// Channels in the CRTP packet describing the update requested
enum controllerUpdate_Channels {
CONTROLLER_QUERY_TYPE = 0,
CONTROLLER_CALL_UPDATE,
CONTROLLER_SWITCH_THROTTLE_CTRL
};
// Numbers specified here must match the quadcopter ID numbers
enum PID_Controller_IDs {
PID_X = 0,
......
......@@ -59,7 +59,7 @@ void CCrazyflie::callback_Packet(CCRTPPacket *crtpPacket) {
switch ( crtpPacket->port() ) {
case 0:
case CRTP_PORT_CONSOLE:
{
// Console
char cText[nLength];
......@@ -71,7 +71,7 @@ void CCrazyflie::callback_Packet(CCRTPPacket *crtpPacket) {
}
break;
case 5:
case CRTP_PORT_LOG:
// Logging
if (crtpPacket->channel() == 2) {
CCRTPPacket *crtpLog = new CCRTPPacket(cData, nLength,
......
......@@ -14,8 +14,8 @@ int CCrazyflie::queryControllerType() {
cBuffer[0] = 1;
// Controller update is on port 8
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 8);
crtpPacket->setChannel(0); // Query is on channel 0
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, CRTP_PORT_CONTROLLER_UPDATE);
crtpPacket->setChannel(CONTROLLER_QUERY_TYPE); // Query is on channel 0
// Send the packet and wait for a response
CCRTPPacket *crtpReceived = m_crRadio->sendAndReceive(crtpPacket, m_nRadioChannel, this);
......@@ -56,8 +56,8 @@ bool CCrazyflie::sendPID_Constants( PID_ControllerParams params ) {
params.controllerID, params.Kp, params.Ki, params.Kd, params.iLimit);
// The PID update is on port 8
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 8);
crtpPacket->setChannel(1); // The PID update is on channel 1
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, CRTP_PORT_CONTROLLER_UPDATE);
crtpPacket->setChannel(CONTROLLER_CALL_UPDATE); // The PID update is on channel 1
CCRTPPacket *crtpReceived = m_crRadio->sendAndReceive(crtpPacket, m_nRadioChannel, this);
bool retVal = false;
......@@ -94,8 +94,8 @@ bool CCrazyflie::modifyThrustController(bool enabled) {
}
// Controller update is on port 8
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 8);
crtpPacket->setChannel(2); // Query is on channel 0
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, CRTP_PORT_CONTROLLER_UPDATE);
crtpPacket->setChannel(CONTROLLER_SWITCH_THROTTLE_CTRL); // Query is on channel 0
// Send the packet and wait for a response
CCRTPPacket *crtpReceived = m_crRadio->sendAndReceive(crtpPacket, m_nRadioChannel, this);
......@@ -133,7 +133,7 @@ bool CCrazyflie::sendCameraData() {
this->m_currentCameraPosition.z, this->m_currentCameraAngle.yaw);
// The XYZ current position is on port 7
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 7);
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, CRTP_PORT_XYZ_POS);
CCRTPPacket *crtpReceived = m_crRadio->sendPacket(m_nRadioChannel, crtpPacket, this);
delete crtpPacket;
......@@ -172,7 +172,7 @@ bool CCrazyflie::sendPositionSetpoint() {
this->m_desiredPosition.z, this->m_desiredYaw);
// The XYZ setpoint is on port 6
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 6);
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, CRTP_PORT_XYZ_SET);
CCRTPPacket *crtpReceived = m_crRadio->sendPacket(m_nRadioChannel, crtpPacket, this);
delete crtpPacket;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment