Using streams/strings to parse data.



Greetings,

I am reading data from a USB device using readFile:

BOOL ReadFile(
HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped
);
This is working OK but I want to start taking advantage of more C++
capabilities such as the way it handles streams and strings. The GPS
sentences read in start with '$' and end with 0x0D 0x0A. However the
device was apparently first implemented as RS-232 and then ported to
USB as there may be any number of nulls in the stream. Thus the
'sentences' may not start at the beginning of the buffer and since
each bufferful is 32 bytes some of the 80 byte 'sentences' may span
three buffers.

Question 1:
Is there an existing sstream function that can convert an array of
characters that may have embedded nulls into a string object.

Question 2:
Since Readfile tells me how many bytes were copied into the buffer, is
there something in sstream that works to cin.getc or cin.getline that
can ignore multiple characters?

Question 3:
Is it possible to intermix a series of gets and appends to a string
object? In other words I want to use the string object as a FIFO,each
time I access this function I want to append more characters to the
string and then pull complete sentence from the front end?

Question 4:
I am more familiar with the Nucleus OS than with Windows and VC++.
Could question 3 be performed across two threads, where one is
appending and the other is extracting? Of course I would use
semaphores. I would appreciate it if you could point me to some
documentation on VC++ threads.

I appreciate your indulgence and hope I have not asked too many
questions. Currently I am using a finite state machine and very C like
code to do this ( at least it has c++ comments). But I sense that
there may be some tools in the C++ libs that may help me clean it up.

Thanks,

jh

.



Relevant Pages

  • Re: Using streams/strings to parse data.
    ... I am reading data from a USB device using readFile: ... Since Readfile tells me how many bytes were copied into the buffer, ... Is it possible to intermix a series of gets and appends to a string ...
    (microsoft.public.vc.language)
  • Using streams/strings to parse data.
    ... I am reading data from a USB device using readFile: ... Since Readfile tells me how many bytes were copied into the buffer, ... Is it possible to intermix a series of gets and appends to a string ...
    (microsoft.public.vc.language)
  • Re: newbie: I/O with nasm
    ... BOOL ReadFile( ... BOOL WriteFile( ... Now, if Windows is what TK is looking for, we've got something to go on. ... Pointer to the buffer that receives the data read from the file. ...
    (alt.lang.asm)
  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Secure C library
    ... I read much of the new "security TR", and gee, I don't know. ... the buffer from the buffer size. ... It is not hard to design a better form of buffer and string handling. ... but this is just one example of how thoughtful interface design can ...
    (comp.std.c)

Loading