141 lines
3.8 KiB
C++
141 lines
3.8 KiB
C++
#ifndef DVT_CMDHANDLERCLASS_H
|
|
#define DVT_CMDHANDLERCLASS_H
|
|
|
|
#include "DVT_GantryClass.h"
|
|
#include "DVT_VariacClass.h"
|
|
#include "DVT_MainClass.h"
|
|
#include "DVT_EncoderClass.h"
|
|
#include "DVT_FilamentClass.h"
|
|
#include "DVT_XRayClass.h"
|
|
|
|
typedef struct {
|
|
String Name;
|
|
int Value;
|
|
bool unknown;
|
|
int ID;
|
|
} cmd_t;
|
|
|
|
class CommandHandler{
|
|
private:
|
|
String cmdList[13];
|
|
public:
|
|
CommandHandler(String cmdList[13]){
|
|
for (int i = 0; i < sizeof(commandList) / sizeof(*commandList); i++) {
|
|
this->cmdList[i] = commandList[i];
|
|
}
|
|
}
|
|
void issueOrder(cmd_t cmd);
|
|
void Recognize(String cmdstr);
|
|
String GetCommandByID(int ID);
|
|
cmd_t lastCommand;
|
|
};
|
|
|
|
CommandHandler cmds = CommandHandler(commandList);
|
|
#endif
|
|
|
|
void CommandHandler::issueOrder(cmd_t cmd){
|
|
debugMSG("issueOrder");
|
|
|
|
switch (cmd.ID) {
|
|
case PULS:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
ENCODE.SetPos(cmd.Value);
|
|
break;
|
|
case ANGL:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
ENCODE.SetPos(cmd.Value * ENCODE.puls_per_angle);
|
|
break;
|
|
case SPCL:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
GANTRY.SetClSpeed(cmd.Value);
|
|
break;
|
|
case SPCC:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
GANTRY.SetCcSpeed(cmd.Value);
|
|
break;
|
|
case RES:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
ENCODE.Reset();
|
|
break;
|
|
case VARF:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
break;
|
|
case VARB:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
break;
|
|
case TEST:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
sysMSG(ENCODE.GetEncoderPos());
|
|
break;
|
|
case RXON:
|
|
XRAY.SetTime(cmd.Value);
|
|
XRAY.Signal();
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
break;
|
|
case STFI:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
FILAMENT.SetFilamentState(cmd.Value);
|
|
break;
|
|
case RXSH:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
break;
|
|
case SCAN:
|
|
CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value));
|
|
break;
|
|
}
|
|
}
|
|
|
|
void CommandHandler::Recognize(String cmdstr){
|
|
cmd_t cmdbuffer;
|
|
debugMSG("CommandRecognize");
|
|
cmdstr.toUpperCase();
|
|
cmdstr.replace("\n", "");
|
|
|
|
if (cmdstr.indexOf(';') > 0) {
|
|
cmdbuffer.Name = cmdstr.substring(0, cmdstr.indexOf(';'));
|
|
cmdbuffer.Value = cmdstr.substring(cmdstr.indexOf(';') + 1).toInt();
|
|
} else {
|
|
cmdbuffer.Name = cmdstr;
|
|
cmdbuffer.Value = 0;
|
|
}
|
|
|
|
for (int i = 0; i < sizeof(cmdList) / sizeof(*cmdList); i++) {
|
|
if (cmdbuffer.Name == cmdList[i]) {
|
|
cmdbuffer.unknown = false;
|
|
cmdbuffer.ID = i;
|
|
break;
|
|
} else {
|
|
cmdbuffer.unknown = true;
|
|
}
|
|
}
|
|
|
|
this->lastCommand = cmdbuffer;
|
|
debugMSG("Command Name : " + this->lastCommand.Name);
|
|
debugMSG("Command Value : " + String(this->lastCommand.Value));
|
|
|
|
switch (lastCommand.unknown) {
|
|
case 0:
|
|
debugMSG("Available");
|
|
break;
|
|
case 1:
|
|
debugMSG("Unknown Command");
|
|
break;
|
|
};
|
|
|
|
debugMSG(' ');
|
|
if (this->lastCommand.unknown) {
|
|
CONTROLMSG("Available Commandlist :");
|
|
for (int i = 0; i < sizeof(this->cmdList) / sizeof(*this->cmdList); i++) {
|
|
CONTROLMSG(this->cmdList[i]);
|
|
}
|
|
CONTROLMSG(' ');
|
|
} else {
|
|
this->issueOrder(this->lastCommand);
|
|
}
|
|
|
|
}
|
|
|
|
String CommandHandler::GetCommandByID(int ID){
|
|
return this->cmdList[ID];
|
|
}
|