bool RINEX_NavigationMessage::Read(const bool withQZSS)
{

	std::ifstream ifs;
	bool flag_gnss = false;
	bool flag_qzss = false;
	bool from_RTKconv = false;

	std::string fname = filename + "n";
	ifs.open(fname.c_str());
	if (!ifs.is_open())
	{
		std::string fname = filename + ".nav";
		ifs.open(fname.c_str());
		if (!ifs.is_open())
		{
			return flag_gnss;
		}
		else
		{
			from_RTKconv = true;
		}
	}
	else
	{
		// Do nothing
	}

	flag_gnss = _Read(ifs);
	ifs.close();

	if (!from_RTKconv && withQZSS)
	{
		fname = filename + "q";
		ifs.open(fname.c_str());
		if (!ifs.is_open())
		{
			return flag_gnss;
		}
		else
		{
			flag_qzss = _Read(ifs);
		}
	}
	else
	{
		return flag_gnss;
	}

	return (flag_gnss && flag_qzss);

}
status_t
BDebugEventInputStream::_GetData(size_t size)
{
    if (fBufferSize >= size)
        return B_OK;

    if (size > fBufferCapacity)
        return B_BUFFER_OVERFLOW;

    // move remaining data to the start of the buffer
    if (fBufferSize > 0 && fBufferPosition > 0)
        memmove(fBuffer, fBuffer + fBufferPosition, fBufferSize);
    fStreamPosition += fBufferPosition;
    fBufferPosition = 0;

    // read more data
    if (fStream != NULL) {
        ssize_t bytesRead = _Read(fBuffer + fBufferSize,
                                  fBufferCapacity - fBufferSize);
        if (bytesRead < 0)
            return bytesRead;

        fBufferSize += bytesRead;
    }

    return fBufferSize >= size ? B_OK : B_BAD_DATA;
}
Example #3
0
/*********************************************************************
*
*       I2C_Read
*
* Function description
*   Reads from a device on I2C.
*/
U8 I2C_Read(U32 I2CBaseAddr, U8 Addr, U8 * pData, U16 NumBytesToRead) {
  U8 r;

  SET_BASE_ADDR(I2CBaseAddr);
  r = _Read(Addr << 1, pData, NumBytesToRead, 0);
  return r;
}
Example #4
0
nOS_Error nOS_QueueRead (nOS_Queue *queue, void *block, nOS_TickCounter timeout)
{
    nOS_Error       err;
    nOS_StatusReg   sr;
    nOS_Thread      *thread;

#if (NOS_CONFIG_SAFE > 0)
    if (queue == NULL) {
        err = NOS_E_INV_OBJ;
    } else if (block == NULL) {
        err = NOS_E_NULL;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (queue->e.type != NOS_EVENT_QUEUE) {
            err = NOS_E_INV_OBJ;
        } else
#endif
        {
            /* No chance a thread waiting to read from queue if count is higher than 0 */
            if (queue->bcount > 0) {
                _Read(queue, block);
                /* Check if thread waiting to write in queue */
                thread = nOS_SendEvent((nOS_Event*)queue, NOS_OK);
                if (thread != NULL) {
                    /* Write thread's block in queue */
                    _Write(queue, thread->ext);
#if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
                    if ((thread->state == NOS_THREAD_READY) && (thread->prio > nOS_runningThread->prio)) {
                        nOS_Schedule();
                    }
#endif
                }
                err = NOS_OK;
            } else if (timeout == NOS_NO_WAIT) {
                err = NOS_E_EMPTY;
            } else if (nOS_isrNestingCounter > 0) {
                err = NOS_E_ISR;
            }
#if (NOS_CONFIG_SCHED_LOCK_ENABLE > 0)
            else if (nOS_lockNestingCounter > 0) {
                err = NOS_E_LOCKED;
            }
#endif
            else if (nOS_runningThread == &nOS_idleHandle) {
                err = NOS_E_IDLE;
            }
            else {
                nOS_runningThread->ext = block;
                err = nOS_WaitForEvent((nOS_Event*)queue, NOS_THREAD_READING_QUEUE, timeout);
            }
        }
        nOS_LeaveCritical(sr);
    }

    return err;
}
Example #5
0
INetPacket * INetPacket::ReadPacket(INetPacket* r)
{
	NetPacketHeader Header;
	_Read( (uint8*)&Header,PACKET_HEADER_SIZE);
	Header.size = _BITSWAP32(Header.size );
	Header.cmd = _BITSWAP32(Header.cmd);
	uint32 size = Header.size - PACKET_HEADER_SIZE;
	if (!r)
	{
		r = NEW_NETPACKET(size, Header.cmd);
	}
	else
	{
		r->SetOpcode(Header.cmd);
	}
	_Read(r->GetWriteBuffer(size), size);
	return r;
};
Example #6
0
SInt64 SFB::InputSource::Read(void *buffer, SInt64 byteCount)
{
	if(!IsOpen() || nullptr == buffer || 0 > byteCount) {
		LOGGER_WARNING("org.sbooth.AudioEngine.InputSource", "Read() called on an InputSource that hasn't been opened");
		return -1;
	}

	return _Read(buffer, byteCount);
}
Example #7
0
int DBObjData::Read(FILE *file) {
    int swap;

    DocsPTR->DeleteAll();
    ArraysPTR->DeleteAll();
    TablesPTR->DeleteAll();
    if ((swap = DBDataHeader::Read(file)) == DBFault) return (DBFault);
    return (_Read(file, swap));
}
Example #8
0
/*********************************************************************
*
*       I2C_WriteRead
*
* Function description:
*   Writes and reads from a device on I2C.
*/
U8 I2C_WriteRead(U32 I2CBaseAddr, U8 Addr, U8 * pData, U16 NumBytesToWrite, U8 * pBuf, U16 NumBytesToRead) {
  U8 r;

  SET_BASE_ADDR(I2CBaseAddr);
  r = _Write(Addr << 1, pData, NumBytesToWrite, 1);
  if (r == I2C_CODE_OK) {
    r = _Read(Addr << 1, pBuf, NumBytesToRead, 1);
  }
  return r;
}
Example #9
0
nOS_Error nOS_QueueRead (nOS_Queue *queue, void *block, nOS_TickCounter timeout)
{
    nOS_Error       err;
    nOS_StatusReg   sr;
    nOS_Thread      *thread;

#if (NOS_CONFIG_SAFE > 0)
    if (queue == NULL) {
        err = NOS_E_INV_OBJ;
    }
    else if (block == NULL) {
        err = NOS_E_NULL;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (queue->e.type != NOS_EVENT_QUEUE) {
            err = NOS_E_INV_OBJ;
        } else
#endif
        /* No chance a thread waiting to read from queue if count is higher than 0 */
        if (queue->bcount > 0) {
            _Read(queue, block);
            /* Check if thread waiting to write in queue */
            thread = nOS_SendEvent((nOS_Event*)queue, NOS_OK);
            if (thread != NULL) {
                /* Write thread's block in queue */
                _Write(queue, thread->ext);
#if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
                /* Verify if a highest prio thread is ready to run */
                nOS_Schedule();
#endif
            }
            err = NOS_OK;
        }
        else if (timeout == NOS_NO_WAIT) {
            err = NOS_E_EMPTY;
        }
        else {
            nOS_runningThread->ext = block;
            err = nOS_WaitForEvent((nOS_Event*)queue,
                                   NOS_THREAD_READING_QUEUE
#if (NOS_CONFIG_WAITING_TIMEOUT_ENABLE > 0)
                                  ,timeout
#elif (NOS_CONFIG_SLEEP_ENABLE > 0) || (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0)
                                  ,NOS_WAIT_INFINITE
#endif
                                  );
        }
        nOS_LeaveCritical(sr);
    }

    return err;
}
Example #10
0
INetPacket * INetPacket::UnPackPacket()
{
	NetPacketHeader Header;
	_Read( (uint8*)&Header,PACKET_HEADER_SIZE);
	//Header.size = BITSWAP16(Header.size );
	Header.cmd  = _BITSWAP16(Header.cmd  );
	//uint16 size = Header.size - PACKET_HEADER_SIZE;
	SetOpcode(Header.cmd);
	//_Read(r->GetWriteBuffer(size), size);
	return this;
};
Example #11
0
File: USBHID.c Project: agb861/ddd
/*********************************************************************
*
*       USBHID_Read
*
*  Function description
*    Reads an input report from device.
*     
*  Return value:
*    On Error:   -1, No valid device Id used or the report size does not match with device.
*    On success: Number of bytes that have be written.
*
*/
int USBHID_Read(unsigned Id, void * pBuffer, unsigned NumBytes) {
  CONN_INFO * pConnInfo;

  pConnInfo = _apConnInfo[Id];
  if (pConnInfo == NULL)  {
    return -1;   // Error device Id does not exist.
  }
  if (NumBytes != (pConnInfo->InputReportByteLength - 1)) {
    return -1;   // Error report size does not match
  }
  return _Read(pConnInfo, pBuffer, NumBytes);
}
Example #12
0
 void Read(KinBodyPtr& pbody, const std::vector<char>& data,const AttributesList& atts)
 {
     _ProcessAtts(atts);
     if( !pbody ) {
         pbody = RaveCreateKinBody(_penv,_bodytype);
     }
     pbody->SetName(_bodyname);
     Assimp::XFileParserOpenRAVE parser(data);
     _Read(pbody,parser.GetImportedData());
     if( pbody->GetName().size() == 0 ) {
         pbody->SetName("body");
     }
 }
Example #13
0
void Cluster::Load(string filename) 
{
  //open and read file to memory
  if(_Read(filename) != 0) {
    cout <<"Error reading file"<<endl;
    exit;
  };

  //parse term-doc count file
  _Parse(terms);

  //Weight by tf*idf, return total number of food items
  this->N = _Weight();

  //normalize indices to unit vector
  _Norm();

  set_lambda(0.5);
}
Example #14
0
status_t
PackageReader::_ReadUnsignedLEB128(uint64& _value)
{
    uint64 result = 0;
    int shift = 0;
    while (true) {
        uint8 byte;
        status_t error = _Read(byte);
        if (error != B_OK)
            return error;

        result |= uint64(byte & 0x7f) << shift;
        if ((byte & 0x80) == 0)
            break;
        shift += 7;
    }

    _value = result;
    return B_OK;
}
Example #15
0
void homepage(const char *host, const char *f_name){
	myLog("Entered homepage func");
	printf("host = %s\n", host);
	printf("f_name = %s\n", f_name);
	int fd, n;
	char line[MAXLINE];

	fd = tcp_connect(host, SERV);

	n = snprintf(line, sizeof(line), GET_CMD, f_name);

	_Write_n(fd, line, n);

	for( ; ;){
		n = _Read(fd, line, MAXLINE);
		if(n == 0)
			break;
		printf("read %d bytes of homepage\n", n);				
	}
	printf("end-of-file on homepage\n");
	close(fd);
}
Example #16
0
 void Read(RobotBasePtr& probot, const std::vector<char>& data,const AttributesList& atts)
 {
     _ProcessAtts(atts);
     if( !probot ) {
         probot = RaveCreateRobot(_penv,_bodytype);
     }
     probot->SetName(_bodyname);
     Assimp::XFileParserOpenRAVE parser(data);
     _Read(probot,parser.GetImportedData());
     if( probot->GetName().size() == 0 ) {
         probot->SetName("robot");
     }
     // add manipulators
     FOREACH(itmanip,_listendeffectors) {
         RobotBase::ManipulatorInfo manipinfo;
         manipinfo._name = itmanip->first->_info._name;
         manipinfo._sEffectorLinkName = itmanip->first->GetName();
         manipinfo._sBaseLinkName = probot->GetLinks().at(0)->GetName();
         manipinfo._tLocalTool = itmanip->second;
         manipinfo._vdirection=Vector(1,0,0);
         probot->_vecManipulators.push_back(RobotBase::ManipulatorPtr(new RobotBase::Manipulator(probot,manipinfo)));
     }
Example #17
0
bool 
UsdMtlxFileFormat::ReadFromString(
    const SdfLayerBasePtr& layerBase,
    const std::string& str) const
{
    TRACE_FUNCTION();

    SdfLayerHandle layer = TfDynamic_cast<SdfLayerHandle>(layerBase);
    if (!TF_VERIFY(layer)) {
        return false;
    }

    auto stage = UsdStage::CreateInMemory();
    if (!_Read(stage,
               [&str](mx::DocumentPtr d) {
                    mx::readFromXmlString(d, str);
               })) {
        return false;
    }

    layer->TransferContent(stage->GetRootLayer());
    return true;
}
Example #18
0
Header::Header(int fd, uint64 lastBlock, uint32 blockSize)
	:
	fBlockSize(blockSize),
	fStatus(B_NO_INIT),
	fEntries(NULL)
{
	// TODO: check the correctness of the protective MBR and warn if invalid

	// Read and check the partition table header

	fStatus = _Read(fd, (uint64)EFI_HEADER_LOCATION * blockSize,
		&fHeader, sizeof(efi_table_header));
	if (fStatus == B_OK) {
		if (!_IsHeaderValid(fHeader, EFI_HEADER_LOCATION))
			fStatus = B_BAD_DATA;
	}

	if (fStatus == B_OK && lastBlock != fHeader.AlternateBlock()) {
		dprintf("gpt: alternate header not in last block (%" B_PRIu64 " vs. %"
			B_PRIu64 ")\n", fHeader.AlternateBlock(), lastBlock);
		lastBlock = fHeader.AlternateBlock();
	}

	// Read backup header, too
	status_t status = _Read(fd, lastBlock * blockSize, &fBackupHeader,
		sizeof(efi_table_header));
	if (status == B_OK) {
		if (!_IsHeaderValid(fBackupHeader, lastBlock))
			status = B_BAD_DATA;
	}

	// If both headers are invalid, bail out -- this is probably not a GPT disk
	if (status != B_OK && fStatus != B_OK)
		return;

	if (fStatus != B_OK) {
		// Recreate primary header from the backup
		fHeader = fBackupHeader;
		fHeader.SetAbsoluteBlock(EFI_HEADER_LOCATION);
		fHeader.SetEntriesBlock(EFI_PARTITION_ENTRIES_BLOCK);
		fHeader.SetAlternateBlock(lastBlock);
	} else if (status != B_OK) {
		// Recreate backup header from primary
		_SetBackupHeaderFromPrimary(lastBlock);
	}

	// allocate, read, and check partition entry array

	fEntries = new (std::nothrow) uint8[_EntryArraySize()];
	if (fEntries == NULL) {
		// TODO: if there cannot be allocated enough (ie. the boot loader's
		//	heap is limited), try a smaller size before failing
		fStatus = B_NO_MEMORY;
		return;
	}

	fStatus = _Read(fd, fHeader.EntriesBlock() * blockSize,
		fEntries, _EntryArraySize());
	if (fStatus != B_OK || !_ValidateEntriesCRC()) {
		// Read backup entries instead
		fStatus = _Read(fd, fBackupHeader.EntriesBlock() * blockSize,
			fEntries, _EntryArraySize());
		if (fStatus != B_OK)
			return;

		if (!_ValidateEntriesCRC()) {
			fStatus = B_BAD_DATA;
			return;
		}
	}

	// TODO: check overlapping or out of range partitions

#ifdef TRACE_EFI_GPT
	_Dump(fHeader);
	_Dump(fBackupHeader);
	_DumpPartitions();
#endif

	fStatus = B_OK;
}
Example #19
0
status_t
PackageReader::_ReadAttributeValue(uint8 type, uint8 encoding,
                                   AttributeValue& _value)
{
    switch (type) {
    case B_HPKG_ATTRIBUTE_TYPE_INT:
    case B_HPKG_ATTRIBUTE_TYPE_UINT:
    {
        uint64 intValue;
        status_t error;

        switch (encoding) {
        case B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT:
        {
            uint8 value;
            error = _Read(value);
            intValue = value;
            break;
        }
        case B_HPKG_ATTRIBUTE_ENCODING_INT_16_BIT:
        {
            uint16 value;
            error = _Read(value);
            intValue = B_BENDIAN_TO_HOST_INT16(value);
            break;
        }
        case B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT:
        {
            uint32 value;
            error = _Read(value);
            intValue = B_BENDIAN_TO_HOST_INT32(value);
            break;
        }
        case B_HPKG_ATTRIBUTE_ENCODING_INT_64_BIT:
        {
            uint64 value;
            error = _Read(value);
            intValue = B_BENDIAN_TO_HOST_INT64(value);
            break;
        }
        default:
        {
            fErrorOutput->PrintError("Error: Invalid TOC section: "
                                     "invalid encoding %d for int value type %d\n", encoding,
                                     type);
            return B_BAD_VALUE;
        }
        }

        if (error != B_OK)
            return error;

        if (type == B_HPKG_ATTRIBUTE_TYPE_INT)
            _value.SetTo((int64)intValue);
        else
            _value.SetTo(intValue);

        return B_OK;
    }

    case B_HPKG_ATTRIBUTE_TYPE_STRING:
    {
        if (encoding == B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE) {
            uint64 index;
            status_t error = _ReadUnsignedLEB128(index);
            if (error != B_OK)
                return error;

            if (index > fTOCStringsCount) {
                fErrorOutput->PrintError("Error: Invalid TOC section: "
                                         "string reference out of bounds\n");
                return B_BAD_DATA;
            }

            _value.SetTo(fStrings[index]);
        } else if (encoding == B_HPKG_ATTRIBUTE_ENCODING_STRING_INLINE) {
            const char* string;
            status_t error = _ReadString(string);
            if (error != B_OK)
                return error;

            _value.SetTo(string);
        } else {
            fErrorOutput->PrintError("Error: Invalid TOC section: invalid "
                                     "string encoding (%u)\n", encoding);
            return B_BAD_DATA;
        }

        return B_OK;
    }

    case B_HPKG_ATTRIBUTE_TYPE_RAW:
    {
        uint64 size;
        status_t error = _ReadUnsignedLEB128(size);
        if (error != B_OK)
            return error;

        if (encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP) {
            uint64 offset;
            error = _ReadUnsignedLEB128(offset);
            if (error != B_OK)
                return error;

            if (offset > fHeapSize || size > fHeapSize - offset) {
                fErrorOutput->PrintError("Error: Invalid TOC section: "
                                         "invalid data reference\n");
                return B_BAD_DATA;
            }

            _value.SetToData(size, fHeapOffset + offset);
        } else if (encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE) {
            if (size > B_HPKG_MAX_INLINE_DATA_SIZE) {
                fErrorOutput->PrintError("Error: Invalid TOC section: "
                                         "inline data too long\n");
                return B_BAD_DATA;
            }

            const void* buffer;
            error = _GetTOCBuffer(size, buffer);
            if (error != B_OK)
                return error;
            _value.SetToData(size, buffer);
        } else {
            fErrorOutput->PrintError("Error: Invalid TOC section: invalid "
                                     "raw encoding (%u)\n", encoding);
            return B_BAD_DATA;
        }

        return B_OK;
    }

    default:
        fErrorOutput->PrintError("Error: Invalid TOC section: invalid "
                                 "value type: %d\n", type);
        return B_BAD_DATA;
    }
}
Example #20
0
size_t GPFileStream::vRead(void* buffer, size_t size)
{
    return _Read(mF, buffer, size);
}
Example #21
0
int read (int fd, void *buffer, long nbytes)
{
    return _Read(fd, buffer, nbytes);
}
Example #22
0
int I2C::Read( uint8_t reg, void* buf, uint32_t len )
{
	return _Read( mAddr, reg, buf, len );
}