void *getData(ivc_connection_t *con) { void *item_start, *item_cur, *item_end; uint32_t avail, rd_amount; unsigned long item_size; assert( con->inbuf ); /* wait until we have enough data to read the size */ do { avail = getAvail(con->inmod, con->input); } while(avail < sizeof(unsigned long)); /* read the size, allocate the buffer, compute various pointers */ readRaw(con, &item_size, sizeof(unsigned long)); item_start = item_cur = malloc(item_size); item_end = (void*)((uintptr_t)item_start + item_size); /* read in the data */ while(item_cur < item_end) { avail = getAvail(con->inmod, con->input); rd_amount = (avail > item_size) ? item_size : avail; if(rd_amount > 0) { readRaw(con, item_cur, rd_amount); item_cur = (void*)((uintptr_t)item_cur + rd_amount); item_size -= rd_amount; } else usleep(0); } assert(item_size == 0); return item_start; }
template <class T> void readRaw(ofFile& in, vector<T>& data) { unsigned int n; readRaw(in, n); data.resize(n); for(int i = 0; i < data.size(); i++) { readRaw(in, data[i]); } }
float Light::readLux() { uint8_t range; uint16_t reading; float lux; if(!initialized || paused) return 0.0; lcd.backlight(0); for(range = 0; range < 4; range++) { setRange(range); reading = readRaw(); if(reading < 45000) break; } scale = range; #define READINGS_COUNT 10 uint32_t readings = 0; uint8_t count = 0; if(range == 0) { for(uint8_t i = 0; i < READINGS_COUNT; i++) { reading = readRaw(); readings += reading; if(reading > 0) count++; } if(count == 0) count = 1; reading = (uint16_t) (readings / count); } switch(range) { case 0: lux = (float)reading / 524.288; break; case 1: lux = (float)reading / 131.072; break; case 2: lux = (float)reading / 32.768; break; case 3: default: lux = (float)reading / 8.192; break; } return lux; }
// Read normalized values Vector L3G4200D::readNormalize() { readRaw(); if (useCalibrate) { n.XAxis = (r.XAxis - d.XAxis) * dpsPerDigit; n.YAxis = (r.YAxis - d.YAxis) * dpsPerDigit; n.ZAxis = (r.ZAxis - d.ZAxis) * dpsPerDigit; } else { n.XAxis = r.XAxis * dpsPerDigit; n.YAxis = r.YAxis * dpsPerDigit; n.ZAxis = r.ZAxis * dpsPerDigit; } if (actualThreshold > 0) { if (abs(n.XAxis) < t.XAxis) n.XAxis = 0; if (abs(n.YAxis) < t.YAxis) n.YAxis = 0; if (abs(n.ZAxis) < t.ZAxis) n.ZAxis = 0; } return n; }
virtual int read (void *buffer, int size) override { if (size <= 0) return 0; // return value int r = 0; // treat destination as char * char *dest = static_cast<char *>(buffer); // First consume data from buffer if available. if (dataStart_ < dataEnd_) { int amount = static_cast<int>(dataEnd_ - dataStart_); if (amount > size) amount = size; CoinMemcpyN( dataStart_, amount, dest); dest += amount; size -= amount; dataStart_ += amount; r = amount; } // If we require more data, use readRaw. // We don't use the buffer here, as readRaw is ecpected to be efficient. if (size > 0) r += readRaw (dest, size); return r; }
vpr::Int16 BufferObjectReader::readInt16() { vpr::Int16 nw_val; std::memcpy(&nw_val, readRaw(2), 2); return vpr::System::Ntohs(nw_val); }
SoftSectoredDisk::SoftSectoredDisk(const char* name, DiskImageFormat format): initialized_m(false) { debugss(ssFloppyDisk, INFO, "Insert Disk: %s\n", name); if (format == dif_Unknown) { determineDiskFormat(name, format); } switch (format) { case dif_IMD: readIMD(name); break; case dif_TD0: readTD0(name); break; case dif_RAW: readRaw(name); break; case dif_8RAW: readRaw8(name); break; default: // Unknown format debugss(ssFloppyDisk, ERROR, "Unknown disk format: %d\n", format); break; } }
vpr::Uint32 BufferObjectReader::readUint32() { vpr::Uint32 nw_val; std::memcpy(&nw_val, readRaw(4), 4); return vpr::System::Ntohl(nw_val); }
// Reading SMS's is a bit involved so we don't use helpers that may cause delays or debug // printouts! bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, uint16_t *readlen) { // text mode if (! sendCheckReply(F("AT+CMGF=1"), F("OK"))) return false; // show all text mode parameters if (! sendCheckReply(F("AT+CSDH=1"), F("OK"))) return false; // parse out the SMS len uint16_t thesmslen = 0; //getReply(F("AT+CMGR="), i, 1000); // do not print debug! mySerial->print(F("AT+CMGR=")); mySerial->println(i); readline(1000); // timeout // parse it out... parseReply(F("+CMGR:"), &thesmslen, ',', 11); readRaw(thesmslen); flushInput(); uint16_t thelen = min(maxlen, strlen(replybuffer)); strncpy(smsbuff, replybuffer, thelen); smsbuff[thelen] = 0; // end the string #ifdef ADAFRUIT_FONA_DEBUG Serial.println(replybuffer); #endif *readlen = thelen; return true; }
void Light::startIR() { unsigned char I2C_Buf[3]; I2C_Buf[0] = I2C_ADDR_WRITE; I2C_Buf[1] = 0x00; I2C_Buf[2] = 0b11000000; TWI_Start_Read_Write(I2C_Buf, 3); I2C_Buf[0] = I2C_ADDR_WRITE; I2C_Buf[1] = 0x01; I2C_Buf[2] = 0b00000100; TWI_Start_Read_Write(I2C_Buf, 3); uint8_t range; uint16_t reading; _delay_ms(10); for(range = 0; range < 4; range++) { I2C_Buf[0] = I2C_ADDR_WRITE; I2C_Buf[1] = 0x01; I2C_Buf[2] = range & 0b00000011; TWI_Start_Read_Write(I2C_Buf, 3); _delay_ms(10); reading = readRaw(); if(reading < 45000) break; } }
//! Read the contents of the MT SBD message buffer. //! @param[in] data buffer to hold binary data. //! @param[in] data_size size of binary data buffer. //! @return number of bytes read. unsigned readBufferMT(uint8_t* data, unsigned data_size) { ReadMode saved_read_mode = getReadMode(); Counter<double> timer(getTimeout()); uint8_t bfr[2] = {0}; uint8_t ccsum[2] = {0}; unsigned length = 0; try { // Prepare to read raw data. setReadMode(READ_MODE_RAW); // Send command. sendAT("+SBDRB"); // Read incoming data length. length = getBufferSizeMT(timer); getTask()->spew("reading %u bytes of SBD binary data", length); // Read data. if (length > data_size) throw BufferTooSmall(data_size, length); if (length > 0) { readRaw(timer, data, length); computeChecksum(data, length, ccsum); } // Read and validate. readRaw(timer, bfr, 2); if ((bfr[0] != ccsum[0]) || (bfr[1] != ccsum[1])) throw Hardware::InvalidChecksum(bfr, ccsum); setReadMode(saved_read_mode); expectOK(); } catch (...) { setReadMode(saved_read_mode); throw; } return length; }
bool EVs_NXTTouch::isPressed() { int a; a = readRaw(); if ( a < 300 ) return true; else return false; }
void ofxSickPlayer::load(string filename) { ofLogVerbose("ofxSickPlayer") << "Loading recorded data from " << filename; ofFile in(filename, ofFile::ReadOnly); if(!in.exists()) { ofLogVerbose("ofxSickPlayer") << "Cannot load recorded data: " << filename << " does not exist."; } while(!in.eof()) { ScanData cur; readRaw(in, cur.first.distance); readRaw(in, cur.first.brightness); readRaw(in, cur.second.distance); readRaw(in, cur.second.brightness); recordedData.push_back(cur); } ofLogVerbose("ofxSickPlayer") << "Done loading " << recordedData.size() << " frames of recorded data."; ofxSick::setup(); }
//Deryabin Andrew: vst chunks support std::vector<char> RemotePluginClient::getVSTChunk() { std::cerr << "RemotePluginClient::getChunk: getting vst chunk.." << std::endl; writeOpcode(m_controlRequestFd, RemotePluginGetVSTChunk); std::vector<char> chunk = readRaw(m_controlResponseFd); std::cerr << "RemotePluginClient::getChunk: got vst chunk, size=" << chunk.size() << std::endl; return chunk; }
vpr::Uint64 BufferObjectReader::readUint64() { vpr::Uint64 nw_val; std::memcpy(&nw_val, readRaw(8), 8); vpr::Uint64 h_val = vpr::System::Ntohll(nw_val); return h_val; }
// Read normalized values Vector ADXL345::readNormalize(void) { readRaw(); // (4 mg/LSB scale factor in Full Res) * Earth gravity n.XAxis = r.XAxis * 0.004 * 9.80665f; n.YAxis = r.YAxis * 0.004 * 9.80665f; n.ZAxis = r.ZAxis * 0.004 * 9.80665f; return n; }
void GP2Y10::readDust(float *dust) { // results are computed for a 5V voltage and a 10bit adc float adcVoltage = readRaw() * (5.0 / 1024); // see why we have this limit on: http://www.pocketmagic.net/sharp-gp2y10-dust-sensor/ if (adcVoltage < 0.583) *dust = 0; else *dust = 6 * adcVoltage / 35 - 0.1; }
// Remove a file from the filesystem bool STORAGE::Filesystem::unlink(File f) { std::string thisName; bool merged = false; lock(f, IO::EXCLUSIVE); { // Save info about the file FilePosition pos = dir->files[f]; FileSize size = dir->headers[f].size; FileSize vsize = dir->headers[f].virtualSize; thisName = std::string(dir->headers[f].name); // Overwrite the file with the last file FilePosition lastFilePos = dir->files[dir->numFiles - 1]; FileHeader lastFileHeader = readHeader(lastFilePos); File &lastFile = lookup[std::string(lastFileHeader.name)]; lock(lastFile, IO::EXCLUSIVE); { dir->files[f] = dir->files[lastFile]; dir->headers[f] = dir->headers[lastFile]; dir->locks[f] = dir->locks[lastFile]; lookup[std::string(dir->headers[lastFile].name)] = f; } unlock(lastFile, IO::EXCLUSIVE); // Validate that the next header is valid. Otherwise we cannot reclaim the space. FileHeader nextHeader = readHeader(pos + size + FileHeader::SIZE); if (strcmp(nextHeader.name, "") != 0 || lookup.find(std::string(nextHeader.name, strlen(nextHeader.name))) != lookup.end()) { File nextFile = lookup[std::string(nextHeader.name)]; FileHeader &nextFileHeader = dir->headers[nextFile]; auto reader = getReader(nextFile); auto writer = getWriter(nextFile); lock(nextFile, IO::EXCLUSIVE); { char *buf = reader.readRaw(); dir->files[nextFile] = pos; // Update the file position dir->headers[nextFile].virtualSize += vsize + FileHeader::SIZE; writer.write(buf, nextFileHeader.size); writeHeader(nextFile); } unlock(nextFile, IO::EXCLUSIVE); merged = true; } } unlock(f, IO::EXCLUSIVE); // Remove the lookup info and fix the directory metadata { std::unique_lock<std::mutex> lk(dirLock); lookup.erase(thisName); dir->numFiles--; dir->nextSpot--; } return merged; }
/* During “Functional Test Mode” only “Raw sensor” and “VOC_short” data are available. “VOC_short” is an image of sensor reactivity and can then be used for functional test. Out of this initial period, the device will have the I2C data CO2 equivalent [ppm] and tVOC equivalent referred to the isobutylene sensitivity unit [ppb]. D1:Data_byte_1: CO2_equ: [13…242] -> CO2_equ [ppm] = (D1 -13) * (1600/229) + 400 D2: Data_byte_2: VOC_short [13…242] D3: Data_byte_3: tVOC: [13…242] -> tVOC [ppb] = (D3 -13) * (1000/229) D4: Data_byte_4: Raw sensor first byte (LSB) D5: Data_byte_5: Raw sensor second byte D6: Data_byte_6: Raw sensor third byte (MSB) -> Resistor value [W] = 10*(D4 + (256*D5) + (65536*D6)) return CO2 equivalent [ppm] and tVOC equivalent referred to the isobutylene sensitivity unit [ppb]. * */ bool VZ89::read(float *co2, uint8_t *reactivity, float *tvoc) { uint8_t data[6]; readRaw(data); if (data[0] < 13 || data[1] < 13 || data[2] < 13) return false; // convert data to meaningful values *co2 = (data[0] - 13) * (1600.0 / 229) + 400; // ppm: 400 .. 2000 *reactivity = data[1]; *tvoc = (data[2] - 13) * (1000.0/229); // ppb: 0 .. 1000 //uint32_t resistor = 10 * (data[3] +256 * data[4] + 65536 * data[5]); return true; }
float Light::readLux() { uint8_t range; uint16_t reading; float lux; lcd.backlight(0); for(range = 0; range < 4; range++) { setRange(range); reading = readRaw(); if(reading < 45000) break; } if(range == 0) { for(uint8_t i = 0; i < 5; i++) { uint16_t reading2 = readRaw(); if(reading2 < reading) reading = reading2; } } switch(range) { case 0: lux = (float)reading / 524.288; break; case 1: lux = (float)reading / 131.072; break; case 2: lux = (float)reading / 32.768; break; case 3: default: lux = (float)reading / 8.192; break; } return lux; }
void ParsedContentObject::init(const unsigned char *data, size_t len) { readRaw(m_bytes, data, len); m_comps = ccn_indexbuf_create(); int res = ccn_parse_ContentObject(head (m_bytes), len, &m_pco, m_comps); if (res < 0) { boost::throw_exception(MisformedContentObjectException()); } }
void Light::setRangeAuto() { uint8_t range; uint16_t reading; lcd.backlight(0); _delay_ms(10); for(range = 0; range < 4; range++) { setRange(range); reading = readRaw(); if(reading < 45000) break; } }
std::string BufferObjectReader::readString() { // Note: If you change this, you need to change STRING_LENGTH_SIZE vpr::Uint32 str_len = readUint32(); std::string ret_val; char tempChar; for(vpr::Uint32 i=0; i<str_len;++i) { tempChar = static_cast<char>(*readRaw(1)); ret_val += tempChar; } return ret_val; }
void MulticastPipe::broadcastRaw(void* data,size_t size) { /* Write or read data depending on whether this is the master node or a slave node: */ if(master) { /* Write the data: */ writeRaw(data,size); } else { /* Read the data: */ readRaw(data,size); } }
int8_t Magnetometer::readGauss(double * x, double * y, double * z) { int16_t x_r, y_r, z_r; int8_t ret = readRaw(&x_r, &y_r, &z_r); // pass the error if (ret != 0) return ret; // convert reading to gauss int16_t divisor; switch (gain_) { case HMC5833L_GAIN_1370: divisor = 1370; break; case HMC5833L_GAIN_1090: divisor = 1090; break; case HMC5833L_GAIN_820: divisor = 820; break; case HMC5833L_GAIN_660: divisor = 660; break; case HMC5833L_GAIN_440: divisor = 440; break; case HMC5833L_GAIN_390: divisor = 390; break; case HMC5833L_GAIN_330: divisor = 330; break; case HMC5833L_GAIN_230: divisor = 230; break; default: return HMC5833L_ERROR_GAINOUTOFRANGE; } *x = (double)x_r / divisor; *y = (double)y_r / divisor; *z = (double)z_r / divisor; return 0; }
virtual char *gets (char *buffer, int size) override { if (size <= 1) return 0; char *dest = buffer; char *destLast = dest + size - 2; // last position allowed to be written bool initiallyEmpty = (dataStart_ == dataEnd_); for (;;) { // refill dataBuffer if needed if (dataStart_ == dataEnd_) { dataStart_ = dataEnd_ = &dataBuffer_[0]; int count = readRaw (dataStart_, static_cast<int>(dataBuffer_.size ())); // at EOF? if (count <= 0) { *dest = 0; // if it was initially empty we had nothing written and should // return 0, otherwise at least the buffer contents were // transfered and buffer has to be returned. return initiallyEmpty ? 0 : buffer; } dataEnd_ = dataStart_ + count; } // copy character from buffer *dest = *dataStart_++; // terminate, if character was \n or bufferEnd was reached if (*dest == '\n' || dest == destLast) { *++dest = 0; return buffer; } ++dest; } // we should never reach this place throw CoinError ("Reached unreachable code!", "gets", "CoinGetslessFileInput"); }
Bytes ParsedContentObject::content() const { const unsigned char *content; size_t len; int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len); if (res < 0) { boost::throw_exception(MisformedContentObjectException()); } Bytes bytes; readRaw(bytes, content, len); return bytes; }
float BufferObjectReader::readFloat() { // We are reading the float as a 4 byte value BOOST_STATIC_ASSERT(sizeof(float) == 4); union { float floatVal; vpr::Uint32 intVal; } data; std::memcpy(&data.intVal, readRaw(4), 4); data.intVal = vpr::System::Ntohl(data.intVal); return data.floatVal; }
double BufferObjectReader::readDouble() { // We are reading the double as a 8 byte value BOOST_STATIC_ASSERT(sizeof(double) == 8); union { double doubleVal; vpr::Uint64 intVal; } data; std::memcpy(&data.intVal, readRaw(8), 8); data.intVal = vpr::System::Ntohll(data.intVal); return data.doubleVal; }
/** @brief Execute the driver */ bool HalMagHMC5883L::sample( math::Vector3i& compassMeas_U) { bool result = false; /* Read data */ if (0<=readRaw(compassMeas_U)) { /* Command a new read */ if (0==commandSample()) { result = true; } } return result; }