示例#1
0
uint16_t AnimationReader::readUnsignedInt16(void) {

    uint16_t result = readUnsignedByte();
    result |= readUnsignedByte() << 8;

    return result;
}
int extractCommandStatus(storage *s, unsigned char commandId, char * description)
{
	 int success=0;

         if(s == NULL) {
           //LOG_E(OMG, " client_traci_OMG::extractCommandStatus():  Tracker is NULL \n");
           //printf(" client_traci_OMG::extractCommandStatus():  Tracker is NULL \n");
           return success=0;
	}

	// validate the the message response from SUMO
	int storageLength_ = storageLength(s);

	// tracker currently points to the begining of the recieved data in the linked list        
        tracker = s;
//         storage *freeTracker = tracker;   // save it for calling free

	int commandLength = readUnsignedByte();
        
	// CommandID needs to fit
        int rcvdCommandId = readUnsignedByte();
        if (rcvdCommandId == (int)commandId)
	{
                //printf("%d",rcvdCommandId);
                //LOG_E(OMG, " Server answered to command\n");
		//printf(" Server answered to command\n");
	}
	// Get result and description
	unsigned char result = readUnsignedByte();
	if (result != RTYPE_OK)
	{       
                
                printf(" Server returned error\n");
		return success=0;
		
	}
	
	if (result == RTYPE_OK) {
		// printf(" Server returned success\n");
		success=1;
        }

       	description = readString();
	// print description if needed 

	
        //free actual message content
	//depends on the message which is handled

        /*   if (commandId != CMD_GET_VEHICLE_VARIABLE)
        freeStorage(freeTracker);*/

        UNUSED_VARIABLE(commandLength);
        UNUSED_VARIABLE(storageLength_);

	return success;
}
示例#3
0
uint32_t AnimationReader::readUnsignedInt32(void) {

    uint32_t result = readUnsignedByte();
    result |= readUnsignedByte() << 8;
    result |= readUnsignedByte() << 16;
    result |= readUnsignedByte() << 24;
    
    return result;
}
示例#4
0
bool WinHelpPhrIndexFile::getNextBitIntAlligned(QFile &file,
    IntAllignedCursor &cur)
{
    if (cur.currentBitIndex == 0)
    {
        cur.currentDwordByte0 = readUnsignedByte(file);
        cur.currentDwordByte1 = readUnsignedByte(file);
        cur.currentDwordByte2 = readUnsignedByte(file);
        cur.currentDwordByte3 = readUnsignedByte(file);
    }
    bool result = false;
    quint8 mask = 0x01 << (cur.currentBitIndex % 8);
    switch (cur.currentBitIndex / 8)
    {
    case 0:
        if ((cur.currentDwordByte0 & mask) != 0)
        {
            result = true;
        }
        break;

    case 1:
        if ((cur.currentDwordByte1 & mask) != 0)
        {
            result = true;
        }
        break;

    case 2:
        if ((cur.currentDwordByte2 & mask) != 0)
        {
            result = true;
        }
        break;

    case 3:
        if ((cur.currentDwordByte3 & mask) != 0)
        {
            result = true;
        }
        break;

    default:
        throw std::runtime_error(
            "Unable to unpack bitcompressed phrases offset");
    }
    cur.currentBitIndex++;
    if (cur.currentBitIndex > 31)
    {
        cur.currentBitIndex = 0;
    }
    return result;
}
void commandGetVehicleVariable(char *vehID, int varID)// malloc for vehID and varID depends on speed or position
{	
	reset();
    	int domID = CMD_GET_VEHICLE_VARIABLE;//0xa4 specific for get vehicle variable command
	
   	// command length
    	writeUnsignedByte(1 + 1 + 1 + 4 + (int)strlen(vehID));
    	// command id
    	writeUnsignedByte(CMD_GET_VEHICLE_VARIABLE);
    	// variable id
    	writeUnsignedByte(varID);
    	// object id
    	writeString(vehID);

    	// send request message
    	sendExact(storageLength(storageStart));
    	// receive answer message
        //receiveExact();
    	if (extractCommandStatus(receiveExact(), CMD_GET_VEHICLE_VARIABLE, description)){//<---RESPONSE_GET_VEHICLE_VARIABLE
	
    	// validate result state
        if(tracker == NULL) {
            // LOG_E(OMG, " client_traci_OMG::commandGetVehicleVariable():  Tracker is NULL \n");
            //printf(" client_traci_OMG::commandGetVehicleVariable():  Tracker is NULL \n");
            return;
	}

        int length = readUnsignedByte();
        if(length ==0)
	  length = readInt();
       	int cmdId =readUnsignedByte();

        if (cmdId != (CMD_GET_VEHICLE_VARIABLE+0x10)) {
		//LOG_E(OMG, " Wrong response recieved\n");
                 //printf(" Wrong response recieved\n");
            	return;
        }
        int VariableID = readUnsignedByte();
	char* rs = readString();

        int valueDataType = readUnsignedByte();
        UNUSED_VARIABLE(VariableID);
        UNUSED_VARIABLE(rs);
        UNUSED_VARIABLE(valueDataType);
        UNUSED_VARIABLE(domID);
    }
}
示例#6
0
quint16 readCompressedUnsignedWord(QIODevice &device)
{
    qint64 pos = device.pos();
    quint8 lowByte = readUnsignedByte(device);
    if((lowByte & 1) != 0)
    {
        seekFile(device, pos);
        return readUnsignedWord(device) / 2;
    }
    else
    {
        return static_cast<quint16>(lowByte) / 2;
    }
}
MetaCreatepatternbrushRecord::MetaCreatepatternbrushRecord(QIODevice &device) : MetafileRecord(device), patternBits()
{
    this->type = readUnsignedWord(device);
    this->width = readUnsignedWord(device);
    this->height = readUnsignedWord(device);
    this->widthBytes = readUnsignedWord(device);
    this->planes = readUnsignedByte(device);
    if(this->planes != 1)
    {
        throw std::runtime_error("Invalid patternBitsLength value");
    }
    this->bitsPerPixel = readUnsignedByte(device);
    seekDevice(device, Q_INT64_C(22));
    quint16 wb = (this->width * static_cast<quint16>(this->bitsPerPixel) + 15)/16;
    quint16 realWidthBytes = wb * 2;
    if(realWidthBytes != this->widthBytes)
    {
        throw std::runtime_error("Invalid widthBytes value");
    }
    this->patternBitsLength = this->widthBytes * this->height;
    QScopedArrayPointer<quint8>(new quint8[this->patternBitsLength]).swap(this->patternBits);
    fillBuffer(device, static_cast<qint64>(this->patternBitsLength), reinterpret_cast<void *>(this->patternBits.data()), static_cast<size_t>(this->patternBitsLength));
}
示例#8
0
qint32 readCompressedSignedDWord(QIODevice &device)
{
    qint64 pos = device.pos();
    quint8 lowByte = readUnsignedByte(device);
    if((lowByte & 1) != 0)
    {
        seekFile(device, pos);
        return static_cast<qint32>((static_cast<qint64>(readUnsignedDWord(
                        device)) - Q_INT64_C(0x80000000)) / Q_INT64_C(2));
    }
    else
    {
        seekFile(device, pos);
        return static_cast<qint32>((static_cast<qint64>(readUnsignedWord(device))
                - Q_INT64_C(0x8000)) / Q_INT64_C(2));
    }
}
示例#9
0
bool WinHelpPhrIndexFile::getNextBitByteAlligned(QFile &file,
    ByteAllignedCursor &cur)
{
    if (cur.currentBitIndex == 0)
    {
        cur.currentByte = readUnsignedByte(file);
    }
    bool result = false;
    quint8 mask = 0x01 << cur.currentBitIndex;
    if ((cur.currentByte & mask) != 0)
    {
        result = true;
    }
    cur.currentBitIndex++;
    if (cur.currentBitIndex > 7)
    {
        cur.currentBitIndex = 0;
    }
    return result;
}
void processSubscriptions() {
   int noSubscriptions = readInt();

   string_list* tmp_departed = departed;
   string_list* tmp_arrived = arrived;
   int s;
   for (s = 0; s<noSubscriptions; ++s) {
    
      int respStart = readInt();
      int respLength = readUnsignedByte();
      if (respLength == 0)
         respLength = readInt();

     
      int cmdId = readUnsignedByte();
      if (cmdId<0xe0||cmdId>0xef) {  // only responses to subscription to supported types (vehicles, TLC, polygones...) are accepted
         //LOG_W(OMG, " Invalide Subscription response: %d\n",cmdId);
         //printf(" Invalide Subscription response: %d\n",cmdId);
         return;
      }
      char *objID = readString();
      int varNo = readUnsignedByte();

      UNUSED_VARIABLE(objID);
      UNUSED_VARIABLE(respStart);

      int i;
      for (i=0; i<varNo; ++i) {
          int varID = readUnsignedByte();
          
          bool ok = readUnsignedByte()==RTYPE_OK;
          int valueDataType = readUnsignedByte();
          UNUSED_VARIABLE(valueDataType);
          if (ok&&cmdId==CMD_SUBSCRIBE_SIM_VARIABLE+0x10&&varID==VAR_DEPARTED_VEHICLES_IDS) {
               tmp_departed = readStringList(tmp_departed);
               //printf(" OMG Got departed cars\n");
               continue;
           }
           if (ok&&cmdId==CMD_SUBSCRIBE_SIM_VARIABLE+0x10&&varID==VAR_ARRIVED_VEHICLES_IDS) {
               tmp_arrived = readStringList(tmp_arrived);
  		//printf(" OMG Got arrived cars\n");
               continue;
           }
       }
    }
}
示例#11
0
NewFontDescriptor::NewFontDescriptor(QFile &file,
    qint64 off) : FontDescriptor(NEW_FONT_DESCRIPTOR)
{
    PRINT_DBG("Reading New font descriptor at %lld", off);
    seekFile(file, off);
    quint8 unknownByte1 = readUnsignedByte(file);
    PRINT_DBG("        Unknown byte 1: %d", unknownByte1);
    this->facenameIndex = readUnsignedWord(file);
    PRINT_DBG("        Facename index: %d", this->facenameIndex);
    this->fgColor = readRGBBytes(file);
    PRINT_DBG("        Fg Red: %d", qRed(this->fgColor));
    PRINT_DBG("        Fg Green: %d", qGreen(this->fgColor));
    PRINT_DBG("        Fg Blue: %d", qBlue(this->fgColor));
    this->bgColor = readRGBBytes(file);
    PRINT_DBG("        Bg Red: %d", qRed(this->bgColor));
    PRINT_DBG("        Bg Green: %d", qGreen(this->bgColor));
    PRINT_DBG("        Bg Blue: %d", qBlue(this->bgColor));
    quint8 unknownBytes2[5] = {
        0, 0, 0, 0, 0
    };
    fillBuffer(file, Q_INT64_C(
            5), reinterpret_cast<void *>(&unknownBytes2), static_cast<size_t>(5));
    PRINT_DBG("        Unknown byte 2-1: %d", unknownBytes2[0]);
    PRINT_DBG("        Unknown byte 2-2: %d", unknownBytes2[1]);
    PRINT_DBG("        Unknown byte 2-3: %d", unknownBytes2[2]);
    PRINT_DBG("        Unknown byte 2-4: %d", unknownBytes2[3]);
    PRINT_DBG("        Unknown byte 2-5: %d", unknownBytes2[4]);
    this->height = readSignedDWord(file);
    PRINT_DBG("        Height: %d", this->height);
    this->width = readSignedDWord(file);
    PRINT_DBG("        Width: %d", this->width);
    this->escapement = readSignedDWord(file);
    PRINT_DBG("        Escapement: %d", this->escapement);
    this->orientation = readSignedDWord(file);
    PRINT_DBG("        Orientation: %d", this->orientation);
    this->weight = readSignedDWord(file);
    PRINT_DBG("        Weight: %d", this->weight);
    quint8 italicByte = readUnsignedByte(file);
    this->italic = false;
    if(italicByte != 0)
    {
        this->italic = true;
        PRINT_DBG("        Italic font");
    }
    quint8 underlineByte = readUnsignedByte(file);
    this->underline = false;
    if(underlineByte != 0)
    {
        this->underline = true;
        PRINT_DBG("        Underline font");
    }
    quint8 strikeoutByte = readUnsignedByte(file);
    this->strikeOut = false;
    if(strikeoutByte != 0)
    {
        this->strikeOut = true;
        PRINT_DBG("        Strike out font");
    }
    this->charset = readUnsignedByte(file);
    PRINT_DBG("        Charset: %d", this->charset);
    this->outPrecision = readUnsignedByte(file);
    PRINT_DBG("        Out precision: %d", this->outPrecision);
    this->clipPrecision = readUnsignedByte(file);
    PRINT_DBG("        Clip precision: %d", this->clipPrecision);
    this->quality = readUnsignedByte(file);
    PRINT_DBG("        Quality: %d", this->quality);
    quint8 pitchAndFamily = readUnsignedByte(file);
    this->pitch = pitchAndFamily & 0x03;
    PRINT_DBG("        Pitch: %d", this->pitch);
    this->family = (((pitchAndFamily & 0xF0) >> 4) & 0x0F);
    PRINT_DBG("        Family: %d", this->family);
    PRINT_DBG("New font descriptor loaded successfully");
}
示例#12
0
WindowHpjRecord::WindowHpjRecord(QFile &file, qint64 off, QTextCodec *codec)
{
    PRINT_DBG("Reading WindowHpj record at %lld", off);
    seekFile(file, off);
    SystemRecordHeader hdr(file, off);
    if (hdr.getRecordSize() < Q_INT64_C(90))
    {
        qDebug() << "WindowHpj record size is too small: "
                 << hdr.getRecordSize();
    }
    quint8 flagsLIn = readUnsignedByte(file);
    PRINT_DBG("        Flags low byte: %d", flagsLIn);
    this->typeIsValid = false;
    if ((flagsLIn & 0x1) != 0)
    {
        this->typeIsValid = true;
        PRINT_DBG("        Window type field is valid");
    }
    ;
    this->nameIsValid = false;
    if ((flagsLIn & 0x2) != 0)
    {
        this->nameIsValid = true;
        PRINT_DBG("        Window name field is valid");
    }
    ;
    this->captionIsValid = false;
    if ((flagsLIn & 0x4) != 0)
    {
        this->captionIsValid = true;
        PRINT_DBG("        Window caption field is valid");
    }
    ;
    this->xIsValid = false;
    if ((flagsLIn & 0x8) != 0)
    {
        this->xIsValid = true;
        PRINT_DBG("        X field is valid");
    }
    ;
    this->yIsValid = false;
    if ((flagsLIn & 0x10) != 0)
    {
        this->yIsValid = true;
        PRINT_DBG("        Y field is valid");
    }
    ;
    this->widthIsValid = false;
    if ((flagsLIn & 0x20) != 0)
    {
        this->widthIsValid = true;
        PRINT_DBG("        Width field is valid");
    }
    ;
    this->heightIsValid = false;
    if ((flagsLIn & 0x40) != 0)
    {
        this->heightIsValid = true;
        PRINT_DBG("        Height type field is valid");
    }
    ;
    this->maximizeWindow = false;
    if ((flagsLIn & 0x80) != 0)
    {
        this->maximizeWindow = true;
        PRINT_DBG("        Maximize field is valid");
    }
    ;
    quint8 flagsHIn = readUnsignedByte(file);
    PRINT_DBG("        Flags high byte: %d", flagsHIn);
    this->rgbIsValid = false;
    if ((flagsHIn & 0x1) != 0)
    {
        this->rgbIsValid = true;
        PRINT_DBG("        RGB field is valid");
    }
    ;
    this->rgbNsrIsValid = false;
    if ((flagsHIn & 0x2) != 0)
    {
        this->rgbNsrIsValid = true;
        PRINT_DBG("        RGB nsr field is valid");
    }
    ;
    this->windowsAlwaysOnTop = false;
    if ((flagsHIn & 0x4) != 0)
    {
        this->windowsAlwaysOnTop = true;
        PRINT_DBG("        Window always on top flag is set");
    }
    ;
    this->autoSizeHeight = false;
    if ((flagsHIn & 0x8) != 0)
    {
        this->autoSizeHeight = true;
        PRINT_DBG("        Auto size height flag is set");
    }
    ;
    this->windowType = readFixedLengthString(file, 10, codec);
    PRINT_DBG("        Window type: %s", this->windowType.toLocal8Bit().data());
    this->windowName = readFixedLengthString(file, 9, codec);
    PRINT_DBG("        Window name: %s", this->windowName.toLocal8Bit().data());
    this->windowCaption = readFixedLengthString(file, 51, codec);
    PRINT_DBG("        Window caption: %s",
        this->windowCaption.toLocal8Bit().data());
    this->x = readUnsignedWord(file);
    PRINT_DBG("        X: %d", this->x);
    this->y = readUnsignedWord(file);
    PRINT_DBG("        Y: %d", this->y);
    this->width = readUnsignedWord(file);
    PRINT_DBG("        Width: %d", this->width);
    this->height = readUnsignedWord(file);
    PRINT_DBG("        Height: %d", this->height);
    this->maximize = readUnsignedWord(file);
    PRINT_DBG("        Maximize: %d", this->maximize);
    this->rgbColor = readRGBDword(file);
    PRINT_DBG("        Red: %d", qRed(this->rgbColor));
    PRINT_DBG("        Green: %d", qGreen(this->rgbColor));
    PRINT_DBG("        Blue: %d", qBlue(this->rgbColor));
    this->rgbNsrColor = readRGBDword(file);
    PRINT_DBG("        Red nsr: %d", qRed(this->rgbNsrColor));
    PRINT_DBG("        Green nsr: %d", qGreen(this->rgbNsrColor));
    PRINT_DBG("        Blue nsr: %d", qBlue(this->rgbNsrColor));
    PRINT_DBG("WindowHpj record loaded successfully");
}
示例#13
0
WinHelpPhraseFile::WinHelpPhraseFile(QFile &file, qint64 off,
    QTextCodec *codec, bool compressed, bool mvbHint) :
    phrases(), phrasesRaw()
{
    PRINT_DBG("Loading WinHelp phrase file at %lld", off);
    if (codec == NULL)
    {
        throw std::runtime_error("Codec is NULL");
    }
    seekFile(file, off);
    InternalDirectoryFileHeader hdr(file, off);
    if (compressed)
    {
        if (mvbHint)
        {
            seekFile(file, off + InternalDirectoryFileHeader::size);
            quint16 eightHundr = readUnsignedWord(file);
            quint16 nPhr = readUnsignedWord(file);
            quint16 oneHundr = readUnsignedWord(file);
            if ((eightHundr == 0x0800) && (oneHundr == 0x0100) && (nPhr != 0))
            {
                PRINT_DBG(
                    "Loading compressed WinHelp phrase file, MVB alternative");
                seekFile(file, off + InternalDirectoryFileHeader::size);
                quint16 eightHundred = readUnsignedWord(file);
                PRINT_DBG("        Eight hundred: %d", eightHundred);
                quint16 numPhrases = readUnsignedWord(file);
                PRINT_DBG("        Num phrases: %d", numPhrases);
                quint16 oneHundred = readUnsignedWord(file);
                PRINT_DBG("        One hundred: %d", oneHundred);
                if (oneHundred != 0x0100)
                {
                    throw std::runtime_error("Not a WinHelp phrase file");
                }
                quint32 uncompressedSize = readUnsignedDWord(file);
                PRINT_DBG("        Uncompressed size: %d", uncompressedSize);
                for (int i = 0; i < 30; i++)
                {
                    quint8 unused = readUnsignedByte(file);
                    PRINT_DBG("        Unused: %d", unused);
                }
                QScopedArrayPointer<uint> phraseOffset(
                    new uint[static_cast<size_t> (numPhrases + 1)]);
                PRINT_DBG("Reading phrase offsets at %lld", file.pos());
                for (quint16 index = 0; index < numPhrases + 1; index++)
                {
                    phraseOffset[index] = static_cast<uint> (readUnsignedWord(
                            file));
                    PRINT_DBG("        Phrase offset: %d", phraseOffset[index]);
                }
                qint64 inputLength = off + hdr.getReservedSpace() - file.pos();
                PRINT_DBG("Reading compressed phrases at %lld", file.pos());
                QScopedArrayPointer<quint8>
                uncompressedPhrases(
                    new quint8[static_cast<size_t> (uncompressedSize)]);
                unpackLZ77(file, file.pos(), inputLength,
                    uncompressedPhrases.data(),
                    static_cast<size_t> (uncompressedSize));
                size_t pointer = static_cast<size_t> (0);
                for (quint16 index = 0; index < numPhrases; index++)
                {
                    uint size = phraseOffset[index + 1] - phraseOffset[index];
                    QString phrase = readFixedLengthStringFromBuffer(
                        uncompressedPhrases.data(),
                        static_cast<size_t> (uncompressedSize),
                        pointer, size, codec);
                    this->phrases.append(phrase);
                    QScopedArrayPointer<quint8> phraseRaw(
                        new quint8[static_cast<size_t> (size)]);
                    copyBytesFromBuffer(
                        reinterpret_cast<const void *> (uncompressedPhrases.
                            data()),
                        static_cast<size_t> (uncompressedSize),
                        pointer, static_cast<size_t> (size),
                        reinterpret_cast<void *> (phraseRaw.data()),
                        static_cast<size_t> (size));
                    this->phrasesRaw.append(QByteArray(
                            reinterpret_cast<const char *> (phraseRaw.data()),
                            static_cast<int> (size)));
                    pointer += static_cast<size_t> (size);
                    PRINT_DBG("        Phrase: %s", phrase.toLocal8Bit().data());
                }
            }
            else
            {
                PRINT_DBG("Loading compressed WinHelp phrase file");
                seekFile(file, off + InternalDirectoryFileHeader::size);
                quint16 numPhrases = readUnsignedWord(file);
                PRINT_DBG("        Num phrases: %d", numPhrases);
                quint16 oneHundred = readUnsignedWord(file);
                PRINT_DBG("        One hundred: %d", oneHundred);
                if (oneHundred != 0x0100)
                {
                    throw std::runtime_error("Not a WinHelp phrase file");
                }
                quint32 uncompressedSize = readUnsignedDWord(file);
                PRINT_DBG("        Uncompressed size: %d", uncompressedSize);
                QScopedArrayPointer<uint> phraseOffset(
                    new uint[static_cast<size_t> (numPhrases + 1)]);
                PRINT_DBG("Reading phrase offsets at %lld", file.pos());
                for (quint16 index = 0; index < numPhrases + 1; index++)
                {
                    phraseOffset[index] = static_cast<uint> (readUnsignedWord(
                            file));
                    PRINT_DBG("        Phrase offset: %d", phraseOffset[index]);
                }
                PRINT_DBG("Reading compressed phrases at %lld", file.pos());
                qint64 inputLength = off + hdr.getReservedSpace() - file.pos();
                QScopedArrayPointer<quint8>
                uncompressedPhrases(
                    new quint8[static_cast<size_t> (uncompressedSize)]);
                unpackLZ77(file, file.pos(), inputLength,
                    uncompressedPhrases.data(),
                    static_cast<size_t> (uncompressedSize));
                size_t pointer = static_cast<size_t> (0);
                for (quint16 index = 0; index < numPhrases; index++)
                {
                    uint size = phraseOffset[index + 1] - phraseOffset[index];
                    QString phrase = readFixedLengthStringFromBuffer(
                        uncompressedPhrases.data(),
                        static_cast<size_t> (uncompressedSize),
                        pointer, size, codec);
                    this->phrases.append(phrase);
                    QScopedArrayPointer<quint8> phraseRaw(
                        new quint8[static_cast<size_t> (size)]);
                    copyBytesFromBuffer(
                        reinterpret_cast<const void *> (uncompressedPhrases.
                            data()),
                        static_cast<size_t> (uncompressedSize),
                        pointer, static_cast<size_t> (size),
                        reinterpret_cast<void *> (phraseRaw.data()),
                        static_cast<size_t> (size));
                    this->phrasesRaw.append(QByteArray(
                            reinterpret_cast<const char *> (phraseRaw.data()),
                            static_cast<int> (size)));
                    pointer += static_cast<size_t> (size);
                    PRINT_DBG("        Phrase: %s", phrase.toLocal8Bit().data());
                }
            }
        }
        else
        {
            PRINT_DBG("Loading compressed WinHelp phrase file");
            seekFile(file, off + InternalDirectoryFileHeader::size);
            quint16 numPhrases = readUnsignedWord(file);
            PRINT_DBG("        Num phrases: %d", numPhrases);
            quint16 oneHundred = readUnsignedWord(file);
            PRINT_DBG("        One hundred: %d", oneHundred);
            if (oneHundred != 0x0100)
            {
                throw std::runtime_error("Not a WinHelp phrase file");
            }
            quint32 uncompressedSize = readUnsignedDWord(file);
            PRINT_DBG("        Uncompressed size: %d", uncompressedSize);
            QScopedArrayPointer<uint> phraseOffset(
                new uint[static_cast<size_t> (numPhrases + 1)]);
            PRINT_DBG("Reading phrase offsets at %lld", file.pos());
            for (quint16 index = 0; index < numPhrases + 1; index++)
            {
                phraseOffset[index]
                    = static_cast<uint> (readUnsignedWord(file));
                PRINT_DBG("        Phrase offset: %d", phraseOffset[index]);
            }
            PRINT_DBG("Reading compressed phrases at %lld", file.pos());
            qint64 inputLength = off + hdr.getReservedSpace() - file.pos();
            QScopedArrayPointer<quint8> uncompressedPhrases(
                new quint8[static_cast<size_t> (uncompressedSize)]);
            unpackLZ77(file, file.pos(), inputLength,
                uncompressedPhrases.data(),
                static_cast<size_t> (uncompressedSize));
            size_t pointer = static_cast<size_t> (0);
            for (quint16 index = 0; index < numPhrases; index++)
            {
                uint size = phraseOffset[index + 1] - phraseOffset[index];
                QString phrase = readFixedLengthStringFromBuffer(
                    uncompressedPhrases.data(),
                    static_cast<size_t> (uncompressedSize), pointer,
                    size, codec);
                this->phrases.append(phrase);
                QScopedArrayPointer<quint8> phraseRaw(
                    new quint8[static_cast<size_t> (size)]);
                copyBytesFromBuffer(
                    reinterpret_cast<const void *> (uncompressedPhrases.data()),
                    static_cast<size_t> (uncompressedSize), pointer,
                    static_cast<size_t> (size),
                    reinterpret_cast<void *> (phraseRaw.data()),
                    static_cast<size_t> (size));
                this->phrasesRaw.append(QByteArray(
                        reinterpret_cast<const char *> (phraseRaw.data()),
                        static_cast<int> (size)));
                pointer += static_cast<size_t> (size);
                PRINT_DBG("        Phrase: %s", phrase.toLocal8Bit().data());
            }
        }
    }
    else
    {
        PRINT_DBG("Loading uncompressed WinHelp phrase file");
        seekFile(file, off + InternalDirectoryFileHeader::size);
        quint16 numPhrases = readUnsignedWord(file);
        PRINT_DBG("        Num phrases: %d", numPhrases);
        quint16 oneHundred = readUnsignedWord(file);
        PRINT_DBG("        One hundred: %d", oneHundred);
        if (oneHundred != 0x0100)
        {
            throw std::runtime_error("Not a WinHelp phrase file");
        }
        QScopedArrayPointer<uint> phraseOffset(
            new uint[static_cast<size_t> (numPhrases + 1)]);
        PRINT_DBG("Reading phrase offsets at %lld", file.pos());
        for (quint16 index = 0; index < numPhrases + 1; index++)
        {
            phraseOffset[index] = static_cast<uint> (readUnsignedWord(file));
            PRINT_DBG("        Phrase offset: %d", phraseOffset[index]);
        }
        PRINT_DBG("Reading phrases at %lld", file.pos());
        for (quint16 index = 0; index < numPhrases; index++)
        {
            uint size = phraseOffset[index + 1] - phraseOffset[index];
            qint64 posMem = file.pos();
            QString phrase = readFixedLengthString(file, size, codec);
            this->phrases.append(phrase);
            QScopedArrayPointer<quint8> phraseRaw(
                new quint8[static_cast<size_t> (size)]);
            seekFile(file, posMem);
            fillBuffer(file, static_cast<qint64> (size),
                reinterpret_cast<void *> (phraseRaw.data()),
                static_cast<size_t> (size));
            this->phrasesRaw.append(QByteArray(
                    reinterpret_cast<const char *> (phraseRaw.data()),
                    static_cast<int> (size)));
            PRINT_DBG("        Phrase: %s", phrase.toLocal8Bit().data());
        }
    }
    PRINT_DBG("WinHelp phrase file loaded successfully");
}
// TODO not working for now..need to find a way to get the same info without using CMD_SCENARIO (as not implemented by SUMO)
int commandGetMaxSUMONodesVariable()
{	
	reset();

        int max_car = 0;

   	// command length
    	writeUnsignedByte(1 + 1 + 1 + 1 + 4 + 1 + 1 + 4);
        // command id
        writeUnsignedByte(CMD_SCENARIO);
        // flag
	writeUnsignedByte(0x00); // GET command for the generic environment-related values
    	// command id
    	//writeUnsignedByte(CMD_SCENARIO);
        // domain id
	writeUnsignedByte(0x01); // vehicle
	
         writeInt(0); // first vehicular domain
    	
        // variable id
    	writeUnsignedByte(DOMVAR_MAXCOUNT); // get maximum number of vehicles

	writeUnsignedByte(TYPE_INTEGER); // get maximum number of vehicles
	writeInt(max_car); // get maximum number of vehicles
    
    	// send request message
    	sendExact(storageLength(storageStart));

    	// receive answer message
    	if (extractCommandStatus(receiveExact(), CMD_SCENARIO, description)){//<---RESPONSE_GET_VEHICLE_VARIABLE
	
    	  // validate result state
          
          if(tracker == NULL) {
            //LOG_E(OMG, " client_traci_OMG::commandGetMaxSUMONodesVariable():  Tracker is NULL \n");
            return -1;
	  }
	  int res = readUnsignedByte();
	  int Length = readUnsignedByte(); // to check with Int
       	  int cmdId =readUnsignedByte();
          if (cmdId != (CMD_SCENARIO)) {
		//LOG_E(OMG, " Wrong response recieved \n");
            	return -1;
          }

 	  int flag = readUnsignedByte(); 
 	  int dom = readUnsignedByte(); // domain
          int domID = readInt(); // domain ID
          int VariableID = readUnsignedByte();

          int valueDataType = readUnsignedByte();
    
	  if (valueDataType == TYPE_INTEGER) {
        	max_car = readInt();
		//LOG_N(OMG, " max Number SUMO nodes is: %f \n", max_car);
    	  } 
      	  else {
               //LOG_W(OMG, " No Matching Data Type Value \n"); 
	  }
      UNUSED_VARIABLE(res);
      UNUSED_VARIABLE(Length);
      UNUSED_VARIABLE(flag);
      UNUSED_VARIABLE(dom);
      UNUSED_VARIABLE(domID);
      UNUSED_VARIABLE(VariableID);
	}   

    return max_car;
}
示例#15
0
WinHelpIcon::WinHelpIcon(QFile &file, qint64 off) :
    images()
{
    PRINT_DBG("Loading icon");
    seekFile(file, off);
    quint16 magicIn = readUnsignedWord(file);
    if (magicIn != 0)
    {
        throw std::runtime_error("Not an icon resource header");
    }
    PRINT_DBG("        Icon resource header magic: %d", magicIn);
    quint16 resourceTypeIn = readUnsignedWord(file);
    if (resourceTypeIn != 1)
    {
        throw std::runtime_error("Resource is not an icon");
    }
    PRINT_DBG("        Icon resource header resource type: %d", resourceTypeIn);
    quint16 imagesCountIn = readUnsignedWord(file);
    PRINT_DBG("        Icon resource header images count: %d", imagesCountIn);
    QScopedArrayPointer<quint8> widths(new quint8[imagesCountIn]);
    QScopedArrayPointer<quint8> heights(new quint8[imagesCountIn]);
    QScopedArrayPointer<quint32> colorCounts(new quint32[imagesCountIn]);
    QScopedArrayPointer<quint16> colorPlanes(new quint16[imagesCountIn]);
    QScopedArrayPointer<quint16> bitsPerPixelCount(new quint16[imagesCountIn]);
    QScopedArrayPointer<qint64> bitmapSizes(new qint64[imagesCountIn]);
    QScopedArrayPointer<qint64> bitmapOffsets(new qint64[imagesCountIn]);
    for (int index = 0; index < imagesCountIn; index++)
    {
        widths[index] = readUnsignedByte(file);
        PRINT_DBG("        Icon image directory image header width: %d",
            widths[index]);
        heights[index] = readUnsignedByte(file);
        PRINT_DBG("        Icon image directory image header height: %d",
            heights[index]);
        colorCounts[index] = static_cast<quint32> (readUnsignedByte(file));
        PRINT_DBG("        Icon image directory image header color count: %d",
            colorCounts[index]);
        quint8 reservedIn = readUnsignedByte(file);
        if (reservedIn != 0)
        {
            qDebug()
            << "Icon image directory image header reserved value is non-zero";
        }
        PRINT_DBG("        Icon image directory image header reserved: %d",
            reservedIn);
        colorPlanes[index] = readUnsignedWord(file);
        PRINT_DBG("        Icon image directory image header color planes: %d",
            colorPlanes[index]);
        bitsPerPixelCount[index] = readUnsignedWord(file);
        PRINT_DBG(
            "        Icon image directory image header bits per pixel count: %d",
            bitsPerPixelCount[index]);
        bitmapSizes[index] = static_cast<qint64> (readUnsignedDWord(file));
        PRINT_DBG("        Icon image directory image header bitmap size: %lld",
            bitmapSizes[index]);
        bitmapOffsets[index] = static_cast<qint64> (readUnsignedDWord(file));
        PRINT_DBG(
            "        Icon image directory image header bitmap offset: %lld",
            bitmapOffsets[index]);
    }
    for (int index = 0; index < imagesCountIn; index++)
    {
        seekFile(file, off + bitmapOffsets[index]);
        quint32 headerSizeIn = readUnsignedDWord(file);
        PRINT_DBG("        Icon image header size: %d", headerSizeIn);
        if (headerSizeIn == 40)
        {
            qint32 widthIn = readSignedDWord(file);
            PRINT_DBG("        Icon image width: %d", widthIn);
            qint64 realWidth = static_cast<qint64> (widths[index]);
            if (realWidth == 0)
            {
                realWidth = static_cast<qint64> (widthIn);
            }
            qint32 heightIn = readSignedDWord(file);
            PRINT_DBG("        Icon image height: %d", heightIn);
            qint64 realHeight = static_cast<qint64> (heights[index]);
            if (realHeight == 0)
            {
                realHeight = (static_cast<qint64> (heightIn)) / (Q_INT64_C(2));
            }
            quint16 colorPlanesIn = readUnsignedWord(file);
            PRINT_DBG("        Icon image color planes: %d", colorPlanesIn);
            quint16 bitsPerPixelCountIn = readUnsignedWord(file);
            PRINT_DBG("        Icon image bits per pixel count: %d",
                bitsPerPixelCountIn);
            if (colorCounts[index] == 0)
            {
                if (colorPlanesIn == 1)
                {
                    if (bitsPerPixelCountIn == 1)
                    {
                        colorCounts[index] = 2;
                    }
                    else
                    {
                        if (bitsPerPixelCountIn == 4)
                        {
                            colorCounts[index] = 16;
                        }
                        else
                        {
                            if (bitsPerPixelCountIn == 8)
                            {
                                colorCounts[index] = 256;
                            }
                            else
                            {
                                if (bitsPerPixelCountIn != 32)
                                {
                                    colorCounts[index] = 1
                                        << bitsPerPixelCountIn;
                                }
                            }
                        }
                    }
                }
                else
                {
                    colorCounts[index] = 1 << (bitsPerPixelCountIn
                        * colorPlanesIn);
                }
            }
            quint32 compressionMethodIn = readUnsignedDWord(file);
            PRINT_DBG("        Icon image compression method: %d",
                compressionMethodIn);
            quint32 imageSizeIn = readUnsignedDWord(file);
            PRINT_DBG("        Icon image size: %d", imageSizeIn);
            qint32 horizontalResolutionIn = readSignedDWord(file);
            PRINT_DBG("        Icon image horizontal resolution: %d",
                horizontalResolutionIn);
            qint32 verticalResolutionIn = readSignedDWord(file);
            PRINT_DBG("        Icon image vertical resolution: %d",
                verticalResolutionIn);
            quint32 colorsInPaletteIn = readUnsignedDWord(file);
            PRINT_DBG("        Icon image colors in palette: %d",
                colorsInPaletteIn);
            quint32 importantColorsUsedIn = readUnsignedDWord(file);
            PRINT_DBG("        Icon image imporatnt colors used: %d",
                importantColorsUsedIn);
            if ((realWidth != 0) && (realHeight != 0) && ((colorCounts[index]
                        == 0) || (colorCounts[index] == 2) ||
                        (colorCounts[index]
                        == 16) || (colorCounts[index] == 256)))
            {
                QImage image(static_cast<int> (realWidth),
                    static_cast<int> (realHeight), QImage::Format_ARGB32);
                if (colorCounts[index] == 2)
                {
                    QScopedArrayPointer<QRgb> palette(new QRgb[2]);
                    for (int i = 0; i < 2; i++)
                    {
                        palette[i] = readBGRDword(file);
                    }
                    qint64 scanlineBytes = ((realWidth + Q_INT64_C(31))
                        / (Q_INT64_C(32))) * Q_INT64_C(4);
                    QScopedArrayPointer<quint8> xorImage(
                        new quint8[scanlineBytes * realHeight]);
                    QScopedArrayPointer<quint8> andImage(
                        new quint8[scanlineBytes * realHeight]);
                    if (file.read(reinterpret_cast<char *> (xorImage.data()),
                                (scanlineBytes * realHeight)) != (scanlineBytes
                            * realHeight))
                    {
                        throw std::runtime_error("Unable to read icon image");
                    }
                    if (file.read(reinterpret_cast<char *> (andImage.data()),
                                (scanlineBytes * realHeight)) != (scanlineBytes
                            * realHeight))
                    {
                        throw std::runtime_error("Unable to read icon image");
                    }
                    quint8 masks[] =
                    {
                        128, 64, 32, 16, 8, 4, 2, 1
                    };
                    for (qint64 row = 0; row < realHeight; row++)
                    {
                        for (qint64 col = 0; col < realWidth; col++)
                        {
                            int colorIndex = 0;
                            if ((xorImage[row * scanlineBytes + col
                                        / (Q_INT64_C(8))] & masks[col
                                        % (Q_INT64_C(8))]) != 0)
                            {
                                colorIndex = 1;
                            }
                            else
                            {
                                colorIndex = 0;
                            }
                            if ((andImage[row * scanlineBytes + col
                                        / (Q_INT64_C(8))] & masks[col
                                        % (Q_INT64_C(8))]) != 0)
                            {
                                image.setPixel(col, realHeight - Q_INT64_C(1)
                                    - row, qRgba(qRed(palette[colorIndex]),
                                        qGreen(palette[colorIndex]), qBlue(
                                            palette[colorIndex]), 0));
                            }
                            else
                            {
                                image.setPixel(col, realHeight - Q_INT64_C(1)
                                    - row, qRgba(qRed(palette[colorIndex]),
                                        qGreen(palette[colorIndex]), qBlue(
                                            palette[colorIndex]), 0xFF));
                            }
                        }
                    }
                }
                else
                {
                    if (colorCounts[index] == 16)
                    {
                        QScopedArrayPointer<QRgb> palette(new QRgb[16]);
                        for (int i = 0; i < 16; i++)
                        {
                            palette[i] = readBGRDword(file);
                        }
                        qint64 scanlineBytesXor = ((realWidth * Q_INT64_C(4)
                                + Q_INT64_C(31)) / (Q_INT64_C(32)))
                            * Q_INT64_C(4);
                        qint64 scanlineBytesAnd = ((realWidth + Q_INT64_C(31))
                            / (Q_INT64_C(32))) * Q_INT64_C(4);
                        QScopedArrayPointer<quint8> xorImage(
                            new quint8[scanlineBytesXor * realHeight]);
                        QScopedArrayPointer<quint8> andImage(
                            new quint8[scanlineBytesAnd * realHeight]);
                        if (file.read(
                                reinterpret_cast<char *> (xorImage.data()),
                                    (scanlineBytesXor * realHeight))
                            != (scanlineBytesXor * realHeight))
                        {
                            throw std::runtime_error(
                                "Unable to read icon image");
                        }
                        if (file.read(
                                reinterpret_cast<char *> (andImage.data()),
                                    (scanlineBytesAnd * realHeight))
                            != (scanlineBytesAnd * realHeight))
                        {
                            throw std::runtime_error(
                                "Unable to read icon image");
                        }
                        quint8 masks[] =
                        {
                            128, 64, 32, 16, 8, 4, 2, 1
                        };
                        for (qint64 row = 0; row < realHeight; row++)
                        {
                            for (qint64 col = 0; col < realWidth; col++)
                            {
                                quint8 colorIndex = 0;
                                if ((col & Q_INT64_C(1)) == Q_INT64_C(0))
                                {
                                    colorIndex = xorImage[row
                                        * scanlineBytesXor + col
                                        / Q_INT64_C(2)];
                                    colorIndex = colorIndex >> 4;
                                }
                                else
                                {
                                    colorIndex = xorImage[row
                                        * scanlineBytesXor + col
                                        / Q_INT64_C(2)] & 15;
                                }
                                if ((andImage[row * scanlineBytesAnd + col
                                            / (Q_INT64_C(8))] & masks[col
                                            % (Q_INT64_C(8))]) != 0)
                                {
                                    image.setPixel(
                                        col,
                                        realHeight - Q_INT64_C(1) - row,
                                        qRgba(
                                            qRed(
                                                palette[static_cast<int> (
                                                        colorIndex)]),
                                            qGreen(
                                                palette[static_cast<int> (
                                                        colorIndex)]),
                                            qBlue(
                                                palette[static_cast<int> (
                                                        colorIndex)]),
                                            0));
                                }
                                else
                                {
                                    image.setPixel(
                                        col,
                                        realHeight - Q_INT64_C(1) - row,
                                        qRgba(
                                            qRed(
                                                palette[static_cast<int> (
                                                        colorIndex)]),
                                            qGreen(
                                                static_cast<int> (palette[
                                                        colorIndex])),
                                            qBlue(
                                                palette[static_cast<int> (
                                                        colorIndex)]),
                                            0xFF));
                                }
                            }
                        }
                    }
示例#16
0
WinHelpPhrIndexFile::WinHelpPhrIndexFile(QFile &file, qint64 off) :
    phrasesOffset(), phrasesBits()
{
    PRINT_DBG("Loading WinHelp PhrIndex file at %lld", off);
    seekFile(file, off);
    InternalDirectoryFileHeader hdr(file, off);
    seekFile(file, off + InternalDirectoryFileHeader::size);
    quint32 magic = readUnsignedDWord(file);
    PRINT_DBG("        Magic: %d", magic);
    if (magic != 1)
    {
        throw std::runtime_error("Not a PhrIndex file");
    }
    quint32 nEntries = readUnsignedDWord(file);
    PRINT_DBG("        nEntries: %d", nEntries);
    quint32 compressedSize = readUnsignedDWord(file);
    PRINT_DBG("        Compressed size: %d", compressedSize);
    this->phrImageSize = static_cast<qint64> (readUnsignedDWord(file));
    PRINT_DBG("        phrImage size: %lld", this->phrImageSize);
    this->phrImageCompressedSize
        = static_cast<qint64> (readUnsignedDWord(file));
    PRINT_DBG("        phrImage compressed size: %lld",
        this->phrImageCompressedSize);
    quint32 alwaysZero = readUnsignedDWord(file);
    PRINT_DBG("        Always zero: %d", alwaysZero);
    if (alwaysZero != 0)
    {
        qDebug() << "Always zero phrIndex file field is non zero";
    }
    quint8 bitfieldL = readUnsignedByte(file);
    PRINT_DBG("        Bitfield low byte: %d", bitfieldL);
    quint8 bitfieldH = readUnsignedByte(file);
    PRINT_DBG("        Bitfield high byte: %d", bitfieldH);
    quint8 bitCount = bitfieldL & 0x0F;
    PRINT_DBG("        Bitcount: %d", bitCount);
    quint16 unknownValue = readUnsignedWord(file);
    PRINT_DBG("        Unknown value: %d", unknownValue);
    this->phrasesOffset.resize(nEntries + 1);
    this->phrasesOffset[0] = 0;
    PRINT_DBG("        Phrase offset: %d", this->phrasesOffset[0]);
    IntAllignedCursor cur;
    cur.currentBitIndex = 0;
    cur.currentDwordByte0 = 0;
    cur.currentDwordByte1 = 0;
    cur.currentDwordByte2 = 0;
    cur.currentDwordByte3 = 0;
    for (quint32 i = 0; i < nEntries; i++)
    {
        uint n = 1;
        while (this->getNextBitIntAlligned(file, cur))
        {
            n += static_cast<uint> (0x0001 << bitCount);
        }
        if (this->getNextBitIntAlligned(file, cur))
        {
            n += 1;
        }
        if (bitCount > 1)
        {
            if (this->getNextBitIntAlligned(file, cur))
            {
                n += 2;
            }
        }
        if (bitCount > 2)
        {
            if (this->getNextBitIntAlligned(file, cur))
            {
                n += 4;
            }
        }
        if (bitCount > 3)
        {
            if (this->getNextBitIntAlligned(file, cur))
            {
                n += 8;
            }
        }
        if (bitCount > 4)
        {
            if (this->getNextBitIntAlligned(file, cur))
            {
                n += 16;
            }
        }
        this->phrasesOffset[i + 1] = this->phrasesOffset[i] + n;
        PRINT_DBG("        Phrase offset: %d", this->phrasesOffset[i + 1]);
    }
    this->phrasesBits.resize(nEntries);
    ByteAllignedCursor bCur;
    bCur.currentBitIndex = 0;
    bCur.currentByte = 0;
    for (quint32 index = 0; index < nEntries; index++)
    {
        if (this->getNextBitByteAlligned(file, bCur))
        {
            this->phrasesBits[index] = true;
            PRINT_DBG("        Phrase bit is true");
        }
        else
        {
            this->phrasesBits[index] = false;
            PRINT_DBG("        Phrase bit is false");
        }
    }
    PRINT_DBG("WinHelp PhrIndex file loaded successfully");
}