Exemplo n.º 1
0
void LocalPC::makeMaster()
{
    bool online = false;
    DEBUG_OUTPUT("[LocalPC]try make MASTER\n");
    DEBUG_OUTPUT("[LocalPC]I'm %s\n", LOCAL_MASTER==getState()?"MASTER":"SLAVE");
    enter();
    online = floatIPOnline();
    leave();
    if(online)
    {
        DEBUG_OUTPUT("[LocalPC]ip(%s) online\n", mFloatIP);
        return;
    }

    bool master = !isSlave();
    if(master)
    {
        makeSlave();
        return;
    }

    enter();
    DEBUG_OUTPUT("[LocalPC]add ip(%s) to ethernet(%s) ... \n", mFloatIP, mEthernet);
    Ipconfig ipconfig;
    ipconfig.addIP(mEthernet, mFloatIP, mFloatNetmask, mFloatGateway);
    online = floatIPOnline();
    leave();
    if(online)
    {
        DEBUG_OUTPUT("[LocalPC]add ip ok\n");
        setState(LOCAL_MASTER);
    }
}
Exemplo n.º 2
0
MyMoneyMoney ReportAccount::deepCurrencyPrice(const QDate& date, bool exactDate) const
{
  DEBUG_ENTER(Q_FUNC_INFO);

  MyMoneyMoney result(1, 1);
  MyMoneyFile* file = MyMoneyFile::instance();

  MyMoneySecurity undersecurity = file->security(currencyId());
  if (! undersecurity.isCurrency()) {
    const MyMoneyPrice &price = file->price(undersecurity.id(), undersecurity.tradingCurrency(), date, exactDate);
    if (price.isValid()) {
      result = price.rate(undersecurity.tradingCurrency());

      DEBUG_OUTPUT(QString("Converting under %1 to deep %2, price on %3 is %4")
                   .arg(undersecurity.name())
                   .arg(file->security(undersecurity.tradingCurrency()).name())
                   .arg(date.toString())
                   .arg(result.toDouble()));
    } else {
      DEBUG_OUTPUT(QString("No price to convert under %1 to deep %2 on %3")
                   .arg(undersecurity.name())
                   .arg(file->security(undersecurity.tradingCurrency()).name())
                   .arg(date.toString()));
      result = MyMoneyMoney();
    }
  }

  return result;
}
Exemplo n.º 3
0
uint8_t	nrf24l01p_transmit( uint8_t *data, uint8_t len ){

	uint8_t status;
	uint8_t ret;

	/* Check fifo full */
	status = nrf24l01p_singleReadReg( FIFO_STATUS );
	if( fifo_tx_full( status ) ){
		DEBUG_OUTPUT( "transmit error: fifo full\n" );
		return 0;
	}

	nrf24l01p_doCommand( W_TX_PAYLOAD, data, 0, len );
	if( nrf24l01p_conf.config & (1<<MASK_TX_DS) ){ // Interrupt disabled
		while( 1 ){
			status = nrf24l01p_singleReadReg( STATUS );
			if( status & (1<<TX_DS) ){
				ret = 1;
				break;
			}
			else if( status & (1<<MAX_RT) ){
				DEBUG_OUTPUT( "transmit error: timeout\r\n" );
				ret = 0;
				break;
			}
		}
	}
	
	//nrf24l01p_singleWriteReg( STATUS, 0xff );
	return ret;
}
Exemplo n.º 4
0
/// Constructs a SimpleBlockFile based on sample data and writes
/// it to disk.
///
/// @param baseFileName The filename to use, but without an extension.
///                     This constructor will add the appropriate
///                     extension (.au in this case).
/// @param sampleData   The sample data to be written to this block.
/// @param sampleLen    The number of samples to be written to this block.
/// @param format       The format of the given samples.
/// @param allowDeferredWrite    Allow deferred write-caching
SimpleBlockFile::SimpleBlockFile(wxFileName baseFileName,
                                 samplePtr sampleData, sampleCount sampleLen,
                                 sampleFormat format,
                                 bool allowDeferredWrite /* = false */):
   BlockFile(wxFileName(baseFileName.GetFullPath() + wxT(".au")), sampleLen)
{
   mCache.active = false;
   
   DEBUG_OUTPUT("SimpleBlockFile created based on sample data");

   bool useCache = GetCache();

   if (!(allowDeferredWrite && useCache))
      WriteSimpleBlockFile(sampleData, sampleLen, format, NULL);
      
   if (useCache) {
      DEBUG_OUTPUT("Caching block file data");
      mCache.active = true;
      mCache.needWrite = true;
      mCache.format = format;
      mCache.sampleData = new char[sampleLen * SAMPLE_SIZE(format)];
      memcpy(mCache.sampleData,
             sampleData, sampleLen * SAMPLE_SIZE(format));
      void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen,
                                                format);
      mCache.summaryData = new char[mSummaryInfo.totalSummaryBytes];
      memcpy(mCache.summaryData, summaryData,
             (size_t)mSummaryInfo.totalSummaryBytes);
    }
}
Exemplo n.º 5
0
static void *thread_task_entry(void *arg)
{
    // attention! here no lock
    easy_tp_man *manager = ((thread_task_arg *)(arg))->man;
    thread_info *ti      = ((thread_task_arg *)(arg))->ti;
    int id               = ((thread_task_arg *)(arg))->id;

    //
    for (;;)
    {
        task_node *task;
        int ret = 0;
        struct timespec ts;

        pthread_mutex_lock(ti->active_mutex);
        clock_gettime(CLOCK_REALTIME, &ts);
        ts.tv_sec += THREAD_TIMED_OUT;
        while (ti->task == NULL && ret == 0)
            ret = pthread_cond_timedwait(ti->active_cond, ti->active_mutex, &ts);
        task = ti->task;
        ti->task = NULL;
        if (ret == ETIMEDOUT && ti->task == NULL)
        {
            DEBUG_OUTPUT("thread %d time out\n", id);
            ti->timedout = 1;
        }
        pthread_mutex_unlock(ti->active_mutex);

        if (!task)
        {
            DEBUG_OUTPUT("thread %d happend a NULL task\n", id);
            break;
        }

        if (task->func != exit_task_entry)
        {
            // ASSERT(ti->task);
            task->desc->ret = task->func(task->desc->arg);
            if (task->desc->fire_task_over)
                task->desc->fire_task_over(task->desc);
            free(task);

            // become idle
            pthread_mutex_lock(manager->idle_threads.mutex);
            manager->idle_threads.idxs[manager->idle_threads.size++] = id;
            pthread_mutex_unlock(manager->idle_threads.mutex);
            pthread_cond_signal(manager->idle_threads.cond);
        }
        else
        {
            free(task);
            break;
        }
    }
    exit_task_entry(&id);
    free(arg);
    return 0;
}
Exemplo n.º 6
0
void gps_satellite_telemetry() {
	DEBUG_OUTPUT("Time:       %02d:%02d:%02d\r\n", NMEA::getHour(), NMEA::getMinute(), NMEA::getSecond());
	DEBUG_OUTPUT("Satellites: %d\r\n", NMEA::getSatellites());
	DEBUG_OUTPUT("Latitude:   %0.5f\r\n", NMEA::getLatitude());
	DEBUG_OUTPUT("Longitude:  %0.5f\r\n", NMEA::getLongitude());
	DEBUG_OUTPUT("Altitude:   %0.2fm\r\n", NMEA::getAltitude());
	DEBUG_OUTPUT("Speed:      %0.2fkm/h\r\n", NMEA::getSpeed());
	DEBUG_OUTPUT("GPS Bearing (Track made good):    %0.2f degrees\r\n", NMEA::getBearing());
	DEBUG_OUTPUT("Compass Bearing: %03.0f\r\n", bearing);
	DEBUG_OUTPUT("Heading Delta to Waypoint: %03.0f\r\n", heading_delta(180.0, bearing));
	DEBUG_OUTPUT("Distance to Next Nav %06.2fm\r\n",
				 distance_to_current_nav(degToRad((double)NMEA::getLatitude()), degToRad((double)NMEA::getLongitude()))
	);
#ifdef SEND_TELEMETRY
	shedBoat_Telemetry telemetryMessage = shedBoat_Telemetry_init_zero;
	if(autopilotEngaged) {
		telemetryMessage.status = shedBoat_Telemetry_Status_UNDERWAY_AUTOPILOT;
	}
	else {
		telemetryMessage.status = shedBoat_Telemetry_Status_UNDERWAY_MANUAL;
	}

	telemetryMessage.has_location = true;

	telemetryMessage.location.has_latitude = true;
	telemetryMessage.location.latitude = NMEA::getLatitude();
	telemetryMessage.location.has_longitude = true;
	telemetryMessage.location.longitude = NMEA::getLongitude();
	telemetryMessage.location.has_number_of_satellites_visible = true;
	telemetryMessage.location.number_of_satellites_visible = NMEA::getSatellites();
	telemetryMessage.location.has_true_heading = true;
	telemetryMessage.location.true_heading = heading * 1000;
	telemetryMessage.location.has_true_bearing = true;
	telemetryMessage.location.true_bearing = bearing * 1000;
	telemetryMessage.location.has_speed_over_ground = true;
	telemetryMessage.location.speed_over_ground = NMEA::getSpeed() * 1000;
	telemetryMessage.location.has_utc_seconds = true;
	telemetryMessage.location.utc_seconds = NMEA::getSecond();
	telemetryMessage.location.fix_quality = (_shedBoat_Location_Quality)NMEA::getFixQuality();
	telemetryMessage.location.has_distance_to_waypoint = true;
	telemetryMessage.location.distance_to_waypoint = (int32_t)distance_to_current_nav(degToRad((double)NMEA::getLatitude()), degToRad((double)NMEA::getLongitude()));
	telemetryMessage.location.has_waypoint_number = true;
	telemetryMessage.location.waypoint_number = get_nav_num();

	uint8_t buffer[100];
	pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
	bool success = pb_encode(&stream, shedBoat_Telemetry_fields, &telemetryMessage);
	if(success) {
		send_xbee_packet(buffer, stream.bytes_written);
	} else {
		error("Failed to encode Proto Buffer");
	}
#endif
}
Exemplo n.º 7
0
JNIEXPORT void JNICALL
Java_xxl_core_io_raw_NativeRawAccess_read (JNIEnv *env, jobject obj, jbyteArray jblock, jlong sector) {
	FILE *jfilep = (FILE*) getfilep(env, obj);		// Get the device int
	jlong fpos;						// The position to read on the device
	jint sectorSize = getsectorSize(env, obj);
	jlong len = (*env)->GetArrayLength(env, jblock); 
	jbyte *block = (*env)->GetByteArrayElements(env, jblock, 0); 
#ifdef SEQ_OPT	
	jlong lastSector = getlastSector(env, obj);
#endif

	DEBUG_OUTPUT("read: sector==%d", (long) sector);
	
	if (jfilep==0) {
		reportError(env,obj,"file not open");
               	return;
	}

	// Is it exactly one block
	if (len!=sectorSize) {
		reportError(env,obj,"byte array does not have sector size");
               	return;
	}

#ifdef SEQ_OPT	
	if (sector != lastSector+1) {
		// non sequential access!
#endif
		fpos = (jlong) sector * sectorSize;
		if (fseek(jfilep,fpos,SEEK_SET)==-1) {
			reportError(env,obj,"filepointer could not be set");
        	       	return;
        	}
#ifdef SEQ_OPT	
	}
#endif

	DEBUG_OUTPUT("read the block",0);
	// Read the block
	if (fread(block, 1, sectorSize, jfilep)!=sectorSize) {
		reportError(env,obj,"read failed");
               	return;
	}
	
	// Convert the c block array to a java byte array
	(*env)->SetByteArrayRegion(env, jblock, 0, sectorSize, block);
#ifdef SEQ_OPT	
	setlastSector(env, obj, sector);
#endif
	(*env)->ReleaseByteArrayElements(env, jblock, block, 0);
}
Exemplo n.º 8
0
void LocalPC::makeSlave()
{
    bool found = false;
    enter();
    DEBUG_OUTPUT("[LocalPC]delete ip(%s) from ethernet(%s) ... \n", mFloatIP, mEthernet);
    Ipconfig ipconfig;
    ipconfig.delIP(mEthernet, mFloatIP);
    found = (!ipconfig.hasIP(mFloatIP));
    leave();
    if(found)
    {
        DEBUG_OUTPUT("[LocalPC]delete ip ok\n");
        setState(LOCAL_SLAVE);
    }
}
Exemplo n.º 9
0
void LocalPC::setEthernet(char *ethernet)
{
    enter();
    mEthernet = ethernet;
    DEBUG_OUTPUT("[LocalPC]ethernet:%s\n", mEthernet);
    leave();
}
Exemplo n.º 10
0
void LocalPC::setFloatNetmask(char *netmask)
{
    enter();
    mFloatNetmask = netmask;
    DEBUG_OUTPUT("[LocalPC]float netmask:%s\n", mFloatNetmask);
    leave();
}
Exemplo n.º 11
0
void LocalPC::tcpServerReceiveData(void *tcp, char *buffer, int size)
{
    DEBUG_OUTPUT("[LocalPC]receive:\n%s\n", buffer_format(buffer, size));
    HeartbeatProtocol protocol;
    Heartbeat *hb = protocol.find(buffer, size);
    if(hb!=NULL)
    {
        delete hb;

        char *p = NULL;
        int size = 0;
        bool slave = isSlave();
        double timePoint = getSetupTime();
        Heartbeat *t = protocol.makeHeartbeat(slave, timePoint);
        if(NULL!=t)
        {
            if(t->makeBuffer(&p, size))
            {
                TcpClient *client = (TcpClient *)tcp;
                client->send(p, size);
                delete p;
            }
        }
    }
}
Exemplo n.º 12
0
void LocalPC::setFloatIP(char *floatIP)
{
    enter();
    mFloatIP = floatIP;
    DEBUG_OUTPUT("[LocalPC]float ip:%s\n", mFloatIP);
    leave();
}
Exemplo n.º 13
0
//*****************************************************************************
//
// Start the process of enumerating a new device by issuing a reset to the
// appropriate downstream port.
//
//*****************************************************************************
static void
HubDriverDeviceReset(uint8_t ui8Port)
{
    DEBUG_OUTPUT("Starting enumeration for port %d\n", ui8Port);

    //
    // Record the fact that we are in the process of enumerating a device.
    //
    g_sRootHub.bEnumerationBusy = true;

    //
    // Save the port that is being enumerated.
    //
    g_sRootHub.ui8EnumIdx = ui8Port;

    //
    // Mark the port as being reset.
    //
    g_sRootHub.psPorts[ui8Port].iState = ePortResetActive;

    //
    // Initiate a reset on the relevant port to start the enumeration process.
    //
    HubSetPortFeature(&g_sRootHub, ui8Port, HUB_FEATURE_PORT_RESET);
}
Exemplo n.º 14
0
ReportAccount::ReportAccount(const QString& accountid):
    MyMoneyAccount(MyMoneyFile::instance()->account(accountid))
{
  DEBUG_ENTER(Q_FUNC_INFO);
  DEBUG_OUTPUT(QString("Account %1").arg(accountid));
  calculateAccountHierarchy();
}
Exemplo n.º 15
0
void send_debug_telemetry()
{

#ifdef SEND_TELEMETRY
	shedBoat_Telemetry telemetryMessage = shedBoat_Telemetry_init_zero;

	telemetryMessage.status = shedBoat_Telemetry_Status_STATIONARY;

	telemetryMessage.has_debug = true;
	telemetryMessage.debug.has_bearing_compensation = true;
	telemetryMessage.debug.bearing_compensation = bearingCompensation * 1000;
	telemetryMessage.debug.has_speed_over_ground_compensation = true;
	telemetryMessage.debug.speed_over_ground_compensation = speedOverGroundCompensation * 1000;
	telemetryMessage.debug.has_motor_1_throttle_compensation = true;
	telemetryMessage.debug.motor_1_throttle_compensation = leftThrottle * 1000;
	telemetryMessage.debug.has_motor_2_throttle_compensation = true;
	telemetryMessage.debug.motor_2_throttle_compensation = rightThrottle * 1000;

	uint8_t buffer[100];
	pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
	bool success = pb_encode(&stream, shedBoat_Telemetry_fields, &telemetryMessage);
	if(success) {
		send_xbee_packet(buffer, stream.bytes_written);
	} else {
		error("Failed to encode Proto Buffer");
		DEBUG_OUTPUT("Failed to encode Proto Buffer /r/n");
	}
#endif
}
Exemplo n.º 16
0
void printString(const String* inStr)
{
	if(inStr->length == 0)
		return;

	DEBUG_OUTPUT(("%.*s", inStr->length, inStr->str));
}
Exemplo n.º 17
0
ReportAccount::ReportAccount(const MyMoneyAccount& account):
    MyMoneyAccount(account)
{
  DEBUG_ENTER(Q_FUNC_INFO);
  DEBUG_OUTPUT(QString("Account %1").arg(account.id()));
  calculateAccountHierarchy();
}
Exemplo n.º 18
0
void LocalPC::setFloatGateway(char *gateway)
{
    enter();
    mFloatGateway = gateway;
    DEBUG_OUTPUT("[LocalPC]float gateway:%s\n", mFloatGateway);
    leave();
}
Exemplo n.º 19
0
//*****************************************************************************
//
// This function is used to retrieve the current status of a port on the
// hub.
//
// \param psHubInstance is the hub device instance.
// \param ui8Port is the port number for this request.
// \param pui16PortStatus is a pointer to the memory to store the current
// status of the port.
// \param pui16PortChange is a pointer to the memory to store the current
// change status of the ports.
//
// This function is used to retrieve the current overall status and change
// status for the port given in the \e ui8Port parameter.  The \e ui8Port value
// indicates which port number to send this request to and can range from 0 to
// the number of valid ports on the given hub.  A \e ui8Port value of 0 is an
// access to the hub itself and not one of the hub ports.
//
// \return None.
//
//*****************************************************************************
static bool
HubGetPortStatus(tHubInstance *psHubInstance, uint8_t ui8Port,
                 uint16_t *pui16PortStatus, uint16_t *pui16PortChange)
{
    uint32_t ui32Data, ui32Read;
    tUSBRequest sSetupPacket;
    tUSBHostDevice *psDevice;

    //
    // Retrieve the device pointer.
    //
    psDevice = psHubInstance->psDevice;

    //
    // This is a standard OUT request.
    //
    sSetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_CLASS |
                                 USB_RTYPE_OTHER;

    //
    // Set the fields to get the hub status.
    //
    sSetupPacket.bRequest = USBREQ_GET_STATUS;
    sSetupPacket.wValue = 0;
    sSetupPacket.wIndex = (uint16_t)ui8Port;
    sSetupPacket.wLength = 4;

    //
    // Send the request.
    //
    ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice,
                                (uint8_t *)&ui32Data, 4,
                                psDevice->sDeviceDescriptor.bMaxPacketSize0);

    //
    // Check that we received the correct number of bytes.
    //
    if(ui32Read != 4)
    {
        return(false);
    }
    else
    {
        //
        // We got 4 bytes from the device. Now translate these into the 2
        // 16-bit values we pass back to the caller.
        //
        *pui16PortStatus = (uint16_t)(ui32Data & 0xFFFF);
        *pui16PortChange = (uint16_t)(ui32Data >> 16);

        DEBUG_OUTPUT("Port %d, status 0x%04x, change 0x%04x\n", ui8Port,
                     *pui16PortStatus, *pui16PortChange);
    }

    //
    // All is well.
    //
    return(true);
}
Exemplo n.º 20
0
//*****************************************************************************
//
//! This function is used to release a hub device instance.
//!
//! \param psHubInstance is the hub device instance that is to be released.
//!
//! This function is called when an instance of the hub device must be
//! released.  This function is typically made in preparation for shutdown or a
//! switch to function as a USB device when in OTG mode.  Following this call,
//! the hub device is no longer available, but it can be opened again using a
//! call to USBHHubOpen().  After calling USBHHubClose(), the host hub driver
//! no longer provides any callbacks or accepts calls to other hub driver APIs.
//!
//! \return None.
//
//*****************************************************************************
void
USBHHubClose(tHubInstance *psHubInstance)
{
    //
    // Forget the instance pointer and callback.
    //
    psHubInstance->psDevice = 0;
    psHubInstance->pfnCallback = 0;

    DEBUG_OUTPUT("USBHHubClose completed.\n");
}
Exemplo n.º 21
0
/// Read the summary section of the disk file.
///
/// @param *data The buffer to write the data to.  It must be at least
/// mSummaryinfo.totalSummaryBytes long.
bool SimpleBlockFile::ReadSummary(void *data)
{
   if (mCache.active)
   {
      DEBUG_OUTPUT("ReadSummary: Summary is already in cache");
      memcpy(data, mCache.summaryData, (size_t)mSummaryInfo.totalSummaryBytes);
      return true;
   } else
   {
      DEBUG_OUTPUT("ReadSummary: Reading summary from disk");
      
      wxFFile file(mFileName.GetFullPath(), wxT("rb"));

      wxLogNull *silence=0;
      if(mSilentLog)silence= new wxLogNull();
   
      if(!file.IsOpened() ){
      
         memset(data,0,(size_t)mSummaryInfo.totalSummaryBytes);

         if(silence) delete silence;
         mSilentLog=TRUE;

         return true;
      
      }

      if(silence) delete silence;
      mSilentLog=FALSE;
   
      // The offset is just past the au header
      if( !file.Seek(sizeof(auHeader)) )
         return false;
   
      int read = (int)file.Read(data, (size_t)mSummaryInfo.totalSummaryBytes);

      FixSummary(data);

      return (read == mSummaryInfo.totalSummaryBytes);
   }
}
Exemplo n.º 22
0
uint8_t nrf24l01p_dataPending( ){
	uint8_t status;
	uint8_t fifo_status;
	uint8_t pipeno = NRF24L01P_PIPE_NONE;

	status = nrf24l01p_singleReadReg( STATUS );
	fifo_status = nrf24l01p_singleReadReg( FIFO_STATUS );
	if( status & (1<<RX_DR) ){
		nrf24l01p_singleWriteReg( STATUS, 0xff );
		pipeno = (status&0x0e)>>1;
		DEBUG_OUTPUT( "jjjj" );
	}
Exemplo n.º 23
0
/// Construct a SimpleBlockFile memory structure that will point to an
/// existing block file.  This file must exist and be a valid block file.
///
/// @param existingFile The disk file this SimpleBlockFile should use.
SimpleBlockFile::SimpleBlockFile(wxFileName existingFile, sampleCount len,
                                 float min, float max, float rms):
   BlockFile(existingFile, len)
{
   DEBUG_OUTPUT("SimpleBlockFile based on existing file created");
   
   mMin = min;
   mMax = max;
   mRMS = rms;

   mCache.active = false;
}
Exemplo n.º 24
0
//*****************************************************************************
//
// A new device has been connected to the hub.  Allocate resources to manage
// it and pass details back to the main USB host enumeration code to have the
// device enumerated.
//
//*****************************************************************************
static void
HubDriverDeviceConnect(uint8_t ui8Port)
{
    DEBUG_OUTPUT("HubDriverDeviceConnect\n");

    //
    // We've allocated a port table entry so fill it in then initiate a reset
    // on the device.
    //
    g_sRootHub.psPorts[ui8Port].bChanged = false;

    //
    // Mark the port as having a device present but not enumerated.
    //
    DEBUG_OUTPUT("Deferring enumeration for port %d\n", ui8Port);
    g_sRootHub.psPorts[ui8Port].iState = ePortConnected;

    //
    // Wait 100ms to reset the device.
    //
    g_sRootHub.psPorts[ui8Port].ui32Count = 100;
}
Exemplo n.º 25
0
//*****************************************************************************
//
//! This function is used to enable the host hub class driver before any
//! devices are present.
//!
//! \param pfnCallback is the driver call back for host hub events.
//!
//! This function is called to open an instance of a host hub device and
//! provides a valid callback function for host hub events in the
//! \e pfnCallback parameter.  This function must be called before the USB
//! host code can successfully enumerate a hub device or any devices attached
//! to the hub.  The \e pui8HubPool is memory provided to the hub class to
//! manage the devices that are connected to the hub.  The \e ui32PoolSize is
//! the number of bytes and should be at least 32 bytes per device including
//! the hub device itself.  A simple formula for providing memory to the hub
//! class is \b MAX_USB_DEVICES * 32 bytes of data to allow for proper
//! enumeration of connected devices.  The value for \b MAX_USB_DEVICES is
//! defined in the usblib.h file and controls the number of devices
//! supported by the USB library.  The \e ui32NumHubs parameter
//! defaults to one and only one buffer of size tHubInstance is required to
//! be passed in the \e psHubInstance parameter.
//!
//! \note Changing the value of \b MAX_USB_DEVICES requires a rebuild of the
//! USB library to have an effect on the library.
//!
//! \return This function returns the driver instance to use for the other
//! host hub functions.  If there is no instance available at the time of
//! this call, this function returns zero.
//
//*****************************************************************************
tHubInstance *
USBHHubOpen(tUSBHHubCallback pfnCallback)
{
    //
    // Only one hub is supported.
    //
    if(g_sRootHub.pfnCallback)
    {
        DEBUG_OUTPUT("USBHHubOpen failed - already connected.\n");
        return(0);
    }

    //
    // Save the instance data for this device.
    //
    g_sRootHub.pfnCallback = pfnCallback;

    DEBUG_OUTPUT("USBHHubOpen completed.\n");

    //
    // Return the device instance pointer.
    //
    return(&g_sRootHub);
}
Exemplo n.º 26
0
MyMoneyMoney ReportAccount::foreignCurrencyPrice(const QString foreignCurrency, const QDate& date, bool exactDate) const
{
  DEBUG_ENTER(Q_FUNC_INFO);

  MyMoneyMoney result(1, 1);
  MyMoneyFile* file = MyMoneyFile::instance();
  MyMoneySecurity security = file->security(foreignCurrency);

  //check whether it is a currency or a commodity. In the latter case case, get the trading currency
  QString tradingCurrency;
  if (security.isCurrency()) {
    tradingCurrency = foreignCurrency;
  } else {
    tradingCurrency = security.tradingCurrency();
  }

  //It makes no sense to get the price if both currencies are the same
  if (currency().id() != tradingCurrency) {
    const MyMoneyPrice &price = file->price(currency().id(), tradingCurrency, date, exactDate);

    if (price.isValid()) {
      result = price.rate(tradingCurrency);
      DEBUG_OUTPUT(QString("Converting deep %1 to currency %2, price on %3 is %4")
                   .arg(file->currency(currency().id()).name())
                   .arg(file->currency(foreignCurrency).name())
                   .arg(date.toString())
                   .arg(result.toDouble()));
    } else {
      DEBUG_OUTPUT(QString("No price to convert deep %1 to currency %2 on %3")
                   .arg(file->currency(currency().id()).name())
                   .arg(file->currency(foreignCurrency).name())
                   .arg(date.toString()));
    }
  }
  return result;
}
Exemplo n.º 27
0
void nrf24l01p_enterRxMode( void ){
	uint8_t config;

	nrf24l01p_chipEnable( 0 );
	nrf24l01p_doCommand( FLUSH_TX, 0, 0, 0 );
	nrf24l01p_doCommand( FLUSH_RX, 0, 0, 0 );
	nrf24l01p_singleWriteReg( STATUS, 0xff );

	//nrf24l01p_singleWriteReg( CONFIG, 0x07 );
	DEBUG_OUTPUT( "enter RxMode, config=0x%x\n", 
		nrf24l01p_conf.config|(1<<PRIM_RX)|(1<<PWR_UP));
	nrf24l01p_singleWriteReg( CONFIG, 
		nrf24l01p_conf.config|(1<<PRIM_RX)|(1<<PWR_UP) );
	nrf24l01p_chipEnable( 1 );
}
Exemplo n.º 28
0
void LocalPC::emitOnSlave()
{
    DEBUG_OUTPUT("[LocalPC]emit OnSlave\n");
    bool hasHandler = false;
    enter();
    hasHandler = (NULL!=mHandler);
    leave();

    if(!hasHandler)
    {
        return;
    }
    enter();
    mHandler->onLocalIsSlave();
    leave();
}
Exemplo n.º 29
0
/*
 * ===  FUNCTION  ======================================================================
 *         Name:  NVNewRoot
 *  Description:
 * =====================================================================================
 */
int NVNewRoot(NVRDescr * addr, void *p, char * name, size_t size) {
    // check valid addr of p
    long newRootOffset =  addr2offset(addr,p);
    void * brk = offset2addr(addr,addr->dataRegionOffset);
    // DEBUG_OUTPUT("test");
    if ( newRootOffset>=addr->rootMapOffset || newRootOffset<=sizeof(NVRDescr)) {
        errno = EINVAL;
        e("NVNewRoot fail");
    }

    NVRootmapItem_t * nvrmPtrCurr= offset2addr(addr, addr->rootMapOffset);
//    NVRootmapItem_t  * nvrmPtrIdx=nvrmPtrCurr ;
// DEBUG_OUTPUT("test");
    if (NVFetchRoot(addr,name)!=NULL) {
        errno=EEXIST;
        e("NVNewRoot fail"); // return -1
    } else {
        // DEBUG_OUTPUT("test");
        // // segment fault
        // #ifdef  DEBUG
        //     printf("%p\n",nvrmPtrCurr);
        //     printf("%p\n",brk);
        // #endif
        if ((void *)(--nvrmPtrCurr)> brk){
            if (p==NULL){
                DEBUG_OUTPUT("Error in input address");
                return -2;
            } else {
                // DEBUG_OUTPUT("test");
                nvrmPtrCurr->location = p;
                nvrmPtrCurr->type = size;
                strcpy(nvrmPtrCurr->name,name);
                // update meta data
                addr->rootMapOffset=addr2offset(membase,nvrmPtrCurr);
                addr->nvRootCnt++;
                // update dataregion mem
                return 0;
            }
        } else {
            errno =ENOMEM;
            e("NVNewRoot fail"); // return -1
        }
        // DEBUG_OUTPUT("test");


    }
}
Exemplo n.º 30
0
//*****************************************************************************
//
//! Informs the hub class driver that a downstream device failed to enumerate.
//!
//! \param ui8Hub is the address of the hub to which the downstream device
//! is attached.
//! \param ui8Port is the port on the hub to which the downstream device is
//! attached.
//!
//! This function is called by the host controller driver to inform the hub
//! class driver that an attempt to enumerate a downstream device has failed.
//! The hub driver then cleans up and continues enumeration of any other newly
//! connected devices.
//!
//! \return None.
//
//*****************************************************************************
void
USBHHubEnumerationError(uint8_t ui8Hub, uint8_t ui8Port)
{
    DEBUG_OUTPUT("Enumeration error for hub %d, port %d\n", ui8Hub, ui8Port);

    //
    // Record the fact that the device is not working correctly.
    //
    g_sRootHub.psPorts[ui8Port].iState = ePortError;

    //
    // Clear the flag we use to defer further enumerations.  This will cause
    // the next connected device (if any) to start enumeration on the next
    // call to USBHHubMain().
    //
    g_sRootHub.bEnumerationBusy = false;
}