/***************************************************************************************
*	This software simulated for ARPEES, 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: SensorNode.h													           *
*	header file for implementing node in the network simulation                        *
***************************************************************************************/

#ifndef NODE_H
#define NODE_H

#include <omnetpp.h>
#include <string.h>
#include "ArpeesDef.h"
#include "NodeModul.h"
#include "BaseStation.h"

class SensorNode : public NodeBase
{
    Module_Class_Members(SensorNode, NodeBase, 0);
  protected:
    virtual void initialize();
    virtual void handleMessage(cMessage * msg);
    virtual void finish();

    void send2BS(int src, int rec, int energy, int status, int cluster,
		         int xpos, int ypos);
    void initNodes();
    void sendTDMA();
    void sendDataToCHead(int cluaterHead);
    
	void sendData2RN(int sender, int receiver);
	void sendData2BS(int sender);
    
	void energyReceive(int bits);
    void energyTransmit(int bits, int dist);

    void energyDataAggr(int signals);
	int selectRelayNode(int ID, int xPos, int yPos);

  public:
	int xpos;                   // just for simulation
    int ypos;
    int nrRounds;               // number of rounds (each round starts with setups)
    int nrFrames;               // number of "rounds in a round" (called frames)
    int curFrame;
    int frameTime;              // how many slots has one frame
	int hopCount;
	int trRange;
	int ssRange;
	int showHideRange;
	//string FILE_OBJ_TRACE;
	int kRequire;
	int protocol;
    int myData;
    int mySlot;                 // slot in current frame
    int bsId;                   // ID of base station
	int checkRedundance();
	int computeNeighbor();
	int neighber;

    double energy;              // energy in microJoule
    int headDist;               // distance from node to CH
    int bsDist;					// distance from node to BS
	int rnDist;					// distance from RN to BS
	double cosa;				// angle between RN-CH-BS
    int myCluster;              // to which cluster this node belongs
	int myAction;				// sleep/active/listen status


    int lastClusterRound;       // round when node was cluster head last time

    SensorNode *nodePtr[NUMBERNODES+3];
    int clusterNodes;

    int cHead;                  // flag denoting if I this node is cluster head
    int headId;                 // id of cluster head (my cluster)
	int relayId;				// id of relay node

    int myHead;

    int nrDataPackets;          // nr of data packets head has received in this frame
    //int sentBS;                 // how many status updates sent to BS by this node
    int wasHead;                // ctr denoting how often a node was cluster head
};

#endif

/************************************************************************************/
