Hex Packets for radio configuration.
billiam2536
Posts: 28
I'm trying to communicate with a DNT900 radio by RFM, and in protocol mode it uses hexadecimal packets, and I really just have no idea where to start. How do I send a packet, such as "0xFB 0x04 0x03 ..." to the radio from the propeller? I am COMPLETELY lost.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
Comments
How you send a packet depends on what the radio expects. Presumably it's some kind of asynchronous serial stream. You need to provide a manual that describes the Baud, how many bits of data, how many stop bits, whether parity is expected or provided. Typically for this sort of thing, there are 8 bits of data, no parity, and 1 stop bit used. The Baud could be anything.
Start with the manual for the radio. There are a variety of ways to send asynchronous serial data. Look at Simple_Serial from the Object Exchange. Also look at FullDuplexSerial which comes with the Propeller Tool. There are demo programs that come with each of these and illustrate the basics of how to use them. Also read the comments in each. Library objects are often documented in the comments in the object's source.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
Post Edited (billiam2536) : 2/28/2010 10:45:00 PM GMT
obex.parallax.com/objects/146/
Of course you will need to study the documents of your device so you can frame your packets as necessary.
--Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
Note that FB is just a hexadecimal representation for the binary number 11111011 which is also equivalent to decimal 251. The dollar sign indicates it is shown as hexadecimal. The binary would be represented by a preceding percent sign, %11111011
What you need to do is to first load the two mentioned library files (and initialize appropriately). Then you can convert the human readable string "FB" into its numeric value using the Numbers object. This value (a single byte) would then be sent to your radio via the serial object. Next you would convert and send "04", then "03" and so on. Or you can convert them first then send the group of bytes. Whatever your radio is expecting is important here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
Firstly, hex vs decimal, I tend to use the Windows Calculator a lot. If you set it to scientific mode it can do hex to decimal with one keypress. So $FB is decimal 251.
Next thing is the simple serial object. I'm a bit confused myself here. The decimal method seems straightforward:
I think you just send it 251, or a variable whose value is 251.
But the hex method is confusing;
For a two byte value I think it is sending two bytes rather than one, as it has 'repeat digits' So if you send it $FB I think it is going to send decimal 70 then decimal 66. Maybe I'm wrong there, but until someone clarifies perhaps stick to decimal numbers and do the conversion in a calculator.
Also, I'm sure there is a way of converting hex to decimal in spin. In basic it is
a=val("&HFB")
(which muddies the waters more as there are at least 4 different hex prefixes/suffixes I can think of - &H at the beginning, H at the end, 0x at the beginning and $ at the beginning).
Serial is hard to do if you can't see what you are doing, especially with values that don't display on a terminal. Decimal 65 (hex 0x41) is fine as it prints A but decimal 01 may not print anything. I've found it helps to have some simple code to output bytes from a PC - eg a few lines of vb.net, plus a serial line monitor program so you can see bytes going out and bytes coming back. Even debugging the propeller it helps to have a serial monitor program - eg program the propeller to output a byte every few seconds (eg A) then run a terminal program on a PC and a serial port monitor program for good measure and watch the bytes come through. The propeller terminal program I think can do the heavy lifting there.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Dr. Acula, the hex function sends two bytes because it is printing the hex value over the serial connection, not sending the value. It is sending an F and then a B using the ascii values of those characters. That is what the lookupz function is for.
The Propeller Tool will recognize $FB as its hex value, no conversion to decimal is necessary.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Not the fish.
sites.google.com/site/bitwinproject/
Without going into analysis of the protocol, their definition of "packet" is a short burst of bytes being sent to or from the radio.
The contents of this packet of bytes determines what you want to tell the radio or what the radio is telling you. You will need to
understand the series of bytes necessary to send your desired command, then also listen to the serial port for information
being sent back from the radio.
Your packet or command string needs to be in a proper format for the radio to understand what you're sending. That's why the
first byte is always a $FB byte indicating the start-of-packet. The second byte tells it how many bytes in your packet so it
knows what to expect. This is used to determine if the whole packet made it -- a sort of error detection.
Here's a very basic program that will do nothing but send "Hello World" to your radio as described in the example in section 4.1.5
of your manual.
Your radio should ACK (acknowledge) this packet with the following string of bytes if received correctly
$FB $06 $15 $00 $02 $01 $00 $C4
but this program isn't listening for any response.
Notice the SOP character at the beginning, then the number 6 showing there will be six characters in the rest of the message.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page
Post Edited (w8an) : 3/1/2010 2:39:47 AM GMT
Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page