unsigned int getQEI(int fd, unsigned int motor) { // Send status update command (required call before reading) putByte(fd, 0xff, 0x00); if (motor == 1) { return getDWord(fd, 0x10); } else if (motor == 2) { return getDWord(fd, 0x14); } else { printf("Error: invalid motor number\n"); return 0; } }
REGFHeader::REGFHeader(RegistryByteBuffer& buf, const uint32_t offset) : BinaryBlock(buf, offset) { uint64_t magic = getDWord(offset); if (magic != 0x66676572) { throw RegistryParseException("REGF magic value not found"); } }
ByteBuffer::ByteArray DBIndirectRecord::getData(uint32_t length) const { std::vector<uint8_t> data; uint32_t count = 0; while (length > 0) { uint32_t size = std::min(DB_DATA_SIZE, length); uint32_t offset = getDWord(OFFSET_LIST_OFFSET + (count * 4)); offset += REGFHeader::FIRST_HBIN_OFFSET; std::auto_ptr< Cell > c(new Cell(_buf, offset)); if (c.get() == NULL) { throw RegistryParseException("Failed to create Cell."); } std::vector<uint8_t> cellData = c->getData(); data.insert(data.end(), cellData.begin(), cellData.begin() + size); length -= size; count += 1; } return data; }
uint32_t VKRecord::getDataLength() const { uint32_t size = getDWord(DATA_LENGTH_OFFSET); if (size >= LARGE_DATA_SIZE){ size -= LARGE_DATA_SIZE; } return size; }
HBIN::HBINPtr REGFHeader::getFirstHBIN() const { if (getDWord(FIRST_HBIN_OFFSET) != 0x6E696268) { throw RegistryParseException("HBIN magic value not found."); } return new HBIN(this, _buf, getAbsoluteOffset(FIRST_HBIN_OFFSET)); }
uint32_t VKRecord::getDataOffset() const { if (getRawDataLength() < SMALL_DATA_SIZE || getRawDataLength() >= LARGE_DATA_SIZE) { return _offset + DATA_OFFSET_OFFSET; } else { return REGFHeader::FIRST_HBIN_OFFSET + getDWord(DATA_OFFSET_OFFSET); } }
int oscar_tlv_chain::getNumber(WORD wType, WORD wIndex) { oscar_tlv *tlv = getTLV(wType, wIndex); if (tlv) { if (tlv->wLen == 1) return getByte(wType, wIndex); else if (tlv->wLen == 2) return getWord(wType, wIndex); else if (tlv->wLen == 4) return getDWord(wType, wIndex); } return 0; }
NKRecord::NKRecordPtr REGFHeader::getRootNKRecord() const { int32_t firstCellOffset = (int32_t)(getDWord(FIRST_KEY_OFFSET_OFFSET)); std::auto_ptr< HBIN > firstHBIN(getFirstHBIN()); if (firstHBIN.get() != NULL) { std::auto_ptr< Cell > cellPtr(firstHBIN->getCellAtOffset(firstCellOffset)); if (cellPtr.get() == NULL) { throw RegistryParseException("Failed to get first cell."); } return cellPtr->getNKRecord(); } else { throw RegistryParseException("Failed to get first HBIN."); } }
HBIN::HBINPtrList REGFHeader::getHBINs() const { uint32_t nextHBINOffset = FIRST_HBIN_OFFSET; HBIN::HBINPtrList hbinList; do { if (getDWord(nextHBINOffset) != 0x6E696268) { // Terminate if this doesn't have the correct magic number. break; } HBIN * nextHBIN = new HBIN(this, _buf, getAbsoluteOffset(nextHBINOffset)); hbinList.push_back(nextHBIN); nextHBINOffset += nextHBIN->getRelativeOffsetNextHBIN(); } while (nextHBINOffset <= getLastHbinOffset()); return hbinList; }
void STC_FLASHMEM ConfigurationManager::getGPIOParams(uint32_t gpioNum, bool *configured, bool *isOutput, bool *pullUp, bool *value) { APtr<char> key(f_printf(FSTR("GPIO%d"), gpioNum)); uint8_t const *infoPtr = FlashDictionary::getValue(key.get()); if (infoPtr) { uint32_t infoInt = getDWord(infoPtr); GPIOInfo *info = (GPIOInfo *)&infoInt; *configured = info->configured; *isOutput = info->isOutput; *pullUp = info->pullUp; *value = info->value; } else { // defaults *configured = false; *isOutput = false; *pullUp = false; *value = false; } }
int main(int argc, char const **argv) { char file[120]; char mode [3]; if (argv[1] == NULL) { printf("Boot needs at lest 1 argument\n"); exit(EXIT_FAILURE); } else { strcpy(file, argv[1]); } if (argv[2] == NULL) { strcpy(mode, "r"); } else { strcpy(mode, argv[2]); } //memcpy(shrmem.fileSysTyp, buf + 54, 8); memcpy(&shrmem.mode, &mode, 2); //memcpy(shrmem.fileSysTyp, buf + 54, 8); // memcpy(&shrmem.mode, &mode, (strlen(mode) * sizeof(char *))); FILE_SYSTEM_ID = fopen(file, mode); setFSID(FILE_SYSTEM_ID); shl_shareMemoryGet(); unsigned char* buf; buf = malloc(BYTES_TO_READ_IN_BOOT_SECTOR); setBPS(BYTES_TO_READ_IN_BOOT_SECTOR); if (read_sector(0, buf) == -1){ printf("Something has gone wrong -- could not read the shrmem sector\n"); } shrmem.bytesPerSector = getWord(buf, 11); setBPS(shrmem.bytesPerSector); shrmem.sectorsPerCluster = getByte(buf, 13); shrmem.numResSector = getWord(buf, 14 ); shrmem.numFat = getByte(buf, 16); shrmem.maxRootDirEnt = getWord(buf, 17); shrmem.totSectCount = getWord(buf, 19); shrmem.sectPerFat = getWord(buf, 22); shrmem.sectPerTrack = getWord(buf, 24); shrmem.numHead = getWord(buf, 26); shrmem.totSectCount4Fat = getDWord(buf, 32); shrmem.bootSig = getByte(buf, 38); shrmem.volID = getDWord(buf, 39); shrmem.volLabel[11] = 0; shrmem.fileSysTyp[8] = 0; memcpy(shrmem.volLabel, buf + 43, 11); memcpy(shrmem.fileSysTyp, buf + 54, 8); free(buf); shrmem.fildes = fileno(FILE_SYSTEM_ID); shl_shareMemorySet(); fclose(FILE_SYSTEM_ID); return 0; }
uint32_t VKRecord::getRawDataLength() const { return getDWord(DATA_LENGTH_OFFSET); }
bool REGFHeader::isSynchronized() const { return (getDWord(SEQ1_OFFSET) == getDWord(SEQ2_OFFSET)); }
ValueData::VALUE_TYPES VKRecord::getValueType() const { return (ValueData::VALUE_TYPES)getDWord(VALUE_TYPE_OFFSET); }
uint32_t REGFHeader::getMinorVersion() const { return getDWord(MINOR_VERSION_OFFSET); }
uint32_t REGFHeader::getLastHbinOffset() const { return getDWord(LAST_HBIN_OFFSET_OFFSET); }
int GetDWordH(const uint8_t **ppCur, uint32_t *pdwLeft, uint32_t *pdwValue) { return getDWord(ppCur, pdwLeft, pdwValue, 0); }