Exemplo n.º 1
0
int
ipfw_module_init(void)
{
	int ret = 0;

	rn_init(64);
	my_mod_register("ipfw",  1, moddesc_ipfw, NULL, NULL);
	my_mod_register("sy_ipfw",  2, NULL,
		sysinit_ipfw_init, sysuninit_ipfw_destroy);
	my_mod_register("sy_Vnet_ipfw",  3, NULL,
		sysinit_vnet_ipfw_init, sysuninit_vnet_ipfw_uninit);
	my_mod_register("dummynet",  4, moddesc_dummynet, NULL, NULL);
	my_mod_register("dn_fifo",  5, moddesc_dn_fifo, NULL, NULL);
	my_mod_register("dn_wf2qp",  6, moddesc_dn_wf2qp, NULL, NULL);
	my_mod_register("dn_rr",  7, moddesc_dn_rr, NULL, NULL);
	my_mod_register("dn_qfq",  8, moddesc_dn_qfq, NULL, NULL);
	my_mod_register("dn_prio",  9, moddesc_dn_prio, NULL, NULL);
	init_children();

#ifdef EMULATE_SYSCTL
	keinit_GST();
#endif 

	return ret;
}
Exemplo n.º 2
0
void rnl_init(void) {
  if(!initialized) { initialized=1;
    rn_init();
    rnc_init(); rnc_verror_handler=&verror_handler_rnc;
    rnd_init(); rnd_verror_handler=&verror_handler_rnd;
  }
}
Exemplo n.º 3
0
void rnc_init(void) {
  if(!initialized) { initialized=1;
    rn_init();
    len_p=LEN_P; path=(char*)m_alloc(len_p,sizeof(char));
    /* initialize scopes */
    sc_init(&nss); sc_init(&dts); sc_init(&defs); sc_init(&refs); sc_init(&prefs);
  }
}
Exemplo n.º 4
0
void main()
{
	auto int key, reading, channel,device0;
	auto rn_search newdev;

	brdInit();                 //initialize controller
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

	//Display user instructions and channel headings
	DispStr(8, 1, GREEN, "\t\t<<< Digital inputs 0 - 23 >>>");
	DispStr(8, 3, BLACK, "IN00\tIN01\tIN02\tIN03\tIN04\tIN05\tIN06\tIN07");
	DispStr(8, 4, BLACK, "----\t----\t----\t----\t----\t----\t----\t----");

	DispStr(8, 7, BLACK, "IN08\tIN09\tIN10\tIN11\tIN12\tIN13\tIN14\tIN15");
	DispStr(8, 8, BLACK, "----\t----\t----\t----\t----\t----\t----\t----");

	DispStr(8,11, BLACK, "IN16\tIN17\tIN18\tIN19\tIN20\tIN21\tIN22\tIN23");
	DispStr(8,12, BLACK, "----\t----\t----\t----\t----\t----\t----\t----");


	DispStr(8, 16, RED, "Connect the Demo Bd. switches to the inputs that you what to toggle.");
	DispStr(8, 17, RED, "(See instructions in sample program for complete details)");
	DispStr(8, 19, RED, "<-PRESS 'Q' TO QUIT->");

	//loop until user presses the "Q" key
	for(;;)
	{
		// update input channels 0 - 7   (display at col = 8 row = 5)
		update_input(device0, 1, 8, 5);

		// update input channels 8 - 15  (display at col = 8 row = 9)
		update_input(device0, 2, 8, 9);

		// update input channels 16 - 23  (display at col = 8 row = 13)
		update_input(device0, 3, 8, 13);

		if(kbhit())
		{
			key = getchar();
			if (key == 'Q' || key == 'q')		// check if it's the q or Q key
			{
				while(kbhit()) getchar();
      		exit(0);
     		}
		}
   }
}
Exemplo n.º 5
0
/*
 * route initialization must occur before ip6_init2(), which happenas at
 * SI_ORDER_MIDDLE.
 */
static void
route_init(void)
{
	struct domain *dom;
	int max_keylen = 0;

	/* whack the tunable ints into  line. */
	if (rt_numfibs > RT_MAXFIBS)
		rt_numfibs = RT_MAXFIBS;
	if (rt_numfibs == 0)
		rt_numfibs = 1;

	for (dom = domains; dom; dom = dom->dom_next)
		if (dom->dom_maxrtkey > max_keylen)
			max_keylen = dom->dom_maxrtkey;

	rn_init(max_keylen);	/* init all zeroes, all ones, mask table */
}
Exemplo n.º 6
0
void
route_init()
{
	struct domain	 *dom;

	pool_init(&rtentry_pool, sizeof(struct rtentry), 0, 0, 0, "rtentpl",
	    NULL);
	rn_init();	/* initialize all zeroes, all ones, mask table */

	bzero(af2rtafidx, sizeof(af2rtafidx));
	rtafidx_max = 1;	/* must have NULL at index 0, so start at 1 */

	/* find out how many tables to allocate */
	for (dom = domains; dom != NULL; dom = dom->dom_next)
		if (dom->dom_rtattach)
			af2rtafidx[dom->dom_family] = rtafidx_max++;

	if (rtable_add(0) == -1)
		panic("route_init rtable_add");
}
Exemplo n.º 7
0
main ()
{
  	auto int device0, status;
	auto rn_search newdev;
   auto rn_AinData aindata;
   auto float voltequ;
   auto int rawdata;
   auto int channel;
   auto int gaincode;
   auto int key, keypress;

	brdInit();                 //initialize controller
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

   printf("\n\nCalibration Data for Single-Ended mode, Ch = 0-7 Gaincode = 0-7.\n");
   for(gaincode = 0; gaincode < 8; gaincode++)
   {
   	for (channel=0; channel < 8; channel++)
		{
			status = rn_anaInRdCalib(device0, channel, RNSINGLE, gaincode, &aindata, 0);
   		printf("Ch=%d Gaincode=%d,  gain=%8.5f offset=%d\n",
                channel, gaincode,
                aindata.gain, aindata.offset);
		}
      printf("\n");
   }

   printf("\n\nPress any key to continue...\n\n");
   while(!kbhit());
   while(kbhit()) getchar();

   printf("\n\nCalibration Data for Diff mode, Ch = 0,2,4 & 6 Gaincode = 0-7.\n");
	for(gaincode = 0 ; gaincode < 8; gaincode++)
	{
      for (channel=0; channel < 8; channel+=2)
		{
			status = rn_anaInRdCalib(device0, channel, RNDIFF, gaincode, &aindata, 0);
         printf("Ch=%d Gaincode=%d,  gain=%8.5f offset=%d\n",
                channel, gaincode,
                aindata.gain, aindata.offset);
		}
      printf("\n");
	}

   printf("\n\nPress any key to continue...\n\n");
   while(!kbhit());
   while(kbhit()) getchar();

   printf("\n\nCalibration Data for 4-20ma mode, Ch = 0-3 Gaincode = 4\n");
   for (channel=0; channel < 4; channel++)
	{
		status = rn_anaInRdCalib(device0, channel, RNmAMP, RNmAMP_GAINCODE, &aindata, 0);
      printf("Ch=%d Gaincode=%d,  gain=%8.5f offset=%d\n",
                channel, RNmAMP_GAINCODE,
                aindata.gain, aindata.offset);
	}

   printf("\n\nPress any key to exit program...\n\n");
   while(!kbhit());
   while(kbhit()) getchar();

}
Exemplo n.º 8
0
void main()
{
	auto int device0, status;
   auto rn_search newdev;
   auto DacCal DacCalTable1;
   auto float volt1, volt2, voltout;
   auto int data1, data2;
   auto int channel, selectChannel, configureDAC;
   auto char tmpbuf[24];
   auto char command;
 	auto int key, done, cal_error;


	brdInit();
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }


	while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}
	}

   configureDAC = TRUE;
  	selectChannel = TRUE;

 	for(;;)
	{

      if(configureDAC)
      {
      	blankScreen(0, 28);
   		DispStr(2, 1, "DAC Board   CH0&1   CH2-7");
			DispStr(2, 2, "-------------------------");

			DispStr(2, 3, "Config = 0  2.5v    10v");
			DispStr(2, 4, "Config = 1  5.0v    10v");
			DispStr(2, 5, "Config = 2  10v     10v");
			DispStr(2, 6, "Config = 3  5v      20v");
			DispStr(2, 7, "Config = 4  10v     20v");
			DispStr(2, 8, "Config = 5  20v     20v");
			DispStr(2, 9, "Please enter the DAC configuration 0 - 5....");
			do
			{
				command = getchar();
			} while (!((command >= '0') && (command <= '5')));
			printf("Config  = %d", command-=0x30);
      	rn_anaOutConfig(device0, command, 0, 0);
         configureDAC = FALSE;
      }

      if(selectChannel)
      {
      	blankScreen(11, 28);
 			DispStr(2, 11, "DAC0 - DAC7 Calibration Program");
			DispStr(2, 12, "-------------------------------");
			DispStr(2, 13, "Please enter an output channel (0 - 7) = ");
			do
			{
				channel = getchar();
			} while (!((channel >= '0') && (channel <= '7')));
			printf("%d", channel-=0x30);
         selectChannel = FALSE;
      }

      // set two known voltage points using rawdata values, the
		// user will then type in the actual voltage for each point
      rn_anaOut(device0, channel, LOCOUNT, 0);
		DispStr(2, 15, "ENTER the voltage reading from meter(~10% of max voltage) = ");
		volt1 = atof(gets(tmpbuf));

		rn_anaOut(device0, channel, HICOUNT, 0);
		DispStr(2, 16, "ENTER the voltage reading from meter(~90% of max voltage) = ");
		volt2 = atof(gets(tmpbuf));

      cal_error = FALSE;
     	rn_anaOutCalib(channel, LOCOUNT, volt1, HICOUNT, volt2, &DacCalTable1, 0);

      // Store coefficients into eeprom
      rn_anaOutWrCalib(device0, channel, &DacCalTable1, 0);
      memset(&DacCalTable1, 0x00, sizeof(&DacCalTable1));
      rn_anaOutRdCalib(device0, channel, &DacCalTable1, 0);
  		DispStr(2, 17, "Calibration constants has been written to the eeprom");

 		done = FALSE;
		while (!done && !cal_error)
		{
			// display DAC voltage message
			DispStr(2, 20, "Type a desired voltage (in Volts) =  ");

			// get user voltage value for the DAC thats being monitored
			voltout = atof(gets(tmpbuf));

			// send voltage value to DAC for it to output the voltage
     		rn_anaOutVolts(device0, channel,  voltout, &DacCalTable1, 0);
			DispStr(2, 21, "Observe voltage on meter.....");

			// display user options
			DispStr(2, 23, "User Options:");
			DispStr(2, 24, "-------------");
			DispStr(2, 25, "1. Change the voltage on current channel");
			DispStr(2, 26, "2  Calibrate another DAC channel");
			DispStr(2, 27, "3. Change overall DAC output configuration");
         DispStr(2, 28, "4. Exit Program");


			// wait for a key to be pressed
			while(1)
			{
				while(!kbhit());
				key = getchar();
				if(key == '1')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(19, 28);
 					break;
				}
            if(key == '2')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               done = TRUE;
               selectChannel = TRUE;
               break;
   			}
            if(key == '3')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               configureDAC = TRUE;
               selectChannel = TRUE;
               done = TRUE;
               break;
   			}
				if(key == '4')
				{
					// exit sample program
     				exit(0);
   			}
 		}
		}
	}
}
Exemplo n.º 9
0
void main()
{
	auto int device0, status;
	auto char tmpbuf[24];
	auto int done, command;
   auto rn_search newdev;
   auto DacCal DacCalTable1;
   auto float voltout;
   auto int channel, selectChannel;
   auto int key;

	brdInit();		// Required for controllers
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

	for(;;)
	{
   	blankScreen(0, 28);

		DispStr(2, 2, "DAC Board   CH0&1   CH2-7 ");
		DispStr(2, 3, "--------------------------");

		DispStr(2, 4, "Config = 0  2.5v    10v");
		DispStr(2, 5, "Config = 1  5.0v    10v");
		DispStr(2, 6, "Config = 2  10v     10v");
		DispStr(2, 7, "Config = 3  5v      20v");
		DispStr(2, 8, "Config = 4  10v     20v");
		DispStr(2, 9, "Config = 5  20v     20v");
		DispStr(2, 10, "Please enter the DAC configuration 0 - 5....");
		do
		{
			command = getchar();
		} while (!((command >= '0') && (command <= '5')));
		printf("Config  = %d", command-=0x30);
      rn_anaOutConfig(device0, command, 1, 0);
      for(channel=0; channel < 8; channel++)
      {
      	rn_anaOutRdCalib(device0, channel, &DacCalTable1, 0);
      }


     	done = FALSE;
      selectChannel = TRUE;
		while (!done)
		{
         if(selectChannel)
         {
         	DispStr(2, 12, "DAC0 - DAC7 Voltage Out Program");
				DispStr(2, 13, "-------------------------------");
				DispStr(2, 14, "Please enter an output channel (0 - 7) = ");
				do
				{
		  			channel = getchar();
				} while (!((channel >= '0') && (channel <= '7')));
				printf("%d", channel-=0x30);
            selectChannel = FALSE;
        	}

         // display DAC voltage message
			DispStr(2, 16, "Type a desired voltage (in Volts) =  ");

			// get user voltage value for the DAC thats being monitored
			voltout = atof(gets(tmpbuf));

 			// send voltage value to DAC for it to output the voltage
     		rn_anaOutVolts(device0, channel,  voltout, &DacCalTable1, 0);

 			// display user options
			DispStr(2, 19, "User Options:");
			DispStr(2, 20, "-------------");
			DispStr(2, 21, "1. Write voltage value to DAC channel (internal register)");
         DispStr(2, 22, "2. Strobe DAC chip, all DAC channels will be updated");
         DispStr(2, 23, "3. Change to another DAC channel");
			DispStr(2, 24, "4. Change overall DAC output configuration");
			DispStr(2, 25, "5. Exit Program");

         DispStr(2, 28, "Note: Must strobe DAC for outputs to be updated!");
         while(1)
			{
				// wait for a key to be pressed
				while(!kbhit());
				key = getchar();
            if(key == '1')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(16, 28);
   				break;
   			}

            if(key == '2')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               rn_anaOutStrobe(device0, 0);
               DispStr(2, 27, "DAC outputs have been updated");
               msDelay(1000);
               DispStr(2, 27, "                                ");
   			}

            if(key == '3')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(12, 28);
               selectChannel = TRUE;
   				break;
   			}

				if(key == '4')
				{
					// exit while loop and clear previous calibration infor
					done = TRUE;
  					blankScreen(15, 28);
					// empty keyboard buffer
					while(kbhit()) getchar();
					break;
				}
				if (key == '5')		// check if it's the q or Q key
				{
					// exit sample program
     				exit(0);
   			}
			}
		}
	}
}
Exemplo n.º 10
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT theDriverObject,
    IN PUNICODE_STRING theRegistryPath)
{
    NTSTATUS status;
    UNICODE_STRING devname, linkname;
    BOOLEAN ip_fw_started = FALSE, pfhook_started = FALSE;
    int i;

    g_driver_object = theDriverObject;

    log_init();

    /* before starting ip_fw init ip_fw_nt wrappers */
    ip_fw_nt_init();
    rn_init();
    init_tables();
    iflist_init();
    init_packet();
    
    /* send load event to ip_fw */
    
    status = module_ipfw->modevent(theDriverObject, MOD_LOAD, NULL);
    if (status != STATUS_SUCCESS) {
        KdPrint(("[wipfw] DriverEntry: ip_fw MOD_LOAD: 0x%x!\n", status));
        goto done;
    }

    ip_fw_started = TRUE;

    /* setup pfhook */

    status = pfhook_init();
    if (status != STATUS_SUCCESS) {
        KdPrint(("[wipfw] DriverEntry: pfhook_init: 0x%x!\n", status));
        goto done;
    }

    pfhook_started = TRUE;

    /* create control device and symbolic link */

    RtlInitUnicodeString(&devname, L"\\Device\\ip_fw");

    status = IoCreateDeviceSecure(theDriverObject, 0, &devname, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, (BOOLEAN) FALSE, \
    	&SDDL_DEVOBJ_SYS_ALL_ADM_ALL, NULL, &g_devcontrol);
    if (status != STATUS_SUCCESS) {
        KdPrint(("[wipfw] DriverEntry: IoCreateDevice: 0x%x!\n", status));
        goto done;
    }
    
    g_devcontrol->Flags |= DO_POWER_PAGABLE;

    RtlInitUnicodeString(&linkname, L"\\??\\ip_fw");

    status = IoCreateSymbolicLink(&linkname, &devname);
    if (status != STATUS_SUCCESS) {
        KdPrint(("[wipfw] DriverEntry: IoCreateSymbolicLink: 0x%x!\n", status));
        goto done;
    }

    for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
        theDriverObject->MajorFunction[i] = DeviceDispatch;
        
    theDriverObject->MajorFunction[IRP_MJ_PNP] = DeviceDispatch;

#ifdef KLD_MODULE
    theDriverObject->DriverUnload = OnUnload;
#endif

    status = STATUS_SUCCESS;

done:
    if (status != STATUS_SUCCESS) {
        if (g_devcontrol != NULL)
            IoDeleteDevice(g_devcontrol);
        if (pfhook_started)
            pfhook_free();
        if (ip_fw_started)
            module_ipfw->modevent(theDriverObject, MOD_UNLOAD, NULL);
        
        iflist_free();
        log_free();
    }

    return status;
}
Exemplo n.º 11
0
main()
{
   auto int device0;
   auto rn_search newdev;
   auto char s[128];
   auto int counter, i, option;

   // Array locations 0 - 5 used to indicate what state relays
   // 0 - 5 are in, here's the possible states.
   // -----------------------------------------
   //  0 = Relay OFF...no action to be taken
   //  1 = Request for relay to be activated
   //  2 = Relay actvated...no action to be taken.
   //  3 = Request for relay to be deactivated.
	//
   // The user will select a menu option which set the memory
   // locations 0 - 5 with the desired relay state. The main
   // program will detect when a change occurs in the memory
   // array, which will then update the relay(s) with the new
   // Relay state.

   auto char CurrentRelayState[6];
   auto char NewRelayState[6];
   auto int relay_control_update;
   auto int relay;

	brdInit();                 //initialize controller
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

  	//Display user instructions and channel headings
  	DispStr(2, 1, "<<< Relay Control Menu >>>");
   DispStr(2, 2, "--------------------------");
   DispStr(2, 3, "1.Sequence Relays 0, 2, and 4 ON, set all others OFF.");
   DispStr(2, 4, "2.Sequence Relays 0, 1, 3, and 5 ON, set all others OFF.");
   DispStr(2, 5, "3.Sequence All Relays ON.");
   DispStr(2, 6, "4.Sequence All Relays OFF.");

   counter = 0;
   relay_control_update = FALSE;
   memset(CurrentRelayState, 0x00, 6);
   memset(NewRelayState, 0x00, 6);

   for(;;)
   {

   	costate
      {
      	sprintf(s,"Application program is running, counter = %d", counter++);
      	DispStr(2, 10, s);

      }
   	costate
   	{
         if(kbhit())
         {
            option = getchar();
           	set_relay_state(option, &CurrentRelayState[0], &relay_control_update);
         }
         waitfor(DelayMs(10));
      }
      costate
      {
      	if(relay_control_update)
         {
         	for(relay=0; relay < 6; relay++)
            {
            	if(NewRelayState[relay] == 1)
               {
               	// Activate given relay, then wait for 50ms
                  rn_Relay(device0, relay, 1, 0);
                  NewRelayState[relay] = RELAY_IS_ON;
                  CurrentRelayState[relay] = RELAY_IS_ON;
                  // Wait for relay to stabilize
                  waitfor(DelayMs(50));
               }
               else if(NewRelayState[relay] == 3)
               {
               	// Deactivate relay, then wait for 5ms
                  rn_Relay(device0, relay, 0, 0);
                  NewRelayState[relay] = RELAY_IS_OFF;
                  CurrentRelayState[relay] = RELAY_IS_OFF;
                  // Wait for relay power OFF completely
                  waitfor(DelayMs(50));
               }
        		}
            relay_control_update = FALSE;
         }
         else
         {
         	if(memcmp(CurrentRelayState,NewRelayState, 6) != 0)
   			{
          		memcpy(NewRelayState, CurrentRelayState, 6);
          		relay_control_update = TRUE;
         	}
         }
      }
   }
}
Exemplo n.º 12
0
void main ()
{
	auto int device0, status;
	auto char buffer[64];
   auto rn_search newdev;
   auto rn_AinData aindata;
   auto float voltage, cal_voltage;
	auto int rawdata;
   auto int gaincode;
   auto int data1, data2;
   auto int channel;
   auto int key;


	brdInit();
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

   while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}

	}
	printf("\n");
	while(kbhit()) getchar();

   while (1)
	{
		// display the voltage that was read on the A/D channels
   	printrange();
		printf("\nChoose Voltage Configuration for the ADC Board 0 - 7.... ");
		do
		{
			gaincode = getchar();
		} while (!( (gaincode >= '0') && (gaincode <= '7')) );
		gaincode = gaincode - 0x30;
		printf("%d", gaincode);
		while(kbhit()) getchar();

	   // enable on all channels for conversions
		for(channel = 0; channel < 8; channel++)
		{
			status = rn_anaInConfig(device0, channel, RNSINGLE, gaincode, 0);
	   }

     	cal_voltage = .1*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=0; channel < 8; channel++)
		{
			ln[channel].volts1 = atof(buffer);
			status = rn_anaIn(device0, channel, &data1, NUMSAMPLES, 0);
			ln[channel].value1 = data1;
			if (ln[channel].value1 == ADOVERFLOW)
				printf("lo:  channel=%d overflow\n", channel);
			else
				printf("lo:  channel=%d raw=%d\n", channel, ln[channel].value1);
		}

   	cal_voltage = .9*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=0; channel < 8; channel++)
		{
			ln[channel].volts2 = atof(buffer);
			status = rn_anaIn(device0, channel, &data2, NUMSAMPLES, 0);
			ln[channel].value2 = data2;
			if (ln[channel].value2 == ADOVERFLOW)
				printf("hi:  channel=%d overflow\n", channel);
			else
				printf("hi:  channel=%d raw=%d\n", channel, ln[channel].value2);
		}

		printf("\nstore all constants to flash\n");
		for (channel=0; channel < 8; channel++)
		{
 			rn_anaInCalib(channel, RNSINGLE, gaincode, ln[channel].value1,
         	ln[channel].volts1,ln[channel].value2, ln[channel].volts2, &aindata);
	   	printf("gain=%8.5f offset=%d\n", aindata.gain, aindata.offset);
			status = rn_anaInWrCalib(device0, channel, RNSINGLE, gaincode, aindata, 0);
		}

		printf("\nread back constants\n");
		for (channel=0; channel < 8; channel++)
		{
			status = rn_anaInRdCalib(device0, channel, RNSINGLE, gaincode, &aindata, 0);
   		printf("read back gain=%8.5f offset=%d\n", aindata.gain, aindata.offset);
		}

      //After writing constants to flash, you must hard reset to close
      // off flash writes.  Wait 1 second to make sure device reinitializes
      // and clear the reset register.
      rn_reset(device0, 0);
      rn_msDelay(1000);

      //Check and clear reset status
      if(!((status = rn_rst_status(device0, buffer)) & 0x01))
     	{
      	printf("Error! ADC board didn't reset");
         exit(1);
      }
     	status =  rn_enable_wdt(device0, 1);  //enable device hardware watchdog

	   // Must enable on all channels for conversions again after reset
		for(channel = 0; channel < 8; channel++)
		{
			status = rn_anaInConfig(device0, channel, RNSINGLE, gaincode, 0);
	   }
  		printf("\nVary power supply for the voltage range selected.... \n\n");
		do
		{
      	for(channel = 0; channel < 8; channel++)
         {
         	status = rn_anaInVolts(device0, channel, &voltage, NUMSAMPLES, 0);
				printf("Ch %2d Volt=%.5f \n", channel, voltage);
         }
			printf("Press ENTER key to read value again or 'Q' to select another gain option\n\n");
			while(!kbhit());
			key = getchar();
			while(kbhit()) getchar();

		}while(key != 'q' && key != 'Q');
	}
}
Exemplo n.º 13
0
int 
main(int argc, char **argv)
{
	/* 32 таблицы ип локальных адресов */
	struct t_ip_groups groups;
	char ch;
	struct sockaddr_in tmp;

	const struct {
		char *local_ips_name;
		char *logfile_name;
		double bw;
		int print_report1;
		int print_report2;
		int print_report3;
	} defaults = {"locals.txt", "-", 4*1000000, 0, 0, 0};

	struct {
		const char *local_ips_name;
		FILE *local_ips;
		const char *logfile_name;
		FILE *logfile;
		double bw;
		int print_report1;
		int print_report2;
		int print_report3;
	}params;

	params.local_ips_name = strdup(defaults.local_ips_name);
	params.logfile_name = strdup(defaults.logfile_name);
	params.bw = defaults.bw;
	params.print_report1 = defaults.print_report1;
	params.print_report2 = defaults.print_report2;
	params.print_report3 = defaults.print_report3;

	while ((ch = getopt(argc, argv, "123c:f:m:")) != -1) {
		switch (ch) {
			case '1':
				params.print_report1 = 1;
				break;
			case '2':
				params.print_report2 = 1;
				break;
			case '3':
				params.print_report3 = 1;
				break;
			case 'c':
				free((void *)params.local_ips_name);
				params.local_ips_name=strdup(optarg);
				break;
			case 'f':
				free((void *)params.logfile_name);
				params.logfile_name = strdup(optarg);
				break;
			case 'm':
				sscanf(optarg, "%lf", &params.bw);
				params.bw = params.bw*1000000;
				break;
			case 'h':
			case '?':
			default:
				usage();
				return 0;
				break;
		}
	}
	argc -= optind;
	argv += optind;

	params.local_ips = my_fopen(params.local_ips_name);
	if ( params.local_ips == NULL) {
		char buf[80];
		snprintf(buf, sizeof(buf), "cannot open config file %s", params.local_ips_name);
		perror (buf);
		return -1;
	}

	rn_init();
	if ( !rn_inithead((void **)&groups.ips, ((uint8_t *)&tmp.sin_addr - (uint8_t *)&tmp) * 8)) {
		fprintf(stderr, "cannot init group");
		return -1;
	}

	if ( load_ip_config(params.local_ips, &groups) < 0) {
		fprintf(stderr, "can not load config file\n");
		return -2;
	}

	params.logfile = my_fopen(params.logfile_name);
	if ( params.logfile == NULL) {
		char buf[80];
		snprintf(buf, sizeof(buf), "cannot open log file %s", params.logfile_name);
		perror (buf);
		return -3;
	}

	if ( load_ip_stats(params.logfile, &groups) < 0) {
		fprintf(stderr, "cannot load stats file\n");
		return -4;
	}
	groups.bw = params.bw;

	if (params.print_report1)
		print_full_time_log(stdout, &groups);
	if (params.print_report2)
		calc_n_print_hour_log(stdout, &groups);
	if (params.print_report3)
		print_unformatted_time_log(stdout, &groups);

	fclose(params.local_ips);
	fclose(params.logfile);
	return 0;
}
Exemplo n.º 14
0
void main (	void	)
{
	auto int wKey, ballspeed, stop;
 	auto int device0;
   auto rn_search newdev;
   auto unsigned int i;

	auto int	px,py;                        // Current Position
	auto int dx,dy;                        // Current Direction
	auto int nx,ny;                        // New Position
	auto int	xl, xh,	yl, yh;

	//------------------------------------------------------------------------
	// Initialize the controller
	//------------------------------------------------------------------------
	brdInit();			// Initialize the controller

   rn_init(RN_PORTS, 1);      // Initialize controller RN ports

   // Verify that the Rabbitnet display board is connected
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

   // Initialize Display and Keypad low-level drivers
   // Note: Functions brdInit() and rn_init() must executed before initializing
   //       display and keypad drivers.
   rn_keyInit(device0, KEYSTROBLINES, 10);   //set key press buzzer for 10ms
	configKeypad3x4(device0);	// Set keys to the default driver configuration
	rn_dispInit(device0, DISPROWS, DISPCOLS);

   rn_dispPrintf(device0, 0, "Start   Pong");
   rn_keyBuzzerAct(device0, 100, 0);
	for (i=0; i<40000; i++);	//small delay
   rn_keyBuzzerAct(device0, 100, 0);
   rn_dispClear(device0, 0);
	rn_dispCursor(device0, RNDISP_CURBLINKON, 0);

	xl =  0;							// box coordinates, start column
	xh =  DISPCOLS;				// box coordinates, end column
	yl =  0;                   // box coordinates, start row
	yh =  DISPROWS; 				// lines 0 .. yh-1
   px = xl; py = yl;        	// Position Ball
   dx = 1; dy = 1;            // Give Direction

   ballspeed = 200;           // start ball speed at 200 ms delay
   stop = 0;

	while(1)
	{
   	costate
      {
      	if (!stop)
         {
		      rn_dispGoto (device0, px, py, 0);
				waitfor(DelayMs(ballspeed));

	   	   nx = px + dx;               	// Try New Position
   	   	ny = py + dy;

	      	if (nx <= xl || nx >= xh)     // Avoid Collision
   	      	dx = -dx;
	   	   if (ny <= yl || ny >= yh)
   	   	   dy = -dy;

	      	nx = px + dx;               	// Next Position
		      ny = py + dy;

	   	   rn_dispGoto (device0, px, py, 0);
				waitfor(DelayMs(ballspeed));

	   	   px = nx; py = ny;           	// Move Ball
         }
      }

		costate
		{
			rn_keyProcess (device0, 0);
			waitfor ( DelayMs(10) );
		}

		costate
		{
			waitfor ( wKey = rn_keyGet(device0, 0) );	//	Wait for Keypress
         if (wKey != 0)
         {
				printf("KEY PRESSED = %c\n", wKey);
         }
		}

		costate
		{
      	if ((wKey == '-') && (ballspeed<500))
         {
         	ballspeed+=10;		//increase delay
            stop = 0;
         }
		}

		costate
		{
      	if ((wKey == '+') && (ballspeed>10))
         {
         	ballspeed-=10;		//decrease delay
            stop = 0;
         }
		}

		costate
		{
      	if (wKey == '0')
         {
         	stop = 1;			//stop ball movement
         }
		}
   }
}