I tried harder and understood that MAVLink packets starts with 0xfe so I started syncronizing my buffer with the received messages both from APM and mission planner. At my serial-UDP converting script I had messages like these ones:
sent message: fe1af801019b1141de36000000000600830017fcfdff000003000000000080006acb
sent message: fe1cf981011e0f954f0016aba3bb3309a8bb94a29c3ec868ddb9a4cb9eb9667158bbdbe2
sent message: fe94fa81014a0080000000008080666642410080000011005d803aeb
sent message: fe9cfb8101213595cf00000000008080000098bdfffff62f0000000080000000d906f5d1age: fe15ec010124c4c8db368007d885ac03d8050f06d885d805840300d219
received message: fe09b9fc0100000000000608c004038468
sent message: fe16ed0101a3ec944f008007d885ac03d8050f86d805d805840380809135
sent message: fe1fee010101a3dca0002380200003dc200070018000ffff000000808000000080000000ff40e4
sent message: fe04ef0101983f1a7585eca7
sent message: fe02f001812a0000cd66
sent message: fe9ef101011800008000000000000000008000000000d8bdffff0f27ffff000000800100d063
sent message: fe09f2810100000000000a03c10483e759
sent message: fe1cf301019ea9944f001e71a3fbcae3a73b997b9cbec8e8ddb9c05df0b890e1693b625c
sent message: fe14f401014a80000000008000005c8f42c18000000011805d001345
sent message: fe1cf50101a352e0cb3ba41692ba2c50d1b60000000080000000e8c5bdb9000080bfd3c1
sent message: fe03f60101a51b920136fc
sent message: fe0cf70181820000008000000000d1944f0006da
sent message: fe1af801019b1141de36000000000600830017fcfdff000003000000000080006acb
sent message: fe1cf981011e0f954f0016aba3bb3309a8bb94a29c3ec868ddb9a4cb9eb9667158bbdbe2
sent message: fe94fa81014a0080000000008080666642410080000011005d803aeb
sent message: fe9cfb8101213595cf00000000008080000098bdfffff62f0000000080000000d906f5d1
I can interpret these messages now with information from https://en.wikipedia.org/wiki/MAVLink#Packet_Structure and http://mavlink.org/messages/common so I think now I do it right - but what happens is mission planner indicates connection for a very short period of time.
What else shall I take into account, please? What are the requirements for mission planner to consider APM link proper?
Thank you in advance for any hints
The script I do it with now is:
#!/usr/bin/env python
import socket
import serial
import sys
import fcntl
import struct
import math
import os
import errno
import time
from threading import Thread
GSC_address = ‘192.168.6.129’
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack(‘256s’, ifname[:15])
)[20:24])
def tty2UDP():
SerialTXbuffer = bytearray()
while(1):
for x in ser.read():
if ( x == ‘\xfe’ ):
# send the buffer, clear it and add this Byte to it
sock.sendto(SerialTXbuffer, (GSC_address, 14550))
#print ‘sent message: ‘, ‘’.join(’{:02x}’.format(z) for z in SerialTXbuffer)
SerialTXbuffer = bytearray()
SerialTXbuffer.append(x)
else:
# just add the Byte to the buffer
SerialTXbuffer.append(x)
ser.close()
exit -1
def UDP2tty():
SerialRXbuffer = bytearray()
while(1):
t, addr = sock.recvfrom(512)
if (t !=’’):
for tx in t:
if ( tx == ‘\xfe’ ):
# send the buffer, clear it and add this Byte to it
ser.write(SerialRXbuffer)
#print ‘received message: ‘, ‘’.join(’{:02x}’.format(z) for z in SerialRXbuffer)
SerialRXbuffer = bytearray()
SerialRXbuffer.append(tx)
else:
# just add the Byte to the buffer
SerialRXbuffer.append(tx)
else:
print 'no input from GCS to be sent to APM '
ser.close()
exit -1
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ser = serial.Serial(’/dev/ttyUSB0’, 57600, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False)
ser.flushInput()
ser.flushOutput()
SerialRXThread = Thread(target=tty2UDP)
SerialRXThread.start()
#SerialRXThread.join()
UDP2tty()
SerialTXThread = Thread(target=UDP2tty)
#SerialTXThread.start()
#SerialTXThread.join()