#ifndef __NETWORK_H_INCLUDED__
#define __NETWORK_H_INCLUDED__

#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

/*** CONSTANTS ***/
const int Fixed_Byte_To_Checksum = 25; // the first byte is not considered in the calculation of "BYTE 2"
const int CONTROL_DATA_LEN = 27;
char * const dp5[8] = { "ML_1", "ML_2", "ML_3", "ML_4", "ML_5",
                                                "ML_6", "HOV_Lane", "FYW_Conn"};
char * const dp6[8] = { "OS_1", "OS_2", "OS_3", "OS_4", "OS_5",
                                                "OS_6", "COLL_DIST_2", "COLL_DIST_OFF"};
char * const dp7[8] = { "DEMAND", "PASSAGE", "QUEUE", "RAMP_ON",
                                                "RAMP_OFF", "RAMP_HOV", "COLL_DIST_1", "COLL_DIST_ON"};
char * const dp8[8] = { "SD_1", "SD_2", "SD_3", "SD_4", "SD_5",
                                                "SD_6", "Pass_Vol_Count", "X"};

/*** NETWORK STRUCTS ***/
typedef struct loopagg LOOPAGG;
struct loopagg
{
	int		index;
	char	lane;			// how namy lanes at the detector station
	long	time;
	int		interval;
	int 	g_vol;
	float	g_occ;
	double	g_spd;
	int		*vol;
	float	*occ;
	double	*spd;
};

// FEP line: has several lds
typedef struct fep_line FEP_LINE;
struct  fep_line
{
	int		lineNum;
	vector<long> lds;
	vector<long> ldsIndex;	// location in ldsMap
	short	ldsNum;			// actual number of lds on the line

	short	count;	// actual count from caltrans
	int		schedule;
	int		lineInfo;
	long	systemKey;
	long	globalSeq;
	long	schedleSeq;
};

// Loop detector station: has several loops
typedef struct Lds_loop LDS_LOOP;
struct  Lds_loop
{
	// Each lds has its own line_num and drop (Caltrans use)
	long	lds;
	short	line_num;
	short	drop;

	int		num;	// number of loops
	long	*loopID;
	char	**loop_loc;

	// LDS data
	unsigned char	*dataPack;
	int		length;		// total length of data (max: 87)
	int		pos;		// pointer for data preparation
	int		MlTotVol;	// each 30 sec, the following will be updated
	int		OppTotVol;	// each 30 sec, the following will be updated
};

#endif
