void VerilatedVcd::closePrev () { if (!isOpen()) return; bufferFlush(); m_isOpen = false; ::close(m_fd); }
void SpTraceVcd::closePrev () { if (!isOpen()) return; bufferFlush(); m_isOpen = false; ::close(m_fd); }
static void controlReceived(uint32_t token) { OpenIBootCmd* cmd = (OpenIBootCmd*)controlRecvBuffer; OpenIBootCmd* reply = (OpenIBootCmd*)controlSendBuffer; if(cmd->command == OPENIBOOTCMD_DUMPBUFFER) { int length; if(sendFileBytesLeft > 0) { length = sendFileBytesLeft; } else { length = getScrollbackLen(); // getScrollbackLen();// USB_BYTES_AT_A_TIME; } reply->command = OPENIBOOTCMD_DUMPBUFFER_LEN; reply->dataLen = length; usb_send_interrupt(3, controlSendBuffer, sizeof(OpenIBootCmd)); //uartPrintf("got dumpbuffer cmd, returning length: %d\r\n", length); } else if(cmd->command == OPENIBOOTCMD_DUMPBUFFER_GOAHEAD) { left = cmd->dataLen; //uartPrintf("got dumpbuffer goahead, writing length: %d\r\n", (int)left); size_t toRead = (left > USB_BYTES_AT_A_TIME) ? USB_BYTES_AT_A_TIME: left; if(sendFileBytesLeft > 0) { usb_send_bulk(1, sendFilePtr, toRead); sendFilePtr += toRead; sendFileBytesLeft -= toRead; if(sendFileBytesLeft == 0) { bufferPrintf("file sent.\r\n"); } } else { bufferFlush((char*) dataSendBuffer, toRead); usb_send_bulk(1, dataSendBuffer, toRead); } left -= toRead; } else if(cmd->command == OPENIBOOTCMD_SENDCOMMAND) { dataRecvPtr = dataRecvBuffer; rxLeft = cmd->dataLen; lastRxLen = rxLeft; //uartPrintf("got sendcommand, receiving length: %d\r\n", (int)rxLeft); reply->command = OPENIBOOTCMD_SENDCOMMAND_GOAHEAD; reply->dataLen = cmd->dataLen; usb_send_interrupt(3, controlSendBuffer, sizeof(OpenIBootCmd)); size_t toRead = (rxLeft > USB_BYTES_AT_A_TIME) ? USB_BYTES_AT_A_TIME: rxLeft; usb_receive_bulk(2, dataRecvPtr, toRead); rxLeft -= toRead; dataRecvPtr += toRead; } usb_receive_interrupt(4, controlRecvBuffer, sizeof(OpenIBootCmd)); }
void CBuffer_Write(CBuffer* cb, int flags, const char* txt) { assert(cb); lock(cb, true); // Check for special write actions first. if(flags & CBLF_RULER) { bufferFlush(cb); bufferNewLine(cb)->flags |= CBLF_RULER; flags &= ~CBLF_RULER; } if(!(!txt || !strcmp(txt, ""))) { size_t i, len = strlen(txt); // Copy the text into the write buffer and flush to the history // buffer when as necessary/required. for(i = 0; i < len; ++i) { cb->wbFlags = flags; if(txt[i] == '\n' || cb->wbc >= cb->maxLineLen) // A new line? { bufferFlush(cb); // Newlines won't get in the buffer at all. if(txt[i] == '\n') continue; } // Copy the next character to the write buffer. cb->writebuf[cb->wbc++] = txt[i]; } if(cb->flags & CBF_ALWAYSFLUSH) { // Don't leave data in the write buffer. bufferFlush(cb); } } lock(cb, false); }
StreamToFileManager::StreamToFileManager(QObject *parent) : QObject(parent), _chunkCounter(0), _targetFile(NULL), _isStreamingAborted(false) { _bufferedTransmitter = new BufferedTransmitter(1024 * 1024 * 2, this); // 2MB connect(_bufferedTransmitter, SIGNAL(bufferFlush(QByteArray)), this, SLOT(_bufferTransmitterFlush(QByteArray))); _backgroundWorkerQueue = new BackgroundWorkerQueue(this); connect(_backgroundWorkerQueue, SIGNAL(queueEmpty()), this, SLOT(_executorQueueEmtpy())); }
/* * Flush the buffer * * This will send the current contents up to and including the last space */ static void flushPhrase(void){ if(phraseBuffer.datalength){ // Write up to the last space phrase[phraseBuffer.datalength] = 0; sayText((char*)phrase); // Reset buffer to start bufferFlush(&phraseBuffer); phraseBuffer.dataindex=0; } }
int main() { int n; char buffer[MAXSIZE]; while((n = GETLINE(buffer, MAXSIZE)) > 0) { if(remove_space(buffer, n)) bufferFlush(buffer); } return 0; }
static int acm_send() { if(acm_file_recv_left > 0) { acm_busy = TRUE; return 1; } if(acm_file_send_left > 0) { acm_busy = TRUE; int amt = acm_file_send_left; if(amt > acm_usb_mps) amt = acm_usb_mps; memcpy(acm_send_buffer, acm_file_ptr, amt); acm_file_ptr += amt; acm_file_send_left -= amt; usb_send_bulk(ACM_EP_SEND, acm_send_buffer, amt); if(acm_file_send_left == 0) bufferPrintf("ACM: Sent file (finished at 0x%08x)!\n", acm_file_ptr); return 1; } if(getScrollbackLen() > 0) { acm_busy = TRUE; int amt = getScrollbackLen(); if(amt > acm_usb_mps) amt = acm_usb_mps; bufferFlush(acm_send_buffer, amt); usb_send_bulk(ACM_EP_SEND, acm_send_buffer, amt); return 1; } acm_busy = FALSE; return 0; }
static void dataSent(uint32_t token) { //uartPrintf("sending remainder: %d\r\n", (int)left); if(left > 0) { size_t toRead = (left > USB_BYTES_AT_A_TIME) ? USB_BYTES_AT_A_TIME: left; if(sendFileBytesLeft > 0) { usb_send_bulk(1, sendFilePtr, toRead); sendFilePtr += toRead; sendFileBytesLeft -= toRead; if(sendFileBytesLeft == 0) { bufferPrintf("file sent.\r\n"); } } else { bufferFlush((char*) dataSendBuffer, toRead); usb_send_bulk(1, dataSendBuffer, toRead); } left -= toRead; } }
void uartFlushReceiveBuffer(u08 nUart) { // flush all data from receive buffer bufferFlush(&uartRxBuffer[nUart]); }
void CBuffer_Flush(CBuffer* cb) { lock(cb, true); bufferFlush(cb); lock(cb, false); }
// process buffer containing STX/ETX packets unsigned char stxetxProcess(cBuffer* rxBuffer) { unsigned char foundpacket = FALSE; unsigned short i; unsigned char length, checksum; //unsigned char type; // process the buffer // go through buffer looking for packets // the STX must be located at least STXETX_HEADERLENGTH+STXETX_TRAILERLENGTH from end // otherwise we must not have a complete packet while( rxBuffer->datalength >= ((uint16_t)STXETX_HEADERLENGTH+(uint16_t)STXETX_TRAILERLENGTH) ) { // look for a potential start of packet if(bufferGetAtIndex(rxBuffer, 0) == STX) { // if this is a start, then get the length length = bufferGetAtIndex(rxBuffer, STXETX_LENGTHOFFSET); // now we must have at least STXETX_HEADERLENGTH+length+STXETX_TRAILERLENGTH in buffer to continue if(rxBuffer->datalength >= ((uint16_t)STXETX_HEADERLENGTH+length+(uint16_t)STXETX_TRAILERLENGTH)) { // check to see if ETX is in the right position if(bufferGetAtIndex(rxBuffer, STXETX_HEADERLENGTH+length+STXETX_TRAILERLENGTH-1) == ETX) { // found potential packet // test checksum checksum = 0; // sum data between STX and ETX, not including checksum itself // (uint16_t) casting needed to avoid unsigned/signed mismatch for(i = 0; i<((uint16_t)STXETX_HEADERLENGTH+length+(uint16_t)STXETX_TRAILERLENGTH-(uint16_t)STXETX_NOETXSTXCHECKSUM); i++) { checksum += bufferGetAtIndex(rxBuffer, i+STXETX_STATUSOFFSET); } // compare checksums if(checksum == bufferGetAtIndex(rxBuffer, STXETX_CHECKSUMOFFSET+length)) { //we have a packet! foundpacket = TRUE; // copy data to buffer // (don't copy STX, ETX, or CHECKSUM) for(i = 0; i < ((uint16_t)STXETX_HEADERLENGTH+length-1); i++) { stxetxRxPacket[i] = bufferGetAtIndex(rxBuffer, i+1); } // debug //rprintf("STXETX Received packet type: 0x%x\n", bufferGetAtIndex(rxBuffer, STXETX_TYPEOFFSET)); // dump this packet from the bufferDumpFromFront(rxBuffer, STXETX_HEADERLENGTH+length+STXETX_TRAILERLENGTH); // done with this processing session break; } else { // checksum bad //rprintf("STXETX Received packet with bad checksum\r\n"); // for now, we dump these // dump this STX bufferGetFromFront(rxBuffer); } } else { // no ETX or ETX in wrong position // dump this STX bufferGetFromFront(rxBuffer); } } else { // not enough data in buffer to decode pending packet // wait until next time break; } } else { // this is not a start, dump it bufferGetFromFront(rxBuffer); } } // check if receive buffer is full with no packets decoding // (ie. deadlocked on garbage data or packet that exceeds buffer size) if(!bufferIsNotFull(rxBuffer)) { // dump receive buffer contents to relieve deadlock bufferFlush(rxBuffer); } return foundpacket; }
uint8_t nmeaProcess(cBuffer* rxBuffer) { uint8_t foundpacket = NMEA_NODATA; uint8_t startFlag = FALSE; //uint8_t data; uint16_t i,j; // process the receive buffer // go through buffer looking for packets while(rxBuffer->datalength) { // look for a start of NMEA packet if(bufferGetAtIndex(rxBuffer,0) == '$') { // found start startFlag = TRUE; // when start is found, we leave it intact in the receive buffer // in case the full NMEA string is not completely received. The // start will be detected in the next nmeaProcess iteration. // done looking for start break; } else bufferGetFromFront(rxBuffer); } // if we detected a start, look for end of packet if(startFlag) { for(i=1; i<(rxBuffer->datalength)-1; i++) { // check for end of NMEA packet <CR><LF> if((bufferGetAtIndex(rxBuffer,i) == '\r') && (bufferGetAtIndex(rxBuffer,i+1) == '\n')) { // have a packet end // dump initial '$' bufferGetFromFront(rxBuffer); // copy packet to NmeaPacket for(j=0; j<(i-1); j++) { // although NMEA strings should be 80 characters or less, // receive buffer errors can generate erroneous packets. // Protect against packet buffer overflow if(j<(NMEA_BUFFERSIZE-1)) NmeaPacket[j] = bufferGetFromFront(rxBuffer); else bufferGetFromFront(rxBuffer); } // null terminate it NmeaPacket[j] = 0; // dump <CR><LF> from rxBuffer bufferGetFromFront(rxBuffer); bufferGetFromFront(rxBuffer); #ifdef NMEA_DEBUG_PKT rprintf("Rx NMEA packet type: "); rprintfStrLen(NmeaPacket, 0, 5); rprintfStrLen(NmeaPacket, 5, (i-1)-5); rprintfCRLF(); #endif // found a packet // done with this processing session foundpacket = NMEA_UNKNOWN; break; } } } if(foundpacket) { // check message type and process appropriately if(!strncmp(NmeaPacket, "GPGGA", 5)) { // process packet of this type nmeaProcessGPGGA(NmeaPacket); // report packet type foundpacket = NMEA_GPGGA; } else if(!strncmp(NmeaPacket, "GPVTG", 5)) { // process packet of this type nmeaProcessGPVTG(NmeaPacket); // report packet type foundpacket = NMEA_GPVTG; } } else if(rxBuffer->datalength >= rxBuffer->size) { // if we found no packet, and the buffer is full // we're logjammed, flush entire buffer bufferFlush(rxBuffer); } return foundpacket; }
void uartClearReceiveBuffer(u08 nUart) { assert(nUart < 4); // flush all data from receive buffer bufferFlush(&uartRxBuffer[nUart]); }