Thread: Extracting series of hexadecimal values from buffer

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    1

    Extracting series of hexadecimal values from buffer

    Hello All,

    I am programming a microcontroller, it get s data from a serial cable 1 byte at a time. It has been programmed to write each received byte to the buffer.

    I have functions to write or read a byte from the buffer.

    I have the buffer filled with data of about 102 bytes. how can I extract from the 70th byte up to the 82nd byte? the value I need is 12 bytes in total but it starts from the 70th byte?

    I will appreciate any help with this task.

    below is a sample of the code that removes a byte from the buffer

    Code:
    /****************************************************************************/
    /***        Macro Definitions                                             ***/
    /****************************************************************************/
    #define CIRCBUFF_PTR_MASK   0x03FFU
    #define MAX_CIRCBUFF_SIZE   1024
    #define NBR_QUEUES          2
    /***********************************************************/
    typedef struct
    {
        uint16 u16Head;
        uint16 u16Tail;
        uint8  u8Buff[MAX_CIRCBUFF_SIZE];
    } tsCircBuff;
    typedef enum {RX_QUEUE = 0, TX_QUEUE } eQueueRef;
    
    PRIVATE tsCircBuff sRxQueue, sTxQueue;
    PRIVATE const tsCircBuff *apsQueueList[NBR_QUEUES] = { &sRxQueue, &sTxQueue };
    
    PUBLIC uint8 u8SerialQ_RemoveItem(eQueueRef eQueue)
    {
        uint8 u8Item = 0;
        tsCircBuff *psQueue;
    
        psQueue = (tsCircBuff *)apsQueueList[eQueue]; /* Set pointer to the requested queue */
    
        if (psQueue->u16Tail != psQueue->u16Head)
        {
            /* Data available on queue so remove a single item */
            u8Item = psQueue->u8Buff[psQueue->u16Tail];
            psQueue->u16Tail = (psQueue->u16Tail + 1) & CIRCBUFF_PTR_MASK;
        }
        return(u8Item);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > I have the buffer filled with data of about 102 bytes. how can I extract from the 70th byte up to the 82nd byte?
    How important are the first 70 bytes? Do you need them for something else?

    Start with
    uint8 frame[102];
    for ( i = 0 ; i < 102 ; i++ ) frame[i] = u8SerialQ_RemoveItem(q);


    Then you can do
    for ( i = 70 ; i < 82 ; i++ ) // do thing with frame[i]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    If you have access to <string.h> you can use memcpy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zero Values being ignored for output (hexadecimal)
    By Oldman47 in forum C++ Programming
    Replies: 5
    Last Post: 12-12-2006, 04:01 PM
  2. Extracting strings from a buffer
    By MoonSire in forum C Programming
    Replies: 11
    Last Post: 07-31-2006, 02:16 AM
  3. hexadecimal values for printer with BIOS
    By frenchfry164 in forum Tech Board
    Replies: 1
    Last Post: 01-17-2003, 07:02 PM
  4. Extracting a string from a buffer?
    By tetradtech in forum Linux Programming
    Replies: 6
    Last Post: 10-10-2002, 11:32 AM
  5. newbie needs help with extracting a file from buffer
    By thebeagle_98 in forum C++ Programming
    Replies: 0
    Last Post: 02-22-2002, 05:58 PM

Tags for this Thread