473,802 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serial data decoding

Ed
Please help!
I have a string of data as the result of serial to parallel hardware
conversion.
I need to decode this string into correct bytes.
The start of a byte position is unknown.
In this particular case, part of my data is as follows.
Serial data string: (not rs232, straight serial data)
010010100100100 101010010010010 010101001000100 10001001010
This was read through a shift register to get 8-bit bytes to store in memory
as:
4A 49 52 49 52 24 4A
I need to decode bit pairs into corrected bits.
00 = 0 01=1 10=0 11=Illegal
So that means every 16bits = 8bit byte
Ultimately I need to find certain values within this string which confirm
bit decode positions.
Somewhere within this string of bits there is a pattern of 4E 4E A1 and on
paper I do see it.
How can I decode this using C++ with a string of 32000 bytes?
This is not a homework assignment, it is an engineering design question.
Thanks,
Ed
Dec 6 '06 #1
2 2811
Ed wrote:
Please help!
I have a string of data as the result of serial to parallel hardware
conversion.
I need to decode this string into correct bytes.
The start of a byte position is unknown.
In this particular case, part of my data is as follows.
Serial data string: (not rs232, straight serial data)
010010100100100 101010010010010 010101001000100 10001001010
This was read through a shift register to get 8-bit bytes to store in memory
as:
4A 49 52 49 52 24 4A
I need to decode bit pairs into corrected bits.
00 = 0 01=1 10=0 11=Illegal
So that means every 16bits = 8bit byte
Ultimately I need to find certain values within this string which confirm
bit decode positions.
Somewhere within this string of bits there is a pattern of 4E 4E A1 and on
paper I do see it.
How can I decode this using C++ with a string of 32000 bytes?
This is not a homework assignment, it is an engineering design question.
There's no simple, out-of-the-box way. You'll have to write an
algorithm to do it. Use the bit operators (e.g., &, |, <<, and >>) or
perhaps std::bitset.

This newsgroup is for C++ language questions, not algorithm or
application design questions
(http://www.parashift.com/c++-faq-lit....html#faq-5.9), so if
you can rephrase your question as a specific language question, we
might be able to provide more assistance.

Cheers! --M

Dec 6 '06 #2
On Wed, 06 Dec 2006 16:25:21 GMT in comp.lang.c++, "Ed"
<ed***@hvc.rr.c omwrote,
>I need to decode bit pairs into corrected bits.
00 = 0 01=1 10=0 11=Illegal
So that means every 16bits = 8bit byte
Ultimately I need to find certain values within this string which confirm
bit decode positions.
Somewhere within this string of bits there is a pattern of 4E 4E A1 and on
paper I do see it.
How can I decode this using C++ with a string of 32000 bytes?
Some crude first approximation of code might look like:

unsigned char *in_ptr = ?, *out_ptr = ?;
int in_bytes = 32000;
unsigned char in_mask = 0xC0, in_bits = 0x40,
out_bit = 0x80, result_byte = 0;

while (in_bytes) {
unsigned char masked_bits = in_mask & *in_ptr;
if (masked_bits == in_bits) {
result_byte |= out_bit;

} else if (masked_bits == in_mask) {
error("illegal" );

} // else result is zero

in_mask >>= 2;
in_bits >>= 2;
if (in_mask == 0) {
--in_bytes;
++in_ptr;
in_mask = 0xC0;
in_bits = 0x40;
}

out_bits >>= 1;
if(out_bits == 0) {
*(out_ptr++) = result_byte;
result_byte = 0;
out_bit = 0x80;
}
}

Dec 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3603
by: Sonoman | last post by:
Hello everyone: I am new to Visual Basic and I have a problem that I cannot put my finger on. I am working on a school project and I am getting some serial data from a microprocessor. I have designed my "Do" loop to wait for each data set coming in at intervals of about 1/2 a second from the microprocessor. When I comment the following lines: bufferVar = ""
4
9094
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
14
4063
by: McBooCzech | last post by:
Hi I am just trying to analyze (parse) data from the serial port (I have connected GPS receiver to the ttyS0, so I can read ASCII characters in the CSV form on the serial port 1). I am doing this just to understand how Python works (yes, you can call me Python/Linux newbie :) My environment is Fedora Core 4, Python 2.4.1 CSV alone (to read CSV data from the file) and py-serial alone (to read data from the serial port) are working...
3
7445
by: Math55 | last post by:
hi, i have this piece of code: --- #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> /* baudrate settings are defined in <asm/termbits.h>, which is
4
11208
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
0
1663
by: kvu95111 | last post by:
Hi All, I have wrote a simple program using RS232 protocol. However, I have the following problem in hand. I used the software to receive data from a RFID reader (you may simply treat it like a barcode scanner) through RS232 communication. The software does receive strings from the reader every time an event is triggered (i.e. a tag is read by the reader). I'm sure the Expecting reading data should look similar to this: ...
7
5398
by: davetelling | last post by:
I'm a newbie that is still struggling with OOP concepts & how to make things work they way I want. Using Visual C# Express, I have a form in which I added a user control to display a graph, based upon data received via the serial port. If I run the serial port in the main form code, I can get data and, using public properties of the user control, transfer the data to be shown on the graph. However, I am trying to add a feature that will...
4
4819
by: max_mont | last post by:
Hi all, I'm a newbie in .NET technology. I've already developed Serial communication applications in C++ (WIN32). And I wanted to migrate to .NET technology. There is a serial component in framework to read and write on serial port. I would like to make asynchronous reception. I saw that we can pass a delegate to the serial class which is call when some data is readen on the port.
0
1299
by: amollokhande1 | last post by:
Hi All, Currently we are facing an issue while decoding the Base64Encoded unicode data. Here is the scenario We have one custom javascript function that encodes the unicode data using Base64 mechanism. After encoding the data on client side we are sending it back to the server. On Server side we are decoding this unicode data using microsoft framework inbuild functions as below Private Function DecodeVarHash(ByVal strEncoded As...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.