// Class automatically generated by Dev-C++ New Class wizard

#include <protocol/packets/GroupPacket.h> // class's header file
#include <string.h>

namespace protocol {
namespace packets {

// class constructor
GroupPacket::GroupPacket(char groupid)
{
	this->groupid = groupid;
	// insert your code here
}

// class destructor
GroupPacket::~GroupPacket()
{
	// insert your code here
}

void GroupPacket::setInit(){
	this->setCommand(BP_INIT);
}

void GroupPacket::setReset(){
   	this->setCommand(BP_RESET);
}

void GroupPacket::setPing(){
	this->setCommand(BP_PING);
}

void GroupPacket::setError(){
	this->setCommand(BP_ERROR);
}

bool GroupPacket::isError(){
	return this->getCommand() == BP_ERROR;
}

char GroupPacket::getErrorCode(){
	char * data = this->getData();
	return data[0];
}

std::string GroupPacket::getErrorString(){
   	char * data = this->getData();
	char length = this->getDataLength();
	char i;
	std::string * out = new std::string();

	for ( i = 1 ; i < length ; i++ )
		out->append(1,data[i]);
	return *out;
}

void GroupPacket::prepareToSend(){
	this->setDestinationGroup(this->groupid);
	this->setOriginGroup(ORIGIN_GROUP);
	this->setOriginId(ORIGIN_ID);
	this->calculateCRC();
}

void GroupPacket::analysePacket(Packet * p){
	memcpy(this->getPacket(),p->getPacket(),p->getActualLength());
	this->refresh();
}

}
}

