Пример #1
0
/**
 * Handle calling a callback function that uses three bytes as parameters
 * e.g. leds, pwmLowSideDrivers
 */
void OpenInterface::callCallbackWithThreeBytes(callbackWithThreeBytes callbackFunction)
{
  uint8_t status[3];
  bool result = readBytes(status, 3);
  if (result && callbackFunction)
  {
    (*callbackFunction)(status[0], status[1], status[2]);
  }
}
Пример #2
0
/* Read device memory to extract current
 accelerometer and gyroscope values. */
void MPU6050::read6dof(int* ax, int* ay, int* az, int* gx, int* gy, int* gz) {
  readBytes(MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
  *ax = (((int)buffer[0]) << 8) | buffer[1];
  *ay = (((int)buffer[2]) << 8) | buffer[3];
  *az = (((int)buffer[4]) << 8) | buffer[5];
  *gx = (((int)buffer[8]) << 8) | buffer[9];
  *gy = (((int)buffer[10]) << 8) | buffer[11];
  *gz = (((int)buffer[12]) << 8) | buffer[13];
}
void LIS2MDL::readData(int16_t * destination)
{
  uint8_t rawData[6];  // x/y/z mag register data stored here
  readBytes(LIS2MDL_ADDRESS, (0x80 | LIS2MDL_OUTX_L_REG), 8, &rawData[0]);  // Read the 6 raw data registers into data array

  destination[0] = ((int16_t)rawData[1] << 8) | rawData[0] ;       // Turn the MSB and LSB into a signed 16-bit value
  destination[1] = ((int16_t)rawData[3] << 8) | rawData[2] ;  
  destination[2] = ((int16_t)rawData[5] << 8) | rawData[4] ; 
}
Пример #4
0
size_t DecompressG711ALaw::getSamples(AudioSample *buffer, size_t length)
{
   AudioByte *byteBuff =
      reinterpret_cast<AudioByte *>(buffer);
   size_t read = readBytes(byteBuff,length);
   for(long i=read-1; i>=0; i--)
      buffer[i] = aLawDecodeTable[ byteBuff[i] ];
   return read;
}
Пример #5
0
int SE_BufferInput::readInt()
{
    int out = 0xFFFFFFFF;
    readBytes((char*)&out, sizeof(int));
    if(mNetOrder)
    {
        out = SE_Util::net2HostInt32(out);
    }
    return out;
}
Пример #6
0
/**
 * Handle wait callback that accepts a single int, e.g. waitAngle, waitDistance
 */
void OpenInterface::waitAction(callbackWithOneInt action)
{
  uint8_t raw[2];
  bool result = readBytes(raw, 2);
  if (result)
  {
    int distance = int(word(raw[0], raw[1]));
    (*action)(distance);
  }
}
Пример #7
0
void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz)
{
	readBytes(MPU6050Addr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
	*ax = (((int16_t)buffer[0]) << 8) | buffer[1];
	*ay = (((int16_t)buffer[2]) << 8) | buffer[3];
	*az = (((int16_t)buffer[4]) << 8) | buffer[5];
	*gx = (((int16_t)buffer[8]) << 8) | buffer[9];
	*gy = (((int16_t)buffer[10]) << 8) | buffer[11];
	*gz = (((int16_t)buffer[12]) << 8) | buffer[13];
}
Пример #8
0
static uint64_t
parseCorrupt( tr_torrent *    tor,
              const uint8_t * buf,
              uint32_t        len )
{
    if( len != sizeof( uint64_t ) )
        return 0;
    readBytes( &tor->corruptPrev, &buf, sizeof( uint64_t ) );
    return TR_FR_CORRUPT;
}
Пример #9
0
size_t DecompressPcm8Unsigned::getSamples(AudioSample * buffer,
                                    size_t length) {
   AudioByte *byteBuff =
      reinterpret_cast<AudioByte *>(buffer);
   size_t samplesRead = readBytes(byteBuff,length);
   for(long i=samplesRead-1; i>=0; i--)
      buffer[i] = static_cast<AudioSample>(byteBuff[i] ^ 0x80)
                  << ((sizeof(AudioSample)-1)*8);
   return samplesRead;
}
Пример #10
0
static uint64_t
parseUploaded( tr_torrent *    tor,
               const uint8_t * buf,
               uint32_t        len )
{
    if( len != sizeof( uint64_t ) )
        return 0;
    readBytes( &tor->uploadedPrev, &buf, sizeof( uint64_t ) );
    return TR_FR_UPLOADED;
}
Пример #11
0
int64_t AbstractTransport::readLong()
{
  std::vector<char> longBytes= readBytes(8);
  int64_t result = 0;
  for (int i = 0; i < 8 ; i++) {
    result <<= 8;
    result ^= (int64_t) *(longBytes.data() + i) & 0xFF;
  }
  return result;
}
Пример #12
0
/** Get 3-axis gyroscope readings.
 * These gyroscope measurement registers, along with the accelerometer
 * measurement registers, temperature measurement registers, and external sensor
 * data registers, are composed of two sets of registers: an internal register
 * set and a user-facing read register set.
 * The data within the gyroscope sensors' internal register set is always
 * updated at the Sample Rate. Meanwhile, the user-facing read register set
 * duplicates the internal register set's data values whenever the serial
 * interface is idle. This guarantees that a burst read of sensor registers will
 * read measurements from the same sampling instant. Note that if burst reads
 * are not used, the user is responsible for ensuring a set of single byte reads
 * correspond to a single sampling instant by checking the Data Ready interrupt.
 *
 * Each 16-bit gyroscope measurement has a full scale defined in FS_SEL
 * (Register 27). For each full scale setting, the gyroscopes' sensitivity per
 * LSB in GYRO_xOUT is shown in the table below:
 *
 * <pre>
 * FS_SEL | Full Scale Range   | LSB Sensitivity
 * -------+--------------------+----------------
 * 0      | +/- 250 degrees/s  | 131 LSB/deg/s
 * 1      | +/- 500 degrees/s  | 65.5 LSB/deg/s
 * 2      | +/- 1000 degrees/s | 32.8 LSB/deg/s
 * 3      | +/- 2000 degrees/s | 16.4 LSB/deg/s
 * </pre>
 *
 * @param x 16-bit signed integer container for X-axis rotation
 * @param y 16-bit signed integer container for Y-axis rotation
 * @param z 16-bit signed integer container for Z-axis rotation
 * @see getMotion6()
 * @see MPU6050_RA_GYRO_XOUT_H
 */
PUBLIC void getRotation(int16* x, int16* y, int16* z) {
	if(gyroEnabled)
	{
		readBytes(LSM6DS0_ADDRESS, OUT_X_L_G, 6, IMUBuffer);
		*x = ((((int16)IMUBuffer[1]) << 8) | IMUBuffer[0]);
		*y = ((((int16)IMUBuffer[3]) << 8) | IMUBuffer[2]);
		*z = ((((int16)IMUBuffer[5]) << 8) | IMUBuffer[4]);
		vWaitMicroseconds(500);
	}
}
Пример #13
0
void* getEntryScript()
{
	fseek(HE1_File, RoomResource->RMDA->ENCD - 4, SEEK_SET);
	uint32_t length;
	readU32LE(HE1_File, &length);
	length = SWAP_CONSTANT_32(length) - 8;
	void* data = malloc(length);
	readBytes(HE1_File, (uint8_t*)data, length);
	return data;
}
Пример #14
0
static uint64_t
parseConnections( tr_torrent *    tor,
                  const uint8_t * buf,
                  uint32_t        len )
{
    if( len != sizeof( uint16_t ) )
        return 0;
    readBytes( &tor->maxConnectedPeers, &buf, sizeof( uint16_t ) );
    return TR_FR_MAX_PEERS;
}
Пример #15
0
/*
 * Read the control register
 */
byte DS1339::readControlRegister() {
  byte ctrlReg = 0;

  if(readBytes(&ctrlReg, DS1339_CONTROL_REG, 1) != 1) {
    // Something went wrong so return -1
    return 0xff;
  }

  return ctrlReg;
}
Пример #16
0
short SE_BufferInput::readShort()
{
    short out = 0xFFFF;
    readBytes((char*)&out, sizeof(short));
    if(mNetOrder)
    {
        out = SE_Util::net2HostInt16(out);
    }    
    return out;
}
Пример #17
0
DS::String DS::Stream::readString(size_t length, DS::StringType format)
{
    String result;
    if (format == e_StringUTF16) {
        chr16_t* buffer = new chr16_t[length];
        ssize_t bytes = readBytes(buffer, length * sizeof(chr16_t));
        DS_DASSERT(bytes == static_cast<ssize_t>(length * sizeof(chr16_t)));
        result = String::FromUtf16(buffer, length);
        delete[] buffer;
    } else {
        chr8_t* buffer = new chr8_t[length];
        ssize_t bytes = readBytes(buffer, length * sizeof(chr8_t));
        DS_DASSERT(bytes == static_cast<ssize_t>(length * sizeof(chr8_t)));
        result = (format == e_StringUTF8) ? String::FromUtf8(buffer, length)
                                          : String::FromRaw(buffer, length);
        delete[] buffer;
    }
    return result;
}
Пример #18
0
ST::string DS::Stream::readString(size_t length, DS::StringType format)
{
    if (format == e_StringUTF16) {
        ST::utf16_buffer result;
        char16_t* buffer = result.create_writable_buffer(length);
        ssize_t bytes = readBytes(buffer, length * sizeof(char16_t));
        DS_DASSERT(bytes == static_cast<ssize_t>(length * sizeof(char16_t)));
        buffer[length] = 0;
        return ST::string::from_utf16(result, ST::substitute_invalid);
    } else {
        ST::char_buffer result;
        char* buffer = result.create_writable_buffer(length);
        ssize_t bytes = readBytes(buffer, length * sizeof(char));
        DS_DASSERT(bytes == static_cast<ssize_t>(length * sizeof(char)));
        buffer[length] = 0;
        return (format == e_StringUTF8) ? ST::string::from_utf8(result, ST::substitute_invalid)
                                        : ST::string::from_latin_1(result);
    }
}
Пример #19
0
bool File::read(unsigned char *data, size_t n)
{
	if (eof())
		return false;
	
	readBytes(data, n);
	cursor += n;
	
	return true;
}
Пример #20
0
int16_t AbstractTransport::readUnsignedShort()
{
  std::vector<char> shortBytes= readBytes(2);
  int16_t result = 0;

  for (int i = 0; i < 2 ; i++) {
    result <<= 8;
    result ^= (int16_t) *(shortBytes.data() + i) & 0xFF;
  }
  return result;
}
Пример #21
0
jboolean 
inStream_readBoolean(PacketInputStream *stream)
{
    jbyte flag = 0;
    (void)readBytes(stream, &flag, sizeof(flag));
    if (stream->error) {
        return 0;
    } else {
        return flag ? JNI_TRUE : JNI_FALSE;
    }
}
Пример #22
0
char *ipstream::readString( char *buf, unsigned maxLen )
{
    assert( buf != 0 );

    uchar len = readByte();
    if( len > maxLen-1 )
        return 0;
    readBytes( buf, len );
    buf[len] = EOS;
    return buf;
}
Пример #23
0
QString DataReader::readString(){
    QByteArray bstr = readBytes(readShort());
    QString str;
    int i = 0;
    while(i != bstr.size())
    {
        str.append(bstr.at(i));
        i++;
    }
    return (str);
}
Пример #24
0
I2C_RESULT I2CDev::writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitMask)
{
	// busy check
	while(IsBusy);
	
	if (readBytes(devAddr, regAddr, 1, buff) == I2C_OK)
		buff[0] |= bitMask;
	else return I2C_FAIL;
	
	return writeBytes(devAddr, regAddr, 1, buff);
}
Пример #25
0
Файл: PTrace.cpp Проект: sas/ds2
ErrorCode PTrace::readString(ProcessThreadId const &ptid,
                             Address const &address, std::string &str,
                             size_t length, size_t *count) {
  char buffer[length];
  ErrorCode err = readBytes(ptid, address, buffer, length, count, true);
  if (err != kSuccess)
    return err;

  str = std::string(buffer);
  return kSuccess;
}
Пример #26
0
static uint64_t
parseProgress( tr_torrent *    tor,
               const uint8_t * buf,
               uint32_t        len )
{
    uint64_t ret = 0;

    if( len == FR_PROGRESS_LEN( tor ) )
    {
        int             i;
        int             n;
        tr_bitfield     bitfield;

        /* compare file mtimes */
        tr_time_t *     curMTimes = getMTimes( tor, &n );
        const uint8_t * walk = buf;
        tr_time_t       mtime;
        for( i = 0; i < n; ++i )
        {
            readBytes( &mtime, &walk, sizeof( tr_time_t ) );
            if( curMTimes[i] == mtime )
                tr_torrentSetFileChecked( tor, i, TRUE );
            else
            {
                tr_torrentSetFileChecked( tor, i, FALSE );
                tr_tordbg( tor, "Torrent needs to be verified" );
            }
        }
        free( curMTimes );

        /* get the completion bitfield */
        memset( &bitfield, 0, sizeof bitfield );
        bitfield.byteCount = FR_BLOCK_BITFIELD_LEN( tor );
        bitfield.bitCount = bitfield.byteCount * 8;
        bitfield.bits = (uint8_t*) walk;
        if( tr_cpBlockBitfieldSet( tor->completion, &bitfield ) )
            ret = TR_FR_PROGRESS;
        else {
            tr_torrentUncheck( tor );
            tr_tordbg( tor, "Torrent needs to be verified" );
        }
    }

    /* the files whose mtimes are wrong,
       remove from completion pending a recheck... */
    {
        tr_piece_index_t i;
        for( i = 0; i < tor->info.pieceCount; ++i )
            if( !tr_torrentIsPieceChecked( tor, i ) )
                tr_cpPieceRem( tor->completion, i );
    }

    return ret;
}
Пример #27
0
/**
 * 读取一个字符串
 */
std::string ByteArray::readString()
{
    int length;
    readNumber(&length);
    char *chars = (char *)malloc(length + 1);
    memset(chars, 0, length + 1);
    readBytes((char *)chars, length, 0);
    std::string str(chars);
    free(chars);
    return str;
}
Пример #28
0
char BMP280::readUInt(char address, double &value)
{
	unsigned char data[2];	//4bit
	data[0] = address;
	if (readBytes(data,2))
	{
		value = (double)(unsigned int)(((unsigned int)data[1]<<8)|(unsigned int)data[0]);
		return(1);
	}
	value = 0;
	return(0);
}
Пример #29
0
/* Reading first page from disk */
RC readFirstBlock (SM_FileHandle *fHandle, SM_PageHandle memPage)
{
    // Is storage manager initialized?
    if (isStorageManagerInitialized() != RC_OK)
        return RC_SM_NOT_INIT;

    // Is this handle already in use?
    if (isFileHandleOpen(fHandle) != RC_OK)
        return RC_FILE_HANDLE_NOT_INIT;

    return readBytes(0, fHandle, memPage);
}
Пример #30
0
/** Get 3-axis accelerometer readings.
 * These registers store the most recent accelerometer measurements.
 * Accelerometer measurements are written to these registers at the Sample Rate
 * as defined in Register 25.
 *
 * The accelerometer measurement registers, along with the temperature
 * measurement registers, gyroscope measurement registers, and external sensor
 * data registers, are composed of two sets of registers: an internal register
 * set and a user-facing read register set.
 *
 * The data within the accelerometer sensors' internal register set is always
 * updated at the Sample Rate. Meanwhile, the user-facing read register set
 * duplicates the internal register set's data values whenever the serial
 * interface is idle. This guarantees that a burst read of sensor registers will
 * read measurements from the same sampling instant. Note that if burst reads
 * are not used, the user is responsible for ensuring a set of single byte reads
 * correspond to a single sampling instant by checking the Data Ready interrupt.
 *
 * Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS
 * (Register 28). For each full scale setting, the accelerometers' sensitivity
 * per LSB in ACCEL_xOUT is shown in the table below:
 *
 * <pre>
 * AFS_SEL | Full Scale Range | LSB Sensitivity
 * --------+------------------+----------------
 * 0       | +/- 2g           | 8192 LSB/mg
 * 1       | +/- 4g           | 4096 LSB/mg
 * 2       | +/- 8g           | 2048 LSB/mg
 * 3       | +/- 16g          | 1024 LSB/mg
 * </pre>
 *
 * @param x 16-bit signed integer container for X-axis acceleration
 * @param y 16-bit signed integer container for Y-axis acceleration
 * @param z 16-bit signed integer container for Z-axis acceleration
 * @see MPU6050_RA_GYRO_XOUT_H
 */
PUBLIC bool getAcceleration(int16* x, int16* y, int16* z) {
	bool b = false;
	if(accelEnabled)
	{
		b = readBytes(LSM6DS0_ADDRESS, OUT_X_L_XL, 6, IMUBuffer);
		*x = ((((int16)IMUBuffer[1]) << 8) | IMUBuffer[0]);
		*y = ((((int16)IMUBuffer[3]) << 8) | IMUBuffer[2]);
		*z = ((((int16)IMUBuffer[5]) << 8) | IMUBuffer[4]);
		vWaitMicroseconds(500);
	}
	return b;
}