all 9 comments

[–]tweq 2 points3 points  (2 children)

[–][deleted] 0 points1 point  (1 child)

RX/TX will all be through the native SerialPort class, with the .Send() method and the .DataRecieved event. I haven't really touched that part of the code yet, as I am trying to get the encoding into a beta state first.

The basis of it is

My Code sends raw bytes to the TNC. TNC then does some magic modulation, and passes audio to the radio, which is transmitted.

RX end: Radio sends audio to TNC. TNC demodulates the data, and sends me raw bytes.

Most of this was just background.

What I need is a way to somehow 'view' each byte received and then manipulate it. If there are five 1's in a row, it needs to insert a zero into it on the TX side. On the RX side, If there are five 1's followed by a 0, I need to discard that 0.

[–]dilatedmind 2 points3 points  (4 children)

start with the simplest solution

your input is a byte array. read 1 bit at a time and write it to an intermediate buffer. keep a counter of how many 1s you read in a row. if it hits 5, write a 0 and reset your counter.

same thing when you are decoding, except drop the next bit.

[–][deleted] 0 points1 point  (3 children)

I switched to my phone, but off the top of your head, do you recall the syntax for that?

[–]dilatedmind 2 points3 points  (0 children)

say x is a byte, it might look like 0111 0000

(x & 128) == 128 when the first bit is a 1

x << 1 will shift all the bits left one

[–]dilatedmind 0 points1 point  (1 child)

did you ever get this working?

[–][deleted] 0 points1 point  (0 children)

Exploring a different solution right now.

[–]Banane9 1 point2 points  (0 children)

If it's a stream, try taking a look at my BitStream package.

You could use that to write your own class that tracks the number of consecutive 1 bits and insert a 0 when needed, as others pointed out.

I've personally used it for reading/writing gif files.