3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).

Dependencies:   MCP23017 TCS3472_I2C WattBob_TextLCD mbed

commander.cpp

Committer:
dreamselec
Date:
2015-11-16
Revision:
6:98fe30430194
Parent:
5:6ef2d954fca3
Child:
7:b6e31bfdb2af

File content as of revision 6:98fe30430194:

//
// commander.cpp
// Created by Chandan Siyag on 14/11/2015.
#include <iostream>
#include <string>
#include "commander.h"

using namespace std;

Commander::Commander() {
	typeChar = '\0';
	typeRaw = CommandTypeRaw::Invalid;
}

Commander::~Commander() {
	
}

void Commander::decodeCommand(CommandTypeRaw type){
	this->typeRaw = type;
	this->typeChar = CommandTypeValue[type];
	
	this->readCommandObject();
	
	char nextChar = '\0';
	char commandCharArray [79] = "";
	int i = 0;
	while (i < 79) {
		scanf("%1c", &nextChar);
		if (nextChar == '\n' || nextChar == '\r' || nextChar == ' ') { continue; }
		else if (nextChar == kCommandTerminator) { break; }
		commandCharArray[i] = nextChar;
		i++;
	}
	
	string tempStr(commandCharArray);
	this->command = tempStr;
	
	return;
}

std::string Commander::description(){
	string str;
	str.append("Command type:\t");
	str.append(&this->typeChar);
	str.append("\nCommand object:\t" + this->object + "\n" + "Command:\t\t" + this->command + " \n");
	
	return str;
}

void Commander::readCommandObject(){
	char objectInitiator = '<';
	char objectTerminator = '>';
	
	char nextChar = '\0';
	
	do {
		scanf("%1c", &nextChar);
	} while (nextChar != objectInitiator);
	
	char objectCharArray [20] = "";
	int i = 0;
	while (i < 20) {
		scanf("%1c", &nextChar);
		if (nextChar == '\n' || nextChar == '\r' || nextChar == ' ') { continue; }
		if (nextChar == objectTerminator)
			break;
		objectCharArray[i] = nextChar;
		i++;
	}
	string tempStr(objectCharArray);
	this->object = tempStr;
	
	return;
}

//string parseReply(Command *cmd){
//    
//}