2011-12-17 18:50:40 -04:00
|
|
|
$dir = "C:/Users/hog/Desktop/DIYDrones/ardupilot-mega/libraries/GCS_MAVLink/include/common/";
|
|
|
|
$dir2 = "C:/Users/hog/Desktop/DIYDrones/ardupilot-mega/libraries/GCS_MAVLink/include/ardupilotmega/";
|
|
|
|
|
|
|
|
$fname = "MAVLinkTypes0.9.cs";
|
|
|
|
|
|
|
|
&doit();
|
2011-09-17 10:22:07 -03:00
|
|
|
|
|
|
|
# mavlink 1.0 with old structs
|
2011-11-08 09:22:07 -04:00
|
|
|
$dir = "C:/Users/hog/Desktop/DIYDrones/ardupilot-mega/libraries/GCS_MAVLink/include_v1.0/common/";
|
|
|
|
$dir2 = "C:/Users/hog/Desktop/DIYDrones/ardupilot-mega/libraries/GCS_MAVLink/include_v1.0/ardupilotmega/";
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-12-17 18:50:40 -04:00
|
|
|
$fname = "MAVLinkTypes.cs";
|
|
|
|
|
2012-03-06 06:27:43 -04:00
|
|
|
#&doit();
|
2011-12-17 18:50:40 -04:00
|
|
|
|
|
|
|
<STDIN>;
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
sub doit
|
|
|
|
{
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
opendir(DIR,$dir) || die print $!;
|
2011-09-17 10:22:07 -03:00
|
|
|
@files2 = readdir(DIR);
|
|
|
|
closedir(DIR);
|
|
|
|
|
|
|
|
opendir(DIR,$dir2) || die print $!;
|
2011-09-08 22:31:32 -03:00
|
|
|
@files = readdir(DIR);
|
|
|
|
closedir(DIR);
|
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
push(@files,@files2);
|
|
|
|
|
|
|
|
|
|
|
|
push(@files,"../mavlink_types.h");
|
|
|
|
|
2011-12-17 18:50:40 -04:00
|
|
|
open(OUT,">$fname");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
$crcs = 0;
|
|
|
|
|
2011-12-17 18:50:40 -04:00
|
|
|
%done = {};
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
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) {
|
2011-09-17 10:22:07 -03:00
|
|
|
print "$file\n";
|
|
|
|
|
|
|
|
if ($done{$file} == 1) {
|
2011-09-08 22:31:32 -03:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
$done{$file} = 1;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
open(F,$dir.$file) || open(F,$dir2.$file);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
$start = 0;
|
|
|
|
|
|
|
|
while ($line = <F>) {
|
2011-09-17 10:22:07 -03:00
|
|
|
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_.*)/) {
|
2011-09-08 22:31:32 -03:00
|
|
|
$start = 1;
|
2011-09-17 10:22:07 -03:00
|
|
|
print OUT "\t\tpublic ";
|
2011-09-08 22:31:32 -03:00
|
|
|
}
|
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
if ($line =~ /#define (MAVLINK_MSG_ID[^\s]+)\s+([0-9]+)/) {
|
2011-11-08 09:22:07 -04:00
|
|
|
if ($line =~ /MAVLINK_MSG_ID_([0-9]+)_LEN/) {
|
|
|
|
next;
|
|
|
|
} else {
|
|
|
|
print OUT "\t\tpublic const byte ".$1 . " = " . $2 . ";\n";
|
|
|
|
$no = $2;
|
|
|
|
}
|
2011-09-17 10:22:07 -03:00
|
|
|
}
|
|
|
|
if ($line =~ /typedef struct(.*)/) {
|
|
|
|
if ($1 =~ /__mavlink_system|param_union/) {
|
|
|
|
last;
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
$start = 1;
|
2011-09-17 10:22:07 -03:00
|
|
|
print OUT "\t\t[StructLayout(LayoutKind.Sequential,Pack=1)]\n";
|
2011-09-08 22:31:32 -03:00
|
|
|
#__mavlink_gps_raw_t
|
2011-09-17 10:22:07 -03:00
|
|
|
$structs[$no] = $1;
|
2011-09-08 22:31:32 -03:00
|
|
|
}
|
2011-09-17 10:22:07 -03:00
|
|
|
if ($start) {
|
|
|
|
$line =~ s/MAV_CMD_NAV_//;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
$line =~ s/MAV_CMD_//;
|
2011-10-04 08:19:25 -03:00
|
|
|
|
|
|
|
$line =~ s/\/\/\/</\/\/\//;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
$line =~ s/typedef/public/;
|
|
|
|
$line =~ s/uint8_t/public byte/;
|
|
|
|
$line =~ s/int8_t/public byte/;
|
2011-11-08 09:22:07 -04:00
|
|
|
$line =~ s/char/public byte/;
|
2011-09-17 10:22:07 -03:00
|
|
|
$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/;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
$line =~ s/}.*/};\n/;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
if ($line =~ /\[(.*)\].*;/) { # array
|
|
|
|
print OUT "\t\t[MarshalAs(
|
|
|
|
UnmanagedType.ByValArray,
|
|
|
|
SizeConst=". $1 .")] \n";
|
|
|
|
$line =~ s/\[.*\]//;
|
|
|
|
$line =~ s/public\s+([^\s]+)/public $1\[\]/o;
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
print OUT "\t\t".$line;
|
|
|
|
}
|
|
|
|
if ($line =~ /}/) {
|
2011-09-08 22:31:32 -03:00
|
|
|
$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;
|
|
|
|
|
2011-12-17 18:50:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-17 10:22:07 -03:00
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
1;
|