示例#1
0
文件: test1.c 项目: Mric26/M2-S1
int main() {
	stats();
	print_part1();
	set_log(1);
	print_part1();
	set_log(0);
	stats();
	return 0;
}
示例#2
0
int main( int argc, char **argv )
{
	void *pTaskHandle = NULL;
	
	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );

	if( init_session(  ) < 0 )
		return -1;
		
	pTaskHandle = create_task( task_test, 5, 100 );
	if ( pTaskHandle )
	{
		CMessage stMsg;
		
		memset( &stMsg, 0x00, sizeof(stMsg) );
		
		post_task_msg( pTaskHandle, &stMsg );
		
		log_print( "create task ok................." );
	}
	else 
		log_print( "create task failed?????????????????????" );
	
	while ( 1 )
		os_sleep( 1000 );
		
	release_session(  );
	
	return 0;	
}
示例#3
0
__PUBLIC__ int main(int argc, const char* const* argv) {
   init();

   config = circus_config_read(stdlib_memory, "cgi.conf");
   int status = 0;

   assert(config != NULL);

   set_log(config);
   if (LOG == NULL) {
      config->free(config);
      exit(1);
   }
   log_info(LOG, "Client starting.");
   log_info(LOG, "Configuration file is %s", config->path(config));

   if (argc != 1) {
      usage(argv[0], stderr);
      status = 1;
   } else {
      run();
   }

   LOG->free(LOG);
   config->free(config);
   return status;
}
示例#4
0
strategy_t configure_server(int argc,char *argv[])
{
	int option,option_count=0;
	strategy_t operation;
	s_start(&total_uptime);

	while((option = getopt(argc,argv,"p:d:w:q:ftv:"))!=-1)
	{
		switch (option)
		{
			case 'p':
				port_number = atoi(optarg);
				break;
			case 'd':
				strcpy(path_root,optarg);
				break;
			case 't': 
				strcpy(strategy_name,"Threads");
				operation = &perform_thread_operation;
				option_count++;
				break;
			case 'f':
				strcpy(strategy_name,"Fork(Using processes)");
				operation = &perform_process_operation;
				option_count++;
				break;
			case 'w':
				strcpy(strategy_name,"Thread Pool");
				worker_max = atoi(optarg);
				operation = &perform_thread_pool_operation;
				option_count++;
				break;
			case 'q':
				buffer_max = atoi(optarg);
				break;
			case 'v':
				set_log(optarg);
				break;
			default:
				print_log(ERROR,"Please enter the right arguments\n");
				break;
		}
	}
	if(option_count > 1)
	{
		print_log(ERROR,"\nDon't pass arguments to use more than one strategy.\n");
		exit(0);
	}
	
	if(!check_folder_exists(path_root)) exit(0);
	
	if(option_count ==0) 
	{	
		operation = &perform_serially;
		strcpy(strategy_name,"Serial Operation");
	}
	return operation;
}
示例#5
0
int main( int argc, char **argv )
{
	void *pShineHandle = NULL;
	CShineParam stShineParam;
	const int8_t *pShineServerIP = "192.168.1.100";
	const int16u_t iShineServerPort = 9000;
	const int8_t *pShineId = "dsflseewfreeeeeeeeee";

	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );
	
	
	if ( init_shine(  ) < 0 )
		return -1;
		
	//
//	void *open_shine( const CShineParam *pShineParam );
	
	memset( &stShineParam, 0x00, sizeof(stShineParam) );
	memcpy( stShineParam.pServerIP, pShineServerIP, strlen(pShineServerIP) + 1 );
	stShineParam.iServerPort = iShineServerPort;
	
	memcpy( stShineParam.pLocalIP, pShineServerIP, strlen(pShineServerIP) + 1 );
	stShineParam.iLocalPort = 8001;
	
	memcpy( stShineParam.pShineId, pShineId, strlen(pShineId) + 1 );
	
	pShineHandle = open_shine( &stShineParam );
	if ( pShineHandle )
	{
		//int32_t open_shine_tunnel( void *pHandle, int8_t *pPeerShineId );
		int32_t iTunnelId = -1;

		log_print( "open shine ok................" );
			
		iTunnelId = open_shine_tunnel( pShineHandle, "134354325" );
		if ( iTunnelId >= 0 )
		{
			log_print( "open shine tunnel ok.............." );
		}
		else 	
			log_print( "open shine tunnel failed." );
	}
	
	while ( 1 )
		os_sleep( 1000 );
		
	release_shine(  );	
	
	return 0;	
}
示例#6
0
int main(int argc, char *argv[])
{
	const char *dir;
	char log[ECHECK_PATH_MAX + 1];
	int failures = 0;

	dir = (argc > 1) ? argv[1] : NULL;
	set_log(log, dir, "test_check_str_m");

	failures += test_check_str_m(log);

	if (failures) {
		fprintf(stderr, "%d failures in %s\n", failures, __FILE__);
	}
	return check_status(failures);
}
int main(int argc, char* argv[])
{

	print_title("BBN APS2 Sequence Player");

	argc-=(argc>0); argv+=(argc>0); // skip program name argv[0] if present
	option::Stats	stats(usage, argc, argv);
	option::Option *options = new option::Option[stats.options_max];
	option::Option *buffer = new option::Option[stats.buffer_max];
	option::Parser parse(usage, argc, argv, options, buffer);

	if (parse.error())
	 return -1;

	if (options[HELP] || argc == 0) {
		option::printUsage(std::cout, usage);
		return 0;
	}

	for (option::Option* opt = options[UNKNOWN]; opt; opt = opt->next())
	 std::cout << "Unknown option: " << opt->name << "\n";

	for (int i = 0; i < parse.nonOptionsCount(); ++i)
	 std::cout << "Non-option #" << i << ": " << parse.nonOption(i) << "\n";

	//Logging level
	TLogLevel logLevel = logINFO;
	if (options[LOG_LEVEL]) {
		logLevel = TLogLevel(atoi(options[LOG_LEVEL].arg));
	}

	//Trigger source -- default of internal
	APS2_TRIGGER_SOURCE triggerSource = INTERNAL;
	if (options[TRIG_MODE]) {
		triggerSource = APS2_TRIGGER_SOURCE(atoi(options[TRIG_MODE].arg));
	}
	set_logging_level(logLevel);
	set_log("stdout");

	//Trigger interval -- default of 10ms
	double trigInterval = 10e-3;
	if (options[TRIG_INTERVAL]) {
		trigInterval = atof(options[TRIG_INTERVAL].arg);
	}

	string seqFile;
	if (options[SEQ_FILE]){
		seqFile = string(options[SEQ_FILE].arg);
	} else {
		std::cerr << "A sequence file is required.";
		return -1;
	}

	string deviceSerial = get_device_id();
	if (deviceSerial.empty()){
		cout << concol::RED << "No APS2 devices connected! Exiting..." << concol::RESET << endl;
		return 0;
	}

	connect_APS(deviceSerial.c_str());

	double uptime;
	get_uptime(deviceSerial.c_str(), &uptime);

	cout << concol::CYAN << "Uptime for device " << deviceSerial << " is " << uptime << " seconds" << concol::RESET << endl;

	// force initialize device
	init_APS(deviceSerial.c_str(), 1);

	//load the sequence file
	load_sequence_file(deviceSerial.c_str(), seqFile.c_str());

	//Set the trigger mode
	set_trigger_source(deviceSerial.c_str(), triggerSource);

	//Trigger interval
	set_trigger_interval(deviceSerial.c_str(), trigInterval);

	//Set to sequence mode
	set_run_mode(deviceSerial.c_str(), RUN_SEQUENCE);

	run(deviceSerial.c_str());

	//For software trigger, trigger on key stroke
	if (triggerSource == 2) {
		cout << concol::YELLOW << "Press t-Return to trigger or q-Return to exit" << concol::RESET << endl;
		while(true) {
			char keyStroke = cin.get();
			if (keyStroke == 't') {
				trigger(deviceSerial.c_str());
			} else if (keyStroke == 'q') {
				break;
			}
		}
	}
	else {
		cout << concol::YELLOW << "Press any key to stop" << concol::RESET;
		cin.get();
	}


	stop(deviceSerial.c_str());
	disconnect_APS(deviceSerial.c_str());

	delete[] options;
	delete[] buffer;
	return 0;
 }
示例#8
0
int main( int argc, char **argv )
{
	int32_t iRetCode = -1;
	CReactor *iUDPReactorId = NULL;
	int8_t pLocalIP[32] = "225.0.0.37";
	CThread *acceptTid = NULL;
	
	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );
	
	if ( strlen( pLocalIP ) <= 0 )
		if ( net_get_local_ip( pLocalIP, sizeof( pLocalIP ) ) < 0 )
			return iRetCode;
	
	log_print( "%s %s:%d local ip-->%s\r\n", __FILE__, __FUNCTION__, __LINE__, pLocalIP );

	if ( init_pine_system(  ) < 0 )
		return iRetCode;
	
	iUDPReactorId = net_reactor(  );
	if ( iUDPReactorId )
	{
		if ( register_reactor_callback( iUDPReactorId, udp_reactor_callback, NULL ) < 0 )
		{	
			log_print( "%s %s:%d register reactor callback failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
			return iRetCode;
		}
		
		iUDPClientSocketId = net_socket( SOCKET_TYPE_DGRAM, 0 );
		if ( iUDPClientSocketId )
		{
			CNetAddr addr, stLocalAddr;
			char tempBuf[1024] = { 0x00, };
			int32_t iLen = 0;
			
			memset( &addr, 0x00, sizeof(addr) );
			memset( &stLocalAddr, 0x00, sizeof(stLocalAddr) );
			memcpy( addr.pIP, pLocalIP, strlen(pLocalIP) );
			addr.iPort = LOCAL_PORT;
			
			memcpy( stLocalAddr.pIP, pLocalIP, strlen(pLocalIP) );
			stLocalAddr.iPort = LOCAL_PORT + 1;

			if ( net_bind( iUDPClientSocketId, &stLocalAddr ) < 0 )
			{
				log_print( "%s %s:%d socket bind failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;	
			}
			else 
				log_print( "bind ok.............." );
				
			if ( net_connect( iUDPClientSocketId, &addr ) < 0 )
			{
				log_print( "%s %s:%d socket connect failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;	
			}
			else 
				log_print( "connect ok.............." );
			
			if ( add_reactor_socket( iUDPReactorId, iUDPClientSocketId, NULL ) < 0 )
			{
				log_print( "%s %s:%d set add reactor socket failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;	
			}
			else 
				log_print( "add reactor socket ok................." );
			
			if ( net_set_socket( iUDPClientSocketId, SOCKET_OPTION_NONE_BLOCK, NULL, 0 ) < 0 )
			{
				log_print( "%s %s:%d set socket none block failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;
			}
			else 
				log_print( "set socket none blocking ok....................." );
			
			
			log_print( "multicast client is running.............." );
			
			
			while ( fgets(tempBuf, sizeof(tempBuf), stdin) )
			{
				int32_t iOpRet = net_sendto( iUDPClientSocketId, tempBuf, strlen(tempBuf) + 1, &addr );	
				
				log_print( "udp client: iOpRet->%d", iOpRet );
			}
		}
	}

		
		
		while ( 1 )
			os_sleep( 1000 );
			
		net_close_reactor( iUDPReactorId );
	
		return 0;
}
示例#9
0
int main( int argc, char **argv )
{
	CSession *pSession = NULL;
	CSessionParam stSessionParam;
	const int8_t *pPeerIP = "www.lelsen.sinaapp.com";
	//const int8_t *pPeerIP = "www.baidu.com";
	const int8_t *pURL = "/business/api/punch.php";
	//const int8_t *pURL = "/index.html";
	const int16u_t iPeerPort = 80;
	
	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );
	
	pHandle = fopen( "./log.txt", "wb" );
	if ( !pHandle )
		return -1;
	
	if ( init_session(  ) < 0 )
		return -1;
	
	log_print( "init_session ok.................." );
		
	memset( &stSessionParam, 0x00, sizeof(stSessionParam) );
	memcpy( stSessionParam.pIP, pPeerIP, strlen(pPeerIP) + 1 );
	stSessionParam.iPort = iPeerPort;
	
	log_print( "start to create session............" );
	pSession = create_session( SESSION_TYPE_HTTP_CLIENT, &stSessionParam );
	
	if ( pSession )
	{
		log_print( "create tcp session ok................" );
		if ( set_session_business( pSession, stream_session_business, NULL ) >= 0 )
		{
			if ( set_session_event( pSession, stream_session_event ) >= 0 )
			{
				CHttpData stHttpData;
				
				memset( &stHttpData, 0x00, sizeof(stHttpData) );
				stHttpData.pHost = pPeerIP;
				stHttpData.pURL = pURL;
				stHttpData.eHttpAction = SESSION_HTTP_GET;

				while ( 1 )
				{
					int i, iNSent = -1;
					
					//printf( "Please enter 1 to send http request:\r\n" );
					i = 0;
				//	scanf( "%d", &i );
					//if ( i == 1 )
						iNSent = send_session_data( pSession, &stHttpData, sizeof(stHttpData), NULL );
						
					os_sleep( 1000 * 2);
				}
			}
		}
	}
	else 
		log_print( "create udp session failed????????????????????????" );
		
	while ( 1 )
		os_sleep( 1000 );
		
	destroy_session( pSession );
	pSession = NULL;
		
	release_session(  );	
	
	return 0;	
}
示例#10
0
int main(int argc, char** argv) {

	int err;

	set_logging_level(logDEBUG1);

	if (argc < 2 || cmdOptionExists(argv, argv + argc, "-h")) {
		test::printHelp();
		return 0;
	}

	int device_id = atoi(argv[1]);

	string bitFile = getCmdOption(argv, argv + argc, "-b");

	if (bitFile.length() == 0) {
		bitFile = "../../bitfiles/mqco_aps_latest";
	}

	cout << "Programming device " << device_id << " using: " << string(bitFile) << endl;

	//Initialize the APSRack from the DLL
	init();

	if (cmdOptionExists(argv, argv + argc, "-0")) {
		char s[] = "stdout";
		set_log(s);
	}

	//Connect to device
	connect_by_ID(device_id);

	err = initAPS(device_id, const_cast<char*>(bitFile.c_str()), true);

	if (err != APS_OK) {
		cout << "Error initializing APS Rack: " << err << endl;
		exit(-1);
	}

//	vector<float> waveform(0);
//
//	for(int ct=0; ct<1000;ct++){
//		waveform.push_back(float(ct)/1000);
//	}

//	stop(0);
//	set_waveform_float(0, 0, &waveform.front(), waveform.size());
//	set_run_mode(0, 0, 0);
//	run(0);
//	usleep(1000);
//	stop(0);

	// select test to run

	if (cmdOptionExists(argv, argv + argc, "-wf")) {
		test::programSquareWaves();
	}

	if (cmdOptionExists(argv, argv + argc, "-stream")) {
		test::streaming();
	}

	if (cmdOptionExists(argv, argv + argc, "-t")) {
		test::doToggleTest();
	}

	if (cmdOptionExists(argv, argv + argc, "-w")) {
		test::doStoreLoadTest();
	}

	if (cmdOptionExists(argv, argv + argc, "-bf")) {
		test::doBulkStateFileTest();
	}

	if (cmdOptionExists(argv, argv + argc, "-sf")) {
		test::doStateFilesTest();
	}

	if (cmdOptionExists(argv, argv + argc, "-trig")) {
		test::getSetTriggerInterval();
	}

	if (cmdOptionExists(argv, argv + argc, "-seq")) {
			test::loadSequenceFile();
	}

	if (cmdOptionExists(argv, argv + argc, "-offset")) {
				test::offsetScale();
		}

	disconnect_by_ID(device_id);

	cout << "Made it through!" << endl;

	return 0;

}
示例#11
0
int main( int argc, char **argv )
{
	int32_t iRetCode = -1;
	CReactor *iUDPReactorId = NULL;
	int8_t pLocalIP[32] = "192.168.1.100";
	CThread *acceptTid = NULL;
	
	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );
	
	if ( strlen( pLocalIP ) <= 0 )
		if ( net_get_local_ip( pLocalIP, sizeof( pLocalIP ) ) < 0 )
			return iRetCode;
	
	log_print( "%s %s:%d local ip-->%s\r\n", __FILE__, __FUNCTION__, __LINE__, pLocalIP );

	if ( init_pine_system(  ) < 0 )
		return iRetCode;
	
	iUDPReactorId = net_reactor(  );
	if ( iUDPReactorId )
	{
		if ( register_reactor_callback( iUDPReactorId, udp_reactor_callback, NULL ) < 0 )
		{	
			log_print( "%s %s:%d register reactor callback failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
			return iRetCode;
		}
		
		iUDPServiceSocketId = net_socket( SOCKET_TYPE_DGRAM, 0 );
		if ( iUDPServiceSocketId )
		{
			CNetAddr addr;
			
			memset( &addr, 0x00, sizeof(addr) );
			memcpy( addr.pIP, pLocalIP, strlen(pLocalIP) );
			addr.iPort = LOCAL_PORT;
			
			if ( net_bind( iUDPServiceSocketId, &addr ) < 0 )
			{
				log_print( "%s %s:%d socket bind failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;	
			}
			else 
				log_print( "bind ok.............." );
			
			if ( net_set_socket( iUDPServiceSocketId, SOCKET_OPTION_REUSE_ADDRESS, NULL, 0 ) < 0 )
			{
				log_print( "%s %s:%d set socket reuse address failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;
			}
			else 
				log_print( "set reuse address ok..............." );
			
			if ( add_reactor_socket( iUDPReactorId, iUDPServiceSocketId, NULL ) < 0 )
			{
				log_print( "%s %s:%d set add reactor socket failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;	
			}
			else 
				log_print( "add reactor socket ok................." );
			
			if ( net_set_socket( iUDPServiceSocketId, SOCKET_OPTION_NONE_BLOCK, NULL, 0 ) < 0 )
			{
				log_print( "%s %s:%d set socket none block failed???????????\r\n", __FILE__, __FUNCTION__, __LINE__ );
				
				return iRetCode;
			}
			else 
				log_print( "set socket none blocking ok....................." );
			
			
			log_print( "udp server is running.............." );
		}
		
		while ( 1 )
			os_sleep( 1000 );
			
		net_close_reactor( iUDPReactorId );
	}

	return 0;	
}