Changing Settings/Sending Settings Messages with Python

48 views
Skip to first unread message

James Dietrich

unread,
Jul 7, 2019, 11:26:59 PM7/7/19
to swiftnav-discuss
Hi all,

I'm getting a project going (a drone boat for river mapping) and I would like to be able to set off the standalone logging feature on my PiksiMulti with an event trigger (a physical switch on a GPIO pin).

I've the serial data stream reading part down (via the sample python script and some help from posts in this group), but I'm struggling with how to compose and send the settings message to enable standalone logging (or change any of the other settings).

I've been trying a few different things from sbp.settings.MsgSettingsWrite with no luck...If anyone has a lead on how this I would appreciate the pointers.

All I've found is some older messages:

My setup:
PiksiMulti (latest firmware)
Raspberry Pi 3B+ w/Raspbian Buster v4.19
 - also Windows 10
Python v3.7
SBP v2.6.5

Thanks,
James
--
Asst. Professor of Geography
University of Northern Iowa
Github: geojames
Message has been deleted

Pheoemph

unread,
Jul 10, 2019, 12:32:39 AM7/10/19
to swiftnav-discuss
Hi James,
         It might be easier to just turn off the logging locally.  You can just receive the decoded messages and only log when you turn it on with the GPIO.  Then you don't have to send a command to the piksi to turn on logging.  It is always spitting out GPS data, it even spits out data that is garbage... even telling you that it is garbage (invalid)....

I wrote a little program that just picks out the messages it wants to read instead of using the SBP library (which is kind of bloaty for a raspberry pi...)  and just logs what I want.... here is a clip...

The following assumes you have a serial connection open.   It will read 100 bytes into a rolling bytearray.   The data that is used is discarded an the rest of the array is added to on the next iteration.
You can add in a switch that starts or stops the logging and all this code works even better if you find a way to ASYNC it.

Hope that points you in a good direction.  

One thing to note is pikisi does things little endian... so in order to find 020C... I flipped the bytes to look for 0x0c 0x02 you'll notice it in the middle part, and in the struct.unpack.

Best of luck

data = b''
BIG_MSG = 45 #a size bigger than the longest msg we care to decode
PREAMBLE = 6 #this is the length of the preamble 0x55 plus the length and the message type bytes.
GPSTimeOfWeek = 0
while True:
            data += serialPort.read(100)
            
            while True:
                index = data.find(b"\x55") #the location of the first preamble byte
                #this line checks to see if there is enough data that it makes sense to even attempt to process the message.
if len(data) < index + BIG_MSG or index == -1:
                    continue
                
                length = data[index+5] #the length of the actual message

                output = ''
                msgType = data[index+1:index+3] #you can get these magic numbers from the SBP message specification
                
                #print("time: %s length: %s index: %s" % (struct.unpack('<i',data[index+6:index+10])[0], len(data), index))
                    
                if msgType == b"\x0c\x02":     #Rover NED's
                    output = {
                        'GPS_TimeOfWeek' : (struct.unpack('<i',data[index+6:index+10])[0]),#in milliseconds
                        'north' : struct.unpack('<i',data[index+10:index+14])[0]*0.001,
                        'east' : struct.unpack('<i',data[index+14:index+18])[0]*0.001,
                        #FIXFLAG is an enumeration for readability in the log... you can just put the number if you wish.
'fixmode' : FIXFLAG(data[index+27]).name
                    }
data = data[index+length+PREAMBLE:] #chop the data chunk we've already used.


Pheoemph

unread,
Jul 10, 2019, 1:05:59 AM7/10/19
to swiftnav-discuss
Ok... if you reaeeaaaaaally want to go about changing it programmatically to the piksi....

[preamble][msg type 0x00A0] [msglength] [msg] [CRC check]

\x55\xA0\x00 length of msg \0standalone_logging\0enable\01\0[crc check]

make sure you use little endian for the different portions

if you get the CRC check right which i don't know how to do yet...   that should work....

the above was taken from
Swift Navigation Binary Protocol Specification v2.6.3.pdf   pgs 78-79   AND pg 2 for CRC information and little endianness
and PiksiMulti-settings-v2.3.17.pdf      pg 5
which you can find here

best of luck
Reply all
Reply to author
Forward
0 new messages