SlimList* SlimList_Deserialize(char* serializedList) { int listLength; SlimList * list = 0; char* current = 0; if(serializedList == 0 || strlen(serializedList) == 0) return 0; current = serializedList; list = SlimList_Create(); SKIP('[') listLength = readLength(¤t); SKIP(':') while (listLength--) { int elementLength = readLength(¤t); SKIP(':') SlimList_AddBuffer(list, current, elementLength); current += elementLength; SKIP(':') } SKIP(']') return list; }
int broadCast(int cond, int lock){ int length=0; readLength(&length); while(length>0){ v(cond); //readLength(&length); length--; writeLength(&length); readLength(&length); } return(0); }
Actuator::Actuator(Leg* parent, int pwmPin, int potPin, float minLength, float maxLength, bool flipped, bool simulate) { this->parent = parent; this->pwmPin = pwmPin; this->potPin = potPin; this->minLength = minLength; this->maxLength = maxLength; this->simulated = simulate; this->flipped = flipped; this->midLength = minLength + (maxLength-minLength)/2; this->kP =50.0f; this->kI = 0.0f; this->kD = 0.0f; if(!simulated) { this->pwmOut.attach(pwmPin, PWM_USEC_MIN,PWM_USEC_MAX, PWM_MIN, PWM_MAX); pinMode(potPin, INPUT_ANALOG); this->length = readLength(50, false); for(int i=0; i<SMOOTH_SAMPLES; i++) this->lengthHistory[i] = length; } else this->length = midLength; setTarget(this->length, true); }
uint32_t TSaslTransport::read(uint8_t* buf, uint32_t len) { // if there's not enough data in cache, read from underlying transport if (memBuf_->available_read() < len) { uint32_t dataLength = readLength(); // Fast path if (len == dataLength && !shouldWrap_) { transport_->readAll(buf, len); return len; } uint8_t* tmpBuf = new uint8_t[dataLength]; transport_->readAll(tmpBuf, dataLength); if (shouldWrap_) { tmpBuf = sasl_->unwrap(tmpBuf, 0, dataLength, &dataLength); } // We will consume all the data, no need to put it in the memory buffer. if (len == dataLength) { memcpy(buf, tmpBuf, len); delete tmpBuf; return len; } memBuf_->write(tmpBuf, dataLength); memBuf_->flush(); delete tmpBuf; } return memBuf_->read(buf, len); }
int signal(int cond, int lock){ int length=0; readLength(&length); if(length>0){ v(cond); //readLength(&length); length--; writeLength(&length); } return(0); }
int wait(int cond, int lock){ int length=0; readLength(&length); length++; writeLength(&length); v(lock); //lock->Release(); p(cond); //s.P(); p(lock); //lock -> Acquire(); return(0); }
QByteArray U2BitCompression::uncompress(const char* data, const QByteArray& alphabetChars, U2OpStatus&) { // algorithm // 1. Derive all chars from header // 2. Assign bit masks per chars that have signed bit in header // 3. Unpack value int alphabetSize = alphabetChars.size(); const char* aChars = alphabetChars.data(); const uchar* bits = (const uchar*)data; int alphaMaskOffset = 0; int len = readLength(bits, alphaMaskOffset); // restore bit masks QVector<bool> visitVector(alphabetSize, false); bool* visited = visitVector.data(); int nChars = 0; for (int i = 0; i < alphabetSize; i++) { if (U2Bits::getBit(bits, i + alphaMaskOffset)) { visited[i] = true; nChars++; } } int bitsPerChar = U2Bits::getNumberOfBitsPerChar(nChars); QVector<char> mask2Char(nChars, 0); uchar m = 0; for (int i = 0; i < alphabetSize; i++) { if (visited[i]) { mask2Char[m] = aChars[i]; m++; } } int pos = alphaMaskOffset + alphabetSize; #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) QByteArray result(len, Qt::Uninitialized); #else QByteArray result(len, (char)0); #endif char* res = result.data(); for (int i = 0; i < len; i++, pos += bitsPerChar) { int m = U2Bits::bitsRange2Int32(bits, pos, bitsPerChar); char c = mask2Char[m]; assert(c != 0); res[i] = c; } return result; }
void Actuator::update() { if(!simulated) { /* for(int i=0; i<10; i++) { togglePin(16); delay(200); } delay(200); */ length = readLength(); //length = 0; float error = length - targetLength; writePWM(error * kP); } else { length = targetLength; } }
uint_read_len DefaultPseudoGenome<uint_read_len, uint_reads_cnt, uint_pg_len, ReadsListClass>::readLengthVirtual(uint_reads_cnt i) { return readLength(i); }
inline const string DefaultPseudoGenome<uint_read_len, uint_reads_cnt, uint_pg_len, ReadsListClass>::getRead(const uint_reads_cnt originalIdx) { uint_pg_len pos = this->readsList->getReadPosition(this->readsList->getReadsListIndexOfOriginalIndex(originalIdx)); return string(sequence + pos, readLength(originalIdx)); }
bool open_base(std::streambuf *sbuf) { _streambuf = sbuf; m_fileLen = readLength(); return (sbuf != nullptr); }
int receiveFile(int sock){ fp = fopen(file_path,"w"); if(fp == NULL) { perror("open"); exit(EXIT_FAILURE); } int test =4; while(1){ char buf[BUFFSIZE]; test--; if(recvfrom(sock, &buf, BUFFSIZE, 0, (struct sockaddr*) &sin6_cli, &sin6len) == -1){ perror("Connection Lost"); exit(EXIT_FAILURE); } int type = readType(buf[0]); int seq = readSeqNumber(buf[1]); printf("Received test:%d seq:%d\n", test, seq); if(type == PTYPE_DATA && test !=0){ window_start = (window_start+1)%MAXWINDOWSIZE; if(seq == seq_number && xor_count !=0){ memcpy(&buffer[(XORFREQ-xor_count)*PAYLOADSIZE], &buf[4], PAYLOADSIZE); msg_rvcd++; xor_count--; seq_number = (seq_number+1)%256; window_end = (window_end+ 1)%MAXWINDOWSIZE; sendMsg(sock, PTYPE_ACK, seq_number, window_end); printf("Ack sent %d %d\n", seq_number, window_end); last_length =readLength(buf); if(last_length<512){ xor_count=0; } }else{// else discard packet, send last ack again. sendMsg(sock, PTYPE_ACK, seq_number, window_end); } }else if(type == PTYPE_XOR){ computeXor(buffer); int seq = readSeqNumber(buf[1]); if(seq == seq_number && xor_count == 0){ if(checkXor(buf)){ xor_count = XORFREQ; seq_number= (seq_number+1)%256; window_end = (window_end+ 1)%MAXWINDOWSIZE; sendMsg(sock, PTYPE_ACK, seq_number, window_end); if(last_length<512){return 0;} msg_rvcd=0; }else{ // Make choice if XOR is wrong /* No ack sent, all window will be retransmitted*/ } } } if(test ==0){ test = 1000; } } fclose(fp); }