#include "AiboInfoPkg.h"

AiboInfoPkg::AiboInfoPkg() : TelepatiPkg(){
  type=INFO;
  numOfAibo=0;
  aiboActive=0;
}

AiboInfoPkg::AiboInfoPkg(aiboState* aiboAct, int aiboNum, int a) : TelepatiPkg(){
  type=INFO;
  aibo=a;
  numOfAibo=aiboNum;
  aiboActive=new aiboState[numOfAibo];
  for(int i=0; i< numOfAibo; i++)
    aiboActive[i]=aiboAct[i];
}

AiboInfoPkg::AiboInfoPkg(byte* ptr) : TelepatiPkg(ptr){
  numOfAibo=(int)ptr[STD_HEADER_SIZE];
  aiboActive=new aiboState[numOfAibo];
  for(int i=0; i<numOfAibo; i++)
    aiboActive[i]=(aiboState)ptr[(STD_HEADER_SIZE+1)+i];
}

AiboInfoPkg::~AiboInfoPkg(){
  delete [] aiboActive;
}


TelepatiPkg* AiboInfoPkg::clone(){
  AiboInfoPkg* clone=new AiboInfoPkg(aiboActive, numOfAibo, aibo);
  clone->serialNum=serialNum;
  return clone;
}

byte* AiboInfoPkg::getMsg(){
  delete [] message;
  message=createStdHeader(1+numOfAibo);
  message[STD_HEADER_SIZE]=(byte)numOfAibo;
  for(int i= 0; i<numOfAibo; i++)
    message[(STD_HEADER_SIZE+1)+i]=aiboActive[i];
  return message;
}

bool AiboInfoPkg::isAllActive(){
  int allActive=0;
  
  for(int i=0; i<numOfAibo; i++){
    allActive+=((aiboActive[i] == ACTIVE || aiboActive[i] == WAITINGREPLY) ? 1: 0);    
  }
  
  if(allActive == numOfAibo && numOfAibo != 0)
    return true;
  else
    return false;
}
