inline bool testPixel(const QPoint& pos) { if ( !_rect.contains(pos) ) return false; const int idx = _rect.width() * (pos.y() - _rect.y()) + (pos.x() - _rect.x()); const bool marked = testBit(idx); if ( !marked ) setBit(idx, true); return !marked; }
void BaseStation::slotSpeakGnssStatus(const GnssStatus* const status) { if(mAudioPlayer && mActionEnableAudio->isChecked()) { if(status->pvtMode != GnssStatus::PvtMode::RtkFixed) mAudioPlayer->setSound(QString("../media/gnss_mode_%1.ogg").arg(status->getPvtMode().toLower().replace(' ', '_'))); else if(status->error != GnssStatus::Error::NoError) mAudioPlayer->setSound(QString("../media/ins_error_%1.ogg").arg(status->getError().toLower().replace(' ', '_'))); else if(!testBit(status->info, 11)) mAudioPlayer->setSound(QString("../media/ins_error_heading_ambiguous.ogg")); else if(status->covariances > Pose::maximumUsableCovariance) mAudioPlayer->setSound(QString("../media/ins_covariances_too_high.ogg")); else if(status->meanCorrAge > 50) mAudioPlayer->setSound(QString("../media/gnss_differential_corrections_missing.ogg")); else mAudioPlayer->setSound(QString("../media/ins_nominal.ogg")); } }
/************************************************************************************* Pattern light * this routine read a constant array to drive leds * array of 16 elements * 0 -> led off * 1 -> led on *************************************************************************************/ void PatternLights(void) { if(_enStrobe == true) { if(_20msElapsed == true) { _20msElapsed = false; // reset 20ms flag STROBE = testBit(patternArray, index); // led state = bit value of pattern array at index bit position if(index < PATTERN_LENGTH) // if index < last bit -> increment { index++; // increment index = move pointer to next bit } else { index = 0; // reset index = move pointer to bit 0 } } } }
bool OsmAnd::RoutingRuleExpression::resolveTagReferenceValue( RoutingRulesetContext* context, const QBitArray& types, const QString& tagRef, const QString& type, float& value ) { bool ok = false; auto itMask = context->ruleset->owner->_tagRuleMask.find(tagRef); if(itMask != context->ruleset->owner->_tagRuleMask.end()) { const auto& mask = *itMask; auto foundBits = (mask & types); if(foundBits.count(true) > 0) { for(auto bitIdx = 0; bitIdx < foundBits.size(); bitIdx++) { if(foundBits.testBit(bitIdx)) { ok = context->ruleset->owner->parseTypedValueFromTag(bitIdx, type, value); break; } } } } return ok; }
int CVICALLBACK RobotTimer (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_TIMER_TICK: SetCtrlVal(panel, PANEL_RB_CURR_POS_X, sys->rb[curRobotId].curPosX/10000.0); SetCtrlVal(panel, PANEL_RB_CURR_POS_Y, sys->rb[curRobotId].curPosY/10000.0); SetCtrlAttribute(panel,PANEL_RB_CHUCK_OFF, ATTR_VISIBLE, testBit(sys->rb[curRobotId].hsChuck,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_RB_CHUCK_ON, ATTR_VISIBLE, testBit(sys->rb[curRobotId].hsChuck,WB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_RB_TEACH_OFF, ATTR_VISIBLE, testBit(sys->rb[curRobotId].hsTeach,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_RB_TEACH_ON, ATTR_VISIBLE, testBit(sys->rb[curRobotId].hsTeach,WB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_RB_FILL_OFF, ATTR_VISIBLE, testBit(sys->rb[curRobotId].hsFill,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_RB_FILL_ON, ATTR_VISIBLE, testBit(sys->rb[curRobotId].hsFill,WB) > 0 ? 1 : 0); break; } return 0; }
void Video::renderSprites() { bool use8x16 = false; if (testBit(_memory->read(LCDC), 2)) use8x16 = true; for (int sprite = 0; sprite < 40; sprite++) { // sprite occupies 4 bytes in the sprite attributes table BYTE index = sprite * 4; BYTE yPos = _memory->read(0xFE00 + index) - 16; BYTE xPos = _memory->read(0xFE00 + index + 1) - 8; BYTE tileLocation = _memory->read(0xFE00 + index + 2); BYTE attributes = _memory->read(0xFE00 + index + 3); bool yFlip = testBit(attributes, 6); bool xFlip = testBit(attributes, 5); int scanline = _memory->read(LY); int ysize = 8; if (use8x16) ysize = 16; // does this sprite intercept with the scanline? if ((scanline >= yPos) && (scanline < (yPos + ysize))) { int line = scanline - yPos; // read the sprite in backwards in the y axis if (yFlip) { line -= ysize; line *= -1; } line *= 2; // same as for tiles WORD dataAddress = (0x8000 + (tileLocation * 16)) + line; BYTE data1 = _memory->read(dataAddress); BYTE data2 = _memory->read(dataAddress + 1); // its easier to read in from right to left as pixel 0 is // bit 7 in the colour data, pixel 1 is bit 6 etc... for (int tilePixel = 7; tilePixel >= 0; tilePixel--) { int colourbit = tilePixel; // read the sprite in backwards for the x axis if (xFlip) { colourbit -= 7; colourbit *= -1; } // the rest is the same as for tiles int colourNum = bitGetVal(data2, colourbit); colourNum <<= 1; colourNum |= bitGetVal(data1, colourbit); WORD colourAddress = testBit(attributes, 4) ? 0xFF49 : 0xFF48; COLOUR col = getColour(colourNum, colourAddress); // white is transparent for sprites. if (col == WHITE) continue; int red = 0; int green = 0; int blue = 0; switch (col) { case WHITE: red = 255; green = 255; blue = 255; break; case LIGHT_GREY:red = 0xCC; green = 0xCC; blue = 0xCC; break; case DARK_GREY:red = 0x77; green = 0x77; blue = 0x77; break; } int xPix = 0 - tilePixel; xPix += 7; int pixel = xPos + xPix; // sanity check if ((scanline<0) || (scanline>143) || (pixel<0) || (pixel>159)) { continue; } // check if pixel is hidden behind background if (testBit(attributes, 7) == 1) { if (((_screenDATA[scanline * 160 + pixel] & 0xFF) != 0xFF) || ((_screenDATA[scanline * 160 + pixel] & 0xFF00) != 0xFF00) || ((_screenDATA[scanline * 160 + pixel] & 0xFF0000) != 0xFF0000)) continue; } _screenDATA[scanline * 160 + pixel] = (red << 16) + (green << 8) + blue; } } } }
void Video::renderTiles() { WORD tileData = 0; WORD backgroundMemory = 0; bool unsig = true; // where to draw the visual area and the window BYTE scrollY = _memory->read(SCY); BYTE scrollX = _memory->read(SCX); BYTE windowY = _memory->read(WY); BYTE windowX = _memory->read(WX) - 7; bool usingWindow = false; // is the window enabled? if (testBit(_memory->read(LCDC), 5)) { // is the current scanline we're drawing // within the windows Y pos?, if (windowY <= _memory->read(LY)) usingWindow = true; } // which tile data are we using? if (testBit(_memory->read(LCDC), 4)) { tileData = 0x8000; } else { // IMPORTANT: This memory region uses signed // bytes as tile identifiers tileData = 0x8800; unsig = false; } // which background mem? if (false == usingWindow) { if (testBit(_memory->read(LCDC), 3)) backgroundMemory = 0x9C00; else backgroundMemory = 0x9800; } else { // which window memory? if (testBit(_memory->read(LCDC), 6)) backgroundMemory = 0x9C00; else backgroundMemory = 0x9800; } BYTE yPos = 0; // yPos is used to calculate which of 32 vertical tiles the // current scanline is drawing if (!usingWindow) yPos = scrollY + _memory->read(LY); else yPos = _memory->read(LY) - windowY; // which of the 8 vertical pixels of the current // tile is the scanline on? WORD tileRow = (((BYTE)(yPos / 8)) * 32); // time to start drawing the 160 horizontal pixels // for this scanline for (int pixel = 0; pixel < 160; pixel++) { BYTE xPos = pixel + scrollX; // translate the current x pos to window space if necessary if (usingWindow) { if (pixel >= windowX) { xPos = pixel - windowX; } } // which of the 32 horizontal tiles does this xPos fall within? WORD tileCol = (xPos / 8); SIGNED_WORD tileNum; // get the tile identity number. Remember it can be signed // or unsigned WORD tileAddrss = backgroundMemory + tileRow + tileCol; if (unsig) tileNum = (BYTE)_memory->read(tileAddrss); else tileNum = (SIGNED_BYTE)_memory->read(tileAddrss); // deduce where this tile identifier is in memory. Remember i // shown this algorithm earlier WORD tileLocation = tileData; if (unsig) tileLocation += (tileNum * 16); else tileLocation += ((tileNum + 128) * 16); // find the correct vertical line we're on of the // tile to get the tile data //from in memory BYTE line = yPos % 8; line *= 2; // each vertical line takes up two bytes of memory BYTE data1 = _memory->read(tileLocation + line); BYTE data2 = _memory->read(tileLocation + line + 1); // pixel 0 in the tile is it 7 of data 1 and data2. // Pixel 1 is bit 6 etc.. int colourBit = xPos % 8; colourBit -= 7; colourBit *= -1; // combine data 2 and data 1 to get the colour id for this pixel // in the tile int colourNum = bitGetVal(data2, colourBit); colourNum <<= 1; colourNum |= bitGetVal(data1, colourBit); // now we have the colour id get the actual // colour from palette 0xFF47 COLOUR col = getColour(colourNum, BGP); int red = 0; int green = 0; int blue = 0; // setup the RGB values switch (col) { case WHITE: red = 255; green = 255; blue = 255; break; case LIGHT_GREY:red = 0xCC; green = 0xCC; blue = 0xCC; break; case DARK_GREY: red = 0x77; green = 0x77; blue = 0x77; break; } int finaly = _memory->read(0xFF44); // safety check to make sure what im about // to set is int the 160x144 bounds if ((finaly<0) || (finaly>143) || (pixel<0) || (pixel>159)) { continue; } _screenDATA[finaly * 160 + pixel] = (red << 16) | (green << 8) | blue; } }
int CVICALLBACK TankTimer (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_TIMER_TICK: //shut if(testBit(sys->tk[curTankId].xShutOpen,RX) > 0 && testBit(sys->tk[curTankId].xShutClose,RX) == 0 ) SetCtrlVal(panel,PANEL_TANK_SHUT, 2); else if(testBit(sys->tk[curTankId].xShutOpen,RX) == 0 && testBit(sys->tk[curTankId].xShutClose,RX) > 0 ) SetCtrlVal(panel,PANEL_TANK_SHUT, 1); else SetCtrlVal(panel,PANEL_TANK_SHUT, 3); //temp if(preTempTrendPos != sys->curTempTrendPos && sys->tk[curTankId].curTemp != 0) { preTempTrendPos = sys->curTempTrendPos; PlotStripChart (panel, PANEL_TANK_STRIPCHART, &sys->tk[curTankId].curTemp, 1, 0, 0, VAL_DOUBLE); } SetCtrlVal(panel,PANEL_TANK_TEMP, sys->tk[curTankId].curTemp); //valve SetCtrlVal(panel,PANEL_TANK_VALVE_DIW_IN, testBit(sys->tk[curTankId].yValveDiwIn,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOWN, testBit(sys->tk[curTankId].yValveDown,RY)>0 ? 1 : 0); //heater SetCtrlAttribute(panel,PANEL_TANK_HEATER, ATTR_VISIBLE, testBit(sys->tk[curTankId].yHeat,RY)>0 ? 1 : 0); //car SetCtrlVal(panel,PANEL_TANK_CAR1, (curRTankId1 != RTK_UNKNOW && testBit(sys->rtk[curRTankId1].hsFill,WB)>0) ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_CAR2, (curRTankId2 != RTK_UNKNOW && testBit(sys->rtk[curRTankId2].hsFill,WB)>0) ? 1 : 0); //pump SetCtrlVal(panel,PANEL_TANK_PUMP, testBit(sys->tk[curTankId].yPump,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_PUMP, testBit(sys->tk[curTankId].yPumpIn,RY)>0 ? 1 : 0); //level int lev = (testBit(sys->tk[curTankId].xLevLL,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xLevL,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xLevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xLevHH,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_TANK, lev); //make buf tank SetCtrlVal(panel,PANEL_TANK_VALVE_MAKE_AC1_IN, testBit(sys->tk[curTankId].yValveMakeAc1In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_MAKE_AC2_IN, testBit(sys->tk[curTankId].yValveMakeAc2In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_MAKE_AC3_IN, testBit(sys->tk[curTankId].yValveMakeAc3In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_MAKE_AC4_IN, testBit(sys->tk[curTankId].yValveMakeAc4In,RY)>0 ? 1 : 0); /* lev = (testBit(sys->tk[curTankId].xMakeAc1LevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xMakeAc1LevL,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_AC1_MAKE_BUF, lev); lev = (testBit(sys->tk[curTankId].xMakeAc2LevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xMakeAc2LevL,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_AC2_MAKE_BUF, lev); */ SetCtrlVal(panel,PANEL_TANK_MAKE_CH1, sys->tk[curTankId].MakeCountCH1/10.0); SetCtrlVal(panel,PANEL_TANK_MAKE_CH2, sys->tk[curTankId].MakeCountCH2/10.0); SetCtrlVal(panel,PANEL_TANK_MAKE_CH3, sys->tk[curTankId].MakeCountCH3/10.0); SetCtrlVal(panel,PANEL_TANK_MAKE_CH4, sys->tk[curTankId].MakeCountCH4/1.0); SetCtrlVal(panel,PANEL_TANK_MMAKE_CH1, sys->tk[curTankId].MMakeCountCH1/10.0); SetCtrlVal(panel,PANEL_TANK_MMAKE_CH2, sys->tk[curTankId].MMakeCountCH2/10.0); SetCtrlVal(panel,PANEL_TANK_MMAKE_CH3, sys->tk[curTankId].MMakeCountCH3/10.0); SetCtrlVal(panel,PANEL_TANK_MMAKE_CH4, sys->tk[curTankId].MMakeCountCH4/1.0); SetCtrlVal(panel,PANEL_TANK_DOS_CH1, sys->tk[curTankId].DosingCountCH1); SetCtrlVal(panel,PANEL_TANK_DOS_CH2, sys->tk[curTankId].DosingCountCH2); SetCtrlVal(panel,PANEL_TANK_DOS_CH3, sys->tk[curTankId].DosingCountCH3); SetCtrlVal(panel,PANEL_TANK_DOS_CH4, sys->tk[curTankId].DosingCountCH4); SetCtrlVal(panel,PANEL_TANK_FLOW, sys->tk[curTankId].Flow/10.0); SetCtrlVal(panel,PANEL_TANK_COND, sys->tk[curTankId].Cond/1.0); //dosing buf tank SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC1_IN, testBit(sys->tk[curTankId].yValveDosAc1In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC1_OUT, testBit(sys->tk[curTankId].yValveDosAc1Out,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC2_IN, testBit(sys->tk[curTankId].yValveDosAc2In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC2_OUT, testBit(sys->tk[curTankId].yValveDosAc2Out,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC3_IN, testBit(sys->tk[curTankId].yValveDosAc3In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC3_OUT, testBit(sys->tk[curTankId].yValveDosAc3Out,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC4_IN, testBit(sys->tk[curTankId].yValveDosAc4In,RY)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_VALVE_DOS_AC4_OUT, testBit(sys->tk[curTankId].yValveDosAc4Out,RY)>0 ? 1 : 0); lev = (testBit(sys->tk[curTankId].xDosAc1LevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xDosAc1LevL,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_AC1_DOS_BUF, lev); lev = (testBit(sys->tk[curTankId].xDosAc2LevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xDosAc2LevL,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_AC2_DOS_BUF, lev); lev = (testBit(sys->tk[curTankId].xDosAc3LevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xDosAc3LevL,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_AC3_DOS_BUF, lev); lev = (testBit(sys->tk[curTankId].xDosAc4LevH,RX)>0 ? 1 : 0); lev += (testBit(sys->tk[curTankId].xDosAc4LevL,RX)>0 ? 1 : 0); SetCtrlVal(panel,PANEL_TANK_AC4_DOS_BUF, lev); //bubble if(testBit(sys->tk[curTankId].hsBubble,WB) > 0) { bubble(panel, PANEL_TANK_BUBBLE1,180,290,30); bubble(panel, PANEL_TANK_BUBBLE2,180,290,30); bubble(panel, PANEL_TANK_BUBBLE3,180,290,30); bubble(panel, PANEL_TANK_BUBBLE4,180,290,30); bubble(panel, PANEL_TANK_BUBBLE5,180,290,30); bubble(panel, PANEL_TANK_BUBBLE6,180,290,30); bubble(panel, PANEL_TANK_BUBBLE7,180,290,30); } //button if(sys->tk[curTankId].hsMake.wid != 0 || sys->tk[curTankId].hsMake.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_AMAKE_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsMake,RB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_AMAKE_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsMake,RB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsMMake,RB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsMMake,RB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsAC1Dos.wid != 0 || sys->tk[curTankId].hsAC1Dos.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC1Dos,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC1Dos,WB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsAC2Dos.wid != 0 || sys->tk[curTankId].hsAC2Dos.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_AC2_DOS_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC2Dos,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_AC2_DOS_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC2Dos,WB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsAC3Dos.wid != 0 || sys->tk[curTankId].hsAC3Dos.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_AC3_DOS_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC3Dos,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_AC3_DOS_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC3Dos,WB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsAC4Dos.wid != 0 || sys->tk[curTankId].hsAC4Dos.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_AC4_DOS_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC4Dos,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_AC4_DOS_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAC4Dos,WB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsWash.wid != 0 || sys->tk[curTankId].hsWash.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_WASH_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsWash,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_WASH_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsWash,WB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsDown.wid != 0 || sys->tk[curTankId].hsDown.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_DOWN_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsDown,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_DOWN_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsDown,WB) > 0 ? 1 : 0); } if(sys->tk[curTankId].hsPump.wid != 0 || sys->tk[curTankId].hsPump.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_PUMP_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsPump,WB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_TANK_PUMP_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsPump,WB) > 0 ? 0 : 1); } if(sys->tk[curTankId].hsPumpIn.wid != 0 || sys->tk[curTankId].hsPumpIn.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_PUMPIN_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsPumpIn,WB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_TANK_PUMPIN_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsPumpIn,WB) > 0 ? 0 : 1); } if(sys->tk[curTankId].hsHeat.wid != 0 || sys->tk[curTankId].hsHeat.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_HEAT_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsHeat,WB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_TANK_HEAT_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsHeat,WB) > 0 ? 0 : 1); } if(sys->tk[curTankId].hsAddWater.wid != 0 || sys->tk[curTankId].hsAddWater.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_ADD_WATER_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAddWater,WB) > 0 ? 1 : 0); SetCtrlAttribute(panel,PANEL_TANK_ADD_WATER_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsAddWater,WB) > 0 ? 0 : 1); } if(sys->tk[curTankId].hsShutOpen.wid != 0 || sys->tk[curTankId].hsShutOpen.bid != 0 ) { SetCtrlAttribute(panel,PANEL_TANK_SHUT_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsShutOpen,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_SHUT_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsShutOpen,WB) > 0 ? 1 : 0); } /* if(sys->tk[curTankId].hsBubble.wid != 0 || sys->tk[curTankId].hsBubble.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_BUBB_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsBubble,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_BUBB_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsBubble,WB) > 0 ? 1 : 0); } */ if(curRTankId1 != RTK_UNKNOW && (sys->rtk[curRTankId1].hsFill.wid != 0 || sys->rtk[curRTankId1].hsFill.bid != 0)) { SetCtrlAttribute(panel,PANEL_TANK_FILL_OFF, ATTR_VISIBLE, testBit(sys->rtk[curRTankId1].hsFill,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_FILL_ON, ATTR_VISIBLE, testBit(sys->rtk[curRTankId1].hsFill,WB) > 0 ? 1 : 0); } if(curRTankId2 != RTK_UNKNOW && (sys->rtk[curRTankId2].hsFill.wid != 0 || sys->rtk[curRTankId2].hsFill.bid != 0) ) { SetCtrlAttribute(panel,PANEL_TANK_FILL2_OFF, ATTR_VISIBLE, testBit(sys->rtk[curRTankId2].hsFill,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_FILL2_ON, ATTR_VISIBLE, testBit(sys->rtk[curRTankId2].hsFill,WB) > 0 ? 1 : 0); } /* if(sys->tk[curTankId].hsDrain.wid != 0 || sys->tk[curTankId].hsDrain.bid != 0) { SetCtrlAttribute(panel,PANEL_TANK_DRAIN_OFF, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsDrain,WB) > 0 ? 0 : 1); SetCtrlAttribute(panel,PANEL_TANK_DRAIN_ON, ATTR_VISIBLE, testBit(sys->tk[curTankId].hsDrain,WB) > 0 ? 1 : 0); } */ break; } return 0; }
bool QDeviceDiscoveryStatic::checkDeviceType(const QString &device) { int fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); if (Q_UNLIKELY(fd == -1)) { qWarning() << "Device discovery cannot open device" << device; return false; } qCDebug(lcDD) << "doing static device discovery for " << device; if ((m_types & Device_DRM) && device.contains(QLatin1String(QT_DRM_DEVICE_PREFIX))) { QT_CLOSE(fd); return true; } long bitsAbs[LONG_FIELD_SIZE(ABS_CNT)]; long bitsKey[LONG_FIELD_SIZE(KEY_CNT)]; long bitsRel[LONG_FIELD_SIZE(REL_CNT)]; memset(bitsAbs, 0, sizeof(bitsAbs)); memset(bitsKey, 0, sizeof(bitsKey)); memset(bitsRel, 0, sizeof(bitsRel)); ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(bitsAbs)), bitsAbs); ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(bitsKey)), bitsKey); ioctl(fd, EVIOCGBIT(EV_REL, sizeof(bitsRel)), bitsRel); QT_CLOSE(fd); if ((m_types & Device_Keyboard)) { if (testBit(KEY_Q, bitsKey)) { qCDebug(lcDD) << "Found keyboard at" << device; return true; } } if ((m_types & Device_Mouse)) { if (testBit(REL_X, bitsRel) && testBit(REL_Y, bitsRel) && testBit(BTN_MOUSE, bitsKey)) { qCDebug(lcDD) << "Found mouse at" << device; return true; } } if ((m_types & (Device_Touchpad | Device_Touchscreen))) { if (testBit(ABS_X, bitsAbs) && testBit(ABS_Y, bitsAbs)) { if ((m_types & Device_Touchpad) && testBit(BTN_TOOL_FINGER, bitsKey)) { qCDebug(lcDD) << "Found touchpad at" << device; return true; } else if ((m_types & Device_Touchscreen) && testBit(BTN_TOUCH, bitsKey)) { qCDebug(lcDD) << "Found touchscreen at" << device; return true; } else if ((m_types & Device_Tablet) && (testBit(BTN_STYLUS, bitsKey) || testBit(BTN_TOOL_PEN, bitsKey))) { qCDebug(lcDD) << "Found tablet at" << device; return true; } } else if (testBit(ABS_MT_POSITION_X, bitsAbs) && testBit(ABS_MT_POSITION_Y, bitsAbs)) { qCDebug(lcDD) << "Found new-style touchscreen at" << device; return true; } } if ((m_types & Device_Joystick)) { if (testBit(BTN_A, bitsKey) || testBit(BTN_TRIGGER, bitsKey) || testBit(ABS_RX, bitsAbs)) { qCDebug(lcDD) << "Found joystick/gamepad at" << device; return true; } } return false; }
void initTankPanel(int panel,TANK_ID tid,RTANK_ID rid1,RTANK_ID rid2) { curTankId = tid; curRTankId1 = rid1; curRTankId2 = rid2; SetPanelAttribute(panel,ATTR_TITLE, sys->tk[tid].name); //heater int v = (sys->tk[tid].hsHeat.wid == 0 && sys->tk[tid].hsHeat.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_TEMP, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_HEATER, ATTR_VISIBLE, v); //valve v = (tid > TANK_15 || (sys->tk[tid].hsDown.wid == 0 && sys->tk[tid].hsDown.wid == 0))?0:1; SetCtrlAttribute(panel,PANEL_TANK_VALVE_DIW_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOWN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_9, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_10, ATTR_VISIBLE, v); //dosing and make v = (sys->tk[tid].hsMake.wid == 0 && sys->tk[tid].hsMake.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC1_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC2_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC3_IN, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC4_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC1_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_BUF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC1_OUT, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC2_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC2_DOS_BUF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC2_OUT, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC3_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC3_DOS_BUF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC3_OUT, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) { SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC4_IN, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC4_DOS_BUF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC4_OUT, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_4, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_8, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_14, ATTR_VISIBLE, v); } SetCtrlAttribute(panel,PANEL_TANK_SPLITTER, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_2, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_3, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_5, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_6, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_7, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_11, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_12, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SPLITTER_13, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC1_MAKE, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC2_MAKE, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC3_MAKE, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) SetCtrlAttribute(panel,PANEL_TANK_AC4_MAKE, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AMAKE_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AMAKE_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AMAKE_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC2_DOS_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC2_DOS_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC3_DOS_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC3_DOS_ON, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) { SetCtrlAttribute(panel,PANEL_TANK_AC4_DOS_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC4_DOS_ON, ATTR_VISIBLE, v); } SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC2_DOS_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_AC3_DOS_LAB, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) SetCtrlAttribute(panel,PANEL_TANK_AC4_DOS_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DECORATION_MAKE, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DECORATION_DOS, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MAKE_CH1, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MAKE_CH2, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MAKE_CH3, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_CH1, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_CH2, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_CH3, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) { SetCtrlAttribute(panel,PANEL_TANK_MAKE_CH4, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_MMAKE_CH4, ATTR_VISIBLE, v); } SetCtrlAttribute(panel,PANEL_TANK_DOS_CH1, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DOS_CH2, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DOS_CH3, ATTR_VISIBLE, v); if(tid == TANK_04 || tid == TANK_07) SetCtrlAttribute(panel,PANEL_TANK_DOS_CH4, ATTR_VISIBLE, v); //SetCtrlAttribute(panel,PANEL_TANK_FLOW, ATTR_VISIBLE, v); //wash v = (sys->tk[tid].hsWash.wid == 0 && sys->tk[tid].hsWash.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_WASH_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_WASH_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_WASH_LAB, ATTR_VISIBLE, v); //down v = (sys->tk[tid].hsDown.wid == 0 && sys->tk[tid].hsDown.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_DOWN_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DOWN_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DOWN_LAB, ATTR_VISIBLE, v); //PUMP v = (sys->tk[tid].hsPump.wid == 0 && sys->tk[tid].hsPump.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_PUMP_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_PUMP_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_PUMP_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_PUMP, ATTR_VISIBLE, v); if(tid == TANK_AUX_DIW || tid == TANK_AUX_TEX || tid == TANK_AUX_HF) SetCtrlAttribute(panel,PANEL_TANK_PUMP, ATTR_VISIBLE, 1); //inlne PUMP v = (sys->tk[tid].hsPumpIn.wid == 0 && sys->tk[tid].hsPumpIn.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_PUMPIN_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_PUMPIN_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_PUMPIN_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_PUMPIN, ATTR_VISIBLE, v); //HEAT v = (sys->tk[tid].hsHeat.wid == 0 && sys->tk[tid].hsHeat.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_HEAT_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_HEAT_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_HEAT_LAB, ATTR_VISIBLE, v); //SHUT v = (sys->tk[tid].hsShutOpen.wid == 0 && sys->tk[tid].hsShutOpen.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_SHUT_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SHUT_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SHUT_LAB, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_SHUT, ATTR_VISIBLE, v); //CAR v = (rid1 == RTK_UNKNOW || (sys->rtk[rid1].hsFill.wid == 0 && sys->rtk[rid1].hsFill.wid == 0))?0:1; SetCtrlAttribute(panel,PANEL_TANK_FILL_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_FILL_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_FILL1_LAB, ATTR_VISIBLE, v); v = (rid2 == RTK_UNKNOW)?0:1; SetCtrlAttribute(panel,PANEL_TANK_FILL2_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_FILL2_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_FILL2_LAB, ATTR_VISIBLE, v); //add water v = (sys->tk[tid].hsAddWater.wid == 0 && sys->tk[tid].hsAddWater.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_ADD_WATER_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_ADD_WATER_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_ADD_WATER_LAB, ATTR_VISIBLE, v); //BUBBle /* v = (sys->tk[tid].hsBubble.wid == 0 && sys->tk[tid].hsBubble.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_BUBB_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_BUBB_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_BUBB_LAB, ATTR_VISIBLE, v);*/ // SetCtrlAttribute(panel,PANEL_TANK_COND, ATTR_VISIBLE, v); //drain /* v = (sys->tk[tid].hsDrain.wid == 0 && sys->tk[tid].hsDrain.wid == 0)?0:1; SetCtrlAttribute(panel,PANEL_TANK_DRAIN_OFF, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DRAIN_ON, ATTR_VISIBLE, v); SetCtrlAttribute(panel,PANEL_TANK_DRAIN_LAB, ATTR_VISIBLE, v); */ if(tid == TANK_02) { SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC1_IN, ATTR_LABEL_TEXT, "H2O2\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC1_IN, ATTR_LABEL_TEXT, "H2O2\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC1_MAKE, ATTR_LABEL_TEXT, "H2O2(L) "); SetCtrlVal(panel,PANEL_TANK_AC1_DOS_LAB, "H2O2¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC2_IN, ATTR_LABEL_TEXT, "KOH\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC2_IN, ATTR_LABEL_TEXT, "KOH\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC2_MAKE, ATTR_LABEL_TEXT, "KOH(L) "); SetCtrlVal(panel,PANEL_TANK_AC2_DOS_LAB, "KOH¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC3_IN, ATTR_LABEL_TEXT, "DIW\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC3_IN, ATTR_LABEL_TEXT, "DIW\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC3_MAKE, ATTR_LABEL_TEXT, "DIW(L) "); SetCtrlVal(panel,PANEL_TANK_AC3_DOS_LAB, "DIW¸É²G"); } if(tid == TANK_04 || tid == TANK_07) { SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC1_IN, ATTR_LABEL_TEXT, "IPA\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC3_IN, ATTR_LABEL_TEXT, "IPA\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC1_MAKE, ATTR_LABEL_TEXT, "IPA(L) "); SetCtrlVal(panel,PANEL_TANK_AC1_DOS_LAB, "IPA¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC1_MAKE, ATTR_DIMMED, 1); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_OFF, ATTR_DIMMED, 1); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_ON, ATTR_DIMMED, 1); /*SetCtrlAttribute(panel,PANEL_TANK_AC1_MAKE, ATTR_VISIBLE, 0); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_LAB, ATTR_VISIBLE, 0); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_OFF, ATTR_VISIBLE, 0); SetCtrlAttribute(panel,PANEL_TANK_AC1_DOS_ON, ATTR_VISIBLE, 0); */ SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC2_IN, ATTR_LABEL_TEXT, "KOH\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC2_IN, ATTR_LABEL_TEXT, "KOH\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC2_MAKE, ATTR_LABEL_TEXT, "KOH(L) "); SetCtrlVal(panel,PANEL_TANK_AC2_DOS_LAB, "KOH¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC3_IN, ATTR_LABEL_TEXT, "DIW\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC1_IN, ATTR_LABEL_TEXT, "DIW\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC3_MAKE, ATTR_LABEL_TEXT, "DIW(L) "); SetCtrlVal(panel,PANEL_TANK_AC3_DOS_LAB, "DIW¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC4_IN, ATTR_LABEL_TEXT, "ADD\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC4_IN, ATTR_LABEL_TEXT, "ADD\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC4_MAKE, ATTR_LABEL_TEXT, "ADD(ML) "); SetCtrlVal(panel,PANEL_TANK_AC4_DOS_LAB, "ADD¸É²G"); } else if(tid == TANK_11) { SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC2_IN, ATTR_LABEL_TEXT, "HF\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC2_IN, ATTR_LABEL_TEXT, "HF\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC2_MAKE, ATTR_LABEL_TEXT, "HF(L) "); SetCtrlVal(panel,PANEL_TANK_AC2_DOS_LAB, "HF¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC1_IN, ATTR_LABEL_TEXT, "HCL\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC1_IN, ATTR_LABEL_TEXT, "HCL\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC1_MAKE, ATTR_LABEL_TEXT, "HCL(L) "); SetCtrlVal(panel,PANEL_TANK_AC1_DOS_LAB, "HCL¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_MAKE_AC3_IN, ATTR_LABEL_TEXT, "DIW\n°t¼Ñ"); SetCtrlAttribute(panel,PANEL_TANK_VALVE_DOS_AC3_IN, ATTR_LABEL_TEXT, "DIW\n¸É²G"); SetCtrlAttribute(panel,PANEL_TANK_AC3_MAKE, ATTR_LABEL_TEXT, "DIW(L) "); SetCtrlVal(panel,PANEL_TANK_AC3_DOS_LAB, "DIW¸É²G"); } if(tid == TANK_02 || tid == TANK_04 || tid == TANK_07 || tid == TANK_11) { if(testBit(sys->tk[tid].hsMake,RB) > 0) { SetCtrlVal(panel,PANEL_TANK_AC1_MAKE,sys->tk[tid].MakeCH1); SetCtrlVal(panel,PANEL_TANK_AC2_MAKE,sys->tk[tid].MakeCH2); SetCtrlVal(panel,PANEL_TANK_AC3_MAKE,sys->tk[tid].MakeCH3); SetCtrlVal(panel,PANEL_TANK_AC4_MAKE,sys->tk[tid].MakeCH4); } else if(testBit(sys->tk[tid].hsMMake,RB) > 0) { SetCtrlVal(panel,PANEL_TANK_AC1_MAKE,sys->tk[tid].MMakeCH1); SetCtrlVal(panel,PANEL_TANK_AC2_MAKE,sys->tk[tid].MMakeCH2); SetCtrlVal(panel,PANEL_TANK_AC3_MAKE,sys->tk[tid].MMakeCH3); SetCtrlVal(panel,PANEL_TANK_AC4_MAKE,sys->tk[tid].MMakeCH4); } } preTempTrendPos = sys->curTempTrendPos; if(sys->tk[curTankId].tempData[TREND_DATA_LEN - sys->curTempTrendPos - 1] != 0) PlotStripChart (panel, PANEL_TANK_STRIPCHART, sys->tk[curTankId].tempData, TREND_DATA_LEN - sys->curTempTrendPos - 1, sys->curTempTrendPos+1, 0, VAL_DOUBLE); PlotStripChart (panel, PANEL_TANK_STRIPCHART, sys->tk[curTankId].tempData, sys->curTempTrendPos + 1, 0, 0, VAL_DOUBLE); }
/* Initialize device, create constant force effect */ void init_device() { unsigned char key_bits[1 + KEY_MAX/8/sizeof(unsigned char)]; unsigned char abs_bits[1 + ABS_MAX/8/sizeof(unsigned char)]; unsigned char ff_bits[1 + FF_MAX/8/sizeof(unsigned char)]; struct input_event event; struct input_absinfo absinfo; /* Open event device with write permission */ device_handle = open(device_name,O_RDWR|O_NONBLOCK); if (device_handle<0) { fprintf(stderr,"ERROR: can not open %s (%s) [%s:%d]\n", device_name,strerror(errno),__FILE__,__LINE__); exit(1); } /* Which buttons has the device? */ memset(key_bits,0,sizeof(key_bits)); if (ioctl(device_handle,EVIOCGBIT(EV_KEY,sizeof(key_bits)),key_bits)<0) { fprintf(stderr,"ERROR: can not get key bits (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } /* Which axes has the device? */ memset(abs_bits,0,sizeof(abs_bits)); if (ioctl(device_handle,EVIOCGBIT(EV_ABS,sizeof(abs_bits)),abs_bits)<0) { fprintf(stderr,"ERROR: can not get abs bits (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } /* Now get some information about force feedback */ memset(ff_bits,0,sizeof(ff_bits)); if (ioctl(device_handle,EVIOCGBIT(EV_FF ,sizeof(ff_bits)),ff_bits)<0) { fprintf(stderr,"ERROR: can not get ff bits (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } /* Check if selected axis is available */ if (!testBit(axis_code, abs_bits)) { fprintf(stderr,"ERROR: selected axis %s not available [%s:%d] (see available ones with fftest)\n", axis_names[axis_index], __FILE__,__LINE__); exit(1); } /* get axis value range */ if (ioctl(device_handle,EVIOCGABS(axis_code),&absinfo)<0) { fprintf(stderr,"ERROR: can not get axis value range (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } axis_min=absinfo.minimum; axis_max=absinfo.maximum; if (axis_min>=axis_max) { fprintf(stderr,"ERROR: bad axis value range (%d,%d) [%s:%d]\n", axis_min,axis_max,__FILE__,__LINE__); exit(1); } /* force feedback supported? */ if (!testBit(FF_CONSTANT,ff_bits)) { fprintf(stderr,"ERROR: device (or driver) has no constant force feedback support [%s:%d]\n", __FILE__,__LINE__); exit(1); } /* Switch off auto centering */ if (autocenter_off) { memset(&event,0,sizeof(event)); event.type=EV_FF; event.code=FF_AUTOCENTER; event.value=0; if (write(device_handle,&event,sizeof(event))!=sizeof(event)) { fprintf(stderr,"ERROR: failed to disable auto centering (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } } /* Initialize constant force effect */ memset(&effect,0,sizeof(effect)); effect.type=FF_CONSTANT; effect.id=-1; effect.trigger.button=0; effect.trigger.interval=0; effect.replay.length=0xffff; effect.replay.delay=0; effect.u.constant.level=0; effect.direction=0xC000; effect.u.constant.envelope.attack_length=0; effect.u.constant.envelope.attack_level=0; effect.u.constant.envelope.fade_length=0; effect.u.constant.envelope.fade_level=0; /* Upload effect */ if (ioctl(device_handle,EVIOCSFF,&effect)<0) { fprintf(stderr,"ERROR: uploading effect failed (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } /* Start effect */ memset(&event,0,sizeof(event)); event.type=EV_FF; event.code=effect.id; event.value=1; if (write(device_handle,&event,sizeof(event))!=sizeof(event)) { fprintf(stderr,"ERROR: starting effect failed (%s) [%s:%d]\n", strerror(errno),__FILE__,__LINE__); exit(1); } }
int ipfix_decode(anonpacket * p, struct IPFIX *ipfix, struct anonflow *flow) { uint16_t i = 0, j = 0, set_length = 0; unsigned char *payload = NULL; struct ipfix_template_set *tmp_template = NULL; struct ipfix_template_record *tmp_record = NULL; if (!ipfix) return (-1); if (!(p->iph)) return (-1); if (p->data == NULL || p->dsize < sizeof(struct ipfix_header)) return (-1); if (!(p->udph) && !(p->tcph)) return (-1); memset(ipfix, 0, sizeof(struct IPFIX)); payload = (unsigned char *)p->data; ipfix->header = (struct ipfix_header *)payload; payload += sizeof(struct ipfix_header); if (ntohs(ipfix->header->length) > p->dsize) return (-1); // XXX could IPFIX span multiple datagrams? while ((uint16_t) (payload - p->data) < p->dsize) { i = ntohs(*(uint16_t *) payload); if (i == 2) // Template set { ipfix->templates = realloc(ipfix->templates, (++ipfix->ntemplates) * sizeof(struct ipfix_template_set *)); ipfix->templates[ipfix->ntemplates - 1] = malloc(sizeof(struct ipfix_template_set)); ipfix->templates[ipfix->ntemplates - 1]->header = (struct ipfix_set_header *)payload; i = sizeof(struct ipfix_set_header); payload += i; tmp_template = ipfix->templates[ipfix->ntemplates - 1]; tmp_template->nrecords = 0; tmp_template->records = NULL; set_length = ntohs(tmp_template->header->length); while (i < set_length) { if (*(uint16_t *) payload == 0) { // Padding! payload = (unsigned char *)tmp_template->header + ntohs(tmp_template->header->length); break; } tmp_template->records = realloc(tmp_template->records, (++tmp_template->nrecords) * sizeof(struct ipfix_template_record *)); tmp_template->records[tmp_template->nrecords - 1] = malloc(sizeof(struct ipfix_template_record)); tmp_template->records[tmp_template->nrecords - 1]->header = malloc(sizeof(struct ipfix_template_header)); tmp_template->records[tmp_template->nrecords - 1]->header->id = ntohs(((struct ipfix_template_header *)payload)->id); tmp_template->records[tmp_template->nrecords - 1]->header->count = ntohs(((struct ipfix_template_header *)payload)->count); i += sizeof(struct ipfix_template_header); payload += sizeof(struct ipfix_template_header); tmp_record = tmp_template->records[tmp_template->nrecords - 1]; tmp_record->nvendor = tmp_record->nietf = 0; tmp_record->ietf_fields = NULL; tmp_record->vendor_fields = NULL; tmp_record->nfields = ntohs(tmp_record->header->count); tmp_record->fields = malloc(tmp_record->nfields * sizeof(unsigned char *)); for (j = 0; j < tmp_record->nfields; j++) { tmp_record->fields[j] = payload; if (testBit(*payload, 7)) { tmp_record->nvendor++; tmp_record->vendor_fields = realloc(tmp_record->vendor_fields, tmp_record->nvendor * sizeof(struct ipfix_vendor_field_specifier)); tmp_record->vendor_fields[tmp_record->nvendor - 1].id = ntohs(*(uint16_t *) payload); payload += sizeof(uint16_t); tmp_record->vendor_fields[tmp_record->nvendor - 1].length = ntohs(*(uint16_t *) payload); payload += sizeof(uint16_t); tmp_record->vendor_fields[tmp_record->nvendor - 1].enterprise = ntohl(*(uint32_t *) payload); payload += sizeof(uint32_t); i += sizeof(struct ipfix_vendor_field_specifier); } else { tmp_record->nietf++; tmp_record->ietf_fields = realloc(tmp_record->ietf_fields, tmp_record->nietf * sizeof(struct ipfix_ietf_field_specifier)); tmp_record->ietf_fields[tmp_record->nietf - 1].id = ntohs(*(uint16_t *) payload); payload += sizeof(uint16_t); tmp_record->ietf_fields[tmp_record->nietf - 1].length = ntohs(*(uint16_t *) payload); payload += sizeof(uint16_t); i += sizeof(struct ipfix_ietf_field_specifier); } } } // Check against template records with the same ID and replace/insert. struct ipfix_template_record *tmp = NULL; for (j = 0; j < tmp_template->nrecords; j++) { if ((tmp = flist_remove(flow->ipfix_templates, tmp_template->records[j]->header->id, FLIST_LEAVE_DATA)) != NULL) { // free it. } // Insert the new template record. flist_append(flow->ipfix_templates, tmp_template->records[j]->header->id, tmp_template->records[j]); } } else if (i == 3) {// Option Template set } else if (i >= 4 && i <= 255) { // reserved for future use payload += sizeof(uint16_t); payload += ntohs(*(uint16_t *) payload); continue; } else if (i > 256) { // Data set ipfix->data = realloc(ipfix->data, ++(ipfix->ndata) * sizeof(struct ipfix_data_set *)); ipfix->data[ipfix->ndata - 1] = malloc(sizeof(struct ipfix_data_set)); ipfix->data[ipfix->ndata - 1]->header = (struct ipfix_set_header *)payload; ipfix->data[ipfix->ndata - 1]->nfields = 0; payload += sizeof(struct ipfix_set_header); i = sizeof(struct ipfix_set_header); // If you try debugging this, good luck. while (i < ntohs(ipfix->data[ipfix->ndata - 1]->header->length)) { if (*(uint16_t *) payload == 0) { // Padding! payload = (unsigned char *)ipfix->data[ipfix->ndata - 1]->header + ntohs(ipfix->data[ipfix->ndata - 1]->header->length); break; } ipfix->data[ipfix->ndata - 1]->fields = realloc(ipfix->data[ipfix->ndata - 1]->fields, ++(ipfix->data[ipfix->ndata - 1]->nfields) * sizeof(unsigned char *)); ipfix->data[ipfix->ndata - 1]->fields[ipfix->data[ipfix->ndata - 1]->nfields - 1] = payload; payload += ((unsigned char)(*payload & (1 << 8))) ? sizeof(struct ipfix_vendor_field_specifier) : sizeof(struct ipfix_ietf_field_specifier); i += ((unsigned char)(*payload & (1 << 8))) ? sizeof(struct ipfix_vendor_field_specifier) : sizeof(struct ipfix_ietf_field_specifier); } } else return (-1); } return (0); }
int main (int argc, char **argv) { int qflag = 0; unsigned long int m_size = UINT_MAX; int object_size; int n_procs = 1; unsigned long int i = 0; unsigned long int j = 0; int n = 0; pid_t pids[n_procs]; pid_t pid; int status; parse_com(argc, argv, &qflag, &m_size, &n_procs); unsigned int *bitmap; object_size = UINT_MAX/8 + 4; //create shared memory void *addr = create_mem("/hazlettb_prime", object_size); bitmap = (unsigned int*)addr; //set up bitmap for sieve for (i=3;i<m_size;i+=2) setBit(bitmap,i); //fork the children for (i = 0; i < n_procs; ++i) { if ((pids[i] = fork()) < 0) { perror("fork"); abort(); } else if (pids[i] == 0) { //each child calculates and stores some of the primes n = 3 + 2*i; for (i = n; i < m_size; i+=(2*n_procs)){ if (testBit(bitmap, i)) for (j=i;i*j<m_size;j++) clearBit(bitmap,(i*j)); } exit(0); } } //wait for children to exit while (n_procs > 0) { pid = wait(&status); --n_procs; } //step through array, check for twins and print if no q for (i = 0; i < (m_size - 2); i++) { if (testBit(bitmap, i) && testBit(bitmap,(i+2))) { if (qflag == 0) printf("%lu %lu\n", i, i + 2); } } //unlink memory object if (shm_unlink("/hazlettb_prime") == -1) printf("unlink failed"); return 0; }
void Video::setLCDStatus(CPU &cpuTemp) { BYTE status = _memory->read(0xFF41); if (!isLCDEnabled()) { // set the mode to 1 during lcd disabled and reset scanline _scanLineCounter = 456; _memory->directModification(LY, 0x00); status &= 0xFC; status = bitSet(status, 0); _memory->write(0xFF41, status); return; } BYTE currentline = _memory->read(LY); BYTE currentmode = status & 0x03; BYTE mode = 0x00; bool reqInt = false; // If is greater we are in VBLank period if (currentline >= 144) { mode = 0x01; status = bitSet(status, 0); status = bitReset(status, 1); reqInt = testBit(status, 4); } // Else, we are drawing scanlines in panel else { int mode2bounds = 456 - 80; int mode3bounds = mode2bounds - 172; // mode 2 if (_scanLineCounter >= mode2bounds) { mode = 0x02; status = bitSet(status, 1); status = bitReset(status, 0); reqInt = testBit(status, 5); } // mode 3 else if (_scanLineCounter >= mode3bounds) { mode = 0x03; status = bitSet(status, 1); status = bitSet(status, 0); } // mode 0 else { mode = 0x00; status = bitReset(status, 1); status = bitReset(status, 0); reqInt = testBit(status, 3); } } // just entered a new mode so request interupt if (reqInt && (mode != currentmode)) cpuTemp.requestInterrupt(LCD); // check the conincidence flag if (_memory->read(LY) == _memory->read(LYC)) { status = bitSet(status, 2); if (testBit(status, 6)) cpuTemp.requestInterrupt(LCD); } else { status = bitReset(status, 2); } _memory->write(0xFF41, status); }
int main(int argc, char** argv) { struct ff_effect effects[N_EFFECTS]; struct input_event play, stop, gain; int fd; const char * device_file_name = "/dev/input/event0"; unsigned char relFeatures[1 + REL_MAX/8/sizeof(unsigned char)]; unsigned char absFeatures[1 + ABS_MAX/8/sizeof(unsigned char)]; unsigned char ffFeatures[1 + FF_MAX/8/sizeof(unsigned char)]; int n_effects; /* Number of effects the device can play at the same time */ int i; printf("Force feedback test program.\n"); printf("HOLD FIRMLY YOUR WHEEL OR JOYSTICK TO PREVENT DAMAGES\n\n"); for (i=1; i<argc; ++i) { if (strncmp(argv[i], "--help", 64) == 0) { printf("Usage: %s /dev/input/eventXX\n", argv[0]); printf("Tests the force feedback driver\n"); exit(1); } else { device_file_name = argv[i]; } } /* Open device */ fd = open(device_file_name, O_RDWR); if (fd == -1) { perror("Open device file"); exit(1); } printf("Device %s opened\n", device_file_name); /* Query device */ printf("Features:\n"); /* Absolute axes */ memset(absFeatures, 0, sizeof(absFeatures)*sizeof(unsigned char)); if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absFeatures)*sizeof(unsigned char)), absFeatures) == -1) { perror("Ioctl absolute axes features query"); exit(1); } printf(" * Absolute axes: "); if (testBit(ABS_X, absFeatures)) printf("X, "); if (testBit(ABS_Y, absFeatures)) printf("Y, "); if (testBit(ABS_Z, absFeatures)) printf("Z, "); if (testBit(ABS_RX, absFeatures)) printf("RX, "); if (testBit(ABS_RY, absFeatures)) printf("RY, "); if (testBit(ABS_RZ, absFeatures)) printf("RZ, "); if (testBit(ABS_THROTTLE, absFeatures)) printf("Throttle, "); if (testBit(ABS_RUDDER, absFeatures)) printf("Rudder, "); if (testBit(ABS_WHEEL, absFeatures)) printf("Wheel, "); if (testBit(ABS_GAS, absFeatures)) printf("Gas, "); if (testBit(ABS_BRAKE, absFeatures)) printf("Brake, "); if (testBit(ABS_HAT0X, absFeatures)) printf("Hat 0 X, "); if (testBit(ABS_HAT0Y, absFeatures)) printf("Hat 0 Y, "); if (testBit(ABS_HAT1X, absFeatures)) printf("Hat 1 X, "); if (testBit(ABS_HAT1Y, absFeatures)) printf("Hat 1 Y, "); if (testBit(ABS_HAT2X, absFeatures)) printf("Hat 2 X, "); if (testBit(ABS_HAT2Y, absFeatures)) printf("Hat 2 Y, "); if (testBit(ABS_HAT3X, absFeatures)) printf("Hat 3 X, "); if (testBit(ABS_HAT3Y, absFeatures)) printf("Hat 3 Y, "); if (testBit(ABS_PRESSURE, absFeatures)) printf("Pressure, "); if (testBit(ABS_DISTANCE, absFeatures)) printf("Distance, "); if (testBit(ABS_TILT_X, absFeatures)) printf("Tilt X, "); if (testBit(ABS_TILT_Y, absFeatures)) printf("Tilt Y, "); if (testBit(ABS_TOOL_WIDTH, absFeatures)) printf("Tool width, "); if (testBit(ABS_VOLUME, absFeatures)) printf("Volume, "); if (testBit(ABS_MISC, absFeatures)) printf("Misc ,"); printf("\n ["); for (i=0; i<sizeof(absFeatures)/sizeof(unsigned char);i++) printf("%02X ", absFeatures[i]); printf("]\n"); /* Relative axes */ memset(relFeatures, 0, sizeof(relFeatures)*sizeof(unsigned char)); if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relFeatures)*sizeof(unsigned char)), relFeatures) == -1) { perror("Ioctl relative axes features query"); exit(1); } printf(" * Relative axes: "); if (testBit(REL_X, relFeatures)) printf("X, "); if (testBit(REL_Y, relFeatures)) printf("Y, "); if (testBit(REL_Z, relFeatures)) printf("Z, "); if (testBit(REL_RX, relFeatures)) printf("RX, "); if (testBit(REL_RY, relFeatures)) printf("RY, "); if (testBit(REL_RZ, relFeatures)) printf("RZ, "); if (testBit(REL_HWHEEL, relFeatures)) printf("HWheel, "); if (testBit(REL_DIAL, relFeatures)) printf("Dial, "); if (testBit(REL_WHEEL, relFeatures)) printf("Wheel, "); if (testBit(REL_MISC, relFeatures)) printf("Misc, "); printf("\n ["); for (i=0; i<sizeof(relFeatures)/sizeof(unsigned char);i++) printf("%02X ", relFeatures[i]); printf("]\n"); /* Force feedback effects */ memset(ffFeatures, 0, sizeof(ffFeatures)*sizeof(unsigned char)); if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ffFeatures)*sizeof(unsigned char)), ffFeatures) == -1) { perror("Ioctl force feedback features query"); exit(1); } printf(" * Force feedback effects types: "); if (testBit(FF_CONSTANT, ffFeatures)) printf("Constant, "); if (testBit(FF_PERIODIC, ffFeatures)) printf("Periodic, "); if (testBit(FF_RAMP, ffFeatures)) printf("Ramp, "); if (testBit(FF_SPRING, ffFeatures)) printf("Spring, "); if (testBit(FF_FRICTION, ffFeatures)) printf("Friction, "); if (testBit(FF_DAMPER, ffFeatures)) printf("Damper, "); if (testBit(FF_RUMBLE, ffFeatures)) printf("Rumble, "); if (testBit(FF_INERTIA, ffFeatures)) printf("Inertia, "); if (testBit(FF_GAIN, ffFeatures)) printf("Gain, "); if (testBit(FF_AUTOCENTER, ffFeatures)) printf("Autocenter, "); printf("\n Force feedback periodic effects: "); if (testBit(FF_SQUARE, ffFeatures)) printf("Square, "); if (testBit(FF_TRIANGLE, ffFeatures)) printf("Triangle, "); if (testBit(FF_SINE, ffFeatures)) printf("Sine, "); if (testBit(FF_SAW_UP, ffFeatures)) printf("Saw up, "); if (testBit(FF_SAW_DOWN, ffFeatures)) printf("Saw down, "); if (testBit(FF_CUSTOM, ffFeatures)) printf("Custom, "); printf("\n ["); for (i=0; i<sizeof(ffFeatures)/sizeof(unsigned char);i++) printf("%02X ", ffFeatures[i]); printf("]\n"); printf(" * Number of simultaneous effects: "); if (ioctl(fd, EVIOCGEFFECTS, &n_effects) == -1) { perror("Ioctl number of effects"); } printf("%d\n\n", n_effects); /* Set master gain to 75% if supported */ if (testBit(FF_GAIN, ffFeatures)) { memset(&gain, 0, sizeof(gain)); gain.type = EV_FF; gain.code = FF_GAIN; gain.value = 0xC000; /* [0, 0xFFFF]) */ printf("Setting master gain to 75%% ... "); fflush(stdout); if (write(fd, &gain, sizeof(gain)) != sizeof(gain)) { perror("Error:"); } else { printf("OK\n"); } } /* download a periodic sinusoidal effect */ memset(&effects[0],0,sizeof(effects[0])); effects[0].type = FF_PERIODIC; effects[0].id = -1; effects[0].u.periodic.waveform = FF_SINE; effects[0].u.periodic.period = 100; /* 0.1 second */ effects[0].u.periodic.magnitude = 0x7fff; /* 0.5 * Maximum magnitude */ effects[0].u.periodic.offset = 0; effects[0].u.periodic.phase = 0; effects[0].direction = 0x4000; /* Along X axis */ effects[0].u.periodic.envelope.attack_length = 1000; effects[0].u.periodic.envelope.attack_level = 0x7fff; effects[0].u.periodic.envelope.fade_length = 1000; effects[0].u.periodic.envelope.fade_level = 0x7fff; effects[0].trigger.button = 0; effects[0].trigger.interval = 0; effects[0].replay.length = 20000; /* 20 seconds */ effects[0].replay.delay = 1000; printf("Uploading effect #0 (Periodic sinusoidal) ... "); fflush(stdout); if (ioctl(fd, EVIOCSFF, &effects[0]) == -1) { perror("Error:"); } else { printf("OK (id %d)\n", effects[0].id); } /* download a constant effect */ effects[1].type = FF_CONSTANT; effects[1].id = -1; effects[1].u.constant.level = 0x2000; /* Strength : 25 % */ effects[1].direction = 0x6000; /* 135 degrees */ effects[1].u.constant.envelope.attack_length = 1000; effects[1].u.constant.envelope.attack_level = 0x1000; effects[1].u.constant.envelope.fade_length = 1000; effects[1].u.constant.envelope.fade_level = 0x1000; effects[1].trigger.button = 0; effects[1].trigger.interval = 0; effects[1].replay.length = 20000; /* 20 seconds */ effects[1].replay.delay = 0; printf("Uploading effect #1 (Constant) ... "); fflush(stdout); if (ioctl(fd, EVIOCSFF, &effects[1]) == -1) { perror("Error"); } else { printf("OK (id %d)\n", effects[1].id); } /* download a condition spring effect */ effects[2].type = FF_SPRING; effects[2].id = -1; effects[2].u.condition[0].right_saturation = 0x7fff; effects[2].u.condition[0].left_saturation = 0x7fff; effects[2].u.condition[0].right_coeff = 0x2000; effects[2].u.condition[0].left_coeff = 0x2000; effects[2].u.condition[0].deadband = 0x0; effects[2].u.condition[0].center = 0x0; effects[2].u.condition[1] = effects[2].u.condition[0]; effects[2].trigger.button = 0; effects[2].trigger.interval = 0; effects[2].replay.length = 20000; /* 20 seconds */ effects[2].replay.delay = 0; printf("Uploading effect #2 (Spring) ... "); fflush(stdout); if (ioctl(fd, EVIOCSFF, &effects[2]) == -1) { perror("Error"); } else { printf("OK (id %d)\n", effects[2].id); } /* download a condition damper effect */ effects[3].type = FF_DAMPER; effects[3].id = -1; effects[3].u.condition[0].right_saturation = 0x7fff; effects[3].u.condition[0].left_saturation = 0x7fff; effects[3].u.condition[0].right_coeff = 0x2000; effects[3].u.condition[0].left_coeff = 0x2000; effects[3].u.condition[0].deadband = 0x0; effects[3].u.condition[0].center = 0x0; effects[3].u.condition[1] = effects[3].u.condition[0]; effects[3].trigger.button = 0; effects[3].trigger.interval = 0; effects[3].replay.length = 20000; /* 20 seconds */ effects[3].replay.delay = 0; printf("Uploading effect #3 (Damper) ... "); fflush(stdout); if (ioctl(fd, EVIOCSFF, &effects[3]) == -1) { perror("Error"); } else { printf("OK (id %d)\n", effects[3].id); } /* a strong rumbling effect */ effects[4].type = FF_RUMBLE; effects[4].id = -1; effects[4].u.rumble.strong_magnitude = 0x8000; effects[4].u.rumble.weak_magnitude = 0; effects[4].replay.length = 5000; effects[4].replay.delay = 1000; printf("Uploading effect #4 (Strong rumble, with heavy motor) ... "); fflush(stdout); if (ioctl(fd, EVIOCSFF, &effects[4]) == -1) { perror("Error"); } else { printf("OK (id %d)\n", effects[4].id); } /* a weak rumbling effect */ effects[5].type = FF_RUMBLE; effects[5].id = -1; effects[5].u.rumble.strong_magnitude = 0; effects[5].u.rumble.weak_magnitude = 0xc000; effects[5].replay.length = 5000; effects[5].replay.delay = 0; printf("Uploading effect #5 (Weak rumble, with light motor) ... "); fflush(stdout); if (ioctl(fd, EVIOCSFF, &effects[5]) == -1) { perror("Error"); } else { printf("OK (id %d)\n", effects[5].id); } /* Ask user what effects to play */ do { printf("Enter effect number, -1 to exit\n"); i = -1; if (scanf("%d", &i) == EOF) { printf("Read error\n"); } else if (i >= 0 && i < N_EFFECTS) { memset(&play,0,sizeof(play)); play.type = EV_FF; play.code = effects[i].id; play.value = 1; if (write(fd, (const void*) &play, sizeof(play)) == -1) { perror("Play effect"); exit(1); } printf("Now Playing: %s\n", effect_names[i]); } else if (i == -2) { /* Crash test */ int i = *((int *)0); printf("Crash test: %d\n", i); } else if (i != -1) { printf("No such effect\n"); } } while (i>=0); /* Stop the effects */ printf("Stopping effects\n"); for (i=0; i<N_EFFECTS; ++i) { memset(&stop,0,sizeof(stop)); stop.type = EV_FF; stop.code = effects[i].id; stop.value = 0; if (write(fd, (const void*) &stop, sizeof(stop)) == -1) { perror(""); exit(1); } } exit(0); }
int CVICALLBACK RobotCommand (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_LEFT_CLICK: if(CheckAuth(OP_ROBOT) == 0) return 0; if (!ButtonConfirm (panel,control)) return 0; switch(control) { int stat; case PANEL_RB_CMD_PUT: if(testBit(sys->rtk[curRid].hsFill,WB) > 0) { MessagePopup("操作條件不滿足","桶槽內已經有料,不可置料!"); break; } if(testBit(sys->rb[curRobotId].hsFill,WB) == 0) { MessagePopup("操作條件不滿足","夾爪上無料,不可置料!"); break; } setRobotCommand(&sys->rb[curRobotId],curRid,PUT_COMMAND); ActionLog(RB_PUT_ACT_EVENT,curRobotId,curRid,0,0,0); break; case PANEL_RB_CMD_GET: if(testBit(sys->rtk[curRid].hsFill,WB) == 0) { MessagePopup("操作條件不滿足","桶槽內無料,不可取料!"); break; } if(testBit(sys->rb[curRobotId].hsFill,WB) > 0) { MessagePopup("操作條件不滿足","夾爪上已經有料,不可取料!"); break; } setRobotCommand(&sys->rb[curRobotId],curRid,GET_COMMAND); ActionLog(RB_GET_ACT_EVENT,curRobotId,curRid,0,0,0); break; case PANEL_RB_CMD_HOME: setRobotCommand(&sys->rb[curRobotId],curRid,HOME_COMMAND); ActionLog(RB_HOME_ACT_EVENT,curRobotId,0,0,0,0); break; case PANEL_RB_CMD_MOVE: setRobotCommand(&sys->rb[curRobotId],curRid,MOVE_COMMAND); ActionLog(RB_MOVE_ACT_EVENT,curRobotId,curRid,0,0,0); break; case PANEL_RB_CMD_CLEAN: setRobotCommand(&sys->rb[curRobotId],curRid,BLOW_COMMAND); ActionLog(RB_CLEAN_ACT_EVENT,curRobotId,0,0,0,0); break; case PANEL_RB_CHUCK_OFF: setBit(sys->rb[curRobotId].hsChuck); ActionLog(RB_CHUCK_ACT_EVENT,curRobotId,1,0,0,0); break; case PANEL_RB_CHUCK_ON: resetBit(sys->rb[curRobotId].hsChuck); ActionLog(RB_CHUCK_ACT_EVENT,curRobotId,0,0,0,0); break; case PANEL_RB_TEACH_OFF: setBit(sys->rb[curRobotId].hsTeach); ActionLog(RB_TEACH_ACT_EVENT,curRobotId,1,0,0,0); break; case PANEL_RB_TEACH_ON: resetBit(sys->rb[curRobotId].hsTeach); ActionLog(RB_TEACH_ACT_EVENT,curRobotId,0,0,0,0); break; case PANEL_RB_FILL_OFF: setBit(sys->rb[curRobotId].hsFill); ActionLog(RB_CAR_ACT_EVENT,curRobotId,1,0,0,0); break; case PANEL_RB_FILL_ON: resetBit(sys->rb[curRobotId].hsFill); ActionLog(RB_CAR_ACT_EVENT,curRobotId,0,0,0,0); break; } break; } return 0; }
int CVICALLBACK Command (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { if(event != EVENT_LEFT_CLICK) return 0; if(CheckAuth(OP_TANK) == 0) return 0; if (!ButtonConfirm (panel,control)) return 0; switch (control) { case PANEL_TANK_AMAKE_OFF: if(testBit(sys->tk[curTankId].hsMakeEnd,RB) > 0) { MessagePopup("¾Þ§@±ø¥ó¤£º¡¨¬","½Ð¥ý±Æ©ñ¡A¤~¥i°õ¦æ°t¼Ñ¡I"); break; } if(g_setupMake == 0) { resetBit(sys->tk[curTankId].hsMakeStop); GetCtrlVal(panel,PANEL_TANK_AC1_MAKE,&sys->tk[curTankId].MakeCH1); GetCtrlVal(panel,PANEL_TANK_AC2_MAKE,&sys->tk[curTankId].MakeCH2); GetCtrlVal(panel,PANEL_TANK_AC3_MAKE,&sys->tk[curTankId].MakeCH3); GetCtrlVal(panel,PANEL_TANK_AC4_MAKE,&sys->tk[curTankId].MakeCH4); g_makeBit = sys->tk[curTankId].hsMake; g_setupMake = 1; ActionLog(TANK_MAKE_ACT_EVENT,curTankId,1,sys->tk[curTankId].MakeCH1,sys->tk[curTankId].MakeCH2,sys->tk[curTankId].MakeCH3); } break; case PANEL_TANK_AMAKE_ON: setBit(sys->tk[curTankId].hsMakeStop); ActionLog(TANK_MAKE_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_MMAKE_OFF: if(testBit(sys->tk[curTankId].hsMakeEnd,RB) == 0) { MessagePopup("¾Þ§@±ø¥ó¤£º¡¨¬","°t¼Ñ¥¼§¹¦¨¡A¤£¥i²K¥[¡I"); break; } if(g_setupMMake == 0) { resetBit(sys->tk[curTankId].hsMMakeStop); GetCtrlVal(panel,PANEL_TANK_AC1_MAKE,&sys->tk[curTankId].MMakeCH1); GetCtrlVal(panel,PANEL_TANK_AC2_MAKE,&sys->tk[curTankId].MMakeCH2); GetCtrlVal(panel,PANEL_TANK_AC3_MAKE,&sys->tk[curTankId].MMakeCH3); GetCtrlVal(panel,PANEL_TANK_AC4_MAKE,&sys->tk[curTankId].MMakeCH4); g_mmakeBit = sys->tk[curTankId].hsMMake; g_setupMMake = 1; ActionLog(TANK_MMAKE_ACT_EVENT,curTankId,1,sys->tk[curTankId].MMakeCH1,sys->tk[curTankId].MMakeCH2,sys->tk[curTankId].MMakeCH3); } break; case PANEL_TANK_MMAKE_ON: setBit(sys->tk[curTankId].hsMMakeStop); ActionLog(TANK_MAKE_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_AC1_DOS_OFF: setBit(sys->tk[curTankId].hsAC1Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,1,1,0,0); break; case PANEL_TANK_AC1_DOS_ON: resetBit(sys->tk[curTankId].hsAC1Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_AC2_DOS_OFF: setBit(sys->tk[curTankId].hsAC2Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,2,1,0,0); break; case PANEL_TANK_AC2_DOS_ON: resetBit(sys->tk[curTankId].hsAC2Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,2,0,0,0); break; case PANEL_TANK_AC3_DOS_OFF: setBit(sys->tk[curTankId].hsAC3Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,3,1,0,0); break; case PANEL_TANK_AC3_DOS_ON: resetBit(sys->tk[curTankId].hsAC3Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,3,0,0,0); break; case PANEL_TANK_AC4_DOS_OFF: setBit(sys->tk[curTankId].hsAC4Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,4,1,0,0); break; case PANEL_TANK_AC4_DOS_ON: resetBit(sys->tk[curTankId].hsAC4Dos); ActionLog(TANK_DOS_ACT_EVENT,curTankId,4,0,0,0); break; case PANEL_TANK_WASH_OFF: setBit(sys->tk[curTankId].hsWash); ActionLog(TANK_WASH_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_WASH_ON: resetBit(sys->tk[curTankId].hsWash); ActionLog(TANK_WASH_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_DOWN_OFF: /*if(testBit(sys->tk[curTankId].hsMakeEnd,RB) == 0) { MessagePopup("¾Þ§@±ø¥ó¤£º¡¨¬","°t¼Ñ¥¼§¹¦¨¡A¤£¥i±Æ©ñ¡I¡I"); break; } */ setBit(sys->tk[curTankId].hsDown); ActionLog(TANK_DOWN_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_DOWN_ON: resetBit(sys->tk[curTankId].hsDown); ActionLog(TANK_DOWN_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_PUMP_OFF: resetBit(sys->tk[curTankId].hsPump); ActionLog(TANK_PUMP_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_PUMP_ON: ActionLog(TANK_PUMP_ACT_EVENT,curTankId,0,0,0,0); setBit(sys->tk[curTankId].hsPump); break; case PANEL_TANK_PUMPIN_OFF: resetBit(sys->tk[curTankId].hsPumpIn); ActionLog(TANK_PUMP_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_PUMPIN_ON: ActionLog(TANK_PUMP_ACT_EVENT,curTankId,0,0,0,0); setBit(sys->tk[curTankId].hsPumpIn); break; case PANEL_TANK_HEAT_OFF: resetBit(sys->tk[curTankId].hsHeat); ActionLog(TANK_HEAT_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_HEAT_ON: setBit(sys->tk[curTankId].hsHeat); ActionLog(TANK_HEAT_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_ADD_WATER_OFF: setBit(sys->tk[curTankId].hsAddWater); ActionLog(TANK_ADD_WATER_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_ADD_WATER_ON: resetBit(sys->tk[curTankId].hsAddWater); ActionLog(TANK_ADD_WATER_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_SHUT_OFF: setBit(sys->tk[curTankId].hsShutOpen); resetBit(sys->tk[curTankId].hsShutClose); ActionLog(TANK_SHUT_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_SHUT_ON: setBit(sys->tk[curTankId].hsShutClose); resetBit(sys->tk[curTankId].hsShutOpen); ActionLog(TANK_SHUT_ACT_EVENT,curTankId,0,0,0,0); break; /* case PANEL_TANK_BUBB_OFF: setBit(sys->tk[curTankId].hsBubble); ActionLog(TANK_BUBB_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_BUBB_ON: resetBit(sys->tk[curTankId].hsBubble); ActionLog(TANK_BUBB_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_DRAIN_OFF: setBit(sys->tk[curTankId].hsDrain); ActionLog(TANK_DRAIN_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_DRAIN_ON: resetBit(sys->tk[curTankId].hsDrain); ActionLog(TANK_DRAIN_ACT_EVENT,curTankId,0,0,0,0); break; */ case PANEL_TANK_FILL_OFF: //ChangFillStatus(sys->rtk[curRTankId1].hsFill,1); setBit(sys->rtk[curRTankId1].hsFill); GetCurrentDateTime(&sys->rtk[curRTankId1].car.iPrcTM[curTankId]); ActionLog(TANK_CAR_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_FILL_ON: resetBit(sys->rtk[curRTankId1].hsFill); //ChangFillStatus(sys->rtk[curRTankId1].hsFill,0); ActionLog(TANK_CAR_ACT_EVENT,curTankId,0,0,0,0); break; case PANEL_TANK_FILL2_OFF: setBit(sys->rtk[curRTankId2].hsFill); GetCurrentDateTime(&sys->rtk[curRTankId2].car.iPrcTM[curTankId]); //ChangFillStatus(sys->rtk[curRTankId2].hsFill,1); ActionLog(TANK_CAR_ACT_EVENT,curTankId,1,0,0,0); break; case PANEL_TANK_FILL2_ON: resetBit(sys->rtk[curRTankId2].hsFill); //ChangFillStatus(sys->rtk[curRTankId2].hsFill,0); ActionLog(TANK_CAR_ACT_EVENT,curTankId,0,0,0,0); break; } return 0; }
JoyEvdev::JoyEvdev(int fd, bool ds3, const wchar_t *id) : Device(LNX_JOY, OTHER, id, id) , m_fd(fd) { // XXX LNX_JOY => DS3 or ??? m_abs.clear(); m_btn.clear(); m_rel.clear(); int last = 0; uint8_t abs_bitmap[nUcharsForNBits(ABS_CNT)] = {0}; uint8_t btn_bitmap[nUcharsForNBits(KEY_CNT)] = {0}; uint8_t rel_bitmap[nUcharsForNBits(REL_CNT)] = {0}; // Add buttons if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(btn_bitmap)), btn_bitmap) >= 0) { for (int bit = BTN_MISC; bit < KEY_CNT; bit++) { if (testBit(bit, btn_bitmap)) { AddPhysicalControl(PSHBTN, last, 0); m_btn.push_back(bit); last++; } } } // Add Absolute axis if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmap)), abs_bitmap) >= 0) { for (int bit = 0; bit < ABS_CNT; bit++) { ControlType type = ABSAXIS; // FIXME DS3 if (testBit(bit, abs_bitmap)) { input_absinfo info; if (ioctl(m_fd, EVIOCGABS(bit), &info) < 0) { fprintf(stderr, "Invalid IOCTL EVIOCGID\n"); continue; } AddPhysicalControl(ABSAXIS, last, 0); last++; if (std::abs(info.value - 127) < 2) { fprintf(stderr, "HALF Axis info %d=>%d, current %d, flat %d, resolution %d\n", info.minimum, info.maximum, info.value, info.flat, info.resolution); // Half axis must be split into 2 parts... AddPhysicalControl(ABSAXIS, last, 0); last++; m_abs.push_back(abs_info(bit, info.minimum, info.value, type)); m_abs.push_back(abs_info(bit, info.value, info.maximum, type)); } else { fprintf(stderr, "FULL Axis info %d=>%d, current %d, flat %d, resolution %d\n", info.minimum, info.maximum, info.value, info.flat, info.resolution); m_abs.push_back(abs_info(bit, info.minimum, info.maximum, type)); } } } } // Add relative axis if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmap)), rel_bitmap) >= 0) { for (int bit = 0; bit < REL_CNT; bit++) { if (testBit(bit, rel_bitmap)) { AddPhysicalControl(RELAXIS, last, last); m_rel.push_back(bit); last++; fprintf(stderr, "Add relative nb %d\n", bit); } } } fprintf(stderr, "New device created. Found axe:%zu, buttons:%zu, m_rel:%zu\n\n", m_abs.size(), m_btn.size(), m_rel.size()); }
void Decoder::read() { auto& s = top(); size_t totalVarIntCount = 0; size_t optionalFieldBits = 0; if (s.state == IN_STRUCT) { size_t nbits = s.dataType->optionalFields.size(); optionalFieldBits = nbits; size_t nbytes = byteCount(nbits); cursor_.gather(nbytes); auto optionalSet = ensure(nbytes).first; // Now we know which optionals are set // Assign by tag. size_t optionalIdx = 0; for (auto& p : s.dataType->fields) { auto tag = p.first; if (!p.second.isRequired && !testBit(optionalSet, optionalIdx++)) { continue; } TypeInfo tinfo(schema_, p.second.type); s.addType(tinfo, p.second, tag, 1); } // Structs encode the bitfield first, so we can use only one bitfield // for both optional fields and bools and strict enums readBoolsAndStrictEnums(nbits); } else { if (s.state == IN_MAP_VALUE) { s.addType(s.list.mapKeyType, StructField(), 0, s.list.remaining); } s.addType(s.list.valueType, StructField(), 0, s.list.remaining); ++totalVarIntCount; // element count } s.ints.values.reserve(s.ints.count); s.int64s.values.reserve(s.int64s.count); s.bytes.values.reserve(s.bytes.count); // Waste some memory. Oh well, the code is simpler :) if (s.bools.count + s.totalStrictEnumBits) { s.bools.values.reserve(byteCount(optionalFieldBits + s.bools.count + s.totalStrictEnumBits)); } s.strictEnums.values.reserve(s.strictEnums.count); s.vars.values.reserve(s.vars.count); s.internedStrings.values.reserve(s.internedStrings.count); // Read ints size_t varIntCount = s.ints.count; size_t varInt64Count = s.int64s.count; size_t varLengthCount = s.vars.count; size_t internCount = s.internedStrings.count; if (s.state == IN_STRUCT) { varIntCount -= (s.str.fixedInt16Tags.size() + s.str.fixedInt32Tags.size()); varInt64Count -= s.str.fixedInt64Tags.size(); } totalVarIntCount += varIntCount + 2 * varInt64Count + varLengthCount + internCount; if (totalVarIntCount) { size_t maxSize = folly::GroupVarint32::maxSize(totalVarIntCount); cursor_.gatherAtMost(maxSize); folly::StringPiece data = SP(cursor_.peek()); folly::GroupVarint32Decoder decoder(data, totalVarIntCount); if (s.state != IN_STRUCT) { uint32_t n; if (!decoder.next(&n)) { throw TProtocolException("too few ints on the wire"); } DCHECK_EQ(n, s.list.remaining); } for (size_t i = 0; i < varIntCount; i++) { uint32_t val; if (!decoder.next(&val)) { throw TProtocolException("too few ints on the wire: int"); } s.ints.values.push_back(val); } for (size_t i = 0; i < varInt64Count; i++) { uint32_t hi; uint32_t lo; if (!decoder.next(&hi) || !decoder.next(&lo)) { throw TProtocolException("too few ints on the wire: int64"); } uint64_t val = ((uint64_t)hi << 32) | lo; s.int64s.values.push_back(val); } for (size_t i = 0; i < varLengthCount; i++) { uint32_t val; if (!decoder.next(&val)) { throw TProtocolException("too few ints on the wire: var"); } s.vars.values.push_back(val); } for (size_t i = 0; i < internCount; i++) { uint32_t val; if (!decoder.next(&val)) { throw TProtocolException("too few ints on the wire: intern"); } auto sp = internTable_->get(val); s.internedStrings.values.push_back(sp); if (s.state == IN_STRUCT) { // fixed size s.str.internedStringTags[i].second.length = sp.size(); } } uint32_t tmp; CHECK(!decoder.next(&tmp)); // or else we have an internal error size_t bytesUsed = data.size() - decoder.rest().size(); cursor_.skip(bytesUsed); s.bytesRead += bytesUsed; } // Read bools and strict enums, already done for structs if (s.state != IN_STRUCT) { readBoolsAndStrictEnums(0); } // Read bytes if (s.bytes.count) { s.bytes.values.resize(s.bytes.count); cursor_.pull(&s.bytes.values.front(), s.bytes.count); s.bytesRead += s.bytes.count; } // Read fixed-size fields, currently only for structs if (s.state == IN_STRUCT) { if (!s.str.fixedInt16Tags.empty()) { for (auto tag : s.str.fixedInt16Tags) { s.ints.values.push_back(cursor_.readBE<uint16_t>()); s.str.intTags.emplace_back(tag); } s.bytesRead += s.str.fixedInt16Tags.size() * sizeof(uint16_t); } if (!s.str.fixedInt32Tags.empty()) { for (auto tag : s.str.fixedInt32Tags) { s.ints.values.push_back(cursor_.readBE<uint32_t>()); s.str.intTags.emplace_back(tag); } s.bytesRead += s.str.fixedInt32Tags.size() * sizeof(uint32_t); } if (!s.str.fixedInt64Tags.empty()) { for (auto tag : s.str.fixedInt64Tags) { s.int64s.values.push_back(cursor_.readBE<uint64_t>()); s.str.int64Tags.push_back(tag); } s.bytesRead += s.str.fixedInt64Tags.size() * sizeof(uint64_t); } } }