Ejemplo n.º 1
0
static void 
precalculate() {

  real_t rad_per_sample;
  int note, k, p;
  for ( note = lo_note; note< hi_note; note++ ) {

	max_powers[note] = 0.0f;

	rad_per_sample = midi_note_to_radians_per_sample(SR, note);

	cos_precalc[note] = (real_t*)malloc ( 2*RINGBUFFERSIZE*N*sizeof(real_t));

	for ( p = 0, k = 0; k < (N*RINGBUFFERSIZE); k++ ) {
	  float win = window( k, RINGBUFFERSIZE * N);
	  cos_precalc[note][p++] = cos( rad_per_sample * (real_t) k ) * win;
	  cos_precalc[note][p++] = sin( rad_per_sample * (real_t) k ) * win;
	}

	weighting_ELC[note] = ra2(midi_note_to_hertz(note));

	if (print_freqs) 
	  fprintf(stderr, 
			  "note: %-3d weighting:%-5.1f freq:%.2f\n", 
			  note,  weighting_ELC[note], midi_note_to_hertz(note));
  }
}
Ejemplo n.º 2
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	try
	{
		CoInitialize(NULL); 
		string common_programs = get_special_folder_path(NULL, CSIDL_COMMON_PROGRAMS, true) + "\\Command & Conquer";
		CreateDirectory(common_programs.c_str(), NULL);
		Creg_key key_ea_games(HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA Games", KEY_QUERY_VALUE | KEY_SET_VALUE);
		Creg_key key_tfd(HKEY_LOCAL_MACHINE, "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer The First Decade", KEY_QUERY_VALUE);
		Creg_key key_westwood(HKEY_LOCAL_MACHINE, "SOFTWARE\\Westwood", KEY_QUERY_VALUE | KEY_SET_VALUE);
		try
		{
			Cgame td(key_tfd, "cc_");
			Creg_key(key_westwood, "Command & Conquer Windows 95 Edition", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", td.m_folder + "\\" + td.m_executable);
			create_shortcut(td.m_folder + "\\" + td.m_executable, td.m_args, common_programs + "\\Tiberian Dawn.lnk");
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame ra(key_tfd, "ra_");
			Creg_key(key_westwood, "Red Alert Windows 95 Edition", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", ra.m_folder + "\\" + ra.m_executable);
			create_shortcut(ra.m_folder + "\\" + ra.m_executable, ra.m_args, common_programs + "\\Red Alert.lnk");
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame ts(key_tfd, "ts_");
			Creg_key(key_westwood, "Tiberian Sun", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", ts.m_folder + "\\" + ts.m_executable);
			create_shortcut(ts.m_folder + "\\" + ts.m_executable, ts.m_args, common_programs + "\\Tiberian Sun.lnk");
			DeleteFile((ts.m_folder + "\\woldata.key").c_str());
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame ra2(key_tfd, "r2_");
			Creg_key(key_westwood, "Red Alert 2", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", ra2.m_folder + "\\" + ra2.m_executable);
			create_shortcut(ra2.m_folder + "\\" + ra2.m_executable, ra2.m_args, common_programs + "\\Red Alert 2.lnk");
			DeleteFile((ra2.m_folder + "\\woldata.key").c_str());
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame ra2_yr(key_tfd, "yr_");
			Creg_key(key_westwood, "Yuri's Revenge", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", ra2_yr.m_folder + "\\" + ra2_yr.m_executable);
			create_shortcut(ra2_yr.m_folder + "\\" + ra2_yr.m_executable, ra2_yr.m_args, common_programs + "\\Yuri's Revenge.lnk");
			DeleteFile((ra2_yr.m_folder + "\\woldata.key").c_str());
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame rg(key_tfd, "rn_");
			Creg_key(key_westwood, "Renegade", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", rg.m_folder + "\\" + rg.m_executable);
			create_shortcut(rg.m_folder + "\\" + rg.m_executable, rg.m_args, common_programs + "\\Renegade.lnk");
			DeleteFile((rg.m_folder + "\\woldata.key").c_str());
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame gr(key_tfd, "gr_");
			Creg_key(key_ea_games, "Generals", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", gr.m_folder + "\\");
			create_shortcut(gr.m_folder + "\\" + gr.m_executable, gr.m_args, common_programs + "\\Generals.lnk");
		}
		catch (exception&)
		{
		}
		try
		{
			Cgame gr_zh(key_tfd, "zh_");
			Creg_key(key_ea_games, "Command and Conquer Generals Zero Hour", KEY_QUERY_VALUE | KEY_SET_VALUE).set_value("InstallPath", gr_zh.m_folder + "\\" + gr_zh.m_executable);
			create_shortcut(gr_zh.m_folder + "\\" + gr_zh.m_executable, gr_zh.m_args, common_programs + "\\Zero Hour.lnk");
		}
		catch (exception&)
		{
		}
	}
	catch (exception&)
	{
		return 1;
	}
	return 0;
}
/*************************************************************************
Processing functions test
*************************************************************************/
static void testprocessing(int nkind,
     int nin,
     int nhid1,
     int nhid2,
     int nout,
     int ec,
     int passcount,
     bool& err)
{
    mlpensemble ensemble;
    mlpensemble ensemble2;
    bool zeronet;
    double a1;
    double a2;
    int pass;
    int i;
    bool allsame;
    int rlen;
    ap::real_1d_array x1;
    ap::real_1d_array x2;
    ap::real_1d_array y1;
    ap::real_1d_array y2;
    ap::real_1d_array ra;
    ap::real_1d_array ra2;
    double v;

    
    //
    // Prepare network
    //
    a1 = 0;
    a2 = 0;
    if( nkind==2 )
    {
        a1 = 1000*ap::randomreal()-500;
        a2 = 2*ap::randomreal()-1;
    }
    if( nkind==3 )
    {
        a1 = 1000*ap::randomreal()-500;
        a2 = a1+(2*ap::randominteger(2)-1)*(0.1+0.9*ap::randomreal());
    }
    
    //
    // Initialize arrays
    //
    x1.setbounds(0, nin-1);
    x2.setbounds(0, nin-1);
    y1.setbounds(0, nout-1);
    y2.setbounds(0, nout-1);
    
    //
    // Main cycle
    //
    for(pass = 1; pass <= passcount; pass++)
    {
        createensemble(ensemble, nkind, a1, a2, nin, nhid1, nhid2, nout, ec);
        
        //
        // Same inputs leads to same outputs
        //
        for(i = 0; i <= nin-1; i++)
        {
            x1(i) = 2*ap::randomreal()-1;
            x2(i) = x1(i);
        }
        for(i = 0; i <= nout-1; i++)
        {
            y1(i) = 2*ap::randomreal()-1;
            y2(i) = 2*ap::randomreal()-1;
        }
        mlpeprocess(ensemble, x1, y1);
        mlpeprocess(ensemble, x2, y2);
        allsame = true;
        for(i = 0; i <= nout-1; i++)
        {
            allsame = allsame&&y1(i)==y2(i);
        }
        err = err||!allsame;
        
        //
        // Same inputs on original network leads to same outputs
        // on copy created using MLPCopy
        //
        unsetensemble(ensemble2);
        mlpecopy(ensemble, ensemble2);
        for(i = 0; i <= nin-1; i++)
        {
            x1(i) = 2*ap::randomreal()-1;
            x2(i) = x1(i);
        }
        for(i = 0; i <= nout-1; i++)
        {
            y1(i) = 2*ap::randomreal()-1;
            y2(i) = 2*ap::randomreal()-1;
        }
        mlpeprocess(ensemble, x1, y1);
        mlpeprocess(ensemble2, x2, y2);
        allsame = true;
        for(i = 0; i <= nout-1; i++)
        {
            allsame = allsame&&y1(i)==y2(i);
        }
        err = err||!allsame;
        
        //
        // Same inputs on original network leads to same outputs
        // on copy created using MLPSerialize
        //
        unsetensemble(ensemble2);
        mlpeserialize(ensemble, ra, rlen);
        ra2.setbounds(0, rlen-1);
        for(i = 0; i <= rlen-1; i++)
        {
            ra2(i) = ra(i);
        }
        mlpeunserialize(ra2, ensemble2);
        for(i = 0; i <= nin-1; i++)
        {
            x1(i) = 2*ap::randomreal()-1;
            x2(i) = x1(i);
        }
        for(i = 0; i <= nout-1; i++)
        {
            y1(i) = 2*ap::randomreal()-1;
            y2(i) = 2*ap::randomreal()-1;
        }
        mlpeprocess(ensemble, x1, y1);
        mlpeprocess(ensemble2, x2, y2);
        allsame = true;
        for(i = 0; i <= nout-1; i++)
        {
            allsame = allsame&&y1(i)==y2(i);
        }
        err = err||!allsame;
        
        //
        // Different inputs leads to different outputs (non-zero network)
        //
        for(i = 0; i <= nin-1; i++)
        {
            x1(i) = 2*ap::randomreal()-1;
            x2(i) = 2*ap::randomreal()-1;
        }
        for(i = 0; i <= nout-1; i++)
        {
            y1(i) = 2*ap::randomreal()-1;
            y2(i) = y1(i);
        }
        mlpeprocess(ensemble, x1, y1);
        mlpeprocess(ensemble, x2, y2);
        allsame = true;
        for(i = 0; i <= nout-1; i++)
        {
            allsame = allsame&&y1(i)==y2(i);
        }
        err = err||allsame;
        
        //
        // Randomization changes outputs (when inputs are unchanged, non-zero network)
        //
        for(i = 0; i <= nin-1; i++)
        {
            x1(i) = 2*ap::randomreal()-1;
            x2(i) = 2*ap::randomreal()-1;
        }
        for(i = 0; i <= nout-1; i++)
        {
            y1(i) = 2*ap::randomreal()-1;
            y2(i) = y1(i);
        }
        mlpecopy(ensemble, ensemble2);
        mlperandomize(ensemble2);
        mlpeprocess(ensemble, x1, y1);
        mlpeprocess(ensemble2, x1, y2);
        allsame = true;
        for(i = 0; i <= nout-1; i++)
        {
            allsame = allsame&&y1(i)==y2(i);
        }
        err = err||allsame;
        
        //
        // Normalization properties
        //
        if( nkind==1 )
        {
            
            //
            // Classifier network outputs are normalized
            //
            for(i = 0; i <= nin-1; i++)
            {
                x1(i) = 2*ap::randomreal()-1;
            }
            mlpeprocess(ensemble, x1, y1);
            v = 0;
            for(i = 0; i <= nout-1; i++)
            {
                v = v+y1(i);
                err = err||y1(i)<0;
            }
            err = err||fabs(v-1)>1000*ap::machineepsilon;
        }
        if( nkind==2 )
        {
            
            //
            // B-type network outputs are bounded from above/below
            //
            for(i = 0; i <= nin-1; i++)
            {
                x1(i) = 2*ap::randomreal()-1;
            }
            mlpeprocess(ensemble, x1, y1);
            for(i = 0; i <= nout-1; i++)
            {
                if( a2>=0 )
                {
                    err = err||y1(i)<a1;
                }
                else
                {
                    err = err||y1(i)>a1;
                }
            }
        }
        if( nkind==3 )
        {
            
            //
            // R-type network outputs are within [A1,A2] (or [A2,A1])
            //
            for(i = 0; i <= nin-1; i++)
            {
                x1(i) = 2*ap::randomreal()-1;
            }
            mlpeprocess(ensemble, x1, y1);
            for(i = 0; i <= nout-1; i++)
            {
                err = err||y1(i)<ap::minreal(a1, a2)||y1(i)>ap::maxreal(a1, a2);
            }
        }
    }
}
/**
 * \brief Main function in astro namespace
 */
int	main(int argc, char *argv[]) {
	int	c;
	double	gamma = 1.0;
	double	minimum = -1.;
	double	maximum = -1.;
	bool	force = false;

	// parse the command line
	int	longindex;
	while (EOF != (c = getopt_long(argc, argv, "df?hm:M:g:", longopts, &longindex)))
		switch (c) {
		case 'd':
			debuglevel = LOG_DEBUG;
			break;
		case 'f':
			force = true;
			break;
		case 'g':
			gamma = std::stod(optarg);
			break;
		case 'm':
			minimum = std::stod(optarg);
			break;
		case 'M':
			maximum = std::stod(optarg);
			break;
		case '?':
		case 'h':
			usage(argv[0]);
			return EXIT_SUCCESS;
			break;
		default:
			throw std::runtime_error("unknown option");
		}

	// two more arguments are required: infile and outfile
	if (2 != argc - optind) {
		std::string	msg("wrong number of arguments");
		debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str());
		throw std::runtime_error(msg);
	}
	std::string	infilename(argv[optind++]);
	std::string	outfilename(argv[optind]);
	debug(LOG_DEBUG, DEBUG_LOG, 0, "calibrate %s to %s",
		infilename.c_str(), outfilename.c_str());

	// read the infile
	FITSin	infile(infilename);
	ImagePtr	image = infile.read();

	// convert pixels according to luminance
	ConstPixelValueAdapter<double>	from(image);

	// get the minimum and maximum values from the input image
	if (maximum < 0) {
		maximum = Max<double, double>()(from);
	}
	if (minimum < 0) {
		minimum = Min<double, double>()(from);
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "min = %f, max = %f",
		minimum, maximum);

	// clamping filter
	ClampingAdapter<double, double>	ca(from, minimum, maximum);

	// rescaling
	double	scale = 1. / (maximum - minimum);
	RescalingAdapter<double>	ra(ca, minimum, scale);

	// gamma correction
	GammaAdapter<double>	ga(ra, gamma);

	// rescale back to the range 0-255
	RescalingAdapter<double>	ra2(ga, 0, 255.);

	// create image from last adapter
	Image<double>	*outimage = new Image<double>(ra2);
	ImagePtr	outimageptr(outimage);

	// remove previous file
	if (force) {
		unlink(outfilename.c_str());
	}

	// after all the calibrations have been performed, write the output
	// file
	FITSout	outfile(outfilename);
	outfile.write(outimageptr);

	// that's it
	return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
/** The RadiusClass is C++ library for RADIUS authentication and accounting.
 * Features:
 * - Sending and Receiving RADIUS packets.
 * - Generates password and authentication packet fields at sending, 
 * 		you only need to set the plain text password for the user for ACCESS_REQUEST packets
 * - password length optional
 * - timeouts for waiting on response packets
 * - sending retries if no response from server
 * - sending to optional number of servers:
 * 		- the first server from the config file is taken
 * 			- config parameter: e.g. wait=5 : wait 5s on a response
 * 			- config parameter: e.g. retry=2 : retry sending the packet 2 times after timeout
 * 		- if the first server do not response -> take the next server from config file
 * - extract attributes from the response packet, e.g. FramedIp or FramedRoutes
 * - functions to convert values from the response packets for integers and ip address as string (see function parseResponsePacket())
 **/
int main_test (void)
{
	
	list<RadiusServer> * serverlist;
	list<RadiusServer>::iterator server;
	//create RadiusPacket: you can already specify the type
	RadiusPacket		packet_access(ACCESS_REQUEST);
	
	//the packets for accounting (start,update,stop)
	RadiusPacket		packet_accounting_start(ACCOUNTING_REQUEST);
	RadiusPacket		packet_accounting_update(ACCOUNTING_REQUEST);
	RadiusPacket		packet_accounting_stop(ACCOUNTING_REQUEST);
	
	//create RadiusAttributes: you can specify type and value.
	RadiusAttribute		ra1(ATTRIB_User_Name,"user1"),
						ra2(ATTRIB_User_Password),
						ra3(ATTRIB_NAS_Port,55),
						ra4(ATTRIB_Calling_Station_Id,"127.0.0.1"),
						ra5(ATTRIB_NAS_Identifier),
						ra6(ATTRIB_NAS_IP_Address),
						ra7(ATTRIB_NAS_Port_Type),
						ra8(ATTRIB_Service_Type),
						ra9(ATTRIB_Framed_IP_Address),
						ra10(ATTRIB_Acct_Session_ID, 99),
						//for accounting packet type (start/update/stop)
						ra11(ATTRIB_Acct_Status_Type),
						ra12(ATTRIB_Framed_Protocol),
						
						//for accounting update and stop packets
						ra13(ATTRIB_Acct_Input_Octets, 99),
						ra14(ATTRIB_Acct_Output_Octets, 10),
						ra15(ATTRIB_Acct_Session_Time, 12345),
						ra16(ATTRIB_Vendor_Specific);
						
	RadiusVendorSpecificAttribute rvsa;
	
	//read in the config
	RadiusConfig config(string("./exampleconfig"));
	
	cout << "*** Sampleprogramm for the RadiusClass. ***\n";
	cout << "---- Print Config ----\n";
	cout << config;
	cout << "-----------------------\n";
	
	// Send a ACCEPT-REQUEST-PACKET
	cout << "-----------------------------------------------------\n";
	cout << "-------- Send a ACCESS-REQUEST-PACKET ---------------\n";
	cout << "-----------------------------------------------------\n";
	
	/*set password (the method setValue() detects which type
	 * the attribut is from, and converts the value correct for
	 * this type)
	 */
	ra2.setValue(string("testing"));
	if(packet_access.addRadiusAttribute(&ra1))
	{
		cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_User_Name.\n";
	}
	if (packet_access.addRadiusAttribute(&ra2))
	{
		cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_User_Password.\n";
	}
	if (packet_access.addRadiusAttribute(&ra3))
	{
		cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_NAS_Port.\n";
	}
	if (packet_access.addRadiusAttribute(&ra4))
	{
		cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_Calling_Station_Id.\n";
	}
	//get information from the config and add it to the packet
	if(strcmp(config.getNASIdentifier(),""))
	{
			ra5.setValue(config.getNASIdentifier());
			if (packet_access.addRadiusAttribute(&ra5))
			{
				cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_NAS_Identifier.\n";
			}
	}
	
	if(strcmp(config.getNASIpAddress(),""))
	{
			if(ra6.setValue(config.getNASIpAddress())!=0)
			{
				cerr << getTime() << "RADIUS-CLASS: Fail to set value ATTRIB_NAS_Ip_Address.\n";
			}
			else
			if (packet_access.addRadiusAttribute(&ra6))
			{
				cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_NAS_Ip_Address.\n";
			}
	}
	if(strcmp(config.getNASPortType(),""))
	{
			ra7.setValue(config.getNASPortType());
			if (packet_access.addRadiusAttribute(&ra7))
			{
				cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_NAS_Port_Type.\n";
			}
	}
	
	if(strcmp(config.getServiceType(),""))
	{
			ra8.setValue(config.getServiceType());
			if (packet_access.addRadiusAttribute(&ra8))
			{
				cerr << getTime() << "RADIUS-CLASS: Fail to add attribute ATTRIB_Service_Type.\n";
			}
	}
	
	//example for sending vendor specific attribute
	rvsa.setId(123);
	rvsa.setType(1);
	rvsa.setValue("Vendor Attribute");
	//integers can be set directly
	//rvsa.setValue(1981);
	Octet * tmp_rvsa=new Octet[rvsa.getLength()+4];
	
	rvsa.getShapedAttribute(tmp_rvsa);
	ra16.setValue((char *)tmp_rvsa);
	
	packet_access.addRadiusAttribute(&ra16);
	
	delete [] tmp_rvsa;
	
	
	//get the server list
	serverlist=config.getRadiusServer();
	
	//check if there are servers
	try
	{
		if(serverlist->empty()==true)
		{
			throw(string("RADIUS-CLASS: No servers defined!"));
		}
	}
	catch(string)
	{
		cerr<< "No servers!";
		//stop the programm if there are no server(s) in config
		return 0;
	}
	
	//set server to the first server
	server=serverlist->begin();
	
	//send the packet to the first server from the list
	if (packet_access.radiusSend(server)<0)
	{
		cerr << getTime() << "RADIUS-CLASS: Packet was not send.\n";
	}
	
	//receive the packet, if the server doesn't response send the packet to the next server in list.
	if (packet_access.radiusReceive(serverlist)==0)
	{
		//is it a accept?
		if(packet_access.getCode()==ACCESS_ACCEPT)
		{
			/*Parse the attributes for framedip, framedroutes and acctinteriminterval.
			This is only an example, so the function has no return values, the
			values are printed at stdout.*/
			parseResponsePacket(&packet_access);
				
		}
		//If the radius server denied the access or sends a ACCESS_CHALLANGE-packet.
		else
		{
			cerr << getTime() << "RADIUS-CLASS: Get ACCESS_REJECT or ACCESS_CHALLANGE-Packet.->ACCESS-DENIED.\n";
		}
		
	}
	else
	{
		cerr << getTime() << "RADIUS-CLASS: Got no or bad response from radius server.\n";
	}
	
	
	// Send a ACCOUNTING-REQUEST-PACKET, Status-Type:Start
	
	cout << "-----------------------------------------------------\n";
	cout << "-------- Send a ACCOUNTING-REQUEST-PACKET -----------\n";
	cout << "-----------------Status-Type: Start------------------\n";
	cout << "-----------------------------------------------------\n";
	
	
	//add the attributes to the packet
	if(packet_accounting_start.addRadiusAttribute(&ra1))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_User_Name.\n";
	}
	
	
	if (packet_accounting_start.addRadiusAttribute(&ra3))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Port.\n";
	}
	if (packet_accounting_start.addRadiusAttribute(&ra4))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Calling_Station_Id.\n";
	}
	
	
	
	if (packet_accounting_start.addRadiusAttribute(&ra10))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Session_Id.\n";
	}
	
	//set status type: start = 1 (see RADIUS RFC)
	ra11.setValue(string("1"));
	if (packet_accounting_start.addRadiusAttribute(&ra11))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Status_Type.\n";
	}
	
	
	//get information from the config and add the attributes to the packet
	if(strcmp(config.getNASIdentifier(),""))
	{
			ra5.setValue(config.getNASIdentifier());
			if (packet_accounting_start.addRadiusAttribute(&ra5))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Identifier.\n";
			}
	}
	
	if(strcmp(config.getNASIpAddress(),""))
	{
			if(ra6.setValue(config.getNASIpAddress())!=0)
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to set value ATTRIB_NAS_Ip_Address.\n";
			}
	
			if (packet_accounting_start.addRadiusAttribute(&ra6))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Ip_Address.\n";
			}
	}
	if(strcmp(config.getNASPortType(),""))
	{
			ra7.setValue(config.getNASPortType());
			if (packet_accounting_start.addRadiusAttribute(&ra7))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Port_Type.\n";
			}
	}
	
	if(strcmp(config.getServiceType(),""))
	{
			ra8.setValue(config.getServiceType());
			if (packet_accounting_start.addRadiusAttribute(&ra8))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Service_Type.\n";
			}
	}
	if(strcmp(config.getFramedProtocol(),""))
	{
			ra12.setValue(config.getFramedProtocol());
			if (packet_accounting_start.addRadiusAttribute(&ra12))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_FramedProtocol.\n";
			}
	}
	ra9.setValue(string("111.222.111.111"));
	if (packet_accounting_start.addRadiusAttribute(&ra9))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Session_ID.\n";
	}
	
	
	
	//send the packet_accounting_start	
	if (packet_accounting_start.radiusSend(server)<0)
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Packet was not send.\n";
	}
	
	//receive the response
	if (packet_accounting_start.radiusReceive(serverlist)>=0)
	{
		//is is a accounting resopnse ?
		if(packet_accounting_start.getCode()==ACCOUNTING_RESPONSE)
		{
			cerr << getTime() << "RADIUS-CLASS:  Get ACCOUNTING_RESPONSET-Packet.\n";

		}
	}	
	else
	{
		cerr << getTime() << "RADIUS-CLASS: Got no or bad response from radius server.\n";
	}
	
	// Send a ACCOUNTING-REQUEST-PACKET, Status-Type:Update
	
	cout << "-----------------------------------------------------\n";
	cout << "-------- Send a ACCOUNTING-REQUEST-PACKET -----------\n";
	cout << "-----------------Status-Type: Update-----------------\n";
	cout << "-----------------------------------------------------\n";
	
	//add the attributes to the packet
	if(packet_accounting_update.addRadiusAttribute(&ra1))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_User_Name.\n";
	}
	
	
	if (packet_accounting_update.addRadiusAttribute(&ra3))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Port.\n";
	}
	if (packet_accounting_update.addRadiusAttribute(&ra4))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Calling_Station_Id.\n";
	}
	
	
	
	
	if (packet_accounting_update.addRadiusAttribute(&ra10))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Session_Id.\n";
	}
	
	//set status type: update = 3(see RADIUS RFC)
	ra11.setValue(string("3"));
	if (packet_accounting_update.addRadiusAttribute(&ra11))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Status_Type.\n";
	}
	
	
	
	if (packet_accounting_update.addRadiusAttribute(&ra13))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Input_Octets.\n";
	}
	if (packet_accounting_update.addRadiusAttribute(&ra14))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Output_Octets.\n";
	}
	if (packet_accounting_update.addRadiusAttribute(&ra14))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Session_Time.\n";
	}
	
	//get information from the config and add the attributes to the packet
	if(strcmp(config.getNASIdentifier(),""))
	{
			ra5.setValue(config.getNASIdentifier());
			if (packet_accounting_update.addRadiusAttribute(&ra5))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Identifier.\n";
			}
	}
	
	if(strcmp(config.getNASIpAddress(),""))
	{
			if(ra6.setValue(config.getNASIpAddress())!=0)
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to set value ATTRIB_NAS_Ip_Address.\n";
			}
	
			if (packet_accounting_update.addRadiusAttribute(&ra6))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Ip_Address.\n";
			}
	}
	if(strcmp(config.getNASPortType(),""))
	{
			ra7.setValue(config.getNASPortType());
			if (packet_accounting_update.addRadiusAttribute(&ra7))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Port_Type.\n";
			}
	}
	
	if(strcmp(config.getServiceType(),""))
	{
			ra8.setValue(config.getServiceType());
			if (packet_accounting_update.addRadiusAttribute(&ra8))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Service_Type.\n";
			}
	}
	if(strcmp(config.getFramedProtocol(),""))
	{
			ra12.setValue(config.getFramedProtocol());
			if (packet_accounting_update.addRadiusAttribute(&ra12))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_FramedProtocol.\n";
			}
	}
	ra9.setValue(string("111.222.111.111"));
	if (packet_accounting_update.addRadiusAttribute(&ra9))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Session_ID.\n";
	}
	
	
	
	//send the packet_accounting_update	
	if (packet_accounting_update.radiusSend(server)<0)
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Packet was not send.\n";
	}
	
	//receive the response
	if (packet_accounting_update.radiusReceive(serverlist)>=0)
	{
		//is is a accounting resopnse ?
		if(packet_accounting_update.getCode()==ACCOUNTING_RESPONSE)
		{
			cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Get ACCOUNTING_RESPONSET-Packet.\n";

		}
		
		
	}
	else
	{
		cerr << getTime() << "RADIUS-CLASS: Got no or bad response from radius server.\n";
	}
	
	// Send a ACCOUNTING-REQUEST-PACKET, Status-Type:Stop
	
	cout << "-----------------------------------------------------\n";
	cout << "-------- Send a ACCOUNTING-REQUEST-PACKET -----------\n";
	cout << "-----------------Status-Type: Stop-------------------\n";
	cout << "-----------------------------------------------------\n";
	
	//add the attributes to the packet
	if(packet_accounting_stop.addRadiusAttribute(&ra1))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_User_Name.\n";
	}
	
	
	if (packet_accounting_stop.addRadiusAttribute(&ra3))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Port.\n";
	}
	if (packet_accounting_stop.addRadiusAttribute(&ra4))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Calling_Station_Id.\n";
	}
	
	
	
	
	if (packet_accounting_stop.addRadiusAttribute(&ra10))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Session_Id.\n";
	}
	
	//set status type: update = 2(see RADIUS RFC)
	ra11.setValue(string("2"));
	if (packet_accounting_stop.addRadiusAttribute(&ra11))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Status_Type.\n";
	}
	
	
	
	if (packet_accounting_stop.addRadiusAttribute(&ra13))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Input_Octets.\n";
	}
	if (packet_accounting_stop.addRadiusAttribute(&ra14))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Output_Octets.\n";
	}
	if (packet_accounting_stop.addRadiusAttribute(&ra14))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Session_Time.\n";
	}
	
	//get information from the config and add the attributes to the packet
	if(strcmp(config.getNASIdentifier(),""))
	{
			ra5.setValue(config.getNASIdentifier());
			if (packet_accounting_stop.addRadiusAttribute(&ra5))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Identifier.\n";
			}
	}
	
	if(strcmp(config.getNASIpAddress(),""))
	{
			if(ra6.setValue(config.getNASIpAddress())!=0)
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to set value ATTRIB_NAS_Ip_Address.\n";
			}
	
			if (packet_accounting_stop.addRadiusAttribute(&ra6))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Ip_Address.\n";
			}
	}
	if(strcmp(config.getNASPortType(),""))
	{
			ra7.setValue(config.getNASPortType());
			if (packet_accounting_stop.addRadiusAttribute(&ra7))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_NAS_Port_Type.\n";
			}
	}
	
	if(strcmp(config.getServiceType(),""))
	{
			ra8.setValue(config.getServiceType());
			if (packet_accounting_stop.addRadiusAttribute(&ra8))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Service_Type.\n";
			}
	}
	if(strcmp(config.getFramedProtocol(),""))
	{
			ra12.setValue(config.getFramedProtocol());
			if (packet_accounting_stop.addRadiusAttribute(&ra12))
			{
				cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_FramedProtocol.\n";
			}
	}
	ra9.setValue(string("111.222.111.111"));
	if (packet_accounting_stop.addRadiusAttribute(&ra9))
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Fail to add attribute ATTRIB_Acct_Session_ID.\n";
	}
	
	
	
	//send the packet_accounting_stop	
	if (packet_accounting_stop.radiusSend(server)<0)
	{
		cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Packet was not send.\n";
	}
	
	//receive the response
	if (packet_accounting_stop.radiusReceive(serverlist)>=0)
	{
		//is is a accounting resopnse ?
		if(packet_accounting_stop.getCode()==ACCOUNTING_RESPONSE)
		{
			cerr << getTime() << "RADIUS-CLASS: BACKGROUND-ACCT:  Get ACCOUNTING_RESPONSET-Packet.\n";

		}
	}
	else
	{
		cerr << getTime() << "RADIUS-CLASS: Got no or bad response from radius server.\n";
	}
	
	cout << "\n---- End ----";
	return (0);


}