/***************************************************************************************
*	This software simulated for ARPEEC, a routing protocol for Wireless Sensor Network *
*	Copyright (C) 2007 by Tran Quang Vinh (vinhtq@mail.hut.edu.vn)                     *
*	Multimedia Information NETwork Lab - MINET                                         *
*	Dept. Electronic Information Systems, Graduate School of Enginnering               *
*	Shibaura Institute of Technology, Japan.                                           *
*--------------------------------------------------------------------------------------*
*	File name: BaseStation.h													           *
*	header file for bs_RAPEEC.cpp to implement base station in the network             *
***************************************************************************************/

#ifndef BS_H
#define BS_H

#include <omnetpp.h>
#include "ArpeesDef.h"
#include "SensorNode.h"
#include "NodeModul.h"

class BaseStation : public NodeBase
{
    Module_Class_Members(BaseStation, NodeBase, 0);
    // this is a macro; it expands to constructor definition etc.
    // 0 says that we use MessageHandlers, not activity()

    void initNodes();
    virtual void initialize(void);
    virtual void handleMessage(cMessage * msg);
    void resetStatus();
    void createEvents();
	int selectClusterHead(int id);


	void finish();

    int xpos;                   // just for simulation
    int ypos;
    int nrStatusRec;            // number of received status
    struct _adv advInfo[NUMBERNODES+4];

    cModule *nodePtr[NUMBERNODES+4];

    int xMax;
    int yMax;
    int numNodes;
    int roundsDone;
    int nrRounds;
    int firstDead;
	int redunNode;
    int roundTimes[NUMBERROUND];        // times when round starts
    int deadRound[NUMBERROUND];
    int nrHeads[NUMBERROUND];
	int totalDeadNodes[NUMBERROUND];
	int totalRedundance[NUMBERROUND];
	double totalEnRemain[NUMBERROUND];// stored energy remain after each round 


    int calledEnd;
    int halfDead;
    int halfDeadCtr;
    int oldDeadNodes;
    int deadNodes;
    double P;
    int cHeadsRound;
};

#endif
/************************************************************************************/
