I know most won’t find this interesting but I thought I would mention a few things that bit me yesterday coding wise yesterday, in case it might help out others not run into the same problems that I did.
I wanted a quick and dirty function that would simply take a pointer to the string to pass back to the DIY receiver. For most of these I make the strings using BYTETABLES. Also to make it easy to modify the strings later and not forget to update the count of bytes, I decided to put the byte count at the beginning of the string instead of a second parameter. So for example when I wanted to pass the “Walking” to the other side the code looked like:
_WALKMODE bytetable 7, "Walking"
...
gosub ControlOutputString@_WALKMODE]
The control function grabbed the first byte from the pointer as the count and then incremented the pointer and then processed the string, by computing a checksum and sending the packet to the DIY.
Well next I wanted to do the different gaits. So first I defined the strings like above, but then I had an index number in the range 0-7
The strings looked like:
_GATENAME0 bytetable 8, "Ripple 6"
_GATENAME1 bytetable 9, "Ripple 12"
_GATENAME2 bytetable 12, "Quadripple 9"
_GATENAME3 bytetable 8, "Tripod 4"
_GATENAME4 bytetable 8, "Tripod 6"
_GATENAME5 bytetable 8, "Tripod 8"
_GATENAME6 bytetable 7, "Wave 12"
_GATENAME7 bytetable 7, "Wave 18"
I could have coded it with a bunch of if Gaittype= 0 then … Output _GateName0, but I don’t like that code. So next I tried to create some type of pointer table.
I was trying to do something like:
_GATENAMES POINTERTABLE @_GATENAME0, @_GATENAME1...
But Pointertable is not defined. I also tried LONGTABLE, but it complained about the @ was not a constant, although the generated address should be. I might be able to setup the table in assembly. May play with this later. Also I will ask Nathan (AcidTech) about this.
So I tried a different approach. That is set the pointer to the address of the first string, and then walk my way down the strings until I get the address of the one I want. That is if I want the address of the _GATENAME1, I grabbed the first byte that pointer is pointing to which was the count, then I added the count + 1 to the pointer and that should get me to the next string (I thought). It did not work so I converted to assembly language, which still does not work. After debugging this, I found out that, the above BYTETABLE entries does not generate the same bytes as:
_GATENAMES bytetable 8, "Ripple 6",|
9, "Ripple 12",|
12, "Quadripple 9",|
8, "Tripod 4",|
8, "Tripod 6",|
8, "Tripod 8",|
7, "Wave 12",|
7, "Wave 18"
It turns out that the BYTETABLE may add an extra byte with a value of 0 to align things. So once my strings were converted into one bytetable it worked!
Again excuse this boring post
Kurt