ardupilot/Tools/ArdupilotMegaPlanner/mavlinklist.pl
Michael Oborne 39640e8d94 APM Planner 1.0.69
prep for ac2 2.0.43 - simple mode
modify some scaling in Config
add hud speed warning. add link quality and time to HUD
fix ac2 logs, relative alt.
prep for mavlink 1.0
add time to tlog > plain text conversion
2011-09-17 21:22:07 +08:00

133 lines
2.8 KiB
Perl

$dir = "C:/Users/hog/Documents/Arduino/libraries/GCS_MAVLink/include/common/";
$dir2 = "C:/Users/hog/Documents/Arduino/libraries/GCS_MAVLink/include/ardupilotmega/";
# mavlink 1.0 with old structs
#$dir = "C:/Users/hog/Desktop/DIYDrones&avr/ardupilot-mega/libraries/GCS_MAVLink/include/common/";
#$dir2 = "C:/Users/hog/Desktop/DIYDrones&avr/ardupilot-mega/libraries/GCS_MAVLink/include/ardupilotmega/";
opendir(DIR,$dir) || die print $!;
@files2 = readdir(DIR);
closedir(DIR);
opendir(DIR,$dir2) || die print $!;
@files = readdir(DIR);
closedir(DIR);
push(@files,@files2);
push(@files,"../mavlink_types.h");
open(OUT,">MAVLinkTypes.cs");
$crcs = 0;
print OUT <<EOF;
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ArdupilotMega
{
partial class MAVLink
{
EOF
foreach $file (@files) {
print "$file\n";
if ($done{$file} == 1) {
next;
}
$done{$file} = 1;
open(F,$dir.$file) || open(F,$dir2.$file);
$start = 0;
while ($line = <F>) {
if ($line =~ /(MAVLINK_MESSAGE_LENGTHS|MAVLINK_MESSAGE_CRCS) (.*)/ && $crcs < 2) {
print OUT "\t\tpublic byte[] $1 = new byte[] $2;\n";
$crcs++;
}
if ($line =~ /enum (MAV_.*)/) {
$start = 1;
print OUT "\t\tpublic ";
}
if ($line =~ /#define (MAVLINK_MSG_ID[^\s]+)\s+([0-9]+)/) {
print OUT "\t\tpublic const byte ".$1 . " = " . $2 . ";\n";
$no = $2;
}
if ($line =~ /typedef struct(.*)/) {
if ($1 =~ /__mavlink_system|param_union/) {
last;
}
$start = 1;
print OUT "\t\t[StructLayout(LayoutKind.Sequential,Pack=1)]\n";
#__mavlink_gps_raw_t
$structs[$no] = $1;
}
if ($start) {
$line =~ s/MAV_CMD_NAV_//;
$line =~ s/MAV_CMD_//;
$line =~ s/typedef/public/;
$line =~ s/uint8_t/public byte/;
$line =~ s/int8_t/public byte/;
$line =~ s/^\s+float/public float/;
$line =~ s/uint16_t/public ushort/;
$line =~ s/uint32_t/public uint/;
$line =~ s/uint64_t/public ulong/;
$line =~ s/int16_t/public short/;
$line =~ s/int32_t/public int/;
$line =~ s/int64_t/public long/;
$line =~ s/typedef/public/;
$line =~ s/}.*/};\n/;
if ($line =~ /\[(.*)\].*;/) { # array
print OUT "\t\t[MarshalAs(
UnmanagedType.ByValArray,
SizeConst=". $1 .")] \n";
$line =~ s/\[.*\]//;
$line =~ s/public\s+([^\s]+)/public $1\[\]/o;
}
print OUT "\t\t".$line;
}
if ($line =~ /}/) {
$start = 0;
}
}
close(F);
}
print OUT "Type[] mavstructs = new Type[] {";
for ($a = 0; $a <= 256;$a++)
{
if (defined($structs[$a])) {
print OUT "typeof(".$structs[$a] .") ,";
} else {
print OUT "null ,";
}
}
print OUT "};\n\n";
print OUT <<EOF;
}
}
EOF
close OUT;
<STDIN>;
1;