How to monitor UDP from Flex 6x00

  • 1
  • Question
  • Updated 3 years ago
I have been able to write some Python code that sends and receives Telnet commands and status to my Flex 6300.  It appears that a lot of the info from the Flex comes over UDP.

This is probably a general UDP question, rather than a Flex specific one.

I have been able to open a UDP socket to the Flex, but I'm not sure I'm doing things right.

The IP address of my Flex that works fine for Telnet is 10.0.1.3, but when I try to bind a socket to 10.0.1.3 and port 4991 (or any port that I have tried), I get an error "The requested address is not valid in its context."

I can open a UDP connection using the IP address of my computer (10.0.1.5). If SmartSDR is running, I see UDP data, but the SSDR panadapter freezes. When I kill my Python app, the panadapter resumes. I assume my program is sucking up the data that the panadapter uses.

If I open a UDP connection without SmartSDR running, there is no data until I open a Telnet session and send a command to subscribe to something. This makes sense.

On a related note, once you have started subscribing to something, how do you stop?

73,
Mark
Photo of Mark Erbaugh

Mark Erbaugh

  • 371 Posts
  • 32 Reply Likes

Posted 3 years ago

  • 1
Photo of K6OZY

K6OZY, Elmer

  • 523 Posts
  • 193 Reply Likes
Wireshark is your friend.
Photo of Steve - N5AC

Steve - N5AC, VP Engineering

  • 1003 Posts
  • 965 Reply Likes
Mark, have you read through the wiki at wiki.flexradio.com?

To unsubscribe, you "unsub" instead of "sub"
Photo of Mark Erbaugh

Mark Erbaugh

  • 371 Posts
  • 32 Reply Likes
Steve,

Thanks for the reply. I had browsed the WIKI before, but either I missed some of it or now that I've dabbled with the API it makes more sense to me. It's definitely going to be helpful. I don't see UNSUB listed on the WIKI, though.
Photo of Larry da Ponte

Larry da Ponte

  • 158 Posts
  • 15 Reply Likes
Hi Mark - here is some sample Python code that is working for me on my Flex 6500.  The first example sends a command to the radio to tell it that my laptop is listening on UDP port 5000.  You can pick any unused UDP port on your PC because you will be telling the radio on which port you are listening.  For example, FlexLib starts out with listening on UDP port 4991 and if this fails it will incremnt the port and try again until it finds an unused port.  If you tried to use UDP port 4991 in your Python app that would conflict with the instance of SmartSDR if running on the same PC as your Python (possibly the cause - I didn't test this).  Make sure that when you are connecting to the radio to send a command, you are connecting to the radio's IP address which you could discover by looking at the settings dialog in SmartSDR or looking at the discovery UDP packets.  When you want to listen to UDP from the radio you have to tell the radio what IP address and port number you want the radio to send the UDP packets to.  My examples below are two seperate Python programs that are running at the same time.  If you start out by listening on UDP port 4992 you will see the Flex discovery protocol packets:

discovery_protocol_version=2.0.0.0 model=FLEX-6500 serial=2514-3157-6500-1623 version=1.3.8.47 nickname=HB9EYQ_6500 callsign=HB9EYQ ip=192.168.137.26 port=4992 status=Available

It is telling you what IP and port number the discovered radio is on.

When you run the UDP program below, it will wait for UDP packets from the radio, then, when you run the TCP program you will notice that the UDP program starts displaying a lot of hex data.  Now, depending on what TCP radio commands you send you can cause the radio to send you audio, IQ, waterfall, or meter data.

----------- TCP send command to radio ----------

__author__ = 'HB9EYQ'

import socket

RADIO_IP = "192.168.137.26" #IP of radio
RADIO_TCP_PORT = 4992
BUFFER_SIZE = 1024

tcpSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpSock.connect((RADIO_IP, RADIO_TCP_PORT))
tcpSock.send("C1|client udpport 5000\n".encode())

while 1:
data = tcpSock.recv(BUFFER_SIZE)
if not data: break
print("TCP:", data)

tcpSock.close() ---------- UDP listen for UDP from radio ------- __author__ = 'HB9EYQ'

import socket

CLIENT_IP = "192.168.137.1" #NIC on my laptop
CLIENT_UDP_PORT = 5000

BUFFER_SIZE = 1024

udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpSock.bind((CLIENT_IP, CLIENT_UDP_PORT))

print("Listening...")

while True:
data, addr = udpSock.recvfrom(1024)
print("UDP:", data)
-Larry
(Edited)
Photo of Larry da Ponte

Larry da Ponte

  • 158 Posts
  • 15 Reply Likes
Also, when you use the bind command what you are telling Python to do is bind to that IP on the local machine which, in this case, doesn't exist because that is the IP address of the radio, not the IP address on the PC where your Python is running.

Even though you are programming in Python, have a look through the FlexLib source as it will tell you how to set up the UDP, TCP, and how to interperate the UDP packet types then you could route them in your Python code by type.  See Radio.cs around line 740 for how the FlexLib splits out the different Vita packet types.
(Edited)
Photo of Mark Erbaugh

Mark Erbaugh

  • 371 Posts
  • 32 Reply Likes
Larry,

Thanks much for the code. I did discover the client udpport command on the wiki after my post.  I used Python's telnet lib for the TCP connection rather than using the socket directly.

Thanks for the pointer on Radio.cs. I have poked around in the code and seen some stuff that may be helpful. One of the reasons I am using Python is that I can use the command line to experiment quickly. I don't have to go through a compile / link phase every time I want to try something different.

73,
Mark
Photo of philip.theis

philip.theis, Elmer

  • 111 Posts
  • 19 Reply Likes
Mark,
I need to plug into this thread.  I have a Beaglebone talking to the API, decided to try Python; but am talking to it fine. It just seems so easy, BBB has Cloud9 IDE already set up ready to go.
Great idea to check the FlexLib code for examples.
Phil K3TUF