Src/pcan_protocol.c
/* request free slot for specific amount of data */
request free slot for specific amount of data
request free slot for specific amount of data
uint8_t *pcan_record_buffer_request( PCAN_RECORD_BUFFER_EX *prec, uint16_t size )
{
  if( size > (BLOCK_SIZE-HEADER_SIZE) )
    return 0;
  uint16_t unused = BLOCK_SIZE - ( prec->pos & (BLOCK_SIZE-1) );
  if( unused < size )
  {
    uint8_t next = ( prec->pos + (BLOCK_SIZE-1) ) & (~((BLOCK_SIZE-1)));
    if( (next+HEADER_SIZE) >= PCAN_MAX_RECORD_SIZE )
      return 0;
    memset( &prec->buffer[next], 0x00, BLOCK_SIZE );
    pcan_record_write_header( &prec->buffer[next] );
    next += 2;
    prec->pos = next;
    prec->ts_counter = 0;
  }
  if( ( prec->pos + size ) > PCAN_MAX_RECORD_SIZE )
    return (void*)0;
  return &prec->buffer[prec->pos];
}
uint8_t * pcan_record_buffer_request ( PCAN_RECORD_BUFFER_EX * prec , uint16_t size ) { if ( size > ( BLOCK_SIZE - HEADER_SIZE ) ) return 0 ; uint16_t unused = BLOCK_SIZE - ( prec -> pos & ( BLOCK_SIZE - 1 ) ) ; if ( unused < size ) { uint8_t next = ( prec -> pos + ( BLOCK_SIZE - 1 ) ) & ( ~ ( ( BLOCK_SIZE - 1 ) ) ) ; if ( ( next + HEADER_SIZE ) >= PCAN_MAX_RECORD_SIZE ) return 0 ; memset ( & prec -> buffer [ next ] , 0x00 , BLOCK_SIZE ) ; pcan_record_write_header ( & prec -> buffer [ next ] ) ; next += 2 ; prec -> pos = next ; prec -> ts_counter = 0 ; } if ( ( prec -> pos + size ) > PCAN_MAX_RECORD_SIZE ) return ( void * ) 0 ; return & prec -> buffer [ prec -> pos ] ; }
request free slot for specific amount of data
request free slot for specific amount of data
/* allocate new slot ? */ /* align data to next slot bound */ /* reset ts_counter for next buffer */