void GammaCompressor::compressUnsignedInt(ofstream * invertedFile, unsigned int number, unsigned char * bitCode, int * currentBit) { int numberSizeByBit; int cpt; if (number > 0) { numberSizeByBit = int(floor(log(number) / log(2)))+1; } else { numberSizeByBit = 0; } cpt = numberSizeByBit; while (cpt > 1) { writeBit(invertedFile, bitCode, currentBit, true); cpt--; } writeBit(invertedFile, bitCode, currentBit, false); if (number == 0) { writeBit(invertedFile, bitCode, currentBit, false); } else if (number == 1) { writeBit(invertedFile, bitCode, currentBit, true); } else { cpt = numberSizeByBit-1; number =number % int(pow(2, cpt)); while (cpt > 0) { writeBit(invertedFile, bitCode, currentBit, number / int(pow(2, cpt - 1)) == 1); number = number % int(pow(2, cpt-1)); cpt--; } } }
void SWD::resync() { for (unsigned int i = 0; i < 50; i++) { writeBit(1); } writeBit(0); // The reference says that we have to read IDCODE here read(false, 0); }
/** * @brief Set tap axes reg to choose which axis using in tap detection * @param AXIS axis - axis want to set * @param bool state - true axis will be using, otherwise axis will be ignore * @return none */ void ADXL345::setTapAxes(AXIS axis, bool state){ switch (axis) { case AXIS_X: writeBit(TAP_AXES_REG, 2, state); break; case AXIS_Y: writeBit(TAP_AXES_REG, 1, state); break; case AXIS_Z: writeBit(TAP_AXES_REG, 0, state); break; default: break; } }
/** * @brief set act inact control register to choose which axes * using in inactivity detection * @param adxl345_axis_t axis - axes using * @param bool state - true axis will be using, false axis will be ignore * @return none */ void ADXL345::setInactControl(AXIS axis, bool state){ switch (axis) { case AXIS_X: writeBit(ACT_INACT_CTL_REG, 2, state); break; case AXIS_Y: writeBit(ACT_INACT_CTL_REG, 1, state); break; case AXIS_Z: writeBit(ACT_INACT_CTL_REG, 0, state); break; default: break; } }
void GfxFeatureMapRequestPacket::setIncludeCountryPolygon( bool includeCountryPolygon) { writeBit(isStartAndEnd_POS, DRAW_COUNTRYPOLYGON_BIT_POS, includeCountryPolygon); }
IDTranslationReplyPacket:: IDTranslationReplyPacket(const IDTranslationRequestPacket* p, uint32 status, const IDPairVector_t& allTranslatedNodes) : ReplyPacket( IDTRANSLATION_REPLY_MAX_LENGTH, Packet::PACKETTYPE_IDTRANSLATIONREPLY, p, status) { int pos = MAP_ID_POS; incWriteLong(pos, p->getMapID()); incWriteLong(pos, p->getUserDefData()); // Skip the flags incWriteLong(pos, MAX_UINT32); // Write the flags writeBit(FLAGS_POS, LOWER_LEVEL_BIT_POS, p->getTranslateToLower()); // Skip the unused position incWriteLong(pos, 0); int nbrNodeVectors = p->getNbrNodeVectors(); // Write the number of node vectors and their sizes. incWriteLong(pos, nbrNodeVectors); for(int i=0; i < nbrNodeVectors; ++i ) { incWriteLong(pos, p->getNbrNodesForVector(i)); } // Write all the nodes for(uint32 i=0; i < allTranslatedNodes.size(); ++i) { incWriteLong(pos, allTranslatedNodes[i].first); // mapID incWriteLong(pos, allTranslatedNodes[i].second); // nodeID } setLength(pos); }
void IDTranslationRequestPacket::init(bool translateToLower, IDPairVector_t** nodeVectors, int nbrNodeVectors, uint32 userDef) { int pos = USER_DEF_POS; incWriteLong(pos, userDef); writeBit(FLAGS_POS, LOWER_LEVEL_BIT_POS, translateToLower); // Skip pos = NBR_NODE_VECT_POS; incWriteLong(pos, nbrNodeVectors); // Write the sizes of the nodevectors for(int i=0; i < nbrNodeVectors; ++i ) { incWriteLong(pos, nodeVectors[i]->size() ); } // Write all the nodes for(int i = 0; i < nbrNodeVectors; ++i ) { const IDPairVector_t* curVect = nodeVectors[i]; int vectSize = curVect->size(); for(int j=0; j < vectSize; ++j) { incWriteLong(pos, (*curVect)[j].first); // mapID incWriteLong(pos, (*curVect)[j].second); // nodeID } } // Don't forget to set the length setLength(pos); }
void HeightEntry::setHeight(const std::array<bool, HEIGHT_BITS>& bits) { for(unsigned int i = 0; i < HEIGHT_BITS; i++) { writeBit(i, bits[i]); } }
void writeByte(uint8_t b){ uint8_t i = 8; while(i--){ //Write actual bit and shift one position right to make the next bit ready writeBit(b & 1); b >>= 1; } }
uint8_t SoftI2C::read() { uint8_t value = 0; for (uint8_t bit = 0; bit < 8; ++bit) value = (value << 1) | readBit(); if (readCount > 1) { // More bytes left to read - send an ACK. writeBit(false); --readCount; } else { // Last byte - send the NACK and a stop condition. writeBit(true); stop(); readCount = 0; } return value; }
void sendByte(unsigned char sByte){ unsigned char i=0; for(i=0;i<8;i++){ writeBit(sByte>>(7-i)); } writeBit(1); //MACK readBit(); //nosak }
static void c64WriteBit(int8_t* buf, int x, int8_t val) { int m = x % 320; int xl = m % 8 + ((m/8) * 64); int yl = x / 320; int r = yl / 8; int idx = ((yl % 8) * 8) + xl + (r * 320 * 8); writeBit(buf, idx, val); }
//Function helps create tree header to write to compressed file void Tree_headerHelper(TreeNode * tn, FILE * outfptr, unsigned char * whichbit, unsigned char * curbyte) { if (tn == NULL) { return; } TreeNode * lc = tn -> left; TreeNode * rc = tn -> right; if((lc == NULL) && (rc == NULL)) { writeBit(outfptr, 1, whichbit, curbyte); char2bits(outfptr, tn -> character, whichbit, curbyte); return; } Tree_headerHelper(lc, outfptr, whichbit, curbyte); Tree_headerHelper(rc, outfptr, whichbit, curbyte); writeBit(outfptr, 0, whichbit, curbyte); }
//Function converts character values to bits using bit shifting void char2bits(FILE * outfptr, int ch, unsigned char * whichbit, unsigned char * curbyte) { unsigned char mask = 0x40; while(mask > 0) { writeBit(outfptr, (ch & mask) == mask, whichbit, curbyte); mask >>= 1; } }
void BitstreamWriter::writeBit32(unsigned int v) { unsigned char result = 0; for(std::size_t i=0; i<32; i++) { bool val = v & (1 << (31-i)); writeBit(val); } }
void BitstreamWriter::writeBit8(unsigned char v) { unsigned char result = 0; for(std::size_t i=0; i<8; i++) { bool val = v & (1 << (7-i)); writeBit(val); } }
//send 10bit color values void shiftBriteColor(unsigned int r, unsigned int g, unsigned int b){ //start latch low RGB_LAT=0; writeBit(0); //color set command begin 00 writeBit(0); write10Bits(b); //shift out write10Bits(r); //shift out write10Bits(g); //shift out //latch high and low RGB_LAT=1; delay(SBDELAY); RGB_LAT=0; }
void SoftI2C::write(uint8_t value) { uint8_t mask = 0x80; while (mask != 0) { writeBit((value & mask) != 0); mask >>= 1; } if (readBit()) // 0: ACK, 1: NACK acked = false; }
// Write BYTE Function void OneWire::write(uint8_t byte) { uint8_t i; uint8_t temp; for (i = 0; i < 8; i++) { temp = byte >> i; temp &= 1; writeBit(temp); } }
unsigned char lastRead(void){ unsigned char i=0; unsigned char dummy = 0; for(i=0;i<8;i++){ dummy |= readBit(); dummy <<= 1; } writeBit(0); //NoMACK sak(); //sak return dummy; }
/* Specify interupt priority 1, but stop the interupt once detected */ void __ISR(_EXTERNAL_2_VECTOR, IPL1) _Int2Handler(void) { uint state = getState(); if(STATE_BEGINING == state) { /* STEP 1. configure the Timer1*/ mT1ClearIntFlag(); OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_1, 64000); /* STEP 2. set the timer interrupt to prioirty level 2 */ ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2); writeBit(1); writeBit(1); setState(STATE_FIRST_EDGE); } else if( STATE_FIRST_EDGE == state) { ConfigIntTimer1(T1_INT_OFF); setEtu(ReadTimer1()/3); OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_1, getEtu()/5); /* STEP 2. set the timer interrupt to prioirty level 2 */ ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2); /*Stopping the timer 1 and reading the value*/ DisableINT2; /*the two first bits of ts are sets*/ setState(STATE_TS); bitIndex = 10 ; } else { /* state == normal processing or no atr but an etu value is set*/ DisableINT2; OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_1, getEtu()); ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2); } /* The flag is cleared at the end to avoid stack overflow * PORTDbits.RD0 is the EXTERNAL_0_VECTOR*/ mINT2ClearIntFlag(); }
unsigned char readByte(void){ unsigned char i=0; unsigned char dummy = 0; for(i=0;i<8;i++){ dummy |= readBit(); dummy <<= 1; } writeBit(1); //MACK sak(); //sak return dummy; }
//Padding int padZero(FILE * fptr, unsigned char * whichbit, unsigned char * curbyte) { int rtv = 0; while((*whichbit) != 0) { rtv = writeBit(fptr, 0, whichbit, curbyte); if(rtv == -1) { return -1; } } return rtv; }
void OWWriteByte(int data) { int loop; // Loop to write each bit in the byte, LS-bit first for (loop = 0; loop < 8; loop++) { writeBit(data & 0x01); // shift the data byte for the next bit data >>= 1; } }
//Function creates hedaer to write to compressed file, stores tree in header for decompression void Tree_header(TreeNode * tn, unsigned int numChar, char * Filename) { FILE * outfptr = fopen(Filename, "w"); if(outfptr == NULL) { return; } unsigned char whichbit = 0; unsigned char curbyte = 0; Tree_headerHelper(tn, outfptr, &whichbit, &curbyte); writeBit(outfptr, 0, &whichbit, &curbyte); padZero(outfptr, &whichbit, &curbyte); fwrite(&numChar, sizeof(unsigned int), 1, outfptr); unsigned char newline = '\n'; fwrite(&newline, sizeof(unsigned char), 1, outfptr); fclose(outfptr); }
uint32_t SWD::read(bool ap, int reg) { int ack = writeCommand(ap, 1, reg); if (ack == ACK_OK) { uint32_t value = 0; int parity = 0; for (unsigned int i = 0; i < 32; i++) { value >>= 1; int bit = readBit(); value |= bit << 31; parity ^= bit; } if (parity == readBit()) { pinMode(SWDAT, OUTPUT); writeBit(0); errors = std::max(errors - 1, 0); return value; } std::cout << "value: " << std::hex << value << std::endl; } else if (ack == ACK_FAULT) {
uint32_t baro_get_pressure(void) { uint32_t pressure; write8(MPL3115A2_CTRL_REG1, MPL3115A2_CTRL_REG1_SBYB | MPL3115A2_CTRL_REG1_OS128 | MPL3115A2_CTRL_REG1_BAR); uint8_t sta = 0; while (! (sta & MPL3115A2_REGISTER_STATUS_PDR)) { sta = read8(MPL3115A2_REGISTER_STATUS); cph_millis_delay(125); } // Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device // Wire.write(MPL3115A2_REGISTER_PRESSURE_MSB); // Wire.endTransmission(false); // end transmission bool status = writeBit(MPL3115A2_ADDRESS, MPL3115A2_REGISTER_PRESSURE_MSB, MPL3115A2_OUT_P_DELTA_MSB, true); // Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)3);// send data n-bytes read // pressure = Wire.read(); // receive DATA // pressure <<= 8; // pressure |= Wire.read(); // receive DATA // pressure <<= 8; // pressure |= Wire.read(); // receive DATA // pressure >>= 4; readBits(MPL3115A2_ADDRESS, 0x01, 0x00, 3, baro_buffer, I2CDEV_DEFAULT_READ_TIMEOUT); pressure = (((int32_t)baro_buffer[0]) << 8) | (((int32_t)baro_buffer[1]) << 8) | (((int32_t)baro_buffer[2]) << 4); float baro = pressure; baro /= 4.0; return baro; }
void GammaCompressor::compressAndWrite(ofstream * outputInvertedFile, list<DocumentTerm>* postingList) { list<DocumentTerm>::iterator it; int delta = 0; int precedendValue = 0; unsigned char bitCode = 0; int currentBit = 0; for (it = postingList->begin(); it != postingList->end(); ++it) { delta = it->documentIndex - precedendValue; precedendValue = it->documentIndex; compressUnsignedInt(outputInvertedFile, delta,&bitCode,¤tBit); compressUnsignedInt(outputInvertedFile, it->ftd, &bitCode, ¤tBit); } if (currentBit != 0) { int initial = currentBit; for (int i = initial; i < 8; i++) { writeBit(outputInvertedFile, &bitCode, ¤tBit, false); } } }
void setInterruptPin() { //Set the appropriate configurations for the Interrupt Pin writeBit(MPU6050Addr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, 0x00); writeBit(MPU6050Addr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, 0x01); writeBit(MPU6050Addr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, 0x00); writeBit(MPU6050Addr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, 0x00); //Set the Interrupt Sources writeBit(MPU6050Addr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, 0x01); writeBit(MPU6050Addr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, 0x00); //Set the Motion Threshold and Duration (Tap Detection) writeByte(MPU6050Addr, MPU6050_RA_MOT_THR, 0x02); writeByte(MPU6050Addr, MPU6050_RA_MOT_DUR, 0x04); }
IDTranslationReplyPacket:: IDTranslationReplyPacket( const IDTranslationRequestPacket* p, uint32 status) : ReplyPacket( IDTRANSLATION_REPLY_MAX_LENGTH, Packet::PACKETTYPE_IDTRANSLATIONREPLY, p, status) { int pos = MAP_ID_POS; incWriteLong(pos, p->getMapID()); incWriteLong(pos, p->getUserDefData()); // Skip the flags incWriteLong(pos, MAX_UINT32); // Skip the unused position incWriteLong(pos, 0); // Write number of nodevectors incWriteLong(pos, 0); // Write the flags writeBit(FLAGS_POS, LOWER_LEVEL_BIT_POS, p->getTranslateToLower()); // Set the length setLength(pos); }