Working on a Raw Data Out app...

Status
Not open for further replies.

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
I decompiled the Raw Audio sample app Uniden included with their downloads. I added a second drop-down box for an Output port, and installed com0com which allows this app to write to a port, and allow another application to connect to com0com's output port to read it (in short, it creates a virtual serial port/device).

So far, the connection is working, and I can see the data from my app going into COM11 (com0com's input) and coming out on COM15 (com0com's output). All I'm doing right now is passing the AdValue (I assume, based on the code, that AdValue is the high and low byte pushed together?) straight through:

Code:
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.serialPort1.BytesToRead > 0)
            {
                int bytesToRead = this.serialPort1.BytesToRead;
                byte[] numArray = new byte[bytesToRead];
                this.serialPort1.Read(numArray, 0, bytesToRead);

                for (int i = 0; i < (int) numArray.Length; i++)
                {
                    if ((numArray[i] & 128) != 0)
                    {
                        this.HighByte = numArray[i];
                        continue;
                    }
                    if ((this.HighByte & 128) != 0)
                    {
                        if (this.serialPort2.IsOpen)
                        {
                            var adElement = new AdElement(DateTime.Now, this.HighByte, numArray[i]);
                            var u = BitConverter.GetBytes(adElement.AdValue);

                            this.serialPort2.Write(u, 0, u.Length);
                        }
                        this.AdDatabs.Append(this.HighByte, numArray[i]);
                    }
                }
                this.pictureBox1.Refresh();
                if (this.buttonLog.Text == "Logging" && !this.AdDatabs.IsLogging())
                {
                    this.buttonLog.Text = "Log";
                    MessageBox.Show("Log reached  65,535 lines.\nLoggin finish");
                }
            }
        }

Am I correct to pass the AdValue straight through as soon as the High Byte and Low Byte are both defined? I'm new to this kind of stuff, but really want to start harnessing this power and perhaps provide a universal tool that translates Uniden's output into straight RS-232 discrim data.

I also noticed it outputs random stuff even when there is no carrier - is it supposed to be like this? Again, I'm new to all this, so forgive me. :)
 
Last edited:

OCO

Member
Joined
Jul 17, 2011
Messages
928
Location
Central Michigan
That's baseband audio, unsquelched.....you're seeing air noise..
Note that Unitrunker is waiting for some of the same info as you are....I'm sure it will be published for all.
 

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
1. stylistic comment ...

Try using ...

Code:
foreach (byte bee in numArray)
{
// code block
}

instead of ...

Code:
for (int i = 0; i < (int) numArray.Length; i++)
{
// code block
}

2. "var" abuse.

Don't use var unless actually needed (like a LINQ expression). In the code you've posted, the actual types byte[] and AdElement do just fine.

3. logic

Your loop assumes alternating high/low bytes.

a. What happens when you get two consecutive high bytes?
b. What happens when you get two consecutive low bytes?

These can actually happen in the data.

Am I correct to pass the AdValue straight through as soon as the High Byte and Low Byte are both defined?
I have no idea what adDatabs is or does so I can't comment.

Good luck.
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
I'm a fairly seasoned programmer of 15 years, but not for hardware at all, and the code is directly decompiled from Uniden's sample apps with only a couple modifications from me. ;) AdDatabs is, I assume, a class that handles the current buffer of received data from the HP. My code isn't assuming alternating high/low - theirs is. :)

I guess now I'm venturing into the 4-level territory too. No idea what I'm doing really, so I'll probably leave it to those who know how. It's been fun to dig into anyway. I just can't wrap my head around it. Looks like whoever puts something together will have an easy time of it though:

4fsk.png
 
Last edited:

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
Also, interesting find: if you launch raw data output and then start scanning, you can use the AD signals outside of the HP's Raw Data window.
 

Kumba

Member
Premium Subscriber
Joined
Apr 9, 2008
Messages
258
Location
Indian Head, MD
1. stylistic comment ...

Try using ...

Code:
foreach (byte bee in numArray)
{
// code block
}

instead of ...

Code:
for (int i = 0; i < (int) numArray.Length; i++)
{
// code block
}

Minor, but 'foreach' is a tad slower than 'for' because it has to enumerate a collection, rather than iterating through all of the items in a collection by direct index. You really never notice it, however, unless constantly executing said loop over and over again.
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
Okay I charted the AdValues periodically along the 'oscilloscope'. Looks like AdValue (the byte currently in question, converted to a short) is indeed the proper number to be passing along, no? And a piece of software should read these bytes properly? Only things left, I think, is setting the sample rate, and tweaking the buffer sizes, etc (all the little things), which we're still waiting on Uniden for.

AdValue is calculated like so:

Code:
        // where h = high byte and l = low byte
        ushort num = (ushort)((h & 31) << 5 | l & 31);
        if ((h & 16) != 0)
        {
            num = (ushort)(num | 64512);
        }
        this.AdValue = (short)num;

Here's a 9600 baud P25 CC:

4fsk1.png
 
Last edited:

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
Minor, but 'foreach' is a tad slower than 'for' because it has to enumerate a collection
That's why I use C++ for this sort of thing. I'm surprised Uniden did "Any" builds instead of x86 builds of their sample apps.
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
Sample rate is 38.4 kHz

Excellent.

So, for UPMan or anyone who can answer, is there a way to use my "virtual serial port" idea for sending the AdValue (+/- 255) to a software app such as PDW? It currently sends the High and Low byte (just as the scanner sends it to me), but PDW doesn't recognize it of course. I also tried sending AdValue as a byte, but since AdValue can be negative, I'm not sure how to send a negative value.

I have a low-power ham-band pager transmitter (POCSAG and FLEX up to 6400). PDW decodes 2-level data in soundcard mode, but nothing in RS232 mode, and I'd like to get it to decode 4-level FSK.

Basically, my goal is to create a software data slicer. Is this even possible?
 

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
What Uniden should have done was use a virtual audio driver for the sampled data.

I think the PCR1500/2500 offers this (but sadly not discriminator audio) as do some of the WinRadios and other SDR models.

All existing sound-card applications would be plug-n-play with no modifications necessary.

To emulate a traditional two level slicer you will need to toggle the CTS, DCD, or DSR pins in your virtual serial port. The TxD/RxD pins aren't involved. That requires accurate timing that's difficult to do in a user mode application. Emulating a four level slicer requires driving all three pins. In short, a virtual audio device would be easier.

There are two external gadgets close to what you're trying to do. Both use a micro-controller. Cost is $40 to $100.

1. There is a "smart" slicer that includes a microcontroller. It provides a bit stream from discriminator audio. The data is sent in 8 bit chunks over the RxD (host) / TxD pins (slicer). You could pursue emulating this device (with little modification to your program). However, PDW is the only app supporting this device that I know so your audience is small.

RS-232 Interface

I can't speak for Peter Hunt but I suspect (shameless speculation) PDW will add native HP-1 support soon - if only because it isn't difficult.

2. Arduino Bitstream device (as a single channel - the bitstream supports multiple). This is open source software run on the Arduino UNO - a COTS microcontroller. However, the Bitstream is so new that no one is using it yet (a work in progress for Unitrunker).

Some digressions ...

It would be nice to see DSD modified to talk to the HP-1 over /dev/ttyS0 (which would also sidestep the audio device driver compatibility problem in Ubuntu 10.8 and later).

For grins I should dig up the Windows version of Trunker 3.83 hacked to run on Windows 2000 (vintage 2003 or 2004) with a buggy WDM slicer driver - rip out the slicer code - drop in some HP-1 specific code. Forget that - Eric Cottrell needs to extend his Windows versions of Trunker to operate with an HP-1.

In conclusion, if you could pipe the data as 16 bit audio samples to a virtual audio port - that would instantly make many existing applications HP-1 compatible.
 
Last edited:

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
Sample rate is 38.4 kHz
Thank you sir. For those wondering, while that may sound like an odd sample rate - it works well for P25 and narrow EDACS (8 samples per symbol) as well as EDACS wide (4 samples per symbol). Motorola gets 10.6 samples per symbol (oh well). POCSAG works out to 16, 32, or 64 samples per symbol. Even FLEX scores 24 or 12 samples per symbol. Compare to standard 44.1khz - at least some protocols are "square" with the sample rate.
 
Last edited:

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
What Uniden should have done was use a virtual audio driver for the sampled data.

I think the PCR1500/2500 offers this (but sadly not discriminator audio) as do some of the WinRadios and other SDR models.

All existing sound-card applications would be plug-n-play with no modifications necessary.

To emulate a traditional two level slicer you will need to toggle the CTS, DCD, or DSR pins in your virtual serial port. The TxD/RxD pins aren't involved. That requires accurate timing that's difficult to do in a user mode application. Emulating a four level slicer requires driving all three pins. In short, a virtual audio device would be easier.

There are two external gadgets close to what you're trying to do. Both use a micro-controller. Cost is $40 to $100.

1. There is a "smart" slicer that includes a microcontroller. It provides a bit stream from discriminator audio. The data is sent in 8 bit chunks over the RxD (host) / TxD pins (slicer). You could pursue emulating this device (with little modification to your program). However, PDW is the only app supporting this device that I know so your audience is small.

RS-232 Interface

I can't speak for Peter Hunt but I suspect (shameless speculation) PDW will add native HP-1 support soon - if only because it isn't difficult.

2. Arduino Bitstream device (as a single channel - the bitstream supports multiple). This is open source software run on the Arduino UNO - a COTS microcontroller. However, the Bitstream is so new that no one is using it yet (a work in progress for Unitrunker).

Some digressions ...

It would be nice to see DSD modified to talk to the HP-1 over /dev/ttyS0 (which would also sidestep the audio device driver compatibility problem in Ubuntu 10.8 and later).

For grins I should dig up the Windows version of Trunker 3.83 hacked to run on Windows 2000 (vintage 2003 or 2004) with a buggy WDM slicer driver - rip out the slicer code - drop in some HP-1 specific code. Forget that - Eric Cottrell needs to extend his Windows versions of Trunker to operate with an HP-1.

In conclusion, if you could pipe the data as 16 bit audio samples to a virtual audio port - that would instantly make many existing applications HP-1 compatible.
I w

I was actually trying to do just that - switch the CTS/DCD/DSR pins, but it requires a low-level control of the port and there are so many variables that play into it that I want to get it right. I also worry about .NET's ability to do these things in a proper manner to cause the expected interpretations. I may have to delve a little deeper and write something in C.

Of course, I can completely imagine someone else writing this up in the next couple months and getting it out there, but I'd have loved to be the pioneer! So far, it's definitely possible. .NET just doesn't let me control the serial port enough, though, so I will look into it further.

If anyone has any schematics of how to convert discriminator data into data compatible with a slicer, please reply! :) I have a feeling it will involve some measurement of the overall signal strength, and when it comes to 2/4 level, will involve some sort of averaging to activate the appropriate pins when deemed necessary.

The replies so far though, haven't discouraged me! :)
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
We are also still very early in the raw output developments of the HP, that someone could come up with something amazing, so don't lose hope just yet! After diving into the code and seeing what is possible, the fact remains that the output is really open-ended and there are limitless opportunities to manipulate the data! I don't know if I'm the man for the job but thus far, the possibilities are limitless.
 
D

DaveNF2G

Guest
Still need LTR Multinet and PassPort tracking so I can stop running MS-DOS on an old laptop.
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
Still need LTR Multinet and PassPort tracking so I can stop running MS-DOS on an old laptop.

I'm not writing a trunking app - just trying to write an app that would emulate a data slicer to allow other apps to work with the HP's discrim output. You can use DR DOS or DOSBOX though if you need old DOS apps to run in newer versions of Windows (Vista and 7 especially).

Unitrunker, thanks for the link to that. I saw that, I am looking for more of an explanation as to which pins are fired when (and why, etc). I'm pretty new to this kinda stuff, so I really have no business even trying, but it's still fun to try to figure it out. :)
 

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
Unitrunker, thanks for the link to that. I saw that, I am looking for more of an explanation as to which pins are fired when (and why, etc). I'm pretty new to this kinda stuff, so I really have no business even trying, but it's still fun to try to figure it out. :)
See the two diodes on the four level circuit? Each feeds a capacitor. The polarity of one diode / capacitor pair is reversed. The forward diode / capacitor acts as a positive peak detector. The reverse diode / capacitor pair acts as a negative peak detector. These two peaks define a voltage span for the working signal. A resistor ladder splits this voltage span into three reference voltages that represent the transition between the four symbol voltage levels. A comparator is the analog equivalent of the compare instruction on most processors. If the + input pin is greater than the - pin, the output swings from low to high to drive the appropriate RS232 pin.

For the two level circuit, all you need is one comparator (or an op amp with enough voltage gain to swing +/- 5 volts or more).
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
Cool. I assume for a 4-level I need some sort of running average to detect where the extra 2 levels might be. Now I just need to find some sort of low-level software serial port manipulator where I can switch the pins, or modify a hardware slicer to accept Uniden's serial data instead of discriminator audio. Interesting stuff.
 

rfaricy

Member
Joined
Mar 8, 2004
Messages
150
Location
Gulfport, FL
Here's the project in case anyone wants to look into all this more. I think I'm venturing beyond my abilities here, but want to offer this up in case anyone wants to fiddle with it more.
http://rfaricy.dyndns.org/RawData.rar

Please note I did not write this app - this was created by Uniden, and they will not support it. I can help where I can, but my knowledge surrounding this stuff is limited. I've simply modified some code here and there.

I've enlarged the graph (might be huge on a non-widescreen monitor), and added 1-second discriminator audio output samples to the soundcard via DirectSound.

It requires Visual Studio 2010, and com0com (or something similar) if you want to forward the output to another virtual serial port.
 
Last edited:
Status
Not open for further replies.
Top