size_t readString( ptr_t address, size_t amountChars, std::basic_string<char_t>& dest) const { std::vector<char_t> returnedBytes(amountChars); rawRead(address, &returnedBytes[0], returnedBytes.size()); //Append a zero in case we didn't read the full string returnedBytes.push_back(0); dest.assign(&returnedBytes[0]); return dest.length(); }
int TLKFile::readStrings(void) { if(!inited.isMax(1) && init(2)) return errcode; strings.resize(strcount); for(uint32 i=0;i<strcount;i++) { if(seek(offstrings+offsets[i])) return errcode; if(rawRead(strings[i], strlengths[i])) return errcode; } offsets.clear(); strlengths.clear(); inited.set(2); return errcode = 0; }
// // seek to, and read central directory file header for a file at 'offset'. // read data into 'hdr'. on failure, throw a zppError. // void zppZipArchive::getCentralHeader(long offset, zppCentralDirFileHeader *hdr) { // first, seek to position in central directory. if (!rawSeek(offset)) throw zppError("Can't seek to central directory record"); // and read central directory header. if (!rawRead((char*)hdr,sizeof(zppCentralDirFileHeader))) throw zppError("Can't read central directory record"); // make sure that magic number matches. if (hdr->magicNumber != ZPP_CENTRAL_FILE_HEADER_MAGIC) throw zppError("Invalid magic number in central file header"); }
int GFFFile::readLabels(void) { std::string str; if(!inited.isMax(0) && init(1)) return errcode; if(seek(offlabel)) return errcode; labels.reserve(labelcount); for(uint32 i=0;i<labelcount;i++) { if(rawRead(str, 16)) return errcode; labels.push_back(str); } inited.set(1); return errcode = 0; }
int SSFFile::readData(void) { if(!inited.isMax(1) && init(2)) return errcode; if(offsets.size() != entrycount) return errcode = 25; stringrefs.resize(entrycount); resrefs.resize(entrycount); for(uint32 i=0;i<entrycount;i++) { if(seek(offsets[i])) return errcode; if(rawRead(resrefs[i], 16)) return errcode; if(binRead(stringrefs[i])) return errcode; } offsets.clear(); return errcode = 0; }
int ERFFile::dumpEntryIntoFile(uint32 entry, std::string fname) { std::ofstream ofile; if((entry == ERROR) && errcode) return errcode; if(entry == NOTFOUND) return errcode = 30; if(!inited.isMax(2) && init(3)) return errcode; if(entry >= entrycount) return errcode = 13; if(seek(offsets[entry])) return errcode; ofile.open(fname.c_str(), std::ios::out | std::ios::binary); if(!ofile) return errcode = 1; rawRead(&ofile, sizes[entry]); ofile.close(); return errcode = 0; }
uint8 *GFFFile::getRaw(uint32 n, Struct &sct, uint32 &size) { uint8 *data; errcode = 0; if(prepareGet(n, sct, NWN_VAR_VOID, offfielddata)) return NULL; if(binRead(size)) return NULL; if(!(data = (uint8 *) malloc(size))) { errcode = 4; return NULL; } if(rawRead((char *)data, size)) { free(data); return NULL; } return data; }
int TLKFile::readTable(void) { uint32 flag, tmp; if(!inited.isMax(0) && init(1)) return errcode; if(seek(20)) return errcode; flags.resize(strcount); sndresrefs.resize(strcount); sndlengths.resize(strcount); offsets.resize(strcount); strlengths.resize(strcount); for(uint32 i=0;i<strcount;i++) { if(binRead(flag)) return errcode; if(rawRead(sndresrefs[i], 16)) return errcode; if(binRead(4, &tmp, &tmp, &offsets[i], &strlengths[i])) return errcode; if(binRead(sndlengths[i])) return errcode; lowerStr(sndresrefs[i]); flags[i] = (uint16) flag; } inited.set(1); return errcode = 0; }
/* * NAME: dasd_write * * FUNCTION: Write to direct access file descriptor * * PARAMETERS: * offset - Starting byte offset for write request * pdata - Starting address of user data buffer * plen - On entry, number of bytes to be write * On exit, number of bytes actually write * vfsp - pointer to vfs structure * * RETURNS: 0 for success; Other indicates failure */ int32 dasd_write( int64 offset, caddr_t pdata, int64 *plen, struct vfs *vfsp) { int64 blocknum; cbuf_t *bp; dio_t *dp; inode_t *dummy_inode; int64 erroff; int64 fbytes; int64 lbytes; int64 mbytes; int64 nbytes = *plen; int32 rc; dummy_inode = getDummyInode(vfsp); /* If offset does not start on sector boundary, calculate number of * bytes in first partial sector. */ if (offset & (vfsp->vfs_bsize - 1)) { fbytes = MIN(nbytes, CM_BSIZE - (offset & CM_OFFSET)); nbytes -= fbytes; } else fbytes = 0; /* If write does not end on sector boundary, calculate number of * bytes in last sector */ if (nbytes & vfsp->vfs_bsize - 1) lbytes = nbytes & CM_OFFSET; else lbytes = 0; mbytes = nbytes - lbytes; nbytes = 0; /* Now counting bytes actually written */ /* First (partial) block */ if (fbytes) { if (rc = rawRead(dummy_inode, offset, &bp)) goto out1; if (rc = copyin(pdata, bp->cm_cdata+(offset & CM_OFFSET), fbytes)) { rawRelease(bp); goto out1; } if (rc = rawWrite(dummy_inode, bp, 1)) goto out1; nbytes = fbytes; offset += fbytes; pdata += fbytes; } /* Write full sectors */ if (mbytes) { blocknum = offset >> dummy_inode->i_l2pbsize; if (rc = dioStart(dummy_inode, &dp)) goto out1; (void) dioWrite(dp, blocknum, mbytes, offset, pdata, 0); if (rc = dioEnd(dp, &erroff)) { nbytes += (erroff - offset); goto out1; } nbytes += mbytes; offset += mbytes; pdata += mbytes; } /* Write last (partial) block */ if (lbytes) { if (rc = rawRead(dummy_inode, offset, &bp)) goto out1; if (rc = copyin(pdata, bp->cm_cdata, lbytes)) { rawRelease(bp); goto out1; } if (rc = rawWrite(dummy_inode, bp, 1)) goto out1; nbytes = +lbytes; } out1: releDummyInode(dummy_inode); *plen = nbytes; return (rc); }
int my_main(const char* str_latero_ip, int print_response, int npack, unsigned int* dacval, int dacval_cnt, char rd, char wr, int addr, int value, char dst_main, char dst_io, int testpattern ) { latero_conn latero; /* struct sockaddr_in si_server, si_other; int s, ii, slen=sizeof(si_other); char pktbuff[BUFLEN]; char rspbuff[BUFLEN]; */ int ii; uint8_t blades[64]; uint16_t dio_out = 0x0000; // For raw address commands uint16_t saddr = 0x0000; uint16_t sdata = 0x0000; latero_dst_device destination; int numbytes = 0; latero_pkt_t response; printf("Init Connection: "); if ( ii = init_connection( &latero, str_latero_ip ) < 0 ) { printf("Error (%d)!\n",ii ); return(-1); } else { printf("OK.\n"); } // Sanitize the dac values for(ii = 0 ; ii < 4 ; ii++ ) { if (ii < dacval_cnt ) { setDAC( &latero, ii, dacval[ii] ); } } /* for(ii = 0 ; ii<64 ; ii++ ) { blades[ii] = ii; } setBlades( &latero, blades ); */ // Run a few test cases here TestInit(); ii = 0; switch(testpattern) { case 1: TestSplit1(&latero); sleep(1); TestSplit2(&latero); break; case 2: TestAllpin(&latero); break; case 3: TestRow(&latero); sleep(1); TestCol(&latero); break; case 4: // Test continuously without stopping while(1) { printf("%d ", ii); TestRow(&latero); printf("%d ", ii); TestCol(&latero); ii++; } break; } /* Just on led is turned on... */ setDIO( &latero, 0xDEAC ); // setDAC( &latero, 0x0, 0x1234 ); // setDAC( &latero, 0x1, 0x5678 ); // setDAC( &latero, 0x2, 0x9ABC ); // setDAC( &latero, 0x3, 0xDEF0 ); printf("Sending\n"); sendNormalPacket( &latero, &response ); printf("printing\n"); printPacket( &response ); /* printf("Test Connection\n"); if( test_connection( &latero ) < 0 ) { fprintf(stderr,"The test_connection() failed\n"); } else { printf("Connection with Latero is OK.\n"); } */ if( rd > 0 || wr > 0 ) { saddr = addr & 0xFFFF; sdata = value & 0xFFFF; if ( dst_main > 0 ) { destination = LATERO_CONTROLLER; } else if ( dst_io > 0 ) { destination = LATERO_IO; } if( rd > 0 ) { rawRead( &latero, destination, saddr, &sdata ); printf("Data Read at address 0x%4.4X = 0x%4.4X\n", saddr,sdata); } else { /* Write */ rawWrite(&latero, destination, saddr, sdata ); printf("0x%4.4X written at address 0x%4.4X\n", sdata,saddr ); } } else { // Normal Latero Packets //fillNormalPacket(PKT_TYPE_FULL, dac, blades, dio_out, &packetSend); } return( close_connection( &latero ) ); }
int readDIODir( latero_conn* latero, uint16_t *value) { return( rawRead( latero, LATERO_IO, 0x18, value ) ); }
void zppZipArchive::parseZipDirectory() { long eofOffset; std::string dirPrefix; fileMap.clear(); if (!rawSeek(0,std::ios_base::end)) throw zppError("zppParseZip: can't seek on stream."); #ifdef ZPP_USE_STDIO eofOffset = ftell(str); current_pos_v = eofOffset; #else eofOffset = str->tellg(); #endif if (eofOffset < 0) throw zppError("zppParseZip: can't tellg() on stream."); // printf("end of file= %d\n",eofOffset); // first, find and then read end-of-central directory structure. if ((ecdOffset = searchCentralDir(eofOffset)) == 0) throw zppError("zppParseZip: can't find end-of-central directory record"); if (!rawSeek(ecdOffset)) throw zppError("zppParseZip: can't seek to end-of-central directory"); // printf("sizeof ECD = %d\n",sizeof(ecdHeader)); if (!rawRead((char*)&ecdHeader,sizeof(ecdHeader))) throw zppError("zppParseZip: can't read end-of-central directory record"); if (ecdHeader.magicNumber != ZPP_END_OF_CENTRAL_DIR_MAGIC) throw zppError("zppParseZip: invalid end of central dir magic #"); // printf("magic = %x, disk = %d, dirDisk = %d, cntThisDsk = %d,\n" // "cntTotal = %d, dirSize = %d, dirOfffset = %d, cmntLen=%d\n", // ecdHeader.magicNumber, ecdHeader.diskNum, ecdHeader.dirDiskNum, ecdHeader.entryCntThisDisk, // ecdHeader.entryCntTotal, ecdHeader.dirSize, ecdHeader.dirOffset, ecdHeader.commentLength); // now read central directory.. if (ecdHeader.diskNum != 0) throw zppError("zppParseZip: multi-disk archives not supported."); // if needed, parse attribute map. if (parseAttrFlag) { try { parseAttrMap(); } catch (zppError e) { printf("%s\n",e.str.c_str()); } } zppStrStrMap::iterator attr; attr = attrMap.find("ZPP_PRIORITY"); if (attr != attrMap.end()) { int p = atoi((*attr).second.c_str()); // printf("Got priority '%s' (%d) from zipcomment\n", (*attr).second.c_str(), p); priority = p; } attr = attrMap.find("ZPP_DIR_PREFIX"); if (attr != attrMap.end()) { dirPrefix = (*attr).second; canonizePath(dirPrefix); // append a slash if needed. // XXX -- should this be "hostified"? if (*(dirPrefix.rbegin()) != '/') dirPrefix.append("/"); } else dirPrefix = ""; int pos = ecdHeader.dirOffset; int i; // here we make a canonical filename -> file reference map. for (i = 0 ; i < ecdHeader.entryCntTotal; i++) { zppZipFileInfo file(pos,this); std::string name = file.getName(); canonizePath(name); // printf("org name = '%s', canonical name = '%s'\n", (*iter).getName().c_str(), tmp.c_str()); fileMap[name] = file; if (isGlobal) { // // search global directory for this (canonical) file name // zppFileMap::iterator i2 = globalMap.find(name); // // update the map entry for the file with name if the global map does // not yet contain an entry for file with name or the priority of // this archive is higher than the priority of the file currently in the map // if (i2 == globalMap.end() || i2->second.getPriority() < priority) { // printf("XXX -- Adding %s prio %d from %s\n", tmp.c_str(), (*iter).getPriority(), (*iter).getParentZip()->getName().c_str()); globalMap[name] = file; } } // advance position in directory by size of this object. pos += file.cdSize(); } }
void PL011::waitInput()const { while(!readReady()); rawRead(); }
gNodeComponentWidget::gNodeComponentWidget(sJarvisNodeComponent* comp,QWidget *parent) : QGroupBox(parent), m_component(comp), ui(new Ui::gNodeComponentWidget) { ui->setupUi(this); this->setTitle(m_component->getId()); QList<jarvisActions> actions = m_component->getActions(); for(int i = 0 ; i < actions.count() ; i++) { jarvisActions action = actions[i]; //qDebug() << QString::number(int(action)); QToolButton* b = new QToolButton(ui->actionsBox); QGridLayout* l = (QGridLayout*)ui->actionsBox->layout(); if (action == A_DIMM){ b->deleteLater(); QSlider* w = new QSlider(this); w->setMaximum(100); w->setValue(50); l->addWidget(w,l->count()/2,l->count()%2); connect(w,SIGNAL(valueChanged(int)),m_component,SLOT(dimm(int))); }else if(action == A_SET_COLOR){ connect(b,SIGNAL(clicked()),this,SLOT(selectComponentColor())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else if(action == A_SET_LEDS){ connect(b,SIGNAL(clicked()),this,SLOT(sendImage())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else if(action == A_DISPLAY){ connect(b,SIGNAL(clicked()),this,SLOT(sendImage())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else if(action == A_PLAYRTTTL){ connect(b,SIGNAL(clicked()),this,SLOT(openRtttlPlayer())); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); }else{ QString slotName = m_component->slotName(m_component->getActions()[i]); b->setText(m_component->actionName((m_component->getActions()[i]))); l->addWidget(b,l->count()/2,l->count()%2); connect(b,SIGNAL(clicked()),m_component,slotName.toStdString().c_str()); } } QList<jarvisEvents> events = m_component->getCapableEvents(); for(int i = 0 ; i < events.count() ; i++) { gBlinkWidget* w = new gBlinkWidget(ui->eventsBox); QLabel* label = new QLabel(ui->eventsBox); QGridLayout* l = (QGridLayout*)ui->eventsBox->layout(); l->addWidget(label,i,0); l->addWidget(w,i,1); w->setMaximumHeight(50); if(events[i] == E_RAW_READ) { connect(m_component,SIGNAL(rawRead()),w,SLOT(blink())); connect(m_component,SIGNAL(rawRead(QStringList)),w,SLOT(displayRead(QStringList))); label->setText(m_component->eventName((m_component->getCapableEvents()[i]))); }else if(events[i] == E_DATA_READ) { connect(m_component,SIGNAL(dataRead()),w,SLOT(blink())); connect(m_component,SIGNAL(dataRead(QStringList)),w,SLOT(displayRead(QStringList))); label->setText(m_component->eventName((m_component->getCapableEvents()[i]))); }else { QString signalName = m_component->signalName(m_component->getCapableEvents()[i]); label->setText(m_component->eventName((m_component->getCapableEvents()[i]))); connect(m_component,signalName.toStdString().c_str(),w,SLOT(blink())); } //w->setMinimumSize(32,32); //w->setMaximumSize(32,32); } }