Пример #1
0
/**
 * Creates an instance of the sensor base and gets an FPGA handle
 */
SensorBase::SensorBase() {
  if (!portsInitialized) {
    for (uint32_t i = 0; i < kDigitalChannels; i++) {
      void* port = getPort(i);
      int32_t status = 0;
      m_digital_ports[i] = initializeDigitalPort(port, &status);
      wpi_setErrorWithContext(status, getHALErrorMessage(status));
      freePort(port);
    }

    for (uint32_t i = 0; i < kRelayChannels; i++) {
      void* port = getPort(i);
      int32_t status = 0;
      m_relay_ports[i] = initializeDigitalPort(port, &status);
      wpi_setErrorWithContext(status, getHALErrorMessage(status));
      freePort(port);
    }

    for (uint32_t i = 0; i < kPwmChannels; i++) {
      void* port = getPort(i);
      int32_t status = 0;
      m_pwm_ports[i] = initializeDigitalPort(port, &status);
      wpi_setErrorWithContext(status, getHALErrorMessage(status));
      freePort(port);
    }
  }
}
Пример #2
0
/**
 * Construct an analog input.
 *
 * @param channel The channel number on the roboRIO to represent. 0-3 are
 * on-board 4-7 are on the MXP port.
 */
AnalogInput::AnalogInput(uint32_t channel) {
  std::stringstream buf;
  buf << "Analog Input " << channel;
  Resource::CreateResourceObject(inputs, kAnalogInputs);

  if (!checkAnalogInputChannel(channel)) {
    wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
    return;
  }

  if (inputs->Allocate(channel, buf.str()) ==
      std::numeric_limits<uint32_t>::max()) {
    CloneError(*inputs);
    return;
  }

  m_channel = channel;

  void* port = getPort(channel);
  int32_t status = 0;
  m_port = initializeAnalogInputPort(port, &status);
  wpi_setErrorWithContext(status, getHALErrorMessage(status));
  freePort(port);

  LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
  HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
}
Пример #3
0
int
main (int argc, char **argv)
{
	int times = (argc > 1)?atoi(argv[1]):100;
	int i, random, port=0, index=0, numPorts = 0;
	struct timeval tv;
	dirxn d;
	PortAlloc *pa;
	int *portList;

	gettimeofday(&tv, NULL);
	srand48(tv.tv_sec);

	portList = calloc(times, sizeof(int));

	NetLogInit();
	NetLogOpen((struct sockaddr_in *)NULL, 0, NETLOG_TERMINAL);
	NETLOG_SETLEVEL(MFCE, NETLOG_DEBUG4);
	NETLOG_SETLEVELE(MFCE, NETLOG_DEBUGMASK|NETLOG_ERRORMASK);

	pa = initPortAllocation(2, 10);

	for (i = 0; i < times; i++) {
		random = (rand() % 100);
		d = ((rand() % 100) < 40) ? rx : tx ; 
		if (numPorts)
			index = rand() % numPorts;

		if (random < 70) {
			if ((random < 50) || (numPorts == 0)) {
				// get a new port
				port = 0;
			}
			else if (random < 70) {
				// choose an allocated port
				port = portList[index];	
			}

//			printf("allocating: port %d for %s\n", port, dirxn2str(d));
			if ((port = allocPort(pa, port, d)) > 0) {
				portList[numPorts] = port;
				numPorts++;
			}
//			else {
//				printf("allocPort failed - %s port %d\n", dirxn2str(d), port);
//			}
		} else if (numPorts) {
			// free this port
//			printf("freeing: port %d for %s\n", portList[index], dirxn2str(d));
			freePort(pa, portList[index], d);
		}

		printPorts(pa);
	}
	
	return 0;
}
Пример #4
0
void PortListener::setEnabledInternal(bool e, const QDateTime &ex) {
	m_config->setGroup("ListenerConfig");
	m_config->writeEntry("enabled_" + m_serviceName, e);
	m_config->writeEntry("enabled_expiration_"+m_serviceName, ex);
	m_config->sync();

	m_expirationTime = ex;

	if (e) {
		if (m_port < 0)
			acquirePort();
		m_enabled = m_port >= 0;

	}
	else {
		freePort();
		m_enabled = false;
	}
}
Пример #5
0
 ForEachItemIn(i,portsinuse) {
     freePort(portsinuse.item(i));
 }
Пример #6
0
 ~MSortSlaveActivity()
 {
     if (portbase) 
         freePort(portbase,NUMSLAVEPORTS);
 }
Пример #7
0
 ~SelfJoinSlaveActivity()
 {
     if(portbase) 
         freePort(portbase,NUMSLAVEPORTS);
 }