diff --git a/.cproject b/.cproject deleted file mode 100644 index b0c8d5a9dd..0000000000 --- a/.cproject +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - make - all - true - true - true - - - make - - clean - true - true - true - - - make - - distclean - true - true - true - - - make - - upload - true - true - true - - - make - - install - true - true - true - - - - diff --git a/.gitignore b/.gitignore index 8d468a56da..40957d3fb8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ .depend .config .version +.project +.cproject apps/namedapp/namedapp_list.h apps/namedapp/namedapp_proto.h Make.dep @@ -35,3 +37,4 @@ Firmware.sublime-workspace .DS_Store nsh_romfsimg.h cscope.out +.configX-e diff --git a/.project b/.project deleted file mode 100644 index 62e37139e4..0000000000 --- a/.project +++ /dev/null @@ -1,135 +0,0 @@ - - - PX4 Firmware - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.autoBuildTarget - all - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.fullBuildTarget - all - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - 1344101890673 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-false-*.o - - - - 1344101890683 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-false-.dep - - - - 1344101890687 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-false-.context - - - - 1344101890691 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-false-.depend - - - - 1344101890695 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-false-.built - - - - 1344101890698 - - 6 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-false-false-*.a - - - - diff --git a/Debug/NuttX b/Debug/NuttX index b6d4e74f05..8257335547 100644 --- a/Debug/NuttX +++ b/Debug/NuttX @@ -73,6 +73,30 @@ document showheap . Prints the contents of the malloc heap(s). end +################################################################################ +# Task file listing +################################################################################ + +define showfiles + set $task = (struct _TCB *)$arg0 + set $nfiles = sizeof((*(struct filelist*)0).fl_files) / sizeof(struct file) + printf "%d files\n", $nfiles + set $index = 0 + while $index < $nfiles + set $file = &($task->filelist->fl_files[$index]) + printf "%d: inode %p f_priv %p\n", $index, $file->f_inode, $file->f_priv + if $file->f_inode != 0 + printf " i_name %s i_private %p\n", &$file->f_inode->i_name[0], $file->f_inode->i_private + end + set $index = $index + 1 + end +end + +document showfiles +. showfiles +. Prints the files opened by a task. +end + ################################################################################ # Task display ################################################################################ @@ -137,8 +161,8 @@ end # define _showsemaphore printf "count %d ", $arg0->semcount - if $arg0->hlist.holder != 0 - set $_task = (struct _TCB *)$arg0->hlist.holder + if $arg0->holder.htcb != 0 + set $_task = (struct _TCB *)$arg0->holder.htcb printf "held by %s", $_task->name end printf "\n" diff --git a/Firmware.sublime-project b/Firmware.sublime-project index 47f8ff732e..a316ae2fa7 100644 --- a/Firmware.sublime-project +++ b/Firmware.sublime-project @@ -10,16 +10,21 @@ ".built", ".context", ".depend", + ".config", + ".version", "Make.dep", ".configured", "*.sublime-project", "*.sublime-workspace", ".project", - ".cproject" + ".cproject", + "cscope.out" ], "folder_exclude_patterns": [ - ".settings" + ".settings", + "nuttx/arch/arm/src/board", + "nuttx/arch/arm/src/chip" ] } ], diff --git a/ROMFS/Makefile b/ROMFS/Makefile index 6437a1e974..56ae63d271 100644 --- a/ROMFS/Makefile +++ b/ROMFS/Makefile @@ -21,11 +21,15 @@ ROMFS_FSSPEC := $(SRCROOT)/scripts/rcS~init.d/rcS \ $(SRCROOT)/scripts/rc.standalone~init.d/rc.standalone \ $(SRCROOT)/scripts/rc.PX4IO~init.d/rc.PX4IO \ $(SRCROOT)/scripts/rc.PX4IOAR~init.d/rc.PX4IOAR \ + $(SRCROOT)/scripts/rc.FMU_quad_x~init.d/rc.FMU_quad_x \ $(SRCROOT)/mixers/FMU_pass.mix~mixers/FMU_pass.mix \ $(SRCROOT)/mixers/FMU_delta.mix~mixers/FMU_delta.mix \ $(SRCROOT)/mixers/FMU_AERT.mix~mixers/FMU_AERT.mix \ $(SRCROOT)/mixers/FMU_AET.mix~mixers/FMU_AET.mix \ - $(SRCROOT)/mixers/FMU_RET.mix~mixers/FMU_ERT.mix + $(SRCROOT)/mixers/FMU_RET.mix~mixers/FMU_ERT.mix \ + $(SRCROOT)/mixers/FMU_quad_x.mix~mixers/FMU_quad_x.mix \ + $(SRCROOT)/mixers/FMU_quad_+.mix~mixers/FMU_quad_+.mix \ + $(SRCROOT)/logging/logconv.m~logging/logconv.m # # Add the PX4IO firmware to the spec if someone has dropped it into the diff --git a/ROMFS/logging/logconv.m b/ROMFS/logging/logconv.m new file mode 100644 index 0000000000..5a615228d6 --- /dev/null +++ b/ROMFS/logging/logconv.m @@ -0,0 +1,98 @@ +clear all +clc + +if exist('actuator_outputs0.bin', 'file') + % Read actuators file + myFile = java.io.File('actuator_outputs0.bin') + fileSize = length(myFile) + + fid = fopen('actuator_outputs0.bin', 'r'); + elements = int64(fileSize./(16*4+8)) + + for i=1:(elements-2) + % timestamp + actuators(i,1) = double(fread(fid, 1, '*uint64', 0, 'ieee-le.l64')); + % actuators 1-16 + % quadrotor: motor 1-4 on the first four positions + actuators(i, 2:17) = fread(fid, 16, 'float', 'ieee-le'); + end +end + +if exist('actuator_controls0.bin', 'file') + % Read actuators file + myFile = java.io.File('actuator_controls0.bin') + fileSize = length(myFile) + + fid = fopen('actuator_controls0.bin', 'r'); + elements = int64(fileSize./(8*4+8)) + + for i=1:elements + % timestamp + actuator_controls(i,1) = fread(fid, 1, 'uint64', 0, 'ieee-le.l64'); + % actuators 1-16 + % quadrotor: motor 1-4 on the first four positions + actuator_controls(i, 2:9) = fread(fid, 8, 'float', 'ieee-le'); + end +end + + +if exist('sensor_combined.bin', 'file') + % Read sensor combined file + % Type definition: Firmware/apps/uORB/topics/sensor_combined.h + % Struct: sensor_combined_s + fileInfo = dir('sensor_combined.bin'); + fileSize = fileInfo.bytes; + + fid = fopen('sensor_combined.bin', 'r'); + + for i=1:elements + % timestamp + sensors(i,1) = double(fread(fid, 1, '*uint64', 0, 'ieee-le.l64')); + % gyro raw + sensors(i,2:4) = fread(fid, 3, 'int16', 0, 'ieee-le'); + % gyro counter + sensors(i,5) = fread(fid, 1, 'uint16', 0, 'ieee-le'); + % gyro in rad/s + sensors(i,6:8) = fread(fid, 3, 'float', 0, 'ieee-le'); + + % accelerometer raw + sensors(i,9:11) = fread(fid, 3, 'int16', 0, 'ieee-le'); + % padding bytes + fread(fid, 1, 'int16', 0, 'ieee-le'); + % accelerometer counter + sensors(i,12) = fread(fid, 1, 'uint32', 0, 'ieee-le'); + % accel in m/s2 + sensors(i,13:15) = fread(fid, 3, 'float', 0, 'ieee-le'); + % accel mode + sensors(i,16) = fread(fid, 1, 'int32', 0, 'ieee-le'); + % accel range + sensors(i,17) = fread(fid, 1, 'float', 0, 'ieee-le'); + + % mag raw + sensors(i,18:20) = fread(fid, 3, 'int16', 0, 'ieee-le'); + % padding bytes + fread(fid, 1, 'int16', 0, 'ieee-le'); + % mag in Gauss + sensors(i,21:23) = fread(fid, 3, 'float', 0, 'ieee-le'); + % mag mode + sensors(i,24) = fread(fid, 1, 'int32', 0, 'ieee-le'); + % mag range + sensors(i,25) = fread(fid, 1, 'float', 0, 'ieee-le'); + % mag cuttoff freq + sensors(i,26) = fread(fid, 1, 'float', 0, 'ieee-le'); + % mag counter + sensors(i,27) = fread(fid, 1, 'int32', 0, 'ieee-le'); + + % baro pressure millibar + % baro alt meter + % baro temp celcius + % battery voltage + % adc voltage (3 channels) + sensors(i,28:34) = fread(fid, 7, 'float', 0, 'ieee-le'); + % baro counter and battery counter + sensors(i,35:36) = fread(fid, 2, 'uint32', 0, 'ieee-le'); + % battery voltage valid flag + sensors(i,37) = fread(fid, 1, 'uint32', 0, 'ieee-le'); + + end +end \ No newline at end of file diff --git a/ROMFS/mixers/FMU_quad_+.mix b/ROMFS/mixers/FMU_quad_+.mix new file mode 100644 index 0000000000..dfdf1d58e0 --- /dev/null +++ b/ROMFS/mixers/FMU_quad_+.mix @@ -0,0 +1,7 @@ +Multirotor mixer for PX4FMU +=========================== + +This file defines a single mixer for a quadrotor in the + configuration. All controls +are mixed 100%. + +R: 4+ 10000 10000 10000 0 diff --git a/ROMFS/mixers/FMU_multirotor.mix b/ROMFS/mixers/FMU_quad_x.mix similarity index 50% rename from ROMFS/mixers/FMU_multirotor.mix rename to ROMFS/mixers/FMU_quad_x.mix index 285a40e1a7..12a3bee20c 100644 --- a/ROMFS/mixers/FMU_multirotor.mix +++ b/ROMFS/mixers/FMU_quad_x.mix @@ -1,7 +1,7 @@ Multirotor mixer for PX4FMU =========================== -This file defines a single mixer for a quadrotor in the X configuration, with 10% contribution from -roll and pitch and 20% contribution from yaw and no deadband. +This file defines a single mixer for a quadrotor in the X configuration. All controls +are mixed 100%. -R: 4x 1000 1000 2000 0 +R: 4x 10000 10000 10000 0 diff --git a/ROMFS/scripts/rc.FMU_quad_x b/ROMFS/scripts/rc.FMU_quad_x new file mode 100644 index 0000000000..94ed2be18b --- /dev/null +++ b/ROMFS/scripts/rc.FMU_quad_x @@ -0,0 +1,40 @@ +# +# Startup for X-quad on FMU1.5/1.6 +# + +echo "[init] uORB" +uorb start + +echo "[init] eeprom" +eeprom start +if [ -f /eeprom/parameters ] +then + eeprom load_param /eeprom/parameters +fi + +echo "[init] sensors" +#bma180 start +#l3gd20 start +mpu6000 start +hmc5883 start +ms5611 start + +sensors start + +echo "[init] mavlink" +mavlink start -d /dev/ttyS0 -b 57600 +usleep 5000 + +echo "[init] commander" +commander start + +echo "[init] attitude control" +attitude_estimator_bm & +multirotor_att_control start + +echo "[init] starting PWM output" +fmu mode_pwm +mixer load /dev/pwm_output /etc/mixers/FMU_quad_x.mix + +echo "[init] startup done, exiting" +exit diff --git a/ROMFS/scripts/rc.PX4IO b/ROMFS/scripts/rc.PX4IO index e2f4fca84f..13c759db2d 100644 --- a/ROMFS/scripts/rc.PX4IO +++ b/ROMFS/scripts/rc.PX4IO @@ -18,7 +18,7 @@ sh /etc/init.d/rc.sensors # # Start MAVLink # -mavlink -d /dev/ttyS0 -b 57600 & +mavlink start -d /dev/ttyS0 -b 57600 # # Start the commander. diff --git a/ROMFS/scripts/rc.PX4IOAR b/ROMFS/scripts/rc.PX4IOAR index d3cf8b5067..2a771cac48 100644 --- a/ROMFS/scripts/rc.PX4IOAR +++ b/ROMFS/scripts/rc.PX4IOAR @@ -18,7 +18,7 @@ sh /etc/init.d/rc.sensors # # Start MAVLink # -mavlink -d /dev/ttyS0 -b 57600 & +mavlink start -d /dev/ttyS0 -b 57600 usleep 5000 # diff --git a/ROMFS/scripts/rc.sensors b/ROMFS/scripts/rc.sensors index 7515c1947e..f913e82af9 100644 --- a/ROMFS/scripts/rc.sensors +++ b/ROMFS/scripts/rc.sensors @@ -7,14 +7,14 @@ # Start sensor drivers here. # -#ms5611 start +ms5611 start +mpu6000 start +hmc5883 start # # Start the sensor collection task. # -# XXX should be 'sensors start' -# -sensors & +sensors start # # Test sensor functionality diff --git a/ROMFS/scripts/rcS b/ROMFS/scripts/rcS index 33f63ca873..9e564e2cc7 100755 --- a/ROMFS/scripts/rcS +++ b/ROMFS/scripts/rcS @@ -18,7 +18,7 @@ # can change this to prevent automatic startup of the flight script. # set MODE autostart -set USB no +set USB autoconnect # # Try to mount the microSD card. @@ -31,6 +31,8 @@ else echo "[init] no microSD card found" fi +usleep 500 + # # Look for an init script on the microSD card. # @@ -46,11 +48,16 @@ fi # # Check for USB host # -if sercon +if [ $USB != autoconnect ] then - echo "[init] USB interface connected" + echo "[init] not connecting USB" else - echo "[init] No USB connected" + if sercon + then + echo "[init] USB interface connected" + else + echo "[init] No USB connected" + fi fi # @@ -77,6 +84,7 @@ else if [ -f /etc/init.d/rc.PX4IOAR ] then echo "[init] reading /etc/init.d/rc.PX4IOAR" + usleep 500 sh /etc/init.d/rc.PX4IOAR fi else @@ -92,6 +100,7 @@ else if [ -f /etc/init.d/rc.PX4IO ] then echo "[init] reading /etc/init.d/rc.PX4IO" + usleep 500 sh /etc/init.d/rc.PX4IO fi else diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py index bc5d7b36bf..7ebd37e750 100755 --- a/Tools/px_uploader.py +++ b/Tools/px_uploader.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python ############################################################################ # # Copyright (C) 2012 PX4 Development Team. All rights reserved. @@ -102,7 +103,8 @@ class uploader(object): REBOOT = chr(0x30) INFO_BL_REV = chr(1) # bootloader protocol revision - BL_REV = 2 # supported bootloader protocol + BL_REV_MIN = 2 # minimum supported bootloader protocol + BL_REV_MAX = 3 # maximum supported bootloader protocol INFO_BOARD_ID = chr(2) # board type INFO_BOARD_REV = chr(3) # board revision INFO_FLASH_SIZE = chr(4) # max firmware size in bytes @@ -111,8 +113,8 @@ class uploader(object): READ_MULTI_MAX = 60 # protocol max is 255, something overflows with >= 64 def __init__(self, portname, baudrate): - # open the port - self.port = serial.Serial(portname, baudrate, timeout=10) + # open the port, keep the default timeout short so we can poll quickly + self.port = serial.Serial(portname, baudrate, timeout=0.25) def close(self): if self.port is not None: @@ -148,16 +150,16 @@ class uploader(object): + uploader.EOC) self.__getSync() - def __trySync(self): - c = self.__recv() - if (c != self.INSYNC): - #print("unexpected 0x%x instead of INSYNC" % ord(c)) - return False; - c = self.__recv() - if (c != self.OK): - #print("unexpected 0x%x instead of OK" % ord(c)) - return False - return True +# def __trySync(self): +# c = self.__recv() +# if (c != self.INSYNC): +# #print("unexpected 0x%x instead of INSYNC" % ord(c)) +# return False; +# c = self.__recv() +# if (c != self.OK): +# #print("unexpected 0x%x instead of OK" % ord(c)) +# return False +# return True # send the GET_DEVICE command and wait for an info parameter def __getInfo(self, param): @@ -171,7 +173,17 @@ class uploader(object): def __erase(self): self.__send(uploader.CHIP_ERASE + uploader.EOC) - self.__getSync() + # erase is very slow, give it 10s + deadline = time.time() + 10 + while time.time() < deadline: + try: + self.__getSync() + return + except RuntimeError as ex: + # we timed out, that's OK + continue + + raise RuntimeError("timed out waiting for erase") # send a PROG_MULTI command to write a collection of bytes def __program_multi(self, data): @@ -186,6 +198,7 @@ class uploader(object): self.__send(uploader.READ_MULTI + chr(len(data)) + uploader.EOC) + self.port.flush() programmed = self.__recv(len(data)) if (programmed != data): print("got " + binascii.hexlify(programmed)) @@ -228,7 +241,8 @@ class uploader(object): # get the bootloader protocol ID first bl_rev = self.__getInfo(uploader.INFO_BL_REV) - if bl_rev != uploader.BL_REV: + if (bl_rev < uploader.BL_REV_MIN) or (bl_rev > uploader.BL_REV_MAX): + print("Unsupported bootloader protocol %d" % uploader.INFO_BL_REV) raise RuntimeError("Bootloader protocol mismatch") self.board_type = self.__getInfo(uploader.INFO_BOARD_ID) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt old mode 100755 new mode 100644 index 01ef090a04..e098099155 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -248,7 +248,7 @@ being set to the priority of the parent thread; losing its configured priority. Reported by Mike Smith. -6.21 2012-xx-xx Gregory Nutt +6.21 2012-08-25 Gregory Nutt * apps/include/: Stylistic clean-up of all header files. * apps/modbus and apps/include/modbus: A port of freemodbus-v1.5.0 @@ -259,9 +259,9 @@ * apps/modbus: Add CONFIG_MB_TERMIOS. If the driver doesn't support termios ioctls, then don't bother trying to configure the baud, parity etc. - * apps/nslib: If waitpid() is supported, then NSH not catches the + * apps/nshlib: If waitpid() is supported, then NSH now catches the return value from spawned applications (provided by Mike Smith) - * apps/nslib: Lock the schedule while starting built-in applications + * apps/nshlib: Lock the scheduler while starting built-in applications in order to eliminate race conditions (also from Mike Smith). * apps/examples/adc, pwm, and qencoder: Add support for testing devices with multiple ADC, PWM, and QE devices. @@ -272,9 +272,67 @@ properties of mounted file systems. * apps/nshlib/nsh_parse.c: Extend help command options. 'help' with no arguments outputs a short list of commands. With -v lists all - command line details. And command name can be added to just get + command line details. A command name can be added to just get help on one command. * system/readline.c: If character input/output is interrupted by a signal, then readline() will try the read/write again. * apps/*/Make.defs: Numerous fixes needed to use the automated configuration (from Richard Cochran). + +6.22 2012-xx-xx Gregory Nutt + + * apps/netutils/thttpd/thttpd_cgi.c: Missing NULL in argv[] + list (contributed by Kate). + * apps/nshlib/nsh_parse.c: CONFIG_NSH_DISABLE_WGET not CONFIG_NSH_DISABLE_GET + in one location (found by Kate). + * apps/examples/ostest/prioinherit.c: Limit the number of test + threds to no more than 3 of each priority. Bad things happen + when the existing logic tried to created several hundred test + treads! + * apps/nshlib/nsh.h: Both CONFIG_LIBC_STRERROR and CONFIG_NSH_STRERROR + must be defined to use strerror() with NSH. + * apps/examples/*/*_main.c, system/i2c/i2c_main.c, and others: Added + configuration variable CONFIG_USER_ENTRYPOINT that may be used to change + the default entry from user_start to some other symbol. Contributed by + Kate. + * apps/netutils/webserver/httpd/c: Fix a typo that as introduced in + version r4402: 'lese' instead of 'else' (Noted by Max Holtzberg). + * tools/mkfsdata.pl: The uIP web server CGI image making perl script was + moved from apps/netutils/webserver/makefsdata to nuttx/tools/mkfsdata.pl + (Part of a larger change submitted by Max Holtzberg). + * apps/netutils/webserver, apps/examples/uip, and apps/include/netutils/httpd.h: + The "canned" version of the uIP web servers content that was at + netutils/webserver/httpd_fsdata.c has been replaced with a dynamically + built configuration located at apps/examples/uip (Contributed by + Max Holtzberg). + * apps/netutils/webserver: Several inenhancements from Kate including the + ability to elide scripting and SERVER headers and the ability to map + files into memory before transferring them. + * apps/netutils/webserver: Add ability to map a URL to CGI function. + Contributed by Kate. + * apps/nshlib/nsh_mntcmds.c: The changes of 6.21 introduced holes in the + error handling: Now the number of arguments to mount can be 0 or 4. + Additional parameter checking is required to prevent mysterious errors + (submiteed by Kate). + * apps/netutils/webserver/httpd_mmap.c: Fix errors when the mmap() + length is zero (submitted by Kate). + * apps/netutils/webserver/httpd_sendfile.c: Add and option, + CONFIG_NETUTILS_HTTPD_SENDFILE to transfer files using the NuttX + sendfile() interface. + * apps/netutils/discover: A UDP network discovery utility contributed + by Max Holtzberg. + * apps/examples/discover: A test example for the UDP network discovery + utility (also contribed by Max Holtzberg). + * apps/examples/*/main.c: Too many files called main.c. Each renamed + to something unique so that they will not collide in the archive. + * apps/netutils/xmlrpc: The Embeddable Lightweight XML-RPC Server + discussed at http://www.drdobbs.com/web-development/\ + an-embeddable-lightweight-xml-rpc-server/184405364. Contributed by + Max Holtzberg. + * apps/netutils/uip_listenon.c: Logic in uip_server.c that creates + the listening socket was moved to this new file to support re-use. + Contributed by Kate. + * apps/netutils/webserver/httpd.c: The option CONFIG_NETUTILS_HTTPD_SINGLECONNECT + can now be used to limit the server to a single thread. Option + CONFIG_NETUTILS_HTTPD_TIMEOUT can be used to generate HTTP 408 errors. + Both from Kate. diff --git a/apps/Make.defs b/apps/Make.defs index f37a654c47..53ac7f8be5 100644 --- a/apps/Make.defs +++ b/apps/Make.defs @@ -3,7 +3,7 @@ # Common make definitions provided to all applications # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/README.txt b/apps/README.txt index 4266585726..f9c9ececd7 100644 --- a/apps/README.txt +++ b/apps/README.txt @@ -118,7 +118,7 @@ the NuttX configuration file: CONFIG_BUILTIN_APP_START= that application shall be invoked immediately after system starts -*instead* of the normal, default "user_start" entry point. +*instead* of the default "user_start" entry point. Note that must be provided as: "hello", will call: diff --git a/apps/ardrone_control/.context b/apps/ardrone_control/.context deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apps/ardrone_control/ardrone_control.c b/apps/ardrone_control/ardrone_control.c deleted file mode 100644 index bc5598f9c5..0000000000 --- a/apps/ardrone_control/ardrone_control.c +++ /dev/null @@ -1,319 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file Implementation of AR.Drone 1.0 / 2.0 control interface - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ardrone_control.h" -#include "attitude_control.h" -#include "rate_control.h" -#include "ardrone_motor_control.h" -#include -#include -#include -#include -#include -#include -#include -#include - -__EXPORT int ardrone_control_main(int argc, char *argv[]); - -// static void turn_xy_plane(const float_vect3 *vector, float yaw, -// float_vect3 *result); -// static void navi2body_xy_plane(const float_vect3 *vector, const float yaw, -// float_vect3 *result); - -// static void turn_xy_plane(const float_vect3 *vector, float yaw, -// float_vect3 *result) -// { -// //turn clockwise -// static uint16_t counter; - -// result->x = (cosf(yaw) * vector->x + sinf(yaw) * vector->y); -// result->y = (-sinf(yaw) * vector->x + cosf(yaw) * vector->y); -// result->z = vector->z; //leave direction normal to xy-plane untouched - -// counter++; -// } - -// static void navi2body_xy_plane(const float_vect3 *vector, const float yaw, -// float_vect3 *result) -// { -// turn_xy_plane(vector, yaw, result); -// // result->x = vector->x; -// // result->y = vector->y; -// // result->z = vector->z; -// // result->x = cos(yaw) * vector->x + sin(yaw) * vector->y; -// // result->y = -sin(yaw) * vector->x + cos(yaw) * vector->y; -// // result->z = vector->z; //leave direction normal to xy-plane untouched -// } - -int ardrone_control_main(int argc, char *argv[]) -{ - /* welcome user */ - printf("[ardrone_control] Control started, taking over motors\n"); - - /* default values for arguments */ - char *ardrone_uart_name = "/dev/ttyS1"; - - /* File descriptors */ - int ardrone_write; - int gpios; - - enum { - CONTROL_MODE_RATES = 0, - CONTROL_MODE_ATTITUDE = 1, - } control_mode = CONTROL_MODE_ATTITUDE; - - char *commandline_usage = "\tusage: ardrone_control -d ardrone-devicename -m mode\n\tmodes are:\n\t\trates\n\t\tattitude\n"; - - bool motor_test_mode = false; - - /* read commandline arguments */ - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //ardrone set - if (argc > i + 1) { - ardrone_uart_name = argv[i + 1]; - } else { - printf(commandline_usage); - return ERROR; - } - - } else if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--mode") == 0) { - if (argc > i + 1) { - if (strcmp(argv[i + 1], "rates") == 0) { - control_mode = CONTROL_MODE_RATES; - - } else if (strcmp(argv[i + 1], "attitude") == 0) { - control_mode = CONTROL_MODE_ATTITUDE; - - } else { - printf(commandline_usage); - return ERROR; - } - - } else { - printf(commandline_usage); - return ERROR; - } - - } else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) { - motor_test_mode = true; - } - } - - /* open uarts */ - printf("[ardrone_control] AR.Drone UART is %s\n", ardrone_uart_name); - ardrone_write = open(ardrone_uart_name, O_RDWR | O_NOCTTY | O_NDELAY); - if (ardrone_write < 0) { - fprintf(stderr, "[ardrone_control] Failed opening AR.Drone UART, exiting.\n"); - exit(ERROR); - } - - /* initialize motors */ - if (OK != ar_init_motors(ardrone_write, &gpios)) { - close(ardrone_write); - fprintf(stderr, "[ardrone_control] Failed initializing AR.Drone motors, exiting.\n"); - exit(ERROR); - } - - /* Led animation */ - int counter = 0; - int led_counter = 0; - - /* declare and safely initialize all structs */ - struct vehicle_status_s state; - memset(&state, 0, sizeof(state)); - struct vehicle_attitude_s att; - memset(&att, 0, sizeof(att)); - struct vehicle_attitude_setpoint_s att_sp; - memset(&att_sp, 0, sizeof(att_sp)); - struct manual_control_setpoint_s manual; - memset(&manual, 0, sizeof(manual)); - struct sensor_combined_s raw; - memset(&raw, 0, sizeof(raw)); - struct ardrone_motors_setpoint_s setpoint; - memset(&setpoint, 0, sizeof(setpoint)); - - /* subscribe to attitude, motor setpoints and system state */ - int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); - int att_setpoint_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint)); - int state_sub = orb_subscribe(ORB_ID(vehicle_status)); - int manual_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); - int sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); - int setpoint_sub = orb_subscribe(ORB_ID(ardrone_motors_setpoint)); - - while (1) { - - /* get a local copy of the vehicle state */ - orb_copy(ORB_ID(vehicle_status), state_sub, &state); - - if (state.state_machine == SYSTEM_STATE_MANUAL || - state.state_machine == SYSTEM_STATE_GROUND_READY || - state.state_machine == SYSTEM_STATE_STABILIZED || - state.state_machine == SYSTEM_STATE_AUTO || - state.state_machine == SYSTEM_STATE_MISSION_ABORT || - state.state_machine == SYSTEM_STATE_EMCY_LANDING || - motor_test_mode) { - - if (control_mode == CONTROL_MODE_RATES) { - orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw); - orb_copy(ORB_ID(ardrone_motors_setpoint), setpoint_sub, &setpoint); - control_rates(ardrone_write, &raw, &setpoint); - - } else if (control_mode == CONTROL_MODE_ATTITUDE) { - - // XXX Add failsafe logic for RC loss situations - /* hardcore, last-resort safety checking */ - //if (status->rc_signal_lost) { - - /* get a local copy of manual setpoint */ - orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual); - /* get a local copy of attitude */ - orb_copy(ORB_ID(vehicle_attitude), att_sub, &att); - /* get a local copy of attitude setpoint */ - orb_copy(ORB_ID(vehicle_attitude_setpoint), att_setpoint_sub, &att_sp); - - att_sp.roll_body = -manual.roll * M_PI_F / 8.0f; - att_sp.pitch_body = -manual.pitch * M_PI_F / 8.0f; - att_sp.yaw_body = -manual.yaw * M_PI_F; - if (motor_test_mode) { - att_sp.roll_body = 0.0f; - att_sp.pitch_body = 0.0f; - att_sp.yaw_body = 0.0f; - att_sp.thrust = 0.3f; - } else { - if (state.state_machine == SYSTEM_STATE_MANUAL || - state.state_machine == SYSTEM_STATE_GROUND_READY || - state.state_machine == SYSTEM_STATE_STABILIZED || - state.state_machine == SYSTEM_STATE_AUTO || - state.state_machine == SYSTEM_STATE_MISSION_ABORT || - state.state_machine == SYSTEM_STATE_EMCY_LANDING) { - att_sp.thrust = manual.throttle; - - } else if (state.state_machine == SYSTEM_STATE_EMCY_CUTOFF) { - /* immediately cut off motors */ - att_sp.thrust = 0.0f; - - } else { - /* limit motor throttle to zero for an unknown mode */ - att_sp.thrust = 0.0f; - } - - } - - float roll_control, pitch_control, yaw_control, thrust_control; - - multirotor_control_attitude(&att_sp, &att, &state, motor_test_mode, - &roll_control, &pitch_control, &yaw_control, &thrust_control); - ardrone_mixing_and_output(ardrone_write, roll_control, pitch_control, yaw_control, thrust_control, motor_test_mode); - - } else { - /* invalid mode, complain */ - if (counter % 200 == 0) printf("[multirotor control] INVALID CONTROL MODE, locking down propulsion\n"); - ardrone_write_motor_commands(ardrone_write, 0, 0, 0, 0); - } - } else { - /* Silently lock down motor speeds to zero */ - ardrone_write_motor_commands(ardrone_write, 0, 0, 0, 0); - } - - if (counter % 30 == 0) { - if (led_counter == 0) ar_set_leds(ardrone_write, 0, 1, 0, 0, 0, 0, 0 , 0); - - if (led_counter == 1) ar_set_leds(ardrone_write, 1, 1, 0, 0, 0, 0, 0 , 0); - - if (led_counter == 2) ar_set_leds(ardrone_write, 1, 0, 0, 0, 0, 0, 0 , 0); - - if (led_counter == 3) ar_set_leds(ardrone_write, 0, 0, 0, 1, 0, 0, 0 , 0); - - if (led_counter == 4) ar_set_leds(ardrone_write, 0, 0, 1, 1, 0, 0, 0 , 0); - - if (led_counter == 5) ar_set_leds(ardrone_write, 0, 0, 1, 0, 0, 0, 0 , 0); - - if (led_counter == 6) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 1, 0 , 0); - - if (led_counter == 7) ar_set_leds(ardrone_write, 0, 0, 0, 0, 1, 1, 0 , 0); - - if (led_counter == 8) ar_set_leds(ardrone_write, 0, 0, 0, 0, 1, 0, 0 , 0); - - if (led_counter == 9) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 0 , 1); - - if (led_counter == 10) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 1 , 1); - - if (led_counter == 11) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 1 , 0); - - led_counter++; - - if (led_counter == 12) led_counter = 0; - } - - /* run at approximately 200 Hz */ - usleep(5000); - - // This is a hardcore debug code piece to validate - // the motor interface - // uint8_t motorSpeedBuf[5] = {1, 2, 3, 4, 5}; - // ar_get_motor_packet(motorSpeedBuf, 20, 20, 20, 20); - // write(ardrone_write, motorSpeedBuf, 5); - // usleep(15000); - - counter++; - } - - /* close uarts */ - close(ardrone_write); - ar_multiplexing_deinit(gpios); - - printf("[ardrone_control] ending now...\n"); - fflush(stdout); - return OK; -} - diff --git a/apps/ardrone_control/ardrone_control.h b/apps/ardrone_control/ardrone_control.h deleted file mode 100644 index 7f9567f861..0000000000 --- a/apps/ardrone_control/ardrone_control.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * ardrone_control.h - * - * Created on: Mar 23, 2012 - * Author: thomasgubler - */ - -#ifndef ARDRONE_CONTROL_H_ -#define ARDRONE_CONTROL_H_ - - -#endif /* ARDRONE_CONTROL_H_ */ diff --git a/apps/ardrone_control/ardrone_control_helper.c b/apps/ardrone_control/ardrone_control_helper.c deleted file mode 100644 index c073119e09..0000000000 --- a/apps/ardrone_control/ardrone_control_helper.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "ardrone_control_helper.h" -#include -#include -#include -#include - -// int read_sensors_raw(sensors_raw_t *sensors_raw) -// { -// static int ret; -// ret = global_data_wait(&global_data_sensors_raw->access_conf_rate_full); - -// if (ret == 0) { -// memcpy(sensors_raw->gyro_raw, global_data_sensors_raw->gyro_raw, sizeof(sensors_raw->gyro_raw)); -// // printf("Timestamp %d\n", &global_data_sensors_raw->timestamp); - -// } else { -// printf("Controller timeout, no new sensor values available\n"); -// } - -// global_data_unlock(&global_data_sensors_raw->access_conf_rate_full); -// return ret; -// } - -// int read_attitude(global_data_attitude_t *attitude) -// { - -// static int ret; -// ret = global_data_wait(&global_data_attitude->access_conf); - -// if (ret == 0) { -// memcpy(&attitude->roll, &global_data_attitude->roll, sizeof(global_data_attitude->roll)); -// memcpy(&attitude->pitch, &global_data_attitude->pitch, sizeof(global_data_attitude->pitch)); -// memcpy(&attitude->yaw, &global_data_attitude->yaw, sizeof(global_data_attitude->yaw)); -// memcpy(&attitude->rollspeed, &global_data_attitude->rollspeed, sizeof(global_data_attitude->rollspeed)); -// memcpy(&attitude->pitchspeed, &global_data_attitude->pitchspeed, sizeof(global_data_attitude->pitchspeed)); -// memcpy(&attitude->yawspeed, &global_data_attitude->yawspeed, sizeof(global_data_attitude->yawspeed)); - -// } else { -// printf("Controller timeout, no new attitude values available\n"); -// } - -// global_data_unlock(&global_data_attitude->access_conf); - - - -// return ret; -// } - -// void read_quad_motors_setpoint(quad_motors_setpoint_t *rate_setpoint) -// { - -// if (0 == global_data_trylock(&global_data_quad_motors_setpoint->access_conf)) { //TODO: check if trylock is the right choice, maybe only lock? -// rate_setpoint->motor_front_nw = global_data_quad_motors_setpoint->motor_front_nw; -// rate_setpoint->motor_right_ne = global_data_quad_motors_setpoint->motor_right_ne; -// rate_setpoint->motor_back_se = global_data_quad_motors_setpoint->motor_back_se; -// rate_setpoint->motor_left_sw = global_data_quad_motors_setpoint->motor_left_sw; - -// global_data_unlock(&global_data_quad_motors_setpoint->access_conf); -// } -// } diff --git a/apps/ardrone_control/ardrone_control_helper.h b/apps/ardrone_control/ardrone_control_helper.h deleted file mode 100644 index 22eebe986d..0000000000 --- a/apps/ardrone_control/ardrone_control_helper.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * ardrone_control_helper.h - * - * Created on: May 15, 2012 - * Author: thomasgubler - */ - -#ifndef ARDRONE_CONTROL_HELPER_H_ -#define ARDRONE_CONTROL_HELPER_H_ - -#include - -// typedef struct { -// int16_t gyro_raw[3]; // l3gd20 -// } sensors_raw_t; - -// /* Copy quad_motors_setpoint values from global memory to private variables */ //TODO: change this once the new mavlink message for rates is available -// void read_quad_motors_setpoint(quad_motors_setpoint_t *rate_setpoint); - - -#endif /* ARDRONE_CONTROL_HELPER_H_ */ diff --git a/apps/ardrone_control/ardrone_motor_control.c b/apps/ardrone_control/ardrone_motor_control.c deleted file mode 100644 index e9733a1a03..0000000000 --- a/apps/ardrone_control/ardrone_motor_control.c +++ /dev/null @@ -1,299 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file ardrone_motor_control.c - * Implementation of AR.Drone 1.0 / 2.0 motor control interface - */ - - - -#include "ardrone_motor_control.h" - -static const unsigned long motor_gpios = GPIO_EXT_1 | GPIO_EXT_2 | GPIO_MULTI_1 | GPIO_MULTI_2; -static const unsigned long motor_gpio[4] = { GPIO_EXT_1, GPIO_EXT_2, GPIO_MULTI_1, GPIO_MULTI_2 }; - -typedef union { - uint16_t motor_value; - uint8_t bytes[2]; -} motor_union_t; - -/** - * @brief Generate the 8-byte motor set packet - * - * @return the number of bytes (8) - */ -void ar_get_motor_packet(uint8_t *motor_buf, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4) -{ - motor_buf[0] = 0x20; - motor_buf[1] = 0x00; - motor_buf[2] = 0x00; - motor_buf[3] = 0x00; - motor_buf[4] = 0x00; - /* - * {0x20, 0x00, 0x00, 0x00, 0x00}; - * 0x20 is start sign / motor command - */ - motor_union_t curr_motor; - uint16_t nineBitMask = 0x1FF; - - /* Set motor 1 */ - curr_motor.motor_value = (motor1 & nineBitMask) << 4; - motor_buf[0] |= curr_motor.bytes[1]; - motor_buf[1] |= curr_motor.bytes[0]; - - /* Set motor 2 */ - curr_motor.motor_value = (motor2 & nineBitMask) << 3; - motor_buf[1] |= curr_motor.bytes[1]; - motor_buf[2] |= curr_motor.bytes[0]; - - /* Set motor 3 */ - curr_motor.motor_value = (motor3 & nineBitMask) << 2; - motor_buf[2] |= curr_motor.bytes[1]; - motor_buf[3] |= curr_motor.bytes[0]; - - /* Set motor 4 */ - curr_motor.motor_value = (motor4 & nineBitMask) << 1; - motor_buf[3] |= curr_motor.bytes[1]; - motor_buf[4] |= curr_motor.bytes[0]; -} - -void ar_enable_broadcast(int fd) -{ - ar_select_motor(fd, 0); -} - -int ar_multiplexing_init() -{ - int fd; - - fd = open(GPIO_DEVICE_PATH, 0); - - if (fd < 0) { - printf("GPIO: open fail\n"); - return fd; - } - - /* deactivate all outputs */ - int ret = 0; - ret += ioctl(fd, GPIO_SET, motor_gpios); - - if (ioctl(fd, GPIO_SET_OUTPUT, motor_gpios) != 0) { - printf("GPIO: output set fail\n"); - close(fd); - return -1; - } - - if (ret < 0) { - printf("GPIO: clearing pins fail\n"); - close(fd); - return -1; - } - - return fd; -} - -int ar_multiplexing_deinit(int fd) -{ - if (fd < 0) { - printf("GPIO: no valid descriptor\n"); - return fd; - } - - int ret = 0; - - /* deselect motor 1-4 */ - ret += ioctl(fd, GPIO_SET, motor_gpios); - - if (ret != 0) { - printf("GPIO: clear failed %d times\n", ret); - } - - if (ioctl(fd, GPIO_SET_INPUT, motor_gpios) != 0) { - printf("GPIO: input set fail\n"); - return -1; - } - - close(fd); - - return ret; -} - -int ar_select_motor(int fd, uint8_t motor) -{ - int ret = 0; - unsigned long gpioset; - /* - * Four GPIOS: - * GPIO_EXT1 - * GPIO_EXT2 - * GPIO_UART2_CTS - * GPIO_UART2_RTS - */ - - /* select motor 0 to enable broadcast */ - if (motor == 0) { - /* select motor 1-4 */ - ret += ioctl(fd, GPIO_CLEAR, motor_gpios); - - } else { - /* deselect all */ - ret += ioctl(fd, GPIO_SET, motor_gpios); - - /* select reqested motor */ - ret += ioctl(fd, GPIO_CLEAR, motor_gpio[motor - 1]); - - /* deselect all others */ - // gpioset = motor_gpios ^ motor_gpio[motor - 1]; - // ret += ioctl(fd, GPIO_SET, gpioset); - } - - return ret; -} - -int ar_init_motors(int ardrone_uart, int *gpios_pin) -{ - /* Initialize multiplexing */ - *gpios_pin = ar_multiplexing_init(); - - /* Write ARDrone commands on UART2 */ - uint8_t initbuf[] = {0xE0, 0x91, 0xA1, 0x00, 0x40}; - uint8_t multicastbuf[] = {0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0}; - - /* initialize all motors - * - select one motor at a time - * - configure motor - */ - int i; - int errcounter = 0; - - for (i = 1; i < 5; ++i) { - /* Initialize motors 1-4 */ - initbuf[3] = i; - errcounter += ar_select_motor(*gpios_pin, i); - - write(ardrone_uart, initbuf + 0, 1); - - /* sleep 400 ms */ - usleep(200000); - usleep(200000); - - write(ardrone_uart, initbuf + 1, 1); - /* wait 50 ms */ - usleep(50000); - - write(ardrone_uart, initbuf + 2, 1); - /* wait 50 ms */ - usleep(50000); - - write(ardrone_uart, initbuf + 3, 1); - /* wait 50 ms */ - usleep(50000); - - write(ardrone_uart, initbuf + 4, 1); - /* wait 50 ms */ - usleep(50000); - - /* enable multicast */ - write(ardrone_uart, multicastbuf + 0, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 1, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 2, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 3, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 4, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 5, 1); - /* wait 5 ms */ - usleep(50000); - } - - /* start the multicast part */ - errcounter += ar_select_motor(*gpios_pin, 0); - - if (errcounter != 0) { - fprintf(stderr, "[ar motors] init sequence incomplete, failed %d times", -errcounter); - fflush(stdout); - } - return errcounter; -} - -/* - * Sets the leds on the motor controllers, 1 turns led on, 0 off. - */ -void ar_set_leds(int ardrone_uart, uint8_t led1_red, uint8_t led1_green, uint8_t led2_red, uint8_t led2_green, uint8_t led3_red, uint8_t led3_green, uint8_t led4_red, uint8_t led4_green) -{ - /* - * 2 bytes are sent. The first 3 bits describe the command: 011 means led control - * the following 4 bits are the red leds for motor 4, 3, 2, 1 - * then 4 bits with unknown function, then 4 bits for green leds for motor 4, 3, 2, 1 - * the last bit is unknown. - * - * The packet is therefore: - * 011 rrrr 0000 gggg 0 - */ - uint8_t leds[2]; - leds[0] = 0x60 | ((led4_red & 0x01) << 4) | ((led3_red & 0x01) << 3) | ((led2_red & 0x01) << 2) | ((led1_red & 0x01) << 1); - leds[1] = ((led4_green & 0x01) << 4) | ((led3_green & 0x01) << 3) | ((led2_green & 0x01) << 2) | ((led1_green & 0x01) << 1); - write(ardrone_uart, leds, 2); -} - -int ardrone_write_motor_commands(int ardrone_fd, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4) { - const int min_motor_interval = 20000; - static uint64_t last_motor_time = 0; - if (hrt_absolute_time() - last_motor_time > min_motor_interval) { - uint8_t buf[5] = {0}; - ar_get_motor_packet(buf, motor1, motor2, motor3, motor4); - int ret; - if ((ret = write(ardrone_fd, buf, sizeof(buf))) > 0) { - return OK; - } else { - return ret; - } - } else { - return -ERROR; - } -} diff --git a/apps/ardrone_control/attitude_control.c b/apps/ardrone_control/attitude_control.c deleted file mode 100644 index d31e36e332..0000000000 --- a/apps/ardrone_control/attitude_control.c +++ /dev/null @@ -1,349 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: @author Thomas Gubler - * @author Julian Oes - * @author Laurens Mackay - * @author Tobias Naegeli - * @author Martin Rutschmann - * @author Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file attitude_control.c - * Implementation of attitude controller - */ - -#include "attitude_control.h" -#include -#include -#include -#include -#include -#include "ardrone_motor_control.h" -#include -#include -#include "pid.h" -#include - -#define MAX_MOTOR_COUNT 16 - -void multirotor_control_attitude(const struct vehicle_attitude_setpoint_s *att_sp, const struct vehicle_attitude_s *att, const struct vehicle_status_s *status, - bool verbose, float* roll_output, float* pitch_output, float* yaw_output, float* thrust_output) -{ - static uint64_t last_run = 0; - const float deltaT = (hrt_absolute_time() - last_run) / 1000000.0f; - last_run = hrt_absolute_time(); - - static int motor_skip_counter = 0; - - static PID_t yaw_pos_controller; - static PID_t yaw_speed_controller; - static PID_t pitch_controller; - static PID_t roll_controller; - - static float pid_yawpos_lim; - static float pid_yawspeed_lim; - static float pid_att_lim; - - static bool initialized = false; - - /* initialize the pid controllers when the function is called for the first time */ - if (initialized == false) { - - pid_init(&yaw_pos_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_AWU], - PID_MODE_DERIVATIV_CALC, 154); - - pid_init(&yaw_speed_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_AWU], - PID_MODE_DERIVATIV_CALC, 155); - - pid_init(&pitch_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU], - PID_MODE_DERIVATIV_SET, 156); - - pid_init(&roll_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU], - PID_MODE_DERIVATIV_SET, 157); - - pid_yawpos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_LIM]; - pid_yawspeed_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_LIM]; - pid_att_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_LIM]; - - initialized = true; - } - - /* load new parameters with lower rate */ - if (motor_skip_counter % 50 == 0) { - pid_set_parameters(&yaw_pos_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_AWU]); - - pid_set_parameters(&yaw_speed_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_AWU]); - - pid_set_parameters(&pitch_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]); - - pid_set_parameters(&roll_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]); - - pid_yawpos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_LIM]; - pid_yawspeed_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_LIM]; - pid_att_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_LIM]; - } - - /*Calculate Controllers*/ - //control Nick - float pitch_control = pid_calculate(&pitch_controller, att_sp->pitch_body + global_data_parameter_storage->pm.param_values[PARAM_ATT_YOFFSET], - att->pitch, att->pitchspeed, deltaT); - //control Roll - float roll_control = pid_calculate(&roll_controller, att_sp->roll_body + global_data_parameter_storage->pm.param_values[PARAM_ATT_XOFFSET], - att->roll, att->rollspeed, deltaT); - //control Yaw Speed - float yaw_rate_control = pid_calculate(&yaw_speed_controller, att_sp->yaw_body, att->yawspeed, 0.0f, deltaT); //attitude_setpoint_bodyframe.z is yaw speed! - - /* - * compensate the vertical loss of thrust - * when thrust plane has an angle. - * start with a factor of 1.0 (no change) - */ - float zcompensation = 1.0f; - - if (fabsf(att->roll) > 1.0f) { - zcompensation *= 1.85081571768f; - - } else { - zcompensation *= 1.0f / cosf(att->roll); - } - - if (fabsf(att->pitch) > 1.0f) { - zcompensation *= 1.85081571768f; - - } else { - zcompensation *= 1.0f / cosf(att->pitch); - } - - float motor_thrust = 0.0f; - - // FLYING MODES - motor_thrust = att_sp->thrust; - - //printf("mot0: %3.1f\n", motor_thrust); - - /* compensate thrust vector for roll / pitch contributions */ - motor_thrust *= zcompensation; - - /* limit yaw rate output */ - if (yaw_rate_control > pid_yawspeed_lim) { - yaw_rate_control = pid_yawspeed_lim; - yaw_speed_controller.saturated = 1; - } - - if (yaw_rate_control < -pid_yawspeed_lim) { - yaw_rate_control = -pid_yawspeed_lim; - yaw_speed_controller.saturated = 1; - } - - if (pitch_control > pid_att_lim) { - pitch_control = pid_att_lim; - pitch_controller.saturated = 1; - } - - if (pitch_control < -pid_att_lim) { - pitch_control = -pid_att_lim; - pitch_controller.saturated = 1; - } - - - if (roll_control > pid_att_lim) { - roll_control = pid_att_lim; - roll_controller.saturated = 1; - } - - if (roll_control < -pid_att_lim) { - roll_control = -pid_att_lim; - roll_controller.saturated = 1; - } - - *roll_output = roll_control; - *pitch_output = pitch_control; - *yaw_output = yaw_rate_control; - *thrust_output = motor_thrust; -} - -void ardrone_mixing_and_output(int ardrone_write, float roll_control, float pitch_control, float yaw_control, float motor_thrust, bool verbose) { - - unsigned int motor_skip_counter = 0; - - const float min_thrust = 0.02f; /**< 2% minimum thrust */ - const float max_thrust = 1.0f; /**< 100% max thrust */ - const float scaling = 512.0f; /**< 100% thrust equals a value of 512 */ - - const float min_gas = min_thrust * scaling; /**< value range sent to motors, minimum */ - const float max_gas = max_thrust * scaling; /**< value range sent to motors, maximum */ - - /* initialize all fields to zero */ - uint16_t motor_pwm[MAX_MOTOR_COUNT] = {0}; - float motor_calc[MAX_MOTOR_COUNT] = {0}; - - float output_band = 0.0f; - float band_factor = 0.75f; - const float startpoint_full_control = 0.25f; /**< start full control at 25% thrust */ - float yaw_factor = 1.0f; - - if (motor_thrust <= min_thrust) { - motor_thrust = min_thrust; - output_band = 0.0f; - - } else if (motor_thrust < startpoint_full_control && motor_thrust > min_thrust) { - output_band = band_factor * (motor_thrust - min_thrust); - - } else if (motor_thrust >= startpoint_full_control && motor_thrust < max_thrust - band_factor * startpoint_full_control) { - output_band = band_factor * startpoint_full_control; - - } else if (motor_thrust >= max_thrust - band_factor * startpoint_full_control) { - output_band = band_factor * (max_thrust - motor_thrust); - } - - if (verbose && motor_skip_counter % 100 == 0) { - printf("1: mot1: %3.1f band: %3.1f r: %3.1f n: %3.1f y: %3.1f\n", (double)motor_thrust, (double)output_band, (double)roll_control, (double)pitch_control, (double)yaw_control); - } - - //add the yaw, nick and roll components to the basic thrust //TODO:this should be done by the mixer - - // FRONT (MOTOR 1) - motor_calc[0] = motor_thrust + (roll_control / 2 + pitch_control / 2 - yaw_control); - - // RIGHT (MOTOR 2) - motor_calc[1] = motor_thrust + (-roll_control / 2 + pitch_control / 2 + yaw_control); - - // BACK (MOTOR 3) - motor_calc[2] = motor_thrust + (-roll_control / 2 - pitch_control / 2 - yaw_control); - - // LEFT (MOTOR 4) - motor_calc[3] = motor_thrust + (roll_control / 2 - pitch_control / 2 + yaw_control); - - // if we are not in the output band - if (!(motor_calc[0] < motor_thrust + output_band && motor_calc[0] > motor_thrust - output_band - && motor_calc[1] < motor_thrust + output_band && motor_calc[1] > motor_thrust - output_band - && motor_calc[2] < motor_thrust + output_band && motor_calc[2] > motor_thrust - output_band - && motor_calc[3] < motor_thrust + output_band && motor_calc[3] > motor_thrust - output_band)) { - - yaw_factor = 0.5f; - // FRONT (MOTOR 1) - motor_calc[0] = motor_thrust + (roll_control / 2 + pitch_control / 2 - yaw_control * yaw_factor); - - // RIGHT (MOTOR 2) - motor_calc[1] = motor_thrust + (-roll_control / 2 + pitch_control / 2 + yaw_control * yaw_factor); - - // BACK (MOTOR 3) - motor_calc[2] = motor_thrust + (-roll_control / 2 - pitch_control / 2 - yaw_control * yaw_factor); - - // LEFT (MOTOR 4) - motor_calc[3] = motor_thrust + (roll_control / 2 - pitch_control / 2 + yaw_control * yaw_factor); - } - - if (verbose && motor_skip_counter % 100 == 0) { - printf("2: m1: %3.1f m2: %3.1f m3: %3.1f m4: %3.1f\n", (double)motor_calc[0], (double)motor_calc[1], (double)motor_calc[2], (double)motor_calc[3]); - } - - for (int i = 0; i < 4; i++) { - //check for limits - if (motor_calc[i] < motor_thrust - output_band) { - motor_calc[i] = motor_thrust - output_band; - } - - if (motor_calc[i] > motor_thrust + output_band) { - motor_calc[i] = motor_thrust + output_band; - } - } - - if (verbose && motor_skip_counter % 100 == 0) { - printf("3: band lim: m1: %3.1f m2: %3.1f m3: %3.1f m4: %3.1f\n", (double)motor_calc[0], (double)motor_calc[1], (double)motor_calc[2], (double)motor_calc[3]); - } - - /* set the motor values */ - - /* scale up from 0..1 to 10..512) */ - motor_pwm[0] = (uint16_t) (motor_calc[0] * ((float)max_gas - min_gas) + min_gas); - motor_pwm[1] = (uint16_t) (motor_calc[1] * ((float)max_gas - min_gas) + min_gas); - motor_pwm[2] = (uint16_t) (motor_calc[2] * ((float)max_gas - min_gas) + min_gas); - motor_pwm[3] = (uint16_t) (motor_calc[3] * ((float)max_gas - min_gas) + min_gas); - - if (verbose && motor_skip_counter % 100 == 0) { - printf("4: scaled: m1: %d m2: %d m3: %d m4: %d\n", motor_pwm[0], motor_pwm[1], motor_pwm[2], motor_pwm[3]); - } - - /* Keep motors spinning while armed and prevent overflows */ - - /* Failsafe logic - should never be necessary */ - motor_pwm[0] = (motor_pwm[0] > 0) ? motor_pwm[0] : 10; - motor_pwm[1] = (motor_pwm[1] > 0) ? motor_pwm[1] : 10; - motor_pwm[2] = (motor_pwm[2] > 0) ? motor_pwm[2] : 10; - motor_pwm[3] = (motor_pwm[3] > 0) ? motor_pwm[3] : 10; - - /* Failsafe logic - should never be necessary */ - motor_pwm[0] = (motor_pwm[0] <= 512) ? motor_pwm[0] : 512; - motor_pwm[1] = (motor_pwm[1] <= 512) ? motor_pwm[1] : 512; - motor_pwm[2] = (motor_pwm[2] <= 512) ? motor_pwm[2] : 512; - motor_pwm[3] = (motor_pwm[3] <= 512) ? motor_pwm[3] : 512; - - /* send motors via UART */ - if (verbose && motor_skip_counter % 100 == 0) printf("5: mot: %3.1f-%i-%i-%i-%i\n\n", (double)motor_thrust, motor_pwm[0], motor_pwm[1], motor_pwm[2], motor_pwm[3]); - ardrone_write_motor_commands(ardrone_write, motor_pwm[0], motor_pwm[1], motor_pwm[2], motor_pwm[3]); - - motor_skip_counter++; -} diff --git a/apps/ardrone_control/pid.c b/apps/ardrone_control/pid.c deleted file mode 100644 index 5ce05670e3..0000000000 --- a/apps/ardrone_control/pid.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "pid.h" - -#include //TODO: move matrix.h to somewhere else? - -void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, - uint8_t mode, uint8_t plot_i) -{ - pid->kp = kp; - pid->ki = ki; - pid->kd = kd; - pid->intmax = intmax; - pid->mode = mode; - pid->plot_i = plot_i; - pid->count = 0; - pid->saturated = 0; - - pid->sp = 0; - pid->error_previous = 0; - pid->integral = 0; -} -void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax) -{ - pid->kp = kp; - pid->ki = ki; - pid->kd = kd; - pid->intmax = intmax; - // pid->mode = mode; - - // pid->sp = 0; - // pid->error_previous = 0; - // pid->integral = 0; -} - -//void pid_set(PID_t *pid, float sp) -//{ -// pid->sp = sp; -// pid->error_previous = 0; -// pid->integral = 0; -//} - -/** - * - * @param pid - * @param val - * @param dt - * @return - */ -float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt) -{ - /* error = setpoint - actual_position - integral = integral + (error*dt) - derivative = (error - previous_error)/dt - output = (Kp*error) + (Ki*integral) + (Kd*derivative) - previous_error = error - wait(dt) - goto start - */ - - float i, d; - pid->sp = sp; - float error = pid->sp - val; - - if (pid->saturated && (pid->integral * error > 0)) { - //Output is saturated and the integral would get bigger (positive or negative) - i = pid->integral; - - //Reset saturation. If we are still saturated this will be set again at output limit check. - pid->saturated = 0; - - } else { - i = pid->integral + (error * dt); - } - - // Anti-Windup. Needed if we don't use the saturation above. - if (pid->intmax != 0.0) { - if (i > pid->intmax) { - pid->integral = pid->intmax; - - } else if (i < -pid->intmax) { - - pid->integral = -pid->intmax; - - } else { - pid->integral = i; - } - - //Send Controller integrals - // Disabled because of new possibilities with debug_vect. - // Now sent in Main Loop at 5 Hz. 26.06.2010 Laurens - // if (pid->plot_i && (pid->count++ % 16 == 0)&&(global_data.param[PARAM_SEND_SLOT_DEBUG_2] == 1)) - // { - // mavlink_msg_debug_send(MAVLINK_COMM_1, pid->plot_i, pid->integral); - // } - } - - if (pid->mode == PID_MODE_DERIVATIV_CALC) { - d = (error - pid->error_previous) / dt; - - } else if (pid->mode == PID_MODE_DERIVATIV_SET) { - d = -val_dot; - - } else { - d = 0; - } - - pid->error_previous = error; - - return (error * pid->kp) + (i * pid->ki) + (d * pid->kd); -} diff --git a/apps/ardrone_control/pid.h b/apps/ardrone_control/pid.h deleted file mode 100644 index a721c839c6..0000000000 --- a/apps/ardrone_control/pid.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * pid.h - * - * Created on: May 29, 2012 - * Author: thomasgubler - */ - -#ifndef PID_H_ -#define PID_H_ - -#include - -/* PID_MODE_DERIVATIV_CALC calculates discrete derivative from previous error - * val_dot in pid_calculate() will be ignored */ -#define PID_MODE_DERIVATIV_CALC 0 -/* Use PID_MODE_DERIVATIV_SET if you have the derivative already (Gyros, Kalman) */ -#define PID_MODE_DERIVATIV_SET 1 - -typedef struct { - float kp; - float ki; - float kd; - float intmax; - float sp; - float integral; - float error_previous; - uint8_t mode; - uint8_t plot_i; - uint8_t count; - uint8_t saturated; -} PID_t; - -void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, uint8_t mode, uint8_t plot_i); -void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax); -//void pid_set(PID_t *pid, float sp); -float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt); - - - -#endif /* PID_H_ */ diff --git a/apps/ardrone_control/position_control.h b/apps/ardrone_control/position_control.h deleted file mode 100644 index dbc0650e66..0000000000 --- a/apps/ardrone_control/position_control.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * position_control.h - * - * Created on: May 29, 2012 - * Author: thomasgubler - */ - -#ifndef POSITION_CONTROL_H_ -#define POSITION_CONTROL_H_ - -void control_position(void); - -#endif /* POSITION_CONTROL_H_ */ diff --git a/apps/ardrone_control/rate_control.c b/apps/ardrone_control/rate_control.c deleted file mode 100644 index df20cd1ab8..0000000000 --- a/apps/ardrone_control/rate_control.c +++ /dev/null @@ -1,321 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: @author Lorenz Meier - * @author Tobias Naegeli - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file rate_control.c - * Implementation of attitude rate control - */ - -#include "rate_control.h" -#include "ardrone_control_helper.h" -#include "ardrone_motor_control.h" -#include - -extern int ardrone_write; -extern int gpios; - -typedef struct { - uint16_t motor_front_nw; ///< Front motor in + configuration, front left motor in x configuration - uint16_t motor_right_ne; ///< Right motor in + configuration, front right motor in x configuration - uint16_t motor_back_se; ///< Back motor in + configuration, back right motor in x configuration - uint16_t motor_left_sw; ///< Left motor in + configuration, back left motor in x configuration - uint8_t target_system; ///< System ID of the system that should set these motor commands -} quad_motors_setpoint_t; - - -void control_rates(int ardrone_write, struct sensor_combined_s *raw, struct ardrone_motors_setpoint_s *setpoints) -{ - static quad_motors_setpoint_t actuators_desired; - //static quad_motors_setpoint_t quad_motors_setpoint_desired; - - static int16_t outputBand = 0; - -// static uint16_t control_counter; - static hrt_abstime now_time; - static hrt_abstime last_time; - - static float setpointXrate; - static float setpointYrate; - static float setpointZrate; - - static float setpointRateCast[3]; - static float Kp; -// static float Ki; - static float setpointThrustCast; - static float startpointFullControll; - static float maxThrustSetpoints; - - static float gyro_filtered[3]; - static float gyro_filtered_offset[3]; - static float gyro_alpha; - static float gyro_alpha_offset; -// static float errXrate; - static float attRatesScaled[3]; - - static uint16_t offsetCnt; -// static float antiwindup; - static int motor_skip_counter; - - static int read_ret; - - static bool initialized; - - if (initialized == false) { - initialized = true; - - /* Read sensors for initial values */ - - gyro_filtered_offset[0] = 0.00026631611f * (float)raw->gyro_raw[0]; - gyro_filtered_offset[1] = 0.00026631611f * (float)raw->gyro_raw[1]; - gyro_filtered_offset[2] = 0.00026631611f * (float)raw->gyro_raw[2]; - - gyro_filtered[0] = 0.00026631611f * (float)raw->gyro_raw[0]; - gyro_filtered[1] = 0.00026631611f * (float)raw->gyro_raw[1]; - gyro_filtered[2] = 0.00026631611f * (float)raw->gyro_raw[2]; - - outputBand = 0; - startpointFullControll = 150.0f; - maxThrustSetpoints = 511.0f; - //Kp=60; - //Kp=40.0f; - //Kp=45; - Kp = 30.0f; -// Ki=0.0f; -// antiwindup=50.0f; - } - - /* Get setpoint */ - - - //Rate Controller - setpointRateCast[0] = -((float)setpoints->motor_right_ne - 9999.0f) * 0.01f / 180.0f * 3.141f; - setpointRateCast[1] = -((float)setpoints->motor_front_nw - 9999.0f) * 0.01f / 180.0f * 3.141f; - setpointRateCast[2] = 0; //-((float)setpoints->motor_back_se-9999.0f)*0.01f; - //Ki=actuatorDesired.motorRight_NE*0.001f; - setpointThrustCast = setpoints->motor_left_sw; - - attRatesScaled[0] = 0.000317603994f * (float)raw->gyro_raw[0]; - attRatesScaled[1] = 0.000317603994f * (float)raw->gyro_raw[1]; - attRatesScaled[2] = 0.000317603994f * (float)raw->gyro_raw[2]; - - //filtering of the gyroscope values - - //compute filter coefficient alpha - - //gyro_alpha=0.005/(2.0f*3.1415f*200.0f+0.005f); - //gyro_alpha=0.009; - gyro_alpha = 0.09f; - gyro_alpha_offset = 0.001f; - //gyro_alpha=0.001; - //offset estimation and filtering - offsetCnt++; - uint8_t i; - - for (i = 0; i < 3; i++) { - if (offsetCnt < 5000) { - gyro_filtered_offset[i] = attRatesScaled[i] * gyro_alpha_offset + gyro_filtered_offset[i] * (1 - gyro_alpha_offset); - } - - gyro_filtered[i] = 1.0f * ((attRatesScaled[i] - gyro_filtered_offset[i]) * gyro_alpha + gyro_filtered[i] * (1 - gyro_alpha)) - 0 * setpointRateCast[i]; - } - - // //START DEBUG - // /* write filtered values to global_data_attitude */ - // global_data_attitude->rollspeed = gyro_filtered[0]; - // global_data_attitude->pitchspeed = gyro_filtered[1]; - // global_data_attitude->yawspeed = gyro_filtered[2]; - // //END DEBUG - - //rate controller - - //X-axis - setpointXrate = -Kp * (setpointRateCast[0] - gyro_filtered[0]); - //Y-axis - setpointYrate = -Kp * (setpointRateCast[1] - gyro_filtered[1]); - //Z-axis - setpointZrate = -Kp * (setpointRateCast[2] - gyro_filtered[2]); - - - - - //Mixing - if (setpointThrustCast <= 0) { - setpointThrustCast = 0; - outputBand = 0; - } - - if ((setpointThrustCast < startpointFullControll) && (setpointThrustCast > 0)) { - outputBand = 0.75f * setpointThrustCast; - } - - if ((setpointThrustCast >= startpointFullControll) && (setpointThrustCast < maxThrustSetpoints - 0.75f * startpointFullControll)) { - outputBand = 0.75f * startpointFullControll; - } - - if (setpointThrustCast >= maxThrustSetpoints - 0.75f * startpointFullControll) { - setpointThrustCast = 0.75f * startpointFullControll; - outputBand = 0.75f * startpointFullControll; - } - - actuators_desired.motor_front_nw = setpointThrustCast + (setpointXrate + setpointYrate + setpointZrate); - actuators_desired.motor_right_ne = setpointThrustCast + (-setpointXrate + setpointYrate - setpointZrate); - actuators_desired.motor_back_se = setpointThrustCast + (-setpointXrate - setpointYrate + setpointZrate); - actuators_desired.motor_left_sw = setpointThrustCast + (setpointXrate - setpointYrate - setpointZrate); - - - if ((setpointThrustCast + setpointXrate + setpointYrate + setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_front_nw = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + setpointXrate + setpointYrate + setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_front_nw = setpointThrustCast - outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + setpointYrate - setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_right_ne = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + setpointYrate - setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_right_ne = setpointThrustCast - outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + (-setpointYrate) + setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_back_se = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + (-setpointYrate) + setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_back_se = setpointThrustCast - outputBand; - } - - if ((setpointThrustCast + setpointXrate + (-setpointYrate) - setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_left_sw = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + setpointXrate + (-setpointYrate) - setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_left_sw = setpointThrustCast - outputBand; - } - - //printf("%lu,%lu,%lu,%lu\n",actuators_desired.motor_front_nw, actuators_desired.motor_right_ne, actuators_desired.motor_back_se, actuators_desired.motor_left_sw); - - if (motor_skip_counter % 5 == 0) { - uint8_t motorSpeedBuf[5]; - ar_get_motor_packet(motorSpeedBuf, actuators_desired.motor_front_nw, actuators_desired.motor_right_ne, actuators_desired.motor_back_se, actuators_desired.motor_left_sw); -// uint8_t* motorSpeedBuf = ar_get_motor_packet(1, 1, 1, 1); -// if(motor_skip_counter %50 == 0) -// { -// if(0==actuators_desired.motor_front_nw || 0 == actuators_desired.motor_right_ne || 0 == actuators_desired.motor_back_se || 0 == actuators_desired.motor_left_sw) -// printf("Motors set: %u, %u, %u, %u\n", actuators_desired.motor_front_nw, actuators_desired.motor_right_ne, actuators_desired.motor_back_se, actuators_desired.motor_left_sw); -// printf("input: %u\n", setpoints->motor_front_nw); -// printf("Roll casted desired: %f, Pitch casted desired: %f, Yaw casted desired: %f\n", setpointRateCast[0], setpointRateCast[1], setpointRateCast[2]); -// } - write(ardrone_write, motorSpeedBuf, 5); -// motor_skip_counter = 0; - } - - motor_skip_counter++; - - //START DEBUG -// global_data_lock(&global_data_ardrone_control->access_conf); -// global_data_ardrone_control->timestamp = hrt_absolute_time(); -// global_data_ardrone_control->gyro_scaled[0] = attRatesScaled[0]; -// global_data_ardrone_control->gyro_scaled[1] = attRatesScaled[1]; -// global_data_ardrone_control->gyro_scaled[2] = attRatesScaled[2]; -// global_data_ardrone_control->gyro_filtered[0] = gyro_filtered[0]; -// global_data_ardrone_control->gyro_filtered[1] = gyro_filtered[1]; -// global_data_ardrone_control->gyro_filtered[2] = gyro_filtered[2]; -// global_data_ardrone_control->gyro_filtered_offset[0] = gyro_filtered_offset[0]; -// global_data_ardrone_control->gyro_filtered_offset[1] = gyro_filtered_offset[1]; -// global_data_ardrone_control->gyro_filtered_offset[2] = gyro_filtered_offset[2]; -// global_data_ardrone_control->setpoint_rate_cast[0] = setpointRateCast[0]; -// global_data_ardrone_control->setpoint_rate_cast[1] = setpointRateCast[1]; -// global_data_ardrone_control->setpoint_rate_cast[2] = setpointRateCast[2]; -// global_data_ardrone_control->setpoint_thrust_cast = setpointThrustCast; -// global_data_ardrone_control->setpoint_rate[0] = setpointXrate; -// global_data_ardrone_control->setpoint_rate[1] = setpointYrate; -// global_data_ardrone_control->setpoint_rate[2] = setpointZrate; -// global_data_ardrone_control->motor_front_nw = actuators_desired.motor_front_nw; -// global_data_ardrone_control->motor_right_ne = actuators_desired.motor_right_ne; -// global_data_ardrone_control->motor_back_se = actuators_desired.motor_back_se; -// global_data_ardrone_control->motor_left_sw = actuators_desired.motor_left_sw; -// global_data_unlock(&global_data_ardrone_control->access_conf); -// global_data_broadcast(&global_data_ardrone_control->access_conf); - //END DEBUG - - - -// gettimeofday(&tv, NULL); -// now = ((uint32_t)tv.tv_sec) * 1000 + tv.tv_usec/1000; -// time_elapsed = now - last_run; -// if (time_elapsed*1000 > CONTROL_LOOP_USLEEP) -// { -// sleep_time = (int32_t)CONTROL_LOOP_USLEEP - ((int32_t)time_elapsed*1000 - (int32_t)CONTROL_LOOP_USLEEP); -// -// if(motor_skip_counter %500 == 0) -// { -// printf("Desired: %u, New usleep: %i, Time elapsed: %u, Now: %u, Last run: %u\n",(uint32_t)CONTROL_LOOP_USLEEP, sleep_time, time_elapsed*1000, now, last_run); -// } -// } -// -// if (sleep_time <= 0) -// { -// printf("WARNING: CPU Overload!\n"); -// printf("Desired: %u, New usleep: %i, Time elapsed: %u, Now: %u, Last run: %u\n",(uint32_t)CONTROL_LOOP_USLEEP, sleep_time, time_elapsed*1000, now, last_run); -// usleep(CONTROL_LOOP_USLEEP); -// } -// else -// { -// usleep(sleep_time); -// } -// last_run = now; -// -// now_time = hrt_absolute_time(); -// if(control_counter % 500 == 0) -// { -// printf("Now: %lu\n",(unsigned long)now_time); -// printf("Last: %lu\n",(unsigned long)last_time); -// printf("Difference: %lu\n", (unsigned long)(now_time - last_time)); -// printf("now seconds: %lu\n", (unsigned long)(now_time / 1000000)); -// } -// last_time = now_time; -// -// now_time = hrt_absolute_time() / 1000000; -// if(now_time - last_time > 0) -// { -// printf("Counter: %ld\n",control_counter); -// last_time = now_time; -// control_counter = 0; -// } -// control_counter++; -} diff --git a/apps/multirotor_position_control/Makefile b/apps/ardrone_interface/Makefile similarity index 88% rename from apps/multirotor_position_control/Makefile rename to apps/ardrone_interface/Makefile index 23e2d49fb4..fea96082f6 100644 --- a/apps/multirotor_position_control/Makefile +++ b/apps/ardrone_interface/Makefile @@ -32,14 +32,11 @@ ############################################################################ # -# Makefile to build uORB +# Makefile to build ardrone interface # -APPNAME = ardrone_control +APPNAME = ardrone_interface PRIORITY = SCHED_PRIORITY_MAX - 15 STACKSIZE = 2048 -# explicit list of sources - not everything is built currently -CSRCS = ardrone_control.c ardrone_motor_control.c ardrone_control_helper.c rate_control.c attitude_control.c pid.c - include $(APPDIR)/mk/app.mk diff --git a/apps/ardrone_interface/ardrone_interface.c b/apps/ardrone_interface/ardrone_interface.c new file mode 100644 index 0000000000..dd7b1847b3 --- /dev/null +++ b/apps/ardrone_interface/ardrone_interface.c @@ -0,0 +1,379 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file ardrone_interface.c + * Implementation of AR.Drone 1.0 / 2.0 motor control interface. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ardrone_motor_control.h" + +__EXPORT int ardrone_interface_main(int argc, char *argv[]); + + +static bool thread_should_exit = false; /**< Deamon exit flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int ardrone_interface_task; /**< Handle of deamon task / thread */ +static int ardrone_write; /**< UART to write AR.Drone commands to */ + +/** + * Mainloop of ardrone_interface. + */ +int ardrone_interface_thread_main(int argc, char *argv[]); + +/** + * Open the UART connected to the motor controllers + */ +static int ardrone_open_uart(struct termios *uart_config_original); + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: ardrone_interface {start|stop|status} [-d ]\n\n"); + exit(1); +} + +/** + * The deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ +int ardrone_interface_main(int argc, char *argv[]) +{ + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1], "start")) { + + if (thread_running) { + printf("ardrone_interface already running\n"); + /* this is not an error */ + exit(0); + } + + thread_should_exit = false; + ardrone_interface_task = task_create("ardrone_interface", SCHED_PRIORITY_MAX - 15, 4096, ardrone_interface_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tardrone_interface is running\n"); + } else { + printf("\tardrone_interface not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} + +static int ardrone_open_uart(struct termios *uart_config_original) +{ + /* baud rate */ + int speed = B115200; + int uart; + const char* uart_name = "/dev/ttyS1"; + + /* open uart */ + printf("[ardrone_interface] UART is /dev/ttyS1, baud rate is 115200\n"); + uart = open(uart_name, O_RDWR | O_NOCTTY); + + /* Try to set baud rate */ + struct termios uart_config; + int termios_state; + + /* Back up the original uart configuration to restore it after exit */ + if ((termios_state = tcgetattr(uart, uart_config_original)) < 0) { + fprintf(stderr, "[ardrone_interface] ERROR getting baudrate / termios config for %s: %d\n", uart_name, termios_state); + close(uart); + return -1; + } + + /* Fill the struct for the new configuration */ + tcgetattr(uart, &uart_config); + + /* Clear ONLCR flag (which appends a CR for every LF) */ + uart_config.c_oflag &= ~ONLCR; + + /* Set baud rate */ + if (cfsetispeed(&uart_config, speed) < 0 || cfsetospeed(&uart_config, speed) < 0) { + fprintf(stderr, "[ardrone_interface] ERROR setting baudrate / termios config for %s: %d (cfsetispeed, cfsetospeed)\n", uart_name, termios_state); + close(uart); + return -1; + } + + + if ((termios_state = tcsetattr(uart, TCSANOW, &uart_config)) < 0) { + fprintf(stderr, "[ardrone_interface] ERROR setting baudrate / termios config for %s (tcsetattr)\n", uart_name); + close(uart); + return -1; + } + + return uart; +} + +int ardrone_interface_thread_main(int argc, char *argv[]) +{ + thread_running = true; + + /* welcome user */ + printf("[ardrone_interface] Control started, taking over motors\n"); + + /* File descriptors */ + int gpios; + + char *commandline_usage = "\tusage: ardrone_interface start|status|stop [-t for motor test (10%% thrust)]\n"; + + bool motor_test_mode = false; + int test_motor = -1; + + /* read commandline arguments */ + for (int i = 0; i < argc && argv[i]; i++) { + if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) { + motor_test_mode = true; + } + + if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--motor") == 0) { + if (i+1 < argc) { + int motor = atoi(argv[i+1]); + if (motor > 0 && motor < 5) { + test_motor = motor; + } else { + errx(1, "supply a motor # between 1 and 4. Example: -m 1\n %s", commandline_usage); + } + } else { + errx(1, "missing parameter to -m 1..4\n %s", commandline_usage); + } + } + } + + struct termios uart_config_original; + + if (motor_test_mode) { + printf("[ardrone_interface] Motor test mode enabled, setting 10 %% thrust.\n"); + } + + /* Led animation */ + int counter = 0; + int led_counter = 0; + + /* declare and safely initialize all structs */ + struct vehicle_status_s state; + memset(&state, 0, sizeof(state)); + struct actuator_controls_s actuator_controls; + memset(&actuator_controls, 0, sizeof(actuator_controls)); + struct actuator_armed_s armed; + armed.armed = false; + + /* subscribe to attitude, motor setpoints and system state */ + int actuator_controls_sub = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS); + int state_sub = orb_subscribe(ORB_ID(vehicle_status)); + int armed_sub = orb_subscribe(ORB_ID(actuator_armed)); + + printf("[ardrone_interface] Motors initialized - ready.\n"); + fflush(stdout); + + /* enable UART, writes potentially an empty buffer, but multiplexing is disabled */ + ardrone_write = ardrone_open_uart(&uart_config_original); + + /* initialize multiplexing, deactivate all outputs - must happen after UART open to claim GPIOs on PX4FMU */ + gpios = ar_multiplexing_init(); + + if (ardrone_write < 0) { + fprintf(stderr, "[ardrone_interface] Failed opening AR.Drone UART, exiting.\n"); + thread_running = false; + exit(ERROR); + } + + /* initialize motors */ + if (OK != ar_init_motors(ardrone_write, gpios)) { + close(ardrone_write); + fprintf(stderr, "[ardrone_interface] Failed initializing AR.Drone motors, exiting.\n"); + thread_running = false; + exit(ERROR); + } + + ardrone_write_motor_commands(ardrone_write, 0, 0, 0, 0); + + + // XXX Re-done initialization to make sure it is accepted by the motors + // XXX should be removed after more testing, but no harm + + /* close uarts */ + close(ardrone_write); + //ar_multiplexing_deinit(gpios); + + /* enable UART, writes potentially an empty buffer, but multiplexing is disabled */ + ardrone_write = ardrone_open_uart(&uart_config_original); + + /* initialize multiplexing, deactivate all outputs - must happen after UART open to claim GPIOs on PX4FMU */ + gpios = ar_multiplexing_init(); + + if (ardrone_write < 0) { + fprintf(stderr, "[ardrone_interface] Failed opening AR.Drone UART, exiting.\n"); + thread_running = false; + exit(ERROR); + } + + /* initialize motors */ + if (OK != ar_init_motors(ardrone_write, gpios)) { + close(ardrone_write); + fprintf(stderr, "[ardrone_interface] Failed initializing AR.Drone motors, exiting.\n"); + thread_running = false; + exit(ERROR); + } + + while (!thread_should_exit) { + + if (motor_test_mode) { + /* set motors to idle speed */ + if (test_motor > 0 && test_motor < 5) { + int motors[4] = {0, 0, 0, 0}; + motors[test_motor - 1] = 10; + ardrone_write_motor_commands(ardrone_write, motors[0], motors[1], motors[2], motors[3]); + } else { + ardrone_write_motor_commands(ardrone_write, 10, 10, 10, 10); + } + + } else { + /* MAIN OPERATION MODE */ + + /* get a local copy of the vehicle state */ + orb_copy(ORB_ID(vehicle_status), state_sub, &state); + /* get a local copy of the actuator controls */ + orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_controls_sub, &actuator_controls); + orb_copy(ORB_ID(actuator_armed), armed_sub, &armed); + + /* for now only spin if armed and immediately shut down + * if in failsafe + */ + if (armed.armed && !armed.lockdown) { + ardrone_mixing_and_output(ardrone_write, &actuator_controls); + } else { + /* Silently lock down motor speeds to zero */ + ardrone_write_motor_commands(ardrone_write, 0, 0, 0, 0); + } + } + + if (counter % 16 == 0) { + if (led_counter == 0) ar_set_leds(ardrone_write, 0, 1, 0, 0, 0, 0, 0 , 0); + + if (led_counter == 1) ar_set_leds(ardrone_write, 1, 1, 0, 0, 0, 0, 0 , 0); + + if (led_counter == 2) ar_set_leds(ardrone_write, 1, 0, 0, 0, 0, 0, 0 , 0); + + if (led_counter == 3) ar_set_leds(ardrone_write, 0, 0, 0, 1, 0, 0, 0 , 0); + + if (led_counter == 4) ar_set_leds(ardrone_write, 0, 0, 1, 1, 0, 0, 0 , 0); + + if (led_counter == 5) ar_set_leds(ardrone_write, 0, 0, 1, 0, 0, 0, 0 , 0); + + if (led_counter == 6) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 1, 0 , 0); + + if (led_counter == 7) ar_set_leds(ardrone_write, 0, 0, 0, 0, 1, 1, 0 , 0); + + if (led_counter == 8) ar_set_leds(ardrone_write, 0, 0, 0, 0, 1, 0, 0 , 0); + + if (led_counter == 9) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 0 , 1); + + if (led_counter == 10) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 1 , 1); + + if (led_counter == 11) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 1 , 0); + + led_counter++; + + if (led_counter == 12) led_counter = 0; + } + + /* run at approximately 200 Hz */ + usleep(5000); + + counter++; + } + + /* restore old UART config */ + int termios_state; + + if ((termios_state = tcsetattr(ardrone_write, TCSANOW, &uart_config_original)) < 0) { + fprintf(stderr, "[ardrone_interface] ERROR setting baudrate / termios config for (tcsetattr)\n"); + } + + printf("[ardrone_interface] Restored original UART config, exiting..\n"); + + /* close uarts */ + close(ardrone_write); + ar_multiplexing_deinit(gpios); + + fflush(stdout); + + thread_running = false; + + return OK; +} + diff --git a/apps/ardrone_interface/ardrone_motor_control.c b/apps/ardrone_interface/ardrone_motor_control.c new file mode 100644 index 0000000000..787db18773 --- /dev/null +++ b/apps/ardrone_interface/ardrone_motor_control.c @@ -0,0 +1,470 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file ardrone_motor_control.c + * Implementation of AR.Drone 1.0 / 2.0 motor control interface + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ardrone_motor_control.h" + +static unsigned long motor_gpios = GPIO_EXT_1 | GPIO_EXT_2 | GPIO_MULTI_1 | GPIO_MULTI_2; +static unsigned long motor_gpio[4] = { GPIO_EXT_1, GPIO_EXT_2, GPIO_MULTI_1, GPIO_MULTI_2 }; + +typedef union { + uint16_t motor_value; + uint8_t bytes[2]; +} motor_union_t; + +#define UART_TRANSFER_TIME_BYTE_US (9+50) /**< 9 us per byte at 115200k plus overhead */ + +/** + * @brief Generate the 8-byte motor set packet + * + * @return the number of bytes (8) + */ +void ar_get_motor_packet(uint8_t *motor_buf, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4) +{ + motor_buf[0] = 0x20; + motor_buf[1] = 0x00; + motor_buf[2] = 0x00; + motor_buf[3] = 0x00; + motor_buf[4] = 0x00; + /* + * {0x20, 0x00, 0x00, 0x00, 0x00}; + * 0x20 is start sign / motor command + */ + motor_union_t curr_motor; + uint16_t nineBitMask = 0x1FF; + + /* Set motor 1 */ + curr_motor.motor_value = (motor1 & nineBitMask) << 4; + motor_buf[0] |= curr_motor.bytes[1]; + motor_buf[1] |= curr_motor.bytes[0]; + + /* Set motor 2 */ + curr_motor.motor_value = (motor2 & nineBitMask) << 3; + motor_buf[1] |= curr_motor.bytes[1]; + motor_buf[2] |= curr_motor.bytes[0]; + + /* Set motor 3 */ + curr_motor.motor_value = (motor3 & nineBitMask) << 2; + motor_buf[2] |= curr_motor.bytes[1]; + motor_buf[3] |= curr_motor.bytes[0]; + + /* Set motor 4 */ + curr_motor.motor_value = (motor4 & nineBitMask) << 1; + motor_buf[3] |= curr_motor.bytes[1]; + motor_buf[4] |= curr_motor.bytes[0]; +} + +void ar_enable_broadcast(int fd) +{ + ar_select_motor(fd, 0); +} + +int ar_multiplexing_init() +{ + int fd; + + fd = open(GPIO_DEVICE_PATH, 0); + + if (fd < 0) { + warn("GPIO: open fail"); + return fd; + } + + /* deactivate all outputs */ + if (ioctl(fd, GPIO_SET, motor_gpios)) { + warn("GPIO: clearing pins fail"); + close(fd); + return -1; + } + + /* configure all motor select GPIOs as outputs */ + if (ioctl(fd, GPIO_SET_OUTPUT, motor_gpios) != 0) { + warn("GPIO: output set fail"); + close(fd); + return -1; + } + + return fd; +} + +int ar_multiplexing_deinit(int fd) +{ + if (fd < 0) { + printf("GPIO: no valid descriptor\n"); + return fd; + } + + int ret = 0; + + /* deselect motor 1-4 */ + ret += ioctl(fd, GPIO_SET, motor_gpios); + + if (ret != 0) { + printf("GPIO: clear failed %d times\n", ret); + } + + if (ioctl(fd, GPIO_SET_INPUT, motor_gpios) != 0) { + printf("GPIO: input set fail\n"); + return -1; + } + + close(fd); + + return ret; +} + +int ar_select_motor(int fd, uint8_t motor) +{ + int ret = 0; + /* + * Four GPIOS: + * GPIO_EXT1 + * GPIO_EXT2 + * GPIO_UART2_CTS + * GPIO_UART2_RTS + */ + + /* select motor 0 to enable broadcast */ + if (motor == 0) { + /* select motor 1-4 */ + ret += ioctl(fd, GPIO_CLEAR, motor_gpios); + + } else { + /* select reqested motor */ + ret += ioctl(fd, GPIO_CLEAR, motor_gpio[motor - 1]); + } + + return ret; +} + +int ar_deselect_motor(int fd, uint8_t motor) +{ + int ret = 0; + /* + * Four GPIOS: + * GPIO_EXT1 + * GPIO_EXT2 + * GPIO_UART2_CTS + * GPIO_UART2_RTS + */ + + if (motor == 0) { + /* deselect motor 1-4 */ + ret += ioctl(fd, GPIO_SET, motor_gpios); + + } else { + /* deselect reqested motor */ + ret = ioctl(fd, GPIO_SET, motor_gpio[motor - 1]); + } + + return ret; +} + +int ar_init_motors(int ardrone_uart, int gpios) +{ + /* Write ARDrone commands on UART2 */ + uint8_t initbuf[] = {0xE0, 0x91, 0xA1, 0x00, 0x40}; + uint8_t multicastbuf[] = {0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0}; + + /* deselect all motors */ + ar_deselect_motor(gpios, 0); + + /* initialize all motors + * - select one motor at a time + * - configure motor + */ + int i; + int errcounter = 0; + + + /* initial setup run */ + for (i = 1; i < 5; ++i) { + /* Initialize motors 1-4 */ + errcounter += ar_select_motor(gpios, i); + usleep(200); + + /* + * write 0xE0 - request status + * receive one status byte + */ + write(ardrone_uart, &(initbuf[0]), 1); + fsync(ardrone_uart); + usleep(UART_TRANSFER_TIME_BYTE_US*1); + + /* + * write 0x91 - request checksum + * receive 120 status bytes + */ + write(ardrone_uart, &(initbuf[1]), 1); + fsync(ardrone_uart); + usleep(UART_TRANSFER_TIME_BYTE_US*120); + + /* + * write 0xA1 - set status OK + * receive one status byte - should be A0 + * to confirm status is OK + */ + write(ardrone_uart, &(initbuf[2]), 1); + fsync(ardrone_uart); + usleep(UART_TRANSFER_TIME_BYTE_US*1); + + /* + * set as motor i, where i = 1..4 + * receive nothing + */ + initbuf[3] = (uint8_t)i; + write(ardrone_uart, &(initbuf[3]), 1); + fsync(ardrone_uart); + + /* + * write 0x40 - check version + * receive 11 bytes encoding the version + */ + write(ardrone_uart, &(initbuf[4]), 1); + fsync(ardrone_uart); + usleep(UART_TRANSFER_TIME_BYTE_US*11); + + ar_deselect_motor(gpios, i); + /* sleep 200 ms */ + usleep(200000); + } + + /* start the multicast part */ + errcounter += ar_select_motor(gpios, 0); + usleep(200); + + /* + * first round + * write six times A0 - enable broadcast + * receive nothing + */ + write(ardrone_uart, multicastbuf, sizeof(multicastbuf)); + fsync(ardrone_uart); + usleep(UART_TRANSFER_TIME_BYTE_US * sizeof(multicastbuf)); + + /* + * second round + * write six times A0 - enable broadcast + * receive nothing + */ + write(ardrone_uart, multicastbuf, sizeof(multicastbuf)); + fsync(ardrone_uart); + usleep(UART_TRANSFER_TIME_BYTE_US * sizeof(multicastbuf)); + + /* set motors to zero speed (fsync is part of the write command */ + ardrone_write_motor_commands(ardrone_uart, 0, 0, 0, 0); + + if (errcounter != 0) { + fprintf(stderr, "[ardrone_interface] init sequence incomplete, failed %d times", -errcounter); + fflush(stdout); + } + return errcounter; +} + +/* + * Sets the leds on the motor controllers, 1 turns led on, 0 off. + */ +void ar_set_leds(int ardrone_uart, uint8_t led1_red, uint8_t led1_green, uint8_t led2_red, uint8_t led2_green, uint8_t led3_red, uint8_t led3_green, uint8_t led4_red, uint8_t led4_green) +{ + /* + * 2 bytes are sent. The first 3 bits describe the command: 011 means led control + * the following 4 bits are the red leds for motor 4, 3, 2, 1 + * then 4 bits with unknown function, then 4 bits for green leds for motor 4, 3, 2, 1 + * the last bit is unknown. + * + * The packet is therefore: + * 011 rrrr 0000 gggg 0 + */ + uint8_t leds[2]; + leds[0] = 0x60 | ((led4_red & 0x01) << 4) | ((led3_red & 0x01) << 3) | ((led2_red & 0x01) << 2) | ((led1_red & 0x01) << 1); + leds[1] = ((led4_green & 0x01) << 4) | ((led3_green & 0x01) << 3) | ((led2_green & 0x01) << 2) | ((led1_green & 0x01) << 1); + write(ardrone_uart, leds, 2); +} + +int ardrone_write_motor_commands(int ardrone_fd, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4) { + const unsigned int min_motor_interval = 4900; + static uint64_t last_motor_time = 0; + + static struct actuator_outputs_s outputs; + outputs.timestamp = hrt_absolute_time(); + outputs.output[0] = motor1; + outputs.output[1] = motor2; + outputs.output[2] = motor3; + outputs.output[3] = motor4; + static orb_advert_t pub = 0; + if (pub == 0) { + pub = orb_advertise(ORB_ID_VEHICLE_CONTROLS, &outputs); + } + + if (hrt_absolute_time() - last_motor_time > min_motor_interval) { + uint8_t buf[5] = {0}; + ar_get_motor_packet(buf, motor1, motor2, motor3, motor4); + int ret; + ret = write(ardrone_fd, buf, sizeof(buf)); + fsync(ardrone_fd); + + /* publish just written values */ + orb_publish(ORB_ID_VEHICLE_CONTROLS, pub, &outputs); + + if (ret == sizeof(buf)) { + return OK; + } else { + return ret; + } + } else { + return -ERROR; + } +} + +void ardrone_mixing_and_output(int ardrone_write, const struct actuator_controls_s *actuators) { + + float roll_control = actuators->control[0]; + float pitch_control = actuators->control[1]; + float yaw_control = actuators->control[2]; + float motor_thrust = actuators->control[3]; + + const float min_thrust = 0.02f; /**< 2% minimum thrust */ + const float max_thrust = 1.0f; /**< 100% max thrust */ + const float scaling = 512.0f; /**< 100% thrust equals a value of 512 */ + + const float min_gas = min_thrust * scaling; /**< value range sent to motors, minimum */ + const float max_gas = max_thrust * scaling; /**< value range sent to motors, maximum */ + + /* initialize all fields to zero */ + uint16_t motor_pwm[4] = {0}; + float motor_calc[4] = {0}; + + float output_band = 0.0f; + float band_factor = 0.75f; + const float startpoint_full_control = 0.25f; /**< start full control at 25% thrust */ + float yaw_factor = 1.0f; + + if (motor_thrust <= min_thrust) { + motor_thrust = min_thrust; + output_band = 0.0f; + + } else if (motor_thrust < startpoint_full_control && motor_thrust > min_thrust) { + output_band = band_factor * (motor_thrust - min_thrust); + + } else if (motor_thrust >= startpoint_full_control && motor_thrust < max_thrust - band_factor * startpoint_full_control) { + output_band = band_factor * startpoint_full_control; + + } else if (motor_thrust >= max_thrust - band_factor * startpoint_full_control) { + output_band = band_factor * (max_thrust - motor_thrust); + } + + //add the yaw, nick and roll components to the basic thrust //TODO:this should be done by the mixer + + // FRONT (MOTOR 1) + motor_calc[0] = motor_thrust + (roll_control / 2 + pitch_control / 2 - yaw_control); + + // RIGHT (MOTOR 2) + motor_calc[1] = motor_thrust + (-roll_control / 2 + pitch_control / 2 + yaw_control); + + // BACK (MOTOR 3) + motor_calc[2] = motor_thrust + (-roll_control / 2 - pitch_control / 2 - yaw_control); + + // LEFT (MOTOR 4) + motor_calc[3] = motor_thrust + (roll_control / 2 - pitch_control / 2 + yaw_control); + + // if we are not in the output band + if (!(motor_calc[0] < motor_thrust + output_band && motor_calc[0] > motor_thrust - output_band + && motor_calc[1] < motor_thrust + output_band && motor_calc[1] > motor_thrust - output_band + && motor_calc[2] < motor_thrust + output_band && motor_calc[2] > motor_thrust - output_band + && motor_calc[3] < motor_thrust + output_band && motor_calc[3] > motor_thrust - output_band)) { + + yaw_factor = 0.5f; + // FRONT (MOTOR 1) + motor_calc[0] = motor_thrust + (roll_control / 2 + pitch_control / 2 - yaw_control * yaw_factor); + + // RIGHT (MOTOR 2) + motor_calc[1] = motor_thrust + (-roll_control / 2 + pitch_control / 2 + yaw_control * yaw_factor); + + // BACK (MOTOR 3) + motor_calc[2] = motor_thrust + (-roll_control / 2 - pitch_control / 2 - yaw_control * yaw_factor); + + // LEFT (MOTOR 4) + motor_calc[3] = motor_thrust + (roll_control / 2 - pitch_control / 2 + yaw_control * yaw_factor); + } + + for (int i = 0; i < 4; i++) { + //check for limits + if (motor_calc[i] < motor_thrust - output_band) { + motor_calc[i] = motor_thrust - output_band; + } + + if (motor_calc[i] > motor_thrust + output_band) { + motor_calc[i] = motor_thrust + output_band; + } + } + + /* set the motor values */ + + /* scale up from 0..1 to 10..512) */ + motor_pwm[0] = (uint16_t) (motor_calc[0] * ((float)max_gas - min_gas) + min_gas); + motor_pwm[1] = (uint16_t) (motor_calc[1] * ((float)max_gas - min_gas) + min_gas); + motor_pwm[2] = (uint16_t) (motor_calc[2] * ((float)max_gas - min_gas) + min_gas); + motor_pwm[3] = (uint16_t) (motor_calc[3] * ((float)max_gas - min_gas) + min_gas); + + /* Keep motors spinning while armed and prevent overflows */ + + /* Failsafe logic - should never be necessary */ + motor_pwm[0] = (motor_pwm[0] > 0) ? motor_pwm[0] : 10; + motor_pwm[1] = (motor_pwm[1] > 0) ? motor_pwm[1] : 10; + motor_pwm[2] = (motor_pwm[2] > 0) ? motor_pwm[2] : 10; + motor_pwm[3] = (motor_pwm[3] > 0) ? motor_pwm[3] : 10; + + /* Failsafe logic - should never be necessary */ + motor_pwm[0] = (motor_pwm[0] <= 512) ? motor_pwm[0] : 512; + motor_pwm[1] = (motor_pwm[1] <= 512) ? motor_pwm[1] : 512; + motor_pwm[2] = (motor_pwm[2] <= 512) ? motor_pwm[2] : 512; + motor_pwm[3] = (motor_pwm[3] <= 512) ? motor_pwm[3] : 512; + + /* send motors via UART */ + ardrone_write_motor_commands(ardrone_write, motor_pwm[0], motor_pwm[1], motor_pwm[2], motor_pwm[3]); +} diff --git a/apps/ardrone_control/ardrone_motor_control.h b/apps/ardrone_interface/ardrone_motor_control.h similarity index 77% rename from apps/ardrone_control/ardrone_motor_control.h rename to apps/ardrone_interface/ardrone_motor_control.h index 2e6df0e694..664419707a 100644 --- a/apps/ardrone_control/ardrone_motor_control.h +++ b/apps/ardrone_interface/ardrone_motor_control.h @@ -1,7 +1,6 @@ /**************************************************************************** - * px4/ardrone_offboard_control.h * - * Copyright (C) 2012 PX4 Autopilot Project. All rights reserved. + * Copyright (C) 2012 PX4 Development Team. All rights reserved. * Author: Lorenz Meier * * Redistribution and use in source and binary forms, with or without @@ -14,7 +13,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be + * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -32,14 +31,14 @@ * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include +/** + * @file ardrone_motor_control.h + * Definition of AR.Drone 1.0 / 2.0 motor control interface + */ + +#include +#include /** * Generate the 5-byte motor set packet. @@ -50,9 +49,20 @@ void ar_get_motor_packet(uint8_t *motor_buf, uint16_t motor1, uint16_t motor2, u /** * Select a motor in the multiplexing. + * + * @param fd GPIO file descriptor + * @param motor Motor number, from 1 to 4, 0 selects all */ int ar_select_motor(int fd, uint8_t motor); +/** + * Deselect a motor in the multiplexing. + * + * @param fd GPIO file descriptor + * @param motor Motor number, from 1 to 4, 0 deselects all + */ +int ar_deselect_motor(int fd, uint8_t motor); + void ar_enable_broadcast(int fd); int ar_multiplexing_init(void); @@ -70,7 +80,11 @@ int ardrone_write_motor_commands(int ardrone_fd, uint16_t motor1, uint16_t motor /** * Initialize the motors. */ -int ar_init_motors(int ardrone_uart, int *gpios_pin); +int ar_init_motors(int ardrone_uart, int gpio); +/** + * Set LED pattern. + */ void ar_set_leds(int ardrone_uart, uint8_t led1_red, uint8_t led1_green, uint8_t led2_red, uint8_t led2_green, uint8_t led3_red, uint8_t led3_green, uint8_t led4_red, uint8_t led4_green); +void ardrone_mixing_and_output(int ardrone_write, const struct actuator_controls_s *actuators); diff --git a/apps/attitude_estimator_ekf/attitude_estimator_ekf_main.c b/apps/attitude_estimator_ekf/attitude_estimator_ekf_main.c index fdf6c9d91d..4b3733be32 100644 --- a/apps/attitude_estimator_ekf/attitude_estimator_ekf_main.c +++ b/apps/attitude_estimator_ekf/attitude_estimator_ekf_main.c @@ -2,7 +2,6 @@ * * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. * Author: Tobias Naegeli - * Laurens Mackay * Lorenz Meier * * Redistribution and use in source and binary forms, with or without @@ -35,14 +34,10 @@ ****************************************************************************/ /* - * @file Extended Kalman Filter for Attitude Estimation + * @file attitude_estimator_ekf_main.c + * Extended Kalman Filter for Attitude Estimation. */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - #include #include #include @@ -138,7 +133,7 @@ int attitude_estimator_ekf_main(int argc, char *argv[]) /* subscribe to raw data */ int sub_raw = orb_subscribe(ORB_ID(sensor_combined)); /* advertise attitude */ - int pub_att = orb_advertise(ORB_ID(vehicle_attitude), &att); + orb_advert_t pub_att = orb_advertise(ORB_ID(vehicle_attitude), &att); int loopcounter = 0; diff --git a/apps/commander/Makefile b/apps/commander/Makefile index f2972ac4ea..d12697274b 100644 --- a/apps/commander/Makefile +++ b/apps/commander/Makefile @@ -37,7 +37,7 @@ APPNAME = commander PRIORITY = SCHED_PRIORITY_MAX - 30 -STACKSIZE = 4096 +STACKSIZE = 2048 INCLUDES = $(TOPDIR)/../mavlink/include/mavlink diff --git a/apps/commander/commander.c b/apps/commander/commander.c index 149a662fd4..c8564792f8 100644 --- a/apps/commander/commander.c +++ b/apps/commander/commander.c @@ -68,9 +68,22 @@ #include #include #include +#include +#include #include - + +#include #include +#include + +/* XXX MOVE CALIBRATION TO SENSORS APP THREAD */ +#include +#include +#include +#include + + + #include extern struct system_load_s system_load; @@ -96,24 +109,56 @@ static int buzzer; static int mavlink_fd; static bool commander_initialized = false; static struct vehicle_status_s current_status; /**< Main state machine */ -static int stat_pub; +static orb_advert_t stat_pub; static uint16_t nofix_counter = 0; static uint16_t gotfix_counter = 0; -static void do_gyro_calibration(int status_pub, struct vehicle_status_s *current_status); -static void do_mag_calibration(int status_pub, struct vehicle_status_s *current_status); -static void handle_command(int status_pub, struct vehicle_status_s *current_status, struct vehicle_command_s *cmd); +static bool thread_should_exit = false; /**< Deamon exit flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int deamon_task; /**< Handle of deamon task / thread */ /* pthread loops */ static void *command_handling_loop(void *arg); -// static void *subsystem_info_loop(void *arg); +static void *orb_receive_loop(void *arg); __EXPORT int commander_main(int argc, char *argv[]); -#ifdef CONFIG_TONE_ALARM +/** + * Mainloop of commander. + */ +int commander_thread_main(int argc, char *argv[]); + static int buzzer_init(void); static void buzzer_deinit(void); +static int led_init(void); +static void led_deinit(void); +static int led_toggle(int led); +static int led_on(int led); +static int led_off(int led); +static void do_gyro_calibration(int status_pub, struct vehicle_status_s *status); +static void do_mag_calibration(int status_pub, struct vehicle_status_s *status); +static void do_accel_calibration(int status_pub, struct vehicle_status_s *status); +static void handle_command(int status_pub, struct vehicle_status_s *current_status, struct vehicle_command_s *cmd); + +int trigger_audio_alarm(uint8_t old_mode, uint8_t old_state, uint8_t new_mode, uint8_t new_state); + + + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + +/** + * Sort calibration values. + * + * Sorts the calibration values with bubble sort. + * + * @param a The array to sort + * @param n The number of entries in the array + */ +static void cal_bsort(float a[], int n); static int buzzer_init() { @@ -131,13 +176,7 @@ static void buzzer_deinit() { close(buzzer); } -#endif -static int led_init(void); -static void led_deinit(void); -static int led_toggle(int led); -static int led_on(int led); -static int led_off(int led); static int led_init() { @@ -211,7 +250,7 @@ int trigger_audio_alarm(uint8_t old_mode, uint8_t old_state, uint8_t new_mode, u return 0; } -void cal_bsort(int16_t a[], int n) +static void cal_bsort(float a[], int n) { int i,j,t; for(i=0;ipreflight_mag_calibration = true; + status->flag_preflight_mag_calibration = true; state_machine_publish(status_pub, status, mavlink_fd); int sub_sensor_combined = orb_subscribe(ORB_ID(sensor_combined)); @@ -244,28 +283,41 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) /* Get rid of 10% */ const int outlier_margin = (peak_samples) / 10; - int16_t *mag_maxima[3]; - mag_maxima[0] = (int16_t*)malloc(peak_samples * sizeof(uint16_t)); - mag_maxima[1] = (int16_t*)malloc(peak_samples * sizeof(uint16_t)); - mag_maxima[2] = (int16_t*)malloc(peak_samples * sizeof(uint16_t)); + float *mag_maxima[3]; + mag_maxima[0] = (float*)malloc(peak_samples * sizeof(float)); + mag_maxima[1] = (float*)malloc(peak_samples * sizeof(float)); + mag_maxima[2] = (float*)malloc(peak_samples * sizeof(float)); - int16_t *mag_minima[3]; - mag_minima[0] = (int16_t*)malloc(peak_samples * sizeof(uint16_t)); - mag_minima[1] = (int16_t*)malloc(peak_samples * sizeof(uint16_t)); - mag_minima[2] = (int16_t*)malloc(peak_samples * sizeof(uint16_t)); + float *mag_minima[3]; + mag_minima[0] = (float*)malloc(peak_samples * sizeof(float)); + mag_minima[1] = (float*)malloc(peak_samples * sizeof(float)); + mag_minima[2] = (float*)malloc(peak_samples * sizeof(float)); /* initialize data table */ for (int i = 0; i < peak_samples; i++) { - mag_maxima[0][i] = INT16_MIN; - mag_maxima[1][i] = INT16_MIN; - mag_maxima[2][i] = INT16_MIN; + mag_maxima[0][i] = FLT_MIN; + mag_maxima[1][i] = FLT_MIN; + mag_maxima[2][i] = FLT_MIN; - mag_minima[0][i] = INT16_MAX; - mag_minima[1][i] = INT16_MAX; - mag_minima[2][i] = INT16_MAX; + mag_minima[0][i] = FLT_MAX; + mag_minima[1][i] = FLT_MAX; + mag_minima[2][i] = FLT_MAX; } - mavlink_log_info(mavlink_fd, "[commander] Please rotate in all directions."); + int fd = open(MAG_DEVICE_PATH, 0); + struct mag_scale mscale_null = { + 0.0f, + 1.0f, + 0.0f, + 1.0f, + 0.0f, + 1.0f, + }; + if (OK != ioctl(fd, MAGIOCSSCALE, (long unsigned int)&mscale_null)) + warn("WARNING: failed to set scale / offsets for mag"); + close(fd); + + mavlink_log_info(mavlink_fd, "[commander] Please rotate around all axes."); uint64_t calibration_start = hrt_absolute_time(); while ((hrt_absolute_time() - calibration_start) < calibration_interval_us) { @@ -281,23 +333,23 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) for (int i = 0; i < peak_samples; i++) { /* x minimum */ if (raw.magnetometer_raw[0] < mag_minima[0][i]) - mag_minima[0][i] = raw.magnetometer_raw[0]; + mag_minima[0][i] = raw.magnetometer_ga[0]; /* y minimum */ if (raw.magnetometer_raw[1] < mag_minima[1][i]) - mag_minima[1][i] = raw.magnetometer_raw[1]; + mag_minima[1][i] = raw.magnetometer_ga[1]; /* z minimum */ if (raw.magnetometer_raw[2] < mag_minima[2][i]) - mag_minima[2][i] = raw.magnetometer_raw[2]; + mag_minima[2][i] = raw.magnetometer_ga[2]; /* x maximum */ if (raw.magnetometer_raw[0] > mag_maxima[0][i]) - mag_maxima[0][i] = raw.magnetometer_raw[0]; + mag_maxima[0][i] = raw.magnetometer_ga[0]; /* y maximum */ if (raw.magnetometer_raw[1] > mag_maxima[1][i]) - mag_maxima[1][i] = raw.magnetometer_raw[1]; + mag_maxima[1][i] = raw.magnetometer_ga[1]; /* z maximum */ if (raw.magnetometer_raw[2] > mag_maxima[2][i]) - mag_maxima[2][i] = raw.magnetometer_raw[2]; + mag_maxima[2][i] = raw.magnetometer_ga[2]; } calibration_counter++; @@ -309,7 +361,7 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) } /* disable calibration mode */ - status->preflight_mag_calibration = false; + status->flag_preflight_mag_calibration = false; state_machine_publish(status_pub, status, mavlink_fd); /* sort values */ @@ -324,32 +376,32 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) float min_avg[3] = { 0.0f, 0.0f, 0.0f }; float max_avg[3] = { 0.0f, 0.0f, 0.0f }; - printf("start:\n"); + // printf("start:\n"); - for (int i = 0; i < 10; i++) { - printf("mag min: %d\t%d\t%d\tmag max: %d\t%d\t%d\n", - mag_minima[0][i], - mag_minima[1][i], - mag_minima[2][i], - mag_maxima[0][i], - mag_maxima[1][i], - mag_maxima[2][i]); - usleep(10000); - } - printf("-----\n"); + // for (int i = 0; i < 10; i++) { + // printf("mag min: %8.4f\t%8.4f\t%8.4f\tmax: %8.4f\t%8.4f\t%8.4f\n", + // mag_minima[0][i], + // mag_minima[1][i], + // mag_minima[2][i], + // mag_maxima[0][i], + // mag_maxima[1][i], + // mag_maxima[2][i]); + // usleep(10000); + // } + // printf("-----\n"); - for (int i = (peak_samples - outlier_margin)-10; i < (peak_samples - outlier_margin); i++) { - printf("mag min: %d\t%d\t%d\tmag max: %d\t%d\t%d\n", - mag_minima[0][i], - mag_minima[1][i], - mag_minima[2][i], - mag_maxima[0][i], - mag_maxima[1][i], - mag_maxima[2][i]); - usleep(10000); - } + // for (int i = (peak_samples - outlier_margin)-10; i < (peak_samples - outlier_margin); i++) { + // printf("mag min: %8.4f\t%8.4f\t%8.4f\tmax: %8.4f\t%8.4f\t%8.4f\n", + // mag_minima[0][i], + // mag_minima[1][i], + // mag_minima[2][i], + // mag_maxima[0][i], + // mag_maxima[1][i], + // mag_maxima[2][i]); + // usleep(10000); + // } - printf("end\n"); + // printf("end\n"); /* take average of center value group */ for (int i = 0; i < (peak_samples - outlier_margin); i++) { @@ -370,7 +422,8 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) max_avg[1] /= (peak_samples - outlier_margin); max_avg[2] /= (peak_samples - outlier_margin); - printf("\nFINAL:\nmag min: %d\t%d\t%d\nmag max: %d\t%d\t%d\n", (int)min_avg[0], (int)min_avg[1], (int)min_avg[2], (int)max_avg[0], (int)max_avg[1], (int)max_avg[2]); + // printf("\nFINAL:\nmag min: %8.4f\t%8.4f\t%8.4f\nmax: %8.4f\t%8.4f\t%8.4f\n", (double)min_avg[0], + // (double)min_avg[1], (double)min_avg[2], (double)max_avg[0], (double)max_avg[1], (double)max_avg[2]); float mag_offset[3]; @@ -390,9 +443,41 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) mag_offset[1] = (max_avg[1] + min_avg[1]) / 2.0f; mag_offset[2] = (max_avg[2] + min_avg[2]) / 2.0f; - global_data_parameter_storage->pm.param_values[PARAM_SENSOR_MAG_XOFFSET] = mag_offset[0]; - global_data_parameter_storage->pm.param_values[PARAM_SENSOR_MAG_YOFFSET] = mag_offset[1]; - global_data_parameter_storage->pm.param_values[PARAM_SENSOR_MAG_ZOFFSET] = mag_offset[2]; + if (!isfinite(mag_offset[1]) || !isfinite(mag_offset[1]) || !isfinite(mag_offset[2])) { + + mavlink_log_critical(mavlink_fd, "[commander] MAG calibration failed (INF/NAN)"); + } else { + /* announce and set new offset */ + + // char offset_output[50]; + // sprintf(offset_output, "[commander] mag cal: %8.4f %8.4f %8.4f", (double)mag_offset[0], (double)mag_offset[1], (double)mag_offset[2]); + // mavlink_log_info(mavlink_fd, offset_output); + + if (param_set(param_find("SENS_MAG_XOFF"), &(mag_offset[0]))) { + fprintf(stderr, "[commander] Setting X mag offset failed!\n"); + } + + if (param_set(param_find("SENS_MAG_YOFF"), &(mag_offset[1]))) { + fprintf(stderr, "[commander] Setting Y mag offset failed!\n"); + } + + if (param_set(param_find("SENS_MAG_ZOFF"), &(mag_offset[2]))) { + fprintf(stderr, "[commander] Setting Z mag offset failed!\n"); + } + } + + fd = open(MAG_DEVICE_PATH, 0); + struct mag_scale mscale = { + mag_offset[0], + 1.0f, + mag_offset[1], + 1.0f, + mag_offset[2], + 1.0f, + }; + if (OK != ioctl(fd, MAGIOCSSCALE, (long unsigned int)&mscale)) + warn("WARNING: failed to set scale / offsets for mag"); + close(fd); free(mag_maxima[0]); free(mag_maxima[1]); @@ -402,16 +487,16 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) free(mag_minima[1]); free(mag_minima[2]); - char offset_output[50]; - sprintf(offset_output, "[commander] mag cal: x:%8.4f y:%8.4f z:%8.4f", (double)mag_offset[0], (double)mag_offset[1], (double)mag_offset[2]); - mavlink_log_info(mavlink_fd, offset_output); - close(sub_sensor_combined); } -void do_gyro_calibration(int status_pub, struct vehicle_status_s *current_status) +void do_gyro_calibration(int status_pub, struct vehicle_status_s *status) { - const int calibration_count = 3000; + /* set to gyro calibration mode */ + status->flag_preflight_gyro_calibration = true; + state_machine_publish(status_pub, status, mavlink_fd); + + const int calibration_count = 5000; int sub_sensor_combined = orb_subscribe(ORB_ID(sensor_combined)); struct sensor_combined_s raw; @@ -419,6 +504,20 @@ void do_gyro_calibration(int status_pub, struct vehicle_status_s *current_status int calibration_counter = 0; float gyro_offset[3] = {0.0f, 0.0f, 0.0f}; + /* set offsets to zero */ + int fd = open(GYRO_DEVICE_PATH, 0); + struct gyro_scale gscale_null = { + 0.0f, + 1.0f, + 0.0f, + 1.0f, + 0.0f, + 1.0f, + }; + if (OK != ioctl(fd, GYROIOCSSCALE, (long unsigned int)&gscale_null)) + warn("WARNING: failed to set scale / offsets for gyro"); + close(fd); + while (calibration_counter < calibration_count) { /* wait blocking for new data */ @@ -426,9 +525,9 @@ void do_gyro_calibration(int status_pub, struct vehicle_status_s *current_status if (poll(fds, 1, 1000)) { orb_copy(ORB_ID(sensor_combined), sub_sensor_combined, &raw); - gyro_offset[0] += raw.gyro_raw[0]; - gyro_offset[1] += raw.gyro_raw[1]; - gyro_offset[2] += raw.gyro_raw[2]; + gyro_offset[0] += raw.gyro_rad_s[0]; + gyro_offset[1] += raw.gyro_rad_s[1]; + gyro_offset[2] += raw.gyro_rad_s[2]; calibration_counter++; } else { /* any poll failure for 1s is a reason to abort */ @@ -441,17 +540,151 @@ void do_gyro_calibration(int status_pub, struct vehicle_status_s *current_status gyro_offset[1] = gyro_offset[1] / calibration_count; gyro_offset[2] = gyro_offset[2] / calibration_count; - global_data_parameter_storage->pm.param_values[PARAM_SENSOR_GYRO_XOFFSET] = gyro_offset[0]; - global_data_parameter_storage->pm.param_values[PARAM_SENSOR_GYRO_YOFFSET] = gyro_offset[1]; - global_data_parameter_storage->pm.param_values[PARAM_SENSOR_GYRO_ZOFFSET] = gyro_offset[2]; + if (param_set(param_find("SENS_GYRO_XOFF"), &(gyro_offset[0]))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting X gyro offset failed!"); + } + + if (param_set(param_find("SENS_GYRO_YOFF"), &(gyro_offset[1]))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting Y gyro offset failed!"); + } - char offset_output[50]; - sprintf(offset_output, "[commander] gyro cal: x:%8.4f y:%8.4f z:%8.4f", (double)gyro_offset[0], (double)gyro_offset[1], (double)gyro_offset[2]); - mavlink_log_info(mavlink_fd, offset_output); + if (param_set(param_find("SENS_GYRO_ZOFF"), &(gyro_offset[2]))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting Z gyro offset failed!"); + } + + /* set offsets to actual value */ + fd = open(GYRO_DEVICE_PATH, 0); + struct gyro_scale gscale = { + gyro_offset[0], + 1.0f, + gyro_offset[1], + 1.0f, + gyro_offset[2], + 1.0f, + }; + if (OK != ioctl(fd, GYROIOCSSCALE, (long unsigned int)&gscale)) + warn("WARNING: failed to set scale / offsets for gyro"); + close(fd); + + /* exit to gyro calibration mode */ + status->flag_preflight_gyro_calibration = false; + state_machine_publish(status_pub, status, mavlink_fd); + + // char offset_output[50]; + // sprintf(offset_output, "[commander] gyro cal: x:%8.4f y:%8.4f z:%8.4f", (double)gyro_offset[0], (double)gyro_offset[1], (double)gyro_offset[2]); + // mavlink_log_info(mavlink_fd, offset_output); close(sub_sensor_combined); +} - // XXX Add a parameter changed broadcast notification +void do_accel_calibration(int status_pub, struct vehicle_status_s *status) +{ + /* announce change */ + usleep(5000); + mavlink_log_info(mavlink_fd, "[commander] The system should be level and not moved"); + + /* set to accel calibration mode */ + status->flag_preflight_accel_calibration = true; + state_machine_publish(status_pub, status, mavlink_fd); + + const int calibration_count = 5000; + + int sub_sensor_combined = orb_subscribe(ORB_ID(sensor_combined)); + struct sensor_combined_s raw; + + int calibration_counter = 0; + float accel_offset[3] = {0.0f, 0.0f, 0.0f}; + + int fd = open(ACCEL_DEVICE_PATH, 0); + struct accel_scale ascale_null = { + 0.0f, + 1.0f, + 0.0f, + 1.0f, + 0.0f, + 1.0f, + }; + if (OK != ioctl(fd, ACCELIOCSSCALE, (long unsigned int)&ascale_null)) + warn("WARNING: failed to set scale / offsets for accel"); + close(fd); + + while (calibration_counter < calibration_count) { + + /* wait blocking for new data */ + struct pollfd fds[1] = { { .fd = sub_sensor_combined, .events = POLLIN } }; + + if (poll(fds, 1, 1000)) { + orb_copy(ORB_ID(sensor_combined), sub_sensor_combined, &raw); + accel_offset[0] += raw.accelerometer_m_s2[0]; + accel_offset[1] += raw.accelerometer_m_s2[1]; + accel_offset[2] += raw.accelerometer_m_s2[2]; + calibration_counter++; + } else { + /* any poll failure for 1s is a reason to abort */ + mavlink_log_info(mavlink_fd, "[commander] gyro calibration aborted, please retry."); + return; + } + } + + accel_offset[0] = accel_offset[0] / calibration_count; + accel_offset[1] = accel_offset[1] / calibration_count; + accel_offset[2] = accel_offset[2] / calibration_count; + + /* add the removed length from x / y to z, since we induce a scaling issue else */ + float total_len = sqrtf(accel_offset[0]*accel_offset[0] + accel_offset[1]*accel_offset[1] + accel_offset[2]*accel_offset[2]); + + /* if length is correct, zero results here */ + accel_offset[2] = accel_offset[2] + total_len; + + float scale = 9.80665f / total_len; + + if (param_set(param_find("SENS_ACC_XOFF"), &(accel_offset[0]))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting X accel offset failed!"); + } + + if (param_set(param_find("SENS_ACC_YOFF"), &(accel_offset[1]))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting Y accel offset failed!"); + } + + if (param_set(param_find("SENS_ACC_ZOFF"), &(accel_offset[2]))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting Z accel offset failed!"); + } + + if (param_set(param_find("SENS_ACC_XSCALE"), &(scale))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting X accel offset failed!"); + } + + if (param_set(param_find("SENS_ACC_YSCALE"), &(scale))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting Y accel offset failed!"); + } + + if (param_set(param_find("SENS_ACC_ZSCALE"), &(scale))) { + mavlink_log_critical(mavlink_fd, "[commander] Setting Z accel offset failed!"); + } + + fd = open(ACCEL_DEVICE_PATH, 0); + struct accel_scale ascale = { + accel_offset[0], + scale, + accel_offset[1], + scale, + accel_offset[2], + scale, + }; + if (OK != ioctl(fd, ACCELIOCSSCALE, (long unsigned int)&ascale)) + warn("WARNING: failed to set scale / offsets for accel"); + close(fd); + + /* exit to gyro calibration mode */ + status->flag_preflight_accel_calibration = false; + state_machine_publish(status_pub, status, mavlink_fd); + + // char offset_output[50]; + // sprintf(offset_output, "[commander] accel cal: x:%8.4f y:%8.4f z:%8.4f", (double)accel_offset[0], + // (double)accel_offset[1], (double)accel_offset[2]); + // mavlink_log_info(mavlink_fd, offset_output); + + close(sub_sensor_combined); } @@ -572,6 +805,24 @@ void handle_command(int status_pub, struct vehicle_status_s *current_vehicle_sta handled = true; } + /* accel calibration */ + if ((int)(cmd->param5) == 1) { + /* transition to calibration state */ + do_state_update(status_pub, ¤t_status, mavlink_fd, SYSTEM_STATE_PREFLIGHT); + + if (current_status.state_machine == SYSTEM_STATE_PREFLIGHT) { + mavlink_log_info(mavlink_fd, "[commander] CMD starting accel calibration"); + do_accel_calibration(status_pub, ¤t_status); + mavlink_log_info(mavlink_fd, "[commander] CMD finished accel calibration"); + do_state_update(status_pub, ¤t_status, mavlink_fd, SYSTEM_STATE_STANDBY); + result = MAV_RESULT_ACCEPTED; + } else { + mavlink_log_critical(mavlink_fd, "[commander] REJECTING accel calibration"); + result = MAV_RESULT_DENIED; + } + handled = true; + } + /* none found */ if (!handled) { //fprintf(stderr, "[commander] refusing unsupported calibration request\n"); @@ -581,44 +832,11 @@ void handle_command(int status_pub, struct vehicle_status_s *current_vehicle_sta } break; - /* preflight parameter load / store */ - case MAV_CMD_PREFLIGHT_STORAGE: { - /* Read all parameters from EEPROM to RAM */ - - if (((int)cmd->param1) == 0) { - - if (OK == get_params_from_eeprom(global_data_parameter_storage)) { - //printf("[commander] Loaded EEPROM params in RAM\n"); - mavlink_log_info(mavlink_fd, "[commander] CMD Loaded EEPROM params in RAM"); - result = MAV_RESULT_ACCEPTED; - - } else { - //fprintf(stderr, "[commander] ERROR loading EEPROM params in RAM\n"); - mavlink_log_critical(mavlink_fd, "[commander] ERROR loading EEPROM params in RAM"); - result = MAV_RESULT_FAILED; - } - - /* Write all parameters from RAM to EEPROM */ - - } else if (((int)cmd->param1) == 1) { - - if (OK == store_params_in_eeprom(global_data_parameter_storage)) { - //printf("[commander] RAM params written to EEPROM\n"); - mavlink_log_info(mavlink_fd, "[commander] RAM params written to EEPROM"); - result = MAV_RESULT_ACCEPTED; - - } else { - //fprintf(stderr, "[commander] ERROR writing RAM params to EEPROM\n"); - mavlink_log_critical(mavlink_fd, "[commander] ERROR writing RAM params to EEPROM"); - result = MAV_RESULT_FAILED; - } - - } else { - //fprintf(stderr, "[commander] refusing unsupported storage request\n"); - mavlink_log_critical(mavlink_fd, "[commander] refusing unsupported storage request"); - result = MAV_RESULT_UNSUPPORTED; - } - } + /* + * do not report an error for commands that are + * handled directly by MAVLink. + */ + case MAV_CMD_PREFLIGHT_STORAGE: break; default: { @@ -634,6 +852,7 @@ void handle_command(int status_pub, struct vehicle_status_s *current_vehicle_sta /* send any requested ACKs */ if (cmd->confirmation > 0) { /* send acknowledge command */ + // XXX TODO } } @@ -650,7 +869,7 @@ static void *command_handling_loop(void *arg) int cmd_sub = orb_subscribe(ORB_ID(vehicle_command)); struct vehicle_command_s cmd; - while (1) { + while (!thread_should_exit) { struct pollfd fds[1] = { { .fd = cmd_sub, .events = POLLIN } }; if (poll(fds, 1, 5000) == 0) { @@ -664,71 +883,37 @@ static void *command_handling_loop(void *arg) } } + close(cmd_sub); + return NULL; } -// static void *subsystem_info_loop(void *arg) //handles status information coming from subsystems (present, enabled, health), these values do not indicate the quality (variance) of the signal -// { -// /* Set thread name */ -// prctl(PR_SET_NAME, "commander subsys", getpid()); +static void *orb_receive_loop(void *arg) //handles status information coming from subsystems (present, enabled, health), these values do not indicate the quality (variance) of the signal +{ + /* Set thread name */ + prctl(PR_SET_NAME, "commander orb rcv", getpid()); -// uint8_t current_info_local = SUBSYSTEM_INFO_BUFFER_SIZE; -// uint16_t total_counter = 0; + /* Subscribe to command topic */ + int subsys_sub = orb_subscribe(ORB_ID(subsystem_info)); + struct subsystem_info_s info; -// while (1) { + while (!thread_should_exit) { + struct pollfd fds[1] = { { .fd = subsys_sub, .events = POLLIN } }; -// if (0 == global_data_wait(&global_data_subsystem_info->access_conf)) { -// // printf("got subsystem_info\n"); + if (poll(fds, 1, 5000) == 0) { + /* timeout, but this is no problem, silently ignore */ + } else { + /* got command */ + orb_copy(ORB_ID(subsystem_info), subsys_sub, &info); -// while (current_info_local != global_data_subsystem_info->current_info) { -// // printf("current_info_local = %d, current_info = %d \n", current_info_local, global_data_subsystem_info->current_info); + printf("Subsys changed: %d\n", (int)info.subsystem_type); + } + } -// current_info_local++; + close(subsys_sub); -// if (current_info_local >= SUBSYSTEM_INFO_BUFFER_SIZE) -// current_info_local = 0; - -// /* Handle the new subsystem info and write updated version of global_data_sys_status */ -// subsystem_info_t *info = &(global_data_subsystem_info->info[current_info_local]); - -// // printf("Commander got subsystem info: %d %d %d\n", info->present, info->enabled, info->health); - - -// if (info->present != 0) { -// update_state_machine_subsystem_present(stat_pub, ¤t_status, &info->subsystem_type); - -// } else { -// update_state_machine_subsystem_notpresent(stat_pub, ¤t_status, &info->subsystem_type); -// } - -// if (info->enabled != 0) { -// update_state_machine_subsystem_enabled(stat_pub, ¤t_status, &info->subsystem_type); - -// } else { -// update_state_machine_subsystem_disabled(stat_pub, ¤t_status, &info->subsystem_type); -// } - -// if (info->health != 0) { -// update_state_machine_subsystem_healthy(stat_pub, ¤t_status, &info->subsystem_type); - -// } else { -// update_state_machine_subsystem_unhealthy(stat_pub, ¤t_status, &info->subsystem_type); -// } - -// total_counter++; -// } - -// if (global_data_subsystem_info->counter - total_counter > SUBSYSTEM_INFO_BUFFER_SIZE) { -// printf("[commander] Warning: Too many subsystem status updates, subsystem_info buffer full\n"); //TODO: add to error queue -// global_data_subsystem_info->counter = total_counter; //this makes sure we print the warning only once -// } - -// global_data_unlock(&global_data_subsystem_info->access_conf); -// } -// } - -// return NULL; -// } + return NULL; +} @@ -745,13 +930,31 @@ enum BAT_CHEM { */ float battery_remaining_estimate_voltage(int cells, int chemistry, float voltage); +PARAM_DEFINE_FLOAT(BAT_V_EMPTY, 3.2f); +PARAM_DEFINE_FLOAT(BAT_V_FULL, 4.05f); + float battery_remaining_estimate_voltage(int cells, int chemistry, float voltage) { float ret = 0; - // XXX do this properly - // XXX rebase on parameters - const float chemistry_voltage_empty[] = {3.2f}; - const float chemistry_voltage_full[] = {4.05f}; + static param_t bat_volt_empty; + static param_t bat_volt_full; + static bool initialized = false; + static unsigned int counter = 0; + + if (!initialized) { + bat_volt_empty = param_find("BAT_V_EMPTY"); + bat_volt_full = param_find("BAT_V_FULL"); + initialized = true; + } + + float chemistry_voltage_empty[1] = { 3.2f }; + float chemistry_voltage_full[1] = { 4.05f }; + + if (counter % 100 == 0) { + param_get(bat_volt_empty, &(chemistry_voltage_empty[0])); + param_get(bat_volt_full, &(chemistry_voltage_full[0])); + } + counter++; ret = (voltage - cells * chemistry_voltage_empty[chemistry]) / (cells * (chemistry_voltage_full[chemistry] - chemistry_voltage_empty[chemistry])); @@ -761,11 +964,61 @@ float battery_remaining_estimate_voltage(int cells, int chemistry, float voltage return ret; } -/**************************************************************************** - * Name: commander - ****************************************************************************/ +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: deamon {start|stop|status} [-p ]\n\n"); + exit(1); +} +/** + * The deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ int commander_main(int argc, char *argv[]) +{ + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1], "start")) { + + if (thread_running) { + printf("commander already running\n"); + /* this is not an error */ + exit(0); + } + + thread_should_exit = false; + deamon_task = task_create("commander", SCHED_PRIORITY_MAX - 50, 4096, commander_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tcommander is running\n"); + } else { + printf("\tcommander not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} + +int commander_thread_main(int argc, char *argv[]) { /* not yet initialized */ commander_initialized = false; @@ -773,9 +1026,9 @@ int commander_main(int argc, char *argv[]) /* welcome user */ printf("[commander] I am in command now!\n"); - /* Pthreads */ + /* pthreads for command and subsystem info handling */ pthread_t command_handling_thread; - // pthread_t subsystem_info_thread; + pthread_t subsystem_info_thread; /* initialize */ if (led_init() != 0) { @@ -809,33 +1062,23 @@ int commander_main(int argc, char *argv[]) mavlink_log_info(mavlink_fd, "[commander] system is running"); - /* load EEPROM parameters */ - if (OK == get_params_from_eeprom(global_data_parameter_storage)) { - printf("[commander] Loaded EEPROM params in RAM\n"); - mavlink_log_info(mavlink_fd, "[commander] Loaded EEPROM params in RAM"); - - } else { - fprintf(stderr, "[commander] ERROR loading EEPROM params in RAM\n"); - mavlink_log_critical(mavlink_fd, "[commander] ERROR loading EEPROM params in RAM"); - } - /* create pthreads */ pthread_attr_t command_handling_attr; pthread_attr_init(&command_handling_attr); - pthread_attr_setstacksize(&command_handling_attr, 4096); + pthread_attr_setstacksize(&command_handling_attr, 6000); pthread_create(&command_handling_thread, &command_handling_attr, command_handling_loop, NULL); - // pthread_attr_t subsystem_info_attr; - // pthread_attr_init(&subsystem_info_attr); - // pthread_attr_setstacksize(&subsystem_info_attr, 2048); - // pthread_create(&subsystem_info_thread, &subsystem_info_attr, subsystem_info_loop, NULL); + pthread_attr_t subsystem_info_attr; + pthread_attr_init(&subsystem_info_attr); + pthread_attr_setstacksize(&subsystem_info_attr, 2048); + pthread_create(&subsystem_info_thread, &subsystem_info_attr, orb_receive_loop, NULL); /* Start monitoring loop */ uint16_t counter = 0; uint8_t flight_env; - // uint8_t fix_type; + /* Initialize to 3.0V to make sure the low-pass loads below valid threshold */ - float battery_voltage = VOLTAGE_BATTERY_HIGH_VOLTS; + float battery_voltage = 12.0f; bool battery_voltage_valid = true; bool low_battery_voltage_actions_done = false; bool critical_battery_voltage_actions_done = false; @@ -844,9 +1087,6 @@ int commander_main(int argc, char *argv[]) int16_t mode_switch_rc_value; float bat_remain = 1.0f; -// bool arm_done = false; -// bool disarm_done = false; - uint16_t stick_off_counter = 0; uint16_t stick_on_counter = 0; @@ -875,7 +1115,9 @@ int commander_main(int argc, char *argv[]) /* now initialized */ commander_initialized = true; - while (1) { + uint64_t start_time = hrt_absolute_time(); + + while (!thread_should_exit) { /* Get current values */ orb_copy(ORB_ID(rc_channels), rc_sub, &rc); @@ -884,9 +1126,14 @@ int commander_main(int argc, char *argv[]) battery_voltage = sensors.battery_voltage_v; battery_voltage_valid = sensors.battery_voltage_valid; - bat_remain = battery_remaining_estimate_voltage(3, BAT_CHEM_LITHIUM_POLYMERE, battery_voltage); -// flight_env = (uint8_t)(global_data_parameter_storage->pm.param_values[PARAM_FLIGHT_ENV]); + /* + * Only update battery voltage estimate if voltage is + * valid and system has been running for two and a half seconds + */ + if (battery_voltage_valid && (hrt_absolute_time() - start_time > 2500000)) { + bat_remain = battery_remaining_estimate_voltage(3, BAT_CHEM_LITHIUM_POLYMERE, battery_voltage); + } /* Slow but important 8 Hz checks */ if (counter % ((1000000 / COMMANDER_MONITORING_INTERVAL) / 8) == 0) { @@ -912,13 +1159,13 @@ int commander_main(int argc, char *argv[]) led_toggle(LED_AMBER); } else { - /* Constant error indication in standby mode without GPS */ - if (flight_env == PX4_FLIGHT_ENVIRONMENT_OUTDOOR && !current_status.gps_valid) { - led_on(LED_AMBER); + // /* Constant error indication in standby mode without GPS */ + // if (!current_status.gps_valid) { + // led_on(LED_AMBER); - } else { - led_off(LED_AMBER); - } + // } else { + // led_off(LED_AMBER); + // } } if (counter % (1000000 / COMMANDER_MONITORING_INTERVAL) == 0) { @@ -951,6 +1198,38 @@ int commander_main(int argc, char *argv[]) ioctl(buzzer, TONE_SET_ALARM, 0); } + /* Check battery voltage */ + /* write to sys_status */ + current_status.voltage_battery = battery_voltage; + + /* if battery voltage is getting lower, warn using buzzer, etc. */ + if (battery_voltage_valid && (bat_remain < 0.15f /* XXX MAGIC NUMBER */) && (false == low_battery_voltage_actions_done)) { //TODO: add filter, or call emergency after n measurements < VOLTAGE_BATTERY_MINIMAL_MILLIVOLTS + + if (low_voltage_counter > LOW_VOLTAGE_BATTERY_COUNTER_LIMIT) { + low_battery_voltage_actions_done = true; + mavlink_log_critical(mavlink_fd, "[commander] WARNING! LOW BATTERY!"); + } + + low_voltage_counter++; + } + + /* Critical, this is rather an emergency, kill signal to sdlog and change state machine */ + else if (battery_voltage_valid && (bat_remain < 0.1f /* XXX MAGIC NUMBER */) && (false == critical_battery_voltage_actions_done && true == low_battery_voltage_actions_done)) { + if (critical_voltage_counter > CRITICAL_VOLTAGE_BATTERY_COUNTER_LIMIT) { + critical_battery_voltage_actions_done = true; + mavlink_log_critical(mavlink_fd, "[commander] EMERGENCY! CIRITICAL BATTERY!"); + state_machine_emergency(stat_pub, ¤t_status, mavlink_fd); + } + + critical_voltage_counter++; + + } else { + low_voltage_counter = 0; + critical_voltage_counter = 0; + } + + /* End battery voltage check */ + /* Check if last transition deserved an audio event */ #warning This code depends on state that is no longer? maintained #if 0 @@ -1009,39 +1288,9 @@ int commander_main(int argc, char *argv[]) //update_state_machine_got_position_fix(stat_pub, ¤t_status, mavlink_fd); /* end: check gps */ - /* Check battery voltage */ - /* write to sys_status */ - current_status.voltage_battery = battery_voltage; - - /* if battery voltage is getting lower, warn using buzzer, etc. */ - if (battery_voltage_valid && (battery_voltage < VOLTAGE_BATTERY_LOW_VOLTS && false == low_battery_voltage_actions_done)) { //TODO: add filter, or call emergency after n measurements < VOLTAGE_BATTERY_MINIMAL_MILLIVOLTS - - if (low_voltage_counter > LOW_VOLTAGE_BATTERY_COUNTER_LIMIT) { - low_battery_voltage_actions_done = true; - mavlink_log_critical(mavlink_fd, "[commander] WARNING! LOW BATTERY!"); - } - - low_voltage_counter++; - } - - /* Critical, this is rather an emergency, kill signal to sdlog and change state machine */ - else if (battery_voltage_valid && (battery_voltage < VOLTAGE_BATTERY_CRITICAL_VOLTS && false == critical_battery_voltage_actions_done && true == low_battery_voltage_actions_done)) { - if (critical_voltage_counter > CRITICAL_VOLTAGE_BATTERY_COUNTER_LIMIT) { - critical_battery_voltage_actions_done = true; - mavlink_log_critical(mavlink_fd, "[commander] EMERGENCY! CIRITICAL BATTERY!"); - state_machine_emergency(stat_pub, ¤t_status, mavlink_fd); - } - - critical_voltage_counter++; - - } else { - low_voltage_counter = 0; - critical_voltage_counter = 0; - } - - /* End battery voltage check */ /* Start RC state check */ + bool prev_lost = current_status.rc_signal_lost; if (rc.chan_count > 4 && (hrt_absolute_time() - rc.timestamp) < 100000) { @@ -1106,10 +1355,18 @@ int commander_main(int argc, char *argv[]) /* flag as lost and update interval since when the signal was lost (to initiate RTL after some time) */ current_status.rc_signal_cutting_off = true; current_status.rc_signal_lost_interval = hrt_absolute_time() - rc.timestamp; + /* if the RC signal is gone for a full second, consider it lost */ if (current_status.rc_signal_lost_interval > 1000000) current_status.rc_signal_lost = true; } + /* Check if this is the first loss or first gain*/ + if ((!prev_lost && current_status.rc_signal_lost) || + prev_lost && !current_status.rc_signal_lost) { + /* publish rc lost */ + publish_armed_status(¤t_status); + } + /* End mode switch */ /* END RC state check */ @@ -1121,8 +1378,9 @@ int commander_main(int argc, char *argv[]) /* If full run came back clean, transition to standby */ if (current_status.state_machine == SYSTEM_STATE_PREFLIGHT && - current_status.preflight_gyro_calibration == false && - current_status.preflight_mag_calibration == false) { + current_status.flag_preflight_gyro_calibration == false && + current_status.flag_preflight_mag_calibration == false && + current_status.flag_preflight_accel_calibration == false) { /* All ok, no calibration going on, go to standby */ do_state_update(stat_pub, ¤t_status, mavlink_fd, SYSTEM_STATE_STANDBY); } @@ -1142,11 +1400,19 @@ int commander_main(int argc, char *argv[]) /* wait for threads to complete */ pthread_join(command_handling_thread, NULL); - // pthread_join(subsystem_info_thread, NULL); + pthread_join(subsystem_info_thread, NULL); /* close fds */ led_deinit(); buzzer_deinit(); + close(rc_sub); + close(gps_sub); + close(sensor_sub); + + printf("[commander] exiting..\n"); + fflush(stdout); + + thread_running = false; return 0; } diff --git a/apps/commander/commander.h b/apps/commander/commander.h index d537a0602c..e9e3b24ca3 100644 --- a/apps/commander/commander.h +++ b/apps/commander/commander.h @@ -39,8 +39,6 @@ #ifndef COMMANDER_H_ #define COMMANDER_H_ -#define VOLTAGE_BATTERY_HIGH_VOLTS 12.0f -#define VOLTAGE_BATTERY_LOW_VOLTS 10.5f #define VOLTAGE_BATTERY_CRITICAL_VOLTS 10.0f #define LOW_VOLTAGE_BATTERY_HYSTERESIS_TIME_MS 1000.0f #define CRITICAL_VOLTAGE_BATTERY_HYSTERESIS_TIME_MS 100.0f diff --git a/apps/commander/state_machine_helper.c b/apps/commander/state_machine_helper.c index 3209ee728d..da85d0868e 100644 --- a/apps/commander/state_machine_helper.c +++ b/apps/commander/state_machine_helper.c @@ -39,14 +39,17 @@ */ #include -#include "state_machine_helper.h" +#include #include #include +#include #include #include #include +#include "state_machine_helper.h" + static const char* system_state_txt[] = { "SYSTEM_STATE_PREFLIGHT", "SYSTEM_STATE_STANDBY", @@ -75,14 +78,12 @@ int do_state_update(int status_pub, struct vehicle_status_s *current_status, con switch (new_state) { case SYSTEM_STATE_MISSION_ABORT: { /* Indoor or outdoor */ - uint8_t flight_environment_parameter = (uint8_t)(global_data_parameter_storage->pm.param_values[PARAM_FLIGHT_ENV]); - - if (flight_environment_parameter == PX4_FLIGHT_ENVIRONMENT_OUTDOOR) { + // if (flight_environment_parameter == PX4_FLIGHT_ENVIRONMENT_OUTDOOR) { ret = do_state_update(status_pub, current_status, mavlink_fd, (commander_state_machine_t)SYSTEM_STATE_EMCY_LANDING); - } else { - ret = do_state_update(status_pub, current_status, mavlink_fd, (commander_state_machine_t)SYSTEM_STATE_EMCY_CUTOFF); - } + // } else { + // ret = do_state_update(status_pub, current_status, mavlink_fd, (commander_state_machine_t)SYSTEM_STATE_EMCY_CUTOFF); + // } } break; @@ -121,7 +122,7 @@ int do_state_update(int status_pub, struct vehicle_status_s *current_status, con if (current_status->state_machine == SYSTEM_STATE_STANDBY || current_status->state_machine == SYSTEM_STATE_PREFLIGHT) { /* set system flags according to state */ - current_status->flag_system_armed = true; + current_status->flag_system_armed = false; mavlink_log_critical(mavlink_fd, "[commander] Switched to PREFLIGHT state"); } else { invalid_state = true; @@ -198,10 +199,14 @@ int do_state_update(int status_pub, struct vehicle_status_s *current_status, con if (invalid_state == false || old_state != new_state) { current_status->state_machine = new_state; state_machine_publish(status_pub, current_status, mavlink_fd); + publish_armed_status(current_status); + ret = OK; } if (invalid_state) { mavlink_log_critical(mavlink_fd, "[commander] REJECTING invalid state transition"); + ret = ERROR; } + return ret; } void state_machine_publish(int status_pub, struct vehicle_status_s *current_status, const int mavlink_fd) { @@ -212,6 +217,17 @@ void state_machine_publish(int status_pub, struct vehicle_status_s *current_stat printf("[commander] new state: %s\n", system_state_txt[current_status->state_machine]); } +void publish_armed_status(const struct vehicle_status_s *current_status) { + struct actuator_armed_s armed; + armed.armed = current_status->flag_system_armed; + /* lock down actuators if required */ + // XXX FIXME Currently any loss of RC will completely disable all actuators + // needs proper failsafe + armed.lockdown = (current_status->rc_signal_lost || current_status->flag_hil_enabled) ? true : false; + orb_advert_t armed_pub = orb_advertise(ORB_ID(actuator_armed), &armed); + orb_publish(ORB_ID(actuator_armed), armed_pub, &armed); +} + /* * Private functions, update the state machine @@ -485,6 +501,8 @@ void update_state_machine_mode_manual(int status_pub, struct vehicle_status_s *c int old_mode = current_status->flight_mode; current_status->flight_mode = VEHICLE_FLIGHT_MODE_MANUAL; current_status->flag_control_manual_enabled = true; + /* enable attitude control per default */ + current_status->flag_control_attitude_enabled = true; if (old_mode != current_status->flight_mode) state_machine_publish(status_pub, current_status, mavlink_fd); if (current_status->state_machine == SYSTEM_STATE_GROUND_READY || current_status->state_machine == SYSTEM_STATE_STABILIZED || current_status->state_machine == SYSTEM_STATE_AUTO) { @@ -522,7 +540,7 @@ void update_state_machine_mode_auto(int status_pub, struct vehicle_status_s *cur uint8_t update_state_machine_mode_request(int status_pub, struct vehicle_status_s *current_status, const int mavlink_fd, uint8_t mode) { - printf("in update state request\n"); + printf("[commander] Requested new mode: %d\n", (int)mode); uint8_t ret = 1; /* vehicle is disarmed, mode requests arming */ @@ -546,13 +564,15 @@ uint8_t update_state_machine_mode_request(int status_pub, struct vehicle_status_ } } - /* Switch on HIL if in standby */ - if ((current_status->state_machine == SYSTEM_STATE_STANDBY) && (mode & VEHICLE_MODE_FLAG_HIL_ENABLED)) { + /* Switch on HIL if in standby and not already in HIL mode */ + if ((current_status->state_machine == SYSTEM_STATE_STANDBY) && (mode & VEHICLE_MODE_FLAG_HIL_ENABLED) + && !current_status->flag_hil_enabled) { /* Enable HIL on request */ current_status->flag_hil_enabled = true; ret = OK; state_machine_publish(status_pub, current_status, mavlink_fd); - printf("[commander] Enabling HIL\n"); + publish_armed_status(current_status); + printf("[commander] Enabling HIL, locking down all actuators for safety.\n\t(Arming the system will not activate them while in HIL mode)\n"); } /* NEVER actually switch off HIL without reboot */ diff --git a/apps/commander/state_machine_helper.h b/apps/commander/state_machine_helper.h index 4908c799ad..c4d1b78a57 100644 --- a/apps/commander/state_machine_helper.h +++ b/apps/commander/state_machine_helper.h @@ -188,6 +188,12 @@ void state_machine_emergency_always_critical(int status_pub, struct vehicle_stat */ void state_machine_emergency(int status_pub, struct vehicle_status_s *current_status, const int mavlink_fd); +/** + * Publish the armed state depending on the current system state + * + * @param current_status the current system status + */ +void publish_armed_status(const struct vehicle_status_s *current_status); diff --git a/apps/drivers/bma180/bma180.cpp b/apps/drivers/bma180/bma180.cpp index a5d66d86b3..8cd7f6a7c7 100644 --- a/apps/drivers/bma180/bma180.cpp +++ b/apps/drivers/bma180/bma180.cpp @@ -32,17 +32,17 @@ ****************************************************************************/ /** - * @file Driver for the Bosch BMA 180 MEMS accelerometer connected via SPI. + * @file bma180.cpp + * Driver for the Bosch BMA 180 MEMS accelerometer connected via SPI. */ #include -#include - #include #include #include #include +#include #include #include #include @@ -52,14 +52,74 @@ #include #include +#include +#include #include #include #include #include +#include +#include #include + +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +static const int ERROR = -1; + +#define DIR_READ (1<<7) +#define DIR_WRITE (0<<7) + +#define ADDR_CHIP_ID 0x00 +#define CHIP_ID 0x03 + +#define ADDR_ACC_X_LSB 0x02 +#define ADDR_ACC_Y_LSB 0x04 +#define ADDR_ACC_Z_LSB 0x06 +#define ADDR_TEMPERATURE 0x08 + +#define ADDR_CTRL_REG0 0x0D +#define REG0_WRITE_ENABLE 0x10 + +#define ADDR_RESET 0x10 +#define SOFT_RESET 0xB6 + +#define ADDR_BW_TCS 0x20 +#define BW_TCS_BW_MASK (0xf<<4) +#define BW_TCS_BW_10HZ (0<<4) +#define BW_TCS_BW_20HZ (1<<4) +#define BW_TCS_BW_40HZ (2<<4) +#define BW_TCS_BW_75HZ (3<<4) +#define BW_TCS_BW_150HZ (4<<4) +#define BW_TCS_BW_300HZ (5<<4) +#define BW_TCS_BW_600HZ (6<<4) +#define BW_TCS_BW_1200HZ (7<<4) + +#define ADDR_HIGH_DUR 0x27 +#define HIGH_DUR_DIS_I2C (1<<0) + +#define ADDR_TCO_Z 0x30 +#define TCO_Z_MODE_MASK 0x3 + +#define ADDR_GAIN_Y 0x33 +#define GAIN_Y_SHADOW_DIS (1<<0) + +#define ADDR_OFFSET_LSB1 0x35 +#define OFFSET_LSB1_RANGE_MASK (7<<1) +#define OFFSET_LSB1_RANGE_1G (0<<1) +#define OFFSET_LSB1_RANGE_2G (2<<1) +#define OFFSET_LSB1_RANGE_3G (3<<1) +#define OFFSET_LSB1_RANGE_4G (4<<1) +#define OFFSET_LSB1_RANGE_8G (5<<1) +#define OFFSET_LSB1_RANGE_16G (6<<1) + +#define ADDR_OFFSET_T 0x37 +#define OFFSET_T_READOUT_12BIT (1<<0) + extern "C" { __EXPORT int bma180_main(int argc, char *argv[]); } class BMA180 : public device::SPI @@ -73,9 +133,6 @@ public: virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); virtual int ioctl(struct file *filp, int cmd, unsigned long arg); - virtual int open_first(struct file *filp); - virtual int close_last(struct file *filp); - /** * Diagnostics - print some basic information about the driver. */ @@ -94,10 +151,15 @@ private: volatile unsigned _oldest_report; struct accel_report *_reports; - struct accel_scale _scale; - float _range_scale; + struct accel_scale _accel_scale; + float _accel_range_scale; + float _accel_range_m_s2; + orb_advert_t _accel_topic; - unsigned _reads; + unsigned _current_lowpass; + unsigned _current_range; + + perf_counter_t _sample_perf; /** * Start automatic measurement. @@ -161,88 +223,44 @@ private: int set_range(unsigned max_g); /** - * Set the BMA180 lowpass filter. + * Set the BMA180 internal lowpass filter frequency. * - * @param frequency Set the lowpass filter cutoff frequency to no less than - * this frequency. + * @param frequency The internal lowpass filter frequency is set to a value + * equal or greater to this. + * Zero selects the highest frequency supported. * @return OK if the value can be supported. */ - int set_bandwidth(unsigned frequency); + int set_lowpass(unsigned frequency); }; /* helper macro for handling report buffer indices */ #define INCREMENT(_x, _lim) do { _x++; if (_x >= _lim) _x = 0; } while(0) -#define DIR_READ (1<<7) -#define DIR_WRITE (0<<7) - -#define ADDR_CHIP_ID 0x00 -#define CHIP_ID 0x03 - -#define ADDR_ACC_X_LSB 0x02 -#define ADDR_ACC_Y_LSB 0x04 -#define ADDR_ACC_Z_LSB 0x06 -#define ADDR_TEMPERATURE 0x08 - -#define ADDR_RESET 0x10 -#define SOFT_RESET 0xB6 - -#define ADDR_BW_TCS 0x20 -#define BW_TCS_BW_MASK (0xf<<4) -#define BW_TCS_BW_10HZ (0<<4) -#define BW_TCS_BW_20HZ (1<<4) -#define BW_TCS_BW_40HZ (2<<4) -#define BW_TCS_BW_75HZ (3<<4) -#define BW_TCS_BW_150HZ (4<<4) -#define BW_TCS_BW_300HZ (5<<4) -#define BW_TCS_BW_600HZ (6<<4) -#define BW_TCS_BW_1200HZ (7<<4) - -#define ADDR_HIGH_DUR 0x27 -#define HIGH_DUR_DIS_I2C (1<<0) - -#define ADDR_TCO_Z 0x30 -#define TCO_Z_MODE_MASK 0x3 - -#define ADDR_GAIN_Y 0x33 -#define GAIN_Y_SHADOW_DIS (1<<0) - -#define ADDR_OFFSET_LSB1 0x35 -#define OFFSET_LSB1_RANGE_MASK (7<<1) -#define OFFSET_LSB1_RANGE_1G (0<<1) -#define OFFSET_LSB1_RANGE_2G (2<<1) -#define OFFSET_LSB1_RANGE_3G (3<<1) -#define OFFSET_LSB1_RANGE_4G (4<<1) -#define OFFSET_LSB1_RANGE_8G (5<<1) -#define OFFSET_LSB1_RANGE_16G (6<<1) - -#define ADDR_OFFSET_T 0x37 -#define OFFSET_T_READOUT_12BIT (1<<0) - -/* - * Driver 'main' command. - */ -extern "C" { int bma180_main(int argc, char *argv[]); } - BMA180::BMA180(int bus, spi_dev_e device) : SPI("BMA180", ACCEL_DEVICE_PATH, bus, device, SPIDEV_MODE3, 8000000), + _call_interval(0), _num_reports(0), _next_report(0), _oldest_report(0), _reports(nullptr), - _reads(0) + _accel_range_scale(0.0f), + _accel_range_m_s2(0.0f), + _accel_topic(-1), + _current_lowpass(0), + _current_range(0), + _sample_perf(perf_alloc(PC_ELAPSED, "bma180_read")) { // enable debug() calls _debug_enabled = true; // default scale factors - _scale.x_offset = 0; - _scale.x_scale = 1.0f; - _scale.y_offset = 0; - _scale.y_scale = 1.0f; - _scale.z_offset = 0; - _scale.z_scale = 1.0f; + _accel_scale.x_offset = 0; + _accel_scale.x_scale = 1.0f; + _accel_scale.y_offset = 0; + _accel_scale.y_scale = 1.0f; + _accel_scale.z_offset = 0; + _accel_scale.z_scale = 1.0f; } BMA180::~BMA180() @@ -253,77 +271,73 @@ BMA180::~BMA180() /* free any existing reports */ if (_reports != nullptr) delete[] _reports; + + /* delete the perf counter */ + perf_free(_sample_perf); } int BMA180::init() { - int ret; + int ret = ERROR; /* do SPI init (and probe) first */ - ret = SPI::init(); - - /* if probe/setup successful, finish chip init */ - if (ret == OK) { - - /* perform soft reset (p48) */ - write_reg(ADDR_RESET, SOFT_RESET); - - /* wait 10us (p49) */ - usleep(10); - - /* disable I2C interface */ - modify_reg(ADDR_HIGH_DUR, HIGH_DUR_DIS_I2C, 0); - - /* switch to low-noise mode */ - modify_reg(ADDR_TCO_Z, TCO_Z_MODE_MASK, 0); - - /* disable 12-bit mode */ - modify_reg(ADDR_OFFSET_T, OFFSET_T_READOUT_12BIT, 0); - - /* disable shadow-disable mode */ - modify_reg(ADDR_GAIN_Y, GAIN_Y_SHADOW_DIS, 0); - } - - return ret; -} - -int -BMA180::open_first(struct file *filp) -{ - /* reset to manual-poll mode */ - _call_interval = 0; + if (SPI::init() != OK) + goto out; /* allocate basic report buffers */ _num_reports = 2; - _reports = new struct accel_report[_num_reports]; _oldest_report = _next_report = 0; + _reports = new struct accel_report[_num_reports]; + if (_reports == nullptr) + goto out; - /* set default range and lowpass */ - set_range(4); /* 4G */ - set_bandwidth(600); /* 600Hz */ + /* advertise sensor topic */ + memset(&_reports[0], 0, sizeof(_reports[0])); + _accel_topic = orb_advertise(ORB_ID(sensor_accel), &_reports[0]); - return OK; -} + /* perform soft reset (p48) */ + write_reg(ADDR_RESET, SOFT_RESET); -int -BMA180::close_last(struct file *filp) -{ - /* stop measurement */ - stop(); + /* wait 10 ms (datasheet incorrectly lists 10 us on page 49) */ + usleep(10000); - /* free report buffers */ - if (_reports != nullptr) { - delete[] _reports; - _num_reports = 0; + /* enable writing to chip config */ + modify_reg(ADDR_CTRL_REG0, 0, REG0_WRITE_ENABLE); + + /* disable I2C interface */ + modify_reg(ADDR_HIGH_DUR, HIGH_DUR_DIS_I2C, 0); + + /* switch to low-noise mode */ + modify_reg(ADDR_TCO_Z, TCO_Z_MODE_MASK, 0); + + /* disable 12-bit mode */ + modify_reg(ADDR_OFFSET_T, OFFSET_T_READOUT_12BIT, 0); + + /* disable shadow-disable mode */ + modify_reg(ADDR_GAIN_Y, GAIN_Y_SHADOW_DIS, 0); + + /* disable writing to chip config */ + modify_reg(ADDR_CTRL_REG0, REG0_WRITE_ENABLE, 0); + + if (set_range(4)) warnx("Failed setting range"); + if (set_lowpass(75)) warnx("Failed setting lowpass"); + + if (read_reg(ADDR_CHIP_ID) == CHIP_ID) { + ret = OK; + } else { + ret = ERROR; } - - return OK; +out: + return ret; } int BMA180::probe() { + /* dummy read to ensure SPI state machine is sane */ + read_reg(ADDR_CHIP_ID); + if (read_reg(ADDR_CHIP_ID) == CHIP_ID) return OK; @@ -356,8 +370,6 @@ BMA180::read(struct file *filp, char *buffer, size_t buflen) } } - _reads++; - /* if there was no data, warn the caller */ return ret ? ret : -EAGAIN; } @@ -378,22 +390,29 @@ BMA180::ioctl(struct file *filp, int cmd, unsigned long arg) { switch (cmd) { - case ACCELIOCSPOLLRATE: { + case SENSORIOCSPOLLRATE: { switch (arg) { /* switching to manual polling */ - case ACC_POLLRATE_MANUAL: + case SENSOR_POLLRATE_MANUAL: stop(); _call_interval = 0; return OK; /* external signalling not supported */ - case ACC_POLLRATE_EXTERNAL: + case SENSOR_POLLRATE_EXTERNAL: /* zero would be bad */ case 0: return -EINVAL; + + /* set default/max polling rate */ + case SENSOR_POLLRATE_MAX: + case SENSOR_POLLRATE_DEFAULT: + /* XXX 500Hz is just a wild guess */ + return ioctl(filp, SENSORIOCSPOLLRATE, 500); + /* adjust to a legal polling interval in Hz */ default: { /* do we need to start internal polling? */ @@ -408,7 +427,7 @@ BMA180::ioctl(struct file *filp, int cmd, unsigned long arg) /* update interval for next measurement */ /* XXX this is a bit shady, but no other way to adjust... */ - _call.period = _call_interval; + _call.period = _call_interval = ticks; /* if we need to start the poll state machine, do it */ if (want_start) @@ -419,7 +438,15 @@ BMA180::ioctl(struct file *filp, int cmd, unsigned long arg) } } - case ACCELIOCSQUEUEDEPTH: { + case SENSORIOCGPOLLRATE: + if (_call_interval == 0) + return SENSOR_POLLRATE_MANUAL; + return 1000000 / _call_interval; + + case SENSORIOCSQUEUEDEPTH: { + /* account for sentinel in the ring */ + arg++; + /* lower bound is mandatory, upper bound is a sanity check */ if ((arg < 2) || (arg > 100)) return -EINVAL; @@ -440,16 +467,41 @@ BMA180::ioctl(struct file *filp, int cmd, unsigned long arg) return OK; } - case ACCELIOCSLOWPASS: - return set_bandwidth(arg); + case SENSORIOCGQUEUEDEPTH: + return _num_reports -1; - case ACCELIORANGE: - return set_range(arg); + case SENSORIOCRESET: + /* XXX implement */ + return -EINVAL; case ACCELIOCSSAMPLERATE: /* sensor sample rate is not (really) adjustable */ - case ACCELIOCSREPORTFORMAT: /* no alternate report formats */ return -EINVAL; + case ACCELIOCGSAMPLERATE: + return 1200; /* always operating in low-noise mode */ + + case ACCELIOCSLOWPASS: + return set_lowpass(arg); + + case ACCELIOCGLOWPASS: + return _current_lowpass; + + case ACCELIOCSSCALE: + /* copy scale in */ + memcpy(&_accel_scale, (struct accel_scale*) arg, sizeof(_accel_scale)); + return OK; + + case ACCELIOCGSCALE: + /* copy scale out */ + memcpy((struct accel_scale*) arg, &_accel_scale, sizeof(_accel_scale)); + return OK; + + case ACCELIOCSRANGE: + return set_range(arg); + + case ACCELIOCGRANGE: + return _current_range; + default: /* give it to the superclass */ return SPI::ioctl(filp, cmd, arg); @@ -494,45 +546,51 @@ int BMA180::set_range(unsigned max_g) { uint8_t rangebits; - float rangescale; - if (max_g > 16) { + if (max_g == 0) + max_g = 16; + if (max_g > 16) return -ERANGE; - } else if (max_g > 8) { /* 16G */ - rangebits = OFFSET_LSB1_RANGE_16G; - rangescale = 1.98; - - } else if (max_g > 4) { /* 8G */ - rangebits = OFFSET_LSB1_RANGE_8G; - rangescale = 0.99; - - } else if (max_g > 3) { /* 4G */ - rangebits = OFFSET_LSB1_RANGE_4G; - rangescale = 0.5; - - } else if (max_g > 2) { /* 3G */ - rangebits = OFFSET_LSB1_RANGE_3G; - rangescale = 0.38; - - } else if (max_g > 1) { /* 2G */ + if (max_g <= 2) { + _current_range = 2; rangebits = OFFSET_LSB1_RANGE_2G; - rangescale = 0.25; - - } else { /* 1G */ - rangebits = OFFSET_LSB1_RANGE_1G; - rangescale = 0.13; + } else if (max_g <= 3) { + _current_range = 3; + rangebits = OFFSET_LSB1_RANGE_3G; + } else if (max_g <= 4) { + _current_range = 4; + rangebits = OFFSET_LSB1_RANGE_4G; + } else if (max_g <= 8) { + _current_range = 8; + rangebits = OFFSET_LSB1_RANGE_8G; + } else if (max_g <= 16) { + _current_range = 16; + rangebits = OFFSET_LSB1_RANGE_16G; + } else { + return -EINVAL; } + /* set new range scaling factor */ + _accel_range_m_s2 = _current_range * 9.80665f; + _accel_range_scale = _accel_range_m_s2 / 8192.0f; + + /* enable writing to chip config */ + modify_reg(ADDR_CTRL_REG0, 0, REG0_WRITE_ENABLE); + /* adjust sensor configuration */ modify_reg(ADDR_OFFSET_LSB1, OFFSET_LSB1_RANGE_MASK, rangebits); - _range_scale = rangescale; - return OK; + /* block writing to chip config */ + modify_reg(ADDR_CTRL_REG0, REG0_WRITE_ENABLE, 0); + + /* check if wanted value is now in register */ + return !((read_reg(ADDR_OFFSET_LSB1) & OFFSET_LSB1_RANGE_MASK) == + (OFFSET_LSB1_RANGE_MASK & rangebits)); } int -BMA180::set_bandwidth(unsigned frequency) +BMA180::set_lowpass(unsigned frequency) { uint8_t bwbits; @@ -564,10 +622,18 @@ BMA180::set_bandwidth(unsigned frequency) bwbits = BW_TCS_BW_10HZ; } + /* enable writing to chip config */ + modify_reg(ADDR_CTRL_REG0, 0, REG0_WRITE_ENABLE); + /* adjust sensor configuration */ modify_reg(ADDR_BW_TCS, BW_TCS_BW_MASK, bwbits); - return OK; + /* block writing to chip config */ + modify_reg(ADDR_CTRL_REG0, REG0_WRITE_ENABLE, 0); + + /* check if wanted value is now in register */ + return !((read_reg(ADDR_BW_TCS) & BW_TCS_BW_MASK) == + (BW_TCS_BW_MASK & bwbits)); } void @@ -601,24 +667,30 @@ BMA180::measure_trampoline(void *arg) void BMA180::measure() { - /* - * This evil is to deal with the stupid layout of the BMA180 - * measurement registers vs. the SPI transaction model. - */ - union { - uint8_t bytes[10]; - uint16_t words[5]; - } buf; + /* BMA180 measurement registers */ +// #pragma pack(push, 1) +// struct { +// uint8_t cmd; +// int16_t x; +// int16_t y; +// int16_t z; +// } raw_report; +// #pragma pack(pop) + + accel_report *report = &_reports[_next_report]; + + /* start the performance counter */ + perf_begin(_sample_perf); /* * Fetch the full set of measurements from the BMA180 in one pass; - * 7 bytes starting from the X LSB. + * starting from the X LSB. */ - buf.bytes[1] = ADDR_ACC_X_LSB; - transfer(&buf.bytes[1], &buf.bytes[1], 8); + //raw_report.cmd = ADDR_ACC_X_LSB; + // XXX PX4DEV transfer((uint8_t *)&raw_report, (uint8_t *)&raw_report, sizeof(raw_report)); /* - * Adjust and scale results to mg. + * Adjust and scale results to SI units. * * Note that we ignore the "new data" bits. At any time we read, each * of the axis measurements are the "most recent", even if we've seen @@ -626,13 +698,28 @@ BMA180::measure() * measurement flow without using the external interrupt. */ _reports[_next_report].timestamp = hrt_absolute_time(); - _reports[_next_report].x = (buf.words[1] >> 2) * _range_scale; - _reports[_next_report].y = (buf.words[2] >> 2) * _range_scale; - _reports[_next_report].z = (buf.words[3] >> 2) * _range_scale; - /* - * @todo Apply additional scaling / calibration factors here. + * y of board is x of sensor and x of board is -y of sensor + * perform only the axis assignment here. + * Two non-value bits are discarded directly */ + report->y_raw = (((int16_t)read_reg(ADDR_ACC_X_LSB+1)) << 8) | (read_reg(ADDR_ACC_X_LSB));// XXX PX4DEV raw_report.x; + report->x_raw = (((int16_t)read_reg(ADDR_ACC_X_LSB+3)) << 8) | (read_reg(ADDR_ACC_X_LSB+2));// XXX PX4DEV raw_report.y; + report->z_raw = (((int16_t)read_reg(ADDR_ACC_X_LSB+5)) << 8) | (read_reg(ADDR_ACC_X_LSB+4));// XXX PX4DEV raw_report.z; + + /* discard two non-value bits in the 16 bit measurement */ + report->x_raw = (report->x_raw >> 2); + report->y_raw = (report->y_raw >> 2); + report->z_raw = (report->z_raw >> 2); + + /* invert y axis, due to 14 bit data no overflow can occur in the negation */ + report->y_raw = -report->y_raw; + + report->x = ((report->x_raw * _accel_range_scale) - _accel_scale.x_offset) * _accel_scale.x_scale; + report->y = ((report->y_raw * _accel_range_scale) - _accel_scale.y_offset) * _accel_scale.y_scale; + report->z = ((report->z_raw * _accel_range_scale) - _accel_scale.z_offset) * _accel_scale.z_scale; + report->scaling = _accel_range_scale; + report->range_m_s2 = _accel_range_m_s2; /* post a report to the ring - note, not locked */ INCREMENT(_next_report, _num_reports); @@ -643,12 +730,18 @@ BMA180::measure() /* notify anyone waiting for data */ poll_notify(POLLIN); + + /* publish for subscribers */ + orb_publish(ORB_ID(sensor_accel), _accel_topic, report); + + /* stop the perf counter */ + perf_end(_sample_perf); } void BMA180::print_info() { - printf("reads: %u\n", _reads); + perf_print_counter(_sample_perf); printf("report queue: %u (%u/%u @ %p)\n", _num_reports, _oldest_report, _next_report, _reports); } @@ -656,67 +749,126 @@ BMA180::print_info() /** * Local functions in support of the shell command. */ -namespace +namespace bma180 { BMA180 *g_dev; -/* - * XXX this should just be part of the generic sensors test... - */ +void start(); +void test(); +void reset(); +void info(); -int +/** + * Start the driver. + */ +void +start() +{ + int fd; + + if (g_dev != nullptr) + errx(1, "already started"); + + /* create the driver */ + g_dev = new BMA180(1 /* XXX magic number */, (spi_dev_e)PX4_SPIDEV_ACCEL); + + if (g_dev == nullptr) + goto fail; + + if (OK != g_dev->init()) + goto fail; + + /* set the poll rate to default, starts automatic data collection */ + fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + if (fd < 0) + goto fail; + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + goto fail; + + exit(0); +fail: + if (g_dev != nullptr) { + delete g_dev; + g_dev = nullptr; + } + errx(1, "driver start failed"); +} + +/** + * Perform some basic functional tests on the driver; + * make sure we can collect data from the sensor in polled + * and automatic modes. + */ +void test() { int fd = -1; - struct accel_report report; + struct accel_report a_report; ssize_t sz; - const char *reason = "test OK"; - do { + /* get the driver */ + fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "%s open failed (try 'bma180 start' if the driver is not running)", + ACCEL_DEVICE_PATH); - /* get the driver */ - fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + /* reset to manual polling */ + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_MANUAL) < 0) + err(1, "reset to manual polling"); + + /* do a simple demand read */ + sz = read(fd, &a_report, sizeof(a_report)); + if (sz != sizeof(a_report)) + err(1, "immediate acc read failed"); - if (fd < 0) { - reason = "can't open driver"; - break; - } + warnx("single read"); + warnx("time: %lld", a_report.timestamp); + warnx("acc x: \t%8.4f\tm/s^2", (double)a_report.x); + warnx("acc y: \t%8.4f\tm/s^2", (double)a_report.y); + warnx("acc z: \t%8.4f\tm/s^2", (double)a_report.z); + warnx("acc x: \t%d\traw 0x%0x", (short)a_report.x_raw, (unsigned short)a_report.x_raw); + warnx("acc y: \t%d\traw 0x%0x", (short)a_report.y_raw, (unsigned short)a_report.y_raw); + warnx("acc z: \t%d\traw 0x%0x", (short)a_report.z_raw, (unsigned short)a_report.z_raw); + warnx("acc range: %8.4f m/s^2 (%8.4f g)", (double)a_report.range_m_s2, + (double)(a_report.range_m_s2 / 9.81f)); - /* do a simple demand read */ - sz = read(fd, &report, sizeof(report)); + /* XXX add poll-rate tests here too */ - if (sz != sizeof(report)) { - reason = "immediate read failed"; - break; - } - - printf("single read\n"); - fflush(stdout); - printf("time: %lld\n", report.timestamp); - printf("x: %f\n", report.x); - printf("y: %f\n", report.y); - printf("z: %f\n", report.z); - - } while (0); - - printf("BMA180: %s\n", reason); - - return OK; + reset(); + errx(0, "PASS"); } -int +/** + * Reset the driver. + */ +void +reset() +{ + int fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "failed "); + if (ioctl(fd, SENSORIOCRESET, 0) < 0) + err(1, "driver reset failed"); + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + err(1, "driver poll restart failed"); + + exit(0); +} + +/** + * Print a little info about the driver. + */ +void info() { - if (g_dev == nullptr) { - fprintf(stderr, "BMA180: driver not running\n"); - return -ENOENT; - } + if (g_dev == nullptr) + errx(1, "BMA180: driver not running"); printf("state @ %p\n", g_dev); g_dev->print_info(); - return OK; + exit(0); } @@ -727,48 +879,28 @@ bma180_main(int argc, char *argv[]) { /* * Start/load the driver. - * - * XXX it would be nice to have a wrapper for this... + */ - if (!strcmp(argv[1], "start")) { - - if (g_dev != nullptr) { - fprintf(stderr, "BMA180: already loaded\n"); - return -EBUSY; - } - - /* create the driver */ - g_dev = new BMA180(CONFIG_BMA180_SPI_BUS, (spi_dev_e)CONFIG_BMA180_SPI_DEVICE); - - if (g_dev == nullptr) { - fprintf(stderr, "BMA180: driver alloc failed\n"); - return -ENOMEM; - } - - if (OK != g_dev->init()) { - fprintf(stderr, "BMA180: driver init failed\n"); - usleep(100000); - delete g_dev; - g_dev = nullptr; - return -EIO; - } - - printf("BMA180: driver started\n"); - return OK; - } + if (!strcmp(argv[1], "start")) + bma180::start(); /* * Test the driver/device. */ if (!strcmp(argv[1], "test")) - return test(); + bma180::test(); + + /* + * Reset the driver. + */ + if (!strcmp(argv[1], "reset")) + bma180::reset(); /* * Print driver information. */ if (!strcmp(argv[1], "info")) - return info(); + bma180::info(); - fprintf(stderr, "unrecognised command, try 'start', 'test' or 'info'\n"); - return -EINVAL; + errx(1, "unrecognised command, try 'start', 'test', 'reset' or 'info'"); } diff --git a/apps/drivers/device/i2c.cpp b/apps/drivers/device/i2c.cpp index 8489db4bb0..c4b2aa944c 100644 --- a/apps/drivers/device/i2c.cpp +++ b/apps/drivers/device/i2c.cpp @@ -53,6 +53,7 @@ I2C::I2C(const char *name, CDev(name, devname, irq), // public // protected + _retries(0), // private _bus(bus), _address(address), @@ -72,7 +73,7 @@ I2C::init() { int ret = OK; - // attach to the i2c bus + /* attach to the i2c bus */ _dev = up_i2cinitialize(_bus); if (_dev == nullptr) { @@ -98,7 +99,7 @@ I2C::init() } // tell the world where we are - log("on bus %d at 0x%02x", _bus, _address); + log("on I2C bus %d at 0x%02x", _bus, _address); out: return ret; @@ -117,33 +118,50 @@ I2C::transfer(uint8_t *send, unsigned send_len, uint8_t *recv, unsigned recv_len struct i2c_msg_s msgv[2]; unsigned msgs; int ret; + unsigned tries = 0; -// debug("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len); + do { + // debug("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len); - msgs = 0; + msgs = 0; - if (send_len > 0) { - msgv[msgs].addr = _address; - msgv[msgs].flags = 0; - msgv[msgs].buffer = send; - msgv[msgs].length = send_len; - msgs++; - } + if (send_len > 0) { + msgv[msgs].addr = _address; + msgv[msgs].flags = 0; + msgv[msgs].buffer = send; + msgv[msgs].length = send_len; + msgs++; + } - if (recv_len > 0) { - msgv[msgs].addr = _address; - msgv[msgs].flags = I2C_M_READ; - msgv[msgs].buffer = recv; - msgv[msgs].length = recv_len; - msgs++; - } + if (recv_len > 0) { + msgv[msgs].addr = _address; + msgv[msgs].flags = I2C_M_READ; + msgv[msgs].buffer = recv; + msgv[msgs].length = recv_len; + msgs++; + } - if (msgs == 0) - return -EINVAL; + if (msgs == 0) + return -EINVAL; - ret = I2C_TRANSFER(_dev, &msgv[0], msgs); + /* + * I2C architecture means there is an unavoidable race here + * if there are any devices on the bus with a different frequency + * preference. Really, this is pointless. + */ + I2C_SETFREQUENCY(_dev, _frequency); + ret = I2C_TRANSFER(_dev, &msgv[0], msgs); + + if (ret == OK) + break; + + // reset the I2C bus to unwedge on error + up_i2creset(_dev); + + } while (tries++ < _retries); return ret; + } } // namespace device \ No newline at end of file diff --git a/apps/drivers/device/i2c.h b/apps/drivers/device/i2c.h index d84f7bd09b..7c5a14d6bf 100644 --- a/apps/drivers/device/i2c.h +++ b/apps/drivers/device/i2c.h @@ -52,6 +52,12 @@ class __EXPORT I2C : public CDev { protected: + /** + * The number of times a read or write operation will be retried on + * error. + */ + unsigned _retries; + /** * @ Constructor * diff --git a/apps/drivers/device/spi.cpp b/apps/drivers/device/spi.cpp index 3ccdaae368..a1761b7694 100644 --- a/apps/drivers/device/spi.cpp +++ b/apps/drivers/device/spi.cpp @@ -35,8 +35,16 @@ * @file Base class for devices connected via SPI. * * @todo Work out if caching the mode/frequency would save any time. + * + * @todo A separate bus/device abstraction would allow for mixed interrupt-mode + * and non-interrupt-mode clients to arbitrate for the bus. As things stand, + * a bus shared between clients of both kinds is vulnerable to races between + * the two, where an interrupt-mode client will ignore the lock held by the + * non-interrupt-mode client. */ +#include + #include "spi.h" #ifndef CONFIG_SPI_EXCHANGE @@ -103,7 +111,7 @@ SPI::init() } // tell the workd where we are - log("on bus %d at %d", _bus, _device); + log("on SPI bus %d at %d", _bus, _device); out: return ret; @@ -124,7 +132,8 @@ SPI::transfer(uint8_t *send, uint8_t *recv, unsigned len) return -EINVAL; /* do common setup */ - SPI_LOCK(_dev, true); + if (!up_interrupt_context()) + SPI_LOCK(_dev, true); SPI_SETFREQUENCY(_dev, _frequency); SPI_SETMODE(_dev, _mode); SPI_SETBITS(_dev, 8); @@ -135,7 +144,8 @@ SPI::transfer(uint8_t *send, uint8_t *recv, unsigned len) /* and clean up */ SPI_SELECT(_dev, _device, false); - SPI_LOCK(_dev, false); + if (!up_interrupt_context()) + SPI_LOCK(_dev, false); return OK; } diff --git a/apps/drivers/device/spi.h b/apps/drivers/device/spi.h index ef382b03cf..b2a111562d 100644 --- a/apps/drivers/device/spi.h +++ b/apps/drivers/device/spi.h @@ -81,6 +81,12 @@ protected: /** * Perform a SPI transfer. * + * If called from interrupt context, this interface does not lock + * the bus and may interfere with non-interrupt-context callers. + * + * Clients in a mixed interrupt/non-interrupt configuration must + * ensure appropriate interlocking. + * * At least one of send or recv must be non-null. * * @param send Bytes to send to the device, or nullptr if diff --git a/apps/drivers/drv_accel.h b/apps/drivers/drv_accel.h index 370cc5d877..6d0c8c545c 100644 --- a/apps/drivers/drv_accel.h +++ b/apps/drivers/drv_accel.h @@ -41,6 +41,7 @@ #include #include +#include "drv_sensor.h" #include "drv_orb_dev.h" #define ACCEL_DEVICE_PATH "/dev/accel" @@ -50,10 +51,18 @@ * structure. */ struct accel_report { - float x; - float y; - float z; uint64_t timestamp; + float x; /**< acceleration in the NED X board axis in m/s^2 */ + float y; /**< acceleration in the NED Y board axis in m/s^2 */ + float z; /**< acceleration in the NED Z board axis in m/s^2 */ + float temperature; /**< temperature in degrees celsius */ + float range_m_s2; /**< range in m/s^2 (+- this value) */ + float scaling; + + int16_t x_raw; + int16_t y_raw; + int16_t z_raw; + int16_t temperature_raw; }; /** accel scaling factors; Vout = (Vin * Vscale) + Voffset */ @@ -73,33 +82,37 @@ ORB_DECLARE(sensor_accel); /* * ioctl() definitions + * + * Accelerometer drivers also implement the generic sensor driver + * interfaces from drv_sensor.h */ -#define _ACCELIOCBASE (0x2000) +#define _ACCELIOCBASE (0x2100) #define _ACCELIOC(_n) (_IOC(_ACCELIOCBASE, _n)) -/** set the driver polling rate to (arg) Hz, or one of the ACC_POLLRATE constants */ -#define ACCELIOCSPOLLRATE _ACCELIOC(0) - -#define ACC_POLLRATE_MANUAL 1000000 /**< poll when read */ -#define ACC_POLLRATE_EXTERNAL 1000001 /**< poll when device signals ready */ - -/** set the internal queue depth to (arg) entries, must be at least 1 */ -#define ACCELIOCSQUEUEDEPTH _ACCELIOC(1) /** set the accel internal sample rate to at least (arg) Hz */ -#define ACCELIOCSSAMPLERATE _ACCELIOC(2) +#define ACCELIOCSSAMPLERATE _ACCELIOC(0) + +/** return the accel internal sample rate in Hz */ +#define ACCELIOCGSAMPLERATE _ACCELIOC(1) /** set the accel internal lowpass filter to no lower than (arg) Hz */ -#define ACCELIOCSLOWPASS _ACCELIOC(3) +#define ACCELIOCSLOWPASS _ACCELIOC(2) -/** set the report format to (arg); zero is the standard, 1-10 are reserved, all others are driver-specific. */ -#define ACCELIOCSREPORTFORMAT _ACCELIOC(4) +/** return the accel internal lowpass filter in Hz */ +#define ACCELIOCGLOWPASS _ACCELIOC(3) /** set the accel scaling constants to the structure pointed to by (arg) */ #define ACCELIOCSSCALE _ACCELIOC(5) +/** get the accel scaling constants into the structure pointed to by (arg) */ +#define ACCELIOCGSCALE _ACCELIOC(6) + /** set the accel measurement range to handle at least (arg) g */ -#define ACCELIORANGE _ACCELIOC(6) +#define ACCELIOCSRANGE _ACCELIOC(7) + +/** get the current accel measurement range in g */ +#define ACCELIOCGRANGE _ACCELIOC(8) #endif /* _DRV_ACCEL_H */ diff --git a/apps/drivers/drv_baro.h b/apps/drivers/drv_baro.h index 323b25c835..176f798c06 100644 --- a/apps/drivers/drv_baro.h +++ b/apps/drivers/drv_baro.h @@ -41,6 +41,7 @@ #include #include +#include "drv_sensor.h" #include "drv_orb_dev.h" #define BARO_DEVICE_PATH "/dev/baro" @@ -65,19 +66,13 @@ ORB_DECLARE(sensor_baro); * ioctl() definitions */ -#define _BAROIOCBASE (0x2100) +#define _BAROIOCBASE (0x2200) #define _BAROIOC(_n) (_IOC(_BAROIOCBASE, _n)) -/** set the driver polling rate to (arg) Hz, or one of the BARO_POLLRATE constants */ -#define BAROIOCSPOLLRATE _BAROIOC(0) +/** set corrected MSL pressure in pascals */ +#define BAROIOCSMSLPRESSURE _BAROIOC(0) -#define BARO_POLLRATE_MANUAL 1000000 /**< poll when read */ -#define BARO_POLLRATE_EXTERNAL 1000001 /**< poll when device signals ready */ - -/** set the internal queue depth to (arg) entries, must be at least 1 */ -#define BAROIOCSQUEUEDEPTH _BAROIOC(1) - -/** set the report format to (arg); zero is the standard, 1-10 are reserved, all others are driver-specific. */ -#define BAROIOCSREPORTFORMAT _BAROIOC(2) +/** get current MSL pressure in pascals */ +#define BAROIOCGMSLPRESSURE _BAROIOC(1) #endif /* _DRV_BARO_H */ diff --git a/apps/drivers/drv_gyro.h b/apps/drivers/drv_gyro.h index 82e23f62af..5c646f243e 100644 --- a/apps/drivers/drv_gyro.h +++ b/apps/drivers/drv_gyro.h @@ -41,6 +41,7 @@ #include #include +#include "drv_sensor.h" #include "drv_orb_dev.h" #define GYRO_DEVICE_PATH "/dev/gyro" @@ -50,10 +51,18 @@ * structure. */ struct gyro_report { - float x; - float y; - float z; uint64_t timestamp; + float x; /**< angular velocity in the NED X board axis in rad/s */ + float y; /**< angular velocity in the NED Y board axis in rad/s */ + float z; /**< angular velocity in the NED Z board axis in rad/s */ + float temperature; /**< temperature in degrees celcius */ + float range_rad_s; + float scaling; + + int16_t x_raw; + int16_t y_raw; + int16_t z_raw; + int16_t temperature_raw; }; /** gyro scaling factors; Vout = (Vin * Vscale) + Voffset */ @@ -75,28 +84,31 @@ ORB_DECLARE(sensor_gyro); * ioctl() definitions */ -#define _GYROIOCBASE (0x2200) +#define _GYROIOCBASE (0x2300) #define _GYROIOC(_n) (_IOC(_GYROIOCBASE, _n)) -/** set the driver polling rate to (arg) Hz, or one of the GYRO_POLLRATE constants */ -#define GYROIOCSPOLLRATE _GYROIOC(0) - -#define GYRO_POLLRATE_MANUAL 1000000 /**< poll when read */ -#define GYRO_POLLRATE_EXTERNAL 1000001 /**< poll when device signals ready */ - -/** set the internal queue depth to (arg) entries, must be at least 1 */ -#define GYROIOCSQUEUEDEPTH _GYROIOC(1) - /** set the gyro internal sample rate to at least (arg) Hz */ -#define GYROIOCSSAMPLERATE _GYROIOC(2) +#define GYROIOCSSAMPLERATE _GYROIOC(0) + +/** return the gyro internal sample rate in Hz */ +#define GYROIOCGSAMPLERATE _GYROIOC(1) /** set the gyro internal lowpass filter to no lower than (arg) Hz */ -#define GYROIOCSLOWPASS _GYROIOC(3) +#define GYROIOCSLOWPASS _GYROIOC(2) -/** set the report format to (arg); zero is the standard, 1-10 are reserved, all others are driver-specific. */ -#define GYROIOCSREPORTFORMAT _GYROIOC(4) +/** set the gyro internal lowpass filter to no lower than (arg) Hz */ +#define GYROIOCGLOWPASS _GYROIOC(3) /** set the gyro scaling constants to (arg) */ -#define GYROIOCSSCALE _GYROIOC(5) +#define GYROIOCSSCALE _GYROIOC(4) + +/** get the gyro scaling constants into (arg) */ +#define GYROIOCGSCALE _GYROIOC(5) + +/** set the gyro measurement range to handle at least (arg) degrees per second */ +#define GYROIOCSRANGE _GYROIOC(6) + +/** get the current gyro measurement range in degrees per second */ +#define GYROIOCGRANGE _GYROIOC(7) #endif /* _DRV_GYRO_H */ diff --git a/apps/drivers/drv_mag.h b/apps/drivers/drv_mag.h index 673a3988fd..1f5bb998e7 100644 --- a/apps/drivers/drv_mag.h +++ b/apps/drivers/drv_mag.h @@ -41,6 +41,7 @@ #include #include +#include "drv_sensor.h" #include "drv_orb_dev.h" #define MAG_DEVICE_PATH "/dev/mag" @@ -48,12 +49,20 @@ /** * mag report structure. Reads from the device must be in multiples of this * structure. + * + * Output values are in gauss. */ struct mag_report { + uint64_t timestamp; float x; float y; float z; - uint64_t timestamp; + float range_ga; + float scaling; + + int16_t x_raw; + int16_t y_raw; + int16_t z_raw; }; /** mag scaling factors; Vout = (Vin * Vscale) + Voffset */ @@ -75,28 +84,22 @@ ORB_DECLARE(sensor_mag); * ioctl() definitions */ -#define _MAGIOCBASE (0x2300) -#define _MAGIOC(_n) (_IOC(_MAGIOBASE, _n)) - -/** set the driver polling rate to (arg) Hz, or one of the MAG_POLLRATE constants */ -#define MAGIOCSPOLLRATE _MAGIOC(0) - -#define MAG_POLLRATE_MANUAL 1000000 /**< poll when read */ -#define MAG_POLLRATE_EXTERNAL 1000001 /**< poll when device signals ready */ - -/** set the internal queue depth to (arg) entries, must be at least 1 */ -#define MAGIOCSQUEUEDEPTH _MAGIOC(1) +#define _MAGIOCBASE (0x2400) +#define _MAGIOC(_n) (_IOC(_MAGIOCBASE, _n)) /** set the mag internal sample rate to at least (arg) Hz */ -#define MAGIOCSSAMPLERATE _MAGIOC(2) +#define MAGIOCSSAMPLERATE _MAGIOC(0) /** set the mag internal lowpass filter to no lower than (arg) Hz */ -#define MAGIOCSLOWPASS _MAGIOC(3) - -/** set the report format to (arg); zero is the standard, 1-10 are reserved, all others are driver-specific. */ -#define MAGIOCSREPORTFORMAT _MAGIOC(4) +#define MAGIOCSLOWPASS _MAGIOC(1) /** set the mag scaling constants to the structure pointed to by (arg) */ -#define MAGIOCSSCALE _MAGIOC(5) +#define MAGIOCSSCALE _MAGIOC(2) + +/** copy the mag scaling constants to the structure pointed to by (arg) */ +#define MAGIOCGSCALE _MAGIOC(3) + +/** perform self-calibration, update scale factors to canonical units */ +#define MAGIOCCALIBRATE _MAGIOC(4) #endif /* _DRV_MAG_H */ diff --git a/apps/drivers/drv_mixer.h b/apps/drivers/drv_mixer.h index fd54ed7fa9..793e86b324 100644 --- a/apps/drivers/drv_mixer.h +++ b/apps/drivers/drv_mixer.h @@ -61,7 +61,7 @@ /* * ioctl() definitions */ -#define _MIXERIOCBASE (0x2400) +#define _MIXERIOCBASE (0x2500) #define _MIXERIOC(_n) (_IOC(_MIXERIOCBASE, _n)) /** get the number of mixable outputs */ diff --git a/apps/drivers/drv_orb_dev.h b/apps/drivers/drv_orb_dev.h index b3fc01a5fa..8495780d56 100644 --- a/apps/drivers/drv_orb_dev.h +++ b/apps/drivers/drv_orb_dev.h @@ -58,7 +58,7 @@ /** maximum ogbject name length */ #define ORB_MAXNAME 32 -#define _ORBIOCBASE (0x2500) +#define _ORBIOCBASE (0x2600) #define _ORBIOC(_n) (_IOC(_ORBIOCBASE, _n)) /* @@ -81,4 +81,7 @@ /** Set the minimum interval at which the topic can be seen to be updated for this subscription */ #define ORBIOCSETINTERVAL _ORBIOC(12) +/** Get the global advertiser handle for the topic */ +#define ORBIOCGADVERTISER _ORBIOC(13) + #endif /* _DRV_UORB_H */ diff --git a/apps/drivers/drv_pwm_output.h b/apps/drivers/drv_pwm_output.h index 73e3310aed..340175a4b6 100644 --- a/apps/drivers/drv_pwm_output.h +++ b/apps/drivers/drv_pwm_output.h @@ -94,7 +94,7 @@ ORB_DECLARE(output_pwm); * Note that ioctls and ObjDev updates should not be mixed, as the * behaviour of the system in this case is not defined. */ -#define _PWM_SERVO_BASE 0x2600 +#define _PWM_SERVO_BASE 0x2700 /** arm all servo outputs handle by this driver */ #define PWM_SERVO_ARM _IOC(_PWM_SERVO_BASE, 0) diff --git a/apps/drivers/drv_sensor.h b/apps/drivers/drv_sensor.h new file mode 100644 index 0000000000..325bd42bfd --- /dev/null +++ b/apps/drivers/drv_sensor.h @@ -0,0 +1,87 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file Common sensor API and ioctl definitions. + */ + +#ifndef _DRV_SENSOR_H +#define _DRV_SENSOR_H + +#include +#include + +/* + * ioctl() definitions + * + * Note that a driver may not implement all of these operations, but + * if the operation is implemented it should conform to this API. + */ + +#define _SENSORIOCBASE (0x2000) +#define _SENSORIOC(_n) (_IOC(_SENSORIOCBASE, _n)) + +/** + * Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE + * constants + */ +#define SENSORIOCSPOLLRATE _SENSORIOC(0) + +/** + * Return the driver's approximate polling rate in Hz, or one of the + * SENSOR_POLLRATE values. + */ +#define SENSORIOCGPOLLRATE _SENSORIOC(1) + +#define SENSOR_POLLRATE_MANUAL 1000000 /**< poll when read */ +#define SENSOR_POLLRATE_EXTERNAL 1000001 /**< poll when device signals ready */ +#define SENSOR_POLLRATE_MAX 1000002 /**< poll at device maximum rate */ +#define SENSOR_POLLRATE_DEFAULT 1000003 /**< poll at driver normal rate */ + +/** + * Set the internal queue depth to (arg) entries, must be at least 1 + * + * This sets the upper bound on the number of readings that can be + * read from the driver. + */ +#define SENSORIOCSQUEUEDEPTH _SENSORIOC(2) + +/** return the internal queue depth */ +#define SENSORIOCGQUEUEDEPTH _SENSORIOC(3) + +/** + * Reset the sensor to its default configuration. + */ +#define SENSORIOCRESET _SENSORIOC(4) + +#endif /* _DRV_SENSOR_H */ \ No newline at end of file diff --git a/apps/mix_and_link/Makefile b/apps/drivers/hmc5883/Makefile similarity index 95% rename from apps/mix_and_link/Makefile rename to apps/drivers/hmc5883/Makefile index a907277c79..aa4a397fb3 100644 --- a/apps/mix_and_link/Makefile +++ b/apps/drivers/hmc5883/Makefile @@ -32,7 +32,11 @@ ############################################################################ # -# Makefile to build the mix-and-link functions +# HMC5883 driver # +APPNAME = hmc5883 +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + include $(APPDIR)/mk/app.mk diff --git a/apps/drivers/hmc5883/hmc5883.cpp b/apps/drivers/hmc5883/hmc5883.cpp new file mode 100644 index 0000000000..c0a5f4049a --- /dev/null +++ b/apps/drivers/hmc5883/hmc5883.cpp @@ -0,0 +1,937 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file hmc5883.cpp + * + * Driver for the HMC5883 magnetometer connected via I2C. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +#include + +/* + * HMC5883 internal constants and data structures. + */ + +/* Max measurement rate is 160Hz */ +#define HMC5883_CONVERSION_INTERVAL (1000000 / 160) /* microseconds */ + +#define ADDR_CONF_A 0x00 +#define ADDR_CONF_B 0x01 +#define ADDR_MODE 0x02 +#define ADDR_DATA_OUT_X_MSB 0x03 +#define ADDR_DATA_OUT_X_LSB 0x04 +#define ADDR_DATA_OUT_Z_MSB 0x05 +#define ADDR_DATA_OUT_Z_LSB 0x06 +#define ADDR_DATA_OUT_Y_MSB 0x07 +#define ADDR_DATA_OUT_Y_LSB 0x08 +#define ADDR_STATUS 0x09 +#define ADDR_ID_A 0x0a +#define ADDR_ID_B 0x0b +#define ADDR_ID_C 0x0c + +#define HMC5883L_ADDRESS 0x1E + +/* modes not changeable outside of driver */ +#define HMC5883L_MODE_NORMAL (0 << 0) /* default */ +#define HMC5883L_MODE_POSITIVE_BIAS (1 << 0) /* positive bias */ +#define HMC5883L_MODE_NEGATIVE_BIAS (1 << 1) /* negative bias */ + +#define HMC5883L_AVERAGING_1 (0 << 5) /* conf a register */ +#define HMC5883L_AVERAGING_2 (1 << 5) +#define HMC5883L_AVERAGING_4 (2 << 5) +#define HMC5883L_AVERAGING_8 (3 << 5) + +#define MODE_REG_CONTINOUS_MODE (0 << 0) +#define MODE_REG_SINGLE_MODE (1 << 0) /* default */ + +#define STATUS_REG_DATA_OUT_LOCK (1 << 1) /* page 16: set if data is only partially read, read device to reset */ +#define STATUS_REG_DATA_READY (1 << 0) /* page 16: set if all axes have valid measurements */ + +#define ID_A_WHO_AM_I 'H' +#define ID_B_WHO_AM_I '4' +#define ID_C_WHO_AM_I '3' + + +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +static const int ERROR = -1; + +class HMC5883 : public device::I2C +{ +public: + HMC5883(int bus); + ~HMC5883(); + + virtual int init(); + + virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); + virtual int ioctl(struct file *filp, int cmd, unsigned long arg); + + /** + * Diagnostics - print some basic information about the driver. + */ + void print_info(); + +protected: + virtual int probe(); + +private: + work_s _work; + unsigned _measure_ticks; + + unsigned _num_reports; + volatile unsigned _next_report; + volatile unsigned _oldest_report; + mag_report *_reports; + mag_scale _scale; + float _range_scale; + float _range_ga; + bool _collect_phase; + + orb_advert_t _mag_topic; + + perf_counter_t _sample_perf; + perf_counter_t _comms_errors; + perf_counter_t _buffer_overflows; + + /** + * Test whether the device supported by the driver is present at a + * specific address. + * + * @param address The I2C bus address to probe. + * @return True if the device is present. + */ + int probe_address(uint8_t address); + + /** + * Initialise the automatic measurement state machine and start it. + * + * @note This function is called at open and error time. It might make sense + * to make it more aggressive about resetting the bus in case of errors. + */ + void start(); + + /** + * Stop the automatic measurement state machine. + */ + void stop(); + + /** + * Perform a poll cycle; collect from the previous measurement + * and start a new one. + * + * This is the heart of the measurement state machine. This function + * alternately starts a measurement, or collects the data from the + * previous measurement. + * + * When the interval between measurements is greater than the minimum + * measurement interval, a gap is inserted between collection + * and measurement to provide the most recent measurement possible + * at the next interval. + */ + void cycle(); + + /** + * Static trampoline from the workq context; because we don't have a + * generic workq wrapper yet. + * + * @param arg Instance pointer for the driver that is polling. + */ + static void cycle_trampoline(void *arg); + + /** + * Write a register. + * + * @param reg The register to write. + * @param val The value to write. + * @return OK on write success. + */ + int write_reg(uint8_t reg, uint8_t val); + + /** + * Read a register. + * + * @param reg The register to read. + * @param val The value read. + * @return OK on read success. + */ + int read_reg(uint8_t reg, uint8_t &val); + + /** + * Issue a measurement command. + * + * @return OK if the measurement command was successful. + */ + int measure(); + + /** + * Collect the result of the most recent measurement. + */ + int collect(); + + /** + * Convert a big-endian signed 16-bit value to a float. + * + * @param in A signed 16-bit big-endian value. + * @return The floating-point representation of the value. + */ + float meas_to_float(uint8_t in[2]); + +}; + +/* helper macro for handling report buffer indices */ +#define INCREMENT(_x, _lim) do { _x++; if (_x >= _lim) _x = 0; } while(0) + +/* + * Driver 'main' command. + */ +extern "C" __EXPORT int hmc5883_main(int argc, char *argv[]); + + +HMC5883::HMC5883(int bus) : + I2C("HMC5883", MAG_DEVICE_PATH, bus, HMC5883L_ADDRESS, 400000), + _measure_ticks(0), + _num_reports(0), + _next_report(0), + _oldest_report(0), + _reports(nullptr), + _mag_topic(-1), + _range_scale(1.0f / 1090.0f), /* default range scale from counts to gauss */ + _range_ga(0.88f), + _sample_perf(perf_alloc(PC_ELAPSED, "hmc5883_read")), + _comms_errors(perf_alloc(PC_COUNT, "hmc5883_comms_errors")), + _buffer_overflows(perf_alloc(PC_COUNT, "hmc5883_buffer_overflows")) +{ + // enable debug() calls + _debug_enabled = true; + + // default scaling + _scale.x_offset = 0; + _scale.x_scale = 1.0f; + _scale.y_offset = 0; + _scale.y_scale = 1.0f; + _scale.z_offset = 0; + _scale.z_scale = 1.0f; + + // work_cancel in the dtor will explode if we don't do this... + memset(&_work, 0, sizeof(_work)); +} + +HMC5883::~HMC5883() +{ + /* make sure we are truly inactive */ + stop(); + + /* free any existing reports */ + if (_reports != nullptr) + delete[] _reports; +} + +int +HMC5883::init() +{ + int ret = ERROR; + + /* do I2C init (and probe) first */ + if (I2C::init() != OK) + goto out; + + /* allocate basic report buffers */ + _num_reports = 2; + _reports = new struct mag_report[_num_reports]; + if (_reports == nullptr) + goto out; + _oldest_report = _next_report = 0; + + /* get a publish handle on the mag topic */ + memset(&_reports[0], 0, sizeof(_reports[0])); + _mag_topic = orb_advertise(ORB_ID(sensor_mag), &_reports[0]); + if (_mag_topic < 0) + debug("failed to create sensor_mag object"); + + ret = OK; +out: + return ret; +} + +int +HMC5883::probe() +{ + uint8_t data[3] = {0, 0, 0}; + + _retries = 10; + if (read_reg(ADDR_ID_A, data[0]) || + read_reg(ADDR_ID_B, data[1]) || + read_reg(ADDR_ID_C, data[2])) + debug("read_reg fail"); + _retries = 1; + + if ((data[0] != ID_A_WHO_AM_I) || + (data[1] != ID_B_WHO_AM_I) || + (data[2] != ID_C_WHO_AM_I)) { + debug("ID byte mismatch (%02x,%02x,%02x)", data[0], data[1], data[2]); + return -EIO; + } + + return OK; +} + +ssize_t +HMC5883::read(struct file *filp, char *buffer, size_t buflen) +{ + unsigned count = buflen / sizeof(struct mag_report); + int ret = 0; + + /* buffer must be large enough */ + if (count < 1) + return -ENOSPC; + + /* if automatic measurement is enabled */ + if (_measure_ticks > 0) { + + /* + * While there is space in the caller's buffer, and reports, copy them. + * Note that we may be pre-empted by the workq thread while we are doing this; + * we are careful to avoid racing with them. + */ + while (count--) { + if (_oldest_report != _next_report) { + memcpy(buffer, _reports + _oldest_report, sizeof(*_reports)); + ret += sizeof(_reports[0]); + INCREMENT(_oldest_report, _num_reports); + } + } + + /* if there was no data, warn the caller */ + return ret ? ret : -EAGAIN; + } + + /* manual measurement - run one conversion */ + /* XXX really it'd be nice to lock against other readers here */ + do { + _oldest_report = _next_report = 0; + + /* trigger a measurement */ + if (OK != measure()) { + ret = -EIO; + break; + } + + /* wait for it to complete */ + usleep(HMC5883_CONVERSION_INTERVAL); + + /* run the collection phase */ + if (OK != collect()) { + ret = -EIO; + break; + } + + /* state machine will have generated a report, copy it out */ + memcpy(buffer, _reports, sizeof(*_reports)); + ret = sizeof(*_reports); + + } while (0); + + return ret; +} + +int +HMC5883::ioctl(struct file *filp, int cmd, unsigned long arg) +{ + switch (cmd) { + + case SENSORIOCSPOLLRATE: { + switch (arg) { + + /* switching to manual polling */ + case SENSOR_POLLRATE_MANUAL: + stop(); + _measure_ticks = 0; + return OK; + + /* external signalling (DRDY) not supported */ + case SENSOR_POLLRATE_EXTERNAL: + + /* zero would be bad */ + case 0: + return -EINVAL; + + /* set default/max polling rate */ + case SENSOR_POLLRATE_MAX: + case SENSOR_POLLRATE_DEFAULT: { + /* do we need to start internal polling? */ + bool want_start = (_measure_ticks == 0); + + /* set interval for next measurement to minimum legal value */ + _measure_ticks = USEC2TICK(HMC5883_CONVERSION_INTERVAL); + + /* if we need to start the poll state machine, do it */ + if (want_start) + start(); + + return OK; + } + + /* adjust to a legal polling interval in Hz */ + default: { + /* do we need to start internal polling? */ + bool want_start = (_measure_ticks == 0); + + /* convert hz to tick interval via microseconds */ + unsigned ticks = USEC2TICK(1000000 / arg); + + /* check against maximum rate */ + if (ticks < USEC2TICK(HMC5883_CONVERSION_INTERVAL)) + return -EINVAL; + + /* update interval for next measurement */ + _measure_ticks = ticks; + + /* if we need to start the poll state machine, do it */ + if (want_start) + start(); + + return OK; + } + } + } + + case SENSORIOCGPOLLRATE: + if (_measure_ticks == 0) + return SENSOR_POLLRATE_MANUAL; + return (1000 / _measure_ticks); + + case SENSORIOCSQUEUEDEPTH: { + /* add one to account for the sentinel in the ring */ + arg++; + + /* lower bound is mandatory, upper bound is a sanity check */ + if ((arg < 2) || (arg > 100)) + return -EINVAL; + + /* allocate new buffer */ + struct mag_report *buf = new struct mag_report[arg]; + + if (nullptr == buf) + return -ENOMEM; + + /* reset the measurement state machine with the new buffer, free the old */ + stop(); + delete[] _reports; + _num_reports = arg; + _reports = buf; + start(); + + return OK; + } + + case SENSORIOCGQUEUEDEPTH: + return _num_reports - 1; + + case SENSORIOCRESET: + /* XXX implement this */ + return -EINVAL; + + case MAGIOCSSAMPLERATE: + /* not supported, always 1 sample per poll */ + return -EINVAL; + + case MAGIOCSLOWPASS: + /* not supported, no internal filtering */ + return -EINVAL; + + case MAGIOCSSCALE: + /* set new scale factors */ + memcpy(&_scale, (mag_scale *)arg, sizeof(_scale)); + return 0; + + case MAGIOCGSCALE: + /* copy out scale factors */ + memcpy((mag_scale *)arg, &_scale, sizeof(_scale)); + return 0; + + case MAGIOCCALIBRATE: + /* XXX perform auto-calibration */ + return -EINVAL; + + default: + /* give it to the superclass */ + return I2C::ioctl(filp, cmd, arg); + } +} + +void +HMC5883::start() +{ + /* reset the report ring and state machine */ + _collect_phase = false; + _oldest_report = _next_report = 0; + + /* schedule a cycle to start things */ + work_queue(HPWORK, &_work, (worker_t)&HMC5883::cycle_trampoline, this, 1); +} + +void +HMC5883::stop() +{ + work_cancel(HPWORK, &_work); +} + +void +HMC5883::cycle_trampoline(void *arg) +{ + HMC5883 *dev = (HMC5883 *)arg; + + dev->cycle(); +} + +void +HMC5883::cycle() +{ + /* collection phase? */ + if (_collect_phase) { + + /* perform collection */ + if (OK != collect()) { + log("collection error"); + /* restart the measurement state machine */ + start(); + return; + } + + /* next phase is measurement */ + _collect_phase = false; + + /* + * Is there a collect->measure gap? + */ + if (_measure_ticks > USEC2TICK(HMC5883_CONVERSION_INTERVAL)) { + + /* schedule a fresh cycle call when we are ready to measure again */ + work_queue(HPWORK, + &_work, + (worker_t)&HMC5883::cycle_trampoline, + this, + _measure_ticks - USEC2TICK(HMC5883_CONVERSION_INTERVAL)); + + return; + } + } + + /* measurement phase */ + if (OK != measure()) + log("measure error"); + + /* next phase is collection */ + _collect_phase = true; + + /* schedule a fresh cycle call when the measurement is done */ + work_queue(HPWORK, + &_work, + (worker_t)&HMC5883::cycle_trampoline, + this, + USEC2TICK(HMC5883_CONVERSION_INTERVAL)); +} + +int +HMC5883::measure() +{ + int ret; + + /* + * Send the command to begin a measurement. + */ + ret = write_reg(ADDR_MODE, MODE_REG_SINGLE_MODE); + + if (OK != ret) + perf_count(_comms_errors); + + return ret; +} + +int +HMC5883::collect() +{ +#pragma pack(push, 1) + struct { /* status register and data as read back from the device */ + uint8_t x[2]; + uint8_t z[2]; + uint8_t y[2]; + } hmc_report; +#pragma pack(pop) + struct { + int16_t x, y, z; + } report; + int ret = -EIO; + uint8_t cmd; + + + perf_begin(_sample_perf); + + /* this should be fairly close to the end of the measurement, so the best approximation of the time */ + _reports[_next_report].timestamp = hrt_absolute_time(); + + /* + * @note We could read the status register here, which could tell us that + * we were too early and that the output registers are still being + * written. In the common case that would just slow us down, and + * we're better off just never being early. + */ + + /* get measurements from the device */ + cmd = ADDR_DATA_OUT_X_MSB; + ret = transfer(&cmd, 1, (uint8_t *)&hmc_report, sizeof(hmc_report)); + + if (ret != OK) { + perf_count(_comms_errors); + debug("data/status read error"); + goto out; + } + + /* swap the data we just received */ + report.x = (((int16_t)hmc_report.x[0]) << 8) + hmc_report.x[1]; + report.y = (((int16_t)hmc_report.y[0]) << 8) + hmc_report.y[1]; + report.z = (((int16_t)hmc_report.z[0]) << 8) + hmc_report.z[1]; + + /* + * If any of the values are -4096, there was an internal math error in the sensor. + * Generalise this to a simple range check that will also catch some bit errors. + */ + if ((abs(report.x) > 2048) || + (abs(report.y) > 2048) || + (abs(report.z) > 2048)) + goto out; + + /* + * RAW outputs + * + * to align the sensor axes with the board, x and y need to be flipped + * and y needs to be negated + */ + _reports[_next_report].x_raw = report.y; + _reports[_next_report].y_raw = ((report.x == -32768) ? 32767 : -report.x); + /* z remains z */ + _reports[_next_report].z_raw = report.z; + + /* scale values for output */ + + /* + * 1) Scale raw value to SI units using scaling from datasheet. + * 2) Subtract static offset (in SI units) + * 3) Scale the statically calibrated values with a linear + * dynamically obtained factor + * + * Note: the static sensor offset is the number the sensor outputs + * at a nominally 'zero' input. Therefore the offset has to + * be subtracted. + * + * Example: A gyro outputs a value of 74 at zero angular rate + * the offset is 74 from the origin and subtracting + * 74 from all measurements centers them around zero. + */ + + /* to align the sensor axes with the board, x and y need to be flipped */ + _reports[_next_report].x = ((report.y * _range_scale) - _scale.x_offset) * _scale.x_scale; + /* flip axes and negate value for y */ + _reports[_next_report].y = ((((report.x == -32768) ? 32767 : -report.x) * _range_scale) - _scale.y_offset) * _scale.y_scale; + /* z remains z */ + _reports[_next_report].z = ((report.z * _range_scale) - _scale.z_offset) * _scale.z_scale; + + /* publish it */ + orb_publish(ORB_ID(sensor_mag), _mag_topic, &_reports[_next_report]); + + /* post a report to the ring - note, not locked */ + INCREMENT(_next_report, _num_reports); + + /* if we are running up against the oldest report, toss it */ + if (_next_report == _oldest_report) { + perf_count(_buffer_overflows); + INCREMENT(_oldest_report, _num_reports); + } + + /* notify anyone waiting for data */ + poll_notify(POLLIN); + + ret = OK; + +out: + perf_end(_sample_perf); + return ret; +} + +int +HMC5883::write_reg(uint8_t reg, uint8_t val) +{ + uint8_t cmd[] = { reg, val }; + + return transfer(&cmd[0], 2, nullptr, 0); +} + +int +HMC5883::read_reg(uint8_t reg, uint8_t &val) +{ + return transfer(®, 1, &val, 1); +} + +float +HMC5883::meas_to_float(uint8_t in[2]) +{ + union { + uint8_t b[2]; + int16_t w; + } u; + + u.b[0] = in[1]; + u.b[1] = in[0]; + + return (float) u.w; +} + +void +HMC5883::print_info() +{ + perf_print_counter(_sample_perf); + perf_print_counter(_comms_errors); + perf_print_counter(_buffer_overflows); + printf("poll interval: %u ticks\n", _measure_ticks); + printf("report queue: %u (%u/%u @ %p)\n", + _num_reports, _oldest_report, _next_report, _reports); +} + +/** + * Local functions in support of the shell command. + */ +namespace hmc5883 +{ + +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +const int ERROR = -1; + +HMC5883 *g_dev; + +void start(); +void test(); +void reset(); +void info(); + +/** + * Start the driver. + */ +void +start() +{ + int fd; + + if (g_dev != nullptr) + errx(1, "already started"); + + /* create the driver */ + /* XXX HORRIBLE hack - the bus number should not come from here */ + g_dev = new HMC5883(2); + + if (g_dev == nullptr) + goto fail; + + if (OK != g_dev->init()) + goto fail; + + /* set the poll rate to default, starts automatic data collection */ + fd = open(MAG_DEVICE_PATH, O_RDONLY); + if (fd < 0) + goto fail; + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + goto fail; + exit(0); + +fail: + if (g_dev != nullptr) { + delete g_dev; + g_dev = nullptr; + } + errx(1, "driver start failed"); +} + +/** + * Perform some basic functional tests on the driver; + * make sure we can collect data from the sensor in polled + * and automatic modes. + */ +void +test() +{ + struct mag_report report; + ssize_t sz; + int ret; + + int fd = open(MAG_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "%s open failed (try 'hmc5883 start' if the driver is not running", MAG_DEVICE_PATH); + + /* do a simple demand read */ + sz = read(fd, &report, sizeof(report)); + if (sz != sizeof(report)) + err(1, "immediate read failed"); + + warnx("single read"); + warnx("measurement: %.6f %.6f %.6f", (double)report.x, (double)report.y, (double)report.z); + warnx("time: %lld", report.timestamp); + + /* set the queue depth to 10 */ + if (OK != ioctl(fd, SENSORIOCSQUEUEDEPTH, 10)) + errx(1, "failed to set queue depth"); + + /* start the sensor polling at 2Hz */ + if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) + errx(1, "failed to set 2Hz poll rate"); + + /* read the sensor 5x and report each value */ + for (unsigned i = 0; i < 5; i++) { + struct pollfd fds; + + /* wait for data to be ready */ + fds.fd = fd; + fds.events = POLLIN; + ret = poll(&fds, 1, 2000); + + if (ret != 1) + errx(1, "timed out waiting for sensor data"); + + /* now go get it */ + sz = read(fd, &report, sizeof(report)); + + if (sz != sizeof(report)) + err(1, "periodic read failed"); + + warnx("periodic read %u", i); + warnx("measurement: %.6f %.6f %.6f", (double)report.x, (double)report.y, (double)report.z); + warnx("time: %lld", report.timestamp); + } + + errx(0, "PASS"); +} + +/** + * Reset the driver. + */ +void +reset() +{ + int fd = open(MAG_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "failed "); + if (ioctl(fd, SENSORIOCRESET, 0) < 0) + err(1, "driver reset failed"); + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + err(1, "driver poll restart failed"); + + exit(0); +} + +/** + * Print a little info about the driver. + */ +void +info() +{ + if (g_dev == nullptr) + errx(1, "driver not running"); + + printf("state @ %p\n", g_dev); + g_dev->print_info(); + + exit(0); +} + +} // namespace + +int +hmc5883_main(int argc, char *argv[]) +{ + /* + * Start/load the driver. + */ + if (!strcmp(argv[1], "start")) + hmc5883::start(); + + /* + * Test the driver/device. + */ + if (!strcmp(argv[1], "test")) + hmc5883::test(); + + /* + * Reset the driver. + */ + if (!strcmp(argv[1], "reset")) + hmc5883::reset(); + + /* + * Print driver information. + */ + if (!strcmp(argv[1], "info")) + hmc5883::info(); + + errx(1, "unrecognised command, try 'start', 'test', 'reset' or 'info'"); +} diff --git a/apps/drivers/l3gd20/Makefile b/apps/drivers/l3gd20/Makefile new file mode 100644 index 0000000000..98e2d57c55 --- /dev/null +++ b/apps/drivers/l3gd20/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Makefile to build the L3GD20 driver. +# + +APPNAME = l3gd20 +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +include $(APPDIR)/mk/app.mk diff --git a/apps/drivers/l3gd20/l3gd20.cpp b/apps/drivers/l3gd20/l3gd20.cpp new file mode 100644 index 0000000000..bfdabe2734 --- /dev/null +++ b/apps/drivers/l3gd20/l3gd20.cpp @@ -0,0 +1,868 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file Driver for the ST L3GD20 MEMS gyro connected via SPI. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include + + +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +static const int ERROR = -1; + +/* SPI protocol address bits */ +#define DIR_READ (1<<7) +#define DIR_WRITE (0<<7) +#define ADDR_INCREMENT (1<<6) + +/* register addresses */ +#define ADDR_WHO_AM_I 0x0F +#define WHO_I_AM 0xD4 + +#define ADDR_CTRL_REG1 0x20 +#define REG1_RATE_LP_MASK 0xF0 /* Mask to guard partial register update */ +/* keep lowpass low to avoid noise issues */ +#define RATE_95HZ_LP_25HZ ((0<<7) | (0<<6) | (0<<5) | (1<<4)) +#define RATE_190HZ_LP_25HZ ((0<<7) | (1<<6) | (1<<5) | (1<<4)) +#define RATE_380HZ_LP_30HZ ((1<<7) | (0<<6) | (1<<5) | (1<<4)) +#define RATE_760HZ_LP_30HZ ((1<<7) | (1<<6) | (1<<5) | (1<<4)) + +#define ADDR_CTRL_REG2 0x21 +#define ADDR_CTRL_REG3 0x22 +#define ADDR_CTRL_REG4 0x23 +#define REG4_RANGE_MASK 0x30 /* Mask to guard partial register update */ +#define RANGE_250DPS (0<<4) +#define RANGE_500DPS (1<<4) +#define RANGE_2000DPS (3<<4) + +#define ADDR_CTRL_REG5 0x24 +#define ADDR_REFERENCE 0x25 +#define ADDR_OUT_TEMP 0x26 +#define ADDR_STATUS_REG 0x27 +#define ADDR_OUT_X_L 0x28 +#define ADDR_OUT_X_H 0x29 +#define ADDR_OUT_Y_L 0x2A +#define ADDR_OUT_Y_H 0x2B +#define ADDR_OUT_Z_L 0x2C +#define ADDR_OUT_Z_H 0x2D +#define ADDR_FIFO_CTRL_REG 0x2E +#define ADDR_FIFO_SRC_REG 0x2F +#define ADDR_INT1_CFG 0x30 +#define ADDR_INT1_SRC 0x31 +#define ADDR_INT1_TSH_XH 0x32 +#define ADDR_INT1_TSH_XL 0x33 +#define ADDR_INT1_TSH_YH 0x34 +#define ADDR_INT1_TSH_YL 0x35 +#define ADDR_INT1_TSH_ZH 0x36 +#define ADDR_INT1_TSH_ZL 0x37 +#define ADDR_INT1_DURATION 0x38 + + +/* Internal configuration values */ +#define REG1_POWER_NORMAL (1<<3) +#define REG1_Z_ENABLE (1<<2) +#define REG1_Y_ENABLE (1<<1) +#define REG1_X_ENABLE (1<<0) + +#define REG4_BDU (1<<7) +#define REG4_BLE (1<<6) +//#define REG4_SPI_3WIRE (1<<0) + +#define REG5_FIFO_ENABLE (1<<6) +#define REG5_REBOOT_MEMORY (1<<7) + +#define STATUS_ZYXOR (1<<7) +#define STATUS_ZOR (1<<6) +#define STATUS_YOR (1<<5) +#define STATUS_XOR (1<<4) +#define STATUS_ZYXDA (1<<3) +#define STATUS_ZDA (1<<2) +#define STATUS_YDA (1<<1) +#define STATUS_XDA (1<<0) + +#define FIFO_CTRL_BYPASS_MODE (0<<5) +#define FIFO_CTRL_FIFO_MODE (1<<5) +#define FIFO_CTRL_STREAM_MODE (1<<6) +#define FIFO_CTRL_STREAM_TO_FIFO_MODE (3<<5) +#define FIFO_CTRL_BYPASS_TO_STREAM_MODE (1<<7) + +extern "C" { __EXPORT int l3gd20_main(int argc, char *argv[]); } + +class L3GD20 : public device::SPI +{ +public: + L3GD20(int bus, spi_dev_e device); + ~L3GD20(); + + virtual int init(); + + virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); + virtual int ioctl(struct file *filp, int cmd, unsigned long arg); + + /** + * Diagnostics - print some basic information about the driver. + */ + void print_info(); + +protected: + virtual int probe(); + +private: + + struct hrt_call _call; + unsigned _call_interval; + + unsigned _num_reports; + volatile unsigned _next_report; + volatile unsigned _oldest_report; + struct gyro_report *_reports; + + struct gyro_scale _gyro_scale; + float _gyro_range_scale; + float _gyro_range_rad_s; + orb_advert_t _gyro_topic; + + unsigned _current_rate; + unsigned _current_range; + + perf_counter_t _sample_perf; + + /** + * Start automatic measurement. + */ + void start(); + + /** + * Stop automatic measurement. + */ + void stop(); + + /** + * Static trampoline from the hrt_call context; because we don't have a + * generic hrt wrapper yet. + * + * Called by the HRT in interrupt context at the specified rate if + * automatic polling is enabled. + * + * @param arg Instance pointer for the driver that is polling. + */ + static void measure_trampoline(void *arg); + + /** + * Fetch measurements from the sensor and update the report ring. + */ + void measure(); + + /** + * Read a register from the L3GD20 + * + * @param The register to read. + * @return The value that was read. + */ + uint8_t read_reg(unsigned reg); + + /** + * Write a register in the L3GD20 + * + * @param reg The register to write. + * @param value The new value to write. + */ + void write_reg(unsigned reg, uint8_t value); + + /** + * Modify a register in the L3GD20 + * + * Bits are cleared before bits are set. + * + * @param reg The register to modify. + * @param clearbits Bits in the register to clear. + * @param setbits Bits in the register to set. + */ + void modify_reg(unsigned reg, uint8_t clearbits, uint8_t setbits); + + /** + * Set the L3GD20 measurement range. + * + * @param max_dps The measurement range is set to permit reading at least + * this rate in degrees per second. + * Zero selects the maximum supported range. + * @return OK if the value can be supported, -ERANGE otherwise. + */ + int set_range(unsigned max_dps); + + /** + * Set the L3GD20 internal sampling frequency. + * + * @param frequency The internal sampling frequency is set to not less than + * this value. + * Zero selects the maximum rate supported. + * @return OK if the value can be supported. + */ + int set_samplerate(unsigned frequency); +}; + +/* helper macro for handling report buffer indices */ +#define INCREMENT(_x, _lim) do { _x++; if (_x >= _lim) _x = 0; } while(0) + + +L3GD20::L3GD20(int bus, spi_dev_e device) : + SPI("L3GD20", GYRO_DEVICE_PATH, bus, device, SPIDEV_MODE3, 8000000), + _call_interval(0), + _num_reports(0), + _next_report(0), + _oldest_report(0), + _reports(nullptr), + _gyro_range_scale(0.0f), + _gyro_range_rad_s(0.0f), + _gyro_topic(-1), + _current_rate(0), + _current_range(0), + _sample_perf(perf_alloc(PC_ELAPSED, "l3gd20_read")) +{ + // enable debug() calls + _debug_enabled = true; + + // default scale factors + _gyro_scale.x_offset = 0; + _gyro_scale.x_scale = 1.0f; + _gyro_scale.y_offset = 0; + _gyro_scale.y_scale = 1.0f; + _gyro_scale.z_offset = 0; + _gyro_scale.z_scale = 1.0f; +} + +L3GD20::~L3GD20() +{ + /* make sure we are truly inactive */ + stop(); + + /* free any existing reports */ + if (_reports != nullptr) + delete[] _reports; + + /* delete the perf counter */ + perf_free(_sample_perf); +} + +int +L3GD20::init() +{ + int ret = ERROR; + + /* do SPI init (and probe) first */ + if (SPI::init() != OK) + goto out; + + /* allocate basic report buffers */ + _num_reports = 2; + _oldest_report = _next_report = 0; + _reports = new struct gyro_report[_num_reports]; + if (_reports == nullptr) + goto out; + + /* advertise sensor topic */ + memset(&_reports[0], 0, sizeof(_reports[0])); + _gyro_topic = orb_advertise(ORB_ID(sensor_gyro), &_reports[0]); + + /* set default configuration */ + write_reg(ADDR_CTRL_REG1, REG1_POWER_NORMAL | REG1_Z_ENABLE | REG1_Y_ENABLE | REG1_X_ENABLE); + write_reg(ADDR_CTRL_REG2, 0); /* disable high-pass filters */ + write_reg(ADDR_CTRL_REG3, 0); /* no interrupts - we don't use them */ + write_reg(ADDR_CTRL_REG4, REG4_BDU); + write_reg(ADDR_CTRL_REG5, 0); + + write_reg(ADDR_CTRL_REG5, REG5_FIFO_ENABLE); /* disable wake-on-interrupt */ + write_reg(ADDR_FIFO_CTRL_REG, FIFO_CTRL_STREAM_MODE); /* Enable FIFO, old data is overwritten */ + + set_range(500); /* default to 500dps */ + set_samplerate(0); /* max sample rate */ + + ret = OK; +out: + return ret; +} + +int +L3GD20::probe() +{ + /* read dummy value to void to clear SPI statemachine on sensor */ + (void)read_reg(ADDR_WHO_AM_I); + + /* verify that the device is attached and functioning */ + if (read_reg(ADDR_WHO_AM_I) == WHO_I_AM) + return OK; + + return -EIO; +} + +ssize_t +L3GD20::read(struct file *filp, char *buffer, size_t buflen) +{ + unsigned count = buflen / sizeof(struct gyro_report); + int ret = 0; + + /* buffer must be large enough */ + if (count < 1) + return -ENOSPC; + + /* if automatic measurement is enabled */ + if (_call_interval > 0) { + + /* + * While there is space in the caller's buffer, and reports, copy them. + * Note that we may be pre-empted by the measurement code while we are doing this; + * we are careful to avoid racing with it. + */ + while (count--) { + if (_oldest_report != _next_report) { + memcpy(buffer, _reports + _oldest_report, sizeof(*_reports)); + ret += sizeof(_reports[0]); + INCREMENT(_oldest_report, _num_reports); + } + } + + /* if there was no data, warn the caller */ + return ret ? ret : -EAGAIN; + } + + /* manual measurement */ + _oldest_report = _next_report = 0; + measure(); + + /* measurement will have generated a report, copy it out */ + memcpy(buffer, _reports, sizeof(*_reports)); + ret = sizeof(*_reports); + + return ret; +} + +int +L3GD20::ioctl(struct file *filp, int cmd, unsigned long arg) +{ + switch (cmd) { + + case SENSORIOCSPOLLRATE: { + switch (arg) { + + /* switching to manual polling */ + case SENSOR_POLLRATE_MANUAL: + stop(); + _call_interval = 0; + return OK; + + /* external signalling not supported */ + case SENSOR_POLLRATE_EXTERNAL: + + /* zero would be bad */ + case 0: + return -EINVAL; + + /* set default/max polling rate */ + case SENSOR_POLLRATE_MAX: + case SENSOR_POLLRATE_DEFAULT: + /* XXX 500Hz is just a wild guess */ + return ioctl(filp, SENSORIOCSPOLLRATE, 500); + + /* adjust to a legal polling interval in Hz */ + default: { + /* do we need to start internal polling? */ + bool want_start = (_call_interval == 0); + + /* convert hz to hrt interval via microseconds */ + unsigned ticks = 1000000 / arg; + + /* check against maximum sane rate */ + if (ticks < 1000) + return -EINVAL; + + /* update interval for next measurement */ + /* XXX this is a bit shady, but no other way to adjust... */ + _call.period = _call_interval = ticks; + + /* if we need to start the poll state machine, do it */ + if (want_start) + start(); + + return OK; + } + } + } + + case SENSORIOCGPOLLRATE: + if (_call_interval == 0) + return SENSOR_POLLRATE_MANUAL; + return 1000000 / _call_interval; + + case SENSORIOCSQUEUEDEPTH: { + /* account for sentinel in the ring */ + arg++; + + /* lower bound is mandatory, upper bound is a sanity check */ + if ((arg < 2) || (arg > 100)) + return -EINVAL; + + /* allocate new buffer */ + struct gyro_report *buf = new struct gyro_report[arg]; + + if (nullptr == buf) + return -ENOMEM; + + /* reset the measurement state machine with the new buffer, free the old */ + stop(); + delete[] _reports; + _num_reports = arg; + _reports = buf; + start(); + + return OK; + } + + case SENSORIOCGQUEUEDEPTH: + return _num_reports -1; + + case SENSORIOCRESET: + /* XXX implement */ + return -EINVAL; + + case GYROIOCSSAMPLERATE: + return set_samplerate(arg); + + case GYROIOCGSAMPLERATE: + return _current_rate; + + case GYROIOCSLOWPASS: + case GYROIOCGLOWPASS: + /* XXX not implemented due to wacky interaction with samplerate */ + return -EINVAL; + + case GYROIOCSSCALE: + /* copy scale in */ + memcpy(&_gyro_scale, (struct gyro_scale*) arg, sizeof(_gyro_scale)); + return OK; + + case GYROIOCGSCALE: + /* copy scale out */ + memcpy((struct gyro_scale*) arg, &_gyro_scale, sizeof(_gyro_scale)); + return OK; + + case GYROIOCSRANGE: + return set_range(arg); + + case GYROIOCGRANGE: + return _current_range; + + default: + /* give it to the superclass */ + return SPI::ioctl(filp, cmd, arg); + } +} + +uint8_t +L3GD20::read_reg(unsigned reg) +{ + uint8_t cmd[2]; + + cmd[0] = reg | DIR_READ; + + transfer(cmd, cmd, sizeof(cmd)); + + return cmd[1]; +} + +void +L3GD20::write_reg(unsigned reg, uint8_t value) +{ + uint8_t cmd[2]; + + cmd[0] = reg | DIR_WRITE; + cmd[1] = value; + + transfer(cmd, nullptr, sizeof(cmd)); +} + +void +L3GD20::modify_reg(unsigned reg, uint8_t clearbits, uint8_t setbits) +{ + uint8_t val; + + val = read_reg(reg); + val &= ~clearbits; + val |= setbits; + write_reg(reg, val); +} + +int +L3GD20::set_range(unsigned max_dps) +{ + uint8_t bits = REG4_BDU; + + if (max_dps == 0) + max_dps = 2000; + + if (max_dps <= 250) { + _current_range = 250; + bits |= RANGE_250DPS; + } else if (max_dps <= 500) { + _current_range = 500; + bits |= RANGE_500DPS; + } else if (max_dps <= 2000) { + _current_range = 2000; + bits |= RANGE_2000DPS; + } else { + return -EINVAL; + } + + _gyro_range_rad_s = _current_range / 180.0f * M_PI_F; + _gyro_range_scale = _gyro_range_rad_s / 32768.0f; + write_reg(ADDR_CTRL_REG4, bits); + + return OK; +} + +int +L3GD20::set_samplerate(unsigned frequency) +{ + uint8_t bits = REG1_POWER_NORMAL | REG1_Z_ENABLE | REG1_Y_ENABLE | REG1_X_ENABLE; + + if (frequency == 0) + frequency = 760; + + if (frequency <= 95) { + _current_rate = 95; + bits |= RATE_95HZ_LP_25HZ; + } else if (frequency <= 190) { + _current_rate = 190; + bits |= RATE_190HZ_LP_25HZ; + } else if (frequency <= 380) { + _current_rate = 380; + bits |= RATE_380HZ_LP_30HZ; + } else if (frequency <= 760) { + _current_rate = 760; + bits |= RATE_760HZ_LP_30HZ; + } else { + return -EINVAL; + } + + write_reg(ADDR_CTRL_REG1, bits); + + return OK; +} + +void +L3GD20::start() +{ + /* make sure we are stopped first */ + stop(); + + /* reset the report ring */ + _oldest_report = _next_report = 0; + + /* start polling at the specified rate */ + hrt_call_every(&_call, 1000, _call_interval, (hrt_callout)&L3GD20::measure_trampoline, this); +} + +void +L3GD20::stop() +{ + hrt_cancel(&_call); +} + +void +L3GD20::measure_trampoline(void *arg) +{ + L3GD20 *dev = (L3GD20 *)arg; + + /* make another measurement */ + dev->measure(); +} + +void +L3GD20::measure() +{ + /* status register and data as read back from the device */ +#pragma pack(push, 1) + struct { + uint8_t cmd; + uint8_t temp; + uint8_t status; + int16_t x; + int16_t y; + int16_t z; + } raw_report; +#pragma pack(pop) + + gyro_report *report = &_reports[_next_report]; + + /* start the performance counter */ + perf_begin(_sample_perf); + + /* fetch data from the sensor */ + raw_report.cmd = ADDR_OUT_TEMP | DIR_READ | ADDR_INCREMENT; + transfer((uint8_t *)&raw_report, (uint8_t *)&raw_report, sizeof(raw_report)); + + /* + * 1) Scale raw value to SI units using scaling from datasheet. + * 2) Subtract static offset (in SI units) + * 3) Scale the statically calibrated values with a linear + * dynamically obtained factor + * + * Note: the static sensor offset is the number the sensor outputs + * at a nominally 'zero' input. Therefore the offset has to + * be subtracted. + * + * Example: A gyro outputs a value of 74 at zero angular rate + * the offset is 74 from the origin and subtracting + * 74 from all measurements centers them around zero. + */ + report->timestamp = hrt_absolute_time(); + /* XXX adjust for sensor alignment to board here */ + report->x_raw = raw_report.x; + report->y_raw = raw_report.y; + report->z_raw = raw_report.z; + + report->x = ((report->x_raw * _gyro_range_scale) - _gyro_scale.x_offset) * _gyro_scale.x_scale; + report->y = ((report->y_raw * _gyro_range_scale) - _gyro_scale.y_offset) * _gyro_scale.y_scale; + report->z = ((report->z_raw * _gyro_range_scale) - _gyro_scale.z_offset) * _gyro_scale.z_scale; + report->scaling = _gyro_range_scale; + report->range_rad_s = _gyro_range_rad_s; + + /* post a report to the ring - note, not locked */ + INCREMENT(_next_report, _num_reports); + + /* if we are running up against the oldest report, fix it */ + if (_next_report == _oldest_report) + INCREMENT(_oldest_report, _num_reports); + + /* notify anyone waiting for data */ + poll_notify(POLLIN); + + /* publish for subscribers */ + orb_publish(ORB_ID(sensor_gyro), _gyro_topic, report); + + /* stop the perf counter */ + perf_end(_sample_perf); +} + +void +L3GD20::print_info() +{ + perf_print_counter(_sample_perf); + printf("report queue: %u (%u/%u @ %p)\n", + _num_reports, _oldest_report, _next_report, _reports); +} + +/** + * Local functions in support of the shell command. + */ +namespace l3gd20 +{ + +L3GD20 *g_dev; + +void start(); +void test(); +void reset(); +void info(); + +/** + * Start the driver. + */ +void +start() +{ + int fd; + + if (g_dev != nullptr) + errx(1, "already started"); + + /* create the driver */ + g_dev = new L3GD20(1 /* XXX magic number */, (spi_dev_e)PX4_SPIDEV_GYRO); + + if (g_dev == nullptr) + goto fail; + + if (OK != g_dev->init()) + goto fail; + + /* set the poll rate to default, starts automatic data collection */ + fd = open(GYRO_DEVICE_PATH, O_RDONLY); + if (fd < 0) + goto fail; + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + goto fail; + + exit(0); +fail: + if (g_dev != nullptr) { + delete g_dev; + g_dev = nullptr; + } + errx(1, "driver start failed"); +} + +/** + * Perform some basic functional tests on the driver; + * make sure we can collect data from the sensor in polled + * and automatic modes. + */ +void +test() +{ + int fd_gyro = -1; + struct gyro_report g_report; + ssize_t sz; + + /* get the driver */ + fd_gyro = open(GYRO_DEVICE_PATH, O_RDONLY); + if (fd_gyro < 0) + err(1, "%s open failed", GYRO_DEVICE_PATH); + + /* reset to manual polling */ + if (ioctl(fd_gyro, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_MANUAL) < 0) + err(1, "reset to manual polling"); + + /* do a simple demand read */ + sz = read(fd_gyro, &g_report, sizeof(g_report)); + if (sz != sizeof(g_report)) + err(1, "immediate gyro read failed"); + + warnx("gyro x: \t% 9.5f\trad/s", (double)g_report.x); + warnx("gyro y: \t% 9.5f\trad/s", (double)g_report.y); + warnx("gyro z: \t% 9.5f\trad/s", (double)g_report.z); + warnx("gyro x: \t%d\traw", (int)g_report.x_raw); + warnx("gyro y: \t%d\traw", (int)g_report.y_raw); + warnx("gyro z: \t%d\traw", (int)g_report.z_raw); + warnx("gyro range: %8.4f rad/s (%d deg/s)", (double)g_report.range_rad_s, + (int)((g_report.range_rad_s / M_PI_F) * 180.0f+0.5f)); + + /* XXX add poll-rate tests here too */ + + reset(); + errx(0, "PASS"); +} + +/** + * Reset the driver. + */ +void +reset() +{ + int fd = open(GYRO_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "failed "); + if (ioctl(fd, SENSORIOCRESET, 0) < 0) + err(1, "driver reset failed"); + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + err(1, "driver poll restart failed"); + + exit(0); +} + +/** + * Print a little info about the driver. + */ +void +info() +{ + if (g_dev == nullptr) + errx(1, "driver not running\n"); + + printf("state @ %p\n", g_dev); + g_dev->print_info(); + + exit(0); +} + + +} // namespace + +int +l3gd20_main(int argc, char *argv[]) +{ + /* + * Start/load the driver. + + */ + if (!strcmp(argv[1], "start")) + l3gd20::start(); + + /* + * Test the driver/device. + */ + if (!strcmp(argv[1], "test")) + l3gd20::test(); + + /* + * Reset the driver. + */ + if (!strcmp(argv[1], "reset")) + l3gd20::reset(); + + /* + * Print driver information. + */ + if (!strcmp(argv[1], "info")) + l3gd20::info(); + + errx(1, "unrecognised command, try 'start', 'test', 'reset' or 'info'"); +} diff --git a/apps/drivers/mpu6000/Makefile b/apps/drivers/mpu6000/Makefile index e03eef67de..32df1bdae7 100644 --- a/apps/drivers/mpu6000/Makefile +++ b/apps/drivers/mpu6000/Makefile @@ -37,6 +37,6 @@ APPNAME = mpu6000 PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +STACKSIZE = 4096 include $(APPDIR)/mk/app.mk diff --git a/apps/drivers/mpu6000/mpu6000.cpp b/apps/drivers/mpu6000/mpu6000.cpp index 7576fc1d96..7b8a84f7eb 100644 --- a/apps/drivers/mpu6000/mpu6000.cpp +++ b/apps/drivers/mpu6000/mpu6000.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,8 @@ #include #include +#include +#include #include #include @@ -155,9 +158,6 @@ public: virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); virtual int ioctl(struct file *filp, int cmd, unsigned long arg); - virtual int open_first(struct file *filp); - virtual int close_last(struct file *filp); - /** * Diagnostics - print some basic information about the driver. */ @@ -181,12 +181,14 @@ private: struct accel_report _accel_report; struct accel_scale _accel_scale; float _accel_range_scale; - int _accel_topic; + float _accel_range_m_s2; + orb_advert_t _accel_topic; struct gyro_report _gyro_report; struct gyro_scale _gyro_scale; float _gyro_range_scale; - int _gyro_topic; + float _gyro_range_rad_s; + orb_advert_t _gyro_topic; unsigned _reads; perf_counter_t _sample_perf; @@ -288,15 +290,17 @@ MPU6000::MPU6000(int bus, spi_dev_e device) : _gyro(new MPU6000_gyro(this)), _product(0), _call_interval(0), - _accel_range_scale(1.0f), + _accel_range_scale(0.0f), + _accel_range_m_s2(0.0f), _accel_topic(-1), - _gyro_range_scale(1.0f), + _gyro_range_scale(0.0f), + _gyro_range_rad_s(0.0f), _gyro_topic(-1), _reads(0), _sample_perf(perf_alloc(PC_ELAPSED, "mpu6000_read")) { - // enable debug() calls - _debug_enabled = true; + // disable debug() calls + _debug_enabled = false; // default accel scale factors _accel_scale.x_offset = 0; @@ -316,6 +320,7 @@ MPU6000::MPU6000(int bus, spi_dev_e device) : memset(&_accel_report, 0, sizeof(_accel_report)); memset(&_gyro_report, 0, sizeof(_gyro_report)); + memset(&_call, 0, sizeof(_call)); } MPU6000::~MPU6000() @@ -364,12 +369,29 @@ MPU6000::init() write_reg(MPUREG_SMPLRT_DIV, 0x04); // Sample rate = 200Hz Fsample= 1Khz/(4+1) = 200Hz usleep(1000); - // FS & DLPF FS=2000¼/s, DLPF = 98Hz (low pass filter) - write_reg(MPUREG_CONFIG, BITS_DLPF_CFG_98HZ); + // FS & DLPF FS=2000 deg/s, DLPF = 20Hz (low pass filter) + // was 90 Hz, but this ruins quality and does not improve the + // system response + write_reg(MPUREG_CONFIG, BITS_DLPF_CFG_20HZ); usleep(1000); - write_reg(MPUREG_GYRO_CONFIG, BITS_FS_2000DPS); // Gyro scale 2000¼/s + // Gyro scale 2000 deg/s () + write_reg(MPUREG_GYRO_CONFIG, BITS_FS_2000DPS); usleep(1000); + // correct gyro scale factors + // scale to rad/s in SI units + // 2000 deg/s = (2000/180)*PI = 34.906585 rad/s + // scaling factor: + // 1/(2^15)*(2000/180)*PI + _gyro_scale.x_offset = 0; + _gyro_scale.x_scale = 1.0f; + _gyro_scale.y_offset = 0; + _gyro_scale.y_scale = 1.0f; + _gyro_scale.z_offset = 0; + _gyro_scale.z_scale = 1.0f; + _gyro_range_scale = (0.0174532 / 16.4);//1.0f / (32768.0f * (2000.0f / 180.0f) * M_PI_F); + _gyro_range_rad_s = (2000.0f / 180.0f) * M_PI_F; + // product-specific scaling switch (_product) { case MPU6000ES_REV_C4: @@ -394,6 +416,17 @@ MPU6000::init() break; } + // Correct accel scale factors of 4096 LSB/g + // scale to m/s^2 ( 1g = 9.81 m/s^2) + _accel_scale.x_offset = 0; + _accel_scale.x_scale = 1.0f; + _accel_scale.y_offset = 0; + _accel_scale.y_scale = 1.0f; + _accel_scale.z_offset = 0; + _accel_scale.z_scale = 1.0f; + _accel_range_scale = (9.81f / 4096.0f); + _accel_range_m_s2 = 8.0f * 9.81f; + usleep(1000); // INT CFG => Interrupt on Data Ready @@ -406,30 +439,12 @@ MPU6000::init() // write_reg(MPUREG_PWR_MGMT_1,MPU_CLK_SEL_PLLGYROZ); usleep(1000); + /* do CDev init for the gyro device node */ + ret = _gyro->init(); return ret; } -int -MPU6000::open_first(struct file *filp) -{ - /* reset to manual-poll mode */ - _call_interval = 0; - - /* XXX set default sampling/acquisition parameters */ - - return OK; -} - -int -MPU6000::close_last(struct file *filp) -{ - /* stop measurement */ - stop(); - - return OK; -} - int MPU6000::probe() { @@ -451,7 +466,7 @@ MPU6000::probe() case MPU6000_REV_D8: case MPU6000_REV_D9: case MPU6000_REV_D10: - log("ID 0x%02x", _product); + debug("ID 0x%02x", _product); return OK; } @@ -472,7 +487,7 @@ MPU6000::read(struct file *filp, char *buffer, size_t buflen) if (_call_interval == 0) measure(); - /* copy out the latest report */ + /* copy out the latest reports */ memcpy(buffer, &_accel_report, sizeof(_accel_report)); ret = sizeof(_accel_report); @@ -504,22 +519,28 @@ MPU6000::ioctl(struct file *filp, int cmd, unsigned long arg) { switch (cmd) { - case ACCELIOCSPOLLRATE: { + case SENSORIOCSPOLLRATE: { switch (arg) { /* switching to manual polling */ - case ACC_POLLRATE_MANUAL: + case SENSOR_POLLRATE_MANUAL: stop(); _call_interval = 0; return OK; /* external signalling not supported */ - case ACC_POLLRATE_EXTERNAL: + case SENSOR_POLLRATE_EXTERNAL: /* zero would be bad */ case 0: return -EINVAL; + /* set default/max polling rate */ + case SENSOR_POLLRATE_MAX: + case SENSOR_POLLRATE_DEFAULT: + /* XXX 500Hz is just a wild guess */ + return ioctl(filp, SENSORIOCSPOLLRATE, 500); + /* adjust to a legal polling interval in Hz */ default: { /* do we need to start internal polling? */ @@ -534,7 +555,7 @@ MPU6000::ioctl(struct file *filp, int cmd, unsigned long arg) /* update interval for next measurement */ /* XXX this is a bit shady, but no other way to adjust... */ - _call.period = _call_interval; + _call.period = _call_interval = ticks; /* if we need to start the poll state machine, do it */ if (want_start) @@ -545,20 +566,46 @@ MPU6000::ioctl(struct file *filp, int cmd, unsigned long arg) } } - case ACCELIOCSQUEUEDEPTH: + case SENSORIOCGPOLLRATE: + if (_call_interval == 0) + return SENSOR_POLLRATE_MANUAL; + return 1000000 / _call_interval; + + case SENSORIOCSQUEUEDEPTH: + /* XXX not implemented */ + return -EINVAL; + + case SENSORIOCGQUEUEDEPTH: + /* XXX not implemented */ + return -EINVAL; + + + case ACCELIOCSSAMPLERATE: + case ACCELIOCGSAMPLERATE: /* XXX not implemented */ return -EINVAL; case ACCELIOCSLOWPASS: + case ACCELIOCGLOWPASS: /* XXX not implemented */ return -EINVAL; - case ACCELIORANGE: - /* XXX not implemented really */ - return set_range(arg); + case ACCELIOCSSCALE: + /* copy scale in */ + memcpy(&_accel_scale, (struct accel_scale*) arg, sizeof(_accel_scale)); + return OK; - case ACCELIOCSSAMPLERATE: /* sensor sample rate is not (really) adjustable */ - case ACCELIOCSREPORTFORMAT: /* no alternate report formats */ + case ACCELIOCGSCALE: + /* copy scale out */ + memcpy((struct accel_scale*) arg, &_accel_scale, sizeof(_accel_scale)); + return OK; + + case ACCELIOCSRANGE: + case ACCELIOCGRANGE: + /* XXX not implemented */ + // XXX change these two values on set: + // _accel_range_scale = (9.81f / 4096.0f); + // _accel_range_rad_s = 8.0f * 9.81f; return -EINVAL; default: @@ -572,24 +619,40 @@ MPU6000::gyro_ioctl(struct file *filp, int cmd, unsigned long arg) { switch (cmd) { - case GYROIOCSPOLLRATE: - /* gyro and accel poll rates are shared */ - return ioctl(filp, ACCELIOCSPOLLRATE, arg); + /* these are shared with the accel side */ + case SENSORIOCSPOLLRATE: + case SENSORIOCGPOLLRATE: + case SENSORIOCSQUEUEDEPTH: + case SENSORIOCGQUEUEDEPTH: + case SENSORIOCRESET: + return ioctl(filp, cmd, arg); - case GYROIOCSQUEUEDEPTH: + case GYROIOCSSAMPLERATE: + case GYROIOCGSAMPLERATE: /* XXX not implemented */ return -EINVAL; case GYROIOCSLOWPASS: + case GYROIOCGLOWPASS: /* XXX not implemented */ return -EINVAL; case GYROIOCSSCALE: - /* XXX not implemented really */ - return set_range(arg); + /* copy scale in */ + memcpy(&_gyro_scale, (struct gyro_scale*) arg, sizeof(_gyro_scale)); + return OK; - case GYROIOCSSAMPLERATE: /* sensor sample rate is not (really) adjustable */ - case GYROIOCSREPORTFORMAT: /* no alternate report formats */ + case GYROIOCGSCALE: + /* copy scale out */ + memcpy((struct gyro_scale*) arg, &_gyro_scale, sizeof(_gyro_scale)); + return OK; + + case GYROIOCSRANGE: + case GYROIOCGRANGE: + /* XXX not implemented */ + // XXX change these two values on set: + // _gyro_range_scale = xx + // _gyro_range_m_s2 = xx return -EINVAL; default: @@ -719,40 +782,118 @@ MPU6000::measure() * Report conversation within the MPU6000, including command byte and * interrupt status. */ - struct Report { + struct MPUReport { uint8_t cmd; uint8_t status; - uint16_t accel_x; - uint16_t accel_y; - uint16_t accel_z; - uint16_t temp; - uint16_t gyro_x; - uint16_t gyro_y; - uint16_t gyro_z; - } report; + uint8_t accel_x[2]; + uint8_t accel_y[2]; + uint8_t accel_z[2]; + uint8_t temp[2]; + uint8_t gyro_x[2]; + uint8_t gyro_y[2]; + uint8_t gyro_z[2]; + } mpu_report; #pragma pack(pop) + struct Report { + int16_t accel_x; + int16_t accel_y; + int16_t accel_z; + int16_t temp; + int16_t gyro_x; + int16_t gyro_y; + int16_t gyro_z; + } report; + /* start measuring */ perf_begin(_sample_perf); /* * Fetch the full set of measurements from the MPU6000 in one pass. */ - report.cmd = DIR_READ | MPUREG_INT_STATUS; - transfer((uint8_t *)&report, (uint8_t *)&report, sizeof(report)); + mpu_report.cmd = DIR_READ | MPUREG_INT_STATUS; + transfer((uint8_t *)&mpu_report, ((uint8_t *)&mpu_report), sizeof(mpu_report)); /* - * Adjust and scale results to mg. + * Convert from big to little endian + */ + + report.accel_x = int16_t_from_bytes(mpu_report.accel_x); + report.accel_y = int16_t_from_bytes(mpu_report.accel_y); + report.accel_z = int16_t_from_bytes(mpu_report.accel_z); + + report.temp = int16_t_from_bytes(mpu_report.temp); + + report.gyro_x = int16_t_from_bytes(mpu_report.gyro_x); + report.gyro_y = int16_t_from_bytes(mpu_report.gyro_y); + report.gyro_z = int16_t_from_bytes(mpu_report.gyro_z); + + /* + * Swap axes and negate y + */ + int16_t accel_xt = report.accel_y; + int16_t accel_yt = ((report.accel_x == -32768) ? 32767 : -report.accel_x); + + int16_t gyro_xt = report.gyro_y; + int16_t gyro_yt = ((report.gyro_x == -32768) ? 32767 : -report.gyro_x); + + /* + * Apply the swap + */ + report.accel_x = accel_xt; + report.accel_y = accel_yt; + report.gyro_x = gyro_xt; + report.gyro_y = gyro_yt; + + /* + * Adjust and scale results to m/s^2. */ _gyro_report.timestamp = _accel_report.timestamp = hrt_absolute_time(); - _accel_report.x = report.accel_x * _accel_range_scale; - _accel_report.y = report.accel_y * _accel_range_scale; - _accel_report.z = report.accel_z * _accel_range_scale; - _gyro_report.x = report.gyro_x * _gyro_range_scale; - _gyro_report.y = report.gyro_y * _gyro_range_scale; - _gyro_report.z = report.gyro_z * _gyro_range_scale; + /* + * 1) Scale raw value to SI units using scaling from datasheet. + * 2) Subtract static offset (in SI units) + * 3) Scale the statically calibrated values with a linear + * dynamically obtained factor + * + * Note: the static sensor offset is the number the sensor outputs + * at a nominally 'zero' input. Therefore the offset has to + * be subtracted. + * + * Example: A gyro outputs a value of 74 at zero angular rate + * the offset is 74 from the origin and subtracting + * 74 from all measurements centers them around zero. + */ + + + /* NOTE: Axes have been swapped to match the board a few lines above. */ + + _accel_report.x_raw = report.accel_x; + _accel_report.y_raw = report.accel_y; + _accel_report.z_raw = report.accel_z; + + _accel_report.x = ((report.accel_x * _accel_range_scale) - _accel_scale.x_offset) * _accel_scale.x_scale; + _accel_report.y = ((report.accel_y * _accel_range_scale) - _accel_scale.y_offset) * _accel_scale.y_scale; + _accel_report.z = ((report.accel_z * _accel_range_scale) - _accel_scale.z_offset) * _accel_scale.z_scale; + _accel_report.scaling = _accel_range_scale; + _accel_report.range_m_s2 = _accel_range_m_s2; + + _accel_report.temperature_raw = report.temp; + _accel_report.temperature = (report.temp) / 361.0f + 35.0f; + + _gyro_report.x_raw = report.gyro_x; + _gyro_report.y_raw = report.gyro_y; + _gyro_report.z_raw = report.gyro_z; + + _gyro_report.x = ((report.gyro_x * _gyro_range_scale) - _gyro_scale.x_offset) * _gyro_scale.x_scale; + _gyro_report.y = ((report.gyro_y * _gyro_range_scale) - _gyro_scale.y_offset) * _gyro_scale.y_scale; + _gyro_report.z = ((report.gyro_z * _gyro_range_scale) - _gyro_scale.z_offset) * _gyro_scale.z_scale; + _gyro_report.scaling = _gyro_range_scale; + _gyro_report.range_rad_s = _gyro_range_rad_s; + + _gyro_report.temperature_raw = report.temp; + _gyro_report.temperature = (report.temp) / 361.0f + 35.0f; /* notify anyone waiting for data */ poll_notify(POLLIN); @@ -803,67 +944,151 @@ MPU6000_gyro::ioctl(struct file *filp, int cmd, unsigned long arg) /** * Local functions in support of the shell command. */ -namespace +namespace mpu6000 { MPU6000 *g_dev; -/* - * XXX this should just be part of the generic sensors test... - */ +void start(); +void test(); +void reset(); +void info(); -int +/** + * Start the driver. + */ +void +start() +{ + int fd; + + if (g_dev != nullptr) + errx(1, "already started"); + + /* create the driver */ + g_dev = new MPU6000(1 /* XXX magic number */, (spi_dev_e)PX4_SPIDEV_MPU); + + if (g_dev == nullptr) + goto fail; + + if (OK != g_dev->init()) + goto fail; + + /* set the poll rate to default, starts automatic data collection */ + fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + if (fd < 0) + goto fail; + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + goto fail; + + exit(0); +fail: + if (g_dev != nullptr) { + delete g_dev; + g_dev = nullptr; + } + errx(1, "driver start failed"); +} + +/** + * Perform some basic functional tests on the driver; + * make sure we can collect data from the sensor in polled + * and automatic modes. + */ +void test() { int fd = -1; - struct accel_report report; + int fd_gyro = -1; + struct accel_report a_report; + struct gyro_report g_report; ssize_t sz; - const char *reason = "test OK"; - do { + /* get the driver */ + fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "%s open failed (try 'mpu6000 start' if the driver is not running)", + ACCEL_DEVICE_PATH); - /* get the driver */ - fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + /* get the driver */ + fd_gyro = open(GYRO_DEVICE_PATH, O_RDONLY); + if (fd_gyro < 0) + err(1, "%s open failed", GYRO_DEVICE_PATH); - if (fd < 0) { - reason = "can't open driver"; - break; - } + /* reset to manual polling */ + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_MANUAL) < 0) + err(1, "reset to manual polling"); + + /* do a simple demand read */ + sz = read(fd, &a_report, sizeof(a_report)); + if (sz != sizeof(a_report)) + err(1, "immediate acc read failed"); - /* do a simple demand read */ - sz = read(fd, &report, sizeof(report)); + warnx("single read"); + warnx("time: %lld", a_report.timestamp); + warnx("acc x: \t%8.4f\tm/s^2", (double)a_report.x); + warnx("acc y: \t%8.4f\tm/s^2", (double)a_report.y); + warnx("acc z: \t%8.4f\tm/s^2", (double)a_report.z); + warnx("acc x: \t%d\traw 0x%0x", (short)a_report.x_raw, (unsigned short)a_report.x_raw); + warnx("acc y: \t%d\traw 0x%0x", (short)a_report.y_raw, (unsigned short)a_report.y_raw); + warnx("acc z: \t%d\traw 0x%0x", (short)a_report.z_raw, (unsigned short)a_report.z_raw); + warnx("acc range: %8.4f m/s^2 (%8.4f g)", (double)a_report.range_m_s2, + (double)(a_report.range_m_s2 / 9.81f)); - if (sz != sizeof(report)) { - reason = "immediate read failed"; - break; - } + /* do a simple demand read */ + sz = read(fd_gyro, &g_report, sizeof(g_report)); + if (sz != sizeof(g_report)) + err(1, "immediate gyro read failed"); - printf("single read\n"); - fflush(stdout); - printf("time: %lld\n", report.timestamp); - printf("x: %f\n", report.x); - printf("y: %f\n", report.y); - printf("z: %f\n", report.z); + warnx("gyro x: \t% 9.5f\trad/s", (double)g_report.x); + warnx("gyro y: \t% 9.5f\trad/s", (double)g_report.y); + warnx("gyro z: \t% 9.5f\trad/s", (double)g_report.z); + warnx("gyro x: \t%d\traw", (int)g_report.x_raw); + warnx("gyro y: \t%d\traw", (int)g_report.y_raw); + warnx("gyro z: \t%d\traw", (int)g_report.z_raw); + warnx("gyro range: %8.4f rad/s (%d deg/s)", (double)g_report.range_rad_s, + (int)((g_report.range_rad_s / M_PI_F) * 180.0f+0.5f)); - } while (0); + warnx("temp: \t%8.4f\tdeg celsius", (double)a_report.temperature); + warnx("temp: \t%d\traw 0x%0x", (short)a_report.temperature_raw, (unsigned short)a_report.temperature_raw); - printf("MPU6000: %s\n", reason); - return OK; + /* XXX add poll-rate tests here too */ + + reset(); + errx(0, "PASS"); } -int +/** + * Reset the driver. + */ +void +reset() +{ + int fd = open(ACCEL_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "failed "); + if (ioctl(fd, SENSORIOCRESET, 0) < 0) + err(1, "driver reset failed"); + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + err(1, "driver poll restart failed"); + + exit(0); +} + +/** + * Print a little info about the driver. + */ +void info() { - if (g_dev == nullptr) { - fprintf(stderr, "MPU6000: driver not running\n"); - return -ENOENT; - } + if (g_dev == nullptr) + errx(1, "driver not running"); printf("state @ %p\n", g_dev); g_dev->print_info(); - return OK; + exit(0); } @@ -874,47 +1099,28 @@ mpu6000_main(int argc, char *argv[]) { /* * Start/load the driver. - * - * XXX it would be nice to have a wrapper for this... + */ - if (!strcmp(argv[1], "start")) { - - if (g_dev != nullptr) { - fprintf(stderr, "MPU6000: already loaded\n"); - return -EBUSY; - } - - /* create the driver */ - g_dev = new MPU6000(1 /* XXX magic number */, (spi_dev_e)PX4_SPIDEV_MPU); - - if (g_dev == nullptr) { - fprintf(stderr, "MPU6000: driver alloc failed\n"); - return -ENOMEM; - } - - if (OK != g_dev->init()) { - fprintf(stderr, "MPU6000: driver init failed\n"); - usleep(100000); - delete g_dev; - g_dev = nullptr; - return -EIO; - } - - return OK; - } + if (!strcmp(argv[1], "start")) + mpu6000::start(); /* * Test the driver/device. */ if (!strcmp(argv[1], "test")) - return test(); + mpu6000::test(); + + /* + * Reset the driver. + */ + if (!strcmp(argv[1], "reset")) + mpu6000::reset(); /* * Print driver information. */ if (!strcmp(argv[1], "info")) - return info(); + mpu6000::info(); - fprintf(stderr, "unrecognised command, try 'start', 'test' or 'info'\n"); - return -EINVAL; + errx(1, "unrecognized command, try 'start', 'test', 'reset' or 'info'"); } diff --git a/apps/drivers/ms5611/ms5611.cpp b/apps/drivers/ms5611/ms5611.cpp index 6c6951d9b5..4df9de94c2 100644 --- a/apps/drivers/ms5611/ms5611.cpp +++ b/apps/drivers/ms5611/ms5611.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -59,9 +60,16 @@ #include #include +#include #include +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +static const int ERROR = -1; + /** * Calibration PROM as reported by the device. */ @@ -97,9 +105,6 @@ public: virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); virtual int ioctl(struct file *filp, int cmd, unsigned long arg); - virtual int open_first(struct file *filp); - virtual int close_last(struct file *filp); - /** * Diagnostics - print some basic information about the driver. */ @@ -122,17 +127,19 @@ private: bool _collect_phase; unsigned _measure_phase; - int32_t _dT; - int64_t _temp64; + /* intermediate temperature values per MS5611 datasheet */ + int32_t _TEMP; + int64_t _OFF; + int64_t _SENS; - int _baro_topic; + /* altitude conversion calibration */ + unsigned _msl_pressure; /* in kPa */ - unsigned _reads; - unsigned _measure_errors; - unsigned _read_errors; - unsigned _buf_overflows; + orb_advert_t _baro_topic; perf_counter_t _sample_perf; + perf_counter_t _comms_errors; + perf_counter_t _buffer_overflows; /** * Test whether the device supported by the driver is present at a @@ -191,6 +198,13 @@ private: */ int collect(); + /** + * Send a reset command to the MS5611. + * + * This is required after any bus reset. + */ + int cmd_reset(); + /** * Read the MS5611 PROM * @@ -211,6 +225,9 @@ private: /* helper macro for handling report buffer indices */ #define INCREMENT(_x, _lim) do { _x++; if (_x >= _lim) _x = 0; } while(0) +/* helper macro for arithmetic - returns the square of the argument */ +#define POW2(_x) ((_x) * (_x)) + /* * MS5611 internal constants and data structures. */ @@ -222,12 +239,12 @@ private: #define MS5611_ADDRESS_1 0x76 /* address select pins pulled high (PX4FMU series v1.6+) */ #define MS5611_ADDRESS_2 0x77 /* address select pins pulled low (PX4FMU prototypes) */ -#define ADDR_RESET_CMD 0x1E /* read from this address to reset chip (0b0011110 on bus) */ -#define ADDR_CMD_CONVERT_D1 0x48 /* 4096 samples to this address to start conversion (0b01001000 on bus) */ -#define ADDR_CMD_CONVERT_D2 0x58 /* 4096 samples */ -#define ADDR_DATA 0x00 /* address of 3 bytes / 32bit pressure data */ -#define ADDR_PROM_SETUP 0xA0 /* address of 8x 2 bytes factory and calibration data */ -#define ADDR_PROM_C1 0xA2 /* address of 6x 2 bytes calibration data */ +#define ADDR_RESET_CMD 0x1E /* write to this address to reset chip */ +#define ADDR_CMD_CONVERT_D1 0x48 /* write to this address to start temperature conversion */ +#define ADDR_CMD_CONVERT_D2 0x58 /* write to this address to start pressure conversion */ +#define ADDR_DATA 0x00 /* address of 3 bytes / 32bit pressure data */ +#define ADDR_PROM_SETUP 0xA0 /* address of 8x 2 bytes factory and calibration data */ +#define ADDR_PROM_C1 0xA2 /* address of 6x 2 bytes calibration data */ /* * Driver 'main' command. @@ -244,19 +261,20 @@ MS5611::MS5611(int bus) : _reports(nullptr), _collect_phase(false), _measure_phase(0), - _dT(0), - _temp64(0), - _reads(0), - _measure_errors(0), - _read_errors(0), - _buf_overflows(0), - _sample_perf(perf_alloc(PC_ELAPSED, "ms5611_read")) + _TEMP(0), + _OFF(0), + _SENS(0), + _msl_pressure(101325), + _baro_topic(-1), + _sample_perf(perf_alloc(PC_ELAPSED, "ms5611_read")), + _comms_errors(perf_alloc(PC_COUNT, "ms5611_comms_errors")), + _buffer_overflows(perf_alloc(PC_COUNT, "ms5611_buffer_overflows")) { // enable debug() calls _debug_enabled = true; // work_cancel in the dtor will explode if we don't do this... - _work.worker = nullptr; + memset(&_work, 0, sizeof(_work)); } MS5611::~MS5611() @@ -272,65 +290,40 @@ MS5611::~MS5611() int MS5611::init() { - int ret; + int ret = ERROR; /* do I2C init (and probe) first */ - ret = I2C::init(); - - /* assuming we're good, advertise the object */ - if (ret == OK) { - struct baro_report b; - - /* if this fails (e.g. no object in the system) that's OK */ - memset(&b, 0, sizeof(b)); - _baro_topic = orb_advertise(ORB_ID(sensor_baro), &b); - - if (_baro_topic < 0) - debug("failed to create sensor_baro object"); - } - - return ret; -} - -int -MS5611::open_first(struct file *filp) -{ - /* reset to manual-poll mode */ - _measure_ticks = 0; + if (I2C::init() != OK) + goto out; /* allocate basic report buffers */ _num_reports = 2; _reports = new struct baro_report[_num_reports]; + if (_reports == nullptr) + goto out; + _oldest_report = _next_report = 0; - return OK; -} + /* get a publish handle on the baro topic */ + memset(&_reports[0], 0, sizeof(_reports[0])); + _baro_topic = orb_advertise(ORB_ID(sensor_baro), &_reports[0]); + if (_baro_topic < 0) + debug("failed to create sensor_baro object"); -int -MS5611::close_last(struct file *filp) -{ - /* stop measurement */ - stop(); - - /* free report buffers */ - if (_reports != nullptr) { - delete[] _reports; - _num_reports = 0; - } - - _measure_ticks = 0; - - return OK; + ret = OK; +out: + return ret; } int MS5611::probe() { - if (OK == probe_address(MS5611_ADDRESS_1)) - return OK; - - if (OK == probe_address(MS5611_ADDRESS_2)) + _retries = 10; + if((OK == probe_address(MS5611_ADDRESS_1)) || + (OK == probe_address(MS5611_ADDRESS_2))) { + _retries = 1; return OK; + } return -EIO; } @@ -338,18 +331,13 @@ MS5611::probe() int MS5611::probe_address(uint8_t address) { - uint8_t cmd = ADDR_RESET_CMD; - /* select the address we are going to try */ set_address(address); /* send reset command */ - if (OK != transfer(&cmd, 1, nullptr, 0)) + if (OK != cmd_reset()) return -EIO; - /* wait for PROM contents to be in the device (2.8 ms) */ - usleep(3000); - /* read PROM */ if (OK != read_prom()) return -EIO; @@ -383,8 +371,6 @@ MS5611::read(struct file *filp, char *buffer, size_t buflen) } } - _reads++; - /* if there was no data, warn the caller */ return ret ? ret : -EAGAIN; } @@ -424,7 +410,6 @@ MS5611::read(struct file *filp, char *buffer, size_t buflen) /* state machine will have generated a report, copy it out */ memcpy(buffer, _reports, sizeof(*_reports)); ret = sizeof(*_reports); - _reads++; } while (0); @@ -436,22 +421,38 @@ MS5611::ioctl(struct file *filp, int cmd, unsigned long arg) { switch (cmd) { - case BAROIOCSPOLLRATE: { + case SENSORIOCSPOLLRATE: { switch (arg) { /* switching to manual polling */ - case BARO_POLLRATE_MANUAL: + case SENSOR_POLLRATE_MANUAL: stop(); _measure_ticks = 0; return OK; /* external signalling not supported */ - case BARO_POLLRATE_EXTERNAL: + case SENSOR_POLLRATE_EXTERNAL: /* zero would be bad */ case 0: return -EINVAL; + /* set default/max polling rate */ + case SENSOR_POLLRATE_MAX: + case SENSOR_POLLRATE_DEFAULT: { + /* do we need to start internal polling? */ + bool want_start = (_measure_ticks == 0); + + /* set interval for next measurement to minimum legal value */ + _measure_ticks = USEC2TICK(MS5611_CONVERSION_INTERVAL); + + /* if we need to start the poll state machine, do it */ + if (want_start) + start(); + + return OK; + } + /* adjust to a legal polling interval in Hz */ default: { /* do we need to start internal polling? */ @@ -476,7 +477,15 @@ MS5611::ioctl(struct file *filp, int cmd, unsigned long arg) } } - case BAROIOCSQUEUEDEPTH: { + case SENSORIOCGPOLLRATE: + if (_measure_ticks == 0) + return SENSOR_POLLRATE_MANUAL; + return (1000 / _measure_ticks); + + case SENSORIOCSQUEUEDEPTH: { + /* add one to account for the sentinel in the ring */ + arg++; + /* lower bound is mandatory, upper bound is a sanity check */ if ((arg < 2) || (arg > 100)) return -EINVAL; @@ -497,20 +506,34 @@ MS5611::ioctl(struct file *filp, int cmd, unsigned long arg) return OK; } - case BAROIOCSREPORTFORMAT: + case SENSORIOCGQUEUEDEPTH: + return _num_reports - 1; + + case SENSORIOCRESET: + /* XXX implement this */ return -EINVAL; + case BAROIOCSMSLPRESSURE: + /* range-check for sanity */ + if ((arg < 80000) || (arg > 120000)) + return -EINVAL; + _msl_pressure = arg; + return OK; + + case BAROIOCGMSLPRESSURE: + return _msl_pressure; + default: - /* give it to the superclass */ - return I2C::ioctl(filp, cmd, arg); + break; } + + /* give it to the superclass */ + return I2C::ioctl(filp, cmd, arg); } void MS5611::start() { - /* make sure we are stopped first */ - stop(); /* reset the report ring and state machine */ _collect_phase = false; @@ -518,13 +541,13 @@ MS5611::start() _oldest_report = _next_report = 0; /* schedule a cycle to start things */ - work_queue(&_work, (worker_t)&MS5611::cycle_trampoline, this, 1); + work_queue(HPWORK, &_work, (worker_t)&MS5611::cycle_trampoline, this, 1); } void MS5611::stop() { - work_cancel(&_work); + work_cancel(HPWORK, &_work); } void @@ -538,12 +561,14 @@ MS5611::cycle_trampoline(void *arg) void MS5611::cycle() { + /* collection phase? */ if (_collect_phase) { /* perform collection */ if (OK != collect()) { - log("FATAL collection error - restarting\n"); + log("collection error"); + /* reset the collection state machine and try again */ start(); return; } @@ -560,7 +585,8 @@ MS5611::cycle() (_measure_ticks > USEC2TICK(MS5611_CONVERSION_INTERVAL))) { /* schedule a fresh cycle call when we are ready to measure again */ - work_queue(&_work, + work_queue(HPWORK, + &_work, (worker_t)&MS5611::cycle_trampoline, this, _measure_ticks - USEC2TICK(MS5611_CONVERSION_INTERVAL)); @@ -570,16 +596,15 @@ MS5611::cycle() } /* measurement phase */ - if (OK != measure()) { - log("FATAL measure error - restarting\n"); - start(); - } + if (OK != measure()) + log("measure error"); /* next phase is collection */ _collect_phase = true; /* schedule a fresh cycle call when the measurement is done */ - work_queue(&_work, + work_queue(HPWORK, + &_work, (worker_t)&MS5611::cycle_trampoline, this, USEC2TICK(MS5611_CONVERSION_INTERVAL)); @@ -601,7 +626,7 @@ MS5611::measure() ret = transfer(&cmd_data, 1, nullptr, 0); if (OK != ret) - _measure_errors++; + perf_count(_comms_errors); return ret; } @@ -611,6 +636,10 @@ MS5611::collect() { uint8_t cmd; uint8_t data[3]; + union { + uint8_t b[4]; + uint32_t w; + } cvt; /* read the most recent measurement */ cmd = 0; @@ -621,46 +650,118 @@ MS5611::collect() _reports[_next_report].timestamp = hrt_absolute_time(); if (OK != transfer(&cmd, 1, &data[0], 3)) { - _read_errors++; + perf_count(_comms_errors); return -EIO; } /* fetch the raw value */ - uint32_t raw = (((uint32_t)data[0]) << 16) | (((uint32_t)data[1]) << 8) | ((uint32_t)data[2]); + cvt.b[0] = data[2]; + cvt.b[1] = data[1]; + cvt.b[2] = data[0]; + cvt.b[3] = 0; + uint32_t raw = cvt.w; /* handle a measurement */ if (_measure_phase == 0) { - /* temperature calculation */ - _dT = raw - (((int32_t)_prom.s.c5_reference_temp) * 256); - _temp64 = 2000 + (((int64_t)_dT) * _prom.s.c6_temp_coeff_temp) / 8388608; + /* temperature offset (in ADC units) */ + int32_t dT = (int32_t)raw - ((int32_t)_prom.s.c5_reference_temp << 8); + /* absolute temperature in centidegrees - note intermediate value is outside 32-bit range */ + _TEMP = 2000 + (int32_t)(((int64_t)dT * _prom.s.c6_temp_coeff_temp) >> 23); + + /* base sensor scale/offset values */ + _SENS = ((int64_t)_prom.s.c1_pressure_sens << 15) + (((int64_t)_prom.s.c3_temp_coeff_pres_sens * dT) >> 8); + _OFF = ((int64_t)_prom.s.c2_pressure_offset << 16) + (((int64_t)_prom.s.c4_temp_coeff_pres_offset * dT) >> 7); + + /* temperature compensation */ + if (_TEMP < 2000) { + + int32_t T2 = POW2(dT) >> 31; + + int64_t f = POW2((int64_t)_TEMP - 2000); + int64_t OFF2 = 5 * f >> 1; + int64_t SENS2 = 5 * f >> 2; + + if (_TEMP < -1500) { + int64_t f2 = POW2(_TEMP + 1500); + OFF2 += 7 * f2; + SENS2 += 11 * f2 >> 1; + } + + _TEMP -= T2; + _OFF -= OFF2; + _SENS -= SENS2; + } } else { - /* pressure calculation */ - int64_t offset = (int64_t)_prom.s.c2_pressure_offset * 65536 + ((int64_t)_dT * _prom.s.c4_temp_coeff_pres_offset) / 128; - int64_t sens = (int64_t)_prom.s.c1_pressure_sens * 32768 + ((int64_t)_dT * _prom.s.c3_temp_coeff_pres_sens) / 256; - - /* it's pretty cold, second order temperature compensation needed */ - if (_temp64 < 2000) { - /* second order temperature compensation */ - int64_t temp2 = (((int64_t)_dT) * _dT) >> 31; - int64_t tmp_64 = (_temp64 - 2000) * (_temp64 - 2000); - int64_t offset2 = (5 * tmp_64) >> 1; - int64_t sens2 = (5 * tmp_64) >> 2; - _temp64 = _temp64 - temp2; - offset = offset - offset2; - sens = sens - sens2; - } - - int64_t press_int64 = (((raw * sens) / 2097152 - offset) / 32768); + /* pressure calculation, result in Pa */ + int32_t P = (((raw * _SENS) >> 21) - _OFF) >> 15; /* generate a new report */ - _reports[_next_report].temperature = _temp64 / 100.0f; - _reports[_next_report].pressure = press_int64 / 100.0f; - /* convert as double for max. precision, store as float (more than enough precision) */ - _reports[_next_report].altitude = (44330.0 * (1.0 - pow((press_int64 / 101325.0), 0.190295))); + _reports[_next_report].temperature = _TEMP / 100.0f; + _reports[_next_report].pressure = P / 100.0f; /* convert to millibar */ + /* altitude calculations based on http://www.kansasflyer.org/index.asp?nav=Avi&sec=Alti&tab=Theory&pg=1 */ + + /* + * PERFORMANCE HINT: + * + * The single precision calculation is 50 microseconds faster than the double + * precision variant. It is however not obvious if double precision is required. + * Pending more inspection and tests, we'll leave the double precision variant active. + * + * Measurements: + * double precision: ms5611_read: 992 events, 258641us elapsed, min 202us max 305us + * single precision: ms5611_read: 963 events, 208066us elapsed, min 202us max 241us + */ +#if 0/* USE_FLOAT */ + /* tropospheric properties (0-11km) for standard atmosphere */ + const float T1 = 15.0f + 273.15f; /* temperature at base height in Kelvin */ + const float a = -6.5f / 1000f; /* temperature gradient in degrees per metre */ + const float g = 9.80665f; /* gravity constant in m/s/s */ + const float R = 287.05f; /* ideal gas constant in J/kg/K */ + + /* current pressure at MSL in kPa */ + float p1 = _msl_pressure / 1000.0f; + + /* measured pressure in kPa */ + float p = P / 1000.0f; + + /* + * Solve: + * + * / -(aR / g) \ + * | (p / p1) . T1 | - T1 + * \ / + * h = ------------------------------- + h1 + * a + */ + _reports[_next_report].altitude = (((powf((p / p1), (-(a * R) / g))) * T1) - T1) / a; +#else + /* tropospheric properties (0-11km) for standard atmosphere */ + const double T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */ + const double a = -6.5 / 1000; /* temperature gradient in degrees per metre */ + const double g = 9.80665; /* gravity constant in m/s/s */ + const double R = 287.05; /* ideal gas constant in J/kg/K */ + + /* current pressure at MSL in kPa */ + double p1 = _msl_pressure / 1000.0; + + /* measured pressure in kPa */ + double p = P / 1000.0; + + /* + * Solve: + * + * / -(aR / g) \ + * | (p / p1) . T1 | - T1 + * \ / + * h = ------------------------------- + h1 + * a + */ + _reports[_next_report].altitude = (((pow((p / p1), (-(a * R) / g))) * T1) - T1) / a; +#endif /* publish it */ orb_publish(ORB_ID(sensor_baro), _baro_topic, &_reports[_next_report]); @@ -669,7 +770,7 @@ MS5611::collect() /* if we are running up against the oldest report, toss it */ if (_next_report == _oldest_report) { - _buf_overflows++; + perf_count(_buffer_overflows); INCREMENT(_oldest_report, _num_reports); } @@ -685,12 +786,37 @@ MS5611::collect() return OK; } +int +MS5611::cmd_reset() +{ + unsigned old_retrycount = _retries; + uint8_t cmd = ADDR_RESET_CMD; + int result; + + /* bump the retry count */ + _retries = 10; + result = transfer(&cmd, 1, nullptr, 0); + _retries = old_retrycount; + + return result; +} + int MS5611::read_prom() { - /* read PROM data */ - uint8_t prom_buf[2] = {255, 255}; + uint8_t prom_buf[2]; + union { + uint8_t b[2]; + uint16_t w; + } cvt; + /* + * Wait for PROM contents to be in the device (2.8 ms) in the case we are + * called immediately after reset. + */ + usleep(3000); + + /* read and convert PROM words */ for (int i = 0; i < 8; i++) { uint8_t cmd = ADDR_PROM_SETUP + (i * 2); @@ -698,11 +824,12 @@ MS5611::read_prom() break; /* assemble 16 bit value and convert from big endian (sensor) to little endian (MCU) */ - _prom.c[i] = (((uint16_t)prom_buf[0]) << 8) | ((uint16_t)prom_buf[1]); - + cvt.b[0] = prom_buf[1]; + cvt.b[1] = prom_buf[0]; + _prom.c[i] = cvt.w; } - /* calculate CRC and return false */ + /* calculate CRC and return success/failure accordingly */ return crc4(&_prom.c[0]) ? OK : -EIO; } @@ -752,98 +879,112 @@ MS5611::crc4(uint16_t *n_prom) void MS5611::print_info() { - printf("reads: %u\n", _reads); - printf("measure errors: %u\n", _measure_errors); - printf("read errors: %u\n", _read_errors); - printf("read overflows: %u\n", _buf_overflows); + perf_print_counter(_sample_perf); + perf_print_counter(_comms_errors); + perf_print_counter(_buffer_overflows); printf("poll interval: %u ticks\n", _measure_ticks); printf("report queue: %u (%u/%u @ %p)\n", _num_reports, _oldest_report, _next_report, _reports); - printf("dT/temp64: %d/%lld\n", _dT, _temp64); + printf("TEMP: %d\n", _TEMP); + printf("SENS: %lld\n", _SENS); + printf("OFF: %lld\n", _OFF); + printf("MSL pressure: %10.4f\n", (double)(_msl_pressure / 100.f)); + + printf("factory_setup %u\n", _prom.s.factory_setup); + printf("c1_pressure_sens %u\n", _prom.s.c1_pressure_sens); + printf("c2_pressure_offset %u\n", _prom.s.c2_pressure_offset); + printf("c3_temp_coeff_pres_sens %u\n", _prom.s.c3_temp_coeff_pres_sens); + printf("c4_temp_coeff_pres_offset %u\n", _prom.s.c4_temp_coeff_pres_offset); + printf("c5_reference_temp %u\n", _prom.s.c5_reference_temp); + printf("c6_temp_coeff_temp %u\n", _prom.s.c6_temp_coeff_temp); + printf("serial_and_crc %u\n", _prom.s.serial_and_crc); } /** * Local functions in support of the shell command. */ -namespace +namespace ms5611 { -/* oddly, ERROR is not defined for c++ */ -#ifdef ERROR -# undef ERROR -#endif -const int ERROR = -1; - MS5611 *g_dev; -/* - * XXX this should just be part of the generic sensors test... +void start(); +void test(); +void reset(); +void info(); +void calibrate(unsigned altitude); + +/** + * Start the driver. */ - - -int -test_fail(const char *fmt, ...) +void +start() { - va_list ap; + int fd; - fprintf(stderr, "FAIL: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - fflush(stderr); - return ERROR; -} + if (g_dev != nullptr) + errx(1, "already started"); -int -test_note(const char *fmt, ...) -{ - va_list ap; + /* create the driver */ + /* XXX HORRIBLE hack - the bus number should not come from here */ + g_dev = new MS5611(2); - fprintf(stderr, "note: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - fflush(stderr); - return OK; + if (g_dev == nullptr) + goto fail; + + if (OK != g_dev->init()) + goto fail; + + /* set the poll rate to default, starts automatic data collection */ + fd = open(BARO_DEVICE_PATH, O_RDONLY); + if (fd < 0) + goto fail; + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + goto fail; + exit(0); + +fail: + if (g_dev != nullptr) { + delete g_dev; + g_dev = nullptr; + } + errx(1, "driver start failed"); } /** * Perform some basic functional tests on the driver; * make sure we can collect data from the sensor in polled * and automatic modes. - * - * @param fd An open file descriptor on the driver. */ -int -test(int fd) +void +test() { struct baro_report report; ssize_t sz; int ret; + int fd = open(BARO_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "%s open failed (try 'ms5611 start' if the driver is not running)", BARO_DEVICE_PATH); /* do a simple demand read */ sz = read(fd, &report, sizeof(report)); - if (sz != sizeof(report)) - return test_fail("immediate read failed: %d", errno); + err(1, "immediate read failed"); - test_note("single read"); - test_note("pressure: %u", (unsigned)report.pressure); - test_note("altitude: %u", (unsigned)report.altitude); - test_note("temperature: %u", (unsigned)report.temperature); - test_note("time: %lld", report.timestamp); - usleep(1000000); + warnx("single read"); + warnx("pressure: %10.4f", (double)report.pressure); + warnx("altitude: %11.4f", (double)report.altitude); + warnx("temperature: %8.4f", (double)report.temperature); + warnx("time: %lld", report.timestamp); /* set the queue depth to 10 */ - if (OK != ioctl(fd, BAROIOCSQUEUEDEPTH, 10)) - return test_fail("failed to set queue depth"); + if (OK != ioctl(fd, SENSORIOCSQUEUEDEPTH, 10)) + errx(1, "failed to set queue depth"); /* start the sensor polling at 2Hz */ - if (OK != ioctl(fd, BAROIOCSPOLLRATE, 2)) - return test_fail("failed to set 2Hz poll rate"); + if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) + errx(1, "failed to set 2Hz poll rate"); /* read the sensor 5x and report each value */ for (unsigned i = 0; i < 5; i++) { @@ -855,39 +996,118 @@ test(int fd) ret = poll(&fds, 1, 2000); if (ret != 1) - return test_fail("timed out waiting for sensor data"); + errx(1, "timed out waiting for sensor data"); /* now go get it */ sz = read(fd, &report, sizeof(report)); if (sz != sizeof(report)) - return test_fail("periodic read failed: %d", errno); + err(1, "periodic read failed"); - test_note("periodic read %u", i); - test_note("pressure: %u", (unsigned)report.pressure); - test_note("altitude: %u", (unsigned)report.altitude); - test_note("temperature: %u", (unsigned)report.temperature); - test_note("time: %lld", report.timestamp); + warnx("periodic read %u", i); + warnx("pressure: %10.4f", (double)report.pressure); + warnx("altitude: %11.4f", (double)report.altitude); + warnx("temperature: %8.4f", (double)report.temperature); + warnx("time: %lld", report.timestamp); } - return test_note("PASS"); - return OK; + errx(0, "PASS"); } -int +/** + * Reset the driver. + */ +void +reset() +{ + int fd = open(BARO_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "failed "); + if (ioctl(fd, SENSORIOCRESET, 0) < 0) + err(1, "driver reset failed"); + if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) + err(1, "driver poll restart failed"); + + exit(0); +} + +/** + * Print a little info about the driver. + */ +void info() { - if (g_dev == nullptr) { - fprintf(stderr, "MS5611: driver not running\n"); - return -ENOENT; - } + if (g_dev == nullptr) + errx(1, "driver not running"); printf("state @ %p\n", g_dev); g_dev->print_info(); - return OK; + exit(0); } +/** + * Calculate actual MSL pressure given current altitude + */ +void +calibrate(unsigned altitude) +{ + struct baro_report report; + float pressure; + float p1; + + int fd = open(BARO_DEVICE_PATH, O_RDONLY); + if (fd < 0) + err(1, "%s open failed (try 'ms5611 start' if the driver is not running)", BARO_DEVICE_PATH); + + /* start the sensor polling at max */ + if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_MAX)) + errx(1, "failed to set poll rate"); + + /* average a few measurements */ + pressure = 0.0f; + for (unsigned i = 0; i < 20; i++) { + struct pollfd fds; + int ret; + ssize_t sz; + + /* wait for data to be ready */ + fds.fd = fd; + fds.events = POLLIN; + ret = poll(&fds, 1, 1000); + + if (ret != 1) + errx(1, "timed out waiting for sensor data"); + + /* now go get it */ + sz = read(fd, &report, sizeof(report)); + + if (sz != sizeof(report)) + err(1, "sensor read failed"); + + pressure += report.pressure; + } + pressure /= 20; /* average */ + pressure /= 10; /* scale from millibar to kPa */ + + /* tropospheric properties (0-11km) for standard atmosphere */ + const float T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */ + const float a = -6.5 / 1000; /* temperature gradient in degrees per metre */ + const float g = 9.80665f; /* gravity constant in m/s/s */ + const float R = 287.05f; /* ideal gas constant in J/kg/K */ + + warnx("averaged pressure %10.4fkPa at %um", pressure, altitude); + + p1 = pressure * (powf(((T1 + (a * (float)altitude)) / T1), (g / (a * R)))); + + warnx("calculated MSL pressure %10.4fkPa", p1); + + /* save as integer Pa */ + p1 *= 1000.0f; + if (ioctl(fd, BAROIOCSMSLPRESSURE, (unsigned long)p1) != OK) + err(1, "BAROIOCSMSLPRESSURE"); + exit(0); +} } // namespace @@ -896,58 +1116,39 @@ ms5611_main(int argc, char *argv[]) { /* * Start/load the driver. - * - * XXX it would be nice to have a wrapper for this... */ - if (!strcmp(argv[1], "start")) { - - if (g_dev != nullptr) { - fprintf(stderr, "MS5611: already loaded\n"); - return -EBUSY; - } - - /* create the driver */ - /* XXX HORRIBLE hack - the bus number should not come from here */ - g_dev = new MS5611(2); - - if (g_dev == nullptr) { - fprintf(stderr, "MS5611: driver alloc failed\n"); - return -ENOMEM; - } - - if (OK != g_dev->init()) { - fprintf(stderr, "MS5611: driver init failed\n"); - usleep(100000); - delete g_dev; - g_dev = nullptr; - return -EIO; - } - - return OK; - } + if (!strcmp(argv[1], "start")) + ms5611::start(); /* * Test the driver/device. */ - if (!strcmp(argv[1], "test")) { - int fd, ret; + if (!strcmp(argv[1], "test")) + ms5611::test(); - fd = open(BARO_DEVICE_PATH, O_RDONLY); - - if (fd < 0) - return test_fail("driver open failed: %d", errno); - - ret = test(fd); - close(fd); - return ret; - } + /* + * Reset the driver. + */ + if (!strcmp(argv[1], "reset")) + ms5611::reset(); /* * Print driver information. */ if (!strcmp(argv[1], "info")) - return info(); + ms5611::info(); - fprintf(stderr, "unrecognised command, try 'start', 'test' or 'info'\n"); - return -EINVAL; + /* + * Perform MSL pressure calibration given an altitude in metres + */ + if (!strcmp(argv[1], "calibrate")) { + if (argc < 2) + errx(1, "missing altitude"); + + long altitude = strtol(argv[2], nullptr, 10); + + ms5611::calibrate(altitude); + } + + errx(1, "unrecognised command, try 'start', 'test', 'reset' or 'info'"); } diff --git a/apps/examples/Kconfig b/apps/examples/Kconfig index a20f7c2e77..865268addb 100644 --- a/apps/examples/Kconfig +++ b/apps/examples/Kconfig @@ -3,115 +3,115 @@ # see misc/tools/kconfig-language.txt. # -menu "ADC example" +menu "ADC Example" source "$APPSDIR/examples/adc/Kconfig" endmenu -menu "Buttons example" +menu "Buttons Example" source "$APPSDIR/examples/buttons/Kconfig" endmenu -menu "CAN example" +menu "CAN Example" source "$APPSDIR/examples/can/Kconfig" endmenu -menu "USB CDC/ACM class driver example" +menu "USB CDC/ACM Class Driver Example" source "$APPSDIR/examples/cdcacm/Kconfig" endmenu -menu "USB composite class driver example" +menu "USB composite Class Driver Example" source "$APPSDIR/examples/composite/Kconfig" endmenu -menu "DHCP server example" +menu "DHCP Server Example" source "$APPSDIR/examples/dhcpd/Kconfig" endmenu -menu "FTP client example" +menu "FTP Client Example" source "$APPSDIR/examples/ftpc/Kconfig" endmenu -menu "FTP server example" +menu "FTP Server Example" source "$APPSDIR/examples/ftpd/Kconfig" endmenu -menu "\"Hello, World!\" example" +menu "\"Hello, World!\" Example" source "$APPSDIR/examples/hello/Kconfig" endmenu -menu "\"Hello, World!\" C++ example" +menu "\"Hello, World!\" C++ Example" source "$APPSDIR/examples/helloxx/Kconfig" endmenu -menu "USB HID keyboard example" +menu "USB HID Keyboard Example" source "$APPSDIR/examples/hidkbd/Kconfig" endmenu -menu "IGMP example" +menu "IGMP Example" source "$APPSDIR/examples/igmp/Kconfig" endmenu -menu "LCD read/write example" +menu "LCD Read/Write Example" source "$APPSDIR/examples/lcdrw/Kconfig" endmenu -menu "Memory management example" +menu "Memory Management Example" source "$APPSDIR/examples/mm/Kconfig" endmenu -menu "File system mount example" +menu "File System Mount Example" source "$APPSDIR/examples/mount/Kconfig" endmenu -menu "FreeModBus example" +menu "FreeModBus Example" source "$APPSDIR/examples/modbus/Kconfig" endmenu -menu "Network test example" +menu "Network Test Example" source "$APPSDIR/examples/nettest/Kconfig" endmenu -menu "NuttShell (NSH) example" +menu "NuttShell (NSH) Example" source "$APPSDIR/examples/nsh/Kconfig" endmenu -menu "NULL example" +menu "NULL Example" source "$APPSDIR/examples/null/Kconfig" endmenu -menu "NX graphics example" +menu "NX Graphics Example" source "$APPSDIR/examples/nx/Kconfig" endmenu -menu "NxConsole example" +menu "NxConsole Example" source "$APPSDIR/examples/nxconsole/Kconfig" endmenu -menu "NXFFS file system example" +menu "NXFFS File System Example" source "$APPSDIR/examples/nxffs/Kconfig" endmenu -menu "NXFLAT example" +menu "NXFLAT Example" source "$APPSDIR/examples/nxflat/Kconfig" endmenu -menu "NX graphics \"Hello, World!\" example" +menu "NX Graphics \"Hello, World!\" Example" source "$APPSDIR/examples/nxhello/Kconfig" endmenu -menu "NX graphics image example" +menu "NX Graphics image Example" source "$APPSDIR/examples/nximage/Kconfig" endmenu -menu "NX graphics lines example" +menu "NX Graphics lines Example" source "$APPSDIR/examples/nxlines/Kconfig" endmenu -menu "NX graphics text example" +menu "NX Graphics Text Example" source "$APPSDIR/examples/nxtext/Kconfig" endmenu -menu "OS test example" +menu "OS Test Example" source "$APPSDIR/examples/ostest/Kconfig" endmenu @@ -119,82 +119,90 @@ menu "Pascal \"Hello, World!\"example" source "$APPSDIR/examples/pashello/Kconfig" endmenu -menu "Pipe example" +menu "Pipe Example" source "$APPSDIR/examples/pipe/Kconfig" endmenu -menu "Poll example" +menu "Poll Example" source "$APPSDIR/examples/poll/Kconfig" endmenu -menu "Pulse width modulation (PWM) example" +menu "Pulse Width Modulation (PWM) Example" source "$APPSDIR/examples/pwm/Kconfig" endmenu -menu "Quadrature encoder example" +menu "Quadrature Encoder Example" source "$APPSDIR/examples/qencoder/Kconfig" endmenu -menu "RGMP example" +menu "RGMP Example" source "$APPSDIR/examples/rgmp/Kconfig" endmenu -menu "ROMFS example" +menu "ROMFS Example" source "$APPSDIR/examples/romfs/Kconfig" endmenu -menu "sendmail example" +menu "sendmail Example" source "$APPSDIR/examples/sendmail/Kconfig" endmenu -menu "Serial loopback example" +menu "Serial Loopback Example" source "$APPSDIR/examples/serloop/Kconfig" endmenu -menu "Telnet daemon example" +menu "Telnet Daemon Example" source "$APPSDIR/examples/telnetd/Kconfig" endmenu -menu "THTTPD web server example" +menu "THTTPD Web Server Example" source "$APPSDIR/examples/thttpd/Kconfig" endmenu -menu "TIFF generation example" +menu "TIFF Generation Example" source "$APPSDIR/examples/tiff/Kconfig" endmenu -menu "Touchscreen example" +menu "Touchscreen Example" source "$APPSDIR/examples/touchscreen/Kconfig" endmenu -menu "UDP example" +menu "UDP Example" source "$APPSDIR/examples/udp/Kconfig" endmenu -menu "uIP web server example" +menu "UDP Discovery Daemon Example" +source "$APPSDIR/examples/discover/Kconfig" +endmenu + +menu "uIP Web Server Example" source "$APPSDIR/examples/uip/Kconfig" endmenu -menu "USB serial test example" +menu "USB Serial Test Example" source "$APPSDIR/examples/usbserial/Kconfig" endmenu -menu "USB mass storage class example" +menu "USB Mass Storage Class Example" source "$APPSDIR/examples/usbstorage/Kconfig" endmenu -menu "USB serial terminal example" +menu "USB Serial Terminal Example" source "$APPSDIR/examples/usbterm/Kconfig" endmenu -menu "Watchdog timer example" +menu "Watchdog timer Example" source "$APPSDIR/examples/watchdog/Kconfig" endmenu -menu "wget example" +menu "wget Example" source "$APPSDIR/examples/wget/Kconfig" endmenu -menu "WLAN example" +menu "WLAN Example" source "$APPSDIR/examples/wlan/Kconfig" endmenu + +menu "XML RPC Example" +source "$APPSDIR/examples/xmlrpc/Kconfig" +endmenu diff --git a/apps/examples/Make.defs b/apps/examples/Make.defs index aa8d83733b..a6e0ae88e4 100644 --- a/apps/examples/Make.defs +++ b/apps/examples/Make.defs @@ -58,6 +58,10 @@ ifeq ($(CONFIG_EXAMPLES_DHCPD),y) CONFIGURED_APPS += examples/dhcpd endif +ifeq ($(CONFIG_EXAMPLE_DISCOVER),y) +CONFIGURED_APPS += examples/discover +endif + ifeq ($(CONFIG_EXAMPLES_FTPC),y) CONFIGURED_APPS += examples/ftpc endif @@ -221,3 +225,7 @@ endif ifeq ($(CONFIG_EXAMPLES_WLAN),y) CONFIGURED_APPS += examples/wlan endif + +ifeq ($(CONFIG_EXAMPLES_XMLRPC),y) +CONFIGURED_APPS += examples/xmlrpc +endif diff --git a/apps/examples/Makefile b/apps/examples/Makefile index ad5be64978..453f99ce71 100644 --- a/apps/examples/Makefile +++ b/apps/examples/Makefile @@ -37,11 +37,12 @@ # Sub-directories -SUBDIRS = adc buttons can cdcacm composite dhcpd ftpc ftpd hello helloxx \ - hidkbd igmp lcdrw mm modbus mount nettest nsh null nx nxconsole nxffs \ - nxflat nxhello nximage nxlines nxtext ostest pashello pipe poll pwm \ - qencoder rgmp romfs serloop telnetd thttpd tiff touchscreen udp uip \ - usbserial sendmail usbstorage usbterm watchdog wget wlan +SUBDIRS = adc buttons can cdcacm composite dhcpd discover ftpc ftpd hello +SUBDIRS += helloxx hidkbd igmp lcdrw mm modbus mount nettest nsh null nx +SUBDIRS += nxconsole nxffs nxflat nxhello nximage nxlines nxtext ostest +SUBDIRS += pashello pipe poll pwm qencoder rgmp romfs serloop telnetd +SUBDIRS += thttpd tiff touchscreen udp uip usbserial sendmail usbstorage +SUBDIRS += usbterm watchdog wget wlan # Sub-directories that might need context setup. Directories may need # context setup for a variety of reasons, but the most common is because @@ -56,7 +57,8 @@ SUBDIRS = adc buttons can cdcacm composite dhcpd ftpc ftpd hello helloxx \ CNTXTDIRS = pwm ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -CNTXTDIRS += adc can cdcacm composite ftpd dhcpd modbus nettest qencoder telnetd watchdog +CNTXTDIRS += adc can cdcacm composite discover ftpd dhcpd modbus nettest +CNTXTDIRS += qencoder telnetd watchdog endif ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y) diff --git a/apps/examples/README.txt b/apps/examples/README.txt index 7d068f9794..12d6d38929 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -275,6 +275,28 @@ examples/dhcpd CONFIGURED_APPS += uiplib +examples/discover +^^^^^^^^^^^^^^^^^ + + This example exercises netutils/discover utility. This example initializes + and starts the UDP discover daemon. This daemon is useful for discovering + devices in local networks, especially with DHCP configured devices. It + listens for UDP broadcasts which also can include a device class so that + groups of devices can be discovered. It is also possible to address all + classes with a kind of broadcast discover. + + This example will automatically be built as an NSH built-in if + CONFIG_NSH_BUILTIN_APPS is selected. Otherwise, it will be a standalone + program with entry point "discover_main". + + NuttX configuration settings: + + CONFIG_EXAMPLE_DISCOVER_DHCPC - DHCP Client + CONFIG_EXAMPLE_DISCOVER_NOMAC - Use canned MAC address + CONFIG_EXAMPLE_DISCOVER_IPADDR - Target IP address + CONFIG_EXAMPLE_DISCOVER_DRIPADDR - Router IP address + CONFIG_EXAMPLE_DISCOVER_NETMASK - Network Mask + examples/ftpc ^^^^^^^^^^^^^ @@ -1111,7 +1133,7 @@ examples/rgmp See http://rgmp.sourceforge.net/wiki/index.php/Main_Page for further - At present, the RGMP example folder contains only an empty main.c file. + At present, the RGMP example folder contains only an empty rgmp_main.c file. examples/romfs ^^^^^^^^^^^^^^ @@ -1345,10 +1367,14 @@ examples/uip file in the configuration driver with instruction to build applications like: - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += dhcpc - CONFIGURED_APPS += resolv - CONFIGURED_APPS += webserver + CONFIGURED_APPS += uiplib + CONFIGURED_APPS += dhcpc + CONFIGURED_APPS += resolv + CONFIGURED_APPS += webserver + + NOTE: This example does depend on the perl script at + nuttx/tools/mkfsdata.pl. You must have perl installed on your + development system at /usr/bin/perl. examples/usbserial ^^^^^^^^^^^^^^^^^^ @@ -1642,8 +1668,27 @@ examples/wget file in the configuration driver with instruction to build applications like: - CONFIGURED_APPS += uiplib - CONFIGURED_APPS += resolv - CONFIGURED_APPS += webclient + CONFIGURED_APPS += uiplib + CONFIGURED_APPS += resolv + CONFIGURED_APPS += webclient +examples/xmlrpc + This example exercises the "Embeddable Lightweight XML-RPC Server" which + is discussed at: + + http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364 + + Configuration options: + + CONFIG_EXAMPLES_XMLRPC_BUFFERSIZE - HTTP buffer size. Default 1024 + CONFIG_EXAMPLES_XMLRPC_DHCPC - Use DHCP Client. Default n. Ignored + if CONFIG_NSH_BUILTIN_APPS is selected. + CONFIG_EXAMPLES_XMLRPC_NOMAC - Use Canned MAC Address. Defaul n. Ignored + if CONFIG_NSH_BUILTIN_APPS is selected. + CONFIG_EXAMPLES_XMLRPC_IPADDR - Target IP address. Default 0x0a000002. + Ignored if CONFIG_NSH_BUILTIN_APPS is selected. + CONFIG_EXAMPLES_XMLRPC_DRIPADDR - Default Router IP address (Gateway). + Default 0x0a000001. Ignored if CONFIG_NSH_BUILTIN_APPS is selected. + CONFIG_EXAMPLES_XMLRPC_NETMASK - Network Mask. Default 0xffffff00 + Ignored if CONFIG_NSH_BUILTIN_APPS is selected. diff --git a/apps/examples/adc/adc_main.c b/apps/examples/adc/adc_main.c index b880326549..4797265db0 100644 --- a/apps/examples/adc/adc_main.c +++ b/apps/examples/adc/adc_main.c @@ -57,14 +57,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME adc_main -# define MAIN_STRING "adc_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -223,10 +215,10 @@ static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv) ****************************************************************************/ /**************************************************************************** - * Name: user_start/adc_main + * Name: adc_main ****************************************************************************/ -int MAIN_NAME(int argc, char *argv[]) +int adc_main(int argc, char *argv[]) { struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE]; size_t readsize; @@ -244,11 +236,11 @@ int MAIN_NAME(int argc, char *argv[]) * this test. */ - message(MAIN_STRING "Initializing external ADC device\n"); + message("adc_main: Initializing external ADC device\n"); ret = adc_devinit(); if (ret != OK) { - message(MAIN_STRING "adc_devinit failed: %d\n", ret); + message("adc_main: adc_devinit failed: %d\n", ret); errval = 1; goto errout; } @@ -276,18 +268,18 @@ int MAIN_NAME(int argc, char *argv[]) */ #if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES) - message(MAIN_STRING "g_adcstate.count: %d\n", g_adcstate.count); + message("adc_main: g_adcstate.count: %d\n", g_adcstate.count); #endif /* Open the ADC device for reading */ - message(MAIN_STRING "Hardware initialized. Opening the ADC device: %s\n", + message("adc_main: Hardware initialized. Opening the ADC device: %s\n", g_adcstate.devpath); fd = open(g_adcstate.devpath, O_RDONLY); if (fd < 0) { - message(MAIN_STRING "open %s failed: %d\n", g_adcstate.devpath, errno); + message("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno); errval = 2; goto errout_with_dev; } @@ -322,17 +314,17 @@ int MAIN_NAME(int argc, char *argv[]) errval = errno; if (errval != EINTR) { - message(MAIN_STRING "read %s failed: %d\n", + message("adc_main: read %s failed: %d\n", g_adcstate.devpath, errval); errval = 3; goto errout_with_dev; } - message(MAIN_STRING "Interrupted read...\n"); + message("adc_main: Interrupted read...\n"); } else if (nbytes == 0) { - message(MAIN_STRING "No data read, Ignoring\n"); + message("adc_main: No data read, Ignoring\n"); } /* Print the sample data on successful return */ @@ -342,7 +334,7 @@ int MAIN_NAME(int argc, char *argv[]) int nsamples = nbytes / sizeof(struct adc_msg_s); if (nsamples * sizeof(struct adc_msg_s) != nbytes) { - message(MAIN_STRING "read size=%d is not a multiple of sample size=%d, Ignoring\n", + message("adc_main: read size=%d is not a multiple of sample size=%d, Ignoring\n", nbytes, sizeof(struct adc_msg_s)); } else diff --git a/apps/examples/buttons/Makefile b/apps/examples/buttons/Makefile index 9c05871998..25d1ef2c2d 100644 --- a/apps/examples/buttons/Makefile +++ b/apps/examples/buttons/Makefile @@ -2,7 +2,7 @@ # apps/examples/buttons/Makefile # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -40,7 +40,7 @@ include $(APPDIR)/Make.defs # Hello, World! Example ASRCS = -CSRCS = main.c +CSRCS = buttons_main.c AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/apps/examples/buttons/main.c b/apps/examples/buttons/buttons_main.c similarity index 97% rename from apps/examples/buttons/main.c rename to apps/examples/buttons/buttons_main.c index fe447ca6b6..a3f6449d4f 100644 --- a/apps/examples/buttons/main.c +++ b/apps/examples/buttons/buttons_main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/buttons/main.c + * examples/buttons/buttons_main.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -130,16 +130,6 @@ #define NUM_BUTTONS (MAX_BUTTON - MIN_BUTTON + 1) #define BUTTON_INDEX(b) ((b)-MIN_BUTTON) -/* Is this being built as an NSH built-in application? */ - -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME buttons_main -# define MAIN_STRING "buttons_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -399,10 +389,10 @@ static int button7_handler(int irq, FAR void *context) ****************************************************************************/ /**************************************************************************** - * user_start/buttons_main + * buttons_main ****************************************************************************/ -int MAIN_NAME(int argc, char *argv[]) +int buttons_main(int argc, char *argv[]) { uint8_t newset; irqstate_t flags; diff --git a/apps/examples/can/can_main.c b/apps/examples/can/can_main.c index 0ea729e5e8..482d3f4383 100644 --- a/apps/examples/can/can_main.c +++ b/apps/examples/can/can_main.c @@ -2,7 +2,7 @@ * examples/can/can_main.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -76,14 +76,6 @@ # define MAX_ID (1 << 11) #endif -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME can_main -# define MAIN_STRING "can_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -109,10 +101,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: user_start/can_main + * Name: can_main ****************************************************************************/ -int MAIN_NAME(int argc, char *argv[]) +int can_main(int argc, char *argv[]) { #ifndef CONFIG_EXAMPLES_CAN_READONLY struct can_msg_s txmsg; @@ -150,31 +142,31 @@ int MAIN_NAME(int argc, char *argv[]) { nmsgs = strtol(argv[1], NULL, 10); } - message(MAIN_STRING "nmsgs: %d\n", nmsgs); + message("can_main: nmsgs: %d\n", nmsgs); #elif defined(CONFIG_EXAMPLES_CAN_NMSGS) - message(MAIN_STRING "nmsgs: %d\n", CONFIG_EXAMPLES_CAN_NMSGS); + message("can_main: nmsgs: %d\n", CONFIG_EXAMPLES_CAN_NMSGS); #endif /* Initialization of the CAN hardware is performed by logic external to * this test. */ - message(MAIN_STRING "Initializing external CAN device\n"); + message("can_main: Initializing external CAN device\n"); ret = can_devinit(); if (ret != OK) { - message(MAIN_STRING "can_devinit failed: %d\n", ret); + message("can_main: can_devinit failed: %d\n", ret); errval = 1; goto errout; } /* Open the CAN device for reading */ - message(MAIN_STRING "Hardware initialized. Opening the CAN device\n"); + message("can_main: Hardware initialized. Opening the CAN device\n"); fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS); if (fd < 0) { - message(MAIN_STRING "open %s failed: %d\n", + message("can_main: open %s failed: %d\n", CONFIG_EXAMPLES_CAN_DEVPATH, errno); errval = 2; goto errout_with_dev; diff --git a/apps/examples/hello/Makefile b/apps/examples/hello/Makefile index 9c3cda894b..1d78d723ed 100644 --- a/apps/examples/hello/Makefile +++ b/apps/examples/hello/Makefile @@ -46,7 +46,7 @@ STACKSIZE = 2048 # Hello, World! Example ASRCS = -CSRCS = main.c +CSRCS = hello_main.c AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/apps/examples/hello/main.c b/apps/examples/hello/hello_main.c similarity index 93% rename from apps/examples/hello/main.c rename to apps/examples/hello/hello_main.c index 7934dc34ba..229027c36b 100644 --- a/apps/examples/hello/main.c +++ b/apps/examples/hello/hello_main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/hello/main.c + * examples/hello/hello_main.c * * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -53,16 +53,10 @@ ****************************************************************************/ /**************************************************************************** - * user_start/hello_main + * hello_main ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_HELLO_BUILTIN -# define MAIN_NAME hello_main -#else -# define MAIN_NAME user_start -#endif - -int MAIN_NAME(int argc, char *argv[]) +int hello_main(int argc, char *argv[]) { printf("Hello, World!!\n"); return 0; diff --git a/apps/examples/helloxx/Makefile b/apps/examples/helloxx/Makefile index c34378d249..8e85eab23e 100644 --- a/apps/examples/helloxx/Makefile +++ b/apps/examples/helloxx/Makefile @@ -2,7 +2,7 @@ # apps/examples/helloxx/Makefile # # Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -41,7 +41,7 @@ include $(APPDIR)/Make.defs ASRCS = CSRCS = -CXXSRCS = main.cxx +CXXSRCS = helloxx_main.cxx AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/apps/examples/helloxx/main.cxx b/apps/examples/helloxx/helloxx_main.cxx similarity index 86% rename from apps/examples/helloxx/main.cxx rename to apps/examples/helloxx/helloxx_main.cxx index 8514fead22..60fd0487b5 100644 --- a/apps/examples/helloxx/main.cxx +++ b/apps/examples/helloxx/helloxx_main.cxx @@ -1,5 +1,5 @@ //*************************************************************************** -// examples/helloxx/main.cxx +// examples/helloxx/helloxx_main.cxx // // Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved. // Author: Gregory Nutt @@ -124,24 +124,11 @@ static CHelloWorld g_HelloWorld; // Public Functions //*************************************************************************** -//*************************************************************************** -// user_start -//*************************************************************************** - /**************************************************************************** - * Name: user_start/nxhello_main + * Name: helloxx_main ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_HELLOXX_BUILTIN -extern "C" int helloxx_main(int argc, char *argv[]); -# define MAIN_NAME helloxx_main -# define MAIN_STRING "helloxx_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - -int MAIN_NAME(int argc, char *argv[]) +int helloxx_main(int argc, char *argv[]) { // If C++ initialization for static constructors is supported, then do // that first @@ -153,7 +140,7 @@ int MAIN_NAME(int argc, char *argv[]) // Exercise an explictly instantiated C++ object CHelloWorld *pHelloWorld = new CHelloWorld; - printf(MAIN_STRING "Saying hello from the dynamically constructed instance\n"); + printf("helloxx_main: Saying hello from the dynamically constructed instance\n"); pHelloWorld->HelloWorld(); // Exercise an C++ object instantiated on the stack @@ -161,14 +148,14 @@ int MAIN_NAME(int argc, char *argv[]) #ifndef CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST CHelloWorld HelloWorld; - printf(MAIN_STRING "Saying hello from the instance constructed on the stack\n"); + printf("helloxx_main: Saying hello from the instance constructed on the stack\n"); HelloWorld.HelloWorld(); #endif // Exercise an statically constructed C++ object #ifdef CONFIG_HAVE_CXXINITIALIZE - printf(MAIN_STRING "Saying hello from the statically constructed instance\n"); + printf("helloxx_main: Saying hello from the statically constructed instance\n"); g_HelloWorld.HelloWorld(); #endif diff --git a/apps/examples/lcdrw/Makefile b/apps/examples/lcdrw/Makefile deleted file mode 100644 index 053c626703..0000000000 --- a/apps/examples/lcdrw/Makefile +++ /dev/null @@ -1,105 +0,0 @@ -############################################################################ -# apps/examples/lcdrw/Makefile -# -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# LCD Read/Write Test - -ASRCS = -CSRCS = lcdrw_main.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(WINTOOL),y) - BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}" -else - BIN = "$(APPDIR)/libapps$(LIBEXT)" -endif - -ROOTDEPPATH = --dep-path . - -# LCD R/W built-in application info - -APPNAME = lcdrw -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 - -# Common build - -VPATH = - -all: .built -.PHONY: clean depend distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $(BIN), $${obj}); \ - done ; ) - @touch .built - -.context: -ifeq ($(CONFIG_EXAMPLES_LCDRW_BUILTIN),y) - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - @touch $@ -endif - -context: .context - -.depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -clean: - @rm -f *.o *~ .*.swp .built - $(call CLEAN) - -distclean: clean - @rm -f Make.dep .depend - --include Make.dep diff --git a/apps/examples/lcdrw/lcdrw_main.c b/apps/examples/lcdrw/lcdrw_main.c deleted file mode 100644 index c366743f47..0000000000 --- a/apps/examples/lcdrw/lcdrw_main.c +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** - * examples/lcdrw/lcdrw_main.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* Most of the NX configuration settings are probbably *not* needed by this - * example. But, presumeably you are using NX too and so the checks might - * be good for you. - */ - -#ifndef CONFIG_NX -# error "CONFIG_NX must be defined to use this test" -#endif - -#ifndef CONFIG_NX_LCDDRIVER -# error "CONFIG_NX_LCDDRIVER must be defined to use this test" -#endif - -#ifndef CONFIG_EXAMPLES_LCDRW_BPP -# define CONFIG_EXAMPLES_LCDRW_BPP 16 -#endif - -#if CONFIG_EXAMPLES_LCDRW_BPP != 16 -# error "Currently only RGB565 is supported -- feel free to extend" -#endif - -#ifdef CONFIG_NX_DISABLE_16BPP -# error "CONFIG_NX_DISABLE_16BPP disables 16-bit support" -#endif - -#ifndef CONFIG_EXAMPLES_LDCRW_DEVNO -# define CONFIG_EXAMPLES_LDCRW_DEVNO 0 -#endif - -#ifndef CONFIG_EXAMPLES_LDCRW_XRES -# define CONFIG_EXAMPLES_LDCRW_XRES 240 -#endif - -#ifndef CONFIG_EXAMPLES_LDCRW_YRES -# define CONFIG_EXAMPLES_LDCRW_YRES 320 -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct lcdrw_instance_s -{ - /* LCD device handle and planeinfo */ - - FAR struct lcd_dev_s *dev; - struct lcd_planeinfo_s pinfo; -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ -/**************************************************************************** - * Name: lcdrw_initialize - ****************************************************************************/ - -static inline int lcdrw_initialize(FAR struct lcdrw_instance_s *inst) -{ - int ret; - - /* Initialize the LCD device */ - - printf("screens_initialize: Initializing LCD\n"); - ret = up_lcdinitialize(); - if (ret < 0) - { - fprintf(stderr, "screens_initialize: up_lcdinitialize failed: %d\n", -ret); - return ret; - } - - /* Get the device instance. */ - - printf("Get LCD instance\n"); - inst->dev = up_lcdgetdev(CONFIG_EXAMPLES_LDCRW_DEVNO); - if (!inst->dev) - { - fprintf(stderr, "up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_LDCRW_DEVNO); - return ret; - } - - /* Turn the LCD on at 75% power. This should not be necessary. */ - - (void)inst->dev->setpower(inst->dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4)); - - /* Get the planeinfo structure */ - - ret = inst->dev->getplaneinfo(inst->dev, 0, &inst->pinfo); - if (ret < 0) - { - fprintf(stderr, "getplaneinfo failed: %d\n", ret); - } - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lcdrw_main/user_start - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_LCDRW_BUILTIN -# define MAIN_NAME lcdrw_main -#else -# define MAIN_NAME user_start -#endif - -int MAIN_NAME(int argc, char *argv[]) -{ - struct lcdrw_instance_s inst; - nxgl_coord_t row; - nxgl_coord_t col; - uint16_t value; - uint32_t offset; - FAR uint16_t *ptr; - int ret; - - /* Initialize the LCD driver */ - - ret = lcdrw_initialize(&inst); - if (ret < 0) - { - exit(1); - } - - /* Loop, writing all possible values to the LCD */ - - value = 0; - for (row = 0; row < CONFIG_EXAMPLES_LDCRW_YRES; row++) - { - /* Create a dummy row. The important thing is to try all - * bit combinations in a predictable way. - */ - - ptr = (FAR uint16_t*)inst.pinfo.buffer; - for (col = 0; col < CONFIG_EXAMPLES_LDCRW_XRES; col++) - { - *ptr++ = value++; - } - - /* Write the row to the LCD */ - - ret = inst.pinfo.putrun(row, 0, inst.pinfo.buffer, - CONFIG_EXAMPLES_LDCRW_XRES); - if (ret < 0) - { - fprintf(stderr, "putrun failed: %d\n", ret); - exit(1); - } - } - - /* Print a header */ - - printf(" "); - for (col = 0; col < 15; col++) - { - printf("---%x ", col); - } - printf("---f\n"); - - /* Then read each line back from the LCD. */ - - offset = 0; - for (row = 0; row < CONFIG_EXAMPLES_LDCRW_YRES; row++) - { - /* Read the row */ - - ret = inst.pinfo.getrun(row, 0, inst.pinfo.buffer, - CONFIG_EXAMPLES_LDCRW_XRES); - if (ret < 0) - { - fprintf(stderr, "getrun failed: %d\n", ret); - exit(1); - } - - /* Then dump the row to the display */ - - ptr = (FAR uint16_t*)inst.pinfo.buffer; - for (col = 0; col < CONFIG_EXAMPLES_LDCRW_XRES; col++) - { - if ((offset & 15) == 0) - { - printf("%06x ", offset); - } - - value = *ptr++; - offset++; - - if ((offset & 15) == 0) - { - printf("%04x\n", value); - } - else - { - printf("%04x ", value); - } - } - } - fflush(stdout); - - return 0; -} - diff --git a/apps/examples/mm/Makefile b/apps/examples/mm/Makefile index e5d9ffb4cf..24ed4926f7 100644 --- a/apps/examples/mm/Makefile +++ b/apps/examples/mm/Makefile @@ -2,7 +2,7 @@ # apps/examples/mm/Makefile # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/mm/mm_main.c b/apps/examples/mm/mm_main.c index 036c390474..149550418c 100644 --- a/apps/examples/mm/mm_main.c +++ b/apps/examples/mm/mm_main.c @@ -2,7 +2,7 @@ * examples/mm/mm_main.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -267,10 +267,10 @@ static void do_frees(void **mem, const int *size, const int *seq, int n) ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: mm_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int mm_main(int argc, char *argv[]) { mm_showmallinfo(); diff --git a/apps/examples/mount/Makefile b/apps/examples/mount/Makefile index 7e48ea44a9..69cf970cf0 100644 --- a/apps/examples/mount/Makefile +++ b/apps/examples/mount/Makefile @@ -2,7 +2,7 @@ # apps/Makefile # # Copyright (C) 2007-2008, 2010-2010 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/mount/mount.h b/apps/examples/mount/mount.h index 68a03674da..c756860860 100644 --- a/apps/examples/mount/mount.h +++ b/apps/examples/mount/mount.h @@ -2,7 +2,7 @@ * examples/mount/mount.h * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/mount/mount_main.c b/apps/examples/mount/mount_main.c index 00070b94c0..e0eb8a6150 100644 --- a/apps/examples/mount/mount_main.c +++ b/apps/examples/mount/mount_main.c @@ -2,7 +2,7 @@ * examples/mount/mount_main.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -567,10 +567,10 @@ static void succeed_stat(const char *path) ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: mount_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int mount_main(int argc, char *argv[]) { int ret; @@ -580,18 +580,18 @@ int user_start(int argc, char *argv[]) ret = create_ramdisk(); if (ret < 0) { - printf("user_start: ERROR failed to create RAM disk\n"); + printf("mount_main: ERROR failed to create RAM disk\n"); return 1; } #endif /* Mount the test file system (see arch/sim/src/up_deviceimage.c */ - printf("user_start: mounting %s filesystem at target=%s with source=%s\n", + printf("mount_main: mounting %s filesystem at target=%s with source=%s\n", g_filesystemtype, g_target, g_source); ret = mount(g_source, g_target, g_filesystemtype, 0, NULL); - printf("user_start: mount() returned %d\n", ret); + printf("mount_main: mount() returned %d\n", ret); if (ret == 0) { @@ -737,16 +737,16 @@ int user_start(int argc, char *argv[]) /* Unmount the file system */ - printf("user_start: Try unmount(%s)\n", g_target); + printf("mount_main: Try unmount(%s)\n", g_target); ret = umount(g_target); if (ret != 0) { - printf("user_start: ERROR umount() failed, errno %d\n", errno); + printf("mount_main: ERROR umount() failed, errno %d\n", errno); g_nerrors++; } - printf("user_start: %d errors reported\n", g_nerrors); + printf("mount_main: %d errors reported\n", g_nerrors); } fflush(stdout); diff --git a/apps/examples/mount/ramdisk.c b/apps/examples/mount/ramdisk.c index 9688580c06..83ef74e423 100644 --- a/apps/examples/mount/ramdisk.c +++ b/apps/examples/mount/ramdisk.c @@ -2,7 +2,7 @@ * examples/mount/ramdisk.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/nsh/Kconfig b/apps/examples/nsh/Kconfig index 289c7e515e..309aa925eb 100644 --- a/apps/examples/nsh/Kconfig +++ b/apps/examples/nsh/Kconfig @@ -6,6 +6,8 @@ config EXAMPLES_NSH bool "NuttShell (NSH) example" default n + select NSH_LIBRARY + select SYSTEM_READLINE ---help--- Enable the NuttShell (NSH) example diff --git a/apps/examples/nsh/Makefile b/apps/examples/nsh/Makefile index b5844f9edc..bad40fb2e2 100644 --- a/apps/examples/nsh/Makefile +++ b/apps/examples/nsh/Makefile @@ -2,7 +2,7 @@ # apps/examples/nsh/Makefile # # Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/nsh/nsh_main.c b/apps/examples/nsh/nsh_main.c index c5b671ab14..97792cb2a3 100644 --- a/apps/examples/nsh/nsh_main.c +++ b/apps/examples/nsh/nsh_main.c @@ -84,10 +84,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: nsh_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int nsh_main(int argc, char *argv[]) { int exitval = 0; int ret; diff --git a/apps/examples/null/Makefile b/apps/examples/null/Makefile index 3938eb1711..6341206007 100644 --- a/apps/examples/null/Makefile +++ b/apps/examples/null/Makefile @@ -2,7 +2,7 @@ # examples/null/Makefile # # Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/null/null_main.c b/apps/examples/null/null_main.c index 10fc1bf1e4..c4624bd1d5 100644 --- a/apps/examples/null/null_main.c +++ b/apps/examples/null/null_main.c @@ -2,7 +2,7 @@ * examples/null/null_main.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,10 +58,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: null_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int null_main(int argc, char *argv[]) { return 0; } diff --git a/apps/examples/ostest/Kconfig b/apps/examples/ostest/Kconfig index ca89579934..0da7e4ce34 100644 --- a/apps/examples/ostest/Kconfig +++ b/apps/examples/ostest/Kconfig @@ -10,4 +10,33 @@ config EXAMPLES_OSTEST Enable the OS test example if EXAMPLES_OSTEST + +config EXAMPLES_OSTEST_BUILTIN + bool "NSH built-in application" + default y if NSH_LIBRARY + default n if !NSH_LIBRARY + ---help--- + Build the OS test example as an NSH built-in application. + +config EXAMPLES_OSTEST_LOOPS + int "OS test loop" + default 1 + ---help--- + Used to control the number of executions of the test. If undefined, the test + executes one time. If defined to be zero, the test runs forever. + +config EXAMPLES_OSTEST_STACKSIZE + int "OS test stack size" + default 8192 + ---help--- + Size of the stack used to create the ostest task. Default is 8192. + +config EXAMPLES_OSTEST_NBARRIER_THREADS + int "Number of barrier threads" + default 8 + ---help--- + Specifies the number of threads to create in the barrier test. The default + is 8 but a smaller number may be needed on systems without sufficient memory + to start so many threads. + endif diff --git a/apps/examples/ostest/Makefile b/apps/examples/ostest/Makefile index eab1db8b39..374964b396 100644 --- a/apps/examples/ostest/Makefile +++ b/apps/examples/ostest/Makefile @@ -46,7 +46,7 @@ STACKSIZE = 2048 # NuttX OS Test ASRCS = -CSRCS = main.c dev_null.c +CSRCS = ostest_main.c dev_null.c ifeq ($(CONFIG_ARCH_FPU),y) CSRCS += fpu.c diff --git a/apps/examples/ostest/barrier.c b/apps/examples/ostest/barrier.c index da1301dc3c..e66496f7b8 100644 --- a/apps/examples/ostest/barrier.c +++ b/apps/examples/ostest/barrier.c @@ -2,7 +2,7 @@ * examples/ostest/barrier.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/cancel.c b/apps/examples/ostest/cancel.c index bf2d03615f..11981d8194 100644 --- a/apps/examples/ostest/cancel.c +++ b/apps/examples/ostest/cancel.c @@ -2,7 +2,7 @@ * examples/ostest/cancel.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/cond.c b/apps/examples/ostest/cond.c index 11191b7d52..96468c3e4e 100644 --- a/apps/examples/ostest/cond.c +++ b/apps/examples/ostest/cond.c @@ -2,7 +2,7 @@ * cond.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/dev_null.c b/apps/examples/ostest/dev_null.c index e8fc6cf3f9..34508d05e6 100644 --- a/apps/examples/ostest/dev_null.c +++ b/apps/examples/ostest/dev_null.c @@ -2,7 +2,7 @@ * examples/ostest/dev_null.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/mutex.c b/apps/examples/ostest/mutex.c index 752f833f25..0b7f70daa1 100644 --- a/apps/examples/ostest/mutex.c +++ b/apps/examples/ostest/mutex.c @@ -2,7 +2,7 @@ * mutex.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/main.c b/apps/examples/ostest/ostest_main.c similarity index 94% rename from apps/examples/ostest/main.c rename to apps/examples/ostest/ostest_main.c index 7d63c0ff48..46726d515d 100644 --- a/apps/examples/ostest/main.c +++ b/apps/examples/ostest/ostest_main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/examples/ostest/main.c + * apps/examples/ostest/ostest_main.c * * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -409,7 +409,7 @@ static int user_main(int argc, char *argv[]) check_test_memory_usage(); #endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ - /* Compare memory usage at time user_start started until + /* Compare memory usage at time ostest_main started until * user_main exits. These should not be identical, but should * be similar enough that we can detect any serious OS memory * leaks. @@ -458,18 +458,10 @@ static void stdio_test(void) ****************************************************************************/ /**************************************************************************** - * user_start/ostest_main + * ostest_main ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_OSTEST_BUILTIN -# define MAIN_NAME ostest_main -# define MAIN_STRING "ostest_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - -int MAIN_NAME(int argc, char *argv[]) +int ostest_main(int argc, char *argv[]) { int result; @@ -492,19 +484,19 @@ int MAIN_NAME(int argc, char *argv[]) /* Set up some environment variables */ #ifndef CONFIG_DISABLE_ENVIRON - printf(MAIN_STRING "putenv(%s)\n", g_putenv_value); + printf("ostest_main: putenv(%s)\n", g_putenv_value); putenv(g_putenv_value); /* Varaible1=BadValue3 */ - printf(MAIN_STRING "setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); + printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ - printf(MAIN_STRING "setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); + printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ - printf(MAIN_STRING "setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); + printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ - printf(MAIN_STRING "setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); + printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ - printf(MAIN_STRING "setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); + printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */ show_environment(true, true, true); #endif @@ -518,13 +510,13 @@ int MAIN_NAME(int argc, char *argv[]) #endif if (result == ERROR) { - printf(MAIN_STRING "ERROR Failed to start user_main\n"); + printf("ostest_main: ERROR Failed to start user_main\n"); } else { - printf(MAIN_STRING "Started user_main at PID=%d\n", result); + printf("ostest_main: Started user_main at PID=%d\n", result); } - printf(MAIN_STRING "Exitting\n"); + printf("ostest_main: Exitting\n"); return 0; } diff --git a/apps/examples/ostest/posixtimer.c b/apps/examples/ostest/posixtimer.c index 3560c712be..ebb1ab79e1 100644 --- a/apps/examples/ostest/posixtimer.c +++ b/apps/examples/ostest/posixtimer.c @@ -2,7 +2,7 @@ * examples/ostest/posixtimer.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/prioinherit.c b/apps/examples/ostest/prioinherit.c index 993c9e14a2..cd04df7e60 100644 --- a/apps/examples/ostest/prioinherit.c +++ b/apps/examples/ostest/prioinherit.c @@ -2,7 +2,7 @@ * examples/ostest/prioinherit.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,12 +58,30 @@ #ifndef CONFIG_SEM_PREALLOCHOLDERS # define CONFIG_SEM_PREALLOCHOLDERS 0 #endif -#define NLOWPRI_THREADS (CONFIG_SEM_PREALLOCHOLDERS+1) + +/* If resources were configured for lots of holders, then run 3 low priority + * threads. Otherwise, just one. + */ + +#if CONFIG_SEM_PREALLOCHOLDERS > 3 +# define NLOWPRI_THREADS 3 +#else +# define NLOWPRI_THREADS 1 +#endif #ifndef CONFIG_SEM_NNESTPRIO # define CONFIG_SEM_NNESTPRIO 0 #endif -#define NHIGHPRI_THREADS (CONFIG_SEM_NNESTPRIO+1) + +/* Where resources configured for lots of waiters? If so then run 3 high + * priority threads. Otherwise, just one. + */ + +#if CONFIG_SEM_NNESTPRIO > 3 +# define NHIGHPRI_THREADS 3 +#else +# define NHIGHPRI_THREADS 1 +#endif /**************************************************************************** * Private Data diff --git a/apps/examples/ostest/rmutex.c b/apps/examples/ostest/rmutex.c index 44eb4bb3b5..ffd99c2dfc 100644 --- a/apps/examples/ostest/rmutex.c +++ b/apps/examples/ostest/rmutex.c @@ -2,7 +2,7 @@ * rmutex.c * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/roundrobin.c b/apps/examples/ostest/roundrobin.c index 061d51f3da..5167a857ed 100644 --- a/apps/examples/ostest/roundrobin.c +++ b/apps/examples/ostest/roundrobin.c @@ -2,7 +2,7 @@ * examples/ostest/roundrobin.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/sem.c b/apps/examples/ostest/sem.c index 850cf8040b..48be57a855 100644 --- a/apps/examples/ostest/sem.c +++ b/apps/examples/ostest/sem.c @@ -2,7 +2,7 @@ * sem.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/sighand.c b/apps/examples/ostest/sighand.c index 6815316395..eabfe56464 100644 --- a/apps/examples/ostest/sighand.c +++ b/apps/examples/ostest/sighand.c @@ -2,7 +2,7 @@ * apps/examples/ostest/sighand.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/timedmqueue.c b/apps/examples/ostest/timedmqueue.c index 807d8537bf..6c3269e844 100644 --- a/apps/examples/ostest/timedmqueue.c +++ b/apps/examples/ostest/timedmqueue.c @@ -2,7 +2,7 @@ * apps/examples/ostest/mqueue.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/ostest/timedwait.c b/apps/examples/ostest/timedwait.c index fc381ddda4..7cf875fb67 100644 --- a/apps/examples/ostest/timedwait.c +++ b/apps/examples/ostest/timedwait.c @@ -2,7 +2,7 @@ * examples/ostest/timedwait.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/pipe/Makefile b/apps/examples/pipe/Makefile index 3bcc9b5f78..956c911b34 100644 --- a/apps/examples/pipe/Makefile +++ b/apps/examples/pipe/Makefile @@ -2,7 +2,7 @@ # apps/examples/pipe/Makefile # # Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/pipe/interlock_test.c b/apps/examples/pipe/interlock_test.c index e049a65f60..20d4113eb5 100644 --- a/apps/examples/pipe/interlock_test.c +++ b/apps/examples/pipe/interlock_test.c @@ -2,7 +2,7 @@ * examples/pipe/interlock_test.c * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/pipe/pipe.h b/apps/examples/pipe/pipe.h index 2c18fd868b..38143e4920 100644 --- a/apps/examples/pipe/pipe.h +++ b/apps/examples/pipe/pipe.h @@ -2,7 +2,7 @@ * examples/pipe/pipe.h * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/pipe/pipe_main.c b/apps/examples/pipe/pipe_main.c index 1f0f73032a..63a4f283fb 100644 --- a/apps/examples/pipe/pipe_main.c +++ b/apps/examples/pipe/pipe_main.c @@ -2,7 +2,7 @@ * examples/pipe/pipe_main.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,21 +69,21 @@ ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: pipe_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int pipe_main(int argc, char *argv[]) { int filedes[2]; int ret; /* Test FIFO logic */ - printf("\nuser_start: Performing FIFO test\n"); + printf("\npipe_main: Performing FIFO test\n"); ret = mkfifo(FIFO_PATH1, 0666); if (ret < 0) { - fprintf(stderr, "user_start: mkfifo failed with errno=%d\n", errno); + fprintf(stderr, "pipe_main: mkfifo failed with errno=%d\n", errno); return 1; } @@ -96,7 +96,7 @@ int user_start(int argc, char *argv[]) filedes[1] = open(FIFO_PATH1, O_WRONLY); if (filedes[1] < 0) { - fprintf(stderr, "user_start: Failed to open FIFO %s for writing, errno=%d\n", + fprintf(stderr, "pipe_main: Failed to open FIFO %s for writing, errno=%d\n", FIFO_PATH1, errno); return 2; } @@ -104,11 +104,11 @@ int user_start(int argc, char *argv[]) filedes[0] = open(FIFO_PATH1, O_RDONLY); if (filedes[0] < 0) { - fprintf(stderr, "user_start: Failed to open FIFO %s for reading, errno=%d\n", + fprintf(stderr, "pipe_main: Failed to open FIFO %s for reading, errno=%d\n", FIFO_PATH1, errno); if (close(filedes[1]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } return 3; } @@ -118,28 +118,28 @@ int user_start(int argc, char *argv[]) ret = transfer_test(filedes[0], filedes[1]); if (close(filedes[0]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } if (close(filedes[1]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } /* unlink(FIFO_PATH1); fails */ if (ret != 0) { - fprintf(stderr, "user_start: FIFO test FAILED (%d)\n", ret); + fprintf(stderr, "pipe_main: FIFO test FAILED (%d)\n", ret); return 4; } - printf("user_start: FIFO test PASSED\n"); + printf("pipe_main: FIFO test PASSED\n"); /* Test PIPE logic */ - printf("\nuser_start: Performing pipe test\n"); + printf("\npipe_main: Performing pipe test\n"); ret = pipe(filedes); if (ret < 0) { - fprintf(stderr, "user_start: pipe failed with errno=%d\n", errno); + fprintf(stderr, "pipe_main: pipe failed with errno=%d\n", errno); return 5; } @@ -148,41 +148,41 @@ int user_start(int argc, char *argv[]) ret = transfer_test(filedes[0], filedes[1]); if (close(filedes[0]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } if (close(filedes[1]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } if (ret != 0) { - fprintf(stderr, "user_start: PIPE test FAILED (%d)\n", ret); + fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret); return 6; } - printf("user_start: PIPE test PASSED\n"); + printf("pipe_main: PIPE test PASSED\n"); /* Perform the FIFO interlock test */ - printf("\nuser_start: Performing pipe interlock test\n"); + printf("\npipe_main: Performing pipe interlock test\n"); ret = interlock_test(); if (ret != 0) { - fprintf(stderr, "user_start: FIFO interlock test FAILED (%d)\n", ret); + fprintf(stderr, "pipe_main: FIFO interlock test FAILED (%d)\n", ret); return 7; } - printf("user_start: PIPE interlock test PASSED\n"); + printf("pipe_main: PIPE interlock test PASSED\n"); /* Perform the pipe redirection test */ - printf("\nuser_start: Performing redirection test\n"); + printf("\npipe_main: Performing redirection test\n"); ret = redirection_test(); if (ret != 0) { - fprintf(stderr, "user_start: FIFO redirection test FAILED (%d)\n", ret); + fprintf(stderr, "pipe_main: FIFO redirection test FAILED (%d)\n", ret); return 7; } - printf("user_start: PIPE redirection test PASSED\n"); + printf("pipe_main: PIPE redirection test PASSED\n"); fflush(stdout); return 0; diff --git a/apps/examples/pipe/redirect_test.c b/apps/examples/pipe/redirect_test.c index 45e86c3560..26fe9bcaa2 100644 --- a/apps/examples/pipe/redirect_test.c +++ b/apps/examples/pipe/redirect_test.c @@ -2,7 +2,7 @@ * examples/pipe/redirect_test.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -301,16 +301,16 @@ int redirection_test(void) if (close(filedes[0]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } if (close(filedes[1]) != 0) { - fprintf(stderr, "user_start: close failed: %d\n", errno); + fprintf(stderr, "pipe_main: close failed: %d\n", errno); } if (ret != 0) { - fprintf(stderr, "user_start: PIPE test FAILED (%d)\n", ret); + fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret); return 6; } diff --git a/apps/examples/pipe/transfer_test.c b/apps/examples/pipe/transfer_test.c index cb8cad04a4..f7c612881a 100644 --- a/apps/examples/pipe/transfer_test.c +++ b/apps/examples/pipe/transfer_test.c @@ -2,7 +2,7 @@ * examples/pipe/transfer_test.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/poll/Makefile b/apps/examples/poll/Makefile index 1c85d6f36d..aef61d199c 100644 --- a/apps/examples/poll/Makefile +++ b/apps/examples/poll/Makefile @@ -2,7 +2,7 @@ # apps/examples/poll/Makefile # # Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/poll/Makefile.host b/apps/examples/poll/Makefile.host index 9d9daee27b..1e6a72089e 100644 --- a/apps/examples/poll/Makefile.host +++ b/apps/examples/poll/Makefile.host @@ -2,7 +2,7 @@ # apps/examples/poll/Makefile.host # # Copyright (C) 2008, 2009, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/poll/poll_internal.h b/apps/examples/poll/poll_internal.h index cbf42ac566..b2400932ed 100644 --- a/apps/examples/poll/poll_internal.h +++ b/apps/examples/poll/poll_internal.h @@ -2,7 +2,7 @@ * examples/poll/poll_internal.h * * Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/poll/poll_listener.c b/apps/examples/poll/poll_listener.c index 816647e340..fe1c95089b 100644 --- a/apps/examples/poll/poll_listener.c +++ b/apps/examples/poll/poll_listener.c @@ -2,7 +2,7 @@ * examples/poll/poll_listener.c * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/poll/poll_main.c b/apps/examples/poll/poll_main.c index 3db0150e77..0c475fa7aa 100644 --- a/apps/examples/poll/poll_main.c +++ b/apps/examples/poll/poll_main.c @@ -2,7 +2,7 @@ * examples/poll/poll_main.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,10 +74,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: poll_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int poll_main(int argc, char *argv[]) { char buffer[64]; ssize_t nbytes; @@ -94,20 +94,20 @@ int user_start(int argc, char *argv[]) /* Open FIFOs */ - message("\nuser_start: Creating FIFO %s\n", FIFO_PATH1); + message("\npoll_main: Creating FIFO %s\n", FIFO_PATH1); ret = mkfifo(FIFO_PATH1, 0666); if (ret < 0) { - message("user_start: mkfifo failed: %d\n", errno); + message("poll_main: mkfifo failed: %d\n", errno); exitcode = 1; goto errout; } - message("\nuser_start: Creating FIFO %s\n", FIFO_PATH2); + message("\npoll_main: Creating FIFO %s\n", FIFO_PATH2); ret = mkfifo(FIFO_PATH2, 0666); if (ret < 0) { - message("user_start: mkfifo failed: %d\n", errno); + message("poll_main: mkfifo failed: %d\n", errno); exitcode = 2; goto errout; } @@ -117,7 +117,7 @@ int user_start(int argc, char *argv[]) fd1 = open(FIFO_PATH1, O_WRONLY); if (fd1 < 0) { - message("user_start: Failed to open FIFO %s for writing, errno=%d\n", + message("poll_main: Failed to open FIFO %s for writing, errno=%d\n", FIFO_PATH1, errno); exitcode = 3; goto errout; @@ -126,7 +126,7 @@ int user_start(int argc, char *argv[]) fd2 = open(FIFO_PATH2, O_WRONLY); if (fd2 < 0) { - message("user_start: Failed to open FIFO %s for writing, errno=%d\n", + message("poll_main: Failed to open FIFO %s for writing, errno=%d\n", FIFO_PATH2, errno); exitcode = 4; goto errout; @@ -134,39 +134,39 @@ int user_start(int argc, char *argv[]) /* Start the listeners */ - message("user_start: Starting poll_listener thread\n"); + message("poll_main: Starting poll_listener thread\n"); ret = pthread_create(&tid1, NULL, poll_listener, NULL); if (ret != 0) { - message("user_start: Failed to create poll_listener thread: %d\n", ret); + message("poll_main: Failed to create poll_listener thread: %d\n", ret); exitcode = 5; goto errout; } - message("user_start: Starting select_listener thread\n"); + message("poll_main: Starting select_listener thread\n"); ret = pthread_create(&tid2, NULL, select_listener, NULL); if (ret != 0) { - message("user_start: Failed to create select_listener thread: %d\n", ret); + message("poll_main: Failed to create select_listener thread: %d\n", ret); exitcode = 6; goto errout; } #ifdef HAVE_NETPOLL #ifdef CONFIG_NET_TCPBACKLOG - message("user_start: Starting net_listener thread\n"); + message("poll_main: Starting net_listener thread\n"); ret = pthread_create(&tid3, NULL, net_listener, NULL); #else - message("user_start: Starting net_reader thread\n"); + message("poll_main: Starting net_reader thread\n"); ret = pthread_create(&tid3, NULL, net_reader, NULL); #endif if (ret != 0) { - message("user_start: Failed to create net_listener thread: %d\n", ret); + message("poll_main: Failed to create net_listener thread: %d\n", ret); } #endif @@ -182,7 +182,7 @@ int user_start(int argc, char *argv[]) nbytes = write(fd1, buffer, strlen(buffer)); if (nbytes < 0) { - message("user_start: Write to fd1 failed: %d\n", errno); + message("poll_main: Write to fd1 failed: %d\n", errno); exitcode = 7; goto errout; } @@ -190,12 +190,12 @@ int user_start(int argc, char *argv[]) nbytes = write(fd2, buffer, strlen(buffer)); if (nbytes < 0) { - message("user_start: Write fd2 failed: %d\n", errno); + message("poll_main: Write fd2 failed: %d\n", errno); exitcode = 8; goto errout; } - message("\nuser_start: Sent '%s' (%d bytes)\n", buffer, nbytes); + message("\npoll_main: Sent '%s' (%d bytes)\n", buffer, nbytes); msgflush(); /* Wait awhile. This delay should be long enough that the diff --git a/apps/examples/poll/select_listener.c b/apps/examples/poll/select_listener.c index 80039ada34..5cb7e78056 100644 --- a/apps/examples/poll/select_listener.c +++ b/apps/examples/poll/select_listener.c @@ -2,7 +2,7 @@ * examples/poll/select_listener.c * * Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/pwm/pwm_main.c b/apps/examples/pwm/pwm_main.c index 64c5dfb2c0..775bdba6b1 100644 --- a/apps/examples/pwm/pwm_main.c +++ b/apps/examples/pwm/pwm_main.c @@ -269,7 +269,7 @@ static void parse_args(FAR struct pwm_state_s *pwm, int argc, FAR char **argv) ****************************************************************************/ /**************************************************************************** - * Name: user_start/pwm_main + * Name: pwm_main ****************************************************************************/ int pwm_main(int argc, char *argv[]) diff --git a/apps/examples/px4_deamon_app/Makefile b/apps/examples/px4_deamon_app/Makefile new file mode 100644 index 0000000000..e4c169872b --- /dev/null +++ b/apps/examples/px4_deamon_app/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Basic example application +# + +APPNAME = px4_deamon_app +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +include $(APPDIR)/mk/app.mk diff --git a/apps/examples/px4_deamon_app/px4_deamon_app.c b/apps/examples/px4_deamon_app/px4_deamon_app.c new file mode 100644 index 0000000000..0531637897 --- /dev/null +++ b/apps/examples/px4_deamon_app/px4_deamon_app.c @@ -0,0 +1,129 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Example User + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file px4_deamon_app.c + * Deamon application example for PX4 autopilot + */ + +#include +#include +#include + +static bool thread_should_exit = false; /**< Deamon exit flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int deamon_task; /**< Handle of deamon task / thread */ + +/** + * Deamon management function. + */ +__EXPORT int px4_deamon_app_main(int argc, char *argv[]); + +/** + * Mainloop of deamon. + */ +int px4_deamon_thread_main(int argc, char *argv[]); + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: deamon {start|stop|status} [-p ]\n\n"); + exit(1); +} + +/** + * The deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ +int px4_deamon_app_main(int argc, char *argv[]) +{ + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1], "start")) { + + if (thread_running) { + printf("deamon already running\n"); + /* this is not an error */ + exit(0); + } + + thread_should_exit = false; + deamon_task = task_create("deamon", SCHED_PRIORITY_DEFAULT, 4096, px4_deamon_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tdeamon app is running\n"); + } else { + printf("\tdeamon app not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} + +int px4_deamon_thread_main(int argc, char *argv[]) { + + printf("[deamon] starting\n"); + + while (!thread_should_exit) { + printf("Hello Deamon!\n"); + sleep(10); + } + + printf("[deamon] exiting.\n"); + + return 0; +} diff --git a/apps/examples/px4_simple_app/px4_simple_app.c b/apps/examples/px4_simple_app/px4_simple_app.c index fd34a5dacb..7f655964d9 100644 --- a/apps/examples/px4_simple_app/px4_simple_app.c +++ b/apps/examples/px4_simple_app/px4_simple_app.c @@ -59,7 +59,7 @@ int px4_simple_app_main(int argc, char *argv[]) /* advertise attitude topic */ struct vehicle_attitude_s att; memset(&att, 0, sizeof(att)); - int att_pub_fd = orb_advertise(ORB_ID(vehicle_attitude), &att); + orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude), &att); /* one could wait for multiple topics with this technique, just using one here */ struct pollfd fds[] = { @@ -103,7 +103,7 @@ int px4_simple_app_main(int argc, char *argv[]) att.roll = raw.accelerometer_m_s2[0]; att.pitch = raw.accelerometer_m_s2[1]; att.yaw = raw.accelerometer_m_s2[2]; - orb_publish(ORB_ID(vehicle_attitude), att_pub_fd, &att); + orb_publish(ORB_ID(vehicle_attitude), att_pub, &att); } /* there could be more file descriptors here, in the form like: * if (fds[1..n].revents & POLLIN) {} diff --git a/apps/examples/qencoder/qe_main.c b/apps/examples/qencoder/qe_main.c index c58a2b0ada..8c185ea1b7 100644 --- a/apps/examples/qencoder/qe_main.c +++ b/apps/examples/qencoder/qe_main.c @@ -59,14 +59,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifdef CONFIG_NSH_BUILTIN_APPS -# define MAIN_NAME qe_main -# define MAIN_STRING "qe_main: " -#else -# define MAIN_NAME user_start -# define MAIN_STRING "user_start: " -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -245,10 +237,10 @@ static void parse_args(int argc, FAR char **argv) ****************************************************************************/ /**************************************************************************** - * Name: user_start/qe_main + * Name: qe_main ****************************************************************************/ -int MAIN_NAME(int argc, char *argv[]) +int qe_main(int argc, char *argv[]) { int32_t position; int fd; @@ -266,11 +258,11 @@ int MAIN_NAME(int argc, char *argv[]) * this test. */ - message(MAIN_STRING "Initializing external encoder(s)\n"); + message("qe_main: Initializing external encoder(s)\n"); ret = qe_devinit(); if (ret != OK) { - message(MAIN_STRING "qe_devinit failed: %d\n", ret); + message("qe_main: qe_devinit failed: %d\n", ret); exitval = EXIT_FAILURE; goto errout; } @@ -289,13 +281,13 @@ int MAIN_NAME(int argc, char *argv[]) /* Open the encoder device for reading */ - message(MAIN_STRING "Hardware initialized. Opening the encoder device: %s\n", + message("qe_main: Hardware initialized. Opening the encoder device: %s\n", g_qeexample.devpath); fd = open(g_qeexample.devpath, O_RDONLY); if (fd < 0) { - message(MAIN_STRING "open %s failed: %d\n", g_qeexample.devpath, errno); + message("qe_main: open %s failed: %d\n", g_qeexample.devpath, errno); exitval = EXIT_FAILURE; goto errout_with_dev; } @@ -304,11 +296,11 @@ int MAIN_NAME(int argc, char *argv[]) if (g_qeexample.reset) { - message(MAIN_STRING "Resetting the count...\n"); + message("qe_main: Resetting the count...\n"); ret = ioctl(fd, QEIOC_RESET, 0); if (ret < 0) { - message(MAIN_STRING "ioctl(QEIOC_RESET) failed: %d\n", errno); + message("qe_main: ioctl(QEIOC_RESET) failed: %d\n", errno); exitval = EXIT_FAILURE; goto errout_with_dev; } @@ -319,10 +311,10 @@ int MAIN_NAME(int argc, char *argv[]) */ #if defined(CONFIG_NSH_BUILTIN_APPS) - message(MAIN_STRING "Number of samples: %d\n", g_qeexample.nloops); + message("qe_main: Number of samples: %d\n", g_qeexample.nloops); for (nloops = 0; nloops < g_qeexample.nloops; nloops++) #elif defined(CONFIG_EXAMPLES_QENCODER_NSAMPLES) - message(MAIN_STRING "Number of samples: %d\n", CONFIG_EXAMPLES_QENCODER_NSAMPLES); + message("qe_main: Number of samples: %d\n", CONFIG_EXAMPLES_QENCODER_NSAMPLES); for (nloops = 0; nloops < CONFIG_EXAMPLES_QENCODER_NSAMPLES; nloops++) #else for (;;) @@ -339,7 +331,7 @@ int MAIN_NAME(int argc, char *argv[]) ret = ioctl(fd, QEIOC_POSITION, (unsigned long)((uintptr_t)&position)); if (ret < 0) { - message(MAIN_STRING "ioctl(QEIOC_POSITION) failed: %d\n", errno); + message("qe_main: ioctl(QEIOC_POSITION) failed: %d\n", errno); exitval = EXIT_FAILURE; goto errout_with_dev; } @@ -348,7 +340,7 @@ int MAIN_NAME(int argc, char *argv[]) else { - message(MAIN_STRING "%3d. %d\n", nloops+1, position); + message("qe_main: %3d. %d\n", nloops+1, position); } /* Delay a little bit */ diff --git a/apps/examples/romfs/Makefile b/apps/examples/romfs/Makefile index 1db45765a7..ba930b77d0 100644 --- a/apps/examples/romfs/Makefile +++ b/apps/examples/romfs/Makefile @@ -2,7 +2,7 @@ # apps/examples/romfs/Makefile # # Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/examples/romfs/romfs_main.c b/apps/examples/romfs/romfs_main.c index 32b3d2654b..3437cb8ace 100644 --- a/apps/examples/romfs/romfs_main.c +++ b/apps/examples/romfs/romfs_main.c @@ -2,7 +2,7 @@ * examples/romfs/romfs_main.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -452,10 +452,10 @@ static void checkdirectories(struct node_s *entry) ****************************************************************************/ /**************************************************************************** - * Name: user_start + * Name: romfs_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int romfs_main(int argc, char *argv[]) { int ret; diff --git a/apps/examples/serloop/Makefile b/apps/examples/serloop/Makefile index 67c805d46c..e1c415cdd8 100644 --- a/apps/examples/serloop/Makefile +++ b/apps/examples/serloop/Makefile @@ -2,7 +2,7 @@ # apps/examples/serloop/Makefile # # Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -40,7 +40,7 @@ include $(APPDIR)/Make.defs # Mindlessly simple console loopack test ASRCS = -CSRCS = main.c +CSRCS = serloop_main.c AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/apps/examples/serloop/main.c b/apps/examples/serloop/serloop_main.c similarity index 95% rename from apps/examples/serloop/main.c rename to apps/examples/serloop/serloop_main.c index 3c635fe886..af171fef3f 100644 --- a/apps/examples/serloop/main.c +++ b/apps/examples/serloop/serloop_main.c @@ -1,8 +1,8 @@ /**************************************************************************** - * examples/serloop/main.c + * examples/serloop/serloop_main.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -56,10 +56,10 @@ ****************************************************************************/ /**************************************************************************** - * user_start + * serloop_main ****************************************************************************/ -int user_start(int argc, char *argv[]) +int serloop_main(int argc, char *argv[]) { #ifdef CONFIG_EXAMPLES_SERLOOP_BUFIO int ch; diff --git a/apps/examples/watchdog/watchdog_main.c b/apps/examples/watchdog/watchdog_main.c index c1341e0fb9..53099d21a5 100644 --- a/apps/examples/watchdog/watchdog_main.c +++ b/apps/examples/watchdog/watchdog_main.c @@ -217,7 +217,7 @@ static void parse_args(FAR struct wdog_example_s *wdog, int argc, FAR char **arg ****************************************************************************/ /**************************************************************************** - * Name: user_start/wdog_main + * Name: wdog_main ****************************************************************************/ int wdog_main(int argc, char *argv[]) diff --git a/apps/fixedwing_control/fixedwing_control.c b/apps/fixedwing_control/fixedwing_control.c index bad62edcfc..67e5d1b289 100644 --- a/apps/fixedwing_control/fixedwing_control.c +++ b/apps/fixedwing_control/fixedwing_control.c @@ -52,21 +52,90 @@ #include #include #include -#include "../mix_and_link/mix_and_link.h" //TODO: add to Makefile #include #include #include #include #include #include -#include +#include +#include +#include +#include -#ifndef F_M_PI -#define F_M_PI ((float)M_PI) -#endif +static bool thread_should_exit = false; /**< Deamon exit flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int deamon_task; /**< Handle of deamon task / thread */ +/** + * Deamon management function. + */ __EXPORT int fixedwing_control_main(int argc, char *argv[]); +/** + * Mainloop of deamon. + */ +int fixedwing_control_thread_main(int argc, char *argv[]); + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: fixedwing_control {start|stop|status}\n\n"); + exit(1); +} + +/** + * The deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ +int fixedwing_control_main(int argc, char *argv[]) +{ + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1], "start")) { + + if (thread_running) { + printf("fixedwing_control already running\n"); + /* this is not an error */ + exit(0); + } + + thread_should_exit = false; + deamon_task = task_create("fixedwing_control", SCHED_PRIORITY_MAX - 20, 4096, fixedwing_control_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tfixedwing_control is running\n"); + } else { + printf("\tfixedwing_control not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} + #define PID_DT 0.01f #define PID_SCALER 0.1f #define PID_DERIVMODE_CALC 0 @@ -135,8 +204,8 @@ typedef struct { /* Next waypoint*/ - float wp_x; - float wp_y; + double wp_x; + double wp_y; float wp_z; /* Setpoints */ @@ -251,7 +320,7 @@ static float pid(float error, float error_deriv, uint16_t dt, float scale, float * discrete low pass filter, cuts out the * high frequency noise that can drive the controller crazy */ - float RC = 1.0 / (2.0f * M_PI * fCut); + float RC = 1.0f / (2.0f * M_PI_F * fCut); derivative = lderiv + (delta_time / (RC + delta_time)) * (derivative - lderiv); @@ -291,6 +360,18 @@ static float pid(float error, float error_deriv, uint16_t dt, float scale, float return output; } +PARAM_DEFINE_FLOAT(FW_ATT_P, 2.0f); +PARAM_DEFINE_FLOAT(FW_ATT_I, 0.0f); +PARAM_DEFINE_FLOAT(FW_ATT_D, 0.0f); +PARAM_DEFINE_FLOAT(FW_ATT_AWU, 5.0f); +PARAM_DEFINE_FLOAT(FW_ATT_LIM, 10.0f); + +PARAM_DEFINE_FLOAT(FW_POS_P, 2.0f); +PARAM_DEFINE_FLOAT(FW_POS_I, 0.0f); +PARAM_DEFINE_FLOAT(FW_POS_D, 0.0f); +PARAM_DEFINE_FLOAT(FW_POS_AWU, 5.0f); +PARAM_DEFINE_FLOAT(FW_POS_LIM, 10.0f); + /** * Load parameters from global storage. * @@ -299,22 +380,47 @@ static float pid(float error, float error_deriv, uint16_t dt, float scale, float * Fetches the current parameters from the global parameter storage and writes them * to the plane_data structure */ - -static void get_parameters(plane_data_t * plane_data) +static void get_parameters(plane_data_t * pdata) { - plane_data->Kp_att = global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P]; - plane_data->Ki_att = global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I]; - plane_data->Kd_att = global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D]; - plane_data->Kp_pos = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_P]; - plane_data->Ki_pos = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_I]; - plane_data->Kd_pos = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_D]; - plane_data->intmax_att = global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]; - plane_data->intmax_pos = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_AWU]; - plane_data->airspeed = global_data_parameter_storage->pm.param_values[PARAM_AIRSPEED]; - plane_data->wp_x = global_data_parameter_storage->pm.param_values[PARAM_WPLON]; - plane_data->wp_y = global_data_parameter_storage->pm.param_values[PARAM_WPLAT]; - plane_data->wp_z = global_data_parameter_storage->pm.param_values[PARAM_WPALT]; - plane_data->mode = global_data_parameter_storage->pm.param_values[PARAM_FLIGHTMODE]; + static bool initialized = false; + static param_t att_p; + static param_t att_i; + static param_t att_d; + static param_t att_awu; + static param_t att_lim; + + static param_t pos_p; + static param_t pos_i; + static param_t pos_d; + static param_t pos_awu; + static param_t pos_lim; + + if (!initialized) { + att_p = param_find("FW_ATT_P"); + att_i = param_find("FW_ATT_I"); + att_d = param_find("FW_ATT_D"); + att_awu = param_find("FW_ATT_AWU"); + att_lim = param_find("FW_ATT_LIM"); + + pos_p = param_find("FW_POS_P"); + pos_i = param_find("FW_POS_I"); + pos_d = param_find("FW_POS_D"); + pos_awu = param_find("FW_POS_AWU"); + pos_lim = param_find("FW_POS_LIM"); + + initialized = true; + } + + param_get(att_p, &(pdata->Kp_att)); + param_get(att_i, &(pdata->Ki_att)); + param_get(att_d, &(pdata->Kd_att)); + param_get(pos_p, &(pdata->Kp_pos)); + param_get(pos_i, &(pdata->Ki_pos)); + param_get(pos_d, &(pdata->Kd_pos)); + param_get(att_awu, &(pdata->intmax_att)); + param_get(pos_awu, &(pdata->intmax_pos)); + pdata->airspeed = 10; + pdata->mode = 1; } /** @@ -395,10 +501,10 @@ static void calc_rotation_matrix(float roll, float pitch, float yaw, float x, fl */ static float calc_bearing() { - float bearing = F_M_PI/2.0f + (float)atan2(-(plane_data.wp_y - plane_data.lat), (plane_data.wp_x - plane_data.lon)); + float bearing = M_PI_F/2.0f + (float)atan2(-(plane_data.wp_y - plane_data.lat), (plane_data.wp_x - plane_data.lon)); if (bearing < 0.0f) { - bearing += 2*F_M_PI; + bearing += 2*M_PI_F; } return bearing; @@ -537,18 +643,13 @@ static float calc_roll_setpoint() { float setpoint = 0; - if (plane_data.mode == TAKEOFF) { - setpoint = 0; + setpoint = calc_bearing() - plane_data.yaw; - } else { - setpoint = calc_bearing() - plane_data.yaw; + if (setpoint < (-35.0f/180.0f)*M_PI_F) + return (-35.0f/180.0f)*M_PI_F; - if (setpoint < (-35.0f/180.0f)*F_M_PI) - return (-35.0f/180.0f)*F_M_PI; - - if (setpoint > (35/180.0f)*F_M_PI) - return (-35.0f/180.0f)*F_M_PI; - } + if (setpoint > (35/180.0f)*M_PI_F) + return (-35.0f/180.0f)*M_PI_F; return setpoint; } @@ -567,77 +668,52 @@ static float calc_pitch_setpoint() { float setpoint = 0.0f; - if (plane_data.mode == TAKEOFF) { - setpoint = ((35/180.0f)*F_M_PI); + // if (plane_data.mode == TAKEOFF) { + // setpoint = ((35/180.0f)*M_PI_F); - } else { + // } else { setpoint = atanf((plane_data.wp_z - plane_data.alt) / calc_wp_distance()); - if (setpoint < (-35.0f/180.0f)*F_M_PI) - return (-35.0f/180.0f)*F_M_PI; + if (setpoint < (-35.0f/180.0f)*M_PI_F) + return (-35.0f/180.0f)*M_PI_F; - if (setpoint > (35/180.0f)*F_M_PI) - return (-35.0f/180.0f)*F_M_PI; - } + if (setpoint > (35/180.0f)*M_PI_F) + return (-35.0f/180.0f)*M_PI_F; + // } return setpoint; } /** - * calc_throttle_setpoint * * Calculates the throttle setpoint for different flight modes * * @return throttle output setpoint * */ - static float calc_throttle_setpoint() { float setpoint = 0; - // if TAKEOFF full throttle - if (plane_data.mode == TAKEOFF) { - setpoint = 60.0f; - } + // // if TAKEOFF full throttle + // if (plane_data.mode == TAKEOFF) { + // setpoint = 60.0f; + // } - // if CRUISE - parameter value - if (plane_data.mode == CRUISE) { + // // if CRUISE - parameter value + // if (plane_data.mode == CRUISE) { setpoint = plane_data.airspeed; - } + // } - // if LAND no throttle - if (plane_data.mode == LAND) { - setpoint = 0.0f; - } + // // if LAND no throttle + // if (plane_data.mode == LAND) { + // setpoint = 0.0f; + // } return setpoint; } /** - * set_plane_mode - * - * Sets the plane mode - * (TAKEOFF, CRUISE, LOITER or LAND) - * - */ - -static void set_plane_mode() -{ - if (plane_data.alt < 10.0f) { - plane_data.mode = TAKEOFF; - - } else { - plane_data.mode = CRUISE; - // TODO: if reached waypoint and no further waypoint exists, go to LOITER mode - } - - // Debug override - don't need TAKEOFF mode for now - plane_data.mode = CRUISE; -} - -/* - * fixedwing_control_main * * @param argc number of arguments * @param argv argument array @@ -645,8 +721,7 @@ static void set_plane_mode() * @return 0 * */ - -int fixedwing_control_main(int argc, char *argv[]) +int fixedwing_control_thread_main(int argc, char *argv[]) { /* default values for arguments */ char *fixedwing_uart_name = "/dev/ttyS1"; @@ -673,19 +748,35 @@ int fixedwing_control_main(int argc, char *argv[]) /* welcome user */ printf("[fixedwing control] started\n"); - /* Set up to publish fixed wing control messages */ - struct fixedwing_control_s control; - int fixedwing_control_pub = orb_advertise(ORB_ID(fixedwing_control), &control); + /* output structs */ + struct actuator_controls_s actuators; + struct vehicle_attitude_setpoint_s att_sp; + memset(&att_sp, 0, sizeof(att_sp)); + + /* publish actuator controls */ + for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++) + actuators.control[i] = 0.0f; + orb_advert_t actuator_pub = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &actuators); + orb_advert_t att_sp_pub = orb_advertise(ORB_ID(vehicle_attitude_setpoint), &att_sp); /* Subscribe to global position, attitude and rc */ struct vehicle_global_position_s global_pos; int global_pos_sub = orb_subscribe(ORB_ID(vehicle_global_position)); - struct vehicle_attitude_s att; - int attitude_sub = orb_subscribe(ORB_ID(vehicle_attitude)); - struct rc_channels_s rc; - int rc_sub = orb_subscribe(ORB_ID(rc_channels)); struct vehicle_global_position_setpoint_s global_setpoint; int global_setpoint_sub = orb_subscribe(ORB_ID(vehicle_global_position_setpoint)); + /* declare and safely initialize all structs */ + struct vehicle_status_s state; + memset(&state, 0, sizeof(state)); + struct vehicle_attitude_s att; + memset(&att_sp, 0, sizeof(att_sp)); + struct manual_control_setpoint_s manual; + memset(&manual, 0, sizeof(manual)); + + /* subscribe to attitude, motor setpoints and system state */ + int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); + int att_setpoint_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint)); + int state_sub = orb_subscribe(ORB_ID(vehicle_status)); + int manual_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); /* Mainloop setup */ unsigned int loopcounter = 0; @@ -697,44 +788,6 @@ int fixedwing_control_main(int argc, char *argv[]) /* Servo setup */ - int fd; - servo_position_t data[PWM_OUTPUT_MAX_CHANNELS]; - - fd = open("/dev/pwm_servo", O_RDWR); - - if (fd < 0) { - printf("[fixedwing control] Failed opening /dev/pwm_servo\n"); - } - - ioctl(fd, PWM_SERVO_ARM, 0); - - int16_t buffer_rc[3]; - int16_t buffer_servo[3]; - mixer_data_t mixer_buffer; - mixer_buffer.input = buffer_rc; - mixer_buffer.output = buffer_servo; - - mixer_conf_t mixers[3]; - - mixers[0].source = PITCH; - mixers[0].nr_actuators = 2; - mixers[0].dest[0] = AIL_1; - mixers[0].dest[1] = AIL_2; - mixers[0].dual_rate[0] = 1; - mixers[0].dual_rate[1] = 1; - - mixers[1].source = ROLL; - mixers[1].nr_actuators = 2; - mixers[1].dest[0] = AIL_1; - mixers[1].dest[1] = AIL_2; - mixers[1].dual_rate[0] = 1; - mixers[1].dual_rate[1] = -1; - - mixers[2].source = THROTTLE; - mixers[2].nr_actuators = 1; - mixers[2].dest[0] = MOT; - mixers[2].dual_rate[0] = 1; - /* * Main control, navigation and servo routine */ @@ -749,8 +802,15 @@ int fixedwing_control_main(int argc, char *argv[]) // XXX add error checking orb_copy(ORB_ID(vehicle_global_position), global_pos_sub, &global_pos); orb_copy(ORB_ID(vehicle_global_position_setpoint), global_setpoint_sub, &global_setpoint); - orb_copy(ORB_ID(vehicle_attitude), attitude_sub, &att); - orb_copy(ORB_ID(rc_channels), rc_sub, &rc); + + /* get a local copy of system state */ + orb_copy(ORB_ID(vehicle_status), state_sub, &state); + /* get a local copy of manual setpoint */ + orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual); + /* get a local copy of attitude */ + orb_copy(ORB_ID(vehicle_attitude), att_sub, &att); + /* get a local copy of attitude setpoint */ + orb_copy(ORB_ID(vehicle_attitude_setpoint), att_setpoint_sub, &att_sp); /* scaling factors are defined by the data from the APM Planner * TODO: ifdef for other parameters (HIL/Real world switch) @@ -772,21 +832,24 @@ int fixedwing_control_main(int argc, char *argv[]) plane_data.pitchspeed = att.pitchspeed; plane_data.yawspeed = att.yawspeed; + plane_data.wp_x = global_setpoint.lat / (double)1e7; + plane_data.wp_y = global_setpoint.lon / (double)1e7; + plane_data.wp_z = global_setpoint.altitude; + /* parameter values */ - get_parameters(&plane_data); + if (loopcounter % 20 == 0) { + get_parameters(&plane_data); + } /* Attitude control part */ if (verbose && loopcounter % 20 == 0) { /******************************** DEBUG OUTPUT ************************************************************/ - printf("Parameter: %i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i \n", (int)plane_data.Kp_att, (int)plane_data.Ki_att, + printf("Parameter: %i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i\n", (int)plane_data.Kp_att, (int)plane_data.Ki_att, (int)plane_data.Kd_att, (int)plane_data.intmax_att, (int)plane_data.Kp_pos, (int)plane_data.Ki_pos, (int)plane_data.Kd_pos, (int)plane_data.intmax_pos, (int)plane_data.airspeed, - (int)plane_data.wp_x, (int)plane_data.wp_y, (int)plane_data.wp_z, - (int)global_data_parameter_storage->pm.param_values[PARAM_WPLON], - (int)global_data_parameter_storage->pm.param_values[PARAM_WPLAT], - (int)global_data_parameter_storage->pm.param_values[PARAM_WPALT]); + (int)plane_data.wp_x, (int)plane_data.wp_y, (int)plane_data.wp_z); printf("PITCH SETPOINT: %i\n", (int)(100.0f*plane_data.pitch_setpoint)); printf("ROLL SETPOINT: %i\n", (int)(100.0f*plane_data.roll_setpoint)); @@ -797,29 +860,19 @@ int fixedwing_control_main(int argc, char *argv[]) // printf("Current Altitude: %i\n\n", (int)plane_data.alt); printf("\nAttitude values: \n R:%i \n P: %i \n Y: %i \n\n RS: %i \n PS: %i \n YS: %i \n ", - (int)(180.0f * plane_data.roll/F_M_PI), (int)(180.0f * plane_data.pitch/F_M_PI), (int)(180.0f * plane_data.yaw/F_M_PI), - (int)(180.0f * plane_data.rollspeed/F_M_PI), (int)(180.0f * plane_data.pitchspeed/F_M_PI), (int)(180.0f * plane_data.yawspeed)/F_M_PI); + (int)(180.0f * plane_data.roll/M_PI_F), (int)(180.0f * plane_data.pitch/M_PI_F), (int)(180.0f * plane_data.yaw/M_PI_F), + (int)(180.0f * plane_data.rollspeed/M_PI_F), (int)(180.0f * plane_data.pitchspeed/M_PI_F), (int)(180.0f * plane_data.yawspeed)/M_PI_F); // printf("\nBody Rates: \n P: %i \n Q: %i \n R: %i \n", // (int)(10000 * plane_data.p), (int)(10000 * plane_data.q), (int)(10000 * plane_data.r)); - printf("\nCalculated outputs: \n R: %i\n P: %i\n Y: %i\n T: %i \n", - (int)(10000.0f * control_outputs.roll_ailerons), (int)(10000.0f * control_outputs.pitch_elevator), - (int)(10000.0f * control_outputs.yaw_rudder), (int)(10000.0f * control_outputs.throttle)); + printf("\nCalculated outputs: \n R: %8.4f\n P: %8.4f\n Y: %8.4f\n T: %8.4f \n", + att_sp.roll_body, att_sp.pitch_body, + att_sp.yaw_body, att_sp.thrust); /************************************************************************************************************/ } - /* - * Computation section - * - * The function calls to compute the required control values happen - * in this section. - */ - - /* Set plane mode */ - set_plane_mode(); - /* Calculate the P,Q,R body rates of the aircraft */ //calc_body_angular_rates(plane_data.roll, plane_data.pitch, plane_data.yaw, // plane_data.rollspeed, plane_data.pitchspeed, plane_data.yawspeed); @@ -827,123 +880,33 @@ int fixedwing_control_main(int argc, char *argv[]) /* Calculate the body frame angles of the aircraft */ //calc_bodyframe_angles(plane_data.roll,plane_data.pitch,plane_data.yaw); - /* Calculate the output values */ - control_outputs.roll_ailerons = calc_roll_ail(); - control_outputs.pitch_elevator = calc_pitch_elev(); - //control_outputs.yaw_rudder = calc_yaw_rudder(); - control_outputs.throttle = calc_throttle(); + // if (manual.override_mode_switch < XXX) { - if (rc.chan[rc.function[OVERRIDE]].scale < MANUAL) { // if we're flying in automated mode - - /* - * TAKEOFF hack for HIL - */ - if (plane_data.mode == TAKEOFF) { - control.attitude_control_output[ROLL] = 0; - control.attitude_control_output[PITCH] = 5000; - control.attitude_control_output[THROTTLE] = 10000; - //global_data_fixedwing_control->attitude_control_output[YAW] = (int16_t)(control_outputs.yaw_rudder); - } - - if (plane_data.mode == CRUISE) { - control.attitude_control_output[ROLL] = control_outputs.roll_ailerons; - control.attitude_control_output[PITCH] = control_outputs.pitch_elevator; - control.attitude_control_output[THROTTLE] = control_outputs.throttle; - //control->attitude_control_output[YAW] = (int16_t)(control_outputs.yaw_rudder); - } - - control.counter++; - control.timestamp = hrt_absolute_time(); - } /* Navigation part */ - // Get GPS Waypoint + // Get Waypoint - // if(global_data_wait(&global_data_position_setpoint->access_conf) == 0) - // { - // plane_data.wp_x = global_data_position_setpoint->x; - // plane_data.wp_y = global_data_position_setpoint->y; - // plane_data.wp_z = global_data_position_setpoint->z; - // } - // global_data_unlock(&global_data_position_setpoint->access_conf); + // XXX FIXME - if (rc.chan[rc.function[OVERRIDE]].scale < MANUAL) { // AUTO mode - // AUTO/HYBRID switch + //else if (manual.override_mode_switch > MANUAL) { // AUTO mode + + /* calculate setpoint based on current position and waypoint */ + att_sp.roll_body = calc_roll_setpoint(); + att_sp.pitch_body = calc_pitch_setpoint(); + att_sp.thrust = calc_throttle_setpoint(); - if (rc.chan[rc.function[OVERRIDE]].scale < AUTO) { - plane_data.roll_setpoint = calc_roll_setpoint(); - plane_data.pitch_setpoint = calc_pitch_setpoint(); - plane_data.throttle_setpoint = calc_throttle_setpoint(); + /* calculate the control outputs based on roll / pitch / yaw setpoints */ + actuators.control[0] = calc_roll_ail(); + actuators.control[1] = calc_pitch_elev(); + actuators.control[2] = calc_yaw_rudder(att.yaw); + actuators.control[3] = calc_throttle(); - } else { - plane_data.roll_setpoint = rc.chan[rc.function[ROLL]].scale / 200; - plane_data.pitch_setpoint = rc.chan[rc.function[PITCH]].scale / 200; - plane_data.throttle_setpoint = rc.chan[rc.function[THROTTLE]].scale / 200; - } + /* publish attitude setpoint (for MAVLink) */ + orb_publish(ORB_ID(vehicle_attitude_setpoint), att_sp_pub, &att_sp); - //control_outputs.yaw_rudder = calc_yaw_rudder(plane_data.hdg); - - } else { - control.attitude_control_output[ROLL] = rc.chan[rc.function[ROLL]].scale/10000; - control.attitude_control_output[PITCH] = rc.chan[rc.function[PITCH]].scale/10000; - control.attitude_control_output[THROTTLE] = rc.chan[rc.function[THROTTLE]].scale/10000; - // since we don't have a yaw rudder - //control->attitude_control_output[3] = global_data_rc_channels->chan[YAW].scale; - - control.counter++; - control.timestamp = hrt_absolute_time(); - } - - /* publish the control data */ - - orb_publish(ORB_ID(fixedwing_control), fixedwing_control_pub, &control); - - /* Servo part */ - - buffer_rc[ROLL] = (int16_t)(10000*control.attitude_control_output[ROLL]); - buffer_rc[PITCH] = (int16_t)(10000*control.attitude_control_output[PITCH]); - buffer_rc[THROTTLE] = (int16_t)(10000*control.attitude_control_output[THROTTLE]); - - //mix_and_link(mixers, 3, 2, &mixer_buffer); - - // Scaling and saturation of servo outputs happens here - - data[AIL_1] = buffer_servo[AIL_1] / global_data_parameter_storage->pm.param_values[PARAM_SERVO_SCALE] - + global_data_parameter_storage->pm.param_values[PARAM_SERVO1_TRIM]; - - if (data[AIL_1] > SERVO_MAX) - data[AIL_1] = SERVO_MAX; - - if (data[AIL_1] < SERVO_MIN) - data[AIL_1] = SERVO_MIN; - - data[AIL_2] = buffer_servo[AIL_2] / global_data_parameter_storage->pm.param_values[PARAM_SERVO_SCALE] - + global_data_parameter_storage->pm.param_values[PARAM_SERVO2_TRIM]; - - if (data[AIL_2] > SERVO_MAX) - data[AIL_2] = SERVO_MAX; - - if (data[AIL_2] < SERVO_MIN) - data[AIL_2] = SERVO_MIN; - - data[MOT] = buffer_servo[MOT] / global_data_parameter_storage->pm.param_values[PARAM_SERVO_SCALE] - + global_data_parameter_storage->pm.param_values[PARAM_SERVO3_TRIM]; - - if (data[MOT] > SERVO_MAX) - data[MOT] = SERVO_MAX; - - if (data[MOT] < SERVO_MIN) - data[MOT] = SERVO_MIN; - - int result = write(fd, &data, sizeof(data)); - - if (result != sizeof(data)) { - if (failcounter < 10 || failcounter % 20 == 0) { - printf("[fixedwing_control] failed writing servo outputs\n"); - } - failcounter++; - } + /* publish actuator setpoints (for mixer) */ + orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators); loopcounter++; diff --git a/apps/fixedwing_control/fixedwing_control.zip b/apps/fixedwing_control/fixedwing_control.zip deleted file mode 100644 index edaac33d5b..0000000000 Binary files a/apps/fixedwing_control/fixedwing_control.zip and /dev/null differ diff --git a/apps/fixedwing_control/pid.c b/apps/fixedwing_control/pid.c deleted file mode 100644 index 652e4143fb..0000000000 --- a/apps/fixedwing_control/pid.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: @author Ivan Ovinnikov - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/** - * @file pid.c - * Implementation of a fixed wing attitude and position controller. - */ - -#include "pid.h" -#include "fixedwing_control.h" - -/******************************************************************************* - * pid() - * - * Calculates the PID control output given an error - * - * Input: float error, uint16_t dt, float scaler, float K_p, float K_i, float K_d - * - * Output: PID control value - * - ******************************************************************************/ - -static float pid(float error, float error_deriv, uint16_t dt, float scaler, float K_p, float K_i, float K_d, float intmax) -{ - // PID parameters - - float Kp = K_p; - float Ki = K_i; - float Kd = K_d; - float delta_time = dt; // delta time - float lerror; // last error value - float imax = intmax; // max integral value - float integrator; - float derivative; - float lderiv; - int fCut = 20; // anything above 20 Hz is considered noise - low pass filter for the derivative - float output = 0; // the output of the PID controller - - output += error * Kp; - - if ((fabs(Kd) > 0) && (dt > 0)) { - - if (PID_DERIVMODE_CALC) { - derivative = (error - lerror) / delta_time; - - // discrete low pass filter, cuts out the - // high frequency noise that can drive the controller crazy - float RC = 1 / (2 * M_PI * fCut); - derivative = lderiv + - (delta_time / (RC + delta_time)) * (derivative - lderiv); - - // update state - lerror = error; - lderiv = derivative; - - } else { - derivative = error_deriv; - } - - // add in derivative component - output += Kd * derivative; - } - - printf("PID derivative %i\n", (int)(1000 * derivative)); - - // scale the P and D components - output *= scaler; - - // Compute integral component if time has elapsed - if ((fabs(Ki) > 0) && (dt > 0)) { - integrator += (error * Ki) * scaler * delta_time; - - if (integrator < -imax) { - integrator = -imax; - - } else if (integrator > imax) { - integrator = imax; - } - - output += integrator; - } - - printf("PID Integrator %i\n", (int)(1000 * integrator)); - - return output; -} - diff --git a/apps/gps/gps.c b/apps/gps/gps.c index 6d3ff0d6bf..976beeaab8 100644 --- a/apps/gps/gps.c +++ b/apps/gps/gps.c @@ -38,7 +38,6 @@ */ #include "gps.h" - #include #include #include @@ -58,6 +57,10 @@ #include #include +static bool thread_should_exit; /**< Deamon status flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int deamon_task; /**< Handle of deamon task / thread */ + /** * GPS module readout and publishing. * @@ -68,6 +71,16 @@ */ __EXPORT int gps_main(int argc, char *argv[]); +/** + * Mainloop of deamon. + */ +int gps_thread_main(int argc, char *argv[]); + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + /**************************************************************************** * Definitions ****************************************************************************/ @@ -91,7 +104,6 @@ enum GPS_MODES { }; - #define AUTO_DETECTION_COUNT 8 const int autodetection_baudrates[] = {B9600, B38400, B38400, B9600, B9600, B38400, B9600, B38400}; const enum GPS_MODES autodetection_gpsmodes[] = {GPS_MODE_UBX, GPS_MODE_MTK, GPS_MODE_UBX, GPS_MODE_MTK, GPS_MODE_UBX, GPS_MODE_MTK, GPS_MODE_NMEA, GPS_MODE_NMEA}; //nmea is the fall-back if nothing else works, therefore we try the standard modes again before finally trying nmea @@ -101,52 +113,66 @@ const enum GPS_MODES autodetection_gpsmodes[] = {GPS_MODE_UBX, GPS_MODE_MTK, GPS ****************************************************************************/ int open_port(char *port); -void close_port(int fd); +void close_port(int *fd); -void setup_port(char *device, int speed, int *fd) +void setup_port(char *device, int speed, int *fd); + + +/** + * The deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ +int gps_main(int argc, char *argv[]) { + if (argc < 1) + usage("missing command"); - /* open port (baud rate is set in defconfig file) */ - *fd = open_port(device); + if (!strcmp(argv[1], "start")) { - if (*fd != -1) { - if (gps_verbose) printf("[gps] Port opened: %s at %d speed\r\n", device, speed); + if (thread_running) { + printf("gps already running\n"); + /* this is not an error */ + exit(0); + } - } else { - fprintf(stderr, "[gps] Could not open port, exiting gps app!\r\n"); - fflush(stdout); + thread_should_exit = false; + deamon_task = task_create("gps", SCHED_PRIORITY_DEFAULT, 4096, gps_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); } - /* Try to set baud rate */ - struct termios uart_config; - int termios_state; - - if ((termios_state = tcgetattr(*fd, &uart_config)) < 0) { - fprintf(stderr, "[gps] ERROR getting baudrate / termios config for %s: %d\r\n", device, termios_state); - close(*fd); + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); } - /* Set baud rate */ - cfsetispeed(&uart_config, speed); - cfsetospeed(&uart_config, speed); - - if ((termios_state = tcsetattr(*fd, TCSANOW, &uart_config)) < 0) { - fprintf(stderr, "[gps] ERROR setting baudrate / termios config for %s (tcsetattr)\r\n", device); - close(*fd); + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tgps is running\n"); + } else { + printf("\tgps not started\n"); + } + exit(0); } + + usage("unrecognized command"); + exit(1); } - /* * Main function of gps app. */ -int gps_main(int argc, char *argv[]) -{ +int gps_thread_main(int argc, char *argv[]) { + /* welcome message */ printf("[gps] Initialized. Searching for GPS receiver..\n"); /* default values */ - const char *commandline_usage = "\tusage: %s -d devicename -b baudrate -m mode\n\tmodes are:\n\t\tubx\n\t\tmtkcustom\n\t\tnmea\n\t\tall\n"; + const char *commandline_usage = "\tusage: %s {start|stop|status} -d devicename -b baudrate -m mode\n\tmodes are:\n\t\tubx\n\t\tmtkcustom\n\t\tnmea\n\t\tall\n"; char *device = "/dev/ttyS3"; char mode[10]; strcpy(mode, "all"); @@ -163,9 +189,10 @@ int gps_main(int argc, char *argv[]) /* read arguments */ int i; - for (i = 1; i < argc; i++) { + for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { //device set printf(commandline_usage, argv[0]); + thread_running = false; return 0; } @@ -175,6 +202,7 @@ int gps_main(int argc, char *argv[]) } else { printf(commandline_usage, argv[0]); + thread_running = false; return 0; } } @@ -185,6 +213,7 @@ int gps_main(int argc, char *argv[]) } else { printf(commandline_usage, argv[0]); + thread_running = false; return 0; } } @@ -195,6 +224,7 @@ int gps_main(int argc, char *argv[]) } else { printf(commandline_usage, argv[0]); + thread_running = false; return 0; } } @@ -205,6 +235,7 @@ int gps_main(int argc, char *argv[]) } else { printf(commandline_usage, argv[0]); + thread_running = false; return 0; } } @@ -225,45 +256,25 @@ int gps_main(int argc, char *argv[]) case -1: gps_baud_try_all = true; break; case 0: current_gps_speed = B0; break; - case 50: current_gps_speed = B50; break; - case 75: current_gps_speed = B75; break; - case 110: current_gps_speed = B110; break; - case 134: current_gps_speed = B134; break; - case 150: current_gps_speed = B150; break; - case 200: current_gps_speed = B200; break; - case 300: current_gps_speed = B300; break; - case 600: current_gps_speed = B600; break; - case 1200: current_gps_speed = B1200; break; - case 1800: current_gps_speed = B1800; break; - case 2400: current_gps_speed = B2400; break; - case 4800: current_gps_speed = B4800; break; - case 9600: current_gps_speed = B9600; break; - case 19200: current_gps_speed = B19200; break; - case 38400: current_gps_speed = B38400; break; - case 57600: current_gps_speed = B57600; break; - case 115200: current_gps_speed = B115200; break; - case 230400: current_gps_speed = B230400; break; - case 460800: current_gps_speed = B460800; break; - case 921600: current_gps_speed = B921600; break; default: @@ -290,11 +301,14 @@ int gps_main(int argc, char *argv[]) } else { fprintf(stderr, "\t[gps] Invalid mode argument\n"); printf(commandline_usage); + thread_running = false; return ERROR; } + /* Declare file descriptor for gps here, open port later in setup_port */ + int fd; - while (true) { + while (!thread_should_exit) { /* Infinite retries or break if retry == false */ /* Loop over all configurations of baud rate and protocol */ @@ -319,15 +333,14 @@ int gps_main(int argc, char *argv[]) * if the gps was once running the wtachdog thread will not return but instead try to reconfigure the gps (depending on the mode/protocol) */ - if (current_gps_mode == GPS_MODE_UBX) { //TODO: make a small enum with all modes to avoid all the strcpy + if (current_gps_mode == GPS_MODE_UBX) { if (gps_verbose) printf("[gps] Trying UBX mode at %d baud\n", current_gps_speed); - mavlink_log_info(mavlink_fd, "GPS: trying to connect to a ubx module"); - - int fd; + mavlink_log_info(mavlink_fd, "[gps] trying to connect to a ubx module"); + setup_port(device, current_gps_speed, &fd); - + /* start ubx thread and watchdog */ pthread_t ubx_thread; pthread_t ubx_watchdog_thread; @@ -342,13 +355,18 @@ int gps_main(int argc, char *argv[]) pthread_attr_t ubx_loop_attr; pthread_attr_init(&ubx_loop_attr); pthread_attr_setstacksize(&ubx_loop_attr, 3000); - pthread_create(&ubx_thread, &ubx_loop_attr, ubx_loop, (void *)&fd); - sleep(2); // XXX TODO Check if this is too short, try to lower sleeps in UBX driver + struct arg_struct args; + args.fd_ptr = &fd; + args.thread_should_exit_ptr = &thread_should_exit; + + pthread_create(&ubx_thread, &ubx_loop_attr, ubx_loop, (void *)&args); + sleep(2); // XXX TODO Check if this is too short, try to lower sleeps in UBX driver + pthread_attr_t ubx_wd_attr; pthread_attr_init(&ubx_wd_attr); pthread_attr_setstacksize(&ubx_wd_attr, 1400); - int pthread_create_res = pthread_create(&ubx_watchdog_thread, &ubx_wd_attr, ubx_watchdog_loop, (void *)&fd); + int pthread_create_res = pthread_create(&ubx_watchdog_thread, &ubx_wd_attr, ubx_watchdog_loop, (void *)&args); if (pthread_create_res != 0) fprintf(stderr, "[gps] ERROR: could not create ubx watchdog thread, pthread_create =%d\n", pthread_create_res); @@ -363,18 +381,23 @@ int gps_main(int argc, char *argv[]) gps_mode_success = true; terminate_gps_thread = false; + + /* maybe the watchdog was stopped through the thread_should_exit flag */ + } else if (thread_should_exit) { + pthread_join(ubx_thread, NULL); + if (gps_verbose) printf("[gps] ubx watchdog and ubx loop threads have been terminated, exiting."); + close(mavlink_fd); + close_port(&fd); + thread_running = false; + return 0; } - close_port(fd); - } - - if (current_gps_mode == GPS_MODE_MTK) { + close_port(&fd); + } else if (current_gps_mode == GPS_MODE_MTK) { if (gps_verbose) printf("[gps] trying MTK binary mode at %d baud\n", current_gps_speed); mavlink_log_info(mavlink_fd, "[gps] trying to connect to a MTK module"); - - int fd; setup_port(device, current_gps_speed, &fd); /* start mtk thread and watchdog */ @@ -394,9 +417,14 @@ int gps_main(int argc, char *argv[]) pthread_attr_t mtk_loop_attr; pthread_attr_init(&mtk_loop_attr); pthread_attr_setstacksize(&mtk_loop_attr, 2048); - pthread_create(&mtk_thread, &mtk_loop_attr, mtk_loop, (void *)&fd); + + struct arg_struct args; + args.fd_ptr = &fd; + args.thread_should_exit_ptr = &thread_should_exit; + + pthread_create(&mtk_thread, &mtk_loop_attr, mtk_loop, (void *)&args); sleep(2); - pthread_create(&mtk_watchdog_thread, NULL, mtk_watchdog_loop, (void *)&fd); + pthread_create(&mtk_watchdog_thread, NULL, mtk_watchdog_loop, (void *)&args); /* wait for threads to complete */ pthread_join(mtk_watchdog_thread, (void *)&fd); @@ -407,23 +435,21 @@ int gps_main(int argc, char *argv[]) terminate_gps_thread = true; pthread_join(mtk_thread, NULL); - // if(true == gps_mode_try_all) - // strcpy(mode, "nmea"); + //if(true == gps_mode_try_all) + //strcpy(mode, "nmea"); gps_mode_success = true; terminate_gps_thread = false; } - close_port(fd); + close_port(&fd); - } - - if (current_gps_mode == GPS_MODE_NMEA) { + } else if (current_gps_mode == GPS_MODE_NMEA) { if (gps_verbose) printf("[gps] Trying NMEA mode at %d baud\n", current_gps_speed); mavlink_log_info(mavlink_fd, "[gps] trying to connect to a NMEA module"); - int fd; + setup_port(device, current_gps_speed, &fd); /* start nmea thread and watchdog */ @@ -440,9 +466,14 @@ int gps_main(int argc, char *argv[]) pthread_attr_t nmea_loop_attr; pthread_attr_init(&nmea_loop_attr); pthread_attr_setstacksize(&nmea_loop_attr, 4096); - pthread_create(&nmea_thread, &nmea_loop_attr, nmea_loop, (void *)&fd); + + struct arg_struct args; + args.fd_ptr = &fd; + args.thread_should_exit_ptr = &thread_should_exit; + + pthread_create(&nmea_thread, &nmea_loop_attr, nmea_loop, (void *)&args); sleep(2); - pthread_create(&nmea_watchdog_thread, NULL, nmea_watchdog_loop, (void *)&fd); + pthread_create(&nmea_watchdog_thread, NULL, nmea_watchdog_loop, (void *)&args); /* wait for threads to complete */ pthread_join(nmea_watchdog_thread, (void *)&fd); @@ -457,14 +488,23 @@ int gps_main(int argc, char *argv[]) terminate_gps_thread = false; } - close_port(fd); + close_port(&fd); } + /* exit quickly if stop command has been received */ + if (thread_should_exit) { + printf("[gps] stopped, exiting.\n"); + close(mavlink_fd); + thread_running = false; + return 0; + } + /* if both, mode and baud is set by argument, we only need one loop*/ if (gps_mode_try_all == false && gps_baud_try_all == false) break; } + if (retry) { printf("[gps] No configuration was successful, retrying in %d seconds \n", RETRY_INTERVAL_SECONDS); mavlink_log_info(mavlink_fd, "[gps] No configuration was successful, retrying..."); @@ -480,9 +520,19 @@ int gps_main(int argc, char *argv[]) sleep(RETRY_INTERVAL_SECONDS); } + printf("[gps] exiting.\n"); close(mavlink_fd); + thread_running = false; + return 0; +} - return ERROR; + +static void usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "\tusage: gps {start|status|stop} -d devicename -b baudrate -m mode\n\tmodes are:\n\t\tubx\n\t\tmtkcustom\n\t\tnmea\n\t\tall\n"); + exit(1); } int open_port(char *port) @@ -495,11 +545,39 @@ int open_port(char *port) } -void close_port(int fd) +void close_port(int *fd) { /* Close serial port */ - close(fd); + close(*fd); } +void setup_port(char *device, int speed, int *fd) +{ + /* open port (baud rate is set in defconfig file) */ + *fd = open_port(device); + if (*fd != -1) { + if (gps_verbose) printf("[gps] Port opened: %s at %d speed\r\n", device, speed); + } else { + fprintf(stderr, "[gps] Could not open port, exiting gps app!\r\n"); + fflush(stdout); + } + + /* Try to set baud rate */ + struct termios uart_config; + int termios_state; + + if ((termios_state = tcgetattr(*fd, &uart_config)) < 0) { + fprintf(stderr, "[gps] ERROR getting baudrate / termios config for %s: %d\r\n", device, termios_state); + close(*fd); + } + if (gps_verbose) printf("[gps] Try to set baud rate %d now\n",speed); + /* Set baud rate */ + cfsetispeed(&uart_config, speed); + cfsetospeed(&uart_config, speed); + if ((termios_state = tcsetattr(*fd, TCSANOW, &uart_config)) < 0) { + fprintf(stderr, "[gps] ERROR setting baudrate / termios config for %s (tcsetattr)\r\n", device); + close(*fd); + } +} diff --git a/apps/gps/gps.h b/apps/gps/gps.h index 313a3a2c2a..499a6164f7 100644 --- a/apps/gps/gps.h +++ b/apps/gps/gps.h @@ -6,15 +6,13 @@ */ #ifndef GPS_H_ -#define GPS_H_ -/**************************************************************************** - * Included Files - ****************************************************************************/ - -int gps_fd; - -//extern gps_bin_ubx_state_t * ubx_state; +#define GPS_H +#include +struct arg_struct { + int *fd_ptr; + bool *thread_should_exit_ptr; +}; #endif /* GPS_H_ */ diff --git a/apps/gps/mtk.c b/apps/gps/mtk.c index cef70601b3..2e90f50b1b 100644 --- a/apps/gps/mtk.c +++ b/apps/gps/mtk.c @@ -35,12 +35,14 @@ /* @file MTK custom binary (3DR) protocol implementation */ +#include "gps.h" #include "mtk.h" #include #include #include #include #include +#include #include #include #include @@ -121,7 +123,7 @@ int mtk_parse(uint8_t b, char *gps_rx_buffer) if (mtk_state->ck_a == packet->ck_a && mtk_state->ck_b == packet->ck_b) { mtk_gps->lat = packet->latitude * 10; // mtk: degrees*1e6, mavlink/ubx: degrees*1e7 mtk_gps->lon = packet->longitude * 10; // mtk: degrees*1e6, mavlink/ubx: degrees*1e7 - mtk_gps->alt = (int32_t)packet->msl_altitude * 10; // conversion from centimeters to millimeters, and from uint32_t to int16_t + mtk_gps->alt = (int32_t)(packet->msl_altitude * 10); // conversion from centimeters to millimeters, and from uint32_t to int16_t mtk_gps->fix_type = packet->fix_type; mtk_gps->eph = packet->hdop; mtk_gps->epv = 65535; //unknown in mtk custom mode @@ -180,7 +182,7 @@ int mtk_parse(uint8_t b, char *gps_rx_buffer) } -int read_gps_mtk(int fd, char *gps_rx_buffer, int buffer_size) // returns 1 if the thread should terminate +int read_gps_mtk(int *fd, char *gps_rx_buffer, int buffer_size) // returns 1 if the thread should terminate { // printf("in read_gps_mtk\n"); uint8_t ret = 0; @@ -191,7 +193,7 @@ int read_gps_mtk(int fd, char *gps_rx_buffer, int buffer_size) // returns 1 if int gpsRxOverflow = 0; struct pollfd fds; - fds.fd = fd; + fds.fd = *fd; fds.events = POLLIN; // This blocks the task until there is something on the buffer @@ -206,7 +208,7 @@ int read_gps_mtk(int fd, char *gps_rx_buffer, int buffer_size) // returns 1 if } if (poll(&fds, 1, 1000) > 0) { - if (read(fd, &c, 1) > 0) { + if (read(*fd, &c, 1) > 0) { // printf("Read %x\n",c); if (rx_count >= buffer_size) { // The buffer is already full and we haven't found a valid NMEA sentence. @@ -243,11 +245,11 @@ int read_gps_mtk(int fd, char *gps_rx_buffer, int buffer_size) // returns 1 if return ret; } -int configure_gps_mtk(int fd) +int configure_gps_mtk(int *fd) { int success = 0; size_t result_write; - result_write = write(fd, MEDIATEK_REFRESH_RATE_10HZ, strlen(MEDIATEK_REFRESH_RATE_10HZ)); + result_write = write(*fd, MEDIATEK_REFRESH_RATE_10HZ, strlen(MEDIATEK_REFRESH_RATE_10HZ)); if (result_write != strlen(MEDIATEK_REFRESH_RATE_10HZ)) { printf("[gps] Set update speed to 10 Hz failed\r\n"); @@ -258,7 +260,7 @@ int configure_gps_mtk(int fd) } //set custom mode - result_write = write(fd, MEDIATEK_CUSTOM_BINARY_MODE, strlen(MEDIATEK_CUSTOM_BINARY_MODE)); + result_write = write(*fd, MEDIATEK_CUSTOM_BINARY_MODE, strlen(MEDIATEK_CUSTOM_BINARY_MODE)); if (result_write != strlen(MEDIATEK_CUSTOM_BINARY_MODE)) { //global_data_send_subsystem_info(&mtk_present); @@ -273,7 +275,7 @@ int configure_gps_mtk(int fd) return success; } -void *mtk_loop(void *arg) +void *mtk_loop(void *args) { // int oldstate; // pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, oldstate); @@ -282,8 +284,10 @@ void *mtk_loop(void *arg) /* Set thread name */ prctl(PR_SET_NAME, "gps mtk read", getpid()); - /* Retrieve file descriptor */ - int fd = *((int *)arg); + /* Retrieve file descriptor and thread flag */ + struct arg_struct *arguments = (struct arg_struct *)args; + int *fd = arguments->fd_ptr; + bool *thread_should_exit = arguments->thread_should_exit_ptr; /* Initialize gps stuff */ // int buffer_size = 1000; @@ -311,25 +315,29 @@ void *mtk_loop(void *arg) /* advertise GPS topic */ struct vehicle_gps_position_s mtk_gps_d; mtk_gps = &mtk_gps_d; - int gps_handle = orb_advertise(ORB_ID(vehicle_gps_position), &mtk_gps); + orb_advert_t gps_handle = orb_advertise(ORB_ID(vehicle_gps_position), mtk_gps); - while (1) { + while (!(*thread_should_exit)) { /* Parse a message from the gps receiver */ if (OK == read_gps_mtk(fd, gps_rx_buffer, MTK_BUFFER_SIZE)) { /* publish new GPS position */ - orb_publish(ORB_ID(vehicle_gps_position), gps_handle, &mtk_gps); + orb_publish(ORB_ID(vehicle_gps_position), gps_handle, mtk_gps); } else { + /* de-advertise */ + close(gps_handle); break; } } + close(gps_handle); + if(gps_verbose) printf("[gps] mtk loop is going to terminate\n"); return NULL; } -void *mtk_watchdog_loop(void *arg) +void *mtk_watchdog_loop(void *args) { // printf("in mtk watchdog loop\n"); fflush(stdout); @@ -337,8 +345,10 @@ void *mtk_watchdog_loop(void *arg) /* Set thread name */ prctl(PR_SET_NAME, "gps mtk watchdog", getpid()); - /* Retrieve file descriptor */ - int fd = *((int *)arg); + /* Retrieve file descriptor and thread flag */ + struct arg_struct *arguments = (struct arg_struct *)args; + int *fd = arguments->fd_ptr; + bool *thread_should_exit = arguments->thread_should_exit_ptr; bool mtk_healthy = false; @@ -349,7 +359,7 @@ void *mtk_watchdog_loop(void *arg) int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - while (1) { + while (!(*thread_should_exit)) { fflush(stdout); /* if we have no update for a long time reconfigure gps */ @@ -416,8 +426,7 @@ void *mtk_watchdog_loop(void *arg) usleep(MTK_WATCHDOG_WAIT_TIME_MICROSECONDS); } - + if(gps_verbose) printf("[gps] mtk watchdog is going to terminate\n"); close(mavlink_fd); - return NULL; } diff --git a/apps/gps/mtk.h b/apps/gps/mtk.h index 1c65a5865c..9fc1caec83 100644 --- a/apps/gps/mtk.h +++ b/apps/gps/mtk.h @@ -87,12 +87,12 @@ void mtk_checksum(uint8_t b, uint8_t *ck_a, uint8_t *ck_b); int mtk_parse(uint8_t b, char *gps_rx_buffer); -int read_gps_mtk(int fd, char *gps_rx_buffer, int buffer_size); +int read_gps_mtk(int *fd, char *gps_rx_buffer, int buffer_size); -int configure_gps_mtk(int fd); +int configure_gps_mtk(int *fd); -void *mtk_loop(void *arg); +void *mtk_loop(void *args); -void *mtk_watchdog_loop(void *arg); +void *mtk_watchdog_loop(void *args); #endif /* MTK_H_ */ diff --git a/apps/gps/nmea_helper.c b/apps/gps/nmea_helper.c index 4b520d4036..d1c9d364b7 100644 --- a/apps/gps/nmea_helper.c +++ b/apps/gps/nmea_helper.c @@ -34,13 +34,17 @@ ****************************************************************************/ /* @file NMEA protocol implementation */ - +#include "gps.h" #include "nmea_helper.h" #include +#include #include +#include +#include #include #include #include +#include #define NMEA_HEALTH_SUCCESS_COUNTER_LIMIT 2 #define NMEA_HEALTH_FAIL_COUNTER_LIMIT 2 @@ -59,7 +63,7 @@ extern bool gps_verbose; extern int current_gps_speed; -int read_gps_nmea(int fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, nmeaPARSER *parser) +int read_gps_nmea(int *fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, nmeaPARSER *parser) { int ret = 1; char c; @@ -69,7 +73,7 @@ int read_gps_nmea(int fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, int gpsRxOverflow = 0; struct pollfd fds; - fds.fd = fd; + fds.fd = *fd; fds.events = POLLIN; // NMEA or SINGLE-SENTENCE GPS mode @@ -86,7 +90,7 @@ int read_gps_nmea(int fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, } if (poll(&fds, 1, 1000) > 0) { - if (read(fd, &c, 1) > 0) { + if (read(*fd, &c, 1) > 0) { // detect start while acquiring stream // printf("Char = %c\n", c); if (!start_flag && (c == '$')) { @@ -155,13 +159,15 @@ float ndeg2degree(float val) return val; } -void *nmea_loop(void *arg) +void *nmea_loop(void *args) { /* Set thread name */ prctl(PR_SET_NAME, "gps nmea read", getpid()); - /* Retrieve file descriptor */ - int fd = *((int *)arg); + /* Retrieve file descriptor and thread flag */ + struct arg_struct *arguments = (struct arg_struct *)args; + int *fd = arguments->fd_ptr; + bool *thread_should_exit = arguments->thread_should_exit_ptr; /* Initialize gps stuff */ nmeaINFO info_d; @@ -174,11 +180,11 @@ void *nmea_loop(void *arg) nmea_zero_INFO(info); /* advertise GPS topic */ - struct vehicle_gps_position_s nmea_gps_d = {0}; + struct vehicle_gps_position_s nmea_gps_d = {.counter=0}; nmea_gps = &nmea_gps_d; - int gps_handle = orb_advertise(ORB_ID(vehicle_gps_position), nmea_gps); + orb_advert_t gps_handle = orb_advertise(ORB_ID(vehicle_gps_position), nmea_gps); - while (1) { + while (!(*thread_should_exit)) { /* Parse a message from the gps receiver */ uint8_t read_res = read_gps_nmea(fd, gps_rx_buffer, NMEA_BUFFER_SIZE, info, &parser); @@ -200,11 +206,11 @@ void *nmea_loop(void *arg) // printf("%d.%d.%d %d:%d:%d:%d\n", timeinfo.tm_year, timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, info->utc.hsec); nmea_gps->timestamp = hrt_absolute_time(); - nmea_gps->time_gps_usec = epoch * 1e6 + info->utc.hsec * 1e4; + nmea_gps->time_gps_usec = (uint64_t)((epoch)*1000000 + (info->utc.hsec)*10000); nmea_gps->fix_type = (uint8_t)info->fix; - nmea_gps->lat = (int32_t)ndeg2degree(info->lat) * 1e7; - nmea_gps->lon = (int32_t)ndeg2degree(info->lon) * 1e7; - nmea_gps->alt = (int32_t)(info->elv * 1e3); + nmea_gps->lat = (int32_t)(ndeg2degree(info->lat) * 1e7f); + nmea_gps->lon = (int32_t)(ndeg2degree(info->lon) * 1e7f); + nmea_gps->alt = (int32_t)(info->elv * 1000.0f); nmea_gps->eph = (uint16_t)(info->HDOP * 100); //TODO:test scaling nmea_gps->epv = (uint16_t)(info->VDOP * 100); //TODO:test scaling nmea_gps->vel = (uint16_t)(info->speed * 1000 / 36); //*1000/3600*100 @@ -251,12 +257,12 @@ void *nmea_loop(void *arg) //destroy gps parser nmea_parser_destroy(&parser); - + if(gps_verbose) printf("[gps] nmea loop is going to terminate\n"); return NULL; } -void *nmea_watchdog_loop(void *arg) +void *nmea_watchdog_loop(void *args) { /* Set thread name */ prctl(PR_SET_NAME, "gps nmea watchdog", getpid()); @@ -267,9 +273,14 @@ void *nmea_watchdog_loop(void *arg) uint8_t nmea_success_count = 0; bool once_ok = false; + /* Retrieve file descriptor and thread flag */ + struct arg_struct *arguments = (struct arg_struct *)args; + //int *fd = arguments->fd_ptr; + bool *thread_should_exit = arguments->thread_should_exit_ptr; + int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - while (1) { + while (!(*thread_should_exit)) { // printf("nmea_watchdog_loop : while "); /* if we have no update for a long time print warning (in nmea mode there is no reconfigure) */ pthread_mutex_lock(nmea_mutex); @@ -328,8 +339,7 @@ void *nmea_watchdog_loop(void *arg) usleep(NMEA_WATCHDOG_WAIT_TIME_MICROSECONDS); } - + if(gps_verbose) printf("[gps] nmea watchdog loop is going to terminate\n"); close(mavlink_fd); - return NULL; } diff --git a/apps/gps/nmea_helper.h b/apps/gps/nmea_helper.h index 8fd630bcd3..3a853dd134 100644 --- a/apps/gps/nmea_helper.h +++ b/apps/gps/nmea_helper.h @@ -30,7 +30,7 @@ extern pthread_mutex_t *nmea_mutex; -int read_gps_nmea(int fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, nmeaPARSER *parser); +int read_gps_nmea(int *fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, nmeaPARSER *parser); void *nmea_loop(void *arg); diff --git a/apps/gps/ubx.c b/apps/gps/ubx.c index 771dfbd6c0..8a658b6230 100644 --- a/apps/gps/ubx.c +++ b/apps/gps/ubx.c @@ -35,12 +35,16 @@ /* @file U-Blox protocol implementation */ + #include "ubx.h" +#include "gps.h" #include #include #include #include #include +#include +#include #include #include @@ -340,8 +344,8 @@ int ubx_parse(uint8_t b, char *gps_rx_buffer) - ubx_gps->time_gps_usec = (uint64_t)epoch * 1e6; //TODO: test this - ubx_gps->time_gps_usec += packet->time_nanoseconds * 1e-3; + ubx_gps->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this + ubx_gps->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); ubx_gps->timestamp = hrt_absolute_time(); ubx_gps->counter++; @@ -474,7 +478,7 @@ int ubx_parse(uint8_t b, char *gps_rx_buffer) if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { ubx_gps->vel = (uint16_t)packet->speed; - ubx_gps->cog = (uint16_t)((float)(packet->heading) * 1e-3); + ubx_gps->cog = (uint16_t)((float)(packet->heading) * 1e-3f); ubx_gps->timestamp = hrt_absolute_time(); ubx_gps->counter++; @@ -570,44 +574,44 @@ void calculate_ubx_checksum(uint8_t *message, uint8_t length) // printf("[%x,%x]\n", message[length-2], message[length-1]); } -int configure_gps_ubx(int fd) +int configure_gps_ubx(int *fd) { - fflush((FILE *)fd); + //fflush(((FILE *)fd)); //TODO: write this in a loop once it is tested //UBX_CFG_PRT_PART: - write_config_message_ubx(UBX_CONFIG_MESSAGE_PRT, sizeof(UBX_CONFIG_MESSAGE_PRT) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_PRT, sizeof(UBX_CONFIG_MESSAGE_PRT) / sizeof(uint8_t) , *fd); usleep(100000); //NAV_POSLLH: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_POSLLH, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_POSLLH) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_POSLLH, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_POSLLH) / sizeof(uint8_t) , *fd); usleep(100000); //NAV_TIMEUTC: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_TIMEUTC, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_TIMEUTC) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_TIMEUTC, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_TIMEUTC) / sizeof(uint8_t) , *fd); usleep(100000); //NAV_DOP: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_DOP, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_DOP) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_DOP, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_DOP) / sizeof(uint8_t) , *fd); usleep(100000); //NAV_SOL: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_SOL, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_SOL) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_SOL, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_SOL) / sizeof(uint8_t) , *fd); usleep(100000); //NAV_SVINFO: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_SVINFO, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_SVINFO) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_SVINFO, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_SVINFO) / sizeof(uint8_t) , *fd); usleep(100000); //NAV_VELNED: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_VELNED, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_VELNED) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_NAV_VELNED, sizeof(UBX_CONFIG_MESSAGE_MSG_NAV_VELNED) / sizeof(uint8_t) , *fd); usleep(100000); //RXM_SVSI: - write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_RXM_SVSI, sizeof(UBX_CONFIG_MESSAGE_MSG_RXM_SVSI) / sizeof(uint8_t) , fd); + write_config_message_ubx(UBX_CONFIG_MESSAGE_MSG_RXM_SVSI, sizeof(UBX_CONFIG_MESSAGE_MSG_RXM_SVSI) / sizeof(uint8_t) , *fd); usleep(100000); return 0; @@ -615,16 +619,15 @@ int configure_gps_ubx(int fd) -int read_gps_ubx(int fd, char *gps_rx_buffer, int buffer_size) +int read_gps_ubx(int *fd, char *gps_rx_buffer, int buffer_size) { - uint8_t ret = 0; uint8_t c; int rx_count = 0; int gpsRxOverflow = 0; struct pollfd fds; - fds.fd = fd; + fds.fd = *fd; fds.events = POLLIN; // UBX GPS mode @@ -641,7 +644,7 @@ int read_gps_ubx(int fd, char *gps_rx_buffer, int buffer_size) } if (poll(&fds, 1, 1000) > 0) { - if (read(fd, &c, 1) > 0) { + if (read(*fd, &c, 1) > 0) { // printf("Read %x\n",c); if (rx_count >= buffer_size) { @@ -685,7 +688,7 @@ int write_config_message_ubx(uint8_t *message, size_t length, int fd) uint8_t ck_a = 0; uint8_t ck_b = 0; - int i; + unsigned int i; for (i = 2; i < length; i++) { ck_a = ck_a + message[i]; @@ -702,14 +705,16 @@ int write_config_message_ubx(uint8_t *message, size_t length, int fd) } -void *ubx_watchdog_loop(void *arg) +void *ubx_watchdog_loop(void *args) { /* Set thread name */ prctl(PR_SET_NAME, "gps ubx watchdog", getpid()); - /* Retrieve file descriptor */ - int fd = *((int *)arg); + /* Retrieve file descriptor and thread flag */ + struct arg_struct *arguments = (struct arg_struct *)args; + int *fd = arguments->fd_ptr; + bool *thread_should_exit = arguments->thread_should_exit_ptr; /* GPS watchdog error message skip counter */ @@ -721,7 +726,9 @@ void *ubx_watchdog_loop(void *arg) int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - while (1) { + //int err_skip_counter = 0; + + while (!(*thread_should_exit)) { /* if some values are to old reconfigure gps */ int i; pthread_mutex_lock(ubx_mutex); @@ -732,7 +739,7 @@ void *ubx_watchdog_loop(void *arg) // printf("timestamp_now=%llu\n", timestamp_now); // printf("last_message_timestamps=%llu\n", ubx_state->last_message_timestamps[i]); if (timestamp_now - ubx_state->last_message_timestamps[i] > UBX_WATCHDOG_CRITICAL_TIME_MICROSECONDS) { -// printf("Warning: GPS ubx message %d not received for a long time\n", i); + //printf("Warning: GPS ubx message %d not received for a long time\n", i); all_okay = false; } } @@ -748,7 +755,7 @@ void *ubx_watchdog_loop(void *arg) // err_skip_counter = 20; // } // err_skip_counter--; -// printf("gps_mode_try_all =%u, ubx_fail_count=%u, ubx_healthy=%u, once_ok=%u\n", gps_mode_try_all, ubx_fail_count, ubx_healthy, once_ok); + //printf("gps_mode_try_all =%u, ubx_fail_count=%u, ubx_healthy=%u, once_ok=%u\n", gps_mode_try_all, ubx_fail_count, ubx_healthy, once_ok); /* If we have too many failures and another mode or baud should be tried, exit... */ @@ -766,7 +773,6 @@ void *ubx_watchdog_loop(void *arg) ubx_healthy = false; ubx_success_count = 0; } - /* trying to reconfigure the gps configuration */ configure_gps_ubx(fd); fflush(stdout); @@ -777,7 +783,7 @@ void *ubx_watchdog_loop(void *arg) ubx_success_count++; if (!ubx_healthy && ubx_success_count == UBX_HEALTH_SUCCESS_COUNTER_LIMIT) { - printf("[gps] ublox UBX module status ok (baud=%d)\r\n", current_gps_speed); + //printf("[gps] ublox UBX module status ok (baud=%d)\r\n", current_gps_speed); // global_data_send_subsystem_info(&ubx_present_enabled_healthy); mavlink_log_info(mavlink_fd, "[gps] UBX module found, status ok\n"); ubx_healthy = true; @@ -790,18 +796,20 @@ void *ubx_watchdog_loop(void *arg) usleep(UBX_WATCHDOG_WAIT_TIME_MICROSECONDS); } + if(gps_verbose) printf("[gps] ubx loop is going to terminate\n"); close(mavlink_fd); - return NULL; } -void *ubx_loop(void *arg) +void *ubx_loop(void *args) { /* Set thread name */ prctl(PR_SET_NAME, "gps ubx read", getpid()); - - /* Retrieve file descriptor */ - int fd = *((int *)arg); + + /* Retrieve file descriptor and thread flag */ + struct arg_struct *arguments = (struct arg_struct *)args; + int *fd = arguments->fd_ptr; + bool *thread_should_exit = arguments->thread_should_exit_ptr; /* Initialize gps stuff */ char gps_rx_buffer[UBX_BUFFER_SIZE]; @@ -809,14 +817,13 @@ void *ubx_loop(void *arg) if (gps_verbose) printf("[gps] UBX protocol driver starting..\r\n"); - //set parameters for ubx + //set parameters for ubx_state - -// //ubx state -// gps_bin_ubx_state_t * ubx_state = malloc(sizeof(gps_bin_ubx_state_t)); -// printf("gps: ubx_state created\n"); -// ubx_decode_init(); -// ubx_state->print_errors = false; + //ubx state + ubx_state = malloc(sizeof(gps_bin_ubx_state_t)); + //printf("gps: ubx_state created\n"); + ubx_decode_init(); + ubx_state->print_errors = false; /* set parameters for ubx */ @@ -825,7 +832,7 @@ void *ubx_loop(void *arg) printf("[gps] Configuration of gps module to ubx failed\r\n"); /* Write shared variable sys_status */ - + // TODO enable this again //global_data_send_subsystem_info(&ubx_present); } else { @@ -834,17 +841,17 @@ void *ubx_loop(void *arg) // XXX Shouldn't the system status only change if the module is known to work ok? /* Write shared variable sys_status */ - + // TODO enable this again //global_data_send_subsystem_info(&ubx_present_enabled); } - struct vehicle_gps_position_s ubx_gps_d = {0}; + struct vehicle_gps_position_s ubx_gps_d = {.counter = 0}; ubx_gps = &ubx_gps_d; - int gps_pub = orb_advertise(ORB_ID(vehicle_gps_position), &ubx_gps); + orb_advert_t gps_pub = orb_advertise(ORB_ID(vehicle_gps_position), &ubx_gps); - while (1) { + while (!(*thread_should_exit)) { /* Parse a message from the gps receiver */ if (0 == read_gps_ubx(fd, gps_rx_buffer, UBX_BUFFER_SIZE)) { /* publish new GPS position */ @@ -857,7 +864,8 @@ void *ubx_loop(void *arg) } } - + if(gps_verbose) printf("[gps] ubx read is going to terminate\n"); + close(gps_pub); return NULL; } diff --git a/apps/gps/ubx.h b/apps/gps/ubx.h index 5def1ed33d..8e98cca5f3 100644 --- a/apps/gps/ubx.h +++ b/apps/gps/ubx.h @@ -298,17 +298,17 @@ void ubx_checksum(uint8_t b, uint8_t *ck_a, uint8_t *ck_b); int ubx_parse(uint8_t b, char *gps_rx_buffer); -int configure_gps_ubx(int fd); +int configure_gps_ubx(int *fd); -int read_gps_ubx(int fd, char *gps_rx_buffer, int buffer_size); +int read_gps_ubx(int *fd, char *gps_rx_buffer, int buffer_size); int write_config_message_ubx(uint8_t *message, size_t length, int fd); void calculate_ubx_checksum(uint8_t *message, uint8_t length); -void *ubx_watchdog_loop(void *arg); +void *ubx_watchdog_loop(void *args); -void *ubx_loop(void *arg); +void *ubx_loop(void *args); #endif /* UBX_H_ */ diff --git a/apps/interpreters/Makefile b/apps/interpreters/Makefile index 1ef9c7439c..5901fc8309 100644 --- a/apps/interpreters/Makefile +++ b/apps/interpreters/Makefile @@ -2,7 +2,7 @@ # apps/interpreters/Makefile # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/interpreters/README.txt b/apps/interpreters/README.txt index 8cf7ce321b..f33c75df1c 100644 --- a/apps/interpreters/README.txt +++ b/apps/interpreters/README.txt @@ -58,7 +58,7 @@ pcode Pascal P-Code at runtime. To use this example, place the following in your appconfig file" - # Path to example in apps/examples containing the user_start entry point + # Path to example in apps/examples containing the passhello_main entry point CONFIGURED_APPS += examples/pashello diff --git a/apps/interpreters/ficl/Makefile b/apps/interpreters/ficl/Makefile index 183246b67a..fb953964e1 100644 --- a/apps/interpreters/ficl/Makefile +++ b/apps/interpreters/ficl/Makefile @@ -2,7 +2,7 @@ # apps/interpreters/ficl/Makefile # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/interpreters/ficl/README.txt b/apps/interpreters/ficl/README.txt old mode 100755 new mode 100644 diff --git a/apps/mavlink/Makefile b/apps/mavlink/Makefile index d4e9a5762a..8ddb69b71d 100644 --- a/apps/mavlink/Makefile +++ b/apps/mavlink/Makefile @@ -37,7 +37,7 @@ APPNAME = mavlink PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 4096 +STACKSIZE = 2048 INCLUDES = $(TOPDIR)/../mavlink/include/mavlink diff --git a/apps/mavlink/mavlink.c b/apps/mavlink/mavlink.c index b6fdc1a3e9..fb96866b0d 100644 --- a/apps/mavlink/mavlink.c +++ b/apps/mavlink/mavlink.c @@ -61,8 +61,6 @@ #include #include #include -#include -#include #include #include #include @@ -73,9 +71,19 @@ #include #include #include +#include +#include +#include +#include +#include + #include "waypoints.h" #include "mavlink_log.h" +/* define MAVLink specific parameters */ +PARAM_DEFINE_INT32(MAV_SYS_ID, 1); +PARAM_DEFINE_INT32(MAV_COMP_ID, 50); +PARAM_DEFINE_INT32(MAV_TYPE, MAV_TYPE_QUADROTOR); __EXPORT int mavlink_main(int argc, char *argv[]); int mavlink_thread_main(int argc, char *argv[]); @@ -86,10 +94,8 @@ static int mavlink_task; /* terminate MAVLink on user request - disabled by default */ static bool mavlink_link_termination_allowed = false; -static bool mavlink_exit_requested = false; -static int system_type = MAV_TYPE_FIXED_WING; -mavlink_system_t mavlink_system = {100, 50, 0, 0, 0, 0}; // System ID, 1-255, Component/Subsystem ID, 1-255 +mavlink_system_t mavlink_system = {100, 50, MAV_TYPE_QUADROTOR, 0, 0, 0}; // System ID, 1-255, Component/Subsystem ID, 1-255 static uint8_t chan = MAVLINK_COMM_0; static mavlink_status_t status; @@ -113,45 +119,82 @@ static struct vehicle_status_s v_status; static struct rc_channels_s rc; /* HIL publishers */ -static int pub_hil_attitude = -1; +static orb_advert_t pub_hil_attitude = -1; /** HIL attitude */ static struct vehicle_attitude_s hil_attitude; static struct vehicle_global_position_s hil_global_pos; -static struct fixedwing_control_s fw_control; - static struct ardrone_motors_setpoint_s ardrone_motors; static struct vehicle_command_s vcmd; -static int pub_hil_global_pos = -1; -static int ardrone_motors_pub = -1; -static int cmd_pub = -1; -static int sensor_sub = -1; -static int global_pos_sub = -1; -static int local_pos_sub = -1; -static int flow_pub = -1; -static int global_position_setpoint_pub = -1; -static int local_position_setpoint_pub = -1; +static struct actuator_armed_s armed; + +static orb_advert_t pub_hil_global_pos = -1; +static orb_advert_t ardrone_motors_pub = -1; +static orb_advert_t cmd_pub = -1; +static orb_advert_t flow_pub = -1; +static orb_advert_t global_position_setpoint_pub = -1; +static orb_advert_t local_position_setpoint_pub = -1; static bool mavlink_hil_enabled = false; static char mavlink_message_string[51] = {0}; +static int baudrate = 57600; + /* interface mode */ static enum { MAVLINK_INTERFACE_MODE_OFFBOARD, MAVLINK_INTERFACE_MODE_ONBOARD } mavlink_link_mode = MAVLINK_INTERFACE_MODE_OFFBOARD; +static struct mavlink_subscriptions { + int sensor_sub; + int att_sub; + int global_pos_sub; + int act_0_sub; + int act_1_sub; + int act_2_sub; + int act_3_sub; + int gps_sub; + int man_control_sp_sub; + int armed_sub; + int actuators_sub; + int local_pos_sub; + int spa_sub; + int spl_sub; + int spg_sub; + int debug_key_value; + bool initialized; +} mavlink_subs = { + .sensor_sub = 0, + .att_sub = 0, + .global_pos_sub = 0, + .act_0_sub = 0, + .act_1_sub = 0, + .act_2_sub = 0, + .act_3_sub = 0, + .gps_sub = 0, + .man_control_sp_sub = 0, + .armed_sub = 0, + .actuators_sub = 0, + .local_pos_sub = 0, + .spa_sub = 0, + .spl_sub = 0, + .spg_sub = 0, + .debug_key_value = 0, + .initialized = false +}; + /* 3: Define waypoint helper functions */ void mavlink_wpm_send_message(mavlink_message_t *msg); void mavlink_wpm_send_gcs_string(const char *string); uint64_t mavlink_wpm_get_system_timestamp(void); -void mavlink_missionlib_send_message(mavlink_message_t *msg); -void mavlink_missionlib_send_gcs_string(const char *string); +int mavlink_missionlib_send_message(mavlink_message_t *msg); +int mavlink_missionlib_send_gcs_string(const char *string); uint64_t mavlink_missionlib_get_system_timestamp(void); void handleMessage(mavlink_message_t *msg); @@ -164,7 +207,7 @@ int set_hil_on_off(bool hil_enabled); /** * Translate the custom state into standard mavlink modes and state. */ -void get_mavlink_mode_and_state(const struct vehicle_status_s *c_status, uint8_t *mavlink_state, uint8_t *mavlink_mode); +void get_mavlink_mode_and_state(const struct vehicle_status_s *c_status, const struct actuator_armed_s *actuator, uint8_t *mavlink_state, uint8_t *mavlink_mode); int mavlink_open_uart(int baudrate, const char *uart_name, struct termios *uart_config_original, bool *is_usb); @@ -182,13 +225,18 @@ static void usage(const char *reason); static uint8_t missionlib_msg_buf[MAVLINK_MAX_PACKET_LEN]; -void mavlink_missionlib_send_message(mavlink_message_t *msg) +int mavlink_missionlib_send_message(mavlink_message_t *msg) { uint16_t len = mavlink_msg_to_send_buffer(missionlib_msg_buf, msg); - write(uart, missionlib_msg_buf, len); + int writelen = write(uart, missionlib_msg_buf, len); + if (writelen != len) { + return 1; + } else { + return 0; + } } -void mavlink_missionlib_send_gcs_string(const char *string) +int mavlink_missionlib_send_gcs_string(const char *string) { const int len = MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN; mavlink_statustext_t statustext; @@ -209,7 +257,9 @@ void mavlink_missionlib_send_gcs_string(const char *string) mavlink_message_t msg; mavlink_msg_statustext_encode(mavlink_system.sysid, mavlink_system.compid, &msg, &statustext); - mavlink_missionlib_send_message(&msg); + return mavlink_missionlib_send_message(&msg); + } else { + return 1; } } @@ -310,16 +360,34 @@ int set_hil_on_off(bool hil_enabled) printf("\n pub_hil_attitude :%i\n", pub_hil_attitude); printf("\n pub_hil_global_pos :%i\n", pub_hil_global_pos); - if (pub_hil_attitude > 0 && pub_hil_global_pos > 0) { - mavlink_hil_enabled = true; + mavlink_hil_enabled = true; + /* ramp up some HIL-related subscriptions */ + unsigned hil_rate_interval; + + if (baudrate < 19200) { + /* 10 Hz */ + hil_rate_interval = 100; + } else if (baudrate < 38400) { + /* 10 Hz */ + hil_rate_interval = 100; + } else if (baudrate < 115200) { + /* 20 Hz */ + hil_rate_interval = 50; + } else if (baudrate < 460800) { + /* 50 Hz */ + hil_rate_interval = 20; } else { - ret = ERROR; + /* 100 Hz */ + hil_rate_interval = 10; } + + orb_set_interval(mavlink_subs.spa_sub, hil_rate_interval); } if (!hil_enabled && mavlink_hil_enabled) { mavlink_hil_enabled = false; + orb_set_interval(mavlink_subs.spa_sub, 200); (void)close(pub_hil_attitude); (void)close(pub_hil_global_pos); @@ -330,7 +398,7 @@ int set_hil_on_off(bool hil_enabled) return ret; } -void get_mavlink_mode_and_state(const struct vehicle_status_s *c_status, uint8_t *mavlink_state, uint8_t *mavlink_mode) +void get_mavlink_mode_and_state(const struct vehicle_status_s *c_status, const struct actuator_armed_s *actuator, uint8_t *mavlink_state, uint8_t *mavlink_mode) { /* reset MAVLink mode bitfield */ *mavlink_mode = 0; @@ -340,68 +408,69 @@ void get_mavlink_mode_and_state(const struct vehicle_status_s *c_status, uint8_t *mavlink_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED; } + if (c_status->flag_hil_enabled) { + *mavlink_mode |= MAV_MODE_FLAG_HIL_ENABLED; + } + + /* set arming state */ + if (actuator->armed) { + *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; + } else { + *mavlink_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED; + } + switch (c_status->state_machine) { case SYSTEM_STATE_PREFLIGHT: - if (c_status->preflight_gyro_calibration || c_status->preflight_mag_calibration) { + if (c_status->flag_preflight_gyro_calibration || + c_status->flag_preflight_mag_calibration || + c_status->flag_preflight_accel_calibration) { *mavlink_state = MAV_STATE_CALIBRATING; - *mavlink_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED; } else { *mavlink_state = MAV_STATE_UNINIT; - *mavlink_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED; } break; case SYSTEM_STATE_STANDBY: *mavlink_state = MAV_STATE_STANDBY; - *mavlink_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED; break; case SYSTEM_STATE_GROUND_READY: *mavlink_state = MAV_STATE_ACTIVE; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; break; case SYSTEM_STATE_MANUAL: *mavlink_state = MAV_STATE_ACTIVE; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; *mavlink_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED; break; case SYSTEM_STATE_STABILIZED: *mavlink_state = MAV_STATE_ACTIVE; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; *mavlink_mode |= MAV_MODE_FLAG_STABILIZE_ENABLED; break; case SYSTEM_STATE_AUTO: *mavlink_state = MAV_STATE_ACTIVE; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; *mavlink_mode |= MAV_MODE_FLAG_GUIDED_ENABLED; break; case SYSTEM_STATE_MISSION_ABORT: *mavlink_state = MAV_STATE_EMERGENCY; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; break; case SYSTEM_STATE_EMCY_LANDING: *mavlink_state = MAV_STATE_EMERGENCY; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; break; case SYSTEM_STATE_EMCY_CUTOFF: *mavlink_state = MAV_STATE_EMERGENCY; - *mavlink_mode |= MAV_MODE_FLAG_SAFETY_ARMED; break; case SYSTEM_STATE_GROUND_ERROR: *mavlink_state = MAV_STATE_EMERGENCY; - *mavlink_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED; break; case SYSTEM_STATE_REBOOT: *mavlink_state = MAV_STATE_POWEROFF; - *mavlink_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED; break; } @@ -412,48 +481,78 @@ void get_mavlink_mode_and_state(const struct vehicle_status_s *c_status, uint8_t */ static void *receiveloop(void *arg) { + int uart_fd = *((int*)arg); + + const int timeout = 1000; uint8_t ch; mavlink_message_t msg; prctl(PR_SET_NAME, "mavlink uart rcv", getpid()); - while (1) { + while (!thread_should_exit) { - if (mavlink_exit_requested) break; + struct pollfd fds[] = { { .fd = uart_fd, .events = POLLIN } }; - /* blocking read on next byte */ - int nread = read(uart, &ch, 1); + if (poll(fds, 1, timeout) > 0) { + /* non-blocking read until buffer is empty */ + int nread = 0; + do { + nread = read(uart_fd, &ch, 1); - if (nread > 0 && mavlink_parse_char(chan, ch, &msg, &status)) { //parse the char - /* handle generic messages and commands */ - handleMessage(&msg); + if (mavlink_parse_char(chan, ch, &msg, &status)) { //parse the char + /* handle generic messages and commands */ + handleMessage(&msg); - /* Handle packet with waypoint component */ - mavlink_wpm_message_handler(&msg, &global_pos, &local_pos); + /* Handle packet with waypoint component */ + mavlink_wpm_message_handler(&msg, &global_pos, &local_pos); - /* Handle packet with parameter component */ - mavlink_pm_message_handler(MAVLINK_COMM_0, &msg); + /* Handle packet with parameter component */ + mavlink_pm_message_handler(MAVLINK_COMM_0, &msg); + } + } while (nread > 0); } - } return NULL; } -static int set_mavlink_interval_limit(int mavlink_msg_id, int min_interval) +static int set_mavlink_interval_limit(struct mavlink_subscriptions *subs, int mavlink_msg_id, int min_interval) { int ret = OK; switch (mavlink_msg_id) { case MAVLINK_MSG_ID_SCALED_IMU: /* senser sub triggers scaled IMU */ - orb_set_interval(sensor_sub, min_interval); + if (subs->sensor_sub) orb_set_interval(subs->sensor_sub, min_interval); + break; + case MAVLINK_MSG_ID_HIGHRES_IMU: + /* senser sub triggers highres IMU */ + if (subs->sensor_sub) orb_set_interval(subs->sensor_sub, min_interval); break; case MAVLINK_MSG_ID_RAW_IMU: /* senser sub triggers RAW IMU */ - orb_set_interval(sensor_sub, min_interval); + if (subs->sensor_sub) orb_set_interval(subs->sensor_sub, min_interval); + break; + case MAVLINK_MSG_ID_ATTITUDE: + /* attitude sub triggers attitude */ + if (subs->att_sub) orb_set_interval(subs->att_sub, min_interval); + break; + case MAVLINK_MSG_ID_SERVO_OUTPUT_RAW: + /* actuator_outputs triggers this message */ + if (subs->act_0_sub) orb_set_interval(subs->act_0_sub, min_interval); + if (subs->act_1_sub) orb_set_interval(subs->act_1_sub, min_interval); + if (subs->act_2_sub) orb_set_interval(subs->act_2_sub, min_interval); + if (subs->act_3_sub) orb_set_interval(subs->act_3_sub, min_interval); + if (subs->actuators_sub) orb_set_interval(subs->actuators_sub, min_interval); + break; + case MAVLINK_MSG_ID_MANUAL_CONTROL: + /* manual_control_setpoint triggers this message */ + if (subs->man_control_sp_sub) orb_set_interval(subs->man_control_sp_sub, min_interval); + break; + case MAVLINK_MSG_ID_NAMED_VALUE_FLOAT: + if (subs->debug_key_value) orb_set_interval(subs->debug_key_value, min_interval); break; default: /* not found */ @@ -473,13 +572,16 @@ static int set_mavlink_interval_limit(int mavlink_msg_id, int min_interval) */ static void *uorb_receiveloop(void *arg) { + /* obtain reference to task's subscriptions */ + struct mavlink_subscriptions *subs = (struct mavlink_subscriptions *)arg; + /* Set thread name */ - prctl(PR_SET_NAME, "mavlink uORB", getpid()); + prctl(PR_SET_NAME, "mavlink orb rcv", getpid()); /* --- IMPORTANT: DEFINE NUMBER OF ORB STRUCTS TO WAIT FOR HERE --- */ /* number of messages */ - const ssize_t fdsc = 15; + const ssize_t fdsc = 25; /* Sanity check variable and index */ ssize_t fdsc_count = 0; /* file descriptors to wait for */ @@ -490,44 +592,38 @@ static void *uorb_receiveloop(void *arg) struct sensor_combined_s raw; struct vehicle_attitude_s att; struct vehicle_gps_position_s gps; - struct ardrone_control_s ar_control; struct vehicle_local_position_setpoint_s local_sp; struct vehicle_global_position_setpoint_s global_sp; struct vehicle_attitude_setpoint_s att_sp; + struct actuator_outputs_s act_outputs; + struct manual_control_setpoint_s man_control; + struct actuator_controls_s actuators; + struct debug_key_value_s debug; } buf; /* --- SENSORS RAW VALUE --- */ /* subscribe to ORB for sensors raw */ - sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); - orb_set_interval(sensor_sub, 100); /* 10Hz updates */ - fds[fdsc_count].fd = sensor_sub; + subs->sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); + fds[fdsc_count].fd = subs->sensor_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; /* --- ATTITUDE VALUE --- */ /* subscribe to ORB for attitude */ - int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); - orb_set_interval(att_sub, 100); /* 10Hz updates */ - fds[fdsc_count].fd = att_sub; + subs->att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); + orb_set_interval(subs->att_sub, 100); + fds[fdsc_count].fd = subs->att_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; /* --- GPS VALUE --- */ /* subscribe to ORB for attitude */ - int gps_sub = orb_subscribe(ORB_ID(vehicle_gps_position)); - orb_set_interval(gps_sub, 1000); /* 1Hz updates */ - fds[fdsc_count].fd = gps_sub; + subs->gps_sub = orb_subscribe(ORB_ID(vehicle_gps_position)); + orb_set_interval(subs->gps_sub, 1000); /* 1Hz updates */ + fds[fdsc_count].fd = subs->gps_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; - // /* --- ARDRONE CONTROL --- */ - // /* subscribe to ORB for AR.Drone controller outputs */ - // int ar_sub = orb_subscribe(ORB_ID(ardrone_control)); - // orb_set_interval(ar_sub, 200); /* 5Hz updates */ - // fds[fdsc_count].fd = ar_sub; - // fds[fdsc_count].events = POLLIN; - // fdsc_count++; - /* --- SYSTEM STATE --- */ /* struct already globally allocated */ /* subscribe to topic */ @@ -546,54 +642,93 @@ static void *uorb_receiveloop(void *arg) fds[fdsc_count].events = POLLIN; fdsc_count++; - /* --- FIXED WING CONTROL VALUE --- */ - /* struct already globally allocated */ - /* subscribe to ORB for fixed wing control */ - int fw_sub = orb_subscribe(ORB_ID(fixedwing_control)); - orb_set_interval(fw_sub, 50); /* 20 Hz updates */ - fds[fdsc_count].fd = fw_sub; - fds[fdsc_count].events = POLLIN; - fdsc_count++; - /* --- GLOBAL POS VALUE --- */ /* struct already globally allocated and topic already subscribed */ - fds[fdsc_count].fd = global_pos_sub; + fds[fdsc_count].fd = subs->global_pos_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; /* --- LOCAL POS VALUE --- */ /* struct and topic already globally subscribed */ - fds[fdsc_count].fd = local_pos_sub; + fds[fdsc_count].fd = subs->local_pos_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; /* --- GLOBAL SETPOINT VALUE --- */ /* subscribe to ORB for local setpoint */ /* struct already allocated */ - int spg_sub = orb_subscribe(ORB_ID(vehicle_global_position_setpoint)); - orb_set_interval(spg_sub, 2000); /* 0.5 Hz updates */ - fds[fdsc_count].fd = spg_sub; + subs->spg_sub = orb_subscribe(ORB_ID(vehicle_global_position_setpoint)); + orb_set_interval(subs->spg_sub, 2000); /* 0.5 Hz updates */ + fds[fdsc_count].fd = subs->spg_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; /* --- LOCAL SETPOINT VALUE --- */ /* subscribe to ORB for local setpoint */ /* struct already allocated */ - int spl_sub = orb_subscribe(ORB_ID(vehicle_local_position_setpoint)); - orb_set_interval(spl_sub, 2000); /* 0.5 Hz updates */ - fds[fdsc_count].fd = spl_sub; + subs->spl_sub = orb_subscribe(ORB_ID(vehicle_local_position_setpoint)); + orb_set_interval(subs->spl_sub, 2000); /* 0.5 Hz updates */ + fds[fdsc_count].fd = subs->spl_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; /* --- ATTITUDE SETPOINT VALUE --- */ /* subscribe to ORB for attitude setpoint */ /* struct already allocated */ - int spa_sub = orb_subscribe(ORB_ID(vehicle_local_position_setpoint)); - orb_set_interval(spa_sub, 2000); /* 0.5 Hz updates */ - fds[fdsc_count].fd = spa_sub; + subs->spa_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint)); + orb_set_interval(subs->spa_sub, 2000); /* 0.5 Hz updates */ + fds[fdsc_count].fd = subs->spa_sub; fds[fdsc_count].events = POLLIN; fdsc_count++; + /** --- ACTUATOR OUTPUTS --- */ + subs->act_0_sub = orb_subscribe(ORB_ID(actuator_outputs_0)); + fds[fdsc_count].fd = subs->act_0_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + subs->act_1_sub = orb_subscribe(ORB_ID(actuator_outputs_1)); + fds[fdsc_count].fd = subs->act_1_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + subs->act_2_sub = orb_subscribe(ORB_ID(actuator_outputs_2)); + fds[fdsc_count].fd = subs->act_2_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + subs->act_3_sub = orb_subscribe(ORB_ID(actuator_outputs_3)); + fds[fdsc_count].fd = subs->act_3_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /** --- MAPPED MANUAL CONTROL INPUTS --- */ + subs->man_control_sp_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); + fds[fdsc_count].fd = subs->man_control_sp_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- ACTUATOR ARMED VALUE --- */ + /* subscribe to ORB for actuator armed */ + subs->armed_sub = orb_subscribe(ORB_ID(actuator_armed)); + fds[fdsc_count].fd = subs->armed_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- ACTUATOR CONTROL VALUE --- */ + /* subscribe to ORB for actuator control */ + subs->actuators_sub = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS); + fds[fdsc_count].fd = subs->actuators_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- DEBUG VALUE OUTPUT --- */ + /* subscribe to ORB for debug value outputs */ + subs->debug_key_value = orb_subscribe(ORB_ID(debug_key_value)); + fds[fdsc_count].fd = subs->debug_key_value; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* all subscriptions initialized, return success */ + subs->initialized = true; + unsigned int sensors_raw_counter = 0; unsigned int attitude_counter = 0; unsigned int gps_counter = 0; @@ -611,18 +746,24 @@ static void *uorb_receiveloop(void *arg) * set up poll to block for new data, * wait for a maximum of 1000 ms (1 second) */ - const int timeout = 5000; + const int timeout = 1000; - while (1) { - if (mavlink_exit_requested) break; + /* + * Last sensor loop time + * some outputs are better timestamped + * with this "global" reference. + */ + uint64_t last_sensor_timestamp = 0; + + while (!thread_should_exit) { int poll_ret = poll(fds, fdsc_count, timeout); /* handle the poll result */ if (poll_ret == 0) { - /* XXX this means none of our providers is giving us data - might be an error? */ + mavlink_missionlib_send_gcs_string("[mavlink] No telemetry data for 1 s"); } else if (poll_ret < 0) { - /* XXX this is seriously bad - should be an emergency */ + mavlink_missionlib_send_gcs_string("[mavlink] ERROR reading uORB data"); } else { int ifds = 0; @@ -631,14 +772,58 @@ static void *uorb_receiveloop(void *arg) if (fds[ifds++].revents & POLLIN) { /* copy sensors raw data into local buffer */ - orb_copy(ORB_ID(sensor_combined), sensor_sub, &buf.raw); + orb_copy(ORB_ID(sensor_combined), subs->sensor_sub, &buf.raw); + + last_sensor_timestamp = buf.raw.timestamp; /* send raw imu data */ - mavlink_msg_raw_imu_send(MAVLINK_COMM_0, buf.raw.timestamp, buf.raw.accelerometer_raw[0], buf.raw.accelerometer_raw[1], buf.raw.accelerometer_raw[2], buf.raw.gyro_raw[0], buf.raw.gyro_raw[1], buf.raw.gyro_raw[2], buf.raw.magnetometer_raw[0], buf.raw.magnetometer_raw[1], buf.raw.magnetometer_raw[2]); - /* send scaled imu data (m/s^2 accelerations scaled back to milli-g) */ - mavlink_msg_scaled_imu_send(MAVLINK_COMM_0, buf.raw.timestamp, buf.raw.accelerometer_m_s2[0] * 101.936799f, buf.raw.accelerometer_m_s2[1] * 101.936799f, buf.raw.accelerometer_m_s2[2] * 101.936799f, buf.raw.gyro_rad_s[0] * 1000, buf.raw.gyro_rad_s[1] * 1000, buf.raw.gyro_rad_s[2] * 1000, buf.raw.magnetometer_ga[0] * 1000, buf.raw.magnetometer_ga[1] * 1000, buf.raw.magnetometer_ga[2] * 1000); + // mavlink_msg_raw_imu_send(MAVLINK_COMM_0, last_sensor_timestamp, buf.raw.accelerometer_raw[0], + // buf.raw.accelerometer_raw[1], buf.raw.accelerometer_raw[2], buf.raw.gyro_raw[0], + // buf.raw.gyro_raw[1], buf.raw.gyro_raw[2], buf.raw.magnetometer_raw[0], + // buf.raw.magnetometer_raw[1], buf.raw.magnetometer_raw[2]); + + /* mark individual fields as changed */ + uint16_t fields_updated = 0; + static unsigned accel_counter = 0; + static unsigned gyro_counter = 0; + static unsigned mag_counter = 0; + static unsigned baro_counter = 0; + + if (accel_counter != buf.raw.accelerometer_counter) { + /* mark first three dimensions as changed */ + fields_updated |= (1 << 0) | (1 << 1) | (1 << 2); + accel_counter = buf.raw.accelerometer_counter; + } + + if (gyro_counter != buf.raw.gyro_counter) { + /* mark first three dimensions as changed */ + fields_updated |= (1 << 3) | (1 << 4) | (1 << 5); + gyro_counter = buf.raw.gyro_counter; + } + + if (mag_counter != buf.raw.magnetometer_counter) { + /* mark first three dimensions as changed */ + fields_updated |= (1 << 6) | (1 << 7) | (1 << 8); + mag_counter = buf.raw.magnetometer_counter; + } + + if (baro_counter != buf.raw.baro_counter) { + /* mark first three dimensions as changed */ + fields_updated |= (1 << 9) | (1 << 11) | (1 << 12); + baro_counter = buf.raw.baro_counter; + } + + mavlink_msg_highres_imu_send(MAVLINK_COMM_0, last_sensor_timestamp, + buf.raw.accelerometer_m_s2[0], buf.raw.accelerometer_m_s2[1], + buf.raw.accelerometer_m_s2[2], buf.raw.gyro_rad_s[0], + buf.raw.gyro_rad_s[1], buf.raw.gyro_rad_s[2], + buf.raw.magnetometer_ga[0], + buf.raw.magnetometer_ga[1],buf.raw.magnetometer_ga[2], + buf.raw.baro_pres_mbar, 0 /* no diff pressure yet */, + buf.raw.baro_alt_meter, buf.raw.baro_temp_celcius, + fields_updated); /* send pressure */ - mavlink_msg_scaled_pressure_send(MAVLINK_COMM_0, buf.raw.timestamp / 1000, buf.raw.baro_pres_mbar, buf.raw.baro_alt_meter, buf.raw.baro_temp_celcius * 100); + //mavlink_msg_scaled_pressure_send(MAVLINK_COMM_0, buf.raw.timestamp / 1000, buf.raw.baro_pres_mbar, buf.raw.baro_alt_meter, buf.raw.baro_temp_celcius * 100); sensors_raw_counter++; } @@ -647,10 +832,10 @@ static void *uorb_receiveloop(void *arg) if (fds[ifds++].revents & POLLIN) { /* copy attitude data into local buffer */ - orb_copy(ORB_ID(vehicle_attitude), att_sub, &buf.att); + orb_copy(ORB_ID(vehicle_attitude), subs->att_sub, &buf.att); /* send sensor values */ - mavlink_msg_attitude_send(MAVLINK_COMM_0, buf.att.timestamp / 1000, buf.att.roll, buf.att.pitch, buf.att.yaw, buf.att.rollspeed, buf.att.pitchspeed, buf.att.yawspeed); + mavlink_msg_attitude_send(MAVLINK_COMM_0, last_sensor_timestamp / 1000, buf.att.roll, buf.att.pitch, buf.att.yaw, buf.att.rollspeed, buf.att.pitchspeed, buf.att.yawspeed); attitude_counter++; } @@ -658,7 +843,7 @@ static void *uorb_receiveloop(void *arg) /* --- GPS VALUE --- */ if (fds[ifds++].revents & POLLIN) { /* copy gps data into local buffer */ - orb_copy(ORB_ID(vehicle_gps_position), gps_sub, &buf.gps); + orb_copy(ORB_ID(vehicle_gps_position), subs->gps_sub, &buf.gps); /* GPS position */ mavlink_msg_gps_raw_int_send(MAVLINK_COMM_0, buf.gps.timestamp, buf.gps.fix_type, buf.gps.lat, buf.gps.lon, buf.gps.alt, buf.gps.eph, buf.gps.epv, buf.gps.vel, buf.gps.cog, buf.gps.satellites_visible); @@ -669,40 +854,21 @@ static void *uorb_receiveloop(void *arg) gps_counter++; } - // /* --- ARDRONE CONTROL OUTPUTS --- */ - // if (fds[ifds++].revents & POLLIN) { - // /* copy ardrone control data into local buffer */ - // orb_copy(ORB_ID(ardrone_control), ar_sub, &buf.ar_control); - // uint64_t timestamp = buf.ar_control.timestamp; - // float setpoint_roll = buf.ar_control.setpoint_attitude[0]; - // float setpoint_pitch = buf.ar_control.setpoint_attitude[1]; - // float setpoint_yaw = buf.ar_control.setpoint_attitude[2]; - // float setpoint_thrust = buf.ar_control.setpoint_thrust_cast; - - // float control_roll = buf.ar_control.attitude_control_output[0]; - // float control_pitch = buf.ar_control.attitude_control_output[1]; - // float control_yaw = buf.ar_control.attitude_control_output[2]; - - // mavlink_msg_roll_pitch_yaw_thrust_setpoint_send(MAVLINK_COMM_0, timestamp / 1000, setpoint_roll, setpoint_pitch, setpoint_yaw, setpoint_thrust); - // mavlink_msg_named_value_float_send(MAVLINK_COMM_0, timestamp / 1000, "cl.roll", control_roll); - // mavlink_msg_named_value_float_send(MAVLINK_COMM_0, timestamp / 1000, "cl.pitch", control_pitch); - // mavlink_msg_named_value_float_send(MAVLINK_COMM_0, timestamp / 1000, "cl.yaw", control_yaw); - // } - /* --- SYSTEM STATUS --- */ if (fds[ifds++].revents & POLLIN) { /* immediately communicate state changes back to user */ orb_copy(ORB_ID(vehicle_status), status_sub, &v_status); + orb_copy(ORB_ID(actuator_armed), mavlink_subs.armed_sub, &armed); /* enable or disable HIL */ set_hil_on_off(v_status.flag_hil_enabled); /* translate the current syste state to mavlink state and mode */ uint8_t mavlink_state = 0; uint8_t mavlink_mode = 0; - get_mavlink_mode_and_state(&v_status, &mavlink_state, &mavlink_mode); + get_mavlink_mode_and_state(&v_status, &armed, &mavlink_state, &mavlink_mode); /* send heartbeat */ - mavlink_msg_heartbeat_send(chan, system_type, MAV_AUTOPILOT_GENERIC, mavlink_mode, v_status.state_machine, mavlink_state); + mavlink_msg_heartbeat_send(chan, mavlink_system.type, MAV_AUTOPILOT_PX4, mavlink_mode, v_status.state_machine, mavlink_state); } /* --- RC CHANNELS --- */ @@ -710,78 +876,14 @@ static void *uorb_receiveloop(void *arg) /* copy rc channels into local buffer */ orb_copy(ORB_ID(rc_channels), rc_sub, &rc); /* Channels are sent in MAVLink main loop at a fixed interval */ - // TODO decide where to send channels - } - - /* --- FIXED WING CONTROL CHANNELS --- */ - if (fds[ifds++].revents & POLLIN) { - /* copy fixed wing control into local buffer */ - orb_copy(ORB_ID(fixedwing_control), fw_sub, &fw_control); - /* send control output via MAVLink */ - mavlink_msg_roll_pitch_yaw_thrust_setpoint_send(MAVLINK_COMM_0, fw_control.timestamp / 1000, fw_control.attitude_control_output[0], - fw_control.attitude_control_output[1], fw_control.attitude_control_output[2], - fw_control.attitude_control_output[3]); - - /* Only send in HIL mode */ - if (v_status.flag_hil_enabled) { - /* Send the desired attitude from RC or from the autonomous controller */ - // XXX it should not depend on a RC setting, but on a system_state value - - float roll_ail, pitch_elev, throttle, yaw_rudd; - - if (rc.chan[rc.function[OVERRIDE]].scale < 2000) { - - //orb_copy(ORB_ID(fixedwing_control), fixed_wing_control_sub, &fixed_wing_control); - roll_ail = fw_control.attitude_control_output[ROLL]; - pitch_elev = fw_control.attitude_control_output[PITCH]; - throttle = fw_control.attitude_control_output[THROTTLE]; - yaw_rudd = fw_control.attitude_control_output[YAW]; - - } else { - - roll_ail = rc.chan[rc.function[ROLL]].scale; - pitch_elev = rc.chan[rc.function[PITCH]].scale; - throttle = rc.chan[rc.function[THROTTLE]].scale; - yaw_rudd = rc.chan[rc.function[YAW]].scale; - } - - /* hacked HIL implementation in order for the APM Planner to work - * (correct cmd: mavlink_msg_hil_controls_send()) - */ - - mavlink_msg_rc_channels_scaled_send(chan, - hrt_absolute_time(), - 0, // port 0 - roll_ail, - pitch_elev, - throttle, - yaw_rudd, - 0, - 0, - 0, - 0, - 1 /*rssi=1*/); - - /* correct command duplicate */ - mavlink_msg_hil_controls_send(chan, - hrt_absolute_time(), - roll_ail, - pitch_elev, - yaw_rudd, - throttle, - 0, - 0, - 0, - 0, - 32, /* HIL_MODE */ - 0); - } + mavlink_msg_rc_channels_raw_send(chan, rc.timestamp / 1000, 0, rc.chan[0].raw, rc.chan[1].raw, rc.chan[2].raw, rc.chan[3].raw, + rc.chan[4].raw, rc.chan[5].raw, rc.chan[6].raw, rc.chan[7].raw, rc.rssi); } /* --- VEHICLE GLOBAL POSITION --- */ if (fds[ifds++].revents & POLLIN) { /* copy global position data into local buffer */ - orb_copy(ORB_ID(vehicle_global_position), global_pos_sub, &global_pos); + orb_copy(ORB_ID(vehicle_global_position), subs->global_pos_sub, &global_pos); uint64_t timestamp = global_pos.timestamp; int32_t lat = global_pos.lat; int32_t lon = global_pos.lon; @@ -793,37 +895,207 @@ static void *uorb_receiveloop(void *arg) /* heading in degrees * 10, from 0 to 36.000) */ uint16_t hdg = (global_pos.hdg / M_PI_F) * (180.0f * 10.0f) + (180.0f * 10.0f); - mavlink_msg_global_position_int_send(MAVLINK_COMM_0, timestamp / 1000, lat, lon, alt, relative_alt, vx, vy, vz, hdg); + mavlink_msg_global_position_int_send(MAVLINK_COMM_0, timestamp / 1000, lat, lon, alt, + relative_alt, vx, vy, vz, hdg); } /* --- VEHICLE LOCAL POSITION --- */ if (fds[ifds++].revents & POLLIN) { /* copy local position data into local buffer */ - orb_copy(ORB_ID(vehicle_local_position), local_pos_sub, &local_pos); - mavlink_msg_local_position_ned_send(MAVLINK_COMM_0, local_pos.timestamp / 1000, local_pos.x, local_pos.y, local_pos.z, local_pos.vx, local_pos.vy, local_pos.vz); + orb_copy(ORB_ID(vehicle_local_position), subs->local_pos_sub, &local_pos); + mavlink_msg_local_position_ned_send(MAVLINK_COMM_0, local_pos.timestamp / 1000, local_pos.x, + local_pos.y, local_pos.z, local_pos.vx, local_pos.vy, local_pos.vz); } /* --- VEHICLE GLOBAL SETPOINT --- */ if (fds[ifds++].revents & POLLIN) { /* copy local position data into local buffer */ - orb_copy(ORB_ID(vehicle_global_position_setpoint), spg_sub, &buf.global_sp); + orb_copy(ORB_ID(vehicle_global_position_setpoint), subs->spg_sub, &buf.global_sp); uint8_t coordinate_frame = MAV_FRAME_GLOBAL; if (buf.global_sp.altitude_is_relative) coordinate_frame = MAV_FRAME_GLOBAL_RELATIVE_ALT; - mavlink_msg_global_position_setpoint_int_send(MAVLINK_COMM_0, coordinate_frame, buf.global_sp.lat, buf.global_sp.lon, buf.global_sp.altitude, buf.global_sp.yaw); + mavlink_msg_global_position_setpoint_int_send(MAVLINK_COMM_0, coordinate_frame, buf.global_sp.lat, + buf.global_sp.lon, buf.global_sp.altitude, buf.global_sp.yaw); } /* --- VEHICLE LOCAL SETPOINT --- */ if (fds[ifds++].revents & POLLIN) { /* copy local position data into local buffer */ - orb_copy(ORB_ID(vehicle_local_position_setpoint), spl_sub, &buf.local_sp); - mavlink_msg_local_position_setpoint_send(MAVLINK_COMM_0, MAV_FRAME_LOCAL_NED, buf.local_sp.x, buf.local_sp.y, buf.local_sp.z, buf.local_sp.yaw); + orb_copy(ORB_ID(vehicle_local_position_setpoint), subs->spl_sub, &buf.local_sp); + mavlink_msg_local_position_setpoint_send(MAVLINK_COMM_0, MAV_FRAME_LOCAL_NED, buf.local_sp.x, + buf.local_sp.y, buf.local_sp.z, buf.local_sp.yaw); } /* --- VEHICLE ATTITUDE SETPOINT --- */ if (fds[ifds++].revents & POLLIN) { /* copy local position data into local buffer */ - orb_copy(ORB_ID(vehicle_attitude_setpoint), spa_sub, &buf.att_sp); - mavlink_msg_roll_pitch_yaw_thrust_setpoint_send(MAVLINK_COMM_0, buf.att_sp.timestamp/1000, buf.att_sp.roll_tait_bryan, buf.att_sp.pitch_tait_bryan, buf.att_sp.yaw_tait_bryan, buf.att_sp.thrust); + orb_copy(ORB_ID(vehicle_attitude_setpoint), subs->spa_sub, &buf.att_sp); + mavlink_msg_roll_pitch_yaw_thrust_setpoint_send(MAVLINK_COMM_0, buf.att_sp.timestamp/1000, + buf.att_sp.roll_body, buf.att_sp.pitch_body, buf.att_sp.yaw_body, buf.att_sp.thrust); + + /* Only send in HIL mode */ + if (mavlink_hil_enabled) { + + /* translate the current syste state to mavlink state and mode */ + uint8_t mavlink_state = 0; + uint8_t mavlink_mode = 0; + get_mavlink_mode_and_state(&v_status, &armed, &mavlink_state, &mavlink_mode); + + /* HIL message as per MAVLink spec */ + mavlink_msg_hil_controls_send(chan, + hrt_absolute_time(), + buf.att_sp.roll_body, /* this may be replaced by ctrl0 later */ + buf.att_sp.pitch_body, + buf.att_sp.yaw_body, + buf.att_sp.thrust, + 0, + 0, + 0, + 0, + mavlink_mode, + 0); + } + } + + /* --- ACTUATOR OUTPUTS 0 --- */ + if (fds[ifds++].revents & POLLIN) { + /* copy actuator data into local buffer */ + orb_copy(ORB_ID(actuator_outputs_0), subs->act_0_sub, &buf.act_outputs); + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + 0 /* port 0 */, + buf.act_outputs.output[0], + buf.act_outputs.output[1], + buf.act_outputs.output[2], + buf.act_outputs.output[3], + buf.act_outputs.output[4], + buf.act_outputs.output[5], + buf.act_outputs.output[6], + buf.act_outputs.output[7]); + // if (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) { + // mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, hrt_absolute_time(), + // 1 /* port 1 */, + // buf.act_outputs.output[ 8], + // buf.act_outputs.output[ 9], + // buf.act_outputs.output[10], + // buf.act_outputs.output[11], + // buf.act_outputs.output[12], + // buf.act_outputs.output[13], + // buf.act_outputs.output[14], + // buf.act_outputs.output[15]); + // } + } + + /* --- ACTUATOR OUTPUTS 1 --- */ + if (fds[ifds++].revents & POLLIN) { + /* copy actuator data into local buffer */ + orb_copy(ORB_ID(actuator_outputs_1), subs->act_1_sub, &buf.act_outputs); + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) ? 2 : 1 /* port 2 or 1*/, + buf.act_outputs.output[0], + buf.act_outputs.output[1], + buf.act_outputs.output[2], + buf.act_outputs.output[3], + buf.act_outputs.output[4], + buf.act_outputs.output[5], + buf.act_outputs.output[6], + buf.act_outputs.output[7]); + if (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) { + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + 3 /* port 3 */, + buf.act_outputs.output[ 8], + buf.act_outputs.output[ 9], + buf.act_outputs.output[10], + buf.act_outputs.output[11], + buf.act_outputs.output[12], + buf.act_outputs.output[13], + buf.act_outputs.output[14], + buf.act_outputs.output[15]); + } + } + + /* --- ACTUATOR OUTPUTS 2 --- */ + if (fds[ifds++].revents & POLLIN) { + /* copy actuator data into local buffer */ + orb_copy(ORB_ID(actuator_outputs_2), subs->act_2_sub, &buf.act_outputs); + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) ? 4 : 2 /* port 4 or 2 */, + buf.act_outputs.output[0], + buf.act_outputs.output[1], + buf.act_outputs.output[2], + buf.act_outputs.output[3], + buf.act_outputs.output[4], + buf.act_outputs.output[5], + buf.act_outputs.output[6], + buf.act_outputs.output[7]); + if (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) { + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + 5 /* port 5 */, + buf.act_outputs.output[ 8], + buf.act_outputs.output[ 9], + buf.act_outputs.output[10], + buf.act_outputs.output[11], + buf.act_outputs.output[12], + buf.act_outputs.output[13], + buf.act_outputs.output[14], + buf.act_outputs.output[15]); + } + } + + /* --- ACTUATOR OUTPUTS 3 --- */ + if (fds[ifds++].revents & POLLIN) { + /* copy actuator data into local buffer */ + orb_copy(ORB_ID(actuator_outputs_3), subs->act_3_sub, &buf.act_outputs); + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) ? 6 : 3 /* port 6 or 3 */, + buf.act_outputs.output[0], + buf.act_outputs.output[1], + buf.act_outputs.output[2], + buf.act_outputs.output[3], + buf.act_outputs.output[4], + buf.act_outputs.output[5], + buf.act_outputs.output[6], + buf.act_outputs.output[7]); + if (NUM_ACTUATOR_OUTPUTS > 8 && NUM_ACTUATOR_OUTPUTS <= 16) { + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_0, last_sensor_timestamp/1000, + 7 /* port 7 */, + buf.act_outputs.output[ 8], + buf.act_outputs.output[ 9], + buf.act_outputs.output[10], + buf.act_outputs.output[11], + buf.act_outputs.output[12], + buf.act_outputs.output[13], + buf.act_outputs.output[14], + buf.act_outputs.output[15]); + } + } + + /* --- MAPPED MANUAL CONTROL INPUTS --- */ + if (fds[ifds++].revents & POLLIN) { + /* copy local position data into local buffer */ + orb_copy(ORB_ID(manual_control_setpoint), subs->man_control_sp_sub, &buf.man_control); + mavlink_msg_manual_control_send(MAVLINK_COMM_0, mavlink_system.sysid, buf.man_control.roll, + buf.man_control.pitch, buf.man_control.yaw, buf.man_control.throttle, 0); + } + + /* --- ACTUATOR ARMED --- */ + if (fds[ifds++].revents & POLLIN) { + } + + /* --- ACTUATOR CONTROL --- */ + if (fds[ifds++].revents & POLLIN) { + orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, subs->actuators_sub, &buf.actuators); + /* send, add spaces so that string buffer is at least 10 chars long */ + mavlink_msg_named_value_float_send(MAVLINK_COMM_0, last_sensor_timestamp / 1000, "ctrl0 ", buf.actuators.control[0]); + mavlink_msg_named_value_float_send(MAVLINK_COMM_0, last_sensor_timestamp / 1000, "ctrl1 ", buf.actuators.control[1]); + mavlink_msg_named_value_float_send(MAVLINK_COMM_0, last_sensor_timestamp / 1000, "ctrl2 ", buf.actuators.control[2]); + mavlink_msg_named_value_float_send(MAVLINK_COMM_0, last_sensor_timestamp / 1000, "ctrl3 ", buf.actuators.control[3]); + } + + /* --- DEBUG KEY/VALUE --- */ + if (fds[ifds++].revents & POLLIN) { + orb_copy(ORB_ID(debug_key_value), subs->debug_key_value, &buf.debug); + /* Enforce null termination */ + buf.debug.key[sizeof(buf.debug.key) - 1] = '\0'; + mavlink_msg_named_value_float_send(MAVLINK_COMM_0, last_sensor_timestamp / 1000, buf.debug.key, buf.debug.value); } } } @@ -871,20 +1143,17 @@ void handleMessage(mavlink_message_t *msg) mavlink_command_long_t cmd_mavlink; mavlink_msg_command_long_decode(msg, &cmd_mavlink); - if (cmd_mavlink.target_system == mavlink_system.sysid && ((cmd_mavlink.target_component == mavlink_system.compid) || (cmd_mavlink.target_component == MAV_COMP_ID_ALL))) { + if (cmd_mavlink.target_system == mavlink_system.sysid && ((cmd_mavlink.target_component == mavlink_system.compid) + || (cmd_mavlink.target_component == MAV_COMP_ID_ALL))) { //check for MAVLINK terminate command if (cmd_mavlink.command == MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN && ((int)cmd_mavlink.param1) == 3) { - /* This is the link shutdown command, terminate mavlink */ //TODO: check what happens with global_data buffers that are read by the mavlink app + /* This is the link shutdown command, terminate mavlink */ printf("[mavlink] Terminating .. \n"); fflush(stdout); usleep(50000); - /* terminate other threads */ - mavlink_exit_requested = true; - pthread_cancel(receive_thread); - pthread_cancel(uorb_receive_thread); - - pthread_exit(NULL); + /* terminate other threads and this thread */ + thread_should_exit = true; } else { @@ -967,26 +1236,36 @@ void handleMessage(mavlink_message_t *msg) /* Handle quadrotor motor setpoints */ - if (msg->msgid == MAVLINK_MSG_ID_SET_QUAD_MOTORS_SETPOINT) { - mavlink_set_quad_motors_setpoint_t quad_motors_setpoint; - mavlink_msg_set_quad_motors_setpoint_decode(msg, &quad_motors_setpoint); + if (msg->msgid == MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST) { + mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t quad_motors_setpoint; + mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_decode(msg, &quad_motors_setpoint); // printf("got MAVLINK_MSG_ID_SET_QUAD_MOTORS_SETPOINT target_system=%u, sysid = %u\n", quad_motors_setpoint.target_system, mavlink_system.sysid); - if (quad_motors_setpoint.target_system == mavlink_system.sysid) { - ardrone_motors.motor_front_nw = quad_motors_setpoint.motor_front_nw; - ardrone_motors.motor_right_ne = quad_motors_setpoint.motor_right_ne; - ardrone_motors.motor_back_se = quad_motors_setpoint.motor_back_se; - ardrone_motors.motor_left_sw = quad_motors_setpoint.motor_left_sw; + if (mavlink_system.sysid < 4) { + ardrone_motors.p1 = quad_motors_setpoint.roll[mavlink_system.sysid]; + ardrone_motors.p2 = quad_motors_setpoint.pitch[mavlink_system.sysid]; + ardrone_motors.p3 = quad_motors_setpoint.yaw[mavlink_system.sysid]; + ardrone_motors.p4 = quad_motors_setpoint.thrust[mavlink_system.sysid]; - ardrone_motors.counter++; ardrone_motors.timestamp = hrt_absolute_time(); - /* check if topic has to be advertised */ - if (ardrone_motors_pub <= 0) { - ardrone_motors_pub = orb_advertise(ORB_ID(ardrone_motors_setpoint), &ardrone_motors); + /* only send if RC is off */ + if (v_status.rc_signal_lost) { + /* check if input has to be enabled */ + if (!v_status.flag_control_offboard_enabled) { + /* XXX Enable offboard control */ + } + + /* XXX decode mode and set flags */ + // if (mode == abc) xxx flag_control_rates_enabled; + + /* check if topic has to be advertised */ + if (ardrone_motors_pub <= 0) { + ardrone_motors_pub = orb_advertise(ORB_ID(ardrone_motors_setpoint), &ardrone_motors); + } + /* Publish */ + orb_publish(ORB_ID(ardrone_motors_setpoint), ardrone_motors_pub, &ardrone_motors); } - /* Publish */ - orb_publish(ORB_ID(ardrone_motors_setpoint), ardrone_motors_pub, &ardrone_motors); } } @@ -1023,10 +1302,10 @@ void handleMessage(mavlink_message_t *msg) hil_global_pos.lat = hil_state.lat; hil_global_pos.lon = hil_state.lon; - hil_global_pos.alt = hil_state.alt/1000; - hil_global_pos.vx = hil_state.vx; - hil_global_pos.vy = hil_state.vy; - hil_global_pos.vz = hil_state.vz; + hil_global_pos.alt = hil_state.alt / 1000.0f; + hil_global_pos.vx = hil_state.vx / 100.0f; + hil_global_pos.vy = hil_state.vy / 100.0f; + hil_global_pos.vz = hil_state.vz / 100.0f; /* set timestamp and notify processes (broadcast) */ hil_global_pos.timestamp = hrt_absolute_time(); @@ -1045,71 +1324,56 @@ void handleMessage(mavlink_message_t *msg) orb_publish(ORB_ID(vehicle_attitude), pub_hil_attitude, &hil_attitude); } - // if (msg->msgid == MAVLINK_MSG_ID_ATTITUDE) { - // mavlink_attitude_t att; - // mavlink_msg_attitude_decode(msg, &att); - // float RAD2DEG = 57.3f; + if (msg->msgid == MAVLINK_MSG_ID_MANUAL_CONTROL) { + mavlink_manual_control_t man; + mavlink_msg_manual_control_decode(msg, &man); - // // printf("\n\n\n ATTITUDE \n\n\n %i \n", (int)(1000*att.rollspeed)); + struct rc_channels_s rc_hil; + memset(&rc_hil, 0, sizeof(rc_hil)); + static orb_advert_t rc_pub = 0; - // global_data_lock(&global_data_attitude->access_conf); - // global_data_attitude->roll = RAD2DEG * att.roll; - // global_data_attitude->pitch = RAD2DEG * att.pitch; - // global_data_attitude->yaw = RAD2DEG * att.yaw; - // global_data_attitude->rollspeed = att.rollspeed; - // global_data_attitude->pitchspeed = att.pitchspeed; - // global_data_attitude->yawspeed = att.yawspeed; + rc_hil.chan[0].raw = 1510 + man.x * 500; + rc_hil.chan[1].raw = 1520 + man.y * 500; + rc_hil.chan[2].raw = 1590 + man.r * 500; + rc_hil.chan[3].raw = 1420 + man.z * 500; - // global_data_attitude->counter++; - // global_data_attitude->timestamp = hrt_absolute_time(); - // global_data_unlock(&global_data_attitude->access_conf); - // global_data_broadcast(&global_data_attitude->access_conf); - // } + rc_hil.chan[0].scaled = man.x; + rc_hil.chan[1].scaled = man.y; + rc_hil.chan[2].scaled = man.r; + rc_hil.chan[3].scaled = man.z; - // if (msg->msgid == MAVLINK_MSG_ID_RAW_IMU) { - // mavlink_raw_imu_t imu; - // mavlink_msg_raw_imu_decode(msg, &imu); + struct manual_control_setpoint_s mc; + static orb_advert_t mc_pub = 0; - // // printf("\n\n\n RAW_IMU : %i \n %i \n %i \n %i \n %i \n %i \n\n\n", (int)(1000*imu.xgyro), - // // (int)(1000*imu.ygyro), (int)(1000*imu.zgyro)); + mc.roll = man.x; + mc.pitch = man.y; + mc.yaw = man.r; + mc.roll = man.z; - // global_data_lock(&global_data_attitude->access_conf); - // global_data_attitude->rollspeed = 1000 * imu.xgyro; - // global_data_attitude->pitchspeed = 1000 * imu.ygyro; - // global_data_attitude->yawspeed = 1000 * imu.zgyro; + /* fake RC channels with manual control input from simulator */ - // global_data_attitude->counter++; - // global_data_attitude->timestamp = hrt_absolute_time(); - // global_data_unlock(&global_data_attitude->access_conf); - // global_data_broadcast(&global_data_attitude->access_conf); - // } - // if (msg->msgid == MAVLINK_MSG_ID_SCALED_IMU) { - // mavlink_raw_imu_t imu; - // mavlink_msg_raw_imu_decode(msg, &imu); + if (rc_pub == 0) { + rc_pub = orb_advertise(ORB_ID(rc_channels), &rc_hil); + } else { + orb_publish(ORB_ID(rc_channels), rc_pub, &rc_hil); + } - // // printf("\n\n\n SCALED_IMU : %i \n %i \n %i \n %i \n %i \n %i \n\n\n", (int)(1000*imu.xgyro), - // // (int)(1000*imu.ygyro), (int)(1000*imu.zgyro)); - - // global_data_lock(&global_data_attitude->access_conf); - // global_data_attitude->rollspeed = 1000 * imu.xgyro; - // global_data_attitude->pitchspeed = 1000 * imu.ygyro; - // global_data_attitude->yawspeed = 1000 * imu.zgyro; - - // global_data_attitude->counter++; - // global_data_attitude->timestamp = hrt_absolute_time(); - // global_data_unlock(&global_data_attitude->access_conf); - // global_data_broadcast(&global_data_attitude->access_conf); - // } + if (mc_pub == 0) { + mc_pub = orb_advertise(ORB_ID(manual_control_setpoint), &mc); + } else { + orb_publish(ORB_ID(manual_control_setpoint), mc_pub, &mc); + } + } } } -int mavlink_open_uart(int baudrate, const char *uart_name, struct termios *uart_config_original, bool *is_usb) +int mavlink_open_uart(int baud, const char *uart_name, struct termios *uart_config_original, bool *is_usb) { /* process baud rate */ int speed; - switch (baudrate) { + switch (baud) { case 0: speed = B0; break; case 50: speed = B50; break; @@ -1153,12 +1417,12 @@ int mavlink_open_uart(int baudrate, const char *uart_name, struct termios *uart_ case 921600: speed = B921600; break; default: - fprintf(stderr, "[mavlink] ERROR: Unsupported baudrate: %d\n\tsupported examples:\n\n\t9600\n19200\n38400\n57600\n115200\n230400\n460800\n921600\n\n", baudrate); + fprintf(stderr, "[mavlink] ERROR: Unsupported baudrate: %d\n\tsupported examples:\n\n\t9600\n19200\n38400\n57600\n115200\n230400\n460800\n921600\n\n", baud); return -EINVAL; } /* open uart */ - printf("[mavlink] UART is %s, baudrate is %d\n", uart_name, baudrate); + printf("[mavlink] UART is %s, baudrate is %d\n", uart_name, baud); uart = open(uart_name, O_RDWR | O_NOCTTY); /* Try to set baud rate */ @@ -1215,7 +1479,6 @@ int mavlink_thread_main(int argc, char *argv[]) memset(&rc, 0, sizeof(rc)); memset(&hil_attitude, 0, sizeof(hil_attitude)); memset(&hil_global_pos, 0, sizeof(hil_global_pos)); - memset(&fw_control, 0, sizeof(fw_control)); memset(&ardrone_motors, 0, sizeof(ardrone_motors)); memset(&vcmd, 0, sizeof(vcmd)); @@ -1226,8 +1489,8 @@ int mavlink_thread_main(int argc, char *argv[]) register_driver(MAVLINK_LOG_DEVICE, &mavlink_fops, 0666, NULL); /* default values for arguments */ - char *uart_name = "/dev/ttyS0"; - int baudrate = 57600; + char *uart_name = "/dev/ttyS1"; + baudrate = 57600; /* read program arguments */ int i; @@ -1271,106 +1534,183 @@ int mavlink_thread_main(int argc, char *argv[]) if (uart < 0) { printf("[mavlink] FAILED to open %s, terminating.\n", uart_name); - return -1; + goto exit_cleanup; } /* Flush UART */ fflush(stdout); + /* Initialize system properties */ + param_t param_system_id = param_find("MAV_SYS_ID"); + param_t param_component_id = param_find("MAV_COMP_ID"); + param_t param_system_type = param_find("MAV_TYPE"); + /* topics to subscribe globally */ /* subscribe to ORB for global position */ - global_pos_sub = orb_subscribe(ORB_ID(vehicle_global_position)); - orb_set_interval(global_pos_sub, 1000); /* 1Hz active updates */ + mavlink_subs.global_pos_sub = orb_subscribe(ORB_ID(vehicle_global_position)); + orb_set_interval(mavlink_subs.global_pos_sub, 1000); /* 1Hz active updates */ /* subscribe to ORB for local position */ - local_pos_sub = orb_subscribe(ORB_ID(vehicle_local_position)); - orb_set_interval(local_pos_sub, 1000); /* 1Hz active updates */ + mavlink_subs.local_pos_sub = orb_subscribe(ORB_ID(vehicle_local_position)); + orb_set_interval(mavlink_subs.local_pos_sub, 1000); /* 1Hz active updates */ pthread_attr_t receiveloop_attr; pthread_attr_init(&receiveloop_attr); pthread_attr_setstacksize(&receiveloop_attr, 2048); - pthread_create(&receive_thread, &receiveloop_attr, receiveloop, NULL); + pthread_create(&receive_thread, &receiveloop_attr, receiveloop, &uart); pthread_attr_t uorb_attr; pthread_attr_init(&uorb_attr); - /* Set stack size, needs more than 4000 bytes */ - pthread_attr_setstacksize(&uorb_attr, 4096); - pthread_create(&uorb_receive_thread, &uorb_attr, uorb_receiveloop, NULL); + /* Set stack size, needs more than 8000 bytes */ + pthread_attr_setstacksize(&uorb_attr, 8192); + pthread_create(&uorb_receive_thread, &uorb_attr, uorb_receiveloop, &mavlink_subs); /* initialize waypoint manager */ mavlink_wpm_init(wpm); uint16_t counter = 0; - int lowspeed_counter = 0; - /* all subscriptions are now active, set up initial guess about rate limits */ - if (baudrate >= 921600) { - /* 1000 Hz / 1 ms */ - set_mavlink_interval_limit(MAVLINK_MSG_ID_SCALED_IMU, 1); - } else if (baudrate >= 460800) { - /* 250 Hz / 4 ms */ - set_mavlink_interval_limit(MAVLINK_MSG_ID_SCALED_IMU, 4); - } else if (baudrate >= 115200) { - /* 50 Hz / 20 ms */ - set_mavlink_interval_limit(MAVLINK_MSG_ID_SCALED_IMU, 20); - } else if (baudrate >= 57600) { - /* 10 Hz / 100 ms */ - set_mavlink_interval_limit(MAVLINK_MSG_ID_SCALED_IMU, 100); - } else { - /* very low baud rate, limit to 1 Hz / 1000 ms */ - set_mavlink_interval_limit(MAVLINK_MSG_ID_SCALED_IMU, 1000); + /* make sure all threads have registered their subscriptions */ + while (!mavlink_subs.initialized) { + usleep(500); } - while (1) { + /* all subscriptions are now active, set up initial guess about rate limits */ + if (baudrate >= 460800) { + /* 200 Hz / 5 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_HIGHRES_IMU, 5); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_RAW_IMU, 5); + /* 200 Hz / 5 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 5); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 5); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_ATTITUDE, 5); + /* 5 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 200); + } else if (baudrate >= 230400) { + /* 200 Hz / 5 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_HIGHRES_IMU, 20); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_RAW_IMU, 20); + /* 50 Hz / 20 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_ATTITUDE, 50); + /* 20 Hz / 50 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 50); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 50); + /* 2 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 100); + } else if (baudrate >= 115200) { + /* 50 Hz / 20 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_HIGHRES_IMU, 20); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_RAW_IMU, 20); + /* 20 Hz / 50 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_ATTITUDE, 20); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 50); + /* 10 Hz / 100 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 100); + /* 1 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 1000); + } else if (baudrate >= 57600) { + /* 10 Hz / 100 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_RAW_IMU, 100); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_HIGHRES_IMU, 100); + /* 10 Hz / 100 ms ATTITUDE */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_ATTITUDE, 100); + /* 5 Hz / 200 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 200); + /* 5 Hz / 200 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 200); + /* 2 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 500); + } else { + /* very low baud rate, limit to 1 Hz / 1000 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_RAW_IMU, 1000); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_ATTITUDE, 1000); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_HIGHRES_IMU, 1000); + /* 1 Hz / 1000 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 1000); + /* 0.5 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 2000); + /* 0.1 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 10000); + } - if (mavlink_exit_requested) break; + thread_running = true; + + /* arm counter to go off immediately */ + int lowspeed_counter = 10; + + while (!thread_should_exit) { /* get local and global position */ - orb_copy(ORB_ID(vehicle_global_position), global_pos_sub, &global_pos); - orb_copy(ORB_ID(vehicle_local_position), local_pos_sub, &local_pos); + orb_copy(ORB_ID(vehicle_global_position), mavlink_subs.global_pos_sub, &global_pos); + orb_copy(ORB_ID(vehicle_local_position), mavlink_subs.local_pos_sub, &local_pos); + orb_copy(ORB_ID(actuator_armed), mavlink_subs.armed_sub, &armed); - /* check if waypoint has been reached against the last positions */ - mavlink_waypoint_eventloop(mavlink_missionlib_get_system_timestamp(), &global_pos, &local_pos); - - // sleep - usleep(50000); - - // 1 Hz + /* 1 Hz */ if (lowspeed_counter == 10) { + /* update system and component id */ + int32_t system_id; + param_get(param_system_id, &system_id); + if (system_id > 0 && system_id < 255) { + mavlink_system.sysid = system_id; + } + + int32_t component_id; + param_get(param_component_id, &component_id); + if (component_id > 0 && component_id < 255) { + mavlink_system.compid = component_id; + } + + int32_t system_type; + param_get(param_system_type, &system_type); + if (system_type >= 0 && system_type < MAV_TYPE_ENUM_END) { + mavlink_system.type = system_type; + } + /* translate the current syste state to mavlink state and mode */ uint8_t mavlink_state = 0; uint8_t mavlink_mode = 0; - get_mavlink_mode_and_state(&v_status, &mavlink_state, &mavlink_mode); + get_mavlink_mode_and_state(&v_status, &armed, &mavlink_state, &mavlink_mode); /* send heartbeat */ - mavlink_msg_heartbeat_send(chan, system_type, MAV_AUTOPILOT_GENERIC, mavlink_mode, v_status.state_machine, mavlink_state); + mavlink_msg_heartbeat_send(chan, mavlink_system.type, MAV_AUTOPILOT_PX4, mavlink_mode, v_status.state_machine, mavlink_state); + + /* switch HIL mode if required */ + set_hil_on_off(v_status.flag_hil_enabled); /* send status (values already copied in the section above) */ mavlink_msg_sys_status_send(chan, v_status.onboard_control_sensors_present, v_status.onboard_control_sensors_enabled, v_status.onboard_control_sensors_health, v_status.load, v_status.voltage_battery * 1000.f, v_status.current_battery * 1000.f, v_status.battery_remaining, v_status.drop_rate_comm, v_status.errors_comm, v_status.errors_count1, v_status.errors_count2, v_status.errors_count3, v_status.errors_count4); - - /* send over MAVLink */ - if ((hrt_absolute_time() - rc.timestamp) < 200000) { - mavlink_msg_rc_channels_raw_send(chan, rc.timestamp / 1000, 0, rc.chan[0].raw, rc.chan[1].raw, rc.chan[2].raw, rc.chan[3].raw, - rc.chan[4].raw, rc.chan[5].raw, rc.chan[6].raw, rc.chan[7].raw, rc.rssi); - } - lowspeed_counter = 0; } - lowspeed_counter++; + /* sleep quarter the time */ + usleep(25000); + + /* check if waypoint has been reached against the last positions */ + mavlink_waypoint_eventloop(mavlink_missionlib_get_system_timestamp(), &global_pos, &local_pos); + + /* sleep quarter the time */ + usleep(25000); + /* send parameters at 20 Hz (if queued for sending) */ mavlink_pm_queued_send(); - usleep(50000); + /* sleep quarter the time */ + usleep(25000); mavlink_pm_queued_send(); + /* sleep 10 ms */ + usleep(10000); + /* send one string at 10 Hz */ mavlink_missionlib_send_gcs_string(mavlink_message_string); mavlink_message_string[0] = '\0'; counter++; + + /* sleep 15 ms */ + usleep(15000); } /* wait for threads to complete */ @@ -1388,9 +1728,15 @@ int mavlink_thread_main(int argc, char *argv[]) printf("[mavlink] Restored original UART config, exiting..\n"); } +exit_cleanup: + /* close uart */ close(uart); + /* close subscriptions */ + close(mavlink_subs.global_pos_sub); + close(mavlink_subs.local_pos_sub); + fflush(stdout); fflush(stderr); @@ -1422,8 +1768,7 @@ int mavlink_main(int argc, char *argv[]) } thread_should_exit = false; - mavlink_task = task_create("mavlink", SCHED_PRIORITY_DEFAULT, 4096, mavlink_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); - thread_running = true; + mavlink_task = task_create("mavlink", SCHED_PRIORITY_DEFAULT, 6000, mavlink_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); exit(0); } diff --git a/apps/mavlink/mavlink_parameters.c b/apps/mavlink/mavlink_parameters.c index a064fc1675..2e15174bb0 100644 --- a/apps/mavlink/mavlink_parameters.c +++ b/apps/mavlink/mavlink_parameters.c @@ -43,54 +43,199 @@ #include #include #include +#include #include #include +#include +#include +#include +#include extern mavlink_system_t mavlink_system; -extern void mavlink_missionlib_send_message(mavlink_message_t *msg); -extern void mavlink_missionlib_send_gcs_string(const char *string); +extern int mavlink_missionlib_send_message(mavlink_message_t *msg); +extern int mavlink_missionlib_send_gcs_string(const char *string); -/* send one parameter, assume lock on global_data_parameter_storage */ -void mavlink_pm_send_one_parameter(uint16_t next_param) +/** + * If the queue index is not at 0, the queue sending + * logic will send parameters from the current index + * to len - 1, the end of the param list. + */ +static unsigned int mavlink_param_queue_index = 0; + +/** + * Callback for param interface. + */ +void mavlink_pm_callback(void *arg, param_t param); + +/** + * Save parameters to EEPROM. + * + * Stores the parameters to /eeprom/parameters + */ +static int mavlink_pm_save_eeprom(void); + +/** + * Load parameters from EEPROM. + * + * Loads the parameters from /eeprom/parameters + */ +static int mavlink_pm_load_eeprom(void); + +void mavlink_pm_callback(void *arg, param_t param) { - if (next_param < global_data_parameter_storage->pm.size) { - static char name_buf[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN]; - mavlink_message_t tx_msg; + mavlink_pm_send_param(param); + usleep(*(unsigned int*)arg); +} - strncpy((char *)name_buf, global_data_parameter_storage->pm.param_names[next_param], MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN); +void mavlink_pm_send_all_params(unsigned int delay) +{ + unsigned int dbuf = delay; + param_foreach(&mavlink_pm_callback, &dbuf, false); +} - mavlink_msg_param_value_pack_chan(mavlink_system.sysid, - mavlink_system.compid, - MAVLINK_COMM_0, - &tx_msg, - name_buf, - global_data_parameter_storage->pm.param_values[next_param], - MAVLINK_TYPE_FLOAT, - global_data_parameter_storage->pm.size, - next_param); - mavlink_missionlib_send_message(&tx_msg); - - - // mavlink_msg_param_value_send(MAVLINK_COMM_0, - // name_buf, - // global_data_parameter_storage->pm.param_values[next_param], - // MAVLINK_TYPE_FLOAT, - // global_data_parameter_storage->pm.size, - // next_param); +int mavlink_pm_queued_send() +{ + if (mavlink_param_queue_index < param_count()) { + mavlink_pm_send_param(param_for_index(mavlink_param_queue_index)); + mavlink_param_queue_index++; + return 0; + } else { + return 1; } } +void mavlink_pm_start_queued_send() +{ + mavlink_param_queue_index = 0; +} + +int mavlink_pm_send_param_for_index(uint16_t index) +{ + return mavlink_pm_send_param(param_for_index(index)); +} + +int mavlink_pm_send_param_for_name(const char* name) +{ + return mavlink_pm_send_param(param_find(name)); +} + +int mavlink_pm_send_param(param_t param) +{ + if (param == PARAM_INVALID) return 1; + + /* buffers for param transmission */ + static char name_buf[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN]; + float val_buf; + static mavlink_message_t tx_msg; + + /* query parameter type */ + param_type_t type = param_type(param); + /* copy parameter name */ + strncpy((char *)name_buf, param_name(param), MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN); + + /* + * Map onboard parameter type to MAVLink type, + * endianess matches (both little endian) + */ + uint8_t mavlink_type; + if (type == PARAM_TYPE_INT32) { + mavlink_type = MAVLINK_TYPE_INT32_T; + } else if (type == PARAM_TYPE_FLOAT) { + mavlink_type = MAVLINK_TYPE_FLOAT; + } else { + mavlink_type = MAVLINK_TYPE_FLOAT; + } + + /* + * get param value, since MAVLink encodes float and int params in the same + * space during transmission, copy param onto float val_buf + */ + + int ret; + if ((ret = param_get(param, &val_buf)) != OK) return ret; + + mavlink_msg_param_value_pack_chan(mavlink_system.sysid, + mavlink_system.compid, + MAVLINK_COMM_0, + &tx_msg, + name_buf, + val_buf, + mavlink_type, + param_count(), + param_get_index(param)); + ret = mavlink_missionlib_send_message(&tx_msg); + return ret; +} + +static const char *mavlink_parameter_file = "/eeprom/parameters"; + +/** + * @return 0 on success, -1 if device open failed, -2 if writing parameters failed + */ +static int mavlink_pm_save_eeprom() +{ + /* delete the file in case it exists */ + unlink(mavlink_parameter_file); + + /* create the file */ + int fd = open(mavlink_parameter_file, O_WRONLY | O_CREAT | O_EXCL); + + if (fd < 0) { + warn("opening '%s' for writing failed", mavlink_parameter_file); + return -1; + } + + int result = param_export(fd, false); + close(fd); + + if (result != 0) { + unlink(mavlink_parameter_file); + warn("error exporting parameters to '%s'", mavlink_parameter_file); + return -2; + } + + return 0; +} + +/** + * @return 0 on success, 1 if all params have not yet been stored, -1 if device open failed, -2 if writing parameters failed + */ +static int +mavlink_pm_load_eeprom() +{ + int fd = open(mavlink_parameter_file, O_RDONLY); + + if (fd < 0) { + /* no parameter file is OK, otherwise this is an error */ + if (errno != ENOENT) { + warn("open '%s' for reading failed", mavlink_parameter_file); + return -1; + } + return 1; + } + + int result = param_load(fd); + close(fd); + + if (result != 0) { + warn("error reading parameters from '%s'", mavlink_parameter_file); + return -2; + } + + return 0; +} + void mavlink_pm_message_handler(const mavlink_channel_t chan, const mavlink_message_t *msg) { switch (msg->msgid) { - case MAVLINK_MSG_ID_PARAM_REQUEST_LIST: { + case MAVLINK_MSG_ID_PARAM_REQUEST_LIST: { /* Start sending parameters */ - global_data_parameter_storage->pm.next_param = 0; - mavlink_missionlib_send_gcs_string("[pm] sending list"); + mavlink_pm_start_queued_send(); + mavlink_missionlib_send_gcs_string("[mavlink pm] sending list"); } break; - case MAVLINK_MSG_ID_PARAM_SET: { + case MAVLINK_MSG_ID_PARAM_SET: { /* Handle parameter setting */ @@ -99,91 +244,109 @@ void mavlink_pm_message_handler(const mavlink_channel_t chan, const mavlink_mess mavlink_msg_param_set_decode(msg, &mavlink_param_set); if (mavlink_param_set.target_system == mavlink_system.sysid && ((mavlink_param_set.target_component == mavlink_system.compid) || (mavlink_param_set.target_component == MAV_COMP_ID_ALL))) { + /* local name buffer to enforce null-terminated string */ + char name[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN+1]; + strncpy(name, mavlink_param_set.param_id, MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN); + /* enforce null termination */ + name[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN] = '\0'; + /* attempt to find parameter, set and send it */ + param_t param = param_find(name); - uint16_t i; //parameters - uint16_t j; //chars - bool match; - - for (i = 0; i < PARAM_MAX_COUNT; i++) { - match = true; - - for (j = 0; j < MAX_PARAM_NAME_LEN; j++) { - /* Compare char by char */ - if (global_data_parameter_storage->pm.param_names[i][j] != mavlink_param_set.param_id[j]) { - match = false; - } - - /* End matching if null termination is reached */ - if (global_data_parameter_storage->pm.param_names[i][j] == '\0') { - break; - } - } - - /* Check if matched */ - if (match) { - // XXX handle param type as well, assuming float here - global_data_parameter_storage->pm.param_values[i] = mavlink_param_set.param_value; - mavlink_pm_send_one_parameter(i); - } + if (param == PARAM_INVALID) { + char buf[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN]; + sprintf(buf, "[mavlink pm] unknown: %s", name); + mavlink_missionlib_send_gcs_string(buf); + } else { + /* set and send parameter */ + param_set(param, &(mavlink_param_set.param_value)); + mavlink_pm_send_param(param); } } } } break; - case MAVLINK_MSG_ID_PARAM_REQUEST_READ: { + case MAVLINK_MSG_ID_PARAM_REQUEST_READ: { mavlink_param_request_read_t mavlink_param_request_read; mavlink_msg_param_request_read_decode(msg, &mavlink_param_request_read); - if (mavlink_param_request_read.target_system == mavlink_system.sysid && ((mavlink_param_request_read.target_component == mavlink_system.compid) || (mavlink_param_request_read.target_component == MAV_COMP_ID_ALL))) { - /* when no index is given, loop through string ids and compare them */ - if (mavlink_param_request_read.param_index == -1) { - - uint16_t i; //parameters - uint16_t j; //chars - bool match; - - for (i = 0; i < PARAM_MAX_COUNT; i++) { - match = true; - - for (j = 0; j < MAX_PARAM_NAME_LEN; j++) { - /* Compare char by char */ - if (global_data_parameter_storage->pm.param_names[i][j] != mavlink_param_request_read.param_id[j]) { - match = false; - } - - /* End matching if null termination is reached */ - if (global_data_parameter_storage->pm.param_names[i][j] == '\0') { - break; - } - } - - /* Check if matched */ - if (match) { - mavlink_pm_send_one_parameter(i); - } + if (mavlink_param_request_read.target_system == mavlink_system.sysid && ((mavlink_param_request_read.target_component == mavlink_system.compid) || (mavlink_param_request_read.target_component == MAV_COMP_ID_ALL))) { + /* when no index is given, loop through string ids and compare them */ + if (mavlink_param_request_read.param_index == -1) { + /* local name buffer to enforce null-terminated string */ + char name[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN+1]; + strncpy(name, mavlink_param_request_read.param_id, MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN); + /* enforce null termination */ + name[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN] = '\0'; + /* attempt to find parameter and send it */ + mavlink_pm_send_param_for_name(name); + } else { + /* when index is >= 0, send this parameter again */ + mavlink_pm_send_param_for_index(mavlink_param_request_read.param_index); } + } - } else { - /* when index is >= 0, send this parameter again */ - mavlink_pm_send_one_parameter(mavlink_param_request_read.param_index); + } break; + + case MAVLINK_MSG_ID_COMMAND_LONG: { + mavlink_command_long_t cmd_mavlink; + mavlink_msg_command_long_decode(msg, &cmd_mavlink); + + uint8_t result = MAV_RESULT_UNSUPPORTED; + + if (cmd_mavlink.target_system == mavlink_system.sysid && + ((cmd_mavlink.target_component == mavlink_system.compid) ||(cmd_mavlink.target_component == MAV_COMP_ID_ALL))) { + + /* preflight parameter load / store */ + if (cmd_mavlink.command == MAV_CMD_PREFLIGHT_STORAGE) { + /* Read all parameters from EEPROM to RAM */ + + if (((int)(cmd_mavlink.param1)) == 0) { + + /* read all parameters from EEPROM to RAM */ + int read_ret = mavlink_pm_load_eeprom(); + if (read_ret == OK) { + //printf("[mavlink pm] Loaded EEPROM params in RAM\n"); + mavlink_missionlib_send_gcs_string("[mavlink pm] OK loaded EEPROM params"); + result = MAV_RESULT_ACCEPTED; + } else if (read_ret == 1) { + mavlink_missionlib_send_gcs_string("[mavlink pm] No stored parameters to load"); + result = MAV_RESULT_ACCEPTED; + } else { + if (read_ret < -1) { + mavlink_missionlib_send_gcs_string("[mavlink pm] ERR loading params from EEPROM"); + } else { + mavlink_missionlib_send_gcs_string("[mavlink pm] ERR loading params, no EEPROM found"); + } + result = MAV_RESULT_FAILED; + } + + } else if (((int)(cmd_mavlink.param1)) == 1) { + + /* write all parameters from RAM to EEPROM */ + int write_ret = mavlink_pm_save_eeprom(); + if (write_ret == OK) { + mavlink_missionlib_send_gcs_string("[mavlink pm] OK params written to EEPROM"); + result = MAV_RESULT_ACCEPTED; + + } else { + if (write_ret < -1) { + mavlink_missionlib_send_gcs_string("[mavlink pm] ERR writing params to EEPROM"); + } else { + mavlink_missionlib_send_gcs_string("[mavlink pm] ERR writing params, no EEPROM found"); + } + result = MAV_RESULT_FAILED; + } + + } else { + //fprintf(stderr, "[mavlink pm] refusing unsupported storage request\n"); + mavlink_missionlib_send_gcs_string("[mavlink pm] refusing unsupported STOR request"); + result = MAV_RESULT_UNSUPPORTED; + } } } + /* send back command result */ + //mavlink_msg_command_ack_send(chan, cmd.command, result); } break; } } - - -/** - * Send low-priority messages at a maximum rate of xx Hertz. - * - * This function sends messages at a lower rate to not exceed the wireless - * bandwidth. It sends one message each time it is called until the buffer is empty. - * Call this function with xx Hertz to increase/decrease the bandwidth. - */ -void mavlink_pm_queued_send(void) -{ - //send parameters one by one: - mavlink_pm_send_one_parameter(global_data_parameter_storage->pm.next_param); - global_data_parameter_storage->pm.next_param++; -} diff --git a/apps/mavlink/mavlink_parameters.h b/apps/mavlink/mavlink_parameters.h index e32732f581..950f82d2de 100644 --- a/apps/mavlink/mavlink_parameters.h +++ b/apps/mavlink/mavlink_parameters.h @@ -1,7 +1,7 @@ /**************************************************************************** * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Lorenz Meier + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,6 +43,60 @@ #include "v1.0/common/mavlink.h" #include +#include +/** + * Handle parameter related messages. + */ void mavlink_pm_message_handler(const mavlink_channel_t chan, const mavlink_message_t *msg); -void mavlink_pm_queued_send(void); + +/** + * Send all parameters at once. + * + * This function blocks until all parameters have been sent. + * it delays each parameter by the passed amount of microseconds. + * + * @param delay The delay in us between sending all parameters. + */ +void mavlink_pm_send_all_params(unsigned int delay); + +/** + * Send one parameter. + * + * @param param The parameter id to send. + * @return zero on success, nonzero on failure. + */ +int mavlink_pm_send_param(param_t param); + +/** + * Send one parameter identified by index. + * + * @param index The index of the parameter to send. + * @return zero on success, nonzero else. + */ +int mavlink_pm_send_param_for_index(uint16_t index); + +/** + * Send one parameter identified by name. + * + * @param name The index of the parameter to send. + * @return zero on success, nonzero else. + */ +int mavlink_pm_send_param_for_name(const char* name); + +/** + * Send a queue of parameters, one parameter per function call. + * + * @return zero on success, nonzero on failure + */ + int mavlink_pm_queued_send(void); + +/** + * Start sending the parameter queue. + * + * This function will not directly send parameters, but instead + * activate the sending of one parameter on each call of + * mavlink_pm_queued_send(). + * @see mavlink_pm_queued_send() + */ +void mavlink_pm_start_queued_send(void); diff --git a/apps/mix_and_link/mix_and_link.c b/apps/mix_and_link/mix_and_link.c deleted file mode 100644 index 495f336b19..0000000000 --- a/apps/mix_and_link/mix_and_link.c +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Nils Wenzler - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file Mixing / linking of RC channels - */ - -#include -#include -#include - -#include "mix_and_link.h" - -/* - * Library function that mixes the abstract functions like ROLL, PITCH, THROTTLE - * to one or several actuators. - * @param *mixers is a pointer to the configuration struct, declared in mix_and_link.h - * @param nr_mixers is a integer that denotes the number of mixers that should be processed - * @param nr_actuators is a integer that denotes the max number of actuators that get linked to one source - * @param *data is a pointer to the mixer data struct, declared in mix_and_link.h - */ -void mix_and_link(const mixer_conf_t *mixers, uint8_t nr_mixers, uint8_t nr_actuators, mixer_data_t *data) -{ - - /* Reset the Output Array */ - uint8_t i, j; - - for (i = 0; i < nr_actuators; i++) { - data->output[i] = 0; - } - - /* Loop throug the given mixers */ - for (i = 0; i < nr_mixers; i++) { - - /* The actual mixing */ - for (j = 0; j < mixers[i].nr_actuators; j++) { - data->output[mixers[i].dest[j]] += (int16_t)(data->input[mixers[i].source] - * mixers[i].dual_rate[j]); - - /* Saturate to +-10000 */ - if (data->output[mixers[i].dest[j]] > 10000) - data->output[mixers[i].dest[j]] = 10000; - else if (data->output[mixers[i].dest[j]] < -10000) - data->output[mixers[i].dest[j]] = -10000; - - } - } -} - - diff --git a/apps/mix_and_link/mix_and_link.h b/apps/mix_and_link/mix_and_link.h deleted file mode 100644 index 0a374fd855..0000000000 --- a/apps/mix_and_link/mix_and_link.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Nils Wenzler - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - - -#ifndef _MIX_AND_LINK_H_ -#define _MIX_AND_LINK_H_ - -#include -#include -#include - -/**< The maximum number of actuators that get linked to one abstract function*/ -#define NR_MAX_ACTUATORS 2 - -/** - * The struct mixer_conf_t contains all the necessary information for one mixer. - * Make an array of type mixer_conf_t for several mix functions. - */ -typedef struct { - uint8_t source; /**< source RC channel index 0..n */ - uint8_t nr_actuators; /**< number of actuators to output to */ - uint8_t dest[NR_MAX_ACTUATORS]; /**< Which actuators to output to */ - float dual_rate[NR_MAX_ACTUATORS]; /**< Direction and rate of mixing. Range [-1,1] */ -} mixer_conf_t; /**< Setup for one mixer */ - -/* - * The struct mixer_data contains two int16_t arrays with the abstract source functions - * (Throttle, Roll,...) in the input, and an empty array output of the desired - * size for the results. - */ -typedef struct { - int16_t *input; - int16_t *output; -} mixer_data_t; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* - * Mixes the functions to the actuators. - * e.g. Throttle, Roll,... - * - * Each mixer_conf struct in the mixers array contains the source function (ex. THROTTLE), the number - * of actuators, an array with the desired actuators, Dual Rate determines which - * percentage of the source gets mixed to the destination and sets the direction. - * It's range is between -1 and 1. - * - * EXAMPLE: Deltamix for a wing plane: - * - * mixer_data_t mixer_buffer; - * mixer_buffer.input = buffer_rc; - * mixer_buffer.output = buffer_servo; - * - * - * mixer_conf_t mixers[3]; - * - * mixers[0].source = PITCH; - * mixers[0].nr_actuators = 2; - * mixers[0].dest[0] = AIL_1; - * mixers[0].dest[1] = AIL_2; - * mixers[0].dual_rate[0] = 1; - * mixers[0].dual_rate[1] = 1; - * - * mixers[1].source = ROLL; - * mixers[1].nr_actuators = 2; - * mixers[1].dest[0] = AIL_1; - * mixers[1].dest[1] = AIL_2; - * mixers[1].dual_rate[0] = 1; - * mixers[1].dual_rate[0] = -1; - * - * mixers[2].source = THROTTLE; - * mixers[2].nr_actuators = 1; - * mixers[2].dest[0] = MOT; - * mixers[2].dual_rate[0] = 1; - * - * @param mixers pointer to the mixer struct array - * @param nr_mixers number of mixers in struct array - * @param nr_actuators number of actuators - * @param data pointer to the mixer_data struct. - */ -void mix_and_link(const mixer_conf_t *mixers, uint8_t nr_mixers, uint8_t nr_actuators, mixer_data_t *data); - -#endif diff --git a/apps/multirotor_control/Makefile b/apps/multirotor_att_control/Makefile similarity index 91% rename from apps/multirotor_control/Makefile rename to apps/multirotor_att_control/Makefile index 7ae1d472a3..03cf33e434 100644 --- a/apps/multirotor_control/Makefile +++ b/apps/multirotor_att_control/Makefile @@ -35,11 +35,8 @@ # Makefile to build uORB # -APPNAME = multirotor_control +APPNAME = multirotor_att_control PRIORITY = SCHED_PRIORITY_MAX - 15 STACKSIZE = 2048 -# explicit list of sources - not everything is built currently -CSRCS = multirotor_control.c multirotor_attitude_control.c pid.c - include $(APPDIR)/mk/app.mk diff --git a/apps/multirotor_att_control/multirotor_att_control_main.c b/apps/multirotor_att_control/multirotor_att_control_main.c new file mode 100644 index 0000000000..5300337015 --- /dev/null +++ b/apps/multirotor_att_control/multirotor_att_control_main.c @@ -0,0 +1,280 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file multirotor_att_control_main.c + * + * Implementation of multirotor attitude control main loop. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "multirotor_attitude_control.h" + +__EXPORT int multirotor_att_control_main(int argc, char *argv[]); + + +static enum { + CONTROL_MODE_RATES = 0, + CONTROL_MODE_ATTITUDE = 1, +} control_mode; + + +static bool thread_should_exit; +static int mc_task; +static bool motor_test_mode = false; + +static int +mc_thread_main(int argc, char *argv[]) +{ + /* declare and safely initialize all structs */ + struct vehicle_status_s state; + memset(&state, 0, sizeof(state)); + struct vehicle_attitude_s att; + memset(&att, 0, sizeof(att)); + struct vehicle_attitude_setpoint_s att_sp; + memset(&att_sp, 0, sizeof(att_sp)); + struct manual_control_setpoint_s manual; + memset(&manual, 0, sizeof(manual)); + struct sensor_combined_s raw; + memset(&raw, 0, sizeof(raw)); + struct ardrone_motors_setpoint_s setpoint; + memset(&setpoint, 0, sizeof(setpoint)); + + struct actuator_controls_s actuators; + + /* subscribe to attitude, motor setpoints and system state */ + int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); + int att_setpoint_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint)); + int state_sub = orb_subscribe(ORB_ID(vehicle_status)); + int manual_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); + int sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); + int setpoint_sub = orb_subscribe(ORB_ID(ardrone_motors_setpoint)); + + /* + * Do not rate-limit the loop to prevent aliasing + * if rate-limiting would be desired later, the line below would + * enable it. + * + * rate-limit the attitude subscription to 200Hz to pace our loop + * orb_set_interval(att_sub, 5); + */ + struct pollfd fds = { .fd = att_sub, .events = POLLIN }; + + /* publish actuator controls */ + for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++) { + actuators.control[i] = 0.0f; + } + + orb_advert_t actuator_pub = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &actuators); + orb_advert_t att_sp_pub = orb_advertise(ORB_ID(vehicle_attitude_setpoint), &att_sp); + + /* register the perf counter */ + perf_counter_t mc_loop_perf = perf_alloc(PC_ELAPSED, "multirotor_att_control"); + + /* welcome user */ + printf("[multirotor_att_control] starting\n"); + + while (!thread_should_exit) { + + /* wait for a sensor update, check for exit condition every 500 ms */ + poll(&fds, 1, 500); + + perf_begin(mc_loop_perf); + + /* get a local copy of system state */ + orb_copy(ORB_ID(vehicle_status), state_sub, &state); + /* get a local copy of manual setpoint */ + orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual); + /* get a local copy of attitude */ + orb_copy(ORB_ID(vehicle_attitude), att_sub, &att); + /* get a local copy of attitude setpoint */ + orb_copy(ORB_ID(vehicle_attitude_setpoint), att_setpoint_sub, &att_sp); + /* get a local copy of the current sensor values */ + orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw); + + + /** STEP 1: Define which input is the dominating control input */ + + if (state.flag_control_manual_enabled) { + /* manual inputs, from RC control or joystick */ + att_sp.roll_body = manual.roll; + att_sp.pitch_body = manual.pitch; + att_sp.yaw_rate_body = manual.yaw; + att_sp.timestamp = hrt_absolute_time(); + + if (motor_test_mode) { + att_sp.roll_body = 0.0f; + att_sp.pitch_body = 0.0f; + att_sp.yaw_body = 0.0f; + att_sp.roll_rate_body = 0.0f; + att_sp.pitch_rate_body = 0.0f; + att_sp.yaw_rate_body = 0.0f; + att_sp.thrust = 0.1f; + } else { + att_sp.thrust = manual.throttle; + } + } else if (state.flag_control_offboard_enabled) { + /* offboard inputs */ + + /* decide wether we want rate or position input */ + } + + /** STEP 2: Identify the controller setup to run and set up the inputs correctly */ + + /* run attitude controller */ + if (state.flag_control_attitude_enabled) { + multirotor_control_attitude(&att_sp, &att, &actuators); + } + + /* XXX could be also run in an independent loop */ + if (state.flag_control_rates_enabled) { + multirotor_control_rates(&att_sp, &raw.gyro_rad_s, &actuators); + } + + /* STEP 3: publish the result to the vehicle actuators */ + orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators); + orb_publish(ORB_ID(vehicle_attitude_setpoint), att_sp_pub, &att_sp); + + perf_end(mc_loop_perf); + } + + printf("[multirotor att control] stopping, disarming motors.\n"); + + /* kill all outputs */ + for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++) + actuators.control[i] = 0.0f; + orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators); + + + close(att_sub); + close(state_sub); + close(manual_sub); + close(actuator_pub); + close(att_sp_pub); + + perf_print_counter(mc_loop_perf); + perf_free(mc_loop_perf); + + fflush(stdout); + exit(0); +} + +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: multirotor_att_control [-m ] [-t] {start|status|stop}\n"); + fprintf(stderr, " is 'rates' or 'attitude'\n"); + fprintf(stderr, " -t enables motor test mode with 10%% thrust\n"); + exit(1); +} + +int multirotor_att_control_main(int argc, char *argv[]) +{ + int ch; + + control_mode = CONTROL_MODE_RATES; + unsigned int optioncount = 0; + + while ((ch = getopt(argc, argv, "tm:")) != EOF) { + switch (ch) { + case 'm': + if (!strcmp(optarg, "rates")) { + control_mode = CONTROL_MODE_RATES; + } else if (!strcmp(optarg, "attitude")) { + control_mode = CONTROL_MODE_RATES; + } else { + usage("unrecognized -m value"); + } + optioncount += 2; + break; + case 't': + motor_test_mode = true; + optioncount += 1; + break; + case ':': + usage("missing parameter"); + break; + default: + fprintf(stderr, "option: -%c\n", ch); + usage("unrecognized option"); + } + } + argc -= optioncount; + //argv += optioncount; + + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1+optioncount], "start")) { + + thread_should_exit = false; + mc_task = task_create("multirotor_att_control", SCHED_PRIORITY_MAX - 15, 2048, mc_thread_main, NULL); + exit(0); + } + + if (!strcmp(argv[1+optioncount], "stop")) { + thread_should_exit = true; + exit(0); + } + + usage("unrecognized command"); + exit(1); +} diff --git a/apps/multirotor_att_control/multirotor_attitude_control.c b/apps/multirotor_att_control/multirotor_attitude_control.c new file mode 100644 index 0000000000..997aa0c108 --- /dev/null +++ b/apps/multirotor_att_control/multirotor_attitude_control.c @@ -0,0 +1,314 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Thomas Gubler + * @author Julian Oes + * @author Laurens Mackay + * @author Tobias Naegeli + * @author Martin Rutschmann + * @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* + * @file multirotor_attitude_control.c + * Implementation of attitude controller + */ + +#include "multirotor_attitude_control.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// PARAM_DEFINE_FLOAT(MC_YAWPOS_P, 0.3f); +// PARAM_DEFINE_FLOAT(MC_YAWPOS_I, 0.15f); +// PARAM_DEFINE_FLOAT(MC_YAWPOS_D, 0.0f); +// PARAM_DEFINE_FLOAT(MC_YAWPOS_AWU, 1.0f); +// PARAM_DEFINE_FLOAT(MC_YAWPOS_LIM, 3.0f); + +PARAM_DEFINE_FLOAT(MC_YAWRATE_P, 0.08f); /* same on Flamewheel */ +PARAM_DEFINE_FLOAT(MC_YAWRATE_I, 0.02f); +PARAM_DEFINE_FLOAT(MC_YAWRATE_D, 0.0f); +PARAM_DEFINE_FLOAT(MC_YAWRATE_AWU, 0.02f); +PARAM_DEFINE_FLOAT(MC_YAWRATE_LIM, 0.1f); + +PARAM_DEFINE_FLOAT(MC_ATT_P, 0.2f); /* 0.15 F405 Flamewheel */ +PARAM_DEFINE_FLOAT(MC_ATT_I, 0.0f); +PARAM_DEFINE_FLOAT(MC_ATT_D, 0.05f); /* 0.025 F405 Flamewheel */ +PARAM_DEFINE_FLOAT(MC_ATT_AWU, 0.05f); +PARAM_DEFINE_FLOAT(MC_ATT_LIM, 0.4f); + +PARAM_DEFINE_FLOAT(MC_ATT_XOFF, 0.0f); +PARAM_DEFINE_FLOAT(MC_ATT_YOFF, 0.0f); + +struct mc_att_control_params { + // float yaw_p; + // float yaw_i; + // float yaw_d; + // float yaw_awu; + // float yaw_lim; + + float yawrate_p; + float yawrate_i; + float yawrate_d; + float yawrate_awu; + float yawrate_lim; + + float att_p; + float att_i; + float att_d; + float att_awu; + float att_lim; + + float att_xoff; + float att_yoff; +}; + +struct mc_att_control_param_handles { + // param_t yaw_p; + // param_t yaw_i; + // param_t yaw_d; + // param_t yaw_awu; + // param_t yaw_lim; + + param_t yawrate_p; + param_t yawrate_i; + param_t yawrate_d; + param_t yawrate_awu; + param_t yawrate_lim; + + param_t att_p; + param_t att_i; + param_t att_d; + param_t att_awu; + param_t att_lim; + + param_t att_xoff; + param_t att_yoff; +}; + +/** + * Initialize all parameter handles and values + * + */ +static int parameters_init(struct mc_att_control_param_handles *h); + +/** + * Update all parameters + * + */ +static int parameters_update(const struct mc_att_control_param_handles *h, struct mc_att_control_params *p); + + +static int parameters_init(struct mc_att_control_param_handles *h) +{ + /* PID parameters */ + // h->yaw_p = param_find("MC_YAWPOS_P"); + // h->yaw_i = param_find("MC_YAWPOS_I"); + // h->yaw_d = param_find("MC_YAWPOS_D"); + // h->yaw_awu = param_find("MC_YAWPOS_AWU"); + // h->yaw_lim = param_find("MC_YAWPOS_LIM"); + + h->yawrate_p = param_find("MC_YAWRATE_P"); + h->yawrate_i = param_find("MC_YAWRATE_I"); + h->yawrate_d = param_find("MC_YAWRATE_D"); + h->yawrate_awu = param_find("MC_YAWRATE_AWU"); + h->yawrate_lim = param_find("MC_YAWRATE_LIM"); + + h->att_p = param_find("MC_ATT_P"); + h->att_i = param_find("MC_ATT_I"); + h->att_d = param_find("MC_ATT_D"); + h->att_awu = param_find("MC_ATT_AWU"); + h->att_lim = param_find("MC_ATT_LIM"); + + h->att_xoff = param_find("MC_ATT_XOFF"); + h->att_yoff = param_find("MC_ATT_YOFF"); + + return OK; +} + +static int parameters_update(const struct mc_att_control_param_handles *h, struct mc_att_control_params *p) +{ + // param_get(h->yaw_p, &(p->yaw_p)); + // param_get(h->yaw_i, &(p->yaw_i)); + // param_get(h->yaw_d, &(p->yaw_d)); + // param_get(h->yaw_awu, &(p->yaw_awu)); + // param_get(h->yaw_lim, &(p->yaw_lim)); + + param_get(h->yawrate_p, &(p->yawrate_p)); + param_get(h->yawrate_i, &(p->yawrate_i)); + param_get(h->yawrate_d, &(p->yawrate_d)); + param_get(h->yawrate_awu, &(p->yawrate_awu)); + param_get(h->yawrate_lim, &(p->yawrate_lim)); + + param_get(h->att_p, &(p->att_p)); + param_get(h->att_i, &(p->att_i)); + param_get(h->att_d, &(p->att_d)); + param_get(h->att_awu, &(p->att_awu)); + param_get(h->att_lim, &(p->att_lim)); + + param_get(h->att_xoff, &(p->att_xoff)); + param_get(h->att_yoff, &(p->att_yoff)); + + return OK; +} + +void multirotor_control_attitude(const struct vehicle_attitude_setpoint_s *att_sp, + const struct vehicle_attitude_s *att, struct actuator_controls_s *actuators) +{ + static uint64_t last_run = 0; + const float deltaT = (hrt_absolute_time() - last_run) / 1000000.0f; + last_run = hrt_absolute_time(); + + static int motor_skip_counter = 0; + + // static PID_t yaw_pos_controller; + static PID_t yaw_speed_controller; + static PID_t pitch_controller; + static PID_t roll_controller; + + static struct mc_att_control_params p; + static struct mc_att_control_param_handles h; + + static bool initialized = false; + + /* initialize the pid controllers when the function is called for the first time */ + if (initialized == false) { + parameters_init(&h); + parameters_update(&h, &p); + + // pid_init(&yaw_pos_controller, p.yaw_p, p.yaw_i, p.yaw_d, p.yaw_awu, + // PID_MODE_DERIVATIV_SET, 154); + pid_init(&yaw_speed_controller, p.yawrate_p, p.yawrate_i, p.yawrate_d, p.yawrate_awu, + PID_MODE_DERIVATIV_SET, 155); + pid_init(&pitch_controller, p.att_p, p.att_i, p.att_d, p.att_awu, + PID_MODE_DERIVATIV_SET, 156); + pid_init(&roll_controller, p.att_p, p.att_i, p.att_d, p.att_awu, + PID_MODE_DERIVATIV_SET, 157); + + initialized = true; + } + + /* load new parameters with lower rate */ + if (motor_skip_counter % 50 == 0) { + /* update parameters from storage */ + parameters_update(&h, &p); + /* apply parameters */ + // pid_set_parameters(&yaw_pos_controller, p.yaw_p, p.yaw_i, p.yaw_d, p.yaw_awu); + pid_set_parameters(&yaw_speed_controller, p.yawrate_p, p.yawrate_i, p.yawrate_d, p.yawrate_awu); + pid_set_parameters(&pitch_controller, p.att_p, p.att_i, p.att_d, p.att_awu); + pid_set_parameters(&roll_controller, p.att_p, p.att_i, p.att_d, p.att_awu); + } + + /* calculate current control outputs */ + + /* control pitch (forward) output */ + float pitch_control = pid_calculate(&pitch_controller, att_sp->pitch_body + p.att_xoff, + att->pitch, att->pitchspeed, deltaT); + /* control roll (left/right) output */ + float roll_control = pid_calculate(&roll_controller, att_sp->roll_body + p.att_yoff, + att->roll, att->rollspeed, deltaT); + /* control yaw rate */ + float yaw_rate_control = pid_calculate(&yaw_speed_controller, att_sp->yaw_rate_body, att->yawspeed, 0.0f, deltaT); + + /* + * compensate the vertical loss of thrust + * when thrust plane has an angle. + * start with a factor of 1.0 (no change) + */ + float zcompensation = 1.0f; + + if (fabsf(att->roll) > 0.3f) { + zcompensation *= 1.04675160154f; + + } else { + zcompensation *= 1.0f / cosf(att->roll); + } + + if (fabsf(att->pitch) > 0.3f) { + zcompensation *= 1.04675160154f; + + } else { + zcompensation *= 1.0f / cosf(att->pitch); + } + + float motor_thrust = 0.0f; + + motor_thrust = att_sp->thrust; + + /* compensate thrust vector for roll / pitch contributions */ + motor_thrust *= zcompensation; + + /* limit yaw rate output */ + if (yaw_rate_control > p.yawrate_lim) { + yaw_rate_control = p.yawrate_lim; + yaw_speed_controller.saturated = 1; + } + + if (yaw_rate_control < -p.yawrate_lim) { + yaw_rate_control = -p.yawrate_lim; + yaw_speed_controller.saturated = 1; + } + + if (pitch_control > p.att_lim) { + pitch_control = p.att_lim; + pitch_controller.saturated = 1; + } + + if (pitch_control < -p.att_lim) { + pitch_control = -p.att_lim; + pitch_controller.saturated = 1; + } + + + if (roll_control > p.att_lim) { + roll_control = p.att_lim; + roll_controller.saturated = 1; + } + + if (roll_control < -p.att_lim) { + roll_control = -p.att_lim; + roll_controller.saturated = 1; + } + + actuators->control[0] = roll_control; + actuators->control[1] = pitch_control; + actuators->control[2] = yaw_rate_control; + actuators->control[3] = motor_thrust; + + motor_skip_counter++; +} diff --git a/apps/ardrone_control/attitude_control.h b/apps/multirotor_att_control/multirotor_attitude_control.h similarity index 80% rename from apps/ardrone_control/attitude_control.h rename to apps/multirotor_att_control/multirotor_attitude_control.h index 56f52dabec..aa8d27369b 100644 --- a/apps/ardrone_control/attitude_control.h +++ b/apps/multirotor_att_control/multirotor_attitude_control.h @@ -38,24 +38,19 @@ ****************************************************************************/ /* - * @file attitude_control.h - * attitude control for multi rotors + * @file multirotor_attitude_control.h + * Attitude control for multi rotors. */ -#ifndef ATTITUDE_CONTROL_H_ -#define ATTITUDE_CONTROL_H_ +#ifndef MULTIROTOR_ATTITUDE_CONTROL_H_ +#define MULTIROTOR_ATTITUDE_CONTROL_H_ #include -#include #include #include -#include -#include +#include void multirotor_control_attitude(const struct vehicle_attitude_setpoint_s *att_sp, const struct vehicle_attitude_s *att, - const struct vehicle_status_s *status, bool verbose, - float* roll_output, float* pitch_output, float* yaw_output, float* thrust_output); + struct actuator_controls_s *actuators); -void ardrone_mixing_and_output(int ardrone_write, float roll_control, float pitch_control, float yaw_control, float motor_thrust, bool verbose); - -#endif /* ATTITUDE_CONTROL_H_ */ +#endif /* MULTIROTOR_ATTITUDE_CONTROL_H_ */ diff --git a/apps/multirotor_att_control/multirotor_rate_control.c b/apps/multirotor_att_control/multirotor_rate_control.c new file mode 100644 index 0000000000..8a3ac78cdc --- /dev/null +++ b/apps/multirotor_att_control/multirotor_rate_control.c @@ -0,0 +1,256 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Tobias Naegeli + * @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file multirotor_rate_control.c + * Implementation of rate controller + */ + +#include "multirotor_rate_control.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// PARAM_DEFINE_FLOAT(MC_YAWRATE_P, 0.08f); /* same on Flamewheel */ +// PARAM_DEFINE_FLOAT(MC_YAWRATE_I, 0.02f); +// PARAM_DEFINE_FLOAT(MC_YAWRATE_AWU, 0.02f); +// PARAM_DEFINE_FLOAT(MC_YAWRATE_LIM, 0.1f); + +PARAM_DEFINE_FLOAT(MC_ATTRATE_P, 0.2f); /* 0.15 F405 Flamewheel */ +PARAM_DEFINE_FLOAT(MC_ATTRATE_I, 0.0f); +PARAM_DEFINE_FLOAT(MC_ATTRATE_AWU, 0.05f); +PARAM_DEFINE_FLOAT(MC_ATTRATE_LIM, 8.0f); /**< roughly < 500 deg/s limit */ + +struct mc_rate_control_params { + + float yawrate_p; + float yawrate_i; + float yawrate_awu; + float yawrate_lim; + + float attrate_p; + float attrate_i; + float attrate_awu; + float attrate_lim; + + float rate_lim; +}; + +struct mc_rate_control_param_handles { + + param_t yawrate_p; + param_t yawrate_i; + param_t yawrate_awu; + param_t yawrate_lim; + + param_t attrate_p; + param_t attrate_i; + param_t attrate_awu; + param_t attrate_lim; +}; + +/** + * Initialize all parameter handles and values + * + */ +static int parameters_init(struct mc_rate_control_param_handles *h); + +/** + * Update all parameters + * + */ +static int parameters_update(const struct mc_rate_control_param_handles *h, struct mc_rate_control_params *p); + + +static int parameters_init(struct mc_rate_control_param_handles *h) +{ + /* PID parameters */ + h->yawrate_p = param_find("MC_YAWRATE_P"); + h->yawrate_i = param_find("MC_YAWRATE_I"); + h->yawrate_awu = param_find("MC_YAWRATE_AWU"); + h->yawrate_lim = param_find("MC_YAWRATE_LIM"); + + h->attrate_p = param_find("MC_ATTRATE_P"); + h->attrate_i = param_find("MC_ATTRATE_I"); + h->attrate_awu = param_find("MC_ATTRATE_AWU"); + h->attrate_lim = param_find("MC_ATTRATE_LIM"); + + return OK; +} + +static int parameters_update(const struct mc_rate_control_param_handles *h, struct mc_rate_control_params *p) +{ + param_get(h->yawrate_p, &(p->yawrate_p)); + param_get(h->yawrate_i, &(p->yawrate_i)); + param_get(h->yawrate_awu, &(p->yawrate_awu)); + param_get(h->yawrate_lim, &(p->yawrate_lim)); + + param_get(h->attrate_p, &(p->attrate_p)); + param_get(h->attrate_i, &(p->attrate_i)); + param_get(h->attrate_awu, &(p->attrate_awu)); + param_get(h->attrate_lim, &(p->attrate_lim)); + + return OK; +} + +void multirotor_control_rates(const struct vehicle_attitude_setpoint_s *rate_sp, + const float rates[], struct actuator_controls_s *actuators) +{ + static uint64_t last_run = 0; + const float deltaT = (hrt_absolute_time() - last_run) / 1000000.0f; + last_run = hrt_absolute_time(); + + static int motor_skip_counter = 0; + + // static PID_t yaw_pos_controller; + static PID_t yaw_speed_controller; + static PID_t pitch_controller; + static PID_t roll_controller; + + static struct mc_rate_control_params p; + static struct mc_rate_control_param_handles h; + + static bool initialized = false; + + /* initialize the pid controllers when the function is called for the first time */ + if (initialized == false) { + parameters_init(&h); + parameters_update(&h, &p); + + pid_init(&yaw_speed_controller, p.yawrate_p, 0, p.yawrate_i, p.yawrate_awu, + PID_MODE_DERIVATIV_SET, 155); + pid_init(&pitch_controller, p.attrate_p, p.attrate_i, 0, p.attrate_awu, + PID_MODE_DERIVATIV_SET, 156); + pid_init(&roll_controller, p.attrate_p, p.attrate_i, 0, p.attrate_awu, + PID_MODE_DERIVATIV_SET, 157); + + initialized = true; + } + + /* load new parameters with lower rate */ + if (motor_skip_counter % 250 == 0) { + /* update parameters from storage */ + parameters_update(&h, &p); + /* apply parameters */ + pid_set_parameters(&yaw_speed_controller, p.yawrate_p, p.yawrate_i, 0, p.yawrate_awu); + pid_set_parameters(&pitch_controller, p.attrate_p, p.attrate_i, 0, p.attrate_awu); + pid_set_parameters(&roll_controller, p.attrate_p, p.attrate_i, 0, p.attrate_awu); + } + + /* calculate current control outputs */ + + /* control pitch (forward) output */ + float pitch_control = pid_calculate(&pitch_controller, rate_sp->pitch_rate_body, + rates[1], 0.0f, deltaT); + /* control roll (left/right) output */ + float roll_control = pid_calculate(&roll_controller, rate_sp->roll_rate_body, + rates[0], 0.0f, deltaT); + /* control yaw rate */ + float yaw_rate_control = pid_calculate(&yaw_speed_controller, rate_sp->yaw_rate_body, rates[2], 0.0f, deltaT); + + /* + * compensate the vertical loss of thrust + * when thrust plane has an angle. + * start with a factor of 1.0 (no change) + */ + float zcompensation = 1.0f; + + // if (fabsf(att->roll) > 0.3f) { + // zcompensation *= 1.04675160154f; + + // } else { + // zcompensation *= 1.0f / cosf(att->roll); + // } + + // if (fabsf(att->pitch) > 0.3f) { + // zcompensation *= 1.04675160154f; + + // } else { + // zcompensation *= 1.0f / cosf(att->pitch); + // } + + float motor_thrust = 0.0f; + + motor_thrust = rate_sp->thrust; + + /* compensate thrust vector for roll / pitch contributions */ + motor_thrust *= zcompensation; + + /* limit yaw rate output */ + if (yaw_rate_control > p.yawrate_lim) { + yaw_rate_control = p.yawrate_lim; + yaw_speed_controller.saturated = 1; + } + + if (yaw_rate_control < -p.yawrate_lim) { + yaw_rate_control = -p.yawrate_lim; + yaw_speed_controller.saturated = 1; + } + + if (pitch_control > p.attrate_lim) { + pitch_control = p.attrate_lim; + pitch_controller.saturated = 1; + } + + if (pitch_control < -p.attrate_lim) { + pitch_control = -p.attrate_lim; + pitch_controller.saturated = 1; + } + + + if (roll_control > p.attrate_lim) { + roll_control = p.attrate_lim; + roll_controller.saturated = 1; + } + + if (roll_control < -p.attrate_lim) { + roll_control = -p.attrate_lim; + roll_controller.saturated = 1; + } + + actuators->control[0] = roll_control; + actuators->control[1] = pitch_control; + actuators->control[2] = yaw_rate_control; + actuators->control[3] = motor_thrust; + + motor_skip_counter++; +} diff --git a/apps/multirotor_control/multirotor_attitude_control.h b/apps/multirotor_att_control/multirotor_rate_control.h similarity index 72% rename from apps/multirotor_control/multirotor_attitude_control.h rename to apps/multirotor_att_control/multirotor_rate_control.h index c3aa470413..6f34d99e7a 100644 --- a/apps/multirotor_control/multirotor_attitude_control.h +++ b/apps/multirotor_att_control/multirotor_rate_control.h @@ -1,9 +1,12 @@ /**************************************************************************** * * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * + * Author: @author Thomas Gubler + * @author Julian Oes + * @author Laurens Mackay + * @author Tobias Naegeli + * @author Martin Rutschmann + * @author Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,22 +37,20 @@ * ****************************************************************************/ -/** +/* * @file multirotor_attitude_control.h - * - * attitude control for multirotors + * Attitude control for multi rotors. */ -#ifndef ATTITUDE_CONTROL_H_ -#define ATTITUDE_CONTROL_H_ +#ifndef MULTIROTOR_RATE_CONTROL_H_ +#define MULTIROTOR_RATE_CONTROL_H_ #include -#include #include -#include +#include #include -void multirotor_control_attitude(const struct rc_channels_s *rc, const struct vehicle_attitude_s *att, - const struct vehicle_status_s *status, struct actuator_controls_s *actuators); +void multirotor_control_rates(const struct vehicle_attitude_setpoint_s *rate_sp, + const float rates[], struct actuator_controls_s *actuators); -#endif /* ATTITUDE_CONTROL_H_ */ +#endif /* MULTIROTOR_RATE_CONTROL_H_ */ diff --git a/apps/multirotor_control/multirotor_attitude_control.c b/apps/multirotor_control/multirotor_attitude_control.c deleted file mode 100644 index 4391c39577..0000000000 --- a/apps/multirotor_control/multirotor_attitude_control.c +++ /dev/null @@ -1,457 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * Laurens Mackay - * Tobias Naegeli - * Martin Rutschmann - * Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/** - * @file multirotor_attitude_control.c - * - * Implementation of multirotor attitude controller. - */ - -#include "multirotor_attitude_control.h" -#include -#include -#include -#include -#include -#include //TODO: move matrix.h to somewhere else? -#include -#include -#include "pid.h" -#include - -extern int multirotor_write; -extern int gpios; - -#define CONTROL_PID_ATTITUDE_INTERVAL 5e-3 - -void turn_xy_plane(const float_vect3 *vector, float yaw, - float_vect3 *result) -{ - //turn clockwise - static uint16_t counter; - - result->x = (cosf(yaw) * vector->x + sinf(yaw) * vector->y); - result->y = (-sinf(yaw) * vector->x + cosf(yaw) * vector->y); - result->z = vector->z; //leave direction normal to xy-plane untouched - - counter++; -} - -void navi2body_xy_plane(const float_vect3 *vector, const float yaw, - float_vect3 *result) -{ - turn_xy_plane(vector, yaw, result); -// result->x = vector->x; -// result->y = vector->y; -// result->z = vector->z; - // result->x = cos(yaw) * vector->x + sin(yaw) * vector->y; - // result->y = -sin(yaw) * vector->x + cos(yaw) * vector->y; - // result->z = vector->z; //leave direction normal to xy-plane untouched -} - -void multirotor_control_attitude(const struct rc_channels_s *rc, - const struct vehicle_attitude_s *att, - const struct vehicle_status_s *status, - struct actuator_controls_s *actuators) -{ - static int motor_skip_counter = 0; - - static PID_t yaw_pos_controller; - static PID_t yaw_speed_controller; - static PID_t nick_controller; - static PID_t roll_controller; - - // XXXM - static const float min_gas = 1; - static const float max_gas = 512; - - - static uint16_t motor_pwm[4] = {0, 0, 0, 0}; - static float motor_calc[4] = {0.0f, 0.0f, 0.0f, 0.0f}; -// static float remote_control_weight_z = 1; -// static float position_control_weight_z = 0; - - static float pid_yawpos_lim; - static float pid_yawspeed_lim; - static float pid_att_lim; - - static bool initialized; - - // static float_vect3 attitude_setpoint_navigationframe_from_positioncontroller; - - // static hrt_abstime now_time; - // static hrt_abstime last_time; - - static commander_state_machine_t current_state; - - /* initialize the pid controllers when the function is called for the first time */ - if (initialized == false) { - - pid_init(&yaw_pos_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_AWU], - PID_MODE_DERIVATIV_CALC, 154); - - pid_init(&yaw_speed_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_AWU], - PID_MODE_DERIVATIV_CALC, 155); - - pid_init(&nick_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU], - PID_MODE_DERIVATIV_SET, 156); - - pid_init(&roll_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU], - PID_MODE_DERIVATIV_SET, 157); - - pid_yawpos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_LIM]; - pid_yawspeed_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_LIM]; - pid_att_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_LIM]; - - // //TODO: true initialization? get gps while on ground? - // attitude_setpoint_navigationframe_from_positioncontroller.x = 0.0f; - // attitude_setpoint_navigationframe_from_positioncontroller.y = 0.0f; - // attitude_setpoint_navigationframe_from_positioncontroller.z = 0.0f; - - // last_time = 0; - initialized = true; - } - - /* load new parameters with lower rate */ - if (motor_skip_counter % 50 == 0) { - pid_set_parameters(&yaw_pos_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_AWU]); - - pid_set_parameters(&yaw_speed_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_AWU]); - - pid_set_parameters(&nick_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]); - - pid_set_parameters(&roll_controller, - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]); - - pid_yawpos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_LIM]; - pid_yawspeed_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_LIM]; - pid_att_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_LIM]; - } - - current_state = status->state_machine; - float_vect3 attitude_setpoint_bodyframe = {0.0f, 0.0f, 0.0f}; //this is the setpoint in the bodyframe "mixed" together from the setpoint from the remote and the setpoint from the position controller - - if (current_state == SYSTEM_STATE_AUTO) { - - // attitude_setpoint_navigationframe_from_positioncontroller.x = ar_control->attitude_setpoint_navigationframe_from_positioncontroller[0]; - // attitude_setpoint_navigationframe_from_positioncontroller.y = ar_control->attitude_setpoint_navigationframe_from_positioncontroller[1]; - // attitude_setpoint_navigationframe_from_positioncontroller.z = ar_control->attitude_setpoint_navigationframe_from_positioncontroller[2]; - - // float yaw_e = att->yaw - attitude_setpoint_navigationframe_from_positioncontroller.z; - - // // don't turn around the wrong side (only works if yaw angle is between +- 180 degree) - // if (yaw_e > M_PI) { - // yaw_e -= 2.0f * M_PI; - // } - - // if (yaw_e < -M_PI) { - // yaw_e += 2.0f * M_PI; - // } - - // attitude_setpoint_navigationframe_from_positioncontroller.z = pid_calculate(&yaw_pos_controller, 0, yaw_e, 0, CONTROL_PID_ATTITUDE_INTERVAL); - - - // /* limit control output */ - // if (attitude_setpoint_navigationframe_from_positioncontroller.z > pid_yawpos_lim) { - // attitude_setpoint_navigationframe_from_positioncontroller.z = pid_yawpos_lim; - // yaw_pos_controller.saturated = 1; - // } - - // if (attitude_setpoint_navigationframe_from_positioncontroller.z < -pid_yawpos_lim) { - // attitude_setpoint_navigationframe_from_positioncontroller.z = -pid_yawpos_lim; - // yaw_pos_controller.saturated = 1; - // } - - // //transform attitude setpoint from position controller from navi to body frame on xy_plane - // float_vect3 attitude_setpoint_bodyframe_from_positioncontroller; - // navi2body_xy_plane(&attitude_setpoint_navigationframe_from_positioncontroller, att->yaw , &attitude_setpoint_bodyframe_from_positioncontroller); //yaw angle= att->yaw - // //now everything is in body frame - - - // //TODO: here we decide which input (position controller or ppm) we use. For now we have only the ppm, this should be decided dpending on the state machione (manula or auto) ppm should always overwrite auto (?) - // attitude_setpoint_bodyframe.x = attitude_setpoint_bodyframe_from_positioncontroller.x; - // attitude_setpoint_bodyframe.y = attitude_setpoint_bodyframe_from_positioncontroller.y; - // attitude_setpoint_bodyframe.z = attitude_setpoint_bodyframe_from_positioncontroller.z; - - } else if (current_state == SYSTEM_STATE_MANUAL) { - attitude_setpoint_bodyframe.x = -((float)rc->chan[rc->function[ROLL]].scale / 10000.0f) * 3.14159265 / 8.0f; - attitude_setpoint_bodyframe.y = -((float)rc->chan[rc->function[PITCH]].scale / 10000.0f) * 3.14159265 / 8.0f; - attitude_setpoint_bodyframe.z = -((float)rc->chan[rc->function[YAW]].scale / 10000.0f) * 3.14159265; - } - - /* add an attitude offset which needs to be estimated somewhere */ - attitude_setpoint_bodyframe.x += global_data_parameter_storage->pm.param_values[PARAM_ATT_XOFFSET]; - attitude_setpoint_bodyframe.y += global_data_parameter_storage->pm.param_values[PARAM_ATT_YOFFSET]; - - /*Calculate Controllers*/ - //control Nick - float nick = pid_calculate(&nick_controller, attitude_setpoint_bodyframe.y, att->pitch, att->pitchspeed, CONTROL_PID_ATTITUDE_INTERVAL); - //control Roll - float roll = pid_calculate(&roll_controller, attitude_setpoint_bodyframe.x, att->roll, att->rollspeed, CONTROL_PID_ATTITUDE_INTERVAL); - //control Yaw Speed - float yaw = pid_calculate(&yaw_speed_controller, attitude_setpoint_bodyframe.z, att->yawspeed, 0, CONTROL_PID_ATTITUDE_INTERVAL); //attitude_setpoint_bodyframe.z is yaw speed! - - //compensation to keep force in z-direction - float zcompensation; - - if (fabs(att->roll) > 0.5f) { - zcompensation = 1.13949393f; - - } else { - zcompensation = 1.0f / cosf(att->roll); - } - - if (fabs(att->pitch) > 0.5f) { - zcompensation *= 1.13949393f; - - } else { - zcompensation *= 1.0f / cosf(att->pitch); - } - - // use global_data.position_control_output.z and mix parameter global_data.param[PARAM_MIX_POSITION_Z_WEIGHT] - // to compute thrust for Z position control - // - // float motor_thrust = min_gas + - // ( ( 1 - global_data.param[PARAM_MIX_POSITION_Z_WEIGHT] ) * ( max_gas - min_gas ) * global_data.gas_remote * zcompensation ) - // + ( global_data.param[PARAM_MIX_POSITION_Z_WEIGHT] * ( max_gas - min_gas ) * controlled_thrust * zcompensation ); - //calculate the basic thrust - - - - float motor_thrust = 0; - - // FLYING MODES - if (current_state == SYSTEM_STATE_MANUAL) { - motor_thrust = (float)rc->chan[rc->function[THROTTLE]].scale; - - } else if (current_state == SYSTEM_STATE_GROUND_READY || current_state == SYSTEM_STATE_STABILIZED || current_state == SYSTEM_STATE_AUTO || current_state == SYSTEM_STATE_MISSION_ABORT) { - motor_thrust = (float)rc->chan[rc->function[THROTTLE]].scale; //TODO - - } else if (current_state == SYSTEM_STATE_EMCY_LANDING) { - motor_thrust = (float)rc->chan[rc->function[THROTTLE]].scale; //TODO - - } else if (current_state == SYSTEM_STATE_EMCY_CUTOFF) { - motor_thrust = 0.0f; //immediately cut off thrust! - - } else { - motor_thrust = 0.0f; // Motor thrust must be zero in any other mode! - } - - // Convertion to motor-step units - motor_thrust *= zcompensation; - motor_thrust *= max_gas / 20000.0f; //TODO: check this - motor_thrust += (max_gas - min_gas) / 2.f; - - // XXXM - // RC channels: assumed to be -10000 to +10000 - - - - //limit control output - //yawspeed - if (yaw > pid_yawspeed_lim) { - yaw = pid_yawspeed_lim; - yaw_speed_controller.saturated = 1; - } - - if (yaw < -pid_yawspeed_lim) { - yaw = -pid_yawspeed_lim; - yaw_speed_controller.saturated = 1; - } - - if (nick > pid_att_lim) { - nick = pid_att_lim; - nick_controller.saturated = 1; - } - - if (nick < -pid_att_lim) { - nick = -pid_att_lim; - nick_controller.saturated = 1; - } - - - if (roll > pid_att_lim) { - roll = pid_att_lim; - roll_controller.saturated = 1; - } - - if (roll < -pid_att_lim) { - roll = -pid_att_lim; - roll_controller.saturated = 1; - } - - // /* Emit controller values */ - // ar_control->setpoint_thrust_cast = motor_thrust; - // ar_control->setpoint_attitude[0] = attitude_setpoint_bodyframe.x; - // ar_control->setpoint_attitude[1] = attitude_setpoint_bodyframe.y; - // ar_control->setpoint_attitude[2] = attitude_setpoint_bodyframe.z; - // ar_control->attitude_control_output[0] = roll; - // ar_control->attitude_control_output[1] = nick; - // ar_control->attitude_control_output[2] = yaw; - // ar_control->zcompensation = zcompensation; - // orb_publish(ORB_ID(multirotor_control), multirotor_pub, ar_control); - - static float output_band = 0.f; - static float band_factor = 0.75f; - static float startpoint_full_control = 150.0f; //TODO - static float yaw_factor = 1.0f; - - - - - - - // MIXING AND THRUST LIMITING START - - - - if (motor_thrust <= min_gas) { - motor_thrust = min_gas; - output_band = 0.f; - - } else if (motor_thrust < startpoint_full_control && motor_thrust > min_gas) { - output_band = band_factor * (motor_thrust - min_gas); - - } else if (motor_thrust >= startpoint_full_control && motor_thrust < max_gas - band_factor * startpoint_full_control) { - output_band = band_factor * startpoint_full_control; - - } else if (motor_thrust >= max_gas - band_factor * startpoint_full_control) { - output_band = band_factor * (max_gas - motor_thrust); - } - - //add the yaw, nick and roll components to the basic thrust //TODO:this should be done by the mixer - - // FRONT (MOTOR 1) - motor_calc[0] = motor_thrust + (roll / 2 + nick / 2 - yaw); - - // RIGHT (MOTOR 2) - motor_calc[1] = motor_thrust + (-roll / 2 + nick / 2 + yaw); - - // BACK (MOTOR 3) - motor_calc[2] = motor_thrust + (-roll / 2 - nick / 2 - yaw); - - // LEFT (MOTOR 4) - motor_calc[3] = motor_thrust + (roll / 2 - nick / 2 + yaw); - - // if we are not in the output band - if (!(motor_calc[0] < motor_thrust + output_band && motor_calc[0] > motor_thrust - output_band - && motor_calc[1] < motor_thrust + output_band && motor_calc[1] > motor_thrust - output_band - && motor_calc[2] < motor_thrust + output_band && motor_calc[2] > motor_thrust - output_band - && motor_calc[3] < motor_thrust + output_band && motor_calc[3] > motor_thrust - output_band)) { - - yaw_factor = 0.5f; - // FRONT (MOTOR 1) - motor_calc[0] = motor_thrust + (roll / 2 + nick / 2 - yaw * yaw_factor); - - // RIGHT (MOTOR 2) - motor_calc[1] = motor_thrust + (-roll / 2 + nick / 2 + yaw * yaw_factor); - - // BACK (MOTOR 3) - motor_calc[2] = motor_thrust + (-roll / 2 - nick / 2 - yaw * yaw_factor); - - // LEFT (MOTOR 4) - motor_calc[3] = motor_thrust + (roll / 2 - nick / 2 + yaw * yaw_factor); - } - - uint8_t i; - - for (i = 0; i < 4; i++) { - //check for limits - if (motor_calc[i] < motor_thrust - output_band) { - motor_calc[i] = motor_thrust - output_band; - } - - if (motor_calc[i] > motor_thrust + output_band) { - motor_calc[i] = motor_thrust + output_band; - } - } - - // Write out actual thrust - - // XXXM - motor_pwm[0] = (uint16_t) motor_calc[0]; - motor_pwm[1] = (uint16_t) motor_calc[1]; - motor_pwm[2] = (uint16_t) motor_calc[2]; - motor_pwm[3] = (uint16_t) motor_calc[3]; - - //SEND MOTOR COMMANDS - - // XXXM - - motor_skip_counter++; - -// now_time = hrt_absolute_time() / 1000000; -// if(now_time - last_time > 0) -// { -// printf("Counter: %ld\n",control_counter); -// last_time = now_time; -// control_counter = 0; -// } -} diff --git a/apps/multirotor_control/multirotor_control.c b/apps/multirotor_control/multirotor_control.c deleted file mode 100644 index 2edc1ba84f..0000000000 --- a/apps/multirotor_control/multirotor_control.c +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file multirotor_control.c - * - * Implementation of multirotor controllers - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "multirotor_control.h" -#include "multirotor_attitude_control.h" -#include -#include -#include -#include -#include - -#include - -__EXPORT int multirotor_control_main(int argc, char *argv[]); - - -static enum { - CONTROL_MODE_RATES = 0, - CONTROL_MODE_ATTITUDE = 1, -} control_mode; - - -static bool thread_should_exit; -static int mc_task; - -static int -mc_thread_main(int argc, char *argv[]) -{ - /* structures */ - struct vehicle_status_s state; - struct vehicle_attitude_s att; - struct rc_channels_s rc; - struct actuator_controls_s actuators; - struct actuator_armed_s armed; - - /* subscribe to attitude, motor setpoints and system state */ - int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); - int state_sub = orb_subscribe(ORB_ID(vehicle_status)); - int rc_sub = orb_subscribe(ORB_ID(rc_channels)); - - /* rate-limit the attitude subscription to 200Hz to pace our loop */ - orb_set_interval(att_sub, 5); - struct pollfd fds = { .fd = att_sub, .events = POLLIN }; - - /* publish actuator controls */ - for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++) - actuators.control[i] = 0.0f; - int actuator_pub = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &actuators); - armed.armed = true; - int armed_pub = orb_advertise(ORB_ID(actuator_armed), &armed); - - /* register the perf counter */ - perf_counter_t mc_loop_perf = perf_alloc(PC_ELAPSED, "multirotor_control"); - - /* welcome user */ - printf("[multirotor_control] starting\n"); - - while (!thread_should_exit) { - - /* wait for a sensor update */ - poll(&fds, 1, -1); - - perf_begin(mc_loop_perf); - - /* get a local copy of the vehicle state */ - orb_copy(ORB_ID(vehicle_status), state_sub, &state); - - /* get a local copy of rc inputs */ - orb_copy(ORB_ID(rc_channels), rc_sub, &rc); - - /* get a local copy of attitude */ - orb_copy(ORB_ID(vehicle_attitude), att_sub, &att); - - /* run the attitude controller */ - multirotor_control_attitude(&rc, &att, &state, &actuators); - - /* publish the result */ - orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators); - - perf_end(mc_loop_perf); - } - - printf("[multirotor_control] stopping\r\n"); - - /* kill all outputs */ - armed.armed = false; - orb_publish(ORB_ID(actuator_armed), armed_pub, &armed); - for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++) - actuators.control[i] = 0.0f; - orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators); - - - close(att_sub); - close(state_sub); - close(rc_sub); - close(actuator_pub); - close(armed_pub); - - perf_print_counter(mc_loop_perf); - perf_free(mc_loop_perf); - - fflush(stdout); - exit(0); -} - -static void -usage(const char *reason) -{ - if (reason) - fprintf(stderr, "%s\n", reason); - fprintf(stderr, "usage: multirotor_control [-m ] {start|stop}\n"); - fprintf(stderr, " is 'rates' or 'attitude'\n"); - exit(1); -} - -int multirotor_control_main(int argc, char *argv[]) -{ - int ch; - - control_mode = CONTROL_MODE_RATES; - - while ((ch = getopt(argc, argv, "m:")) != EOF) { - switch (ch) { - case 'm': - if (!strcmp(optarg, "rates")) { - control_mode = CONTROL_MODE_RATES; - } else if (!strcmp(optarg, "attitude")) { - control_mode = CONTROL_MODE_RATES; - } else { - usage("unrecognized -m value"); - } - default: - usage("unrecognized option"); - } - } - argc -= optind; - argv += optind; - - if (argc < 1) - usage("missing command"); - - if (!strcmp(argv[1], "start")) { - - thread_should_exit = false; - mc_task = task_create("multirotor_attitude", SCHED_PRIORITY_MAX - 15, 2048, mc_thread_main, NULL); - exit(0); - } - - if (!strcmp(argv[1], "stop")) { - thread_should_exit = true; - exit(0); - } - - usage("unrecognised command"); - exit(1); -} diff --git a/apps/multirotor_control/multirotor_control.h b/apps/multirotor_control/multirotor_control.h deleted file mode 100644 index cd779d3691..0000000000 --- a/apps/multirotor_control/multirotor_control.h +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @file multirotor_control.h - * - * Created on: Mar 23, 2012 - * Author: thomasgubler - */ - -#ifndef multirotor_CONTROL_H_ -#define multirotor_CONTROL_H_ - - -#endif /* multirotor_CONTROL_H_ */ diff --git a/apps/multirotor_control/pid.c b/apps/multirotor_control/pid.c deleted file mode 100644 index 5ce05670e3..0000000000 --- a/apps/multirotor_control/pid.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "pid.h" - -#include //TODO: move matrix.h to somewhere else? - -void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, - uint8_t mode, uint8_t plot_i) -{ - pid->kp = kp; - pid->ki = ki; - pid->kd = kd; - pid->intmax = intmax; - pid->mode = mode; - pid->plot_i = plot_i; - pid->count = 0; - pid->saturated = 0; - - pid->sp = 0; - pid->error_previous = 0; - pid->integral = 0; -} -void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax) -{ - pid->kp = kp; - pid->ki = ki; - pid->kd = kd; - pid->intmax = intmax; - // pid->mode = mode; - - // pid->sp = 0; - // pid->error_previous = 0; - // pid->integral = 0; -} - -//void pid_set(PID_t *pid, float sp) -//{ -// pid->sp = sp; -// pid->error_previous = 0; -// pid->integral = 0; -//} - -/** - * - * @param pid - * @param val - * @param dt - * @return - */ -float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt) -{ - /* error = setpoint - actual_position - integral = integral + (error*dt) - derivative = (error - previous_error)/dt - output = (Kp*error) + (Ki*integral) + (Kd*derivative) - previous_error = error - wait(dt) - goto start - */ - - float i, d; - pid->sp = sp; - float error = pid->sp - val; - - if (pid->saturated && (pid->integral * error > 0)) { - //Output is saturated and the integral would get bigger (positive or negative) - i = pid->integral; - - //Reset saturation. If we are still saturated this will be set again at output limit check. - pid->saturated = 0; - - } else { - i = pid->integral + (error * dt); - } - - // Anti-Windup. Needed if we don't use the saturation above. - if (pid->intmax != 0.0) { - if (i > pid->intmax) { - pid->integral = pid->intmax; - - } else if (i < -pid->intmax) { - - pid->integral = -pid->intmax; - - } else { - pid->integral = i; - } - - //Send Controller integrals - // Disabled because of new possibilities with debug_vect. - // Now sent in Main Loop at 5 Hz. 26.06.2010 Laurens - // if (pid->plot_i && (pid->count++ % 16 == 0)&&(global_data.param[PARAM_SEND_SLOT_DEBUG_2] == 1)) - // { - // mavlink_msg_debug_send(MAVLINK_COMM_1, pid->plot_i, pid->integral); - // } - } - - if (pid->mode == PID_MODE_DERIVATIV_CALC) { - d = (error - pid->error_previous) / dt; - - } else if (pid->mode == PID_MODE_DERIVATIV_SET) { - d = -val_dot; - - } else { - d = 0; - } - - pid->error_previous = error; - - return (error * pid->kp) + (i * pid->ki) + (d * pid->kd); -} diff --git a/apps/multirotor_control/pid.h b/apps/multirotor_control/pid.h deleted file mode 100644 index a721c839c6..0000000000 --- a/apps/multirotor_control/pid.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * pid.h - * - * Created on: May 29, 2012 - * Author: thomasgubler - */ - -#ifndef PID_H_ -#define PID_H_ - -#include - -/* PID_MODE_DERIVATIV_CALC calculates discrete derivative from previous error - * val_dot in pid_calculate() will be ignored */ -#define PID_MODE_DERIVATIV_CALC 0 -/* Use PID_MODE_DERIVATIV_SET if you have the derivative already (Gyros, Kalman) */ -#define PID_MODE_DERIVATIV_SET 1 - -typedef struct { - float kp; - float ki; - float kd; - float intmax; - float sp; - float integral; - float error_previous; - uint8_t mode; - uint8_t plot_i; - uint8_t count; - uint8_t saturated; -} PID_t; - -void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, uint8_t mode, uint8_t plot_i); -void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax); -//void pid_set(PID_t *pid, float sp); -float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt); - - - -#endif /* PID_H_ */ diff --git a/apps/multirotor_pos_control/Makefile b/apps/multirotor_pos_control/Makefile new file mode 100644 index 0000000000..c88c854356 --- /dev/null +++ b/apps/multirotor_pos_control/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Makefile to build multirotor position control +# + +APPNAME = multirotor_pos_control +PRIORITY = SCHED_PRIORITY_MAX - 25 +STACKSIZE = 2048 + +include $(APPDIR)/mk/app.mk diff --git a/apps/multirotor_pos_control/multirotor_pos_control.c b/apps/multirotor_pos_control/multirotor_pos_control.c new file mode 100644 index 0000000000..3f9c725177 --- /dev/null +++ b/apps/multirotor_pos_control/multirotor_pos_control.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* + * @file Implementation of AR.Drone 1.0 / 2.0 control interface + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ardrone_control.h" +#include "attitude_control.h" +#include "rate_control.h" +#include "ardrone_motor_control.h" +#include "position_control.h" +#include +#include +#include +#include + +__EXPORT int multirotor_pos_control_main(int argc, char *argv[]); + +static bool thread_should_exit; +static bool thread_running = false; +static int mpc_task; + +static int +mpc_thread_main(int argc, char *argv[]) +{ + /* welcome user */ + printf("[multirotor pos control] Control started, taking over position control\n"); + + /* structures */ + struct vehicle_status_s state; + struct vehicle_attitude_s att; + //struct vehicle_global_position_setpoint_s global_pos_sp; + struct vehicle_local_position_setpoint_s local_pos_sp; + struct vehicle_local_position_s local_pos; + struct manual_control_setpoint_s manual; + struct vehicle_attitude_setpoint_s att_sp; + + /* subscribe to attitude, motor setpoints and system state */ + int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); + int state_sub = orb_subscribe(ORB_ID(vehicle_status)); + int manual_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); + int local_pos_sub = orb_subscribe(ORB_ID(vehicle_local_position)); + //int global_pos_sp_sub = orb_subscribe(ORB_ID(vehicle_global_position_setpoint)); + int local_pos_sp_sub = orb_subscribe(ORB_ID(vehicle_local_position_setpoint)); + + /* publish attitude setpoint */ + orb_advert_t att_sp_pub = orb_advertise(ORB_ID(vehicle_attitude_setpoint), &att_sp); + + while (1) { + /* get a local copy of the vehicle state */ + orb_copy(ORB_ID(vehicle_status), state_sub, &state); + /* get a local copy of manual setpoint */ + orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual); + /* get a local copy of attitude */ + orb_copy(ORB_ID(vehicle_attitude), att_sub, &att); + /* get a local copy of local position */ + orb_copy(ORB_ID(vehicle_local_position), local_pos_sub, &local_pos); + /* get a local copy of local position setpoint */ + orb_copy(ORB_ID(vehicle_local_position_setpoint), local_pos_sp_sub, &local_pos_sp); + + if (state.state_machine == SYSTEM_STATE_AUTO) { + position_control(&state, &manual, &att, &local_pos, &local_pos_sp, &att_sp); + /* publish new attitude setpoint */ + orb_publish(ORB_ID(vehicle_attitude_setpoint), att_sp_pub, &att_sp); + } else if (state.state_machine == SYSTEM_STATE_STABILIZE) { + /* set setpoint to current position */ + // XXX select pos reset channel on remote + /* reset setpoint to current position (position hold) */ + // if (1 == 2) { + // local_pos_sp.x = local_pos.x; + // local_pos_sp.y = local_pos.y; + // local_pos_sp.z = local_pos.z; + // local_pos_sp.yaw = att.yaw; + // } + } + + /* run at approximately 50 Hz */ + usleep(20000); + + counter++; + } + + /* close uarts */ + close(ardrone_write); + ar_multiplexing_deinit(gpios); + + printf("[multirotor pos control] ending now...\r\n"); + fflush(stdout); + return 0; +} + diff --git a/apps/ardrone_control/position_control.c b/apps/multirotor_pos_control/position_control.c similarity index 77% rename from apps/ardrone_control/position_control.c rename to apps/multirotor_pos_control/position_control.c index 6ba1654595..fd731a33de 100644 --- a/apps/ardrone_control/position_control.c +++ b/apps/multirotor_pos_control/position_control.c @@ -1,8 +1,10 @@ /**************************************************************************** - * ardrone_control/position_control.c * - * Copyright (C) 2008, 2012 Thomas Gubler, Julian Oes, Lorenz Meier. All rights reserved. - * Author: Based on the pixhawk quadrotor controller + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * @author Laurens Mackay + * @author Tobias Naegeli + * @author Martin Rutschmann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -14,7 +16,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be + * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,7 +35,11 @@ * ****************************************************************************/ -#include "position_control.h" +/** + * @file multirotor_position_control.c + * Implementation of the position control for a multirotor VTOL + */ + #include #include #include @@ -41,41 +47,11 @@ #include #include #include -#include "pid.h" +#include -#ifndef FM_PI -#define FM_PI 3.1415926535897932384626433832795f -#endif +#include "multirotor_position_control.h" - - -#define CONTROL_PID_POSITION_INTERVAL 0.020 - -int read_lock_position(global_data_position_t *position) -{ - static int ret; - ret = global_data_wait(&global_data_position->access_conf); - - if (ret == 0) { - memcpy(&position->lat, &global_data_position->lat, sizeof(global_data_position->lat)); - memcpy(&position->lon, &global_data_position->lon, sizeof(global_data_position->lon)); - memcpy(&position->alt, &global_data_position->alt, sizeof(global_data_position->alt)); - memcpy(&position->relative_alt, &global_data_position->relative_alt, sizeof(global_data_position->relative_alt)); - memcpy(&position->vx, &global_data_position->vx, sizeof(global_data_position->vx)); - memcpy(&position->vy, &global_data_position->vy, sizeof(global_data_position->vy)); - memcpy(&position->vz, &global_data_position->vz, sizeof(global_data_position->vz)); - memcpy(&position->hdg, &global_data_position->hdg, sizeof(global_data_position->hdg)); - - - } else { - printf("Controller timeout, no new position values available\n"); - } - - global_data_unlock(&global_data_position->access_conf); - return ret; -} - -float get_distance_to_next_waypoint(float lat_now, float lon_now, float lat_next, float lon_next) +float get_distance_to_next_waypoint(double lat_now, double lon_now, double lat_next, double lon_next) { double lat_now_rad = lat_now / 180.0 * M_PI; double lon_now_rad = lon_now / 180.0 * M_PI; @@ -94,7 +70,7 @@ float get_distance_to_next_waypoint(float lat_now, float lon_now, float lat_next return radius_earth * c; } -float get_bearing_to_next_waypoint(float lat_now, float lon_now, float lat_next, float lon_next) +float get_bearing_to_next_waypoint(double lat_now, double lon_now, double lat_next, double lon_next) { double lat_now_rad = lat_now / 180.0 * M_PI; double lon_now_rad = lon_now / 180.0 * M_PI; @@ -104,17 +80,20 @@ float get_bearing_to_next_waypoint(float lat_now, float lon_now, float lat_next, double d_lat = lat_next_rad - lat_now_rad; double d_lon = lon_next_rad - lon_now_rad; - + /* conscious mix of double and float trig function to maximize speed and efficiency */ float theta = atan2f(sin(d_lon) * cos(lat_next_rad) , cos(lat_now_rad) * sin(lat_next_rad) - sin(lat_now_rad) * cos(lat_next_rad) * cos(d_lon)); - if (theta < 0) { - theta = theta + 2 * FM_PI; + // XXX wrapping check is incomplete + if (theta < 0.0f) { + theta = theta + 2.0f * M_PI_F; } return theta; } -void control_position(void) +void control_multirotor_position(const struct vehicle_state_s *vstatus, const struct vehicle_manual_control_s *manual, + const struct vehicle_attitude_s *att, const struct vehicle_local_position_s *local_pos, + const struct vehicle_local_position_setpoint_s *local_pos_sp, struct vehicle_attitude_setpoint_s *att_sp) { static PID_t distance_controller; @@ -136,8 +115,6 @@ void control_position(void) if (initialized == false) { - global_data_lock(&global_data_parameter_storage->access_conf); - pid_init(&distance_controller, global_data_parameter_storage->pm.param_values[PARAM_PID_POS_P], global_data_parameter_storage->pm.param_values[PARAM_PID_POS_I], @@ -148,10 +125,6 @@ void control_position(void) // pid_pos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_LIM]; // pid_pos_z_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_Z_LIM]; - pm_counter = global_data_parameter_storage->counter; - - global_data_unlock(&global_data_parameter_storage->access_conf); - thrust_total = 0.0f; /* Position initialization */ @@ -295,14 +268,8 @@ void control_position(void) roll_desired = asinf(roll_fraction); } - /*Broadcast desired angles */ - global_data_lock(&global_data_ardrone_control->access_conf); - global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller[0] = roll_desired; - global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller[1] = pitch_desired; - global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller[2] = bearing; //TODO: add yaw setpoint - global_data_unlock(&global_data_ardrone_control->access_conf); - global_data_broadcast(&global_data_ardrone_control->access_conf); - + att_sp.roll = roll_desired; + att_sp.pitch = pitch_desired; counter++; } diff --git a/apps/multirotor_pos_control/position_control.h b/apps/multirotor_pos_control/position_control.h new file mode 100644 index 0000000000..5ba59362e3 --- /dev/null +++ b/apps/multirotor_pos_control/position_control.h @@ -0,0 +1,50 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * @author Laurens Mackay + * @author Tobias Naegeli + * @author Martin Rutschmann + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file multirotor_position_control.h + * Definition of the position control for a multirotor VTOL + */ + +#ifndef POSITION_CONTROL_H_ +#define POSITION_CONTROL_H_ + +void control_multirotor_position(const struct vehicle_state_s *vstatus, const struct vehicle_manual_control_s *manual, + const struct vehicle_attitude_s *att, const struct vehicle_local_position_s *local_pos, + const struct vehicle_local_position_setpoint_s *local_pos_sp, struct vehicle_attitude_setpoint_s *att_sp); + +#endif /* POSITION_CONTROL_H_ */ diff --git a/apps/multirotor_position_control/ardrone_control.c b/apps/multirotor_position_control/ardrone_control.c deleted file mode 100644 index 89983724e1..0000000000 --- a/apps/multirotor_position_control/ardrone_control.c +++ /dev/null @@ -1,290 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file Implementation of AR.Drone 1.0 / 2.0 control interface - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ardrone_control.h" -#include "attitude_control.h" -#include "rate_control.h" -#include "ardrone_motor_control.h" -#include "position_control.h" -#include -#include -#include -#include -#include -#include -#include - -#include "ardrone_control_helper.h" - -__EXPORT int ardrone_control_main(int argc, char *argv[]); - -/**************************************************************************** - * Internal Definitions - ****************************************************************************/ - - -enum { - CONTROL_MODE_RATES = 0, - CONTROL_MODE_ATTITUDE = 1, -} control_mode; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/*File descriptors */ -int ardrone_write; -int gpios; - -bool position_control_thread_started; - -/**************************************************************************** - * pthread loops - ****************************************************************************/ -static void *position_control_loop(void *arg) -{ - struct vehicle_status_s *state = (struct vehicle_status_s *)arg; - // Set thread name - prctl(PR_SET_NAME, "ardrone pos ctrl", getpid()); - - while (1) { - if (state->state_machine == SYSTEM_STATE_AUTO) { -// control_position(); //FIXME TODO XXX - /* temporary 50 Hz execution */ - usleep(20000); - - } else { - position_control_thread_started = false; - break; - } - } - - return NULL; -} - -/**************************************************************************** - * main - ****************************************************************************/ - -int ardrone_control_main(int argc, char *argv[]) -{ - /* welcome user */ - printf("[ardrone_control] Control started, taking over motors\n"); - - /* default values for arguments */ - char *ardrone_uart_name = "/dev/ttyS1"; - control_mode = CONTROL_MODE_ATTITUDE; - - char *commandline_usage = "\tusage: ardrone_control -d ardrone-devicename -m mode\n\tmodes are:\n\t\trates\n\t\tattitude\n"; - - /* read commandline arguments */ - int i; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //ardrone set - if (argc > i + 1) { - ardrone_uart_name = argv[i + 1]; - - } else { - printf(commandline_usage); - return 0; - } - - } else if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--mode") == 0) { - if (argc > i + 1) { - if (strcmp(argv[i + 1], "rates") == 0) { - control_mode = CONTROL_MODE_RATES; - - } else if (strcmp(argv[i + 1], "attitude") == 0) { - control_mode = CONTROL_MODE_ATTITUDE; - - } else { - printf(commandline_usage); - return 0; - } - - } else { - printf(commandline_usage); - return 0; - } - } - } - - /* open uarts */ - printf("[ardrone_control] AR.Drone UART is %s\n", ardrone_uart_name); - ardrone_write = open(ardrone_uart_name, O_RDWR | O_NOCTTY | O_NDELAY); - if (ardrone_write < 0) { - printf("[ardrone_control] Failed opening AR.Drone UART, exiting.\n"); - exit(ERROR); - } - - /* initialize motors */ - ar_init_motors(ardrone_write, &gpios); - int counter = 0; - - /* Led animation */ - int led_counter = 0; - - /* pthread for position control */ - pthread_t position_control_thread; - position_control_thread_started = false; - - /* structures */ - struct vehicle_status_s state; - struct vehicle_attitude_s att; - struct ardrone_control_s ar_control; - struct manual_control_setpoint_s manual; - struct sensor_combined_s raw; - struct ardrone_motors_setpoint_s setpoint; - - /* subscribe to attitude, motor setpoints and system state */ - int att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); - int state_sub = orb_subscribe(ORB_ID(vehicle_status)); - int manual_sub = orb_subscribe(ORB_ID(manual_control_setpoint)); - int sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); - int setpoint_sub = orb_subscribe(ORB_ID(ardrone_motors_setpoint)); - - /* publish AR.Drone motor control state */ - int ardrone_pub = orb_advertise(ORB_ID(ardrone_control), &ar_control); - - while (1) { - /* get a local copy of the vehicle state */ - orb_copy(ORB_ID(vehicle_status), state_sub, &state); - /* get a local copy of manual setpoint */ - orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual); - /* get a local copy of attitude */ - orb_copy(ORB_ID(vehicle_attitude), att_sub, &att); - - if (state.state_machine == SYSTEM_STATE_AUTO) { - if (false == position_control_thread_started) { - pthread_attr_t position_control_thread_attr; - pthread_attr_init(&position_control_thread_attr); - pthread_attr_setstacksize(&position_control_thread_attr, 2048); - pthread_create(&position_control_thread, &position_control_thread_attr, position_control_loop, &state); - position_control_thread_started = true; - } - - control_attitude(0, 0, 0, 0, &att, &state, ardrone_pub, &ar_control); - - //No check for remote sticks to disarm in auto mode, land/disarm with ground station - - } else if (state.state_machine == SYSTEM_STATE_MANUAL) { - if (control_mode == CONTROL_MODE_RATES) { - orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw); - orb_copy(ORB_ID(ardrone_motors_setpoint), setpoint_sub, &setpoint); - control_rates(&raw, &setpoint); - - } else if (control_mode == CONTROL_MODE_ATTITUDE) { - - // XXX Add failsafe logic for RC loss situations - /* hardcore, last-resort safety checking */ - //if (status->rc_signal_lost) { - - control_attitude(manual.roll, manual.pitch, manual.yaw, - manual.throttle, &att, &state, ardrone_pub, &ar_control); - } - - } else { - - } - - if (counter % 30 == 0) { - if (led_counter == 0) ar_set_leds(ardrone_write, 0, 1, 0, 0, 0, 0, 0 , 0); - - if (led_counter == 1) ar_set_leds(ardrone_write, 1, 1, 0, 0, 0, 0, 0 , 0); - - if (led_counter == 2) ar_set_leds(ardrone_write, 1, 0, 0, 0, 0, 0, 0 , 0); - - if (led_counter == 3) ar_set_leds(ardrone_write, 0, 0, 0, 1, 0, 0, 0 , 0); - - if (led_counter == 4) ar_set_leds(ardrone_write, 0, 0, 1, 1, 0, 0, 0 , 0); - - if (led_counter == 5) ar_set_leds(ardrone_write, 0, 0, 1, 0, 0, 0, 0 , 0); - - if (led_counter == 6) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 1, 0 , 0); - - if (led_counter == 7) ar_set_leds(ardrone_write, 0, 0, 0, 0, 1, 1, 0 , 0); - - if (led_counter == 8) ar_set_leds(ardrone_write, 0, 0, 0, 0, 1, 0, 0 , 0); - - if (led_counter == 9) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 0 , 1); - - if (led_counter == 10) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 1 , 1); - - if (led_counter == 11) ar_set_leds(ardrone_write, 0, 0, 0, 0, 0, 0, 1 , 0); - - led_counter++; - - if (led_counter == 12) led_counter = 0; - } - - /* run at approximately 200 Hz */ - usleep(5000); - - // This is a hardcore debug code piece to validate - // the motor interface - // uint8_t motorSpeedBuf[5] = {1, 2, 3, 4, 5}; - // ar_get_motor_packet(motorSpeedBuf, 20, 20, 20, 20); - // write(ardrone_write, motorSpeedBuf, 5); - // usleep(15000); - - counter++; - } - - /* close uarts */ - close(ardrone_write); - ar_multiplexing_deinit(gpios); - - printf("[ardrone_control] ending now...\r\n"); - fflush(stdout); - return 0; -} - diff --git a/apps/multirotor_position_control/ardrone_control.h b/apps/multirotor_position_control/ardrone_control.h deleted file mode 100644 index 7f9567f861..0000000000 --- a/apps/multirotor_position_control/ardrone_control.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * ardrone_control.h - * - * Created on: Mar 23, 2012 - * Author: thomasgubler - */ - -#ifndef ARDRONE_CONTROL_H_ -#define ARDRONE_CONTROL_H_ - - -#endif /* ARDRONE_CONTROL_H_ */ diff --git a/apps/multirotor_position_control/ardrone_control_helper.c b/apps/multirotor_position_control/ardrone_control_helper.c deleted file mode 100644 index c073119e09..0000000000 --- a/apps/multirotor_position_control/ardrone_control_helper.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "ardrone_control_helper.h" -#include -#include -#include -#include - -// int read_sensors_raw(sensors_raw_t *sensors_raw) -// { -// static int ret; -// ret = global_data_wait(&global_data_sensors_raw->access_conf_rate_full); - -// if (ret == 0) { -// memcpy(sensors_raw->gyro_raw, global_data_sensors_raw->gyro_raw, sizeof(sensors_raw->gyro_raw)); -// // printf("Timestamp %d\n", &global_data_sensors_raw->timestamp); - -// } else { -// printf("Controller timeout, no new sensor values available\n"); -// } - -// global_data_unlock(&global_data_sensors_raw->access_conf_rate_full); -// return ret; -// } - -// int read_attitude(global_data_attitude_t *attitude) -// { - -// static int ret; -// ret = global_data_wait(&global_data_attitude->access_conf); - -// if (ret == 0) { -// memcpy(&attitude->roll, &global_data_attitude->roll, sizeof(global_data_attitude->roll)); -// memcpy(&attitude->pitch, &global_data_attitude->pitch, sizeof(global_data_attitude->pitch)); -// memcpy(&attitude->yaw, &global_data_attitude->yaw, sizeof(global_data_attitude->yaw)); -// memcpy(&attitude->rollspeed, &global_data_attitude->rollspeed, sizeof(global_data_attitude->rollspeed)); -// memcpy(&attitude->pitchspeed, &global_data_attitude->pitchspeed, sizeof(global_data_attitude->pitchspeed)); -// memcpy(&attitude->yawspeed, &global_data_attitude->yawspeed, sizeof(global_data_attitude->yawspeed)); - -// } else { -// printf("Controller timeout, no new attitude values available\n"); -// } - -// global_data_unlock(&global_data_attitude->access_conf); - - - -// return ret; -// } - -// void read_quad_motors_setpoint(quad_motors_setpoint_t *rate_setpoint) -// { - -// if (0 == global_data_trylock(&global_data_quad_motors_setpoint->access_conf)) { //TODO: check if trylock is the right choice, maybe only lock? -// rate_setpoint->motor_front_nw = global_data_quad_motors_setpoint->motor_front_nw; -// rate_setpoint->motor_right_ne = global_data_quad_motors_setpoint->motor_right_ne; -// rate_setpoint->motor_back_se = global_data_quad_motors_setpoint->motor_back_se; -// rate_setpoint->motor_left_sw = global_data_quad_motors_setpoint->motor_left_sw; - -// global_data_unlock(&global_data_quad_motors_setpoint->access_conf); -// } -// } diff --git a/apps/multirotor_position_control/ardrone_control_helper.h b/apps/multirotor_position_control/ardrone_control_helper.h deleted file mode 100644 index 22eebe986d..0000000000 --- a/apps/multirotor_position_control/ardrone_control_helper.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * ardrone_control_helper.h - * - * Created on: May 15, 2012 - * Author: thomasgubler - */ - -#ifndef ARDRONE_CONTROL_HELPER_H_ -#define ARDRONE_CONTROL_HELPER_H_ - -#include - -// typedef struct { -// int16_t gyro_raw[3]; // l3gd20 -// } sensors_raw_t; - -// /* Copy quad_motors_setpoint values from global memory to private variables */ //TODO: change this once the new mavlink message for rates is available -// void read_quad_motors_setpoint(quad_motors_setpoint_t *rate_setpoint); - - -#endif /* ARDRONE_CONTROL_HELPER_H_ */ diff --git a/apps/multirotor_position_control/ardrone_motor_control.c b/apps/multirotor_position_control/ardrone_motor_control.c deleted file mode 100644 index f13427eea7..0000000000 --- a/apps/multirotor_position_control/ardrone_motor_control.c +++ /dev/null @@ -1,281 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file ardrone_motor_control.c - * Implementation of AR.Drone 1.0 / 2.0 motor control interface - */ - - - -#include "ardrone_motor_control.h" - -static const unsigned long motor_gpios = GPIO_EXT_1 | GPIO_EXT_2 | GPIO_MULTI_1 | GPIO_MULTI_2; -static const unsigned long motor_gpio[4] = { GPIO_EXT_1, GPIO_EXT_2, GPIO_MULTI_1, GPIO_MULTI_2 }; - -typedef union { - uint16_t motor_value; - uint8_t bytes[2]; -} motor_union_t; - -/** - * @brief Generate the 8-byte motor set packet - * - * @return the number of bytes (8) - */ -void ar_get_motor_packet(uint8_t *motor_buf, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4) -{ - motor_buf[0] = 0x20; - motor_buf[1] = 0x00; - motor_buf[2] = 0x00; - motor_buf[3] = 0x00; - motor_buf[4] = 0x00; - /* - * {0x20, 0x00, 0x00, 0x00, 0x00}; - * 0x20 is start sign / motor command - */ - motor_union_t curr_motor; - uint16_t nineBitMask = 0x1FF; - - /* Set motor 1 */ - curr_motor.motor_value = (motor1 & nineBitMask) << 4; - motor_buf[0] |= curr_motor.bytes[1]; - motor_buf[1] |= curr_motor.bytes[0]; - - /* Set motor 2 */ - curr_motor.motor_value = (motor2 & nineBitMask) << 3; - motor_buf[1] |= curr_motor.bytes[1]; - motor_buf[2] |= curr_motor.bytes[0]; - - /* Set motor 3 */ - curr_motor.motor_value = (motor3 & nineBitMask) << 2; - motor_buf[2] |= curr_motor.bytes[1]; - motor_buf[3] |= curr_motor.bytes[0]; - - /* Set motor 4 */ - curr_motor.motor_value = (motor4 & nineBitMask) << 1; - motor_buf[3] |= curr_motor.bytes[1]; - motor_buf[4] |= curr_motor.bytes[0]; -} - -void ar_enable_broadcast(int fd) -{ - ar_select_motor(fd, 0); -} - -int ar_multiplexing_init() -{ - int fd; - - fd = open(GPIO_DEVICE_PATH, 0); - - if (fd < 0) { - printf("GPIO: open fail\n"); - return fd; - } - - /* deactivate all outputs */ - int ret = 0; - ret += ioctl(fd, GPIO_SET, motor_gpios); - - if (ioctl(fd, GPIO_SET_OUTPUT, motor_gpios) != 0) { - printf("GPIO: output set fail\n"); - close(fd); - return -1; - } - - if (ret < 0) { - printf("GPIO: clearing pins fail\n"); - close(fd); - return -1; - } - - return fd; -} - -int ar_multiplexing_deinit(int fd) -{ - if (fd < 0) { - printf("GPIO: no valid descriptor\n"); - return fd; - } - - int ret = 0; - - /* deselect motor 1-4 */ - ret += ioctl(fd, GPIO_SET, motor_gpios); - - if (ret != 0) { - printf("GPIO: clear failed %d times\n", ret); - } - - if (ioctl(fd, GPIO_SET_INPUT, motor_gpios) != 0) { - printf("GPIO: input set fail\n"); - return -1; - } - - close(fd); - - return ret; -} - -int ar_select_motor(int fd, uint8_t motor) -{ - int ret = 0; - unsigned long gpioset; - /* - * Four GPIOS: - * GPIO_EXT1 - * GPIO_EXT2 - * GPIO_UART2_CTS - * GPIO_UART2_RTS - */ - - /* select motor 0 to enable broadcast */ - if (motor == 0) { - /* select motor 1-4 */ - ret += ioctl(fd, GPIO_CLEAR, motor_gpios); - - } else { - /* deselect all */ - ret += ioctl(fd, GPIO_SET, motor_gpios); - - /* select reqested motor */ - ret += ioctl(fd, GPIO_CLEAR, motor_gpio[motor - 1]); - - /* deselect all others */ - // gpioset = motor_gpios ^ motor_gpio[motor - 1]; - // ret += ioctl(fd, GPIO_SET, gpioset); - } - - return ret; -} - -void ar_init_motors(int ardrone_uart, int *gpios_pin) -{ - /* Initialize multiplexing */ - *gpios_pin = ar_multiplexing_init(); - - /* Write ARDrone commands on UART2 */ - uint8_t initbuf[] = {0xE0, 0x91, 0xA1, 0x00, 0x40}; - uint8_t multicastbuf[] = {0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0}; - - /* initialize all motors - * - select one motor at a time - * - configure motor - */ - int i; - int errcounter = 0; - - for (i = 1; i < 5; ++i) { - /* Initialize motors 1-4 */ - initbuf[3] = i; - errcounter += ar_select_motor(*gpios_pin, i); - - write(ardrone_uart, initbuf + 0, 1); - - /* sleep 400 ms */ - usleep(200000); - usleep(200000); - - write(ardrone_uart, initbuf + 1, 1); - /* wait 50 ms */ - usleep(50000); - - write(ardrone_uart, initbuf + 2, 1); - /* wait 50 ms */ - usleep(50000); - - write(ardrone_uart, initbuf + 3, 1); - /* wait 50 ms */ - usleep(50000); - - write(ardrone_uart, initbuf + 4, 1); - /* wait 50 ms */ - usleep(50000); - - /* enable multicast */ - write(ardrone_uart, multicastbuf + 0, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 1, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 2, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 3, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 4, 1); - /* wait 1 ms */ - usleep(1000); - - write(ardrone_uart, multicastbuf + 5, 1); - /* wait 5 ms */ - usleep(50000); - } - - /* start the multicast part */ - errcounter += ar_select_motor(*gpios_pin, 0); - - if (errcounter != 0) { - printf("AR: init sequence incomplete, failed %d times", -errcounter); - fflush(stdout); - } -} - -/* - * Sets the leds on the motor controllers, 1 turns led on, 0 off. - */ -void ar_set_leds(int ardrone_uart, uint8_t led1_red, uint8_t led1_green, uint8_t led2_red, uint8_t led2_green, uint8_t led3_red, uint8_t led3_green, uint8_t led4_red, uint8_t led4_green) -{ - /* - * 2 bytes are sent. The first 3 bits describe the command: 011 means led control - * the following 4 bits are the red leds for motor 4, 3, 2, 1 - * then 4 bits with unknown function, then 4 bits for green leds for motor 4, 3, 2, 1 - * the last bit is unknown. - * - * The packet is therefore: - * 011 rrrr 0000 gggg 0 - */ - uint8_t leds[2]; - leds[0] = 0x60 | ((led4_red & 0x01) << 4) | ((led3_red & 0x01) << 3) | ((led2_red & 0x01) << 2) | ((led1_red & 0x01) << 1); - leds[1] = ((led4_green & 0x01) << 4) | ((led3_green & 0x01) << 3) | ((led2_green & 0x01) << 2) | ((led1_green & 0x01) << 1); - write(ardrone_uart, leds, 2); -} diff --git a/apps/multirotor_position_control/ardrone_motor_control.h b/apps/multirotor_position_control/ardrone_motor_control.h deleted file mode 100644 index bf41e3f3b4..0000000000 --- a/apps/multirotor_position_control/ardrone_motor_control.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * px4/ardrone_offboard_control.h - * - * Copyright (C) 2012 PX4 Autopilot Project. All rights reserved. - * Author: Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include - - -/** - * @brief Generate the 8-byte motor set packet - * - * @return the number of bytes (8) - */ -void ar_get_motor_packet(uint8_t *motor_buf, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4); - -int ar_select_motor(int fd, uint8_t motor); - -void ar_enable_broadcast(int fd); - -int ar_multiplexing_init(void); -int ar_multiplexing_deinit(int fd); - -void ar_init_motors(int ardrone_uart, int *gpios_uart); - -void ar_set_leds(int ardrone_uart, uint8_t led1_red, uint8_t led1_green, uint8_t led2_red, uint8_t led2_green, uint8_t led3_red, uint8_t led3_green, uint8_t led4_red, uint8_t led4_green); - diff --git a/apps/multirotor_position_control/attitude_control.c b/apps/multirotor_position_control/attitude_control.c deleted file mode 100644 index 8bcd33ede6..0000000000 --- a/apps/multirotor_position_control/attitude_control.c +++ /dev/null @@ -1,459 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * Laurens Mackay - * Tobias Naegeli - * Martin Rutschmann - * Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file Implementation of attitude controller - */ - -#include "attitude_control.h" -#include -#include -#include -#include -#include -#include //TODO: move matrix.h to somewhere else? -#include "ardrone_motor_control.h" -#include -#include -#include "pid.h" -#include - -extern int ardrone_write; -extern int gpios; - -#define CONTROL_PID_ATTITUDE_INTERVAL 5e-3f - -void turn_xy_plane(const float_vect3 *vector, float yaw, - float_vect3 *result); -void navi2body_xy_plane(const float_vect3 *vector, const float yaw, - float_vect3 *result); - -void turn_xy_plane(const float_vect3 *vector, float yaw, - float_vect3 *result) -{ - //turn clockwise - static uint16_t counter; - - result->x = (cosf(yaw) * vector->x + sinf(yaw) * vector->y); - result->y = (-sinf(yaw) * vector->x + cosf(yaw) * vector->y); - result->z = vector->z; //leave direction normal to xy-plane untouched - - counter++; -} - -void navi2body_xy_plane(const float_vect3 *vector, const float yaw, - float_vect3 *result) -{ - turn_xy_plane(vector, yaw, result); -// result->x = vector->x; -// result->y = vector->y; -// result->z = vector->z; - // result->x = cos(yaw) * vector->x + sin(yaw) * vector->y; - // result->y = -sin(yaw) * vector->x + cos(yaw) * vector->y; - // result->z = vector->z; //leave direction normal to xy-plane untouched -} - -void control_attitude(float roll, float pitch, float yaw, float thrust, const struct vehicle_attitude_s *att, const struct vehicle_status_s *status, int ardrone_pub, struct ardrone_control_s *ar_control) -{ - static int motor_skip_counter = 0; - - static PID_t yaw_pos_controller; - static PID_t yaw_speed_controller; - static PID_t nick_controller; - static PID_t roll_controller; - - const float min_thrust = 0.02f; /**< 2% minimum thrust */ - const float max_thrust = 1.0f; /**< 100% max thrust */ - const float scaling = 512.0f; /**< 100% thrust equals a value of 512 */ - - const float min_gas = min_thrust * scaling; - const float max_gas = max_thrust * scaling; - - static uint16_t motor_pwm[4] = {0, 0, 0, 0}; - static float motor_calc[4] = {0.0f, 0.0f, 0.0f, 0.0f}; -// static float remote_control_weight_z = 1; -// static float position_control_weight_z = 0; - - static float pid_yawpos_lim; - static float pid_yawspeed_lim; - static float pid_att_lim; - - static bool initialized; - - static float_vect3 attitude_setpoint_navigationframe_from_positioncontroller; - static commander_state_machine_t current_state; - - /* initialize the pid controllers when the function is called for the first time */ - if (initialized == false) { - - pid_init(&yaw_pos_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_AWU], - PID_MODE_DERIVATIV_CALC, 154); - - pid_init(&yaw_speed_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_AWU], - PID_MODE_DERIVATIV_CALC, 155); - - pid_init(&nick_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU], - PID_MODE_DERIVATIV_SET, 156); - - pid_init(&roll_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU], - PID_MODE_DERIVATIV_SET, 157); - - pid_yawpos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_LIM]; - pid_yawspeed_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_LIM]; - pid_att_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_LIM]; - - //TODO: true initialization? get gps while on ground? - attitude_setpoint_navigationframe_from_positioncontroller.x = 0.0f; - attitude_setpoint_navigationframe_from_positioncontroller.y = 0.0f; - attitude_setpoint_navigationframe_from_positioncontroller.z = 0.0f; - - initialized = true; - } - - /* load new parameters with lower rate */ - if (motor_skip_counter % 50 == 0) { - pid_set_parameters(&yaw_pos_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_AWU]); - - pid_set_parameters(&yaw_speed_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_AWU]); - - pid_set_parameters(&nick_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]); - - pid_set_parameters(&roll_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_AWU]); - - pid_yawpos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_YAWPOS_LIM]; - pid_yawspeed_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_YAWSPEED_LIM]; - pid_att_lim = (max_gas - min_gas) * global_data_parameter_storage->pm.param_values[PARAM_PID_ATT_LIM]; - } - - current_state = status->state_machine; - float_vect3 attitude_setpoint_bodyframe = {.x = 0.0f, .y = 0.0f, .z = 0.0f}; //this is the setpoint in the bodyframe "mixed" together from the setpoint from the remote and the setpoint from the position controller - - if (current_state == SYSTEM_STATE_AUTO) { - - attitude_setpoint_navigationframe_from_positioncontroller.x = ar_control->attitude_setpoint_navigationframe_from_positioncontroller[0]; - attitude_setpoint_navigationframe_from_positioncontroller.y = ar_control->attitude_setpoint_navigationframe_from_positioncontroller[1]; - attitude_setpoint_navigationframe_from_positioncontroller.z = ar_control->attitude_setpoint_navigationframe_from_positioncontroller[2]; - - float yaw_e = att->yaw - attitude_setpoint_navigationframe_from_positioncontroller.z; - - // don't turn around the wrong side (only works if yaw angle is between +- 180 degree) - if (yaw_e > M_PI_F) { - yaw_e -= 2.0f * M_PI_F; - } - - if (yaw_e < -M_PI_F) { - yaw_e += 2.0f * M_PI_F; - } - - attitude_setpoint_navigationframe_from_positioncontroller.z = pid_calculate(&yaw_pos_controller, 0.0f, yaw_e, 0.0f, CONTROL_PID_ATTITUDE_INTERVAL); - - - /* limit control output */ - if (attitude_setpoint_navigationframe_from_positioncontroller.z > pid_yawpos_lim) { - attitude_setpoint_navigationframe_from_positioncontroller.z = pid_yawpos_lim; - yaw_pos_controller.saturated = 1; - } - - if (attitude_setpoint_navigationframe_from_positioncontroller.z < -pid_yawpos_lim) { - attitude_setpoint_navigationframe_from_positioncontroller.z = -pid_yawpos_lim; - yaw_pos_controller.saturated = 1; - } - - //transform attitude setpoint from position controller from navi to body frame on xy_plane - float_vect3 attitude_setpoint_bodyframe_from_positioncontroller; - navi2body_xy_plane(&attitude_setpoint_navigationframe_from_positioncontroller, att->yaw , &attitude_setpoint_bodyframe_from_positioncontroller); //yaw angle= att->yaw - //now everything is in body frame - - - //TODO: here we decide which input (position controller or ppm) we use. For now we have only the ppm, this should be decided dpending on the state machione (manula or auto) ppm should always overwrite auto (?) - attitude_setpoint_bodyframe.x = attitude_setpoint_bodyframe_from_positioncontroller.x; - attitude_setpoint_bodyframe.y = attitude_setpoint_bodyframe_from_positioncontroller.y; - attitude_setpoint_bodyframe.z = attitude_setpoint_bodyframe_from_positioncontroller.z; - - } else if (current_state == SYSTEM_STATE_MANUAL) { - attitude_setpoint_bodyframe.x = -roll * M_PI_F / 8.0f; - attitude_setpoint_bodyframe.y = -pitch * M_PI_F / 8.0f; - attitude_setpoint_bodyframe.z = -yaw * M_PI_F; - } - - /* add an attitude offset which needs to be estimated somewhere */ - attitude_setpoint_bodyframe.x += global_data_parameter_storage->pm.param_values[PARAM_ATT_XOFFSET]; - attitude_setpoint_bodyframe.y += global_data_parameter_storage->pm.param_values[PARAM_ATT_YOFFSET]; - - /*Calculate Controllers*/ - //control Nick - float nick_control = pid_calculate(&nick_controller, attitude_setpoint_bodyframe.y, att->pitch, att->pitchspeed, CONTROL_PID_ATTITUDE_INTERVAL); - //control Roll - float roll_control = pid_calculate(&roll_controller, attitude_setpoint_bodyframe.x, att->roll, att->rollspeed, CONTROL_PID_ATTITUDE_INTERVAL); - //control Yaw Speed - float yaw_rate_control = pid_calculate(&yaw_speed_controller, attitude_setpoint_bodyframe.z, att->yawspeed, 0.0f, CONTROL_PID_ATTITUDE_INTERVAL); //attitude_setpoint_bodyframe.z is yaw speed! - - /* - * compensate the vertical loss of thrust - * when thrust plane has an angle. - * start with a factor of 1.0 (no change) - */ - float zcompensation = 1.0f; - - if (fabsf(att->roll) > 1.0f) { - zcompensation *= 1.85081571768f; - - } else { - zcompensation *= 1.0f / cosf(att->roll); - } - - if (fabsf(att->pitch) > 1.0f) { - zcompensation *= 1.85081571768f; - - } else { - zcompensation *= 1.0f / cosf(att->pitch); - } - - // use global_data.position_control_output.z and mix parameter global_data.param[PARAM_MIX_POSITION_Z_WEIGHT] - // to compute thrust for Z position control - // - // float motor_thrust = min_gas + - // ( ( 1 - global_data.param[PARAM_MIX_POSITION_Z_WEIGHT] ) * ( max_gas - min_gas ) * global_data.gas_remote * zcompensation ) - // + ( global_data.param[PARAM_MIX_POSITION_Z_WEIGHT] * ( max_gas - min_gas ) * controlled_thrust * zcompensation ); - //calculate the basic thrust - - - - float motor_thrust = 0; - - // FLYING MODES - if (current_state == SYSTEM_STATE_MANUAL) { - motor_thrust = thrust; - - } else if (current_state == SYSTEM_STATE_GROUND_READY || - current_state == SYSTEM_STATE_STABILIZED || - current_state == SYSTEM_STATE_AUTO || - current_state == SYSTEM_STATE_MISSION_ABORT) { - motor_thrust = thrust; //TODO - - } else if (current_state == SYSTEM_STATE_EMCY_LANDING) { - motor_thrust = thrust; //TODO - - } else if (current_state == SYSTEM_STATE_EMCY_CUTOFF) { - /* immediately cut off motors */ - motor_thrust = 0; - - } else { - /* limit motor throttle to zero for an unknown mode */ - motor_thrust = 0; - } - - printf("t1:%1.3f "); - - /* compensate thrust vector for roll / pitch contributions */ - motor_thrust *= zcompensation; - - printf("t2:%1.3f\n"); - - /* limit yaw rate output */ - if (yaw_rate_control > pid_yawspeed_lim) { - yaw_rate_control = pid_yawspeed_lim; - yaw_speed_controller.saturated = 1; - } - - if (yaw_rate_control < -pid_yawspeed_lim) { - yaw_rate_control = -pid_yawspeed_lim; - yaw_speed_controller.saturated = 1; - } - - if (nick_control > pid_att_lim) { - nick_control = pid_att_lim; - nick_controller.saturated = 1; - } - - if (nick_control < -pid_att_lim) { - nick_control = -pid_att_lim; - nick_controller.saturated = 1; - } - - - if (roll_control > pid_att_lim) { - roll_control = pid_att_lim; - roll_controller.saturated = 1; - } - - if (roll_control < -pid_att_lim) { - roll_control = -pid_att_lim; - roll_controller.saturated = 1; - } - - /* Emit controller values */ - ar_control->setpoint_thrust_cast = motor_thrust; - ar_control->setpoint_attitude[0] = attitude_setpoint_bodyframe.x; - ar_control->setpoint_attitude[1] = attitude_setpoint_bodyframe.y; - ar_control->setpoint_attitude[2] = attitude_setpoint_bodyframe.z; - ar_control->attitude_control_output[0] = roll_control; - ar_control->attitude_control_output[1] = nick_control; - ar_control->attitude_control_output[2] = yaw_rate_control; - ar_control->zcompensation = zcompensation; - orb_publish(ORB_ID(ardrone_control), ardrone_pub, ar_control); - - float output_band = 0.f; - float band_factor = 0.75f; - const float startpoint_full_control = 0.25f; /**< start full control at 25% thrust */ - float yaw_factor = 1.0f; - - if (motor_thrust <= min_thrust) { - motor_thrust = min_thrust; - output_band = 0.f; - - } else if (motor_thrust < startpoint_full_control && motor_thrust > min_thrust) { - output_band = band_factor * (motor_thrust - min_thrust); - - } else if (motor_thrust >= startpoint_full_control && motor_thrust < max_thrust - band_factor * startpoint_full_control) { - output_band = band_factor * startpoint_full_control; - - } else if (motor_thrust >= max_thrust - band_factor * startpoint_full_control) { - output_band = band_factor * (max_thrust - motor_thrust); - } - - //add the yaw, nick and roll components to the basic thrust //TODO:this should be done by the mixer - - // FRONT (MOTOR 1) - motor_calc[0] = motor_thrust + (roll_control / 2 + nick_control / 2 - yaw_rate_control); - - // RIGHT (MOTOR 2) - motor_calc[1] = motor_thrust + (-roll_control / 2 + nick_control / 2 + yaw_rate_control); - - // BACK (MOTOR 3) - motor_calc[2] = motor_thrust + (-roll_control / 2 - nick_control / 2 - yaw_rate_control); - - // LEFT (MOTOR 4) - motor_calc[3] = motor_thrust + (roll_control / 2 - nick_control / 2 + yaw_rate_control); - - // if we are not in the output band - if (!(motor_calc[0] < motor_thrust + output_band && motor_calc[0] > motor_thrust - output_band - && motor_calc[1] < motor_thrust + output_band && motor_calc[1] > motor_thrust - output_band - && motor_calc[2] < motor_thrust + output_band && motor_calc[2] > motor_thrust - output_band - && motor_calc[3] < motor_thrust + output_band && motor_calc[3] > motor_thrust - output_band)) { - - yaw_factor = 0.5f; - // FRONT (MOTOR 1) - motor_calc[0] = motor_thrust + (roll_control / 2 + nick_control / 2 - yaw_rate_control * yaw_factor); - - // RIGHT (MOTOR 2) - motor_calc[1] = motor_thrust + (-roll_control / 2 + nick_control / 2 + yaw_rate_control * yaw_factor); - - // BACK (MOTOR 3) - motor_calc[2] = motor_thrust + (-roll_control / 2 - nick_control / 2 - yaw_rate_control * yaw_factor); - - // LEFT (MOTOR 4) - motor_calc[3] = motor_thrust + (roll_control / 2 - nick_control / 2 + yaw_rate_control * yaw_factor); - } - - for (int i = 0; i < 4; i++) { - //check for limits - if (motor_calc[i] < motor_thrust - output_band) { - motor_calc[i] = motor_thrust - output_band; - } - - if (motor_calc[i] > motor_thrust + output_band) { - motor_calc[i] = motor_thrust + output_band; - } - } - - /* set the motor values */ - - /* scale up from 0..1 to 10..512) */ - motor_pwm[0] = (uint16_t) motor_calc[0] * ((float)max_gas - min_gas) + min_gas; - motor_pwm[1] = (uint16_t) motor_calc[1] * ((float)max_gas - min_gas) + min_gas; - motor_pwm[2] = (uint16_t) motor_calc[2] * ((float)max_gas - min_gas) + min_gas; - motor_pwm[3] = (uint16_t) motor_calc[3] * ((float)max_gas - min_gas) + min_gas; - - /* Keep motors spinning while armed and prevent overflows */ - - /* Failsafe logic - should never be necessary */ - motor_pwm[0] = (motor_pwm[0] > 0) ? motor_pwm[0] : 10; - motor_pwm[1] = (motor_pwm[1] > 0) ? motor_pwm[1] : 10; - motor_pwm[2] = (motor_pwm[2] > 0) ? motor_pwm[2] : 10; - motor_pwm[3] = (motor_pwm[3] > 0) ? motor_pwm[3] : 10; - - /* Failsafe logic - should never be necessary */ - motor_pwm[0] = (motor_pwm[0] <= 512) ? motor_pwm[0] : 512; - motor_pwm[1] = (motor_pwm[1] <= 512) ? motor_pwm[1] : 512; - motor_pwm[2] = (motor_pwm[2] <= 512) ? motor_pwm[2] : 512; - motor_pwm[3] = (motor_pwm[3] <= 512) ? motor_pwm[3] : 512; - - /* send motors via UART */ - if (motor_skip_counter % 5 == 0) { - uint8_t motorSpeedBuf[5] = {1, 2, 3, 4, 5}; - ar_get_motor_packet(motorSpeedBuf, motor_pwm[0], motor_pwm[1], motor_pwm[2], motor_pwm[3]); - write(ardrone_write, motorSpeedBuf, 5); - } - - motor_skip_counter++; - -} diff --git a/apps/multirotor_position_control/pid.c b/apps/multirotor_position_control/pid.c deleted file mode 100644 index 5ce05670e3..0000000000 --- a/apps/multirotor_position_control/pid.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "pid.h" - -#include //TODO: move matrix.h to somewhere else? - -void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, - uint8_t mode, uint8_t plot_i) -{ - pid->kp = kp; - pid->ki = ki; - pid->kd = kd; - pid->intmax = intmax; - pid->mode = mode; - pid->plot_i = plot_i; - pid->count = 0; - pid->saturated = 0; - - pid->sp = 0; - pid->error_previous = 0; - pid->integral = 0; -} -void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax) -{ - pid->kp = kp; - pid->ki = ki; - pid->kd = kd; - pid->intmax = intmax; - // pid->mode = mode; - - // pid->sp = 0; - // pid->error_previous = 0; - // pid->integral = 0; -} - -//void pid_set(PID_t *pid, float sp) -//{ -// pid->sp = sp; -// pid->error_previous = 0; -// pid->integral = 0; -//} - -/** - * - * @param pid - * @param val - * @param dt - * @return - */ -float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt) -{ - /* error = setpoint - actual_position - integral = integral + (error*dt) - derivative = (error - previous_error)/dt - output = (Kp*error) + (Ki*integral) + (Kd*derivative) - previous_error = error - wait(dt) - goto start - */ - - float i, d; - pid->sp = sp; - float error = pid->sp - val; - - if (pid->saturated && (pid->integral * error > 0)) { - //Output is saturated and the integral would get bigger (positive or negative) - i = pid->integral; - - //Reset saturation. If we are still saturated this will be set again at output limit check. - pid->saturated = 0; - - } else { - i = pid->integral + (error * dt); - } - - // Anti-Windup. Needed if we don't use the saturation above. - if (pid->intmax != 0.0) { - if (i > pid->intmax) { - pid->integral = pid->intmax; - - } else if (i < -pid->intmax) { - - pid->integral = -pid->intmax; - - } else { - pid->integral = i; - } - - //Send Controller integrals - // Disabled because of new possibilities with debug_vect. - // Now sent in Main Loop at 5 Hz. 26.06.2010 Laurens - // if (pid->plot_i && (pid->count++ % 16 == 0)&&(global_data.param[PARAM_SEND_SLOT_DEBUG_2] == 1)) - // { - // mavlink_msg_debug_send(MAVLINK_COMM_1, pid->plot_i, pid->integral); - // } - } - - if (pid->mode == PID_MODE_DERIVATIV_CALC) { - d = (error - pid->error_previous) / dt; - - } else if (pid->mode == PID_MODE_DERIVATIV_SET) { - d = -val_dot; - - } else { - d = 0; - } - - pid->error_previous = error; - - return (error * pid->kp) + (i * pid->ki) + (d * pid->kd); -} diff --git a/apps/multirotor_position_control/pid.h b/apps/multirotor_position_control/pid.h deleted file mode 100644 index a721c839c6..0000000000 --- a/apps/multirotor_position_control/pid.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * pid.h - * - * Created on: May 29, 2012 - * Author: thomasgubler - */ - -#ifndef PID_H_ -#define PID_H_ - -#include - -/* PID_MODE_DERIVATIV_CALC calculates discrete derivative from previous error - * val_dot in pid_calculate() will be ignored */ -#define PID_MODE_DERIVATIV_CALC 0 -/* Use PID_MODE_DERIVATIV_SET if you have the derivative already (Gyros, Kalman) */ -#define PID_MODE_DERIVATIV_SET 1 - -typedef struct { - float kp; - float ki; - float kd; - float intmax; - float sp; - float integral; - float error_previous; - uint8_t mode; - uint8_t plot_i; - uint8_t count; - uint8_t saturated; -} PID_t; - -void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, uint8_t mode, uint8_t plot_i); -void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax); -//void pid_set(PID_t *pid, float sp); -float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt); - - - -#endif /* PID_H_ */ diff --git a/apps/multirotor_position_control/position_control.c b/apps/multirotor_position_control/position_control.c deleted file mode 100644 index 6ba1654595..0000000000 --- a/apps/multirotor_position_control/position_control.c +++ /dev/null @@ -1,308 +0,0 @@ -/**************************************************************************** - * ardrone_control/position_control.c - * - * Copyright (C) 2008, 2012 Thomas Gubler, Julian Oes, Lorenz Meier. All rights reserved. - * Author: Based on the pixhawk quadrotor controller - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#include "position_control.h" -#include -#include -#include -#include -#include -#include -#include -#include "pid.h" - -#ifndef FM_PI -#define FM_PI 3.1415926535897932384626433832795f -#endif - - - -#define CONTROL_PID_POSITION_INTERVAL 0.020 - -int read_lock_position(global_data_position_t *position) -{ - static int ret; - ret = global_data_wait(&global_data_position->access_conf); - - if (ret == 0) { - memcpy(&position->lat, &global_data_position->lat, sizeof(global_data_position->lat)); - memcpy(&position->lon, &global_data_position->lon, sizeof(global_data_position->lon)); - memcpy(&position->alt, &global_data_position->alt, sizeof(global_data_position->alt)); - memcpy(&position->relative_alt, &global_data_position->relative_alt, sizeof(global_data_position->relative_alt)); - memcpy(&position->vx, &global_data_position->vx, sizeof(global_data_position->vx)); - memcpy(&position->vy, &global_data_position->vy, sizeof(global_data_position->vy)); - memcpy(&position->vz, &global_data_position->vz, sizeof(global_data_position->vz)); - memcpy(&position->hdg, &global_data_position->hdg, sizeof(global_data_position->hdg)); - - - } else { - printf("Controller timeout, no new position values available\n"); - } - - global_data_unlock(&global_data_position->access_conf); - return ret; -} - -float get_distance_to_next_waypoint(float lat_now, float lon_now, float lat_next, float lon_next) -{ - double lat_now_rad = lat_now / 180.0 * M_PI; - double lon_now_rad = lon_now / 180.0 * M_PI; - double lat_next_rad = lat_next / 180.0 * M_PI; - double lon_next_rad = lon_next / 180.0 * M_PI; - - - double d_lat = lat_next_rad - lat_now_rad; - double d_lon = lon_next_rad - lon_now_rad; - - double a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat_now_rad) * cos(lat_next_rad); - double c = 2 * atan2(sqrt(a), sqrt(1 - a)); - - const double radius_earth = 6371000.0; - - return radius_earth * c; -} - -float get_bearing_to_next_waypoint(float lat_now, float lon_now, float lat_next, float lon_next) -{ - double lat_now_rad = lat_now / 180.0 * M_PI; - double lon_now_rad = lon_now / 180.0 * M_PI; - double lat_next_rad = lat_next / 180.0 * M_PI; - double lon_next_rad = lon_next / 180.0 * M_PI; - - double d_lat = lat_next_rad - lat_now_rad; - double d_lon = lon_next_rad - lon_now_rad; - - - float theta = atan2f(sin(d_lon) * cos(lat_next_rad) , cos(lat_now_rad) * sin(lat_next_rad) - sin(lat_now_rad) * cos(lat_next_rad) * cos(d_lon)); - - if (theta < 0) { - theta = theta + 2 * FM_PI; - } - - return theta; -} - -void control_position(void) -{ - static PID_t distance_controller; - - static int read_ret; - static global_data_position_t position_estimated; - - static uint16_t counter; - - static bool initialized; - static uint16_t pm_counter; - - static float lat_next; - static float lon_next; - - static float pitch_current; - - static float thrust_total; - - - if (initialized == false) { - - global_data_lock(&global_data_parameter_storage->access_conf); - - pid_init(&distance_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_AWU], - PID_MODE_DERIVATIV_CALC, 150);//150 - -// pid_pos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_LIM]; -// pid_pos_z_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_Z_LIM]; - - pm_counter = global_data_parameter_storage->counter; - - global_data_unlock(&global_data_parameter_storage->access_conf); - - thrust_total = 0.0f; - - /* Position initialization */ - /* Wait for new position estimate */ - do { - read_ret = read_lock_position(&position_estimated); - } while (read_ret != 0); - - lat_next = position_estimated.lat; - lon_next = position_estimated.lon; - - /* attitude initialization */ - global_data_lock(&global_data_attitude->access_conf); - pitch_current = global_data_attitude->pitch; - global_data_unlock(&global_data_attitude->access_conf); - - initialized = true; - } - - /* load new parameters with 10Hz */ - if (counter % 50 == 0) { - if (global_data_trylock(&global_data_parameter_storage->access_conf) == 0) { - /* check whether new parameters are available */ - if (global_data_parameter_storage->counter > pm_counter) { - pid_set_parameters(&distance_controller, - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_P], - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_I], - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_D], - global_data_parameter_storage->pm.param_values[PARAM_PID_POS_AWU]); - -// -// pid_pos_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_LIM]; -// pid_pos_z_lim = global_data_parameter_storage->pm.param_values[PARAM_PID_POS_Z_LIM]; - - pm_counter = global_data_parameter_storage->counter; - printf("Position controller changed pid parameters\n"); - } - } - - global_data_unlock(&global_data_parameter_storage->access_conf); - } - - - /* Wait for new position estimate */ - do { - read_ret = read_lock_position(&position_estimated); - } while (read_ret != 0); - - /* Get next waypoint */ //TODO: add local copy - - if (0 == global_data_trylock(&global_data_position_setpoint->access_conf)) { - lat_next = global_data_position_setpoint->x; - lon_next = global_data_position_setpoint->y; - global_data_unlock(&global_data_position_setpoint->access_conf); - } - - /* Get distance to waypoint */ - float distance_to_waypoint = get_distance_to_next_waypoint(position_estimated.lat , position_estimated.lon, lat_next, lon_next); -// if(counter % 5 == 0) -// printf("distance_to_waypoint: %.4f\n", distance_to_waypoint); - - /* Get bearing to waypoint (direction on earth surface to next waypoint) */ - float bearing = get_bearing_to_next_waypoint(position_estimated.lat, position_estimated.lon, lat_next, lon_next); - - if (counter % 5 == 0) - printf("bearing: %.4f\n", bearing); - - /* Calculate speed in direction of bearing (needed for controller) */ - float speed_norm = sqrtf(position_estimated.vx * position_estimated.vx + position_estimated.vy * position_estimated.vy); -// if(counter % 5 == 0) -// printf("speed_norm: %.4f\n", speed_norm); - float speed_to_waypoint = 0; //(position_estimated.vx * cosf(bearing) + position_estimated.vy * sinf(bearing))/speed_norm; //FIXME, TODO: re-enable this once we have a full estimate of the speed, then we can do a PID for the distance controller - - /* Control Thrust in bearing direction */ - float horizontal_thrust = -pid_calculate(&distance_controller, 0, distance_to_waypoint, speed_to_waypoint, - CONTROL_PID_POSITION_INTERVAL); //TODO: maybe this "-" sign is an error somewhere else - -// if(counter % 5 == 0) -// printf("horizontal thrust: %.4f\n", horizontal_thrust); - - /* Get total thrust (from remote for now) */ - if (0 == global_data_trylock(&global_data_rc_channels->access_conf)) { - thrust_total = (float)global_data_rc_channels->chan[THROTTLE].scale; //TODO: how should we use the RC_CHANNELS_FUNCTION enum? - global_data_unlock(&global_data_rc_channels->access_conf); - } - - const float max_gas = 500.0f; - thrust_total *= max_gas / 20000.0f; //TODO: check this - thrust_total += max_gas / 2.0f; - - - if (horizontal_thrust > thrust_total) { - horizontal_thrust = thrust_total; - - } else if (horizontal_thrust < -thrust_total) { - horizontal_thrust = -thrust_total; - } - - - - //TODO: maybe we want to add a speed controller later... - - /* Calclulate thrust in east and north direction */ - float thrust_north = cosf(bearing) * horizontal_thrust; - float thrust_east = sinf(bearing) * horizontal_thrust; - - if (counter % 10 == 0) { - printf("thrust north: %.4f\n", thrust_north); - printf("thrust east: %.4f\n", thrust_east); - fflush(stdout); - } - - /* Get current attitude */ - if (0 == global_data_trylock(&global_data_attitude->access_conf)) { - pitch_current = global_data_attitude->pitch; - global_data_unlock(&global_data_attitude->access_conf); - } - - /* Get desired pitch & roll */ - float pitch_desired = 0.0f; - float roll_desired = 0.0f; - - if (thrust_total != 0) { - float pitch_fraction = -thrust_north / thrust_total; - float roll_fraction = thrust_east / (cosf(pitch_current) * thrust_total); - - if (roll_fraction < -1) { - roll_fraction = -1; - - } else if (roll_fraction > 1) { - roll_fraction = 1; - } - -// if(counter % 5 == 0) -// { -// printf("pitch_fraction: %.4f, roll_fraction: %.4f\n",pitch_fraction, roll_fraction); -// fflush(stdout); -// } - - pitch_desired = asinf(pitch_fraction); - roll_desired = asinf(roll_fraction); - } - - /*Broadcast desired angles */ - global_data_lock(&global_data_ardrone_control->access_conf); - global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller[0] = roll_desired; - global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller[1] = pitch_desired; - global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller[2] = bearing; //TODO: add yaw setpoint - global_data_unlock(&global_data_ardrone_control->access_conf); - global_data_broadcast(&global_data_ardrone_control->access_conf); - - - counter++; -} diff --git a/apps/multirotor_position_control/position_control.h b/apps/multirotor_position_control/position_control.h deleted file mode 100644 index dbc0650e66..0000000000 --- a/apps/multirotor_position_control/position_control.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * position_control.h - * - * Created on: May 29, 2012 - * Author: thomasgubler - */ - -#ifndef POSITION_CONTROL_H_ -#define POSITION_CONTROL_H_ - -void control_position(void); - -#endif /* POSITION_CONTROL_H_ */ diff --git a/apps/multirotor_position_control/rate_control.c b/apps/multirotor_position_control/rate_control.c deleted file mode 100644 index 4abba62556..0000000000 --- a/apps/multirotor_position_control/rate_control.c +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Tobias Naegeli - * Lorenz Meier - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* - * @file Implementation of attitude rate control - */ - -#include "rate_control.h" -#include "ardrone_control_helper.h" -#include "ardrone_motor_control.h" -#include - -extern int ardrone_write; -extern int gpios; - -typedef struct { - uint16_t motor_front_nw; ///< Front motor in + configuration, front left motor in x configuration - uint16_t motor_right_ne; ///< Right motor in + configuration, front right motor in x configuration - uint16_t motor_back_se; ///< Back motor in + configuration, back right motor in x configuration - uint16_t motor_left_sw; ///< Left motor in + configuration, back left motor in x configuration - uint8_t target_system; ///< System ID of the system that should set these motor commands -} quad_motors_setpoint_t; - - -void control_rates(struct sensor_combined_s *raw, struct ardrone_motors_setpoint_s *setpoints) -{ - static quad_motors_setpoint_t actuators_desired; - //static quad_motors_setpoint_t quad_motors_setpoint_desired; - - static int16_t outputBand = 0; - -// static uint16_t control_counter; - static hrt_abstime now_time; - static hrt_abstime last_time; - - static float setpointXrate; - static float setpointYrate; - static float setpointZrate; - - static float setpointRateCast[3]; - static float Kp; -// static float Ki; - static float setpointThrustCast; - static float startpointFullControll; - static float maxThrustSetpoints; - - static float gyro_filtered[3]; - static float gyro_filtered_offset[3]; - static float gyro_alpha; - static float gyro_alpha_offset; -// static float errXrate; - static float attRatesScaled[3]; - - static uint16_t offsetCnt; -// static float antiwindup; - static int motor_skip_counter; - - static int read_ret; - - static bool initialized; - - if (initialized == false) { - initialized = true; - - /* Read sensors for initial values */ - - gyro_filtered_offset[0] = 0.00026631611f * (float)raw->gyro_raw[0]; - gyro_filtered_offset[1] = 0.00026631611f * (float)raw->gyro_raw[1]; - gyro_filtered_offset[2] = 0.00026631611f * (float)raw->gyro_raw[2]; - - gyro_filtered[0] = 0.00026631611f * (float)raw->gyro_raw[0]; - gyro_filtered[1] = 0.00026631611f * (float)raw->gyro_raw[1]; - gyro_filtered[2] = 0.00026631611f * (float)raw->gyro_raw[2]; - - outputBand = 0; - startpointFullControll = 150.0f; - maxThrustSetpoints = 511.0f; - //Kp=60; - //Kp=40.0f; - //Kp=45; - Kp = 30.0f; -// Ki=0.0f; -// antiwindup=50.0f; - } - - /* Get setpoint */ - - - //Rate Controller - setpointRateCast[0] = -((float)setpoints->motor_right_ne - 9999.0f) * 0.01f / 180.0f * 3.141f; - setpointRateCast[1] = -((float)setpoints->motor_front_nw - 9999.0f) * 0.01f / 180.0f * 3.141f; - setpointRateCast[2] = 0; //-((float)setpoints->motor_back_se-9999.0f)*0.01f; - //Ki=actuatorDesired.motorRight_NE*0.001f; - setpointThrustCast = setpoints->motor_left_sw; - - attRatesScaled[0] = 0.000317603994f * (float)raw->gyro_raw[0]; - attRatesScaled[1] = 0.000317603994f * (float)raw->gyro_raw[1]; - attRatesScaled[2] = 0.000317603994f * (float)raw->gyro_raw[2]; - - //filtering of the gyroscope values - - //compute filter coefficient alpha - - //gyro_alpha=0.005/(2.0f*3.1415f*200.0f+0.005f); - //gyro_alpha=0.009; - gyro_alpha = 0.09f; - gyro_alpha_offset = 0.001f; - //gyro_alpha=0.001; - //offset estimation and filtering - offsetCnt++; - uint8_t i; - - for (i = 0; i < 3; i++) { - if (offsetCnt < 5000) { - gyro_filtered_offset[i] = attRatesScaled[i] * gyro_alpha_offset + gyro_filtered_offset[i] * (1 - gyro_alpha_offset); - } - - gyro_filtered[i] = 1.0f * ((attRatesScaled[i] - gyro_filtered_offset[i]) * gyro_alpha + gyro_filtered[i] * (1 - gyro_alpha)) - 0 * setpointRateCast[i]; - } - - // //START DEBUG - // /* write filtered values to global_data_attitude */ - // global_data_attitude->rollspeed = gyro_filtered[0]; - // global_data_attitude->pitchspeed = gyro_filtered[1]; - // global_data_attitude->yawspeed = gyro_filtered[2]; - // //END DEBUG - - //rate controller - - //X-axis - setpointXrate = -Kp * (setpointRateCast[0] - gyro_filtered[0]); - //Y-axis - setpointYrate = -Kp * (setpointRateCast[1] - gyro_filtered[1]); - //Z-axis - setpointZrate = -Kp * (setpointRateCast[2] - gyro_filtered[2]); - - - - - //Mixing - if (setpointThrustCast <= 0) { - setpointThrustCast = 0; - outputBand = 0; - } - - if ((setpointThrustCast < startpointFullControll) && (setpointThrustCast > 0)) { - outputBand = 0.75f * setpointThrustCast; - } - - if ((setpointThrustCast >= startpointFullControll) && (setpointThrustCast < maxThrustSetpoints - 0.75f * startpointFullControll)) { - outputBand = 0.75f * startpointFullControll; - } - - if (setpointThrustCast >= maxThrustSetpoints - 0.75f * startpointFullControll) { - setpointThrustCast = 0.75f * startpointFullControll; - outputBand = 0.75f * startpointFullControll; - } - - actuators_desired.motor_front_nw = setpointThrustCast + (setpointXrate + setpointYrate + setpointZrate); - actuators_desired.motor_right_ne = setpointThrustCast + (-setpointXrate + setpointYrate - setpointZrate); - actuators_desired.motor_back_se = setpointThrustCast + (-setpointXrate - setpointYrate + setpointZrate); - actuators_desired.motor_left_sw = setpointThrustCast + (setpointXrate - setpointYrate - setpointZrate); - - - if ((setpointThrustCast + setpointXrate + setpointYrate + setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_front_nw = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + setpointXrate + setpointYrate + setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_front_nw = setpointThrustCast - outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + setpointYrate - setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_right_ne = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + setpointYrate - setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_right_ne = setpointThrustCast - outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + (-setpointYrate) + setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_back_se = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + (-setpointXrate) + (-setpointYrate) + setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_back_se = setpointThrustCast - outputBand; - } - - if ((setpointThrustCast + setpointXrate + (-setpointYrate) - setpointZrate) > (setpointThrustCast + outputBand)) { - actuators_desired.motor_left_sw = setpointThrustCast + outputBand; - } - - if ((setpointThrustCast + setpointXrate + (-setpointYrate) - setpointZrate) < (setpointThrustCast - outputBand)) { - actuators_desired.motor_left_sw = setpointThrustCast - outputBand; - } - - //printf("%lu,%lu,%lu,%lu\n",actuators_desired.motor_front_nw, actuators_desired.motor_right_ne, actuators_desired.motor_back_se, actuators_desired.motor_left_sw); - - if (motor_skip_counter % 5 == 0) { - uint8_t motorSpeedBuf[5]; - ar_get_motor_packet(motorSpeedBuf, actuators_desired.motor_front_nw, actuators_desired.motor_right_ne, actuators_desired.motor_back_se, actuators_desired.motor_left_sw); -// uint8_t* motorSpeedBuf = ar_get_motor_packet(1, 1, 1, 1); -// if(motor_skip_counter %50 == 0) -// { -// if(0==actuators_desired.motor_front_nw || 0 == actuators_desired.motor_right_ne || 0 == actuators_desired.motor_back_se || 0 == actuators_desired.motor_left_sw) -// printf("Motors set: %u, %u, %u, %u\n", actuators_desired.motor_front_nw, actuators_desired.motor_right_ne, actuators_desired.motor_back_se, actuators_desired.motor_left_sw); -// printf("input: %u\n", setpoints->motor_front_nw); -// printf("Roll casted desired: %f, Pitch casted desired: %f, Yaw casted desired: %f\n", setpointRateCast[0], setpointRateCast[1], setpointRateCast[2]); -// } - write(ardrone_write, motorSpeedBuf, 5); -// motor_skip_counter = 0; - } - - motor_skip_counter++; - - //START DEBUG -// global_data_lock(&global_data_ardrone_control->access_conf); -// global_data_ardrone_control->timestamp = hrt_absolute_time(); -// global_data_ardrone_control->gyro_scaled[0] = attRatesScaled[0]; -// global_data_ardrone_control->gyro_scaled[1] = attRatesScaled[1]; -// global_data_ardrone_control->gyro_scaled[2] = attRatesScaled[2]; -// global_data_ardrone_control->gyro_filtered[0] = gyro_filtered[0]; -// global_data_ardrone_control->gyro_filtered[1] = gyro_filtered[1]; -// global_data_ardrone_control->gyro_filtered[2] = gyro_filtered[2]; -// global_data_ardrone_control->gyro_filtered_offset[0] = gyro_filtered_offset[0]; -// global_data_ardrone_control->gyro_filtered_offset[1] = gyro_filtered_offset[1]; -// global_data_ardrone_control->gyro_filtered_offset[2] = gyro_filtered_offset[2]; -// global_data_ardrone_control->setpoint_rate_cast[0] = setpointRateCast[0]; -// global_data_ardrone_control->setpoint_rate_cast[1] = setpointRateCast[1]; -// global_data_ardrone_control->setpoint_rate_cast[2] = setpointRateCast[2]; -// global_data_ardrone_control->setpoint_thrust_cast = setpointThrustCast; -// global_data_ardrone_control->setpoint_rate[0] = setpointXrate; -// global_data_ardrone_control->setpoint_rate[1] = setpointYrate; -// global_data_ardrone_control->setpoint_rate[2] = setpointZrate; -// global_data_ardrone_control->motor_front_nw = actuators_desired.motor_front_nw; -// global_data_ardrone_control->motor_right_ne = actuators_desired.motor_right_ne; -// global_data_ardrone_control->motor_back_se = actuators_desired.motor_back_se; -// global_data_ardrone_control->motor_left_sw = actuators_desired.motor_left_sw; -// global_data_unlock(&global_data_ardrone_control->access_conf); -// global_data_broadcast(&global_data_ardrone_control->access_conf); - //END DEBUG - - - -// gettimeofday(&tv, NULL); -// now = ((uint32_t)tv.tv_sec) * 1000 + tv.tv_usec/1000; -// time_elapsed = now - last_run; -// if (time_elapsed*1000 > CONTROL_LOOP_USLEEP) -// { -// sleep_time = (int32_t)CONTROL_LOOP_USLEEP - ((int32_t)time_elapsed*1000 - (int32_t)CONTROL_LOOP_USLEEP); -// -// if(motor_skip_counter %500 == 0) -// { -// printf("Desired: %u, New usleep: %i, Time elapsed: %u, Now: %u, Last run: %u\n",(uint32_t)CONTROL_LOOP_USLEEP, sleep_time, time_elapsed*1000, now, last_run); -// } -// } -// -// if (sleep_time <= 0) -// { -// printf("WARNING: CPU Overload!\n"); -// printf("Desired: %u, New usleep: %i, Time elapsed: %u, Now: %u, Last run: %u\n",(uint32_t)CONTROL_LOOP_USLEEP, sleep_time, time_elapsed*1000, now, last_run); -// usleep(CONTROL_LOOP_USLEEP); -// } -// else -// { -// usleep(sleep_time); -// } -// last_run = now; -// -// now_time = hrt_absolute_time(); -// if(control_counter % 500 == 0) -// { -// printf("Now: %lu\n",(unsigned long)now_time); -// printf("Last: %lu\n",(unsigned long)last_time); -// printf("Difference: %lu\n", (unsigned long)(now_time - last_time)); -// printf("now seconds: %lu\n", (unsigned long)(now_time / 1000000)); -// } -// last_time = now_time; -// -// now_time = hrt_absolute_time() / 1000000; -// if(now_time - last_time > 0) -// { -// printf("Counter: %ld\n",control_counter); -// last_time = now_time; -// control_counter = 0; -// } -// control_counter++; -} diff --git a/apps/namedapp/Makefile b/apps/namedapp/Makefile index fba8fb1ff9..6b0fd6a053 100644 --- a/apps/namedapp/Makefile +++ b/apps/namedapp/Makefile @@ -2,7 +2,7 @@ # apps/nshlib/Makefile # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/namedapp/namedapp.c b/apps/namedapp/namedapp.c index a5c2bee0e2..d59ce6e3b7 100644 --- a/apps/namedapp/namedapp.c +++ b/apps/namedapp/namedapp.c @@ -4,7 +4,7 @@ * Copyright (C) 2011 Uros Platise. All rights reserved. * Copyright (C) 2011 Gregory Nutt. All rights reserved. * Authors: Uros Platise - * Gregory Nutt + * Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig index 7e419bdde4..c0f7d6a92f 100644 --- a/apps/nshlib/Kconfig +++ b/apps/nshlib/Kconfig @@ -6,6 +6,7 @@ config NSH_LIBRARY bool "NSH Library" default n + select SYSTEM_READLINE ---help--- Build the NSH support library. This is used, for example, by examples/nsh in order to implement the full NuttShell (NSH). @@ -148,9 +149,12 @@ config NSH_FILEIOSIZE config NSH_STRERROR bool "Use strerror()" default n + depends on LIBC_STRERROR ---help--- strerror(errno) makes more readable output but strerror() is very large and will not be used unless this setting is 'y' + This setting depends upon the strerror() having been enabled + with LIBC_STRERROR. config NSH_LINELEN int "Max command line length" @@ -198,6 +202,7 @@ config NSH_MMCSDMINOR config NSH_ROMFSETC bool "Support ROMFS start-up script" default n + depends on FS_ROMFS ---help--- Mount a ROMFS filesystem at /etc and provide a startup script at /etc/init.d/rcS. The default startup script will mount @@ -241,6 +246,7 @@ config NSH_ROMFSSECTSIZE config NSH_FATDEVNO int "FAT block device minor number" default 0 + depends on FS_FAT ---help--- When the default rcS file used when NSH_ROMFSETC is selected, it will mount a FAT FS under /tmp. This is the minor number of the FAT @@ -249,6 +255,7 @@ config NSH_FATDEVNO config NSH_FATSECTSIZE int "FAT sector size" default 512 + depends on FS_FAT ---help--- When the default rcS file used when NSH_ROMFSETC is selected, it will mount a FAT FS under /tmp. This is the sector size use with the @@ -257,6 +264,7 @@ config NSH_FATSECTSIZE config NSH_FATNSECTORS int "FAT number of sectors" default 1024 + depends on FS_FAT ---help--- When the default rcS file used when NSH_ROMFSETC is selected, it will mount a FAT FS under /tmp. This is the number of sectors to use @@ -265,11 +273,13 @@ config NSH_FATNSECTORS config NSH_FATMOUNTPT string "FAT mount point" - default 512 + default "/tmp" + depends on FS_FAT ---help--- When the default rcS file used when NSH_ROMFSETC is selected, it will mount a FAT FS under /tmp. This is the location where the FAT - FS will be mounted. Default is /tmp. + FS will be mounted. Default is "/tmp". + endif if NSH_LIBRARY diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index d8edd89695..0f6aee759b 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -915,7 +915,9 @@ NSH-Specific Configuration Settings * CONFIG_NSH_STRERROR strerror(errno) makes more readable output but strerror() is - very large and will not be used unless this setting is 'y' + very large and will not be used unless this setting is 'y'. + This setting depends upon the strerror() having been enabled + with CONFIG_LIBC_STRERROR. * CONFIG_NSH_LINELEN The maximum length of one command line and of one output line. diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index 439c2ffd10..e6dd2683b2 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -234,13 +234,20 @@ #endif /* This is the maximum number of arguments that will be accepted for a command */ - -#define NSH_MAX_ARGUMENTS 6 - +#ifdef CONFIG_NSH_MAX_ARGUMENTS +# define NSH_MAX_ARGUMENTS CONFIG_NSH_MAX_ARGUMENTS +#else +# define NSH_MAX_ARGUMENTS 10 +#endif /* strerror() produces much nicer output but is, however, quite large and - * will only be used if CONFIG_NSH_STRERROR is defined. + * will only be used if CONFIG_NSH_STRERROR is defined. Note that the strerror + * interface must also have been enabled with CONFIG_LIBC_STRERROR. */ +#ifndef CONFIG_LIBC_STRERROR +# undef CONFIG_NSH_STRERROR +#endif + #ifdef CONFIG_NSH_STRERROR # define NSH_ERRNO strerror(errno) # define NSH_ERRNO_OF(err) strerror(err) diff --git a/apps/nshlib/nsh_console.h b/apps/nshlib/nsh_console.h index 8abf9154b0..53e8c78976 100644 --- a/apps/nshlib/nsh_console.h +++ b/apps/nshlib/nsh_console.h @@ -2,7 +2,7 @@ * apps/nshlib/nsh_console.h * * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c index baf2e74b4d..6b51be4705 100644 --- a/apps/nshlib/nsh_consolemain.c +++ b/apps/nshlib/nsh_consolemain.c @@ -97,9 +97,10 @@ int nsh_consolemain(int argc, char *argv[]) { FAR struct console_stdio_s *pstate = nsh_newconsole(); - DEBUGASSERT(pstate); int ret; + DEBUGASSERT(pstate); + /* If we are using a USB serial console, then we will have to wait for the * USB to be connected to the host. */ diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c index b5935bdea1..690d027cae 100644 --- a/apps/nshlib/nsh_mntcmds.c +++ b/apps/nshlib/nsh_mntcmds.c @@ -195,10 +195,11 @@ int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { - char *source; - char *target; - char *filesystem = 0; + FAR char *source; + FAR char *target; + FAR char *filesystem = NULL; bool badarg = false; + int option; int ret; /* The mount command behaves differently if no parameters are provided */ @@ -208,9 +209,12 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return mount_show(vtbl, argv[0]); } - /* Get the mount options */ + /* Get the mount options. NOTE: getopt() is not thread safe nor re-entrant. + * To keep its state proper for the next usage, it is necessary to parse to + * the end of the line even if an error occurs. If an error occurs, this + * logic just sets 'badarg' and continues. + */ - int option; while ((option = getopt(argc, argv, ":t:")) != ERROR) { switch (option) @@ -232,14 +236,18 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } } - /* If a bad argument was encountered, then return without processing the command */ + /* If a bad argument was encountered, then return without processing the + * command. + */ if (badarg) { return ERROR; } - /* There are two required arguments after the options */ + /* There are two required arguments after the options: the source and target + * paths. + */ if (optind + 2 < argc) { @@ -252,6 +260,16 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ERROR; } + /* While the above parsing for the -t argument looks nice, the -t argument + * not really optional. + */ + + if (!filesystem) + { + nsh_output(vtbl, g_fmtargrequired, argv[0]); + return ERROR; + } + /* The source and target paths might be relative to the current * working directory. */ diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c index 5d74b30d77..bc845c4ed3 100644 --- a/apps/nshlib/nsh_netinit.c +++ b/apps/nshlib/nsh_netinit.c @@ -164,6 +164,7 @@ int nsh_netinit(void) dhcpc_close(handle); } #endif + return OK; } diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index 165f842fc3..ba597a0628 100644 --- a/apps/nshlib/nsh_parse.c +++ b/apps/nshlib/nsh_parse.c @@ -370,7 +370,7 @@ static const struct cmdmap_s g_cmdmap[] = #endif #if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_GET +# ifndef CONFIG_NSH_DISABLE_WGET { "wget", cmd_wget, 2, 4, "[-o ] " }, # endif #endif diff --git a/apps/position_estimator/position_estimator_main.c b/apps/position_estimator/position_estimator_main.c index 773cd87ff3..17482dc0a8 100644 --- a/apps/position_estimator/position_estimator_main.c +++ b/apps/position_estimator/position_estimator_main.c @@ -297,7 +297,7 @@ int position_estimator_main(int argc, char *argv[]) .lon = lon_current * 1e7, .alt = gps.alt }; - int global_pos_pub = orb_advertise(ORB_ID(vehicle_global_position), &global_pos); + orb_advert_t global_pos_pub = orb_advertise(ORB_ID(vehicle_global_position), &global_pos); printf("[multirotor position estimator] initialized projection with: lat: %.10f, lon:%.10f\n", lat_current, lon_current); diff --git a/apps/px4/attitude_estimator_bm/attitude_bm.c b/apps/px4/attitude_estimator_bm/attitude_bm.c index 41ef479184..6921db3757 100644 --- a/apps/px4/attitude_estimator_bm/attitude_bm.c +++ b/apps/px4/attitude_estimator_bm/attitude_bm.c @@ -147,18 +147,18 @@ void attitude_blackmagic_init(void) // }; static m_elem kal_gain[12 * 9] = { - 0.0006f , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, - 0 , 0.0006f , 0 , 0 , 0 , 0 , 0 , 0 , 0, - 0 , 0 , 0.0006f , 0 , 0 , 0 , 0 , 0 , 0, + 0.0007f , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0.0007f , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0.0007f , 0 , 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0.015f, 0 , 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0.015f, 0 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0 , 0.015f, 0 , 0 , 0, 0.0000f , +0.00002f, 0 , 0 , 0, 0, 0, 0 , 0, -0.00002f, 0 , 0 , 0 , 0, 0, 0, 0, 0, 0, 0 , 0 , 0, 0, 0, 0, 0, 0, - 0 , 0 , 0 , 0 , 0 , 0 , 0.6f , 0 , 0, - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0.6f , 0, - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0.6f + 0 , 0 , 0 , 0 , 0 , 0 , 0.7f , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0.7f , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0.7f }; //offset update only correct if not upside down. @@ -207,10 +207,6 @@ void attitude_blackmagic_init(void) void attitude_blackmagic(const float_vect3 *accel, const float_vect3 *mag, const float_vect3 *gyro) { - //Transform accelerometer used in all directions - // float_vect3 acc_nav; - //body2navi(&global_data.accel_si, &global_data.attitude, &acc_nav); - // Kalman Filter //Calculate new linearized A matrix @@ -225,6 +221,18 @@ void attitude_blackmagic(const float_vect3 *accel, const float_vect3 *mag, const m_elem mask[9] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; + // XXX Hack - stop updating accel if upside down + + if (accel->z > 0) { + mask[0] = 0.0f; + mask[1] = 0.0f; + mask[2] = 0.0f; + } else { + mask[0] = 1.0f; + mask[1] = 1.0f; + mask[2] = 1.0f; + } + measurement[0] = accel->x; measurement[1] = accel->y; measurement[2] = accel->z; diff --git a/apps/px4/attitude_estimator_bm/attitude_estimator_bm.c b/apps/px4/attitude_estimator_bm/attitude_estimator_bm.c index c917ff7b26..45267f3157 100644 --- a/apps/px4/attitude_estimator_bm/attitude_estimator_bm.c +++ b/apps/px4/attitude_estimator_bm/attitude_estimator_bm.c @@ -87,14 +87,25 @@ int attitude_estimator_bm_update(struct sensor_combined_s *raw, float_vect3 *eul gyro_values.z = raw->gyro_rad_s[2]; float_vect3 accel_values; - accel_values.x = raw->accelerometer_m_s2[0] * 9.81f; - accel_values.y = raw->accelerometer_m_s2[1] * 9.81f; - accel_values.z = raw->accelerometer_m_s2[2] * 9.81f; + accel_values.x = (raw->accelerometer_m_s2[0] / 9.81f) * 100; + accel_values.y = (raw->accelerometer_m_s2[1] / 9.81f) * 100; + accel_values.z = (raw->accelerometer_m_s2[2] / 9.81f) * 100; float_vect3 mag_values; - mag_values.x = raw->magnetometer_ga[0]*100.0f; - mag_values.y = raw->magnetometer_ga[1]*100.0f; - mag_values.z = raw->magnetometer_ga[2]*100.0f; + mag_values.x = raw->magnetometer_ga[0]*1500.0f; + mag_values.y = raw->magnetometer_ga[1]*1500.0f; + mag_values.z = raw->magnetometer_ga[2]*1500.0f; + + // static int i = 0; + + // if (i == 500) { + // printf("[att estim bm] gyro: %8.4f\t%8.4f\t%8.4f\t accel: %8.4f\t%8.4f\t%8.4f\t mag: %8.4f\t%8.4f\t%8.4f\t\n", + // gyro_values.x, gyro_values.y, gyro_values.z, + // accel_values.x, accel_values.y, accel_values.z, + // mag_values.x, mag_values.y, mag_values.z); + // i = 0; + // } + // i++; attitude_blackmagic(&accel_values, &mag_values, &gyro_values); @@ -143,7 +154,7 @@ int attitude_estimator_bm_main(int argc, char *argv[]) bool publishing = false; /* advertise attitude */ - int pub_att = orb_advertise(ORB_ID(vehicle_attitude), &att); + orb_advert_t pub_att = orb_advertise(ORB_ID(vehicle_attitude), &att); publishing = true; struct pollfd fds[] = { @@ -215,7 +226,7 @@ int attitude_estimator_bm_main(int argc, char *argv[]) att.timestamp = sensor_combined_s_local.timestamp; att.roll = euler.x; att.pitch = euler.y; - att.yaw = euler.z - M_PI_F; + att.yaw = euler.z; if (att.yaw > M_PI_F) { att.yaw -= 2.0f * M_PI_F; diff --git a/apps/px4/fmu/fmu.cpp b/apps/px4/fmu/fmu.cpp index 9d88472462..a9aab04320 100644 --- a/apps/px4/fmu/fmu.cpp +++ b/apps/px4/fmu/fmu.cpp @@ -64,6 +64,7 @@ #include #include +#include class FMUServo : public device::CDev @@ -88,6 +89,7 @@ private: int _task; int _t_actuators; int _t_armed; + orb_advert_t _t_outputs; unsigned _num_outputs; volatile bool _task_should_exit; @@ -98,15 +100,12 @@ private: actuator_controls_s _controls; static void task_main_trampoline(int argc, char *argv[]); - void task_main(); + void task_main() __attribute__((noreturn)); - static int control_callback_trampoline(uintptr_t handle, + static int control_callback(uintptr_t handle, uint8_t control_group, uint8_t control_index, float &input); - int control_callback(uint8_t control_group, - uint8_t control_index, - float &input); }; namespace @@ -122,6 +121,8 @@ FMUServo::FMUServo(Mode mode) : _task(-1), _t_actuators(-1), _t_armed(-1), + _t_outputs(0), + _num_outputs(0), _task_should_exit(false), _armed(false), _mixers(nullptr) @@ -210,7 +211,12 @@ FMUServo::task_main() orb_set_interval(_t_actuators, 20); /* 50Hz update rate */ _t_armed = orb_subscribe(ORB_ID(actuator_armed)); - orb_set_interval(_t_armed, 100); /* 10Hz update rate */ + orb_set_interval(_t_armed, 200); /* 5Hz update rate */ + + /* advertise the mixed control outputs */ + struct actuator_outputs_s outputs; + memset(&outputs, 0, sizeof(outputs)); + _t_outputs = orb_advertise(ORB_ID_VEHICLE_CONTROLS, &outputs); struct pollfd fds[2]; fds[0].fd = _t_actuators; @@ -237,7 +243,6 @@ FMUServo::task_main() /* do we have a control update? */ if (fds[0].revents & POLLIN) { - float outputs[num_outputs]; /* get controls - must always do this to avoid spinning */ orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, _t_actuators, &_controls); @@ -246,14 +251,20 @@ FMUServo::task_main() if (_mixers != nullptr) { /* do mixing */ - _mixers->mix(&outputs[0], num_outputs); + _mixers->mix(&outputs.output[0], num_outputs); /* iterate actuators */ for (unsigned i = 0; i < num_outputs; i++) { /* scale for PWM output 900 - 2100us */ - up_pwm_servo_set(i, 1500 + (600 * outputs[i])); + outputs.output[i] = 1500 + (600 * outputs.output[i]); + + /* output to the servo */ + up_pwm_servo_set(i, outputs.output[i]); } + + /* and publish for anyone that cares to see */ + orb_publish(ORB_ID_VEHICLE_CONTROLS, _t_outputs, &outputs); } } @@ -264,7 +275,7 @@ FMUServo::task_main() /* get new value */ orb_copy(ORB_ID(actuator_armed), _t_armed, &aa); - /* update PMW servo armed status */ + /* update PWM servo armed status */ up_pwm_servo_arm(aa.armed); } } @@ -285,24 +296,14 @@ FMUServo::task_main() } int -FMUServo::control_callback_trampoline(uintptr_t handle, +FMUServo::control_callback(uintptr_t handle, uint8_t control_group, uint8_t control_index, float &input) { - return ((FMUServo *)handle)->control_callback(control_group, control_index, input); -} + const actuator_controls_s *controls = (actuator_controls_s *)handle; -int -FMUServo::control_callback(uint8_t control_group, - uint8_t control_index, - float &input) -{ - /* XXX currently only supporting group zero */ - if ((control_group != 0) || (control_index > NUM_ACTUATOR_CONTROLS)) - return -1; - - input = _controls.control[control_index]; + input = controls->control[control_index]; return 0; } @@ -377,7 +378,8 @@ FMUServo::ioctl(struct file *filp, int cmd, unsigned long arg) case MIXERIOCADDSIMPLE: { mixer_simple_s *mixinfo = (mixer_simple_s *)arg; - SimpleMixer *mixer = new SimpleMixer(control_callback_trampoline, (uintptr_t)this, mixinfo); + SimpleMixer *mixer = new SimpleMixer(control_callback, + (uintptr_t)&_controls, mixinfo); if (mixer->check()) { delete mixer; @@ -385,7 +387,8 @@ FMUServo::ioctl(struct file *filp, int cmd, unsigned long arg) } else { if (_mixers == nullptr) - _mixers = new MixerGroup(control_callback_trampoline, (uintptr_t)this); + _mixers = new MixerGroup(control_callback, + (uintptr_t)&_controls); _mixers->add_mixer(mixer); } @@ -406,7 +409,7 @@ FMUServo::ioctl(struct file *filp, int cmd, unsigned long arg) _mixers = nullptr; } - _mixers = new MixerGroup(control_callback_trampoline, (uintptr_t)this); + _mixers = new MixerGroup(control_callback, (uintptr_t)&_controls); if (_mixers->load_from_file(path) != 0) { delete _mixers; @@ -550,7 +553,7 @@ void fake(int argc, char *argv[]) { if (argc < 5) { - puts("fmu fake (values -100 - 100)"); + puts("fmu fake (values -100 .. 100)"); exit(1); } @@ -564,15 +567,13 @@ fake(int argc, char *argv[]) ac.control[3] = strtol(argv[4], 0, 0) / 100.0f; - int handle = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &ac); + orb_advert_t handle = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &ac); if (handle < 0) { puts("advertise failed"); exit(1); } - close(handle); - exit(0); } diff --git a/apps/px4/ground_estimator/Makefile b/apps/px4/ground_estimator/Makefile new file mode 100644 index 0000000000..b44d871c67 --- /dev/null +++ b/apps/px4/ground_estimator/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Basic example application +# + +APPNAME = ground_estimator +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +include $(APPDIR)/mk/app.mk diff --git a/apps/px4/ground_estimator/ground_estimator.c b/apps/px4/ground_estimator/ground_estimator.c new file mode 100644 index 0000000000..46f86a348d --- /dev/null +++ b/apps/px4/ground_estimator/ground_estimator.c @@ -0,0 +1,180 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Example User + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file ground_estimator.c + * ground_estimator application example for PX4 autopilot + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +static bool thread_should_exit = false; /**< ground_estimator exit flag */ +static bool thread_running = false; /**< ground_estimator status flag */ +static int ground_estimator_task; /**< Handle of ground_estimator task / thread */ + +/** + * ground_estimator management function. + */ +__EXPORT int ground_estimator_main(int argc, char *argv[]); + +/** + * Mainloop of ground_estimator. + */ +int ground_estimator_thread_main(int argc, char *argv[]); + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + +int ground_estimator_thread_main(int argc, char *argv[]) { + + printf("[ground_estimator] starting\n"); + + /* subscribe to raw data */ + int sub_raw = orb_subscribe(ORB_ID(sensor_combined)); + + /* advertise attitude */ + struct debug_key_value_s dbg = { .key = "posx", .value = 0.0f }; + orb_advert_t pub_dbg = orb_advertise(ORB_ID(debug_key_value), &dbg); + + float position[3] = {}; + float velocity[3] = {}; + + uint64_t last_time = 0; + + struct pollfd fds[] = { + { .fd = sub_raw, .events = POLLIN }, + }; + + while (!thread_should_exit) { + + /* wait for sensor update */ + int ret = poll(fds, 1, 1000); + + if (ret < 0) { + /* XXX this is seriously bad - should be an emergency */ + } else if (ret == 0) { + /* XXX this means no sensor data - should be critical or emergency */ + printf("[attitude estimator bm] WARNING: Not getting sensor data - sensor app running?\n"); + } else { + struct sensor_combined_s s; + orb_copy(ORB_ID(sensor_combined), sub_raw, &s); + + float dt = ((float)(s.timestamp - last_time)) / 1000000.0f; + + /* Integration */ + position[0] += velocity[0] * dt; + position[1] += velocity[1] * dt; + position[2] += velocity[2] * dt; + + velocity[0] += velocity[0] * 0.01f + 0.99f * s.accelerometer_m_s2[0] * dt; + velocity[1] += velocity[1] * 0.01f + 0.99f * s.accelerometer_m_s2[1] * dt; + velocity[2] += velocity[2] * 0.01f + 0.99f * s.accelerometer_m_s2[2] * dt; + + dbg.value = position[0]; + + orb_publish(ORB_ID(debug_key_value), pub_dbg, &dbg); + } + + } + + printf("[ground_estimator] exiting.\n"); + + return 0; +} + +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: ground_estimator {start|stop|status} [-p ]\n\n"); + exit(1); +} + +/** + * The ground_estimator app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ +int ground_estimator_main(int argc, char *argv[]) +{ + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1], "start")) { + + if (thread_running) { + printf("ground_estimator already running\n"); + /* this is not an error */ + exit(0); + } + + thread_should_exit = false; + ground_estimator_task = task_create("ground_estimator", SCHED_PRIORITY_DEFAULT, 4096, ground_estimator_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tground_estimator is running\n"); + } else { + printf("\tground_estimator not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} diff --git a/apps/px4/px4io/driver/px4io.cpp b/apps/px4/px4io/driver/px4io.cpp index a5def874d8..c3371c138b 100644 --- a/apps/px4/px4io/driver/px4io.cpp +++ b/apps/px4/px4io/driver/px4io.cpp @@ -99,7 +99,7 @@ protected: void set_channels(unsigned count, const servo_position_t *data); private: - int _publication; + orb_advert_t _publication; struct rc_input_values _input; }; diff --git a/apps/px4/tests/Makefile b/apps/px4/tests/Makefile index ad8849454e..cb1c3c6185 100644 --- a/apps/px4/tests/Makefile +++ b/apps/px4/tests/Makefile @@ -37,6 +37,6 @@ APPNAME = tests PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 8096 +STACKSIZE = 12000 include $(APPDIR)/mk/app.mk diff --git a/apps/px4/tests/test_float.c b/apps/px4/tests/test_float.c index 4922d06b15..8c70b720bb 100644 --- a/apps/px4/tests/test_float.c +++ b/apps/px4/tests/test_float.c @@ -74,7 +74,7 @@ int test_float(int argc, char *argv[]) printf("\t success: sinf(0.0f) == 0.0f\n"); } else { - printf("\t FAIL: sinf(0.0f) != 0.0f, result: %f\n", sinf_zero); + printf("\t FAIL: sinf(0.0f) != 0.0f, result: %8.4f\n", (double)sinf_zero); ret = -4; } @@ -84,7 +84,7 @@ int test_float(int argc, char *argv[]) printf("\t success: sinf(1.0f) == 0.84147f\n"); } else { - printf("\t FAIL: sinf(1.0f) != 0.84147f, result: %f\n", sinf_one); + printf("\t FAIL: sinf(1.0f) != 0.84147f, result: %8.4f\n", (double)sinf_one); ret = -1; } @@ -108,7 +108,7 @@ int test_float(int argc, char *argv[]) printf("\t success: cosf(1.0f) == 0.54030f\n"); } else { - printf("\t FAIL: cosf(1.0f) != 0.54030f, result: %f\n", cosf_one); + printf("\t FAIL: cosf(1.0f) != 0.54030f, result: %8.4f\n", (double)cosf_one); ret = -1; } @@ -121,7 +121,7 @@ int test_float(int argc, char *argv[]) printf("\t success: acosf(1.0f) == 0.0f\n"); } else { - printf("\t FAIL: acosf(1.0f) != 0.0f, result: %f\n", acosf_one); + printf("\t FAIL: acosf(1.0f) != 0.0f, result: %8.4f\n", (double)acosf_one); ret = -1; } @@ -134,7 +134,7 @@ int test_float(int argc, char *argv[]) printf("\t success: sinf(0.1f) == 0.09983f\n"); } else { - printf("\t FAIL: sinf(0.1f) != 0.09983f, result: %f\n", sinf_zero_one); + printf("\t FAIL: sinf(0.1f) != 0.09983f, result: %8.4f\n", (double)sinf_zero_one); ret = -2; } @@ -142,7 +142,7 @@ int test_float(int argc, char *argv[]) printf("\t success: sqrt(2.0f) == 1.41421f\n"); } else { - printf("\t FAIL: sqrt(2.0f) != 1.41421f, result: %f\n", sinf_zero_one); + printf("\t FAIL: sqrt(2.0f) != 1.41421f, result: %8.4f\n", (double)sinf_zero_one); ret = -3; } @@ -152,7 +152,7 @@ int test_float(int argc, char *argv[]) printf("\t success: atan2f(1.0f, 1.0f) == 0.78539f\n"); } else { - printf("\t FAIL: atan2f(1.0f, 1.0f) != 0.78539f, result: %8.4f\n", atan2f_ones); + printf("\t FAIL: atan2f(1.0f, 1.0f) != 0.78539f, result: %8.4f\n", (double)atan2f_ones); ret = -4; } @@ -162,12 +162,23 @@ int test_float(int argc, char *argv[]) if (sbuf[0] == ' ' && sbuf[1] == ' ' && sbuf[2] == '0' && sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { - printf("\t success: printf(\"%%8.4f\", 0.553415f) == %8.4f\n", 0.553415f); + printf("\t success: printf(\"%%8.4f\", 0.553415f) == %8.4f\n", (double)0.553415f); } else { printf("\t FAIL: printf(\"%%8.4f\", 0.553415f) != \" 0.5534\", result: %s\n", sbuf); ret = -5; } + sprintf(sbuf, "%8.4f", -0.553415f); + + if (sbuf[0] == ' ' && sbuf[1] == '-' && sbuf[2] == '0' && + sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' + && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { + printf("\t success: printf(\"%%8.4f\", -0.553415f) == %8.4f\n", (double)-0.553415f); + } else { + printf("\t FAIL: printf(\"%%8.4f\", -0.553415f) != \" -0.5534\", result: %s\n", sbuf); + ret = -6; + } + @@ -183,7 +194,8 @@ int test_float(int argc, char *argv[]) printf("\t success: 1.0111 * 2.0 == 2.0222\n"); } else { - printf("\t FAIL: 1.0111 * 2.0 != 2.0222, result: %f\n", d1d2); + printf("\t FAIL: 1.0111 * 2.0 != 2.0222, result: %8.4f\n", d1d2); + ret = -7; } fflush(stdout); @@ -195,8 +207,8 @@ int test_float(int argc, char *argv[]) printf("\t success: (float) 1.55f == 1.55 (double)\n"); } else { - printf("\t FAIL: (float) 1.55f != 1.55 (double), result: %f\n", f1); - ret = -4; + printf("\t FAIL: (float) 1.55f != 1.55 (double), result: %8.4f\n", f1); + ret = -8; } fflush(stdout); @@ -210,24 +222,24 @@ int test_float(int argc, char *argv[]) printf("\t success: sin(0.0) == 0.0\n"); } else { - printf("\t FAIL: sin(0.0) != 0.0, result: %f\n", sin_zero); - ret = -5; + printf("\t FAIL: sin(0.0) != 0.0, result: %8.4f\n", sin_zero); + ret = -9; } if (sin_one == 0.841470984807896504875657228695) { printf("\t success: sin(1.0) == 0.84147098480\n"); } else { - printf("\t FAIL: sin(1.0) != 1.0, result: %f\n", sin_one); - ret = -6; + printf("\t FAIL: sin(1.0) != 1.0, result: %8.4f\n", sin_one); + ret = -10; } if (atan2_ones != 0.785398) { printf("\t success: atan2(1.0, 1.0) == 0.785398\n"); } else { - printf("\t FAIL: atan2(1.0, 1.0) != 0.785398, result: %f\n", atan2_ones); - ret = -7; + printf("\t FAIL: atan2(1.0, 1.0) != 0.785398, result: %8.4f\n", atan2_ones); + ret = -11; } printf("\t testing pow() with magic value\n"); @@ -245,7 +257,18 @@ int test_float(int argc, char *argv[]) printf("\t success: printf(\"%%8.4f\", 0.553415) == %8.4f\n", 0.553415); } else { printf("\t FAIL: printf(\"%%8.4f\", 0.553415) != \" 0.5534\", result: %s\n", sbuf); - ret = -8; + ret = -12; + } + + sprintf(sbuf, "%8.4f", -0.553415); + + if (sbuf[0] == ' ' && sbuf[1] == '-' && sbuf[2] == '0' && + sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' + && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { + printf("\t success: printf(\"%%8.4f\", -0.553415) == %8.4f\n", -0.553415); + } else { + printf("\t FAIL: printf(\"%%8.4f\", -0.553415) != \" -0.5534\", result: %s\n", sbuf); + ret = -13; } diff --git a/apps/px4/tests/test_sensors.c b/apps/px4/tests/test_sensors.c index 91397d11c0..87ea7f0580 100644 --- a/apps/px4/tests/test_sensors.c +++ b/apps/px4/tests/test_sensors.c @@ -90,11 +90,11 @@ struct { const char *path; int (* test)(int argc, char *argv[]); } sensors[] = { - {"l3gd20", "/dev/l3gd20", l3gd20}, {"bma180", "/dev/bma180", bma180}, + {"mpu6000", "/dev/accel", mpu6000}, + {"l3gd20", "/dev/l3gd20", l3gd20}, {"hmc5883l", "/dev/hmc5883l", hmc5883l}, {"ms5611", "/dev/ms5611", ms5611}, - {"mpu6000", "/dev/accel", mpu6000}, // {"lis331", "/dev/lis331", lis331}, {NULL, NULL, NULL} }; @@ -253,6 +253,9 @@ l3gd20(int argc, char *argv[]) static int bma180(int argc, char *argv[]) { + // XXX THIS SENSOR IS OBSOLETE + // TEST REMAINS, BUT ALWAYS RETURNS OK + printf("\tBMA180: test start\n"); fflush(stdout); @@ -264,7 +267,7 @@ bma180(int argc, char *argv[]) if (fd < 0) { printf("\tBMA180: open fail\n"); - return ERROR; + return OK; } // if (ioctl(fd, LIS331_SETRATE, LIS331_RATE_50Hz) || @@ -283,7 +286,7 @@ bma180(int argc, char *argv[]) if (ret != sizeof(buf)) { printf("\tBMA180: read1 fail (%d)\n", ret); close(fd); - return ERROR; + return OK; } else { printf("\tBMA180 values: x:%d\ty:%d\tz:%d\n", buf[0], buf[1], buf[2]); @@ -297,7 +300,7 @@ bma180(int argc, char *argv[]) if (ret != sizeof(buf)) { printf("\tBMA180: read2 fail (%d)\n", ret); close(fd); - return ERROR; + return OK; } else { printf("\tBMA180: x:%d\ty:%d\tz:%d\n", buf[0], buf[1], buf[2]); diff --git a/apps/px4/tests/tests.h b/apps/px4/tests/tests.h index aa6dae1e09..8dc9d34e5e 100644 --- a/apps/px4/tests/tests.h +++ b/apps/px4/tests/tests.h @@ -95,5 +95,7 @@ extern int test_sleep(int argc, char *argv[]); extern int test_time(int argc, char *argv[]); extern int test_uart_console(int argc, char *argv[]); extern int test_jig_voltages(int argc, char *argv[]); +extern int test_param(int argc, char *argv[]); +extern int test_file(int argc, char *argv[]); #endif /* __APPS_PX4_TESTS_H */ diff --git a/apps/px4/tests/tests_file.c b/apps/px4/tests/tests_file.c new file mode 100644 index 0000000000..2cff622f7d --- /dev/null +++ b/apps/px4/tests/tests_file.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file tests_file.c + * + * File write test. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "tests.h" + +int +test_file(int argc, char *argv[]) +{ + uint8_t buf[512]; + hrt_abstime start, end; + perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes"); + + int fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT); + memset(buf, 0, sizeof(buf)); + + start = hrt_absolute_time(); + for (unsigned i = 0; i < 1024; i++) { + perf_begin(wperf); + write(fd, buf, sizeof(buf)); + perf_end(wperf); + } + end = hrt_absolute_time(); + + close(fd); + + warnx("512KiB in %llu microseconds", end - start); + perf_print_counter(wperf); + perf_free(wperf); + + return 0; +} diff --git a/apps/px4/tests/tests_main.c b/apps/px4/tests/tests_main.c index 268e7d5f9d..9604710c59 100644 --- a/apps/px4/tests/tests_main.c +++ b/apps/px4/tests/tests_main.c @@ -108,6 +108,8 @@ struct { {"perf", test_perf, OPT_NOJIGTEST, 0}, {"all", test_all, OPT_NOALLTEST | OPT_NOJIGTEST, 0}, {"jig", test_jig, OPT_NOJIGTEST | OPT_NOALLTEST, 0}, + {"param", test_param, 0, 0}, + {"file", test_file, 0, 0}, {"help", test_help, OPT_NOALLTEST | OPT_NOHELP | OPT_NOJIGTEST, 0}, {NULL, NULL, 0, 0} }; diff --git a/apps/px4/tests/tests_param.c b/apps/px4/tests/tests_param.c new file mode 100644 index 0000000000..5ac9f03430 --- /dev/null +++ b/apps/px4/tests/tests_param.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file tests_param.c + * + * Tests related to the parameter system. + */ + +#include +#include "systemlib/err.h" + +#include "systemlib/param/param.h" +#include "tests.h" + +PARAM_DEFINE_INT32(test, 0x12345678); + +int +test_param(int argc, char *argv[]) +{ + param_t p; + + p = param_find("test"); + if (p == PARAM_INVALID) + errx(1, "test parameter not found"); + + param_type_t t = param_type(p); + if (t != PARAM_TYPE_INT32) + errx(1, "test parameter type mismatch (got %u)", (unsigned)t); + + int32_t val; + if (param_get(p, &val) != 0) + errx(1, "failed to read test parameter"); + if (val != 0x12345678) + errx(1, "parameter value mismatch"); + + val = 0xa5a5a5a5; + if (param_set(p, &val) != 0) + errx(1, "failed to write test parameter"); + if (param_get(p, &val) != 0) + errx(1, "failed to re-read test parameter"); + if ((uint32_t)val != 0xa5a5a5a5) + errx(1, "parameter value mismatch after write"); + + param_export(-1, false); + + warnx("parameter test PASS"); + + return 0; +} diff --git a/apps/sdlog/Makefile b/apps/sdlog/Makefile index 1e5abdb553..61f224e999 100644 --- a/apps/sdlog/Makefile +++ b/apps/sdlog/Makefile @@ -36,9 +36,7 @@ # APPNAME = sdlog -PRIORITY = SCHED_PRIORITY_DEFAULT - 1 -STACKSIZE = 3000 - -INCLUDES = $(TOPDIR)/../mavlink/include/mavlink +PRIORITY = SCHED_PRIORITY_DEFAULT - 30 +STACKSIZE = 2048 include $(APPDIR)/mk/app.mk diff --git a/apps/sdlog/mfile.template b/apps/sdlog/mfile.template deleted file mode 100644 index 0f7ebd0454..0000000000 --- a/apps/sdlog/mfile.template +++ /dev/null @@ -1,136 +0,0 @@ -%% Import logfiles - -if (exist ('OCTAVE_VERSION', 'builtin')) - % Octave - graphics_toolkit ("fltk") -else - % Matlab -end - -% define log file and GPSs -logfileFolder = 'logfiles'; -fileName = 'all'; -fileEnding = 'px4log'; - -numberOfLogTypes = length(logTypes); - -path = [fileName,'.', fileEnding]; -fid = fopen(path, 'r'); - -% get file length -fseek(fid, 0,'eof'); -fileLength = ftell(fid); -fseek(fid, 0,'bof'); - -% get length of one block -blockLength = 4; % check: $$$$ -for i=1:numberOfLogTypes - blockLength = blockLength + logTypes{i}.type_bytes*logTypes{i}.number_of_array; -end - -% determine number of entries -entries = fileLength / blockLength; - - -% import data -offset = 0; -for i=1:numberOfLogTypes - - data.(genvarname(logTypes{i}.data)).(genvarname(logTypes{i}.variable_name)) = transpose(fread(fid,[logTypes{i}.number_of_array,entries],[num2str(logTypes{i}.number_of_array),'*',logTypes{i}.type_name,'=>',logTypes{i}.type_name],blockLength-logTypes{i}.type_bytes*logTypes{i}.number_of_array)); - offset = offset + logTypes{i}.type_bytes*logTypes{i}.number_of_array; - fseek(fid, offset,'bof'); - - progressPercentage = i/numberOfLogTypes*100; - fprintf('%3.0f%%',progressPercentage); -end - - -%% Plots - -figure -plot(data.sensors_raw.timestamp,data.sensors_raw.gyro_raw) - -figure -plot(data.sensors_raw.timestamp,data.sensors_raw.accelerometer_raw) - -%% Check for lost data - -% to detect lost frames (either when logging to sd card or if no new data is -% data is available for some time) -diff_counter = diff(data.sensors_raw.gyro_raw_counter); -figure -plot(diff_counter) - -% to detect how accurate the timing was -diff_timestamp = diff(data.sensors_raw.timestamp); - -figure -plot(diff_timestamp) - -%% Export to file for google earth - - -if(isfield(data.gps,'lat') && isfield(data.gps,'lon') && isfield(data.gps,'alt')) - - % extract coordinates and height where they are not zero - maskWhereNotZero = ((data.gps.lon ~= 0 & data.gps.lat ~= 0 ) & data.gps.alt ~= 0); - - % plot - figure - plot3(data.gps.lon(maskWhereNotZero),data.gps.lat(maskWhereNotZero),data.gps.alt(maskWhereNotZero)) - - - % create a kml file according to https://developers.google.com/kml/documentation/kml_tut - % also see https://support.google.com/earth/bin/answer.py?hl=en&answer=148072&topic=2376756&ctx=topic - - % open file and overwrite content - fileId = fopen('gps_path.kml','w+'); - - % define strings that should be written to file - fileStartDocumentString = ['PathsPath']; - - fileStyleString = ''; - - filePlacemarkString = 'Absolute ExtrudedTransparent blue wall with blue outlines#blueLinebluePoly11absolute'; - - fileEndPlacemarkString = ''; - fileEndDocumentString = ''; - - % start writing to file - fprintf(fileId,fileStartDocumentString); - - fprintf(fileId,fileStyleString); - fprintf(fileId,filePlacemarkString); - - - lonTemp = double(data.gps.lon(maskWhereNotZero))/1E7; - latTemp = double(data.gps.lat(maskWhereNotZero))/1E7; - altTemp = double(data.gps.alt(maskWhereNotZero))/1E3 + 100.0; % in order to see the lines above ground - - % write coordinates to file - for k=1:length(data.gps.lat(maskWhereNotZero)) - if(mod(k,10)==0) - fprintf(fileId,'%.10f,%.10f,%.10f\\n',lonTemp(k),latTemp(k),altTemp(k)); - end - end - - % write end placemark - fprintf(fileId,fileEndPlacemarkString); - - % write end of file - fprintf(fileId,fileEndDocumentString); - - % close file, it should now be readable in Google Earth using File -> Open - fclose(fileId); - -end - -if(isfield(data.position,'lat') && isfield(data.position,'lon') && isfield(data.position,'alt')) - - % extract coordinates and height where they are not zero - maskWhereNotZero = ((data.position.lon ~= 0 & data.position.lat ~= 0 ) & data.position.alt ~= 0); - - % plot - figure - plot3(data.position.lon(maskWhereNotZero),data.position.lat(maskWhereNotZero),data.position.alt(maskWhereNotZero)) -end diff --git a/apps/sdlog/sdlog.c b/apps/sdlog/sdlog.c index 1b87aab77b..b99c6652c8 100644 --- a/apps/sdlog/sdlog.c +++ b/apps/sdlog/sdlog.c @@ -1,8 +1,7 @@ /**************************************************************************** - * examples/hello/main.c * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -14,7 +13,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be + * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,152 +32,129 @@ * ****************************************************************************/ +/** + * @file sdlog.c + * @author Lorenz Meier + * + * Simple SD logger for flight data + */ -#include #include +#include +#include +#include +#include #include #include -#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include -#include "sdlog.h" -#include "sdlog_generated.h" +#include +#include +#include +#include +#include +#include +#include -/**************************************************************************** - * Definitions - ****************************************************************************/ +static bool thread_should_exit = false; /**< Deamon exit flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int deamon_task; /**< Handle of deamon task / thread */ +static const int MAX_NO_LOGFOLDER = 999; /**< Maximum number of log folders */ +static const char *mountpoint = "/fs/microsd"; + +/** + * SD log management function. + */ __EXPORT int sdlog_main(int argc, char *argv[]); -const char *src = "/dev/mmcsd0"; -const char *trgt = "/fs/microsd"; -const char *type = "vfat"; -const char *logfile_end = ".px4log"; -const char *mfile_end = ".m"; -char folder_path[64]; +/** + * Mainloop of sd log deamon. + */ +int sdlog_thread_main(int argc, char *argv[]); -#define SDLOG_LED_PRIORITY LED_REQUEST_PRIORITY_MAX -#define BUFFER_BYTES 1000 // length of buffer -#define SAVE_EVERY_BYTES 2000 -#define MAX_MOUNT_TRIES 5 +/** + * Print the correct usage. + */ +static void usage(const char *reason); -static void sdlog_sig_handler(int signo, siginfo_t *info, void *ucontext); // is executed when SIGUSR1 is received -bool sdlog_sigusr1_rcvd; // if this is set to true through SIGUSR1, sdlog will terminate +static int file_exist(const char *filename); -static pthread_t logbuffer_thread; // thread to copy log values to the buffer -static void *logbuffer_loop(void *arg); +/** + * Create folder for current logging session. + */ +static int create_logfolder(char* folder_path); - -uint8_t *buffer_start; // always points to the very beginning -uint8_t *buffer_end; // always points to the very end -uint8_t *buffer_cursor_start; // points to the start of the current buffer -uint8_t *buffer_cursor_end; // points to the end of the current buffer -size_t buffer_bytes_used; // amount stored in the buffer at the moment - -uint32_t bytes_recv; // to count bytes received and written to the sdcard -uint32_t bytes_sent; // to count the bytes written to the buffer - -/**************************************************************************** - * user_start - ****************************************************************************/ - -int file_exist(const char *filename) +static void +usage(const char *reason) { - struct stat buffer; - return (stat(filename, &buffer) == 0); + if (reason) + fprintf(stderr, "%s\n", reason); + errx(1, "usage: sdlog {start|stop|status} [-p ]\n\n"); } - +/** + * The sd log deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ int sdlog_main(int argc, char *argv[]) { - // print text - printf("[sdlog] initialized\n"); - usleep(10000); + if (argc < 1) + usage("missing command"); - sdlog_sigusr1_rcvd = false; + if (!strcmp(argv[1], "start")) { - led_request_t amber_on_request = {.led = LED_AMBER, .priority = SDLOG_LED_PRIORITY, .request_type = LED_REQUEST_ON}; - led_request_t amber_off_request = {.led = LED_AMBER, .priority = SDLOG_LED_PRIORITY, .request_type = LED_REQUEST_OFF}; - amber_on_request.pid = getpid(); - amber_off_request.pid = getpid(); - - /* signal handler to abort when low voltage occurs */ - struct sigaction act; - struct sigaction oact; - act.sa_sigaction = sdlog_sig_handler; - (void)sigemptyset(&act.sa_mask); - (void)sigaddset(&act.sa_mask, SIGUSR1); - (void)sigaction(SIGUSR1, &act, &oact); - - uint8_t mount_counter = 0; - - commander_state_machine_t current_system_state; - - global_data_send_led_request(&amber_on_request); - - if (file_exist(trgt) == 1) { - printf("[sdlog] Mount already available at %s\n", trgt); - global_data_send_led_request(&amber_off_request); - - } else { - printf("[sdlog] Mount not available yet, trying to mount...\n"); - - /* mostly the first mount fails, sometimes it helps to press the card onto the board! */ - while (mount(src, trgt, type, 0, "") != 0) { - /* abort if kill signal is received */ - if (sdlog_sigusr1_rcvd == true) { - return 0; - } - - //make sure were not airborne - global_data_trylock(&global_data_sys_status->access_conf); - current_system_state = global_data_sys_status->state_machine; - global_data_unlock(&global_data_sys_status->access_conf); - - if (current_system_state == SYSTEM_STATE_STANDBY || current_system_state == SYSTEM_STATE_PREFLIGHT || current_system_state == SYSTEM_STATE_GROUND_ERROR) { - usleep(1000000); - printf("[sdlog] ERROR: Failed to mount SD card (attempt %d of %d), reason: %s\n", mount_counter + 1, MAX_MOUNT_TRIES, strerror((int)*get_errno_ptr())); - global_data_send_led_request(&amber_off_request); - mount_counter++; - - } else { - printf("[sdlog] WARNING: Not mounting SD card in flight!\n"); - printf("[sdlog] ending now...\n"); - fflush(stdout); - return 0; - } - - if (mount_counter >= MAX_MOUNT_TRIES) { - printf("[sdlog] ERROR: SD card could not be mounted!\n"); - printf("[sdlog] ending now...\n"); - fflush(stdout); - return 0; - } + if (thread_running) { + printf("sdlog already running\n"); + /* this is not an error */ + exit(0); } - printf("[sdlog] Mount created at %s...\n", trgt); - global_data_send_led_request(&amber_off_request); + thread_should_exit = false; + deamon_task = task_create("sdlog", SCHED_PRIORITY_DEFAULT - 30, 4096, sdlog_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); } + if (!strcmp(argv[1], "stop")) { + if (!thread_running) { + printf("\tsdlog is not started\n"); + } + thread_should_exit = true; + exit(0); + } + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tsdlog is running\n"); + } else { + printf("\tsdlog not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} + +int create_logfolder(char* folder_path) { /* make folder on sdcard */ uint16_t foldernumber = 1; // start with folder 0001 int mkdir_ret; /* look for the next folder that does not exist */ while (foldernumber < MAX_NO_LOGFOLDER) { - /* set up file path: e.g. /mnt/sdcard/logfile0001.txt */ - sprintf(folder_path, "%s/session%04u", trgt, foldernumber); + /* set up file path: e.g. /mnt/sdcard/sensorfile0001.txt */ + sprintf(folder_path, "%s/session%04u", mountpoint, foldernumber); mkdir_ret = mkdir(folder_path, S_IRWXU | S_IRWXG | S_IRWXO); /* the result is -1 if the folder exists */ @@ -188,255 +164,329 @@ int sdlog_main(int argc, char *argv[]) } else if (mkdir_ret == -1) { /* folder exists already */ - foldernumber++; // to try next time + foldernumber++; continue; } else { - printf("[sdlog] ERROR: Failed creating new folder: %s\n", strerror((int)*get_errno_ptr())); + warn("failed creating new folder"); return -1; } } if (foldernumber >= MAX_NO_LOGFOLDER) { /* we should not end up here, either we have more than MAX_NO_LOGFOLDER on the SD card, or another problem */ - printf("[sdlog] ERROR: all %d possible folders exist already\n", MAX_NO_LOGFOLDER); + warn("all %d possible folders exist already", MAX_NO_LOGFOLDER); return -1; } + return 0; +} - /* write m-file for evaluation in Matlab */ - FILE *mfile; - char mfile_path[64] = ""; // string to hold the path to the mfile - const char *mfilename = "sdlog_eval"; +int sdlog_thread_main(int argc, char *argv[]) { - sprintf(mfile_path, "%s/%s%s", folder_path, mfilename, mfile_end); + printf("[sdlog] starting\n"); - if (NULL == (mfile = fopen(mfile_path, "w"))) { - printf("[sdlog] ERROR: opening %s failed: %s\n", mfile_path, strerror((int)*get_errno_ptr())); + if (file_exist(mountpoint) != OK) { + errx(1, "logging mount point %s not present, exiting.", mountpoint); } - /* write file contents generated using updatesdlog.sh and mfile.template in nuttx/configs/px4fmu/include */ - fwrite(MFILE_STRING, sizeof(MFILE_STRING), 1, mfile); - fprintf(mfile, "\n"); - fclose(mfile); - printf("[sdlog] m-file written to sdcard\n"); + char folder_path[64]; + if (create_logfolder(folder_path)) + errx(1, "unable to create logging folder, exiting"); + /* create sensorfile */ + int sensorfile = -1; + unsigned sensor_combined_bytes = 0; + int actuator_outputs_file = -1; + unsigned actuator_outputs_bytes = 0; + int actuator_controls_file = -1; + unsigned actuator_controls_bytes = 0; + int sysvector_file = -1; + unsigned sysvector_bytes = 0; + FILE *gpsfile; + unsigned blackbox_file_bytes = 0; + FILE *blackbox_file; + // FILE *vehiclefile; - /* create the ringbuffer */ - uint8_t buffer[BUFFER_BYTES]; - buffer_start = buffer; - buffer_cursor_start = buffer; - buffer_cursor_end = buffer; - buffer_end = buffer + BUFFER_BYTES; + char path_buf[64] = ""; // string to hold the path to the sensorfile - /* create loop to write log data in a ringbuffer */ - pthread_attr_t logbuffer_attr; - pthread_attr_init(&logbuffer_attr); - pthread_attr_setstacksize(&logbuffer_attr, 2400); - pthread_create(&logbuffer_thread, &logbuffer_attr, logbuffer_loop, NULL); + printf("[sdlog] logging to directory %s\n", folder_path); - /* create logfile */ - FILE *logfile; - char logfile_path[64] = ""; // string to hold the path to the logfile - const char *logfilename = "all"; - - /* set up file path: e.g. /mnt/sdcard/session0001/gpslog.txt */ - sprintf(logfile_path, "%s/%s%s", folder_path, logfilename, logfile_end); - - - if (NULL == (logfile = fopen(logfile_path, "wb"))) { - printf("[sdlog] opening %s failed: %s\n", logfile_path, strerror((int)*get_errno_ptr())); + /* set up file path: e.g. /mnt/sdcard/session0001/sensor_combined.bin */ + sprintf(path_buf, "%s/%s.bin", folder_path, "sensor_combined"); + if (0 == (sensorfile = open(path_buf, O_CREAT | O_WRONLY | O_DSYNC))) { + errx(1, "opening %s failed.\n", path_buf); } -// else -// { -// printf("[sdlog] opening %s was successful\n",logfile_path); -// } + // /* set up file path: e.g. /mnt/sdcard/session0001/actuator_outputs0.bin */ + // sprintf(path_buf, "%s/%s.bin", folder_path, "actuator_outputs0"); + // if (0 == (actuator_outputs_file = open(path_buf, O_CREAT | O_WRONLY | O_DSYNC))) { + // errx(1, "opening %s failed.\n", path_buf); + // } - int logfile_no = fileno(logfile); - - bytes_recv = 0; /**< count all bytes that were received and written to the sdcard */ - size_t ret_write; /**< last amount written to sdcard */ - size_t target_write; /**< desired amount to write to sdcard */ - int ret_fsync; /**< return value of fsync() system call */ - int error_count = 0; /**< number of continous errors (one successful write resets it) */ - - /* Start logging */ - while (1) { - /* write as soon as content is in the buffer */ - while (buffer_bytes_used > 1) { - /* case where the data is not wrapped in the buffer */ - if (buffer_cursor_start < buffer_cursor_end) { - /* write all available data */ - target_write = (size_t)(buffer_cursor_end - buffer_cursor_start); - - if (0 <= (ret_write = fwrite(buffer_cursor_start, 1, target_write, logfile))) { - /* decrease the amount stored in the buffer, normally to 0 */ - buffer_bytes_used -= ret_write; - /* set new cursor position: wrap it in case it falls out of the buffer */ - buffer_cursor_start = buffer_start + (buffer_cursor_start - buffer_start + ret_write) % BUFFER_BYTES; - bytes_recv += ret_write; - error_count = 0; - - } else { - error_count++; - printf("[sdlog] ERROR: Write fail: %d of %d, %s\n", ret_write, target_write, strerror((int)*get_errno_ptr())); - } - } - - /* case where the content is wrapped around the buffer */ - else if (buffer_cursor_start > buffer_cursor_end) { - /* write data until the end of the buffer */ - target_write = (size_t)(buffer_end - buffer_cursor_start); - - if (0 <= (ret_write = fwrite(buffer_cursor_start, 1, target_write, logfile))) { - /* decrease the amount stored in the buffer */ - buffer_bytes_used -= ret_write; - /* set new cursor position: wrap it in case it falls out of the buffer */ - buffer_cursor_start = buffer_start + (buffer_cursor_start - buffer_start + ret_write) % BUFFER_BYTES; - bytes_recv += ret_write; - error_count = 0; - - } else { - error_count++; - printf("[sdlog] ERROR: Write fail: %d of %d, %s\n", ret_write, target_write, strerror((int)*get_errno_ptr())); - } - - /* write the rest of the data at the beginning of the buffer */ - target_write = (size_t)(buffer_cursor_end - buffer_start); - - if (0 <= (ret_write = fwrite(buffer_start, 1, target_write, logfile))) { - /* decrease the amount stored in the buffer, now normally to 0 */ - buffer_bytes_used -= ret_write; - /* set new cursor position: wrap it in case it falls out of the buffer */ - buffer_cursor_start = buffer_start + (buffer_cursor_start - buffer_start + ret_write) % BUFFER_BYTES; - bytes_recv += ret_write; - error_count = 0; - - } else { - error_count++; - printf("[sdlog] ERROR: write fail: %d of %d, %s\n", ret_write, target_write, strerror((int)*get_errno_ptr())); - } - - } else { - error_count++; - printf("[sdlog] ERROR: dropped data\n"); - } - -// if(bytes_recv>500000) -// { -// goto finished; -// } - } - - - /* save and exit if we received signal 1 or have a permanent error */ - if (sdlog_sigusr1_rcvd == true || error_count > 100) { - fclose(logfile); - umount(trgt); - - if (error_count > 100) { - return ERROR; - - } else { - return OK; - } - } - - /* save file from time to time */ - else if ((bytes_recv > 0 && bytes_recv % SAVE_EVERY_BYTES == 0)) { - if ((ret_fsync = fsync(logfile_no)) != OK) { - printf("[sdlog] ERROR: sync fail: #%d, %s\n", ret_fsync, strerror((int)*get_errno_ptr())); - } - } - -// else if(bytes_recv > 2*SAVE_EVERY_BYTES) -// { -// goto finished; -// } - /* sleep, not to block everybody else */ - usleep(1000); + /* set up file path: e.g. /mnt/sdcard/session0001/actuator_controls0.bin */ + sprintf(path_buf, "%s/%s.bin", folder_path, "sysvector"); + if (0 == (sysvector_file = open(path_buf, O_CREAT | O_WRONLY | O_DSYNC))) { + errx(1, "opening %s failed.\n", path_buf); } -//finished: -// -// /* at the moment we should not end here */ -// fclose(logfile); -// printf("[sdlog] logfile saved\n"); -// umount(trgt); -// printf("[sdlog] ending...\n"); -// fflush(stdout); + /* set up file path: e.g. /mnt/sdcard/session0001/actuator_controls0.bin */ + sprintf(path_buf, "%s/%s.bin", folder_path, "actuator_controls0"); + if (0 == (actuator_controls_file = open(path_buf, O_CREAT | O_WRONLY | O_DSYNC))) { + errx(1, "opening %s failed.\n", path_buf); + } + + /* set up file path: e.g. /mnt/sdcard/session0001/gps.txt */ + sprintf(path_buf, "%s/%s.txt", folder_path, "gps"); + if (NULL == (gpsfile = fopen(path_buf, "w"))) { + errx(1, "opening %s failed.\n", path_buf); + } + int gpsfile_no = fileno(gpsfile); + + /* set up file path: e.g. /mnt/sdcard/session0001/blackbox.txt */ + sprintf(path_buf, "%s/%s.txt", folder_path, "blackbox"); + if (NULL == (blackbox_file = fopen(path_buf, "w"))) { + errx(1, "opening %s failed.\n", path_buf); + } + int blackbox_file_no = fileno(blackbox_file); + + /* --- IMPORTANT: DEFINE NUMBER OF ORB STRUCTS TO WAIT FOR HERE --- */ + /* number of messages */ + const ssize_t fdsc = 25; + /* Sanity check variable and index */ + ssize_t fdsc_count = 0; + /* file descriptors to wait for */ + struct pollfd fds[fdsc]; + + + struct { + struct sensor_combined_s raw; + struct vehicle_attitude_s att; + struct vehicle_attitude_setpoint_s att_sp; + struct actuator_outputs_s act_outputs; + struct actuator_controls_s act_controls; + struct vehicle_command_s cmd; + } buf; + memset(&buf, 0, sizeof(buf)); + + struct { + int cmd_sub; + int sensor_sub; + int att_sub; + int spa_sub; + int act_0_sub; + int controls0_sub; + } subs; + + /* --- MANAGEMENT - LOGGING COMMAND --- */ + /* subscribe to ORB for sensors raw */ + subs.cmd_sub = orb_subscribe(ORB_ID(vehicle_command)); + fds[fdsc_count].fd = subs.cmd_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- SENSORS RAW VALUE --- */ + /* subscribe to ORB for sensors raw */ + subs.sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); + fds[fdsc_count].fd = subs.sensor_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- ATTITUDE VALUE --- */ + /* subscribe to ORB for attitude */ + subs.att_sub = orb_subscribe(ORB_ID(vehicle_attitude)); + fds[fdsc_count].fd = subs.att_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- ATTITUDE SETPOINT VALUE --- */ + /* subscribe to ORB for attitude setpoint */ + /* struct already allocated */ + subs.spa_sub = orb_subscribe(ORB_ID(vehicle_attitude_setpoint)); + fds[fdsc_count].fd = subs.spa_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /** --- ACTUATOR OUTPUTS --- */ + subs.act_0_sub = orb_subscribe(ORB_ID(actuator_outputs_0)); + fds[fdsc_count].fd = subs.act_0_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* --- ACTUATOR CONTROL VALUE --- */ + /* subscribe to ORB for actuator control */ + subs.controls0_sub = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS); + fds[fdsc_count].fd = subs.controls0_sub; + fds[fdsc_count].events = POLLIN; + fdsc_count++; + + /* WARNING: If you get the error message below, + * then the number of registered messages (fdsc) + * differs from the number of messages in the above list. + */ + if (fdsc_count > fdsc) { + warn("WARNING: Not enough space for poll fds allocated. Check %s:%d.\n", __FILE__, __LINE__); + fdsc_count = fdsc; + } + + /* + * set up poll to block for new data, + * wait for a maximum of 1000 ms (1 second) + */ + const int timeout = 1000; + + thread_running = true; + + int poll_count = 0; + + uint64_t starttime = hrt_absolute_time(); + + while (!thread_should_exit) { + + // int poll_ret = poll(fds, fdsc_count, timeout); + + // /* handle the poll result */ + // if (poll_ret == 0) { + // /* XXX this means none of our providers is giving us data - might be an error? */ + // } else if (poll_ret < 0) { + // /* XXX this is seriously bad - should be an emergency */ + // } else { + + // int ifds = 0; + + // if (poll_count % 5000 == 0) { + // fsync(sensorfile); + // fsync(actuator_outputs_file); + // fsync(actuator_controls_file); + // fsync(blackbox_file_no); + // } + + + + // /* --- VEHICLE COMMAND VALUE --- */ + // if (fds[ifds++].revents & POLLIN) { + // /* copy command into local buffer */ + // orb_copy(ORB_ID(vehicle_command), subs.cmd_sub, &buf.cmd); + // blackbox_file_bytes += fprintf(blackbox_file, "[%10.4f\tVCMD] CMD #%d [%f\t%f\t%f\t%f\t%f\t%f\t%f]\n", hrt_absolute_time()/1000000.0d, + // buf.cmd.command, (double)buf.cmd.param1, (double)buf.cmd.param2, (double)buf.cmd.param3, (double)buf.cmd.param4, + // (double)buf.cmd.param5, (double)buf.cmd.param6, (double)buf.cmd.param7); + // } + + // /* --- SENSORS RAW VALUE --- */ + // if (fds[ifds++].revents & POLLIN) { + + // /* copy sensors raw data into local buffer */ + // orb_copy(ORB_ID(sensor_combined), subs.sensor_sub, &buf.raw); + // /* write out */ + // sensor_combined_bytes += write(sensorfile, (const char*)&(buf.raw), sizeof(buf.raw)); + // } + + // /* --- ATTITUDE VALUE --- */ + // if (fds[ifds++].revents & POLLIN) { + + // /* copy attitude data into local buffer */ + // orb_copy(ORB_ID(vehicle_attitude), subs.att_sub, &buf.att); + + + // } + + // /* --- VEHICLE ATTITUDE SETPOINT --- */ + // if (fds[ifds++].revents & POLLIN) { + // /* copy local position data into local buffer */ + // orb_copy(ORB_ID(vehicle_attitude_setpoint), subs.spa_sub, &buf.att_sp); + + // } + + // /* --- ACTUATOR OUTPUTS 0 --- */ + // if (fds[ifds++].revents & POLLIN) { + // /* copy actuator data into local buffer */ + // orb_copy(ORB_ID(actuator_outputs_0), subs.act_0_sub, &buf.act_outputs); + // /* write out */ + // // actuator_outputs_bytes += write(actuator_outputs_file, (const char*)&buf.act_outputs, sizeof(buf.act_outputs)); + // } + + // /* --- ACTUATOR CONTROL --- */ + // if (fds[ifds++].revents & POLLIN) { + // orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, subs.controls0_sub, &buf.act_controls); + // /* write out */ + // actuator_controls_bytes += write(actuator_controls_file, (const char*)&buf.act_controls, sizeof(buf.act_controls)); + // } + // } + + if (poll_count % 100 == 0) { + fsync(sysvector_file); + } + + poll_count++; + + + /* copy sensors raw data into local buffer */ + orb_copy(ORB_ID(sensor_combined), subs.sensor_sub, &buf.raw); + orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, subs.controls0_sub, &buf.act_controls); + /* copy actuator data into local buffer */ + orb_copy(ORB_ID(actuator_outputs_0), subs.act_0_sub, &buf.act_outputs); + orb_copy(ORB_ID(vehicle_attitude_setpoint), subs.spa_sub, &buf.att_sp); + + #pragma pack(push, 1) + struct { + uint64_t timestamp; + float gyro[3]; + float accel[3]; + float mag[3]; + float baro; + float baro_alt; + float baro_temp; + float control[4]; + + float actuators[8]; + float vbat; + float adc[3]; + } sysvector = { + .timestamp = buf.raw.timestamp, + .gyro = {buf.raw.gyro_rad_s[0], buf.raw.gyro_rad_s[1], buf.raw.gyro_rad_s[2]}, + .accel = {buf.raw.accelerometer_m_s2[0], buf.raw.accelerometer_m_s2[1], buf.raw.accelerometer_m_s2[2]}, + .mag = {buf.raw.magnetometer_ga[0], buf.raw.magnetometer_ga[1], buf.raw.magnetometer_ga[2]}, + .baro = buf.raw.baro_pres_mbar, + .baro_alt = buf.raw.baro_alt_meter, + .baro_temp = buf.raw.baro_temp_celcius, + .control = {buf.act_controls.control[0], buf.act_controls.control[1], buf.act_controls.control[2], buf.act_controls.control[3]}, + .actuators = {buf.act_outputs.output[0], buf.act_outputs.output[1], buf.act_outputs.output[2], buf.act_outputs.output[3], + buf.act_outputs.output[4], buf.act_outputs.output[5], buf.act_outputs.output[6], buf.act_outputs.output[7]}, + .vbat = buf.raw.battery_voltage_v, + .adc = {buf.raw.adc_voltage_v[0], buf.raw.adc_voltage_v[1], buf.raw.adc_voltage_v[2]} + }; + #pragma pack(pop) + + sysvector_bytes += write(sysvector_file, (const char*)&sysvector, sizeof(sysvector)); + + usleep(4900); + } + + unsigned bytes = sensor_combined_bytes + actuator_outputs_bytes + blackbox_file_bytes + actuator_controls_bytes; + float mebibytes = bytes / 1024.0f / 1024.0f; + float seconds = ((float)(hrt_absolute_time() - starttime)) / 1000000.0f; + + printf("[sdlog] wrote %4.2f MiB (average %5.3f MiB/s).\n", (double)mebibytes, (double)(mebibytes / seconds)); + + printf("[sdlog] exiting.\n"); + + close(sensorfile); + close(actuator_outputs_file); + close(actuator_controls_file); + fclose(gpsfile); + fclose(blackbox_file); + + thread_running = false; return 0; } -/* is executed when SIGUSR1 is raised (to terminate the app) */ -static void sdlog_sig_handler(int signo, siginfo_t *info, void *ucontext) +/** + * @return 0 if file exists + */ +int file_exist(const char *filename) { - sdlog_sigusr1_rcvd = true; + struct stat buffer; + return stat(filename, &buffer); } - -static void *logbuffer_loop(void *arg) -{ - /* set name for this pthread */ - prctl(PR_SET_NAME, "sdlog logbuffer", getpid()); - - bytes_sent = 0; // count all bytes written to the buffer - - //size_t block_length = sizeof(global_data_sensors_raw_t) - 4*sizeof(access_conf_t); - size_t first_block_length; - size_t second_block_length; - buffer_bytes_used = 0; - - log_block_t log_block = {.check = {'$', '$', '$', '$'}}; - - size_t block_length = sizeof(log_block_t); -// printf("Block length is: %u",(uint16_t)block_length); - -// uint16_t test_counter = 0; - - /* start copying data to buffer */ - while (1) { - copy_block(&log_block); - - /* no more free space in buffer */ - if (buffer_bytes_used + (uint16_t)block_length > BUFFER_BYTES) { - printf("[sdlog] buf full, skipping\n"); - } - - /* data needs to be wrapped around ringbuffer*/ - else if (buffer_cursor_end + block_length >= buffer_end) { - /* first block length is from cursor until the end of the buffer */ - first_block_length = (size_t)(buffer_end - buffer_cursor_end); - /* second block length is the rest */ - second_block_length = block_length - first_block_length; - /* copy the data, not the pointer conversion */ - memcpy(buffer_cursor_end, ((uint8_t *) & (log_block)), first_block_length); - memcpy(buffer_start, ((uint8_t *) & (log_block)) + first_block_length, second_block_length); - /* set the end position of the cursor */ - buffer_cursor_end = buffer_start + second_block_length; - /* increase the amount stored in the buffer */ - buffer_bytes_used += block_length; - bytes_sent += block_length; - } - - /* data does not need to be wrapped around */ - else { - /* copy the whole block in one step */ - memcpy(buffer_cursor_end, ((uint8_t *) & (log_block)), block_length); - /* set the cursor to 0 of the buffer instead of the end */ - buffer_cursor_end = buffer_start + (buffer_cursor_end - buffer_start + block_length) % BUFFER_BYTES; - /* increase the amount stored in the buffer */ - buffer_bytes_used += block_length; - bytes_sent += block_length; - } - - /* also end the pthread when we receive a SIGUSR1 */ - if (sdlog_sigusr1_rcvd == true) { - break; - } - } - - return NULL; -} diff --git a/apps/sdlog/sdlog.h b/apps/sdlog/sdlog.h deleted file mode 100644 index 8012af1777..0000000000 --- a/apps/sdlog/sdlog.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * sdlog.h - * - * Created on: Mar 8, 2012 - * Author: romanpatscheider - */ - -#ifndef SENSORS_H_ -#define SENSORS_H_ -/**************************************************************************** - * Included Files - ****************************************************************************/ - - -#define MAX_NO_LOGFOLDER 3000 // tested up to here... - -#endif /* SENSORS_H_ */ diff --git a/apps/sdlog/sdlog_generated.h b/apps/sdlog/sdlog_generated.h deleted file mode 100644 index ca16ef908a..0000000000 --- a/apps/sdlog/sdlog_generated.h +++ /dev/null @@ -1,238 +0,0 @@ -/* This file is autogenerated in nuttx/configs/px4fmu/include/updatesdlog.py */ - -#ifndef SDLOG_GENERATED_H_ -#define SDLOG_GENERATED_H_ - - -typedef struct { - uint64_t sensors_raw_timestamp; - int16_t sensors_raw_gyro_raw[3]; - uint16_t sensors_raw_gyro_raw_counter; - int16_t sensors_raw_accelerometer_raw[3]; - uint16_t sensors_raw_accelerometer_raw_counter; - float attitude_roll; - float attitude_pitch; - float attitude_yaw; - float position_lat; - float position_lon; - float position_alt; - float position_relative_alt; - float position_vx; - float position_vy; - float position_vz; - int32_t gps_lat; - int32_t gps_lon; - int32_t gps_alt; - uint16_t gps_eph; - float ardrone_control_setpoint_thrust_cast; - float ardrone_control_setpoint_attitude[3]; - float ardrone_control_position_control_output[3]; - float ardrone_control_attitude_setpoint_navigationframe_from_positioncontroller[3]; - char check[4]; -} __attribute__((__packed__)) log_block_t; - -void copy_block(log_block_t *log_block) -{ - if (global_data_wait(&global_data_sensors_raw->access_conf_rate_low) == 0) { - memcpy(&log_block->sensors_raw_timestamp, &global_data_sensors_raw->timestamp, sizeof(uint64_t) * 1); - memcpy(&log_block->sensors_raw_gyro_raw, &global_data_sensors_raw->gyro_raw, sizeof(int16_t) * 3); - memcpy(&log_block->sensors_raw_gyro_raw_counter, &global_data_sensors_raw->gyro_raw_counter, sizeof(uint16_t) * 1); - memcpy(&log_block->sensors_raw_accelerometer_raw, &global_data_sensors_raw->accelerometer_raw, sizeof(int16_t) * 3); - memcpy(&log_block->sensors_raw_accelerometer_raw_counter, &global_data_sensors_raw->accelerometer_raw_counter, sizeof(uint16_t) * 1); - - if (global_data_trylock(&global_data_attitude->access_conf) == 0) { - memcpy(&log_block->attitude_roll, &global_data_attitude->roll, sizeof(float) * 1); - memcpy(&log_block->attitude_pitch, &global_data_attitude->pitch, sizeof(float) * 1); - memcpy(&log_block->attitude_yaw, &global_data_attitude->yaw, sizeof(float) * 1); - global_data_unlock(&global_data_attitude->access_conf); - } - - if (global_data_trylock(&global_data_position->access_conf) == 0) { - memcpy(&log_block->position_lat, &global_data_position->lat, sizeof(float) * 1); - memcpy(&log_block->position_lon, &global_data_position->lon, sizeof(float) * 1); - memcpy(&log_block->position_alt, &global_data_position->alt, sizeof(float) * 1); - memcpy(&log_block->position_relative_alt, &global_data_position->relative_alt, sizeof(float) * 1); - memcpy(&log_block->position_vx, &global_data_position->vx, sizeof(float) * 1); - memcpy(&log_block->position_vy, &global_data_position->vy, sizeof(float) * 1); - memcpy(&log_block->position_vz, &global_data_position->vz, sizeof(float) * 1); - global_data_unlock(&global_data_position->access_conf); - } - - if (global_data_trylock(&global_data_gps->access_conf) == 0) { - memcpy(&log_block->gps_lat, &global_data_gps->lat, sizeof(int32_t) * 1); - memcpy(&log_block->gps_lon, &global_data_gps->lon, sizeof(int32_t) * 1); - memcpy(&log_block->gps_alt, &global_data_gps->alt, sizeof(int32_t) * 1); - memcpy(&log_block->gps_eph, &global_data_gps->eph, sizeof(uint16_t) * 1); - global_data_unlock(&global_data_gps->access_conf); - } - - if (global_data_trylock(&global_data_ardrone_control->access_conf) == 0) { - memcpy(&log_block->ardrone_control_setpoint_thrust_cast, &global_data_ardrone_control->setpoint_thrust_cast, sizeof(float) * 1); - memcpy(&log_block->ardrone_control_setpoint_attitude, &global_data_ardrone_control->setpoint_attitude, sizeof(float) * 3); - memcpy(&log_block->ardrone_control_position_control_output, &global_data_ardrone_control->position_control_output, sizeof(float) * 3); - memcpy(&log_block->ardrone_control_attitude_setpoint_navigationframe_from_positioncontroller, &global_data_ardrone_control->attitude_setpoint_navigationframe_from_positioncontroller, sizeof(float) * 3); - global_data_unlock(&global_data_ardrone_control->access_conf); - } - - global_data_unlock(&global_data_sensors_raw->access_conf_rate_low); - } -} -#define MFILE_STRING "% This file is autogenerated in updatesdlog.py and mfile.template in apps/sdlog\n\ -%% Define logged values \n\ -\n\ -logTypes = {};\n\ -logTypes{end+1} = struct('data','sensors_raw','variable_name','timestamp','type_name','uint64','type_bytes',8,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','sensors_raw','variable_name','gyro_raw','type_name','int16','type_bytes',2,'number_of_array',3);\n\ -logTypes{end+1} = struct('data','sensors_raw','variable_name','gyro_raw_counter','type_name','uint16','type_bytes',2,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','sensors_raw','variable_name','accelerometer_raw','type_name','int16','type_bytes',2,'number_of_array',3);\n\ -logTypes{end+1} = struct('data','sensors_raw','variable_name','accelerometer_raw_counter','type_name','uint16','type_bytes',2,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','attitude','variable_name','roll','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','attitude','variable_name','pitch','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','attitude','variable_name','yaw','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','lat','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','lon','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','alt','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','relative_alt','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','vx','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','vy','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','position','variable_name','vz','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','gps','variable_name','lat','type_name','int32','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','gps','variable_name','lon','type_name','int32','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','gps','variable_name','alt','type_name','int32','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','gps','variable_name','eph','type_name','uint16','type_bytes',2,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','ardrone_control','variable_name','setpoint_thrust_cast','type_name','float','type_bytes',4,'number_of_array',1);\n\ -logTypes{end+1} = struct('data','ardrone_control','variable_name','setpoint_attitude','type_name','float','type_bytes',4,'number_of_array',3);\n\ -logTypes{end+1} = struct('data','ardrone_control','variable_name','position_control_output','type_name','float','type_bytes',4,'number_of_array',3);\n\ -logTypes{end+1} = struct('data','ardrone_control','variable_name','attitude_setpoint_navigationframe_from_positioncontroller','type_name','float','type_bytes',4,'number_of_array',3);\n\ -\ -%% Import logfiles\n\ -\n\ -% define log file and GPSs\n\ -logfileFolder = 'logfiles';\n\ -fileName = 'all';\n\ -fileEnding = 'px4log';\n\ -\n\ -numberOfLogTypes = length(logTypes);\n\ -\n\ -path = [fileName,'.', fileEnding];\n\ -fid = fopen(path, 'r');\n\ -\n\ -% get file length\n\ -fseek(fid, 0,'eof');\n\ -fileLength = ftell(fid);\n\ -fseek(fid, 0,'bof');\n\ -\n\ -% get length of one block\n\ -blockLength = 4; % check: $$$$\n\ -for i=1:numberOfLogTypes\n\ - blockLength = blockLength + logTypes{i}.type_bytes*logTypes{i}.number_of_array;\n\ -end\n\ -\n\ -% determine number of entries\n\ -entries = fileLength / blockLength;\n\ -\n\ -\n\ -% import data\n\ -offset = 0;\n\ -for i=1:numberOfLogTypes\n\ - \n\ - data.(genvarname(logTypes{i}.data)).(genvarname(logTypes{i}.variable_name)) = transpose(fread(fid,[logTypes{i}.number_of_array,entries],[num2str(logTypes{i}.number_of_array),'*',logTypes{i}.type_name,'=>',logTypes{i}.type_name],blockLength-logTypes{i}.type_bytes*logTypes{i}.number_of_array));\n\ - offset = offset + logTypes{i}.type_bytes*logTypes{i}.number_of_array;\n\ - fseek(fid, offset,'bof');\n\ - \n\ - progressPercentage = i/numberOfLogTypes*100;\n\ - fprintf('%3.0f%%',progressPercentage);\n\ -end\n\ -\n\ -\n\ -%% Plots\n\ -\n\ -figure\n\ -plot(data.sensors_raw.timestamp,data.sensors_raw.gyro_raw)\n\ -\n\ -figure\n\ -plot(data.sensors_raw.timestamp,data.sensors_raw.accelerometer_raw)\n\ -\n\ -%% Check for lost data\n\ -\n\ -% to detect lost frames (either when logging to sd card or if no new data is\n\ -% data is available for some time)\n\ -diff_counter = diff(data.sensors_raw.gyro_raw_counter);\n\ -figure\n\ -plot(diff_counter)\n\ -\n\ -% to detect how accurate the timing was\n\ -diff_timestamp = diff(data.sensors_raw.timestamp);\n\ -\n\ -figure\n\ -plot(diff_timestamp)\n\ -\n\ -%% Export to file for google earth\n\ -\n\ -\n\ -if(isfield(data.gps,'lat') && isfield(data.gps,'lon') && isfield(data.gps,'alt'))\n\ -\n\ - % extract coordinates and height where they are not zero\n\ - maskWhereNotZero = ((data.gps.lon ~= 0 & data.gps.lat ~= 0 ) & data.gps.alt ~= 0);\n\ -\n\ - % plot\n\ - figure\n\ - plot3(data.gps.lon(maskWhereNotZero),data.gps.lat(maskWhereNotZero),data.gps.alt(maskWhereNotZero))\n\ -\n\ -\n\ - % create a kml file according to https://developers.google.com/kml/documentation/kml_tut\n\ - % also see https://support.google.com/earth/bin/answer.py?hl=en&answer=148072&topic=2376756&ctx=topic\n\ -\n\ - % open file and overwrite content\n\ - fileId = fopen('gps_path.kml','w+');\n\ -\n\ - % define strings that should be written to file\n\ - fileStartDocumentString = ['PathsPath'];\n\ -\n\ - fileStyleString = '';\n\ -\n\ - filePlacemarkString = 'Absolute ExtrudedTransparent blue wall with blue outlines#blueLinebluePoly11absolute';\n\ -\n\ - fileEndPlacemarkString = '';\n\ - fileEndDocumentString = '';\n\ -\n\ - % start writing to file\n\ - fprintf(fileId,fileStartDocumentString);\n\ -\n\ - fprintf(fileId,fileStyleString);\n\ - fprintf(fileId,filePlacemarkString);\n\ -\n\ - \n\ - lonTemp = double(data.gps.lon(maskWhereNotZero))/1E7;\n\ - latTemp = double(data.gps.lat(maskWhereNotZero))/1E7;\n\ - altTemp = double(data.gps.alt(maskWhereNotZero))/1E3 + 100.0; % in order to see the lines above ground\n\ -\n\ - % write coordinates to file\n\ - for k=1:length(data.gps.lat(maskWhereNotZero))\n\ - if(mod(k,10)==0)\n\ - fprintf(fileId,'%.10f,%.10f,%.10f\\n',lonTemp(k),latTemp(k),altTemp(k));\n\ - end\n\ - end\n\ -\n\ - % write end placemark\n\ - fprintf(fileId,fileEndPlacemarkString);\n\ -\n\ - % write end of file\n\ - fprintf(fileId,fileEndDocumentString);\n\ -\n\ - % close file, it should now be readable in Google Earth using File -> Open\n\ - fclose(fileId);\n\ -\n\ -end\n\ -\n\ -if(isfield(data.position,'lat') && isfield(data.position,'lon') && isfield(data.position,'alt'))\n\ -\n\ - % extract coordinates and height where they are not zero\n\ - maskWhereNotZero = ((data.position.lon ~= 0 & data.position.lat ~= 0 ) & data.position.alt ~= 0);\n\ - \n\ - % plot\n\ - figure\n\ - plot3(data.position.lon(maskWhereNotZero),data.position.lat(maskWhereNotZero),data.position.alt(maskWhereNotZero))\n\ -end\n\ -" -#endif \ No newline at end of file diff --git a/apps/sdlog/updatesdlog.py b/apps/sdlog/updatesdlog.py deleted file mode 100644 index 5892bc40ae..0000000000 --- a/apps/sdlog/updatesdlog.py +++ /dev/null @@ -1,199 +0,0 @@ -import os -import glob - -# path to global data files -base_path = '../orb/' -cfile = './sdlog_generated.h' -mfile_template = './mfile.template' - -# there should be one LOGBROADCAST which gives the timing for the logging -logbroadcast_found = 0 - -# these types can nicely be imported into Matlab -allowed_types = ['uint8_t','int8_t','uint16_t','int16_t','uint32_t','int32_t','uint64_t','int64_t','float','double'] - -log_entries = [] -# loop through global_data_files ending in _t.h and look for LOGME (per variable) and LOGBROADCAST (overall) -for path in glob.glob( os.path.join(base_path, '*_t.h') ): - # filename is supposed to be global_data_bapedibup_t.h - if 'global_data' not in path: - print 'path: ' + path - raise 'wrong filename found' - f = open(path, 'r') - access_conf_found = False; - # strip away ../../../../apps/orb/ and _t.h - data_name = path.lstrip(base_path)[0:-4] - # strip away ../../../../apps/orb/ and global_data_ and _t.h - name = path.lstrip(base_path)[12:-4] - log_entry = {'data_name': data_name,'name':name,'vars': []} - - logbroadcast = False; - - # loop throug lines - for line in f: - - line_parts = line.split() - # access_conf is needed to lock the data - if 'access_conf_t' in line: - - # always use the access_conf which has the LOGBROADCAST flag - if 'LOGBROADCAST' in line: - access_conf_found = True - log_entry['access_conf_name'] = line_parts[1].rstrip(';') - logbroadcast = True - print 'LOGBROADCAST found in ' + data_name - logbroadcast_found += 1 - # but use an access_conf anyway - elif access_conf_found == False: - access_conf_found = True - log_entry['access_conf_name'] = line_parts[1].rstrip(';') - # variables flagged with LOGME should be logged - elif 'LOGME' in line: - var_entry = {'type': line_parts[0]} - - # check that it is an allowed type - if var_entry['type'] not in allowed_types: - print 'file: '+ path + ', type: ' + var_entry['type'] - raise 'unsupported type' - - # save variable name and number for array - if '[' in line_parts[1]: - var_entry['name'] = line_parts[1].split('[')[0] - var_entry['number'] = line_parts[1].split('[')[1].rstrip('];') - else: - var_entry['name'] = line_parts[1].rstrip(';') - var_entry['number'] = 1 - - # add the variable - log_entry['vars'].append(var_entry) - # only use the global data file if any variables have a LOGME - if logbroadcast == True and len(log_entry['vars']) > 0: - logbroadcast_entry = log_entry - elif len(log_entry['vars']) > 0: - print 'added ' + log_entry['data_name'] - log_entries.append(log_entry) - f.close() - -# check that we have one and only one LOGBROADCAST -if logbroadcast_found > 1: - raise 'too many LOGBROADCAST found\n' -elif logbroadcast_found == 0: - raise 'no LOGBROADCAST found\n' - -# write function to c file - -header = '/* This file is autogenerated in nuttx/configs/px4fmu/include/updatesdlog.py */\n\ -\n\ -#ifndef SDLOG_GENERATED_H_\n\ -#define SDLOG_GENERATED_H_\n\ -\n\ -\n\ -' - -cstruct = 'typedef struct\n{\n' - -for j in logbroadcast_entry['vars']: - cstruct += '\t' + j['type'] + ' ' + logbroadcast_entry['name'] + '_' + j['name'] - if j['number'] == 1: - cstruct += ';\n' - else: - cstruct += '[' + j['number'] + '];\n' - -for i in log_entries: - for j in i['vars']: - cstruct += '\t' + j['type'] + ' ' + i['name'] + '_' + j['name'] - if j['number'] == 1: - cstruct += ';\n' - else: - cstruct += '[' + j['number'] + '];\n' - -cstruct += '\tchar check[4];\n} __attribute__((__packed__)) log_block_t;\n\n' - - -copy_function = 'void copy_block(log_block_t* log_block)\n{\n' -copy_function += '\tif(global_data_wait(&' + logbroadcast_entry['data_name'] + '->' + logbroadcast_entry['access_conf_name'] + ') == 0)\n\t{\n' - -for j in logbroadcast_entry['vars']: - copy_function += '\t\tmemcpy(&log_block->' + logbroadcast_entry['name'] + '_' + j['name'] + ',&' + logbroadcast_entry['data_name'] + '->' + j['name'] + ',sizeof(' + j['type'] + ')*' + str(j['number']) + ');\n' - #copy_function += '\t\t}\n' - -# generate logging MACRO - - -for i in log_entries: - copy_function += '\t\tif(global_data_trylock(&' + i['data_name'] + '->' + i['access_conf_name'] + ') == 0)\n\t\t{\n' - - for j in i['vars']: - copy_function += '\t\t\tmemcpy(&log_block->' + i['name'] + '_' + j['name'] + ',&' + i['data_name'] + '->' + j['name'] + ',sizeof(' + j['type'] + ')*' + str(j['number']) + ');\n' - - copy_function += '\t\t\tglobal_data_unlock(&' + i['data_name'] + '->' + i['access_conf_name'] + ');\n' - copy_function += '\t\t}\n' -copy_function += '\t\tglobal_data_unlock(&' + logbroadcast_entry['data_name'] + '->' + logbroadcast_entry['access_conf_name'] + ');\n' -copy_function += '\t}\n' - -copy_function += '}\n' - -footer = '\n#endif' - - - -# generate mfile - -type_bytes = { -'uint8_t' : 1, -'int8_t' : 1, -'uint16_t' : 2, -'int16_t' : 2, -'uint32_t' : 4, -'int32_t' : 4, -'uint64_t' : 8, -'int64_t' : 8, -'float' : 4, -'double' : 8, -} - -type_names_matlab = { -'uint8_t' : 'uint8', -'int8_t' : 'int8', -'uint16_t' : 'uint16', -'int16_t' : 'int16', -'uint32_t' : 'uint32', -'int32_t' : 'int32', -'uint64_t' : 'uint64', -'int64_t' : 'int64', -'float' : 'float', -'double' : 'double', -} - - -# read template mfile -mf = open(mfile_template, 'r') -mfile_template_string = mf.read() - -mfile_define = '#define MFILE_STRING "% This file is autogenerated in updatesdlog.py and mfile.template in apps/sdlog\\n\\\n' -mfile_define += '%% Define logged values \\n\\\n\\n\\\nlogTypes = {};\\n\\\n' - -for j in logbroadcast_entry['vars']: - mfile_define += 'logTypes{end+1} = struct(\'data\',\'' + logbroadcast_entry['name'] + '\',\'variable_name\',\'' + j['name'] + '\',\'type_name\',\'' + type_names_matlab.get(j['type']) + '\',\'type_bytes\',' + str(type_bytes.get(j['type'])) + ',\'number_of_array\',' + str(j['number']) + ');\\n\\\n' - -for i in log_entries: - for j in i['vars']: - mfile_define += 'logTypes{end+1} = struct(\'data\',\'' + i['name'] + '\',\'variable_name\',\'' + j['name'] + '\',\'type_name\',\'' + type_names_matlab.get(j['type']) + '\',\'type_bytes\',' + str(type_bytes.get(j['type'])) + ',\'number_of_array\',' + str(j['number']) + ');\\n\\\n' - - - -mfile_define += '\\\n' + mfile_template_string.replace('\n', '\\n\\\n').replace('\"','\\\"') + '"' - - -# write to c File -cf = open(cfile, 'w') -cf.write(header) -cf.write(cstruct); -cf.write(copy_function) - -cf.write(mfile_define) - -cf.write(footer) -cf.close() - -print 'finished, cleanbuild needed!' diff --git a/apps/sensors/Makefile b/apps/sensors/Makefile index 125839bb35..526fb0164f 100644 --- a/apps/sensors/Makefile +++ b/apps/sensors/Makefile @@ -39,4 +39,7 @@ APPNAME = sensors PRIORITY = SCHED_PRIORITY_MAX-5 STACKSIZE = 4096 +CXXSRCS = sensors.cpp +CSRCS = sensor_params.c + include $(APPDIR)/mk/app.mk diff --git a/apps/sensors/sensor_params.c b/apps/sensors/sensor_params.c new file mode 100644 index 0000000000..e6f2f7e765 --- /dev/null +++ b/apps/sensors/sensor_params.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * @author Thomas Gubler + * @author Julian Oes + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file sensor_params.c + * + * Parameters defined by the sensors task. + */ + +#include + +#include + +PARAM_DEFINE_FLOAT(SENS_GYRO_XOFF, 0.0f); +PARAM_DEFINE_FLOAT(SENS_GYRO_YOFF, 0.0f); +PARAM_DEFINE_FLOAT(SENS_GYRO_ZOFF, 0.0f); + +PARAM_DEFINE_FLOAT(SENS_MAG_XOFF, 0.0f); +PARAM_DEFINE_FLOAT(SENS_MAG_YOFF, 0.0f); +PARAM_DEFINE_FLOAT(SENS_MAG_ZOFF, 0.0f); + +PARAM_DEFINE_FLOAT(SENS_ACC_XOFF, 0.0f); +PARAM_DEFINE_FLOAT(SENS_ACC_YOFF, 0.0f); +PARAM_DEFINE_FLOAT(SENS_ACC_ZOFF, 0.0f); + +PARAM_DEFINE_FLOAT(SENS_ACC_XSCALE, 0.0f); +PARAM_DEFINE_FLOAT(SENS_ACC_YSCALE, 0.0f); +PARAM_DEFINE_FLOAT(SENS_ACC_ZSCALE, 0.0f); + +PARAM_DEFINE_FLOAT(RC1_MIN, 1000.0f); +PARAM_DEFINE_FLOAT(RC1_TRIM, 1500.0f); +PARAM_DEFINE_FLOAT(RC1_MAX, 2000.0f); +PARAM_DEFINE_FLOAT(RC1_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC1_DZ, 30.0f); +PARAM_DEFINE_FLOAT(RC1_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC2_MIN, 1000); +PARAM_DEFINE_FLOAT(RC2_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC2_MAX, 2000); +PARAM_DEFINE_FLOAT(RC2_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC2_DZ, 30.0f); +PARAM_DEFINE_FLOAT(RC2_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC3_MIN, 1000); +PARAM_DEFINE_FLOAT(RC3_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC3_MAX, 2000); +PARAM_DEFINE_FLOAT(RC3_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC3_DZ, 10.0f); +PARAM_DEFINE_FLOAT(RC3_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC4_MIN, 1000); +PARAM_DEFINE_FLOAT(RC4_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC4_MAX, 2000); +PARAM_DEFINE_FLOAT(RC4_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC4_DZ, 30.0f); +PARAM_DEFINE_FLOAT(RC4_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC5_MIN, 1000); +PARAM_DEFINE_FLOAT(RC5_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC5_MAX, 2000); +PARAM_DEFINE_FLOAT(RC5_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC5_DZ, 0.0f); +PARAM_DEFINE_FLOAT(RC5_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC6_MIN, 1000); +PARAM_DEFINE_FLOAT(RC6_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC6_MAX, 2000); +PARAM_DEFINE_FLOAT(RC6_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC6_DZ, 0.1f); +PARAM_DEFINE_FLOAT(RC6_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC7_MIN, 1000); +PARAM_DEFINE_FLOAT(RC7_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC7_MAX, 2000); +PARAM_DEFINE_FLOAT(RC7_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC7_DZ, 0.1f); +PARAM_DEFINE_FLOAT(RC7_EXP, 0.0f); + +PARAM_DEFINE_FLOAT(RC8_MIN, 1000); +PARAM_DEFINE_FLOAT(RC8_TRIM, 1500); +PARAM_DEFINE_FLOAT(RC8_MAX, 2000); +PARAM_DEFINE_FLOAT(RC8_REV, 1.0f); +PARAM_DEFINE_FLOAT(RC8_DZ, 0.1f); +PARAM_DEFINE_FLOAT(RC8_EXP, 0.0f); + +PARAM_DEFINE_INT32(RC_TYPE, 1); // 1 = FUTABA + +/* default is conversion factor for the PX4IO / PX4IOAR board, the factor for PX4FMU standalone is different */ +PARAM_DEFINE_FLOAT(BAT_V_SCALING, (3.3f * 52.0f / 5.0f / 4095.0f)); + +PARAM_DEFINE_INT32(RC_MAP_ROLL, 1); +PARAM_DEFINE_INT32(RC_MAP_PITCH, 2); +PARAM_DEFINE_INT32(RC_MAP_THROTTLE, 3); +PARAM_DEFINE_INT32(RC_MAP_YAW, 4); +PARAM_DEFINE_INT32(RC_MAP_MODE_SW, 5); + +PARAM_DEFINE_FLOAT(RC_SCALE_ROLL, 0.4f); +PARAM_DEFINE_FLOAT(RC_SCALE_PITCH, 0.4f); +PARAM_DEFINE_FLOAT(RC_SCALE_YAW, 3.0f); + diff --git a/apps/sensors/sensors.c b/apps/sensors/sensors.c deleted file mode 100644 index 564ee4f8c4..0000000000 --- a/apps/sensors/sensors.c +++ /dev/null @@ -1,987 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: @author Lorenz Meier - * @author Thomas Gubler - * @author Julian Oes - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/** - * @file sensors.c - * Sensor readout process. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "sensors.h" - -#define errno *get_errno_ptr() - -#define SENSOR_INTERVAL_MICROSEC 2000 - -#define GYRO_HEALTH_COUNTER_LIMIT_ERROR 20 /* 40 ms downtime at 500 Hz update rate */ -#define ACC_HEALTH_COUNTER_LIMIT_ERROR 20 /* 40 ms downtime at 500 Hz update rate */ -#define MAGN_HEALTH_COUNTER_LIMIT_ERROR 100 /* 1000 ms downtime at 100 Hz update rate */ -#define BARO_HEALTH_COUNTER_LIMIT_ERROR 50 /* 500 ms downtime at 100 Hz update rate */ -#define ADC_HEALTH_COUNTER_LIMIT_ERROR 10 /* 100 ms downtime at 100 Hz update rate */ - -#define GYRO_HEALTH_COUNTER_LIMIT_OK 5 -#define ACC_HEALTH_COUNTER_LIMIT_OK 5 -#define MAGN_HEALTH_COUNTER_LIMIT_OK 5 -#define BARO_HEALTH_COUNTER_LIMIT_OK 5 -#define ADC_HEALTH_COUNTER_LIMIT_OK 5 - -#define ADC_BATTERY_VOLATGE_CHANNEL 10 - -#define BAT_VOL_INITIAL 12.f -#define BAT_VOL_LOWPASS_1 0.99f -#define BAT_VOL_LOWPASS_2 0.01f -#define VOLTAGE_BATTERY_IGNORE_THRESHOLD_VOLTS 3.5f - -/* PPM Settings */ -#define PPM_MIN 1000 -#define PPM_MAX 2000 -/* Internal resolution is 10000 */ -#define PPM_SCALE 10000/((PPM_MAX-PPM_MIN)/2) - -#define PPM_MID (PPM_MIN+PPM_MAX)/2 - -static pthread_cond_t sensors_read_ready; -static pthread_mutex_t sensors_read_ready_mutex; - -static int sensors_timer_loop_counter = 0; - -/* File descriptors for all sensors */ -static int fd_gyro = -1; -static int fd_accelerometer = -1; -static int fd_magnetometer = -1; -static int fd_barometer = -1; -static int fd_adc = -1; - -static bool thread_should_exit = false; -static bool thread_running = false; -static int sensors_task; - -/* Private functions declared static */ -static void sensors_timer_loop(void *arg); - -#ifdef CONFIG_HRT_PPM -extern uint16_t ppm_buffer[]; -extern unsigned ppm_decoded_channels; -extern uint64_t ppm_last_valid_decode; -#endif - -/* file handle that will be used for subscribing */ -static int sensor_pub; - -/** - * Sensor readout and publishing. - * - * This function reads all onboard sensors and publishes the sensor_combined topic. - * - * @see sensor_combined_s - * @ingroup apps - */ -__EXPORT int sensors_main(int argc, char *argv[]); - -/** - * Print the usage - */ -static void usage(const char *reason); - -/** - * Initialize all sensor drivers. - * - * @return 0 on success, != 0 on failure - */ -static int sensors_init(void) -{ - printf("[sensors] Sensor configuration..\n"); - - /* open magnetometer */ - fd_magnetometer = open("/dev/hmc5883l", O_RDONLY); - - if (fd_magnetometer < 0) { - fprintf(stderr, "[sensors] HMC5883L open fail (err #%d): %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - fflush(stderr); - /* this sensor is critical, exit on failed init */ - errno = ENOSYS; - return ERROR; - - } else { - printf("[sensors] HMC5883L open ok\n"); - } - - /* open barometer */ - fd_barometer = open("/dev/ms5611", O_RDONLY); - - if (fd_barometer < 0) { - fprintf(stderr, "[sensors] MS5611 open fail (err #%d): %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - fflush(stderr); - - } else { - printf("[sensors] MS5611 open ok\n"); - } - - /* open gyro */ - fd_gyro = open("/dev/l3gd20", O_RDONLY); - - if (fd_gyro < 0) { - fprintf(stderr, "[sensors] L3GD20 open fail (err #%d): %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - fflush(stderr); - /* this sensor is critical, exit on failed init */ - errno = ENOSYS; - return ERROR; - - } else { - printf("[sensors] L3GD20 open ok\n"); - } - - /* open accelerometer */ - fd_accelerometer = open("/dev/bma180", O_RDONLY); - - if (fd_accelerometer < 0) { - fprintf(stderr, "[sensors] BMA180: open fail (err #%d): %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - fflush(stderr); - /* this sensor is critical, exit on failed init */ - errno = ENOSYS; - return ERROR; - - } else { - printf("[sensors] BMA180 open ok\n"); - } - - /* open adc */ - fd_adc = open("/dev/adc0", O_RDONLY | O_NONBLOCK); - - if (fd_adc < 0) { - fprintf(stderr, "[sensors] ADC: open fail (err #%d): %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - fflush(stderr); - /* this sensor is critical, exit on failed init */ - errno = ENOSYS; - return ERROR; - - } else { - printf("[sensors] ADC open ok\n"); - } - - /* configure gyro */ - if (ioctl(fd_gyro, L3GD20_SETRATE, L3GD20_RATE_760HZ_LP_30HZ) || ioctl(fd_gyro, L3GD20_SETRANGE, L3GD20_RANGE_500DPS)) { - fprintf(stderr, "[sensors] L3GD20 configuration (ioctl) fail (err #%d): %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - fflush(stderr); - /* this sensor is critical, exit on failed init */ - errno = ENOSYS; - return ERROR; - - } else { - printf("[sensors] L3GD20 configuration ok\n"); - } - - /* XXX Add IOCTL configuration of remaining sensors */ - - printf("[sensors] All sensors configured\n"); - return OK; -} - -/** - * Callback function called by high resolution timer. - * - * This function signals a pthread condition and wakes up the - * sensor main loop. - */ -static void sensors_timer_loop(void *arg) -{ - /* Inform the read thread that it is now time to read */ - sensors_timer_loop_counter++; - /* Do not use global data broadcast because of - * use of printf() in call - would be fatal here - */ - pthread_cond_broadcast(&sensors_read_ready); -} - -int sensors_thread_main(int argc, char *argv[]) -{ - /* inform about start */ - printf("[sensors] Initializing..\n"); - fflush(stdout); - int ret = OK; - - /* start sensor reading */ - if (sensors_init() != OK) { - fprintf(stderr, "[sensors] ERROR: Failed to initialize all sensors\n"); - /* Clean up */ - close(fd_gyro); - close(fd_accelerometer); - close(fd_magnetometer); - close(fd_barometer); - close(fd_adc); - - fprintf(stderr, "[sensors] rebooting system.\n"); - fflush(stderr); - fflush(stdout); - usleep(100000); - - /* Sensors are critical, immediately reboot system on failure */ - reboot(); - /* Not ever reaching here */ - - } else { - /* flush stdout from init routine */ - fflush(stdout); - } - - bool gyro_healthy = false; - bool acc_healthy = false; - bool magn_healthy = false; - bool baro_healthy = false; - bool adc_healthy = false; - - bool hil_enabled = false; /**< HIL is disabled by default */ - bool publishing = false; /**< the app is not publishing by default, only if HIL is disabled on first run */ - - int magcounter = 0; - int barocounter = 0; - int adccounter = 0; - - unsigned int mag_fail_count = 0; - unsigned int mag_success_count = 0; - - unsigned int baro_fail_count = 0; - unsigned int baro_success_count = 0; - - unsigned int gyro_fail_count = 0; - unsigned int gyro_success_count = 0; - - unsigned int acc_fail_count = 0; - unsigned int acc_success_count = 0; - - unsigned int adc_fail_count = 0; - unsigned int adc_success_count = 0; - - ssize_t ret_gyro; - ssize_t ret_accelerometer; - ssize_t ret_magnetometer; - ssize_t ret_barometer; - ssize_t ret_adc; - int nsamples_adc; - - int16_t buf_gyro[3]; - int16_t buf_accelerometer[3]; - int16_t buf_magnetometer[7]; - float buf_barometer[3]; - - int16_t mag_offset[3] = {0, 0, 0}; - int16_t acc_offset[3] = {200, 0, 0}; - int16_t gyro_offset[3] = {0, 0, 0}; - - bool mag_calibration_enabled = false; - - #pragma pack(push,1) - struct adc_msg4_s { - uint8_t am_channel1; /**< The 8-bit ADC Channel 1 */ - int32_t am_data1; /**< ADC convert result 1 (4 bytes) */ - uint8_t am_channel2; /**< The 8-bit ADC Channel 2 */ - int32_t am_data2; /**< ADC convert result 2 (4 bytes) */ - uint8_t am_channel3; /**< The 8-bit ADC Channel 3 */ - int32_t am_data3; /**< ADC convert result 3 (4 bytes) */ - uint8_t am_channel4; /**< The 8-bit ADC Channel 4 */ - int32_t am_data4; /**< ADC convert result 4 (4 bytes) */ - }; - #pragma pack(pop) - - struct adc_msg4_s buf_adc; - size_t adc_readsize = 1 * sizeof(struct adc_msg4_s); - - float battery_voltage_conversion; - battery_voltage_conversion = global_data_parameter_storage->pm.param_values[PARAM_BATTERYVOLTAGE_CONVERSION]; - - if (-1 == (int)battery_voltage_conversion) { - /* default is conversion factor for the PX4IO / PX4IOAR board, the factor for PX4FMU standalone is different */ - battery_voltage_conversion = 3.3f * 52.0f / 5.0f / 4095.0f; - } - -#ifdef CONFIG_HRT_PPM - int ppmcounter = 0; -#endif - /* initialize to 100 to execute immediately */ - int paramcounter = 100; - int excessive_readout_time_counter = 0; - int read_loop_counter = 0; - - /* Empty sensor buffers, avoid junk values */ - /* Read first two values of each sensor into void */ - (void)read(fd_gyro, buf_gyro, sizeof(buf_gyro)); - (void)read(fd_accelerometer, buf_accelerometer, sizeof(buf_accelerometer)); - (void)read(fd_magnetometer, buf_magnetometer, sizeof(buf_magnetometer)); - - if (fd_barometer > 0)(void)read(fd_barometer, buf_barometer, sizeof(buf_barometer)); - - struct sensor_combined_s raw = { - .timestamp = hrt_absolute_time(), - .gyro_raw = {buf_gyro[0], buf_gyro[1], buf_gyro[2]}, - .gyro_raw_counter = 0, - .gyro_rad_s = {0, 0, 0}, - .accelerometer_raw = {buf_accelerometer[0], buf_accelerometer[1], buf_accelerometer[2]}, - .accelerometer_raw_counter = 0, - .accelerometer_m_s2 = {0, 0, 0}, - .magnetometer_raw = {buf_magnetometer[0], buf_magnetometer[1], buf_magnetometer[2]}, - .magnetometer_raw_counter = 0, - .baro_pres_mbar = 0, - .baro_alt_meter = 0, - .baro_temp_celcius = 0, - .battery_voltage_v = BAT_VOL_INITIAL, - .adc_voltage_v = {0, 0 , 0}, - .baro_raw_counter = 0, - .battery_voltage_counter = 0, - .battery_voltage_valid = false, - }; - - /* condition to wait for */ - pthread_mutex_init(&sensors_read_ready_mutex, NULL); - pthread_cond_init(&sensors_read_ready, NULL); - - /* advertise the sensor_combined topic and make the initial publication */ - sensor_pub = orb_advertise(ORB_ID(sensor_combined), &raw); - publishing = true; - - /* advertise the manual_control topic */ - struct manual_control_setpoint_s manual_control = { .mode = ROLLPOS_PITCHPOS_YAWRATE_THROTTLE, - .roll = 0.0f, - .pitch = 0.0f, - .yaw = 0.0f, - .throttle = 0.0f }; - - int manual_control_pub = orb_advertise(ORB_ID(manual_control_setpoint), &manual_control); - - if (manual_control_pub < 0) { - fprintf(stderr, "[sensors] ERROR: orb_advertise for topic manual_control_setpoint failed.\n"); - } - - /* advertise the rc topic */ - struct rc_channels_s rc; - memset(&rc, 0, sizeof(rc)); - int rc_pub = orb_advertise(ORB_ID(rc_channels), &rc); - - if (rc_pub < 0) { - fprintf(stderr, "[sensors] ERROR: orb_advertise for topic rc_channels failed.\n"); - } - - /* subscribe to system status */ - struct vehicle_status_s vstatus; - memset(&vstatus, 0, sizeof(vstatus)); - int vstatus_sub = orb_subscribe(ORB_ID(vehicle_status)); - - - printf("[sensors] rate: %u Hz\n", (unsigned int)(1000000 / SENSOR_INTERVAL_MICROSEC)); - - struct hrt_call sensors_hrt_call; - /* Enable high resolution timer callback to unblock main thread, run after 2 ms */ - hrt_call_every(&sensors_hrt_call, 2000, SENSOR_INTERVAL_MICROSEC, &sensors_timer_loop, NULL); - - thread_running = true; - - while (1) { - pthread_mutex_lock(&sensors_read_ready_mutex); - - struct timespec time_to_wait = {0, 0}; - /* Wait 2 seconds until timeout */ - time_to_wait.tv_nsec = 0; - time_to_wait.tv_sec = time(NULL) + 2; - - if (pthread_cond_timedwait(&sensors_read_ready, &sensors_read_ready_mutex, &time_to_wait) == OK) { - pthread_mutex_unlock(&sensors_read_ready_mutex); - - bool gyro_updated = false; - bool acc_updated = false; - bool magn_updated = false; - bool baro_updated = false; - bool adc_updated = false; - - /* store the time closest to all measurements */ - uint64_t current_time = hrt_absolute_time(); - raw.timestamp = current_time; - - if (paramcounter == 100) { - // XXX paramcounter is not a good name, rename / restructure - // XXX make counter ticks dependent on update rate of sensor main loop - - /* Check HIL state */ - orb_copy(ORB_ID(vehicle_status), vstatus_sub, &vstatus); - - /* switching from non-HIL to HIL mode */ - //printf("[sensors] Vehicle mode: %i \t AND: %i, HIL: %i\n", vstatus.mode, vstatus.mode & VEHICLE_MODE_FLAG_HIL_ENABLED, hil_enabled); - if (vstatus.flag_hil_enabled && !hil_enabled) { - hil_enabled = true; - publishing = false; - int ret = close(sensor_pub); - printf("[sensors] Closing sensor pub: %i \n", ret); - - /* switching from HIL to non-HIL mode */ - - } else if (!publishing && !hil_enabled) { - /* advertise the topic and make the initial publication */ - sensor_pub = orb_advertise(ORB_ID(sensor_combined), &raw); - hil_enabled = false; - publishing = true; - } - - - /* Update RC scalings and function mappings */ - rc.chan[0].scaling_factor = (1 / ((global_data_parameter_storage->pm.param_values[PARAM_RC1_MAX] - global_data_parameter_storage->pm.param_values[PARAM_RC1_MIN]) / 2) - * global_data_parameter_storage->pm.param_values[PARAM_RC1_REV]); - rc.chan[0].mid = (uint16_t)global_data_parameter_storage->pm.param_values[PARAM_RC1_TRIM]; - - rc.chan[1].scaling_factor = (1 / ((global_data_parameter_storage->pm.param_values[PARAM_RC2_MAX] - global_data_parameter_storage->pm.param_values[PARAM_RC2_MIN]) / 2) - * global_data_parameter_storage->pm.param_values[PARAM_RC2_REV]); - rc.chan[1].mid = (uint16_t)global_data_parameter_storage->pm.param_values[PARAM_RC2_TRIM]; - - rc.chan[2].scaling_factor = (1 / ((global_data_parameter_storage->pm.param_values[PARAM_RC3_MAX] - global_data_parameter_storage->pm.param_values[PARAM_RC3_MIN]) / 2) - * global_data_parameter_storage->pm.param_values[PARAM_RC3_REV]); - rc.chan[2].mid = (uint16_t)global_data_parameter_storage->pm.param_values[PARAM_RC3_TRIM]; - - rc.chan[3].scaling_factor = (1 / ((global_data_parameter_storage->pm.param_values[PARAM_RC4_MAX] - global_data_parameter_storage->pm.param_values[PARAM_RC4_MIN]) / 2) - * global_data_parameter_storage->pm.param_values[PARAM_RC4_REV]); - rc.chan[3].mid = (uint16_t)global_data_parameter_storage->pm.param_values[PARAM_RC4_TRIM]; - - rc.chan[4].scaling_factor = (1 / ((global_data_parameter_storage->pm.param_values[PARAM_RC5_MAX] - global_data_parameter_storage->pm.param_values[PARAM_RC5_MIN]) / 2) - * global_data_parameter_storage->pm.param_values[PARAM_RC5_REV]); - rc.chan[4].mid = (uint16_t)global_data_parameter_storage->pm.param_values[PARAM_RC5_TRIM]; - - rc.function[0] = global_data_parameter_storage->pm.param_values[PARAM_THROTTLE_CHAN] - 1; - rc.function[1] = global_data_parameter_storage->pm.param_values[PARAM_ROLL_CHAN] - 1; - rc.function[2] = global_data_parameter_storage->pm.param_values[PARAM_PITCH_CHAN] - 1; - rc.function[3] = global_data_parameter_storage->pm.param_values[PARAM_YAW_CHAN] - 1; - rc.function[4] = global_data_parameter_storage->pm.param_values[PARAM_OVERRIDE_CHAN] - 1; - - gyro_offset[0] = global_data_parameter_storage->pm.param_values[PARAM_SENSOR_GYRO_XOFFSET]; - gyro_offset[1] = global_data_parameter_storage->pm.param_values[PARAM_SENSOR_GYRO_YOFFSET]; - gyro_offset[2] = global_data_parameter_storage->pm.param_values[PARAM_SENSOR_GYRO_ZOFFSET]; - - mag_offset[0] = global_data_parameter_storage->pm.param_values[PARAM_SENSOR_MAG_XOFFSET]; - mag_offset[1] = global_data_parameter_storage->pm.param_values[PARAM_SENSOR_MAG_YOFFSET]; - mag_offset[2] = global_data_parameter_storage->pm.param_values[PARAM_SENSOR_MAG_ZOFFSET]; - - paramcounter = 0; - } - - paramcounter++; - - /* try reading gyro */ - uint64_t start_gyro = hrt_absolute_time(); - ret_gyro = read(fd_gyro, buf_gyro, sizeof(buf_gyro)); - int gyrotime = hrt_absolute_time() - start_gyro; - - if (gyrotime > 500) printf("GYRO (pure read): %d us\n", gyrotime); - - /* GYROSCOPE */ - if (ret_gyro != sizeof(buf_gyro)) { - gyro_fail_count++; - - if ((((gyro_fail_count % 20) == 0) || (gyro_fail_count > 20 && gyro_fail_count < 100)) && (int)*get_errno_ptr() != EAGAIN) { - fprintf(stderr, "[sensors] L3GD20 ERROR #%d: %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - } - - if (gyro_healthy && gyro_fail_count >= GYRO_HEALTH_COUNTER_LIMIT_ERROR) { - // global_data_send_subsystem_info(&gyro_present_enabled); - gyro_healthy = false; - gyro_success_count = 0; - } - - } else { - gyro_success_count++; - - if (!gyro_healthy && gyro_success_count >= GYRO_HEALTH_COUNTER_LIMIT_OK) { - // global_data_send_subsystem_info(&gyro_present_enabled_healthy); - gyro_healthy = true; - gyro_fail_count = 0; - - } - - gyro_updated = true; - } - - gyrotime = hrt_absolute_time() - start_gyro; - - if (gyrotime > 500) printf("GYRO (complete): %d us\n", gyrotime); - - /* try reading acc */ - uint64_t start_acc = hrt_absolute_time(); - ret_accelerometer = read(fd_accelerometer, buf_accelerometer, sizeof(buf_accelerometer)); - - /* ACCELEROMETER */ - if (ret_accelerometer != sizeof(buf_accelerometer)) { - acc_fail_count++; - - if (acc_fail_count & 0b1000 || (acc_fail_count > 20 && acc_fail_count < 100)) { - fprintf(stderr, "[sensors] BMA180 ERROR #%d: %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - } - - if (acc_healthy && acc_fail_count >= ACC_HEALTH_COUNTER_LIMIT_ERROR) { - // global_data_send_subsystem_info(&acc_present_enabled); - gyro_healthy = false; - acc_success_count = 0; - } - - } else { - acc_success_count++; - - if (!acc_healthy && acc_success_count >= ACC_HEALTH_COUNTER_LIMIT_OK) { - - // global_data_send_subsystem_info(&acc_present_enabled_healthy); - acc_healthy = true; - acc_fail_count = 0; - - } - - acc_updated = true; - } - - int acctime = hrt_absolute_time() - start_acc; - - if (acctime > 500) printf("ACC: %d us\n", acctime); - - /* MAGNETOMETER */ - if (magcounter == 4) { /* 120 Hz */ - uint64_t start_mag = hrt_absolute_time(); - /* start calibration mode if requested */ - if (!mag_calibration_enabled && vstatus.preflight_mag_calibration) { - ioctl(fd_magnetometer, HMC5883L_CALIBRATION_ON, 0); - printf("[sensors] enabling mag calibration mode\n"); - mag_calibration_enabled = true; - } else if (mag_calibration_enabled && !vstatus.preflight_mag_calibration) { - ioctl(fd_magnetometer, HMC5883L_CALIBRATION_OFF, 0); - printf("[sensors] disabling mag calibration mode\n"); - mag_calibration_enabled = false; - } - - ret_magnetometer = read(fd_magnetometer, buf_magnetometer, sizeof(buf_magnetometer)); - int errcode_mag = (int) * get_errno_ptr(); - int magtime = hrt_absolute_time() - start_mag; - - if (magtime > 2000) { - printf("MAG (pure read): %d us\n", magtime); - } - - if (ret_magnetometer != sizeof(buf_magnetometer)) { - mag_fail_count++; - - if (mag_fail_count & 0b1000 || (mag_fail_count > 20 && mag_fail_count < 100)) { - fprintf(stderr, "[sensors] HMC5883L ERROR #%d: %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - } - - if (magn_healthy && mag_fail_count >= MAGN_HEALTH_COUNTER_LIMIT_ERROR) { - // global_data_send_subsystem_info(&magn_present_enabled); - magn_healthy = false; - mag_success_count = 0; - } - - } else { - mag_success_count++; - - if (!magn_healthy && mag_success_count >= MAGN_HEALTH_COUNTER_LIMIT_OK) { - // global_data_send_subsystem_info(&magn_present_enabled_healthy); - magn_healthy = true; - mag_fail_count = 0; - } - - magn_updated = true; - } - - magtime = hrt_absolute_time() - start_mag; - - if (magtime > 2000) { - printf("MAG (overall time): %d us\n", magtime); - fprintf(stderr, "[sensors] TIMEOUT HMC5883L ERROR #%d: %s\n", errcode_mag, strerror(errcode_mag)); - } - - magcounter = 0; - } - - magcounter++; - - /* BAROMETER */ - if (barocounter == 5 && (fd_barometer > 0)) { /* 100 Hz */ - uint64_t start_baro = hrt_absolute_time(); - *get_errno_ptr() = 0; - ret_barometer = read(fd_barometer, buf_barometer, sizeof(buf_barometer)); - - if (ret_barometer != sizeof(buf_barometer)) { - baro_fail_count++; - - if ((baro_fail_count & 0b1000 || (baro_fail_count > 20 && baro_fail_count < 100)) && (int)*get_errno_ptr() != EAGAIN) { - fprintf(stderr, "[sensors] MS5611 ERROR #%d: %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - } - - if (baro_healthy && baro_fail_count >= BARO_HEALTH_COUNTER_LIMIT_ERROR) { - /* switched from healthy to unhealthy */ - baro_healthy = false; - baro_success_count = 0; - // global_data_send_subsystem_info(&baro_present_enabled); - } - - } else { - baro_success_count++; - - if (!baro_healthy && baro_success_count >= MAGN_HEALTH_COUNTER_LIMIT_OK) { - /* switched from unhealthy to healthy */ - baro_healthy = true; - baro_fail_count = 0; - // global_data_send_subsystem_info(&baro_present_enabled_healthy); - } - - baro_updated = true; - } - - barocounter = 0; - int barotime = hrt_absolute_time() - start_baro; - - if (barotime > 2000) printf("BARO: %d us\n", barotime); - } - - barocounter++; - - /* ADC */ - if (adccounter == 5) { - ret_adc = read(fd_adc, &buf_adc, adc_readsize); - nsamples_adc = ret_adc / sizeof(struct adc_msg_s); - - if (ret_adc < 0 || nsamples_adc * sizeof(struct adc_msg_s) != ret_adc) { - adc_fail_count++; - - if ((adc_fail_count & 0b1000 || adc_fail_count < 10) && (int)*get_errno_ptr() != EAGAIN) { - fprintf(stderr, "[sensors] ADC ERROR #%d: %s\n", (int)*get_errno_ptr(), strerror((int)*get_errno_ptr())); - } - - if (adc_healthy && adc_fail_count >= ADC_HEALTH_COUNTER_LIMIT_ERROR) { - adc_healthy = false; - adc_success_count = 0; - } - - } else { - adc_success_count++; - - if (!adc_healthy && adc_success_count >= ADC_HEALTH_COUNTER_LIMIT_OK) { - adc_healthy = true; - adc_fail_count = 0; - } - - adc_updated = true; - } - - adccounter = 0; - - } - - adccounter++; - - - -#ifdef CONFIG_HRT_PPM - bool ppm_updated = false; - - /* PPM */ - if (ppmcounter == 5) { - - /* require at least two channels - * to consider the signal valid - * check that decoded measurement is up to date - */ - if (ppm_decoded_channels > 1 && (hrt_absolute_time() - ppm_last_valid_decode) < 45000) { - /* Read out values from HRT */ - for (int i = 0; i < ppm_decoded_channels; i++) { - rc.chan[i].raw = ppm_buffer[i]; - /* Set the range to +-, then scale up */ - rc.chan[i].scale = (ppm_buffer[i] - rc.chan[i].mid) * rc.chan[i].scaling_factor * 10000; - rc.chan[i].scaled = (ppm_buffer[i] - rc.chan[i].mid) * rc.chan[i].scaling_factor; - } - - rc.chan_count = ppm_decoded_channels; - rc.timestamp = ppm_last_valid_decode; - - /* publish a few lines of code later if set to true */ - ppm_updated = true; - - /* roll input */ - manual_control.roll = rc.chan[rc.function[ROLL]].scaled; - if (manual_control.roll < -1.0f) manual_control.roll = -1.0f; - if (manual_control.roll > 1.0f) manual_control.roll = 1.0f; - - /* pitch input */ - manual_control.pitch = rc.chan[rc.function[PITCH]].scaled; - if (manual_control.pitch < -1.0f) manual_control.pitch = -1.0f; - if (manual_control.pitch > 1.0f) manual_control.pitch = 1.0f; - - /* yaw input */ - manual_control.yaw = rc.chan[rc.function[YAW]].scaled; - if (manual_control.yaw < -1.0f) manual_control.yaw = -1.0f; - if (manual_control.yaw > 1.0f) manual_control.yaw = 1.0f; - - /* throttle input */ - manual_control.throttle = rc.chan[rc.function[THROTTLE]].scaled/2.0f; - if (manual_control.throttle < 0.0f) manual_control.throttle = 0.0f; - if (manual_control.throttle > 1.0f) manual_control.throttle = 1.0f; - - /* mode switch input */ - manual_control.override_mode_switch = rc.chan[rc.function[OVERRIDE]].scaled; - if (manual_control.override_mode_switch < -1.0f) manual_control.override_mode_switch = -1.0f; - if (manual_control.override_mode_switch > 1.0f) manual_control.override_mode_switch = 1.0f; - - } - ppmcounter = 0; - } - - ppmcounter++; -#endif - - /* Copy values of gyro, acc, magnetometer & barometer */ - - /* GYROSCOPE */ - if (gyro_updated) { - /* copy sensor readings to global data and transform coordinates into px4fmu board frame */ - - raw.gyro_raw[0] = ((buf_gyro[1] == -32768) ? -32768 : buf_gyro[1]); // x of the board is y of the sensor - /* assign negated value, except for -SHORT_MAX, as it would wrap there */ - raw.gyro_raw[1] = ((buf_gyro[0] == -32768) ? 32767 : -buf_gyro[0]); // y on the board is -x of the sensor - raw.gyro_raw[2] = ((buf_gyro[2] == -32768) ? -32768 : buf_gyro[2]); // z of the board is z of the sensor - - /* scale measurements */ - // XXX request scaling from driver instead of hardcoding it - /* scaling calculated as: raw * (1/(32768*(500/180*PI))) */ - raw.gyro_rad_s[0] = (raw.gyro_raw[0] - gyro_offset[0]) * 0.000266316109f; - raw.gyro_rad_s[1] = (raw.gyro_raw[1] - gyro_offset[1]) * 0.000266316109f; - raw.gyro_rad_s[2] = (raw.gyro_raw[2] - gyro_offset[2]) * 0.000266316109f; - - raw.gyro_raw_counter++; - } - - /* ACCELEROMETER */ - if (acc_updated) { - /* copy sensor readings to global data and transform coordinates into px4fmu board frame */ - - /* assign negated value, except for -SHORT_MAX, as it would wrap there */ - raw.accelerometer_raw[0] = (buf_accelerometer[1] == -32768) ? 32767 : -buf_accelerometer[1]; // x of the board is -y of the sensor - raw.accelerometer_raw[1] = (buf_accelerometer[0] == -32768) ? -32768 : buf_accelerometer[0]; // y on the board is x of the sensor - raw.accelerometer_raw[2] = (buf_accelerometer[2] == -32768) ? -32768 : buf_accelerometer[2]; // z of the board is z of the sensor - - // XXX read range from sensor - float range_g = 4.0f; - /* scale from 14 bit to m/s2 */ - raw.accelerometer_m_s2[0] = (((raw.accelerometer_raw[0] - acc_offset[0]) / 8192.0f) * range_g) * 9.81f; - raw.accelerometer_m_s2[1] = (((raw.accelerometer_raw[1] - acc_offset[1]) / 8192.0f) * range_g) * 9.81f; - raw.accelerometer_m_s2[2] = (((raw.accelerometer_raw[2] - acc_offset[2]) / 8192.0f) * range_g) * 9.81f; - - raw.accelerometer_raw_counter++; - } - - /* MAGNETOMETER */ - if (magn_updated) { - /* copy sensor readings to global data and transform coordinates into px4fmu board frame */ - - /* assign negated value, except for -SHORT_MAX, as it would wrap there */ - raw.magnetometer_raw[0] = (buf_magnetometer[1] == -32768) ? 32767 : buf_magnetometer[1]; // x of the board is y of the sensor - raw.magnetometer_raw[1] = (buf_magnetometer[0] == -32768) ? 32767 : -buf_magnetometer[0]; // y on the board is -x of the sensor - raw.magnetometer_raw[2] = (buf_magnetometer[2] == -32768) ? -32768 : buf_magnetometer[2]; // z of the board is z of the sensor - - // XXX Read out mag range via I2C on init, assuming 0.88 Ga and 12 bit res here - raw.magnetometer_ga[0] = ((raw.magnetometer_raw[0] - mag_offset[0]) / 4096.0f) * 0.88f; - raw.magnetometer_ga[1] = ((raw.magnetometer_raw[1] - mag_offset[1]) / 4096.0f) * 0.88f; - raw.magnetometer_ga[2] = ((raw.magnetometer_raw[2] - mag_offset[2]) / 4096.0f) * 0.88f; - - /* store mode */ - raw.magnetometer_mode = buf_magnetometer[3]; - - raw.magnetometer_raw_counter++; - } - - /* BAROMETER */ - if (baro_updated) { - /* copy sensor readings to global data and transform coordinates into px4fmu board frame */ - - raw.baro_pres_mbar = buf_barometer[0]; // Pressure in mbar - raw.baro_alt_meter = buf_barometer[1]; // Altitude in meters - raw.baro_temp_celcius = buf_barometer[2]; // Temperature in degrees celcius - - raw.baro_raw_counter++; - } - - /* ADC */ - if (adc_updated) { - /* copy sensor readings to global data*/ - - if (ADC_BATTERY_VOLATGE_CHANNEL == buf_adc.am_channel1) { - /* Voltage in volts */ - raw.battery_voltage_v = (BAT_VOL_LOWPASS_1 * (raw.battery_voltage_v + BAT_VOL_LOWPASS_2 * (buf_adc.am_data1 * battery_voltage_conversion))); - - if ((buf_adc.am_data1 * battery_voltage_conversion) < VOLTAGE_BATTERY_IGNORE_THRESHOLD_VOLTS) { - raw.battery_voltage_valid = false; - raw.battery_voltage_v = 0.f; - - } else { - raw.battery_voltage_valid = true; - } - - raw.battery_voltage_counter++; - } - } - - uint64_t total_time = hrt_absolute_time() - current_time; - - /* Inform other processes that new data is available to copy */ - if ((gyro_updated || acc_updated || magn_updated || baro_updated) && publishing) { - /* Values changed, publish */ - orb_publish(ORB_ID(sensor_combined), sensor_pub, &raw); - } - -#ifdef CONFIG_HRT_PPM - - if (ppm_updated) { - orb_publish(ORB_ID(rc_channels), rc_pub, &rc); - orb_publish(ORB_ID(manual_control_setpoint), manual_control_pub, &manual_control); - } - -#endif - - if (total_time > 2600) { - excessive_readout_time_counter++; - } - - if (total_time > 2600 && excessive_readout_time_counter > 100 && excessive_readout_time_counter % 100 == 0) { - fprintf(stderr, "[sensors] slow update (>2600 us): %d us (#%d)\n", (int)total_time, excessive_readout_time_counter); - - } else if (total_time > 6000) { - if (excessive_readout_time_counter < 100 || excessive_readout_time_counter % 100 == 0) fprintf(stderr, "[sensors] WARNING: Slow update (>6000 us): %d us (#%d)\n", (int)total_time, excessive_readout_time_counter); - } - - - read_loop_counter++; -#ifdef CONFIG_SENSORS_DEBUG_ENABLED - - if (read_loop_counter % 1000 == 0) printf("[sensors] read loop counter: %d\n", read_loop_counter); - - fflush(stdout); - - if (sensors_timer_loop_counter % 1000 == 0) printf("[sensors] timer/trigger loop counter: %d\n", sensors_timer_loop_counter); - -#endif - } - - if (thread_should_exit) break; - } - - /* Never really getting here */ - printf("[sensors] sensor readout stopped\n"); - - close(fd_gyro); - close(fd_accelerometer); - close(fd_magnetometer); - close(fd_barometer); - close(fd_adc); - - printf("[sensors] exiting.\n"); - - thread_running = false; - - return ret; -} - -static void -usage(const char *reason) -{ - if (reason) - fprintf(stderr, "%s\n", reason); - fprintf(stderr, "usage: sensors {start|stop|status}\n"); - exit(1); -} - -int sensors_main(int argc, char *argv[]) -{ - if (argc < 1) - usage("missing command"); - - if (!strcmp(argv[1], "start")) { - - if (thread_running) { - printf("sensors app already running\n"); - } else { - thread_should_exit = false; - sensors_task = task_create("sensors", SCHED_PRIORITY_MAX - 5, 4096, sensors_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); - } - exit(0); - } - - if (!strcmp(argv[1], "stop")) { - if (!thread_running) { - printf("sensors app not started\n"); - } else { - printf("stopping sensors app"); - thread_should_exit = true; - } - exit(0); - } - - if (!strcmp(argv[1], "status")) { - if (thread_running) { - printf("\tsensors app is running\n"); - } else { - printf("\tsensors app not started\n"); - } - exit(0); - } - - usage("unrecognized command"); - exit(1); -} - diff --git a/apps/sensors/sensors.cpp b/apps/sensors/sensors.cpp new file mode 100644 index 0000000000..bd1b7b37da --- /dev/null +++ b/apps/sensors/sensors.cpp @@ -0,0 +1,1228 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file sensors.cpp + * + * Sensor readout process. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define GYRO_HEALTH_COUNTER_LIMIT_ERROR 20 /* 40 ms downtime at 500 Hz update rate */ +#define ACC_HEALTH_COUNTER_LIMIT_ERROR 20 /* 40 ms downtime at 500 Hz update rate */ +#define MAGN_HEALTH_COUNTER_LIMIT_ERROR 100 /* 1000 ms downtime at 100 Hz update rate */ +#define BARO_HEALTH_COUNTER_LIMIT_ERROR 50 /* 500 ms downtime at 100 Hz update rate */ +#define ADC_HEALTH_COUNTER_LIMIT_ERROR 10 /* 100 ms downtime at 100 Hz update rate */ + +#define GYRO_HEALTH_COUNTER_LIMIT_OK 5 +#define ACC_HEALTH_COUNTER_LIMIT_OK 5 +#define MAGN_HEALTH_COUNTER_LIMIT_OK 5 +#define BARO_HEALTH_COUNTER_LIMIT_OK 5 +#define ADC_HEALTH_COUNTER_LIMIT_OK 5 + +#define ADC_BATTERY_VOLATGE_CHANNEL 10 + +#define BAT_VOL_INITIAL 12.f +#define BAT_VOL_LOWPASS_1 0.99f +#define BAT_VOL_LOWPASS_2 0.01f +#define VOLTAGE_BATTERY_IGNORE_THRESHOLD_VOLTS 3.5f + +#ifdef CONFIG_HRT_PPM +extern "C" { + extern uint16_t ppm_buffer[]; + extern unsigned ppm_decoded_channels; + extern uint64_t ppm_last_valid_decode; +} + +/* PPM Settings */ +# define PPM_MIN 1000 +# define PPM_MAX 2000 +/* Internal resolution is 10000 */ +# define PPM_SCALE 10000/((PPM_MAX-PPM_MIN)/2) +# define PPM_MID (PPM_MIN+PPM_MAX)/2 +#endif + +/** + * Sensor app start / stop handling function + * + * @ingroup apps + */ +extern "C" __EXPORT int sensors_main(int argc, char *argv[]); + +class Sensors +{ +public: + /** + * Constructor + */ + Sensors(); + + /** + * Destructor, also kills the sensors task. + */ + ~Sensors(); + + /** + * Start the sensors task. + * + * @return OK on success. + */ + int start(); + +private: + static const unsigned _rc_max_chan_count = 8; /**< maximum number of r/c channels we handle */ + + /* legacy sensor descriptors */ + int _fd_bma180; /**< old accel driver */ + int _fd_gyro_l3gd20; /**< old gyro driver */ + +#if CONFIG_HRT_PPM + hrt_abstime _ppm_last_valid; /**< last time we got a valid ppm signal */ + + /** + * Gather and publish PPM input data. + */ + void ppm_poll(); +#endif + + /* XXX should not be here - should be own driver */ + int _fd_adc; /**< ADC driver handle */ + hrt_abstime _last_adc; /**< last time we took input from the ADC */ + + bool _task_should_exit; /**< if true, sensor task should exit */ + int _sensors_task; /**< task handle for sensor task */ + + bool _hil_enabled; /**< if true, HIL is active */ + bool _publishing; /**< if true, we are publishing sensor data */ + + int _gyro_sub; /**< raw gyro data subscription */ + int _accel_sub; /**< raw accel data subscription */ + int _mag_sub; /**< raw mag data subscription */ + int _baro_sub; /**< raw baro data subscription */ + int _vstatus_sub; /**< vehicle status subscription */ + int _params_sub; /**< notification of parameter updates */ + + orb_advert_t _sensor_pub; /**< combined sensor data topic */ + orb_advert_t _manual_control_pub; /**< manual control signal topic */ + orb_advert_t _rc_pub; /**< raw r/c control topic */ + + perf_counter_t _loop_perf; /**< loop performance counter */ + + struct rc_channels_s _rc; /**< r/c channel data */ + + struct { + float min[_rc_max_chan_count]; + float trim[_rc_max_chan_count]; + float max[_rc_max_chan_count]; + float rev[_rc_max_chan_count]; + float dz[_rc_max_chan_count]; + float ex[_rc_max_chan_count]; + + float gyro_offset[3]; + float mag_offset[3]; + float accel_offset[3]; + float accel_scale[3]; + + int rc_type; + + int rc_map_roll; + int rc_map_pitch; + int rc_map_yaw; + int rc_map_throttle; + int rc_map_mode_sw; + + float rc_scale_roll; + float rc_scale_pitch; + float rc_scale_yaw; + + float battery_voltage_scaling; + } _parameters; /**< local copies of interesting parameters */ + + struct { + param_t min[_rc_max_chan_count]; + param_t trim[_rc_max_chan_count]; + param_t max[_rc_max_chan_count]; + param_t rev[_rc_max_chan_count]; + param_t dz[_rc_max_chan_count]; + param_t ex[_rc_max_chan_count]; + param_t rc_type; + + param_t gyro_offset[3]; + param_t accel_offset[3]; + param_t accel_scale[3]; + param_t mag_offset[3]; + + param_t rc_map_roll; + param_t rc_map_pitch; + param_t rc_map_yaw; + param_t rc_map_throttle; + param_t rc_map_mode_sw; + + param_t rc_scale_roll; + param_t rc_scale_pitch; + param_t rc_scale_yaw; + + param_t battery_voltage_scaling; + } _parameter_handles; /**< handles for interesting parameters */ + + + /** + * Update our local parameter cache. + */ + int parameters_update(); + + /** + * Do accel-related initialisation. + */ + void accel_init(); + + /** + * Do gyro-related initialisation. + */ + void gyro_init(); + + /** + * Do mag-related initialisation. + */ + void mag_init(); + + /** + * Do baro-related initialisation. + */ + void baro_init(); + + /** + * Do adc-related initialisation. + */ + void adc_init(); + + /** + * Poll the accelerometer for updated data. + * + * @param raw Combined sensor data structure into which + * data should be returned. + */ + void accel_poll(struct sensor_combined_s &raw); + + /** + * Poll the gyro for updated data. + * + * @param raw Combined sensor data structure into which + * data should be returned. + */ + void gyro_poll(struct sensor_combined_s &raw); + + /** + * Poll the magnetometer for updated data. + * + * @param raw Combined sensor data structure into which + * data should be returned. + */ + void mag_poll(struct sensor_combined_s &raw); + + /** + * Poll the barometer for updated data. + * + * @param raw Combined sensor data structure into which + * data should be returned. + */ + void baro_poll(struct sensor_combined_s &raw); + + /** + * Check for changes in vehicle status. + */ + void vehicle_status_poll(); + + /** + * Check for changes in parameters. + */ + void parameter_update_poll(bool forced = false); + + /** + * Poll the ADC and update readings to suit. + * + * @param raw Combined sensor data structure into which + * data should be returned. + */ + void adc_poll(struct sensor_combined_s &raw); + + /** + * Shim for calling task_main from task_create. + */ + static void task_main_trampoline(int argc, char *argv[]); + + /** + * Main sensor collection task. + */ + void task_main() __attribute__((noreturn)); +}; + +namespace sensors +{ + +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +static const int ERROR = -1; + +Sensors *g_sensors; +} + +Sensors::Sensors() : + _fd_bma180(-1), + _fd_gyro_l3gd20(-1), + _ppm_last_valid(0), + + _fd_adc(-1), + _last_adc(0), + + _task_should_exit(false), + _sensors_task(-1), + _hil_enabled(false), + _publishing(true), + + /* subscriptions */ + _gyro_sub(-1), + _accel_sub(-1), + _mag_sub(-1), + _baro_sub(-1), + _vstatus_sub(-1), + _params_sub(-1), + + /* publications */ + _sensor_pub(-1), + _manual_control_pub(-1), + _rc_pub(-1), + + /* performance counters */ + _loop_perf(perf_alloc(PC_ELAPSED, "sensor task update")) +{ + + /* basic r/c parameters */ + for (unsigned i = 0; i < _rc_max_chan_count; i++) { + char nbuf[16]; + + /* min values */ + sprintf(nbuf, "RC%d_MIN", i + 1); + _parameter_handles.min[i] = param_find(nbuf); + + /* trim values */ + sprintf(nbuf, "RC%d_TRIM", i + 1); + _parameter_handles.trim[i] = param_find(nbuf); + + /* max values */ + sprintf(nbuf, "RC%d_MAX", i + 1); + _parameter_handles.max[i] = param_find(nbuf); + + /* channel reverse */ + sprintf(nbuf, "RC%d_REV", i + 1); + _parameter_handles.rev[i] = param_find(nbuf); + + /* channel deadzone */ + sprintf(nbuf, "RC%d_DZ", i + 1); + _parameter_handles.dz[i] = param_find(nbuf); + + /* channel exponential gain */ + sprintf(nbuf, "RC%d_EXP", i + 1); + _parameter_handles.ex[i] = param_find(nbuf); + } + + _parameter_handles.rc_type = param_find("RC_TYPE"); + + _parameter_handles.rc_map_roll = param_find("RC_MAP_ROLL"); + _parameter_handles.rc_map_pitch = param_find("RC_MAP_PITCH"); + _parameter_handles.rc_map_yaw = param_find("RC_MAP_YAW"); + _parameter_handles.rc_map_throttle = param_find("RC_MAP_THROTTLE"); + _parameter_handles.rc_map_mode_sw = param_find("RC_MAP_MODE_SW"); + + _parameter_handles.rc_scale_roll = param_find("RC_SCALE_ROLL"); + _parameter_handles.rc_scale_pitch = param_find("RC_SCALE_PITCH"); + _parameter_handles.rc_scale_yaw = param_find("RC_SCALE_YAW"); + + /* gyro offsets */ + _parameter_handles.gyro_offset[0] = param_find("SENS_GYRO_XOFF"); + _parameter_handles.gyro_offset[1] = param_find("SENS_GYRO_YOFF"); + _parameter_handles.gyro_offset[2] = param_find("SENS_GYRO_ZOFF"); + + /* accel offsets */ + _parameter_handles.accel_offset[0] = param_find("SENS_ACC_XOFF"); + _parameter_handles.accel_offset[1] = param_find("SENS_ACC_YOFF"); + _parameter_handles.accel_offset[2] = param_find("SENS_ACC_ZOFF"); + _parameter_handles.accel_scale[0] = param_find("SENS_ACC_XSCALE"); + _parameter_handles.accel_scale[1] = param_find("SENS_ACC_YSCALE"); + _parameter_handles.accel_scale[2] = param_find("SENS_ACC_ZSCALE"); + + /* mag offsets */ + _parameter_handles.mag_offset[0] = param_find("SENS_MAG_XOFF"); + _parameter_handles.mag_offset[1] = param_find("SENS_MAG_YOFF"); + _parameter_handles.mag_offset[2] = param_find("SENS_MAG_ZOFF"); + + _parameter_handles.battery_voltage_scaling = param_find("BAT_V_SCALING"); + + /* fetch initial parameter values */ + parameters_update(); +} + +Sensors::~Sensors() +{ + if (_sensors_task != -1) { + + /* task wakes up every 100ms or so at the longest */ + _task_should_exit = true; + + /* wait for a second for the task to quit at our request */ + unsigned i = 0; + do { + /* wait 20ms */ + usleep(20000); + + /* if we have given up, kill it */ + if (++i > 50) { + task_delete(_sensors_task); + break; + } + } while (_sensors_task != -1); + } + + sensors::g_sensors = nullptr; +} + +int +Sensors::parameters_update() +{ + const unsigned int nchans = 8; + + /* rc values */ + for (unsigned int i = 0; i < nchans; i++) { + + if (param_get(_parameter_handles.min[i], &(_parameters.min[i])) != OK) { + warnx("Failed getting min for chan %d", i); + } + if (param_get(_parameter_handles.trim[i], &(_parameters.trim[i])) != OK) { + warnx("Failed getting trim for chan %d", i); + } + if (param_get(_parameter_handles.max[i], &(_parameters.max[i])) != OK) { + warnx("Failed getting max for chan %d", i); + } + if (param_get(_parameter_handles.rev[i], &(_parameters.rev[i])) != OK) { + warnx("Failed getting rev for chan %d", i); + } + if (param_get(_parameter_handles.dz[i], &(_parameters.dz[i])) != OK) { + warnx("Failed getting dead zone for chan %d", i); + } + if (param_get(_parameter_handles.ex[i], &(_parameters.ex[i])) != OK) { + warnx("Failed getting exponential gain for chan %d", i); + } + + _rc.chan[i].scaling_factor = (1.0f / ((_parameters.max[i] - _parameters.min[i]) / 2.0f) * _parameters.rev[i]); + + /* handle blowup in the scaling factor calculation */ + if (isnan(_rc.chan[i].scaling_factor) || isinf(_rc.chan[i].scaling_factor)) { + _rc.chan[i].scaling_factor = 0; + } + + _rc.chan[i].mid = _parameters.trim[i]; + } + + /* update RC function mappings */ + _rc.function[0] = _parameters.rc_map_throttle - 1; + _rc.function[1] = _parameters.rc_map_roll - 1; + _rc.function[2] = _parameters.rc_map_pitch - 1; + _rc.function[3] = _parameters.rc_map_yaw - 1; + _rc.function[4] = _parameters.rc_map_mode_sw - 1; + + /* remote control type */ + if (param_get(_parameter_handles.rc_type, &(_parameters.rc_type)) != OK) { + warnx("Failed getting remote control type"); + } + + /* channel mapping */ + if (param_get(_parameter_handles.rc_map_roll, &(_parameters.rc_map_roll)) != OK) { + warnx("Failed getting roll chan index"); + } + if (param_get(_parameter_handles.rc_map_pitch, &(_parameters.rc_map_pitch)) != OK) { + warnx("Failed getting pitch chan index"); + } + if (param_get(_parameter_handles.rc_map_yaw, &(_parameters.rc_map_yaw)) != OK) { + warnx("Failed getting yaw chan index"); + } + if (param_get(_parameter_handles.rc_map_throttle, &(_parameters.rc_map_throttle)) != OK) { + warnx("Failed getting throttle chan index"); + } + if (param_get(_parameter_handles.rc_map_mode_sw, &(_parameters.rc_map_mode_sw)) != OK) { + warnx("Failed getting mode sw chan index"); + } + + if (param_get(_parameter_handles.rc_scale_roll, &(_parameters.rc_scale_roll)) != OK) { + warnx("Failed getting rc scaling for roll"); + } + if (param_get(_parameter_handles.rc_scale_pitch, &(_parameters.rc_scale_pitch)) != OK) { + warnx("Failed getting rc scaling for pitch"); + } + if (param_get(_parameter_handles.rc_scale_yaw, &(_parameters.rc_scale_yaw)) != OK) { + warnx("Failed getting rc scaling for yaw"); + } + + /* gyro offsets */ + param_get(_parameter_handles.gyro_offset[0], &(_parameters.gyro_offset[0])); + param_get(_parameter_handles.gyro_offset[1], &(_parameters.gyro_offset[1])); + param_get(_parameter_handles.gyro_offset[2], &(_parameters.gyro_offset[2])); + + /* accel offsets */ + param_get(_parameter_handles.accel_offset[0], &(_parameters.accel_offset[0])); + param_get(_parameter_handles.accel_offset[1], &(_parameters.accel_offset[1])); + param_get(_parameter_handles.accel_offset[2], &(_parameters.accel_offset[2])); + param_get(_parameter_handles.accel_scale[0], &(_parameters.accel_scale[0])); + param_get(_parameter_handles.accel_scale[1], &(_parameters.accel_scale[1])); + param_get(_parameter_handles.accel_scale[2], &(_parameters.accel_scale[2])); + + /* mag offsets */ + param_get(_parameter_handles.mag_offset[0], &(_parameters.mag_offset[0])); + param_get(_parameter_handles.mag_offset[1], &(_parameters.mag_offset[1])); + param_get(_parameter_handles.mag_offset[2], &(_parameters.mag_offset[2])); + + /* scaling of ADC ticks to battery voltage */ + if (param_get(_parameter_handles.battery_voltage_scaling, &(_parameters.battery_voltage_scaling)) != OK) { + warnx("Failed updating voltage scaling param"); + } + + return OK; +} + +void +Sensors::accel_init() +{ + int fd; + + fd = open(ACCEL_DEVICE_PATH, 0); + if (fd < 0) { + warn("%s", ACCEL_DEVICE_PATH); + + /* fall back to bma180 here (new driver would be better...) */ + _fd_bma180 = open("/dev/bma180", O_RDONLY); + if (_fd_bma180 < 0) { + warn("/dev/bma180"); + errx(1, "FATAL: no accelerometer found"); + } + + /* discard first (junk) reading */ + int16_t junk_buf[3]; + read(_fd_bma180, junk_buf, sizeof(junk_buf)); + + warnx("using BMA180"); + } else { + /* set the accel internal sampling rate up to at leat 500Hz */ + ioctl(fd, ACCELIOCSSAMPLERATE, 500); + + /* set the driver to poll at 500Hz */ + ioctl(fd, SENSORIOCSPOLLRATE, 500); + + warnx("using system accel"); + close(fd); + } +} + +void +Sensors::gyro_init() +{ + int fd; + + fd = open(GYRO_DEVICE_PATH, 0); + if (fd < 0) { + warn("%s", GYRO_DEVICE_PATH); + + /* fall back to bma180 here (new driver would be better...) */ + _fd_gyro_l3gd20 = open("/dev/l3gd20", O_RDONLY); + if (_fd_gyro_l3gd20 < 0) { + warn("/dev/l3gd20"); + errx(1, "FATAL: no gyro found"); + } + + /* discard first (junk) reading */ + int16_t junk_buf[3]; + read(_fd_gyro_l3gd20, junk_buf, sizeof(junk_buf)); + + warn("using L3GD20"); + } else { + /* set the gyro internal sampling rate up to at leat 500Hz */ + ioctl(fd, GYROIOCSSAMPLERATE, 500); + + /* set the driver to poll at 500Hz */ + ioctl(fd, SENSORIOCSPOLLRATE, 500); + + warnx("using system gyro"); + close(fd); + } +} + +void +Sensors::mag_init() +{ + int fd; + + fd = open(MAG_DEVICE_PATH, 0); + if (fd < 0) { + warn("%s", MAG_DEVICE_PATH); + errx(1, "FATAL: no magnetometer found"); + } + + /* set the mag internal poll rate to at least 150Hz */ + ioctl(fd, MAGIOCSSAMPLERATE, 150); + + /* set the driver to poll at 150Hz */ + ioctl(fd, SENSORIOCSPOLLRATE, 150); + + close(fd); +} + +void +Sensors::baro_init() +{ + int fd; + + fd = open(BARO_DEVICE_PATH, 0); + if (fd < 0) { + warn("%s", BARO_DEVICE_PATH); + errx(1, "FATAL: no barometer found"); + } + + /* set the driver to poll at 150Hz */ + ioctl(fd, SENSORIOCSPOLLRATE, 150); + + close(fd); +} + +void +Sensors::adc_init() +{ + + _fd_adc = open("/dev/adc0", O_RDONLY | O_NONBLOCK); + if (_fd_adc < 0) { + warn("/dev/adc0"); + errx(1, "FATAL: no ADC found"); + } +} + +void +Sensors::accel_poll(struct sensor_combined_s &raw) +{ + struct accel_report accel_report; + + if (_fd_bma180 >= 0) { + /* do ORB emulation for BMA180 */ + int16_t buf[3]; + + read(_fd_bma180, buf, sizeof(buf)); + + accel_report.timestamp = hrt_absolute_time(); + + accel_report.x_raw = (buf[1] == -32768) ? 32767 : -buf[1]; + accel_report.y_raw = buf[0]; + accel_report.z_raw = buf[2]; + + const float range_g = 4.0f; + /* scale from 14 bit to m/s2 */ + accel_report.x = (((accel_report.x_raw - _parameters.accel_offset[0]) * range_g) / 8192.0f) / 9.81f; + accel_report.y = (((accel_report.y_raw - _parameters.accel_offset[0]) * range_g) / 8192.0f) / 9.81f; + accel_report.z = (((accel_report.z_raw - _parameters.accel_offset[0]) * range_g) / 8192.0f) / 9.81f; + raw.accelerometer_counter++; + + } else { + bool accel_updated; + orb_check(_accel_sub, &accel_updated); + + if (accel_updated) { + orb_copy(ORB_ID(sensor_accel), _accel_sub, &accel_report); + raw.accelerometer_counter++; + } + } + + raw.accelerometer_m_s2[0] = accel_report.x; + raw.accelerometer_m_s2[1] = accel_report.y; + raw.accelerometer_m_s2[2] = accel_report.z; + + raw.accelerometer_raw[0] = accel_report.x_raw; + raw.accelerometer_raw[1] = accel_report.y_raw; + raw.accelerometer_raw[2] = accel_report.z_raw; +} + +void +Sensors::gyro_poll(struct sensor_combined_s &raw) +{ + struct gyro_report gyro_report; + + if (_fd_gyro_l3gd20 >= 0) { + /* do ORB emulation for L3GD20 */ + int16_t buf[3]; + + read(_fd_gyro_l3gd20, buf, sizeof(buf)); + + gyro_report.timestamp = hrt_absolute_time(); + + gyro_report.x_raw = buf[1]; + gyro_report.y_raw = ((buf[0] == -32768) ? 32767 : -buf[0]); + gyro_report.z_raw = buf[2]; + + /* scaling calculated as: raw * (1/(32768*(500/180*PI))) */ + gyro_report.x = (gyro_report.x_raw - _parameters.gyro_offset[0]) * 0.000266316109f; + gyro_report.y = (gyro_report.y_raw - _parameters.gyro_offset[1]) * 0.000266316109f; + gyro_report.z = (gyro_report.z_raw - _parameters.gyro_offset[2]) * 0.000266316109f; + + raw.gyro_rad_s[0] = gyro_report.x; + raw.gyro_rad_s[1] = gyro_report.y; + raw.gyro_rad_s[2] = gyro_report.z; + + raw.gyro_raw[0] = gyro_report.x_raw; + raw.gyro_raw[1] = gyro_report.y_raw; + raw.gyro_raw[2] = gyro_report.z_raw; + + raw.gyro_counter++; + + } else { + + bool gyro_updated; + orb_check(_gyro_sub, &gyro_updated); + + if (gyro_updated) { + orb_copy(ORB_ID(sensor_gyro), _gyro_sub, &gyro_report); + + raw.gyro_rad_s[0] = gyro_report.x; + raw.gyro_rad_s[1] = gyro_report.y; + raw.gyro_rad_s[2] = gyro_report.z; + + raw.gyro_raw[0] = gyro_report.x_raw; + raw.gyro_raw[1] = gyro_report.y_raw; + raw.gyro_raw[2] = gyro_report.z_raw; + + raw.gyro_counter++; + } + } +} + +void +Sensors::mag_poll(struct sensor_combined_s &raw) +{ + bool mag_updated; + orb_check(_mag_sub, &mag_updated); + + if (mag_updated) { + struct mag_report mag_report; + + orb_copy(ORB_ID(sensor_mag), _mag_sub, &mag_report); + + raw.magnetometer_ga[0] = mag_report.x; + raw.magnetometer_ga[1] = mag_report.y; + raw.magnetometer_ga[2] = mag_report.z; + + raw.magnetometer_raw[0] = mag_report.x_raw; + raw.magnetometer_raw[1] = mag_report.y_raw; + raw.magnetometer_raw[2] = mag_report.z_raw; + + raw.magnetometer_counter++; + } +} + +void +Sensors::baro_poll(struct sensor_combined_s &raw) +{ + bool baro_updated; + orb_check(_baro_sub, &baro_updated); + + if (baro_updated) { + struct baro_report baro_report; + + orb_copy(ORB_ID(sensor_baro), _baro_sub, &baro_report); + + raw.baro_pres_mbar = baro_report.pressure; // Pressure in mbar + raw.baro_alt_meter = baro_report.altitude; // Altitude in meters + raw.baro_temp_celcius = baro_report.temperature; // Temperature in degrees celcius + + raw.baro_counter++; + } +} + +void +Sensors::vehicle_status_poll() +{ + struct vehicle_status_s vstatus; + bool vstatus_updated; + + /* Check HIL state if vehicle status has changed */ + orb_check(_vstatus_sub, &vstatus_updated); + if (vstatus_updated) { + + orb_copy(ORB_ID(vehicle_status), _vstatus_sub, &vstatus); + + /* switching from non-HIL to HIL mode */ + //printf("[sensors] Vehicle mode: %i \t AND: %i, HIL: %i\n", vstatus.mode, vstatus.mode & VEHICLE_MODE_FLAG_HIL_ENABLED, hil_enabled); + if (vstatus.flag_hil_enabled && !_hil_enabled) { + _hil_enabled = true; + _publishing = false; + + /* switching from HIL to non-HIL mode */ + + } else if (!_publishing && !_hil_enabled) { + _hil_enabled = false; + _publishing = true; + } + } +} + +void +Sensors::parameter_update_poll(bool forced) +{ + bool param_updated; + + /* Check if any parameter has changed */ + orb_check(_params_sub, ¶m_updated); + + if (param_updated || forced) + { + /* read from param to clear updated flag */ + struct parameter_update_s update; + orb_copy(ORB_ID(parameter_update), _params_sub, &update); + + /* update parameters */ + parameters_update(); + + /* update sensor offsets */ + int fd = open(GYRO_DEVICE_PATH, 0); + struct gyro_scale gscale = { + _parameters.gyro_offset[0], + 1.0f, + _parameters.gyro_offset[1], + 1.0f, + _parameters.gyro_offset[2], + 1.0f, + }; + if (OK != ioctl(fd, GYROIOCSSCALE, (long unsigned int)&gscale)) + warn("WARNING: failed to set scale / offsets for gyro"); + close(fd); + + fd = open(ACCEL_DEVICE_PATH, 0); + struct accel_scale ascale = { + _parameters.accel_offset[0], + _parameters.accel_scale[0], + _parameters.accel_offset[1], + _parameters.accel_scale[1], + _parameters.accel_offset[2], + _parameters.accel_scale[2], + }; + if (OK != ioctl(fd, ACCELIOCSSCALE, (long unsigned int)&ascale)) + warn("WARNING: failed to set scale / offsets for accel"); + close(fd); + + fd = open(MAG_DEVICE_PATH, 0); + struct mag_scale mscale = { + _parameters.mag_offset[0], + 1.0f, + _parameters.mag_offset[1], + 1.0f, + _parameters.mag_offset[2], + 1.0f, + }; + if (OK != ioctl(fd, MAGIOCSSCALE, (long unsigned int)&mscale)) + warn("WARNING: failed to set scale / offsets for mag"); + close(fd); + +#if 0 + printf("CH0: RAW MAX: %d MIN %d S: %d MID: %d FUNC: %d\n", (int)_parameters.max[0], (int)_parameters.min[0], (int)(_rc.chan[0].scaling_factor*10000), (int)(_rc.chan[0].mid), (int)_rc.function[0]); + printf("CH1: RAW MAX: %d MIN %d S: %d MID: %d FUNC: %d\n", (int)_parameters.max[1], (int)_parameters.min[1], (int)(_rc.chan[1].scaling_factor*10000), (int)(_rc.chan[1].mid), (int)_rc.function[1]); + printf("MAN: %d %d\n", (int)(_rc.chan[0].scaled*100), (int)(_rc.chan[1].scaled*100)); + fflush(stdout); + usleep(5000); +#endif + } +} + +void +Sensors::adc_poll(struct sensor_combined_s &raw) +{ + #pragma pack(push,1) + struct adc_msg4_s { + uint8_t am_channel1; /**< The 8-bit ADC Channel 1 */ + int32_t am_data1; /**< ADC convert result 1 (4 bytes) */ + uint8_t am_channel2; /**< The 8-bit ADC Channel 2 */ + int32_t am_data2; /**< ADC convert result 2 (4 bytes) */ + uint8_t am_channel3; /**< The 8-bit ADC Channel 3 */ + int32_t am_data3; /**< ADC convert result 3 (4 bytes) */ + uint8_t am_channel4; /**< The 8-bit ADC Channel 4 */ + int32_t am_data4; /**< ADC convert result 4 (4 bytes) */ + } buf_adc; + #pragma pack(pop) + + if (hrt_absolute_time() - _last_adc >= 10000) { + read(_fd_adc, &buf_adc, sizeof(buf_adc)); + + if (ADC_BATTERY_VOLATGE_CHANNEL == buf_adc.am_channel1) { + /* Voltage in volts */ + raw.battery_voltage_v = (BAT_VOL_LOWPASS_1 * (raw.battery_voltage_v + BAT_VOL_LOWPASS_2 * (buf_adc.am_data1 * _parameters.battery_voltage_scaling))); + + if ((raw.battery_voltage_v) < VOLTAGE_BATTERY_IGNORE_THRESHOLD_VOLTS) { + raw.battery_voltage_valid = false; + raw.battery_voltage_v = 0.f; + + } else { + raw.battery_voltage_valid = true; + } + + raw.battery_voltage_counter++; + } + _last_adc = hrt_absolute_time(); + } +} + +#if CONFIG_HRT_PPM +void +Sensors::ppm_poll() +{ + struct manual_control_setpoint_s manual_control; + + /* check to see whether a new frame has been decoded */ + if (_ppm_last_valid == ppm_last_valid_decode) + return; + /* require at least two chanels to consider the signal valid */ + if (ppm_decoded_channels < 4) + return; + + unsigned channel_limit = ppm_decoded_channels; + if (channel_limit > _rc_max_chan_count) + channel_limit = _rc_max_chan_count; + + /* we are accepting this decode */ + _ppm_last_valid = ppm_last_valid_decode; + + /* Read out values from HRT */ + for (unsigned int i = 0; i < channel_limit; i++) { + _rc.chan[i].raw = ppm_buffer[i]; + /* Set the range to +-, then scale up */ + _rc.chan[i].scale = (ppm_buffer[i] - _rc.chan[i].mid) * _rc.chan[i].scaling_factor * 10000; + + /* scale around the mid point differently for lower and upper range */ + if (ppm_buffer[i] > (_parameters.trim[i] + _parameters.dz[i])) { + _rc.chan[i].scaled = (ppm_buffer[i] - _parameters.trim[i]) / (float)(_parameters.max[i] - _parameters.trim[i]); + } else if (ppm_buffer[i] < (_parameters.trim[i] - _parameters.dz[i])) { + /* division by zero impossible for trim == min (as for throttle), as this falls in the above if clause */ + _rc.chan[i].scaled = -1.0f + ((ppm_buffer[i] - _parameters.min[i]) / (float)(_parameters.trim[i] - _parameters.min[i])); + + } else { + /* in the configured dead zone, output zero */ + _rc.chan[i].scaled = 0.0f; + } + + /* reverse channel if required */ + _rc.chan[i].scaled *= _parameters.rev[i]; + + /* handle any parameter-induced blowups */ + if (isnan(_rc.chan[i].scaled) || isinf(_rc.chan[i].scaled)) + _rc.chan[i].scaled = 0.0f; + + //_rc.chan[i].scaled = (ppm_buffer[i] - _rc.chan[i].mid) * _rc.chan[i].scaling_factor; + } + + _rc.chan_count = ppm_decoded_channels; + _rc.timestamp = ppm_last_valid_decode; + + /* roll input - rolling right is stick-wise and rotation-wise positive */ + manual_control.roll = _rc.chan[_rc.function[ROLL]].scaled; + if (manual_control.roll < -1.0f) manual_control.roll = -1.0f; + if (manual_control.roll > 1.0f) manual_control.roll = 1.0f; + if (!isnan(_parameters.rc_scale_roll) || !isinf(_parameters.rc_scale_roll)) { + manual_control.roll *= _parameters.rc_scale_roll; + } + + /* + * pitch input - stick down is negative, but stick down is pitching up (pos) in NED, + * so reverse sign. + */ + manual_control.pitch = -1.0f * _rc.chan[_rc.function[PITCH]].scaled; + if (manual_control.pitch < -1.0f) manual_control.pitch = -1.0f; + if (manual_control.pitch > 1.0f) manual_control.pitch = 1.0f; + if (!isnan(_parameters.rc_scale_pitch) || !isinf(_parameters.rc_scale_pitch)) { + manual_control.pitch *= _parameters.rc_scale_pitch; + } + + /* yaw input - stick right is positive and positive rotation */ + manual_control.yaw = _rc.chan[_rc.function[YAW]].scaled * _parameters.rc_scale_yaw; + if (manual_control.yaw < -1.0f) manual_control.yaw = -1.0f; + if (manual_control.yaw > 1.0f) manual_control.yaw = 1.0f; + if (!isnan(_parameters.rc_scale_yaw) || !isinf(_parameters.rc_scale_yaw)) { + manual_control.yaw *= _parameters.rc_scale_yaw; + } + + /* throttle input */ + manual_control.throttle = _rc.chan[_rc.function[THROTTLE]].scaled; + if (manual_control.throttle < 0.0f) manual_control.throttle = 0.0f; + if (manual_control.throttle > 1.0f) manual_control.throttle = 1.0f; + + /* mode switch input */ + manual_control.override_mode_switch = _rc.chan[_rc.function[OVERRIDE]].scaled; + if (manual_control.override_mode_switch < -1.0f) manual_control.override_mode_switch = -1.0f; + if (manual_control.override_mode_switch > 1.0f) manual_control.override_mode_switch = 1.0f; + + orb_publish(ORB_ID(rc_channels), _rc_pub, &_rc); + orb_publish(ORB_ID(manual_control_setpoint), _manual_control_pub, &manual_control); +} +#endif + +void +Sensors::task_main_trampoline(int argc, char *argv[]) +{ + sensors::g_sensors->task_main(); +} + +void +Sensors::task_main() +{ + + /* inform about start */ + printf("[sensors] Initializing..\n"); + fflush(stdout); + + /* start individual sensors */ + accel_init(); + gyro_init(); + mag_init(); + baro_init(); + adc_init(); + + /* + * do subscriptions + */ + _gyro_sub = orb_subscribe(ORB_ID(sensor_gyro)); + _accel_sub = orb_subscribe(ORB_ID(sensor_accel)); + _mag_sub = orb_subscribe(ORB_ID(sensor_mag)); + _baro_sub = orb_subscribe(ORB_ID(sensor_baro)); + _vstatus_sub = orb_subscribe(ORB_ID(vehicle_status)); + _params_sub = orb_subscribe(ORB_ID(parameter_update)); + + /* rate limit vehicle status updates to 5Hz */ + orb_set_interval(_vstatus_sub, 200); + + /* + * do advertisements + */ + struct sensor_combined_s raw; + raw.timestamp = hrt_absolute_time(); + raw.battery_voltage_v = BAT_VOL_INITIAL; + raw.adc_voltage_v[0] = 0.9f; + raw.adc_voltage_v[1] = 0.0f; + raw.adc_voltage_v[2] = 0.0f; + raw.battery_voltage_counter = 0; + raw.battery_voltage_valid = false; + + /* get a set of initial values */ + accel_poll(raw); + gyro_poll(raw); + mag_poll(raw); + baro_poll(raw); + + parameter_update_poll(true /* forced */); + + /* advertise the sensor_combined topic and make the initial publication */ + _sensor_pub = orb_advertise(ORB_ID(sensor_combined), &raw); + + /* advertise the manual_control topic */ + { + struct manual_control_setpoint_s manual_control; + manual_control.mode = ROLLPOS_PITCHPOS_YAWRATE_THROTTLE; + manual_control.roll = 0.0f; + manual_control.pitch = 0.0f; + manual_control.yaw = 0.0f; + manual_control.throttle = 0.0f; + + _manual_control_pub = orb_advertise(ORB_ID(manual_control_setpoint), &manual_control); + } + + /* advertise the rc topic */ + { + struct rc_channels_s rc; + memset(&rc, 0, sizeof(rc)); + _rc_pub = orb_advertise(ORB_ID(rc_channels), &rc); + } + + /* wakeup source(s) */ + struct pollfd fds[1]; + + /* use the gyro to pace output - XXX BROKEN if we are using the L3GD20 */ + fds[0].fd = _gyro_sub; + fds[0].events = POLLIN; + + while (!_task_should_exit) { + + /* wait for up to 500ms for data */ + int pret = poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 100); + + /* timed out - periodic check for _task_should_exit, etc. */ + if (pret == 0) + continue; + + /* this is undesirable but not much we can do - might want to flag unhappy status */ + if (pret < 0) { + warn("poll error %d, %d", pret, errno); + continue; + } + + perf_begin(_loop_perf); + + /* check vehicle status for changes to publication state */ + vehicle_status_poll(); + + /* check parameters for updates */ + parameter_update_poll(); + + /* store the time closest to all measurements (this is bogus, sensor timestamps should be propagated...) */ + raw.timestamp = hrt_absolute_time(); + + /* copy most recent sensor data */ + gyro_poll(raw); + accel_poll(raw); + mag_poll(raw); + baro_poll(raw); + + /* check battery voltage */ + adc_poll(raw); + + /* Inform other processes that new data is available to copy */ + if (_publishing) + orb_publish(ORB_ID(sensor_combined), _sensor_pub, &raw); + +#ifdef CONFIG_HRT_PPM + /* Look for new r/c input data */ + ppm_poll(); +#endif + + perf_end(_loop_perf); + } + + printf("[sensors] exiting.\n"); + + _sensors_task = -1; + _exit(0); +} + +int +Sensors::start() +{ + ASSERT(_sensors_task == -1); + + /* start the task */ + _sensors_task = task_create("sensors_task", + SCHED_PRIORITY_MAX - 5, + 6000, /* XXX may be excesssive */ + (main_t)&Sensors::task_main_trampoline, + nullptr); + + if (_sensors_task < 0) { + warn("task start failed"); + return -errno; + } + return OK; +} + +int sensors_main(int argc, char *argv[]) +{ + if (argc < 1) + errx(1, "usage: sensors {start|stop|status}"); + + if (!strcmp(argv[1], "start")) { + + if (sensors::g_sensors != nullptr) + errx(1, "sensors task already running"); + + sensors::g_sensors = new Sensors; + if (sensors::g_sensors == nullptr) + errx(1, "sensors task alloc failed"); + + if (OK != sensors::g_sensors->start()) { + delete sensors::g_sensors; + sensors::g_sensors = nullptr; + err(1, "sensors task start failed"); + } + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + if (sensors::g_sensors == nullptr) + errx(1, "sensors task not running"); + delete sensors::g_sensors; + sensors::g_sensors = nullptr; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (sensors::g_sensors) { + errx(0, "task is running"); + } else { + errx(1, "task is not running"); + } + } + + errx(1, "unrecognized command"); +} + diff --git a/apps/sensors/sensors.h b/apps/sensors/sensors.h deleted file mode 100644 index 87ea19972b..0000000000 --- a/apps/sensors/sensors.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * gps.h - * - * Created on: Mar 8, 2012 - * Author: thomasgubler - */ - -#ifndef SENSORS_H_ -#define SENSORS_H_ -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#endif /* SENSORS_H_ */ diff --git a/apps/system/Make.defs b/apps/system/Make.defs index e72f56ef53..a4aea2d318 100644 --- a/apps/system/Make.defs +++ b/apps/system/Make.defs @@ -34,18 +34,18 @@ # ############################################################################ -ifeq ($(CONFIG_VSN_POWEROFF),y) -CONFIGURED_APPS += vsn/poweroff +ifeq ($(CONFIG_SYSTEM_FREE),y) +CONFIGURED_APPS += system/free endif -ifeq ($(CONFIG_VSN_RAMTRON),y) -CONFIGURED_APPS += vsn/ramtron +ifeq ($(CONFIG_SYSTEM_I2CTOOL),y) +CONFIGURED_APPS += system/i2c endif -ifeq ($(CONFIG_VSN_SDCARD),y) -CONFIGURED_APPS += vsn/sdcard +ifeq ($(CONFIG_SYSTEM_INSTALL),y) +CONFIGURED_APPS += system/install endif -ifeq ($(CONFIG_VSN_SYSINFO),y) -CONFIGURED_APPS += vsn/sysinfo +ifeq ($(CONFIG_SYSTEM_READLINE),y) +CONFIGURED_APPS += system/readline endif diff --git a/apps/system/Makefile b/apps/system/Makefile index a0eb5dfdee..73eb60d152 100644 --- a/apps/system/Makefile +++ b/apps/system/Makefile @@ -68,3 +68,4 @@ distclean: clean @for dir in $(INSTALLED_DIRS) ; do \ $(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ done + diff --git a/apps/system/free/Makefile b/apps/system/free/Makefile index 974c989133..7f911d81cc 100644 --- a/apps/system/free/Makefile +++ b/apps/system/free/Makefile @@ -3,7 +3,7 @@ # # Copyright (C) 2011 Uros Platise. All rights reserved. # Author: Uros Platise -# Gregory Nutt +# Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/system/free/README.txt b/apps/system/free/README.txt index dd92a94ae2..1c2d380d4e 100644 --- a/apps/system/free/README.txt +++ b/apps/system/free/README.txt @@ -2,5 +2,5 @@ This application provides UNIX style memory free information. Source: NuttX - Author: Gregory Nutt + Author: Gregory Nutt Date: 17. March 2011 diff --git a/apps/system/free/free.c b/apps/system/free/free.c index 2f61a1dae3..3d9698ecbe 100644 --- a/apps/system/free/free.c +++ b/apps/system/free/free.c @@ -2,7 +2,7 @@ * apps/system/free/free.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/README.txt b/apps/system/i2c/README.txt old mode 100755 new mode 100644 index 97801bcaaa..7b432533be --- a/apps/system/i2c/README.txt +++ b/apps/system/i2c/README.txt @@ -211,7 +211,7 @@ COMMAND SUMMARY =============== We have already seen the I2C help (or ?) commands above. This section will -discusse the remaining commands. +discuss the remaining commands. List buses: bus [OPTIONS] -------------------------- diff --git a/apps/system/i2c/i2c_bus.c b/apps/system/i2c/i2c_bus.c index 07e6d2da38..a684166ff7 100644 --- a/apps/system/i2c/i2c_bus.c +++ b/apps/system/i2c/i2c_bus.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_bus.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/i2c_common.c b/apps/system/i2c/i2c_common.c index e7b27693ad..4af648c7d5 100644 --- a/apps/system/i2c/i2c_common.c +++ b/apps/system/i2c/i2c_common.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_common.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/i2c_dev.c b/apps/system/i2c/i2c_dev.c index f2b5a0e212..3d0480a15c 100644 --- a/apps/system/i2c/i2c_dev.c +++ b/apps/system/i2c/i2c_dev.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_dev.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/i2c_get.c b/apps/system/i2c/i2c_get.c index 773f2c9637..08510af4b6 100644 --- a/apps/system/i2c/i2c_get.c +++ b/apps/system/i2c/i2c_get.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_get.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/i2c_main.c b/apps/system/i2c/i2c_main.c index 2a0e5d626d..0cf6786cbc 100644 --- a/apps/system/i2c/i2c_main.c +++ b/apps/system/i2c/i2c_main.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_main.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -351,15 +351,7 @@ static void i2c_teardown(FAR struct i2ctool_s *i2ctool) * Name: i2c_main ****************************************************************************/ -#ifdef CONFIG_I2CTOOL_BUILTIN -# define MAIN_NAME i2c_main -# define MAIN_NAME_STRING "i2c_main" -#else -# define MAIN_NAME user_start -# define MAIN_NAME_STRING "user_start" -#endif - -int MAIN_NAME(int argc, char *argv[]) +int i2c_main(int argc, char *argv[]) { /* Verify settings */ diff --git a/apps/system/i2c/i2c_set.c b/apps/system/i2c/i2c_set.c index 66fd8c85a0..5baf7f8354 100644 --- a/apps/system/i2c/i2c_set.c +++ b/apps/system/i2c/i2c_set.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_set.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/i2c_verf.c b/apps/system/i2c/i2c_verf.c index 0fa34b96e1..109e9c4ce6 100644 --- a/apps/system/i2c/i2c_verf.c +++ b/apps/system/i2c/i2c_verf.c @@ -2,7 +2,7 @@ * apps/system/i2c/i2c_verf.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/i2c/i2ctool.h b/apps/system/i2c/i2ctool.h index 9726f0083f..4ff26d03ed 100644 --- a/apps/system/i2c/i2ctool.h +++ b/apps/system/i2c/i2ctool.h @@ -2,7 +2,7 @@ * apps/system/i2c/i2ctool.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/system/install/Makefile b/apps/system/install/Makefile old mode 100755 new mode 100644 index 4528ad44ef..71d82f34ce --- a/apps/system/install/Makefile +++ b/apps/system/install/Makefile @@ -3,7 +3,7 @@ # # Copyright (C) 2011 Uros Platise. All rights reserved. # Author: Uros Platise -# Gregory Nutt +# Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/apps/system/install/README.txt b/apps/system/install/README.txt old mode 100755 new mode 100644 diff --git a/apps/system/install/install.c b/apps/system/install/install.c old mode 100755 new mode 100644 diff --git a/apps/system/readline/Kconfig b/apps/system/readline/Kconfig index 2ed9cafd67..6482b12044 100644 --- a/apps/system/readline/Kconfig +++ b/apps/system/readline/Kconfig @@ -19,21 +19,4 @@ config READLINE_ECHO already has local echo support or you need to suppress the back-channel responses for any other reason. -choice - prompt "Newline Options" - default EOL_IS_EITHER_CRLF - -config EOL_IS_CR - bool "EOL is CR" - -config EOL_IS_LF - bool "EOL is LF" - -config EOL_IS_BOTH_CRLF - bool "EOL is CR and LF" - -config EOL_IS_EITHER_CRLF - bool "EOL is CR or LF" - -endchoice endif diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index bdd39e67be..ec2dc1c0a6 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -63,13 +63,32 @@ #define CONFIG_READLINE_ECHO 1 /* Some environments may return CR as end-of-line, others LF, and others - * both. The logic here assumes either but not both. + * both. If not specified, the logic here assumes either (but not both) as + * the default. */ -#undef CONFIG_EOL_IS_CR -#undef CONFIG_EOL_IS_LF -#undef CONFIG_EOL_IS_BOTH_CRLF -#define CONFIG_EOL_IS_EITHER_CRLF 1 +#if defined(CONFIG_EOL_IS_CR) +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_LF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_BOTH_CRLF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_BOTH_CRLF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_EITHER_CRLF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +#else +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +# define CONFIG_EOL_IS_EITHER_CRLF 1 +#endif /**************************************************************************** * Private Type Declarations diff --git a/apps/systemcmds/bl_update/Makefile b/apps/systemcmds/bl_update/Makefile new file mode 100644 index 0000000000..9d0e156f60 --- /dev/null +++ b/apps/systemcmds/bl_update/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Build the eeprom tool. +# + +APPNAME = bl_update +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 4096 + +include $(APPDIR)/mk/app.mk diff --git a/apps/systemcmds/bl_update/bl_update.c b/apps/systemcmds/bl_update/bl_update.c new file mode 100644 index 0000000000..8bfc292348 --- /dev/null +++ b/apps/systemcmds/bl_update/bl_update.c @@ -0,0 +1,174 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file bl_update.c + * + * STM32F4 bootloader update tool. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "systemlib/systemlib.h" +#include "systemlib/param/param.h" +#include "systemlib/err.h" + +__EXPORT int bl_update_main(int argc, char *argv[]); + +int +bl_update_main(int argc, char *argv[]) +{ + if (argc != 2) + errx(1, "missing firmware filename"); + + int fd = open(argv[1], O_RDONLY); + if (fd < 0) + err(1, "open %s", argv[1]); + + struct stat s; + if (stat(argv[1], &s) < 0) + err(1, "stat %s", argv[1]); + + /* sanity-check file size */ + if (s.st_size > 16384) + errx(1, "%s: file too large", argv[1]); + + uint8_t *buf = malloc(s.st_size); + if (buf == NULL) + errx(1, "failed to allocate %u bytes for firmware buffer", s.st_size); + + if (read(fd, buf, s.st_size) != s.st_size) + err(1, "firmware read error"); + close(fd); + + uint32_t *hdr = (uint32_t *)buf; + if ((hdr[0] < 0x20000000) || /* stack not below RAM */ + (hdr[0] > (0x20000000 + (128 * 1024))) || /* stack not above RAM */ + (hdr[1] < 0x08000000) || /* entrypoint not below flash */ + ((hdr[1] - 0x08000000) > 16384)) { /* entrypoint not outside bootloader */ + free(buf); + errx(1, "not a bootloader image"); + } + + warnx("image validated, erasing bootloader..."); + usleep(10000); + + /* prevent other tasks from running while we do this */ + sched_lock(); + + /* unlock the control register */ + volatile uint32_t *keyr = (volatile uint32_t *)0x40023c04; + *keyr = 0x45670123U; + *keyr = 0xcdef89abU; + + volatile uint32_t *sr = (volatile uint32_t *)0x40023c0c; + volatile uint32_t *cr = (volatile uint32_t *)0x40023c10; + volatile uint8_t *base = (volatile uint8_t *)0x08000000; + + /* check the control register */ + if (*cr & 0x80000000) { + warnx("WARNING: flash unlock failed, flash aborted"); + goto flash_end; + } + + /* erase the bootloader sector */ + *cr = 0x2; + *cr = 0x10002; + + /* wait for the operation to complete */ + while (*sr & 0x1000) { + } + if (*sr & 0xf2) { + warnx("WARNING: erase error 0x%02x", *sr); + goto flash_end; + } + + /* verify the erase */ + for (int i = 0; i < s.st_size; i++) { + if (base[i] != 0xff) { + warnx("WARNING: erase failed at %d - retry update, DO NOT reboot", i); + goto flash_end; + } + } + + warnx("flashing..."); + + /* now program the bootloader - speed is not critical so use x8 mode */ + for (int i = 0; i < s.st_size; i++) { + + /* program a byte */ + *cr = 1; + base[i] = buf[i]; + + /* wait for the operation to complete */ + while (*sr & 0x1000) { + } + if (*sr & 0xf2) { + warnx("WARNING: program error 0x%02x", *sr); + goto flash_end; + } + } + + /* re-lock the flash control register */ + *cr = 0x80000000; + + warnx("verifying..."); + + /* now run a verify pass */ + for (int i = 0; i < s.st_size; i++) { + if (base[i] != buf[i]) { + warnx("WARNING: verify failed at %u - retry update, DO NOT reboot", i); + goto flash_end; + } + } + + warnx("bootloader update complete"); + +flash_end: + /* unlock the scheduler */ + sched_unlock(); + + free(buf); + exit(0); +} diff --git a/apps/systemcmds/boardinfo/boardinfo.c b/apps/systemcmds/boardinfo/boardinfo.c index 0ae0ee8d2b..bce8c27e7c 100644 --- a/apps/systemcmds/boardinfo/boardinfo.c +++ b/apps/systemcmds/boardinfo/boardinfo.c @@ -247,7 +247,7 @@ int boardinfo_main(int argc, char *argv[]) int ret = carrier_get_board_info(&info); if (ret != sizeof(info)) { - fprintf(stderr, "[boardinfo] ERROR loading board info from EEPROM (errno #%d), aborting\n", -ret); + fprintf(stderr, "[boardinfo] no EEPROM for board %d\n", test_boardid); exit(1); } diff --git a/apps/systemcmds/eeprom/24xxxx_mtd.c b/apps/systemcmds/eeprom/24xxxx_mtd.c new file mode 100644 index 0000000000..3cded52fa6 --- /dev/null +++ b/apps/systemcmds/eeprom/24xxxx_mtd.c @@ -0,0 +1,534 @@ +/************************************************************************************ + * Driver for 24xxxx-style I2C EEPROMs. + * + * Adapted from: + * + * drivers/mtd/at24xx.c + * Driver for I2C-based at24cxx EEPROM(at24c32,at24c64,at24c128,at24c256) + * + * Copyright (C) 2011 Li Zhuoyi. All rights reserved. + * Author: Li Zhuoyi + * History: 0.1 2011-08-20 initial version + * + * 2011-11-1 Added support for larger MTD block sizes: Hal Glenn + * + * Derived from drivers/mtd/m25px.c + * + * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "systemlib/perf_counter.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* + * Configuration is as for the AT24 driver, but the CONFIG_MTD_AT24XX define should be + * omitted in order to avoid building the AT24XX driver as well. + */ + +/* As a minimum, the size of the AT24 part and its 7-bit I2C address are required. */ + +#ifndef CONFIG_AT24XX_SIZE +# warning "Assuming AT24 size 64" +# define CONFIG_AT24XX_SIZE 64 +#endif +#ifndef CONFIG_AT24XX_ADDR +# warning "Assuming AT24 address of 0x50" +# define CONFIG_AT24XX_ADDR 0x50 +#endif + +/* Get the part configuration based on the size configuration */ + +#if CONFIG_AT24XX_SIZE == 32 +# define AT24XX_NPAGES 128 +# define AT24XX_PAGESIZE 32 +#elif CONFIG_AT24XX_SIZE == 48 +# define AT24XX_NPAGES 192 +# define AT24XX_PAGESIZE 32 +#elif CONFIG_AT24XX_SIZE == 64 +# define AT24XX_NPAGES 256 +# define AT24XX_PAGESIZE 32 +#elif CONFIG_AT24XX_SIZE == 128 +# define AT24XX_NPAGES 256 +# define AT24XX_PAGESIZE 64 +#elif CONFIG_AT24XX_SIZE == 256 +# define AT24XX_NPAGES 512 +# define AT24XX_PAGESIZE 64 +#endif + +/* For applications where a file system is used on the AT24, the tiny page sizes + * will result in very inefficient FLASH usage. In such cases, it is better if + * blocks are comprised of "clusters" of pages so that the file system block + * size is, say, 256 or 512 bytes. In any event, the block size *must* be an + * even multiple of the pages. + */ + +#ifndef CONFIG_AT24XX_MTD_BLOCKSIZE +# warning "Assuming driver block size is the same as the FLASH page size" +# define CONFIG_AT24XX_MTD_BLOCKSIZE AT24XX_PAGESIZE +#endif + +/* The AT24 does not respond on the bus during write cycles, so we depend on a long + * timeout to detect problems. The max program time is typically ~5ms. + */ +#ifndef CONFIG_AT24XX_WRITE_TIMEOUT_MS +# define CONFIG_AT24XX_WRITE_TIMEOUT_MS 20 +#endif + +/************************************************************************************ + * Private Types + ************************************************************************************/ + +/* This type represents the state of the MTD device. The struct mtd_dev_s + * must appear at the beginning of the definition so that you can freely + * cast between pointers to struct mtd_dev_s and struct at24c_dev_s. + */ + +struct at24c_dev_s +{ + struct mtd_dev_s mtd; /* MTD interface */ + FAR struct i2c_dev_s *dev; /* Saved I2C interface instance */ + uint8_t addr; /* I2C address */ + uint16_t pagesize; /* 32, 63 */ + uint16_t npages; /* 128, 256, 512, 1024 */ + + perf_counter_t perf_reads; + perf_counter_t perf_writes; + perf_counter_t perf_resets; + perf_counter_t perf_read_retries; + perf_counter_t perf_read_errors; + perf_counter_t perf_write_errors; +}; + +/************************************************************************************ + * Private Function Prototypes + ************************************************************************************/ + +/* MTD driver methods */ + +static int at24c_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); +static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf); +static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf); +static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +/* At present, only a single AT24 part is supported. In this case, a statically + * allocated state structure may be used. + */ + +static struct at24c_dev_s g_at24c; + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +static int at24c_eraseall(FAR struct at24c_dev_s *priv) +{ + int startblock = 0; + uint8_t buf[AT24XX_PAGESIZE + 2]; + + struct i2c_msg_s msgv[1] = + { + { + .addr = priv->addr, + .flags = 0, + .buffer = &buf[0], + .length = sizeof(buf), + } + }; + + memset(&buf[2],0xff,priv->pagesize); + + for (startblock = 0; startblock < priv->npages; startblock++) + { + uint16_t offset = startblock * priv->pagesize; + buf[1] = offset & 0xff; + buf[0] = (offset >> 8) & 0xff; + + while (I2C_TRANSFER(priv->dev, &msgv[0], 1) < 0) + { + fvdbg("erase stall\n"); + usleep(10000); + } + } + + return OK; +} + +/************************************************************************************ + * Name: at24c_erase + ************************************************************************************/ + +static int at24c_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) +{ + /* EEprom need not erase */ + + return (int)nblocks; +} + +/************************************************************************************ + * Name: at24c_bread + ************************************************************************************/ + +static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buffer) +{ + FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev; + size_t blocksleft; + uint8_t addr[2]; + int ret; + + struct i2c_msg_s msgv[2] = + { + { + .addr = priv->addr, + .flags = 0, + .buffer = &addr[0], + .length = sizeof(addr), + }, + { + .addr = priv->addr, + .flags = I2C_M_READ, + .buffer = 0, + .length = priv->pagesize, + } + }; + +#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE + startblock *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); + nblocks *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); +#endif + blocksleft = nblocks; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + if (startblock >= priv->npages) + { + return 0; + } + + if (startblock + nblocks > priv->npages) + { + nblocks = priv->npages - startblock; + } + + while (blocksleft-- > 0) + { + uint16_t offset = startblock * priv->pagesize; + unsigned tries = CONFIG_AT24XX_WRITE_TIMEOUT_MS; + + addr[1] = offset & 0xff; + addr[0] = (offset >> 8) & 0xff; + msgv[1].buffer = buffer; + + for (;;) + { + + perf_begin(priv->perf_reads); + ret = I2C_TRANSFER(priv->dev, &msgv[0], 2); + perf_end(priv->perf_reads); + if (ret >= 0) + break; + + fvdbg("read stall"); + usleep(1000); + + /* We should normally only be here on the first read after + * a write. + * + * XXX maybe do special first-read handling with optional + * bus reset as well? + */ + perf_count(priv->perf_read_retries); + if (--tries == 0) + { + perf_count(priv->perf_read_errors); + return ERROR; + } + } + + startblock++; + buffer += priv->pagesize; + } + +#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE + return nblocks / (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); +#else + return nblocks; +#endif +} + +/************************************************************************************ + * Name: at24c_bwrite + * + * Operates on MTD block's and translates to FLASH pages + * + ************************************************************************************/ + +static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR const uint8_t *buffer) +{ + FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev; + size_t blocksleft; + uint8_t buf[AT24XX_PAGESIZE+2]; + int ret; + + struct i2c_msg_s msgv[1] = + { + { + .addr = priv->addr, + .flags = 0, + .buffer = &buf[0], + .length = sizeof(buf), + } + }; + +#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE + startblock *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); + nblocks *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); +#endif + blocksleft = nblocks; + + if (startblock >= priv->npages) + { + return 0; + } + + if (startblock + nblocks > priv->npages) + { + nblocks = priv->npages - startblock; + } + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + while (blocksleft-- > 0) + { + uint16_t offset = startblock * priv->pagesize; + unsigned tries = CONFIG_AT24XX_WRITE_TIMEOUT_MS; + + buf[1] = offset & 0xff; + buf[0] = (offset >> 8) & 0xff; + memcpy(&buf[2], buffer, priv->pagesize); + + for (;;) + { + + perf_begin(priv->perf_writes); + ret = I2C_TRANSFER(priv->dev, &msgv[0], 1); + perf_end(priv->perf_writes); + + if (ret >= 0) + break; + + fvdbg("write stall"); + usleep(1000); + + /* We expect to see a number of retries per write cycle as we + * poll for write completion. + */ + if (--tries == 0) + { + perf_count(priv->perf_write_errors); + return ERROR; + } + } + + startblock++; + buffer += priv->pagesize; + } + +#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE + return nblocks / (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); +#else + return nblocks; +#endif +} + +/************************************************************************************ + * Name: at24c_ioctl + ************************************************************************************/ + +static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +{ + FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev; + int ret = -EINVAL; /* Assume good command with bad parameters */ + + fvdbg("cmd: %d \n", cmd); + + switch (cmd) + { + case MTDIOC_GEOMETRY: + { + FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg); + if (geo) + { + /* Populate the geometry structure with information need to know + * the capacity and how to access the device. + * + * NOTE: that the device is treated as though it where just an array + * of fixed size blocks. That is most likely not true, but the client + * will expect the device logic to do whatever is necessary to make it + * appear so. + * + * blocksize: + * May be user defined. The block size for the at24XX devices may be + * larger than the page size in order to better support file systems. + * The read and write functions translate BLOCKS to pages for the + * small flash devices + * erasesize: + * It has to be at least as big as the blocksize, bigger serves no + * purpose. + * neraseblocks + * Note that the device size is in kilobits and must be scaled by + * 1024 / 8 + */ + +#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE + geo->blocksize = CONFIG_AT24XX_MTD_BLOCKSIZE; + geo->erasesize = CONFIG_AT24XX_MTD_BLOCKSIZE; + geo->neraseblocks = (CONFIG_AT24XX_SIZE * 1024 / 8) / CONFIG_AT24XX_MTD_BLOCKSIZE; +#else + geo->blocksize = priv->pagesize; + geo->erasesize = priv->pagesize; + geo->neraseblocks = priv->npages; +#endif + ret = OK; + + fvdbg("blocksize: %d erasesize: %d neraseblocks: %d\n", + geo->blocksize, geo->erasesize, geo->neraseblocks); + } + } + break; + + case MTDIOC_BULKERASE: + ret=at24c_eraseall(priv); + break; + + case MTDIOC_XIPBASE: + default: + ret = -ENOTTY; /* Bad command */ + break; + } + + return ret; +} + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: at24c_initialize + * + * Description: + * Create an initialize MTD device instance. MTD devices are not registered + * in the file system, but are created as instances that can be bound to + * other functions (such as a block or character driver front end). + * + ************************************************************************************/ + +FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) +{ + FAR struct at24c_dev_s *priv; + + fvdbg("dev: %p\n", dev); + + /* Allocate a state structure (we allocate the structure instead of using + * a fixed, static allocation so that we can handle multiple FLASH devices. + * The current implementation would handle only one FLASH part per I2C + * device (only because of the SPIDEV_FLASH definition) and so would have + * to be extended to handle multiple FLASH parts on the same I2C bus. + */ + + priv = &g_at24c; + if (priv) + { + /* Initialize the allocated structure */ + + priv->addr = CONFIG_AT24XX_ADDR; + priv->pagesize = AT24XX_PAGESIZE; + priv->npages = AT24XX_NPAGES; + + priv->mtd.erase = at24c_erase; + priv->mtd.bread = at24c_bread; + priv->mtd.bwrite = at24c_bwrite; + priv->mtd.ioctl = at24c_ioctl; + priv->dev = dev; + + priv->perf_reads = perf_alloc(PC_ELAPSED, "EEPROM read"); + priv->perf_writes = perf_alloc(PC_ELAPSED, "EEPROM write"); + priv->perf_resets = perf_alloc(PC_COUNT, "EEPROM reset"); + priv->perf_read_retries = perf_alloc(PC_COUNT, "EEPROM read retries"); + priv->perf_read_errors = perf_alloc(PC_COUNT, "EEPROM read errors"); + priv->perf_write_errors = perf_alloc(PC_COUNT, "EEPROM write errors"); + } + + /* Return the implementation-specific state structure as the MTD device */ + + fvdbg("Return %p\n", priv); + return (FAR struct mtd_dev_s *)priv; +} + +/* + * XXX: debug hackery + */ +int at24c_nuke(void) +{ + return at24c_eraseall(&g_at24c); +} diff --git a/apps/systemcmds/eeprom/Makefile b/apps/systemcmds/eeprom/Makefile new file mode 100644 index 0000000000..2f3db0fdce --- /dev/null +++ b/apps/systemcmds/eeprom/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Build the eeprom tool. +# + +APPNAME = eeprom +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 4096 + +include $(APPDIR)/mk/app.mk diff --git a/apps/systemcmds/eeprom/eeprom.c b/apps/systemcmds/eeprom/eeprom.c new file mode 100644 index 0000000000..a0b15f77b7 --- /dev/null +++ b/apps/systemcmds/eeprom/eeprom.c @@ -0,0 +1,237 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file eeprom.c + * + * EEPROM service and utility app. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "systemlib/systemlib.h" +#include "systemlib/param/param.h" +#include "systemlib/err.h" + +#ifndef PX4_I2C_BUS_ONBOARD +# error PX4_I2C_BUS_ONBOARD not defined, cannot locate onboard EEPROM +#endif + +__EXPORT int eeprom_main(int argc, char *argv[]); + +static void eeprom_attach(void); +static void eeprom_start(void); +static void eeprom_erase(void); +static void eeprom_ioctl(unsigned operation); +static void eeprom_save(const char *name); +static void eeprom_load(const char *name); + +static bool attached = false; +static bool started = false; +static struct mtd_dev_s *eeprom_mtd; + +int eeprom_main(int argc, char *argv[]) +{ + if (argc >= 2) { + if (!strcmp(argv[1], "start")) + eeprom_start(); + + if (!strcmp(argv[1], "save_param")) + eeprom_save(argv[2]); + + if (!strcmp(argv[1], "load_param")) + eeprom_load(argv[2]); + + if (!strcmp(argv[1], "erase")) + eeprom_erase(); + + if (0) { /* these actually require a file on the filesystem... */ + + if (!strcmp(argv[1], "reformat")) + eeprom_ioctl(FIOC_REFORMAT); + + if (!strcmp(argv[1], "repack")) + eeprom_ioctl(FIOC_OPTIMIZE); + } + } + + errx(1, "expected a command, try 'start'\n\t'save_param /eeprom/parameters'\n\t'load_param /eeprom/parameters'\n\t'erase'\n"); +} + + +static void +eeprom_attach(void) +{ + /* find the right I2C */ + struct i2c_dev_s *i2c = up_i2cinitialize(PX4_I2C_BUS_ONBOARD); + /* this resets the I2C bus, set correct bus speed again */ + I2C_SETFREQUENCY(i2c, 400000); + + if (i2c == NULL) + errx(1, "failed to locate I2C bus"); + + /* start the MTD driver */ + eeprom_mtd = at24c_initialize(i2c); + + if (eeprom_mtd == NULL) + errx(1, "failed to initialize EEPROM driver"); + + attached = true; +} + +static void +eeprom_start(void) +{ + int ret; + + if (started) + errx(1, "EEPROM already mounted"); + + if (!attached) + eeprom_attach(); + + /* start NXFFS */ + ret = nxffs_initialize(eeprom_mtd); + + if (ret < 0) + errx(1, "failed to initialize NXFFS - erase EEPROM to reformat"); + + /* mount the EEPROM */ + ret = mount(NULL, "/eeprom", "nxffs", 0, NULL); + + if (ret < 0) + errx(1, "failed to mount /eeprom - erase EEPROM to reformat"); + + started = true; + warnx("mounted EEPROM at /eeprom"); + exit(0); +} + +extern int at24c_nuke(void); + +static void +eeprom_erase(void) +{ + if (!attached) + eeprom_attach(); + + if (at24c_nuke()) + errx(1, "erase failed"); + errx(0, "erase done, reboot now"); +} + +static void +eeprom_ioctl(unsigned operation) +{ + int fd; + + fd = open("/eeprom/.", 0); + + if (fd < 0) + err(1, "open /eeprom"); + + if (ioctl(fd, operation, 0) < 0) + err(1, "ioctl"); + + exit(0); +} + +static void +eeprom_save(const char *name) +{ + if (!started) + errx(1, "must be started first"); + + if (!name) + err(1, "missing argument for device name, try '/eeprom/parameters'"); + + /* delete the file in case it exists */ + unlink(name); + + /* create the file */ + int fd = open(name, O_WRONLY | O_CREAT | O_EXCL); + + if (fd < 0) + err(1, "opening '%s' failed", name); + + int result = param_export(fd, false); + close(fd); + + if (result < 0) { + unlink(name); + errx(1, "error exporting to '%s'", name); + } + + exit(0); +} + +static void +eeprom_load(const char *name) +{ + if (!started) + errx(1, "must be started first"); + + if (!name) + err(1, "missing argument for device name, try '/eeprom/parameters'"); + + int fd = open(name, O_RDONLY); + + if (fd < 0) + err(1, "open '%s'", name); + + int result = param_load(fd); + close(fd); + + if (result < 0) + errx(1, "error importing from '%s'", name); + + exit(0); +} diff --git a/apps/ardrone_control/Makefile b/apps/systemcmds/led/Makefile similarity index 87% rename from apps/ardrone_control/Makefile rename to apps/systemcmds/led/Makefile index a6d471567b..eb9d8f9097 100644 --- a/apps/ardrone_control/Makefile +++ b/apps/systemcmds/led/Makefile @@ -32,14 +32,11 @@ ############################################################################ # -# Makefile to build uORB +# Makefile to build ardrone interface # -APPNAME = ardrone_control +APPNAME = led PRIORITY = SCHED_PRIORITY_MAX - 15 -STACKSIZE = 4096 - -# explicit list of sources - not everything is built currently -CSRCS = ardrone_control.c ardrone_motor_control.c ardrone_control_helper.c rate_control.c attitude_control.c pid.c +STACKSIZE = 2048 include $(APPDIR)/mk/app.mk diff --git a/apps/systemcmds/led/led.c b/apps/systemcmds/led/led.c new file mode 100644 index 0000000000..a6d73210a6 --- /dev/null +++ b/apps/systemcmds/led/led.c @@ -0,0 +1,198 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file led.c + * Plain, stupid led outputs + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +__EXPORT int led_main(int argc, char *argv[]); + + +static bool thread_should_exit = false; /**< Deamon exit flag */ +static bool thread_running = false; /**< Deamon status flag */ +static int led_task; /**< Handle of deamon task / thread */ +static int leds; + +static int led_init() +{ + leds = open("/dev/led", O_RDONLY | O_NONBLOCK); + + if (leds < 0) { + errx(1, "[led] LED: open fail\n"); + } + + if (ioctl(leds, LED_ON, LED_BLUE) || ioctl(leds, LED_ON, LED_AMBER)) { + errx(1, "[led] LED: ioctl fail\n"); + } + + return 0; +} + +static void led_deinit() +{ + close(leds); +} + +static int led_toggle(int led) +{ + static int last_blue = LED_ON; + static int last_amber = LED_ON; + + if (led == LED_BLUE) last_blue = (last_blue == LED_ON) ? LED_OFF : LED_ON; + + if (led == LED_AMBER) last_amber = (last_amber == LED_ON) ? LED_OFF : LED_ON; + + return ioctl(leds, ((led == LED_BLUE) ? last_blue : last_amber), led); +} + +static int led_on(int led) +{ + return ioctl(leds, LED_ON, led); +} + +static int led_off(int led) +{ + return ioctl(leds, LED_OFF, led); +} + +/** + * Mainloop of led. + */ +int led_thread_main(int argc, char *argv[]); + +/** + * Print the correct usage. + */ +static void usage(const char *reason); + +static void +usage(const char *reason) +{ + if (reason) + fprintf(stderr, "%s\n", reason); + fprintf(stderr, "usage: led {start|stop|status} [-d ]\n\n"); + exit(1); +} + +/** + * The deamon app only briefly exists to start + * the background job. The stack size assigned in the + * Makefile does only apply to this management task. + * + * The actual stack size should be set in the call + * to task_create(). + */ +int led_main(int argc, char *argv[]) +{ + if (argc < 1) + usage("missing command"); + + if (!strcmp(argv[1], "start")) { + + if (thread_running) { + printf("led already running\n"); + /* this is not an error */ + exit(0); + } + + thread_should_exit = false; + led_task = task_create("led", SCHED_PRIORITY_MAX - 15, 4096, led_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); + thread_running = true; + exit(0); + } + + if (!strcmp(argv[1], "stop")) { + thread_should_exit = true; + exit(0); + } + + if (!strcmp(argv[1], "status")) { + if (thread_running) { + printf("\tled is running\n"); + } else { + printf("\tled not started\n"); + } + exit(0); + } + + usage("unrecognized command"); + exit(1); +} + +int led_thread_main(int argc, char *argv[]) +{ + /* welcome user */ + printf("[led] Control started, taking over motors\n"); + + /* open leds */ + led_init(); + + unsigned int rate = 200; + + while (!thread_should_exit) { + /* swell blue led */ + + + /* 200 Hz base loop */ + usleep(1000000 / rate); + } + + /* close leds */ + led_deinit(); + + printf("[led] ending now...\n\n"); + fflush(stdout); + + thread_running = false; + + return OK; +} + diff --git a/apps/systemlib/Makefile b/apps/systemlib/Makefile index 172eef979d..ec6bb3fb32 100644 --- a/apps/systemlib/Makefile +++ b/apps/systemlib/Makefile @@ -37,13 +37,18 @@ CSRCS = err.c \ hx_stream.c \ - perf_counter.c + perf_counter.c \ + param/param.c \ + bson/tinybson.c \ + conversions.c \ + getopt_long.c # # XXX this really should be a CONFIG_* test # ifeq ($(TARGET),px4fmu) -CSRCS += systemlib.c +CSRCS += systemlib.c \ + pid/pid.c endif include $(APPDIR)/mk/app.mk diff --git a/apps/systemlib/bson/tinybson.c b/apps/systemlib/bson/tinybson.c new file mode 100644 index 0000000000..46ced013d4 --- /dev/null +++ b/apps/systemlib/bson/tinybson.c @@ -0,0 +1,316 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file tinybson.c + * + * A simple subset SAX-style BSON parser and generator. + */ + +#include +#include +#include + +#include "tinybson.h" + + +#if 0 +# define debug(fmt, args...) do { warnx("BSON: " fmt, ##args); } while(0) +#else +# define debug(fmt, args...) do { } while(0) +#endif + +#define CODER_CHECK(_c) do { if (_c->fd == -1) return -1; } while(0) +#define CODER_KILL(_c, _reason) do { debug("killed: %s", _reason); _c->fd = -1; return -1; } while(0) + +static int +read_int8(bson_decoder_t decoder, int8_t *b) +{ + return (read(decoder->fd, b, sizeof(*b)) == sizeof(*b)) ? 0 : -1; +} + +static int +read_int32(bson_decoder_t decoder, int32_t *i) +{ + return (read(decoder->fd, i, sizeof(*i)) == sizeof(*i)) ? 0 : -1; +} + +static int +read_double(bson_decoder_t decoder, double *d) +{ + return (read(decoder->fd, d, sizeof(*d)) == sizeof(*d)) ? 0 : -1; +} + +int +bson_decoder_init(bson_decoder_t decoder, int fd, bson_decoder_callback callback, void *private) +{ + int32_t junk; + + decoder->fd = fd; + decoder->callback = callback; + decoder->private = private; + decoder->nesting = 1; + decoder->pending = 0; + decoder->node.type = BSON_UNDEFINED; + + /* read and discard document size */ + if (read_int32(decoder, &junk)) + CODER_KILL(decoder, "failed reading length"); + + /* ready for decoding */ + return 0; +} + +int +bson_decoder_next(bson_decoder_t decoder) +{ + int8_t tbyte; + unsigned nlen; + + CODER_CHECK(decoder); + + /* if the previous node was EOO, pop a nesting level */ + if (decoder->node.type == BSON_EOO) { + if (decoder->nesting > 0) + decoder->nesting--; + + /* if the nesting level is now zero, the top-level document is done */ + if (decoder->nesting == 0) { + CODER_KILL(decoder, "nesting is zero, document is done"); + + /* return end-of-file to the caller */ + return 0; + } + } + + /* if there are unread bytes pending in the stream, discard them */ + while (decoder->pending > 0) { + if (read_int8(decoder, &tbyte)) + CODER_KILL(decoder, "read error discarding pending bytes"); + decoder->pending--; + } + + /* get the type byte */ + if (read_int8(decoder, &tbyte)) + CODER_KILL(decoder, "read error on type byte"); + decoder->node.type = tbyte; + decoder->pending = 0; + + debug("got type byte 0x%02x", decoder->node.type); + + /* EOO is special; it has no name/data following */ + if (decoder->node.type != BSON_EOO) { + + /* get the node name */ + nlen = 0; + for (;;) { + if (nlen >= BSON_MAXNAME) + CODER_KILL(decoder, "node name overflow"); + if (read_int8(decoder, (int8_t *)&decoder->node.name[nlen])) + CODER_KILL(decoder, "read error on node name"); + if (decoder->node.name[nlen] == '\0') + break; + nlen++; + } + + debug("got name '%s'", decoder->node.name); + + switch (decoder->node.type) { + case BSON_INT: + if (read_int32(decoder, &decoder->node.i)) + CODER_KILL(decoder, "read error on BSON_INT"); + break; + case BSON_DOUBLE: + if (read_double(decoder, &decoder->node.d)) + CODER_KILL(decoder, "read error on BSON_DOUBLE"); + break; + case BSON_STRING: + if (read_int32(decoder, &decoder->pending)) + CODER_KILL(decoder, "read error on BSON_STRING length"); + break; + case BSON_BINDATA: + if (read_int32(decoder, &decoder->pending)) + CODER_KILL(decoder, "read error on BSON_BINDATA size"); + if (read_int8(decoder, &tbyte)) + CODER_KILL(decoder, "read error on BSON_BINDATA subtype"); + decoder->node.subtype = tbyte; + break; + + /* XXX currently not supporting other types */ + default: + CODER_KILL(decoder, "unsupported node type"); + } + } + + /* call the callback and pass its results back */ + return decoder->callback(decoder, decoder->private, &decoder->node); +} + +int +bson_decoder_copy_data(bson_decoder_t decoder, void *buf) +{ + int result; + + CODER_CHECK(decoder); + + /* if data already copied, return zero bytes */ + if (decoder->pending == 0) + return 0; + + /* copy bytes per the node size */ + result = read(decoder->fd, buf, decoder->pending); + if (result != decoder->pending) + CODER_KILL(decoder, "read error on copy_data"); + + /* pending count is discharged */ + decoder->pending = 0; + return 0; +} + +size_t +bson_decoder_data_pending(bson_decoder_t decoder) +{ + return decoder->pending; +} + +static int +write_int8(bson_encoder_t encoder, int8_t b) +{ + debug("write_int8 %d", b); + return (write(encoder->fd, &b, sizeof(b)) == sizeof(b)) ? 0 : -1; +} + +static int +write_int32(bson_encoder_t encoder, int32_t i) +{ + debug("write_int32 %d", i); + return (write(encoder->fd, &i, sizeof(i)) == sizeof(i)) ? 0 : -1; +} + +static int +write_double(bson_encoder_t encoder, double d) +{ + debug("write_double"); + return (write(encoder->fd, &d, sizeof(d)) == sizeof(d)) ? 0 : -1; +} + +static int +write_name(bson_encoder_t encoder, const char *name) +{ + size_t len = strlen(name); + + if (len > BSON_MAXNAME) + return -1; + debug("write name '%s' len %d", name, len); + return (write(encoder->fd, name, len + 1) == (int)(len + 1)) ? 0 : -1; +} + +int +bson_encoder_init(bson_encoder_t encoder, int fd) +{ + encoder->fd = fd; + + if (write_int32(encoder, 0)) + CODER_KILL(encoder, "write error on document length"); + + return 0; +} + +int +bson_encoder_fini(bson_encoder_t encoder) +{ + CODER_CHECK(encoder); + + if (write_int8(encoder, BSON_EOO)) + CODER_KILL(encoder, "write error on document terminator"); + + return 0; +} + +int +bson_encoder_append_int(bson_encoder_t encoder, const char *name, int32_t value) +{ + CODER_CHECK(encoder); + + if (write_int8(encoder, BSON_INT) || + write_name(encoder, name) || + write_int32(encoder, value)) + CODER_KILL(encoder, "write error on BSON_INT"); + + return 0; +} + +int +bson_encoder_append_double(bson_encoder_t encoder, const char *name, double value) +{ + CODER_CHECK(encoder); + + if (write_int8(encoder, BSON_DOUBLE) || + write_name(encoder, name) || + write_double(encoder, value)) + CODER_KILL(encoder, "write error on BSON_DOUBLE"); + + + return 0; +} + +int +bson_encoder_append_string(bson_encoder_t encoder, const char *name, const char *string) +{ + size_t len; + + CODER_CHECK(encoder); + + len = strlen(string); + + if (write_int8(encoder, BSON_DOUBLE) || + write_name(encoder, name) || + write_int32(encoder, len) || + write(encoder->fd, name, len + 1) != (int)(len + 1)) + CODER_KILL(encoder, "write error on BSON_STRING"); + return 0; +} + +int +bson_encoder_append_binary(bson_encoder_t encoder, const char *name, bson_binary_subtype_t subtype, size_t size, const void *data) +{ + CODER_CHECK(encoder); + + if (write_int8(encoder, BSON_BINDATA) || + write_name(encoder, name) || + write_int32(encoder, size) || + write_int8(encoder, subtype) || + write(encoder->fd, data, size) != (int)(size)) + CODER_KILL(encoder, "write error on BSON_BINDATA"); + return 0; +} diff --git a/apps/systemlib/bson/tinybson.h b/apps/systemlib/bson/tinybson.h new file mode 100644 index 0000000000..1b9de5cd32 --- /dev/null +++ b/apps/systemlib/bson/tinybson.h @@ -0,0 +1,183 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + + /** + * @file tinybson.h + * + * A simple subset SAX-style BSON parser and generator. See http://bsonspec.org + * + * Some types and defines taken from the standalone BSON parser/generator + * in the Mongo C connector. + */ + +#ifndef _TINYBSON_H +#define _TINYBSON_H + +#include +#include +#include + +/** subset of the BSON node types we might care about */ +typedef enum { + BSON_EOO = 0, + BSON_DOUBLE = 1, + BSON_STRING = 2, + BSON_OBJECT = 3, + BSON_ARRAY = 4, + BSON_BINDATA = 5, + BSON_UNDEFINED = 6, + BSON_BOOL = 8, + BSON_DATE = 9, + BSON_NULL = 10, + BSON_INT = 16, + BSON_TIMESTAMP = 17, + BSON_LONG = 18 +} bson_type_t; + +typedef enum bson_binary_subtype { + BSON_BIN_BINARY = 0, + BSON_BIN_USER = 128 +} bson_binary_subtype_t; + +/** + * Maximum node name length. + */ +#define BSON_MAXNAME 32 + +/** + * Node structure passed to the callback. + */ +typedef struct bson_node_s +{ + char name[BSON_MAXNAME]; + bson_type_t type; + bson_binary_subtype_t subtype; + union { + int32_t i; + double d; + bool b; + }; +} *bson_node_t; + +typedef struct bson_decoder_s *bson_decoder_t; + +/** + * Node callback. + */ +typedef int (* bson_decoder_callback)(bson_decoder_t decoder, void *private, bson_node_t node); + +struct bson_decoder_s +{ + int fd; + bson_decoder_callback callback; + void *private; + unsigned nesting; + struct bson_node_s node; + int32_t pending; +}; + +/** + * Initialise the decoder. + * + * @param decoder Decoder state structure to be initialised. + * @param fd File to read BSON data from. + * @param callback Callback to be invoked by bson_decoder_next + * @param private Callback private data, stored in node. + * @return Zero on success. + */ +__EXPORT int bson_decoder_init(bson_decoder_t decoder, int fd, bson_decoder_callback callback, void *private); + +/** + * Process the next node from the stream and invoke the callback. + * + * @param decoder Decoder state, must have been initialised with bson_decoder_init. + * @return -1 if parsing encountered an error, 0 if the BSON stream has ended, + * otherwise the return value from the callback. + */ +__EXPORT int bson_decoder_next(bson_decoder_t decoder); + +/** + * Copy node data. + * + * @param decoder Decoder state, must have been initialised with bson_decoder_init. + */ +__EXPORT int bson_decoder_copy_data(bson_decoder_t decoder, void *buf); + +/** + * Report copyable data size. + * + * @param decoder Decoder state, must have been initialised with bson_decoder_init. + */ +__EXPORT size_t bson_decoder_data_pending(bson_decoder_t decoder); + +/** + * Encoder state structure. + */ +typedef struct bson_encoder_s +{ + int fd; + +} *bson_encoder_t; + +/** + * Initialze the encoder. + */ +__EXPORT int bson_encoder_init(bson_encoder_t encoder, int fd); + +/** + * Finalise the encoded stream. + */ +__EXPORT int bson_encoder_fini(bson_encoder_t encoder); + +/** + * Append an integer to the encoded stream. + */ +__EXPORT int bson_encoder_append_int(bson_encoder_t encoder, const char *name, int32_t value); + +/** + * Append a double to the encoded stream + */ +__EXPORT int bson_encoder_append_double(bson_encoder_t encoder, const char *name, double value); + +/** + * Append a string to the encoded stream. + */ +__EXPORT int bson_encoder_append_string(bson_encoder_t encoder, const char *name, const char *string); + +/** + * Append a binary blob to the encoded stream. + */ +__EXPORT int bson_encoder_append_binary(bson_encoder_t encoder, const char *name, bson_binary_subtype_t subtype, size_t size, const void *data); + + +#endif diff --git a/apps/ardrone_control/rate_control.h b/apps/systemlib/conversions.c similarity index 77% rename from apps/ardrone_control/rate_control.h rename to apps/systemlib/conversions.c index 61bd7bf38b..99ee41508f 100644 --- a/apps/ardrone_control/rate_control.h +++ b/apps/systemlib/conversions.c @@ -1,8 +1,7 @@ /**************************************************************************** * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012 PX4 Development Team. All rights reserved. * Author: @author Lorenz Meier - * @author Tobias Naegeli * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,16 +33,25 @@ ****************************************************************************/ /** - * @file rate_control.h - * Definition of attitude rate control + * @file conversions.c + * Implementation of commonly used conversions. */ -#ifndef RATE_CONTROL_H_ -#define RATE_CONTROL_H_ -#include -#include -#include +#include +#include -void control_rates(int ardrone_write, struct sensor_combined_s *raw, struct ardrone_motors_setpoint_s *setpoints); +#include "conversions.h" -#endif /* RATE_CONTROL_H_ */ +int16_t +int16_t_from_bytes(uint8_t bytes[]) +{ + union { + uint8_t b[2]; + int16_t w; + } u; + + u.b[1] = bytes[0]; + u.b[0] = bytes[1]; + + return u.w; +} diff --git a/apps/multirotor_position_control/attitude_control.h b/apps/systemlib/conversions.h similarity index 69% rename from apps/multirotor_position_control/attitude_control.h rename to apps/systemlib/conversions.h index a93a511bae..dc383e770f 100644 --- a/apps/multirotor_position_control/attitude_control.h +++ b/apps/systemlib/conversions.h @@ -1,9 +1,7 @@ /**************************************************************************** * * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * + * Author: Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,19 +32,30 @@ * ****************************************************************************/ -/* @file attitude control for quadrotors */ +/** + * @file conversions.h + * Definition of commonly used conversions. + * + * Includes bit / byte / geo representation and unit conversions. + */ -#ifndef ATTITUDE_CONTROL_H_ -#define ATTITUDE_CONTROL_H_ +#ifndef CONVERSIONS_H_ +#define CONVERSIONS_H_ +#include +#include -#include -#include -#include -#include -#include +__BEGIN_DECLS -void control_attitude(float roll, float pitch, float yaw, float thrust, const struct vehicle_attitude_s *att, - const struct vehicle_status_s *status, int ardrone_pub, - struct ardrone_control_s *ar_control); +/** + * Converts a signed 16 bit integer from big endian to little endian. + * + * This function is for commonly used 16 bit big endian sensor data, + * delivered by driver routines as two 8 bit numbers in big endian order. + * Common vendors with big endian representation are Invense, Bosch and + * Honeywell. ST micro devices tend to use a little endian representation. + */ +__EXPORT int16_t int16_t_from_bytes(uint8_t bytes[]); -#endif /* ATTITUDE_CONTROL_H_ */ +__END_DECLS + +#endif /* CONVERSIONS_H_ */ diff --git a/apps/systemlib/err.c b/apps/systemlib/err.c index 9692f03dd9..f22c5ed0db 100644 --- a/apps/systemlib/err.c +++ b/apps/systemlib/err.c @@ -155,7 +155,7 @@ warn(const char *fmt, ...) void vwarn(const char *fmt, va_list args) { - warnerr_core(NOCODE, fmt, args); + warnerr_core(errno, fmt, args); } void diff --git a/apps/systemlib/err.h b/apps/systemlib/err.h index bc390d233d..f798b97e7a 100644 --- a/apps/systemlib/err.h +++ b/apps/systemlib/err.h @@ -36,6 +36,30 @@ * * Simple error/warning functions, heavily inspired by the BSD functions of * the same names. + * + * The err() and warn() family of functions display a formatted error + * message on the standard error output. In all cases, the last + * component of the program name, a colon character, and a space are + * output. If the fmt argument is not NULL, the printf(3)-like formatted + * error message is output. The output is terminated by a newline + * character. + * + * The err(), errc(), verr(), verrc(), warn(), warnc(), vwarn(), and + * vwarnc() functions append an error message obtained from strerror(3) + * based on a supplied error code value or the global variable errno, + * preceded by another colon and space unless the fmt argument is NULL. + * + * In the case of the errc(), verrc(), warnc(), and vwarnc() functions, + * the code argument is used to look up the error message. + * + * The err(), verr(), warn(), and vwarn() functions use the global + * variable errno to look up the error message. + * + * The errx() and warnx() functions do not append an error message. + * + * The err(), verr(), errc(), verrc(), errx(), and verrx() functions do + * not return, but exit with the value of the argument eval. + * */ #ifndef _SYSTEMLIB_ERR_H @@ -47,18 +71,18 @@ __BEGIN_DECLS __EXPORT const char *getprogname(void); -__EXPORT void err(int, const char *, ...) __attribute__((noreturn,format(printf,2, 3))); -__EXPORT void verr(int, const char *, va_list) __attribute__((noreturn,format(printf,2, 0))); -__EXPORT void errc(int, int, const char *, ...) __attribute__((noreturn,format(printf,3, 4))); -__EXPORT void verrc(int, int, const char *, va_list) __attribute__((noreturn,format(printf,3, 0))); -__EXPORT void errx(int, const char *, ...) __attribute__((noreturn,format(printf,2, 3))); -__EXPORT void verrx(int, const char *, va_list) __attribute__((noreturn,format(printf,2, 0))); -__EXPORT void warn(const char *, ...) __attribute__((format(printf,1, 2))); -__EXPORT void vwarn(const char *, va_list) __attribute__((format(printf,1, 0))); -__EXPORT void warnc(int, const char *, ...) __attribute__((format(printf,2, 3))); -__EXPORT void vwarnc(int, const char *, va_list) __attribute__((format(printf,2, 0))); -__EXPORT void warnx(const char *, ...) __attribute__((format(printf,1, 2))); -__EXPORT void vwarnx(const char *, va_list) __attribute__((format(printf,1, 0))); +__EXPORT void err(int eval, const char *fmt, ...) __attribute__((noreturn,format(printf,2, 3))); +__EXPORT void verr(int eval, const char *fmt, va_list) __attribute__((noreturn,format(printf,2, 0))); +__EXPORT void errc(int eval, int code, const char *fmt, ...) __attribute__((noreturn,format(printf,3, 4))); +__EXPORT void verrc(int eval, int code, const char *fmt, va_list) __attribute__((noreturn,format(printf,3, 0))); +__EXPORT void errx(int eval, const char *fmt, ...) __attribute__((noreturn,format(printf,2, 3))); +__EXPORT void verrx(int eval, const char *fmt, va_list) __attribute__((noreturn,format(printf,2, 0))); +__EXPORT void warn(const char *fmt, ...) __attribute__((format(printf,1, 2))); +__EXPORT void vwarn(const char *fmt, va_list) __attribute__((format(printf,1, 0))); +__EXPORT void warnc(int code, const char *fmt, ...) __attribute__((format(printf,2, 3))); +__EXPORT void vwarnc(int code, const char *fmt, va_list) __attribute__((format(printf,2, 0))); +__EXPORT void warnx(const char *fmt, ...) __attribute__((format(printf,1, 2))); +__EXPORT void vwarnx(const char *fmt, va_list) __attribute__((format(printf,1, 0))); __END_DECLS diff --git a/apps/systemlib/getopt_long.c b/apps/systemlib/getopt_long.c new file mode 100644 index 0000000000..27c38635f7 --- /dev/null +++ b/apps/systemlib/getopt_long.c @@ -0,0 +1,404 @@ +/**************************************************************************** + +getopt.c - Read command line options + +AUTHOR: Gregory Pietsch +CREATED Fri Jan 10 21:13:05 1997 + +DESCRIPTION: + +The getopt() function parses the command line arguments. Its arguments argc +and argv are the argument count and array as passed to the main() function +on program invocation. The argument optstring is a list of available option +characters. If such a character is followed by a colon (`:'), the option +takes an argument, which is placed in optarg. If such a character is +followed by two colons, the option takes an optional argument, which is +placed in optarg. If the option does not take an argument, optarg is NULL. + +The external variable optind is the index of the next array element of argv +to be processed; it communicates from one call to the next which element to +process. + +The getopt_long() function works like getopt() except that it also accepts +long options started by two dashes `--'. If these take values, it is either +in the form + +--arg=value + + or + +--arg value + +It takes the additional arguments longopts which is a pointer to the first +element of an array of type GETOPT_LONG_OPTION_T. The last element of the +array has to be filled with NULL for the name field. + +The longind pointer points to the index of the current long option relative +to longopts if it is non-NULL. + +The getopt() function returns the option character if the option was found +successfully, `:' if there was a missing parameter for one of the options, +`?' for an unknown option character, and EOF for the end of the option list. + +The getopt_long() function's return value is described in the header file. + +The function getopt_long_only() is identical to getopt_long(), except that a +plus sign `+' can introduce long options as well as `--'. + +The following describes how to deal with options that follow non-option +argv-elements. + +If the caller did not specify anything, the default is REQUIRE_ORDER if the +environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. + +REQUIRE_ORDER means don't recognize them as options; stop option processing +when the first non-option is seen. This is what Unix does. This mode of +operation is selected by either setting the environment variable +POSIXLY_CORRECT, or using `+' as the first character of the optstring +parameter. + +PERMUTE is the default. We permute the contents of ARGV as we scan, so that +eventually all the non-options are at the end. This allows options to be +given in any order, even with programs that were not written to expect this. + +RETURN_IN_ORDER is an option available to programs that were written to +expect options and other argv-elements in any order and that care about the +ordering of the two. We describe each non-option argv-element as if it were +the argument of an option with character code 1. Using `-' as the first +character of the optstring parameter selects this mode of operation. + +The special argument `--' forces an end of option-scanning regardless of the +value of ordering. In the case of RETURN_IN_ORDER, only `--' can cause +getopt() and friends to return EOF with optind != argc. + +COPYRIGHT NOTICE AND DISCLAIMER: + +Copyright (C) 1997 Gregory Pietsch + +This file and the accompanying getopt.h header file are hereby placed in the +public domain without restrictions. Just give the author credit, don't +claim you wrote it or prevent anyone else from using it. + +Gregory Pietsch's current e-mail address: +gpietsch@comcast.net +****************************************************************************/ + +/* include files */ +#include +#include +#include +#include "getopt_long.h" + +/* macros */ + +/* types */ +typedef enum GETOPT_ORDERING_T +{ + PERMUTE, + RETURN_IN_ORDER, + REQUIRE_ORDER +} GETOPT_ORDERING_T; + +/* globally-defined variables */ +char *optarg = NULL; +int optind = 0; +int opterr = 1; +int optopt = '?'; + +/* functions */ + +/* reverse_argv_elements: reverses num elements starting at argv */ +static void +reverse_argv_elements (char **argv, int num) +{ + int i; + char *tmp; + + for (i = 0; i < (num >> 1); i++) + { + tmp = argv[i]; + argv[i] = argv[num - i - 1]; + argv[num - i - 1] = tmp; + } +} + +/* permute: swap two blocks of argv-elements given their lengths */ +static void +permute (char **argv, int len1, int len2) +{ + reverse_argv_elements (argv, len1); + reverse_argv_elements (argv, len1 + len2); + reverse_argv_elements (argv, len2); +} + +/* is_option: is this argv-element an option or the end of the option list? */ +static int +is_option (char *argv_element, int only) +{ + return ((argv_element == NULL) + || (argv_element[0] == '-') || (only && argv_element[0] == '+')); +} + +/* getopt_internal: the function that does all the dirty work */ +static int +getopt_internal (int argc, char **argv, const char *shortopts, + const GETOPT_LONG_OPTION_T * longopts, int *longind, int only) +{ + GETOPT_ORDERING_T ordering = PERMUTE; + static size_t optwhere = 0; + size_t permute_from = 0; + int num_nonopts = 0; + int optindex = 0; + size_t match_chars = 0; + char *possible_arg = NULL; + int longopt_match = -1; + int has_arg = -1; + char *cp = NULL; + int arg_next = 0; + + /* first, deal with silly parameters and easy stuff */ + if (argc == 0 || argv == NULL || (shortopts == NULL && longopts == NULL) + || optind >= argc || argv[optind] == NULL) + return EOF; + if (strcmp (argv[optind], "--") == 0) + { + optind++; + return EOF; + } + /* if this is our first time through */ + if (optind == 0) + optind = optwhere = 1; + + /* define ordering */ + if (shortopts != NULL && (*shortopts == '-' || *shortopts == '+')) + { + ordering = (*shortopts == '-') ? RETURN_IN_ORDER : REQUIRE_ORDER; + shortopts++; + } + else + ordering = /*(getenv ("POSIXLY_CORRECT") != NULL) ? REQUIRE_ORDER :*/ PERMUTE; + + /* + * based on ordering, find our next option, if we're at the beginning of + * one + */ + if (optwhere == 1) + { + switch (ordering) + { + default: /* shouldn't happen */ + case PERMUTE: + permute_from = optind; + num_nonopts = 0; + while (!is_option (argv[optind], only)) + { + optind++; + num_nonopts++; + } + if (argv[optind] == NULL) + { + /* no more options */ + optind = permute_from; + return EOF; + } + else if (strcmp (argv[optind], "--") == 0) + { + /* no more options, but have to get `--' out of the way */ + permute (argv + permute_from, num_nonopts, 1); + optind = permute_from + 1; + return EOF; + } + break; + case RETURN_IN_ORDER: + if (!is_option (argv[optind], only)) + { + optarg = argv[optind++]; + return (optopt = 1); + } + break; + case REQUIRE_ORDER: + if (!is_option (argv[optind], only)) + return EOF; + break; + } + } + /* we've got an option, so parse it */ + + /* first, is it a long option? */ + if (longopts != NULL + && (memcmp (argv[optind], "--", 2) == 0 + || (only && argv[optind][0] == '+')) && optwhere == 1) + { + /* handle long options */ + if (memcmp (argv[optind], "--", 2) == 0) + optwhere = 2; + longopt_match = -1; + possible_arg = strchr (argv[optind] + optwhere, '='); + if (possible_arg == NULL) + { + /* no =, so next argv might be arg */ + match_chars = strlen (argv[optind]); + possible_arg = argv[optind] + match_chars; + match_chars = match_chars - optwhere; + } + else + match_chars = (possible_arg - argv[optind]) - optwhere; + for (optindex = 0; longopts[optindex].name != NULL; optindex++) + { + if (memcmp (argv[optind] + optwhere, + longopts[optindex].name, match_chars) == 0) + { + /* do we have an exact match? */ + if (match_chars == (unsigned) (strlen (longopts[optindex].name))) + { + longopt_match = optindex; + break; + } + /* do any characters match? */ + else + { + if (longopt_match < 0) + longopt_match = optindex; + else + { + /* we have ambiguous options */ + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous " + "(could be `--%s' or `--%s')\n", + argv[0], + argv[optind], + longopts[longopt_match].name, + longopts[optindex].name); + return (optopt = '?'); + } + } + } + } + if (longopt_match >= 0) + has_arg = longopts[longopt_match].has_arg; + } + /* if we didn't find a long option, is it a short option? */ + if (longopt_match < 0 && shortopts != NULL) + { + cp = strchr (shortopts, argv[optind][optwhere]); + if (cp == NULL) + { + /* couldn't find option in shortopts */ + if (opterr) + fprintf (stderr, + "%s: invalid option -- `-%c'\n", + argv[0], argv[optind][optwhere]); + optwhere++; + if (argv[optind][optwhere] == '\0') + { + optind++; + optwhere = 1; + } + return (optopt = '?'); + } + has_arg = ((cp[1] == ':') + ? ((cp[2] == ':') ? OPTIONAL_ARG : REQUIRED_ARG) : NO_ARG); + possible_arg = argv[optind] + optwhere + 1; + optopt = *cp; + } + /* get argument and reset optwhere */ + arg_next = 0; + switch (has_arg) + { + case OPTIONAL_ARG: + if (*possible_arg == '=') + possible_arg++; + optarg = (*possible_arg != '\0') ? possible_arg : 0; + optwhere = 1; + break; + case REQUIRED_ARG: + if (*possible_arg == '=') + possible_arg++; + if (*possible_arg != '\0') + { + optarg = possible_arg; + optwhere = 1; + } + else if (optind + 1 >= argc) + { + if (opterr) + { + fprintf (stderr, "%s: argument required for option `", argv[0]); + if (longopt_match >= 0) + fprintf (stderr, "--%s'\n", longopts[longopt_match].name); + else + fprintf (stderr, "-%c'\n", *cp); + } + optind++; + return (optopt = ':'); + } + else + { + optarg = argv[optind + 1]; + arg_next = 1; + optwhere = 1; + } + break; + default: /* shouldn't happen */ + case NO_ARG: + if (longopt_match < 0) + { + optwhere++; + if (argv[optind][optwhere] == '\0') + optwhere = 1; + } + else + optwhere = 1; + optarg = NULL; + break; + } + + /* do we have to permute or otherwise modify optind? */ + if (ordering == PERMUTE && optwhere == 1 && num_nonopts != 0) + { + permute (argv + permute_from, num_nonopts, 1 + arg_next); + optind = permute_from + 1 + arg_next; + } + else if (optwhere == 1) + optind = optind + 1 + arg_next; + + /* finally return */ + if (longopt_match >= 0) + { + if (longind != NULL) + *longind = longopt_match; + if (longopts[longopt_match].flag != NULL) + { + *(longopts[longopt_match].flag) = longopts[longopt_match].val; + return 0; + } + else + return longopts[longopt_match].val; + } + else + return optopt; +} + +#if 0 +int +getopt (int argc, char **argv, char *optstring) +{ + return getopt_internal (argc, argv, optstring, NULL, NULL, 0); +} +#endif + +int +getopt_long (int argc, char **argv, const char *shortopts, + const GETOPT_LONG_OPTION_T * longopts, int *longind) +{ + return getopt_internal (argc, argv, shortopts, longopts, longind, 0); +} + +int +getopt_long_only (int argc, char **argv, const char *shortopts, + const GETOPT_LONG_OPTION_T * longopts, int *longind) +{ + return getopt_internal (argc, argv, shortopts, longopts, longind, 1); +} + +/* end of file GETOPT.C */ diff --git a/apps/systemlib/getopt_long.h b/apps/systemlib/getopt_long.h new file mode 100644 index 0000000000..3e51550a60 --- /dev/null +++ b/apps/systemlib/getopt_long.h @@ -0,0 +1,139 @@ +/**************************************************************************** + +getopt.h - Read command line options + +AUTHOR: Gregory Pietsch +CREATED Thu Jan 09 22:37:00 1997 + +DESCRIPTION: + +The getopt() function parses the command line arguments. Its arguments argc +and argv are the argument count and array as passed to the main() function +on program invocation. The argument optstring is a list of available option +characters. If such a character is followed by a colon (`:'), the option +takes an argument, which is placed in optarg. If such a character is +followed by two colons, the option takes an optional argument, which is +placed in optarg. If the option does not take an argument, optarg is NULL. + +The external variable optind is the index of the next array element of argv +to be processed; it communicates from one call to the next which element to +process. + +The getopt_long() function works like getopt() except that it also accepts +long options started by two dashes `--'. If these take values, it is either +in the form + +--arg=value + + or + +--arg value + +It takes the additional arguments longopts which is a pointer to the first +element of an array of type GETOPT_LONG_OPTION_T, defined below. The last +element of the array has to be filled with NULL for the name field. + +The longind pointer points to the index of the current long option relative +to longopts if it is non-NULL. + +The getopt() function returns the option character if the option was found +successfully, `:' if there was a missing parameter for one of the options, +`?' for an unknown option character, and EOF for the end of the option list. + +The getopt_long() function's return value is described below. + +The function getopt_long_only() is identical to getopt_long(), except that a +plus sign `+' can introduce long options as well as `--'. + +Describe how to deal with options that follow non-option ARGV-elements. + +If the caller did not specify anything, the default is REQUIRE_ORDER if the +environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. + +REQUIRE_ORDER means don't recognize them as options; stop option processing +when the first non-option is seen. This is what Unix does. This mode of +operation is selected by either setting the environment variable +POSIXLY_CORRECT, or using `+' as the first character of the optstring +parameter. + +PERMUTE is the default. We permute the contents of ARGV as we scan, so that +eventually all the non-options are at the end. This allows options to be +given in any order, even with programs that were not written to expect this. + +RETURN_IN_ORDER is an option available to programs that were written to +expect options and other ARGV-elements in any order and that care about the +ordering of the two. We describe each non-option ARGV-element as if it were +the argument of an option with character code 1. Using `-' as the first +character of the optstring parameter selects this mode of operation. + +The special argument `--' forces an end of option-scanning regardless of the +value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause +getopt() and friends to return EOF with optind != argc. + +COPYRIGHT NOTICE AND DISCLAIMER: + +Copyright (C) 1997 Gregory Pietsch + +This file and the accompanying getopt.c implementation file are hereby +placed in the public domain without restrictions. Just give the author +credit, don't claim you wrote it or prevent anyone else from using it. + +Gregory Pietsch's current e-mail address: +gpietsch@comcast.net +****************************************************************************/ + +#ifndef GETOPT_H +#define GETOPT_H + +/* include files needed by this include file */ + +/* macros defined by this include file */ +#define NO_ARG 0 +#define REQUIRED_ARG 1 +#define OPTIONAL_ARG 2 + +/* types defined by this include file */ + +/* GETOPT_LONG_OPTION_T: The type of long option */ +typedef struct GETOPT_LONG_OPTION_T +{ + char *name; /* the name of the long option */ + int has_arg; /* one of the above macros */ + int *flag; /* determines if getopt_long() returns a + * value for a long option; if it is + * non-NULL, 0 is returned as a function + * value and the value of val is stored in + * the area pointed to by flag. Otherwise, + * val is returned. */ + int val; /* determines the value to return if flag is + * NULL. */ +} GETOPT_LONG_OPTION_T; + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* externally-defined variables */ + extern char *optarg; + extern int optind; + extern int opterr; + extern int optopt; + + /* function prototypes */ +#if 0 + int getopt (int argc, char **argv, char *optstring); +#endif + int getopt_long (int argc, char **argv, const char *shortopts, + const GETOPT_LONG_OPTION_T * longopts, int *longind); + int getopt_long_only (int argc, char **argv, const char *shortopts, + const GETOPT_LONG_OPTION_T * longopts, int *longind); + +#ifdef __cplusplus +}; + +#endif + +#endif /* GETOPT_H */ + +/* END OF FILE getopt.h */ diff --git a/apps/systemlib/mixer/mixer_group.cpp b/apps/systemlib/mixer/mixer_group.cpp index bc944ccd9b..44a33bf8b2 100644 --- a/apps/systemlib/mixer/mixer_group.cpp +++ b/apps/systemlib/mixer/mixer_group.cpp @@ -217,7 +217,7 @@ mixer_load_multirotor(Mixer::ControlCallback control_cb, uintptr_t cb_handle, co char geomname[8]; int s[4]; - if (sscanf(buf, "R: %7s %d %d %d %d", geomname, &s[0], &s[1], &s[2], &s[3]) != 5) { + if (sscanf(buf, "R: %s %d %d %d %d", geomname, &s[0], &s[1], &s[2], &s[3]) != 5) { debug("multirotor parse failed on '%s'", buf); return nullptr; } diff --git a/apps/systemlib/mixer/mixer_multirotor.cpp b/apps/systemlib/mixer/mixer_multirotor.cpp index 60b71c60a6..e2576a8483 100644 --- a/apps/systemlib/mixer/mixer_multirotor.cpp +++ b/apps/systemlib/mixer/mixer_multirotor.cpp @@ -64,52 +64,52 @@ namespace * These tables automatically generated by multi_tables - do not edit. */ const MultirotorMixer::Rotor _config_quad_x[] = { - { -0.707107, 0.707107, 1.00 }, - { 0.707107, -0.707107, 1.00 }, - { 0.707107, 0.707107, -1.00 }, - { -0.707107, -0.707107, -1.00 }, + { -0.707107, 0.707107, -1.00 }, + { 0.707107, -0.707107, -1.00 }, + { 0.707107, 0.707107, 1.00 }, + { -0.707107, -0.707107, 1.00 }, }; const MultirotorMixer::Rotor _config_quad_plus[] = { - { -1.000000, 0.000000, 1.00 }, - { 1.000000, 0.000000, 1.00 }, - { 0.000000, 1.000000, -1.00 }, - { -0.000000, -1.000000, -1.00 }, + { -1.000000, 0.000000, -1.00 }, + { 1.000000, 0.000000, -1.00 }, + { 0.000000, 1.000000, 1.00 }, + { -0.000000, -1.000000, 1.00 }, }; const MultirotorMixer::Rotor _config_hex_x[] = { - { -1.000000, 0.000000, -1.00 }, - { 1.000000, 0.000000, 1.00 }, - { 0.500000, 0.866025, -1.00 }, - { -0.500000, -0.866025, 1.00 }, - { -0.500000, 0.866025, 1.00 }, - { 0.500000, -0.866025, -1.00 }, + { -1.000000, 0.000000, 1.00 }, + { 1.000000, 0.000000, -1.00 }, + { 0.500000, 0.866025, 1.00 }, + { -0.500000, -0.866025, -1.00 }, + { -0.500000, 0.866025, -1.00 }, + { 0.500000, -0.866025, 1.00 }, }; const MultirotorMixer::Rotor _config_hex_plus[] = { - { 0.000000, 1.000000, -1.00 }, - { -0.000000, -1.000000, 1.00 }, - { 0.866025, -0.500000, -1.00 }, - { -0.866025, 0.500000, 1.00 }, - { 0.866025, 0.500000, 1.00 }, - { -0.866025, -0.500000, -1.00 }, + { 0.000000, 1.000000, 1.00 }, + { -0.000000, -1.000000, -1.00 }, + { 0.866025, -0.500000, 1.00 }, + { -0.866025, 0.500000, -1.00 }, + { 0.866025, 0.500000, -1.00 }, + { -0.866025, -0.500000, 1.00 }, }; const MultirotorMixer::Rotor _config_octa_x[] = { - { -0.382683, 0.923880, -1.00 }, - { 0.382683, -0.923880, -1.00 }, - { -0.923880, 0.382683, 1.00 }, - { -0.382683, -0.923880, 1.00 }, - { 0.382683, 0.923880, 1.00 }, - { 0.923880, -0.382683, 1.00 }, - { 0.923880, 0.382683, -1.00 }, - { -0.923880, -0.382683, -1.00 }, + { -0.382683, 0.923880, 1.00 }, + { 0.382683, -0.923880, 1.00 }, + { -0.923880, 0.382683, -1.00 }, + { -0.382683, -0.923880, -1.00 }, + { 0.382683, 0.923880, -1.00 }, + { 0.923880, -0.382683, -1.00 }, + { 0.923880, 0.382683, 1.00 }, + { -0.923880, -0.382683, 1.00 }, }; const MultirotorMixer::Rotor _config_octa_plus[] = { - { 0.000000, 1.000000, -1.00 }, - { -0.000000, -1.000000, -1.00 }, - { -0.707107, 0.707107, 1.00 }, - { -0.707107, -0.707107, 1.00 }, - { 0.707107, 0.707107, 1.00 }, - { 0.707107, -0.707107, 1.00 }, - { 1.000000, 0.000000, -1.00 }, - { -1.000000, 0.000000, -1.00 }, + { 0.000000, 1.000000, 1.00 }, + { -0.000000, -1.000000, 1.00 }, + { -0.707107, 0.707107, -1.00 }, + { -0.707107, -0.707107, -1.00 }, + { 0.707107, 0.707107, -1.00 }, + { 0.707107, -0.707107, -1.00 }, + { 1.000000, 0.000000, 1.00 }, + { -1.000000, 0.000000, 1.00 }, }; const MultirotorMixer::Rotor *_config_index[MultirotorMixer::Geometry::MAX_GEOMETRY] = { &_config_quad_x[0], @@ -141,7 +141,7 @@ MultirotorMixer::MultirotorMixer(ControlCallback control_cb, _roll_scale(roll_scale), _pitch_scale(pitch_scale), _yaw_scale(yaw_scale), - _deadband(-1.0 + deadband), /* shift to output range here to avoid runtime calculation */ + _deadband(-1.0f + deadband), /* shift to output range here to avoid runtime calculation */ _rotor_count(_config_rotor_count[geometry]), _rotors(_config_index[geometry]) { @@ -179,7 +179,7 @@ MultirotorMixer::mix(float *outputs, unsigned space) fixup_scale = 2.0f; } for (unsigned i = 0; i < _rotor_count; i++) - outputs[i] = -1.0 + (outputs[i] * fixup_scale); + outputs[i] = -1.0f + (outputs[i] * fixup_scale); /* ensure outputs are out of the deadband */ for (unsigned i = 0; i < _rotor_count; i++) diff --git a/apps/systemlib/mixer/multi_tables b/apps/systemlib/mixer/multi_tables index 3da1a11bab..2c4a5abed9 100755 --- a/apps/systemlib/mixer/multi_tables +++ b/apps/systemlib/mixer/multi_tables @@ -62,7 +62,7 @@ set octa_plus { set tables {quad_x quad_plus hex_x hex_plus octa_x octa_plus} -proc factors {a d} { puts [format "\t{ %9.6f, %9.6f, %5.2f }," [rcos [expr $a + 90]] [rcos $a] $d]} +proc factors {a d} { puts [format "\t{ %9.6f, %9.6f, %5.2f }," [rcos [expr $a + 90]] [rcos $a] [expr -$d]]} foreach table $tables { puts [format "const MultirotorMixer::Rotor _config_%s\[\] = {" $table] diff --git a/apps/systemlib/param/param.c b/apps/systemlib/param/param.c new file mode 100644 index 0000000000..a01c170a68 --- /dev/null +++ b/apps/systemlib/param/param.c @@ -0,0 +1,691 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file param.c + * + * Global parameter store. + * + * Note that it might make sense to convert this into a driver. That would + * offer some interesting options regarding state for e.g. ORB advertisements + * and background parameter saving. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "systemlib/param/param.h" +#include "systemlib/uthash/utarray.h" +#include "systemlib/bson/tinybson.h" + +#include "uORB/uORB.h" +#include "uORB/topics/parameter_update.h" + +#if 1 +# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0) +#else +# define debug(fmt, args...) do { } while(0) +#endif + +/** + * Array of static parameter info. + */ +extern char __param_start, __param_end; +static const struct param_info_s *param_info_base = (struct param_info_s *) &__param_start; +static const struct param_info_s *param_info_limit = (struct param_info_s *) &__param_end; +#define param_info_count ((unsigned)(param_info_limit - param_info_base)) + +/** + * Storage for modified parameters. + */ +struct param_wbuf_s { + param_t param; + union param_value_u val; + bool unsaved; +}; + +/** flexible array holding modified parameter values */ +UT_array *param_values; + +/** array info for the modified parameters array */ +UT_icd param_icd = {sizeof(struct param_wbuf_s), NULL, NULL, NULL}; + +/** parameter update topic */ +ORB_DEFINE(parameter_update, struct parameter_update_s); + +/** parameter update topic handle */ +static orb_advert_t param_topic = -1; + +/** lock the parameter store */ +static void +param_lock(void) +{ + /* XXX */ +} + +/** unlock the parameter store */ +static void +param_unlock(void) +{ + /* XXX */ +} + +/** assert that the parameter store is locked */ +static void +param_assert_locked(void) +{ + /* XXX */ +} + +/** + * Test whether a param_t is value. + * + * @param param The parameter handle to test. + * @return True if the handle is valid. + */ +static bool +handle_in_range(param_t param) +{ + return (param < param_info_count); +} + +/** + * Compare two modifid parameter structures to determine ordering. + * + * This function is suitable for passing to qsort or bsearch. + */ +static int +param_compare_values(const void *a, const void *b) +{ + struct param_wbuf_s *pa = (struct param_wbuf_s *)a; + struct param_wbuf_s *pb = (struct param_wbuf_s *)b; + + if (pa->param < pb->param) + return -1; + + if (pa->param > pb->param) + return 1; + + return 0; +} + +/** + * Locate the modified parameter structure for a parameter, if it exists. + * + * @param param The parameter being searched. + * @return The structure holding the modified value, or + * NULL if the parameter has not been modified. + */ +static struct param_wbuf_s * +param_find_changed(param_t param) { + struct param_wbuf_s *s = NULL; + + param_assert_locked(); + + if (param_values != NULL) { +#if 0 /* utarray_find requires bsearch, not available */ + struct param_wbuf_s key; + key.param = param; + s = utarray_find(param_values, &key, param_compare_values); +#else + + while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != NULL) { + if (s->param == param) + break; + } + +#endif + } + + return s; +} + +static void +param_notify_changes(void) +{ + struct parameter_update_s pup = { .timestamp = hrt_absolute_time() }; + + /* + * If we don't have a handle to our topic, create one now; otherwise + * just publish. + */ + if (param_topic == -1) { + param_topic = orb_advertise(ORB_ID(parameter_update), &pup); + } else { + orb_publish(ORB_ID(parameter_update), param_topic, &pup); + } +} + +param_t +param_find(const char *name) +{ + param_t param; + + /* perform a linear search of the known parameters */ + for (param = 0; handle_in_range(param); param++) { + if (!strcmp(param_info_base[param].name, name)) + return param; + } + + /* not found */ + return PARAM_INVALID; +} + +unsigned +param_count(void) +{ + return param_info_count; +} + +param_t +param_for_index(unsigned index) +{ + if (index < param_info_count) + return (param_t)index; + + return PARAM_INVALID; +} + +int +param_get_index(param_t param) +{ + if (handle_in_range(param)) + return (unsigned)param; + + return -1; +} + +const char * +param_name(param_t param) +{ + if (handle_in_range(param)) + return param_info_base[param].name; + + return NULL; +} + +enum param_type_e +param_type(param_t param) +{ + if (handle_in_range(param)) + return param_info_base[param].type; + + return PARAM_TYPE_UNKNOWN; +} + +size_t +param_size(param_t param) +{ + if (handle_in_range(param)) { + switch (param_type(param)) { + case PARAM_TYPE_INT32: + case PARAM_TYPE_FLOAT: + return 4; + + case PARAM_TYPE_STRUCT ... PARAM_TYPE_STRUCT_MAX: + /* decode structure size from type value */ + return param_type(param) - PARAM_TYPE_STRUCT; + + default: + return 0; + } + } + + return 0; +} + +/** + * Obtain a pointer to the storage allocated for a parameter. + * + * @param param The parameter whose storage is sought. + * @return A pointer to the parameter value, or NULL + * if the parameter does not exist. + */ +static const void * +param_get_value_ptr(param_t param) +{ + const void *result = NULL; + + param_assert_locked(); + + if (handle_in_range(param)) { + + const union param_value_u *v; + + /* work out whether we're fetching the default or a written value */ + struct param_wbuf_s *s = param_find_changed(param); + + if (s != NULL) { + v = &s->val; + + } else { + v = ¶m_info_base[param].val; + } + + if (param_type(param) == PARAM_TYPE_STRUCT) { + result = v->p; + + } else { + result = v; + } + } + + return result; +} + +int +param_get(param_t param, void *val) +{ + int result = -1; + + param_lock(); + + const void *v = param_get_value_ptr(param); + + if (val != NULL) { + memcpy(val, v, param_size(param)); + result = 0; + } + + param_unlock(); + + return result; +} + +int +param_set(param_t param, const void *val) +{ + int result = -1; + bool params_changed = false; + + param_lock(); + + if (param_values == NULL) + utarray_new(param_values, ¶m_icd); + + if (param_values == NULL) { + debug("failed to allocate modified values array"); + goto out; + } + + if (handle_in_range(param)) { + + struct param_wbuf_s *s = param_find_changed(param); + + if (s == NULL) { + + /* construct a new parameter */ + struct param_wbuf_s buf = { + .param = param, + .val.p = NULL, + .unsaved = false + }; + + /* add it to the array and sort */ + utarray_push_back(param_values, &buf); + utarray_sort(param_values, param_compare_values); + + /* find it after sorting */ + s = param_find_changed(param); + } + + /* update the changed value */ + switch (param_type(param)) { + case PARAM_TYPE_INT32: + s->val.i = *(int32_t *)val; + break; + + case PARAM_TYPE_FLOAT: + s->val.f = *(float *)val; + break; + + case PARAM_TYPE_STRUCT ... PARAM_TYPE_STRUCT_MAX: + if (s->val.p == NULL) { + s->val.p = malloc(param_size(param)); + + if (s->val.p == NULL) { + debug("failed to allocate parameter storage"); + goto out; + } + } + + memcpy(s->val.p, val, param_size(param)); + break; + + default: + goto out; + } + + s->unsaved = true; + params_changed = true; + result = 0; + } + +out: + param_unlock(); + + /* + * If we set something, now that we have unlocked, go ahead and advertise that + * a thing has been set. + */ + if (params_changed) + param_notify_changes(); + + return result; +} + +void +param_reset(param_t param) +{ + struct param_wbuf_s *s = NULL; + + param_lock(); + + if (handle_in_range(param)) { + + /* look for a saved value */ + s = param_find_changed(param); + + /* if we found one, erase it */ + if (s != NULL) { + int pos = utarry_eltidx(param_values, s); + utarray_erase(param_values, pos, 1); + } + } + param_unlock(); + + if (s != NULL) + param_notify_changes(); +} + +void +param_reset_all(void) +{ + param_lock(); + + if (param_values != NULL) { + utarray_free(param_values); + } + + /* mark as reset / deleted */ + param_values = NULL; + + param_unlock(); + + param_notify_changes(); +} + +int +param_export(int fd, bool only_unsaved) +{ + struct param_wbuf_s *s = NULL; + struct bson_encoder_s encoder; + int result = -1; + + param_lock(); + + bson_encoder_init(&encoder, fd); + + /* no modified parameters -> we are done */ + if (param_values == NULL) { + result = 0; + goto out; + } + + while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != NULL) { + + int32_t i; + float f; + + /* + * If we are only saving values changed since last save, and this + * one hasn't, then skip it + */ + if (only_unsaved && !s->unsaved) + continue; + + s->unsaved = false; + + /* append the appripriate BSON type object */ + switch (param_type(s->param)) { + case PARAM_TYPE_INT32: + param_get(s->param, &i); + + if (bson_encoder_append_int(&encoder, param_name(s->param), i)) { + debug("BSON append failed for '%s'", param_name(s->param)); + goto out; + } + + break; + + case PARAM_TYPE_FLOAT: + param_get(s->param, &f); + + if (bson_encoder_append_double(&encoder, param_name(s->param), f)) { + debug("BSON append failed for '%s'", param_name(s->param)); + goto out; + } + + break; + + case PARAM_TYPE_STRUCT ... PARAM_TYPE_STRUCT_MAX: + if (bson_encoder_append_binary(&encoder, + param_name(s->param), + BSON_BIN_BINARY, + param_size(s->param), + param_get_value_ptr(s->param))) { + debug("BSON append failed for '%s'", param_name(s->param)); + goto out; + } + + break; + + default: + debug("unrecognized parameter type"); + goto out; + } + } + + result = 0; + +out: + param_unlock(); + + if (result == 0) + result = bson_encoder_fini(&encoder); + + return result; +} + +static int +param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node) +{ + float f; + int32_t i; + void *v, *tmp = NULL; + int result = -1; + + /* + * EOO means the end of the parameter object. (Currently not supporting + * nested BSON objects). + */ + if (node->type == BSON_EOO) { + *(bool *)private = true; + debug("end of parameters"); + return 0; + } + + /* + * Find the parameter this node represents. If we don't know it, + * ignore the node. + */ + param_t param = param_find(node->name); + + if (param == PARAM_INVALID) { + debug("ignoring unrecognised parameter '%s'", node->name); + return 1; + } + + /* + * Handle setting the parameter from the node + */ + + switch (node->type) { + case BSON_INT: + if (param_type(param) != PARAM_TYPE_INT32) { + debug("unexpected type for '%s", node->name); + goto out; + } + + i = node->i; + v = &i; + break; + + case BSON_DOUBLE: + if (param_type(param) != PARAM_TYPE_FLOAT) { + debug("unexpected type for '%s", node->name); + goto out; + } + + f = node->d; + v = &f; + break; + + case BSON_BINDATA: + if (node->subtype != BSON_BIN_BINARY) { + debug("unexpected subtype for '%s", node->name); + goto out; + } + + if (bson_decoder_data_pending(decoder) != param_size(param)) { + debug("bad size for '%s'", node->name); + goto out; + } + + /* XXX check actual file data size? */ + tmp = malloc(param_size(param)); + + if (tmp == NULL) { + debug("failed allocating for '%s'", node->name); + goto out; + } + + if (bson_decoder_copy_data(decoder, tmp)) { + debug("failed copying data for '%s'", node->name); + goto out; + } + + v = tmp; + break; + + default: + debug("unrecognised node type"); + goto out; + } + + if (param_set(param, v)) { + debug("error setting value for '%s'", node->name); + goto out; + } + + if (tmp != NULL) { + free(tmp); + tmp = NULL; + } + + /* don't return zero, that means EOF */ + result = 1; + +out: + + if (tmp != NULL) + free(tmp); + + return result; +} + +int +param_import(int fd) +{ + bool done; + struct bson_decoder_s decoder; + int result = -1; + + if (bson_decoder_init(&decoder, fd, param_import_callback, &done)) { + debug("decoder init failed"); + goto out; + } + + done = false; + + do { + result = bson_decoder_next(&decoder); + + } while(result > 0); + +out: + if (result < 0) + debug("BSON error decoding parameters"); + + return result; +} + +int +param_load(int fd) +{ + param_reset_all(); + return param_import(fd); +} + +void +param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_changed) +{ + param_t param; + + for (param = 0; handle_in_range(param); param++) { + + /* if requested, skip unchanged values */ + if (only_changed && (param_find_changed(param) == NULL)) + continue; + + func(arg, param); + } +} \ No newline at end of file diff --git a/apps/systemlib/param/param.h b/apps/systemlib/param/param.h new file mode 100644 index 0000000000..ffce07a4ed --- /dev/null +++ b/apps/systemlib/param/param.h @@ -0,0 +1,287 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file param.h + * + * Global parameter store. + * + * Note that a number of API members are marked const or pure; these + * assume that the set of parameters cannot change, or that a parameter + * cannot change type or size over its lifetime. If any of these assumptions + * are invalidated, the attributes should be re-evaluated. + */ + +#ifndef _SYSTEMLIB_PARAM_PARAM_H +#define _SYSTEMLIB_PARAM_PARAM_H + +#include +#include +#include + +/** Maximum size of the parameter backing file */ +#define PARAM_FILE_MAXSIZE 4096 + +__BEGIN_DECLS + +/** + * Parameter types. + */ +typedef enum param_type_e { + /* globally-known parameter types */ + PARAM_TYPE_INT32 = 0, + PARAM_TYPE_FLOAT, + + /* structure parameters; size is encoded in the type value */ + PARAM_TYPE_STRUCT = 100, + PARAM_TYPE_STRUCT_MAX = 16384 + PARAM_TYPE_STRUCT, + + PARAM_TYPE_UNKNOWN = 0xffff +} param_type_t; + +/** + * Parameter handle. + * + * Parameters are represented by parameter handles, which can + * be obtained by looking up (or creating?) parameters. + */ +typedef uintptr_t param_t; + +/** + * Handle returned when a parameter cannot be found. + */ +#define PARAM_INVALID ((uintptr_t)0xffffffff) + +/** + * Look up a parameter by name. + * + * @param name The canonical name of the parameter being looked up. + * @return A handle to the parameter, or PARAM_INVALID if the parameter does not exist. + */ +__EXPORT param_t param_find(const char *name); + +/** + * Return the total number of parameters. + * + * @return The number of parameters. + */ +__EXPORT unsigned param_count(void); + +/** + * Look up a parameter by index. + * + * @param index An index from 0 to n, where n is param_count()-1. + * @return A handle to the parameter, or PARAM_INVALID if the index is out of range. + */ +__EXPORT param_t param_for_index(unsigned index); + +/** + * Look up the index of a parameter. + * + * @param param The parameter to obtain the index for. + * @return The index, or -1 if the parameter does not exist. + */ +__EXPORT int param_get_index(param_t param); + +/** + * Obtain the name of a parameter. + * + * @param param A handle returned by param_find or passed by param_foreach. + * @return The name assigned to the parameter, or NULL if the handle is invalid. + */ +__EXPORT const char *param_name(param_t param); + +/** + * Obtain the type of a parameter. + * + * @param param A handle returned by param_find or passed by param_foreach. + * @return The type assigned to the parameter. + */ +__EXPORT param_type_t param_type(param_t param); + +/** + * Determine the size of a parameter. + * + * @param param A handle returned by param_find or passed by param_foreach. + * @return The size of the parameter's value. + */ +__EXPORT size_t param_size(param_t param); + +/** + * Copy the value of a parameter. + * + * @param param A handle returned by param_find or passed by param_foreach. + * @param val Where to return the value, assumed to point to suitable storage for the parameter type. + * For structures, a bitwise copy of the structure is performed to this address. + * @return Zero if the parameter's value could be returned, nonzero otherwise. + */ +__EXPORT int param_get(param_t param, void *val); + +/** + * Set the value of a parameter. + * + * @param param A handle returned by param_find or passed by param_foreach. + * @param val The value to set; assumed to point to a variable of the parameter type. + * For structures, the pointer is assumed to point to a structure to be copied. + * @return Zero if the parameter's value could be set from a scalar, nonzero otherwise. + */ +__EXPORT int param_set(param_t param, const void *val); + +/** + * Reset a parameter to its default value. + * + * This function frees any storage used by struct parameters, but scalar parameters + * + * @param param A handle returned by param_find or passed by param_foreach. + */ +__EXPORT void param_reset(param_t param); + +/** + * Reset all parameters to their default values. + * + * This function also releases the storage used by struct parameters. + */ +__EXPORT void param_reset_all(void); + +/** + * Export changed parameters to a file. + * + * @param fd File descriptor to export to. + * @param only_unsaved Only export changed parameters that have not yet been exported. + * @return Zero on success, nonzero on failure. + */ +__EXPORT int param_export(int fd, bool only_unsaved); + +/** + * Import parameters from a file, discarding any unrecognized parameters. + * + * This function merges the imported parameters with the current parameter set. + * + * @param fd File descriptor to import from. (Currently expected to be a file.) + * @return Zero on success, nonzero if an error occurred during import. + * Note that in the failure case, parameters may be inconsistent. + */ +__EXPORT int param_import(int fd); + +/** + * Load parameters from a file. + * + * This function resets all parameters to their default values, then loads new + * values from a file. + * + * @param fd File descriptor to import from. (Currently expected to be a file.) + * @return Zero on success, nonzero if an error occurred during import. + * Note that in the failure case, parameters may be inconsistent. + */ +__EXPORT int param_load(int fd); + +/** + * Apply a function to each parameter. + * + * Note that the parameter set is not locked during the traversal. It also does + * not hold an internal state, so the callback function can block or sleep between + * parameter callbacks. + * + * @param func The function to invoke for each parameter. + * @param arg Argument passed to the function. + * @param only_changed If true, the function is only called for parameters whose values have + * been changed from the default. + */ +__EXPORT void param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_changed); + +/* + * Macros creating static parameter definitions. + * + * Note that these structures are not known by name; they are + * collected into a section that is iterated by the parameter + * code. + * + * Note that these macros cannot be used in C++ code due to + * their use of designated initializers. They should probably + * be refactored to avoid the use of a union for param_value_u. + */ + +/** define an int32 parameter */ +#define PARAM_DEFINE_INT32(_name, _default) \ + static const \ + __attribute__((used, section("__param"))) \ + struct param_info_s __param__##_name = { \ + #_name, \ + PARAM_TYPE_INT32, \ + .val.i = _default \ + } + +/** define a float parameter */ +#define PARAM_DEFINE_FLOAT(_name, _default) \ + static const \ + __attribute__((used, section("__param"))) \ + struct param_info_s __param__##_name = { \ + #_name, \ + PARAM_TYPE_FLOAT, \ + .val.f = _default \ + } + +/** define a parameter that points to a structure */ +#define PARAM_DEFINE_STRUCT(_name, _default) \ + static const \ + __attribute__((used, section("__param"))) \ + struct param_info_s __param__##_name = { \ + #_name, \ + PARAM_TYPE_STRUCT + sizeof(_default), \ + .val.p = &_default; \ + } + +/** + * Parameter value union. + */ +union param_value_u { + void *p; + int32_t i; + float f; +}; + +/** + * Static parameter definition structure. + * + * This is normally not used by user code; see the PARAM_DEFINE macros + * instead. + */ +struct param_info_s { + const char *name; + param_type_t type; + union param_value_u val; +}; + +__END_DECLS + +#endif diff --git a/apps/systemlib/pid/pid.c b/apps/systemlib/pid/pid.c new file mode 100644 index 0000000000..807373c158 --- /dev/null +++ b/apps/systemlib/pid/pid.c @@ -0,0 +1,148 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Laurens Mackay + * @author Tobias Naegeli + * @author Martin Rutschmann + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file pid.c + * Implementation of generic PID control interface + */ + +#include "pid.h" + +__EXPORT void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, + uint8_t mode, uint8_t plot_i) +{ + pid->kp = kp; + pid->ki = ki; + pid->kd = kd; + pid->intmax = intmax; + pid->mode = mode; + pid->plot_i = plot_i; + pid->count = 0; + pid->saturated = 0; + + pid->sp = 0; + pid->error_previous = 0; + pid->integral = 0; +} +__EXPORT void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax) +{ + pid->kp = kp; + pid->ki = ki; + pid->kd = kd; + pid->intmax = intmax; + // pid->mode = mode; + + // pid->sp = 0; + // pid->error_previous = 0; + // pid->integral = 0; +} + +//void pid_set(PID_t *pid, float sp) +//{ +// pid->sp = sp; +// pid->error_previous = 0; +// pid->integral = 0; +//} + +/** + * + * @param pid + * @param val + * @param dt + * @return + */ +__EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt) +{ + /* error = setpoint - actual_position + integral = integral + (error*dt) + derivative = (error - previous_error)/dt + output = (Kp*error) + (Ki*integral) + (Kd*derivative) + previous_error = error + wait(dt) + goto start + */ + + float i, d; + pid->sp = sp; + float error = pid->sp - val; + + if (pid->saturated && (pid->integral * error > 0)) { + //Output is saturated and the integral would get bigger (positive or negative) + i = pid->integral; + + //Reset saturation. If we are still saturated this will be set again at output limit check. + pid->saturated = 0; + + } else { + i = pid->integral + (error * dt); + } + + // Anti-Windup. Needed if we don't use the saturation above. + if (pid->intmax != 0.0) { + if (i > pid->intmax) { + pid->integral = pid->intmax; + + } else if (i < -pid->intmax) { + + pid->integral = -pid->intmax; + + } else { + pid->integral = i; + } + + //Send Controller integrals + // Disabled because of new possibilities with debug_vect. + // Now sent in Main Loop at 5 Hz. 26.06.2010 Laurens + // if (pid->plot_i && (pid->count++ % 16 == 0)&&(global_data.param[PARAM_SEND_SLOT_DEBUG_2] == 1)) + // { + // mavlink_msg_debug_send(MAVLINK_COMM_1, pid->plot_i, pid->integral); + // } + } + + if (pid->mode == PID_MODE_DERIVATIV_CALC) { + d = (error - pid->error_previous) / dt; + + } else if (pid->mode == PID_MODE_DERIVATIV_SET) { + d = -val_dot; + + } else { + d = 0; + } + + pid->error_previous = error; + + return (error * pid->kp) + (i * pid->ki) + (d * pid->kd); +} diff --git a/apps/systemlib/pid/pid.h b/apps/systemlib/pid/pid.h new file mode 100644 index 0000000000..83bf09b59f --- /dev/null +++ b/apps/systemlib/pid/pid.h @@ -0,0 +1,74 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Laurens Mackay + * @author Tobias Naegeli + * @author Martin Rutschmann + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file pid.h + * Definition of generic PID control interface + */ + +#ifndef PID_H_ +#define PID_H_ + +#include + +/* PID_MODE_DERIVATIV_CALC calculates discrete derivative from previous error + * val_dot in pid_calculate() will be ignored */ +#define PID_MODE_DERIVATIV_CALC 0 +/* Use PID_MODE_DERIVATIV_SET if you have the derivative already (Gyros, Kalman) */ +#define PID_MODE_DERIVATIV_SET 1 + +typedef struct { + float kp; + float ki; + float kd; + float intmax; + float sp; + float integral; + float error_previous; + uint8_t mode; + uint8_t plot_i; + uint8_t count; + uint8_t saturated; +} PID_t; + +__EXPORT void pid_init(PID_t *pid, float kp, float ki, float kd, float intmax, uint8_t mode, uint8_t plot_i); +__EXPORT void pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float intmax); +//void pid_set(PID_t *pid, float sp); +__EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt); + + + +#endif /* PID_H_ */ diff --git a/apps/systemlib/systemlib.c b/apps/systemlib/systemlib.c index b1a8de7bd7..4c7aae83e2 100644 --- a/apps/systemlib/systemlib.c +++ b/apps/systemlib/systemlib.c @@ -3,7 +3,6 @@ * Copyright (C) 2012 PX4 Development Team. All rights reserved. * Author: @author Lorenz Meier * - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -35,7 +34,7 @@ /** * @file systemlib.c - * Implementation of commonly used low-level system-call like functions + * Implementation of commonly used low-level system-call like functions. */ #include @@ -47,7 +46,6 @@ #include #include #include -#include #include #include @@ -123,142 +121,6 @@ void kill_task(FAR _TCB *tcb, FAR void *arg) kill(tcb->pid, SIGUSR1); } -union param_union { - float f; - char c[4]; -}; - -int store_params_in_eeprom(struct global_data_parameter_storage_t *params) -{ - int ret = ERROR; - int fd = open("/dev/eeprom", O_RDWR | O_NONBLOCK); - int lseek_res = lseek(fd, EEPROM_OFFSET, SEEK_SET); //don't touch first 64 bytes - int write_res; - - if (fd < 0) { - fprintf(stderr, "onboard eeprom: open fail\n"); - ret = ERROR; - - } else if (lseek_res < 0) { - fprintf(stderr, "onboard eeprom: set offet fail\n"); - ret = ERROR; - - } else { - /*Write start magic byte */ - uint8_t mb = EEPROM_PARAM_MAGIC_BYTE; - write_res = write(fd, &mb, sizeof(mb)); - - if (write_res != sizeof(mb)) { - ret = ERROR; - - } else { - for (int i = 0; i < PARAM_MAX_COUNT; i++) { - - union param_union p; - p.f = params->pm.param_values[i]; - write_res = write(fd, p.c, sizeof(p.f)); - - if (write_res != sizeof(p.f)) return ERROR; - } - - /*Write end magic byte */ - write_res = write(fd, &mb, sizeof(mb)); - - if (write_res != sizeof(mb)) { - ret = ERROR; - - } else { - ret = OK; - } - } - - } - - close(fd); - - return ret; -} - -int get_params_from_eeprom(struct global_data_parameter_storage_t *params) -{ - int ret = ERROR; - uint8_t magic_byte = 0; - int fd = open("/dev/eeprom", O_RDWR | O_NONBLOCK); - int lseek_res = lseek(fd, EEPROM_OFFSET, SEEK_SET); //don't touch first 64 bytes - - if (fd < 0) { - fprintf(stderr, "onboard eeprom: open fail\n"); - ret = ERROR; - - } else if (lseek_res < 0) { - fprintf(stderr, "onboard eeprom: set offet fail\n"); - ret = ERROR; - - } else { - /*Get start magic byte */ - magic_byte = 0; - int read_res = read(fd, &magic_byte, sizeof(uint8_t)); - - if (read_res != sizeof(uint8_t)) { - ret = ERROR; - - } else { - if (magic_byte != EEPROM_PARAM_MAGIC_BYTE) { - ret = ERROR; - fprintf(stderr, "onboard eeprom: parameters: start magic byte wrong\n"); - - } else { - /*get end magic byte */ - lseek_res = lseek(fd, EEPROM_OFFSET + 1 + params->pm.size * sizeof(float), SEEK_SET); // jump to 2nd magic byte - - if (lseek_res == OK) { - /*Get end magic */ - read_res = read(fd, &magic_byte, sizeof(uint8_t)); - - if (read_res != sizeof(uint8_t)) { - ret = ERROR; - - } else { - if (magic_byte != EEPROM_PARAM_MAGIC_BYTE) { - ret = ERROR; - printf("onboard eeprom: parameters: end magic byte wrong\n"); - - } else { - lseek_res = lseek(fd, EEPROM_OFFSET + 1, SEEK_SET); - - /* read data */ - if (lseek_res == OK) { - - for (int i = 0; i < PARAM_MAX_COUNT; i++) { - union param_union p; - read_res = read(fd, p.c, sizeof(p.f)); - params->pm.param_values[i] = p.f; - if (read_res != sizeof(p.f)) return ERROR; - } - - ret = OK; - - } else { - /* lseek #2 failed */ - ret = ERROR; - } - } - } - - } else { - /* lseek #1 failed */ - ret = ERROR; - } - } - } - - } - - close(fd); - - return ret; -} - #define PX4_BOARD_ID_FMU (5) int fmu_get_board_info(struct fmu_board_info_s *info) @@ -268,23 +130,20 @@ int fmu_get_board_info(struct fmu_board_info_s *info) int statres; /* Copy version-specific fields */ - statres = stat("/dev/bma280", &sb); + statres = stat("/dev/bma180", &sb); if (statres == OK) { - /* BMA280 indicates a v1.7+ board */ - strcpy(info->board_name, "FMU v1.7"); - info->board_version = 17; - - } else { - statres = stat("/dev/bma180", &sb); - - if (statres == OK) { /* BMA180 indicates a v1.5-v1.6 board */ strcpy(info->board_name, "FMU v1.6"); info->board_version = 16; - + } else { + statres = stat("/dev/accel", &sb); + if (statres == OK) { + /* MPU-6000 indicates a v1.7+ board */ + strcpy(info->board_name, "FMU v1.7"); + info->board_version = 17; } else { - /* If no BMA pressure sensor is present, it is a v1.3 board */ + /* If no BMA and no MPU is present, it is a v1.3 board */ strcpy(info->board_name, "FMU v1.3"); info->board_version = 13; } @@ -317,7 +176,8 @@ int carrier_get_board_info(struct carrier_board_info_s *info) int ret; int fd = open("/dev/eeprom", O_RDONLY | O_NONBLOCK); - if (fd < 0) fprintf(stderr, "[boardinfo carrier] ERROR opening carrier eeprom\n"); + if (fd < 0) + return -1; /* no board */ ret = read(fd, info, sizeof(struct carrier_board_info_s)); diff --git a/apps/systemlib/systemlib.h b/apps/systemlib/systemlib.h index eec43a5b44..add47f4401 100644 --- a/apps/systemlib/systemlib.h +++ b/apps/systemlib/systemlib.h @@ -34,7 +34,7 @@ /** * @file systemlib.h - * Definition of commonly used low-level system-call like functions + * Definition of commonly used low-level system-call like functions. */ #ifndef SYSTEMLIB_H_ @@ -50,12 +50,6 @@ __EXPORT int reboot(void); /** Sends SIGUSR1 to all processes */ __EXPORT void killall(void); -struct global_data_parameter_storage_t; - -__EXPORT int store_params_in_eeprom(struct global_data_parameter_storage_t *params); - -__EXPORT int get_params_from_eeprom(struct global_data_parameter_storage_t *params); - enum MULT_PORTS { MULT_0_US2_RXTX = 0, MULT_1_US2_FLOW, diff --git a/apps/systemlib/uthash/doc/userguide.txt b/apps/systemlib/uthash/doc/userguide.txt new file mode 100644 index 0000000000..3e65a52fc9 --- /dev/null +++ b/apps/systemlib/uthash/doc/userguide.txt @@ -0,0 +1,1682 @@ +uthash User Guide +================= +Troy D. Hanson +v1.9.6, April 2012 + +include::sflogo.txt[] +include::topnav.txt[] + +A hash in C +----------- +include::toc.txt[] + +This document is written for C programmers. Since you're reading this, chances +are that you know a hash is used for looking up items using a key. In scripting +languages like Perl, hashes are used all the time. In C, hashes don't exist in +the language itself. This software provides a hash table for C structures. + +What can it do? +~~~~~~~~~~~~~~~~~ +This software supports these operations on items in a hash table: + +1. add +2. find +3. delete +4. count +5. iterate +6. sort +7. select + +Is it fast? +~~~~~~~~~~~ +Add, find and delete are normally constant-time operations. This is influenced +by your key domain and the hash function. + +This hash aims to be minimalistic and efficient. It's around 900 lines of C. +It inlines automatically because it's implemented as macros. It's fast as long +as the hash function is suited to your keys. You can use the default hash +function, or easily compare performance and choose from among several other +<>. + +Is it a library? +~~~~~~~~~~~~~~~~ +No, it's just a single header file: `uthash.h`. All you need to do is copy +the header file into your project, and: + + #include "uthash.h" + +Since uthash is a header file only, there is no library code to link against. + +C/C++ and platforms +~~~~~~~~~~~~~~~~~~~ +This software can be used in C and C++ programs. It has been tested on: + + * Linux + * Mac OS X + * Windows using Visual Studio 2008 and 2010 + * Solaris + * OpenBSD + * FreeBSD + +Test suite +^^^^^^^^^^ +To run the test suite, enter the `tests` directory. Then, + + * on Unix platforms, run `make` + * on Windows, run the "do_tests_win32.cmd" batch file. (You may edit the + batch file if your Visual Studio is installed in a non-standard location). + +BSD licensed +~~~~~~~~~~~~ +This software is made available under the +link:license.html[revised BSD license]. +It is free and open source. + +Obtaining uthash +~~~~~~~~~~~~~~~~ +Please follow the link to download on the +http://uthash.sourceforge.net[uthash website] at http://uthash.sourceforge.net. + +A number of platforms include uthash in their package repositories. For example, +Debian/Ubuntu users may simply `aptitude install uthash-dev`. + +Getting help +~~~~~~~~~~~~ +Feel free to mailto:tdh@tkhanson.net[email the author] at +tdh@tkhanson.net. + +Resources +~~~~~~~~~ +Users of uthash may wish to follow the news feed for information about new +releases. Also, there are some extra bonus headers included with uthash. + +News:: + The author has a news feed for http://troydhanson.wordpress.com/[software updates] image:img/rss.png[(RSS)]. +Extras included with uthash:: + uthash ships with these "extras"-- independent headers similar to uthash. + First link:utlist.html[utlist.h] provides linked list macros for C structures. + Second, link:utarray.html[utarray.h] implements dynamic arrays using macros. + Third, link:utstring.html[utstring.h] implements a basic dynamic string. +Other software:: + Other open-source software by the author is listed at http://tkhanson.net. + +Who's using it? +~~~~~~~~~~~~~~~ +Since releasing uthash in 2006, it has been downloaded thousands of times, +incorporated into commercial software, academic research, and into other +open-source software. + +Your structure +-------------- + +In uthash, a hash table is comprised of structures. Each structure represents a +key-value association. One or more of the structure fields constitute the key. +The structure pointer itself is the value. + +.Defining a structure that can be hashed +---------------------------------------------------------------------- +#include "uthash.h" + +struct my_struct { + int id; /* key */ + char name[10]; + UT_hash_handle hh; /* makes this structure hashable */ +}; +---------------------------------------------------------------------- + +Note that, in uthash, your structure will never be moved or copied into another +location when you add it into a hash table. This means that you can keep other +data structures that safely point to your structure-- regardless of whether you +add or delete it from a hash table during your program's lifetime. + +The key +~~~~~~~ +There are no restrictions on the data type or name of the key field. The key +can also comprise multiple contiguous fields, having any names and data types. + +.Any data type... really? +***************************************************************************** +Yes, your key and structure can have any data type. Unlike function calls with +fixed prototypes, uthash consists of macros-- whose arguments are untyped-- and +thus able to work with any type of structure or key. +***************************************************************************** + +Unique keys +^^^^^^^^^^^ +As with any hash, every item must have a unique key. Your application must +enforce key uniqueness. Before you add an item to the hash table, you must +first know (if in doubt, check!) that the key is not already in use. You +can check whether a key already exists in the hash table using `HASH_FIND`. + +The hash handle +~~~~~~~~~~~~~~~ +The `UT_hash_handle` field must be present in your structure. It is used for +the internal bookkeeping that makes the hash work. It does not require +initialization. It can be named anything, but you can simplify matters by +naming it `hh`. This allows you to use the easier "convenience" macros to add, +find and delete items. + +A word about memory +~~~~~~~~~~~~~~~~~~~ +Some have asked how uthash cleans up its internal memory. The answer is simple: +'when you delete the final item' from a hash table, uthash releases all the +internal memory associated with that hash table, and sets its pointer to NULL. + +Hash operations +--------------- + +This section introduces the uthash macros by example. For a more succinct +listing, see <>. + +.Convenience vs. general macros: +***************************************************************************** +The uthash macros fall into two categories. The 'convenience' macros can be used +with integer, pointer or string keys (and require that you chose the conventional +name `hh` for the `UT_hash_handle` field). The convenience macros take fewer +arguments than the general macros, making their usage a bit simpler for these +common types of keys. + +The 'general' macros can be used for any types of keys, or for multi-field keys, +or when the `UT_hash_handle` has been named something other than `hh`. These +macros take more arguments and offer greater flexibility in return. But if the +convenience macros suit your needs, use them-- your code will be more readable. +***************************************************************************** + +Declare the hash +~~~~~~~~~~~~~~~~ +Your hash must be declared as a `NULL`-initialized pointer to your structure. + + struct my_struct *users = NULL; /* important! initialize to NULL */ + +Add item +~~~~~~~~ +Allocate and initialize your structure as you see fit. The only aspect +of this that matters to uthash is that your key must be initialized to +a unique value. Then call `HASH_ADD`. (Here we use the convenience macro +`HASH_ADD_INT`, which offers simplified usage for keys of type `int`). + +.Add an item to a hash +---------------------------------------------------------------------- +void add_user(int user_id, char *name) { + struct my_struct *s; + + s = malloc(sizeof(struct my_struct)); + s->id = user_id; + strcpy(s->name, name); + HASH_ADD_INT( users, id, s ); /* id: name of key field */ +} +---------------------------------------------------------------------- + +The first parameter to `HASH_ADD_INT` is the hash table, and the +second parameter is the 'name' of the key field. Here, this is `id`. The +last parameter is a pointer to the structure being added. + +[[validc]] +.Wait.. the field name is a parameter? +******************************************************************************* +If you find it strange that `id`, which is the 'name of a field' in the +structure, can be passed as a parameter, welcome to the world of macros. Don't +worry- the C preprocessor expands this to valid C code. +******************************************************************************* + +Key must not be modified while in-use +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Once a structure has been added to the hash, do not change the value of its key. +Instead, delete the item from the hash, change the key, and then re-add it. + +Passing the hash pointer into functions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +In the example above `users` is a global variable, but what if the caller wanted +to pass the hash pointer 'into' the `add_user` function? At first glance it would +appear that you could simply pass `users` as an argument, but that won't work +right. + + /* bad */ + void add_user(struct my_struct *users, int user_id, char *name) { + ... + HASH_ADD_INT( users, id, s ); + } + +You really need to pass 'a pointer' to the hash pointer: + + /* good */ + void add_user(struct my_struct **users, int user_id, char *name) { ... + ... + HASH_ADD_INT( *users, id, s ); + } + +Note that we dereferenced the pointer in the `HASH_ADD` also. + +The reason it's necessary to deal with a pointer to the hash pointer is simple: +the hash macros modify it (in other words, they modify the 'pointer itself' not +just what it points to). + +Find item +~~~~~~~~~ +To look up a structure in a hash, you need its key. Then call `HASH_FIND`. +(Here we use the convenience macro `HASH_FIND_INT` for keys of type `int`). + +.Find a structure using its key +---------------------------------------------------------------------- +struct my_struct *find_user(int user_id) { + struct my_struct *s; + + HASH_FIND_INT( users, &user_id, s ); /* s: output pointer */ + return s; +} +---------------------------------------------------------------------- + +Here, the hash table is `users`, and `&user_id` points to the key (an integer +in this case). Last, `s` is the 'output' variable of `HASH_FIND_INT`. The +final result is that `s` points to the structure with the given key, or +is `NULL` if the key wasn't found in the hash. + +[NOTE] +The middle argument is a 'pointer' to the key. You can't pass a literal key +value to `HASH_FIND`. Instead assign the literal value to a variable, and pass +a pointer to the variable. + + +Delete item +~~~~~~~~~~~ +To delete a structure from a hash, you must have a pointer to it. (If you only +have the key, first do a `HASH_FIND` to get the structure pointer). + +.Delete an item from a hash +---------------------------------------------------------------------- +void delete_user(struct my_struct *user) { + HASH_DEL( users, user); /* user: pointer to deletee */ + free(user); /* optional; it's up to you! */ +} +---------------------------------------------------------------------- + +Here again, `users` is the hash table, and `user` is a pointer to the +structure we want to remove from the hash. + +uthash never frees your structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Deleting a structure just removes it from the hash table-- it doesn't `free` +it. The choice of when to free your structure is entirely up to you; uthash +will never free your structure. + +Delete can change the pointer +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The hash table pointer (which initially points to the first item added to the +hash) can change in response to `HASH_DEL` (i.e. if you delete the first item +in the hash table). + +Iterative deletion +^^^^^^^^^^^^^^^^^^ +The `HASH_ITER` macro is a deletion-safe iteration construct which expands +to a simple 'for' loop. + +.Delete all items from a hash +---------------------------------------------------------------------- +void delete_all() { + struct my_struct *current_user, *tmp; + + HASH_ITER(hh, users, current_user, tmp) { + HASH_DEL(users,current_user); /* delete; users advances to next */ + free(current_user); /* optional- if you want to free */ + } +} +---------------------------------------------------------------------- + +All-at-once deletion +^^^^^^^^^^^^^^^^^^^^ +If you only want to delete all the items, but not free them or do any +per-element clean up, you can do this more efficiently in a single operation: + + HASH_CLEAR(hh,users); + +Afterward, the list head (here, `users`) will be set to `NULL`. + +Count items +~~~~~~~~~~~ + +The number of items in the hash table can be obtained using `HASH_COUNT`: + +.Count of items in the hash table +---------------------------------------------------------------------- +unsigned int num_users; +num_users = HASH_COUNT(users); +printf("there are %u users\n", num_users); +---------------------------------------------------------------------- + +Incidentally, this works even the list (`users`, here) is `NULL`, in +which case the count is 0. + +Iterating and sorting +~~~~~~~~~~~~~~~~~~~~~ + +You can loop over the items in the hash by starting from the beginning and +following the `hh.next` pointer. + +.Iterating over all the items in a hash +---------------------------------------------------------------------- +void print_users() { + struct my_struct *s; + + for(s=users; s != NULL; s=s->hh.next) { + printf("user id %d: name %s\n", s->id, s->name); + } +} +---------------------------------------------------------------------- + +There is also an `hh.prev` pointer you could use to iterate backwards through +the hash, starting from any known item. + +[[deletesafe]] +Deletion-safe iteration +^^^^^^^^^^^^^^^^^^^^^^^ +In the example above, it would not be safe to delete and free `s` in the body +of the 'for' loop, (because `s` is derefenced each time the loop iterates). +This is easy to rewrite correctly (by copying the `s->hh.next` pointer to a +temporary variable 'before' freeing `s`), but it comes up often enough that a +deletion-safe iteration macro, `HASH_ITER`, is included. It expands to a +`for`-loop header. Here is how it could be used to rewrite the last example: + + struct my_struct *s, *tmp; + + HASH_ITER(hh, users, s, tmp) { + printf("user id %d: name %s\n", s->id, s->name); + /* ... it is safe to delete and free s here */ + } + +.A hash is also a doubly-linked list. +******************************************************************************* +Iterating backward and forward through the items in the hash is possible +because of the `hh.prev` and `hh.next` fields. All the items in the hash can +be reached by repeatedly following these pointers, thus the hash is also a +doubly-linked list. +******************************************************************************* + +If you're using uthash in a C++ program, you need an extra cast on the `for` +iterator, e.g., `s=(struct my_struct*)s->hh.next`. + +Sorted iteration +^^^^^^^^^^^^^^^^ +The items in the hash are, by default, traversed in the order they were added +("insertion order") when you follow the `hh.next` pointer. But you can sort +the items into a new order using `HASH_SORT`. E.g., + + HASH_SORT( users, name_sort ); + +The second argument is a pointer to a comparison function. It must accept two +arguments which are pointers to two items to compare. Its return value should +be less than zero, zero, or greater than zero, if the first item sorts before, +equal to, or after the second item, respectively. (Just like `strcmp`). + +.Sorting the items in the hash +---------------------------------------------------------------------- +int name_sort(struct my_struct *a, struct my_struct *b) { + return strcmp(a->name,b->name); +} + +int id_sort(struct my_struct *a, struct my_struct *b) { + return (a->id - b->id); +} + +void sort_by_name() { + HASH_SORT(users, name_sort); +} + +void sort_by_id() { + HASH_SORT(users, id_sort); +} +---------------------------------------------------------------------- + +When the items in the hash are sorted, the first item may change position. In +the example above, `users` may point to a different structure after calling +`HASH_SORT`. + +A complete example +~~~~~~~~~~~~~~~~~~ + +We'll repeat all the code and embellish it with a `main()` function to form a +working example. + +If this code was placed in a file called `example.c` in the same directory as +`uthash.h`, it could be compiled and run like this: + + cc -o example example.c + ./example + +Follow the prompts to try the program. + +.A complete program +---------------------------------------------------------------------- +#include /* gets */ +#include /* atoi, malloc */ +#include /* strcpy */ +#include "uthash.h" + +struct my_struct { + int id; /* key */ + char name[10]; + UT_hash_handle hh; /* makes this structure hashable */ +}; + +struct my_struct *users = NULL; + +void add_user(int user_id, char *name) { + struct my_struct *s; + + s = (struct my_struct*)malloc(sizeof(struct my_struct)); + s->id = user_id; + strcpy(s->name, name); + HASH_ADD_INT( users, id, s ); /* id: name of key field */ +} + +struct my_struct *find_user(int user_id) { + struct my_struct *s; + + HASH_FIND_INT( users, &user_id, s ); /* s: output pointer */ + return s; +} + +void delete_user(struct my_struct *user) { + HASH_DEL( users, user); /* user: pointer to deletee */ + free(user); +} + +void delete_all() { + struct my_struct *current_user, *tmp; + + HASH_ITER(hh, users, current_user, tmp) { + HASH_DEL(users,current_user); /* delete it (users advances to next) */ + free(current_user); /* free it */ + } +} + +void print_users() { + struct my_struct *s; + + for(s=users; s != NULL; s=(struct my_struct*)(s->hh.next)) { + printf("user id %d: name %s\n", s->id, s->name); + } +} + +int name_sort(struct my_struct *a, struct my_struct *b) { + return strcmp(a->name,b->name); +} + +int id_sort(struct my_struct *a, struct my_struct *b) { + return (a->id - b->id); +} + +void sort_by_name() { + HASH_SORT(users, name_sort); +} + +void sort_by_id() { + HASH_SORT(users, id_sort); +} + +int main(int argc, char *argv[]) { + char in[10]; + int id=1, running=1; + struct my_struct *s; + unsigned num_users; + + while (running) { + printf("1. add user\n"); + printf("2. find user\n"); + printf("3. delete user\n"); + printf("4. delete all users\n"); + printf("5. sort items by name\n"); + printf("6. sort items by id\n"); + printf("7. print users\n"); + printf("8. count users\n"); + printf("9. quit\n"); + gets(in); + switch(atoi(in)) { + case 1: + printf("name?\n"); + add_user(id++, gets(in)); + break; + case 2: + printf("id?\n"); + s = find_user(atoi(gets(in))); + printf("user: %s\n", s ? s->name : "unknown"); + break; + case 3: + printf("id?\n"); + s = find_user(atoi(gets(in))); + if (s) delete_user(s); + else printf("id unknown\n"); + break; + case 4: + delete_all(); + break; + case 5: + sort_by_name(); + break; + case 6: + sort_by_id(); + break; + case 7: + print_users(); + break; + case 8: + num_users=HASH_COUNT(users); + printf("there are %u users\n", num_users); + break; + case 9: + running=0; + break; + } + } + + delete_all(); /* free any structures */ + return 0; +} +---------------------------------------------------------------------- + +This program is included in the distribution in `tests/example.c`. You can run +`make example` in that directory to compile it easily. + +Standard key types +------------------ +This section goes into specifics of how to work with different kinds of keys. +You can use nearly any type of key-- integers, strings, pointers, structures, etc. + +[NOTE] +.A note about float +================================================================================ +You can use floating point keys. This comes with the same caveats as with any +program that tests floating point equality. In other words, even the tiniest +difference in two floating point numbers makes them distinct keys. +================================================================================ + +Integer keys +~~~~~~~~~~~~ +The preceding examples demonstrated use of integer keys. To recap, use the +convenience macros `HASH_ADD_INT` and `HASH_FIND_INT` for structures with +integer keys. (The other operations such as `HASH_DELETE` and `HASH_SORT` are +the same for all types of keys). + +String keys +~~~~~~~~~~~ +If your structure has a string key, the operations to use depend on whether your +structure 'points to' the key (`char *`) or the string resides `within` the +structure (`char a[10]`). *This distinction is important*. As we'll see below, +you need to use `HASH_ADD_KEYPTR` when your structure 'points' to a key (that is, +the key itself is 'outside' of the structure); in contrast, use `HASH_ADD_STR` +for a string key that is contained *within* your structure. + +[NOTE] +.char[ ] vs. char* +================================================================================ +The string is 'within' the structure in the first example below-- `name` is a +`char[10]` field. In the second example, the key is 'outside' of the +structure-- `name` is a `char *`. So the first example uses `HASH_ADD_STR` but +the second example uses `HASH_ADD_KEYPTR`. For information on this macro, see +the <>. +================================================================================ + +String 'within' structure +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.A string-keyed hash (string within structure) +---------------------------------------------------------------------- +#include /* strcpy */ +#include /* malloc */ +#include /* printf */ +#include "uthash.h" + +struct my_struct { + char name[10]; /* key (string is WITHIN the structure) */ + int id; + UT_hash_handle hh; /* makes this structure hashable */ +}; + + +int main(int argc, char *argv[]) { + const char **n, *names[] = { "joe", "bob", "betty", NULL }; + struct my_struct *s, *tmp, *users = NULL; + int i=0; + + for (n = names; *n != NULL; n++) { + s = (struct my_struct*)malloc(sizeof(struct my_struct)); + strncpy(s->name, *n,10); + s->id = i++; + HASH_ADD_STR( users, name, s ); + } + + HASH_FIND_STR( users, "betty", s); + if (s) printf("betty's id is %d\n", s->id); + + /* free the hash table contents */ + HASH_ITER(hh, users, s, tmp) { + HASH_DEL(users, s); + free(s); + } + return 0; +} +---------------------------------------------------------------------- + +This example is included in the distribution in `tests/test15.c`. It prints: + + betty's id is 2 + +String 'pointer' in structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Now, here is the same example but using a `char *` key instead of `char [ ]`: + +.A string-keyed hash (structure points to string) +---------------------------------------------------------------------- +#include /* strcpy */ +#include /* malloc */ +#include /* printf */ +#include "uthash.h" + +struct my_struct { + const char *name; /* key */ + int id; + UT_hash_handle hh; /* makes this structure hashable */ +}; + + +int main(int argc, char *argv[]) { + const char **n, *names[] = { "joe", "bob", "betty", NULL }; + struct my_struct *s, *tmp, *users = NULL; + int i=0; + + for (n = names; *n != NULL; n++) { + s = (struct my_struct*)malloc(sizeof(struct my_struct)); + s->name = *n; + s->id = i++; + HASH_ADD_KEYPTR( hh, users, s->name, strlen(s->name), s ); + } + + HASH_FIND_STR( users, "betty", s); + if (s) printf("betty's id is %d\n", s->id); + + /* free the hash table contents */ + HASH_ITER(hh, users, s, tmp) { + HASH_DEL(users, s); + free(s); + } + return 0; +} +---------------------------------------------------------------------- + +This example is included in `tests/test40.c`. + +Pointer keys +~~~~~~~~~~~~ +Your key can be a pointer. To be very clear, this means the 'pointer itself' +can be the key (in contrast, if the thing 'pointed to' is the key, this is a +different use case handled by `HASH_ADD_KEYPTR`). + +Here is a simple example where a structure has a pointer member, called `key`. + +.A pointer key +---------------------------------------------------------------------- +#include +#include +#include "uthash.h" + +typedef struct { + void *key; + int i; + UT_hash_handle hh; +} el_t; + +el_t *hash = NULL; +char *someaddr = NULL; + +int main() { + el_t *d; + el_t *e = (el_t*)malloc(sizeof(el_t)); + if (!e) return -1; + e->key = (void*)someaddr; + e->i = 1; + HASH_ADD_PTR(hash,key,e); + HASH_FIND_PTR(hash, &someaddr, d); + if (d) printf("found\n"); + + /* release memory */ + HASH_DEL(hash,e); + free(e); + return 0; +} +---------------------------------------------------------------------- + +This example is included in `tests/test57.c`. Note that the end of the program +deletes the element out of the hash, (and since no more elements remain in the +hash), uthash releases its internal memory. + +Structure keys +~~~~~~~~~~~~~~ +Your key field can have any data type. To uthash, it is just a sequence of +bytes. Therefore, even a nested structure can be used as a key. We'll use the +general macros `HASH_ADD` and `HASH_FIND` to demonstrate. + +NOTE: Structures contain padding (wasted internal space used to fulfill +alignment requirements for the members of the structure). These padding bytes +'must be zeroed' before adding an item to the hash or looking up an item. +Therefore always zero the whole structure before setting the members of +interest. The example below does this-- see the two calls to `memset`. + +.A key which is a structure +---------------------------------------------------------------------- +#include +#include +#include "uthash.h" + +typedef struct { + char a; + int b; +} record_key_t; + +typedef struct { + record_key_t key; + /* ... other data ... */ + UT_hash_handle hh; +} record_t; + +int main(int argc, char *argv[]) { + record_t l, *p, *r, *tmp, *records = NULL; + + r = (record_t*)malloc( sizeof(record_t) ); + memset(r, 0, sizeof(record_t)); + r->key.a = 'a'; + r->key.b = 1; + HASH_ADD(hh, records, key, sizeof(record_key_t), r); + + memset(&l, 0, sizeof(record_t)); + l.key.a = 'a'; + l.key.b = 1; + HASH_FIND(hh, records, &l.key, sizeof(record_key_t), p); + + if (p) printf("found %c %d\n", p->key.a, p->key.b); + + HASH_ITER(hh, records, p, tmp) { + HASH_DEL(records, p); + free(p); + } + return 0; +} + +---------------------------------------------------------------------- + +This usage is nearly the same as use of a compound key explained below. + +Note that the general macros require the name of the `UT_hash_handle` to be +passed as the first argument (here, this is `hh`). The general macros are +documented in <>. + +Advanced Topics +--------------- + +Compound keys +~~~~~~~~~~~~~ +Your key can even comprise multiple contiguous fields. + +.A multi-field key +---------------------------------------------------------------------- +#include /* malloc */ +#include /* offsetof */ +#include /* printf */ +#include /* memset */ +#include "uthash.h" + +#define UTF32 1 + +typedef struct { + UT_hash_handle hh; + int len; + char encoding; /* these two fields */ + int text[]; /* comprise the key */ +} msg_t; + +typedef struct { + char encoding; + int text[]; +} lookup_key_t; + +int main(int argc, char *argv[]) { + unsigned keylen; + msg_t *msg, *tmp, *msgs = NULL; + lookup_key_t *lookup_key; + + int beijing[] = {0x5317, 0x4eac}; /* UTF-32LE for 北京 */ + + /* allocate and initialize our structure */ + msg = (msg_t*)malloc( sizeof(msg_t) + sizeof(beijing) ); + memset(msg, 0, sizeof(msg_t)+sizeof(beijing)); /* zero fill */ + msg->len = sizeof(beijing); + msg->encoding = UTF32; + memcpy(msg->text, beijing, sizeof(beijing)); + + /* calculate the key length including padding, using formula */ + keylen = offsetof(msg_t, text) /* offset of last key field */ + + sizeof(beijing) /* size of last key field */ + - offsetof(msg_t, encoding); /* offset of first key field */ + + /* add our structure to the hash table */ + HASH_ADD( hh, msgs, encoding, keylen, msg); + + /* look it up to prove that it worked :-) */ + msg=NULL; + + lookup_key = (lookup_key_t*)malloc(sizeof(*lookup_key) + sizeof(beijing)); + memset(lookup_key, 0, sizeof(*lookup_key) + sizeof(beijing)); + lookup_key->encoding = UTF32; + memcpy(lookup_key->text, beijing, sizeof(beijing)); + HASH_FIND( hh, msgs, &lookup_key->encoding, keylen, msg ); + if (msg) printf("found \n"); + free(lookup_key); + + HASH_ITER(hh, msgs, msg, tmp) { + HASH_DEL(msgs, msg); + free(msg); + } + return 0; +} +---------------------------------------------------------------------- + +This example is included in the distribution in `tests/test22.c`. + +If you use multi-field keys, recognize that the compiler pads adjacent fields +(by inserting unused space between them) in order to fulfill the alignment +requirement of each field. For example a structure containing a `char` followed +by an `int` will normally have 3 "wasted" bytes of padding after the char, in +order to make the `int` field start on a multiple-of-4 address (4 is the length +of the int). + +.Calculating the length of a multi-field key: +******************************************************************************* +To determine the key length when using a multi-field key, you must include any +intervening structure padding the compiler adds for alignment purposes. + +An easy way to calculate the key length is to use the `offsetof` macro from +``. The formula is: + + key length = offsetof(last_key_field) + + sizeof(last_key_field) + - offsetof(first_key_field) + +In the example above, the `keylen` variable is set using this formula. +******************************************************************************* + +When dealing with a multi-field key, you must zero-fill your structure before +`HASH_ADD`'ing it to a hash table, or using its fields in a `HASH_FIND` key. + +In the previous example, `memset` is used to initialize the structure by +zero-filling it. This zeroes out any padding between the key fields. If we +didn't zero-fill the structure, this padding would contain random values. The +random values would lead to `HASH_FIND` failures; as two "identical" keys will +appear to mismatch if there are any differences within their padding. + +[[multilevel]] +Multi-level hash tables +~~~~~~~~~~~~~~~~~~~~~~~ +A multi-level hash table arises when each element of a hash table contains its +own secondary hash table. There can be any number of levels. In a scripting +language you might see: + + $items{bob}{age}=37 + +The C program below builds this example in uthash: the hash table is called +`items`. It contains one element (`bob`) whose own hash table contains one +element (`age`) with value 37. No special functions are necessary to build +a multi-level hash table. + +While this example represents both levels (`bob` and `age`) using the same +structure, it would also be fine to use two different structure definitions. +It would also be fine if there were three or more levels instead of two. + +.Multi-level hash table +---------------------------------------------------------------------- +#include +#include +#include +#include "uthash.h" + +/* hash of hashes */ +typedef struct item { + char name[10]; + struct item *sub; + int val; + UT_hash_handle hh; +} item_t; + +item_t *items=NULL; + +int main(int argc, char *argvp[]) { + item_t *item1, *item2, *tmp1, *tmp2; + + /* make initial element */ + item_t *i = malloc(sizeof(*i)); + strcpy(i->name, "bob"); + i->sub = NULL; + i->val = 0; + HASH_ADD_STR(items, name, i); + + /* add a sub hash table off this element */ + item_t *s = malloc(sizeof(*s)); + strcpy(s->name, "age"); + s->sub = NULL; + s->val = 37; + HASH_ADD_STR(i->sub, name, s); + + /* iterate over hash elements */ + HASH_ITER(hh, items, item1, tmp1) { + HASH_ITER(hh, item1->sub, item2, tmp2) { + printf("$items{%s}{%s} = %d\n", item1->name, item2->name, item2->val); + } + } + + /* clean up both hash tables */ + HASH_ITER(hh, items, item1, tmp1) { + HASH_ITER(hh, item1->sub, item2, tmp2) { + HASH_DEL(item1->sub, item2); + free(item2); + } + HASH_DEL(items, item1); + free(item1); + } + + return 0; +} +---------------------------------------------------------------------- +The example above is included in `tests/test59.c`. + +[[multihash]] +Items in several hash tables +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +A structure can be added to more than one hash table. A few reasons you might do +this include: + +- each hash table may use an alternative key; +- each hash table may have its own sort order; +- or you might simply use multiple hash tables for grouping purposes. E.g., + you could have users in an `admin_users` and a `users` hash table. + +Your structure needs to have a `UT_hash_handle` field for each hash table to +which it might be added. You can name them anything. E.g., + + UT_hash_handle hh1, hh2; + +Items with alternative keys +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +You might create a hash table keyed on an ID field, and another hash table keyed +on username (if usernames are unique). You can add the same user structure to +both hash tables (without duplication of the structure), allowing lookup of a +user structure by their name or ID. The way to achieve this is to have a +separate `UT_hash_handle` for each hash to which the structure may be added. + +.A structure with two alternative keys +---------------------------------------------------------------------- +struct my_struct { + int id; /* usual key */ + char username[10]; /* alternative key */ + UT_hash_handle hh1; /* handle for first hash table */ + UT_hash_handle hh2; /* handle for second hash table */ +}; +---------------------------------------------------------------------- + +In the example above, the structure can now be added to two separate hash +tables. In one hash, `id` is its key, while in the other hash, `username` is +its key. (There is no requirement that the two hashes have different key +fields. They could both use the same key, such as `id`). + +Notice the structure has two hash handles (`hh1` and `hh2`). In the code +below, notice that each hash handle is used exclusively with a particular hash +table. (`hh1` is always used with the `users_by_id` hash, while `hh2` is +always used with the `users_by_name` hash table). + +.Two keys on a structure +---------------------------------------------------------------------- + struct my_struct *users_by_id = NULL, *users_by_name = NULL, *s; + int i; + char *name; + + s = malloc(sizeof(struct my_struct)); + s->id = 1; + strcpy(s->username, "thanson"); + + /* add the structure to both hash tables */ + HASH_ADD(hh1, users_by_id, id, sizeof(int), s); + HASH_ADD(hh2, users_by_name, username, strlen(s->username), s); + + /* lookup user by ID in the "users_by_id" hash table */ + i=1; + HASH_FIND(hh1, users_by_id, &i, sizeof(int), s); + if (s) printf("found id %d: %s\n", i, s->username); + + /* lookup user by username in the "users_by_name" hash table */ + name = "thanson"; + HASH_FIND(hh2, users_by_name, name, strlen(name), s); + if (s) printf("found user %s: %d\n", name, s->id); +---------------------------------------------------------------------- + + +Several sort orders +~~~~~~~~~~~~~~~~~~~ +It comes as no suprise that two hash tables can have different sort orders, but +this fact can also be used advantageously to sort the 'same items' in several +ways. This is based on the ability to store a structure in several hash tables. + +Extending the previous example, suppose we have many users. We have added each +user structure to the `users_by_id` hash table and the `users_by_name` hash table. +(To reiterate, this is done without the need to have two copies of each structure). +Now we can define two sort functions, then use `HASH_SRT`. + + int sort_by_id(struct my_struct *a, struct my_struct *b) { + if (a->id == b->id) return 0; + return (a->id < b->id) ? -1 : 1; + } + + int sort_by_name(struct my_struct *a, struct my_struct *b) { + return strcmp(a->username,b->username); + } + + HASH_SRT(hh1, users_by_id, sort_by_id); + HASH_SRT(hh2, users_by_name, sort_by_name); + +Now iterating over the items in `users_by_id` will traverse them in id-order +while, naturally, iterating over `users_by_name` will traverse them in +name-order. The items are fully forward-and-backward linked in each order. +So even for one set of users, we might store them in two hash tables to provide +easy iteration in two different sort orders. + +Bloom filter (faster misses) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Programs that generate a fair miss rate (`HASH_FIND` that result in `NULL`) may +benefit from the built-in Bloom filter support. This is disabled by default, +because programs that generate only hits would incur a slight penalty from it. +Also, programs that do deletes should not use the Bloom filter. While the +program would operate correctly, deletes diminish the benefit of the filter. +To enable the Bloom filter, simply compile with `-DHASH_BLOOM=n` like: + + -DHASH_BLOOM=27 + +where the number can be any value up to 32 which determines the amount of memory +used by the filter, as shown below. Using more memory makes the filter more +accurate and has the potential to speed up your program by making misses bail +out faster. + +.Bloom filter sizes for selected values of n +[width="50%",cols="10m,30",grid="none",options="header"] +|===================================================================== +| n | Bloom filter size (per hash table) +| 16 | 8 kilobytes +| 20 | 128 kilobytes +| 24 | 2 megabytes +| 28 | 32 megabytes +| 32 | 512 megabytes +|===================================================================== + +Bloom filters are only a performance feature; they do not change the results of +hash operations in any way. The only way to gauge whether or not a Bloom filter +is right for your program is to test it. Reasonable values for the size of the +Bloom filter are 16-32 bits. + +Select +~~~~~~ +An experimental 'select' operation is provided that inserts those items from a +source hash that satisfy a given condition into a destination hash. This +insertion is done with somewhat more efficiency than if this were using +`HASH_ADD`, namely because the hash function is not recalculated for keys of the +selected items. This operation does not remove any items from the source hash. +Rather the selected items obtain dual presence in both hashes. The destination +hash may already have items in it; the selected items are added to it. In order +for a structure to be usable with `HASH_SELECT`, it must have two or more hash +handles. (As described <>, a structure can exist in many +hash tables at the same time; it must have a separate hash handle for each one). + + user_t *users=NULL, *admins=NULL; /* two hash tables */ + + typedef struct { + int id; + UT_hash_handle hh; /* handle for users hash */ + UT_hash_handle ah; /* handle for admins hash */ + } user_t; + +Now suppose we have added some users, and want to select just the administrator +users who have id's less than 1024. + + #define is_admin(x) (((user_t*)x)->id < 1024) + HASH_SELECT(ah,admins,hh,users,is_admin); + +The first two parameters are the 'destination' hash handle and hash table, the +second two parameters are the 'source' hash handle and hash table, and the last +parameter is the 'select condition'. Here we used a macro `is_admin()` but we +could just as well have used a function. + + int is_admin(void *userv) { + user_t *user = (user_t*)userv; + return (user->id < 1024) ? 1 : 0; + } + +If the select condition always evaluates to true, this operation is +essentially a 'merge' of the source hash into the destination hash. Of course, +the source hash remains unchanged under any use of `HASH_SELECT`. It only adds +items to the destination hash selectively. + +The two hash handles must differ. An example of using `HASH_SELECT` is included +in `tests/test36.c`. + + +[[hash_functions]] +Built-in hash functions +~~~~~~~~~~~~~~~~~~~~~~~ +Internally, a hash function transforms a key into a bucket number. You don't +have to take any action to use the default hash function, currently Jenkin's. + +Some programs may benefit from using another of the built-in hash functions. +There is a simple analysis utility included with uthash to help you determine +if another hash function will give you better performance. + +You can use a different hash function by compiling your program with +`-DHASH_FUNCTION=HASH_xyz` where `xyz` is one of the symbolic names listed +below. E.g., + + cc -DHASH_FUNCTION=HASH_BER -o program program.c + +.Built-in hash functions +[width="50%",cols="^5m,20",grid="none",options="header"] +|=============================================================================== +|Symbol | Name +|JEN | Jenkins (default) +|BER | Bernstein +|SAX | Shift-Add-Xor +|OAT | One-at-a-time +|FNV | Fowler/Noll/Vo +|SFH | Paul Hsieh +|MUR | MurmurHash v3 (see note) +|=============================================================================== + +[NOTE] +.MurmurHash +================================================================================ +A special symbol must be defined if you intend to use MurmurHash. To use it, add +`-DHASH_USING_NO_STRICT_ALIASING` to your `CFLAGS`. And, if you are using +the gcc compiler with optimization, add `-fno-strict-aliasing` to your `CFLAGS`. +================================================================================ + +Which hash function is best? +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +You can easily determine the best hash function for your key domain. To do so, +you'll need to run your program once in a data-collection pass, and then run +the collected data through an included analysis utility. + +First you must build the analysis utility. From the top-level directory, + + cd tests/ + make + +We'll use `test14.c` to demonstrate the data-collection and analysis steps +(here using `sh` syntax to redirect file descriptor 3 to a file): + +.Using keystats +-------------------------------------------------------------------------------- +% cc -DHASH_EMIT_KEYS=3 -I../src -o test14 test14.c +% ./test14 3>test14.keys +% ./keystats test14.keys +fcn ideal% #items #buckets dup% fl add_usec find_usec del-all usec +--- ------ ---------- ---------- ----- -- ---------- ---------- ------------ +SFH 91.6% 1219 256 0% ok 92 131 25 +FNV 90.3% 1219 512 0% ok 107 97 31 +SAX 88.7% 1219 512 0% ok 111 109 32 +OAT 87.2% 1219 256 0% ok 99 138 26 +JEN 86.7% 1219 256 0% ok 87 130 27 +BER 86.2% 1219 256 0% ok 121 129 27 +-------------------------------------------------------------------------------- + +[NOTE] +The number 3 in `-DHASH_EMIT_KEYS=3` is a file descriptor. Any file descriptor +that your program doesn't use for its own purposes can be used instead of 3. +The data-collection mode enabled by `-DHASH_EMIT_KEYS=x` should not be used in +production code. + +Usually, you should just pick the first hash function that is listed. Here, this +is `SFH`. This is the function that provides the most even distribution for +your keys. If several have the same `ideal%`, then choose the fastest one +according to the `find_usec` column. + +keystats column reference +^^^^^^^^^^^^^^^^^^^^^^^^^ +fcn:: + symbolic name of hash function +ideal%:: + The percentage of items in the hash table which can be looked up within an + ideal number of steps. (Further explained below). +#items:: + the number of keys that were read in from the emitted key file +#buckets:: + the number of buckets in the hash after all the keys were added +dup%:: + the percent of duplicate keys encountered in the emitted key file. + Duplicates keys are filtered out to maintain key uniqueness. (Duplicates + are normal. For example, if the application adds an item to a hash, + deletes it, then re-adds it, the key is written twice to the emitted file.) +flags:: + this is either `ok`, or `nx` (noexpand) if the expansion inhibited flag is + set, described in <>. It is not recommended + to use a hash function that has the `noexpand` flag set. +add_usec:: + the clock time in microseconds required to add all the keys to a hash +find_usec:: + the clock time in microseconds required to look up every key in the hash +del-all usec:: + the clock time in microseconds required to delete every item in the hash + +[[ideal]] +ideal% +^^^^^^ + +.What is ideal%? +***************************************************************************** +The 'n' items in a hash are distributed into 'k' buckets. Ideally each bucket +would contain an equal share '(n/k)' of the items. In other words, the maximum +linear position of any item in a bucket chain would be 'n/k' if every bucket is +equally used. If some buckets are overused and others are underused, the +overused buckets will contain items whose linear position surpasses 'n/k'. +Such items are considered non-ideal. + +As you might guess, `ideal%` is the percentage of ideal items in the hash. These +items have favorable linear positions in their bucket chains. As `ideal%` +approaches 100%, the hash table approaches constant-time lookup performance. +***************************************************************************** + +[[hashscan]] +hashscan +~~~~~~~~ +NOTE: This utility is only available on Linux, and on FreeBSD (8.1 and up). + +A utility called `hashscan` is included in the `tests/` directory. It +is built automatically when you run `make` in that directory. This tool +examines a running process and reports on the uthash tables that it finds in +that program's memory. It can also save the keys from each table in a format +that can be fed into `keystats`. + +Here is an example of using `hashscan`. First ensure that it is built: + + cd tests/ + make + +Since `hashscan` needs a running program to inspect, we'll start up a simple +program that makes a hash table and then sleeps as our test subject: + + ./test_sleep & + pid: 9711 + +Now that we have a test program, let's run `hashscan` on it: + + ./hashscan 9711 + Address ideal items buckets mc fl bloom/sat fcn keys saved to + ------------------ ----- -------- -------- -- -- --------- --- ------------- + 0x862e038 81% 10000 4096 11 ok 16 14% JEN + +If we wanted to copy out all its keys for external analysis using `keystats`, +add the `-k` flag: + + ./hashscan -k 9711 + Address ideal items buckets mc fl bloom/sat fcn keys saved to + ------------------ ----- -------- -------- -- -- --------- --- ------------- + 0x862e038 81% 10000 4096 11 ok 16 14% JEN /tmp/9711-0.key + +Now we could run `./keystats /tmp/9711-0.key` to analyze which hash function +has the best characteristics on this set of keys. + +hashscan column reference +^^^^^^^^^^^^^^^^^^^^^^^^^ +Address:: + virtual address of the hash table +ideal:: + The percentage of items in the table which can be looked up within an ideal + number of steps. See <> in the `keystats` section. +items:: + number of items in the hash table +buckets:: + number of buckets in the hash table +mc:: + the maximum chain length found in the hash table (uthash usually tries to + keep fewer than 10 items in each bucket, or in some cases a multiple of 10) +fl:: + flags (either `ok`, or `NX` if the expansion-inhibited flag is set) +bloom/sat:: + if the hash table uses a Bloom filter, this is the size (as a power of two) + of the filter (e.g. 16 means the filter is 2^16 bits in size). The second + number is the "saturation" of the bits expressed as a percentage. The lower + the percentage, the more potential benefit to identify cache misses quickly. +fcn:: + symbolic name of hash function +keys saved to:: + file to which keys were saved, if any + +.How hashscan works +***************************************************************************** +When hashscan runs, it attaches itself to the target process, which suspends +the target process momentarily. During this brief suspension, it scans the +target's virtual memory for the signature of a uthash hash table. It then +checks if a valid hash table structure accompanies the signature and reports +what it finds. When it detaches, the target process resumes running normally. +The hashscan is performed "read-only"-- the target process is not modified. +Since hashscan is analyzing a momentary snapshot of a running process, it may +return different results from one run to another. +***************************************************************************** + +[[expansion]] +Expansion internals +~~~~~~~~~~~~~~~~~~~ +Internally this hash manages the number of buckets, with the goal of having +enough buckets so that each one contains only a small number of items. + +.Why does the number of buckets matter? +******************************************************************************** +When looking up an item by its key, this hash scans linearly through the items +in the appropriate bucket. In order for the linear scan to run in constant +time, the number of items in each bucket must be bounded. This is accomplished +by increasing the number of buckets as needed. +******************************************************************************** + +Normal expansion +^^^^^^^^^^^^^^^^ +This hash attempts to keep fewer than 10 items in each bucket. When an item is +added that would cause a bucket to exceed this number, the number of buckets in +the hash is doubled and the items are redistributed into the new buckets. In an +ideal world, each bucket will then contain half as many items as it did before. + +Bucket expansion occurs automatically and invisibly as needed. There is +no need for the application to know when it occurs. + +Per-bucket expansion threshold +++++++++++++++++++++++++++++++ +Normally all buckets share the same threshold (10 items) at which point bucket +expansion is triggered. During the process of bucket expansion, uthash can +adjust this expansion-trigger threshold on a per-bucket basis if it sees that +certain buckets are over-utilized. + +When this threshold is adjusted, it goes from 10 to a multiple of 10 (for that +particular bucket). The multiple is based on how many times greater the actual +chain length is than the ideal length. It is a practical measure to reduce +excess bucket expansion in the case where a hash function over-utilizes a few +buckets but has good overall distribution. However, if the overall distribution +gets too bad, uthash changes tactics. + +Inhibited expansion +^^^^^^^^^^^^^^^^^^^ +You usually don't need to know or worry about this, particularly if you used +the `keystats` utility during development to select a good hash for your keys. + +A hash function may yield an uneven distribution of items across the buckets. +In moderation this is not a problem. Normal bucket expansion takes place as +the chain lengths grow. But when significant imbalance occurs (because the hash +function is not well suited to the key domain), bucket expansion may be +ineffective at reducing the chain lengths. + +Imagine a very bad hash function which always puts every item in bucket 0. No +matter how many times the number of buckets is doubled, the chain length of +bucket 0 stays the same. In a situation like this, the best behavior is to +stop expanding, and accept O(n) lookup performance. This is what uthash +does. It degrades gracefully if the hash function is ill-suited to the keys. + +If two consecutive bucket expansions yield `ideal%` values below 50%, uthash +inhibits expansion for that hash table. Once set, the 'bucket expansion +inhibited' flag remains in effect as long as the hash has items in it. +Inhibited expansion may cause `HASH_FIND` to exhibit worse than constant-time +performance. + +Hooks +~~~~~ +You don't need to use these hooks- they are only here if you want to modify +the behavior of uthash. Hooks can be used to change how uthash allocates +memory, and to run code in response to certain internal events. + +malloc/free +^^^^^^^^^^^ +By default this hash implementation uses `malloc` and `free` to manage memory. +If your application uses its own custom allocator, this hash can use them too. + +.Specifying alternate memory management functions +---------------------------------------------------------------------------- +#include "uthash.h" + +/* undefine the defaults */ +#undef uthash_malloc +#undef uthash_free + +/* re-define, specifying alternate functions */ +#define uthash_malloc(sz) my_malloc(sz) +#define uthash_free(ptr,sz) my_free(ptr) + +... +---------------------------------------------------------------------------- + +Notice that `uthash_free` receives two parameters. The `sz` parameter is for +convenience on embedded platforms that manage their own memory. + +Out of memory +^^^^^^^^^^^^^ +If memory allocation fails (i.e., the malloc function returned `NULL`), the +default behavior is to terminate the process by calling `exit(-1)`. This can +be modified by re-defining the `uthash_fatal` macro. + + #undef uthash_fatal + #define uthash_fatal(msg) my_fatal_function(msg); + +The fatal function should terminate the process or `longjmp` back to a safe +place. Uthash does not support "returning a failure" if memory cannot be +allocated. + +Internal events +^^^^^^^^^^^^^^^ +There is no need for the application to set these hooks or take action in +response to these events. They are mainly for diagnostic purposes. + +These two hooks are "notification" hooks which get executed if uthash is +expanding buckets, or setting the 'bucket expansion inhibited' flag. Normally +both of these hooks are undefined and thus compile away to nothing. + +Expansion ++++++++++ +There is a hook for the bucket expansion event. + +.Bucket expansion hook +---------------------------------------------------------------------------- +#include "uthash.h" + +#undef uthash_expand_fyi +#define uthash_expand_fyi(tbl) printf("expanded to %d buckets\n", tbl->num_buckets) + +... +---------------------------------------------------------------------------- + +Expansion-inhibition +++++++++++++++++++++ +This hook can be defined to code to execute in the event that uthash decides to +set the 'bucket expansion inhibited' flag. + +.Bucket expansion inhibited hook +---------------------------------------------------------------------------- +#include "uthash.h" + +#undef uthash_noexpand_fyi +#define uthash_noexpand_fyi printf("warning: bucket expansion inhibited\n"); + +... +---------------------------------------------------------------------------- + + +Debug mode +~~~~~~~~~~ +If a program that uses this hash is compiled with `-DHASH_DEBUG=1`, a special +internal consistency-checking mode is activated. In this mode, the integrity +of the whole hash is checked following every add or delete operation. This is +for debugging the uthash software only, not for use in production code. + +In the `tests/` directory, running `make debug` will run all the tests in +this mode. + +In this mode, any internal errors in the hash data structure will cause a +message to be printed to `stderr` and the program to exit. + +The `UT_hash_handle` data structure includes `next`, `prev`, `hh_next` and +`hh_prev` fields. The former two fields determine the "application" ordering +(that is, insertion order-- the order the items were added). The latter two +fields determine the "bucket chain" order. These link the `UT_hash_handles` +together in a doubly-linked list that is a bucket chain. + +Checks performed in `-DHASH_DEBUG=1` mode: + +- the hash is walked in its entirety twice: once in 'bucket' order and a + second time in 'application' order +- the total number of items encountered in both walks is checked against the + stored number +- during the walk in 'bucket' order, each item's `hh_prev` pointer is compared + for equality with the last visited item +- during the walk in 'application' order, each item's `prev` pointer is compared + for equality with the last visited item + +.Macro debugging: +******************************************************************************** +Sometimes it's difficult to interpret a compiler warning on a line which +contains a macro call. In the case of uthash, one macro can expand to dozens of +lines. In this case, it is helpful to expand the macros and then recompile. +By doing so, the warning message will refer to the exact line within the macro. + +Here is an example of how to expand the macros and then recompile. This uses the +`test1.c` program in the `tests/` subdirectory. + + gcc -E -I../src test1.c > /tmp/a.c + egrep -v '^#' /tmp/a.c > /tmp/b.c + indent /tmp/b.c + gcc -o /tmp/b /tmp/b.c + +The last line compiles the original program (test1.c) with all macros expanded. +If there was a warning, the referenced line number can be checked in `/tmp/b.c`. +******************************************************************************** + +Thread safety +~~~~~~~~~~~~~ +You can use uthash in a threaded program. But you must do the locking. Use a +read-write lock to protect against concurrent writes. It is ok to have +concurrent readers (since uthash 1.5). + +For example using pthreads you can create an rwlock like this: + + pthread_rwlock_t lock; + if (pthread_rwlock_init(&lock,NULL) != 0) fatal("can't create rwlock"); + +Then, readers must acquire the read lock before doing any `HASH_FIND` calls or +before iterating over the hash elements: + + if (pthread_rwlock_rdlock(&lock) != 0) fatal("can't get rdlock"); + HASH_FIND_INT(elts, &i, e); + pthread_rwlock_unlock(&lock); + +Writers must acquire the exclusive write lock before doing any update. Add, +delete, and sort are all updates that must be locked. + + if (pthread_rwlock_wrlock(&lock) != 0) fatal("can't get wrlock"); + HASH_DEL(elts, e); + pthread_rwlock_unlock(&lock); + +If you prefer, you can use a mutex instead of a read-write lock, but this will +reduce reader concurrency to a single thread at a time. + +An example program using uthash with a read-write lock is included in +`tests/threads/test1.c`. + +[[Macro_reference]] +Macro reference +--------------- + +Convenience macros +~~~~~~~~~~~~~~~~~~ +The convenience macros do the same thing as the generalized macros, but +require fewer arguments. + +In order to use the convenience macros, + +1. the structure's `UT_hash_handle` field must be named `hh`, and +2. for add or find, the key field must be of type `int` or `char[]` or pointer + +.Convenience macros +[width="90%",cols="10m,30m",grid="none",options="header"] +|=============================================================================== +|macro | arguments +|HASH_ADD_INT | (head, keyfield_name, item_ptr) +|HASH_FIND_INT | (head, key_ptr, item_ptr) +|HASH_ADD_STR | (head, keyfield_name, item_ptr) +|HASH_FIND_STR | (head, key_ptr, item_ptr) +|HASH_ADD_PTR | (head, keyfield_name, item_ptr) +|HASH_FIND_PTR | (head, key_ptr, item_ptr) +|HASH_DEL | (head, item_ptr) +|HASH_SORT | (head, cmp) +|HASH_COUNT | (head) +|=============================================================================== + +General macros +~~~~~~~~~~~~~~ + +These macros add, find, delete and sort the items in a hash. You need to +use the general macros if your `UT_hash_handle` is named something other +than `hh`, or if your key's data type isn't `int` or `char[]`. + +.General macros +[width="90%",cols="10m,30m",grid="none",options="header"] +|=============================================================================== +|macro | arguments +|HASH_ADD | (hh_name, head, keyfield_name, key_len, item_ptr) +|HASH_ADD_KEYPTR| (hh_name, head, key_ptr, key_len, item_ptr) +|HASH_FIND | (hh_name, head, key_ptr, key_len, item_ptr) +|HASH_DELETE | (hh_name, head, item_ptr) +|HASH_SRT | (hh_name, head, cmp) +|HASH_CNT | (hh_name, head) +|HASH_CLEAR | (hh_name, head) +|HASH_SELECT | (dst_hh_name, dst_head, src_hh_name, src_head, condition) +|HASH_ITER | (hh_name, head, item_ptr, tmp_item_ptr) +|=============================================================================== + +[NOTE] +`HASH_ADD_KEYPTR` is used when the structure contains a pointer to the +key, rather than the key itself. + + +Argument descriptions +^^^^^^^^^^^^^^^^^^^^^ +hh_name:: + name of the `UT_hash_handle` field in the structure. Conventionally called + `hh`. +head:: + the structure pointer variable which acts as the "head" of the hash. So + named because it initially points to the first item that is added to the hash. +keyfield_name:: + the name of the key field in the structure. (In the case of a multi-field + key, this is the first field of the key). If you're new to macros, it + might seem strange to pass the name of a field as a parameter. See + <>. +key_len:: + the length of the key field in bytes. E.g. for an integer key, this is + `sizeof(int)`, while for a string key it's `strlen(key)`. (For a + multi-field key, see the notes in this guide on calculating key length). +key_ptr:: + for `HASH_FIND`, this is a pointer to the key to look up in the hash + (since it's a pointer, you can't directly pass a literal value here). For + `HASH_ADD_KEYPTR`, this is the address of the key of the item being added. +item_ptr:: + pointer to the structure being added, deleted, or looked up, or the current + pointer during iteration. This is an input parameter for `HASH_ADD` and + `HASH_DELETE` macros, and an output parameter for `HASH_FIND` and + `HASH_ITER`. (When using `HASH_ITER` to iterate, `tmp_item_ptr` + is another variable of the same type as `item_ptr`, used internally). +cmp:: + pointer to comparison function which accepts two arguments (pointers to + items to compare) and returns an int specifying whether the first item + should sort before, equal to, or after the second item (like `strcmp`). +condition:: + a function or macro which accepts a single argument-- a void pointer to a + structure, which needs to be cast to the appropriate structure type. The + function or macro should return (or evaluate to) a non-zero value if the + structure should be "selected" for addition to the destination hash. + +// vim: set tw=80 wm=2 syntax=asciidoc: + diff --git a/apps/systemlib/uthash/doc/utarray.txt b/apps/systemlib/uthash/doc/utarray.txt new file mode 100644 index 0000000000..37830f1244 --- /dev/null +++ b/apps/systemlib/uthash/doc/utarray.txt @@ -0,0 +1,376 @@ +utarray: dynamic array macros for C +=================================== +Troy D. Hanson +v1.9.5, November 2011 + +include::sflogo.txt[] +include::topnav_utarray.txt[] + +Introduction +------------ +include::toc.txt[] + +A set of general-purpose dynamic array macros for C structures are included with +uthash in `utarray.h`. To use these macros in your own C program, just +copy `utarray.h` into your source directory and use it in your programs. + + #include "utarray.h" + +The dynamic array supports basic operations such as push, pop, and erase on the +array elements. These array elements can be any simple datatype or structure. +The array <> are based loosely on the C++ STL vector methods. + +Internally the dynamic array contains a contiguous memory region into which +the elements are copied. This buffer is grown as needed using `realloc` to +accomodate all the data that is pushed into it. + +Download +~~~~~~~~ +To download the `utarray.h` header file, follow the link on the +http://uthash.sourceforge.net[uthash home page]. + +BSD licensed +~~~~~~~~~~~~ +This software is made available under the +link:license.html[revised BSD license]. +It is free and open source. + +Platforms +~~~~~~~~~ +The 'utarray' macros have been tested on: + + * Linux, + * Mac OS X, + * Windows, using Visual Studio 2008 and Visual Studio 2010 + +Usage +----- + +Declaration +~~~~~~~~~~~ + +The array itself has the data type `UT_array`, regardless of the type of +elements to be stored in it. It is declared like, + + UT_array *nums; + +New and free +~~~~~~~~~~~~ +The next step is to create the array using `utarray_new`. Later when you're +done with the array, `utarray_free` will free it and all its elements. + +Push, pop, etc +~~~~~~~~~~~~~~ +The central features of the utarray involve putting elements into it, taking +them out, and iterating over them. There are several <> +to pick from that deal with either single elements or ranges of elements at a +time. In the examples below we will use only the push operation to insert +elements. + +Elements +-------- + +Support for dynamic arrays of integers or strings is especially easy. These are +best shown by example: + +Integers +~~~~~~~~ +This example makes a utarray of integers, pushes 0-9 into it, then prints it. +Lastly it frees it. + +.Integer elements +------------------------------------------------------------------------------- +#include +#include "utarray.h" + +int main() { + UT_array *nums; + int i, *p; + + utarray_new(nums,&ut_int_icd); + for(i=0; i < 10; i++) utarray_push_back(nums,&i); + + for(p=(int*)utarray_front(nums); + p!=NULL; + p=(int*)utarray_next(nums,p)) { + printf("%d\n",*p); + } + + utarray_free(nums); + + return 0; +} +------------------------------------------------------------------------------- + +The second argument to `utarray_push_back` is always a 'pointer' to the type +(so a literal cannot be used). So for integers, it is an `int*`. + +Strings +~~~~~~~ +In this example we make a utarray of strings, push two strings into it, print +it and free it. + +.String elements +------------------------------------------------------------------------------- +#include +#include "utarray.h" + +int main() { + UT_array *strs; + char *s, **p; + + utarray_new(strs,&ut_str_icd); + + s = "hello"; utarray_push_back(strs, &s); + s = "world"; utarray_push_back(strs, &s); + p = NULL; + while ( (p=(char**)utarray_next(strs,p))) { + printf("%s\n",*p); + } + + utarray_free(strs); + + return 0; +} +------------------------------------------------------------------------------- + +In this example, since the element is a `char*`, we pass a pointer to it +(`char**`) as the second argument to `utarray_push_back`. Note that "push" makes +a copy of the source string and pushes that copy into the array. + +About UT_icd +~~~~~~~~~~~~ + +Arrays be made of any type of element, not just integers and strings. The +elements can be basic types or structures. Unless you're dealing with integers +and strings (which use pre-defined `ut_int_icd` and `ut_str_icd`), you'll need +to define a `UT_icd` helper structure. This structure contains everything that +utarray needs to initialize, copy or destruct elements. + + typedef struct { + size_t sz; + init_f *init; + ctor_f *copy; + dtor_f *dtor; + } UT_icd; + +The three function pointers `init`, `copy`, and `dtor` have these prototypes: + + typedef void (ctor_f)(void *dst, const void *src); + typedef void (dtor_f)(void *elt); + typedef void (init_f)(void *elt); + +The `sz` is just the size of the element being stored in the array. + +The `init` function will be invoked whenever utarray needs to initialize an +empty element. This only happens as a byproduct of `utarray_resize` or +`utarray_extend_back`. If `init` is `NULL`, it defaults to zero filling the +new element using memset. + +The `copy` function is used whenever an element is copied into the array. +It is invoked during `utarray_push_back`, `utarray_insert`, `utarray_inserta`, +or `utarray_concat`. If `copy` is `NULL`, it defaults to a bitwise copy using +memcpy. + +The `dtor` function is used to clean up an element that is being removed from +the array. It may be invoked due to `utarray_resize`, `utarray_pop_back`, +`utarray_erase`, `utarray_clear`, `utarray_done` or `utarray_free`. If the +elements need no cleanup upon destruction, `dtor` may be `NULL`. + +Scalar types +~~~~~~~~~~~~ + +The next example uses `UT_icd` with all its defaults to make a utarray of +`long` elements. This example pushes two longs, prints them, and frees the +array. + +.long elements +------------------------------------------------------------------------------- +#include +#include "utarray.h" + +UT_icd long_icd = {sizeof(long), NULL, NULL, NULL }; + +int main() { + UT_array *nums; + long l, *p; + utarray_new(nums, &long_icd); + + l=1; utarray_push_back(nums, &l); + l=2; utarray_push_back(nums, &l); + + p=NULL; + while( (p=(long*)utarray_next(nums,p))) printf("%ld\n", *p); + + utarray_free(nums); + return 0; +} +------------------------------------------------------------------------------- + +Structures +~~~~~~~~~~ + +Structures can be used as utarray elements. If the structure requires no +special effort to initialize, copy or destruct, we can use `UT_icd` with all +its defaults. This example shows a structure that consists of two integers. Here +we push two values, print them and free the array. + +.Structure (simple) +------------------------------------------------------------------------------- +#include +#include "utarray.h" + +typedef struct { + int a; + int b; +} intpair_t; + +UT_icd intpair_icd = {sizeof(intpair_t), NULL, NULL, NULL}; + +int main() { + + UT_array *pairs; + intpair_t ip, *p; + utarray_new(pairs,&intpair_icd); + + ip.a=1; ip.b=2; utarray_push_back(pairs, &ip); + ip.a=10; ip.b=20; utarray_push_back(pairs, &ip); + + for(p=(intpair_t*)utarray_front(pairs); + p!=NULL; + p=(intpair_t*)utarray_next(pairs,p)) { + printf("%d %d\n", p->a, p->b); + } + + utarray_free(pairs); + return 0; +} +------------------------------------------------------------------------------- + +The real utility of `UT_icd` is apparent when the elements of the utarray are +structures that require special work to initialize, copy or destruct. + +For example, when a structure contains pointers to related memory areas that +need to be copied when the structure is copied (and freed when the structure is +freed), we can use custom `init`, `copy`, and `dtor` members in the `UT_icd`. + +Here we take an example of a structure that contains an integer and a string. +When this element is copied (such as when an element is pushed into the array), +we want to "deep copy" the `s` pointer (so the original element and the new +element point to their own copies of `s`). When an element is destructed, we +want to "deep free" its copy of `s`. Lastly, this example is written to work +even if `s` has the value `NULL`. + +.Structure (complex) +------------------------------------------------------------------------------- +#include +#include +#include "utarray.h" + +typedef struct { + int a; + char *s; +} intchar_t; + +void intchar_copy(void *_dst, const void *_src) { + intchar_t *dst = (intchar_t*)_dst, *src = (intchar_t*)_src; + dst->a = src->a; + dst->s = src->s ? strdup(src->s) : NULL; +} + +void intchar_dtor(void *_elt) { + intchar_t *elt = (intchar_t*)_elt; + if (elt->s) free(elt->s); +} + +UT_icd intchar_icd = {sizeof(intchar_t), NULL, intchar_copy, intchar_dtor}; + +int main() { + UT_array *intchars; + intchar_t ic, *p; + utarray_new(intchars, &intchar_icd); + + ic.a=1; ic.s="hello"; utarray_push_back(intchars, &ic); + ic.a=2; ic.s="world"; utarray_push_back(intchars, &ic); + + p=NULL; + while( (p=(intchar_t*)utarray_next(intchars,p))) { + printf("%d %s\n", p->a, (p->s ? p->s : "null")); + } + + utarray_free(intchars); + return 0; +} + +------------------------------------------------------------------------------- + +[[operations]] +Reference +--------- +This table lists all the utarray operations. These are loosely based on the C++ +vector class. + +Operations +~~~~~~~~~~ + +[width="100%",cols="50 +v1.9.5, November 2011 + +include::sflogo.txt[] +include::topnav_utlist.txt[] + +Introduction +------------ +include::toc.txt[] + +A set of general-purpose 'linked list' macros for C structures are included with +uthash in `utlist.h`. To use these macros in your own C program, just +copy `utlist.h` into your source directory and use it in your programs. + + #include "utlist.h" + +These macros support the basic linked list operations: adding and deleting +elements, sorting them and iterating over them. + +Download +~~~~~~~~ +To download the `utlist.h` header file, follow the link on the +http://uthash.sourceforge.net[uthash home page]. + +BSD licensed +~~~~~~~~~~~~ +This software is made available under the +link:license.html[revised BSD license]. +It is free and open source. + +Platforms +~~~~~~~~~ +The 'utlist' macros have been tested on: + + * Linux, + * Mac OS X, and + * Windows, using Visual Studio 2008, Visual Studio 2010, or Cygwin/MinGW. + +Using utlist +------------ + +Types of lists +~~~~~~~~~~~~~~ +Three types of linked lists are supported: + +- *singly-linked* lists, +- *doubly-linked* lists, and +- *circular, doubly-linked* lists + +Efficiency +^^^^^^^^^^ +For all types of lists, prepending elements and deleting elements are +constant-time operations. Appending to a singly-linked list is an 'O(n)' +operation but appending to a doubly-linked list is constant time using these +macros. (This is because, in the utlist implementation of the doubly-linked +list, the head element's `prev` member points back to the list tail, even when +the list is non-circular). Sorting is an 'O(n log(n))' operation. Iteration +and searching are `O(n)` for all list types. + +List elements +~~~~~~~~~~~~~ +You can use any structure with these macros, as long as the structure +contains a `next` pointer. If you want to make a doubly-linked list, +the element also needs to have a `prev` pointer. + + typedef struct element { + char *name; + struct element *prev; /* needed for a doubly-linked list only */ + struct element *next; /* needed for singly- or doubly-linked lists */ + } element; + +You can name your structure anything. In the example above it is called `element`. +Within a particular list, all elements must be of the same type. + +List head +~~~~~~~~~ +The list head is simply a pointer to your element structure. You can name it +anything. *It must be initialized to `NULL`*. + + element *head = NULL; + +List operations +~~~~~~~~~~~~~~~ +The lists support inserting or deleting elements, sorting the elements and +iterating over them. + +[width="100%",cols="10 +#include +#include +#include "utlist.h" + +#define BUFLEN 20 + +typedef struct el { + char bname[BUFLEN]; + struct el *next, *prev; +} el; + +int namecmp(el *a, el *b) { + return strcmp(a->bname,b->bname); +} + +el *head = NULL; /* important- initialize to NULL! */ + +int main(int argc, char *argv[]) { + el *name, *elt, *tmp, etmp; + + char linebuf[BUFLEN]; + FILE *file; + + if ( (file = fopen( "test11.dat", "r" )) == NULL ) { + perror("can't open: "); + exit(-1); + } + + while (fgets(linebuf,BUFLEN,file) != NULL) { + if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1); + strncpy(name->bname,linebuf,BUFLEN); + DL_APPEND(head, name); + } + DL_SORT(head, namecmp); + DL_FOREACH(head,elt) printf("%s", elt->bname); + + memcpy(&etmp.bname, "WES\n", 5); + DL_SEARCH(head,elt,&etmp,namecmp); + if (elt) printf("found %s\n", elt->bname); + + /* now delete each element, use the safe iterator */ + DL_FOREACH_SAFE(head,elt,tmp) { + DL_DELETE(head,elt); + } + + fclose(file); + + return 0; +} +-------------------------------------------------------------------------------- + +// vim: set nowrap syntax=asciidoc: + diff --git a/apps/systemlib/uthash/doc/utstring.txt b/apps/systemlib/uthash/doc/utstring.txt new file mode 100644 index 0000000000..abfdcd1074 --- /dev/null +++ b/apps/systemlib/uthash/doc/utstring.txt @@ -0,0 +1,178 @@ +utstring: dynamic string macros for C +===================================== +Troy D. Hanson +v1.9.5, November 2011 + +include::sflogo.txt[] +include::topnav_utstring.txt[] + +Introduction +------------ +include::toc.txt[] + +A set of very basic dynamic string macros for C programs are included with +uthash in `utstring.h`. To use these macros in your own C program, just +copy `utstring.h` into your source directory and use it in your programs. + + #include "utstring.h" + +The dynamic string supports basic operations such as inserting data (including +binary data-- despite its name, utstring is not limited to string content), +concatenation, getting the length and content, and clearing it. The string +<> are listed below. + +Download +~~~~~~~~ +To download the `utstring.h` header file, follow the link on the +http://uthash.sourceforge.net[uthash home page]. + +BSD licensed +~~~~~~~~~~~~ +This software is made available under the +link:license.html[revised BSD license]. +It is free and open source. + +Platforms +~~~~~~~~~ +The 'utstring' macros have been tested on: + + * Linux, + * Windows, using Visual Studio 2008 and Visual Studio 2010 + +Usage +----- + +Declaration +~~~~~~~~~~~ + +The dynamic string itself has the data type `UT_string`. It is declared like, + + UT_string *str; + +New and free +~~~~~~~~~~~~ +The next step is to create the string using `utstring_new`. Later when you're +done with it, `utstring_free` will free it and all its content. + +Manipulation +~~~~~~~~~~~~ +The `utstring_printf` or `utstring_bincpy` operations insert (copy) data into +the string. To concatenate one utstring to another, use `utstring_concat`. To +clear the content of the string, use `utstring_clear`. The length of the string +is available from `utstring_len`, and its content from `utstring_body`. This +evaluates to a `char*`. The buffer it points to is always null-terminated. +So, it can be used directly with external functions that expect a string. +This automatic null terminator is not counted in the length of the string. + +Samples +~~~~~~~ + +These examples show how to use utstring. + +.Sample 1 +------------------------------------------------------------------------------- +#include +#include "utstring.h" + +int main() { + UT_string *s; + + utstring_new(s); + utstring_printf(s, "hello world!" ); + printf("%s\n", utstring_body(s)); + + utstring_free(s); + return 0; +} +------------------------------------------------------------------------------- + +The next example is meant to demonstrate that printf 'appends' to the string. +It also shows concatenation. + +.Sample 2 +------------------------------------------------------------------------------- +#include +#include "utstring.h" + +int main() { + UT_string *s, *t; + + utstring_new(s); + utstring_new(t); + + utstring_printf(s, "hello " ); + utstring_printf(s, "world " ); + + utstring_printf(t, "hi " ); + utstring_printf(t, "there " ); + + utstring_concat(s, t); + printf("length: %u\n", utstring_len(s)); + printf("%s\n", utstring_body(s)); + + utstring_free(s); + utstring_free(t); + return 0; +} +------------------------------------------------------------------------------- + +The last example shows how binary data can be inserted into the string. It also +clears the string and prints new data into it. + +.Sample 3 +------------------------------------------------------------------------------- +#include +#include "utstring.h" + +int main() { + UT_string *s; + char binary[] = "\xff\xff"; + + utstring_new(s); + utstring_bincpy(s, binary, sizeof(binary)); + printf("length is %u\n", utstring_len(s)); + + utstring_clear(s); + utstring_printf(s,"number %d", 10); + printf("%s\n", utstring_body(s)); + + utstring_free(s); + return 0; +} +------------------------------------------------------------------------------- + +[[operations]] +Reference +--------- +These are the utstring operations. + +Operations +~~~~~~~~~~ + +[width="100%",cols="50 /* size_t */ +#include /* memset, etc */ +#include /* exit */ + +#define oom() exit(-1) + +typedef void (ctor_f)(void *dst, const void *src); +typedef void (dtor_f)(void *elt); +typedef void (init_f)(void *elt); +typedef struct { + size_t sz; + init_f *init; + ctor_f *copy; + dtor_f *dtor; +} UT_icd; + +typedef struct { + unsigned i,n;/* i: index of next available slot, n: num slots */ + UT_icd icd; /* initializer, copy and destructor functions */ + char *d; /* n slots of size icd->sz*/ +} UT_array; + +#define utarray_init(a,_icd) do { \ + memset(a,0,sizeof(UT_array)); \ + (a)->icd=*_icd; \ +} while(0) + +#define utarray_done(a) do { \ + if ((a)->n) { \ + if ((a)->icd.dtor) { \ + size_t _ut_i; \ + for(_ut_i=0; _ut_i < (a)->i; _ut_i++) { \ + (a)->icd.dtor(utarray_eltptr(a,_ut_i)); \ + } \ + } \ + free((a)->d); \ + } \ + (a)->n=0; \ +} while(0) + +#define utarray_new(a,_icd) do { \ + a=(UT_array*)malloc(sizeof(UT_array)); \ + utarray_init(a,_icd); \ +} while(0) + +#define utarray_free(a) do { \ + utarray_done(a); \ + free(a); \ +} while(0) + +#define utarray_reserve(a,by) do { \ + if (((a)->i+by) > ((a)->n)) { \ + while(((a)->i+by) > ((a)->n)) { (a)->n = ((a)->n ? (2*(a)->n) : 8); } \ + if ( ((a)->d=(char*)realloc((a)->d, (a)->n*(a)->icd.sz)) == NULL) oom(); \ + } \ +} while(0) + +#define utarray_push_back(a,p) do { \ + utarray_reserve(a,1); \ + if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,(a)->i++), p); } \ + else { memcpy(_utarray_eltptr(a,(a)->i++), p, (a)->icd.sz); }; \ +} while(0) + +#define utarray_pop_back(a) do { \ + if ((a)->icd.dtor) { (a)->icd.dtor( _utarray_eltptr(a,--((a)->i))); } \ + else { (a)->i--; } \ +} while(0) + +#define utarray_extend_back(a) do { \ + utarray_reserve(a,1); \ + if ((a)->icd.init) { (a)->icd.init(_utarray_eltptr(a,(a)->i)); } \ + else { memset(_utarray_eltptr(a,(a)->i),0,(a)->icd.sz); } \ + (a)->i++; \ +} while(0) + +#define utarray_len(a) ((a)->i) + +#define utarray_eltptr(a,j) (((j) < (a)->i) ? _utarray_eltptr(a,j) : NULL) +#define _utarray_eltptr(a,j) ((char*)((a)->d + ((a)->icd.sz*(j) ))) + +#define utarray_insert(a,p,j) do { \ + utarray_reserve(a,1); \ + if (j > (a)->i) break; \ + if ((j) < (a)->i) { \ + memmove( _utarray_eltptr(a,(j)+1), _utarray_eltptr(a,j), \ + ((a)->i - (j))*((a)->icd.sz)); \ + } \ + if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,j), p); } \ + else { memcpy(_utarray_eltptr(a,j), p, (a)->icd.sz); }; \ + (a)->i++; \ +} while(0) + +#define utarray_inserta(a,w,j) do { \ + if (utarray_len(w) == 0) break; \ + if (j > (a)->i) break; \ + utarray_reserve(a,utarray_len(w)); \ + if ((j) < (a)->i) { \ + memmove(_utarray_eltptr(a,(j)+utarray_len(w)), \ + _utarray_eltptr(a,j), \ + ((a)->i - (j))*((a)->icd.sz)); \ + } \ + if ((a)->icd.copy) { \ + size_t _ut_i; \ + for(_ut_i=0;_ut_i<(w)->i;_ut_i++) { \ + (a)->icd.copy(_utarray_eltptr(a,j+_ut_i), _utarray_eltptr(w,_ut_i)); \ + } \ + } else { \ + memcpy(_utarray_eltptr(a,j), _utarray_eltptr(w,0), \ + utarray_len(w)*((a)->icd.sz)); \ + } \ + (a)->i += utarray_len(w); \ +} while(0) + +#define utarray_resize(dst,num) do { \ + size_t _ut_i; \ + if (dst->i > (size_t)(num)) { \ + if ((dst)->icd.dtor) { \ + for(_ut_i=num; _ut_i < dst->i; _ut_i++) { \ + (dst)->icd.dtor(utarray_eltptr(dst,_ut_i)); \ + } \ + } \ + } else if (dst->i < (size_t)(num)) { \ + utarray_reserve(dst,num-dst->i); \ + if ((dst)->icd.init) { \ + for(_ut_i=dst->i; _ut_i < num; _ut_i++) { \ + (dst)->icd.init(utarray_eltptr(dst,_ut_i)); \ + } \ + } else { \ + memset(_utarray_eltptr(dst,dst->i),0,(dst)->icd.sz*(num-dst->i)); \ + } \ + } \ + dst->i = num; \ +} while(0) + +#define utarray_concat(dst,src) do { \ + utarray_inserta((dst),(src),utarray_len(dst)); \ +} while(0) + +#define utarray_erase(a,pos,len) do { \ + if ((a)->icd.dtor) { \ + size_t _ut_i; \ + for(_ut_i=0; _ut_i < len; _ut_i++) { \ + (a)->icd.dtor(utarray_eltptr((a),pos+_ut_i)); \ + } \ + } \ + if ((a)->i > (pos+len)) { \ + memmove( _utarray_eltptr((a),pos), _utarray_eltptr((a),pos+len), \ + (((a)->i)-(pos+len))*((a)->icd.sz)); \ + } \ + (a)->i -= (len); \ +} while(0) + +#define utarray_renew(a,u) do { \ + if (a) utarray_clear(a); \ + else utarray_new((a),(u)); \ +} while(0) + +#define utarray_clear(a) do { \ + if ((a)->i > 0) { \ + if ((a)->icd.dtor) { \ + size_t _ut_i; \ + for(_ut_i=0; _ut_i < (a)->i; _ut_i++) { \ + (a)->icd.dtor(utarray_eltptr(a,_ut_i)); \ + } \ + } \ + (a)->i = 0; \ + } \ +} while(0) + +#define utarray_sort(a,cmp) do { \ + qsort((a)->d, (a)->i, (a)->icd.sz, cmp); \ +} while(0) + +#define utarray_find(a,v,cmp) bsearch((v),(a)->d,(a)->i,(a)->icd.sz,cmp) + +#define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL) +#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : ((((a)->i) > (utarray_eltidx(a,e)+1)) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL)) +#define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) > 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL)) +#define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL) +#define utarray_eltidx(a,e) (((char*)(e) >= (char*)((a)->d)) ? (((char*)(e) - (char*)((a)->d))/(a)->icd.sz) : -1) + +/* last we pre-define a few icd for common utarrays of ints and strings */ +static void utarray_str_cpy(void *dst, const void *src) { + char **_src = (char**)src, **_dst = (char**)dst; + *_dst = (*_src == NULL) ? NULL : strdup(*_src); +} +static void utarray_str_dtor(void *elt) { + char **eltc = (char**)elt; + if (*eltc) free(*eltc); +} +static const UT_icd ut_str_icd _UNUSED_ = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor}; +static const UT_icd ut_int_icd _UNUSED_ = {sizeof(int),NULL,NULL,NULL}; +static const UT_icd ut_ptr_icd _UNUSED_ = {sizeof(void*),NULL,NULL,NULL}; + + +#endif /* UTARRAY_H */ diff --git a/apps/systemlib/uthash/uthash.h b/apps/systemlib/uthash/uthash.h new file mode 100644 index 0000000000..9f83fc34f1 --- /dev/null +++ b/apps/systemlib/uthash/uthash.h @@ -0,0 +1,915 @@ +/* +Copyright (c) 2003-2012, Troy D. Hanson http://uthash.sourceforge.net +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef UTHASH_H +#define UTHASH_H + +#include /* memcmp,strlen */ +#include /* ptrdiff_t */ +#include /* exit() */ + +/* These macros use decltype or the earlier __typeof GNU extension. + As decltype is only available in newer compilers (VS2010 or gcc 4.3+ + when compiling c++ source) this code uses whatever method is needed + or, for VS2008 where neither is available, uses casting workarounds. */ +#ifdef _MSC_VER /* MS compiler */ +#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ +#define DECLTYPE(x) (decltype(x)) +#else /* VS2008 or older (or VS2010 in C mode) */ +#define NO_DECLTYPE +#define DECLTYPE(x) +#endif +#else /* GNU, Sun and other compilers */ +#define DECLTYPE(x) (__typeof(x)) +#endif + +#ifdef NO_DECLTYPE +#define DECLTYPE_ASSIGN(dst,src) \ +do { \ + char **_da_dst = (char**)(&(dst)); \ + *_da_dst = (char*)(src); \ +} while(0) +#else +#define DECLTYPE_ASSIGN(dst,src) \ +do { \ + (dst) = DECLTYPE(dst)(src); \ +} while(0) +#endif + +/* a number of the hash function use uint32_t which isn't defined on win32 */ +#ifdef _MSC_VER +typedef unsigned int uint32_t; +typedef unsigned char uint8_t; +#else +#include /* uint32_t */ +#endif + +#define UTHASH_VERSION 1.9.6 + +#ifndef uthash_fatal +#define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */ +#endif +#ifndef uthash_malloc +#define uthash_malloc(sz) malloc(sz) /* malloc fcn */ +#endif +#ifndef uthash_free +#define uthash_free(ptr,sz) free(ptr) /* free fcn */ +#endif + +#ifndef uthash_noexpand_fyi +#define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ +#endif +#ifndef uthash_expand_fyi +#define uthash_expand_fyi(tbl) /* can be defined to log expands */ +#endif + +/* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */ +#define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */ + +/* calculate the element whose hash handle address is hhe */ +#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho))) + +#define HASH_FIND(hh,head,keyptr,keylen,out) \ +do { \ + unsigned _hf_bkt,_hf_hashv; \ + out=NULL; \ + if (head) { \ + HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \ + if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ + HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \ + keyptr,keylen,out); \ + } \ + } \ +} while (0) + +#ifdef HASH_BLOOM +#define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM) +#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0) +#define HASH_BLOOM_MAKE(tbl) \ +do { \ + (tbl)->bloom_nbits = HASH_BLOOM; \ + (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ + if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \ + memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ + (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ +} while (0) + +#define HASH_BLOOM_FREE(tbl) \ +do { \ + uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ +} while (0) + +#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8))) +#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8))) + +#define HASH_BLOOM_ADD(tbl,hashv) \ + HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) + +#define HASH_BLOOM_TEST(tbl,hashv) \ + HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) + +#else +#define HASH_BLOOM_MAKE(tbl) +#define HASH_BLOOM_FREE(tbl) +#define HASH_BLOOM_ADD(tbl,hashv) +#define HASH_BLOOM_TEST(tbl,hashv) (1) +#endif + +#define HASH_MAKE_TABLE(hh,head) \ +do { \ + (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \ + sizeof(UT_hash_table)); \ + if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \ + memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ + (head)->hh.tbl->tail = &((head)->hh); \ + (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ + (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ + (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ + (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ + HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ + if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \ + memset((head)->hh.tbl->buckets, 0, \ + HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ + HASH_BLOOM_MAKE((head)->hh.tbl); \ + (head)->hh.tbl->signature = HASH_SIGNATURE; \ +} while(0) + +#define HASH_ADD(hh,head,fieldname,keylen_in,add) \ + HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add) + +#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ +do { \ + unsigned _ha_bkt; \ + (add)->hh.next = NULL; \ + (add)->hh.key = (char*)keyptr; \ + (add)->hh.keylen = (unsigned)keylen_in; \ + if (!(head)) { \ + head = (add); \ + (head)->hh.prev = NULL; \ + HASH_MAKE_TABLE(hh,head); \ + } else { \ + (head)->hh.tbl->tail->next = (add); \ + (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ + (head)->hh.tbl->tail = &((add)->hh); \ + } \ + (head)->hh.tbl->num_items++; \ + (add)->hh.tbl = (head)->hh.tbl; \ + HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \ + (add)->hh.hashv, _ha_bkt); \ + HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \ + HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \ + HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \ + HASH_FSCK(hh,head); \ +} while(0) + +#define HASH_TO_BKT( hashv, num_bkts, bkt ) \ +do { \ + bkt = ((hashv) & ((num_bkts) - 1)); \ +} while(0) + +/* delete "delptr" from the hash table. + * "the usual" patch-up process for the app-order doubly-linked-list. + * The use of _hd_hh_del below deserves special explanation. + * These used to be expressed using (delptr) but that led to a bug + * if someone used the same symbol for the head and deletee, like + * HASH_DELETE(hh,users,users); + * We want that to work, but by changing the head (users) below + * we were forfeiting our ability to further refer to the deletee (users) + * in the patch-up process. Solution: use scratch space to + * copy the deletee pointer, then the latter references are via that + * scratch pointer rather than through the repointed (users) symbol. + */ +#define HASH_DELETE(hh,head,delptr) \ +do { \ + unsigned _hd_bkt; \ + struct UT_hash_handle *_hd_hh_del; \ + if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \ + uthash_free((head)->hh.tbl->buckets, \ + (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ + HASH_BLOOM_FREE((head)->hh.tbl); \ + uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ + head = NULL; \ + } else { \ + _hd_hh_del = &((delptr)->hh); \ + if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \ + (head)->hh.tbl->tail = \ + (UT_hash_handle*)((char*)((delptr)->hh.prev) + \ + (head)->hh.tbl->hho); \ + } \ + if ((delptr)->hh.prev) { \ + ((UT_hash_handle*)((char*)((delptr)->hh.prev) + \ + (head)->hh.tbl->hho))->next = (delptr)->hh.next; \ + } else { \ + DECLTYPE_ASSIGN(head,(delptr)->hh.next); \ + } \ + if (_hd_hh_del->next) { \ + ((UT_hash_handle*)((char*)_hd_hh_del->next + \ + (head)->hh.tbl->hho))->prev = \ + _hd_hh_del->prev; \ + } \ + HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ + HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ + (head)->hh.tbl->num_items--; \ + } \ + HASH_FSCK(hh,head); \ +} while (0) + + +/* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */ +#define HASH_FIND_STR(head,findstr,out) \ + HASH_FIND(hh,head,findstr,strlen(findstr),out) +#define HASH_ADD_STR(head,strfield,add) \ + HASH_ADD(hh,head,strfield,strlen(add->strfield),add) +#define HASH_FIND_INT(head,findint,out) \ + HASH_FIND(hh,head,findint,sizeof(int),out) +#define HASH_ADD_INT(head,intfield,add) \ + HASH_ADD(hh,head,intfield,sizeof(int),add) +#define HASH_FIND_PTR(head,findptr,out) \ + HASH_FIND(hh,head,findptr,sizeof(void *),out) +#define HASH_ADD_PTR(head,ptrfield,add) \ + HASH_ADD(hh,head,ptrfield,sizeof(void *),add) +#define HASH_DEL(head,delptr) \ + HASH_DELETE(hh,head,delptr) + +/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined. + * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined. + */ +#ifdef HASH_DEBUG +#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) +#define HASH_FSCK(hh,head) \ +do { \ + unsigned _bkt_i; \ + unsigned _count, _bkt_count; \ + char *_prev; \ + struct UT_hash_handle *_thh; \ + if (head) { \ + _count = 0; \ + for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \ + _bkt_count = 0; \ + _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ + _prev = NULL; \ + while (_thh) { \ + if (_prev != (char*)(_thh->hh_prev)) { \ + HASH_OOPS("invalid hh_prev %p, actual %p\n", \ + _thh->hh_prev, _prev ); \ + } \ + _bkt_count++; \ + _prev = (char*)(_thh); \ + _thh = _thh->hh_next; \ + } \ + _count += _bkt_count; \ + if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ + HASH_OOPS("invalid bucket count %d, actual %d\n", \ + (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ + } \ + } \ + if (_count != (head)->hh.tbl->num_items) { \ + HASH_OOPS("invalid hh item count %d, actual %d\n", \ + (head)->hh.tbl->num_items, _count ); \ + } \ + /* traverse hh in app order; check next/prev integrity, count */ \ + _count = 0; \ + _prev = NULL; \ + _thh = &(head)->hh; \ + while (_thh) { \ + _count++; \ + if (_prev !=(char*)(_thh->prev)) { \ + HASH_OOPS("invalid prev %p, actual %p\n", \ + _thh->prev, _prev ); \ + } \ + _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ + _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \ + (head)->hh.tbl->hho) : NULL ); \ + } \ + if (_count != (head)->hh.tbl->num_items) { \ + HASH_OOPS("invalid app item count %d, actual %d\n", \ + (head)->hh.tbl->num_items, _count ); \ + } \ + } \ +} while (0) +#else +#define HASH_FSCK(hh,head) +#endif + +/* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to + * the descriptor to which this macro is defined for tuning the hash function. + * The app can #include to get the prototype for write(2). */ +#ifdef HASH_EMIT_KEYS +#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ +do { \ + unsigned _klen = fieldlen; \ + write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ + write(HASH_EMIT_KEYS, keyptr, fieldlen); \ +} while (0) +#else +#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) +#endif + +/* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */ +#ifdef HASH_FUNCTION +#define HASH_FCN HASH_FUNCTION +#else +#define HASH_FCN HASH_JEN +#endif + +/* The Bernstein hash function, used in Perl prior to v5.6 */ +#define HASH_BER(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _hb_keylen=keylen; \ + char *_hb_key=(char*)(key); \ + (hashv) = 0; \ + while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \ + bkt = (hashv) & (num_bkts-1); \ +} while (0) + + +/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at + * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ +#define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _sx_i; \ + char *_hs_key=(char*)(key); \ + hashv = 0; \ + for(_sx_i=0; _sx_i < keylen; _sx_i++) \ + hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ + bkt = hashv & (num_bkts-1); \ +} while (0) + +#define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _fn_i; \ + char *_hf_key=(char*)(key); \ + hashv = 2166136261UL; \ + for(_fn_i=0; _fn_i < keylen; _fn_i++) \ + hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +#define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _ho_i; \ + char *_ho_key=(char*)(key); \ + hashv = 0; \ + for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ + hashv += _ho_key[_ho_i]; \ + hashv += (hashv << 10); \ + hashv ^= (hashv >> 6); \ + } \ + hashv += (hashv << 3); \ + hashv ^= (hashv >> 11); \ + hashv += (hashv << 15); \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +#define HASH_JEN_MIX(a,b,c) \ +do { \ + a -= b; a -= c; a ^= ( c >> 13 ); \ + b -= c; b -= a; b ^= ( a << 8 ); \ + c -= a; c -= b; c ^= ( b >> 13 ); \ + a -= b; a -= c; a ^= ( c >> 12 ); \ + b -= c; b -= a; b ^= ( a << 16 ); \ + c -= a; c -= b; c ^= ( b >> 5 ); \ + a -= b; a -= c; a ^= ( c >> 3 ); \ + b -= c; b -= a; b ^= ( a << 10 ); \ + c -= a; c -= b; c ^= ( b >> 15 ); \ +} while (0) + +#define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ +do { \ + unsigned _hj_i,_hj_j,_hj_k; \ + char *_hj_key=(char*)(key); \ + hashv = 0xfeedbeef; \ + _hj_i = _hj_j = 0x9e3779b9; \ + _hj_k = (unsigned)keylen; \ + while (_hj_k >= 12) { \ + _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ + + ( (unsigned)_hj_key[2] << 16 ) \ + + ( (unsigned)_hj_key[3] << 24 ) ); \ + _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ + + ( (unsigned)_hj_key[6] << 16 ) \ + + ( (unsigned)_hj_key[7] << 24 ) ); \ + hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ + + ( (unsigned)_hj_key[10] << 16 ) \ + + ( (unsigned)_hj_key[11] << 24 ) ); \ + \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + \ + _hj_key += 12; \ + _hj_k -= 12; \ + } \ + hashv += keylen; \ + switch ( _hj_k ) { \ + case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \ + case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \ + case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \ + case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \ + case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \ + case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \ + case 5: _hj_j += _hj_key[4]; \ + case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \ + case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \ + case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \ + case 1: _hj_i += _hj_key[0]; \ + } \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +/* The Paul Hsieh hash function */ +#undef get16bits +#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ + || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) +#define get16bits(d) (*((const uint16_t *) (d))) +#endif + +#if !defined (get16bits) +#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ + +(uint32_t)(((const uint8_t *)(d))[0]) ) +#endif +#define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ +do { \ + char *_sfh_key=(char*)(key); \ + uint32_t _sfh_tmp, _sfh_len = keylen; \ + \ + int _sfh_rem = _sfh_len & 3; \ + _sfh_len >>= 2; \ + hashv = 0xcafebabe; \ + \ + /* Main loop */ \ + for (;_sfh_len > 0; _sfh_len--) { \ + hashv += get16bits (_sfh_key); \ + _sfh_tmp = (get16bits (_sfh_key+2) << 11) ^ hashv; \ + hashv = (hashv << 16) ^ _sfh_tmp; \ + _sfh_key += 2*sizeof (uint16_t); \ + hashv += hashv >> 11; \ + } \ + \ + /* Handle end cases */ \ + switch (_sfh_rem) { \ + case 3: hashv += get16bits (_sfh_key); \ + hashv ^= hashv << 16; \ + hashv ^= _sfh_key[sizeof (uint16_t)] << 18; \ + hashv += hashv >> 11; \ + break; \ + case 2: hashv += get16bits (_sfh_key); \ + hashv ^= hashv << 11; \ + hashv += hashv >> 17; \ + break; \ + case 1: hashv += *_sfh_key; \ + hashv ^= hashv << 10; \ + hashv += hashv >> 1; \ + } \ + \ + /* Force "avalanching" of final 127 bits */ \ + hashv ^= hashv << 3; \ + hashv += hashv >> 5; \ + hashv ^= hashv << 4; \ + hashv += hashv >> 17; \ + hashv ^= hashv << 25; \ + hashv += hashv >> 6; \ + bkt = hashv & (num_bkts-1); \ +} while(0) + +#ifdef HASH_USING_NO_STRICT_ALIASING +/* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads. + * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error. + * MurmurHash uses the faster approach only on CPU's where we know it's safe. + * + * Note the preprocessor built-in defines can be emitted using: + * + * gcc -m64 -dM -E - < /dev/null (on gcc) + * cc -## a.c (where a.c is a simple test file) (Sun Studio) + */ +#if (defined(__i386__) || defined(__x86_64__)) +#define MUR_GETBLOCK(p,i) p[i] +#else /* non intel */ +#define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0) +#define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 0x3) == 1) +#define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2) +#define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3) +#define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL)) +#if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__)) +#define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24)) +#define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16)) +#define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8)) +#else /* assume little endian non-intel */ +#define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24)) +#define MUR_TWO_TWO(p) ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16)) +#define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) << 8)) +#endif +#define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \ + (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \ + (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \ + MUR_ONE_THREE(p)))) +#endif +#define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) +#define MUR_FMIX(_h) \ +do { \ + _h ^= _h >> 16; \ + _h *= 0x85ebca6b; \ + _h ^= _h >> 13; \ + _h *= 0xc2b2ae35l; \ + _h ^= _h >> 16; \ +} while(0) + +#define HASH_MUR(key,keylen,num_bkts,hashv,bkt) \ +do { \ + const uint8_t *_mur_data = (const uint8_t*)(key); \ + const int _mur_nblocks = (keylen) / 4; \ + uint32_t _mur_h1 = 0xf88D5353; \ + uint32_t _mur_c1 = 0xcc9e2d51; \ + uint32_t _mur_c2 = 0x1b873593; \ + const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \ + int _mur_i; \ + for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) { \ + uint32_t _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i); \ + _mur_k1 *= _mur_c1; \ + _mur_k1 = MUR_ROTL32(_mur_k1,15); \ + _mur_k1 *= _mur_c2; \ + \ + _mur_h1 ^= _mur_k1; \ + _mur_h1 = MUR_ROTL32(_mur_h1,13); \ + _mur_h1 = _mur_h1*5+0xe6546b64; \ + } \ + const uint8_t *_mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4); \ + uint32_t _mur_k1=0; \ + switch((keylen) & 3) { \ + case 3: _mur_k1 ^= _mur_tail[2] << 16; \ + case 2: _mur_k1 ^= _mur_tail[1] << 8; \ + case 1: _mur_k1 ^= _mur_tail[0]; \ + _mur_k1 *= _mur_c1; \ + _mur_k1 = MUR_ROTL32(_mur_k1,15); \ + _mur_k1 *= _mur_c2; \ + _mur_h1 ^= _mur_k1; \ + } \ + _mur_h1 ^= (keylen); \ + MUR_FMIX(_mur_h1); \ + hashv = _mur_h1; \ + bkt = hashv & (num_bkts-1); \ +} while(0) +#endif /* HASH_USING_NO_STRICT_ALIASING */ + +/* key comparison function; return 0 if keys equal */ +#define HASH_KEYCMP(a,b,len) memcmp(a,b,len) + +/* iterate over items in a known bucket to find desired item */ +#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \ +do { \ + if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \ + else out=NULL; \ + while (out) { \ + if ((out)->hh.keylen == keylen_in) { \ + if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break; \ + } \ + if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \ + else out = NULL; \ + } \ +} while(0) + +/* add an item to a bucket */ +#define HASH_ADD_TO_BKT(head,addhh) \ +do { \ + head.count++; \ + (addhh)->hh_next = head.hh_head; \ + (addhh)->hh_prev = NULL; \ + if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \ + (head).hh_head=addhh; \ + if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \ + && (addhh)->tbl->noexpand != 1) { \ + HASH_EXPAND_BUCKETS((addhh)->tbl); \ + } \ +} while(0) + +/* remove an item from a given bucket */ +#define HASH_DEL_IN_BKT(hh,head,hh_del) \ + (head).count--; \ + if ((head).hh_head == hh_del) { \ + (head).hh_head = hh_del->hh_next; \ + } \ + if (hh_del->hh_prev) { \ + hh_del->hh_prev->hh_next = hh_del->hh_next; \ + } \ + if (hh_del->hh_next) { \ + hh_del->hh_next->hh_prev = hh_del->hh_prev; \ + } + +/* Bucket expansion has the effect of doubling the number of buckets + * and redistributing the items into the new buckets. Ideally the + * items will distribute more or less evenly into the new buckets + * (the extent to which this is true is a measure of the quality of + * the hash function as it applies to the key domain). + * + * With the items distributed into more buckets, the chain length + * (item count) in each bucket is reduced. Thus by expanding buckets + * the hash keeps a bound on the chain length. This bounded chain + * length is the essence of how a hash provides constant time lookup. + * + * The calculation of tbl->ideal_chain_maxlen below deserves some + * explanation. First, keep in mind that we're calculating the ideal + * maximum chain length based on the *new* (doubled) bucket count. + * In fractions this is just n/b (n=number of items,b=new num buckets). + * Since the ideal chain length is an integer, we want to calculate + * ceil(n/b). We don't depend on floating point arithmetic in this + * hash, so to calculate ceil(n/b) with integers we could write + * + * ceil(n/b) = (n/b) + ((n%b)?1:0) + * + * and in fact a previous version of this hash did just that. + * But now we have improved things a bit by recognizing that b is + * always a power of two. We keep its base 2 log handy (call it lb), + * so now we can write this with a bit shift and logical AND: + * + * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0) + * + */ +#define HASH_EXPAND_BUCKETS(tbl) \ +do { \ + unsigned _he_bkt; \ + unsigned _he_bkt_i; \ + struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ + UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ + _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ + 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ + if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \ + memset(_he_new_buckets, 0, \ + 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ + tbl->ideal_chain_maxlen = \ + (tbl->num_items >> (tbl->log2_num_buckets+1)) + \ + ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \ + tbl->nonideal_items = 0; \ + for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \ + { \ + _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \ + while (_he_thh) { \ + _he_hh_nxt = _he_thh->hh_next; \ + HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \ + _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \ + if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \ + tbl->nonideal_items++; \ + _he_newbkt->expand_mult = _he_newbkt->count / \ + tbl->ideal_chain_maxlen; \ + } \ + _he_thh->hh_prev = NULL; \ + _he_thh->hh_next = _he_newbkt->hh_head; \ + if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \ + _he_thh; \ + _he_newbkt->hh_head = _he_thh; \ + _he_thh = _he_hh_nxt; \ + } \ + } \ + uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ + tbl->num_buckets *= 2; \ + tbl->log2_num_buckets++; \ + tbl->buckets = _he_new_buckets; \ + tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \ + (tbl->ineff_expands+1) : 0; \ + if (tbl->ineff_expands > 1) { \ + tbl->noexpand=1; \ + uthash_noexpand_fyi(tbl); \ + } \ + uthash_expand_fyi(tbl); \ +} while(0) + + +/* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */ +/* Note that HASH_SORT assumes the hash handle name to be hh. + * HASH_SRT was added to allow the hash handle name to be passed in. */ +#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) +#define HASH_SRT(hh,head,cmpfcn) \ +do { \ + unsigned _hs_i; \ + unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ + struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ + if (head) { \ + _hs_insize = 1; \ + _hs_looping = 1; \ + _hs_list = &((head)->hh); \ + while (_hs_looping) { \ + _hs_p = _hs_list; \ + _hs_list = NULL; \ + _hs_tail = NULL; \ + _hs_nmerges = 0; \ + while (_hs_p) { \ + _hs_nmerges++; \ + _hs_q = _hs_p; \ + _hs_psize = 0; \ + for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \ + _hs_psize++; \ + _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ + ((void*)((char*)(_hs_q->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + if (! (_hs_q) ) break; \ + } \ + _hs_qsize = _hs_insize; \ + while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \ + if (_hs_psize == 0) { \ + _hs_e = _hs_q; \ + _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ + ((void*)((char*)(_hs_q->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_qsize--; \ + } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \ + _hs_e = _hs_p; \ + _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ + ((void*)((char*)(_hs_p->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_psize--; \ + } else if (( \ + cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \ + DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \ + ) <= 0) { \ + _hs_e = _hs_p; \ + _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ + ((void*)((char*)(_hs_p->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_psize--; \ + } else { \ + _hs_e = _hs_q; \ + _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ + ((void*)((char*)(_hs_q->next) + \ + (head)->hh.tbl->hho)) : NULL); \ + _hs_qsize--; \ + } \ + if ( _hs_tail ) { \ + _hs_tail->next = ((_hs_e) ? \ + ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \ + } else { \ + _hs_list = _hs_e; \ + } \ + _hs_e->prev = ((_hs_tail) ? \ + ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \ + _hs_tail = _hs_e; \ + } \ + _hs_p = _hs_q; \ + } \ + _hs_tail->next = NULL; \ + if ( _hs_nmerges <= 1 ) { \ + _hs_looping=0; \ + (head)->hh.tbl->tail = _hs_tail; \ + DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \ + } \ + _hs_insize *= 2; \ + } \ + HASH_FSCK(hh,head); \ + } \ +} while (0) + +/* This function selects items from one hash into another hash. + * The end result is that the selected items have dual presence + * in both hashes. There is no copy of the items made; rather + * they are added into the new hash through a secondary hash + * hash handle that must be present in the structure. */ +#define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ +do { \ + unsigned _src_bkt, _dst_bkt; \ + void *_last_elt=NULL, *_elt; \ + UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ + ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ + if (src) { \ + for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ + for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ + _src_hh; \ + _src_hh = _src_hh->hh_next) { \ + _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ + if (cond(_elt)) { \ + _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ + _dst_hh->key = _src_hh->key; \ + _dst_hh->keylen = _src_hh->keylen; \ + _dst_hh->hashv = _src_hh->hashv; \ + _dst_hh->prev = _last_elt; \ + _dst_hh->next = NULL; \ + if (_last_elt_hh) { _last_elt_hh->next = _elt; } \ + if (!dst) { \ + DECLTYPE_ASSIGN(dst,_elt); \ + HASH_MAKE_TABLE(hh_dst,dst); \ + } else { \ + _dst_hh->tbl = (dst)->hh_dst.tbl; \ + } \ + HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ + HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \ + (dst)->hh_dst.tbl->num_items++; \ + _last_elt = _elt; \ + _last_elt_hh = _dst_hh; \ + } \ + } \ + } \ + } \ + HASH_FSCK(hh_dst,dst); \ +} while (0) + +#define HASH_CLEAR(hh,head) \ +do { \ + if (head) { \ + uthash_free((head)->hh.tbl->buckets, \ + (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \ + HASH_BLOOM_FREE((head)->hh.tbl); \ + uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ + (head)=NULL; \ + } \ +} while(0) + +#ifdef NO_DECLTYPE +#define HASH_ITER(hh,head,el,tmp) \ +for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \ + el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL)) +#else +#define HASH_ITER(hh,head,el,tmp) \ +for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \ + el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL)) +#endif + +/* obtain a count of items in the hash */ +#define HASH_COUNT(head) HASH_CNT(hh,head) +#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0) + +typedef struct UT_hash_bucket { + struct UT_hash_handle *hh_head; + unsigned count; + + /* expand_mult is normally set to 0. In this situation, the max chain length + * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If + * the bucket's chain exceeds this length, bucket expansion is triggered). + * However, setting expand_mult to a non-zero value delays bucket expansion + * (that would be triggered by additions to this particular bucket) + * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. + * (The multiplier is simply expand_mult+1). The whole idea of this + * multiplier is to reduce bucket expansions, since they are expensive, in + * situations where we know that a particular bucket tends to be overused. + * It is better to let its chain length grow to a longer yet-still-bounded + * value, than to do an O(n) bucket expansion too often. + */ + unsigned expand_mult; + +} UT_hash_bucket; + +/* random signature used only to find hash tables in external analysis */ +#define HASH_SIGNATURE 0xa0111fe1 +#define HASH_BLOOM_SIGNATURE 0xb12220f2 + +typedef struct UT_hash_table { + UT_hash_bucket *buckets; + unsigned num_buckets, log2_num_buckets; + unsigned num_items; + struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ + ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ + + /* in an ideal situation (all buckets used equally), no bucket would have + * more than ceil(#items/#buckets) items. that's the ideal chain length. */ + unsigned ideal_chain_maxlen; + + /* nonideal_items is the number of items in the hash whose chain position + * exceeds the ideal chain maxlen. these items pay the penalty for an uneven + * hash distribution; reaching them in a chain traversal takes >ideal steps */ + unsigned nonideal_items; + + /* ineffective expands occur when a bucket doubling was performed, but + * afterward, more than half the items in the hash had nonideal chain + * positions. If this happens on two consecutive expansions we inhibit any + * further expansion, as it's not helping; this happens when the hash + * function isn't a good fit for the key domain. When expansion is inhibited + * the hash will still work, albeit no longer in constant time. */ + unsigned ineff_expands, noexpand; + + uint32_t signature; /* used only to find hash tables in external analysis */ +#ifdef HASH_BLOOM + uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ + uint8_t *bloom_bv; + char bloom_nbits; +#endif + +} UT_hash_table; + +typedef struct UT_hash_handle { + struct UT_hash_table *tbl; + void *prev; /* prev element in app order */ + void *next; /* next element in app order */ + struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ + struct UT_hash_handle *hh_next; /* next hh in bucket order */ + void *key; /* ptr to enclosing struct's key */ + unsigned keylen; /* enclosing struct's key len */ + unsigned hashv; /* result of hash-fcn(key) */ +} UT_hash_handle; + +#endif /* UTHASH_H */ diff --git a/apps/systemlib/uthash/utlist.h b/apps/systemlib/uthash/utlist.h new file mode 100644 index 0000000000..1578acad2f --- /dev/null +++ b/apps/systemlib/uthash/utlist.h @@ -0,0 +1,522 @@ +/* +Copyright (c) 2007-2012, Troy D. Hanson http://uthash.sourceforge.net +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef UTLIST_H +#define UTLIST_H + +#define UTLIST_VERSION 1.9.6 + +#include + +/* + * This file contains macros to manipulate singly and doubly-linked lists. + * + * 1. LL_ macros: singly-linked lists. + * 2. DL_ macros: doubly-linked lists. + * 3. CDL_ macros: circular doubly-linked lists. + * + * To use singly-linked lists, your structure must have a "next" pointer. + * To use doubly-linked lists, your structure must "prev" and "next" pointers. + * Either way, the pointer to the head of the list must be initialized to NULL. + * + * ----------------.EXAMPLE ------------------------- + * struct item { + * int id; + * struct item *prev, *next; + * } + * + * struct item *list = NULL: + * + * int main() { + * struct item *item; + * ... allocate and populate item ... + * DL_APPEND(list, item); + * } + * -------------------------------------------------- + * + * For doubly-linked lists, the append and delete macros are O(1) + * For singly-linked lists, append and delete are O(n) but prepend is O(1) + * The sort macro is O(n log(n)) for all types of single/double/circular lists. + */ + +/* These macros use decltype or the earlier __typeof GNU extension. + As decltype is only available in newer compilers (VS2010 or gcc 4.3+ + when compiling c++ code), this code uses whatever method is needed + or, for VS2008 where neither is available, uses casting workarounds. */ +#ifdef _MSC_VER /* MS compiler */ +#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ +#define LDECLTYPE(x) decltype(x) +#else /* VS2008 or older (or VS2010 in C mode) */ +#define NO_DECLTYPE +#define LDECLTYPE(x) char* +#endif +#else /* GNU, Sun and other compilers */ +#define LDECLTYPE(x) __typeof(x) +#endif + +/* for VS2008 we use some workarounds to get around the lack of decltype, + * namely, we always reassign our tmp variable to the list head if we need + * to dereference its prev/next pointers, and save/restore the real head.*/ +#ifdef NO_DECLTYPE +#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); } +#define _NEXT(elt,list) ((char*)((list)->next)) +#define _NEXTASGN(elt,list,to) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); } +#define _PREV(elt,list) ((char*)((list)->prev)) +#define _PREVASGN(elt,list,to) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); } +#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; } +#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); } +#else +#define _SV(elt,list) +#define _NEXT(elt,list) ((elt)->next) +#define _NEXTASGN(elt,list,to) ((elt)->next)=(to) +#define _PREV(elt,list) ((elt)->prev) +#define _PREVASGN(elt,list,to) ((elt)->prev)=(to) +#define _RS(list) +#define _CASTASGN(a,b) (a)=(b) +#endif + +/****************************************************************************** + * The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort * + * Unwieldy variable names used here to avoid shadowing passed-in variables. * + *****************************************************************************/ +#define LL_SORT(list, cmp) \ +do { \ + LDECLTYPE(list) _ls_p; \ + LDECLTYPE(list) _ls_q; \ + LDECLTYPE(list) _ls_e; \ + LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _ls_oldhead; \ + LDECLTYPE(list) _tmp; \ + int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ + if (list) { \ + _ls_insize = 1; \ + _ls_looping = 1; \ + while (_ls_looping) { \ + _CASTASGN(_ls_p,list); \ + _CASTASGN(_ls_oldhead,list); \ + list = NULL; \ + _ls_tail = NULL; \ + _ls_nmerges = 0; \ + while (_ls_p) { \ + _ls_nmerges++; \ + _ls_q = _ls_p; \ + _ls_psize = 0; \ + for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ + _ls_psize++; \ + _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \ + if (!_ls_q) break; \ + } \ + _ls_qsize = _ls_insize; \ + while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ + if (_ls_psize == 0) { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } else if (_ls_qsize == 0 || !_ls_q) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else if (cmp(_ls_p,_ls_q) <= 0) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } \ + if (_ls_tail) { \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \ + } else { \ + _CASTASGN(list,_ls_e); \ + } \ + _ls_tail = _ls_e; \ + } \ + _ls_p = _ls_q; \ + } \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \ + if (_ls_nmerges <= 1) { \ + _ls_looping=0; \ + } \ + _ls_insize *= 2; \ + } \ + } else _tmp=NULL; /* quiet gcc unused variable warning */ \ +} while (0) + +#define DL_SORT(list, cmp) \ +do { \ + LDECLTYPE(list) _ls_p; \ + LDECLTYPE(list) _ls_q; \ + LDECLTYPE(list) _ls_e; \ + LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _ls_oldhead; \ + LDECLTYPE(list) _tmp; \ + int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ + if (list) { \ + _ls_insize = 1; \ + _ls_looping = 1; \ + while (_ls_looping) { \ + _CASTASGN(_ls_p,list); \ + _CASTASGN(_ls_oldhead,list); \ + list = NULL; \ + _ls_tail = NULL; \ + _ls_nmerges = 0; \ + while (_ls_p) { \ + _ls_nmerges++; \ + _ls_q = _ls_p; \ + _ls_psize = 0; \ + for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ + _ls_psize++; \ + _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \ + if (!_ls_q) break; \ + } \ + _ls_qsize = _ls_insize; \ + while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ + if (_ls_psize == 0) { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } else if (_ls_qsize == 0 || !_ls_q) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else if (cmp(_ls_p,_ls_q) <= 0) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + } else { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + } \ + if (_ls_tail) { \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \ + } else { \ + _CASTASGN(list,_ls_e); \ + } \ + _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \ + _ls_tail = _ls_e; \ + } \ + _ls_p = _ls_q; \ + } \ + _CASTASGN(list->prev, _ls_tail); \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \ + if (_ls_nmerges <= 1) { \ + _ls_looping=0; \ + } \ + _ls_insize *= 2; \ + } \ + } else _tmp=NULL; /* quiet gcc unused variable warning */ \ +} while (0) + +#define CDL_SORT(list, cmp) \ +do { \ + LDECLTYPE(list) _ls_p; \ + LDECLTYPE(list) _ls_q; \ + LDECLTYPE(list) _ls_e; \ + LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _ls_oldhead; \ + LDECLTYPE(list) _tmp; \ + LDECLTYPE(list) _tmp2; \ + int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ + if (list) { \ + _ls_insize = 1; \ + _ls_looping = 1; \ + while (_ls_looping) { \ + _CASTASGN(_ls_p,list); \ + _CASTASGN(_ls_oldhead,list); \ + list = NULL; \ + _ls_tail = NULL; \ + _ls_nmerges = 0; \ + while (_ls_p) { \ + _ls_nmerges++; \ + _ls_q = _ls_p; \ + _ls_psize = 0; \ + for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ + _ls_psize++; \ + _SV(_ls_q,list); \ + if (_NEXT(_ls_q,list) == _ls_oldhead) { \ + _ls_q = NULL; \ + } else { \ + _ls_q = _NEXT(_ls_q,list); \ + } \ + _RS(list); \ + if (!_ls_q) break; \ + } \ + _ls_qsize = _ls_insize; \ + while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ + if (_ls_psize == 0) { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \ + } else if (_ls_qsize == 0 || !_ls_q) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \ + } else if (cmp(_ls_p,_ls_q) <= 0) { \ + _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \ + if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \ + } else { \ + _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \ + if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \ + } \ + if (_ls_tail) { \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \ + } else { \ + _CASTASGN(list,_ls_e); \ + } \ + _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \ + _ls_tail = _ls_e; \ + } \ + _ls_p = _ls_q; \ + } \ + _CASTASGN(list->prev,_ls_tail); \ + _CASTASGN(_tmp2,list); \ + _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp2); _RS(list); \ + if (_ls_nmerges <= 1) { \ + _ls_looping=0; \ + } \ + _ls_insize *= 2; \ + } \ + } else _tmp=NULL; /* quiet gcc unused variable warning */ \ +} while (0) + +/****************************************************************************** + * singly linked list macros (non-circular) * + *****************************************************************************/ +#define LL_PREPEND(head,add) \ +do { \ + (add)->next = head; \ + head = add; \ +} while (0) + +#define LL_CONCAT(head1,head2) \ +do { \ + LDECLTYPE(head1) _tmp; \ + if (head1) { \ + _tmp = head1; \ + while (_tmp->next) { _tmp = _tmp->next; } \ + _tmp->next=(head2); \ + } else { \ + (head1)=(head2); \ + } \ +} while (0) + +#define LL_APPEND(head,add) \ +do { \ + LDECLTYPE(head) _tmp; \ + (add)->next=NULL; \ + if (head) { \ + _tmp = head; \ + while (_tmp->next) { _tmp = _tmp->next; } \ + _tmp->next=(add); \ + } else { \ + (head)=(add); \ + } \ +} while (0) + +#define LL_DELETE(head,del) \ +do { \ + LDECLTYPE(head) _tmp; \ + if ((head) == (del)) { \ + (head)=(head)->next; \ + } else { \ + _tmp = head; \ + while (_tmp->next && (_tmp->next != (del))) { \ + _tmp = _tmp->next; \ + } \ + if (_tmp->next) { \ + _tmp->next = ((del)->next); \ + } \ + } \ +} while (0) + +/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */ +#define LL_APPEND_VS2008(head,add) \ +do { \ + if (head) { \ + (add)->next = head; /* use add->next as a temp variable */ \ + while ((add)->next->next) { (add)->next = (add)->next->next; } \ + (add)->next->next=(add); \ + } else { \ + (head)=(add); \ + } \ + (add)->next=NULL; \ +} while (0) + +#define LL_DELETE_VS2008(head,del) \ +do { \ + if ((head) == (del)) { \ + (head)=(head)->next; \ + } else { \ + char *_tmp = (char*)(head); \ + while ((head)->next && ((head)->next != (del))) { \ + head = (head)->next; \ + } \ + if ((head)->next) { \ + (head)->next = ((del)->next); \ + } \ + { \ + char **_head_alias = (char**)&(head); \ + *_head_alias = _tmp; \ + } \ + } \ +} while (0) +#ifdef NO_DECLTYPE +#undef LL_APPEND +#define LL_APPEND LL_APPEND_VS2008 +#undef LL_DELETE +#define LL_DELETE LL_DELETE_VS2008 +#undef LL_CONCAT /* no LL_CONCAT_VS2008 */ +#undef DL_CONCAT /* no DL_CONCAT_VS2008 */ +#endif +/* end VS2008 replacements */ + +#define LL_FOREACH(head,el) \ + for(el=head;el;el=(el)->next) + +#define LL_FOREACH_SAFE(head,el,tmp) \ + for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) + +#define LL_SEARCH_SCALAR(head,out,field,val) \ +do { \ + LL_FOREACH(head,out) { \ + if ((out)->field == (val)) break; \ + } \ +} while(0) + +#define LL_SEARCH(head,out,elt,cmp) \ +do { \ + LL_FOREACH(head,out) { \ + if ((cmp(out,elt))==0) break; \ + } \ +} while(0) + +/****************************************************************************** + * doubly linked list macros (non-circular) * + *****************************************************************************/ +#define DL_PREPEND(head,add) \ +do { \ + (add)->next = head; \ + if (head) { \ + (add)->prev = (head)->prev; \ + (head)->prev = (add); \ + } else { \ + (add)->prev = (add); \ + } \ + (head) = (add); \ +} while (0) + +#define DL_APPEND(head,add) \ +do { \ + if (head) { \ + (add)->prev = (head)->prev; \ + (head)->prev->next = (add); \ + (head)->prev = (add); \ + (add)->next = NULL; \ + } else { \ + (head)=(add); \ + (head)->prev = (head); \ + (head)->next = NULL; \ + } \ +} while (0) + +#define DL_CONCAT(head1,head2) \ +do { \ + LDECLTYPE(head1) _tmp; \ + if (head2) { \ + if (head1) { \ + _tmp = (head2)->prev; \ + (head2)->prev = (head1)->prev; \ + (head1)->prev->next = (head2); \ + (head1)->prev = _tmp; \ + } else { \ + (head1)=(head2); \ + } \ + } \ +} while (0) + +#define DL_DELETE(head,del) \ +do { \ + assert((del)->prev != NULL); \ + if ((del)->prev == (del)) { \ + (head)=NULL; \ + } else if ((del)==(head)) { \ + (del)->next->prev = (del)->prev; \ + (head) = (del)->next; \ + } else { \ + (del)->prev->next = (del)->next; \ + if ((del)->next) { \ + (del)->next->prev = (del)->prev; \ + } else { \ + (head)->prev = (del)->prev; \ + } \ + } \ +} while (0) + + +#define DL_FOREACH(head,el) \ + for(el=head;el;el=(el)->next) + +/* this version is safe for deleting the elements during iteration */ +#define DL_FOREACH_SAFE(head,el,tmp) \ + for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) + +/* these are identical to their singly-linked list counterparts */ +#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR +#define DL_SEARCH LL_SEARCH + +/****************************************************************************** + * circular doubly linked list macros * + *****************************************************************************/ +#define CDL_PREPEND(head,add) \ +do { \ + if (head) { \ + (add)->prev = (head)->prev; \ + (add)->next = (head); \ + (head)->prev = (add); \ + (add)->prev->next = (add); \ + } else { \ + (add)->prev = (add); \ + (add)->next = (add); \ + } \ +(head)=(add); \ +} while (0) + +#define CDL_DELETE(head,del) \ +do { \ + if ( ((head)==(del)) && ((head)->next == (head))) { \ + (head) = 0L; \ + } else { \ + (del)->next->prev = (del)->prev; \ + (del)->prev->next = (del)->next; \ + if ((del) == (head)) (head)=(del)->next; \ + } \ +} while (0) + +#define CDL_FOREACH(head,el) \ + for(el=head;el;el=((el)->next==head ? 0L : (el)->next)) + +#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2) \ + for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL); \ + (el) && ((tmp2)=(el)->next, 1); \ + ((el) = (((el)==(tmp1)) ? 0L : (tmp2)))) + +#define CDL_SEARCH_SCALAR(head,out,field,val) \ +do { \ + CDL_FOREACH(head,out) { \ + if ((out)->field == (val)) break; \ + } \ +} while(0) + +#define CDL_SEARCH(head,out,elt,cmp) \ +do { \ + CDL_FOREACH(head,out) { \ + if ((cmp(out,elt))==0) break; \ + } \ +} while(0) + +#endif /* UTLIST_H */ + diff --git a/apps/systemlib/uthash/utstring.h b/apps/systemlib/uthash/utstring.h new file mode 100644 index 0000000000..a181ad7785 --- /dev/null +++ b/apps/systemlib/uthash/utstring.h @@ -0,0 +1,148 @@ +/* +Copyright (c) 2008-2012, Troy D. Hanson http://uthash.sourceforge.net +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* a dynamic string implementation using macros + * see http://uthash.sourceforge.net/utstring + */ +#ifndef UTSTRING_H +#define UTSTRING_H + +#define UTSTRING_VERSION 1.9.6 + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((__unused__)) +#else +#define _UNUSED_ +#endif + +#include +#include +#include +#define oom() exit(-1) + +typedef struct { + char *d; + size_t n; /* allocd size */ + size_t i; /* index of first unused byte */ +} UT_string; + +#define utstring_reserve(s,amt) \ +do { \ + if (((s)->n - (s)->i) < (size_t)(amt)) { \ + (s)->d = (char*)realloc((s)->d, (s)->n + amt); \ + if ((s)->d == NULL) oom(); \ + (s)->n += amt; \ + } \ +} while(0) + +#define utstring_init(s) \ +do { \ + (s)->n = 0; (s)->i = 0; (s)->d = NULL; \ + utstring_reserve(s,100); \ + (s)->d[0] = '\0'; \ +} while(0) + +#define utstring_done(s) \ +do { \ + if ((s)->d != NULL) free((s)->d); \ + (s)->n = 0; \ +} while(0) + +#define utstring_free(s) \ +do { \ + utstring_done(s); \ + free(s); \ +} while(0) + +#define utstring_new(s) \ +do { \ + s = (UT_string*)calloc(sizeof(UT_string),1); \ + if (!s) oom(); \ + utstring_init(s); \ +} while(0) + +#define utstring_renew(s) \ +do { \ + if (s) { \ + utstring_clear(s); \ + } else { \ + utstring_new(s); \ + } \ +} while(0) + +#define utstring_clear(s) \ +do { \ + (s)->i = 0; \ + (s)->d[0] = '\0'; \ +} while(0) + +#define utstring_bincpy(s,b,l) \ +do { \ + utstring_reserve((s),(l)+1); \ + if (l) memcpy(&(s)->d[(s)->i], b, l); \ + (s)->i += l; \ + (s)->d[(s)->i]='\0'; \ +} while(0) + +#define utstring_concat(dst,src) \ +do { \ + utstring_reserve((dst),((src)->i)+1); \ + if ((src)->i) memcpy(&(dst)->d[(dst)->i], (src)->d, (src)->i); \ + (dst)->i += (src)->i; \ + (dst)->d[(dst)->i]='\0'; \ +} while(0) + +#define utstring_len(s) ((unsigned)((s)->i)) + +#define utstring_body(s) ((s)->d) + +_UNUSED_ static void utstring_printf_va(UT_string *s, const char *fmt, va_list ap) { + int n; + va_list cp; + while (1) { +#ifdef _WIN32 + cp = ap; +#else + va_copy(cp, ap); +#endif + n = vsnprintf (&s->d[s->i], s->n-s->i, fmt, cp); + va_end(cp); + + if ((n > -1) && (n < (int)(s->n-s->i))) { + s->i += n; + return; + } + + /* Else try again with more space. */ + if (n > -1) utstring_reserve(s,n+1); /* exact */ + else utstring_reserve(s,(s->n)*2); /* 2x */ + } +} +_UNUSED_ static void utstring_printf(UT_string *s, const char *fmt, ...) { + va_list ap; + va_start(ap,fmt); + utstring_printf_va(s,fmt,ap); + va_end(ap); +} + +#endif /* UTSTRING_H */ diff --git a/apps/uORB/Makefile b/apps/uORB/Makefile index 0766a66eb0..64ba52e9c5 100644 --- a/apps/uORB/Makefile +++ b/apps/uORB/Makefile @@ -37,6 +37,6 @@ APPNAME = uorb PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +STACKSIZE = 4096 include $(APPDIR)/mk/app.mk diff --git a/apps/uORB/objects_common.cpp b/apps/uORB/objects_common.cpp index d6b566b6a8..1cad57a436 100644 --- a/apps/uORB/objects_common.cpp +++ b/apps/uORB/objects_common.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ /** - * @file objects_common.h + * @file objects_common.cpp * * Common object definitions without a better home. */ @@ -78,18 +78,12 @@ ORB_DEFINE(vehicle_global_position, struct vehicle_global_position_s); #include "topics/vehicle_local_position.h" ORB_DEFINE(vehicle_local_position, struct vehicle_local_position_s); -#include "topics/ardrone_control.h" -ORB_DEFINE(ardrone_control, struct ardrone_control_s); - #include "topics/ardrone_motors_setpoint.h" ORB_DEFINE(ardrone_motors_setpoint, struct ardrone_motors_setpoint_s); #include "topics/rc_channels.h" ORB_DEFINE(rc_channels, struct rc_channels_s); -#include "topics/fixedwing_control.h" -ORB_DEFINE(fixedwing_control, struct fixedwing_control_s); - #include "topics/vehicle_command.h" ORB_DEFINE(vehicle_command, struct vehicle_command_s); @@ -108,9 +102,21 @@ ORB_DEFINE(manual_control_setpoint, struct manual_control_setpoint_s); #include "topics/optical_flow.h" ORB_DEFINE(optical_flow, struct optical_flow_s); +#include "topics/subsystem_info.h" +ORB_DEFINE(subsystem_info, struct subsystem_info_s); + #include "topics/actuator_controls.h" ORB_DEFINE(actuator_controls_0, struct actuator_controls_s); ORB_DEFINE(actuator_controls_1, struct actuator_controls_s); ORB_DEFINE(actuator_controls_2, struct actuator_controls_s); ORB_DEFINE(actuator_controls_3, struct actuator_controls_s); ORB_DEFINE(actuator_armed, struct actuator_armed_s); + +#include "topics/actuator_outputs.h" +ORB_DEFINE(actuator_outputs_0, struct actuator_outputs_s); +ORB_DEFINE(actuator_outputs_1, struct actuator_outputs_s); +ORB_DEFINE(actuator_outputs_2, struct actuator_outputs_s); +ORB_DEFINE(actuator_outputs_3, struct actuator_outputs_s); + +#include "topics/debug_key_value.h" +ORB_DEFINE(debug_key_value, struct debug_key_value_s); diff --git a/apps/uORB/parameter_storage.c b/apps/uORB/parameter_storage.c deleted file mode 100644 index f4bd1c7120..0000000000 --- a/apps/uORB/parameter_storage.c +++ /dev/null @@ -1,379 +0,0 @@ - -#include "parameter_storage.h" -#include - - -/* Global symbols / flags */ - -struct global_data_parameter_storage_t global_data_parameter_storage_d = { /*.counter = 0, .timestamp = 0,*/ .pm = {.size = PARAM_MAX_COUNT, - .param_values[PARAM_SYSTEM_ID] = 12, - .param_names[PARAM_SYSTEM_ID] = "SYS_ID", - .param_needs_write[PARAM_SYSTEM_ID] = false, - - .param_values[PARAM_COMP_ID] = 200, - .param_names[PARAM_COMP_ID] = "COMP_ID", - .param_needs_write[PARAM_COMP_ID] = false, - - .param_values[PARAM_FLIGHT_ENV] = (float)PX4_FLIGHT_ENVIRONMENT_INDOOR, - .param_names[PARAM_FLIGHT_ENV] = "FLIGHT_ENV", - .param_needs_write[PARAM_FLIGHT_ENV] = false, - - .param_values[PARAM_BATTERYVOLTAGE_CONVERSION] = -1.f, - .param_names[PARAM_BATTERYVOLTAGE_CONVERSION] = "BATVOLTAG_CONV", - .param_needs_write[PARAM_BATTERYVOLTAGE_CONVERSION] = false, - - .param_values[PARAM_PID_YAWPOS_P] = 0.3f, - .param_names[PARAM_PID_YAWPOS_P] = "PID_YAWPOS_P", - .param_needs_write[PARAM_PID_YAWPOS_P] = false, - - .param_values[PARAM_PID_YAWPOS_I] = 0.15f, - .param_names[PARAM_PID_YAWPOS_I] = "PID_YAWPOS_I", - .param_needs_write[PARAM_PID_YAWPOS_I] = false, - - .param_values[PARAM_PID_YAWPOS_D] = 0.0f, - .param_names[PARAM_PID_YAWPOS_D] = "PID_YAWPOS_D", - .param_needs_write[PARAM_PID_YAWPOS_D] = false, - - .param_values[PARAM_PID_YAWPOS_AWU] = 1.0f, - .param_names[PARAM_PID_YAWPOS_AWU] = "PID_YAWPOS_AWU", - .param_needs_write[PARAM_PID_YAWPOS_AWU] = false, - - .param_values[PARAM_PID_YAWPOS_LIM] = 3.0f, - .param_names[PARAM_PID_YAWPOS_LIM] = "PID_YAWPOS_LIM", - .param_needs_write[PARAM_PID_YAWPOS_LIM] = false, - - .param_values[PARAM_PID_YAWSPEED_P] = 0.1f, - .param_names[PARAM_PID_YAWSPEED_P] = "PID_YAWSPD_P", - .param_needs_write[PARAM_PID_YAWSPEED_P] = false, - - .param_values[PARAM_PID_YAWSPEED_I] = 0.02f, - .param_names[PARAM_PID_YAWSPEED_I] = "PID_YAWSPD_I", - .param_needs_write[PARAM_PID_YAWSPEED_I] = false, - - .param_values[PARAM_PID_YAWSPEED_D] = 0.0f, - .param_names[PARAM_PID_YAWSPEED_D] = "PID_YAWSPD_D", - .param_needs_write[PARAM_PID_YAWSPEED_D] = false, - - .param_values[PARAM_PID_YAWSPEED_AWU] = 0.02f, - .param_names[PARAM_PID_YAWSPEED_AWU] = "PID_YAWSPD_AWU", - .param_needs_write[PARAM_PID_YAWSPEED_AWU] = false, - - .param_values[PARAM_PID_YAWSPEED_LIM] = 0.1f, - .param_names[PARAM_PID_YAWSPEED_LIM] = "PID_YAWSPD_LIM", - .param_needs_write[PARAM_PID_YAWSPEED_LIM] = false, - - .param_values[PARAM_PID_ATT_P] = 0.3f, - .param_names[PARAM_PID_ATT_P] = "PID_ATT_P", - .param_needs_write[PARAM_PID_ATT_P] = false, - - .param_values[PARAM_PID_ATT_I] = 0.0f, - .param_names[PARAM_PID_ATT_I] = "PID_ATT_I", - .param_needs_write[PARAM_PID_ATT_I] = false, - - .param_values[PARAM_PID_ATT_D] = 0.1f, - .param_names[PARAM_PID_ATT_D] = "PID_ATT_D", - .param_needs_write[PARAM_PID_ATT_D] = false, - - .param_values[PARAM_PID_ATT_AWU] = 0.05f, - .param_names[PARAM_PID_ATT_AWU] = "PID_ATT_AWU", - .param_needs_write[PARAM_PID_ATT_AWU] = false, - - .param_values[PARAM_PID_ATT_LIM] = 0.3f, - .param_names[PARAM_PID_ATT_LIM] = "PID_ATT_LIM", - .param_needs_write[PARAM_PID_ATT_LIM] = false, - - .param_values[PARAM_PID_POS_P] = 40.0f, - .param_names[PARAM_PID_POS_P] = "PID_POS_P", - .param_needs_write[PARAM_PID_POS_P] = false, - - .param_values[PARAM_PID_POS_I] = 0.0f, - .param_names[PARAM_PID_POS_I] = "PID_POS_I", - .param_needs_write[PARAM_PID_POS_I] = false, - - .param_values[PARAM_PID_POS_D] = 0.0f, - .param_names[PARAM_PID_POS_D] = "PID_POS_D", - .param_needs_write[PARAM_PID_POS_D] = false, - - .param_values[PARAM_PID_POS_AWU] = 5.0f, - .param_names[PARAM_PID_POS_AWU] = "PID_POS_AWU", - .param_needs_write[PARAM_PID_POS_AWU] = false, - - .param_values[PARAM_PID_POS_LIM] = 0.3f, - .param_names[PARAM_PID_POS_LIM] = "PID_POS_LIM", - .param_needs_write[PARAM_PID_POS_LIM] = false, - - .param_values[PARAM_PID_POS_Z_P] = 10.0f, - .param_names[PARAM_PID_POS_Z_P] = "PID_POS_Z_P", - .param_needs_write[PARAM_PID_POS_Z_P] = false, - - .param_values[PARAM_PID_POS_Z_I] = 0.0f, - .param_names[PARAM_PID_POS_Z_I] = "PID_POS_Z_I", - .param_needs_write[PARAM_PID_POS_Z_I] = false, - - .param_values[PARAM_PID_POS_Z_D] = 0.0f, - .param_names[PARAM_PID_POS_Z_D] = "PID_POS_Z_D", - .param_needs_write[PARAM_PID_POS_Z_D] = false, - - .param_values[PARAM_PID_POS_Z_AWU] = 3.0f, - .param_names[PARAM_PID_POS_Z_AWU] = "PID_POS_Z_AWU", - .param_needs_write[PARAM_PID_POS_Z_AWU] = false, - - .param_values[PARAM_PID_POS_Z_LIM] = 0.3f, - .param_names[PARAM_PID_POS_Z_LIM] = "PID_POS_Z_LIM", - .param_needs_write[PARAM_PID_POS_Z_LIM] = false, - - .param_values[PARAM_AIRSPEED] = 30.0f, - .param_names[PARAM_AIRSPEED] = "AIRSPEED", - .param_needs_write[PARAM_AIRSPEED] = false, - - .param_values[PARAM_WPLON] = -120.0f, - .param_names[PARAM_WPLON] = "WPLON", - .param_needs_write[PARAM_WPLON] = false, - - .param_values[PARAM_WPLAT] = 38.0f, - .param_names[PARAM_WPLAT] = "WPLAT", - .param_needs_write[PARAM_WPLAT] = false, - - .param_values[PARAM_WPALT] = 500.0f, - .param_names[PARAM_WPALT] = "WPALT", - .param_needs_write[PARAM_WPALT] = false, - - .param_values[PARAM_FLIGHTMODE] = CRUISE, - .param_names[PARAM_FLIGHTMODE] = "FLIGHTMODE", - .param_needs_write[PARAM_FLIGHTMODE] = false, - - .param_values[PARAM_SENSOR_GYRO_XOFFSET] = 700.f, - .param_names[PARAM_SENSOR_GYRO_XOFFSET] = "SENSOR_GYRO_XOF", - .param_needs_write[PARAM_SENSOR_GYRO_XOFFSET] = false, - - .param_values[PARAM_SENSOR_GYRO_YOFFSET] = 1400.0f, - .param_names[PARAM_SENSOR_GYRO_YOFFSET] = "SENSOR_GYRO_YOF", - .param_needs_write[PARAM_SENSOR_GYRO_YOFFSET] = false, - - .param_values[PARAM_SENSOR_GYRO_ZOFFSET] = 0.0f, - .param_names[PARAM_SENSOR_GYRO_ZOFFSET] = "SENSOR_GYRO_ZOF", - .param_needs_write[PARAM_SENSOR_GYRO_ZOFFSET] = false, - - .param_values[PARAM_SENSOR_MAG_XOFFSET] = 422.0f, - .param_names[PARAM_SENSOR_MAG_XOFFSET] = "SENSOR_MAG_XOF", - .param_needs_write[PARAM_SENSOR_MAG_XOFFSET] = false, - - .param_values[PARAM_SENSOR_MAG_YOFFSET] = -85.0f, - .param_names[PARAM_SENSOR_MAG_YOFFSET] = "SENSOR_MAG_YOF", - .param_needs_write[PARAM_SENSOR_MAG_YOFFSET] = false, - - .param_values[PARAM_SENSOR_MAG_ZOFFSET] = -370.0f, - .param_names[PARAM_SENSOR_MAG_ZOFFSET] = "SENSOR_MAG_ZOF", - .param_needs_write[PARAM_SENSOR_MAG_ZOFFSET] = false, - - .param_values[PARAM_ATT_XOFFSET] = 0.0f, - .param_names[PARAM_ATT_XOFFSET] = "ATT_XOFF", - .param_needs_write[PARAM_ATT_XOFFSET] = false, - - .param_values[PARAM_ATT_YOFFSET] = 0.0f, - .param_names[PARAM_ATT_YOFFSET] = "ATT_YOFF", - .param_needs_write[PARAM_ATT_YOFFSET] = false, - - .param_values[PARAM_RC1_MIN] = 1000.0f, - .param_names[PARAM_RC1_MIN] = "RC1_MIN", - .param_needs_write[PARAM_RC1_MIN] = false, - - .param_values[PARAM_RC1_MAX] = 2000.0f, - .param_names[PARAM_RC1_MAX] = "RC1_MAX", - .param_needs_write[PARAM_RC1_MAX] = false, - - .param_values[PARAM_RC1_TRIM] = 1500.0f, - .param_names[PARAM_RC1_TRIM] = "RC1_TRIM", - .param_needs_write[PARAM_RC1_TRIM] = false, - - .param_values[PARAM_RC1_REV] = 1.0f, - .param_names[PARAM_RC1_REV] = "RC1_REV", - .param_needs_write[PARAM_RC1_REV] = false, - - .param_values[PARAM_RC2_MIN] = 1000.0f, - .param_names[PARAM_RC2_MIN] = "RC2_MIN", - .param_needs_write[PARAM_RC2_MIN] = false, - - .param_values[PARAM_RC2_MAX] = 2000.0f, - .param_names[PARAM_RC2_MAX] = "RC2_MAX", - .param_needs_write[PARAM_RC2_MAX] = false, - - .param_values[PARAM_RC2_TRIM] = 1500.0f, - .param_names[PARAM_RC2_TRIM] = "RC2_TRIM", - .param_needs_write[PARAM_RC2_TRIM] = false, - - .param_values[PARAM_RC2_REV] = 1.0f, - .param_names[PARAM_RC2_REV] = "RC2_REV", - .param_needs_write[PARAM_RC2_REV] = false, - - .param_values[PARAM_RC3_MIN] = 1000.0f, - .param_names[PARAM_RC3_MIN] = "RC3_MIN", - .param_needs_write[PARAM_RC3_MIN] = false, - - .param_values[PARAM_RC3_MAX] = 2000.0f, - .param_names[PARAM_RC3_MAX] = "RC3_MAX", - .param_needs_write[PARAM_RC3_MAX] = false, - - .param_values[PARAM_RC3_TRIM] = 1500.0f, - .param_names[PARAM_RC3_TRIM] = "RC3_TRIM", - .param_needs_write[PARAM_RC3_TRIM] = false, - - .param_values[PARAM_RC3_REV] = 1.0f, - .param_names[PARAM_RC3_REV] = "RC3_REV", - .param_needs_write[PARAM_RC3_REV] = false, - - .param_values[PARAM_RC4_MIN] = 1000.0f, - .param_names[PARAM_RC4_MIN] = "RC4_MIN", - .param_needs_write[PARAM_RC4_MIN] = false, - - .param_values[PARAM_RC4_MAX] = 2000.0f, - .param_names[PARAM_RC4_MAX] = "RC4_MAX", - .param_needs_write[PARAM_RC4_MAX] = false, - - .param_values[PARAM_RC4_TRIM] = 1500.0f, - .param_names[PARAM_RC4_TRIM] = "RC4_TRIM", - .param_needs_write[PARAM_RC4_TRIM] = false, - - .param_values[PARAM_RC4_REV] = 1.0f, - .param_names[PARAM_RC4_REV] = "RC4_REV", - .param_needs_write[PARAM_RC4_MIN] = false, - - .param_values[PARAM_RC5_MIN] = 1000.0f, - .param_names[PARAM_RC5_MIN] = "RC5_MIN", - .param_needs_write[PARAM_RC5_MIN] = false, - - .param_values[PARAM_RC5_MAX] = 2000.0f, - .param_names[PARAM_RC5_MAX] = "RC5_MAX", - .param_needs_write[PARAM_RC5_MAX] = false, - - .param_values[PARAM_RC5_TRIM] = 1500.0f, - .param_names[PARAM_RC5_TRIM] = "RC5_TRIM", - .param_needs_write[PARAM_RC5_TRIM] = false, - - .param_values[PARAM_RC5_REV] = 1.0f, - .param_names[PARAM_RC5_REV] = "RC5_REV", - .param_needs_write[PARAM_RC5_REV] = false, - - .param_values[PARAM_RC6_MIN] = 1000.0f, - .param_names[PARAM_RC6_MIN] = "RC6_MIN", - .param_needs_write[PARAM_RC6_MIN] = false, - - .param_values[PARAM_RC6_MAX] = 2000.0f, - .param_names[PARAM_RC6_MAX] = "RC6_MAX", - .param_needs_write[PARAM_RC6_MAX] = false, - - .param_values[PARAM_RC6_TRIM] = 1500.0f, - .param_names[PARAM_RC6_TRIM] = "RC6_TRIM", - .param_needs_write[PARAM_RC6_TRIM] = false, - - .param_values[PARAM_RC6_REV] = 1.0f, - .param_names[PARAM_RC6_REV] = "RC6_REV", - .param_needs_write[PARAM_RC6_REV] = false, - - .param_values[PARAM_RC7_MIN] = 1000, - .param_names[PARAM_RC7_MIN] = "RC7_MIN", - .param_needs_write[PARAM_RC7_MIN] = false, - - .param_values[PARAM_RC7_MAX] = 2000, - .param_names[PARAM_RC7_MAX] = "RC7_MAX", - .param_needs_write[PARAM_RC7_MAX] = false, - - .param_values[PARAM_RC7_TRIM] = 1500, - .param_names[PARAM_RC7_TRIM] = "RC7_TRIM", - .param_needs_write[PARAM_RC7_TRIM] = false, - - .param_values[PARAM_RC7_REV] = 1.0f, - .param_names[PARAM_RC7_REV] = "RC7_REV", - .param_needs_write[PARAM_RC7_REV] = false, - - .param_values[PARAM_RC8_MIN] = 1000, - .param_names[PARAM_RC8_MIN] = "RC8_MIN", - .param_needs_write[PARAM_RC8_MIN] = false, - - .param_values[PARAM_RC8_MAX] = 2000, - .param_names[PARAM_RC8_MAX] = "RC8_MAX", - .param_needs_write[PARAM_RC8_MAX] = false, - - .param_values[PARAM_RC8_TRIM] = 1500, - .param_names[PARAM_RC8_TRIM] = "RC8_TRIM", - .param_needs_write[PARAM_RC8_TRIM] = false, - - .param_values[PARAM_RC8_REV] = 1.0f, - .param_names[PARAM_RC8_REV] = "RC8_REV", - .param_needs_write[PARAM_RC8_REV] = false, - - .param_values[PARAM_ROLL_CHAN] = 1, - .param_names[PARAM_ROLL_CHAN] = "ROLL_CHAN", - .param_needs_write[PARAM_ROLL_CHAN] = false, - - .param_values[PARAM_PITCH_CHAN] = 2, - .param_names[PARAM_PITCH_CHAN] = "PITCH_CHAN", - .param_needs_write[PARAM_PITCH_CHAN] = false, - - .param_values[PARAM_THROTTLE_CHAN] = 3, - .param_names[PARAM_THROTTLE_CHAN] = "THROTTLE_CHAN", - .param_needs_write[PARAM_THROTTLE_CHAN] = false, - - .param_values[PARAM_YAW_CHAN] = 4, - .param_names[PARAM_YAW_CHAN] = "YAW_CHAN", - .param_needs_write[PARAM_YAW_CHAN] = false, - - .param_values[PARAM_OVERRIDE_CHAN] = 5, - .param_names[PARAM_OVERRIDE_CHAN] = "OVERRIDE_CHAN", - .param_needs_write[PARAM_OVERRIDE_CHAN] = false, - - .param_values[PARAM_SERVO1_MIN] = 1000.0f, - .param_names[PARAM_SERVO1_MIN] = "SERVO1_MIN", - .param_needs_write[PARAM_SERVO1_MIN] = false, - - .param_values[PARAM_SERVO1_MAX] = 2000.0f, - .param_names[PARAM_SERVO1_MAX] = "SERVO1_MAX", - .param_needs_write[PARAM_SERVO1_MAX] = false, - - .param_values[PARAM_SERVO1_TRIM] = 1500.0f, - .param_names[PARAM_SERVO1_TRIM] = "SERVO1_TRIM", - .param_needs_write[PARAM_SERVO1_TRIM] = false, - - .param_values[PARAM_SERVO2_MIN] = 1000.0f, - .param_names[PARAM_SERVO2_MIN] = "SERVO2_MIN", - .param_needs_write[PARAM_SERVO2_MIN] = false, - - .param_values[PARAM_SERVO2_MAX] = 2000.0f, - .param_names[PARAM_SERVO2_MAX] = "SERVO2_MAX", - .param_needs_write[PARAM_SERVO2_MAX] = false, - - .param_values[PARAM_SERVO2_TRIM] = 1500.0f, - .param_names[PARAM_SERVO2_TRIM] = "SERVO2_TRIM", - .param_needs_write[PARAM_SERVO2_TRIM] = false, - - .param_values[PARAM_SERVO3_MIN] = 1000.0f, - .param_names[PARAM_SERVO3_MIN] = "SERVO3_MIN", - .param_needs_write[PARAM_SERVO3_MIN] = false, - - .param_values[PARAM_SERVO3_MAX] = 2000.0f, - .param_names[PARAM_SERVO3_MAX] = "SERVO3_MAX", - .param_needs_write[PARAM_SERVO3_MAX] = false, - - .param_values[PARAM_SERVO3_TRIM] = 1500.0f, - .param_names[PARAM_SERVO3_TRIM] = "SERVO3_TRIM", - .param_needs_write[PARAM_SERVO3_TRIM] = false, - - .param_values[PARAM_SERVO4_MIN] = 1000.0f, - .param_names[PARAM_SERVO4_MIN] = "SERVO4_MIN", - .param_needs_write[PARAM_SERVO4_MIN] = false, - - .param_values[PARAM_SERVO4_MAX] = 2000.0f, - .param_names[PARAM_SERVO4_MAX] = "SERVO4_MAX", - .param_needs_write[PARAM_SERVO4_MAX] = false, - - .param_values[PARAM_SERVO4_TRIM] = 1500.0f, - .param_names[PARAM_SERVO4_TRIM] = "SERVO4_TRIM", - .param_needs_write[PARAM_SERVO4_TRIM] = false, - - .param_values[PARAM_SERVO_SCALE] = 20.0f, - .param_names[PARAM_SERVO_SCALE] = "SERVO_SCALE", - .param_needs_write[PARAM_SERVO_SCALE] = false - } -}; - -struct global_data_parameter_storage_t *global_data_parameter_storage = &global_data_parameter_storage_d; diff --git a/apps/uORB/parameter_storage.h b/apps/uORB/parameter_storage.h deleted file mode 100644 index aa4c1bb4fb..0000000000 --- a/apps/uORB/parameter_storage.h +++ /dev/null @@ -1,152 +0,0 @@ -/* Structure for storage of parameters */ - -#ifndef GLOBAL_DATA_PARAMETER_STORAGE_T_H_ //adjust this line! -#define GLOBAL_DATA_PARAMETER_STORAGE_T_H_ //adjust this line! - -#define PX4_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN 16 -#define MAX_PARAM_NAME_LEN 16 - -#include -#include - -enum MODE { - TAKEOFF = 1, - CRUISE, - LOITER, - LAND -}; - -enum PARAM { - PARAM_SYSTEM_ID = 0, ///< System ID used for communication - PARAM_COMP_ID, ///< Component ID - PARAM_FLIGHT_ENV, ///< Flight environment, indoor or outdoor - PARAM_BATTERYVOLTAGE_CONVERSION, ///< Conversion factor from adc measurement to millivolts. if not set the sensor app will use the default value for the ardrone board - PARAM_PID_YAWPOS_P, - PARAM_PID_YAWPOS_I, - PARAM_PID_YAWPOS_D, - PARAM_PID_YAWPOS_AWU, - PARAM_PID_YAWPOS_LIM, - PARAM_PID_YAWSPEED_P, - PARAM_PID_YAWSPEED_I, - PARAM_PID_YAWSPEED_D, - PARAM_PID_YAWSPEED_AWU, - PARAM_PID_YAWSPEED_LIM, - PARAM_PID_ATT_P, - PARAM_PID_ATT_I, - PARAM_PID_ATT_D, - PARAM_PID_ATT_AWU, - PARAM_PID_ATT_LIM, - PARAM_PID_POS_P, - PARAM_PID_POS_I, - PARAM_PID_POS_D, - PARAM_PID_POS_AWU, - PARAM_PID_POS_LIM, - PARAM_PID_POS_Z_P, - PARAM_PID_POS_Z_I, - PARAM_PID_POS_Z_D, - PARAM_PID_POS_Z_AWU, - PARAM_PID_POS_Z_LIM, - PARAM_AIRSPEED, - PARAM_WPLON, - PARAM_WPLAT, - PARAM_WPALT, - PARAM_FLIGHTMODE, - PARAM_SENSOR_GYRO_XOFFSET, - PARAM_SENSOR_GYRO_YOFFSET, - PARAM_SENSOR_GYRO_ZOFFSET, - PARAM_SENSOR_MAG_XOFFSET, - PARAM_SENSOR_MAG_YOFFSET, - PARAM_SENSOR_MAG_ZOFFSET, - PARAM_ATT_XOFFSET, - PARAM_ATT_YOFFSET, - PARAM_RC1_MIN, - PARAM_RC1_MAX, - PARAM_RC1_TRIM, - PARAM_RC1_REV, - PARAM_RC2_MIN, - PARAM_RC2_MAX, - PARAM_RC2_TRIM, - PARAM_RC2_REV, - PARAM_RC3_MIN, - PARAM_RC3_MAX, - PARAM_RC3_TRIM, - PARAM_RC3_REV, - PARAM_RC4_MIN, - PARAM_RC4_MAX, - PARAM_RC4_TRIM, - PARAM_RC4_REV, - PARAM_RC5_MIN, - PARAM_RC5_MAX, - PARAM_RC5_TRIM, - PARAM_RC5_REV, - PARAM_RC6_MIN, - PARAM_RC6_MAX, - PARAM_RC6_TRIM, - PARAM_RC6_REV, - PARAM_RC7_MIN, - PARAM_RC7_MAX, - PARAM_RC7_TRIM, - PARAM_RC7_REV, - PARAM_RC8_MIN, - PARAM_RC8_MAX, - PARAM_RC8_TRIM, - PARAM_RC8_REV, - PARAM_THROTTLE_CHAN, - PARAM_ROLL_CHAN, - PARAM_PITCH_CHAN, - PARAM_YAW_CHAN, - PARAM_OVERRIDE_CHAN, - PARAM_SERVO1_MIN, - PARAM_SERVO1_MAX, - PARAM_SERVO1_TRIM, - PARAM_SERVO2_MIN, - PARAM_SERVO2_MAX, - PARAM_SERVO2_TRIM, - PARAM_SERVO3_MIN, - PARAM_SERVO3_MAX, - PARAM_SERVO3_TRIM, - PARAM_SERVO4_MIN, - PARAM_SERVO4_MAX, - PARAM_SERVO4_TRIM, - PARAM_SERVO_SCALE, - PARAM_MAX_COUNT ///< LEAVE THIS IN PLACE AS LAST ELEMENT! -}; - -#pragma pack(push, 1) -struct px4_parameter_storage_t { - float param_values[PARAM_MAX_COUNT]; ///< Parameter values - bool param_needs_write[PARAM_MAX_COUNT]; - const char *param_names[PARAM_MAX_COUNT]; ///< Parameter names - uint16_t next_param; - uint16_t size; -}; -#pragma pack(pop) - - -#define PX4_FLIGHT_ENVIRONMENT_INDOOR 0 -#define PX4_FLIGHT_ENVIRONMENT_OUTDOOR 1 -#define PX4_FLIGHT_ENVIRONMENT_TESTING 2 //NO check for position fix in this environment - -#pragma pack(push, 1) -struct global_data_parameter_storage_t { - - /* use of a counter and timestamp recommended (but not necessary) */ - -// uint16_t counter; //incremented by the writing thread everytime new data is stored - uint64_t timestamp; //in microseconds since system start, is set whenever the writing thread stores new data - - /* Actual data, this is specific to the type of data which is stored in this struct */ - - //***** Start: Add your variables here ***** - - /* Parameters (set by a param_set mavlink message */ - struct px4_parameter_storage_t pm; - - //*****END: Add your variables here ***** - -}; -#pragma pack(pop) - -__attribute__ ((visibility ("default"))) extern struct global_data_parameter_storage_t *global_data_parameter_storage; //adjust this line! - -#endif diff --git a/apps/uORB/topics/UNPORTED_subsystem_info.h b/apps/uORB/topics/UNPORTED_subsystem_info.h deleted file mode 100644 index 24f973a02c..0000000000 --- a/apps/uORB/topics/UNPORTED_subsystem_info.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Structure for storage of shared variables (extended( */ - -/* global_data_subsystem_info stores a buffer of the sensor info/status messages (sent by sensors or gps app), this is then handled by the commander. (The commander then writes to global_data_sys_status which is read by mavlink) */ - -/* (any app) --> global_data_subsystem_info (buffered) --> (commander app) --> global_data_sys_status --> (mavlink app) */ - -#ifndef GLOBAL_DATA_SUBSYSTEM_INFO_T_H_ //adjust this line! -#define GLOBAL_DATA_SUBSYSTEM_INFO_T_H_ //adjust this line! - -#define SUBSYSTEM_INFO_BUFFER_SIZE 10 - -#include "global_data_access.h" - -typedef enum //values correspond to bitmasks of mavlink message sys_status, this is crucial for the underlying bitmask to work -{ - SUBSYSTEM_TYPE_GYRO = 0, - SUBSYSTEM_TYPE_ACC = 1, - SUBSYSTEM_TYPE_MAG = 2, - SUBSYSTEM_TYPE_ABSPRESSURE = 3, - SUBSYSTEM_TYPE_DIFFPRESSURE = 4, - SUBSYSTEM_TYPE_GPS = 5, - SUBSYSTEM_TYPE_OPTICALFLOW = 6, - SUBSYSTEM_TYPE_CVPOSITION = 7, - SUBSYSTEM_TYPE_LASERPOSITION = 8, - SUBSYSTEM_TYPE_EXTERNALGROUNDTRUTH = 9, - SUBSYSTEM_TYPE_ANGULARRATECONTROL = 10, - SUBSYSTEM_TYPE_ATTITUDESTABILIZATION = 11, - SUBSYSTEM_TYPE_YAWPOSITION = 12, - SUBSYSTEM_TYPE_ALTITUDECONTROL = 13, - SUBSYSTEM_TYPE_POSITIONCONTROL = 14, - SUBSYSTEM_TYPE_MOTORCONTROL = 15 - -} subsystem_type_t; - -typedef struct -{ - uint8_t present; - uint8_t enabled; - uint8_t health; - - subsystem_type_t subsystem_type; - -} __attribute__((__packed__)) subsystem_info_t; - -typedef struct -{ - /* Struct which stores the access configuration, this is the same for all shared structs */ - - access_conf_t access_conf; //don't remove this line! - - /* use of a counter and timestamp recommended (but not necessary) */ - - uint16_t counter; //incremented by the writing thread everytime new data is stored - uint64_t timestamp; //in microseconds since system start, is set whenever the writing thread stores new data - - /* Actual data, this is specific to the type of data which is stored in this struct */ - - //***** Start: Add your variables here ***** - subsystem_info_t info[SUBSYSTEM_INFO_BUFFER_SIZE]; - uint8_t current_info; - - //*****END: Add your variables here ***** - -} global_data_subsystem_info_t; //adjust this line! - -extern global_data_subsystem_info_t* global_data_subsystem_info; //adjust this line! - -#endif diff --git a/apps/uORB/topics/actuator_controls.h b/apps/uORB/topics/actuator_controls.h index 2b7d7de5d9..0b50a29ac8 100644 --- a/apps/uORB/topics/actuator_controls.h +++ b/apps/uORB/topics/actuator_controls.h @@ -53,6 +53,7 @@ #define NUM_ACTUATOR_CONTROL_GROUPS 4 /**< for sanity checking */ struct actuator_controls_s { + uint64_t timestamp; float control[NUM_ACTUATOR_CONTROLS]; }; @@ -67,7 +68,8 @@ ORB_DECLARE(actuator_controls_3); /** global 'actuator output is live' control. */ struct actuator_armed_s { - bool armed; + bool armed; /**< Set to true if system is armed */ + bool lockdown; /**< Set to true if actuators are forced to being disabled (due to emergency or HIL) */ }; ORB_DECLARE(actuator_armed); diff --git a/apps/uORB/topics/actuator_outputs.h b/apps/uORB/topics/actuator_outputs.h new file mode 100644 index 0000000000..accd560afb --- /dev/null +++ b/apps/uORB/topics/actuator_outputs.h @@ -0,0 +1,69 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file actuator_outputs.h + * + * Actuator output values. + * + * Values published to these topics are the outputs of the control mixing + * system as sent to the actuators (servos, motors, etc.) that operate + * the vehicle. + * + * Each topic can be published by a single output driver. + */ + +#ifndef TOPIC_ACTUATOR_OUTPUTS_H +#define TOPIC_ACTUATOR_OUTPUTS_H + +#include +#include "../uORB.h" + +#define NUM_ACTUATOR_OUTPUTS 16 +#define NUM_ACTUATOR_OUTPUT_GROUPS 4 /**< for sanity checking */ + +struct actuator_outputs_s { + uint64_t timestamp; + float output[NUM_ACTUATOR_OUTPUTS]; +}; + +/* actuator output sets; this list can be expanded as more drivers emerge */ +ORB_DECLARE(actuator_outputs_0); +ORB_DECLARE(actuator_outputs_1); +ORB_DECLARE(actuator_outputs_2); +ORB_DECLARE(actuator_outputs_3); + +/* output sets with pre-defined applications */ +#define ORB_ID_VEHICLE_CONTROLS ORB_ID(actuator_outputs_0) + +#endif \ No newline at end of file diff --git a/apps/uORB/topics/ardrone_motors_setpoint.h b/apps/uORB/topics/ardrone_motors_setpoint.h index 54d81b7065..d0cb0ad733 100644 --- a/apps/uORB/topics/ardrone_motors_setpoint.h +++ b/apps/uORB/topics/ardrone_motors_setpoint.h @@ -50,14 +50,14 @@ struct ardrone_motors_setpoint_s { - uint16_t counter; //incremented by the writing thread everytime new data is stored uint64_t timestamp; //in microseconds since system start, is set whenever the writing thread stores new data - uint16_t motor_front_nw; ///< Front motor in + configuration, front left motor in x configuration - uint16_t motor_right_ne; ///< Right motor in + configuration, front right motor in x configuration - uint16_t motor_back_se; ///< Back motor in + configuration, back right motor in x configuration - uint16_t motor_left_sw; ///< Left motor in + configuration, back left motor in x configuration - + uint8_t group; /**< quadrotor group */ + uint8_t mode; /**< requested flight mode XXX define */ + float p1; /**< parameter 1: rate control: roll rate, att control: roll angle (in radians, NED) */ + float p2; /**< parameter 2: rate control: pitch rate, att control: pitch angle (in radians, NED) */ + float p3; /**< parameter 3: rate control: yaw rate, att control: yaw angle (in radians, NED) */ + float p4; /**< parameter 4: thrust, [0..1] */ }; /**< AR.Drone low level motors */ /** diff --git a/apps/uORB/topics/fixedwing_control.h b/apps/uORB/topics/debug_key_value.h similarity index 71% rename from apps/uORB/topics/fixedwing_control.h rename to apps/uORB/topics/debug_key_value.h index 5f70cad40b..a9d1b83fdc 100644 --- a/apps/uORB/topics/fixedwing_control.h +++ b/apps/uORB/topics/debug_key_value.h @@ -2,7 +2,6 @@ * * Copyright (C) 2012 PX4 Development Team. All rights reserved. * Author: @author Lorenz Meier - * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,36 +33,35 @@ ****************************************************************************/ /** - * @file fixedwing_control.h - * Definition of the fixedwing_control uORB topic. + * @file debug_key_value.h + * Definition of the debug named value uORB topic. Allows to send a 10-char key + * with a float as value. */ -#ifndef TOPIC_FIXEDWING_CONTROL_H_ -#define TOPIC_FIXEDWING_CONTROL_H_ +#ifndef TOPIC_DEBUG_KEY_VALUE_H_ +#define TOPIC_DEBUG_KEY_VALUE_H_ #include +#include #include "../uORB.h" /** * @addtogroup topics - * @{ */ /** - * fixed wing control status. + * Key/value pair for debugging */ -struct fixedwing_control_s -{ - /* use of a counter and timestamp recommended (but not necessary) */ +struct debug_key_value_s { - uint16_t counter; //incremented by the writing thread everytime new data is stored - uint64_t timestamp; //in microseconds since system start, is set whenever the writing thread stores new data - - float setpoint_rate_cast[3]; - float setpoint_attitude_rate[3]; - float setpoint_attitude[3]; - float attitude_control_output[4]; /**< roll, pitch, yaw, throttle */ - float position_control_output[4]; + /* + * Actual data, this is specific to the type of data which is stored in this struct + * A line containing L0GME will be added by the Python logging code generator to the + * logged dataset. + */ + uint32_t timestamp_ms; /**< in milliseconds since system start */ + char key[10]; /**< max. 10 characters as key / name */ + float value; /**< the value to send as debug output */ }; @@ -72,6 +70,6 @@ struct fixedwing_control_s */ /* register this as object request broker structure */ -ORB_DECLARE(fixedwing_control); +ORB_DECLARE(debug_key_value); -#endif //GLOBAL_DATA_FIXEDWING_CONTROL_T_H_ +#endif diff --git a/apps/multirotor_position_control/rate_control.h b/apps/uORB/topics/parameter_update.h similarity index 76% rename from apps/multirotor_position_control/rate_control.h rename to apps/uORB/topics/parameter_update.h index a69745d9b4..300e895c7d 100644 --- a/apps/multirotor_position_control/rate_control.h +++ b/apps/uORB/topics/parameter_update.h @@ -1,8 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Tobias Naegeli - * Lorenz Meier + * Copyright (C) 2012 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,16 +31,22 @@ * ****************************************************************************/ -/* - * @file Definition of attitude rate control +/** + * @file parameter_update.h + * Notification about a parameter update. */ -#ifndef RATE_CONTROL_H_ -#define RATE_CONTROL_H_ -#include -#include -#include +#ifndef TOPIC_PARAMETER_UPDATE_H +#define TOPIC_PARAMETER_UPDATE_H -void control_rates(struct sensor_combined_s *raw, struct ardrone_motors_setpoint_s *setpoints); +#include +#include "../uORB.h" -#endif /* RATE_CONTROL_H_ */ +struct parameter_update_s { + /** time at which the latest parameter was updated */ + uint64_t timestamp; +}; + +ORB_DECLARE(parameter_update); + +#endif \ No newline at end of file diff --git a/apps/uORB/topics/rc_channels.h b/apps/uORB/topics/rc_channels.h index 5bd2adeec4..e34376e82e 100644 --- a/apps/uORB/topics/rc_channels.h +++ b/apps/uORB/topics/rc_channels.h @@ -62,11 +62,6 @@ enum RC_CHANNELS_STATUS * This defines the mapping of the RC functions. * The value assigned to the specific function corresponds to the entry of * the channel array chan[]. - * Ex. To read out the scaled Pitch value: - * pitch = global_data_rc_channels->chan[PITCH].scale; - * The override is on channel 8, since we don't usually have a 12 channel RC - * and channel 5/6 (GRAUPNER/FUTABA) are mapped to the second ROLL servo, which - * can only be disabled on more advanced RC sets. */ enum RC_CHANNELS_FUNCTION { @@ -98,10 +93,10 @@ struct rc_channels_s { uint16_t override; enum RC_CHANNELS_STATUS status; /**< status of the channel */ } chan[RC_CHANNELS_FUNCTION_MAX]; - uint8_t chan_count; /**< maximum number of valid channels */ + uint8_t chan_count; /**< maximum number of valid channels */ /*String array to store the names of the functions*/ - const char function_name[RC_CHANNELS_FUNCTION_MAX][20]; + char function_name[RC_CHANNELS_FUNCTION_MAX][20]; uint8_t function[RC_CHANNELS_FUNCTION_MAX]; uint8_t rssi; /**< Overall receive signal strength */ }; /**< radio control channels. */ diff --git a/apps/uORB/topics/sensor_combined.h b/apps/uORB/topics/sensor_combined.h index 8fae788585..8c18477533 100644 --- a/apps/uORB/topics/sensor_combined.h +++ b/apps/uORB/topics/sensor_combined.h @@ -80,11 +80,11 @@ struct sensor_combined_s { uint64_t timestamp; /**< Timestamp in microseconds since boot LOGME */ int16_t gyro_raw[3]; /**< Raw sensor values of angular velocity LOGME */ - uint16_t gyro_raw_counter; /**< Number of raw measurments taken LOGME */ + uint16_t gyro_counter; /**< Number of raw measurments taken LOGME */ float gyro_rad_s[3]; /**< Angular velocity in radian per seconds LOGME */ int16_t accelerometer_raw[3]; /**< Raw acceleration in NED body frame LOGME */ - uint16_t accelerometer_raw_counter; /**< Number of raw acc measurements taken LOGME */ + uint32_t accelerometer_counter; /**< Number of raw acc measurements taken LOGME */ float accelerometer_m_s2[3]; /**< Acceleration in NED body frame, in m/s^2 LOGME */ int accelerometer_mode; /**< Accelerometer measurement mode */ float accelerometer_range_m_s2; /**< Accelerometer measurement range in m/s^2 */ @@ -94,15 +94,15 @@ struct sensor_combined_s { int magnetometer_mode; /**< Magnetometer measurement mode */ float magnetometer_range_ga; /**< ± measurement range in Gauss */ float magnetometer_cuttoff_freq_hz; /**< Internal analog low pass frequency of sensor */ - uint16_t magnetometer_raw_counter; /**< Number of raw mag measurements taken LOGME */ + uint32_t magnetometer_counter; /**< Number of raw mag measurements taken LOGME */ float baro_pres_mbar; /**< Barometric pressure, already temp. comp. LOGME */ float baro_alt_meter; /**< Altitude, already temp. comp. LOGME */ float baro_temp_celcius; /**< Temperature in degrees celsius LOGME */ float battery_voltage_v; /**< Battery voltage in volts, filtered LOGME */ float adc_voltage_v[3]; /**< ADC voltages of ADC Chan 11/12/13 or -1 LOGME */ - uint16_t baro_raw_counter; /**< Number of raw baro measurements taken LOGME */ - uint16_t battery_voltage_counter; /**< Number of voltage measurements taken LOGME */ + uint32_t baro_counter; /**< Number of raw baro measurements taken LOGME */ + uint32_t battery_voltage_counter; /**< Number of voltage measurements taken LOGME */ bool battery_voltage_valid; /**< True if battery voltage can be measured LOGME */ }; diff --git a/apps/uORB/topics/ardrone_control.h b/apps/uORB/topics/subsystem_info.h similarity index 59% rename from apps/uORB/topics/ardrone_control.h rename to apps/uORB/topics/subsystem_info.h index 1f582f52ac..89b3974783 100644 --- a/apps/uORB/topics/ardrone_control.h +++ b/apps/uORB/topics/subsystem_info.h @@ -1,9 +1,9 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: @author Thomas Gubler + * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. + * Author: @author Lorenz Meier + * @author Thomas Gubler * @author Julian Oes - * @author Lorenz Meier * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,50 +34,59 @@ * ****************************************************************************/ -/* - * @file ardrone_control.c - * Definition of the ardrone_control uORB topic. +/** + * @file subsystem_info.h + * Definition of the subsystem info topic. */ -#ifndef TOPIC_ARDRONE_CONTROL_H_ -#define TOPIC_ARDRONE_CONTROL_H_ +#ifndef TOPIC_SUBSYSTEM_INFO_H_ +#define TOPIC_SUBSYSTEM_INFO_H_ #include +#include #include "../uORB.h" /** * @addtogroup topics - * @{ */ -struct ardrone_control_s +enum SUBSYSTEM_TYPE { - uint16_t counter; /**< incremented by the publishing thread everytime new data is stored. */ - uint64_t timestamp; /**< in microseconds since system start, is set whenever the writing thread stores new data. */ + SUBSYSTEM_TYPE_GYRO = 1, + SUBSYSTEM_TYPE_ACC = 2, + SUBSYSTEM_TYPE_MAG = 4, + SUBSYSTEM_TYPE_ABSPRESSURE = 8, + SUBSYSTEM_TYPE_DIFFPRESSURE = 16, + SUBSYSTEM_TYPE_GPS = 32, + SUBSYSTEM_TYPE_OPTICALFLOW = 64, + SUBSYSTEM_TYPE_CVPOSITION = 128, + SUBSYSTEM_TYPE_LASERPOSITION = 256, + SUBSYSTEM_TYPE_EXTERNALGROUNDTRUTH = 512, + SUBSYSTEM_TYPE_ANGULARRATECONTROL = 1024, + SUBSYSTEM_TYPE_ATTITUDESTABILIZATION = 2048, + SUBSYSTEM_TYPE_YAWPOSITION = 4096, + SUBSYSTEM_TYPE_ALTITUDECONTROL = 16384, + SUBSYSTEM_TYPE_POSITIONCONTROL = 32768, + SUBSYSTEM_TYPE_MOTORCONTROL = 65536 +}; - float setpoint_rate_cast[3]; - float setpoint_thrust_cast; /**< LOGME */ - float setpoint_attitude_rate[3]; - float setpoint_attitude[3]; /**< LOGME */ - float attitude_control_output[3]; /**< roll, pitch, yaw. */ - float position_control_output[3]; /**< x, y, z. */ - float attitude_setpoint_navigationframe_from_positioncontroller[3]; /**< LOGME */ - float gyro_scaled[3]; - float gyro_filtered[3]; - float gyro_filtered_offset[3]; - float zcompensation; - uint16_t motor_front_nw; - uint16_t motor_right_ne; - uint16_t motor_back_se; - uint16_t motor_left_sw; +/** + * State of individual sub systems + */ +struct subsystem_info_s { + bool present; + bool enabled; + bool ok; -}; /**< ardrone control status */ + enum SUBSYSTEM_TYPE subsystem_type; +}; /** * @} */ /* register this as object request broker structure */ -ORB_DECLARE(ardrone_control); +ORB_DECLARE(subsystem_info); + +#endif /* TOPIC_SUBSYSTEM_INFO_H_ */ -#endif /* TOPIC_ARDRONE_CONTROL_H_ */ diff --git a/apps/uORB/topics/vehicle_attitude_setpoint.h b/apps/uORB/topics/vehicle_attitude_setpoint.h index 65ba98e9dc..0c33ebff8c 100644 --- a/apps/uORB/topics/vehicle_attitude_setpoint.h +++ b/apps/uORB/topics/vehicle_attitude_setpoint.h @@ -64,6 +64,9 @@ struct vehicle_attitude_setpoint_s float roll_body; /**< body angle in NED frame */ float pitch_body; /**< body angle in NED frame */ float yaw_body; /**< body angle in NED frame */ + float roll_rate_body; /**< body angle in NED frame */ + float pitch_rate_body; /**< body angle in NED frame */ + float yaw_rate_body; /**< body angle in NED frame */ float body_valid; /**< Set to true if Tait-Bryan angles are valid */ float R_body[9]; /**< Rotation matrix describing the setpoint as rotation from the current body frame */ diff --git a/apps/uORB/topics/vehicle_status.h b/apps/uORB/topics/vehicle_status.h index c378b05f1b..cfde2ab53c 100644 --- a/apps/uORB/topics/vehicle_status.h +++ b/apps/uORB/topics/vehicle_status.h @@ -111,26 +111,28 @@ struct vehicle_status_s uint16_t counter; /**< incremented by the writing thread everytime new data is stored */ uint64_t timestamp; /**< in microseconds since system start, is set whenever the writing thread stores new data */ - commander_state_machine_t state_machine; /**< Current flight state, main state machine */ - enum VEHICLE_FLIGHT_MODE flight_mode; /**< Current flight mode, as defined by mode switch */ - enum VEHICLE_ATTITUDE_MODE attitute_mode; /**< Current attitude control mode, as defined by VEHICLE_ATTITUDE_MODE enum */ + commander_state_machine_t state_machine; /**< current flight state, main state machine */ + enum VEHICLE_FLIGHT_MODE flight_mode; /**< current flight mode, as defined by mode switch */ + enum VEHICLE_ATTITUDE_MODE attitute_mode; /**< current attitude control mode, as defined by VEHICLE_ATTITUDE_MODE enum */ // uint8_t mode; /* system flags - these represent the state predicates */ - bool flag_system_armed; /**< True is motors / actuators are armed */ + bool flag_system_armed; /**< true is motors / actuators are armed */ bool flag_control_manual_enabled; /**< true if manual input is mixed in */ - bool flag_hil_enabled; /**< True if hardware in the loop simulation is enabled */ + bool flag_control_offboard_enabled; /**< true if offboard control input is on */ + bool flag_hil_enabled; /**< true if hardware in the loop simulation is enabled */ - // bool flag_control_rates_enabled; /**< true if rates are stabilized */ - // bool flag_control_attitude_enabled; *< true if attitude stabilization is mixed in - // bool control_speed_enabled; /**< true if speed (implies direction) is controlled */ - // bool control_position_enabled; /**< true if position is controlled */ + bool flag_control_rates_enabled; /**< true if rates are stabilized */ + bool flag_control_attitude_enabled; /**< true if attitude stabilization is mixed in */ + bool flag_control_speed_enabled; /**< true if speed (implies direction) is controlled */ + bool flag_control_position_enabled; /**< true if position is controlled */ - bool preflight_gyro_calibration; /**< true if gyro calibration is requested */ - bool preflight_mag_calibration; /**< true if mag calibration is requested */ + bool flag_preflight_gyro_calibration; /**< true if gyro calibration is requested */ + bool flag_preflight_mag_calibration; /**< true if mag calibration is requested */ + bool flag_preflight_accel_calibration; bool rc_signal_lost; /**< true if RC reception is terminally lost */ bool rc_signal_cutting_off; /**< true if RC reception is weak / cutting off */ diff --git a/apps/uORB/uORB.cpp b/apps/uORB/uORB.cpp index 1e7cdc8db1..72a60f8713 100644 --- a/apps/uORB/uORB.cpp +++ b/apps/uORB/uORB.cpp @@ -32,7 +32,8 @@ ****************************************************************************/ /** - * @file A lightweight object broker. + * @file uORB.cpp + * A lightweight object broker. */ #include @@ -112,6 +113,8 @@ public: virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen); virtual int ioctl(struct file *filp, int cmd, unsigned long arg); + static ssize_t publish(const orb_metadata *meta, orb_advert_t handle, const void *data); + protected: virtual pollevent_t poll_state(struct file *filp); virtual void poll_notify_one(struct pollfd *fds, pollevent_t events); @@ -298,6 +301,8 @@ ORBDevNode::write(struct file *filp, const char *buffer, size_t buflen) * * Writes outside interrupt context will allocate the object * if it has not yet been allocated. + * + * Note that filp will usually be NULL. */ if (nullptr == _data) { if (!up_interrupt_context()) { @@ -353,12 +358,42 @@ ORBDevNode::ioctl(struct file *filp, int cmd, unsigned long arg) sd->update_interval = arg; return OK; + case ORBIOCGADVERTISER: + *(uintptr_t *)arg = (uintptr_t)this; + return OK; + default: /* give it to the superclass */ return CDev::ioctl(filp, cmd, arg); } } +ssize_t +ORBDevNode::publish(const orb_metadata *meta, orb_advert_t handle, const void *data) +{ + ORBDevNode *devnode = (ORBDevNode *)handle; + int ret; + + /* this is a bit risky, since we are trusting the handle in order to deref it */ + if (devnode->_meta != meta) { + errno = EINVAL; + return ERROR; + } + + /* call the devnode write method with no file pointer */ + ret = devnode->write(nullptr, (const char *)data, meta->o_size); + + if (ret < 0) + return ERROR; + + if (ret != (int)meta->o_size) { + errno = EIO; + return ERROR; + } + + return OK; +} + pollevent_t ORBDevNode::poll_state(struct file *filp) { @@ -614,7 +649,7 @@ test() if (pfd < 0) return test_fail("advertise failed: %d", errno); - test_note("publish fd %d", pfd); + test_note("publish handle 0x%08x", pfd); sfd = orb_subscribe(ORB_ID(orb_test)); if (sfd < 0) @@ -877,29 +912,35 @@ node_open(Flavor f, const struct orb_metadata *meta, const void *data, bool adve return ERROR; } - /* the advertiser must perform an initial publish to initialise the object */ - if (advertiser) { - ret = orb_publish(meta, fd, data); - - if (ret != OK) { - /* save errno across the close */ - ret = errno; - close(fd); - errno = ret; - return ERROR; - } - } - /* everything has been OK, we can return the handle now */ return fd; } } // namespace -int +orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) { - return node_open(PUBSUB, meta, data, true); + int result, fd; + orb_advert_t advertiser; + + /* open the node as an advertiser */ + fd = node_open(PUBSUB, meta, data, true); + if (fd == ERROR) + return ERROR; + + /* get the advertiser handle and close the node */ + result = ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser); + close(fd); + if (result == ERROR) + return ERROR; + + /* the advertiser must perform an initial publish to initialise the object */ + result= orb_publish(meta, advertiser, data); + if (result == ERROR) + return ERROR; + + return advertiser; } int @@ -915,21 +956,9 @@ orb_unsubscribe(int handle) } int -orb_publish(const struct orb_metadata *meta, int handle, const void *data) +orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) { - int ret; - - ret = write(handle, data, meta->o_size); - - if (ret < 0) - return ERROR; - - if (ret != (int)meta->o_size) { - errno = EIO; - return ERROR; - } - - return OK; + return ORBDevNode::publish(meta, handle, data); } int diff --git a/apps/uORB/uORB.h b/apps/uORB/uORB.h index c36d0044f2..172c37d0fa 100644 --- a/apps/uORB/uORB.h +++ b/apps/uORB/uORB.h @@ -35,14 +35,13 @@ #define _UORB_UORB_H /** - * @file API for the uORB lightweight object broker. + * @file uORB.h + * API for the uORB lightweight object broker. */ #include #include #include - // Hack until parameter storage is cleaned up -#include "parameter_storage.h" // Hack until everything is using this header #include @@ -105,12 +104,27 @@ struct orb_metadata { __BEGIN_DECLS +/** + * ORB topic advertiser handle. + * + * Advertiser handles are global; once obtained they can be shared freely + * and do not need to be closed or released. + * + * This permits publication from interrupt context and other contexts where + * a file-descriptor-based handle would not otherwise be in scope for the + * publisher. + */ +typedef intptr_t orb_advert_t; + /** * Advertise as the publisher of a topic. * * This performs the initial advertisement of a topic; it creates the topic * node in /obj if required and publishes the initial data. * + * Any number of advertisers may publish to a topic; publications are atomic + * but co-ordination between publishers is not provided by the ORB. + * * @param meta The uORB metadata (usually from the ORB_ID() macro) * for the topic. * @param data A pointer to the initial data to be published. @@ -122,7 +136,7 @@ __BEGIN_DECLS * ORB_DEFINE with no corresponding ORB_DECLARE) * this function will return -1 and set errno to ENOENT. */ -extern int orb_advertise(const struct orb_metadata *meta, const void *data) __EXPORT; +extern orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) __EXPORT; /** * Publish new data to a topic. @@ -131,13 +145,13 @@ extern int orb_advertise(const struct orb_metadata *meta, const void *data) __EX * will be notified. Subscribers that are not waiting can check the topic * for updates using orb_check and/or orb_stat. * - * @handle The handle returned from orb_advertise. * @param meta The uORB metadata (usually from the ORB_ID() macro) * for the topic. + * @handle The handle returned from orb_advertise. * @param data A pointer to the data to be published. * @return OK on success, ERROR otherwise with errno set accordingly. */ -extern int orb_publish(const struct orb_metadata *meta, int handle, const void *data) __EXPORT; +extern int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) __EXPORT; /** * Subscribe to a topic. diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/ardupilotmega.h b/mavlink/include/mavlink/v0.9/ardupilotmega/ardupilotmega.h deleted file mode 100644 index 4148b5a6a9..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/ardupilotmega.h +++ /dev/null @@ -1,154 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from ardupilotmega.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef ARDUPILOTMEGA_H -#define ARDUPILOTMEGA_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {3, 4, 8, 14, 8, 28, 3, 32, 0, 2, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 19, 2, 23, 21, 0, 37, 26, 101, 26, 16, 32, 32, 37, 32, 11, 17, 17, 16, 18, 36, 4, 4, 2, 2, 4, 2, 2, 3, 14, 12, 18, 16, 8, 27, 25, 18, 18, 24, 24, 0, 0, 0, 26, 16, 36, 5, 6, 56, 26, 21, 18, 0, 0, 18, 20, 20, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 8, 4, 12, 15, 13, 6, 15, 14, 0, 12, 3, 8, 28, 36, 3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 14, 14, 51, 5} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {72, 39, 190, 92, 191, 217, 104, 119, 0, 219, 60, 186, 10, 0, 0, 0, 0, 0, 0, 0, 89, 159, 162, 121, 0, 149, 222, 110, 179, 136, 66, 126, 185, 147, 112, 252, 162, 215, 229, 128, 9, 106, 101, 213, 4, 229, 21, 214, 215, 14, 206, 50, 157, 126, 108, 213, 95, 5, 127, 0, 0, 0, 57, 126, 130, 119, 193, 191, 236, 158, 143, 0, 0, 104, 123, 131, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 143, 29, 208, 188, 118, 242, 19, 97, 233, 0, 18, 68, 136, 127, 42, 21, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 224, 60, 106, 7} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_BOOT, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_SYSTEM_TIME_UTC, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_ACTION_ACK, MAVLINK_MESSAGE_INFO_ACTION, MAVLINK_MESSAGE_INFO_SET_MODE, MAVLINK_MESSAGE_INFO_SET_NAV_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_LOCAL_POSITION, MAVLINK_MESSAGE_INFO_GPS_RAW, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_WAYPOINT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST, MAVLINK_MESSAGE_INFO_WAYPOINT_SET_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST_LIST, MAVLINK_MESSAGE_INFO_WAYPOINT_COUNT, MAVLINK_MESSAGE_INFO_WAYPOINT_CLEAR_ALL, MAVLINK_MESSAGE_INFO_WAYPOINT_REACHED, MAVLINK_MESSAGE_INFO_WAYPOINT_ACK, MAVLINK_MESSAGE_INFO_GPS_SET_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_LOCAL_ORIGIN_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_CONTROL_STATUS, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, MAVLINK_MESSAGE_INFO_POSITION_TARGET, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, MAVLINK_MESSAGE_INFO_SET_ALTITUDE, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_VFR_HUD, MAVLINK_MESSAGE_INFO_COMMAND, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBJECT_DETECTION_EVENT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SENSOR_OFFSETS, MAVLINK_MESSAGE_INFO_SET_MAG_OFFSETS, MAVLINK_MESSAGE_INFO_MEMINFO, MAVLINK_MESSAGE_INFO_AP_ADC, MAVLINK_MESSAGE_INFO_DIGICAM_CONFIGURE, MAVLINK_MESSAGE_INFO_DIGICAM_CONTROL, MAVLINK_MESSAGE_INFO_MOUNT_CONFIGURE, MAVLINK_MESSAGE_INFO_MOUNT_CONTROL, MAVLINK_MESSAGE_INFO_MOUNT_STATUS, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_FENCE_POINT, MAVLINK_MESSAGE_INFO_FENCE_FETCH_POINT, MAVLINK_MESSAGE_INFO_FENCE_STATUS, MAVLINK_MESSAGE_INFO_AHRS, MAVLINK_MESSAGE_INFO_SIMSTATE, MAVLINK_MESSAGE_INFO_HWSTATUS, MAVLINK_MESSAGE_INFO_RADIO, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_ARDUPILOTMEGA - -#include "../common/common.h" - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - -/** @brief Enumeration of possible mount operation modes */ -#ifndef HAVE_ENUM_MAV_MOUNT_MODE -#define HAVE_ENUM_MAV_MOUNT_MODE -enum MAV_MOUNT_MODE -{ - MAV_MOUNT_MODE_RETRACT=0, /* Load and keep safe position (Roll,Pitch,Yaw) from EEPROM and stop stabilization | */ - MAV_MOUNT_MODE_NEUTRAL=1, /* Load and keep neutral position (Roll,Pitch,Yaw) from EEPROM. | */ - MAV_MOUNT_MODE_MAVLINK_TARGETING=2, /* Load neutral position and start MAVLink Roll,Pitch,Yaw control with stabilization | */ - MAV_MOUNT_MODE_RC_TARGETING=3, /* Load neutral position and start RC Roll,Pitch,Yaw control with stabilization | */ - MAV_MOUNT_MODE_GPS_POINT=4, /* Load neutral position and start to point to Lat,Lon,Alt | */ - MAV_MOUNT_MODE_ENUM_END=5, /* | */ -}; -#endif - -/** @brief */ -#ifndef HAVE_ENUM_MAV_CMD -#define HAVE_ENUM_MAV_CMD -enum MAV_CMD -{ - MAV_CMD_NAV_WAYPOINT=16, /* Navigate to waypoint. |Hold time in decimal seconds. (ignored by fixed wing, time to stay at waypoint for rotary wing)| Acceptance radius in meters (if the sphere with this radius is hit, the waypoint counts as reached)| 0 to pass through the WP, if > 0 radius in meters to pass by WP. Positive value for clockwise orbit, negative value for counter-clockwise orbit. Allows trajectory control.| Desired yaw angle at waypoint (rotary wing)| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_LOITER_UNLIM=17, /* Loiter around this waypoint an unlimited amount of time |Empty| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_LOITER_TURNS=18, /* Loiter around this waypoint for X turns |Turns| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_LOITER_TIME=19, /* Loiter around this waypoint for X seconds |Seconds (decimal)| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_RETURN_TO_LAUNCH=20, /* Return to launch location |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_NAV_LAND=21, /* Land at location |Empty| Empty| Empty| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_TAKEOFF=22, /* Takeoff from ground / hand |Minimum pitch (if airspeed sensor present), desired pitch without sensor| Empty| Empty| Yaw angle (if magnetometer present), ignored without magnetometer| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_ROI=80, /* Sets the region of interest (ROI) for a sensor set or the - vehicle itself. This can then be used by the vehicles control - system to control the vehicle attitude and the attitude of various - sensors such as cameras. |Region of intereset mode. (see MAV_ROI enum)| Waypoint index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple ROI's)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| */ - MAV_CMD_NAV_PATHPLANNING=81, /* Control autonomous path planning on the MAV. |0: Disable local obstacle avoidance / local path planning (without resetting map), 1: Enable local path planning, 2: Enable and reset local path planning| 0: Disable full path planning (without resetting map), 1: Enable, 2: Enable and reset map/occupancy grid, 3: Enable and reset planned route, but not occupancy grid| Empty| Yaw angle at goal, in compass degrees, [0..360]| Latitude/X of goal| Longitude/Y of goal| Altitude/Z of goal| */ - MAV_CMD_NAV_LAST=95, /* NOP - This command is only used to mark the upper limit of the NAV/ACTION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_DELAY=112, /* Delay mission state machine. |Delay in seconds (decimal)| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_CHANGE_ALT=113, /* Ascend/descend at rate. Delay mission state machine until desired altitude reached. |Descent / Ascend rate (m/s)| Empty| Empty| Empty| Empty| Empty| Finish Altitude| */ - MAV_CMD_CONDITION_DISTANCE=114, /* Delay mission state machine until within desired distance of next NAV point. |Distance (meters)| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_YAW=115, /* Reach a certain target angle. |target angle: [0-360], 0 is north| speed during yaw change:[deg per second]| direction: negative: counter clockwise, positive: clockwise [-1,1]| relative offset or absolute angle: [ 1,0]| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_LAST=159, /* NOP - This command is only used to mark the upper limit of the CONDITION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_MODE=176, /* Set system mode. |Mode, as defined by ENUM MAV_MODE| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_JUMP=177, /* Jump to the desired command in the mission list. Repeat this action only the specified number of times |Sequence number| Repeat count| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_CHANGE_SPEED=178, /* Change speed and/or throttle set points. |Speed type (0=Airspeed, 1=Ground Speed)| Speed (m/s, -1 indicates no change)| Throttle ( Percent, -1 indicates no change)| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_HOME=179, /* Changes the home location either to the current location or a specified location. |Use current (1=use current location, 0=use specified location)| Empty| Empty| Empty| Latitude| Longitude| Altitude| */ - MAV_CMD_DO_SET_PARAMETER=180, /* Set a system parameter. Caution! Use of this command requires knowledge of the numeric enumeration value of the parameter. |Parameter number| Parameter value| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_RELAY=181, /* Set a relay to a condition. |Relay number| Setting (1=on, 0=off, others possible depending on system hardware)| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_REPEAT_RELAY=182, /* Cycle a relay on and off for a desired number of cyles with a desired period. |Relay number| Cycle count| Cycle time (seconds, decimal)| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_SERVO=183, /* Set a servo to a desired PWM value. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_REPEAT_SERVO=184, /* Cycle a between its nominal setting and a desired PWM for a desired number of cycles with a desired period. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Cycle count| Cycle time (seconds)| Empty| Empty| Empty| */ - MAV_CMD_DO_CONTROL_VIDEO=200, /* Control onboard camera capturing. |Camera ID (-1 for all)| Transmission: 0: disabled, 1: enabled compressed, 2: enabled raw| Transmission mode: 0: video stream, >0: single images every n seconds (decimal)| Recording: 0: disabled, 1: enabled compressed, 2: enabled raw| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_ROI=201, /* Sets the region of interest (ROI) for a sensor set or the - vehicle itself. This can then be used by the vehicles control - system to control the vehicle attitude and the attitude of various - devices such as cameras. - |Region of interest mode. (see MAV_ROI enum)| Waypoint index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple cameras etc.)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| */ - MAV_CMD_DO_DIGICAM_CONFIGURE=202, /* Mission command to configure an on-board camera controller system. |Modes: P, TV, AV, M, Etc| Shutter speed: Divisor number for one second| Aperture: F stop number| ISO number e.g. 80, 100, 200, Etc| Exposure type enumerator| Command Identity| Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off)| */ - MAV_CMD_DO_DIGICAM_CONTROL=203, /* Mission command to control an on-board camera controller system. |Session control e.g. show/hide lens| Zoom's absolute position| Zooming step value to offset zoom from the current position| Focus Locking, Unlocking or Re-locking| Shooting Command| Command Identity| Empty| */ - MAV_CMD_DO_MOUNT_CONFIGURE=204, /* Mission command to configure a camera or antenna mount |Mount operation mode (see MAV_MOUNT_MODE enum)| stabilize roll? (1 = yes, 0 = no)| stabilize pitch? (1 = yes, 0 = no)| stabilize yaw? (1 = yes, 0 = no)| Empty| Empty| Empty| */ - MAV_CMD_DO_MOUNT_CONTROL=205, /* Mission command to control a camera or antenna mount |pitch(deg*100) or lat, depending on mount mode.| roll(deg*100) or lon depending on mount mode| yaw(deg*100) or alt (in cm) depending on mount mode| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_LAST=240, /* NOP - This command is only used to mark the upper limit of the DO commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_PREFLIGHT_CALIBRATION=241, /* Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Empty| Empty| Empty| */ - MAV_CMD_PREFLIGHT_STORAGE=245, /* Request storage of different parameter values and logs. This command will be only accepted if in pre-flight mode. |Parameter storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Mission storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Reserved| Reserved| Empty| Empty| Empty| */ - MAV_CMD_ENUM_END=246, /* | */ -}; -#endif - -/** @brief */ -#ifndef HAVE_ENUM_FENCE_ACTION -#define HAVE_ENUM_FENCE_ACTION -enum FENCE_ACTION -{ - FENCE_ACTION_NONE=0, /* Disable fenced mode | */ - FENCE_ACTION_GUIDED=1, /* Switched to guided mode to return point (fence point 0) | */ - FENCE_ACTION_ENUM_END=2, /* | */ -}; -#endif - -/** @brief */ -#ifndef HAVE_ENUM_FENCE_BREACH -#define HAVE_ENUM_FENCE_BREACH -enum FENCE_BREACH -{ - FENCE_BREACH_NONE=0, /* No last fence breach | */ - FENCE_BREACH_MINALT=1, /* Breached minimum altitude | */ - FENCE_BREACH_MAXALT=2, /* Breached minimum altitude | */ - FENCE_BREACH_BOUNDARY=3, /* Breached fence boundary | */ - FENCE_BREACH_ENUM_END=4, /* | */ -}; -#endif - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_sensor_offsets.h" -#include "./mavlink_msg_set_mag_offsets.h" -#include "./mavlink_msg_meminfo.h" -#include "./mavlink_msg_ap_adc.h" -#include "./mavlink_msg_digicam_configure.h" -#include "./mavlink_msg_digicam_control.h" -#include "./mavlink_msg_mount_configure.h" -#include "./mavlink_msg_mount_control.h" -#include "./mavlink_msg_mount_status.h" -#include "./mavlink_msg_fence_point.h" -#include "./mavlink_msg_fence_fetch_point.h" -#include "./mavlink_msg_fence_status.h" -#include "./mavlink_msg_ahrs.h" -#include "./mavlink_msg_simstate.h" -#include "./mavlink_msg_hwstatus.h" -#include "./mavlink_msg_radio.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // ARDUPILOTMEGA_H diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink.h deleted file mode 100644 index 72e0248d98..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - * @brief MAVLink comm protocol built from ardupilotmega.xml - * @see http://pixhawk.ethz.ch/software/mavlink - */ -#ifndef MAVLINK_H -#define MAVLINK_H - -#ifndef MAVLINK_STX -#define MAVLINK_STX 85 -#endif - -#ifndef MAVLINK_ENDIAN -#define MAVLINK_ENDIAN MAVLINK_BIG_ENDIAN -#endif - -#ifndef MAVLINK_ALIGNED_FIELDS -#define MAVLINK_ALIGNED_FIELDS 0 -#endif - -#ifndef MAVLINK_CRC_EXTRA -#define MAVLINK_CRC_EXTRA 0 -#endif - -#include "version.h" -#include "ardupilotmega.h" - -#endif // MAVLINK_H diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_ahrs.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_ahrs.h deleted file mode 100644 index 9cb06e6b1a..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_ahrs.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE AHRS PACKING - -#define MAVLINK_MSG_ID_AHRS 163 - -typedef struct __mavlink_ahrs_t -{ - float omegaIx; ///< X gyro drift estimate rad/s - float omegaIy; ///< Y gyro drift estimate rad/s - float omegaIz; ///< Z gyro drift estimate rad/s - float accel_weight; ///< average accel_weight - float renorm_val; ///< average renormalisation value - float error_rp; ///< average error_roll_pitch value - float error_yaw; ///< average error_yaw value -} mavlink_ahrs_t; - -#define MAVLINK_MSG_ID_AHRS_LEN 28 -#define MAVLINK_MSG_ID_163_LEN 28 - - - -#define MAVLINK_MESSAGE_INFO_AHRS { \ - "AHRS", \ - 7, \ - { { "omegaIx", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_ahrs_t, omegaIx) }, \ - { "omegaIy", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_ahrs_t, omegaIy) }, \ - { "omegaIz", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_ahrs_t, omegaIz) }, \ - { "accel_weight", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_ahrs_t, accel_weight) }, \ - { "renorm_val", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_ahrs_t, renorm_val) }, \ - { "error_rp", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_ahrs_t, error_rp) }, \ - { "error_yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_ahrs_t, error_yaw) }, \ - } \ -} - - -/** - * @brief Pack a ahrs message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param omegaIx X gyro drift estimate rad/s - * @param omegaIy Y gyro drift estimate rad/s - * @param omegaIz Z gyro drift estimate rad/s - * @param accel_weight average accel_weight - * @param renorm_val average renormalisation value - * @param error_rp average error_roll_pitch value - * @param error_yaw average error_yaw value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ahrs_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float omegaIx, float omegaIy, float omegaIz, float accel_weight, float renorm_val, float error_rp, float error_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[28]; - _mav_put_float(buf, 0, omegaIx); - _mav_put_float(buf, 4, omegaIy); - _mav_put_float(buf, 8, omegaIz); - _mav_put_float(buf, 12, accel_weight); - _mav_put_float(buf, 16, renorm_val); - _mav_put_float(buf, 20, error_rp); - _mav_put_float(buf, 24, error_yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 28); -#else - mavlink_ahrs_t packet; - packet.omegaIx = omegaIx; - packet.omegaIy = omegaIy; - packet.omegaIz = omegaIz; - packet.accel_weight = accel_weight; - packet.renorm_val = renorm_val; - packet.error_rp = error_rp; - packet.error_yaw = error_yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 28); -#endif - - msg->msgid = MAVLINK_MSG_ID_AHRS; - return mavlink_finalize_message(msg, system_id, component_id, 28); -} - -/** - * @brief Pack a ahrs message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param omegaIx X gyro drift estimate rad/s - * @param omegaIy Y gyro drift estimate rad/s - * @param omegaIz Z gyro drift estimate rad/s - * @param accel_weight average accel_weight - * @param renorm_val average renormalisation value - * @param error_rp average error_roll_pitch value - * @param error_yaw average error_yaw value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ahrs_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float omegaIx,float omegaIy,float omegaIz,float accel_weight,float renorm_val,float error_rp,float error_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[28]; - _mav_put_float(buf, 0, omegaIx); - _mav_put_float(buf, 4, omegaIy); - _mav_put_float(buf, 8, omegaIz); - _mav_put_float(buf, 12, accel_weight); - _mav_put_float(buf, 16, renorm_val); - _mav_put_float(buf, 20, error_rp); - _mav_put_float(buf, 24, error_yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 28); -#else - mavlink_ahrs_t packet; - packet.omegaIx = omegaIx; - packet.omegaIy = omegaIy; - packet.omegaIz = omegaIz; - packet.accel_weight = accel_weight; - packet.renorm_val = renorm_val; - packet.error_rp = error_rp; - packet.error_yaw = error_yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 28); -#endif - - msg->msgid = MAVLINK_MSG_ID_AHRS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 28); -} - -/** - * @brief Encode a ahrs struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ahrs C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ahrs_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ahrs_t* ahrs) -{ - return mavlink_msg_ahrs_pack(system_id, component_id, msg, ahrs->omegaIx, ahrs->omegaIy, ahrs->omegaIz, ahrs->accel_weight, ahrs->renorm_val, ahrs->error_rp, ahrs->error_yaw); -} - -/** - * @brief Send a ahrs message - * @param chan MAVLink channel to send the message - * - * @param omegaIx X gyro drift estimate rad/s - * @param omegaIy Y gyro drift estimate rad/s - * @param omegaIz Z gyro drift estimate rad/s - * @param accel_weight average accel_weight - * @param renorm_val average renormalisation value - * @param error_rp average error_roll_pitch value - * @param error_yaw average error_yaw value - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ahrs_send(mavlink_channel_t chan, float omegaIx, float omegaIy, float omegaIz, float accel_weight, float renorm_val, float error_rp, float error_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[28]; - _mav_put_float(buf, 0, omegaIx); - _mav_put_float(buf, 4, omegaIy); - _mav_put_float(buf, 8, omegaIz); - _mav_put_float(buf, 12, accel_weight); - _mav_put_float(buf, 16, renorm_val); - _mav_put_float(buf, 20, error_rp); - _mav_put_float(buf, 24, error_yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AHRS, buf, 28); -#else - mavlink_ahrs_t packet; - packet.omegaIx = omegaIx; - packet.omegaIy = omegaIy; - packet.omegaIz = omegaIz; - packet.accel_weight = accel_weight; - packet.renorm_val = renorm_val; - packet.error_rp = error_rp; - packet.error_yaw = error_yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AHRS, (const char *)&packet, 28); -#endif -} - -#endif - -// MESSAGE AHRS UNPACKING - - -/** - * @brief Get field omegaIx from ahrs message - * - * @return X gyro drift estimate rad/s - */ -static inline float mavlink_msg_ahrs_get_omegaIx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field omegaIy from ahrs message - * - * @return Y gyro drift estimate rad/s - */ -static inline float mavlink_msg_ahrs_get_omegaIy(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field omegaIz from ahrs message - * - * @return Z gyro drift estimate rad/s - */ -static inline float mavlink_msg_ahrs_get_omegaIz(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field accel_weight from ahrs message - * - * @return average accel_weight - */ -static inline float mavlink_msg_ahrs_get_accel_weight(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field renorm_val from ahrs message - * - * @return average renormalisation value - */ -static inline float mavlink_msg_ahrs_get_renorm_val(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field error_rp from ahrs message - * - * @return average error_roll_pitch value - */ -static inline float mavlink_msg_ahrs_get_error_rp(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field error_yaw from ahrs message - * - * @return average error_yaw value - */ -static inline float mavlink_msg_ahrs_get_error_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Decode a ahrs message into a struct - * - * @param msg The message to decode - * @param ahrs C-struct to decode the message contents into - */ -static inline void mavlink_msg_ahrs_decode(const mavlink_message_t* msg, mavlink_ahrs_t* ahrs) -{ -#if MAVLINK_NEED_BYTE_SWAP - ahrs->omegaIx = mavlink_msg_ahrs_get_omegaIx(msg); - ahrs->omegaIy = mavlink_msg_ahrs_get_omegaIy(msg); - ahrs->omegaIz = mavlink_msg_ahrs_get_omegaIz(msg); - ahrs->accel_weight = mavlink_msg_ahrs_get_accel_weight(msg); - ahrs->renorm_val = mavlink_msg_ahrs_get_renorm_val(msg); - ahrs->error_rp = mavlink_msg_ahrs_get_error_rp(msg); - ahrs->error_yaw = mavlink_msg_ahrs_get_error_yaw(msg); -#else - memcpy(ahrs, _MAV_PAYLOAD(msg), 28); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_ap_adc.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_ap_adc.h deleted file mode 100644 index 07eacc9a91..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_ap_adc.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE AP_ADC PACKING - -#define MAVLINK_MSG_ID_AP_ADC 153 - -typedef struct __mavlink_ap_adc_t -{ - uint16_t adc1; ///< ADC output 1 - uint16_t adc2; ///< ADC output 2 - uint16_t adc3; ///< ADC output 3 - uint16_t adc4; ///< ADC output 4 - uint16_t adc5; ///< ADC output 5 - uint16_t adc6; ///< ADC output 6 -} mavlink_ap_adc_t; - -#define MAVLINK_MSG_ID_AP_ADC_LEN 12 -#define MAVLINK_MSG_ID_153_LEN 12 - - - -#define MAVLINK_MESSAGE_INFO_AP_ADC { \ - "AP_ADC", \ - 6, \ - { { "adc1", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_ap_adc_t, adc1) }, \ - { "adc2", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_ap_adc_t, adc2) }, \ - { "adc3", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_ap_adc_t, adc3) }, \ - { "adc4", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_ap_adc_t, adc4) }, \ - { "adc5", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_ap_adc_t, adc5) }, \ - { "adc6", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_ap_adc_t, adc6) }, \ - } \ -} - - -/** - * @brief Pack a ap_adc message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param adc1 ADC output 1 - * @param adc2 ADC output 2 - * @param adc3 ADC output 3 - * @param adc4 ADC output 4 - * @param adc5 ADC output 5 - * @param adc6 ADC output 6 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ap_adc_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t adc1, uint16_t adc2, uint16_t adc3, uint16_t adc4, uint16_t adc5, uint16_t adc6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint16_t(buf, 0, adc1); - _mav_put_uint16_t(buf, 2, adc2); - _mav_put_uint16_t(buf, 4, adc3); - _mav_put_uint16_t(buf, 6, adc4); - _mav_put_uint16_t(buf, 8, adc5); - _mav_put_uint16_t(buf, 10, adc6); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_ap_adc_t packet; - packet.adc1 = adc1; - packet.adc2 = adc2; - packet.adc3 = adc3; - packet.adc4 = adc4; - packet.adc5 = adc5; - packet.adc6 = adc6; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_AP_ADC; - return mavlink_finalize_message(msg, system_id, component_id, 12); -} - -/** - * @brief Pack a ap_adc message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param adc1 ADC output 1 - * @param adc2 ADC output 2 - * @param adc3 ADC output 3 - * @param adc4 ADC output 4 - * @param adc5 ADC output 5 - * @param adc6 ADC output 6 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ap_adc_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t adc1,uint16_t adc2,uint16_t adc3,uint16_t adc4,uint16_t adc5,uint16_t adc6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint16_t(buf, 0, adc1); - _mav_put_uint16_t(buf, 2, adc2); - _mav_put_uint16_t(buf, 4, adc3); - _mav_put_uint16_t(buf, 6, adc4); - _mav_put_uint16_t(buf, 8, adc5); - _mav_put_uint16_t(buf, 10, adc6); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_ap_adc_t packet; - packet.adc1 = adc1; - packet.adc2 = adc2; - packet.adc3 = adc3; - packet.adc4 = adc4; - packet.adc5 = adc5; - packet.adc6 = adc6; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_AP_ADC; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 12); -} - -/** - * @brief Encode a ap_adc struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ap_adc C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ap_adc_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ap_adc_t* ap_adc) -{ - return mavlink_msg_ap_adc_pack(system_id, component_id, msg, ap_adc->adc1, ap_adc->adc2, ap_adc->adc3, ap_adc->adc4, ap_adc->adc5, ap_adc->adc6); -} - -/** - * @brief Send a ap_adc message - * @param chan MAVLink channel to send the message - * - * @param adc1 ADC output 1 - * @param adc2 ADC output 2 - * @param adc3 ADC output 3 - * @param adc4 ADC output 4 - * @param adc5 ADC output 5 - * @param adc6 ADC output 6 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ap_adc_send(mavlink_channel_t chan, uint16_t adc1, uint16_t adc2, uint16_t adc3, uint16_t adc4, uint16_t adc5, uint16_t adc6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint16_t(buf, 0, adc1); - _mav_put_uint16_t(buf, 2, adc2); - _mav_put_uint16_t(buf, 4, adc3); - _mav_put_uint16_t(buf, 6, adc4); - _mav_put_uint16_t(buf, 8, adc5); - _mav_put_uint16_t(buf, 10, adc6); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AP_ADC, buf, 12); -#else - mavlink_ap_adc_t packet; - packet.adc1 = adc1; - packet.adc2 = adc2; - packet.adc3 = adc3; - packet.adc4 = adc4; - packet.adc5 = adc5; - packet.adc6 = adc6; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AP_ADC, (const char *)&packet, 12); -#endif -} - -#endif - -// MESSAGE AP_ADC UNPACKING - - -/** - * @brief Get field adc1 from ap_adc message - * - * @return ADC output 1 - */ -static inline uint16_t mavlink_msg_ap_adc_get_adc1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field adc2 from ap_adc message - * - * @return ADC output 2 - */ -static inline uint16_t mavlink_msg_ap_adc_get_adc2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field adc3 from ap_adc message - * - * @return ADC output 3 - */ -static inline uint16_t mavlink_msg_ap_adc_get_adc3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 4); -} - -/** - * @brief Get field adc4 from ap_adc message - * - * @return ADC output 4 - */ -static inline uint16_t mavlink_msg_ap_adc_get_adc4(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 6); -} - -/** - * @brief Get field adc5 from ap_adc message - * - * @return ADC output 5 - */ -static inline uint16_t mavlink_msg_ap_adc_get_adc5(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Get field adc6 from ap_adc message - * - * @return ADC output 6 - */ -static inline uint16_t mavlink_msg_ap_adc_get_adc6(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 10); -} - -/** - * @brief Decode a ap_adc message into a struct - * - * @param msg The message to decode - * @param ap_adc C-struct to decode the message contents into - */ -static inline void mavlink_msg_ap_adc_decode(const mavlink_message_t* msg, mavlink_ap_adc_t* ap_adc) -{ -#if MAVLINK_NEED_BYTE_SWAP - ap_adc->adc1 = mavlink_msg_ap_adc_get_adc1(msg); - ap_adc->adc2 = mavlink_msg_ap_adc_get_adc2(msg); - ap_adc->adc3 = mavlink_msg_ap_adc_get_adc3(msg); - ap_adc->adc4 = mavlink_msg_ap_adc_get_adc4(msg); - ap_adc->adc5 = mavlink_msg_ap_adc_get_adc5(msg); - ap_adc->adc6 = mavlink_msg_ap_adc_get_adc6(msg); -#else - memcpy(ap_adc, _MAV_PAYLOAD(msg), 12); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_digicam_configure.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_digicam_configure.h deleted file mode 100644 index 8df0a00d8b..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_digicam_configure.h +++ /dev/null @@ -1,364 +0,0 @@ -// MESSAGE DIGICAM_CONFIGURE PACKING - -#define MAVLINK_MSG_ID_DIGICAM_CONFIGURE 154 - -typedef struct __mavlink_digicam_configure_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t mode; ///< Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) - uint16_t shutter_speed; ///< Divisor number //e.g. 1000 means 1/1000 (0 means ignore) - uint8_t aperture; ///< F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) - uint8_t iso; ///< ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) - uint8_t exposure_type; ///< Exposure type enumeration from 1 to N (0 means ignore) - uint8_t command_id; ///< Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - uint8_t engine_cut_off; ///< Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) - uint8_t extra_param; ///< Extra parameters enumeration (0 means ignore) - float extra_value; ///< Correspondent value to given extra_param -} mavlink_digicam_configure_t; - -#define MAVLINK_MSG_ID_DIGICAM_CONFIGURE_LEN 15 -#define MAVLINK_MSG_ID_154_LEN 15 - - - -#define MAVLINK_MESSAGE_INFO_DIGICAM_CONFIGURE { \ - "DIGICAM_CONFIGURE", \ - 11, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_digicam_configure_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_digicam_configure_t, target_component) }, \ - { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_digicam_configure_t, mode) }, \ - { "shutter_speed", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_digicam_configure_t, shutter_speed) }, \ - { "aperture", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_digicam_configure_t, aperture) }, \ - { "iso", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_digicam_configure_t, iso) }, \ - { "exposure_type", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_digicam_configure_t, exposure_type) }, \ - { "command_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_digicam_configure_t, command_id) }, \ - { "engine_cut_off", NULL, MAVLINK_TYPE_UINT8_T, 0, 9, offsetof(mavlink_digicam_configure_t, engine_cut_off) }, \ - { "extra_param", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_digicam_configure_t, extra_param) }, \ - { "extra_value", NULL, MAVLINK_TYPE_FLOAT, 0, 11, offsetof(mavlink_digicam_configure_t, extra_value) }, \ - } \ -} - - -/** - * @brief Pack a digicam_configure message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param mode Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) - * @param shutter_speed Divisor number //e.g. 1000 means 1/1000 (0 means ignore) - * @param aperture F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) - * @param iso ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) - * @param exposure_type Exposure type enumeration from 1 to N (0 means ignore) - * @param command_id Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - * @param engine_cut_off Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) - * @param extra_param Extra parameters enumeration (0 means ignore) - * @param extra_value Correspondent value to given extra_param - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_digicam_configure_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t mode, uint16_t shutter_speed, uint8_t aperture, uint8_t iso, uint8_t exposure_type, uint8_t command_id, uint8_t engine_cut_off, uint8_t extra_param, float extra_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[15]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, mode); - _mav_put_uint16_t(buf, 3, shutter_speed); - _mav_put_uint8_t(buf, 5, aperture); - _mav_put_uint8_t(buf, 6, iso); - _mav_put_uint8_t(buf, 7, exposure_type); - _mav_put_uint8_t(buf, 8, command_id); - _mav_put_uint8_t(buf, 9, engine_cut_off); - _mav_put_uint8_t(buf, 10, extra_param); - _mav_put_float(buf, 11, extra_value); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 15); -#else - mavlink_digicam_configure_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mode = mode; - packet.shutter_speed = shutter_speed; - packet.aperture = aperture; - packet.iso = iso; - packet.exposure_type = exposure_type; - packet.command_id = command_id; - packet.engine_cut_off = engine_cut_off; - packet.extra_param = extra_param; - packet.extra_value = extra_value; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 15); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIGICAM_CONFIGURE; - return mavlink_finalize_message(msg, system_id, component_id, 15); -} - -/** - * @brief Pack a digicam_configure message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param mode Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) - * @param shutter_speed Divisor number //e.g. 1000 means 1/1000 (0 means ignore) - * @param aperture F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) - * @param iso ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) - * @param exposure_type Exposure type enumeration from 1 to N (0 means ignore) - * @param command_id Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - * @param engine_cut_off Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) - * @param extra_param Extra parameters enumeration (0 means ignore) - * @param extra_value Correspondent value to given extra_param - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_digicam_configure_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t mode,uint16_t shutter_speed,uint8_t aperture,uint8_t iso,uint8_t exposure_type,uint8_t command_id,uint8_t engine_cut_off,uint8_t extra_param,float extra_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[15]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, mode); - _mav_put_uint16_t(buf, 3, shutter_speed); - _mav_put_uint8_t(buf, 5, aperture); - _mav_put_uint8_t(buf, 6, iso); - _mav_put_uint8_t(buf, 7, exposure_type); - _mav_put_uint8_t(buf, 8, command_id); - _mav_put_uint8_t(buf, 9, engine_cut_off); - _mav_put_uint8_t(buf, 10, extra_param); - _mav_put_float(buf, 11, extra_value); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 15); -#else - mavlink_digicam_configure_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mode = mode; - packet.shutter_speed = shutter_speed; - packet.aperture = aperture; - packet.iso = iso; - packet.exposure_type = exposure_type; - packet.command_id = command_id; - packet.engine_cut_off = engine_cut_off; - packet.extra_param = extra_param; - packet.extra_value = extra_value; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 15); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIGICAM_CONFIGURE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 15); -} - -/** - * @brief Encode a digicam_configure struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param digicam_configure C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_digicam_configure_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_digicam_configure_t* digicam_configure) -{ - return mavlink_msg_digicam_configure_pack(system_id, component_id, msg, digicam_configure->target_system, digicam_configure->target_component, digicam_configure->mode, digicam_configure->shutter_speed, digicam_configure->aperture, digicam_configure->iso, digicam_configure->exposure_type, digicam_configure->command_id, digicam_configure->engine_cut_off, digicam_configure->extra_param, digicam_configure->extra_value); -} - -/** - * @brief Send a digicam_configure message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param mode Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) - * @param shutter_speed Divisor number //e.g. 1000 means 1/1000 (0 means ignore) - * @param aperture F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) - * @param iso ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) - * @param exposure_type Exposure type enumeration from 1 to N (0 means ignore) - * @param command_id Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - * @param engine_cut_off Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) - * @param extra_param Extra parameters enumeration (0 means ignore) - * @param extra_value Correspondent value to given extra_param - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_digicam_configure_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t mode, uint16_t shutter_speed, uint8_t aperture, uint8_t iso, uint8_t exposure_type, uint8_t command_id, uint8_t engine_cut_off, uint8_t extra_param, float extra_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[15]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, mode); - _mav_put_uint16_t(buf, 3, shutter_speed); - _mav_put_uint8_t(buf, 5, aperture); - _mav_put_uint8_t(buf, 6, iso); - _mav_put_uint8_t(buf, 7, exposure_type); - _mav_put_uint8_t(buf, 8, command_id); - _mav_put_uint8_t(buf, 9, engine_cut_off); - _mav_put_uint8_t(buf, 10, extra_param); - _mav_put_float(buf, 11, extra_value); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIGICAM_CONFIGURE, buf, 15); -#else - mavlink_digicam_configure_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mode = mode; - packet.shutter_speed = shutter_speed; - packet.aperture = aperture; - packet.iso = iso; - packet.exposure_type = exposure_type; - packet.command_id = command_id; - packet.engine_cut_off = engine_cut_off; - packet.extra_param = extra_param; - packet.extra_value = extra_value; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIGICAM_CONFIGURE, (const char *)&packet, 15); -#endif -} - -#endif - -// MESSAGE DIGICAM_CONFIGURE UNPACKING - - -/** - * @brief Get field target_system from digicam_configure message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_digicam_configure_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from digicam_configure message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_digicam_configure_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field mode from digicam_configure message - * - * @return Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_configure_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field shutter_speed from digicam_configure message - * - * @return Divisor number //e.g. 1000 means 1/1000 (0 means ignore) - */ -static inline uint16_t mavlink_msg_digicam_configure_get_shutter_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field aperture from digicam_configure message - * - * @return F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_configure_get_aperture(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field iso from digicam_configure message - * - * @return ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_configure_get_iso(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field exposure_type from digicam_configure message - * - * @return Exposure type enumeration from 1 to N (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_configure_get_exposure_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 7); -} - -/** - * @brief Get field command_id from digicam_configure message - * - * @return Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - */ -static inline uint8_t mavlink_msg_digicam_configure_get_command_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Get field engine_cut_off from digicam_configure message - * - * @return Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) - */ -static inline uint8_t mavlink_msg_digicam_configure_get_engine_cut_off(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 9); -} - -/** - * @brief Get field extra_param from digicam_configure message - * - * @return Extra parameters enumeration (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_configure_get_extra_param(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 10); -} - -/** - * @brief Get field extra_value from digicam_configure message - * - * @return Correspondent value to given extra_param - */ -static inline float mavlink_msg_digicam_configure_get_extra_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 11); -} - -/** - * @brief Decode a digicam_configure message into a struct - * - * @param msg The message to decode - * @param digicam_configure C-struct to decode the message contents into - */ -static inline void mavlink_msg_digicam_configure_decode(const mavlink_message_t* msg, mavlink_digicam_configure_t* digicam_configure) -{ -#if MAVLINK_NEED_BYTE_SWAP - digicam_configure->target_system = mavlink_msg_digicam_configure_get_target_system(msg); - digicam_configure->target_component = mavlink_msg_digicam_configure_get_target_component(msg); - digicam_configure->mode = mavlink_msg_digicam_configure_get_mode(msg); - digicam_configure->shutter_speed = mavlink_msg_digicam_configure_get_shutter_speed(msg); - digicam_configure->aperture = mavlink_msg_digicam_configure_get_aperture(msg); - digicam_configure->iso = mavlink_msg_digicam_configure_get_iso(msg); - digicam_configure->exposure_type = mavlink_msg_digicam_configure_get_exposure_type(msg); - digicam_configure->command_id = mavlink_msg_digicam_configure_get_command_id(msg); - digicam_configure->engine_cut_off = mavlink_msg_digicam_configure_get_engine_cut_off(msg); - digicam_configure->extra_param = mavlink_msg_digicam_configure_get_extra_param(msg); - digicam_configure->extra_value = mavlink_msg_digicam_configure_get_extra_value(msg); -#else - memcpy(digicam_configure, _MAV_PAYLOAD(msg), 15); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_digicam_control.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_digicam_control.h deleted file mode 100644 index f0cc511de7..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_digicam_control.h +++ /dev/null @@ -1,342 +0,0 @@ -// MESSAGE DIGICAM_CONTROL PACKING - -#define MAVLINK_MSG_ID_DIGICAM_CONTROL 155 - -typedef struct __mavlink_digicam_control_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t session; ///< 0: stop, 1: start or keep it up //Session control e.g. show/hide lens - uint8_t zoom_pos; ///< 1 to N //Zoom's absolute position (0 means ignore) - int8_t zoom_step; ///< -100 to 100 //Zooming step value to offset zoom from the current position - uint8_t focus_lock; ///< 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus - uint8_t shot; ///< 0: ignore, 1: shot or start filming - uint8_t command_id; ///< Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - uint8_t extra_param; ///< Extra parameters enumeration (0 means ignore) - float extra_value; ///< Correspondent value to given extra_param -} mavlink_digicam_control_t; - -#define MAVLINK_MSG_ID_DIGICAM_CONTROL_LEN 13 -#define MAVLINK_MSG_ID_155_LEN 13 - - - -#define MAVLINK_MESSAGE_INFO_DIGICAM_CONTROL { \ - "DIGICAM_CONTROL", \ - 10, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_digicam_control_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_digicam_control_t, target_component) }, \ - { "session", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_digicam_control_t, session) }, \ - { "zoom_pos", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_digicam_control_t, zoom_pos) }, \ - { "zoom_step", NULL, MAVLINK_TYPE_INT8_T, 0, 4, offsetof(mavlink_digicam_control_t, zoom_step) }, \ - { "focus_lock", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_digicam_control_t, focus_lock) }, \ - { "shot", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_digicam_control_t, shot) }, \ - { "command_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_digicam_control_t, command_id) }, \ - { "extra_param", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_digicam_control_t, extra_param) }, \ - { "extra_value", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_digicam_control_t, extra_value) }, \ - } \ -} - - -/** - * @brief Pack a digicam_control message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param session 0: stop, 1: start or keep it up //Session control e.g. show/hide lens - * @param zoom_pos 1 to N //Zoom's absolute position (0 means ignore) - * @param zoom_step -100 to 100 //Zooming step value to offset zoom from the current position - * @param focus_lock 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus - * @param shot 0: ignore, 1: shot or start filming - * @param command_id Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - * @param extra_param Extra parameters enumeration (0 means ignore) - * @param extra_value Correspondent value to given extra_param - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_digicam_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t session, uint8_t zoom_pos, int8_t zoom_step, uint8_t focus_lock, uint8_t shot, uint8_t command_id, uint8_t extra_param, float extra_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, session); - _mav_put_uint8_t(buf, 3, zoom_pos); - _mav_put_int8_t(buf, 4, zoom_step); - _mav_put_uint8_t(buf, 5, focus_lock); - _mav_put_uint8_t(buf, 6, shot); - _mav_put_uint8_t(buf, 7, command_id); - _mav_put_uint8_t(buf, 8, extra_param); - _mav_put_float(buf, 9, extra_value); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 13); -#else - mavlink_digicam_control_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.session = session; - packet.zoom_pos = zoom_pos; - packet.zoom_step = zoom_step; - packet.focus_lock = focus_lock; - packet.shot = shot; - packet.command_id = command_id; - packet.extra_param = extra_param; - packet.extra_value = extra_value; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 13); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIGICAM_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 13); -} - -/** - * @brief Pack a digicam_control message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param session 0: stop, 1: start or keep it up //Session control e.g. show/hide lens - * @param zoom_pos 1 to N //Zoom's absolute position (0 means ignore) - * @param zoom_step -100 to 100 //Zooming step value to offset zoom from the current position - * @param focus_lock 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus - * @param shot 0: ignore, 1: shot or start filming - * @param command_id Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - * @param extra_param Extra parameters enumeration (0 means ignore) - * @param extra_value Correspondent value to given extra_param - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_digicam_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t session,uint8_t zoom_pos,int8_t zoom_step,uint8_t focus_lock,uint8_t shot,uint8_t command_id,uint8_t extra_param,float extra_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, session); - _mav_put_uint8_t(buf, 3, zoom_pos); - _mav_put_int8_t(buf, 4, zoom_step); - _mav_put_uint8_t(buf, 5, focus_lock); - _mav_put_uint8_t(buf, 6, shot); - _mav_put_uint8_t(buf, 7, command_id); - _mav_put_uint8_t(buf, 8, extra_param); - _mav_put_float(buf, 9, extra_value); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 13); -#else - mavlink_digicam_control_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.session = session; - packet.zoom_pos = zoom_pos; - packet.zoom_step = zoom_step; - packet.focus_lock = focus_lock; - packet.shot = shot; - packet.command_id = command_id; - packet.extra_param = extra_param; - packet.extra_value = extra_value; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 13); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIGICAM_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 13); -} - -/** - * @brief Encode a digicam_control struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param digicam_control C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_digicam_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_digicam_control_t* digicam_control) -{ - return mavlink_msg_digicam_control_pack(system_id, component_id, msg, digicam_control->target_system, digicam_control->target_component, digicam_control->session, digicam_control->zoom_pos, digicam_control->zoom_step, digicam_control->focus_lock, digicam_control->shot, digicam_control->command_id, digicam_control->extra_param, digicam_control->extra_value); -} - -/** - * @brief Send a digicam_control message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param session 0: stop, 1: start or keep it up //Session control e.g. show/hide lens - * @param zoom_pos 1 to N //Zoom's absolute position (0 means ignore) - * @param zoom_step -100 to 100 //Zooming step value to offset zoom from the current position - * @param focus_lock 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus - * @param shot 0: ignore, 1: shot or start filming - * @param command_id Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - * @param extra_param Extra parameters enumeration (0 means ignore) - * @param extra_value Correspondent value to given extra_param - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_digicam_control_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t session, uint8_t zoom_pos, int8_t zoom_step, uint8_t focus_lock, uint8_t shot, uint8_t command_id, uint8_t extra_param, float extra_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, session); - _mav_put_uint8_t(buf, 3, zoom_pos); - _mav_put_int8_t(buf, 4, zoom_step); - _mav_put_uint8_t(buf, 5, focus_lock); - _mav_put_uint8_t(buf, 6, shot); - _mav_put_uint8_t(buf, 7, command_id); - _mav_put_uint8_t(buf, 8, extra_param); - _mav_put_float(buf, 9, extra_value); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIGICAM_CONTROL, buf, 13); -#else - mavlink_digicam_control_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.session = session; - packet.zoom_pos = zoom_pos; - packet.zoom_step = zoom_step; - packet.focus_lock = focus_lock; - packet.shot = shot; - packet.command_id = command_id; - packet.extra_param = extra_param; - packet.extra_value = extra_value; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIGICAM_CONTROL, (const char *)&packet, 13); -#endif -} - -#endif - -// MESSAGE DIGICAM_CONTROL UNPACKING - - -/** - * @brief Get field target_system from digicam_control message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_digicam_control_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from digicam_control message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_digicam_control_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field session from digicam_control message - * - * @return 0: stop, 1: start or keep it up //Session control e.g. show/hide lens - */ -static inline uint8_t mavlink_msg_digicam_control_get_session(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field zoom_pos from digicam_control message - * - * @return 1 to N //Zoom's absolute position (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_control_get_zoom_pos(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field zoom_step from digicam_control message - * - * @return -100 to 100 //Zooming step value to offset zoom from the current position - */ -static inline int8_t mavlink_msg_digicam_control_get_zoom_step(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int8_t(msg, 4); -} - -/** - * @brief Get field focus_lock from digicam_control message - * - * @return 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus - */ -static inline uint8_t mavlink_msg_digicam_control_get_focus_lock(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field shot from digicam_control message - * - * @return 0: ignore, 1: shot or start filming - */ -static inline uint8_t mavlink_msg_digicam_control_get_shot(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field command_id from digicam_control message - * - * @return Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once - */ -static inline uint8_t mavlink_msg_digicam_control_get_command_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 7); -} - -/** - * @brief Get field extra_param from digicam_control message - * - * @return Extra parameters enumeration (0 means ignore) - */ -static inline uint8_t mavlink_msg_digicam_control_get_extra_param(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Get field extra_value from digicam_control message - * - * @return Correspondent value to given extra_param - */ -static inline float mavlink_msg_digicam_control_get_extra_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Decode a digicam_control message into a struct - * - * @param msg The message to decode - * @param digicam_control C-struct to decode the message contents into - */ -static inline void mavlink_msg_digicam_control_decode(const mavlink_message_t* msg, mavlink_digicam_control_t* digicam_control) -{ -#if MAVLINK_NEED_BYTE_SWAP - digicam_control->target_system = mavlink_msg_digicam_control_get_target_system(msg); - digicam_control->target_component = mavlink_msg_digicam_control_get_target_component(msg); - digicam_control->session = mavlink_msg_digicam_control_get_session(msg); - digicam_control->zoom_pos = mavlink_msg_digicam_control_get_zoom_pos(msg); - digicam_control->zoom_step = mavlink_msg_digicam_control_get_zoom_step(msg); - digicam_control->focus_lock = mavlink_msg_digicam_control_get_focus_lock(msg); - digicam_control->shot = mavlink_msg_digicam_control_get_shot(msg); - digicam_control->command_id = mavlink_msg_digicam_control_get_command_id(msg); - digicam_control->extra_param = mavlink_msg_digicam_control_get_extra_param(msg); - digicam_control->extra_value = mavlink_msg_digicam_control_get_extra_value(msg); -#else - memcpy(digicam_control, _MAV_PAYLOAD(msg), 13); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_fetch_point.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_fetch_point.h deleted file mode 100644 index 112b1ecf07..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_fetch_point.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE FENCE_FETCH_POINT PACKING - -#define MAVLINK_MSG_ID_FENCE_FETCH_POINT 161 - -typedef struct __mavlink_fence_fetch_point_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t idx; ///< point index (first point is 1, 0 is for return point) -} mavlink_fence_fetch_point_t; - -#define MAVLINK_MSG_ID_FENCE_FETCH_POINT_LEN 3 -#define MAVLINK_MSG_ID_161_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_FENCE_FETCH_POINT { \ - "FENCE_FETCH_POINT", \ - 3, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_fence_fetch_point_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_fence_fetch_point_t, target_component) }, \ - { "idx", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_fence_fetch_point_t, idx) }, \ - } \ -} - - -/** - * @brief Pack a fence_fetch_point message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param idx point index (first point is 1, 0 is for return point) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_fence_fetch_point_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t idx) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, idx); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_fence_fetch_point_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.idx = idx; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_FENCE_FETCH_POINT; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a fence_fetch_point message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param idx point index (first point is 1, 0 is for return point) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_fence_fetch_point_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t idx) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, idx); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_fence_fetch_point_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.idx = idx; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_FENCE_FETCH_POINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a fence_fetch_point struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param fence_fetch_point C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_fence_fetch_point_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_fence_fetch_point_t* fence_fetch_point) -{ - return mavlink_msg_fence_fetch_point_pack(system_id, component_id, msg, fence_fetch_point->target_system, fence_fetch_point->target_component, fence_fetch_point->idx); -} - -/** - * @brief Send a fence_fetch_point message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param idx point index (first point is 1, 0 is for return point) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_fence_fetch_point_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t idx) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, idx); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_FENCE_FETCH_POINT, buf, 3); -#else - mavlink_fence_fetch_point_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.idx = idx; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_FENCE_FETCH_POINT, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE FENCE_FETCH_POINT UNPACKING - - -/** - * @brief Get field target_system from fence_fetch_point message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_fence_fetch_point_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from fence_fetch_point message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_fence_fetch_point_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field idx from fence_fetch_point message - * - * @return point index (first point is 1, 0 is for return point) - */ -static inline uint8_t mavlink_msg_fence_fetch_point_get_idx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a fence_fetch_point message into a struct - * - * @param msg The message to decode - * @param fence_fetch_point C-struct to decode the message contents into - */ -static inline void mavlink_msg_fence_fetch_point_decode(const mavlink_message_t* msg, mavlink_fence_fetch_point_t* fence_fetch_point) -{ -#if MAVLINK_NEED_BYTE_SWAP - fence_fetch_point->target_system = mavlink_msg_fence_fetch_point_get_target_system(msg); - fence_fetch_point->target_component = mavlink_msg_fence_fetch_point_get_target_component(msg); - fence_fetch_point->idx = mavlink_msg_fence_fetch_point_get_idx(msg); -#else - memcpy(fence_fetch_point, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_point.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_point.h deleted file mode 100644 index b46b259f44..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_point.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE FENCE_POINT PACKING - -#define MAVLINK_MSG_ID_FENCE_POINT 160 - -typedef struct __mavlink_fence_point_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t idx; ///< point index (first point is 1, 0 is for return point) - uint8_t count; ///< total number of points (for sanity checking) - float lat; ///< Latitude of point - float lng; ///< Longitude of point -} mavlink_fence_point_t; - -#define MAVLINK_MSG_ID_FENCE_POINT_LEN 12 -#define MAVLINK_MSG_ID_160_LEN 12 - - - -#define MAVLINK_MESSAGE_INFO_FENCE_POINT { \ - "FENCE_POINT", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_fence_point_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_fence_point_t, target_component) }, \ - { "idx", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_fence_point_t, idx) }, \ - { "count", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_fence_point_t, count) }, \ - { "lat", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_fence_point_t, lat) }, \ - { "lng", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_fence_point_t, lng) }, \ - } \ -} - - -/** - * @brief Pack a fence_point message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param idx point index (first point is 1, 0 is for return point) - * @param count total number of points (for sanity checking) - * @param lat Latitude of point - * @param lng Longitude of point - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_fence_point_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t idx, uint8_t count, float lat, float lng) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, idx); - _mav_put_uint8_t(buf, 3, count); - _mav_put_float(buf, 4, lat); - _mav_put_float(buf, 8, lng); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_fence_point_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.idx = idx; - packet.count = count; - packet.lat = lat; - packet.lng = lng; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_FENCE_POINT; - return mavlink_finalize_message(msg, system_id, component_id, 12); -} - -/** - * @brief Pack a fence_point message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param idx point index (first point is 1, 0 is for return point) - * @param count total number of points (for sanity checking) - * @param lat Latitude of point - * @param lng Longitude of point - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_fence_point_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t idx,uint8_t count,float lat,float lng) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, idx); - _mav_put_uint8_t(buf, 3, count); - _mav_put_float(buf, 4, lat); - _mav_put_float(buf, 8, lng); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_fence_point_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.idx = idx; - packet.count = count; - packet.lat = lat; - packet.lng = lng; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_FENCE_POINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 12); -} - -/** - * @brief Encode a fence_point struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param fence_point C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_fence_point_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_fence_point_t* fence_point) -{ - return mavlink_msg_fence_point_pack(system_id, component_id, msg, fence_point->target_system, fence_point->target_component, fence_point->idx, fence_point->count, fence_point->lat, fence_point->lng); -} - -/** - * @brief Send a fence_point message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param idx point index (first point is 1, 0 is for return point) - * @param count total number of points (for sanity checking) - * @param lat Latitude of point - * @param lng Longitude of point - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_fence_point_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t idx, uint8_t count, float lat, float lng) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, idx); - _mav_put_uint8_t(buf, 3, count); - _mav_put_float(buf, 4, lat); - _mav_put_float(buf, 8, lng); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_FENCE_POINT, buf, 12); -#else - mavlink_fence_point_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.idx = idx; - packet.count = count; - packet.lat = lat; - packet.lng = lng; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_FENCE_POINT, (const char *)&packet, 12); -#endif -} - -#endif - -// MESSAGE FENCE_POINT UNPACKING - - -/** - * @brief Get field target_system from fence_point message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_fence_point_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from fence_point message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_fence_point_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field idx from fence_point message - * - * @return point index (first point is 1, 0 is for return point) - */ -static inline uint8_t mavlink_msg_fence_point_get_idx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field count from fence_point message - * - * @return total number of points (for sanity checking) - */ -static inline uint8_t mavlink_msg_fence_point_get_count(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field lat from fence_point message - * - * @return Latitude of point - */ -static inline float mavlink_msg_fence_point_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field lng from fence_point message - * - * @return Longitude of point - */ -static inline float mavlink_msg_fence_point_get_lng(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Decode a fence_point message into a struct - * - * @param msg The message to decode - * @param fence_point C-struct to decode the message contents into - */ -static inline void mavlink_msg_fence_point_decode(const mavlink_message_t* msg, mavlink_fence_point_t* fence_point) -{ -#if MAVLINK_NEED_BYTE_SWAP - fence_point->target_system = mavlink_msg_fence_point_get_target_system(msg); - fence_point->target_component = mavlink_msg_fence_point_get_target_component(msg); - fence_point->idx = mavlink_msg_fence_point_get_idx(msg); - fence_point->count = mavlink_msg_fence_point_get_count(msg); - fence_point->lat = mavlink_msg_fence_point_get_lat(msg); - fence_point->lng = mavlink_msg_fence_point_get_lng(msg); -#else - memcpy(fence_point, _MAV_PAYLOAD(msg), 12); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_status.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_status.h deleted file mode 100644 index 77b3e56310..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_fence_status.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE FENCE_STATUS PACKING - -#define MAVLINK_MSG_ID_FENCE_STATUS 162 - -typedef struct __mavlink_fence_status_t -{ - uint8_t breach_status; ///< 0 if currently inside fence, 1 if outside - uint16_t breach_count; ///< number of fence breaches - uint8_t breach_type; ///< last breach type (see FENCE_BREACH_* enum) - uint32_t breach_time; ///< time of last breach in milliseconds since boot -} mavlink_fence_status_t; - -#define MAVLINK_MSG_ID_FENCE_STATUS_LEN 8 -#define MAVLINK_MSG_ID_162_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_FENCE_STATUS { \ - "FENCE_STATUS", \ - 4, \ - { { "breach_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_fence_status_t, breach_status) }, \ - { "breach_count", NULL, MAVLINK_TYPE_UINT16_T, 0, 1, offsetof(mavlink_fence_status_t, breach_count) }, \ - { "breach_type", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_fence_status_t, breach_type) }, \ - { "breach_time", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_fence_status_t, breach_time) }, \ - } \ -} - - -/** - * @brief Pack a fence_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param breach_status 0 if currently inside fence, 1 if outside - * @param breach_count number of fence breaches - * @param breach_type last breach type (see FENCE_BREACH_* enum) - * @param breach_time time of last breach in milliseconds since boot - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_fence_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t breach_status, uint16_t breach_count, uint8_t breach_type, uint32_t breach_time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, breach_status); - _mav_put_uint16_t(buf, 1, breach_count); - _mav_put_uint8_t(buf, 3, breach_type); - _mav_put_uint32_t(buf, 4, breach_time); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_fence_status_t packet; - packet.breach_status = breach_status; - packet.breach_count = breach_count; - packet.breach_type = breach_type; - packet.breach_time = breach_time; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_FENCE_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a fence_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param breach_status 0 if currently inside fence, 1 if outside - * @param breach_count number of fence breaches - * @param breach_type last breach type (see FENCE_BREACH_* enum) - * @param breach_time time of last breach in milliseconds since boot - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_fence_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t breach_status,uint16_t breach_count,uint8_t breach_type,uint32_t breach_time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, breach_status); - _mav_put_uint16_t(buf, 1, breach_count); - _mav_put_uint8_t(buf, 3, breach_type); - _mav_put_uint32_t(buf, 4, breach_time); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_fence_status_t packet; - packet.breach_status = breach_status; - packet.breach_count = breach_count; - packet.breach_type = breach_type; - packet.breach_time = breach_time; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_FENCE_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a fence_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param fence_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_fence_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_fence_status_t* fence_status) -{ - return mavlink_msg_fence_status_pack(system_id, component_id, msg, fence_status->breach_status, fence_status->breach_count, fence_status->breach_type, fence_status->breach_time); -} - -/** - * @brief Send a fence_status message - * @param chan MAVLink channel to send the message - * - * @param breach_status 0 if currently inside fence, 1 if outside - * @param breach_count number of fence breaches - * @param breach_type last breach type (see FENCE_BREACH_* enum) - * @param breach_time time of last breach in milliseconds since boot - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_fence_status_send(mavlink_channel_t chan, uint8_t breach_status, uint16_t breach_count, uint8_t breach_type, uint32_t breach_time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, breach_status); - _mav_put_uint16_t(buf, 1, breach_count); - _mav_put_uint8_t(buf, 3, breach_type); - _mav_put_uint32_t(buf, 4, breach_time); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_FENCE_STATUS, buf, 8); -#else - mavlink_fence_status_t packet; - packet.breach_status = breach_status; - packet.breach_count = breach_count; - packet.breach_type = breach_type; - packet.breach_time = breach_time; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_FENCE_STATUS, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE FENCE_STATUS UNPACKING - - -/** - * @brief Get field breach_status from fence_status message - * - * @return 0 if currently inside fence, 1 if outside - */ -static inline uint8_t mavlink_msg_fence_status_get_breach_status(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field breach_count from fence_status message - * - * @return number of fence breaches - */ -static inline uint16_t mavlink_msg_fence_status_get_breach_count(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 1); -} - -/** - * @brief Get field breach_type from fence_status message - * - * @return last breach type (see FENCE_BREACH_* enum) - */ -static inline uint8_t mavlink_msg_fence_status_get_breach_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field breach_time from fence_status message - * - * @return time of last breach in milliseconds since boot - */ -static inline uint32_t mavlink_msg_fence_status_get_breach_time(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 4); -} - -/** - * @brief Decode a fence_status message into a struct - * - * @param msg The message to decode - * @param fence_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_fence_status_decode(const mavlink_message_t* msg, mavlink_fence_status_t* fence_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - fence_status->breach_status = mavlink_msg_fence_status_get_breach_status(msg); - fence_status->breach_count = mavlink_msg_fence_status_get_breach_count(msg); - fence_status->breach_type = mavlink_msg_fence_status_get_breach_type(msg); - fence_status->breach_time = mavlink_msg_fence_status_get_breach_time(msg); -#else - memcpy(fence_status, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_hwstatus.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_hwstatus.h deleted file mode 100644 index 47cc21484a..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_hwstatus.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE HWSTATUS PACKING - -#define MAVLINK_MSG_ID_HWSTATUS 165 - -typedef struct __mavlink_hwstatus_t -{ - uint16_t Vcc; ///< board voltage (mV) - uint8_t I2Cerr; ///< I2C error count -} mavlink_hwstatus_t; - -#define MAVLINK_MSG_ID_HWSTATUS_LEN 3 -#define MAVLINK_MSG_ID_165_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_HWSTATUS { \ - "HWSTATUS", \ - 2, \ - { { "Vcc", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_hwstatus_t, Vcc) }, \ - { "I2Cerr", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_hwstatus_t, I2Cerr) }, \ - } \ -} - - -/** - * @brief Pack a hwstatus message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param Vcc board voltage (mV) - * @param I2Cerr I2C error count - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_hwstatus_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t Vcc, uint8_t I2Cerr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint16_t(buf, 0, Vcc); - _mav_put_uint8_t(buf, 2, I2Cerr); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_hwstatus_t packet; - packet.Vcc = Vcc; - packet.I2Cerr = I2Cerr; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_HWSTATUS; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a hwstatus message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param Vcc board voltage (mV) - * @param I2Cerr I2C error count - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_hwstatus_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t Vcc,uint8_t I2Cerr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint16_t(buf, 0, Vcc); - _mav_put_uint8_t(buf, 2, I2Cerr); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_hwstatus_t packet; - packet.Vcc = Vcc; - packet.I2Cerr = I2Cerr; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_HWSTATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a hwstatus struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param hwstatus C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_hwstatus_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_hwstatus_t* hwstatus) -{ - return mavlink_msg_hwstatus_pack(system_id, component_id, msg, hwstatus->Vcc, hwstatus->I2Cerr); -} - -/** - * @brief Send a hwstatus message - * @param chan MAVLink channel to send the message - * - * @param Vcc board voltage (mV) - * @param I2Cerr I2C error count - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_hwstatus_send(mavlink_channel_t chan, uint16_t Vcc, uint8_t I2Cerr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint16_t(buf, 0, Vcc); - _mav_put_uint8_t(buf, 2, I2Cerr); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HWSTATUS, buf, 3); -#else - mavlink_hwstatus_t packet; - packet.Vcc = Vcc; - packet.I2Cerr = I2Cerr; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HWSTATUS, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE HWSTATUS UNPACKING - - -/** - * @brief Get field Vcc from hwstatus message - * - * @return board voltage (mV) - */ -static inline uint16_t mavlink_msg_hwstatus_get_Vcc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field I2Cerr from hwstatus message - * - * @return I2C error count - */ -static inline uint8_t mavlink_msg_hwstatus_get_I2Cerr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a hwstatus message into a struct - * - * @param msg The message to decode - * @param hwstatus C-struct to decode the message contents into - */ -static inline void mavlink_msg_hwstatus_decode(const mavlink_message_t* msg, mavlink_hwstatus_t* hwstatus) -{ -#if MAVLINK_NEED_BYTE_SWAP - hwstatus->Vcc = mavlink_msg_hwstatus_get_Vcc(msg); - hwstatus->I2Cerr = mavlink_msg_hwstatus_get_I2Cerr(msg); -#else - memcpy(hwstatus, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_meminfo.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_meminfo.h deleted file mode 100644 index e9efa5da22..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_meminfo.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE MEMINFO PACKING - -#define MAVLINK_MSG_ID_MEMINFO 152 - -typedef struct __mavlink_meminfo_t -{ - uint16_t brkval; ///< heap top - uint16_t freemem; ///< free memory -} mavlink_meminfo_t; - -#define MAVLINK_MSG_ID_MEMINFO_LEN 4 -#define MAVLINK_MSG_ID_152_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_MEMINFO { \ - "MEMINFO", \ - 2, \ - { { "brkval", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_meminfo_t, brkval) }, \ - { "freemem", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_meminfo_t, freemem) }, \ - } \ -} - - -/** - * @brief Pack a meminfo message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param brkval heap top - * @param freemem free memory - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_meminfo_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t brkval, uint16_t freemem) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, brkval); - _mav_put_uint16_t(buf, 2, freemem); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_meminfo_t packet; - packet.brkval = brkval; - packet.freemem = freemem; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_MEMINFO; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a meminfo message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param brkval heap top - * @param freemem free memory - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_meminfo_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t brkval,uint16_t freemem) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, brkval); - _mav_put_uint16_t(buf, 2, freemem); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_meminfo_t packet; - packet.brkval = brkval; - packet.freemem = freemem; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_MEMINFO; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a meminfo struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param meminfo C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_meminfo_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_meminfo_t* meminfo) -{ - return mavlink_msg_meminfo_pack(system_id, component_id, msg, meminfo->brkval, meminfo->freemem); -} - -/** - * @brief Send a meminfo message - * @param chan MAVLink channel to send the message - * - * @param brkval heap top - * @param freemem free memory - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_meminfo_send(mavlink_channel_t chan, uint16_t brkval, uint16_t freemem) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, brkval); - _mav_put_uint16_t(buf, 2, freemem); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MEMINFO, buf, 4); -#else - mavlink_meminfo_t packet; - packet.brkval = brkval; - packet.freemem = freemem; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MEMINFO, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE MEMINFO UNPACKING - - -/** - * @brief Get field brkval from meminfo message - * - * @return heap top - */ -static inline uint16_t mavlink_msg_meminfo_get_brkval(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field freemem from meminfo message - * - * @return free memory - */ -static inline uint16_t mavlink_msg_meminfo_get_freemem(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a meminfo message into a struct - * - * @param msg The message to decode - * @param meminfo C-struct to decode the message contents into - */ -static inline void mavlink_msg_meminfo_decode(const mavlink_message_t* msg, mavlink_meminfo_t* meminfo) -{ -#if MAVLINK_NEED_BYTE_SWAP - meminfo->brkval = mavlink_msg_meminfo_get_brkval(msg); - meminfo->freemem = mavlink_msg_meminfo_get_freemem(msg); -#else - memcpy(meminfo, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_configure.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_configure.h deleted file mode 100644 index 688d89415a..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_configure.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE MOUNT_CONFIGURE PACKING - -#define MAVLINK_MSG_ID_MOUNT_CONFIGURE 156 - -typedef struct __mavlink_mount_configure_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t mount_mode; ///< mount operating mode (see MAV_MOUNT_MODE enum) - uint8_t stab_roll; ///< (1 = yes, 0 = no) - uint8_t stab_pitch; ///< (1 = yes, 0 = no) - uint8_t stab_yaw; ///< (1 = yes, 0 = no) -} mavlink_mount_configure_t; - -#define MAVLINK_MSG_ID_MOUNT_CONFIGURE_LEN 6 -#define MAVLINK_MSG_ID_156_LEN 6 - - - -#define MAVLINK_MESSAGE_INFO_MOUNT_CONFIGURE { \ - "MOUNT_CONFIGURE", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_mount_configure_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_mount_configure_t, target_component) }, \ - { "mount_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_mount_configure_t, mount_mode) }, \ - { "stab_roll", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_mount_configure_t, stab_roll) }, \ - { "stab_pitch", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_mount_configure_t, stab_pitch) }, \ - { "stab_yaw", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_mount_configure_t, stab_yaw) }, \ - } \ -} - - -/** - * @brief Pack a mount_configure message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param mount_mode mount operating mode (see MAV_MOUNT_MODE enum) - * @param stab_roll (1 = yes, 0 = no) - * @param stab_pitch (1 = yes, 0 = no) - * @param stab_yaw (1 = yes, 0 = no) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mount_configure_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t mount_mode, uint8_t stab_roll, uint8_t stab_pitch, uint8_t stab_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, mount_mode); - _mav_put_uint8_t(buf, 3, stab_roll); - _mav_put_uint8_t(buf, 4, stab_pitch); - _mav_put_uint8_t(buf, 5, stab_yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 6); -#else - mavlink_mount_configure_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mount_mode = mount_mode; - packet.stab_roll = stab_roll; - packet.stab_pitch = stab_pitch; - packet.stab_yaw = stab_yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 6); -#endif - - msg->msgid = MAVLINK_MSG_ID_MOUNT_CONFIGURE; - return mavlink_finalize_message(msg, system_id, component_id, 6); -} - -/** - * @brief Pack a mount_configure message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param mount_mode mount operating mode (see MAV_MOUNT_MODE enum) - * @param stab_roll (1 = yes, 0 = no) - * @param stab_pitch (1 = yes, 0 = no) - * @param stab_yaw (1 = yes, 0 = no) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mount_configure_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t mount_mode,uint8_t stab_roll,uint8_t stab_pitch,uint8_t stab_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, mount_mode); - _mav_put_uint8_t(buf, 3, stab_roll); - _mav_put_uint8_t(buf, 4, stab_pitch); - _mav_put_uint8_t(buf, 5, stab_yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 6); -#else - mavlink_mount_configure_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mount_mode = mount_mode; - packet.stab_roll = stab_roll; - packet.stab_pitch = stab_pitch; - packet.stab_yaw = stab_yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 6); -#endif - - msg->msgid = MAVLINK_MSG_ID_MOUNT_CONFIGURE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 6); -} - -/** - * @brief Encode a mount_configure struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param mount_configure C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_mount_configure_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_mount_configure_t* mount_configure) -{ - return mavlink_msg_mount_configure_pack(system_id, component_id, msg, mount_configure->target_system, mount_configure->target_component, mount_configure->mount_mode, mount_configure->stab_roll, mount_configure->stab_pitch, mount_configure->stab_yaw); -} - -/** - * @brief Send a mount_configure message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param mount_mode mount operating mode (see MAV_MOUNT_MODE enum) - * @param stab_roll (1 = yes, 0 = no) - * @param stab_pitch (1 = yes, 0 = no) - * @param stab_yaw (1 = yes, 0 = no) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_mount_configure_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t mount_mode, uint8_t stab_roll, uint8_t stab_pitch, uint8_t stab_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, mount_mode); - _mav_put_uint8_t(buf, 3, stab_roll); - _mav_put_uint8_t(buf, 4, stab_pitch); - _mav_put_uint8_t(buf, 5, stab_yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOUNT_CONFIGURE, buf, 6); -#else - mavlink_mount_configure_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mount_mode = mount_mode; - packet.stab_roll = stab_roll; - packet.stab_pitch = stab_pitch; - packet.stab_yaw = stab_yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOUNT_CONFIGURE, (const char *)&packet, 6); -#endif -} - -#endif - -// MESSAGE MOUNT_CONFIGURE UNPACKING - - -/** - * @brief Get field target_system from mount_configure message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_mount_configure_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from mount_configure message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_mount_configure_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field mount_mode from mount_configure message - * - * @return mount operating mode (see MAV_MOUNT_MODE enum) - */ -static inline uint8_t mavlink_msg_mount_configure_get_mount_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field stab_roll from mount_configure message - * - * @return (1 = yes, 0 = no) - */ -static inline uint8_t mavlink_msg_mount_configure_get_stab_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field stab_pitch from mount_configure message - * - * @return (1 = yes, 0 = no) - */ -static inline uint8_t mavlink_msg_mount_configure_get_stab_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field stab_yaw from mount_configure message - * - * @return (1 = yes, 0 = no) - */ -static inline uint8_t mavlink_msg_mount_configure_get_stab_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Decode a mount_configure message into a struct - * - * @param msg The message to decode - * @param mount_configure C-struct to decode the message contents into - */ -static inline void mavlink_msg_mount_configure_decode(const mavlink_message_t* msg, mavlink_mount_configure_t* mount_configure) -{ -#if MAVLINK_NEED_BYTE_SWAP - mount_configure->target_system = mavlink_msg_mount_configure_get_target_system(msg); - mount_configure->target_component = mavlink_msg_mount_configure_get_target_component(msg); - mount_configure->mount_mode = mavlink_msg_mount_configure_get_mount_mode(msg); - mount_configure->stab_roll = mavlink_msg_mount_configure_get_stab_roll(msg); - mount_configure->stab_pitch = mavlink_msg_mount_configure_get_stab_pitch(msg); - mount_configure->stab_yaw = mavlink_msg_mount_configure_get_stab_yaw(msg); -#else - memcpy(mount_configure, _MAV_PAYLOAD(msg), 6); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_control.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_control.h deleted file mode 100644 index f13bea2d9f..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_control.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE MOUNT_CONTROL PACKING - -#define MAVLINK_MSG_ID_MOUNT_CONTROL 157 - -typedef struct __mavlink_mount_control_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - int32_t input_a; ///< pitch(deg*100) or lat, depending on mount mode - int32_t input_b; ///< roll(deg*100) or lon depending on mount mode - int32_t input_c; ///< yaw(deg*100) or alt (in cm) depending on mount mode - uint8_t save_position; ///< if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) -} mavlink_mount_control_t; - -#define MAVLINK_MSG_ID_MOUNT_CONTROL_LEN 15 -#define MAVLINK_MSG_ID_157_LEN 15 - - - -#define MAVLINK_MESSAGE_INFO_MOUNT_CONTROL { \ - "MOUNT_CONTROL", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_mount_control_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_mount_control_t, target_component) }, \ - { "input_a", NULL, MAVLINK_TYPE_INT32_T, 0, 2, offsetof(mavlink_mount_control_t, input_a) }, \ - { "input_b", NULL, MAVLINK_TYPE_INT32_T, 0, 6, offsetof(mavlink_mount_control_t, input_b) }, \ - { "input_c", NULL, MAVLINK_TYPE_INT32_T, 0, 10, offsetof(mavlink_mount_control_t, input_c) }, \ - { "save_position", NULL, MAVLINK_TYPE_UINT8_T, 0, 14, offsetof(mavlink_mount_control_t, save_position) }, \ - } \ -} - - -/** - * @brief Pack a mount_control message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param input_a pitch(deg*100) or lat, depending on mount mode - * @param input_b roll(deg*100) or lon depending on mount mode - * @param input_c yaw(deg*100) or alt (in cm) depending on mount mode - * @param save_position if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mount_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, int32_t input_a, int32_t input_b, int32_t input_c, uint8_t save_position) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[15]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, input_a); - _mav_put_int32_t(buf, 6, input_b); - _mav_put_int32_t(buf, 10, input_c); - _mav_put_uint8_t(buf, 14, save_position); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 15); -#else - mavlink_mount_control_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.input_a = input_a; - packet.input_b = input_b; - packet.input_c = input_c; - packet.save_position = save_position; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 15); -#endif - - msg->msgid = MAVLINK_MSG_ID_MOUNT_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 15); -} - -/** - * @brief Pack a mount_control message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param input_a pitch(deg*100) or lat, depending on mount mode - * @param input_b roll(deg*100) or lon depending on mount mode - * @param input_c yaw(deg*100) or alt (in cm) depending on mount mode - * @param save_position if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mount_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,int32_t input_a,int32_t input_b,int32_t input_c,uint8_t save_position) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[15]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, input_a); - _mav_put_int32_t(buf, 6, input_b); - _mav_put_int32_t(buf, 10, input_c); - _mav_put_uint8_t(buf, 14, save_position); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 15); -#else - mavlink_mount_control_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.input_a = input_a; - packet.input_b = input_b; - packet.input_c = input_c; - packet.save_position = save_position; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 15); -#endif - - msg->msgid = MAVLINK_MSG_ID_MOUNT_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 15); -} - -/** - * @brief Encode a mount_control struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param mount_control C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_mount_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_mount_control_t* mount_control) -{ - return mavlink_msg_mount_control_pack(system_id, component_id, msg, mount_control->target_system, mount_control->target_component, mount_control->input_a, mount_control->input_b, mount_control->input_c, mount_control->save_position); -} - -/** - * @brief Send a mount_control message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param input_a pitch(deg*100) or lat, depending on mount mode - * @param input_b roll(deg*100) or lon depending on mount mode - * @param input_c yaw(deg*100) or alt (in cm) depending on mount mode - * @param save_position if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_mount_control_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, int32_t input_a, int32_t input_b, int32_t input_c, uint8_t save_position) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[15]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, input_a); - _mav_put_int32_t(buf, 6, input_b); - _mav_put_int32_t(buf, 10, input_c); - _mav_put_uint8_t(buf, 14, save_position); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOUNT_CONTROL, buf, 15); -#else - mavlink_mount_control_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.input_a = input_a; - packet.input_b = input_b; - packet.input_c = input_c; - packet.save_position = save_position; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOUNT_CONTROL, (const char *)&packet, 15); -#endif -} - -#endif - -// MESSAGE MOUNT_CONTROL UNPACKING - - -/** - * @brief Get field target_system from mount_control message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_mount_control_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from mount_control message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_mount_control_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field input_a from mount_control message - * - * @return pitch(deg*100) or lat, depending on mount mode - */ -static inline int32_t mavlink_msg_mount_control_get_input_a(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 2); -} - -/** - * @brief Get field input_b from mount_control message - * - * @return roll(deg*100) or lon depending on mount mode - */ -static inline int32_t mavlink_msg_mount_control_get_input_b(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 6); -} - -/** - * @brief Get field input_c from mount_control message - * - * @return yaw(deg*100) or alt (in cm) depending on mount mode - */ -static inline int32_t mavlink_msg_mount_control_get_input_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 10); -} - -/** - * @brief Get field save_position from mount_control message - * - * @return if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) - */ -static inline uint8_t mavlink_msg_mount_control_get_save_position(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 14); -} - -/** - * @brief Decode a mount_control message into a struct - * - * @param msg The message to decode - * @param mount_control C-struct to decode the message contents into - */ -static inline void mavlink_msg_mount_control_decode(const mavlink_message_t* msg, mavlink_mount_control_t* mount_control) -{ -#if MAVLINK_NEED_BYTE_SWAP - mount_control->target_system = mavlink_msg_mount_control_get_target_system(msg); - mount_control->target_component = mavlink_msg_mount_control_get_target_component(msg); - mount_control->input_a = mavlink_msg_mount_control_get_input_a(msg); - mount_control->input_b = mavlink_msg_mount_control_get_input_b(msg); - mount_control->input_c = mavlink_msg_mount_control_get_input_c(msg); - mount_control->save_position = mavlink_msg_mount_control_get_save_position(msg); -#else - memcpy(mount_control, _MAV_PAYLOAD(msg), 15); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_status.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_status.h deleted file mode 100644 index 75a44321ec..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_mount_status.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE MOUNT_STATUS PACKING - -#define MAVLINK_MSG_ID_MOUNT_STATUS 158 - -typedef struct __mavlink_mount_status_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - int32_t pointing_a; ///< pitch(deg*100) or lat, depending on mount mode - int32_t pointing_b; ///< roll(deg*100) or lon depending on mount mode - int32_t pointing_c; ///< yaw(deg*100) or alt (in cm) depending on mount mode -} mavlink_mount_status_t; - -#define MAVLINK_MSG_ID_MOUNT_STATUS_LEN 14 -#define MAVLINK_MSG_ID_158_LEN 14 - - - -#define MAVLINK_MESSAGE_INFO_MOUNT_STATUS { \ - "MOUNT_STATUS", \ - 5, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_mount_status_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_mount_status_t, target_component) }, \ - { "pointing_a", NULL, MAVLINK_TYPE_INT32_T, 0, 2, offsetof(mavlink_mount_status_t, pointing_a) }, \ - { "pointing_b", NULL, MAVLINK_TYPE_INT32_T, 0, 6, offsetof(mavlink_mount_status_t, pointing_b) }, \ - { "pointing_c", NULL, MAVLINK_TYPE_INT32_T, 0, 10, offsetof(mavlink_mount_status_t, pointing_c) }, \ - } \ -} - - -/** - * @brief Pack a mount_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param pointing_a pitch(deg*100) or lat, depending on mount mode - * @param pointing_b roll(deg*100) or lon depending on mount mode - * @param pointing_c yaw(deg*100) or alt (in cm) depending on mount mode - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mount_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, int32_t pointing_a, int32_t pointing_b, int32_t pointing_c) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, pointing_a); - _mav_put_int32_t(buf, 6, pointing_b); - _mav_put_int32_t(buf, 10, pointing_c); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_mount_status_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.pointing_a = pointing_a; - packet.pointing_b = pointing_b; - packet.pointing_c = pointing_c; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_MOUNT_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 14); -} - -/** - * @brief Pack a mount_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param pointing_a pitch(deg*100) or lat, depending on mount mode - * @param pointing_b roll(deg*100) or lon depending on mount mode - * @param pointing_c yaw(deg*100) or alt (in cm) depending on mount mode - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mount_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,int32_t pointing_a,int32_t pointing_b,int32_t pointing_c) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, pointing_a); - _mav_put_int32_t(buf, 6, pointing_b); - _mav_put_int32_t(buf, 10, pointing_c); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_mount_status_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.pointing_a = pointing_a; - packet.pointing_b = pointing_b; - packet.pointing_c = pointing_c; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_MOUNT_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 14); -} - -/** - * @brief Encode a mount_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param mount_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_mount_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_mount_status_t* mount_status) -{ - return mavlink_msg_mount_status_pack(system_id, component_id, msg, mount_status->target_system, mount_status->target_component, mount_status->pointing_a, mount_status->pointing_b, mount_status->pointing_c); -} - -/** - * @brief Send a mount_status message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param pointing_a pitch(deg*100) or lat, depending on mount mode - * @param pointing_b roll(deg*100) or lon depending on mount mode - * @param pointing_c yaw(deg*100) or alt (in cm) depending on mount mode - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_mount_status_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, int32_t pointing_a, int32_t pointing_b, int32_t pointing_c) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, pointing_a); - _mav_put_int32_t(buf, 6, pointing_b); - _mav_put_int32_t(buf, 10, pointing_c); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOUNT_STATUS, buf, 14); -#else - mavlink_mount_status_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.pointing_a = pointing_a; - packet.pointing_b = pointing_b; - packet.pointing_c = pointing_c; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOUNT_STATUS, (const char *)&packet, 14); -#endif -} - -#endif - -// MESSAGE MOUNT_STATUS UNPACKING - - -/** - * @brief Get field target_system from mount_status message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_mount_status_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from mount_status message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_mount_status_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field pointing_a from mount_status message - * - * @return pitch(deg*100) or lat, depending on mount mode - */ -static inline int32_t mavlink_msg_mount_status_get_pointing_a(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 2); -} - -/** - * @brief Get field pointing_b from mount_status message - * - * @return roll(deg*100) or lon depending on mount mode - */ -static inline int32_t mavlink_msg_mount_status_get_pointing_b(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 6); -} - -/** - * @brief Get field pointing_c from mount_status message - * - * @return yaw(deg*100) or alt (in cm) depending on mount mode - */ -static inline int32_t mavlink_msg_mount_status_get_pointing_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 10); -} - -/** - * @brief Decode a mount_status message into a struct - * - * @param msg The message to decode - * @param mount_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_mount_status_decode(const mavlink_message_t* msg, mavlink_mount_status_t* mount_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - mount_status->target_system = mavlink_msg_mount_status_get_target_system(msg); - mount_status->target_component = mavlink_msg_mount_status_get_target_component(msg); - mount_status->pointing_a = mavlink_msg_mount_status_get_pointing_a(msg); - mount_status->pointing_b = mavlink_msg_mount_status_get_pointing_b(msg); - mount_status->pointing_c = mavlink_msg_mount_status_get_pointing_c(msg); -#else - memcpy(mount_status, _MAV_PAYLOAD(msg), 14); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_radio.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_radio.h deleted file mode 100644 index 50b23b4e0f..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_radio.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE RADIO PACKING - -#define MAVLINK_MSG_ID_RADIO 166 - -typedef struct __mavlink_radio_t -{ - uint8_t rssi; ///< local signal strength - uint8_t remrssi; ///< remote signal strength - uint8_t txbuf; ///< how full the tx buffer is as a percentage - uint8_t noise; ///< background noise level - uint8_t remnoise; ///< remote background noise level - uint16_t rxerrors; ///< receive errors - uint16_t fixed; ///< count of error corrected packets -} mavlink_radio_t; - -#define MAVLINK_MSG_ID_RADIO_LEN 9 -#define MAVLINK_MSG_ID_166_LEN 9 - - - -#define MAVLINK_MESSAGE_INFO_RADIO { \ - "RADIO", \ - 7, \ - { { "rssi", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_radio_t, rssi) }, \ - { "remrssi", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_radio_t, remrssi) }, \ - { "txbuf", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_radio_t, txbuf) }, \ - { "noise", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_radio_t, noise) }, \ - { "remnoise", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_radio_t, remnoise) }, \ - { "rxerrors", NULL, MAVLINK_TYPE_UINT16_T, 0, 5, offsetof(mavlink_radio_t, rxerrors) }, \ - { "fixed", NULL, MAVLINK_TYPE_UINT16_T, 0, 7, offsetof(mavlink_radio_t, fixed) }, \ - } \ -} - - -/** - * @brief Pack a radio message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param rssi local signal strength - * @param remrssi remote signal strength - * @param txbuf how full the tx buffer is as a percentage - * @param noise background noise level - * @param remnoise remote background noise level - * @param rxerrors receive errors - * @param fixed count of error corrected packets - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_radio_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t rssi, uint8_t remrssi, uint8_t txbuf, uint8_t noise, uint8_t remnoise, uint16_t rxerrors, uint16_t fixed) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[9]; - _mav_put_uint8_t(buf, 0, rssi); - _mav_put_uint8_t(buf, 1, remrssi); - _mav_put_uint8_t(buf, 2, txbuf); - _mav_put_uint8_t(buf, 3, noise); - _mav_put_uint8_t(buf, 4, remnoise); - _mav_put_uint16_t(buf, 5, rxerrors); - _mav_put_uint16_t(buf, 7, fixed); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 9); -#else - mavlink_radio_t packet; - packet.rssi = rssi; - packet.remrssi = remrssi; - packet.txbuf = txbuf; - packet.noise = noise; - packet.remnoise = remnoise; - packet.rxerrors = rxerrors; - packet.fixed = fixed; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9); -#endif - - msg->msgid = MAVLINK_MSG_ID_RADIO; - return mavlink_finalize_message(msg, system_id, component_id, 9); -} - -/** - * @brief Pack a radio message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param rssi local signal strength - * @param remrssi remote signal strength - * @param txbuf how full the tx buffer is as a percentage - * @param noise background noise level - * @param remnoise remote background noise level - * @param rxerrors receive errors - * @param fixed count of error corrected packets - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_radio_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t rssi,uint8_t remrssi,uint8_t txbuf,uint8_t noise,uint8_t remnoise,uint16_t rxerrors,uint16_t fixed) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[9]; - _mav_put_uint8_t(buf, 0, rssi); - _mav_put_uint8_t(buf, 1, remrssi); - _mav_put_uint8_t(buf, 2, txbuf); - _mav_put_uint8_t(buf, 3, noise); - _mav_put_uint8_t(buf, 4, remnoise); - _mav_put_uint16_t(buf, 5, rxerrors); - _mav_put_uint16_t(buf, 7, fixed); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 9); -#else - mavlink_radio_t packet; - packet.rssi = rssi; - packet.remrssi = remrssi; - packet.txbuf = txbuf; - packet.noise = noise; - packet.remnoise = remnoise; - packet.rxerrors = rxerrors; - packet.fixed = fixed; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9); -#endif - - msg->msgid = MAVLINK_MSG_ID_RADIO; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 9); -} - -/** - * @brief Encode a radio struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param radio C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_radio_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_radio_t* radio) -{ - return mavlink_msg_radio_pack(system_id, component_id, msg, radio->rssi, radio->remrssi, radio->txbuf, radio->noise, radio->remnoise, radio->rxerrors, radio->fixed); -} - -/** - * @brief Send a radio message - * @param chan MAVLink channel to send the message - * - * @param rssi local signal strength - * @param remrssi remote signal strength - * @param txbuf how full the tx buffer is as a percentage - * @param noise background noise level - * @param remnoise remote background noise level - * @param rxerrors receive errors - * @param fixed count of error corrected packets - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_radio_send(mavlink_channel_t chan, uint8_t rssi, uint8_t remrssi, uint8_t txbuf, uint8_t noise, uint8_t remnoise, uint16_t rxerrors, uint16_t fixed) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[9]; - _mav_put_uint8_t(buf, 0, rssi); - _mav_put_uint8_t(buf, 1, remrssi); - _mav_put_uint8_t(buf, 2, txbuf); - _mav_put_uint8_t(buf, 3, noise); - _mav_put_uint8_t(buf, 4, remnoise); - _mav_put_uint16_t(buf, 5, rxerrors); - _mav_put_uint16_t(buf, 7, fixed); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RADIO, buf, 9); -#else - mavlink_radio_t packet; - packet.rssi = rssi; - packet.remrssi = remrssi; - packet.txbuf = txbuf; - packet.noise = noise; - packet.remnoise = remnoise; - packet.rxerrors = rxerrors; - packet.fixed = fixed; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RADIO, (const char *)&packet, 9); -#endif -} - -#endif - -// MESSAGE RADIO UNPACKING - - -/** - * @brief Get field rssi from radio message - * - * @return local signal strength - */ -static inline uint8_t mavlink_msg_radio_get_rssi(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field remrssi from radio message - * - * @return remote signal strength - */ -static inline uint8_t mavlink_msg_radio_get_remrssi(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field txbuf from radio message - * - * @return how full the tx buffer is as a percentage - */ -static inline uint8_t mavlink_msg_radio_get_txbuf(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field noise from radio message - * - * @return background noise level - */ -static inline uint8_t mavlink_msg_radio_get_noise(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field remnoise from radio message - * - * @return remote background noise level - */ -static inline uint8_t mavlink_msg_radio_get_remnoise(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field rxerrors from radio message - * - * @return receive errors - */ -static inline uint16_t mavlink_msg_radio_get_rxerrors(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 5); -} - -/** - * @brief Get field fixed from radio message - * - * @return count of error corrected packets - */ -static inline uint16_t mavlink_msg_radio_get_fixed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 7); -} - -/** - * @brief Decode a radio message into a struct - * - * @param msg The message to decode - * @param radio C-struct to decode the message contents into - */ -static inline void mavlink_msg_radio_decode(const mavlink_message_t* msg, mavlink_radio_t* radio) -{ -#if MAVLINK_NEED_BYTE_SWAP - radio->rssi = mavlink_msg_radio_get_rssi(msg); - radio->remrssi = mavlink_msg_radio_get_remrssi(msg); - radio->txbuf = mavlink_msg_radio_get_txbuf(msg); - radio->noise = mavlink_msg_radio_get_noise(msg); - radio->remnoise = mavlink_msg_radio_get_remnoise(msg); - radio->rxerrors = mavlink_msg_radio_get_rxerrors(msg); - radio->fixed = mavlink_msg_radio_get_fixed(msg); -#else - memcpy(radio, _MAV_PAYLOAD(msg), 9); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_sensor_offsets.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_sensor_offsets.h deleted file mode 100644 index 3016ea9bd9..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_sensor_offsets.h +++ /dev/null @@ -1,386 +0,0 @@ -// MESSAGE SENSOR_OFFSETS PACKING - -#define MAVLINK_MSG_ID_SENSOR_OFFSETS 150 - -typedef struct __mavlink_sensor_offsets_t -{ - int16_t mag_ofs_x; ///< magnetometer X offset - int16_t mag_ofs_y; ///< magnetometer Y offset - int16_t mag_ofs_z; ///< magnetometer Z offset - float mag_declination; ///< magnetic declination (radians) - int32_t raw_press; ///< raw pressure from barometer - int32_t raw_temp; ///< raw temperature from barometer - float gyro_cal_x; ///< gyro X calibration - float gyro_cal_y; ///< gyro Y calibration - float gyro_cal_z; ///< gyro Z calibration - float accel_cal_x; ///< accel X calibration - float accel_cal_y; ///< accel Y calibration - float accel_cal_z; ///< accel Z calibration -} mavlink_sensor_offsets_t; - -#define MAVLINK_MSG_ID_SENSOR_OFFSETS_LEN 42 -#define MAVLINK_MSG_ID_150_LEN 42 - - - -#define MAVLINK_MESSAGE_INFO_SENSOR_OFFSETS { \ - "SENSOR_OFFSETS", \ - 12, \ - { { "mag_ofs_x", NULL, MAVLINK_TYPE_INT16_T, 0, 0, offsetof(mavlink_sensor_offsets_t, mag_ofs_x) }, \ - { "mag_ofs_y", NULL, MAVLINK_TYPE_INT16_T, 0, 2, offsetof(mavlink_sensor_offsets_t, mag_ofs_y) }, \ - { "mag_ofs_z", NULL, MAVLINK_TYPE_INT16_T, 0, 4, offsetof(mavlink_sensor_offsets_t, mag_ofs_z) }, \ - { "mag_declination", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_sensor_offsets_t, mag_declination) }, \ - { "raw_press", NULL, MAVLINK_TYPE_INT32_T, 0, 10, offsetof(mavlink_sensor_offsets_t, raw_press) }, \ - { "raw_temp", NULL, MAVLINK_TYPE_INT32_T, 0, 14, offsetof(mavlink_sensor_offsets_t, raw_temp) }, \ - { "gyro_cal_x", NULL, MAVLINK_TYPE_FLOAT, 0, 18, offsetof(mavlink_sensor_offsets_t, gyro_cal_x) }, \ - { "gyro_cal_y", NULL, MAVLINK_TYPE_FLOAT, 0, 22, offsetof(mavlink_sensor_offsets_t, gyro_cal_y) }, \ - { "gyro_cal_z", NULL, MAVLINK_TYPE_FLOAT, 0, 26, offsetof(mavlink_sensor_offsets_t, gyro_cal_z) }, \ - { "accel_cal_x", NULL, MAVLINK_TYPE_FLOAT, 0, 30, offsetof(mavlink_sensor_offsets_t, accel_cal_x) }, \ - { "accel_cal_y", NULL, MAVLINK_TYPE_FLOAT, 0, 34, offsetof(mavlink_sensor_offsets_t, accel_cal_y) }, \ - { "accel_cal_z", NULL, MAVLINK_TYPE_FLOAT, 0, 38, offsetof(mavlink_sensor_offsets_t, accel_cal_z) }, \ - } \ -} - - -/** - * @brief Pack a sensor_offsets message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param mag_ofs_x magnetometer X offset - * @param mag_ofs_y magnetometer Y offset - * @param mag_ofs_z magnetometer Z offset - * @param mag_declination magnetic declination (radians) - * @param raw_press raw pressure from barometer - * @param raw_temp raw temperature from barometer - * @param gyro_cal_x gyro X calibration - * @param gyro_cal_y gyro Y calibration - * @param gyro_cal_z gyro Z calibration - * @param accel_cal_x accel X calibration - * @param accel_cal_y accel Y calibration - * @param accel_cal_z accel Z calibration - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sensor_offsets_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - int16_t mag_ofs_x, int16_t mag_ofs_y, int16_t mag_ofs_z, float mag_declination, int32_t raw_press, int32_t raw_temp, float gyro_cal_x, float gyro_cal_y, float gyro_cal_z, float accel_cal_x, float accel_cal_y, float accel_cal_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - _mav_put_int16_t(buf, 0, mag_ofs_x); - _mav_put_int16_t(buf, 2, mag_ofs_y); - _mav_put_int16_t(buf, 4, mag_ofs_z); - _mav_put_float(buf, 6, mag_declination); - _mav_put_int32_t(buf, 10, raw_press); - _mav_put_int32_t(buf, 14, raw_temp); - _mav_put_float(buf, 18, gyro_cal_x); - _mav_put_float(buf, 22, gyro_cal_y); - _mav_put_float(buf, 26, gyro_cal_z); - _mav_put_float(buf, 30, accel_cal_x); - _mav_put_float(buf, 34, accel_cal_y); - _mav_put_float(buf, 38, accel_cal_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 42); -#else - mavlink_sensor_offsets_t packet; - packet.mag_ofs_x = mag_ofs_x; - packet.mag_ofs_y = mag_ofs_y; - packet.mag_ofs_z = mag_ofs_z; - packet.mag_declination = mag_declination; - packet.raw_press = raw_press; - packet.raw_temp = raw_temp; - packet.gyro_cal_x = gyro_cal_x; - packet.gyro_cal_y = gyro_cal_y; - packet.gyro_cal_z = gyro_cal_z; - packet.accel_cal_x = accel_cal_x; - packet.accel_cal_y = accel_cal_y; - packet.accel_cal_z = accel_cal_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 42); -#endif - - msg->msgid = MAVLINK_MSG_ID_SENSOR_OFFSETS; - return mavlink_finalize_message(msg, system_id, component_id, 42); -} - -/** - * @brief Pack a sensor_offsets message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param mag_ofs_x magnetometer X offset - * @param mag_ofs_y magnetometer Y offset - * @param mag_ofs_z magnetometer Z offset - * @param mag_declination magnetic declination (radians) - * @param raw_press raw pressure from barometer - * @param raw_temp raw temperature from barometer - * @param gyro_cal_x gyro X calibration - * @param gyro_cal_y gyro Y calibration - * @param gyro_cal_z gyro Z calibration - * @param accel_cal_x accel X calibration - * @param accel_cal_y accel Y calibration - * @param accel_cal_z accel Z calibration - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sensor_offsets_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - int16_t mag_ofs_x,int16_t mag_ofs_y,int16_t mag_ofs_z,float mag_declination,int32_t raw_press,int32_t raw_temp,float gyro_cal_x,float gyro_cal_y,float gyro_cal_z,float accel_cal_x,float accel_cal_y,float accel_cal_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - _mav_put_int16_t(buf, 0, mag_ofs_x); - _mav_put_int16_t(buf, 2, mag_ofs_y); - _mav_put_int16_t(buf, 4, mag_ofs_z); - _mav_put_float(buf, 6, mag_declination); - _mav_put_int32_t(buf, 10, raw_press); - _mav_put_int32_t(buf, 14, raw_temp); - _mav_put_float(buf, 18, gyro_cal_x); - _mav_put_float(buf, 22, gyro_cal_y); - _mav_put_float(buf, 26, gyro_cal_z); - _mav_put_float(buf, 30, accel_cal_x); - _mav_put_float(buf, 34, accel_cal_y); - _mav_put_float(buf, 38, accel_cal_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 42); -#else - mavlink_sensor_offsets_t packet; - packet.mag_ofs_x = mag_ofs_x; - packet.mag_ofs_y = mag_ofs_y; - packet.mag_ofs_z = mag_ofs_z; - packet.mag_declination = mag_declination; - packet.raw_press = raw_press; - packet.raw_temp = raw_temp; - packet.gyro_cal_x = gyro_cal_x; - packet.gyro_cal_y = gyro_cal_y; - packet.gyro_cal_z = gyro_cal_z; - packet.accel_cal_x = accel_cal_x; - packet.accel_cal_y = accel_cal_y; - packet.accel_cal_z = accel_cal_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 42); -#endif - - msg->msgid = MAVLINK_MSG_ID_SENSOR_OFFSETS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 42); -} - -/** - * @brief Encode a sensor_offsets struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param sensor_offsets C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_sensor_offsets_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_sensor_offsets_t* sensor_offsets) -{ - return mavlink_msg_sensor_offsets_pack(system_id, component_id, msg, sensor_offsets->mag_ofs_x, sensor_offsets->mag_ofs_y, sensor_offsets->mag_ofs_z, sensor_offsets->mag_declination, sensor_offsets->raw_press, sensor_offsets->raw_temp, sensor_offsets->gyro_cal_x, sensor_offsets->gyro_cal_y, sensor_offsets->gyro_cal_z, sensor_offsets->accel_cal_x, sensor_offsets->accel_cal_y, sensor_offsets->accel_cal_z); -} - -/** - * @brief Send a sensor_offsets message - * @param chan MAVLink channel to send the message - * - * @param mag_ofs_x magnetometer X offset - * @param mag_ofs_y magnetometer Y offset - * @param mag_ofs_z magnetometer Z offset - * @param mag_declination magnetic declination (radians) - * @param raw_press raw pressure from barometer - * @param raw_temp raw temperature from barometer - * @param gyro_cal_x gyro X calibration - * @param gyro_cal_y gyro Y calibration - * @param gyro_cal_z gyro Z calibration - * @param accel_cal_x accel X calibration - * @param accel_cal_y accel Y calibration - * @param accel_cal_z accel Z calibration - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_sensor_offsets_send(mavlink_channel_t chan, int16_t mag_ofs_x, int16_t mag_ofs_y, int16_t mag_ofs_z, float mag_declination, int32_t raw_press, int32_t raw_temp, float gyro_cal_x, float gyro_cal_y, float gyro_cal_z, float accel_cal_x, float accel_cal_y, float accel_cal_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - _mav_put_int16_t(buf, 0, mag_ofs_x); - _mav_put_int16_t(buf, 2, mag_ofs_y); - _mav_put_int16_t(buf, 4, mag_ofs_z); - _mav_put_float(buf, 6, mag_declination); - _mav_put_int32_t(buf, 10, raw_press); - _mav_put_int32_t(buf, 14, raw_temp); - _mav_put_float(buf, 18, gyro_cal_x); - _mav_put_float(buf, 22, gyro_cal_y); - _mav_put_float(buf, 26, gyro_cal_z); - _mav_put_float(buf, 30, accel_cal_x); - _mav_put_float(buf, 34, accel_cal_y); - _mav_put_float(buf, 38, accel_cal_z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SENSOR_OFFSETS, buf, 42); -#else - mavlink_sensor_offsets_t packet; - packet.mag_ofs_x = mag_ofs_x; - packet.mag_ofs_y = mag_ofs_y; - packet.mag_ofs_z = mag_ofs_z; - packet.mag_declination = mag_declination; - packet.raw_press = raw_press; - packet.raw_temp = raw_temp; - packet.gyro_cal_x = gyro_cal_x; - packet.gyro_cal_y = gyro_cal_y; - packet.gyro_cal_z = gyro_cal_z; - packet.accel_cal_x = accel_cal_x; - packet.accel_cal_y = accel_cal_y; - packet.accel_cal_z = accel_cal_z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SENSOR_OFFSETS, (const char *)&packet, 42); -#endif -} - -#endif - -// MESSAGE SENSOR_OFFSETS UNPACKING - - -/** - * @brief Get field mag_ofs_x from sensor_offsets message - * - * @return magnetometer X offset - */ -static inline int16_t mavlink_msg_sensor_offsets_get_mag_ofs_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 0); -} - -/** - * @brief Get field mag_ofs_y from sensor_offsets message - * - * @return magnetometer Y offset - */ -static inline int16_t mavlink_msg_sensor_offsets_get_mag_ofs_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 2); -} - -/** - * @brief Get field mag_ofs_z from sensor_offsets message - * - * @return magnetometer Z offset - */ -static inline int16_t mavlink_msg_sensor_offsets_get_mag_ofs_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 4); -} - -/** - * @brief Get field mag_declination from sensor_offsets message - * - * @return magnetic declination (radians) - */ -static inline float mavlink_msg_sensor_offsets_get_mag_declination(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field raw_press from sensor_offsets message - * - * @return raw pressure from barometer - */ -static inline int32_t mavlink_msg_sensor_offsets_get_raw_press(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 10); -} - -/** - * @brief Get field raw_temp from sensor_offsets message - * - * @return raw temperature from barometer - */ -static inline int32_t mavlink_msg_sensor_offsets_get_raw_temp(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 14); -} - -/** - * @brief Get field gyro_cal_x from sensor_offsets message - * - * @return gyro X calibration - */ -static inline float mavlink_msg_sensor_offsets_get_gyro_cal_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 18); -} - -/** - * @brief Get field gyro_cal_y from sensor_offsets message - * - * @return gyro Y calibration - */ -static inline float mavlink_msg_sensor_offsets_get_gyro_cal_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 22); -} - -/** - * @brief Get field gyro_cal_z from sensor_offsets message - * - * @return gyro Z calibration - */ -static inline float mavlink_msg_sensor_offsets_get_gyro_cal_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 26); -} - -/** - * @brief Get field accel_cal_x from sensor_offsets message - * - * @return accel X calibration - */ -static inline float mavlink_msg_sensor_offsets_get_accel_cal_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 30); -} - -/** - * @brief Get field accel_cal_y from sensor_offsets message - * - * @return accel Y calibration - */ -static inline float mavlink_msg_sensor_offsets_get_accel_cal_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 34); -} - -/** - * @brief Get field accel_cal_z from sensor_offsets message - * - * @return accel Z calibration - */ -static inline float mavlink_msg_sensor_offsets_get_accel_cal_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 38); -} - -/** - * @brief Decode a sensor_offsets message into a struct - * - * @param msg The message to decode - * @param sensor_offsets C-struct to decode the message contents into - */ -static inline void mavlink_msg_sensor_offsets_decode(const mavlink_message_t* msg, mavlink_sensor_offsets_t* sensor_offsets) -{ -#if MAVLINK_NEED_BYTE_SWAP - sensor_offsets->mag_ofs_x = mavlink_msg_sensor_offsets_get_mag_ofs_x(msg); - sensor_offsets->mag_ofs_y = mavlink_msg_sensor_offsets_get_mag_ofs_y(msg); - sensor_offsets->mag_ofs_z = mavlink_msg_sensor_offsets_get_mag_ofs_z(msg); - sensor_offsets->mag_declination = mavlink_msg_sensor_offsets_get_mag_declination(msg); - sensor_offsets->raw_press = mavlink_msg_sensor_offsets_get_raw_press(msg); - sensor_offsets->raw_temp = mavlink_msg_sensor_offsets_get_raw_temp(msg); - sensor_offsets->gyro_cal_x = mavlink_msg_sensor_offsets_get_gyro_cal_x(msg); - sensor_offsets->gyro_cal_y = mavlink_msg_sensor_offsets_get_gyro_cal_y(msg); - sensor_offsets->gyro_cal_z = mavlink_msg_sensor_offsets_get_gyro_cal_z(msg); - sensor_offsets->accel_cal_x = mavlink_msg_sensor_offsets_get_accel_cal_x(msg); - sensor_offsets->accel_cal_y = mavlink_msg_sensor_offsets_get_accel_cal_y(msg); - sensor_offsets->accel_cal_z = mavlink_msg_sensor_offsets_get_accel_cal_z(msg); -#else - memcpy(sensor_offsets, _MAV_PAYLOAD(msg), 42); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_set_mag_offsets.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_set_mag_offsets.h deleted file mode 100644 index 99473e2f12..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_set_mag_offsets.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE SET_MAG_OFFSETS PACKING - -#define MAVLINK_MSG_ID_SET_MAG_OFFSETS 151 - -typedef struct __mavlink_set_mag_offsets_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - int16_t mag_ofs_x; ///< magnetometer X offset - int16_t mag_ofs_y; ///< magnetometer Y offset - int16_t mag_ofs_z; ///< magnetometer Z offset -} mavlink_set_mag_offsets_t; - -#define MAVLINK_MSG_ID_SET_MAG_OFFSETS_LEN 8 -#define MAVLINK_MSG_ID_151_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_SET_MAG_OFFSETS { \ - "SET_MAG_OFFSETS", \ - 5, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_mag_offsets_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_set_mag_offsets_t, target_component) }, \ - { "mag_ofs_x", NULL, MAVLINK_TYPE_INT16_T, 0, 2, offsetof(mavlink_set_mag_offsets_t, mag_ofs_x) }, \ - { "mag_ofs_y", NULL, MAVLINK_TYPE_INT16_T, 0, 4, offsetof(mavlink_set_mag_offsets_t, mag_ofs_y) }, \ - { "mag_ofs_z", NULL, MAVLINK_TYPE_INT16_T, 0, 6, offsetof(mavlink_set_mag_offsets_t, mag_ofs_z) }, \ - } \ -} - - -/** - * @brief Pack a set_mag_offsets message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param mag_ofs_x magnetometer X offset - * @param mag_ofs_y magnetometer Y offset - * @param mag_ofs_z magnetometer Z offset - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_mag_offsets_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, int16_t mag_ofs_x, int16_t mag_ofs_y, int16_t mag_ofs_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int16_t(buf, 2, mag_ofs_x); - _mav_put_int16_t(buf, 4, mag_ofs_y); - _mav_put_int16_t(buf, 6, mag_ofs_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_set_mag_offsets_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mag_ofs_x = mag_ofs_x; - packet.mag_ofs_y = mag_ofs_y; - packet.mag_ofs_z = mag_ofs_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_MAG_OFFSETS; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a set_mag_offsets message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param mag_ofs_x magnetometer X offset - * @param mag_ofs_y magnetometer Y offset - * @param mag_ofs_z magnetometer Z offset - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_mag_offsets_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,int16_t mag_ofs_x,int16_t mag_ofs_y,int16_t mag_ofs_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int16_t(buf, 2, mag_ofs_x); - _mav_put_int16_t(buf, 4, mag_ofs_y); - _mav_put_int16_t(buf, 6, mag_ofs_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_set_mag_offsets_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mag_ofs_x = mag_ofs_x; - packet.mag_ofs_y = mag_ofs_y; - packet.mag_ofs_z = mag_ofs_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_MAG_OFFSETS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a set_mag_offsets struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_mag_offsets C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_mag_offsets_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_mag_offsets_t* set_mag_offsets) -{ - return mavlink_msg_set_mag_offsets_pack(system_id, component_id, msg, set_mag_offsets->target_system, set_mag_offsets->target_component, set_mag_offsets->mag_ofs_x, set_mag_offsets->mag_ofs_y, set_mag_offsets->mag_ofs_z); -} - -/** - * @brief Send a set_mag_offsets message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param mag_ofs_x magnetometer X offset - * @param mag_ofs_y magnetometer Y offset - * @param mag_ofs_z magnetometer Z offset - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_mag_offsets_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, int16_t mag_ofs_x, int16_t mag_ofs_y, int16_t mag_ofs_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int16_t(buf, 2, mag_ofs_x); - _mav_put_int16_t(buf, 4, mag_ofs_y); - _mav_put_int16_t(buf, 6, mag_ofs_z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_MAG_OFFSETS, buf, 8); -#else - mavlink_set_mag_offsets_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.mag_ofs_x = mag_ofs_x; - packet.mag_ofs_y = mag_ofs_y; - packet.mag_ofs_z = mag_ofs_z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_MAG_OFFSETS, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE SET_MAG_OFFSETS UNPACKING - - -/** - * @brief Get field target_system from set_mag_offsets message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_set_mag_offsets_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from set_mag_offsets message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_set_mag_offsets_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field mag_ofs_x from set_mag_offsets message - * - * @return magnetometer X offset - */ -static inline int16_t mavlink_msg_set_mag_offsets_get_mag_ofs_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 2); -} - -/** - * @brief Get field mag_ofs_y from set_mag_offsets message - * - * @return magnetometer Y offset - */ -static inline int16_t mavlink_msg_set_mag_offsets_get_mag_ofs_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 4); -} - -/** - * @brief Get field mag_ofs_z from set_mag_offsets message - * - * @return magnetometer Z offset - */ -static inline int16_t mavlink_msg_set_mag_offsets_get_mag_ofs_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 6); -} - -/** - * @brief Decode a set_mag_offsets message into a struct - * - * @param msg The message to decode - * @param set_mag_offsets C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_mag_offsets_decode(const mavlink_message_t* msg, mavlink_set_mag_offsets_t* set_mag_offsets) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_mag_offsets->target_system = mavlink_msg_set_mag_offsets_get_target_system(msg); - set_mag_offsets->target_component = mavlink_msg_set_mag_offsets_get_target_component(msg); - set_mag_offsets->mag_ofs_x = mavlink_msg_set_mag_offsets_get_mag_ofs_x(msg); - set_mag_offsets->mag_ofs_y = mavlink_msg_set_mag_offsets_get_mag_ofs_y(msg); - set_mag_offsets->mag_ofs_z = mavlink_msg_set_mag_offsets_get_mag_ofs_z(msg); -#else - memcpy(set_mag_offsets, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_simstate.h b/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_simstate.h deleted file mode 100644 index 05f9ca3cc4..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/mavlink_msg_simstate.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE SIMSTATE PACKING - -#define MAVLINK_MSG_ID_SIMSTATE 164 - -typedef struct __mavlink_simstate_t -{ - float roll; ///< Roll angle (rad) - float pitch; ///< Pitch angle (rad) - float yaw; ///< Yaw angle (rad) - float xacc; ///< X acceleration m/s/s - float yacc; ///< Y acceleration m/s/s - float zacc; ///< Z acceleration m/s/s - float xgyro; ///< Angular speed around X axis rad/s - float ygyro; ///< Angular speed around Y axis rad/s - float zgyro; ///< Angular speed around Z axis rad/s -} mavlink_simstate_t; - -#define MAVLINK_MSG_ID_SIMSTATE_LEN 36 -#define MAVLINK_MSG_ID_164_LEN 36 - - - -#define MAVLINK_MESSAGE_INFO_SIMSTATE { \ - "SIMSTATE", \ - 9, \ - { { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_simstate_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_simstate_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_simstate_t, yaw) }, \ - { "xacc", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_simstate_t, xacc) }, \ - { "yacc", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_simstate_t, yacc) }, \ - { "zacc", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_simstate_t, zacc) }, \ - { "xgyro", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_simstate_t, xgyro) }, \ - { "ygyro", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_simstate_t, ygyro) }, \ - { "zgyro", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_simstate_t, zgyro) }, \ - } \ -} - - -/** - * @brief Pack a simstate message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param xacc X acceleration m/s/s - * @param yacc Y acceleration m/s/s - * @param zacc Z acceleration m/s/s - * @param xgyro Angular speed around X axis rad/s - * @param ygyro Angular speed around Y axis rad/s - * @param zgyro Angular speed around Z axis rad/s - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_simstate_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float roll, float pitch, float yaw, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_float(buf, 0, roll); - _mav_put_float(buf, 4, pitch); - _mav_put_float(buf, 8, yaw); - _mav_put_float(buf, 12, xacc); - _mav_put_float(buf, 16, yacc); - _mav_put_float(buf, 20, zacc); - _mav_put_float(buf, 24, xgyro); - _mav_put_float(buf, 28, ygyro); - _mav_put_float(buf, 32, zgyro); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_simstate_t packet; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_SIMSTATE; - return mavlink_finalize_message(msg, system_id, component_id, 36); -} - -/** - * @brief Pack a simstate message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param xacc X acceleration m/s/s - * @param yacc Y acceleration m/s/s - * @param zacc Z acceleration m/s/s - * @param xgyro Angular speed around X axis rad/s - * @param ygyro Angular speed around Y axis rad/s - * @param zgyro Angular speed around Z axis rad/s - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_simstate_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float roll,float pitch,float yaw,float xacc,float yacc,float zacc,float xgyro,float ygyro,float zgyro) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_float(buf, 0, roll); - _mav_put_float(buf, 4, pitch); - _mav_put_float(buf, 8, yaw); - _mav_put_float(buf, 12, xacc); - _mav_put_float(buf, 16, yacc); - _mav_put_float(buf, 20, zacc); - _mav_put_float(buf, 24, xgyro); - _mav_put_float(buf, 28, ygyro); - _mav_put_float(buf, 32, zgyro); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_simstate_t packet; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_SIMSTATE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 36); -} - -/** - * @brief Encode a simstate struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param simstate C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_simstate_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_simstate_t* simstate) -{ - return mavlink_msg_simstate_pack(system_id, component_id, msg, simstate->roll, simstate->pitch, simstate->yaw, simstate->xacc, simstate->yacc, simstate->zacc, simstate->xgyro, simstate->ygyro, simstate->zgyro); -} - -/** - * @brief Send a simstate message - * @param chan MAVLink channel to send the message - * - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param xacc X acceleration m/s/s - * @param yacc Y acceleration m/s/s - * @param zacc Z acceleration m/s/s - * @param xgyro Angular speed around X axis rad/s - * @param ygyro Angular speed around Y axis rad/s - * @param zgyro Angular speed around Z axis rad/s - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_simstate_send(mavlink_channel_t chan, float roll, float pitch, float yaw, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_float(buf, 0, roll); - _mav_put_float(buf, 4, pitch); - _mav_put_float(buf, 8, yaw); - _mav_put_float(buf, 12, xacc); - _mav_put_float(buf, 16, yacc); - _mav_put_float(buf, 20, zacc); - _mav_put_float(buf, 24, xgyro); - _mav_put_float(buf, 28, ygyro); - _mav_put_float(buf, 32, zgyro); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SIMSTATE, buf, 36); -#else - mavlink_simstate_t packet; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SIMSTATE, (const char *)&packet, 36); -#endif -} - -#endif - -// MESSAGE SIMSTATE UNPACKING - - -/** - * @brief Get field roll from simstate message - * - * @return Roll angle (rad) - */ -static inline float mavlink_msg_simstate_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field pitch from simstate message - * - * @return Pitch angle (rad) - */ -static inline float mavlink_msg_simstate_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field yaw from simstate message - * - * @return Yaw angle (rad) - */ -static inline float mavlink_msg_simstate_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field xacc from simstate message - * - * @return X acceleration m/s/s - */ -static inline float mavlink_msg_simstate_get_xacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yacc from simstate message - * - * @return Y acceleration m/s/s - */ -static inline float mavlink_msg_simstate_get_yacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field zacc from simstate message - * - * @return Z acceleration m/s/s - */ -static inline float mavlink_msg_simstate_get_zacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field xgyro from simstate message - * - * @return Angular speed around X axis rad/s - */ -static inline float mavlink_msg_simstate_get_xgyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field ygyro from simstate message - * - * @return Angular speed around Y axis rad/s - */ -static inline float mavlink_msg_simstate_get_ygyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Get field zgyro from simstate message - * - * @return Angular speed around Z axis rad/s - */ -static inline float mavlink_msg_simstate_get_zgyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 32); -} - -/** - * @brief Decode a simstate message into a struct - * - * @param msg The message to decode - * @param simstate C-struct to decode the message contents into - */ -static inline void mavlink_msg_simstate_decode(const mavlink_message_t* msg, mavlink_simstate_t* simstate) -{ -#if MAVLINK_NEED_BYTE_SWAP - simstate->roll = mavlink_msg_simstate_get_roll(msg); - simstate->pitch = mavlink_msg_simstate_get_pitch(msg); - simstate->yaw = mavlink_msg_simstate_get_yaw(msg); - simstate->xacc = mavlink_msg_simstate_get_xacc(msg); - simstate->yacc = mavlink_msg_simstate_get_yacc(msg); - simstate->zacc = mavlink_msg_simstate_get_zacc(msg); - simstate->xgyro = mavlink_msg_simstate_get_xgyro(msg); - simstate->ygyro = mavlink_msg_simstate_get_ygyro(msg); - simstate->zgyro = mavlink_msg_simstate_get_zgyro(msg); -#else - memcpy(simstate, _MAV_PAYLOAD(msg), 36); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ardupilotmega/testsuite.h b/mavlink/include/mavlink/v0.9/ardupilotmega/testsuite.h deleted file mode 100644 index a3ac5476ca..0000000000 --- a/mavlink/include/mavlink/v0.9/ardupilotmega/testsuite.h +++ /dev/null @@ -1,908 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from ardupilotmega.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef ARDUPILOTMEGA_TESTSUITE_H -#define ARDUPILOTMEGA_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); -static void mavlink_test_ardupilotmega(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_test_common(system_id, component_id, last_msg); - mavlink_test_ardupilotmega(system_id, component_id, last_msg); -} -#endif - -#include "../common/testsuite.h" - - -static void mavlink_test_sensor_offsets(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_sensor_offsets_t packet_in = { - 17235, - 17339, - 17443, - 59.0, - 963497984, - 963498192, - 143.0, - 171.0, - 199.0, - 227.0, - 255.0, - 283.0, - }; - mavlink_sensor_offsets_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.mag_ofs_x = packet_in.mag_ofs_x; - packet1.mag_ofs_y = packet_in.mag_ofs_y; - packet1.mag_ofs_z = packet_in.mag_ofs_z; - packet1.mag_declination = packet_in.mag_declination; - packet1.raw_press = packet_in.raw_press; - packet1.raw_temp = packet_in.raw_temp; - packet1.gyro_cal_x = packet_in.gyro_cal_x; - packet1.gyro_cal_y = packet_in.gyro_cal_y; - packet1.gyro_cal_z = packet_in.gyro_cal_z; - packet1.accel_cal_x = packet_in.accel_cal_x; - packet1.accel_cal_y = packet_in.accel_cal_y; - packet1.accel_cal_z = packet_in.accel_cal_z; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_sensor_offsets_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_sensor_offsets_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_sensor_offsets_pack(system_id, component_id, &msg , packet1.mag_ofs_x , packet1.mag_ofs_y , packet1.mag_ofs_z , packet1.mag_declination , packet1.raw_press , packet1.raw_temp , packet1.gyro_cal_x , packet1.gyro_cal_y , packet1.gyro_cal_z , packet1.accel_cal_x , packet1.accel_cal_y , packet1.accel_cal_z ); - mavlink_msg_sensor_offsets_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_sensor_offsets_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.mag_ofs_x , packet1.mag_ofs_y , packet1.mag_ofs_z , packet1.mag_declination , packet1.raw_press , packet1.raw_temp , packet1.gyro_cal_x , packet1.gyro_cal_y , packet1.gyro_cal_z , packet1.accel_cal_x , packet1.accel_cal_y , packet1.accel_cal_z ); - mavlink_msg_sensor_offsets_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; i>8) ^ (tmp<<8) ^ (tmp <<3) ^ (tmp>>4); -} - -/** - * @brief Initiliaze the buffer for the X.25 CRC - * - * @param crcAccum the 16 bit X.25 CRC - */ -static inline void crc_init(uint16_t* crcAccum) -{ - *crcAccum = X25_INIT_CRC; -} - - -/** - * @brief Calculates the X.25 checksum on a byte buffer - * - * @param pBuffer buffer containing the byte array to hash - * @param length length of the byte array - * @return the checksum over the buffer bytes - **/ -static inline uint16_t crc_calculate(uint8_t* pBuffer, uint16_t length) -{ - uint16_t crcTmp; - crc_init(&crcTmp); - while (length--) { - crc_accumulate(*pBuffer++, &crcTmp); - } - return crcTmp; -} - -/** - * @brief Accumulate the X.25 CRC by adding an array of bytes - * - * The checksum function adds the hash of one char at a time to the - * 16 bit checksum (uint16_t). - * - * @param data new bytes to hash - * @param crcAccum the already accumulated checksum - **/ -static inline void crc_accumulate_buffer(uint16_t *crcAccum, const char *pBuffer, uint8_t length) -{ - const uint8_t *p = (const uint8_t *)pBuffer; - while (length--) { - crc_accumulate(*p++, crcAccum); - } -} - - - - -#endif /* _CHECKSUM_H_ */ - -#ifdef __cplusplus -} -#endif diff --git a/mavlink/include/mavlink/v0.9/common/common.h b/mavlink/include/mavlink/v0.9/common/common.h deleted file mode 100644 index 84538ed570..0000000000 --- a/mavlink/include/mavlink/v0.9/common/common.h +++ /dev/null @@ -1,208 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from common.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef COMMON_H -#define COMMON_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {3, 4, 8, 14, 8, 28, 3, 32, 0, 2, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 19, 2, 23, 21, 0, 37, 26, 101, 26, 16, 32, 32, 37, 32, 11, 17, 17, 16, 18, 36, 4, 4, 2, 2, 4, 2, 2, 3, 14, 12, 18, 16, 8, 27, 25, 18, 18, 24, 24, 0, 0, 0, 26, 16, 36, 5, 6, 56, 26, 21, 18, 0, 0, 18, 20, 20, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 14, 14, 51, 5} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {72, 39, 190, 92, 191, 217, 104, 119, 0, 219, 60, 186, 10, 0, 0, 0, 0, 0, 0, 0, 89, 159, 162, 121, 0, 149, 222, 110, 179, 136, 66, 126, 185, 147, 112, 252, 162, 215, 229, 128, 9, 106, 101, 213, 4, 229, 21, 214, 215, 14, 206, 50, 157, 126, 108, 213, 95, 5, 127, 0, 0, 0, 57, 126, 130, 119, 193, 191, 236, 158, 143, 0, 0, 104, 123, 131, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 224, 60, 106, 7} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_BOOT, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_SYSTEM_TIME_UTC, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_ACTION_ACK, MAVLINK_MESSAGE_INFO_ACTION, MAVLINK_MESSAGE_INFO_SET_MODE, MAVLINK_MESSAGE_INFO_SET_NAV_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_LOCAL_POSITION, MAVLINK_MESSAGE_INFO_GPS_RAW, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_WAYPOINT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST, MAVLINK_MESSAGE_INFO_WAYPOINT_SET_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST_LIST, MAVLINK_MESSAGE_INFO_WAYPOINT_COUNT, MAVLINK_MESSAGE_INFO_WAYPOINT_CLEAR_ALL, MAVLINK_MESSAGE_INFO_WAYPOINT_REACHED, MAVLINK_MESSAGE_INFO_WAYPOINT_ACK, MAVLINK_MESSAGE_INFO_GPS_SET_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_LOCAL_ORIGIN_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_CONTROL_STATUS, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, MAVLINK_MESSAGE_INFO_POSITION_TARGET, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, MAVLINK_MESSAGE_INFO_SET_ALTITUDE, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_VFR_HUD, MAVLINK_MESSAGE_INFO_COMMAND, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBJECT_DETECTION_EVENT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_COMMON - - - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - -/** @brief Commands to be executed by the MAV. They can be executed on user request, - or as part of a mission script. If the action is used in a mission, the parameter mapping - to the waypoint/mission message is as follows: - Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what - ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. */ -#ifndef HAVE_ENUM_MAV_CMD -#define HAVE_ENUM_MAV_CMD -enum MAV_CMD -{ - MAV_CMD_NAV_WAYPOINT=16, /* Navigate to waypoint. |Hold time in decimal seconds. (ignored by fixed wing, time to stay at waypoint for rotary wing)| Acceptance radius in meters (if the sphere with this radius is hit, the waypoint counts as reached)| 0 to pass through the WP, if > 0 radius in meters to pass by WP. Positive value for clockwise orbit, negative value for counter-clockwise orbit. Allows trajectory control.| Desired yaw angle at waypoint (rotary wing)| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_LOITER_UNLIM=17, /* Loiter around this waypoint an unlimited amount of time |Empty| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_LOITER_TURNS=18, /* Loiter around this waypoint for X turns |Turns| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_LOITER_TIME=19, /* Loiter around this waypoint for X seconds |Seconds (decimal)| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_RETURN_TO_LAUNCH=20, /* Return to launch location |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_NAV_LAND=21, /* Land at location |Empty| Empty| Empty| Desired yaw angle.| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_TAKEOFF=22, /* Takeoff from ground / hand |Minimum pitch (if airspeed sensor present), desired pitch without sensor| Empty| Empty| Yaw angle (if magnetometer present), ignored without magnetometer| Latitude| Longitude| Altitude| */ - MAV_CMD_NAV_ROI=80, /* Sets the region of interest (ROI) for a sensor set or the - vehicle itself. This can then be used by the vehicles control - system to control the vehicle attitude and the attitude of various - sensors such as cameras. |Region of intereset mode. (see MAV_ROI enum)| Waypoint index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple ROI's)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| */ - MAV_CMD_NAV_PATHPLANNING=81, /* Control autonomous path planning on the MAV. |0: Disable local obstacle avoidance / local path planning (without resetting map), 1: Enable local path planning, 2: Enable and reset local path planning| 0: Disable full path planning (without resetting map), 1: Enable, 2: Enable and reset map/occupancy grid, 3: Enable and reset planned route, but not occupancy grid| Empty| Yaw angle at goal, in compass degrees, [0..360]| Latitude/X of goal| Longitude/Y of goal| Altitude/Z of goal| */ - MAV_CMD_NAV_LAST=95, /* NOP - This command is only used to mark the upper limit of the NAV/ACTION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_DELAY=112, /* Delay mission state machine. |Delay in seconds (decimal)| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_CHANGE_ALT=113, /* Ascend/descend at rate. Delay mission state machine until desired altitude reached. |Descent / Ascend rate (m/s)| Empty| Empty| Empty| Empty| Empty| Finish Altitude| */ - MAV_CMD_CONDITION_DISTANCE=114, /* Delay mission state machine until within desired distance of next NAV point. |Distance (meters)| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_YAW=115, /* Reach a certain target angle. |target angle: [0-360], 0 is north| speed during yaw change:[deg per second]| direction: negative: counter clockwise, positive: clockwise [-1,1]| relative offset or absolute angle: [ 1,0]| Empty| Empty| Empty| */ - MAV_CMD_CONDITION_LAST=159, /* NOP - This command is only used to mark the upper limit of the CONDITION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_MODE=176, /* Set system mode. |Mode, as defined by ENUM MAV_MODE| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_JUMP=177, /* Jump to the desired command in the mission list. Repeat this action only the specified number of times |Sequence number| Repeat count| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_CHANGE_SPEED=178, /* Change speed and/or throttle set points. |Speed type (0=Airspeed, 1=Ground Speed)| Speed (m/s, -1 indicates no change)| Throttle ( Percent, -1 indicates no change)| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_HOME=179, /* Changes the home location either to the current location or a specified location. |Use current (1=use current location, 0=use specified location)| Empty| Empty| Empty| Latitude| Longitude| Altitude| */ - MAV_CMD_DO_SET_PARAMETER=180, /* Set a system parameter. Caution! Use of this command requires knowledge of the numeric enumeration value of the parameter. |Parameter number| Parameter value| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_RELAY=181, /* Set a relay to a condition. |Relay number| Setting (1=on, 0=off, others possible depending on system hardware)| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_REPEAT_RELAY=182, /* Cycle a relay on and off for a desired number of cyles with a desired period. |Relay number| Cycle count| Cycle time (seconds, decimal)| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_SERVO=183, /* Set a servo to a desired PWM value. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_DO_REPEAT_SERVO=184, /* Cycle a between its nominal setting and a desired PWM for a desired number of cycles with a desired period. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Cycle count| Cycle time (seconds)| Empty| Empty| Empty| */ - MAV_CMD_DO_CONTROL_VIDEO=200, /* Control onboard camera capturing. |Camera ID (-1 for all)| Transmission: 0: disabled, 1: enabled compressed, 2: enabled raw| Transmission mode: 0: video stream, >0: single images every n seconds (decimal)| Recording: 0: disabled, 1: enabled compressed, 2: enabled raw| Empty| Empty| Empty| */ - MAV_CMD_DO_SET_ROI=201, /* Sets the region of interest (ROI) for a sensor set or the - vehicle itself. This can then be used by the vehicles control - system to control the vehicle attitude and the attitude of various - devices such as cameras. - |Region of interest mode. (see MAV_ROI enum)| Waypoint index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple cameras etc.)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| */ - MAV_CMD_DO_LAST=240, /* NOP - This command is only used to mark the upper limit of the DO commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_PREFLIGHT_CALIBRATION=241, /* Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Empty| Empty| Empty| */ - MAV_CMD_PREFLIGHT_STORAGE=245, /* Request storage of different parameter values and logs. This command will be only accepted if in pre-flight mode. |Parameter storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Mission storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Reserved| Reserved| Empty| Empty| Empty| */ - MAV_CMD_ENUM_END=246, /* | */ -}; -#endif - -/** @brief Data stream IDs. A data stream is not a fixed set of messages, but rather a - recommendation to the autopilot software. Individual autopilots may or may not obey - the recommended messages. - */ -#ifndef HAVE_ENUM_MAV_DATA_STREAM -#define HAVE_ENUM_MAV_DATA_STREAM -enum MAV_DATA_STREAM -{ - MAV_DATA_STREAM_ALL=0, /* Enable all data streams | */ - MAV_DATA_STREAM_RAW_SENSORS=1, /* Enable IMU_RAW, GPS_RAW, GPS_STATUS packets. | */ - MAV_DATA_STREAM_EXTENDED_STATUS=2, /* Enable GPS_STATUS, CONTROL_STATUS, AUX_STATUS | */ - MAV_DATA_STREAM_RC_CHANNELS=3, /* Enable RC_CHANNELS_SCALED, RC_CHANNELS_RAW, SERVO_OUTPUT_RAW | */ - MAV_DATA_STREAM_RAW_CONTROLLER=4, /* Enable ATTITUDE_CONTROLLER_OUTPUT, POSITION_CONTROLLER_OUTPUT, NAV_CONTROLLER_OUTPUT. | */ - MAV_DATA_STREAM_POSITION=6, /* Enable LOCAL_POSITION, GLOBAL_POSITION/GLOBAL_POSITION_INT messages. | */ - MAV_DATA_STREAM_EXTRA1=10, /* Dependent on the autopilot | */ - MAV_DATA_STREAM_EXTRA2=11, /* Dependent on the autopilot | */ - MAV_DATA_STREAM_EXTRA3=12, /* Dependent on the autopilot | */ - MAV_DATA_STREAM_ENUM_END=13, /* | */ -}; -#endif - -/** @brief The ROI (region of interest) for the vehicle. This can be - be used by the vehicle for camera/vehicle attitude alignment (see - MAV_CMD_NAV_ROI). - */ -#ifndef HAVE_ENUM_MAV_ROI -#define HAVE_ENUM_MAV_ROI -enum MAV_ROI -{ - MAV_ROI_NONE=0, /* No region of interest. | */ - MAV_ROI_WPNEXT=1, /* Point toward next waypoint. | */ - MAV_ROI_WPINDEX=2, /* Point toward given waypoint. | */ - MAV_ROI_LOCATION=3, /* Point toward fixed location. | */ - MAV_ROI_TARGET=4, /* Point toward of given id. | */ - MAV_ROI_ENUM_END=5, /* | */ -}; -#endif - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_heartbeat.h" -#include "./mavlink_msg_boot.h" -#include "./mavlink_msg_system_time.h" -#include "./mavlink_msg_ping.h" -#include "./mavlink_msg_system_time_utc.h" -#include "./mavlink_msg_change_operator_control.h" -#include "./mavlink_msg_change_operator_control_ack.h" -#include "./mavlink_msg_auth_key.h" -#include "./mavlink_msg_action_ack.h" -#include "./mavlink_msg_action.h" -#include "./mavlink_msg_set_mode.h" -#include "./mavlink_msg_set_nav_mode.h" -#include "./mavlink_msg_param_request_read.h" -#include "./mavlink_msg_param_request_list.h" -#include "./mavlink_msg_param_value.h" -#include "./mavlink_msg_param_set.h" -#include "./mavlink_msg_gps_raw_int.h" -#include "./mavlink_msg_scaled_imu.h" -#include "./mavlink_msg_gps_status.h" -#include "./mavlink_msg_raw_imu.h" -#include "./mavlink_msg_raw_pressure.h" -#include "./mavlink_msg_scaled_pressure.h" -#include "./mavlink_msg_attitude.h" -#include "./mavlink_msg_local_position.h" -#include "./mavlink_msg_global_position.h" -#include "./mavlink_msg_gps_raw.h" -#include "./mavlink_msg_sys_status.h" -#include "./mavlink_msg_rc_channels_raw.h" -#include "./mavlink_msg_rc_channels_scaled.h" -#include "./mavlink_msg_servo_output_raw.h" -#include "./mavlink_msg_waypoint.h" -#include "./mavlink_msg_waypoint_request.h" -#include "./mavlink_msg_waypoint_set_current.h" -#include "./mavlink_msg_waypoint_current.h" -#include "./mavlink_msg_waypoint_request_list.h" -#include "./mavlink_msg_waypoint_count.h" -#include "./mavlink_msg_waypoint_clear_all.h" -#include "./mavlink_msg_waypoint_reached.h" -#include "./mavlink_msg_waypoint_ack.h" -#include "./mavlink_msg_gps_set_global_origin.h" -#include "./mavlink_msg_gps_local_origin_set.h" -#include "./mavlink_msg_local_position_setpoint_set.h" -#include "./mavlink_msg_local_position_setpoint.h" -#include "./mavlink_msg_control_status.h" -#include "./mavlink_msg_safety_set_allowed_area.h" -#include "./mavlink_msg_safety_allowed_area.h" -#include "./mavlink_msg_set_roll_pitch_yaw_thrust.h" -#include "./mavlink_msg_set_roll_pitch_yaw_speed_thrust.h" -#include "./mavlink_msg_roll_pitch_yaw_thrust_setpoint.h" -#include "./mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint.h" -#include "./mavlink_msg_nav_controller_output.h" -#include "./mavlink_msg_position_target.h" -#include "./mavlink_msg_state_correction.h" -#include "./mavlink_msg_set_altitude.h" -#include "./mavlink_msg_request_data_stream.h" -#include "./mavlink_msg_hil_state.h" -#include "./mavlink_msg_hil_controls.h" -#include "./mavlink_msg_manual_control.h" -#include "./mavlink_msg_rc_channels_override.h" -#include "./mavlink_msg_global_position_int.h" -#include "./mavlink_msg_vfr_hud.h" -#include "./mavlink_msg_command.h" -#include "./mavlink_msg_command_ack.h" -#include "./mavlink_msg_optical_flow.h" -#include "./mavlink_msg_object_detection_event.h" -#include "./mavlink_msg_debug_vect.h" -#include "./mavlink_msg_named_value_float.h" -#include "./mavlink_msg_named_value_int.h" -#include "./mavlink_msg_statustext.h" -#include "./mavlink_msg_debug.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // COMMON_H diff --git a/mavlink/include/mavlink/v0.9/common/mavlink.h b/mavlink/include/mavlink/v0.9/common/mavlink.h deleted file mode 100644 index 02ff5bd392..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - * @brief MAVLink comm protocol built from common.xml - * @see http://pixhawk.ethz.ch/software/mavlink - */ -#ifndef MAVLINK_H -#define MAVLINK_H - -#ifndef MAVLINK_STX -#define MAVLINK_STX 85 -#endif - -#ifndef MAVLINK_ENDIAN -#define MAVLINK_ENDIAN MAVLINK_BIG_ENDIAN -#endif - -#ifndef MAVLINK_ALIGNED_FIELDS -#define MAVLINK_ALIGNED_FIELDS 0 -#endif - -#ifndef MAVLINK_CRC_EXTRA -#define MAVLINK_CRC_EXTRA 0 -#endif - -#include "version.h" -#include "common.h" - -#endif // MAVLINK_H diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_action.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_action.h deleted file mode 100644 index ada9aa7a29..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_action.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE ACTION PACKING - -#define MAVLINK_MSG_ID_ACTION 10 - -typedef struct __mavlink_action_t -{ - uint8_t target; ///< The system executing the action - uint8_t target_component; ///< The component executing the action - uint8_t action; ///< The action id -} mavlink_action_t; - -#define MAVLINK_MSG_ID_ACTION_LEN 3 -#define MAVLINK_MSG_ID_10_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_ACTION { \ - "ACTION", \ - 3, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_action_t, target) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_action_t, target_component) }, \ - { "action", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_action_t, action) }, \ - } \ -} - - -/** - * @brief Pack a action message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system executing the action - * @param target_component The component executing the action - * @param action The action id - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_action_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint8_t target_component, uint8_t action) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, action); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_action_t packet; - packet.target = target; - packet.target_component = target_component; - packet.action = action; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_ACTION; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a action message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system executing the action - * @param target_component The component executing the action - * @param action The action id - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_action_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint8_t target_component,uint8_t action) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, action); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_action_t packet; - packet.target = target; - packet.target_component = target_component; - packet.action = action; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_ACTION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a action struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param action C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_action_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_action_t* action) -{ - return mavlink_msg_action_pack(system_id, component_id, msg, action->target, action->target_component, action->action); -} - -/** - * @brief Send a action message - * @param chan MAVLink channel to send the message - * - * @param target The system executing the action - * @param target_component The component executing the action - * @param action The action id - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_action_send(mavlink_channel_t chan, uint8_t target, uint8_t target_component, uint8_t action) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, action); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ACTION, buf, 3); -#else - mavlink_action_t packet; - packet.target = target; - packet.target_component = target_component; - packet.action = action; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ACTION, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE ACTION UNPACKING - - -/** - * @brief Get field target from action message - * - * @return The system executing the action - */ -static inline uint8_t mavlink_msg_action_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from action message - * - * @return The component executing the action - */ -static inline uint8_t mavlink_msg_action_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field action from action message - * - * @return The action id - */ -static inline uint8_t mavlink_msg_action_get_action(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a action message into a struct - * - * @param msg The message to decode - * @param action C-struct to decode the message contents into - */ -static inline void mavlink_msg_action_decode(const mavlink_message_t* msg, mavlink_action_t* action) -{ -#if MAVLINK_NEED_BYTE_SWAP - action->target = mavlink_msg_action_get_target(msg); - action->target_component = mavlink_msg_action_get_target_component(msg); - action->action = mavlink_msg_action_get_action(msg); -#else - memcpy(action, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_action_ack.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_action_ack.h deleted file mode 100644 index a87b35b599..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_action_ack.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE ACTION_ACK PACKING - -#define MAVLINK_MSG_ID_ACTION_ACK 9 - -typedef struct __mavlink_action_ack_t -{ - uint8_t action; ///< The action id - uint8_t result; ///< 0: Action DENIED, 1: Action executed -} mavlink_action_ack_t; - -#define MAVLINK_MSG_ID_ACTION_ACK_LEN 2 -#define MAVLINK_MSG_ID_9_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_ACTION_ACK { \ - "ACTION_ACK", \ - 2, \ - { { "action", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_action_ack_t, action) }, \ - { "result", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_action_ack_t, result) }, \ - } \ -} - - -/** - * @brief Pack a action_ack message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param action The action id - * @param result 0: Action DENIED, 1: Action executed - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_action_ack_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t action, uint8_t result) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, action); - _mav_put_uint8_t(buf, 1, result); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_action_ack_t packet; - packet.action = action; - packet.result = result; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_ACTION_ACK; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a action_ack message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param action The action id - * @param result 0: Action DENIED, 1: Action executed - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_action_ack_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t action,uint8_t result) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, action); - _mav_put_uint8_t(buf, 1, result); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_action_ack_t packet; - packet.action = action; - packet.result = result; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_ACTION_ACK; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a action_ack struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param action_ack C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_action_ack_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_action_ack_t* action_ack) -{ - return mavlink_msg_action_ack_pack(system_id, component_id, msg, action_ack->action, action_ack->result); -} - -/** - * @brief Send a action_ack message - * @param chan MAVLink channel to send the message - * - * @param action The action id - * @param result 0: Action DENIED, 1: Action executed - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_action_ack_send(mavlink_channel_t chan, uint8_t action, uint8_t result) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, action); - _mav_put_uint8_t(buf, 1, result); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ACTION_ACK, buf, 2); -#else - mavlink_action_ack_t packet; - packet.action = action; - packet.result = result; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ACTION_ACK, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE ACTION_ACK UNPACKING - - -/** - * @brief Get field action from action_ack message - * - * @return The action id - */ -static inline uint8_t mavlink_msg_action_ack_get_action(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field result from action_ack message - * - * @return 0: Action DENIED, 1: Action executed - */ -static inline uint8_t mavlink_msg_action_ack_get_result(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Decode a action_ack message into a struct - * - * @param msg The message to decode - * @param action_ack C-struct to decode the message contents into - */ -static inline void mavlink_msg_action_ack_decode(const mavlink_message_t* msg, mavlink_action_ack_t* action_ack) -{ -#if MAVLINK_NEED_BYTE_SWAP - action_ack->action = mavlink_msg_action_ack_get_action(msg); - action_ack->result = mavlink_msg_action_ack_get_result(msg); -#else - memcpy(action_ack, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_attitude.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_attitude.h deleted file mode 100644 index 188f1eb0ff..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_attitude.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE ATTITUDE PACKING - -#define MAVLINK_MSG_ID_ATTITUDE 30 - -typedef struct __mavlink_attitude_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - float roll; ///< Roll angle (rad) - float pitch; ///< Pitch angle (rad) - float yaw; ///< Yaw angle (rad) - float rollspeed; ///< Roll angular speed (rad/s) - float pitchspeed; ///< Pitch angular speed (rad/s) - float yawspeed; ///< Yaw angular speed (rad/s) -} mavlink_attitude_t; - -#define MAVLINK_MSG_ID_ATTITUDE_LEN 32 -#define MAVLINK_MSG_ID_30_LEN 32 - - - -#define MAVLINK_MESSAGE_INFO_ATTITUDE { \ - "ATTITUDE", \ - 7, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_attitude_t, usec) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_attitude_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_attitude_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_attitude_t, yaw) }, \ - { "rollspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_attitude_t, rollspeed) }, \ - { "pitchspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_attitude_t, pitchspeed) }, \ - { "yawspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_attitude_t, yawspeed) }, \ - } \ -} - - -/** - * @brief Pack a attitude message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param rollspeed Roll angular speed (rad/s) - * @param pitchspeed Pitch angular speed (rad/s) - * @param yawspeed Yaw angular speed (rad/s) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_attitude_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float roll, float pitch, float yaw, float rollspeed, float pitchspeed, float yawspeed) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, rollspeed); - _mav_put_float(buf, 24, pitchspeed); - _mav_put_float(buf, 28, yawspeed); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_attitude_t packet; - packet.usec = usec; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.rollspeed = rollspeed; - packet.pitchspeed = pitchspeed; - packet.yawspeed = yawspeed; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_ATTITUDE; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a attitude message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param rollspeed Roll angular speed (rad/s) - * @param pitchspeed Pitch angular speed (rad/s) - * @param yawspeed Yaw angular speed (rad/s) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_attitude_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float roll,float pitch,float yaw,float rollspeed,float pitchspeed,float yawspeed) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, rollspeed); - _mav_put_float(buf, 24, pitchspeed); - _mav_put_float(buf, 28, yawspeed); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_attitude_t packet; - packet.usec = usec; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.rollspeed = rollspeed; - packet.pitchspeed = pitchspeed; - packet.yawspeed = yawspeed; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_ATTITUDE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a attitude struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param attitude C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_attitude_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_attitude_t* attitude) -{ - return mavlink_msg_attitude_pack(system_id, component_id, msg, attitude->usec, attitude->roll, attitude->pitch, attitude->yaw, attitude->rollspeed, attitude->pitchspeed, attitude->yawspeed); -} - -/** - * @brief Send a attitude message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param rollspeed Roll angular speed (rad/s) - * @param pitchspeed Pitch angular speed (rad/s) - * @param yawspeed Yaw angular speed (rad/s) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_attitude_send(mavlink_channel_t chan, uint64_t usec, float roll, float pitch, float yaw, float rollspeed, float pitchspeed, float yawspeed) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, rollspeed); - _mav_put_float(buf, 24, pitchspeed); - _mav_put_float(buf, 28, yawspeed); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE, buf, 32); -#else - mavlink_attitude_t packet; - packet.usec = usec; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.rollspeed = rollspeed; - packet.pitchspeed = pitchspeed; - packet.yawspeed = yawspeed; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE ATTITUDE UNPACKING - - -/** - * @brief Get field usec from attitude message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_attitude_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field roll from attitude message - * - * @return Roll angle (rad) - */ -static inline float mavlink_msg_attitude_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field pitch from attitude message - * - * @return Pitch angle (rad) - */ -static inline float mavlink_msg_attitude_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yaw from attitude message - * - * @return Yaw angle (rad) - */ -static inline float mavlink_msg_attitude_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field rollspeed from attitude message - * - * @return Roll angular speed (rad/s) - */ -static inline float mavlink_msg_attitude_get_rollspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field pitchspeed from attitude message - * - * @return Pitch angular speed (rad/s) - */ -static inline float mavlink_msg_attitude_get_pitchspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field yawspeed from attitude message - * - * @return Yaw angular speed (rad/s) - */ -static inline float mavlink_msg_attitude_get_yawspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a attitude message into a struct - * - * @param msg The message to decode - * @param attitude C-struct to decode the message contents into - */ -static inline void mavlink_msg_attitude_decode(const mavlink_message_t* msg, mavlink_attitude_t* attitude) -{ -#if MAVLINK_NEED_BYTE_SWAP - attitude->usec = mavlink_msg_attitude_get_usec(msg); - attitude->roll = mavlink_msg_attitude_get_roll(msg); - attitude->pitch = mavlink_msg_attitude_get_pitch(msg); - attitude->yaw = mavlink_msg_attitude_get_yaw(msg); - attitude->rollspeed = mavlink_msg_attitude_get_rollspeed(msg); - attitude->pitchspeed = mavlink_msg_attitude_get_pitchspeed(msg); - attitude->yawspeed = mavlink_msg_attitude_get_yawspeed(msg); -#else - memcpy(attitude, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_auth_key.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_auth_key.h deleted file mode 100644 index c451444eac..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_auth_key.h +++ /dev/null @@ -1,144 +0,0 @@ -// MESSAGE AUTH_KEY PACKING - -#define MAVLINK_MSG_ID_AUTH_KEY 7 - -typedef struct __mavlink_auth_key_t -{ - char key[32]; ///< key -} mavlink_auth_key_t; - -#define MAVLINK_MSG_ID_AUTH_KEY_LEN 32 -#define MAVLINK_MSG_ID_7_LEN 32 - -#define MAVLINK_MSG_AUTH_KEY_FIELD_KEY_LEN 32 - -#define MAVLINK_MESSAGE_INFO_AUTH_KEY { \ - "AUTH_KEY", \ - 1, \ - { { "key", NULL, MAVLINK_TYPE_CHAR, 32, 0, offsetof(mavlink_auth_key_t, key) }, \ - } \ -} - - -/** - * @brief Pack a auth_key message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param key key - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_auth_key_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const char *key) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - - _mav_put_char_array(buf, 0, key, 32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_auth_key_t packet; - - mav_array_memcpy(packet.key, key, sizeof(char)*32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_AUTH_KEY; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a auth_key message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param key key - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_auth_key_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const char *key) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - - _mav_put_char_array(buf, 0, key, 32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_auth_key_t packet; - - mav_array_memcpy(packet.key, key, sizeof(char)*32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_AUTH_KEY; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a auth_key struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param auth_key C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_auth_key_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_auth_key_t* auth_key) -{ - return mavlink_msg_auth_key_pack(system_id, component_id, msg, auth_key->key); -} - -/** - * @brief Send a auth_key message - * @param chan MAVLink channel to send the message - * - * @param key key - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_auth_key_send(mavlink_channel_t chan, const char *key) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - - _mav_put_char_array(buf, 0, key, 32); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AUTH_KEY, buf, 32); -#else - mavlink_auth_key_t packet; - - mav_array_memcpy(packet.key, key, sizeof(char)*32); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AUTH_KEY, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE AUTH_KEY UNPACKING - - -/** - * @brief Get field key from auth_key message - * - * @return key - */ -static inline uint16_t mavlink_msg_auth_key_get_key(const mavlink_message_t* msg, char *key) -{ - return _MAV_RETURN_char_array(msg, key, 32, 0); -} - -/** - * @brief Decode a auth_key message into a struct - * - * @param msg The message to decode - * @param auth_key C-struct to decode the message contents into - */ -static inline void mavlink_msg_auth_key_decode(const mavlink_message_t* msg, mavlink_auth_key_t* auth_key) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_auth_key_get_key(msg, auth_key->key); -#else - memcpy(auth_key, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_boot.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_boot.h deleted file mode 100644 index 570949bd56..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_boot.h +++ /dev/null @@ -1,144 +0,0 @@ -// MESSAGE BOOT PACKING - -#define MAVLINK_MSG_ID_BOOT 1 - -typedef struct __mavlink_boot_t -{ - uint32_t version; ///< The onboard software version -} mavlink_boot_t; - -#define MAVLINK_MSG_ID_BOOT_LEN 4 -#define MAVLINK_MSG_ID_1_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_BOOT { \ - "BOOT", \ - 1, \ - { { "version", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_boot_t, version) }, \ - } \ -} - - -/** - * @brief Pack a boot message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param version The onboard software version - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_boot_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint32_t version) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint32_t(buf, 0, version); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_boot_t packet; - packet.version = version; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_BOOT; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a boot message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param version The onboard software version - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_boot_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint32_t version) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint32_t(buf, 0, version); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_boot_t packet; - packet.version = version; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_BOOT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a boot struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param boot C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_boot_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_boot_t* boot) -{ - return mavlink_msg_boot_pack(system_id, component_id, msg, boot->version); -} - -/** - * @brief Send a boot message - * @param chan MAVLink channel to send the message - * - * @param version The onboard software version - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_boot_send(mavlink_channel_t chan, uint32_t version) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint32_t(buf, 0, version); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BOOT, buf, 4); -#else - mavlink_boot_t packet; - packet.version = version; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BOOT, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE BOOT UNPACKING - - -/** - * @brief Get field version from boot message - * - * @return The onboard software version - */ -static inline uint32_t mavlink_msg_boot_get_version(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 0); -} - -/** - * @brief Decode a boot message into a struct - * - * @param msg The message to decode - * @param boot C-struct to decode the message contents into - */ -static inline void mavlink_msg_boot_decode(const mavlink_message_t* msg, mavlink_boot_t* boot) -{ -#if MAVLINK_NEED_BYTE_SWAP - boot->version = mavlink_msg_boot_get_version(msg); -#else - memcpy(boot, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_change_operator_control.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_change_operator_control.h deleted file mode 100644 index 8fad932ea8..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_change_operator_control.h +++ /dev/null @@ -1,204 +0,0 @@ -// MESSAGE CHANGE_OPERATOR_CONTROL PACKING - -#define MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL 5 - -typedef struct __mavlink_change_operator_control_t -{ - uint8_t target_system; ///< System the GCS requests control for - uint8_t control_request; ///< 0: request control of this MAV, 1: Release control of this MAV - uint8_t version; ///< 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. - char passkey[25]; ///< Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" -} mavlink_change_operator_control_t; - -#define MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_LEN 28 -#define MAVLINK_MSG_ID_5_LEN 28 - -#define MAVLINK_MSG_CHANGE_OPERATOR_CONTROL_FIELD_PASSKEY_LEN 25 - -#define MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL { \ - "CHANGE_OPERATOR_CONTROL", \ - 4, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_change_operator_control_t, target_system) }, \ - { "control_request", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_change_operator_control_t, control_request) }, \ - { "version", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_change_operator_control_t, version) }, \ - { "passkey", NULL, MAVLINK_TYPE_CHAR, 25, 3, offsetof(mavlink_change_operator_control_t, passkey) }, \ - } \ -} - - -/** - * @brief Pack a change_operator_control message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System the GCS requests control for - * @param control_request 0: request control of this MAV, 1: Release control of this MAV - * @param version 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. - * @param passkey Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_change_operator_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t control_request, uint8_t version, const char *passkey) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[28]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, control_request); - _mav_put_uint8_t(buf, 2, version); - _mav_put_char_array(buf, 3, passkey, 25); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 28); -#else - mavlink_change_operator_control_t packet; - packet.target_system = target_system; - packet.control_request = control_request; - packet.version = version; - mav_array_memcpy(packet.passkey, passkey, sizeof(char)*25); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 28); -#endif - - msg->msgid = MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 28); -} - -/** - * @brief Pack a change_operator_control message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System the GCS requests control for - * @param control_request 0: request control of this MAV, 1: Release control of this MAV - * @param version 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. - * @param passkey Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_change_operator_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t control_request,uint8_t version,const char *passkey) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[28]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, control_request); - _mav_put_uint8_t(buf, 2, version); - _mav_put_char_array(buf, 3, passkey, 25); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 28); -#else - mavlink_change_operator_control_t packet; - packet.target_system = target_system; - packet.control_request = control_request; - packet.version = version; - mav_array_memcpy(packet.passkey, passkey, sizeof(char)*25); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 28); -#endif - - msg->msgid = MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 28); -} - -/** - * @brief Encode a change_operator_control struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param change_operator_control C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_change_operator_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_change_operator_control_t* change_operator_control) -{ - return mavlink_msg_change_operator_control_pack(system_id, component_id, msg, change_operator_control->target_system, change_operator_control->control_request, change_operator_control->version, change_operator_control->passkey); -} - -/** - * @brief Send a change_operator_control message - * @param chan MAVLink channel to send the message - * - * @param target_system System the GCS requests control for - * @param control_request 0: request control of this MAV, 1: Release control of this MAV - * @param version 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. - * @param passkey Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_change_operator_control_send(mavlink_channel_t chan, uint8_t target_system, uint8_t control_request, uint8_t version, const char *passkey) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[28]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, control_request); - _mav_put_uint8_t(buf, 2, version); - _mav_put_char_array(buf, 3, passkey, 25); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL, buf, 28); -#else - mavlink_change_operator_control_t packet; - packet.target_system = target_system; - packet.control_request = control_request; - packet.version = version; - mav_array_memcpy(packet.passkey, passkey, sizeof(char)*25); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL, (const char *)&packet, 28); -#endif -} - -#endif - -// MESSAGE CHANGE_OPERATOR_CONTROL UNPACKING - - -/** - * @brief Get field target_system from change_operator_control message - * - * @return System the GCS requests control for - */ -static inline uint8_t mavlink_msg_change_operator_control_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field control_request from change_operator_control message - * - * @return 0: request control of this MAV, 1: Release control of this MAV - */ -static inline uint8_t mavlink_msg_change_operator_control_get_control_request(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field version from change_operator_control message - * - * @return 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. - */ -static inline uint8_t mavlink_msg_change_operator_control_get_version(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field passkey from change_operator_control message - * - * @return Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" - */ -static inline uint16_t mavlink_msg_change_operator_control_get_passkey(const mavlink_message_t* msg, char *passkey) -{ - return _MAV_RETURN_char_array(msg, passkey, 25, 3); -} - -/** - * @brief Decode a change_operator_control message into a struct - * - * @param msg The message to decode - * @param change_operator_control C-struct to decode the message contents into - */ -static inline void mavlink_msg_change_operator_control_decode(const mavlink_message_t* msg, mavlink_change_operator_control_t* change_operator_control) -{ -#if MAVLINK_NEED_BYTE_SWAP - change_operator_control->target_system = mavlink_msg_change_operator_control_get_target_system(msg); - change_operator_control->control_request = mavlink_msg_change_operator_control_get_control_request(msg); - change_operator_control->version = mavlink_msg_change_operator_control_get_version(msg); - mavlink_msg_change_operator_control_get_passkey(msg, change_operator_control->passkey); -#else - memcpy(change_operator_control, _MAV_PAYLOAD(msg), 28); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_change_operator_control_ack.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_change_operator_control_ack.h deleted file mode 100644 index e9e195bbb9..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_change_operator_control_ack.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE CHANGE_OPERATOR_CONTROL_ACK PACKING - -#define MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK 6 - -typedef struct __mavlink_change_operator_control_ack_t -{ - uint8_t gcs_system_id; ///< ID of the GCS this message - uint8_t control_request; ///< 0: request control of this MAV, 1: Release control of this MAV - uint8_t ack; ///< 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control -} mavlink_change_operator_control_ack_t; - -#define MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK_LEN 3 -#define MAVLINK_MSG_ID_6_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK { \ - "CHANGE_OPERATOR_CONTROL_ACK", \ - 3, \ - { { "gcs_system_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_change_operator_control_ack_t, gcs_system_id) }, \ - { "control_request", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_change_operator_control_ack_t, control_request) }, \ - { "ack", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_change_operator_control_ack_t, ack) }, \ - } \ -} - - -/** - * @brief Pack a change_operator_control_ack message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param gcs_system_id ID of the GCS this message - * @param control_request 0: request control of this MAV, 1: Release control of this MAV - * @param ack 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_change_operator_control_ack_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t gcs_system_id, uint8_t control_request, uint8_t ack) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, gcs_system_id); - _mav_put_uint8_t(buf, 1, control_request); - _mav_put_uint8_t(buf, 2, ack); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_change_operator_control_ack_t packet; - packet.gcs_system_id = gcs_system_id; - packet.control_request = control_request; - packet.ack = ack; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a change_operator_control_ack message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param gcs_system_id ID of the GCS this message - * @param control_request 0: request control of this MAV, 1: Release control of this MAV - * @param ack 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_change_operator_control_ack_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t gcs_system_id,uint8_t control_request,uint8_t ack) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, gcs_system_id); - _mav_put_uint8_t(buf, 1, control_request); - _mav_put_uint8_t(buf, 2, ack); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_change_operator_control_ack_t packet; - packet.gcs_system_id = gcs_system_id; - packet.control_request = control_request; - packet.ack = ack; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a change_operator_control_ack struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param change_operator_control_ack C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_change_operator_control_ack_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_change_operator_control_ack_t* change_operator_control_ack) -{ - return mavlink_msg_change_operator_control_ack_pack(system_id, component_id, msg, change_operator_control_ack->gcs_system_id, change_operator_control_ack->control_request, change_operator_control_ack->ack); -} - -/** - * @brief Send a change_operator_control_ack message - * @param chan MAVLink channel to send the message - * - * @param gcs_system_id ID of the GCS this message - * @param control_request 0: request control of this MAV, 1: Release control of this MAV - * @param ack 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_change_operator_control_ack_send(mavlink_channel_t chan, uint8_t gcs_system_id, uint8_t control_request, uint8_t ack) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, gcs_system_id); - _mav_put_uint8_t(buf, 1, control_request); - _mav_put_uint8_t(buf, 2, ack); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK, buf, 3); -#else - mavlink_change_operator_control_ack_t packet; - packet.gcs_system_id = gcs_system_id; - packet.control_request = control_request; - packet.ack = ack; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE CHANGE_OPERATOR_CONTROL_ACK UNPACKING - - -/** - * @brief Get field gcs_system_id from change_operator_control_ack message - * - * @return ID of the GCS this message - */ -static inline uint8_t mavlink_msg_change_operator_control_ack_get_gcs_system_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field control_request from change_operator_control_ack message - * - * @return 0: request control of this MAV, 1: Release control of this MAV - */ -static inline uint8_t mavlink_msg_change_operator_control_ack_get_control_request(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field ack from change_operator_control_ack message - * - * @return 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control - */ -static inline uint8_t mavlink_msg_change_operator_control_ack_get_ack(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a change_operator_control_ack message into a struct - * - * @param msg The message to decode - * @param change_operator_control_ack C-struct to decode the message contents into - */ -static inline void mavlink_msg_change_operator_control_ack_decode(const mavlink_message_t* msg, mavlink_change_operator_control_ack_t* change_operator_control_ack) -{ -#if MAVLINK_NEED_BYTE_SWAP - change_operator_control_ack->gcs_system_id = mavlink_msg_change_operator_control_ack_get_gcs_system_id(msg); - change_operator_control_ack->control_request = mavlink_msg_change_operator_control_ack_get_control_request(msg); - change_operator_control_ack->ack = mavlink_msg_change_operator_control_ack_get_ack(msg); -#else - memcpy(change_operator_control_ack, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_command.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_command.h deleted file mode 100644 index b5d44f8b2b..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_command.h +++ /dev/null @@ -1,298 +0,0 @@ -// MESSAGE COMMAND PACKING - -#define MAVLINK_MSG_ID_COMMAND 75 - -typedef struct __mavlink_command_t -{ - uint8_t target_system; ///< System which should execute the command - uint8_t target_component; ///< Component which should execute the command, 0 for all components - uint8_t command; ///< Command ID, as defined by MAV_CMD enum. - uint8_t confirmation; ///< 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) - float param1; ///< Parameter 1, as defined by MAV_CMD enum. - float param2; ///< Parameter 2, as defined by MAV_CMD enum. - float param3; ///< Parameter 3, as defined by MAV_CMD enum. - float param4; ///< Parameter 4, as defined by MAV_CMD enum. -} mavlink_command_t; - -#define MAVLINK_MSG_ID_COMMAND_LEN 20 -#define MAVLINK_MSG_ID_75_LEN 20 - - - -#define MAVLINK_MESSAGE_INFO_COMMAND { \ - "COMMAND", \ - 8, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_command_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_command_t, target_component) }, \ - { "command", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_command_t, command) }, \ - { "confirmation", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_command_t, confirmation) }, \ - { "param1", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_command_t, param1) }, \ - { "param2", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_command_t, param2) }, \ - { "param3", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_command_t, param3) }, \ - { "param4", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_command_t, param4) }, \ - } \ -} - - -/** - * @brief Pack a command message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System which should execute the command - * @param target_component Component which should execute the command, 0 for all components - * @param command Command ID, as defined by MAV_CMD enum. - * @param confirmation 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) - * @param param1 Parameter 1, as defined by MAV_CMD enum. - * @param param2 Parameter 2, as defined by MAV_CMD enum. - * @param param3 Parameter 3, as defined by MAV_CMD enum. - * @param param4 Parameter 4, as defined by MAV_CMD enum. - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_command_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t command, uint8_t confirmation, float param1, float param2, float param3, float param4) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, command); - _mav_put_uint8_t(buf, 3, confirmation); - _mav_put_float(buf, 4, param1); - _mav_put_float(buf, 8, param2); - _mav_put_float(buf, 12, param3); - _mav_put_float(buf, 16, param4); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_command_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.command = command; - packet.confirmation = confirmation; - packet.param1 = param1; - packet.param2 = param2; - packet.param3 = param3; - packet.param4 = param4; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_COMMAND; - return mavlink_finalize_message(msg, system_id, component_id, 20); -} - -/** - * @brief Pack a command message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System which should execute the command - * @param target_component Component which should execute the command, 0 for all components - * @param command Command ID, as defined by MAV_CMD enum. - * @param confirmation 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) - * @param param1 Parameter 1, as defined by MAV_CMD enum. - * @param param2 Parameter 2, as defined by MAV_CMD enum. - * @param param3 Parameter 3, as defined by MAV_CMD enum. - * @param param4 Parameter 4, as defined by MAV_CMD enum. - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_command_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t command,uint8_t confirmation,float param1,float param2,float param3,float param4) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, command); - _mav_put_uint8_t(buf, 3, confirmation); - _mav_put_float(buf, 4, param1); - _mav_put_float(buf, 8, param2); - _mav_put_float(buf, 12, param3); - _mav_put_float(buf, 16, param4); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_command_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.command = command; - packet.confirmation = confirmation; - packet.param1 = param1; - packet.param2 = param2; - packet.param3 = param3; - packet.param4 = param4; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_COMMAND; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 20); -} - -/** - * @brief Encode a command struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param command C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_command_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_command_t* command) -{ - return mavlink_msg_command_pack(system_id, component_id, msg, command->target_system, command->target_component, command->command, command->confirmation, command->param1, command->param2, command->param3, command->param4); -} - -/** - * @brief Send a command message - * @param chan MAVLink channel to send the message - * - * @param target_system System which should execute the command - * @param target_component Component which should execute the command, 0 for all components - * @param command Command ID, as defined by MAV_CMD enum. - * @param confirmation 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) - * @param param1 Parameter 1, as defined by MAV_CMD enum. - * @param param2 Parameter 2, as defined by MAV_CMD enum. - * @param param3 Parameter 3, as defined by MAV_CMD enum. - * @param param4 Parameter 4, as defined by MAV_CMD enum. - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_command_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t command, uint8_t confirmation, float param1, float param2, float param3, float param4) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, command); - _mav_put_uint8_t(buf, 3, confirmation); - _mav_put_float(buf, 4, param1); - _mav_put_float(buf, 8, param2); - _mav_put_float(buf, 12, param3); - _mav_put_float(buf, 16, param4); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COMMAND, buf, 20); -#else - mavlink_command_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.command = command; - packet.confirmation = confirmation; - packet.param1 = param1; - packet.param2 = param2; - packet.param3 = param3; - packet.param4 = param4; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COMMAND, (const char *)&packet, 20); -#endif -} - -#endif - -// MESSAGE COMMAND UNPACKING - - -/** - * @brief Get field target_system from command message - * - * @return System which should execute the command - */ -static inline uint8_t mavlink_msg_command_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from command message - * - * @return Component which should execute the command, 0 for all components - */ -static inline uint8_t mavlink_msg_command_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field command from command message - * - * @return Command ID, as defined by MAV_CMD enum. - */ -static inline uint8_t mavlink_msg_command_get_command(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field confirmation from command message - * - * @return 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) - */ -static inline uint8_t mavlink_msg_command_get_confirmation(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field param1 from command message - * - * @return Parameter 1, as defined by MAV_CMD enum. - */ -static inline float mavlink_msg_command_get_param1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field param2 from command message - * - * @return Parameter 2, as defined by MAV_CMD enum. - */ -static inline float mavlink_msg_command_get_param2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field param3 from command message - * - * @return Parameter 3, as defined by MAV_CMD enum. - */ -static inline float mavlink_msg_command_get_param3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field param4 from command message - * - * @return Parameter 4, as defined by MAV_CMD enum. - */ -static inline float mavlink_msg_command_get_param4(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Decode a command message into a struct - * - * @param msg The message to decode - * @param command C-struct to decode the message contents into - */ -static inline void mavlink_msg_command_decode(const mavlink_message_t* msg, mavlink_command_t* command) -{ -#if MAVLINK_NEED_BYTE_SWAP - command->target_system = mavlink_msg_command_get_target_system(msg); - command->target_component = mavlink_msg_command_get_target_component(msg); - command->command = mavlink_msg_command_get_command(msg); - command->confirmation = mavlink_msg_command_get_confirmation(msg); - command->param1 = mavlink_msg_command_get_param1(msg); - command->param2 = mavlink_msg_command_get_param2(msg); - command->param3 = mavlink_msg_command_get_param3(msg); - command->param4 = mavlink_msg_command_get_param4(msg); -#else - memcpy(command, _MAV_PAYLOAD(msg), 20); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_command_ack.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_command_ack.h deleted file mode 100644 index ee4c89dcfa..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_command_ack.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE COMMAND_ACK PACKING - -#define MAVLINK_MSG_ID_COMMAND_ACK 76 - -typedef struct __mavlink_command_ack_t -{ - float command; ///< Current airspeed in m/s - float result; ///< 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION -} mavlink_command_ack_t; - -#define MAVLINK_MSG_ID_COMMAND_ACK_LEN 8 -#define MAVLINK_MSG_ID_76_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_COMMAND_ACK { \ - "COMMAND_ACK", \ - 2, \ - { { "command", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_command_ack_t, command) }, \ - { "result", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_command_ack_t, result) }, \ - } \ -} - - -/** - * @brief Pack a command_ack message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param command Current airspeed in m/s - * @param result 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_command_ack_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float command, float result) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_float(buf, 0, command); - _mav_put_float(buf, 4, result); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_command_ack_t packet; - packet.command = command; - packet.result = result; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_COMMAND_ACK; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a command_ack message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param command Current airspeed in m/s - * @param result 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_command_ack_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float command,float result) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_float(buf, 0, command); - _mav_put_float(buf, 4, result); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_command_ack_t packet; - packet.command = command; - packet.result = result; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_COMMAND_ACK; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a command_ack struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param command_ack C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_command_ack_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_command_ack_t* command_ack) -{ - return mavlink_msg_command_ack_pack(system_id, component_id, msg, command_ack->command, command_ack->result); -} - -/** - * @brief Send a command_ack message - * @param chan MAVLink channel to send the message - * - * @param command Current airspeed in m/s - * @param result 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_command_ack_send(mavlink_channel_t chan, float command, float result) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_float(buf, 0, command); - _mav_put_float(buf, 4, result); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COMMAND_ACK, buf, 8); -#else - mavlink_command_ack_t packet; - packet.command = command; - packet.result = result; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_COMMAND_ACK, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE COMMAND_ACK UNPACKING - - -/** - * @brief Get field command from command_ack message - * - * @return Current airspeed in m/s - */ -static inline float mavlink_msg_command_ack_get_command(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field result from command_ack message - * - * @return 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION - */ -static inline float mavlink_msg_command_ack_get_result(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Decode a command_ack message into a struct - * - * @param msg The message to decode - * @param command_ack C-struct to decode the message contents into - */ -static inline void mavlink_msg_command_ack_decode(const mavlink_message_t* msg, mavlink_command_ack_t* command_ack) -{ -#if MAVLINK_NEED_BYTE_SWAP - command_ack->command = mavlink_msg_command_ack_get_command(msg); - command_ack->result = mavlink_msg_command_ack_get_result(msg); -#else - memcpy(command_ack, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_control_status.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_control_status.h deleted file mode 100644 index ebc1568cc1..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_control_status.h +++ /dev/null @@ -1,298 +0,0 @@ -// MESSAGE CONTROL_STATUS PACKING - -#define MAVLINK_MSG_ID_CONTROL_STATUS 52 - -typedef struct __mavlink_control_status_t -{ - uint8_t position_fix; ///< Position fix: 0: lost, 2: 2D position fix, 3: 3D position fix - uint8_t vision_fix; ///< Vision position fix: 0: lost, 1: 2D local position hold, 2: 2D global position fix, 3: 3D global position fix - uint8_t gps_fix; ///< GPS position fix: 0: no reception, 1: Minimum 1 satellite, but no position fix, 2: 2D position fix, 3: 3D position fix - uint8_t ahrs_health; ///< Attitude estimation health: 0: poor, 255: excellent - uint8_t control_att; ///< 0: Attitude control disabled, 1: enabled - uint8_t control_pos_xy; ///< 0: X, Y position control disabled, 1: enabled - uint8_t control_pos_z; ///< 0: Z position control disabled, 1: enabled - uint8_t control_pos_yaw; ///< 0: Yaw angle control disabled, 1: enabled -} mavlink_control_status_t; - -#define MAVLINK_MSG_ID_CONTROL_STATUS_LEN 8 -#define MAVLINK_MSG_ID_52_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_CONTROL_STATUS { \ - "CONTROL_STATUS", \ - 8, \ - { { "position_fix", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_control_status_t, position_fix) }, \ - { "vision_fix", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_control_status_t, vision_fix) }, \ - { "gps_fix", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_control_status_t, gps_fix) }, \ - { "ahrs_health", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_control_status_t, ahrs_health) }, \ - { "control_att", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_control_status_t, control_att) }, \ - { "control_pos_xy", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_control_status_t, control_pos_xy) }, \ - { "control_pos_z", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_control_status_t, control_pos_z) }, \ - { "control_pos_yaw", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_control_status_t, control_pos_yaw) }, \ - } \ -} - - -/** - * @brief Pack a control_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param position_fix Position fix: 0: lost, 2: 2D position fix, 3: 3D position fix - * @param vision_fix Vision position fix: 0: lost, 1: 2D local position hold, 2: 2D global position fix, 3: 3D global position fix - * @param gps_fix GPS position fix: 0: no reception, 1: Minimum 1 satellite, but no position fix, 2: 2D position fix, 3: 3D position fix - * @param ahrs_health Attitude estimation health: 0: poor, 255: excellent - * @param control_att 0: Attitude control disabled, 1: enabled - * @param control_pos_xy 0: X, Y position control disabled, 1: enabled - * @param control_pos_z 0: Z position control disabled, 1: enabled - * @param control_pos_yaw 0: Yaw angle control disabled, 1: enabled - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_control_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t position_fix, uint8_t vision_fix, uint8_t gps_fix, uint8_t ahrs_health, uint8_t control_att, uint8_t control_pos_xy, uint8_t control_pos_z, uint8_t control_pos_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, position_fix); - _mav_put_uint8_t(buf, 1, vision_fix); - _mav_put_uint8_t(buf, 2, gps_fix); - _mav_put_uint8_t(buf, 3, ahrs_health); - _mav_put_uint8_t(buf, 4, control_att); - _mav_put_uint8_t(buf, 5, control_pos_xy); - _mav_put_uint8_t(buf, 6, control_pos_z); - _mav_put_uint8_t(buf, 7, control_pos_yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_control_status_t packet; - packet.position_fix = position_fix; - packet.vision_fix = vision_fix; - packet.gps_fix = gps_fix; - packet.ahrs_health = ahrs_health; - packet.control_att = control_att; - packet.control_pos_xy = control_pos_xy; - packet.control_pos_z = control_pos_z; - packet.control_pos_yaw = control_pos_yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_CONTROL_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a control_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param position_fix Position fix: 0: lost, 2: 2D position fix, 3: 3D position fix - * @param vision_fix Vision position fix: 0: lost, 1: 2D local position hold, 2: 2D global position fix, 3: 3D global position fix - * @param gps_fix GPS position fix: 0: no reception, 1: Minimum 1 satellite, but no position fix, 2: 2D position fix, 3: 3D position fix - * @param ahrs_health Attitude estimation health: 0: poor, 255: excellent - * @param control_att 0: Attitude control disabled, 1: enabled - * @param control_pos_xy 0: X, Y position control disabled, 1: enabled - * @param control_pos_z 0: Z position control disabled, 1: enabled - * @param control_pos_yaw 0: Yaw angle control disabled, 1: enabled - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_control_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t position_fix,uint8_t vision_fix,uint8_t gps_fix,uint8_t ahrs_health,uint8_t control_att,uint8_t control_pos_xy,uint8_t control_pos_z,uint8_t control_pos_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, position_fix); - _mav_put_uint8_t(buf, 1, vision_fix); - _mav_put_uint8_t(buf, 2, gps_fix); - _mav_put_uint8_t(buf, 3, ahrs_health); - _mav_put_uint8_t(buf, 4, control_att); - _mav_put_uint8_t(buf, 5, control_pos_xy); - _mav_put_uint8_t(buf, 6, control_pos_z); - _mav_put_uint8_t(buf, 7, control_pos_yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_control_status_t packet; - packet.position_fix = position_fix; - packet.vision_fix = vision_fix; - packet.gps_fix = gps_fix; - packet.ahrs_health = ahrs_health; - packet.control_att = control_att; - packet.control_pos_xy = control_pos_xy; - packet.control_pos_z = control_pos_z; - packet.control_pos_yaw = control_pos_yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_CONTROL_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a control_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param control_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_control_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_control_status_t* control_status) -{ - return mavlink_msg_control_status_pack(system_id, component_id, msg, control_status->position_fix, control_status->vision_fix, control_status->gps_fix, control_status->ahrs_health, control_status->control_att, control_status->control_pos_xy, control_status->control_pos_z, control_status->control_pos_yaw); -} - -/** - * @brief Send a control_status message - * @param chan MAVLink channel to send the message - * - * @param position_fix Position fix: 0: lost, 2: 2D position fix, 3: 3D position fix - * @param vision_fix Vision position fix: 0: lost, 1: 2D local position hold, 2: 2D global position fix, 3: 3D global position fix - * @param gps_fix GPS position fix: 0: no reception, 1: Minimum 1 satellite, but no position fix, 2: 2D position fix, 3: 3D position fix - * @param ahrs_health Attitude estimation health: 0: poor, 255: excellent - * @param control_att 0: Attitude control disabled, 1: enabled - * @param control_pos_xy 0: X, Y position control disabled, 1: enabled - * @param control_pos_z 0: Z position control disabled, 1: enabled - * @param control_pos_yaw 0: Yaw angle control disabled, 1: enabled - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_control_status_send(mavlink_channel_t chan, uint8_t position_fix, uint8_t vision_fix, uint8_t gps_fix, uint8_t ahrs_health, uint8_t control_att, uint8_t control_pos_xy, uint8_t control_pos_z, uint8_t control_pos_yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, position_fix); - _mav_put_uint8_t(buf, 1, vision_fix); - _mav_put_uint8_t(buf, 2, gps_fix); - _mav_put_uint8_t(buf, 3, ahrs_health); - _mav_put_uint8_t(buf, 4, control_att); - _mav_put_uint8_t(buf, 5, control_pos_xy); - _mav_put_uint8_t(buf, 6, control_pos_z); - _mav_put_uint8_t(buf, 7, control_pos_yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CONTROL_STATUS, buf, 8); -#else - mavlink_control_status_t packet; - packet.position_fix = position_fix; - packet.vision_fix = vision_fix; - packet.gps_fix = gps_fix; - packet.ahrs_health = ahrs_health; - packet.control_att = control_att; - packet.control_pos_xy = control_pos_xy; - packet.control_pos_z = control_pos_z; - packet.control_pos_yaw = control_pos_yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CONTROL_STATUS, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE CONTROL_STATUS UNPACKING - - -/** - * @brief Get field position_fix from control_status message - * - * @return Position fix: 0: lost, 2: 2D position fix, 3: 3D position fix - */ -static inline uint8_t mavlink_msg_control_status_get_position_fix(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field vision_fix from control_status message - * - * @return Vision position fix: 0: lost, 1: 2D local position hold, 2: 2D global position fix, 3: 3D global position fix - */ -static inline uint8_t mavlink_msg_control_status_get_vision_fix(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field gps_fix from control_status message - * - * @return GPS position fix: 0: no reception, 1: Minimum 1 satellite, but no position fix, 2: 2D position fix, 3: 3D position fix - */ -static inline uint8_t mavlink_msg_control_status_get_gps_fix(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field ahrs_health from control_status message - * - * @return Attitude estimation health: 0: poor, 255: excellent - */ -static inline uint8_t mavlink_msg_control_status_get_ahrs_health(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field control_att from control_status message - * - * @return 0: Attitude control disabled, 1: enabled - */ -static inline uint8_t mavlink_msg_control_status_get_control_att(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field control_pos_xy from control_status message - * - * @return 0: X, Y position control disabled, 1: enabled - */ -static inline uint8_t mavlink_msg_control_status_get_control_pos_xy(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field control_pos_z from control_status message - * - * @return 0: Z position control disabled, 1: enabled - */ -static inline uint8_t mavlink_msg_control_status_get_control_pos_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field control_pos_yaw from control_status message - * - * @return 0: Yaw angle control disabled, 1: enabled - */ -static inline uint8_t mavlink_msg_control_status_get_control_pos_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 7); -} - -/** - * @brief Decode a control_status message into a struct - * - * @param msg The message to decode - * @param control_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_control_status_decode(const mavlink_message_t* msg, mavlink_control_status_t* control_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - control_status->position_fix = mavlink_msg_control_status_get_position_fix(msg); - control_status->vision_fix = mavlink_msg_control_status_get_vision_fix(msg); - control_status->gps_fix = mavlink_msg_control_status_get_gps_fix(msg); - control_status->ahrs_health = mavlink_msg_control_status_get_ahrs_health(msg); - control_status->control_att = mavlink_msg_control_status_get_control_att(msg); - control_status->control_pos_xy = mavlink_msg_control_status_get_control_pos_xy(msg); - control_status->control_pos_z = mavlink_msg_control_status_get_control_pos_z(msg); - control_status->control_pos_yaw = mavlink_msg_control_status_get_control_pos_yaw(msg); -#else - memcpy(control_status, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_debug.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_debug.h deleted file mode 100644 index 5a0fbdd710..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_debug.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE DEBUG PACKING - -#define MAVLINK_MSG_ID_DEBUG 255 - -typedef struct __mavlink_debug_t -{ - uint8_t ind; ///< index of debug variable - float value; ///< DEBUG value -} mavlink_debug_t; - -#define MAVLINK_MSG_ID_DEBUG_LEN 5 -#define MAVLINK_MSG_ID_255_LEN 5 - - - -#define MAVLINK_MESSAGE_INFO_DEBUG { \ - "DEBUG", \ - 2, \ - { { "ind", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_debug_t, ind) }, \ - { "value", NULL, MAVLINK_TYPE_FLOAT, 0, 1, offsetof(mavlink_debug_t, value) }, \ - } \ -} - - -/** - * @brief Pack a debug message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param ind index of debug variable - * @param value DEBUG value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_debug_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t ind, float value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[5]; - _mav_put_uint8_t(buf, 0, ind); - _mav_put_float(buf, 1, value); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 5); -#else - mavlink_debug_t packet; - packet.ind = ind; - packet.value = value; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 5); -#endif - - msg->msgid = MAVLINK_MSG_ID_DEBUG; - return mavlink_finalize_message(msg, system_id, component_id, 5); -} - -/** - * @brief Pack a debug message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param ind index of debug variable - * @param value DEBUG value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_debug_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t ind,float value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[5]; - _mav_put_uint8_t(buf, 0, ind); - _mav_put_float(buf, 1, value); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 5); -#else - mavlink_debug_t packet; - packet.ind = ind; - packet.value = value; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 5); -#endif - - msg->msgid = MAVLINK_MSG_ID_DEBUG; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 5); -} - -/** - * @brief Encode a debug struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param debug C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_debug_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_debug_t* debug) -{ - return mavlink_msg_debug_pack(system_id, component_id, msg, debug->ind, debug->value); -} - -/** - * @brief Send a debug message - * @param chan MAVLink channel to send the message - * - * @param ind index of debug variable - * @param value DEBUG value - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_debug_send(mavlink_channel_t chan, uint8_t ind, float value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[5]; - _mav_put_uint8_t(buf, 0, ind); - _mav_put_float(buf, 1, value); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, buf, 5); -#else - mavlink_debug_t packet; - packet.ind = ind; - packet.value = value; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG, (const char *)&packet, 5); -#endif -} - -#endif - -// MESSAGE DEBUG UNPACKING - - -/** - * @brief Get field ind from debug message - * - * @return index of debug variable - */ -static inline uint8_t mavlink_msg_debug_get_ind(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field value from debug message - * - * @return DEBUG value - */ -static inline float mavlink_msg_debug_get_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 1); -} - -/** - * @brief Decode a debug message into a struct - * - * @param msg The message to decode - * @param debug C-struct to decode the message contents into - */ -static inline void mavlink_msg_debug_decode(const mavlink_message_t* msg, mavlink_debug_t* debug) -{ -#if MAVLINK_NEED_BYTE_SWAP - debug->ind = mavlink_msg_debug_get_ind(msg); - debug->value = mavlink_msg_debug_get_value(msg); -#else - memcpy(debug, _MAV_PAYLOAD(msg), 5); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_debug_vect.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_debug_vect.h deleted file mode 100644 index 51895f3bad..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_debug_vect.h +++ /dev/null @@ -1,226 +0,0 @@ -// MESSAGE DEBUG_VECT PACKING - -#define MAVLINK_MSG_ID_DEBUG_VECT 251 - -typedef struct __mavlink_debug_vect_t -{ - char name[10]; ///< Name - uint64_t usec; ///< Timestamp - float x; ///< x - float y; ///< y - float z; ///< z -} mavlink_debug_vect_t; - -#define MAVLINK_MSG_ID_DEBUG_VECT_LEN 30 -#define MAVLINK_MSG_ID_251_LEN 30 - -#define MAVLINK_MSG_DEBUG_VECT_FIELD_NAME_LEN 10 - -#define MAVLINK_MESSAGE_INFO_DEBUG_VECT { \ - "DEBUG_VECT", \ - 5, \ - { { "name", NULL, MAVLINK_TYPE_CHAR, 10, 0, offsetof(mavlink_debug_vect_t, name) }, \ - { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 10, offsetof(mavlink_debug_vect_t, usec) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 18, offsetof(mavlink_debug_vect_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 22, offsetof(mavlink_debug_vect_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 26, offsetof(mavlink_debug_vect_t, z) }, \ - } \ -} - - -/** - * @brief Pack a debug_vect message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param name Name - * @param usec Timestamp - * @param x x - * @param y y - * @param z z - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_debug_vect_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const char *name, uint64_t usec, float x, float y, float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_uint64_t(buf, 10, usec); - _mav_put_float(buf, 18, x); - _mav_put_float(buf, 22, y); - _mav_put_float(buf, 26, z); - _mav_put_char_array(buf, 0, name, 10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 30); -#else - mavlink_debug_vect_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 30); -#endif - - msg->msgid = MAVLINK_MSG_ID_DEBUG_VECT; - return mavlink_finalize_message(msg, system_id, component_id, 30); -} - -/** - * @brief Pack a debug_vect message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param name Name - * @param usec Timestamp - * @param x x - * @param y y - * @param z z - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_debug_vect_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const char *name,uint64_t usec,float x,float y,float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_uint64_t(buf, 10, usec); - _mav_put_float(buf, 18, x); - _mav_put_float(buf, 22, y); - _mav_put_float(buf, 26, z); - _mav_put_char_array(buf, 0, name, 10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 30); -#else - mavlink_debug_vect_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 30); -#endif - - msg->msgid = MAVLINK_MSG_ID_DEBUG_VECT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 30); -} - -/** - * @brief Encode a debug_vect struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param debug_vect C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_debug_vect_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_debug_vect_t* debug_vect) -{ - return mavlink_msg_debug_vect_pack(system_id, component_id, msg, debug_vect->name, debug_vect->usec, debug_vect->x, debug_vect->y, debug_vect->z); -} - -/** - * @brief Send a debug_vect message - * @param chan MAVLink channel to send the message - * - * @param name Name - * @param usec Timestamp - * @param x x - * @param y y - * @param z z - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_debug_vect_send(mavlink_channel_t chan, const char *name, uint64_t usec, float x, float y, float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_uint64_t(buf, 10, usec); - _mav_put_float(buf, 18, x); - _mav_put_float(buf, 22, y); - _mav_put_float(buf, 26, z); - _mav_put_char_array(buf, 0, name, 10); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG_VECT, buf, 30); -#else - mavlink_debug_vect_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DEBUG_VECT, (const char *)&packet, 30); -#endif -} - -#endif - -// MESSAGE DEBUG_VECT UNPACKING - - -/** - * @brief Get field name from debug_vect message - * - * @return Name - */ -static inline uint16_t mavlink_msg_debug_vect_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 10, 0); -} - -/** - * @brief Get field usec from debug_vect message - * - * @return Timestamp - */ -static inline uint64_t mavlink_msg_debug_vect_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 10); -} - -/** - * @brief Get field x from debug_vect message - * - * @return x - */ -static inline float mavlink_msg_debug_vect_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 18); -} - -/** - * @brief Get field y from debug_vect message - * - * @return y - */ -static inline float mavlink_msg_debug_vect_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 22); -} - -/** - * @brief Get field z from debug_vect message - * - * @return z - */ -static inline float mavlink_msg_debug_vect_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 26); -} - -/** - * @brief Decode a debug_vect message into a struct - * - * @param msg The message to decode - * @param debug_vect C-struct to decode the message contents into - */ -static inline void mavlink_msg_debug_vect_decode(const mavlink_message_t* msg, mavlink_debug_vect_t* debug_vect) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_debug_vect_get_name(msg, debug_vect->name); - debug_vect->usec = mavlink_msg_debug_vect_get_usec(msg); - debug_vect->x = mavlink_msg_debug_vect_get_x(msg); - debug_vect->y = mavlink_msg_debug_vect_get_y(msg); - debug_vect->z = mavlink_msg_debug_vect_get_z(msg); -#else - memcpy(debug_vect, _MAV_PAYLOAD(msg), 30); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_global_position.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_global_position.h deleted file mode 100644 index 5e0b9fe810..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_global_position.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE GLOBAL_POSITION PACKING - -#define MAVLINK_MSG_ID_GLOBAL_POSITION 33 - -typedef struct __mavlink_global_position_t -{ - uint64_t usec; ///< Timestamp (microseconds since unix epoch) - float lat; ///< Latitude, in degrees - float lon; ///< Longitude, in degrees - float alt; ///< Absolute altitude, in meters - float vx; ///< X Speed (in Latitude direction, positive: going north) - float vy; ///< Y Speed (in Longitude direction, positive: going east) - float vz; ///< Z Speed (in Altitude direction, positive: going up) -} mavlink_global_position_t; - -#define MAVLINK_MSG_ID_GLOBAL_POSITION_LEN 32 -#define MAVLINK_MSG_ID_33_LEN 32 - - - -#define MAVLINK_MESSAGE_INFO_GLOBAL_POSITION { \ - "GLOBAL_POSITION", \ - 7, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_global_position_t, usec) }, \ - { "lat", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_global_position_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_global_position_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_global_position_t, alt) }, \ - { "vx", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_global_position_t, vx) }, \ - { "vy", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_global_position_t, vy) }, \ - { "vz", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_global_position_t, vz) }, \ - } \ -} - - -/** - * @brief Pack a global_position message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since unix epoch) - * @param lat Latitude, in degrees - * @param lon Longitude, in degrees - * @param alt Absolute altitude, in meters - * @param vx X Speed (in Latitude direction, positive: going north) - * @param vy Y Speed (in Longitude direction, positive: going east) - * @param vz Z Speed (in Altitude direction, positive: going up) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_global_position_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float lat, float lon, float alt, float vx, float vy, float vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, lat); - _mav_put_float(buf, 12, lon); - _mav_put_float(buf, 16, alt); - _mav_put_float(buf, 20, vx); - _mav_put_float(buf, 24, vy); - _mav_put_float(buf, 28, vz); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_global_position_t packet; - packet.usec = usec; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_GLOBAL_POSITION; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a global_position message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since unix epoch) - * @param lat Latitude, in degrees - * @param lon Longitude, in degrees - * @param alt Absolute altitude, in meters - * @param vx X Speed (in Latitude direction, positive: going north) - * @param vy Y Speed (in Longitude direction, positive: going east) - * @param vz Z Speed (in Altitude direction, positive: going up) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_global_position_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float lat,float lon,float alt,float vx,float vy,float vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, lat); - _mav_put_float(buf, 12, lon); - _mav_put_float(buf, 16, alt); - _mav_put_float(buf, 20, vx); - _mav_put_float(buf, 24, vy); - _mav_put_float(buf, 28, vz); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_global_position_t packet; - packet.usec = usec; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_GLOBAL_POSITION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a global_position struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param global_position C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_global_position_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_global_position_t* global_position) -{ - return mavlink_msg_global_position_pack(system_id, component_id, msg, global_position->usec, global_position->lat, global_position->lon, global_position->alt, global_position->vx, global_position->vy, global_position->vz); -} - -/** - * @brief Send a global_position message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since unix epoch) - * @param lat Latitude, in degrees - * @param lon Longitude, in degrees - * @param alt Absolute altitude, in meters - * @param vx X Speed (in Latitude direction, positive: going north) - * @param vy Y Speed (in Longitude direction, positive: going east) - * @param vz Z Speed (in Altitude direction, positive: going up) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_global_position_send(mavlink_channel_t chan, uint64_t usec, float lat, float lon, float alt, float vx, float vy, float vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, lat); - _mav_put_float(buf, 12, lon); - _mav_put_float(buf, 16, alt); - _mav_put_float(buf, 20, vx); - _mav_put_float(buf, 24, vy); - _mav_put_float(buf, 28, vz); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GLOBAL_POSITION, buf, 32); -#else - mavlink_global_position_t packet; - packet.usec = usec; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GLOBAL_POSITION, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE GLOBAL_POSITION UNPACKING - - -/** - * @brief Get field usec from global_position message - * - * @return Timestamp (microseconds since unix epoch) - */ -static inline uint64_t mavlink_msg_global_position_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field lat from global_position message - * - * @return Latitude, in degrees - */ -static inline float mavlink_msg_global_position_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field lon from global_position message - * - * @return Longitude, in degrees - */ -static inline float mavlink_msg_global_position_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field alt from global_position message - * - * @return Absolute altitude, in meters - */ -static inline float mavlink_msg_global_position_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field vx from global_position message - * - * @return X Speed (in Latitude direction, positive: going north) - */ -static inline float mavlink_msg_global_position_get_vx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field vy from global_position message - * - * @return Y Speed (in Longitude direction, positive: going east) - */ -static inline float mavlink_msg_global_position_get_vy(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field vz from global_position message - * - * @return Z Speed (in Altitude direction, positive: going up) - */ -static inline float mavlink_msg_global_position_get_vz(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a global_position message into a struct - * - * @param msg The message to decode - * @param global_position C-struct to decode the message contents into - */ -static inline void mavlink_msg_global_position_decode(const mavlink_message_t* msg, mavlink_global_position_t* global_position) -{ -#if MAVLINK_NEED_BYTE_SWAP - global_position->usec = mavlink_msg_global_position_get_usec(msg); - global_position->lat = mavlink_msg_global_position_get_lat(msg); - global_position->lon = mavlink_msg_global_position_get_lon(msg); - global_position->alt = mavlink_msg_global_position_get_alt(msg); - global_position->vx = mavlink_msg_global_position_get_vx(msg); - global_position->vy = mavlink_msg_global_position_get_vy(msg); - global_position->vz = mavlink_msg_global_position_get_vz(msg); -#else - memcpy(global_position, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_global_position_int.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_global_position_int.h deleted file mode 100644 index 859a500499..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_global_position_int.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE GLOBAL_POSITION_INT PACKING - -#define MAVLINK_MSG_ID_GLOBAL_POSITION_INT 73 - -typedef struct __mavlink_global_position_int_t -{ - int32_t lat; ///< Latitude, expressed as * 1E7 - int32_t lon; ///< Longitude, expressed as * 1E7 - int32_t alt; ///< Altitude in meters, expressed as * 1000 (millimeters) - int16_t vx; ///< Ground X Speed (Latitude), expressed as m/s * 100 - int16_t vy; ///< Ground Y Speed (Longitude), expressed as m/s * 100 - int16_t vz; ///< Ground Z Speed (Altitude), expressed as m/s * 100 -} mavlink_global_position_int_t; - -#define MAVLINK_MSG_ID_GLOBAL_POSITION_INT_LEN 18 -#define MAVLINK_MSG_ID_73_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT { \ - "GLOBAL_POSITION_INT", \ - 6, \ - { { "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_global_position_int_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_global_position_int_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_INT32_T, 0, 8, offsetof(mavlink_global_position_int_t, alt) }, \ - { "vx", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_global_position_int_t, vx) }, \ - { "vy", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_global_position_int_t, vy) }, \ - { "vz", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_global_position_int_t, vz) }, \ - } \ -} - - -/** - * @brief Pack a global_position_int message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param lat Latitude, expressed as * 1E7 - * @param lon Longitude, expressed as * 1E7 - * @param alt Altitude in meters, expressed as * 1000 (millimeters) - * @param vx Ground X Speed (Latitude), expressed as m/s * 100 - * @param vy Ground Y Speed (Longitude), expressed as m/s * 100 - * @param vz Ground Z Speed (Altitude), expressed as m/s * 100 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_global_position_int_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - int32_t lat, int32_t lon, int32_t alt, int16_t vx, int16_t vy, int16_t vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_int32_t(buf, 0, lat); - _mav_put_int32_t(buf, 4, lon); - _mav_put_int32_t(buf, 8, alt); - _mav_put_int16_t(buf, 12, vx); - _mav_put_int16_t(buf, 14, vy); - _mav_put_int16_t(buf, 16, vz); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_global_position_int_t packet; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_GLOBAL_POSITION_INT; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a global_position_int message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param lat Latitude, expressed as * 1E7 - * @param lon Longitude, expressed as * 1E7 - * @param alt Altitude in meters, expressed as * 1000 (millimeters) - * @param vx Ground X Speed (Latitude), expressed as m/s * 100 - * @param vy Ground Y Speed (Longitude), expressed as m/s * 100 - * @param vz Ground Z Speed (Altitude), expressed as m/s * 100 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_global_position_int_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - int32_t lat,int32_t lon,int32_t alt,int16_t vx,int16_t vy,int16_t vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_int32_t(buf, 0, lat); - _mav_put_int32_t(buf, 4, lon); - _mav_put_int32_t(buf, 8, alt); - _mav_put_int16_t(buf, 12, vx); - _mav_put_int16_t(buf, 14, vy); - _mav_put_int16_t(buf, 16, vz); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_global_position_int_t packet; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_GLOBAL_POSITION_INT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a global_position_int struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param global_position_int C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_global_position_int_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_global_position_int_t* global_position_int) -{ - return mavlink_msg_global_position_int_pack(system_id, component_id, msg, global_position_int->lat, global_position_int->lon, global_position_int->alt, global_position_int->vx, global_position_int->vy, global_position_int->vz); -} - -/** - * @brief Send a global_position_int message - * @param chan MAVLink channel to send the message - * - * @param lat Latitude, expressed as * 1E7 - * @param lon Longitude, expressed as * 1E7 - * @param alt Altitude in meters, expressed as * 1000 (millimeters) - * @param vx Ground X Speed (Latitude), expressed as m/s * 100 - * @param vy Ground Y Speed (Longitude), expressed as m/s * 100 - * @param vz Ground Z Speed (Altitude), expressed as m/s * 100 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_global_position_int_send(mavlink_channel_t chan, int32_t lat, int32_t lon, int32_t alt, int16_t vx, int16_t vy, int16_t vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_int32_t(buf, 0, lat); - _mav_put_int32_t(buf, 4, lon); - _mav_put_int32_t(buf, 8, alt); - _mav_put_int16_t(buf, 12, vx); - _mav_put_int16_t(buf, 14, vy); - _mav_put_int16_t(buf, 16, vz); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GLOBAL_POSITION_INT, buf, 18); -#else - mavlink_global_position_int_t packet; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GLOBAL_POSITION_INT, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE GLOBAL_POSITION_INT UNPACKING - - -/** - * @brief Get field lat from global_position_int message - * - * @return Latitude, expressed as * 1E7 - */ -static inline int32_t mavlink_msg_global_position_int_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 0); -} - -/** - * @brief Get field lon from global_position_int message - * - * @return Longitude, expressed as * 1E7 - */ -static inline int32_t mavlink_msg_global_position_int_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 4); -} - -/** - * @brief Get field alt from global_position_int message - * - * @return Altitude in meters, expressed as * 1000 (millimeters) - */ -static inline int32_t mavlink_msg_global_position_int_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 8); -} - -/** - * @brief Get field vx from global_position_int message - * - * @return Ground X Speed (Latitude), expressed as m/s * 100 - */ -static inline int16_t mavlink_msg_global_position_int_get_vx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field vy from global_position_int message - * - * @return Ground Y Speed (Longitude), expressed as m/s * 100 - */ -static inline int16_t mavlink_msg_global_position_int_get_vy(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Get field vz from global_position_int message - * - * @return Ground Z Speed (Altitude), expressed as m/s * 100 - */ -static inline int16_t mavlink_msg_global_position_int_get_vz(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 16); -} - -/** - * @brief Decode a global_position_int message into a struct - * - * @param msg The message to decode - * @param global_position_int C-struct to decode the message contents into - */ -static inline void mavlink_msg_global_position_int_decode(const mavlink_message_t* msg, mavlink_global_position_int_t* global_position_int) -{ -#if MAVLINK_NEED_BYTE_SWAP - global_position_int->lat = mavlink_msg_global_position_int_get_lat(msg); - global_position_int->lon = mavlink_msg_global_position_int_get_lon(msg); - global_position_int->alt = mavlink_msg_global_position_int_get_alt(msg); - global_position_int->vx = mavlink_msg_global_position_int_get_vx(msg); - global_position_int->vy = mavlink_msg_global_position_int_get_vy(msg); - global_position_int->vz = mavlink_msg_global_position_int_get_vz(msg); -#else - memcpy(global_position_int, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_local_origin_set.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_local_origin_set.h deleted file mode 100644 index 5faec2812c..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_local_origin_set.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE GPS_LOCAL_ORIGIN_SET PACKING - -#define MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET 49 - -typedef struct __mavlink_gps_local_origin_set_t -{ - int32_t latitude; ///< Latitude (WGS84), expressed as * 1E7 - int32_t longitude; ///< Longitude (WGS84), expressed as * 1E7 - int32_t altitude; ///< Altitude(WGS84), expressed as * 1000 -} mavlink_gps_local_origin_set_t; - -#define MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET_LEN 12 -#define MAVLINK_MSG_ID_49_LEN 12 - - - -#define MAVLINK_MESSAGE_INFO_GPS_LOCAL_ORIGIN_SET { \ - "GPS_LOCAL_ORIGIN_SET", \ - 3, \ - { { "latitude", NULL, MAVLINK_TYPE_INT32_T, 0, 0, offsetof(mavlink_gps_local_origin_set_t, latitude) }, \ - { "longitude", NULL, MAVLINK_TYPE_INT32_T, 0, 4, offsetof(mavlink_gps_local_origin_set_t, longitude) }, \ - { "altitude", NULL, MAVLINK_TYPE_INT32_T, 0, 8, offsetof(mavlink_gps_local_origin_set_t, altitude) }, \ - } \ -} - - -/** - * @brief Pack a gps_local_origin_set message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param latitude Latitude (WGS84), expressed as * 1E7 - * @param longitude Longitude (WGS84), expressed as * 1E7 - * @param altitude Altitude(WGS84), expressed as * 1000 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_local_origin_set_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - int32_t latitude, int32_t longitude, int32_t altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_int32_t(buf, 0, latitude); - _mav_put_int32_t(buf, 4, longitude); - _mav_put_int32_t(buf, 8, altitude); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_gps_local_origin_set_t packet; - packet.latitude = latitude; - packet.longitude = longitude; - packet.altitude = altitude; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET; - return mavlink_finalize_message(msg, system_id, component_id, 12); -} - -/** - * @brief Pack a gps_local_origin_set message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param latitude Latitude (WGS84), expressed as * 1E7 - * @param longitude Longitude (WGS84), expressed as * 1E7 - * @param altitude Altitude(WGS84), expressed as * 1000 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_local_origin_set_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - int32_t latitude,int32_t longitude,int32_t altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_int32_t(buf, 0, latitude); - _mav_put_int32_t(buf, 4, longitude); - _mav_put_int32_t(buf, 8, altitude); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_gps_local_origin_set_t packet; - packet.latitude = latitude; - packet.longitude = longitude; - packet.altitude = altitude; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 12); -} - -/** - * @brief Encode a gps_local_origin_set struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_local_origin_set C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_local_origin_set_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_local_origin_set_t* gps_local_origin_set) -{ - return mavlink_msg_gps_local_origin_set_pack(system_id, component_id, msg, gps_local_origin_set->latitude, gps_local_origin_set->longitude, gps_local_origin_set->altitude); -} - -/** - * @brief Send a gps_local_origin_set message - * @param chan MAVLink channel to send the message - * - * @param latitude Latitude (WGS84), expressed as * 1E7 - * @param longitude Longitude (WGS84), expressed as * 1E7 - * @param altitude Altitude(WGS84), expressed as * 1000 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_local_origin_set_send(mavlink_channel_t chan, int32_t latitude, int32_t longitude, int32_t altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_int32_t(buf, 0, latitude); - _mav_put_int32_t(buf, 4, longitude); - _mav_put_int32_t(buf, 8, altitude); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET, buf, 12); -#else - mavlink_gps_local_origin_set_t packet; - packet.latitude = latitude; - packet.longitude = longitude; - packet.altitude = altitude; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET, (const char *)&packet, 12); -#endif -} - -#endif - -// MESSAGE GPS_LOCAL_ORIGIN_SET UNPACKING - - -/** - * @brief Get field latitude from gps_local_origin_set message - * - * @return Latitude (WGS84), expressed as * 1E7 - */ -static inline int32_t mavlink_msg_gps_local_origin_set_get_latitude(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 0); -} - -/** - * @brief Get field longitude from gps_local_origin_set message - * - * @return Longitude (WGS84), expressed as * 1E7 - */ -static inline int32_t mavlink_msg_gps_local_origin_set_get_longitude(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 4); -} - -/** - * @brief Get field altitude from gps_local_origin_set message - * - * @return Altitude(WGS84), expressed as * 1000 - */ -static inline int32_t mavlink_msg_gps_local_origin_set_get_altitude(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 8); -} - -/** - * @brief Decode a gps_local_origin_set message into a struct - * - * @param msg The message to decode - * @param gps_local_origin_set C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_local_origin_set_decode(const mavlink_message_t* msg, mavlink_gps_local_origin_set_t* gps_local_origin_set) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_local_origin_set->latitude = mavlink_msg_gps_local_origin_set_get_latitude(msg); - gps_local_origin_set->longitude = mavlink_msg_gps_local_origin_set_get_longitude(msg); - gps_local_origin_set->altitude = mavlink_msg_gps_local_origin_set_get_altitude(msg); -#else - memcpy(gps_local_origin_set, _MAV_PAYLOAD(msg), 12); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_raw.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_raw.h deleted file mode 100644 index 255cb27bef..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_raw.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE GPS_RAW PACKING - -#define MAVLINK_MSG_ID_GPS_RAW 32 - -typedef struct __mavlink_gps_raw_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - uint8_t fix_type; ///< 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - float lat; ///< Latitude in degrees - float lon; ///< Longitude in degrees - float alt; ///< Altitude in meters - float eph; ///< GPS HDOP - float epv; ///< GPS VDOP - float v; ///< GPS ground speed - float hdg; ///< Compass heading in degrees, 0..360 degrees -} mavlink_gps_raw_t; - -#define MAVLINK_MSG_ID_GPS_RAW_LEN 37 -#define MAVLINK_MSG_ID_32_LEN 37 - - - -#define MAVLINK_MESSAGE_INFO_GPS_RAW { \ - "GPS_RAW", \ - 9, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_gps_raw_t, usec) }, \ - { "fix_type", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_gps_raw_t, fix_type) }, \ - { "lat", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_gps_raw_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_FLOAT, 0, 13, offsetof(mavlink_gps_raw_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 17, offsetof(mavlink_gps_raw_t, alt) }, \ - { "eph", NULL, MAVLINK_TYPE_FLOAT, 0, 21, offsetof(mavlink_gps_raw_t, eph) }, \ - { "epv", NULL, MAVLINK_TYPE_FLOAT, 0, 25, offsetof(mavlink_gps_raw_t, epv) }, \ - { "v", NULL, MAVLINK_TYPE_FLOAT, 0, 29, offsetof(mavlink_gps_raw_t, v) }, \ - { "hdg", NULL, MAVLINK_TYPE_FLOAT, 0, 33, offsetof(mavlink_gps_raw_t, hdg) }, \ - } \ -} - - -/** - * @brief Pack a gps_raw message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param fix_type 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - * @param lat Latitude in degrees - * @param lon Longitude in degrees - * @param alt Altitude in meters - * @param eph GPS HDOP - * @param epv GPS VDOP - * @param v GPS ground speed - * @param hdg Compass heading in degrees, 0..360 degrees - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_raw_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, uint8_t fix_type, float lat, float lon, float alt, float eph, float epv, float v, float hdg) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[37]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_uint8_t(buf, 8, fix_type); - _mav_put_float(buf, 9, lat); - _mav_put_float(buf, 13, lon); - _mav_put_float(buf, 17, alt); - _mav_put_float(buf, 21, eph); - _mav_put_float(buf, 25, epv); - _mav_put_float(buf, 29, v); - _mav_put_float(buf, 33, hdg); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 37); -#else - mavlink_gps_raw_t packet; - packet.usec = usec; - packet.fix_type = fix_type; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.eph = eph; - packet.epv = epv; - packet.v = v; - packet.hdg = hdg; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 37); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_RAW; - return mavlink_finalize_message(msg, system_id, component_id, 37); -} - -/** - * @brief Pack a gps_raw message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param fix_type 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - * @param lat Latitude in degrees - * @param lon Longitude in degrees - * @param alt Altitude in meters - * @param eph GPS HDOP - * @param epv GPS VDOP - * @param v GPS ground speed - * @param hdg Compass heading in degrees, 0..360 degrees - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_raw_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,uint8_t fix_type,float lat,float lon,float alt,float eph,float epv,float v,float hdg) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[37]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_uint8_t(buf, 8, fix_type); - _mav_put_float(buf, 9, lat); - _mav_put_float(buf, 13, lon); - _mav_put_float(buf, 17, alt); - _mav_put_float(buf, 21, eph); - _mav_put_float(buf, 25, epv); - _mav_put_float(buf, 29, v); - _mav_put_float(buf, 33, hdg); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 37); -#else - mavlink_gps_raw_t packet; - packet.usec = usec; - packet.fix_type = fix_type; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.eph = eph; - packet.epv = epv; - packet.v = v; - packet.hdg = hdg; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 37); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_RAW; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 37); -} - -/** - * @brief Encode a gps_raw struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_raw C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_raw_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_raw_t* gps_raw) -{ - return mavlink_msg_gps_raw_pack(system_id, component_id, msg, gps_raw->usec, gps_raw->fix_type, gps_raw->lat, gps_raw->lon, gps_raw->alt, gps_raw->eph, gps_raw->epv, gps_raw->v, gps_raw->hdg); -} - -/** - * @brief Send a gps_raw message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param fix_type 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - * @param lat Latitude in degrees - * @param lon Longitude in degrees - * @param alt Altitude in meters - * @param eph GPS HDOP - * @param epv GPS VDOP - * @param v GPS ground speed - * @param hdg Compass heading in degrees, 0..360 degrees - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_raw_send(mavlink_channel_t chan, uint64_t usec, uint8_t fix_type, float lat, float lon, float alt, float eph, float epv, float v, float hdg) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[37]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_uint8_t(buf, 8, fix_type); - _mav_put_float(buf, 9, lat); - _mav_put_float(buf, 13, lon); - _mav_put_float(buf, 17, alt); - _mav_put_float(buf, 21, eph); - _mav_put_float(buf, 25, epv); - _mav_put_float(buf, 29, v); - _mav_put_float(buf, 33, hdg); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_RAW, buf, 37); -#else - mavlink_gps_raw_t packet; - packet.usec = usec; - packet.fix_type = fix_type; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.eph = eph; - packet.epv = epv; - packet.v = v; - packet.hdg = hdg; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_RAW, (const char *)&packet, 37); -#endif -} - -#endif - -// MESSAGE GPS_RAW UNPACKING - - -/** - * @brief Get field usec from gps_raw message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_gps_raw_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field fix_type from gps_raw message - * - * @return 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - */ -static inline uint8_t mavlink_msg_gps_raw_get_fix_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Get field lat from gps_raw message - * - * @return Latitude in degrees - */ -static inline float mavlink_msg_gps_raw_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Get field lon from gps_raw message - * - * @return Longitude in degrees - */ -static inline float mavlink_msg_gps_raw_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 13); -} - -/** - * @brief Get field alt from gps_raw message - * - * @return Altitude in meters - */ -static inline float mavlink_msg_gps_raw_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 17); -} - -/** - * @brief Get field eph from gps_raw message - * - * @return GPS HDOP - */ -static inline float mavlink_msg_gps_raw_get_eph(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 21); -} - -/** - * @brief Get field epv from gps_raw message - * - * @return GPS VDOP - */ -static inline float mavlink_msg_gps_raw_get_epv(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 25); -} - -/** - * @brief Get field v from gps_raw message - * - * @return GPS ground speed - */ -static inline float mavlink_msg_gps_raw_get_v(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 29); -} - -/** - * @brief Get field hdg from gps_raw message - * - * @return Compass heading in degrees, 0..360 degrees - */ -static inline float mavlink_msg_gps_raw_get_hdg(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 33); -} - -/** - * @brief Decode a gps_raw message into a struct - * - * @param msg The message to decode - * @param gps_raw C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_raw_decode(const mavlink_message_t* msg, mavlink_gps_raw_t* gps_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_raw->usec = mavlink_msg_gps_raw_get_usec(msg); - gps_raw->fix_type = mavlink_msg_gps_raw_get_fix_type(msg); - gps_raw->lat = mavlink_msg_gps_raw_get_lat(msg); - gps_raw->lon = mavlink_msg_gps_raw_get_lon(msg); - gps_raw->alt = mavlink_msg_gps_raw_get_alt(msg); - gps_raw->eph = mavlink_msg_gps_raw_get_eph(msg); - gps_raw->epv = mavlink_msg_gps_raw_get_epv(msg); - gps_raw->v = mavlink_msg_gps_raw_get_v(msg); - gps_raw->hdg = mavlink_msg_gps_raw_get_hdg(msg); -#else - memcpy(gps_raw, _MAV_PAYLOAD(msg), 37); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_raw_int.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_raw_int.h deleted file mode 100644 index f1e7a05e5d..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_raw_int.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE GPS_RAW_INT PACKING - -#define MAVLINK_MSG_ID_GPS_RAW_INT 25 - -typedef struct __mavlink_gps_raw_int_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - uint8_t fix_type; ///< 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - int32_t lat; ///< Latitude in 1E7 degrees - int32_t lon; ///< Longitude in 1E7 degrees - int32_t alt; ///< Altitude in 1E3 meters (millimeters) - float eph; ///< GPS HDOP - float epv; ///< GPS VDOP - float v; ///< GPS ground speed (m/s) - float hdg; ///< Compass heading in degrees, 0..360 degrees -} mavlink_gps_raw_int_t; - -#define MAVLINK_MSG_ID_GPS_RAW_INT_LEN 37 -#define MAVLINK_MSG_ID_25_LEN 37 - - - -#define MAVLINK_MESSAGE_INFO_GPS_RAW_INT { \ - "GPS_RAW_INT", \ - 9, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_gps_raw_int_t, usec) }, \ - { "fix_type", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_gps_raw_int_t, fix_type) }, \ - { "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 9, offsetof(mavlink_gps_raw_int_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 13, offsetof(mavlink_gps_raw_int_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_INT32_T, 0, 17, offsetof(mavlink_gps_raw_int_t, alt) }, \ - { "eph", NULL, MAVLINK_TYPE_FLOAT, 0, 21, offsetof(mavlink_gps_raw_int_t, eph) }, \ - { "epv", NULL, MAVLINK_TYPE_FLOAT, 0, 25, offsetof(mavlink_gps_raw_int_t, epv) }, \ - { "v", NULL, MAVLINK_TYPE_FLOAT, 0, 29, offsetof(mavlink_gps_raw_int_t, v) }, \ - { "hdg", NULL, MAVLINK_TYPE_FLOAT, 0, 33, offsetof(mavlink_gps_raw_int_t, hdg) }, \ - } \ -} - - -/** - * @brief Pack a gps_raw_int message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param fix_type 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - * @param lat Latitude in 1E7 degrees - * @param lon Longitude in 1E7 degrees - * @param alt Altitude in 1E3 meters (millimeters) - * @param eph GPS HDOP - * @param epv GPS VDOP - * @param v GPS ground speed (m/s) - * @param hdg Compass heading in degrees, 0..360 degrees - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_raw_int_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, uint8_t fix_type, int32_t lat, int32_t lon, int32_t alt, float eph, float epv, float v, float hdg) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[37]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_uint8_t(buf, 8, fix_type); - _mav_put_int32_t(buf, 9, lat); - _mav_put_int32_t(buf, 13, lon); - _mav_put_int32_t(buf, 17, alt); - _mav_put_float(buf, 21, eph); - _mav_put_float(buf, 25, epv); - _mav_put_float(buf, 29, v); - _mav_put_float(buf, 33, hdg); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 37); -#else - mavlink_gps_raw_int_t packet; - packet.usec = usec; - packet.fix_type = fix_type; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.eph = eph; - packet.epv = epv; - packet.v = v; - packet.hdg = hdg; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 37); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_RAW_INT; - return mavlink_finalize_message(msg, system_id, component_id, 37); -} - -/** - * @brief Pack a gps_raw_int message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param fix_type 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - * @param lat Latitude in 1E7 degrees - * @param lon Longitude in 1E7 degrees - * @param alt Altitude in 1E3 meters (millimeters) - * @param eph GPS HDOP - * @param epv GPS VDOP - * @param v GPS ground speed (m/s) - * @param hdg Compass heading in degrees, 0..360 degrees - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_raw_int_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,uint8_t fix_type,int32_t lat,int32_t lon,int32_t alt,float eph,float epv,float v,float hdg) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[37]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_uint8_t(buf, 8, fix_type); - _mav_put_int32_t(buf, 9, lat); - _mav_put_int32_t(buf, 13, lon); - _mav_put_int32_t(buf, 17, alt); - _mav_put_float(buf, 21, eph); - _mav_put_float(buf, 25, epv); - _mav_put_float(buf, 29, v); - _mav_put_float(buf, 33, hdg); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 37); -#else - mavlink_gps_raw_int_t packet; - packet.usec = usec; - packet.fix_type = fix_type; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.eph = eph; - packet.epv = epv; - packet.v = v; - packet.hdg = hdg; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 37); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_RAW_INT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 37); -} - -/** - * @brief Encode a gps_raw_int struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_raw_int C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_raw_int_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_raw_int_t* gps_raw_int) -{ - return mavlink_msg_gps_raw_int_pack(system_id, component_id, msg, gps_raw_int->usec, gps_raw_int->fix_type, gps_raw_int->lat, gps_raw_int->lon, gps_raw_int->alt, gps_raw_int->eph, gps_raw_int->epv, gps_raw_int->v, gps_raw_int->hdg); -} - -/** - * @brief Send a gps_raw_int message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param fix_type 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - * @param lat Latitude in 1E7 degrees - * @param lon Longitude in 1E7 degrees - * @param alt Altitude in 1E3 meters (millimeters) - * @param eph GPS HDOP - * @param epv GPS VDOP - * @param v GPS ground speed (m/s) - * @param hdg Compass heading in degrees, 0..360 degrees - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_raw_int_send(mavlink_channel_t chan, uint64_t usec, uint8_t fix_type, int32_t lat, int32_t lon, int32_t alt, float eph, float epv, float v, float hdg) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[37]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_uint8_t(buf, 8, fix_type); - _mav_put_int32_t(buf, 9, lat); - _mav_put_int32_t(buf, 13, lon); - _mav_put_int32_t(buf, 17, alt); - _mav_put_float(buf, 21, eph); - _mav_put_float(buf, 25, epv); - _mav_put_float(buf, 29, v); - _mav_put_float(buf, 33, hdg); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_RAW_INT, buf, 37); -#else - mavlink_gps_raw_int_t packet; - packet.usec = usec; - packet.fix_type = fix_type; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.eph = eph; - packet.epv = epv; - packet.v = v; - packet.hdg = hdg; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_RAW_INT, (const char *)&packet, 37); -#endif -} - -#endif - -// MESSAGE GPS_RAW_INT UNPACKING - - -/** - * @brief Get field usec from gps_raw_int message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_gps_raw_int_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field fix_type from gps_raw_int message - * - * @return 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. - */ -static inline uint8_t mavlink_msg_gps_raw_int_get_fix_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Get field lat from gps_raw_int message - * - * @return Latitude in 1E7 degrees - */ -static inline int32_t mavlink_msg_gps_raw_int_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 9); -} - -/** - * @brief Get field lon from gps_raw_int message - * - * @return Longitude in 1E7 degrees - */ -static inline int32_t mavlink_msg_gps_raw_int_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 13); -} - -/** - * @brief Get field alt from gps_raw_int message - * - * @return Altitude in 1E3 meters (millimeters) - */ -static inline int32_t mavlink_msg_gps_raw_int_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 17); -} - -/** - * @brief Get field eph from gps_raw_int message - * - * @return GPS HDOP - */ -static inline float mavlink_msg_gps_raw_int_get_eph(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 21); -} - -/** - * @brief Get field epv from gps_raw_int message - * - * @return GPS VDOP - */ -static inline float mavlink_msg_gps_raw_int_get_epv(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 25); -} - -/** - * @brief Get field v from gps_raw_int message - * - * @return GPS ground speed (m/s) - */ -static inline float mavlink_msg_gps_raw_int_get_v(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 29); -} - -/** - * @brief Get field hdg from gps_raw_int message - * - * @return Compass heading in degrees, 0..360 degrees - */ -static inline float mavlink_msg_gps_raw_int_get_hdg(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 33); -} - -/** - * @brief Decode a gps_raw_int message into a struct - * - * @param msg The message to decode - * @param gps_raw_int C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_raw_int_decode(const mavlink_message_t* msg, mavlink_gps_raw_int_t* gps_raw_int) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_raw_int->usec = mavlink_msg_gps_raw_int_get_usec(msg); - gps_raw_int->fix_type = mavlink_msg_gps_raw_int_get_fix_type(msg); - gps_raw_int->lat = mavlink_msg_gps_raw_int_get_lat(msg); - gps_raw_int->lon = mavlink_msg_gps_raw_int_get_lon(msg); - gps_raw_int->alt = mavlink_msg_gps_raw_int_get_alt(msg); - gps_raw_int->eph = mavlink_msg_gps_raw_int_get_eph(msg); - gps_raw_int->epv = mavlink_msg_gps_raw_int_get_epv(msg); - gps_raw_int->v = mavlink_msg_gps_raw_int_get_v(msg); - gps_raw_int->hdg = mavlink_msg_gps_raw_int_get_hdg(msg); -#else - memcpy(gps_raw_int, _MAV_PAYLOAD(msg), 37); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_set_global_origin.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_set_global_origin.h deleted file mode 100644 index cdd1f242a7..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_set_global_origin.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE GPS_SET_GLOBAL_ORIGIN PACKING - -#define MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN 48 - -typedef struct __mavlink_gps_set_global_origin_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - int32_t latitude; ///< global position * 1E7 - int32_t longitude; ///< global position * 1E7 - int32_t altitude; ///< global position * 1000 -} mavlink_gps_set_global_origin_t; - -#define MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN_LEN 14 -#define MAVLINK_MSG_ID_48_LEN 14 - - - -#define MAVLINK_MESSAGE_INFO_GPS_SET_GLOBAL_ORIGIN { \ - "GPS_SET_GLOBAL_ORIGIN", \ - 5, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_gps_set_global_origin_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_gps_set_global_origin_t, target_component) }, \ - { "latitude", NULL, MAVLINK_TYPE_INT32_T, 0, 2, offsetof(mavlink_gps_set_global_origin_t, latitude) }, \ - { "longitude", NULL, MAVLINK_TYPE_INT32_T, 0, 6, offsetof(mavlink_gps_set_global_origin_t, longitude) }, \ - { "altitude", NULL, MAVLINK_TYPE_INT32_T, 0, 10, offsetof(mavlink_gps_set_global_origin_t, altitude) }, \ - } \ -} - - -/** - * @brief Pack a gps_set_global_origin message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param latitude global position * 1E7 - * @param longitude global position * 1E7 - * @param altitude global position * 1000 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_set_global_origin_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, int32_t latitude, int32_t longitude, int32_t altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, latitude); - _mav_put_int32_t(buf, 6, longitude); - _mav_put_int32_t(buf, 10, altitude); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_gps_set_global_origin_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.latitude = latitude; - packet.longitude = longitude; - packet.altitude = altitude; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN; - return mavlink_finalize_message(msg, system_id, component_id, 14); -} - -/** - * @brief Pack a gps_set_global_origin message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param latitude global position * 1E7 - * @param longitude global position * 1E7 - * @param altitude global position * 1000 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_set_global_origin_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,int32_t latitude,int32_t longitude,int32_t altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, latitude); - _mav_put_int32_t(buf, 6, longitude); - _mav_put_int32_t(buf, 10, altitude); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_gps_set_global_origin_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.latitude = latitude; - packet.longitude = longitude; - packet.altitude = altitude; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 14); -} - -/** - * @brief Encode a gps_set_global_origin struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_set_global_origin C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_set_global_origin_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_set_global_origin_t* gps_set_global_origin) -{ - return mavlink_msg_gps_set_global_origin_pack(system_id, component_id, msg, gps_set_global_origin->target_system, gps_set_global_origin->target_component, gps_set_global_origin->latitude, gps_set_global_origin->longitude, gps_set_global_origin->altitude); -} - -/** - * @brief Send a gps_set_global_origin message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param latitude global position * 1E7 - * @param longitude global position * 1E7 - * @param altitude global position * 1000 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_set_global_origin_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, int32_t latitude, int32_t longitude, int32_t altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int32_t(buf, 2, latitude); - _mav_put_int32_t(buf, 6, longitude); - _mav_put_int32_t(buf, 10, altitude); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN, buf, 14); -#else - mavlink_gps_set_global_origin_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.latitude = latitude; - packet.longitude = longitude; - packet.altitude = altitude; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN, (const char *)&packet, 14); -#endif -} - -#endif - -// MESSAGE GPS_SET_GLOBAL_ORIGIN UNPACKING - - -/** - * @brief Get field target_system from gps_set_global_origin message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_gps_set_global_origin_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from gps_set_global_origin message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_gps_set_global_origin_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field latitude from gps_set_global_origin message - * - * @return global position * 1E7 - */ -static inline int32_t mavlink_msg_gps_set_global_origin_get_latitude(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 2); -} - -/** - * @brief Get field longitude from gps_set_global_origin message - * - * @return global position * 1E7 - */ -static inline int32_t mavlink_msg_gps_set_global_origin_get_longitude(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 6); -} - -/** - * @brief Get field altitude from gps_set_global_origin message - * - * @return global position * 1000 - */ -static inline int32_t mavlink_msg_gps_set_global_origin_get_altitude(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 10); -} - -/** - * @brief Decode a gps_set_global_origin message into a struct - * - * @param msg The message to decode - * @param gps_set_global_origin C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_set_global_origin_decode(const mavlink_message_t* msg, mavlink_gps_set_global_origin_t* gps_set_global_origin) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_set_global_origin->target_system = mavlink_msg_gps_set_global_origin_get_target_system(msg); - gps_set_global_origin->target_component = mavlink_msg_gps_set_global_origin_get_target_component(msg); - gps_set_global_origin->latitude = mavlink_msg_gps_set_global_origin_get_latitude(msg); - gps_set_global_origin->longitude = mavlink_msg_gps_set_global_origin_get_longitude(msg); - gps_set_global_origin->altitude = mavlink_msg_gps_set_global_origin_get_altitude(msg); -#else - memcpy(gps_set_global_origin, _MAV_PAYLOAD(msg), 14); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_status.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_status.h deleted file mode 100644 index e13ffe3829..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_gps_status.h +++ /dev/null @@ -1,252 +0,0 @@ -// MESSAGE GPS_STATUS PACKING - -#define MAVLINK_MSG_ID_GPS_STATUS 27 - -typedef struct __mavlink_gps_status_t -{ - uint8_t satellites_visible; ///< Number of satellites visible - int8_t satellite_prn[20]; ///< Global satellite ID - int8_t satellite_used[20]; ///< 0: Satellite not used, 1: used for localization - int8_t satellite_elevation[20]; ///< Elevation (0: right on top of receiver, 90: on the horizon) of satellite - int8_t satellite_azimuth[20]; ///< Direction of satellite, 0: 0 deg, 255: 360 deg. - int8_t satellite_snr[20]; ///< Signal to noise ratio of satellite -} mavlink_gps_status_t; - -#define MAVLINK_MSG_ID_GPS_STATUS_LEN 101 -#define MAVLINK_MSG_ID_27_LEN 101 - -#define MAVLINK_MSG_GPS_STATUS_FIELD_SATELLITE_PRN_LEN 20 -#define MAVLINK_MSG_GPS_STATUS_FIELD_SATELLITE_USED_LEN 20 -#define MAVLINK_MSG_GPS_STATUS_FIELD_SATELLITE_ELEVATION_LEN 20 -#define MAVLINK_MSG_GPS_STATUS_FIELD_SATELLITE_AZIMUTH_LEN 20 -#define MAVLINK_MSG_GPS_STATUS_FIELD_SATELLITE_SNR_LEN 20 - -#define MAVLINK_MESSAGE_INFO_GPS_STATUS { \ - "GPS_STATUS", \ - 6, \ - { { "satellites_visible", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_gps_status_t, satellites_visible) }, \ - { "satellite_prn", NULL, MAVLINK_TYPE_INT8_T, 20, 1, offsetof(mavlink_gps_status_t, satellite_prn) }, \ - { "satellite_used", NULL, MAVLINK_TYPE_INT8_T, 20, 21, offsetof(mavlink_gps_status_t, satellite_used) }, \ - { "satellite_elevation", NULL, MAVLINK_TYPE_INT8_T, 20, 41, offsetof(mavlink_gps_status_t, satellite_elevation) }, \ - { "satellite_azimuth", NULL, MAVLINK_TYPE_INT8_T, 20, 61, offsetof(mavlink_gps_status_t, satellite_azimuth) }, \ - { "satellite_snr", NULL, MAVLINK_TYPE_INT8_T, 20, 81, offsetof(mavlink_gps_status_t, satellite_snr) }, \ - } \ -} - - -/** - * @brief Pack a gps_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param satellites_visible Number of satellites visible - * @param satellite_prn Global satellite ID - * @param satellite_used 0: Satellite not used, 1: used for localization - * @param satellite_elevation Elevation (0: right on top of receiver, 90: on the horizon) of satellite - * @param satellite_azimuth Direction of satellite, 0: 0 deg, 255: 360 deg. - * @param satellite_snr Signal to noise ratio of satellite - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t satellites_visible, const int8_t *satellite_prn, const int8_t *satellite_used, const int8_t *satellite_elevation, const int8_t *satellite_azimuth, const int8_t *satellite_snr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[101]; - _mav_put_uint8_t(buf, 0, satellites_visible); - _mav_put_int8_t_array(buf, 1, satellite_prn, 20); - _mav_put_int8_t_array(buf, 21, satellite_used, 20); - _mav_put_int8_t_array(buf, 41, satellite_elevation, 20); - _mav_put_int8_t_array(buf, 61, satellite_azimuth, 20); - _mav_put_int8_t_array(buf, 81, satellite_snr, 20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 101); -#else - mavlink_gps_status_t packet; - packet.satellites_visible = satellites_visible; - mav_array_memcpy(packet.satellite_prn, satellite_prn, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_used, satellite_used, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_elevation, satellite_elevation, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_azimuth, satellite_azimuth, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_snr, satellite_snr, sizeof(int8_t)*20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 101); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 101); -} - -/** - * @brief Pack a gps_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param satellites_visible Number of satellites visible - * @param satellite_prn Global satellite ID - * @param satellite_used 0: Satellite not used, 1: used for localization - * @param satellite_elevation Elevation (0: right on top of receiver, 90: on the horizon) of satellite - * @param satellite_azimuth Direction of satellite, 0: 0 deg, 255: 360 deg. - * @param satellite_snr Signal to noise ratio of satellite - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t satellites_visible,const int8_t *satellite_prn,const int8_t *satellite_used,const int8_t *satellite_elevation,const int8_t *satellite_azimuth,const int8_t *satellite_snr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[101]; - _mav_put_uint8_t(buf, 0, satellites_visible); - _mav_put_int8_t_array(buf, 1, satellite_prn, 20); - _mav_put_int8_t_array(buf, 21, satellite_used, 20); - _mav_put_int8_t_array(buf, 41, satellite_elevation, 20); - _mav_put_int8_t_array(buf, 61, satellite_azimuth, 20); - _mav_put_int8_t_array(buf, 81, satellite_snr, 20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 101); -#else - mavlink_gps_status_t packet; - packet.satellites_visible = satellites_visible; - mav_array_memcpy(packet.satellite_prn, satellite_prn, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_used, satellite_used, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_elevation, satellite_elevation, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_azimuth, satellite_azimuth, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_snr, satellite_snr, sizeof(int8_t)*20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 101); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 101); -} - -/** - * @brief Encode a gps_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_status_t* gps_status) -{ - return mavlink_msg_gps_status_pack(system_id, component_id, msg, gps_status->satellites_visible, gps_status->satellite_prn, gps_status->satellite_used, gps_status->satellite_elevation, gps_status->satellite_azimuth, gps_status->satellite_snr); -} - -/** - * @brief Send a gps_status message - * @param chan MAVLink channel to send the message - * - * @param satellites_visible Number of satellites visible - * @param satellite_prn Global satellite ID - * @param satellite_used 0: Satellite not used, 1: used for localization - * @param satellite_elevation Elevation (0: right on top of receiver, 90: on the horizon) of satellite - * @param satellite_azimuth Direction of satellite, 0: 0 deg, 255: 360 deg. - * @param satellite_snr Signal to noise ratio of satellite - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_status_send(mavlink_channel_t chan, uint8_t satellites_visible, const int8_t *satellite_prn, const int8_t *satellite_used, const int8_t *satellite_elevation, const int8_t *satellite_azimuth, const int8_t *satellite_snr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[101]; - _mav_put_uint8_t(buf, 0, satellites_visible); - _mav_put_int8_t_array(buf, 1, satellite_prn, 20); - _mav_put_int8_t_array(buf, 21, satellite_used, 20); - _mav_put_int8_t_array(buf, 41, satellite_elevation, 20); - _mav_put_int8_t_array(buf, 61, satellite_azimuth, 20); - _mav_put_int8_t_array(buf, 81, satellite_snr, 20); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_STATUS, buf, 101); -#else - mavlink_gps_status_t packet; - packet.satellites_visible = satellites_visible; - mav_array_memcpy(packet.satellite_prn, satellite_prn, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_used, satellite_used, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_elevation, satellite_elevation, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_azimuth, satellite_azimuth, sizeof(int8_t)*20); - mav_array_memcpy(packet.satellite_snr, satellite_snr, sizeof(int8_t)*20); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_STATUS, (const char *)&packet, 101); -#endif -} - -#endif - -// MESSAGE GPS_STATUS UNPACKING - - -/** - * @brief Get field satellites_visible from gps_status message - * - * @return Number of satellites visible - */ -static inline uint8_t mavlink_msg_gps_status_get_satellites_visible(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field satellite_prn from gps_status message - * - * @return Global satellite ID - */ -static inline uint16_t mavlink_msg_gps_status_get_satellite_prn(const mavlink_message_t* msg, int8_t *satellite_prn) -{ - return _MAV_RETURN_int8_t_array(msg, satellite_prn, 20, 1); -} - -/** - * @brief Get field satellite_used from gps_status message - * - * @return 0: Satellite not used, 1: used for localization - */ -static inline uint16_t mavlink_msg_gps_status_get_satellite_used(const mavlink_message_t* msg, int8_t *satellite_used) -{ - return _MAV_RETURN_int8_t_array(msg, satellite_used, 20, 21); -} - -/** - * @brief Get field satellite_elevation from gps_status message - * - * @return Elevation (0: right on top of receiver, 90: on the horizon) of satellite - */ -static inline uint16_t mavlink_msg_gps_status_get_satellite_elevation(const mavlink_message_t* msg, int8_t *satellite_elevation) -{ - return _MAV_RETURN_int8_t_array(msg, satellite_elevation, 20, 41); -} - -/** - * @brief Get field satellite_azimuth from gps_status message - * - * @return Direction of satellite, 0: 0 deg, 255: 360 deg. - */ -static inline uint16_t mavlink_msg_gps_status_get_satellite_azimuth(const mavlink_message_t* msg, int8_t *satellite_azimuth) -{ - return _MAV_RETURN_int8_t_array(msg, satellite_azimuth, 20, 61); -} - -/** - * @brief Get field satellite_snr from gps_status message - * - * @return Signal to noise ratio of satellite - */ -static inline uint16_t mavlink_msg_gps_status_get_satellite_snr(const mavlink_message_t* msg, int8_t *satellite_snr) -{ - return _MAV_RETURN_int8_t_array(msg, satellite_snr, 20, 81); -} - -/** - * @brief Decode a gps_status message into a struct - * - * @param msg The message to decode - * @param gps_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_status_decode(const mavlink_message_t* msg, mavlink_gps_status_t* gps_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_status->satellites_visible = mavlink_msg_gps_status_get_satellites_visible(msg); - mavlink_msg_gps_status_get_satellite_prn(msg, gps_status->satellite_prn); - mavlink_msg_gps_status_get_satellite_used(msg, gps_status->satellite_used); - mavlink_msg_gps_status_get_satellite_elevation(msg, gps_status->satellite_elevation); - mavlink_msg_gps_status_get_satellite_azimuth(msg, gps_status->satellite_azimuth); - mavlink_msg_gps_status_get_satellite_snr(msg, gps_status->satellite_snr); -#else - memcpy(gps_status, _MAV_PAYLOAD(msg), 101); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_heartbeat.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_heartbeat.h deleted file mode 100644 index aad90d29f3..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_heartbeat.h +++ /dev/null @@ -1,185 +0,0 @@ -// MESSAGE HEARTBEAT PACKING - -#define MAVLINK_MSG_ID_HEARTBEAT 0 - -typedef struct __mavlink_heartbeat_t -{ - uint8_t type; ///< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - uint8_t autopilot; ///< Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - uint8_t mavlink_version; ///< MAVLink version -} mavlink_heartbeat_t; - -#define MAVLINK_MSG_ID_HEARTBEAT_LEN 3 -#define MAVLINK_MSG_ID_0_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_HEARTBEAT { \ - "HEARTBEAT", \ - 3, \ - { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_heartbeat_t, type) }, \ - { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_heartbeat_t, autopilot) }, \ - { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_heartbeat_t, mavlink_version) }, \ - } \ -} - - -/** - * @brief Pack a heartbeat message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, uint8_t autopilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, autopilot); - _mav_put_uint8_t(buf, 2, 2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_heartbeat_t packet; - packet.type = type; - packet.autopilot = autopilot; - packet.mavlink_version = 2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a heartbeat message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,uint8_t autopilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, autopilot); - _mav_put_uint8_t(buf, 2, 2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_heartbeat_t packet; - packet.type = type; - packet.autopilot = autopilot; - packet.mavlink_version = 2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a heartbeat struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param heartbeat C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat) -{ - return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot); -} - -/** - * @brief Send a heartbeat message - * @param chan MAVLink channel to send the message - * - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_heartbeat_send(mavlink_channel_t chan, uint8_t type, uint8_t autopilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, autopilot); - _mav_put_uint8_t(buf, 2, 2); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, 3); -#else - mavlink_heartbeat_t packet; - packet.type = type; - packet.autopilot = autopilot; - packet.mavlink_version = 2; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE HEARTBEAT UNPACKING - - -/** - * @brief Get field type from heartbeat message - * - * @return Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - */ -static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field autopilot from heartbeat message - * - * @return Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - */ -static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field mavlink_version from heartbeat message - * - * @return MAVLink version - */ -static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a heartbeat message into a struct - * - * @param msg The message to decode - * @param heartbeat C-struct to decode the message contents into - */ -static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat) -{ -#if MAVLINK_NEED_BYTE_SWAP - heartbeat->type = mavlink_msg_heartbeat_get_type(msg); - heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg); - heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg); -#else - memcpy(heartbeat, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_hil_controls.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_hil_controls.h deleted file mode 100644 index 231c6f216b..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_hil_controls.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE HIL_CONTROLS PACKING - -#define MAVLINK_MSG_ID_HIL_CONTROLS 68 - -typedef struct __mavlink_hil_controls_t -{ - uint64_t time_us; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - float roll_ailerons; ///< Control output -3 .. 1 - float pitch_elevator; ///< Control output -1 .. 1 - float yaw_rudder; ///< Control output -1 .. 1 - float throttle; ///< Throttle 0 .. 1 - uint8_t mode; ///< System mode (MAV_MODE) - uint8_t nav_mode; ///< Navigation mode (MAV_NAV_MODE) -} mavlink_hil_controls_t; - -#define MAVLINK_MSG_ID_HIL_CONTROLS_LEN 26 -#define MAVLINK_MSG_ID_68_LEN 26 - - - -#define MAVLINK_MESSAGE_INFO_HIL_CONTROLS { \ - "HIL_CONTROLS", \ - 7, \ - { { "time_us", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_hil_controls_t, time_us) }, \ - { "roll_ailerons", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_hil_controls_t, roll_ailerons) }, \ - { "pitch_elevator", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_hil_controls_t, pitch_elevator) }, \ - { "yaw_rudder", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_hil_controls_t, yaw_rudder) }, \ - { "throttle", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_hil_controls_t, throttle) }, \ - { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 24, offsetof(mavlink_hil_controls_t, mode) }, \ - { "nav_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 25, offsetof(mavlink_hil_controls_t, nav_mode) }, \ - } \ -} - - -/** - * @brief Pack a hil_controls message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param time_us Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll_ailerons Control output -3 .. 1 - * @param pitch_elevator Control output -1 .. 1 - * @param yaw_rudder Control output -1 .. 1 - * @param throttle Throttle 0 .. 1 - * @param mode System mode (MAV_MODE) - * @param nav_mode Navigation mode (MAV_NAV_MODE) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_hil_controls_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t time_us, float roll_ailerons, float pitch_elevator, float yaw_rudder, float throttle, uint8_t mode, uint8_t nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll_ailerons); - _mav_put_float(buf, 12, pitch_elevator); - _mav_put_float(buf, 16, yaw_rudder); - _mav_put_float(buf, 20, throttle); - _mav_put_uint8_t(buf, 24, mode); - _mav_put_uint8_t(buf, 25, nav_mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_hil_controls_t packet; - packet.time_us = time_us; - packet.roll_ailerons = roll_ailerons; - packet.pitch_elevator = pitch_elevator; - packet.yaw_rudder = yaw_rudder; - packet.throttle = throttle; - packet.mode = mode; - packet.nav_mode = nav_mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_HIL_CONTROLS; - return mavlink_finalize_message(msg, system_id, component_id, 26); -} - -/** - * @brief Pack a hil_controls message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param time_us Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll_ailerons Control output -3 .. 1 - * @param pitch_elevator Control output -1 .. 1 - * @param yaw_rudder Control output -1 .. 1 - * @param throttle Throttle 0 .. 1 - * @param mode System mode (MAV_MODE) - * @param nav_mode Navigation mode (MAV_NAV_MODE) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_hil_controls_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t time_us,float roll_ailerons,float pitch_elevator,float yaw_rudder,float throttle,uint8_t mode,uint8_t nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll_ailerons); - _mav_put_float(buf, 12, pitch_elevator); - _mav_put_float(buf, 16, yaw_rudder); - _mav_put_float(buf, 20, throttle); - _mav_put_uint8_t(buf, 24, mode); - _mav_put_uint8_t(buf, 25, nav_mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_hil_controls_t packet; - packet.time_us = time_us; - packet.roll_ailerons = roll_ailerons; - packet.pitch_elevator = pitch_elevator; - packet.yaw_rudder = yaw_rudder; - packet.throttle = throttle; - packet.mode = mode; - packet.nav_mode = nav_mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_HIL_CONTROLS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 26); -} - -/** - * @brief Encode a hil_controls struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param hil_controls C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_hil_controls_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_hil_controls_t* hil_controls) -{ - return mavlink_msg_hil_controls_pack(system_id, component_id, msg, hil_controls->time_us, hil_controls->roll_ailerons, hil_controls->pitch_elevator, hil_controls->yaw_rudder, hil_controls->throttle, hil_controls->mode, hil_controls->nav_mode); -} - -/** - * @brief Send a hil_controls message - * @param chan MAVLink channel to send the message - * - * @param time_us Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll_ailerons Control output -3 .. 1 - * @param pitch_elevator Control output -1 .. 1 - * @param yaw_rudder Control output -1 .. 1 - * @param throttle Throttle 0 .. 1 - * @param mode System mode (MAV_MODE) - * @param nav_mode Navigation mode (MAV_NAV_MODE) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_hil_controls_send(mavlink_channel_t chan, uint64_t time_us, float roll_ailerons, float pitch_elevator, float yaw_rudder, float throttle, uint8_t mode, uint8_t nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll_ailerons); - _mav_put_float(buf, 12, pitch_elevator); - _mav_put_float(buf, 16, yaw_rudder); - _mav_put_float(buf, 20, throttle); - _mav_put_uint8_t(buf, 24, mode); - _mav_put_uint8_t(buf, 25, nav_mode); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HIL_CONTROLS, buf, 26); -#else - mavlink_hil_controls_t packet; - packet.time_us = time_us; - packet.roll_ailerons = roll_ailerons; - packet.pitch_elevator = pitch_elevator; - packet.yaw_rudder = yaw_rudder; - packet.throttle = throttle; - packet.mode = mode; - packet.nav_mode = nav_mode; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HIL_CONTROLS, (const char *)&packet, 26); -#endif -} - -#endif - -// MESSAGE HIL_CONTROLS UNPACKING - - -/** - * @brief Get field time_us from hil_controls message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_hil_controls_get_time_us(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field roll_ailerons from hil_controls message - * - * @return Control output -3 .. 1 - */ -static inline float mavlink_msg_hil_controls_get_roll_ailerons(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field pitch_elevator from hil_controls message - * - * @return Control output -1 .. 1 - */ -static inline float mavlink_msg_hil_controls_get_pitch_elevator(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yaw_rudder from hil_controls message - * - * @return Control output -1 .. 1 - */ -static inline float mavlink_msg_hil_controls_get_yaw_rudder(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field throttle from hil_controls message - * - * @return Throttle 0 .. 1 - */ -static inline float mavlink_msg_hil_controls_get_throttle(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field mode from hil_controls message - * - * @return System mode (MAV_MODE) - */ -static inline uint8_t mavlink_msg_hil_controls_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 24); -} - -/** - * @brief Get field nav_mode from hil_controls message - * - * @return Navigation mode (MAV_NAV_MODE) - */ -static inline uint8_t mavlink_msg_hil_controls_get_nav_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 25); -} - -/** - * @brief Decode a hil_controls message into a struct - * - * @param msg The message to decode - * @param hil_controls C-struct to decode the message contents into - */ -static inline void mavlink_msg_hil_controls_decode(const mavlink_message_t* msg, mavlink_hil_controls_t* hil_controls) -{ -#if MAVLINK_NEED_BYTE_SWAP - hil_controls->time_us = mavlink_msg_hil_controls_get_time_us(msg); - hil_controls->roll_ailerons = mavlink_msg_hil_controls_get_roll_ailerons(msg); - hil_controls->pitch_elevator = mavlink_msg_hil_controls_get_pitch_elevator(msg); - hil_controls->yaw_rudder = mavlink_msg_hil_controls_get_yaw_rudder(msg); - hil_controls->throttle = mavlink_msg_hil_controls_get_throttle(msg); - hil_controls->mode = mavlink_msg_hil_controls_get_mode(msg); - hil_controls->nav_mode = mavlink_msg_hil_controls_get_nav_mode(msg); -#else - memcpy(hil_controls, _MAV_PAYLOAD(msg), 26); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_hil_state.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_hil_state.h deleted file mode 100644 index 6692c22580..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_hil_state.h +++ /dev/null @@ -1,474 +0,0 @@ -// MESSAGE HIL_STATE PACKING - -#define MAVLINK_MSG_ID_HIL_STATE 67 - -typedef struct __mavlink_hil_state_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - float roll; ///< Roll angle (rad) - float pitch; ///< Pitch angle (rad) - float yaw; ///< Yaw angle (rad) - float rollspeed; ///< Roll angular speed (rad/s) - float pitchspeed; ///< Pitch angular speed (rad/s) - float yawspeed; ///< Yaw angular speed (rad/s) - int32_t lat; ///< Latitude, expressed as * 1E7 - int32_t lon; ///< Longitude, expressed as * 1E7 - int32_t alt; ///< Altitude in meters, expressed as * 1000 (millimeters) - int16_t vx; ///< Ground X Speed (Latitude), expressed as m/s * 100 - int16_t vy; ///< Ground Y Speed (Longitude), expressed as m/s * 100 - int16_t vz; ///< Ground Z Speed (Altitude), expressed as m/s * 100 - int16_t xacc; ///< X acceleration (mg) - int16_t yacc; ///< Y acceleration (mg) - int16_t zacc; ///< Z acceleration (mg) -} mavlink_hil_state_t; - -#define MAVLINK_MSG_ID_HIL_STATE_LEN 56 -#define MAVLINK_MSG_ID_67_LEN 56 - - - -#define MAVLINK_MESSAGE_INFO_HIL_STATE { \ - "HIL_STATE", \ - 16, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_hil_state_t, usec) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_hil_state_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_hil_state_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_hil_state_t, yaw) }, \ - { "rollspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_hil_state_t, rollspeed) }, \ - { "pitchspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_hil_state_t, pitchspeed) }, \ - { "yawspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_hil_state_t, yawspeed) }, \ - { "lat", NULL, MAVLINK_TYPE_INT32_T, 0, 32, offsetof(mavlink_hil_state_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_INT32_T, 0, 36, offsetof(mavlink_hil_state_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_INT32_T, 0, 40, offsetof(mavlink_hil_state_t, alt) }, \ - { "vx", NULL, MAVLINK_TYPE_INT16_T, 0, 44, offsetof(mavlink_hil_state_t, vx) }, \ - { "vy", NULL, MAVLINK_TYPE_INT16_T, 0, 46, offsetof(mavlink_hil_state_t, vy) }, \ - { "vz", NULL, MAVLINK_TYPE_INT16_T, 0, 48, offsetof(mavlink_hil_state_t, vz) }, \ - { "xacc", NULL, MAVLINK_TYPE_INT16_T, 0, 50, offsetof(mavlink_hil_state_t, xacc) }, \ - { "yacc", NULL, MAVLINK_TYPE_INT16_T, 0, 52, offsetof(mavlink_hil_state_t, yacc) }, \ - { "zacc", NULL, MAVLINK_TYPE_INT16_T, 0, 54, offsetof(mavlink_hil_state_t, zacc) }, \ - } \ -} - - -/** - * @brief Pack a hil_state message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param rollspeed Roll angular speed (rad/s) - * @param pitchspeed Pitch angular speed (rad/s) - * @param yawspeed Yaw angular speed (rad/s) - * @param lat Latitude, expressed as * 1E7 - * @param lon Longitude, expressed as * 1E7 - * @param alt Altitude in meters, expressed as * 1000 (millimeters) - * @param vx Ground X Speed (Latitude), expressed as m/s * 100 - * @param vy Ground Y Speed (Longitude), expressed as m/s * 100 - * @param vz Ground Z Speed (Altitude), expressed as m/s * 100 - * @param xacc X acceleration (mg) - * @param yacc Y acceleration (mg) - * @param zacc Z acceleration (mg) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_hil_state_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float roll, float pitch, float yaw, float rollspeed, float pitchspeed, float yawspeed, int32_t lat, int32_t lon, int32_t alt, int16_t vx, int16_t vy, int16_t vz, int16_t xacc, int16_t yacc, int16_t zacc) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[56]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, rollspeed); - _mav_put_float(buf, 24, pitchspeed); - _mav_put_float(buf, 28, yawspeed); - _mav_put_int32_t(buf, 32, lat); - _mav_put_int32_t(buf, 36, lon); - _mav_put_int32_t(buf, 40, alt); - _mav_put_int16_t(buf, 44, vx); - _mav_put_int16_t(buf, 46, vy); - _mav_put_int16_t(buf, 48, vz); - _mav_put_int16_t(buf, 50, xacc); - _mav_put_int16_t(buf, 52, yacc); - _mav_put_int16_t(buf, 54, zacc); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 56); -#else - mavlink_hil_state_t packet; - packet.usec = usec; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.rollspeed = rollspeed; - packet.pitchspeed = pitchspeed; - packet.yawspeed = yawspeed; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 56); -#endif - - msg->msgid = MAVLINK_MSG_ID_HIL_STATE; - return mavlink_finalize_message(msg, system_id, component_id, 56); -} - -/** - * @brief Pack a hil_state message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param rollspeed Roll angular speed (rad/s) - * @param pitchspeed Pitch angular speed (rad/s) - * @param yawspeed Yaw angular speed (rad/s) - * @param lat Latitude, expressed as * 1E7 - * @param lon Longitude, expressed as * 1E7 - * @param alt Altitude in meters, expressed as * 1000 (millimeters) - * @param vx Ground X Speed (Latitude), expressed as m/s * 100 - * @param vy Ground Y Speed (Longitude), expressed as m/s * 100 - * @param vz Ground Z Speed (Altitude), expressed as m/s * 100 - * @param xacc X acceleration (mg) - * @param yacc Y acceleration (mg) - * @param zacc Z acceleration (mg) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_hil_state_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float roll,float pitch,float yaw,float rollspeed,float pitchspeed,float yawspeed,int32_t lat,int32_t lon,int32_t alt,int16_t vx,int16_t vy,int16_t vz,int16_t xacc,int16_t yacc,int16_t zacc) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[56]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, rollspeed); - _mav_put_float(buf, 24, pitchspeed); - _mav_put_float(buf, 28, yawspeed); - _mav_put_int32_t(buf, 32, lat); - _mav_put_int32_t(buf, 36, lon); - _mav_put_int32_t(buf, 40, alt); - _mav_put_int16_t(buf, 44, vx); - _mav_put_int16_t(buf, 46, vy); - _mav_put_int16_t(buf, 48, vz); - _mav_put_int16_t(buf, 50, xacc); - _mav_put_int16_t(buf, 52, yacc); - _mav_put_int16_t(buf, 54, zacc); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 56); -#else - mavlink_hil_state_t packet; - packet.usec = usec; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.rollspeed = rollspeed; - packet.pitchspeed = pitchspeed; - packet.yawspeed = yawspeed; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 56); -#endif - - msg->msgid = MAVLINK_MSG_ID_HIL_STATE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 56); -} - -/** - * @brief Encode a hil_state struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param hil_state C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_hil_state_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_hil_state_t* hil_state) -{ - return mavlink_msg_hil_state_pack(system_id, component_id, msg, hil_state->usec, hil_state->roll, hil_state->pitch, hil_state->yaw, hil_state->rollspeed, hil_state->pitchspeed, hil_state->yawspeed, hil_state->lat, hil_state->lon, hil_state->alt, hil_state->vx, hil_state->vy, hil_state->vz, hil_state->xacc, hil_state->yacc, hil_state->zacc); -} - -/** - * @brief Send a hil_state message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) - * @param rollspeed Roll angular speed (rad/s) - * @param pitchspeed Pitch angular speed (rad/s) - * @param yawspeed Yaw angular speed (rad/s) - * @param lat Latitude, expressed as * 1E7 - * @param lon Longitude, expressed as * 1E7 - * @param alt Altitude in meters, expressed as * 1000 (millimeters) - * @param vx Ground X Speed (Latitude), expressed as m/s * 100 - * @param vy Ground Y Speed (Longitude), expressed as m/s * 100 - * @param vz Ground Z Speed (Altitude), expressed as m/s * 100 - * @param xacc X acceleration (mg) - * @param yacc Y acceleration (mg) - * @param zacc Z acceleration (mg) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_hil_state_send(mavlink_channel_t chan, uint64_t usec, float roll, float pitch, float yaw, float rollspeed, float pitchspeed, float yawspeed, int32_t lat, int32_t lon, int32_t alt, int16_t vx, int16_t vy, int16_t vz, int16_t xacc, int16_t yacc, int16_t zacc) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[56]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, rollspeed); - _mav_put_float(buf, 24, pitchspeed); - _mav_put_float(buf, 28, yawspeed); - _mav_put_int32_t(buf, 32, lat); - _mav_put_int32_t(buf, 36, lon); - _mav_put_int32_t(buf, 40, alt); - _mav_put_int16_t(buf, 44, vx); - _mav_put_int16_t(buf, 46, vy); - _mav_put_int16_t(buf, 48, vz); - _mav_put_int16_t(buf, 50, xacc); - _mav_put_int16_t(buf, 52, yacc); - _mav_put_int16_t(buf, 54, zacc); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HIL_STATE, buf, 56); -#else - mavlink_hil_state_t packet; - packet.usec = usec; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.rollspeed = rollspeed; - packet.pitchspeed = pitchspeed; - packet.yawspeed = yawspeed; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HIL_STATE, (const char *)&packet, 56); -#endif -} - -#endif - -// MESSAGE HIL_STATE UNPACKING - - -/** - * @brief Get field usec from hil_state message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_hil_state_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field roll from hil_state message - * - * @return Roll angle (rad) - */ -static inline float mavlink_msg_hil_state_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field pitch from hil_state message - * - * @return Pitch angle (rad) - */ -static inline float mavlink_msg_hil_state_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yaw from hil_state message - * - * @return Yaw angle (rad) - */ -static inline float mavlink_msg_hil_state_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field rollspeed from hil_state message - * - * @return Roll angular speed (rad/s) - */ -static inline float mavlink_msg_hil_state_get_rollspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field pitchspeed from hil_state message - * - * @return Pitch angular speed (rad/s) - */ -static inline float mavlink_msg_hil_state_get_pitchspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field yawspeed from hil_state message - * - * @return Yaw angular speed (rad/s) - */ -static inline float mavlink_msg_hil_state_get_yawspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Get field lat from hil_state message - * - * @return Latitude, expressed as * 1E7 - */ -static inline int32_t mavlink_msg_hil_state_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 32); -} - -/** - * @brief Get field lon from hil_state message - * - * @return Longitude, expressed as * 1E7 - */ -static inline int32_t mavlink_msg_hil_state_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 36); -} - -/** - * @brief Get field alt from hil_state message - * - * @return Altitude in meters, expressed as * 1000 (millimeters) - */ -static inline int32_t mavlink_msg_hil_state_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 40); -} - -/** - * @brief Get field vx from hil_state message - * - * @return Ground X Speed (Latitude), expressed as m/s * 100 - */ -static inline int16_t mavlink_msg_hil_state_get_vx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 44); -} - -/** - * @brief Get field vy from hil_state message - * - * @return Ground Y Speed (Longitude), expressed as m/s * 100 - */ -static inline int16_t mavlink_msg_hil_state_get_vy(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 46); -} - -/** - * @brief Get field vz from hil_state message - * - * @return Ground Z Speed (Altitude), expressed as m/s * 100 - */ -static inline int16_t mavlink_msg_hil_state_get_vz(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 48); -} - -/** - * @brief Get field xacc from hil_state message - * - * @return X acceleration (mg) - */ -static inline int16_t mavlink_msg_hil_state_get_xacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 50); -} - -/** - * @brief Get field yacc from hil_state message - * - * @return Y acceleration (mg) - */ -static inline int16_t mavlink_msg_hil_state_get_yacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 52); -} - -/** - * @brief Get field zacc from hil_state message - * - * @return Z acceleration (mg) - */ -static inline int16_t mavlink_msg_hil_state_get_zacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 54); -} - -/** - * @brief Decode a hil_state message into a struct - * - * @param msg The message to decode - * @param hil_state C-struct to decode the message contents into - */ -static inline void mavlink_msg_hil_state_decode(const mavlink_message_t* msg, mavlink_hil_state_t* hil_state) -{ -#if MAVLINK_NEED_BYTE_SWAP - hil_state->usec = mavlink_msg_hil_state_get_usec(msg); - hil_state->roll = mavlink_msg_hil_state_get_roll(msg); - hil_state->pitch = mavlink_msg_hil_state_get_pitch(msg); - hil_state->yaw = mavlink_msg_hil_state_get_yaw(msg); - hil_state->rollspeed = mavlink_msg_hil_state_get_rollspeed(msg); - hil_state->pitchspeed = mavlink_msg_hil_state_get_pitchspeed(msg); - hil_state->yawspeed = mavlink_msg_hil_state_get_yawspeed(msg); - hil_state->lat = mavlink_msg_hil_state_get_lat(msg); - hil_state->lon = mavlink_msg_hil_state_get_lon(msg); - hil_state->alt = mavlink_msg_hil_state_get_alt(msg); - hil_state->vx = mavlink_msg_hil_state_get_vx(msg); - hil_state->vy = mavlink_msg_hil_state_get_vy(msg); - hil_state->vz = mavlink_msg_hil_state_get_vz(msg); - hil_state->xacc = mavlink_msg_hil_state_get_xacc(msg); - hil_state->yacc = mavlink_msg_hil_state_get_yacc(msg); - hil_state->zacc = mavlink_msg_hil_state_get_zacc(msg); -#else - memcpy(hil_state, _MAV_PAYLOAD(msg), 56); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position.h deleted file mode 100644 index 121fb3af64..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE LOCAL_POSITION PACKING - -#define MAVLINK_MSG_ID_LOCAL_POSITION 31 - -typedef struct __mavlink_local_position_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - float x; ///< X Position - float y; ///< Y Position - float z; ///< Z Position - float vx; ///< X Speed - float vy; ///< Y Speed - float vz; ///< Z Speed -} mavlink_local_position_t; - -#define MAVLINK_MSG_ID_LOCAL_POSITION_LEN 32 -#define MAVLINK_MSG_ID_31_LEN 32 - - - -#define MAVLINK_MESSAGE_INFO_LOCAL_POSITION { \ - "LOCAL_POSITION", \ - 7, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_local_position_t, usec) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_local_position_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_local_position_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_local_position_t, z) }, \ - { "vx", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_local_position_t, vx) }, \ - { "vy", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_local_position_t, vy) }, \ - { "vz", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_local_position_t, vz) }, \ - } \ -} - - -/** - * @brief Pack a local_position message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param x X Position - * @param y Y Position - * @param z Z Position - * @param vx X Speed - * @param vy Y Speed - * @param vz Z Speed - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_local_position_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float x, float y, float z, float vx, float vy, float vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, vx); - _mav_put_float(buf, 24, vy); - _mav_put_float(buf, 28, vz); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_local_position_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_LOCAL_POSITION; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a local_position message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param x X Position - * @param y Y Position - * @param z Z Position - * @param vx X Speed - * @param vy Y Speed - * @param vz Z Speed - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_local_position_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float x,float y,float z,float vx,float vy,float vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, vx); - _mav_put_float(buf, 24, vy); - _mav_put_float(buf, 28, vz); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_local_position_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_LOCAL_POSITION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a local_position struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param local_position C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_local_position_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_local_position_t* local_position) -{ - return mavlink_msg_local_position_pack(system_id, component_id, msg, local_position->usec, local_position->x, local_position->y, local_position->z, local_position->vx, local_position->vy, local_position->vz); -} - -/** - * @brief Send a local_position message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param x X Position - * @param y Y Position - * @param z Z Position - * @param vx X Speed - * @param vy Y Speed - * @param vz Z Speed - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_local_position_send(mavlink_channel_t chan, uint64_t usec, float x, float y, float z, float vx, float vy, float vz) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, vx); - _mav_put_float(buf, 24, vy); - _mav_put_float(buf, 28, vz); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOCAL_POSITION, buf, 32); -#else - mavlink_local_position_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.vx = vx; - packet.vy = vy; - packet.vz = vz; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOCAL_POSITION, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE LOCAL_POSITION UNPACKING - - -/** - * @brief Get field usec from local_position message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_local_position_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field x from local_position message - * - * @return X Position - */ -static inline float mavlink_msg_local_position_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field y from local_position message - * - * @return Y Position - */ -static inline float mavlink_msg_local_position_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field z from local_position message - * - * @return Z Position - */ -static inline float mavlink_msg_local_position_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field vx from local_position message - * - * @return X Speed - */ -static inline float mavlink_msg_local_position_get_vx(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field vy from local_position message - * - * @return Y Speed - */ -static inline float mavlink_msg_local_position_get_vy(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field vz from local_position message - * - * @return Z Speed - */ -static inline float mavlink_msg_local_position_get_vz(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a local_position message into a struct - * - * @param msg The message to decode - * @param local_position C-struct to decode the message contents into - */ -static inline void mavlink_msg_local_position_decode(const mavlink_message_t* msg, mavlink_local_position_t* local_position) -{ -#if MAVLINK_NEED_BYTE_SWAP - local_position->usec = mavlink_msg_local_position_get_usec(msg); - local_position->x = mavlink_msg_local_position_get_x(msg); - local_position->y = mavlink_msg_local_position_get_y(msg); - local_position->z = mavlink_msg_local_position_get_z(msg); - local_position->vx = mavlink_msg_local_position_get_vx(msg); - local_position->vy = mavlink_msg_local_position_get_vy(msg); - local_position->vz = mavlink_msg_local_position_get_vz(msg); -#else - memcpy(local_position, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position_setpoint.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position_setpoint.h deleted file mode 100644 index 2e6178d96e..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position_setpoint.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE LOCAL_POSITION_SETPOINT PACKING - -#define MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT 51 - -typedef struct __mavlink_local_position_setpoint_t -{ - float x; ///< x position - float y; ///< y position - float z; ///< z position - float yaw; ///< Desired yaw angle -} mavlink_local_position_setpoint_t; - -#define MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_LEN 16 -#define MAVLINK_MSG_ID_51_LEN 16 - - - -#define MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT { \ - "LOCAL_POSITION_SETPOINT", \ - 4, \ - { { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_local_position_setpoint_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_local_position_setpoint_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_local_position_setpoint_t, z) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_local_position_setpoint_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a local_position_setpoint message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param x x position - * @param y y position - * @param z z position - * @param yaw Desired yaw angle - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_local_position_setpoint_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_float(buf, 12, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_local_position_setpoint_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT; - return mavlink_finalize_message(msg, system_id, component_id, 16); -} - -/** - * @brief Pack a local_position_setpoint message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param x x position - * @param y y position - * @param z z position - * @param yaw Desired yaw angle - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_local_position_setpoint_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float x,float y,float z,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_float(buf, 12, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_local_position_setpoint_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 16); -} - -/** - * @brief Encode a local_position_setpoint struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param local_position_setpoint C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_local_position_setpoint_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_local_position_setpoint_t* local_position_setpoint) -{ - return mavlink_msg_local_position_setpoint_pack(system_id, component_id, msg, local_position_setpoint->x, local_position_setpoint->y, local_position_setpoint->z, local_position_setpoint->yaw); -} - -/** - * @brief Send a local_position_setpoint message - * @param chan MAVLink channel to send the message - * - * @param x x position - * @param y y position - * @param z z position - * @param yaw Desired yaw angle - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_local_position_setpoint_send(mavlink_channel_t chan, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_float(buf, 12, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT, buf, 16); -#else - mavlink_local_position_setpoint_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT, (const char *)&packet, 16); -#endif -} - -#endif - -// MESSAGE LOCAL_POSITION_SETPOINT UNPACKING - - -/** - * @brief Get field x from local_position_setpoint message - * - * @return x position - */ -static inline float mavlink_msg_local_position_setpoint_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field y from local_position_setpoint message - * - * @return y position - */ -static inline float mavlink_msg_local_position_setpoint_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field z from local_position_setpoint message - * - * @return z position - */ -static inline float mavlink_msg_local_position_setpoint_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field yaw from local_position_setpoint message - * - * @return Desired yaw angle - */ -static inline float mavlink_msg_local_position_setpoint_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Decode a local_position_setpoint message into a struct - * - * @param msg The message to decode - * @param local_position_setpoint C-struct to decode the message contents into - */ -static inline void mavlink_msg_local_position_setpoint_decode(const mavlink_message_t* msg, mavlink_local_position_setpoint_t* local_position_setpoint) -{ -#if MAVLINK_NEED_BYTE_SWAP - local_position_setpoint->x = mavlink_msg_local_position_setpoint_get_x(msg); - local_position_setpoint->y = mavlink_msg_local_position_setpoint_get_y(msg); - local_position_setpoint->z = mavlink_msg_local_position_setpoint_get_z(msg); - local_position_setpoint->yaw = mavlink_msg_local_position_setpoint_get_yaw(msg); -#else - memcpy(local_position_setpoint, _MAV_PAYLOAD(msg), 16); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position_setpoint_set.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position_setpoint_set.h deleted file mode 100644 index e676c28329..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_local_position_setpoint_set.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE LOCAL_POSITION_SETPOINT_SET PACKING - -#define MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET 50 - -typedef struct __mavlink_local_position_setpoint_set_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - float x; ///< x position - float y; ///< y position - float z; ///< z position - float yaw; ///< Desired yaw angle -} mavlink_local_position_setpoint_set_t; - -#define MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET_LEN 18 -#define MAVLINK_MSG_ID_50_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT_SET { \ - "LOCAL_POSITION_SETPOINT_SET", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_local_position_setpoint_set_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_local_position_setpoint_set_t, target_component) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 2, offsetof(mavlink_local_position_setpoint_set_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_local_position_setpoint_set_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_local_position_setpoint_set_t, z) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_local_position_setpoint_set_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a local_position_setpoint_set message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param x x position - * @param y y position - * @param z z position - * @param yaw Desired yaw angle - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_local_position_setpoint_set_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_local_position_setpoint_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a local_position_setpoint_set message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param x x position - * @param y y position - * @param z z position - * @param yaw Desired yaw angle - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_local_position_setpoint_set_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,float x,float y,float z,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_local_position_setpoint_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a local_position_setpoint_set struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param local_position_setpoint_set C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_local_position_setpoint_set_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_local_position_setpoint_set_t* local_position_setpoint_set) -{ - return mavlink_msg_local_position_setpoint_set_pack(system_id, component_id, msg, local_position_setpoint_set->target_system, local_position_setpoint_set->target_component, local_position_setpoint_set->x, local_position_setpoint_set->y, local_position_setpoint_set->z, local_position_setpoint_set->yaw); -} - -/** - * @brief Send a local_position_setpoint_set message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param x x position - * @param y y position - * @param z z position - * @param yaw Desired yaw angle - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_local_position_setpoint_set_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET, buf, 18); -#else - mavlink_local_position_setpoint_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE LOCAL_POSITION_SETPOINT_SET UNPACKING - - -/** - * @brief Get field target_system from local_position_setpoint_set message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_local_position_setpoint_set_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from local_position_setpoint_set message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_local_position_setpoint_set_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field x from local_position_setpoint_set message - * - * @return x position - */ -static inline float mavlink_msg_local_position_setpoint_set_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 2); -} - -/** - * @brief Get field y from local_position_setpoint_set message - * - * @return y position - */ -static inline float mavlink_msg_local_position_setpoint_set_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field z from local_position_setpoint_set message - * - * @return z position - */ -static inline float mavlink_msg_local_position_setpoint_set_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Get field yaw from local_position_setpoint_set message - * - * @return Desired yaw angle - */ -static inline float mavlink_msg_local_position_setpoint_set_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Decode a local_position_setpoint_set message into a struct - * - * @param msg The message to decode - * @param local_position_setpoint_set C-struct to decode the message contents into - */ -static inline void mavlink_msg_local_position_setpoint_set_decode(const mavlink_message_t* msg, mavlink_local_position_setpoint_set_t* local_position_setpoint_set) -{ -#if MAVLINK_NEED_BYTE_SWAP - local_position_setpoint_set->target_system = mavlink_msg_local_position_setpoint_set_get_target_system(msg); - local_position_setpoint_set->target_component = mavlink_msg_local_position_setpoint_set_get_target_component(msg); - local_position_setpoint_set->x = mavlink_msg_local_position_setpoint_set_get_x(msg); - local_position_setpoint_set->y = mavlink_msg_local_position_setpoint_set_get_y(msg); - local_position_setpoint_set->z = mavlink_msg_local_position_setpoint_set_get_z(msg); - local_position_setpoint_set->yaw = mavlink_msg_local_position_setpoint_set_get_yaw(msg); -#else - memcpy(local_position_setpoint_set, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_manual_control.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_manual_control.h deleted file mode 100644 index 26b70ce4ae..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_manual_control.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE MANUAL_CONTROL PACKING - -#define MAVLINK_MSG_ID_MANUAL_CONTROL 69 - -typedef struct __mavlink_manual_control_t -{ - uint8_t target; ///< The system to be controlled - float roll; ///< roll - float pitch; ///< pitch - float yaw; ///< yaw - float thrust; ///< thrust - uint8_t roll_manual; ///< roll control enabled auto:0, manual:1 - uint8_t pitch_manual; ///< pitch auto:0, manual:1 - uint8_t yaw_manual; ///< yaw auto:0, manual:1 - uint8_t thrust_manual; ///< thrust auto:0, manual:1 -} mavlink_manual_control_t; - -#define MAVLINK_MSG_ID_MANUAL_CONTROL_LEN 21 -#define MAVLINK_MSG_ID_69_LEN 21 - - - -#define MAVLINK_MESSAGE_INFO_MANUAL_CONTROL { \ - "MANUAL_CONTROL", \ - 9, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_manual_control_t, target) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 1, offsetof(mavlink_manual_control_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 5, offsetof(mavlink_manual_control_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_manual_control_t, yaw) }, \ - { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 13, offsetof(mavlink_manual_control_t, thrust) }, \ - { "roll_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_manual_control_t, roll_manual) }, \ - { "pitch_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 18, offsetof(mavlink_manual_control_t, pitch_manual) }, \ - { "yaw_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 19, offsetof(mavlink_manual_control_t, yaw_manual) }, \ - { "thrust_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 20, offsetof(mavlink_manual_control_t, thrust_manual) }, \ - } \ -} - - -/** - * @brief Pack a manual_control message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_manual_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, float roll, float pitch, float yaw, float thrust, uint8_t roll_manual, uint8_t pitch_manual, uint8_t yaw_manual, uint8_t thrust_manual) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, roll); - _mav_put_float(buf, 5, pitch); - _mav_put_float(buf, 9, yaw); - _mav_put_float(buf, 13, thrust); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); -#else - mavlink_manual_control_t packet; - packet.target = target; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); -#endif - - msg->msgid = MAVLINK_MSG_ID_MANUAL_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 21); -} - -/** - * @brief Pack a manual_control message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_manual_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,float roll,float pitch,float yaw,float thrust,uint8_t roll_manual,uint8_t pitch_manual,uint8_t yaw_manual,uint8_t thrust_manual) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, roll); - _mav_put_float(buf, 5, pitch); - _mav_put_float(buf, 9, yaw); - _mav_put_float(buf, 13, thrust); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); -#else - mavlink_manual_control_t packet; - packet.target = target; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); -#endif - - msg->msgid = MAVLINK_MSG_ID_MANUAL_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 21); -} - -/** - * @brief Encode a manual_control struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param manual_control C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_manual_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_manual_control_t* manual_control) -{ - return mavlink_msg_manual_control_pack(system_id, component_id, msg, manual_control->target, manual_control->roll, manual_control->pitch, manual_control->yaw, manual_control->thrust, manual_control->roll_manual, manual_control->pitch_manual, manual_control->yaw_manual, manual_control->thrust_manual); -} - -/** - * @brief Send a manual_control message - * @param chan MAVLink channel to send the message - * - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_manual_control_send(mavlink_channel_t chan, uint8_t target, float roll, float pitch, float yaw, float thrust, uint8_t roll_manual, uint8_t pitch_manual, uint8_t yaw_manual, uint8_t thrust_manual) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, roll); - _mav_put_float(buf, 5, pitch); - _mav_put_float(buf, 9, yaw); - _mav_put_float(buf, 13, thrust); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MANUAL_CONTROL, buf, 21); -#else - mavlink_manual_control_t packet; - packet.target = target; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MANUAL_CONTROL, (const char *)&packet, 21); -#endif -} - -#endif - -// MESSAGE MANUAL_CONTROL UNPACKING - - -/** - * @brief Get field target from manual_control message - * - * @return The system to be controlled - */ -static inline uint8_t mavlink_msg_manual_control_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field roll from manual_control message - * - * @return roll - */ -static inline float mavlink_msg_manual_control_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 1); -} - -/** - * @brief Get field pitch from manual_control message - * - * @return pitch - */ -static inline float mavlink_msg_manual_control_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 5); -} - -/** - * @brief Get field yaw from manual_control message - * - * @return yaw - */ -static inline float mavlink_msg_manual_control_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Get field thrust from manual_control message - * - * @return thrust - */ -static inline float mavlink_msg_manual_control_get_thrust(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 13); -} - -/** - * @brief Get field roll_manual from manual_control message - * - * @return roll control enabled auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_roll_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 17); -} - -/** - * @brief Get field pitch_manual from manual_control message - * - * @return pitch auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_pitch_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 18); -} - -/** - * @brief Get field yaw_manual from manual_control message - * - * @return yaw auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_yaw_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 19); -} - -/** - * @brief Get field thrust_manual from manual_control message - * - * @return thrust auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_thrust_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 20); -} - -/** - * @brief Decode a manual_control message into a struct - * - * @param msg The message to decode - * @param manual_control C-struct to decode the message contents into - */ -static inline void mavlink_msg_manual_control_decode(const mavlink_message_t* msg, mavlink_manual_control_t* manual_control) -{ -#if MAVLINK_NEED_BYTE_SWAP - manual_control->target = mavlink_msg_manual_control_get_target(msg); - manual_control->roll = mavlink_msg_manual_control_get_roll(msg); - manual_control->pitch = mavlink_msg_manual_control_get_pitch(msg); - manual_control->yaw = mavlink_msg_manual_control_get_yaw(msg); - manual_control->thrust = mavlink_msg_manual_control_get_thrust(msg); - manual_control->roll_manual = mavlink_msg_manual_control_get_roll_manual(msg); - manual_control->pitch_manual = mavlink_msg_manual_control_get_pitch_manual(msg); - manual_control->yaw_manual = mavlink_msg_manual_control_get_yaw_manual(msg); - manual_control->thrust_manual = mavlink_msg_manual_control_get_thrust_manual(msg); -#else - memcpy(manual_control, _MAV_PAYLOAD(msg), 21); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_named_value_float.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_named_value_float.h deleted file mode 100644 index 5cf76e372e..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_named_value_float.h +++ /dev/null @@ -1,160 +0,0 @@ -// MESSAGE NAMED_VALUE_FLOAT PACKING - -#define MAVLINK_MSG_ID_NAMED_VALUE_FLOAT 252 - -typedef struct __mavlink_named_value_float_t -{ - char name[10]; ///< Name of the debug variable - float value; ///< Floating point value -} mavlink_named_value_float_t; - -#define MAVLINK_MSG_ID_NAMED_VALUE_FLOAT_LEN 14 -#define MAVLINK_MSG_ID_252_LEN 14 - -#define MAVLINK_MSG_NAMED_VALUE_FLOAT_FIELD_NAME_LEN 10 - -#define MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT { \ - "NAMED_VALUE_FLOAT", \ - 2, \ - { { "name", NULL, MAVLINK_TYPE_CHAR, 10, 0, offsetof(mavlink_named_value_float_t, name) }, \ - { "value", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_named_value_float_t, value) }, \ - } \ -} - - -/** - * @brief Pack a named_value_float message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param name Name of the debug variable - * @param value Floating point value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_named_value_float_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const char *name, float value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_float(buf, 10, value); - _mav_put_char_array(buf, 0, name, 10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_named_value_float_t packet; - packet.value = value; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAMED_VALUE_FLOAT; - return mavlink_finalize_message(msg, system_id, component_id, 14); -} - -/** - * @brief Pack a named_value_float message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param name Name of the debug variable - * @param value Floating point value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_named_value_float_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const char *name,float value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_float(buf, 10, value); - _mav_put_char_array(buf, 0, name, 10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_named_value_float_t packet; - packet.value = value; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAMED_VALUE_FLOAT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 14); -} - -/** - * @brief Encode a named_value_float struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param named_value_float C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_named_value_float_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_named_value_float_t* named_value_float) -{ - return mavlink_msg_named_value_float_pack(system_id, component_id, msg, named_value_float->name, named_value_float->value); -} - -/** - * @brief Send a named_value_float message - * @param chan MAVLink channel to send the message - * - * @param name Name of the debug variable - * @param value Floating point value - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_named_value_float_send(mavlink_channel_t chan, const char *name, float value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_float(buf, 10, value); - _mav_put_char_array(buf, 0, name, 10); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, buf, 14); -#else - mavlink_named_value_float_t packet; - packet.value = value; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, (const char *)&packet, 14); -#endif -} - -#endif - -// MESSAGE NAMED_VALUE_FLOAT UNPACKING - - -/** - * @brief Get field name from named_value_float message - * - * @return Name of the debug variable - */ -static inline uint16_t mavlink_msg_named_value_float_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 10, 0); -} - -/** - * @brief Get field value from named_value_float message - * - * @return Floating point value - */ -static inline float mavlink_msg_named_value_float_get_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Decode a named_value_float message into a struct - * - * @param msg The message to decode - * @param named_value_float C-struct to decode the message contents into - */ -static inline void mavlink_msg_named_value_float_decode(const mavlink_message_t* msg, mavlink_named_value_float_t* named_value_float) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_named_value_float_get_name(msg, named_value_float->name); - named_value_float->value = mavlink_msg_named_value_float_get_value(msg); -#else - memcpy(named_value_float, _MAV_PAYLOAD(msg), 14); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_named_value_int.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_named_value_int.h deleted file mode 100644 index 93f0911aa8..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_named_value_int.h +++ /dev/null @@ -1,160 +0,0 @@ -// MESSAGE NAMED_VALUE_INT PACKING - -#define MAVLINK_MSG_ID_NAMED_VALUE_INT 253 - -typedef struct __mavlink_named_value_int_t -{ - char name[10]; ///< Name of the debug variable - int32_t value; ///< Signed integer value -} mavlink_named_value_int_t; - -#define MAVLINK_MSG_ID_NAMED_VALUE_INT_LEN 14 -#define MAVLINK_MSG_ID_253_LEN 14 - -#define MAVLINK_MSG_NAMED_VALUE_INT_FIELD_NAME_LEN 10 - -#define MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT { \ - "NAMED_VALUE_INT", \ - 2, \ - { { "name", NULL, MAVLINK_TYPE_CHAR, 10, 0, offsetof(mavlink_named_value_int_t, name) }, \ - { "value", NULL, MAVLINK_TYPE_INT32_T, 0, 10, offsetof(mavlink_named_value_int_t, value) }, \ - } \ -} - - -/** - * @brief Pack a named_value_int message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param name Name of the debug variable - * @param value Signed integer value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_named_value_int_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const char *name, int32_t value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_int32_t(buf, 10, value); - _mav_put_char_array(buf, 0, name, 10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_named_value_int_t packet; - packet.value = value; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAMED_VALUE_INT; - return mavlink_finalize_message(msg, system_id, component_id, 14); -} - -/** - * @brief Pack a named_value_int message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param name Name of the debug variable - * @param value Signed integer value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_named_value_int_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const char *name,int32_t value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_int32_t(buf, 10, value); - _mav_put_char_array(buf, 0, name, 10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_named_value_int_t packet; - packet.value = value; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAMED_VALUE_INT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 14); -} - -/** - * @brief Encode a named_value_int struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param named_value_int C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_named_value_int_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_named_value_int_t* named_value_int) -{ - return mavlink_msg_named_value_int_pack(system_id, component_id, msg, named_value_int->name, named_value_int->value); -} - -/** - * @brief Send a named_value_int message - * @param chan MAVLink channel to send the message - * - * @param name Name of the debug variable - * @param value Signed integer value - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_named_value_int_send(mavlink_channel_t chan, const char *name, int32_t value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_int32_t(buf, 10, value); - _mav_put_char_array(buf, 0, name, 10); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAMED_VALUE_INT, buf, 14); -#else - mavlink_named_value_int_t packet; - packet.value = value; - mav_array_memcpy(packet.name, name, sizeof(char)*10); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAMED_VALUE_INT, (const char *)&packet, 14); -#endif -} - -#endif - -// MESSAGE NAMED_VALUE_INT UNPACKING - - -/** - * @brief Get field name from named_value_int message - * - * @return Name of the debug variable - */ -static inline uint16_t mavlink_msg_named_value_int_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 10, 0); -} - -/** - * @brief Get field value from named_value_int message - * - * @return Signed integer value - */ -static inline int32_t mavlink_msg_named_value_int_get_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 10); -} - -/** - * @brief Decode a named_value_int message into a struct - * - * @param msg The message to decode - * @param named_value_int C-struct to decode the message contents into - */ -static inline void mavlink_msg_named_value_int_decode(const mavlink_message_t* msg, mavlink_named_value_int_t* named_value_int) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_named_value_int_get_name(msg, named_value_int->name); - named_value_int->value = mavlink_msg_named_value_int_get_value(msg); -#else - memcpy(named_value_int, _MAV_PAYLOAD(msg), 14); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_nav_controller_output.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_nav_controller_output.h deleted file mode 100644 index 64a4a7fb4e..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_nav_controller_output.h +++ /dev/null @@ -1,298 +0,0 @@ -// MESSAGE NAV_CONTROLLER_OUTPUT PACKING - -#define MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT 62 - -typedef struct __mavlink_nav_controller_output_t -{ - float nav_roll; ///< Current desired roll in degrees - float nav_pitch; ///< Current desired pitch in degrees - int16_t nav_bearing; ///< Current desired heading in degrees - int16_t target_bearing; ///< Bearing to current waypoint/target in degrees - uint16_t wp_dist; ///< Distance to active waypoint in meters - float alt_error; ///< Current altitude error in meters - float aspd_error; ///< Current airspeed error in meters/second - float xtrack_error; ///< Current crosstrack error on x-y plane in meters -} mavlink_nav_controller_output_t; - -#define MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT_LEN 26 -#define MAVLINK_MSG_ID_62_LEN 26 - - - -#define MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT { \ - "NAV_CONTROLLER_OUTPUT", \ - 8, \ - { { "nav_roll", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_nav_controller_output_t, nav_roll) }, \ - { "nav_pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_nav_controller_output_t, nav_pitch) }, \ - { "nav_bearing", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_nav_controller_output_t, nav_bearing) }, \ - { "target_bearing", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_nav_controller_output_t, target_bearing) }, \ - { "wp_dist", NULL, MAVLINK_TYPE_UINT16_T, 0, 12, offsetof(mavlink_nav_controller_output_t, wp_dist) }, \ - { "alt_error", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_nav_controller_output_t, alt_error) }, \ - { "aspd_error", NULL, MAVLINK_TYPE_FLOAT, 0, 18, offsetof(mavlink_nav_controller_output_t, aspd_error) }, \ - { "xtrack_error", NULL, MAVLINK_TYPE_FLOAT, 0, 22, offsetof(mavlink_nav_controller_output_t, xtrack_error) }, \ - } \ -} - - -/** - * @brief Pack a nav_controller_output message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param nav_roll Current desired roll in degrees - * @param nav_pitch Current desired pitch in degrees - * @param nav_bearing Current desired heading in degrees - * @param target_bearing Bearing to current waypoint/target in degrees - * @param wp_dist Distance to active waypoint in meters - * @param alt_error Current altitude error in meters - * @param aspd_error Current airspeed error in meters/second - * @param xtrack_error Current crosstrack error on x-y plane in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_nav_controller_output_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float nav_roll, float nav_pitch, int16_t nav_bearing, int16_t target_bearing, uint16_t wp_dist, float alt_error, float aspd_error, float xtrack_error) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_float(buf, 0, nav_roll); - _mav_put_float(buf, 4, nav_pitch); - _mav_put_int16_t(buf, 8, nav_bearing); - _mav_put_int16_t(buf, 10, target_bearing); - _mav_put_uint16_t(buf, 12, wp_dist); - _mav_put_float(buf, 14, alt_error); - _mav_put_float(buf, 18, aspd_error); - _mav_put_float(buf, 22, xtrack_error); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_nav_controller_output_t packet; - packet.nav_roll = nav_roll; - packet.nav_pitch = nav_pitch; - packet.nav_bearing = nav_bearing; - packet.target_bearing = target_bearing; - packet.wp_dist = wp_dist; - packet.alt_error = alt_error; - packet.aspd_error = aspd_error; - packet.xtrack_error = xtrack_error; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT; - return mavlink_finalize_message(msg, system_id, component_id, 26); -} - -/** - * @brief Pack a nav_controller_output message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param nav_roll Current desired roll in degrees - * @param nav_pitch Current desired pitch in degrees - * @param nav_bearing Current desired heading in degrees - * @param target_bearing Bearing to current waypoint/target in degrees - * @param wp_dist Distance to active waypoint in meters - * @param alt_error Current altitude error in meters - * @param aspd_error Current airspeed error in meters/second - * @param xtrack_error Current crosstrack error on x-y plane in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_nav_controller_output_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float nav_roll,float nav_pitch,int16_t nav_bearing,int16_t target_bearing,uint16_t wp_dist,float alt_error,float aspd_error,float xtrack_error) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_float(buf, 0, nav_roll); - _mav_put_float(buf, 4, nav_pitch); - _mav_put_int16_t(buf, 8, nav_bearing); - _mav_put_int16_t(buf, 10, target_bearing); - _mav_put_uint16_t(buf, 12, wp_dist); - _mav_put_float(buf, 14, alt_error); - _mav_put_float(buf, 18, aspd_error); - _mav_put_float(buf, 22, xtrack_error); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_nav_controller_output_t packet; - packet.nav_roll = nav_roll; - packet.nav_pitch = nav_pitch; - packet.nav_bearing = nav_bearing; - packet.target_bearing = target_bearing; - packet.wp_dist = wp_dist; - packet.alt_error = alt_error; - packet.aspd_error = aspd_error; - packet.xtrack_error = xtrack_error; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 26); -} - -/** - * @brief Encode a nav_controller_output struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param nav_controller_output C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_nav_controller_output_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_nav_controller_output_t* nav_controller_output) -{ - return mavlink_msg_nav_controller_output_pack(system_id, component_id, msg, nav_controller_output->nav_roll, nav_controller_output->nav_pitch, nav_controller_output->nav_bearing, nav_controller_output->target_bearing, nav_controller_output->wp_dist, nav_controller_output->alt_error, nav_controller_output->aspd_error, nav_controller_output->xtrack_error); -} - -/** - * @brief Send a nav_controller_output message - * @param chan MAVLink channel to send the message - * - * @param nav_roll Current desired roll in degrees - * @param nav_pitch Current desired pitch in degrees - * @param nav_bearing Current desired heading in degrees - * @param target_bearing Bearing to current waypoint/target in degrees - * @param wp_dist Distance to active waypoint in meters - * @param alt_error Current altitude error in meters - * @param aspd_error Current airspeed error in meters/second - * @param xtrack_error Current crosstrack error on x-y plane in meters - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_nav_controller_output_send(mavlink_channel_t chan, float nav_roll, float nav_pitch, int16_t nav_bearing, int16_t target_bearing, uint16_t wp_dist, float alt_error, float aspd_error, float xtrack_error) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_float(buf, 0, nav_roll); - _mav_put_float(buf, 4, nav_pitch); - _mav_put_int16_t(buf, 8, nav_bearing); - _mav_put_int16_t(buf, 10, target_bearing); - _mav_put_uint16_t(buf, 12, wp_dist); - _mav_put_float(buf, 14, alt_error); - _mav_put_float(buf, 18, aspd_error); - _mav_put_float(buf, 22, xtrack_error); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT, buf, 26); -#else - mavlink_nav_controller_output_t packet; - packet.nav_roll = nav_roll; - packet.nav_pitch = nav_pitch; - packet.nav_bearing = nav_bearing; - packet.target_bearing = target_bearing; - packet.wp_dist = wp_dist; - packet.alt_error = alt_error; - packet.aspd_error = aspd_error; - packet.xtrack_error = xtrack_error; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT, (const char *)&packet, 26); -#endif -} - -#endif - -// MESSAGE NAV_CONTROLLER_OUTPUT UNPACKING - - -/** - * @brief Get field nav_roll from nav_controller_output message - * - * @return Current desired roll in degrees - */ -static inline float mavlink_msg_nav_controller_output_get_nav_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field nav_pitch from nav_controller_output message - * - * @return Current desired pitch in degrees - */ -static inline float mavlink_msg_nav_controller_output_get_nav_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field nav_bearing from nav_controller_output message - * - * @return Current desired heading in degrees - */ -static inline int16_t mavlink_msg_nav_controller_output_get_nav_bearing(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 8); -} - -/** - * @brief Get field target_bearing from nav_controller_output message - * - * @return Bearing to current waypoint/target in degrees - */ -static inline int16_t mavlink_msg_nav_controller_output_get_target_bearing(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 10); -} - -/** - * @brief Get field wp_dist from nav_controller_output message - * - * @return Distance to active waypoint in meters - */ -static inline uint16_t mavlink_msg_nav_controller_output_get_wp_dist(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 12); -} - -/** - * @brief Get field alt_error from nav_controller_output message - * - * @return Current altitude error in meters - */ -static inline float mavlink_msg_nav_controller_output_get_alt_error(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Get field aspd_error from nav_controller_output message - * - * @return Current airspeed error in meters/second - */ -static inline float mavlink_msg_nav_controller_output_get_aspd_error(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 18); -} - -/** - * @brief Get field xtrack_error from nav_controller_output message - * - * @return Current crosstrack error on x-y plane in meters - */ -static inline float mavlink_msg_nav_controller_output_get_xtrack_error(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 22); -} - -/** - * @brief Decode a nav_controller_output message into a struct - * - * @param msg The message to decode - * @param nav_controller_output C-struct to decode the message contents into - */ -static inline void mavlink_msg_nav_controller_output_decode(const mavlink_message_t* msg, mavlink_nav_controller_output_t* nav_controller_output) -{ -#if MAVLINK_NEED_BYTE_SWAP - nav_controller_output->nav_roll = mavlink_msg_nav_controller_output_get_nav_roll(msg); - nav_controller_output->nav_pitch = mavlink_msg_nav_controller_output_get_nav_pitch(msg); - nav_controller_output->nav_bearing = mavlink_msg_nav_controller_output_get_nav_bearing(msg); - nav_controller_output->target_bearing = mavlink_msg_nav_controller_output_get_target_bearing(msg); - nav_controller_output->wp_dist = mavlink_msg_nav_controller_output_get_wp_dist(msg); - nav_controller_output->alt_error = mavlink_msg_nav_controller_output_get_alt_error(msg); - nav_controller_output->aspd_error = mavlink_msg_nav_controller_output_get_aspd_error(msg); - nav_controller_output->xtrack_error = mavlink_msg_nav_controller_output_get_xtrack_error(msg); -#else - memcpy(nav_controller_output, _MAV_PAYLOAD(msg), 26); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_object_detection_event.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_object_detection_event.h deleted file mode 100644 index 617eb50d44..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_object_detection_event.h +++ /dev/null @@ -1,270 +0,0 @@ -// MESSAGE OBJECT_DETECTION_EVENT PACKING - -#define MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT 140 - -typedef struct __mavlink_object_detection_event_t -{ - uint32_t time; ///< Timestamp in milliseconds since system boot - uint16_t object_id; ///< Object ID - uint8_t type; ///< Object type: 0: image, 1: letter, 2: ground vehicle, 3: air vehicle, 4: surface vehicle, 5: sub-surface vehicle, 6: human, 7: animal - char name[20]; ///< Name of the object as defined by the detector - uint8_t quality; ///< Detection quality / confidence. 0: bad, 255: maximum confidence - float bearing; ///< Angle of the object with respect to the body frame in NED coordinates in radians. 0: front - float distance; ///< Ground distance in meters -} mavlink_object_detection_event_t; - -#define MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT_LEN 36 -#define MAVLINK_MSG_ID_140_LEN 36 - -#define MAVLINK_MSG_OBJECT_DETECTION_EVENT_FIELD_NAME_LEN 20 - -#define MAVLINK_MESSAGE_INFO_OBJECT_DETECTION_EVENT { \ - "OBJECT_DETECTION_EVENT", \ - 7, \ - { { "time", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_object_detection_event_t, time) }, \ - { "object_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_object_detection_event_t, object_id) }, \ - { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_object_detection_event_t, type) }, \ - { "name", NULL, MAVLINK_TYPE_CHAR, 20, 7, offsetof(mavlink_object_detection_event_t, name) }, \ - { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 27, offsetof(mavlink_object_detection_event_t, quality) }, \ - { "bearing", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_object_detection_event_t, bearing) }, \ - { "distance", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_object_detection_event_t, distance) }, \ - } \ -} - - -/** - * @brief Pack a object_detection_event message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param time Timestamp in milliseconds since system boot - * @param object_id Object ID - * @param type Object type: 0: image, 1: letter, 2: ground vehicle, 3: air vehicle, 4: surface vehicle, 5: sub-surface vehicle, 6: human, 7: animal - * @param name Name of the object as defined by the detector - * @param quality Detection quality / confidence. 0: bad, 255: maximum confidence - * @param bearing Angle of the object with respect to the body frame in NED coordinates in radians. 0: front - * @param distance Ground distance in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_object_detection_event_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint32_t time, uint16_t object_id, uint8_t type, const char *name, uint8_t quality, float bearing, float distance) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_uint32_t(buf, 0, time); - _mav_put_uint16_t(buf, 4, object_id); - _mav_put_uint8_t(buf, 6, type); - _mav_put_uint8_t(buf, 27, quality); - _mav_put_float(buf, 28, bearing); - _mav_put_float(buf, 32, distance); - _mav_put_char_array(buf, 7, name, 20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_object_detection_event_t packet; - packet.time = time; - packet.object_id = object_id; - packet.type = type; - packet.quality = quality; - packet.bearing = bearing; - packet.distance = distance; - mav_array_memcpy(packet.name, name, sizeof(char)*20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT; - return mavlink_finalize_message(msg, system_id, component_id, 36); -} - -/** - * @brief Pack a object_detection_event message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param time Timestamp in milliseconds since system boot - * @param object_id Object ID - * @param type Object type: 0: image, 1: letter, 2: ground vehicle, 3: air vehicle, 4: surface vehicle, 5: sub-surface vehicle, 6: human, 7: animal - * @param name Name of the object as defined by the detector - * @param quality Detection quality / confidence. 0: bad, 255: maximum confidence - * @param bearing Angle of the object with respect to the body frame in NED coordinates in radians. 0: front - * @param distance Ground distance in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_object_detection_event_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint32_t time,uint16_t object_id,uint8_t type,const char *name,uint8_t quality,float bearing,float distance) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_uint32_t(buf, 0, time); - _mav_put_uint16_t(buf, 4, object_id); - _mav_put_uint8_t(buf, 6, type); - _mav_put_uint8_t(buf, 27, quality); - _mav_put_float(buf, 28, bearing); - _mav_put_float(buf, 32, distance); - _mav_put_char_array(buf, 7, name, 20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_object_detection_event_t packet; - packet.time = time; - packet.object_id = object_id; - packet.type = type; - packet.quality = quality; - packet.bearing = bearing; - packet.distance = distance; - mav_array_memcpy(packet.name, name, sizeof(char)*20); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 36); -} - -/** - * @brief Encode a object_detection_event struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param object_detection_event C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_object_detection_event_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_object_detection_event_t* object_detection_event) -{ - return mavlink_msg_object_detection_event_pack(system_id, component_id, msg, object_detection_event->time, object_detection_event->object_id, object_detection_event->type, object_detection_event->name, object_detection_event->quality, object_detection_event->bearing, object_detection_event->distance); -} - -/** - * @brief Send a object_detection_event message - * @param chan MAVLink channel to send the message - * - * @param time Timestamp in milliseconds since system boot - * @param object_id Object ID - * @param type Object type: 0: image, 1: letter, 2: ground vehicle, 3: air vehicle, 4: surface vehicle, 5: sub-surface vehicle, 6: human, 7: animal - * @param name Name of the object as defined by the detector - * @param quality Detection quality / confidence. 0: bad, 255: maximum confidence - * @param bearing Angle of the object with respect to the body frame in NED coordinates in radians. 0: front - * @param distance Ground distance in meters - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_object_detection_event_send(mavlink_channel_t chan, uint32_t time, uint16_t object_id, uint8_t type, const char *name, uint8_t quality, float bearing, float distance) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_uint32_t(buf, 0, time); - _mav_put_uint16_t(buf, 4, object_id); - _mav_put_uint8_t(buf, 6, type); - _mav_put_uint8_t(buf, 27, quality); - _mav_put_float(buf, 28, bearing); - _mav_put_float(buf, 32, distance); - _mav_put_char_array(buf, 7, name, 20); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT, buf, 36); -#else - mavlink_object_detection_event_t packet; - packet.time = time; - packet.object_id = object_id; - packet.type = type; - packet.quality = quality; - packet.bearing = bearing; - packet.distance = distance; - mav_array_memcpy(packet.name, name, sizeof(char)*20); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT, (const char *)&packet, 36); -#endif -} - -#endif - -// MESSAGE OBJECT_DETECTION_EVENT UNPACKING - - -/** - * @brief Get field time from object_detection_event message - * - * @return Timestamp in milliseconds since system boot - */ -static inline uint32_t mavlink_msg_object_detection_event_get_time(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 0); -} - -/** - * @brief Get field object_id from object_detection_event message - * - * @return Object ID - */ -static inline uint16_t mavlink_msg_object_detection_event_get_object_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 4); -} - -/** - * @brief Get field type from object_detection_event message - * - * @return Object type: 0: image, 1: letter, 2: ground vehicle, 3: air vehicle, 4: surface vehicle, 5: sub-surface vehicle, 6: human, 7: animal - */ -static inline uint8_t mavlink_msg_object_detection_event_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field name from object_detection_event message - * - * @return Name of the object as defined by the detector - */ -static inline uint16_t mavlink_msg_object_detection_event_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 20, 7); -} - -/** - * @brief Get field quality from object_detection_event message - * - * @return Detection quality / confidence. 0: bad, 255: maximum confidence - */ -static inline uint8_t mavlink_msg_object_detection_event_get_quality(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 27); -} - -/** - * @brief Get field bearing from object_detection_event message - * - * @return Angle of the object with respect to the body frame in NED coordinates in radians. 0: front - */ -static inline float mavlink_msg_object_detection_event_get_bearing(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Get field distance from object_detection_event message - * - * @return Ground distance in meters - */ -static inline float mavlink_msg_object_detection_event_get_distance(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 32); -} - -/** - * @brief Decode a object_detection_event message into a struct - * - * @param msg The message to decode - * @param object_detection_event C-struct to decode the message contents into - */ -static inline void mavlink_msg_object_detection_event_decode(const mavlink_message_t* msg, mavlink_object_detection_event_t* object_detection_event) -{ -#if MAVLINK_NEED_BYTE_SWAP - object_detection_event->time = mavlink_msg_object_detection_event_get_time(msg); - object_detection_event->object_id = mavlink_msg_object_detection_event_get_object_id(msg); - object_detection_event->type = mavlink_msg_object_detection_event_get_type(msg); - mavlink_msg_object_detection_event_get_name(msg, object_detection_event->name); - object_detection_event->quality = mavlink_msg_object_detection_event_get_quality(msg); - object_detection_event->bearing = mavlink_msg_object_detection_event_get_bearing(msg); - object_detection_event->distance = mavlink_msg_object_detection_event_get_distance(msg); -#else - memcpy(object_detection_event, _MAV_PAYLOAD(msg), 36); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_optical_flow.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_optical_flow.h deleted file mode 100644 index 33067cc891..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_optical_flow.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE OPTICAL_FLOW PACKING - -#define MAVLINK_MSG_ID_OPTICAL_FLOW 100 - -typedef struct __mavlink_optical_flow_t -{ - uint64_t time; ///< Timestamp (UNIX) - uint8_t sensor_id; ///< Sensor ID - int16_t flow_x; ///< Flow in pixels in x-sensor direction - int16_t flow_y; ///< Flow in pixels in y-sensor direction - uint8_t quality; ///< Optical flow quality / confidence. 0: bad, 255: maximum quality - float ground_distance; ///< Ground distance in meters -} mavlink_optical_flow_t; - -#define MAVLINK_MSG_ID_OPTICAL_FLOW_LEN 18 -#define MAVLINK_MSG_ID_100_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_OPTICAL_FLOW { \ - "OPTICAL_FLOW", \ - 6, \ - { { "time", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_optical_flow_t, time) }, \ - { "sensor_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_optical_flow_t, sensor_id) }, \ - { "flow_x", NULL, MAVLINK_TYPE_INT16_T, 0, 9, offsetof(mavlink_optical_flow_t, flow_x) }, \ - { "flow_y", NULL, MAVLINK_TYPE_INT16_T, 0, 11, offsetof(mavlink_optical_flow_t, flow_y) }, \ - { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 13, offsetof(mavlink_optical_flow_t, quality) }, \ - { "ground_distance", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_optical_flow_t, ground_distance) }, \ - } \ -} - - -/** - * @brief Pack a optical_flow message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param time Timestamp (UNIX) - * @param sensor_id Sensor ID - * @param flow_x Flow in pixels in x-sensor direction - * @param flow_y Flow in pixels in y-sensor direction - * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality - * @param ground_distance Ground distance in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_optical_flow_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t time, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, uint8_t quality, float ground_distance) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint64_t(buf, 0, time); - _mav_put_uint8_t(buf, 8, sensor_id); - _mav_put_int16_t(buf, 9, flow_x); - _mav_put_int16_t(buf, 11, flow_y); - _mav_put_uint8_t(buf, 13, quality); - _mav_put_float(buf, 14, ground_distance); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_optical_flow_t packet; - packet.time = time; - packet.sensor_id = sensor_id; - packet.flow_x = flow_x; - packet.flow_y = flow_y; - packet.quality = quality; - packet.ground_distance = ground_distance; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a optical_flow message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param time Timestamp (UNIX) - * @param sensor_id Sensor ID - * @param flow_x Flow in pixels in x-sensor direction - * @param flow_y Flow in pixels in y-sensor direction - * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality - * @param ground_distance Ground distance in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_optical_flow_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t time,uint8_t sensor_id,int16_t flow_x,int16_t flow_y,uint8_t quality,float ground_distance) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint64_t(buf, 0, time); - _mav_put_uint8_t(buf, 8, sensor_id); - _mav_put_int16_t(buf, 9, flow_x); - _mav_put_int16_t(buf, 11, flow_y); - _mav_put_uint8_t(buf, 13, quality); - _mav_put_float(buf, 14, ground_distance); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_optical_flow_t packet; - packet.time = time; - packet.sensor_id = sensor_id; - packet.flow_x = flow_x; - packet.flow_y = flow_y; - packet.quality = quality; - packet.ground_distance = ground_distance; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a optical_flow struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param optical_flow C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_optical_flow_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_optical_flow_t* optical_flow) -{ - return mavlink_msg_optical_flow_pack(system_id, component_id, msg, optical_flow->time, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->quality, optical_flow->ground_distance); -} - -/** - * @brief Send a optical_flow message - * @param chan MAVLink channel to send the message - * - * @param time Timestamp (UNIX) - * @param sensor_id Sensor ID - * @param flow_x Flow in pixels in x-sensor direction - * @param flow_y Flow in pixels in y-sensor direction - * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality - * @param ground_distance Ground distance in meters - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_optical_flow_send(mavlink_channel_t chan, uint64_t time, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, uint8_t quality, float ground_distance) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint64_t(buf, 0, time); - _mav_put_uint8_t(buf, 8, sensor_id); - _mav_put_int16_t(buf, 9, flow_x); - _mav_put_int16_t(buf, 11, flow_y); - _mav_put_uint8_t(buf, 13, quality); - _mav_put_float(buf, 14, ground_distance); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, 18); -#else - mavlink_optical_flow_t packet; - packet.time = time; - packet.sensor_id = sensor_id; - packet.flow_x = flow_x; - packet.flow_y = flow_y; - packet.quality = quality; - packet.ground_distance = ground_distance; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE OPTICAL_FLOW UNPACKING - - -/** - * @brief Get field time from optical_flow message - * - * @return Timestamp (UNIX) - */ -static inline uint64_t mavlink_msg_optical_flow_get_time(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field sensor_id from optical_flow message - * - * @return Sensor ID - */ -static inline uint8_t mavlink_msg_optical_flow_get_sensor_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Get field flow_x from optical_flow message - * - * @return Flow in pixels in x-sensor direction - */ -static inline int16_t mavlink_msg_optical_flow_get_flow_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 9); -} - -/** - * @brief Get field flow_y from optical_flow message - * - * @return Flow in pixels in y-sensor direction - */ -static inline int16_t mavlink_msg_optical_flow_get_flow_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 11); -} - -/** - * @brief Get field quality from optical_flow message - * - * @return Optical flow quality / confidence. 0: bad, 255: maximum quality - */ -static inline uint8_t mavlink_msg_optical_flow_get_quality(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 13); -} - -/** - * @brief Get field ground_distance from optical_flow message - * - * @return Ground distance in meters - */ -static inline float mavlink_msg_optical_flow_get_ground_distance(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Decode a optical_flow message into a struct - * - * @param msg The message to decode - * @param optical_flow C-struct to decode the message contents into - */ -static inline void mavlink_msg_optical_flow_decode(const mavlink_message_t* msg, mavlink_optical_flow_t* optical_flow) -{ -#if MAVLINK_NEED_BYTE_SWAP - optical_flow->time = mavlink_msg_optical_flow_get_time(msg); - optical_flow->sensor_id = mavlink_msg_optical_flow_get_sensor_id(msg); - optical_flow->flow_x = mavlink_msg_optical_flow_get_flow_x(msg); - optical_flow->flow_y = mavlink_msg_optical_flow_get_flow_y(msg); - optical_flow->quality = mavlink_msg_optical_flow_get_quality(msg); - optical_flow->ground_distance = mavlink_msg_optical_flow_get_ground_distance(msg); -#else - memcpy(optical_flow, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_request_list.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_request_list.h deleted file mode 100644 index 39e35915e1..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_request_list.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE PARAM_REQUEST_LIST PACKING - -#define MAVLINK_MSG_ID_PARAM_REQUEST_LIST 21 - -typedef struct __mavlink_param_request_list_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID -} mavlink_param_request_list_t; - -#define MAVLINK_MSG_ID_PARAM_REQUEST_LIST_LEN 2 -#define MAVLINK_MSG_ID_21_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST { \ - "PARAM_REQUEST_LIST", \ - 2, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_param_request_list_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_param_request_list_t, target_component) }, \ - } \ -} - - -/** - * @brief Pack a param_request_list message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_request_list_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_param_request_list_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_REQUEST_LIST; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a param_request_list message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_request_list_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_param_request_list_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_REQUEST_LIST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a param_request_list struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param param_request_list C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_param_request_list_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_param_request_list_t* param_request_list) -{ - return mavlink_msg_param_request_list_pack(system_id, component_id, msg, param_request_list->target_system, param_request_list->target_component); -} - -/** - * @brief Send a param_request_list message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_param_request_list_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_REQUEST_LIST, buf, 2); -#else - mavlink_param_request_list_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_REQUEST_LIST, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE PARAM_REQUEST_LIST UNPACKING - - -/** - * @brief Get field target_system from param_request_list message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_param_request_list_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from param_request_list message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_param_request_list_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Decode a param_request_list message into a struct - * - * @param msg The message to decode - * @param param_request_list C-struct to decode the message contents into - */ -static inline void mavlink_msg_param_request_list_decode(const mavlink_message_t* msg, mavlink_param_request_list_t* param_request_list) -{ -#if MAVLINK_NEED_BYTE_SWAP - param_request_list->target_system = mavlink_msg_param_request_list_get_target_system(msg); - param_request_list->target_component = mavlink_msg_param_request_list_get_target_component(msg); -#else - memcpy(param_request_list, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_request_read.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_request_read.h deleted file mode 100644 index c02cb04492..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_request_read.h +++ /dev/null @@ -1,204 +0,0 @@ -// MESSAGE PARAM_REQUEST_READ PACKING - -#define MAVLINK_MSG_ID_PARAM_REQUEST_READ 20 - -typedef struct __mavlink_param_request_read_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - int8_t param_id[15]; ///< Onboard parameter id - int16_t param_index; ///< Parameter index. Send -1 to use the param ID field as identifier -} mavlink_param_request_read_t; - -#define MAVLINK_MSG_ID_PARAM_REQUEST_READ_LEN 19 -#define MAVLINK_MSG_ID_20_LEN 19 - -#define MAVLINK_MSG_PARAM_REQUEST_READ_FIELD_PARAM_ID_LEN 15 - -#define MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ { \ - "PARAM_REQUEST_READ", \ - 4, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_param_request_read_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_param_request_read_t, target_component) }, \ - { "param_id", NULL, MAVLINK_TYPE_INT8_T, 15, 2, offsetof(mavlink_param_request_read_t, param_id) }, \ - { "param_index", NULL, MAVLINK_TYPE_INT16_T, 0, 17, offsetof(mavlink_param_request_read_t, param_index) }, \ - } \ -} - - -/** - * @brief Pack a param_request_read message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_index Parameter index. Send -1 to use the param ID field as identifier - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_request_read_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, const int8_t *param_id, int16_t param_index) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[19]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int16_t(buf, 17, param_index); - _mav_put_int8_t_array(buf, 2, param_id, 15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 19); -#else - mavlink_param_request_read_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.param_index = param_index; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 19); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_REQUEST_READ; - return mavlink_finalize_message(msg, system_id, component_id, 19); -} - -/** - * @brief Pack a param_request_read message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_index Parameter index. Send -1 to use the param ID field as identifier - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_request_read_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,const int8_t *param_id,int16_t param_index) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[19]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int16_t(buf, 17, param_index); - _mav_put_int8_t_array(buf, 2, param_id, 15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 19); -#else - mavlink_param_request_read_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.param_index = param_index; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 19); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_REQUEST_READ; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 19); -} - -/** - * @brief Encode a param_request_read struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param param_request_read C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_param_request_read_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_param_request_read_t* param_request_read) -{ - return mavlink_msg_param_request_read_pack(system_id, component_id, msg, param_request_read->target_system, param_request_read->target_component, param_request_read->param_id, param_request_read->param_index); -} - -/** - * @brief Send a param_request_read message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_index Parameter index. Send -1 to use the param ID field as identifier - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_param_request_read_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, const int8_t *param_id, int16_t param_index) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[19]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_int16_t(buf, 17, param_index); - _mav_put_int8_t_array(buf, 2, param_id, 15); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_REQUEST_READ, buf, 19); -#else - mavlink_param_request_read_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.param_index = param_index; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_REQUEST_READ, (const char *)&packet, 19); -#endif -} - -#endif - -// MESSAGE PARAM_REQUEST_READ UNPACKING - - -/** - * @brief Get field target_system from param_request_read message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_param_request_read_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from param_request_read message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_param_request_read_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field param_id from param_request_read message - * - * @return Onboard parameter id - */ -static inline uint16_t mavlink_msg_param_request_read_get_param_id(const mavlink_message_t* msg, int8_t *param_id) -{ - return _MAV_RETURN_int8_t_array(msg, param_id, 15, 2); -} - -/** - * @brief Get field param_index from param_request_read message - * - * @return Parameter index. Send -1 to use the param ID field as identifier - */ -static inline int16_t mavlink_msg_param_request_read_get_param_index(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 17); -} - -/** - * @brief Decode a param_request_read message into a struct - * - * @param msg The message to decode - * @param param_request_read C-struct to decode the message contents into - */ -static inline void mavlink_msg_param_request_read_decode(const mavlink_message_t* msg, mavlink_param_request_read_t* param_request_read) -{ -#if MAVLINK_NEED_BYTE_SWAP - param_request_read->target_system = mavlink_msg_param_request_read_get_target_system(msg); - param_request_read->target_component = mavlink_msg_param_request_read_get_target_component(msg); - mavlink_msg_param_request_read_get_param_id(msg, param_request_read->param_id); - param_request_read->param_index = mavlink_msg_param_request_read_get_param_index(msg); -#else - memcpy(param_request_read, _MAV_PAYLOAD(msg), 19); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_set.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_set.h deleted file mode 100644 index e6648430f6..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_set.h +++ /dev/null @@ -1,204 +0,0 @@ -// MESSAGE PARAM_SET PACKING - -#define MAVLINK_MSG_ID_PARAM_SET 23 - -typedef struct __mavlink_param_set_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - int8_t param_id[15]; ///< Onboard parameter id - float param_value; ///< Onboard parameter value -} mavlink_param_set_t; - -#define MAVLINK_MSG_ID_PARAM_SET_LEN 21 -#define MAVLINK_MSG_ID_23_LEN 21 - -#define MAVLINK_MSG_PARAM_SET_FIELD_PARAM_ID_LEN 15 - -#define MAVLINK_MESSAGE_INFO_PARAM_SET { \ - "PARAM_SET", \ - 4, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_param_set_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_param_set_t, target_component) }, \ - { "param_id", NULL, MAVLINK_TYPE_INT8_T, 15, 2, offsetof(mavlink_param_set_t, param_id) }, \ - { "param_value", NULL, MAVLINK_TYPE_FLOAT, 0, 17, offsetof(mavlink_param_set_t, param_value) }, \ - } \ -} - - -/** - * @brief Pack a param_set message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_value Onboard parameter value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_set_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, const int8_t *param_id, float param_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 17, param_value); - _mav_put_int8_t_array(buf, 2, param_id, 15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); -#else - mavlink_param_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.param_value = param_value; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_SET; - return mavlink_finalize_message(msg, system_id, component_id, 21); -} - -/** - * @brief Pack a param_set message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_value Onboard parameter value - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_set_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,const int8_t *param_id,float param_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 17, param_value); - _mav_put_int8_t_array(buf, 2, param_id, 15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); -#else - mavlink_param_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.param_value = param_value; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_SET; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 21); -} - -/** - * @brief Encode a param_set struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param param_set C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_param_set_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_param_set_t* param_set) -{ - return mavlink_msg_param_set_pack(system_id, component_id, msg, param_set->target_system, param_set->target_component, param_set->param_id, param_set->param_value); -} - -/** - * @brief Send a param_set message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_value Onboard parameter value - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_param_set_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, const int8_t *param_id, float param_value) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 17, param_value); - _mav_put_int8_t_array(buf, 2, param_id, 15); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_SET, buf, 21); -#else - mavlink_param_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.param_value = param_value; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_SET, (const char *)&packet, 21); -#endif -} - -#endif - -// MESSAGE PARAM_SET UNPACKING - - -/** - * @brief Get field target_system from param_set message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_param_set_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from param_set message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_param_set_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field param_id from param_set message - * - * @return Onboard parameter id - */ -static inline uint16_t mavlink_msg_param_set_get_param_id(const mavlink_message_t* msg, int8_t *param_id) -{ - return _MAV_RETURN_int8_t_array(msg, param_id, 15, 2); -} - -/** - * @brief Get field param_value from param_set message - * - * @return Onboard parameter value - */ -static inline float mavlink_msg_param_set_get_param_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 17); -} - -/** - * @brief Decode a param_set message into a struct - * - * @param msg The message to decode - * @param param_set C-struct to decode the message contents into - */ -static inline void mavlink_msg_param_set_decode(const mavlink_message_t* msg, mavlink_param_set_t* param_set) -{ -#if MAVLINK_NEED_BYTE_SWAP - param_set->target_system = mavlink_msg_param_set_get_target_system(msg); - param_set->target_component = mavlink_msg_param_set_get_target_component(msg); - mavlink_msg_param_set_get_param_id(msg, param_set->param_id); - param_set->param_value = mavlink_msg_param_set_get_param_value(msg); -#else - memcpy(param_set, _MAV_PAYLOAD(msg), 21); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_value.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_value.h deleted file mode 100644 index 634fbb1527..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_param_value.h +++ /dev/null @@ -1,204 +0,0 @@ -// MESSAGE PARAM_VALUE PACKING - -#define MAVLINK_MSG_ID_PARAM_VALUE 22 - -typedef struct __mavlink_param_value_t -{ - int8_t param_id[15]; ///< Onboard parameter id - float param_value; ///< Onboard parameter value - uint16_t param_count; ///< Total number of onboard parameters - uint16_t param_index; ///< Index of this onboard parameter -} mavlink_param_value_t; - -#define MAVLINK_MSG_ID_PARAM_VALUE_LEN 23 -#define MAVLINK_MSG_ID_22_LEN 23 - -#define MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN 15 - -#define MAVLINK_MESSAGE_INFO_PARAM_VALUE { \ - "PARAM_VALUE", \ - 4, \ - { { "param_id", NULL, MAVLINK_TYPE_INT8_T, 15, 0, offsetof(mavlink_param_value_t, param_id) }, \ - { "param_value", NULL, MAVLINK_TYPE_FLOAT, 0, 15, offsetof(mavlink_param_value_t, param_value) }, \ - { "param_count", NULL, MAVLINK_TYPE_UINT16_T, 0, 19, offsetof(mavlink_param_value_t, param_count) }, \ - { "param_index", NULL, MAVLINK_TYPE_UINT16_T, 0, 21, offsetof(mavlink_param_value_t, param_index) }, \ - } \ -} - - -/** - * @brief Pack a param_value message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param param_id Onboard parameter id - * @param param_value Onboard parameter value - * @param param_count Total number of onboard parameters - * @param param_index Index of this onboard parameter - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_value_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const int8_t *param_id, float param_value, uint16_t param_count, uint16_t param_index) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[23]; - _mav_put_float(buf, 15, param_value); - _mav_put_uint16_t(buf, 19, param_count); - _mav_put_uint16_t(buf, 21, param_index); - _mav_put_int8_t_array(buf, 0, param_id, 15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 23); -#else - mavlink_param_value_t packet; - packet.param_value = param_value; - packet.param_count = param_count; - packet.param_index = param_index; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 23); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_VALUE; - return mavlink_finalize_message(msg, system_id, component_id, 23); -} - -/** - * @brief Pack a param_value message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param param_id Onboard parameter id - * @param param_value Onboard parameter value - * @param param_count Total number of onboard parameters - * @param param_index Index of this onboard parameter - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_param_value_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const int8_t *param_id,float param_value,uint16_t param_count,uint16_t param_index) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[23]; - _mav_put_float(buf, 15, param_value); - _mav_put_uint16_t(buf, 19, param_count); - _mav_put_uint16_t(buf, 21, param_index); - _mav_put_int8_t_array(buf, 0, param_id, 15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 23); -#else - mavlink_param_value_t packet; - packet.param_value = param_value; - packet.param_count = param_count; - packet.param_index = param_index; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 23); -#endif - - msg->msgid = MAVLINK_MSG_ID_PARAM_VALUE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 23); -} - -/** - * @brief Encode a param_value struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param param_value C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_param_value_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_param_value_t* param_value) -{ - return mavlink_msg_param_value_pack(system_id, component_id, msg, param_value->param_id, param_value->param_value, param_value->param_count, param_value->param_index); -} - -/** - * @brief Send a param_value message - * @param chan MAVLink channel to send the message - * - * @param param_id Onboard parameter id - * @param param_value Onboard parameter value - * @param param_count Total number of onboard parameters - * @param param_index Index of this onboard parameter - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_param_value_send(mavlink_channel_t chan, const int8_t *param_id, float param_value, uint16_t param_count, uint16_t param_index) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[23]; - _mav_put_float(buf, 15, param_value); - _mav_put_uint16_t(buf, 19, param_count); - _mav_put_uint16_t(buf, 21, param_index); - _mav_put_int8_t_array(buf, 0, param_id, 15); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_VALUE, buf, 23); -#else - mavlink_param_value_t packet; - packet.param_value = param_value; - packet.param_count = param_count; - packet.param_index = param_index; - mav_array_memcpy(packet.param_id, param_id, sizeof(int8_t)*15); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PARAM_VALUE, (const char *)&packet, 23); -#endif -} - -#endif - -// MESSAGE PARAM_VALUE UNPACKING - - -/** - * @brief Get field param_id from param_value message - * - * @return Onboard parameter id - */ -static inline uint16_t mavlink_msg_param_value_get_param_id(const mavlink_message_t* msg, int8_t *param_id) -{ - return _MAV_RETURN_int8_t_array(msg, param_id, 15, 0); -} - -/** - * @brief Get field param_value from param_value message - * - * @return Onboard parameter value - */ -static inline float mavlink_msg_param_value_get_param_value(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 15); -} - -/** - * @brief Get field param_count from param_value message - * - * @return Total number of onboard parameters - */ -static inline uint16_t mavlink_msg_param_value_get_param_count(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 19); -} - -/** - * @brief Get field param_index from param_value message - * - * @return Index of this onboard parameter - */ -static inline uint16_t mavlink_msg_param_value_get_param_index(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 21); -} - -/** - * @brief Decode a param_value message into a struct - * - * @param msg The message to decode - * @param param_value C-struct to decode the message contents into - */ -static inline void mavlink_msg_param_value_decode(const mavlink_message_t* msg, mavlink_param_value_t* param_value) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_param_value_get_param_id(msg, param_value->param_id); - param_value->param_value = mavlink_msg_param_value_get_param_value(msg); - param_value->param_count = mavlink_msg_param_value_get_param_count(msg); - param_value->param_index = mavlink_msg_param_value_get_param_index(msg); -#else - memcpy(param_value, _MAV_PAYLOAD(msg), 23); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_ping.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_ping.h deleted file mode 100644 index ad076fd9b5..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_ping.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE PING PACKING - -#define MAVLINK_MSG_ID_PING 3 - -typedef struct __mavlink_ping_t -{ - uint32_t seq; ///< PING sequence - uint8_t target_system; ///< 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system - uint8_t target_component; ///< 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system - uint64_t time; ///< Unix timestamp in microseconds -} mavlink_ping_t; - -#define MAVLINK_MSG_ID_PING_LEN 14 -#define MAVLINK_MSG_ID_3_LEN 14 - - - -#define MAVLINK_MESSAGE_INFO_PING { \ - "PING", \ - 4, \ - { { "seq", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_ping_t, seq) }, \ - { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_ping_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_ping_t, target_component) }, \ - { "time", NULL, MAVLINK_TYPE_UINT64_T, 0, 6, offsetof(mavlink_ping_t, time) }, \ - } \ -} - - -/** - * @brief Pack a ping message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param seq PING sequence - * @param target_system 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system - * @param target_component 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system - * @param time Unix timestamp in microseconds - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ping_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint32_t seq, uint8_t target_system, uint8_t target_component, uint64_t time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint32_t(buf, 0, seq); - _mav_put_uint8_t(buf, 4, target_system); - _mav_put_uint8_t(buf, 5, target_component); - _mav_put_uint64_t(buf, 6, time); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_ping_t packet; - packet.seq = seq; - packet.target_system = target_system; - packet.target_component = target_component; - packet.time = time; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_PING; - return mavlink_finalize_message(msg, system_id, component_id, 14); -} - -/** - * @brief Pack a ping message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param seq PING sequence - * @param target_system 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system - * @param target_component 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system - * @param time Unix timestamp in microseconds - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ping_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint32_t seq,uint8_t target_system,uint8_t target_component,uint64_t time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint32_t(buf, 0, seq); - _mav_put_uint8_t(buf, 4, target_system); - _mav_put_uint8_t(buf, 5, target_component); - _mav_put_uint64_t(buf, 6, time); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 14); -#else - mavlink_ping_t packet; - packet.seq = seq; - packet.target_system = target_system; - packet.target_component = target_component; - packet.time = time; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 14); -#endif - - msg->msgid = MAVLINK_MSG_ID_PING; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 14); -} - -/** - * @brief Encode a ping struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ping C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ping_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ping_t* ping) -{ - return mavlink_msg_ping_pack(system_id, component_id, msg, ping->seq, ping->target_system, ping->target_component, ping->time); -} - -/** - * @brief Send a ping message - * @param chan MAVLink channel to send the message - * - * @param seq PING sequence - * @param target_system 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system - * @param target_component 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system - * @param time Unix timestamp in microseconds - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ping_send(mavlink_channel_t chan, uint32_t seq, uint8_t target_system, uint8_t target_component, uint64_t time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[14]; - _mav_put_uint32_t(buf, 0, seq); - _mav_put_uint8_t(buf, 4, target_system); - _mav_put_uint8_t(buf, 5, target_component); - _mav_put_uint64_t(buf, 6, time); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PING, buf, 14); -#else - mavlink_ping_t packet; - packet.seq = seq; - packet.target_system = target_system; - packet.target_component = target_component; - packet.time = time; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PING, (const char *)&packet, 14); -#endif -} - -#endif - -// MESSAGE PING UNPACKING - - -/** - * @brief Get field seq from ping message - * - * @return PING sequence - */ -static inline uint32_t mavlink_msg_ping_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 0); -} - -/** - * @brief Get field target_system from ping message - * - * @return 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system - */ -static inline uint8_t mavlink_msg_ping_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field target_component from ping message - * - * @return 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system - */ -static inline uint8_t mavlink_msg_ping_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field time from ping message - * - * @return Unix timestamp in microseconds - */ -static inline uint64_t mavlink_msg_ping_get_time(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 6); -} - -/** - * @brief Decode a ping message into a struct - * - * @param msg The message to decode - * @param ping C-struct to decode the message contents into - */ -static inline void mavlink_msg_ping_decode(const mavlink_message_t* msg, mavlink_ping_t* ping) -{ -#if MAVLINK_NEED_BYTE_SWAP - ping->seq = mavlink_msg_ping_get_seq(msg); - ping->target_system = mavlink_msg_ping_get_target_system(msg); - ping->target_component = mavlink_msg_ping_get_target_component(msg); - ping->time = mavlink_msg_ping_get_time(msg); -#else - memcpy(ping, _MAV_PAYLOAD(msg), 14); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_position_target.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_position_target.h deleted file mode 100644 index 6cd7719fb2..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_position_target.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE POSITION_TARGET PACKING - -#define MAVLINK_MSG_ID_POSITION_TARGET 63 - -typedef struct __mavlink_position_target_t -{ - float x; ///< x position - float y; ///< y position - float z; ///< z position - float yaw; ///< yaw orientation in radians, 0 = NORTH -} mavlink_position_target_t; - -#define MAVLINK_MSG_ID_POSITION_TARGET_LEN 16 -#define MAVLINK_MSG_ID_63_LEN 16 - - - -#define MAVLINK_MESSAGE_INFO_POSITION_TARGET { \ - "POSITION_TARGET", \ - 4, \ - { { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_position_target_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_position_target_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_position_target_t, z) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_position_target_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a position_target message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_target_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_float(buf, 12, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_position_target_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_TARGET; - return mavlink_finalize_message(msg, system_id, component_id, 16); -} - -/** - * @brief Pack a position_target message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_target_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float x,float y,float z,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_float(buf, 12, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_position_target_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_TARGET; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 16); -} - -/** - * @brief Encode a position_target struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param position_target C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_position_target_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_position_target_t* position_target) -{ - return mavlink_msg_position_target_pack(system_id, component_id, msg, position_target->x, position_target->y, position_target->z, position_target->yaw); -} - -/** - * @brief Send a position_target message - * @param chan MAVLink channel to send the message - * - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_position_target_send(mavlink_channel_t chan, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_float(buf, 12, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_TARGET, buf, 16); -#else - mavlink_position_target_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_TARGET, (const char *)&packet, 16); -#endif -} - -#endif - -// MESSAGE POSITION_TARGET UNPACKING - - -/** - * @brief Get field x from position_target message - * - * @return x position - */ -static inline float mavlink_msg_position_target_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field y from position_target message - * - * @return y position - */ -static inline float mavlink_msg_position_target_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field z from position_target message - * - * @return z position - */ -static inline float mavlink_msg_position_target_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field yaw from position_target message - * - * @return yaw orientation in radians, 0 = NORTH - */ -static inline float mavlink_msg_position_target_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Decode a position_target message into a struct - * - * @param msg The message to decode - * @param position_target C-struct to decode the message contents into - */ -static inline void mavlink_msg_position_target_decode(const mavlink_message_t* msg, mavlink_position_target_t* position_target) -{ -#if MAVLINK_NEED_BYTE_SWAP - position_target->x = mavlink_msg_position_target_get_x(msg); - position_target->y = mavlink_msg_position_target_get_y(msg); - position_target->z = mavlink_msg_position_target_get_z(msg); - position_target->yaw = mavlink_msg_position_target_get_yaw(msg); -#else - memcpy(position_target, _MAV_PAYLOAD(msg), 16); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_raw_imu.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_raw_imu.h deleted file mode 100644 index c60945ae9f..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_raw_imu.h +++ /dev/null @@ -1,342 +0,0 @@ -// MESSAGE RAW_IMU PACKING - -#define MAVLINK_MSG_ID_RAW_IMU 28 - -typedef struct __mavlink_raw_imu_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - int16_t xacc; ///< X acceleration (raw) - int16_t yacc; ///< Y acceleration (raw) - int16_t zacc; ///< Z acceleration (raw) - int16_t xgyro; ///< Angular speed around X axis (raw) - int16_t ygyro; ///< Angular speed around Y axis (raw) - int16_t zgyro; ///< Angular speed around Z axis (raw) - int16_t xmag; ///< X Magnetic field (raw) - int16_t ymag; ///< Y Magnetic field (raw) - int16_t zmag; ///< Z Magnetic field (raw) -} mavlink_raw_imu_t; - -#define MAVLINK_MSG_ID_RAW_IMU_LEN 26 -#define MAVLINK_MSG_ID_28_LEN 26 - - - -#define MAVLINK_MESSAGE_INFO_RAW_IMU { \ - "RAW_IMU", \ - 10, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_raw_imu_t, usec) }, \ - { "xacc", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_raw_imu_t, xacc) }, \ - { "yacc", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_raw_imu_t, yacc) }, \ - { "zacc", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_raw_imu_t, zacc) }, \ - { "xgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_raw_imu_t, xgyro) }, \ - { "ygyro", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_raw_imu_t, ygyro) }, \ - { "zgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 18, offsetof(mavlink_raw_imu_t, zgyro) }, \ - { "xmag", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_raw_imu_t, xmag) }, \ - { "ymag", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_raw_imu_t, ymag) }, \ - { "zmag", NULL, MAVLINK_TYPE_INT16_T, 0, 24, offsetof(mavlink_raw_imu_t, zmag) }, \ - } \ -} - - -/** - * @brief Pack a raw_imu message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param xacc X acceleration (raw) - * @param yacc Y acceleration (raw) - * @param zacc Z acceleration (raw) - * @param xgyro Angular speed around X axis (raw) - * @param ygyro Angular speed around Y axis (raw) - * @param zgyro Angular speed around Z axis (raw) - * @param xmag X Magnetic field (raw) - * @param ymag Y Magnetic field (raw) - * @param zmag Z Magnetic field (raw) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_raw_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, xacc); - _mav_put_int16_t(buf, 10, yacc); - _mav_put_int16_t(buf, 12, zacc); - _mav_put_int16_t(buf, 14, xgyro); - _mav_put_int16_t(buf, 16, ygyro); - _mav_put_int16_t(buf, 18, zgyro); - _mav_put_int16_t(buf, 20, xmag); - _mav_put_int16_t(buf, 22, ymag); - _mav_put_int16_t(buf, 24, zmag); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_raw_imu_t packet; - packet.usec = usec; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - packet.xmag = xmag; - packet.ymag = ymag; - packet.zmag = zmag; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_RAW_IMU; - return mavlink_finalize_message(msg, system_id, component_id, 26); -} - -/** - * @brief Pack a raw_imu message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param xacc X acceleration (raw) - * @param yacc Y acceleration (raw) - * @param zacc Z acceleration (raw) - * @param xgyro Angular speed around X axis (raw) - * @param ygyro Angular speed around Y axis (raw) - * @param zgyro Angular speed around Z axis (raw) - * @param xmag X Magnetic field (raw) - * @param ymag Y Magnetic field (raw) - * @param zmag Z Magnetic field (raw) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_raw_imu_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,int16_t xacc,int16_t yacc,int16_t zacc,int16_t xgyro,int16_t ygyro,int16_t zgyro,int16_t xmag,int16_t ymag,int16_t zmag) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, xacc); - _mav_put_int16_t(buf, 10, yacc); - _mav_put_int16_t(buf, 12, zacc); - _mav_put_int16_t(buf, 14, xgyro); - _mav_put_int16_t(buf, 16, ygyro); - _mav_put_int16_t(buf, 18, zgyro); - _mav_put_int16_t(buf, 20, xmag); - _mav_put_int16_t(buf, 22, ymag); - _mav_put_int16_t(buf, 24, zmag); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_raw_imu_t packet; - packet.usec = usec; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - packet.xmag = xmag; - packet.ymag = ymag; - packet.zmag = zmag; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_RAW_IMU; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 26); -} - -/** - * @brief Encode a raw_imu struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param raw_imu C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_raw_imu_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_raw_imu_t* raw_imu) -{ - return mavlink_msg_raw_imu_pack(system_id, component_id, msg, raw_imu->usec, raw_imu->xacc, raw_imu->yacc, raw_imu->zacc, raw_imu->xgyro, raw_imu->ygyro, raw_imu->zgyro, raw_imu->xmag, raw_imu->ymag, raw_imu->zmag); -} - -/** - * @brief Send a raw_imu message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param xacc X acceleration (raw) - * @param yacc Y acceleration (raw) - * @param zacc Z acceleration (raw) - * @param xgyro Angular speed around X axis (raw) - * @param ygyro Angular speed around Y axis (raw) - * @param zgyro Angular speed around Z axis (raw) - * @param xmag X Magnetic field (raw) - * @param ymag Y Magnetic field (raw) - * @param zmag Z Magnetic field (raw) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_raw_imu_send(mavlink_channel_t chan, uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, xacc); - _mav_put_int16_t(buf, 10, yacc); - _mav_put_int16_t(buf, 12, zacc); - _mav_put_int16_t(buf, 14, xgyro); - _mav_put_int16_t(buf, 16, ygyro); - _mav_put_int16_t(buf, 18, zgyro); - _mav_put_int16_t(buf, 20, xmag); - _mav_put_int16_t(buf, 22, ymag); - _mav_put_int16_t(buf, 24, zmag); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, buf, 26); -#else - mavlink_raw_imu_t packet; - packet.usec = usec; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - packet.xmag = xmag; - packet.ymag = ymag; - packet.zmag = zmag; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_IMU, (const char *)&packet, 26); -#endif -} - -#endif - -// MESSAGE RAW_IMU UNPACKING - - -/** - * @brief Get field usec from raw_imu message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_raw_imu_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field xacc from raw_imu message - * - * @return X acceleration (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_xacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 8); -} - -/** - * @brief Get field yacc from raw_imu message - * - * @return Y acceleration (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_yacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 10); -} - -/** - * @brief Get field zacc from raw_imu message - * - * @return Z acceleration (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_zacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field xgyro from raw_imu message - * - * @return Angular speed around X axis (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_xgyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Get field ygyro from raw_imu message - * - * @return Angular speed around Y axis (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_ygyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 16); -} - -/** - * @brief Get field zgyro from raw_imu message - * - * @return Angular speed around Z axis (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_zgyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 18); -} - -/** - * @brief Get field xmag from raw_imu message - * - * @return X Magnetic field (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_xmag(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 20); -} - -/** - * @brief Get field ymag from raw_imu message - * - * @return Y Magnetic field (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_ymag(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 22); -} - -/** - * @brief Get field zmag from raw_imu message - * - * @return Z Magnetic field (raw) - */ -static inline int16_t mavlink_msg_raw_imu_get_zmag(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 24); -} - -/** - * @brief Decode a raw_imu message into a struct - * - * @param msg The message to decode - * @param raw_imu C-struct to decode the message contents into - */ -static inline void mavlink_msg_raw_imu_decode(const mavlink_message_t* msg, mavlink_raw_imu_t* raw_imu) -{ -#if MAVLINK_NEED_BYTE_SWAP - raw_imu->usec = mavlink_msg_raw_imu_get_usec(msg); - raw_imu->xacc = mavlink_msg_raw_imu_get_xacc(msg); - raw_imu->yacc = mavlink_msg_raw_imu_get_yacc(msg); - raw_imu->zacc = mavlink_msg_raw_imu_get_zacc(msg); - raw_imu->xgyro = mavlink_msg_raw_imu_get_xgyro(msg); - raw_imu->ygyro = mavlink_msg_raw_imu_get_ygyro(msg); - raw_imu->zgyro = mavlink_msg_raw_imu_get_zgyro(msg); - raw_imu->xmag = mavlink_msg_raw_imu_get_xmag(msg); - raw_imu->ymag = mavlink_msg_raw_imu_get_ymag(msg); - raw_imu->zmag = mavlink_msg_raw_imu_get_zmag(msg); -#else - memcpy(raw_imu, _MAV_PAYLOAD(msg), 26); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_raw_pressure.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_raw_pressure.h deleted file mode 100644 index b493b7e988..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_raw_pressure.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE RAW_PRESSURE PACKING - -#define MAVLINK_MSG_ID_RAW_PRESSURE 29 - -typedef struct __mavlink_raw_pressure_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - int16_t press_abs; ///< Absolute pressure (raw) - int16_t press_diff1; ///< Differential pressure 1 (raw) - int16_t press_diff2; ///< Differential pressure 2 (raw) - int16_t temperature; ///< Raw Temperature measurement (raw) -} mavlink_raw_pressure_t; - -#define MAVLINK_MSG_ID_RAW_PRESSURE_LEN 16 -#define MAVLINK_MSG_ID_29_LEN 16 - - - -#define MAVLINK_MESSAGE_INFO_RAW_PRESSURE { \ - "RAW_PRESSURE", \ - 5, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_raw_pressure_t, usec) }, \ - { "press_abs", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_raw_pressure_t, press_abs) }, \ - { "press_diff1", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_raw_pressure_t, press_diff1) }, \ - { "press_diff2", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_raw_pressure_t, press_diff2) }, \ - { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_raw_pressure_t, temperature) }, \ - } \ -} - - -/** - * @brief Pack a raw_pressure message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param press_abs Absolute pressure (raw) - * @param press_diff1 Differential pressure 1 (raw) - * @param press_diff2 Differential pressure 2 (raw) - * @param temperature Raw Temperature measurement (raw) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_raw_pressure_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, int16_t press_abs, int16_t press_diff1, int16_t press_diff2, int16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, press_abs); - _mav_put_int16_t(buf, 10, press_diff1); - _mav_put_int16_t(buf, 12, press_diff2); - _mav_put_int16_t(buf, 14, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_raw_pressure_t packet; - packet.usec = usec; - packet.press_abs = press_abs; - packet.press_diff1 = press_diff1; - packet.press_diff2 = press_diff2; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_RAW_PRESSURE; - return mavlink_finalize_message(msg, system_id, component_id, 16); -} - -/** - * @brief Pack a raw_pressure message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param press_abs Absolute pressure (raw) - * @param press_diff1 Differential pressure 1 (raw) - * @param press_diff2 Differential pressure 2 (raw) - * @param temperature Raw Temperature measurement (raw) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_raw_pressure_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,int16_t press_abs,int16_t press_diff1,int16_t press_diff2,int16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, press_abs); - _mav_put_int16_t(buf, 10, press_diff1); - _mav_put_int16_t(buf, 12, press_diff2); - _mav_put_int16_t(buf, 14, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_raw_pressure_t packet; - packet.usec = usec; - packet.press_abs = press_abs; - packet.press_diff1 = press_diff1; - packet.press_diff2 = press_diff2; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_RAW_PRESSURE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 16); -} - -/** - * @brief Encode a raw_pressure struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param raw_pressure C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_raw_pressure_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_raw_pressure_t* raw_pressure) -{ - return mavlink_msg_raw_pressure_pack(system_id, component_id, msg, raw_pressure->usec, raw_pressure->press_abs, raw_pressure->press_diff1, raw_pressure->press_diff2, raw_pressure->temperature); -} - -/** - * @brief Send a raw_pressure message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param press_abs Absolute pressure (raw) - * @param press_diff1 Differential pressure 1 (raw) - * @param press_diff2 Differential pressure 2 (raw) - * @param temperature Raw Temperature measurement (raw) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_raw_pressure_send(mavlink_channel_t chan, uint64_t usec, int16_t press_abs, int16_t press_diff1, int16_t press_diff2, int16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, press_abs); - _mav_put_int16_t(buf, 10, press_diff1); - _mav_put_int16_t(buf, 12, press_diff2); - _mav_put_int16_t(buf, 14, temperature); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_PRESSURE, buf, 16); -#else - mavlink_raw_pressure_t packet; - packet.usec = usec; - packet.press_abs = press_abs; - packet.press_diff1 = press_diff1; - packet.press_diff2 = press_diff2; - packet.temperature = temperature; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_PRESSURE, (const char *)&packet, 16); -#endif -} - -#endif - -// MESSAGE RAW_PRESSURE UNPACKING - - -/** - * @brief Get field usec from raw_pressure message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_raw_pressure_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field press_abs from raw_pressure message - * - * @return Absolute pressure (raw) - */ -static inline int16_t mavlink_msg_raw_pressure_get_press_abs(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 8); -} - -/** - * @brief Get field press_diff1 from raw_pressure message - * - * @return Differential pressure 1 (raw) - */ -static inline int16_t mavlink_msg_raw_pressure_get_press_diff1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 10); -} - -/** - * @brief Get field press_diff2 from raw_pressure message - * - * @return Differential pressure 2 (raw) - */ -static inline int16_t mavlink_msg_raw_pressure_get_press_diff2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field temperature from raw_pressure message - * - * @return Raw Temperature measurement (raw) - */ -static inline int16_t mavlink_msg_raw_pressure_get_temperature(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Decode a raw_pressure message into a struct - * - * @param msg The message to decode - * @param raw_pressure C-struct to decode the message contents into - */ -static inline void mavlink_msg_raw_pressure_decode(const mavlink_message_t* msg, mavlink_raw_pressure_t* raw_pressure) -{ -#if MAVLINK_NEED_BYTE_SWAP - raw_pressure->usec = mavlink_msg_raw_pressure_get_usec(msg); - raw_pressure->press_abs = mavlink_msg_raw_pressure_get_press_abs(msg); - raw_pressure->press_diff1 = mavlink_msg_raw_pressure_get_press_diff1(msg); - raw_pressure->press_diff2 = mavlink_msg_raw_pressure_get_press_diff2(msg); - raw_pressure->temperature = mavlink_msg_raw_pressure_get_temperature(msg); -#else - memcpy(raw_pressure, _MAV_PAYLOAD(msg), 16); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_override.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_override.h deleted file mode 100644 index 30e5a8f98e..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_override.h +++ /dev/null @@ -1,342 +0,0 @@ -// MESSAGE RC_CHANNELS_OVERRIDE PACKING - -#define MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE 70 - -typedef struct __mavlink_rc_channels_override_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint16_t chan1_raw; ///< RC channel 1 value, in microseconds - uint16_t chan2_raw; ///< RC channel 2 value, in microseconds - uint16_t chan3_raw; ///< RC channel 3 value, in microseconds - uint16_t chan4_raw; ///< RC channel 4 value, in microseconds - uint16_t chan5_raw; ///< RC channel 5 value, in microseconds - uint16_t chan6_raw; ///< RC channel 6 value, in microseconds - uint16_t chan7_raw; ///< RC channel 7 value, in microseconds - uint16_t chan8_raw; ///< RC channel 8 value, in microseconds -} mavlink_rc_channels_override_t; - -#define MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE_LEN 18 -#define MAVLINK_MSG_ID_70_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE { \ - "RC_CHANNELS_OVERRIDE", \ - 10, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_rc_channels_override_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_rc_channels_override_t, target_component) }, \ - { "chan1_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_rc_channels_override_t, chan1_raw) }, \ - { "chan2_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_rc_channels_override_t, chan2_raw) }, \ - { "chan3_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_rc_channels_override_t, chan3_raw) }, \ - { "chan4_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_rc_channels_override_t, chan4_raw) }, \ - { "chan5_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_rc_channels_override_t, chan5_raw) }, \ - { "chan6_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 12, offsetof(mavlink_rc_channels_override_t, chan6_raw) }, \ - { "chan7_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 14, offsetof(mavlink_rc_channels_override_t, chan7_raw) }, \ - { "chan8_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 16, offsetof(mavlink_rc_channels_override_t, chan8_raw) }, \ - } \ -} - - -/** - * @brief Pack a rc_channels_override message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_rc_channels_override_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint16_t chan1_raw, uint16_t chan2_raw, uint16_t chan3_raw, uint16_t chan4_raw, uint16_t chan5_raw, uint16_t chan6_raw, uint16_t chan7_raw, uint16_t chan8_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, chan1_raw); - _mav_put_uint16_t(buf, 4, chan2_raw); - _mav_put_uint16_t(buf, 6, chan3_raw); - _mav_put_uint16_t(buf, 8, chan4_raw); - _mav_put_uint16_t(buf, 10, chan5_raw); - _mav_put_uint16_t(buf, 12, chan6_raw); - _mav_put_uint16_t(buf, 14, chan7_raw); - _mav_put_uint16_t(buf, 16, chan8_raw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_rc_channels_override_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.chan1_raw = chan1_raw; - packet.chan2_raw = chan2_raw; - packet.chan3_raw = chan3_raw; - packet.chan4_raw = chan4_raw; - packet.chan5_raw = chan5_raw; - packet.chan6_raw = chan6_raw; - packet.chan7_raw = chan7_raw; - packet.chan8_raw = chan8_raw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a rc_channels_override message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_rc_channels_override_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint16_t chan1_raw,uint16_t chan2_raw,uint16_t chan3_raw,uint16_t chan4_raw,uint16_t chan5_raw,uint16_t chan6_raw,uint16_t chan7_raw,uint16_t chan8_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, chan1_raw); - _mav_put_uint16_t(buf, 4, chan2_raw); - _mav_put_uint16_t(buf, 6, chan3_raw); - _mav_put_uint16_t(buf, 8, chan4_raw); - _mav_put_uint16_t(buf, 10, chan5_raw); - _mav_put_uint16_t(buf, 12, chan6_raw); - _mav_put_uint16_t(buf, 14, chan7_raw); - _mav_put_uint16_t(buf, 16, chan8_raw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_rc_channels_override_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.chan1_raw = chan1_raw; - packet.chan2_raw = chan2_raw; - packet.chan3_raw = chan3_raw; - packet.chan4_raw = chan4_raw; - packet.chan5_raw = chan5_raw; - packet.chan6_raw = chan6_raw; - packet.chan7_raw = chan7_raw; - packet.chan8_raw = chan8_raw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a rc_channels_override struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param rc_channels_override C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_rc_channels_override_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_rc_channels_override_t* rc_channels_override) -{ - return mavlink_msg_rc_channels_override_pack(system_id, component_id, msg, rc_channels_override->target_system, rc_channels_override->target_component, rc_channels_override->chan1_raw, rc_channels_override->chan2_raw, rc_channels_override->chan3_raw, rc_channels_override->chan4_raw, rc_channels_override->chan5_raw, rc_channels_override->chan6_raw, rc_channels_override->chan7_raw, rc_channels_override->chan8_raw); -} - -/** - * @brief Send a rc_channels_override message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_rc_channels_override_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t chan1_raw, uint16_t chan2_raw, uint16_t chan3_raw, uint16_t chan4_raw, uint16_t chan5_raw, uint16_t chan6_raw, uint16_t chan7_raw, uint16_t chan8_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, chan1_raw); - _mav_put_uint16_t(buf, 4, chan2_raw); - _mav_put_uint16_t(buf, 6, chan3_raw); - _mav_put_uint16_t(buf, 8, chan4_raw); - _mav_put_uint16_t(buf, 10, chan5_raw); - _mav_put_uint16_t(buf, 12, chan6_raw); - _mav_put_uint16_t(buf, 14, chan7_raw); - _mav_put_uint16_t(buf, 16, chan8_raw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE, buf, 18); -#else - mavlink_rc_channels_override_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.chan1_raw = chan1_raw; - packet.chan2_raw = chan2_raw; - packet.chan3_raw = chan3_raw; - packet.chan4_raw = chan4_raw; - packet.chan5_raw = chan5_raw; - packet.chan6_raw = chan6_raw; - packet.chan7_raw = chan7_raw; - packet.chan8_raw = chan8_raw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE RC_CHANNELS_OVERRIDE UNPACKING - - -/** - * @brief Get field target_system from rc_channels_override message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_rc_channels_override_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from rc_channels_override message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_rc_channels_override_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field chan1_raw from rc_channels_override message - * - * @return RC channel 1 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan1_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field chan2_raw from rc_channels_override message - * - * @return RC channel 2 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan2_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 4); -} - -/** - * @brief Get field chan3_raw from rc_channels_override message - * - * @return RC channel 3 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan3_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 6); -} - -/** - * @brief Get field chan4_raw from rc_channels_override message - * - * @return RC channel 4 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan4_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Get field chan5_raw from rc_channels_override message - * - * @return RC channel 5 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan5_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 10); -} - -/** - * @brief Get field chan6_raw from rc_channels_override message - * - * @return RC channel 6 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan6_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 12); -} - -/** - * @brief Get field chan7_raw from rc_channels_override message - * - * @return RC channel 7 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan7_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 14); -} - -/** - * @brief Get field chan8_raw from rc_channels_override message - * - * @return RC channel 8 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_override_get_chan8_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 16); -} - -/** - * @brief Decode a rc_channels_override message into a struct - * - * @param msg The message to decode - * @param rc_channels_override C-struct to decode the message contents into - */ -static inline void mavlink_msg_rc_channels_override_decode(const mavlink_message_t* msg, mavlink_rc_channels_override_t* rc_channels_override) -{ -#if MAVLINK_NEED_BYTE_SWAP - rc_channels_override->target_system = mavlink_msg_rc_channels_override_get_target_system(msg); - rc_channels_override->target_component = mavlink_msg_rc_channels_override_get_target_component(msg); - rc_channels_override->chan1_raw = mavlink_msg_rc_channels_override_get_chan1_raw(msg); - rc_channels_override->chan2_raw = mavlink_msg_rc_channels_override_get_chan2_raw(msg); - rc_channels_override->chan3_raw = mavlink_msg_rc_channels_override_get_chan3_raw(msg); - rc_channels_override->chan4_raw = mavlink_msg_rc_channels_override_get_chan4_raw(msg); - rc_channels_override->chan5_raw = mavlink_msg_rc_channels_override_get_chan5_raw(msg); - rc_channels_override->chan6_raw = mavlink_msg_rc_channels_override_get_chan6_raw(msg); - rc_channels_override->chan7_raw = mavlink_msg_rc_channels_override_get_chan7_raw(msg); - rc_channels_override->chan8_raw = mavlink_msg_rc_channels_override_get_chan8_raw(msg); -#else - memcpy(rc_channels_override, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_raw.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_raw.h deleted file mode 100644 index 855f7cced3..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_raw.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE RC_CHANNELS_RAW PACKING - -#define MAVLINK_MSG_ID_RC_CHANNELS_RAW 35 - -typedef struct __mavlink_rc_channels_raw_t -{ - uint16_t chan1_raw; ///< RC channel 1 value, in microseconds - uint16_t chan2_raw; ///< RC channel 2 value, in microseconds - uint16_t chan3_raw; ///< RC channel 3 value, in microseconds - uint16_t chan4_raw; ///< RC channel 4 value, in microseconds - uint16_t chan5_raw; ///< RC channel 5 value, in microseconds - uint16_t chan6_raw; ///< RC channel 6 value, in microseconds - uint16_t chan7_raw; ///< RC channel 7 value, in microseconds - uint16_t chan8_raw; ///< RC channel 8 value, in microseconds - uint8_t rssi; ///< Receive signal strength indicator, 0: 0%, 255: 100% -} mavlink_rc_channels_raw_t; - -#define MAVLINK_MSG_ID_RC_CHANNELS_RAW_LEN 17 -#define MAVLINK_MSG_ID_35_LEN 17 - - - -#define MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW { \ - "RC_CHANNELS_RAW", \ - 9, \ - { { "chan1_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_rc_channels_raw_t, chan1_raw) }, \ - { "chan2_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_rc_channels_raw_t, chan2_raw) }, \ - { "chan3_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_rc_channels_raw_t, chan3_raw) }, \ - { "chan4_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_rc_channels_raw_t, chan4_raw) }, \ - { "chan5_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_rc_channels_raw_t, chan5_raw) }, \ - { "chan6_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_rc_channels_raw_t, chan6_raw) }, \ - { "chan7_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 12, offsetof(mavlink_rc_channels_raw_t, chan7_raw) }, \ - { "chan8_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 14, offsetof(mavlink_rc_channels_raw_t, chan8_raw) }, \ - { "rssi", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_rc_channels_raw_t, rssi) }, \ - } \ -} - - -/** - * @brief Pack a rc_channels_raw message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_rc_channels_raw_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t chan1_raw, uint16_t chan2_raw, uint16_t chan3_raw, uint16_t chan4_raw, uint16_t chan5_raw, uint16_t chan6_raw, uint16_t chan7_raw, uint16_t chan8_raw, uint8_t rssi) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[17]; - _mav_put_uint16_t(buf, 0, chan1_raw); - _mav_put_uint16_t(buf, 2, chan2_raw); - _mav_put_uint16_t(buf, 4, chan3_raw); - _mav_put_uint16_t(buf, 6, chan4_raw); - _mav_put_uint16_t(buf, 8, chan5_raw); - _mav_put_uint16_t(buf, 10, chan6_raw); - _mav_put_uint16_t(buf, 12, chan7_raw); - _mav_put_uint16_t(buf, 14, chan8_raw); - _mav_put_uint8_t(buf, 16, rssi); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 17); -#else - mavlink_rc_channels_raw_t packet; - packet.chan1_raw = chan1_raw; - packet.chan2_raw = chan2_raw; - packet.chan3_raw = chan3_raw; - packet.chan4_raw = chan4_raw; - packet.chan5_raw = chan5_raw; - packet.chan6_raw = chan6_raw; - packet.chan7_raw = chan7_raw; - packet.chan8_raw = chan8_raw; - packet.rssi = rssi; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 17); -#endif - - msg->msgid = MAVLINK_MSG_ID_RC_CHANNELS_RAW; - return mavlink_finalize_message(msg, system_id, component_id, 17); -} - -/** - * @brief Pack a rc_channels_raw message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_rc_channels_raw_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t chan1_raw,uint16_t chan2_raw,uint16_t chan3_raw,uint16_t chan4_raw,uint16_t chan5_raw,uint16_t chan6_raw,uint16_t chan7_raw,uint16_t chan8_raw,uint8_t rssi) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[17]; - _mav_put_uint16_t(buf, 0, chan1_raw); - _mav_put_uint16_t(buf, 2, chan2_raw); - _mav_put_uint16_t(buf, 4, chan3_raw); - _mav_put_uint16_t(buf, 6, chan4_raw); - _mav_put_uint16_t(buf, 8, chan5_raw); - _mav_put_uint16_t(buf, 10, chan6_raw); - _mav_put_uint16_t(buf, 12, chan7_raw); - _mav_put_uint16_t(buf, 14, chan8_raw); - _mav_put_uint8_t(buf, 16, rssi); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 17); -#else - mavlink_rc_channels_raw_t packet; - packet.chan1_raw = chan1_raw; - packet.chan2_raw = chan2_raw; - packet.chan3_raw = chan3_raw; - packet.chan4_raw = chan4_raw; - packet.chan5_raw = chan5_raw; - packet.chan6_raw = chan6_raw; - packet.chan7_raw = chan7_raw; - packet.chan8_raw = chan8_raw; - packet.rssi = rssi; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 17); -#endif - - msg->msgid = MAVLINK_MSG_ID_RC_CHANNELS_RAW; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 17); -} - -/** - * @brief Encode a rc_channels_raw struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param rc_channels_raw C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_rc_channels_raw_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_rc_channels_raw_t* rc_channels_raw) -{ - return mavlink_msg_rc_channels_raw_pack(system_id, component_id, msg, rc_channels_raw->chan1_raw, rc_channels_raw->chan2_raw, rc_channels_raw->chan3_raw, rc_channels_raw->chan4_raw, rc_channels_raw->chan5_raw, rc_channels_raw->chan6_raw, rc_channels_raw->chan7_raw, rc_channels_raw->chan8_raw, rc_channels_raw->rssi); -} - -/** - * @brief Send a rc_channels_raw message - * @param chan MAVLink channel to send the message - * - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_rc_channels_raw_send(mavlink_channel_t chan, uint16_t chan1_raw, uint16_t chan2_raw, uint16_t chan3_raw, uint16_t chan4_raw, uint16_t chan5_raw, uint16_t chan6_raw, uint16_t chan7_raw, uint16_t chan8_raw, uint8_t rssi) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[17]; - _mav_put_uint16_t(buf, 0, chan1_raw); - _mav_put_uint16_t(buf, 2, chan2_raw); - _mav_put_uint16_t(buf, 4, chan3_raw); - _mav_put_uint16_t(buf, 6, chan4_raw); - _mav_put_uint16_t(buf, 8, chan5_raw); - _mav_put_uint16_t(buf, 10, chan6_raw); - _mav_put_uint16_t(buf, 12, chan7_raw); - _mav_put_uint16_t(buf, 14, chan8_raw); - _mav_put_uint8_t(buf, 16, rssi); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RC_CHANNELS_RAW, buf, 17); -#else - mavlink_rc_channels_raw_t packet; - packet.chan1_raw = chan1_raw; - packet.chan2_raw = chan2_raw; - packet.chan3_raw = chan3_raw; - packet.chan4_raw = chan4_raw; - packet.chan5_raw = chan5_raw; - packet.chan6_raw = chan6_raw; - packet.chan7_raw = chan7_raw; - packet.chan8_raw = chan8_raw; - packet.rssi = rssi; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RC_CHANNELS_RAW, (const char *)&packet, 17); -#endif -} - -#endif - -// MESSAGE RC_CHANNELS_RAW UNPACKING - - -/** - * @brief Get field chan1_raw from rc_channels_raw message - * - * @return RC channel 1 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan1_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field chan2_raw from rc_channels_raw message - * - * @return RC channel 2 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan2_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field chan3_raw from rc_channels_raw message - * - * @return RC channel 3 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan3_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 4); -} - -/** - * @brief Get field chan4_raw from rc_channels_raw message - * - * @return RC channel 4 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan4_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 6); -} - -/** - * @brief Get field chan5_raw from rc_channels_raw message - * - * @return RC channel 5 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan5_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Get field chan6_raw from rc_channels_raw message - * - * @return RC channel 6 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan6_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 10); -} - -/** - * @brief Get field chan7_raw from rc_channels_raw message - * - * @return RC channel 7 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan7_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 12); -} - -/** - * @brief Get field chan8_raw from rc_channels_raw message - * - * @return RC channel 8 value, in microseconds - */ -static inline uint16_t mavlink_msg_rc_channels_raw_get_chan8_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 14); -} - -/** - * @brief Get field rssi from rc_channels_raw message - * - * @return Receive signal strength indicator, 0: 0%, 255: 100% - */ -static inline uint8_t mavlink_msg_rc_channels_raw_get_rssi(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 16); -} - -/** - * @brief Decode a rc_channels_raw message into a struct - * - * @param msg The message to decode - * @param rc_channels_raw C-struct to decode the message contents into - */ -static inline void mavlink_msg_rc_channels_raw_decode(const mavlink_message_t* msg, mavlink_rc_channels_raw_t* rc_channels_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP - rc_channels_raw->chan1_raw = mavlink_msg_rc_channels_raw_get_chan1_raw(msg); - rc_channels_raw->chan2_raw = mavlink_msg_rc_channels_raw_get_chan2_raw(msg); - rc_channels_raw->chan3_raw = mavlink_msg_rc_channels_raw_get_chan3_raw(msg); - rc_channels_raw->chan4_raw = mavlink_msg_rc_channels_raw_get_chan4_raw(msg); - rc_channels_raw->chan5_raw = mavlink_msg_rc_channels_raw_get_chan5_raw(msg); - rc_channels_raw->chan6_raw = mavlink_msg_rc_channels_raw_get_chan6_raw(msg); - rc_channels_raw->chan7_raw = mavlink_msg_rc_channels_raw_get_chan7_raw(msg); - rc_channels_raw->chan8_raw = mavlink_msg_rc_channels_raw_get_chan8_raw(msg); - rc_channels_raw->rssi = mavlink_msg_rc_channels_raw_get_rssi(msg); -#else - memcpy(rc_channels_raw, _MAV_PAYLOAD(msg), 17); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_scaled.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_scaled.h deleted file mode 100644 index 49df14a7ac..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_rc_channels_scaled.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE RC_CHANNELS_SCALED PACKING - -#define MAVLINK_MSG_ID_RC_CHANNELS_SCALED 36 - -typedef struct __mavlink_rc_channels_scaled_t -{ - int16_t chan1_scaled; ///< RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan2_scaled; ///< RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan3_scaled; ///< RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan4_scaled; ///< RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan5_scaled; ///< RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan6_scaled; ///< RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan7_scaled; ///< RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan8_scaled; ///< RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - uint8_t rssi; ///< Receive signal strength indicator, 0: 0%, 255: 100% -} mavlink_rc_channels_scaled_t; - -#define MAVLINK_MSG_ID_RC_CHANNELS_SCALED_LEN 17 -#define MAVLINK_MSG_ID_36_LEN 17 - - - -#define MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED { \ - "RC_CHANNELS_SCALED", \ - 9, \ - { { "chan1_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 0, offsetof(mavlink_rc_channels_scaled_t, chan1_scaled) }, \ - { "chan2_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 2, offsetof(mavlink_rc_channels_scaled_t, chan2_scaled) }, \ - { "chan3_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 4, offsetof(mavlink_rc_channels_scaled_t, chan3_scaled) }, \ - { "chan4_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 6, offsetof(mavlink_rc_channels_scaled_t, chan4_scaled) }, \ - { "chan5_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_rc_channels_scaled_t, chan5_scaled) }, \ - { "chan6_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_rc_channels_scaled_t, chan6_scaled) }, \ - { "chan7_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_rc_channels_scaled_t, chan7_scaled) }, \ - { "chan8_scaled", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_rc_channels_scaled_t, chan8_scaled) }, \ - { "rssi", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_rc_channels_scaled_t, rssi) }, \ - } \ -} - - -/** - * @brief Pack a rc_channels_scaled message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_rc_channels_scaled_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - int16_t chan1_scaled, int16_t chan2_scaled, int16_t chan3_scaled, int16_t chan4_scaled, int16_t chan5_scaled, int16_t chan6_scaled, int16_t chan7_scaled, int16_t chan8_scaled, uint8_t rssi) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[17]; - _mav_put_int16_t(buf, 0, chan1_scaled); - _mav_put_int16_t(buf, 2, chan2_scaled); - _mav_put_int16_t(buf, 4, chan3_scaled); - _mav_put_int16_t(buf, 6, chan4_scaled); - _mav_put_int16_t(buf, 8, chan5_scaled); - _mav_put_int16_t(buf, 10, chan6_scaled); - _mav_put_int16_t(buf, 12, chan7_scaled); - _mav_put_int16_t(buf, 14, chan8_scaled); - _mav_put_uint8_t(buf, 16, rssi); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 17); -#else - mavlink_rc_channels_scaled_t packet; - packet.chan1_scaled = chan1_scaled; - packet.chan2_scaled = chan2_scaled; - packet.chan3_scaled = chan3_scaled; - packet.chan4_scaled = chan4_scaled; - packet.chan5_scaled = chan5_scaled; - packet.chan6_scaled = chan6_scaled; - packet.chan7_scaled = chan7_scaled; - packet.chan8_scaled = chan8_scaled; - packet.rssi = rssi; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 17); -#endif - - msg->msgid = MAVLINK_MSG_ID_RC_CHANNELS_SCALED; - return mavlink_finalize_message(msg, system_id, component_id, 17); -} - -/** - * @brief Pack a rc_channels_scaled message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_rc_channels_scaled_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - int16_t chan1_scaled,int16_t chan2_scaled,int16_t chan3_scaled,int16_t chan4_scaled,int16_t chan5_scaled,int16_t chan6_scaled,int16_t chan7_scaled,int16_t chan8_scaled,uint8_t rssi) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[17]; - _mav_put_int16_t(buf, 0, chan1_scaled); - _mav_put_int16_t(buf, 2, chan2_scaled); - _mav_put_int16_t(buf, 4, chan3_scaled); - _mav_put_int16_t(buf, 6, chan4_scaled); - _mav_put_int16_t(buf, 8, chan5_scaled); - _mav_put_int16_t(buf, 10, chan6_scaled); - _mav_put_int16_t(buf, 12, chan7_scaled); - _mav_put_int16_t(buf, 14, chan8_scaled); - _mav_put_uint8_t(buf, 16, rssi); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 17); -#else - mavlink_rc_channels_scaled_t packet; - packet.chan1_scaled = chan1_scaled; - packet.chan2_scaled = chan2_scaled; - packet.chan3_scaled = chan3_scaled; - packet.chan4_scaled = chan4_scaled; - packet.chan5_scaled = chan5_scaled; - packet.chan6_scaled = chan6_scaled; - packet.chan7_scaled = chan7_scaled; - packet.chan8_scaled = chan8_scaled; - packet.rssi = rssi; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 17); -#endif - - msg->msgid = MAVLINK_MSG_ID_RC_CHANNELS_SCALED; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 17); -} - -/** - * @brief Encode a rc_channels_scaled struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param rc_channels_scaled C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_rc_channels_scaled_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_rc_channels_scaled_t* rc_channels_scaled) -{ - return mavlink_msg_rc_channels_scaled_pack(system_id, component_id, msg, rc_channels_scaled->chan1_scaled, rc_channels_scaled->chan2_scaled, rc_channels_scaled->chan3_scaled, rc_channels_scaled->chan4_scaled, rc_channels_scaled->chan5_scaled, rc_channels_scaled->chan6_scaled, rc_channels_scaled->chan7_scaled, rc_channels_scaled->chan8_scaled, rc_channels_scaled->rssi); -} - -/** - * @brief Send a rc_channels_scaled message - * @param chan MAVLink channel to send the message - * - * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_rc_channels_scaled_send(mavlink_channel_t chan, int16_t chan1_scaled, int16_t chan2_scaled, int16_t chan3_scaled, int16_t chan4_scaled, int16_t chan5_scaled, int16_t chan6_scaled, int16_t chan7_scaled, int16_t chan8_scaled, uint8_t rssi) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[17]; - _mav_put_int16_t(buf, 0, chan1_scaled); - _mav_put_int16_t(buf, 2, chan2_scaled); - _mav_put_int16_t(buf, 4, chan3_scaled); - _mav_put_int16_t(buf, 6, chan4_scaled); - _mav_put_int16_t(buf, 8, chan5_scaled); - _mav_put_int16_t(buf, 10, chan6_scaled); - _mav_put_int16_t(buf, 12, chan7_scaled); - _mav_put_int16_t(buf, 14, chan8_scaled); - _mav_put_uint8_t(buf, 16, rssi); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RC_CHANNELS_SCALED, buf, 17); -#else - mavlink_rc_channels_scaled_t packet; - packet.chan1_scaled = chan1_scaled; - packet.chan2_scaled = chan2_scaled; - packet.chan3_scaled = chan3_scaled; - packet.chan4_scaled = chan4_scaled; - packet.chan5_scaled = chan5_scaled; - packet.chan6_scaled = chan6_scaled; - packet.chan7_scaled = chan7_scaled; - packet.chan8_scaled = chan8_scaled; - packet.rssi = rssi; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RC_CHANNELS_SCALED, (const char *)&packet, 17); -#endif -} - -#endif - -// MESSAGE RC_CHANNELS_SCALED UNPACKING - - -/** - * @brief Get field chan1_scaled from rc_channels_scaled message - * - * @return RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan1_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 0); -} - -/** - * @brief Get field chan2_scaled from rc_channels_scaled message - * - * @return RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan2_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 2); -} - -/** - * @brief Get field chan3_scaled from rc_channels_scaled message - * - * @return RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan3_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 4); -} - -/** - * @brief Get field chan4_scaled from rc_channels_scaled message - * - * @return RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan4_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 6); -} - -/** - * @brief Get field chan5_scaled from rc_channels_scaled message - * - * @return RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan5_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 8); -} - -/** - * @brief Get field chan6_scaled from rc_channels_scaled message - * - * @return RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan6_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 10); -} - -/** - * @brief Get field chan7_scaled from rc_channels_scaled message - * - * @return RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan7_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field chan8_scaled from rc_channels_scaled message - * - * @return RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - */ -static inline int16_t mavlink_msg_rc_channels_scaled_get_chan8_scaled(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Get field rssi from rc_channels_scaled message - * - * @return Receive signal strength indicator, 0: 0%, 255: 100% - */ -static inline uint8_t mavlink_msg_rc_channels_scaled_get_rssi(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 16); -} - -/** - * @brief Decode a rc_channels_scaled message into a struct - * - * @param msg The message to decode - * @param rc_channels_scaled C-struct to decode the message contents into - */ -static inline void mavlink_msg_rc_channels_scaled_decode(const mavlink_message_t* msg, mavlink_rc_channels_scaled_t* rc_channels_scaled) -{ -#if MAVLINK_NEED_BYTE_SWAP - rc_channels_scaled->chan1_scaled = mavlink_msg_rc_channels_scaled_get_chan1_scaled(msg); - rc_channels_scaled->chan2_scaled = mavlink_msg_rc_channels_scaled_get_chan2_scaled(msg); - rc_channels_scaled->chan3_scaled = mavlink_msg_rc_channels_scaled_get_chan3_scaled(msg); - rc_channels_scaled->chan4_scaled = mavlink_msg_rc_channels_scaled_get_chan4_scaled(msg); - rc_channels_scaled->chan5_scaled = mavlink_msg_rc_channels_scaled_get_chan5_scaled(msg); - rc_channels_scaled->chan6_scaled = mavlink_msg_rc_channels_scaled_get_chan6_scaled(msg); - rc_channels_scaled->chan7_scaled = mavlink_msg_rc_channels_scaled_get_chan7_scaled(msg); - rc_channels_scaled->chan8_scaled = mavlink_msg_rc_channels_scaled_get_chan8_scaled(msg); - rc_channels_scaled->rssi = mavlink_msg_rc_channels_scaled_get_rssi(msg); -#else - memcpy(rc_channels_scaled, _MAV_PAYLOAD(msg), 17); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_request_data_stream.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_request_data_stream.h deleted file mode 100644 index e80473aa11..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_request_data_stream.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE REQUEST_DATA_STREAM PACKING - -#define MAVLINK_MSG_ID_REQUEST_DATA_STREAM 66 - -typedef struct __mavlink_request_data_stream_t -{ - uint8_t target_system; ///< The target requested to send the message stream. - uint8_t target_component; ///< The target requested to send the message stream. - uint8_t req_stream_id; ///< The ID of the requested message type - uint16_t req_message_rate; ///< Update rate in Hertz - uint8_t start_stop; ///< 1 to start sending, 0 to stop sending. -} mavlink_request_data_stream_t; - -#define MAVLINK_MSG_ID_REQUEST_DATA_STREAM_LEN 6 -#define MAVLINK_MSG_ID_66_LEN 6 - - - -#define MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM { \ - "REQUEST_DATA_STREAM", \ - 5, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_request_data_stream_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_request_data_stream_t, target_component) }, \ - { "req_stream_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_request_data_stream_t, req_stream_id) }, \ - { "req_message_rate", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_request_data_stream_t, req_message_rate) }, \ - { "start_stop", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_request_data_stream_t, start_stop) }, \ - } \ -} - - -/** - * @brief Pack a request_data_stream message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system The target requested to send the message stream. - * @param target_component The target requested to send the message stream. - * @param req_stream_id The ID of the requested message type - * @param req_message_rate Update rate in Hertz - * @param start_stop 1 to start sending, 0 to stop sending. - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_request_data_stream_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t req_stream_id, uint16_t req_message_rate, uint8_t start_stop) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, req_stream_id); - _mav_put_uint16_t(buf, 3, req_message_rate); - _mav_put_uint8_t(buf, 5, start_stop); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 6); -#else - mavlink_request_data_stream_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.req_stream_id = req_stream_id; - packet.req_message_rate = req_message_rate; - packet.start_stop = start_stop; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 6); -#endif - - msg->msgid = MAVLINK_MSG_ID_REQUEST_DATA_STREAM; - return mavlink_finalize_message(msg, system_id, component_id, 6); -} - -/** - * @brief Pack a request_data_stream message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system The target requested to send the message stream. - * @param target_component The target requested to send the message stream. - * @param req_stream_id The ID of the requested message type - * @param req_message_rate Update rate in Hertz - * @param start_stop 1 to start sending, 0 to stop sending. - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_request_data_stream_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t req_stream_id,uint16_t req_message_rate,uint8_t start_stop) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, req_stream_id); - _mav_put_uint16_t(buf, 3, req_message_rate); - _mav_put_uint8_t(buf, 5, start_stop); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 6); -#else - mavlink_request_data_stream_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.req_stream_id = req_stream_id; - packet.req_message_rate = req_message_rate; - packet.start_stop = start_stop; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 6); -#endif - - msg->msgid = MAVLINK_MSG_ID_REQUEST_DATA_STREAM; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 6); -} - -/** - * @brief Encode a request_data_stream struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param request_data_stream C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_request_data_stream_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_request_data_stream_t* request_data_stream) -{ - return mavlink_msg_request_data_stream_pack(system_id, component_id, msg, request_data_stream->target_system, request_data_stream->target_component, request_data_stream->req_stream_id, request_data_stream->req_message_rate, request_data_stream->start_stop); -} - -/** - * @brief Send a request_data_stream message - * @param chan MAVLink channel to send the message - * - * @param target_system The target requested to send the message stream. - * @param target_component The target requested to send the message stream. - * @param req_stream_id The ID of the requested message type - * @param req_message_rate Update rate in Hertz - * @param start_stop 1 to start sending, 0 to stop sending. - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_request_data_stream_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t req_stream_id, uint16_t req_message_rate, uint8_t start_stop) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, req_stream_id); - _mav_put_uint16_t(buf, 3, req_message_rate); - _mav_put_uint8_t(buf, 5, start_stop); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_REQUEST_DATA_STREAM, buf, 6); -#else - mavlink_request_data_stream_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.req_stream_id = req_stream_id; - packet.req_message_rate = req_message_rate; - packet.start_stop = start_stop; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_REQUEST_DATA_STREAM, (const char *)&packet, 6); -#endif -} - -#endif - -// MESSAGE REQUEST_DATA_STREAM UNPACKING - - -/** - * @brief Get field target_system from request_data_stream message - * - * @return The target requested to send the message stream. - */ -static inline uint8_t mavlink_msg_request_data_stream_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from request_data_stream message - * - * @return The target requested to send the message stream. - */ -static inline uint8_t mavlink_msg_request_data_stream_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field req_stream_id from request_data_stream message - * - * @return The ID of the requested message type - */ -static inline uint8_t mavlink_msg_request_data_stream_get_req_stream_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field req_message_rate from request_data_stream message - * - * @return Update rate in Hertz - */ -static inline uint16_t mavlink_msg_request_data_stream_get_req_message_rate(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field start_stop from request_data_stream message - * - * @return 1 to start sending, 0 to stop sending. - */ -static inline uint8_t mavlink_msg_request_data_stream_get_start_stop(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Decode a request_data_stream message into a struct - * - * @param msg The message to decode - * @param request_data_stream C-struct to decode the message contents into - */ -static inline void mavlink_msg_request_data_stream_decode(const mavlink_message_t* msg, mavlink_request_data_stream_t* request_data_stream) -{ -#if MAVLINK_NEED_BYTE_SWAP - request_data_stream->target_system = mavlink_msg_request_data_stream_get_target_system(msg); - request_data_stream->target_component = mavlink_msg_request_data_stream_get_target_component(msg); - request_data_stream->req_stream_id = mavlink_msg_request_data_stream_get_req_stream_id(msg); - request_data_stream->req_message_rate = mavlink_msg_request_data_stream_get_req_message_rate(msg); - request_data_stream->start_stop = mavlink_msg_request_data_stream_get_start_stop(msg); -#else - memcpy(request_data_stream, _MAV_PAYLOAD(msg), 6); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint.h deleted file mode 100644 index b344f3aa27..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT PACKING - -#define MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT 58 - -typedef struct __mavlink_roll_pitch_yaw_speed_thrust_setpoint_t -{ - uint64_t time_us; ///< Timestamp in micro seconds since unix epoch - float roll_speed; ///< Desired roll angular speed in rad/s - float pitch_speed; ///< Desired pitch angular speed in rad/s - float yaw_speed; ///< Desired yaw angular speed in rad/s - float thrust; ///< Collective thrust, normalized to 0 .. 1 -} mavlink_roll_pitch_yaw_speed_thrust_setpoint_t; - -#define MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT_LEN 24 -#define MAVLINK_MSG_ID_58_LEN 24 - - - -#define MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT { \ - "ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT", \ - 5, \ - { { "time_us", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_roll_pitch_yaw_speed_thrust_setpoint_t, time_us) }, \ - { "roll_speed", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_roll_pitch_yaw_speed_thrust_setpoint_t, roll_speed) }, \ - { "pitch_speed", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_roll_pitch_yaw_speed_thrust_setpoint_t, pitch_speed) }, \ - { "yaw_speed", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_roll_pitch_yaw_speed_thrust_setpoint_t, yaw_speed) }, \ - { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_roll_pitch_yaw_speed_thrust_setpoint_t, thrust) }, \ - } \ -} - - -/** - * @brief Pack a roll_pitch_yaw_speed_thrust_setpoint message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param time_us Timestamp in micro seconds since unix epoch - * @param roll_speed Desired roll angular speed in rad/s - * @param pitch_speed Desired pitch angular speed in rad/s - * @param yaw_speed Desired yaw angular speed in rad/s - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t time_us, float roll_speed, float pitch_speed, float yaw_speed, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll_speed); - _mav_put_float(buf, 12, pitch_speed); - _mav_put_float(buf, 16, yaw_speed); - _mav_put_float(buf, 20, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_roll_pitch_yaw_speed_thrust_setpoint_t packet; - packet.time_us = time_us; - packet.roll_speed = roll_speed; - packet.pitch_speed = pitch_speed; - packet.yaw_speed = yaw_speed; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT; - return mavlink_finalize_message(msg, system_id, component_id, 24); -} - -/** - * @brief Pack a roll_pitch_yaw_speed_thrust_setpoint message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param time_us Timestamp in micro seconds since unix epoch - * @param roll_speed Desired roll angular speed in rad/s - * @param pitch_speed Desired pitch angular speed in rad/s - * @param yaw_speed Desired yaw angular speed in rad/s - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t time_us,float roll_speed,float pitch_speed,float yaw_speed,float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll_speed); - _mav_put_float(buf, 12, pitch_speed); - _mav_put_float(buf, 16, yaw_speed); - _mav_put_float(buf, 20, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_roll_pitch_yaw_speed_thrust_setpoint_t packet; - packet.time_us = time_us; - packet.roll_speed = roll_speed; - packet.pitch_speed = pitch_speed; - packet.yaw_speed = yaw_speed; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 24); -} - -/** - * @brief Encode a roll_pitch_yaw_speed_thrust_setpoint struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param roll_pitch_yaw_speed_thrust_setpoint C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_roll_pitch_yaw_speed_thrust_setpoint_t* roll_pitch_yaw_speed_thrust_setpoint) -{ - return mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_pack(system_id, component_id, msg, roll_pitch_yaw_speed_thrust_setpoint->time_us, roll_pitch_yaw_speed_thrust_setpoint->roll_speed, roll_pitch_yaw_speed_thrust_setpoint->pitch_speed, roll_pitch_yaw_speed_thrust_setpoint->yaw_speed, roll_pitch_yaw_speed_thrust_setpoint->thrust); -} - -/** - * @brief Send a roll_pitch_yaw_speed_thrust_setpoint message - * @param chan MAVLink channel to send the message - * - * @param time_us Timestamp in micro seconds since unix epoch - * @param roll_speed Desired roll angular speed in rad/s - * @param pitch_speed Desired pitch angular speed in rad/s - * @param yaw_speed Desired yaw angular speed in rad/s - * @param thrust Collective thrust, normalized to 0 .. 1 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_send(mavlink_channel_t chan, uint64_t time_us, float roll_speed, float pitch_speed, float yaw_speed, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll_speed); - _mav_put_float(buf, 12, pitch_speed); - _mav_put_float(buf, 16, yaw_speed); - _mav_put_float(buf, 20, thrust); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, buf, 24); -#else - mavlink_roll_pitch_yaw_speed_thrust_setpoint_t packet; - packet.time_us = time_us; - packet.roll_speed = roll_speed; - packet.pitch_speed = pitch_speed; - packet.yaw_speed = yaw_speed; - packet.thrust = thrust; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, (const char *)&packet, 24); -#endif -} - -#endif - -// MESSAGE ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT UNPACKING - - -/** - * @brief Get field time_us from roll_pitch_yaw_speed_thrust_setpoint message - * - * @return Timestamp in micro seconds since unix epoch - */ -static inline uint64_t mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_time_us(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field roll_speed from roll_pitch_yaw_speed_thrust_setpoint message - * - * @return Desired roll angular speed in rad/s - */ -static inline float mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_roll_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field pitch_speed from roll_pitch_yaw_speed_thrust_setpoint message - * - * @return Desired pitch angular speed in rad/s - */ -static inline float mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_pitch_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yaw_speed from roll_pitch_yaw_speed_thrust_setpoint message - * - * @return Desired yaw angular speed in rad/s - */ -static inline float mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_yaw_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field thrust from roll_pitch_yaw_speed_thrust_setpoint message - * - * @return Collective thrust, normalized to 0 .. 1 - */ -static inline float mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_thrust(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Decode a roll_pitch_yaw_speed_thrust_setpoint message into a struct - * - * @param msg The message to decode - * @param roll_pitch_yaw_speed_thrust_setpoint C-struct to decode the message contents into - */ -static inline void mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_decode(const mavlink_message_t* msg, mavlink_roll_pitch_yaw_speed_thrust_setpoint_t* roll_pitch_yaw_speed_thrust_setpoint) -{ -#if MAVLINK_NEED_BYTE_SWAP - roll_pitch_yaw_speed_thrust_setpoint->time_us = mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_time_us(msg); - roll_pitch_yaw_speed_thrust_setpoint->roll_speed = mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_roll_speed(msg); - roll_pitch_yaw_speed_thrust_setpoint->pitch_speed = mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_pitch_speed(msg); - roll_pitch_yaw_speed_thrust_setpoint->yaw_speed = mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_yaw_speed(msg); - roll_pitch_yaw_speed_thrust_setpoint->thrust = mavlink_msg_roll_pitch_yaw_speed_thrust_setpoint_get_thrust(msg); -#else - memcpy(roll_pitch_yaw_speed_thrust_setpoint, _MAV_PAYLOAD(msg), 24); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_roll_pitch_yaw_thrust_setpoint.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_roll_pitch_yaw_thrust_setpoint.h deleted file mode 100644 index 16155f1343..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_roll_pitch_yaw_thrust_setpoint.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE ROLL_PITCH_YAW_THRUST_SETPOINT PACKING - -#define MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT 57 - -typedef struct __mavlink_roll_pitch_yaw_thrust_setpoint_t -{ - uint64_t time_us; ///< Timestamp in micro seconds since unix epoch - float roll; ///< Desired roll angle in radians - float pitch; ///< Desired pitch angle in radians - float yaw; ///< Desired yaw angle in radians - float thrust; ///< Collective thrust, normalized to 0 .. 1 -} mavlink_roll_pitch_yaw_thrust_setpoint_t; - -#define MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT_LEN 24 -#define MAVLINK_MSG_ID_57_LEN 24 - - - -#define MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT { \ - "ROLL_PITCH_YAW_THRUST_SETPOINT", \ - 5, \ - { { "time_us", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_roll_pitch_yaw_thrust_setpoint_t, time_us) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_roll_pitch_yaw_thrust_setpoint_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_roll_pitch_yaw_thrust_setpoint_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_roll_pitch_yaw_thrust_setpoint_t, yaw) }, \ - { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_roll_pitch_yaw_thrust_setpoint_t, thrust) }, \ - } \ -} - - -/** - * @brief Pack a roll_pitch_yaw_thrust_setpoint message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param time_us Timestamp in micro seconds since unix epoch - * @param roll Desired roll angle in radians - * @param pitch Desired pitch angle in radians - * @param yaw Desired yaw angle in radians - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_roll_pitch_yaw_thrust_setpoint_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t time_us, float roll, float pitch, float yaw, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_roll_pitch_yaw_thrust_setpoint_t packet; - packet.time_us = time_us; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT; - return mavlink_finalize_message(msg, system_id, component_id, 24); -} - -/** - * @brief Pack a roll_pitch_yaw_thrust_setpoint message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param time_us Timestamp in micro seconds since unix epoch - * @param roll Desired roll angle in radians - * @param pitch Desired pitch angle in radians - * @param yaw Desired yaw angle in radians - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_roll_pitch_yaw_thrust_setpoint_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t time_us,float roll,float pitch,float yaw,float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_roll_pitch_yaw_thrust_setpoint_t packet; - packet.time_us = time_us; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 24); -} - -/** - * @brief Encode a roll_pitch_yaw_thrust_setpoint struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param roll_pitch_yaw_thrust_setpoint C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_roll_pitch_yaw_thrust_setpoint_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_roll_pitch_yaw_thrust_setpoint_t* roll_pitch_yaw_thrust_setpoint) -{ - return mavlink_msg_roll_pitch_yaw_thrust_setpoint_pack(system_id, component_id, msg, roll_pitch_yaw_thrust_setpoint->time_us, roll_pitch_yaw_thrust_setpoint->roll, roll_pitch_yaw_thrust_setpoint->pitch, roll_pitch_yaw_thrust_setpoint->yaw, roll_pitch_yaw_thrust_setpoint->thrust); -} - -/** - * @brief Send a roll_pitch_yaw_thrust_setpoint message - * @param chan MAVLink channel to send the message - * - * @param time_us Timestamp in micro seconds since unix epoch - * @param roll Desired roll angle in radians - * @param pitch Desired pitch angle in radians - * @param yaw Desired yaw angle in radians - * @param thrust Collective thrust, normalized to 0 .. 1 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_roll_pitch_yaw_thrust_setpoint_send(mavlink_channel_t chan, uint64_t time_us, float roll, float pitch, float yaw, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_uint64_t(buf, 0, time_us); - _mav_put_float(buf, 8, roll); - _mav_put_float(buf, 12, pitch); - _mav_put_float(buf, 16, yaw); - _mav_put_float(buf, 20, thrust); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT, buf, 24); -#else - mavlink_roll_pitch_yaw_thrust_setpoint_t packet; - packet.time_us = time_us; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT, (const char *)&packet, 24); -#endif -} - -#endif - -// MESSAGE ROLL_PITCH_YAW_THRUST_SETPOINT UNPACKING - - -/** - * @brief Get field time_us from roll_pitch_yaw_thrust_setpoint message - * - * @return Timestamp in micro seconds since unix epoch - */ -static inline uint64_t mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_time_us(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field roll from roll_pitch_yaw_thrust_setpoint message - * - * @return Desired roll angle in radians - */ -static inline float mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field pitch from roll_pitch_yaw_thrust_setpoint message - * - * @return Desired pitch angle in radians - */ -static inline float mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yaw from roll_pitch_yaw_thrust_setpoint message - * - * @return Desired yaw angle in radians - */ -static inline float mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field thrust from roll_pitch_yaw_thrust_setpoint message - * - * @return Collective thrust, normalized to 0 .. 1 - */ -static inline float mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_thrust(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Decode a roll_pitch_yaw_thrust_setpoint message into a struct - * - * @param msg The message to decode - * @param roll_pitch_yaw_thrust_setpoint C-struct to decode the message contents into - */ -static inline void mavlink_msg_roll_pitch_yaw_thrust_setpoint_decode(const mavlink_message_t* msg, mavlink_roll_pitch_yaw_thrust_setpoint_t* roll_pitch_yaw_thrust_setpoint) -{ -#if MAVLINK_NEED_BYTE_SWAP - roll_pitch_yaw_thrust_setpoint->time_us = mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_time_us(msg); - roll_pitch_yaw_thrust_setpoint->roll = mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_roll(msg); - roll_pitch_yaw_thrust_setpoint->pitch = mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_pitch(msg); - roll_pitch_yaw_thrust_setpoint->yaw = mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_yaw(msg); - roll_pitch_yaw_thrust_setpoint->thrust = mavlink_msg_roll_pitch_yaw_thrust_setpoint_get_thrust(msg); -#else - memcpy(roll_pitch_yaw_thrust_setpoint, _MAV_PAYLOAD(msg), 24); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_safety_allowed_area.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_safety_allowed_area.h deleted file mode 100644 index 07b91fd0ed..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_safety_allowed_area.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE SAFETY_ALLOWED_AREA PACKING - -#define MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA 54 - -typedef struct __mavlink_safety_allowed_area_t -{ - uint8_t frame; ///< Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - float p1x; ///< x position 1 / Latitude 1 - float p1y; ///< y position 1 / Longitude 1 - float p1z; ///< z position 1 / Altitude 1 - float p2x; ///< x position 2 / Latitude 2 - float p2y; ///< y position 2 / Longitude 2 - float p2z; ///< z position 2 / Altitude 2 -} mavlink_safety_allowed_area_t; - -#define MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA_LEN 25 -#define MAVLINK_MSG_ID_54_LEN 25 - - - -#define MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA { \ - "SAFETY_ALLOWED_AREA", \ - 7, \ - { { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_safety_allowed_area_t, frame) }, \ - { "p1x", NULL, MAVLINK_TYPE_FLOAT, 0, 1, offsetof(mavlink_safety_allowed_area_t, p1x) }, \ - { "p1y", NULL, MAVLINK_TYPE_FLOAT, 0, 5, offsetof(mavlink_safety_allowed_area_t, p1y) }, \ - { "p1z", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_safety_allowed_area_t, p1z) }, \ - { "p2x", NULL, MAVLINK_TYPE_FLOAT, 0, 13, offsetof(mavlink_safety_allowed_area_t, p2x) }, \ - { "p2y", NULL, MAVLINK_TYPE_FLOAT, 0, 17, offsetof(mavlink_safety_allowed_area_t, p2y) }, \ - { "p2z", NULL, MAVLINK_TYPE_FLOAT, 0, 21, offsetof(mavlink_safety_allowed_area_t, p2z) }, \ - } \ -} - - -/** - * @brief Pack a safety_allowed_area message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param frame Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - * @param p1x x position 1 / Latitude 1 - * @param p1y y position 1 / Longitude 1 - * @param p1z z position 1 / Altitude 1 - * @param p2x x position 2 / Latitude 2 - * @param p2y y position 2 / Longitude 2 - * @param p2z z position 2 / Altitude 2 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_safety_allowed_area_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t frame, float p1x, float p1y, float p1z, float p2x, float p2y, float p2z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[25]; - _mav_put_uint8_t(buf, 0, frame); - _mav_put_float(buf, 1, p1x); - _mav_put_float(buf, 5, p1y); - _mav_put_float(buf, 9, p1z); - _mav_put_float(buf, 13, p2x); - _mav_put_float(buf, 17, p2y); - _mav_put_float(buf, 21, p2z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 25); -#else - mavlink_safety_allowed_area_t packet; - packet.frame = frame; - packet.p1x = p1x; - packet.p1y = p1y; - packet.p1z = p1z; - packet.p2x = p2x; - packet.p2y = p2y; - packet.p2z = p2z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 25); -#endif - - msg->msgid = MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA; - return mavlink_finalize_message(msg, system_id, component_id, 25); -} - -/** - * @brief Pack a safety_allowed_area message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param frame Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - * @param p1x x position 1 / Latitude 1 - * @param p1y y position 1 / Longitude 1 - * @param p1z z position 1 / Altitude 1 - * @param p2x x position 2 / Latitude 2 - * @param p2y y position 2 / Longitude 2 - * @param p2z z position 2 / Altitude 2 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_safety_allowed_area_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t frame,float p1x,float p1y,float p1z,float p2x,float p2y,float p2z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[25]; - _mav_put_uint8_t(buf, 0, frame); - _mav_put_float(buf, 1, p1x); - _mav_put_float(buf, 5, p1y); - _mav_put_float(buf, 9, p1z); - _mav_put_float(buf, 13, p2x); - _mav_put_float(buf, 17, p2y); - _mav_put_float(buf, 21, p2z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 25); -#else - mavlink_safety_allowed_area_t packet; - packet.frame = frame; - packet.p1x = p1x; - packet.p1y = p1y; - packet.p1z = p1z; - packet.p2x = p2x; - packet.p2y = p2y; - packet.p2z = p2z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 25); -#endif - - msg->msgid = MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 25); -} - -/** - * @brief Encode a safety_allowed_area struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param safety_allowed_area C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_safety_allowed_area_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_safety_allowed_area_t* safety_allowed_area) -{ - return mavlink_msg_safety_allowed_area_pack(system_id, component_id, msg, safety_allowed_area->frame, safety_allowed_area->p1x, safety_allowed_area->p1y, safety_allowed_area->p1z, safety_allowed_area->p2x, safety_allowed_area->p2y, safety_allowed_area->p2z); -} - -/** - * @brief Send a safety_allowed_area message - * @param chan MAVLink channel to send the message - * - * @param frame Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - * @param p1x x position 1 / Latitude 1 - * @param p1y y position 1 / Longitude 1 - * @param p1z z position 1 / Altitude 1 - * @param p2x x position 2 / Latitude 2 - * @param p2y y position 2 / Longitude 2 - * @param p2z z position 2 / Altitude 2 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_safety_allowed_area_send(mavlink_channel_t chan, uint8_t frame, float p1x, float p1y, float p1z, float p2x, float p2y, float p2z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[25]; - _mav_put_uint8_t(buf, 0, frame); - _mav_put_float(buf, 1, p1x); - _mav_put_float(buf, 5, p1y); - _mav_put_float(buf, 9, p1z); - _mav_put_float(buf, 13, p2x); - _mav_put_float(buf, 17, p2y); - _mav_put_float(buf, 21, p2z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA, buf, 25); -#else - mavlink_safety_allowed_area_t packet; - packet.frame = frame; - packet.p1x = p1x; - packet.p1y = p1y; - packet.p1z = p1z; - packet.p2x = p2x; - packet.p2y = p2y; - packet.p2z = p2z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA, (const char *)&packet, 25); -#endif -} - -#endif - -// MESSAGE SAFETY_ALLOWED_AREA UNPACKING - - -/** - * @brief Get field frame from safety_allowed_area message - * - * @return Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - */ -static inline uint8_t mavlink_msg_safety_allowed_area_get_frame(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field p1x from safety_allowed_area message - * - * @return x position 1 / Latitude 1 - */ -static inline float mavlink_msg_safety_allowed_area_get_p1x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 1); -} - -/** - * @brief Get field p1y from safety_allowed_area message - * - * @return y position 1 / Longitude 1 - */ -static inline float mavlink_msg_safety_allowed_area_get_p1y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 5); -} - -/** - * @brief Get field p1z from safety_allowed_area message - * - * @return z position 1 / Altitude 1 - */ -static inline float mavlink_msg_safety_allowed_area_get_p1z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Get field p2x from safety_allowed_area message - * - * @return x position 2 / Latitude 2 - */ -static inline float mavlink_msg_safety_allowed_area_get_p2x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 13); -} - -/** - * @brief Get field p2y from safety_allowed_area message - * - * @return y position 2 / Longitude 2 - */ -static inline float mavlink_msg_safety_allowed_area_get_p2y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 17); -} - -/** - * @brief Get field p2z from safety_allowed_area message - * - * @return z position 2 / Altitude 2 - */ -static inline float mavlink_msg_safety_allowed_area_get_p2z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 21); -} - -/** - * @brief Decode a safety_allowed_area message into a struct - * - * @param msg The message to decode - * @param safety_allowed_area C-struct to decode the message contents into - */ -static inline void mavlink_msg_safety_allowed_area_decode(const mavlink_message_t* msg, mavlink_safety_allowed_area_t* safety_allowed_area) -{ -#if MAVLINK_NEED_BYTE_SWAP - safety_allowed_area->frame = mavlink_msg_safety_allowed_area_get_frame(msg); - safety_allowed_area->p1x = mavlink_msg_safety_allowed_area_get_p1x(msg); - safety_allowed_area->p1y = mavlink_msg_safety_allowed_area_get_p1y(msg); - safety_allowed_area->p1z = mavlink_msg_safety_allowed_area_get_p1z(msg); - safety_allowed_area->p2x = mavlink_msg_safety_allowed_area_get_p2x(msg); - safety_allowed_area->p2y = mavlink_msg_safety_allowed_area_get_p2y(msg); - safety_allowed_area->p2z = mavlink_msg_safety_allowed_area_get_p2z(msg); -#else - memcpy(safety_allowed_area, _MAV_PAYLOAD(msg), 25); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_safety_set_allowed_area.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_safety_set_allowed_area.h deleted file mode 100644 index 3c122227a6..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_safety_set_allowed_area.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE SAFETY_SET_ALLOWED_AREA PACKING - -#define MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA 53 - -typedef struct __mavlink_safety_set_allowed_area_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t frame; ///< Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - float p1x; ///< x position 1 / Latitude 1 - float p1y; ///< y position 1 / Longitude 1 - float p1z; ///< z position 1 / Altitude 1 - float p2x; ///< x position 2 / Latitude 2 - float p2y; ///< y position 2 / Longitude 2 - float p2z; ///< z position 2 / Altitude 2 -} mavlink_safety_set_allowed_area_t; - -#define MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA_LEN 27 -#define MAVLINK_MSG_ID_53_LEN 27 - - - -#define MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA { \ - "SAFETY_SET_ALLOWED_AREA", \ - 9, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_safety_set_allowed_area_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_safety_set_allowed_area_t, target_component) }, \ - { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_safety_set_allowed_area_t, frame) }, \ - { "p1x", NULL, MAVLINK_TYPE_FLOAT, 0, 3, offsetof(mavlink_safety_set_allowed_area_t, p1x) }, \ - { "p1y", NULL, MAVLINK_TYPE_FLOAT, 0, 7, offsetof(mavlink_safety_set_allowed_area_t, p1y) }, \ - { "p1z", NULL, MAVLINK_TYPE_FLOAT, 0, 11, offsetof(mavlink_safety_set_allowed_area_t, p1z) }, \ - { "p2x", NULL, MAVLINK_TYPE_FLOAT, 0, 15, offsetof(mavlink_safety_set_allowed_area_t, p2x) }, \ - { "p2y", NULL, MAVLINK_TYPE_FLOAT, 0, 19, offsetof(mavlink_safety_set_allowed_area_t, p2y) }, \ - { "p2z", NULL, MAVLINK_TYPE_FLOAT, 0, 23, offsetof(mavlink_safety_set_allowed_area_t, p2z) }, \ - } \ -} - - -/** - * @brief Pack a safety_set_allowed_area message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param frame Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - * @param p1x x position 1 / Latitude 1 - * @param p1y y position 1 / Longitude 1 - * @param p1z z position 1 / Altitude 1 - * @param p2x x position 2 / Latitude 2 - * @param p2y y position 2 / Longitude 2 - * @param p2z z position 2 / Altitude 2 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_safety_set_allowed_area_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t frame, float p1x, float p1y, float p1z, float p2x, float p2y, float p2z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[27]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, frame); - _mav_put_float(buf, 3, p1x); - _mav_put_float(buf, 7, p1y); - _mav_put_float(buf, 11, p1z); - _mav_put_float(buf, 15, p2x); - _mav_put_float(buf, 19, p2y); - _mav_put_float(buf, 23, p2z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 27); -#else - mavlink_safety_set_allowed_area_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.frame = frame; - packet.p1x = p1x; - packet.p1y = p1y; - packet.p1z = p1z; - packet.p2x = p2x; - packet.p2y = p2y; - packet.p2z = p2z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 27); -#endif - - msg->msgid = MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA; - return mavlink_finalize_message(msg, system_id, component_id, 27); -} - -/** - * @brief Pack a safety_set_allowed_area message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param frame Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - * @param p1x x position 1 / Latitude 1 - * @param p1y y position 1 / Longitude 1 - * @param p1z z position 1 / Altitude 1 - * @param p2x x position 2 / Latitude 2 - * @param p2y y position 2 / Longitude 2 - * @param p2z z position 2 / Altitude 2 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_safety_set_allowed_area_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t frame,float p1x,float p1y,float p1z,float p2x,float p2y,float p2z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[27]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, frame); - _mav_put_float(buf, 3, p1x); - _mav_put_float(buf, 7, p1y); - _mav_put_float(buf, 11, p1z); - _mav_put_float(buf, 15, p2x); - _mav_put_float(buf, 19, p2y); - _mav_put_float(buf, 23, p2z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 27); -#else - mavlink_safety_set_allowed_area_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.frame = frame; - packet.p1x = p1x; - packet.p1y = p1y; - packet.p1z = p1z; - packet.p2x = p2x; - packet.p2y = p2y; - packet.p2z = p2z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 27); -#endif - - msg->msgid = MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 27); -} - -/** - * @brief Encode a safety_set_allowed_area struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param safety_set_allowed_area C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_safety_set_allowed_area_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_safety_set_allowed_area_t* safety_set_allowed_area) -{ - return mavlink_msg_safety_set_allowed_area_pack(system_id, component_id, msg, safety_set_allowed_area->target_system, safety_set_allowed_area->target_component, safety_set_allowed_area->frame, safety_set_allowed_area->p1x, safety_set_allowed_area->p1y, safety_set_allowed_area->p1z, safety_set_allowed_area->p2x, safety_set_allowed_area->p2y, safety_set_allowed_area->p2z); -} - -/** - * @brief Send a safety_set_allowed_area message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param frame Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - * @param p1x x position 1 / Latitude 1 - * @param p1y y position 1 / Longitude 1 - * @param p1z z position 1 / Altitude 1 - * @param p2x x position 2 / Latitude 2 - * @param p2y y position 2 / Longitude 2 - * @param p2z z position 2 / Altitude 2 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_safety_set_allowed_area_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t frame, float p1x, float p1y, float p1z, float p2x, float p2y, float p2z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[27]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, frame); - _mav_put_float(buf, 3, p1x); - _mav_put_float(buf, 7, p1y); - _mav_put_float(buf, 11, p1z); - _mav_put_float(buf, 15, p2x); - _mav_put_float(buf, 19, p2y); - _mav_put_float(buf, 23, p2z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA, buf, 27); -#else - mavlink_safety_set_allowed_area_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.frame = frame; - packet.p1x = p1x; - packet.p1y = p1y; - packet.p1z = p1z; - packet.p2x = p2x; - packet.p2y = p2y; - packet.p2z = p2z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA, (const char *)&packet, 27); -#endif -} - -#endif - -// MESSAGE SAFETY_SET_ALLOWED_AREA UNPACKING - - -/** - * @brief Get field target_system from safety_set_allowed_area message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_safety_set_allowed_area_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from safety_set_allowed_area message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_safety_set_allowed_area_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field frame from safety_set_allowed_area message - * - * @return Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. - */ -static inline uint8_t mavlink_msg_safety_set_allowed_area_get_frame(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field p1x from safety_set_allowed_area message - * - * @return x position 1 / Latitude 1 - */ -static inline float mavlink_msg_safety_set_allowed_area_get_p1x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 3); -} - -/** - * @brief Get field p1y from safety_set_allowed_area message - * - * @return y position 1 / Longitude 1 - */ -static inline float mavlink_msg_safety_set_allowed_area_get_p1y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 7); -} - -/** - * @brief Get field p1z from safety_set_allowed_area message - * - * @return z position 1 / Altitude 1 - */ -static inline float mavlink_msg_safety_set_allowed_area_get_p1z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 11); -} - -/** - * @brief Get field p2x from safety_set_allowed_area message - * - * @return x position 2 / Latitude 2 - */ -static inline float mavlink_msg_safety_set_allowed_area_get_p2x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 15); -} - -/** - * @brief Get field p2y from safety_set_allowed_area message - * - * @return y position 2 / Longitude 2 - */ -static inline float mavlink_msg_safety_set_allowed_area_get_p2y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 19); -} - -/** - * @brief Get field p2z from safety_set_allowed_area message - * - * @return z position 2 / Altitude 2 - */ -static inline float mavlink_msg_safety_set_allowed_area_get_p2z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 23); -} - -/** - * @brief Decode a safety_set_allowed_area message into a struct - * - * @param msg The message to decode - * @param safety_set_allowed_area C-struct to decode the message contents into - */ -static inline void mavlink_msg_safety_set_allowed_area_decode(const mavlink_message_t* msg, mavlink_safety_set_allowed_area_t* safety_set_allowed_area) -{ -#if MAVLINK_NEED_BYTE_SWAP - safety_set_allowed_area->target_system = mavlink_msg_safety_set_allowed_area_get_target_system(msg); - safety_set_allowed_area->target_component = mavlink_msg_safety_set_allowed_area_get_target_component(msg); - safety_set_allowed_area->frame = mavlink_msg_safety_set_allowed_area_get_frame(msg); - safety_set_allowed_area->p1x = mavlink_msg_safety_set_allowed_area_get_p1x(msg); - safety_set_allowed_area->p1y = mavlink_msg_safety_set_allowed_area_get_p1y(msg); - safety_set_allowed_area->p1z = mavlink_msg_safety_set_allowed_area_get_p1z(msg); - safety_set_allowed_area->p2x = mavlink_msg_safety_set_allowed_area_get_p2x(msg); - safety_set_allowed_area->p2y = mavlink_msg_safety_set_allowed_area_get_p2y(msg); - safety_set_allowed_area->p2z = mavlink_msg_safety_set_allowed_area_get_p2z(msg); -#else - memcpy(safety_set_allowed_area, _MAV_PAYLOAD(msg), 27); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_scaled_imu.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_scaled_imu.h deleted file mode 100644 index 4315dac275..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_scaled_imu.h +++ /dev/null @@ -1,342 +0,0 @@ -// MESSAGE SCALED_IMU PACKING - -#define MAVLINK_MSG_ID_SCALED_IMU 26 - -typedef struct __mavlink_scaled_imu_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - int16_t xacc; ///< X acceleration (mg) - int16_t yacc; ///< Y acceleration (mg) - int16_t zacc; ///< Z acceleration (mg) - int16_t xgyro; ///< Angular speed around X axis (millirad /sec) - int16_t ygyro; ///< Angular speed around Y axis (millirad /sec) - int16_t zgyro; ///< Angular speed around Z axis (millirad /sec) - int16_t xmag; ///< X Magnetic field (milli tesla) - int16_t ymag; ///< Y Magnetic field (milli tesla) - int16_t zmag; ///< Z Magnetic field (milli tesla) -} mavlink_scaled_imu_t; - -#define MAVLINK_MSG_ID_SCALED_IMU_LEN 26 -#define MAVLINK_MSG_ID_26_LEN 26 - - - -#define MAVLINK_MESSAGE_INFO_SCALED_IMU { \ - "SCALED_IMU", \ - 10, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_scaled_imu_t, usec) }, \ - { "xacc", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_scaled_imu_t, xacc) }, \ - { "yacc", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_scaled_imu_t, yacc) }, \ - { "zacc", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_scaled_imu_t, zacc) }, \ - { "xgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_scaled_imu_t, xgyro) }, \ - { "ygyro", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_scaled_imu_t, ygyro) }, \ - { "zgyro", NULL, MAVLINK_TYPE_INT16_T, 0, 18, offsetof(mavlink_scaled_imu_t, zgyro) }, \ - { "xmag", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_scaled_imu_t, xmag) }, \ - { "ymag", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_scaled_imu_t, ymag) }, \ - { "zmag", NULL, MAVLINK_TYPE_INT16_T, 0, 24, offsetof(mavlink_scaled_imu_t, zmag) }, \ - } \ -} - - -/** - * @brief Pack a scaled_imu message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param xacc X acceleration (mg) - * @param yacc Y acceleration (mg) - * @param zacc Z acceleration (mg) - * @param xgyro Angular speed around X axis (millirad /sec) - * @param ygyro Angular speed around Y axis (millirad /sec) - * @param zgyro Angular speed around Z axis (millirad /sec) - * @param xmag X Magnetic field (milli tesla) - * @param ymag Y Magnetic field (milli tesla) - * @param zmag Z Magnetic field (milli tesla) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_scaled_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, xacc); - _mav_put_int16_t(buf, 10, yacc); - _mav_put_int16_t(buf, 12, zacc); - _mav_put_int16_t(buf, 14, xgyro); - _mav_put_int16_t(buf, 16, ygyro); - _mav_put_int16_t(buf, 18, zgyro); - _mav_put_int16_t(buf, 20, xmag); - _mav_put_int16_t(buf, 22, ymag); - _mav_put_int16_t(buf, 24, zmag); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_scaled_imu_t packet; - packet.usec = usec; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - packet.xmag = xmag; - packet.ymag = ymag; - packet.zmag = zmag; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_SCALED_IMU; - return mavlink_finalize_message(msg, system_id, component_id, 26); -} - -/** - * @brief Pack a scaled_imu message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param xacc X acceleration (mg) - * @param yacc Y acceleration (mg) - * @param zacc Z acceleration (mg) - * @param xgyro Angular speed around X axis (millirad /sec) - * @param ygyro Angular speed around Y axis (millirad /sec) - * @param zgyro Angular speed around Z axis (millirad /sec) - * @param xmag X Magnetic field (milli tesla) - * @param ymag Y Magnetic field (milli tesla) - * @param zmag Z Magnetic field (milli tesla) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_scaled_imu_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,int16_t xacc,int16_t yacc,int16_t zacc,int16_t xgyro,int16_t ygyro,int16_t zgyro,int16_t xmag,int16_t ymag,int16_t zmag) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, xacc); - _mav_put_int16_t(buf, 10, yacc); - _mav_put_int16_t(buf, 12, zacc); - _mav_put_int16_t(buf, 14, xgyro); - _mav_put_int16_t(buf, 16, ygyro); - _mav_put_int16_t(buf, 18, zgyro); - _mav_put_int16_t(buf, 20, xmag); - _mav_put_int16_t(buf, 22, ymag); - _mav_put_int16_t(buf, 24, zmag); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_scaled_imu_t packet; - packet.usec = usec; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - packet.xmag = xmag; - packet.ymag = ymag; - packet.zmag = zmag; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_SCALED_IMU; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 26); -} - -/** - * @brief Encode a scaled_imu struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param scaled_imu C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_scaled_imu_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_scaled_imu_t* scaled_imu) -{ - return mavlink_msg_scaled_imu_pack(system_id, component_id, msg, scaled_imu->usec, scaled_imu->xacc, scaled_imu->yacc, scaled_imu->zacc, scaled_imu->xgyro, scaled_imu->ygyro, scaled_imu->zgyro, scaled_imu->xmag, scaled_imu->ymag, scaled_imu->zmag); -} - -/** - * @brief Send a scaled_imu message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param xacc X acceleration (mg) - * @param yacc Y acceleration (mg) - * @param zacc Z acceleration (mg) - * @param xgyro Angular speed around X axis (millirad /sec) - * @param ygyro Angular speed around Y axis (millirad /sec) - * @param zgyro Angular speed around Z axis (millirad /sec) - * @param xmag X Magnetic field (milli tesla) - * @param ymag Y Magnetic field (milli tesla) - * @param zmag Z Magnetic field (milli tesla) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_scaled_imu_send(mavlink_channel_t chan, uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_int16_t(buf, 8, xacc); - _mav_put_int16_t(buf, 10, yacc); - _mav_put_int16_t(buf, 12, zacc); - _mav_put_int16_t(buf, 14, xgyro); - _mav_put_int16_t(buf, 16, ygyro); - _mav_put_int16_t(buf, 18, zgyro); - _mav_put_int16_t(buf, 20, xmag); - _mav_put_int16_t(buf, 22, ymag); - _mav_put_int16_t(buf, 24, zmag); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SCALED_IMU, buf, 26); -#else - mavlink_scaled_imu_t packet; - packet.usec = usec; - packet.xacc = xacc; - packet.yacc = yacc; - packet.zacc = zacc; - packet.xgyro = xgyro; - packet.ygyro = ygyro; - packet.zgyro = zgyro; - packet.xmag = xmag; - packet.ymag = ymag; - packet.zmag = zmag; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SCALED_IMU, (const char *)&packet, 26); -#endif -} - -#endif - -// MESSAGE SCALED_IMU UNPACKING - - -/** - * @brief Get field usec from scaled_imu message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_scaled_imu_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field xacc from scaled_imu message - * - * @return X acceleration (mg) - */ -static inline int16_t mavlink_msg_scaled_imu_get_xacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 8); -} - -/** - * @brief Get field yacc from scaled_imu message - * - * @return Y acceleration (mg) - */ -static inline int16_t mavlink_msg_scaled_imu_get_yacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 10); -} - -/** - * @brief Get field zacc from scaled_imu message - * - * @return Z acceleration (mg) - */ -static inline int16_t mavlink_msg_scaled_imu_get_zacc(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field xgyro from scaled_imu message - * - * @return Angular speed around X axis (millirad /sec) - */ -static inline int16_t mavlink_msg_scaled_imu_get_xgyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Get field ygyro from scaled_imu message - * - * @return Angular speed around Y axis (millirad /sec) - */ -static inline int16_t mavlink_msg_scaled_imu_get_ygyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 16); -} - -/** - * @brief Get field zgyro from scaled_imu message - * - * @return Angular speed around Z axis (millirad /sec) - */ -static inline int16_t mavlink_msg_scaled_imu_get_zgyro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 18); -} - -/** - * @brief Get field xmag from scaled_imu message - * - * @return X Magnetic field (milli tesla) - */ -static inline int16_t mavlink_msg_scaled_imu_get_xmag(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 20); -} - -/** - * @brief Get field ymag from scaled_imu message - * - * @return Y Magnetic field (milli tesla) - */ -static inline int16_t mavlink_msg_scaled_imu_get_ymag(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 22); -} - -/** - * @brief Get field zmag from scaled_imu message - * - * @return Z Magnetic field (milli tesla) - */ -static inline int16_t mavlink_msg_scaled_imu_get_zmag(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 24); -} - -/** - * @brief Decode a scaled_imu message into a struct - * - * @param msg The message to decode - * @param scaled_imu C-struct to decode the message contents into - */ -static inline void mavlink_msg_scaled_imu_decode(const mavlink_message_t* msg, mavlink_scaled_imu_t* scaled_imu) -{ -#if MAVLINK_NEED_BYTE_SWAP - scaled_imu->usec = mavlink_msg_scaled_imu_get_usec(msg); - scaled_imu->xacc = mavlink_msg_scaled_imu_get_xacc(msg); - scaled_imu->yacc = mavlink_msg_scaled_imu_get_yacc(msg); - scaled_imu->zacc = mavlink_msg_scaled_imu_get_zacc(msg); - scaled_imu->xgyro = mavlink_msg_scaled_imu_get_xgyro(msg); - scaled_imu->ygyro = mavlink_msg_scaled_imu_get_ygyro(msg); - scaled_imu->zgyro = mavlink_msg_scaled_imu_get_zgyro(msg); - scaled_imu->xmag = mavlink_msg_scaled_imu_get_xmag(msg); - scaled_imu->ymag = mavlink_msg_scaled_imu_get_ymag(msg); - scaled_imu->zmag = mavlink_msg_scaled_imu_get_zmag(msg); -#else - memcpy(scaled_imu, _MAV_PAYLOAD(msg), 26); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_scaled_pressure.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_scaled_pressure.h deleted file mode 100644 index 579f7f4ee3..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_scaled_pressure.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE SCALED_PRESSURE PACKING - -#define MAVLINK_MSG_ID_SCALED_PRESSURE 38 - -typedef struct __mavlink_scaled_pressure_t -{ - uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) - float press_abs; ///< Absolute pressure (hectopascal) - float press_diff; ///< Differential pressure 1 (hectopascal) - int16_t temperature; ///< Temperature measurement (0.01 degrees celsius) -} mavlink_scaled_pressure_t; - -#define MAVLINK_MSG_ID_SCALED_PRESSURE_LEN 18 -#define MAVLINK_MSG_ID_38_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_SCALED_PRESSURE { \ - "SCALED_PRESSURE", \ - 4, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_scaled_pressure_t, usec) }, \ - { "press_abs", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_scaled_pressure_t, press_abs) }, \ - { "press_diff", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_scaled_pressure_t, press_diff) }, \ - { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_scaled_pressure_t, temperature) }, \ - } \ -} - - -/** - * @brief Pack a scaled_pressure message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param press_abs Absolute pressure (hectopascal) - * @param press_diff Differential pressure 1 (hectopascal) - * @param temperature Temperature measurement (0.01 degrees celsius) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_scaled_pressure_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float press_abs, float press_diff, int16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, press_abs); - _mav_put_float(buf, 12, press_diff); - _mav_put_int16_t(buf, 16, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_scaled_pressure_t packet; - packet.usec = usec; - packet.press_abs = press_abs; - packet.press_diff = press_diff; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_SCALED_PRESSURE; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a scaled_pressure message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param press_abs Absolute pressure (hectopascal) - * @param press_diff Differential pressure 1 (hectopascal) - * @param temperature Temperature measurement (0.01 degrees celsius) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_scaled_pressure_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float press_abs,float press_diff,int16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, press_abs); - _mav_put_float(buf, 12, press_diff); - _mav_put_int16_t(buf, 16, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_scaled_pressure_t packet; - packet.usec = usec; - packet.press_abs = press_abs; - packet.press_diff = press_diff; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_SCALED_PRESSURE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a scaled_pressure struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param scaled_pressure C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_scaled_pressure_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_scaled_pressure_t* scaled_pressure) -{ - return mavlink_msg_scaled_pressure_pack(system_id, component_id, msg, scaled_pressure->usec, scaled_pressure->press_abs, scaled_pressure->press_diff, scaled_pressure->temperature); -} - -/** - * @brief Send a scaled_pressure message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot) - * @param press_abs Absolute pressure (hectopascal) - * @param press_diff Differential pressure 1 (hectopascal) - * @param temperature Temperature measurement (0.01 degrees celsius) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_scaled_pressure_send(mavlink_channel_t chan, uint64_t usec, float press_abs, float press_diff, int16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, press_abs); - _mav_put_float(buf, 12, press_diff); - _mav_put_int16_t(buf, 16, temperature); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SCALED_PRESSURE, buf, 18); -#else - mavlink_scaled_pressure_t packet; - packet.usec = usec; - packet.press_abs = press_abs; - packet.press_diff = press_diff; - packet.temperature = temperature; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SCALED_PRESSURE, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE SCALED_PRESSURE UNPACKING - - -/** - * @brief Get field usec from scaled_pressure message - * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) - */ -static inline uint64_t mavlink_msg_scaled_pressure_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field press_abs from scaled_pressure message - * - * @return Absolute pressure (hectopascal) - */ -static inline float mavlink_msg_scaled_pressure_get_press_abs(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field press_diff from scaled_pressure message - * - * @return Differential pressure 1 (hectopascal) - */ -static inline float mavlink_msg_scaled_pressure_get_press_diff(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field temperature from scaled_pressure message - * - * @return Temperature measurement (0.01 degrees celsius) - */ -static inline int16_t mavlink_msg_scaled_pressure_get_temperature(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 16); -} - -/** - * @brief Decode a scaled_pressure message into a struct - * - * @param msg The message to decode - * @param scaled_pressure C-struct to decode the message contents into - */ -static inline void mavlink_msg_scaled_pressure_decode(const mavlink_message_t* msg, mavlink_scaled_pressure_t* scaled_pressure) -{ -#if MAVLINK_NEED_BYTE_SWAP - scaled_pressure->usec = mavlink_msg_scaled_pressure_get_usec(msg); - scaled_pressure->press_abs = mavlink_msg_scaled_pressure_get_press_abs(msg); - scaled_pressure->press_diff = mavlink_msg_scaled_pressure_get_press_diff(msg); - scaled_pressure->temperature = mavlink_msg_scaled_pressure_get_temperature(msg); -#else - memcpy(scaled_pressure, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_servo_output_raw.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_servo_output_raw.h deleted file mode 100644 index b5be3318cc..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_servo_output_raw.h +++ /dev/null @@ -1,298 +0,0 @@ -// MESSAGE SERVO_OUTPUT_RAW PACKING - -#define MAVLINK_MSG_ID_SERVO_OUTPUT_RAW 37 - -typedef struct __mavlink_servo_output_raw_t -{ - uint16_t servo1_raw; ///< Servo output 1 value, in microseconds - uint16_t servo2_raw; ///< Servo output 2 value, in microseconds - uint16_t servo3_raw; ///< Servo output 3 value, in microseconds - uint16_t servo4_raw; ///< Servo output 4 value, in microseconds - uint16_t servo5_raw; ///< Servo output 5 value, in microseconds - uint16_t servo6_raw; ///< Servo output 6 value, in microseconds - uint16_t servo7_raw; ///< Servo output 7 value, in microseconds - uint16_t servo8_raw; ///< Servo output 8 value, in microseconds -} mavlink_servo_output_raw_t; - -#define MAVLINK_MSG_ID_SERVO_OUTPUT_RAW_LEN 16 -#define MAVLINK_MSG_ID_37_LEN 16 - - - -#define MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW { \ - "SERVO_OUTPUT_RAW", \ - 8, \ - { { "servo1_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_servo_output_raw_t, servo1_raw) }, \ - { "servo2_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_servo_output_raw_t, servo2_raw) }, \ - { "servo3_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_servo_output_raw_t, servo3_raw) }, \ - { "servo4_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_servo_output_raw_t, servo4_raw) }, \ - { "servo5_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_servo_output_raw_t, servo5_raw) }, \ - { "servo6_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_servo_output_raw_t, servo6_raw) }, \ - { "servo7_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 12, offsetof(mavlink_servo_output_raw_t, servo7_raw) }, \ - { "servo8_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 14, offsetof(mavlink_servo_output_raw_t, servo8_raw) }, \ - } \ -} - - -/** - * @brief Pack a servo_output_raw message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param servo1_raw Servo output 1 value, in microseconds - * @param servo2_raw Servo output 2 value, in microseconds - * @param servo3_raw Servo output 3 value, in microseconds - * @param servo4_raw Servo output 4 value, in microseconds - * @param servo5_raw Servo output 5 value, in microseconds - * @param servo6_raw Servo output 6 value, in microseconds - * @param servo7_raw Servo output 7 value, in microseconds - * @param servo8_raw Servo output 8 value, in microseconds - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_servo_output_raw_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t servo1_raw, uint16_t servo2_raw, uint16_t servo3_raw, uint16_t servo4_raw, uint16_t servo5_raw, uint16_t servo6_raw, uint16_t servo7_raw, uint16_t servo8_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint16_t(buf, 0, servo1_raw); - _mav_put_uint16_t(buf, 2, servo2_raw); - _mav_put_uint16_t(buf, 4, servo3_raw); - _mav_put_uint16_t(buf, 6, servo4_raw); - _mav_put_uint16_t(buf, 8, servo5_raw); - _mav_put_uint16_t(buf, 10, servo6_raw); - _mav_put_uint16_t(buf, 12, servo7_raw); - _mav_put_uint16_t(buf, 14, servo8_raw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_servo_output_raw_t packet; - packet.servo1_raw = servo1_raw; - packet.servo2_raw = servo2_raw; - packet.servo3_raw = servo3_raw; - packet.servo4_raw = servo4_raw; - packet.servo5_raw = servo5_raw; - packet.servo6_raw = servo6_raw; - packet.servo7_raw = servo7_raw; - packet.servo8_raw = servo8_raw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_SERVO_OUTPUT_RAW; - return mavlink_finalize_message(msg, system_id, component_id, 16); -} - -/** - * @brief Pack a servo_output_raw message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param servo1_raw Servo output 1 value, in microseconds - * @param servo2_raw Servo output 2 value, in microseconds - * @param servo3_raw Servo output 3 value, in microseconds - * @param servo4_raw Servo output 4 value, in microseconds - * @param servo5_raw Servo output 5 value, in microseconds - * @param servo6_raw Servo output 6 value, in microseconds - * @param servo7_raw Servo output 7 value, in microseconds - * @param servo8_raw Servo output 8 value, in microseconds - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_servo_output_raw_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t servo1_raw,uint16_t servo2_raw,uint16_t servo3_raw,uint16_t servo4_raw,uint16_t servo5_raw,uint16_t servo6_raw,uint16_t servo7_raw,uint16_t servo8_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint16_t(buf, 0, servo1_raw); - _mav_put_uint16_t(buf, 2, servo2_raw); - _mav_put_uint16_t(buf, 4, servo3_raw); - _mav_put_uint16_t(buf, 6, servo4_raw); - _mav_put_uint16_t(buf, 8, servo5_raw); - _mav_put_uint16_t(buf, 10, servo6_raw); - _mav_put_uint16_t(buf, 12, servo7_raw); - _mav_put_uint16_t(buf, 14, servo8_raw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_servo_output_raw_t packet; - packet.servo1_raw = servo1_raw; - packet.servo2_raw = servo2_raw; - packet.servo3_raw = servo3_raw; - packet.servo4_raw = servo4_raw; - packet.servo5_raw = servo5_raw; - packet.servo6_raw = servo6_raw; - packet.servo7_raw = servo7_raw; - packet.servo8_raw = servo8_raw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_SERVO_OUTPUT_RAW; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 16); -} - -/** - * @brief Encode a servo_output_raw struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param servo_output_raw C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_servo_output_raw_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_servo_output_raw_t* servo_output_raw) -{ - return mavlink_msg_servo_output_raw_pack(system_id, component_id, msg, servo_output_raw->servo1_raw, servo_output_raw->servo2_raw, servo_output_raw->servo3_raw, servo_output_raw->servo4_raw, servo_output_raw->servo5_raw, servo_output_raw->servo6_raw, servo_output_raw->servo7_raw, servo_output_raw->servo8_raw); -} - -/** - * @brief Send a servo_output_raw message - * @param chan MAVLink channel to send the message - * - * @param servo1_raw Servo output 1 value, in microseconds - * @param servo2_raw Servo output 2 value, in microseconds - * @param servo3_raw Servo output 3 value, in microseconds - * @param servo4_raw Servo output 4 value, in microseconds - * @param servo5_raw Servo output 5 value, in microseconds - * @param servo6_raw Servo output 6 value, in microseconds - * @param servo7_raw Servo output 7 value, in microseconds - * @param servo8_raw Servo output 8 value, in microseconds - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_servo_output_raw_send(mavlink_channel_t chan, uint16_t servo1_raw, uint16_t servo2_raw, uint16_t servo3_raw, uint16_t servo4_raw, uint16_t servo5_raw, uint16_t servo6_raw, uint16_t servo7_raw, uint16_t servo8_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint16_t(buf, 0, servo1_raw); - _mav_put_uint16_t(buf, 2, servo2_raw); - _mav_put_uint16_t(buf, 4, servo3_raw); - _mav_put_uint16_t(buf, 6, servo4_raw); - _mav_put_uint16_t(buf, 8, servo5_raw); - _mav_put_uint16_t(buf, 10, servo6_raw); - _mav_put_uint16_t(buf, 12, servo7_raw); - _mav_put_uint16_t(buf, 14, servo8_raw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, buf, 16); -#else - mavlink_servo_output_raw_t packet; - packet.servo1_raw = servo1_raw; - packet.servo2_raw = servo2_raw; - packet.servo3_raw = servo3_raw; - packet.servo4_raw = servo4_raw; - packet.servo5_raw = servo5_raw; - packet.servo6_raw = servo6_raw; - packet.servo7_raw = servo7_raw; - packet.servo8_raw = servo8_raw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, (const char *)&packet, 16); -#endif -} - -#endif - -// MESSAGE SERVO_OUTPUT_RAW UNPACKING - - -/** - * @brief Get field servo1_raw from servo_output_raw message - * - * @return Servo output 1 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo1_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field servo2_raw from servo_output_raw message - * - * @return Servo output 2 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo2_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field servo3_raw from servo_output_raw message - * - * @return Servo output 3 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo3_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 4); -} - -/** - * @brief Get field servo4_raw from servo_output_raw message - * - * @return Servo output 4 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo4_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 6); -} - -/** - * @brief Get field servo5_raw from servo_output_raw message - * - * @return Servo output 5 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo5_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Get field servo6_raw from servo_output_raw message - * - * @return Servo output 6 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo6_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 10); -} - -/** - * @brief Get field servo7_raw from servo_output_raw message - * - * @return Servo output 7 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo7_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 12); -} - -/** - * @brief Get field servo8_raw from servo_output_raw message - * - * @return Servo output 8 value, in microseconds - */ -static inline uint16_t mavlink_msg_servo_output_raw_get_servo8_raw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 14); -} - -/** - * @brief Decode a servo_output_raw message into a struct - * - * @param msg The message to decode - * @param servo_output_raw C-struct to decode the message contents into - */ -static inline void mavlink_msg_servo_output_raw_decode(const mavlink_message_t* msg, mavlink_servo_output_raw_t* servo_output_raw) -{ -#if MAVLINK_NEED_BYTE_SWAP - servo_output_raw->servo1_raw = mavlink_msg_servo_output_raw_get_servo1_raw(msg); - servo_output_raw->servo2_raw = mavlink_msg_servo_output_raw_get_servo2_raw(msg); - servo_output_raw->servo3_raw = mavlink_msg_servo_output_raw_get_servo3_raw(msg); - servo_output_raw->servo4_raw = mavlink_msg_servo_output_raw_get_servo4_raw(msg); - servo_output_raw->servo5_raw = mavlink_msg_servo_output_raw_get_servo5_raw(msg); - servo_output_raw->servo6_raw = mavlink_msg_servo_output_raw_get_servo6_raw(msg); - servo_output_raw->servo7_raw = mavlink_msg_servo_output_raw_get_servo7_raw(msg); - servo_output_raw->servo8_raw = mavlink_msg_servo_output_raw_get_servo8_raw(msg); -#else - memcpy(servo_output_raw, _MAV_PAYLOAD(msg), 16); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_altitude.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_altitude.h deleted file mode 100644 index 72cc5e7b0c..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_altitude.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE SET_ALTITUDE PACKING - -#define MAVLINK_MSG_ID_SET_ALTITUDE 65 - -typedef struct __mavlink_set_altitude_t -{ - uint8_t target; ///< The system setting the altitude - uint32_t mode; ///< The new altitude in meters -} mavlink_set_altitude_t; - -#define MAVLINK_MSG_ID_SET_ALTITUDE_LEN 5 -#define MAVLINK_MSG_ID_65_LEN 5 - - - -#define MAVLINK_MESSAGE_INFO_SET_ALTITUDE { \ - "SET_ALTITUDE", \ - 2, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_altitude_t, target) }, \ - { "mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 1, offsetof(mavlink_set_altitude_t, mode) }, \ - } \ -} - - -/** - * @brief Pack a set_altitude message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the altitude - * @param mode The new altitude in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_altitude_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint32_t mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[5]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint32_t(buf, 1, mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 5); -#else - mavlink_set_altitude_t packet; - packet.target = target; - packet.mode = mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 5); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_ALTITUDE; - return mavlink_finalize_message(msg, system_id, component_id, 5); -} - -/** - * @brief Pack a set_altitude message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the altitude - * @param mode The new altitude in meters - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_altitude_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint32_t mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[5]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint32_t(buf, 1, mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 5); -#else - mavlink_set_altitude_t packet; - packet.target = target; - packet.mode = mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 5); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_ALTITUDE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 5); -} - -/** - * @brief Encode a set_altitude struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_altitude C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_altitude_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_altitude_t* set_altitude) -{ - return mavlink_msg_set_altitude_pack(system_id, component_id, msg, set_altitude->target, set_altitude->mode); -} - -/** - * @brief Send a set_altitude message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the altitude - * @param mode The new altitude in meters - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_altitude_send(mavlink_channel_t chan, uint8_t target, uint32_t mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[5]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint32_t(buf, 1, mode); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_ALTITUDE, buf, 5); -#else - mavlink_set_altitude_t packet; - packet.target = target; - packet.mode = mode; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_ALTITUDE, (const char *)&packet, 5); -#endif -} - -#endif - -// MESSAGE SET_ALTITUDE UNPACKING - - -/** - * @brief Get field target from set_altitude message - * - * @return The system setting the altitude - */ -static inline uint8_t mavlink_msg_set_altitude_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field mode from set_altitude message - * - * @return The new altitude in meters - */ -static inline uint32_t mavlink_msg_set_altitude_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 1); -} - -/** - * @brief Decode a set_altitude message into a struct - * - * @param msg The message to decode - * @param set_altitude C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_altitude_decode(const mavlink_message_t* msg, mavlink_set_altitude_t* set_altitude) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_altitude->target = mavlink_msg_set_altitude_get_target(msg); - set_altitude->mode = mavlink_msg_set_altitude_get_mode(msg); -#else - memcpy(set_altitude, _MAV_PAYLOAD(msg), 5); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_mode.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_mode.h deleted file mode 100644 index 8a3f20593d..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_mode.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE SET_MODE PACKING - -#define MAVLINK_MSG_ID_SET_MODE 11 - -typedef struct __mavlink_set_mode_t -{ - uint8_t target; ///< The system setting the mode - uint8_t mode; ///< The new mode -} mavlink_set_mode_t; - -#define MAVLINK_MSG_ID_SET_MODE_LEN 2 -#define MAVLINK_MSG_ID_11_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_SET_MODE { \ - "SET_MODE", \ - 2, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_mode_t, target) }, \ - { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_set_mode_t, mode) }, \ - } \ -} - - -/** - * @brief Pack a set_mode message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the mode - * @param mode The new mode - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_mode_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint8_t mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_set_mode_t packet; - packet.target = target; - packet.mode = mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_MODE; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a set_mode message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the mode - * @param mode The new mode - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_mode_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint8_t mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_set_mode_t packet; - packet.target = target; - packet.mode = mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_MODE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a set_mode struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_mode C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_mode_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_mode_t* set_mode) -{ - return mavlink_msg_set_mode_pack(system_id, component_id, msg, set_mode->target, set_mode->mode); -} - -/** - * @brief Send a set_mode message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the mode - * @param mode The new mode - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_mode_send(mavlink_channel_t chan, uint8_t target, uint8_t mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, mode); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_MODE, buf, 2); -#else - mavlink_set_mode_t packet; - packet.target = target; - packet.mode = mode; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_MODE, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE SET_MODE UNPACKING - - -/** - * @brief Get field target from set_mode message - * - * @return The system setting the mode - */ -static inline uint8_t mavlink_msg_set_mode_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field mode from set_mode message - * - * @return The new mode - */ -static inline uint8_t mavlink_msg_set_mode_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Decode a set_mode message into a struct - * - * @param msg The message to decode - * @param set_mode C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_mode_decode(const mavlink_message_t* msg, mavlink_set_mode_t* set_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_mode->target = mavlink_msg_set_mode_get_target(msg); - set_mode->mode = mavlink_msg_set_mode_get_mode(msg); -#else - memcpy(set_mode, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_nav_mode.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_nav_mode.h deleted file mode 100644 index 02efa26b19..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_nav_mode.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE SET_NAV_MODE PACKING - -#define MAVLINK_MSG_ID_SET_NAV_MODE 12 - -typedef struct __mavlink_set_nav_mode_t -{ - uint8_t target; ///< The system setting the mode - uint8_t nav_mode; ///< The new navigation mode -} mavlink_set_nav_mode_t; - -#define MAVLINK_MSG_ID_SET_NAV_MODE_LEN 2 -#define MAVLINK_MSG_ID_12_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_SET_NAV_MODE { \ - "SET_NAV_MODE", \ - 2, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_nav_mode_t, target) }, \ - { "nav_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_set_nav_mode_t, nav_mode) }, \ - } \ -} - - -/** - * @brief Pack a set_nav_mode message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the mode - * @param nav_mode The new navigation mode - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_nav_mode_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint8_t nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, nav_mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_set_nav_mode_t packet; - packet.target = target; - packet.nav_mode = nav_mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_NAV_MODE; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a set_nav_mode message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the mode - * @param nav_mode The new navigation mode - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_nav_mode_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint8_t nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, nav_mode); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_set_nav_mode_t packet; - packet.target = target; - packet.nav_mode = nav_mode; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_NAV_MODE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a set_nav_mode struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_nav_mode C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_nav_mode_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_nav_mode_t* set_nav_mode) -{ - return mavlink_msg_set_nav_mode_pack(system_id, component_id, msg, set_nav_mode->target, set_nav_mode->nav_mode); -} - -/** - * @brief Send a set_nav_mode message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the mode - * @param nav_mode The new navigation mode - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_nav_mode_send(mavlink_channel_t chan, uint8_t target, uint8_t nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, nav_mode); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_NAV_MODE, buf, 2); -#else - mavlink_set_nav_mode_t packet; - packet.target = target; - packet.nav_mode = nav_mode; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_NAV_MODE, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE SET_NAV_MODE UNPACKING - - -/** - * @brief Get field target from set_nav_mode message - * - * @return The system setting the mode - */ -static inline uint8_t mavlink_msg_set_nav_mode_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field nav_mode from set_nav_mode message - * - * @return The new navigation mode - */ -static inline uint8_t mavlink_msg_set_nav_mode_get_nav_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Decode a set_nav_mode message into a struct - * - * @param msg The message to decode - * @param set_nav_mode C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_nav_mode_decode(const mavlink_message_t* msg, mavlink_set_nav_mode_t* set_nav_mode) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_nav_mode->target = mavlink_msg_set_nav_mode_get_target(msg); - set_nav_mode->nav_mode = mavlink_msg_set_nav_mode_get_nav_mode(msg); -#else - memcpy(set_nav_mode, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_roll_pitch_yaw_speed_thrust.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_roll_pitch_yaw_speed_thrust.h deleted file mode 100644 index 6a9c01215b..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_roll_pitch_yaw_speed_thrust.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE SET_ROLL_PITCH_YAW_SPEED_THRUST PACKING - -#define MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST 56 - -typedef struct __mavlink_set_roll_pitch_yaw_speed_thrust_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - float roll_speed; ///< Desired roll angular speed in rad/s - float pitch_speed; ///< Desired pitch angular speed in rad/s - float yaw_speed; ///< Desired yaw angular speed in rad/s - float thrust; ///< Collective thrust, normalized to 0 .. 1 -} mavlink_set_roll_pitch_yaw_speed_thrust_t; - -#define MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST_LEN 18 -#define MAVLINK_MSG_ID_56_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST { \ - "SET_ROLL_PITCH_YAW_SPEED_THRUST", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_roll_pitch_yaw_speed_thrust_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_set_roll_pitch_yaw_speed_thrust_t, target_component) }, \ - { "roll_speed", NULL, MAVLINK_TYPE_FLOAT, 0, 2, offsetof(mavlink_set_roll_pitch_yaw_speed_thrust_t, roll_speed) }, \ - { "pitch_speed", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_set_roll_pitch_yaw_speed_thrust_t, pitch_speed) }, \ - { "yaw_speed", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_set_roll_pitch_yaw_speed_thrust_t, yaw_speed) }, \ - { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_set_roll_pitch_yaw_speed_thrust_t, thrust) }, \ - } \ -} - - -/** - * @brief Pack a set_roll_pitch_yaw_speed_thrust message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param roll_speed Desired roll angular speed in rad/s - * @param pitch_speed Desired pitch angular speed in rad/s - * @param yaw_speed Desired yaw angular speed in rad/s - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_roll_pitch_yaw_speed_thrust_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, float roll_speed, float pitch_speed, float yaw_speed, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, roll_speed); - _mav_put_float(buf, 6, pitch_speed); - _mav_put_float(buf, 10, yaw_speed); - _mav_put_float(buf, 14, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_set_roll_pitch_yaw_speed_thrust_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.roll_speed = roll_speed; - packet.pitch_speed = pitch_speed; - packet.yaw_speed = yaw_speed; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a set_roll_pitch_yaw_speed_thrust message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param roll_speed Desired roll angular speed in rad/s - * @param pitch_speed Desired pitch angular speed in rad/s - * @param yaw_speed Desired yaw angular speed in rad/s - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_roll_pitch_yaw_speed_thrust_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,float roll_speed,float pitch_speed,float yaw_speed,float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, roll_speed); - _mav_put_float(buf, 6, pitch_speed); - _mav_put_float(buf, 10, yaw_speed); - _mav_put_float(buf, 14, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_set_roll_pitch_yaw_speed_thrust_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.roll_speed = roll_speed; - packet.pitch_speed = pitch_speed; - packet.yaw_speed = yaw_speed; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a set_roll_pitch_yaw_speed_thrust struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_roll_pitch_yaw_speed_thrust C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_roll_pitch_yaw_speed_thrust_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_roll_pitch_yaw_speed_thrust_t* set_roll_pitch_yaw_speed_thrust) -{ - return mavlink_msg_set_roll_pitch_yaw_speed_thrust_pack(system_id, component_id, msg, set_roll_pitch_yaw_speed_thrust->target_system, set_roll_pitch_yaw_speed_thrust->target_component, set_roll_pitch_yaw_speed_thrust->roll_speed, set_roll_pitch_yaw_speed_thrust->pitch_speed, set_roll_pitch_yaw_speed_thrust->yaw_speed, set_roll_pitch_yaw_speed_thrust->thrust); -} - -/** - * @brief Send a set_roll_pitch_yaw_speed_thrust message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param roll_speed Desired roll angular speed in rad/s - * @param pitch_speed Desired pitch angular speed in rad/s - * @param yaw_speed Desired yaw angular speed in rad/s - * @param thrust Collective thrust, normalized to 0 .. 1 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_roll_pitch_yaw_speed_thrust_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, float roll_speed, float pitch_speed, float yaw_speed, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, roll_speed); - _mav_put_float(buf, 6, pitch_speed); - _mav_put_float(buf, 10, yaw_speed); - _mav_put_float(buf, 14, thrust); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST, buf, 18); -#else - mavlink_set_roll_pitch_yaw_speed_thrust_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.roll_speed = roll_speed; - packet.pitch_speed = pitch_speed; - packet.yaw_speed = yaw_speed; - packet.thrust = thrust; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE SET_ROLL_PITCH_YAW_SPEED_THRUST UNPACKING - - -/** - * @brief Get field target_system from set_roll_pitch_yaw_speed_thrust message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from set_roll_pitch_yaw_speed_thrust message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field roll_speed from set_roll_pitch_yaw_speed_thrust message - * - * @return Desired roll angular speed in rad/s - */ -static inline float mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_roll_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 2); -} - -/** - * @brief Get field pitch_speed from set_roll_pitch_yaw_speed_thrust message - * - * @return Desired pitch angular speed in rad/s - */ -static inline float mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_pitch_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field yaw_speed from set_roll_pitch_yaw_speed_thrust message - * - * @return Desired yaw angular speed in rad/s - */ -static inline float mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_yaw_speed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Get field thrust from set_roll_pitch_yaw_speed_thrust message - * - * @return Collective thrust, normalized to 0 .. 1 - */ -static inline float mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_thrust(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Decode a set_roll_pitch_yaw_speed_thrust message into a struct - * - * @param msg The message to decode - * @param set_roll_pitch_yaw_speed_thrust C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_roll_pitch_yaw_speed_thrust_decode(const mavlink_message_t* msg, mavlink_set_roll_pitch_yaw_speed_thrust_t* set_roll_pitch_yaw_speed_thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_roll_pitch_yaw_speed_thrust->target_system = mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_target_system(msg); - set_roll_pitch_yaw_speed_thrust->target_component = mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_target_component(msg); - set_roll_pitch_yaw_speed_thrust->roll_speed = mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_roll_speed(msg); - set_roll_pitch_yaw_speed_thrust->pitch_speed = mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_pitch_speed(msg); - set_roll_pitch_yaw_speed_thrust->yaw_speed = mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_yaw_speed(msg); - set_roll_pitch_yaw_speed_thrust->thrust = mavlink_msg_set_roll_pitch_yaw_speed_thrust_get_thrust(msg); -#else - memcpy(set_roll_pitch_yaw_speed_thrust, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_roll_pitch_yaw_thrust.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_roll_pitch_yaw_thrust.h deleted file mode 100644 index dad4f657dd..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_set_roll_pitch_yaw_thrust.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE SET_ROLL_PITCH_YAW_THRUST PACKING - -#define MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST 55 - -typedef struct __mavlink_set_roll_pitch_yaw_thrust_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - float roll; ///< Desired roll angle in radians - float pitch; ///< Desired pitch angle in radians - float yaw; ///< Desired yaw angle in radians - float thrust; ///< Collective thrust, normalized to 0 .. 1 -} mavlink_set_roll_pitch_yaw_thrust_t; - -#define MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST_LEN 18 -#define MAVLINK_MSG_ID_55_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST { \ - "SET_ROLL_PITCH_YAW_THRUST", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_roll_pitch_yaw_thrust_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_set_roll_pitch_yaw_thrust_t, target_component) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 2, offsetof(mavlink_set_roll_pitch_yaw_thrust_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_set_roll_pitch_yaw_thrust_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_set_roll_pitch_yaw_thrust_t, yaw) }, \ - { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_set_roll_pitch_yaw_thrust_t, thrust) }, \ - } \ -} - - -/** - * @brief Pack a set_roll_pitch_yaw_thrust message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param roll Desired roll angle in radians - * @param pitch Desired pitch angle in radians - * @param yaw Desired yaw angle in radians - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_roll_pitch_yaw_thrust_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, float roll, float pitch, float yaw, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, roll); - _mav_put_float(buf, 6, pitch); - _mav_put_float(buf, 10, yaw); - _mav_put_float(buf, 14, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_set_roll_pitch_yaw_thrust_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a set_roll_pitch_yaw_thrust message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param roll Desired roll angle in radians - * @param pitch Desired pitch angle in radians - * @param yaw Desired yaw angle in radians - * @param thrust Collective thrust, normalized to 0 .. 1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_roll_pitch_yaw_thrust_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,float roll,float pitch,float yaw,float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, roll); - _mav_put_float(buf, 6, pitch); - _mav_put_float(buf, 10, yaw); - _mav_put_float(buf, 14, thrust); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_set_roll_pitch_yaw_thrust_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a set_roll_pitch_yaw_thrust struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_roll_pitch_yaw_thrust C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_roll_pitch_yaw_thrust_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_roll_pitch_yaw_thrust_t* set_roll_pitch_yaw_thrust) -{ - return mavlink_msg_set_roll_pitch_yaw_thrust_pack(system_id, component_id, msg, set_roll_pitch_yaw_thrust->target_system, set_roll_pitch_yaw_thrust->target_component, set_roll_pitch_yaw_thrust->roll, set_roll_pitch_yaw_thrust->pitch, set_roll_pitch_yaw_thrust->yaw, set_roll_pitch_yaw_thrust->thrust); -} - -/** - * @brief Send a set_roll_pitch_yaw_thrust message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param roll Desired roll angle in radians - * @param pitch Desired pitch angle in radians - * @param yaw Desired yaw angle in radians - * @param thrust Collective thrust, normalized to 0 .. 1 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_roll_pitch_yaw_thrust_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, float roll, float pitch, float yaw, float thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, roll); - _mav_put_float(buf, 6, pitch); - _mav_put_float(buf, 10, yaw); - _mav_put_float(buf, 14, thrust); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST, buf, 18); -#else - mavlink_set_roll_pitch_yaw_thrust_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE SET_ROLL_PITCH_YAW_THRUST UNPACKING - - -/** - * @brief Get field target_system from set_roll_pitch_yaw_thrust message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_set_roll_pitch_yaw_thrust_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from set_roll_pitch_yaw_thrust message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_set_roll_pitch_yaw_thrust_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field roll from set_roll_pitch_yaw_thrust message - * - * @return Desired roll angle in radians - */ -static inline float mavlink_msg_set_roll_pitch_yaw_thrust_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 2); -} - -/** - * @brief Get field pitch from set_roll_pitch_yaw_thrust message - * - * @return Desired pitch angle in radians - */ -static inline float mavlink_msg_set_roll_pitch_yaw_thrust_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field yaw from set_roll_pitch_yaw_thrust message - * - * @return Desired yaw angle in radians - */ -static inline float mavlink_msg_set_roll_pitch_yaw_thrust_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Get field thrust from set_roll_pitch_yaw_thrust message - * - * @return Collective thrust, normalized to 0 .. 1 - */ -static inline float mavlink_msg_set_roll_pitch_yaw_thrust_get_thrust(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Decode a set_roll_pitch_yaw_thrust message into a struct - * - * @param msg The message to decode - * @param set_roll_pitch_yaw_thrust C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_roll_pitch_yaw_thrust_decode(const mavlink_message_t* msg, mavlink_set_roll_pitch_yaw_thrust_t* set_roll_pitch_yaw_thrust) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_roll_pitch_yaw_thrust->target_system = mavlink_msg_set_roll_pitch_yaw_thrust_get_target_system(msg); - set_roll_pitch_yaw_thrust->target_component = mavlink_msg_set_roll_pitch_yaw_thrust_get_target_component(msg); - set_roll_pitch_yaw_thrust->roll = mavlink_msg_set_roll_pitch_yaw_thrust_get_roll(msg); - set_roll_pitch_yaw_thrust->pitch = mavlink_msg_set_roll_pitch_yaw_thrust_get_pitch(msg); - set_roll_pitch_yaw_thrust->yaw = mavlink_msg_set_roll_pitch_yaw_thrust_get_yaw(msg); - set_roll_pitch_yaw_thrust->thrust = mavlink_msg_set_roll_pitch_yaw_thrust_get_thrust(msg); -#else - memcpy(set_roll_pitch_yaw_thrust, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_state_correction.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_state_correction.h deleted file mode 100644 index ddd785a2ac..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_state_correction.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE STATE_CORRECTION PACKING - -#define MAVLINK_MSG_ID_STATE_CORRECTION 64 - -typedef struct __mavlink_state_correction_t -{ - float xErr; ///< x position error - float yErr; ///< y position error - float zErr; ///< z position error - float rollErr; ///< roll error (radians) - float pitchErr; ///< pitch error (radians) - float yawErr; ///< yaw error (radians) - float vxErr; ///< x velocity - float vyErr; ///< y velocity - float vzErr; ///< z velocity -} mavlink_state_correction_t; - -#define MAVLINK_MSG_ID_STATE_CORRECTION_LEN 36 -#define MAVLINK_MSG_ID_64_LEN 36 - - - -#define MAVLINK_MESSAGE_INFO_STATE_CORRECTION { \ - "STATE_CORRECTION", \ - 9, \ - { { "xErr", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_state_correction_t, xErr) }, \ - { "yErr", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_state_correction_t, yErr) }, \ - { "zErr", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_state_correction_t, zErr) }, \ - { "rollErr", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_state_correction_t, rollErr) }, \ - { "pitchErr", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_state_correction_t, pitchErr) }, \ - { "yawErr", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_state_correction_t, yawErr) }, \ - { "vxErr", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_state_correction_t, vxErr) }, \ - { "vyErr", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_state_correction_t, vyErr) }, \ - { "vzErr", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_state_correction_t, vzErr) }, \ - } \ -} - - -/** - * @brief Pack a state_correction message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param xErr x position error - * @param yErr y position error - * @param zErr z position error - * @param rollErr roll error (radians) - * @param pitchErr pitch error (radians) - * @param yawErr yaw error (radians) - * @param vxErr x velocity - * @param vyErr y velocity - * @param vzErr z velocity - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_state_correction_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float xErr, float yErr, float zErr, float rollErr, float pitchErr, float yawErr, float vxErr, float vyErr, float vzErr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_float(buf, 0, xErr); - _mav_put_float(buf, 4, yErr); - _mav_put_float(buf, 8, zErr); - _mav_put_float(buf, 12, rollErr); - _mav_put_float(buf, 16, pitchErr); - _mav_put_float(buf, 20, yawErr); - _mav_put_float(buf, 24, vxErr); - _mav_put_float(buf, 28, vyErr); - _mav_put_float(buf, 32, vzErr); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_state_correction_t packet; - packet.xErr = xErr; - packet.yErr = yErr; - packet.zErr = zErr; - packet.rollErr = rollErr; - packet.pitchErr = pitchErr; - packet.yawErr = yawErr; - packet.vxErr = vxErr; - packet.vyErr = vyErr; - packet.vzErr = vzErr; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_STATE_CORRECTION; - return mavlink_finalize_message(msg, system_id, component_id, 36); -} - -/** - * @brief Pack a state_correction message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param xErr x position error - * @param yErr y position error - * @param zErr z position error - * @param rollErr roll error (radians) - * @param pitchErr pitch error (radians) - * @param yawErr yaw error (radians) - * @param vxErr x velocity - * @param vyErr y velocity - * @param vzErr z velocity - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_state_correction_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float xErr,float yErr,float zErr,float rollErr,float pitchErr,float yawErr,float vxErr,float vyErr,float vzErr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_float(buf, 0, xErr); - _mav_put_float(buf, 4, yErr); - _mav_put_float(buf, 8, zErr); - _mav_put_float(buf, 12, rollErr); - _mav_put_float(buf, 16, pitchErr); - _mav_put_float(buf, 20, yawErr); - _mav_put_float(buf, 24, vxErr); - _mav_put_float(buf, 28, vyErr); - _mav_put_float(buf, 32, vzErr); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_state_correction_t packet; - packet.xErr = xErr; - packet.yErr = yErr; - packet.zErr = zErr; - packet.rollErr = rollErr; - packet.pitchErr = pitchErr; - packet.yawErr = yawErr; - packet.vxErr = vxErr; - packet.vyErr = vyErr; - packet.vzErr = vzErr; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_STATE_CORRECTION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 36); -} - -/** - * @brief Encode a state_correction struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param state_correction C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_state_correction_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_state_correction_t* state_correction) -{ - return mavlink_msg_state_correction_pack(system_id, component_id, msg, state_correction->xErr, state_correction->yErr, state_correction->zErr, state_correction->rollErr, state_correction->pitchErr, state_correction->yawErr, state_correction->vxErr, state_correction->vyErr, state_correction->vzErr); -} - -/** - * @brief Send a state_correction message - * @param chan MAVLink channel to send the message - * - * @param xErr x position error - * @param yErr y position error - * @param zErr z position error - * @param rollErr roll error (radians) - * @param pitchErr pitch error (radians) - * @param yawErr yaw error (radians) - * @param vxErr x velocity - * @param vyErr y velocity - * @param vzErr z velocity - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_state_correction_send(mavlink_channel_t chan, float xErr, float yErr, float zErr, float rollErr, float pitchErr, float yawErr, float vxErr, float vyErr, float vzErr) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_float(buf, 0, xErr); - _mav_put_float(buf, 4, yErr); - _mav_put_float(buf, 8, zErr); - _mav_put_float(buf, 12, rollErr); - _mav_put_float(buf, 16, pitchErr); - _mav_put_float(buf, 20, yawErr); - _mav_put_float(buf, 24, vxErr); - _mav_put_float(buf, 28, vyErr); - _mav_put_float(buf, 32, vzErr); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_STATE_CORRECTION, buf, 36); -#else - mavlink_state_correction_t packet; - packet.xErr = xErr; - packet.yErr = yErr; - packet.zErr = zErr; - packet.rollErr = rollErr; - packet.pitchErr = pitchErr; - packet.yawErr = yawErr; - packet.vxErr = vxErr; - packet.vyErr = vyErr; - packet.vzErr = vzErr; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_STATE_CORRECTION, (const char *)&packet, 36); -#endif -} - -#endif - -// MESSAGE STATE_CORRECTION UNPACKING - - -/** - * @brief Get field xErr from state_correction message - * - * @return x position error - */ -static inline float mavlink_msg_state_correction_get_xErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field yErr from state_correction message - * - * @return y position error - */ -static inline float mavlink_msg_state_correction_get_yErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field zErr from state_correction message - * - * @return z position error - */ -static inline float mavlink_msg_state_correction_get_zErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field rollErr from state_correction message - * - * @return roll error (radians) - */ -static inline float mavlink_msg_state_correction_get_rollErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field pitchErr from state_correction message - * - * @return pitch error (radians) - */ -static inline float mavlink_msg_state_correction_get_pitchErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field yawErr from state_correction message - * - * @return yaw error (radians) - */ -static inline float mavlink_msg_state_correction_get_yawErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field vxErr from state_correction message - * - * @return x velocity - */ -static inline float mavlink_msg_state_correction_get_vxErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field vyErr from state_correction message - * - * @return y velocity - */ -static inline float mavlink_msg_state_correction_get_vyErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Get field vzErr from state_correction message - * - * @return z velocity - */ -static inline float mavlink_msg_state_correction_get_vzErr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 32); -} - -/** - * @brief Decode a state_correction message into a struct - * - * @param msg The message to decode - * @param state_correction C-struct to decode the message contents into - */ -static inline void mavlink_msg_state_correction_decode(const mavlink_message_t* msg, mavlink_state_correction_t* state_correction) -{ -#if MAVLINK_NEED_BYTE_SWAP - state_correction->xErr = mavlink_msg_state_correction_get_xErr(msg); - state_correction->yErr = mavlink_msg_state_correction_get_yErr(msg); - state_correction->zErr = mavlink_msg_state_correction_get_zErr(msg); - state_correction->rollErr = mavlink_msg_state_correction_get_rollErr(msg); - state_correction->pitchErr = mavlink_msg_state_correction_get_pitchErr(msg); - state_correction->yawErr = mavlink_msg_state_correction_get_yawErr(msg); - state_correction->vxErr = mavlink_msg_state_correction_get_vxErr(msg); - state_correction->vyErr = mavlink_msg_state_correction_get_vyErr(msg); - state_correction->vzErr = mavlink_msg_state_correction_get_vzErr(msg); -#else - memcpy(state_correction, _MAV_PAYLOAD(msg), 36); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_statustext.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_statustext.h deleted file mode 100644 index c65f629e99..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_statustext.h +++ /dev/null @@ -1,160 +0,0 @@ -// MESSAGE STATUSTEXT PACKING - -#define MAVLINK_MSG_ID_STATUSTEXT 254 - -typedef struct __mavlink_statustext_t -{ - uint8_t severity; ///< Severity of status, 0 = info message, 255 = critical fault - int8_t text[50]; ///< Status text message, without null termination character -} mavlink_statustext_t; - -#define MAVLINK_MSG_ID_STATUSTEXT_LEN 51 -#define MAVLINK_MSG_ID_254_LEN 51 - -#define MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN 50 - -#define MAVLINK_MESSAGE_INFO_STATUSTEXT { \ - "STATUSTEXT", \ - 2, \ - { { "severity", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_statustext_t, severity) }, \ - { "text", NULL, MAVLINK_TYPE_INT8_T, 50, 1, offsetof(mavlink_statustext_t, text) }, \ - } \ -} - - -/** - * @brief Pack a statustext message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param severity Severity of status, 0 = info message, 255 = critical fault - * @param text Status text message, without null termination character - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_statustext_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t severity, const int8_t *text) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[51]; - _mav_put_uint8_t(buf, 0, severity); - _mav_put_int8_t_array(buf, 1, text, 50); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 51); -#else - mavlink_statustext_t packet; - packet.severity = severity; - mav_array_memcpy(packet.text, text, sizeof(int8_t)*50); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 51); -#endif - - msg->msgid = MAVLINK_MSG_ID_STATUSTEXT; - return mavlink_finalize_message(msg, system_id, component_id, 51); -} - -/** - * @brief Pack a statustext message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param severity Severity of status, 0 = info message, 255 = critical fault - * @param text Status text message, without null termination character - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_statustext_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t severity,const int8_t *text) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[51]; - _mav_put_uint8_t(buf, 0, severity); - _mav_put_int8_t_array(buf, 1, text, 50); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 51); -#else - mavlink_statustext_t packet; - packet.severity = severity; - mav_array_memcpy(packet.text, text, sizeof(int8_t)*50); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 51); -#endif - - msg->msgid = MAVLINK_MSG_ID_STATUSTEXT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 51); -} - -/** - * @brief Encode a statustext struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param statustext C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_statustext_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_statustext_t* statustext) -{ - return mavlink_msg_statustext_pack(system_id, component_id, msg, statustext->severity, statustext->text); -} - -/** - * @brief Send a statustext message - * @param chan MAVLink channel to send the message - * - * @param severity Severity of status, 0 = info message, 255 = critical fault - * @param text Status text message, without null termination character - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_statustext_send(mavlink_channel_t chan, uint8_t severity, const int8_t *text) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[51]; - _mav_put_uint8_t(buf, 0, severity); - _mav_put_int8_t_array(buf, 1, text, 50); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_STATUSTEXT, buf, 51); -#else - mavlink_statustext_t packet; - packet.severity = severity; - mav_array_memcpy(packet.text, text, sizeof(int8_t)*50); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_STATUSTEXT, (const char *)&packet, 51); -#endif -} - -#endif - -// MESSAGE STATUSTEXT UNPACKING - - -/** - * @brief Get field severity from statustext message - * - * @return Severity of status, 0 = info message, 255 = critical fault - */ -static inline uint8_t mavlink_msg_statustext_get_severity(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field text from statustext message - * - * @return Status text message, without null termination character - */ -static inline uint16_t mavlink_msg_statustext_get_text(const mavlink_message_t* msg, int8_t *text) -{ - return _MAV_RETURN_int8_t_array(msg, text, 50, 1); -} - -/** - * @brief Decode a statustext message into a struct - * - * @param msg The message to decode - * @param statustext C-struct to decode the message contents into - */ -static inline void mavlink_msg_statustext_decode(const mavlink_message_t* msg, mavlink_statustext_t* statustext) -{ -#if MAVLINK_NEED_BYTE_SWAP - statustext->severity = mavlink_msg_statustext_get_severity(msg); - mavlink_msg_statustext_get_text(msg, statustext->text); -#else - memcpy(statustext, _MAV_PAYLOAD(msg), 51); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_sys_status.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_sys_status.h deleted file mode 100644 index 1217ea60e9..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_sys_status.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE SYS_STATUS PACKING - -#define MAVLINK_MSG_ID_SYS_STATUS 34 - -typedef struct __mavlink_sys_status_t -{ - uint8_t mode; ///< System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h - uint8_t nav_mode; ///< Navigation mode, see MAV_NAV_MODE ENUM - uint8_t status; ///< System status flag, see MAV_STATUS ENUM - uint16_t load; ///< Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 - uint16_t vbat; ///< Battery voltage, in millivolts (1 = 1 millivolt) - uint16_t battery_remaining; ///< Remaining battery energy: (0%: 0, 100%: 1000) - uint16_t packet_drop; ///< Dropped packets (packets that were corrupted on reception on the MAV) -} mavlink_sys_status_t; - -#define MAVLINK_MSG_ID_SYS_STATUS_LEN 11 -#define MAVLINK_MSG_ID_34_LEN 11 - - - -#define MAVLINK_MESSAGE_INFO_SYS_STATUS { \ - "SYS_STATUS", \ - 7, \ - { { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_sys_status_t, mode) }, \ - { "nav_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_sys_status_t, nav_mode) }, \ - { "status", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_sys_status_t, status) }, \ - { "load", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_sys_status_t, load) }, \ - { "vbat", NULL, MAVLINK_TYPE_UINT16_T, 0, 5, offsetof(mavlink_sys_status_t, vbat) }, \ - { "battery_remaining", NULL, MAVLINK_TYPE_UINT16_T, 0, 7, offsetof(mavlink_sys_status_t, battery_remaining) }, \ - { "packet_drop", NULL, MAVLINK_TYPE_UINT16_T, 0, 9, offsetof(mavlink_sys_status_t, packet_drop) }, \ - } \ -} - - -/** - * @brief Pack a sys_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param mode System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h - * @param nav_mode Navigation mode, see MAV_NAV_MODE ENUM - * @param status System status flag, see MAV_STATUS ENUM - * @param load Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 - * @param vbat Battery voltage, in millivolts (1 = 1 millivolt) - * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 1000) - * @param packet_drop Dropped packets (packets that were corrupted on reception on the MAV) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sys_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t mode, uint8_t nav_mode, uint8_t status, uint16_t load, uint16_t vbat, uint16_t battery_remaining, uint16_t packet_drop) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[11]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, status); - _mav_put_uint16_t(buf, 3, load); - _mav_put_uint16_t(buf, 5, vbat); - _mav_put_uint16_t(buf, 7, battery_remaining); - _mav_put_uint16_t(buf, 9, packet_drop); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 11); -#else - mavlink_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.status = status; - packet.load = load; - packet.vbat = vbat; - packet.battery_remaining = battery_remaining; - packet.packet_drop = packet_drop; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 11); -#endif - - msg->msgid = MAVLINK_MSG_ID_SYS_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 11); -} - -/** - * @brief Pack a sys_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param mode System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h - * @param nav_mode Navigation mode, see MAV_NAV_MODE ENUM - * @param status System status flag, see MAV_STATUS ENUM - * @param load Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 - * @param vbat Battery voltage, in millivolts (1 = 1 millivolt) - * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 1000) - * @param packet_drop Dropped packets (packets that were corrupted on reception on the MAV) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sys_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t mode,uint8_t nav_mode,uint8_t status,uint16_t load,uint16_t vbat,uint16_t battery_remaining,uint16_t packet_drop) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[11]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, status); - _mav_put_uint16_t(buf, 3, load); - _mav_put_uint16_t(buf, 5, vbat); - _mav_put_uint16_t(buf, 7, battery_remaining); - _mav_put_uint16_t(buf, 9, packet_drop); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 11); -#else - mavlink_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.status = status; - packet.load = load; - packet.vbat = vbat; - packet.battery_remaining = battery_remaining; - packet.packet_drop = packet_drop; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 11); -#endif - - msg->msgid = MAVLINK_MSG_ID_SYS_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 11); -} - -/** - * @brief Encode a sys_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param sys_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_sys_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_sys_status_t* sys_status) -{ - return mavlink_msg_sys_status_pack(system_id, component_id, msg, sys_status->mode, sys_status->nav_mode, sys_status->status, sys_status->load, sys_status->vbat, sys_status->battery_remaining, sys_status->packet_drop); -} - -/** - * @brief Send a sys_status message - * @param chan MAVLink channel to send the message - * - * @param mode System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h - * @param nav_mode Navigation mode, see MAV_NAV_MODE ENUM - * @param status System status flag, see MAV_STATUS ENUM - * @param load Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 - * @param vbat Battery voltage, in millivolts (1 = 1 millivolt) - * @param battery_remaining Remaining battery energy: (0%: 0, 100%: 1000) - * @param packet_drop Dropped packets (packets that were corrupted on reception on the MAV) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_sys_status_send(mavlink_channel_t chan, uint8_t mode, uint8_t nav_mode, uint8_t status, uint16_t load, uint16_t vbat, uint16_t battery_remaining, uint16_t packet_drop) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[11]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, status); - _mav_put_uint16_t(buf, 3, load); - _mav_put_uint16_t(buf, 5, vbat); - _mav_put_uint16_t(buf, 7, battery_remaining); - _mav_put_uint16_t(buf, 9, packet_drop); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYS_STATUS, buf, 11); -#else - mavlink_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.status = status; - packet.load = load; - packet.vbat = vbat; - packet.battery_remaining = battery_remaining; - packet.packet_drop = packet_drop; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYS_STATUS, (const char *)&packet, 11); -#endif -} - -#endif - -// MESSAGE SYS_STATUS UNPACKING - - -/** - * @brief Get field mode from sys_status message - * - * @return System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h - */ -static inline uint8_t mavlink_msg_sys_status_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field nav_mode from sys_status message - * - * @return Navigation mode, see MAV_NAV_MODE ENUM - */ -static inline uint8_t mavlink_msg_sys_status_get_nav_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field status from sys_status message - * - * @return System status flag, see MAV_STATUS ENUM - */ -static inline uint8_t mavlink_msg_sys_status_get_status(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field load from sys_status message - * - * @return Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 - */ -static inline uint16_t mavlink_msg_sys_status_get_load(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field vbat from sys_status message - * - * @return Battery voltage, in millivolts (1 = 1 millivolt) - */ -static inline uint16_t mavlink_msg_sys_status_get_vbat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 5); -} - -/** - * @brief Get field battery_remaining from sys_status message - * - * @return Remaining battery energy: (0%: 0, 100%: 1000) - */ -static inline uint16_t mavlink_msg_sys_status_get_battery_remaining(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 7); -} - -/** - * @brief Get field packet_drop from sys_status message - * - * @return Dropped packets (packets that were corrupted on reception on the MAV) - */ -static inline uint16_t mavlink_msg_sys_status_get_packet_drop(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 9); -} - -/** - * @brief Decode a sys_status message into a struct - * - * @param msg The message to decode - * @param sys_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_sys_status_decode(const mavlink_message_t* msg, mavlink_sys_status_t* sys_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - sys_status->mode = mavlink_msg_sys_status_get_mode(msg); - sys_status->nav_mode = mavlink_msg_sys_status_get_nav_mode(msg); - sys_status->status = mavlink_msg_sys_status_get_status(msg); - sys_status->load = mavlink_msg_sys_status_get_load(msg); - sys_status->vbat = mavlink_msg_sys_status_get_vbat(msg); - sys_status->battery_remaining = mavlink_msg_sys_status_get_battery_remaining(msg); - sys_status->packet_drop = mavlink_msg_sys_status_get_packet_drop(msg); -#else - memcpy(sys_status, _MAV_PAYLOAD(msg), 11); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_system_time.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_system_time.h deleted file mode 100644 index 362586a70d..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_system_time.h +++ /dev/null @@ -1,144 +0,0 @@ -// MESSAGE SYSTEM_TIME PACKING - -#define MAVLINK_MSG_ID_SYSTEM_TIME 2 - -typedef struct __mavlink_system_time_t -{ - uint64_t time_usec; ///< Timestamp of the master clock in microseconds since UNIX epoch. -} mavlink_system_time_t; - -#define MAVLINK_MSG_ID_SYSTEM_TIME_LEN 8 -#define MAVLINK_MSG_ID_2_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_SYSTEM_TIME { \ - "SYSTEM_TIME", \ - 1, \ - { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_system_time_t, time_usec) }, \ - } \ -} - - -/** - * @brief Pack a system_time message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param time_usec Timestamp of the master clock in microseconds since UNIX epoch. - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_system_time_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t time_usec) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint64_t(buf, 0, time_usec); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_system_time_t packet; - packet.time_usec = time_usec; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a system_time message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param time_usec Timestamp of the master clock in microseconds since UNIX epoch. - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_system_time_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t time_usec) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint64_t(buf, 0, time_usec); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_system_time_t packet; - packet.time_usec = time_usec; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a system_time struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param system_time C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_system_time_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_system_time_t* system_time) -{ - return mavlink_msg_system_time_pack(system_id, component_id, msg, system_time->time_usec); -} - -/** - * @brief Send a system_time message - * @param chan MAVLink channel to send the message - * - * @param time_usec Timestamp of the master clock in microseconds since UNIX epoch. - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_system_time_send(mavlink_channel_t chan, uint64_t time_usec) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint64_t(buf, 0, time_usec); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, buf, 8); -#else - mavlink_system_time_t packet; - packet.time_usec = time_usec; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE SYSTEM_TIME UNPACKING - - -/** - * @brief Get field time_usec from system_time message - * - * @return Timestamp of the master clock in microseconds since UNIX epoch. - */ -static inline uint64_t mavlink_msg_system_time_get_time_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Decode a system_time message into a struct - * - * @param msg The message to decode - * @param system_time C-struct to decode the message contents into - */ -static inline void mavlink_msg_system_time_decode(const mavlink_message_t* msg, mavlink_system_time_t* system_time) -{ -#if MAVLINK_NEED_BYTE_SWAP - system_time->time_usec = mavlink_msg_system_time_get_time_usec(msg); -#else - memcpy(system_time, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_system_time_utc.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_system_time_utc.h deleted file mode 100644 index 5688435d53..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_system_time_utc.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE SYSTEM_TIME_UTC PACKING - -#define MAVLINK_MSG_ID_SYSTEM_TIME_UTC 4 - -typedef struct __mavlink_system_time_utc_t -{ - uint32_t utc_date; ///< GPS UTC date ddmmyy - uint32_t utc_time; ///< GPS UTC time hhmmss -} mavlink_system_time_utc_t; - -#define MAVLINK_MSG_ID_SYSTEM_TIME_UTC_LEN 8 -#define MAVLINK_MSG_ID_4_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_SYSTEM_TIME_UTC { \ - "SYSTEM_TIME_UTC", \ - 2, \ - { { "utc_date", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_system_time_utc_t, utc_date) }, \ - { "utc_time", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_system_time_utc_t, utc_time) }, \ - } \ -} - - -/** - * @brief Pack a system_time_utc message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param utc_date GPS UTC date ddmmyy - * @param utc_time GPS UTC time hhmmss - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_system_time_utc_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint32_t utc_date, uint32_t utc_time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint32_t(buf, 0, utc_date); - _mav_put_uint32_t(buf, 4, utc_time); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_system_time_utc_t packet; - packet.utc_date = utc_date; - packet.utc_time = utc_time; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME_UTC; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a system_time_utc message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param utc_date GPS UTC date ddmmyy - * @param utc_time GPS UTC time hhmmss - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_system_time_utc_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint32_t utc_date,uint32_t utc_time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint32_t(buf, 0, utc_date); - _mav_put_uint32_t(buf, 4, utc_time); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_system_time_utc_t packet; - packet.utc_date = utc_date; - packet.utc_time = utc_time; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_SYSTEM_TIME_UTC; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a system_time_utc struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param system_time_utc C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_system_time_utc_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_system_time_utc_t* system_time_utc) -{ - return mavlink_msg_system_time_utc_pack(system_id, component_id, msg, system_time_utc->utc_date, system_time_utc->utc_time); -} - -/** - * @brief Send a system_time_utc message - * @param chan MAVLink channel to send the message - * - * @param utc_date GPS UTC date ddmmyy - * @param utc_time GPS UTC time hhmmss - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_system_time_utc_send(mavlink_channel_t chan, uint32_t utc_date, uint32_t utc_time) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint32_t(buf, 0, utc_date); - _mav_put_uint32_t(buf, 4, utc_time); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME_UTC, buf, 8); -#else - mavlink_system_time_utc_t packet; - packet.utc_date = utc_date; - packet.utc_time = utc_time; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SYSTEM_TIME_UTC, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE SYSTEM_TIME_UTC UNPACKING - - -/** - * @brief Get field utc_date from system_time_utc message - * - * @return GPS UTC date ddmmyy - */ -static inline uint32_t mavlink_msg_system_time_utc_get_utc_date(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 0); -} - -/** - * @brief Get field utc_time from system_time_utc message - * - * @return GPS UTC time hhmmss - */ -static inline uint32_t mavlink_msg_system_time_utc_get_utc_time(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 4); -} - -/** - * @brief Decode a system_time_utc message into a struct - * - * @param msg The message to decode - * @param system_time_utc C-struct to decode the message contents into - */ -static inline void mavlink_msg_system_time_utc_decode(const mavlink_message_t* msg, mavlink_system_time_utc_t* system_time_utc) -{ -#if MAVLINK_NEED_BYTE_SWAP - system_time_utc->utc_date = mavlink_msg_system_time_utc_get_utc_date(msg); - system_time_utc->utc_time = mavlink_msg_system_time_utc_get_utc_time(msg); -#else - memcpy(system_time_utc, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_vfr_hud.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_vfr_hud.h deleted file mode 100644 index 0f92de775e..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_vfr_hud.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE VFR_HUD PACKING - -#define MAVLINK_MSG_ID_VFR_HUD 74 - -typedef struct __mavlink_vfr_hud_t -{ - float airspeed; ///< Current airspeed in m/s - float groundspeed; ///< Current ground speed in m/s - int16_t heading; ///< Current heading in degrees, in compass units (0..360, 0=north) - uint16_t throttle; ///< Current throttle setting in integer percent, 0 to 100 - float alt; ///< Current altitude (MSL), in meters - float climb; ///< Current climb rate in meters/second -} mavlink_vfr_hud_t; - -#define MAVLINK_MSG_ID_VFR_HUD_LEN 20 -#define MAVLINK_MSG_ID_74_LEN 20 - - - -#define MAVLINK_MESSAGE_INFO_VFR_HUD { \ - "VFR_HUD", \ - 6, \ - { { "airspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_vfr_hud_t, airspeed) }, \ - { "groundspeed", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_vfr_hud_t, groundspeed) }, \ - { "heading", NULL, MAVLINK_TYPE_INT16_T, 0, 8, offsetof(mavlink_vfr_hud_t, heading) }, \ - { "throttle", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_vfr_hud_t, throttle) }, \ - { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vfr_hud_t, alt) }, \ - { "climb", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_vfr_hud_t, climb) }, \ - } \ -} - - -/** - * @brief Pack a vfr_hud message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param airspeed Current airspeed in m/s - * @param groundspeed Current ground speed in m/s - * @param heading Current heading in degrees, in compass units (0..360, 0=north) - * @param throttle Current throttle setting in integer percent, 0 to 100 - * @param alt Current altitude (MSL), in meters - * @param climb Current climb rate in meters/second - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vfr_hud_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_float(buf, 0, airspeed); - _mav_put_float(buf, 4, groundspeed); - _mav_put_int16_t(buf, 8, heading); - _mav_put_uint16_t(buf, 10, throttle); - _mav_put_float(buf, 12, alt); - _mav_put_float(buf, 16, climb); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_vfr_hud_t packet; - packet.airspeed = airspeed; - packet.groundspeed = groundspeed; - packet.heading = heading; - packet.throttle = throttle; - packet.alt = alt; - packet.climb = climb; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_VFR_HUD; - return mavlink_finalize_message(msg, system_id, component_id, 20); -} - -/** - * @brief Pack a vfr_hud message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param airspeed Current airspeed in m/s - * @param groundspeed Current ground speed in m/s - * @param heading Current heading in degrees, in compass units (0..360, 0=north) - * @param throttle Current throttle setting in integer percent, 0 to 100 - * @param alt Current altitude (MSL), in meters - * @param climb Current climb rate in meters/second - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vfr_hud_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float airspeed,float groundspeed,int16_t heading,uint16_t throttle,float alt,float climb) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_float(buf, 0, airspeed); - _mav_put_float(buf, 4, groundspeed); - _mav_put_int16_t(buf, 8, heading); - _mav_put_uint16_t(buf, 10, throttle); - _mav_put_float(buf, 12, alt); - _mav_put_float(buf, 16, climb); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_vfr_hud_t packet; - packet.airspeed = airspeed; - packet.groundspeed = groundspeed; - packet.heading = heading; - packet.throttle = throttle; - packet.alt = alt; - packet.climb = climb; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_VFR_HUD; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 20); -} - -/** - * @brief Encode a vfr_hud struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param vfr_hud C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_vfr_hud_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vfr_hud_t* vfr_hud) -{ - return mavlink_msg_vfr_hud_pack(system_id, component_id, msg, vfr_hud->airspeed, vfr_hud->groundspeed, vfr_hud->heading, vfr_hud->throttle, vfr_hud->alt, vfr_hud->climb); -} - -/** - * @brief Send a vfr_hud message - * @param chan MAVLink channel to send the message - * - * @param airspeed Current airspeed in m/s - * @param groundspeed Current ground speed in m/s - * @param heading Current heading in degrees, in compass units (0..360, 0=north) - * @param throttle Current throttle setting in integer percent, 0 to 100 - * @param alt Current altitude (MSL), in meters - * @param climb Current climb rate in meters/second - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_vfr_hud_send(mavlink_channel_t chan, float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_float(buf, 0, airspeed); - _mav_put_float(buf, 4, groundspeed); - _mav_put_int16_t(buf, 8, heading); - _mav_put_uint16_t(buf, 10, throttle); - _mav_put_float(buf, 12, alt); - _mav_put_float(buf, 16, climb); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, buf, 20); -#else - mavlink_vfr_hud_t packet; - packet.airspeed = airspeed; - packet.groundspeed = groundspeed; - packet.heading = heading; - packet.throttle = throttle; - packet.alt = alt; - packet.climb = climb; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VFR_HUD, (const char *)&packet, 20); -#endif -} - -#endif - -// MESSAGE VFR_HUD UNPACKING - - -/** - * @brief Get field airspeed from vfr_hud message - * - * @return Current airspeed in m/s - */ -static inline float mavlink_msg_vfr_hud_get_airspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field groundspeed from vfr_hud message - * - * @return Current ground speed in m/s - */ -static inline float mavlink_msg_vfr_hud_get_groundspeed(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field heading from vfr_hud message - * - * @return Current heading in degrees, in compass units (0..360, 0=north) - */ -static inline int16_t mavlink_msg_vfr_hud_get_heading(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 8); -} - -/** - * @brief Get field throttle from vfr_hud message - * - * @return Current throttle setting in integer percent, 0 to 100 - */ -static inline uint16_t mavlink_msg_vfr_hud_get_throttle(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 10); -} - -/** - * @brief Get field alt from vfr_hud message - * - * @return Current altitude (MSL), in meters - */ -static inline float mavlink_msg_vfr_hud_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field climb from vfr_hud message - * - * @return Current climb rate in meters/second - */ -static inline float mavlink_msg_vfr_hud_get_climb(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Decode a vfr_hud message into a struct - * - * @param msg The message to decode - * @param vfr_hud C-struct to decode the message contents into - */ -static inline void mavlink_msg_vfr_hud_decode(const mavlink_message_t* msg, mavlink_vfr_hud_t* vfr_hud) -{ -#if MAVLINK_NEED_BYTE_SWAP - vfr_hud->airspeed = mavlink_msg_vfr_hud_get_airspeed(msg); - vfr_hud->groundspeed = mavlink_msg_vfr_hud_get_groundspeed(msg); - vfr_hud->heading = mavlink_msg_vfr_hud_get_heading(msg); - vfr_hud->throttle = mavlink_msg_vfr_hud_get_throttle(msg); - vfr_hud->alt = mavlink_msg_vfr_hud_get_alt(msg); - vfr_hud->climb = mavlink_msg_vfr_hud_get_climb(msg); -#else - memcpy(vfr_hud, _MAV_PAYLOAD(msg), 20); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint.h deleted file mode 100644 index d9b21e3c94..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint.h +++ /dev/null @@ -1,430 +0,0 @@ -// MESSAGE WAYPOINT PACKING - -#define MAVLINK_MSG_ID_WAYPOINT 39 - -typedef struct __mavlink_waypoint_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint16_t seq; ///< Sequence - uint8_t frame; ///< The coordinate system of the waypoint. see MAV_FRAME in mavlink_types.h - uint8_t command; ///< The scheduled action for the waypoint. see MAV_COMMAND in common.xml MAVLink specs - uint8_t current; ///< false:0, true:1 - uint8_t autocontinue; ///< autocontinue to next wp - float param1; ///< PARAM1 / For NAV command waypoints: Radius in which the waypoint is accepted as reached, in meters - float param2; ///< PARAM2 / For NAV command waypoints: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds - float param3; ///< PARAM3 / For LOITER command waypoints: Orbit to circle around the waypoint, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. - float param4; ///< PARAM4 / For NAV and LOITER command waypoints: Yaw orientation in degrees, [0..360] 0 = NORTH - float x; ///< PARAM5 / local: x position, global: latitude - float y; ///< PARAM6 / y position: global: longitude - float z; ///< PARAM7 / z position: global: altitude -} mavlink_waypoint_t; - -#define MAVLINK_MSG_ID_WAYPOINT_LEN 36 -#define MAVLINK_MSG_ID_39_LEN 36 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT { \ - "WAYPOINT", \ - 14, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_t, target_component) }, \ - { "seq", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_waypoint_t, seq) }, \ - { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_waypoint_t, frame) }, \ - { "command", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_waypoint_t, command) }, \ - { "current", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_waypoint_t, current) }, \ - { "autocontinue", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_waypoint_t, autocontinue) }, \ - { "param1", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_waypoint_t, param1) }, \ - { "param2", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_waypoint_t, param2) }, \ - { "param3", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_waypoint_t, param3) }, \ - { "param4", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_waypoint_t, param4) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_waypoint_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_waypoint_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_waypoint_t, z) }, \ - } \ -} - - -/** - * @brief Pack a waypoint message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @param frame The coordinate system of the waypoint. see MAV_FRAME in mavlink_types.h - * @param command The scheduled action for the waypoint. see MAV_COMMAND in common.xml MAVLink specs - * @param current false:0, true:1 - * @param autocontinue autocontinue to next wp - * @param param1 PARAM1 / For NAV command waypoints: Radius in which the waypoint is accepted as reached, in meters - * @param param2 PARAM2 / For NAV command waypoints: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds - * @param param3 PARAM3 / For LOITER command waypoints: Orbit to circle around the waypoint, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. - * @param param4 PARAM4 / For NAV and LOITER command waypoints: Yaw orientation in degrees, [0..360] 0 = NORTH - * @param x PARAM5 / local: x position, global: latitude - * @param y PARAM6 / y position: global: longitude - * @param z PARAM7 / z position: global: altitude - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint16_t seq, uint8_t frame, uint8_t command, uint8_t current, uint8_t autocontinue, float param1, float param2, float param3, float param4, float x, float y, float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - _mav_put_uint8_t(buf, 4, frame); - _mav_put_uint8_t(buf, 5, command); - _mav_put_uint8_t(buf, 6, current); - _mav_put_uint8_t(buf, 7, autocontinue); - _mav_put_float(buf, 8, param1); - _mav_put_float(buf, 12, param2); - _mav_put_float(buf, 16, param3); - _mav_put_float(buf, 20, param4); - _mav_put_float(buf, 24, x); - _mav_put_float(buf, 28, y); - _mav_put_float(buf, 32, z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_waypoint_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - packet.frame = frame; - packet.command = command; - packet.current = current; - packet.autocontinue = autocontinue; - packet.param1 = param1; - packet.param2 = param2; - packet.param3 = param3; - packet.param4 = param4; - packet.x = x; - packet.y = y; - packet.z = z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT; - return mavlink_finalize_message(msg, system_id, component_id, 36); -} - -/** - * @brief Pack a waypoint message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @param frame The coordinate system of the waypoint. see MAV_FRAME in mavlink_types.h - * @param command The scheduled action for the waypoint. see MAV_COMMAND in common.xml MAVLink specs - * @param current false:0, true:1 - * @param autocontinue autocontinue to next wp - * @param param1 PARAM1 / For NAV command waypoints: Radius in which the waypoint is accepted as reached, in meters - * @param param2 PARAM2 / For NAV command waypoints: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds - * @param param3 PARAM3 / For LOITER command waypoints: Orbit to circle around the waypoint, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. - * @param param4 PARAM4 / For NAV and LOITER command waypoints: Yaw orientation in degrees, [0..360] 0 = NORTH - * @param x PARAM5 / local: x position, global: latitude - * @param y PARAM6 / y position: global: longitude - * @param z PARAM7 / z position: global: altitude - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint16_t seq,uint8_t frame,uint8_t command,uint8_t current,uint8_t autocontinue,float param1,float param2,float param3,float param4,float x,float y,float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - _mav_put_uint8_t(buf, 4, frame); - _mav_put_uint8_t(buf, 5, command); - _mav_put_uint8_t(buf, 6, current); - _mav_put_uint8_t(buf, 7, autocontinue); - _mav_put_float(buf, 8, param1); - _mav_put_float(buf, 12, param2); - _mav_put_float(buf, 16, param3); - _mav_put_float(buf, 20, param4); - _mav_put_float(buf, 24, x); - _mav_put_float(buf, 28, y); - _mav_put_float(buf, 32, z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); -#else - mavlink_waypoint_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - packet.frame = frame; - packet.command = command; - packet.current = current; - packet.autocontinue = autocontinue; - packet.param1 = param1; - packet.param2 = param2; - packet.param3 = param3; - packet.param4 = param4; - packet.x = x; - packet.y = y; - packet.z = z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 36); -} - -/** - * @brief Encode a waypoint struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_t* waypoint) -{ - return mavlink_msg_waypoint_pack(system_id, component_id, msg, waypoint->target_system, waypoint->target_component, waypoint->seq, waypoint->frame, waypoint->command, waypoint->current, waypoint->autocontinue, waypoint->param1, waypoint->param2, waypoint->param3, waypoint->param4, waypoint->x, waypoint->y, waypoint->z); -} - -/** - * @brief Send a waypoint message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @param frame The coordinate system of the waypoint. see MAV_FRAME in mavlink_types.h - * @param command The scheduled action for the waypoint. see MAV_COMMAND in common.xml MAVLink specs - * @param current false:0, true:1 - * @param autocontinue autocontinue to next wp - * @param param1 PARAM1 / For NAV command waypoints: Radius in which the waypoint is accepted as reached, in meters - * @param param2 PARAM2 / For NAV command waypoints: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds - * @param param3 PARAM3 / For LOITER command waypoints: Orbit to circle around the waypoint, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. - * @param param4 PARAM4 / For NAV and LOITER command waypoints: Yaw orientation in degrees, [0..360] 0 = NORTH - * @param x PARAM5 / local: x position, global: latitude - * @param y PARAM6 / y position: global: longitude - * @param z PARAM7 / z position: global: altitude - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t seq, uint8_t frame, uint8_t command, uint8_t current, uint8_t autocontinue, float param1, float param2, float param3, float param4, float x, float y, float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - _mav_put_uint8_t(buf, 4, frame); - _mav_put_uint8_t(buf, 5, command); - _mav_put_uint8_t(buf, 6, current); - _mav_put_uint8_t(buf, 7, autocontinue); - _mav_put_float(buf, 8, param1); - _mav_put_float(buf, 12, param2); - _mav_put_float(buf, 16, param3); - _mav_put_float(buf, 20, param4); - _mav_put_float(buf, 24, x); - _mav_put_float(buf, 28, y); - _mav_put_float(buf, 32, z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT, buf, 36); -#else - mavlink_waypoint_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - packet.frame = frame; - packet.command = command; - packet.current = current; - packet.autocontinue = autocontinue; - packet.param1 = param1; - packet.param2 = param2; - packet.param3 = param3; - packet.param4 = param4; - packet.x = x; - packet.y = y; - packet.z = z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT, (const char *)&packet, 36); -#endif -} - -#endif - -// MESSAGE WAYPOINT UNPACKING - - -/** - * @brief Get field target_system from waypoint message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field seq from waypoint message - * - * @return Sequence - */ -static inline uint16_t mavlink_msg_waypoint_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field frame from waypoint message - * - * @return The coordinate system of the waypoint. see MAV_FRAME in mavlink_types.h - */ -static inline uint8_t mavlink_msg_waypoint_get_frame(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field command from waypoint message - * - * @return The scheduled action for the waypoint. see MAV_COMMAND in common.xml MAVLink specs - */ -static inline uint8_t mavlink_msg_waypoint_get_command(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field current from waypoint message - * - * @return false:0, true:1 - */ -static inline uint8_t mavlink_msg_waypoint_get_current(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field autocontinue from waypoint message - * - * @return autocontinue to next wp - */ -static inline uint8_t mavlink_msg_waypoint_get_autocontinue(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 7); -} - -/** - * @brief Get field param1 from waypoint message - * - * @return PARAM1 / For NAV command waypoints: Radius in which the waypoint is accepted as reached, in meters - */ -static inline float mavlink_msg_waypoint_get_param1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field param2 from waypoint message - * - * @return PARAM2 / For NAV command waypoints: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds - */ -static inline float mavlink_msg_waypoint_get_param2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field param3 from waypoint message - * - * @return PARAM3 / For LOITER command waypoints: Orbit to circle around the waypoint, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. - */ -static inline float mavlink_msg_waypoint_get_param3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field param4 from waypoint message - * - * @return PARAM4 / For NAV and LOITER command waypoints: Yaw orientation in degrees, [0..360] 0 = NORTH - */ -static inline float mavlink_msg_waypoint_get_param4(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field x from waypoint message - * - * @return PARAM5 / local: x position, global: latitude - */ -static inline float mavlink_msg_waypoint_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field y from waypoint message - * - * @return PARAM6 / y position: global: longitude - */ -static inline float mavlink_msg_waypoint_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Get field z from waypoint message - * - * @return PARAM7 / z position: global: altitude - */ -static inline float mavlink_msg_waypoint_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 32); -} - -/** - * @brief Decode a waypoint message into a struct - * - * @param msg The message to decode - * @param waypoint C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_decode(const mavlink_message_t* msg, mavlink_waypoint_t* waypoint) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint->target_system = mavlink_msg_waypoint_get_target_system(msg); - waypoint->target_component = mavlink_msg_waypoint_get_target_component(msg); - waypoint->seq = mavlink_msg_waypoint_get_seq(msg); - waypoint->frame = mavlink_msg_waypoint_get_frame(msg); - waypoint->command = mavlink_msg_waypoint_get_command(msg); - waypoint->current = mavlink_msg_waypoint_get_current(msg); - waypoint->autocontinue = mavlink_msg_waypoint_get_autocontinue(msg); - waypoint->param1 = mavlink_msg_waypoint_get_param1(msg); - waypoint->param2 = mavlink_msg_waypoint_get_param2(msg); - waypoint->param3 = mavlink_msg_waypoint_get_param3(msg); - waypoint->param4 = mavlink_msg_waypoint_get_param4(msg); - waypoint->x = mavlink_msg_waypoint_get_x(msg); - waypoint->y = mavlink_msg_waypoint_get_y(msg); - waypoint->z = mavlink_msg_waypoint_get_z(msg); -#else - memcpy(waypoint, _MAV_PAYLOAD(msg), 36); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_ack.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_ack.h deleted file mode 100644 index ddba2adf4c..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_ack.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE WAYPOINT_ACK PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_ACK 47 - -typedef struct __mavlink_waypoint_ack_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint8_t type; ///< 0: OK, 1: Error -} mavlink_waypoint_ack_t; - -#define MAVLINK_MSG_ID_WAYPOINT_ACK_LEN 3 -#define MAVLINK_MSG_ID_47_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_ACK { \ - "WAYPOINT_ACK", \ - 3, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_ack_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_ack_t, target_component) }, \ - { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_waypoint_ack_t, type) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_ack message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param type 0: OK, 1: Error - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_ack_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint8_t type) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, type); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_waypoint_ack_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.type = type; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_ACK; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a waypoint_ack message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param type 0: OK, 1: Error - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_ack_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint8_t type) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, type); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_waypoint_ack_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.type = type; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_ACK; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a waypoint_ack struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_ack C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_ack_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_ack_t* waypoint_ack) -{ - return mavlink_msg_waypoint_ack_pack(system_id, component_id, msg, waypoint_ack->target_system, waypoint_ack->target_component, waypoint_ack->type); -} - -/** - * @brief Send a waypoint_ack message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param type 0: OK, 1: Error - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_ack_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint8_t type) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint8_t(buf, 2, type); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_ACK, buf, 3); -#else - mavlink_waypoint_ack_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.type = type; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_ACK, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE WAYPOINT_ACK UNPACKING - - -/** - * @brief Get field target_system from waypoint_ack message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_ack_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint_ack message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_ack_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field type from waypoint_ack message - * - * @return 0: OK, 1: Error - */ -static inline uint8_t mavlink_msg_waypoint_ack_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a waypoint_ack message into a struct - * - * @param msg The message to decode - * @param waypoint_ack C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_ack_decode(const mavlink_message_t* msg, mavlink_waypoint_ack_t* waypoint_ack) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_ack->target_system = mavlink_msg_waypoint_ack_get_target_system(msg); - waypoint_ack->target_component = mavlink_msg_waypoint_ack_get_target_component(msg); - waypoint_ack->type = mavlink_msg_waypoint_ack_get_type(msg); -#else - memcpy(waypoint_ack, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_clear_all.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_clear_all.h deleted file mode 100644 index 8eab44b267..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_clear_all.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE WAYPOINT_CLEAR_ALL PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL 45 - -typedef struct __mavlink_waypoint_clear_all_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID -} mavlink_waypoint_clear_all_t; - -#define MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL_LEN 2 -#define MAVLINK_MSG_ID_45_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_CLEAR_ALL { \ - "WAYPOINT_CLEAR_ALL", \ - 2, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_clear_all_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_clear_all_t, target_component) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_clear_all message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_clear_all_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_clear_all_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a waypoint_clear_all message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_clear_all_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_clear_all_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a waypoint_clear_all struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_clear_all C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_clear_all_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_clear_all_t* waypoint_clear_all) -{ - return mavlink_msg_waypoint_clear_all_pack(system_id, component_id, msg, waypoint_clear_all->target_system, waypoint_clear_all->target_component); -} - -/** - * @brief Send a waypoint_clear_all message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_clear_all_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL, buf, 2); -#else - mavlink_waypoint_clear_all_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE WAYPOINT_CLEAR_ALL UNPACKING - - -/** - * @brief Get field target_system from waypoint_clear_all message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_clear_all_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint_clear_all message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_clear_all_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Decode a waypoint_clear_all message into a struct - * - * @param msg The message to decode - * @param waypoint_clear_all C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_clear_all_decode(const mavlink_message_t* msg, mavlink_waypoint_clear_all_t* waypoint_clear_all) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_clear_all->target_system = mavlink_msg_waypoint_clear_all_get_target_system(msg); - waypoint_clear_all->target_component = mavlink_msg_waypoint_clear_all_get_target_component(msg); -#else - memcpy(waypoint_clear_all, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_count.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_count.h deleted file mode 100644 index af1dd382b6..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_count.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE WAYPOINT_COUNT PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_COUNT 44 - -typedef struct __mavlink_waypoint_count_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint16_t count; ///< Number of Waypoints in the Sequence -} mavlink_waypoint_count_t; - -#define MAVLINK_MSG_ID_WAYPOINT_COUNT_LEN 4 -#define MAVLINK_MSG_ID_44_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_COUNT { \ - "WAYPOINT_COUNT", \ - 3, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_count_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_count_t, target_component) }, \ - { "count", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_waypoint_count_t, count) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_count message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param count Number of Waypoints in the Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_count_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint16_t count) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, count); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_waypoint_count_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.count = count; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_COUNT; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a waypoint_count message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param count Number of Waypoints in the Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_count_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint16_t count) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, count); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_waypoint_count_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.count = count; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_COUNT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a waypoint_count struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_count C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_count_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_count_t* waypoint_count) -{ - return mavlink_msg_waypoint_count_pack(system_id, component_id, msg, waypoint_count->target_system, waypoint_count->target_component, waypoint_count->count); -} - -/** - * @brief Send a waypoint_count message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param count Number of Waypoints in the Sequence - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_count_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t count) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, count); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_COUNT, buf, 4); -#else - mavlink_waypoint_count_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.count = count; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_COUNT, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE WAYPOINT_COUNT UNPACKING - - -/** - * @brief Get field target_system from waypoint_count message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_count_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint_count message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_count_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field count from waypoint_count message - * - * @return Number of Waypoints in the Sequence - */ -static inline uint16_t mavlink_msg_waypoint_count_get_count(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a waypoint_count message into a struct - * - * @param msg The message to decode - * @param waypoint_count C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_count_decode(const mavlink_message_t* msg, mavlink_waypoint_count_t* waypoint_count) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_count->target_system = mavlink_msg_waypoint_count_get_target_system(msg); - waypoint_count->target_component = mavlink_msg_waypoint_count_get_target_component(msg); - waypoint_count->count = mavlink_msg_waypoint_count_get_count(msg); -#else - memcpy(waypoint_count, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_current.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_current.h deleted file mode 100644 index a7e4557d6e..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_current.h +++ /dev/null @@ -1,144 +0,0 @@ -// MESSAGE WAYPOINT_CURRENT PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_CURRENT 42 - -typedef struct __mavlink_waypoint_current_t -{ - uint16_t seq; ///< Sequence -} mavlink_waypoint_current_t; - -#define MAVLINK_MSG_ID_WAYPOINT_CURRENT_LEN 2 -#define MAVLINK_MSG_ID_42_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_CURRENT { \ - "WAYPOINT_CURRENT", \ - 1, \ - { { "seq", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_waypoint_current_t, seq) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_current message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_current_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint16_t(buf, 0, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_current_t packet; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_CURRENT; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a waypoint_current message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_current_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint16_t(buf, 0, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_current_t packet; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_CURRENT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a waypoint_current struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_current C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_current_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_current_t* waypoint_current) -{ - return mavlink_msg_waypoint_current_pack(system_id, component_id, msg, waypoint_current->seq); -} - -/** - * @brief Send a waypoint_current message - * @param chan MAVLink channel to send the message - * - * @param seq Sequence - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_current_send(mavlink_channel_t chan, uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint16_t(buf, 0, seq); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_CURRENT, buf, 2); -#else - mavlink_waypoint_current_t packet; - packet.seq = seq; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_CURRENT, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE WAYPOINT_CURRENT UNPACKING - - -/** - * @brief Get field seq from waypoint_current message - * - * @return Sequence - */ -static inline uint16_t mavlink_msg_waypoint_current_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Decode a waypoint_current message into a struct - * - * @param msg The message to decode - * @param waypoint_current C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_current_decode(const mavlink_message_t* msg, mavlink_waypoint_current_t* waypoint_current) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_current->seq = mavlink_msg_waypoint_current_get_seq(msg); -#else - memcpy(waypoint_current, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_reached.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_reached.h deleted file mode 100644 index d28dce1494..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_reached.h +++ /dev/null @@ -1,144 +0,0 @@ -// MESSAGE WAYPOINT_REACHED PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_REACHED 46 - -typedef struct __mavlink_waypoint_reached_t -{ - uint16_t seq; ///< Sequence -} mavlink_waypoint_reached_t; - -#define MAVLINK_MSG_ID_WAYPOINT_REACHED_LEN 2 -#define MAVLINK_MSG_ID_46_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_REACHED { \ - "WAYPOINT_REACHED", \ - 1, \ - { { "seq", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_waypoint_reached_t, seq) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_reached message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_reached_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint16_t(buf, 0, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_reached_t packet; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_REACHED; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a waypoint_reached message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_reached_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint16_t(buf, 0, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_reached_t packet; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_REACHED; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a waypoint_reached struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_reached C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_reached_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_reached_t* waypoint_reached) -{ - return mavlink_msg_waypoint_reached_pack(system_id, component_id, msg, waypoint_reached->seq); -} - -/** - * @brief Send a waypoint_reached message - * @param chan MAVLink channel to send the message - * - * @param seq Sequence - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_reached_send(mavlink_channel_t chan, uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint16_t(buf, 0, seq); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_REACHED, buf, 2); -#else - mavlink_waypoint_reached_t packet; - packet.seq = seq; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_REACHED, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE WAYPOINT_REACHED UNPACKING - - -/** - * @brief Get field seq from waypoint_reached message - * - * @return Sequence - */ -static inline uint16_t mavlink_msg_waypoint_reached_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Decode a waypoint_reached message into a struct - * - * @param msg The message to decode - * @param waypoint_reached C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_reached_decode(const mavlink_message_t* msg, mavlink_waypoint_reached_t* waypoint_reached) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_reached->seq = mavlink_msg_waypoint_reached_get_seq(msg); -#else - memcpy(waypoint_reached, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_request.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_request.h deleted file mode 100644 index 38167c0806..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_request.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE WAYPOINT_REQUEST PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_REQUEST 40 - -typedef struct __mavlink_waypoint_request_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint16_t seq; ///< Sequence -} mavlink_waypoint_request_t; - -#define MAVLINK_MSG_ID_WAYPOINT_REQUEST_LEN 4 -#define MAVLINK_MSG_ID_40_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST { \ - "WAYPOINT_REQUEST", \ - 3, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_request_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_request_t, target_component) }, \ - { "seq", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_waypoint_request_t, seq) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_request message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_request_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_waypoint_request_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_REQUEST; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a waypoint_request message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_request_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_waypoint_request_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_REQUEST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a waypoint_request struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_request C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_request_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_request_t* waypoint_request) -{ - return mavlink_msg_waypoint_request_pack(system_id, component_id, msg, waypoint_request->target_system, waypoint_request->target_component, waypoint_request->seq); -} - -/** - * @brief Send a waypoint_request message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_request_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_REQUEST, buf, 4); -#else - mavlink_waypoint_request_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_REQUEST, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE WAYPOINT_REQUEST UNPACKING - - -/** - * @brief Get field target_system from waypoint_request message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_request_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint_request message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_request_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field seq from waypoint_request message - * - * @return Sequence - */ -static inline uint16_t mavlink_msg_waypoint_request_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a waypoint_request message into a struct - * - * @param msg The message to decode - * @param waypoint_request C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_request_decode(const mavlink_message_t* msg, mavlink_waypoint_request_t* waypoint_request) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_request->target_system = mavlink_msg_waypoint_request_get_target_system(msg); - waypoint_request->target_component = mavlink_msg_waypoint_request_get_target_component(msg); - waypoint_request->seq = mavlink_msg_waypoint_request_get_seq(msg); -#else - memcpy(waypoint_request, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_request_list.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_request_list.h deleted file mode 100644 index ba21fbc82d..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_request_list.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE WAYPOINT_REQUEST_LIST PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST 43 - -typedef struct __mavlink_waypoint_request_list_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID -} mavlink_waypoint_request_list_t; - -#define MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST_LEN 2 -#define MAVLINK_MSG_ID_43_LEN 2 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST_LIST { \ - "WAYPOINT_REQUEST_LIST", \ - 2, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_request_list_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_request_list_t, target_component) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_request_list message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_request_list_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_request_list_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST; - return mavlink_finalize_message(msg, system_id, component_id, 2); -} - -/** - * @brief Pack a waypoint_request_list message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_request_list_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 2); -#else - mavlink_waypoint_request_list_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 2); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 2); -} - -/** - * @brief Encode a waypoint_request_list struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_request_list C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_request_list_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_request_list_t* waypoint_request_list) -{ - return mavlink_msg_waypoint_request_list_pack(system_id, component_id, msg, waypoint_request_list->target_system, waypoint_request_list->target_component); -} - -/** - * @brief Send a waypoint_request_list message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_request_list_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[2]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST, buf, 2); -#else - mavlink_waypoint_request_list_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST, (const char *)&packet, 2); -#endif -} - -#endif - -// MESSAGE WAYPOINT_REQUEST_LIST UNPACKING - - -/** - * @brief Get field target_system from waypoint_request_list message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_request_list_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint_request_list message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_request_list_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Decode a waypoint_request_list message into a struct - * - * @param msg The message to decode - * @param waypoint_request_list C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_request_list_decode(const mavlink_message_t* msg, mavlink_waypoint_request_list_t* waypoint_request_list) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_request_list->target_system = mavlink_msg_waypoint_request_list_get_target_system(msg); - waypoint_request_list->target_component = mavlink_msg_waypoint_request_list_get_target_component(msg); -#else - memcpy(waypoint_request_list, _MAV_PAYLOAD(msg), 2); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_set_current.h b/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_set_current.h deleted file mode 100644 index f1ba68b456..0000000000 --- a/mavlink/include/mavlink/v0.9/common/mavlink_msg_waypoint_set_current.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE WAYPOINT_SET_CURRENT PACKING - -#define MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT 41 - -typedef struct __mavlink_waypoint_set_current_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint16_t seq; ///< Sequence -} mavlink_waypoint_set_current_t; - -#define MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT_LEN 4 -#define MAVLINK_MSG_ID_41_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_WAYPOINT_SET_CURRENT { \ - "WAYPOINT_SET_CURRENT", \ - 3, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_waypoint_set_current_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_waypoint_set_current_t, target_component) }, \ - { "seq", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_waypoint_set_current_t, seq) }, \ - } \ -} - - -/** - * @brief Pack a waypoint_set_current message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_set_current_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_waypoint_set_current_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a waypoint_set_current message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_waypoint_set_current_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_waypoint_set_current_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a waypoint_set_current struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param waypoint_set_current C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_waypoint_set_current_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_waypoint_set_current_t* waypoint_set_current) -{ - return mavlink_msg_waypoint_set_current_pack(system_id, component_id, msg, waypoint_set_current->target_system, waypoint_set_current->target_component, waypoint_set_current->seq); -} - -/** - * @brief Send a waypoint_set_current message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param seq Sequence - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_waypoint_set_current_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t seq) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, seq); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT, buf, 4); -#else - mavlink_waypoint_set_current_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.seq = seq; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE WAYPOINT_SET_CURRENT UNPACKING - - -/** - * @brief Get field target_system from waypoint_set_current message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_waypoint_set_current_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from waypoint_set_current message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_waypoint_set_current_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field seq from waypoint_set_current message - * - * @return Sequence - */ -static inline uint16_t mavlink_msg_waypoint_set_current_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a waypoint_set_current message into a struct - * - * @param msg The message to decode - * @param waypoint_set_current C-struct to decode the message contents into - */ -static inline void mavlink_msg_waypoint_set_current_decode(const mavlink_message_t* msg, mavlink_waypoint_set_current_t* waypoint_set_current) -{ -#if MAVLINK_NEED_BYTE_SWAP - waypoint_set_current->target_system = mavlink_msg_waypoint_set_current_get_target_system(msg); - waypoint_set_current->target_component = mavlink_msg_waypoint_set_current_get_target_component(msg); - waypoint_set_current->seq = mavlink_msg_waypoint_set_current_get_seq(msg); -#else - memcpy(waypoint_set_current, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/common/testsuite.h b/mavlink/include/mavlink/v0.9/common/testsuite.h deleted file mode 100644 index b3a94e96ea..0000000000 --- a/mavlink/include/mavlink/v0.9/common/testsuite.h +++ /dev/null @@ -1,3700 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from common.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef COMMON_TESTSUITE_H -#define COMMON_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL - -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - - mavlink_test_common(system_id, component_id, last_msg); -} -#endif - - - - -static void mavlink_test_heartbeat(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_heartbeat_t packet_in = { - 5, - 72, - 2, - }; - mavlink_heartbeat_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.type = packet_in.type; - packet1.autopilot = packet_in.autopilot; - packet1.mavlink_version = packet_in.mavlink_version; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_pack(system_id, component_id, &msg , packet1.type , packet1.autopilot ); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.type , packet1.autopilot ); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imagic = MAVLINK_STX; - msg->len = length; - msg->sysid = system_id; - msg->compid = component_id; - // One sequence number per component - msg->seq = mavlink_get_channel_status(chan)->current_tx_seq; - mavlink_get_channel_status(chan)->current_tx_seq = mavlink_get_channel_status(chan)->current_tx_seq+1; - checksum = crc_calculate((uint8_t*)&msg->len, length + MAVLINK_CORE_HEADER_LEN); -#if MAVLINK_CRC_EXTRA - crc_accumulate(crc_extra, &checksum); -#endif - mavlink_ck_a(msg) = (uint8_t)(checksum & 0xFF); - mavlink_ck_b(msg) = (uint8_t)(checksum >> 8); - - return length + MAVLINK_NUM_NON_PAYLOAD_BYTES; -} - - -/** - * @brief Finalize a MAVLink message with MAVLINK_COMM_0 as default channel - */ -#if MAVLINK_CRC_EXTRA -MAVLINK_HELPER uint16_t mavlink_finalize_message(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, - uint8_t length, uint8_t crc_extra) -{ - return mavlink_finalize_message_chan(msg, system_id, component_id, MAVLINK_COMM_0, length, crc_extra); -} -#else -MAVLINK_HELPER uint16_t mavlink_finalize_message(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, - uint8_t length) -{ - return mavlink_finalize_message_chan(msg, system_id, component_id, MAVLINK_COMM_0, length); -} -#endif - -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS -MAVLINK_HELPER void _mavlink_send_uart(mavlink_channel_t chan, const char *buf, uint16_t len); - -/** - * @brief Finalize a MAVLink message with channel assignment and send - */ -#if MAVLINK_CRC_EXTRA -MAVLINK_HELPER void _mav_finalize_message_chan_send(mavlink_channel_t chan, uint8_t msgid, const char *packet, - uint8_t length, uint8_t crc_extra) -#else -MAVLINK_HELPER void _mav_finalize_message_chan_send(mavlink_channel_t chan, uint8_t msgid, const char *packet, uint8_t length) -#endif -{ - uint16_t checksum; - uint8_t buf[MAVLINK_NUM_HEADER_BYTES]; - uint8_t ck[2]; - mavlink_status_t *status = mavlink_get_channel_status(chan); - buf[0] = MAVLINK_STX; - buf[1] = length; - buf[2] = status->current_tx_seq; - buf[3] = mavlink_system.sysid; - buf[4] = mavlink_system.compid; - buf[5] = msgid; - status->current_tx_seq++; - checksum = crc_calculate((uint8_t*)&buf[1], MAVLINK_CORE_HEADER_LEN); - crc_accumulate_buffer(&checksum, packet, length); -#if MAVLINK_CRC_EXTRA - crc_accumulate(crc_extra, &checksum); -#endif - ck[0] = (uint8_t)(checksum & 0xFF); - ck[1] = (uint8_t)(checksum >> 8); - - MAVLINK_START_UART_SEND(chan, MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)length); - _mavlink_send_uart(chan, (const char *)buf, MAVLINK_NUM_HEADER_BYTES); - _mavlink_send_uart(chan, packet, length); - _mavlink_send_uart(chan, (const char *)ck, 2); - MAVLINK_END_UART_SEND(chan, MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)length); -} -#endif // MAVLINK_USE_CONVENIENCE_FUNCTIONS - -/** - * @brief Pack a message to send it over a serial byte stream - */ -MAVLINK_HELPER uint16_t mavlink_msg_to_send_buffer(uint8_t *buffer, const mavlink_message_t *msg) -{ - memcpy(buffer, (uint8_t *)&msg->magic, MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)msg->len); - return MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)msg->len; -} - -union __mavlink_bitfield { - uint8_t uint8; - int8_t int8; - uint16_t uint16; - int16_t int16; - uint32_t uint32; - int32_t int32; -}; - - -MAVLINK_HELPER void mavlink_start_checksum(mavlink_message_t* msg) -{ - crc_init(&msg->checksum); -} - -MAVLINK_HELPER void mavlink_update_checksum(mavlink_message_t* msg, uint8_t c) -{ - crc_accumulate(c, &msg->checksum); -} - -/** - * This is a convenience function which handles the complete MAVLink parsing. - * the function will parse one byte at a time and return the complete packet once - * it could be successfully decoded. Checksum and other failures will be silently - * ignored. - * - * @param chan ID of the current channel. This allows to parse different channels with this function. - * a channel is not a physical message channel like a serial port, but a logic partition of - * the communication streams in this case. COMM_NB is the limit for the number of channels - * on MCU (e.g. ARM7), while COMM_NB_HIGH is the limit for the number of channels in Linux/Windows - * @param c The char to barse - * - * @param returnMsg NULL if no message could be decoded, the message data else - * @return 0 if no message could be decoded, 1 else - * - * A typical use scenario of this function call is: - * - * @code - * #include // For fixed-width uint8_t type - * - * mavlink_message_t msg; - * int chan = 0; - * - * - * while(serial.bytesAvailable > 0) - * { - * uint8_t byte = serial.getNextByte(); - * if (mavlink_parse_char(chan, byte, &msg)) - * { - * printf("Received message with ID %d, sequence: %d from component %d of system %d", msg.msgid, msg.seq, msg.compid, msg.sysid); - * } - * } - * - * - * @endcode - */ -MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_message_t* r_message, mavlink_status_t* r_mavlink_status) -{ - static mavlink_message_t m_mavlink_message[MAVLINK_COMM_NUM_BUFFERS]; - - /* - default message crc function. You can override this per-system to - put this data in a different memory segment - */ -#if MAVLINK_CRC_EXTRA -#ifndef MAVLINK_MESSAGE_CRC - static const uint8_t mavlink_message_crcs[256] = MAVLINK_MESSAGE_CRCS; -#define MAVLINK_MESSAGE_CRC(msgid) mavlink_message_crcs[msgid] -#endif -#endif - - mavlink_message_t* rxmsg = &m_mavlink_message[chan]; ///< The currently decoded message - mavlink_status_t* status = mavlink_get_channel_status(chan); ///< The current decode status - int bufferIndex = 0; - - status->msg_received = 0; - - switch (status->parse_state) - { - case MAVLINK_PARSE_STATE_UNINIT: - case MAVLINK_PARSE_STATE_IDLE: - if (c == MAVLINK_STX) - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_STX; - rxmsg->len = 0; - mavlink_start_checksum(rxmsg); - } - break; - - case MAVLINK_PARSE_STATE_GOT_STX: - if (status->msg_received - /* Support shorter buffers than the - default maximum packet size */ -#if (MAVLINK_MAX_PAYLOAD_LEN < 255) - || c > MAVLINK_MAX_PAYLOAD_LEN -#endif - ) - { - status->buffer_overrun++; - status->parse_error++; - status->msg_received = 0; - status->parse_state = MAVLINK_PARSE_STATE_IDLE; - } - else - { - // NOT counting STX, LENGTH, SEQ, SYSID, COMPID, MSGID, CRC1 and CRC2 - rxmsg->len = c; - status->packet_idx = 0; - mavlink_update_checksum(rxmsg, c); - status->parse_state = MAVLINK_PARSE_STATE_GOT_LENGTH; - } - break; - - case MAVLINK_PARSE_STATE_GOT_LENGTH: - rxmsg->seq = c; - mavlink_update_checksum(rxmsg, c); - status->parse_state = MAVLINK_PARSE_STATE_GOT_SEQ; - break; - - case MAVLINK_PARSE_STATE_GOT_SEQ: - rxmsg->sysid = c; - mavlink_update_checksum(rxmsg, c); - status->parse_state = MAVLINK_PARSE_STATE_GOT_SYSID; - break; - - case MAVLINK_PARSE_STATE_GOT_SYSID: - rxmsg->compid = c; - mavlink_update_checksum(rxmsg, c); - status->parse_state = MAVLINK_PARSE_STATE_GOT_COMPID; - break; - - case MAVLINK_PARSE_STATE_GOT_COMPID: - rxmsg->msgid = c; - mavlink_update_checksum(rxmsg, c); - if (rxmsg->len == 0) - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_PAYLOAD; - } - else - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_MSGID; - } - break; - - case MAVLINK_PARSE_STATE_GOT_MSGID: - _MAV_PAYLOAD(rxmsg)[status->packet_idx++] = (char)c; - mavlink_update_checksum(rxmsg, c); - if (status->packet_idx == rxmsg->len) - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_PAYLOAD; - } - break; - - case MAVLINK_PARSE_STATE_GOT_PAYLOAD: -#if MAVLINK_CRC_EXTRA - mavlink_update_checksum(rxmsg, MAVLINK_MESSAGE_CRC(rxmsg->msgid)); -#endif - if (c != (rxmsg->checksum & 0xFF)) { - // Check first checksum byte - status->parse_error++; - status->msg_received = 0; - status->parse_state = MAVLINK_PARSE_STATE_IDLE; - if (c == MAVLINK_STX) - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_STX; - rxmsg->len = 0; - mavlink_start_checksum(rxmsg); - } - } - else - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_CRC1; - } - break; - - case MAVLINK_PARSE_STATE_GOT_CRC1: - if (c != (rxmsg->checksum >> 8)) { - // Check second checksum byte - status->parse_error++; - status->msg_received = 0; - status->parse_state = MAVLINK_PARSE_STATE_IDLE; - if (c == MAVLINK_STX) - { - status->parse_state = MAVLINK_PARSE_STATE_GOT_STX; - rxmsg->len = 0; - mavlink_start_checksum(rxmsg); - } - } - else - { - // Successfully got message - status->msg_received = 1; - status->parse_state = MAVLINK_PARSE_STATE_IDLE; - memcpy(r_message, rxmsg, sizeof(mavlink_message_t)); - } - break; - } - - bufferIndex++; - // If a message has been sucessfully decoded, check index - if (status->msg_received == 1) - { - //while(status->current_seq != rxmsg->seq) - //{ - // status->packet_rx_drop_count++; - // status->current_seq++; - //} - status->current_rx_seq = rxmsg->seq; - // Initial condition: If no packet has been received so far, drop count is undefined - if (status->packet_rx_success_count == 0) status->packet_rx_drop_count = 0; - // Count this packet as received - status->packet_rx_success_count++; - } - - r_mavlink_status->current_rx_seq = status->current_rx_seq+1; - r_mavlink_status->packet_rx_success_count = status->packet_rx_success_count; - r_mavlink_status->packet_rx_drop_count = status->parse_error; - status->parse_error = 0; - return status->msg_received; -} - -/** - * @brief Put a bitfield of length 1-32 bit into the buffer - * - * @param b the value to add, will be encoded in the bitfield - * @param bits number of bits to use to encode b, e.g. 1 for boolean, 2, 3, etc. - * @param packet_index the position in the packet (the index of the first byte to use) - * @param bit_index the position in the byte (the index of the first bit to use) - * @param buffer packet buffer to write into - * @return new position of the last used byte in the buffer - */ -MAVLINK_HELPER uint8_t put_bitfield_n_by_index(int32_t b, uint8_t bits, uint8_t packet_index, uint8_t bit_index, uint8_t* r_bit_index, uint8_t* buffer) -{ - uint16_t bits_remain = bits; - // Transform number into network order - int32_t v; - uint8_t i_bit_index, i_byte_index, curr_bits_n; -#if MAVLINK_NEED_BYTE_SWAP - union { - int32_t i; - uint8_t b[4]; - } bin, bout; - bin.i = b; - bout.b[0] = bin.b[3]; - bout.b[1] = bin.b[2]; - bout.b[2] = bin.b[1]; - bout.b[3] = bin.b[0]; - v = bout.i; -#else - v = b; -#endif - - // buffer in - // 01100000 01000000 00000000 11110001 - // buffer out - // 11110001 00000000 01000000 01100000 - - // Existing partly filled byte (four free slots) - // 0111xxxx - - // Mask n free bits - // 00001111 = 2^0 + 2^1 + 2^2 + 2^3 = 2^n - 1 - // = ((uint32_t)(1 << n)) - 1; // = 2^n - 1 - - // Shift n bits into the right position - // out = in >> n; - - // Mask and shift bytes - i_bit_index = bit_index; - i_byte_index = packet_index; - if (bit_index > 0) - { - // If bits were available at start, they were available - // in the byte before the current index - i_byte_index--; - } - - // While bits have not been packed yet - while (bits_remain > 0) - { - // Bits still have to be packed - // there can be more than 8 bits, so - // we might have to pack them into more than one byte - - // First pack everything we can into the current 'open' byte - //curr_bits_n = bits_remain << 3; // Equals bits_remain mod 8 - //FIXME - if (bits_remain <= (uint8_t)(8 - i_bit_index)) - { - // Enough space - curr_bits_n = (uint8_t)bits_remain; - } - else - { - curr_bits_n = (8 - i_bit_index); - } - - // Pack these n bits into the current byte - // Mask out whatever was at that position with ones (xxx11111) - buffer[i_byte_index] &= (0xFF >> (8 - curr_bits_n)); - // Put content to this position, by masking out the non-used part - buffer[i_byte_index] |= ((0x00 << curr_bits_n) & v); - - // Increment the bit index - i_bit_index += curr_bits_n; - - // Now proceed to the next byte, if necessary - bits_remain -= curr_bits_n; - if (bits_remain > 0) - { - // Offer another 8 bits / one byte - i_byte_index++; - i_bit_index = 0; - } - } - - *r_bit_index = i_bit_index; - // If a partly filled byte is present, mark this as consumed - if (i_bit_index != 7) i_byte_index++; - return i_byte_index - packet_index; -} - -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -// To make MAVLink work on your MCU, define comm_send_ch() if you wish -// to send 1 byte at a time, or MAVLINK_SEND_UART_BYTES() to send a -// whole packet at a time - -/* - -#include "mavlink_types.h" - -void comm_send_ch(mavlink_channel_t chan, uint8_t ch) -{ - if (chan == MAVLINK_COMM_0) - { - uart0_transmit(ch); - } - if (chan == MAVLINK_COMM_1) - { - uart1_transmit(ch); - } -} - */ - -MAVLINK_HELPER void _mavlink_send_uart(mavlink_channel_t chan, const char *buf, uint16_t len) -{ -#ifdef MAVLINK_SEND_UART_BYTES - /* this is the more efficient approach, if the platform - defines it */ - MAVLINK_SEND_UART_BYTES(chan, (uint8_t *)buf, len); -#else - /* fallback to one byte at a time */ - uint16_t i; - for (i = 0; i < len; i++) { - comm_send_ch(chan, (uint8_t)buf[i]); - } -#endif -} -#endif // MAVLINK_USE_CONVENIENCE_FUNCTIONS - -#endif /* _MAVLINK_HELPERS_H_ */ diff --git a/mavlink/include/mavlink/v0.9/mavlink_types.h b/mavlink/include/mavlink/v0.9/mavlink_types.h deleted file mode 100644 index 630cb84b77..0000000000 --- a/mavlink/include/mavlink/v0.9/mavlink_types.h +++ /dev/null @@ -1,300 +0,0 @@ -#ifndef MAVLINK_TYPES_H_ -#define MAVLINK_TYPES_H_ - -#include "inttypes.h" - -enum MAV_CLASS -{ - MAV_CLASS_GENERIC = 0, ///< Generic autopilot, full support for everything - MAV_CLASS_PIXHAWK = 1, ///< PIXHAWK autopilot, http://pixhawk.ethz.ch - MAV_CLASS_SLUGS = 2, ///< SLUGS autopilot, http://slugsuav.soe.ucsc.edu - MAV_CLASS_ARDUPILOTMEGA = 3, ///< ArduPilotMega / ArduCopter, http://diydrones.com - MAV_CLASS_OPENPILOT = 4, ///< OpenPilot, http://openpilot.org - MAV_CLASS_GENERIC_MISSION_WAYPOINTS_ONLY = 5, ///< Generic autopilot only supporting simple waypoints - MAV_CLASS_GENERIC_MISSION_NAVIGATION_ONLY = 6, ///< Generic autopilot supporting waypoints and other simple navigation commands - MAV_CLASS_GENERIC_MISSION_FULL = 7, ///< Generic autopilot supporting the full mission command set - MAV_CLASS_NONE = 8, ///< No valid autopilot - MAV_CLASS_NB ///< Number of autopilot classes -}; - -enum MAV_ACTION -{ - MAV_ACTION_HOLD = 0, - MAV_ACTION_MOTORS_START = 1, - MAV_ACTION_LAUNCH = 2, - MAV_ACTION_RETURN = 3, - MAV_ACTION_EMCY_LAND = 4, - MAV_ACTION_EMCY_KILL = 5, - MAV_ACTION_CONFIRM_KILL = 6, - MAV_ACTION_CONTINUE = 7, - MAV_ACTION_MOTORS_STOP = 8, - MAV_ACTION_HALT = 9, - MAV_ACTION_SHUTDOWN = 10, - MAV_ACTION_REBOOT = 11, - MAV_ACTION_SET_MANUAL = 12, - MAV_ACTION_SET_AUTO = 13, - MAV_ACTION_STORAGE_READ = 14, - MAV_ACTION_STORAGE_WRITE = 15, - MAV_ACTION_CALIBRATE_RC = 16, - MAV_ACTION_CALIBRATE_GYRO = 17, - MAV_ACTION_CALIBRATE_MAG = 18, - MAV_ACTION_CALIBRATE_ACC = 19, - MAV_ACTION_CALIBRATE_PRESSURE = 20, - MAV_ACTION_REC_START = 21, - MAV_ACTION_REC_PAUSE = 22, - MAV_ACTION_REC_STOP = 23, - MAV_ACTION_TAKEOFF = 24, - MAV_ACTION_NAVIGATE = 25, - MAV_ACTION_LAND = 26, - MAV_ACTION_LOITER = 27, - MAV_ACTION_SET_ORIGIN = 28, - MAV_ACTION_RELAY_ON = 29, - MAV_ACTION_RELAY_OFF = 30, - MAV_ACTION_GET_IMAGE = 31, - MAV_ACTION_VIDEO_START = 32, - MAV_ACTION_VIDEO_STOP = 33, - MAV_ACTION_RESET_MAP = 34, - MAV_ACTION_RESET_PLAN = 35, - MAV_ACTION_DELAY_BEFORE_COMMAND = 36, - MAV_ACTION_ASCEND_AT_RATE = 37, - MAV_ACTION_CHANGE_MODE = 38, - MAV_ACTION_LOITER_MAX_TURNS = 39, - MAV_ACTION_LOITER_MAX_TIME = 40, - MAV_ACTION_START_HILSIM = 41, - MAV_ACTION_STOP_HILSIM = 42, - MAV_ACTION_NB ///< Number of MAV actions -}; - -enum MAV_MODE -{ - MAV_MODE_UNINIT = 0, ///< System is in undefined state - MAV_MODE_LOCKED = 1, ///< Motors are blocked, system is safe - MAV_MODE_MANUAL = 2, ///< System is allowed to be active, under manual (RC) control - MAV_MODE_GUIDED = 3, ///< System is allowed to be active, under autonomous control, manual setpoint - MAV_MODE_AUTO = 4, ///< System is allowed to be active, under autonomous control and navigation - MAV_MODE_TEST1 = 5, ///< Generic test mode, for custom use - MAV_MODE_TEST2 = 6, ///< Generic test mode, for custom use - MAV_MODE_TEST3 = 7, ///< Generic test mode, for custom use - MAV_MODE_READY = 8, ///< System is ready, motors are unblocked, but controllers are inactive - MAV_MODE_RC_TRAINING = 9 ///< System is blocked, only RC valued are read and reported back -}; - -enum MAV_STATE -{ - MAV_STATE_UNINIT = 0, - MAV_STATE_BOOT, - MAV_STATE_CALIBRATING, - MAV_STATE_STANDBY, - MAV_STATE_ACTIVE, - MAV_STATE_CRITICAL, - MAV_STATE_EMERGENCY, - MAV_STATE_HILSIM, - MAV_STATE_POWEROFF -}; - -enum MAV_NAV -{ - MAV_NAV_GROUNDED = 0, - MAV_NAV_LIFTOFF, - MAV_NAV_HOLD, - MAV_NAV_WAYPOINT, - MAV_NAV_VECTOR, - MAV_NAV_RETURNING, - MAV_NAV_LANDING, - MAV_NAV_LOST, - MAV_NAV_LOITER, - MAV_NAV_FREE_DRIFT -}; - -enum MAV_TYPE -{ - MAV_GENERIC = 0, - MAV_FIXED_WING = 1, - MAV_QUADROTOR = 2, - MAV_COAXIAL = 3, - MAV_HELICOPTER = 4, - MAV_GROUND = 5, - OCU = 6, - MAV_AIRSHIP = 7, - MAV_FREE_BALLOON = 8, - MAV_ROCKET = 9, - UGV_GROUND_ROVER = 10, - UGV_SURFACE_SHIP = 11 -}; - -enum MAV_AUTOPILOT_TYPE -{ - MAV_AUTOPILOT_GENERIC = 0, - MAV_AUTOPILOT_PIXHAWK = 1, - MAV_AUTOPILOT_SLUGS = 2, - MAV_AUTOPILOT_ARDUPILOTMEGA = 3, - MAV_AUTOPILOT_NONE = 4 -}; - -enum MAV_COMPONENT -{ - MAV_COMP_ID_GPS, - MAV_COMP_ID_WAYPOINTPLANNER, - MAV_COMP_ID_BLOBTRACKER, - MAV_COMP_ID_PATHPLANNER, - MAV_COMP_ID_AIRSLAM, - MAV_COMP_ID_MAPPER, - MAV_COMP_ID_CAMERA, - MAV_COMP_ID_RADIO = 68, - MAV_COMP_ID_IMU = 200, - MAV_COMP_ID_IMU_2 = 201, - MAV_COMP_ID_IMU_3 = 202, - MAV_COMP_ID_UDP_BRIDGE = 240, - MAV_COMP_ID_UART_BRIDGE = 241, - MAV_COMP_ID_SYSTEM_CONTROL = 250 -}; - -enum MAV_FRAME -{ - MAV_FRAME_GLOBAL = 0, - MAV_FRAME_LOCAL = 1, - MAV_FRAME_MISSION = 2, - MAV_FRAME_GLOBAL_RELATIVE_ALT = 3, - MAV_FRAME_LOCAL_ENU = 4 -}; - -enum MAVLINK_DATA_STREAM_TYPE -{ - MAVLINK_DATA_STREAM_IMG_JPEG, - MAVLINK_DATA_STREAM_IMG_BMP, - MAVLINK_DATA_STREAM_IMG_RAW8U, - MAVLINK_DATA_STREAM_IMG_RAW32U, - MAVLINK_DATA_STREAM_IMG_PGM, - MAVLINK_DATA_STREAM_IMG_PNG -}; - -#ifndef MAVLINK_MAX_PAYLOAD_LEN -// it is possible to override this, but be careful! -#define MAVLINK_MAX_PAYLOAD_LEN 255 ///< Maximum payload length -#endif - -#define MAVLINK_CORE_HEADER_LEN 5 ///< Length of core header (of the comm. layer): message length (1 byte) + message sequence (1 byte) + message system id (1 byte) + message component id (1 byte) + message type id (1 byte) -#define MAVLINK_NUM_HEADER_BYTES (MAVLINK_CORE_HEADER_LEN + 1) ///< Length of all header bytes, including core and checksum -#define MAVLINK_NUM_CHECKSUM_BYTES 2 -#define MAVLINK_NUM_NON_PAYLOAD_BYTES (MAVLINK_NUM_HEADER_BYTES + MAVLINK_NUM_CHECKSUM_BYTES) - -#define MAVLINK_MAX_PACKET_LEN (MAVLINK_MAX_PAYLOAD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) ///< Maximum packet length - -typedef struct param_union { - union { - float param_float; - int32_t param_int32; - uint32_t param_uint32; - }; - uint8_t type; -} mavlink_param_union_t; - -typedef struct __mavlink_system { - uint8_t sysid; ///< Used by the MAVLink message_xx_send() convenience function - uint8_t compid; ///< Used by the MAVLink message_xx_send() convenience function - uint8_t type; ///< Unused, can be used by user to store the system's type - uint8_t state; ///< Unused, can be used by user to store the system's state - uint8_t mode; ///< Unused, can be used by user to store the system's mode - uint8_t nav_mode; ///< Unused, can be used by user to store the system's navigation mode -} mavlink_system_t; - -typedef struct __mavlink_message { - uint16_t checksum; /// sent at end of packet - uint8_t magic; ///< protocol magic marker - uint8_t len; ///< Length of payload - uint8_t seq; ///< Sequence of packet - uint8_t sysid; ///< ID of message sender system/aircraft - uint8_t compid; ///< ID of the message sender component - uint8_t msgid; ///< ID of message in payload - uint64_t payload64[(MAVLINK_MAX_PAYLOAD_LEN+MAVLINK_NUM_CHECKSUM_BYTES+7)/8]; -} mavlink_message_t; - -typedef enum { - MAVLINK_TYPE_CHAR = 0, - MAVLINK_TYPE_UINT8_T = 1, - MAVLINK_TYPE_INT8_T = 2, - MAVLINK_TYPE_UINT16_T = 3, - MAVLINK_TYPE_INT16_T = 4, - MAVLINK_TYPE_UINT32_T = 5, - MAVLINK_TYPE_INT32_T = 6, - MAVLINK_TYPE_UINT64_T = 7, - MAVLINK_TYPE_INT64_T = 8, - MAVLINK_TYPE_FLOAT = 9, - MAVLINK_TYPE_DOUBLE = 10 -} mavlink_message_type_t; - -#define MAVLINK_MAX_FIELDS 64 - -typedef struct __mavlink_field_info { - const char *name; // name of this field - const char *print_format; // printing format hint, or NULL - mavlink_message_type_t type; // type of this field - unsigned array_length; // if non-zero, field is an array - unsigned wire_offset; // offset of each field in the payload - unsigned structure_offset; // offset in a C structure -} mavlink_field_info_t; - -// note that in this structure the order of fields is the order -// in the XML file, not necessary the wire order -typedef struct __mavlink_message_info { - const char *name; // name of the message - unsigned num_fields; // how many fields in this message - mavlink_field_info_t fields[MAVLINK_MAX_FIELDS]; // field information -} mavlink_message_info_t; - -#define _MAV_PAYLOAD(msg) ((char *)(&(msg)->payload64[0])) -#define _MAV_PAYLOAD_NON_CONST(msg) ((char *)(&((msg)->payload64[0]))) - -// checksum is immediately after the payload bytes -#define mavlink_ck_a(msg) *(msg->len + (uint8_t *)_MAV_PAYLOAD(msg)) -#define mavlink_ck_b(msg) *((msg->len+(uint16_t)1) + (uint8_t *)_MAV_PAYLOAD(msg)) - -typedef enum { - MAVLINK_COMM_0, - MAVLINK_COMM_1, - MAVLINK_COMM_2, - MAVLINK_COMM_3 -} mavlink_channel_t; - -/* - * applications can set MAVLINK_COMM_NUM_BUFFERS to the maximum number - * of buffers they will use. If more are used, then the result will be - * a stack overrun - */ -#ifndef MAVLINK_COMM_NUM_BUFFERS -#if (defined linux) | (defined __linux) | (defined __MACH__) | (defined _WIN32) -# define MAVLINK_COMM_NUM_BUFFERS 16 -#else -# define MAVLINK_COMM_NUM_BUFFERS 4 -#endif -#endif - -typedef enum { - MAVLINK_PARSE_STATE_UNINIT=0, - MAVLINK_PARSE_STATE_IDLE, - MAVLINK_PARSE_STATE_GOT_STX, - MAVLINK_PARSE_STATE_GOT_SEQ, - MAVLINK_PARSE_STATE_GOT_LENGTH, - MAVLINK_PARSE_STATE_GOT_SYSID, - MAVLINK_PARSE_STATE_GOT_COMPID, - MAVLINK_PARSE_STATE_GOT_MSGID, - MAVLINK_PARSE_STATE_GOT_PAYLOAD, - MAVLINK_PARSE_STATE_GOT_CRC1 -} mavlink_parse_state_t; ///< The state machine for the comm parser - -typedef struct __mavlink_status { - uint8_t msg_received; ///< Number of received messages - uint8_t buffer_overrun; ///< Number of buffer overruns - uint8_t parse_error; ///< Number of parse errors - mavlink_parse_state_t parse_state; ///< Parsing state machine - uint8_t packet_idx; ///< Index in current packet - uint8_t current_rx_seq; ///< Sequence number of last packet received - uint8_t current_tx_seq; ///< Sequence number of last packet sent - uint16_t packet_rx_success_count; ///< Received packets - uint16_t packet_rx_drop_count; ///< Number of packet drops -} mavlink_status_t; - -#define MAVLINK_BIG_ENDIAN 0 -#define MAVLINK_LITTLE_ENDIAN 1 - -#endif /* MAVLINK_TYPES_H_ */ diff --git a/mavlink/include/mavlink/v0.9/minimal/mavlink.h b/mavlink/include/mavlink/v0.9/minimal/mavlink.h deleted file mode 100644 index 3f1c8b4295..0000000000 --- a/mavlink/include/mavlink/v0.9/minimal/mavlink.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - * @brief MAVLink comm protocol built from minimal.xml - * @see http://pixhawk.ethz.ch/software/mavlink - */ -#ifndef MAVLINK_H -#define MAVLINK_H - -#ifndef MAVLINK_STX -#define MAVLINK_STX 85 -#endif - -#ifndef MAVLINK_ENDIAN -#define MAVLINK_ENDIAN MAVLINK_BIG_ENDIAN -#endif - -#ifndef MAVLINK_ALIGNED_FIELDS -#define MAVLINK_ALIGNED_FIELDS 0 -#endif - -#ifndef MAVLINK_CRC_EXTRA -#define MAVLINK_CRC_EXTRA 0 -#endif - -#include "version.h" -#include "minimal.h" - -#endif // MAVLINK_H diff --git a/mavlink/include/mavlink/v0.9/minimal/mavlink_msg_heartbeat.h b/mavlink/include/mavlink/v0.9/minimal/mavlink_msg_heartbeat.h deleted file mode 100644 index aad90d29f3..0000000000 --- a/mavlink/include/mavlink/v0.9/minimal/mavlink_msg_heartbeat.h +++ /dev/null @@ -1,185 +0,0 @@ -// MESSAGE HEARTBEAT PACKING - -#define MAVLINK_MSG_ID_HEARTBEAT 0 - -typedef struct __mavlink_heartbeat_t -{ - uint8_t type; ///< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - uint8_t autopilot; ///< Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - uint8_t mavlink_version; ///< MAVLink version -} mavlink_heartbeat_t; - -#define MAVLINK_MSG_ID_HEARTBEAT_LEN 3 -#define MAVLINK_MSG_ID_0_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_HEARTBEAT { \ - "HEARTBEAT", \ - 3, \ - { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_heartbeat_t, type) }, \ - { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_heartbeat_t, autopilot) }, \ - { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_heartbeat_t, mavlink_version) }, \ - } \ -} - - -/** - * @brief Pack a heartbeat message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, uint8_t autopilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, autopilot); - _mav_put_uint8_t(buf, 2, 2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_heartbeat_t packet; - packet.type = type; - packet.autopilot = autopilot; - packet.mavlink_version = 2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a heartbeat message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,uint8_t autopilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, autopilot); - _mav_put_uint8_t(buf, 2, 2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_heartbeat_t packet; - packet.type = type; - packet.autopilot = autopilot; - packet.mavlink_version = 2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a heartbeat struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param heartbeat C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat) -{ - return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot); -} - -/** - * @brief Send a heartbeat message - * @param chan MAVLink channel to send the message - * - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_heartbeat_send(mavlink_channel_t chan, uint8_t type, uint8_t autopilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, autopilot); - _mav_put_uint8_t(buf, 2, 2); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, 3); -#else - mavlink_heartbeat_t packet; - packet.type = type; - packet.autopilot = autopilot; - packet.mavlink_version = 2; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE HEARTBEAT UNPACKING - - -/** - * @brief Get field type from heartbeat message - * - * @return Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - */ -static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field autopilot from heartbeat message - * - * @return Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM - */ -static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field mavlink_version from heartbeat message - * - * @return MAVLink version - */ -static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a heartbeat message into a struct - * - * @param msg The message to decode - * @param heartbeat C-struct to decode the message contents into - */ -static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat) -{ -#if MAVLINK_NEED_BYTE_SWAP - heartbeat->type = mavlink_msg_heartbeat_get_type(msg); - heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg); - heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg); -#else - memcpy(heartbeat, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/minimal/minimal.h b/mavlink/include/mavlink/v0.9/minimal/minimal.h deleted file mode 100644 index 5979f806b8..0000000000 --- a/mavlink/include/mavlink/v0.9/minimal/minimal.h +++ /dev/null @@ -1,53 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from minimal.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef MINIMAL_H -#define MINIMAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_MINIMAL - - - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_heartbeat.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // MINIMAL_H diff --git a/mavlink/include/mavlink/v0.9/minimal/testsuite.h b/mavlink/include/mavlink/v0.9/minimal/testsuite.h deleted file mode 100644 index be1d5ed6dd..0000000000 --- a/mavlink/include/mavlink/v0.9/minimal/testsuite.h +++ /dev/null @@ -1,82 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from minimal.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef MINIMAL_TESTSUITE_H -#define MINIMAL_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL - -static void mavlink_test_minimal(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - - mavlink_test_minimal(system_id, component_id, last_msg); -} -#endif - - - - -static void mavlink_test_heartbeat(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_heartbeat_t packet_in = { - 5, - 72, - 2, - }; - mavlink_heartbeat_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.type = packet_in.type; - packet1.autopilot = packet_in.autopilot; - packet1.mavlink_version = packet_in.mavlink_version; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_pack(system_id, component_id, &msg , packet1.type , packet1.autopilot ); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.type , packet1.autopilot ); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imsgid = MAVLINK_MSG_ID_ATTITUDE_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 21); -} - -/** - * @brief Pack a attitude_control message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_attitude_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,float roll,float pitch,float yaw,float thrust,uint8_t roll_manual,uint8_t pitch_manual,uint8_t yaw_manual,uint8_t thrust_manual) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, roll); - _mav_put_float(buf, 5, pitch); - _mav_put_float(buf, 9, yaw); - _mav_put_float(buf, 13, thrust); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); -#else - mavlink_attitude_control_t packet; - packet.target = target; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); -#endif - - msg->msgid = MAVLINK_MSG_ID_ATTITUDE_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 21); -} - -/** - * @brief Encode a attitude_control struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param attitude_control C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_attitude_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_attitude_control_t* attitude_control) -{ - return mavlink_msg_attitude_control_pack(system_id, component_id, msg, attitude_control->target, attitude_control->roll, attitude_control->pitch, attitude_control->yaw, attitude_control->thrust, attitude_control->roll_manual, attitude_control->pitch_manual, attitude_control->yaw_manual, attitude_control->thrust_manual); -} - -/** - * @brief Send a attitude_control message - * @param chan MAVLink channel to send the message - * - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_attitude_control_send(mavlink_channel_t chan, uint8_t target, float roll, float pitch, float yaw, float thrust, uint8_t roll_manual, uint8_t pitch_manual, uint8_t yaw_manual, uint8_t thrust_manual) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, roll); - _mav_put_float(buf, 5, pitch); - _mav_put_float(buf, 9, yaw); - _mav_put_float(buf, 13, thrust); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_CONTROL, buf, 21); -#else - mavlink_attitude_control_t packet; - packet.target = target; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_CONTROL, (const char *)&packet, 21); -#endif -} - -#endif - -// MESSAGE ATTITUDE_CONTROL UNPACKING - - -/** - * @brief Get field target from attitude_control message - * - * @return The system to be controlled - */ -static inline uint8_t mavlink_msg_attitude_control_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field roll from attitude_control message - * - * @return roll - */ -static inline float mavlink_msg_attitude_control_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 1); -} - -/** - * @brief Get field pitch from attitude_control message - * - * @return pitch - */ -static inline float mavlink_msg_attitude_control_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 5); -} - -/** - * @brief Get field yaw from attitude_control message - * - * @return yaw - */ -static inline float mavlink_msg_attitude_control_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Get field thrust from attitude_control message - * - * @return thrust - */ -static inline float mavlink_msg_attitude_control_get_thrust(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 13); -} - -/** - * @brief Get field roll_manual from attitude_control message - * - * @return roll control enabled auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_attitude_control_get_roll_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 17); -} - -/** - * @brief Get field pitch_manual from attitude_control message - * - * @return pitch auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_attitude_control_get_pitch_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 18); -} - -/** - * @brief Get field yaw_manual from attitude_control message - * - * @return yaw auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_attitude_control_get_yaw_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 19); -} - -/** - * @brief Get field thrust_manual from attitude_control message - * - * @return thrust auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_attitude_control_get_thrust_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 20); -} - -/** - * @brief Decode a attitude_control message into a struct - * - * @param msg The message to decode - * @param attitude_control C-struct to decode the message contents into - */ -static inline void mavlink_msg_attitude_control_decode(const mavlink_message_t* msg, mavlink_attitude_control_t* attitude_control) -{ -#if MAVLINK_NEED_BYTE_SWAP - attitude_control->target = mavlink_msg_attitude_control_get_target(msg); - attitude_control->roll = mavlink_msg_attitude_control_get_roll(msg); - attitude_control->pitch = mavlink_msg_attitude_control_get_pitch(msg); - attitude_control->yaw = mavlink_msg_attitude_control_get_yaw(msg); - attitude_control->thrust = mavlink_msg_attitude_control_get_thrust(msg); - attitude_control->roll_manual = mavlink_msg_attitude_control_get_roll_manual(msg); - attitude_control->pitch_manual = mavlink_msg_attitude_control_get_pitch_manual(msg); - attitude_control->yaw_manual = mavlink_msg_attitude_control_get_yaw_manual(msg); - attitude_control->thrust_manual = mavlink_msg_attitude_control_get_thrust_manual(msg); -#else - memcpy(attitude_control, _MAV_PAYLOAD(msg), 21); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_brief_feature.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_brief_feature.h deleted file mode 100644 index 866d1be44e..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_brief_feature.h +++ /dev/null @@ -1,292 +0,0 @@ -// MESSAGE BRIEF_FEATURE PACKING - -#define MAVLINK_MSG_ID_BRIEF_FEATURE 195 - -typedef struct __mavlink_brief_feature_t -{ - float x; ///< x position in m - float y; ///< y position in m - float z; ///< z position in m - uint8_t orientation_assignment; ///< Orientation assignment 0: false, 1:true - uint16_t size; ///< Size in pixels - uint16_t orientation; ///< Orientation - uint8_t descriptor[32]; ///< Descriptor - float response; ///< Harris operator response at this location -} mavlink_brief_feature_t; - -#define MAVLINK_MSG_ID_BRIEF_FEATURE_LEN 53 -#define MAVLINK_MSG_ID_195_LEN 53 - -#define MAVLINK_MSG_BRIEF_FEATURE_FIELD_DESCRIPTOR_LEN 32 - -#define MAVLINK_MESSAGE_INFO_BRIEF_FEATURE { \ - "BRIEF_FEATURE", \ - 8, \ - { { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_brief_feature_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_brief_feature_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_brief_feature_t, z) }, \ - { "orientation_assignment", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_brief_feature_t, orientation_assignment) }, \ - { "size", NULL, MAVLINK_TYPE_UINT16_T, 0, 13, offsetof(mavlink_brief_feature_t, size) }, \ - { "orientation", NULL, MAVLINK_TYPE_UINT16_T, 0, 15, offsetof(mavlink_brief_feature_t, orientation) }, \ - { "descriptor", NULL, MAVLINK_TYPE_UINT8_T, 32, 17, offsetof(mavlink_brief_feature_t, descriptor) }, \ - { "response", NULL, MAVLINK_TYPE_FLOAT, 0, 49, offsetof(mavlink_brief_feature_t, response) }, \ - } \ -} - - -/** - * @brief Pack a brief_feature message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param x x position in m - * @param y y position in m - * @param z z position in m - * @param orientation_assignment Orientation assignment 0: false, 1:true - * @param size Size in pixels - * @param orientation Orientation - * @param descriptor Descriptor - * @param response Harris operator response at this location - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_brief_feature_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float x, float y, float z, uint8_t orientation_assignment, uint16_t size, uint16_t orientation, const uint8_t *descriptor, float response) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[53]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_uint8_t(buf, 12, orientation_assignment); - _mav_put_uint16_t(buf, 13, size); - _mav_put_uint16_t(buf, 15, orientation); - _mav_put_float(buf, 49, response); - _mav_put_uint8_t_array(buf, 17, descriptor, 32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 53); -#else - mavlink_brief_feature_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.orientation_assignment = orientation_assignment; - packet.size = size; - packet.orientation = orientation; - packet.response = response; - mav_array_memcpy(packet.descriptor, descriptor, sizeof(uint8_t)*32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 53); -#endif - - msg->msgid = MAVLINK_MSG_ID_BRIEF_FEATURE; - return mavlink_finalize_message(msg, system_id, component_id, 53); -} - -/** - * @brief Pack a brief_feature message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param x x position in m - * @param y y position in m - * @param z z position in m - * @param orientation_assignment Orientation assignment 0: false, 1:true - * @param size Size in pixels - * @param orientation Orientation - * @param descriptor Descriptor - * @param response Harris operator response at this location - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_brief_feature_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float x,float y,float z,uint8_t orientation_assignment,uint16_t size,uint16_t orientation,const uint8_t *descriptor,float response) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[53]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_uint8_t(buf, 12, orientation_assignment); - _mav_put_uint16_t(buf, 13, size); - _mav_put_uint16_t(buf, 15, orientation); - _mav_put_float(buf, 49, response); - _mav_put_uint8_t_array(buf, 17, descriptor, 32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 53); -#else - mavlink_brief_feature_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.orientation_assignment = orientation_assignment; - packet.size = size; - packet.orientation = orientation; - packet.response = response; - mav_array_memcpy(packet.descriptor, descriptor, sizeof(uint8_t)*32); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 53); -#endif - - msg->msgid = MAVLINK_MSG_ID_BRIEF_FEATURE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 53); -} - -/** - * @brief Encode a brief_feature struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param brief_feature C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_brief_feature_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_brief_feature_t* brief_feature) -{ - return mavlink_msg_brief_feature_pack(system_id, component_id, msg, brief_feature->x, brief_feature->y, brief_feature->z, brief_feature->orientation_assignment, brief_feature->size, brief_feature->orientation, brief_feature->descriptor, brief_feature->response); -} - -/** - * @brief Send a brief_feature message - * @param chan MAVLink channel to send the message - * - * @param x x position in m - * @param y y position in m - * @param z z position in m - * @param orientation_assignment Orientation assignment 0: false, 1:true - * @param size Size in pixels - * @param orientation Orientation - * @param descriptor Descriptor - * @param response Harris operator response at this location - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_brief_feature_send(mavlink_channel_t chan, float x, float y, float z, uint8_t orientation_assignment, uint16_t size, uint16_t orientation, const uint8_t *descriptor, float response) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[53]; - _mav_put_float(buf, 0, x); - _mav_put_float(buf, 4, y); - _mav_put_float(buf, 8, z); - _mav_put_uint8_t(buf, 12, orientation_assignment); - _mav_put_uint16_t(buf, 13, size); - _mav_put_uint16_t(buf, 15, orientation); - _mav_put_float(buf, 49, response); - _mav_put_uint8_t_array(buf, 17, descriptor, 32); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BRIEF_FEATURE, buf, 53); -#else - mavlink_brief_feature_t packet; - packet.x = x; - packet.y = y; - packet.z = z; - packet.orientation_assignment = orientation_assignment; - packet.size = size; - packet.orientation = orientation; - packet.response = response; - mav_array_memcpy(packet.descriptor, descriptor, sizeof(uint8_t)*32); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_BRIEF_FEATURE, (const char *)&packet, 53); -#endif -} - -#endif - -// MESSAGE BRIEF_FEATURE UNPACKING - - -/** - * @brief Get field x from brief_feature message - * - * @return x position in m - */ -static inline float mavlink_msg_brief_feature_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field y from brief_feature message - * - * @return y position in m - */ -static inline float mavlink_msg_brief_feature_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field z from brief_feature message - * - * @return z position in m - */ -static inline float mavlink_msg_brief_feature_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field orientation_assignment from brief_feature message - * - * @return Orientation assignment 0: false, 1:true - */ -static inline uint8_t mavlink_msg_brief_feature_get_orientation_assignment(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 12); -} - -/** - * @brief Get field size from brief_feature message - * - * @return Size in pixels - */ -static inline uint16_t mavlink_msg_brief_feature_get_size(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 13); -} - -/** - * @brief Get field orientation from brief_feature message - * - * @return Orientation - */ -static inline uint16_t mavlink_msg_brief_feature_get_orientation(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 15); -} - -/** - * @brief Get field descriptor from brief_feature message - * - * @return Descriptor - */ -static inline uint16_t mavlink_msg_brief_feature_get_descriptor(const mavlink_message_t* msg, uint8_t *descriptor) -{ - return _MAV_RETURN_uint8_t_array(msg, descriptor, 32, 17); -} - -/** - * @brief Get field response from brief_feature message - * - * @return Harris operator response at this location - */ -static inline float mavlink_msg_brief_feature_get_response(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 49); -} - -/** - * @brief Decode a brief_feature message into a struct - * - * @param msg The message to decode - * @param brief_feature C-struct to decode the message contents into - */ -static inline void mavlink_msg_brief_feature_decode(const mavlink_message_t* msg, mavlink_brief_feature_t* brief_feature) -{ -#if MAVLINK_NEED_BYTE_SWAP - brief_feature->x = mavlink_msg_brief_feature_get_x(msg); - brief_feature->y = mavlink_msg_brief_feature_get_y(msg); - brief_feature->z = mavlink_msg_brief_feature_get_z(msg); - brief_feature->orientation_assignment = mavlink_msg_brief_feature_get_orientation_assignment(msg); - brief_feature->size = mavlink_msg_brief_feature_get_size(msg); - brief_feature->orientation = mavlink_msg_brief_feature_get_orientation(msg); - mavlink_msg_brief_feature_get_descriptor(msg, brief_feature->descriptor); - brief_feature->response = mavlink_msg_brief_feature_get_response(msg); -#else - memcpy(brief_feature, _MAV_PAYLOAD(msg), 53); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_data_transmission_handshake.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_data_transmission_handshake.h deleted file mode 100644 index 9c0d75a9a1..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_data_transmission_handshake.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE DATA_TRANSMISSION_HANDSHAKE PACKING - -#define MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE 193 - -typedef struct __mavlink_data_transmission_handshake_t -{ - uint8_t type; ///< type of requested/acknowledged data (as defined in ENUM DATA_TYPES in mavlink/include/mavlink_types.h) - uint32_t size; ///< total data size in bytes (set on ACK only) - uint8_t packets; ///< number of packets beeing sent (set on ACK only) - uint8_t payload; ///< payload size per packet (normally 253 byte, see DATA field size in message ENCAPSULATED_DATA) (set on ACK only) - uint8_t jpg_quality; ///< JPEG quality out of [1,100] -} mavlink_data_transmission_handshake_t; - -#define MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE_LEN 8 -#define MAVLINK_MSG_ID_193_LEN 8 - - - -#define MAVLINK_MESSAGE_INFO_DATA_TRANSMISSION_HANDSHAKE { \ - "DATA_TRANSMISSION_HANDSHAKE", \ - 5, \ - { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_data_transmission_handshake_t, type) }, \ - { "size", NULL, MAVLINK_TYPE_UINT32_T, 0, 1, offsetof(mavlink_data_transmission_handshake_t, size) }, \ - { "packets", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_data_transmission_handshake_t, packets) }, \ - { "payload", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_data_transmission_handshake_t, payload) }, \ - { "jpg_quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_data_transmission_handshake_t, jpg_quality) }, \ - } \ -} - - -/** - * @brief Pack a data_transmission_handshake message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type type of requested/acknowledged data (as defined in ENUM DATA_TYPES in mavlink/include/mavlink_types.h) - * @param size total data size in bytes (set on ACK only) - * @param packets number of packets beeing sent (set on ACK only) - * @param payload payload size per packet (normally 253 byte, see DATA field size in message ENCAPSULATED_DATA) (set on ACK only) - * @param jpg_quality JPEG quality out of [1,100] - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_data_transmission_handshake_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, uint32_t size, uint8_t packets, uint8_t payload, uint8_t jpg_quality) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint32_t(buf, 1, size); - _mav_put_uint8_t(buf, 5, packets); - _mav_put_uint8_t(buf, 6, payload); - _mav_put_uint8_t(buf, 7, jpg_quality); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_data_transmission_handshake_t packet; - packet.type = type; - packet.size = size; - packet.packets = packets; - packet.payload = payload; - packet.jpg_quality = jpg_quality; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE; - return mavlink_finalize_message(msg, system_id, component_id, 8); -} - -/** - * @brief Pack a data_transmission_handshake message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type type of requested/acknowledged data (as defined in ENUM DATA_TYPES in mavlink/include/mavlink_types.h) - * @param size total data size in bytes (set on ACK only) - * @param packets number of packets beeing sent (set on ACK only) - * @param payload payload size per packet (normally 253 byte, see DATA field size in message ENCAPSULATED_DATA) (set on ACK only) - * @param jpg_quality JPEG quality out of [1,100] - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_data_transmission_handshake_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,uint32_t size,uint8_t packets,uint8_t payload,uint8_t jpg_quality) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint32_t(buf, 1, size); - _mav_put_uint8_t(buf, 5, packets); - _mav_put_uint8_t(buf, 6, payload); - _mav_put_uint8_t(buf, 7, jpg_quality); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 8); -#else - mavlink_data_transmission_handshake_t packet; - packet.type = type; - packet.size = size; - packet.packets = packets; - packet.payload = payload; - packet.jpg_quality = jpg_quality; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 8); -#endif - - msg->msgid = MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 8); -} - -/** - * @brief Encode a data_transmission_handshake struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param data_transmission_handshake C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_data_transmission_handshake_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data_transmission_handshake_t* data_transmission_handshake) -{ - return mavlink_msg_data_transmission_handshake_pack(system_id, component_id, msg, data_transmission_handshake->type, data_transmission_handshake->size, data_transmission_handshake->packets, data_transmission_handshake->payload, data_transmission_handshake->jpg_quality); -} - -/** - * @brief Send a data_transmission_handshake message - * @param chan MAVLink channel to send the message - * - * @param type type of requested/acknowledged data (as defined in ENUM DATA_TYPES in mavlink/include/mavlink_types.h) - * @param size total data size in bytes (set on ACK only) - * @param packets number of packets beeing sent (set on ACK only) - * @param payload payload size per packet (normally 253 byte, see DATA field size in message ENCAPSULATED_DATA) (set on ACK only) - * @param jpg_quality JPEG quality out of [1,100] - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_data_transmission_handshake_send(mavlink_channel_t chan, uint8_t type, uint32_t size, uint8_t packets, uint8_t payload, uint8_t jpg_quality) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[8]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint32_t(buf, 1, size); - _mav_put_uint8_t(buf, 5, packets); - _mav_put_uint8_t(buf, 6, payload); - _mav_put_uint8_t(buf, 7, jpg_quality); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE, buf, 8); -#else - mavlink_data_transmission_handshake_t packet; - packet.type = type; - packet.size = size; - packet.packets = packets; - packet.payload = payload; - packet.jpg_quality = jpg_quality; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE, (const char *)&packet, 8); -#endif -} - -#endif - -// MESSAGE DATA_TRANSMISSION_HANDSHAKE UNPACKING - - -/** - * @brief Get field type from data_transmission_handshake message - * - * @return type of requested/acknowledged data (as defined in ENUM DATA_TYPES in mavlink/include/mavlink_types.h) - */ -static inline uint8_t mavlink_msg_data_transmission_handshake_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field size from data_transmission_handshake message - * - * @return total data size in bytes (set on ACK only) - */ -static inline uint32_t mavlink_msg_data_transmission_handshake_get_size(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 1); -} - -/** - * @brief Get field packets from data_transmission_handshake message - * - * @return number of packets beeing sent (set on ACK only) - */ -static inline uint8_t mavlink_msg_data_transmission_handshake_get_packets(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field payload from data_transmission_handshake message - * - * @return payload size per packet (normally 253 byte, see DATA field size in message ENCAPSULATED_DATA) (set on ACK only) - */ -static inline uint8_t mavlink_msg_data_transmission_handshake_get_payload(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field jpg_quality from data_transmission_handshake message - * - * @return JPEG quality out of [1,100] - */ -static inline uint8_t mavlink_msg_data_transmission_handshake_get_jpg_quality(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 7); -} - -/** - * @brief Decode a data_transmission_handshake message into a struct - * - * @param msg The message to decode - * @param data_transmission_handshake C-struct to decode the message contents into - */ -static inline void mavlink_msg_data_transmission_handshake_decode(const mavlink_message_t* msg, mavlink_data_transmission_handshake_t* data_transmission_handshake) -{ -#if MAVLINK_NEED_BYTE_SWAP - data_transmission_handshake->type = mavlink_msg_data_transmission_handshake_get_type(msg); - data_transmission_handshake->size = mavlink_msg_data_transmission_handshake_get_size(msg); - data_transmission_handshake->packets = mavlink_msg_data_transmission_handshake_get_packets(msg); - data_transmission_handshake->payload = mavlink_msg_data_transmission_handshake_get_payload(msg); - data_transmission_handshake->jpg_quality = mavlink_msg_data_transmission_handshake_get_jpg_quality(msg); -#else - memcpy(data_transmission_handshake, _MAV_PAYLOAD(msg), 8); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_encapsulated_data.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_encapsulated_data.h deleted file mode 100644 index 705a6cc29d..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_encapsulated_data.h +++ /dev/null @@ -1,160 +0,0 @@ -// MESSAGE ENCAPSULATED_DATA PACKING - -#define MAVLINK_MSG_ID_ENCAPSULATED_DATA 194 - -typedef struct __mavlink_encapsulated_data_t -{ - uint16_t seqnr; ///< sequence number (starting with 0 on every transmission) - uint8_t data[253]; ///< image data bytes -} mavlink_encapsulated_data_t; - -#define MAVLINK_MSG_ID_ENCAPSULATED_DATA_LEN 255 -#define MAVLINK_MSG_ID_194_LEN 255 - -#define MAVLINK_MSG_ENCAPSULATED_DATA_FIELD_DATA_LEN 253 - -#define MAVLINK_MESSAGE_INFO_ENCAPSULATED_DATA { \ - "ENCAPSULATED_DATA", \ - 2, \ - { { "seqnr", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_encapsulated_data_t, seqnr) }, \ - { "data", NULL, MAVLINK_TYPE_UINT8_T, 253, 2, offsetof(mavlink_encapsulated_data_t, data) }, \ - } \ -} - - -/** - * @brief Pack a encapsulated_data message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param seqnr sequence number (starting with 0 on every transmission) - * @param data image data bytes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_encapsulated_data_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t seqnr, const uint8_t *data) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[255]; - _mav_put_uint16_t(buf, 0, seqnr); - _mav_put_uint8_t_array(buf, 2, data, 253); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 255); -#else - mavlink_encapsulated_data_t packet; - packet.seqnr = seqnr; - mav_array_memcpy(packet.data, data, sizeof(uint8_t)*253); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 255); -#endif - - msg->msgid = MAVLINK_MSG_ID_ENCAPSULATED_DATA; - return mavlink_finalize_message(msg, system_id, component_id, 255); -} - -/** - * @brief Pack a encapsulated_data message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param seqnr sequence number (starting with 0 on every transmission) - * @param data image data bytes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_encapsulated_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t seqnr,const uint8_t *data) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[255]; - _mav_put_uint16_t(buf, 0, seqnr); - _mav_put_uint8_t_array(buf, 2, data, 253); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 255); -#else - mavlink_encapsulated_data_t packet; - packet.seqnr = seqnr; - mav_array_memcpy(packet.data, data, sizeof(uint8_t)*253); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 255); -#endif - - msg->msgid = MAVLINK_MSG_ID_ENCAPSULATED_DATA; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 255); -} - -/** - * @brief Encode a encapsulated_data struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param encapsulated_data C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_encapsulated_data_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_encapsulated_data_t* encapsulated_data) -{ - return mavlink_msg_encapsulated_data_pack(system_id, component_id, msg, encapsulated_data->seqnr, encapsulated_data->data); -} - -/** - * @brief Send a encapsulated_data message - * @param chan MAVLink channel to send the message - * - * @param seqnr sequence number (starting with 0 on every transmission) - * @param data image data bytes - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_encapsulated_data_send(mavlink_channel_t chan, uint16_t seqnr, const uint8_t *data) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[255]; - _mav_put_uint16_t(buf, 0, seqnr); - _mav_put_uint8_t_array(buf, 2, data, 253); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ENCAPSULATED_DATA, buf, 255); -#else - mavlink_encapsulated_data_t packet; - packet.seqnr = seqnr; - mav_array_memcpy(packet.data, data, sizeof(uint8_t)*253); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ENCAPSULATED_DATA, (const char *)&packet, 255); -#endif -} - -#endif - -// MESSAGE ENCAPSULATED_DATA UNPACKING - - -/** - * @brief Get field seqnr from encapsulated_data message - * - * @return sequence number (starting with 0 on every transmission) - */ -static inline uint16_t mavlink_msg_encapsulated_data_get_seqnr(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field data from encapsulated_data message - * - * @return image data bytes - */ -static inline uint16_t mavlink_msg_encapsulated_data_get_data(const mavlink_message_t* msg, uint8_t *data) -{ - return _MAV_RETURN_uint8_t_array(msg, data, 253, 2); -} - -/** - * @brief Decode a encapsulated_data message into a struct - * - * @param msg The message to decode - * @param encapsulated_data C-struct to decode the message contents into - */ -static inline void mavlink_msg_encapsulated_data_decode(const mavlink_message_t* msg, mavlink_encapsulated_data_t* encapsulated_data) -{ -#if MAVLINK_NEED_BYTE_SWAP - encapsulated_data->seqnr = mavlink_msg_encapsulated_data_get_seqnr(msg); - mavlink_msg_encapsulated_data_get_data(msg, encapsulated_data->data); -#else - memcpy(encapsulated_data, _MAV_PAYLOAD(msg), 255); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_available.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_available.h deleted file mode 100644 index 40d1901c69..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_available.h +++ /dev/null @@ -1,628 +0,0 @@ -// MESSAGE IMAGE_AVAILABLE PACKING - -#define MAVLINK_MSG_ID_IMAGE_AVAILABLE 154 - -typedef struct __mavlink_image_available_t -{ - uint64_t cam_id; ///< Camera id - uint8_t cam_no; ///< Camera # (starts with 0) - uint64_t timestamp; ///< Timestamp - uint64_t valid_until; ///< Until which timestamp this buffer will stay valid - uint32_t img_seq; ///< The image sequence number - uint32_t img_buf_index; ///< Position of the image in the buffer, starts with 0 - uint16_t width; ///< Image width - uint16_t height; ///< Image height - uint16_t depth; ///< Image depth - uint8_t channels; ///< Image channels - uint32_t key; ///< Shared memory area key - uint32_t exposure; ///< Exposure time, in microseconds - float gain; ///< Camera gain - float roll; ///< Roll angle in rad - float pitch; ///< Pitch angle in rad - float yaw; ///< Yaw angle in rad - float local_z; ///< Local frame Z coordinate (height over ground) - float lat; ///< GPS X coordinate - float lon; ///< GPS Y coordinate - float alt; ///< Global frame altitude - float ground_x; ///< Ground truth X - float ground_y; ///< Ground truth Y - float ground_z; ///< Ground truth Z -} mavlink_image_available_t; - -#define MAVLINK_MSG_ID_IMAGE_AVAILABLE_LEN 92 -#define MAVLINK_MSG_ID_154_LEN 92 - - - -#define MAVLINK_MESSAGE_INFO_IMAGE_AVAILABLE { \ - "IMAGE_AVAILABLE", \ - 23, \ - { { "cam_id", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_image_available_t, cam_id) }, \ - { "cam_no", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_image_available_t, cam_no) }, \ - { "timestamp", NULL, MAVLINK_TYPE_UINT64_T, 0, 9, offsetof(mavlink_image_available_t, timestamp) }, \ - { "valid_until", NULL, MAVLINK_TYPE_UINT64_T, 0, 17, offsetof(mavlink_image_available_t, valid_until) }, \ - { "img_seq", NULL, MAVLINK_TYPE_UINT32_T, 0, 25, offsetof(mavlink_image_available_t, img_seq) }, \ - { "img_buf_index", NULL, MAVLINK_TYPE_UINT32_T, 0, 29, offsetof(mavlink_image_available_t, img_buf_index) }, \ - { "width", NULL, MAVLINK_TYPE_UINT16_T, 0, 33, offsetof(mavlink_image_available_t, width) }, \ - { "height", NULL, MAVLINK_TYPE_UINT16_T, 0, 35, offsetof(mavlink_image_available_t, height) }, \ - { "depth", NULL, MAVLINK_TYPE_UINT16_T, 0, 37, offsetof(mavlink_image_available_t, depth) }, \ - { "channels", NULL, MAVLINK_TYPE_UINT8_T, 0, 39, offsetof(mavlink_image_available_t, channels) }, \ - { "key", NULL, MAVLINK_TYPE_UINT32_T, 0, 40, offsetof(mavlink_image_available_t, key) }, \ - { "exposure", NULL, MAVLINK_TYPE_UINT32_T, 0, 44, offsetof(mavlink_image_available_t, exposure) }, \ - { "gain", NULL, MAVLINK_TYPE_FLOAT, 0, 48, offsetof(mavlink_image_available_t, gain) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 52, offsetof(mavlink_image_available_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 56, offsetof(mavlink_image_available_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 60, offsetof(mavlink_image_available_t, yaw) }, \ - { "local_z", NULL, MAVLINK_TYPE_FLOAT, 0, 64, offsetof(mavlink_image_available_t, local_z) }, \ - { "lat", NULL, MAVLINK_TYPE_FLOAT, 0, 68, offsetof(mavlink_image_available_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_FLOAT, 0, 72, offsetof(mavlink_image_available_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 76, offsetof(mavlink_image_available_t, alt) }, \ - { "ground_x", NULL, MAVLINK_TYPE_FLOAT, 0, 80, offsetof(mavlink_image_available_t, ground_x) }, \ - { "ground_y", NULL, MAVLINK_TYPE_FLOAT, 0, 84, offsetof(mavlink_image_available_t, ground_y) }, \ - { "ground_z", NULL, MAVLINK_TYPE_FLOAT, 0, 88, offsetof(mavlink_image_available_t, ground_z) }, \ - } \ -} - - -/** - * @brief Pack a image_available message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param cam_id Camera id - * @param cam_no Camera # (starts with 0) - * @param timestamp Timestamp - * @param valid_until Until which timestamp this buffer will stay valid - * @param img_seq The image sequence number - * @param img_buf_index Position of the image in the buffer, starts with 0 - * @param width Image width - * @param height Image height - * @param depth Image depth - * @param channels Image channels - * @param key Shared memory area key - * @param exposure Exposure time, in microseconds - * @param gain Camera gain - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @param local_z Local frame Z coordinate (height over ground) - * @param lat GPS X coordinate - * @param lon GPS Y coordinate - * @param alt Global frame altitude - * @param ground_x Ground truth X - * @param ground_y Ground truth Y - * @param ground_z Ground truth Z - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_image_available_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t cam_id, uint8_t cam_no, uint64_t timestamp, uint64_t valid_until, uint32_t img_seq, uint32_t img_buf_index, uint16_t width, uint16_t height, uint16_t depth, uint8_t channels, uint32_t key, uint32_t exposure, float gain, float roll, float pitch, float yaw, float local_z, float lat, float lon, float alt, float ground_x, float ground_y, float ground_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[92]; - _mav_put_uint64_t(buf, 0, cam_id); - _mav_put_uint8_t(buf, 8, cam_no); - _mav_put_uint64_t(buf, 9, timestamp); - _mav_put_uint64_t(buf, 17, valid_until); - _mav_put_uint32_t(buf, 25, img_seq); - _mav_put_uint32_t(buf, 29, img_buf_index); - _mav_put_uint16_t(buf, 33, width); - _mav_put_uint16_t(buf, 35, height); - _mav_put_uint16_t(buf, 37, depth); - _mav_put_uint8_t(buf, 39, channels); - _mav_put_uint32_t(buf, 40, key); - _mav_put_uint32_t(buf, 44, exposure); - _mav_put_float(buf, 48, gain); - _mav_put_float(buf, 52, roll); - _mav_put_float(buf, 56, pitch); - _mav_put_float(buf, 60, yaw); - _mav_put_float(buf, 64, local_z); - _mav_put_float(buf, 68, lat); - _mav_put_float(buf, 72, lon); - _mav_put_float(buf, 76, alt); - _mav_put_float(buf, 80, ground_x); - _mav_put_float(buf, 84, ground_y); - _mav_put_float(buf, 88, ground_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 92); -#else - mavlink_image_available_t packet; - packet.cam_id = cam_id; - packet.cam_no = cam_no; - packet.timestamp = timestamp; - packet.valid_until = valid_until; - packet.img_seq = img_seq; - packet.img_buf_index = img_buf_index; - packet.width = width; - packet.height = height; - packet.depth = depth; - packet.channels = channels; - packet.key = key; - packet.exposure = exposure; - packet.gain = gain; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.local_z = local_z; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.ground_x = ground_x; - packet.ground_y = ground_y; - packet.ground_z = ground_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 92); -#endif - - msg->msgid = MAVLINK_MSG_ID_IMAGE_AVAILABLE; - return mavlink_finalize_message(msg, system_id, component_id, 92); -} - -/** - * @brief Pack a image_available message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param cam_id Camera id - * @param cam_no Camera # (starts with 0) - * @param timestamp Timestamp - * @param valid_until Until which timestamp this buffer will stay valid - * @param img_seq The image sequence number - * @param img_buf_index Position of the image in the buffer, starts with 0 - * @param width Image width - * @param height Image height - * @param depth Image depth - * @param channels Image channels - * @param key Shared memory area key - * @param exposure Exposure time, in microseconds - * @param gain Camera gain - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @param local_z Local frame Z coordinate (height over ground) - * @param lat GPS X coordinate - * @param lon GPS Y coordinate - * @param alt Global frame altitude - * @param ground_x Ground truth X - * @param ground_y Ground truth Y - * @param ground_z Ground truth Z - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_image_available_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t cam_id,uint8_t cam_no,uint64_t timestamp,uint64_t valid_until,uint32_t img_seq,uint32_t img_buf_index,uint16_t width,uint16_t height,uint16_t depth,uint8_t channels,uint32_t key,uint32_t exposure,float gain,float roll,float pitch,float yaw,float local_z,float lat,float lon,float alt,float ground_x,float ground_y,float ground_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[92]; - _mav_put_uint64_t(buf, 0, cam_id); - _mav_put_uint8_t(buf, 8, cam_no); - _mav_put_uint64_t(buf, 9, timestamp); - _mav_put_uint64_t(buf, 17, valid_until); - _mav_put_uint32_t(buf, 25, img_seq); - _mav_put_uint32_t(buf, 29, img_buf_index); - _mav_put_uint16_t(buf, 33, width); - _mav_put_uint16_t(buf, 35, height); - _mav_put_uint16_t(buf, 37, depth); - _mav_put_uint8_t(buf, 39, channels); - _mav_put_uint32_t(buf, 40, key); - _mav_put_uint32_t(buf, 44, exposure); - _mav_put_float(buf, 48, gain); - _mav_put_float(buf, 52, roll); - _mav_put_float(buf, 56, pitch); - _mav_put_float(buf, 60, yaw); - _mav_put_float(buf, 64, local_z); - _mav_put_float(buf, 68, lat); - _mav_put_float(buf, 72, lon); - _mav_put_float(buf, 76, alt); - _mav_put_float(buf, 80, ground_x); - _mav_put_float(buf, 84, ground_y); - _mav_put_float(buf, 88, ground_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 92); -#else - mavlink_image_available_t packet; - packet.cam_id = cam_id; - packet.cam_no = cam_no; - packet.timestamp = timestamp; - packet.valid_until = valid_until; - packet.img_seq = img_seq; - packet.img_buf_index = img_buf_index; - packet.width = width; - packet.height = height; - packet.depth = depth; - packet.channels = channels; - packet.key = key; - packet.exposure = exposure; - packet.gain = gain; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.local_z = local_z; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.ground_x = ground_x; - packet.ground_y = ground_y; - packet.ground_z = ground_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 92); -#endif - - msg->msgid = MAVLINK_MSG_ID_IMAGE_AVAILABLE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 92); -} - -/** - * @brief Encode a image_available struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param image_available C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_image_available_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_image_available_t* image_available) -{ - return mavlink_msg_image_available_pack(system_id, component_id, msg, image_available->cam_id, image_available->cam_no, image_available->timestamp, image_available->valid_until, image_available->img_seq, image_available->img_buf_index, image_available->width, image_available->height, image_available->depth, image_available->channels, image_available->key, image_available->exposure, image_available->gain, image_available->roll, image_available->pitch, image_available->yaw, image_available->local_z, image_available->lat, image_available->lon, image_available->alt, image_available->ground_x, image_available->ground_y, image_available->ground_z); -} - -/** - * @brief Send a image_available message - * @param chan MAVLink channel to send the message - * - * @param cam_id Camera id - * @param cam_no Camera # (starts with 0) - * @param timestamp Timestamp - * @param valid_until Until which timestamp this buffer will stay valid - * @param img_seq The image sequence number - * @param img_buf_index Position of the image in the buffer, starts with 0 - * @param width Image width - * @param height Image height - * @param depth Image depth - * @param channels Image channels - * @param key Shared memory area key - * @param exposure Exposure time, in microseconds - * @param gain Camera gain - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @param local_z Local frame Z coordinate (height over ground) - * @param lat GPS X coordinate - * @param lon GPS Y coordinate - * @param alt Global frame altitude - * @param ground_x Ground truth X - * @param ground_y Ground truth Y - * @param ground_z Ground truth Z - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_image_available_send(mavlink_channel_t chan, uint64_t cam_id, uint8_t cam_no, uint64_t timestamp, uint64_t valid_until, uint32_t img_seq, uint32_t img_buf_index, uint16_t width, uint16_t height, uint16_t depth, uint8_t channels, uint32_t key, uint32_t exposure, float gain, float roll, float pitch, float yaw, float local_z, float lat, float lon, float alt, float ground_x, float ground_y, float ground_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[92]; - _mav_put_uint64_t(buf, 0, cam_id); - _mav_put_uint8_t(buf, 8, cam_no); - _mav_put_uint64_t(buf, 9, timestamp); - _mav_put_uint64_t(buf, 17, valid_until); - _mav_put_uint32_t(buf, 25, img_seq); - _mav_put_uint32_t(buf, 29, img_buf_index); - _mav_put_uint16_t(buf, 33, width); - _mav_put_uint16_t(buf, 35, height); - _mav_put_uint16_t(buf, 37, depth); - _mav_put_uint8_t(buf, 39, channels); - _mav_put_uint32_t(buf, 40, key); - _mav_put_uint32_t(buf, 44, exposure); - _mav_put_float(buf, 48, gain); - _mav_put_float(buf, 52, roll); - _mav_put_float(buf, 56, pitch); - _mav_put_float(buf, 60, yaw); - _mav_put_float(buf, 64, local_z); - _mav_put_float(buf, 68, lat); - _mav_put_float(buf, 72, lon); - _mav_put_float(buf, 76, alt); - _mav_put_float(buf, 80, ground_x); - _mav_put_float(buf, 84, ground_y); - _mav_put_float(buf, 88, ground_z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_IMAGE_AVAILABLE, buf, 92); -#else - mavlink_image_available_t packet; - packet.cam_id = cam_id; - packet.cam_no = cam_no; - packet.timestamp = timestamp; - packet.valid_until = valid_until; - packet.img_seq = img_seq; - packet.img_buf_index = img_buf_index; - packet.width = width; - packet.height = height; - packet.depth = depth; - packet.channels = channels; - packet.key = key; - packet.exposure = exposure; - packet.gain = gain; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.local_z = local_z; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.ground_x = ground_x; - packet.ground_y = ground_y; - packet.ground_z = ground_z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_IMAGE_AVAILABLE, (const char *)&packet, 92); -#endif -} - -#endif - -// MESSAGE IMAGE_AVAILABLE UNPACKING - - -/** - * @brief Get field cam_id from image_available message - * - * @return Camera id - */ -static inline uint64_t mavlink_msg_image_available_get_cam_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field cam_no from image_available message - * - * @return Camera # (starts with 0) - */ -static inline uint8_t mavlink_msg_image_available_get_cam_no(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Get field timestamp from image_available message - * - * @return Timestamp - */ -static inline uint64_t mavlink_msg_image_available_get_timestamp(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 9); -} - -/** - * @brief Get field valid_until from image_available message - * - * @return Until which timestamp this buffer will stay valid - */ -static inline uint64_t mavlink_msg_image_available_get_valid_until(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 17); -} - -/** - * @brief Get field img_seq from image_available message - * - * @return The image sequence number - */ -static inline uint32_t mavlink_msg_image_available_get_img_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 25); -} - -/** - * @brief Get field img_buf_index from image_available message - * - * @return Position of the image in the buffer, starts with 0 - */ -static inline uint32_t mavlink_msg_image_available_get_img_buf_index(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 29); -} - -/** - * @brief Get field width from image_available message - * - * @return Image width - */ -static inline uint16_t mavlink_msg_image_available_get_width(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 33); -} - -/** - * @brief Get field height from image_available message - * - * @return Image height - */ -static inline uint16_t mavlink_msg_image_available_get_height(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 35); -} - -/** - * @brief Get field depth from image_available message - * - * @return Image depth - */ -static inline uint16_t mavlink_msg_image_available_get_depth(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 37); -} - -/** - * @brief Get field channels from image_available message - * - * @return Image channels - */ -static inline uint8_t mavlink_msg_image_available_get_channels(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 39); -} - -/** - * @brief Get field key from image_available message - * - * @return Shared memory area key - */ -static inline uint32_t mavlink_msg_image_available_get_key(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 40); -} - -/** - * @brief Get field exposure from image_available message - * - * @return Exposure time, in microseconds - */ -static inline uint32_t mavlink_msg_image_available_get_exposure(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 44); -} - -/** - * @brief Get field gain from image_available message - * - * @return Camera gain - */ -static inline float mavlink_msg_image_available_get_gain(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 48); -} - -/** - * @brief Get field roll from image_available message - * - * @return Roll angle in rad - */ -static inline float mavlink_msg_image_available_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 52); -} - -/** - * @brief Get field pitch from image_available message - * - * @return Pitch angle in rad - */ -static inline float mavlink_msg_image_available_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 56); -} - -/** - * @brief Get field yaw from image_available message - * - * @return Yaw angle in rad - */ -static inline float mavlink_msg_image_available_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 60); -} - -/** - * @brief Get field local_z from image_available message - * - * @return Local frame Z coordinate (height over ground) - */ -static inline float mavlink_msg_image_available_get_local_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 64); -} - -/** - * @brief Get field lat from image_available message - * - * @return GPS X coordinate - */ -static inline float mavlink_msg_image_available_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 68); -} - -/** - * @brief Get field lon from image_available message - * - * @return GPS Y coordinate - */ -static inline float mavlink_msg_image_available_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 72); -} - -/** - * @brief Get field alt from image_available message - * - * @return Global frame altitude - */ -static inline float mavlink_msg_image_available_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 76); -} - -/** - * @brief Get field ground_x from image_available message - * - * @return Ground truth X - */ -static inline float mavlink_msg_image_available_get_ground_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 80); -} - -/** - * @brief Get field ground_y from image_available message - * - * @return Ground truth Y - */ -static inline float mavlink_msg_image_available_get_ground_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 84); -} - -/** - * @brief Get field ground_z from image_available message - * - * @return Ground truth Z - */ -static inline float mavlink_msg_image_available_get_ground_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 88); -} - -/** - * @brief Decode a image_available message into a struct - * - * @param msg The message to decode - * @param image_available C-struct to decode the message contents into - */ -static inline void mavlink_msg_image_available_decode(const mavlink_message_t* msg, mavlink_image_available_t* image_available) -{ -#if MAVLINK_NEED_BYTE_SWAP - image_available->cam_id = mavlink_msg_image_available_get_cam_id(msg); - image_available->cam_no = mavlink_msg_image_available_get_cam_no(msg); - image_available->timestamp = mavlink_msg_image_available_get_timestamp(msg); - image_available->valid_until = mavlink_msg_image_available_get_valid_until(msg); - image_available->img_seq = mavlink_msg_image_available_get_img_seq(msg); - image_available->img_buf_index = mavlink_msg_image_available_get_img_buf_index(msg); - image_available->width = mavlink_msg_image_available_get_width(msg); - image_available->height = mavlink_msg_image_available_get_height(msg); - image_available->depth = mavlink_msg_image_available_get_depth(msg); - image_available->channels = mavlink_msg_image_available_get_channels(msg); - image_available->key = mavlink_msg_image_available_get_key(msg); - image_available->exposure = mavlink_msg_image_available_get_exposure(msg); - image_available->gain = mavlink_msg_image_available_get_gain(msg); - image_available->roll = mavlink_msg_image_available_get_roll(msg); - image_available->pitch = mavlink_msg_image_available_get_pitch(msg); - image_available->yaw = mavlink_msg_image_available_get_yaw(msg); - image_available->local_z = mavlink_msg_image_available_get_local_z(msg); - image_available->lat = mavlink_msg_image_available_get_lat(msg); - image_available->lon = mavlink_msg_image_available_get_lon(msg); - image_available->alt = mavlink_msg_image_available_get_alt(msg); - image_available->ground_x = mavlink_msg_image_available_get_ground_x(msg); - image_available->ground_y = mavlink_msg_image_available_get_ground_y(msg); - image_available->ground_z = mavlink_msg_image_available_get_ground_z(msg); -#else - memcpy(image_available, _MAV_PAYLOAD(msg), 92); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_trigger_control.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_trigger_control.h deleted file mode 100644 index 36b280ec0d..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_trigger_control.h +++ /dev/null @@ -1,144 +0,0 @@ -// MESSAGE IMAGE_TRIGGER_CONTROL PACKING - -#define MAVLINK_MSG_ID_IMAGE_TRIGGER_CONTROL 153 - -typedef struct __mavlink_image_trigger_control_t -{ - uint8_t enable; ///< 0 to disable, 1 to enable -} mavlink_image_trigger_control_t; - -#define MAVLINK_MSG_ID_IMAGE_TRIGGER_CONTROL_LEN 1 -#define MAVLINK_MSG_ID_153_LEN 1 - - - -#define MAVLINK_MESSAGE_INFO_IMAGE_TRIGGER_CONTROL { \ - "IMAGE_TRIGGER_CONTROL", \ - 1, \ - { { "enable", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_image_trigger_control_t, enable) }, \ - } \ -} - - -/** - * @brief Pack a image_trigger_control message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param enable 0 to disable, 1 to enable - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_image_trigger_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t enable) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[1]; - _mav_put_uint8_t(buf, 0, enable); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 1); -#else - mavlink_image_trigger_control_t packet; - packet.enable = enable; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 1); -#endif - - msg->msgid = MAVLINK_MSG_ID_IMAGE_TRIGGER_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 1); -} - -/** - * @brief Pack a image_trigger_control message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param enable 0 to disable, 1 to enable - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_image_trigger_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t enable) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[1]; - _mav_put_uint8_t(buf, 0, enable); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 1); -#else - mavlink_image_trigger_control_t packet; - packet.enable = enable; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 1); -#endif - - msg->msgid = MAVLINK_MSG_ID_IMAGE_TRIGGER_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 1); -} - -/** - * @brief Encode a image_trigger_control struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param image_trigger_control C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_image_trigger_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_image_trigger_control_t* image_trigger_control) -{ - return mavlink_msg_image_trigger_control_pack(system_id, component_id, msg, image_trigger_control->enable); -} - -/** - * @brief Send a image_trigger_control message - * @param chan MAVLink channel to send the message - * - * @param enable 0 to disable, 1 to enable - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_image_trigger_control_send(mavlink_channel_t chan, uint8_t enable) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[1]; - _mav_put_uint8_t(buf, 0, enable); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_IMAGE_TRIGGER_CONTROL, buf, 1); -#else - mavlink_image_trigger_control_t packet; - packet.enable = enable; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_IMAGE_TRIGGER_CONTROL, (const char *)&packet, 1); -#endif -} - -#endif - -// MESSAGE IMAGE_TRIGGER_CONTROL UNPACKING - - -/** - * @brief Get field enable from image_trigger_control message - * - * @return 0 to disable, 1 to enable - */ -static inline uint8_t mavlink_msg_image_trigger_control_get_enable(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Decode a image_trigger_control message into a struct - * - * @param msg The message to decode - * @param image_trigger_control C-struct to decode the message contents into - */ -static inline void mavlink_msg_image_trigger_control_decode(const mavlink_message_t* msg, mavlink_image_trigger_control_t* image_trigger_control) -{ -#if MAVLINK_NEED_BYTE_SWAP - image_trigger_control->enable = mavlink_msg_image_trigger_control_get_enable(msg); -#else - memcpy(image_trigger_control, _MAV_PAYLOAD(msg), 1); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_triggered.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_triggered.h deleted file mode 100644 index a40bc134b5..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_image_triggered.h +++ /dev/null @@ -1,386 +0,0 @@ -// MESSAGE IMAGE_TRIGGERED PACKING - -#define MAVLINK_MSG_ID_IMAGE_TRIGGERED 152 - -typedef struct __mavlink_image_triggered_t -{ - uint64_t timestamp; ///< Timestamp - uint32_t seq; ///< IMU seq - float roll; ///< Roll angle in rad - float pitch; ///< Pitch angle in rad - float yaw; ///< Yaw angle in rad - float local_z; ///< Local frame Z coordinate (height over ground) - float lat; ///< GPS X coordinate - float lon; ///< GPS Y coordinate - float alt; ///< Global frame altitude - float ground_x; ///< Ground truth X - float ground_y; ///< Ground truth Y - float ground_z; ///< Ground truth Z -} mavlink_image_triggered_t; - -#define MAVLINK_MSG_ID_IMAGE_TRIGGERED_LEN 52 -#define MAVLINK_MSG_ID_152_LEN 52 - - - -#define MAVLINK_MESSAGE_INFO_IMAGE_TRIGGERED { \ - "IMAGE_TRIGGERED", \ - 12, \ - { { "timestamp", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_image_triggered_t, timestamp) }, \ - { "seq", NULL, MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_image_triggered_t, seq) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_image_triggered_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_image_triggered_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_image_triggered_t, yaw) }, \ - { "local_z", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_image_triggered_t, local_z) }, \ - { "lat", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_image_triggered_t, lat) }, \ - { "lon", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_image_triggered_t, lon) }, \ - { "alt", NULL, MAVLINK_TYPE_FLOAT, 0, 36, offsetof(mavlink_image_triggered_t, alt) }, \ - { "ground_x", NULL, MAVLINK_TYPE_FLOAT, 0, 40, offsetof(mavlink_image_triggered_t, ground_x) }, \ - { "ground_y", NULL, MAVLINK_TYPE_FLOAT, 0, 44, offsetof(mavlink_image_triggered_t, ground_y) }, \ - { "ground_z", NULL, MAVLINK_TYPE_FLOAT, 0, 48, offsetof(mavlink_image_triggered_t, ground_z) }, \ - } \ -} - - -/** - * @brief Pack a image_triggered message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param timestamp Timestamp - * @param seq IMU seq - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @param local_z Local frame Z coordinate (height over ground) - * @param lat GPS X coordinate - * @param lon GPS Y coordinate - * @param alt Global frame altitude - * @param ground_x Ground truth X - * @param ground_y Ground truth Y - * @param ground_z Ground truth Z - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_image_triggered_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t timestamp, uint32_t seq, float roll, float pitch, float yaw, float local_z, float lat, float lon, float alt, float ground_x, float ground_y, float ground_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[52]; - _mav_put_uint64_t(buf, 0, timestamp); - _mav_put_uint32_t(buf, 8, seq); - _mav_put_float(buf, 12, roll); - _mav_put_float(buf, 16, pitch); - _mav_put_float(buf, 20, yaw); - _mav_put_float(buf, 24, local_z); - _mav_put_float(buf, 28, lat); - _mav_put_float(buf, 32, lon); - _mav_put_float(buf, 36, alt); - _mav_put_float(buf, 40, ground_x); - _mav_put_float(buf, 44, ground_y); - _mav_put_float(buf, 48, ground_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 52); -#else - mavlink_image_triggered_t packet; - packet.timestamp = timestamp; - packet.seq = seq; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.local_z = local_z; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.ground_x = ground_x; - packet.ground_y = ground_y; - packet.ground_z = ground_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 52); -#endif - - msg->msgid = MAVLINK_MSG_ID_IMAGE_TRIGGERED; - return mavlink_finalize_message(msg, system_id, component_id, 52); -} - -/** - * @brief Pack a image_triggered message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param timestamp Timestamp - * @param seq IMU seq - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @param local_z Local frame Z coordinate (height over ground) - * @param lat GPS X coordinate - * @param lon GPS Y coordinate - * @param alt Global frame altitude - * @param ground_x Ground truth X - * @param ground_y Ground truth Y - * @param ground_z Ground truth Z - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_image_triggered_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t timestamp,uint32_t seq,float roll,float pitch,float yaw,float local_z,float lat,float lon,float alt,float ground_x,float ground_y,float ground_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[52]; - _mav_put_uint64_t(buf, 0, timestamp); - _mav_put_uint32_t(buf, 8, seq); - _mav_put_float(buf, 12, roll); - _mav_put_float(buf, 16, pitch); - _mav_put_float(buf, 20, yaw); - _mav_put_float(buf, 24, local_z); - _mav_put_float(buf, 28, lat); - _mav_put_float(buf, 32, lon); - _mav_put_float(buf, 36, alt); - _mav_put_float(buf, 40, ground_x); - _mav_put_float(buf, 44, ground_y); - _mav_put_float(buf, 48, ground_z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 52); -#else - mavlink_image_triggered_t packet; - packet.timestamp = timestamp; - packet.seq = seq; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.local_z = local_z; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.ground_x = ground_x; - packet.ground_y = ground_y; - packet.ground_z = ground_z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 52); -#endif - - msg->msgid = MAVLINK_MSG_ID_IMAGE_TRIGGERED; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 52); -} - -/** - * @brief Encode a image_triggered struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param image_triggered C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_image_triggered_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_image_triggered_t* image_triggered) -{ - return mavlink_msg_image_triggered_pack(system_id, component_id, msg, image_triggered->timestamp, image_triggered->seq, image_triggered->roll, image_triggered->pitch, image_triggered->yaw, image_triggered->local_z, image_triggered->lat, image_triggered->lon, image_triggered->alt, image_triggered->ground_x, image_triggered->ground_y, image_triggered->ground_z); -} - -/** - * @brief Send a image_triggered message - * @param chan MAVLink channel to send the message - * - * @param timestamp Timestamp - * @param seq IMU seq - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @param local_z Local frame Z coordinate (height over ground) - * @param lat GPS X coordinate - * @param lon GPS Y coordinate - * @param alt Global frame altitude - * @param ground_x Ground truth X - * @param ground_y Ground truth Y - * @param ground_z Ground truth Z - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_image_triggered_send(mavlink_channel_t chan, uint64_t timestamp, uint32_t seq, float roll, float pitch, float yaw, float local_z, float lat, float lon, float alt, float ground_x, float ground_y, float ground_z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[52]; - _mav_put_uint64_t(buf, 0, timestamp); - _mav_put_uint32_t(buf, 8, seq); - _mav_put_float(buf, 12, roll); - _mav_put_float(buf, 16, pitch); - _mav_put_float(buf, 20, yaw); - _mav_put_float(buf, 24, local_z); - _mav_put_float(buf, 28, lat); - _mav_put_float(buf, 32, lon); - _mav_put_float(buf, 36, alt); - _mav_put_float(buf, 40, ground_x); - _mav_put_float(buf, 44, ground_y); - _mav_put_float(buf, 48, ground_z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_IMAGE_TRIGGERED, buf, 52); -#else - mavlink_image_triggered_t packet; - packet.timestamp = timestamp; - packet.seq = seq; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.local_z = local_z; - packet.lat = lat; - packet.lon = lon; - packet.alt = alt; - packet.ground_x = ground_x; - packet.ground_y = ground_y; - packet.ground_z = ground_z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_IMAGE_TRIGGERED, (const char *)&packet, 52); -#endif -} - -#endif - -// MESSAGE IMAGE_TRIGGERED UNPACKING - - -/** - * @brief Get field timestamp from image_triggered message - * - * @return Timestamp - */ -static inline uint64_t mavlink_msg_image_triggered_get_timestamp(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field seq from image_triggered message - * - * @return IMU seq - */ -static inline uint32_t mavlink_msg_image_triggered_get_seq(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 8); -} - -/** - * @brief Get field roll from image_triggered message - * - * @return Roll angle in rad - */ -static inline float mavlink_msg_image_triggered_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field pitch from image_triggered message - * - * @return Pitch angle in rad - */ -static inline float mavlink_msg_image_triggered_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field yaw from image_triggered message - * - * @return Yaw angle in rad - */ -static inline float mavlink_msg_image_triggered_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field local_z from image_triggered message - * - * @return Local frame Z coordinate (height over ground) - */ -static inline float mavlink_msg_image_triggered_get_local_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field lat from image_triggered message - * - * @return GPS X coordinate - */ -static inline float mavlink_msg_image_triggered_get_lat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Get field lon from image_triggered message - * - * @return GPS Y coordinate - */ -static inline float mavlink_msg_image_triggered_get_lon(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 32); -} - -/** - * @brief Get field alt from image_triggered message - * - * @return Global frame altitude - */ -static inline float mavlink_msg_image_triggered_get_alt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 36); -} - -/** - * @brief Get field ground_x from image_triggered message - * - * @return Ground truth X - */ -static inline float mavlink_msg_image_triggered_get_ground_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 40); -} - -/** - * @brief Get field ground_y from image_triggered message - * - * @return Ground truth Y - */ -static inline float mavlink_msg_image_triggered_get_ground_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 44); -} - -/** - * @brief Get field ground_z from image_triggered message - * - * @return Ground truth Z - */ -static inline float mavlink_msg_image_triggered_get_ground_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 48); -} - -/** - * @brief Decode a image_triggered message into a struct - * - * @param msg The message to decode - * @param image_triggered C-struct to decode the message contents into - */ -static inline void mavlink_msg_image_triggered_decode(const mavlink_message_t* msg, mavlink_image_triggered_t* image_triggered) -{ -#if MAVLINK_NEED_BYTE_SWAP - image_triggered->timestamp = mavlink_msg_image_triggered_get_timestamp(msg); - image_triggered->seq = mavlink_msg_image_triggered_get_seq(msg); - image_triggered->roll = mavlink_msg_image_triggered_get_roll(msg); - image_triggered->pitch = mavlink_msg_image_triggered_get_pitch(msg); - image_triggered->yaw = mavlink_msg_image_triggered_get_yaw(msg); - image_triggered->local_z = mavlink_msg_image_triggered_get_local_z(msg); - image_triggered->lat = mavlink_msg_image_triggered_get_lat(msg); - image_triggered->lon = mavlink_msg_image_triggered_get_lon(msg); - image_triggered->alt = mavlink_msg_image_triggered_get_alt(msg); - image_triggered->ground_x = mavlink_msg_image_triggered_get_ground_x(msg); - image_triggered->ground_y = mavlink_msg_image_triggered_get_ground_y(msg); - image_triggered->ground_z = mavlink_msg_image_triggered_get_ground_z(msg); -#else - memcpy(image_triggered, _MAV_PAYLOAD(msg), 52); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_marker.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_marker.h deleted file mode 100644 index f5d20dd045..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_marker.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE MARKER PACKING - -#define MAVLINK_MSG_ID_MARKER 171 - -typedef struct __mavlink_marker_t -{ - uint16_t id; ///< ID - float x; ///< x position - float y; ///< y position - float z; ///< z position - float roll; ///< roll orientation - float pitch; ///< pitch orientation - float yaw; ///< yaw orientation -} mavlink_marker_t; - -#define MAVLINK_MSG_ID_MARKER_LEN 26 -#define MAVLINK_MSG_ID_171_LEN 26 - - - -#define MAVLINK_MESSAGE_INFO_MARKER { \ - "MARKER", \ - 7, \ - { { "id", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_marker_t, id) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 2, offsetof(mavlink_marker_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_marker_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_marker_t, z) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_marker_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 18, offsetof(mavlink_marker_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 22, offsetof(mavlink_marker_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a marker message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param id ID - * @param x x position - * @param y y position - * @param z z position - * @param roll roll orientation - * @param pitch pitch orientation - * @param yaw yaw orientation - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_marker_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t id, float x, float y, float z, float roll, float pitch, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint16_t(buf, 0, id); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, roll); - _mav_put_float(buf, 18, pitch); - _mav_put_float(buf, 22, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_marker_t packet; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_MARKER; - return mavlink_finalize_message(msg, system_id, component_id, 26); -} - -/** - * @brief Pack a marker message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param id ID - * @param x x position - * @param y y position - * @param z z position - * @param roll roll orientation - * @param pitch pitch orientation - * @param yaw yaw orientation - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_marker_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t id,float x,float y,float z,float roll,float pitch,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint16_t(buf, 0, id); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, roll); - _mav_put_float(buf, 18, pitch); - _mav_put_float(buf, 22, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 26); -#else - mavlink_marker_t packet; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 26); -#endif - - msg->msgid = MAVLINK_MSG_ID_MARKER; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 26); -} - -/** - * @brief Encode a marker struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param marker C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_marker_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_marker_t* marker) -{ - return mavlink_msg_marker_pack(system_id, component_id, msg, marker->id, marker->x, marker->y, marker->z, marker->roll, marker->pitch, marker->yaw); -} - -/** - * @brief Send a marker message - * @param chan MAVLink channel to send the message - * - * @param id ID - * @param x x position - * @param y y position - * @param z z position - * @param roll roll orientation - * @param pitch pitch orientation - * @param yaw yaw orientation - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_marker_send(mavlink_channel_t chan, uint16_t id, float x, float y, float z, float roll, float pitch, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[26]; - _mav_put_uint16_t(buf, 0, id); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, roll); - _mav_put_float(buf, 18, pitch); - _mav_put_float(buf, 22, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MARKER, buf, 26); -#else - mavlink_marker_t packet; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MARKER, (const char *)&packet, 26); -#endif -} - -#endif - -// MESSAGE MARKER UNPACKING - - -/** - * @brief Get field id from marker message - * - * @return ID - */ -static inline uint16_t mavlink_msg_marker_get_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field x from marker message - * - * @return x position - */ -static inline float mavlink_msg_marker_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 2); -} - -/** - * @brief Get field y from marker message - * - * @return y position - */ -static inline float mavlink_msg_marker_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field z from marker message - * - * @return z position - */ -static inline float mavlink_msg_marker_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Get field roll from marker message - * - * @return roll orientation - */ -static inline float mavlink_msg_marker_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Get field pitch from marker message - * - * @return pitch orientation - */ -static inline float mavlink_msg_marker_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 18); -} - -/** - * @brief Get field yaw from marker message - * - * @return yaw orientation - */ -static inline float mavlink_msg_marker_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 22); -} - -/** - * @brief Decode a marker message into a struct - * - * @param msg The message to decode - * @param marker C-struct to decode the message contents into - */ -static inline void mavlink_msg_marker_decode(const mavlink_message_t* msg, mavlink_marker_t* marker) -{ -#if MAVLINK_NEED_BYTE_SWAP - marker->id = mavlink_msg_marker_get_id(msg); - marker->x = mavlink_msg_marker_get_x(msg); - marker->y = mavlink_msg_marker_get_y(msg); - marker->z = mavlink_msg_marker_get_z(msg); - marker->roll = mavlink_msg_marker_get_roll(msg); - marker->pitch = mavlink_msg_marker_get_pitch(msg); - marker->yaw = mavlink_msg_marker_get_yaw(msg); -#else - memcpy(marker, _MAV_PAYLOAD(msg), 26); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_pattern_detected.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_pattern_detected.h deleted file mode 100644 index a5aabe9f9c..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_pattern_detected.h +++ /dev/null @@ -1,204 +0,0 @@ -// MESSAGE PATTERN_DETECTED PACKING - -#define MAVLINK_MSG_ID_PATTERN_DETECTED 190 - -typedef struct __mavlink_pattern_detected_t -{ - uint8_t type; ///< 0: Pattern, 1: Letter - float confidence; ///< Confidence of detection - char file[100]; ///< Pattern file name - uint8_t detected; ///< Accepted as true detection, 0 no, 1 yes -} mavlink_pattern_detected_t; - -#define MAVLINK_MSG_ID_PATTERN_DETECTED_LEN 106 -#define MAVLINK_MSG_ID_190_LEN 106 - -#define MAVLINK_MSG_PATTERN_DETECTED_FIELD_FILE_LEN 100 - -#define MAVLINK_MESSAGE_INFO_PATTERN_DETECTED { \ - "PATTERN_DETECTED", \ - 4, \ - { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_pattern_detected_t, type) }, \ - { "confidence", NULL, MAVLINK_TYPE_FLOAT, 0, 1, offsetof(mavlink_pattern_detected_t, confidence) }, \ - { "file", NULL, MAVLINK_TYPE_CHAR, 100, 5, offsetof(mavlink_pattern_detected_t, file) }, \ - { "detected", NULL, MAVLINK_TYPE_UINT8_T, 0, 105, offsetof(mavlink_pattern_detected_t, detected) }, \ - } \ -} - - -/** - * @brief Pack a pattern_detected message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type 0: Pattern, 1: Letter - * @param confidence Confidence of detection - * @param file Pattern file name - * @param detected Accepted as true detection, 0 no, 1 yes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_pattern_detected_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, float confidence, const char *file, uint8_t detected) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[106]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_float(buf, 1, confidence); - _mav_put_uint8_t(buf, 105, detected); - _mav_put_char_array(buf, 5, file, 100); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 106); -#else - mavlink_pattern_detected_t packet; - packet.type = type; - packet.confidence = confidence; - packet.detected = detected; - mav_array_memcpy(packet.file, file, sizeof(char)*100); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 106); -#endif - - msg->msgid = MAVLINK_MSG_ID_PATTERN_DETECTED; - return mavlink_finalize_message(msg, system_id, component_id, 106); -} - -/** - * @brief Pack a pattern_detected message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type 0: Pattern, 1: Letter - * @param confidence Confidence of detection - * @param file Pattern file name - * @param detected Accepted as true detection, 0 no, 1 yes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_pattern_detected_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,float confidence,const char *file,uint8_t detected) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[106]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_float(buf, 1, confidence); - _mav_put_uint8_t(buf, 105, detected); - _mav_put_char_array(buf, 5, file, 100); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 106); -#else - mavlink_pattern_detected_t packet; - packet.type = type; - packet.confidence = confidence; - packet.detected = detected; - mav_array_memcpy(packet.file, file, sizeof(char)*100); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 106); -#endif - - msg->msgid = MAVLINK_MSG_ID_PATTERN_DETECTED; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 106); -} - -/** - * @brief Encode a pattern_detected struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param pattern_detected C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_pattern_detected_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_pattern_detected_t* pattern_detected) -{ - return mavlink_msg_pattern_detected_pack(system_id, component_id, msg, pattern_detected->type, pattern_detected->confidence, pattern_detected->file, pattern_detected->detected); -} - -/** - * @brief Send a pattern_detected message - * @param chan MAVLink channel to send the message - * - * @param type 0: Pattern, 1: Letter - * @param confidence Confidence of detection - * @param file Pattern file name - * @param detected Accepted as true detection, 0 no, 1 yes - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_pattern_detected_send(mavlink_channel_t chan, uint8_t type, float confidence, const char *file, uint8_t detected) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[106]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_float(buf, 1, confidence); - _mav_put_uint8_t(buf, 105, detected); - _mav_put_char_array(buf, 5, file, 100); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PATTERN_DETECTED, buf, 106); -#else - mavlink_pattern_detected_t packet; - packet.type = type; - packet.confidence = confidence; - packet.detected = detected; - mav_array_memcpy(packet.file, file, sizeof(char)*100); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PATTERN_DETECTED, (const char *)&packet, 106); -#endif -} - -#endif - -// MESSAGE PATTERN_DETECTED UNPACKING - - -/** - * @brief Get field type from pattern_detected message - * - * @return 0: Pattern, 1: Letter - */ -static inline uint8_t mavlink_msg_pattern_detected_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field confidence from pattern_detected message - * - * @return Confidence of detection - */ -static inline float mavlink_msg_pattern_detected_get_confidence(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 1); -} - -/** - * @brief Get field file from pattern_detected message - * - * @return Pattern file name - */ -static inline uint16_t mavlink_msg_pattern_detected_get_file(const mavlink_message_t* msg, char *file) -{ - return _MAV_RETURN_char_array(msg, file, 100, 5); -} - -/** - * @brief Get field detected from pattern_detected message - * - * @return Accepted as true detection, 0 no, 1 yes - */ -static inline uint8_t mavlink_msg_pattern_detected_get_detected(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 105); -} - -/** - * @brief Decode a pattern_detected message into a struct - * - * @param msg The message to decode - * @param pattern_detected C-struct to decode the message contents into - */ -static inline void mavlink_msg_pattern_detected_decode(const mavlink_message_t* msg, mavlink_pattern_detected_t* pattern_detected) -{ -#if MAVLINK_NEED_BYTE_SWAP - pattern_detected->type = mavlink_msg_pattern_detected_get_type(msg); - pattern_detected->confidence = mavlink_msg_pattern_detected_get_confidence(msg); - mavlink_msg_pattern_detected_get_file(msg, pattern_detected->file); - pattern_detected->detected = mavlink_msg_pattern_detected_get_detected(msg); -#else - memcpy(pattern_detected, _MAV_PAYLOAD(msg), 106); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_point_of_interest.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_point_of_interest.h deleted file mode 100644 index 008ed436ed..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_point_of_interest.h +++ /dev/null @@ -1,292 +0,0 @@ -// MESSAGE POINT_OF_INTEREST PACKING - -#define MAVLINK_MSG_ID_POINT_OF_INTEREST 191 - -typedef struct __mavlink_point_of_interest_t -{ - uint8_t type; ///< 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - uint8_t color; ///< 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - uint8_t coordinate_system; ///< 0: global, 1:local - uint16_t timeout; ///< 0: no timeout, >1: timeout in seconds - float x; ///< X Position - float y; ///< Y Position - float z; ///< Z Position - char name[26]; ///< POI name -} mavlink_point_of_interest_t; - -#define MAVLINK_MSG_ID_POINT_OF_INTEREST_LEN 43 -#define MAVLINK_MSG_ID_191_LEN 43 - -#define MAVLINK_MSG_POINT_OF_INTEREST_FIELD_NAME_LEN 26 - -#define MAVLINK_MESSAGE_INFO_POINT_OF_INTEREST { \ - "POINT_OF_INTEREST", \ - 8, \ - { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_point_of_interest_t, type) }, \ - { "color", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_point_of_interest_t, color) }, \ - { "coordinate_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_point_of_interest_t, coordinate_system) }, \ - { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_point_of_interest_t, timeout) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 5, offsetof(mavlink_point_of_interest_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_point_of_interest_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 13, offsetof(mavlink_point_of_interest_t, z) }, \ - { "name", NULL, MAVLINK_TYPE_CHAR, 26, 17, offsetof(mavlink_point_of_interest_t, name) }, \ - } \ -} - - -/** - * @brief Pack a point_of_interest message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - * @param color 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - * @param coordinate_system 0: global, 1:local - * @param timeout 0: no timeout, >1: timeout in seconds - * @param x X Position - * @param y Y Position - * @param z Z Position - * @param name POI name - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_point_of_interest_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, uint8_t color, uint8_t coordinate_system, uint16_t timeout, float x, float y, float z, const char *name) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[43]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, color); - _mav_put_uint8_t(buf, 2, coordinate_system); - _mav_put_uint16_t(buf, 3, timeout); - _mav_put_float(buf, 5, x); - _mav_put_float(buf, 9, y); - _mav_put_float(buf, 13, z); - _mav_put_char_array(buf, 17, name, 26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 43); -#else - mavlink_point_of_interest_t packet; - packet.type = type; - packet.color = color; - packet.coordinate_system = coordinate_system; - packet.timeout = timeout; - packet.x = x; - packet.y = y; - packet.z = z; - mav_array_memcpy(packet.name, name, sizeof(char)*26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 43); -#endif - - msg->msgid = MAVLINK_MSG_ID_POINT_OF_INTEREST; - return mavlink_finalize_message(msg, system_id, component_id, 43); -} - -/** - * @brief Pack a point_of_interest message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - * @param color 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - * @param coordinate_system 0: global, 1:local - * @param timeout 0: no timeout, >1: timeout in seconds - * @param x X Position - * @param y Y Position - * @param z Z Position - * @param name POI name - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_point_of_interest_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,uint8_t color,uint8_t coordinate_system,uint16_t timeout,float x,float y,float z,const char *name) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[43]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, color); - _mav_put_uint8_t(buf, 2, coordinate_system); - _mav_put_uint16_t(buf, 3, timeout); - _mav_put_float(buf, 5, x); - _mav_put_float(buf, 9, y); - _mav_put_float(buf, 13, z); - _mav_put_char_array(buf, 17, name, 26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 43); -#else - mavlink_point_of_interest_t packet; - packet.type = type; - packet.color = color; - packet.coordinate_system = coordinate_system; - packet.timeout = timeout; - packet.x = x; - packet.y = y; - packet.z = z; - mav_array_memcpy(packet.name, name, sizeof(char)*26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 43); -#endif - - msg->msgid = MAVLINK_MSG_ID_POINT_OF_INTEREST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 43); -} - -/** - * @brief Encode a point_of_interest struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param point_of_interest C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_point_of_interest_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_point_of_interest_t* point_of_interest) -{ - return mavlink_msg_point_of_interest_pack(system_id, component_id, msg, point_of_interest->type, point_of_interest->color, point_of_interest->coordinate_system, point_of_interest->timeout, point_of_interest->x, point_of_interest->y, point_of_interest->z, point_of_interest->name); -} - -/** - * @brief Send a point_of_interest message - * @param chan MAVLink channel to send the message - * - * @param type 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - * @param color 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - * @param coordinate_system 0: global, 1:local - * @param timeout 0: no timeout, >1: timeout in seconds - * @param x X Position - * @param y Y Position - * @param z Z Position - * @param name POI name - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_point_of_interest_send(mavlink_channel_t chan, uint8_t type, uint8_t color, uint8_t coordinate_system, uint16_t timeout, float x, float y, float z, const char *name) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[43]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, color); - _mav_put_uint8_t(buf, 2, coordinate_system); - _mav_put_uint16_t(buf, 3, timeout); - _mav_put_float(buf, 5, x); - _mav_put_float(buf, 9, y); - _mav_put_float(buf, 13, z); - _mav_put_char_array(buf, 17, name, 26); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POINT_OF_INTEREST, buf, 43); -#else - mavlink_point_of_interest_t packet; - packet.type = type; - packet.color = color; - packet.coordinate_system = coordinate_system; - packet.timeout = timeout; - packet.x = x; - packet.y = y; - packet.z = z; - mav_array_memcpy(packet.name, name, sizeof(char)*26); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POINT_OF_INTEREST, (const char *)&packet, 43); -#endif -} - -#endif - -// MESSAGE POINT_OF_INTEREST UNPACKING - - -/** - * @brief Get field type from point_of_interest message - * - * @return 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - */ -static inline uint8_t mavlink_msg_point_of_interest_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field color from point_of_interest message - * - * @return 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - */ -static inline uint8_t mavlink_msg_point_of_interest_get_color(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field coordinate_system from point_of_interest message - * - * @return 0: global, 1:local - */ -static inline uint8_t mavlink_msg_point_of_interest_get_coordinate_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field timeout from point_of_interest message - * - * @return 0: no timeout, >1: timeout in seconds - */ -static inline uint16_t mavlink_msg_point_of_interest_get_timeout(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field x from point_of_interest message - * - * @return X Position - */ -static inline float mavlink_msg_point_of_interest_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 5); -} - -/** - * @brief Get field y from point_of_interest message - * - * @return Y Position - */ -static inline float mavlink_msg_point_of_interest_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Get field z from point_of_interest message - * - * @return Z Position - */ -static inline float mavlink_msg_point_of_interest_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 13); -} - -/** - * @brief Get field name from point_of_interest message - * - * @return POI name - */ -static inline uint16_t mavlink_msg_point_of_interest_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 26, 17); -} - -/** - * @brief Decode a point_of_interest message into a struct - * - * @param msg The message to decode - * @param point_of_interest C-struct to decode the message contents into - */ -static inline void mavlink_msg_point_of_interest_decode(const mavlink_message_t* msg, mavlink_point_of_interest_t* point_of_interest) -{ -#if MAVLINK_NEED_BYTE_SWAP - point_of_interest->type = mavlink_msg_point_of_interest_get_type(msg); - point_of_interest->color = mavlink_msg_point_of_interest_get_color(msg); - point_of_interest->coordinate_system = mavlink_msg_point_of_interest_get_coordinate_system(msg); - point_of_interest->timeout = mavlink_msg_point_of_interest_get_timeout(msg); - point_of_interest->x = mavlink_msg_point_of_interest_get_x(msg); - point_of_interest->y = mavlink_msg_point_of_interest_get_y(msg); - point_of_interest->z = mavlink_msg_point_of_interest_get_z(msg); - mavlink_msg_point_of_interest_get_name(msg, point_of_interest->name); -#else - memcpy(point_of_interest, _MAV_PAYLOAD(msg), 43); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_point_of_interest_connection.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_point_of_interest_connection.h deleted file mode 100644 index d8de738c79..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_point_of_interest_connection.h +++ /dev/null @@ -1,358 +0,0 @@ -// MESSAGE POINT_OF_INTEREST_CONNECTION PACKING - -#define MAVLINK_MSG_ID_POINT_OF_INTEREST_CONNECTION 192 - -typedef struct __mavlink_point_of_interest_connection_t -{ - uint8_t type; ///< 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - uint8_t color; ///< 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - uint8_t coordinate_system; ///< 0: global, 1:local - uint16_t timeout; ///< 0: no timeout, >1: timeout in seconds - float xp1; ///< X1 Position - float yp1; ///< Y1 Position - float zp1; ///< Z1 Position - float xp2; ///< X2 Position - float yp2; ///< Y2 Position - float zp2; ///< Z2 Position - char name[26]; ///< POI connection name -} mavlink_point_of_interest_connection_t; - -#define MAVLINK_MSG_ID_POINT_OF_INTEREST_CONNECTION_LEN 55 -#define MAVLINK_MSG_ID_192_LEN 55 - -#define MAVLINK_MSG_POINT_OF_INTEREST_CONNECTION_FIELD_NAME_LEN 26 - -#define MAVLINK_MESSAGE_INFO_POINT_OF_INTEREST_CONNECTION { \ - "POINT_OF_INTEREST_CONNECTION", \ - 11, \ - { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_point_of_interest_connection_t, type) }, \ - { "color", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_point_of_interest_connection_t, color) }, \ - { "coordinate_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_point_of_interest_connection_t, coordinate_system) }, \ - { "timeout", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_point_of_interest_connection_t, timeout) }, \ - { "xp1", NULL, MAVLINK_TYPE_FLOAT, 0, 5, offsetof(mavlink_point_of_interest_connection_t, xp1) }, \ - { "yp1", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_point_of_interest_connection_t, yp1) }, \ - { "zp1", NULL, MAVLINK_TYPE_FLOAT, 0, 13, offsetof(mavlink_point_of_interest_connection_t, zp1) }, \ - { "xp2", NULL, MAVLINK_TYPE_FLOAT, 0, 17, offsetof(mavlink_point_of_interest_connection_t, xp2) }, \ - { "yp2", NULL, MAVLINK_TYPE_FLOAT, 0, 21, offsetof(mavlink_point_of_interest_connection_t, yp2) }, \ - { "zp2", NULL, MAVLINK_TYPE_FLOAT, 0, 25, offsetof(mavlink_point_of_interest_connection_t, zp2) }, \ - { "name", NULL, MAVLINK_TYPE_CHAR, 26, 29, offsetof(mavlink_point_of_interest_connection_t, name) }, \ - } \ -} - - -/** - * @brief Pack a point_of_interest_connection message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - * @param color 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - * @param coordinate_system 0: global, 1:local - * @param timeout 0: no timeout, >1: timeout in seconds - * @param xp1 X1 Position - * @param yp1 Y1 Position - * @param zp1 Z1 Position - * @param xp2 X2 Position - * @param yp2 Y2 Position - * @param zp2 Z2 Position - * @param name POI connection name - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_point_of_interest_connection_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, uint8_t color, uint8_t coordinate_system, uint16_t timeout, float xp1, float yp1, float zp1, float xp2, float yp2, float zp2, const char *name) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[55]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, color); - _mav_put_uint8_t(buf, 2, coordinate_system); - _mav_put_uint16_t(buf, 3, timeout); - _mav_put_float(buf, 5, xp1); - _mav_put_float(buf, 9, yp1); - _mav_put_float(buf, 13, zp1); - _mav_put_float(buf, 17, xp2); - _mav_put_float(buf, 21, yp2); - _mav_put_float(buf, 25, zp2); - _mav_put_char_array(buf, 29, name, 26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 55); -#else - mavlink_point_of_interest_connection_t packet; - packet.type = type; - packet.color = color; - packet.coordinate_system = coordinate_system; - packet.timeout = timeout; - packet.xp1 = xp1; - packet.yp1 = yp1; - packet.zp1 = zp1; - packet.xp2 = xp2; - packet.yp2 = yp2; - packet.zp2 = zp2; - mav_array_memcpy(packet.name, name, sizeof(char)*26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 55); -#endif - - msg->msgid = MAVLINK_MSG_ID_POINT_OF_INTEREST_CONNECTION; - return mavlink_finalize_message(msg, system_id, component_id, 55); -} - -/** - * @brief Pack a point_of_interest_connection message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - * @param color 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - * @param coordinate_system 0: global, 1:local - * @param timeout 0: no timeout, >1: timeout in seconds - * @param xp1 X1 Position - * @param yp1 Y1 Position - * @param zp1 Z1 Position - * @param xp2 X2 Position - * @param yp2 Y2 Position - * @param zp2 Z2 Position - * @param name POI connection name - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_point_of_interest_connection_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,uint8_t color,uint8_t coordinate_system,uint16_t timeout,float xp1,float yp1,float zp1,float xp2,float yp2,float zp2,const char *name) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[55]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, color); - _mav_put_uint8_t(buf, 2, coordinate_system); - _mav_put_uint16_t(buf, 3, timeout); - _mav_put_float(buf, 5, xp1); - _mav_put_float(buf, 9, yp1); - _mav_put_float(buf, 13, zp1); - _mav_put_float(buf, 17, xp2); - _mav_put_float(buf, 21, yp2); - _mav_put_float(buf, 25, zp2); - _mav_put_char_array(buf, 29, name, 26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 55); -#else - mavlink_point_of_interest_connection_t packet; - packet.type = type; - packet.color = color; - packet.coordinate_system = coordinate_system; - packet.timeout = timeout; - packet.xp1 = xp1; - packet.yp1 = yp1; - packet.zp1 = zp1; - packet.xp2 = xp2; - packet.yp2 = yp2; - packet.zp2 = zp2; - mav_array_memcpy(packet.name, name, sizeof(char)*26); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 55); -#endif - - msg->msgid = MAVLINK_MSG_ID_POINT_OF_INTEREST_CONNECTION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 55); -} - -/** - * @brief Encode a point_of_interest_connection struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param point_of_interest_connection C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_point_of_interest_connection_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_point_of_interest_connection_t* point_of_interest_connection) -{ - return mavlink_msg_point_of_interest_connection_pack(system_id, component_id, msg, point_of_interest_connection->type, point_of_interest_connection->color, point_of_interest_connection->coordinate_system, point_of_interest_connection->timeout, point_of_interest_connection->xp1, point_of_interest_connection->yp1, point_of_interest_connection->zp1, point_of_interest_connection->xp2, point_of_interest_connection->yp2, point_of_interest_connection->zp2, point_of_interest_connection->name); -} - -/** - * @brief Send a point_of_interest_connection message - * @param chan MAVLink channel to send the message - * - * @param type 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - * @param color 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - * @param coordinate_system 0: global, 1:local - * @param timeout 0: no timeout, >1: timeout in seconds - * @param xp1 X1 Position - * @param yp1 Y1 Position - * @param zp1 Z1 Position - * @param xp2 X2 Position - * @param yp2 Y2 Position - * @param zp2 Z2 Position - * @param name POI connection name - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_point_of_interest_connection_send(mavlink_channel_t chan, uint8_t type, uint8_t color, uint8_t coordinate_system, uint16_t timeout, float xp1, float yp1, float zp1, float xp2, float yp2, float zp2, const char *name) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[55]; - _mav_put_uint8_t(buf, 0, type); - _mav_put_uint8_t(buf, 1, color); - _mav_put_uint8_t(buf, 2, coordinate_system); - _mav_put_uint16_t(buf, 3, timeout); - _mav_put_float(buf, 5, xp1); - _mav_put_float(buf, 9, yp1); - _mav_put_float(buf, 13, zp1); - _mav_put_float(buf, 17, xp2); - _mav_put_float(buf, 21, yp2); - _mav_put_float(buf, 25, zp2); - _mav_put_char_array(buf, 29, name, 26); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POINT_OF_INTEREST_CONNECTION, buf, 55); -#else - mavlink_point_of_interest_connection_t packet; - packet.type = type; - packet.color = color; - packet.coordinate_system = coordinate_system; - packet.timeout = timeout; - packet.xp1 = xp1; - packet.yp1 = yp1; - packet.zp1 = zp1; - packet.xp2 = xp2; - packet.yp2 = yp2; - packet.zp2 = zp2; - mav_array_memcpy(packet.name, name, sizeof(char)*26); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POINT_OF_INTEREST_CONNECTION, (const char *)&packet, 55); -#endif -} - -#endif - -// MESSAGE POINT_OF_INTEREST_CONNECTION UNPACKING - - -/** - * @brief Get field type from point_of_interest_connection message - * - * @return 0: Notice, 1: Warning, 2: Critical, 3: Emergency, 4: Debug - */ -static inline uint8_t mavlink_msg_point_of_interest_connection_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field color from point_of_interest_connection message - * - * @return 0: blue, 1: yellow, 2: red, 3: orange, 4: green, 5: magenta - */ -static inline uint8_t mavlink_msg_point_of_interest_connection_get_color(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field coordinate_system from point_of_interest_connection message - * - * @return 0: global, 1:local - */ -static inline uint8_t mavlink_msg_point_of_interest_connection_get_coordinate_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field timeout from point_of_interest_connection message - * - * @return 0: no timeout, >1: timeout in seconds - */ -static inline uint16_t mavlink_msg_point_of_interest_connection_get_timeout(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field xp1 from point_of_interest_connection message - * - * @return X1 Position - */ -static inline float mavlink_msg_point_of_interest_connection_get_xp1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 5); -} - -/** - * @brief Get field yp1 from point_of_interest_connection message - * - * @return Y1 Position - */ -static inline float mavlink_msg_point_of_interest_connection_get_yp1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Get field zp1 from point_of_interest_connection message - * - * @return Z1 Position - */ -static inline float mavlink_msg_point_of_interest_connection_get_zp1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 13); -} - -/** - * @brief Get field xp2 from point_of_interest_connection message - * - * @return X2 Position - */ -static inline float mavlink_msg_point_of_interest_connection_get_xp2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 17); -} - -/** - * @brief Get field yp2 from point_of_interest_connection message - * - * @return Y2 Position - */ -static inline float mavlink_msg_point_of_interest_connection_get_yp2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 21); -} - -/** - * @brief Get field zp2 from point_of_interest_connection message - * - * @return Z2 Position - */ -static inline float mavlink_msg_point_of_interest_connection_get_zp2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 25); -} - -/** - * @brief Get field name from point_of_interest_connection message - * - * @return POI connection name - */ -static inline uint16_t mavlink_msg_point_of_interest_connection_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 26, 29); -} - -/** - * @brief Decode a point_of_interest_connection message into a struct - * - * @param msg The message to decode - * @param point_of_interest_connection C-struct to decode the message contents into - */ -static inline void mavlink_msg_point_of_interest_connection_decode(const mavlink_message_t* msg, mavlink_point_of_interest_connection_t* point_of_interest_connection) -{ -#if MAVLINK_NEED_BYTE_SWAP - point_of_interest_connection->type = mavlink_msg_point_of_interest_connection_get_type(msg); - point_of_interest_connection->color = mavlink_msg_point_of_interest_connection_get_color(msg); - point_of_interest_connection->coordinate_system = mavlink_msg_point_of_interest_connection_get_coordinate_system(msg); - point_of_interest_connection->timeout = mavlink_msg_point_of_interest_connection_get_timeout(msg); - point_of_interest_connection->xp1 = mavlink_msg_point_of_interest_connection_get_xp1(msg); - point_of_interest_connection->yp1 = mavlink_msg_point_of_interest_connection_get_yp1(msg); - point_of_interest_connection->zp1 = mavlink_msg_point_of_interest_connection_get_zp1(msg); - point_of_interest_connection->xp2 = mavlink_msg_point_of_interest_connection_get_xp2(msg); - point_of_interest_connection->yp2 = mavlink_msg_point_of_interest_connection_get_yp2(msg); - point_of_interest_connection->zp2 = mavlink_msg_point_of_interest_connection_get_zp2(msg); - mavlink_msg_point_of_interest_connection_get_name(msg, point_of_interest_connection->name); -#else - memcpy(point_of_interest_connection, _MAV_PAYLOAD(msg), 55); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_offset_set.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_offset_set.h deleted file mode 100644 index 1591b6abea..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_offset_set.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE POSITION_CONTROL_OFFSET_SET PACKING - -#define MAVLINK_MSG_ID_POSITION_CONTROL_OFFSET_SET 160 - -typedef struct __mavlink_position_control_offset_set_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - float x; ///< x position offset - float y; ///< y position offset - float z; ///< z position offset - float yaw; ///< yaw orientation offset in radians, 0 = NORTH -} mavlink_position_control_offset_set_t; - -#define MAVLINK_MSG_ID_POSITION_CONTROL_OFFSET_SET_LEN 18 -#define MAVLINK_MSG_ID_160_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_POSITION_CONTROL_OFFSET_SET { \ - "POSITION_CONTROL_OFFSET_SET", \ - 6, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_position_control_offset_set_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_position_control_offset_set_t, target_component) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 2, offsetof(mavlink_position_control_offset_set_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_position_control_offset_set_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_position_control_offset_set_t, z) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_position_control_offset_set_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a position_control_offset_set message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param x x position offset - * @param y y position offset - * @param z z position offset - * @param yaw yaw orientation offset in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_control_offset_set_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_position_control_offset_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_CONTROL_OFFSET_SET; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a position_control_offset_set message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param x x position offset - * @param y y position offset - * @param z z position offset - * @param yaw yaw orientation offset in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_control_offset_set_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,float x,float y,float z,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_position_control_offset_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_CONTROL_OFFSET_SET; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a position_control_offset_set struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param position_control_offset_set C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_position_control_offset_set_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_position_control_offset_set_t* position_control_offset_set) -{ - return mavlink_msg_position_control_offset_set_pack(system_id, component_id, msg, position_control_offset_set->target_system, position_control_offset_set->target_component, position_control_offset_set->x, position_control_offset_set->y, position_control_offset_set->z, position_control_offset_set->yaw); -} - -/** - * @brief Send a position_control_offset_set message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param x x position offset - * @param y y position offset - * @param z z position offset - * @param yaw yaw orientation offset in radians, 0 = NORTH - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_position_control_offset_set_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_CONTROL_OFFSET_SET, buf, 18); -#else - mavlink_position_control_offset_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_CONTROL_OFFSET_SET, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE POSITION_CONTROL_OFFSET_SET UNPACKING - - -/** - * @brief Get field target_system from position_control_offset_set message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_position_control_offset_set_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from position_control_offset_set message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_position_control_offset_set_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field x from position_control_offset_set message - * - * @return x position offset - */ -static inline float mavlink_msg_position_control_offset_set_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 2); -} - -/** - * @brief Get field y from position_control_offset_set message - * - * @return y position offset - */ -static inline float mavlink_msg_position_control_offset_set_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field z from position_control_offset_set message - * - * @return z position offset - */ -static inline float mavlink_msg_position_control_offset_set_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Get field yaw from position_control_offset_set message - * - * @return yaw orientation offset in radians, 0 = NORTH - */ -static inline float mavlink_msg_position_control_offset_set_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Decode a position_control_offset_set message into a struct - * - * @param msg The message to decode - * @param position_control_offset_set C-struct to decode the message contents into - */ -static inline void mavlink_msg_position_control_offset_set_decode(const mavlink_message_t* msg, mavlink_position_control_offset_set_t* position_control_offset_set) -{ -#if MAVLINK_NEED_BYTE_SWAP - position_control_offset_set->target_system = mavlink_msg_position_control_offset_set_get_target_system(msg); - position_control_offset_set->target_component = mavlink_msg_position_control_offset_set_get_target_component(msg); - position_control_offset_set->x = mavlink_msg_position_control_offset_set_get_x(msg); - position_control_offset_set->y = mavlink_msg_position_control_offset_set_get_y(msg); - position_control_offset_set->z = mavlink_msg_position_control_offset_set_get_z(msg); - position_control_offset_set->yaw = mavlink_msg_position_control_offset_set_get_yaw(msg); -#else - memcpy(position_control_offset_set, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_setpoint.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_setpoint.h deleted file mode 100644 index 3e13f402d3..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_setpoint.h +++ /dev/null @@ -1,232 +0,0 @@ -// MESSAGE POSITION_CONTROL_SETPOINT PACKING - -#define MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT 170 - -typedef struct __mavlink_position_control_setpoint_t -{ - uint16_t id; ///< ID of waypoint, 0 for plain position - float x; ///< x position - float y; ///< y position - float z; ///< z position - float yaw; ///< yaw orientation in radians, 0 = NORTH -} mavlink_position_control_setpoint_t; - -#define MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_LEN 18 -#define MAVLINK_MSG_ID_170_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_POSITION_CONTROL_SETPOINT { \ - "POSITION_CONTROL_SETPOINT", \ - 5, \ - { { "id", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_position_control_setpoint_t, id) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 2, offsetof(mavlink_position_control_setpoint_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 6, offsetof(mavlink_position_control_setpoint_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 10, offsetof(mavlink_position_control_setpoint_t, z) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_position_control_setpoint_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a position_control_setpoint message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param id ID of waypoint, 0 for plain position - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_control_setpoint_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t id, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint16_t(buf, 0, id); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_position_control_setpoint_t packet; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a position_control_setpoint message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param id ID of waypoint, 0 for plain position - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_control_setpoint_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t id,float x,float y,float z,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint16_t(buf, 0, id); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_position_control_setpoint_t packet; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a position_control_setpoint struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param position_control_setpoint C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_position_control_setpoint_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_position_control_setpoint_t* position_control_setpoint) -{ - return mavlink_msg_position_control_setpoint_pack(system_id, component_id, msg, position_control_setpoint->id, position_control_setpoint->x, position_control_setpoint->y, position_control_setpoint->z, position_control_setpoint->yaw); -} - -/** - * @brief Send a position_control_setpoint message - * @param chan MAVLink channel to send the message - * - * @param id ID of waypoint, 0 for plain position - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_position_control_setpoint_send(mavlink_channel_t chan, uint16_t id, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_uint16_t(buf, 0, id); - _mav_put_float(buf, 2, x); - _mav_put_float(buf, 6, y); - _mav_put_float(buf, 10, z); - _mav_put_float(buf, 14, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT, buf, 18); -#else - mavlink_position_control_setpoint_t packet; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE POSITION_CONTROL_SETPOINT UNPACKING - - -/** - * @brief Get field id from position_control_setpoint message - * - * @return ID of waypoint, 0 for plain position - */ -static inline uint16_t mavlink_msg_position_control_setpoint_get_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field x from position_control_setpoint message - * - * @return x position - */ -static inline float mavlink_msg_position_control_setpoint_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 2); -} - -/** - * @brief Get field y from position_control_setpoint message - * - * @return y position - */ -static inline float mavlink_msg_position_control_setpoint_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 6); -} - -/** - * @brief Get field z from position_control_setpoint message - * - * @return z position - */ -static inline float mavlink_msg_position_control_setpoint_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 10); -} - -/** - * @brief Get field yaw from position_control_setpoint message - * - * @return yaw orientation in radians, 0 = NORTH - */ -static inline float mavlink_msg_position_control_setpoint_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 14); -} - -/** - * @brief Decode a position_control_setpoint message into a struct - * - * @param msg The message to decode - * @param position_control_setpoint C-struct to decode the message contents into - */ -static inline void mavlink_msg_position_control_setpoint_decode(const mavlink_message_t* msg, mavlink_position_control_setpoint_t* position_control_setpoint) -{ -#if MAVLINK_NEED_BYTE_SWAP - position_control_setpoint->id = mavlink_msg_position_control_setpoint_get_id(msg); - position_control_setpoint->x = mavlink_msg_position_control_setpoint_get_x(msg); - position_control_setpoint->y = mavlink_msg_position_control_setpoint_get_y(msg); - position_control_setpoint->z = mavlink_msg_position_control_setpoint_get_z(msg); - position_control_setpoint->yaw = mavlink_msg_position_control_setpoint_get_yaw(msg); -#else - memcpy(position_control_setpoint, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_setpoint_set.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_setpoint_set.h deleted file mode 100644 index 4a556e57f4..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_position_control_setpoint_set.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE POSITION_CONTROL_SETPOINT_SET PACKING - -#define MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_SET 159 - -typedef struct __mavlink_position_control_setpoint_set_t -{ - uint8_t target_system; ///< System ID - uint8_t target_component; ///< Component ID - uint16_t id; ///< ID of waypoint, 0 for plain position - float x; ///< x position - float y; ///< y position - float z; ///< z position - float yaw; ///< yaw orientation in radians, 0 = NORTH -} mavlink_position_control_setpoint_set_t; - -#define MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_SET_LEN 20 -#define MAVLINK_MSG_ID_159_LEN 20 - - - -#define MAVLINK_MESSAGE_INFO_POSITION_CONTROL_SETPOINT_SET { \ - "POSITION_CONTROL_SETPOINT_SET", \ - 7, \ - { { "target_system", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_position_control_setpoint_set_t, target_system) }, \ - { "target_component", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_position_control_setpoint_set_t, target_component) }, \ - { "id", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_position_control_setpoint_set_t, id) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_position_control_setpoint_set_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_position_control_setpoint_set_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_position_control_setpoint_set_t, z) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_position_control_setpoint_set_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a position_control_setpoint_set message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system System ID - * @param target_component Component ID - * @param id ID of waypoint, 0 for plain position - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_control_setpoint_set_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system, uint8_t target_component, uint16_t id, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, id); - _mav_put_float(buf, 4, x); - _mav_put_float(buf, 8, y); - _mav_put_float(buf, 12, z); - _mav_put_float(buf, 16, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_position_control_setpoint_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_SET; - return mavlink_finalize_message(msg, system_id, component_id, 20); -} - -/** - * @brief Pack a position_control_setpoint_set message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system System ID - * @param target_component Component ID - * @param id ID of waypoint, 0 for plain position - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_position_control_setpoint_set_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system,uint8_t target_component,uint16_t id,float x,float y,float z,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, id); - _mav_put_float(buf, 4, x); - _mav_put_float(buf, 8, y); - _mav_put_float(buf, 12, z); - _mav_put_float(buf, 16, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_position_control_setpoint_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_SET; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 20); -} - -/** - * @brief Encode a position_control_setpoint_set struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param position_control_setpoint_set C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_position_control_setpoint_set_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_position_control_setpoint_set_t* position_control_setpoint_set) -{ - return mavlink_msg_position_control_setpoint_set_pack(system_id, component_id, msg, position_control_setpoint_set->target_system, position_control_setpoint_set->target_component, position_control_setpoint_set->id, position_control_setpoint_set->x, position_control_setpoint_set->y, position_control_setpoint_set->z, position_control_setpoint_set->yaw); -} - -/** - * @brief Send a position_control_setpoint_set message - * @param chan MAVLink channel to send the message - * - * @param target_system System ID - * @param target_component Component ID - * @param id ID of waypoint, 0 for plain position - * @param x x position - * @param y y position - * @param z z position - * @param yaw yaw orientation in radians, 0 = NORTH - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_position_control_setpoint_set_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t id, float x, float y, float z, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint8_t(buf, 0, target_system); - _mav_put_uint8_t(buf, 1, target_component); - _mav_put_uint16_t(buf, 2, id); - _mav_put_float(buf, 4, x); - _mav_put_float(buf, 8, y); - _mav_put_float(buf, 12, z); - _mav_put_float(buf, 16, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_SET, buf, 20); -#else - mavlink_position_control_setpoint_set_t packet; - packet.target_system = target_system; - packet.target_component = target_component; - packet.id = id; - packet.x = x; - packet.y = y; - packet.z = z; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_POSITION_CONTROL_SETPOINT_SET, (const char *)&packet, 20); -#endif -} - -#endif - -// MESSAGE POSITION_CONTROL_SETPOINT_SET UNPACKING - - -/** - * @brief Get field target_system from position_control_setpoint_set message - * - * @return System ID - */ -static inline uint8_t mavlink_msg_position_control_setpoint_set_get_target_system(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field target_component from position_control_setpoint_set message - * - * @return Component ID - */ -static inline uint8_t mavlink_msg_position_control_setpoint_set_get_target_component(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field id from position_control_setpoint_set message - * - * @return ID of waypoint, 0 for plain position - */ -static inline uint16_t mavlink_msg_position_control_setpoint_set_get_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field x from position_control_setpoint_set message - * - * @return x position - */ -static inline float mavlink_msg_position_control_setpoint_set_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field y from position_control_setpoint_set message - * - * @return y position - */ -static inline float mavlink_msg_position_control_setpoint_set_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field z from position_control_setpoint_set message - * - * @return z position - */ -static inline float mavlink_msg_position_control_setpoint_set_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field yaw from position_control_setpoint_set message - * - * @return yaw orientation in radians, 0 = NORTH - */ -static inline float mavlink_msg_position_control_setpoint_set_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Decode a position_control_setpoint_set message into a struct - * - * @param msg The message to decode - * @param position_control_setpoint_set C-struct to decode the message contents into - */ -static inline void mavlink_msg_position_control_setpoint_set_decode(const mavlink_message_t* msg, mavlink_position_control_setpoint_set_t* position_control_setpoint_set) -{ -#if MAVLINK_NEED_BYTE_SWAP - position_control_setpoint_set->target_system = mavlink_msg_position_control_setpoint_set_get_target_system(msg); - position_control_setpoint_set->target_component = mavlink_msg_position_control_setpoint_set_get_target_component(msg); - position_control_setpoint_set->id = mavlink_msg_position_control_setpoint_set_get_id(msg); - position_control_setpoint_set->x = mavlink_msg_position_control_setpoint_set_get_x(msg); - position_control_setpoint_set->y = mavlink_msg_position_control_setpoint_set_get_y(msg); - position_control_setpoint_set->z = mavlink_msg_position_control_setpoint_set_get_z(msg); - position_control_setpoint_set->yaw = mavlink_msg_position_control_setpoint_set_get_yaw(msg); -#else - memcpy(position_control_setpoint_set, _MAV_PAYLOAD(msg), 20); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_raw_aux.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_raw_aux.h deleted file mode 100644 index 154653de2d..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_raw_aux.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE RAW_AUX PACKING - -#define MAVLINK_MSG_ID_RAW_AUX 172 - -typedef struct __mavlink_raw_aux_t -{ - uint16_t adc1; ///< ADC1 (J405 ADC3, LPC2148 AD0.6) - uint16_t adc2; ///< ADC2 (J405 ADC5, LPC2148 AD0.2) - uint16_t adc3; ///< ADC3 (J405 ADC6, LPC2148 AD0.1) - uint16_t adc4; ///< ADC4 (J405 ADC7, LPC2148 AD1.3) - uint16_t vbat; ///< Battery voltage - int16_t temp; ///< Temperature (degrees celcius) - int32_t baro; ///< Barometric pressure (hecto Pascal) -} mavlink_raw_aux_t; - -#define MAVLINK_MSG_ID_RAW_AUX_LEN 16 -#define MAVLINK_MSG_ID_172_LEN 16 - - - -#define MAVLINK_MESSAGE_INFO_RAW_AUX { \ - "RAW_AUX", \ - 7, \ - { { "adc1", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_raw_aux_t, adc1) }, \ - { "adc2", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_raw_aux_t, adc2) }, \ - { "adc3", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_raw_aux_t, adc3) }, \ - { "adc4", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_raw_aux_t, adc4) }, \ - { "vbat", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_raw_aux_t, vbat) }, \ - { "temp", NULL, MAVLINK_TYPE_INT16_T, 0, 10, offsetof(mavlink_raw_aux_t, temp) }, \ - { "baro", NULL, MAVLINK_TYPE_INT32_T, 0, 12, offsetof(mavlink_raw_aux_t, baro) }, \ - } \ -} - - -/** - * @brief Pack a raw_aux message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param adc1 ADC1 (J405 ADC3, LPC2148 AD0.6) - * @param adc2 ADC2 (J405 ADC5, LPC2148 AD0.2) - * @param adc3 ADC3 (J405 ADC6, LPC2148 AD0.1) - * @param adc4 ADC4 (J405 ADC7, LPC2148 AD1.3) - * @param vbat Battery voltage - * @param temp Temperature (degrees celcius) - * @param baro Barometric pressure (hecto Pascal) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_raw_aux_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t adc1, uint16_t adc2, uint16_t adc3, uint16_t adc4, uint16_t vbat, int16_t temp, int32_t baro) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint16_t(buf, 0, adc1); - _mav_put_uint16_t(buf, 2, adc2); - _mav_put_uint16_t(buf, 4, adc3); - _mav_put_uint16_t(buf, 6, adc4); - _mav_put_uint16_t(buf, 8, vbat); - _mav_put_int16_t(buf, 10, temp); - _mav_put_int32_t(buf, 12, baro); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_raw_aux_t packet; - packet.adc1 = adc1; - packet.adc2 = adc2; - packet.adc3 = adc3; - packet.adc4 = adc4; - packet.vbat = vbat; - packet.temp = temp; - packet.baro = baro; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_RAW_AUX; - return mavlink_finalize_message(msg, system_id, component_id, 16); -} - -/** - * @brief Pack a raw_aux message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param adc1 ADC1 (J405 ADC3, LPC2148 AD0.6) - * @param adc2 ADC2 (J405 ADC5, LPC2148 AD0.2) - * @param adc3 ADC3 (J405 ADC6, LPC2148 AD0.1) - * @param adc4 ADC4 (J405 ADC7, LPC2148 AD1.3) - * @param vbat Battery voltage - * @param temp Temperature (degrees celcius) - * @param baro Barometric pressure (hecto Pascal) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_raw_aux_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t adc1,uint16_t adc2,uint16_t adc3,uint16_t adc4,uint16_t vbat,int16_t temp,int32_t baro) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint16_t(buf, 0, adc1); - _mav_put_uint16_t(buf, 2, adc2); - _mav_put_uint16_t(buf, 4, adc3); - _mav_put_uint16_t(buf, 6, adc4); - _mav_put_uint16_t(buf, 8, vbat); - _mav_put_int16_t(buf, 10, temp); - _mav_put_int32_t(buf, 12, baro); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 16); -#else - mavlink_raw_aux_t packet; - packet.adc1 = adc1; - packet.adc2 = adc2; - packet.adc3 = adc3; - packet.adc4 = adc4; - packet.vbat = vbat; - packet.temp = temp; - packet.baro = baro; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 16); -#endif - - msg->msgid = MAVLINK_MSG_ID_RAW_AUX; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 16); -} - -/** - * @brief Encode a raw_aux struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param raw_aux C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_raw_aux_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_raw_aux_t* raw_aux) -{ - return mavlink_msg_raw_aux_pack(system_id, component_id, msg, raw_aux->adc1, raw_aux->adc2, raw_aux->adc3, raw_aux->adc4, raw_aux->vbat, raw_aux->temp, raw_aux->baro); -} - -/** - * @brief Send a raw_aux message - * @param chan MAVLink channel to send the message - * - * @param adc1 ADC1 (J405 ADC3, LPC2148 AD0.6) - * @param adc2 ADC2 (J405 ADC5, LPC2148 AD0.2) - * @param adc3 ADC3 (J405 ADC6, LPC2148 AD0.1) - * @param adc4 ADC4 (J405 ADC7, LPC2148 AD1.3) - * @param vbat Battery voltage - * @param temp Temperature (degrees celcius) - * @param baro Barometric pressure (hecto Pascal) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_raw_aux_send(mavlink_channel_t chan, uint16_t adc1, uint16_t adc2, uint16_t adc3, uint16_t adc4, uint16_t vbat, int16_t temp, int32_t baro) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[16]; - _mav_put_uint16_t(buf, 0, adc1); - _mav_put_uint16_t(buf, 2, adc2); - _mav_put_uint16_t(buf, 4, adc3); - _mav_put_uint16_t(buf, 6, adc4); - _mav_put_uint16_t(buf, 8, vbat); - _mav_put_int16_t(buf, 10, temp); - _mav_put_int32_t(buf, 12, baro); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_AUX, buf, 16); -#else - mavlink_raw_aux_t packet; - packet.adc1 = adc1; - packet.adc2 = adc2; - packet.adc3 = adc3; - packet.adc4 = adc4; - packet.vbat = vbat; - packet.temp = temp; - packet.baro = baro; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RAW_AUX, (const char *)&packet, 16); -#endif -} - -#endif - -// MESSAGE RAW_AUX UNPACKING - - -/** - * @brief Get field adc1 from raw_aux message - * - * @return ADC1 (J405 ADC3, LPC2148 AD0.6) - */ -static inline uint16_t mavlink_msg_raw_aux_get_adc1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field adc2 from raw_aux message - * - * @return ADC2 (J405 ADC5, LPC2148 AD0.2) - */ -static inline uint16_t mavlink_msg_raw_aux_get_adc2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field adc3 from raw_aux message - * - * @return ADC3 (J405 ADC6, LPC2148 AD0.1) - */ -static inline uint16_t mavlink_msg_raw_aux_get_adc3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 4); -} - -/** - * @brief Get field adc4 from raw_aux message - * - * @return ADC4 (J405 ADC7, LPC2148 AD1.3) - */ -static inline uint16_t mavlink_msg_raw_aux_get_adc4(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 6); -} - -/** - * @brief Get field vbat from raw_aux message - * - * @return Battery voltage - */ -static inline uint16_t mavlink_msg_raw_aux_get_vbat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Get field temp from raw_aux message - * - * @return Temperature (degrees celcius) - */ -static inline int16_t mavlink_msg_raw_aux_get_temp(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 10); -} - -/** - * @brief Get field baro from raw_aux message - * - * @return Barometric pressure (hecto Pascal) - */ -static inline int32_t mavlink_msg_raw_aux_get_baro(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 12); -} - -/** - * @brief Decode a raw_aux message into a struct - * - * @param msg The message to decode - * @param raw_aux C-struct to decode the message contents into - */ -static inline void mavlink_msg_raw_aux_decode(const mavlink_message_t* msg, mavlink_raw_aux_t* raw_aux) -{ -#if MAVLINK_NEED_BYTE_SWAP - raw_aux->adc1 = mavlink_msg_raw_aux_get_adc1(msg); - raw_aux->adc2 = mavlink_msg_raw_aux_get_adc2(msg); - raw_aux->adc3 = mavlink_msg_raw_aux_get_adc3(msg); - raw_aux->adc4 = mavlink_msg_raw_aux_get_adc4(msg); - raw_aux->vbat = mavlink_msg_raw_aux_get_vbat(msg); - raw_aux->temp = mavlink_msg_raw_aux_get_temp(msg); - raw_aux->baro = mavlink_msg_raw_aux_get_baro(msg); -#else - memcpy(raw_aux, _MAV_PAYLOAD(msg), 16); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_set_cam_shutter.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_set_cam_shutter.h deleted file mode 100644 index c51ac730df..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_set_cam_shutter.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE SET_CAM_SHUTTER PACKING - -#define MAVLINK_MSG_ID_SET_CAM_SHUTTER 151 - -typedef struct __mavlink_set_cam_shutter_t -{ - uint8_t cam_no; ///< Camera id - uint8_t cam_mode; ///< Camera mode: 0 = auto, 1 = manual - uint8_t trigger_pin; ///< Trigger pin, 0-3 for PtGrey FireFly - uint16_t interval; ///< Shutter interval, in microseconds - uint16_t exposure; ///< Exposure time, in microseconds - float gain; ///< Camera gain -} mavlink_set_cam_shutter_t; - -#define MAVLINK_MSG_ID_SET_CAM_SHUTTER_LEN 11 -#define MAVLINK_MSG_ID_151_LEN 11 - - - -#define MAVLINK_MESSAGE_INFO_SET_CAM_SHUTTER { \ - "SET_CAM_SHUTTER", \ - 6, \ - { { "cam_no", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_set_cam_shutter_t, cam_no) }, \ - { "cam_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_set_cam_shutter_t, cam_mode) }, \ - { "trigger_pin", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_set_cam_shutter_t, trigger_pin) }, \ - { "interval", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_set_cam_shutter_t, interval) }, \ - { "exposure", NULL, MAVLINK_TYPE_UINT16_T, 0, 5, offsetof(mavlink_set_cam_shutter_t, exposure) }, \ - { "gain", NULL, MAVLINK_TYPE_FLOAT, 0, 7, offsetof(mavlink_set_cam_shutter_t, gain) }, \ - } \ -} - - -/** - * @brief Pack a set_cam_shutter message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param cam_no Camera id - * @param cam_mode Camera mode: 0 = auto, 1 = manual - * @param trigger_pin Trigger pin, 0-3 for PtGrey FireFly - * @param interval Shutter interval, in microseconds - * @param exposure Exposure time, in microseconds - * @param gain Camera gain - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_cam_shutter_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t cam_no, uint8_t cam_mode, uint8_t trigger_pin, uint16_t interval, uint16_t exposure, float gain) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[11]; - _mav_put_uint8_t(buf, 0, cam_no); - _mav_put_uint8_t(buf, 1, cam_mode); - _mav_put_uint8_t(buf, 2, trigger_pin); - _mav_put_uint16_t(buf, 3, interval); - _mav_put_uint16_t(buf, 5, exposure); - _mav_put_float(buf, 7, gain); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 11); -#else - mavlink_set_cam_shutter_t packet; - packet.cam_no = cam_no; - packet.cam_mode = cam_mode; - packet.trigger_pin = trigger_pin; - packet.interval = interval; - packet.exposure = exposure; - packet.gain = gain; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 11); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_CAM_SHUTTER; - return mavlink_finalize_message(msg, system_id, component_id, 11); -} - -/** - * @brief Pack a set_cam_shutter message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param cam_no Camera id - * @param cam_mode Camera mode: 0 = auto, 1 = manual - * @param trigger_pin Trigger pin, 0-3 for PtGrey FireFly - * @param interval Shutter interval, in microseconds - * @param exposure Exposure time, in microseconds - * @param gain Camera gain - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_set_cam_shutter_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t cam_no,uint8_t cam_mode,uint8_t trigger_pin,uint16_t interval,uint16_t exposure,float gain) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[11]; - _mav_put_uint8_t(buf, 0, cam_no); - _mav_put_uint8_t(buf, 1, cam_mode); - _mav_put_uint8_t(buf, 2, trigger_pin); - _mav_put_uint16_t(buf, 3, interval); - _mav_put_uint16_t(buf, 5, exposure); - _mav_put_float(buf, 7, gain); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 11); -#else - mavlink_set_cam_shutter_t packet; - packet.cam_no = cam_no; - packet.cam_mode = cam_mode; - packet.trigger_pin = trigger_pin; - packet.interval = interval; - packet.exposure = exposure; - packet.gain = gain; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 11); -#endif - - msg->msgid = MAVLINK_MSG_ID_SET_CAM_SHUTTER; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 11); -} - -/** - * @brief Encode a set_cam_shutter struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param set_cam_shutter C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_set_cam_shutter_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_cam_shutter_t* set_cam_shutter) -{ - return mavlink_msg_set_cam_shutter_pack(system_id, component_id, msg, set_cam_shutter->cam_no, set_cam_shutter->cam_mode, set_cam_shutter->trigger_pin, set_cam_shutter->interval, set_cam_shutter->exposure, set_cam_shutter->gain); -} - -/** - * @brief Send a set_cam_shutter message - * @param chan MAVLink channel to send the message - * - * @param cam_no Camera id - * @param cam_mode Camera mode: 0 = auto, 1 = manual - * @param trigger_pin Trigger pin, 0-3 for PtGrey FireFly - * @param interval Shutter interval, in microseconds - * @param exposure Exposure time, in microseconds - * @param gain Camera gain - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_set_cam_shutter_send(mavlink_channel_t chan, uint8_t cam_no, uint8_t cam_mode, uint8_t trigger_pin, uint16_t interval, uint16_t exposure, float gain) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[11]; - _mav_put_uint8_t(buf, 0, cam_no); - _mav_put_uint8_t(buf, 1, cam_mode); - _mav_put_uint8_t(buf, 2, trigger_pin); - _mav_put_uint16_t(buf, 3, interval); - _mav_put_uint16_t(buf, 5, exposure); - _mav_put_float(buf, 7, gain); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_CAM_SHUTTER, buf, 11); -#else - mavlink_set_cam_shutter_t packet; - packet.cam_no = cam_no; - packet.cam_mode = cam_mode; - packet.trigger_pin = trigger_pin; - packet.interval = interval; - packet.exposure = exposure; - packet.gain = gain; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_CAM_SHUTTER, (const char *)&packet, 11); -#endif -} - -#endif - -// MESSAGE SET_CAM_SHUTTER UNPACKING - - -/** - * @brief Get field cam_no from set_cam_shutter message - * - * @return Camera id - */ -static inline uint8_t mavlink_msg_set_cam_shutter_get_cam_no(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field cam_mode from set_cam_shutter message - * - * @return Camera mode: 0 = auto, 1 = manual - */ -static inline uint8_t mavlink_msg_set_cam_shutter_get_cam_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field trigger_pin from set_cam_shutter message - * - * @return Trigger pin, 0-3 for PtGrey FireFly - */ -static inline uint8_t mavlink_msg_set_cam_shutter_get_trigger_pin(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field interval from set_cam_shutter message - * - * @return Shutter interval, in microseconds - */ -static inline uint16_t mavlink_msg_set_cam_shutter_get_interval(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field exposure from set_cam_shutter message - * - * @return Exposure time, in microseconds - */ -static inline uint16_t mavlink_msg_set_cam_shutter_get_exposure(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 5); -} - -/** - * @brief Get field gain from set_cam_shutter message - * - * @return Camera gain - */ -static inline float mavlink_msg_set_cam_shutter_get_gain(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 7); -} - -/** - * @brief Decode a set_cam_shutter message into a struct - * - * @param msg The message to decode - * @param set_cam_shutter C-struct to decode the message contents into - */ -static inline void mavlink_msg_set_cam_shutter_decode(const mavlink_message_t* msg, mavlink_set_cam_shutter_t* set_cam_shutter) -{ -#if MAVLINK_NEED_BYTE_SWAP - set_cam_shutter->cam_no = mavlink_msg_set_cam_shutter_get_cam_no(msg); - set_cam_shutter->cam_mode = mavlink_msg_set_cam_shutter_get_cam_mode(msg); - set_cam_shutter->trigger_pin = mavlink_msg_set_cam_shutter_get_trigger_pin(msg); - set_cam_shutter->interval = mavlink_msg_set_cam_shutter_get_interval(msg); - set_cam_shutter->exposure = mavlink_msg_set_cam_shutter_get_exposure(msg); - set_cam_shutter->gain = mavlink_msg_set_cam_shutter_get_gain(msg); -#else - memcpy(set_cam_shutter, _MAV_PAYLOAD(msg), 11); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vicon_position_estimate.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vicon_position_estimate.h deleted file mode 100644 index d2b4fbefba..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vicon_position_estimate.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE VICON_POSITION_ESTIMATE PACKING - -#define MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE 157 - -typedef struct __mavlink_vicon_position_estimate_t -{ - uint64_t usec; ///< Timestamp (milliseconds) - float x; ///< Global X position - float y; ///< Global Y position - float z; ///< Global Z position - float roll; ///< Roll angle in rad - float pitch; ///< Pitch angle in rad - float yaw; ///< Yaw angle in rad -} mavlink_vicon_position_estimate_t; - -#define MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE_LEN 32 -#define MAVLINK_MSG_ID_157_LEN 32 - - - -#define MAVLINK_MESSAGE_INFO_VICON_POSITION_ESTIMATE { \ - "VICON_POSITION_ESTIMATE", \ - 7, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_vicon_position_estimate_t, usec) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vicon_position_estimate_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vicon_position_estimate_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_vicon_position_estimate_t, z) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_vicon_position_estimate_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_vicon_position_estimate_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_vicon_position_estimate_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a vicon_position_estimate message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (milliseconds) - * @param x Global X position - * @param y Global Y position - * @param z Global Z position - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vicon_position_estimate_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float x, float y, float z, float roll, float pitch, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, roll); - _mav_put_float(buf, 24, pitch); - _mav_put_float(buf, 28, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_vicon_position_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a vicon_position_estimate message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) - * @param x Global X position - * @param y Global Y position - * @param z Global Z position - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vicon_position_estimate_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float x,float y,float z,float roll,float pitch,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, roll); - _mav_put_float(buf, 24, pitch); - _mav_put_float(buf, 28, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_vicon_position_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a vicon_position_estimate struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param vicon_position_estimate C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_vicon_position_estimate_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vicon_position_estimate_t* vicon_position_estimate) -{ - return mavlink_msg_vicon_position_estimate_pack(system_id, component_id, msg, vicon_position_estimate->usec, vicon_position_estimate->x, vicon_position_estimate->y, vicon_position_estimate->z, vicon_position_estimate->roll, vicon_position_estimate->pitch, vicon_position_estimate->yaw); -} - -/** - * @brief Send a vicon_position_estimate message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (milliseconds) - * @param x Global X position - * @param y Global Y position - * @param z Global Z position - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_vicon_position_estimate_send(mavlink_channel_t chan, uint64_t usec, float x, float y, float z, float roll, float pitch, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, roll); - _mav_put_float(buf, 24, pitch); - _mav_put_float(buf, 28, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE, buf, 32); -#else - mavlink_vicon_position_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE VICON_POSITION_ESTIMATE UNPACKING - - -/** - * @brief Get field usec from vicon_position_estimate message - * - * @return Timestamp (milliseconds) - */ -static inline uint64_t mavlink_msg_vicon_position_estimate_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field x from vicon_position_estimate message - * - * @return Global X position - */ -static inline float mavlink_msg_vicon_position_estimate_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field y from vicon_position_estimate message - * - * @return Global Y position - */ -static inline float mavlink_msg_vicon_position_estimate_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field z from vicon_position_estimate message - * - * @return Global Z position - */ -static inline float mavlink_msg_vicon_position_estimate_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field roll from vicon_position_estimate message - * - * @return Roll angle in rad - */ -static inline float mavlink_msg_vicon_position_estimate_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field pitch from vicon_position_estimate message - * - * @return Pitch angle in rad - */ -static inline float mavlink_msg_vicon_position_estimate_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field yaw from vicon_position_estimate message - * - * @return Yaw angle in rad - */ -static inline float mavlink_msg_vicon_position_estimate_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a vicon_position_estimate message into a struct - * - * @param msg The message to decode - * @param vicon_position_estimate C-struct to decode the message contents into - */ -static inline void mavlink_msg_vicon_position_estimate_decode(const mavlink_message_t* msg, mavlink_vicon_position_estimate_t* vicon_position_estimate) -{ -#if MAVLINK_NEED_BYTE_SWAP - vicon_position_estimate->usec = mavlink_msg_vicon_position_estimate_get_usec(msg); - vicon_position_estimate->x = mavlink_msg_vicon_position_estimate_get_x(msg); - vicon_position_estimate->y = mavlink_msg_vicon_position_estimate_get_y(msg); - vicon_position_estimate->z = mavlink_msg_vicon_position_estimate_get_z(msg); - vicon_position_estimate->roll = mavlink_msg_vicon_position_estimate_get_roll(msg); - vicon_position_estimate->pitch = mavlink_msg_vicon_position_estimate_get_pitch(msg); - vicon_position_estimate->yaw = mavlink_msg_vicon_position_estimate_get_yaw(msg); -#else - memcpy(vicon_position_estimate, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vision_position_estimate.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vision_position_estimate.h deleted file mode 100644 index d257972b70..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vision_position_estimate.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE VISION_POSITION_ESTIMATE PACKING - -#define MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE 156 - -typedef struct __mavlink_vision_position_estimate_t -{ - uint64_t usec; ///< Timestamp (milliseconds) - float x; ///< Global X position - float y; ///< Global Y position - float z; ///< Global Z position - float roll; ///< Roll angle in rad - float pitch; ///< Pitch angle in rad - float yaw; ///< Yaw angle in rad -} mavlink_vision_position_estimate_t; - -#define MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE_LEN 32 -#define MAVLINK_MSG_ID_156_LEN 32 - - - -#define MAVLINK_MESSAGE_INFO_VISION_POSITION_ESTIMATE { \ - "VISION_POSITION_ESTIMATE", \ - 7, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_vision_position_estimate_t, usec) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vision_position_estimate_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vision_position_estimate_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_vision_position_estimate_t, z) }, \ - { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_vision_position_estimate_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_vision_position_estimate_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_vision_position_estimate_t, yaw) }, \ - } \ -} - - -/** - * @brief Pack a vision_position_estimate message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (milliseconds) - * @param x Global X position - * @param y Global Y position - * @param z Global Z position - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vision_position_estimate_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float x, float y, float z, float roll, float pitch, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, roll); - _mav_put_float(buf, 24, pitch); - _mav_put_float(buf, 28, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_vision_position_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a vision_position_estimate message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) - * @param x Global X position - * @param y Global Y position - * @param z Global Z position - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vision_position_estimate_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float x,float y,float z,float roll,float pitch,float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, roll); - _mav_put_float(buf, 24, pitch); - _mav_put_float(buf, 28, yaw); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_vision_position_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a vision_position_estimate struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param vision_position_estimate C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_vision_position_estimate_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vision_position_estimate_t* vision_position_estimate) -{ - return mavlink_msg_vision_position_estimate_pack(system_id, component_id, msg, vision_position_estimate->usec, vision_position_estimate->x, vision_position_estimate->y, vision_position_estimate->z, vision_position_estimate->roll, vision_position_estimate->pitch, vision_position_estimate->yaw); -} - -/** - * @brief Send a vision_position_estimate message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (milliseconds) - * @param x Global X position - * @param y Global Y position - * @param z Global Z position - * @param roll Roll angle in rad - * @param pitch Pitch angle in rad - * @param yaw Yaw angle in rad - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_vision_position_estimate_send(mavlink_channel_t chan, uint64_t usec, float x, float y, float z, float roll, float pitch, float yaw) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - _mav_put_float(buf, 20, roll); - _mav_put_float(buf, 24, pitch); - _mav_put_float(buf, 28, yaw); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE, buf, 32); -#else - mavlink_vision_position_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE VISION_POSITION_ESTIMATE UNPACKING - - -/** - * @brief Get field usec from vision_position_estimate message - * - * @return Timestamp (milliseconds) - */ -static inline uint64_t mavlink_msg_vision_position_estimate_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field x from vision_position_estimate message - * - * @return Global X position - */ -static inline float mavlink_msg_vision_position_estimate_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field y from vision_position_estimate message - * - * @return Global Y position - */ -static inline float mavlink_msg_vision_position_estimate_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field z from vision_position_estimate message - * - * @return Global Z position - */ -static inline float mavlink_msg_vision_position_estimate_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field roll from vision_position_estimate message - * - * @return Roll angle in rad - */ -static inline float mavlink_msg_vision_position_estimate_get_roll(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field pitch from vision_position_estimate message - * - * @return Pitch angle in rad - */ -static inline float mavlink_msg_vision_position_estimate_get_pitch(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field yaw from vision_position_estimate message - * - * @return Yaw angle in rad - */ -static inline float mavlink_msg_vision_position_estimate_get_yaw(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a vision_position_estimate message into a struct - * - * @param msg The message to decode - * @param vision_position_estimate C-struct to decode the message contents into - */ -static inline void mavlink_msg_vision_position_estimate_decode(const mavlink_message_t* msg, mavlink_vision_position_estimate_t* vision_position_estimate) -{ -#if MAVLINK_NEED_BYTE_SWAP - vision_position_estimate->usec = mavlink_msg_vision_position_estimate_get_usec(msg); - vision_position_estimate->x = mavlink_msg_vision_position_estimate_get_x(msg); - vision_position_estimate->y = mavlink_msg_vision_position_estimate_get_y(msg); - vision_position_estimate->z = mavlink_msg_vision_position_estimate_get_z(msg); - vision_position_estimate->roll = mavlink_msg_vision_position_estimate_get_roll(msg); - vision_position_estimate->pitch = mavlink_msg_vision_position_estimate_get_pitch(msg); - vision_position_estimate->yaw = mavlink_msg_vision_position_estimate_get_yaw(msg); -#else - memcpy(vision_position_estimate, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vision_speed_estimate.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vision_speed_estimate.h deleted file mode 100644 index 22929dd215..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_vision_speed_estimate.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE VISION_SPEED_ESTIMATE PACKING - -#define MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE 158 - -typedef struct __mavlink_vision_speed_estimate_t -{ - uint64_t usec; ///< Timestamp (milliseconds) - float x; ///< Global X speed - float y; ///< Global Y speed - float z; ///< Global Z speed -} mavlink_vision_speed_estimate_t; - -#define MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE_LEN 20 -#define MAVLINK_MSG_ID_158_LEN 20 - - - -#define MAVLINK_MESSAGE_INFO_VISION_SPEED_ESTIMATE { \ - "VISION_SPEED_ESTIMATE", \ - 4, \ - { { "usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_vision_speed_estimate_t, usec) }, \ - { "x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_vision_speed_estimate_t, x) }, \ - { "y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_vision_speed_estimate_t, y) }, \ - { "z", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_vision_speed_estimate_t, z) }, \ - } \ -} - - -/** - * @brief Pack a vision_speed_estimate message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param usec Timestamp (milliseconds) - * @param x Global X speed - * @param y Global Y speed - * @param z Global Z speed - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vision_speed_estimate_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint64_t usec, float x, float y, float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_vision_speed_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE; - return mavlink_finalize_message(msg, system_id, component_id, 20); -} - -/** - * @brief Pack a vision_speed_estimate message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) - * @param x Global X speed - * @param y Global Y speed - * @param z Global Z speed - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_vision_speed_estimate_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float x,float y,float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 20); -#else - mavlink_vision_speed_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 20); -#endif - - msg->msgid = MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 20); -} - -/** - * @brief Encode a vision_speed_estimate struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param vision_speed_estimate C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_vision_speed_estimate_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vision_speed_estimate_t* vision_speed_estimate) -{ - return mavlink_msg_vision_speed_estimate_pack(system_id, component_id, msg, vision_speed_estimate->usec, vision_speed_estimate->x, vision_speed_estimate->y, vision_speed_estimate->z); -} - -/** - * @brief Send a vision_speed_estimate message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (milliseconds) - * @param x Global X speed - * @param y Global Y speed - * @param z Global Z speed - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_vision_speed_estimate_send(mavlink_channel_t chan, uint64_t usec, float x, float y, float z) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[20]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, x); - _mav_put_float(buf, 12, y); - _mav_put_float(buf, 16, z); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE, buf, 20); -#else - mavlink_vision_speed_estimate_t packet; - packet.usec = usec; - packet.x = x; - packet.y = y; - packet.z = z; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE, (const char *)&packet, 20); -#endif -} - -#endif - -// MESSAGE VISION_SPEED_ESTIMATE UNPACKING - - -/** - * @brief Get field usec from vision_speed_estimate message - * - * @return Timestamp (milliseconds) - */ -static inline uint64_t mavlink_msg_vision_speed_estimate_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field x from vision_speed_estimate message - * - * @return Global X speed - */ -static inline float mavlink_msg_vision_speed_estimate_get_x(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field y from vision_speed_estimate message - * - * @return Global Y speed - */ -static inline float mavlink_msg_vision_speed_estimate_get_y(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field z from vision_speed_estimate message - * - * @return Global Z speed - */ -static inline float mavlink_msg_vision_speed_estimate_get_z(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Decode a vision_speed_estimate message into a struct - * - * @param msg The message to decode - * @param vision_speed_estimate C-struct to decode the message contents into - */ -static inline void mavlink_msg_vision_speed_estimate_decode(const mavlink_message_t* msg, mavlink_vision_speed_estimate_t* vision_speed_estimate) -{ -#if MAVLINK_NEED_BYTE_SWAP - vision_speed_estimate->usec = mavlink_msg_vision_speed_estimate_get_usec(msg); - vision_speed_estimate->x = mavlink_msg_vision_speed_estimate_get_x(msg); - vision_speed_estimate->y = mavlink_msg_vision_speed_estimate_get_y(msg); - vision_speed_estimate->z = mavlink_msg_vision_speed_estimate_get_z(msg); -#else - memcpy(vision_speed_estimate, _MAV_PAYLOAD(msg), 20); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_command.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_command.h deleted file mode 100644 index a3ffe71adb..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_command.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE WATCHDOG_COMMAND PACKING - -#define MAVLINK_MSG_ID_WATCHDOG_COMMAND 183 - -typedef struct __mavlink_watchdog_command_t -{ - uint8_t target_system_id; ///< Target system ID - uint16_t watchdog_id; ///< Watchdog ID - uint16_t process_id; ///< Process ID - uint8_t command_id; ///< Command ID -} mavlink_watchdog_command_t; - -#define MAVLINK_MSG_ID_WATCHDOG_COMMAND_LEN 6 -#define MAVLINK_MSG_ID_183_LEN 6 - - - -#define MAVLINK_MESSAGE_INFO_WATCHDOG_COMMAND { \ - "WATCHDOG_COMMAND", \ - 4, \ - { { "target_system_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_watchdog_command_t, target_system_id) }, \ - { "watchdog_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 1, offsetof(mavlink_watchdog_command_t, watchdog_id) }, \ - { "process_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 3, offsetof(mavlink_watchdog_command_t, process_id) }, \ - { "command_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_watchdog_command_t, command_id) }, \ - } \ -} - - -/** - * @brief Pack a watchdog_command message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target_system_id Target system ID - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param command_id Command ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_command_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target_system_id, uint16_t watchdog_id, uint16_t process_id, uint8_t command_id) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system_id); - _mav_put_uint16_t(buf, 1, watchdog_id); - _mav_put_uint16_t(buf, 3, process_id); - _mav_put_uint8_t(buf, 5, command_id); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 6); -#else - mavlink_watchdog_command_t packet; - packet.target_system_id = target_system_id; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.command_id = command_id; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 6); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_COMMAND; - return mavlink_finalize_message(msg, system_id, component_id, 6); -} - -/** - * @brief Pack a watchdog_command message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target_system_id Target system ID - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param command_id Command ID - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_command_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target_system_id,uint16_t watchdog_id,uint16_t process_id,uint8_t command_id) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system_id); - _mav_put_uint16_t(buf, 1, watchdog_id); - _mav_put_uint16_t(buf, 3, process_id); - _mav_put_uint8_t(buf, 5, command_id); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 6); -#else - mavlink_watchdog_command_t packet; - packet.target_system_id = target_system_id; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.command_id = command_id; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 6); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_COMMAND; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 6); -} - -/** - * @brief Encode a watchdog_command struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param watchdog_command C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_watchdog_command_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_watchdog_command_t* watchdog_command) -{ - return mavlink_msg_watchdog_command_pack(system_id, component_id, msg, watchdog_command->target_system_id, watchdog_command->watchdog_id, watchdog_command->process_id, watchdog_command->command_id); -} - -/** - * @brief Send a watchdog_command message - * @param chan MAVLink channel to send the message - * - * @param target_system_id Target system ID - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param command_id Command ID - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_watchdog_command_send(mavlink_channel_t chan, uint8_t target_system_id, uint16_t watchdog_id, uint16_t process_id, uint8_t command_id) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[6]; - _mav_put_uint8_t(buf, 0, target_system_id); - _mav_put_uint16_t(buf, 1, watchdog_id); - _mav_put_uint16_t(buf, 3, process_id); - _mav_put_uint8_t(buf, 5, command_id); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_COMMAND, buf, 6); -#else - mavlink_watchdog_command_t packet; - packet.target_system_id = target_system_id; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.command_id = command_id; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_COMMAND, (const char *)&packet, 6); -#endif -} - -#endif - -// MESSAGE WATCHDOG_COMMAND UNPACKING - - -/** - * @brief Get field target_system_id from watchdog_command message - * - * @return Target system ID - */ -static inline uint8_t mavlink_msg_watchdog_command_get_target_system_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field watchdog_id from watchdog_command message - * - * @return Watchdog ID - */ -static inline uint16_t mavlink_msg_watchdog_command_get_watchdog_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 1); -} - -/** - * @brief Get field process_id from watchdog_command message - * - * @return Process ID - */ -static inline uint16_t mavlink_msg_watchdog_command_get_process_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 3); -} - -/** - * @brief Get field command_id from watchdog_command message - * - * @return Command ID - */ -static inline uint8_t mavlink_msg_watchdog_command_get_command_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Decode a watchdog_command message into a struct - * - * @param msg The message to decode - * @param watchdog_command C-struct to decode the message contents into - */ -static inline void mavlink_msg_watchdog_command_decode(const mavlink_message_t* msg, mavlink_watchdog_command_t* watchdog_command) -{ -#if MAVLINK_NEED_BYTE_SWAP - watchdog_command->target_system_id = mavlink_msg_watchdog_command_get_target_system_id(msg); - watchdog_command->watchdog_id = mavlink_msg_watchdog_command_get_watchdog_id(msg); - watchdog_command->process_id = mavlink_msg_watchdog_command_get_process_id(msg); - watchdog_command->command_id = mavlink_msg_watchdog_command_get_command_id(msg); -#else - memcpy(watchdog_command, _MAV_PAYLOAD(msg), 6); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_heartbeat.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_heartbeat.h deleted file mode 100644 index 6dbe21104b..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_heartbeat.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE WATCHDOG_HEARTBEAT PACKING - -#define MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT 180 - -typedef struct __mavlink_watchdog_heartbeat_t -{ - uint16_t watchdog_id; ///< Watchdog ID - uint16_t process_count; ///< Number of processes -} mavlink_watchdog_heartbeat_t; - -#define MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT_LEN 4 -#define MAVLINK_MSG_ID_180_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_WATCHDOG_HEARTBEAT { \ - "WATCHDOG_HEARTBEAT", \ - 2, \ - { { "watchdog_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_watchdog_heartbeat_t, watchdog_id) }, \ - { "process_count", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_watchdog_heartbeat_t, process_count) }, \ - } \ -} - - -/** - * @brief Pack a watchdog_heartbeat message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param watchdog_id Watchdog ID - * @param process_count Number of processes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t watchdog_id, uint16_t process_count) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_count); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_watchdog_heartbeat_t packet; - packet.watchdog_id = watchdog_id; - packet.process_count = process_count; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a watchdog_heartbeat message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param watchdog_id Watchdog ID - * @param process_count Number of processes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t watchdog_id,uint16_t process_count) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_count); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_watchdog_heartbeat_t packet; - packet.watchdog_id = watchdog_id; - packet.process_count = process_count; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a watchdog_heartbeat struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param watchdog_heartbeat C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_watchdog_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_watchdog_heartbeat_t* watchdog_heartbeat) -{ - return mavlink_msg_watchdog_heartbeat_pack(system_id, component_id, msg, watchdog_heartbeat->watchdog_id, watchdog_heartbeat->process_count); -} - -/** - * @brief Send a watchdog_heartbeat message - * @param chan MAVLink channel to send the message - * - * @param watchdog_id Watchdog ID - * @param process_count Number of processes - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_watchdog_heartbeat_send(mavlink_channel_t chan, uint16_t watchdog_id, uint16_t process_count) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_count); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT, buf, 4); -#else - mavlink_watchdog_heartbeat_t packet; - packet.watchdog_id = watchdog_id; - packet.process_count = process_count; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE WATCHDOG_HEARTBEAT UNPACKING - - -/** - * @brief Get field watchdog_id from watchdog_heartbeat message - * - * @return Watchdog ID - */ -static inline uint16_t mavlink_msg_watchdog_heartbeat_get_watchdog_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field process_count from watchdog_heartbeat message - * - * @return Number of processes - */ -static inline uint16_t mavlink_msg_watchdog_heartbeat_get_process_count(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a watchdog_heartbeat message into a struct - * - * @param msg The message to decode - * @param watchdog_heartbeat C-struct to decode the message contents into - */ -static inline void mavlink_msg_watchdog_heartbeat_decode(const mavlink_message_t* msg, mavlink_watchdog_heartbeat_t* watchdog_heartbeat) -{ -#if MAVLINK_NEED_BYTE_SWAP - watchdog_heartbeat->watchdog_id = mavlink_msg_watchdog_heartbeat_get_watchdog_id(msg); - watchdog_heartbeat->process_count = mavlink_msg_watchdog_heartbeat_get_process_count(msg); -#else - memcpy(watchdog_heartbeat, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_process_info.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_process_info.h deleted file mode 100644 index 42e8966927..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_process_info.h +++ /dev/null @@ -1,227 +0,0 @@ -// MESSAGE WATCHDOG_PROCESS_INFO PACKING - -#define MAVLINK_MSG_ID_WATCHDOG_PROCESS_INFO 181 - -typedef struct __mavlink_watchdog_process_info_t -{ - uint16_t watchdog_id; ///< Watchdog ID - uint16_t process_id; ///< Process ID - char name[100]; ///< Process name - char arguments[147]; ///< Process arguments - int32_t timeout; ///< Timeout (seconds) -} mavlink_watchdog_process_info_t; - -#define MAVLINK_MSG_ID_WATCHDOG_PROCESS_INFO_LEN 255 -#define MAVLINK_MSG_ID_181_LEN 255 - -#define MAVLINK_MSG_WATCHDOG_PROCESS_INFO_FIELD_NAME_LEN 100 -#define MAVLINK_MSG_WATCHDOG_PROCESS_INFO_FIELD_ARGUMENTS_LEN 147 - -#define MAVLINK_MESSAGE_INFO_WATCHDOG_PROCESS_INFO { \ - "WATCHDOG_PROCESS_INFO", \ - 5, \ - { { "watchdog_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_watchdog_process_info_t, watchdog_id) }, \ - { "process_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_watchdog_process_info_t, process_id) }, \ - { "name", NULL, MAVLINK_TYPE_CHAR, 100, 4, offsetof(mavlink_watchdog_process_info_t, name) }, \ - { "arguments", NULL, MAVLINK_TYPE_CHAR, 147, 104, offsetof(mavlink_watchdog_process_info_t, arguments) }, \ - { "timeout", NULL, MAVLINK_TYPE_INT32_T, 0, 251, offsetof(mavlink_watchdog_process_info_t, timeout) }, \ - } \ -} - - -/** - * @brief Pack a watchdog_process_info message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param name Process name - * @param arguments Process arguments - * @param timeout Timeout (seconds) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_process_info_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t watchdog_id, uint16_t process_id, const char *name, const char *arguments, int32_t timeout) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[255]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_id); - _mav_put_int32_t(buf, 251, timeout); - _mav_put_char_array(buf, 4, name, 100); - _mav_put_char_array(buf, 104, arguments, 147); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 255); -#else - mavlink_watchdog_process_info_t packet; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.timeout = timeout; - mav_array_memcpy(packet.name, name, sizeof(char)*100); - mav_array_memcpy(packet.arguments, arguments, sizeof(char)*147); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 255); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_PROCESS_INFO; - return mavlink_finalize_message(msg, system_id, component_id, 255); -} - -/** - * @brief Pack a watchdog_process_info message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param name Process name - * @param arguments Process arguments - * @param timeout Timeout (seconds) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_process_info_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t watchdog_id,uint16_t process_id,const char *name,const char *arguments,int32_t timeout) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[255]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_id); - _mav_put_int32_t(buf, 251, timeout); - _mav_put_char_array(buf, 4, name, 100); - _mav_put_char_array(buf, 104, arguments, 147); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 255); -#else - mavlink_watchdog_process_info_t packet; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.timeout = timeout; - mav_array_memcpy(packet.name, name, sizeof(char)*100); - mav_array_memcpy(packet.arguments, arguments, sizeof(char)*147); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 255); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_PROCESS_INFO; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 255); -} - -/** - * @brief Encode a watchdog_process_info struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param watchdog_process_info C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_watchdog_process_info_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_watchdog_process_info_t* watchdog_process_info) -{ - return mavlink_msg_watchdog_process_info_pack(system_id, component_id, msg, watchdog_process_info->watchdog_id, watchdog_process_info->process_id, watchdog_process_info->name, watchdog_process_info->arguments, watchdog_process_info->timeout); -} - -/** - * @brief Send a watchdog_process_info message - * @param chan MAVLink channel to send the message - * - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param name Process name - * @param arguments Process arguments - * @param timeout Timeout (seconds) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_watchdog_process_info_send(mavlink_channel_t chan, uint16_t watchdog_id, uint16_t process_id, const char *name, const char *arguments, int32_t timeout) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[255]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_id); - _mav_put_int32_t(buf, 251, timeout); - _mav_put_char_array(buf, 4, name, 100); - _mav_put_char_array(buf, 104, arguments, 147); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_PROCESS_INFO, buf, 255); -#else - mavlink_watchdog_process_info_t packet; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.timeout = timeout; - mav_array_memcpy(packet.name, name, sizeof(char)*100); - mav_array_memcpy(packet.arguments, arguments, sizeof(char)*147); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_PROCESS_INFO, (const char *)&packet, 255); -#endif -} - -#endif - -// MESSAGE WATCHDOG_PROCESS_INFO UNPACKING - - -/** - * @brief Get field watchdog_id from watchdog_process_info message - * - * @return Watchdog ID - */ -static inline uint16_t mavlink_msg_watchdog_process_info_get_watchdog_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field process_id from watchdog_process_info message - * - * @return Process ID - */ -static inline uint16_t mavlink_msg_watchdog_process_info_get_process_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field name from watchdog_process_info message - * - * @return Process name - */ -static inline uint16_t mavlink_msg_watchdog_process_info_get_name(const mavlink_message_t* msg, char *name) -{ - return _MAV_RETURN_char_array(msg, name, 100, 4); -} - -/** - * @brief Get field arguments from watchdog_process_info message - * - * @return Process arguments - */ -static inline uint16_t mavlink_msg_watchdog_process_info_get_arguments(const mavlink_message_t* msg, char *arguments) -{ - return _MAV_RETURN_char_array(msg, arguments, 147, 104); -} - -/** - * @brief Get field timeout from watchdog_process_info message - * - * @return Timeout (seconds) - */ -static inline int32_t mavlink_msg_watchdog_process_info_get_timeout(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 251); -} - -/** - * @brief Decode a watchdog_process_info message into a struct - * - * @param msg The message to decode - * @param watchdog_process_info C-struct to decode the message contents into - */ -static inline void mavlink_msg_watchdog_process_info_decode(const mavlink_message_t* msg, mavlink_watchdog_process_info_t* watchdog_process_info) -{ -#if MAVLINK_NEED_BYTE_SWAP - watchdog_process_info->watchdog_id = mavlink_msg_watchdog_process_info_get_watchdog_id(msg); - watchdog_process_info->process_id = mavlink_msg_watchdog_process_info_get_process_id(msg); - mavlink_msg_watchdog_process_info_get_name(msg, watchdog_process_info->name); - mavlink_msg_watchdog_process_info_get_arguments(msg, watchdog_process_info->arguments); - watchdog_process_info->timeout = mavlink_msg_watchdog_process_info_get_timeout(msg); -#else - memcpy(watchdog_process_info, _MAV_PAYLOAD(msg), 255); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_process_status.h b/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_process_status.h deleted file mode 100644 index de5c7b2b21..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/mavlink_msg_watchdog_process_status.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE WATCHDOG_PROCESS_STATUS PACKING - -#define MAVLINK_MSG_ID_WATCHDOG_PROCESS_STATUS 182 - -typedef struct __mavlink_watchdog_process_status_t -{ - uint16_t watchdog_id; ///< Watchdog ID - uint16_t process_id; ///< Process ID - uint8_t state; ///< Is running / finished / suspended / crashed - uint8_t muted; ///< Is muted - int32_t pid; ///< PID - uint16_t crashes; ///< Number of crashes -} mavlink_watchdog_process_status_t; - -#define MAVLINK_MSG_ID_WATCHDOG_PROCESS_STATUS_LEN 12 -#define MAVLINK_MSG_ID_182_LEN 12 - - - -#define MAVLINK_MESSAGE_INFO_WATCHDOG_PROCESS_STATUS { \ - "WATCHDOG_PROCESS_STATUS", \ - 6, \ - { { "watchdog_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_watchdog_process_status_t, watchdog_id) }, \ - { "process_id", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_watchdog_process_status_t, process_id) }, \ - { "state", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_watchdog_process_status_t, state) }, \ - { "muted", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_watchdog_process_status_t, muted) }, \ - { "pid", NULL, MAVLINK_TYPE_INT32_T, 0, 6, offsetof(mavlink_watchdog_process_status_t, pid) }, \ - { "crashes", NULL, MAVLINK_TYPE_UINT16_T, 0, 10, offsetof(mavlink_watchdog_process_status_t, crashes) }, \ - } \ -} - - -/** - * @brief Pack a watchdog_process_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param state Is running / finished / suspended / crashed - * @param muted Is muted - * @param pid PID - * @param crashes Number of crashes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_process_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint16_t watchdog_id, uint16_t process_id, uint8_t state, uint8_t muted, int32_t pid, uint16_t crashes) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_id); - _mav_put_uint8_t(buf, 4, state); - _mav_put_uint8_t(buf, 5, muted); - _mav_put_int32_t(buf, 6, pid); - _mav_put_uint16_t(buf, 10, crashes); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_watchdog_process_status_t packet; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.state = state; - packet.muted = muted; - packet.pid = pid; - packet.crashes = crashes; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_PROCESS_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 12); -} - -/** - * @brief Pack a watchdog_process_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param state Is running / finished / suspended / crashed - * @param muted Is muted - * @param pid PID - * @param crashes Number of crashes - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_watchdog_process_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint16_t watchdog_id,uint16_t process_id,uint8_t state,uint8_t muted,int32_t pid,uint16_t crashes) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_id); - _mav_put_uint8_t(buf, 4, state); - _mav_put_uint8_t(buf, 5, muted); - _mav_put_int32_t(buf, 6, pid); - _mav_put_uint16_t(buf, 10, crashes); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); -#else - mavlink_watchdog_process_status_t packet; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.state = state; - packet.muted = muted; - packet.pid = pid; - packet.crashes = crashes; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); -#endif - - msg->msgid = MAVLINK_MSG_ID_WATCHDOG_PROCESS_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 12); -} - -/** - * @brief Encode a watchdog_process_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param watchdog_process_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_watchdog_process_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_watchdog_process_status_t* watchdog_process_status) -{ - return mavlink_msg_watchdog_process_status_pack(system_id, component_id, msg, watchdog_process_status->watchdog_id, watchdog_process_status->process_id, watchdog_process_status->state, watchdog_process_status->muted, watchdog_process_status->pid, watchdog_process_status->crashes); -} - -/** - * @brief Send a watchdog_process_status message - * @param chan MAVLink channel to send the message - * - * @param watchdog_id Watchdog ID - * @param process_id Process ID - * @param state Is running / finished / suspended / crashed - * @param muted Is muted - * @param pid PID - * @param crashes Number of crashes - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_watchdog_process_status_send(mavlink_channel_t chan, uint16_t watchdog_id, uint16_t process_id, uint8_t state, uint8_t muted, int32_t pid, uint16_t crashes) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[12]; - _mav_put_uint16_t(buf, 0, watchdog_id); - _mav_put_uint16_t(buf, 2, process_id); - _mav_put_uint8_t(buf, 4, state); - _mav_put_uint8_t(buf, 5, muted); - _mav_put_int32_t(buf, 6, pid); - _mav_put_uint16_t(buf, 10, crashes); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_PROCESS_STATUS, buf, 12); -#else - mavlink_watchdog_process_status_t packet; - packet.watchdog_id = watchdog_id; - packet.process_id = process_id; - packet.state = state; - packet.muted = muted; - packet.pid = pid; - packet.crashes = crashes; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WATCHDOG_PROCESS_STATUS, (const char *)&packet, 12); -#endif -} - -#endif - -// MESSAGE WATCHDOG_PROCESS_STATUS UNPACKING - - -/** - * @brief Get field watchdog_id from watchdog_process_status message - * - * @return Watchdog ID - */ -static inline uint16_t mavlink_msg_watchdog_process_status_get_watchdog_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Get field process_id from watchdog_process_status message - * - * @return Process ID - */ -static inline uint16_t mavlink_msg_watchdog_process_status_get_process_id(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Get field state from watchdog_process_status message - * - * @return Is running / finished / suspended / crashed - */ -static inline uint8_t mavlink_msg_watchdog_process_status_get_state(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field muted from watchdog_process_status message - * - * @return Is muted - */ -static inline uint8_t mavlink_msg_watchdog_process_status_get_muted(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field pid from watchdog_process_status message - * - * @return PID - */ -static inline int32_t mavlink_msg_watchdog_process_status_get_pid(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 6); -} - -/** - * @brief Get field crashes from watchdog_process_status message - * - * @return Number of crashes - */ -static inline uint16_t mavlink_msg_watchdog_process_status_get_crashes(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 10); -} - -/** - * @brief Decode a watchdog_process_status message into a struct - * - * @param msg The message to decode - * @param watchdog_process_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_watchdog_process_status_decode(const mavlink_message_t* msg, mavlink_watchdog_process_status_t* watchdog_process_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - watchdog_process_status->watchdog_id = mavlink_msg_watchdog_process_status_get_watchdog_id(msg); - watchdog_process_status->process_id = mavlink_msg_watchdog_process_status_get_process_id(msg); - watchdog_process_status->state = mavlink_msg_watchdog_process_status_get_state(msg); - watchdog_process_status->muted = mavlink_msg_watchdog_process_status_get_muted(msg); - watchdog_process_status->pid = mavlink_msg_watchdog_process_status_get_pid(msg); - watchdog_process_status->crashes = mavlink_msg_watchdog_process_status_get_crashes(msg); -#else - memcpy(watchdog_process_status, _MAV_PAYLOAD(msg), 12); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/pixhawk/pixhawk.h b/mavlink/include/mavlink/v0.9/pixhawk/pixhawk.h deleted file mode 100644 index feb759ef99..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/pixhawk.h +++ /dev/null @@ -1,86 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from pixhawk.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef PIXHAWK_H -#define PIXHAWK_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {3, 4, 8, 14, 8, 28, 3, 32, 0, 2, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 19, 2, 23, 21, 0, 37, 26, 101, 26, 16, 32, 32, 37, 32, 11, 17, 17, 16, 18, 36, 4, 4, 2, 2, 4, 2, 2, 3, 14, 12, 18, 16, 8, 27, 25, 18, 18, 24, 24, 0, 0, 0, 26, 16, 36, 5, 6, 56, 26, 21, 18, 0, 0, 18, 20, 20, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 52, 1, 92, 0, 32, 32, 20, 20, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 26, 16, 0, 0, 0, 0, 0, 0, 0, 4, 255, 12, 6, 0, 0, 0, 0, 0, 0, 106, 43, 55, 8, 255, 53, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 14, 14, 51, 5} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {72, 39, 190, 92, 191, 217, 104, 119, 0, 219, 60, 186, 10, 0, 0, 0, 0, 0, 0, 0, 89, 159, 162, 121, 0, 149, 222, 110, 179, 136, 66, 126, 185, 147, 112, 252, 162, 215, 229, 128, 9, 106, 101, 213, 4, 229, 21, 214, 215, 14, 206, 50, 157, 126, 108, 213, 95, 5, 127, 0, 0, 0, 57, 126, 130, 119, 193, 191, 236, 158, 143, 0, 0, 104, 123, 131, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 86, 95, 49, 0, 158, 56, 208, 218, 115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 136, 140, 0, 0, 0, 0, 0, 0, 0, 153, 110, 92, 188, 0, 0, 0, 0, 0, 0, 106, 154, 83, 98, 223, 254, 0, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 224, 60, 106, 7} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_BOOT, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_SYSTEM_TIME_UTC, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_ACTION_ACK, MAVLINK_MESSAGE_INFO_ACTION, MAVLINK_MESSAGE_INFO_SET_MODE, MAVLINK_MESSAGE_INFO_SET_NAV_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_LOCAL_POSITION, MAVLINK_MESSAGE_INFO_GPS_RAW, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_WAYPOINT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST, MAVLINK_MESSAGE_INFO_WAYPOINT_SET_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST_LIST, MAVLINK_MESSAGE_INFO_WAYPOINT_COUNT, MAVLINK_MESSAGE_INFO_WAYPOINT_CLEAR_ALL, MAVLINK_MESSAGE_INFO_WAYPOINT_REACHED, MAVLINK_MESSAGE_INFO_WAYPOINT_ACK, MAVLINK_MESSAGE_INFO_GPS_SET_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_LOCAL_ORIGIN_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_CONTROL_STATUS, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, MAVLINK_MESSAGE_INFO_POSITION_TARGET, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, MAVLINK_MESSAGE_INFO_SET_ALTITUDE, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_VFR_HUD, MAVLINK_MESSAGE_INFO_COMMAND, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBJECT_DETECTION_EVENT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SET_CAM_SHUTTER, MAVLINK_MESSAGE_INFO_IMAGE_TRIGGERED, MAVLINK_MESSAGE_INFO_IMAGE_TRIGGER_CONTROL, MAVLINK_MESSAGE_INFO_IMAGE_AVAILABLE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VICON_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_SPEED_ESTIMATE, MAVLINK_MESSAGE_INFO_POSITION_CONTROL_SETPOINT_SET, MAVLINK_MESSAGE_INFO_POSITION_CONTROL_OFFSET_SET, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_POSITION_CONTROL_SETPOINT, MAVLINK_MESSAGE_INFO_MARKER, MAVLINK_MESSAGE_INFO_RAW_AUX, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_WATCHDOG_HEARTBEAT, MAVLINK_MESSAGE_INFO_WATCHDOG_PROCESS_INFO, MAVLINK_MESSAGE_INFO_WATCHDOG_PROCESS_STATUS, MAVLINK_MESSAGE_INFO_WATCHDOG_COMMAND, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PATTERN_DETECTED, MAVLINK_MESSAGE_INFO_POINT_OF_INTEREST, MAVLINK_MESSAGE_INFO_POINT_OF_INTEREST_CONNECTION, MAVLINK_MESSAGE_INFO_DATA_TRANSMISSION_HANDSHAKE, MAVLINK_MESSAGE_INFO_ENCAPSULATED_DATA, MAVLINK_MESSAGE_INFO_BRIEF_FEATURE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_ATTITUDE_CONTROL, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_PIXHAWK - -#include "../common/common.h" - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - -/** @brief Content Types for data transmission handshake */ -#ifndef HAVE_ENUM_DATA_TYPES -#define HAVE_ENUM_DATA_TYPES -enum DATA_TYPES -{ - DATA_TYPE_JPEG_IMAGE=1, /* | */ - DATA_TYPE_RAW_IMAGE=2, /* | */ - DATA_TYPE_KINECT=3, /* | */ - DATA_TYPES_ENUM_END=4, /* | */ -}; -#endif - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_set_cam_shutter.h" -#include "./mavlink_msg_image_triggered.h" -#include "./mavlink_msg_image_trigger_control.h" -#include "./mavlink_msg_image_available.h" -#include "./mavlink_msg_vision_position_estimate.h" -#include "./mavlink_msg_vicon_position_estimate.h" -#include "./mavlink_msg_vision_speed_estimate.h" -#include "./mavlink_msg_position_control_setpoint_set.h" -#include "./mavlink_msg_position_control_offset_set.h" -#include "./mavlink_msg_position_control_setpoint.h" -#include "./mavlink_msg_marker.h" -#include "./mavlink_msg_raw_aux.h" -#include "./mavlink_msg_watchdog_heartbeat.h" -#include "./mavlink_msg_watchdog_process_info.h" -#include "./mavlink_msg_watchdog_process_status.h" -#include "./mavlink_msg_watchdog_command.h" -#include "./mavlink_msg_pattern_detected.h" -#include "./mavlink_msg_point_of_interest.h" -#include "./mavlink_msg_point_of_interest_connection.h" -#include "./mavlink_msg_data_transmission_handshake.h" -#include "./mavlink_msg_encapsulated_data.h" -#include "./mavlink_msg_brief_feature.h" -#include "./mavlink_msg_attitude_control.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // PIXHAWK_H diff --git a/mavlink/include/mavlink/v0.9/pixhawk/testsuite.h b/mavlink/include/mavlink/v0.9/pixhawk/testsuite.h deleted file mode 100644 index 3e18abc827..0000000000 --- a/mavlink/include/mavlink/v0.9/pixhawk/testsuite.h +++ /dev/null @@ -1,1312 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from pixhawk.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef PIXHAWK_TESTSUITE_H -#define PIXHAWK_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); -static void mavlink_test_pixhawk(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_test_common(system_id, component_id, last_msg); - mavlink_test_pixhawk(system_id, component_id, last_msg); -} -#endif - -#include "../common/testsuite.h" - - -static void mavlink_test_set_cam_shutter(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_set_cam_shutter_t packet_in = { - 5, - 72, - 139, - 17391, - 17495, - 66.0, - }; - mavlink_set_cam_shutter_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.cam_no = packet_in.cam_no; - packet1.cam_mode = packet_in.cam_mode; - packet1.trigger_pin = packet_in.trigger_pin; - packet1.interval = packet_in.interval; - packet1.exposure = packet_in.exposure; - packet1.gain = packet_in.gain; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_set_cam_shutter_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_set_cam_shutter_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_set_cam_shutter_pack(system_id, component_id, &msg , packet1.cam_no , packet1.cam_mode , packet1.trigger_pin , packet1.interval , packet1.exposure , packet1.gain ); - mavlink_msg_set_cam_shutter_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_set_cam_shutter_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.cam_no , packet1.cam_mode , packet1.trigger_pin , packet1.interval , packet1.exposure , packet1.gain ); - mavlink_msg_set_cam_shutter_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; ilen + MAVLINK_NUM_NON_PAYLOAD_BYTES; -} - -#if MAVLINK_NEED_BYTE_SWAP -static inline void byte_swap_2(char *dst, const char *src) -{ - dst[0] = src[1]; - dst[1] = src[0]; -} -static inline void byte_swap_4(char *dst, const char *src) -{ - dst[0] = src[3]; - dst[1] = src[2]; - dst[2] = src[1]; - dst[3] = src[0]; -} -static inline void byte_swap_8(char *dst, const char *src) -{ - dst[0] = src[7]; - dst[1] = src[6]; - dst[2] = src[5]; - dst[3] = src[4]; - dst[4] = src[3]; - dst[5] = src[2]; - dst[6] = src[1]; - dst[7] = src[0]; -} -#elif !MAVLINK_ALIGNED_FIELDS -static inline void byte_copy_2(char *dst, const char *src) -{ - dst[0] = src[0]; - dst[1] = src[1]; -} -static inline void byte_copy_4(char *dst, const char *src) -{ - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; -} -static inline void byte_copy_8(char *dst, const char *src) -{ - memcpy(dst, src, 8); -} -#endif - -#define _mav_put_uint8_t(buf, wire_offset, b) buf[wire_offset] = (uint8_t)b -#define _mav_put_int8_t(buf, wire_offset, b) buf[wire_offset] = (int8_t)b -#define _mav_put_char(buf, wire_offset, b) buf[wire_offset] = b - -#if MAVLINK_NEED_BYTE_SWAP -#define _mav_put_uint16_t(buf, wire_offset, b) byte_swap_2(&buf[wire_offset], (const char *)&b) -#define _mav_put_int16_t(buf, wire_offset, b) byte_swap_2(&buf[wire_offset], (const char *)&b) -#define _mav_put_uint32_t(buf, wire_offset, b) byte_swap_4(&buf[wire_offset], (const char *)&b) -#define _mav_put_int32_t(buf, wire_offset, b) byte_swap_4(&buf[wire_offset], (const char *)&b) -#define _mav_put_uint64_t(buf, wire_offset, b) byte_swap_8(&buf[wire_offset], (const char *)&b) -#define _mav_put_int64_t(buf, wire_offset, b) byte_swap_8(&buf[wire_offset], (const char *)&b) -#define _mav_put_float(buf, wire_offset, b) byte_swap_4(&buf[wire_offset], (const char *)&b) -#define _mav_put_double(buf, wire_offset, b) byte_swap_8(&buf[wire_offset], (const char *)&b) -#elif !MAVLINK_ALIGNED_FIELDS -#define _mav_put_uint16_t(buf, wire_offset, b) byte_copy_2(&buf[wire_offset], (const char *)&b) -#define _mav_put_int16_t(buf, wire_offset, b) byte_copy_2(&buf[wire_offset], (const char *)&b) -#define _mav_put_uint32_t(buf, wire_offset, b) byte_copy_4(&buf[wire_offset], (const char *)&b) -#define _mav_put_int32_t(buf, wire_offset, b) byte_copy_4(&buf[wire_offset], (const char *)&b) -#define _mav_put_uint64_t(buf, wire_offset, b) byte_copy_8(&buf[wire_offset], (const char *)&b) -#define _mav_put_int64_t(buf, wire_offset, b) byte_copy_8(&buf[wire_offset], (const char *)&b) -#define _mav_put_float(buf, wire_offset, b) byte_copy_4(&buf[wire_offset], (const char *)&b) -#define _mav_put_double(buf, wire_offset, b) byte_copy_8(&buf[wire_offset], (const char *)&b) -#else -#define _mav_put_uint16_t(buf, wire_offset, b) *(uint16_t *)&buf[wire_offset] = b -#define _mav_put_int16_t(buf, wire_offset, b) *(int16_t *)&buf[wire_offset] = b -#define _mav_put_uint32_t(buf, wire_offset, b) *(uint32_t *)&buf[wire_offset] = b -#define _mav_put_int32_t(buf, wire_offset, b) *(int32_t *)&buf[wire_offset] = b -#define _mav_put_uint64_t(buf, wire_offset, b) *(uint64_t *)&buf[wire_offset] = b -#define _mav_put_int64_t(buf, wire_offset, b) *(int64_t *)&buf[wire_offset] = b -#define _mav_put_float(buf, wire_offset, b) *(float *)&buf[wire_offset] = b -#define _mav_put_double(buf, wire_offset, b) *(double *)&buf[wire_offset] = b -#endif - -/* - like memcpy(), but if src is NULL, do a memset to zero - */ -static void mav_array_memcpy(void *dest, const void *src, size_t n) -{ - if (src == NULL) { - memset(dest, 0, n); - } else { - memcpy(dest, src, n); - } -} - -/* - * Place a char array into a buffer - */ -static inline void _mav_put_char_array(char *buf, uint8_t wire_offset, const char *b, uint8_t array_length) -{ - mav_array_memcpy(&buf[wire_offset], b, array_length); -} - -/* - * Place a uint8_t array into a buffer - */ -static inline void _mav_put_uint8_t_array(char *buf, uint8_t wire_offset, const uint8_t *b, uint8_t array_length) -{ - mav_array_memcpy(&buf[wire_offset], b, array_length); -} - -/* - * Place a int8_t array into a buffer - */ -static inline void _mav_put_int8_t_array(char *buf, uint8_t wire_offset, const int8_t *b, uint8_t array_length) -{ - mav_array_memcpy(&buf[wire_offset], b, array_length); -} - -#if MAVLINK_NEED_BYTE_SWAP -#define _MAV_PUT_ARRAY(TYPE, V) \ -static inline void _mav_put_ ## TYPE ##_array(char *buf, uint8_t wire_offset, const TYPE *b, uint8_t array_length) \ -{ \ - if (b == NULL) { \ - memset(&buf[wire_offset], 0, array_length*sizeof(TYPE)); \ - } else { \ - uint16_t i; \ - for (i=0; imsgid = MAVLINK_MSG_ID_AIR_DATA; - return mavlink_finalize_message(msg, system_id, component_id, 10); -} - -/** - * @brief Pack a air_data message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param dynamicPressure Dynamic pressure (Pa) - * @param staticPressure Static pressure (Pa) - * @param temperature Board temperature - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_air_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float dynamicPressure,float staticPressure,uint16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[10]; - _mav_put_float(buf, 0, dynamicPressure); - _mav_put_float(buf, 4, staticPressure); - _mav_put_uint16_t(buf, 8, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 10); -#else - mavlink_air_data_t packet; - packet.dynamicPressure = dynamicPressure; - packet.staticPressure = staticPressure; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 10); -#endif - - msg->msgid = MAVLINK_MSG_ID_AIR_DATA; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 10); -} - -/** - * @brief Encode a air_data struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param air_data C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_air_data_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_air_data_t* air_data) -{ - return mavlink_msg_air_data_pack(system_id, component_id, msg, air_data->dynamicPressure, air_data->staticPressure, air_data->temperature); -} - -/** - * @brief Send a air_data message - * @param chan MAVLink channel to send the message - * - * @param dynamicPressure Dynamic pressure (Pa) - * @param staticPressure Static pressure (Pa) - * @param temperature Board temperature - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_air_data_send(mavlink_channel_t chan, float dynamicPressure, float staticPressure, uint16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[10]; - _mav_put_float(buf, 0, dynamicPressure); - _mav_put_float(buf, 4, staticPressure); - _mav_put_uint16_t(buf, 8, temperature); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AIR_DATA, buf, 10); -#else - mavlink_air_data_t packet; - packet.dynamicPressure = dynamicPressure; - packet.staticPressure = staticPressure; - packet.temperature = temperature; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AIR_DATA, (const char *)&packet, 10); -#endif -} - -#endif - -// MESSAGE AIR_DATA UNPACKING - - -/** - * @brief Get field dynamicPressure from air_data message - * - * @return Dynamic pressure (Pa) - */ -static inline float mavlink_msg_air_data_get_dynamicPressure(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field staticPressure from air_data message - * - * @return Static pressure (Pa) - */ -static inline float mavlink_msg_air_data_get_staticPressure(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field temperature from air_data message - * - * @return Board temperature - */ -static inline uint16_t mavlink_msg_air_data_get_temperature(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Decode a air_data message into a struct - * - * @param msg The message to decode - * @param air_data C-struct to decode the message contents into - */ -static inline void mavlink_msg_air_data_decode(const mavlink_message_t* msg, mavlink_air_data_t* air_data) -{ -#if MAVLINK_NEED_BYTE_SWAP - air_data->dynamicPressure = mavlink_msg_air_data_get_dynamicPressure(msg); - air_data->staticPressure = mavlink_msg_air_data_get_staticPressure(msg); - air_data->temperature = mavlink_msg_air_data_get_temperature(msg); -#else - memcpy(air_data, _MAV_PAYLOAD(msg), 10); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_cpu_load.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_cpu_load.h deleted file mode 100644 index a3bc972f1b..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_cpu_load.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE CPU_LOAD PACKING - -#define MAVLINK_MSG_ID_CPU_LOAD 170 - -typedef struct __mavlink_cpu_load_t -{ - uint8_t sensLoad; ///< Sensor DSC Load - uint8_t ctrlLoad; ///< Control DSC Load - uint16_t batVolt; ///< Battery Voltage in millivolts -} mavlink_cpu_load_t; - -#define MAVLINK_MSG_ID_CPU_LOAD_LEN 4 -#define MAVLINK_MSG_ID_170_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_CPU_LOAD { \ - "CPU_LOAD", \ - 3, \ - { { "sensLoad", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_cpu_load_t, sensLoad) }, \ - { "ctrlLoad", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_cpu_load_t, ctrlLoad) }, \ - { "batVolt", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_cpu_load_t, batVolt) }, \ - } \ -} - - -/** - * @brief Pack a cpu_load message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param sensLoad Sensor DSC Load - * @param ctrlLoad Control DSC Load - * @param batVolt Battery Voltage in millivolts - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_cpu_load_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t sensLoad, uint8_t ctrlLoad, uint16_t batVolt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, sensLoad); - _mav_put_uint8_t(buf, 1, ctrlLoad); - _mav_put_uint16_t(buf, 2, batVolt); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_cpu_load_t packet; - packet.sensLoad = sensLoad; - packet.ctrlLoad = ctrlLoad; - packet.batVolt = batVolt; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_CPU_LOAD; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a cpu_load message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param sensLoad Sensor DSC Load - * @param ctrlLoad Control DSC Load - * @param batVolt Battery Voltage in millivolts - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_cpu_load_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t sensLoad,uint8_t ctrlLoad,uint16_t batVolt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, sensLoad); - _mav_put_uint8_t(buf, 1, ctrlLoad); - _mav_put_uint16_t(buf, 2, batVolt); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_cpu_load_t packet; - packet.sensLoad = sensLoad; - packet.ctrlLoad = ctrlLoad; - packet.batVolt = batVolt; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_CPU_LOAD; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a cpu_load struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param cpu_load C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_cpu_load_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_cpu_load_t* cpu_load) -{ - return mavlink_msg_cpu_load_pack(system_id, component_id, msg, cpu_load->sensLoad, cpu_load->ctrlLoad, cpu_load->batVolt); -} - -/** - * @brief Send a cpu_load message - * @param chan MAVLink channel to send the message - * - * @param sensLoad Sensor DSC Load - * @param ctrlLoad Control DSC Load - * @param batVolt Battery Voltage in millivolts - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_cpu_load_send(mavlink_channel_t chan, uint8_t sensLoad, uint8_t ctrlLoad, uint16_t batVolt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, sensLoad); - _mav_put_uint8_t(buf, 1, ctrlLoad); - _mav_put_uint16_t(buf, 2, batVolt); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CPU_LOAD, buf, 4); -#else - mavlink_cpu_load_t packet; - packet.sensLoad = sensLoad; - packet.ctrlLoad = ctrlLoad; - packet.batVolt = batVolt; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CPU_LOAD, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE CPU_LOAD UNPACKING - - -/** - * @brief Get field sensLoad from cpu_load message - * - * @return Sensor DSC Load - */ -static inline uint8_t mavlink_msg_cpu_load_get_sensLoad(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field ctrlLoad from cpu_load message - * - * @return Control DSC Load - */ -static inline uint8_t mavlink_msg_cpu_load_get_ctrlLoad(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field batVolt from cpu_load message - * - * @return Battery Voltage in millivolts - */ -static inline uint16_t mavlink_msg_cpu_load_get_batVolt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a cpu_load message into a struct - * - * @param msg The message to decode - * @param cpu_load C-struct to decode the message contents into - */ -static inline void mavlink_msg_cpu_load_decode(const mavlink_message_t* msg, mavlink_cpu_load_t* cpu_load) -{ -#if MAVLINK_NEED_BYTE_SWAP - cpu_load->sensLoad = mavlink_msg_cpu_load_get_sensLoad(msg); - cpu_load->ctrlLoad = mavlink_msg_cpu_load_get_ctrlLoad(msg); - cpu_load->batVolt = mavlink_msg_cpu_load_get_batVolt(msg); -#else - memcpy(cpu_load, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_ctrl_srfc_pt.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_ctrl_srfc_pt.h deleted file mode 100644 index d6f94e1dac..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_ctrl_srfc_pt.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE CTRL_SRFC_PT PACKING - -#define MAVLINK_MSG_ID_CTRL_SRFC_PT 181 - -typedef struct __mavlink_ctrl_srfc_pt_t -{ - uint8_t target; ///< The system setting the commands - uint16_t bitfieldPt; ///< Bitfield containing the PT configuration -} mavlink_ctrl_srfc_pt_t; - -#define MAVLINK_MSG_ID_CTRL_SRFC_PT_LEN 3 -#define MAVLINK_MSG_ID_181_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_CTRL_SRFC_PT { \ - "CTRL_SRFC_PT", \ - 2, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_ctrl_srfc_pt_t, target) }, \ - { "bitfieldPt", NULL, MAVLINK_TYPE_UINT16_T, 0, 1, offsetof(mavlink_ctrl_srfc_pt_t, bitfieldPt) }, \ - } \ -} - - -/** - * @brief Pack a ctrl_srfc_pt message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the commands - * @param bitfieldPt Bitfield containing the PT configuration - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint16_t bitfieldPt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint16_t(buf, 1, bitfieldPt); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ctrl_srfc_pt_t packet; - packet.target = target; - packet.bitfieldPt = bitfieldPt; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_CTRL_SRFC_PT; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a ctrl_srfc_pt message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the commands - * @param bitfieldPt Bitfield containing the PT configuration - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint16_t bitfieldPt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint16_t(buf, 1, bitfieldPt); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ctrl_srfc_pt_t packet; - packet.target = target; - packet.bitfieldPt = bitfieldPt; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_CTRL_SRFC_PT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a ctrl_srfc_pt struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ctrl_srfc_pt C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ctrl_srfc_pt_t* ctrl_srfc_pt) -{ - return mavlink_msg_ctrl_srfc_pt_pack(system_id, component_id, msg, ctrl_srfc_pt->target, ctrl_srfc_pt->bitfieldPt); -} - -/** - * @brief Send a ctrl_srfc_pt message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the commands - * @param bitfieldPt Bitfield containing the PT configuration - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ctrl_srfc_pt_send(mavlink_channel_t chan, uint8_t target, uint16_t bitfieldPt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint16_t(buf, 1, bitfieldPt); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CTRL_SRFC_PT, buf, 3); -#else - mavlink_ctrl_srfc_pt_t packet; - packet.target = target; - packet.bitfieldPt = bitfieldPt; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CTRL_SRFC_PT, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE CTRL_SRFC_PT UNPACKING - - -/** - * @brief Get field target from ctrl_srfc_pt message - * - * @return The system setting the commands - */ -static inline uint8_t mavlink_msg_ctrl_srfc_pt_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field bitfieldPt from ctrl_srfc_pt message - * - * @return Bitfield containing the PT configuration - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_get_bitfieldPt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 1); -} - -/** - * @brief Decode a ctrl_srfc_pt message into a struct - * - * @param msg The message to decode - * @param ctrl_srfc_pt C-struct to decode the message contents into - */ -static inline void mavlink_msg_ctrl_srfc_pt_decode(const mavlink_message_t* msg, mavlink_ctrl_srfc_pt_t* ctrl_srfc_pt) -{ -#if MAVLINK_NEED_BYTE_SWAP - ctrl_srfc_pt->target = mavlink_msg_ctrl_srfc_pt_get_target(msg); - ctrl_srfc_pt->bitfieldPt = mavlink_msg_ctrl_srfc_pt_get_bitfieldPt(msg); -#else - memcpy(ctrl_srfc_pt, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_data_log.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_data_log.h deleted file mode 100644 index 19a03e5c68..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_data_log.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE DATA_LOG PACKING - -#define MAVLINK_MSG_ID_DATA_LOG 177 - -typedef struct __mavlink_data_log_t -{ - float fl_1; ///< Log value 1 - float fl_2; ///< Log value 2 - float fl_3; ///< Log value 3 - float fl_4; ///< Log value 4 - float fl_5; ///< Log value 5 - float fl_6; ///< Log value 6 -} mavlink_data_log_t; - -#define MAVLINK_MSG_ID_DATA_LOG_LEN 24 -#define MAVLINK_MSG_ID_177_LEN 24 - - - -#define MAVLINK_MESSAGE_INFO_DATA_LOG { \ - "DATA_LOG", \ - 6, \ - { { "fl_1", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_data_log_t, fl_1) }, \ - { "fl_2", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_data_log_t, fl_2) }, \ - { "fl_3", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_data_log_t, fl_3) }, \ - { "fl_4", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_data_log_t, fl_4) }, \ - { "fl_5", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_data_log_t, fl_5) }, \ - { "fl_6", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_data_log_t, fl_6) }, \ - } \ -} - - -/** - * @brief Pack a data_log message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param fl_1 Log value 1 - * @param fl_2 Log value 2 - * @param fl_3 Log value 3 - * @param fl_4 Log value 4 - * @param fl_5 Log value 5 - * @param fl_6 Log value 6 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_data_log_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float fl_1, float fl_2, float fl_3, float fl_4, float fl_5, float fl_6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, fl_1); - _mav_put_float(buf, 4, fl_2); - _mav_put_float(buf, 8, fl_3); - _mav_put_float(buf, 12, fl_4); - _mav_put_float(buf, 16, fl_5); - _mav_put_float(buf, 20, fl_6); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_data_log_t packet; - packet.fl_1 = fl_1; - packet.fl_2 = fl_2; - packet.fl_3 = fl_3; - packet.fl_4 = fl_4; - packet.fl_5 = fl_5; - packet.fl_6 = fl_6; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_DATA_LOG; - return mavlink_finalize_message(msg, system_id, component_id, 24); -} - -/** - * @brief Pack a data_log message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param fl_1 Log value 1 - * @param fl_2 Log value 2 - * @param fl_3 Log value 3 - * @param fl_4 Log value 4 - * @param fl_5 Log value 5 - * @param fl_6 Log value 6 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_data_log_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float fl_1,float fl_2,float fl_3,float fl_4,float fl_5,float fl_6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, fl_1); - _mav_put_float(buf, 4, fl_2); - _mav_put_float(buf, 8, fl_3); - _mav_put_float(buf, 12, fl_4); - _mav_put_float(buf, 16, fl_5); - _mav_put_float(buf, 20, fl_6); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_data_log_t packet; - packet.fl_1 = fl_1; - packet.fl_2 = fl_2; - packet.fl_3 = fl_3; - packet.fl_4 = fl_4; - packet.fl_5 = fl_5; - packet.fl_6 = fl_6; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_DATA_LOG; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 24); -} - -/** - * @brief Encode a data_log struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param data_log C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_data_log_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data_log_t* data_log) -{ - return mavlink_msg_data_log_pack(system_id, component_id, msg, data_log->fl_1, data_log->fl_2, data_log->fl_3, data_log->fl_4, data_log->fl_5, data_log->fl_6); -} - -/** - * @brief Send a data_log message - * @param chan MAVLink channel to send the message - * - * @param fl_1 Log value 1 - * @param fl_2 Log value 2 - * @param fl_3 Log value 3 - * @param fl_4 Log value 4 - * @param fl_5 Log value 5 - * @param fl_6 Log value 6 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_data_log_send(mavlink_channel_t chan, float fl_1, float fl_2, float fl_3, float fl_4, float fl_5, float fl_6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, fl_1); - _mav_put_float(buf, 4, fl_2); - _mav_put_float(buf, 8, fl_3); - _mav_put_float(buf, 12, fl_4); - _mav_put_float(buf, 16, fl_5); - _mav_put_float(buf, 20, fl_6); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_LOG, buf, 24); -#else - mavlink_data_log_t packet; - packet.fl_1 = fl_1; - packet.fl_2 = fl_2; - packet.fl_3 = fl_3; - packet.fl_4 = fl_4; - packet.fl_5 = fl_5; - packet.fl_6 = fl_6; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_LOG, (const char *)&packet, 24); -#endif -} - -#endif - -// MESSAGE DATA_LOG UNPACKING - - -/** - * @brief Get field fl_1 from data_log message - * - * @return Log value 1 - */ -static inline float mavlink_msg_data_log_get_fl_1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field fl_2 from data_log message - * - * @return Log value 2 - */ -static inline float mavlink_msg_data_log_get_fl_2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field fl_3 from data_log message - * - * @return Log value 3 - */ -static inline float mavlink_msg_data_log_get_fl_3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field fl_4 from data_log message - * - * @return Log value 4 - */ -static inline float mavlink_msg_data_log_get_fl_4(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field fl_5 from data_log message - * - * @return Log value 5 - */ -static inline float mavlink_msg_data_log_get_fl_5(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field fl_6 from data_log message - * - * @return Log value 6 - */ -static inline float mavlink_msg_data_log_get_fl_6(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Decode a data_log message into a struct - * - * @param msg The message to decode - * @param data_log C-struct to decode the message contents into - */ -static inline void mavlink_msg_data_log_decode(const mavlink_message_t* msg, mavlink_data_log_t* data_log) -{ -#if MAVLINK_NEED_BYTE_SWAP - data_log->fl_1 = mavlink_msg_data_log_get_fl_1(msg); - data_log->fl_2 = mavlink_msg_data_log_get_fl_2(msg); - data_log->fl_3 = mavlink_msg_data_log_get_fl_3(msg); - data_log->fl_4 = mavlink_msg_data_log_get_fl_4(msg); - data_log->fl_5 = mavlink_msg_data_log_get_fl_5(msg); - data_log->fl_6 = mavlink_msg_data_log_get_fl_6(msg); -#else - memcpy(data_log, _MAV_PAYLOAD(msg), 24); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_diagnostic.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_diagnostic.h deleted file mode 100644 index 5cdf890aea..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_diagnostic.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE DIAGNOSTIC PACKING - -#define MAVLINK_MSG_ID_DIAGNOSTIC 173 - -typedef struct __mavlink_diagnostic_t -{ - float diagFl1; ///< Diagnostic float 1 - float diagFl2; ///< Diagnostic float 2 - float diagFl3; ///< Diagnostic float 3 - int16_t diagSh1; ///< Diagnostic short 1 - int16_t diagSh2; ///< Diagnostic short 2 - int16_t diagSh3; ///< Diagnostic short 3 -} mavlink_diagnostic_t; - -#define MAVLINK_MSG_ID_DIAGNOSTIC_LEN 18 -#define MAVLINK_MSG_ID_173_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_DIAGNOSTIC { \ - "DIAGNOSTIC", \ - 6, \ - { { "diagFl1", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_diagnostic_t, diagFl1) }, \ - { "diagFl2", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_diagnostic_t, diagFl2) }, \ - { "diagFl3", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_diagnostic_t, diagFl3) }, \ - { "diagSh1", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_diagnostic_t, diagSh1) }, \ - { "diagSh2", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_diagnostic_t, diagSh2) }, \ - { "diagSh3", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_diagnostic_t, diagSh3) }, \ - } \ -} - - -/** - * @brief Pack a diagnostic message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param diagFl1 Diagnostic float 1 - * @param diagFl2 Diagnostic float 2 - * @param diagFl3 Diagnostic float 3 - * @param diagSh1 Diagnostic short 1 - * @param diagSh2 Diagnostic short 2 - * @param diagSh3 Diagnostic short 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_diagnostic_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_float(buf, 0, diagFl1); - _mav_put_float(buf, 4, diagFl2); - _mav_put_float(buf, 8, diagFl3); - _mav_put_int16_t(buf, 12, diagSh1); - _mav_put_int16_t(buf, 14, diagSh2); - _mav_put_int16_t(buf, 16, diagSh3); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_diagnostic_t packet; - packet.diagFl1 = diagFl1; - packet.diagFl2 = diagFl2; - packet.diagFl3 = diagFl3; - packet.diagSh1 = diagSh1; - packet.diagSh2 = diagSh2; - packet.diagSh3 = diagSh3; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIAGNOSTIC; - return mavlink_finalize_message(msg, system_id, component_id, 18); -} - -/** - * @brief Pack a diagnostic message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param diagFl1 Diagnostic float 1 - * @param diagFl2 Diagnostic float 2 - * @param diagFl3 Diagnostic float 3 - * @param diagSh1 Diagnostic short 1 - * @param diagSh2 Diagnostic short 2 - * @param diagSh3 Diagnostic short 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_diagnostic_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float diagFl1,float diagFl2,float diagFl3,int16_t diagSh1,int16_t diagSh2,int16_t diagSh3) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_float(buf, 0, diagFl1); - _mav_put_float(buf, 4, diagFl2); - _mav_put_float(buf, 8, diagFl3); - _mav_put_int16_t(buf, 12, diagSh1); - _mav_put_int16_t(buf, 14, diagSh2); - _mav_put_int16_t(buf, 16, diagSh3); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_diagnostic_t packet; - packet.diagFl1 = diagFl1; - packet.diagFl2 = diagFl2; - packet.diagFl3 = diagFl3; - packet.diagSh1 = diagSh1; - packet.diagSh2 = diagSh2; - packet.diagSh3 = diagSh3; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIAGNOSTIC; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18); -} - -/** - * @brief Encode a diagnostic struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param diagnostic C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_diagnostic_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_diagnostic_t* diagnostic) -{ - return mavlink_msg_diagnostic_pack(system_id, component_id, msg, diagnostic->diagFl1, diagnostic->diagFl2, diagnostic->diagFl3, diagnostic->diagSh1, diagnostic->diagSh2, diagnostic->diagSh3); -} - -/** - * @brief Send a diagnostic message - * @param chan MAVLink channel to send the message - * - * @param diagFl1 Diagnostic float 1 - * @param diagFl2 Diagnostic float 2 - * @param diagFl3 Diagnostic float 3 - * @param diagSh1 Diagnostic short 1 - * @param diagSh2 Diagnostic short 2 - * @param diagSh3 Diagnostic short 3 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_diagnostic_send(mavlink_channel_t chan, float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_float(buf, 0, diagFl1); - _mav_put_float(buf, 4, diagFl2); - _mav_put_float(buf, 8, diagFl3); - _mav_put_int16_t(buf, 12, diagSh1); - _mav_put_int16_t(buf, 14, diagSh2); - _mav_put_int16_t(buf, 16, diagSh3); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIAGNOSTIC, buf, 18); -#else - mavlink_diagnostic_t packet; - packet.diagFl1 = diagFl1; - packet.diagFl2 = diagFl2; - packet.diagFl3 = diagFl3; - packet.diagSh1 = diagSh1; - packet.diagSh2 = diagSh2; - packet.diagSh3 = diagSh3; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIAGNOSTIC, (const char *)&packet, 18); -#endif -} - -#endif - -// MESSAGE DIAGNOSTIC UNPACKING - - -/** - * @brief Get field diagFl1 from diagnostic message - * - * @return Diagnostic float 1 - */ -static inline float mavlink_msg_diagnostic_get_diagFl1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field diagFl2 from diagnostic message - * - * @return Diagnostic float 2 - */ -static inline float mavlink_msg_diagnostic_get_diagFl2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field diagFl3 from diagnostic message - * - * @return Diagnostic float 3 - */ -static inline float mavlink_msg_diagnostic_get_diagFl3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field diagSh1 from diagnostic message - * - * @return Diagnostic short 1 - */ -static inline int16_t mavlink_msg_diagnostic_get_diagSh1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field diagSh2 from diagnostic message - * - * @return Diagnostic short 2 - */ -static inline int16_t mavlink_msg_diagnostic_get_diagSh2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Get field diagSh3 from diagnostic message - * - * @return Diagnostic short 3 - */ -static inline int16_t mavlink_msg_diagnostic_get_diagSh3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 16); -} - -/** - * @brief Decode a diagnostic message into a struct - * - * @param msg The message to decode - * @param diagnostic C-struct to decode the message contents into - */ -static inline void mavlink_msg_diagnostic_decode(const mavlink_message_t* msg, mavlink_diagnostic_t* diagnostic) -{ -#if MAVLINK_NEED_BYTE_SWAP - diagnostic->diagFl1 = mavlink_msg_diagnostic_get_diagFl1(msg); - diagnostic->diagFl2 = mavlink_msg_diagnostic_get_diagFl2(msg); - diagnostic->diagFl3 = mavlink_msg_diagnostic_get_diagFl3(msg); - diagnostic->diagSh1 = mavlink_msg_diagnostic_get_diagSh1(msg); - diagnostic->diagSh2 = mavlink_msg_diagnostic_get_diagSh2(msg); - diagnostic->diagSh3 = mavlink_msg_diagnostic_get_diagSh3(msg); -#else - memcpy(diagnostic, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_gps_date_time.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_gps_date_time.h deleted file mode 100644 index 6104fd7a7b..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_gps_date_time.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE GPS_DATE_TIME PACKING - -#define MAVLINK_MSG_ID_GPS_DATE_TIME 179 - -typedef struct __mavlink_gps_date_time_t -{ - uint8_t year; ///< Year reported by Gps - uint8_t month; ///< Month reported by Gps - uint8_t day; ///< Day reported by Gps - uint8_t hour; ///< Hour reported by Gps - uint8_t min; ///< Min reported by Gps - uint8_t sec; ///< Sec reported by Gps - uint8_t visSat; ///< Visible sattelites reported by Gps -} mavlink_gps_date_time_t; - -#define MAVLINK_MSG_ID_GPS_DATE_TIME_LEN 7 -#define MAVLINK_MSG_ID_179_LEN 7 - - - -#define MAVLINK_MESSAGE_INFO_GPS_DATE_TIME { \ - "GPS_DATE_TIME", \ - 7, \ - { { "year", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_gps_date_time_t, year) }, \ - { "month", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_gps_date_time_t, month) }, \ - { "day", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_gps_date_time_t, day) }, \ - { "hour", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_gps_date_time_t, hour) }, \ - { "min", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_gps_date_time_t, min) }, \ - { "sec", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_gps_date_time_t, sec) }, \ - { "visSat", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_gps_date_time_t, visSat) }, \ - } \ -} - - -/** - * @brief Pack a gps_date_time message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param year Year reported by Gps - * @param month Month reported by Gps - * @param day Day reported by Gps - * @param hour Hour reported by Gps - * @param min Min reported by Gps - * @param sec Sec reported by Gps - * @param visSat Visible sattelites reported by Gps - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_date_time_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec, uint8_t visSat) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[7]; - _mav_put_uint8_t(buf, 0, year); - _mav_put_uint8_t(buf, 1, month); - _mav_put_uint8_t(buf, 2, day); - _mav_put_uint8_t(buf, 3, hour); - _mav_put_uint8_t(buf, 4, min); - _mav_put_uint8_t(buf, 5, sec); - _mav_put_uint8_t(buf, 6, visSat); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 7); -#else - mavlink_gps_date_time_t packet; - packet.year = year; - packet.month = month; - packet.day = day; - packet.hour = hour; - packet.min = min; - packet.sec = sec; - packet.visSat = visSat; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 7); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_DATE_TIME; - return mavlink_finalize_message(msg, system_id, component_id, 7); -} - -/** - * @brief Pack a gps_date_time message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param year Year reported by Gps - * @param month Month reported by Gps - * @param day Day reported by Gps - * @param hour Hour reported by Gps - * @param min Min reported by Gps - * @param sec Sec reported by Gps - * @param visSat Visible sattelites reported by Gps - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_date_time_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t year,uint8_t month,uint8_t day,uint8_t hour,uint8_t min,uint8_t sec,uint8_t visSat) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[7]; - _mav_put_uint8_t(buf, 0, year); - _mav_put_uint8_t(buf, 1, month); - _mav_put_uint8_t(buf, 2, day); - _mav_put_uint8_t(buf, 3, hour); - _mav_put_uint8_t(buf, 4, min); - _mav_put_uint8_t(buf, 5, sec); - _mav_put_uint8_t(buf, 6, visSat); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 7); -#else - mavlink_gps_date_time_t packet; - packet.year = year; - packet.month = month; - packet.day = day; - packet.hour = hour; - packet.min = min; - packet.sec = sec; - packet.visSat = visSat; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 7); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_DATE_TIME; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 7); -} - -/** - * @brief Encode a gps_date_time struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_date_time C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_date_time_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_date_time_t* gps_date_time) -{ - return mavlink_msg_gps_date_time_pack(system_id, component_id, msg, gps_date_time->year, gps_date_time->month, gps_date_time->day, gps_date_time->hour, gps_date_time->min, gps_date_time->sec, gps_date_time->visSat); -} - -/** - * @brief Send a gps_date_time message - * @param chan MAVLink channel to send the message - * - * @param year Year reported by Gps - * @param month Month reported by Gps - * @param day Day reported by Gps - * @param hour Hour reported by Gps - * @param min Min reported by Gps - * @param sec Sec reported by Gps - * @param visSat Visible sattelites reported by Gps - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_date_time_send(mavlink_channel_t chan, uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec, uint8_t visSat) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[7]; - _mav_put_uint8_t(buf, 0, year); - _mav_put_uint8_t(buf, 1, month); - _mav_put_uint8_t(buf, 2, day); - _mav_put_uint8_t(buf, 3, hour); - _mav_put_uint8_t(buf, 4, min); - _mav_put_uint8_t(buf, 5, sec); - _mav_put_uint8_t(buf, 6, visSat); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_DATE_TIME, buf, 7); -#else - mavlink_gps_date_time_t packet; - packet.year = year; - packet.month = month; - packet.day = day; - packet.hour = hour; - packet.min = min; - packet.sec = sec; - packet.visSat = visSat; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_DATE_TIME, (const char *)&packet, 7); -#endif -} - -#endif - -// MESSAGE GPS_DATE_TIME UNPACKING - - -/** - * @brief Get field year from gps_date_time message - * - * @return Year reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_year(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field month from gps_date_time message - * - * @return Month reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_month(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field day from gps_date_time message - * - * @return Day reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_day(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field hour from gps_date_time message - * - * @return Hour reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_hour(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field min from gps_date_time message - * - * @return Min reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_min(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field sec from gps_date_time message - * - * @return Sec reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_sec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field visSat from gps_date_time message - * - * @return Visible sattelites reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_visSat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Decode a gps_date_time message into a struct - * - * @param msg The message to decode - * @param gps_date_time C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_date_time_decode(const mavlink_message_t* msg, mavlink_gps_date_time_t* gps_date_time) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_date_time->year = mavlink_msg_gps_date_time_get_year(msg); - gps_date_time->month = mavlink_msg_gps_date_time_get_month(msg); - gps_date_time->day = mavlink_msg_gps_date_time_get_day(msg); - gps_date_time->hour = mavlink_msg_gps_date_time_get_hour(msg); - gps_date_time->min = mavlink_msg_gps_date_time_get_min(msg); - gps_date_time->sec = mavlink_msg_gps_date_time_get_sec(msg); - gps_date_time->visSat = mavlink_msg_gps_date_time_get_visSat(msg); -#else - memcpy(gps_date_time, _MAV_PAYLOAD(msg), 7); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_mid_lvl_cmds.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_mid_lvl_cmds.h deleted file mode 100644 index 4ae723b440..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_mid_lvl_cmds.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE MID_LVL_CMDS PACKING - -#define MAVLINK_MSG_ID_MID_LVL_CMDS 180 - -typedef struct __mavlink_mid_lvl_cmds_t -{ - uint8_t target; ///< The system setting the commands - float hCommand; ///< Commanded Airspeed - float uCommand; ///< Log value 2 - float rCommand; ///< Log value 3 -} mavlink_mid_lvl_cmds_t; - -#define MAVLINK_MSG_ID_MID_LVL_CMDS_LEN 13 -#define MAVLINK_MSG_ID_180_LEN 13 - - - -#define MAVLINK_MESSAGE_INFO_MID_LVL_CMDS { \ - "MID_LVL_CMDS", \ - 4, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_mid_lvl_cmds_t, target) }, \ - { "hCommand", NULL, MAVLINK_TYPE_FLOAT, 0, 1, offsetof(mavlink_mid_lvl_cmds_t, hCommand) }, \ - { "uCommand", NULL, MAVLINK_TYPE_FLOAT, 0, 5, offsetof(mavlink_mid_lvl_cmds_t, uCommand) }, \ - { "rCommand", NULL, MAVLINK_TYPE_FLOAT, 0, 9, offsetof(mavlink_mid_lvl_cmds_t, rCommand) }, \ - } \ -} - - -/** - * @brief Pack a mid_lvl_cmds message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the commands - * @param hCommand Commanded Airspeed - * @param uCommand Log value 2 - * @param rCommand Log value 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mid_lvl_cmds_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, float hCommand, float uCommand, float rCommand) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, hCommand); - _mav_put_float(buf, 5, uCommand); - _mav_put_float(buf, 9, rCommand); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 13); -#else - mavlink_mid_lvl_cmds_t packet; - packet.target = target; - packet.hCommand = hCommand; - packet.uCommand = uCommand; - packet.rCommand = rCommand; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 13); -#endif - - msg->msgid = MAVLINK_MSG_ID_MID_LVL_CMDS; - return mavlink_finalize_message(msg, system_id, component_id, 13); -} - -/** - * @brief Pack a mid_lvl_cmds message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the commands - * @param hCommand Commanded Airspeed - * @param uCommand Log value 2 - * @param rCommand Log value 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mid_lvl_cmds_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,float hCommand,float uCommand,float rCommand) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, hCommand); - _mav_put_float(buf, 5, uCommand); - _mav_put_float(buf, 9, rCommand); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 13); -#else - mavlink_mid_lvl_cmds_t packet; - packet.target = target; - packet.hCommand = hCommand; - packet.uCommand = uCommand; - packet.rCommand = rCommand; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 13); -#endif - - msg->msgid = MAVLINK_MSG_ID_MID_LVL_CMDS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 13); -} - -/** - * @brief Encode a mid_lvl_cmds struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param mid_lvl_cmds C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_mid_lvl_cmds_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_mid_lvl_cmds_t* mid_lvl_cmds) -{ - return mavlink_msg_mid_lvl_cmds_pack(system_id, component_id, msg, mid_lvl_cmds->target, mid_lvl_cmds->hCommand, mid_lvl_cmds->uCommand, mid_lvl_cmds->rCommand); -} - -/** - * @brief Send a mid_lvl_cmds message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the commands - * @param hCommand Commanded Airspeed - * @param uCommand Log value 2 - * @param rCommand Log value 3 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_mid_lvl_cmds_send(mavlink_channel_t chan, uint8_t target, float hCommand, float uCommand, float rCommand) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_float(buf, 1, hCommand); - _mav_put_float(buf, 5, uCommand); - _mav_put_float(buf, 9, rCommand); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MID_LVL_CMDS, buf, 13); -#else - mavlink_mid_lvl_cmds_t packet; - packet.target = target; - packet.hCommand = hCommand; - packet.uCommand = uCommand; - packet.rCommand = rCommand; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MID_LVL_CMDS, (const char *)&packet, 13); -#endif -} - -#endif - -// MESSAGE MID_LVL_CMDS UNPACKING - - -/** - * @brief Get field target from mid_lvl_cmds message - * - * @return The system setting the commands - */ -static inline uint8_t mavlink_msg_mid_lvl_cmds_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field hCommand from mid_lvl_cmds message - * - * @return Commanded Airspeed - */ -static inline float mavlink_msg_mid_lvl_cmds_get_hCommand(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 1); -} - -/** - * @brief Get field uCommand from mid_lvl_cmds message - * - * @return Log value 2 - */ -static inline float mavlink_msg_mid_lvl_cmds_get_uCommand(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 5); -} - -/** - * @brief Get field rCommand from mid_lvl_cmds message - * - * @return Log value 3 - */ -static inline float mavlink_msg_mid_lvl_cmds_get_rCommand(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 9); -} - -/** - * @brief Decode a mid_lvl_cmds message into a struct - * - * @param msg The message to decode - * @param mid_lvl_cmds C-struct to decode the message contents into - */ -static inline void mavlink_msg_mid_lvl_cmds_decode(const mavlink_message_t* msg, mavlink_mid_lvl_cmds_t* mid_lvl_cmds) -{ -#if MAVLINK_NEED_BYTE_SWAP - mid_lvl_cmds->target = mavlink_msg_mid_lvl_cmds_get_target(msg); - mid_lvl_cmds->hCommand = mavlink_msg_mid_lvl_cmds_get_hCommand(msg); - mid_lvl_cmds->uCommand = mavlink_msg_mid_lvl_cmds_get_uCommand(msg); - mid_lvl_cmds->rCommand = mavlink_msg_mid_lvl_cmds_get_rCommand(msg); -#else - memcpy(mid_lvl_cmds, _MAV_PAYLOAD(msg), 13); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_sensor_bias.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_sensor_bias.h deleted file mode 100644 index 7afb96bd64..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_sensor_bias.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE SENSOR_BIAS PACKING - -#define MAVLINK_MSG_ID_SENSOR_BIAS 172 - -typedef struct __mavlink_sensor_bias_t -{ - float axBias; ///< Accelerometer X bias (m/s) - float ayBias; ///< Accelerometer Y bias (m/s) - float azBias; ///< Accelerometer Z bias (m/s) - float gxBias; ///< Gyro X bias (rad/s) - float gyBias; ///< Gyro Y bias (rad/s) - float gzBias; ///< Gyro Z bias (rad/s) -} mavlink_sensor_bias_t; - -#define MAVLINK_MSG_ID_SENSOR_BIAS_LEN 24 -#define MAVLINK_MSG_ID_172_LEN 24 - - - -#define MAVLINK_MESSAGE_INFO_SENSOR_BIAS { \ - "SENSOR_BIAS", \ - 6, \ - { { "axBias", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_sensor_bias_t, axBias) }, \ - { "ayBias", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_sensor_bias_t, ayBias) }, \ - { "azBias", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_sensor_bias_t, azBias) }, \ - { "gxBias", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_sensor_bias_t, gxBias) }, \ - { "gyBias", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_sensor_bias_t, gyBias) }, \ - { "gzBias", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_sensor_bias_t, gzBias) }, \ - } \ -} - - -/** - * @brief Pack a sensor_bias message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param axBias Accelerometer X bias (m/s) - * @param ayBias Accelerometer Y bias (m/s) - * @param azBias Accelerometer Z bias (m/s) - * @param gxBias Gyro X bias (rad/s) - * @param gyBias Gyro Y bias (rad/s) - * @param gzBias Gyro Z bias (rad/s) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sensor_bias_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float axBias, float ayBias, float azBias, float gxBias, float gyBias, float gzBias) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, axBias); - _mav_put_float(buf, 4, ayBias); - _mav_put_float(buf, 8, azBias); - _mav_put_float(buf, 12, gxBias); - _mav_put_float(buf, 16, gyBias); - _mav_put_float(buf, 20, gzBias); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_sensor_bias_t packet; - packet.axBias = axBias; - packet.ayBias = ayBias; - packet.azBias = azBias; - packet.gxBias = gxBias; - packet.gyBias = gyBias; - packet.gzBias = gzBias; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_SENSOR_BIAS; - return mavlink_finalize_message(msg, system_id, component_id, 24); -} - -/** - * @brief Pack a sensor_bias message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param axBias Accelerometer X bias (m/s) - * @param ayBias Accelerometer Y bias (m/s) - * @param azBias Accelerometer Z bias (m/s) - * @param gxBias Gyro X bias (rad/s) - * @param gyBias Gyro Y bias (rad/s) - * @param gzBias Gyro Z bias (rad/s) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sensor_bias_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float axBias,float ayBias,float azBias,float gxBias,float gyBias,float gzBias) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, axBias); - _mav_put_float(buf, 4, ayBias); - _mav_put_float(buf, 8, azBias); - _mav_put_float(buf, 12, gxBias); - _mav_put_float(buf, 16, gyBias); - _mav_put_float(buf, 20, gzBias); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_sensor_bias_t packet; - packet.axBias = axBias; - packet.ayBias = ayBias; - packet.azBias = azBias; - packet.gxBias = gxBias; - packet.gyBias = gyBias; - packet.gzBias = gzBias; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_SENSOR_BIAS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 24); -} - -/** - * @brief Encode a sensor_bias struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param sensor_bias C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_sensor_bias_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_sensor_bias_t* sensor_bias) -{ - return mavlink_msg_sensor_bias_pack(system_id, component_id, msg, sensor_bias->axBias, sensor_bias->ayBias, sensor_bias->azBias, sensor_bias->gxBias, sensor_bias->gyBias, sensor_bias->gzBias); -} - -/** - * @brief Send a sensor_bias message - * @param chan MAVLink channel to send the message - * - * @param axBias Accelerometer X bias (m/s) - * @param ayBias Accelerometer Y bias (m/s) - * @param azBias Accelerometer Z bias (m/s) - * @param gxBias Gyro X bias (rad/s) - * @param gyBias Gyro Y bias (rad/s) - * @param gzBias Gyro Z bias (rad/s) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_sensor_bias_send(mavlink_channel_t chan, float axBias, float ayBias, float azBias, float gxBias, float gyBias, float gzBias) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, axBias); - _mav_put_float(buf, 4, ayBias); - _mav_put_float(buf, 8, azBias); - _mav_put_float(buf, 12, gxBias); - _mav_put_float(buf, 16, gyBias); - _mav_put_float(buf, 20, gzBias); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SENSOR_BIAS, buf, 24); -#else - mavlink_sensor_bias_t packet; - packet.axBias = axBias; - packet.ayBias = ayBias; - packet.azBias = azBias; - packet.gxBias = gxBias; - packet.gyBias = gyBias; - packet.gzBias = gzBias; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SENSOR_BIAS, (const char *)&packet, 24); -#endif -} - -#endif - -// MESSAGE SENSOR_BIAS UNPACKING - - -/** - * @brief Get field axBias from sensor_bias message - * - * @return Accelerometer X bias (m/s) - */ -static inline float mavlink_msg_sensor_bias_get_axBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field ayBias from sensor_bias message - * - * @return Accelerometer Y bias (m/s) - */ -static inline float mavlink_msg_sensor_bias_get_ayBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field azBias from sensor_bias message - * - * @return Accelerometer Z bias (m/s) - */ -static inline float mavlink_msg_sensor_bias_get_azBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field gxBias from sensor_bias message - * - * @return Gyro X bias (rad/s) - */ -static inline float mavlink_msg_sensor_bias_get_gxBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field gyBias from sensor_bias message - * - * @return Gyro Y bias (rad/s) - */ -static inline float mavlink_msg_sensor_bias_get_gyBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field gzBias from sensor_bias message - * - * @return Gyro Z bias (rad/s) - */ -static inline float mavlink_msg_sensor_bias_get_gzBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Decode a sensor_bias message into a struct - * - * @param msg The message to decode - * @param sensor_bias C-struct to decode the message contents into - */ -static inline void mavlink_msg_sensor_bias_decode(const mavlink_message_t* msg, mavlink_sensor_bias_t* sensor_bias) -{ -#if MAVLINK_NEED_BYTE_SWAP - sensor_bias->axBias = mavlink_msg_sensor_bias_get_axBias(msg); - sensor_bias->ayBias = mavlink_msg_sensor_bias_get_ayBias(msg); - sensor_bias->azBias = mavlink_msg_sensor_bias_get_azBias(msg); - sensor_bias->gxBias = mavlink_msg_sensor_bias_get_gxBias(msg); - sensor_bias->gyBias = mavlink_msg_sensor_bias_get_gyBias(msg); - sensor_bias->gzBias = mavlink_msg_sensor_bias_get_gzBias(msg); -#else - memcpy(sensor_bias, _MAV_PAYLOAD(msg), 24); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_slugs_action.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_slugs_action.h deleted file mode 100644 index da56b98b5a..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_slugs_action.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE SLUGS_ACTION PACKING - -#define MAVLINK_MSG_ID_SLUGS_ACTION 183 - -typedef struct __mavlink_slugs_action_t -{ - uint8_t target; ///< The system reporting the action - uint8_t actionId; ///< Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - uint16_t actionVal; ///< Value associated with the action -} mavlink_slugs_action_t; - -#define MAVLINK_MSG_ID_SLUGS_ACTION_LEN 4 -#define MAVLINK_MSG_ID_183_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_SLUGS_ACTION { \ - "SLUGS_ACTION", \ - 3, \ - { { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_slugs_action_t, target) }, \ - { "actionId", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_slugs_action_t, actionId) }, \ - { "actionVal", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_slugs_action_t, actionVal) }, \ - } \ -} - - -/** - * @brief Pack a slugs_action message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system reporting the action - * @param actionId Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - * @param actionVal Value associated with the action - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_action_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint8_t actionId, uint16_t actionVal) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, actionId); - _mav_put_uint16_t(buf, 2, actionVal); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_slugs_action_t packet; - packet.target = target; - packet.actionId = actionId; - packet.actionVal = actionVal; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_ACTION; - return mavlink_finalize_message(msg, system_id, component_id, 4); -} - -/** - * @brief Pack a slugs_action message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system reporting the action - * @param actionId Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - * @param actionVal Value associated with the action - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_action_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint8_t actionId,uint16_t actionVal) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, actionId); - _mav_put_uint16_t(buf, 2, actionVal); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_slugs_action_t packet; - packet.target = target; - packet.actionId = actionId; - packet.actionVal = actionVal; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_ACTION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4); -} - -/** - * @brief Encode a slugs_action struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param slugs_action C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_slugs_action_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_slugs_action_t* slugs_action) -{ - return mavlink_msg_slugs_action_pack(system_id, component_id, msg, slugs_action->target, slugs_action->actionId, slugs_action->actionVal); -} - -/** - * @brief Send a slugs_action message - * @param chan MAVLink channel to send the message - * - * @param target The system reporting the action - * @param actionId Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - * @param actionVal Value associated with the action - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_slugs_action_send(mavlink_channel_t chan, uint8_t target, uint8_t actionId, uint16_t actionVal) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint8_t(buf, 0, target); - _mav_put_uint8_t(buf, 1, actionId); - _mav_put_uint16_t(buf, 2, actionVal); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_ACTION, buf, 4); -#else - mavlink_slugs_action_t packet; - packet.target = target; - packet.actionId = actionId; - packet.actionVal = actionVal; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_ACTION, (const char *)&packet, 4); -#endif -} - -#endif - -// MESSAGE SLUGS_ACTION UNPACKING - - -/** - * @brief Get field target from slugs_action message - * - * @return The system reporting the action - */ -static inline uint8_t mavlink_msg_slugs_action_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field actionId from slugs_action message - * - * @return Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - */ -static inline uint8_t mavlink_msg_slugs_action_get_actionId(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field actionVal from slugs_action message - * - * @return Value associated with the action - */ -static inline uint16_t mavlink_msg_slugs_action_get_actionVal(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 2); -} - -/** - * @brief Decode a slugs_action message into a struct - * - * @param msg The message to decode - * @param slugs_action C-struct to decode the message contents into - */ -static inline void mavlink_msg_slugs_action_decode(const mavlink_message_t* msg, mavlink_slugs_action_t* slugs_action) -{ -#if MAVLINK_NEED_BYTE_SWAP - slugs_action->target = mavlink_msg_slugs_action_get_target(msg); - slugs_action->actionId = mavlink_msg_slugs_action_get_actionId(msg); - slugs_action->actionVal = mavlink_msg_slugs_action_get_actionVal(msg); -#else - memcpy(slugs_action, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_slugs_navigation.h b/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_slugs_navigation.h deleted file mode 100644 index b81bde72ff..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/mavlink_msg_slugs_navigation.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE SLUGS_NAVIGATION PACKING - -#define MAVLINK_MSG_ID_SLUGS_NAVIGATION 176 - -typedef struct __mavlink_slugs_navigation_t -{ - float u_m; ///< Measured Airspeed prior to the Nav Filter - float phi_c; ///< Commanded Roll - float theta_c; ///< Commanded Pitch - float psiDot_c; ///< Commanded Turn rate - float ay_body; ///< Y component of the body acceleration - float totalDist; ///< Total Distance to Run on this leg of Navigation - float dist2Go; ///< Remaining distance to Run on this leg of Navigation - uint8_t fromWP; ///< Origin WP - uint8_t toWP; ///< Destination WP -} mavlink_slugs_navigation_t; - -#define MAVLINK_MSG_ID_SLUGS_NAVIGATION_LEN 30 -#define MAVLINK_MSG_ID_176_LEN 30 - - - -#define MAVLINK_MESSAGE_INFO_SLUGS_NAVIGATION { \ - "SLUGS_NAVIGATION", \ - 9, \ - { { "u_m", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_slugs_navigation_t, u_m) }, \ - { "phi_c", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_slugs_navigation_t, phi_c) }, \ - { "theta_c", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_slugs_navigation_t, theta_c) }, \ - { "psiDot_c", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_slugs_navigation_t, psiDot_c) }, \ - { "ay_body", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_slugs_navigation_t, ay_body) }, \ - { "totalDist", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_slugs_navigation_t, totalDist) }, \ - { "dist2Go", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_slugs_navigation_t, dist2Go) }, \ - { "fromWP", NULL, MAVLINK_TYPE_UINT8_T, 0, 28, offsetof(mavlink_slugs_navigation_t, fromWP) }, \ - { "toWP", NULL, MAVLINK_TYPE_UINT8_T, 0, 29, offsetof(mavlink_slugs_navigation_t, toWP) }, \ - } \ -} - - -/** - * @brief Pack a slugs_navigation message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param u_m Measured Airspeed prior to the Nav Filter - * @param phi_c Commanded Roll - * @param theta_c Commanded Pitch - * @param psiDot_c Commanded Turn rate - * @param ay_body Y component of the body acceleration - * @param totalDist Total Distance to Run on this leg of Navigation - * @param dist2Go Remaining distance to Run on this leg of Navigation - * @param fromWP Origin WP - * @param toWP Destination WP - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_navigation_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float u_m, float phi_c, float theta_c, float psiDot_c, float ay_body, float totalDist, float dist2Go, uint8_t fromWP, uint8_t toWP) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_float(buf, 0, u_m); - _mav_put_float(buf, 4, phi_c); - _mav_put_float(buf, 8, theta_c); - _mav_put_float(buf, 12, psiDot_c); - _mav_put_float(buf, 16, ay_body); - _mav_put_float(buf, 20, totalDist); - _mav_put_float(buf, 24, dist2Go); - _mav_put_uint8_t(buf, 28, fromWP); - _mav_put_uint8_t(buf, 29, toWP); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 30); -#else - mavlink_slugs_navigation_t packet; - packet.u_m = u_m; - packet.phi_c = phi_c; - packet.theta_c = theta_c; - packet.psiDot_c = psiDot_c; - packet.ay_body = ay_body; - packet.totalDist = totalDist; - packet.dist2Go = dist2Go; - packet.fromWP = fromWP; - packet.toWP = toWP; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 30); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_NAVIGATION; - return mavlink_finalize_message(msg, system_id, component_id, 30); -} - -/** - * @brief Pack a slugs_navigation message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param u_m Measured Airspeed prior to the Nav Filter - * @param phi_c Commanded Roll - * @param theta_c Commanded Pitch - * @param psiDot_c Commanded Turn rate - * @param ay_body Y component of the body acceleration - * @param totalDist Total Distance to Run on this leg of Navigation - * @param dist2Go Remaining distance to Run on this leg of Navigation - * @param fromWP Origin WP - * @param toWP Destination WP - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_navigation_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float u_m,float phi_c,float theta_c,float psiDot_c,float ay_body,float totalDist,float dist2Go,uint8_t fromWP,uint8_t toWP) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_float(buf, 0, u_m); - _mav_put_float(buf, 4, phi_c); - _mav_put_float(buf, 8, theta_c); - _mav_put_float(buf, 12, psiDot_c); - _mav_put_float(buf, 16, ay_body); - _mav_put_float(buf, 20, totalDist); - _mav_put_float(buf, 24, dist2Go); - _mav_put_uint8_t(buf, 28, fromWP); - _mav_put_uint8_t(buf, 29, toWP); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 30); -#else - mavlink_slugs_navigation_t packet; - packet.u_m = u_m; - packet.phi_c = phi_c; - packet.theta_c = theta_c; - packet.psiDot_c = psiDot_c; - packet.ay_body = ay_body; - packet.totalDist = totalDist; - packet.dist2Go = dist2Go; - packet.fromWP = fromWP; - packet.toWP = toWP; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 30); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_NAVIGATION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 30); -} - -/** - * @brief Encode a slugs_navigation struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param slugs_navigation C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_slugs_navigation_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_slugs_navigation_t* slugs_navigation) -{ - return mavlink_msg_slugs_navigation_pack(system_id, component_id, msg, slugs_navigation->u_m, slugs_navigation->phi_c, slugs_navigation->theta_c, slugs_navigation->psiDot_c, slugs_navigation->ay_body, slugs_navigation->totalDist, slugs_navigation->dist2Go, slugs_navigation->fromWP, slugs_navigation->toWP); -} - -/** - * @brief Send a slugs_navigation message - * @param chan MAVLink channel to send the message - * - * @param u_m Measured Airspeed prior to the Nav Filter - * @param phi_c Commanded Roll - * @param theta_c Commanded Pitch - * @param psiDot_c Commanded Turn rate - * @param ay_body Y component of the body acceleration - * @param totalDist Total Distance to Run on this leg of Navigation - * @param dist2Go Remaining distance to Run on this leg of Navigation - * @param fromWP Origin WP - * @param toWP Destination WP - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_slugs_navigation_send(mavlink_channel_t chan, float u_m, float phi_c, float theta_c, float psiDot_c, float ay_body, float totalDist, float dist2Go, uint8_t fromWP, uint8_t toWP) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_float(buf, 0, u_m); - _mav_put_float(buf, 4, phi_c); - _mav_put_float(buf, 8, theta_c); - _mav_put_float(buf, 12, psiDot_c); - _mav_put_float(buf, 16, ay_body); - _mav_put_float(buf, 20, totalDist); - _mav_put_float(buf, 24, dist2Go); - _mav_put_uint8_t(buf, 28, fromWP); - _mav_put_uint8_t(buf, 29, toWP); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_NAVIGATION, buf, 30); -#else - mavlink_slugs_navigation_t packet; - packet.u_m = u_m; - packet.phi_c = phi_c; - packet.theta_c = theta_c; - packet.psiDot_c = psiDot_c; - packet.ay_body = ay_body; - packet.totalDist = totalDist; - packet.dist2Go = dist2Go; - packet.fromWP = fromWP; - packet.toWP = toWP; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_NAVIGATION, (const char *)&packet, 30); -#endif -} - -#endif - -// MESSAGE SLUGS_NAVIGATION UNPACKING - - -/** - * @brief Get field u_m from slugs_navigation message - * - * @return Measured Airspeed prior to the Nav Filter - */ -static inline float mavlink_msg_slugs_navigation_get_u_m(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field phi_c from slugs_navigation message - * - * @return Commanded Roll - */ -static inline float mavlink_msg_slugs_navigation_get_phi_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field theta_c from slugs_navigation message - * - * @return Commanded Pitch - */ -static inline float mavlink_msg_slugs_navigation_get_theta_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field psiDot_c from slugs_navigation message - * - * @return Commanded Turn rate - */ -static inline float mavlink_msg_slugs_navigation_get_psiDot_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field ay_body from slugs_navigation message - * - * @return Y component of the body acceleration - */ -static inline float mavlink_msg_slugs_navigation_get_ay_body(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field totalDist from slugs_navigation message - * - * @return Total Distance to Run on this leg of Navigation - */ -static inline float mavlink_msg_slugs_navigation_get_totalDist(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field dist2Go from slugs_navigation message - * - * @return Remaining distance to Run on this leg of Navigation - */ -static inline float mavlink_msg_slugs_navigation_get_dist2Go(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field fromWP from slugs_navigation message - * - * @return Origin WP - */ -static inline uint8_t mavlink_msg_slugs_navigation_get_fromWP(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 28); -} - -/** - * @brief Get field toWP from slugs_navigation message - * - * @return Destination WP - */ -static inline uint8_t mavlink_msg_slugs_navigation_get_toWP(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 29); -} - -/** - * @brief Decode a slugs_navigation message into a struct - * - * @param msg The message to decode - * @param slugs_navigation C-struct to decode the message contents into - */ -static inline void mavlink_msg_slugs_navigation_decode(const mavlink_message_t* msg, mavlink_slugs_navigation_t* slugs_navigation) -{ -#if MAVLINK_NEED_BYTE_SWAP - slugs_navigation->u_m = mavlink_msg_slugs_navigation_get_u_m(msg); - slugs_navigation->phi_c = mavlink_msg_slugs_navigation_get_phi_c(msg); - slugs_navigation->theta_c = mavlink_msg_slugs_navigation_get_theta_c(msg); - slugs_navigation->psiDot_c = mavlink_msg_slugs_navigation_get_psiDot_c(msg); - slugs_navigation->ay_body = mavlink_msg_slugs_navigation_get_ay_body(msg); - slugs_navigation->totalDist = mavlink_msg_slugs_navigation_get_totalDist(msg); - slugs_navigation->dist2Go = mavlink_msg_slugs_navigation_get_dist2Go(msg); - slugs_navigation->fromWP = mavlink_msg_slugs_navigation_get_fromWP(msg); - slugs_navigation->toWP = mavlink_msg_slugs_navigation_get_toWP(msg); -#else - memcpy(slugs_navigation, _MAV_PAYLOAD(msg), 30); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/slugs/slugs.h b/mavlink/include/mavlink/v0.9/slugs/slugs.h deleted file mode 100644 index 27f4e10bee..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/slugs.h +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from slugs.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef SLUGS_H -#define SLUGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {3, 4, 8, 14, 8, 28, 3, 32, 0, 2, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 19, 2, 23, 21, 0, 37, 26, 101, 26, 16, 32, 32, 37, 32, 11, 17, 17, 16, 18, 36, 4, 4, 2, 2, 4, 2, 2, 3, 14, 12, 18, 16, 8, 27, 25, 18, 18, 24, 24, 0, 0, 0, 26, 16, 36, 5, 6, 56, 26, 21, 18, 0, 0, 18, 20, 20, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 10, 24, 18, 0, 0, 30, 24, 0, 7, 13, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 14, 14, 51, 5} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {72, 39, 190, 92, 191, 217, 104, 119, 0, 219, 60, 186, 10, 0, 0, 0, 0, 0, 0, 0, 89, 159, 162, 121, 0, 149, 222, 110, 179, 136, 66, 126, 185, 147, 112, 252, 162, 215, 229, 128, 9, 106, 101, 213, 4, 229, 21, 214, 215, 14, 206, 50, 157, 126, 108, 213, 95, 5, 127, 0, 0, 0, 57, 126, 130, 119, 193, 191, 236, 158, 143, 0, 0, 104, 123, 131, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150, 232, 168, 2, 0, 0, 120, 167, 0, 16, 2, 52, 0, 202, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 224, 60, 106, 7} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_BOOT, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_SYSTEM_TIME_UTC, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_ACTION_ACK, MAVLINK_MESSAGE_INFO_ACTION, MAVLINK_MESSAGE_INFO_SET_MODE, MAVLINK_MESSAGE_INFO_SET_NAV_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_LOCAL_POSITION, MAVLINK_MESSAGE_INFO_GPS_RAW, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_WAYPOINT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST, MAVLINK_MESSAGE_INFO_WAYPOINT_SET_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_CURRENT, MAVLINK_MESSAGE_INFO_WAYPOINT_REQUEST_LIST, MAVLINK_MESSAGE_INFO_WAYPOINT_COUNT, MAVLINK_MESSAGE_INFO_WAYPOINT_CLEAR_ALL, MAVLINK_MESSAGE_INFO_WAYPOINT_REACHED, MAVLINK_MESSAGE_INFO_WAYPOINT_ACK, MAVLINK_MESSAGE_INFO_GPS_SET_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_LOCAL_ORIGIN_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT_SET, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_CONTROL_STATUS, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, MAVLINK_MESSAGE_INFO_POSITION_TARGET, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, MAVLINK_MESSAGE_INFO_SET_ALTITUDE, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_VFR_HUD, MAVLINK_MESSAGE_INFO_COMMAND, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBJECT_DETECTION_EVENT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_CPU_LOAD, MAVLINK_MESSAGE_INFO_AIR_DATA, MAVLINK_MESSAGE_INFO_SENSOR_BIAS, MAVLINK_MESSAGE_INFO_DIAGNOSTIC, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SLUGS_NAVIGATION, MAVLINK_MESSAGE_INFO_DATA_LOG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GPS_DATE_TIME, MAVLINK_MESSAGE_INFO_MID_LVL_CMDS, MAVLINK_MESSAGE_INFO_CTRL_SRFC_PT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SLUGS_ACTION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_SLUGS - -#include "../common/common.h" - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_cpu_load.h" -#include "./mavlink_msg_air_data.h" -#include "./mavlink_msg_sensor_bias.h" -#include "./mavlink_msg_diagnostic.h" -#include "./mavlink_msg_slugs_navigation.h" -#include "./mavlink_msg_data_log.h" -#include "./mavlink_msg_gps_date_time.h" -#include "./mavlink_msg_mid_lvl_cmds.h" -#include "./mavlink_msg_ctrl_srfc_pt.h" -#include "./mavlink_msg_slugs_action.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // SLUGS_H diff --git a/mavlink/include/mavlink/v0.9/slugs/testsuite.h b/mavlink/include/mavlink/v0.9/slugs/testsuite.h deleted file mode 100644 index d1596a8164..0000000000 --- a/mavlink/include/mavlink/v0.9/slugs/testsuite.h +++ /dev/null @@ -1,552 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from slugs.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef SLUGS_TESTSUITE_H -#define SLUGS_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); -static void mavlink_test_slugs(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_test_common(system_id, component_id, last_msg); - mavlink_test_slugs(system_id, component_id, last_msg); -} -#endif - -#include "../common/testsuite.h" - - -static void mavlink_test_cpu_load(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_cpu_load_t packet_in = { - 5, - 72, - 17339, - }; - mavlink_cpu_load_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.sensLoad = packet_in.sensLoad; - packet1.ctrlLoad = packet_in.ctrlLoad; - packet1.batVolt = packet_in.batVolt; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_cpu_load_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_cpu_load_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_cpu_load_pack(system_id, component_id, &msg , packet1.sensLoad , packet1.ctrlLoad , packet1.batVolt ); - mavlink_msg_cpu_load_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_cpu_load_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.sensLoad , packet1.ctrlLoad , packet1.batVolt ); - mavlink_msg_cpu_load_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imsgid = MAVLINK_MSG_ID_TEST_TYPES; - return mavlink_finalize_message(msg, system_id, component_id, 179); -} - -/** - * @brief Pack a test_types message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param c char - * @param s string - * @param u8 uint8_t - * @param u16 uint16_t - * @param u32 uint32_t - * @param u64 uint64_t - * @param s8 int8_t - * @param s16 int16_t - * @param s32 int32_t - * @param s64 int64_t - * @param f float - * @param d double - * @param u8_array uint8_t_array - * @param u16_array uint16_t_array - * @param u32_array uint32_t_array - * @param u64_array uint64_t_array - * @param s8_array int8_t_array - * @param s16_array int16_t_array - * @param s32_array int32_t_array - * @param s64_array int64_t_array - * @param f_array float_array - * @param d_array double_array - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_test_types_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - char c,const char *s,uint8_t u8,uint16_t u16,uint32_t u32,uint64_t u64,int8_t s8,int16_t s16,int32_t s32,int64_t s64,float f,double d,const uint8_t *u8_array,const uint16_t *u16_array,const uint32_t *u32_array,const uint64_t *u64_array,const int8_t *s8_array,const int16_t *s16_array,const int32_t *s32_array,const int64_t *s64_array,const float *f_array,const double *d_array) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[179]; - _mav_put_char(buf, 0, c); - _mav_put_uint8_t(buf, 11, u8); - _mav_put_uint16_t(buf, 12, u16); - _mav_put_uint32_t(buf, 14, u32); - _mav_put_uint64_t(buf, 18, u64); - _mav_put_int8_t(buf, 26, s8); - _mav_put_int16_t(buf, 27, s16); - _mav_put_int32_t(buf, 29, s32); - _mav_put_int64_t(buf, 33, s64); - _mav_put_float(buf, 41, f); - _mav_put_double(buf, 45, d); - _mav_put_char_array(buf, 1, s, 10); - _mav_put_uint8_t_array(buf, 53, u8_array, 3); - _mav_put_uint16_t_array(buf, 56, u16_array, 3); - _mav_put_uint32_t_array(buf, 62, u32_array, 3); - _mav_put_uint64_t_array(buf, 74, u64_array, 3); - _mav_put_int8_t_array(buf, 98, s8_array, 3); - _mav_put_int16_t_array(buf, 101, s16_array, 3); - _mav_put_int32_t_array(buf, 107, s32_array, 3); - _mav_put_int64_t_array(buf, 119, s64_array, 3); - _mav_put_float_array(buf, 143, f_array, 3); - _mav_put_double_array(buf, 155, d_array, 3); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 179); -#else - mavlink_test_types_t packet; - packet.c = c; - packet.u8 = u8; - packet.u16 = u16; - packet.u32 = u32; - packet.u64 = u64; - packet.s8 = s8; - packet.s16 = s16; - packet.s32 = s32; - packet.s64 = s64; - packet.f = f; - packet.d = d; - mav_array_memcpy(packet.s, s, sizeof(char)*10); - mav_array_memcpy(packet.u8_array, u8_array, sizeof(uint8_t)*3); - mav_array_memcpy(packet.u16_array, u16_array, sizeof(uint16_t)*3); - mav_array_memcpy(packet.u32_array, u32_array, sizeof(uint32_t)*3); - mav_array_memcpy(packet.u64_array, u64_array, sizeof(uint64_t)*3); - mav_array_memcpy(packet.s8_array, s8_array, sizeof(int8_t)*3); - mav_array_memcpy(packet.s16_array, s16_array, sizeof(int16_t)*3); - mav_array_memcpy(packet.s32_array, s32_array, sizeof(int32_t)*3); - mav_array_memcpy(packet.s64_array, s64_array, sizeof(int64_t)*3); - mav_array_memcpy(packet.f_array, f_array, sizeof(float)*3); - mav_array_memcpy(packet.d_array, d_array, sizeof(double)*3); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 179); -#endif - - msg->msgid = MAVLINK_MSG_ID_TEST_TYPES; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 179); -} - -/** - * @brief Encode a test_types struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param test_types C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_test_types_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_test_types_t* test_types) -{ - return mavlink_msg_test_types_pack(system_id, component_id, msg, test_types->c, test_types->s, test_types->u8, test_types->u16, test_types->u32, test_types->u64, test_types->s8, test_types->s16, test_types->s32, test_types->s64, test_types->f, test_types->d, test_types->u8_array, test_types->u16_array, test_types->u32_array, test_types->u64_array, test_types->s8_array, test_types->s16_array, test_types->s32_array, test_types->s64_array, test_types->f_array, test_types->d_array); -} - -/** - * @brief Send a test_types message - * @param chan MAVLink channel to send the message - * - * @param c char - * @param s string - * @param u8 uint8_t - * @param u16 uint16_t - * @param u32 uint32_t - * @param u64 uint64_t - * @param s8 int8_t - * @param s16 int16_t - * @param s32 int32_t - * @param s64 int64_t - * @param f float - * @param d double - * @param u8_array uint8_t_array - * @param u16_array uint16_t_array - * @param u32_array uint32_t_array - * @param u64_array uint64_t_array - * @param s8_array int8_t_array - * @param s16_array int16_t_array - * @param s32_array int32_t_array - * @param s64_array int64_t_array - * @param f_array float_array - * @param d_array double_array - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_test_types_send(mavlink_channel_t chan, char c, const char *s, uint8_t u8, uint16_t u16, uint32_t u32, uint64_t u64, int8_t s8, int16_t s16, int32_t s32, int64_t s64, float f, double d, const uint8_t *u8_array, const uint16_t *u16_array, const uint32_t *u32_array, const uint64_t *u64_array, const int8_t *s8_array, const int16_t *s16_array, const int32_t *s32_array, const int64_t *s64_array, const float *f_array, const double *d_array) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[179]; - _mav_put_char(buf, 0, c); - _mav_put_uint8_t(buf, 11, u8); - _mav_put_uint16_t(buf, 12, u16); - _mav_put_uint32_t(buf, 14, u32); - _mav_put_uint64_t(buf, 18, u64); - _mav_put_int8_t(buf, 26, s8); - _mav_put_int16_t(buf, 27, s16); - _mav_put_int32_t(buf, 29, s32); - _mav_put_int64_t(buf, 33, s64); - _mav_put_float(buf, 41, f); - _mav_put_double(buf, 45, d); - _mav_put_char_array(buf, 1, s, 10); - _mav_put_uint8_t_array(buf, 53, u8_array, 3); - _mav_put_uint16_t_array(buf, 56, u16_array, 3); - _mav_put_uint32_t_array(buf, 62, u32_array, 3); - _mav_put_uint64_t_array(buf, 74, u64_array, 3); - _mav_put_int8_t_array(buf, 98, s8_array, 3); - _mav_put_int16_t_array(buf, 101, s16_array, 3); - _mav_put_int32_t_array(buf, 107, s32_array, 3); - _mav_put_int64_t_array(buf, 119, s64_array, 3); - _mav_put_float_array(buf, 143, f_array, 3); - _mav_put_double_array(buf, 155, d_array, 3); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TEST_TYPES, buf, 179); -#else - mavlink_test_types_t packet; - packet.c = c; - packet.u8 = u8; - packet.u16 = u16; - packet.u32 = u32; - packet.u64 = u64; - packet.s8 = s8; - packet.s16 = s16; - packet.s32 = s32; - packet.s64 = s64; - packet.f = f; - packet.d = d; - mav_array_memcpy(packet.s, s, sizeof(char)*10); - mav_array_memcpy(packet.u8_array, u8_array, sizeof(uint8_t)*3); - mav_array_memcpy(packet.u16_array, u16_array, sizeof(uint16_t)*3); - mav_array_memcpy(packet.u32_array, u32_array, sizeof(uint32_t)*3); - mav_array_memcpy(packet.u64_array, u64_array, sizeof(uint64_t)*3); - mav_array_memcpy(packet.s8_array, s8_array, sizeof(int8_t)*3); - mav_array_memcpy(packet.s16_array, s16_array, sizeof(int16_t)*3); - mav_array_memcpy(packet.s32_array, s32_array, sizeof(int32_t)*3); - mav_array_memcpy(packet.s64_array, s64_array, sizeof(int64_t)*3); - mav_array_memcpy(packet.f_array, f_array, sizeof(float)*3); - mav_array_memcpy(packet.d_array, d_array, sizeof(double)*3); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TEST_TYPES, (const char *)&packet, 179); -#endif -} - -#endif - -// MESSAGE TEST_TYPES UNPACKING - - -/** - * @brief Get field c from test_types message - * - * @return char - */ -static inline char mavlink_msg_test_types_get_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_char(msg, 0); -} - -/** - * @brief Get field s from test_types message - * - * @return string - */ -static inline uint16_t mavlink_msg_test_types_get_s(const mavlink_message_t* msg, char *s) -{ - return _MAV_RETURN_char_array(msg, s, 10, 1); -} - -/** - * @brief Get field u8 from test_types message - * - * @return uint8_t - */ -static inline uint8_t mavlink_msg_test_types_get_u8(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 11); -} - -/** - * @brief Get field u16 from test_types message - * - * @return uint16_t - */ -static inline uint16_t mavlink_msg_test_types_get_u16(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 12); -} - -/** - * @brief Get field u32 from test_types message - * - * @return uint32_t - */ -static inline uint32_t mavlink_msg_test_types_get_u32(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 14); -} - -/** - * @brief Get field u64 from test_types message - * - * @return uint64_t - */ -static inline uint64_t mavlink_msg_test_types_get_u64(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 18); -} - -/** - * @brief Get field s8 from test_types message - * - * @return int8_t - */ -static inline int8_t mavlink_msg_test_types_get_s8(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int8_t(msg, 26); -} - -/** - * @brief Get field s16 from test_types message - * - * @return int16_t - */ -static inline int16_t mavlink_msg_test_types_get_s16(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 27); -} - -/** - * @brief Get field s32 from test_types message - * - * @return int32_t - */ -static inline int32_t mavlink_msg_test_types_get_s32(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 29); -} - -/** - * @brief Get field s64 from test_types message - * - * @return int64_t - */ -static inline int64_t mavlink_msg_test_types_get_s64(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int64_t(msg, 33); -} - -/** - * @brief Get field f from test_types message - * - * @return float - */ -static inline float mavlink_msg_test_types_get_f(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 41); -} - -/** - * @brief Get field d from test_types message - * - * @return double - */ -static inline double mavlink_msg_test_types_get_d(const mavlink_message_t* msg) -{ - return _MAV_RETURN_double(msg, 45); -} - -/** - * @brief Get field u8_array from test_types message - * - * @return uint8_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u8_array(const mavlink_message_t* msg, uint8_t *u8_array) -{ - return _MAV_RETURN_uint8_t_array(msg, u8_array, 3, 53); -} - -/** - * @brief Get field u16_array from test_types message - * - * @return uint16_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u16_array(const mavlink_message_t* msg, uint16_t *u16_array) -{ - return _MAV_RETURN_uint16_t_array(msg, u16_array, 3, 56); -} - -/** - * @brief Get field u32_array from test_types message - * - * @return uint32_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u32_array(const mavlink_message_t* msg, uint32_t *u32_array) -{ - return _MAV_RETURN_uint32_t_array(msg, u32_array, 3, 62); -} - -/** - * @brief Get field u64_array from test_types message - * - * @return uint64_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u64_array(const mavlink_message_t* msg, uint64_t *u64_array) -{ - return _MAV_RETURN_uint64_t_array(msg, u64_array, 3, 74); -} - -/** - * @brief Get field s8_array from test_types message - * - * @return int8_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s8_array(const mavlink_message_t* msg, int8_t *s8_array) -{ - return _MAV_RETURN_int8_t_array(msg, s8_array, 3, 98); -} - -/** - * @brief Get field s16_array from test_types message - * - * @return int16_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s16_array(const mavlink_message_t* msg, int16_t *s16_array) -{ - return _MAV_RETURN_int16_t_array(msg, s16_array, 3, 101); -} - -/** - * @brief Get field s32_array from test_types message - * - * @return int32_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s32_array(const mavlink_message_t* msg, int32_t *s32_array) -{ - return _MAV_RETURN_int32_t_array(msg, s32_array, 3, 107); -} - -/** - * @brief Get field s64_array from test_types message - * - * @return int64_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s64_array(const mavlink_message_t* msg, int64_t *s64_array) -{ - return _MAV_RETURN_int64_t_array(msg, s64_array, 3, 119); -} - -/** - * @brief Get field f_array from test_types message - * - * @return float_array - */ -static inline uint16_t mavlink_msg_test_types_get_f_array(const mavlink_message_t* msg, float *f_array) -{ - return _MAV_RETURN_float_array(msg, f_array, 3, 143); -} - -/** - * @brief Get field d_array from test_types message - * - * @return double_array - */ -static inline uint16_t mavlink_msg_test_types_get_d_array(const mavlink_message_t* msg, double *d_array) -{ - return _MAV_RETURN_double_array(msg, d_array, 3, 155); -} - -/** - * @brief Decode a test_types message into a struct - * - * @param msg The message to decode - * @param test_types C-struct to decode the message contents into - */ -static inline void mavlink_msg_test_types_decode(const mavlink_message_t* msg, mavlink_test_types_t* test_types) -{ -#if MAVLINK_NEED_BYTE_SWAP - test_types->c = mavlink_msg_test_types_get_c(msg); - mavlink_msg_test_types_get_s(msg, test_types->s); - test_types->u8 = mavlink_msg_test_types_get_u8(msg); - test_types->u16 = mavlink_msg_test_types_get_u16(msg); - test_types->u32 = mavlink_msg_test_types_get_u32(msg); - test_types->u64 = mavlink_msg_test_types_get_u64(msg); - test_types->s8 = mavlink_msg_test_types_get_s8(msg); - test_types->s16 = mavlink_msg_test_types_get_s16(msg); - test_types->s32 = mavlink_msg_test_types_get_s32(msg); - test_types->s64 = mavlink_msg_test_types_get_s64(msg); - test_types->f = mavlink_msg_test_types_get_f(msg); - test_types->d = mavlink_msg_test_types_get_d(msg); - mavlink_msg_test_types_get_u8_array(msg, test_types->u8_array); - mavlink_msg_test_types_get_u16_array(msg, test_types->u16_array); - mavlink_msg_test_types_get_u32_array(msg, test_types->u32_array); - mavlink_msg_test_types_get_u64_array(msg, test_types->u64_array); - mavlink_msg_test_types_get_s8_array(msg, test_types->s8_array); - mavlink_msg_test_types_get_s16_array(msg, test_types->s16_array); - mavlink_msg_test_types_get_s32_array(msg, test_types->s32_array); - mavlink_msg_test_types_get_s64_array(msg, test_types->s64_array); - mavlink_msg_test_types_get_f_array(msg, test_types->f_array); - mavlink_msg_test_types_get_d_array(msg, test_types->d_array); -#else - memcpy(test_types, _MAV_PAYLOAD(msg), 179); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/test/test.h b/mavlink/include/mavlink/v0.9/test/test.h deleted file mode 100644 index cfcf4753e7..0000000000 --- a/mavlink/include/mavlink/v0.9/test/test.h +++ /dev/null @@ -1,53 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from test.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef TEST_H -#define TEST_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_TEST_TYPES, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_TEST - - - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 3 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 3 -#endif - -// ENUM DEFINITIONS - - - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_test_types.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // TEST_H diff --git a/mavlink/include/mavlink/v0.9/test/testsuite.h b/mavlink/include/mavlink/v0.9/test/testsuite.h deleted file mode 100644 index 9b0fc041b5..0000000000 --- a/mavlink/include/mavlink/v0.9/test/testsuite.h +++ /dev/null @@ -1,120 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from test.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef TEST_TESTSUITE_H -#define TEST_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL - -static void mavlink_test_test(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - - mavlink_test_test(system_id, component_id, last_msg); -} -#endif - - - - -static void mavlink_test_test_types(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_test_types_t packet_in = { - 'A', - "BCDEFGHIJ", - 230, - 17859, - 963498192, - 93372036854776941ULL, - 211, - 18639, - 963498972, - 93372036854777886LL, - 304.0, - 438.0, - { 228, 229, 230 }, - { 20147, 20148, 20149 }, - { 963500688, 963500689, 963500690 }, - { 93372036854780469, 93372036854780470, 93372036854780471 }, - { 171, 172, 173 }, - { 22487, 22488, 22489 }, - { 963503028, 963503029, 963503030 }, - { 93372036854783304, 93372036854783305, 93372036854783306 }, - { 1018.0, 1019.0, 1020.0 }, - { 1208.0, 1209.0, 1210.0 }, - }; - mavlink_test_types_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.c = packet_in.c; - packet1.u8 = packet_in.u8; - packet1.u16 = packet_in.u16; - packet1.u32 = packet_in.u32; - packet1.u64 = packet_in.u64; - packet1.s8 = packet_in.s8; - packet1.s16 = packet_in.s16; - packet1.s32 = packet_in.s32; - packet1.s64 = packet_in.s64; - packet1.f = packet_in.f; - packet1.d = packet_in.d; - - mav_array_memcpy(packet1.s, packet_in.s, sizeof(char)*10); - mav_array_memcpy(packet1.u8_array, packet_in.u8_array, sizeof(uint8_t)*3); - mav_array_memcpy(packet1.u16_array, packet_in.u16_array, sizeof(uint16_t)*3); - mav_array_memcpy(packet1.u32_array, packet_in.u32_array, sizeof(uint32_t)*3); - mav_array_memcpy(packet1.u64_array, packet_in.u64_array, sizeof(uint64_t)*3); - mav_array_memcpy(packet1.s8_array, packet_in.s8_array, sizeof(int8_t)*3); - mav_array_memcpy(packet1.s16_array, packet_in.s16_array, sizeof(int16_t)*3); - mav_array_memcpy(packet1.s32_array, packet_in.s32_array, sizeof(int32_t)*3); - mav_array_memcpy(packet1.s64_array, packet_in.s64_array, sizeof(int64_t)*3); - mav_array_memcpy(packet1.f_array, packet_in.f_array, sizeof(float)*3); - mav_array_memcpy(packet1.d_array, packet_in.d_array, sizeof(double)*3); - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_test_types_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_test_types_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_test_types_pack(system_id, component_id, &msg , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array ); - mavlink_msg_test_types_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_test_types_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array ); - mavlink_msg_test_types_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imsgid = MAVLINK_MSG_ID_NAV_FILTER_BIAS; - return mavlink_finalize_message(msg, system_id, component_id, 32); -} - -/** - * @brief Pack a nav_filter_bias message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds) - * @param accel_0 b_f[0] - * @param accel_1 b_f[1] - * @param accel_2 b_f[2] - * @param gyro_0 b_f[0] - * @param gyro_1 b_f[1] - * @param gyro_2 b_f[2] - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_nav_filter_bias_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float accel_0,float accel_1,float accel_2,float gyro_0,float gyro_1,float gyro_2) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, accel_0); - _mav_put_float(buf, 12, accel_1); - _mav_put_float(buf, 16, accel_2); - _mav_put_float(buf, 20, gyro_0); - _mav_put_float(buf, 24, gyro_1); - _mav_put_float(buf, 28, gyro_2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_nav_filter_bias_t packet; - packet.usec = usec; - packet.accel_0 = accel_0; - packet.accel_1 = accel_1; - packet.accel_2 = accel_2; - packet.gyro_0 = gyro_0; - packet.gyro_1 = gyro_1; - packet.gyro_2 = gyro_2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAV_FILTER_BIAS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32); -} - -/** - * @brief Encode a nav_filter_bias struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param nav_filter_bias C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_nav_filter_bias_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_nav_filter_bias_t* nav_filter_bias) -{ - return mavlink_msg_nav_filter_bias_pack(system_id, component_id, msg, nav_filter_bias->usec, nav_filter_bias->accel_0, nav_filter_bias->accel_1, nav_filter_bias->accel_2, nav_filter_bias->gyro_0, nav_filter_bias->gyro_1, nav_filter_bias->gyro_2); -} - -/** - * @brief Send a nav_filter_bias message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds) - * @param accel_0 b_f[0] - * @param accel_1 b_f[1] - * @param accel_2 b_f[2] - * @param gyro_0 b_f[0] - * @param gyro_1 b_f[1] - * @param gyro_2 b_f[2] - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_nav_filter_bias_send(mavlink_channel_t chan, uint64_t usec, float accel_0, float accel_1, float accel_2, float gyro_0, float gyro_1, float gyro_2) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, accel_0); - _mav_put_float(buf, 12, accel_1); - _mav_put_float(buf, 16, accel_2); - _mav_put_float(buf, 20, gyro_0); - _mav_put_float(buf, 24, gyro_1); - _mav_put_float(buf, 28, gyro_2); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAV_FILTER_BIAS, buf, 32); -#else - mavlink_nav_filter_bias_t packet; - packet.usec = usec; - packet.accel_0 = accel_0; - packet.accel_1 = accel_1; - packet.accel_2 = accel_2; - packet.gyro_0 = gyro_0; - packet.gyro_1 = gyro_1; - packet.gyro_2 = gyro_2; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAV_FILTER_BIAS, (const char *)&packet, 32); -#endif -} - -#endif - -// MESSAGE NAV_FILTER_BIAS UNPACKING - - -/** - * @brief Get field usec from nav_filter_bias message - * - * @return Timestamp (microseconds) - */ -static inline uint64_t mavlink_msg_nav_filter_bias_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field accel_0 from nav_filter_bias message - * - * @return b_f[0] - */ -static inline float mavlink_msg_nav_filter_bias_get_accel_0(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field accel_1 from nav_filter_bias message - * - * @return b_f[1] - */ -static inline float mavlink_msg_nav_filter_bias_get_accel_1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field accel_2 from nav_filter_bias message - * - * @return b_f[2] - */ -static inline float mavlink_msg_nav_filter_bias_get_accel_2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field gyro_0 from nav_filter_bias message - * - * @return b_f[0] - */ -static inline float mavlink_msg_nav_filter_bias_get_gyro_0(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field gyro_1 from nav_filter_bias message - * - * @return b_f[1] - */ -static inline float mavlink_msg_nav_filter_bias_get_gyro_1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field gyro_2 from nav_filter_bias message - * - * @return b_f[2] - */ -static inline float mavlink_msg_nav_filter_bias_get_gyro_2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a nav_filter_bias message into a struct - * - * @param msg The message to decode - * @param nav_filter_bias C-struct to decode the message contents into - */ -static inline void mavlink_msg_nav_filter_bias_decode(const mavlink_message_t* msg, mavlink_nav_filter_bias_t* nav_filter_bias) -{ -#if MAVLINK_NEED_BYTE_SWAP - nav_filter_bias->usec = mavlink_msg_nav_filter_bias_get_usec(msg); - nav_filter_bias->accel_0 = mavlink_msg_nav_filter_bias_get_accel_0(msg); - nav_filter_bias->accel_1 = mavlink_msg_nav_filter_bias_get_accel_1(msg); - nav_filter_bias->accel_2 = mavlink_msg_nav_filter_bias_get_accel_2(msg); - nav_filter_bias->gyro_0 = mavlink_msg_nav_filter_bias_get_gyro_0(msg); - nav_filter_bias->gyro_1 = mavlink_msg_nav_filter_bias_get_gyro_1(msg); - nav_filter_bias->gyro_2 = mavlink_msg_nav_filter_bias_get_gyro_2(msg); -#else - memcpy(nav_filter_bias, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ualberta/mavlink_msg_radio_calibration.h b/mavlink/include/mavlink/v0.9/ualberta/mavlink_msg_radio_calibration.h deleted file mode 100644 index 3feb7c8a59..0000000000 --- a/mavlink/include/mavlink/v0.9/ualberta/mavlink_msg_radio_calibration.h +++ /dev/null @@ -1,259 +0,0 @@ -// MESSAGE RADIO_CALIBRATION PACKING - -#define MAVLINK_MSG_ID_RADIO_CALIBRATION 221 - -typedef struct __mavlink_radio_calibration_t -{ - uint16_t aileron[3]; ///< Aileron setpoints: left, center, right - uint16_t elevator[3]; ///< Elevator setpoints: nose down, center, nose up - uint16_t rudder[3]; ///< Rudder setpoints: nose left, center, nose right - uint16_t gyro[2]; ///< Tail gyro mode/gain setpoints: heading hold, rate mode - uint16_t pitch[5]; ///< Pitch curve setpoints (every 25%) - uint16_t throttle[5]; ///< Throttle curve setpoints (every 25%) -} mavlink_radio_calibration_t; - -#define MAVLINK_MSG_ID_RADIO_CALIBRATION_LEN 42 -#define MAVLINK_MSG_ID_221_LEN 42 - -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_AILERON_LEN 3 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_ELEVATOR_LEN 3 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_RUDDER_LEN 3 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_GYRO_LEN 2 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_PITCH_LEN 5 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_THROTTLE_LEN 5 - -#define MAVLINK_MESSAGE_INFO_RADIO_CALIBRATION { \ - "RADIO_CALIBRATION", \ - 6, \ - { { "aileron", NULL, MAVLINK_TYPE_UINT16_T, 3, 0, offsetof(mavlink_radio_calibration_t, aileron) }, \ - { "elevator", NULL, MAVLINK_TYPE_UINT16_T, 3, 6, offsetof(mavlink_radio_calibration_t, elevator) }, \ - { "rudder", NULL, MAVLINK_TYPE_UINT16_T, 3, 12, offsetof(mavlink_radio_calibration_t, rudder) }, \ - { "gyro", NULL, MAVLINK_TYPE_UINT16_T, 2, 18, offsetof(mavlink_radio_calibration_t, gyro) }, \ - { "pitch", NULL, MAVLINK_TYPE_UINT16_T, 5, 22, offsetof(mavlink_radio_calibration_t, pitch) }, \ - { "throttle", NULL, MAVLINK_TYPE_UINT16_T, 5, 32, offsetof(mavlink_radio_calibration_t, throttle) }, \ - } \ -} - - -/** - * @brief Pack a radio_calibration message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param aileron Aileron setpoints: left, center, right - * @param elevator Elevator setpoints: nose down, center, nose up - * @param rudder Rudder setpoints: nose left, center, nose right - * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode - * @param pitch Pitch curve setpoints (every 25%) - * @param throttle Throttle curve setpoints (every 25%) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_radio_calibration_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const uint16_t *aileron, const uint16_t *elevator, const uint16_t *rudder, const uint16_t *gyro, const uint16_t *pitch, const uint16_t *throttle) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - - _mav_put_uint16_t_array(buf, 0, aileron, 3); - _mav_put_uint16_t_array(buf, 6, elevator, 3); - _mav_put_uint16_t_array(buf, 12, rudder, 3); - _mav_put_uint16_t_array(buf, 18, gyro, 2); - _mav_put_uint16_t_array(buf, 22, pitch, 5); - _mav_put_uint16_t_array(buf, 32, throttle, 5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 42); -#else - mavlink_radio_calibration_t packet; - - mav_array_memcpy(packet.aileron, aileron, sizeof(uint16_t)*3); - mav_array_memcpy(packet.elevator, elevator, sizeof(uint16_t)*3); - mav_array_memcpy(packet.rudder, rudder, sizeof(uint16_t)*3); - mav_array_memcpy(packet.gyro, gyro, sizeof(uint16_t)*2); - mav_array_memcpy(packet.pitch, pitch, sizeof(uint16_t)*5); - mav_array_memcpy(packet.throttle, throttle, sizeof(uint16_t)*5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 42); -#endif - - msg->msgid = MAVLINK_MSG_ID_RADIO_CALIBRATION; - return mavlink_finalize_message(msg, system_id, component_id, 42); -} - -/** - * @brief Pack a radio_calibration message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param aileron Aileron setpoints: left, center, right - * @param elevator Elevator setpoints: nose down, center, nose up - * @param rudder Rudder setpoints: nose left, center, nose right - * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode - * @param pitch Pitch curve setpoints (every 25%) - * @param throttle Throttle curve setpoints (every 25%) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_radio_calibration_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const uint16_t *aileron,const uint16_t *elevator,const uint16_t *rudder,const uint16_t *gyro,const uint16_t *pitch,const uint16_t *throttle) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - - _mav_put_uint16_t_array(buf, 0, aileron, 3); - _mav_put_uint16_t_array(buf, 6, elevator, 3); - _mav_put_uint16_t_array(buf, 12, rudder, 3); - _mav_put_uint16_t_array(buf, 18, gyro, 2); - _mav_put_uint16_t_array(buf, 22, pitch, 5); - _mav_put_uint16_t_array(buf, 32, throttle, 5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 42); -#else - mavlink_radio_calibration_t packet; - - mav_array_memcpy(packet.aileron, aileron, sizeof(uint16_t)*3); - mav_array_memcpy(packet.elevator, elevator, sizeof(uint16_t)*3); - mav_array_memcpy(packet.rudder, rudder, sizeof(uint16_t)*3); - mav_array_memcpy(packet.gyro, gyro, sizeof(uint16_t)*2); - mav_array_memcpy(packet.pitch, pitch, sizeof(uint16_t)*5); - mav_array_memcpy(packet.throttle, throttle, sizeof(uint16_t)*5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 42); -#endif - - msg->msgid = MAVLINK_MSG_ID_RADIO_CALIBRATION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 42); -} - -/** - * @brief Encode a radio_calibration struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param radio_calibration C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_radio_calibration_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_radio_calibration_t* radio_calibration) -{ - return mavlink_msg_radio_calibration_pack(system_id, component_id, msg, radio_calibration->aileron, radio_calibration->elevator, radio_calibration->rudder, radio_calibration->gyro, radio_calibration->pitch, radio_calibration->throttle); -} - -/** - * @brief Send a radio_calibration message - * @param chan MAVLink channel to send the message - * - * @param aileron Aileron setpoints: left, center, right - * @param elevator Elevator setpoints: nose down, center, nose up - * @param rudder Rudder setpoints: nose left, center, nose right - * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode - * @param pitch Pitch curve setpoints (every 25%) - * @param throttle Throttle curve setpoints (every 25%) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_radio_calibration_send(mavlink_channel_t chan, const uint16_t *aileron, const uint16_t *elevator, const uint16_t *rudder, const uint16_t *gyro, const uint16_t *pitch, const uint16_t *throttle) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - - _mav_put_uint16_t_array(buf, 0, aileron, 3); - _mav_put_uint16_t_array(buf, 6, elevator, 3); - _mav_put_uint16_t_array(buf, 12, rudder, 3); - _mav_put_uint16_t_array(buf, 18, gyro, 2); - _mav_put_uint16_t_array(buf, 22, pitch, 5); - _mav_put_uint16_t_array(buf, 32, throttle, 5); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RADIO_CALIBRATION, buf, 42); -#else - mavlink_radio_calibration_t packet; - - mav_array_memcpy(packet.aileron, aileron, sizeof(uint16_t)*3); - mav_array_memcpy(packet.elevator, elevator, sizeof(uint16_t)*3); - mav_array_memcpy(packet.rudder, rudder, sizeof(uint16_t)*3); - mav_array_memcpy(packet.gyro, gyro, sizeof(uint16_t)*2); - mav_array_memcpy(packet.pitch, pitch, sizeof(uint16_t)*5); - mav_array_memcpy(packet.throttle, throttle, sizeof(uint16_t)*5); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RADIO_CALIBRATION, (const char *)&packet, 42); -#endif -} - -#endif - -// MESSAGE RADIO_CALIBRATION UNPACKING - - -/** - * @brief Get field aileron from radio_calibration message - * - * @return Aileron setpoints: left, center, right - */ -static inline uint16_t mavlink_msg_radio_calibration_get_aileron(const mavlink_message_t* msg, uint16_t *aileron) -{ - return _MAV_RETURN_uint16_t_array(msg, aileron, 3, 0); -} - -/** - * @brief Get field elevator from radio_calibration message - * - * @return Elevator setpoints: nose down, center, nose up - */ -static inline uint16_t mavlink_msg_radio_calibration_get_elevator(const mavlink_message_t* msg, uint16_t *elevator) -{ - return _MAV_RETURN_uint16_t_array(msg, elevator, 3, 6); -} - -/** - * @brief Get field rudder from radio_calibration message - * - * @return Rudder setpoints: nose left, center, nose right - */ -static inline uint16_t mavlink_msg_radio_calibration_get_rudder(const mavlink_message_t* msg, uint16_t *rudder) -{ - return _MAV_RETURN_uint16_t_array(msg, rudder, 3, 12); -} - -/** - * @brief Get field gyro from radio_calibration message - * - * @return Tail gyro mode/gain setpoints: heading hold, rate mode - */ -static inline uint16_t mavlink_msg_radio_calibration_get_gyro(const mavlink_message_t* msg, uint16_t *gyro) -{ - return _MAV_RETURN_uint16_t_array(msg, gyro, 2, 18); -} - -/** - * @brief Get field pitch from radio_calibration message - * - * @return Pitch curve setpoints (every 25%) - */ -static inline uint16_t mavlink_msg_radio_calibration_get_pitch(const mavlink_message_t* msg, uint16_t *pitch) -{ - return _MAV_RETURN_uint16_t_array(msg, pitch, 5, 22); -} - -/** - * @brief Get field throttle from radio_calibration message - * - * @return Throttle curve setpoints (every 25%) - */ -static inline uint16_t mavlink_msg_radio_calibration_get_throttle(const mavlink_message_t* msg, uint16_t *throttle) -{ - return _MAV_RETURN_uint16_t_array(msg, throttle, 5, 32); -} - -/** - * @brief Decode a radio_calibration message into a struct - * - * @param msg The message to decode - * @param radio_calibration C-struct to decode the message contents into - */ -static inline void mavlink_msg_radio_calibration_decode(const mavlink_message_t* msg, mavlink_radio_calibration_t* radio_calibration) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_radio_calibration_get_aileron(msg, radio_calibration->aileron); - mavlink_msg_radio_calibration_get_elevator(msg, radio_calibration->elevator); - mavlink_msg_radio_calibration_get_rudder(msg, radio_calibration->rudder); - mavlink_msg_radio_calibration_get_gyro(msg, radio_calibration->gyro); - mavlink_msg_radio_calibration_get_pitch(msg, radio_calibration->pitch); - mavlink_msg_radio_calibration_get_throttle(msg, radio_calibration->throttle); -#else - memcpy(radio_calibration, _MAV_PAYLOAD(msg), 42); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ualberta/mavlink_msg_ualberta_sys_status.h b/mavlink/include/mavlink/v0.9/ualberta/mavlink_msg_ualberta_sys_status.h deleted file mode 100644 index 511ca6b0db..0000000000 --- a/mavlink/include/mavlink/v0.9/ualberta/mavlink_msg_ualberta_sys_status.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE UALBERTA_SYS_STATUS PACKING - -#define MAVLINK_MSG_ID_UALBERTA_SYS_STATUS 222 - -typedef struct __mavlink_ualberta_sys_status_t -{ - uint8_t mode; ///< System mode, see UALBERTA_AUTOPILOT_MODE ENUM - uint8_t nav_mode; ///< Navigation mode, see UALBERTA_NAV_MODE ENUM - uint8_t pilot; ///< Pilot mode, see UALBERTA_PILOT_MODE -} mavlink_ualberta_sys_status_t; - -#define MAVLINK_MSG_ID_UALBERTA_SYS_STATUS_LEN 3 -#define MAVLINK_MSG_ID_222_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_UALBERTA_SYS_STATUS { \ - "UALBERTA_SYS_STATUS", \ - 3, \ - { { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_ualberta_sys_status_t, mode) }, \ - { "nav_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_ualberta_sys_status_t, nav_mode) }, \ - { "pilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_ualberta_sys_status_t, pilot) }, \ - } \ -} - - -/** - * @brief Pack a ualberta_sys_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param mode System mode, see UALBERTA_AUTOPILOT_MODE ENUM - * @param nav_mode Navigation mode, see UALBERTA_NAV_MODE ENUM - * @param pilot Pilot mode, see UALBERTA_PILOT_MODE - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ualberta_sys_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t mode, uint8_t nav_mode, uint8_t pilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, pilot); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ualberta_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.pilot = pilot; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_UALBERTA_SYS_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 3); -} - -/** - * @brief Pack a ualberta_sys_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param mode System mode, see UALBERTA_AUTOPILOT_MODE ENUM - * @param nav_mode Navigation mode, see UALBERTA_NAV_MODE ENUM - * @param pilot Pilot mode, see UALBERTA_PILOT_MODE - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ualberta_sys_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t mode,uint8_t nav_mode,uint8_t pilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, pilot); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ualberta_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.pilot = pilot; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_UALBERTA_SYS_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3); -} - -/** - * @brief Encode a ualberta_sys_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ualberta_sys_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ualberta_sys_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ualberta_sys_status_t* ualberta_sys_status) -{ - return mavlink_msg_ualberta_sys_status_pack(system_id, component_id, msg, ualberta_sys_status->mode, ualberta_sys_status->nav_mode, ualberta_sys_status->pilot); -} - -/** - * @brief Send a ualberta_sys_status message - * @param chan MAVLink channel to send the message - * - * @param mode System mode, see UALBERTA_AUTOPILOT_MODE ENUM - * @param nav_mode Navigation mode, see UALBERTA_NAV_MODE ENUM - * @param pilot Pilot mode, see UALBERTA_PILOT_MODE - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ualberta_sys_status_send(mavlink_channel_t chan, uint8_t mode, uint8_t nav_mode, uint8_t pilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, pilot); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_UALBERTA_SYS_STATUS, buf, 3); -#else - mavlink_ualberta_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.pilot = pilot; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_UALBERTA_SYS_STATUS, (const char *)&packet, 3); -#endif -} - -#endif - -// MESSAGE UALBERTA_SYS_STATUS UNPACKING - - -/** - * @brief Get field mode from ualberta_sys_status message - * - * @return System mode, see UALBERTA_AUTOPILOT_MODE ENUM - */ -static inline uint8_t mavlink_msg_ualberta_sys_status_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field nav_mode from ualberta_sys_status message - * - * @return Navigation mode, see UALBERTA_NAV_MODE ENUM - */ -static inline uint8_t mavlink_msg_ualberta_sys_status_get_nav_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field pilot from ualberta_sys_status message - * - * @return Pilot mode, see UALBERTA_PILOT_MODE - */ -static inline uint8_t mavlink_msg_ualberta_sys_status_get_pilot(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a ualberta_sys_status message into a struct - * - * @param msg The message to decode - * @param ualberta_sys_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_ualberta_sys_status_decode(const mavlink_message_t* msg, mavlink_ualberta_sys_status_t* ualberta_sys_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - ualberta_sys_status->mode = mavlink_msg_ualberta_sys_status_get_mode(msg); - ualberta_sys_status->nav_mode = mavlink_msg_ualberta_sys_status_get_nav_mode(msg); - ualberta_sys_status->pilot = mavlink_msg_ualberta_sys_status_get_pilot(msg); -#else - memcpy(ualberta_sys_status, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v0.9/ualberta/testsuite.h b/mavlink/include/mavlink/v0.9/ualberta/testsuite.h deleted file mode 100644 index 79a6a004a4..0000000000 --- a/mavlink/include/mavlink/v0.9/ualberta/testsuite.h +++ /dev/null @@ -1,192 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from ualberta.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef UALBERTA_TESTSUITE_H -#define UALBERTA_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); -static void mavlink_test_ualberta(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_test_common(system_id, component_id, last_msg); - mavlink_test_ualberta(system_id, component_id, last_msg); -} -#endif - -#include "../common/testsuite.h" - - -static void mavlink_test_nav_filter_bias(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_nav_filter_bias_t packet_in = { - 93372036854775807ULL, - 73.0, - 101.0, - 129.0, - 157.0, - 185.0, - 213.0, - }; - mavlink_nav_filter_bias_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.usec = packet_in.usec; - packet1.accel_0 = packet_in.accel_0; - packet1.accel_1 = packet_in.accel_1; - packet1.accel_2 = packet_in.accel_2; - packet1.gyro_0 = packet_in.gyro_0; - packet1.gyro_1 = packet_in.gyro_1; - packet1.gyro_2 = packet_in.gyro_2; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_nav_filter_bias_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_nav_filter_bias_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_nav_filter_bias_pack(system_id, component_id, &msg , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 ); - mavlink_msg_nav_filter_bias_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_nav_filter_bias_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 ); - mavlink_msg_nav_filter_bias_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imsgid = MAVLINK_MSG_ID_DATA16; + return mavlink_finalize_message(msg, system_id, component_id, 18, 234); +} + +/** + * @brief Pack a data16 message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data16_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint8_t type,uint8_t len,const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[18]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 16); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); +#else + mavlink_data16_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*16); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA16; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18, 234); +} + +/** + * @brief Encode a data16 struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param data16 C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_data16_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data16_t* data16) +{ + return mavlink_msg_data16_pack(system_id, component_id, msg, data16->type, data16->len, data16->data); +} + +/** + * @brief Send a data16 message + * @param chan MAVLink channel to send the message + * + * @param type data type + * @param len data length + * @param data raw data + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_data16_send(mavlink_channel_t chan, uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[18]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 16); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA16, buf, 18, 234); +#else + mavlink_data16_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*16); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA16, (const char *)&packet, 18, 234); +#endif +} + +#endif + +// MESSAGE DATA16 UNPACKING + + +/** + * @brief Get field type from data16 message + * + * @return data type + */ +static inline uint8_t mavlink_msg_data16_get_type(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 0); +} + +/** + * @brief Get field len from data16 message + * + * @return data length + */ +static inline uint8_t mavlink_msg_data16_get_len(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 1); +} + +/** + * @brief Get field data from data16 message + * + * @return raw data + */ +static inline uint16_t mavlink_msg_data16_get_data(const mavlink_message_t* msg, uint8_t *data) +{ + return _MAV_RETURN_uint8_t_array(msg, data, 16, 2); +} + +/** + * @brief Decode a data16 message into a struct + * + * @param msg The message to decode + * @param data16 C-struct to decode the message contents into + */ +static inline void mavlink_msg_data16_decode(const mavlink_message_t* msg, mavlink_data16_t* data16) +{ +#if MAVLINK_NEED_BYTE_SWAP + data16->type = mavlink_msg_data16_get_type(msg); + data16->len = mavlink_msg_data16_get_len(msg); + mavlink_msg_data16_get_data(msg, data16->data); +#else + memcpy(data16, _MAV_PAYLOAD(msg), 18); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data32.h b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data32.h new file mode 100644 index 0000000000..a9b3fe28d6 --- /dev/null +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data32.h @@ -0,0 +1,182 @@ +// MESSAGE DATA32 PACKING + +#define MAVLINK_MSG_ID_DATA32 170 + +typedef struct __mavlink_data32_t +{ + uint8_t type; ///< data type + uint8_t len; ///< data length + uint8_t data[32]; ///< raw data +} mavlink_data32_t; + +#define MAVLINK_MSG_ID_DATA32_LEN 34 +#define MAVLINK_MSG_ID_170_LEN 34 + +#define MAVLINK_MSG_DATA32_FIELD_DATA_LEN 32 + +#define MAVLINK_MESSAGE_INFO_DATA32 { \ + "DATA32", \ + 3, \ + { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_data32_t, type) }, \ + { "len", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_data32_t, len) }, \ + { "data", NULL, MAVLINK_TYPE_UINT8_T, 32, 2, offsetof(mavlink_data32_t, data) }, \ + } \ +} + + +/** + * @brief Pack a data32 message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data32_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[34]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 32); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 34); +#else + mavlink_data32_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*32); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 34); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA32; + return mavlink_finalize_message(msg, system_id, component_id, 34, 73); +} + +/** + * @brief Pack a data32 message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data32_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint8_t type,uint8_t len,const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[34]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 32); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 34); +#else + mavlink_data32_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*32); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 34); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA32; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 34, 73); +} + +/** + * @brief Encode a data32 struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param data32 C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_data32_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data32_t* data32) +{ + return mavlink_msg_data32_pack(system_id, component_id, msg, data32->type, data32->len, data32->data); +} + +/** + * @brief Send a data32 message + * @param chan MAVLink channel to send the message + * + * @param type data type + * @param len data length + * @param data raw data + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_data32_send(mavlink_channel_t chan, uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[34]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 32); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, buf, 34, 73); +#else + mavlink_data32_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*32); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA32, (const char *)&packet, 34, 73); +#endif +} + +#endif + +// MESSAGE DATA32 UNPACKING + + +/** + * @brief Get field type from data32 message + * + * @return data type + */ +static inline uint8_t mavlink_msg_data32_get_type(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 0); +} + +/** + * @brief Get field len from data32 message + * + * @return data length + */ +static inline uint8_t mavlink_msg_data32_get_len(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 1); +} + +/** + * @brief Get field data from data32 message + * + * @return raw data + */ +static inline uint16_t mavlink_msg_data32_get_data(const mavlink_message_t* msg, uint8_t *data) +{ + return _MAV_RETURN_uint8_t_array(msg, data, 32, 2); +} + +/** + * @brief Decode a data32 message into a struct + * + * @param msg The message to decode + * @param data32 C-struct to decode the message contents into + */ +static inline void mavlink_msg_data32_decode(const mavlink_message_t* msg, mavlink_data32_t* data32) +{ +#if MAVLINK_NEED_BYTE_SWAP + data32->type = mavlink_msg_data32_get_type(msg); + data32->len = mavlink_msg_data32_get_len(msg); + mavlink_msg_data32_get_data(msg, data32->data); +#else + memcpy(data32, _MAV_PAYLOAD(msg), 34); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data64.h b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data64.h new file mode 100644 index 0000000000..29dcaa6d80 --- /dev/null +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data64.h @@ -0,0 +1,182 @@ +// MESSAGE DATA64 PACKING + +#define MAVLINK_MSG_ID_DATA64 171 + +typedef struct __mavlink_data64_t +{ + uint8_t type; ///< data type + uint8_t len; ///< data length + uint8_t data[64]; ///< raw data +} mavlink_data64_t; + +#define MAVLINK_MSG_ID_DATA64_LEN 66 +#define MAVLINK_MSG_ID_171_LEN 66 + +#define MAVLINK_MSG_DATA64_FIELD_DATA_LEN 64 + +#define MAVLINK_MESSAGE_INFO_DATA64 { \ + "DATA64", \ + 3, \ + { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_data64_t, type) }, \ + { "len", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_data64_t, len) }, \ + { "data", NULL, MAVLINK_TYPE_UINT8_T, 64, 2, offsetof(mavlink_data64_t, data) }, \ + } \ +} + + +/** + * @brief Pack a data64 message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data64_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[66]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 64); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 66); +#else + mavlink_data64_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*64); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 66); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA64; + return mavlink_finalize_message(msg, system_id, component_id, 66, 181); +} + +/** + * @brief Pack a data64 message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data64_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint8_t type,uint8_t len,const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[66]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 64); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 66); +#else + mavlink_data64_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*64); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 66); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA64; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 66, 181); +} + +/** + * @brief Encode a data64 struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param data64 C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_data64_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data64_t* data64) +{ + return mavlink_msg_data64_pack(system_id, component_id, msg, data64->type, data64->len, data64->data); +} + +/** + * @brief Send a data64 message + * @param chan MAVLink channel to send the message + * + * @param type data type + * @param len data length + * @param data raw data + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_data64_send(mavlink_channel_t chan, uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[66]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 64); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA64, buf, 66, 181); +#else + mavlink_data64_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*64); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA64, (const char *)&packet, 66, 181); +#endif +} + +#endif + +// MESSAGE DATA64 UNPACKING + + +/** + * @brief Get field type from data64 message + * + * @return data type + */ +static inline uint8_t mavlink_msg_data64_get_type(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 0); +} + +/** + * @brief Get field len from data64 message + * + * @return data length + */ +static inline uint8_t mavlink_msg_data64_get_len(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 1); +} + +/** + * @brief Get field data from data64 message + * + * @return raw data + */ +static inline uint16_t mavlink_msg_data64_get_data(const mavlink_message_t* msg, uint8_t *data) +{ + return _MAV_RETURN_uint8_t_array(msg, data, 64, 2); +} + +/** + * @brief Decode a data64 message into a struct + * + * @param msg The message to decode + * @param data64 C-struct to decode the message contents into + */ +static inline void mavlink_msg_data64_decode(const mavlink_message_t* msg, mavlink_data64_t* data64) +{ +#if MAVLINK_NEED_BYTE_SWAP + data64->type = mavlink_msg_data64_get_type(msg); + data64->len = mavlink_msg_data64_get_len(msg); + mavlink_msg_data64_get_data(msg, data64->data); +#else + memcpy(data64, _MAV_PAYLOAD(msg), 66); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data96.h b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data96.h new file mode 100644 index 0000000000..df0821c878 --- /dev/null +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_data96.h @@ -0,0 +1,182 @@ +// MESSAGE DATA96 PACKING + +#define MAVLINK_MSG_ID_DATA96 172 + +typedef struct __mavlink_data96_t +{ + uint8_t type; ///< data type + uint8_t len; ///< data length + uint8_t data[96]; ///< raw data +} mavlink_data96_t; + +#define MAVLINK_MSG_ID_DATA96_LEN 98 +#define MAVLINK_MSG_ID_172_LEN 98 + +#define MAVLINK_MSG_DATA96_FIELD_DATA_LEN 96 + +#define MAVLINK_MESSAGE_INFO_DATA96 { \ + "DATA96", \ + 3, \ + { { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_data96_t, type) }, \ + { "len", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_data96_t, len) }, \ + { "data", NULL, MAVLINK_TYPE_UINT8_T, 96, 2, offsetof(mavlink_data96_t, data) }, \ + } \ +} + + +/** + * @brief Pack a data96 message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data96_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[98]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 96); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 98); +#else + mavlink_data96_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*96); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 98); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA96; + return mavlink_finalize_message(msg, system_id, component_id, 98, 22); +} + +/** + * @brief Pack a data96 message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param type data type + * @param len data length + * @param data raw data + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_data96_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint8_t type,uint8_t len,const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[98]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 96); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 98); +#else + mavlink_data96_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*96); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 98); +#endif + + msg->msgid = MAVLINK_MSG_ID_DATA96; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 98, 22); +} + +/** + * @brief Encode a data96 struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param data96 C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_data96_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data96_t* data96) +{ + return mavlink_msg_data96_pack(system_id, component_id, msg, data96->type, data96->len, data96->data); +} + +/** + * @brief Send a data96 message + * @param chan MAVLink channel to send the message + * + * @param type data type + * @param len data length + * @param data raw data + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_data96_send(mavlink_channel_t chan, uint8_t type, uint8_t len, const uint8_t *data) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[98]; + _mav_put_uint8_t(buf, 0, type); + _mav_put_uint8_t(buf, 1, len); + _mav_put_uint8_t_array(buf, 2, data, 96); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA96, buf, 98, 22); +#else + mavlink_data96_t packet; + packet.type = type; + packet.len = len; + mav_array_memcpy(packet.data, data, sizeof(uint8_t)*96); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA96, (const char *)&packet, 98, 22); +#endif +} + +#endif + +// MESSAGE DATA96 UNPACKING + + +/** + * @brief Get field type from data96 message + * + * @return data type + */ +static inline uint8_t mavlink_msg_data96_get_type(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 0); +} + +/** + * @brief Get field len from data96 message + * + * @return data length + */ +static inline uint8_t mavlink_msg_data96_get_len(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 1); +} + +/** + * @brief Get field data from data96 message + * + * @return raw data + */ +static inline uint16_t mavlink_msg_data96_get_data(const mavlink_message_t* msg, uint8_t *data) +{ + return _MAV_RETURN_uint8_t_array(msg, data, 96, 2); +} + +/** + * @brief Decode a data96 message into a struct + * + * @param msg The message to decode + * @param data96 C-struct to decode the message contents into + */ +static inline void mavlink_msg_data96_decode(const mavlink_message_t* msg, mavlink_data96_t* data96) +{ +#if MAVLINK_NEED_BYTE_SWAP + data96->type = mavlink_msg_data96_get_type(msg); + data96->len = mavlink_msg_data96_get_len(msg); + mavlink_msg_data96_get_data(msg, data96->data); +#else + memcpy(data96, _MAV_PAYLOAD(msg), 98); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_limits_status.h b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_limits_status.h new file mode 100644 index 0000000000..7caac1c5a1 --- /dev/null +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_limits_status.h @@ -0,0 +1,320 @@ +// MESSAGE LIMITS_STATUS PACKING + +#define MAVLINK_MSG_ID_LIMITS_STATUS 167 + +typedef struct __mavlink_limits_status_t +{ + uint32_t last_trigger; ///< time of last breach in milliseconds since boot + uint32_t last_action; ///< time of last recovery action in milliseconds since boot + uint32_t last_recovery; ///< time of last successful recovery in milliseconds since boot + uint32_t last_clear; ///< time of last all-clear in milliseconds since boot + uint16_t breach_count; ///< number of fence breaches + uint8_t limits_state; ///< state of AP_Limits, (see enum LimitState, LIMITS_STATE) + uint8_t mods_enabled; ///< AP_Limit_Module bitfield of enabled modules, (see enum moduleid or LIMIT_MODULE) + uint8_t mods_required; ///< AP_Limit_Module bitfield of required modules, (see enum moduleid or LIMIT_MODULE) + uint8_t mods_triggered; ///< AP_Limit_Module bitfield of triggered modules, (see enum moduleid or LIMIT_MODULE) +} mavlink_limits_status_t; + +#define MAVLINK_MSG_ID_LIMITS_STATUS_LEN 22 +#define MAVLINK_MSG_ID_167_LEN 22 + + + +#define MAVLINK_MESSAGE_INFO_LIMITS_STATUS { \ + "LIMITS_STATUS", \ + 9, \ + { { "last_trigger", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_limits_status_t, last_trigger) }, \ + { "last_action", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_limits_status_t, last_action) }, \ + { "last_recovery", NULL, MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_limits_status_t, last_recovery) }, \ + { "last_clear", NULL, MAVLINK_TYPE_UINT32_T, 0, 12, offsetof(mavlink_limits_status_t, last_clear) }, \ + { "breach_count", NULL, MAVLINK_TYPE_UINT16_T, 0, 16, offsetof(mavlink_limits_status_t, breach_count) }, \ + { "limits_state", NULL, MAVLINK_TYPE_UINT8_T, 0, 18, offsetof(mavlink_limits_status_t, limits_state) }, \ + { "mods_enabled", NULL, MAVLINK_TYPE_UINT8_T, 0, 19, offsetof(mavlink_limits_status_t, mods_enabled) }, \ + { "mods_required", NULL, MAVLINK_TYPE_UINT8_T, 0, 20, offsetof(mavlink_limits_status_t, mods_required) }, \ + { "mods_triggered", NULL, MAVLINK_TYPE_UINT8_T, 0, 21, offsetof(mavlink_limits_status_t, mods_triggered) }, \ + } \ +} + + +/** + * @brief Pack a limits_status message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param limits_state state of AP_Limits, (see enum LimitState, LIMITS_STATE) + * @param last_trigger time of last breach in milliseconds since boot + * @param last_action time of last recovery action in milliseconds since boot + * @param last_recovery time of last successful recovery in milliseconds since boot + * @param last_clear time of last all-clear in milliseconds since boot + * @param breach_count number of fence breaches + * @param mods_enabled AP_Limit_Module bitfield of enabled modules, (see enum moduleid or LIMIT_MODULE) + * @param mods_required AP_Limit_Module bitfield of required modules, (see enum moduleid or LIMIT_MODULE) + * @param mods_triggered AP_Limit_Module bitfield of triggered modules, (see enum moduleid or LIMIT_MODULE) + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_limits_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + uint8_t limits_state, uint32_t last_trigger, uint32_t last_action, uint32_t last_recovery, uint32_t last_clear, uint16_t breach_count, uint8_t mods_enabled, uint8_t mods_required, uint8_t mods_triggered) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[22]; + _mav_put_uint32_t(buf, 0, last_trigger); + _mav_put_uint32_t(buf, 4, last_action); + _mav_put_uint32_t(buf, 8, last_recovery); + _mav_put_uint32_t(buf, 12, last_clear); + _mav_put_uint16_t(buf, 16, breach_count); + _mav_put_uint8_t(buf, 18, limits_state); + _mav_put_uint8_t(buf, 19, mods_enabled); + _mav_put_uint8_t(buf, 20, mods_required); + _mav_put_uint8_t(buf, 21, mods_triggered); + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 22); +#else + mavlink_limits_status_t packet; + packet.last_trigger = last_trigger; + packet.last_action = last_action; + packet.last_recovery = last_recovery; + packet.last_clear = last_clear; + packet.breach_count = breach_count; + packet.limits_state = limits_state; + packet.mods_enabled = mods_enabled; + packet.mods_required = mods_required; + packet.mods_triggered = mods_triggered; + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 22); +#endif + + msg->msgid = MAVLINK_MSG_ID_LIMITS_STATUS; + return mavlink_finalize_message(msg, system_id, component_id, 22, 144); +} + +/** + * @brief Pack a limits_status message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param limits_state state of AP_Limits, (see enum LimitState, LIMITS_STATE) + * @param last_trigger time of last breach in milliseconds since boot + * @param last_action time of last recovery action in milliseconds since boot + * @param last_recovery time of last successful recovery in milliseconds since boot + * @param last_clear time of last all-clear in milliseconds since boot + * @param breach_count number of fence breaches + * @param mods_enabled AP_Limit_Module bitfield of enabled modules, (see enum moduleid or LIMIT_MODULE) + * @param mods_required AP_Limit_Module bitfield of required modules, (see enum moduleid or LIMIT_MODULE) + * @param mods_triggered AP_Limit_Module bitfield of triggered modules, (see enum moduleid or LIMIT_MODULE) + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_limits_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint8_t limits_state,uint32_t last_trigger,uint32_t last_action,uint32_t last_recovery,uint32_t last_clear,uint16_t breach_count,uint8_t mods_enabled,uint8_t mods_required,uint8_t mods_triggered) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[22]; + _mav_put_uint32_t(buf, 0, last_trigger); + _mav_put_uint32_t(buf, 4, last_action); + _mav_put_uint32_t(buf, 8, last_recovery); + _mav_put_uint32_t(buf, 12, last_clear); + _mav_put_uint16_t(buf, 16, breach_count); + _mav_put_uint8_t(buf, 18, limits_state); + _mav_put_uint8_t(buf, 19, mods_enabled); + _mav_put_uint8_t(buf, 20, mods_required); + _mav_put_uint8_t(buf, 21, mods_triggered); + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 22); +#else + mavlink_limits_status_t packet; + packet.last_trigger = last_trigger; + packet.last_action = last_action; + packet.last_recovery = last_recovery; + packet.last_clear = last_clear; + packet.breach_count = breach_count; + packet.limits_state = limits_state; + packet.mods_enabled = mods_enabled; + packet.mods_required = mods_required; + packet.mods_triggered = mods_triggered; + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 22); +#endif + + msg->msgid = MAVLINK_MSG_ID_LIMITS_STATUS; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 22, 144); +} + +/** + * @brief Encode a limits_status struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param limits_status C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_limits_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_limits_status_t* limits_status) +{ + return mavlink_msg_limits_status_pack(system_id, component_id, msg, limits_status->limits_state, limits_status->last_trigger, limits_status->last_action, limits_status->last_recovery, limits_status->last_clear, limits_status->breach_count, limits_status->mods_enabled, limits_status->mods_required, limits_status->mods_triggered); +} + +/** + * @brief Send a limits_status message + * @param chan MAVLink channel to send the message + * + * @param limits_state state of AP_Limits, (see enum LimitState, LIMITS_STATE) + * @param last_trigger time of last breach in milliseconds since boot + * @param last_action time of last recovery action in milliseconds since boot + * @param last_recovery time of last successful recovery in milliseconds since boot + * @param last_clear time of last all-clear in milliseconds since boot + * @param breach_count number of fence breaches + * @param mods_enabled AP_Limit_Module bitfield of enabled modules, (see enum moduleid or LIMIT_MODULE) + * @param mods_required AP_Limit_Module bitfield of required modules, (see enum moduleid or LIMIT_MODULE) + * @param mods_triggered AP_Limit_Module bitfield of triggered modules, (see enum moduleid or LIMIT_MODULE) + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_limits_status_send(mavlink_channel_t chan, uint8_t limits_state, uint32_t last_trigger, uint32_t last_action, uint32_t last_recovery, uint32_t last_clear, uint16_t breach_count, uint8_t mods_enabled, uint8_t mods_required, uint8_t mods_triggered) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[22]; + _mav_put_uint32_t(buf, 0, last_trigger); + _mav_put_uint32_t(buf, 4, last_action); + _mav_put_uint32_t(buf, 8, last_recovery); + _mav_put_uint32_t(buf, 12, last_clear); + _mav_put_uint16_t(buf, 16, breach_count); + _mav_put_uint8_t(buf, 18, limits_state); + _mav_put_uint8_t(buf, 19, mods_enabled); + _mav_put_uint8_t(buf, 20, mods_required); + _mav_put_uint8_t(buf, 21, mods_triggered); + + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LIMITS_STATUS, buf, 22, 144); +#else + mavlink_limits_status_t packet; + packet.last_trigger = last_trigger; + packet.last_action = last_action; + packet.last_recovery = last_recovery; + packet.last_clear = last_clear; + packet.breach_count = breach_count; + packet.limits_state = limits_state; + packet.mods_enabled = mods_enabled; + packet.mods_required = mods_required; + packet.mods_triggered = mods_triggered; + + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LIMITS_STATUS, (const char *)&packet, 22, 144); +#endif +} + +#endif + +// MESSAGE LIMITS_STATUS UNPACKING + + +/** + * @brief Get field limits_state from limits_status message + * + * @return state of AP_Limits, (see enum LimitState, LIMITS_STATE) + */ +static inline uint8_t mavlink_msg_limits_status_get_limits_state(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 18); +} + +/** + * @brief Get field last_trigger from limits_status message + * + * @return time of last breach in milliseconds since boot + */ +static inline uint32_t mavlink_msg_limits_status_get_last_trigger(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint32_t(msg, 0); +} + +/** + * @brief Get field last_action from limits_status message + * + * @return time of last recovery action in milliseconds since boot + */ +static inline uint32_t mavlink_msg_limits_status_get_last_action(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint32_t(msg, 4); +} + +/** + * @brief Get field last_recovery from limits_status message + * + * @return time of last successful recovery in milliseconds since boot + */ +static inline uint32_t mavlink_msg_limits_status_get_last_recovery(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint32_t(msg, 8); +} + +/** + * @brief Get field last_clear from limits_status message + * + * @return time of last all-clear in milliseconds since boot + */ +static inline uint32_t mavlink_msg_limits_status_get_last_clear(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint32_t(msg, 12); +} + +/** + * @brief Get field breach_count from limits_status message + * + * @return number of fence breaches + */ +static inline uint16_t mavlink_msg_limits_status_get_breach_count(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint16_t(msg, 16); +} + +/** + * @brief Get field mods_enabled from limits_status message + * + * @return AP_Limit_Module bitfield of enabled modules, (see enum moduleid or LIMIT_MODULE) + */ +static inline uint8_t mavlink_msg_limits_status_get_mods_enabled(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 19); +} + +/** + * @brief Get field mods_required from limits_status message + * + * @return AP_Limit_Module bitfield of required modules, (see enum moduleid or LIMIT_MODULE) + */ +static inline uint8_t mavlink_msg_limits_status_get_mods_required(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 20); +} + +/** + * @brief Get field mods_triggered from limits_status message + * + * @return AP_Limit_Module bitfield of triggered modules, (see enum moduleid or LIMIT_MODULE) + */ +static inline uint8_t mavlink_msg_limits_status_get_mods_triggered(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 21); +} + +/** + * @brief Decode a limits_status message into a struct + * + * @param msg The message to decode + * @param limits_status C-struct to decode the message contents into + */ +static inline void mavlink_msg_limits_status_decode(const mavlink_message_t* msg, mavlink_limits_status_t* limits_status) +{ +#if MAVLINK_NEED_BYTE_SWAP + limits_status->last_trigger = mavlink_msg_limits_status_get_last_trigger(msg); + limits_status->last_action = mavlink_msg_limits_status_get_last_action(msg); + limits_status->last_recovery = mavlink_msg_limits_status_get_last_recovery(msg); + limits_status->last_clear = mavlink_msg_limits_status_get_last_clear(msg); + limits_status->breach_count = mavlink_msg_limits_status_get_breach_count(msg); + limits_status->limits_state = mavlink_msg_limits_status_get_limits_state(msg); + limits_status->mods_enabled = mavlink_msg_limits_status_get_mods_enabled(msg); + limits_status->mods_required = mavlink_msg_limits_status_get_mods_required(msg); + limits_status->mods_triggered = mavlink_msg_limits_status_get_mods_triggered(msg); +#else + memcpy(limits_status, _MAV_PAYLOAD(msg), 22); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_simstate.h b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_simstate.h index dfcddfc2b6..8ee447c778 100644 --- a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_simstate.h +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_simstate.h @@ -13,16 +13,18 @@ typedef struct __mavlink_simstate_t float xgyro; ///< Angular speed around X axis rad/s float ygyro; ///< Angular speed around Y axis rad/s float zgyro; ///< Angular speed around Z axis rad/s + float lat; ///< Latitude in degrees + float lng; ///< Longitude in degrees } mavlink_simstate_t; -#define MAVLINK_MSG_ID_SIMSTATE_LEN 36 -#define MAVLINK_MSG_ID_164_LEN 36 +#define MAVLINK_MSG_ID_SIMSTATE_LEN 44 +#define MAVLINK_MSG_ID_164_LEN 44 #define MAVLINK_MESSAGE_INFO_SIMSTATE { \ "SIMSTATE", \ - 9, \ + 11, \ { { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_simstate_t, roll) }, \ { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_simstate_t, pitch) }, \ { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_simstate_t, yaw) }, \ @@ -32,6 +34,8 @@ typedef struct __mavlink_simstate_t { "xgyro", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_simstate_t, xgyro) }, \ { "ygyro", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_simstate_t, ygyro) }, \ { "zgyro", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_simstate_t, zgyro) }, \ + { "lat", NULL, MAVLINK_TYPE_FLOAT, 0, 36, offsetof(mavlink_simstate_t, lat) }, \ + { "lng", NULL, MAVLINK_TYPE_FLOAT, 0, 40, offsetof(mavlink_simstate_t, lng) }, \ } \ } @@ -51,13 +55,15 @@ typedef struct __mavlink_simstate_t * @param xgyro Angular speed around X axis rad/s * @param ygyro Angular speed around Y axis rad/s * @param zgyro Angular speed around Z axis rad/s + * @param lat Latitude in degrees + * @param lng Longitude in degrees * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_simstate_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float roll, float pitch, float yaw, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro) + float roll, float pitch, float yaw, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro, float lat, float lng) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; + char buf[44]; _mav_put_float(buf, 0, roll); _mav_put_float(buf, 4, pitch); _mav_put_float(buf, 8, yaw); @@ -67,8 +73,10 @@ static inline uint16_t mavlink_msg_simstate_pack(uint8_t system_id, uint8_t comp _mav_put_float(buf, 24, xgyro); _mav_put_float(buf, 28, ygyro); _mav_put_float(buf, 32, zgyro); + _mav_put_float(buf, 36, lat); + _mav_put_float(buf, 40, lng); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 44); #else mavlink_simstate_t packet; packet.roll = roll; @@ -80,12 +88,14 @@ static inline uint16_t mavlink_msg_simstate_pack(uint8_t system_id, uint8_t comp packet.xgyro = xgyro; packet.ygyro = ygyro; packet.zgyro = zgyro; + packet.lat = lat; + packet.lng = lng; - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 44); #endif msg->msgid = MAVLINK_MSG_ID_SIMSTATE; - return mavlink_finalize_message(msg, system_id, component_id, 36, 42); + return mavlink_finalize_message(msg, system_id, component_id, 44, 111); } /** @@ -103,14 +113,16 @@ static inline uint16_t mavlink_msg_simstate_pack(uint8_t system_id, uint8_t comp * @param xgyro Angular speed around X axis rad/s * @param ygyro Angular speed around Y axis rad/s * @param zgyro Angular speed around Z axis rad/s + * @param lat Latitude in degrees + * @param lng Longitude in degrees * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_simstate_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, - float roll,float pitch,float yaw,float xacc,float yacc,float zacc,float xgyro,float ygyro,float zgyro) + float roll,float pitch,float yaw,float xacc,float yacc,float zacc,float xgyro,float ygyro,float zgyro,float lat,float lng) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; + char buf[44]; _mav_put_float(buf, 0, roll); _mav_put_float(buf, 4, pitch); _mav_put_float(buf, 8, yaw); @@ -120,8 +132,10 @@ static inline uint16_t mavlink_msg_simstate_pack_chan(uint8_t system_id, uint8_t _mav_put_float(buf, 24, xgyro); _mav_put_float(buf, 28, ygyro); _mav_put_float(buf, 32, zgyro); + _mav_put_float(buf, 36, lat); + _mav_put_float(buf, 40, lng); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 36); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 44); #else mavlink_simstate_t packet; packet.roll = roll; @@ -133,12 +147,14 @@ static inline uint16_t mavlink_msg_simstate_pack_chan(uint8_t system_id, uint8_t packet.xgyro = xgyro; packet.ygyro = ygyro; packet.zgyro = zgyro; + packet.lat = lat; + packet.lng = lng; - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 36); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 44); #endif msg->msgid = MAVLINK_MSG_ID_SIMSTATE; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 36, 42); + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 44, 111); } /** @@ -151,7 +167,7 @@ static inline uint16_t mavlink_msg_simstate_pack_chan(uint8_t system_id, uint8_t */ static inline uint16_t mavlink_msg_simstate_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_simstate_t* simstate) { - return mavlink_msg_simstate_pack(system_id, component_id, msg, simstate->roll, simstate->pitch, simstate->yaw, simstate->xacc, simstate->yacc, simstate->zacc, simstate->xgyro, simstate->ygyro, simstate->zgyro); + return mavlink_msg_simstate_pack(system_id, component_id, msg, simstate->roll, simstate->pitch, simstate->yaw, simstate->xacc, simstate->yacc, simstate->zacc, simstate->xgyro, simstate->ygyro, simstate->zgyro, simstate->lat, simstate->lng); } /** @@ -167,13 +183,15 @@ static inline uint16_t mavlink_msg_simstate_encode(uint8_t system_id, uint8_t co * @param xgyro Angular speed around X axis rad/s * @param ygyro Angular speed around Y axis rad/s * @param zgyro Angular speed around Z axis rad/s + * @param lat Latitude in degrees + * @param lng Longitude in degrees */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS -static inline void mavlink_msg_simstate_send(mavlink_channel_t chan, float roll, float pitch, float yaw, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro) +static inline void mavlink_msg_simstate_send(mavlink_channel_t chan, float roll, float pitch, float yaw, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro, float lat, float lng) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[36]; + char buf[44]; _mav_put_float(buf, 0, roll); _mav_put_float(buf, 4, pitch); _mav_put_float(buf, 8, yaw); @@ -183,8 +201,10 @@ static inline void mavlink_msg_simstate_send(mavlink_channel_t chan, float roll, _mav_put_float(buf, 24, xgyro); _mav_put_float(buf, 28, ygyro); _mav_put_float(buf, 32, zgyro); + _mav_put_float(buf, 36, lat); + _mav_put_float(buf, 40, lng); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SIMSTATE, buf, 36, 42); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SIMSTATE, buf, 44, 111); #else mavlink_simstate_t packet; packet.roll = roll; @@ -196,8 +216,10 @@ static inline void mavlink_msg_simstate_send(mavlink_channel_t chan, float roll, packet.xgyro = xgyro; packet.ygyro = ygyro; packet.zgyro = zgyro; + packet.lat = lat; + packet.lng = lng; - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SIMSTATE, (const char *)&packet, 36, 42); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SIMSTATE, (const char *)&packet, 44, 111); #endif } @@ -296,6 +318,26 @@ static inline float mavlink_msg_simstate_get_zgyro(const mavlink_message_t* msg) return _MAV_RETURN_float(msg, 32); } +/** + * @brief Get field lat from simstate message + * + * @return Latitude in degrees + */ +static inline float mavlink_msg_simstate_get_lat(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 36); +} + +/** + * @brief Get field lng from simstate message + * + * @return Longitude in degrees + */ +static inline float mavlink_msg_simstate_get_lng(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 40); +} + /** * @brief Decode a simstate message into a struct * @@ -314,7 +356,9 @@ static inline void mavlink_msg_simstate_decode(const mavlink_message_t* msg, mav simstate->xgyro = mavlink_msg_simstate_get_xgyro(msg); simstate->ygyro = mavlink_msg_simstate_get_ygyro(msg); simstate->zgyro = mavlink_msg_simstate_get_zgyro(msg); + simstate->lat = mavlink_msg_simstate_get_lat(msg); + simstate->lng = mavlink_msg_simstate_get_lng(msg); #else - memcpy(simstate, _MAV_PAYLOAD(msg), 36); + memcpy(simstate, _MAV_PAYLOAD(msg), 44); #endif } diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_wind.h b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_wind.h new file mode 100644 index 0000000000..e0810a9d3b --- /dev/null +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/mavlink_msg_wind.h @@ -0,0 +1,188 @@ +// MESSAGE WIND PACKING + +#define MAVLINK_MSG_ID_WIND 168 + +typedef struct __mavlink_wind_t +{ + float direction; ///< wind direction (degrees) + float speed; ///< wind speed in ground plane (m/s) + float speed_z; ///< vertical wind speed (m/s) +} mavlink_wind_t; + +#define MAVLINK_MSG_ID_WIND_LEN 12 +#define MAVLINK_MSG_ID_168_LEN 12 + + + +#define MAVLINK_MESSAGE_INFO_WIND { \ + "WIND", \ + 3, \ + { { "direction", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_wind_t, direction) }, \ + { "speed", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_wind_t, speed) }, \ + { "speed_z", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_wind_t, speed_z) }, \ + } \ +} + + +/** + * @brief Pack a wind message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param direction wind direction (degrees) + * @param speed wind speed in ground plane (m/s) + * @param speed_z vertical wind speed (m/s) + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_wind_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + float direction, float speed, float speed_z) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[12]; + _mav_put_float(buf, 0, direction); + _mav_put_float(buf, 4, speed); + _mav_put_float(buf, 8, speed_z); + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); +#else + mavlink_wind_t packet; + packet.direction = direction; + packet.speed = speed; + packet.speed_z = speed_z; + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); +#endif + + msg->msgid = MAVLINK_MSG_ID_WIND; + return mavlink_finalize_message(msg, system_id, component_id, 12, 1); +} + +/** + * @brief Pack a wind message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param direction wind direction (degrees) + * @param speed wind speed in ground plane (m/s) + * @param speed_z vertical wind speed (m/s) + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_wind_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + float direction,float speed,float speed_z) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[12]; + _mav_put_float(buf, 0, direction); + _mav_put_float(buf, 4, speed); + _mav_put_float(buf, 8, speed_z); + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 12); +#else + mavlink_wind_t packet; + packet.direction = direction; + packet.speed = speed; + packet.speed_z = speed_z; + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 12); +#endif + + msg->msgid = MAVLINK_MSG_ID_WIND; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 12, 1); +} + +/** + * @brief Encode a wind struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param wind C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_wind_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_wind_t* wind) +{ + return mavlink_msg_wind_pack(system_id, component_id, msg, wind->direction, wind->speed, wind->speed_z); +} + +/** + * @brief Send a wind message + * @param chan MAVLink channel to send the message + * + * @param direction wind direction (degrees) + * @param speed wind speed in ground plane (m/s) + * @param speed_z vertical wind speed (m/s) + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_wind_send(mavlink_channel_t chan, float direction, float speed, float speed_z) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[12]; + _mav_put_float(buf, 0, direction); + _mav_put_float(buf, 4, speed); + _mav_put_float(buf, 8, speed_z); + + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WIND, buf, 12, 1); +#else + mavlink_wind_t packet; + packet.direction = direction; + packet.speed = speed; + packet.speed_z = speed_z; + + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_WIND, (const char *)&packet, 12, 1); +#endif +} + +#endif + +// MESSAGE WIND UNPACKING + + +/** + * @brief Get field direction from wind message + * + * @return wind direction (degrees) + */ +static inline float mavlink_msg_wind_get_direction(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 0); +} + +/** + * @brief Get field speed from wind message + * + * @return wind speed in ground plane (m/s) + */ +static inline float mavlink_msg_wind_get_speed(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 4); +} + +/** + * @brief Get field speed_z from wind message + * + * @return vertical wind speed (m/s) + */ +static inline float mavlink_msg_wind_get_speed_z(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 8); +} + +/** + * @brief Decode a wind message into a struct + * + * @param msg The message to decode + * @param wind C-struct to decode the message contents into + */ +static inline void mavlink_msg_wind_decode(const mavlink_message_t* msg, mavlink_wind_t* wind) +{ +#if MAVLINK_NEED_BYTE_SWAP + wind->direction = mavlink_msg_wind_get_direction(msg); + wind->speed = mavlink_msg_wind_get_speed(msg); + wind->speed_z = mavlink_msg_wind_get_speed_z(msg); +#else + memcpy(wind, _MAV_PAYLOAD(msg), 12); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/ardupilotmega/testsuite.h b/mavlink/include/mavlink/v1.0/ardupilotmega/testsuite.h index aa83889d66..0442ab7875 100644 --- a/mavlink/include/mavlink/v1.0/ardupilotmega/testsuite.h +++ b/mavlink/include/mavlink/v1.0/ardupilotmega/testsuite.h @@ -738,6 +738,8 @@ static void mavlink_test_simstate(uint8_t system_id, uint8_t component_id, mavli 185.0, 213.0, 241.0, + 269.0, + 297.0, }; mavlink_simstate_t packet1, packet2; memset(&packet1, 0, sizeof(packet1)); @@ -750,6 +752,8 @@ static void mavlink_test_simstate(uint8_t system_id, uint8_t component_id, mavli packet1.xgyro = packet_in.xgyro; packet1.ygyro = packet_in.ygyro; packet1.zgyro = packet_in.zgyro; + packet1.lat = packet_in.lat; + packet1.lng = packet_in.lng; @@ -759,12 +763,12 @@ static void mavlink_test_simstate(uint8_t system_id, uint8_t component_id, mavli MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_simstate_pack(system_id, component_id, &msg , packet1.roll , packet1.pitch , packet1.yaw , packet1.xacc , packet1.yacc , packet1.zacc , packet1.xgyro , packet1.ygyro , packet1.zgyro ); + mavlink_msg_simstate_pack(system_id, component_id, &msg , packet1.roll , packet1.pitch , packet1.yaw , packet1.xacc , packet1.yacc , packet1.zacc , packet1.xgyro , packet1.ygyro , packet1.zgyro , packet1.lat , packet1.lng ); mavlink_msg_simstate_decode(&msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_simstate_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.roll , packet1.pitch , packet1.yaw , packet1.xacc , packet1.yacc , packet1.zacc , packet1.xgyro , packet1.ygyro , packet1.zgyro ); + mavlink_msg_simstate_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.roll , packet1.pitch , packet1.yaw , packet1.xacc , packet1.yacc , packet1.zacc , packet1.xgyro , packet1.ygyro , packet1.zgyro , packet1.lat , packet1.lng ); mavlink_msg_simstate_decode(&msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); @@ -777,7 +781,7 @@ static void mavlink_test_simstate(uint8_t system_id, uint8_t component_id, mavli MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_simstate_send(MAVLINK_COMM_1 , packet1.roll , packet1.pitch , packet1.yaw , packet1.xacc , packet1.yacc , packet1.zacc , packet1.xgyro , packet1.ygyro , packet1.zgyro ); + mavlink_msg_simstate_send(MAVLINK_COMM_1 , packet1.roll , packet1.pitch , packet1.yaw , packet1.xacc , packet1.yacc , packet1.zacc , packet1.xgyro , packet1.ygyro , packet1.zgyro , packet1.lat , packet1.lng ); mavlink_msg_simstate_decode(last_msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); } @@ -882,6 +886,300 @@ static void mavlink_test_radio(uint8_t system_id, uint8_t component_id, mavlink_ MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); } +static void mavlink_test_limits_status(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) +{ + mavlink_message_t msg; + uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; + uint16_t i; + mavlink_limits_status_t packet_in = { + 963497464, + 963497672, + 963497880, + 963498088, + 18067, + 187, + 254, + 65, + 132, + }; + mavlink_limits_status_t packet1, packet2; + memset(&packet1, 0, sizeof(packet1)); + packet1.last_trigger = packet_in.last_trigger; + packet1.last_action = packet_in.last_action; + packet1.last_recovery = packet_in.last_recovery; + packet1.last_clear = packet_in.last_clear; + packet1.breach_count = packet_in.breach_count; + packet1.limits_state = packet_in.limits_state; + packet1.mods_enabled = packet_in.mods_enabled; + packet1.mods_required = packet_in.mods_required; + packet1.mods_triggered = packet_in.mods_triggered; + + + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_limits_status_encode(system_id, component_id, &msg, &packet1); + mavlink_msg_limits_status_decode(&msg, &packet2); + MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_limits_status_pack(system_id, component_id, &msg , packet1.limits_state , packet1.last_trigger , packet1.last_action , packet1.last_recovery , packet1.last_clear , packet1.breach_count , packet1.mods_enabled , packet1.mods_required , packet1.mods_triggered ); + mavlink_msg_limits_status_decode(&msg, &packet2); + MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_limits_status_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.limits_state , packet1.last_trigger , packet1.last_action , packet1.last_recovery , packet1.last_clear , packet1.breach_count , packet1.mods_enabled , packet1.mods_required , packet1.mods_triggered ); + mavlink_msg_limits_status_decode(&msg, &packet2); + MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_to_send_buffer(buffer, &msg); + for (i=0; i0: single images every n seconds (decimal)| Recording: 0: disabled, 1: enabled compressed, 2: enabled raw| Empty| Empty| Empty| */ MAV_CMD_DO_LAST=240, /* NOP - This command is only used to mark the upper limit of the DO commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_PREFLIGHT_CALIBRATION=241, /* Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Empty| Empty| Empty| */ + MAV_CMD_PREFLIGHT_CALIBRATION=241, /* Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Accelerometer calibration: 0: no, 1: yes| Empty| Empty| */ MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS=242, /* Set sensor offsets. This command will be only accepted if in pre-flight mode. |Sensor to adjust the offsets for: 0: gyros, 1: accelerometer, 2: magnetometer, 3: barometer, 4: optical flow| X axis offset (or generic dimension 1), in the sensor's raw units| Y axis offset (or generic dimension 2), in the sensor's raw units| Z axis offset (or generic dimension 3), in the sensor's raw units| Generic dimension 4, in the sensor's raw units| Generic dimension 5, in the sensor's raw units| Generic dimension 6, in the sensor's raw units| */ MAV_CMD_PREFLIGHT_STORAGE=245, /* Request storage of different parameter values and logs. This command will be only accepted if in pre-flight mode. |Parameter storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Mission storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Reserved| Reserved| Empty| Empty| Empty| */ MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN=246, /* Request the reboot or shutdown of system components. |0: Do nothing for autopilot, 1: Reboot autopilot, 2: Shutdown autopilot.| 0: Do nothing for onboard computer, 1: Reboot onboard computer, 2: Shutdown onboard computer.| Reserved| Reserved| Empty| Empty| Empty| */ @@ -336,19 +324,22 @@ enum MAV_CMD_ACK }; #endif -/** @brief type of a mavlink parameter */ -#ifndef HAVE_ENUM_MAV_VAR -#define HAVE_ENUM_MAV_VAR -enum MAV_VAR +/** @brief Specifies the datatype of a MAVLink parameter. */ +#ifndef HAVE_ENUM_MAV_PARAM_TYPE +#define HAVE_ENUM_MAV_PARAM_TYPE +enum MAV_PARAM_TYPE { - MAV_VAR_FLOAT=0, /* 32 bit float | */ - MAV_VAR_UINT8=1, /* 8 bit unsigned integer | */ - MAV_VAR_INT8=2, /* 8 bit signed integer | */ - MAV_VAR_UINT16=3, /* 16 bit unsigned integer | */ - MAV_VAR_INT16=4, /* 16 bit signed integer | */ - MAV_VAR_UINT32=5, /* 32 bit unsigned integer | */ - MAV_VAR_INT32=6, /* 32 bit signed integer | */ - MAV_VAR_ENUM_END=7, /* | */ + MAV_PARAM_TYPE_UINT8=1, /* 8-bit unsigned integer | */ + MAV_PARAM_TYPE_INT8=2, /* 8-bit signed integer | */ + MAV_PARAM_TYPE_UINT16=3, /* 16-bit unsigned integer | */ + MAV_PARAM_TYPE_INT16=4, /* 16-bit signed integer | */ + MAV_PARAM_TYPE_UINT32=5, /* 32-bit unsigned integer | */ + MAV_PARAM_TYPE_INT32=6, /* 32-bit signed integer | */ + MAV_PARAM_TYPE_UINT64=7, /* 64-bit unsigned integer | */ + MAV_PARAM_TYPE_INT64=8, /* 64-bit signed integer | */ + MAV_PARAM_TYPE_REAL32=9, /* 32-bit floating-point | */ + MAV_PARAM_TYPE_REAL64=10, /* 64-bit floating-point | */ + MAV_PARAM_TYPE_ENUM_END=11, /* | */ }; #endif @@ -407,6 +398,19 @@ enum MAV_SEVERITY }; #endif + + +// MAVLINK VERSION + +#ifndef MAVLINK_VERSION +#define MAVLINK_VERSION 3 +#endif + +#if (MAVLINK_VERSION == 0) +#undef MAVLINK_VERSION +#define MAVLINK_VERSION 3 +#endif + // MESSAGE DEFINITIONS #include "./mavlink_msg_heartbeat.h" #include "./mavlink_msg_sys_status.h" @@ -459,6 +463,7 @@ enum MAV_SEVERITY #include "./mavlink_msg_set_quad_motors_setpoint.h" #include "./mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust.h" #include "./mavlink_msg_nav_controller_output.h" +#include "./mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust.h" #include "./mavlink_msg_state_correction.h" #include "./mavlink_msg_request_data_stream.h" #include "./mavlink_msg_data_stream.h" @@ -476,6 +481,7 @@ enum MAV_SEVERITY #include "./mavlink_msg_vision_position_estimate.h" #include "./mavlink_msg_vision_speed_estimate.h" #include "./mavlink_msg_vicon_position_estimate.h" +#include "./mavlink_msg_highres_imu.h" #include "./mavlink_msg_memory_vect.h" #include "./mavlink_msg_debug_vect.h" #include "./mavlink_msg_named_value_float.h" diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_attitude.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_attitude.h index 9074a1d80f..6db0592f24 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_attitude.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_attitude.h @@ -5,9 +5,9 @@ typedef struct __mavlink_attitude_t { uint32_t time_boot_ms; ///< Timestamp (milliseconds since system boot) - float roll; ///< Roll angle (rad) - float pitch; ///< Pitch angle (rad) - float yaw; ///< Yaw angle (rad) + float roll; ///< Roll angle (rad, -pi..+pi) + float pitch; ///< Pitch angle (rad, -pi..+pi) + float yaw; ///< Yaw angle (rad, -pi..+pi) float rollspeed; ///< Roll angular speed (rad/s) float pitchspeed; ///< Pitch angular speed (rad/s) float yawspeed; ///< Yaw angular speed (rad/s) @@ -39,9 +39,9 @@ typedef struct __mavlink_attitude_t * @param msg The MAVLink message to compress the data into * * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) + * @param roll Roll angle (rad, -pi..+pi) + * @param pitch Pitch angle (rad, -pi..+pi) + * @param yaw Yaw angle (rad, -pi..+pi) * @param rollspeed Roll angular speed (rad/s) * @param pitchspeed Pitch angular speed (rad/s) * @param yawspeed Yaw angular speed (rad/s) @@ -85,9 +85,9 @@ static inline uint16_t mavlink_msg_attitude_pack(uint8_t system_id, uint8_t comp * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) + * @param roll Roll angle (rad, -pi..+pi) + * @param pitch Pitch angle (rad, -pi..+pi) + * @param yaw Yaw angle (rad, -pi..+pi) * @param rollspeed Roll angular speed (rad/s) * @param pitchspeed Pitch angular speed (rad/s) * @param yawspeed Yaw angular speed (rad/s) @@ -143,9 +143,9 @@ static inline uint16_t mavlink_msg_attitude_encode(uint8_t system_id, uint8_t co * @param chan MAVLink channel to send the message * * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param roll Roll angle (rad) - * @param pitch Pitch angle (rad) - * @param yaw Yaw angle (rad) + * @param roll Roll angle (rad, -pi..+pi) + * @param pitch Pitch angle (rad, -pi..+pi) + * @param yaw Yaw angle (rad, -pi..+pi) * @param rollspeed Roll angular speed (rad/s) * @param pitchspeed Pitch angular speed (rad/s) * @param yawspeed Yaw angular speed (rad/s) @@ -197,7 +197,7 @@ static inline uint32_t mavlink_msg_attitude_get_time_boot_ms(const mavlink_messa /** * @brief Get field roll from attitude message * - * @return Roll angle (rad) + * @return Roll angle (rad, -pi..+pi) */ static inline float mavlink_msg_attitude_get_roll(const mavlink_message_t* msg) { @@ -207,7 +207,7 @@ static inline float mavlink_msg_attitude_get_roll(const mavlink_message_t* msg) /** * @brief Get field pitch from attitude message * - * @return Pitch angle (rad) + * @return Pitch angle (rad, -pi..+pi) */ static inline float mavlink_msg_attitude_get_pitch(const mavlink_message_t* msg) { @@ -217,7 +217,7 @@ static inline float mavlink_msg_attitude_get_pitch(const mavlink_message_t* msg) /** * @brief Get field yaw from attitude message * - * @return Yaw angle (rad) + * @return Yaw angle (rad, -pi..+pi) */ static inline float mavlink_msg_attitude_get_yaw(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_global_vision_position_estimate.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_global_vision_position_estimate.h index e4617702bd..a911fe25ef 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_global_vision_position_estimate.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_global_vision_position_estimate.h @@ -4,7 +4,7 @@ typedef struct __mavlink_global_vision_position_estimate_t { - uint64_t usec; ///< Timestamp (milliseconds) + uint64_t usec; ///< Timestamp (microseconds, synced to UNIX time or since system boot) float x; ///< Global X position float y; ///< Global Y position float z; ///< Global Z position @@ -38,7 +38,7 @@ typedef struct __mavlink_global_vision_position_estimate_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -84,7 +84,7 @@ static inline uint16_t mavlink_msg_global_vision_position_estimate_pack(uint8_t * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -142,7 +142,7 @@ static inline uint16_t mavlink_msg_global_vision_position_estimate_encode(uint8_ * @brief Send a global_vision_position_estimate message * @param chan MAVLink channel to send the message * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -187,7 +187,7 @@ static inline void mavlink_msg_global_vision_position_estimate_send(mavlink_chan /** * @brief Get field usec from global_vision_position_estimate message * - * @return Timestamp (milliseconds) + * @return Timestamp (microseconds, synced to UNIX time or since system boot) */ static inline uint64_t mavlink_msg_global_vision_position_estimate_get_usec(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_highres_imu.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_highres_imu.h new file mode 100644 index 0000000000..9714c698fa --- /dev/null +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_highres_imu.h @@ -0,0 +1,452 @@ +// MESSAGE HIGHRES_IMU PACKING + +#define MAVLINK_MSG_ID_HIGHRES_IMU 105 + +typedef struct __mavlink_highres_imu_t +{ + uint64_t time_usec; ///< Timestamp (microseconds, synced to UNIX time or since system boot) + float xacc; ///< X acceleration (m/s^2) + float yacc; ///< Y acceleration (m/s^2) + float zacc; ///< Z acceleration (m/s^2) + float xgyro; ///< Angular speed around X axis (rad / sec) + float ygyro; ///< Angular speed around Y axis (rad / sec) + float zgyro; ///< Angular speed around Z axis (rad / sec) + float xmag; ///< X Magnetic field (Gauss) + float ymag; ///< Y Magnetic field (Gauss) + float zmag; ///< Z Magnetic field (Gauss) + float abs_pressure; ///< Absolute pressure in millibar + float diff_pressure; ///< Differential pressure in millibar + float pressure_alt; ///< Altitude calculated from pressure + float temperature; ///< Temperature in degrees celsius + uint16_t fields_updated; ///< Bitmask for fields that have updated since last message, bit 0 = xacc, bit 12: temperature +} mavlink_highres_imu_t; + +#define MAVLINK_MSG_ID_HIGHRES_IMU_LEN 62 +#define MAVLINK_MSG_ID_105_LEN 62 + + + +#define MAVLINK_MESSAGE_INFO_HIGHRES_IMU { \ + "HIGHRES_IMU", \ + 15, \ + { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_highres_imu_t, time_usec) }, \ + { "xacc", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_highres_imu_t, xacc) }, \ + { "yacc", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_highres_imu_t, yacc) }, \ + { "zacc", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_highres_imu_t, zacc) }, \ + { "xgyro", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_highres_imu_t, xgyro) }, \ + { "ygyro", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_highres_imu_t, ygyro) }, \ + { "zgyro", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_highres_imu_t, zgyro) }, \ + { "xmag", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_highres_imu_t, xmag) }, \ + { "ymag", NULL, MAVLINK_TYPE_FLOAT, 0, 36, offsetof(mavlink_highres_imu_t, ymag) }, \ + { "zmag", NULL, MAVLINK_TYPE_FLOAT, 0, 40, offsetof(mavlink_highres_imu_t, zmag) }, \ + { "abs_pressure", NULL, MAVLINK_TYPE_FLOAT, 0, 44, offsetof(mavlink_highres_imu_t, abs_pressure) }, \ + { "diff_pressure", NULL, MAVLINK_TYPE_FLOAT, 0, 48, offsetof(mavlink_highres_imu_t, diff_pressure) }, \ + { "pressure_alt", NULL, MAVLINK_TYPE_FLOAT, 0, 52, offsetof(mavlink_highres_imu_t, pressure_alt) }, \ + { "temperature", NULL, MAVLINK_TYPE_FLOAT, 0, 56, offsetof(mavlink_highres_imu_t, temperature) }, \ + { "fields_updated", NULL, MAVLINK_TYPE_UINT16_T, 0, 60, offsetof(mavlink_highres_imu_t, fields_updated) }, \ + } \ +} + + +/** + * @brief Pack a highres_imu message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param time_usec Timestamp (microseconds, synced to UNIX time or since system boot) + * @param xacc X acceleration (m/s^2) + * @param yacc Y acceleration (m/s^2) + * @param zacc Z acceleration (m/s^2) + * @param xgyro Angular speed around X axis (rad / sec) + * @param ygyro Angular speed around Y axis (rad / sec) + * @param zgyro Angular speed around Z axis (rad / sec) + * @param xmag X Magnetic field (Gauss) + * @param ymag Y Magnetic field (Gauss) + * @param zmag Z Magnetic field (Gauss) + * @param abs_pressure Absolute pressure in millibar + * @param diff_pressure Differential pressure in millibar + * @param pressure_alt Altitude calculated from pressure + * @param temperature Temperature in degrees celsius + * @param fields_updated Bitmask for fields that have updated since last message, bit 0 = xacc, bit 12: temperature + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_highres_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + uint64_t time_usec, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro, float xmag, float ymag, float zmag, float abs_pressure, float diff_pressure, float pressure_alt, float temperature, uint16_t fields_updated) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[62]; + _mav_put_uint64_t(buf, 0, time_usec); + _mav_put_float(buf, 8, xacc); + _mav_put_float(buf, 12, yacc); + _mav_put_float(buf, 16, zacc); + _mav_put_float(buf, 20, xgyro); + _mav_put_float(buf, 24, ygyro); + _mav_put_float(buf, 28, zgyro); + _mav_put_float(buf, 32, xmag); + _mav_put_float(buf, 36, ymag); + _mav_put_float(buf, 40, zmag); + _mav_put_float(buf, 44, abs_pressure); + _mav_put_float(buf, 48, diff_pressure); + _mav_put_float(buf, 52, pressure_alt); + _mav_put_float(buf, 56, temperature); + _mav_put_uint16_t(buf, 60, fields_updated); + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 62); +#else + mavlink_highres_imu_t packet; + packet.time_usec = time_usec; + packet.xacc = xacc; + packet.yacc = yacc; + packet.zacc = zacc; + packet.xgyro = xgyro; + packet.ygyro = ygyro; + packet.zgyro = zgyro; + packet.xmag = xmag; + packet.ymag = ymag; + packet.zmag = zmag; + packet.abs_pressure = abs_pressure; + packet.diff_pressure = diff_pressure; + packet.pressure_alt = pressure_alt; + packet.temperature = temperature; + packet.fields_updated = fields_updated; + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 62); +#endif + + msg->msgid = MAVLINK_MSG_ID_HIGHRES_IMU; + return mavlink_finalize_message(msg, system_id, component_id, 62, 93); +} + +/** + * @brief Pack a highres_imu message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param time_usec Timestamp (microseconds, synced to UNIX time or since system boot) + * @param xacc X acceleration (m/s^2) + * @param yacc Y acceleration (m/s^2) + * @param zacc Z acceleration (m/s^2) + * @param xgyro Angular speed around X axis (rad / sec) + * @param ygyro Angular speed around Y axis (rad / sec) + * @param zgyro Angular speed around Z axis (rad / sec) + * @param xmag X Magnetic field (Gauss) + * @param ymag Y Magnetic field (Gauss) + * @param zmag Z Magnetic field (Gauss) + * @param abs_pressure Absolute pressure in millibar + * @param diff_pressure Differential pressure in millibar + * @param pressure_alt Altitude calculated from pressure + * @param temperature Temperature in degrees celsius + * @param fields_updated Bitmask for fields that have updated since last message, bit 0 = xacc, bit 12: temperature + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_highres_imu_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint64_t time_usec,float xacc,float yacc,float zacc,float xgyro,float ygyro,float zgyro,float xmag,float ymag,float zmag,float abs_pressure,float diff_pressure,float pressure_alt,float temperature,uint16_t fields_updated) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[62]; + _mav_put_uint64_t(buf, 0, time_usec); + _mav_put_float(buf, 8, xacc); + _mav_put_float(buf, 12, yacc); + _mav_put_float(buf, 16, zacc); + _mav_put_float(buf, 20, xgyro); + _mav_put_float(buf, 24, ygyro); + _mav_put_float(buf, 28, zgyro); + _mav_put_float(buf, 32, xmag); + _mav_put_float(buf, 36, ymag); + _mav_put_float(buf, 40, zmag); + _mav_put_float(buf, 44, abs_pressure); + _mav_put_float(buf, 48, diff_pressure); + _mav_put_float(buf, 52, pressure_alt); + _mav_put_float(buf, 56, temperature); + _mav_put_uint16_t(buf, 60, fields_updated); + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 62); +#else + mavlink_highres_imu_t packet; + packet.time_usec = time_usec; + packet.xacc = xacc; + packet.yacc = yacc; + packet.zacc = zacc; + packet.xgyro = xgyro; + packet.ygyro = ygyro; + packet.zgyro = zgyro; + packet.xmag = xmag; + packet.ymag = ymag; + packet.zmag = zmag; + packet.abs_pressure = abs_pressure; + packet.diff_pressure = diff_pressure; + packet.pressure_alt = pressure_alt; + packet.temperature = temperature; + packet.fields_updated = fields_updated; + + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 62); +#endif + + msg->msgid = MAVLINK_MSG_ID_HIGHRES_IMU; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 62, 93); +} + +/** + * @brief Encode a highres_imu struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param highres_imu C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_highres_imu_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_highres_imu_t* highres_imu) +{ + return mavlink_msg_highres_imu_pack(system_id, component_id, msg, highres_imu->time_usec, highres_imu->xacc, highres_imu->yacc, highres_imu->zacc, highres_imu->xgyro, highres_imu->ygyro, highres_imu->zgyro, highres_imu->xmag, highres_imu->ymag, highres_imu->zmag, highres_imu->abs_pressure, highres_imu->diff_pressure, highres_imu->pressure_alt, highres_imu->temperature, highres_imu->fields_updated); +} + +/** + * @brief Send a highres_imu message + * @param chan MAVLink channel to send the message + * + * @param time_usec Timestamp (microseconds, synced to UNIX time or since system boot) + * @param xacc X acceleration (m/s^2) + * @param yacc Y acceleration (m/s^2) + * @param zacc Z acceleration (m/s^2) + * @param xgyro Angular speed around X axis (rad / sec) + * @param ygyro Angular speed around Y axis (rad / sec) + * @param zgyro Angular speed around Z axis (rad / sec) + * @param xmag X Magnetic field (Gauss) + * @param ymag Y Magnetic field (Gauss) + * @param zmag Z Magnetic field (Gauss) + * @param abs_pressure Absolute pressure in millibar + * @param diff_pressure Differential pressure in millibar + * @param pressure_alt Altitude calculated from pressure + * @param temperature Temperature in degrees celsius + * @param fields_updated Bitmask for fields that have updated since last message, bit 0 = xacc, bit 12: temperature + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_highres_imu_send(mavlink_channel_t chan, uint64_t time_usec, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro, float xmag, float ymag, float zmag, float abs_pressure, float diff_pressure, float pressure_alt, float temperature, uint16_t fields_updated) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[62]; + _mav_put_uint64_t(buf, 0, time_usec); + _mav_put_float(buf, 8, xacc); + _mav_put_float(buf, 12, yacc); + _mav_put_float(buf, 16, zacc); + _mav_put_float(buf, 20, xgyro); + _mav_put_float(buf, 24, ygyro); + _mav_put_float(buf, 28, zgyro); + _mav_put_float(buf, 32, xmag); + _mav_put_float(buf, 36, ymag); + _mav_put_float(buf, 40, zmag); + _mav_put_float(buf, 44, abs_pressure); + _mav_put_float(buf, 48, diff_pressure); + _mav_put_float(buf, 52, pressure_alt); + _mav_put_float(buf, 56, temperature); + _mav_put_uint16_t(buf, 60, fields_updated); + + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HIGHRES_IMU, buf, 62, 93); +#else + mavlink_highres_imu_t packet; + packet.time_usec = time_usec; + packet.xacc = xacc; + packet.yacc = yacc; + packet.zacc = zacc; + packet.xgyro = xgyro; + packet.ygyro = ygyro; + packet.zgyro = zgyro; + packet.xmag = xmag; + packet.ymag = ymag; + packet.zmag = zmag; + packet.abs_pressure = abs_pressure; + packet.diff_pressure = diff_pressure; + packet.pressure_alt = pressure_alt; + packet.temperature = temperature; + packet.fields_updated = fields_updated; + + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HIGHRES_IMU, (const char *)&packet, 62, 93); +#endif +} + +#endif + +// MESSAGE HIGHRES_IMU UNPACKING + + +/** + * @brief Get field time_usec from highres_imu message + * + * @return Timestamp (microseconds, synced to UNIX time or since system boot) + */ +static inline uint64_t mavlink_msg_highres_imu_get_time_usec(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint64_t(msg, 0); +} + +/** + * @brief Get field xacc from highres_imu message + * + * @return X acceleration (m/s^2) + */ +static inline float mavlink_msg_highres_imu_get_xacc(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 8); +} + +/** + * @brief Get field yacc from highres_imu message + * + * @return Y acceleration (m/s^2) + */ +static inline float mavlink_msg_highres_imu_get_yacc(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 12); +} + +/** + * @brief Get field zacc from highres_imu message + * + * @return Z acceleration (m/s^2) + */ +static inline float mavlink_msg_highres_imu_get_zacc(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 16); +} + +/** + * @brief Get field xgyro from highres_imu message + * + * @return Angular speed around X axis (rad / sec) + */ +static inline float mavlink_msg_highres_imu_get_xgyro(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 20); +} + +/** + * @brief Get field ygyro from highres_imu message + * + * @return Angular speed around Y axis (rad / sec) + */ +static inline float mavlink_msg_highres_imu_get_ygyro(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 24); +} + +/** + * @brief Get field zgyro from highres_imu message + * + * @return Angular speed around Z axis (rad / sec) + */ +static inline float mavlink_msg_highres_imu_get_zgyro(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 28); +} + +/** + * @brief Get field xmag from highres_imu message + * + * @return X Magnetic field (Gauss) + */ +static inline float mavlink_msg_highres_imu_get_xmag(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 32); +} + +/** + * @brief Get field ymag from highres_imu message + * + * @return Y Magnetic field (Gauss) + */ +static inline float mavlink_msg_highres_imu_get_ymag(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 36); +} + +/** + * @brief Get field zmag from highres_imu message + * + * @return Z Magnetic field (Gauss) + */ +static inline float mavlink_msg_highres_imu_get_zmag(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 40); +} + +/** + * @brief Get field abs_pressure from highres_imu message + * + * @return Absolute pressure in millibar + */ +static inline float mavlink_msg_highres_imu_get_abs_pressure(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 44); +} + +/** + * @brief Get field diff_pressure from highres_imu message + * + * @return Differential pressure in millibar + */ +static inline float mavlink_msg_highres_imu_get_diff_pressure(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 48); +} + +/** + * @brief Get field pressure_alt from highres_imu message + * + * @return Altitude calculated from pressure + */ +static inline float mavlink_msg_highres_imu_get_pressure_alt(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 52); +} + +/** + * @brief Get field temperature from highres_imu message + * + * @return Temperature in degrees celsius + */ +static inline float mavlink_msg_highres_imu_get_temperature(const mavlink_message_t* msg) +{ + return _MAV_RETURN_float(msg, 56); +} + +/** + * @brief Get field fields_updated from highres_imu message + * + * @return Bitmask for fields that have updated since last message, bit 0 = xacc, bit 12: temperature + */ +static inline uint16_t mavlink_msg_highres_imu_get_fields_updated(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint16_t(msg, 60); +} + +/** + * @brief Decode a highres_imu message into a struct + * + * @param msg The message to decode + * @param highres_imu C-struct to decode the message contents into + */ +static inline void mavlink_msg_highres_imu_decode(const mavlink_message_t* msg, mavlink_highres_imu_t* highres_imu) +{ +#if MAVLINK_NEED_BYTE_SWAP + highres_imu->time_usec = mavlink_msg_highres_imu_get_time_usec(msg); + highres_imu->xacc = mavlink_msg_highres_imu_get_xacc(msg); + highres_imu->yacc = mavlink_msg_highres_imu_get_yacc(msg); + highres_imu->zacc = mavlink_msg_highres_imu_get_zacc(msg); + highres_imu->xgyro = mavlink_msg_highres_imu_get_xgyro(msg); + highres_imu->ygyro = mavlink_msg_highres_imu_get_ygyro(msg); + highres_imu->zgyro = mavlink_msg_highres_imu_get_zgyro(msg); + highres_imu->xmag = mavlink_msg_highres_imu_get_xmag(msg); + highres_imu->ymag = mavlink_msg_highres_imu_get_ymag(msg); + highres_imu->zmag = mavlink_msg_highres_imu_get_zmag(msg); + highres_imu->abs_pressure = mavlink_msg_highres_imu_get_abs_pressure(msg); + highres_imu->diff_pressure = mavlink_msg_highres_imu_get_diff_pressure(msg); + highres_imu->pressure_alt = mavlink_msg_highres_imu_get_pressure_alt(msg); + highres_imu->temperature = mavlink_msg_highres_imu_get_temperature(msg); + highres_imu->fields_updated = mavlink_msg_highres_imu_get_fields_updated(msg); +#else + memcpy(highres_imu, _MAV_PAYLOAD(msg), 62); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_manual_control.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_manual_control.h index 93adce265b..96b3d3040c 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_manual_control.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_manual_control.h @@ -4,34 +4,28 @@ typedef struct __mavlink_manual_control_t { - float roll; ///< roll - float pitch; ///< pitch - float yaw; ///< yaw - float thrust; ///< thrust - uint8_t target; ///< The system to be controlled - uint8_t roll_manual; ///< roll control enabled auto:0, manual:1 - uint8_t pitch_manual; ///< pitch auto:0, manual:1 - uint8_t yaw_manual; ///< yaw auto:0, manual:1 - uint8_t thrust_manual; ///< thrust auto:0, manual:1 + int16_t x; ///< X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle. + int16_t y; ///< Y-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to left(-1000)-right(1000) movement on a joystick and the roll of a vehicle. + int16_t z; ///< Z-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a separate slider movement with maximum being 1000 and minimum being -1000 on a joystick and the thrust of a vehicle. + int16_t r; ///< R-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a twisting of the joystick, with counter-clockwise being 1000 and clockwise being -1000, and the yaw of a vehicle. + uint16_t buttons; ///< A bitfield corresponding to the joystick buttons' current state, 1 for pressed, 0 for released. The lowest bit corresponds to Button 1. + uint8_t target; ///< The system to be controlled. } mavlink_manual_control_t; -#define MAVLINK_MSG_ID_MANUAL_CONTROL_LEN 21 -#define MAVLINK_MSG_ID_69_LEN 21 +#define MAVLINK_MSG_ID_MANUAL_CONTROL_LEN 11 +#define MAVLINK_MSG_ID_69_LEN 11 #define MAVLINK_MESSAGE_INFO_MANUAL_CONTROL { \ "MANUAL_CONTROL", \ - 9, \ - { { "roll", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_manual_control_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_manual_control_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_manual_control_t, yaw) }, \ - { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_manual_control_t, thrust) }, \ - { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_manual_control_t, target) }, \ - { "roll_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_manual_control_t, roll_manual) }, \ - { "pitch_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 18, offsetof(mavlink_manual_control_t, pitch_manual) }, \ - { "yaw_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 19, offsetof(mavlink_manual_control_t, yaw_manual) }, \ - { "thrust_manual", NULL, MAVLINK_TYPE_UINT8_T, 0, 20, offsetof(mavlink_manual_control_t, thrust_manual) }, \ + 6, \ + { { "x", NULL, MAVLINK_TYPE_INT16_T, 0, 0, offsetof(mavlink_manual_control_t, x) }, \ + { "y", NULL, MAVLINK_TYPE_INT16_T, 0, 2, offsetof(mavlink_manual_control_t, y) }, \ + { "z", NULL, MAVLINK_TYPE_INT16_T, 0, 4, offsetof(mavlink_manual_control_t, z) }, \ + { "r", NULL, MAVLINK_TYPE_INT16_T, 0, 6, offsetof(mavlink_manual_control_t, r) }, \ + { "buttons", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_manual_control_t, buttons) }, \ + { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_manual_control_t, target) }, \ } \ } @@ -42,50 +36,41 @@ typedef struct __mavlink_manual_control_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 + * @param target The system to be controlled. + * @param x X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle. + * @param y Y-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to left(-1000)-right(1000) movement on a joystick and the roll of a vehicle. + * @param z Z-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a separate slider movement with maximum being 1000 and minimum being -1000 on a joystick and the thrust of a vehicle. + * @param r R-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a twisting of the joystick, with counter-clockwise being 1000 and clockwise being -1000, and the yaw of a vehicle. + * @param buttons A bitfield corresponding to the joystick buttons' current state, 1 for pressed, 0 for released. The lowest bit corresponds to Button 1. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_manual_control_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, float roll, float pitch, float yaw, float thrust, uint8_t roll_manual, uint8_t pitch_manual, uint8_t yaw_manual, uint8_t thrust_manual) + uint8_t target, int16_t x, int16_t y, int16_t z, int16_t r, uint16_t buttons) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_float(buf, 0, roll); - _mav_put_float(buf, 4, pitch); - _mav_put_float(buf, 8, yaw); - _mav_put_float(buf, 12, thrust); - _mav_put_uint8_t(buf, 16, target); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); + char buf[11]; + _mav_put_int16_t(buf, 0, x); + _mav_put_int16_t(buf, 2, y); + _mav_put_int16_t(buf, 4, z); + _mav_put_int16_t(buf, 6, r); + _mav_put_uint16_t(buf, 8, buttons); + _mav_put_uint8_t(buf, 10, target); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 11); #else mavlink_manual_control_t packet; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; + packet.x = x; + packet.y = y; + packet.z = z; + packet.r = r; + packet.buttons = buttons; packet.target = target; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 11); #endif msg->msgid = MAVLINK_MSG_ID_MANUAL_CONTROL; - return mavlink_finalize_message(msg, system_id, component_id, 21, 52); + return mavlink_finalize_message(msg, system_id, component_id, 11, 243); } /** @@ -94,51 +79,42 @@ static inline uint16_t mavlink_msg_manual_control_pack(uint8_t system_id, uint8_ * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 + * @param target The system to be controlled. + * @param x X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle. + * @param y Y-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to left(-1000)-right(1000) movement on a joystick and the roll of a vehicle. + * @param z Z-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a separate slider movement with maximum being 1000 and minimum being -1000 on a joystick and the thrust of a vehicle. + * @param r R-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a twisting of the joystick, with counter-clockwise being 1000 and clockwise being -1000, and the yaw of a vehicle. + * @param buttons A bitfield corresponding to the joystick buttons' current state, 1 for pressed, 0 for released. The lowest bit corresponds to Button 1. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_manual_control_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, - uint8_t target,float roll,float pitch,float yaw,float thrust,uint8_t roll_manual,uint8_t pitch_manual,uint8_t yaw_manual,uint8_t thrust_manual) + uint8_t target,int16_t x,int16_t y,int16_t z,int16_t r,uint16_t buttons) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_float(buf, 0, roll); - _mav_put_float(buf, 4, pitch); - _mav_put_float(buf, 8, yaw); - _mav_put_float(buf, 12, thrust); - _mav_put_uint8_t(buf, 16, target); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); + char buf[11]; + _mav_put_int16_t(buf, 0, x); + _mav_put_int16_t(buf, 2, y); + _mav_put_int16_t(buf, 4, z); + _mav_put_int16_t(buf, 6, r); + _mav_put_uint16_t(buf, 8, buttons); + _mav_put_uint8_t(buf, 10, target); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 11); #else mavlink_manual_control_t packet; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; + packet.x = x; + packet.y = y; + packet.z = z; + packet.r = r; + packet.buttons = buttons; packet.target = target; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 21); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 11); #endif msg->msgid = MAVLINK_MSG_ID_MANUAL_CONTROL; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 21, 52); + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 11, 243); } /** @@ -151,53 +127,44 @@ static inline uint16_t mavlink_msg_manual_control_pack_chan(uint8_t system_id, u */ static inline uint16_t mavlink_msg_manual_control_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_manual_control_t* manual_control) { - return mavlink_msg_manual_control_pack(system_id, component_id, msg, manual_control->target, manual_control->roll, manual_control->pitch, manual_control->yaw, manual_control->thrust, manual_control->roll_manual, manual_control->pitch_manual, manual_control->yaw_manual, manual_control->thrust_manual); + return mavlink_msg_manual_control_pack(system_id, component_id, msg, manual_control->target, manual_control->x, manual_control->y, manual_control->z, manual_control->r, manual_control->buttons); } /** * @brief Send a manual_control message * @param chan MAVLink channel to send the message * - * @param target The system to be controlled - * @param roll roll - * @param pitch pitch - * @param yaw yaw - * @param thrust thrust - * @param roll_manual roll control enabled auto:0, manual:1 - * @param pitch_manual pitch auto:0, manual:1 - * @param yaw_manual yaw auto:0, manual:1 - * @param thrust_manual thrust auto:0, manual:1 + * @param target The system to be controlled. + * @param x X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle. + * @param y Y-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to left(-1000)-right(1000) movement on a joystick and the roll of a vehicle. + * @param z Z-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a separate slider movement with maximum being 1000 and minimum being -1000 on a joystick and the thrust of a vehicle. + * @param r R-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a twisting of the joystick, with counter-clockwise being 1000 and clockwise being -1000, and the yaw of a vehicle. + * @param buttons A bitfield corresponding to the joystick buttons' current state, 1 for pressed, 0 for released. The lowest bit corresponds to Button 1. */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS -static inline void mavlink_msg_manual_control_send(mavlink_channel_t chan, uint8_t target, float roll, float pitch, float yaw, float thrust, uint8_t roll_manual, uint8_t pitch_manual, uint8_t yaw_manual, uint8_t thrust_manual) +static inline void mavlink_msg_manual_control_send(mavlink_channel_t chan, uint8_t target, int16_t x, int16_t y, int16_t z, int16_t r, uint16_t buttons) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[21]; - _mav_put_float(buf, 0, roll); - _mav_put_float(buf, 4, pitch); - _mav_put_float(buf, 8, yaw); - _mav_put_float(buf, 12, thrust); - _mav_put_uint8_t(buf, 16, target); - _mav_put_uint8_t(buf, 17, roll_manual); - _mav_put_uint8_t(buf, 18, pitch_manual); - _mav_put_uint8_t(buf, 19, yaw_manual); - _mav_put_uint8_t(buf, 20, thrust_manual); + char buf[11]; + _mav_put_int16_t(buf, 0, x); + _mav_put_int16_t(buf, 2, y); + _mav_put_int16_t(buf, 4, z); + _mav_put_int16_t(buf, 6, r); + _mav_put_uint16_t(buf, 8, buttons); + _mav_put_uint8_t(buf, 10, target); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MANUAL_CONTROL, buf, 21, 52); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MANUAL_CONTROL, buf, 11, 243); #else mavlink_manual_control_t packet; - packet.roll = roll; - packet.pitch = pitch; - packet.yaw = yaw; - packet.thrust = thrust; + packet.x = x; + packet.y = y; + packet.z = z; + packet.r = r; + packet.buttons = buttons; packet.target = target; - packet.roll_manual = roll_manual; - packet.pitch_manual = pitch_manual; - packet.yaw_manual = yaw_manual; - packet.thrust_manual = thrust_manual; - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MANUAL_CONTROL, (const char *)&packet, 21, 52); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MANUAL_CONTROL, (const char *)&packet, 11, 243); #endif } @@ -209,91 +176,61 @@ static inline void mavlink_msg_manual_control_send(mavlink_channel_t chan, uint8 /** * @brief Get field target from manual_control message * - * @return The system to be controlled + * @return The system to be controlled. */ static inline uint8_t mavlink_msg_manual_control_get_target(const mavlink_message_t* msg) { - return _MAV_RETURN_uint8_t(msg, 16); + return _MAV_RETURN_uint8_t(msg, 10); } /** - * @brief Get field roll from manual_control message + * @brief Get field x from manual_control message * - * @return roll + * @return X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle. */ -static inline float mavlink_msg_manual_control_get_roll(const mavlink_message_t* msg) +static inline int16_t mavlink_msg_manual_control_get_x(const mavlink_message_t* msg) { - return _MAV_RETURN_float(msg, 0); + return _MAV_RETURN_int16_t(msg, 0); } /** - * @brief Get field pitch from manual_control message + * @brief Get field y from manual_control message * - * @return pitch + * @return Y-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to left(-1000)-right(1000) movement on a joystick and the roll of a vehicle. */ -static inline float mavlink_msg_manual_control_get_pitch(const mavlink_message_t* msg) +static inline int16_t mavlink_msg_manual_control_get_y(const mavlink_message_t* msg) { - return _MAV_RETURN_float(msg, 4); + return _MAV_RETURN_int16_t(msg, 2); } /** - * @brief Get field yaw from manual_control message + * @brief Get field z from manual_control message * - * @return yaw + * @return Z-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a separate slider movement with maximum being 1000 and minimum being -1000 on a joystick and the thrust of a vehicle. */ -static inline float mavlink_msg_manual_control_get_yaw(const mavlink_message_t* msg) +static inline int16_t mavlink_msg_manual_control_get_z(const mavlink_message_t* msg) { - return _MAV_RETURN_float(msg, 8); + return _MAV_RETURN_int16_t(msg, 4); } /** - * @brief Get field thrust from manual_control message + * @brief Get field r from manual_control message * - * @return thrust + * @return R-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a twisting of the joystick, with counter-clockwise being 1000 and clockwise being -1000, and the yaw of a vehicle. */ -static inline float mavlink_msg_manual_control_get_thrust(const mavlink_message_t* msg) +static inline int16_t mavlink_msg_manual_control_get_r(const mavlink_message_t* msg) { - return _MAV_RETURN_float(msg, 12); + return _MAV_RETURN_int16_t(msg, 6); } /** - * @brief Get field roll_manual from manual_control message + * @brief Get field buttons from manual_control message * - * @return roll control enabled auto:0, manual:1 + * @return A bitfield corresponding to the joystick buttons' current state, 1 for pressed, 0 for released. The lowest bit corresponds to Button 1. */ -static inline uint8_t mavlink_msg_manual_control_get_roll_manual(const mavlink_message_t* msg) +static inline uint16_t mavlink_msg_manual_control_get_buttons(const mavlink_message_t* msg) { - return _MAV_RETURN_uint8_t(msg, 17); -} - -/** - * @brief Get field pitch_manual from manual_control message - * - * @return pitch auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_pitch_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 18); -} - -/** - * @brief Get field yaw_manual from manual_control message - * - * @return yaw auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_yaw_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 19); -} - -/** - * @brief Get field thrust_manual from manual_control message - * - * @return thrust auto:0, manual:1 - */ -static inline uint8_t mavlink_msg_manual_control_get_thrust_manual(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 20); + return _MAV_RETURN_uint16_t(msg, 8); } /** @@ -305,16 +242,13 @@ static inline uint8_t mavlink_msg_manual_control_get_thrust_manual(const mavlink static inline void mavlink_msg_manual_control_decode(const mavlink_message_t* msg, mavlink_manual_control_t* manual_control) { #if MAVLINK_NEED_BYTE_SWAP - manual_control->roll = mavlink_msg_manual_control_get_roll(msg); - manual_control->pitch = mavlink_msg_manual_control_get_pitch(msg); - manual_control->yaw = mavlink_msg_manual_control_get_yaw(msg); - manual_control->thrust = mavlink_msg_manual_control_get_thrust(msg); + manual_control->x = mavlink_msg_manual_control_get_x(msg); + manual_control->y = mavlink_msg_manual_control_get_y(msg); + manual_control->z = mavlink_msg_manual_control_get_z(msg); + manual_control->r = mavlink_msg_manual_control_get_r(msg); + manual_control->buttons = mavlink_msg_manual_control_get_buttons(msg); manual_control->target = mavlink_msg_manual_control_get_target(msg); - manual_control->roll_manual = mavlink_msg_manual_control_get_roll_manual(msg); - manual_control->pitch_manual = mavlink_msg_manual_control_get_pitch_manual(msg); - manual_control->yaw_manual = mavlink_msg_manual_control_get_yaw_manual(msg); - manual_control->thrust_manual = mavlink_msg_manual_control_get_thrust_manual(msg); #else - memcpy(manual_control, _MAV_PAYLOAD(msg), 21); + memcpy(manual_control, _MAV_PAYLOAD(msg), 11); #endif } diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_request_read.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_request_read.h index 61d00f62d1..dba528df97 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_request_read.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_request_read.h @@ -4,10 +4,10 @@ typedef struct __mavlink_param_request_read_t { - int16_t param_index; ///< Parameter index. Send -1 to use the param ID field as identifier + int16_t param_index; ///< Parameter index. Send -1 to use the param ID field as identifier (else the param id will be ignored) uint8_t target_system; ///< System ID uint8_t target_component; ///< Component ID - char param_id[16]; ///< Onboard parameter id + char param_id[16]; ///< Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string } mavlink_param_request_read_t; #define MAVLINK_MSG_ID_PARAM_REQUEST_READ_LEN 20 @@ -34,8 +34,8 @@ typedef struct __mavlink_param_request_read_t * * @param target_system System ID * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_index Parameter index. Send -1 to use the param ID field as identifier + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string + * @param param_index Parameter index. Send -1 to use the param ID field as identifier (else the param id will be ignored) * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_param_request_read_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, @@ -69,8 +69,8 @@ static inline uint16_t mavlink_msg_param_request_read_pack(uint8_t system_id, ui * @param msg The MAVLink message to compress the data into * @param target_system System ID * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_index Parameter index. Send -1 to use the param ID field as identifier + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string + * @param param_index Parameter index. Send -1 to use the param ID field as identifier (else the param id will be ignored) * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_param_request_read_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, @@ -116,8 +116,8 @@ static inline uint16_t mavlink_msg_param_request_read_encode(uint8_t system_id, * * @param target_system System ID * @param target_component Component ID - * @param param_id Onboard parameter id - * @param param_index Parameter index. Send -1 to use the param ID field as identifier + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string + * @param param_index Parameter index. Send -1 to use the param ID field as identifier (else the param id will be ignored) */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS @@ -168,7 +168,7 @@ static inline uint8_t mavlink_msg_param_request_read_get_target_component(const /** * @brief Get field param_id from param_request_read message * - * @return Onboard parameter id + * @return Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string */ static inline uint16_t mavlink_msg_param_request_read_get_param_id(const mavlink_message_t* msg, char *param_id) { @@ -178,7 +178,7 @@ static inline uint16_t mavlink_msg_param_request_read_get_param_id(const mavlink /** * @brief Get field param_index from param_request_read message * - * @return Parameter index. Send -1 to use the param ID field as identifier + * @return Parameter index. Send -1 to use the param ID field as identifier (else the param id will be ignored) */ static inline int16_t mavlink_msg_param_request_read_get_param_index(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_set.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_set.h index a7e895f18d..8f00f22e9d 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_set.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_set.h @@ -7,8 +7,8 @@ typedef struct __mavlink_param_set_t float param_value; ///< Onboard parameter value uint8_t target_system; ///< System ID uint8_t target_component; ///< Component ID - char param_id[16]; ///< Onboard parameter id - uint8_t param_type; ///< Onboard parameter type: see MAV_VAR enum + char param_id[16]; ///< Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string + uint8_t param_type; ///< Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. } mavlink_param_set_t; #define MAVLINK_MSG_ID_PARAM_SET_LEN 23 @@ -36,9 +36,9 @@ typedef struct __mavlink_param_set_t * * @param target_system System ID * @param target_component Component ID - * @param param_id Onboard parameter id + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string * @param param_value Onboard parameter value - * @param param_type Onboard parameter type: see MAV_VAR enum + * @param param_type Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_param_set_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, @@ -74,9 +74,9 @@ static inline uint16_t mavlink_msg_param_set_pack(uint8_t system_id, uint8_t com * @param msg The MAVLink message to compress the data into * @param target_system System ID * @param target_component Component ID - * @param param_id Onboard parameter id + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string * @param param_value Onboard parameter value - * @param param_type Onboard parameter type: see MAV_VAR enum + * @param param_type Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_param_set_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, @@ -124,9 +124,9 @@ static inline uint16_t mavlink_msg_param_set_encode(uint8_t system_id, uint8_t c * * @param target_system System ID * @param target_component Component ID - * @param param_id Onboard parameter id + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string * @param param_value Onboard parameter value - * @param param_type Onboard parameter type: see MAV_VAR enum + * @param param_type Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS @@ -179,7 +179,7 @@ static inline uint8_t mavlink_msg_param_set_get_target_component(const mavlink_m /** * @brief Get field param_id from param_set message * - * @return Onboard parameter id + * @return Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string */ static inline uint16_t mavlink_msg_param_set_get_param_id(const mavlink_message_t* msg, char *param_id) { @@ -199,7 +199,7 @@ static inline float mavlink_msg_param_set_get_param_value(const mavlink_message_ /** * @brief Get field param_type from param_set message * - * @return Onboard parameter type: see MAV_VAR enum + * @return Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. */ static inline uint8_t mavlink_msg_param_set_get_param_type(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_value.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_value.h index 4e16a56318..03a6319843 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_value.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_param_value.h @@ -7,8 +7,8 @@ typedef struct __mavlink_param_value_t float param_value; ///< Onboard parameter value uint16_t param_count; ///< Total number of onboard parameters uint16_t param_index; ///< Index of this onboard parameter - char param_id[16]; ///< Onboard parameter id - uint8_t param_type; ///< Onboard parameter type: see MAV_VAR enum + char param_id[16]; ///< Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string + uint8_t param_type; ///< Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. } mavlink_param_value_t; #define MAVLINK_MSG_ID_PARAM_VALUE_LEN 25 @@ -34,9 +34,9 @@ typedef struct __mavlink_param_value_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param param_id Onboard parameter id + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string * @param param_value Onboard parameter value - * @param param_type Onboard parameter type: see MAV_VAR enum + * @param param_type Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. * @param param_count Total number of onboard parameters * @param param_index Index of this onboard parameter * @return length of the message in bytes (excluding serial stream start sign) @@ -72,9 +72,9 @@ static inline uint16_t mavlink_msg_param_value_pack(uint8_t system_id, uint8_t c * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param param_id Onboard parameter id + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string * @param param_value Onboard parameter value - * @param param_type Onboard parameter type: see MAV_VAR enum + * @param param_type Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. * @param param_count Total number of onboard parameters * @param param_index Index of this onboard parameter * @return length of the message in bytes (excluding serial stream start sign) @@ -122,9 +122,9 @@ static inline uint16_t mavlink_msg_param_value_encode(uint8_t system_id, uint8_t * @brief Send a param_value message * @param chan MAVLink channel to send the message * - * @param param_id Onboard parameter id + * @param param_id Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string * @param param_value Onboard parameter value - * @param param_type Onboard parameter type: see MAV_VAR enum + * @param param_type Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. * @param param_count Total number of onboard parameters * @param param_index Index of this onboard parameter */ @@ -159,7 +159,7 @@ static inline void mavlink_msg_param_value_send(mavlink_channel_t chan, const ch /** * @brief Get field param_id from param_value message * - * @return Onboard parameter id + * @return Onboard parameter id, terminated by NULL if the length is less than 16 human-readable chars and WITHOUT null termination (NULL) byte if the length is exactly 16 chars - applications have to provide 16+1 bytes storage if the ID is stored as string */ static inline uint16_t mavlink_msg_param_value_get_param_id(const mavlink_message_t* msg, char *param_id) { @@ -179,7 +179,7 @@ static inline float mavlink_msg_param_value_get_param_value(const mavlink_messag /** * @brief Get field param_type from param_value message * - * @return Onboard parameter type: see MAV_VAR enum + * @return Onboard parameter type: see the MAV_PARAM_TYPE enum for supported data types. */ static inline uint8_t mavlink_msg_param_value_get_param_type(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_raw.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_raw.h index a5b28021d5..a4d40da380 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_raw.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_raw.h @@ -5,16 +5,16 @@ typedef struct __mavlink_rc_channels_raw_t { uint32_t time_boot_ms; ///< Timestamp (milliseconds since system boot) - uint16_t chan1_raw; ///< RC channel 1 value, in microseconds - uint16_t chan2_raw; ///< RC channel 2 value, in microseconds - uint16_t chan3_raw; ///< RC channel 3 value, in microseconds - uint16_t chan4_raw; ///< RC channel 4 value, in microseconds - uint16_t chan5_raw; ///< RC channel 5 value, in microseconds - uint16_t chan6_raw; ///< RC channel 6 value, in microseconds - uint16_t chan7_raw; ///< RC channel 7 value, in microseconds - uint16_t chan8_raw; ///< RC channel 8 value, in microseconds - uint8_t port; ///< Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - uint8_t rssi; ///< Receive signal strength indicator, 0: 0%, 255: 100% + uint16_t chan1_raw; ///< RC channel 1 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan2_raw; ///< RC channel 2 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan3_raw; ///< RC channel 3 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan4_raw; ///< RC channel 4 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan5_raw; ///< RC channel 5 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan6_raw; ///< RC channel 6 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan7_raw; ///< RC channel 7 value, in microseconds. A value of 65535 implies the channel is unused. + uint16_t chan8_raw; ///< RC channel 8 value, in microseconds. A value of 65535 implies the channel is unused. + uint8_t port; ///< Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + uint8_t rssi; ///< Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. } mavlink_rc_channels_raw_t; #define MAVLINK_MSG_ID_RC_CHANNELS_RAW_LEN 22 @@ -47,16 +47,16 @@ typedef struct __mavlink_rc_channels_raw_t * @param msg The MAVLink message to compress the data into * * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% + * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + * @param chan1_raw RC channel 1 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan2_raw RC channel 2 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan3_raw RC channel 3 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan4_raw RC channel 4 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan5_raw RC channel 5 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan6_raw RC channel 6 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan7_raw RC channel 7 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan8_raw RC channel 8 value, in microseconds. A value of 65535 implies the channel is unused. + * @param rssi Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_rc_channels_raw_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, @@ -105,16 +105,16 @@ static inline uint16_t mavlink_msg_rc_channels_raw_pack(uint8_t system_id, uint8 * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% + * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + * @param chan1_raw RC channel 1 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan2_raw RC channel 2 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan3_raw RC channel 3 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan4_raw RC channel 4 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan5_raw RC channel 5 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan6_raw RC channel 6 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan7_raw RC channel 7 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan8_raw RC channel 8 value, in microseconds. A value of 65535 implies the channel is unused. + * @param rssi Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_rc_channels_raw_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, @@ -175,16 +175,16 @@ static inline uint16_t mavlink_msg_rc_channels_raw_encode(uint8_t system_id, uin * @param chan MAVLink channel to send the message * * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - * @param chan1_raw RC channel 1 value, in microseconds - * @param chan2_raw RC channel 2 value, in microseconds - * @param chan3_raw RC channel 3 value, in microseconds - * @param chan4_raw RC channel 4 value, in microseconds - * @param chan5_raw RC channel 5 value, in microseconds - * @param chan6_raw RC channel 6 value, in microseconds - * @param chan7_raw RC channel 7 value, in microseconds - * @param chan8_raw RC channel 8 value, in microseconds - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% + * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + * @param chan1_raw RC channel 1 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan2_raw RC channel 2 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan3_raw RC channel 3 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan4_raw RC channel 4 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan5_raw RC channel 5 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan6_raw RC channel 6 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan7_raw RC channel 7 value, in microseconds. A value of 65535 implies the channel is unused. + * @param chan8_raw RC channel 8 value, in microseconds. A value of 65535 implies the channel is unused. + * @param rssi Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS @@ -241,7 +241,7 @@ static inline uint32_t mavlink_msg_rc_channels_raw_get_time_boot_ms(const mavlin /** * @brief Get field port from rc_channels_raw message * - * @return Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. + * @return Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. */ static inline uint8_t mavlink_msg_rc_channels_raw_get_port(const mavlink_message_t* msg) { @@ -251,7 +251,7 @@ static inline uint8_t mavlink_msg_rc_channels_raw_get_port(const mavlink_message /** * @brief Get field chan1_raw from rc_channels_raw message * - * @return RC channel 1 value, in microseconds + * @return RC channel 1 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan1_raw(const mavlink_message_t* msg) { @@ -261,7 +261,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan1_raw(const mavlink_m /** * @brief Get field chan2_raw from rc_channels_raw message * - * @return RC channel 2 value, in microseconds + * @return RC channel 2 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan2_raw(const mavlink_message_t* msg) { @@ -271,7 +271,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan2_raw(const mavlink_m /** * @brief Get field chan3_raw from rc_channels_raw message * - * @return RC channel 3 value, in microseconds + * @return RC channel 3 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan3_raw(const mavlink_message_t* msg) { @@ -281,7 +281,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan3_raw(const mavlink_m /** * @brief Get field chan4_raw from rc_channels_raw message * - * @return RC channel 4 value, in microseconds + * @return RC channel 4 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan4_raw(const mavlink_message_t* msg) { @@ -291,7 +291,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan4_raw(const mavlink_m /** * @brief Get field chan5_raw from rc_channels_raw message * - * @return RC channel 5 value, in microseconds + * @return RC channel 5 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan5_raw(const mavlink_message_t* msg) { @@ -301,7 +301,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan5_raw(const mavlink_m /** * @brief Get field chan6_raw from rc_channels_raw message * - * @return RC channel 6 value, in microseconds + * @return RC channel 6 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan6_raw(const mavlink_message_t* msg) { @@ -311,7 +311,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan6_raw(const mavlink_m /** * @brief Get field chan7_raw from rc_channels_raw message * - * @return RC channel 7 value, in microseconds + * @return RC channel 7 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan7_raw(const mavlink_message_t* msg) { @@ -321,7 +321,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan7_raw(const mavlink_m /** * @brief Get field chan8_raw from rc_channels_raw message * - * @return RC channel 8 value, in microseconds + * @return RC channel 8 value, in microseconds. A value of 65535 implies the channel is unused. */ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan8_raw(const mavlink_message_t* msg) { @@ -331,7 +331,7 @@ static inline uint16_t mavlink_msg_rc_channels_raw_get_chan8_raw(const mavlink_m /** * @brief Get field rssi from rc_channels_raw message * - * @return Receive signal strength indicator, 0: 0%, 255: 100% + * @return Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. */ static inline uint8_t mavlink_msg_rc_channels_raw_get_rssi(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_scaled.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_scaled.h index 23c14c03d7..dd21d4162c 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_scaled.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_rc_channels_scaled.h @@ -5,16 +5,16 @@ typedef struct __mavlink_rc_channels_scaled_t { uint32_t time_boot_ms; ///< Timestamp (milliseconds since system boot) - int16_t chan1_scaled; ///< RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan2_scaled; ///< RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan3_scaled; ///< RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan4_scaled; ///< RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan5_scaled; ///< RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan6_scaled; ///< RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan7_scaled; ///< RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - int16_t chan8_scaled; ///< RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - uint8_t port; ///< Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - uint8_t rssi; ///< Receive signal strength indicator, 0: 0%, 255: 100% + int16_t chan1_scaled; ///< RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan2_scaled; ///< RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan3_scaled; ///< RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan4_scaled; ///< RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan5_scaled; ///< RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan6_scaled; ///< RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan7_scaled; ///< RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + int16_t chan8_scaled; ///< RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + uint8_t port; ///< Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + uint8_t rssi; ///< Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. } mavlink_rc_channels_scaled_t; #define MAVLINK_MSG_ID_RC_CHANNELS_SCALED_LEN 22 @@ -47,16 +47,16 @@ typedef struct __mavlink_rc_channels_scaled_t * @param msg The MAVLink message to compress the data into * * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% + * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param rssi Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_rc_channels_scaled_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, @@ -105,16 +105,16 @@ static inline uint16_t mavlink_msg_rc_channels_scaled_pack(uint8_t system_id, ui * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% + * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param rssi Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_rc_channels_scaled_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, @@ -175,16 +175,16 @@ static inline uint16_t mavlink_msg_rc_channels_scaled_encode(uint8_t system_id, * @param chan MAVLink channel to send the message * * @param time_boot_ms Timestamp (milliseconds since system boot) - * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. - * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 - * @param rssi Receive signal strength indicator, 0: 0%, 255: 100% + * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. + * @param chan1_scaled RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan2_scaled RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan3_scaled RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan4_scaled RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan5_scaled RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan6_scaled RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan7_scaled RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param chan8_scaled RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. + * @param rssi Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS @@ -241,7 +241,7 @@ static inline uint32_t mavlink_msg_rc_channels_scaled_get_time_boot_ms(const mav /** * @brief Get field port from rc_channels_scaled message * - * @return Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. + * @return Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows for more than 8 servos. */ static inline uint8_t mavlink_msg_rc_channels_scaled_get_port(const mavlink_message_t* msg) { @@ -251,7 +251,7 @@ static inline uint8_t mavlink_msg_rc_channels_scaled_get_port(const mavlink_mess /** * @brief Get field chan1_scaled from rc_channels_scaled message * - * @return RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan1_scaled(const mavlink_message_t* msg) { @@ -261,7 +261,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan1_scaled(const mavl /** * @brief Get field chan2_scaled from rc_channels_scaled message * - * @return RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan2_scaled(const mavlink_message_t* msg) { @@ -271,7 +271,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan2_scaled(const mavl /** * @brief Get field chan3_scaled from rc_channels_scaled message * - * @return RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan3_scaled(const mavlink_message_t* msg) { @@ -281,7 +281,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan3_scaled(const mavl /** * @brief Get field chan4_scaled from rc_channels_scaled message * - * @return RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan4_scaled(const mavlink_message_t* msg) { @@ -291,7 +291,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan4_scaled(const mavl /** * @brief Get field chan5_scaled from rc_channels_scaled message * - * @return RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan5_scaled(const mavlink_message_t* msg) { @@ -301,7 +301,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan5_scaled(const mavl /** * @brief Get field chan6_scaled from rc_channels_scaled message * - * @return RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan6_scaled(const mavlink_message_t* msg) { @@ -311,7 +311,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan6_scaled(const mavl /** * @brief Get field chan7_scaled from rc_channels_scaled message * - * @return RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan7_scaled(const mavlink_message_t* msg) { @@ -321,7 +321,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan7_scaled(const mavl /** * @brief Get field chan8_scaled from rc_channels_scaled message * - * @return RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + * @return RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000, (invalid) 32767. */ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan8_scaled(const mavlink_message_t* msg) { @@ -331,7 +331,7 @@ static inline int16_t mavlink_msg_rc_channels_scaled_get_chan8_scaled(const mavl /** * @brief Get field rssi from rc_channels_scaled message * - * @return Receive signal strength indicator, 0: 0%, 255: 100% + * @return Receive signal strength indicator, 0: 0%, 100: 100%, 255: invalid/unknown. */ static inline uint8_t mavlink_msg_rc_channels_scaled_get_rssi(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_scaled_pressure.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_scaled_pressure.h index dac1e0b9a6..d9ddcd47f9 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_scaled_pressure.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_scaled_pressure.h @@ -4,7 +4,7 @@ typedef struct __mavlink_scaled_pressure_t { - uint32_t time_boot_ms; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot) + uint32_t time_boot_ms; ///< Timestamp (milliseconds since system boot) float press_abs; ///< Absolute pressure (hectopascal) float press_diff; ///< Differential pressure 1 (hectopascal) int16_t temperature; ///< Temperature measurement (0.01 degrees celsius) @@ -32,7 +32,7 @@ typedef struct __mavlink_scaled_pressure_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param time_boot_ms Timestamp (microseconds since UNIX epoch or microseconds since system boot) + * @param time_boot_ms Timestamp (milliseconds since system boot) * @param press_abs Absolute pressure (hectopascal) * @param press_diff Differential pressure 1 (hectopascal) * @param temperature Temperature measurement (0.01 degrees celsius) @@ -69,7 +69,7 @@ static inline uint16_t mavlink_msg_scaled_pressure_pack(uint8_t system_id, uint8 * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param time_boot_ms Timestamp (microseconds since UNIX epoch or microseconds since system boot) + * @param time_boot_ms Timestamp (milliseconds since system boot) * @param press_abs Absolute pressure (hectopascal) * @param press_diff Differential pressure 1 (hectopascal) * @param temperature Temperature measurement (0.01 degrees celsius) @@ -118,7 +118,7 @@ static inline uint16_t mavlink_msg_scaled_pressure_encode(uint8_t system_id, uin * @brief Send a scaled_pressure message * @param chan MAVLink channel to send the message * - * @param time_boot_ms Timestamp (microseconds since UNIX epoch or microseconds since system boot) + * @param time_boot_ms Timestamp (milliseconds since system boot) * @param press_abs Absolute pressure (hectopascal) * @param press_diff Differential pressure 1 (hectopascal) * @param temperature Temperature measurement (0.01 degrees celsius) @@ -154,7 +154,7 @@ static inline void mavlink_msg_scaled_pressure_send(mavlink_channel_t chan, uint /** * @brief Get field time_boot_ms from scaled_pressure message * - * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot) + * @return Timestamp (milliseconds since system boot) */ static inline uint32_t mavlink_msg_scaled_pressure_get_time_boot_ms(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_servo_output_raw.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_servo_output_raw.h index 34a58cd763..dbf0b2035c 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_servo_output_raw.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_servo_output_raw.h @@ -4,7 +4,7 @@ typedef struct __mavlink_servo_output_raw_t { - uint32_t time_usec; ///< Timestamp (since UNIX epoch or microseconds since system boot) + uint32_t time_boot_ms; ///< Timestamp (microseconds since system boot) uint16_t servo1_raw; ///< Servo output 1 value, in microseconds uint16_t servo2_raw; ///< Servo output 2 value, in microseconds uint16_t servo3_raw; ///< Servo output 3 value, in microseconds @@ -24,7 +24,7 @@ typedef struct __mavlink_servo_output_raw_t #define MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW { \ "SERVO_OUTPUT_RAW", \ 10, \ - { { "time_usec", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_servo_output_raw_t, time_usec) }, \ + { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_servo_output_raw_t, time_boot_ms) }, \ { "servo1_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_servo_output_raw_t, servo1_raw) }, \ { "servo2_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_servo_output_raw_t, servo2_raw) }, \ { "servo3_raw", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_servo_output_raw_t, servo3_raw) }, \ @@ -44,7 +44,7 @@ typedef struct __mavlink_servo_output_raw_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param time_usec Timestamp (since UNIX epoch or microseconds since system boot) + * @param time_boot_ms Timestamp (microseconds since system boot) * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. * @param servo1_raw Servo output 1 value, in microseconds * @param servo2_raw Servo output 2 value, in microseconds @@ -57,11 +57,11 @@ typedef struct __mavlink_servo_output_raw_t * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_servo_output_raw_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint32_t time_usec, uint8_t port, uint16_t servo1_raw, uint16_t servo2_raw, uint16_t servo3_raw, uint16_t servo4_raw, uint16_t servo5_raw, uint16_t servo6_raw, uint16_t servo7_raw, uint16_t servo8_raw) + uint32_t time_boot_ms, uint8_t port, uint16_t servo1_raw, uint16_t servo2_raw, uint16_t servo3_raw, uint16_t servo4_raw, uint16_t servo5_raw, uint16_t servo6_raw, uint16_t servo7_raw, uint16_t servo8_raw) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[21]; - _mav_put_uint32_t(buf, 0, time_usec); + _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_uint16_t(buf, 4, servo1_raw); _mav_put_uint16_t(buf, 6, servo2_raw); _mav_put_uint16_t(buf, 8, servo3_raw); @@ -75,7 +75,7 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack(uint8_t system_id, uint memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); #else mavlink_servo_output_raw_t packet; - packet.time_usec = time_usec; + packet.time_boot_ms = time_boot_ms; packet.servo1_raw = servo1_raw; packet.servo2_raw = servo2_raw; packet.servo3_raw = servo3_raw; @@ -90,7 +90,7 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack(uint8_t system_id, uint #endif msg->msgid = MAVLINK_MSG_ID_SERVO_OUTPUT_RAW; - return mavlink_finalize_message(msg, system_id, component_id, 21, 222); + return mavlink_finalize_message(msg, system_id, component_id, 21, 242); } /** @@ -99,7 +99,7 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack(uint8_t system_id, uint * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param time_usec Timestamp (since UNIX epoch or microseconds since system boot) + * @param time_boot_ms Timestamp (microseconds since system boot) * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. * @param servo1_raw Servo output 1 value, in microseconds * @param servo2_raw Servo output 2 value, in microseconds @@ -113,11 +113,11 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack(uint8_t system_id, uint */ static inline uint16_t mavlink_msg_servo_output_raw_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, - uint32_t time_usec,uint8_t port,uint16_t servo1_raw,uint16_t servo2_raw,uint16_t servo3_raw,uint16_t servo4_raw,uint16_t servo5_raw,uint16_t servo6_raw,uint16_t servo7_raw,uint16_t servo8_raw) + uint32_t time_boot_ms,uint8_t port,uint16_t servo1_raw,uint16_t servo2_raw,uint16_t servo3_raw,uint16_t servo4_raw,uint16_t servo5_raw,uint16_t servo6_raw,uint16_t servo7_raw,uint16_t servo8_raw) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[21]; - _mav_put_uint32_t(buf, 0, time_usec); + _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_uint16_t(buf, 4, servo1_raw); _mav_put_uint16_t(buf, 6, servo2_raw); _mav_put_uint16_t(buf, 8, servo3_raw); @@ -131,7 +131,7 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack_chan(uint8_t system_id, memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 21); #else mavlink_servo_output_raw_t packet; - packet.time_usec = time_usec; + packet.time_boot_ms = time_boot_ms; packet.servo1_raw = servo1_raw; packet.servo2_raw = servo2_raw; packet.servo3_raw = servo3_raw; @@ -146,7 +146,7 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack_chan(uint8_t system_id, #endif msg->msgid = MAVLINK_MSG_ID_SERVO_OUTPUT_RAW; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 21, 222); + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 21, 242); } /** @@ -159,14 +159,14 @@ static inline uint16_t mavlink_msg_servo_output_raw_pack_chan(uint8_t system_id, */ static inline uint16_t mavlink_msg_servo_output_raw_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_servo_output_raw_t* servo_output_raw) { - return mavlink_msg_servo_output_raw_pack(system_id, component_id, msg, servo_output_raw->time_usec, servo_output_raw->port, servo_output_raw->servo1_raw, servo_output_raw->servo2_raw, servo_output_raw->servo3_raw, servo_output_raw->servo4_raw, servo_output_raw->servo5_raw, servo_output_raw->servo6_raw, servo_output_raw->servo7_raw, servo_output_raw->servo8_raw); + return mavlink_msg_servo_output_raw_pack(system_id, component_id, msg, servo_output_raw->time_boot_ms, servo_output_raw->port, servo_output_raw->servo1_raw, servo_output_raw->servo2_raw, servo_output_raw->servo3_raw, servo_output_raw->servo4_raw, servo_output_raw->servo5_raw, servo_output_raw->servo6_raw, servo_output_raw->servo7_raw, servo_output_raw->servo8_raw); } /** * @brief Send a servo_output_raw message * @param chan MAVLink channel to send the message * - * @param time_usec Timestamp (since UNIX epoch or microseconds since system boot) + * @param time_boot_ms Timestamp (microseconds since system boot) * @param port Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. * @param servo1_raw Servo output 1 value, in microseconds * @param servo2_raw Servo output 2 value, in microseconds @@ -179,11 +179,11 @@ static inline uint16_t mavlink_msg_servo_output_raw_encode(uint8_t system_id, ui */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS -static inline void mavlink_msg_servo_output_raw_send(mavlink_channel_t chan, uint32_t time_usec, uint8_t port, uint16_t servo1_raw, uint16_t servo2_raw, uint16_t servo3_raw, uint16_t servo4_raw, uint16_t servo5_raw, uint16_t servo6_raw, uint16_t servo7_raw, uint16_t servo8_raw) +static inline void mavlink_msg_servo_output_raw_send(mavlink_channel_t chan, uint32_t time_boot_ms, uint8_t port, uint16_t servo1_raw, uint16_t servo2_raw, uint16_t servo3_raw, uint16_t servo4_raw, uint16_t servo5_raw, uint16_t servo6_raw, uint16_t servo7_raw, uint16_t servo8_raw) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[21]; - _mav_put_uint32_t(buf, 0, time_usec); + _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_uint16_t(buf, 4, servo1_raw); _mav_put_uint16_t(buf, 6, servo2_raw); _mav_put_uint16_t(buf, 8, servo3_raw); @@ -194,10 +194,10 @@ static inline void mavlink_msg_servo_output_raw_send(mavlink_channel_t chan, uin _mav_put_uint16_t(buf, 18, servo8_raw); _mav_put_uint8_t(buf, 20, port); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, buf, 21, 222); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, buf, 21, 242); #else mavlink_servo_output_raw_t packet; - packet.time_usec = time_usec; + packet.time_boot_ms = time_boot_ms; packet.servo1_raw = servo1_raw; packet.servo2_raw = servo2_raw; packet.servo3_raw = servo3_raw; @@ -208,7 +208,7 @@ static inline void mavlink_msg_servo_output_raw_send(mavlink_channel_t chan, uin packet.servo8_raw = servo8_raw; packet.port = port; - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, (const char *)&packet, 21, 222); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, (const char *)&packet, 21, 242); #endif } @@ -218,11 +218,11 @@ static inline void mavlink_msg_servo_output_raw_send(mavlink_channel_t chan, uin /** - * @brief Get field time_usec from servo_output_raw message + * @brief Get field time_boot_ms from servo_output_raw message * - * @return Timestamp (since UNIX epoch or microseconds since system boot) + * @return Timestamp (microseconds since system boot) */ -static inline uint32_t mavlink_msg_servo_output_raw_get_time_usec(const mavlink_message_t* msg) +static inline uint32_t mavlink_msg_servo_output_raw_get_time_boot_ms(const mavlink_message_t* msg) { return _MAV_RETURN_uint32_t(msg, 0); } @@ -326,7 +326,7 @@ static inline uint16_t mavlink_msg_servo_output_raw_get_servo8_raw(const mavlink static inline void mavlink_msg_servo_output_raw_decode(const mavlink_message_t* msg, mavlink_servo_output_raw_t* servo_output_raw) { #if MAVLINK_NEED_BYTE_SWAP - servo_output_raw->time_usec = mavlink_msg_servo_output_raw_get_time_usec(msg); + servo_output_raw->time_boot_ms = mavlink_msg_servo_output_raw_get_time_boot_ms(msg); servo_output_raw->servo1_raw = mavlink_msg_servo_output_raw_get_servo1_raw(msg); servo_output_raw->servo2_raw = mavlink_msg_servo_output_raw_get_servo2_raw(msg); servo_output_raw->servo3_raw = mavlink_msg_servo_output_raw_get_servo3_raw(msg); diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust.h new file mode 100644 index 0000000000..75a1420a1d --- /dev/null +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust.h @@ -0,0 +1,320 @@ +// MESSAGE SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST PACKING + +#define MAVLINK_MSG_ID_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST 63 + +typedef struct __mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t +{ + int16_t roll[4]; ///< Desired roll angle in radians +-PI (+-32767) + int16_t pitch[4]; ///< Desired pitch angle in radians +-PI (+-32767) + int16_t yaw[4]; ///< Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + uint16_t thrust[4]; ///< Collective thrust, scaled to uint16 (0..65535) + uint8_t group; ///< ID of the quadrotor group (0 - 255, up to 256 groups supported) + uint8_t mode; ///< ID of the flight mode (0 - 255, up to 256 modes supported) + uint8_t led_red[4]; ///< RGB red channel (0-255) + uint8_t led_blue[4]; ///< RGB green channel (0-255) + uint8_t led_green[4]; ///< RGB blue channel (0-255) +} mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t; + +#define MAVLINK_MSG_ID_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_LEN 46 +#define MAVLINK_MSG_ID_63_LEN 46 + +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_ROLL_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_PITCH_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_YAW_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_THRUST_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_LED_RED_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_LED_BLUE_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST_FIELD_LED_GREEN_LEN 4 + +#define MAVLINK_MESSAGE_INFO_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST { \ + "SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST", \ + 9, \ + { { "roll", NULL, MAVLINK_TYPE_INT16_T, 4, 0, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, roll) }, \ + { "pitch", NULL, MAVLINK_TYPE_INT16_T, 4, 8, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, pitch) }, \ + { "yaw", NULL, MAVLINK_TYPE_INT16_T, 4, 16, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, yaw) }, \ + { "thrust", NULL, MAVLINK_TYPE_UINT16_T, 4, 24, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, thrust) }, \ + { "group", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, group) }, \ + { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, mode) }, \ + { "led_red", NULL, MAVLINK_TYPE_UINT8_T, 4, 34, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, led_red) }, \ + { "led_blue", NULL, MAVLINK_TYPE_UINT8_T, 4, 38, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, led_blue) }, \ + { "led_green", NULL, MAVLINK_TYPE_UINT8_T, 4, 42, offsetof(mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t, led_green) }, \ + } \ +} + + +/** + * @brief Pack a set_quad_swarm_led_roll_pitch_yaw_thrust message + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * + * @param group ID of the quadrotor group (0 - 255, up to 256 groups supported) + * @param mode ID of the flight mode (0 - 255, up to 256 modes supported) + * @param led_red RGB red channel (0-255) + * @param led_blue RGB green channel (0-255) + * @param led_green RGB blue channel (0-255) + * @param roll Desired roll angle in radians +-PI (+-32767) + * @param pitch Desired pitch angle in radians +-PI (+-32767) + * @param yaw Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + * @param thrust Collective thrust, scaled to uint16 (0..65535) + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, + uint8_t group, uint8_t mode, const uint8_t *led_red, const uint8_t *led_blue, const uint8_t *led_green, const int16_t *roll, const int16_t *pitch, const int16_t *yaw, const uint16_t *thrust) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[46]; + _mav_put_uint8_t(buf, 32, group); + _mav_put_uint8_t(buf, 33, mode); + _mav_put_int16_t_array(buf, 0, roll, 4); + _mav_put_int16_t_array(buf, 8, pitch, 4); + _mav_put_int16_t_array(buf, 16, yaw, 4); + _mav_put_uint16_t_array(buf, 24, thrust, 4); + _mav_put_uint8_t_array(buf, 34, led_red, 4); + _mav_put_uint8_t_array(buf, 38, led_blue, 4); + _mav_put_uint8_t_array(buf, 42, led_green, 4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 46); +#else + mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t packet; + packet.group = group; + packet.mode = mode; + mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*4); + mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*4); + mav_array_memcpy(packet.led_red, led_red, sizeof(uint8_t)*4); + mav_array_memcpy(packet.led_blue, led_blue, sizeof(uint8_t)*4); + mav_array_memcpy(packet.led_green, led_green, sizeof(uint8_t)*4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 46); +#endif + + msg->msgid = MAVLINK_MSG_ID_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST; + return mavlink_finalize_message(msg, system_id, component_id, 46, 130); +} + +/** + * @brief Pack a set_quad_swarm_led_roll_pitch_yaw_thrust message on a channel + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param chan The MAVLink channel this message was sent over + * @param msg The MAVLink message to compress the data into + * @param group ID of the quadrotor group (0 - 255, up to 256 groups supported) + * @param mode ID of the flight mode (0 - 255, up to 256 modes supported) + * @param led_red RGB red channel (0-255) + * @param led_blue RGB green channel (0-255) + * @param led_green RGB blue channel (0-255) + * @param roll Desired roll angle in radians +-PI (+-32767) + * @param pitch Desired pitch angle in radians +-PI (+-32767) + * @param yaw Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + * @param thrust Collective thrust, scaled to uint16 (0..65535) + * @return length of the message in bytes (excluding serial stream start sign) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, + mavlink_message_t* msg, + uint8_t group,uint8_t mode,const uint8_t *led_red,const uint8_t *led_blue,const uint8_t *led_green,const int16_t *roll,const int16_t *pitch,const int16_t *yaw,const uint16_t *thrust) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[46]; + _mav_put_uint8_t(buf, 32, group); + _mav_put_uint8_t(buf, 33, mode); + _mav_put_int16_t_array(buf, 0, roll, 4); + _mav_put_int16_t_array(buf, 8, pitch, 4); + _mav_put_int16_t_array(buf, 16, yaw, 4); + _mav_put_uint16_t_array(buf, 24, thrust, 4); + _mav_put_uint8_t_array(buf, 34, led_red, 4); + _mav_put_uint8_t_array(buf, 38, led_blue, 4); + _mav_put_uint8_t_array(buf, 42, led_green, 4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 46); +#else + mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t packet; + packet.group = group; + packet.mode = mode; + mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*4); + mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*4); + mav_array_memcpy(packet.led_red, led_red, sizeof(uint8_t)*4); + mav_array_memcpy(packet.led_blue, led_blue, sizeof(uint8_t)*4); + mav_array_memcpy(packet.led_green, led_green, sizeof(uint8_t)*4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 46); +#endif + + msg->msgid = MAVLINK_MSG_ID_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST; + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 46, 130); +} + +/** + * @brief Encode a set_quad_swarm_led_roll_pitch_yaw_thrust struct into a message + * + * @param system_id ID of this system + * @param component_id ID of this component (e.g. 200 for IMU) + * @param msg The MAVLink message to compress the data into + * @param set_quad_swarm_led_roll_pitch_yaw_thrust C-struct to read the message contents from + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t* set_quad_swarm_led_roll_pitch_yaw_thrust) +{ + return mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_pack(system_id, component_id, msg, set_quad_swarm_led_roll_pitch_yaw_thrust->group, set_quad_swarm_led_roll_pitch_yaw_thrust->mode, set_quad_swarm_led_roll_pitch_yaw_thrust->led_red, set_quad_swarm_led_roll_pitch_yaw_thrust->led_blue, set_quad_swarm_led_roll_pitch_yaw_thrust->led_green, set_quad_swarm_led_roll_pitch_yaw_thrust->roll, set_quad_swarm_led_roll_pitch_yaw_thrust->pitch, set_quad_swarm_led_roll_pitch_yaw_thrust->yaw, set_quad_swarm_led_roll_pitch_yaw_thrust->thrust); +} + +/** + * @brief Send a set_quad_swarm_led_roll_pitch_yaw_thrust message + * @param chan MAVLink channel to send the message + * + * @param group ID of the quadrotor group (0 - 255, up to 256 groups supported) + * @param mode ID of the flight mode (0 - 255, up to 256 modes supported) + * @param led_red RGB red channel (0-255) + * @param led_blue RGB green channel (0-255) + * @param led_green RGB blue channel (0-255) + * @param roll Desired roll angle in radians +-PI (+-32767) + * @param pitch Desired pitch angle in radians +-PI (+-32767) + * @param yaw Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + * @param thrust Collective thrust, scaled to uint16 (0..65535) + */ +#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS + +static inline void mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_send(mavlink_channel_t chan, uint8_t group, uint8_t mode, const uint8_t *led_red, const uint8_t *led_blue, const uint8_t *led_green, const int16_t *roll, const int16_t *pitch, const int16_t *yaw, const uint16_t *thrust) +{ +#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS + char buf[46]; + _mav_put_uint8_t(buf, 32, group); + _mav_put_uint8_t(buf, 33, mode); + _mav_put_int16_t_array(buf, 0, roll, 4); + _mav_put_int16_t_array(buf, 8, pitch, 4); + _mav_put_int16_t_array(buf, 16, yaw, 4); + _mav_put_uint16_t_array(buf, 24, thrust, 4); + _mav_put_uint8_t_array(buf, 34, led_red, 4); + _mav_put_uint8_t_array(buf, 38, led_blue, 4); + _mav_put_uint8_t_array(buf, 42, led_green, 4); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST, buf, 46, 130); +#else + mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t packet; + packet.group = group; + packet.mode = mode; + mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*4); + mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*4); + mav_array_memcpy(packet.led_red, led_red, sizeof(uint8_t)*4); + mav_array_memcpy(packet.led_blue, led_blue, sizeof(uint8_t)*4); + mav_array_memcpy(packet.led_green, led_green, sizeof(uint8_t)*4); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST, (const char *)&packet, 46, 130); +#endif +} + +#endif + +// MESSAGE SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST UNPACKING + + +/** + * @brief Get field group from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return ID of the quadrotor group (0 - 255, up to 256 groups supported) + */ +static inline uint8_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_group(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 32); +} + +/** + * @brief Get field mode from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return ID of the flight mode (0 - 255, up to 256 modes supported) + */ +static inline uint8_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_mode(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 33); +} + +/** + * @brief Get field led_red from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return RGB red channel (0-255) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_led_red(const mavlink_message_t* msg, uint8_t *led_red) +{ + return _MAV_RETURN_uint8_t_array(msg, led_red, 4, 34); +} + +/** + * @brief Get field led_blue from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return RGB green channel (0-255) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_led_blue(const mavlink_message_t* msg, uint8_t *led_blue) +{ + return _MAV_RETURN_uint8_t_array(msg, led_blue, 4, 38); +} + +/** + * @brief Get field led_green from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return RGB blue channel (0-255) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_led_green(const mavlink_message_t* msg, uint8_t *led_green) +{ + return _MAV_RETURN_uint8_t_array(msg, led_green, 4, 42); +} + +/** + * @brief Get field roll from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return Desired roll angle in radians +-PI (+-32767) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_roll(const mavlink_message_t* msg, int16_t *roll) +{ + return _MAV_RETURN_int16_t_array(msg, roll, 4, 0); +} + +/** + * @brief Get field pitch from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return Desired pitch angle in radians +-PI (+-32767) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_pitch(const mavlink_message_t* msg, int16_t *pitch) +{ + return _MAV_RETURN_int16_t_array(msg, pitch, 4, 8); +} + +/** + * @brief Get field yaw from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_yaw(const mavlink_message_t* msg, int16_t *yaw) +{ + return _MAV_RETURN_int16_t_array(msg, yaw, 4, 16); +} + +/** + * @brief Get field thrust from set_quad_swarm_led_roll_pitch_yaw_thrust message + * + * @return Collective thrust, scaled to uint16 (0..65535) + */ +static inline uint16_t mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_thrust(const mavlink_message_t* msg, uint16_t *thrust) +{ + return _MAV_RETURN_uint16_t_array(msg, thrust, 4, 24); +} + +/** + * @brief Decode a set_quad_swarm_led_roll_pitch_yaw_thrust message into a struct + * + * @param msg The message to decode + * @param set_quad_swarm_led_roll_pitch_yaw_thrust C-struct to decode the message contents into + */ +static inline void mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_decode(const mavlink_message_t* msg, mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t* set_quad_swarm_led_roll_pitch_yaw_thrust) +{ +#if MAVLINK_NEED_BYTE_SWAP + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_roll(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->roll); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_pitch(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->pitch); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_yaw(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->yaw); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_thrust(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->thrust); + set_quad_swarm_led_roll_pitch_yaw_thrust->group = mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_group(msg); + set_quad_swarm_led_roll_pitch_yaw_thrust->mode = mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_mode(msg); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_led_red(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->led_red); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_led_blue(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->led_blue); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_get_led_green(msg, set_quad_swarm_led_roll_pitch_yaw_thrust->led_green); +#else + memcpy(set_quad_swarm_led_roll_pitch_yaw_thrust, _MAV_PAYLOAD(msg), 46); +#endif +} diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust.h index c3ea8de408..35c5db18c8 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust.h @@ -4,30 +4,31 @@ typedef struct __mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t { - int16_t roll[6]; ///< Desired roll angle in radians, scaled to int16 for 6 quadrotors: 0..5 - int16_t pitch[6]; ///< Desired pitch angle in radians, scaled to int16 for 6 quadrotors: 0..5 - int16_t yaw[6]; ///< Desired yaw angle in radians, scaled to int16 for 6 quadrotors: 0..5 - uint16_t thrust[6]; ///< Collective thrust, scaled to uint16 for 6 quadrotors: 0..5 - uint8_t target_systems[6]; ///< System IDs for 6 quadrotors: 0..5, the ID's are the MAVLink IDs + int16_t roll[4]; ///< Desired roll angle in radians +-PI (+-32767) + int16_t pitch[4]; ///< Desired pitch angle in radians +-PI (+-32767) + int16_t yaw[4]; ///< Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + uint16_t thrust[4]; ///< Collective thrust, scaled to uint16 (0..65535) + uint8_t group; ///< ID of the quadrotor group (0 - 255, up to 256 groups supported) + uint8_t mode; ///< ID of the flight mode (0 - 255, up to 256 modes supported) } mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t; -#define MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_LEN 54 -#define MAVLINK_MSG_ID_61_LEN 54 +#define MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_LEN 34 +#define MAVLINK_MSG_ID_61_LEN 34 -#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_ROLL_LEN 6 -#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_PITCH_LEN 6 -#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_YAW_LEN 6 -#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_THRUST_LEN 6 -#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_TARGET_SYSTEMS_LEN 6 +#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_ROLL_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_PITCH_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_YAW_LEN 4 +#define MAVLINK_MSG_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST_FIELD_THRUST_LEN 4 #define MAVLINK_MESSAGE_INFO_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST { \ "SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST", \ - 5, \ - { { "roll", NULL, MAVLINK_TYPE_INT16_T, 6, 0, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, roll) }, \ - { "pitch", NULL, MAVLINK_TYPE_INT16_T, 6, 12, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, pitch) }, \ - { "yaw", NULL, MAVLINK_TYPE_INT16_T, 6, 24, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, yaw) }, \ - { "thrust", NULL, MAVLINK_TYPE_UINT16_T, 6, 36, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, thrust) }, \ - { "target_systems", NULL, MAVLINK_TYPE_UINT8_T, 6, 48, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, target_systems) }, \ + 6, \ + { { "roll", NULL, MAVLINK_TYPE_INT16_T, 4, 0, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, roll) }, \ + { "pitch", NULL, MAVLINK_TYPE_INT16_T, 4, 8, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, pitch) }, \ + { "yaw", NULL, MAVLINK_TYPE_INT16_T, 4, 16, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, yaw) }, \ + { "thrust", NULL, MAVLINK_TYPE_UINT16_T, 4, 24, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, thrust) }, \ + { "group", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, group) }, \ + { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 33, offsetof(mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t, mode) }, \ } \ } @@ -38,38 +39,39 @@ typedef struct __mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param target_systems System IDs for 6 quadrotors: 0..5, the ID's are the MAVLink IDs - * @param roll Desired roll angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param pitch Desired pitch angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param yaw Desired yaw angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param thrust Collective thrust, scaled to uint16 for 6 quadrotors: 0..5 + * @param group ID of the quadrotor group (0 - 255, up to 256 groups supported) + * @param mode ID of the flight mode (0 - 255, up to 256 modes supported) + * @param roll Desired roll angle in radians +-PI (+-32767) + * @param pitch Desired pitch angle in radians +-PI (+-32767) + * @param yaw Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + * @param thrust Collective thrust, scaled to uint16 (0..65535) * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const uint8_t *target_systems, const int16_t *roll, const int16_t *pitch, const int16_t *yaw, const uint16_t *thrust) + uint8_t group, uint8_t mode, const int16_t *roll, const int16_t *pitch, const int16_t *yaw, const uint16_t *thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[54]; - - _mav_put_int16_t_array(buf, 0, roll, 6); - _mav_put_int16_t_array(buf, 12, pitch, 6); - _mav_put_int16_t_array(buf, 24, yaw, 6); - _mav_put_uint16_t_array(buf, 36, thrust, 6); - _mav_put_uint8_t_array(buf, 48, target_systems, 6); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 54); + char buf[34]; + _mav_put_uint8_t(buf, 32, group); + _mav_put_uint8_t(buf, 33, mode); + _mav_put_int16_t_array(buf, 0, roll, 4); + _mav_put_int16_t_array(buf, 8, pitch, 4); + _mav_put_int16_t_array(buf, 16, yaw, 4); + _mav_put_uint16_t_array(buf, 24, thrust, 4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 34); #else mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t packet; - - mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*6); - mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*6); - mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*6); - mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*6); - mav_array_memcpy(packet.target_systems, target_systems, sizeof(uint8_t)*6); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 54); + packet.group = group; + packet.mode = mode; + mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*4); + mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 34); #endif msg->msgid = MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST; - return mavlink_finalize_message(msg, system_id, component_id, 54, 200); + return mavlink_finalize_message(msg, system_id, component_id, 34, 240); } /** @@ -78,39 +80,40 @@ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack(uin * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param target_systems System IDs for 6 quadrotors: 0..5, the ID's are the MAVLink IDs - * @param roll Desired roll angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param pitch Desired pitch angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param yaw Desired yaw angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param thrust Collective thrust, scaled to uint16 for 6 quadrotors: 0..5 + * @param group ID of the quadrotor group (0 - 255, up to 256 groups supported) + * @param mode ID of the flight mode (0 - 255, up to 256 modes supported) + * @param roll Desired roll angle in radians +-PI (+-32767) + * @param pitch Desired pitch angle in radians +-PI (+-32767) + * @param yaw Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + * @param thrust Collective thrust, scaled to uint16 (0..65535) * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, - const uint8_t *target_systems,const int16_t *roll,const int16_t *pitch,const int16_t *yaw,const uint16_t *thrust) + uint8_t group,uint8_t mode,const int16_t *roll,const int16_t *pitch,const int16_t *yaw,const uint16_t *thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[54]; - - _mav_put_int16_t_array(buf, 0, roll, 6); - _mav_put_int16_t_array(buf, 12, pitch, 6); - _mav_put_int16_t_array(buf, 24, yaw, 6); - _mav_put_uint16_t_array(buf, 36, thrust, 6); - _mav_put_uint8_t_array(buf, 48, target_systems, 6); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 54); + char buf[34]; + _mav_put_uint8_t(buf, 32, group); + _mav_put_uint8_t(buf, 33, mode); + _mav_put_int16_t_array(buf, 0, roll, 4); + _mav_put_int16_t_array(buf, 8, pitch, 4); + _mav_put_int16_t_array(buf, 16, yaw, 4); + _mav_put_uint16_t_array(buf, 24, thrust, 4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 34); #else mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t packet; - - mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*6); - mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*6); - mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*6); - mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*6); - mav_array_memcpy(packet.target_systems, target_systems, sizeof(uint8_t)*6); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 54); + packet.group = group; + packet.mode = mode; + mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*4); + mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*4); + memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 34); #endif msg->msgid = MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 54, 200); + return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 34, 240); } /** @@ -123,41 +126,42 @@ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack_cha */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t* set_quad_swarm_roll_pitch_yaw_thrust) { - return mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack(system_id, component_id, msg, set_quad_swarm_roll_pitch_yaw_thrust->target_systems, set_quad_swarm_roll_pitch_yaw_thrust->roll, set_quad_swarm_roll_pitch_yaw_thrust->pitch, set_quad_swarm_roll_pitch_yaw_thrust->yaw, set_quad_swarm_roll_pitch_yaw_thrust->thrust); + return mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack(system_id, component_id, msg, set_quad_swarm_roll_pitch_yaw_thrust->group, set_quad_swarm_roll_pitch_yaw_thrust->mode, set_quad_swarm_roll_pitch_yaw_thrust->roll, set_quad_swarm_roll_pitch_yaw_thrust->pitch, set_quad_swarm_roll_pitch_yaw_thrust->yaw, set_quad_swarm_roll_pitch_yaw_thrust->thrust); } /** * @brief Send a set_quad_swarm_roll_pitch_yaw_thrust message * @param chan MAVLink channel to send the message * - * @param target_systems System IDs for 6 quadrotors: 0..5, the ID's are the MAVLink IDs - * @param roll Desired roll angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param pitch Desired pitch angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param yaw Desired yaw angle in radians, scaled to int16 for 6 quadrotors: 0..5 - * @param thrust Collective thrust, scaled to uint16 for 6 quadrotors: 0..5 + * @param group ID of the quadrotor group (0 - 255, up to 256 groups supported) + * @param mode ID of the flight mode (0 - 255, up to 256 modes supported) + * @param roll Desired roll angle in radians +-PI (+-32767) + * @param pitch Desired pitch angle in radians +-PI (+-32767) + * @param yaw Desired yaw angle in radians, scaled to int16 +-PI (+-32767) + * @param thrust Collective thrust, scaled to uint16 (0..65535) */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS -static inline void mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_send(mavlink_channel_t chan, const uint8_t *target_systems, const int16_t *roll, const int16_t *pitch, const int16_t *yaw, const uint16_t *thrust) +static inline void mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_send(mavlink_channel_t chan, uint8_t group, uint8_t mode, const int16_t *roll, const int16_t *pitch, const int16_t *yaw, const uint16_t *thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[54]; - - _mav_put_int16_t_array(buf, 0, roll, 6); - _mav_put_int16_t_array(buf, 12, pitch, 6); - _mav_put_int16_t_array(buf, 24, yaw, 6); - _mav_put_uint16_t_array(buf, 36, thrust, 6); - _mav_put_uint8_t_array(buf, 48, target_systems, 6); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, buf, 54, 200); + char buf[34]; + _mav_put_uint8_t(buf, 32, group); + _mav_put_uint8_t(buf, 33, mode); + _mav_put_int16_t_array(buf, 0, roll, 4); + _mav_put_int16_t_array(buf, 8, pitch, 4); + _mav_put_int16_t_array(buf, 16, yaw, 4); + _mav_put_uint16_t_array(buf, 24, thrust, 4); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, buf, 34, 240); #else mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t packet; - - mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*6); - mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*6); - mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*6); - mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*6); - mav_array_memcpy(packet.target_systems, target_systems, sizeof(uint8_t)*6); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, (const char *)&packet, 54, 200); + packet.group = group; + packet.mode = mode; + mav_array_memcpy(packet.roll, roll, sizeof(int16_t)*4); + mav_array_memcpy(packet.pitch, pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet.yaw, yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet.thrust, thrust, sizeof(uint16_t)*4); + _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, (const char *)&packet, 34, 240); #endif } @@ -167,53 +171,63 @@ static inline void mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_send(mavlink /** - * @brief Get field target_systems from set_quad_swarm_roll_pitch_yaw_thrust message + * @brief Get field group from set_quad_swarm_roll_pitch_yaw_thrust message * - * @return System IDs for 6 quadrotors: 0..5, the ID's are the MAVLink IDs + * @return ID of the quadrotor group (0 - 255, up to 256 groups supported) */ -static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_target_systems(const mavlink_message_t* msg, uint8_t *target_systems) +static inline uint8_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_group(const mavlink_message_t* msg) { - return _MAV_RETURN_uint8_t_array(msg, target_systems, 6, 48); + return _MAV_RETURN_uint8_t(msg, 32); +} + +/** + * @brief Get field mode from set_quad_swarm_roll_pitch_yaw_thrust message + * + * @return ID of the flight mode (0 - 255, up to 256 modes supported) + */ +static inline uint8_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_mode(const mavlink_message_t* msg) +{ + return _MAV_RETURN_uint8_t(msg, 33); } /** * @brief Get field roll from set_quad_swarm_roll_pitch_yaw_thrust message * - * @return Desired roll angle in radians, scaled to int16 for 6 quadrotors: 0..5 + * @return Desired roll angle in radians +-PI (+-32767) */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_roll(const mavlink_message_t* msg, int16_t *roll) { - return _MAV_RETURN_int16_t_array(msg, roll, 6, 0); + return _MAV_RETURN_int16_t_array(msg, roll, 4, 0); } /** * @brief Get field pitch from set_quad_swarm_roll_pitch_yaw_thrust message * - * @return Desired pitch angle in radians, scaled to int16 for 6 quadrotors: 0..5 + * @return Desired pitch angle in radians +-PI (+-32767) */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_pitch(const mavlink_message_t* msg, int16_t *pitch) { - return _MAV_RETURN_int16_t_array(msg, pitch, 6, 12); + return _MAV_RETURN_int16_t_array(msg, pitch, 4, 8); } /** * @brief Get field yaw from set_quad_swarm_roll_pitch_yaw_thrust message * - * @return Desired yaw angle in radians, scaled to int16 for 6 quadrotors: 0..5 + * @return Desired yaw angle in radians, scaled to int16 +-PI (+-32767) */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_yaw(const mavlink_message_t* msg, int16_t *yaw) { - return _MAV_RETURN_int16_t_array(msg, yaw, 6, 24); + return _MAV_RETURN_int16_t_array(msg, yaw, 4, 16); } /** * @brief Get field thrust from set_quad_swarm_roll_pitch_yaw_thrust message * - * @return Collective thrust, scaled to uint16 for 6 quadrotors: 0..5 + * @return Collective thrust, scaled to uint16 (0..65535) */ static inline uint16_t mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_thrust(const mavlink_message_t* msg, uint16_t *thrust) { - return _MAV_RETURN_uint16_t_array(msg, thrust, 6, 36); + return _MAV_RETURN_uint16_t_array(msg, thrust, 4, 24); } /** @@ -229,8 +243,9 @@ static inline void mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_decode(const mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_pitch(msg, set_quad_swarm_roll_pitch_yaw_thrust->pitch); mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_yaw(msg, set_quad_swarm_roll_pitch_yaw_thrust->yaw); mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_thrust(msg, set_quad_swarm_roll_pitch_yaw_thrust->thrust); - mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_target_systems(msg, set_quad_swarm_roll_pitch_yaw_thrust->target_systems); + set_quad_swarm_roll_pitch_yaw_thrust->group = mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_group(msg); + set_quad_swarm_roll_pitch_yaw_thrust->mode = mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_get_mode(msg); #else - memcpy(set_quad_swarm_roll_pitch_yaw_thrust, _MAV_PAYLOAD(msg), 54); + memcpy(set_quad_swarm_roll_pitch_yaw_thrust, _MAV_PAYLOAD(msg), 34); #endif } diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_vicon_position_estimate.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_vicon_position_estimate.h index ecb565684d..93ad097f91 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_vicon_position_estimate.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_vicon_position_estimate.h @@ -4,7 +4,7 @@ typedef struct __mavlink_vicon_position_estimate_t { - uint64_t usec; ///< Timestamp (milliseconds) + uint64_t usec; ///< Timestamp (microseconds, synced to UNIX time or since system boot) float x; ///< Global X position float y; ///< Global Y position float z; ///< Global Z position @@ -38,7 +38,7 @@ typedef struct __mavlink_vicon_position_estimate_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -84,7 +84,7 @@ static inline uint16_t mavlink_msg_vicon_position_estimate_pack(uint8_t system_i * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -142,7 +142,7 @@ static inline uint16_t mavlink_msg_vicon_position_estimate_encode(uint8_t system * @brief Send a vicon_position_estimate message * @param chan MAVLink channel to send the message * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -187,7 +187,7 @@ static inline void mavlink_msg_vicon_position_estimate_send(mavlink_channel_t ch /** * @brief Get field usec from vicon_position_estimate message * - * @return Timestamp (milliseconds) + * @return Timestamp (microseconds, synced to UNIX time or since system boot) */ static inline uint64_t mavlink_msg_vicon_position_estimate_get_usec(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_position_estimate.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_position_estimate.h index 041caf7a07..ca567c1191 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_position_estimate.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_position_estimate.h @@ -4,7 +4,7 @@ typedef struct __mavlink_vision_position_estimate_t { - uint64_t usec; ///< Timestamp (milliseconds) + uint64_t usec; ///< Timestamp (microseconds, synced to UNIX time or since system boot) float x; ///< Global X position float y; ///< Global Y position float z; ///< Global Z position @@ -38,7 +38,7 @@ typedef struct __mavlink_vision_position_estimate_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -84,7 +84,7 @@ static inline uint16_t mavlink_msg_vision_position_estimate_pack(uint8_t system_ * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -142,7 +142,7 @@ static inline uint16_t mavlink_msg_vision_position_estimate_encode(uint8_t syste * @brief Send a vision_position_estimate message * @param chan MAVLink channel to send the message * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X position * @param y Global Y position * @param z Global Z position @@ -187,7 +187,7 @@ static inline void mavlink_msg_vision_position_estimate_send(mavlink_channel_t c /** * @brief Get field usec from vision_position_estimate message * - * @return Timestamp (milliseconds) + * @return Timestamp (microseconds, synced to UNIX time or since system boot) */ static inline uint64_t mavlink_msg_vision_position_estimate_get_usec(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_speed_estimate.h b/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_speed_estimate.h index 3e30b9247a..10ec1026c7 100644 --- a/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_speed_estimate.h +++ b/mavlink/include/mavlink/v1.0/common/mavlink_msg_vision_speed_estimate.h @@ -4,7 +4,7 @@ typedef struct __mavlink_vision_speed_estimate_t { - uint64_t usec; ///< Timestamp (milliseconds) + uint64_t usec; ///< Timestamp (microseconds, synced to UNIX time or since system boot) float x; ///< Global X speed float y; ///< Global Y speed float z; ///< Global Z speed @@ -32,7 +32,7 @@ typedef struct __mavlink_vision_speed_estimate_t * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X speed * @param y Global Y speed * @param z Global Z speed @@ -69,7 +69,7 @@ static inline uint16_t mavlink_msg_vision_speed_estimate_pack(uint8_t system_id, * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message was sent over * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X speed * @param y Global Y speed * @param z Global Z speed @@ -118,7 +118,7 @@ static inline uint16_t mavlink_msg_vision_speed_estimate_encode(uint8_t system_i * @brief Send a vision_speed_estimate message * @param chan MAVLink channel to send the message * - * @param usec Timestamp (milliseconds) + * @param usec Timestamp (microseconds, synced to UNIX time or since system boot) * @param x Global X speed * @param y Global Y speed * @param z Global Z speed @@ -154,7 +154,7 @@ static inline void mavlink_msg_vision_speed_estimate_send(mavlink_channel_t chan /** * @brief Get field usec from vision_speed_estimate message * - * @return Timestamp (milliseconds) + * @return Timestamp (microseconds, synced to UNIX time or since system boot) */ static inline uint64_t mavlink_msg_vision_speed_estimate_get_usec(const mavlink_message_t* msg) { diff --git a/mavlink/include/mavlink/v1.0/common/testsuite.h b/mavlink/include/mavlink/v1.0/common/testsuite.h index 5459a61a5a..2bcaac77a0 100644 --- a/mavlink/include/mavlink/v1.0/common/testsuite.h +++ b/mavlink/include/mavlink/v1.0/common/testsuite.h @@ -1327,7 +1327,7 @@ static void mavlink_test_servo_output_raw(uint8_t system_id, uint8_t component_i }; mavlink_servo_output_raw_t packet1, packet2; memset(&packet1, 0, sizeof(packet1)); - packet1.time_usec = packet_in.time_usec; + packet1.time_boot_ms = packet_in.time_boot_ms; packet1.servo1_raw = packet_in.servo1_raw; packet1.servo2_raw = packet_in.servo2_raw; packet1.servo3_raw = packet_in.servo3_raw; @@ -1346,12 +1346,12 @@ static void mavlink_test_servo_output_raw(uint8_t system_id, uint8_t component_i MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_servo_output_raw_pack(system_id, component_id, &msg , packet1.time_usec , packet1.port , packet1.servo1_raw , packet1.servo2_raw , packet1.servo3_raw , packet1.servo4_raw , packet1.servo5_raw , packet1.servo6_raw , packet1.servo7_raw , packet1.servo8_raw ); + mavlink_msg_servo_output_raw_pack(system_id, component_id, &msg , packet1.time_boot_ms , packet1.port , packet1.servo1_raw , packet1.servo2_raw , packet1.servo3_raw , packet1.servo4_raw , packet1.servo5_raw , packet1.servo6_raw , packet1.servo7_raw , packet1.servo8_raw ); mavlink_msg_servo_output_raw_decode(&msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_servo_output_raw_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.time_usec , packet1.port , packet1.servo1_raw , packet1.servo2_raw , packet1.servo3_raw , packet1.servo4_raw , packet1.servo5_raw , packet1.servo6_raw , packet1.servo7_raw , packet1.servo8_raw ); + mavlink_msg_servo_output_raw_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.time_boot_ms , packet1.port , packet1.servo1_raw , packet1.servo2_raw , packet1.servo3_raw , packet1.servo4_raw , packet1.servo5_raw , packet1.servo6_raw , packet1.servo7_raw , packet1.servo8_raw ); mavlink_msg_servo_output_raw_decode(&msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); @@ -1364,7 +1364,7 @@ static void mavlink_test_servo_output_raw(uint8_t system_id, uint8_t component_i MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_servo_output_raw_send(MAVLINK_COMM_1 , packet1.time_usec , packet1.port , packet1.servo1_raw , packet1.servo2_raw , packet1.servo3_raw , packet1.servo4_raw , packet1.servo5_raw , packet1.servo6_raw , packet1.servo7_raw , packet1.servo8_raw ); + mavlink_msg_servo_output_raw_send(MAVLINK_COMM_1 , packet1.time_boot_ms , packet1.port , packet1.servo1_raw , packet1.servo2_raw , packet1.servo3_raw , packet1.servo4_raw , packet1.servo5_raw , packet1.servo6_raw , packet1.servo7_raw , packet1.servo8_raw ); mavlink_msg_servo_output_raw_decode(last_msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); } @@ -2583,20 +2583,22 @@ static void mavlink_test_set_quad_swarm_roll_pitch_yaw_thrust(uint8_t system_id, uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; uint16_t i; mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t packet_in = { - { 17235, 17236, 17237, 17238, 17239, 17240 }, - { 17859, 17860, 17861, 17862, 17863, 17864 }, - { 18483, 18484, 18485, 18486, 18487, 18488 }, - { 19107, 19108, 19109, 19110, 19111, 19112 }, - { 149, 150, 151, 152, 153, 154 }, + { 17235, 17236, 17237, 17238 }, + { 17651, 17652, 17653, 17654 }, + { 18067, 18068, 18069, 18070 }, + { 18483, 18484, 18485, 18486 }, + 101, + 168, }; mavlink_set_quad_swarm_roll_pitch_yaw_thrust_t packet1, packet2; memset(&packet1, 0, sizeof(packet1)); + packet1.group = packet_in.group; + packet1.mode = packet_in.mode; - mav_array_memcpy(packet1.roll, packet_in.roll, sizeof(int16_t)*6); - mav_array_memcpy(packet1.pitch, packet_in.pitch, sizeof(int16_t)*6); - mav_array_memcpy(packet1.yaw, packet_in.yaw, sizeof(int16_t)*6); - mav_array_memcpy(packet1.thrust, packet_in.thrust, sizeof(uint16_t)*6); - mav_array_memcpy(packet1.target_systems, packet_in.target_systems, sizeof(uint8_t)*6); + mav_array_memcpy(packet1.roll, packet_in.roll, sizeof(int16_t)*4); + mav_array_memcpy(packet1.pitch, packet_in.pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet1.yaw, packet_in.yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet1.thrust, packet_in.thrust, sizeof(uint16_t)*4); memset(&packet2, 0, sizeof(packet2)); @@ -2605,12 +2607,12 @@ static void mavlink_test_set_quad_swarm_roll_pitch_yaw_thrust(uint8_t system_id, MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack(system_id, component_id, &msg , packet1.target_systems , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); + mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack(system_id, component_id, &msg , packet1.group , packet1.mode , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_decode(&msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.target_systems , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); + mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.group , packet1.mode , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_decode(&msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); @@ -2623,7 +2625,7 @@ static void mavlink_test_set_quad_swarm_roll_pitch_yaw_thrust(uint8_t system_id, MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_send(MAVLINK_COMM_1 , packet1.target_systems , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); + mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_send(MAVLINK_COMM_1 , packet1.group , packet1.mode , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); mavlink_msg_set_quad_swarm_roll_pitch_yaw_thrust_decode(last_msg, &packet2); MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); } @@ -2685,6 +2687,65 @@ static void mavlink_test_nav_controller_output(uint8_t system_id, uint8_t compon MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); } +static void mavlink_test_set_quad_swarm_led_roll_pitch_yaw_thrust(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) +{ + mavlink_message_t msg; + uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; + uint16_t i; + mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t packet_in = { + { 17235, 17236, 17237, 17238 }, + { 17651, 17652, 17653, 17654 }, + { 18067, 18068, 18069, 18070 }, + { 18483, 18484, 18485, 18486 }, + 101, + 168, + { 235, 236, 237, 238 }, + { 247, 248, 249, 250 }, + { 3, 4, 5, 6 }, + }; + mavlink_set_quad_swarm_led_roll_pitch_yaw_thrust_t packet1, packet2; + memset(&packet1, 0, sizeof(packet1)); + packet1.group = packet_in.group; + packet1.mode = packet_in.mode; + + mav_array_memcpy(packet1.roll, packet_in.roll, sizeof(int16_t)*4); + mav_array_memcpy(packet1.pitch, packet_in.pitch, sizeof(int16_t)*4); + mav_array_memcpy(packet1.yaw, packet_in.yaw, sizeof(int16_t)*4); + mav_array_memcpy(packet1.thrust, packet_in.thrust, sizeof(uint16_t)*4); + mav_array_memcpy(packet1.led_red, packet_in.led_red, sizeof(uint8_t)*4); + mav_array_memcpy(packet1.led_blue, packet_in.led_blue, sizeof(uint8_t)*4); + mav_array_memcpy(packet1.led_green, packet_in.led_green, sizeof(uint8_t)*4); + + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_encode(system_id, component_id, &msg, &packet1); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_decode(&msg, &packet2); + MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_pack(system_id, component_id, &msg , packet1.group , packet1.mode , packet1.led_red , packet1.led_blue , packet1.led_green , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_decode(&msg, &packet2); + MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.group , packet1.mode , packet1.led_red , packet1.led_blue , packet1.led_green , packet1.roll , packet1.pitch , packet1.yaw , packet1.thrust ); + mavlink_msg_set_quad_swarm_led_roll_pitch_yaw_thrust_decode(&msg, &packet2); + MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); + + memset(&packet2, 0, sizeof(packet2)); + mavlink_msg_to_send_buffer(buffer, &msg); + for (i=0; iparse_state = MAVLINK_PARSE_STATE_IDLE; +} + /** * @brief Finalize a MAVLink message with channel assignment * @@ -131,6 +140,24 @@ MAVLINK_HELPER void _mav_finalize_message_chan_send(mavlink_channel_t chan, uint _mavlink_send_uart(chan, (const char *)ck, 2); MAVLINK_END_UART_SEND(chan, MAVLINK_NUM_NON_PAYLOAD_BYTES + (uint16_t)length); } + +/** + * @brief re-send a message over a uart channel + * this is more stack efficient than re-marshalling the message + */ +MAVLINK_HELPER void _mavlink_resend_uart(mavlink_channel_t chan, const mavlink_message_t *msg) +{ + uint8_t ck[2]; + + ck[0] = (uint8_t)(msg->checksum & 0xFF); + ck[1] = (uint8_t)(msg->checksum >> 8); + + MAVLINK_START_UART_SEND(chan, MAVLINK_NUM_NON_PAYLOAD_BYTES + msg->len); + _mavlink_send_uart(chan, (const char *)&msg->magic, MAVLINK_NUM_HEADER_BYTES); + _mavlink_send_uart(chan, _MAV_PAYLOAD(msg), msg->len); + _mavlink_send_uart(chan, (const char *)ck, 2); + MAVLINK_END_UART_SEND(chan, MAVLINK_NUM_NON_PAYLOAD_BYTES + msg->len); +} #endif // MAVLINK_USE_CONVENIENCE_FUNCTIONS /** @@ -209,6 +236,19 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa static const uint8_t mavlink_message_crcs[256] = MAVLINK_MESSAGE_CRCS; #define MAVLINK_MESSAGE_CRC(msgid) mavlink_message_crcs[msgid] #endif +#endif + +/* Enable this option to check the length of each message. + This allows invalid messages to be caught much sooner. Use if the transmission + medium is prone to missing (or extra) characters (e.g. a radio that fades in + and out). Only use if the channel will only contain messages types listed in + the headers. +*/ +#if MAVLINK_CHECK_MESSAGE_LENGTH +#ifndef MAVLINK_MESSAGE_LENGTH + static const uint8_t mavlink_message_lengths[256] = MAVLINK_MESSAGE_LENGTHS; +#define MAVLINK_MESSAGE_LENGTH(msgid) mavlink_message_lengths[msgid] +#endif #endif mavlink_message_t* rxmsg = mavlink_get_channel_buffer(chan); ///< The currently decoded message @@ -273,6 +313,19 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa break; case MAVLINK_PARSE_STATE_GOT_COMPID: +#if MAVLINK_CHECK_MESSAGE_LENGTH + if (rxmsg->len != MAVLINK_MESSAGE_LENGTH(c)) + { + status->parse_error++; + status->parse_state = MAVLINK_PARSE_STATE_IDLE; + break; + if (c == MAVLINK_STX) + { + status->parse_state = MAVLINK_PARSE_STATE_GOT_STX; + mavlink_start_checksum(rxmsg); + } + } +#endif rxmsg->msgid = c; mavlink_update_checksum(rxmsg, c); if (rxmsg->len == 0) diff --git a/mavlink/include/mavlink/v1.0/minimal/mavlink.h b/mavlink/include/mavlink/v1.0/minimal/mavlink.h deleted file mode 100644 index 0a759b6185..0000000000 --- a/mavlink/include/mavlink/v1.0/minimal/mavlink.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - * @brief MAVLink comm protocol built from minimal.xml - * @see http://pixhawk.ethz.ch/software/mavlink - */ -#ifndef MAVLINK_H -#define MAVLINK_H - -#ifndef MAVLINK_STX -#define MAVLINK_STX 254 -#endif - -#ifndef MAVLINK_ENDIAN -#define MAVLINK_ENDIAN MAVLINK_LITTLE_ENDIAN -#endif - -#ifndef MAVLINK_ALIGNED_FIELDS -#define MAVLINK_ALIGNED_FIELDS 1 -#endif - -#ifndef MAVLINK_CRC_EXTRA -#define MAVLINK_CRC_EXTRA 1 -#endif - -#include "version.h" -#include "minimal.h" - -#endif // MAVLINK_H diff --git a/mavlink/include/mavlink/v1.0/minimal/mavlink_msg_heartbeat.h b/mavlink/include/mavlink/v1.0/minimal/mavlink_msg_heartbeat.h deleted file mode 100644 index 3503387070..0000000000 --- a/mavlink/include/mavlink/v1.0/minimal/mavlink_msg_heartbeat.h +++ /dev/null @@ -1,251 +0,0 @@ -// MESSAGE HEARTBEAT PACKING - -#define MAVLINK_MSG_ID_HEARTBEAT 0 - -typedef struct __mavlink_heartbeat_t -{ - uint32_t custom_mode; ///< A bitfield for use for autopilot-specific flags. - uint8_t type; ///< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - uint8_t autopilot; ///< Autopilot type / class. defined in MAV_AUTOPILOT ENUM - uint8_t base_mode; ///< System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h - uint8_t system_status; ///< System status flag, see MAV_STATE ENUM - uint8_t mavlink_version; ///< MAVLink version -} mavlink_heartbeat_t; - -#define MAVLINK_MSG_ID_HEARTBEAT_LEN 9 -#define MAVLINK_MSG_ID_0_LEN 9 - - - -#define MAVLINK_MESSAGE_INFO_HEARTBEAT { \ - "HEARTBEAT", \ - 6, \ - { { "custom_mode", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_heartbeat_t, custom_mode) }, \ - { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_heartbeat_t, type) }, \ - { "autopilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_heartbeat_t, autopilot) }, \ - { "base_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_heartbeat_t, base_mode) }, \ - { "system_status", NULL, MAVLINK_TYPE_UINT8_T, 0, 7, offsetof(mavlink_heartbeat_t, system_status) }, \ - { "mavlink_version", NULL, MAVLINK_TYPE_UINT8_T, 0, 8, offsetof(mavlink_heartbeat_t, mavlink_version) }, \ - } \ -} - - -/** - * @brief Pack a heartbeat message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Autopilot type / class. defined in MAV_AUTOPILOT ENUM - * @param base_mode System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h - * @param custom_mode A bitfield for use for autopilot-specific flags. - * @param system_status System status flag, see MAV_STATE ENUM - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_heartbeat_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[9]; - _mav_put_uint32_t(buf, 0, custom_mode); - _mav_put_uint8_t(buf, 4, type); - _mav_put_uint8_t(buf, 5, autopilot); - _mav_put_uint8_t(buf, 6, base_mode); - _mav_put_uint8_t(buf, 7, system_status); - _mav_put_uint8_t(buf, 8, 2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 9); -#else - mavlink_heartbeat_t packet; - packet.custom_mode = custom_mode; - packet.type = type; - packet.autopilot = autopilot; - packet.base_mode = base_mode; - packet.system_status = system_status; - packet.mavlink_version = 2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9); -#endif - - msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; - return mavlink_finalize_message(msg, system_id, component_id, 9, 50); -} - -/** - * @brief Pack a heartbeat message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Autopilot type / class. defined in MAV_AUTOPILOT ENUM - * @param base_mode System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h - * @param custom_mode A bitfield for use for autopilot-specific flags. - * @param system_status System status flag, see MAV_STATE ENUM - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t type,uint8_t autopilot,uint8_t base_mode,uint32_t custom_mode,uint8_t system_status) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[9]; - _mav_put_uint32_t(buf, 0, custom_mode); - _mav_put_uint8_t(buf, 4, type); - _mav_put_uint8_t(buf, 5, autopilot); - _mav_put_uint8_t(buf, 6, base_mode); - _mav_put_uint8_t(buf, 7, system_status); - _mav_put_uint8_t(buf, 8, 2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 9); -#else - mavlink_heartbeat_t packet; - packet.custom_mode = custom_mode; - packet.type = type; - packet.autopilot = autopilot; - packet.base_mode = base_mode; - packet.system_status = system_status; - packet.mavlink_version = 2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 9); -#endif - - msg->msgid = MAVLINK_MSG_ID_HEARTBEAT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 9, 50); -} - -/** - * @brief Encode a heartbeat struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param heartbeat C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_heartbeat_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_heartbeat_t* heartbeat) -{ - return mavlink_msg_heartbeat_pack(system_id, component_id, msg, heartbeat->type, heartbeat->autopilot, heartbeat->base_mode, heartbeat->custom_mode, heartbeat->system_status); -} - -/** - * @brief Send a heartbeat message - * @param chan MAVLink channel to send the message - * - * @param type Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - * @param autopilot Autopilot type / class. defined in MAV_AUTOPILOT ENUM - * @param base_mode System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h - * @param custom_mode A bitfield for use for autopilot-specific flags. - * @param system_status System status flag, see MAV_STATE ENUM - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_heartbeat_send(mavlink_channel_t chan, uint8_t type, uint8_t autopilot, uint8_t base_mode, uint32_t custom_mode, uint8_t system_status) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[9]; - _mav_put_uint32_t(buf, 0, custom_mode); - _mav_put_uint8_t(buf, 4, type); - _mav_put_uint8_t(buf, 5, autopilot); - _mav_put_uint8_t(buf, 6, base_mode); - _mav_put_uint8_t(buf, 7, system_status); - _mav_put_uint8_t(buf, 8, 2); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, buf, 9, 50); -#else - mavlink_heartbeat_t packet; - packet.custom_mode = custom_mode; - packet.type = type; - packet.autopilot = autopilot; - packet.base_mode = base_mode; - packet.system_status = system_status; - packet.mavlink_version = 2; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_HEARTBEAT, (const char *)&packet, 9, 50); -#endif -} - -#endif - -// MESSAGE HEARTBEAT UNPACKING - - -/** - * @brief Get field type from heartbeat message - * - * @return Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) - */ -static inline uint8_t mavlink_msg_heartbeat_get_type(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field autopilot from heartbeat message - * - * @return Autopilot type / class. defined in MAV_AUTOPILOT ENUM - */ -static inline uint8_t mavlink_msg_heartbeat_get_autopilot(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field base_mode from heartbeat message - * - * @return System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h - */ -static inline uint8_t mavlink_msg_heartbeat_get_base_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Get field custom_mode from heartbeat message - * - * @return A bitfield for use for autopilot-specific flags. - */ -static inline uint32_t mavlink_msg_heartbeat_get_custom_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 0); -} - -/** - * @brief Get field system_status from heartbeat message - * - * @return System status flag, see MAV_STATE ENUM - */ -static inline uint8_t mavlink_msg_heartbeat_get_system_status(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 7); -} - -/** - * @brief Get field mavlink_version from heartbeat message - * - * @return MAVLink version - */ -static inline uint8_t mavlink_msg_heartbeat_get_mavlink_version(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 8); -} - -/** - * @brief Decode a heartbeat message into a struct - * - * @param msg The message to decode - * @param heartbeat C-struct to decode the message contents into - */ -static inline void mavlink_msg_heartbeat_decode(const mavlink_message_t* msg, mavlink_heartbeat_t* heartbeat) -{ -#if MAVLINK_NEED_BYTE_SWAP - heartbeat->custom_mode = mavlink_msg_heartbeat_get_custom_mode(msg); - heartbeat->type = mavlink_msg_heartbeat_get_type(msg); - heartbeat->autopilot = mavlink_msg_heartbeat_get_autopilot(msg); - heartbeat->base_mode = mavlink_msg_heartbeat_get_base_mode(msg); - heartbeat->system_status = mavlink_msg_heartbeat_get_system_status(msg); - heartbeat->mavlink_version = mavlink_msg_heartbeat_get_mavlink_version(msg); -#else - memcpy(heartbeat, _MAV_PAYLOAD(msg), 9); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/minimal/minimal.h b/mavlink/include/mavlink/v1.0/minimal/minimal.h deleted file mode 100644 index 30c6c1cdc6..0000000000 --- a/mavlink/include/mavlink/v1.0/minimal/minimal.h +++ /dev/null @@ -1,150 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from minimal.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef MINIMAL_H -#define MINIMAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_MINIMAL - - - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - -/** @brief Micro air vehicle / autopilot classes. This identifies the individual model. */ -#ifndef HAVE_ENUM_MAV_AUTOPILOT -#define HAVE_ENUM_MAV_AUTOPILOT -enum MAV_AUTOPILOT -{ - MAV_AUTOPILOT_GENERIC=0, /* Generic autopilot, full support for everything | */ - MAV_AUTOPILOT_PIXHAWK=1, /* PIXHAWK autopilot, http://pixhawk.ethz.ch | */ - MAV_AUTOPILOT_SLUGS=2, /* SLUGS autopilot, http://slugsuav.soe.ucsc.edu | */ - MAV_AUTOPILOT_ARDUPILOTMEGA=3, /* ArduPilotMega / ArduCopter, http://diydrones.com | */ - MAV_AUTOPILOT_OPENPILOT=4, /* OpenPilot, http://openpilot.org | */ - MAV_AUTOPILOT_GENERIC_WAYPOINTS_ONLY=5, /* Generic autopilot only supporting simple waypoints | */ - MAV_AUTOPILOT_GENERIC_WAYPOINTS_AND_SIMPLE_NAVIGATION_ONLY=6, /* Generic autopilot supporting waypoints and other simple navigation commands | */ - MAV_AUTOPILOT_GENERIC_MISSION_FULL=7, /* Generic autopilot supporting the full mission command set | */ - MAV_AUTOPILOT_INVALID=8, /* No valid autopilot, e.g. a GCS or other MAVLink component | */ - MAV_AUTOPILOT_PPZ=9, /* PPZ UAV - http://nongnu.org/paparazzi | */ - MAV_AUTOPILOT_UDB=10, /* UAV Dev Board | */ - MAV_AUTOPILOT_FP=11, /* FlexiPilot | */ - MAV_AUTOPILOT_ENUM_END=12, /* | */ -}; -#endif - -/** @brief */ -#ifndef HAVE_ENUM_MAV_TYPE -#define HAVE_ENUM_MAV_TYPE -enum MAV_TYPE -{ - MAV_TYPE_GENERIC=0, /* Generic micro air vehicle. | */ - MAV_TYPE_FIXED_WING=1, /* Fixed wing aircraft. | */ - MAV_TYPE_QUADROTOR=2, /* Quadrotor | */ - MAV_TYPE_COAXIAL=3, /* Coaxial helicopter | */ - MAV_TYPE_HELICOPTER=4, /* Normal helicopter with tail rotor. | */ - MAV_TYPE_ANTENNA_TRACKER=5, /* Ground installation | */ - MAV_TYPE_GCS=6, /* Operator control unit / ground control station | */ - MAV_TYPE_AIRSHIP=7, /* Airship, controlled | */ - MAV_TYPE_FREE_BALLOON=8, /* Free balloon, uncontrolled | */ - MAV_TYPE_ROCKET=9, /* Rocket | */ - MAV_TYPE_GROUND_ROVER=10, /* Ground rover | */ - MAV_TYPE_SURFACE_BOAT=11, /* Surface vessel, boat, ship | */ - MAV_TYPE_SUBMARINE=12, /* Submarine | */ - MAV_TYPE_HEXAROTOR=13, /* Hexarotor | */ - MAV_TYPE_OCTOROTOR=14, /* Octorotor | */ - MAV_TYPE_TRICOPTER=15, /* Octorotor | */ - MAV_TYPE_FLAPPING_WING=16, /* Flapping wing | */ - MAV_TYPE_ENUM_END=17, /* | */ -}; -#endif - -/** @brief These flags encode the MAV mode. */ -#ifndef HAVE_ENUM_MAV_MODE_FLAG -#define HAVE_ENUM_MAV_MODE_FLAG -enum MAV_MODE_FLAG -{ - MAV_MODE_FLAG_CUSTOM_MODE_ENABLED=1, /* 0b00000001 Reserved for future use. | */ - MAV_MODE_FLAG_TEST_ENABLED=2, /* 0b00000010 system has a test mode enabled. This flag is intended for temporary system tests and should not be used for stable implementations. | */ - MAV_MODE_FLAG_AUTO_ENABLED=4, /* 0b00000100 autonomous mode enabled, system finds its own goal positions. Guided flag can be set or not, depends on the actual implementation. | */ - MAV_MODE_FLAG_GUIDED_ENABLED=8, /* 0b00001000 guided mode enabled, system flies MISSIONs / mission items. | */ - MAV_MODE_FLAG_STABILIZE_ENABLED=16, /* 0b00010000 system stabilizes electronically its attitude (and optionally position). It needs however further control inputs to move around. | */ - MAV_MODE_FLAG_HIL_ENABLED=32, /* 0b00100000 hardware in the loop simulation. All motors / actuators are blocked, but internal software is full operational. | */ - MAV_MODE_FLAG_MANUAL_INPUT_ENABLED=64, /* 0b01000000 remote control input is enabled. | */ - MAV_MODE_FLAG_SAFETY_ARMED=128, /* 0b10000000 MAV safety set to armed. Motors are enabled / running / can start. Ready to fly. | */ - MAV_MODE_FLAG_ENUM_END=129, /* | */ -}; -#endif - -/** @brief These values encode the bit positions of the decode position. These values can be used to read the value of a flag bit by combining the base_mode variable with AND with the flag position value. The result will be either 0 or 1, depending on if the flag is set or not. */ -#ifndef HAVE_ENUM_MAV_MODE_FLAG_DECODE_POSITION -#define HAVE_ENUM_MAV_MODE_FLAG_DECODE_POSITION -enum MAV_MODE_FLAG_DECODE_POSITION -{ - MAV_MODE_FLAG_DECODE_POSITION_CUSTOM_MODE=1, /* Eighth bit: 00000001 | */ - MAV_MODE_FLAG_DECODE_POSITION_TEST=2, /* Seventh bit: 00000010 | */ - MAV_MODE_FLAG_DECODE_POSITION_AUTO=4, /* Sixt bit: 00000100 | */ - MAV_MODE_FLAG_DECODE_POSITION_GUIDED=8, /* Fifth bit: 00001000 | */ - MAV_MODE_FLAG_DECODE_POSITION_STABILIZE=16, /* Fourth bit: 00010000 | */ - MAV_MODE_FLAG_DECODE_POSITION_HIL=32, /* Third bit: 00100000 | */ - MAV_MODE_FLAG_DECODE_POSITION_MANUAL=64, /* Second bit: 01000000 | */ - MAV_MODE_FLAG_DECODE_POSITION_SAFETY=128, /* First bit: 10000000 | */ - MAV_MODE_FLAG_DECODE_POSITION_ENUM_END=129, /* | */ -}; -#endif - -/** @brief */ -#ifndef HAVE_ENUM_MAV_STATE -#define HAVE_ENUM_MAV_STATE -enum MAV_STATE -{ - MAV_STATE_UNINIT=0, /* Uninitialized system, state is unknown. | */ - MAV_STATE_BOOT=1, /* System is booting up. | */ - MAV_STATE_CALIBRATING=2, /* System is calibrating and not flight-ready. | */ - MAV_STATE_STANDBY=3, /* System is grounded and on standby. It can be launched any time. | */ - MAV_STATE_ACTIVE=4, /* System is active and might be already airborne. Motors are engaged. | */ - MAV_STATE_CRITICAL=5, /* System is in a non-normal flight mode. It can however still navigate. | */ - MAV_STATE_EMERGENCY=6, /* System is in a non-normal flight mode. It lost control over parts or over the whole airframe. It is in mayday and going down. | */ - MAV_STATE_POWEROFF=7, /* System just initialized its power-down sequence, will shut down now. | */ - MAV_STATE_ENUM_END=8, /* | */ -}; -#endif - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_heartbeat.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // MINIMAL_H diff --git a/mavlink/include/mavlink/v1.0/minimal/testsuite.h b/mavlink/include/mavlink/v1.0/minimal/testsuite.h deleted file mode 100644 index 1758c912cf..0000000000 --- a/mavlink/include/mavlink/v1.0/minimal/testsuite.h +++ /dev/null @@ -1,88 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from minimal.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef MINIMAL_TESTSUITE_H -#define MINIMAL_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL - -static void mavlink_test_minimal(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - - mavlink_test_minimal(system_id, component_id, last_msg); -} -#endif - - - - -static void mavlink_test_heartbeat(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_heartbeat_t packet_in = { - 963497464, - 17, - 84, - 151, - 218, - 2, - }; - mavlink_heartbeat_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.custom_mode = packet_in.custom_mode; - packet1.type = packet_in.type; - packet1.autopilot = packet_in.autopilot; - packet1.base_mode = packet_in.base_mode; - packet1.system_status = packet_in.system_status; - packet1.mavlink_version = packet_in.mavlink_version; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_pack(system_id, component_id, &msg , packet1.type , packet1.autopilot , packet1.base_mode , packet1.custom_mode , packet1.system_status ); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_heartbeat_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.type , packet1.autopilot , packet1.base_mode , packet1.custom_mode , packet1.system_status ); - mavlink_msg_heartbeat_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; i0: single images every n seconds (decimal)| Recording: 0: disabled, 1: enabled compressed, 2: enabled raw| Empty| Empty| Empty| */ MAV_CMD_DO_LAST=240, /* NOP - This command is only used to mark the upper limit of the DO commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| */ - MAV_CMD_PREFLIGHT_CALIBRATION=241, /* Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Empty| Empty| Empty| */ + MAV_CMD_PREFLIGHT_CALIBRATION=241, /* Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Accelerometer calibration: 0: no, 1: yes| Empty| Empty| */ MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS=242, /* Set sensor offsets. This command will be only accepted if in pre-flight mode. |Sensor to adjust the offsets for: 0: gyros, 1: accelerometer, 2: magnetometer, 3: barometer, 4: optical flow| X axis offset (or generic dimension 1), in the sensor's raw units| Y axis offset (or generic dimension 2), in the sensor's raw units| Z axis offset (or generic dimension 3), in the sensor's raw units| Generic dimension 4, in the sensor's raw units| Generic dimension 5, in the sensor's raw units| Generic dimension 6, in the sensor's raw units| */ MAV_CMD_PREFLIGHT_STORAGE=245, /* Request storage of different parameter values and logs. This command will be only accepted if in pre-flight mode. |Parameter storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Mission storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Reserved| Reserved| Empty| Empty| Empty| */ MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN=246, /* Request the reboot or shutdown of system components. |0: Do nothing for autopilot, 1: Reboot autopilot, 2: Shutdown autopilot.| 0: Do nothing for onboard computer, 1: Reboot onboard computer, 2: Shutdown onboard computer.| Reserved| Reserved| Empty| Empty| Empty| */ @@ -100,6 +87,19 @@ enum MAV_CMD }; #endif +#include "../common/common.h" + +// MAVLINK VERSION + +#ifndef MAVLINK_VERSION +#define MAVLINK_VERSION 2 +#endif + +#if (MAVLINK_VERSION == 0) +#undef MAVLINK_VERSION +#define MAVLINK_VERSION 2 +#endif + // MESSAGE DEFINITIONS #include "./mavlink_msg_set_cam_shutter.h" #include "./mavlink_msg_image_triggered.h" diff --git a/mavlink/include/mavlink/v1.0/pixhawk/version.h b/mavlink/include/mavlink/v1.0/pixhawk/version.h index d571d19910..c5fa7d9649 100644 --- a/mavlink/include/mavlink/v1.0/pixhawk/version.h +++ b/mavlink/include/mavlink/v1.0/pixhawk/version.h @@ -5,7 +5,7 @@ #ifndef MAVLINK_VERSION_H #define MAVLINK_VERSION_H -#define MAVLINK_BUILD_DATE "Sat Apr 28 19:24:08 2012" +#define MAVLINK_BUILD_DATE "Fri Sep 14 10:41:07 2012" #define MAVLINK_WIRE_PROTOCOL_VERSION "1.0" #define MAVLINK_MAX_DIALECT_PAYLOAD_SIZE 255 diff --git a/mavlink/include/mavlink/v1.0/protocol.h b/mavlink/include/mavlink/v1.0/protocol.h index 7b3e3c0bd2..019ae5fc45 100644 --- a/mavlink/include/mavlink/v1.0/protocol.h +++ b/mavlink/include/mavlink/v1.0/protocol.h @@ -43,6 +43,7 @@ /* always include the prototypes to ensure we don't get out of sync */ MAVLINK_HELPER mavlink_status_t* mavlink_get_channel_status(uint8_t chan); +MAVLINK_HELPER void mavlink_reset_channel_status(uint8_t chan); #if MAVLINK_CRC_EXTRA MAVLINK_HELPER uint16_t mavlink_finalize_message_chan(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, uint8_t chan, uint8_t length, uint8_t crc_extra); @@ -67,6 +68,7 @@ MAVLINK_HELPER uint8_t put_bitfield_n_by_index(int32_t b, uint8_t bits, uint8_t uint8_t* r_bit_index, uint8_t* buffer); #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS MAVLINK_HELPER void _mavlink_send_uart(mavlink_channel_t chan, const char *buf, uint16_t len); +MAVLINK_HELPER void _mavlink_resend_uart(mavlink_channel_t chan, const mavlink_message_t *msg); #endif /** diff --git a/mavlink/include/mavlink/v1.0/sensesoar/sensesoar.h b/mavlink/include/mavlink/v1.0/sensesoar/sensesoar.h index 5a6022d59f..906cd01876 100644 --- a/mavlink/include/mavlink/v1.0/sensesoar/sensesoar.h +++ b/mavlink/include/mavlink/v1.0/sensesoar/sensesoar.h @@ -12,34 +12,21 @@ extern "C" { // MESSAGE LENGTHS AND CRCS #ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {9, 31, 12, 0, 14, 28, 3, 32, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 25, 23, 30, 101, 22, 26, 16, 14, 28, 32, 28, 28, 22, 22, 21, 6, 6, 37, 4, 4, 2, 2, 4, 2, 2, 3, 13, 12, 19, 17, 15, 15, 27, 25, 18, 18, 20, 20, 9, 54, 26, 0, 36, 0, 6, 4, 0, 21, 18, 0, 0, 0, 20, 0, 33, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 56, 42, 33, 0, 0, 0, 0, 0, 0, 0, 26, 32, 32, 20, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 12, 0, 32, 0, 12, 0, 12, 0, 24, 0, 4, 4, 12, 0, 12, 0, 20, 0, 4, 0, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 30, 18, 18, 51, 9, 0} +#define MAVLINK_MESSAGE_LENGTHS {9, 31, 12, 0, 14, 28, 3, 32, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 25, 23, 30, 101, 22, 26, 16, 14, 28, 32, 28, 28, 22, 22, 21, 6, 6, 37, 4, 4, 2, 2, 4, 2, 2, 3, 13, 12, 19, 17, 15, 15, 27, 25, 18, 18, 20, 20, 9, 34, 26, 46, 36, 0, 6, 4, 0, 11, 18, 0, 0, 0, 20, 0, 33, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 56, 42, 33, 0, 0, 0, 0, 0, 0, 0, 26, 32, 32, 20, 32, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 12, 0, 32, 0, 12, 0, 12, 0, 24, 0, 4, 4, 12, 0, 12, 0, 20, 0, 4, 0, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 30, 18, 18, 51, 9, 0} #endif #ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 214, 223, 141, 33, 15, 3, 100, 24, 239, 238, 30, 200, 183, 0, 130, 0, 148, 21, 0, 52, 124, 0, 0, 0, 20, 0, 152, 143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 108, 0, 146, 0, 16, 0, 32, 0, 159, 0, 24, 248, 79, 0, 5, 0, 170, 0, 157, 0, 209, 0, 243, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 49, 170, 44, 83, 46, 0} +#define MAVLINK_MESSAGE_CRCS {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 242, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 214, 223, 141, 33, 15, 3, 100, 24, 239, 238, 30, 240, 183, 130, 130, 0, 148, 21, 0, 243, 124, 0, 0, 0, 20, 0, 152, 143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 108, 0, 146, 0, 16, 0, 32, 0, 159, 0, 24, 248, 79, 0, 5, 0, 170, 0, 157, 0, 209, 0, 243, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 49, 170, 44, 83, 46, 0} #endif #ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SET_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_ATTITUDE_QUATERNION, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_NED, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_MISSION_REQUEST_PARTIAL_LIST, MAVLINK_MESSAGE_INFO_MISSION_WRITE_PARTIAL_LIST, MAVLINK_MESSAGE_INFO_MISSION_ITEM, MAVLINK_MESSAGE_INFO_MISSION_REQUEST, MAVLINK_MESSAGE_INFO_MISSION_SET_CURRENT, MAVLINK_MESSAGE_INFO_MISSION_CURRENT, MAVLINK_MESSAGE_INFO_MISSION_REQUEST_LIST, MAVLINK_MESSAGE_INFO_MISSION_COUNT, MAVLINK_MESSAGE_INFO_MISSION_CLEAR_ALL, MAVLINK_MESSAGE_INFO_MISSION_ITEM_REACHED, MAVLINK_MESSAGE_INFO_MISSION_ACK, MAVLINK_MESSAGE_INFO_SET_GPS_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_SET_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_SETPOINT_INT, MAVLINK_MESSAGE_INFO_SET_GLOBAL_POSITION_SETPOINT_INT, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_SET_QUAD_MOTORS_SETPOINT, MAVLINK_MESSAGE_INFO_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_DATA_STREAM, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_VFR_HUD, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_COMMAND_LONG, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_NED_SYSTEM_GLOBAL_OFFSET, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_HIL_RC_INPUTS_RAW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, MAVLINK_MESSAGE_INFO_GLOBAL_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_SPEED_ESTIMATE, MAVLINK_MESSAGE_INFO_VICON_POSITION_ESTIMATE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_POSITION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_VELOCITY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_ATTITUDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_WIND, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_AIR_VELOCITY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_BIAS, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_QFF, MAVLINK_MESSAGE_INFO_OBS_AIR_TEMP, MAVLINK_MESSAGE_INFO_FILT_ROT_VEL, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_LLC_OUT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PM_ELEC, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SYS_Stat, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_CMD_AIRSPEED_CHNG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_CMD_AIRSPEED_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_MEMORY_VECT, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} +#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SET_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_ATTITUDE_QUATERNION, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_NED, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_MISSION_REQUEST_PARTIAL_LIST, MAVLINK_MESSAGE_INFO_MISSION_WRITE_PARTIAL_LIST, MAVLINK_MESSAGE_INFO_MISSION_ITEM, MAVLINK_MESSAGE_INFO_MISSION_REQUEST, MAVLINK_MESSAGE_INFO_MISSION_SET_CURRENT, MAVLINK_MESSAGE_INFO_MISSION_CURRENT, MAVLINK_MESSAGE_INFO_MISSION_REQUEST_LIST, MAVLINK_MESSAGE_INFO_MISSION_COUNT, MAVLINK_MESSAGE_INFO_MISSION_CLEAR_ALL, MAVLINK_MESSAGE_INFO_MISSION_ITEM_REACHED, MAVLINK_MESSAGE_INFO_MISSION_ACK, MAVLINK_MESSAGE_INFO_SET_GPS_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_SET_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_SETPOINT_INT, MAVLINK_MESSAGE_INFO_SET_GLOBAL_POSITION_SETPOINT_INT, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_SET_QUAD_MOTORS_SETPOINT, MAVLINK_MESSAGE_INFO_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, MAVLINK_MESSAGE_INFO_SET_QUAD_SWARM_LED_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_DATA_STREAM, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_VFR_HUD, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_COMMAND_LONG, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_NED_SYSTEM_GLOBAL_OFFSET, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_HIL_RC_INPUTS_RAW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, MAVLINK_MESSAGE_INFO_GLOBAL_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_SPEED_ESTIMATE, MAVLINK_MESSAGE_INFO_VICON_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_HIGHRES_IMU, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_POSITION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_VELOCITY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_ATTITUDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_WIND, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_AIR_VELOCITY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_BIAS, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OBS_QFF, MAVLINK_MESSAGE_INFO_OBS_AIR_TEMP, MAVLINK_MESSAGE_INFO_FILT_ROT_VEL, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_LLC_OUT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PM_ELEC, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SYS_Stat, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_CMD_AIRSPEED_CHNG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_CMD_AIRSPEED_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_MEMORY_VECT, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} #endif #include "../protocol.h" #define MAVLINK_ENABLED_SENSESOAR -#include "../common/common.h" - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - // ENUM DEFINITIONS @@ -55,6 +42,19 @@ enum SENSESOAR_MODE }; #endif +#include "../common/common.h" + +// MAVLINK VERSION + +#ifndef MAVLINK_VERSION +#define MAVLINK_VERSION 2 +#endif + +#if (MAVLINK_VERSION == 0) +#undef MAVLINK_VERSION +#define MAVLINK_VERSION 2 +#endif + // MESSAGE DEFINITIONS #include "./mavlink_msg_obs_position.h" #include "./mavlink_msg_obs_velocity.h" diff --git a/mavlink/include/mavlink/v1.0/sensesoar/version.h b/mavlink/include/mavlink/v1.0/sensesoar/version.h index f2a254a516..81879520c4 100644 --- a/mavlink/include/mavlink/v1.0/sensesoar/version.h +++ b/mavlink/include/mavlink/v1.0/sensesoar/version.h @@ -5,7 +5,7 @@ #ifndef MAVLINK_VERSION_H #define MAVLINK_VERSION_H -#define MAVLINK_BUILD_DATE "Fri Apr 20 12:22:51 2012" +#define MAVLINK_BUILD_DATE "Fri Sep 14 10:41:18 2012" #define MAVLINK_WIRE_PROTOCOL_VERSION "1.0" #define MAVLINK_MAX_DIALECT_PAYLOAD_SIZE 101 diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink.h b/mavlink/include/mavlink/v1.0/slugs/mavlink.h deleted file mode 100644 index d28bbc7b96..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - * @brief MAVLink comm protocol built from slugs.xml - * @see http://pixhawk.ethz.ch/software/mavlink - */ -#ifndef MAVLINK_H -#define MAVLINK_H - -#ifndef MAVLINK_STX -#define MAVLINK_STX 254 -#endif - -#ifndef MAVLINK_ENDIAN -#define MAVLINK_ENDIAN MAVLINK_LITTLE_ENDIAN -#endif - -#ifndef MAVLINK_ALIGNED_FIELDS -#define MAVLINK_ALIGNED_FIELDS 1 -#endif - -#ifndef MAVLINK_CRC_EXTRA -#define MAVLINK_CRC_EXTRA 1 -#endif - -#include "version.h" -#include "slugs.h" - -#endif // MAVLINK_H diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_air_data.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_air_data.h deleted file mode 100644 index 4b02f6dcf6..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_air_data.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE AIR_DATA PACKING - -#define MAVLINK_MSG_ID_AIR_DATA 171 - -typedef struct __mavlink_air_data_t -{ - float dynamicPressure; ///< Dynamic pressure (Pa) - float staticPressure; ///< Static pressure (Pa) - uint16_t temperature; ///< Board temperature -} mavlink_air_data_t; - -#define MAVLINK_MSG_ID_AIR_DATA_LEN 10 -#define MAVLINK_MSG_ID_171_LEN 10 - - - -#define MAVLINK_MESSAGE_INFO_AIR_DATA { \ - "AIR_DATA", \ - 3, \ - { { "dynamicPressure", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_air_data_t, dynamicPressure) }, \ - { "staticPressure", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_air_data_t, staticPressure) }, \ - { "temperature", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_air_data_t, temperature) }, \ - } \ -} - - -/** - * @brief Pack a air_data message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param dynamicPressure Dynamic pressure (Pa) - * @param staticPressure Static pressure (Pa) - * @param temperature Board temperature - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_air_data_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float dynamicPressure, float staticPressure, uint16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[10]; - _mav_put_float(buf, 0, dynamicPressure); - _mav_put_float(buf, 4, staticPressure); - _mav_put_uint16_t(buf, 8, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 10); -#else - mavlink_air_data_t packet; - packet.dynamicPressure = dynamicPressure; - packet.staticPressure = staticPressure; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 10); -#endif - - msg->msgid = MAVLINK_MSG_ID_AIR_DATA; - return mavlink_finalize_message(msg, system_id, component_id, 10, 232); -} - -/** - * @brief Pack a air_data message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param dynamicPressure Dynamic pressure (Pa) - * @param staticPressure Static pressure (Pa) - * @param temperature Board temperature - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_air_data_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float dynamicPressure,float staticPressure,uint16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[10]; - _mav_put_float(buf, 0, dynamicPressure); - _mav_put_float(buf, 4, staticPressure); - _mav_put_uint16_t(buf, 8, temperature); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 10); -#else - mavlink_air_data_t packet; - packet.dynamicPressure = dynamicPressure; - packet.staticPressure = staticPressure; - packet.temperature = temperature; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 10); -#endif - - msg->msgid = MAVLINK_MSG_ID_AIR_DATA; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 10, 232); -} - -/** - * @brief Encode a air_data struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param air_data C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_air_data_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_air_data_t* air_data) -{ - return mavlink_msg_air_data_pack(system_id, component_id, msg, air_data->dynamicPressure, air_data->staticPressure, air_data->temperature); -} - -/** - * @brief Send a air_data message - * @param chan MAVLink channel to send the message - * - * @param dynamicPressure Dynamic pressure (Pa) - * @param staticPressure Static pressure (Pa) - * @param temperature Board temperature - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_air_data_send(mavlink_channel_t chan, float dynamicPressure, float staticPressure, uint16_t temperature) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[10]; - _mav_put_float(buf, 0, dynamicPressure); - _mav_put_float(buf, 4, staticPressure); - _mav_put_uint16_t(buf, 8, temperature); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AIR_DATA, buf, 10, 232); -#else - mavlink_air_data_t packet; - packet.dynamicPressure = dynamicPressure; - packet.staticPressure = staticPressure; - packet.temperature = temperature; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_AIR_DATA, (const char *)&packet, 10, 232); -#endif -} - -#endif - -// MESSAGE AIR_DATA UNPACKING - - -/** - * @brief Get field dynamicPressure from air_data message - * - * @return Dynamic pressure (Pa) - */ -static inline float mavlink_msg_air_data_get_dynamicPressure(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field staticPressure from air_data message - * - * @return Static pressure (Pa) - */ -static inline float mavlink_msg_air_data_get_staticPressure(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field temperature from air_data message - * - * @return Board temperature - */ -static inline uint16_t mavlink_msg_air_data_get_temperature(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 8); -} - -/** - * @brief Decode a air_data message into a struct - * - * @param msg The message to decode - * @param air_data C-struct to decode the message contents into - */ -static inline void mavlink_msg_air_data_decode(const mavlink_message_t* msg, mavlink_air_data_t* air_data) -{ -#if MAVLINK_NEED_BYTE_SWAP - air_data->dynamicPressure = mavlink_msg_air_data_get_dynamicPressure(msg); - air_data->staticPressure = mavlink_msg_air_data_get_staticPressure(msg); - air_data->temperature = mavlink_msg_air_data_get_temperature(msg); -#else - memcpy(air_data, _MAV_PAYLOAD(msg), 10); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_cpu_load.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_cpu_load.h deleted file mode 100644 index 5f86c7091e..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_cpu_load.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE CPU_LOAD PACKING - -#define MAVLINK_MSG_ID_CPU_LOAD 170 - -typedef struct __mavlink_cpu_load_t -{ - uint16_t batVolt; ///< Battery Voltage in millivolts - uint8_t sensLoad; ///< Sensor DSC Load - uint8_t ctrlLoad; ///< Control DSC Load -} mavlink_cpu_load_t; - -#define MAVLINK_MSG_ID_CPU_LOAD_LEN 4 -#define MAVLINK_MSG_ID_170_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_CPU_LOAD { \ - "CPU_LOAD", \ - 3, \ - { { "batVolt", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_cpu_load_t, batVolt) }, \ - { "sensLoad", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_cpu_load_t, sensLoad) }, \ - { "ctrlLoad", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_cpu_load_t, ctrlLoad) }, \ - } \ -} - - -/** - * @brief Pack a cpu_load message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param sensLoad Sensor DSC Load - * @param ctrlLoad Control DSC Load - * @param batVolt Battery Voltage in millivolts - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_cpu_load_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t sensLoad, uint8_t ctrlLoad, uint16_t batVolt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, batVolt); - _mav_put_uint8_t(buf, 2, sensLoad); - _mav_put_uint8_t(buf, 3, ctrlLoad); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_cpu_load_t packet; - packet.batVolt = batVolt; - packet.sensLoad = sensLoad; - packet.ctrlLoad = ctrlLoad; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_CPU_LOAD; - return mavlink_finalize_message(msg, system_id, component_id, 4, 75); -} - -/** - * @brief Pack a cpu_load message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param sensLoad Sensor DSC Load - * @param ctrlLoad Control DSC Load - * @param batVolt Battery Voltage in millivolts - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_cpu_load_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t sensLoad,uint8_t ctrlLoad,uint16_t batVolt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, batVolt); - _mav_put_uint8_t(buf, 2, sensLoad); - _mav_put_uint8_t(buf, 3, ctrlLoad); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_cpu_load_t packet; - packet.batVolt = batVolt; - packet.sensLoad = sensLoad; - packet.ctrlLoad = ctrlLoad; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_CPU_LOAD; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4, 75); -} - -/** - * @brief Encode a cpu_load struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param cpu_load C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_cpu_load_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_cpu_load_t* cpu_load) -{ - return mavlink_msg_cpu_load_pack(system_id, component_id, msg, cpu_load->sensLoad, cpu_load->ctrlLoad, cpu_load->batVolt); -} - -/** - * @brief Send a cpu_load message - * @param chan MAVLink channel to send the message - * - * @param sensLoad Sensor DSC Load - * @param ctrlLoad Control DSC Load - * @param batVolt Battery Voltage in millivolts - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_cpu_load_send(mavlink_channel_t chan, uint8_t sensLoad, uint8_t ctrlLoad, uint16_t batVolt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, batVolt); - _mav_put_uint8_t(buf, 2, sensLoad); - _mav_put_uint8_t(buf, 3, ctrlLoad); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CPU_LOAD, buf, 4, 75); -#else - mavlink_cpu_load_t packet; - packet.batVolt = batVolt; - packet.sensLoad = sensLoad; - packet.ctrlLoad = ctrlLoad; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CPU_LOAD, (const char *)&packet, 4, 75); -#endif -} - -#endif - -// MESSAGE CPU_LOAD UNPACKING - - -/** - * @brief Get field sensLoad from cpu_load message - * - * @return Sensor DSC Load - */ -static inline uint8_t mavlink_msg_cpu_load_get_sensLoad(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field ctrlLoad from cpu_load message - * - * @return Control DSC Load - */ -static inline uint8_t mavlink_msg_cpu_load_get_ctrlLoad(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field batVolt from cpu_load message - * - * @return Battery Voltage in millivolts - */ -static inline uint16_t mavlink_msg_cpu_load_get_batVolt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Decode a cpu_load message into a struct - * - * @param msg The message to decode - * @param cpu_load C-struct to decode the message contents into - */ -static inline void mavlink_msg_cpu_load_decode(const mavlink_message_t* msg, mavlink_cpu_load_t* cpu_load) -{ -#if MAVLINK_NEED_BYTE_SWAP - cpu_load->batVolt = mavlink_msg_cpu_load_get_batVolt(msg); - cpu_load->sensLoad = mavlink_msg_cpu_load_get_sensLoad(msg); - cpu_load->ctrlLoad = mavlink_msg_cpu_load_get_ctrlLoad(msg); -#else - memcpy(cpu_load, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_ctrl_srfc_pt.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_ctrl_srfc_pt.h deleted file mode 100644 index e506ed18fd..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_ctrl_srfc_pt.h +++ /dev/null @@ -1,166 +0,0 @@ -// MESSAGE CTRL_SRFC_PT PACKING - -#define MAVLINK_MSG_ID_CTRL_SRFC_PT 181 - -typedef struct __mavlink_ctrl_srfc_pt_t -{ - uint16_t bitfieldPt; ///< Bitfield containing the PT configuration - uint8_t target; ///< The system setting the commands -} mavlink_ctrl_srfc_pt_t; - -#define MAVLINK_MSG_ID_CTRL_SRFC_PT_LEN 3 -#define MAVLINK_MSG_ID_181_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_CTRL_SRFC_PT { \ - "CTRL_SRFC_PT", \ - 2, \ - { { "bitfieldPt", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_ctrl_srfc_pt_t, bitfieldPt) }, \ - { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_ctrl_srfc_pt_t, target) }, \ - } \ -} - - -/** - * @brief Pack a ctrl_srfc_pt message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the commands - * @param bitfieldPt Bitfield containing the PT configuration - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint16_t bitfieldPt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint16_t(buf, 0, bitfieldPt); - _mav_put_uint8_t(buf, 2, target); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ctrl_srfc_pt_t packet; - packet.bitfieldPt = bitfieldPt; - packet.target = target; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_CTRL_SRFC_PT; - return mavlink_finalize_message(msg, system_id, component_id, 3, 104); -} - -/** - * @brief Pack a ctrl_srfc_pt message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the commands - * @param bitfieldPt Bitfield containing the PT configuration - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint16_t bitfieldPt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint16_t(buf, 0, bitfieldPt); - _mav_put_uint8_t(buf, 2, target); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ctrl_srfc_pt_t packet; - packet.bitfieldPt = bitfieldPt; - packet.target = target; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_CTRL_SRFC_PT; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3, 104); -} - -/** - * @brief Encode a ctrl_srfc_pt struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ctrl_srfc_pt C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ctrl_srfc_pt_t* ctrl_srfc_pt) -{ - return mavlink_msg_ctrl_srfc_pt_pack(system_id, component_id, msg, ctrl_srfc_pt->target, ctrl_srfc_pt->bitfieldPt); -} - -/** - * @brief Send a ctrl_srfc_pt message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the commands - * @param bitfieldPt Bitfield containing the PT configuration - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ctrl_srfc_pt_send(mavlink_channel_t chan, uint8_t target, uint16_t bitfieldPt) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint16_t(buf, 0, bitfieldPt); - _mav_put_uint8_t(buf, 2, target); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CTRL_SRFC_PT, buf, 3, 104); -#else - mavlink_ctrl_srfc_pt_t packet; - packet.bitfieldPt = bitfieldPt; - packet.target = target; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_CTRL_SRFC_PT, (const char *)&packet, 3, 104); -#endif -} - -#endif - -// MESSAGE CTRL_SRFC_PT UNPACKING - - -/** - * @brief Get field target from ctrl_srfc_pt message - * - * @return The system setting the commands - */ -static inline uint8_t mavlink_msg_ctrl_srfc_pt_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field bitfieldPt from ctrl_srfc_pt message - * - * @return Bitfield containing the PT configuration - */ -static inline uint16_t mavlink_msg_ctrl_srfc_pt_get_bitfieldPt(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Decode a ctrl_srfc_pt message into a struct - * - * @param msg The message to decode - * @param ctrl_srfc_pt C-struct to decode the message contents into - */ -static inline void mavlink_msg_ctrl_srfc_pt_decode(const mavlink_message_t* msg, mavlink_ctrl_srfc_pt_t* ctrl_srfc_pt) -{ -#if MAVLINK_NEED_BYTE_SWAP - ctrl_srfc_pt->bitfieldPt = mavlink_msg_ctrl_srfc_pt_get_bitfieldPt(msg); - ctrl_srfc_pt->target = mavlink_msg_ctrl_srfc_pt_get_target(msg); -#else - memcpy(ctrl_srfc_pt, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_data_log.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_data_log.h deleted file mode 100644 index 49e340704d..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_data_log.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE DATA_LOG PACKING - -#define MAVLINK_MSG_ID_DATA_LOG 177 - -typedef struct __mavlink_data_log_t -{ - float fl_1; ///< Log value 1 - float fl_2; ///< Log value 2 - float fl_3; ///< Log value 3 - float fl_4; ///< Log value 4 - float fl_5; ///< Log value 5 - float fl_6; ///< Log value 6 -} mavlink_data_log_t; - -#define MAVLINK_MSG_ID_DATA_LOG_LEN 24 -#define MAVLINK_MSG_ID_177_LEN 24 - - - -#define MAVLINK_MESSAGE_INFO_DATA_LOG { \ - "DATA_LOG", \ - 6, \ - { { "fl_1", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_data_log_t, fl_1) }, \ - { "fl_2", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_data_log_t, fl_2) }, \ - { "fl_3", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_data_log_t, fl_3) }, \ - { "fl_4", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_data_log_t, fl_4) }, \ - { "fl_5", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_data_log_t, fl_5) }, \ - { "fl_6", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_data_log_t, fl_6) }, \ - } \ -} - - -/** - * @brief Pack a data_log message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param fl_1 Log value 1 - * @param fl_2 Log value 2 - * @param fl_3 Log value 3 - * @param fl_4 Log value 4 - * @param fl_5 Log value 5 - * @param fl_6 Log value 6 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_data_log_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float fl_1, float fl_2, float fl_3, float fl_4, float fl_5, float fl_6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, fl_1); - _mav_put_float(buf, 4, fl_2); - _mav_put_float(buf, 8, fl_3); - _mav_put_float(buf, 12, fl_4); - _mav_put_float(buf, 16, fl_5); - _mav_put_float(buf, 20, fl_6); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_data_log_t packet; - packet.fl_1 = fl_1; - packet.fl_2 = fl_2; - packet.fl_3 = fl_3; - packet.fl_4 = fl_4; - packet.fl_5 = fl_5; - packet.fl_6 = fl_6; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_DATA_LOG; - return mavlink_finalize_message(msg, system_id, component_id, 24, 167); -} - -/** - * @brief Pack a data_log message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param fl_1 Log value 1 - * @param fl_2 Log value 2 - * @param fl_3 Log value 3 - * @param fl_4 Log value 4 - * @param fl_5 Log value 5 - * @param fl_6 Log value 6 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_data_log_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float fl_1,float fl_2,float fl_3,float fl_4,float fl_5,float fl_6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, fl_1); - _mav_put_float(buf, 4, fl_2); - _mav_put_float(buf, 8, fl_3); - _mav_put_float(buf, 12, fl_4); - _mav_put_float(buf, 16, fl_5); - _mav_put_float(buf, 20, fl_6); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_data_log_t packet; - packet.fl_1 = fl_1; - packet.fl_2 = fl_2; - packet.fl_3 = fl_3; - packet.fl_4 = fl_4; - packet.fl_5 = fl_5; - packet.fl_6 = fl_6; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_DATA_LOG; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 24, 167); -} - -/** - * @brief Encode a data_log struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param data_log C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_data_log_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_data_log_t* data_log) -{ - return mavlink_msg_data_log_pack(system_id, component_id, msg, data_log->fl_1, data_log->fl_2, data_log->fl_3, data_log->fl_4, data_log->fl_5, data_log->fl_6); -} - -/** - * @brief Send a data_log message - * @param chan MAVLink channel to send the message - * - * @param fl_1 Log value 1 - * @param fl_2 Log value 2 - * @param fl_3 Log value 3 - * @param fl_4 Log value 4 - * @param fl_5 Log value 5 - * @param fl_6 Log value 6 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_data_log_send(mavlink_channel_t chan, float fl_1, float fl_2, float fl_3, float fl_4, float fl_5, float fl_6) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, fl_1); - _mav_put_float(buf, 4, fl_2); - _mav_put_float(buf, 8, fl_3); - _mav_put_float(buf, 12, fl_4); - _mav_put_float(buf, 16, fl_5); - _mav_put_float(buf, 20, fl_6); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_LOG, buf, 24, 167); -#else - mavlink_data_log_t packet; - packet.fl_1 = fl_1; - packet.fl_2 = fl_2; - packet.fl_3 = fl_3; - packet.fl_4 = fl_4; - packet.fl_5 = fl_5; - packet.fl_6 = fl_6; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DATA_LOG, (const char *)&packet, 24, 167); -#endif -} - -#endif - -// MESSAGE DATA_LOG UNPACKING - - -/** - * @brief Get field fl_1 from data_log message - * - * @return Log value 1 - */ -static inline float mavlink_msg_data_log_get_fl_1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field fl_2 from data_log message - * - * @return Log value 2 - */ -static inline float mavlink_msg_data_log_get_fl_2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field fl_3 from data_log message - * - * @return Log value 3 - */ -static inline float mavlink_msg_data_log_get_fl_3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field fl_4 from data_log message - * - * @return Log value 4 - */ -static inline float mavlink_msg_data_log_get_fl_4(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field fl_5 from data_log message - * - * @return Log value 5 - */ -static inline float mavlink_msg_data_log_get_fl_5(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field fl_6 from data_log message - * - * @return Log value 6 - */ -static inline float mavlink_msg_data_log_get_fl_6(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Decode a data_log message into a struct - * - * @param msg The message to decode - * @param data_log C-struct to decode the message contents into - */ -static inline void mavlink_msg_data_log_decode(const mavlink_message_t* msg, mavlink_data_log_t* data_log) -{ -#if MAVLINK_NEED_BYTE_SWAP - data_log->fl_1 = mavlink_msg_data_log_get_fl_1(msg); - data_log->fl_2 = mavlink_msg_data_log_get_fl_2(msg); - data_log->fl_3 = mavlink_msg_data_log_get_fl_3(msg); - data_log->fl_4 = mavlink_msg_data_log_get_fl_4(msg); - data_log->fl_5 = mavlink_msg_data_log_get_fl_5(msg); - data_log->fl_6 = mavlink_msg_data_log_get_fl_6(msg); -#else - memcpy(data_log, _MAV_PAYLOAD(msg), 24); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_diagnostic.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_diagnostic.h deleted file mode 100644 index ef77e5f085..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_diagnostic.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE DIAGNOSTIC PACKING - -#define MAVLINK_MSG_ID_DIAGNOSTIC 173 - -typedef struct __mavlink_diagnostic_t -{ - float diagFl1; ///< Diagnostic float 1 - float diagFl2; ///< Diagnostic float 2 - float diagFl3; ///< Diagnostic float 3 - int16_t diagSh1; ///< Diagnostic short 1 - int16_t diagSh2; ///< Diagnostic short 2 - int16_t diagSh3; ///< Diagnostic short 3 -} mavlink_diagnostic_t; - -#define MAVLINK_MSG_ID_DIAGNOSTIC_LEN 18 -#define MAVLINK_MSG_ID_173_LEN 18 - - - -#define MAVLINK_MESSAGE_INFO_DIAGNOSTIC { \ - "DIAGNOSTIC", \ - 6, \ - { { "diagFl1", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_diagnostic_t, diagFl1) }, \ - { "diagFl2", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_diagnostic_t, diagFl2) }, \ - { "diagFl3", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_diagnostic_t, diagFl3) }, \ - { "diagSh1", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_diagnostic_t, diagSh1) }, \ - { "diagSh2", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_diagnostic_t, diagSh2) }, \ - { "diagSh3", NULL, MAVLINK_TYPE_INT16_T, 0, 16, offsetof(mavlink_diagnostic_t, diagSh3) }, \ - } \ -} - - -/** - * @brief Pack a diagnostic message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param diagFl1 Diagnostic float 1 - * @param diagFl2 Diagnostic float 2 - * @param diagFl3 Diagnostic float 3 - * @param diagSh1 Diagnostic short 1 - * @param diagSh2 Diagnostic short 2 - * @param diagSh3 Diagnostic short 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_diagnostic_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_float(buf, 0, diagFl1); - _mav_put_float(buf, 4, diagFl2); - _mav_put_float(buf, 8, diagFl3); - _mav_put_int16_t(buf, 12, diagSh1); - _mav_put_int16_t(buf, 14, diagSh2); - _mav_put_int16_t(buf, 16, diagSh3); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_diagnostic_t packet; - packet.diagFl1 = diagFl1; - packet.diagFl2 = diagFl2; - packet.diagFl3 = diagFl3; - packet.diagSh1 = diagSh1; - packet.diagSh2 = diagSh2; - packet.diagSh3 = diagSh3; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIAGNOSTIC; - return mavlink_finalize_message(msg, system_id, component_id, 18, 2); -} - -/** - * @brief Pack a diagnostic message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param diagFl1 Diagnostic float 1 - * @param diagFl2 Diagnostic float 2 - * @param diagFl3 Diagnostic float 3 - * @param diagSh1 Diagnostic short 1 - * @param diagSh2 Diagnostic short 2 - * @param diagSh3 Diagnostic short 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_diagnostic_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float diagFl1,float diagFl2,float diagFl3,int16_t diagSh1,int16_t diagSh2,int16_t diagSh3) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_float(buf, 0, diagFl1); - _mav_put_float(buf, 4, diagFl2); - _mav_put_float(buf, 8, diagFl3); - _mav_put_int16_t(buf, 12, diagSh1); - _mav_put_int16_t(buf, 14, diagSh2); - _mav_put_int16_t(buf, 16, diagSh3); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 18); -#else - mavlink_diagnostic_t packet; - packet.diagFl1 = diagFl1; - packet.diagFl2 = diagFl2; - packet.diagFl3 = diagFl3; - packet.diagSh1 = diagSh1; - packet.diagSh2 = diagSh2; - packet.diagSh3 = diagSh3; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 18); -#endif - - msg->msgid = MAVLINK_MSG_ID_DIAGNOSTIC; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 18, 2); -} - -/** - * @brief Encode a diagnostic struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param diagnostic C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_diagnostic_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_diagnostic_t* diagnostic) -{ - return mavlink_msg_diagnostic_pack(system_id, component_id, msg, diagnostic->diagFl1, diagnostic->diagFl2, diagnostic->diagFl3, diagnostic->diagSh1, diagnostic->diagSh2, diagnostic->diagSh3); -} - -/** - * @brief Send a diagnostic message - * @param chan MAVLink channel to send the message - * - * @param diagFl1 Diagnostic float 1 - * @param diagFl2 Diagnostic float 2 - * @param diagFl3 Diagnostic float 3 - * @param diagSh1 Diagnostic short 1 - * @param diagSh2 Diagnostic short 2 - * @param diagSh3 Diagnostic short 3 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_diagnostic_send(mavlink_channel_t chan, float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[18]; - _mav_put_float(buf, 0, diagFl1); - _mav_put_float(buf, 4, diagFl2); - _mav_put_float(buf, 8, diagFl3); - _mav_put_int16_t(buf, 12, diagSh1); - _mav_put_int16_t(buf, 14, diagSh2); - _mav_put_int16_t(buf, 16, diagSh3); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIAGNOSTIC, buf, 18, 2); -#else - mavlink_diagnostic_t packet; - packet.diagFl1 = diagFl1; - packet.diagFl2 = diagFl2; - packet.diagFl3 = diagFl3; - packet.diagSh1 = diagSh1; - packet.diagSh2 = diagSh2; - packet.diagSh3 = diagSh3; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DIAGNOSTIC, (const char *)&packet, 18, 2); -#endif -} - -#endif - -// MESSAGE DIAGNOSTIC UNPACKING - - -/** - * @brief Get field diagFl1 from diagnostic message - * - * @return Diagnostic float 1 - */ -static inline float mavlink_msg_diagnostic_get_diagFl1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field diagFl2 from diagnostic message - * - * @return Diagnostic float 2 - */ -static inline float mavlink_msg_diagnostic_get_diagFl2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field diagFl3 from diagnostic message - * - * @return Diagnostic float 3 - */ -static inline float mavlink_msg_diagnostic_get_diagFl3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field diagSh1 from diagnostic message - * - * @return Diagnostic short 1 - */ -static inline int16_t mavlink_msg_diagnostic_get_diagSh1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 12); -} - -/** - * @brief Get field diagSh2 from diagnostic message - * - * @return Diagnostic short 2 - */ -static inline int16_t mavlink_msg_diagnostic_get_diagSh2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 14); -} - -/** - * @brief Get field diagSh3 from diagnostic message - * - * @return Diagnostic short 3 - */ -static inline int16_t mavlink_msg_diagnostic_get_diagSh3(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 16); -} - -/** - * @brief Decode a diagnostic message into a struct - * - * @param msg The message to decode - * @param diagnostic C-struct to decode the message contents into - */ -static inline void mavlink_msg_diagnostic_decode(const mavlink_message_t* msg, mavlink_diagnostic_t* diagnostic) -{ -#if MAVLINK_NEED_BYTE_SWAP - diagnostic->diagFl1 = mavlink_msg_diagnostic_get_diagFl1(msg); - diagnostic->diagFl2 = mavlink_msg_diagnostic_get_diagFl2(msg); - diagnostic->diagFl3 = mavlink_msg_diagnostic_get_diagFl3(msg); - diagnostic->diagSh1 = mavlink_msg_diagnostic_get_diagSh1(msg); - diagnostic->diagSh2 = mavlink_msg_diagnostic_get_diagSh2(msg); - diagnostic->diagSh3 = mavlink_msg_diagnostic_get_diagSh3(msg); -#else - memcpy(diagnostic, _MAV_PAYLOAD(msg), 18); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_gps_date_time.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_gps_date_time.h deleted file mode 100644 index 62b33d475a..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_gps_date_time.h +++ /dev/null @@ -1,276 +0,0 @@ -// MESSAGE GPS_DATE_TIME PACKING - -#define MAVLINK_MSG_ID_GPS_DATE_TIME 179 - -typedef struct __mavlink_gps_date_time_t -{ - uint8_t year; ///< Year reported by Gps - uint8_t month; ///< Month reported by Gps - uint8_t day; ///< Day reported by Gps - uint8_t hour; ///< Hour reported by Gps - uint8_t min; ///< Min reported by Gps - uint8_t sec; ///< Sec reported by Gps - uint8_t visSat; ///< Visible sattelites reported by Gps -} mavlink_gps_date_time_t; - -#define MAVLINK_MSG_ID_GPS_DATE_TIME_LEN 7 -#define MAVLINK_MSG_ID_179_LEN 7 - - - -#define MAVLINK_MESSAGE_INFO_GPS_DATE_TIME { \ - "GPS_DATE_TIME", \ - 7, \ - { { "year", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_gps_date_time_t, year) }, \ - { "month", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_gps_date_time_t, month) }, \ - { "day", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_gps_date_time_t, day) }, \ - { "hour", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_gps_date_time_t, hour) }, \ - { "min", NULL, MAVLINK_TYPE_UINT8_T, 0, 4, offsetof(mavlink_gps_date_time_t, min) }, \ - { "sec", NULL, MAVLINK_TYPE_UINT8_T, 0, 5, offsetof(mavlink_gps_date_time_t, sec) }, \ - { "visSat", NULL, MAVLINK_TYPE_UINT8_T, 0, 6, offsetof(mavlink_gps_date_time_t, visSat) }, \ - } \ -} - - -/** - * @brief Pack a gps_date_time message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param year Year reported by Gps - * @param month Month reported by Gps - * @param day Day reported by Gps - * @param hour Hour reported by Gps - * @param min Min reported by Gps - * @param sec Sec reported by Gps - * @param visSat Visible sattelites reported by Gps - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_date_time_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec, uint8_t visSat) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[7]; - _mav_put_uint8_t(buf, 0, year); - _mav_put_uint8_t(buf, 1, month); - _mav_put_uint8_t(buf, 2, day); - _mav_put_uint8_t(buf, 3, hour); - _mav_put_uint8_t(buf, 4, min); - _mav_put_uint8_t(buf, 5, sec); - _mav_put_uint8_t(buf, 6, visSat); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 7); -#else - mavlink_gps_date_time_t packet; - packet.year = year; - packet.month = month; - packet.day = day; - packet.hour = hour; - packet.min = min; - packet.sec = sec; - packet.visSat = visSat; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 7); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_DATE_TIME; - return mavlink_finalize_message(msg, system_id, component_id, 7, 16); -} - -/** - * @brief Pack a gps_date_time message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param year Year reported by Gps - * @param month Month reported by Gps - * @param day Day reported by Gps - * @param hour Hour reported by Gps - * @param min Min reported by Gps - * @param sec Sec reported by Gps - * @param visSat Visible sattelites reported by Gps - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_gps_date_time_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t year,uint8_t month,uint8_t day,uint8_t hour,uint8_t min,uint8_t sec,uint8_t visSat) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[7]; - _mav_put_uint8_t(buf, 0, year); - _mav_put_uint8_t(buf, 1, month); - _mav_put_uint8_t(buf, 2, day); - _mav_put_uint8_t(buf, 3, hour); - _mav_put_uint8_t(buf, 4, min); - _mav_put_uint8_t(buf, 5, sec); - _mav_put_uint8_t(buf, 6, visSat); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 7); -#else - mavlink_gps_date_time_t packet; - packet.year = year; - packet.month = month; - packet.day = day; - packet.hour = hour; - packet.min = min; - packet.sec = sec; - packet.visSat = visSat; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 7); -#endif - - msg->msgid = MAVLINK_MSG_ID_GPS_DATE_TIME; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 7, 16); -} - -/** - * @brief Encode a gps_date_time struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param gps_date_time C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_gps_date_time_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gps_date_time_t* gps_date_time) -{ - return mavlink_msg_gps_date_time_pack(system_id, component_id, msg, gps_date_time->year, gps_date_time->month, gps_date_time->day, gps_date_time->hour, gps_date_time->min, gps_date_time->sec, gps_date_time->visSat); -} - -/** - * @brief Send a gps_date_time message - * @param chan MAVLink channel to send the message - * - * @param year Year reported by Gps - * @param month Month reported by Gps - * @param day Day reported by Gps - * @param hour Hour reported by Gps - * @param min Min reported by Gps - * @param sec Sec reported by Gps - * @param visSat Visible sattelites reported by Gps - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_gps_date_time_send(mavlink_channel_t chan, uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec, uint8_t visSat) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[7]; - _mav_put_uint8_t(buf, 0, year); - _mav_put_uint8_t(buf, 1, month); - _mav_put_uint8_t(buf, 2, day); - _mav_put_uint8_t(buf, 3, hour); - _mav_put_uint8_t(buf, 4, min); - _mav_put_uint8_t(buf, 5, sec); - _mav_put_uint8_t(buf, 6, visSat); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_DATE_TIME, buf, 7, 16); -#else - mavlink_gps_date_time_t packet; - packet.year = year; - packet.month = month; - packet.day = day; - packet.hour = hour; - packet.min = min; - packet.sec = sec; - packet.visSat = visSat; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GPS_DATE_TIME, (const char *)&packet, 7, 16); -#endif -} - -#endif - -// MESSAGE GPS_DATE_TIME UNPACKING - - -/** - * @brief Get field year from gps_date_time message - * - * @return Year reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_year(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field month from gps_date_time message - * - * @return Month reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_month(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field day from gps_date_time message - * - * @return Day reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_day(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field hour from gps_date_time message - * - * @return Hour reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_hour(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field min from gps_date_time message - * - * @return Min reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_min(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 4); -} - -/** - * @brief Get field sec from gps_date_time message - * - * @return Sec reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_sec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 5); -} - -/** - * @brief Get field visSat from gps_date_time message - * - * @return Visible sattelites reported by Gps - */ -static inline uint8_t mavlink_msg_gps_date_time_get_visSat(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 6); -} - -/** - * @brief Decode a gps_date_time message into a struct - * - * @param msg The message to decode - * @param gps_date_time C-struct to decode the message contents into - */ -static inline void mavlink_msg_gps_date_time_decode(const mavlink_message_t* msg, mavlink_gps_date_time_t* gps_date_time) -{ -#if MAVLINK_NEED_BYTE_SWAP - gps_date_time->year = mavlink_msg_gps_date_time_get_year(msg); - gps_date_time->month = mavlink_msg_gps_date_time_get_month(msg); - gps_date_time->day = mavlink_msg_gps_date_time_get_day(msg); - gps_date_time->hour = mavlink_msg_gps_date_time_get_hour(msg); - gps_date_time->min = mavlink_msg_gps_date_time_get_min(msg); - gps_date_time->sec = mavlink_msg_gps_date_time_get_sec(msg); - gps_date_time->visSat = mavlink_msg_gps_date_time_get_visSat(msg); -#else - memcpy(gps_date_time, _MAV_PAYLOAD(msg), 7); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_mid_lvl_cmds.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_mid_lvl_cmds.h deleted file mode 100644 index 6542ab1dec..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_mid_lvl_cmds.h +++ /dev/null @@ -1,210 +0,0 @@ -// MESSAGE MID_LVL_CMDS PACKING - -#define MAVLINK_MSG_ID_MID_LVL_CMDS 180 - -typedef struct __mavlink_mid_lvl_cmds_t -{ - float hCommand; ///< Commanded Airspeed - float uCommand; ///< Log value 2 - float rCommand; ///< Log value 3 - uint8_t target; ///< The system setting the commands -} mavlink_mid_lvl_cmds_t; - -#define MAVLINK_MSG_ID_MID_LVL_CMDS_LEN 13 -#define MAVLINK_MSG_ID_180_LEN 13 - - - -#define MAVLINK_MESSAGE_INFO_MID_LVL_CMDS { \ - "MID_LVL_CMDS", \ - 4, \ - { { "hCommand", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_mid_lvl_cmds_t, hCommand) }, \ - { "uCommand", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_mid_lvl_cmds_t, uCommand) }, \ - { "rCommand", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_mid_lvl_cmds_t, rCommand) }, \ - { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_mid_lvl_cmds_t, target) }, \ - } \ -} - - -/** - * @brief Pack a mid_lvl_cmds message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system setting the commands - * @param hCommand Commanded Airspeed - * @param uCommand Log value 2 - * @param rCommand Log value 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mid_lvl_cmds_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, float hCommand, float uCommand, float rCommand) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_float(buf, 0, hCommand); - _mav_put_float(buf, 4, uCommand); - _mav_put_float(buf, 8, rCommand); - _mav_put_uint8_t(buf, 12, target); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 13); -#else - mavlink_mid_lvl_cmds_t packet; - packet.hCommand = hCommand; - packet.uCommand = uCommand; - packet.rCommand = rCommand; - packet.target = target; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 13); -#endif - - msg->msgid = MAVLINK_MSG_ID_MID_LVL_CMDS; - return mavlink_finalize_message(msg, system_id, component_id, 13, 146); -} - -/** - * @brief Pack a mid_lvl_cmds message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system setting the commands - * @param hCommand Commanded Airspeed - * @param uCommand Log value 2 - * @param rCommand Log value 3 - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_mid_lvl_cmds_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,float hCommand,float uCommand,float rCommand) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_float(buf, 0, hCommand); - _mav_put_float(buf, 4, uCommand); - _mav_put_float(buf, 8, rCommand); - _mav_put_uint8_t(buf, 12, target); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 13); -#else - mavlink_mid_lvl_cmds_t packet; - packet.hCommand = hCommand; - packet.uCommand = uCommand; - packet.rCommand = rCommand; - packet.target = target; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 13); -#endif - - msg->msgid = MAVLINK_MSG_ID_MID_LVL_CMDS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 13, 146); -} - -/** - * @brief Encode a mid_lvl_cmds struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param mid_lvl_cmds C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_mid_lvl_cmds_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_mid_lvl_cmds_t* mid_lvl_cmds) -{ - return mavlink_msg_mid_lvl_cmds_pack(system_id, component_id, msg, mid_lvl_cmds->target, mid_lvl_cmds->hCommand, mid_lvl_cmds->uCommand, mid_lvl_cmds->rCommand); -} - -/** - * @brief Send a mid_lvl_cmds message - * @param chan MAVLink channel to send the message - * - * @param target The system setting the commands - * @param hCommand Commanded Airspeed - * @param uCommand Log value 2 - * @param rCommand Log value 3 - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_mid_lvl_cmds_send(mavlink_channel_t chan, uint8_t target, float hCommand, float uCommand, float rCommand) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[13]; - _mav_put_float(buf, 0, hCommand); - _mav_put_float(buf, 4, uCommand); - _mav_put_float(buf, 8, rCommand); - _mav_put_uint8_t(buf, 12, target); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MID_LVL_CMDS, buf, 13, 146); -#else - mavlink_mid_lvl_cmds_t packet; - packet.hCommand = hCommand; - packet.uCommand = uCommand; - packet.rCommand = rCommand; - packet.target = target; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MID_LVL_CMDS, (const char *)&packet, 13, 146); -#endif -} - -#endif - -// MESSAGE MID_LVL_CMDS UNPACKING - - -/** - * @brief Get field target from mid_lvl_cmds message - * - * @return The system setting the commands - */ -static inline uint8_t mavlink_msg_mid_lvl_cmds_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 12); -} - -/** - * @brief Get field hCommand from mid_lvl_cmds message - * - * @return Commanded Airspeed - */ -static inline float mavlink_msg_mid_lvl_cmds_get_hCommand(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field uCommand from mid_lvl_cmds message - * - * @return Log value 2 - */ -static inline float mavlink_msg_mid_lvl_cmds_get_uCommand(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field rCommand from mid_lvl_cmds message - * - * @return Log value 3 - */ -static inline float mavlink_msg_mid_lvl_cmds_get_rCommand(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Decode a mid_lvl_cmds message into a struct - * - * @param msg The message to decode - * @param mid_lvl_cmds C-struct to decode the message contents into - */ -static inline void mavlink_msg_mid_lvl_cmds_decode(const mavlink_message_t* msg, mavlink_mid_lvl_cmds_t* mid_lvl_cmds) -{ -#if MAVLINK_NEED_BYTE_SWAP - mid_lvl_cmds->hCommand = mavlink_msg_mid_lvl_cmds_get_hCommand(msg); - mid_lvl_cmds->uCommand = mavlink_msg_mid_lvl_cmds_get_uCommand(msg); - mid_lvl_cmds->rCommand = mavlink_msg_mid_lvl_cmds_get_rCommand(msg); - mid_lvl_cmds->target = mavlink_msg_mid_lvl_cmds_get_target(msg); -#else - memcpy(mid_lvl_cmds, _MAV_PAYLOAD(msg), 13); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_sensor_bias.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_sensor_bias.h deleted file mode 100644 index 7dec47ed3a..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_sensor_bias.h +++ /dev/null @@ -1,254 +0,0 @@ -// MESSAGE SENSOR_BIAS PACKING - -#define MAVLINK_MSG_ID_SENSOR_BIAS 172 - -typedef struct __mavlink_sensor_bias_t -{ - float axBias; ///< Accelerometer X bias (m/s) - float ayBias; ///< Accelerometer Y bias (m/s) - float azBias; ///< Accelerometer Z bias (m/s) - float gxBias; ///< Gyro X bias (rad/s) - float gyBias; ///< Gyro Y bias (rad/s) - float gzBias; ///< Gyro Z bias (rad/s) -} mavlink_sensor_bias_t; - -#define MAVLINK_MSG_ID_SENSOR_BIAS_LEN 24 -#define MAVLINK_MSG_ID_172_LEN 24 - - - -#define MAVLINK_MESSAGE_INFO_SENSOR_BIAS { \ - "SENSOR_BIAS", \ - 6, \ - { { "axBias", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_sensor_bias_t, axBias) }, \ - { "ayBias", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_sensor_bias_t, ayBias) }, \ - { "azBias", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_sensor_bias_t, azBias) }, \ - { "gxBias", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_sensor_bias_t, gxBias) }, \ - { "gyBias", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_sensor_bias_t, gyBias) }, \ - { "gzBias", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_sensor_bias_t, gzBias) }, \ - } \ -} - - -/** - * @brief Pack a sensor_bias message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param axBias Accelerometer X bias (m/s) - * @param ayBias Accelerometer Y bias (m/s) - * @param azBias Accelerometer Z bias (m/s) - * @param gxBias Gyro X bias (rad/s) - * @param gyBias Gyro Y bias (rad/s) - * @param gzBias Gyro Z bias (rad/s) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sensor_bias_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float axBias, float ayBias, float azBias, float gxBias, float gyBias, float gzBias) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, axBias); - _mav_put_float(buf, 4, ayBias); - _mav_put_float(buf, 8, azBias); - _mav_put_float(buf, 12, gxBias); - _mav_put_float(buf, 16, gyBias); - _mav_put_float(buf, 20, gzBias); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_sensor_bias_t packet; - packet.axBias = axBias; - packet.ayBias = ayBias; - packet.azBias = azBias; - packet.gxBias = gxBias; - packet.gyBias = gyBias; - packet.gzBias = gzBias; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_SENSOR_BIAS; - return mavlink_finalize_message(msg, system_id, component_id, 24, 168); -} - -/** - * @brief Pack a sensor_bias message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param axBias Accelerometer X bias (m/s) - * @param ayBias Accelerometer Y bias (m/s) - * @param azBias Accelerometer Z bias (m/s) - * @param gxBias Gyro X bias (rad/s) - * @param gyBias Gyro Y bias (rad/s) - * @param gzBias Gyro Z bias (rad/s) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_sensor_bias_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float axBias,float ayBias,float azBias,float gxBias,float gyBias,float gzBias) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, axBias); - _mav_put_float(buf, 4, ayBias); - _mav_put_float(buf, 8, azBias); - _mav_put_float(buf, 12, gxBias); - _mav_put_float(buf, 16, gyBias); - _mav_put_float(buf, 20, gzBias); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 24); -#else - mavlink_sensor_bias_t packet; - packet.axBias = axBias; - packet.ayBias = ayBias; - packet.azBias = azBias; - packet.gxBias = gxBias; - packet.gyBias = gyBias; - packet.gzBias = gzBias; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 24); -#endif - - msg->msgid = MAVLINK_MSG_ID_SENSOR_BIAS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 24, 168); -} - -/** - * @brief Encode a sensor_bias struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param sensor_bias C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_sensor_bias_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_sensor_bias_t* sensor_bias) -{ - return mavlink_msg_sensor_bias_pack(system_id, component_id, msg, sensor_bias->axBias, sensor_bias->ayBias, sensor_bias->azBias, sensor_bias->gxBias, sensor_bias->gyBias, sensor_bias->gzBias); -} - -/** - * @brief Send a sensor_bias message - * @param chan MAVLink channel to send the message - * - * @param axBias Accelerometer X bias (m/s) - * @param ayBias Accelerometer Y bias (m/s) - * @param azBias Accelerometer Z bias (m/s) - * @param gxBias Gyro X bias (rad/s) - * @param gyBias Gyro Y bias (rad/s) - * @param gzBias Gyro Z bias (rad/s) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_sensor_bias_send(mavlink_channel_t chan, float axBias, float ayBias, float azBias, float gxBias, float gyBias, float gzBias) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[24]; - _mav_put_float(buf, 0, axBias); - _mav_put_float(buf, 4, ayBias); - _mav_put_float(buf, 8, azBias); - _mav_put_float(buf, 12, gxBias); - _mav_put_float(buf, 16, gyBias); - _mav_put_float(buf, 20, gzBias); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SENSOR_BIAS, buf, 24, 168); -#else - mavlink_sensor_bias_t packet; - packet.axBias = axBias; - packet.ayBias = ayBias; - packet.azBias = azBias; - packet.gxBias = gxBias; - packet.gyBias = gyBias; - packet.gzBias = gzBias; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SENSOR_BIAS, (const char *)&packet, 24, 168); -#endif -} - -#endif - -// MESSAGE SENSOR_BIAS UNPACKING - - -/** - * @brief Get field axBias from sensor_bias message - * - * @return Accelerometer X bias (m/s) - */ -static inline float mavlink_msg_sensor_bias_get_axBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field ayBias from sensor_bias message - * - * @return Accelerometer Y bias (m/s) - */ -static inline float mavlink_msg_sensor_bias_get_ayBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field azBias from sensor_bias message - * - * @return Accelerometer Z bias (m/s) - */ -static inline float mavlink_msg_sensor_bias_get_azBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field gxBias from sensor_bias message - * - * @return Gyro X bias (rad/s) - */ -static inline float mavlink_msg_sensor_bias_get_gxBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field gyBias from sensor_bias message - * - * @return Gyro Y bias (rad/s) - */ -static inline float mavlink_msg_sensor_bias_get_gyBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field gzBias from sensor_bias message - * - * @return Gyro Z bias (rad/s) - */ -static inline float mavlink_msg_sensor_bias_get_gzBias(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Decode a sensor_bias message into a struct - * - * @param msg The message to decode - * @param sensor_bias C-struct to decode the message contents into - */ -static inline void mavlink_msg_sensor_bias_decode(const mavlink_message_t* msg, mavlink_sensor_bias_t* sensor_bias) -{ -#if MAVLINK_NEED_BYTE_SWAP - sensor_bias->axBias = mavlink_msg_sensor_bias_get_axBias(msg); - sensor_bias->ayBias = mavlink_msg_sensor_bias_get_ayBias(msg); - sensor_bias->azBias = mavlink_msg_sensor_bias_get_azBias(msg); - sensor_bias->gxBias = mavlink_msg_sensor_bias_get_gxBias(msg); - sensor_bias->gyBias = mavlink_msg_sensor_bias_get_gyBias(msg); - sensor_bias->gzBias = mavlink_msg_sensor_bias_get_gzBias(msg); -#else - memcpy(sensor_bias, _MAV_PAYLOAD(msg), 24); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_slugs_action.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_slugs_action.h deleted file mode 100644 index 84b87a308e..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_slugs_action.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE SLUGS_ACTION PACKING - -#define MAVLINK_MSG_ID_SLUGS_ACTION 183 - -typedef struct __mavlink_slugs_action_t -{ - uint16_t actionVal; ///< Value associated with the action - uint8_t target; ///< The system reporting the action - uint8_t actionId; ///< Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names -} mavlink_slugs_action_t; - -#define MAVLINK_MSG_ID_SLUGS_ACTION_LEN 4 -#define MAVLINK_MSG_ID_183_LEN 4 - - - -#define MAVLINK_MESSAGE_INFO_SLUGS_ACTION { \ - "SLUGS_ACTION", \ - 3, \ - { { "actionVal", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_slugs_action_t, actionVal) }, \ - { "target", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_slugs_action_t, target) }, \ - { "actionId", NULL, MAVLINK_TYPE_UINT8_T, 0, 3, offsetof(mavlink_slugs_action_t, actionId) }, \ - } \ -} - - -/** - * @brief Pack a slugs_action message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param target The system reporting the action - * @param actionId Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - * @param actionVal Value associated with the action - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_action_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t target, uint8_t actionId, uint16_t actionVal) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, actionVal); - _mav_put_uint8_t(buf, 2, target); - _mav_put_uint8_t(buf, 3, actionId); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_slugs_action_t packet; - packet.actionVal = actionVal; - packet.target = target; - packet.actionId = actionId; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_ACTION; - return mavlink_finalize_message(msg, system_id, component_id, 4, 65); -} - -/** - * @brief Pack a slugs_action message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param target The system reporting the action - * @param actionId Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - * @param actionVal Value associated with the action - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_action_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t target,uint8_t actionId,uint16_t actionVal) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, actionVal); - _mav_put_uint8_t(buf, 2, target); - _mav_put_uint8_t(buf, 3, actionId); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 4); -#else - mavlink_slugs_action_t packet; - packet.actionVal = actionVal; - packet.target = target; - packet.actionId = actionId; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 4); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_ACTION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 4, 65); -} - -/** - * @brief Encode a slugs_action struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param slugs_action C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_slugs_action_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_slugs_action_t* slugs_action) -{ - return mavlink_msg_slugs_action_pack(system_id, component_id, msg, slugs_action->target, slugs_action->actionId, slugs_action->actionVal); -} - -/** - * @brief Send a slugs_action message - * @param chan MAVLink channel to send the message - * - * @param target The system reporting the action - * @param actionId Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - * @param actionVal Value associated with the action - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_slugs_action_send(mavlink_channel_t chan, uint8_t target, uint8_t actionId, uint16_t actionVal) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[4]; - _mav_put_uint16_t(buf, 0, actionVal); - _mav_put_uint8_t(buf, 2, target); - _mav_put_uint8_t(buf, 3, actionId); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_ACTION, buf, 4, 65); -#else - mavlink_slugs_action_t packet; - packet.actionVal = actionVal; - packet.target = target; - packet.actionId = actionId; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_ACTION, (const char *)&packet, 4, 65); -#endif -} - -#endif - -// MESSAGE SLUGS_ACTION UNPACKING - - -/** - * @brief Get field target from slugs_action message - * - * @return The system reporting the action - */ -static inline uint8_t mavlink_msg_slugs_action_get_target(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Get field actionId from slugs_action message - * - * @return Action ID. See apDefinitions.h in the SLUGS /clib directory for the ID names - */ -static inline uint8_t mavlink_msg_slugs_action_get_actionId(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 3); -} - -/** - * @brief Get field actionVal from slugs_action message - * - * @return Value associated with the action - */ -static inline uint16_t mavlink_msg_slugs_action_get_actionVal(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 0); -} - -/** - * @brief Decode a slugs_action message into a struct - * - * @param msg The message to decode - * @param slugs_action C-struct to decode the message contents into - */ -static inline void mavlink_msg_slugs_action_decode(const mavlink_message_t* msg, mavlink_slugs_action_t* slugs_action) -{ -#if MAVLINK_NEED_BYTE_SWAP - slugs_action->actionVal = mavlink_msg_slugs_action_get_actionVal(msg); - slugs_action->target = mavlink_msg_slugs_action_get_target(msg); - slugs_action->actionId = mavlink_msg_slugs_action_get_actionId(msg); -#else - memcpy(slugs_action, _MAV_PAYLOAD(msg), 4); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_slugs_navigation.h b/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_slugs_navigation.h deleted file mode 100644 index b29a889975..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/mavlink_msg_slugs_navigation.h +++ /dev/null @@ -1,320 +0,0 @@ -// MESSAGE SLUGS_NAVIGATION PACKING - -#define MAVLINK_MSG_ID_SLUGS_NAVIGATION 176 - -typedef struct __mavlink_slugs_navigation_t -{ - float u_m; ///< Measured Airspeed prior to the Nav Filter - float phi_c; ///< Commanded Roll - float theta_c; ///< Commanded Pitch - float psiDot_c; ///< Commanded Turn rate - float ay_body; ///< Y component of the body acceleration - float totalDist; ///< Total Distance to Run on this leg of Navigation - float dist2Go; ///< Remaining distance to Run on this leg of Navigation - uint8_t fromWP; ///< Origin WP - uint8_t toWP; ///< Destination WP -} mavlink_slugs_navigation_t; - -#define MAVLINK_MSG_ID_SLUGS_NAVIGATION_LEN 30 -#define MAVLINK_MSG_ID_176_LEN 30 - - - -#define MAVLINK_MESSAGE_INFO_SLUGS_NAVIGATION { \ - "SLUGS_NAVIGATION", \ - 9, \ - { { "u_m", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_slugs_navigation_t, u_m) }, \ - { "phi_c", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_slugs_navigation_t, phi_c) }, \ - { "theta_c", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_slugs_navigation_t, theta_c) }, \ - { "psiDot_c", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_slugs_navigation_t, psiDot_c) }, \ - { "ay_body", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_slugs_navigation_t, ay_body) }, \ - { "totalDist", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_slugs_navigation_t, totalDist) }, \ - { "dist2Go", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_slugs_navigation_t, dist2Go) }, \ - { "fromWP", NULL, MAVLINK_TYPE_UINT8_T, 0, 28, offsetof(mavlink_slugs_navigation_t, fromWP) }, \ - { "toWP", NULL, MAVLINK_TYPE_UINT8_T, 0, 29, offsetof(mavlink_slugs_navigation_t, toWP) }, \ - } \ -} - - -/** - * @brief Pack a slugs_navigation message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param u_m Measured Airspeed prior to the Nav Filter - * @param phi_c Commanded Roll - * @param theta_c Commanded Pitch - * @param psiDot_c Commanded Turn rate - * @param ay_body Y component of the body acceleration - * @param totalDist Total Distance to Run on this leg of Navigation - * @param dist2Go Remaining distance to Run on this leg of Navigation - * @param fromWP Origin WP - * @param toWP Destination WP - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_navigation_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - float u_m, float phi_c, float theta_c, float psiDot_c, float ay_body, float totalDist, float dist2Go, uint8_t fromWP, uint8_t toWP) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_float(buf, 0, u_m); - _mav_put_float(buf, 4, phi_c); - _mav_put_float(buf, 8, theta_c); - _mav_put_float(buf, 12, psiDot_c); - _mav_put_float(buf, 16, ay_body); - _mav_put_float(buf, 20, totalDist); - _mav_put_float(buf, 24, dist2Go); - _mav_put_uint8_t(buf, 28, fromWP); - _mav_put_uint8_t(buf, 29, toWP); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 30); -#else - mavlink_slugs_navigation_t packet; - packet.u_m = u_m; - packet.phi_c = phi_c; - packet.theta_c = theta_c; - packet.psiDot_c = psiDot_c; - packet.ay_body = ay_body; - packet.totalDist = totalDist; - packet.dist2Go = dist2Go; - packet.fromWP = fromWP; - packet.toWP = toWP; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 30); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_NAVIGATION; - return mavlink_finalize_message(msg, system_id, component_id, 30, 120); -} - -/** - * @brief Pack a slugs_navigation message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param u_m Measured Airspeed prior to the Nav Filter - * @param phi_c Commanded Roll - * @param theta_c Commanded Pitch - * @param psiDot_c Commanded Turn rate - * @param ay_body Y component of the body acceleration - * @param totalDist Total Distance to Run on this leg of Navigation - * @param dist2Go Remaining distance to Run on this leg of Navigation - * @param fromWP Origin WP - * @param toWP Destination WP - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_slugs_navigation_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - float u_m,float phi_c,float theta_c,float psiDot_c,float ay_body,float totalDist,float dist2Go,uint8_t fromWP,uint8_t toWP) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_float(buf, 0, u_m); - _mav_put_float(buf, 4, phi_c); - _mav_put_float(buf, 8, theta_c); - _mav_put_float(buf, 12, psiDot_c); - _mav_put_float(buf, 16, ay_body); - _mav_put_float(buf, 20, totalDist); - _mav_put_float(buf, 24, dist2Go); - _mav_put_uint8_t(buf, 28, fromWP); - _mav_put_uint8_t(buf, 29, toWP); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 30); -#else - mavlink_slugs_navigation_t packet; - packet.u_m = u_m; - packet.phi_c = phi_c; - packet.theta_c = theta_c; - packet.psiDot_c = psiDot_c; - packet.ay_body = ay_body; - packet.totalDist = totalDist; - packet.dist2Go = dist2Go; - packet.fromWP = fromWP; - packet.toWP = toWP; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 30); -#endif - - msg->msgid = MAVLINK_MSG_ID_SLUGS_NAVIGATION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 30, 120); -} - -/** - * @brief Encode a slugs_navigation struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param slugs_navigation C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_slugs_navigation_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_slugs_navigation_t* slugs_navigation) -{ - return mavlink_msg_slugs_navigation_pack(system_id, component_id, msg, slugs_navigation->u_m, slugs_navigation->phi_c, slugs_navigation->theta_c, slugs_navigation->psiDot_c, slugs_navigation->ay_body, slugs_navigation->totalDist, slugs_navigation->dist2Go, slugs_navigation->fromWP, slugs_navigation->toWP); -} - -/** - * @brief Send a slugs_navigation message - * @param chan MAVLink channel to send the message - * - * @param u_m Measured Airspeed prior to the Nav Filter - * @param phi_c Commanded Roll - * @param theta_c Commanded Pitch - * @param psiDot_c Commanded Turn rate - * @param ay_body Y component of the body acceleration - * @param totalDist Total Distance to Run on this leg of Navigation - * @param dist2Go Remaining distance to Run on this leg of Navigation - * @param fromWP Origin WP - * @param toWP Destination WP - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_slugs_navigation_send(mavlink_channel_t chan, float u_m, float phi_c, float theta_c, float psiDot_c, float ay_body, float totalDist, float dist2Go, uint8_t fromWP, uint8_t toWP) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[30]; - _mav_put_float(buf, 0, u_m); - _mav_put_float(buf, 4, phi_c); - _mav_put_float(buf, 8, theta_c); - _mav_put_float(buf, 12, psiDot_c); - _mav_put_float(buf, 16, ay_body); - _mav_put_float(buf, 20, totalDist); - _mav_put_float(buf, 24, dist2Go); - _mav_put_uint8_t(buf, 28, fromWP); - _mav_put_uint8_t(buf, 29, toWP); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_NAVIGATION, buf, 30, 120); -#else - mavlink_slugs_navigation_t packet; - packet.u_m = u_m; - packet.phi_c = phi_c; - packet.theta_c = theta_c; - packet.psiDot_c = psiDot_c; - packet.ay_body = ay_body; - packet.totalDist = totalDist; - packet.dist2Go = dist2Go; - packet.fromWP = fromWP; - packet.toWP = toWP; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_SLUGS_NAVIGATION, (const char *)&packet, 30, 120); -#endif -} - -#endif - -// MESSAGE SLUGS_NAVIGATION UNPACKING - - -/** - * @brief Get field u_m from slugs_navigation message - * - * @return Measured Airspeed prior to the Nav Filter - */ -static inline float mavlink_msg_slugs_navigation_get_u_m(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 0); -} - -/** - * @brief Get field phi_c from slugs_navigation message - * - * @return Commanded Roll - */ -static inline float mavlink_msg_slugs_navigation_get_phi_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 4); -} - -/** - * @brief Get field theta_c from slugs_navigation message - * - * @return Commanded Pitch - */ -static inline float mavlink_msg_slugs_navigation_get_theta_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field psiDot_c from slugs_navigation message - * - * @return Commanded Turn rate - */ -static inline float mavlink_msg_slugs_navigation_get_psiDot_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field ay_body from slugs_navigation message - * - * @return Y component of the body acceleration - */ -static inline float mavlink_msg_slugs_navigation_get_ay_body(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field totalDist from slugs_navigation message - * - * @return Total Distance to Run on this leg of Navigation - */ -static inline float mavlink_msg_slugs_navigation_get_totalDist(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field dist2Go from slugs_navigation message - * - * @return Remaining distance to Run on this leg of Navigation - */ -static inline float mavlink_msg_slugs_navigation_get_dist2Go(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field fromWP from slugs_navigation message - * - * @return Origin WP - */ -static inline uint8_t mavlink_msg_slugs_navigation_get_fromWP(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 28); -} - -/** - * @brief Get field toWP from slugs_navigation message - * - * @return Destination WP - */ -static inline uint8_t mavlink_msg_slugs_navigation_get_toWP(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 29); -} - -/** - * @brief Decode a slugs_navigation message into a struct - * - * @param msg The message to decode - * @param slugs_navigation C-struct to decode the message contents into - */ -static inline void mavlink_msg_slugs_navigation_decode(const mavlink_message_t* msg, mavlink_slugs_navigation_t* slugs_navigation) -{ -#if MAVLINK_NEED_BYTE_SWAP - slugs_navigation->u_m = mavlink_msg_slugs_navigation_get_u_m(msg); - slugs_navigation->phi_c = mavlink_msg_slugs_navigation_get_phi_c(msg); - slugs_navigation->theta_c = mavlink_msg_slugs_navigation_get_theta_c(msg); - slugs_navigation->psiDot_c = mavlink_msg_slugs_navigation_get_psiDot_c(msg); - slugs_navigation->ay_body = mavlink_msg_slugs_navigation_get_ay_body(msg); - slugs_navigation->totalDist = mavlink_msg_slugs_navigation_get_totalDist(msg); - slugs_navigation->dist2Go = mavlink_msg_slugs_navigation_get_dist2Go(msg); - slugs_navigation->fromWP = mavlink_msg_slugs_navigation_get_fromWP(msg); - slugs_navigation->toWP = mavlink_msg_slugs_navigation_get_toWP(msg); -#else - memcpy(slugs_navigation, _MAV_PAYLOAD(msg), 30); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/slugs/slugs.h b/mavlink/include/mavlink/v1.0/slugs/slugs.h deleted file mode 100644 index b943624b53..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/slugs.h +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from slugs.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef SLUGS_H -#define SLUGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {9, 31, 12, 0, 14, 28, 3, 32, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 25, 23, 30, 101, 22, 26, 16, 14, 28, 32, 28, 28, 22, 22, 21, 6, 6, 37, 4, 4, 2, 2, 4, 2, 2, 3, 13, 12, 19, 17, 15, 15, 27, 25, 18, 18, 20, 20, 9, 54, 26, 0, 36, 0, 6, 4, 0, 21, 18, 0, 0, 0, 20, 0, 33, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 56, 42, 33, 0, 0, 0, 0, 0, 0, 0, 26, 32, 32, 20, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 10, 24, 18, 0, 0, 30, 24, 0, 7, 13, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 30, 18, 18, 51, 9, 0} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 214, 223, 141, 33, 15, 3, 100, 24, 239, 238, 30, 200, 183, 0, 130, 0, 148, 21, 0, 52, 124, 0, 0, 0, 20, 0, 152, 143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 232, 168, 2, 0, 0, 120, 167, 0, 16, 146, 104, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 49, 170, 44, 83, 46, 0} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_HEARTBEAT, MAVLINK_MESSAGE_INFO_SYS_STATUS, MAVLINK_MESSAGE_INFO_SYSTEM_TIME, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PING, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL, MAVLINK_MESSAGE_INFO_CHANGE_OPERATOR_CONTROL_ACK, MAVLINK_MESSAGE_INFO_AUTH_KEY, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SET_MODE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_READ, MAVLINK_MESSAGE_INFO_PARAM_REQUEST_LIST, MAVLINK_MESSAGE_INFO_PARAM_VALUE, MAVLINK_MESSAGE_INFO_PARAM_SET, MAVLINK_MESSAGE_INFO_GPS_RAW_INT, MAVLINK_MESSAGE_INFO_GPS_STATUS, MAVLINK_MESSAGE_INFO_SCALED_IMU, MAVLINK_MESSAGE_INFO_RAW_IMU, MAVLINK_MESSAGE_INFO_RAW_PRESSURE, MAVLINK_MESSAGE_INFO_SCALED_PRESSURE, MAVLINK_MESSAGE_INFO_ATTITUDE, MAVLINK_MESSAGE_INFO_ATTITUDE_QUATERNION, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_NED, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_INT, MAVLINK_MESSAGE_INFO_RC_CHANNELS_SCALED, MAVLINK_MESSAGE_INFO_RC_CHANNELS_RAW, MAVLINK_MESSAGE_INFO_SERVO_OUTPUT_RAW, MAVLINK_MESSAGE_INFO_MISSION_REQUEST_PARTIAL_LIST, MAVLINK_MESSAGE_INFO_MISSION_WRITE_PARTIAL_LIST, MAVLINK_MESSAGE_INFO_MISSION_ITEM, MAVLINK_MESSAGE_INFO_MISSION_REQUEST, MAVLINK_MESSAGE_INFO_MISSION_SET_CURRENT, MAVLINK_MESSAGE_INFO_MISSION_CURRENT, MAVLINK_MESSAGE_INFO_MISSION_REQUEST_LIST, MAVLINK_MESSAGE_INFO_MISSION_COUNT, MAVLINK_MESSAGE_INFO_MISSION_CLEAR_ALL, MAVLINK_MESSAGE_INFO_MISSION_ITEM_REACHED, MAVLINK_MESSAGE_INFO_MISSION_ACK, MAVLINK_MESSAGE_INFO_SET_GPS_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_GPS_GLOBAL_ORIGIN, MAVLINK_MESSAGE_INFO_SET_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_SETPOINT, MAVLINK_MESSAGE_INFO_GLOBAL_POSITION_SETPOINT_INT, MAVLINK_MESSAGE_INFO_SET_GLOBAL_POSITION_SETPOINT_INT, MAVLINK_MESSAGE_INFO_SAFETY_SET_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SAFETY_ALLOWED_AREA, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_SET_ROLL_PITCH_YAW_SPEED_THRUST, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT, MAVLINK_MESSAGE_INFO_SET_QUAD_MOTORS_SETPOINT, MAVLINK_MESSAGE_INFO_SET_QUAD_SWARM_ROLL_PITCH_YAW_THRUST, MAVLINK_MESSAGE_INFO_NAV_CONTROLLER_OUTPUT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_STATE_CORRECTION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_REQUEST_DATA_STREAM, MAVLINK_MESSAGE_INFO_DATA_STREAM, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_MANUAL_CONTROL, MAVLINK_MESSAGE_INFO_RC_CHANNELS_OVERRIDE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_VFR_HUD, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_COMMAND_LONG, MAVLINK_MESSAGE_INFO_COMMAND_ACK, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_LOCAL_POSITION_NED_SYSTEM_GLOBAL_OFFSET, MAVLINK_MESSAGE_INFO_HIL_STATE, MAVLINK_MESSAGE_INFO_HIL_CONTROLS, MAVLINK_MESSAGE_INFO_HIL_RC_INPUTS_RAW, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_OPTICAL_FLOW, MAVLINK_MESSAGE_INFO_GLOBAL_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_POSITION_ESTIMATE, MAVLINK_MESSAGE_INFO_VISION_SPEED_ESTIMATE, MAVLINK_MESSAGE_INFO_VICON_POSITION_ESTIMATE, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_CPU_LOAD, MAVLINK_MESSAGE_INFO_AIR_DATA, MAVLINK_MESSAGE_INFO_SENSOR_BIAS, MAVLINK_MESSAGE_INFO_DIAGNOSTIC, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SLUGS_NAVIGATION, MAVLINK_MESSAGE_INFO_DATA_LOG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_GPS_DATE_TIME, MAVLINK_MESSAGE_INFO_MID_LVL_CMDS, MAVLINK_MESSAGE_INFO_CTRL_SRFC_PT, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_SLUGS_ACTION, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, MAVLINK_MESSAGE_INFO_MEMORY_VECT, MAVLINK_MESSAGE_INFO_DEBUG_VECT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_FLOAT, MAVLINK_MESSAGE_INFO_NAMED_VALUE_INT, MAVLINK_MESSAGE_INFO_STATUSTEXT, MAVLINK_MESSAGE_INFO_DEBUG, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_SLUGS - -#include "../common/common.h" - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 2 -#endif - -// ENUM DEFINITIONS - - - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_cpu_load.h" -#include "./mavlink_msg_air_data.h" -#include "./mavlink_msg_sensor_bias.h" -#include "./mavlink_msg_diagnostic.h" -#include "./mavlink_msg_slugs_navigation.h" -#include "./mavlink_msg_data_log.h" -#include "./mavlink_msg_gps_date_time.h" -#include "./mavlink_msg_mid_lvl_cmds.h" -#include "./mavlink_msg_ctrl_srfc_pt.h" -#include "./mavlink_msg_slugs_action.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // SLUGS_H diff --git a/mavlink/include/mavlink/v1.0/slugs/testsuite.h b/mavlink/include/mavlink/v1.0/slugs/testsuite.h deleted file mode 100644 index 4593235a4a..0000000000 --- a/mavlink/include/mavlink/v1.0/slugs/testsuite.h +++ /dev/null @@ -1,552 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from slugs.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef SLUGS_TESTSUITE_H -#define SLUGS_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); -static void mavlink_test_slugs(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_test_common(system_id, component_id, last_msg); - mavlink_test_slugs(system_id, component_id, last_msg); -} -#endif - -#include "../common/testsuite.h" - - -static void mavlink_test_cpu_load(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_cpu_load_t packet_in = { - 17235, - 139, - 206, - }; - mavlink_cpu_load_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.batVolt = packet_in.batVolt; - packet1.sensLoad = packet_in.sensLoad; - packet1.ctrlLoad = packet_in.ctrlLoad; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_cpu_load_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_cpu_load_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_cpu_load_pack(system_id, component_id, &msg , packet1.sensLoad , packet1.ctrlLoad , packet1.batVolt ); - mavlink_msg_cpu_load_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_cpu_load_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.sensLoad , packet1.ctrlLoad , packet1.batVolt ); - mavlink_msg_cpu_load_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imsgid = MAVLINK_MSG_ID_TEST_TYPES; - return mavlink_finalize_message(msg, system_id, component_id, 179, 103); -} - -/** - * @brief Pack a test_types message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param c char - * @param s string - * @param u8 uint8_t - * @param u16 uint16_t - * @param u32 uint32_t - * @param u64 uint64_t - * @param s8 int8_t - * @param s16 int16_t - * @param s32 int32_t - * @param s64 int64_t - * @param f float - * @param d double - * @param u8_array uint8_t_array - * @param u16_array uint16_t_array - * @param u32_array uint32_t_array - * @param u64_array uint64_t_array - * @param s8_array int8_t_array - * @param s16_array int16_t_array - * @param s32_array int32_t_array - * @param s64_array int64_t_array - * @param f_array float_array - * @param d_array double_array - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_test_types_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - char c,const char *s,uint8_t u8,uint16_t u16,uint32_t u32,uint64_t u64,int8_t s8,int16_t s16,int32_t s32,int64_t s64,float f,double d,const uint8_t *u8_array,const uint16_t *u16_array,const uint32_t *u32_array,const uint64_t *u64_array,const int8_t *s8_array,const int16_t *s16_array,const int32_t *s32_array,const int64_t *s64_array,const float *f_array,const double *d_array) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[179]; - _mav_put_uint64_t(buf, 0, u64); - _mav_put_int64_t(buf, 8, s64); - _mav_put_double(buf, 16, d); - _mav_put_uint32_t(buf, 96, u32); - _mav_put_int32_t(buf, 100, s32); - _mav_put_float(buf, 104, f); - _mav_put_uint16_t(buf, 144, u16); - _mav_put_int16_t(buf, 146, s16); - _mav_put_char(buf, 160, c); - _mav_put_uint8_t(buf, 171, u8); - _mav_put_int8_t(buf, 172, s8); - _mav_put_uint64_t_array(buf, 24, u64_array, 3); - _mav_put_int64_t_array(buf, 48, s64_array, 3); - _mav_put_double_array(buf, 72, d_array, 3); - _mav_put_uint32_t_array(buf, 108, u32_array, 3); - _mav_put_int32_t_array(buf, 120, s32_array, 3); - _mav_put_float_array(buf, 132, f_array, 3); - _mav_put_uint16_t_array(buf, 148, u16_array, 3); - _mav_put_int16_t_array(buf, 154, s16_array, 3); - _mav_put_char_array(buf, 161, s, 10); - _mav_put_uint8_t_array(buf, 173, u8_array, 3); - _mav_put_int8_t_array(buf, 176, s8_array, 3); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 179); -#else - mavlink_test_types_t packet; - packet.u64 = u64; - packet.s64 = s64; - packet.d = d; - packet.u32 = u32; - packet.s32 = s32; - packet.f = f; - packet.u16 = u16; - packet.s16 = s16; - packet.c = c; - packet.u8 = u8; - packet.s8 = s8; - mav_array_memcpy(packet.u64_array, u64_array, sizeof(uint64_t)*3); - mav_array_memcpy(packet.s64_array, s64_array, sizeof(int64_t)*3); - mav_array_memcpy(packet.d_array, d_array, sizeof(double)*3); - mav_array_memcpy(packet.u32_array, u32_array, sizeof(uint32_t)*3); - mav_array_memcpy(packet.s32_array, s32_array, sizeof(int32_t)*3); - mav_array_memcpy(packet.f_array, f_array, sizeof(float)*3); - mav_array_memcpy(packet.u16_array, u16_array, sizeof(uint16_t)*3); - mav_array_memcpy(packet.s16_array, s16_array, sizeof(int16_t)*3); - mav_array_memcpy(packet.s, s, sizeof(char)*10); - mav_array_memcpy(packet.u8_array, u8_array, sizeof(uint8_t)*3); - mav_array_memcpy(packet.s8_array, s8_array, sizeof(int8_t)*3); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 179); -#endif - - msg->msgid = MAVLINK_MSG_ID_TEST_TYPES; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 179, 103); -} - -/** - * @brief Encode a test_types struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param test_types C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_test_types_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_test_types_t* test_types) -{ - return mavlink_msg_test_types_pack(system_id, component_id, msg, test_types->c, test_types->s, test_types->u8, test_types->u16, test_types->u32, test_types->u64, test_types->s8, test_types->s16, test_types->s32, test_types->s64, test_types->f, test_types->d, test_types->u8_array, test_types->u16_array, test_types->u32_array, test_types->u64_array, test_types->s8_array, test_types->s16_array, test_types->s32_array, test_types->s64_array, test_types->f_array, test_types->d_array); -} - -/** - * @brief Send a test_types message - * @param chan MAVLink channel to send the message - * - * @param c char - * @param s string - * @param u8 uint8_t - * @param u16 uint16_t - * @param u32 uint32_t - * @param u64 uint64_t - * @param s8 int8_t - * @param s16 int16_t - * @param s32 int32_t - * @param s64 int64_t - * @param f float - * @param d double - * @param u8_array uint8_t_array - * @param u16_array uint16_t_array - * @param u32_array uint32_t_array - * @param u64_array uint64_t_array - * @param s8_array int8_t_array - * @param s16_array int16_t_array - * @param s32_array int32_t_array - * @param s64_array int64_t_array - * @param f_array float_array - * @param d_array double_array - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_test_types_send(mavlink_channel_t chan, char c, const char *s, uint8_t u8, uint16_t u16, uint32_t u32, uint64_t u64, int8_t s8, int16_t s16, int32_t s32, int64_t s64, float f, double d, const uint8_t *u8_array, const uint16_t *u16_array, const uint32_t *u32_array, const uint64_t *u64_array, const int8_t *s8_array, const int16_t *s16_array, const int32_t *s32_array, const int64_t *s64_array, const float *f_array, const double *d_array) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[179]; - _mav_put_uint64_t(buf, 0, u64); - _mav_put_int64_t(buf, 8, s64); - _mav_put_double(buf, 16, d); - _mav_put_uint32_t(buf, 96, u32); - _mav_put_int32_t(buf, 100, s32); - _mav_put_float(buf, 104, f); - _mav_put_uint16_t(buf, 144, u16); - _mav_put_int16_t(buf, 146, s16); - _mav_put_char(buf, 160, c); - _mav_put_uint8_t(buf, 171, u8); - _mav_put_int8_t(buf, 172, s8); - _mav_put_uint64_t_array(buf, 24, u64_array, 3); - _mav_put_int64_t_array(buf, 48, s64_array, 3); - _mav_put_double_array(buf, 72, d_array, 3); - _mav_put_uint32_t_array(buf, 108, u32_array, 3); - _mav_put_int32_t_array(buf, 120, s32_array, 3); - _mav_put_float_array(buf, 132, f_array, 3); - _mav_put_uint16_t_array(buf, 148, u16_array, 3); - _mav_put_int16_t_array(buf, 154, s16_array, 3); - _mav_put_char_array(buf, 161, s, 10); - _mav_put_uint8_t_array(buf, 173, u8_array, 3); - _mav_put_int8_t_array(buf, 176, s8_array, 3); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TEST_TYPES, buf, 179, 103); -#else - mavlink_test_types_t packet; - packet.u64 = u64; - packet.s64 = s64; - packet.d = d; - packet.u32 = u32; - packet.s32 = s32; - packet.f = f; - packet.u16 = u16; - packet.s16 = s16; - packet.c = c; - packet.u8 = u8; - packet.s8 = s8; - mav_array_memcpy(packet.u64_array, u64_array, sizeof(uint64_t)*3); - mav_array_memcpy(packet.s64_array, s64_array, sizeof(int64_t)*3); - mav_array_memcpy(packet.d_array, d_array, sizeof(double)*3); - mav_array_memcpy(packet.u32_array, u32_array, sizeof(uint32_t)*3); - mav_array_memcpy(packet.s32_array, s32_array, sizeof(int32_t)*3); - mav_array_memcpy(packet.f_array, f_array, sizeof(float)*3); - mav_array_memcpy(packet.u16_array, u16_array, sizeof(uint16_t)*3); - mav_array_memcpy(packet.s16_array, s16_array, sizeof(int16_t)*3); - mav_array_memcpy(packet.s, s, sizeof(char)*10); - mav_array_memcpy(packet.u8_array, u8_array, sizeof(uint8_t)*3); - mav_array_memcpy(packet.s8_array, s8_array, sizeof(int8_t)*3); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_TEST_TYPES, (const char *)&packet, 179, 103); -#endif -} - -#endif - -// MESSAGE TEST_TYPES UNPACKING - - -/** - * @brief Get field c from test_types message - * - * @return char - */ -static inline char mavlink_msg_test_types_get_c(const mavlink_message_t* msg) -{ - return _MAV_RETURN_char(msg, 160); -} - -/** - * @brief Get field s from test_types message - * - * @return string - */ -static inline uint16_t mavlink_msg_test_types_get_s(const mavlink_message_t* msg, char *s) -{ - return _MAV_RETURN_char_array(msg, s, 10, 161); -} - -/** - * @brief Get field u8 from test_types message - * - * @return uint8_t - */ -static inline uint8_t mavlink_msg_test_types_get_u8(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 171); -} - -/** - * @brief Get field u16 from test_types message - * - * @return uint16_t - */ -static inline uint16_t mavlink_msg_test_types_get_u16(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint16_t(msg, 144); -} - -/** - * @brief Get field u32 from test_types message - * - * @return uint32_t - */ -static inline uint32_t mavlink_msg_test_types_get_u32(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint32_t(msg, 96); -} - -/** - * @brief Get field u64 from test_types message - * - * @return uint64_t - */ -static inline uint64_t mavlink_msg_test_types_get_u64(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field s8 from test_types message - * - * @return int8_t - */ -static inline int8_t mavlink_msg_test_types_get_s8(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int8_t(msg, 172); -} - -/** - * @brief Get field s16 from test_types message - * - * @return int16_t - */ -static inline int16_t mavlink_msg_test_types_get_s16(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int16_t(msg, 146); -} - -/** - * @brief Get field s32 from test_types message - * - * @return int32_t - */ -static inline int32_t mavlink_msg_test_types_get_s32(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int32_t(msg, 100); -} - -/** - * @brief Get field s64 from test_types message - * - * @return int64_t - */ -static inline int64_t mavlink_msg_test_types_get_s64(const mavlink_message_t* msg) -{ - return _MAV_RETURN_int64_t(msg, 8); -} - -/** - * @brief Get field f from test_types message - * - * @return float - */ -static inline float mavlink_msg_test_types_get_f(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 104); -} - -/** - * @brief Get field d from test_types message - * - * @return double - */ -static inline double mavlink_msg_test_types_get_d(const mavlink_message_t* msg) -{ - return _MAV_RETURN_double(msg, 16); -} - -/** - * @brief Get field u8_array from test_types message - * - * @return uint8_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u8_array(const mavlink_message_t* msg, uint8_t *u8_array) -{ - return _MAV_RETURN_uint8_t_array(msg, u8_array, 3, 173); -} - -/** - * @brief Get field u16_array from test_types message - * - * @return uint16_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u16_array(const mavlink_message_t* msg, uint16_t *u16_array) -{ - return _MAV_RETURN_uint16_t_array(msg, u16_array, 3, 148); -} - -/** - * @brief Get field u32_array from test_types message - * - * @return uint32_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u32_array(const mavlink_message_t* msg, uint32_t *u32_array) -{ - return _MAV_RETURN_uint32_t_array(msg, u32_array, 3, 108); -} - -/** - * @brief Get field u64_array from test_types message - * - * @return uint64_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_u64_array(const mavlink_message_t* msg, uint64_t *u64_array) -{ - return _MAV_RETURN_uint64_t_array(msg, u64_array, 3, 24); -} - -/** - * @brief Get field s8_array from test_types message - * - * @return int8_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s8_array(const mavlink_message_t* msg, int8_t *s8_array) -{ - return _MAV_RETURN_int8_t_array(msg, s8_array, 3, 176); -} - -/** - * @brief Get field s16_array from test_types message - * - * @return int16_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s16_array(const mavlink_message_t* msg, int16_t *s16_array) -{ - return _MAV_RETURN_int16_t_array(msg, s16_array, 3, 154); -} - -/** - * @brief Get field s32_array from test_types message - * - * @return int32_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s32_array(const mavlink_message_t* msg, int32_t *s32_array) -{ - return _MAV_RETURN_int32_t_array(msg, s32_array, 3, 120); -} - -/** - * @brief Get field s64_array from test_types message - * - * @return int64_t_array - */ -static inline uint16_t mavlink_msg_test_types_get_s64_array(const mavlink_message_t* msg, int64_t *s64_array) -{ - return _MAV_RETURN_int64_t_array(msg, s64_array, 3, 48); -} - -/** - * @brief Get field f_array from test_types message - * - * @return float_array - */ -static inline uint16_t mavlink_msg_test_types_get_f_array(const mavlink_message_t* msg, float *f_array) -{ - return _MAV_RETURN_float_array(msg, f_array, 3, 132); -} - -/** - * @brief Get field d_array from test_types message - * - * @return double_array - */ -static inline uint16_t mavlink_msg_test_types_get_d_array(const mavlink_message_t* msg, double *d_array) -{ - return _MAV_RETURN_double_array(msg, d_array, 3, 72); -} - -/** - * @brief Decode a test_types message into a struct - * - * @param msg The message to decode - * @param test_types C-struct to decode the message contents into - */ -static inline void mavlink_msg_test_types_decode(const mavlink_message_t* msg, mavlink_test_types_t* test_types) -{ -#if MAVLINK_NEED_BYTE_SWAP - test_types->u64 = mavlink_msg_test_types_get_u64(msg); - test_types->s64 = mavlink_msg_test_types_get_s64(msg); - test_types->d = mavlink_msg_test_types_get_d(msg); - mavlink_msg_test_types_get_u64_array(msg, test_types->u64_array); - mavlink_msg_test_types_get_s64_array(msg, test_types->s64_array); - mavlink_msg_test_types_get_d_array(msg, test_types->d_array); - test_types->u32 = mavlink_msg_test_types_get_u32(msg); - test_types->s32 = mavlink_msg_test_types_get_s32(msg); - test_types->f = mavlink_msg_test_types_get_f(msg); - mavlink_msg_test_types_get_u32_array(msg, test_types->u32_array); - mavlink_msg_test_types_get_s32_array(msg, test_types->s32_array); - mavlink_msg_test_types_get_f_array(msg, test_types->f_array); - test_types->u16 = mavlink_msg_test_types_get_u16(msg); - test_types->s16 = mavlink_msg_test_types_get_s16(msg); - mavlink_msg_test_types_get_u16_array(msg, test_types->u16_array); - mavlink_msg_test_types_get_s16_array(msg, test_types->s16_array); - test_types->c = mavlink_msg_test_types_get_c(msg); - mavlink_msg_test_types_get_s(msg, test_types->s); - test_types->u8 = mavlink_msg_test_types_get_u8(msg); - test_types->s8 = mavlink_msg_test_types_get_s8(msg); - mavlink_msg_test_types_get_u8_array(msg, test_types->u8_array); - mavlink_msg_test_types_get_s8_array(msg, test_types->s8_array); -#else - memcpy(test_types, _MAV_PAYLOAD(msg), 179); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/test/test.h b/mavlink/include/mavlink/v1.0/test/test.h deleted file mode 100644 index ff552d5149..0000000000 --- a/mavlink/include/mavlink/v1.0/test/test.h +++ /dev/null @@ -1,53 +0,0 @@ -/** @file - * @brief MAVLink comm protocol generated from test.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef TEST_H -#define TEST_H - -#ifdef __cplusplus -extern "C" { -#endif - -// MESSAGE LENGTHS AND CRCS - -#ifndef MAVLINK_MESSAGE_LENGTHS -#define MAVLINK_MESSAGE_LENGTHS {179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_CRCS -#define MAVLINK_MESSAGE_CRCS {103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#endif - -#ifndef MAVLINK_MESSAGE_INFO -#define MAVLINK_MESSAGE_INFO {MAVLINK_MESSAGE_INFO_TEST_TYPES, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}, {"EMPTY",0,{{"","",MAVLINK_TYPE_CHAR,0,0,0}}}} -#endif - -#include "../protocol.h" - -#define MAVLINK_ENABLED_TEST - - - -// MAVLINK VERSION - -#ifndef MAVLINK_VERSION -#define MAVLINK_VERSION 3 -#endif - -#if (MAVLINK_VERSION == 0) -#undef MAVLINK_VERSION -#define MAVLINK_VERSION 3 -#endif - -// ENUM DEFINITIONS - - - -// MESSAGE DEFINITIONS -#include "./mavlink_msg_test_types.h" - -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // TEST_H diff --git a/mavlink/include/mavlink/v1.0/test/testsuite.h b/mavlink/include/mavlink/v1.0/test/testsuite.h deleted file mode 100644 index 658e1ae071..0000000000 --- a/mavlink/include/mavlink/v1.0/test/testsuite.h +++ /dev/null @@ -1,120 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from test.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef TEST_TESTSUITE_H -#define TEST_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL - -static void mavlink_test_test(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - - mavlink_test_test(system_id, component_id, last_msg); -} -#endif - - - - -static void mavlink_test_test_types(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_test_types_t packet_in = { - 93372036854775807ULL, - 93372036854776311LL, - 235.0, - { 93372036854777319, 93372036854777320, 93372036854777321 }, - { 93372036854778831, 93372036854778832, 93372036854778833 }, - { 627.0, 628.0, 629.0 }, - 963502456, - 963502664, - 745.0, - { 963503080, 963503081, 963503082 }, - { 963503704, 963503705, 963503706 }, - { 941.0, 942.0, 943.0 }, - 24723, - 24827, - { 24931, 24932, 24933 }, - { 25243, 25244, 25245 }, - 'E', - "FGHIJKLMN", - 198, - 9, - { 76, 77, 78 }, - { 21, 22, 23 }, - }; - mavlink_test_types_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.u64 = packet_in.u64; - packet1.s64 = packet_in.s64; - packet1.d = packet_in.d; - packet1.u32 = packet_in.u32; - packet1.s32 = packet_in.s32; - packet1.f = packet_in.f; - packet1.u16 = packet_in.u16; - packet1.s16 = packet_in.s16; - packet1.c = packet_in.c; - packet1.u8 = packet_in.u8; - packet1.s8 = packet_in.s8; - - mav_array_memcpy(packet1.u64_array, packet_in.u64_array, sizeof(uint64_t)*3); - mav_array_memcpy(packet1.s64_array, packet_in.s64_array, sizeof(int64_t)*3); - mav_array_memcpy(packet1.d_array, packet_in.d_array, sizeof(double)*3); - mav_array_memcpy(packet1.u32_array, packet_in.u32_array, sizeof(uint32_t)*3); - mav_array_memcpy(packet1.s32_array, packet_in.s32_array, sizeof(int32_t)*3); - mav_array_memcpy(packet1.f_array, packet_in.f_array, sizeof(float)*3); - mav_array_memcpy(packet1.u16_array, packet_in.u16_array, sizeof(uint16_t)*3); - mav_array_memcpy(packet1.s16_array, packet_in.s16_array, sizeof(int16_t)*3); - mav_array_memcpy(packet1.s, packet_in.s, sizeof(char)*10); - mav_array_memcpy(packet1.u8_array, packet_in.u8_array, sizeof(uint8_t)*3); - mav_array_memcpy(packet1.s8_array, packet_in.s8_array, sizeof(int8_t)*3); - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_test_types_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_test_types_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_test_types_pack(system_id, component_id, &msg , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array ); - mavlink_msg_test_types_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_test_types_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array ); - mavlink_msg_test_types_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; imsgid = MAVLINK_MSG_ID_NAV_FILTER_BIAS; - return mavlink_finalize_message(msg, system_id, component_id, 32, 34); -} - -/** - * @brief Pack a nav_filter_bias message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param usec Timestamp (microseconds) - * @param accel_0 b_f[0] - * @param accel_1 b_f[1] - * @param accel_2 b_f[2] - * @param gyro_0 b_f[0] - * @param gyro_1 b_f[1] - * @param gyro_2 b_f[2] - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_nav_filter_bias_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint64_t usec,float accel_0,float accel_1,float accel_2,float gyro_0,float gyro_1,float gyro_2) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, accel_0); - _mav_put_float(buf, 12, accel_1); - _mav_put_float(buf, 16, accel_2); - _mav_put_float(buf, 20, gyro_0); - _mav_put_float(buf, 24, gyro_1); - _mav_put_float(buf, 28, gyro_2); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 32); -#else - mavlink_nav_filter_bias_t packet; - packet.usec = usec; - packet.accel_0 = accel_0; - packet.accel_1 = accel_1; - packet.accel_2 = accel_2; - packet.gyro_0 = gyro_0; - packet.gyro_1 = gyro_1; - packet.gyro_2 = gyro_2; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 32); -#endif - - msg->msgid = MAVLINK_MSG_ID_NAV_FILTER_BIAS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 32, 34); -} - -/** - * @brief Encode a nav_filter_bias struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param nav_filter_bias C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_nav_filter_bias_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_nav_filter_bias_t* nav_filter_bias) -{ - return mavlink_msg_nav_filter_bias_pack(system_id, component_id, msg, nav_filter_bias->usec, nav_filter_bias->accel_0, nav_filter_bias->accel_1, nav_filter_bias->accel_2, nav_filter_bias->gyro_0, nav_filter_bias->gyro_1, nav_filter_bias->gyro_2); -} - -/** - * @brief Send a nav_filter_bias message - * @param chan MAVLink channel to send the message - * - * @param usec Timestamp (microseconds) - * @param accel_0 b_f[0] - * @param accel_1 b_f[1] - * @param accel_2 b_f[2] - * @param gyro_0 b_f[0] - * @param gyro_1 b_f[1] - * @param gyro_2 b_f[2] - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_nav_filter_bias_send(mavlink_channel_t chan, uint64_t usec, float accel_0, float accel_1, float accel_2, float gyro_0, float gyro_1, float gyro_2) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[32]; - _mav_put_uint64_t(buf, 0, usec); - _mav_put_float(buf, 8, accel_0); - _mav_put_float(buf, 12, accel_1); - _mav_put_float(buf, 16, accel_2); - _mav_put_float(buf, 20, gyro_0); - _mav_put_float(buf, 24, gyro_1); - _mav_put_float(buf, 28, gyro_2); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAV_FILTER_BIAS, buf, 32, 34); -#else - mavlink_nav_filter_bias_t packet; - packet.usec = usec; - packet.accel_0 = accel_0; - packet.accel_1 = accel_1; - packet.accel_2 = accel_2; - packet.gyro_0 = gyro_0; - packet.gyro_1 = gyro_1; - packet.gyro_2 = gyro_2; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_NAV_FILTER_BIAS, (const char *)&packet, 32, 34); -#endif -} - -#endif - -// MESSAGE NAV_FILTER_BIAS UNPACKING - - -/** - * @brief Get field usec from nav_filter_bias message - * - * @return Timestamp (microseconds) - */ -static inline uint64_t mavlink_msg_nav_filter_bias_get_usec(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint64_t(msg, 0); -} - -/** - * @brief Get field accel_0 from nav_filter_bias message - * - * @return b_f[0] - */ -static inline float mavlink_msg_nav_filter_bias_get_accel_0(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 8); -} - -/** - * @brief Get field accel_1 from nav_filter_bias message - * - * @return b_f[1] - */ -static inline float mavlink_msg_nav_filter_bias_get_accel_1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 12); -} - -/** - * @brief Get field accel_2 from nav_filter_bias message - * - * @return b_f[2] - */ -static inline float mavlink_msg_nav_filter_bias_get_accel_2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 16); -} - -/** - * @brief Get field gyro_0 from nav_filter_bias message - * - * @return b_f[0] - */ -static inline float mavlink_msg_nav_filter_bias_get_gyro_0(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 20); -} - -/** - * @brief Get field gyro_1 from nav_filter_bias message - * - * @return b_f[1] - */ -static inline float mavlink_msg_nav_filter_bias_get_gyro_1(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 24); -} - -/** - * @brief Get field gyro_2 from nav_filter_bias message - * - * @return b_f[2] - */ -static inline float mavlink_msg_nav_filter_bias_get_gyro_2(const mavlink_message_t* msg) -{ - return _MAV_RETURN_float(msg, 28); -} - -/** - * @brief Decode a nav_filter_bias message into a struct - * - * @param msg The message to decode - * @param nav_filter_bias C-struct to decode the message contents into - */ -static inline void mavlink_msg_nav_filter_bias_decode(const mavlink_message_t* msg, mavlink_nav_filter_bias_t* nav_filter_bias) -{ -#if MAVLINK_NEED_BYTE_SWAP - nav_filter_bias->usec = mavlink_msg_nav_filter_bias_get_usec(msg); - nav_filter_bias->accel_0 = mavlink_msg_nav_filter_bias_get_accel_0(msg); - nav_filter_bias->accel_1 = mavlink_msg_nav_filter_bias_get_accel_1(msg); - nav_filter_bias->accel_2 = mavlink_msg_nav_filter_bias_get_accel_2(msg); - nav_filter_bias->gyro_0 = mavlink_msg_nav_filter_bias_get_gyro_0(msg); - nav_filter_bias->gyro_1 = mavlink_msg_nav_filter_bias_get_gyro_1(msg); - nav_filter_bias->gyro_2 = mavlink_msg_nav_filter_bias_get_gyro_2(msg); -#else - memcpy(nav_filter_bias, _MAV_PAYLOAD(msg), 32); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/ualberta/mavlink_msg_radio_calibration.h b/mavlink/include/mavlink/v1.0/ualberta/mavlink_msg_radio_calibration.h deleted file mode 100644 index 7227036788..0000000000 --- a/mavlink/include/mavlink/v1.0/ualberta/mavlink_msg_radio_calibration.h +++ /dev/null @@ -1,259 +0,0 @@ -// MESSAGE RADIO_CALIBRATION PACKING - -#define MAVLINK_MSG_ID_RADIO_CALIBRATION 221 - -typedef struct __mavlink_radio_calibration_t -{ - uint16_t aileron[3]; ///< Aileron setpoints: left, center, right - uint16_t elevator[3]; ///< Elevator setpoints: nose down, center, nose up - uint16_t rudder[3]; ///< Rudder setpoints: nose left, center, nose right - uint16_t gyro[2]; ///< Tail gyro mode/gain setpoints: heading hold, rate mode - uint16_t pitch[5]; ///< Pitch curve setpoints (every 25%) - uint16_t throttle[5]; ///< Throttle curve setpoints (every 25%) -} mavlink_radio_calibration_t; - -#define MAVLINK_MSG_ID_RADIO_CALIBRATION_LEN 42 -#define MAVLINK_MSG_ID_221_LEN 42 - -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_AILERON_LEN 3 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_ELEVATOR_LEN 3 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_RUDDER_LEN 3 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_GYRO_LEN 2 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_PITCH_LEN 5 -#define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_THROTTLE_LEN 5 - -#define MAVLINK_MESSAGE_INFO_RADIO_CALIBRATION { \ - "RADIO_CALIBRATION", \ - 6, \ - { { "aileron", NULL, MAVLINK_TYPE_UINT16_T, 3, 0, offsetof(mavlink_radio_calibration_t, aileron) }, \ - { "elevator", NULL, MAVLINK_TYPE_UINT16_T, 3, 6, offsetof(mavlink_radio_calibration_t, elevator) }, \ - { "rudder", NULL, MAVLINK_TYPE_UINT16_T, 3, 12, offsetof(mavlink_radio_calibration_t, rudder) }, \ - { "gyro", NULL, MAVLINK_TYPE_UINT16_T, 2, 18, offsetof(mavlink_radio_calibration_t, gyro) }, \ - { "pitch", NULL, MAVLINK_TYPE_UINT16_T, 5, 22, offsetof(mavlink_radio_calibration_t, pitch) }, \ - { "throttle", NULL, MAVLINK_TYPE_UINT16_T, 5, 32, offsetof(mavlink_radio_calibration_t, throttle) }, \ - } \ -} - - -/** - * @brief Pack a radio_calibration message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param aileron Aileron setpoints: left, center, right - * @param elevator Elevator setpoints: nose down, center, nose up - * @param rudder Rudder setpoints: nose left, center, nose right - * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode - * @param pitch Pitch curve setpoints (every 25%) - * @param throttle Throttle curve setpoints (every 25%) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_radio_calibration_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - const uint16_t *aileron, const uint16_t *elevator, const uint16_t *rudder, const uint16_t *gyro, const uint16_t *pitch, const uint16_t *throttle) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - - _mav_put_uint16_t_array(buf, 0, aileron, 3); - _mav_put_uint16_t_array(buf, 6, elevator, 3); - _mav_put_uint16_t_array(buf, 12, rudder, 3); - _mav_put_uint16_t_array(buf, 18, gyro, 2); - _mav_put_uint16_t_array(buf, 22, pitch, 5); - _mav_put_uint16_t_array(buf, 32, throttle, 5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 42); -#else - mavlink_radio_calibration_t packet; - - mav_array_memcpy(packet.aileron, aileron, sizeof(uint16_t)*3); - mav_array_memcpy(packet.elevator, elevator, sizeof(uint16_t)*3); - mav_array_memcpy(packet.rudder, rudder, sizeof(uint16_t)*3); - mav_array_memcpy(packet.gyro, gyro, sizeof(uint16_t)*2); - mav_array_memcpy(packet.pitch, pitch, sizeof(uint16_t)*5); - mav_array_memcpy(packet.throttle, throttle, sizeof(uint16_t)*5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 42); -#endif - - msg->msgid = MAVLINK_MSG_ID_RADIO_CALIBRATION; - return mavlink_finalize_message(msg, system_id, component_id, 42, 71); -} - -/** - * @brief Pack a radio_calibration message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param aileron Aileron setpoints: left, center, right - * @param elevator Elevator setpoints: nose down, center, nose up - * @param rudder Rudder setpoints: nose left, center, nose right - * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode - * @param pitch Pitch curve setpoints (every 25%) - * @param throttle Throttle curve setpoints (every 25%) - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_radio_calibration_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - const uint16_t *aileron,const uint16_t *elevator,const uint16_t *rudder,const uint16_t *gyro,const uint16_t *pitch,const uint16_t *throttle) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - - _mav_put_uint16_t_array(buf, 0, aileron, 3); - _mav_put_uint16_t_array(buf, 6, elevator, 3); - _mav_put_uint16_t_array(buf, 12, rudder, 3); - _mav_put_uint16_t_array(buf, 18, gyro, 2); - _mav_put_uint16_t_array(buf, 22, pitch, 5); - _mav_put_uint16_t_array(buf, 32, throttle, 5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 42); -#else - mavlink_radio_calibration_t packet; - - mav_array_memcpy(packet.aileron, aileron, sizeof(uint16_t)*3); - mav_array_memcpy(packet.elevator, elevator, sizeof(uint16_t)*3); - mav_array_memcpy(packet.rudder, rudder, sizeof(uint16_t)*3); - mav_array_memcpy(packet.gyro, gyro, sizeof(uint16_t)*2); - mav_array_memcpy(packet.pitch, pitch, sizeof(uint16_t)*5); - mav_array_memcpy(packet.throttle, throttle, sizeof(uint16_t)*5); - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 42); -#endif - - msg->msgid = MAVLINK_MSG_ID_RADIO_CALIBRATION; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 42, 71); -} - -/** - * @brief Encode a radio_calibration struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param radio_calibration C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_radio_calibration_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_radio_calibration_t* radio_calibration) -{ - return mavlink_msg_radio_calibration_pack(system_id, component_id, msg, radio_calibration->aileron, radio_calibration->elevator, radio_calibration->rudder, radio_calibration->gyro, radio_calibration->pitch, radio_calibration->throttle); -} - -/** - * @brief Send a radio_calibration message - * @param chan MAVLink channel to send the message - * - * @param aileron Aileron setpoints: left, center, right - * @param elevator Elevator setpoints: nose down, center, nose up - * @param rudder Rudder setpoints: nose left, center, nose right - * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode - * @param pitch Pitch curve setpoints (every 25%) - * @param throttle Throttle curve setpoints (every 25%) - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_radio_calibration_send(mavlink_channel_t chan, const uint16_t *aileron, const uint16_t *elevator, const uint16_t *rudder, const uint16_t *gyro, const uint16_t *pitch, const uint16_t *throttle) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[42]; - - _mav_put_uint16_t_array(buf, 0, aileron, 3); - _mav_put_uint16_t_array(buf, 6, elevator, 3); - _mav_put_uint16_t_array(buf, 12, rudder, 3); - _mav_put_uint16_t_array(buf, 18, gyro, 2); - _mav_put_uint16_t_array(buf, 22, pitch, 5); - _mav_put_uint16_t_array(buf, 32, throttle, 5); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RADIO_CALIBRATION, buf, 42, 71); -#else - mavlink_radio_calibration_t packet; - - mav_array_memcpy(packet.aileron, aileron, sizeof(uint16_t)*3); - mav_array_memcpy(packet.elevator, elevator, sizeof(uint16_t)*3); - mav_array_memcpy(packet.rudder, rudder, sizeof(uint16_t)*3); - mav_array_memcpy(packet.gyro, gyro, sizeof(uint16_t)*2); - mav_array_memcpy(packet.pitch, pitch, sizeof(uint16_t)*5); - mav_array_memcpy(packet.throttle, throttle, sizeof(uint16_t)*5); - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_RADIO_CALIBRATION, (const char *)&packet, 42, 71); -#endif -} - -#endif - -// MESSAGE RADIO_CALIBRATION UNPACKING - - -/** - * @brief Get field aileron from radio_calibration message - * - * @return Aileron setpoints: left, center, right - */ -static inline uint16_t mavlink_msg_radio_calibration_get_aileron(const mavlink_message_t* msg, uint16_t *aileron) -{ - return _MAV_RETURN_uint16_t_array(msg, aileron, 3, 0); -} - -/** - * @brief Get field elevator from radio_calibration message - * - * @return Elevator setpoints: nose down, center, nose up - */ -static inline uint16_t mavlink_msg_radio_calibration_get_elevator(const mavlink_message_t* msg, uint16_t *elevator) -{ - return _MAV_RETURN_uint16_t_array(msg, elevator, 3, 6); -} - -/** - * @brief Get field rudder from radio_calibration message - * - * @return Rudder setpoints: nose left, center, nose right - */ -static inline uint16_t mavlink_msg_radio_calibration_get_rudder(const mavlink_message_t* msg, uint16_t *rudder) -{ - return _MAV_RETURN_uint16_t_array(msg, rudder, 3, 12); -} - -/** - * @brief Get field gyro from radio_calibration message - * - * @return Tail gyro mode/gain setpoints: heading hold, rate mode - */ -static inline uint16_t mavlink_msg_radio_calibration_get_gyro(const mavlink_message_t* msg, uint16_t *gyro) -{ - return _MAV_RETURN_uint16_t_array(msg, gyro, 2, 18); -} - -/** - * @brief Get field pitch from radio_calibration message - * - * @return Pitch curve setpoints (every 25%) - */ -static inline uint16_t mavlink_msg_radio_calibration_get_pitch(const mavlink_message_t* msg, uint16_t *pitch) -{ - return _MAV_RETURN_uint16_t_array(msg, pitch, 5, 22); -} - -/** - * @brief Get field throttle from radio_calibration message - * - * @return Throttle curve setpoints (every 25%) - */ -static inline uint16_t mavlink_msg_radio_calibration_get_throttle(const mavlink_message_t* msg, uint16_t *throttle) -{ - return _MAV_RETURN_uint16_t_array(msg, throttle, 5, 32); -} - -/** - * @brief Decode a radio_calibration message into a struct - * - * @param msg The message to decode - * @param radio_calibration C-struct to decode the message contents into - */ -static inline void mavlink_msg_radio_calibration_decode(const mavlink_message_t* msg, mavlink_radio_calibration_t* radio_calibration) -{ -#if MAVLINK_NEED_BYTE_SWAP - mavlink_msg_radio_calibration_get_aileron(msg, radio_calibration->aileron); - mavlink_msg_radio_calibration_get_elevator(msg, radio_calibration->elevator); - mavlink_msg_radio_calibration_get_rudder(msg, radio_calibration->rudder); - mavlink_msg_radio_calibration_get_gyro(msg, radio_calibration->gyro); - mavlink_msg_radio_calibration_get_pitch(msg, radio_calibration->pitch); - mavlink_msg_radio_calibration_get_throttle(msg, radio_calibration->throttle); -#else - memcpy(radio_calibration, _MAV_PAYLOAD(msg), 42); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/ualberta/mavlink_msg_ualberta_sys_status.h b/mavlink/include/mavlink/v1.0/ualberta/mavlink_msg_ualberta_sys_status.h deleted file mode 100644 index 176469d25a..0000000000 --- a/mavlink/include/mavlink/v1.0/ualberta/mavlink_msg_ualberta_sys_status.h +++ /dev/null @@ -1,188 +0,0 @@ -// MESSAGE UALBERTA_SYS_STATUS PACKING - -#define MAVLINK_MSG_ID_UALBERTA_SYS_STATUS 222 - -typedef struct __mavlink_ualberta_sys_status_t -{ - uint8_t mode; ///< System mode, see UALBERTA_AUTOPILOT_MODE ENUM - uint8_t nav_mode; ///< Navigation mode, see UALBERTA_NAV_MODE ENUM - uint8_t pilot; ///< Pilot mode, see UALBERTA_PILOT_MODE -} mavlink_ualberta_sys_status_t; - -#define MAVLINK_MSG_ID_UALBERTA_SYS_STATUS_LEN 3 -#define MAVLINK_MSG_ID_222_LEN 3 - - - -#define MAVLINK_MESSAGE_INFO_UALBERTA_SYS_STATUS { \ - "UALBERTA_SYS_STATUS", \ - 3, \ - { { "mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 0, offsetof(mavlink_ualberta_sys_status_t, mode) }, \ - { "nav_mode", NULL, MAVLINK_TYPE_UINT8_T, 0, 1, offsetof(mavlink_ualberta_sys_status_t, nav_mode) }, \ - { "pilot", NULL, MAVLINK_TYPE_UINT8_T, 0, 2, offsetof(mavlink_ualberta_sys_status_t, pilot) }, \ - } \ -} - - -/** - * @brief Pack a ualberta_sys_status message - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * - * @param mode System mode, see UALBERTA_AUTOPILOT_MODE ENUM - * @param nav_mode Navigation mode, see UALBERTA_NAV_MODE ENUM - * @param pilot Pilot mode, see UALBERTA_PILOT_MODE - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ualberta_sys_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, - uint8_t mode, uint8_t nav_mode, uint8_t pilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, pilot); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ualberta_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.pilot = pilot; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_UALBERTA_SYS_STATUS; - return mavlink_finalize_message(msg, system_id, component_id, 3, 15); -} - -/** - * @brief Pack a ualberta_sys_status message on a channel - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param chan The MAVLink channel this message was sent over - * @param msg The MAVLink message to compress the data into - * @param mode System mode, see UALBERTA_AUTOPILOT_MODE ENUM - * @param nav_mode Navigation mode, see UALBERTA_NAV_MODE ENUM - * @param pilot Pilot mode, see UALBERTA_PILOT_MODE - * @return length of the message in bytes (excluding serial stream start sign) - */ -static inline uint16_t mavlink_msg_ualberta_sys_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, - mavlink_message_t* msg, - uint8_t mode,uint8_t nav_mode,uint8_t pilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, pilot); - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, 3); -#else - mavlink_ualberta_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.pilot = pilot; - - memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, 3); -#endif - - msg->msgid = MAVLINK_MSG_ID_UALBERTA_SYS_STATUS; - return mavlink_finalize_message_chan(msg, system_id, component_id, chan, 3, 15); -} - -/** - * @brief Encode a ualberta_sys_status struct into a message - * - * @param system_id ID of this system - * @param component_id ID of this component (e.g. 200 for IMU) - * @param msg The MAVLink message to compress the data into - * @param ualberta_sys_status C-struct to read the message contents from - */ -static inline uint16_t mavlink_msg_ualberta_sys_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_ualberta_sys_status_t* ualberta_sys_status) -{ - return mavlink_msg_ualberta_sys_status_pack(system_id, component_id, msg, ualberta_sys_status->mode, ualberta_sys_status->nav_mode, ualberta_sys_status->pilot); -} - -/** - * @brief Send a ualberta_sys_status message - * @param chan MAVLink channel to send the message - * - * @param mode System mode, see UALBERTA_AUTOPILOT_MODE ENUM - * @param nav_mode Navigation mode, see UALBERTA_NAV_MODE ENUM - * @param pilot Pilot mode, see UALBERTA_PILOT_MODE - */ -#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS - -static inline void mavlink_msg_ualberta_sys_status_send(mavlink_channel_t chan, uint8_t mode, uint8_t nav_mode, uint8_t pilot) -{ -#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS - char buf[3]; - _mav_put_uint8_t(buf, 0, mode); - _mav_put_uint8_t(buf, 1, nav_mode); - _mav_put_uint8_t(buf, 2, pilot); - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_UALBERTA_SYS_STATUS, buf, 3, 15); -#else - mavlink_ualberta_sys_status_t packet; - packet.mode = mode; - packet.nav_mode = nav_mode; - packet.pilot = pilot; - - _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_UALBERTA_SYS_STATUS, (const char *)&packet, 3, 15); -#endif -} - -#endif - -// MESSAGE UALBERTA_SYS_STATUS UNPACKING - - -/** - * @brief Get field mode from ualberta_sys_status message - * - * @return System mode, see UALBERTA_AUTOPILOT_MODE ENUM - */ -static inline uint8_t mavlink_msg_ualberta_sys_status_get_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 0); -} - -/** - * @brief Get field nav_mode from ualberta_sys_status message - * - * @return Navigation mode, see UALBERTA_NAV_MODE ENUM - */ -static inline uint8_t mavlink_msg_ualberta_sys_status_get_nav_mode(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 1); -} - -/** - * @brief Get field pilot from ualberta_sys_status message - * - * @return Pilot mode, see UALBERTA_PILOT_MODE - */ -static inline uint8_t mavlink_msg_ualberta_sys_status_get_pilot(const mavlink_message_t* msg) -{ - return _MAV_RETURN_uint8_t(msg, 2); -} - -/** - * @brief Decode a ualberta_sys_status message into a struct - * - * @param msg The message to decode - * @param ualberta_sys_status C-struct to decode the message contents into - */ -static inline void mavlink_msg_ualberta_sys_status_decode(const mavlink_message_t* msg, mavlink_ualberta_sys_status_t* ualberta_sys_status) -{ -#if MAVLINK_NEED_BYTE_SWAP - ualberta_sys_status->mode = mavlink_msg_ualberta_sys_status_get_mode(msg); - ualberta_sys_status->nav_mode = mavlink_msg_ualberta_sys_status_get_nav_mode(msg); - ualberta_sys_status->pilot = mavlink_msg_ualberta_sys_status_get_pilot(msg); -#else - memcpy(ualberta_sys_status, _MAV_PAYLOAD(msg), 3); -#endif -} diff --git a/mavlink/include/mavlink/v1.0/ualberta/testsuite.h b/mavlink/include/mavlink/v1.0/ualberta/testsuite.h deleted file mode 100644 index 79a6a004a4..0000000000 --- a/mavlink/include/mavlink/v1.0/ualberta/testsuite.h +++ /dev/null @@ -1,192 +0,0 @@ -/** @file - * @brief MAVLink comm protocol testsuite generated from ualberta.xml - * @see http://qgroundcontrol.org/mavlink/ - */ -#ifndef UALBERTA_TESTSUITE_H -#define UALBERTA_TESTSUITE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MAVLINK_TEST_ALL -#define MAVLINK_TEST_ALL -static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg); -static void mavlink_test_ualberta(uint8_t, uint8_t, mavlink_message_t *last_msg); - -static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_test_common(system_id, component_id, last_msg); - mavlink_test_ualberta(system_id, component_id, last_msg); -} -#endif - -#include "../common/testsuite.h" - - -static void mavlink_test_nav_filter_bias(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg) -{ - mavlink_message_t msg; - uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; - uint16_t i; - mavlink_nav_filter_bias_t packet_in = { - 93372036854775807ULL, - 73.0, - 101.0, - 129.0, - 157.0, - 185.0, - 213.0, - }; - mavlink_nav_filter_bias_t packet1, packet2; - memset(&packet1, 0, sizeof(packet1)); - packet1.usec = packet_in.usec; - packet1.accel_0 = packet_in.accel_0; - packet1.accel_1 = packet_in.accel_1; - packet1.accel_2 = packet_in.accel_2; - packet1.gyro_0 = packet_in.gyro_0; - packet1.gyro_1 = packet_in.gyro_1; - packet1.gyro_2 = packet_in.gyro_2; - - - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_nav_filter_bias_encode(system_id, component_id, &msg, &packet1); - mavlink_msg_nav_filter_bias_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_nav_filter_bias_pack(system_id, component_id, &msg , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 ); - mavlink_msg_nav_filter_bias_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_nav_filter_bias_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 ); - mavlink_msg_nav_filter_bias_decode(&msg, &packet2); - MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0); - - memset(&packet2, 0, sizeof(packet2)); - mavlink_msg_to_send_buffer(buffer, &msg); - for (i=0; i - - - - Debug - Win32 - - - Release - Win32 - - - - {02C30EBC-DF41-4C36-B2F3-79BED7E6EF9F} - Win32Proj - testmav - - - - Application - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - E:\pymavlink\generator\C\include_v1.0 - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mavlink/share/pyshared/pymavlink/tools/mavplayback.py b/mavlink/share/pyshared/pymavlink/tools/mavplayback.py index 50a6fd45dd..033746697f 100644 --- a/mavlink/share/pyshared/pymavlink/tools/mavplayback.py +++ b/mavlink/share/pyshared/pymavlink/tools/mavplayback.py @@ -43,7 +43,7 @@ filename = args[0] def LoadImage(filename): '''return an image from the images/ directory''' app_dir = os.path.dirname(os.path.realpath(__file__)) - path = os.path.join(app_dir, 'images', filename) + path = os.path.join(app_dir, 'files/images', filename) return Tkinter.PhotoImage(file=path) diff --git a/nuttx/COPYING b/nuttx/COPYING index 82d3a8a58a..863b81a2fc 100644 --- a/nuttx/COPYING +++ b/nuttx/COPYING @@ -71,7 +71,12 @@ FAT Long File Names FAT implementations that include support for long filenames, and that removable solid state media and consumer devices only using short names would be unaffected. ..." - + + This Wikipedia entry has been updated with recent legal decisions in favor + of Microsoft. Refer to: + + http://en.wikipedia.org/wiki/File_Allocation_Table#Legal_issues + So you have been forewarned: Use the long filename at your own risk! uIP diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 48f1866c33..7ad830d890 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -1458,7 +1458,7 @@ * Renamed arc/hc/include/mc9s12ne64 and src/mc9s12ne64 to m9s12. That name is shorter and more general. * The NuttX repository has been converted to SVN and can now be found here - http://nuttx.svn.sourceforge.net/viewvc/nuttx/ + http://svn.code.sf.net/p/nuttx/code/trunk/ * configs/mbed/hidkbd: Added USB host support for the mbed LPC1768 board; add a USB host HID keyboard configuraion. * drivers/usbhost/hid_parser.c: Leverages the LUFA HID parser written by @@ -2280,7 +2280,7 @@ the particular condition that revealed the bug occurred. My impression is that this latter bugfix also fixes some STM32 USB performance problems. * configs/hymini-stm32v: A configuration for the HY-Mini STM32v board contributed - by Laurent Latil. Theses changes also include support for the STM32F103VCT6. + by Laurent Latil. These changes also include support for the STM32F103VCT6. * arch/configs/stm3240g-eval/src/up_pwm.c: Add hooks needed to use the new apps/examples/pwm test of the STM32 PWM driver. * drivers/mtd/mp25x.c: Add ability to use different SPI modes and different @@ -2977,7 +2977,7 @@ * configs/lpc4330-xplorer/nsh: Add an NSH configuration for the LPC4330 Xplorer board. -6.21 2012-xx-xx Gregory Nutt +6.21 2012-08-25 Gregory Nutt * configs/lpc4330-xplorer/up_nsh.c: Add support for a basic SPIFI block driver for use by NSH. Does not work! Crashes on first SPIFI write. @@ -3024,7 +3024,7 @@ but the driver still does not work. * arch/arm/src/stm32 and arch/arm/include/stm32: Make name of RTC ALARM interrupt common on STM32 F1,2,4 - * arch/arm/src/stm32 and arch/arm/include/stm32: Add add support for the + * arch/arm/src/stm32 and arch/arm/include/stm32: Add support for the STM32F100x "Value Line" devices. This includes changes to stm32F10xx_rcc.c that add the ability to run the chip off the internal oscillator. There is no open board configuration for this part yet (the STM32VLDiscovery would be a candidate). @@ -3050,7 +3050,7 @@ * include/termios.h and lib/termios/*: Redesigned yet again (this is getting painful. NuttX now supports the BOTHER baud setting just as Linux does. termios Bxxx definitions are again encoded; cf[set|get][o|i]speed now deal with only the - encoded values. If the encode baud is set to BOTHER, then the values in the (non- + encoded values. If the encoded baud is set to BOTHER, then the values in the (non- standard) c_ispeed and c_ospeed baud values may be accessed directly. * arch/arm/src/stm32/stm32_serial.c: Add minimal termios support for the STM32 (BOTHER style baud settings only). Contributed by Mike Smith. @@ -3063,8 +3063,7 @@ * arch/arm/src/stm32/stm32_sdio.c and chip/stm32f20xx_pinmap.h: STM32 F2 SDIO fixes from Gary Teravskis and Scott Rondestvedt. * include/termios.h and lib/termios/*: Replace cfsetispeed and cfsetospeed with - cfsetspeed (with definitions for the input/outputs in termios.h). Same for - cfgetispeed and cfgetospeed. + cfsetspeed (with definitions for the input/outputs in termios.h). * configs/stm32f4discovery/src and configs/stm32f4discovery/pm: Add a power management configuration for the STM32F4Discovery and supporting logic. This check-in also includes some fixes for the F4 RTC alarm logic. @@ -3090,10 +3089,10 @@ * arch/mips/src/pic32mx/pic32mx-gpio.c: Now supports the PIC32MX1/2 ANSEL IOPORT register. * lib/string/lib_memchr.c: Add support for memchr() (contributed by Mike Smith) - * lib/string/lib_memccpy.c: Add support for memcpy() + * lib/string/lib_memccpy.c: Add support for memccpy() * arch/arm/src/lpc17xx/lpc17_serial.c: Now supports ioctl commands to change the baud using tcsetattr() (contributed by Chris Taglia). - * arch/*/src/*_serial.c: Fix ioctl method return values. Theses methods + * arch/*/src/*_serial.c: Fix ioctl method return values. These methods should return a negated errno value; they should not set the errno variable. * sched/on_exit.c, sched/task_exithook.c, and include/nuttx/sched.c: Add @@ -3118,7 +3117,7 @@ * arch/arm/src/stm32/stm32*_rcc.c and .h: If CONFIG_PM is defined, add a function called stm32_clockenable() that can be used by PM logic to re-start the PLL after re-awakening from deep sleep modes. - * fs/fs_foreachinode.c and fs/fs_foreachmountpoint.c: All logic to traverse + * fs/fs_foreachinode.c and fs/fs_foreachmountpoint.c: Add logic to traverse inodes and mountpoints in the NuttX pseudo-file system. * fs/fat/fs_fat32.c: Max. filename length reported by statfs() was wrong if FAT long file names were enabled. @@ -3137,7 +3136,7 @@ LPC31xx has the same USB IP, but will require some additional initialization (and lots of testing) before it can be used with the LPC43xx. * nuttx/Documentation/NuttShell.html: Added a section covering ways to - customize the behavior or NSH. + customize the behavior of NSH. * arch/arm/src/stm32/chip/stm32f1*_pinmap.h: STM32 CAN TX/RX pins reversed; inconsistent conditional compilation. Reported by Max Holtzberg. * arch/arm/*/stm32: Add support for STM32 F107 "Connectivity Line" @@ -3166,5 +3165,215 @@ for all 8-bit AVR platforms (Thanks Richard Cochran). * lib/stdio/lib_*stream.c: Revised to handle new error return values from serial.c. - * arch/arm/src/stm32/stm32_spi.c: SPI driver can now survice re- + * arch/arm/src/stm32/stm32_spi.c: SPI driver can now service re- initialization (Mike Smith). + * tools/mkconfig.c: If CONFIG_DRAM_END is not specified, this tool + will provide default definition of (CONFIG_DRAM_START + CONFIG_DRAM_SIZE) + * arch/arm/src/stm32/stm32_otgfshost.c: Renamed from stm32_usbhost.c. + This is nearly code complete and, with any luck, will be available + in NuttX-6.21. + * configs/*/defconfig: Update all defconfig files to remove syntax + that is incompatible with the mconf configuration tool. + * arch/arm/src/stm32/stm32_otgfshost.c: This driver now appears to be + functional (although more testing is necesary). + +6.22 2012-xx-xx Gregory Nutt + + * include/semaphore.h, sched/sem_holders.c, and lib/semaphore/sem_init.c: + Fix some strange (and probably wrong) list handling when + CONFIG_PRIORITY_INHERITANCE and CONFIG_SEM_PREALLOCHOLDERS are defined. + This list handling was probably causing errors reported by Mike Smith + * sched/sched_waitpid.c: Fix a possible issue with logic logic that + should be brought into a critical section (suggested by Mike Smith) + * sched/sched_setuptaskfiles.c: Should be 'struct socket' not + 'struct sockets'. How did this compile before? (found by Kate) + * syscall/syscall.csv: Fix prototype for usleep() and prctl() (also + from Kate). + * arch/arm/src/lpc17xx/lpc17_ethernet.c: Conditionally elide setting PHY + speed/duplex. This does not work for certain PHYs. Still some unresolved + issues (also from Kate). + * tools/Config.mk, Makefile, configs/*/Make.defs: Add a new Makefile + fragement to de-quoate certain strings from the Kconfig logic that + need to be used at path segments (Richard Cochran). + * arch/arm/src/stm32/stm32_usbotghost.c: The STM32 USB host driver only + works with debug turned on. The problem appears to be that with debug + OFF, there are more NAKs occuring in more places than before and this + reveals a variety of errors. This check in improves NAK robustness + for control transfers but does not resolve all of the issues. + * configs/stm3220g-eval/*/defconfig: Calibrated delay loop. It had + never been calibrated was was way off. + * sched/sem_holder.c: Add logic to handler some priority inheritance + cases when sem_post() is called from an interrupt handler. The + logic is clearly wrong, but it is not known if this is the + cause of any known bugs. + * lib/stdio/lib_perror(): Add perror(). Contributed by Kate. + * lib/string/lib_strerror(): Add option CONFIG_LIBC_STRERROR that + is now required to enabled strerror(). Add an option + CONFIG_LIBC_STRERROR_SHORT that can be used to output shortened + strings by strerror(). + * arch/arm/src/stm32/stm32_usbotghost.c: Finally... the USB OTG FS + appears to handle NAKing correctly is complete. + * configs/stm32f4discovery/*: Added and verifed support for USB OTG FS + host on the STM32F4Discovery board. + * configs/*/defconfig: Remove configuration documentation from config + files. It is redundant, error-prone, and difficult to maintain. + Configuration documentation is available in configs/README.txt for + common configurations and in configs/*/README.txt for board and MCU_ + specific configurations. + * configs/stm3240g-eval: Add USB host support. + * sched/os_bring.c, configs/*/defconfig, tools/mkconfig.c, and others: Added + configuration variable CONFIG_USER_ENTRYPOINT that may be used to change + the default entry from user_start to some other symbol. Contributed by + Kate. NOTE: This change does introduce a minor backward incompatibility. + For example, if your application uses NSH as its start-up program, then your + code will not fail because it will be unable to find "user_start". The fix + for this link failure is to add the following to your configuration file: + CONFIG_USER_ENTRYPOINT="nsh_main". + * libs/stdio/lib_libfread.c and lib_*flush*.c: Correct a couple of + error cases where the lib semaphore was not be released on error + exits (thanks Ronen Vainish). Also, improved some error reporting: + the generic ERROR was being used instead of the specific errno + value; the errno variable was not always set correctly. + * tools/mkfsdata.pl: The uIP web server CGI image making perl script was + moved from apps/netutils/webserver/makefsdata to nuttx/tools/mkfsdata.pl + (Part of a larger change submitted by Max Holtzberg). + * configs/stm3240g-eval/script/ld.script: All of the identical ld.script + files for the STM3240G-EVAL were replaced by one version in this directory. + * configs/stm3240g-eval/webserver: Configuration submitted by Max Holtzberg + for testing the changes to the uIP web server (see apps/ChangeLog.txt). + * lib/stdio/lib_perror.c: Remove CONFIG_LIBC_PERROR_DEVNAME. What was I + thinking? Arbitrary streams cannot be shared by different tasks. + * tools/mksyscall.c, csvparser.c, and csvparser.h: Separate CSV parsing + logic from mksyscall.c into files where it can be shared. + * tools/mksymtab.c: Add a tool that can be used to convert a CSV file + into a NuttX-style symbol table. + * sched/work_cancel.c: Fix a bad assertion (reported by Mike Smith) + * configs/stm3210e-eval/src/up_idle.c: Correct some power management + compilation errors (reported by Diego Sanchez). + * include/nuttx/wqueue.h, sched/work*, and others: Added logic to support + a second, lower priority work queue (CONFIG_SCHED_LPWORK). + * arch/arm/src/stm32/stm32_dma.c, chip/stm32*_memorymap.h: FSMC SRAM is + only 16-bits wide and the SDIO DMA must be set up differently. + * arch/arm/src/stm32/stm32_dma.c: Back out the 16-bit DMA change. It + is incorrect. + * configs/: Make use of UART4/5 vs USART4/5 consistent in all places. + * Kconfig: Serial 2STOP setting must be integer 0/1, not a boolean. + * lib/misc/sendfile.c and include/sys/sendfile.h: Add a Linux style + sendfile() (non-standard!) + * Kconfig: Refactor serial settings (moved from chip to drivers/serial). + AVR "teensy" now builds with Kconfig (contributed by Richard Cochran). + * Kconfig: Add configuration settings for the LPC17xx + * Kconfig: Add configuration settings for the LM3S (from Richard Cochran). + * Kconfig: Verify configuration settings for the STM32. This includes + changes in the way that the external SRAM is configured: Define + CONFIG_HEAP2_SIZE (decimal) instead of CONFIG_HEAP2_END (hex). + * tools/configure.sh: Don't append the apps directory path setting + if the correct setting is already in defined in the defconfig file. + * fs/fat/fs_utils.c: Improper constructed bool expression. This + would cause many unnecessary writes to FLASH (Thanks Ronen Vainish). + * Kconfig: Verify configuration settings for the LPC43xx. This includes + some corrections to configuration variable names and defconfig settings. + * Kconfig: Add and verify configuration settings for the LPC31xx. + * arch/arm/src/stm32/stm32_uart.h and stm32_serial.c: Add logic to + re-initialize the console UART as needed to enable DMA on the + console UART (contributed by Mike Smith). + * net/recvfrom.c, net/Kconfig, include/nuttx/net/uipopt.h: Remove delay + after receiving data. That has historical reasons to be there (it + was needed before read-ahead buffering was added), but kills performance. + (Noted by Max Holtzberg). + * configs/shenzhou: Add beginnings of a board configuration for the + Shenzhou STM32107 board (see www.armjishu.com). Very little is in + place as of this initial check-in. + * QEMU: Fixes from Richard Cochran to build QEMU with Kconfig files. + * arch/*/src/Makefile: Remove some old logic that was kicked off + when CONFIG_BOOT_RUNFROMFLASH=y. The old logic used to use + objcopy to move sections. Newer logic changes the load position + of sections in the the linker script. As far as I can tell, there + is nothing in the source tree now that depends on the old way of + doing things (if I am wrong, they will need a change to the linker + script). + * configs/fire-stm32v2: Configuration for the M3 Wildfire board. I + don't know very much about this board other than is has an + STM32F103VET6 chip, LCD, touchscreen, and ENC28J60 network. Very + little is in place on the initial check-in. + * configs/shenzhou: Coding for the Shenzhou board port is complete, + but tested has been deferred until I get the right tools. + * arch/arc/include/stm32/chip.h and arch/arm/src/stm32/chip.h: + Add support for the STM32F103VET6. + * fs/fs_fdopen.c: Bad check for failure to allocate memory. (Noted + by Ronen Vainish). + * drivers/mmcsd/mmcsd_sdio.c: If the MMC/SD driver were ever + uninitialized then there would be a double release of memory + (Noted by Ronen Vainish). + * fs/mmap/fs_rammap.c: Fix logic error and errno check (contributed + by Kate). + * arch/avr/src: Fixes from AVR32 build errors that have crept in + over the time; incorporated Kconfig for AVR3 (Richard Cochran). + * fs/fat and include/nuttx/fs/fat.h: The FAT file system allocates + memory for sector I/O buffers used to exchange data with the + configured block driver. In some contexts, the block driver may + require DMA-capable memory. If CONFIG_FAT_DMAMEMORY is defined, + then the FAT FS will use platform-provided DMA memory allocators + to allocate the block driver I/O buffers. + * CONFIG_NET_ENC28J60 renamed CONFIG_ENC28J60 to be consistent + in all places. + * drivers/enc28j60.c, include/nuttx/net/enc28j60.h, and + olimex-strp711/src/up_enc28j60.c: No longer passes IRQ number + as a parameters. Instead now passes a call table to manage + ENC28J60 GPIO interrupts. That is because GPIO interrupts are + handled in different ways by different MCUs and some do not + support IRQ numbers for GPIO interrupts. + * mm/mm_gran* and include/nuttx/gran.h: Add a simple granule- + based allocator. The intent of this allocator is to support + simple allocation of DMA I/O buffers. The initiali check-in + is code complete but untested (not event built into the + mm/Makefile yet. + * confgs/fire-stm32v2: The board port is basically functional. + Not all features have been verified. The ENC28J60 network + is not yet functional. + * configs/stm3240g-eval/discover: A configuration for testing + the UDP discovery utility. Contributed by Max Holtzberg. + * mm/README.txt: Add a new README file. + * include/nuttx/usb/usb.h, arch/*/src/*usb.c, and arch/*/src/*otg*.c: + Add hooks to to use common, external DMA buffer allocation + implementation. + * net/recvfrom.c: Don't block in recvfrom if (1) read-ahead buffering + is enabled and (2) some data was obtained from read-ahead buffers. + Blocking is a bad idea in that case because there is no timeout! + (submitted by Max Holtzberg). + * configs/stm3240g-eval/xmlrpc: An example configuration for the + Embeddable Lightweight XML-RPC Server at apps/examples/xmlrpc. + See http://www.drdobbs.com/web-development/\ + an-embeddable-lightweight-xml-rpc-server/184405364 for more info. + Contributed by Max Holtzberg. + * configs/*/nxwm/defconfig and sched/task_exithook.c: Fixes for + bugs that crept in during recent changes. (Submitted by Max + Holtzberg). + * arch/arm/include/armv7-m/irq.h: Fix a critical bug in irqsave(). + It looks like sometimes the compile will re-order some instructions + inapproapriately. This end result is that interrupts will get + stuff off. + * drivers/mtd/w25.c: Beginning of a driver for the Windbond SPI + FLASH family (W25x16, W25x32, and W25x64). The initial check-in + is basically just the SST25 driver with some name changes. + * arch/arm/include/armv7-m/irq.h and arch/arm/src/stm32/stm32_spi.c: + Back out the last change in irq.h. It is (most likely) fine the + way it was. The really interrupt related problem was in stm32_spi.c: + When SPI3 is not enabled, then the irqrestore() falls in the + else clause. + * include/nuttx/compiler.h and other files: Moved always_inline + and noinline __attributes__ here. Also replaced all occurrences + of explicit __atributes__ in other files with definitions from + this header file. + * drivers/mtd/w25.c: The Windbond SPI FLASH W25 FLASH driver is + code complete (but still untested). + * arch/arm/src/stm32/stm32_i2c.c: I2C improvements from Mike Smith. + Unified configuration logic; dynamic timeout calculations; + I2C reset logic to recover from locked devices on the bus. + * configs/*/*/Make.defs, tools/Config.mk, Makefile: Refactor all + common make definitions from the various Make.defs files into + the common tools/Make.mk. Add support for a verbosity options: + Specify V=1 on the make command line in order to see the exact + commands used in the build (Contributed by Richard Cochran). + * drivers/net/enc28j60.c: The ENC28J60 Ethernet driver is + now functional. diff --git a/nuttx/Kconfig b/nuttx/Kconfig index 7a8ba9bf28..f920e4984d 100644 --- a/nuttx/Kconfig +++ b/nuttx/Kconfig @@ -16,7 +16,7 @@ config NUTTX_NEWCONFIG bool default y -menu "General Setup" +menu "Build Setup" config EXPERIMENTAL bool "Prompt for development and/or incomplete code/drivers" @@ -152,26 +152,91 @@ config RAW_BINARY should not be selected if you are not using the GNU toolchain. endmenu +menu "Customize Header Files" + +config ARCH_STDBOOL_H + bool "stdbool.h" + default n + ---help--- + The stdbool.h header file can be found at nuttx/include/stdbool.h. + However, that header includes logic to redirect the inclusion of an + architecture specific header file like: + + #ifdef CONFIG_ARCH_STDBOOL_H + # include + #else + ... + #endif + + Recall that that include path, include/arch, is a symbolic link and + will refer to a version of stdbool.h at nuttx/arch//include/stdbool.h. + +config ARCH_MATH_H + bool "math.h" + default n + ---help--- + There is also a re-directing version of math.h in the source tree. + However, it resides out-of-the-way at include/nuttx/math.h because it + conflicts too often with the system math.h. If ARCH_MATH_H=y is + defined, however, the top-level makefile will copy the redirecting + math.h header file from include/nuttx/math.h to include/math.h. math.h + will then include the architecture-specific version of math.h that you + must provide at nuttx/arch/>architecture + #endif + + So for the architectures that define ARCH_MATH_H=y, include/math.h + will be the redirecting math.h header file; for the architectures + that don't select ARCH_MATH_H, the redirecting math.h header file + will stay out-of-the-way in include/nuttx/. + +config ARCH_STDARG_H + bool "stdarg.h" + default n + ---help--- + There is also a redirecting version of stdarg.h in the source tree + as well. It also resides out-of-the-way at include/nuttx/stdarg.h. + This is because you should normally use your toolchain's stdarg.h + file. But sometimes, your toolchain's stdarg.h file may have other + header file dependencies and so may not be usable in the NuttX build + environment. In those cases, you may have to create a architecture- + specific stdarg.h header file at nuttx/arch//include/stdarg.h + + If ARCH_STDARG_H=y is defined, the top-level makefile will copy the + re-directing stdarg.h header file from include/nuttx/stdarg.h to + include/stdarg.h. So for the architectures that cannot use their + toolchain's stdarg.h file, they can use this alternative by defining + ARCH_STDARG_H=y and providing. If ARCH_STDARG_H, is not defined, then + the stdarg.h header file will stay out-of-the-way in include/nuttx/. + +endmenu + menu "Debug Options" config DEBUG - bool "Enable debug output" + bool "Enable debug features" default n ---help--- - enables built-in debug options + Enables built-in debug features. Selecting this option will (1) Enable + debug assertions in the code, (2) enable extended parameter testing in + many functions, and (3) enable support for debug output. Note that enabling + this option by itself does not produce debug output. Debug output must + also be selected on a subsystem-by-subsystem basis. if DEBUG config DEBUG_VERBOSE bool "Enable debug verbose output" default n ---help--- - enables verbose debug output + Enables verbose debug output (assuming debug output is enabled) config DEBUG_ENABLE bool "Enable debug controls" default n ---help--- - Support an interface to enable or disable debug output. + Support an interface to dynamically enable or disable debug output. config DEBUG_SCHED bool "Enable scheduler debug output" @@ -258,7 +323,7 @@ menu "Board Selection" source "configs/Kconfig" endmenu -menu "Kernel Features" +menu "RTOS Features" source sched/Kconfig endmenu @@ -266,24 +331,24 @@ menu "Device Drivers" source drivers/Kconfig endmenu -menu "Networking support" +menu "Networking Support" source net/Kconfig endmenu -menu "File systems" +menu "File Systems" source fs/Kconfig endmenu -menu "Memory management" +menu "Memory Management" source mm/Kconfig endmenu -menu "Library routines" +menu "Library Routines" source lib/Kconfig source libxx/Kconfig endmenu -menu "Application configuration" +menu "Application Configuration" source "$APPSDIR/Kconfig" endmenu diff --git a/nuttx/Makefile b/nuttx/Makefile index ea83d69ee2..3c6e9c1985 100644 --- a/nuttx/Makefile +++ b/nuttx/Makefile @@ -35,8 +35,16 @@ TOPDIR := ${shell pwd | sed -e 's/ /\\ /g'} -include ${TOPDIR}/.config +-include ${TOPDIR}/tools/Config.mk -include ${TOPDIR}/Make.defs +# Control build verbosity. +ifeq ($(V),1) +export Q := +else +export Q := @ +endif + # Default tools ifeq ($(DIRLINK),) @@ -276,8 +284,8 @@ include/stdarg.h: endif # Targets used to build include/nuttx/version.h. Creation of version.h is -# part of the overall NuttX configuration sequency. Notice that the -# tools/mkversion tool is cuilt and used to create include/nuttx/version.h +# part of the overall NuttX configuration sequence. Notice that the +# tools/mkversion tool is built and used to create include/nuttx/version.h tools/mkversion: @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion @@ -293,8 +301,8 @@ include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion @tools/mkversion $(TOPDIR) > include/nuttx/version.h # Targets used to build include/nuttx/config.h. Creation of config.h is -# part of the overall NuttX configuration sequency. Notice that the -# tools/mkconfig tool is cuilt and used to create include/nuttx/config.h +# part of the overall NuttX configuration sequence. Notice that the +# tools/mkconfig tool is built and used to create include/nuttx/config.h tools/mkconfig: @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig @@ -602,7 +610,7 @@ distclean: clean subdir_distclean clean_context ifeq ($(CONFIG_BUILD_2PASS),y) @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean endif - @rm -f Make.defs setenv.sh .config + @rm -f Make.defs setenv.sh .config .config.old # Application housekeeping targets. The APPDIR variable refers to the user # application directory. A sample apps/ directory is included with NuttX, @@ -615,9 +623,10 @@ endif # apps_clean: Perform the clean operation only in the user application # directory # apps_distclean: Perform the distclean operation only in the user application -# directory. Note that the apps/.config file is preserved -# so that this is not a "full" distclean but more of a -# configuration "reset." +# directory. Note that the apps/.config file (inf any) is +# preserved so that this is not a "full" distclean but more of a +# configuration "reset." (There willnot be an apps/.config +# file if the configuration was generated via make menuconfig). apps_clean: ifneq ($(APPDIR),) @@ -626,10 +635,16 @@ endif apps_distclean: ifneq ($(APPDIR),) - @cp "$(TOPDIR)/$(APPDIR)/.config" _SAVED_APPS_config || \ - { echo "Copy of $(APPDIR)/.config failed" ; exit 1 ; } + @if [ -r "$(TOPDIR)/$(APPDIR)/.config" ]; then \ + cp "$(TOPDIR)/$(APPDIR)/.config" _SAVED_APPS_config || \ + { echo "Copy of $(APPDIR)/.config failed" ; exit 1 ; } \ + else \ + rm -f _SAVED_APPS_config; \ + fi @$(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" distclean - @mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \ - { echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } + @if [ -r _SAVED_APPS_config ]; then \ + @mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \ + { echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } \ + fi endif diff --git a/nuttx/README.txt b/nuttx/README.txt index 28b4fba032..5c330aa683 100644 --- a/nuttx/README.txt +++ b/nuttx/README.txt @@ -17,7 +17,7 @@ README o Building NuttX - Building - Re-building - - Build Targets + - Build Targets and Options o Cygwin Build Problems - Strange Path Problems - Window Native Toolchain Issues @@ -118,7 +118,7 @@ Installation Directories with Spaces in the Path I work around spaces in the home directory name, by creating a new directory that does not contain any spaces, such as /home/nuttx. Then I install NuttX in /home/nuttx and always build from - /home/nuttx/nuttx. + /home/nuttx/nuttx-code. Notes about Header Files ------------------------ @@ -380,9 +380,10 @@ Re-building This 'make' command will remove of the copied directories, re-copy them, then make NuttX. -Build Targets -------------- +Build Targets and Options +------------------------- + Build Targets: Below is a summary of the build targets available in the top-level NuttX Makefile: @@ -450,10 +451,22 @@ Build Targets the config.h and version.h header files in the include/nuttx directory and the establishment of symbolic links to configured directories. - clean_context + clean_context - This is part of the distclean target. It removes all of the header files - and symbolic links created by the context target. + This is part of the distclean target. It removes all of the header files + and symbolic links created by the context target. + + Build Options: + Of course, the value any make variable an be overriden from the make command + line. However, there is one particular variable assignment option that may + be useful to you: + + V=1 + + This is the build "verbosity flag." If you specify V=1 on the make command + line, you will see the exact commands used in the build. This can be very + useful when adding new boards or tracking down compile time errors and + warnings (Contributed by Richard Cochran). CYGWIN BUILD PROBLEMS ^^^^^^^^^^^^^^^^^^^^^ @@ -461,27 +474,27 @@ CYGWIN BUILD PROBLEMS Strange Path Problems --------------------- -If you see strange behavior when building under Cygwin then you may have -a problem with your PATH variable. For example, if you see failures to -locate files that are clearly present, that may mean that you are using -the wrong version of a tool. For example, you may not be using Cygwin's -'make' program at /usr/bin/make. Try: + If you see strange behavior when building under Cygwin then you may have + a problem with your PATH variable. For example, if you see failures to + locate files that are clearly present, that may mean that you are using + the wrong version of a tool. For example, you may not be using Cygwin's + 'make' program at /usr/bin/make. Try: $ which make /usr/bin/make -When you install some toolchains (such as Yargarto or CodeSourcery tools), -they may modify your PATH variable to include a path to their binaries. -At that location, they make have GNUWin32 versions of the tools. So you -might actually be using a version of make that does not understand Cygwin -paths. + When you install some toolchains (such as Yargarto or CodeSourcery tools), + they may modify your PATH variable to include a path to their binaries. + At that location, they make have GNUWin32 versions of the tools. So you + might actually be using a version of make that does not understand Cygwin + paths. -The solution is either: + The solution is either: -1. Edit your PATH to remove the path to the GNUWin32 tools, or -2. Put /usr/local/bin, /usr/bin, and /bin at the front of your path: + 1. Edit your PATH to remove the path to the GNUWin32 tools, or + 2. Put /usr/local/bin, /usr/bin, and /bin at the front of your path: - $ export PATH=/usr/local/bin:/usr/bin:/bin:$PATH + $ export PATH=/usr/local/bin:/usr/bin:/bin:$PATH Window Native Toolchain Issues ------------------------------ @@ -568,7 +581,7 @@ General Pre-built Toolchain Issues And finally you may not be able to use NXFLAT. 7. NXFLAT. If you use a pre-built toolchain, you will lose all support - for NXFLAT. NXFLAT is a binary format described in + for NXFLAT. NXFLAT is a binary format described in Documentation/NuttXNxFlat.html. It may be possible to build standalone versions of the NXFLAT tools; there are a few examples of this in the misc/buildroot/configs directory. However, it @@ -654,6 +667,8 @@ nuttx | | |- ostest/README.txt | | |- poll/README.txt | | `- README.txt + | |- fire-stm32v2/ + | | `- README.txt | |- hymini-stm32v/ | | |- include/README.txt | | |- src/README.txt @@ -735,6 +750,8 @@ nuttx | | |- include/README.txt | | |- src/README.txt | | `- README.txt + | |- shenzhou/ + | | `- README.txt | |- skp16c26/ | | |- include/README.txt | | |- src/README.txt @@ -802,6 +819,8 @@ nuttx | `- README.txt |- libxx/ | `- README.txt + |- mm/ + | `- README.txt |- syscall/ | `- README.txt `- tools/ @@ -820,6 +839,8 @@ apps |- modbus/ | `- README.txt |- netutils/ + | |- discover + | | `- README.txt | |- ftpc | | `- README.txt | |- telnetd diff --git a/nuttx/ReleaseNotes b/nuttx/ReleaseNotes index 26af0e38d4..4d72116694 100644 --- a/nuttx/ReleaseNotes +++ b/nuttx/ReleaseNotes @@ -1968,7 +1968,7 @@ release includes several new features: small for the MCU usage and has some limitations. No formal documentation of NXFFS yet exists. See the fs/nxffs/README.txt file for details (see - http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/fs/nxffs/README.txt?view=log) + http://svn.code.sf.net/p/nuttx/code/trunk/nuttx/fs/nxffs/README.txt?view=log) * Support for NXP LPCXpresso LPC1768 board on the Embedded Artists base board. The Code Red toolchain is supported under either Linux or Windows. Verified configurations include @@ -2999,3 +2999,67 @@ Bugfixes (see the change log for details) : on Z80. As well as other, less critical bugs (see the ChangeLog for details) + +NuttX-6.21 +^^^^^^^^^^ + +The 88th release of NuttX, Version 6.21, was made on August 25, 2012, +and is available for download from the SourceForge website. Note +that release consists of two tarballs: nuttx-6.21.tar.gz and +apps-6.21.tar.gz. Both may be needed (see the top-level nuttx/README.txt +file for build information). + +This release corresponds with SVN release number: r5052 + +Additional new features and extended functionality: + + * Core: Add support for multiple registered atexit() functions. Syslog + extended: Now any character driver may be used for the debug logging + device. Mountpoint traversal logic. + * Drivers: Added support for the TI PGA112-7 amplifier/multiplexor. + * LPC43xx: Added clock ramp-up logic to run at 204 MHz + * LPC43xx Drivers: SPIFI block driver, RS-485 support, Minimal termios + support. Framework for USB0 device controller driver. + * LPC17xx Drivers: Minimal termios support + * STM32: Support for STM32 F1 "Value Line" (contributed by Mike Smith). + Add support for STM32 F107 "Connectivity Line" (contributed by Max + Holtzberg). + Clock restart logic needed for recovery from low power modes. + * STM32 Drivers: RTC alarm support. Usable for wakeup from sleep mode, + Minimal serial termios support. USB OTG FS host driver (alpha). + * STM32 Boards: Add power management hooks for the STM32F4Discovery, + Add support for the Olimex STM32-P107 (contributed by Max Holtzberg). + * PIC32: Add support for the Pinguino MIPS toolchain. + * PIC32 Drivers: GPIO driver now supports F1 analog regiaters (ANSEL). + * PIC32 Boards: Add support for the PGA117 on the Mirtoo module. + * Calypso: Add support for the SSD1783 LCD on the Compal E99. + * Library: cfsetispeed(), cfsetospeed(), tcflush(), memchr(), and + memccpy(). + * Applications: Port of freemodbus-v1.5.0. Add support for testing + devices with multiple ADC, PWM, and QE devices. + NSH: NSH 'mount' command (with no arguments) will now show mounted + volumes. Add new NSH 'df' command. Extended 'help' support. NSH + now catches the return value from spawned applications (provided + by Mike Smith). + * Build System: mkconfig will not define CONFIG_DRAM_END. A lot of + progress has been made on the automated NuttX configuration logic + (Thanks go to Richard Cochran). + * Documentation: Document ways to customize the behavior of NSH. + +Bugfixes (see the change log for details) : + + * Serial drivers (all): Fix ioctl return value. Common "upper half" + serial driver will now return with EINTR if a serial wait is + interrupted by a signal. + * FAT: Fix statfs() file name length. + * LPC43xx: Clock configuration. + * STM32: Pinmap fixes, SPI driver re-initialization + * STM32 Boards: Correct and lower SDIO frequency for F2 and f4 boards. + * AVR: C++ build issues. + * PM: Fix a place where interrupts were not be re-enabled. + * Applications: NSH application start-up race conditions. + * Library: Fieldwidth and justification for %s format. Fixed several + issues with presenting floating point numbers. NULL definition + for C++ + +As well as other, less critical bugs (see the ChangeLog for details) diff --git a/nuttx/TODO b/nuttx/TODO index 543d15f707..72a94290b9 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated August 12, 2012) +NuttX TODO List (Last updated September 16, 2012) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -6,7 +6,7 @@ standards, things that could be improved, and ideas for enhancements. nuttx/ - (5) Task/Scheduler (sched/) + (6) Task/Scheduler (sched/) (1) On-demand paging (sched/) (1) Memory Managment (mm/) (2) Signals (sched/, arch/) @@ -110,6 +110,13 @@ o Task/Scheduler (sched/) Status: Open Priority: Low + Title: posix_spawn() + Description: This would be a good interface to add to NuttX. It is really + just a re-packaging of the existing, non-standard NuttX exec() + function. + Status: Open + Priority: Medium low. + o On-demand paging (sched/) ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -541,13 +548,6 @@ o Network (net/, drivers/net) Status: Open Priority: Low... fix defconfig files as necessary. - Title: UNFINISHED ENC28J60 DRIVER - Description: So far, I have not come up with a usable hardware platform to - verify the ENC28J60 Ethernet driver (drivers/net/enc28j60.c). - So it is untested. - Status: Open - Priority: Low unless you need it. - o USB (drivers/usbdev, drivers/usbhost) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/nuttx/arch/Kconfig b/nuttx/arch/Kconfig index 6e0e0fb9da..bbe99c17c2 100644 --- a/nuttx/arch/Kconfig +++ b/nuttx/arch/Kconfig @@ -14,21 +14,27 @@ config ARCH_8051 config ARCH_ARM bool "ARM" + select ARCH_HAVE_INTERRUPTSTACK ---help--- The ARM architectures config ARCH_AVR bool "AVR" + select ARCH_NOINTC + select ARCH_HAVE_INTERRUPTSTACK ---help--- Atmel 8-bit bit AVR and 32-bit AVR32 architectures config ARCH_HC bool "Freescale HC" + select ARCH_NOINTC + select ARCH_HAVE_INTERRUPTSTACK ---help--- Freescale HC architectures (M9S12) config ARCH_MIPS bool "MIPS" + select ARCH_HAVE_INTERRUPTSTACK ---help--- MIPS architectures (PIC32) @@ -39,7 +45,9 @@ config ARCH_RGMP http://rgmp.sourceforge.net/wiki/index.php/Main_Page. config ARCH_SH - bool "Rensas" + bool "Renesas" + select ARCH_NOINTC + select ARCH_HAVE_INTERRUPTSTACK ---help--- Renesas architectures (SH and M16C). @@ -55,11 +63,13 @@ config ARCH_X86 config ARCH_Z16 bool "ZNEO" + select ARCH_HAVE_HEAP2 ---help--- ZiLOG ZNEO 16-bit architectures (z16f). config ARCH_Z80 bool "z80" + select ARCH_HAVE_HEAP2 ---help--- ZiLOG 8-bit architectures (z80, ez80, z8). @@ -90,3 +100,99 @@ source arch/sim/Kconfig source arch/x86/Kconfig source arch/z16/Kconfig source arch/z80/Kconfig + +comment "Architecture Options" + +config ARCH_NOINTC + bool + default n + +config ARCH_DMA + bool + default n + +config ARCH_STACKDUMP + bool "Dump stack on assertions" + default n + ---help--- + Enable to do stack dumps after assertions + +comment "Board Settings" + +config BOARD_LOOPSPERMSEC + int "Loops per millisecond" + help + Must be calibrated for correct operation of delay loops. + You simply use a stop watch to measure the 100 second delay + then adjust CONFIG_BOARD_LOOPSPERMSEC until it is actually + is 100 seconds. + +config DRAM_START + hex "DRAM start physical address" + help + The physical start address of installed RAM. Despite the naming, + this may be SDRAM or SRAM or any other RAM technology that support + program execution. + +config DRAM_VSTART + hex "DRAM start virtual address" + depends on ARCH_HAVE_MMU + help + The virtual start address of installed RAM. Despite the naming, + this may be SDRAM or SRAM or any other RAM technology that support + program execution. + +config DRAM_SIZE + int "DRAM size" + help + The size in bytes of the installed RAM. Despite the naming, + this may be SDRAM or SRAM or any other RAM technology that support + program execution. + +config ARCH_HAVE_INTERRUPTSTACK + bool + +config ARCH_INTERRUPTSTACK + int "Interrupt Stack Size" + depends on ARCH_HAVE_INTERRUPTSTACK + default 0 + ---help--- + This architecture supports an interrupt stack. If defined, this symbol + will be the size of the interrupt stack in bytes. If not defined (or + defined to be zero), the user task stacks will be used during interrupt + handling. + +comment "Boot options" + +choice + prompt "Boot Mode" + default BOOT_RUNFROMFLASH + +config BOOT_RUNFROMEXTSRAM + bool "Run from external SRAM" + ---help--- + Some configuration support booting and running from external SRAM. + +config BOOT_RUNFROMFLASH + bool "Boot and run from flash" + ---help--- + Most configurations support XIP operation from FLASH but must copy + initialized .data sections to RAM. (This is the default). + +config BOOT_RUNFROMISRAM + bool "Boot and run from internal SRAM" + ---help--- + Some configuration support booting and running from internal SRAM. + +config BOOT_RUNFROMSDRAM + bool "Boot and run from external SDRAM" + ---help--- + Some configuration support booting and running from external SDRAM. + +config BOOT_COPYTORAM + bool "Boot from FLASH but copy to ram" + ---help--- + Some configurations boot in FLASH but copy themselves entirely into + RAM for better performance. + +endchoice diff --git a/nuttx/arch/arm/Kconfig b/nuttx/arch/arm/Kconfig index 40dcb11059..2a7ea10b59 100644 --- a/nuttx/arch/arm/Kconfig +++ b/nuttx/arch/arm/Kconfig @@ -10,71 +10,107 @@ choice config ARCH_CHIP_C5471 bool "TMS320 C5471" + select ARCH_ARM7TDMI + select ARCH_HAVE_LOWVECTORS ---help--- TI TMS320 C5471, A180, or DA180 (ARM7TDMI) config ARCH_CHIP_CALYPSO bool "Calypso" + select ARCH_ARM7TDMI + select ARCH_HAVE_HEAP2 + select ARCH_HAVE_LOWVECTORS ---help--- TI Calypso-based cell phones (ARM7TDMI) config ARCH_CHIP_DM320 bool "TMS320 DM320" + select ARCH_ARM926EJS + select ARCH_HAVE_LOWVECTORS + select ARCH_HAVE_MMU ---help--- TI DMS320 DM320 (ARM926EJS) config ARCH_CHIP_IMX bool "Freescale iMX" + select ARCH_ARM920T + select ARCH_HAVE_HEAP2 + select ARCH_HAVE_LOWVECTORS + select ARCH_HAVE_MMU ---help--- Freescale iMX architectures (ARM920T) config ARCH_CHIP_KINETIS bool "Freescale Kinetis" + select ARCH_CORTEXM4 + select ARCH_HAVE_MPU ---help--- Freescale Kinetis Architectures (ARM Cortex-M4) config ARCH_CHIP_LM3S bool "TI Stellaris" + select ARCH_CORTEXM3 + select ARCH_HAVE_MPU ---help--- TI Stellaris LMS3 architecutres (ARM Cortex-M3) config ARCH_CHIP_LPC17XX bool "NXP LPC17xx" + select ARCH_CORTEXM3 + select ARCH_HAVE_MPU ---help--- NXP LPC17xx architectures (ARM Cortex-M3) config ARCH_CHIP_LPC214X bool "NXP LPC214x" + select ARCH_ARM7TDMI + select ARCH_HAVE_LOWVECTORS ---help--- NXP LPC2145x architectures (ARM7TDMI) config ARCH_CHIP_LPC2378 bool "NXP LPC2378" + select ARCH_ARM7TDMI + select ARCH_HAVE_LOWVECTORS ---help--- NXP LPC2145x architectures (ARM7TDMI) config ARCH_CHIP_LPC31XX bool "NXP LPC31XX" + select ARCH_ARM926EJS + select ARCH_HAVE_LOWVECTORS + select ARCH_HAVE_MMU ---help--- NPX LPC31XX architectures (ARM926EJS). config ARCH_CHIP_LPC43XX bool "NXP LPC43XX" + select ARCH_CORTEXM4 + select ARCH_HAVE_CMNVECTOR + select ARMV7M_CMNVECTOR + select ARCH_HAVE_MPU ---help--- NPX LPC43XX architectures (ARM Cortex-M4). config ARCH_CHIP_SAM3U bool "Atmel AT91SAM3U" + select ARCH_CORTEXM3 + select ARCH_HAVE_MPU ---help--- Atmel AT91SAM3U architectures (ARM Cortex-M3) config ARCH_CHIP_STM32 bool "STMicro STM32" + select ARCH_HAVE_CMNVECTOR + select ARCH_HAVE_MPU + select ARCH_HAVE_I2CRESET ---help--- STMicro STM32 architectures (ARM Cortex-M3/4). config ARCH_CHIP_STR71X bool "STMicro STR71x" + select ARCH_ARM7TDMI + select ARCH_HAVE_LOWVECTORS ---help--- STMicro STR71x architectures (ARM7TDMI). @@ -82,24 +118,23 @@ endchoice config ARCH_ARM7TDMI bool - default y if ARCH_CHIP_C5471 || ARCH_CHIP_CALYPSO || ARCH_CHIP_LPC214X || ARCH_CHIP_LPC2378 || ARCH_CHIP_STR71X config ARCH_ARM926EJS bool - default y if ARCH_CHIP_DM320 || ARCH_CHIP_LPC31XX config ARCH_ARM920T bool - default y if ARCH_CHIP_IMX -config ARCH_CORTEXM +config ARCH_CORTEXM3 + bool + +config ARCH_CORTEXM4 bool - default y if ARCH_CHIP_KINETIS || ARCH_CHIP_LM3S || ARCH_CHIP_LPC17XX || ARCH_CHIP_LPC43XX || ARCH_CHIP_SAM3U || ARCH_CHIP_STM32 config ARCH_FAMILY string default "arm" if ARCH_ARM7TDMI || ARCH_ARM926EJS || ARCH_ARM920T - default "armv7-m" if ARCH_CORTEXM + default "armv7-m" if ARCH_CORTEXM3 || ARCH_CORTEXM4 config ARCH_CHIP string @@ -109,7 +144,7 @@ config ARCH_CHIP default "imx" if ARCH_CHIP_IMX default "kinetis" if ARCH_CHIP_KINETIS default "lm3s" if ARCH_CHIP_LM3S - default "lpc17x" if ARCH_CHIP_LPC17XX + default "lpc17xx" if ARCH_CHIP_LPC17XX default "lpc214x" if ARCH_CHIP_LPC214X default "lpc2378" if ARCH_CHIP_LPC2378 default "lpc31xx" if ARCH_CHIP_LPC31XX @@ -118,33 +153,77 @@ config ARCH_CHIP default "stm32" if ARCH_CHIP_STM32 default "str71x" if ARCH_CHIP_STR71X -config ARCH_STACKDUMP - bool "Dump stack on assertions" +config ARMV7M_CMNVECTOR + bool "Use common ARMv7-M vectors" default n + depends on ARCH_HAVE_CMNVECTOR ---help--- - Enable to do stack dumps after assertions + Some architectures use their own, built-in vector logic. Some use only + the common vector logic. Some can use either their own built-in vector + logic or the common vector logic. This applies only to ARMv7-M + architectures. -config ARCH_LEDS - bool "Use board LEDs to show state" +config ARCH_FPU + bool "FPU support" default y + depends on ARCH_CORTEXM4 ---help--- - Use LEDs to show state. Unique to boards that have LEDs + Build in support for the ARM Cortex-M4 Floating Point Unit (FPU). + Check your chip specifications first; not all Cortex-M4 chips support the FPU. -config ARCH_INTERRUPTSTACK - bool "Use interrupt stack" - default y +config ARCH_HAVE_MPU + bool + +config ARMV7M_MPU + bool "MPU support" + default n + depends on ARCH_HAVE_MPU ---help--- - This architecture supports an interrupt stack. If defined, this symbol - is the size of the interrupt stack in bytes. If not defined, the user - task stacks will be used during interrupt handling. + Build in support for the ARM Cortex-M3/4 Memory Protection Unit (MPU). + Check your chip specifications first; not all Cortex-M3/4 chips support the MPU. + +config ARCH_HAVE_LOWVECTORS + bool + +config ARCH_LOWVECTORS + bool "Vectors in low memory" + default n + depends on ARCH_HAVE_LOWVECTORS + ---help--- + Support ARM vectors in low memory. + +config ARCH_HAVE_MMU + bool + +config PGTABLE_VADDR + hex "Page table virtual address" + depends on ARCH_HAVE_MMU + ---help--- + Page table virtual address (might be defined in the board.h file). Not + applicable to all architectures. + +config ARCH_ROMPGTABLE + bool "ROM page table" + default n + depends on ARCH_HAVE_MMU + ---help--- + Support a fixed memory mapping use a (read-only) page table in ROM/FLASH. + +config PAGING + bool "On-demand paging" + default n + depends on ARCH_HAVE_MMU && !ARCH_ROMPGTABLE + ---help--- + If set =y in your configation file, this setting will enable the on-demand + paging feature as described in http://www.nuttx.org/NuttXDemandPaging.html. config ARCH_IRQPRIO bool "Interrupt priority" - default y if ARCH_CORTEXM + default y if ARCH_CORTEXM3 || ARCH_CORTEXM4 ---help--- Select if your board supports interrupt prioritization. -config ARCH_LOOPSPERMSEC +config BOARD_LOOPSPERMSEC int "Delay loops per millisecond" default 5000 ---help--- @@ -156,8 +235,8 @@ config ARCH_CALIBRATION ---help--- Enables some built in instrumentation that causes a 100 second delay during boot-up. This 100 second delay serves no purpose other than it - allows you to calibratre ARCH_LOOPSPERMSEC. You simply use a stop - watch to measure the 100 second delay then adjust ARCH_LOOPSPERMSEC until + allows you to calibratre BOARD_LOOPSPERMSEC. You simply use a stop + watch to measure the 100 second delay then adjust BOARD_LOOPSPERMSEC until the delay actually is 100 seconds. if ARCH_CHIP_C5471 diff --git a/nuttx/arch/arm/include/arch.h b/nuttx/arch/arm/include/arch.h index dd750ad77a..d0b2602eba 100644 --- a/nuttx/arch/arm/include/arch.h +++ b/nuttx/arch/arm/include/arch.h @@ -2,7 +2,7 @@ * arch/arm/include/arch.h * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/arm/irq.h b/nuttx/arch/arm/include/arm/irq.h index 6b4f05539a..a06abe8886 100644 --- a/nuttx/arch/arm/include/arm/irq.h +++ b/nuttx/arch/arm/include/arm/irq.h @@ -2,7 +2,7 @@ * arch/arm/include/arm/irq.h * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/arm/syscall.h b/nuttx/arch/arm/include/arm/syscall.h index e06de1a3c2..3fc36c3db0 100644 --- a/nuttx/arch/arm/include/arm/syscall.h +++ b/nuttx/arch/arm/include/arm/syscall.h @@ -2,7 +2,7 @@ * arch/arm/include/arm/syscall.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/armv7-m/irq.h b/nuttx/arch/arm/include/armv7-m/irq.h index 6cef85c02a..606b3988f4 100644 --- a/nuttx/arch/arm/include/armv7-m/irq.h +++ b/nuttx/arch/arm/include/armv7-m/irq.h @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/include/armv7-m/irq.h * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #ifndef __ASSEMBLY__ +# include # include #endif @@ -131,6 +132,7 @@ struct xcptcontext /* Disable IRQs */ +static inline void irqdisable(void) inline_function; static inline void irqdisable(void) { __asm__ __volatile__ ("\tcpsid i\n"); @@ -138,6 +140,7 @@ static inline void irqdisable(void) /* Save the current primask state & disable IRQs */ +static inline irqstate_t irqsave(void) inline_function; static inline irqstate_t irqsave(void) { unsigned short primask; @@ -153,11 +156,13 @@ static inline irqstate_t irqsave(void) : "=r" (primask) : : "memory"); + return primask; } /* Enable IRQs */ +static inline void irqenable(void) inline_function; static inline void irqenable(void) { __asm__ __volatile__ ("\tcpsie i\n"); @@ -165,6 +170,7 @@ static inline void irqenable(void) /* Restore saved primask state */ +static inline void irqrestore(irqstate_t primask) inline_function; static inline void irqrestore(irqstate_t primask) { /* If bit 0 of the primask is 0, then we need to restore @@ -184,6 +190,7 @@ static inline void irqrestore(irqstate_t primask) /* Get/set the primask register */ +static inline uint8_t getprimask(void) inline_function; static inline uint8_t getprimask(void) { uint32_t primask; @@ -193,9 +200,11 @@ static inline uint8_t getprimask(void) : "=r" (primask) : : "memory"); + return (uint8_t)primask; } +static inline void setprimask(uint32_t primask) inline_function; static inline void setprimask(uint32_t primask) { __asm__ __volatile__ @@ -208,18 +217,22 @@ static inline void setprimask(uint32_t primask) /* Get/set the basepri register */ +static inline uint8_t getbasepri(void) inline_function; static inline uint8_t getbasepri(void) { uint32_t basepri; + __asm__ __volatile__ ( "\tmrs %0, basepri\n" : "=r" (basepri) : : "memory"); + return (uint8_t)basepri; } +static inline void setbasepri(uint32_t basepri) inline_function; static inline void setbasepri(uint32_t basepri) { __asm__ __volatile__ @@ -232,6 +245,7 @@ static inline void setbasepri(uint32_t basepri) /* Get/set IPSR */ +static inline uint32_t getipsr(void) inline_function; static inline uint32_t getipsr(void) { uint32_t ipsr; @@ -241,9 +255,11 @@ static inline uint32_t getipsr(void) : "=r" (ipsr) : : "memory"); + return ipsr; } +static inline void setipsr(uint32_t ipsr) inline_function; static inline void setipsr(uint32_t ipsr) { __asm__ __volatile__ @@ -256,6 +272,7 @@ static inline void setipsr(uint32_t ipsr) /* Get/set CONTROL */ +static inline uint32_t getcontrol(void) inline_function; static inline uint32_t getcontrol(void) { uint32_t control; @@ -265,9 +282,11 @@ static inline uint32_t getcontrol(void) : "=r" (control) : : "memory"); + return control; } +static inline void setcontrol(uint32_t control) inline_function; static inline void setcontrol(uint32_t control) { __asm__ __volatile__ diff --git a/nuttx/arch/arm/include/armv7-m/syscall.h b/nuttx/arch/arm/include/armv7-m/syscall.h index 4c7b843021..4278c3a36b 100644 --- a/nuttx/arch/arm/include/armv7-m/syscall.h +++ b/nuttx/arch/arm/include/armv7-m/syscall.h @@ -2,7 +2,7 @@ * arch/arm/include/armv7-m/syscall.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/irq.h b/nuttx/arch/arm/include/irq.h index 71493a9fed..bde751b990 100644 --- a/nuttx/arch/arm/include/irq.h +++ b/nuttx/arch/arm/include/irq.h @@ -2,7 +2,7 @@ * arch/arm/include/irq.h * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/serial.h b/nuttx/arch/arm/include/serial.h index 80eefb2b4a..844f78a2b9 100644 --- a/nuttx/arch/arm/include/serial.h +++ b/nuttx/arch/arm/include/serial.h @@ -2,7 +2,7 @@ * arch/arm/include/serial.h * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/stm32/chip.h b/nuttx/arch/arm/include/stm32/chip.h index 2bf1d79b45..d01929e1ca 100644 --- a/nuttx/arch/arm/include/stm32/chip.h +++ b/nuttx/arch/arm/include/stm32/chip.h @@ -56,6 +56,8 @@ * the chip datasheet. */ +/* STM32 F100 Value Line ************************************************************/ + #if defined(CONFIG_ARCH_CHIP_STM32F100C8) || defined(CONFIG_ARCH_CHIP_STM32F100CB) \ || defined(CONFIG_ARCH_CHIP_STM32F100R8) || defined(CONFIG_ARCH_CHIP_STM32F100RB) \ || defined(CONFIG_ARCH_CHIP_STM32F100V8) || defined(CONFIG_ARCH_CHIP_STM32F100VB) @@ -87,34 +89,10 @@ # define STM32_NRNG 0 /* No random number generator (RNG) */ # define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ -#elif defined(CONFIG_ARCH_CHIP_STM32F103ZET6) -# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ -# undef CONFIG_STM32_VALUELINE /* STM32F100x */ -# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ -# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ -# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */ -# define STM32_NFSMC 1 /* FSMC */ -# define STM32_NATIM 1 /* One advanced timer TIM1 */ -# define STM32_NGTIM 4 /* 16-bit generall timers TIM2,3,4,5 with DMA */ -# define STM32_NBTIM 0 /* No basic timers */ -# define STM32_NDMA 2 /* DMA1-2 */ -# define STM32_NSPI 2 /* SPI1-2 */ -# define STM32_NI2S 0 /* No I2S (?) */ -# define STM32_NUSART 3 /* USART1-3 */ -# define STM32_NI2C 2 /* I2C1-2 */ -# define STM32_NCAN 1 /* CAN1 */ -# define STM32_NSDIO 1 /* SDIO */ -# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */ -# define STM32_NGPIO 112 /* GPIOA-G */ -# define STM32_NADC 1 /* ADC1 */ -# define STM32_NDAC 0 /* No DAC */ -# define STM32_NCRC 0 /* No CRC */ -# define STM32_NETHERNET 0 /* No ethernet */ -# define STM32_NRNG 0 /* No random number generator (RNG) */ -# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ +/* STM32 F103 High Density Family ***************************************************/ +/* STM32F103RC, STM32F103RD, and STM32F103RE are all provided in 64 pin packages and differ + * only in the available FLASH and SRAM. + */ #elif defined(CONFIG_ARCH_CHIP_STM32F103RET6) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ @@ -145,7 +123,11 @@ # define STM32_NRNG 0 /* No random number generator (RNG) */ # define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ -#elif defined(CONFIG_ARCH_CHIP_STM32F103VCT6) +/* STM32F103VC, STM32F103VD, and STM32F103VE are all provided in 100 pin packages and differ + * only in the available FLASH and SRAM. + */ + +#elif defined(CONFIG_ARCH_CHIP_STM32F103VCT6) || defined(CONFIG_ARCH_CHIP_STM32F103VET6) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ # undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ # undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ @@ -174,6 +156,40 @@ # define STM32_NRNG 0 /* No random number generator (RNG) */ # define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ +/* STM32F103ZC, STM32F103ZD, and STM32F103ZE are all provided in 144 pin packages and differ + * only in the available FLASH and SRAM. + */ + +#elif defined(CONFIG_ARCH_CHIP_STM32F103ZET6) +# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_VALUELINE /* STM32F100x */ +# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ +# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ +# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */ +# define STM32_NFSMC 1 /* FSMC */ +# define STM32_NATIM 1 /* One advanced timer TIM1 */ +# define STM32_NGTIM 4 /* 16-bit generall timers TIM2,3,4,5 with DMA */ +# define STM32_NBTIM 0 /* No basic timers */ +# define STM32_NDMA 2 /* DMA1-2 */ +# define STM32_NSPI 2 /* SPI1-2 */ +# define STM32_NI2S 0 /* No I2S (?) */ +# define STM32_NUSART 3 /* USART1-3 */ +# define STM32_NI2C 2 /* I2C1-2 */ +# define STM32_NCAN 1 /* CAN1 */ +# define STM32_NSDIO 1 /* SDIO */ +# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */ +# define STM32_NGPIO 112 /* GPIOA-G */ +# define STM32_NADC 1 /* ADC1 */ +# define STM32_NDAC 0 /* No DAC */ +# define STM32_NCRC 0 /* No CRC */ +# define STM32_NETHERNET 0 /* No ethernet */ +# define STM32_NRNG 0 /* No random number generator (RNG) */ +# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ + +/* STM32 F105/F107 Connectivity Line *******************************************************/ #elif defined(CONFIG_ARCH_CHIP_STM32F105VBT7) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ # undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ @@ -232,6 +248,7 @@ # define STM32_NRNG 0 /* No random number generator (RNG) */ # define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ +/* STM32 F2 Family ******************************************************************/ #elif defined(CONFIG_ARCH_CHIP_STM32F207IG) /* UFBGA-176 1024Kb FLASH 128Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ # undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ @@ -263,6 +280,7 @@ # define STM32_NRNG 1 /* Random number generator (RNG) */ # define STM32_NDCMI 1 /* Digital camera interface (DCMI) */ +/* STM23 F4 Family ******************************************************************/ #elif defined(CONFIG_ARCH_CHIP_STM32F405RG) /* LQFP 64 10x10x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ # undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ diff --git a/nuttx/arch/arm/include/syscall.h b/nuttx/arch/arm/include/syscall.h index 4c9eee63ef..8b438200a8 100644 --- a/nuttx/arch/arm/include/syscall.h +++ b/nuttx/arch/arm/include/syscall.h @@ -2,7 +2,7 @@ * arch/arm/include/syscall.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/types.h b/nuttx/arch/arm/include/types.h index c3471ca59b..c06b289503 100644 --- a/nuttx/arch/arm/include/types.h +++ b/nuttx/arch/arm/include/types.h @@ -2,7 +2,7 @@ * arch/arm/include/types.h * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/include/watchdog.h b/nuttx/arch/arm/include/watchdog.h index f70b8d2e9a..43fbac2be8 100644 --- a/nuttx/arch/arm/include/watchdog.h +++ b/nuttx/arch/arm/include/watchdog.h @@ -2,7 +2,7 @@ * arch/arm/include/watchdog.h * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/Makefile b/nuttx/arch/arm/src/Makefile index ef04153756..74be6c18d1 100644 --- a/nuttx/arch/arm/src/Makefile +++ b/nuttx/arch/arm/src/Makefile @@ -111,11 +111,6 @@ nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT) @echo "LD: nuttx" @$(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \ --start-group $(LDLIBS) -lboard $(EXTRA_LIBS) $(LIBGCC) --end-group -ifeq ($(CONFIG_BOOT_RUNFROMFLASH),y) - @export flashloc=`$(OBJDUMP) --all-headers $(NUTTX)$(EXEEXT) | grep _eronly | cut -d' ' -f1`; \ - $(OBJCOPY) $(OBJCOPYARGS) --adjust-section-vma=.data=0x$$flashloc $(NUTTX)$(EXEEXT) $(NUTTX).flashimage - @mv $(NUTTX).flashimage $(NUTTX)$(EXEEXT) -endif @$(NM) $(NUTTX)$(EXEEXT) | \ grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \ sort > $(TOPDIR)/System.map diff --git a/nuttx/arch/arm/src/armv7-m/psr.h b/nuttx/arch/arm/src/armv7-m/psr.h index 30913f7c9e..b8b33c80f6 100644 --- a/nuttx/arch/arm/src/armv7-m/psr.h +++ b/nuttx/arch/arm/src/armv7-m/psr.h @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/psr.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/svcall.h b/nuttx/arch/arm/src/armv7-m/svcall.h index 51b5b9111a..6758297999 100644 --- a/nuttx/arch/arm/src/armv7-m/svcall.h +++ b/nuttx/arch/arm/src/armv7-m/svcall.h @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/svcall.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,7 +74,7 @@ /* SYS call 1: * - * void up_fullcontextrestore(uint32_t *restoreregs) __attribute__ ((noreturn)); + * void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function; */ #define SYS_restore_context (1) diff --git a/nuttx/arch/arm/src/armv7-m/up_assert.c b/nuttx/arch/arm/src/armv7-m/up_assert.c index 77fd0b596f..282ff6a57d 100644 --- a/nuttx/arch/arm/src/armv7-m/up_assert.c +++ b/nuttx/arch/arm/src/armv7-m/up_assert.c @@ -1,8 +1,8 @@ /**************************************************************************** * arch/arm/src/armv7-m/up_assert.c * - * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2009-2010, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -262,7 +262,7 @@ static void up_dumpstate(void) * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* __attribute__ ((noreturn)) */ +static void _up_assert(int errorcode) /* noreturn_function */ { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/arm/src/armv7-m/up_blocktask.c b/nuttx/arch/arm/src/armv7-m/up_blocktask.c old mode 100755 new mode 100644 diff --git a/nuttx/arch/arm/src/armv7-m/up_copystate.c b/nuttx/arch/arm/src/armv7-m/up_copystate.c index a5ad312f5e..e9eede8f99 100644 --- a/nuttx/arch/arm/src/armv7-m/up_copystate.c +++ b/nuttx/arch/arm/src/armv7-m/up_copystate.c @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_copystate.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_doirq.c b/nuttx/arch/arm/src/armv7-m/up_doirq.c index 7ac1ec34db..375054fba6 100644 --- a/nuttx/arch/arm/src/armv7-m/up_doirq.c +++ b/nuttx/arch/arm/src/armv7-m/up_doirq.c @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_doirq.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_fullcontextrestore.S b/nuttx/arch/arm/src/armv7-m/up_fullcontextrestore.S index 3ce51c9cd6..4c77b66b89 100755 --- a/nuttx/arch/arm/src/armv7-m/up_fullcontextrestore.S +++ b/nuttx/arch/arm/src/armv7-m/up_fullcontextrestore.S @@ -69,7 +69,7 @@ * Description: * Restore the current thread context. Full prototype is: * - * void up_fullcontextrestore(uint32_t *restoreregs) __attribute__ ((noreturn)); + * void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function; * * Return: * None diff --git a/nuttx/arch/arm/src/armv7-m/up_hardfault.c b/nuttx/arch/arm/src/armv7-m/up_hardfault.c index a9eea81036..cb3ce9e8a9 100644 --- a/nuttx/arch/arm/src/armv7-m/up_hardfault.c +++ b/nuttx/arch/arm/src/armv7-m/up_hardfault.c @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_hardfault.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_memfault.c b/nuttx/arch/arm/src/armv7-m/up_memfault.c index bbe3f6573f..ab93c7697d 100644 --- a/nuttx/arch/arm/src/armv7-m/up_memfault.c +++ b/nuttx/arch/arm/src/armv7-m/up_memfault.c @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_memfault.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_mpu.c b/nuttx/arch/arm/src/armv7-m/up_mpu.c index 27936562c9..4bb3f21d98 100644 --- a/nuttx/arch/arm/src/armv7-m/up_mpu.c +++ b/nuttx/arch/arm/src/armv7-m/up_mpu.c @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_mpu.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_releasepending.c b/nuttx/arch/arm/src/armv7-m/up_releasepending.c old mode 100755 new mode 100644 diff --git a/nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c b/nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c old mode 100755 new mode 100644 diff --git a/nuttx/arch/arm/src/armv7-m/up_saveusercontext.S b/nuttx/arch/arm/src/armv7-m/up_saveusercontext.S index c8da074303..06eb183d21 100755 --- a/nuttx/arch/arm/src/armv7-m/up_saveusercontext.S +++ b/nuttx/arch/arm/src/armv7-m/up_saveusercontext.S @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_saveusercontext.S * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_sigdeliver.c b/nuttx/arch/arm/src/armv7-m/up_sigdeliver.c index 3c340b8d3c..38673c41d4 100644 --- a/nuttx/arch/arm/src/armv7-m/up_sigdeliver.c +++ b/nuttx/arch/arm/src/armv7-m/up_sigdeliver.c @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_sigdeliver.c * * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_svcall.c b/nuttx/arch/arm/src/armv7-m/up_svcall.c index 5a4d64fe20..d32f0afc2a 100644 --- a/nuttx/arch/arm/src/armv7-m/up_svcall.c +++ b/nuttx/arch/arm/src/armv7-m/up_svcall.c @@ -280,7 +280,7 @@ int up_svcall(int irq, FAR void *context) /* R0=SYS_restore_context: This a restore context command: * - * void up_fullcontextrestore(uint32_t *restoreregs) __attribute__ ((noreturn)); + * void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function; * * At this point, the following values are saved in context: * diff --git a/nuttx/arch/arm/src/armv7-m/up_switchcontext.S b/nuttx/arch/arm/src/armv7-m/up_switchcontext.S index 854f6fa162..762e2066e8 100755 --- a/nuttx/arch/arm/src/armv7-m/up_switchcontext.S +++ b/nuttx/arch/arm/src/armv7-m/up_switchcontext.S @@ -2,7 +2,7 @@ * arch/arm/src/armv7-m/up_switchcontext.S * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/armv7-m/up_unblocktask.c b/nuttx/arch/arm/src/armv7-m/up_unblocktask.c old mode 100755 new mode 100644 diff --git a/nuttx/arch/arm/src/common/up_allocateheap.c b/nuttx/arch/arm/src/common/up_allocateheap.c index fbd1421a74..d4b763196e 100644 --- a/nuttx/arch/arm/src/common/up_allocateheap.c +++ b/nuttx/arch/arm/src/common/up_allocateheap.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_allocateheap.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_arch.h b/nuttx/arch/arm/src/common/up_arch.h index b612f6af25..af29bbf652 100644 --- a/nuttx/arch/arm/src/common/up_arch.h +++ b/nuttx/arch/arm/src/common/up_arch.h @@ -2,7 +2,7 @@ * arch/arm/src/common/up_arch.h * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_checkstack.c b/nuttx/arch/arm/src/common/up_checkstack.c index 6c13f63d13..ac8d9e7b91 100644 --- a/nuttx/arch/arm/src/common/up_checkstack.c +++ b/nuttx/arch/arm/src/common/up_checkstack.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_checkstack.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_etherstub.c b/nuttx/arch/arm/src/common/up_etherstub.c old mode 100755 new mode 100644 index 1c4a71ce68..407e7b45bc --- a/nuttx/arch/arm/src/common/up_etherstub.c +++ b/nuttx/arch/arm/src/common/up_etherstub.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_etherstub.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_idle.c b/nuttx/arch/arm/src/common/up_idle.c index 62557c3a8d..187af76e7d 100644 --- a/nuttx/arch/arm/src/common/up_idle.c +++ b/nuttx/arch/arm/src/common/up_idle.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_idle.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_internal.h b/nuttx/arch/arm/src/common/up_internal.h index 45cb1dcc09..9f20775c09 100644 --- a/nuttx/arch/arm/src/common/up_internal.h +++ b/nuttx/arch/arm/src/common/up_internal.h @@ -40,7 +40,10 @@ * Included Files ****************************************************************************/ +#include + #ifndef __ASSEMBLY__ +# include # include # include #endif @@ -223,7 +226,7 @@ extern void up_boot(void); extern void up_copystate(uint32_t *dest, uint32_t *src); extern void up_decodeirq(uint32_t *regs); extern int up_saveusercontext(uint32_t *saveregs); -extern void up_fullcontextrestore(uint32_t *restoreregs) __attribute__ ((noreturn)); +extern void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function; extern void up_switchcontext(uint32_t *saveregs, uint32_t *restoreregs); /* Signal handling **********************************************************/ diff --git a/nuttx/arch/arm/src/common/up_interruptcontext.c b/nuttx/arch/arm/src/common/up_interruptcontext.c index b67ad523a2..0039692bcd 100644 --- a/nuttx/arch/arm/src/common/up_interruptcontext.c +++ b/nuttx/arch/arm/src/common/up_interruptcontext.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_interruptcontext.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_lowputs.c b/nuttx/arch/arm/src/common/up_lowputs.c index 8b2919a05e..890167e0ef 100644 --- a/nuttx/arch/arm/src/common/up_lowputs.c +++ b/nuttx/arch/arm/src/common/up_lowputs.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_lowputs.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_mdelay.c b/nuttx/arch/arm/src/common/up_mdelay.c index b9b9ffc0e4..2c04476206 100644 --- a/nuttx/arch/arm/src/common/up_mdelay.c +++ b/nuttx/arch/arm/src/common/up_mdelay.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_mdelay.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_modifyreg16.c b/nuttx/arch/arm/src/common/up_modifyreg16.c index e488a6eee3..32ebd6f96a 100644 --- a/nuttx/arch/arm/src/common/up_modifyreg16.c +++ b/nuttx/arch/arm/src/common/up_modifyreg16.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_modifyreg16.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_modifyreg32.c b/nuttx/arch/arm/src/common/up_modifyreg32.c index 8b93f6b84f..a878732847 100644 --- a/nuttx/arch/arm/src/common/up_modifyreg32.c +++ b/nuttx/arch/arm/src/common/up_modifyreg32.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_modifyreg32.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_modifyreg8.c b/nuttx/arch/arm/src/common/up_modifyreg8.c index 2c9dbac250..92ed48eff2 100644 --- a/nuttx/arch/arm/src/common/up_modifyreg8.c +++ b/nuttx/arch/arm/src/common/up_modifyreg8.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_modifyreg8.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_puts.c b/nuttx/arch/arm/src/common/up_puts.c index 4e74f0cdc3..f56dbf07e5 100644 --- a/nuttx/arch/arm/src/common/up_puts.c +++ b/nuttx/arch/arm/src/common/up_puts.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_puts.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_releasestack.c b/nuttx/arch/arm/src/common/up_releasestack.c index 407bd1b544..82f5db88ff 100644 --- a/nuttx/arch/arm/src/common/up_releasestack.c +++ b/nuttx/arch/arm/src/common/up_releasestack.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_releasestack.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_udelay.c b/nuttx/arch/arm/src/common/up_udelay.c index d2d5b74d93..8fcb935223 100644 --- a/nuttx/arch/arm/src/common/up_udelay.c +++ b/nuttx/arch/arm/src/common/up_udelay.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_udelay.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/common/up_usestack.c b/nuttx/arch/arm/src/common/up_usestack.c index f46be0cc90..a3f4f48163 100644 --- a/nuttx/arch/arm/src/common/up_usestack.c +++ b/nuttx/arch/arm/src/common/up_usestack.c @@ -2,7 +2,7 @@ * arch/arm/src/common/up_usestack.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig index 5d0d48f880..8b0cea32e4 100644 --- a/nuttx/arch/arm/src/stm32/Kconfig +++ b/nuttx/arch/arm/src/stm32/Kconfig @@ -3,95 +3,205 @@ # see misc/tools/kconfig-language.txt. # +comment "STM32 Configuration Options" + choice prompt "STM32 Chip Selection" default ARCH_CHIP_STM32F103ZET6 depends on ARCH_CHIP_STM32 -config ARCH_CHIP_STM32F103ZET6 - bool "STM32F103ZET6" +config ARCH_CHIP_STM32F100C8 + bool "STM32F100C8" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + +config ARCH_CHIP_STM32F100CB + bool "STM32F100CB" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + +config ARCH_CHIP_STM32F100R8 + bool "STM32F100R8" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + +config ARCH_CHIP_STM32F100RB + bool "STM32F100RB" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + +config ARCH_CHIP_STM32F100V8 + bool "STM32F100V8" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + +config ARCH_CHIP_STM32F100VB + bool "STM32F100VB" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE config ARCH_CHIP_STM32F103RET6 bool "STM32F103RET6" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_HIGHDENSITY config ARCH_CHIP_STM32F103VCT6 bool "STM32F103VCT6" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_HIGHDENSITY + +config ARCH_CHIP_STM32F103VET6 + bool "STM32F103VET6" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_HIGHDENSITY + +config ARCH_CHIP_STM32F103ZET6 + bool "STM32F103ZET6" + select ARCH_CORTEXM3 + select STM32_STM32F10XX config ARCH_CHIP_STM32F105VBT7 bool "STM32F105VBT7" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_CONNECTIVITYLINE config ARCH_CHIP_STM32F107VC bool "STM32F107VC" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_CONNECTIVITYLINE config ARCH_CHIP_STM32F207IG bool "STM32F207IG" + select ARCH_CORTEXM3 + select STM32_STM32F20XX config ARCH_CHIP_STM32F405RG bool "STM32F405RG" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F405VG bool "STM32F405VG" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F405ZG bool "STM32F405ZG" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F407VE bool "STM32F407VE" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F407VG bool "STM32F407VG" + select ARCH_CORTEXM3 + select STM32_STM32F40XX config ARCH_CHIP_STM32F407ZE bool "STM32F407ZE" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F407ZG bool "STM32F407ZG" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F407IE bool "STM32F407IE" + select ARCH_CORTEXM4 + select STM32_STM32F40XX config ARCH_CHIP_STM32F407IG bool "STM32F407IG" + select ARCH_CORTEXM4 + select STM32_STM32F40XX endchoice config STM32_STM32F10XX bool - default y if ARCH_CHIP_STM32F103ZET6 || ARCH_CHIP_STM32F103RET6 || ARCH_CHIP_STM32F103VCT6 || ARCH_CHIP_STM32F105VBT7 || ARCH_CHIP_STM32F107VC + +config STM32_VALUELINE + bool + +config STM32_HIGHDENSITY + bool config STM32_CONNECTIVITYLINE bool - default y if ARCH_CHIP_STM32F105VBT7 || ARCH_CHIP_STM32F107VC config STM32_STM32F20XX bool - default y if ARCH_CHIP_STM32F207IG config STM32_STM32F40XX bool - default y if ARCH_CHIP_STM32F405RG || ARCH_CHIP_STM32F405VG || ARCH_CHIP_STM32F405ZG || ARCH_CHIP_STM32F407VE || ARCH_CHIP_STM32F407VG || ARCH_CHIP_STM32F407ZE || ARCH_CHIP_STM32F407ZG || ARCH_CHIP_STM32F407IE || ARCH_CHIP_STM32F407IE -config ARCH_CORTEXM3 - bool - default y if !STM32_STM32F40XX +choice + prompt "Toolchain Selection" + default STM32_CODESOURCERYW + depends on ARCH_CHIP_STM32 -config ARCH_CORTEXM4 - bool - default y if STM32_STM32F40XX +config STM32_CODESOURCERYW + bool "CodeSourcery for Windows" + +config STM32_CODESOURCERYL + bool "CodeSourcery for Linux" + +config STM32_ATOLLIC_LITE + bool "Atollic Lite for Windows" + +config STM32_ATOLLIC_PRO + bool "Atollic Pro for Windows" + +config STM32_DEVKITARM + bool "DevkitARM (Windows)" + +config STM32_RAISONANCE + bool "STMicro Raisonance for Windows" + +config STM32_BUILDROOT + bool "NuttX buildroot (Cygwin or Linux)" + +endchoice + +config STM32_DFU + bool "DFU bootloader" + default n + ---help--- + Configure and position code for use with the STMicro DFU bootloader. Do + not select this option if you will load code using JTAG/SWM. menu "STM32 Peripheral Support" config STM32_ADC1 bool "ADC1" default n + select STM32_ADC config STM32_ADC2 bool "ADC2" default n + select STM32_ADC config STM32_ADC3 bool "ADC3" default n + select STM32_ADC config STM32_CRC bool "CRC" @@ -100,10 +210,12 @@ config STM32_CRC config STM32_DMA1 bool "DMA1" default n + select ARCH_DMA config STM32_DMA2 bool "DMA2" default n + select ARCH_DMA config STM32_BKP bool "BKP" @@ -118,11 +230,15 @@ config STM32_BKPSRAM config STM32_CAN1 bool "CAN1" default n + select CAN + select STM32_CAN config STM32_CAN2 bool "CAN2" default n depends on STM32_STM32F20XX || STM32_STM32F40XX + select CAN + select STM32_CAN config STM32_CCMDATARAM bool "CMD/DATA RAM" @@ -137,10 +253,12 @@ config STM32_CRYP config STM32_DAC1 bool "DAC1" default n + select STM32_DAC config STM32_DAC2 bool "DAC2" default n + select STM32_DAC config STM32_DCMI bool "DCMI" @@ -150,11 +268,12 @@ config STM32_DCMI config STM32_ETHMAC bool "Ethernet MAC" default n - depends on STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_CONNECTIVITYLINE || STM32_STM32F20XX || STM32_STM32F40XX config STM32_FSMC bool "FSMC" default n + depends on !STM32_CONNECTIVITYLINE config STM32_HASH bool "HASH" @@ -164,19 +283,23 @@ config STM32_HASH config STM32_I2C1 bool "I2C1" default n + select STM32_I2C config STM32_I2C2 bool "I2C2" default n + select STM32_I2C config STM32_I2C3 bool "I2C3" default n depends on STM32_STM32F20XX || STM32_STM32F40XX + select STM32_I2C config STM32_IWDG bool "IWDG" default n + select WATCHDOG config STM32_OTGFS bool "OTG FS" @@ -200,28 +323,37 @@ config STM32_RNG config STM32_SDIO bool "SDIO" default n + depends on !STM32_CONNECTIVITYLINE config STM32_SPI1 bool "SPI1" default n + select SPI + select STM32_SPI config STM32_SPI2 bool "SPI2" default n + select SPI + select STM32_SPI config STM32_SPI3 bool "SPI3" default n depends on STM32_STM32F20XX || STM32_STM32F40XX + select SPI + select STM32_SPI config STM32_SPI4 bool "SPI4" default n depends on STM32_STM32F10XX + select SPI + select STM32_SPI config STM32_SYSCFG bool "SYSCFG" - default n + default y depends on STM32_STM32F20XX || STM32_STM32F40XX config STM32_TIM1 @@ -289,58 +421,63 @@ config STM32_TIM14 config STM32_USART1 bool "USART1" default n + select ARCH_HAVE_USART1 config STM32_USART2 bool "USART2" default n + select ARCH_HAVE_USART2 config STM32_USART3 bool "USART3" default n + select ARCH_HAVE_USART3 config STM32_UART4 bool "UART4" default n + select ARCH_HAVE_UART4 config STM32_UART5 bool "UART5" default n + select ARCH_HAVE_UART5 config STM32_USART6 bool "USART6" default n depends on STM32_STM32F20XX || STM32_STM32F40XX + select ARCH_HAVE_USART6 config STM32_USB bool "USB Device" default n depends on STM32_STM32F10XX + select USBDEV config STM32_WWDG bool "WWDG" default n + select WATCHDOG endmenu config STM32_ADC bool - default y if STM32_ADC1 || STM32_ADC2 || STM32_ADC3 config STM32_DAC bool - default y if STM32_DAC1 || STM32_ADC2 config STM32_SPI bool - default y if STM32_SPI1 || STM32_SPI2 || STM32_SPI3 || STM32_SPI4 -config STM32_DMA +config STM32_I2C bool - default y if STM32_DMA1 || STM32_DMA2 config STM32_CAN bool - default y if STM32_CAN1 || STM32_CAN2 + +menu "Alternate Pin Mapping" choice prompt "TIM1 Alternate Pin Mappings" @@ -447,18 +584,25 @@ choice config STM32_CAN1_NO_REMAP bool "No pin remapping" -config STM32_CAN1_FULL_REMAP - bool "Full pin remapping" +config STM32_CAN1_REMAP1 + bool "CAN1 alternate pin remapping #1" -config STM32_CAN1_PARTIAL_REMAP - bool "Partial pin remapping" +config STM32_CAN1_REMAP2 + bool "CAN1 alternate pin remapping #2" endchoice config STM32_CAN2_REMAP bool "CAN2 Alternate Pin Mapping" default n - depends on STM32_STM32F10XX && STM32_CAN2 + depends on STM32_CONNECTIVITYLINE && STM32_CAN2 + +config STM32_ETH_REMAP + bool "Ethernet Alternate Pin Mapping" + default n + depends on STM32_CONNECTIVITYLINE && STM32_ETHMAC + +endmenu choice prompt "JTAG Configuration" @@ -497,39 +641,18 @@ config ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG config STM32_CCMEXCLUDE bool "Exclude CCM SRAM from the heap" depends on STM32_STM32F20XX || STM32_STM32F40XX - default y if STM32_DMA1 || STM32_DMA2 + default y if ARCH_DMA ---help--- Exclude CCM SRAM from the HEAP because it cannot be used for DMA. config STM32_FSMC_SRAM bool "External SRAM on FSMC" default n - depends on FSMC + depends on STM32_FSMC + select ARCH_HAVE_HEAP2 ---help--- In addition to internal SRAM, SRAM may also be available through the FSMC. -config HEAP2_BASE - hex "FSMC SRAM base address" - default 0x00000000 - depends on STM32_FSMC_SRAM - ---help--- - The base address of the SRAM in the FSMC address space. - -config HEAP2_END - hex "FSMC SRAM end+1 address" - default 0x00000000 - depends on STM32_FSMC_SRAM - ---help--- - The end (+1) of the SRAM in the FSMC address space - -config ARCH_FPU - bool "FPU support" - default y - depends on ARCH_CORTEXM4 - ---help--- - Build in support for the ARM Cortex-M4 FPU. Only the STM3240xxx supports - a floating point unit (FPU) - config STM32_TIM1_PWM bool "TIM1 PWM" default n @@ -1420,342 +1543,48 @@ config STM32_TIM14_DAC2 endchoice -menu "USART1 Configuration" - depends on STM32_USART1 - -config USART1_SERIAL_CONSOLE - bool "USART1 serial console" - default y - ---help--- - Selects the USART1 for the console and ttys0 (default is the USART1). - -config USART1_RXBUFSIZE - int "USART1 Rx buffer size" - default 256 - ---help--- - Characters are buffered as received. This specific the size of the receive - buffer. - -config USART1_TXBUFSIZE - int "USART1 Tx buffer size" - default 256 - ---help--- - Characters are buffered before being sent. This specific the size of the - transmit buffer - -config USART1_BAUD - int "USART1 BAUD" - default 11520 - ---help--- - The configured BAUD of the UART - -config USART1_BITS - int "USART1 number of bits" - default 8 - ---help--- - The number of bits. Must be either 7 or 8. - -config USART1_PARITY - int "USART1 parity" - default 0 - ---help--- - 0=no parity, 1=odd parity, 2=even parity - -config USART1_2STOP - bool "USART1 two stop bits" - default n - ---help--- - Two stop bits - config USART1_RXDMA bool "USART1 Rx DMA" default n - depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA2 + depends on STM32_STM32F40XX && STM32_DMA2 ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors -endmenu - -menu "USART2 Configuration" - depends on STM32_USART2 - -config USART2_SERIAL_CONSOLE - bool "USART2 serial console" - default y if !STM32_USART1 - ---help--- - Selects the USART2 for the console and ttys0 (default is the USART2). - -config USART2_RXBUFSIZE - int "USART2 Rx buffer size" - default 256 - ---help--- - Characters are buffered as received. This specific the size of the receive - buffer. - -config USART2_TXBUFSIZE - int "USART2 Tx buffer size" - default 256 - ---help--- - Characters are buffered before being sent. This specific the size of the - transmit buffer - -config USART2_BAUD - int "USART2 BAUD" - default 11520 - ---help--- - The configured BAUD of the UART - -config USART2_BITS - int "USART2 number of bits" - default 8 - ---help--- - The number of bits. Must be either 7 or 8. - -config USART2_PARITY - int "USART2 parity" - default 0 - ---help--- - 0=no parity, 1=odd parity, 2=even parity - -config USART2_2STOP - bool "USART2 two stop bits" - default n - ---help--- - Two stop bits - config USART2_RXDMA bool "USART2 Rx DMA" default n - depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1 + depends on STM32_STM32F40XX && STM32_DMA1 ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors -endmenu - -menu "USART3 Configuration" - depends on STM32_USART3 - -config USART3_SERIAL_CONSOLE - bool "USART3 serial console" - default y if !STM32_USART1 && !STM32_USART2 - ---help--- - Selects the USART3 for the console and ttys0 (default is the USART3). - -config USART3_RXBUFSIZE - int "USART3 Rx buffer size" - default 256 - ---help--- - Characters are buffered as received. This specific the size of the receive - buffer. - -config USART3_TXBUFSIZE - int "USART3 Tx buffer size" - default 256 - ---help--- - Characters are buffered before being sent. This specific the size of the - transmit buffer - -config USART3_BAUD - int "USART3 BAUD" - default 11520 - ---help--- - The configured BAUD of the UART - -config USART3_BITS - int "USART3 number of bits" - default 8 - ---help--- - The number of bits. Must be either 7 or 8. - -config USART3_PARITY - int "USART3 parity" - default 0 - ---help--- - 0=no parity, 1=odd parity, 2=even parity - -config USART3_2STOP - bool "USART3 two stop bits" - default n - ---help--- - Two stop bits - config USART3_RXDMA bool "USART3 Rx DMA" default n - depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1 + depends on STM32_STM32F40XX && STM32_DMA1 ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors -endmenu - -menu "UART4 Configuration" - depends on STM32_UART4 - -config USART4_SERIAL_CONSOLE - bool "UART4 serial console" - default y if !STM32_USART1 && !STM32_USART2 && !STM32_USART3 - ---help--- - Selects the UART4 for the console and ttys0 (default is the USART1). - -config USART4_RXBUFSIZE - int "UART4 Rx buffer size" - default 256 - ---help--- - Characters are buffered as received. This specific the size of the receive - buffer. - -config USART4_TXBUFSIZE - int "UART4 Tx buffer size" - default 256 - ---help--- - Characters are buffered before being sent. This specific the size of the - transmit buffer - -config USART4_BAUD - int "UART4 BAUD" - default 11520 - ---help--- - The configured BAUD of the UART - -config USART4_BITS - int "UART4 number of bits" - default 8 - ---help--- - The number of bits. Must be either 7 or 8. - -config USART4_PARITY - int "UART4 parity" - default 0 - ---help--- - 0=no parity, 1=odd parity, 2=even parity - -config USART4_2STOP - bool "UART4 two stop bits" +config UART4_RXDMA + bool "UART4 Rx DMA" default n - ---help--- - Two stop bits - -config USART4_RXDMA - bool "USART4 Rx DMA" - default n - depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1 + depends on STM32_STM32F40XX && STM32_DMA1 ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors -endmenu - -menu "UART5 Configuration" - depends on STM32_UART5 - -config USART5_SERIAL_CONSOLE - bool "UART5 serial console" - default y if !STM32_USART1 && !STM32_USART2 && !STM32_USART3 && !STM32_UART4 - ---help--- - Selects the UART5 for the console and ttys0 (default is the USART1). - -config USART5_RXBUFSIZE - int "USART5 Rx buffer size" - default 256 - ---help--- - Characters are buffered as received. This specific the size of the receive - buffer. - -config USART5_TXBUFSIZE - int "UART5 Tx buffer size" - default 256 - ---help--- - Characters are buffered before being sent. This specific the size of the - transmit buffer - -config USART5_BAUD - int "UART5 BAUD" - default 11520 - ---help--- - The configured BAUD of the UART - -config USART5_BITS - int "UART5 number of bits" - default 8 - ---help--- - The number of bits. Must be either 7 or 8. - -config USART5_PARITY - int "UART5 parity" - default 0 - ---help--- - 0=no parity, 1=odd parity, 2=even parity - -config USART5_2STOP - bool "UART5 two stop bits" +config UART5_RXDMA + bool "UART5 Rx DMA" default n - ---help--- - Two stop bits - -config USART5_RXDMA - bool "USART5 Rx DMA" - default n - depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1 + depends on STM32_STM32F40XX && STM32_DMA1 ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors -endmenu - -menu "USART6 Configuration" - depends on STM32_USART6 - -config USART6_SERIAL_CONSOLE - bool "USART6 serial console" - default y if !STM32_USART1 && !STM32_USART2 && !STM32_USART3 && !STM32_UART4 && !STM32_UART5 - ---help--- - Selects the USART6 for the console and ttys0 (default is the USART6). - -config USART6_RXBUFSIZE - int "USART6 Rx buffer size" - default 256 - ---help--- - Characters are buffered as received. This specific the size of the receive - buffer. - -config USART6_TXBUFSIZE - int "USART6 Tx buffer size" - default 256 - ---help--- - Characters are buffered before being sent. This specific the size of the - transmit buffer - -config USART6_BAUD - int "USART6 BAUD" - default 11520 - ---help--- - The configured BAUD of the UART - -config USART6_BITS - int "USART6 number of bits" - default 8 - ---help--- - The number of bits. Must be either 7 or 8. - -config USART6_PARITY - int "USART6 parity" - default 0 - ---help--- - 0=no parity, 1=odd parity, 2=even parity - -config USART6_2STOP - bool "USART6 two stop bits" - default n - ---help--- - Two stop bits - config USART6_RXDMA bool "USART6 Rx DMA" default n - depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA2 + depends on STM32_STM32F40XX && STM32_DMA2 ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors -endmenu - config SERIAL_TERMIOS bool "Serial driver TERMIOS supported" depends on STM32_USART1 || STM32_USART2 || STM32_USART3 || STM32_UART4 || STM32_UART5 || STM32_USART6 @@ -1784,6 +1613,46 @@ config STM32_SPI_DMA endmenu +menu "I2C Configuration" + depends on STM32_I2C + +config STM32_I2C_DYNTIMEO + bool "Use dynamic timeouts" + default n + depends on STM32_I2C + +config STM32_I2C_DYNTIMEO_USECPERBYTE + int "Timeout Microseconds per Byte" + default 0 + depends on STM32_I2C_DYNTIMEO + +config STM32_I2C_DYNTIMEO_STARTSTOP + int "Timeout for Start/Stop (Milliseconds)" + default 5000 + depends on STM32_I2C_DYNTIMEO + +config STM32_I2CTIMEOSEC + int "Timeout seconds" + default 0 + depends on STM32_I2C + +config STM32_I2CTIMEOMS + int "Timeout Milliseconds" + default 500 + depends on STM32_I2C && !STM32_I2C_DYNTIMEO + +config STM32_I2CTIMEOTICKS + int "Timeout for Done and Stop (ticks)" + default 500 + depends on STM32_I2C && !STM32_I2C_DYNTIMEO + +config STM32_I2C_DUTY16_9 + bool "Frequency with Tlow/Thigh = 16/9 " + default n + depends on STM32_I2C + +endmenu + menu "SDIO Configuration" depends on STM32_SDIO @@ -1819,32 +1688,60 @@ menu "Ethernet MAC configuration" config STM32_PHYADDR int "PHY address" + default 1 ---help--- - The 5-bit address of the PHY on the board + The 5-bit address of the PHY on the board. Default: 1 config STM32_MII bool "Use MII interface" default n + depends on STM32_ETHMAC ---help--- Support Ethernet MII interface. +choice + prompt "MII clock configuration" + default STM32_MII_MCO if STM32_STM32F10XX + default STM32_MII_MCO1 if STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_MII + +config STM32_MII_MCO + bool "Use MC0 as MII clock" + depends on STM32_STM32F10XX + ---help--- + Use MCO to clock the MII interface. Default: Use MC0 + +config STM32_MII_MCO1 + bool "Use MC01 as MII clock" + depends on (STM32_STM32F20XX || STM32_STM32F40XX) + ---help--- + Use MCO1 to clock the MII interface. Default: Use MC01 + config STM32_MII_MCO2 bool "Use MC02 as MII clock" - default n - depends on STM32_MII + depends on (STM32_STM32F20XX || STM32_STM32F40XX) ---help--- Use MCO2 to clock the MII interface. Default: Use MC01 +config STM32_MII_EXTCLK + bool "External MII clock" + ---help--- + Clocking is provided by external logic. Don't use MCO for MII + clock. Default: Use MC0[1] + +endchoice + config STM32_AUTONEG bool "Use autonegtiation" default y + depends on STM32_ETHMAC ---help--- Use PHY autonegotion to determine speed and mode config STM32_ETHFD bool "Full duplex" default n - depends on !STM32_AUTONEG + depends on STM32_ETHMAC && !STM32_AUTONEG ---help--- If STM32_AUTONEG is not defined, then this may be defined to select full duplex mode. Default: half-duplex @@ -1852,7 +1749,7 @@ config STM32_ETHFD config STM32_ETH100MBPS bool "100 Mbps" default n - depends on !STM32_AUTONEG + depends on STM32_ETHMAC && !STM32_AUTONEG ---help--- If STM32_AUTONEG is not defined, then this may be defined to select 100 MBps speed. Default: 10 Mbps @@ -1896,6 +1793,7 @@ config STM32_PHYSR_FULLDUPLEX config STM32_ETH_PTP bool "Precision Time Protocol (PTP)" default n + depends on STM32_ETHMAC ---help--- Precision Time Protocol (PTP). Not supported but some hooks are indicated with this condition. @@ -1905,8 +1803,89 @@ endmenu config STM32_RMII bool default y if !STM32_MII + depends on STM32_ETHMAC -config STM32_MII_MCO1 - bool - default y if !STM32_MII_MCO2 - depends on STM32_MII +choice + prompt "RMII clock configuration" + default STM32_RMII_MCO if STM32_STM32F10XX + default STM32_RMII_MCO1 if STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_RMII + +config STM32_RMII_MCO + bool "Use MC0 as RMII clock" + depends on STM32_STM32F10XX + ---help--- + Use MCO to clock the RMII interface. Default: Use MC0 + +config STM32_RMII_MCO1 + bool "Use MC01 as RMII clock" + depends on (STM32_STM32F20XX || STM32_STM32F40XX) + ---help--- + Use MCO1 to clock the RMII interface. Default: Use MC01 + +config STM32_RMII_MCO2 + bool "Use MC02 as RMII clock" + depends on (STM32_STM32F20XX || STM32_STM32F40XX) + ---help--- + Use MCO2 to clock the RMII interface. Default: Use MC01 + +config STM32_RMII_EXTCLK + bool "External RMII clock" + ---help--- + Clocking is provided by external logic. Don't use MCO for RMII + clock. Default: Use MC0[1] + +endchoice + +menu "USB Host Configuration" + +config STM32_OTGFS_RXFIFO_SIZE + int "Rx Packet Size" + default 128 + depends on USBHOST && STM32_OTGFS + ---help--- + Size of the RX FIFO in 32-bit words. Default 128 (512 bytes) + +config STM32_OTGFS_NPTXFIFO_SIZE + int "Non-periodic Tx FIFO Size" + default 96 + depends on USBHOST && STM32_OTGFS + ---help--- + Size of the non-periodic Tx FIFO in 32-bit words. Default 96 (384 bytes) + +config STM32_OTGFS_PTXFIFO_SIZE + int "Periodic Tx FIFO size" + default 128 + depends on USBHOST && STM32_OTGFS + ---help--- + Size of the periodic Tx FIFO in 32-bit words. Default 96 (384 bytes) + +config STM32_OTGFS_DESCSIZE + int "Descriptor Size" + default 128 + depends on USBHOST && STM32_OTGFS + ---help--- + Maximum size to allocate for descriptor memory descriptor. Default: 128 + +config STM32_OTGFS_SOFINTR + bool "Enable SOF interrupts" + default n + depends on USBHOST && STM32_OTGFS + ---help--- + Enable SOF interrupts. Why would you ever want to do that? + +config STM32_USBHOST_REGDEBUG + bool "Register-Level Debug" + default n + depends on USBHOST && STM32_OTGFS + ---help--- + Enable very low-level register access debug. Depends on DEBUG. + +config STM32_USBHOST_PKTDUMP + bool "Packet Dump Debug" + default n + depends on USBHOST && STM32_OTGFS + ---help--- + Dump all incoming and outgoing USB packets. Depends on DEBUG. + +endmenu diff --git a/nuttx/arch/arm/src/stm32/Make.defs b/nuttx/arch/arm/src/stm32/Make.defs index 1deb23189e..32e84a78a7 100644 --- a/nuttx/arch/arm/src/stm32/Make.defs +++ b/nuttx/arch/arm/src/stm32/Make.defs @@ -81,6 +81,12 @@ CMN_CSRCS += stm32_otgfsdev.c endif endif +ifeq ($(CONFIG_USBHOST),y) +ifeq ($(CONFIG_STM32_OTGFS),y) +CMN_CSRCS += stm32_otgfshost.c +endif +endif + ifeq ($(CONFIG_ARMV7M_CMNVECTOR),y) CHIP_ASRCS += stm32_vectors.S endif diff --git a/nuttx/arch/arm/src/stm32/chip.h b/nuttx/arch/arm/src/stm32/chip.h index cc3ee1f96b..3fac597ef2 100644 --- a/nuttx/arch/arm/src/stm32/chip.h +++ b/nuttx/arch/arm/src/stm32/chip.h @@ -48,24 +48,51 @@ /* Include the chip pin configuration file */ +/* STM32 F1 Family ******************************************************************/ #if defined(CONFIG_STM32_STM32F10XX) + +/* STM32F100 Value Line */ + # if defined(CONFIG_STM32_VALUELINE) # include "chip/stm32f100_pinmap.h" -# elif defined(CONFIG_ARCH_CHIP_STM32F103ZET6) -# include "chip/stm32f103ze_pinmap.h" + +/* STM32 F103 High Density Family */ +/* STM32F103RC, STM32F103RD, and STM32F103RE are all provided in 64 pin packages and differ + * only in the available FLASH and SRAM. + */ + # elif defined(CONFIG_ARCH_CHIP_STM32F103RET6) # include "chip/stm32f103re_pinmap.h" -# elif defined(CONFIG_ARCH_CHIP_STM32F103VCT6) + +/* STM32F103VC, STM32F103VD, and STM32F103VE are all provided in 100 pin packages and differ + * only in the available FLASH and SRAM. + */ + +# elif defined(CONFIG_ARCH_CHIP_STM32F103VCT6) || defined(CONFIG_ARCH_CHIP_STM32F103VET6) # include "chip/stm32f103vc_pinmap.h" + +/* STM32F103ZC, STM32F103ZD, and STM32F103ZE are all provided in 144 pin packages and differ + * only in the available FLASH and SRAM. + */ +# elif defined(CONFIG_ARCH_CHIP_STM32F103ZET6) +# include "chip/stm32f103ze_pinmap.h" + +/* STM32 F105/F107 Connectivity Line */ + # elif defined(CONFIG_ARCH_CHIP_STM32F105VBT7) # include "chip/stm32f105vb_pinmap.h" + # elif defined(CONFIG_ARCH_CHIP_STM32F107VC) # include "chip/stm32f107vc_pinmap.h" # else # error "Unsupported STM32F10XXX chip" # endif + +/* STM32 F2 Family ******************************************************************/ #elif defined(CONFIG_STM32_STM32F20XX) # include "chip/stm32f20xxx_pinmap.h" + +/* STM32 F4 Family ******************************************************************/ #elif defined(CONFIG_STM32_STM32F40XX) # include "chip/stm32f40xxx_pinmap.h" #else diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_bkp.h b/nuttx/arch/arm/src/stm32/chip/stm32_bkp.h index 1788bdee08..5bda839a88 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32_bkp.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32_bkp.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32_bkp.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_exti.h b/nuttx/arch/arm/src/stm32/chip/stm32_exti.h index 82477db549..5386a260fb 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32_exti.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32_exti.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32_exti.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_memorymap.h b/nuttx/arch/arm/src/stm32/chip/stm32_memorymap.h index a53c7441cf..36813b5651 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32_memorymap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32_memorymap.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32_memorymap.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_otgfs.h b/nuttx/arch/arm/src/stm32/chip/stm32_otgfs.h index d3bf7eb547..ee34172cfd 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32_otgfs.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32_otgfs.h @@ -46,6 +46,18 @@ /**************************************************************************************************** * Pre-processor Definitions ****************************************************************************************************/ +/* General definitions */ + +#define OTGFS_EPTYPE_CTRL (0) /* Control */ +#define OTGFS_EPTYPE_ISOC (1) /* Isochronous */ +#define OTGFS_EPTYPE_BULK (2) /* Bulk */ +#define OTGFS_EPTYPE_INTR (3) /* Interrupt */ + +#define OTGFS_PID_DATA0 (0) +#define OTGFS_PID_DATA2 (1) +#define OTGFS_PID_DATA1 (2) +#define OTGFS_PID_MDATA (3) /* Non-control */ +#define OTGFS_PID_SETUP (3) /* Control */ /* Register Offsets *********************************************************************************/ /* Core global control and status registers */ @@ -125,8 +137,8 @@ #define STM32_OTGFS_HCTSIZ3_OFFSET 0x0570 /* Host channel-3 interrupt register */ #define STM32_OTGFS_HCTSIZ4_OFFSET 0x0590 /* Host channel-4 interrupt register */ #define STM32_OTGFS_HCTSIZ5_OFFSET 0x05b0 /* Host channel-5 interrupt register */ -#define STM32_OTGFS_HCTSIZ6_OFFSET 0x05d9 /* Host channel-6 interrupt register */ -#define STM32_OTGFS_HCTSIZ7_OFFSET 0x05f9 /* Host channel-7 interrupt register */ +#define STM32_OTGFS_HCTSIZ6_OFFSET 0x05d0 /* Host channel-6 interrupt register */ +#define STM32_OTGFS_HCTSIZ7_OFFSET 0x05f0 /* Host channel-7 interrupt register */ /* Device-mode control and status registers */ @@ -193,6 +205,10 @@ #define STM32_OTGFS_DOEPTSIZ2_OFFSET 0x00b50 /* Device OUT endpoint-2 transfer size register */ #define STM32_OTGFS_DOEPTSIZ3_OFFSET 0x00b70 /* Device OUT endpoint-3 transfer size register */ +/* Power and clock gating registers */ + +#define STM32_OTGFS_PCGCCTL_OFFSET 0x0e00 /* Power and clock gating control register */ + /* Data FIFO (DFIFO) access registers */ #define STM32_OTGFS_DFIFO_DEP_OFFSET(n) (0x1000 + ((n) << 12)) @@ -204,15 +220,11 @@ #define STM32_OTGFS_DFIFO_DEP1_OFFSET 0x2000 /* 0x2000-0x2ffc Device IN/OUT Endpoint 1 DFIFO Write/Read Access */ #define STM32_OTGFS_DFIFO_HCH1_OFFSET 0x2000 /* 0x2000-0x2ffc Host OUT/IN Channel 1 DFIFO Read/Write Access */ -#define STM32_OTGFS_DFIFO_DEP2_OFFSET 0x3000 /* 0x3000-0x3ffc Device IN/OUT Endpoint 1 DFIFO Write/Read Access */ -#define STM32_OTGFS_DFIFO_HCH2_OFFSET 0x3000 /* 0x3000-0x3ffc Host OUT/IN Channel 1 DFIFO Read/Write Access */ +#define STM32_OTGFS_DFIFO_DEP2_OFFSET 0x3000 /* 0x3000-0x3ffc Device IN/OUT Endpoint 2 DFIFO Write/Read Access */ +#define STM32_OTGFS_DFIFO_HCH2_OFFSET 0x3000 /* 0x3000-0x3ffc Host OUT/IN Channel 2 DFIFO Read/Write Access */ -#define STM32_OTGFS_DFIFO_DEP3_OFFSET 0x4000 /* 0x4000-0x4ffc Device IN/OUT Endpoint 1 DFIFO Write/Read Access */ -#define STM32_OTGFS_DFIFO_HCH3_OFFSET 0x4000 /* 0x4000-0x4ffc Host OUT/IN Channel 1 DFIFO Read/Write Access */ - -/* Power and clock gating registers */ - -#define STM32_OTGFS_PCGCCTL_OFFSET 0x0e00 /* Power and clock gating control register */ +#define STM32_OTGFS_DFIFO_DEP3_OFFSET 0x4000 /* 0x4000-0x4ffc Device IN/OUT Endpoint 3 DFIFO Write/Read Access */ +#define STM32_OTGFS_DFIFO_HCH3_OFFSET 0x4000 /* 0x4000-0x4ffc Host OUT/IN Channel 3 DFIFO Read/Write Access */ /* Register Addresses *******************************************************************************/ @@ -349,6 +361,10 @@ #define STM32_OTGFS_DOEPTSIZ2 (STM32_OTGFS_BASE+STM32_OTGFS_DOEPTSIZ2_OFFSET) #define STM32_OTGFS_DOEPTSIZ3 (STM32_OTGFS_BASE+STM32_OTGFS_DOEPTSIZ3_OFFSET) +/* Power and clock gating registers */ + +#define STM32_OTGFS_PCGCCTL (STM32_OTGFS_BASE+STM32_OTGFS_PCGCCTL_OFFSET) + /* Data FIFO (DFIFO) access registers */ #define STM32_OTGFS_DFIFO_DEP(n) (STM32_OTGFS_BASE+STM32_OTGFS_DFIFO_DEP_OFFSET(n)) @@ -366,10 +382,6 @@ #define STM32_OTGFS_DFIFO_DEP3 (STM32_OTGFS_BASE+STM32_OTGFS_DFIFO_DEP3_OFFSET) #define STM32_OTGFS_DFIFO_HCH3 (STM32_OTGFS_BASE+STM32_OTGFS_DFIFO_HCH3_OFFSET) -/* Power and clock gating registers */ - -#define STM32_OTGFS_PCGCCTL (STM32_OTGFS_BASE+STM32_OTGFS_PCGCCTL_OFFSET) - /* Register Bitfield Definitions ********************************************************************/ /* Core global control and status registers */ @@ -411,7 +423,9 @@ #define OTGFS_GUSBCFG_TOCAL_SHIFT (0) /* Bits 0-2: FS timeout calibration */ #define OTGFS_GUSBCFG_TOCAL_MASK (7 << OTGFS_GUSBCFG_TOCAL_SHIFT) - /* Bits 3-6: Reserved, must be kept at reset value */ + /* Bits 3-5: Reserved, must be kept at reset value */ +#define OTGFS_GUSBCFG_PHYSEL (1 << 6) /* Bit 6: Full Speed serial transceiver select */ + /* Bit 7: Reserved, must be kept at reset value */ #define OTGFS_GUSBCFG_SRPCAP (1 << 8) /* Bit 8: SRP-capable */ #define OTGFS_GUSBCFG_HNPCAP (1 << 9) /* Bit 9: HNP-capable */ #define OTGFS_GUSBCFG_TRDT_SHIFT (10) /* Bits 10-13: USB turnaround time */ @@ -491,7 +505,7 @@ #define OTGFS_GRXSTSH_PKTSTS_MASK (15 << OTGFS_GRXSTSH_PKTSTS_SHIFT) # define OTGFS_GRXSTSH_PKTSTS_INRECVD (2 << OTGFS_GRXSTSH_PKTSTS_SHIFT) /* IN data packet received */ # define OTGFS_GRXSTSH_PKTSTS_INDONE (3 << OTGFS_GRXSTSH_PKTSTS_SHIFT) /* IN transfer completed */ -# define OTGFS_GRXSTSH_PKTSTS_DTOGERR (2 << OTGFS_GRXSTSH_PKTSTS_SHIFT) /* Data toggle error */ +# define OTGFS_GRXSTSH_PKTSTS_DTOGERR (5 << OTGFS_GRXSTSH_PKTSTS_SHIFT) /* Data toggle error */ # define OTGFS_GRXSTSH_PKTSTS_HALTED (7 << OTGFS_GRXSTSH_PKTSTS_SHIFT) /* Channel halted */ /* Bits 21-31: Reserved, must be kept at reset value */ /* Receive status debug read/OTG status read and pop registers (device mode) */ @@ -559,7 +573,7 @@ # define OTGFS_HNPTXSTS_EPNUM_SHIFT (27) /* Bits 27-30: Endpoint number */ # define OTGFS_HNPTXSTS_EPNUM_MASK (15 << OTGFS_HNPTXSTS_EPNUM_SHIFT) /* Bit 31 Reserved, must be kept at reset value */ -/* general core configuration register */ +/* General core configuration register */ /* Bits 15:0 Reserved, must be kept at reset value */ #define OTGFS_GCCFG_PWRDWN (1 << 16) /* Bit 16: Power down */ /* Bit 17 Reserved, must be kept at reset value */ @@ -625,9 +639,11 @@ # define OTGFS_HPTXSTS_TYPE_HALT (3 << OTGFS_HPTXSTS_TYPE_SHIFT) /* Disable channel command */ # define OTGFS_HPTXSTS_EPNUM_SHIFT (27) /* Bits 27-30: Endpoint number */ # define OTGFS_HPTXSTS_EPNUM_MASK (15 << OTGFS_HPTXSTS_EPNUM_SHIFT) +# define OTGFS_HPTXSTS_CHNUM_SHIFT (27) /* Bits 27-30: Channel number */ +# define OTGFS_HPTXSTS_CHNUM_MASK (15 << OTGFS_HPTXSTS_CHNUM_SHIFT) # define OTGFS_HPTXSTS_ODD (1 << 24) /* Bit 31: Send in odd (vs even) frame */ -/* Host all channels interrupt and all channels interrupt mask registers */ +/* Host all channels interrupt and all channels interrupt mask registers */ #define OTGFS_HAINT(n) (1 << (n)) /* Bits 15:0 HAINTM: Channel interrupt */ @@ -664,7 +680,7 @@ /* Host channel-n characteristics register */ -#define OTGFS_HCCHAR0_MPSIZ_SHIFT (0) /* Bits 0-10: Maximum packet size */ +#define OTGFS_HCCHAR_MPSIZ_SHIFT (0) /* Bits 0-10: Maximum packet size */ #define OTGFS_HCCHAR_MPSIZ_MASK (0x7ff << OTGFS_HCCHAR_MPSIZ_SHIFT) #define OTGFS_HCCHAR_EPNUM_SHIFT (11) /* Bits 11-14: Endpoint number */ #define OTGFS_HCCHAR_EPNUM_MASK (15 << OTGFS_HCCHAR_EPNUM_SHIFT) @@ -695,7 +711,7 @@ #define OTGFS_HCINT_STALL (1 << 3) /* Bit 3: STALL response received interrupt */ #define OTGFS_HCINT_NAK (1 << 4) /* Bit 4: NAK response received interrupt */ #define OTGFS_HCINT_ACK (1 << 5) /* Bit 5: ACK response received/transmitted interrupt */ -#define OTGFS_HCINTMSK_NYET (1 << 6) /* Bit 6: response received interrupt mask */ +#define OTGFS_HCINT_NYET (1 << 6) /* Bit 6: Response received interrupt */ #define OTGFS_HCINT_TXERR (1 << 7) /* Bit 7: Transaction error */ #define OTGFS_HCINT_BBERR (1 << 8) /* Bit 8: Babble error */ #define OTGFS_HCINT_FRMOR (1 << 9) /* Bit 9: Frame overrun */ @@ -712,7 +728,8 @@ # define OTGFS_HCTSIZ_DPID_DATA0 (0 << OTGFS_HCTSIZ_DPID_SHIFT) # define OTGFS_HCTSIZ_DPID_DATA2 (1 << OTGFS_HCTSIZ_DPID_SHIFT) # define OTGFS_HCTSIZ_DPID_DATA1 (2 << OTGFS_HCTSIZ_DPID_SHIFT) -# define OTGFS_HCTSIZ_DPID_MDATA (3 << OTGFS_HCTSIZ_DPID_SHIFT) +# define OTGFS_HCTSIZ_DPID_MDATA (3 << OTGFS_HCTSIZ_DPID_SHIFT) /* Non-control */ +# define OTGFS_HCTSIZ_PID_SETUP (3 << OTGFS_HCTSIZ_DPID_SHIFT) /* Control */ /* Bit 31 Reserved, must be kept at reset value */ /* Device-mode control and status registers */ @@ -989,8 +1006,6 @@ # define OTGFS_DOEPTSIZ_RXDPID_DATA1 (2 << OTGFS_DOEPTSIZ_RXDPID_SHIFT) # define OTGFS_DOEPTSIZ_RXDPID_MDATA (3 << OTGFS_DOEPTSIZ_RXDPID_SHIFT) /* Bit 31: Reserved, must be kept at reset value */ -/* Power and clock gating registers */ - /* Power and clock gating control register */ #define OTGFS_PCGCCTL_STPPCLK (1 << 0) /* Bit 0: Stop PHY clock */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h index 18e8435f77..01d6e1ce06 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h @@ -4,7 +4,7 @@ * Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved. * Copyright (C) 2012 Michael Smith. All Rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * Uros Platise * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f103re_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f103re_pinmap.h index d0b5a6386b..042f57f74a 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f103re_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f103re_pinmap.h @@ -3,7 +3,7 @@ * * Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * Uros Platise * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h index fde8dd9358..7a5ec3381e 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32f105vb_pinmap.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h index 82f1fa5e78..9bbc214798 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32f107vc_pinmap.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -93,41 +93,41 @@ #define GPIO_ETH_MDC (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN1) #define GPIO_ETH_MDIO (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN2) -#define GPIO_ETH_MIICOL (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN3) -#define GPIO_ETH_MIICRSWKUP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN0) -#define GPIO_ETH_MIIRXCLK (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN1) +#define GPIO_ETH_MII_COL (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN3) +#define GPIO_ETH_MII_CRS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN0) +#define GPIO_ETH_MII_RX_CLK (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN1) #if defined(CONFIG_STM32_ETH_REMAP) -# define GPIO_ETH_MIIRXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN9) -# define GPIO_ETH_MIIRXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN10) -# define GPIO_ETH_MIIRXD2 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN11) -# define GPIO_ETH_MIIRXD3 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN12) -# define GPIO_ETH_MIIRXDV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN8) +# define GPIO_ETH_MII_RXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN9) +# define GPIO_ETH_MII_RXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN10) +# define GPIO_ETH_MII_RXD2 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN11) +# define GPIO_ETH_MII_RXD3 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN12) +# define GPIO_ETH_MII_RX_DV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN8) #else -# define GPIO_ETH_MIIRXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN4) -# define GPIO_ETH_MIIRXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN5) -# define GPIO_ETH_MIIRXD2 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN0) -# define GPIO_ETH_MIIRXD3 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN1) -# define GPIO_ETH_MIIRXDV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) +# define GPIO_ETH_MII_RXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN4) +# define GPIO_ETH_MII_RXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN5) +# define GPIO_ETH_MII_RXD2 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN0) +# define GPIO_ETH_MII_RXD3 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN1) +# define GPIO_ETH_MII_RX_DV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) #endif -#define GPIO_ETH_MIIRXER (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10) -#define GPIO_ETH_MIITXCLK (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN3) -#define GPIO_ETH_MIITXD0 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) -#define GPIO_ETH_MIITXD1 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13) -#define GPIO_ETH_MIITXD2 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN2) -#define GPIO_ETH_MIITXD3 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8) -#define GPIO_ETH_MIITXEN (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN11) +#define GPIO_ETH_MII_RX_ER (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10) +#define GPIO_ETH_MII_TX_CLK (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN3) +#define GPIO_ETH_MII_TXD0 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) +#define GPIO_ETH_MII_TXD1 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13) +#define GPIO_ETH_MII_TXD2 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN2) +#define GPIO_ETH_MII_TXD3 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8) +#define GPIO_ETH_MII_TX_EN (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN11) #define GPIO_ETH_PPS_OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5) #define GPIO_ETH_RMII_REF_CLK (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN1) #if defined(CONFIG_STM32_ETH_REMAP) -# define GPIO_ETH_RMII_CRS_DV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN8) -# define GPIO_ETH_RMII_RXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN9) -# define GPIO_ETH_RMII_RXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN10) +# define GPIO_ETH_RMII_CRS_DV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN8) +# define GPIO_ETH_RMII_RXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN9) +# define GPIO_ETH_RMII_RXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTD|GPIO_PIN10) #else -# define GPIO_ETH_RMII_CRS_DV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) -# define GPIO_ETH_RMII_RXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN4) -# define GPIO_ETH_RMII_RXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN5) +# define GPIO_ETH_RMII_CRS_DV (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) +# define GPIO_ETH_RMII_RXD0 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN4) +# define GPIO_ETH_RMII_RXD1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN5) #endif #define GPIO_ETH_RMII_TXD0 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) #define GPIO_ETH_RMII_TXD1 (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13) diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h index 80b38a89fe..ed1bc26259 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,6 +47,9 @@ #define STM32_SRAMBB_BASE 0x22000000 #define STM32_PERIPH_BASE 0x40000000 +#define STM32_REGION_MASK 0xf0000000 +#define STM32_IS_SRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_SRAM_BASE) + /* Register Base Address ************************************************************/ /* APB1 bus */ @@ -123,7 +126,13 @@ /* Flexible SRAM controller (FSMC) */ -#define STM32_FSMC_BASE 0xa0000000 +#define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */ +#define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */ +#define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */ +#define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/ +#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1) + +#define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */ /* Other registers -- see armv7-m/nvic.h for standard Cortex-M3 registers in this * address range diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_memorymap.h b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_memorymap.h index 2fa7056076..777b9595fe 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_memorymap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_memorymap.h @@ -46,11 +46,19 @@ #define STM32_SRAM_BASE 0x20000000 /* 0x20000000-0x3fffffff: 512Mb sram block */ #define STM32_PERIPH_BASE 0x40000000 /* 0x40000000-0x5fffffff: 512Mb peripheral block */ #define STM32_FSMC_BASE12 0x60000000 /* 0x60000000-0x7fffffff: 512Mb FSMC bank1&2 block */ +# define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */ +# define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */ #define STM32_FSMC_BASE34 0x80000000 /* 0x80000000-0x8fffffff: 512Mb FSMC bank3&4 block */ +# define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */ +# define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/ #define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */ /* 0xc0000000-0xdfffffff: 512Mb (not used) */ #define STM32_CORTEX_BASE 0xe0000000 /* 0xe0000000-0xffffffff: 512Mb Cortex-M4 block */ +#define STM32_REGION_MASK 0xf0000000 +#define STM32_IS_SRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_SRAM_BASE) +#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1) + /* Code Base Addresses **************************************************************/ #define STM32_BOOT_BASE 0x00000000 /* 0x00000000-0x000fffff: Aliased boot memory */ @@ -185,7 +193,7 @@ #define STM32_HASH_BASE 0x50060400 /* 0x50060400-0x500607ff: HASH */ #define STM32_RNG_BASE 0x50060800 /* 0x50060800-0x50060bff: RNG */ -/* Cortex-M4 Base Addresses *********************************************************/ +/* Cortex-M3 Base Addresses *********************************************************/ /* Other registers -- see armv7-m/nvic.h for standard Cortex-M3 registers in this * address range */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h index 2c8587855e..817e747f71 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h * * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -365,7 +365,7 @@ #define GPIO_JTMS_SWDIO (GPIO_ALT|GPIO_AF0|GPIO_PORTA|GPIO_PIN13) #define GPIO_JTRST (GPIO_ALT|GPIO_AF0|GPIO_PORTB|GPIO_PIN4) -/* OTG FS/HS */ +/* OTG FS/HS (VBUS PA9 is not an alternate configuration) */ #define GPIO_OTGFS_DM (GPIO_ALT|GPIO_FLOAT|GPIO_AF10|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN11) #define GPIO_OTGFS_DP (GPIO_ALT|GPIO_FLOAT|GPIO_AF10|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN12) diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_gpio.h b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_gpio.h index aa7353ed9d..3a5f8bc6a1 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_gpio.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_gpio.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32f40xxx_gpio.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_memorymap.h b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_memorymap.h index c7f7ff2ec3..6b99121216 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_memorymap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_memorymap.h @@ -46,11 +46,19 @@ #define STM32_SRAM_BASE 0x20000000 /* 0x20000000-0x3fffffff: 512Mb sram block */ #define STM32_PERIPH_BASE 0x40000000 /* 0x40000000-0x5fffffff: 512Mb peripheral block */ #define STM32_FSMC_BASE12 0x60000000 /* 0x60000000-0x7fffffff: 512Mb FSMC bank1&2 block */ +# define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */ +# define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */ #define STM32_FSMC_BASE34 0x80000000 /* 0x80000000-0x8fffffff: 512Mb FSMC bank3&4 block */ +# define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */ +# define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/ #define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */ /* 0xc0000000-0xdfffffff: 512Mb (not used) */ #define STM32_CORTEX_BASE 0xe0000000 /* 0xe0000000-0xffffffff: 512Mb Cortex-M4 block */ +#define STM32_REGION_MASK 0xf0000000 +#define STM32_IS_SRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_SRAM_BASE) +#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1) + /* Code Base Addresses **************************************************************/ #define STM32_BOOT_BASE 0x00000000 /* 0x00000000-0x000fffff: Aliased boot memory */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h index a588b56a27..ae2436a70f 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h @@ -365,7 +365,7 @@ #define GPIO_JTMS_SWDIO (GPIO_ALT|GPIO_AF0|GPIO_PORTA|GPIO_PIN13) #define GPIO_JTRST (GPIO_ALT|GPIO_AF0|GPIO_PORTB|GPIO_PIN4) -/* OTG FS/HS */ +/* OTG FS/HS (VBUS PA9 is not an alternate configuration) */ #define GPIO_OTGFS_DM (GPIO_ALT|GPIO_FLOAT|GPIO_AF10|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN11) #define GPIO_OTGFS_DP (GPIO_ALT|GPIO_FLOAT|GPIO_AF10|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN12) diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_rtc.h b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_rtc.h index fdfa9b3230..a656cfda04 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_rtc.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_rtc.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/chip/stm32f40xxx_rtc.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_allocateheap.c b/nuttx/arch/arm/src/stm32/stm32_allocateheap.c index 4c186a852b..4b8707a2b7 100644 --- a/nuttx/arch/arm/src/stm32/stm32_allocateheap.c +++ b/nuttx/arch/arm/src/stm32/stm32_allocateheap.c @@ -73,13 +73,14 @@ * * CONFIG_STM32_FSMC=y : Enables the FSMC * CONFIG_STM32_FSMC_SRAM=y : Indicates that SRAM is available via the - * FSMC (as opposed to an LCD or FLASH). + * FSMC (as opposed to an LCD or FLASH). * CONFIG_HEAP2_BASE : The base address of the SRAM in the FSMC - * address space - * CONFIG_HEAP2_END : The end (+1) of the SRAM in the FSMC - * address space + * address space + * CONFIG_HEAP2_SIZE : The size of the SRAM in the FSMC + * address space * CONFIG_MM_REGIONS : Must be set to a large enough value to - * include the FSMC SRAM (as determined by the rules provided below) + * include the FSMC SRAM (as determined by + * the rules provided below) */ #ifndef CONFIG_STM32_FSMC @@ -211,7 +212,7 @@ * should be 3. */ -# ifdef CONFIG_STM32_DMA +# ifdef CONFIG_ARCH_DMA # warning "CCM SRAM is included in the heap AND DMA is enabled" # endif # if CONFIG_MM_REGIONS != 3 @@ -237,7 +238,7 @@ * should be disabled and CONFIG_MM_REGIONS should be 2. */ -# ifdef CONFIG_STM32_DMA +# ifdef CONFIG_ARCH_DMA # warning "CCM SRAM is included in the heap AND DMA is enabled" # endif # if CONFIG_MM_REGIONS < 2 @@ -256,12 +257,12 @@ /* If FSMC SRAM is going to be used as heap, then verify that the starting * address and size of the external SRAM region has been provided in the - * configuration (as CONFIG_HEAP2_BASE and CONFIG_HEAP2_END). + * configuration (as CONFIG_HEAP2_BASE and CONFIG_HEAP2_SIZE). */ #ifdef CONFIG_STM32_FSMC_SRAM -# if !defined(CONFIG_HEAP2_BASE) || !defined(CONFIG_HEAP2_END) -# error "CONFIG_HEAP2_BASE and CONFIG_HEAP2_END must be provided" +# if !defined(CONFIG_HEAP2_BASE) || !defined(CONFIG_HEAP2_SIZE) +# error "CONFIG_HEAP2_BASE and CONFIG_HEAP2_SIZE must be provided" # undef CONFIG_STM32_FSMC_SRAM # endif #endif @@ -317,7 +318,7 @@ void up_addregion(void) /* Add the external FSMC SRAM heap region. */ #ifdef CONFIG_STM32_FSMC_SRAM - mm_addregion((FAR void*)CONFIG_HEAP2_BASE, CONFIG_HEAP2_END - CONFIG_HEAP2_BASE); + mm_addregion((FAR void*)CONFIG_HEAP2_BASE, CONFIG_HEAP2_SIZE); #endif } #endif diff --git a/nuttx/arch/arm/src/stm32/stm32_dbgmcu.h b/nuttx/arch/arm/src/stm32/stm32_dbgmcu.h index 080f4bec5d..5fb1921866 100644 --- a/nuttx/arch/arm/src/stm32/stm32_dbgmcu.h +++ b/nuttx/arch/arm/src/stm32/stm32_dbgmcu.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_dbgmcu.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c index 57d4cc2d33..59f3def7f6 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.c +++ b/nuttx/arch/arm/src/stm32/stm32_eth.c @@ -102,11 +102,32 @@ #endif #ifdef CONFIG_STM32_MII -# if !defined(CONFIG_STM32_MII_MCO1) && !defined(CONFIG_STM32_MII_MCO2) -# warning "Neither CONFIG_STM32_MII_MCO1 nor CONFIG_STM32_MII_MCO2 defined" +# if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) +# if !defined(CONFIG_STM32_MII_MCO1) && !defined(CONFIG_STM32_MII_MCO2) && !defined(CONFIG_STM32_MII_EXTCLK) +# warning "Neither CONFIG_STM32_MII_MCO1, CONFIG_STM32_MII_MCO2, nor CONFIG_STM32_MII_EXTCLK defined" +# endif +# if defined(CONFIG_STM32_MII_MCO1) && defined(CONFIG_STM32_MII_MCO2) +# error "Both CONFIG_STM32_MII_MCO1 and CONFIG_STM32_MII_MCO2 defined" +# endif +# elif defined(CONFIG_STM32_CONNECTIVITYLINE) +# if !defined(CONFIG_STM32_MII_MCO) && !defined(CONFIG_STM32_MII_EXTCLK) +# warning "Neither CONFIG_STM32_MII_MCO nor CONFIG_STM32_MII_EXTCLK defined" +# endif # endif -# if defined(CONFIG_STM32_MII_MCO1) && defined(CONFIG_STM32_MII_MCO2) -# error "Both CONFIG_STM32_MII_MCO1 and CONFIG_STM32_MII_MCO2 defined" +#endif + +#ifdef CONFIG_STM32_RMII +# if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) +# if !defined(CONFIG_STM32_RMII_MCO1) && !defined(CONFIG_STM32_RMII_MCO2) && !defined(CONFIG_STM32_RMII_EXTCLK) +# warning "Neither CONFIG_STM32_RMII_MCO1, CONFIG_STM32_RMII_MCO2, nor CONFIG_STM32_RMII_EXTCLK defined" +# endif +# if defined(CONFIG_STM32_RMII_MCO1) && defined(CONFIG_STM32_RMII_MCO2) +# error "Both CONFIG_STM32_RMII_MCO1 and CONFIG_STM32_RMII_MCO2 defined" +# endif +# elif defined(CONFIG_STM32_CONNECTIVITYLINE) +# if !defined(CONFIG_STM32_RMII_MCO) && !defined(CONFIG_STM32_RMII_EXTCLK) +# warning "Neither CONFIG_STM32_RMII_MCO nor CONFIG_STM32_RMII_EXTCLK defined" +# endif # endif #endif @@ -608,6 +629,12 @@ static int stm32_phyinit(FAR struct stm32_ethmac_s *priv); /* MAC/DMA Initialization */ +#ifdef CONFIG_STM32_MII +static inline void stm32_selectmii(void); +#endif +#ifdef CONFIG_STM32_RMII +static inline void stm32_selectrmii(void); +#endif static inline void stm32_ethgpioconfig(FAR struct stm32_ethmac_s *priv); static void stm32_ethreset(FAR struct stm32_ethmac_s *priv); static int stm32_macconfig(FAR struct stm32_ethmac_s *priv); @@ -2570,6 +2597,66 @@ static int stm32_phyinit(FAR struct stm32_ethmac_s *priv) return OK; } +/************************************************************************************ + * Name: stm32_selectmii + * + * Description: + * Selects the MII inteface. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ************************************************************************************/ + +#ifdef CONFIG_STM32_MII +static inline void stm32_selectmii(void) +{ + uint32_t regval; + +#ifdef CONFIG_STM32_CONNECTIVITYLINE + regval = getreg32(STM32_AFIO_MAPR); + regval &= ~AFIO_MAPR_MII_RMII_SEL; + putreg32(regval, STM32_AFIO_MAPR); +#else + regval = getreg32(STM32_SYSCFG_PMC); + regval &= ~SYSCFG_PMC_MII_RMII_SEL; + putreg32(regval, STM32_SYSCFG_PMC); +#endif +} +#endif + +/************************************************************************************ + * Name: stm32_selectrmii + * + * Description: + * Selects the RMII inteface. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ************************************************************************************/ + +static inline void stm32_selectrmii(void) +{ + uint32_t regval; + +#ifdef CONFIG_STM32_CONNECTIVITYLINE + regval = getreg32(STM32_AFIO_MAPR); + regval |= AFIO_MAPR_MII_RMII_SEL; + putreg32(regval, STM32_AFIO_MAPR); +#else + regval = getreg32(STM32_SYSCFG_PMC); + regval |= SYSCFG_PMC_MII_RMII_SEL; + putreg32(regval, STM32_SYSCFG_PMC); +#endif +} + /**************************************************************************** * Function: stm32_ethgpioconfig * @@ -2605,7 +2692,7 @@ static inline void stm32_ethgpioconfig(FAR struct stm32_ethmac_s *priv) stm32_selectmii(); - /* Provide clocking via MCO1 or MCO2: + /* Provide clocking via MCO, MCO1 or MCO2: * * "MCO1 (microcontroller clock output), used to output HSI, LSE, HSE or PLL * clock (through a configurable prescaler) on PA8 pin." @@ -2614,7 +2701,7 @@ static inline void stm32_ethgpioconfig(FAR struct stm32_ethmac_s *priv) * PLLI2S clock (through a configurable prescaler) on PC9 pin." */ -# if defined(CONFIG_STM32_MII_MCO1) +# if defined(CONFIG_STM32_MII_MCO1) /* Configure MC01 to drive the PHY. Board logic must provide MC01 clocking * info. */ @@ -2622,14 +2709,20 @@ static inline void stm32_ethgpioconfig(FAR struct stm32_ethmac_s *priv) stm32_configgpio(GPIO_MCO1); stm32_mco1config(BOARD_CFGR_MC01_SOURCE, BOARD_CFGR_MC01_DIVIDER); -# elif defined(CONFIG_STM32_MII_MCO2) +# elif defined(CONFIG_STM32_MII_MCO2) /* Configure MC02 to drive the PHY. Board logic must provide MC02 clocking * info. */ stm32_configgpio(GPIO_MCO2); stm32_mco2config(BOARD_CFGR_MC02_SOURCE, BOARD_CFGR_MC02_DIVIDER); -# endif + +# elif defined(CONFIG_STM32_MII_MCO) + /* Setup MCO pin for alternative usage */ + + stm32_configgpio(GPIO_MCO); + stm32_mcoconfig(BOARD_CFGR_MCO_SOURCE); +# endif /* MII interface pins (17): * @@ -2657,17 +2750,42 @@ static inline void stm32_ethgpioconfig(FAR struct stm32_ethmac_s *priv) #elif defined(CONFIG_STM32_RMII) - /* Setup MCO pin for alternative usage */ - -#if defined(CONFIG_STM32_RMII_MCO) - stm32_configgpio(GPIO_MCO); - stm32_mcoconfig(BOARD_CFGR_MCO_SOURCE); -#endif - /* Select the RMII interface */ stm32_selectrmii(); + /* Provide clocking via MCO, MCO1 or MCO2: + * + * "MCO1 (microcontroller clock output), used to output HSI, LSE, HSE or PLL + * clock (through a configurable prescaler) on PA8 pin." + * + * "MCO2 (microcontroller clock output), used to output HSE, PLL, SYSCLK or + * PLLI2S clock (through a configurable prescaler) on PC9 pin." + */ + +# if defined(CONFIG_STM32_RMII_MCO1) + /* Configure MC01 to drive the PHY. Board logic must provide MC01 clocking + * info. + */ + + stm32_configgpio(GPIO_MCO1); + stm32_mco1config(BOARD_CFGR_MC01_SOURCE, BOARD_CFGR_MC01_DIVIDER); + +# elif defined(CONFIG_STM32_RMII_MCO2) + /* Configure MC02 to drive the PHY. Board logic must provide MC02 clocking + * info. + */ + + stm32_configgpio(GPIO_MCO2); + stm32_mco2config(BOARD_CFGR_MC02_SOURCE, BOARD_CFGR_MC02_DIVIDER); + +# elif defined(CONFIG_STM32_RMII_MCO) + /* Setup MCO pin for alternative usage */ + + stm32_configgpio(GPIO_MCO); + stm32_mcoconfig(BOARD_CFGR_MCO_SOURCE); +# endif + /* RMII interface pins (7): * * RMII_TXD[1:0], RMII_TX_EN, RMII_RXD[1:0], RMII_CRS_DV, MDC, MDIO, diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.h b/nuttx/arch/arm/src/stm32/stm32_eth.h index 188dc10d36..f0c14b5b1f 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.h +++ b/nuttx/arch/arm/src/stm32/stm32_eth.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_eth.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_gpio.h b/nuttx/arch/arm/src/stm32/stm32_gpio.h index 34623c5253..fde564cbbf 100644 --- a/nuttx/arch/arm/src/stm32/stm32_gpio.h +++ b/nuttx/arch/arm/src/stm32/stm32_gpio.h @@ -3,7 +3,7 @@ * * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * Uros Platise * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c index d02115a157..a4b10b55c6 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.c +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c @@ -196,11 +196,29 @@ struct stm32_trace_s uint32_t time; /* First of event or first status */ }; +/* I2C Device hardware configuration */ + +struct stm32_i2c_config_s +{ + uint32_t base; /* I2C base address */ +#ifndef CONFIG_I2C_POLLED + int ( *isr)(int, void *); /* Interrupt handler */ +#endif + uint32_t clk_bit; /* Clock enable bit */ + uint32_t reset_bit; /* Reset bit */ + uint32_t scl_pin; /* GPIO configuration for SCL as SCL */ + uint32_t scl_gpio; /* GPIO configuration for SCL as a GPIO */ + uint32_t sda_pin; /* GPIO configuration for SDA as SDA */ + uint32_t sda_gpio; /* GPIO configuration for SDA as a GPIO */ + uint32_t ev_irq; /* Event IRQ */ + uint32_t er_irq; /* Error IRQ */ +}; + /* I2C Device Private Data */ struct stm32_i2c_priv_s { - uint32_t base; /* I2C base address */ + const struct stm32_i2c_config_s *config; /* Port configuration */ int refs; /* Referernce count */ sem_t sem_excl; /* Mutual exclusion semaphore */ #ifndef CONFIG_I2C_POLLED @@ -311,9 +329,32 @@ static int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *m ************************************************************************************/ #ifdef CONFIG_STM32_I2C1 -struct stm32_i2c_priv_s stm32_i2c1_priv = +# ifndef GPIO_I2C1_SCL_GPIO +# define GPIO_I2C1_SCL_GPIO 0 +# endif +# ifndef GPIO_I2C1_SDA_GPIO +# define GPIO_I2C1_SDA_GPIO 0 +# endif + +static const struct stm32_i2c_config_s stm32_i2c1_config = { .base = STM32_I2C1_BASE, +#ifndef CONFIG_I2C_POLLED + .isr = stm32_i2c1_isr, +#endif + .clk_bit = RCC_APB1ENR_I2C1EN, + .reset_bit = RCC_APB1RSTR_I2C1RST, + .scl_pin = GPIO_I2C1_SCL, + .scl_gpio = GPIO_I2C1_SCL_GPIO, + .sda_pin = GPIO_I2C1_SDA, + .sda_gpio = GPIO_I2C1_SDA_GPIO, + .ev_irq = STM32_IRQ_I2C1EV, + .er_irq = STM32_IRQ_I2C1ER +}; + +struct stm32_i2c_priv_s stm32_i2c1_priv = +{ + .config = &stm32_i2c1_config, .refs = 0, .intstate = INTSTATE_IDLE, .msgc = 0, @@ -326,9 +367,32 @@ struct stm32_i2c_priv_s stm32_i2c1_priv = #endif #ifdef CONFIG_STM32_I2C2 -struct stm32_i2c_priv_s stm32_i2c2_priv = +# ifndef GPIO_I2C2_SCL_GPIO +# define GPIO_I2C2_SCL_GPIO 0 +# endif +# ifndef GPIO_I2C2_SDA_GPIO +# define GPIO_I2C2_SDA_GPIO 0 +# endif + +static const struct stm32_i2c_config_s stm32_i2c2_config = { .base = STM32_I2C2_BASE, +#ifndef CONFIG_I2C_POLLED + .isr = stm32_i2c2_isr, +#endif + .clk_bit = RCC_APB1ENR_I2C2EN, + .reset_bit = RCC_APB1RSTR_I2C2RST, + .scl_pin = GPIO_I2C2_SCL, + .scl_gpio = GPIO_I2C2_SCL_GPIO, + .sda_pin = GPIO_I2C2_SDA, + .sda_gpio = GPIO_I2C2_SDA_GPIO, + .ev_irq = STM32_IRQ_I2C2EV, + .er_irq = STM32_IRQ_I2C2ER +}; + +struct stm32_i2c_priv_s stm32_i2c2_priv = +{ + .config = &stm32_i2c2_config, .refs = 0, .intstate = INTSTATE_IDLE, .msgc = 0, @@ -341,9 +405,32 @@ struct stm32_i2c_priv_s stm32_i2c2_priv = #endif #ifdef CONFIG_STM32_I2C3 -struct stm32_i2c_priv_s stm32_i2c3_priv = +# ifndef GPIO_I2C3_SCL_GPIO +# define GPIO_I2C3_SCL_GPIO 0 +# endif +# ifndef GPIO_I2C3_SDA_GPIO +# define GPIO_I2C3_SDA_GPIO 0 +# endif + +static const struct stm32_i2c_config_s stm32_i2c3_config = { .base = STM32_I2C3_BASE, +#ifndef CONFIG_I2C_POLLED + .isr = stm32_i2c3_isr, +#endif + .clk_bit = RCC_APB1ENR_I2C3EN, + .reset_bit = RCC_APB1RSTR_I2C3RST, + .scl_pin = GPIO_I2C3_SCL, + .scl_gpio = GPIO_I2C3_SCL_GPIO, + .sda_pin = GPIO_I2C3_SDA, + .sda_gpio = GPIO_I2C3_SDA_GPIO, + .ev_irq = STM32_IRQ_I2C3EV, + .er_irq = STM32_IRQ_I2C3ER +}; + +struct stm32_i2c_priv_s stm32_i2c3_priv = +{ + .config = &stm32_i2c3_config, .refs = 0, .intstate = INTSTATE_IDLE, .msgc = 0, @@ -355,7 +442,6 @@ struct stm32_i2c_priv_s stm32_i2c3_priv = }; #endif - /* Device Structures, Instantiation */ struct i2c_ops_s stm32_i2c_ops = @@ -391,7 +477,7 @@ struct i2c_ops_s stm32_i2c_ops = static inline uint16_t stm32_i2c_getreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset) { - return getreg16(priv->base + offset); + return getreg16(priv->config->base + offset); } /************************************************************************************ @@ -405,7 +491,7 @@ static inline uint16_t stm32_i2c_getreg(FAR struct stm32_i2c_priv_s *priv, static inline void stm32_i2c_putreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t value) { - putreg16(value, priv->base + offset); + putreg16(value, priv->config->base + offset); } /************************************************************************************ @@ -420,7 +506,7 @@ static inline void stm32_i2c_modifyreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t clearbits, uint16_t setbits) { - modifyreg16(priv->base + offset, clearbits, setbits); + modifyreg16(priv->config->base + offset, clearbits, setbits); } /************************************************************************************ @@ -986,7 +1072,7 @@ static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv) /* Is this I2C1 */ #ifdef CONFIG_STM32_I2C2 - if (priv->base == STM32_I2C1_BASE) + if (priv->config->base == STM32_I2C1_BASE) #endif { /* Disable FSMC unconditionally */ @@ -1112,6 +1198,10 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) { stm32_i2c_traceevent(priv, I2CEVENT_RCVBYTE, priv->dcnt); +#ifdef CONFIG_I2C_POLLED + irqstate_t state = irqsave(); +#endif + /* Receive a byte */ *priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET); @@ -1123,6 +1213,11 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, 0); } priv->dcnt--; + +#ifdef CONFIG_I2C_POLLED + irqrestore(state); +#endif + } } @@ -1310,114 +1405,35 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv) { /* Power-up and configure GPIOs */ - switch (priv->base) - { -#ifdef CONFIG_STM32_I2C1 - case STM32_I2C1_BASE: + /* Enable power and reset the peripheral */ - /* Enable power and reset the peripheral */ + modifyreg32(STM32_RCC_APB1ENR, 0, priv->config->clk_bit); - modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_I2C1EN); + modifyreg32(STM32_RCC_APB1RSTR, 0, priv->config->reset_bit); + modifyreg32(STM32_RCC_APB1RSTR, priv->config->reset_bit, 0); - modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_I2C1RST); - modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C1RST, 0); - - /* Configure pins */ - - if (stm32_configgpio(GPIO_I2C1_SCL) < 0) - { - return ERROR; - } - - if (stm32_configgpio(GPIO_I2C1_SDA) < 0) - { - stm32_unconfiggpio(GPIO_I2C1_SCL); - return ERROR; - } - - /* Attach ISRs */ - -#ifndef CONFIG_I2C_POLLED - irq_attach(STM32_IRQ_I2C1EV, stm32_i2c1_isr); - irq_attach(STM32_IRQ_I2C1ER, stm32_i2c1_isr); - up_enable_irq(STM32_IRQ_I2C1EV); - up_enable_irq(STM32_IRQ_I2C1ER); -#endif - break; -#endif + /* Configure pins */ -#ifdef CONFIG_STM32_I2C2 - case STM32_I2C2_BASE: - - /* Enable power and reset the peripheral */ - - modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_I2C2EN); - - modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_I2C2RST); - modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C2RST, 0); - - /* Configure pins */ - - if (stm32_configgpio(GPIO_I2C2_SCL) < 0) - { - return ERROR; - } - - if (stm32_configgpio(GPIO_I2C2_SDA) < 0) - { - stm32_unconfiggpio(GPIO_I2C2_SCL); - return ERROR; - } - - /* Attach ISRs */ - -#ifndef CONFIG_I2C_POLLED - irq_attach(STM32_IRQ_I2C2EV, stm32_i2c2_isr); - irq_attach(STM32_IRQ_I2C2ER, stm32_i2c2_isr); - up_enable_irq(STM32_IRQ_I2C2EV); - up_enable_irq(STM32_IRQ_I2C2ER); -#endif - break; -#endif - -#ifdef CONFIG_STM32_I2C3 - case STM32_I2C3_BASE: - - /* Enable power and reset the peripheral */ - - modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_I2C3EN); - - modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_I2C3RST); - modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C3RST, 0); - - /* Configure pins */ - - if (stm32_configgpio(GPIO_I2C3_SCL) < 0) - { - return ERROR; - } - - if (stm32_configgpio(GPIO_I2C3_SDA) < 0) - { - stm32_unconfiggpio(GPIO_I2C3_SCL); - return ERROR; - } - - /* Attach ISRs */ - -#ifndef CONFIG_I2C_POLLED - irq_attach(STM32_IRQ_I2C3EV, stm32_i2c3_isr); - irq_attach(STM32_IRQ_I2C3ER, stm32_i2c3_isr); - up_enable_irq(STM32_IRQ_I2C3EV); - up_enable_irq(STM32_IRQ_I2C3ER); -#endif - break; -#endif - - default: - return ERROR; + if (stm32_configgpio(priv->config->scl_pin) < 0) + { + return ERROR; } + if (stm32_configgpio(priv->config->sda_pin) < 0) + { + stm32_unconfiggpio(priv->config->scl_pin); + return ERROR; + } + + /* Attach ISRs */ + +#ifndef CONFIG_I2C_POLLED + irq_attach(priv->config->ev_irq, priv->config->isr); + irq_attach(priv->config->er_irq, priv->config->isr); + up_enable_irq(priv->config->ev_irq); + up_enable_irq(priv->config->er_irq); +#endif + /* Set peripheral frequency, where it must be at least 2 MHz for 100 kHz * or 4 MHz for 400 kHz. This also disables all I2C interrupts. */ @@ -1445,56 +1461,16 @@ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv) stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, 0); - switch (priv->base) - { -#ifdef CONFIG_STM32_I2C1 - case STM32_I2C1_BASE: - stm32_unconfiggpio(GPIO_I2C1_SCL); - stm32_unconfiggpio(GPIO_I2C1_SDA); + stm32_unconfiggpio(priv->config->scl_pin); + stm32_unconfiggpio(priv->config->sda_pin); #ifndef CONFIG_I2C_POLLED - up_disable_irq(STM32_IRQ_I2C1EV); - up_disable_irq(STM32_IRQ_I2C1ER); - irq_detach(STM32_IRQ_I2C1EV); - irq_detach(STM32_IRQ_I2C1ER); + up_disable_irq(priv->config->ev_irq); + up_disable_irq(priv->config->er_irq); + irq_detach(priv->config->ev_irq); + irq_detach(priv->config->er_irq); #endif - modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_I2C1EN, 0); - break; -#endif - -#ifdef CONFIG_STM32_I2C2 - case STM32_I2C2_BASE: - stm32_unconfiggpio(GPIO_I2C2_SCL); - stm32_unconfiggpio(GPIO_I2C2_SDA); - -#ifndef CONFIG_I2C_POLLED - up_disable_irq(STM32_IRQ_I2C2EV); - up_disable_irq(STM32_IRQ_I2C2ER); - irq_detach(STM32_IRQ_I2C2EV); - irq_detach(STM32_IRQ_I2C2ER); -#endif - modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_I2C2EN, 0); - break; -#endif - -#ifdef CONFIG_STM32_I2C3 - case STM32_I2C3_BASE: - stm32_unconfiggpio(GPIO_I2C3_SCL); - stm32_unconfiggpio(GPIO_I2C3_SDA); - -#ifndef CONFIG_I2C_POLLED - up_disable_irq(STM32_IRQ_I2C3EV); - up_disable_irq(STM32_IRQ_I2C3ER); - irq_detach(STM32_IRQ_I2C3EV); - irq_detach(STM32_IRQ_I2C3ER); -#endif - modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_I2C3EN, 0); - break; -#endif - - default: - return ERROR; - } + modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0); return OK; } @@ -1979,159 +1955,119 @@ int up_i2cuninitialize(FAR struct i2c_dev_s * dev) int up_i2creset(FAR struct i2c_dev_s * dev) { - // ASSERT(dev); - - // stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */ + struct stm32_i2c_priv_s * priv; + unsigned clock_count; + unsigned stretch_count; + int ret = ERROR; + irqstate_t state; - // struct stm32_i2c_inst_s *inst = (struct stm32_i2c_inst_s *)dev; - // FAR struct stm32_i2c_priv_s *priv = inst->priv; - - // /* Clear any pending error interrupts */ - - // stm32_i2c_putreg(priv, STM32_I2C_SR1_OFFSET, 0); - - // /* "Note: When the STOP, START or PEC bit is set, the software must - // * not perform any write access to I2C_CR1 before this bit is - // * cleared by hardware. Otherwise there is a risk of setting a - // * second STOP, START or PEC request." However, if the bits are - // * not cleared by hardware, then we will have to do that from hardware. - // */ - - // stm32_i2c_clrstart(priv); - - // /* Reset peripheral */ - // uint16_t cr1 = stm32_i2c_getreg(priv, STM32_I2C_CR1_OFFSET); - // /* Set reset flag */ - // cr1 &= I2C_CR1_SWRST; - // stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, cr1); - // /* Clear CR1 */ - // stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, 0); - - // switch (priv->base) - // { - // case STM32_I2C1_BASE: - // modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_I2C1RST); - // modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C1RST, 0); - // break; - // case STM32_I2C2_BASE: - // modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_I2C2RST); - // modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C2RST, 0); - // break; - // case STM32_I2C3_BASE: - // modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_I2C3RST); - // modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_I2C3RST, 0); - // break; - // } - - - - // stm32_i2c_putreg(priv, STM32_I2C_CR2_OFFSET, (STM32_PCLK1_FREQUENCY / 1000000)); - // stm32_i2c_setclock(priv, inst->frequency); - // inst->flags = 0; - - // /* Enable I2C */ - - // stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_PE); - - - - - - - - - - - - - - - - int irqs; - ASSERT(dev); - - /* Decrement refs and check for underflow */ - - if (((struct stm32_i2c_inst_s *)dev)->priv->refs == 0) - { - return ERROR; - } - irqs = irqsave(); - - irqrestore(irqs); - - /* Disable power and other HW resource (GPIO's) */ - - //stm32_i2c_deinit( ((struct stm32_i2c_inst_s *)dev)->priv ); - - /* Release unused resources */ - - //stm32_i2c_sem_destroy( (struct i2c_dev_s *)dev ); - - struct stm32_i2c_priv_s * priv = NULL; /* private data of device with multiple instances */ - struct stm32_i2c_inst_s * inst = NULL; /* device, single instance */ - -#if STM32_PCLK1_FREQUENCY < 4000000 -# warning STM32_I2C_INIT: Peripheral clock must be at least 4 MHz to support 400 kHz operation. -#endif - -#if STM32_PCLK1_FREQUENCY < 2000000 -# warning STM32_I2C_INIT: Peripheral clock must be at least 2 MHz to support 100 kHz operation. - return NULL; -#endif - /* Get I2C private structure */ - priv = ((struct stm32_i2c_inst_s *)dev)->priv; + priv = ((struct stm32_i2c_inst_s *)dev)->priv; -// switch (port) -// { -// #ifdef CONFIG_STM32_I2C1 -// case 1: -// priv = (struct stm32_i2c_priv_s *)&stm32_i2c1_priv; -// break; -// #endif -// #ifdef CONFIG_STM32_I2C2 -// case 2: -// priv = (struct stm32_i2c_priv_s *)&stm32_i2c2_priv; -// break; -// #endif -// #ifdef CONFIG_STM32_I2C3 -// case 3: -// priv = (struct stm32_i2c_priv_s *)&stm32_i2c3_priv; -// break; -// #endif -// default: -// return NULL; -// } + /* Our caller must own a ref */ - /* Allocate instance */ - inst = (struct stm32_i2c_inst_s *)dev; + ASSERT(priv->refs > 0); - /* Initialize instance */ + /* Lock out other clients */ - inst->ops = &stm32_i2c_ops; - inst->priv = priv; - inst->frequency = 100000; - inst->address = 0; - inst->flags = 0; + stm32_i2c_sem_wait(dev); - /* Init private data for the first time, increment refs count, - * power-up hardware and configure GPIOs. - */ - - irqs = irqsave(); - - if ((volatile int)priv->refs++ == 0) + /* De-init the port */ + + stm32_i2c_deinit(priv); + + /* If possible, use GPIO configuration to un-wedge the bus */ + + if ((priv->config->scl_gpio != 0) && (priv->config->sda_gpio != 0)) { - stm32_i2c_sem_init( (struct i2c_dev_s *)inst ); - stm32_i2c_init( priv ); + stm32_configgpio(priv->config->scl_gpio); + stm32_configgpio(priv->config->sda_gpio); + + /* + * Clock the bus until any slaves currently driving it let it go. + */ + + clock_count = 0; + while (!stm32_gpioread(priv->config->sda_gpio)) + { + + /* Give up if we have tried too hard */ + + if (clock_count++ > 1000) + { + goto out; + } + + /* + * Sniff to make sure that clock stretching has finished. + * + * If the bus never relaxes, the reset has failed. + */ + + stretch_count = 0; + while (!stm32_gpioread(priv->config->scl_gpio)) + { + + /* Give up if we have tried too hard */ + + if (stretch_count++ > 1000) + { + goto out; + } + + up_udelay(10); + + } + + /* Drive SCL low */ + + stm32_gpiowrite(priv->config->scl_gpio, 0); + up_udelay(10); + + /* Drive SCL high again */ + + stm32_gpiowrite(priv->config->scl_gpio, 1); + up_udelay(10); + + } + + /* + * Generate a start followed by a stop to reset slave + * state machines. + */ + + stm32_gpiowrite(priv->config->sda_gpio, 0); + up_udelay(10); + stm32_gpiowrite(priv->config->scl_gpio, 0); + up_udelay(10); + stm32_gpiowrite(priv->config->scl_gpio, 1); + up_udelay(10); + stm32_gpiowrite(priv->config->sda_gpio, 1); + up_udelay(10); + + /* + * Revert the GPIO configuration. + */ + stm32_unconfiggpio(priv->config->sda_gpio); + stm32_unconfiggpio(priv->config->scl_gpio); + } - - irqrestore(irqs); - return OK; + + /* Re-init the port */ + + stm32_i2c_init(priv); + ret = OK; + +out: + + /* release the port for re-use by other clients */ + + stm32_i2c_sem_post(dev); + + return ret; } -#endif /* defined(CONFIG_STM32_I2C1) && defined(CONFIG_STM32_I2C2) */ +#endif /* defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3) */ diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.h b/nuttx/arch/arm/src/stm32/stm32_i2c.h index 23a06bc051..b914c4247b 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.h +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_i2c.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_lowputc.c b/nuttx/arch/arm/src/stm32/stm32_lowputc.c index 14f4efae46..7f72056729 100644 --- a/nuttx/arch/arm/src/stm32/stm32_lowputc.c +++ b/nuttx/arch/arm/src/stm32/stm32_lowputc.c @@ -85,22 +85,22 @@ # define STM32_CONSOLE_2STOP CONFIG_USART3_2STOP # define STM32_CONSOLE_TX GPIO_USART3_TX # define STM32_CONSOLE_RX GPIO_USART3_RX -#elif defined(CONFIG_USART4_SERIAL_CONSOLE) +#elif defined(CONFIG_UART4_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_UART4_BASE # define STM32_APBCLOCK STM32_PCLK1_FREQUENCY -# define STM32_CONSOLE_BAUD CONFIG_USART4_BAUD -# define STM32_CONSOLE_BITS CONFIG_USART4_BITS -# define STM32_CONSOLE_PARITY CONFIG_USART4_PARITY -# define STM32_CONSOLE_2STOP CONFIG_USART4_2STOP +# define STM32_CONSOLE_BAUD CONFIG_UART4_BAUD +# define STM32_CONSOLE_BITS CONFIG_UART4_BITS +# define STM32_CONSOLE_PARITY CONFIG_UART4_PARITY +# define STM32_CONSOLE_2STOP CONFIG_UART4_2STOP # define STM32_CONSOLE_TX GPIO_UART4_TX # define STM32_CONSOLE_RX GPIO_UART4_RX -#elif defined(CONFIG_USART5_SERIAL_CONSOLE) +#elif defined(CONFIG_UART5_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_UART5_BASE # define STM32_APBCLOCK STM32_PCLK1_FREQUENCY -# define STM32_CONSOLE_BAUD CONFIG_USART5_BAUD -# define STM32_CONSOLE_BITS CONFIG_USART5_BITS -# define STM32_CONSOLE_PARITY CONFIG_USART5_PARITY -# define STM32_CONSOLE_2STOP CONFIG_USART5_2STOP +# define STM32_CONSOLE_BAUD CONFIG_UART5_BAUD +# define STM32_CONSOLE_BITS CONFIG_UART5_BITS +# define STM32_CONSOLE_PARITY CONFIG_UART5_PARITY +# define STM32_CONSOLE_2STOP CONFIG_UART5_2STOP # define STM32_CONSOLE_TX GPIO_UART5_TX # define STM32_CONSOLE_RX GPIO_UART5_RX #elif defined(CONFIG_USART6_SERIAL_CONSOLE) diff --git a/nuttx/arch/arm/src/stm32/stm32_lowputc.h b/nuttx/arch/arm/src/stm32/stm32_lowputc.h index edcc78d8f1..659de7b1c6 100644 --- a/nuttx/arch/arm/src/stm32/stm32_lowputc.h +++ b/nuttx/arch/arm/src/stm32/stm32_lowputc.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_lowputc.h * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c index 39c40d80ab..461d500ad1 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c @@ -607,7 +607,7 @@ static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, /* Endpoint buffer management */ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif @@ -669,7 +669,7 @@ static const struct usbdev_epops_s g_epops = .disable = stm32_ep_disable, .allocreq = stm32_ep_allocreq, .freereq = stm32_ep_freereq, -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA .allocbuffer = stm32_ep_allocbuffer, .freebuffer = stm32_ep_freebuffer, #endif @@ -4070,11 +4070,16 @@ static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s * *******************************************************************************/ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); - return malloc(bytes) + +#ifdef CONFIG_USBDEV_DMAMEMORY + return usbdev_dma_alloc(bytes); +#else + return malloc(bytes); +#endif } #endif @@ -4086,11 +4091,16 @@ static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) * *******************************************************************************/ -#ifdef CONFIG_LPC313x_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->epphy); + +#ifdef CONFIG_USBDEV_DMAMEMORY + usbdev_dma_free(buf); +#else free(buf); +#endif } #endif @@ -4645,7 +4655,6 @@ static int stm32_wakeup(struct usbdev_s *dev) regval &= ~(OTGFS_PCGCCTL_STPPCLK | OTGFS_PCGCCTL_GATEHCLK); stm32_putreg(regval, STM32_OTGFS_PCGCCTL); #endif - /* Activate Remote wakeup signaling */ regval = stm32_getreg(STM32_OTGFS_DCTL); @@ -4971,7 +4980,7 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv) #ifndef CONFIG_USBDEV_VBUSSENSING regval |= OTGFS_GCCFG_NOVBUSSENS; #endif -#ifdef CONFIG_USBDEV_SOFOUTPUT +#ifdef CONFIG_STM32_OTGFS_SOFOUTPUT regval |= OTGFS_GCCFG_SOFOUTEN; #endif stm32_putreg(regval, STM32_OTGFS_GCCFG); @@ -5173,12 +5182,29 @@ void up_usbinitialize(void) * current detection. */ - /* Configure OTG FS alternate function pins */ + /* Configure OTG FS alternate function pins + * + * PIN* SIGNAL DIRECTION + * ---- ----------- ---------- + * PA8 OTG_FS_SOF SOF clock output + * PA9 OTG_FS_VBUS VBUS input for device, Driven by external regulator by + * host (not an alternate function) + * PA10 OTG_FS_ID OTG ID pin (only needed in Dual mode) + * PA11 OTG_FS_DM D- I/O + * PA12 OTG_FS_DP D+ I/O + * + * *Pins may vary from device-to-device. + */ stm32_configgpio(GPIO_OTGFS_DM); stm32_configgpio(GPIO_OTGFS_DP); - stm32_configgpio(GPIO_OTGFS_ID); + stm32_configgpio(GPIO_OTGFS_ID); /* Only needed for OTG */ + + /* SOF output pin configuration is configurable. */ + +#ifdef CONFIG_STM32_OTGFS_SOFOUTPUT stm32_configgpio(GPIO_OTGFS_SOF); +#endif /* Uninitialize the hardware so that we know that we are starting from a * known state. */ diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c new file mode 100644 index 0000000000..02b12ec873 --- /dev/null +++ b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c @@ -0,0 +1,4290 @@ +/******************************************************************************* + * arch/arm/src/stm32/stm32_otgfshost.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *******************************************************************************/ + +/******************************************************************************* + * Included Files + *******************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "chip.h" /* Includes default GPIO settings */ +#include /* May redefine GPIO settings */ + +#include "up_arch.h" +#include "up_internal.h" + +#include "stm32_usbhost.h" + +#if defined(CONFIG_USBHOST) && defined(CONFIG_STM32_OTGFS) + +/******************************************************************************* + * Definitions + *******************************************************************************/ +/* Configuration ***************************************************************/ +/* + * STM32 USB OTG FS Host Driver Support + * + * Pre-requisites + * + * CONFIG_USBHOST - Enable general USB host support + * CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block + * CONFIG_STM32_SYSCFG - Needed + * + * Options: + * + * CONFIG_STM32_OTGFS_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words. + * Default 128 (512 bytes) + * CONFIG_STM32_OTGFS_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO + * in 32-bit words. Default 96 (384 bytes) + * CONFIG_STM32_OTGFS_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit + * words. Default 96 (384 bytes) + * CONFIG_STM32_OTGFS_DESCSIZE - Maximum size of a descriptor. Default: 128 + * CONFIG_STM32_OTGFS_SOFINTR - Enable SOF interrupts. Why would you ever + * want to do that? + * CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access + * debug. Depends on CONFIG_DEBUG. + * CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB + * packets. Depends on CONFIG_DEBUG. + */ + +/* Pre-requistites (partial) */ + +#ifndef CONFIG_STM32_SYSCFG +# error "CONFIG_STM32_SYSCFG is required" +#endif + +/* Default RxFIFO size */ + +#ifndef CONFIG_STM32_OTGFS_RXFIFO_SIZE +# define CONFIG_STM32_OTGFS_RXFIFO_SIZE 128 +#endif + +/* Default host non-periodic Tx FIFO size */ + +#ifndef CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +# define CONFIG_STM32_OTGFS_NPTXFIFO_SIZE 96 +#endif + +/* Default host periodic Tx fifo size register */ + +#ifndef CONFIG_STM32_OTGFS_PTXFIFO_SIZE +# define CONFIG_STM32_OTGFS_PTXFIFO_SIZE 96 +#endif + +/* Maximum size of a descriptor */ + +#ifndef CONFIG_STM32_OTGFS_DESCSIZE +# define CONFIG_STM32_OTGFS_DESCSIZE 128 +#endif + +/* Register/packet debug depends on CONFIG_DEBUG */ + +#ifndef CONFIG_DEBUG +# undef CONFIG_STM32_USBHOST_REGDEBUG +# undef CONFIG_STM32_USBHOST_PKTDUMP +#endif + +/* HCD Setup *******************************************************************/ +/* Hardware capabilities */ + +#define STM32_NHOST_CHANNELS 8 /* Number of host channels */ +#define STM32_MAX_PACKET_SIZE 64 /* Full speed max packet size */ +#define STM32_EP0_DEF_PACKET_SIZE 8 /* EP0 default packet size */ +#define STM32_EP0_MAX_PACKET_SIZE 64 /* EP0 FS max packet size */ +#define STM32_MAX_TX_FIFOS 15 /* Max number of TX FIFOs */ +#define STM32_MAX_PKTCOUNT 256 /* Max packet count */ +#define STM32_RETRY_COUNT 3 /* Number of ctrl transfer retries */ +#define STM32_DEF_DEVADDR 0 /* Default device address */ + +/* Delays **********************************************************************/ + +#define STM32_READY_DELAY 200000 /* In loop counts */ +#define STM32_FLUSH_DELAY 200000 /* In loop counts */ +#define STM32_SETUP_DELAY 5000 /* In frames */ +#define STM32_DATANAK_DELAY 5000 /* In frames */ + +/* Ever-present MIN/MAX macros */ + +#ifndef MIN +# define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +/******************************************************************************* + * Private Types + *******************************************************************************/ + +/* The following enumeration represents the various states of the USB host + * state machine (for debug purposes only) + */ + +enum stm32_smstate_e +{ + SMSTATE_DETACHED = 0, /* Not attached to a device */ + SMSTATE_ATTACHED, /* Attached to a device */ + SMSTATE_ENUM, /* Attached, enumerating */ + SMSTATE_CLASS_BOUND, /* Enumeration complete, class bound */ +}; + +/* This enumeration provides the reason for the channel halt. */ + +enum stm32_chreason_e +{ + CHREASON_IDLE = 0, /* Inactive (initial state) */ + CHREASON_FREED, /* Channel is no longer in use */ + CHREASON_XFRC, /* Transfer complete */ + CHREASON_NAK, /* NAK received */ + CHREASON_NYET, /* NotYet received */ + CHREASON_STALL, /* Endpoint stalled */ + CHREASON_TXERR, /* Transfer error received */ + CHREASON_DTERR, /* Data toggle error received */ + CHREASON_FRMOR /* Frame overrun */ +}; + +/* This structure retains the state of one host channel. NOTE: Since there + * is only one channel operation active at a time, some of the fields in + * in the structure could be moved in struct stm32_ubhost_s to achieve + * some memory savings. + */ + +struct stm32_chan_s +{ + sem_t waitsem; /* Channel wait semaphore */ + volatile uint8_t result; /* The result of the transfer */ + volatile uint8_t chreason; /* Channel halt reason. See enum stm32_chreason_e */ + uint8_t epno; /* Device endpoint number (0-127) */ + uint8_t eptype; /* See OTGFS_EPTYPE_* definitions */ + uint8_t pid; /* Data PID */ + uint8_t npackets; /* Number of packets (for data toggle) */ + bool inuse; /* True: This channel is "in use" */ + volatile bool indata1; /* IN data toggle. True: DATA01 (Bulk and INTR only) */ + volatile bool outdata1; /* OUT data toggle. True: DATA01 */ + bool in; /* True: IN endpoint */ + volatile bool waiter; /* True: Thread is waiting for a channel event */ + uint16_t maxpacket; /* Max packet size */ + volatile uint16_t buflen; /* Buffer length (remaining) */ + volatile uint16_t inflight; /* Number of Tx bytes "in-flight" */ + FAR uint8_t *buffer; /* Transfer buffer pointer */ +}; + +/* This structure retains the state of the USB host controller */ + +struct stm32_usbhost_s +{ + /* Common device fields. This must be the first thing defined in the + * structure so that it is possible to simply cast from struct usbhost_s + * to structstm32_usbhost_s. + */ + + struct usbhost_driver_s drvr; + + /* The bound device class driver */ + + struct usbhost_class_s *class; + + /* Overall driver status */ + + volatile uint8_t smstate; /* The state of the USB host state machine */ + uint8_t devaddr; /* Device address */ + uint8_t ep0in; /* EP0 IN control channel index */ + uint8_t ep0out; /* EP0 OUT control channel index */ + uint8_t ep0size; /* EP0 max packet size */ + uint8_t chidx; /* ID of channel waiting for space in Tx FIFO */ + bool lowspeed; /* True: low speed device */ + volatile bool connected; /* Connected to device */ + volatile bool eventwait; /* True: Thread is waiting for a port event */ + sem_t exclsem; /* Support mutually exclusive access */ + sem_t eventsem; /* Semaphore to wait for a port event */ + + /* The state of each host channel */ + + struct stm32_chan_s chan[STM32_MAX_TX_FIFOS]; +}; + +/******************************************************************************* + * Private Function Prototypes + *******************************************************************************/ + +/* Register operations ********************************************************/ + +#ifdef CONFIG_STM32_USBHOST_REGDEBUG +static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite); +static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite); +static uint32_t stm32_getreg(uint32_t addr); +static void stm32_putreg(uint32_t addr, uint32_t value); +#else +# define stm32_getreg(addr) getreg32(addr) +# define stm32_putreg(addr,val) putreg32(val,addr) +#endif + +static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits, + uint32_t setbits); + +#ifdef CONFIG_STM32_USBHOST_PKTDUMP +# define stm32_pktdump(m,b,n) lib_dumpbuffer(m,b,n) +#else +# define stm32_pktdump(m,b,n) +#endif + +/* Semaphores ******************************************************************/ + +static void stm32_takesem(sem_t *sem); +#define stm32_givesem(s) sem_post(s); + +/* Byte stream access helper functions *****************************************/ + +static inline uint16_t stm32_getle16(const uint8_t *val); + +/* Channel management **********************************************************/ + +static int stm32_chan_alloc(FAR struct stm32_usbhost_s *priv); +static inline void stm32_chan_free(FAR struct stm32_usbhost_s *priv, int chidx); +static inline void stm32_chan_freeall(FAR struct stm32_usbhost_s *priv); +static void stm32_chan_configure(FAR struct stm32_usbhost_s *priv, int chidx); +static void stm32_chan_halt(FAR struct stm32_usbhost_s *priv, int chidx, + enum stm32_chreason_e chreason); +static int stm32_chan_waitsetup(FAR struct stm32_usbhost_s *priv, + FAR struct stm32_chan_s *chan); +static int stm32_chan_wait(FAR struct stm32_usbhost_s *priv, + FAR struct stm32_chan_s *chan); +static void stm32_chan_wakeup(FAR struct stm32_usbhost_s *priv, + FAR struct stm32_chan_s *chan); + +/* Control/data transfer logic *************************************************/ + +static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx); +static inline uint16_t stm32_getframe(void); +static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv, + FAR const struct usb_ctrlreq_s *req); +static int stm32_ctrl_senddata(FAR struct stm32_usbhost_s *priv, + FAR uint8_t *buffer, unsigned int buflen); +static int stm32_ctrl_recvdata(FAR struct stm32_usbhost_s *priv, + FAR uint8_t *buffer, unsigned int buflen); +static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx, + FAR uint8_t *buffer, size_t buflen); +static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx, + FAR uint8_t *buffer, size_t buflen); + +/* Interrupt handling **********************************************************/ +/* Lower level interrupt handlers */ + +static void stm32_gint_wrpacket(FAR struct stm32_usbhost_s *priv, + FAR uint8_t *buffer, int chidx, int buflen); +static inline void stm32_gint_hcinisr(FAR struct stm32_usbhost_s *priv, + int chidx); +static inline void stm32_gint_hcoutisr(FAR struct stm32_usbhost_s *priv, + int chidx); +static void stm32_gint_connected(FAR struct stm32_usbhost_s *priv); +static void stm32_gint_disconnected(FAR struct stm32_usbhost_s *priv); + +/* Second level interrupt handlers */ + +#ifdef CONFIG_STM32_OTGFS_SOFINTR +static inline void stm32_gint_sofisr(FAR struct stm32_usbhost_s *priv); +#endif +static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv); +static inline void stm32_gint_nptxfeisr(FAR struct stm32_usbhost_s *priv); +static inline void stm32_gint_ptxfeisr(FAR struct stm32_usbhost_s *priv); +static inline void stm32_gint_hcisr(FAR struct stm32_usbhost_s *priv); +static inline void stm32_gint_hprtisr(FAR struct stm32_usbhost_s *priv); +static inline void stm32_gint_discisr(FAR struct stm32_usbhost_s *priv); +static inline void stm32_gint_iisooxfrisr(FAR struct stm32_usbhost_s *priv); + +/* First level, global interrupt handler */ + +static int stm32_gint_isr(int irq, FAR void *context); + +/* Interrupt controls */ + +static void stm32_gint_enable(void); +static void stm32_gint_disable(void); +static inline void stm32_hostinit_enable(void); +static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx); + +/* USB host controller operations **********************************************/ + +static int stm32_wait(FAR struct usbhost_driver_s *drvr, bool connected); +static int stm32_enumerate(FAR struct usbhost_driver_s *drvr); +static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, + uint16_t maxpacketsize); +static int stm32_epalloc(FAR struct usbhost_driver_s *drvr, + FAR const FAR struct usbhost_epdesc_s *epdesc, + FAR usbhost_ep_t *ep); +static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep); +static int stm32_alloc(FAR struct usbhost_driver_s *drvr, + FAR uint8_t **buffer, FAR size_t *maxlen); +static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer); +static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr, + FAR uint8_t **buffer, size_t buflen); +static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer); +static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, + FAR const struct usb_ctrlreq_s *req, + FAR uint8_t *buffer); +static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, + FAR const struct usb_ctrlreq_s *req, + FAR const uint8_t *buffer); +static int stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep, + FAR uint8_t *buffer, size_t buflen); +static void stm32_disconnect(FAR struct usbhost_driver_s *drvr); + +/* Initialization **************************************************************/ + +static void stm32_portreset(FAR struct stm32_usbhost_s *priv); +static void stm32_flush_txfifos(uint32_t txfnum); +static void stm32_flush_rxfifo(void); +static void stm32_vbusdrive(FAR struct stm32_usbhost_s *priv, bool state); +static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv); + +static inline void stm32_sw_initialize(FAR struct stm32_usbhost_s *priv); +static inline int stm32_hw_initialize(FAR struct stm32_usbhost_s *priv); + +/******************************************************************************* + * Private Data + *******************************************************************************/ + +/* In this driver implementation, support is provided for only a single a single + * USB device. All status information can be simply retained in a single global + * instance. + */ + +static struct stm32_usbhost_s g_usbhost = +{ + .drvr = + { + .wait = stm32_wait, + .enumerate = stm32_enumerate, + .ep0configure = stm32_ep0configure, + .epalloc = stm32_epalloc, + .epfree = stm32_epfree, + .alloc = stm32_alloc, + .free = stm32_free, + .ioalloc = stm32_ioalloc, + .iofree = stm32_iofree, + .ctrlin = stm32_ctrlin, + .ctrlout = stm32_ctrlout, + .transfer = stm32_transfer, + .disconnect = stm32_disconnect, + }, + .class = NULL, +}; + +/******************************************************************************* + * Public Data + *******************************************************************************/ + +/******************************************************************************* + * Private Functions + *******************************************************************************/ + +/******************************************************************************* + * Name: stm32_printreg + * + * Description: + * Print the contents of an STM32xx register operation + * + *******************************************************************************/ + +#ifdef CONFIG_STM32_USBHOST_REGDEBUG +static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite) +{ + lldbg("%08x%s%08x\n", addr, iswrite ? "<-" : "->", val); +} +#endif + +/******************************************************************************* + * Name: stm32_checkreg + * + * Description: + * Get the contents of an STM32 register + * + *******************************************************************************/ + +#ifdef CONFIG_STM32_USBHOST_REGDEBUG +static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite) +{ + static uint32_t prevaddr = 0; + static uint32_t preval = 0; + static uint32_t count = 0; + static bool prevwrite = false; + + /* Is this the same value that we read from/wrote to the same register last time? + * Are we polling the register? If so, suppress the output. + */ + + if (addr == prevaddr && val == preval && prevwrite == iswrite) + { + /* Yes.. Just increment the count */ + + count++; + } + else + { + /* No this is a new address or value or operation. Were there any + * duplicate accesses before this one? + */ + + if (count > 0) + { + /* Yes.. Just one? */ + + if (count == 1) + { + /* Yes.. Just one */ + + stm32_printreg(prevaddr, preval, prevwrite); + } + else + { + /* No.. More than one. */ + + lldbg("[repeats %d more times]\n", count); + } + } + + /* Save the new address, value, count, and operation for next time */ + + prevaddr = addr; + preval = val; + count = 0; + prevwrite = iswrite; + + /* Show the new regisgter access */ + + stm32_printreg(addr, val, iswrite); + } +} +#endif + +/******************************************************************************* + * Name: stm32_getreg + * + * Description: + * Get the contents of an STM32 register + * + *******************************************************************************/ + +#ifdef CONFIG_STM32_USBHOST_REGDEBUG +static uint32_t stm32_getreg(uint32_t addr) +{ + /* Read the value from the register */ + + uint32_t val = getreg32(addr); + + /* Check if we need to print this value */ + + stm32_checkreg(addr, val, false); + return val; +} +#endif + +/******************************************************************************* + * Name: stm32_putreg + * + * Description: + * Set the contents of an STM32 register to a value + * + *******************************************************************************/ + +#ifdef CONFIG_STM32_USBHOST_REGDEBUG +static void stm32_putreg(uint32_t addr, uint32_t val) +{ + /* Check if we need to print this value */ + + stm32_checkreg(addr, val, true); + + /* Write the value */ + + putreg32(val, addr); +} +#endif + +/******************************************************************************* + * Name: stm32_modifyreg + * + * Description: + * Modify selected bits of an STM32 register. + * + *******************************************************************************/ + +static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits, uint32_t setbits) +{ + stm32_putreg(addr, (((stm32_getreg(addr)) & ~clrbits) | setbits)); +} + +/**************************************************************************** + * Name: stm32_takesem + * + * Description: + * This is just a wrapper to handle the annoying behavior of semaphore + * waits that return due to the receipt of a signal. + * + *******************************************************************************/ + +static void stm32_takesem(sem_t *sem) +{ + /* Take the semaphore (perhaps waiting) */ + + while (sem_wait(sem) != 0) + { + /* The only case that an error should occr here is if the wait was + * awakened by a signal. + */ + + ASSERT(errno == EINTR); + } +} + +/**************************************************************************** + * Name: stm32_getle16 + * + * Description: + * Get a (possibly unaligned) 16-bit little endian value. + * + *******************************************************************************/ + +static inline uint16_t stm32_getle16(const uint8_t *val) +{ + return (uint16_t)val[1] << 8 | (uint16_t)val[0]; +} + +/******************************************************************************* + * Name: stm32_chan_alloc + * + * Description: + * Allocate a channel. + * + *******************************************************************************/ + +static int stm32_chan_alloc(FAR struct stm32_usbhost_s *priv) +{ + int chidx; + + /* Search the table of channels */ + + for (chidx = 0 ; chidx < STM32_NHOST_CHANNELS ; chidx++) + { + /* Is this channel available? */ + + if (!priv->chan[chidx].inuse) + { + /* Yes... make it "in use" and return the index */ + + priv->chan[chidx].inuse = true; + return chidx; + } + } + + /* All of the channels are "in-use" */ + + return -EBUSY; +} + +/******************************************************************************* + * Name: stm32_chan_free + * + * Description: + * Free a previoiusly allocated channel. + * + *******************************************************************************/ + +static void stm32_chan_free(FAR struct stm32_usbhost_s *priv, int chidx) +{ + DEBUGASSERT((unsigned)chidx < STM32_NHOST_CHANNELS); + + /* Halt the channel */ + + stm32_chan_halt(priv, chidx, CHREASON_FREED); + + /* Mark the channel available */ + + priv->chan[chidx].inuse = false; +} + +/******************************************************************************* + * Name: stm32_chan_freeall + * + * Description: + * Free all channels. + * + *******************************************************************************/ + +static inline void stm32_chan_freeall(FAR struct stm32_usbhost_s *priv) +{ + uint8_t chidx; + + /* Free all host channels */ + + for (chidx = 2; chidx < STM32_NHOST_CHANNELS ; chidx ++) + { + stm32_chan_free(priv, chidx); + } +} + +/******************************************************************************* + * Name: stm32_chan_configure + * + * Description: + * Configure or re-configure a host channel. Host channels are configured + * when endpoint is allocated and EP0 (only) is re-configured with the + * max packet size or device address changes. + * + *******************************************************************************/ + +static void stm32_chan_configure(FAR struct stm32_usbhost_s *priv, int chidx) +{ + uint32_t regval; + + /* Clear any old pending interrupts for this host channel. */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), 0xffffffff); + + /* Enable channel interrupts required for transfers on this channel. */ + + regval = 0; + + switch (priv->chan[chidx].eptype) + { + case OTGFS_EPTYPE_CTRL: + case OTGFS_EPTYPE_BULK: + { + /* Interrupts required for CTRL and BULK endpoints */ + + regval |= (OTGFS_HCINT_XFRC | OTGFS_HCINT_STALL | OTGFS_HCINT_NAK | + OTGFS_HCINT_TXERR | OTGFS_HCINT_DTERR); + + /* Additional setting for IN/OUT endpoints */ + + if (priv->chan[chidx].in) + { + regval |= OTGFS_HCINT_BBERR; + } + else + { + regval |= OTGFS_HCINT_NYET; + } + } + break; + + case OTGFS_EPTYPE_INTR: + { + /* Interrupts required for INTR endpoints */ + + regval |= (OTGFS_HCINT_XFRC | OTGFS_HCINT_STALL | OTGFS_HCINT_NAK | + OTGFS_HCINT_TXERR | OTGFS_HCINT_FRMOR | OTGFS_HCINT_DTERR); + + /* Additional setting for IN endpoints */ + + if (priv->chan[chidx].in) + { + regval |= OTGFS_HCINT_BBERR; + } + } + break; + + case OTGFS_EPTYPE_ISOC: + { + /* Interrupts required for ISOC endpoints */ + + regval |= (OTGFS_HCINT_XFRC | OTGFS_HCINT_ACK | OTGFS_HCINT_FRMOR); + + /* Additional setting for IN endpoints */ + + if (priv->chan[chidx].in) + { + regval |= (OTGFS_HCINT_TXERR | OTGFS_HCINT_BBERR); + } + } + break; + } + + stm32_putreg(STM32_OTGFS_HCINTMSK(chidx), regval); + + /* Enable the top level host channel interrupt. */ + + stm32_modifyreg(STM32_OTGFS_HAINTMSK, 0, OTGFS_HAINT(chidx)); + + /* Make sure host channel interrupts are enabled. */ + + stm32_modifyreg(STM32_OTGFS_GINTMSK, 0, OTGFS_GINT_HC); + + /* Program the HCCHAR register */ + + regval = ((uint32_t)priv->chan[chidx].maxpacket << OTGFS_HCCHAR_MPSIZ_SHIFT) | + ((uint32_t)priv->chan[chidx].epno << OTGFS_HCCHAR_EPNUM_SHIFT) | + ((uint32_t)priv->chan[chidx].eptype << OTGFS_HCCHAR_EPTYP_SHIFT) | + ((uint32_t)priv->devaddr << OTGFS_HCCHAR_DAD_SHIFT); + + /* Special case settings for low speed devices */ + + if (priv->lowspeed) + { + regval |= OTGFS_HCCHAR_LSDEV; + } + + /* Special case settings for IN endpoints */ + + if (priv->chan[chidx].in) + { + regval |= OTGFS_HCCHAR_EPDIR_IN; + } + + /* Special case settings for INTR endpoints */ + + if (priv->chan[chidx].eptype == OTGFS_EPTYPE_INTR) + { + regval |= OTGFS_HCCHAR_ODDFRM; + } + + /* Write the channel configuration */ + + stm32_putreg(STM32_OTGFS_HCCHAR(chidx), regval); +} + +/******************************************************************************* + * Name: stm32_chan_halt + * + * Description: + * Halt the channel associated with 'chidx' by setting the CHannel DISable + * (CHDIS) bit in in the HCCHAR register. + * + *******************************************************************************/ + +static void stm32_chan_halt(FAR struct stm32_usbhost_s *priv, int chidx, + enum stm32_chreason_e chreason) +{ + uint32_t hcchar; + uint32_t intmsk; + uint32_t eptype; + unsigned int avail; + + /* Save the reason for the halt. We need this in the channel halt interrrupt + * handling logic to know what to do next. + */ + + priv->chan[chidx].chreason = (uint8_t)chreason; + + /* "The application can disable any channel by programming the OTG_FS_HCCHARx + * register with the CHDIS and CHENA bits set to 1. This enables the OTG_FS + * host to flush the posted requests (if any) and generates a channel halted + * interrupt. The application must wait for the CHH interrupt in OTG_FS_HCINTx + * before reallocating the channel for other transactions. The OTG_FS host + * does not interrupt the transaction that has already been started on the + * USB." + */ + + hcchar = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + hcchar |= (OTGFS_HCCHAR_CHDIS | OTGFS_HCCHAR_CHENA); + + /* Get the endpoint type from the HCCHAR register */ + + eptype = hcchar & OTGFS_HCCHAR_EPTYP_MASK; + + /* Check for space in the Tx FIFO to issue the halt. + * + * "Before disabling a channel, the application must ensure that there is at + * least one free space available in the non-periodic request queue (when + * disabling a non-periodic channel) or the periodic request queue (when + * disabling a periodic channel). The application can simply flush the + * posted requests when the Request queue is full (before disabling the + * channel), by programming the OTG_FS_HCCHARx register with the CHDIS bit + * set to 1, and the CHENA bit cleared to 0. + */ + + if (eptype == OTGFS_HCCHAR_EPTYP_CTRL || eptype == OTGFS_HCCHAR_EPTYP_BULK) + { + /* Get the number of words available in the non-periodic Tx FIFO. */ + + avail = stm32_getreg(STM32_OTGFS_HNPTXSTS) & OTGFS_HNPTXSTS_NPTXFSAV_MASK; + } + else /* if (eptype == OTGFS_HCCHAR_EPTYP_ISOC || eptype == OTGFS_HCCHAR_EPTYP_INTR) */ + { + /* Get the number of words available in the non-periodic Tx FIFO. */ + + avail = stm32_getreg(STM32_OTGFS_HPTXSTS) & OTGFS_HPTXSTS_PTXFSAVL_MASK; + } + + /* Check if there is any space available in the Tx FIFO. */ + + if (avail == 0) + { + /* The Tx FIFO is full... disable the channel to flush the requests */ + + hcchar &= ~OTGFS_HCCHAR_CHENA; + } + + /* Unmask the CHannel Halted (CHH) interrupt */ + + intmsk = stm32_getreg(STM32_OTGFS_HCINTMSK(chidx)); + intmsk |= OTGFS_HCINT_CHH; + stm32_putreg(STM32_OTGFS_HCINTMSK(chidx), intmsk); + + /* Halt the channel by setting CHDIS (and maybe CHENA) in the HCCHAR */ + + stm32_putreg(STM32_OTGFS_HCCHAR(chidx), hcchar); +} + +/******************************************************************************* + * Name: stm32_chan_waitsetup + * + * Description: + * Set the request for the transfer complete event well BEFORE enabling the + * transfer (as soon as we are absolutely committed to the to avoid transfer). + * We do this to minimize race conditions. This logic would have to be expanded + * if we want to have more than one packet in flight at a time! + * + * Assumptions: + * Called from a normal thread context BEFORE the transfer has been started. + * + *******************************************************************************/ + +static int stm32_chan_waitsetup(FAR struct stm32_usbhost_s *priv, + FAR struct stm32_chan_s *chan) +{ + irqstate_t flags = irqsave(); + int ret = -ENODEV; + + /* Is the device still connected? */ + + if (priv->connected) + { + /* Yes.. then set waiter to indicate that we expect to be informed when + * either (1) the device is disconnected, or (2) the transfer completed. + */ + + chan->waiter = true; + ret = OK; + } + + irqrestore(flags); + return ret; +} + +/******************************************************************************* + * Name: stm32_chan_wait + * + * Description: + * Wait for a transfer on a channel to complete. + * + * Assumptions: + * Called from a normal thread context + * + *******************************************************************************/ + +static int stm32_chan_wait(FAR struct stm32_usbhost_s *priv, + FAR struct stm32_chan_s *chan) +{ + irqstate_t flags; + int ret; + + /* Disable interrupts so that the following operations will be atomic. On + * the OTG FS global interrupt needs to be disabled. However, here we disable + * all interrupts to exploit that fact that interrupts will be re-enabled + * while we wait. + */ + + flags = irqsave(); + + /* Loop, testing for an end of transfer conditino. The channel 'result' + * was set to EBUSY and 'waiter' was set to true before the transfer; 'waiter' + * will be set to false and 'result' will be set appropriately when the + * tranfer is completed. + */ + + do + { + /* Wait for the transfer to complete. NOTE the transfer may already + * completed before we get here or the transfer may complete while we + * wait here. + */ + + ret = sem_wait(&chan->waitsem); + + /* sem_wait should succeeed. But it is possible that we could be + * awakened by a signal too. + */ + + DEBUGASSERT(ret == OK || get_errno() == EINTR); + } + while (chan->waiter); + + /* The transfer is complete re-enable interrupts and return the result */ + + ret = -(int)chan->result; + irqrestore(flags); + return ret; +} + +/******************************************************************************* + * Name: stm32_chan_wakeup + * + * Description: + * A channel transfer has completed... wakeup any threads waiting for the + * transfer to complete. + * + * Assumptions: + * This function is called from the transfer complete interrupt handler for + * the channel. Interrupts are disabled. + * + *******************************************************************************/ + +static void stm32_chan_wakeup(FAR struct stm32_usbhost_s *priv, + FAR struct stm32_chan_s *chan) +{ + /* Is the the transfer complete? Is there a thread waiting for this transfer + * to complete? + */ + + if (chan->result != EBUSY && chan->waiter) + { + ullvdbg("Wakeup with result: %d\n", chan->result); + stm32_givesem(&chan->waitsem); + chan->waiter = false; + } +} + +/******************************************************************************* + * Name: stm32_transfer_start + * + * Description: + * Start at transfer on the select IN or OUT channel. + * + *******************************************************************************/ + +static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx) +{ + FAR struct stm32_chan_s *chan; + uint32_t regval; + unsigned int npackets; + unsigned int maxpacket; + unsigned int avail; + unsigned int wrsize; + unsigned int minsize; + + /* Set up the initial state of the transfer */ + + chan = &priv->chan[chidx]; + uvdbg("chidx: %d buflen: %d\n", chidx, chan->buflen); + + chan->result = EBUSY; + chan->inflight = 0; + priv->chidx = chidx; + + /* Compute the expected number of packets associated to the transfer. + * If the transfer length is zero (or less than the size of one maximum + * size packet), then one packet is expected. + */ + + /* If the transfer size is greater than one packet, then calculate the + * number of packets that will be received/sent, including any partial + * final packet. + */ + + maxpacket = chan->maxpacket; + + if (chan->buflen > maxpacket) + { + npackets = (chan->buflen + maxpacket - 1) / maxpacket; + + /* Clip if the buffer length if it exceeds the maximum number of + * packets that can be transferred (this should not happen). + */ + + if (npackets > STM32_MAX_PKTCOUNT) + { + npackets = STM32_MAX_PKTCOUNT; + chan->buflen = STM32_MAX_PKTCOUNT * maxpacket; + ulldbg("CLIP: chidx: %d buflen: %d\n", chidx, chan->buflen); + } + } + else + { + /* One packet will be sent/received (might be a zero length packet) */ + + npackets = 1; + } + + /* If it is an IN transfer, then adjust the size of the buffer UP to + * a full number of packets. Hmmm... couldn't this cause an overrun + * into unallocated memory? + */ + +#if 0 /* Think about this */ + if (chan->in) + { + /* Force the buffer length to an even multiple of maxpacket */ + + chan->buflen = npackets * maxpacket; + } +#endif + + /* Save the number of packets in the transfer. We will need this in + * order to set the next data toggle correctly when the transfer + * completes. + */ + + chan->npackets = (uint8_t)npackets; + + /* Setup the HCTSIZn register */ + + regval = ((uint32_t)chan->buflen << OTGFS_HCTSIZ_XFRSIZ_SHIFT) | + ((uint32_t)npackets << OTGFS_HCTSIZ_PKTCNT_SHIFT) | + ((uint32_t)chan->pid << OTGFS_HCTSIZ_DPID_SHIFT); + stm32_putreg(STM32_OTGFS_HCTSIZ(chidx), regval); + + /* Setup the HCCHAR register: Frame oddness and host channel enable */ + + regval = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + + /* Set/clear the Odd Frame bit. Check for an even frame; if so set Odd + * Frame. This field is applicable for only periodic (isochronous and + * interrupt) channels. + */ + + if ((stm32_getreg(STM32_OTGFS_HFNUM) & 1) == 0) + { + regval |= OTGFS_HCCHAR_ODDFRM; + } + + regval &= ~OTGFS_HCCHAR_CHDIS; + regval |= OTGFS_HCCHAR_CHENA; + stm32_putreg(STM32_OTGFS_HCCHAR(chidx), regval); + + /* If this is an out transfer, then we need to do more.. we need to copy + * the outgoing data into the correct TxFIFO. + */ + + if (!chan->in && chan->buflen > 0) + { + /* Handle non-periodic (CTRL and BULK) OUT transfers differently than + * periodic (INTR and ISOC) OUT transfers. + */ + + minsize = MIN(chan->buflen, chan->maxpacket); + + switch (chan->eptype) + { + case OTGFS_EPTYPE_CTRL: /* Non periodic transfer */ + case OTGFS_EPTYPE_BULK: + { + /* Read the Non-periodic Tx FIFO status register */ + + regval = stm32_getreg(STM32_OTGFS_HNPTXSTS); + avail = ((regval & OTGFS_HNPTXSTS_NPTXFSAV_MASK) >> OTGFS_HNPTXSTS_NPTXFSAV_SHIFT) << 2; + } + break; + + /* Periodic transfer */ + + case OTGFS_EPTYPE_INTR: + case OTGFS_EPTYPE_ISOC: + { + /* Read the Non-periodic Tx FIFO status register */ + + regval = stm32_getreg(STM32_OTGFS_HPTXSTS); + avail = ((regval & OTGFS_HPTXSTS_PTXFSAVL_MASK) >> OTGFS_HPTXSTS_PTXFSAVL_SHIFT) << 2; + } + break; + + default: + DEBUGASSERT(false); + return; + } + + /* Is there space in the TxFIFO to hold the minimum size packet? */ + + if (minsize <= avail) + { + /* Yes.. Get the size of the biggest thing that we can put in the Tx FIFO now */ + + wrsize = chan->buflen; + if (wrsize > avail) + { + /* Clip the write size to the number of full, max sized packets + * that will fit in the Tx FIFO. + */ + + unsigned int wrpackets = avail / chan->maxpacket; + wrsize = wrpackets * chan->maxpacket; + } + + /* Write packet into the Tx FIFO. */ + + stm32_gint_wrpacket(priv, chan->buffer, chidx, wrsize); + } + + /* Did we put the entire buffer into the Tx FIFO? */ + + if (chan->buflen > avail) + { + /* No, there was insufficient space to hold the entire transfer ... + * Enable the Tx FIFO interrupt to handle the transfer when the Tx + * FIFO becomes empty. + */ + + stm32_txfe_enable(priv, chidx); + } + } +} + +/******************************************************************************* + * Name: stm32_getframe + * + * Description: + * Get the current frame number. + * + *******************************************************************************/ + +static inline uint16_t stm32_getframe(void) +{ + return (uint16_t)(stm32_getreg(STM32_OTGFS_HFNUM) & OTGFS_HFNUM_FRNUM_MASK); +} + +/******************************************************************************* + * Name: stm32_ctrl_sendsetup + * + * Description: + * Send an IN/OUT SETUP packet. + * + *******************************************************************************/ + +static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv, + FAR const struct usb_ctrlreq_s *req) +{ + FAR struct stm32_chan_s *chan; + uint16_t start; + uint16_t elapsed; + int ret; + + /* Loop while the device reports NAK (and a timeout is not exceeded */ + + chan = &priv->chan[priv->ep0out]; + start = stm32_getframe(); + + do + { + /* Send the SETUP packet */ + + chan->pid = OTGFS_PID_SETUP; + chan->buffer = (FAR uint8_t *)req; + chan->buflen = USB_SIZEOF_CTRLREQ; + + /* Set up for the wait BEFORE starting the transfer */ + + ret = stm32_chan_waitsetup(priv, chan); + if (ret != OK) + { + udbg("ERROR: Device disconnected\n"); + return ret; + } + + /* Start the transfer */ + + stm32_transfer_start(priv, priv->ep0out); + + /* Wait for the transfer to complete */ + + ret = stm32_chan_wait(priv, chan); + + /* Return on success and for all failures other than EAGAIN. EAGAIN + * means that the device NAKed the SETUP command and that we should + * try a few more times. + */ + + if (ret != -EAGAIN) + { + /* Output some debug information if the transfer failed */ + + if (ret < 0) + { + udbg("Transfer failed: %d\n", ret); + } + + /* Return the result in any event */ + + return ret; + } + + /* Get the elapsed time (in frames) */ + + elapsed = stm32_getframe() - start; + } + while (elapsed < STM32_SETUP_DELAY); + + return -ETIMEDOUT; +} + +/******************************************************************************* + * Name: stm32_ctrl_senddata + * + * Description: + * Send data in the data phase of an OUT control transfer. Or send status + * in the status phase of an IN control transfer + * + *******************************************************************************/ + +static int stm32_ctrl_senddata(FAR struct stm32_usbhost_s *priv, + FAR uint8_t *buffer, unsigned int buflen) +{ + FAR struct stm32_chan_s *chan = &priv->chan[priv->ep0out]; + int ret; + + /* Save buffer information */ + + chan->buffer = buffer; + chan->buflen = buflen; + + /* Set the DATA PID */ + + if (buflen == 0) + { + /* For status OUT stage with buflen == 0, set PID DATA1 */ + + chan->outdata1 = true; + } + + /* Set the Data PID as per the outdata1 boolean */ + + chan->pid = chan->outdata1 ? OTGFS_PID_DATA1 : OTGFS_PID_DATA0; + + /* Set up for the wait BEFORE starting the transfer */ + + ret = stm32_chan_waitsetup(priv, chan); + if (ret != OK) + { + udbg("ERROR: Device disconnected\n"); + return ret; + } + + /* Start the transfer */ + + stm32_transfer_start(priv, priv->ep0out); + + /* Wait for the transfer to complete and return the result */ + + return stm32_chan_wait(priv, chan); +} + +/******************************************************************************* + * Name: stm32_ctrl_recvdata + * + * Description: + * Receive data in the data phase of an IN control transfer. Or receive status + * in the status phase of an OUT control transfer + * + *******************************************************************************/ + +static int stm32_ctrl_recvdata(FAR struct stm32_usbhost_s *priv, + FAR uint8_t *buffer, unsigned int buflen) +{ + FAR struct stm32_chan_s *chan = &priv->chan[priv->ep0in]; + int ret; + + /* Save buffer information */ + + chan->pid = OTGFS_PID_DATA1; + chan->buffer = buffer; + chan->buflen = buflen; + + /* Set up for the wait BEFORE starting the transfer */ + + ret = stm32_chan_waitsetup(priv, chan); + if (ret != OK) + { + udbg("ERROR: Device disconnected\n"); + return ret; + } + + /* Start the transfer */ + + stm32_transfer_start(priv, priv->ep0in); + + /* Wait for the transfer to complete and return the result */ + + return stm32_chan_wait(priv, chan); +} + +/******************************************************************************* + * Name: stm32_in_transfer + * + * Description: + * Transfer 'buflen' bytes into 'buffer' from an IN channel. + * + *******************************************************************************/ + +static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx, + FAR uint8_t *buffer, size_t buflen) +{ + FAR struct stm32_chan_s *chan; + uint16_t start; + uint16_t elapsed; + int ret = OK; + + /* Loop until the transfer completes (i.e., buflen is decremented to zero) + * or a fatal error occurs (any error other than a simple NAK) + */ + + chan = &priv->chan[chidx]; + chan->buffer = buffer; + chan->buflen = buflen; + + start = stm32_getframe(); + while (chan->buflen > 0) + { + /* Set up for the wait BEFORE starting the transfer */ + + ret = stm32_chan_waitsetup(priv, chan); + if (ret != OK) + { + udbg("ERROR: Device disconnected\n"); + return ret; + } + + /* Set up for the transfer based on the direction and the endpoint type */ + + switch (chan->eptype) + { + default: + case OTGFS_EPTYPE_CTRL: /* Control */ + { + /* This kind of transfer on control endpoints other than EP0 are not + * currently supported + */ + + return -ENOSYS; + } + + case OTGFS_EPTYPE_ISOC: /* Isochronous */ + { + /* Set up the IN data PID */ + + chan->pid = OTGFS_PID_DATA0; + } + break; + + case OTGFS_EPTYPE_BULK: /* Bulk */ + case OTGFS_EPTYPE_INTR: /* Interrupt */ + { + /* Setup the IN data PID */ + + chan->pid = chan->indata1 ? OTGFS_PID_DATA1 : OTGFS_PID_DATA0; + } + break; + } + + /* Start the transfer */ + + stm32_transfer_start(priv, chidx); + + /* Wait for the transfer to complete and get the result */ + + ret = stm32_chan_wait(priv, chan); + + /* EAGAIN indicates that the device NAKed the transfer and we need + * do try again. Anything else (success or other errors) will + * cause use to return + */ + + if (ret != OK) + { + udbg("Transfer failed: %d\n", ret); + + /* Check for a special case: If (1) the transfer was NAKed and (2) + * no Tx FIFO empty or Rx FIFO not-empty event occurred, then we + * should be able to just flush the Rx and Tx FIFOs and try again. + * We can detect this latter case becasue the then the transfer + * buffer pointer and buffer size will be unaltered. + */ + + elapsed = stm32_getframe() - start; + if (ret != -EAGAIN || /* Not a NAK condition OR */ + elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */ + chan->buflen != buflen) /* Data has been partially transferred */ + { + /* Break out and return the error */ + + break; + } + } + } + + return ret; +} + +/******************************************************************************* + * Name: stm32_out_transfer + * + * Description: + * Transfer the 'buflen' bytes in 'buffer' through an OUT channel. + * + *******************************************************************************/ + +static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx, + FAR uint8_t *buffer, size_t buflen) +{ + FAR struct stm32_chan_s *chan; + uint16_t start; + uint16_t elapsed; + size_t xfrlen; + int ret = OK; + + /* Loop until the transfer completes (i.e., buflen is decremented to zero) + * or a fatal error occurs (any error other than a simple NAK) + */ + + chan = &priv->chan[chidx]; + start = stm32_getframe(); + + while (buflen > 0) + { + /* Transfer one packet at a time. The hardware is capable of queueing + * multiple OUT packets, but I just haven't figured out how to handle + * the case where a single OUT packet in the group is NAKed. + */ + + xfrlen = MIN(chan->maxpacket, buflen); + chan->buffer = buffer; + chan->buflen = xfrlen; + + /* Set up for the wait BEFORE starting the transfer */ + + ret = stm32_chan_waitsetup(priv, chan); + if (ret != OK) + { + udbg("ERROR: Device disconnected\n"); + return ret; + } + + /* Set up for the transfer based on the direction and the endpoint type */ + + switch (chan->eptype) + { + default: + case OTGFS_EPTYPE_CTRL: /* Control */ + { + /* This kind of transfer on control endpoints other than EP0 are not + * currently supported + */ + + return -ENOSYS; + } + + case OTGFS_EPTYPE_ISOC: /* Isochronous */ + { + /* Set up the OUT data PID */ + + chan->pid = OTGFS_PID_DATA0; + } + break; + + case OTGFS_EPTYPE_BULK: /* Bulk */ + { + /* Setup the OUT data PID */ + + chan->pid = chan->outdata1 ? OTGFS_PID_DATA1 : OTGFS_PID_DATA0; + } + break; + + case OTGFS_EPTYPE_INTR: /* Interrupt */ + { + /* Setup the OUT data PID */ + + chan->pid = chan->outdata1 ? OTGFS_PID_DATA1 : OTGFS_PID_DATA0; + + /* Toggle the OUT data PID for the next transfer */ + + chan->outdata1 ^= true; + } + } + + /* Start the transfer */ + + stm32_transfer_start(priv, chidx); + + /* Wait for the transfer to complete and get the result */ + + ret = stm32_chan_wait(priv, chan); + + /* Handle transfer failures */ + + if (ret != OK) + { + udbg("Transfer failed: %d\n", ret); + + /* Check for a special case: If (1) the transfer was NAKed and (2) + * no Tx FIFO empty or Rx FIFO not-empty event occurred, then we + * should be able to just flush the Rx and Tx FIFOs and try again. + * We can detect this latter case becasue the then the transfer + * buffer pointer and buffer size will be unaltered. + */ + + elapsed = stm32_getframe() - start; + if (ret != -EAGAIN || /* Not a NAK condition OR */ + elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */ + chan->buflen != xfrlen) /* Data has been partially transferred */ + { + /* Break out and return the error */ + + break; + } + + /* Is this flush really necessary? What does the hardware do with the + * data in the FIFO when the NAK occurs? Does it discard it? + */ + + stm32_flush_txfifos(OTGFS_GRSTCTL_TXFNUM_HALL); + + /* Get the device a little time to catch up. Then retry the transfer + * using the same buffer pointer and length. + */ + + usleep(20*1000); + } + else + { + /* Successfully transferred. Update the buffer pointer and length */ + + buffer += xfrlen; + buflen -= xfrlen; + } + } + + return ret; +} + +/******************************************************************************* + * Name: stm32_gint_wrpacket + * + * Description: + * Transfer the 'buflen' bytes in 'buffer' to the Tx FIFO associated with + * 'chidx' (non-DMA). + * + *******************************************************************************/ + +static void stm32_gint_wrpacket(FAR struct stm32_usbhost_s *priv, + FAR uint8_t *buffer, int chidx, int buflen) +{ + FAR uint32_t *src; + uint32_t fifo; + int buflen32; + + stm32_pktdump("Sending", buffer, buflen); + + /* Get the number of 32-byte words associated with this byte size */ + + buflen32 = (buflen + 3) >> 2; + + /* Get the address of the Tx FIFO associated with this channel */ + + fifo = STM32_OTGFS_DFIFO_HCH(chidx); + + /* Transfer all of the data into the Tx FIFO */ + + src = (FAR uint32_t *)buffer; + for (; buflen32 > 0; buflen32--) + { + uint32_t data = *src++; + stm32_putreg(fifo, data); + } + + /* Increment the count of bytes "in-flight" in the Tx FIFO */ + + priv->chan[chidx].inflight += buflen; +} + +/******************************************************************************* + * Name: stm32_gint_hcinisr + * + * Description: + * USB OTG FS host IN channels interrupt handler + * + * One the completion of the transfer, the channel result byte may be set as + * follows: + * + * OK - Transfer completed successfully + * EAGAIN - If devices NAKs the transfer or NYET occurs + * EPERM - If the endpoint stalls + * EIO - On a TX or data toggle error + * EPIPE - Frame overrun + * + * EBUSY in the result field indicates that the transfer has not completed. + * + *******************************************************************************/ + +static inline void stm32_gint_hcinisr(FAR struct stm32_usbhost_s *priv, + int chidx) +{ + FAR struct stm32_chan_s *chan = &priv->chan[chidx]; + uint32_t regval; + uint32_t pending; + + /* Read the HCINT register to get the pending HC interrupts. Read the + * HCINTMSK register to get the set of enabled HC interrupts. + */ + + pending = stm32_getreg(STM32_OTGFS_HCINT(chidx)); + regval = stm32_getreg(STM32_OTGFS_HCINTMSK(chidx)); + + /* AND the two to get the set of enabled, pending HC interrupts */ + + pending &= regval; + ullvdbg("HCINTMSK%d: %08x pending: %08x\n", chidx, regval, pending); + + /* Check for a pending ACK response received/transmitted (ACK) interrupt */ + + if ((pending & OTGFS_HCINT_ACK) != 0) + { + /* Clear the pending the ACK response received/transmitted (ACK) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_ACK); + } + + /* Check for a pending STALL response receive (STALL) interrupt */ + + else if ((pending & OTGFS_HCINT_STALL) != 0) + { + /* Clear the NAK and STALL Conditions. */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), (OTGFS_HCINT_NAK | OTGFS_HCINT_STALL)); + + /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is + * received on the channel. + */ + + stm32_chan_halt(priv, chidx, CHREASON_STALL); + + /* When there is a STALL, clear any pending NAK so that it is not + * processed below. + */ + + pending &= ~OTGFS_HCINT_NAK; + } + + /* Check for a pending Data Toggle ERRor (DTERR) interrupt */ + + else if ((pending & OTGFS_HCINT_DTERR) != 0) + { + /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is + * received on the channel. + */ + + stm32_chan_halt(priv, chidx, CHREASON_DTERR); + + /* Clear the NAK and data toggle error conditions */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), (OTGFS_HCINT_NAK | OTGFS_HCINT_DTERR)); + } + + /* Check for a pending FRaMe OverRun (FRMOR) interrupt */ + + if ((pending & OTGFS_HCINT_FRMOR) != 0) + { + /* Halt the channel -- the CHH interrrupt is expected next */ + + stm32_chan_halt(priv, chidx, CHREASON_FRMOR); + + /* Clear the FRaMe OverRun (FRMOR) condition */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_FRMOR); + } + + /* Check for a pending TransFeR Completed (XFRC) interrupt */ + + else if ((pending & OTGFS_HCINT_XFRC) != 0) + { + /* Clear the TransFeR Completed (XFRC) condition */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_XFRC); + + /* Then handle the transfer completion event based on the endpoint type */ + + if (chan->eptype == OTGFS_EPTYPE_CTRL || chan->eptype == OTGFS_EPTYPE_BULK) + { + /* Halt the channel -- the CHH interrrupt is expected next */ + + stm32_chan_halt(priv, chidx, CHREASON_XFRC); + + /* Clear any pending NAK condition. The 'indata1' data toggle + * should have been appropriately updated by the the RxFIFO + * logic as each packet was received. + */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_NAK); + } + else if (chan->eptype == OTGFS_EPTYPE_INTR) + { + /* Force the next transfer on an ODD frame */ + + regval = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + regval |= OTGFS_HCCHAR_ODDFRM; + stm32_putreg(STM32_OTGFS_HCCHAR(chidx), regval); + + /* Set the request done state */ + + chan->result = OK; + } + } + + /* Check for a pending CHannel Halted (CHH) interrupt */ + + else if ((pending & OTGFS_HCINT_CHH) != 0) + { + /* Mask the CHannel Halted (CHH) interrupt */ + + regval = stm32_getreg(STM32_OTGFS_HCINTMSK(chidx)); + regval &= ~OTGFS_HCINT_CHH; + stm32_putreg(STM32_OTGFS_HCINTMSK(chidx), regval); + + /* Update the request state based on the host state machine state */ + + if (chan->chreason == CHREASON_XFRC) + { + /* Set the request done reult */ + + chan->result = OK; + } + else if (chan->chreason == CHREASON_STALL) + { + /* Set the request stall result */ + + chan->result = EPERM; + } + else if ((chan->chreason == CHREASON_TXERR) || + (chan->chreason == CHREASON_DTERR)) + { + /* Set the request I/O error result */ + + chan->result = EIO; + } + else if (chan->chreason == CHREASON_NAK) + { + /* Halt on NAK only happens on an INTR channel. Fetch the HCCHAR register + * and check for an interrupt endpoint. + */ + + regval = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + if ((regval & OTGFS_HCCHAR_EPTYP_MASK) == OTGFS_HCCHAR_EPTYP_INTR) + { + /* Toggle the IN data toggle (Used by Bulk and INTR only) */ + + chan->indata1 ^= true; + } + + /* Set the NAK error result */ + + chan->result = EAGAIN; + } + else /* if (chan->chreason == CHREASON_FRMOR) */ + { + /* Set the frame overrun error result */ + + chan->result = EPIPE; + } + + /* Clear the CHannel Halted (CHH) condition */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_CHH); + } + + /* Check for a pending Transaction ERror (TXERR) interrupt */ + + else if ((pending & OTGFS_HCINT_TXERR) != 0) + { + /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is + * received on the channel. + */ + + stm32_chan_halt(priv, chidx, CHREASON_TXERR); + + /* Clear the Transaction ERror (TXERR) condition */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_TXERR); + } + + /* Check for a pending NAK response received (NAK) interrupt */ + + else if ((pending & OTGFS_HCINT_NAK) != 0) + { + /* For a BULK tranfer, the hardware is capable of retrying + * automatically on a NAK. However, this is not always + * what we need to do. So we always halt the transfer and + * return control to high level logic in the even of a NAK. + */ + +#if 0 + /* Halt the interrupt channel */ + + if (chan->eptype == OTGFS_EPTYPE_CTRL) + { + /* Halt the channel -- the CHH interrrupt is expected next */ + + stm32_chan_halt(priv, chidx, CHREASON_NAK); + } + + /* Re-activate CTRL and BULK channels */ + + else if (chan->eptype == OTGFS_EPTYPE_CTRL || + chan->eptype == OTGFS_EPTYPE_BULK) + { + /* Re-activate the channel by clearing CHDIS and assuring that + * CHENA is set + */ + + regval = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + regval |= OTGFS_HCCHAR_CHENA; + regval &= ~OTGFS_HCCHAR_CHDIS; + stm32_putreg(STM32_OTGFS_HCCHAR(chidx), regval); + } +#else + /* Halt all transfers on the NAK -- the CHH interrrupt is expected next */ + + stm32_chan_halt(priv, chidx, CHREASON_NAK); +#endif + /* Clear the NAK condition */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_NAK); + } + + /* Check for a transfer complete event */ + + stm32_chan_wakeup(priv, chan); +} + +/******************************************************************************* + * Name: stm32_gint_hcoutisr + * + * Description: + * USB OTG FS host OUT channels interrupt handler + * + * One the completion of the transfer, the channel result byte may be set as + * follows: + * + * OK - Transfer completed successfully + * EAGAIN - If devices NAKs the transfer or NYET occurs + * EPERM - If the endpoint stalls + * EIO - On a TX or data toggle error + * EPIPE - Frame overrun + * + * EBUSY in the result field indicates that the transfer has not completed. + * + *******************************************************************************/ + +static inline void stm32_gint_hcoutisr(FAR struct stm32_usbhost_s *priv, + int chidx) +{ + FAR struct stm32_chan_s *chan = &priv->chan[chidx]; + uint32_t regval; + uint32_t pending; + + /* Read the HCINT register to get the pending HC interrupts. Read the + * HCINTMSK register to get the set of enabled HC interrupts. + */ + + pending = stm32_getreg(STM32_OTGFS_HCINT(chidx)); + regval = stm32_getreg(STM32_OTGFS_HCINTMSK(chidx)); + + /* AND the two to get the set of enabled, pending HC interrupts */ + + pending &= regval; + ullvdbg("HCINTMSK%d: %08x pending: %08x\n", chidx, regval, pending); + + /* Check for a pending ACK response received/transmitted (ACK) interrupt */ + + if ((pending & OTGFS_HCINT_ACK) != 0) + { + /* Clear the pending the ACK response received/transmitted (ACK) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_ACK); + } + + /* Check for a pending FRaMe OverRun (FRMOR) interrupt */ + + else if ((pending & OTGFS_HCINT_FRMOR) != 0) + { + /* Halt the channel (probably not necessary for FRMOR) */ + + stm32_chan_halt(priv, chidx, CHREASON_FRMOR); + + /* Clear the pending the FRaMe OverRun (FRMOR) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_FRMOR); + } + + /* Check for a pending TransFeR Completed (XFRC) interrupt */ + + else if ((pending & OTGFS_HCINT_XFRC) != 0) + { + /* Decrement the number of bytes remaining by the number of + * bytes that were "in-flight". + */ + + priv->chan[chidx].buffer += priv->chan[chidx].inflight; + priv->chan[chidx].buflen -= priv->chan[chidx].inflight; + priv->chan[chidx].inflight = 0; + + /* Halt the channel -- the CHH interrrupt is expected next */ + + stm32_chan_halt(priv, chidx, CHREASON_XFRC); + + /* Clear the pending the TransFeR Completed (XFRC) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_XFRC); + } + + /* Check for a pending STALL response receive (STALL) interrupt */ + + else if ((pending & OTGFS_HCINT_STALL) != 0) + { + /* Clear the pending the STALL response receiv (STALL) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_STALL); + + /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is + * received on the channel. + */ + + stm32_chan_halt(priv, chidx, CHREASON_STALL); + } + + /* Check for a pending NAK response received (NAK) interrupt */ + + else if ((pending & OTGFS_HCINT_NAK) != 0) + { + /* Halt the channel -- the CHH interrrupt is expected next */ + + stm32_chan_halt(priv, chidx, CHREASON_NAK); + + /* Clear the pending the NAK response received (NAK) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_NAK); + } + + /* Check for a pending Transaction ERror (TXERR) interrupt */ + + else if ((pending & OTGFS_HCINT_TXERR) != 0) + { + /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is + * received on the channel. + */ + + stm32_chan_halt(priv, chidx, CHREASON_TXERR); + + /* Clear the pending the Transaction ERror (TXERR) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_TXERR); + } + + /* Check for a NYET interrupt */ + +#if 0 /* NYET is a reserved bit in the HCINT register */ + else if ((pending & OTGFS_HCINT_NYET) != 0) + { + /* Halt the channel */ + + stm32_chan_halt(priv, chidx, CHREASON_NYET); + + /* Clear the pending the NYET interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_NYET); + } +#endif + + /* Check for a pending Data Toggle ERRor (DTERR) interrupt */ + + else if (pending & OTGFS_HCINT_DTERR) + { + /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is + * received on the channel. + */ + + stm32_chan_halt(priv, chidx, CHREASON_DTERR); + + /* Clear the pending the Data Toggle ERRor (DTERR) and NAK interrupts */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), (OTGFS_HCINT_DTERR | OTGFS_HCINT_NAK)); + } + + /* Check for a pending CHannel Halted (CHH) interrupt */ + + else if ((pending & OTGFS_HCINT_CHH) != 0) + { + /* Mask the CHannel Halted (CHH) interrupt */ + + regval = stm32_getreg(STM32_OTGFS_HCINTMSK(chidx)); + regval &= ~OTGFS_HCINT_CHH; + stm32_putreg(STM32_OTGFS_HCINTMSK(chidx), regval); + + if (chan->chreason == CHREASON_XFRC) + { + /* Set the request done result */ + + chan->result = OK; + + /* Read the HCCHAR register to get the HCCHAR register to get + * the endpoint type. + */ + + regval = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + + /* Is it a bulk endpoint? Were an odd number of packets + * transferred? + */ + + if ((regval & OTGFS_HCCHAR_EPTYP_MASK) == OTGFS_HCCHAR_EPTYP_BULK && + (chan->npackets & 1) != 0) + { + /* Yes to both... toggle the data out PID */ + + chan->outdata1 ^= true; + } + } + else if (chan->chreason == CHREASON_NAK || + chan->chreason == CHREASON_NYET) + { + /* Set the try again later result */ + + chan->result = EAGAIN; + } + else if (chan->chreason == CHREASON_STALL) + { + /* Set the request stall result */ + + chan->result = EPERM; + } + else if ((chan->chreason == CHREASON_TXERR) || + (chan->chreason == CHREASON_DTERR)) + { + /* Set the I/O failure result */ + + chan->result = EIO; + } + else /* if (chan->chreason == CHREASON_FRMOR) */ + { + /* Set the frame error result */ + + chan->result = EPIPE; + } + + /* Clear the pending the CHannel Halted (CHH) interrupt */ + + stm32_putreg(STM32_OTGFS_HCINT(chidx), OTGFS_HCINT_CHH); + } + + /* Check for a transfer complete event */ + + stm32_chan_wakeup(priv, chan); +} + +/******************************************************************************* + * Name: stm32_gint_connected + * + * Description: + * Handle a connection event. + * + *******************************************************************************/ + +static void stm32_gint_connected(FAR struct stm32_usbhost_s *priv) +{ + /* We we previously disconnected? */ + + if (!priv->connected) + { + /* Yes.. then now we are connected */ + + ullvdbg("Connected\n"); + priv->connected = true; + DEBUGASSERT(priv->smstate == SMSTATE_DETACHED); + + /* Notify any waiters */ + + priv->smstate = SMSTATE_ATTACHED; + if (priv->eventwait) + { + stm32_givesem(&priv->eventsem); + priv->eventwait = false; + } + } +} + +/******************************************************************************* + * Name: stm32_gint_disconnected + * + * Description: + * Handle a disconnection event. + * + *******************************************************************************/ + +static void stm32_gint_disconnected(FAR struct stm32_usbhost_s *priv) +{ + /* Were we previously connected? */ + + if (!priv->connected) + { + /* Yes.. then we no longer connected */ + + ullvdbg("Disconnected\n"); + + /* Are we bound to a class driver? */ + + if (priv->class) + { + /* Yes.. Disconnect the class driver */ + + CLASS_DISCONNECTED(priv->class); + priv->class = NULL; + } + + /* Re-Initilaize Host for new Enumeration */ + + priv->smstate = SMSTATE_DETACHED; + priv->ep0size = STM32_EP0_MAX_PACKET_SIZE; + priv->devaddr = STM32_DEF_DEVADDR; + priv->connected = false; + priv->lowspeed = false; + stm32_chan_freeall(priv); + + /* Notify any waiters that there is a change in the connection state */ + + if (priv->eventwait) + { + stm32_givesem(&priv->eventsem); + priv->eventwait = false; + } + } +} + +/******************************************************************************* + * Name: stm32_gint_sofisr + * + * Description: + * USB OTG FS start-of-frame interrupt handler + * + *******************************************************************************/ + +#ifdef CONFIG_STM32_OTGFS_SOFINTR +static inline void stm32_gint_sofisr(FAR struct stm32_usbhost_s *priv) +{ + /* Handle SOF interrupt */ +#warning "Do what?" + + /* Clear pending SOF interrupt */ + + stm32_putreg(STM32_OTGFS_GINTSTS, OTGFS_GINT_SOF); +} +#endif + +/******************************************************************************* + * Name: stm32_gint_rxflvlisr + * + * Description: + * USB OTG FS RxFIFO non-empty interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv) +{ + FAR uint32_t *dest; + uint32_t grxsts; + uint32_t intmsk; + uint32_t hcchar; + uint32_t hctsiz; + uint32_t fifo; + int bcnt; + int bcnt32; + int chidx; + int i; + + /* Disable the RxFIFO non-empty interrupt */ + + intmsk = stm32_getreg(STM32_OTGFS_GINTMSK); + intmsk &= ~OTGFS_GINT_RXFLVL; + stm32_putreg(STM32_OTGFS_GINTMSK, intmsk); + + /* Read and pop the next status from the Rx FIFO */ + + grxsts = stm32_getreg(STM32_OTGFS_GRXSTSP); + ullvdbg("GRXSTS: %08x\n", grxsts); + + /* Isolate the channel number/index in the status word */ + + chidx = (grxsts & OTGFS_GRXSTSH_CHNUM_MASK) >> OTGFS_GRXSTSH_CHNUM_SHIFT; + + /* Get the host channel characteristics register (HCCHAR) for this channel */ + + hcchar = stm32_getreg(STM32_OTGFS_HCCHAR(chidx)); + + /* Then process the interrupt according to the packet status */ + + switch (grxsts & OTGFS_GRXSTSH_PKTSTS_MASK) + { + case OTGFS_GRXSTSH_PKTSTS_INRECVD: /* IN data packet received */ + { + /* Read the data into the host buffer. */ + + bcnt = (grxsts & OTGFS_GRXSTSH_BCNT_MASK) >> OTGFS_GRXSTSH_BCNT_SHIFT; + if (bcnt > 0 && priv->chan[chidx].buffer != NULL) + { + /* Transfer the packet from the Rx FIFO into the user buffer */ + + dest = (FAR uint32_t *)priv->chan[chidx].buffer; + fifo = STM32_OTGFS_DFIFO_HCH(0); + bcnt32 = (bcnt + 3) >> 2; + + for (i = 0; i < bcnt32; i++) + { + *dest++ = stm32_getreg(fifo); + } + + stm32_pktdump("Received", priv->chan[chidx].buffer, bcnt); + + /* Toggle the IN data pid (Used by Bulk and INTR only) */ + + priv->chan[chidx].indata1 ^= true; + + /* Manage multiple packet transfers */ + + priv->chan[chidx].buffer += bcnt; + priv->chan[chidx].buflen -= bcnt; + + /* Check if more packets are expected */ + + hctsiz = stm32_getreg(STM32_OTGFS_HCTSIZ(chidx)); + if ((hctsiz & OTGFS_HCTSIZ_PKTCNT_MASK) != 0) + { + /* Re-activate the channel when more packets are expected */ + + hcchar |= OTGFS_HCCHAR_CHENA; + hcchar &= ~OTGFS_HCCHAR_CHDIS; + stm32_putreg(STM32_OTGFS_HCCHAR(chidx), hcchar); + } + } + } + break; + + case OTGFS_GRXSTSH_PKTSTS_INDONE: /* IN transfer completed */ + case OTGFS_GRXSTSH_PKTSTS_DTOGERR: /* Data toggle error */ + case OTGFS_GRXSTSH_PKTSTS_HALTED: /* Channel halted */ + default: + break; + } + + /* Re-enable the RxFIFO non-empty interrupt */ + + intmsk |= OTGFS_GINT_RXFLVL; + stm32_putreg(STM32_OTGFS_GINTMSK, intmsk); +} + +/******************************************************************************* + * Name: stm32_gint_nptxfeisr + * + * Description: + * USB OTG FS non-periodic TxFIFO empty interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_nptxfeisr(FAR struct stm32_usbhost_s *priv) +{ + FAR struct stm32_chan_s *chan; + uint32_t regval; + unsigned int wrsize; + unsigned int minsize; + unsigned int avail; + unsigned int chidx; + + /* Recover the index of the channel that is waiting for space in the Tx + * FIFO. + */ + + chidx = priv->chidx; + chan = &priv->chan[chidx]; + + /* Reduce the buffer size by the number of bytes that were previously placed + * in the Tx FIFO. + */ + + chan->buffer += chan->inflight; + chan->buflen -= chan->inflight; + chan->inflight = 0; + + /* If we have now transfered the entire buffer, then this transfer is + * complete (this case really should never happen because we disable + * the NPTXFE interrupt on the final packet). + */ + + if (chan->buflen <= 0) + { + /* Disable further Tx FIFO empty interrupts and bail. */ + + stm32_modifyreg(STM32_OTGFS_GINTMSK, OTGFS_GINT_NPTXFE, 0); + return; + } + + /* Read the status from the top of the non-periodic TxFIFO */ + + regval = stm32_getreg(STM32_OTGFS_HNPTXSTS); + + /* Extract the number of bytes available in the non-periodic Tx FIFO. */ + + avail = ((regval & OTGFS_HNPTXSTS_NPTXFSAV_MASK) >> OTGFS_HNPTXSTS_NPTXFSAV_SHIFT) << 2; + + /* Get minimal size packet that can be sent. Something is serioulsy + * configured wrong if one packet will not fit into the empty Tx FIFO. + */ + + minsize = MIN(chan->buflen, chan->maxpacket); + DEBUGASSERT(chan->buflen > 0 && avail >= minsize); + + /* Get the size to put in the Tx FIFO now */ + + wrsize = chan->buflen; + if (wrsize > avail) + { + /* Clip the write size to the number of full, max sized packets + * that will fit in the Tx FIFO. + */ + + unsigned int wrpackets = avail / chan->maxpacket; + wrsize = wrpackets * chan->maxpacket; + } + + /* Otherwise, this will be the last packet to be sent in this transaction. + * We now need to disable further NPTXFE interrupts. + */ + + else + { + stm32_modifyreg(STM32_OTGFS_GINTMSK, OTGFS_GINT_NPTXFE, 0); + } + + /* Write the next group of packets into the Tx FIFO */ + + ullvdbg("HNPTXSTS: %08x chidx: %d avail: %d buflen: %d wrsize: %d\n", + regval, chidx, avail, chan->buflen, wrsize); + + stm32_gint_wrpacket(priv, chan->buffer, chidx, wrsize); +} + +/******************************************************************************* + * Name: stm32_gint_ptxfeisr + * + * Description: + * USB OTG FS periodic TxFIFO empty interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_ptxfeisr(FAR struct stm32_usbhost_s *priv) +{ + FAR struct stm32_chan_s *chan; + uint32_t regval; + unsigned int wrsize; + unsigned int minsize; + unsigned int avail; + unsigned int chidx; + + /* Recover the index of the channel that is waiting for space in the Tx + * FIFO. + */ + + chidx = priv->chidx; + chan = &priv->chan[chidx]; + + /* Reduce the buffer size by the number of bytes that were previously placed + * in the Tx FIFO. + */ + + chan->buffer += chan->inflight; + chan->buflen -= chan->inflight; + chan->inflight = 0; + + /* If we have now transfered the entire buffer, then this transfer is + * complete (this case really should never happen because we disable + * the PTXFE interrupt on the final packet). + */ + + if (chan->buflen <= 0) + { + /* Disable further Tx FIFO empty interrupts and bail. */ + + stm32_modifyreg(STM32_OTGFS_GINTMSK, OTGFS_GINT_PTXFE, 0); + return; + } + + /* Read the status from the top of the periodic TxFIFO */ + + regval = stm32_getreg(STM32_OTGFS_HPTXSTS); + + /* Extract the number of bytes available in the periodic Tx FIFO. */ + + avail = ((regval & OTGFS_HPTXSTS_PTXFSAVL_MASK) >> OTGFS_HPTXSTS_PTXFSAVL_SHIFT) << 2; + + /* Get minimal size packet that can be sent. Something is serioulsy + * configured wrong if one packet will not fit into the empty Tx FIFO. + */ + + minsize = MIN(chan->buflen, chan->maxpacket); + DEBUGASSERT(chan->buflen > 0 && avail >= minsize); + + /* Get the size to put in the Tx FIFO now */ + + wrsize = chan->buflen; + if (wrsize > avail) + { + /* Clip the write size to the number of full, max sized packets + * that will fit in the Tx FIFO. + */ + + unsigned int wrpackets = avail / chan->maxpacket; + wrsize = wrpackets * chan->maxpacket; + } + + /* Otherwise, this will be the last packet to be sent in this transaction. + * We now need to disable further PTXFE interrupts. + */ + + else + { + stm32_modifyreg(STM32_OTGFS_GINTMSK, OTGFS_GINT_PTXFE, 0); + } + + /* Write the next group of packets into the Tx FIFO */ + + ullvdbg("HPTXSTS: %08x chidx: %d avail: %d buflen: %d wrsize: %d\n", + regval, chidx, avail, chan->buflen, wrsize); + + stm32_gint_wrpacket(priv, chan->buffer, chidx, wrsize); +} + +/******************************************************************************* + * Name: stm32_gint_hcisr + * + * Description: + * USB OTG FS host channels interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_hcisr(FAR struct stm32_usbhost_s *priv) +{ + uint32_t haint; + uint32_t hcchar; + int i = 0; + + /* Read the Host all channels interrupt register and test each bit in the + * register. Each bit i, i=0...(STM32_NHOST_CHANNELS-1), corresponds to + * a pending interrupt on channel i. + */ + + haint = stm32_getreg(STM32_OTGFS_HAINT); + for (i = 0; i < STM32_NHOST_CHANNELS; i++) + { + /* Is an interrupt pending on this channel? */ + + if ((haint & OTGFS_HAINT(i)) != 0) + { + /* Yes... read the HCCHAR register to get the direction bit */ + + hcchar = stm32_getreg(STM32_OTGFS_HCCHAR(i)); + + /* Was this an interrupt on an IN or an OUT channel? */ + + if ((hcchar & OTGFS_HCCHAR_EPDIR) != 0) + { + /* Handle the HC IN channel interrupt */ + + stm32_gint_hcinisr(priv, i); + } + else + { + /* Handle the HC OUT channel interrupt */ + + stm32_gint_hcoutisr(priv, i); + } + } + } +} + +/******************************************************************************* + * Name: stm32_gint_hprtisr + * + * Description: + * USB OTG FS host port interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_hprtisr(FAR struct stm32_usbhost_s *priv) +{ + uint32_t hprt; + uint32_t newhprt; + uint32_t hcfg; + + /* Read the port status and control register (HPRT) */ + + hprt = stm32_getreg(STM32_OTGFS_HPRT); + + /* Setup to clear the interrupt bits in GINTSTS by setting the corresponding + * bits in the HPRT. The HCINT interrupt bit is cleared when the appropriate + * status bits in the HPRT register are cleared. + */ + + newhprt = hprt & ~(OTGFS_HPRT_PENA | OTGFS_HPRT_PCDET | + OTGFS_HPRT_PENCHNG | OTGFS_HPRT_POCCHNG); + + /* Check for Port Overcurrent CHaNGe (POCCHNG) */ + + if ((hprt & OTGFS_HPRT_POCCHNG) != 0) + { + /* Set up to clear the POCCHNG status in the new HPRT contents. */ + + newhprt |= OTGFS_HPRT_POCCHNG; + } + + /* Check for Port Connect DETected (PCDET). The core sets this bit when a + * device connection is detected. + */ + + if ((hprt & OTGFS_HPRT_PCDET) != 0) + { + /* Set up to clear the PCDET status in the new HPRT contents. Then + * process the new connection event. + */ + + newhprt |= OTGFS_HPRT_PCDET; + stm32_gint_connected(priv); + } + + /* Check for Port Enable CHaNGed (PENCHNG) */ + + if ((hprt & OTGFS_HPRT_PENCHNG) != 0) + { + /* Set up to clear the PENCHNG status in the new HPRT contents. */ + + newhprt |= OTGFS_HPRT_PENCHNG; + + /* Was the port enabled? */ + + if ((hprt & OTGFS_HPRT_PENA) != 0) + { + /* Yes.. handle the new connection event */ + + stm32_gint_connected(priv); + + /* Check the Host ConFiGuration register (HCFG) */ + + hcfg = stm32_getreg(STM32_OTGFS_HCFG); + + /* Is this a low speed or full speed connection (OTG FS does not + * support high speed) + */ + + if ((hprt & OTGFS_HPRT_PSPD_MASK) == OTGFS_HPRT_PSPD_LS) + { + /* Set the Host Frame Interval Register for the 6KHz speed */ + + stm32_putreg(STM32_OTGFS_HFIR, 6000); + + /* Are we switching from FS to LS? */ + + if ((hcfg & OTGFS_HCFG_FSLSPCS_MASK) != OTGFS_HCFG_FSLSPCS_LS6MHz) + { + /* Yes... configure for LS */ + + hcfg &= ~OTGFS_HCFG_FSLSPCS_MASK; + hcfg |= OTGFS_HCFG_FSLSPCS_LS6MHz; + stm32_putreg(STM32_OTGFS_HCFG, hcfg); + + /* And reset the port */ + + stm32_portreset(priv); + } + } + else /* if ((hprt & OTGFS_HPRT_PSPD_MASK) == OTGFS_HPRT_PSPD_FS) */ + { + stm32_putreg(STM32_OTGFS_HFIR, 48000); + + /* Are we switching from LS to FS? */ + + if ((hcfg & OTGFS_HCFG_FSLSPCS_MASK) != OTGFS_HCFG_FSLSPCS_FS48MHz) + { + /* Yes... configure for FS */ + + hcfg &= ~OTGFS_HCFG_FSLSPCS_MASK; + hcfg |= OTGFS_HCFG_FSLSPCS_FS48MHz; + stm32_putreg(STM32_OTGFS_HCFG, hcfg); + + /* And reset the port */ + + stm32_portreset(priv); + } + } + } + } + + /* Clear port interrupts by setting bits in the HPRT */ + + stm32_putreg(STM32_OTGFS_HPRT, newhprt); +} + +/******************************************************************************* + * Name: stm32_gint_discisr + * + * Description: + * USB OTG FS disconnect detected interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_discisr(FAR struct stm32_usbhost_s *priv) +{ + /* Handle the disconnection event */ + + stm32_gint_disconnected(priv); + + /* Clear the dicsonnect interrupt */ + + stm32_putreg(STM32_OTGFS_GINTSTS, OTGFS_GINT_DISC); +} + +/******************************************************************************* + * Name: stm32_gint_iisooxfrisr + * + * Description: + * USB OTG FS incomplete isochronous interrupt handler + * + *******************************************************************************/ + +static inline void stm32_gint_iisooxfrisr(FAR struct stm32_usbhost_s *priv) +{ + uint32_t regval; + + /* CHENA : Set to enable the channel + * CHDIS : Set to stop transmitting/receiving data on a channel + */ + + regval = stm32_getreg(STM32_OTGFS_HCCHAR(0)); + regval |= (OTGFS_HCCHAR_CHDIS | OTGFS_HCCHAR_CHENA); + stm32_putreg(STM32_OTGFS_HCCHAR(0), regval); + + /* Clear the incomplete isochronous OUT interrupt */ + + stm32_putreg(STM32_OTGFS_GINTSTS, OTGFS_GINT_IISOOXFR); +} + +/******************************************************************************* + * Name: stm32_gint_isr + * + * Description: + * USB OTG FS global interrupt handler + * + *******************************************************************************/ + +static int stm32_gint_isr(int irq, FAR void *context) +{ + /* At present, there is only support for a single OTG FS host. Hence it is + * pre-allocated as g_usbhost. However, in most code, the private data + * structure will be referenced using the 'priv' pointer (rather than the + * global data) in order to simplify any future support for multiple devices. + */ + + FAR struct stm32_usbhost_s *priv = &g_usbhost; + uint32_t pending; + + /* If OTG were supported, we would need to check if we are in host or + * device mode when the global interrupt occurs. Here we support only + * host mode + */ + + /* Loop while there are pending interrupts to process. This loop may save a + * little interrupt handling overhead. + */ + + for (;;) + { + /* Get the unmasked bits in the GINT status */ + + pending = stm32_getreg(STM32_OTGFS_GINTSTS); + pending &= stm32_getreg(STM32_OTGFS_GINTMSK); + + /* Return from the interrupt when there are no furhter pending + * interrupts. + */ + + if (pending == 0) + { + return OK; + } + + /* Otherwise, process each pending, unmasked GINT interrupts */ + + ullvdbg("GINTSTS: %08x\n", pending); + + /* Handle the start of frame interrupt */ + +#ifdef CONFIG_STM32_OTGFS_SOFINTR + if ((pending & OTGFS_GINT_SOF) != 0) + { + stm32_gint_sofisr(priv); + } +#endif + + /* Handle the RxFIFO non-empty interrupt */ + + if ((pending & OTGFS_GINT_RXFLVL) != 0) + { + stm32_gint_rxflvlisr(priv); + } + + /* Handle the non-periodic TxFIFO empty interrupt */ + + if ((pending & OTGFS_GINT_NPTXFE) != 0) + { + stm32_gint_nptxfeisr(priv); + } + + /* Handle the periodic TxFIFO empty interrupt */ + + if ((pending & OTGFS_GINT_PTXFE) != 0) + { + stm32_gint_ptxfeisr(priv); + } + + /* Handle the host channels interrupt */ + + if ((pending & OTGFS_GINT_HC) != 0) + { + stm32_gint_hcisr(priv); + } + + /* Handle the host port interrupt */ + + if ((pending & OTGFS_GINT_HPRT) != 0) + { + stm32_gint_hprtisr(priv); + } + + /* Handle the disconnect detected interrupt */ + + if ((pending & OTGFS_GINT_DISC) != 0) + { + stm32_gint_discisr(priv); + } + + /* Handle the incomplete isochronous OUT transfer */ + + if ((pending & OTGFS_GINT_IISOOXFR) != 0) + { + stm32_gint_iisooxfrisr(priv); + } + } + + /* We won't get here */ + + return OK; +} + +/******************************************************************************* + * Name: stm32_gint_enable and stm32_gint_disable + * + * Description: + * Respectively enable or disable the global OTG FS interrupt. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + *******************************************************************************/ + +static void stm32_gint_enable(void) +{ + uint32_t regval; + + /* Set the GINTMSK bit to unmask the interrupt */ + + regval = stm32_getreg(STM32_OTGFS_GAHBCFG); + regval |= OTGFS_GAHBCFG_GINTMSK; + stm32_putreg(STM32_OTGFS_GAHBCFG, regval); +} + +static void stm32_gint_disable(void) +{ + uint32_t regval; + + /* Clear the GINTMSK bit to mask the interrupt */ + + regval = stm32_getreg(STM32_OTGFS_GAHBCFG); + regval &= ~OTGFS_GAHBCFG_GINTMSK; + stm32_putreg(STM32_OTGFS_GAHBCFG, regval); +} + +/******************************************************************************* + * Name: stm32_hostinit_enable + * + * Description: + * Enable host interrupts. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + *******************************************************************************/ + +static inline void stm32_hostinit_enable(void) +{ + uint32_t regval; + + /* Disable all interrupts. */ + + stm32_putreg(STM32_OTGFS_GINTMSK, 0); + + /* Clear any pending interrupts. */ + + stm32_putreg(STM32_OTGFS_GINTSTS, 0xffffffff); + + /* Clear any pending USB OTG Interrupts (should be done elsewhere if OTG is supported) */ + + stm32_putreg(STM32_OTGFS_GOTGINT, 0xffffffff); + + /* Clear any pending USB OTG interrupts */ + + stm32_putreg(STM32_OTGFS_GINTSTS, 0xbfffffff); + + /* Enable the host interrupts */ + /* Common interrupts: + * + * OTGFS_GINT_WKUP : Resume/remote wakeup detected interrupt + * OTGFS_GINT_USBSUSP : USB suspend + */ + + regval = (OTGFS_GINT_WKUP | OTGFS_GINT_USBSUSP); + + /* If OTG were supported, we would need to enable the following as well: + * + * OTGFS_GINT_OTG : OTG interrupt + * OTGFS_GINT_SRQ : Session request/new session detected interrupt + * OTGFS_GINT_CIDSCHG : Connector ID status change + */ + + /* Host-specific interrupts + * + * OTGFS_GINT_SOF : Start of frame + * OTGFS_GINT_RXFLVL : RxFIFO non-empty + * OTGFS_GINT_IISOOXFR : Incomplete isochronous OUT transfer + * OTGFS_GINT_HPRT : Host port interrupt + * OTGFS_GINT_HC : Host channels interrupt + * OTGFS_GINT_DISC : Disconnect detected interrupt + */ + +#ifdef CONFIG_STM32_OTGFS_SOFINTR + regval |= (OTGFS_GINT_SOF | OTGFS_GINT_RXFLVL | OTGFS_GINT_IISOOXFR | + OTGFS_GINT_HPRT | OTGFS_GINT_HC | OTGFS_GINT_DISC); +#else + regval |= (OTGFS_GINT_RXFLVL | OTGFS_GINT_IISOOXFR | OTGFS_GINT_HPRT | + OTGFS_GINT_HC | OTGFS_GINT_DISC); +#endif + stm32_putreg(STM32_OTGFS_GINTMSK, regval); +} + +/******************************************************************************* + * Name: stm32_txfe_enable + * + * Description: + * Enable Tx FIFO empty interrupts. This is necessary when the entire + * transfer will not fit into Tx FIFO. The transfer will then be completed + * when the Tx FIFO is empty. NOTE: The Tx FIFO interrupt is disabled + * the the fifo empty interrupt handler when the transfer is complete. + * + * Input Parameters: + * priv - Driver state structure reference + * chidx - The channel that requires the Tx FIFO empty interrupt + * + * Returned Value: + * None + * + * Assumptions: + * Called from user task context. Interrupts must be disabled to assure + * exclusive access to the GINTMSK register. + * + *******************************************************************************/ + +static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx) +{ + FAR struct stm32_chan_s *chan = &priv->chan[chidx]; + irqstate_t flags; + uint32_t regval; + + /* Disable all interrupts so that we have exclusive access to the GINTMSK + * (it would be sufficent just to disable the GINT interrupt). + */ + + flags = irqsave(); + + /* Should we enable the periodic or non-peridic Tx FIFO empty interrupts */ + + regval = stm32_getreg(STM32_OTGFS_GINTMSK); + switch (chan->eptype) + { + default: + case OTGFS_EPTYPE_CTRL: /* Non periodic transfer */ + case OTGFS_EPTYPE_BULK: + regval |= OTGFS_GINT_NPTXFE; + break; + + case OTGFS_EPTYPE_INTR: /* Periodic transfer */ + case OTGFS_EPTYPE_ISOC: + regval |= OTGFS_GINT_PTXFE; + break; + } + + /* Enable interrupts */ + + stm32_putreg(STM32_OTGFS_GINTMSK, regval); + irqrestore(flags); +} + +/******************************************************************************* + * USB Host Controller Operations + *******************************************************************************/ + +/******************************************************************************* + * Name: stm32_wait + * + * Description: + * Wait for a device to be connected or disconneced. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * connected - TRUE: Wait for device to be connected; FALSE: wait for device + * to be disconnected + * + * Returned Values: + * Zero (OK) is returned when a device in connected. This function will not + * return until either (1) a device is connected or (2) some failure occurs. + * On a failure, a negated errno value is returned indicating the nature of + * the failure + * + * Assumptions: + * - Called from a single thread so no mutual exclusion is required. + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static int stm32_wait(FAR struct usbhost_driver_s *drvr, bool connected) +{ + FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr; + irqstate_t flags; + + /* Are we already connected? */ + + flags = irqsave(); + while (priv->connected == connected) + { + /* No... wait for the connection/disconnection */ + + priv->eventwait = true; + stm32_takesem(&priv->eventsem); + } + + irqrestore(flags); + + udbg("Connected:%s\n", priv->connected ? "YES" : "NO"); + return OK; +} + +/******************************************************************************* + * Name: stm32_enumerate + * + * Description: + * Enumerate the connected device. As part of this enumeration process, + * the driver will (1) get the device's configuration descriptor, (2) + * extract the class ID info from the configuration descriptor, (3) call + * usbhost_findclass() to find the class that supports this device, (4) + * call the create() method on the struct usbhost_registry_s interface + * to get a class instance, and finally (5) call the configdesc() method + * of the struct usbhost_class_s interface. After that, the class is in + * charge of the sequence of operations. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * - Only a single class bound to a single device is supported. + * - Called from a single thread so no mutual exclusion is required. + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static int stm32_enumerate(FAR struct usbhost_driver_s *drvr) +{ + struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; + uint32_t regval; + int chidx; + int ret; + + /* Are we connected to a device? The caller should have called the wait() + * method first to be assured that a device is connected. + */ + + while (!priv->connected) + { + /* No, return an error */ + + udbg("Not connected\n"); + return -ENODEV; + } + + DEBUGASSERT(priv->smstate == SMSTATE_ATTACHED); + + /* Allocate and initialize the control OUT channel */ + + chidx = stm32_chan_alloc(priv); + DEBUGASSERT(chidx >= 0); + + priv->ep0out = chidx; + priv->chan[chidx].epno = 0; + priv->chan[chidx].in = false; + priv->chan[chidx].eptype = OTGFS_EPTYPE_CTRL; + priv->chan[chidx].maxpacket = STM32_EP0_DEF_PACKET_SIZE; + priv->chan[chidx].indata1 = false; + priv->chan[chidx].outdata1 = false; + + /* Allocate and initialize the control IN channel */ + + chidx = stm32_chan_alloc(priv); + DEBUGASSERT(chidx >= 0); + + priv->ep0in = chidx; + priv->chan[chidx].epno = 0; + priv->chan[chidx].in = true; + priv->chan[chidx].eptype = OTGFS_EPTYPE_CTRL; + priv->chan[chidx].maxpacket = STM32_EP0_DEF_PACKET_SIZE; + priv->chan[chidx].indata1 = false; + priv->chan[chidx].outdata1 = false; + + /* USB 2.0 spec says at least 50ms delay before port reset. We wait 100ms. */ + + usleep(100*1000); + + /* Reset the host port */ + + stm32_portreset(priv); + + /* Get the current device speed */ + + regval = stm32_getreg(STM32_OTGFS_HPRT); + priv->lowspeed = ((regval & OTGFS_HPRT_PSPD_MASK) == OTGFS_HPRT_PSPD_LS); + + /* Configure control channels */ + + stm32_chan_configure(priv, priv->ep0out) ; + stm32_chan_configure(priv, priv->ep0in) ; + + /* Let the common usbhost_enumerate do all of the real work. Note that the + * FunctionAddress (USB address) is hardcoded to one. + */ + + uvdbg("Enumerate the device\n"); + priv->smstate = SMSTATE_ENUM; + ret = usbhost_enumerate(drvr, 1, &priv->class); + + /* The enumeration may fail either because of some HCD interfaces failure + * or because the device class is not supported. In either case, we just + * need to perform the disconnection operation and make ready for a new + * enumeration. + */ + + if (ret < 0) + { + /* Return to the disconnected state */ + + stm32_gint_disconnected(priv); + } + + return ret; +} + +/************************************************************************************ + * Name: stm32_ep0configure + * + * Description: + * Configure endpoint 0. This method is normally used internally by the + * enumerate() method but is made available at the interface to support an + * external implementation of the enumeration logic. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * funcaddr - The USB address of the function containing the endpoint that EP0 + * controls + * maxpacketsize - The maximum number of bytes that can be sent to or + * received from the endpoint in a single data packet + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * This function will *not* be called from an interrupt handler. + * + ************************************************************************************/ + +static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, + uint16_t maxpacketsize) +{ + FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr; + + DEBUGASSERT(drvr && funcaddr < 128 && maxpacketsize < 2048); + + /* We must have exclusive access to the USB host hardware and state structures */ + + stm32_takesem(&priv->exclsem); + + /* Save the device address and EP0 max packet size */ + + priv->devaddr = funcaddr; + priv->ep0size = maxpacketsize; + + /* Configure the EP0 OUT channel */ + + priv->chan[priv->ep0out].maxpacket = maxpacketsize; + stm32_chan_configure(priv, priv->ep0out); + + /* Configure the EP0 IN channel */ + + priv->chan[priv->ep0in].maxpacket = maxpacketsize; + stm32_chan_configure(priv, priv->ep0in); + + stm32_givesem(&priv->exclsem); + return OK; +} + +/************************************************************************************ + * Name: stm32_epalloc + * + * Description: + * Allocate and configure one endpoint. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * epdesc - Describes the endpoint to be allocated. + * ep - A memory location provided by the caller in which to receive the + * allocated endpoint desciptor. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * This function will *not* be called from an interrupt handler. + * + ************************************************************************************/ + +static int stm32_epalloc(FAR struct usbhost_driver_s *drvr, + FAR const struct usbhost_epdesc_s *epdesc, + FAR usbhost_ep_t *ep) +{ + FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr; + FAR struct stm32_chan_s *chan; + int chidx; + int ret; + + /* Sanity check. NOTE that this method should only be called if a device is + * connected (because we need a valid low speed indication). + */ + + DEBUGASSERT(priv && epdesc && ep && priv->connected); + + /* We must have exclusive access to the USB host hardware and state structures */ + + stm32_takesem(&priv->exclsem); + + /* Allocate a host channel for the endpoint */ + + chidx = stm32_chan_alloc(priv); + if (chidx < 0) + { + udbg("Failed to allocate a host channel\n"); + ret = -ENOMEM; + goto errout; + } + + /* Decode the endpoint descriptor to initialize the channel data structures. + * Note: Here we depend on the fact that the endpoint point type is + * encoded in the same way in the endpoint descriptor as it is in the OTG + * FS hardware. + */ + + chan = &priv->chan[chidx]; + chan->epno = epdesc->addr & USB_EPNO_MASK; + chan->in = epdesc->in; + chan->eptype = epdesc->xfrtype; + chan->maxpacket = epdesc->mxpacketsize; + chan->indata1 = false; + chan->outdata1 = false; + + /* Then configure the endpoint */ + + stm32_chan_configure(priv, chidx) ; + + /* Return the index to the allocated channel as the endpoint "handle" */ + + *ep = (usbhost_ep_t)chidx; + ret = OK; + +errout: + stm32_givesem(&priv->exclsem); + return ret; +} + +/************************************************************************************ + * Name: stm32_epfree + * + * Description: + * Free and endpoint previously allocated by DRVR_EPALLOC. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * ep - The endpint to be freed. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * This function will *not* be called from an interrupt handler. + * + ************************************************************************************/ + +static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep) +{ + struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; + int chidx = (int)ep; + + DEBUGASSERT(priv && chidx < STM32_MAX_TX_FIFOS); + + /* We must have exclusive access to the USB host hardware and state structures */ + + stm32_takesem(&priv->exclsem); + + /* Halt the channel and mark the channel avaiable */ + + stm32_chan_free(priv, chidx); + + stm32_givesem(&priv->exclsem); + return OK; +} + +/******************************************************************************* + * Name: stm32_alloc + * + * Description: + * Some hardware supports special memory in which request and descriptor data can + * be accessed more efficiently. This method provides a mechanism to allocate + * the request/descriptor memory. If the underlying hardware does not support + * such "special" memory, this functions may simply map to kmalloc. + * + * This interface was optimized under a particular assumption. It was assumed + * that the driver maintains a pool of small, pre-allocated buffers for descriptor + * traffic. NOTE that size is not an input, but an output: The size of the + * pre-allocated buffer is returned. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * buffer - The address of a memory location provided by the caller in which to + * return the allocated buffer memory address. + * maxlen - The address of a memory location provided by the caller in which to + * return the maximum size of the allocated buffer memory. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * - Called from a single thread so no mutual exclusion is required. + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static int stm32_alloc(FAR struct usbhost_driver_s *drvr, + FAR uint8_t **buffer, FAR size_t *maxlen) +{ + FAR uint8_t *alloc; + + DEBUGASSERT(drvr && buffer && maxlen); + + /* There is no special memory requirement for the STM32. */ + + alloc = (FAR uint8_t *)kmalloc(CONFIG_STM32_OTGFS_DESCSIZE); + if (!alloc) + { + return -ENOMEM; + } + + /* Return the allocated address and size of the descriptor buffer */ + + *buffer = alloc; + *maxlen = CONFIG_STM32_OTGFS_DESCSIZE; + return OK; +} + +/******************************************************************************* + * Name: stm32_free + * + * Description: + * Some hardware supports special memory in which request and descriptor data can + * be accessed more efficiently. This method provides a mechanism to free that + * request/descriptor memory. If the underlying hardware does not support + * such "special" memory, this functions may simply map to kfree(). + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * buffer - The address of the allocated buffer memory to be freed. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer) +{ + /* There is no special memory requirement */ + + DEBUGASSERT(drvr && buffer); + kfree(buffer); + return OK; +} + +/************************************************************************************ + * Name: stm32_ioalloc + * + * Description: + * Some hardware supports special memory in which larger IO buffers can + * be accessed more efficiently. This method provides a mechanism to allocate + * the request/descriptor memory. If the underlying hardware does not support + * such "special" memory, this functions may simply map to kmalloc. + * + * This interface differs from DRVR_ALLOC in that the buffers are variable-sized. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * buffer - The address of a memory location provided by the caller in which to + * return the allocated buffer memory address. + * buflen - The size of the buffer required. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * This function will *not* be called from an interrupt handler. + * + ************************************************************************************/ + +static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr, + FAR uint8_t **buffer, size_t buflen) +{ + FAR uint8_t *alloc; + + DEBUGASSERT(drvr && buffer && buflen > 0); + + /* There is no special memory requirement */ + + alloc = (FAR uint8_t *)kmalloc(buflen); + if (!alloc) + { + return -ENOMEM; + } + + /* Return the allocated buffer */ + + *buffer = alloc; + return OK; +} + +/************************************************************************************ + * Name: stm32_iofree + * + * Description: + * Some hardware supports special memory in which IO data can be accessed more + * efficiently. This method provides a mechanism to free that IO buffer + * memory. If the underlying hardware does not support such "special" memory, + * this functions may simply map to kfree(). + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * buffer - The address of the allocated buffer memory to be freed. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * This function will *not* be called from an interrupt handler. + * + ************************************************************************************/ + +static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer) +{ + /* There is no special memory requirement */ + + DEBUGASSERT(drvr && buffer); + kfree(buffer); + return OK; +} + +/******************************************************************************* + * Name: stm32_ctrlin and stm32_ctrlout + * + * Description: + * Process a IN or OUT request on the control endpoint. These methods + * will enqueue the request and wait for it to complete. Only one transfer may be + * queued; Neither these methods nor the transfer() method can be called again + * until the control transfer functions returns. + * + * These are blocking methods; these functions will not return until the + * control transfer has completed. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * req - Describes the request to be sent. This request must lie in memory + * created by DRVR_ALLOC. + * buffer - A buffer used for sending the request and for returning any + * responses. This buffer must be large enough to hold the length value + * in the request description. buffer must have been allocated using DRVR_ALLOC + * + * NOTE: On an IN transaction, req and buffer may refer to the same allocated + * memory. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure + * + * Assumptions: + * - Only a single class bound to a single device is supported. + * - Called from a single thread so no mutual exclusion is required. + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, + FAR const struct usb_ctrlreq_s *req, + FAR uint8_t *buffer) +{ + struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; + uint16_t buflen; + uint16_t start; + uint16_t elapsed; + int retries; + int ret; + + DEBUGASSERT(drvr && req); + uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n", + req->type, req->req, req->value[1], req->value[0], + req->index[1], req->index[0], req->len[1], req->len[0]); + + /* Extract values from the request */ + + buflen = stm32_getle16(req->len); + + /* We must have exclusive access to the USB host hardware and state structures */ + + stm32_takesem(&priv->exclsem); + + /* Loop, retrying until the retry time expires */ + + for (retries = 0; retries < STM32_RETRY_COUNT; retries++) + { + /* Send the SETUP request */ + + ret = stm32_ctrl_sendsetup(priv, req); + if (ret < 0) + { + udbg("stm32_ctrl_sendsetup failed: %d\n", ret); + continue; + } + + /* Get the start time. Loop again until the timeout expires */ + + start = stm32_getframe(); + do + { + /* Handle the IN data phase (if any) */ + + if (buflen > 0) + { + ret = stm32_ctrl_recvdata(priv, buffer, buflen); + if (ret < 0) + { + udbg("stm32_ctrl_recvdata failed: %d\n", ret); + } + } + + /* Handle the status OUT phase */ + + if (ret == OK) + { + priv->chan[priv->ep0out].outdata1 ^= true; + ret = stm32_ctrl_senddata(priv, NULL, 0); + if (ret == OK) + { + /* All success transactions exit here */ + + stm32_givesem(&priv->exclsem); + return OK; + } + + udbg("stm32_ctrl_senddata failed: %d\n", ret); + } + + /* Get the elapsed time (in frames) */ + + elapsed = stm32_getframe() - start; + } + while (elapsed < STM32_DATANAK_DELAY); + } + + /* All failures exit here after all retries and timeouts have been exhausted */ + + stm32_givesem(&priv->exclsem); + return -ETIMEDOUT; +} + +static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, + FAR const struct usb_ctrlreq_s *req, + FAR const uint8_t *buffer) +{ + struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; + uint16_t buflen; + uint16_t start; + uint16_t elapsed; + int retries; + int ret; + + DEBUGASSERT(drvr && req); + uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n", + req->type, req->req, req->value[1], req->value[0], + req->index[1], req->index[0], req->len[1], req->len[0]); + + /* Extract values from the request */ + + buflen = stm32_getle16(req->len); + + /* We must have exclusive access to the USB host hardware and state structures */ + + stm32_takesem(&priv->exclsem); + + /* Loop, retrying until the retry time expires */ + + for (retries = 0; retries < STM32_RETRY_COUNT; retries++) + { + /* Send the SETUP request */ + + /* Send the SETUP request */ + + ret = stm32_ctrl_sendsetup(priv, req); + if (ret < 0) + { + udbg("stm32_ctrl_sendsetup failed: %d\n", ret); + continue; + } + + /* Get the start time. Loop again until the timeout expires */ + + start = stm32_getframe(); + do + { + /* Handle the data OUT phase (if any) */ + + if (buflen > 0) + { + /* Start DATA out transfer (only one DATA packet) */ + + priv->chan[priv->ep0out].outdata1 = true; + ret = stm32_ctrl_senddata(priv, NULL, 0); + if (ret < 0) + { + udbg("stm32_ctrl_senddata failed: %d\n", ret); + } + } + + /* Handle the status IN phase */ + + if (ret == OK) + { + ret = stm32_ctrl_recvdata(priv, NULL, 0); + if (ret == OK) + { + /* All success transactins exit here */ + + stm32_givesem(&priv->exclsem); + return OK; + } + + udbg("stm32_ctrl_recvdata failed: %d\n", ret); + } + + /* Get the elapsed time (in frames) */ + + elapsed = stm32_getframe() - start; + } + while (elapsed < STM32_DATANAK_DELAY); + } + + /* All failures exit here after all retries and timeouts have been exhausted */ + + stm32_givesem(&priv->exclsem); + return -ETIMEDOUT; +} + +/******************************************************************************* + * Name: stm32_transfer + * + * Description: + * Process a request to handle a transfer descriptor. This method will + * enqueue the transfer request and return immediately. Only one transfer may be + * queued; Neither this method nor the ctrlin or ctrlout methods can be called + * again until this function returns. + * + * This is a blocking method; this functions will not return until the + * transfer has completed. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * ep - The IN or OUT endpoint descriptor for the device endpoint on which to + * perform the transfer. + * buffer - A buffer containing the data to be sent (OUT endpoint) or received + * (IN endpoint). buffer must have been allocated using DRVR_ALLOC + * buflen - The length of the data to be sent or received. + * + * Returned Values: + * On success, zero (OK) is returned. On a failure, a negated errno value is + * returned indicating the nature of the failure: + * + * EAGAIN - If devices NAKs the transfer (or NYET or other error where + * it may be appropriate to restart the entire transaction). + * EPERM - If the endpoint stalls + * EIO - On a TX or data toggle error + * EPIPE - Overrun errors + * + * Assumptions: + * - Only a single class bound to a single device is supported. + * - Called from a single thread so no mutual exclusion is required. + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static int stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep, + FAR uint8_t *buffer, size_t buflen) +{ + FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr; + unsigned int chidx = (unsigned int)ep; + int ret; + + uvdbg("chidx: %d buflen: %d\n", (unsigned int)ep, buflen); + + DEBUGASSERT(priv && buffer && chidx < STM32_MAX_TX_FIFOS && buflen > 0); + + /* We must have exclusive access to the USB host hardware and state structures */ + + stm32_takesem(&priv->exclsem); + + /* Handle IN and OUT transfer slightly differently */ + + if (priv->chan[chidx].in) + { + ret = stm32_in_transfer(priv, chidx, buffer, buflen); + } + else + { + ret = stm32_out_transfer(priv, chidx, buffer, buflen); + } + + stm32_givesem(&priv->exclsem); + return ret; +} + +/******************************************************************************* + * Name: stm32_disconnect + * + * Description: + * Called by the class when an error occurs and driver has been disconnected. + * The USB host driver should discard the handle to the class instance (it is + * stale) and not attempt any further interaction with the class driver instance + * (until a new instance is received from the create() method). The driver + * should not called the class' disconnected() method. + * + * Input Parameters: + * drvr - The USB host driver instance obtained as a parameter from the call to + * the class create() method. + * + * Returned Values: + * None + * + * Assumptions: + * - Only a single class bound to a single device is supported. + * - Never called from an interrupt handler. + * + *******************************************************************************/ + +static void stm32_disconnect(FAR struct usbhost_driver_s *drvr) +{ + struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; + priv->class = NULL; +} + +/******************************************************************************* + * Initialization + *******************************************************************************/ +/******************************************************************************* + * Name: stm32_portreset + * + * Description: + * Reset the USB host port. + * + * NOTE: "Before starting to drive a USB reset, the application waits for the + * OTG interrupt triggered by the debounce done bit (DBCDNE bit in + * OTG_FS_GOTGINT), which indicates that the bus is stable again after the + * electrical debounce caused by the attachment of a pull-up resistor on DP + * (FS) or DM (LS). + * + * Input Parameters: + * priv -- USB host driver private data structure. + * + * Returned Value: + * None + * + *******************************************************************************/ + +static void stm32_portreset(FAR struct stm32_usbhost_s *priv) +{ + uint32_t regval; + + regval = stm32_getreg(STM32_OTGFS_HPRT); + regval &= ~(OTGFS_HPRT_PENA|OTGFS_HPRT_PCDET|OTGFS_HPRT_PENCHNG|OTGFS_HPRT_POCCHNG); + regval |= OTGFS_HPRT_PRST; + stm32_putreg(STM32_OTGFS_HPRT, regval); + + up_mdelay(10); + + regval &= ~OTGFS_HPRT_PRST; + stm32_putreg(STM32_OTGFS_HPRT, regval); + + up_mdelay(20); +} + +/******************************************************************************* + * Name: stm32_flush_txfifos + * + * Description: + * Flush the selected Tx FIFO. + * + * Input Parameters: + * txfnum -- USB host driver private data structure. + * + * Returned Value: + * None. + * + *******************************************************************************/ + +static void stm32_flush_txfifos(uint32_t txfnum) +{ + uint32_t regval; + uint32_t timeout; + + /* Initiate the TX FIFO flush operation */ + + regval = OTGFS_GRSTCTL_TXFFLSH | txfnum; + stm32_putreg(regval, STM32_OTGFS_GRSTCTL); + + /* Wait for the FLUSH to complete */ + + for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++) + { + regval = stm32_getreg(STM32_OTGFS_GRSTCTL); + if ((regval & OTGFS_GRSTCTL_TXFFLSH) == 0) + { + break; + } + } + + /* Wait for 3 PHY Clocks */ + + up_udelay(3); +} + +/******************************************************************************* + * Name: stm32_flush_rxfifo + * + * Description: + * Flush the Rx FIFO. + * + * Input Parameters: + * priv -- USB host driver private data structure. + * + * Returned Value: + * None. + * + *******************************************************************************/ + +static void stm32_flush_rxfifo(void) +{ + uint32_t regval; + uint32_t timeout; + + /* Initiate the RX FIFO flush operation */ + + stm32_putreg(OTGFS_GRSTCTL_RXFFLSH, STM32_OTGFS_GRSTCTL); + + /* Wait for the FLUSH to complete */ + + for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++) + { + regval = stm32_getreg(STM32_OTGFS_GRSTCTL); + if ((regval & OTGFS_GRSTCTL_RXFFLSH) == 0) + { + break; + } + } + + /* Wait for 3 PHY Clocks */ + + up_udelay(3); +} + +/******************************************************************************* + * Name: stm32_vbusdrive + * + * Description: + * Drive the Vbus +5V. + * + * Input Parameters: + * priv - USB host driver private data structure. + * state - True: Drive, False: Don't drive + * + * Returned Value: + * None. + * + *******************************************************************************/ + +static void stm32_vbusdrive(FAR struct stm32_usbhost_s *priv, bool state) +{ + uint32_t regval; + + /* Enable/disable the external charge pump */ + + stm32_usbhost_vbusdrive(0, state); + + /* Turn on the Host port power. */ + + regval = stm32_getreg(STM32_OTGFS_HPRT); + regval &= ~(OTGFS_HPRT_PENA|OTGFS_HPRT_PCDET|OTGFS_HPRT_PENCHNG|OTGFS_HPRT_POCCHNG); + + if (((regval & OTGFS_HPRT_PPWR) == 0) && state) + { + regval |= OTGFS_HPRT_PPWR; + stm32_putreg(STM32_OTGFS_HPRT, regval); + } + + if (((regval & OTGFS_HPRT_PPWR) != 0) && !state) + { + regval &= ~OTGFS_HPRT_PPWR; + stm32_putreg(STM32_OTGFS_HPRT, regval); + } + + up_mdelay(200); +} + +/******************************************************************************* + * Name: stm32_host_initialize + * + * Description: + * Initialize/re-initialize hardware for host mode operation. At present, + * this function is called only from stm32_hw_initialize(). But if OTG mode + * were supported, this function would also be called to swtich between + * host and device modes on a connector ID change interrupt. + * + * Input Parameters: + * priv -- USB host driver private data structure. + * + * Returned Value: + * None. + * + *******************************************************************************/ + +static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv) +{ + uint32_t regval; + uint32_t offset; + int i; + + /* Restart the PHY Clock */ + + stm32_putreg(STM32_OTGFS_PCGCCTL, 0); + + /* Initialize Host Configuration (HCFG) register */ + + regval = stm32_getreg(STM32_OTGFS_HCFG); + regval &= ~OTGFS_HCFG_FSLSPCS_MASK; + regval |= OTGFS_HCFG_FSLSPCS_FS48MHz; + stm32_putreg(STM32_OTGFS_HCFG, regval); + + /* Reset the host port */ + + stm32_portreset(priv); + + /* Clear the FS-/LS-only support bit in the HCFG register */ + + regval = stm32_getreg(STM32_OTGFS_HCFG); + regval &= ~OTGFS_HCFG_FSLSS; + stm32_putreg(STM32_OTGFS_HCFG, regval); + + /* Carve up FIFO memory for the Rx FIFO and the periodic and non-periodic Tx FIFOs */ + /* Configure Rx FIFO size (GRXFSIZ) */ + + stm32_putreg(STM32_OTGFS_GRXFSIZ, CONFIG_STM32_OTGFS_RXFIFO_SIZE); + offset = CONFIG_STM32_OTGFS_RXFIFO_SIZE; + + /* Setup the host non-periodic Tx FIFO size (HNPTXFSIZ) */ + + regval = (offset | (CONFIG_STM32_OTGFS_NPTXFIFO_SIZE << OTGFS_HNPTXFSIZ_NPTXFD_SHIFT)); + stm32_putreg(STM32_OTGFS_HNPTXFSIZ, regval); + offset += CONFIG_STM32_OTGFS_NPTXFIFO_SIZE; + + /* Set up the host periodic Tx fifo size register (HPTXFSIZ) */ + + regval = (offset | (CONFIG_STM32_OTGFS_PTXFIFO_SIZE << OTGFS_HPTXFSIZ_PTXFD_SHIFT)); + stm32_putreg(STM32_OTGFS_HPTXFSIZ, regval); + + /* If OTG were supported, we sould need to clear HNP enable bit in the + * USB_OTG control register about here. + */ + + /* Flush all FIFOs */ + + stm32_flush_txfifos(OTGFS_GRSTCTL_TXFNUM_HALL); + stm32_flush_rxfifo(); + + /* Clear all pending HC Interrupts */ + + for (i = 0; i < STM32_NHOST_CHANNELS; i++) + { + stm32_putreg(STM32_OTGFS_HCINT(i), 0xffffffff); + stm32_putreg(STM32_OTGFS_HCINTMSK(i), 0); + } + + /* Driver Vbus +5V (the smoke test). Should be done elsewhere in OTG + * mode. + */ + + stm32_vbusdrive(priv, true); + + /* Enable host interrupts */ + + stm32_hostinit_enable(); +} + +/******************************************************************************* + * Name: stm32_sw_initialize + * + * Description: + * One-time setup of the host driver state structure. + * + * Input Parameters: + * priv -- USB host driver private data structure. + * + * Returned Value: + * None. + * + *******************************************************************************/ + +static inline void stm32_sw_initialize(FAR struct stm32_usbhost_s *priv) +{ + int i; + + /* Initialize the state data structure */ + + sem_init(&priv->eventsem, 0, 0); + sem_init(&priv->exclsem, 0, 1); + + priv->smstate = SMSTATE_DETACHED; + priv->ep0size = STM32_EP0_MAX_PACKET_SIZE; + priv->devaddr = STM32_DEF_DEVADDR; + priv->connected = false; + priv->lowspeed = false; + + /* Put all of the channels back in their initial, allocated state */ + + memset(priv->chan, 0, STM32_MAX_TX_FIFOS * sizeof(struct stm32_chan_s)); + + /* Initialize each channel */ + + for (i = 0; i < STM32_MAX_TX_FIFOS; i++) + { + FAR struct stm32_chan_s *chan = &priv->chan[i]; + sem_init(&chan->waitsem, 0, 0); + } +} + +/******************************************************************************* + * Name: stm32_hw_initialize + * + * Description: + * One-time setup of the host controller harware for normal operations. + * + * Input Parameters: + * priv -- USB host driver private data structure. + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + *******************************************************************************/ + +static inline int stm32_hw_initialize(FAR struct stm32_usbhost_s *priv) +{ + uint32_t regval; + unsigned long timeout; + + /* Set the PHYSEL bit in the GUSBCFG register to select the OTG FS serial + * transceiver: "This bit is always 1 with write-only access" + */ + + regval = stm32_getreg(STM32_OTGFS_GUSBCFG);; + regval |= OTGFS_GUSBCFG_PHYSEL; + stm32_putreg(STM32_OTGFS_GUSBCFG, regval); + + /* Reset after a PHY select and set Host mode. First, wait for AHB master + * IDLE state. + */ + + for (timeout = 0; timeout < STM32_READY_DELAY; timeout++) + { + up_udelay(3); + regval = stm32_getreg(STM32_OTGFS_GRSTCTL); + if ((regval & OTGFS_GRSTCTL_AHBIDL) != 0) + { + break; + } + } + + /* Then perform the core soft reset. */ + + stm32_putreg(STM32_OTGFS_GRSTCTL, OTGFS_GRSTCTL_CSRST); + for (timeout = 0; timeout < STM32_READY_DELAY; timeout++) + { + regval = stm32_getreg(STM32_OTGFS_GRSTCTL); + if ((regval & OTGFS_GRSTCTL_CSRST) == 0) + { + break; + } + } + + /* Wait for 3 PHY Clocks */ + + up_udelay(3); + + /* Deactivate the power down */ + + regval = (OTGFS_GCCFG_PWRDWN | OTGFS_GCCFG_VBUSASEN | OTGFS_GCCFG_VBUSBSEN); +#ifndef CONFIG_USBDEV_VBUSSENSING + regval |= OTGFS_GCCFG_NOVBUSSENS; +#endif +#ifdef CONFIG_STM32_OTGFS_SOFOUTPUT + regval |= OTGFS_GCCFG_SOFOUTEN; +#endif + stm32_putreg(STM32_OTGFS_GCCFG, regval); + up_mdelay(20); + + /* Initialize OTG features: In order to support OTP, the HNPCAP and SRPCAP + * bits would need to be set in the GUSBCFG register about here. + */ + + /* Force Host Mode */ + + regval = stm32_getreg(STM32_OTGFS_GUSBCFG); + regval &= ~OTGFS_GUSBCFG_FDMOD; + regval |= OTGFS_GUSBCFG_FHMOD; + stm32_putreg(STM32_OTGFS_GUSBCFG, regval); + up_mdelay(50); + + /* Initialize host mode and return success */ + + stm32_host_initialize(priv); + return OK; +} + +/******************************************************************************* + * Public Functions + *******************************************************************************/ + +/******************************************************************************* + * Name: usbhost_initialize + * + * Description: + * Initialize USB host device controller hardware. + * + * Input Parameters: + * controller -- If the device supports more than USB host controller, then + * this identifies which controller is being intialized. Normally, this + * is just zero. + * + * Returned Value: + * And instance of the USB host interface. The controlling task should + * use this interface to (1) call the wait() method to wait for a device + * to be connected, and (2) call the enumerate() method to bind the device + * to a class driver. + * + * Assumptions: + * - This function should called in the initialization sequence in order + * to initialize the USB device functionality. + * - Class drivers should be initialized prior to calling this function. + * Otherwise, there is a race condition if the device is already connected. + * + *******************************************************************************/ + +FAR struct usbhost_driver_s *usbhost_initialize(int controller) +{ + /* At present, there is only support for a single OTG FS host. Hence it is + * pre-allocated as g_usbhost. However, in most code, the private data + * structure will be referenced using the 'priv' pointer (rather than the + * global data) in order to simplify any future support for multiple devices. + */ + + FAR struct stm32_usbhost_s *priv = &g_usbhost; + + /* Sanity checks */ + + DEBUGASSERT(controller == 0); + + /* Make sure that interrupts from the OTG FS core are disabled */ + + stm32_gint_disable(); + + /* Reset the state of the host driver */ + + stm32_sw_initialize(priv); + + /* Alternate function pin configuration. Here we assume that: + * + * 1. GPIOA, SYSCFG, and OTG FS peripheral clocking have already been\ + * enabled as part of the boot sequence. + * 2. Board-specific logic has already enabled other board specific GPIOs + * for things like soft pull-up, VBUS sensing, power controls, and over- + * current detection. + */ + + /* Configure OTG FS alternate function pins for DM, DP, ID, and SOF. + * + * PIN* SIGNAL DIRECTION + * ---- ----------- ---------- + * PA8 OTG_FS_SOF SOF clock output + * PA9 OTG_FS_VBUS VBUS input for device, Driven by external regulator by + * host (not an alternate function) + * PA10 OTG_FS_ID OTG ID pin (only needed in Dual mode) + * PA11 OTG_FS_DM D- I/O + * PA12 OTG_FS_DP D+ I/O + * + * *Pins may vary from device-to-device. + */ + + stm32_configgpio(GPIO_OTGFS_DM); + stm32_configgpio(GPIO_OTGFS_DP); + stm32_configgpio(GPIO_OTGFS_ID); /* Only needed for OTG */ + + /* SOF output pin configuration is configurable */ + +#ifdef CONFIG_STM32_OTGFS_SOFOUTPUT + stm32_configgpio(GPIO_OTGFS_SOF); +#endif + + /* Initialize the USB OTG FS core */ + + stm32_hw_initialize(priv); + + /* Attach USB host controller interrupt handler */ + + if (irq_attach(STM32_IRQ_OTGFS, stm32_gint_isr) != 0) + { + udbg("Failed to attach IRQ\n"); + return NULL; + } + + /* Enable USB OTG FS global interrupts */ + + stm32_gint_enable(); + + /* Enable interrupts at the interrupt controller */ + + up_enable_irq(STM32_IRQ_OTGFS); + return &priv->drvr; +} + +#endif /* CONFIG_USBHOST && CONFIG_STM32_OTGFS */ diff --git a/nuttx/arch/arm/src/stm32/stm32_pwr.c b/nuttx/arch/arm/src/stm32/stm32_pwr.c index bada048e3e..14149922f9 100644 --- a/nuttx/arch/arm/src/stm32/stm32_pwr.c +++ b/nuttx/arch/arm/src/stm32/stm32_pwr.c @@ -95,4 +95,4 @@ void stm32_pwr_enablebkp(void) stm32_pwr_modifyreg(STM32_PWR_CR_OFFSET, 0, PWR_CR_DBP); } -#endif // defined(CONFIG_STM32_PWR) +#endif /* CONFIG_STM32_PWR */ diff --git a/nuttx/arch/arm/src/stm32/stm32_pwr.h b/nuttx/arch/arm/src/stm32/stm32_pwr.h index 56aee49b67..7a2751677e 100644 --- a/nuttx/arch/arm/src/stm32/stm32_pwr.h +++ b/nuttx/arch/arm/src/stm32/stm32_pwr.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_pwr.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_sdio.c b/nuttx/arch/arm/src/stm32/stm32_sdio.c index 57d5f80d96..a8bcae3070 100644 --- a/nuttx/arch/arm/src/stm32/stm32_sdio.c +++ b/nuttx/arch/arm/src/stm32/stm32_sdio.c @@ -2512,6 +2512,7 @@ static int stm32_dmarecvsetup(FAR struct sdio_dev_s *dev, FAR uint8_t *buffer, stm32_sample(priv, SAMPLENDX_AFTER_SETUP); ret = OK; } + return ret; } #endif @@ -2587,6 +2588,7 @@ static int stm32_dmasendsetup(FAR struct sdio_dev_s *dev, ret = OK; } + return ret; } #endif @@ -2660,7 +2662,7 @@ static void stm32_callback(void *arg) /* Yes.. queue it */ fvdbg("Queuing callback to %p(%p)\n", priv->callback, priv->cbarg); - (void)work_queue(&priv->cbwork, (worker_t)priv->callback, priv->cbarg, 0); + (void)work_queue(HPWORK, &priv->cbwork, (worker_t)priv->callback, priv->cbarg, 0); } else { diff --git a/nuttx/arch/arm/src/stm32/stm32_serial.c b/nuttx/arch/arm/src/stm32/stm32_serial.c index 265abfbf35..ff18d208bc 100644 --- a/nuttx/arch/arm/src/stm32/stm32_serial.c +++ b/nuttx/arch/arm/src/stm32/stm32_serial.c @@ -90,7 +90,7 @@ # endif # if defined(CONFIG_USART2_RXDMA) || defined(CONFIG_USART3_RXDMA) || \ - defined(CONFIG_USART4_RXDMA) || defined(CONFIG_USART5_RXDMA) + defined(CONFIG_UART4_RXDMA) || defined(CONFIG_UART5_RXDMA) # ifndef CONFIG_STM32_DMA1 # error STM32 USART2/3/4/5 receive DMA requires CONFIG_STM32_DMA1 # endif @@ -113,11 +113,11 @@ # error "USART3 DMA channel not defined (DMAMAP_USART3_RX)" # endif -# if defined(CONFIG_USART4_RXDMA) && !defined(DMAMAP_UART4_RX) +# if defined(CONFIG_UART4_RXDMA) && !defined(DMAMAP_UART4_RX) # error "UART4 DMA channel not defined (DMAMAP_UART4_RX)" # endif -# if defined(CONFIG_USART5_RXDMA) && !defined(DMAMAP_UART5_RX) +# if defined(CONFIG_UART5_RXDMA) && !defined(DMAMAP_UART5_RX) # error "UART5 DMA channel not defined (DMAMAP_UART5_RX)" # endif @@ -338,17 +338,17 @@ static char g_usart3rxfifo[RXDMA_BUFFER_SIZE]; #endif #ifdef CONFIG_STM32_UART4 -static char g_uart4rxbuffer[CONFIG_USART4_RXBUFSIZE]; -static char g_uart4txbuffer[CONFIG_USART4_TXBUFSIZE]; -# ifdef CONFIG_USART4_RXDMA +static char g_uart4rxbuffer[CONFIG_UART4_RXBUFSIZE]; +static char g_uart4txbuffer[CONFIG_UART4_TXBUFSIZE]; +# ifdef CONFIG_UART4_RXDMA static char g_uart4rxfifo[RXDMA_BUFFER_SIZE]; # endif #endif #ifdef CONFIG_STM32_UART5 -static char g_uart5rxbuffer[CONFIG_USART5_RXBUFSIZE]; -static char g_uart5txbuffer[CONFIG_USART5_TXBUFSIZE]; -# ifdef CONFIG_USART5_RXDMA +static char g_uart5rxbuffer[CONFIG_UART5_RXBUFSIZE]; +static char g_uart5txbuffer[CONFIG_UART5_TXBUFSIZE]; +# ifdef CONFIG_UART5_RXDMA static char g_uart5rxfifo[RXDMA_BUFFER_SIZE]; # endif #endif @@ -526,15 +526,15 @@ static struct up_dev_s g_uart4priv = #endif .recv = { - .size = CONFIG_USART4_RXBUFSIZE, + .size = CONFIG_UART4_RXBUFSIZE, .buffer = g_uart4rxbuffer, }, .xmit = { - .size = CONFIG_USART4_TXBUFSIZE, + .size = CONFIG_UART4_TXBUFSIZE, .buffer = g_uart4txbuffer, }, -#ifdef CONFIG_USART4_RXDMA +#ifdef CONFIG_UART4_RXDMA .ops = &g_uart_dma_ops, #else .ops = &g_uart_ops, @@ -543,21 +543,21 @@ static struct up_dev_s g_uart4priv = }, .irq = STM32_IRQ_UART4, - .parity = CONFIG_USART4_PARITY, - .bits = CONFIG_USART4_BITS, - .stopbits2 = CONFIG_USART4_2STOP, - .baud = CONFIG_USART4_BAUD, + .parity = CONFIG_UART4_PARITY, + .bits = CONFIG_UART4_BITS, + .stopbits2 = CONFIG_UART4_2STOP, + .baud = CONFIG_UART4_BAUD, .apbclock = STM32_PCLK1_FREQUENCY, .usartbase = STM32_UART4_BASE, .tx_gpio = GPIO_UART4_TX, .rx_gpio = GPIO_UART4_RX, -#ifdef GPIO_USART4_CTS +#ifdef GPIO_UART4_CTS .cts_gpio = GPIO_UART4_CTS, #endif -#ifdef GPIO_USART4_RTS +#ifdef GPIO_UART4_RTS .rts_gpio = GPIO_UART4_RTS, #endif -#ifdef CONFIG_USART4_RXDMA +#ifdef CONFIG_UART4_RXDMA .rxdma_channel = DMAMAP_UART4_RX, .rxfifo = g_uart4rxfifo, #endif @@ -577,15 +577,15 @@ static struct up_dev_s g_uart5priv = #endif .recv = { - .size = CONFIG_USART5_RXBUFSIZE, + .size = CONFIG_UART5_RXBUFSIZE, .buffer = g_uart5rxbuffer, }, .xmit = { - .size = CONFIG_USART5_TXBUFSIZE, + .size = CONFIG_UART5_TXBUFSIZE, .buffer = g_uart5txbuffer, }, -#ifdef CONFIG_USART5_RXDMA +#ifdef CONFIG_UART5_RXDMA .ops = &g_uart_dma_ops, #else .ops = &g_uart_ops, @@ -594,21 +594,21 @@ static struct up_dev_s g_uart5priv = }, .irq = STM32_IRQ_UART5, - .parity = CONFIG_USART5_PARITY, - .bits = CONFIG_USART5_BITS, - .stopbits2 = CONFIG_USART5_2STOP, - .baud = CONFIG_USART5_BAUD, + .parity = CONFIG_UART5_PARITY, + .bits = CONFIG_UART5_BITS, + .stopbits2 = CONFIG_UART5_2STOP, + .baud = CONFIG_UART5_BAUD, .apbclock = STM32_PCLK1_FREQUENCY, .usartbase = STM32_UART5_BASE, .tx_gpio = GPIO_UART5_TX, .rx_gpio = GPIO_UART5_RX, -#ifdef GPIO_USART5_CTS +#ifdef GPIO_UART5_CTS .cts_gpio = GPIO_UART5_CTS, #endif -#ifdef GPIO_USART5_RTS +#ifdef GPIO_UART5_RTS .rts_gpio = GPIO_UART5_RTS, #endif -#ifdef CONFIG_USART5_RXDMA +#ifdef CONFIG_UART5_RXDMA .rxdma_channel = DMAMAP_UART5_RX, .rxfifo = g_uart5rxfifo, #endif @@ -956,7 +956,8 @@ static int up_setup(struct uart_dev_s *dev) /* Set up the cached interrupt enables value */ - priv->ie = 0; + up_restoreusartint(priv, 0); + return OK; } @@ -976,12 +977,15 @@ static int up_dma_setup(struct uart_dev_s *dev) int result; uint32_t regval; - /* Do the basic UART setup first */ + /* Do the basic UART setup first, unless we are the console */ - result = up_setup(dev); - if (result != OK) - { - return result; + if (!dev->isconsole) + { + result = up_setup(dev); + if (result != OK) + { + return result; + } } /* Acquire the DMA channel. This should always succeed. */ @@ -1835,7 +1839,14 @@ void up_serialinit(void) #if CONSOLE_UART > 0 (void)uart_register("/dev/console", &uart_devs[CONSOLE_UART - 1]->dev); (void)uart_register("/dev/ttyS0", &uart_devs[CONSOLE_UART - 1]->dev); -#endif + + /* If we need to re-initialise the console to enable DMA do that here. */ + +# ifdef SERIAL_HAVE_CONSOLE_DMA + up_dma_setup(&uart_devs[CONSOLE_UART - 1]->dev); +# endif + +#endif /* CONSOLE_UART > 0 */ /* Register all remaining USARTs */ @@ -1898,14 +1909,14 @@ void stm32_serial_dma_poll(void) } #endif -#ifdef CONFIG_USART4_RXDMA +#ifdef CONFIG_UART4_RXDMA if (g_uart4priv.rxdma != NULL) { up_dma_rxcallback(g_uart4priv.rxdma, 0, &g_uart4priv); } #endif -#ifdef CONFIG_USART5_RXDMA +#ifdef CONFIG_UART5_RXDMA if (g_uart5priv.rxdma != NULL) { up_dma_rxcallback(g_uart5priv.rxdma, 0, &g_uart5priv); @@ -1934,10 +1945,10 @@ void stm32_serial_dma_poll(void) int up_putc(int ch) { #if CONSOLE_UART > 0 - struct up_dev_s *priv = uart_devs[CONSOLE_UART - 1]; - uint16_t ie; +// struct up_dev_s *priv = uart_devs[CONSOLE_UART - 1]; +// uint16_t ie; - up_disableusartint(priv, &ie); +// up_disableusartint(priv, &ie); /* Check for LF */ @@ -1949,7 +1960,7 @@ int up_putc(int ch) } up_lowputc(ch); - up_restoreusartint(priv, ie); +// up_restoreusartint(priv, ie); #endif return ch; } diff --git a/nuttx/arch/arm/src/stm32/stm32_spi.c b/nuttx/arch/arm/src/stm32/stm32_spi.c index 40b1a29a09..8de698cd5a 100644 --- a/nuttx/arch/arm/src/stm32/stm32_spi.c +++ b/nuttx/arch/arm/src/stm32/stm32_spi.c @@ -49,7 +49,7 @@ * 3. Add a calls to up_spiinitialize() in your low level application * initialization logic * 4. The handle returned by up_spiinitialize() may then be used to bind the - * SPI driver to higher level logic (e.g., calling + * SPI driver to higher level logic (e.g., calling * mmcsd_spislotinitialize(), for example, will bind the SPI driver to * the SPI MMC/SD driver). * @@ -881,7 +881,7 @@ static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency) else { /* Less than fPCLK/128. This is as slow as we can go */ - + setbits = SPI_CR1_FPCLCKd256; /* 111: fPCLK/256 */ actual = priv->spiclock >> 8; } @@ -941,22 +941,22 @@ static void spi_setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode) setbits = 0; clrbits = SPI_CR1_CPOL|SPI_CR1_CPHA; break; - + case SPIDEV_MODE1: /* CPOL=0; CPHA=1 */ setbits = SPI_CR1_CPHA; clrbits = SPI_CR1_CPOL; break; - + case SPIDEV_MODE2: /* CPOL=1; CPHA=0 */ setbits = SPI_CR1_CPOL; clrbits = SPI_CR1_CPHA; break; - + case SPIDEV_MODE3: /* CPOL=1; CPHA=1 */ setbits = SPI_CR1_CPOL|SPI_CR1_CPHA; clrbits = 0; break; - + default: return; } @@ -1008,7 +1008,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits) setbits = 0; clrbits = SPI_CR1_DFF; break; - + case 16: setbits = SPI_CR1_DFF; clrbits = 0; @@ -1111,7 +1111,7 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, } /* Exchange one word */ - + word = spi_send(dev, word); /* Is there a buffer to receive the return value? */ @@ -1120,7 +1120,7 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, { *dest++ = word; } - } + } } else { @@ -1144,7 +1144,7 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, } /* Exchange one word */ - + word = (uint8_t)spi_send(dev, (uint16_t)word); /* Is there a buffer to receive the return value? */ @@ -1152,7 +1152,7 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, if (dest) { *dest++ = word; - } + } } } } @@ -1331,7 +1331,7 @@ static void spi_portinitialize(FAR struct stm32_spidev_s *priv) priv->txdma = stm32_dmachannel(priv->txch); DEBUGASSERT(priv->rxdma && priv->txdma); #endif - + /* Enable spi */ spi_modifycr1(priv, SPI_CR1_SPE, 0); @@ -1360,7 +1360,7 @@ FAR struct spi_dev_s *up_spiinitialize(int port) FAR struct stm32_spidev_s *priv = NULL; irqstate_t flags = irqsave(); - + #ifdef CONFIG_STM32_SPI1 if (port == 1) { @@ -1431,7 +1431,12 @@ FAR struct spi_dev_s *up_spiinitialize(int port) spi_portinitialize(priv); } } + else #endif + { + spidbg("ERROR: Unsupported SPI port: %d\n", port); + return NULL; + } irqrestore(flags); return (FAR struct spi_dev_s *)priv; diff --git a/nuttx/arch/arm/src/stm32/stm32_spi.h b/nuttx/arch/arm/src/stm32/stm32_spi.h index 268589bf35..6030ddfdd2 100644 --- a/nuttx/arch/arm/src/stm32/stm32_spi.h +++ b/nuttx/arch/arm/src/stm32/stm32_spi.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_spi.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_syscfg.h b/nuttx/arch/arm/src/stm32/stm32_syscfg.h index 8a57a2c58f..d1487da409 100644 --- a/nuttx/arch/arm/src/stm32/stm32_syscfg.h +++ b/nuttx/arch/arm/src/stm32/stm32_syscfg.h @@ -45,60 +45,10 @@ #if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) # include "chip/stm32_syscfg.h" +#endif /* CONFIG_STM32_STM32F20XX || CONFIG_STM32_STM32F40XX */ /**************************************************************************************************** * Pre-processor Definitions ****************************************************************************************************/ -/**************************************************************************************************** - * Inline Functions - ****************************************************************************************************/ - -/************************************************************************************ - * Name: stm32_selectmii - * - * Description: - * Selects the MII inteface. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ************************************************************************************/ - -static inline void stm32_selectmii(void) -{ - uint32_t regval; - - regval = getreg32(STM32_SYSCFG_PMC); - regval &= ~SYSCFG_PMC_MII_RMII_SEL; - putreg32(regval, STM32_SYSCFG_PMC); -} - -/************************************************************************************ - * Name: stm32_selectrmii - * - * Description: - * Selects the RMII inteface. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ************************************************************************************/ - -static inline void stm32_selectrmii(void) -{ - uint32_t regval; - - regval = getreg32(STM32_SYSCFG_PMC); - regval |= SYSCFG_PMC_MII_RMII_SEL; - putreg32(regval, STM32_SYSCFG_PMC); -} - -#endif /* CONFIG_STM32_STM32F20XX || CONFIG_STM32_STM32F40XX */ #endif /* __ARCH_ARM_SRC_STM32_STM32_SYSCFG_H */ diff --git a/nuttx/arch/arm/src/stm32/stm32_timerisr.c b/nuttx/arch/arm/src/stm32/stm32_timerisr.c index 93cca02aca..ff64994156 100644 --- a/nuttx/arch/arm/src/stm32/stm32_timerisr.c +++ b/nuttx/arch/arm/src/stm32/stm32_timerisr.c @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_timerisr.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_uart.h b/nuttx/arch/arm/src/stm32/stm32_uart.h index 42fe9e346b..a70923cbf9 100644 --- a/nuttx/arch/arm/src/stm32/stm32_uart.h +++ b/nuttx/arch/arm/src/stm32/stm32_uart.h @@ -84,40 +84,40 @@ #if defined(CONFIG_USART1_SERIAL_CONSOLE) && defined(CONFIG_STM32_USART1) # undef CONFIG_USART2_SERIAL_CONSOLE # undef CONFIG_USART3_SERIAL_CONSOLE -# undef CONFIG_USART4_SERIAL_CONSOLE -# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_UART4_SERIAL_CONSOLE +# undef CONFIG_UART5_SERIAL_CONSOLE # undef CONFIG_USART6_SERIAL_CONSOLE # define CONSOLE_UART 1 # define HAVE_CONSOLE 1 #elif defined(CONFIG_USART2_SERIAL_CONSOLE) && defined(CONFIG_STM32_USART2) # undef CONFIG_USART1_SERIAL_CONSOLE # undef CONFIG_USART3_SERIAL_CONSOLE -# undef CONFIG_USART4_SERIAL_CONSOLE -# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_UART4_SERIAL_CONSOLE +# undef CONFIG_UART5_SERIAL_CONSOLE # undef CONFIG_USART6_SERIAL_CONSOLE # define CONSOLE_UART 2 # define HAVE_CONSOLE 1 #elif defined(CONFIG_USART3_SERIAL_CONSOLE) && defined(CONFIG_STM32_USART3) # undef CONFIG_USART1_SERIAL_CONSOLE # undef CONFIG_USART2_SERIAL_CONSOLE -# undef CONFIG_USART4_SERIAL_CONSOLE -# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_UART4_SERIAL_CONSOLE +# undef CONFIG_UART5_SERIAL_CONSOLE # undef CONFIG_USART6_SERIAL_CONSOLE # define CONSOLE_UART 3 # define HAVE_CONSOLE 1 -#elif defined(CONFIG_USART4_SERIAL_CONSOLE) && defined(CONFIG_STM32_UART4) +#elif defined(CONFIG_UART4_SERIAL_CONSOLE) && defined(CONFIG_STM32_UART4) # undef CONFIG_USART1_SERIAL_CONSOLE # undef CONFIG_USART2_SERIAL_CONSOLE # undef CONFIG_USART3_SERIAL_CONSOLE -# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_UART5_SERIAL_CONSOLE # undef CONFIG_USART6_SERIAL_CONSOLE # define CONSOLE_UART 4 # define HAVE_CONSOLE 1 -#elif defined(CONFIG_USART5_SERIAL_CONSOLE) && defined(CONFIG_STM32_UART5) +#elif defined(CONFIG_UART5_SERIAL_CONSOLE) && defined(CONFIG_STM32_UART5) # undef CONFIG_USART1_SERIAL_CONSOLE # undef CONFIG_USART2_SERIAL_CONSOLE # undef CONFIG_USART3_SERIAL_CONSOLE -# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_UART4_SERIAL_CONSOLE # undef CONFIG_USART6_SERIAL_CONSOLE # define CONSOLE_UART 5 # define HAVE_CONSOLE 1 @@ -125,16 +125,16 @@ # undef CONFIG_USART1_SERIAL_CONSOLE # undef CONFIG_USART2_SERIAL_CONSOLE # undef CONFIG_USART3_SERIAL_CONSOLE -# undef CONFIG_USART4_SERIAL_CONSOLE -# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_UART4_SERIAL_CONSOLE +# undef CONFIG_UART5_SERIAL_CONSOLE # define CONSOLE_UART 6 # define HAVE_CONSOLE 1 #else # undef CONFIG_USART1_SERIAL_CONSOLE # undef CONFIG_USART2_SERIAL_CONSOLE # undef CONFIG_USART3_SERIAL_CONSOLE -# undef CONFIG_USART4_SERIAL_CONSOLE -# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_UART4_SERIAL_CONSOLE +# undef CONFIG_UART5_SERIAL_CONSOLE # undef CONFIG_USART6_SERIAL_CONSOLE # define CONSOLE_UART 0 # undef HAVE_CONSOLE @@ -149,8 +149,8 @@ # undef CONFIG_USART1_RXDMA # undef CONFIG_USART2_RXDMA # undef CONFIG_USART3_RXDMA -# undef CONFIG_USART4_RXDMA -# undef CONFIG_USART5_RXDMA +# undef CONFIG_UART4_RXDMA +# undef CONFIG_UART5_RXDMA # undef CONFIG_USART6_RXDMA #endif @@ -169,11 +169,11 @@ #endif #ifndef CONFIG_STM32_UART4 -# undef CONFIG_USART4_RXDMA +# undef CONFIG_UART4_RXDMA #endif #ifndef CONFIG_STM32_UART5 -# undef CONFIG_USART5_RXDMA +# undef CONFIG_UART5_RXDMA #endif #ifndef CONFIG_STM32_USART6 @@ -184,11 +184,28 @@ #undef SERIAL_HAVE_DMA #if defined(CONFIG_USART1_RXDMA) || defined(CONFIG_USART2_RXDMA) || \ - defined(CONFIG_USART3_RXDMA) || defined(CONFIG_USART4_RXDMA) || \ - defined(CONFIG_USART5_RXDMA) || defined(CONFIG_USART6_RXDMA) + defined(CONFIG_USART3_RXDMA) || defined(CONFIG_UART4_RXDMA) || \ + defined(CONFIG_UART5_RXDMA) || defined(CONFIG_USART6_RXDMA) # define SERIAL_HAVE_DMA 1 #endif +/* Is DMA used on the console UART? */ + +#undef SERIAL_HAVE_CONSOLE_DMA +#if defined(CONFIG_USART1_SERIAL_CONSOLE) && defined(CONFIG_USART1_RXDMA) +# define SERIAL_HAVE_CONSOLE_DMA 1 +#elif defined(CONFIG_USART2_SERIAL_CONSOLE) && defined(CONFIG_USART2_RXDMA) +# define SERIAL_HAVE_CONSOLE_DMA 1 +#elif defined(CONFIG_USART3_SERIAL_CONSOLE) && defined(CONFIG_USART3_RXDMA) +# define SERIAL_HAVE_CONSOLE_DMA 1 +#elif defined(CONFIG_UART4_SERIAL_CONSOLE) && defined(CONFIG_UART4_RXDMA) +# define SERIAL_HAVE_CONSOLE_DMA 1 +#elif defined(CONFIG_UART5_SERIAL_CONSOLE) && defined(CONFIG_UART5_RXDMA) +# define SERIAL_HAVE_CONSOLE_DMA 1 +#elif defined(CONFIG_USART6_SERIAL_CONSOLE) && defined(CONFIG_USART6_RXDMA) +# define SERIAL_HAVE_CONSOLE_DMA 1 +#endif + /* Is DMA used on all (enabled) USARTs */ #define SERIAL_HAVE_ONLY_DMA 1 @@ -198,9 +215,9 @@ # undef SERIAL_HAVE_ONLY_DMA #elif defined(CONFIG_STM32_USART3) && !defined(CONFIG_USART3_RXDMA) # undef SERIAL_HAVE_ONLY_DMA -#elif defined(CONFIG_STM32_UART4) && !defined(CONFIG_USART4_RXDMA) +#elif defined(CONFIG_STM32_UART4) && !defined(CONFIG_UART4_RXDMA) # undef SERIAL_HAVE_ONLY_DMA -#elif defined(CONFIG_STM32_UART5) && !defined(CONFIG_USART5_RXDMA) +#elif defined(CONFIG_STM32_UART5) && !defined(CONFIG_UART5_RXDMA) # undef SERIAL_HAVE_ONLY_DMA #elif defined(CONFIG_STM32_USART6) && !defined(CONFIG_USART6_RXDMA) # undef SERIAL_HAVE_ONLY_DMA diff --git a/nuttx/arch/arm/src/stm32/stm32_usbdev.h b/nuttx/arch/arm/src/stm32/stm32_usbdev.h index a1af471b25..587107dc8a 100644 --- a/nuttx/arch/arm/src/stm32/stm32_usbdev.h +++ b/nuttx/arch/arm/src/stm32/stm32_usbdev.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_usbdev.h * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32_usbhost.c b/nuttx/arch/arm/src/stm32/stm32_usbhost.c deleted file mode 100644 index 4bf6d646da..0000000000 --- a/nuttx/arch/arm/src/stm32/stm32_usbhost.c +++ /dev/null @@ -1,2695 +0,0 @@ -/******************************************************************************* - * arch/arm/src/stm32/stm32_usbhost.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Authors: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - *******************************************************************************/ - -/******************************************************************************* - * Included Files - *******************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "chip.h" /* Includes default GPIO settings */ -#include /* May redefine GPIO settings */ - -#include "up_arch.h" -#include "up_internal.h" - -#include "stm32_usbhost.h" - -/******************************************************************************* - * Definitions - *******************************************************************************/ - -/* Configuration ***************************************************************/ - -/* All I/O buffers must lie in AHB SRAM because of the OHCI DMA. It might be - * okay if no I/O buffers are used *IF* the application can guarantee that all - * end-user I/O buffers reside in AHB SRAM. - */ - -#if STM32_IOBUFFERS < 1 -# warning "No IO buffers allocated" -#endif - -/* OHCI Setup ******************************************************************/ -/* Frame Interval / Periodic Start */ - -#define BITS_PER_FRAME 12000 -#define FI (BITS_PER_FRAME-1) -#define FSMPS ((6 * (FI - 210)) / 7) -#define DEFAULT_FMINTERVAL ((FSMPS << OHCI_FMINT_FSMPS_SHIFT) | FI) -#define DEFAULT_PERSTART (((9 * BITS_PER_FRAME) / 10) - 1) - -/* CLKCTRL enable bits */ - -#define STM32_CLKCTRL_ENABLES (USBOTG_CLK_HOSTCLK|USBOTG_CLK_PORTSELCLK|USBOTG_CLK_AHBCLK) - -/* Interrupt enable bits */ - -#ifdef CONFIG_DEBUG_USB -# define STM32_DEBUG_INTS (OHCI_INT_SO|OHCI_INT_RD|OHCI_INT_UE|OHCI_INT_OC) -#else -# define STM32_DEBUG_INTS 0 -#endif - -#define STM32_NORMAL_INTS (OHCI_INT_WDH|OHCI_INT_RHSC) -#define STM32_ALL_INTS (STM32_NORMAL_INTS|STM32_DEBUG_INTS) - -/* Dump GPIO registers */ - -#if defined(CONFIG_STM32_USBHOST_REGDEBUG) && defined(CONFIG_DEBUG_GPIO) -# define usbhost_dumpgpio() \ - do { \ - stm32_dumpgpio(GPIO_USB_DP, "D+ P0.29; D- P0.30"); \ - stm32_dumpgpio(GPIO_USB_UPLED, "LED P1:18; PPWR P1:19 PWRD P1:22 PVRCR P1:27"); \ - } while (0); -#else -# define usbhost_dumpgpio() -#endif - -/* USB Host Memory *************************************************************/ - -/* Helper definitions */ - -#define HCCA ((struct ohci_hcca_s *)STM32_HCCA_BASE) -#define TDTAIL ((struct stm32_gtd_s *)STM32_TDTAIL_ADDR) -#define EDCTRL ((struct stm32_ed_s *)STM32_EDCTRL_ADDR) - -/* Periodic intervals 2, 4, 8, 16,and 32 supported */ - -#define MIN_PERINTERVAL 2 -#define MAX_PERINTERVAL 32 - -/* Descriptors *****************************************************************/ - -/* TD delay interrupt value */ - -#define TD_DELAY(n) (uint32_t)((n) << GTD_STATUS_DI_SHIFT) - -/******************************************************************************* - * Private Types - *******************************************************************************/ - -/* This structure retains the state of the USB host controller */ - -struct stm32_usbhost_s -{ - /* Common device fields. This must be the first thing defined in the - * structure so that it is possible to simply cast from struct usbhost_s - * to structstm32_usbhost_s. - */ - - struct usbhost_driver_s drvr; - - /* The bound device class driver */ - - struct usbhost_class_s *class; - - /* Driver status */ - - volatile bool connected; /* Connected to device */ - volatile bool lowspeed; /* Low speed device attached. */ - volatile bool rhswait; /* TRUE: Thread is waiting for Root Hub Status change */ -#ifndef CONFIG_USBHOST_INT_DISABLE - uint8_t ininterval; /* Minimum periodic IN EP polling interval: 2, 4, 6, 16, or 32 */ - uint8_t outinterval; /* Minimum periodic IN EP polling interval: 2, 4, 6, 16, or 32 */ -#endif - sem_t exclsem; /* Support mutually exclusive access */ - sem_t rhssem; /* Semaphore to wait Writeback Done Head event */ -}; - -/* The OCHI expects the size of an endpoint descriptor to be 16 bytes. - * However, the size allocated for an endpoint descriptor is 32 bytes in - * stm32_ohciram.h. This extra 16-bytes is used by the OHCI host driver in - * order to maintain additional endpoint-specific data. - */ - -struct stm32_ed_s -{ - /* Hardware specific fields */ - - struct ohci_ed_s hw; - - /* Software specific fields */ - - uint8_t xfrtype; /* Transfer type. See SB_EP_ATTR_XFER_* in usb.h */ - uint8_t interval; /* Periodic EP polling interval: 2, 4, 6, 16, or 32 */ - volatile uint8_t tdstatus; /* TD control status bits from last Writeback Done Head event */ - volatile bool wdhwait; /* TRUE: Thread is waiting for WDH interrupt */ - sem_t wdhsem; /* Semaphore used to wait for Writeback Done Head event */ - /* Unused bytes follow, depending on the size of sem_t */ -}; - -/* The OCHI expects the size of an transfer descriptor to be 16 bytes. - * However, the size allocated for an endpoint descriptor is 32 bytes in - * stm32_ohciram.h. This extra 16-bytes is used by the OHCI host driver in - * order to maintain additional endpoint-specific data. - */ - -struct stm32_gtd_s -{ - /* Hardware specific fields */ - - struct ohci_gtd_s hw; - - /* Software specific fields */ - - struct stm32_ed_s *ed; /* Pointer to parent ED */ - uint8_t pad[12]; -}; - -/* The following is used to manage lists of free EDs, TDs, and TD buffers */ - -struct stm32_list_s -{ - struct stm32_list_s *flink; /* Link to next buffer in the list */ - /* Variable length buffer data follows */ -}; - -/******************************************************************************* - * Private Function Prototypes - *******************************************************************************/ - -/* Register operations ********************************************************/ - -#ifdef CONFIG_STM32_USBHOST_REGDEBUG -static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite); -static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite); -static uint32_t stm32_getreg(uint32_t addr); -static void stm32_putreg(uint32_t val, uint32_t addr); -#else -# define stm32_getreg(addr) getreg32(addr) -# define stm32_putreg(val,addr) putreg32(val,addr) -#endif - -/* Semaphores ******************************************************************/ - -static void stm32_takesem(sem_t *sem); -#define stm32_givesem(s) sem_post(s); - -/* Byte stream access helper functions *****************************************/ - -static inline uint16_t stm32_getle16(const uint8_t *val); -static void stm32_putle16(uint8_t *dest, uint16_t val); - -/* OHCI memory pool helper functions *******************************************/ - -static inline void stm32_edfree(struct stm32_ed_s *ed); -static struct stm32_gtd_s *stm32_tdalloc(void); -static void stm32_tdfree(struct stm32_gtd_s *buffer); -static uint8_t *stm32_tballoc(void); -static void stm32_tbfree(uint8_t *buffer); -#if STM32_IOBUFFERS > 0 -static uint8_t *stm32_allocio(void); -static void stm32_freeio(uint8_t *buffer); -#endif - -/* ED list helper functions ****************************************************/ - -static inline int stm32_addbulked(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed); -static inline int stm32_rembulked(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed); - -#if !defined(CONFIG_USBHOST_INT_DISABLE) || !defined(CONFIG_USBHOST_ISOC_DISABLE) -static unsigned int stm32_getinterval(uint8_t interval); -static void stm32_setinttab(uint32_t value, unsigned int interval, unsigned int offset); -#endif - -static inline int stm32_addinted(struct stm32_usbhost_s *priv, - const FAR struct usbhost_epdesc_s *epdesc, - struct stm32_ed_s *ed); -static inline int stm32_reminted(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed); - -static inline int stm32_addisoced(struct stm32_usbhost_s *priv, - const FAR struct usbhost_epdesc_s *epdesc, - struct stm32_ed_s *ed); -static inline int stm32_remisoced(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed); - -/* Descriptor helper functions *************************************************/ - -static int stm32_enqueuetd(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed, uint32_t dirpid, - uint32_t toggle, volatile uint8_t *buffer, - size_t buflen); -static int stm32_ctrltd(struct stm32_usbhost_s *priv, uint32_t dirpid, - uint8_t *buffer, size_t buflen); - -/* Interrupt handling **********************************************************/ - -static int stm32_usbinterrupt(int irq, FAR void *context); - -/* USB host controller operations **********************************************/ - -static int stm32_wait(FAR struct usbhost_driver_s *drvr, bool connected); -static int stm32_enumerate(FAR struct usbhost_driver_s *drvr); -static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, - uint16_t maxpacketsize); -static int stm32_epalloc(FAR struct usbhost_driver_s *drvr, - const FAR struct usbhost_epdesc_s *epdesc, usbhost_ep_t *ep); -static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep); -static int stm32_alloc(FAR struct usbhost_driver_s *drvr, - FAR uint8_t **buffer, FAR size_t *maxlen); -static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer); -static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr, - FAR uint8_t **buffer, size_t buflen); -static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer); -static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, - FAR const struct usb_ctrlreq_s *req, - FAR uint8_t *buffer); -static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, - FAR const struct usb_ctrlreq_s *req, - FAR const uint8_t *buffer); -static int stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep, - FAR uint8_t *buffer, size_t buflen); -static void stm32_disconnect(FAR struct usbhost_driver_s *drvr); - -/* Initialization **************************************************************/ - -static inline void stm32_ep0init(struct stm32_usbhost_s *priv); - -/******************************************************************************* - * Private Data - *******************************************************************************/ - -/* In this driver implementation, support is provided for only a single a single - * USB device. All status information can be simply retained in a single global - * instance. - */ - -static struct stm32_usbhost_s g_usbhost = -{ - .drvr = - { - .wait = stm32_wait, - .enumerate = stm32_enumerate, - .ep0configure = stm32_ep0configure, - .epalloc = stm32_epalloc, - .epfree = stm32_epfree, - .alloc = stm32_alloc, - .free = stm32_free, - .ioalloc = stm32_ioalloc, - .iofree = stm32_iofree, - .ctrlin = stm32_ctrlin, - .ctrlout = stm32_ctrlout, - .transfer = stm32_transfer, - .disconnect = stm32_disconnect, - }, - .class = NULL, -}; - -/* This is a free list of EDs and TD buffers */ - -static struct stm32_list_s *g_edfree; /* List of unused EDs */ -static struct stm32_list_s *g_tdfree; /* List of unused TDs */ -static struct stm32_list_s *g_tbfree; /* List of unused transfer buffers */ -#if STM32_IOBUFFERS > 0 -static struct stm32_list_s *g_iofree; /* List of unused I/O buffers */ -#endif - -/******************************************************************************* - * Public Data - *******************************************************************************/ - -/******************************************************************************* - * Private Functions - *******************************************************************************/ - -/******************************************************************************* - * Name: stm32_printreg - * - * Description: - * Print the contents of an STM32xx register operation - * - *******************************************************************************/ - -#ifdef CONFIG_STM32_USBHOST_REGDEBUG -static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite) -{ - lldbg("%08x%s%08x\n", addr, iswrite ? "<-" : "->", val); -} -#endif - -/******************************************************************************* - * Name: stm32_checkreg - * - * Description: - * Get the contents of an STM32 register - * - *******************************************************************************/ - -#ifdef CONFIG_STM32_USBHOST_REGDEBUG -static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite) -{ - static uint32_t prevaddr = 0; - static uint32_t preval = 0; - static uint32_t count = 0; - static bool prevwrite = false; - - /* Is this the same value that we read from/wrote to the same register last time? - * Are we polling the register? If so, suppress the output. - */ - - if (addr == prevaddr && val == preval && prevwrite == iswrite) - { - /* Yes.. Just increment the count */ - - count++; - } - else - { - /* No this is a new address or value or operation. Were there any - * duplicate accesses before this one? - */ - - if (count > 0) - { - /* Yes.. Just one? */ - - if (count == 1) - { - /* Yes.. Just one */ - - stm32_printreg(prevaddr, preval, prevwrite); - } - else - { - /* No.. More than one. */ - - lldbg("[repeats %d more times]\n", count); - } - } - - /* Save the new address, value, count, and operation for next time */ - - prevaddr = addr; - preval = val; - count = 0; - prevwrite = iswrite; - - /* Show the new regisgter access */ - - stm32_printreg(addr, val, iswrite); - } -} -#endif - -/******************************************************************************* - * Name: stm32_getreg - * - * Description: - * Get the contents of an STM32 register - * - *******************************************************************************/ - -#ifdef CONFIG_STM32_USBHOST_REGDEBUG -static uint32_t stm32_getreg(uint32_t addr) -{ - /* Read the value from the register */ - - uint32_t val = getreg32(addr); - - /* Check if we need to print this value */ - - stm32_checkreg(addr, val, false); - return val; -} -#endif - -/******************************************************************************* - * Name: stm32_putreg - * - * Description: - * Set the contents of an STM32 register to a value - * - *******************************************************************************/ - -#ifdef CONFIG_STM32_USBHOST_REGDEBUG -static void stm32_putreg(uint32_t val, uint32_t addr) -{ - /* Check if we need to print this value */ - - stm32_checkreg(addr, val, true); - - /* Write the value */ - - putreg32(val, addr); -} -#endif - -/**************************************************************************** - * Name: stm32_takesem - * - * Description: - * This is just a wrapper to handle the annoying behavior of semaphore - * waits that return due to the receipt of a signal. - * - *******************************************************************************/ - -static void stm32_takesem(sem_t *sem) -{ - /* Take the semaphore (perhaps waiting) */ - - while (sem_wait(sem) != 0) - { - /* The only case that an error should occr here is if the wait was - * awakened by a signal. - */ - - ASSERT(errno == EINTR); - } -} - -/**************************************************************************** - * Name: stm32_getle16 - * - * Description: - * Get a (possibly unaligned) 16-bit little endian value. - * - *******************************************************************************/ - -static inline uint16_t stm32_getle16(const uint8_t *val) -{ - return (uint16_t)val[1] << 8 | (uint16_t)val[0]; -} - -/**************************************************************************** - * Name: stm32_putle16 - * - * Description: - * Put a (possibly unaligned) 16-bit little endian value. - * - *******************************************************************************/ - -static void stm32_putle16(uint8_t *dest, uint16_t val) -{ - dest[0] = val & 0xff; /* Little endian means LS byte first in byte stream */ - dest[1] = val >> 8; -} - -/******************************************************************************* - * Name: stm32_edfree - * - * Description: - * Return an endpoint descriptor to the free list - * - *******************************************************************************/ - -static inline void stm32_edfree(struct stm32_ed_s *ed) -{ - struct stm32_list_s *entry = (struct stm32_list_s *)ed; - - /* Put the ED back into the free list */ - - entry->flink = g_edfree; - g_edfree = entry; -} - -/******************************************************************************* - * Name: stm32_tdalloc - * - * Description: - * Allocate an transfer descriptor from the free list - * - * Assumptions: - * - Never called from an interrupt handler. - * - Protected from conconcurrent access to the TD pool by the interrupt - * handler - * - Protection from re-entrance must be assured by the caller - * - *******************************************************************************/ - -static struct stm32_gtd_s *stm32_tdalloc(void) -{ - struct stm32_gtd_s *ret; - irqstate_t flags; - - /* Disable interrupts momentarily so that stm32_tdfree is not called from the - * interrupt handler. - */ - - flags = irqsave(); - ret = (struct stm32_gtd_s *)g_tdfree; - if (ret) - { - g_tdfree = ((struct stm32_list_s*)ret)->flink; - } - - irqrestore(flags); - return ret; -} - -/******************************************************************************* - * Name: stm32_tdfree - * - * Description: - * Return an transfer descriptor to the free list - * - * Assumptions: - * - Only called from the WDH interrupt handler (and during initialization). - * - Interrupts are disabled in any case. - * - *******************************************************************************/ - -static void stm32_tdfree(struct stm32_gtd_s *td) -{ - struct stm32_list_s *tdfree = (struct stm32_list_s *)td; - - /* This should not happen but just to be safe, don't free the common, pre- - * allocated tail TD. - */ - - if (tdfree != NULL && td != TDTAIL) - { - tdfree->flink = g_tdfree; - g_tdfree = tdfree; - } -} - -/******************************************************************************* - * Name: stm32_tballoc - * - * Description: - * Allocate an request/descriptor transfer buffer from the free list - * - * Assumptions: - * - Never called from an interrupt handler. - * - Protection from re-entrance must be assured by the caller - * - *******************************************************************************/ - -static uint8_t *stm32_tballoc(void) -{ - uint8_t *ret = (uint8_t *)g_tbfree; - if (ret) - { - g_tbfree = ((struct stm32_list_s*)ret)->flink; - } - return ret; -} - -/******************************************************************************* - * Name: stm32_tbfree - * - * Description: - * Return an request/descriptor transfer buffer to the free list - * - *******************************************************************************/ - -static void stm32_tbfree(uint8_t *buffer) -{ - struct stm32_list_s *tbfree = (struct stm32_list_s *)buffer; - - if (tbfree) - { - tbfree->flink = g_tbfree; - g_tbfree = tbfree; - } -} - -/******************************************************************************* - * Name: stm32_allocio - * - * Description: - * Allocate an IO buffer from the free list - * - * Assumptions: - * - Never called from an interrupt handler. - * - Protection from re-entrance must be assured by the caller - * - *******************************************************************************/ - -#if STM32_IOBUFFERS > 0 -static uint8_t *stm32_allocio(void) -{ - uint8_t *ret = (uint8_t *)g_iofree; - if (ret) - { - g_iofree = ((struct stm32_list_s*)ret)->flink; - } - return ret; -} -#endif - -/******************************************************************************* - * Name: stm32_freeio - * - * Description: - * Return an TD buffer to the free list - * - *******************************************************************************/ - -#if STM32_IOBUFFERS > 0 -static void stm32_freeio(uint8_t *buffer) -{ - struct stm32_list_s *iofree = (struct stm32_list_s *)buffer; - iofree->flink = g_iofree; - g_iofree = iofree; -} -#endif - -/******************************************************************************* - * Name: stm32_addbulked - * - * Description: - * Helper function to add an ED to the bulk list. - * - *******************************************************************************/ - -static inline int stm32_addbulked(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed) -{ -#ifndef CONFIG_USBHOST_BULK_DISABLE - uint32_t regval; - - /* Add the new bulk ED to the head of the bulk list */ - - ed->hw.nexted = stm32_getreg(STM32_USBHOST_BULKHEADED); - stm32_putreg((uint32_t)ed, STM32_USBHOST_BULKHEADED); - - /* BulkListEnable. This bit is set to enable the processing of the - * Bulk list. Note: once enabled, it remains. We really should - * never modify the bulk list while BLE is set. - */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval |= OHCI_CTRL_BLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); - return OK; -#else - return -ENOSYS; -#endif -} - -/******************************************************************************* - * Name: stm32_rembulked - * - * Description: - * Helper function remove an ED from the bulk list. - * - *******************************************************************************/ - -static inline int stm32_rembulked(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed) -{ -#ifndef CONFIG_USBHOST_BULK_DISABLE - struct stm32_ed_s *curr; - struct stm32_ed_s *prev; - uint32_t regval; - - /* Find the ED in the bulk list. NOTE: We really should never be mucking - * with the bulk list while BLE is set. - */ - - for (curr = (struct stm32_ed_s *)stm32_getreg(STM32_USBHOST_BULKHEADED), - prev = NULL; - curr && curr != ed; - prev = curr, curr = (struct stm32_ed_s *)curr->hw.nexted); - - /* Hmmm.. It would be a bug if we do not find the ED in the bulk list. */ - - DEBUGASSERT(curr != NULL); - - /* Remove the ED from the bulk list */ - - if (curr != NULL) - { - /* Is this ED the first on in the bulk list? */ - - if (prev == NULL) - { - /* Yes... set the head of the bulk list to skip over this ED */ - - stm32_putreg(ed->hw.nexted, STM32_USBHOST_BULKHEADED); - - /* If the bulk list is now empty, then disable it */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval &= ~OHCI_CTRL_BLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); - } - else - { - /* No.. set the forward link of the previous ED in the list - * skip over this ED. - */ - - prev->hw.nexted = ed->hw.nexted; - } - } - - return OK; -#else - return -ENOSYS; -#endif -} - -/******************************************************************************* - * Name: stm32_getinterval - * - * Description: - * Convert the endpoint polling interval into a HCCA table increment - * - *******************************************************************************/ - -#if !defined(CONFIG_USBHOST_INT_DISABLE) || !defined(CONFIG_USBHOST_ISOC_DISABLE) -static unsigned int stm32_getinterval(uint8_t interval) -{ - /* The bInterval field of the endpoint descriptor contains the polling interval - * for interrupt and isochronous endpoints. For other types of endpoint, this - * value should be ignored. bInterval is provided in units of 1MS frames. - */ - - if (interval < 3) - { - return 2; - } - else if (interval < 7) - { - return 4; - } - else if (interval < 15) - { - return 8; - } - else if (interval < 31) - { - return 16; - } - else - { - return 32; - } -} -#endif - -/******************************************************************************* - * Name: stm32_setinttab - * - * Description: - * Set the interrupt table to the selected value using the provided interval - * and offset. - * - *******************************************************************************/ - -#if !defined(CONFIG_USBHOST_INT_DISABLE) || !defined(CONFIG_USBHOST_ISOC_DISABLE) -static void stm32_setinttab(uint32_t value, unsigned int interval, unsigned int offset) -{ - unsigned int i; - for (i = offset; i < HCCA_INTTBL_WSIZE; i += interval) - { - HCCA->inttbl[i] = value; - } -} -#endif - -/******************************************************************************* - * Name: stm32_addinted - * - * Description: - * Helper function to add an ED to the HCCA interrupt table. - * - * To avoid reshuffling the table so much and to keep life simple in general, - * the following rules are applied: - * - * 1. IN EDs get the even entries, OUT EDs get the odd entries. - * 2. Add IN/OUT EDs are scheduled together at the minimum interval of all - * IN/OUT EDs. - * - * This has the following consequences: - * - * 1. The minimum support polling rate is 2MS, and - * 2. Some devices may get polled at a much higher rate than they request. - * - *******************************************************************************/ - -static inline int stm32_addinted(struct stm32_usbhost_s *priv, - const FAR struct usbhost_epdesc_s *epdesc, - struct stm32_ed_s *ed) -{ -#ifndef CONFIG_USBHOST_INT_DISABLE - unsigned int interval; - unsigned int offset; - uint32_t head; - uint32_t regval; - - /* Disable periodic list processing. Does this take effect immediately? Or - * at the next SOF... need to check. - */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval &= ~OHCI_CTRL_PLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); - - /* Get the quanitized interval value associated with this ED and save it - * in the ED. - */ - - interval = stm32_getinterval(epdesc->interval); - ed->interval = interval; - uvdbg("interval: %d->%d\n", epdesc->interval, interval); - - /* Get the offset associated with the ED direction. IN EDs get the even - * entries, OUT EDs get the odd entries. - * - * Get the new, minimum interval. Add IN/OUT EDs are scheduled together - * at the minimum interval of all IN/OUT EDs. - */ - - if (epdesc->in) - { - offset = 0; - if (priv->ininterval > interval) - { - priv->ininterval = interval; - } - else - { - interval = priv->ininterval; - } - } - else - { - offset = 1; - if (priv->outinterval > interval) - { - priv->outinterval = interval; - } - else - { - interval = priv->outinterval; - } - } - uvdbg("min interval: %d offset: %d\n", interval, offset); - - /* Get the head of the first of the duplicated entries. The first offset - * entry is always guaranteed to contain the common ED list head. - */ - - head = HCCA->inttbl[offset]; - - /* Clear all current entries in the interrupt table for this direction */ - - stm32_setinttab(0, 2, offset); - - /* Add the new ED before the old head of the periodic ED list and set the - * new ED as the head ED in all of the appropriate entries of the HCCA - * interrupt table. - */ - - ed->hw.nexted = head; - stm32_setinttab((uint32_t)ed, interval, offset); - uvdbg("head: %08x next: %08x\n", ed, head); - - /* Re-enabled periodic list processing */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval |= OHCI_CTRL_PLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); - return OK; -#else - return -ENOSYS; -#endif -} - -/******************************************************************************* - * Name: stm32_reminted - * - * Description: - * Helper function to remove an ED from the HCCA interrupt table. - * - * To avoid reshuffling the table so much and to keep life simple in general, - * the following rules are applied: - * - * 1. IN EDs get the even entries, OUT EDs get the odd entries. - * 2. Add IN/OUT EDs are scheduled together at the minimum interval of all - * IN/OUT EDs. - * - * This has the following consequences: - * - * 1. The minimum support polling rate is 2MS, and - * 2. Some devices may get polled at a much higher rate than they request. - * - *******************************************************************************/ - -static inline int stm32_reminted(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed) -{ -#ifndef CONFIG_USBHOST_INT_DISABLE - struct stm32_ed_s *head; - struct stm32_ed_s *curr; - struct stm32_ed_s *prev; - unsigned int interval; - unsigned int offset; - uint32_t regval; - - /* Disable periodic list processing. Does this take effect immediately? Or - * at the next SOF... need to check. - */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval &= ~OHCI_CTRL_PLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); - - /* Get the offset associated with the ED direction. IN EDs get the even - * entries, OUT EDs get the odd entries. - */ - - if ((ed->hw.ctrl & ED_CONTROL_D_MASK) == ED_CONTROL_D_IN) - { - offset = 0; - } - else - { - offset = 1; - } - - /* Get the head of the first of the duplicated entries. The first offset - * entry is always guaranteed to contain the common ED list head. - */ - - head = (struct stm32_ed_s *)HCCA->inttbl[offset]; - uvdbg("ed: %08x head: %08x next: %08x offset: %d\n", - ed, head, head ? head->hw.nexted : 0, offset); - - /* Find the ED to be removed in the ED list */ - - for (curr = head, prev = NULL; - curr && curr != ed; - prev = curr, curr = (struct stm32_ed_s *)curr->hw.nexted); - - /* Hmmm.. It would be a bug if we do not find the ED in the bulk list. */ - - DEBUGASSERT(curr != NULL); - if (curr != NULL) - { - /* Clear all current entries in the interrupt table for this direction */ - - stm32_setinttab(0, 2, offset); - - /* Remove the ED from the list.. Is this ED the first on in the list? */ - - if (prev == NULL) - { - /* Yes... set the head of the bulk list to skip over this ED */ - - head = (struct stm32_ed_s *)ed->hw.nexted; - } - else - { - /* No.. set the forward link of the previous ED in the list - * skip over this ED. - */ - - prev->hw.nexted = ed->hw.nexted; - } - uvdbg("ed: %08x head: %08x next: %08x\n", - ed, head, head ? head->hw.nexted : 0); - - /* Calculate the new minimum interval for this list */ - - interval = MAX_PERINTERVAL; - for (curr = head; curr; curr = (struct stm32_ed_s *)curr->hw.nexted) - { - if (curr->interval < interval) - { - interval = curr->interval; - } - } - uvdbg("min interval: %d offset: %d\n", interval, offset); - - /* Save the new minimum interval */ - - if ((ed->hw.ctrl && ED_CONTROL_D_MASK) == ED_CONTROL_D_IN) - { - priv->ininterval = interval; - } - else - { - priv->outinterval = interval; - } - - /* Set the head ED in all of the appropriate entries of the HCCA interrupt - * table (head might be NULL). - */ - - stm32_setinttab((uint32_t)head, interval, offset); - } - - /* Re-enabled periodic list processing */ - - if (head != NULL) - { - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval |= OHCI_CTRL_PLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); - } - - return OK; -#else - return -ENOSYS; -#endif -} - -/******************************************************************************* - * Name: stm32_addisoced - * - * Description: - * Helper functions to add an ED to the periodic table. - * - *******************************************************************************/ - -static inline int stm32_addisoced(struct stm32_usbhost_s *priv, - const FAR struct usbhost_epdesc_s *epdesc, - struct stm32_ed_s *ed) -{ -#ifndef CONFIG_USBHOST_ISOC_DISABLE -# warning "Isochronous endpoints not yet supported" -#endif - return -ENOSYS; - -} - -/******************************************************************************* - * Name: stm32_remisoced - * - * Description: - * Helper functions to remove an ED from the periodic table. - * - *******************************************************************************/ - -static inline int stm32_remisoced(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed) -{ -#ifndef CONFIG_USBHOST_ISOC_DISABLE -# warning "Isochronous endpoints not yet supported" -#endif - return -ENOSYS; -} - -/******************************************************************************* - * Name: stm32_enqueuetd - * - * Description: - * Enqueue a transfer descriptor. Notice that this function only supports - * queue on TD per ED. - * - *******************************************************************************/ - -static int stm32_enqueuetd(struct stm32_usbhost_s *priv, - struct stm32_ed_s *ed, uint32_t dirpid, - uint32_t toggle, volatile uint8_t *buffer, size_t buflen) -{ - struct stm32_gtd_s *td; - int ret = -ENOMEM; - - /* Allocate a TD from the free list */ - - td = stm32_tdalloc(); - if (td != NULL) - { - /* Initialize the allocated TD and link it before the common tail TD. */ - - td->hw.ctrl = (GTD_STATUS_R | dirpid | TD_DELAY(0) | toggle | GTD_STATUS_CC_MASK); - TDTAIL->hw.ctrl = 0; - td->hw.cbp = (uint32_t)buffer; - TDTAIL->hw.cbp = 0; - td->hw.nexttd = (uint32_t)TDTAIL; - TDTAIL->hw.nexttd = 0; - td->hw.be = (uint32_t)(buffer + (buflen - 1)); - TDTAIL->hw.be = 0; - - /* Configure driver-only fields in the extended TD structure */ - - td->ed = ed; - - /* Link the td to the head of the ED's TD list */ - - ed->hw.headp = (uint32_t)td | ((ed->hw.headp) & ED_HEADP_C); - ed->hw.tailp = (uint32_t)TDTAIL; - - ret = OK; - } - - return ret; -} - -/******************************************************************************* - * Name: stm32_wdhwait - * - * Description: - * Set the request for the Writeback Done Head event well BEFORE enabling the - * transfer (as soon as we are absolutely committed to the to avoid transfer). - * We do this to minimize race conditions. This logic would have to be expanded - * if we want to have more than one packet in flight at a time! - * - *******************************************************************************/ - -static int stm32_wdhwait(struct stm32_usbhost_s *priv, struct stm32_ed_s *ed) -{ - irqstate_t flags = irqsave(); - int ret = -ENODEV; - - /* Is the device still connected? */ - - if (priv->connected) - { - /* Yes.. then set wdhwait to indicate that we expect to be informed when - * either (1) the device is disconnected, or (2) the transfer completed. - */ - - ed->wdhwait = true; - ret = OK; - } - - irqrestore(flags); - return ret; -} - -/******************************************************************************* - * Name: stm32_ctrltd - * - * Description: - * Process a IN or OUT request on the control endpoint. This function - * will enqueue the request and wait for it to complete. Only one transfer - * may be queued; Neither these methods nor the transfer() method can be - * called again until the control transfer functions returns. - * - * These are blocking methods; these functions will not return until the - * control transfer has completed. - * - *******************************************************************************/ - -static int stm32_ctrltd(struct stm32_usbhost_s *priv, uint32_t dirpid, - uint8_t *buffer, size_t buflen) -{ - uint32_t toggle; - uint32_t regval; - int ret; - - /* Set the request for the Writeback Done Head event well BEFORE enabling the - * transfer. - */ - - ret = stm32_wdhwait(priv, EDCTRL); - if (ret != OK) - { - udbg("ERROR: Device disconnected\n"); - return ret; - } - - /* Configure the toggle field in the TD */ - - if (dirpid == GTD_STATUS_DP_SETUP) - { - toggle = GTD_STATUS_T_DATA0; - } - else - { - toggle = GTD_STATUS_T_DATA1; - } - - /* Then enqueue the transfer */ - - EDCTRL->tdstatus = TD_CC_NOERROR; - ret = stm32_enqueuetd(priv, EDCTRL, dirpid, toggle, buffer, buflen); - if (ret == OK) - { - /* Set ControlListFilled. This bit is used to indicate whether there are - * TDs on the Control list. - */ - - regval = stm32_getreg(STM32_USBHOST_CMDST); - regval |= OHCI_CMDST_CLF; - stm32_putreg(regval, STM32_USBHOST_CMDST); - - /* Wait for the Writeback Done Head interrupt */ - - stm32_takesem(&EDCTRL->wdhsem); - - /* Check the TD completion status bits */ - - if (EDCTRL->tdstatus == TD_CC_NOERROR) - { - ret = OK; - } - else - { - uvdbg("Bad TD completion status: %d\n", EDCTRL->tdstatus); - ret = -EIO; - } - } - - /* Make sure that there is no outstanding request on this endpoint */ - - EDCTRL->wdhwait = false; - return ret; -} - -/******************************************************************************* - * Name: stm32_usbinterrupt - * - * Description: - * USB interrupt handler - * - *******************************************************************************/ - -static int stm32_usbinterrupt(int irq, FAR void *context) -{ - struct stm32_usbhost_s *priv = &g_usbhost; - uint32_t intst; - uint32_t pending; - uint32_t regval; - - /* Read Interrupt Status and mask out interrupts that are not enabled. */ - - intst = stm32_getreg(STM32_USBHOST_INTST); - regval = stm32_getreg(STM32_USBHOST_INTEN); - ullvdbg("INST: %08x INTEN: %08x\n", intst, regval); - - pending = intst & regval; - if (pending != 0) - { - /* Root hub status change interrupt */ - - if ((pending & OHCI_INT_RHSC) != 0) - { - uint32_t rhportst1 = stm32_getreg(STM32_USBHOST_RHPORTST1); - ullvdbg("Root Hub Status Change, RHPORTST1: %08x\n", rhportst1); - - if ((rhportst1 & OHCI_RHPORTST_CSC) != 0) - { - uint32_t rhstatus = stm32_getreg(STM32_USBHOST_RHSTATUS); - ullvdbg("Connect Status Change, RHSTATUS: %08x\n", rhstatus); - - /* If DRWE is set, Connect Status Change indicates a remote wake-up event */ - - if (rhstatus & OHCI_RHSTATUS_DRWE) - { - ullvdbg("DRWE: Remote wake-up\n"); - } - - /* Otherwise... Not a remote wake-up event */ - - else - { - /* Check current connect status */ - - if ((rhportst1 & OHCI_RHPORTST_CCS) != 0) - { - /* Connected ... Did we just become connected? */ - - if (!priv->connected) - { - /* Yes.. connected. */ - - ullvdbg("Connected\n"); - priv->connected = true; - - /* Notify any waiters */ - - if (priv->rhswait) - { - stm32_givesem(&priv->rhssem); - priv->rhswait = false; - } - } - else - { - ulldbg("Spurious status change (connected)\n"); - } - - /* The LSDA (Low speed device attached) bit is valid - * when CCS == 1. - */ - - priv->lowspeed = (rhportst1 & OHCI_RHPORTST_LSDA) != 0; - ullvdbg("Speed:%s\n", priv->lowspeed ? "LOW" : "FULL"); - } - - /* Check if we are now disconnected */ - - else if (priv->connected) - { - /* Yes.. disconnect the device */ - - ullvdbg("Disconnected\n"); - priv->connected = false; - priv->lowspeed = false; - - /* Are we bound to a class instance? */ - - if (priv->class) - { - /* Yes.. Disconnect the class */ - - CLASS_DISCONNECTED(priv->class); - priv->class = NULL; - } - - /* Notify any waiters for the Root Hub Status change event */ - - if (priv->rhswait) - { - stm32_givesem(&priv->rhssem); - priv->rhswait = false; - } - } - else - { - ulldbg("Spurious status change (disconnected)\n"); - } - } - - /* Clear the status change interrupt */ - - stm32_putreg(OHCI_RHPORTST_CSC, STM32_USBHOST_RHPORTST1); - } - - /* Check for port reset status change */ - - if ((rhportst1 & OHCI_RHPORTST_PRSC) != 0) - { - /* Release the RH port from reset */ - - stm32_putreg(OHCI_RHPORTST_PRSC, STM32_USBHOST_RHPORTST1); - } - } - - /* Writeback Done Head interrupt */ - - if ((pending & OHCI_INT_WDH) != 0) - { - struct stm32_gtd_s *td; - struct stm32_gtd_s *next; - - /* The host controller just wrote the list of finished TDs into the HCCA - * done head. This may include multiple packets that were transferred - * in the preceding frame. - * - * Remove the TD(s) from the Writeback Done Head in the HCCA and return - * them to the free list. Note that this is safe because the hardware - * will not modify the writeback done head again until the WDH bit is - * cleared in the interrupt status register. - */ - - td = (struct stm32_gtd_s *)HCCA->donehead; - HCCA->donehead = 0; - - /* Process each TD in the write done list */ - - for (; td; td = next) - { - /* Get the ED in which this TD was enqueued */ - - struct stm32_ed_s *ed = td->ed; - DEBUGASSERT(ed != NULL); - - /* Save the condition code from the (single) TD status/control - * word. - */ - - ed->tdstatus = (td->hw.ctrl & GTD_STATUS_CC_MASK) >> GTD_STATUS_CC_SHIFT; - -#ifdef CONFIG_DEBUG_USB - if (ed->tdstatus != TD_CC_NOERROR) - { - /* The transfer failed for some reason... dump some diagnostic info. */ - - ulldbg("ERROR: ED xfrtype:%d TD CTRL:%08x/CC:%d RHPORTST1:%08x\n", - ed->xfrtype, td->hw.ctrl, ed->tdstatus, - stm32_getreg(STM32_USBHOST_RHPORTST1)); - } -#endif - - /* Return the TD to the free list */ - - next = (struct stm32_gtd_s *)td->hw.nexttd; - stm32_tdfree(td); - - /* And wake up the thread waiting for the WDH event */ - - if (ed->wdhwait) - { - stm32_givesem(&ed->wdhsem); - ed->wdhwait = false; - } - } - } - -#ifdef CONFIG_DEBUG_USB - if ((pending & STM32_DEBUG_INTS) != 0) - { - ulldbg("ERROR: Unhandled interrupts INTST:%08x\n", intst); - } -#endif - - /* Clear interrupt status register */ - - stm32_putreg(intst, STM32_USBHOST_INTST); - } - - return OK; -} - -/******************************************************************************* - * USB Host Controller Operations - *******************************************************************************/ - -/******************************************************************************* - * Name: stm32_wait - * - * Description: - * Wait for a device to be connected or disconneced. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * connected - TRUE: Wait for device to be connected; FALSE: wait for device - * to be disconnected - * - * Returned Values: - * Zero (OK) is returned when a device in connected. This function will not - * return until either (1) a device is connected or (2) some failure occurs. - * On a failure, a negated errno value is returned indicating the nature of - * the failure - * - * Assumptions: - * - Called from a single thread so no mutual exclusion is required. - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static int stm32_wait(FAR struct usbhost_driver_s *drvr, bool connected) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - irqstate_t flags; - - /* Are we already connected? */ - - flags = irqsave(); - while (priv->connected == connected) - { - /* No... wait for the connection/disconnection */ - - priv->rhswait = true; - stm32_takesem(&priv->rhssem); - } - irqrestore(flags); - - udbg("Connected:%s\n", priv->connected ? "YES" : "NO"); - return OK; -} - -/******************************************************************************* - * Name: stm32_enumerate - * - * Description: - * Enumerate the connected device. As part of this enumeration process, - * the driver will (1) get the device's configuration descriptor, (2) - * extract the class ID info from the configuration descriptor, (3) call - * usbhost_findclass() to find the class that supports this device, (4) - * call the create() method on the struct usbhost_registry_s interface - * to get a class instance, and finally (5) call the configdesc() method - * of the struct usbhost_class_s interface. After that, the class is in - * charge of the sequence of operations. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * - Only a single class bound to a single device is supported. - * - Called from a single thread so no mutual exclusion is required. - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static int stm32_enumerate(FAR struct usbhost_driver_s *drvr) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - - /* Are we connected to a device? The caller should have called the wait() - * method first to be assured that a device is connected. - */ - - while (!priv->connected) - { - /* No, return an error */ - - udbg("Not connected\n"); - return -ENODEV; - } - - /* USB 2.0 spec says at least 50ms delay before port reset */ - - up_mdelay(100); - - /* Put RH port 1 in reset (the STM32 supports only a single downstream port) */ - - stm32_putreg(OHCI_RHPORTST_PRS, STM32_USBHOST_RHPORTST1); - - /* Wait for the port reset to complete */ - - while ((stm32_getreg(STM32_USBHOST_RHPORTST1) & OHCI_RHPORTST_PRS) != 0); - - /* Release RH port 1 from reset and wait a bit */ - - stm32_putreg(OHCI_RHPORTST_PRSC, STM32_USBHOST_RHPORTST1); - up_mdelay(200); - - /* Let the common usbhost_enumerate do all of the real work. Note that the - * FunctionAddress (USB address) is hardcoded to one. - */ - - uvdbg("Enumerate the device\n"); - return usbhost_enumerate(drvr, 1, &priv->class); -} - -/************************************************************************************ - * Name: stm32_ep0configure - * - * Description: - * Configure endpoint 0. This method is normally used internally by the - * enumerate() method but is made available at the interface to support - * an external implementation of the enumeration logic. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * funcaddr - The USB address of the function containing the endpoint that EP0 - * controls - * maxpacketsize - The maximum number of bytes that can be sent to or - * received from the endpoint in a single data packet - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * This function will *not* be called from an interrupt handler. - * - ************************************************************************************/ - -static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, - uint16_t maxpacketsize) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - - DEBUGASSERT(drvr && funcaddr < 128 && maxpacketsize < 2048); - - /* We must have exclusive access to EP0 and the control list */ - - stm32_takesem(&priv->exclsem); - - /* Set the EP0 ED control word */ - - EDCTRL->hw.ctrl = (uint32_t)funcaddr << ED_CONTROL_FA_SHIFT | - (uint32_t)maxpacketsize << ED_CONTROL_MPS_SHIFT; - - if (priv->lowspeed) - { - EDCTRL->hw.ctrl |= ED_CONTROL_S; - } - - /* Set the transfer type to control */ - - EDCTRL->xfrtype = USB_EP_ATTR_XFER_CONTROL; - stm32_givesem(&priv->exclsem); - - uvdbg("EP0 CTRL:%08x\n", EDCTRL->hw.ctrl); - return OK; -} - -/************************************************************************************ - * Name: stm32_epalloc - * - * Description: - * Allocate and configure one endpoint. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * epdesc - Describes the endpoint to be allocated. - * ep - A memory location provided by the caller in which to receive the - * allocated endpoint desciptor. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * This function will *not* be called from an interrupt handler. - * - ************************************************************************************/ - -static int stm32_epalloc(FAR struct usbhost_driver_s *drvr, - const FAR struct usbhost_epdesc_s *epdesc, usbhost_ep_t *ep) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - struct stm32_ed_s *ed; - int ret = -ENOMEM; - - /* Sanity check. NOTE that this method should only be called if a device is - * connected (because we need a valid low speed indication). - */ - - DEBUGASSERT(priv && epdesc && ep && priv->connected); - - /* We must have exclusive access to the ED pool, the bulk list, the periodic list - * and the interrupt table. - */ - - stm32_takesem(&priv->exclsem); - - /* Take the next ED from the beginning of the free list */ - - ed = (struct stm32_ed_s *)g_edfree; - if (ed) - { - /* Remove the ED from the freelist */ - - g_edfree = ((struct stm32_list_s*)ed)->flink; - - /* Configure the endpoint descriptor. */ - - memset((void*)ed, 0, sizeof(struct stm32_ed_s)); - ed->hw.ctrl = (uint32_t)(epdesc->funcaddr) << ED_CONTROL_FA_SHIFT | - (uint32_t)(epdesc->addr) << ED_CONTROL_EN_SHIFT | - (uint32_t)(epdesc->mxpacketsize) << ED_CONTROL_MPS_SHIFT; - - /* Get the direction of the endpoint */ - - if (epdesc->in) - { - ed->hw.ctrl |= ED_CONTROL_D_IN; - } - else - { - ed->hw.ctrl |= ED_CONTROL_D_OUT; - } - - /* Check for a low-speed device */ - - if (priv->lowspeed) - { - ed->hw.ctrl |= ED_CONTROL_S; - } - - /* Set the transfer type */ - - ed->xfrtype = epdesc->xfrtype; - - /* Special Case isochronous transfer types */ - -#if 0 /* Isochronous transfers not yet supported */ - if (ed->xfrtype == USB_EP_ATTR_XFER_ISOC) - { - ed->hw.ctrl |= ED_CONTROL_F; - } -#endif - uvdbg("EP%d CTRL:%08x\n", epdesc->addr, ed->hw.ctrl); - - /* Initialize the semaphore that is used to wait for the endpoint - * WDH event. - */ - - sem_init(&ed->wdhsem, 0, 0); - - /* Link the common tail TD to the ED's TD list */ - - ed->hw.headp = (uint32_t)TDTAIL; - ed->hw.tailp = (uint32_t)TDTAIL; - - /* Now add the endpoint descriptor to the appropriate list */ - - switch (ed->xfrtype) - { - case USB_EP_ATTR_XFER_BULK: - ret = stm32_addbulked(priv, ed); - break; - - case USB_EP_ATTR_XFER_INT: - ret = stm32_addinted(priv, epdesc, ed); - break; - - case USB_EP_ATTR_XFER_ISOC: - ret = stm32_addisoced(priv, epdesc, ed); - break; - - case USB_EP_ATTR_XFER_CONTROL: - default: - ret = -EINVAL; - break; - } - - /* Was the ED successfully added? */ - - if (ret != OK) - { - /* No.. destroy it and report the error */ - - udbg("ERROR: Failed to queue ED for transfer type: %d\n", ed->xfrtype); - sem_destroy(&ed->wdhsem); - stm32_edfree(ed); - } - else - { - /* Yes.. return an opaque reference to the ED */ - - *ep = (usbhost_ep_t)ed; - } - } - - stm32_givesem(&priv->exclsem); - return ret; -} - -/************************************************************************************ - * Name: stm32_epfree - * - * Description: - * Free and endpoint previously allocated by DRVR_EPALLOC. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * ep - The endpint to be freed. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * This function will *not* be called from an interrupt handler. - * - ************************************************************************************/ - -static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - struct stm32_ed_s *ed = (struct stm32_ed_s *)ep; - int ret; - - /* There should not be any pending, real TDs linked to this ED */ - - DEBUGASSERT(ed && (ed->hw.headp & ED_HEADP_ADDR_MASK) == STM32_TDTAIL_ADDR); - - /* We must have exclusive access to the ED pool, the bulk list, the periodic list - * and the interrupt table. - */ - - stm32_takesem(&priv->exclsem); - - /* Remove the ED to the correct list depending on the trasfer type */ - - switch (ed->xfrtype) - { - case USB_EP_ATTR_XFER_BULK: - ret = stm32_rembulked(priv, ed); - break; - - case USB_EP_ATTR_XFER_INT: - ret = stm32_reminted(priv, ed); - break; - - case USB_EP_ATTR_XFER_ISOC: - ret = stm32_remisoced(priv, ed); - break; - - case USB_EP_ATTR_XFER_CONTROL: - default: - ret = -EINVAL; - break; - } - - /* Destroy the semaphore */ - - sem_destroy(&ed->wdhsem); - - /* Put the ED back into the free list */ - - stm32_edfree(ed); - stm32_givesem(&priv->exclsem); - return ret; -} - -/******************************************************************************* - * Name: stm32_alloc - * - * Description: - * Some hardware supports special memory in which request and descriptor data can - * be accessed more efficiently. This method provides a mechanism to allocate - * the request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to malloc. - * - * This interface was optimized under a particular assumption. It was assumed - * that the driver maintains a pool of small, pre-allocated buffers for descriptor - * traffic. NOTE that size is not an input, but an output: The size of the - * pre-allocated buffer is returned. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * buffer - The address of a memory location provided by the caller in which to - * return the allocated buffer memory address. - * maxlen - The address of a memory location provided by the caller in which to - * return the maximum size of the allocated buffer memory. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * - Called from a single thread so no mutual exclusion is required. - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static int stm32_alloc(FAR struct usbhost_driver_s *drvr, - FAR uint8_t **buffer, FAR size_t *maxlen) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - DEBUGASSERT(priv && buffer && maxlen); - int ret = -ENOMEM; - - /* We must have exclusive access to the transfer buffer pool */ - - stm32_takesem(&priv->exclsem); - - *buffer = stm32_tballoc(); - if (*buffer) - { - *maxlen = CONFIG_USBHOST_TDBUFSIZE; - ret = OK; - } - - stm32_givesem(&priv->exclsem); - return ret; -} - -/******************************************************************************* - * Name: stm32_free - * - * Description: - * Some hardware supports special memory in which request and descriptor data can - * be accessed more efficiently. This method provides a mechanism to free that - * request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to free(). - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * buffer - The address of the allocated buffer memory to be freed. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - DEBUGASSERT(buffer); - - /* We must have exclusive access to the transfer buffer pool */ - - stm32_takesem(&priv->exclsem); - stm32_tbfree(buffer); - stm32_givesem(&priv->exclsem); - return OK; -} - -/************************************************************************************ - * Name: stm32_ioalloc - * - * Description: - * Some hardware supports special memory in which larger IO buffers can - * be accessed more efficiently. This method provides a mechanism to allocate - * the request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to malloc. - * - * This interface differs from DRVR_ALLOC in that the buffers are variable-sized. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * buffer - The address of a memory location provided by the caller in which to - * return the allocated buffer memory address. - * buflen - The size of the buffer required. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * This function will *not* be called from an interrupt handler. - * - ************************************************************************************/ - -static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr, - FAR uint8_t **buffer, size_t buflen) -{ - DEBUGASSERT(drvr && buffer); - -#if STM32_IOBUFFERS > 0 - if (buflen <= CONFIG_USBHOST_IOBUFSIZE) - { - FAR uint8_t *alloc = stm32_allocio(); - if (alloc) - { - *buffer = alloc; - return OK; - } - } - return -ENOMEM; -#else - return -ENOSYS; -#endif -} - -/************************************************************************************ - * Name: stm32_iofree - * - * Description: - * Some hardware supports special memory in which IO data can be accessed more - * efficiently. This method provides a mechanism to free that IO buffer - * memory. If the underlying hardware does not support such "special" memory, - * this functions may simply map to free(). - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * buffer - The address of the allocated buffer memory to be freed. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * This function will *not* be called from an interrupt handler. - * - ************************************************************************************/ - -static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer) -{ - DEBUGASSERT(drvr && buffer); - -#if STM32_IOBUFFERS > 0 - stm32_freeio(buffer); - return OK; -#else - return -ENOSYS; -#endif -} - -/******************************************************************************* - * Name: stm32_ctrlin and stm32_ctrlout - * - * Description: - * Process a IN or OUT request on the control endpoint. These methods - * will enqueue the request and wait for it to complete. Only one transfer may be - * queued; Neither these methods nor the transfer() method can be called again - * until the control transfer functions returns. - * - * These are blocking methods; these functions will not return until the - * control transfer has completed. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * req - Describes the request to be sent. This request must lie in memory - * created by DRVR_ALLOC. - * buffer - A buffer used for sending the request and for returning any - * responses. This buffer must be large enough to hold the length value - * in the request description. buffer must have been allocated using DRVR_ALLOC - * - * NOTE: On an IN transaction, req and buffer may refer to the same allocated - * memory. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * - Only a single class bound to a single device is supported. - * - Called from a single thread so no mutual exclusion is required. - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, - FAR const struct usb_ctrlreq_s *req, - FAR uint8_t *buffer) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - uint16_t len; - int ret; - - DEBUGASSERT(drvr && req); - uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n", - req->type, req->req, req->value[1], req->value[0], - req->index[1], req->index[0], req->len[1], req->len[0]); - - /* We must have exclusive access to EP0 and the control list */ - - stm32_takesem(&priv->exclsem); - - len = stm32_getle16(req->len); - ret = stm32_ctrltd(priv, GTD_STATUS_DP_SETUP, (uint8_t*)req, USB_SIZEOF_CTRLREQ); - if (ret == OK) - { - if (len) - { - ret = stm32_ctrltd(priv, GTD_STATUS_DP_IN, buffer, len); - } - - if (ret == OK) - { - ret = stm32_ctrltd(priv, GTD_STATUS_DP_OUT, NULL, 0); - } - } - - stm32_givesem(&priv->exclsem); - return ret; -} - -static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, - FAR const struct usb_ctrlreq_s *req, - FAR const uint8_t *buffer) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - uint16_t len; - int ret; - - DEBUGASSERT(drvr && req); - uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n", - req->type, req->req, req->value[1], req->value[0], - req->index[1], req->index[0], req->len[1], req->len[0]); - - /* We must have exclusive access to EP0 and the control list */ - - stm32_takesem(&priv->exclsem); - - len = stm32_getle16(req->len); - ret = stm32_ctrltd(priv, GTD_STATUS_DP_SETUP, (uint8_t*)req, USB_SIZEOF_CTRLREQ); - if (ret == OK) - { - if (len) - { - ret = stm32_ctrltd(priv, GTD_STATUS_DP_OUT, (uint8_t*)buffer, len); - } - - if (ret == OK) - { - ret = stm32_ctrltd(priv, GTD_STATUS_DP_IN, NULL, 0); - } - } - - stm32_givesem(&priv->exclsem); - return ret; -} - -/******************************************************************************* - * Name: stm32_transfer - * - * Description: - * Process a request to handle a transfer descriptor. This method will - * enqueue the transfer request and return immediately. Only one transfer may be - * queued; Neither this method nor the ctrlin or ctrlout methods can be called - * again until this function returns. - * - * This is a blocking method; this functions will not return until the - * transfer has completed. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * ep - The IN or OUT endpoint descriptor for the device endpoint on which to - * perform the transfer. - * buffer - A buffer containing the data to be sent (OUT endpoint) or received - * (IN endpoint). buffer must have been allocated using DRVR_ALLOC - * buflen - The length of the data to be sent or received. - * - * Returned Values: - * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure - * - * Assumptions: - * - Only a single class bound to a single device is supported. - * - Called from a single thread so no mutual exclusion is required. - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static int stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep, - FAR uint8_t *buffer, size_t buflen) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - struct stm32_ed_s *ed = (struct stm32_ed_s *)ep; - uint32_t dirpid; - uint32_t regval; -#if STM32_IOBUFFERS > 0 - uint8_t *origbuf = NULL; -#endif - bool in; - int ret; - - DEBUGASSERT(priv && ed && buffer && buflen > 0); - - in = (ed->hw.ctrl & ED_CONTROL_D_MASK) == ED_CONTROL_D_IN; - uvdbg("EP%d %s toggle:%d maxpacket:%d buflen:%d\n", - (ed->hw.ctrl & ED_CONTROL_EN_MASK) >> ED_CONTROL_EN_SHIFT, - in ? "IN" : "OUT", - (ed->hw.headp & ED_HEADP_C) != 0 ? 1 : 0, - (ed->hw.ctrl & ED_CONTROL_MPS_MASK) >> ED_CONTROL_MPS_SHIFT, - buflen); - - /* We must have exclusive access to the endpoint, the TD pool, the I/O buffer - * pool, the bulk and interrupt lists, and the HCCA interrupt table. - */ - - stm32_takesem(&priv->exclsem); - - /* Allocate an IO buffer if the user buffer does not lie in AHB SRAM */ - -#if STM32_IOBUFFERS > 0 - if ((uintptr_t)buffer < STM32_SRAM_BANK0 || - (uintptr_t)buffer >= (STM32_SRAM_BANK0 + STM32_BANK0_SIZE + STM32_BANK1_SIZE)) - { - /* Will the transfer fit in an IO buffer? */ - - if (buflen > CONFIG_USBHOST_IOBUFSIZE) - { - uvdbg("buflen (%d) > IO buffer size (%d)\n", - buflen, CONFIG_USBHOST_IOBUFSIZE); - ret = -ENOMEM; - goto errout; - } - - /* Allocate an IO buffer in AHB SRAM */ - - origbuf = buffer; - buffer = stm32_allocio(); - if (!buffer) - { - uvdbg("IO buffer allocation failed\n"); - ret = -ENOMEM; - goto errout; - } - - /* If this is an OUT transaction, copy the user data into the AHB - * SRAM IO buffer. Sad... so inefficient. But without exposing - * the AHB SRAM to the final, end-user client I don't know of any - * way around this copy. - */ - - if (!in) - { - memcpy(buffer, origbuf, buflen); - } - } -#endif - - /* Set the request for the Writeback Done Head event well BEFORE enabling the - * transfer. - */ - - ret = stm32_wdhwait(priv, ed); - if (ret != OK) - { - udbg("ERROR: Device disconnected\n"); - goto errout; - } - - /* Get the direction of the endpoint */ - - if (in) - { - dirpid = GTD_STATUS_DP_IN; - } - else - { - dirpid = GTD_STATUS_DP_OUT; - } - - /* Then enqueue the transfer */ - - ed->tdstatus = TD_CC_NOERROR; - ret = stm32_enqueuetd(priv, ed, dirpid, GTD_STATUS_T_TOGGLE, buffer, buflen); - if (ret == OK) - { - /* BulkListFilled. This bit is used to indicate whether there are any - * TDs on the Bulk list. - */ - - regval = stm32_getreg(STM32_USBHOST_CMDST); - regval |= OHCI_CMDST_BLF; - stm32_putreg(regval, STM32_USBHOST_CMDST); - - /* Wait for the Writeback Done Head interrupt */ - - stm32_takesem(&ed->wdhsem); - - /* Check the TD completion status bits */ - - if (ed->tdstatus == TD_CC_NOERROR) - { - ret = OK; - } - else - { - uvdbg("Bad TD completion status: %d\n", ed->tdstatus); - ret = -EIO; - } - } - -errout: - /* Make sure that there is no outstanding request on this endpoint */ - - ed->wdhwait = false; - - /* Free any temporary IO buffers */ - -#if STM32_IOBUFFERS > 0 - if (buffer && origbuf) - { - /* If this is an IN transaction, get the user data from the AHB - * SRAM IO buffer. Sad... so inefficient. But without exposing - * the AHB SRAM to the final, end-user client I don't know of any - * way around this copy. - */ - - if (in && ret == OK) - { - memcpy(origbuf, buffer, buflen); - } - - /* Then free the temporary I/O buffer */ - - stm32_freeio(buffer); - } -#endif - - stm32_givesem(&priv->exclsem); - return ret; -} - -/******************************************************************************* - * Name: stm32_disconnect - * - * Description: - * Called by the class when an error occurs and driver has been disconnected. - * The USB host driver should discard the handle to the class instance (it is - * stale) and not attempt any further interaction with the class driver instance - * (until a new instance is received from the create() method). The driver - * should not called the class' disconnected() method. - * - * Input Parameters: - * drvr - The USB host driver instance obtained as a parameter from the call to - * the class create() method. - * - * Returned Values: - * None - * - * Assumptions: - * - Only a single class bound to a single device is supported. - * - Never called from an interrupt handler. - * - *******************************************************************************/ - -static void stm32_disconnect(FAR struct usbhost_driver_s *drvr) -{ - struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr; - priv->class = NULL; -} - -/******************************************************************************* - * Initialization - *******************************************************************************/ -/******************************************************************************* - * Name: stm32_ep0init - * - * Description: - * Initialize ED for EP0, add it to the control ED list, and enable control - * transfers. - * - * Input Parameters: - * priv - private driver state instance. - * - * Returned Values: - * None - * - *******************************************************************************/ - -static inline void stm32_ep0init(struct stm32_usbhost_s *priv) -{ - uint32_t regval; - - /* Set up some default values */ - - (void)stm32_ep0configure(&priv->drvr, 1, 8); - - /* Initialize the common tail TD. */ - - memset(TDTAIL, 0, sizeof(struct stm32_gtd_s)); - TDTAIL->ed = EDCTRL; - - /* Link the common tail TD to the ED's TD list */ - - memset(EDCTRL, 0, sizeof(struct stm32_ed_s)); - EDCTRL->hw.headp = (uint32_t)TDTAIL; - EDCTRL->hw.tailp = (uint32_t)TDTAIL; - - /* Set the head of the control list to the EP0 EDCTRL (this would have to - * change if we want more than on control EP queued at a time). - */ - - stm32_putreg(STM32_EDCTRL_ADDR, STM32_USBHOST_CTRLHEADED); - - /* ControlListEnable. This bit is set to enable the processing of the - * Control list. Note: once enabled, it remains enabled and we may even - * complete list processing before we get the bit set. We really - * should never modify the control list while CLE is set. - */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval |= OHCI_CTRL_CLE; - stm32_putreg(regval, STM32_USBHOST_CTRL); -} - -/******************************************************************************* - * Public Functions - *******************************************************************************/ - -/******************************************************************************* - * Name: usbhost_initialize - * - * Description: - * Initialize USB host device controller hardware. - * - * Input Parameters: - * controller -- If the device supports more than USB host controller, then - * this identifies which controller is being intialized. Normally, this - * is just zero. - * - * Returned Value: - * And instance of the USB host interface. The controlling task should - * use this interface to (1) call the wait() method to wait for a device - * to be connected, and (2) call the enumerate() method to bind the device - * to a class driver. - * - * Assumptions: - * - This function should called in the initialization sequence in order - * to initialize the USB device functionality. - * - Class drivers should be initialized prior to calling this function. - * Otherwise, there is a race condition if the device is already connected. - * - *******************************************************************************/ - -FAR struct usbhost_driver_s *usbhost_initialize(int controller) -{ - struct stm32_usbhost_s *priv = &g_usbhost; - uint32_t regval; - uint8_t *buffer; - irqstate_t flags; - int i; - - /* Sanity checks. NOTE: If certain OS features are enabled, it may be - * necessary to increase the size of STM32_ED/TD_SIZE in stm32_ohciram.h - */ - - DEBUGASSERT(controller == 0); - DEBUGASSERT(sizeof(struct stm32_ed_s) <= STM32_ED_SIZE); - DEBUGASSERT(sizeof(struct stm32_gtd_s) <= STM32_TD_SIZE); - - /* Initialize the state data structure */ - - sem_init(&priv->rhssem, 0, 0); - sem_init(&priv->exclsem, 0, 1); - -#ifndef CONFIG_USBHOST_INT_DISABLE - priv->ininterval = MAX_PERINTERVAL; - priv->outinterval = MAX_PERINTERVAL; -#endif - - /* Enable power by setting PCUSB in the PCONP register. Disable interrupts - * because this register may be shared with other drivers. - */ - - flags = irqsave(); - regval = stm32_getreg(STM32_SYSCON_PCONP); - regval |= SYSCON_PCONP_PCUSB; - stm32_putreg(regval, STM32_SYSCON_PCONP); - irqrestore(flags); - - /* Enable clocking on USB (USB PLL clocking was initialized in very low- - * evel clock setup logic (see stm32_clockconfig.c)). We do still need - * to set up USBOTG CLKCTRL to enable clocking. - * - * NOTE: The PORTSEL clock needs to be enabled only when accessing OTGSTCTRL - */ - - stm32_putreg(STM32_CLKCTRL_ENABLES, STM32_USBOTG_CLKCTRL); - - /* Then wait for the clocks to be reported as "ON" */ - - do - { - regval = stm32_getreg(STM32_USBOTG_CLKST); - } - while ((regval & STM32_CLKCTRL_ENABLES) != STM32_CLKCTRL_ENABLES); - - /* Set the OTG status and control register. Bits 0:1 apparently mean: - * - * 00: U1=device, U2=host - * 01: U1=host, U2=host - * 10: reserved - * 11: U1=host, U2=device - * - * We need only select U1=host (Bit 0=1, Bit 1 is not used on STM32); - * NOTE: The PORTSEL clock needs to be enabled when accessing OTGSTCTRL - */ - - stm32_putreg(1, STM32_USBOTG_STCTRL); - - /* Now we can turn off the PORTSEL clock */ - - stm32_putreg((STM32_CLKCTRL_ENABLES & ~USBOTG_CLK_PORTSELCLK), STM32_USBOTG_CLKCTRL); - - /* Configure I/O pins */ - - usbhost_dumpgpio(); - stm32_configgpio(GPIO_USB_DP); /* Positive differential data */ - stm32_configgpio(GPIO_USB_DM); /* Negative differential data */ - stm32_configgpio(GPIO_USB_UPLED); /* GoodLink LED control signal */ - stm32_configgpio(GPIO_USB_PPWR); /* Port Power enable signal for USB port */ - stm32_configgpio(GPIO_USB_PWRD); /* Power Status for USB port (host power switch) */ - stm32_configgpio(GPIO_USB_OVRCR); /* USB port Over-Current status */ - usbhost_dumpgpio(); - - udbg("Initializing Host Stack\n"); - - /* Show AHB SRAM memory map */ - -#if 0 /* Useful if you have doubts about the layout */ - uvdbg("AHB SRAM:\n"); - uvdbg(" HCCA: %08x %d\n", STM32_HCCA_BASE, STM32_HCCA_SIZE); - uvdbg(" TDTAIL: %08x %d\n", STM32_TDTAIL_ADDR, STM32_TD_SIZE); - uvdbg(" EDCTRL: %08x %d\n", STM32_EDCTRL_ADDR, STM32_ED_SIZE); - uvdbg(" EDFREE: %08x %d\n", STM32_EDFREE_BASE, STM32_ED_SIZE); - uvdbg(" TDFREE: %08x %d\n", STM32_TDFREE_BASE, STM32_EDFREE_SIZE); - uvdbg(" TBFREE: %08x %d\n", STM32_TBFREE_BASE, STM32_TBFREE_SIZE); - uvdbg(" IOFREE: %08x %d\n", STM32_IOFREE_BASE, STM32_IOBUFFERS * CONFIG_USBHOST_IOBUFSIZE); -#endif - - /* Initialize all the TDs, EDs and HCCA to 0 */ - - memset((void*)HCCA, 0, sizeof(struct ohci_hcca_s)); - memset((void*)TDTAIL, 0, sizeof(struct ohci_gtd_s)); - memset((void*)EDCTRL, 0, sizeof(struct stm32_ed_s)); - sem_init(&EDCTRL->wdhsem, 0, 0); - - /* Initialize user-configurable EDs */ - - buffer = (uint8_t *)STM32_EDFREE_BASE; - for (i = 0; i < CONFIG_USBHOST_NEDS; i++) - { - /* Put the ED in a free list */ - - stm32_edfree((struct stm32_ed_s *)buffer); - buffer += STM32_ED_SIZE; - } - - /* Initialize user-configurable TDs */ - - buffer = (uint8_t *)STM32_TDFREE_BASE; - for (i = 0; i < CONFIG_USBHOST_NTDS; i++) - { - /* Put the ED in a free list */ - - stm32_tdfree((struct stm32_gtd_s *)buffer); - buffer += STM32_TD_SIZE; - } - - /* Initialize user-configurable request/descriptor transfer buffers */ - - buffer = (uint8_t *)STM32_TBFREE_BASE; - for (i = 0; i < CONFIG_USBHOST_TDBUFFERS; i++) - { - /* Put the TD buffer in a free list */ - - stm32_tbfree(buffer); - buffer += CONFIG_USBHOST_TDBUFSIZE; - } - -#if STM32_IOBUFFERS > 0 - /* Initialize user-configurable IO buffers */ - - buffer = (uint8_t *)STM32_IOFREE_BASE; - for (i = 0; i < STM32_IOBUFFERS; i++) - { - /* Put the IO buffer in a free list */ - - stm32_freeio(buffer); - buffer += CONFIG_USBHOST_IOBUFSIZE; - } -#endif - - /* Wait 50MS then perform hardware reset */ - - up_mdelay(50); - - stm32_putreg(0, STM32_USBHOST_CTRL); /* Hardware reset */ - stm32_putreg(0, STM32_USBHOST_CTRLHEADED); /* Initialize control list head to Zero */ - stm32_putreg(0, STM32_USBHOST_BULKHEADED); /* Initialize bulk list head to Zero */ - - /* Software reset */ - - stm32_putreg(OHCI_CMDST_HCR, STM32_USBHOST_CMDST); - - /* Write Fm interval (FI), largest data packet counter (FSMPS), and - * periodic start. - */ - - stm32_putreg(DEFAULT_FMINTERVAL, STM32_USBHOST_FMINT); - stm32_putreg(DEFAULT_PERSTART, STM32_USBHOST_PERSTART); - - /* Put HC in operational state */ - - regval = stm32_getreg(STM32_USBHOST_CTRL); - regval &= ~OHCI_CTRL_HCFS_MASK; - regval |= OHCI_CTRL_HCFS_OPER; - stm32_putreg(regval, STM32_USBHOST_CTRL); - - /* Set global power in HcRhStatus */ - - stm32_putreg(OHCI_RHSTATUS_SGP, STM32_USBHOST_RHSTATUS); - - /* Set HCCA base address */ - - stm32_putreg((uint32_t)HCCA, STM32_USBHOST_HCCA); - - /* Set up EP0 */ - - stm32_ep0init(priv); - - /* Clear pending interrupts */ - - regval = stm32_getreg(STM32_USBHOST_INTST); - stm32_putreg(regval, STM32_USBHOST_INTST); - - /* Enable OHCI interrupts */ - - stm32_putreg((STM32_ALL_INTS|OHCI_INT_MIE), STM32_USBHOST_INTEN); - - /* Attach USB host controller interrupt handler */ - - if (irq_attach(STM32_IRQ_USB, stm32_usbinterrupt) != 0) - { - udbg("Failed to attach IRQ\n"); - return NULL; - } - - /* Enable USB interrupts at the SYCON controller. Disable interrupts - * because this register may be shared with other drivers. - */ - - flags = irqsave(); - regval = stm32_getreg(STM32_SYSCON_USBINTST); - regval |= SYSCON_USBINTST_ENINTS; - stm32_putreg(regval, STM32_SYSCON_USBINTST); - irqrestore(flags); - - /* If there is a USB device in the slot at power up, then we will not - * get the status change interrupt to signal us that the device is - * connected. We need to set the initial connected state accordingly. - */ - - regval = stm32_getreg(STM32_USBHOST_RHPORTST1); - priv->connected = ((regval & OHCI_RHPORTST_CCS) != 0); - - /* Enable interrupts at the interrupt controller */ - - up_enable_irq(STM32_IRQ_USB); /* enable USB interrupt */ - udbg("USB host Initialized, Device connected:%s\n", - priv->connected ? "YES" : "NO"); - - return &priv->drvr; -} diff --git a/nuttx/arch/arm/src/stm32/stm32_usbhost.h b/nuttx/arch/arm/src/stm32/stm32_usbhost.h index 854c327235..d9bce33f77 100644 --- a/nuttx/arch/arm/src/stm32/stm32_usbhost.h +++ b/nuttx/arch/arm/src/stm32/stm32_usbhost.h @@ -47,6 +47,34 @@ #include "chip.h" #include "chip/stm32_otgfs.h" +#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) + +/************************************************************************************ + * Public Functions + ************************************************************************************/ +/* + * STM32 USB OTG FS Host Driver Support + * + * Pre-requisites + * + * CONFIG_USBHOST - Enable general USB host support + * CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block + * CONFIG_STM32_SYSCFG - Needed + * + * Options: + * + * CONFIG_STM32_OTGFS_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words. + * Default 128 (512 bytes) + * CONFIG_STM32_OTGFS_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO + * in 32-bit words. Default 96 (384 bytes) + * CONFIG_STM32_OTGFS_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit + * words. Default 96 (384 bytes) + * CONFIG_STM32_OTGFS_SOFINTR - Enable SOF interrupts. Why would you ever + * want to do that? + * CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access + * debug. Depends on CONFIG_DEBUG. + */ + /************************************************************************************ * Public Functions ************************************************************************************/ @@ -61,11 +89,40 @@ extern "C" { #define EXTERN extern #endif +/*********************************************************************************** + * Name: stm32_usbhost_vbusdrive + * + * Description: + * Enable/disable driving of VBUS 5V output. This function must be provided be + * each platform that implements the STM32 OTG FS host interface + * + * "On-chip 5 V VBUS generation is not supported. For this reason, a charge pump + * or, if 5 V are available on the application board, a basic power switch, must + * be added externally to drive the 5 V VBUS line. The external charge pump can + * be driven by any GPIO output. When the application decides to power on VBUS + * using the chosen GPIO, it must also set the port power bit in the host port + * control and status register (PPWR bit in OTG_FS_HPRT). + * + * "The application uses this field to control power to this port, and the core + * clears this bit on an overcurrent condition." + * + * Input Parameters: + * iface - For future growth to handle multiple USB host interface. Should be zero. + * enable - true: enable VBUS power; false: disable VBUS power + * + * Returned Value: + * None + * + ***********************************************************************************/ + +EXTERN void stm32_usbhost_vbusdrive(int iface, bool enable); + #undef EXTERN #if defined(__cplusplus) } #endif #endif /* __ASSEMBLY__ */ +#endif /* CONFIG_STM32_OTGFS && CONFIG_USBHOST */ #endif /* __ARCH_ARM_SRC_STM32_STM32_USBHOST_H */ diff --git a/nuttx/arch/arm/src/stm32/stm32_wdg.h b/nuttx/arch/arm/src/stm32/stm32_wdg.h index 38af388f92..fbb8128b55 100644 --- a/nuttx/arch/arm/src/stm32/stm32_wdg.h +++ b/nuttx/arch/arm/src/stm32/stm32_wdg.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_wdg.h * * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c b/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c index df8ad9dd5a..e1d52ac099 100644 --- a/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c +++ b/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c @@ -113,6 +113,10 @@ # error "CONFIG_STM32_BKP is required for CONFIG_RTC" #endif +#ifndef CONFIG_STM32_PWR +# error "CONFIG_STM32_PWR is required for CONFIG_RTC" +#endif + /* RTC/BKP Definitions *************************************************************/ /* STM32_RTC_PRESCALAR_VALUE * RTC pre-scalar value. The RTC is driven by a 32,768Hz input clock. This input diff --git a/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c b/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c index 8cfd405ded..335992524c 100644 --- a/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c +++ b/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c @@ -616,7 +616,7 @@ static void stm32_stdclockconfig(void) /* Set the PLL dividers and multiplers to configure the main PLL */ regval = (STM32_PLLCFG_PLLM | STM32_PLLCFG_PLLN |STM32_PLLCFG_PLLP | - RCC_PLLCFG_PLLSRC_HSE | STM32_PLLCFG_PPQ); + RCC_PLLCFG_PLLSRC_HSE | STM32_PLLCFG_PLLQ); putreg32(regval, STM32_RCC_PLLCFG); /* Enable the main PLL */ diff --git a/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c b/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c index 7ba341b2b8..45980f2889 100644 --- a/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c +++ b/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c @@ -618,7 +618,7 @@ static void stm32_stdclockconfig(void) /* Set the PLL dividers and multiplers to configure the main PLL */ regval = (STM32_PLLCFG_PLLM | STM32_PLLCFG_PLLN |STM32_PLLCFG_PLLP | - RCC_PLLCFG_PLLSRC_HSE | STM32_PLLCFG_PPQ); + RCC_PLLCFG_PLLSRC_HSE | STM32_PLLCFG_PLLQ); putreg32(regval, STM32_RCC_PLLCFG); /* Enable the main PLL */ diff --git a/nuttx/binfmt/Makefile b/nuttx/binfmt/Makefile index dd9e459ced..b3a9269b30 100644 --- a/nuttx/binfmt/Makefile +++ b/nuttx/binfmt/Makefile @@ -2,7 +2,7 @@ # nxflat/Makefile # # Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_dumpmodule.c b/nuttx/binfmt/binfmt_dumpmodule.c index 945dcb3ace..32a3fef3e3 100644 --- a/nuttx/binfmt/binfmt_dumpmodule.c +++ b/nuttx/binfmt/binfmt_dumpmodule.c @@ -2,7 +2,7 @@ * binfmt/binfmt_dumpmodule.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_exec.c b/nuttx/binfmt/binfmt_exec.c index cefd3aa5c7..c070324c31 100644 --- a/nuttx/binfmt/binfmt_exec.c +++ b/nuttx/binfmt/binfmt_exec.c @@ -2,7 +2,7 @@ * binfmt/binfmt_exec.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_execmodule.c b/nuttx/binfmt/binfmt_execmodule.c index 1965f6fa0b..1b511b0cb8 100644 --- a/nuttx/binfmt/binfmt_execmodule.c +++ b/nuttx/binfmt/binfmt_execmodule.c @@ -2,7 +2,7 @@ * binfmt/binfmt_execmodule.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_globals.c b/nuttx/binfmt/binfmt_globals.c index 0d0b2dbb42..069d3a2aa9 100644 --- a/nuttx/binfmt/binfmt_globals.c +++ b/nuttx/binfmt/binfmt_globals.c @@ -2,7 +2,7 @@ * binfmt/binfmt_globals.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_internal.h b/nuttx/binfmt/binfmt_internal.h index 22fadcd211..da67f5350b 100644 --- a/nuttx/binfmt/binfmt_internal.h +++ b/nuttx/binfmt/binfmt_internal.h @@ -2,7 +2,7 @@ * binfmt/binfmt_internal.h * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_loadmodule.c b/nuttx/binfmt/binfmt_loadmodule.c index d4ef7cde27..01ab8cc883 100644 --- a/nuttx/binfmt/binfmt_loadmodule.c +++ b/nuttx/binfmt/binfmt_loadmodule.c @@ -2,7 +2,7 @@ * binfmt/binfmt_loadmodule.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_register.c b/nuttx/binfmt/binfmt_register.c index e41c7a0d98..7f6eef671a 100644 --- a/nuttx/binfmt/binfmt_register.c +++ b/nuttx/binfmt/binfmt_register.c @@ -2,7 +2,7 @@ * binfmt/binfmt_register.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_unloadmodule.c b/nuttx/binfmt/binfmt_unloadmodule.c index c6fa90c396..04859a2910 100644 --- a/nuttx/binfmt/binfmt_unloadmodule.c +++ b/nuttx/binfmt/binfmt_unloadmodule.c @@ -2,7 +2,7 @@ * binfmt/binfmt_loadmodule.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/binfmt_unregister.c b/nuttx/binfmt/binfmt_unregister.c index 1b50b2c582..b97b9b67dd 100644 --- a/nuttx/binfmt/binfmt_unregister.c +++ b/nuttx/binfmt/binfmt_unregister.c @@ -2,7 +2,7 @@ * binfmt/binfmt_unregister.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/Make.defs b/nuttx/binfmt/libnxflat/Make.defs index 9e95936519..f979741e51 100644 --- a/nuttx/binfmt/libnxflat/Make.defs +++ b/nuttx/binfmt/libnxflat/Make.defs @@ -2,7 +2,7 @@ # nxflat/lib/Make.defs # # Copyright (C) 2009 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/gnu-nxflat.ld b/nuttx/binfmt/libnxflat/gnu-nxflat.ld index 9a59c0ec09..e66b1dff52 100644 --- a/nuttx/binfmt/libnxflat/gnu-nxflat.ld +++ b/nuttx/binfmt/libnxflat/gnu-nxflat.ld @@ -2,7 +2,7 @@ * examples/nxflat/nxflat.ld * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_bind.c b/nuttx/binfmt/libnxflat/libnxflat_bind.c index eb65a7e63a..ca348178dd 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_bind.c +++ b/nuttx/binfmt/libnxflat/libnxflat_bind.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/libnxflat_bind.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_init.c b/nuttx/binfmt/libnxflat/libnxflat_init.c index 45f016e271..5b6375ff16 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_init.c +++ b/nuttx/binfmt/libnxflat/libnxflat_init.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/libnxflat_init.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_load.c b/nuttx/binfmt/libnxflat/libnxflat_load.c index 25be056212..0991d0c2d7 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_load.c +++ b/nuttx/binfmt/libnxflat/libnxflat_load.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/libnxflat_load.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_read.c b/nuttx/binfmt/libnxflat/libnxflat_read.c index 8f1650e873..dbcd542791 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_read.c +++ b/nuttx/binfmt/libnxflat/libnxflat_read.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/libnxflat_read.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_uninit.c b/nuttx/binfmt/libnxflat/libnxflat_uninit.c index 72be6c7aed..5d06296c79 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_uninit.c +++ b/nuttx/binfmt/libnxflat/libnxflat_uninit.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/libnxflat_uninit.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_unload.c b/nuttx/binfmt/libnxflat/libnxflat_unload.c index 7dc3e87a74..55a2e45e60 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_unload.c +++ b/nuttx/binfmt/libnxflat/libnxflat_unload.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/libnxflat_unload.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/libnxflat/libnxflat_verify.c b/nuttx/binfmt/libnxflat/libnxflat_verify.c index de952774fc..f799aca4f6 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_verify.c +++ b/nuttx/binfmt/libnxflat/libnxflat_verify.c @@ -2,7 +2,7 @@ * binfmt/libnxflat/nxflat_verify.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/nxflat.c b/nuttx/binfmt/nxflat.c index 99b99249a1..4f5869bd92 100644 --- a/nuttx/binfmt/nxflat.c +++ b/nuttx/binfmt/nxflat.c @@ -2,7 +2,7 @@ * binfmt/nxflat.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/symtab_findbyname.c b/nuttx/binfmt/symtab_findbyname.c index 02b2ac22b4..201d7ba07d 100644 --- a/nuttx/binfmt/symtab_findbyname.c +++ b/nuttx/binfmt/symtab_findbyname.c @@ -2,7 +2,7 @@ * binfmt/symtab_findbyname.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/symtab_findbyvalue.c b/nuttx/binfmt/symtab_findbyvalue.c index 80df746684..4382ed5d8d 100644 --- a/nuttx/binfmt/symtab_findbyvalue.c +++ b/nuttx/binfmt/symtab_findbyvalue.c @@ -2,7 +2,7 @@ * binfmt/symtab_findbyvalue.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/symtab_findorderedbyname.c b/nuttx/binfmt/symtab_findorderedbyname.c index 82d68bfea4..61decf49ad 100644 --- a/nuttx/binfmt/symtab_findorderedbyname.c +++ b/nuttx/binfmt/symtab_findorderedbyname.c @@ -2,7 +2,7 @@ * binfmt/symtab_findorderedbyname.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/binfmt/symtab_findorderedbyvalue.c b/nuttx/binfmt/symtab_findorderedbyvalue.c index a995595da9..92b107856d 100644 --- a/nuttx/binfmt/symtab_findorderedbyvalue.c +++ b/nuttx/binfmt/symtab_findorderedbyvalue.c @@ -2,7 +2,7 @@ * binfmt/symtab_findorderedbyvalue.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/configs/Kconfig b/nuttx/configs/Kconfig index 2f6595dbdc..b67c11ab33 100644 --- a/nuttx/configs/Kconfig +++ b/nuttx/configs/Kconfig @@ -12,703 +12,28 @@ choice be available for selection. Use ARCH_BOARD_CUSTOM to create a new board configuration. -config ARCH_BOARD_AMBER - bool "Amber Web Server" - depends on ARCH_CHIP_ATMEGA128 +config ARCH_BOARD_PX4FMU + bool "PX4FMU board" + depends on ARCH_CHIP_STM32F405RG ---help--- - This is placeholder for the SoC Robotics Amber Web Server that is based - on the Atmel AVR ATMega128 MCU. There is not much there yet and what is - there is untested due to tool-related issues. + PX4 system Flight Management Unit -config ARCH_BOARD_AVR32DEV1 - bool "Atmel AVR32DEV1 board" - depends on ARCH_CHIP_AT32UC3B0256 +config ARCH_BOARD_PX4IO + bool "PX4IO board" + depends on ARCH_CHIP_STM32F100C8 ---help--- - This is a port of NuttX to the Atmel AVR32DEV1 board. That board is - based on the Atmel AT32UC3B0256 MCU and uses a specially patched - version of the GNU toolchain: The patches provide support for the - AVR32 family. That patched GNU toolchain is available only from the - Atmel website. STATUS: This port is functional but very basic. There - are configurations for NSH and the OS test. - -config ARCH_BOARD_C5471EVM - bool "Spectrum Digital C5471 evaluation board" - depends on ARCH_CHIP_C5471 - ---help--- - This is a port to the Spectrum Digital C5471 evaluation board. The - TMS320C5471 is a dual core processor from TI with an ARM7TDMI general - purpose processor and a c54 DSP. It is also known as TMS320DA180 or just DA180. - NuttX runs on the ARM core and is built with a GNU arm-elf toolchain*. - This port is complete and verified. - -config ARCH_BOARD_COMPALE88 - bool "Compal e88 phone" - depends on ARCH_CHIP_CALYPSO - ---help--- - These directories contain the board support for compal e88 and e99 phones. - These ports are based on patches contributed by Denis Carikli for both the - compal e99 and e88. The patches were made by Alan Carvalho de Assis and - Denis Carikli using the Stefan Richter's Osmocom-bb patches. - -config ARCH_BOARD_COMPALE99 - bool "Compal e99 phone" - depends on ARCH_CHIP_CALYPSO - ---help--- - These directories contain the board support for compal e88 and e99 phones. - These ports are based on patches contributed by Denis Carikli for both the - compal e99 and e88. The patches were made by Alan Carvalho de Assis and - Denis Carikli using the Stefan Richter's Osmocom-bb patches. - -config ARCH_BOARD_DEMOS92S12NEC64 - bool "Freescale DMO9S12NE64 board" - depends on ARCH_CHIP_MCS92S12NEC64 - ---help--- - Freescale DMO9S12NE64 board based on the MC9S12NE64 hcs12 cpu. This - port uses the m9s12x GCC toolchain. STATUS: (Still) under development; it - is code complete but has not yet been verified. - -config ARCH_BOARD_EA3131 - bool "Embedded Artists EA3131 Development board" - depends on ARCH_CHIP_LPC3131 - ---help--- - Embedded Artists EA3131 Development board. This board is based on the - an NXP LPC3131 MCU. This OS is built with the arm-elf toolchain*. - STATUS: This port is complete and mature. - -config ARCH_BOARD_EA3152 - bool "Embedded Artists EA3152 Development board" - depends on ARCH_CHIP_LPC3152 - ---help--- - Embedded Artists EA3152 Development board. This board is based on the - an NXP LPC3152 MCU. This OS is built with the arm-elf toolchain*. - STATUS: This port is has not be exercised well, but since it is - a simple derivative of the ea3131, it should be fully functional. - -config ARCH_BOARD_EAGLE100 - bool "Micromint Eagle-100 Development board" - depends on ARCH_CHIP_LM3S6918 - ---help--- - Micromint Eagle-100 Development board. This board is based on the - an ARM Cortex-M3 MCU, the Luminary LM3S6918. This OS is built with the - arm-elf toolchain*. STATUS: This port is complete and mature. - -config ARCH_BOARD_EKK_LM3S9B96 - bool "TI/Stellaris EKK-LM3S9B96" - depends on ARCH_CHIP_LM3S9B96 - ---help--- - TI/Stellaris EKK-LM3S9B96 board. This board is based on the - an EKK-LM3S9B96 which is a Cortex-M3. - -config ARCH_BOARD_EZ80F910200KITG - bool "ZiLOG ez80f0910200kitg development kit" - depends on ARCH_CHIP_EZ80F91 - ---help--- - ez80Acclaim! Microcontroller. This port use the ZiLOG ez80f0910200kitg - development kit, eZ80F091 part, and the Zilog ZDS-II Windows command line - tools. The development environment is Cygwin under WinXP. - -config ARCH_BOARD_EZ80F910200ZCO - bool "ZiLOG ez80f0910200zco development kit" - depends on ARCH_CHIP_EZ80F91 - ---help--- - ez80Acclaim! Microcontroller. This port use the Zilog ez80f0910200zco - development kit, eZ80F091 part, and the Zilog ZDS-II Windows command line - tools. The development environment is Cygwin under WinXP. - -config ARCH_BOARD_HYMINI_STM32V - bool "HY-Mini STM32v board" - depends on ARCH_CHIP_STM32F103VCT - ---help--- - A configuration for the HY-Mini STM32v board. This board is based on the - STM32F103VCT chip. - -config ARCH_BOARD_LINCOLN60 - bool "Micromint Lincoln 60 board" - depends on ARCH_CHIP_LPC1769 - ---help--- - Micromint Lincoln 60 board using the NXP LPC1769 MCU. - -config ARCH_BOARD_KWIKSTIK_K40 - bool "FreeScale KwikStik-K40 development board" - depends on ARCH_CHIP_MK40X256VLQ100 - ---help--- - Kinetis K40 Cortex-M4 MCU. This port uses the FreeScale KwikStik-K40 - development board. - -config ARCH_BOARD_LM3S6432S2E - bool "Stellaris RDK-S2E Reference Design Kit" - depends on ARCH_CHIP_LM3S6432 - ---help--- - Stellaris RDK-S2E Reference Design Kit and the MDL-S2E Ethernet to - Serial module. - -config ARCH_BOARD_LM3S6965EK - bool "Stellaris LM3S6965 Evaluation Kit" - depends on ARCH_CHIP_LM3S6965 - ---help--- - Stellaris LM3S6965 Evaluation Kit. This board is based on the - an ARM Cortex-M3 MCU, the Luminary/TI LM3S6965. This OS is built with the - arm-elf toolchain*. STATUS: This port is complete and mature. - -config ARCH_BOARD_LM3S8962EK - bool "Stellaris LMS38962 Evaluation Kit" - depends on ARCH_CHIP_LM3S8962 - ---help--- - Stellaris LMS38962 Evaluation Kit. - -config ARCH_BOARD_LPCXPRESSO - bool "NXP LPCExpresso LPC1768" - depends on ARCH_CHIP_LPC1768 - ---help--- - Embedded Artists base board with NXP LPCExpresso LPC1768. This board - is based on the NXP LPC1768. The Code Red toolchain is used by default. - -config ARCH_BOARD_LPC4330_XPLORER - bool "NXG LPC4330-Xplorer" - depends on ARCH_CHIP_LPC4330FET100 - ---help--- - NXG Technologoies LPC4330 Xplorer board. This board is based on the - LPC4330FET100. The Code Red toolchain is used by default. - -config ARCH_BOARD_M68332EVB - bool "Motoroloa M68332EVB" - depends on ARCH_M68332 - ---help--- - This is a work in progress for the venerable m68322evb board from - Motorola. This OS is also built with the arm-elf toolchain. STATUS: - This port was never completed. - -config ARCH_BOARD_MBED - bool "mbed LCP1768" - depends on ARCH_CHIP_LPC1768 - ---help--- - The configurations in this directory support the mbed board (http://mbed.org) - that features the NXP LPC1768 microcontroller. This OS is also built - with the arm-elf toolchain*. STATUS: Contributed. - -config ARCH_BOARD_MCU123 - bool "mcu123.com LPC2148 Development Board" - depends on ARCH_CHIP_LPC2148 - ---help--- - This port is for the NXP LPC2148 as provided on the mcu123.com - lpc214x development board. This OS is also built with the arm-elf - toolchain*. The port supports serial, timer0, spi, and usb. - -config ARCH_BOARD_MICROPENDOUS - bool "Opendous Micropendous 3 board" - depends on ARCH_CHIP_AT90USB646 || ARCH_CHIP_AT90USB647 || ARCH_CHIP_AT90USB1286 || ARCH_CHIP_AT90USB1287 - ---help--- - This is a port to the Opendous Micropendous 3 board. This board may - be populated with either an AVR AT90USB646, 647, 1286, or 1287 MCU. - Support is configured for the AT90USB647. - -config ARCH_BOARD_MX1ADS - bool "Motorola MX1ADS development board" - depends on ARCH_CHIP_IMX1 - ---help--- - This is a port to the Motorola MX1ADS development board. That board - is based on the Freescale i.MX1 processor. The i.MX1 is an ARM920T. - STATUS: This port is nearly code complete but was never fully - integrated due to tool-related issues. - -config ARCH_BOARD_NE64BADGE - bool "FEG NE64 /PoE Badge board" - depends on ARCH_CHIP_MCS92S12NEC64 - ---help--- - Future Electronics Group NE64 /PoE Badge board based on the - MC9S12NE64 hcs12 cpu. This port uses the m9s12x GCC toolchain. - STATUS: Under development. The port is code-complete but has - not yet been fully tested. - -config ARCH_BOARD_NTOSD_DM320 - bool "Neuros OSD v1.0 Dev Board" - depends on ARCH_CHIP_DM320 - ---help--- - This port uses the Neuros OSD v1.0 Dev Board with a GNU arm-elf - toolchain*: see - - http://wiki.neurostechnology.com/index.php/OSD_1.0_Developer_Home - - There are some differences between the Dev Board and the currently - available commercial v1.0 Boards. See - - http://wiki.neurostechnology.com/index.php/OSD_Developer_Board_v1 - - NuttX operates on the ARM9EJS of this dual core processor. - STATUS: This port is code complete, verified, and included in the - NuttX 0.2.1 release. - -config ARCH_BOARD_NUCLEUS2G - bool "Nucleus 2G board" - depends on ARCH_CHIP_LPC1768 - ---help--- - This port uses the Nucleus 2G board (with Babel CAN board). This board - features an NXP LPC1768 processor. See the 2G website (http://www.2g-eng.com/) - for more information about the Nucleus 2G. - -config ARCH_BOARD_LPC1766STK - bool "Olimex LPC1766-STK board" - depends on ARCH_CHIP_LPC1766 - ---help--- - This port uses the Olimex LPC1766-STK board and a GNU GCC toolchain* under - Linux or Cygwin. STATUS: Complete and mature. - -config ARCH_BOARD_MIRTOO - bool "Mirtoo PIC32 Module from Dimitech" - depends on ARCH_CHIP_PIC32MX250F128D - ---help--- - This is the port to the DTX1-4000L "Mirtoo" module. This module uses MicroChip - PIC32MX250F128D. See http://www.dimitech.com/ for further information. - -config ARCH_BOARD_OLIMEXLPC2378 - bool "Olimex-lpc2378 board" - depends on ARCH_CHIP_LPC2378 - ---help--- - This port uses the Olimex-lpc2378 board and a GNU arm-elf toolchain* under - Linux or Cygwin. STATUS: ostest and NSH configurations available. - This port for the NXP LPC2378 was contributed by Rommel Marcelo. - -config ARCH_BOARD_OLIMEX_STRP711 - bool "Olimex STR-P711 board" - depends on ARCH_CHIP_STR71X - ---help--- - This port uses the Olimex STR-P711 board and a GNU arm-elf toolchain* under - Linux or Cygwin. See the http://www.olimex.com/dev/str-p711.html" for - further information. STATUS: Configurations for the basic OS test and NSH - are complete and verified. - -config ARCH_BOARD_PCBLOGICPIC32MX - bool "PIC32MX board from PCB Logic Design Co" - depends on ARCH_CHIP_PIC32MX460F512L - ---help--- - This is the port of NuttX to the PIC32MX board from PCB Logic Design Co. - This board features the MicroChip PIC32MX460F512L. - The board is a very simple -- little more than a carrier for the PIC32 - MCU plus voltage regulation, debug interface, and an OTG connector. - STATUS: Code complete but testing has been stalled due to tool related problems - (PICkit 2 does not work with the PIC32). - -config ARCH_BOARD_PIC32_STARTERKIT - bool "Microchip PIC32 Ethernet Starter Kit (DM320004)" - depends on ARCH_CHIP_PIC32MX795F512L - ---help--- - This is the port of NuttX to the Microchip PIC32 Ethernet Starter Kit - (DM320004) with the Multimedia Expansion Board (MEB, DM320005). - See www.microchip.com for further information. - -config ARCH_BOARD_PIC32_PIC32MX7MMB - bool "Mikroelektronika PIC32MX7 MMB" - depends on ARCH_CHIP_PIC32MX795F512L - ---help--- - This is the port NuttX to the Mikroelektronika PIC32MX7 Multimedia Board - (MMB). See http://www.mikroe.com/ for further information. - -config ARCH_BOARD_PJRC_87C52 - bool "PJRC 87C52 development system" - depends on ARCH_CHIP_8052 - ---help--- - 8051 Microcontroller. This port uses the PJRC 87C52 development system - and the SDCC toolchain. This port is not quite ready for prime time. - -config ARCH_BOARD_QEMU_I486 - bool "Qemu i486 Mode" - depends on ARCH_QEMU - ---help--- - Port of NuttX to QEMU in i486 mode. This port will also run on real i486 - hardwared (Google the Bifferboard). - -config ARCH_BOARD_RGMP - bool "RGMP" - depends on ARCH_RGMP - ---help--- - RGMP stands for RTOS and GPOS on Multi-Processor. RGMP is a project for - running GPOS and RTOS simultaneously on multi-processor platforms. You can - port your favorite RTOS to RGMP together with an unmodified Linux to form a - hybrid operating system. This makes your application able to use both RTOS - and GPOS features. - - See http://rgmp.sourceforge.net/wiki/index.php/Main_Page for further information - about RGMP. - -config ARCH_BOARD_SAM3UEK - bool "Atmel SAM3U-EK development board" - depends on ARCH_CHIP_AT91SAM3U4E - ---help--- - The port of NuttX to the Atmel SAM3U-EK development board. - -config ARCH_BOARD_SKP16C26 - bool "Renesas SKP16C26 StarterKit" - depends on ARCH_CHIP_M30262F8 - ---help--- - Renesas M16C processor on the Renesas SKP16C26 StarterKit. This port - uses the GNU m32c toolchain. STATUS: The port is complete but untested - due to issues with compiler internal errors. - -config ARCH_BOARD_STM3210E_EVAL - bool "STMicro STM3210E-EVAL development board" - depends on ARCH_CHIP_STM32F103ZET6 - ---help--- - STMicro STM3210E-EVAL development board based on the STMicro STM32F103ZET6 - microcontroller (ARM Cortex-M3). This port uses the GNU Cortex-M3 - toolchain. - -config ARCH_BOARD_STM3220G_EVAL - bool "STMicro STM3220G-EVAL development board" - depends on ARCH_CHIP_STM32F207IG - ---help--- - STMicro STM3220G-EVAL development board based on the STMicro STM32F407IG - microcontroller (ARM Cortex-M3). - -config ARCH_BOARD_STM3240G_EVAL - bool "STMicro STM3240G-EVAL development board" - depends on ARCH_CHIP_STM32F407IG - ---help--- - STMicro STM3240G-EVAL development board based on the STMicro STM32F103ZET6 - microcontroller (ARM Cortex-M4 with FPU). This port uses a GNU Cortex-M4 - toolchain (such as CodeSourcery). - -config ARCH_BOARD_STM32F4_DISCOVERY - bool "STMicro STM32F4-Discovery board" - depends on ARCH_CHIP_STM32F407VG - ---help--- - STMicro STM32F4-Discovery board boased on the STMIcro STM32F407VGT6 MCU. - -config ARCH_BOARD_SUREPIC32MX - bool "Sure PIC32MX boards" - depends on ARCH_CHIP_PIC32MX440F512H - ---help--- - The "Advanced USB Storage Demo Board," Model DB-DP11215, from Sure - Electronics (http://www.sureelectronics.net/). This board features - the MicroChip PIC32MX440F512H. See also - http://www.sureelectronics.net/goods.php?id=1168 for further - information about the Sure DB-DP11215 board. - -config ARCH_BOARD_TEENSY - bool "PJRC Teensy++ 2.0 board" - depends on ARCH_CHIP_AT90USB1286 - ---help--- - This is the port of NuttX to the PJRC Teensy++ 2.0 board. This board is - developed by http://pjrc.com/teensy/. The Teensy++ 2.0 is based - on an Atmel AT90USB1286 MCU. - -config ARCH_BOARD_TWR_K60N512 - bool "FreeScale TWR-K60N512d evelopment board" - depends on ARCH_CHIP_MK60N512VMD100 - ---help--- - Kinetis K60 Cortex-M4 MCU. This port uses the FreeScale TWR-K60N512 - development board. - -config ARCH_BOARD_UBW32 - bool "UBW32 v2.4 board from Sparkfun" - depends on ARCH_CHIP_PIC32MX460F512L - ---help--- - This is the port to the Sparkfun UBW32 board. This port uses the original v2.4 - board which is based on the MicroChip PIC32MX460F512L. See - http://www.sparkfun.com/products/8971. This older version has been replaced - with this board http://www.sparkfun.com/products/9713. See also - http://www.schmalzhaus.com/UBW32/. - -config ARCH_BOARD_US7032EVB1 - bool "Hitachi SH-1/US7032EVB1 board" - depends on ARCH_CHIP_SH7032 - ---help--- - This is a port of the Hitachi SH-1 on the Hitachi SH-1/US7032EVB1 board. - STATUS: Work has just began on this port. - -config ARCH_BOARD_VSN - bool "SOTEL NetClamps VSN sensor network platform" - depends on ARCH_CHIP_STM32F103RET6 - ---help--- - ISOTEL NetClamps VSN V1.2 ready2go sensor network platform based on the - STMicro STM32F103RET6. Contributed by Uros Platise. See - http://isotel.eu/NetClamps/ - -config ARCH_BOARD_XTRS - bool "XTRS TRS80 Model 3 emulation" - depends on ARCH_CHIP_Z80 - ---help--- - TRS80 Model 3. This port uses a vintage computer based on the Z80. - An emulator for this computer is available to run TRS80 programs on a - linux platform (http://www.tim-mann.org/xtrs.html). - -config ARCH_BOARD_Z16F2800100ZCOG - bool "Zilog Z16F2800100ZCOG Development Kit" - depends on ARCH_CHIP_Z16F281 - ---help--- - z16f Microcontroller. This port use the ZiLIG z16f2800100zcog - development kit and the Zilog ZDS-II Windows command line tools. The - development environment is Cygwin under WinXP. - -config ARCH_BOARD_Z80SIM - bool "Z80 Instruction Set Simulator" - depends on ARCH_CHIP_Z80 - ---help--- - z80 Microcontroller. This port uses a Z80 instruction set simulator. - That simulator can be found in the NuttX SVN at - http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/misc/sims/z80sim. - This port also uses the SDCC toolchain (http://sdcc.sourceforge.net/") - (verified with version 2.6.0). - -config ARCH_BOARD_Z8ENCORE000ZCO - bool "ZiLOG z8encore000zco Development Kit" - depends on ARCH_CHIP_Z8F6403 - ---help--- - z8Encore! Microcontroller. This port use the ZiLOG z8encore000zco - development kit, Z8F6403 part, and the Zilog ZDS-II Windows command line - tools. The development environment is Cygwin under WinXP. - -config ARCH_BOARD_Z8F64200100KI - bool "ZiLOG Z8F64200100KIT Development Kit" - depends on ARCH_CHIP_Z8F642X - ---help--- - z8Encore! Microcontroller. This port use the Zilog z8f64200100kit - development kit, Z8F6423 part, and the Zilog ZDS-II Windows command line - tools. The development environment is Cygwin under WinXP. - -config ARCH_BOARD_SIM - bool "User mode simulation" - depends on ARCH_SIM - ---help--- - A user-mode port of NuttX to the x86 Linux/Cygwin platform is available. - The purpose of this port is primarily to support OS feature development. - This port does not support interrupts or a real timer (and hence no - round robin scheduler) Otherwise, it is complete. - -config ARCH_BOARD_CUSTOM - bool "Custom development board" - ---help--- - Select this option if there is no directory for the board under configs/. - - Don't see the board you want? You must first select the exact MCU part - number, then the boards supporting that part will be available for selection. - + PX4 system I/O expansion board endchoice config ARCH_BOARD string - default "amber" if ARCH_BOARD_AMBER - default "avr32dev1" if ARCH_BOARD_AVR32DEV1 - default "c5471evm" if ARCH_BOARD_C5471EVM - default "compal_e88" if ARCH_BOARD_COMPALE88 - default "compal_e99" if ARCH_BOARD_COMPALE99 - default "demo9s12ne64" if ARCH_BOARD_DEMOS92S12NEC64 - default "ea3131" if ARCH_BOARD_EA3131 - default "ea3152" if ARCH_BOARD_EA3152 - default "eagle100" if ARCH_BOARD_EAGLE100 - default "ekk-lm3s9b96" if ARCH_BOARD_EKK_LM3S9B96 - default "ez80f0910200kitg" if ARCH_BOARD_EZ80F910200KITG - default "ez80f0910200zco" if ARCH_BOARD_EZ80F910200ZCO - default "hymini-stm32v" if ARCH_BOARD_HYMINI_STM32V - default "kwikstik-k40" if ARCH_BOARD_KWIKSTIK_K40 - default "lincoln60" if ARCH_BOARD_LINCOLN60 - default "lm3s6432-s2e" if ARCH_BOARD_LM3S6432S2E - default "lm3s6965-ek" if ARCH_BOARD_LM3S6965EK - default "lm3s8962-ek" if ARCH_BOARD_LM3S8962EK - default "lpc4330-xplorer" if ARCH_BOARD_LPC4330_XPLORER - default "lpcxpresso-lpc1768" if ARCH_BOARD_LPCXPRESSO - default "m68322evb" if ARCH_BOARD_M68332EVB - default "mbed" if ARCH_BOARD_MBED - default "mcu123-lpc214x" if ARCH_BOARD_MCU123 - default "micropendous3" if ARCH_BOARD_MICROPENDOUS - default "mirtoo" if ARCH_BOARD_MIRTOO - default "mx1ads" if ARCH_BOARD_MX1ADS - default "ne64badge" if ARCH_BOARD_NE64BADGE - default "ntosd-dm320" if ARCH_BOARD_NTOSD_DM320 - default "nucleus2g" if ARCH_BOARD_NUCLEUS2G - default "olimex-lpc1766stk" if ARCH_BOARD_LPC1766STK - default "olimex-lpc2378" if ARCH_BOARD_OLIMEXLPC2378 - default "olimex-strp711" if ARCH_BOARD_OLIMEX_STRP711 - default "pcblogic-pic32mx" if ARCH_BOARD_PCBLOGICPIC32MX - default "pic32-starterkit" if ARCH_BOARD_PIC32_STARTERKIT - default "pic32mx7mmb" if ARCH_BOARD_PIC32_PIC32MX7MMB - default "pjrc-8051" if ARCH_BOARD_PJRC_87C52 - default "qemu-i486" if ARCH_BOARD_QEMU_I486 - default "rgmp" if ARCH_BOARD_RGMP - default "sam3u-ek" if ARCH_BOARD_SAM3UEK - default "skp16c26" if ARCH_BOARD_SKP16C26 - default "stm3210e-eval" if ARCH_BOARD_STM3210E_EVAL - default "stm3220g-eval" if ARCH_BOARD_STM3220G_EVAL - default "stm3240g-eval" if ARCH_BOARD_STM3240G_EVAL - default "stm32f4discovery" if ARCH_BOARD_STM32F4_DISCOVERY - default "sure-pic32mx" if ARCH_BOARD_SUREPIC32MX - default "teensy" if ARCH_BOARD_TEENSY - default "twr-k60n512" if ARCH_BOARD_TWR_K60N512 - default "ubw32" if ARCH_BOARD_UBW32 - default "us7032evb1" if ARCH_BOARD_US7032EVB1 - default "vsn" if ARCH_BOARD_VSN - default "xtrs" if ARCH_BOARD_XTRS - default "z16f2800100zcog" if ARCH_BOARD_Z16F2800100ZCOG - default "z80sim" if ARCH_BOARD_Z80SIM - default "z8encore000zco" if ARCH_BOARD_Z8ENCORE000ZCO - default "z8f64200100kit" if ARCH_BOARD_Z8F64200100KI - default "sim" if ARCH_BOARD_SIM + default "px4fmu" if ARCH_BOARD_PX4FMU + default "px4io" if ARCH_BOARD_PX4IO default "" if ARCH_BOARD_CUSTOM -if ARCH_BOARD_AMBER -source "configs/amber/Kconfig" +if ARCH_BOARD_PX4FMU +source "configs/px4fmu/Kconfig" endif -if ARCH_BOARD_AVR32DEV1 -source "configs/avr32dev1/Kconfig" -endif -if ARCH_BOARD_C5471EVM -source "configs/c5471evm/Kconfig" -endif -if ARCH_BOARD_COMPALE88 -source "configs/compal_e88/Kconfig" -endif -if ARCH_BOARD_COMPALE99 -source "configs/compal_e99/Kconfig" -endif -if ARCH_BOARD_DEMOS92S12NEC64 -source "configs/demo9s12ne64/Kconfig" -endif -if ARCH_BOARD_EA3131 -source "configs/ea3131/Kconfig" -endif -if ARCH_BOARD_EA3152 -source "configs/ea3152/Kconfig" -endif -if ARCH_BOARD_EAGLE100 -source "configs/eagle100/Kconfig" -endif -if ARCH_BOARD_EKK_LM3S9B96 -source "configs/ekk-lm3s9b96/Kconfig" -endif -if ARCH_BOARD_EZ80F910200KITG -source "configs/ez80f910200kitg/Kconfig" -endif -if ARCH_BOARD_EZ80F910200ZCO -source "configs/ez80f910200zco/Kconfig" -endif -if ARCH_BOARD_HYMINI_STM32V -source "configs/hymini-stm32v/Kconfig" -endif -if ARCH_BOARD_KWIKSTIK_K40 -source "configs/kwikstik-k40/Kconfig" -endif -if ARCH_BOARD_LINCOLN60 -source "configs/lincoln60/Kconfig" -endif -if ARCH_BOARD_LM3S6432S2E -source "configs/lm3s6432-s2e/Kconfig" -endif -if ARCH_BOARD_LM3S6965EK -source "configs/lm3s6965-ek/Kconfig" -endif -if ARCH_BOARD_LM3S8962EK -source "configs/lm3s8962-ek/Kconfig" -endif -if ARCH_BOARD_LPC4330_XPLORER -source "configs/lpc4330-xplorer/Kconfig" -endif -if ARCH_BOARD_LPCXPRESSO -source "configs/lpcxpresso-lpc1768/Kconfig" -endif -if ARCH_BOARD_M68332EVB -source "configs/m68332evb/Kconfig" -endif -if ARCH_BOARD_MBED -source "configs/mbed/Kconfig" -endif -if ARCH_BOARD_MCU123 -source "configs/mcu123-lpc214x/Kconfig" -endif -if ARCH_BOARD_MICROPENDOUS -source "configs/micropendous3/Kconfig" -endif -if ARCH_BOARD_MIRTOO -source "configs/mirtoo/Kconfig" -endif -if ARCH_BOARD_MX1ADS -source "configs/mx1ads/Kconfig" -endif -if ARCH_BOARD_NE64BADGE -source "configs/ne64badge/Kconfig" -endif -if ARCH_BOARD_NTOSD_DM320 -source "configs/ntosd-dm320/Kconfig" -endif -if ARCH_BOARD_NUCLEUS2G -source "configs/nucleus2g/Kconfig" -endif -if ARCH_BOARD_LPC1766STK -source "configs/olimex-lpc1766stk/Kconfig" -endif -if ARCH_BOARD_OLIMEXLPC2378 -source "configs/olimex-lpc2378/Kconfig" -endif -if ARCH_BOARD_OLIMEX_STRP711 -source "configs/olimex-strp711/Kconfig" -endif -if ARCH_BOARD_PCBLOGICPIC32MX -source "configs/pcblogic-pic32mx/Kconfig" -endif -if ARCH_BOARD_PIC32_STARTERKIT -source "configs/pic32-starterkit/Kconfig" -endif -if ARCH_BOARD_PIC32_PIC32MX7MMB -source "configs/pic32mx7mmb/Kconfig" -endif -if ARCH_BOARD_PJRC_87C52 -source "configs/pjrc-8051/Kconfig" -endif -if ARCH_BOARD_QEMU_I486 -source "configs/qemu-i486/Kconfig" -endif -if ARCH_BOARD_RGMP -source "configs/rgmp/Kconfig" -endif -if ARCH_BOARD_SAM3UEK -source "configs/sam3u-ek/Kconfig" -endif -if ARCH_BOARD_SKP16C26 -source "configs/skp16c26/Kconfig" -endif -if ARCH_BOARD_STM3210E_EVAL -source "configs/stm3210e-eval/Kconfig" -endif -if ARCH_BOARD_STM3220G_EVAL -source "configs/stm3220g-eval/Kconfig" -endif -if ARCH_BOARD_STM3240G_EVAL -source "configs/stm3240g-eval/Kconfig" -endif -if ARCH_BOARD_STM32F4_DISCOVERY -source "configs/stm32f4discovery/Kconfig" -endif -if ARCH_BOARD_SUREPIC32MX -source "configs/sure-pic32mx/Kconfig" -endif -if ARCH_BOARD_TEENSY -source "configs/teensy/Kconfig" -endif -if ARCH_BOARD_TWR_K60N512 -source "configs/twr-k60n512/Kconfig" -endif -if ARCH_BOARD_UBW32 -source "configs/ubw32/Kconfig" -endif -if ARCH_BOARD_US7032EVB1 -source "configs/us7032evb1/Kconfig" -endif -if ARCH_BOARD_VSN -source "configs/vsn/Kconfig" -endif -if ARCH_BOARD_XTRS -source "configs/xtrs/Kconfig" -endif -if ARCH_BOARD_Z16F2800100ZCOG -source "configs/z16f2800100zcog/Kconfig" -endif -if ARCH_BOARD_Z80SIM -source "configs/z80sim/Kconfig" -endif -if ARCH_BOARD_Z8ENCORE000ZCO -source "configs/z8encore000zco/Kconfig" -endif -if ARCH_BOARD_Z8F64200100KI -source "configs/z8f64200100kit/Kconfig" -endif -if ARCH_BOARD_SIM -source "configs/sim/Kconfig" +if ARCH_BOARD_PX4IO +source "configs/px4io/Kconfig" endif diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 87725bf58f..b5ada6ee5d 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -7,6 +7,7 @@ Table of Contents o Summary of Files o Supported Architectures o Configuring NuttX + o Building Symbol Tables Board-Specific Configurations ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -268,8 +269,7 @@ defconfig -- This is a configuration file similar to the Linux by default) CONFIG_DEBUG_GRAPHICS - enable NX graphics debug output (disabled by default) - CONFIG_ARCH_LOWPUTC - architecture supports low-level, boot - time console output + CONFIG_MM_REGIONS - If the architecture includes multiple regions of memory to allocate from, this specifies the number of memory regions that the memory manager must @@ -283,6 +283,33 @@ defconfig -- This is a configuration file similar to the Linux of size less than or equal to 64Kb. In this case, CONFIG_MM_SMALL can be defined so that those MCUs will also benefit from the smaller, 16-bit-based allocation overhead. + CONFIG_HEAP2_BASE and CONFIG_HEAP2_SIZE + Some architectures use these settings to specify the size of + a second heap region. + CONFIG_GRAN + Enable granual allocator support. Allocations will be aligned to the + granule size; allocations will be in units of the granule size. + Larger granules will give better performance and less overhead but + more losses of memory due to alignment and quantization waste. + NOTE: The current implementation also restricts the maximum + allocation size to 32 granaules. That restriction could be + eliminated with some additional coding effort. + CONFIG_GRAN_SINGLE + Select if there is only one instance of the granule allocator (i.e., + gran_initialize will be called only once. In this case, (1) there + are a few optimizations that can can be done and (2) the GRAN_HANDLE + is not needed. + CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator + data is assured using a semaphore. If this option is set then, instead, + mutual exclusion logic will disable interrupts. While this options is + more invasive to system performance, it will also support use of the + granule allocator from interrupt level logic. + CONFIG_DEBUG_GRAM + Just like CONFIG_DEBUG_MM, but only generates ouput from the gran + allocation logic. + + CONFIG_ARCH_LOWPUTC - architecture supports low-level, boot + time console output CONFIG_MSEC_PER_TICK - The default system timer is 100Hz or MSEC_PER_TICK=10. This setting may be defined to inform NuttX that the processor hardware is providing @@ -323,13 +350,17 @@ defconfig -- This is a configuration file similar to the Linux set to zero if priority inheritance is disabled OR if you are only using semaphores as mutexes (only one holder) OR if no more than two threads participate using a counting - semaphore. + semaphore. If defined, then this should be a relatively + large number because this is the total number of counts on + the total number of semaphores (like 64 or 100). CONFIG_SEM_NNESTPRIO. If priority inheritance is enabled, then this setting is the maximum number of higher priority threads (minus 1) than can be waiting for another thread to release a count on a semaphore. This value may be set to zero if no more than one thread is expected to wait for - a semaphore. + a semaphore. If defined, then this should be a relatively + small number because this the number of maximumum of waiters + on one semaphore (like 4 or 8). CONFIG_FDCLONE_DISABLE. Disable cloning of all file descriptors by task_create() when a new task is started. If set, all files/drivers will appear to be closed in the new task. @@ -355,13 +386,24 @@ defconfig -- This is a configuration file similar to the Linux if memory reclamation is of high priority). If CONFIG_SCHED_WORKQUEUE is enabled, then the following options can also be used: CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker - thread. Default: 50 + thread. Default: 192 CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for work in units of microseconds. Default: 50*1000 (50 MS). CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker thread. Default: CONFIG_IDLETHREAD_STACKSIZE. CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up the worker thread. Default: 4 + CONFIG_SCHED_LPWORK. If CONFIG_SCHED_WORKQUEUE is defined, then a single + work queue is created by default. If CONFIG_SCHED_LPWORK is also defined + then an additional, lower-priority work queue will also be created. This + lower priority work queue is better suited for more extended processing + (such as file system clean-up operations) + CONFIG_SCHED_LPWORKPRIORITY - The execution priority of the lower priority + worker thread. Default: 50 + CONFIG_SCHED_LPWORKPERIOD - How often the lower priority worker thread + checks for work in units of microseconds. Default: 50*1000 (50 MS). + CONFIG_SCHED_LPWORKSTACKSIZE - The stack size allocated for the lower + priority worker thread. Default: CONFIG_IDLETHREAD_STACKSIZE. CONFIG_SCHED_WAITPID - Enables the waitpid() API CONFIG_SCHED_ATEXIT - Enables the atexit() API CONFIG_SCHED_ATEXIT_MAX - By default if CONFIG_SCHED_ATEXIT is @@ -371,6 +413,10 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_SCHED_ONEXIT_MAX - By default if CONFIG_SCHED_ONEXIT is selected, only a single on_exit() function is supported. That number can be increased by defined this setting to the number that you require. + CONFIG_USER_ENTRYPOINT - The name of the entry point for user + applications. For the example applications this is of the form 'app_main' + where 'app' is the application name. If not defined, CONFIG_USER_ENTRYPOINT + defaults to user_start. System Logging: CONFIG_SYSLOG enables general system logging support. @@ -542,10 +588,28 @@ defconfig -- This is a configuration file similar to the Linux Misc libc settings - CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a - little smaller if we do not support fieldwidthes - CONFIG_LIBC_FLOATINGPOINT - By default, floating point - support in printf, sscanf, etc. is disabled. + CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a little smaller + if we do not support fieldwidthes + CONFIG_LIBC_FLOATINGPOINT - By default, floating point support in printf, + sscanf, etc. is disabled. + CONFIG_LIBC_STRERROR - strerror() is useful because it decodes 'errno' + values into a human readable strings. But it can also require + a lot of memory. If this option is selected, strerror() will still + exist in the build but it will not decode error values. This option + should be used by other logic to decide if it should use strerror() or + not. For example, the NSH application will not use strerror() if this + option is not selected; perror() will not use strerror() is this option + is not selected (see also CONFIG_NSH_STRERROR). + CONFIG_LIBC_STRERROR_SHORT - If this option is selected, then strerror() + will use a shortened string when it decodes the error. Specifically, + strerror() is simply use the string that is the common name for the + error. For example, the 'errno' value of 2 will produce the string + "No such file or directory" if CONFIG_LIBC_STRERROR_SHORT is not + defined but the string "ENOENT" if CONFIG_LIBC_STRERROR_SHORT is + defined. + CONFIG_LIBC_PERROR_STDOUT - POSIX requires that perror() provide its output + on stderr. This option may be defined, however, to provide perror() output + that is serialized with other stdout messages. Allow for architecture optimized implementations @@ -682,7 +746,6 @@ defconfig -- This is a configuration file similar to the Linux Filesystem configuration CONFIG_FS_FAT - Enable FAT filesystem support - CONFIG_FAT_SECTORSIZE - Max supported sector size CONFIG_FAT_LCNAMES - Enable use of the NT-style upper/lower case 8.3 file name support. CONFIG_FAT_LFN - Enable FAT long file names. NOTE: Microsoft claims @@ -912,7 +975,7 @@ defconfig -- This is a configuration file similar to the Linux ENC28J60 Ethernet Driver Configuration Settings: - CONFIG_NET_ENC28J60 - Enabled ENC28J60 support + CONFIG_ENC28J60 - Enabled ENC28J60 support CONFIG_ENC28J60_SPIMODE - Controls the SPI mode CONFIG_ENC28J60_FREQUENCY - Define to use a different bus frequency CONFIG_ENC28J60_NINTERFACES - Specifies the number of physical ENC28J60 @@ -951,7 +1014,10 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers - (may be zero) + (may be zero to disable TCP/IP read-ahead buffering) + CONFIG_NET_TCP_RECVDELAY - Delay (in deciseconds) after a TCP/IP packet + is received. This delay may allow catching of additional packets + when TCP/IP read-ahead is disabled. Default: 0 CONFIG_NET_TCPBACKLOG - Incoming connections pend in a backlog until accept() is called. The size of the backlog is selected when listen() is called. @@ -977,8 +1043,6 @@ defconfig -- This is a configuration file similar to the Linux from incoming IP packets. CONFIG_NET_BROADCAST - Incoming UDP broadcast support CONFIG_NET_MULTICAST - Outgoing multi-cast address support - CONFIG_NET_FWCACHE_SIZE - number of packets to remember when - looking for duplicates SLIP Driver. SLIP supports point-to-point IP communications over a serial port. The default data link layer for uIP is Ethernet. If CONFIG_NET_SLIP @@ -1415,8 +1479,6 @@ defconfig -- This is a configuration file similar to the Linux but copy themselves entirely into RAM for better performance. CONFIG_BOOT_RAMFUNCS - Other configurations may copy just some functions into RAM, either for better performance or for errata workarounds. - CONFIG_STACK_POINTER - The initial stack pointer (may not be supported - in all architectures). CONFIG_STACK_ALIGNMENT - Set if the your application has specific stack alignment requirements (may not be supported in all architectures). @@ -1506,6 +1568,10 @@ configs/ez80f0910200zco development kit, eZ80F091 part, and the Zilog ZDS-II Windows command line tools. The development environment is Cygwin under WinXP. +configs/fire-stm32v2 + A configuration for the M3 Wildfire STM32 board. This board is based on the + STM32F103VET6 chip. See http://firestm32.taobao.com + configs/hymini-stm32v A configuration for the HY-Mini STM32v board. This board is based on the STM32F103VCT chip. @@ -1667,6 +1733,10 @@ configs/sim This port does not support interrupts or a real timer (and hence no round robin scheduler) Otherwise, it is complete. +configs/shenzhou + This is the port of NuttX to the Shenzhou development board from + www.armjishu.com. This board features the STMicro STM32F107VCT MCU. + configs/skp16c26 Renesas M16C processor on the Renesas SKP16C26 StarterKit. This port uses the GNU m32c toolchain. STATUS: The port is complete but untested @@ -1735,7 +1805,7 @@ configs/z16f2800100zcog configs/z80sim z80 Microcontroller. This port uses a Z80 instruction set simulator. That simulator can be found in the NuttX SVN at - http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/misc/sims/z80sim. + http://svn.code.sf.net/p/nuttx/code/trunk/misc/sims/z80sim. This port also uses the SDCC toolchain (http://sdcc.sourceforge.net/") (verified with version 2.6.0). @@ -1778,3 +1848,26 @@ command line like: cd tools ./configure.sh -a / + +Building Symbol Tables +^^^^^^^^^^^^^^^^^^^^^^ + +Symbol tables are needed at several of the binfmt interfaces in order to bind +a module to the base code. These symbol tables can be tricky to create and +will probably have to be tailored for any specific application, balancing +the number of symbols and the size of the symbol table against the symbols +required by the applications. + +The top-level System.map file is one good source of symbol information +(which, or course, was just generated from the top-level nuttx file +using the GNU 'nm' tool). + +There are also common-separated value (CSV) values in the source try that +provide information about symbols. In particular: + + nuttx/syscall/syscall.csv - Describes the NuttX RTOS interface, and + nuttx/lib/lib.csv - Describes the NuttX C library interface. + +There is a tool at nuttx/tools/mksymtab that will use these CSV files as +input to generate a generic symbol table. See nuttx/tools/README.txt for +more information about using the mksymtab tool. diff --git a/nuttx/configs/px4fmu/Kconfig b/nuttx/configs/px4fmu/Kconfig new file mode 100644 index 0000000000..b5e6d5515f --- /dev/null +++ b/nuttx/configs/px4fmu/Kconfig @@ -0,0 +1,26 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +if ARCH_BOARD_PX4FMU +config ARCH_LEDS + bool "NuttX LED support" + default n + ---help--- + "Support control of board LEDs by NuttX to indicate system state" + +config ARCH_BUTTONS + bool "Button support" + default n + ---help--- + "Support interfaces to use buttons provided by the board." + +config ARCH_IRQBUTTONS + bool "Button interrupt support" + default n + depends on ARCH_BUTTONS + ---help--- + "Support EXTI interrupts on button presses and releases." + +endif diff --git a/nuttx/configs/px4fmu/common/ld.script b/nuttx/configs/px4fmu/common/ld.script index e3ca771b16..b1852b0bd9 100644 --- a/nuttx/configs/px4fmu/common/ld.script +++ b/nuttx/configs/px4fmu/common/ld.script @@ -75,8 +75,6 @@ SECTIONS *(.gnu.warning) *(.rodata .rodata.*) *(.gnu.linkonce.t.*) - *(.glue_7) - *(.glue_7t) *(.got) *(.gcc_except_table) *(.gnu.linkonce.r.*) @@ -89,6 +87,15 @@ SECTIONS __errno = get_errno_ptr; } > flash + /* + * Construction data for parameters. + */ + __param ALIGN(4): { + __param_start = ABSOLUTE(.); + KEEP(*(__param*)) + __param_end = ABSOLUTE(.); + } > flash + .ARM.extab : { *(.ARM.extab*) } > flash diff --git a/nuttx/configs/px4fmu/include/board.h b/nuttx/configs/px4fmu/include/board.h index 0db8580ba9..a7dae6552a 100755 --- a/nuttx/configs/px4fmu/include/board.h +++ b/nuttx/configs/px4fmu/include/board.h @@ -106,7 +106,7 @@ #define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(24) #define STM32_PLLCFG_PLLN RCC_PLLCFG_PLLN(336) #define STM32_PLLCFG_PLLP RCC_PLLCFG_PLLP_2 -#define STM32_PLLCFG_PPQ RCC_PLLCFG_PLLQ(7) +#define STM32_PLLCFG_PLLQ RCC_PLLCFG_PLLQ(7) #define STM32_SYSCLK_FREQUENCY 168000000ul @@ -265,15 +265,25 @@ /* * I2C + * + * The optional _GPIO configurations allow the I2C driver to manually + * reset the bus to clear stuck slaves. They match the pin configuration, + * but are normally-high GPIOs. */ -#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2 -#define GPIO_I2C1_SDA GPIO_I2C1_SDA_2 +#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2 +#define GPIO_I2C1_SDA GPIO_I2C1_SDA_2 +#define GPIO_I2C1_SCL_GPIO (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN8) +#define GPIO_I2C1_SDA_GPIO (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN9) -#define GPIO_I2C2_SCL GPIO_I2C2_SCL_1 -#define GPIO_I2C2_SDA GPIO_I2C2_SDA_1 +#define GPIO_I2C2_SCL GPIO_I2C2_SCL_1 +#define GPIO_I2C2_SDA GPIO_I2C2_SDA_1 +#define GPIO_I2C2_SCL_GPIO (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN10) +#define GPIO_I2C2_SDA_GPIO (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN11) -#define GPIO_I2C3_SCL GPIO_I2C3_SCL_1 -#define GPIO_I2C3_SDA GPIO_I2C3_SDA_1 +#define GPIO_I2C3_SCL GPIO_I2C3_SCL_1 +#define GPIO_I2C3_SDA GPIO_I2C3_SDA_1 +#define GPIO_I2C3_SCL_GPIO (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN8) +#define GPIO_I2C3_SDA_GPIO (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN9) /* * I2C busses @@ -289,7 +299,7 @@ */ #define PX4_I2C_OBDEV_HMC5883 0x1e #define PX4_I2C_OBDEV_MS5611 NOTDEFINED -#define PX4_I2C_OBDEV_EEPROM 0x50 +#define PX4_I2C_OBDEV_EEPROM NOTDEFINED #define PX4_I2C_OBDEV_PX4IO_BL 0x18 #define PX4_I2C_OBDEV_PX4IO 0x19 diff --git a/nuttx/configs/px4fmu/include/drv_eeprom.h b/nuttx/configs/px4fmu/include/drv_eeprom.h index e6801f6c4a..57589ed84b 100644 --- a/nuttx/configs/px4fmu/include/drv_eeprom.h +++ b/nuttx/configs/px4fmu/include/drv_eeprom.h @@ -31,34 +31,21 @@ * ****************************************************************************/ -/* - * Driver for the ST MS5611 gyroscope - */ - -/* IMPORTANT NOTES: - * - * SPI max. clock frequency: 10 Mhz - * CS has to be high before transfer, - * go low right before transfer and - * go high again right after transfer +/** + * @file drv_eeprom.h * + * Config for the non-MTD EEPROM driver. */ /* IMPORTANT: Adjust this number! */ -#define MAX_EEPROMS 2 +#define MAX_EEPROMS 2 /* FMU onboard */ -#define FMU_ONBOARD_EEPROM_ADDRESS 0x50 -#define FMU_ONBOARD_EEPROM_TOTAL_SIZE_BYTES 16000 -#define FMU_ONBOARD_EEPROM_PAGE_SIZE_BYTES 64 -#define FMU_ONBOARD_EEPROM_PAGE_WRITE_TIME_US 5500 -#define FMU_ONBOARD_EEPROM_BUS_CLOCK 1000000 ///< 1 Mhz max. clock - -#define FMU_BASEBOARD_EEPROM_ADDRESS 0x57 +#define FMU_BASEBOARD_EEPROM_ADDRESS 0x57 #define FMU_BASEBOARD_EEPROM_TOTAL_SIZE_BYTES 128 #define FMU_BASEBOARD_EEPROM_PAGE_SIZE_BYTES 8 #define FMU_BASEBOARD_EEPROM_PAGE_WRITE_TIME_US 3300 -#define FMU_BASEBOARD_EEPROM_BUS_CLOCK 400000 ///< 400 KHz max. clock +#define FMU_BASEBOARD_EEPROM_BUS_CLOCK 400000 ///< 400 KHz max. clock /** * @brief i2c I2C bus struct diff --git a/nuttx/configs/px4fmu/include/drv_mpu6000.h b/nuttx/configs/px4fmu/include/drv_mpu6000.h deleted file mode 100644 index 0a5a48b707..0000000000 --- a/nuttx/configs/px4fmu/include/drv_mpu6000.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2012 Lorenz Meier. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of the author or the names of contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Driver for the Invense MPU-6000 gyroscope - */ - -/* IMPORTANT NOTES: - * - * SPI max. clock frequency: 10 Mhz - * CS has to be high before transfer, - * go low right before transfer and - * go high again right after transfer - * - */ - -#include - -#define _MPU6000BASE 0x7600 -#define MPU6000C(_x) _IOC(_MPU6000BASE, _x) - -/* - * Sets the sensor internal sampling rate, and if a buffer - * has been configured, the rate at which entries will be - * added to the buffer. - */ -#define MPU6000_SETRATE MPU6000C(1) - -#define MPU6000_RATE_95HZ_LP_12_5HZ ((0<<7) | (0<<6) | (0<<5) | (0<<4)) - -/* - * Sets the sensor internal range. - */ -#define MPU6000_SETRANGE MPU6000C(2) - -#define MPU6000_RANGE_250DPS (0<<4) - -#define MPU6000_RATE_95HZ ((0<<6) | (0<<4)) - - - -/* - * Sets the address of a shared MPU6000_buffer - * structure that is maintained by the driver. - * - * If zero is passed as the address, disables - * the buffer updating. - */ -#define MPU6000_SETBUFFER MPU6000C(3) - -struct MPU6000_buffer { - uint32_t size; /* number of entries in the samples[] array */ - uint32_t next; /* the next entry that will be populated */ - struct { - uint16_t x; - uint16_t y; - uint16_t z; - uint16_t roll; - uint16_t pitch; - uint16_t yaw; - } samples[]; -}; - -extern int mpu6000_attach(struct spi_dev_s *spi, int spi_id); diff --git a/nuttx/configs/px4fmu/nsh/Make.defs b/nuttx/configs/px4fmu/nsh/Make.defs index 87508e22ec..3e6f88bd3a 100644 --- a/nuttx/configs/px4fmu/nsh/Make.defs +++ b/nuttx/configs/px4fmu/nsh/Make.defs @@ -1,3 +1,3 @@ include ${TOPDIR}/.config -include $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/common/Make.defs +include $(TOPDIR)/configs/px4fmu/common/Make.defs diff --git a/nuttx/configs/px4fmu/nsh/appconfig b/nuttx/configs/px4fmu/nsh/appconfig index 4f0c5093f5..fab4d6a7e5 100644 --- a/nuttx/configs/px4fmu/nsh/appconfig +++ b/nuttx/configs/px4fmu/nsh/appconfig @@ -45,42 +45,52 @@ CONFIGURED_APPS += system/readline CONFIGURED_APPS += systemlib CONFIGURED_APPS += systemlib/mixer +# System utility commands CONFIGURED_APPS += systemcmds/reboot CONFIGURED_APPS += systemcmds/perf CONFIGURED_APPS += systemcmds/top CONFIGURED_APPS += systemcmds/boardinfo CONFIGURED_APPS += systemcmds/mixer +CONFIGURED_APPS += systemcmds/eeprom +CONFIGURED_APPS += systemcmds/led +CONFIGURED_APPS += systemcmds/bl_update #CONFIGURED_APPS += systemcmds/calibration # Tutorial code from # https://pixhawk.ethz.ch/px4/dev/hello_sky # CONFIGURED_APPS += examples/px4_simple_app +# Tutorial code from +# https://pixhawk.ethz.ch/px4/dev/deamon +# CONFIGURED_APPS += examples/px4_deamon_app + +# Shared object broker; required by many parts of the system. CONFIGURED_APPS += uORB -ifeq ($(CONFIG_MAVLINK),y) CONFIGURED_APPS += mavlink -endif - CONFIGURED_APPS += gps CONFIGURED_APPS += commander -#CONFIGURED_APPS += sdlog +CONFIGURED_APPS += sdlog CONFIGURED_APPS += sensors -CONFIGURED_APPS += ardrone_control -CONFIGURED_APPS += multirotor_control +CONFIGURED_APPS += ardrone_interface +CONFIGURED_APPS += multirotor_att_control CONFIGURED_APPS += px4/attitude_estimator_bm CONFIGURED_APPS += fixedwing_control -CONFIGURED_APPS += mix_and_link CONFIGURED_APPS += position_estimator CONFIGURED_APPS += attitude_estimator_ekf +CONFIGURED_APPS += px4/ground_estimator +# Hacking tools #CONFIGURED_APPS += system/i2c #CONFIGURED_APPS += tools/i2c_dev # Communication and Drivers CONFIGURED_APPS += drivers/device CONFIGURED_APPS += drivers/ms5611 +CONFIGURED_APPS += drivers/hmc5883 CONFIGURED_APPS += drivers/mpu6000 +CONFIGURED_APPS += drivers/bma180 +CONFIGURED_APPS += drivers/l3gd20 CONFIGURED_APPS += px4/px4io/driver CONFIGURED_APPS += px4/fmu @@ -97,4 +107,3 @@ endif CONFIGURED_APPS += examples/cdcacm #endif #endif - diff --git a/nuttx/configs/px4fmu/nsh/defconfig b/nuttx/configs/px4fmu/nsh/defconfig index a87ce7ffac..e1ba862cf7 100755 --- a/nuttx/configs/px4fmu/nsh/defconfig +++ b/nuttx/configs/px4fmu/nsh/defconfig @@ -1,7 +1,8 @@ ############################################################################ # configs/px4fmu/nsh/defconfig # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -41,7 +42,7 @@ # particular chip family that the architecture is implemented # in. # CONFIG_ARCH_architecture - for use in C code. This identifies the -# specific architecture within the chip familyl. +# specific architecture within the chip family. # CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory # CONFIG_ARCH_CHIP_name - For use in C code # CONFIG_ARCH_BOARD - identifies the configs subdirectory and, hence, @@ -51,7 +52,6 @@ # CONFIG_BOARD_LOOPSPERMSEC - for delay loops # CONFIG_DRAM_SIZE - Describes the installed DRAM. # CONFIG_DRAM_START - The start address of DRAM (physical) -# CONFIG_DRAM_END - Last address+1 of installed RAM # CONFIG_ARCH_IRQPRIO - The STM3240xxx supports interrupt prioritization # CONFIG_ARCH_FPU - The STM3240xxx supports a floating point unit (FPU). # CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt @@ -70,17 +70,16 @@ # the delay actually is 100 seconds. # CONFIG_ARCH_DMA - Support DMA initialization # -CONFIG_ARCH=arm +CONFIG_ARCH="arm" CONFIG_ARCH_ARM=y CONFIG_ARCH_CORTEXM4=y -CONFIG_ARCH_CHIP=stm32 +CONFIG_ARCH_CHIP="stm32" CONFIG_ARCH_CHIP_STM32F405RG=y -CONFIG_ARCH_BOARD=px4fmu +CONFIG_ARCH_BOARD="px4fmu" CONFIG_ARCH_BOARD_PX4FMU=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_DRAM_SIZE=0x00030000 CONFIG_DRAM_START=0x20000000 -CONFIG_DRAM_END=(CONFIG_DRAM_START+CONFIG_DRAM_SIZE) CONFIG_ARCH_IRQPRIO=y CONFIG_ARCH_FPU=y CONFIG_ARCH_INTERRUPTSTACK=n @@ -94,26 +93,6 @@ CONFIG_ARCH_MATH_H=y CONFIG_ARMV7M_CMNVECTOR=y -# -# LIBC printf() options -# -# CONFIG_LIBC_FLOATINGPOINT - Enables printf("%f") -# CONFIG_LIBC_FIXEDPRECISION - Sets 7 digits after dot for printing: -# 5.1234567 -# CONFIG_HAVE_LONG_LONG - Enabled printf("%llu) -# -CONFIG_LIBC_FLOATINGPOINT=y -CONFIG_HAVE_LONG_LONG=y -#CONFIG_LIBC_FIXEDPRECISION=7 - -# -# CMSIS options -# -# CONFIG_DSPLIB_TARGET - Target for the CMSIS DSP library, one of -# CortexM0, CortexM3 or CortexM4 (with fpu) -# -CONFIG_CMSIS_DSPLIB_TARGET=CortexM4 - # # JTAG Enable settings (by default JTAG-DP and SW-DP are enabled): # @@ -131,6 +110,14 @@ CONFIG_STM32_JTAG_FULL_ENABLE=y CONFIG_STM32_JTAG_NOJNTRST_ENABLE=n CONFIG_STM32_JTAG_SW_ENABLE=n +# +# On-chip CCM SRAM configuration +# +# CONFIG_STM32_CCMEXCLUDE - Exclude CCM SRAM from the HEAP. You would need +# to do this if DMA is enabled to prevent non-DMA-able CCM memory from +# being a part of the stack. +# + # # On-board FSMC SRAM configuration # @@ -181,6 +168,7 @@ CONFIG_STM32_TIM12=y CONFIG_STM32_TIM13=y CONFIG_STM32_TIM14=y CONFIG_STM32_WWDG=y +CONFIG_STM32_IWDG=n CONFIG_STM32_SPI2=n CONFIG_STM32_SPI3=y CONFIG_STM32_USART2=y @@ -211,40 +199,17 @@ CONFIG_STM32_TIM9=y CONFIG_STM32_TIM10=y CONFIG_STM32_TIM11=y -# -# Configure the ADC -# -CONFIG_ADC=y -# select trigger timer -CONFIG_STM32_TIM4_ADC3=y -# select sample frequency 1^=1.5Msamples/second -# 65535^=10samples/second 16bit-timer runs at 84/128 MHz -CONFIG_STM32_ADC3_SAMPLE_FREQUENCY=6000 -# select timer channel 0=CC1,...,3=CC4 -CONFIG_STM32_ADC3_TIMTRIG=3 -CONFIG_ADC_DMA=y -# only 4 places usable! -CONFIG_ADC_FIFOSIZE=5 # -# Timer and I2C devices may need to the following to force power to be applied: +# Enable the MTD driver for the onboard I2C EEPROM # -#CONFIG_STM32_FORCEPOWER=y - +# Note that we are using a private copy of the AT24XX driver that +# does not require CONFIG_MTD_XT24XX to be set. # -# I2C configuration -# -CONFIG_I2C=y -CONFIG_I2C_POLLED=y -CONFIG_I2C_TRANSFER=y -CONFIG_I2C_WRITEREAD=y -CONFIG_I2C_TRACE=n -# Allow 180 us per byte, a wide margin for the 400 KHz clock we're using -# e.g. 9.6 ms for an EEPROM page write, 0.9 ms for a MAG update -CONFIG_STM32_I2CTIMEOUS_PER_BYTE=200 -# Constant overhead for generating I2C start / stop conditions -CONFIG_STM32_I2CTIMEOUS_START_STOP=700 -CONFIG_DEBUG_I2C=n +#CONFIG_MTD_AT24XX=y +CONFIG_AT24XX_ADDR=0x50 +CONFIG_AT24XX_SIZE=128 +CONFIG_AT24XX_MTD_BLOCKSIZE=256 # # STM32F40xxx specific serial device driver settings @@ -253,6 +218,9 @@ CONFIG_DEBUG_I2C=n # tcflush, etc.). If this is not defined, then the terminal settings (baud, # parity, etc.) are not configurable at runtime; serial streams cannot be # flushed, etc. +# CONFIG_SERIAL_CONSOLE_REINIT - re-initializes the console serial port +# immediately after creating the /dev/console device. This is required +# if the console serial port has RX DMA enabled. # # CONFIG_USARTn_SERIAL_CONSOLE - selects the USARTn for the # console and ttys0 (default is the USART1). @@ -266,62 +234,64 @@ CONFIG_DEBUG_I2C=n # CONFIG_USARTn_2STOP - Two stop bits # CONFIG_SERIAL_TERMIOS=y +CONFIG_SERIAL_CONSOLE_REINIT=y CONFIG_USART1_SERIAL_CONSOLE=y CONFIG_USART2_SERIAL_CONSOLE=n CONFIG_USART3_SERIAL_CONSOLE=n -CONFIG_USART4_SERIAL_CONSOLE=n -CONFIG_USART5_SERIAL_CONSOLE=n +CONFIG_UART4_SERIAL_CONSOLE=n +CONFIG_UART5_SERIAL_CONSOLE=n CONFIG_USART6_SERIAL_CONSOLE=n #Mavlink messages can be bigger than 128 CONFIG_USART1_TXBUFSIZE=512 CONFIG_USART2_TXBUFSIZE=128 CONFIG_USART3_TXBUFSIZE=128 -CONFIG_USART4_TXBUFSIZE=128 -CONFIG_USART5_TXBUFSIZE=64 +CONFIG_UART4_TXBUFSIZE=128 +CONFIG_UART5_TXBUFSIZE=64 CONFIG_USART6_TXBUFSIZE=128 CONFIG_USART1_RXBUFSIZE=512 CONFIG_USART2_RXBUFSIZE=128 CONFIG_USART3_RXBUFSIZE=128 -CONFIG_USART4_RXBUFSIZE=128 -CONFIG_USART5_RXBUFSIZE=128 +CONFIG_UART4_RXBUFSIZE=128 +CONFIG_UART5_RXBUFSIZE=128 CONFIG_USART6_RXBUFSIZE=128 CONFIG_USART1_BAUD=57600 CONFIG_USART2_BAUD=115200 CONFIG_USART3_BAUD=115200 -CONFIG_USART4_BAUD=115200 -CONFIG_USART5_BAUD=115200 +CONFIG_UART4_BAUD=115200 +CONFIG_UART5_BAUD=115200 CONFIG_USART6_BAUD=9600 CONFIG_USART1_BITS=8 CONFIG_USART2_BITS=8 CONFIG_USART3_BITS=8 -CONFIG_USART4_BITS=8 -CONFIG_USART5_BITS=8 +CONFIG_UART4_BITS=8 +CONFIG_UART5_BITS=8 CONFIG_USART6_BITS=8 CONFIG_USART1_PARITY=0 CONFIG_USART2_PARITY=0 CONFIG_USART3_PARITY=0 -CONFIG_USART4_PARITY=0 -CONFIG_USART5_PARITY=0 +CONFIG_UART4_PARITY=0 +CONFIG_UART5_PARITY=0 CONFIG_USART6_PARITY=0 CONFIG_USART1_2STOP=0 CONFIG_USART2_2STOP=0 CONFIG_USART3_2STOP=0 -CONFIG_USART4_2STOP=0 -CONFIG_USART5_2STOP=0 +CONFIG_UART4_2STOP=0 +CONFIG_UART5_2STOP=0 CONFIG_USART6_2STOP=0 -CONFIG_USART1_RXDMA=n +CONFIG_USART1_RXDMA=y +SERIAL_HAVE_CONSOLE_DMA=y CONFIG_USART2_RXDMA=y CONFIG_USART3_RXDMA=n -CONFIG_USART4_RXDMA=n -CONFIG_USART5_RXDMA=y +CONFIG_UART4_RXDMA=n +CONFIG_UART5_RXDMA=y CONFIG_USART6_RXDMA=y # @@ -356,13 +326,6 @@ CONFIG_TONE_ALARM=y CONFIG_PWM_SERVO=n CONFIG_MULTIPORT=n -# -# CONFIG_UART2_RTS_CTS_AS_GPIO -# If set, enables RTS and CTS pins as additional GPIOs 2 and 3 -# -CONFIG_PX4_UART2_RTS_CTS_AS_GPIO=y - - # # STM32F40xxx specific SPI device driver settings # @@ -375,6 +338,8 @@ CONFIG_SPI_EXCHANGE=y # # CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or # CONFIG_STM32_CAN2 must also be defined) +# CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default +# Standard 11-bit IDs. # CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages. # Default: 8 # CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests. @@ -383,14 +348,53 @@ CONFIG_SPI_EXCHANGE=y # mode for testing. The STM32 CAN driver does support loopback mode. # CONFIG_CAN1_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN1 is defined. # CONFIG_CAN2_BAUD - CAN1 BAUD rate. Required if CONFIG_STM32_CAN2 is defined. +# CONFIG_CAN_TSEG1 - The number of CAN time quanta in segment 1. Default: 6 +# CONFIG_CAN_TSEG2 - the number of CAN time quanta in segment 2. Default: 7 # CONFIG_CAN=n +CONFIG_CAN_EXTID=n #CONFIG_CAN_FIFOSIZE #CONFIG_CAN_NPENDINGRTR CONFIG_CAN_LOOPBACK=n CONFIG_CAN1_BAUD=700000 CONFIG_CAN2_BAUD=700000 +# +# I2C configuration +# +CONFIG_I2C=y +CONFIG_I2C_POLLED=y +CONFIG_I2C_TRANSFER=y +CONFIG_I2C_TRACE=n +# Allow 180 us per byte, a wide margin for the 400 KHz clock we're using +# e.g. 9.6 ms for an EEPROM page write, 0.9 ms for a MAG update +CONFIG_STM32_I2CTIMEOUS_PER_BYTE=200 +# Constant overhead for generating I2C start / stop conditions +CONFIG_STM32_I2CTIMEOUS_START_STOP=700 +# XXX this is bad and we want it gone +CONFIG_I2C_WRITEREAD=y + +# +# ADC configuration +# +# Enable ADC driver support. +# +# CONFIG_ADC=y : Enable the generic ADC infrastructure +# CONFIG_STM32_TIM1_ADC=y : Indicate that timer 1 will be used to trigger an ADC +# CONFIG_STM32_TIM1_ADC3=y : Assign timer 1 to drive ADC3 sampling +# CONFIG_STM32_ADC3_SAMPLE_FREQUENCY=100 : Select a sampling frequency +# +CONFIG_ADC=y +CONFIG_STM32_TIM4_ADC3=y +# select sample frequency 1^=1.5Msamples/second +# 65535^=10samples/second 16bit-timer runs at 84/128 MHz +CONFIG_STM32_ADC3_SAMPLE_FREQUENCY=6000 +# select timer channel 0=CC1,...,3=CC4 +CONFIG_STM32_ADC3_TIMTRIG=3 +CONFIG_ADC_DMA=y +# only 4 places usable! +CONFIG_ADC_FIFOSIZE=5 + # # General build options # @@ -408,7 +412,7 @@ CONFIG_CAN2_BAUD=700000 # CONFIG_HAVE_LIBM - toolchain supports libm.a # CONFIG_RRLOAD_BINARY=n -CONFIG_INTELHEX_BINARY=y +CONFIG_INTELHEX_BINARY=n CONFIG_MOTOROLA_SREC=n CONFIG_RAW_BINARY=y CONFIG_HAVE_LIBM=y @@ -423,6 +427,9 @@ CONFIG_HAVE_LIBM=y # CONFIG_DEBUG_SYMBOLS - build without optimization and with # debug symbols (needed for use with a debugger). # CONFIG_HAVE_CXX - Enable support for C++ +# CONFIG_HAVE_CXXINITIALIZE - The platform-specific logic includes support +# for initialization of static C++ instances for this architecture +# and for the selected toolchain (via up_cxxinitialize()). # CONFIG_MM_REGIONS - If the architecture includes multiple # regions of memory to allocate from, this specifies the # number of memory regions that the memory manager must @@ -485,38 +492,57 @@ CONFIG_HAVE_LIBM=y # desciptors by task_create() when a new task is started. If # set, all sockets will appear to be closed in the new task. # CONFIG_SCHED_WORKQUEUE. Create a dedicated "worker" thread to -# handle delayed processing from interrupt handlers. This feature -# is required for some drivers but, if there are not complaints, -# can be safely disabled. The worker thread also performs -# garbage collection -- completing any delayed memory deallocations -# from interrupt handlers. If the worker thread is disabled, -# then that clean will be performed by the IDLE thread instead -# (which runs at the lowest of priority and may not be appropriate -# if memory reclamation is of high priority). If CONFIG_SCHED_WORKQUEUE -# is enabled, then the following options can also be used: +# handle delayed processing from interrupt handlers. This feature +# is required for some drivers but, if there are not complaints, +# can be safely disabled. The worker thread also performs +# garbage collection -- completing any delayed memory deallocations +# from interrupt handlers. If the worker thread is disabled, +# then that clean will be performed by the IDLE thread instead +# (which runs at the lowest of priority and may not be appropriate +# if memory reclamation is of high priority). If CONFIG_SCHED_WORKQUEUE +# is enabled, then the following options can also be used: # CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker -# thread. Default: 50 +# thread. Default: 192 # CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for -# work in units of microseconds. Default: 50*1000 (50 MS). +# work in units of microseconds. Default: 50*1000 (50 MS). # CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker -# thread. Default: CONFIG_IDLETHREAD_STACKSIZE. +# thread. Default: CONFIG_IDLETHREAD_STACKSIZE. # CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up -# the worker thread. Default: 4 +# the worker thread. Default: 4 +# +# CONFIG_SCHED_LPWORK. If CONFIG_SCHED_WORKQUEUE is defined, then a single +# work queue is created by default. If CONFIG_SCHED_LPWORK is also defined +# then an additional, lower-priority work queue will also be created. This +# lower priority work queue is better suited for more extended processing +# (such as file system clean-up operations) +# CONFIG_SCHED_LPWORKPRIORITY - The execution priority of the lower priority +# worker thread. Default: 50 +# CONFIG_SCHED_LPWORKPERIOD - How often the lower priority worker thread +# checks for work in units of microseconds. Default: 50*1000 (50 MS). +# CONFIG_SCHED_LPWORKSTACKSIZE - The stack size allocated for the lower +# priority worker thread. Default: CONFIG_IDLETHREAD_STACKSIZE. # CONFIG_SCHED_WAITPID - Enable the waitpid() API # CONFIG_SCHED_ATEXIT - Enabled the atexit() API # +CONFIG_USER_ENTRYPOINT="nsh_main" #CONFIG_APPS_DIR= CONFIG_DEBUG=y CONFIG_DEBUG_VERBOSE=y CONFIG_DEBUG_SYMBOLS=y -CONFIG_DEBUG_ANALOG=n CONFIG_DEBUG_FS=n CONFIG_DEBUG_GRAPHICS=n CONFIG_DEBUG_LCD=n CONFIG_DEBUG_USB=n CONFIG_DEBUG_NET=n CONFIG_DEBUG_RTC=n +CONFIG_DEBUG_ANALOG=n +CONFIG_DEBUG_PWM=n +CONFIG_DEBUG_CAN=n +CONFIG_DEBUG_I2C=n +CONFIG_DEBUG_INPUT=n + CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=n CONFIG_MM_REGIONS=2 CONFIG_ARCH_LOWPUTC=y CONFIG_MSEC_PER_TICK=1 @@ -538,13 +564,49 @@ CONFIG_FDCLONE_DISABLE=n CONFIG_FDCLONE_STDIO=y CONFIG_SDCLONE_DISABLE=y CONFIG_SCHED_WORKQUEUE=y -CONFIG_SCHED_WORKPRIORITY=199 -CONFIG_SCHED_WORKPERIOD=(5*1000) +CONFIG_SCHED_WORKPRIORITY=192 +CONFIG_SCHED_WORKPERIOD=5000 CONFIG_SCHED_WORKSTACKSIZE=2048 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_LPWORKPRIORITY=50 +CONFIG_SCHED_LPWORKPERIOD=50000 +CONFIG_SCHED_LPWORKSTACKSIZE=2048 CONFIG_SIG_SIGWORK=4 CONFIG_SCHED_WAITPID=y CONFIG_SCHED_ATEXIT=n +# +# System Logging +# +# CONFIG_SYSLOG - Enables the System Logging feature. +# CONFIG_RAMLOG - Enables the RAM logging feature +# CONFIG_RAMLOG_CONSOLE - Use the RAM logging device as a system console. +# If this feature is enabled (along with CONFIG_DEV_CONSOLE), then all +# console output will be re-directed to a circular buffer in RAM. This +# is useful, for example, if the only console is a Telnet console. Then +# in that case, console output from non-Telnet threads will go to the +# circular buffer and can be viewed using the NSH 'dmesg' command. +# CONFIG_RAMLOG_SYSLOG - Use the RAM logging device for the syslogging +# interface. If this feature is enabled (along with CONFIG_SYSLOG), +# then all debug output (only) will be re-directed to the circular +# buffer in RAM. This RAM log can be view from NSH using the 'dmesg' +# command. +# CONFIG_RAMLOG_NPOLLWAITERS - The number of threads than can be waiting +# for this driver on poll(). Default: 4 +# +# If CONFIG_RAMLOG_CONSOLE or CONFIG_RAMLOG_SYSLOG is selected, then the +# following may also be provided: +# +# CONFIG_RAMLOG_CONSOLE_BUFSIZE - Size of the console RAM log. Default: 1024 +# + +CONFIG_SYSLOG=n +CONFIG_RAMLOG=n +CONFIG_RAMLOG_CONSOLE=n +CONFIG_RAMLOG_SYSLOG=n +#CONFIG_RAMLOG_NPOLLWAITERS +#CONFIG_RAMLOG_CONSOLE_BUFSIZE + # # The following can be used to disable categories of # APIs supported by the OS. If the compiler supports @@ -574,8 +636,14 @@ CONFIG_DISABLE_POLL=n # # CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a # little smaller if we do not support fieldwidthes +# CONFIG_LIBC_FLOATINGPOINT - Enables printf("%f") +# CONFIG_LIBC_FIXEDPRECISION - Sets 7 digits after dot for printing: +# 5.1234567 +# CONFIG_HAVE_LONG_LONG - Enabled printf("%llu) # CONFIG_NOPRINTF_FIELDWIDTH=n +CONFIG_LIBC_FLOATINGPOINT=y +CONFIG_HAVE_LONG_LONG=y # # Allow for architecture optimized implementations @@ -640,8 +708,8 @@ CONFIG_ARCH_BZERO=n CONFIG_MAX_TASKS=32 CONFIG_MAX_TASK_ARGS=8 CONFIG_NPTHREAD_KEYS=4 -CONFIG_NFILE_DESCRIPTORS=20 -CONFIG_NFILE_STREAMS=20 +CONFIG_NFILE_DESCRIPTORS=25 +CONFIG_NFILE_STREAMS=25 CONFIG_NAME_MAX=32 CONFIG_STDIO_BUFFER_SIZE=256 CONFIG_STDIO_LINEBUFFER=y @@ -699,7 +767,10 @@ CONFIG_FS_FAT=y CONFIG_FAT_LCNAMES=y CONFIG_FAT_LFN=y CONFIG_FAT_MAXFNAME=32 -CONFIG_FS_NXFFS=n +CONFIG_FS_NXFFS=y +CONFIG_NXFFS_MAXNAMLEN=32 +CONFIG_NXFFS_TAILTHRESHOLD=2048 +CONFIG_NXFFS_PREALLOCATED=y CONFIG_FS_ROMFS=y # @@ -788,42 +859,6 @@ CONFIG_USBDEV_MAXPOWER=500 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=512 -# -# USB Serial Device Configuration (Prolifics PL2303 emulation) -# -# CONFIG_PL2303 -# Enable compilation of the USB serial driver -# CONFIG_PL2303_EPINTIN -# The logical 7-bit address of a hardware endpoint that supports -# interrupt IN operation -# CONFIG_PL2303_EPBULKOUT -# The logical 7-bit address of a hardware endpoint that supports -# bulk OUT operation -# CONFIG_PL2303_EPBULKIN -# The logical 7-bit address of a hardware endpoint that supports -# bulk IN operation -# # CONFIG_PL2303_NWRREQS and CONFIG_PL2303_NRDREQS -# The number of write/read requests that can be in flight -# CONFIG_PL2303_VENDORID and CONFIG_PL2303_VENDORSTR -# The vendor ID code/string -# CONFIG_PL2303_PRODUCTID and CONFIG_PL2303_PRODUCTSTR -# The product ID code/string -# CONFIG_PL2303_RXBUFSIZE and CONFIG_PL2303_TXBUFSIZE -# Size of the serial receive/transmit buffers -# -CONFIG_PL2303=n -CONFIG_PL2303_EPINTIN=1 -CONFIG_PL2303_EPBULKOUT=2 -CONFIG_PL2303_EPBULKIN=3 -CONFIG_PL2303_NWRREQS=4 -CONFIG_PL2303_NRDREQS=4 -CONFIG_PL2303_VENDORID=0x067b -CONFIG_PL2303_PRODUCTID=0x2303 -CONFIG_PL2303_VENDORSTR="Nuttx" -CONFIG_PL2303_PRODUCTSTR="USBdev Serial" -CONFIG_PL2303_RXBUFSIZE=512 -CONFIG_PL2303_TXBUFSIZE=512 - # # USB serial device class driver (Standard CDC ACM class) # @@ -896,44 +931,6 @@ CONFIG_CDCACM_PRODUCTSTR="PX4 FMU v1.6" #CONFIG_CDCACM_RXBUFSIZE #CONFIG_CDCACM_TXBUFSIZE -# -# USB Storage Device Configuration -# -# CONFIG_USBMSC -# Enable compilation of the USB storage driver -# CONFIG_USBMSC_EP0MAXPACKET -# Max packet size for endpoint 0 -# CONFIG_USBMSC_EPBULKOUT and CONFIG_USBMSC_EPBULKIN -# The logical 7-bit address of a hardware endpoints that support -# bulk OUT and IN operations -# CONFIG_USBMSC_NWRREQS and CONFIG_USBMSC_NRDREQS -# The number of write/read requests that can be in flight -# CONFIG_USBMSC_BULKINREQLEN and CONFIG_USBMSC_BULKOUTREQLEN -# The size of the buffer in each write/read request. This -# value needs to be at least as large as the endpoint -# maxpacket and ideally as large as a block device sector. -# CONFIG_USBMSC_VENDORID and CONFIG_USBMSC_VENDORSTR -# The vendor ID code/string -# CONFIG_USBMSC_PRODUCTID and CONFIG_USBMSC_PRODUCTSTR -# The product ID code/string -# CONFIG_USBMSC_REMOVABLE -# Select if the media is removable -# -CONFIG_USBMSC=n -CONFIG_USBMSC_EP0MAXPACKET=64 -CONFIG_USBMSC_EPBULKOUT=2 -CONFIG_USBMSC_EPBULKIN=5 -CONFIG_USBMSC_NRDREQS=2 -CONFIG_USBMSC_NWRREQS=2 -CONFIG_USBMSC_BULKINREQLEN=256 -CONFIG_USBMSC_BULKOUTREQLEN=256 -CONFIG_USBMSC_VENDORID=0x584e -CONFIG_USBMSC_VENDORSTR="NuttX" -CONFIG_USBMSC_PRODUCTID=0x5342 -CONFIG_USBMSC_PRODUCTSTR="USBdev Storage" -CONFIG_USBMSC_VERSIONNO=0x0399 -CONFIG_USBMSC_REMOVABLE=y - # # Settings for apps/nshlib @@ -944,7 +941,7 @@ CONFIG_USBMSC_REMOVABLE=y # CONFIG_NSH_FILEIOSIZE - Size of a static I/O buffer # CONFIG_NSH_STRERROR - Use strerror(errno) # CONFIG_NSH_LINELEN - Maximum length of one command line -# CONFIG_NSH_STACKSIZE - Stack size to use for new threads. +# CONFIG_NSH_MAX_ARGUMENTS - Maximum number of arguments for command line # CONFIG_NSH_NESTDEPTH - Max number of nested if-then[-else]-fi # CONFIG_NSH_DISABLESCRIPT - Disable scripting support # CONFIG_NSH_DISABLEBG - Disable background commands @@ -976,6 +973,7 @@ CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_STRERROR=y CONFIG_NSH_LINELEN=128 +CONFIG_NSH_MAX_ARGUMENTS=12 CONFIG_NSH_NESTDEPTH=8 CONFIG_NSH_DISABLESCRIPT=n CONFIG_NSH_DISABLEBG=n @@ -989,9 +987,9 @@ CONFIG_NSH_ARCHINIT=y CONFIG_NSH_IOBUFFER_SIZE=512 CONFIG_NSH_DHCPC=n CONFIG_NSH_NOMAC=y -CONFIG_NSH_IPADDR=(10<<24|0<<16|0<<8|2) -CONFIG_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1) -CONFIG_NSH_NETMASK=(255<<24|255<<16|255<<8|0) +CONFIG_NSH_IPADDR=0x0a000002 +CONFIG_NSH_DRIPADDR=0x0a000001 +CONFIG_NSH_NETMASK=0xffffff00 CONFIG_NSH_ROMFSMOUNTPT="/etc" CONFIG_NSH_INITSCRIPT="init.d/rcS" CONFIG_NSH_ROMFSDEVNO=0 @@ -1008,13 +1006,6 @@ CONFIG_NSH_MMCSDSPIPORTNO=3 CONFIG_NSH_MMCSDSLOTNO=0 CONFIG_NSH_MMCSDMINOR=0 -# -# Settings for mavlink -# -# CONFIG_MAVLINK - Enable MAVLINK app -# CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function. -# Default: Built as a standalone problem -CONFIG_MAVLINK=y # # Stack and heap information @@ -1045,8 +1036,10 @@ CONFIG_CUSTOM_STACK=n CONFIG_STACK_POINTER= # Idle thread needs 4096 bytes # default 1 KB is not enough -CONFIG_IDLETHREAD_STACKSIZE=4096 -CONFIG_USERMAIN_STACKSIZE=3072 +# 4096 bytes +CONFIG_IDLETHREAD_STACKSIZE=6000 +# USERMAIN stack size probably needs to be around 4096 bytes +CONFIG_USERMAIN_STACKSIZE=4096 CONFIG_PTHREAD_STACK_MIN=512 CONFIG_PTHREAD_STACK_DEFAULT=2048 CONFIG_HEAP_BASE= diff --git a/nuttx/configs/px4fmu/src/Makefile b/nuttx/configs/px4fmu/src/Makefile index 2e3138aaa0..5a60b7d197 100644 --- a/nuttx/configs/px4fmu/src/Makefile +++ b/nuttx/configs/px4fmu/src/Makefile @@ -42,9 +42,9 @@ AOBJS = $(ASRCS:.S=$(OBJEXT)) CSRCS = up_boot.c up_leds.c up_spi.c up_hrt.c \ drv_gpio.c drv_bma180.c drv_l3gd20.c \ - drv_led.c drv_hmc5833l.c drv_ms5611.c drv_eeprom.c \ + drv_led.c drv_eeprom.c \ drv_tone_alarm.c up_pwm_servo.c up_usbdev.c \ - up_cpuload.c drv_mpu6000.c + up_cpuload.c ifeq ($(CONFIG_NSH_ARCHINIT),y) CSRCS += up_nsh.c diff --git a/nuttx/configs/px4fmu/src/drv_hmc5833l.c b/nuttx/configs/px4fmu/src/drv_hmc5833l.c index df6e26d4b6..d51d654f7b 100644 --- a/nuttx/configs/px4fmu/src/drv_hmc5833l.c +++ b/nuttx/configs/px4fmu/src/drv_hmc5833l.c @@ -323,13 +323,20 @@ hmc5883l_ioctl(struct file *filp, int cmd, unsigned long arg) return result; } +extern int up_i2creset(FAR struct i2c_dev_s * dev); + int hmc5883l_reset() { int ret; +#if 1 + ret = up_i2creset(hmc5883l_dev.i2c); + printf("HMC5883: BUS RESET %s\n", ret ? "FAIL" : "OK"); +#else printf("[hmc5883l drv] Resettet I2C2 BUS\n"); up_i2cuninitialize(hmc5883l_dev.i2c); hmc5883l_dev.i2c = up_i2cinitialize(2); I2C_SETFREQUENCY(hmc5883l_dev.i2c, 400000); +#endif return ret; } diff --git a/nuttx/configs/px4fmu/src/drv_mpu6000.c b/nuttx/configs/px4fmu/src/drv_mpu6000.c deleted file mode 100644 index aded703189..0000000000 --- a/nuttx/configs/px4fmu/src/drv_mpu6000.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2012 Lorenz Meier. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of the author or the names of contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Driver for the ST mpu6000 MEMS gyroscope - */ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "chip.h" -#include "stm32_internal.h" -#include "px4fmu-internal.h" - -#include - -#define DIR_READ (0x80) -#define DIR_WRITE (0<<7) -#define ADDR_INCREMENT (1<<6) - -#define WHO_I_AM 0xD4 - -// MPU 6000 registers -#define MPUREG_WHOAMI 0x75 // -#define MPUREG_SMPLRT_DIV 0x19 // -#define MPUREG_CONFIG 0x1A // -#define MPUREG_GYRO_CONFIG 0x1B -#define MPUREG_ACCEL_CONFIG 0x1C -#define MPUREG_FIFO_EN 0x23 -#define MPUREG_INT_PIN_CFG 0x37 -#define MPUREG_INT_ENABLE 0x38 -#define MPUREG_INT_STATUS 0x3A -#define MPUREG_ACCEL_XOUT_H 0x3B // -#define MPUREG_ACCEL_XOUT_L 0x3C // -#define MPUREG_ACCEL_YOUT_H 0x3D // -#define MPUREG_ACCEL_YOUT_L 0x3E // -#define MPUREG_ACCEL_ZOUT_H 0x3F // -#define MPUREG_ACCEL_ZOUT_L 0x40 // -#define MPUREG_TEMP_OUT_H 0x41// -#define MPUREG_TEMP_OUT_L 0x42// -#define MPUREG_GYRO_XOUT_H 0x43 // -#define MPUREG_GYRO_XOUT_L 0x44 // -#define MPUREG_GYRO_YOUT_H 0x45 // -#define MPUREG_GYRO_YOUT_L 0x46 // -#define MPUREG_GYRO_ZOUT_H 0x47 // -#define MPUREG_GYRO_ZOUT_L 0x48 // -#define MPUREG_USER_CTRL 0x6A // -#define MPUREG_PWR_MGMT_1 0x6B // -#define MPUREG_PWR_MGMT_2 0x6C // -#define MPUREG_FIFO_COUNTH 0x72 -#define MPUREG_FIFO_COUNTL 0x73 -#define MPUREG_FIFO_R_W 0x74 -#define MPUREG_PRODUCT_ID 0x0C // Product ID Register - - -// Configuration bits MPU 3000 and MPU 6000 (not revised)? -#define BIT_SLEEP 0x40 -#define BIT_H_RESET 0x80 -#define BITS_CLKSEL 0x07 -#define MPU_CLK_SEL_PLLGYROX 0x01 -#define MPU_CLK_SEL_PLLGYROZ 0x03 -#define MPU_EXT_SYNC_GYROX 0x02 -#define BITS_FS_250DPS 0x00 -#define BITS_FS_500DPS 0x08 -#define BITS_FS_1000DPS 0x10 -#define BITS_FS_2000DPS 0x18 -#define BITS_FS_MASK 0x18 -#define BITS_DLPF_CFG_256HZ_NOLPF2 0x00 -#define BITS_DLPF_CFG_188HZ 0x01 -#define BITS_DLPF_CFG_98HZ 0x02 -#define BITS_DLPF_CFG_42HZ 0x03 -#define BITS_DLPF_CFG_20HZ 0x04 -#define BITS_DLPF_CFG_10HZ 0x05 -#define BITS_DLPF_CFG_5HZ 0x06 -#define BITS_DLPF_CFG_2100HZ_NOLPF 0x07 -#define BITS_DLPF_CFG_MASK 0x07 -#define BIT_INT_ANYRD_2CLEAR 0x10 -#define BIT_RAW_RDY_EN 0x01 -#define BIT_I2C_IF_DIS 0x10 -#define BIT_INT_STATUS_DATA 0x01 - // Product ID Description for MPU6000 - // high 4 bits low 4 bits - // Product Name Product Revision -#define MPU6000ES_REV_C4 0x14 // 0001 0100 -#define MPU6000ES_REV_C5 0x15 // 0001 0101 -#define MPU6000ES_REV_D6 0x16 // 0001 0110 -#define MPU6000ES_REV_D7 0x17 // 0001 0111 -#define MPU6000ES_REV_D8 0x18 // 0001 1000 -#define MPU6000_REV_C4 0x54 // 0101 0100 -#define MPU6000_REV_C5 0x55 // 0101 0101 -#define MPU6000_REV_D6 0x56 // 0101 0110 -#define MPU6000_REV_D7 0x57 // 0101 0111 -#define MPU6000_REV_D8 0x58 // 0101 1000 -#define MPU6000_REV_D9 0x59 // 0101 1001 -#define MPU6000_REV_D10 0x5A // 0101 1010 - -static FAR struct mpu6000_dev_s mpu6000_dev; - -static ssize_t mpu6000_read(struct file *filp, FAR char *buffer, size_t buflen); -static int mpu6000_ioctl(struct file *filp, int cmd, unsigned long arg); - -static const struct file_operations mpu6000_fops = { - .open = 0, - .close = 0, - .read = mpu6000_read, - .write = 0, - .seek = 0, - .ioctl = mpu6000_ioctl, -#ifndef CONFIG_DISABLE_POLL - .poll = 0 -#endif -}; - -struct mpu6000_dev_s -{ - struct spi_dev_s *spi; - int spi_id; - uint8_t rate; - struct mpu6000_buffer *buffer; -}; - -static void mpu6000_write_reg(uint8_t address, uint8_t data); -static uint8_t mpu6000_read_reg(uint8_t address); - -static void -mpu6000_write_reg(uint8_t address, uint8_t data) -{ - uint8_t cmd[2] = { address | DIR_WRITE, data }; - - SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, true); - SPI_SNDBLOCK(mpu6000_dev.spi, &cmd, sizeof(cmd)); - SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, false); -} - -static uint8_t -mpu6000_read_reg(uint8_t address) -{ - uint8_t cmd[2] = {address | DIR_READ, 0}; - uint8_t data[2]; - - SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, true); - SPI_EXCHANGE(mpu6000_dev.spi, cmd, data, sizeof(cmd)); - SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, false); - - return data[1]; -} - -static int16_t -mpu6000_read_int16(uint8_t address) -{ - uint8_t cmd[3] = {address | DIR_READ, 0, 0}; - uint8_t data[3]; - - SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, true); - SPI_EXCHANGE(mpu6000_dev.spi, cmd, data, sizeof(cmd)); - SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, false); - - return (((int16_t)data[1])<<8) | data[2]; -} - -static int -mpu6000_set_range(uint8_t range) -{ -// /* mask out illegal bit positions */ -// uint8_t write_range = range & REG4_RANGE_MASK; -// /* immediately return if user supplied invalid value */ -// if (write_range != range) return EINVAL; -// /* set remaining bits to a sane value */ -// write_range |= REG4_BDU; -// /* write to device */ -// write_reg(ADDR_CTRL_REG4, write_range); -// /* return 0 if register value is now written value, 1 if unchanged */ -// return !(read_reg(ADDR_CTRL_REG4) == write_range); -} - -static int -mpu6000_set_rate(uint8_t rate) -{ -// /* mask out illegal bit positions */ -// uint8_t write_rate = rate & REG1_RATE_LP_MASK; -// /* immediately return if user supplied invalid value */ -// if (write_rate != rate) return EINVAL; -// /* set remaining bits to a sane value */ -// write_rate |= REG1_POWER_NORMAL | REG1_Z_ENABLE | REG1_Y_ENABLE | REG1_X_ENABLE; -// /* write to device */ -// write_reg(ADDR_CTRL_REG1, write_rate); -// /* return 0 if register value is now written value, 1 if unchanged */ -// return !(read_reg(ADDR_CTRL_REG1) == write_rate); -} - -static int -mpu6000_read_fifo(int16_t *data) -{ -// struct { /* status register and data as read back from the device */ -// uint8_t cmd; -// uint8_t temp; -// uint8_t status; -// int16_t x; -// int16_t y; -// int16_t z; -// } __attribute__((packed)) report; -// -// report.cmd = ADDR_OUT_TEMP | DIR_READ | ADDR_INCREMENT; -// -// /* exchange the report structure with the device */ -// SPI_LOCK(mpu6000_dev.spi, true); -// -// SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, true); -// -// read_reg(ADDR_WHO_AM_I); -// -// SPI_EXCHANGE(mpu6000_dev.spi, &report, &report, sizeof(report)); -// SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, false); -// -// SPI_LOCK(mpu6000_dev.spi, false); -// -// -// - // - - // Device has MSB first at lower address (big endian) - - - struct { /* status register and data as read back from the device */ - // uint8_t cmd; - // uint8_t int_status; - int16_t xacc; - int16_t yacc; - int16_t zacc; - int16_t temp; - int16_t rollspeed; - int16_t pitchspeed; - int16_t yawspeed; - } report; - - uint8_t cmd[sizeof(report)]; - cmd[0] = MPUREG_ACCEL_XOUT_H | DIR_READ; // was addr_incr - - SPI_LOCK(mpu6000_dev.spi, true); - SPI_SELECT(mpu6000_dev.spi, PX4_SPIDEV_MPU, true); - report.xacc = mpu6000_read_int16(MPUREG_ACCEL_XOUT_H); - report.yacc = mpu6000_read_int16(MPUREG_ACCEL_YOUT_H); - report.zacc = mpu6000_read_int16(MPUREG_ACCEL_ZOUT_H); - report.rollspeed = mpu6000_read_int16(MPUREG_GYRO_XOUT_H); - report.pitchspeed = mpu6000_read_int16(MPUREG_GYRO_YOUT_H); - report.yawspeed = mpu6000_read_int16(MPUREG_GYRO_ZOUT_H); - SPI_SELECT(mpu6000_dev.spi, PX4_SPIDEV_MPU, false); - SPI_LOCK(mpu6000_dev.spi, false); - - data[0] = report.xacc; - data[1] = report.yacc; - data[2] = report.zacc; - data[3] = report.rollspeed; - data[4] = report.pitchspeed; - data[5] = report.yawspeed; - - return 1;//(report.int_status & 0x01); -} - -static ssize_t -mpu6000_read(struct file *filp, char *buffer, size_t buflen) -{ - /* if the buffer is large enough, and data are available, return success */ - if (buflen >= 12) { - if (mpu6000_read_fifo((int16_t *)buffer)) - return 12; - - /* no data */ - return 0; - } - - /* buffer too small */ - errno = ENOSPC; - return ERROR; -} - -static int -mpu6000_ioctl(struct file *filp, int cmd, unsigned long arg) -{ - int result = ERROR; - - switch (cmd) { - case MPU6000_SETRATE: - if ((arg & 0x00/* XXX REG MASK MISSING */) == arg) { - SPI_LOCK(mpu6000_dev.spi, true); - mpu6000_set_rate(arg); - SPI_LOCK(mpu6000_dev.spi, false); - result = 0; - mpu6000_dev.rate = arg; - } - break; - - case MPU6000_SETRANGE: - if ((arg & 0x00/* XXX REG MASK MISSING */) == arg) { - SPI_LOCK(mpu6000_dev.spi, true); - mpu6000_set_range(arg); - SPI_LOCK(mpu6000_dev.spi, false); - result = 0; - } - break; - - case MPU6000_SETBUFFER: - mpu6000_dev.buffer = (struct mpu6000_buffer *)arg; - result = 0; - break; - } - - if (result) - errno = EINVAL; - return result; -} - -int -mpu6000_attach(struct spi_dev_s *spi, int spi_id) -{ - int result = ERROR; - - mpu6000_dev.spi = spi; - mpu6000_dev.spi_id = spi_id; - - SPI_LOCK(mpu6000_dev.spi, true); - - // Set sensor-specific SPI mode - SPI_SETFREQUENCY(mpu6000_dev.spi, 10000000); // 500 KHz - SPI_SETBITS(mpu6000_dev.spi, 8); - // Either mode 1 or mode 3 - SPI_SETMODE(mpu6000_dev.spi, SPIDEV_MODE3); - - // Chip reset - mpu6000_write_reg(MPUREG_PWR_MGMT_1, BIT_H_RESET); - up_udelay(10000); - // Wake up device and select GyroZ clock (better performance) - mpu6000_write_reg(MPUREG_PWR_MGMT_1, MPU_CLK_SEL_PLLGYROZ); - up_udelay(1000); - // Disable I2C bus (recommended on datasheet) - mpu6000_write_reg(MPUREG_USER_CTRL, BIT_I2C_IF_DIS); - up_udelay(1000); - // SAMPLE RATE - mpu6000_write_reg(MPUREG_SMPLRT_DIV,0x04); // Sample rate = 200Hz Fsample= 1Khz/(4+1) = 200Hz - usleep(1000); - // FS & DLPF FS=2000¼/s, DLPF = 98Hz (low pass filter) - mpu6000_write_reg(MPUREG_CONFIG, BITS_DLPF_CFG_98HZ); - usleep(1000); - mpu6000_write_reg(MPUREG_GYRO_CONFIG,BITS_FS_2000DPS); // Gyro scale 2000¼/s - usleep(1000); - - uint8_t _product_id = mpu6000_read_reg(MPUREG_PRODUCT_ID); - printf("MPU-6000 product id: %d\n", (int)_product_id); - - if ((_product_id == MPU6000ES_REV_C4) || (_product_id == MPU6000ES_REV_C5) || - (_product_id == MPU6000_REV_C4) || (_product_id == MPU6000_REV_C5)){ - // Accel scale 8g (4096 LSB/g) - // Rev C has different scaling than rev D - mpu6000_write_reg(MPUREG_ACCEL_CONFIG,1<<3); - } else { - // Accel scale 8g (4096 LSB/g) - mpu6000_write_reg(MPUREG_ACCEL_CONFIG,2<<3); - } - usleep(1000); - - // INT CFG => Interrupt on Data Ready - mpu6000_write_reg(MPUREG_INT_ENABLE,BIT_RAW_RDY_EN); // INT: Raw data ready - usleep(1000); - mpu6000_write_reg(MPUREG_INT_PIN_CFG,BIT_INT_ANYRD_2CLEAR); // INT: Clear on any read - usleep(1000); - // Oscillator set - // write_reg(MPUREG_PWR_MGMT_1,MPU_CLK_SEL_PLLGYROZ); - usleep(1000); - - /* revert back to normal bus mode */ - SPI_SETFREQUENCY(mpu6000_dev.spi, 10000000); - SPI_SETBITS(mpu6000_dev.spi, 8); - SPI_SETMODE(mpu6000_dev.spi, SPIDEV_MODE3); - - /* verify that the device is attached and functioning */ - if ((_product_id == MPU6000ES_REV_C4) || (_product_id == MPU6000ES_REV_C5) || - (_product_id == MPU6000_REV_C4) || (_product_id == MPU6000_REV_C5) || - (_product_id == MPU6000_REV_D7) || (_product_id == MPU6000_REV_D8) || - (_product_id == MPU6000_REV_D9) || (_product_id == MPU6000_REV_D10)){ - - /* make ourselves available */ - register_driver("/dev/mpu6000", &mpu6000_fops, 0666, NULL); - - result = OK; - } else { - - errno = EIO; - } - - SPI_LOCK(mpu6000_dev.spi, false); - - SPI_LOCK(mpu6000_dev.spi, false); - - return result; -} diff --git a/nuttx/configs/px4fmu/src/up_cpuload.c b/nuttx/configs/px4fmu/src/up_cpuload.c index 750ec48522..bf867ae8b0 100644 --- a/nuttx/configs/px4fmu/src/up_cpuload.c +++ b/nuttx/configs/px4fmu/src/up_cpuload.c @@ -45,6 +45,7 @@ #include #include +#include #include #include diff --git a/nuttx/configs/px4fmu/src/up_hrt.c b/nuttx/configs/px4fmu/src/up_hrt.c index 507358f8bd..c8ff1ce383 100644 --- a/nuttx/configs/px4fmu/src/up_hrt.c +++ b/nuttx/configs/px4fmu/src/up_hrt.c @@ -244,9 +244,21 @@ */ static struct sq_queue_s callout_queue; +/* latency baseline (last compare value applied) */ +static uint16_t latency_baseline; + +/* timer count at interrupt (for latency purposes) */ +static uint16_t latency_actual; + +/* latency histogram */ +#define LATENCY_BUCKET_COUNT 8 +static const uint16_t latency_buckets[LATENCY_BUCKET_COUNT] = { 1, 2, 5, 10, 20, 50, 100, 1000 }; +static uint32_t latency_counters[LATENCY_BUCKET_COUNT + 1]; + /* timer-specific functions */ static void hrt_tim_init(void); static int hrt_tim_isr(int irq, void *context); +static void hrt_latency_update(void); /* callout list manipulation */ static void hrt_call_internal(struct hrt_call *entry, @@ -302,9 +314,9 @@ static void hrt_call_invoke(void); * PPM decoder tuning parameters */ # define PPM_MAX_PULSE_WIDTH 500 /* maximum width of a pulse */ -# define PPM_MIN_CHANNEL_VALUE 750 /* shortest valid channel signal */ -# define PPM_MAX_CHANNEL_VALUE 2400 /* longest valid channel signal */ -# define PPM_MIN_START 5000 /* shortest valid start gap */ +# define PPM_MIN_CHANNEL_VALUE 800 /* shortest valid channel signal */ +# define PPM_MAX_CHANNEL_VALUE 2200 /* longest valid channel signal */ +# define PPM_MIN_START 2500 /* shortest valid start gap */ /* decoded PPM buffer */ #define PPM_MAX_CHANNELS 12 @@ -502,6 +514,9 @@ hrt_tim_isr(int irq, void *context) { uint32_t status; + /* grab the timer for latency tracking purposes */ + latency_actual = rCNT; + /* copy interrupt status */ status = rSR; @@ -516,6 +531,10 @@ hrt_tim_isr(int irq, void *context) /* was this a timer tick? */ if (status & SR_INT_HRT) { + + /* do latency calculations */ + hrt_latency_update(); + /* run any callouts that have met their deadline */ hrt_call_invoke(); @@ -799,8 +818,26 @@ hrt_call_reschedule() } //lldbg("schedule for %u at %u\n", (unsigned)(deadline & 0xffffffff), (unsigned)(now & 0xffffffff)); - /* set the new compare value */ - rCCR_HRT = deadline & 0xffff; + /* set the new compare value and remember it for latency tracking */ + rCCR_HRT = latency_baseline = deadline & 0xffff; } +static void +hrt_latency_update(void) +{ + uint16_t latency = latency_actual - latency_baseline; + unsigned index; + + /* bounded buckets */ + for (index = 0; index < LATENCY_BUCKET_COUNT; index++) { + if (latency <= latency_buckets[index]) { + latency_counters[index]++; + return; + } + } + /* catch-all at the end */ + latency_counters[index]++; +} + + #endif /* CONFIG_HRT_TIMER */ diff --git a/nuttx/configs/px4fmu/src/up_nsh.c b/nuttx/configs/px4fmu/src/up_nsh.c index d089f2df33..25f3c2795e 100644 --- a/nuttx/configs/px4fmu/src/up_nsh.c +++ b/nuttx/configs/px4fmu/src/up_nsh.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/stm3210e_eval/src/up_nsh.c + * config/px4fmu/src/up_nsh.c * arch/arm/src/board/up_nsh.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. @@ -63,11 +63,8 @@ #include #include #include -#include -#include -#include -#include #include +#include /**************************************************************************** * Pre-Processor Definitions @@ -95,20 +92,6 @@ * Protected Functions ****************************************************************************/ -/**************************************************************************** - * Name: multiport_setup - * - * Description: - * Perform setup of the PX4FMU's multi function ports - * - ****************************************************************************/ -int multiport_setup(void) -{ - int result = OK; - - return result; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -221,7 +204,7 @@ int nsh_archinitialize(void) up_udelay(1000); } - if (gyro_fail) message("[boot] FAILED to attach L3GD20 gyro\r\n"); + if (!gyro_fail) message("[boot] Found L3GD20 gyro\n"); int acc_attempts = 0; int acc_fail = 0; @@ -234,13 +217,13 @@ int nsh_archinitialize(void) up_udelay(1000); } - if (acc_fail) message("[boot] FAILED to attach BMA180 accelerometer\r\n"); + if (!acc_fail) message("[boot] Found BMA180 accelerometer\n"); /* initialize I2C2 bus */ i2c2 = up_i2cinitialize(2); if (!i2c2) { - message("[boot] FAILED to initialize I2C bus 2\r\n"); + message("[boot] FAILED to initialize I2C bus 2\n"); up_ledon(LED_AMBER); return -ENODEV; } @@ -251,7 +234,7 @@ int nsh_archinitialize(void) i2c3 = up_i2cinitialize(3); if (!i2c3) { - message("[boot] FAILED to initialize I2C bus 3\r\n"); + message("[boot] FAILED to initialize I2C bus 3\n"); up_ledon(LED_AMBER); return -ENODEV; } @@ -259,88 +242,41 @@ int nsh_archinitialize(void) /* set I2C3 speed */ I2C_SETFREQUENCY(i2c3, 400000); - int mag_attempts = 0; - int mag_fail = 0; - - while (mag_attempts < 5) - { - mag_fail = hmc5883l_attach(i2c2); - mag_attempts++; - if (mag_fail == 0) break; - up_udelay(1000); - } - - if (mag_fail) message("[boot] FAILED to attach HMC5883L magnetometer\r\n"); - - int baro_attempts = 0; - int baro_fail = 0; - while (baro_attempts < 5) - { - baro_fail = ms5611_attach(i2c2); - baro_attempts++; - if (baro_fail == 0) break; - up_udelay(1000); - } - - if (baro_fail) message("[boot] FAILED to attach MS5611 baro at addr #1 or #2 (0x76 or 0x77)\r\n"); - /* try to attach, don't fail if device is not responding */ (void)eeprom_attach(i2c3, FMU_BASEBOARD_EEPROM_ADDRESS, FMU_BASEBOARD_EEPROM_TOTAL_SIZE_BYTES, FMU_BASEBOARD_EEPROM_PAGE_SIZE_BYTES, FMU_BASEBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/baseboard_eeprom", 1); - int eeprom_attempts = 0; - int eeprom_fail; - while (eeprom_attempts < 5) - { - /* try to attach, fail if device does not respond */ - eeprom_fail = eeprom_attach(i2c2, FMU_ONBOARD_EEPROM_ADDRESS, - FMU_ONBOARD_EEPROM_TOTAL_SIZE_BYTES, - FMU_ONBOARD_EEPROM_PAGE_SIZE_BYTES, - FMU_ONBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/eeprom", 1); - eeprom_attempts++; - if (eeprom_fail == OK) break; - up_udelay(1000); - } - - if (eeprom_fail) message("[boot] FAILED to attach FMU EEPROM\r\n"); - - /* Report back sensor status */ - if (gyro_fail || mag_fail || baro_fail || eeprom_fail) - { - up_ledon(LED_AMBER); - } - #if defined(CONFIG_STM32_SPI3) /* Get the SPI port */ - message("[boot] Initializing SPI port 3\r\n"); + message("[boot] Initializing SPI port 3\n"); spi3 = up_spiinitialize(3); if (!spi3) { - message("[boot] FAILED to initialize SPI port 3\r\n"); + message("[boot] FAILED to initialize SPI port 3\n"); up_ledon(LED_AMBER); return -ENODEV; } - message("[boot] Successfully initialized SPI port 3\r\n"); + message("[boot] Successfully initialized SPI port 3\n"); /* Now bind the SPI interface to the MMCSD driver */ result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3); if (result != OK) { - message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\r\n"); + message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n"); up_ledon(LED_AMBER); return -ENODEV; } - message("[boot] Successfully bound SPI port 3 to the MMCSD driver\r\n"); + message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n"); #endif /* SPI3 */ /* initialize I2C1 bus */ i2c1 = up_i2cinitialize(1); if (!i2c1) { - message("[boot] FAILED to initialize I2C bus 1\r\n"); + message("[boot] FAILED to initialize I2C bus 1\n"); up_ledon(LED_AMBER); return -ENODEV; } @@ -352,7 +288,7 @@ int nsh_archinitialize(void) /* Get board information if available */ - /* Initialize the user GPIOs */ + /* Initialize the user GPIOs */ px4fmu_gpio_init(); #ifdef CONFIG_ADC @@ -364,7 +300,7 @@ int nsh_archinitialize(void) if (adc_state != OK) { /* Give up */ - message("[boot] FAILED adc_devinit: %d\r\n", adc_state); + message("[boot] FAILED adc_devinit: %d\n", adc_state); return -ENODEV; } } diff --git a/nuttx/configs/px4io/common/setenv.sh b/nuttx/configs/px4io/common/setenv.sh index d836851921..ee33a8d21d 100755 --- a/nuttx/configs/px4io/common/setenv.sh +++ b/nuttx/configs/px4io/common/setenv.sh @@ -2,7 +2,7 @@ # configs/stm3210e-eval/dfu/setenv.sh # # Copyright (C) 2009 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/configs/px4io/io/Make.defs b/nuttx/configs/px4io/io/Make.defs index 87508e22ec..369772d03f 100644 --- a/nuttx/configs/px4io/io/Make.defs +++ b/nuttx/configs/px4io/io/Make.defs @@ -1,3 +1,3 @@ include ${TOPDIR}/.config -include $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/common/Make.defs +include $(TOPDIR)/configs/px4io/common/Make.defs diff --git a/nuttx/configs/px4io/io/defconfig b/nuttx/configs/px4io/io/defconfig index 8ae6afe3cb..eea430a464 100755 --- a/nuttx/configs/px4io/io/defconfig +++ b/nuttx/configs/px4io/io/defconfig @@ -1,7 +1,8 @@ ############################################################################ # configs/px4io/nsh/defconfig # -# Copyright (C) 2009-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012 PX4 Development Team. All rights reserved. +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -41,7 +42,7 @@ # particular chip family that the architecture is implemented # in. # CONFIG_ARCH_architecture - for use in C code. This identifies the -# specific architecture within the chip familyl. +# specific architecture within the chip family. # CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory # CONFIG_ARCH_CHIP_name - For use in C code # CONFIG_ARCH_BOARD - identifies the configs subdirectory and, hence, @@ -51,7 +52,6 @@ # CONFIG_BOARD_LOOPSPERMSEC - for delay loops # CONFIG_DRAM_SIZE - Describes the installed DRAM. # CONFIG_DRAM_START - The start address of DRAM (physical) -# CONFIG_DRAM_END - Last address+1 of installed RAM # CONFIG_ARCH_IRQPRIO - The ST32F100CB supports interrupt prioritization # CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt # stack. If defined, this symbol is the size of the interrupt @@ -69,17 +69,16 @@ # the delay actually is 100 seconds. # CONFIG_ARCH_DMA - Support DMA initialization # -CONFIG_ARCH=arm +CONFIG_ARCH="arm" CONFIG_ARCH_ARM=y CONFIG_ARCH_CORTEXM3=y -CONFIG_ARCH_CHIP=stm32 +CONFIG_ARCH_CHIP="stm32" CONFIG_ARCH_CHIP_STM32F100C8=y -CONFIG_ARCH_BOARD=px4io +CONFIG_ARCH_BOARD="px4io" CONFIG_ARCH_BOARD_PX4IO=y CONFIG_BOARD_LOOPSPERMSEC=2000 CONFIG_DRAM_SIZE=0x00002000 CONFIG_DRAM_START=0x20000000 -CONFIG_DRAM_END=(CONFIG_DRAM_START+CONFIG_DRAM_SIZE) CONFIG_ARCH_IRQPRIO=y CONFIG_ARCH_INTERRUPTSTACK=n CONFIG_ARCH_STACKDUMP=y @@ -109,6 +108,7 @@ CONFIG_STM32_JTAG_SW_ENABLE=n # # Individual subsystems can be enabled: +# # AHB: CONFIG_STM32_DMA1=n CONFIG_STM32_DMA2=n @@ -140,10 +140,6 @@ CONFIG_STM32_TIM8=n CONFIG_STM32_USART1=y CONFIG_STM32_ADC3=n -# -# Timer and I2C devices may need to the following to force power to be applied: -# -#CONFIG_STM32_FORCEPOWER=y # # STM32F100 specific serial device driver settings @@ -306,9 +302,6 @@ CONFIG_HAVE_LIBM=n # CONFIG_SDCLONE_DISABLE. Disable cloning of all socket # desciptors by task_create() when a new task is started. If # set, all sockets will appear to be closed in the new task. -# CONFIG_NXFLAT. Enable support for the NXFLAT binary format. -# This format will support execution of NuttX binaries located -# in a ROMFS filesystem (see examples/nxflat). # CONFIG_SCHED_WORKQUEUE. Create a dedicated "worker" thread to # handle delayed processing from interrupt handlers. This feature # is required for some drivers but, if there are not complaints, @@ -327,11 +320,26 @@ CONFIG_HAVE_LIBM=n # thread. Default: CONFIG_IDLETHREAD_STACKSIZE. # CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up # the worker thread. Default: 4 +# CONFIG_SCHED_WAITPID - Enable the waitpid() API +# CONFIG_SCHED_ATEXIT - Enabled the atexit() API # +CONFIG_USER_ENTRYPOINT="user_start" #CONFIG_APPS_DIR= CONFIG_DEBUG=n CONFIG_DEBUG_VERBOSE=n CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEBUG_FS=n +CONFIG_DEBUG_GRAPHICS=n +CONFIG_DEBUG_LCD=n +CONFIG_DEBUG_USB=n +CONFIG_DEBUG_NET=n +CONFIG_DEBUG_RTC=n +CONFIG_DEBUG_ANALOG=n +CONFIG_DEBUG_PWM=n +CONFIG_DEBUG_CAN=n +CONFIG_DEBUG_I2C=n +CONFIG_DEBUG_INPUT=n + CONFIG_HAVE_CXX=n CONFIG_HAVE_CXXINITIALIZE=n CONFIG_MM_REGIONS=1 @@ -340,9 +348,9 @@ CONFIG_ARCH_LOWPUTC=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_INSTRUMENTATION=n CONFIG_TASK_NAME_SIZE=0 -CONFIG_START_YEAR=2009 -CONFIG_START_MONTH=9 -CONFIG_START_DAY=21 +CONFIG_START_YEAR=1970 +CONFIG_START_MONTH=1 +CONFIG_START_DAY=1 CONFIG_GREGORIAN_TIME=n CONFIG_JULIAN_TIME=n CONFIG_DEV_CONSOLE=y @@ -354,12 +362,13 @@ CONFIG_SEM_NNESTPRIO=0 CONFIG_FDCLONE_DISABLE=n CONFIG_FDCLONE_STDIO=y CONFIG_SDCLONE_DISABLE=y -CONFIG_NXFLAT=n CONFIG_SCHED_WORKQUEUE=n CONFIG_SCHED_WORKPRIORITY=50 -CONFIG_SCHED_WORKPERIOD=(50*1000) +CONFIG_SCHED_WORKPERIOD=50000 CONFIG_SCHED_WORKSTACKSIZE=1024 CONFIG_SIG_SIGWORK=4 +CONFIG_SCHED_WAITPID=n +CONFIG_SCHED_ATEXIT=n # # The following can be used to disable categories of @@ -427,6 +436,14 @@ CONFIG_ARCH_BZERO=n # CONFIG_NAME_MAX - The maximum size of a file name. # CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate # on fopen. (Only if CONFIG_NFILE_STREAMS > 0) +# CONFIG_STDIO_LINEBUFFER - If standard C buffered I/O is enabled +# (CONFIG_STDIO_BUFFER_SIZE > 0), then this option may be added +# to force automatic, line-oriented flushing the output buffer +# for putc(), fputc(), putchar(), puts(), fputs(), printf(), +# fprintf(), and vfprintf(). When a newline is encountered in +# the output string, the output buffer will be flushed. This +# (slightly) increases the NuttX footprint but supports the kind +# of behavior that people expect for printf(). # CONFIG_NUNGET_CHARS - Number of characters that can be # buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0) # CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message @@ -452,6 +469,7 @@ CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=0 CONFIG_NAME_MAX=32 CONFIG_STDIO_BUFFER_SIZE=64 +CONFIG_STDIO_LINEBUFFER=n CONFIG_NUNGET_CHARS=2 CONFIG_PREALLOC_MQ_MSGS=4 CONFIG_MQ_MAXMSGSIZE=32 diff --git a/nuttx/configs/px4io/io/setenv.sh b/nuttx/configs/px4io/io/setenv.sh index d836851921..ee33a8d21d 100755 --- a/nuttx/configs/px4io/io/setenv.sh +++ b/nuttx/configs/px4io/io/setenv.sh @@ -2,7 +2,7 @@ # configs/stm3210e-eval/dfu/setenv.sh # # Copyright (C) 2009 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/configs/px4io/src/drv_ppm_input.c b/nuttx/configs/px4io/src/drv_ppm_input.c index f25ae41e27..2db0fbf0b5 100644 --- a/nuttx/configs/px4io/src/drv_ppm_input.c +++ b/nuttx/configs/px4io/src/drv_ppm_input.c @@ -96,9 +96,9 @@ * values are advertised to clients. */ #define PPM_MAX_PULSE_WIDTH 500 /* maximum width of a pulse */ -#define PPM_MIN_CHANNEL_VALUE 750 /* shortest valid channel signal */ -#define PPM_MAX_CHANNEL_VALUE 2400 /* longest valid channel signal */ -#define PPM_MIN_START 5000 /* shortest valid start gap */ +#define PPM_MIN_CHANNEL_VALUE 800 /* shortest valid channel signal */ +#define PPM_MAX_CHANNEL_VALUE 2200 /* longest valid channel signal */ +#define PPM_MIN_START 2500 /* shortest valid start gap */ /* Input timeout - after this interval we assume signal is lost */ #define PPM_INPUT_TIMEOUT 100 * 1000 /* 100ms */ diff --git a/nuttx/drivers/Kconfig b/nuttx/drivers/Kconfig index 6d4c5fc6ae..32d127aa43 100644 --- a/nuttx/drivers/Kconfig +++ b/nuttx/drivers/Kconfig @@ -3,15 +3,13 @@ # see misc/tools/kconfig-language.txt. # -comment "Device Driver Configuration" - config DEV_NULL bool "Enable /dev/null" default y config DEV_ZERO bool "Enable /dev/zero" - default y + default n config LOOP bool "Enable loop device" @@ -22,15 +20,15 @@ config LOOP loteardown() in include/nuttx/fs/fs.h. config RAMDISK - bool "RAM disk support" + bool "RAM Disk Support" default n ---help--- Can be used to set up a block of memory or (read-only) FLASH as a block driver that can be mounted as a files system. See include/nuttx/ramdisk.h. -config CAN - bool "CAN support" +menuconfig CAN + bool "CAN Driver Support" default n ---help--- This selection enables building of the "upper-half" CAN driver. @@ -65,8 +63,8 @@ config CAN_LOOPBACK endif -config PWM - bool "PWM support" +menuconfig PWM + bool "PWM Driver Support" default n ---help--- This selection enables building of the "upper-half" PWM driver. @@ -74,7 +72,7 @@ config PWM if PWM config PWM_PULSECOUNT - bool "PWM pulse count support" + bool "PWM Pulse Count Support" default n ---help--- Some hardware will support generation of a fixed number of pulses. This @@ -84,19 +82,54 @@ config PWM_PULSECOUNT endif -config I2C - bool "I2C support" - default y +menuconfig I2C + bool "I2C Driver Support" + default n ---help--- This selection enables building of the "upper-half" I2C driver. See include/nuttx/i2c.h for further I2C driver information. -if I2C -endif +config I2C_SLAVE + bool "I2C Slave" + default n + depends on I2C -config SPI - bool "SPI support" - default y +config I2C_TRANSFER + bool "Support the I2C transfer() method" + default n + depends on I2C + +config I2C_WRITEREAD + bool "Support the I2C writeread() method" + default n + depends on I2C + +config I2C_POLLED + bool "Polled I2C (no interrupts)" + default n + depends on I2C + +config I2C_TRACE + bool "Enable I2C trace debug" + default n + depends on I2C + +config I2C_NTRACE + bool "Enable I2C trace debug" + default n + depends on I2C_TRACE + +config ARCH_HAVE_I2CRESET + bool + +config I2C_RESET + bool "Support up_i2creset" + default n + depends on I2C && ARCH_HAVE_I2CRESET + +menuconfig SPI + bool "SPI Driver Support" + default n ---help--- This selection enables building of the "upper-half" SPI driver. See include/nuttx/spi.h for further SPI driver information. @@ -104,7 +137,7 @@ config SPI if SPI config SPI_OWNBUS bool "SPI single device" - default y + default n ---help--- Set if there is only one active device on the SPI bus. No locking or SPI configuration will be performed. It is not necessary for clients to lock, @@ -126,9 +159,62 @@ config SPI_CMDDATA endif -config WATCHDOG - bool "Watchdog timer support" - default y +menuconfig RTC + bool "RTC Driver Support" + default n + ---help--- + This selection enables configuration of a real time clock (RTCdriver. + See include/nuttx/rtc.h for further watchdog timer driver information. + Most RTC drivers are MCU specific and may require other specific settings. + +config RTC_DATETIME + bool "Date/Time RTC Support" + default n + depends on RTC + ---help--- + There are two general types of RTC: (1) A simple battery backed counter + that keeps the time when power is down, and (2) a full date / time RTC the + provides the date and time information, often in BCD format. If + RTC_DATETIME is selected, it specifies this second kind of RTC. In this + case, the RTC is used to "seed" the normal NuttX timer and the NuttX system + timer provides for higher resolution time. + +config RTC_HIRES + bool "Hi-Res RTC Support" + default n + depends on RTC && !RTC_DATETIME + ---help--- + If RTC_DATETIME not selected, then the simple, battery backed counter is + used. There are two different implementations of such simple counters + based on the time resolution of the counter: The typical RTC keeps time + to resolution of 1 second, usually supporting a 32-bit time_t value. In + this case, the RTC is used to "seed" the normal NuttX timer and the NuttX + timer provides for higherresoution time. + + If RTC_HIRES is enabled in the NuttX configuration, then the RTC provides + higher resolution time and completely replaces the system timer for purpose + of date and time. + +config RTC_FREQUENCY + int "Hi-Res RTC frequency" + default 1 + depends on RTC && !RTC_DATETIME && RTC_HIRES + ---help--- + If RTC_HIRES is defined, then the frequency of the high resolution RTC + must be provided. If RTC_HIRES is not defined, RTC_FREQUENCY is assumed + to be one Hz. + +config RTC_ALARM + bool "RTC Alarm Support" + default n + depends on RTC + ---help--- + Enable if the RTC hardware supports setting of an alarm. A callback + function will be executed when the alarm goes off. + +menuconfig WATCHDOG + bool "Watchdog Timer Support" + default n ---help--- This selection enables building of the "upper-half" watchdog timer driver. See include/nuttx/watchdog.h for further watchdog timer driver information. @@ -137,7 +223,7 @@ if WATCHDOG endif menuconfig ANALOG - bool "Analog Device(ADC/DAC) support" + bool "Analog Device(ADC/DAC) Support" default n ---help--- This directory holds implementations of analog device drivers. @@ -149,8 +235,8 @@ if ANALOG source drivers/analog/Kconfig endif -config BCH - bool "BCH support" +menuconfig BCH + bool "Block-to-Character (BCH) Support" default n ---help--- Contains logic that may be used to convert a block driver into @@ -163,8 +249,8 @@ source drivers/bch/Kconfig endif menuconfig INPUT - bool "Input device support" - default y + bool "Input Device Support" + default n ---help--- This directory holds implementations of input device drivers. This includes such things as touchscreen and keypad drivers. @@ -175,19 +261,23 @@ source drivers/input/Kconfig endif menuconfig LCD - bool "LCD support" + bool "LCD Driver Support" default n select NX_LCDDRIVER ---help--- Drivers for parallel and serial LCD and OLED type devices. These drivers support interfaces as defined in include/nuttx/lcd/lcd.h + This selection is necessary to enable support for LCD drivers in + drivers/lcd as well as for board-specific LCD drivers in the configs/ + subdirectories. + if LCD source drivers/lcd/Kconfig endif menuconfig MMCSD - bool "MMC/SD support" + bool "MMC/SD Driver Support" default n ---help--- Support for MMC/SD block drivers. MMC/SD block drivers based on @@ -197,9 +287,9 @@ menuconfig MMCSD if MMCSD source drivers/mmcsd/Kconfig endif - + menuconfig MTD - bool "Memory Technology Device (MTD) support" + bool "Memory Technology Device (MTD) Support" default n ---help--- Memory Technology Device (MTD) drivers. Some simple drivers for @@ -216,8 +306,9 @@ source drivers/mtd/Kconfig endif menuconfig NETDEVICES - bool "Network Device support" + bool "Network Device Support" default n + depends on NET ---help--- Network interface drivers. See also include/nuttx/net/net.h @@ -246,7 +337,7 @@ config PM drivers are not active. menuconfig POWER - bool "Power management device support" + bool "Power Management Support" default n ---help--- Enable building of power-related devices (battery monitors, chargers, etc). @@ -256,7 +347,7 @@ source drivers/power/Kconfig endif menuconfig SENSORS - bool "Sensors support" + bool "Sensor Device Support" default n ---help--- Drivers for various sensors @@ -266,7 +357,7 @@ source drivers/sensors/Kconfig endif menuconfig SERCOMM_CONSOLE - bool "Osmocom-bb serial console" + bool "Osmocom-bb Sercomm Driver Support" default n ---help--- Sercomm is the transport used by osmocom-bb that runs on top of serial. @@ -283,7 +374,7 @@ source drivers/sercomm/Kconfig endif menuconfig SERIAL - bool "Serial support" + bool "Serial Driver Support" default y ---help--- Front-end character drivers for chip-specific UARTs. This provide @@ -295,7 +386,7 @@ source drivers/serial/Kconfig endif menuconfig USBDEV - bool "USB device support" + bool "USB Device Driver Support" default n ---help--- USB device drivers. See also include/nuttx/usb/usbdev.h @@ -305,7 +396,7 @@ source drivers/usbdev/Kconfig endif menuconfig USBHOST - bool "USB Host support" + bool "USB Host Driver Support" default n ---help--- USB host drivers. See also include/nuttx/usb/usbhost.h @@ -315,7 +406,7 @@ source drivers/usbhost/Kconfig endif menuconfig WIRELESS - bool "Wireless support" + bool "Wireless Device Support" default n ---help--- Drivers for various wireless devices. @@ -324,6 +415,8 @@ if WIRELESS source drivers/wireless/Kconfig endif +comment "System Logging Device Options" + source drivers/syslog/Kconfig diff --git a/nuttx/drivers/analog/Make.defs b/nuttx/drivers/analog/Make.defs index 10b0db4785..d94e397587 100644 --- a/nuttx/drivers/analog/Make.defs +++ b/nuttx/drivers/analog/Make.defs @@ -2,7 +2,7 @@ # drivers/analog/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/analog/dac.c b/nuttx/drivers/analog/dac.c index 9371e3414c..e1fc3049ff 100644 --- a/nuttx/drivers/analog/dac.c +++ b/nuttx/drivers/analog/dac.c @@ -8,7 +8,7 @@ * Derived from drivers/can.c * * Copyright (C) 2008-2009Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/input/Make.defs b/nuttx/drivers/input/Make.defs index aaf08b8270..6dbae268e5 100644 --- a/nuttx/drivers/input/Make.defs +++ b/nuttx/drivers/input/Make.defs @@ -2,7 +2,7 @@ # drivers/input/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/input/ads7843e.c b/nuttx/drivers/input/ads7843e.c index 750b91ff2e..e08a7a7280 100644 --- a/nuttx/drivers/input/ads7843e.c +++ b/nuttx/drivers/input/ads7843e.c @@ -521,7 +521,7 @@ static int ads7843e_schedule(FAR struct ads7843e_dev_s *priv) */ DEBUGASSERT(priv->work.worker == NULL); - ret = work_queue(&priv->work, ads7843e_worker, priv, 0); + ret = work_queue(HPWORK, &priv->work, ads7843e_worker, priv, 0); if (ret != 0) { illdbg("Failed to queue work: %d\n", ret); @@ -1179,7 +1179,7 @@ int ads7843e_register(FAR struct spi_dev_s *dev, * availability conditions. */ - ret = work_queue(&priv->work, ads7843e_worker, priv, 0); + ret = work_queue(HPWORK, &priv->work, ads7843e_worker, priv, 0); if (ret != 0) { idbg("Failed to queue work: %d\n", ret); diff --git a/nuttx/drivers/input/stmpe811_base.c b/nuttx/drivers/input/stmpe811_base.c index 72af1575a9..f37c24622c 100644 --- a/nuttx/drivers/input/stmpe811_base.c +++ b/nuttx/drivers/input/stmpe811_base.c @@ -195,7 +195,7 @@ static int stmpe811_interrupt(int irq, FAR void *context) * action should be required to protect the work queue. */ - ret = work_queue(&priv->work, stmpe811_worker, priv, 0); + ret = work_queue(HPWORK, &priv->work, stmpe811_worker, priv, 0); if (ret != 0) { illdbg("Failed to queue work: %d\n", ret); diff --git a/nuttx/drivers/input/stmpe811_tsc.c b/nuttx/drivers/input/stmpe811_tsc.c index e2ab2827d5..c7f8b473b8 100644 --- a/nuttx/drivers/input/stmpe811_tsc.c +++ b/nuttx/drivers/input/stmpe811_tsc.c @@ -783,7 +783,7 @@ static void stmpe811_timeout(int argc, uint32_t arg1, ...) * action should be required to protect the work queue. */ - ret = work_queue(&priv->timeout, stmpe811_timeoutworker, priv, 0); + ret = work_queue(HPWORK, &priv->timeout, stmpe811_timeoutworker, priv, 0); if (ret != 0) { illdbg("Failed to queue work: %d\n", ret); diff --git a/nuttx/drivers/input/tsc2007.c b/nuttx/drivers/input/tsc2007.c index 07acb53712..163118b95d 100644 --- a/nuttx/drivers/input/tsc2007.c +++ b/nuttx/drivers/input/tsc2007.c @@ -775,7 +775,7 @@ static int tsc2007_interrupt(int irq, FAR void *context) */ DEBUGASSERT(priv->work.worker == NULL); - ret = work_queue(&priv->work, tsc2007_worker, priv, 0); + ret = work_queue(HPWORK, &priv->work, tsc2007_worker, priv, 0); if (ret != 0) { illdbg("Failed to queue work: %d\n", ret); @@ -1316,7 +1316,7 @@ int tsc2007_register(FAR struct i2c_dev_s *dev, * availability conditions. */ - ret = work_queue(&priv->work, tsc2007_worker, priv, 0); + ret = work_queue(HPWORK, &priv->work, tsc2007_worker, priv, 0); if (ret != 0) { idbg("Failed to queue work: %d\n", ret); diff --git a/nuttx/drivers/lcd/Kconfig b/nuttx/drivers/lcd/Kconfig index af94ac16a3..081a79c89d 100644 --- a/nuttx/drivers/lcd/Kconfig +++ b/nuttx/drivers/lcd/Kconfig @@ -173,3 +173,42 @@ config LCD_UG9664HSWAG01 ug-9664hswag01.c. OLED Display Module, UG-9664HSWAG01", Univision Technology Inc. Used with the LPC Xpresso and Embedded Artists base board. + +choice + prompt "LCD Orientation" + default LCD_LANDSCAPE + depends on LCD + ---help--- + Some LCD drivers may support displays in different orientations. + If the LCD driver supports this capability, than these are configuration + options to select that display orientation. + +config LCD_LANDSCAPE + bool "Landscape orientation" + ---help--- + Define for "landscape" orientation support. Landscape mode refers one + of two orientations where the the display is wider than it is tall + (LCD_RLANDSCAPE is the other). This is the default orientation. + +config LCD_PORTRAIT + bool "Portrait orientation" + ---help--- + Define for "portrait" orientation support. Portrait mode refers one + of two orientations where the the display is taller than it is wide + (LCD_RPORTAIT is the other). + +config LCD_RPORTRAIT + bool "Reverse portrait display" + ---help--- + Define for "reverse portrait" orientation support. Reverse portrait mode + refers one of two orientations where the the display is taller than it is + wide (LCD_PORTAIT is the other). + +config LCD_RLANDSCAPE + bool "Reverse landscape orientation" + ---help--- + Define for "reverse landscape" orientation support. Reverse landscape mode + refers one of two orientations where the the display is wider than it is + tall (LCD_LANDSCAPE is the other). + +endchoice diff --git a/nuttx/drivers/lcd/nokia6100.c b/nuttx/drivers/lcd/nokia6100.c index d450e05dbf..7354b8a917 100644 --- a/nuttx/drivers/lcd/nokia6100.c +++ b/nuttx/drivers/lcd/nokia6100.c @@ -3,7 +3,7 @@ * Nokia 6100 LCD Display Driver * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: * "Nokia 6100 LCD Display Driver," Revision 1, James P. Lynch ("Nokia 6100 LCD diff --git a/nuttx/drivers/lcd/pcf8833.h b/nuttx/drivers/lcd/pcf8833.h index b0a7e14d41..36dc65ac3f 100644 --- a/nuttx/drivers/lcd/pcf8833.h +++ b/nuttx/drivers/lcd/pcf8833.h @@ -1,152 +1,152 @@ -/************************************************************************************** - * drivers/lcd/pcf8833.h - * Definitions for the Phillips PCF8833 LCD controller - * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * References: "Data Sheet, PCF8833 STN RGB 132x132x3 driver," Phillips, 2003 Feb 14. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - **************************************************************************************/ - -#ifndef __DRIVERS_LCD_PCF8833_H -#define __DRIVERS_LCD_PCF8833_H - -/************************************************************************************** - * Included Files - **************************************************************************************/ - -/************************************************************************************** - * Pre-processor Definitions - **************************************************************************************/ -/* Pixel format codes */ - -#define PCF8833_FMT_8BPS (2) -#define PCF8833_FMT_12BPS (3) -#define PCF8833_FMT_16BPS (5) - -/* LCD Commands */ - -#define PCF8833_NOP 0x00 /* No operation; Data: none */ -#define PCF8833_SWRESET 0x01 /* Software reset ; Data: none */ -#define PCF8833_BSTROFF 0x02 /* Booster voltage off; Data: none */ -#define PCF8833_BSTRON 0x03 /* Booster voltage on; Data: none */ -#define PCF8833_RDDIDIF 0x04 /* Read display identification; Data: none */ -#define PCF8833_RDDST 0x09 /* Read display status; Data: none */ -#define PCF8833_SLEEPIN 0x10 /* Sleep_IN; Data: none */ -#define PCF8833_SLEEPOUT 0x11 /* Sleep_OUT; Data: none */ -#define PCF8833_PTLON 0x12 /* Partial mode on; Data: none */ -#define PCF8833_NORON 0x13 /* Normal Display mode on; Data: none */ -#define PCF8833_INVOFF 0x20 /* Display inversion off; Data: none */ -#define PCF8833_INVON 0x21 /* Display inversion on; Data: none */ -#define PCF8833_DALO 0x22 /* All pixel off; Data: none */ -#define PCF8833_DAL 0x23 /* All pixel on; Data: none */ -#define PCF8833_SETCON 0x25 /* Set contrast; Data: (1) contrast */ -#define PCF8833_DISPOFF 0x28 /* Display off; Data: none */ -#define PCF8833_DISPON 0x29 /* Display on; Data: none */ -#define PCF8833_CASET 0x2a /* Column address set; Data: (1) X start (2) X end */ -#define PCF8833_PASET 0x2b /* Page address set Data: (1) Y start (2) Y end */ -#define PCF8833_RAMWR 0x2c /* Memory write; Data: (1) write data */ -#define PCF8833_RGBSET 0x2d /* Colour set; Data: (1-8) red tones, (9-16) green tones, (17-20) blue tones */ -#define PCF8833_PTLAR 0x30 /* Partial area; Data: (1) start address (2) end address */ -#define PCF8833_VSCRDEF 0x33 /* Vertical scroll definition; Data: (1) top fixed, (2) scrol area, (3) bottom fixed */ -#define PCF8833_TEOFF 0x34 /* Tearing line off; Data: none */ -#define PCF8833_TEON 0x35 /* Tearing line on; Data: (1) don't care */ -#define PCF8833_MADCTL 0x36 /* Memory data access control; Data: (1) access control settings */ -#define PCF8833_SEP 0x37 /* Set Scroll Entry Point; Data: (1) scroll entry point */ -#define PCF8833_IDMOFF 0x38 /* Idle mode off; Data: none */ -#define PCF8833_IDMON 0x39 /* Idle mode on; Data: none */ -#define PCF8833_COLMOD 0x3a /* Interface pixel format; Data: (1) color interface format */ -#define PCF8833_SETVOP 0xb0 /* Set VOP; Data: (1) VOP5-8 (2) VOP0-4 */ -#define PCF8833_BRS 0xb4 /* Bottom Row Swap; Data: none */ -#define PCF8833_TRS 0xb6 /* Top Row Swap; Data: none */ -#define PCF8833_FINV 0xb9 /* Super Frame INVersion; Data: none */ -#define PCF8833_DOR 0xba /* Data ORder; Data: none */ -#define PCF8833_TCDFE 0xbd /* Enable/disable DF temp comp; Data: none */ -#define PCF8833_TCVOPE 0xbf /* Enable or disable VOP temp comp; Data: none */ -#define PCF8833_EC 0xc0 /* Internal or external oscillator; Data: none */ -#define PCF8833_SETMUL 0xc2 /* Set multiplication factor; Data: (1) Multiplication factor */ -#define PCF8833_TCVOPAB 0xc3 /* Set TCVOP slopes A and B; Data: (1) SLB and SLA */ -#define PCF8833_TCVOPCD 0xc4 /* Set TCVOP slopes C and D; Data: (1) SLD and SLC */ -#define PCF8833_TCDF 0xc5 /* Set divider frequency; Data: Divider factor in region (1) A (2) B (3) C (4) D */ -#define PCF8833_DF8COLOR 0xc6 /* Set divider frequency 8-colour mode; Data: (1) DF80-6 */ -#define PCF8833_SETBS 0xc7 /* Set bias system; Data: (1) Bias systems */ -#define PCF8833_RDTEMP 0xc8 /* Temperature read back; Data: none */ -#define PCF8833_NLI 0xc9 /* N-Line Inversion; Data: (1) NLI time slots invervsion */ -#define PCF8833_RDID1 0xda /* Read ID1; Data: none */ -#define PCF8833_RDID2 0xdb /* Read ID2; Data: none */ -#define PCF8833_RDID3 0xdc /* Read ID3; Data: none */ -#define PCF8833_SFD 0xef /* Select factory defaults; Data: none */ -#define PCF8833_ECM 0xf0 /* Enter Calibration mode; Data: (1) Calibration control settings */ -#define PCF8833_OTPSHTIN 0xf1 /* Shift data in OTP shift registers; Data: Any number of bytes */ - -/* Memory data access control (MADCTL) bit definitions */ - -#define MADCTL_RGB (1 << 3) /* Bit 3: BGR */ -#define MADCTL_LAO (1 << 4) /* Bit 4: Line address order bottom to top */ -#define MADCTL_V (1 << 5) /* Bit 5: Vertical RAM write; in Y direction */ -#define MADCTL_MX (1 << 6) /* Bit 6: Mirror X */ -#define MADCTL_MY (1 << 7) /* Bit 7: Mirror Y */ - -/* PCF8833 status register bit definitions */ -/* CMD format: RDDST command followed by four status bytes: */ -/* Byte 1: D31 d30 D29 D28 D27 D26 --- --- */ - -#define PCF8833_ST_RGB (1 << 2) /* Bit 2: D26 - RGB/BGR order */ -#define PCF8833_ST_LINEADDR (1 << 3) /* Bit 3: D27 - Line address order */ -#define PCF8833_ST_ADDRMODE (1 << 4) /* Bit 4: D28 - Vertical/horizontal addressing mode */ -#define PCF8833_ST_XADDR (1 << 5) /* Bit 5: D29 - X address order */ -#define PCF8833_ST_YADDR (1 << 6) /* Bit 6: D30 - Y address order */ -#define PCF8833_ST_BOOSTER (1 << 7) /* Bit 7: D31 - Booster voltage status */ - -/* Byte 2: --- D22 D21 D20 D19 D18 D17 D16 */ - -#define PCF8833_ST_NORMAL (1 << 0) /* Bit 0: D16 - Normal display mode */ -#define PCF8833_ST_SLEEPIN (1 << 1) /* Bit 1: D17 - Sleep in selected */ -#define PCF8833_ST_PARTIAL (1 << 2) /* Bit 2: D18 - Partial mode on */ -#define PCF8833_ST_IDLE (1 << 3) /* Bit 3: D19 - Idle mode selected */ -#define PCF8833_ST_PIXELFMT_SHIFT (4) /* Bits 4-6: D20-D22 - Interface pixel format */ -#define PCF8833_ST_PIXELFMT_MASK (7 << PCF8833_ST_PIXELFMT_SHIFT) -# define PCF8833_ST_PIXELFMT_8BPS (PCF8833_FMT_8BPS << PCF8833_ST_PIXELFMT_SHIFT) -# define PCF8833_ST_PIXELFMT_12BPS (PCF8833_FMT_12BPS << PCF8833_ST_PIXELFMT_SHIFT) -# define PCF8833_ST_PIXELFMT_16BPS (PCF8833_FMT_16BPS << PCF8833_ST_PIXELFMT_SHIFT) - -/* Byte 3: D15 -- D13 D12 D11 D10 D9 --- */ - -#define PCF8833_ST_TEARING (1 << 1) /* Bit 1: D9 - Tearing effect on */ -#define PCF8833_ST_DISPLAYON (1 << 2) /* Bit 2: D10 - Display on */ -#define PCF8833_ST_PIXELSOFF (1 << 3) /* Bit 3: D11 - All pixels off */ -#define PCF8833_ST_PIXELSON (1 << 4) /* Bit 4: D12 - All pixels on */ -#define PCF8833_ST_INV (1 << 5) /* Bit 5: D13 - Display inversion */ -#define PCF8833_ST_VSCROLL (1 << 7) /* Bit 6: D15 - Vertical scroll mode */ - -/* Byte 4: All zero */ - +/************************************************************************************** + * drivers/lcd/pcf8833.h + * Definitions for the Phillips PCF8833 LCD controller + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * References: "Data Sheet, PCF8833 STN RGB 132x132x3 driver," Phillips, 2003 Feb 14. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************************/ + +#ifndef __DRIVERS_LCD_PCF8833_H +#define __DRIVERS_LCD_PCF8833_H + +/************************************************************************************** + * Included Files + **************************************************************************************/ + +/************************************************************************************** + * Pre-processor Definitions + **************************************************************************************/ +/* Pixel format codes */ + +#define PCF8833_FMT_8BPS (2) +#define PCF8833_FMT_12BPS (3) +#define PCF8833_FMT_16BPS (5) + +/* LCD Commands */ + +#define PCF8833_NOP 0x00 /* No operation; Data: none */ +#define PCF8833_SWRESET 0x01 /* Software reset ; Data: none */ +#define PCF8833_BSTROFF 0x02 /* Booster voltage off; Data: none */ +#define PCF8833_BSTRON 0x03 /* Booster voltage on; Data: none */ +#define PCF8833_RDDIDIF 0x04 /* Read display identification; Data: none */ +#define PCF8833_RDDST 0x09 /* Read display status; Data: none */ +#define PCF8833_SLEEPIN 0x10 /* Sleep_IN; Data: none */ +#define PCF8833_SLEEPOUT 0x11 /* Sleep_OUT; Data: none */ +#define PCF8833_PTLON 0x12 /* Partial mode on; Data: none */ +#define PCF8833_NORON 0x13 /* Normal Display mode on; Data: none */ +#define PCF8833_INVOFF 0x20 /* Display inversion off; Data: none */ +#define PCF8833_INVON 0x21 /* Display inversion on; Data: none */ +#define PCF8833_DALO 0x22 /* All pixel off; Data: none */ +#define PCF8833_DAL 0x23 /* All pixel on; Data: none */ +#define PCF8833_SETCON 0x25 /* Set contrast; Data: (1) contrast */ +#define PCF8833_DISPOFF 0x28 /* Display off; Data: none */ +#define PCF8833_DISPON 0x29 /* Display on; Data: none */ +#define PCF8833_CASET 0x2a /* Column address set; Data: (1) X start (2) X end */ +#define PCF8833_PASET 0x2b /* Page address set Data: (1) Y start (2) Y end */ +#define PCF8833_RAMWR 0x2c /* Memory write; Data: (1) write data */ +#define PCF8833_RGBSET 0x2d /* Colour set; Data: (1-8) red tones, (9-16) green tones, (17-20) blue tones */ +#define PCF8833_PTLAR 0x30 /* Partial area; Data: (1) start address (2) end address */ +#define PCF8833_VSCRDEF 0x33 /* Vertical scroll definition; Data: (1) top fixed, (2) scrol area, (3) bottom fixed */ +#define PCF8833_TEOFF 0x34 /* Tearing line off; Data: none */ +#define PCF8833_TEON 0x35 /* Tearing line on; Data: (1) don't care */ +#define PCF8833_MADCTL 0x36 /* Memory data access control; Data: (1) access control settings */ +#define PCF8833_SEP 0x37 /* Set Scroll Entry Point; Data: (1) scroll entry point */ +#define PCF8833_IDMOFF 0x38 /* Idle mode off; Data: none */ +#define PCF8833_IDMON 0x39 /* Idle mode on; Data: none */ +#define PCF8833_COLMOD 0x3a /* Interface pixel format; Data: (1) color interface format */ +#define PCF8833_SETVOP 0xb0 /* Set VOP; Data: (1) VOP5-8 (2) VOP0-4 */ +#define PCF8833_BRS 0xb4 /* Bottom Row Swap; Data: none */ +#define PCF8833_TRS 0xb6 /* Top Row Swap; Data: none */ +#define PCF8833_FINV 0xb9 /* Super Frame INVersion; Data: none */ +#define PCF8833_DOR 0xba /* Data ORder; Data: none */ +#define PCF8833_TCDFE 0xbd /* Enable/disable DF temp comp; Data: none */ +#define PCF8833_TCVOPE 0xbf /* Enable or disable VOP temp comp; Data: none */ +#define PCF8833_EC 0xc0 /* Internal or external oscillator; Data: none */ +#define PCF8833_SETMUL 0xc2 /* Set multiplication factor; Data: (1) Multiplication factor */ +#define PCF8833_TCVOPAB 0xc3 /* Set TCVOP slopes A and B; Data: (1) SLB and SLA */ +#define PCF8833_TCVOPCD 0xc4 /* Set TCVOP slopes C and D; Data: (1) SLD and SLC */ +#define PCF8833_TCDF 0xc5 /* Set divider frequency; Data: Divider factor in region (1) A (2) B (3) C (4) D */ +#define PCF8833_DF8COLOR 0xc6 /* Set divider frequency 8-colour mode; Data: (1) DF80-6 */ +#define PCF8833_SETBS 0xc7 /* Set bias system; Data: (1) Bias systems */ +#define PCF8833_RDTEMP 0xc8 /* Temperature read back; Data: none */ +#define PCF8833_NLI 0xc9 /* N-Line Inversion; Data: (1) NLI time slots invervsion */ +#define PCF8833_RDID1 0xda /* Read ID1; Data: none */ +#define PCF8833_RDID2 0xdb /* Read ID2; Data: none */ +#define PCF8833_RDID3 0xdc /* Read ID3; Data: none */ +#define PCF8833_SFD 0xef /* Select factory defaults; Data: none */ +#define PCF8833_ECM 0xf0 /* Enter Calibration mode; Data: (1) Calibration control settings */ +#define PCF8833_OTPSHTIN 0xf1 /* Shift data in OTP shift registers; Data: Any number of bytes */ + +/* Memory data access control (MADCTL) bit definitions */ + +#define MADCTL_RGB (1 << 3) /* Bit 3: BGR */ +#define MADCTL_LAO (1 << 4) /* Bit 4: Line address order bottom to top */ +#define MADCTL_V (1 << 5) /* Bit 5: Vertical RAM write; in Y direction */ +#define MADCTL_MX (1 << 6) /* Bit 6: Mirror X */ +#define MADCTL_MY (1 << 7) /* Bit 7: Mirror Y */ + +/* PCF8833 status register bit definitions */ +/* CMD format: RDDST command followed by four status bytes: */ +/* Byte 1: D31 d30 D29 D28 D27 D26 --- --- */ + +#define PCF8833_ST_RGB (1 << 2) /* Bit 2: D26 - RGB/BGR order */ +#define PCF8833_ST_LINEADDR (1 << 3) /* Bit 3: D27 - Line address order */ +#define PCF8833_ST_ADDRMODE (1 << 4) /* Bit 4: D28 - Vertical/horizontal addressing mode */ +#define PCF8833_ST_XADDR (1 << 5) /* Bit 5: D29 - X address order */ +#define PCF8833_ST_YADDR (1 << 6) /* Bit 6: D30 - Y address order */ +#define PCF8833_ST_BOOSTER (1 << 7) /* Bit 7: D31 - Booster voltage status */ + +/* Byte 2: --- D22 D21 D20 D19 D18 D17 D16 */ + +#define PCF8833_ST_NORMAL (1 << 0) /* Bit 0: D16 - Normal display mode */ +#define PCF8833_ST_SLEEPIN (1 << 1) /* Bit 1: D17 - Sleep in selected */ +#define PCF8833_ST_PARTIAL (1 << 2) /* Bit 2: D18 - Partial mode on */ +#define PCF8833_ST_IDLE (1 << 3) /* Bit 3: D19 - Idle mode selected */ +#define PCF8833_ST_PIXELFMT_SHIFT (4) /* Bits 4-6: D20-D22 - Interface pixel format */ +#define PCF8833_ST_PIXELFMT_MASK (7 << PCF8833_ST_PIXELFMT_SHIFT) +# define PCF8833_ST_PIXELFMT_8BPS (PCF8833_FMT_8BPS << PCF8833_ST_PIXELFMT_SHIFT) +# define PCF8833_ST_PIXELFMT_12BPS (PCF8833_FMT_12BPS << PCF8833_ST_PIXELFMT_SHIFT) +# define PCF8833_ST_PIXELFMT_16BPS (PCF8833_FMT_16BPS << PCF8833_ST_PIXELFMT_SHIFT) + +/* Byte 3: D15 -- D13 D12 D11 D10 D9 --- */ + +#define PCF8833_ST_TEARING (1 << 1) /* Bit 1: D9 - Tearing effect on */ +#define PCF8833_ST_DISPLAYON (1 << 2) /* Bit 2: D10 - Display on */ +#define PCF8833_ST_PIXELSOFF (1 << 3) /* Bit 3: D11 - All pixels off */ +#define PCF8833_ST_PIXELSON (1 << 4) /* Bit 4: D12 - All pixels on */ +#define PCF8833_ST_INV (1 << 5) /* Bit 5: D13 - Display inversion */ +#define PCF8833_ST_VSCROLL (1 << 7) /* Bit 6: D15 - Vertical scroll mode */ + +/* Byte 4: All zero */ + #endif /* __DRIVERS_LCD_PCF8833_H */ \ No newline at end of file diff --git a/nuttx/drivers/lcd/s1d15g10.h b/nuttx/drivers/lcd/s1d15g10.h index df2dd8be27..9b5f7738fe 100644 --- a/nuttx/drivers/lcd/s1d15g10.h +++ b/nuttx/drivers/lcd/s1d15g10.h @@ -1,141 +1,141 @@ -/************************************************************************************** - * drivers/lcd/s1d15g10.h - * Definitions for the Epson S1D15G0 LCD controller - * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * References: S1D15G0D08B000, Seiko Epson Corportation, 2002. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - **************************************************************************************/ - -#ifndef __DRIVERS_LCD_S1D15G10_H -#define __DRIVERS_LCD_S1D15G10_H - -/************************************************************************************** - * Included Files - **************************************************************************************/ - -/************************************************************************************** - * Pre-processor Definitions - **************************************************************************************/ - -/* Epson S1D15G10 Command Set */ - -#define S1D15G10_DISON 0xaf /* Display on; Data: none */ -#define S1D15G10_DISOFF 0xae /* Display off; Data: none */ -#define S1D15G10_DISNOR 0xa6 /* Normal display; Data: none */ -#define S1D15G10_DISINV 0xa7 /* Inverse display; Data: none */ -#define S1D15G10_COMSCN 0xbb /* Common scan direction; Data: (1) common scan direction */ -#define S1D15G10_DISCTL 0xca /* Display control; Data: Data: (1) CL div, F1/2 pat, (2) duty, (3) FR inverse (4) dispersion */ -#define S1D15G10_SLPIN 0x95 /* Sleep in; Data: none */ -#define S1D15G10_SLPOUT 0x94 /* Sleep out; Data: none */ -#define S1D15G10_PASET 0x75 /* Page address set; Data: (1) start page, (2) end page */ -#define S1D15G10_CASET 0x15 /* Column address set; Data: (1) start addr, (2) end addr */ -#define S1D15G10_DATCTL 0xbc /* Data scan direction, etc.; Data: (1) inverse, scan dir (2) RGB, (3) gray-scale */ -#define S1D15G10_RGBSET8 0xce /* 256-color position set; Data: (1-8) red tones, (9-16) green tones, (17-20) blue tones */ -#define S1D15G10_RAMWR 0x5c /* Writing to memory; Data: (1) write data */ -#define S1D15G10_RAMRD 0x5d /* Reading from memory; Data: (1) read data */ -#define S1D15G10_PTLIN 0xa8 /* Partial display in; Data: (1) start addr, (2) end addr */ -#define S1D15G10_PTLOUT 0xa9 /* Partial display out; Data: none */ -#define S1D15G10_RMWIN 0xe0 /* Read and modify write; Data: none */ -#define S1D15G10_RMWOUT 0xee /* End; Data: none */ -#define S1D15G10_ASCSET 0xaa /* Area scroll set; Data: (1) top addr, (2) bottom addr, (3) Num blocks, (4) scroll mode */ -#define S1D15G10_SCSTART 0xab /* Scroll start set; Data: (1) start block addr */ -#define S1D15G10_OSCON 0xd1 /* Internal oscillation on; Data: none */ -#define S1D15G10_OSCOFF 0xd2 /* Internal oscillation off; Data: none */ -#define S1D15G10_PWRCTR 0x20 /* Power control; Data: (1) LCD drive power */ -#define S1D15G10_VOLCTR 0x81 /* Electronic volume control; Data: (1) volume value, (2) resistance ratio */ -#define S1D15G10_VOLUP 0xd6 /* Increment electronic control by 1; Data: none */ -#define S1D15G10_VOLDOWN 0xd7 /* Decrement electronic control by 1; Data: none */ -#define S1D15G10_TMPGRD 0x82 /* Temperature gradient set; Data: (1-14) temperature gradient */ -#define S1D15G10_EPCTIN 0xcd /* Control EEPROM; Data: (1) read/write */ -#define S1D15G10_EPCOUT 0xcc /* Cancel EEPROM control; Data: none */ -#define S1D15G10_EPMWR 0xfc /* Write into EEPROM; Data: none */ -#define S1D15G10_EPMRD 0xfd /* Read from EEPROM; Data: none */ -#define S1D15G10_EPSRRD1 0x7c /* Read register 1; Data: none */ -#define S1D15G10_EPSRRD2 0x7d /* Read regiser 2; Data: none */ -#define S1D15G10_NOP 0x25 /* NOP intruction (0x45?); Data: none */ -#define S1D15G10_STREAD 0x20 /* Status read; Data: none */ - -/* Display control (DISCTL) bit definitions */ - -#define DISCTL_PERIOD_SHIFT (0) /* P1: Bits 0-1, F1 and F2 drive-pattern switching period */ -#define DISCTL_PERIOD_MASK (3 << DISCTL_PERIOD_SHIFT) -# define DISCTL_PERIOD_8 (0 << DISCTL_PERIOD_SHIFT) -# define DISCTL_PERIOD_4 (1 << DISCTL_PERIOD_SHIFT) -# define DISCTL_PERIOD_16 (2 << DISCTL_PERIOD_SHIFT) -# define DISCTL_PERIOD_FLD (3 << DISCTL_PERIOD_SHIFT) -#define DISCTL_CLDIV_SHIFT (2) /* P1: Bits 2-4, Clock divider */ -#define DISCTL_CLDIV_MASK (7 << DISCTL_CLDIV_SHIFT) -# define DISCTL_CLDIV_2 (0 << DISCTL_CLDIV_SHIFT) -# define DISCTL_CLDIV_4 (1 << DISCTL_CLDIV_SHIFT) -# define DISCTL_CLDIV_8 (2 << DISCTL_CLDIV_SHIFT) -# define DISCTL_CLDIV_NONE (3 << DISCTL_CLDIV_SHIFT) - -/* Power control (PWRCTR) bit definitions */ - -#define PWCTR_REFVOLTAGE (1 << 0) /* P1: Bit 0, Turn on reference voltage generation circuit. */ -#define PWCTR_REGULATOR (1 << 1) /* P1: Bit 1, Turn on voltage regulator and circuit voltage follower. */ -#define PWCTR_BOOSTER2 (1 << 2) /* P1: Bit 2, Turn on secondary booster/step-down circuit. */ -#define PWCTR_BOOSTER1 (1 << 3) /* P1: Bit 3, Turn on primary booster circuit. */ -#define PWCTR_EXTR (1 << 4) /* P1: Bit 4, Use external resistance to adjust voltage. */ - -/* Data control (DATCTL) bit definitions */ - -#define DATCTL_PGADDR_INV (1 << 0) /* P1: Bit 0, Inverse display of the page address. */ -#define DATCTL_COLADDR_REV (1 << 1) /* P1: Bit 1, Reverse turn of column address. */ -#define DATCTL_ADDR_PGDIR (1 << 2) /* P1: Bit 2, Address-scan direction in page (vs column) direction. */ - -#define DATCTL_BGR (1 << 0) /* P2: Bit0, RGB->BGR */ - -#define DATCTL_8GRAY (1) /* P3: Bits 0-2 = 001, 8 gray-scale */ -#define DATCTL_16GRAY_A (2) /* P3: Bits 0-2 = 010, 16 gray-scale display type A */ -#define DATCTL_16GRAY_B (4) /* P3: Bits 0-2 = 100, 16 gray-scale display type B */ - -/* Status register bit definions (after reset or NOP) */ - -#define S1D15G10_SR_PARTIAL (1 << 0) /* Bit 0: Partial display */ -#define S1D15G10_SR_NORMAL (1 << 1) /* Bit 1: Normal (vs. inverse) display */ -#define S1D15G10_SR_EEPROM (1 << 2) /* Bit 2: EEPROM access */ -#define S1D15G10_SR_DISPON (1 << 3) /* Bit 3: Display on */ -#define S1D15G10_SR_COLSCAN (1 << 4) /* Bit 4: Column (vs. page) scan direction */ -#define S1D15G10_SR_RMW (1 << 5) /* Bit 5: Read modify write */ -#define S1D15G10_SR_SCROLL (3 << 6) /* Bits 6-7: Area scroll mode */ - -/* Status register bit definions (after EPSRRD1) */ - -#define S1D15G10_SR_VOLUME 0x3f /* Bits 0-5: Electronic volume control values */ - -/* Status register bit definions (after EPSRRD2) */ - -#define S1D15G10_SR_RRATIO 0x07 /* Bits 0-2: Built-in resistance ratio */ - +/************************************************************************************** + * drivers/lcd/s1d15g10.h + * Definitions for the Epson S1D15G0 LCD controller + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * References: S1D15G0D08B000, Seiko Epson Corportation, 2002. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************************/ + +#ifndef __DRIVERS_LCD_S1D15G10_H +#define __DRIVERS_LCD_S1D15G10_H + +/************************************************************************************** + * Included Files + **************************************************************************************/ + +/************************************************************************************** + * Pre-processor Definitions + **************************************************************************************/ + +/* Epson S1D15G10 Command Set */ + +#define S1D15G10_DISON 0xaf /* Display on; Data: none */ +#define S1D15G10_DISOFF 0xae /* Display off; Data: none */ +#define S1D15G10_DISNOR 0xa6 /* Normal display; Data: none */ +#define S1D15G10_DISINV 0xa7 /* Inverse display; Data: none */ +#define S1D15G10_COMSCN 0xbb /* Common scan direction; Data: (1) common scan direction */ +#define S1D15G10_DISCTL 0xca /* Display control; Data: Data: (1) CL div, F1/2 pat, (2) duty, (3) FR inverse (4) dispersion */ +#define S1D15G10_SLPIN 0x95 /* Sleep in; Data: none */ +#define S1D15G10_SLPOUT 0x94 /* Sleep out; Data: none */ +#define S1D15G10_PASET 0x75 /* Page address set; Data: (1) start page, (2) end page */ +#define S1D15G10_CASET 0x15 /* Column address set; Data: (1) start addr, (2) end addr */ +#define S1D15G10_DATCTL 0xbc /* Data scan direction, etc.; Data: (1) inverse, scan dir (2) RGB, (3) gray-scale */ +#define S1D15G10_RGBSET8 0xce /* 256-color position set; Data: (1-8) red tones, (9-16) green tones, (17-20) blue tones */ +#define S1D15G10_RAMWR 0x5c /* Writing to memory; Data: (1) write data */ +#define S1D15G10_RAMRD 0x5d /* Reading from memory; Data: (1) read data */ +#define S1D15G10_PTLIN 0xa8 /* Partial display in; Data: (1) start addr, (2) end addr */ +#define S1D15G10_PTLOUT 0xa9 /* Partial display out; Data: none */ +#define S1D15G10_RMWIN 0xe0 /* Read and modify write; Data: none */ +#define S1D15G10_RMWOUT 0xee /* End; Data: none */ +#define S1D15G10_ASCSET 0xaa /* Area scroll set; Data: (1) top addr, (2) bottom addr, (3) Num blocks, (4) scroll mode */ +#define S1D15G10_SCSTART 0xab /* Scroll start set; Data: (1) start block addr */ +#define S1D15G10_OSCON 0xd1 /* Internal oscillation on; Data: none */ +#define S1D15G10_OSCOFF 0xd2 /* Internal oscillation off; Data: none */ +#define S1D15G10_PWRCTR 0x20 /* Power control; Data: (1) LCD drive power */ +#define S1D15G10_VOLCTR 0x81 /* Electronic volume control; Data: (1) volume value, (2) resistance ratio */ +#define S1D15G10_VOLUP 0xd6 /* Increment electronic control by 1; Data: none */ +#define S1D15G10_VOLDOWN 0xd7 /* Decrement electronic control by 1; Data: none */ +#define S1D15G10_TMPGRD 0x82 /* Temperature gradient set; Data: (1-14) temperature gradient */ +#define S1D15G10_EPCTIN 0xcd /* Control EEPROM; Data: (1) read/write */ +#define S1D15G10_EPCOUT 0xcc /* Cancel EEPROM control; Data: none */ +#define S1D15G10_EPMWR 0xfc /* Write into EEPROM; Data: none */ +#define S1D15G10_EPMRD 0xfd /* Read from EEPROM; Data: none */ +#define S1D15G10_EPSRRD1 0x7c /* Read register 1; Data: none */ +#define S1D15G10_EPSRRD2 0x7d /* Read regiser 2; Data: none */ +#define S1D15G10_NOP 0x25 /* NOP intruction (0x45?); Data: none */ +#define S1D15G10_STREAD 0x20 /* Status read; Data: none */ + +/* Display control (DISCTL) bit definitions */ + +#define DISCTL_PERIOD_SHIFT (0) /* P1: Bits 0-1, F1 and F2 drive-pattern switching period */ +#define DISCTL_PERIOD_MASK (3 << DISCTL_PERIOD_SHIFT) +# define DISCTL_PERIOD_8 (0 << DISCTL_PERIOD_SHIFT) +# define DISCTL_PERIOD_4 (1 << DISCTL_PERIOD_SHIFT) +# define DISCTL_PERIOD_16 (2 << DISCTL_PERIOD_SHIFT) +# define DISCTL_PERIOD_FLD (3 << DISCTL_PERIOD_SHIFT) +#define DISCTL_CLDIV_SHIFT (2) /* P1: Bits 2-4, Clock divider */ +#define DISCTL_CLDIV_MASK (7 << DISCTL_CLDIV_SHIFT) +# define DISCTL_CLDIV_2 (0 << DISCTL_CLDIV_SHIFT) +# define DISCTL_CLDIV_4 (1 << DISCTL_CLDIV_SHIFT) +# define DISCTL_CLDIV_8 (2 << DISCTL_CLDIV_SHIFT) +# define DISCTL_CLDIV_NONE (3 << DISCTL_CLDIV_SHIFT) + +/* Power control (PWRCTR) bit definitions */ + +#define PWCTR_REFVOLTAGE (1 << 0) /* P1: Bit 0, Turn on reference voltage generation circuit. */ +#define PWCTR_REGULATOR (1 << 1) /* P1: Bit 1, Turn on voltage regulator and circuit voltage follower. */ +#define PWCTR_BOOSTER2 (1 << 2) /* P1: Bit 2, Turn on secondary booster/step-down circuit. */ +#define PWCTR_BOOSTER1 (1 << 3) /* P1: Bit 3, Turn on primary booster circuit. */ +#define PWCTR_EXTR (1 << 4) /* P1: Bit 4, Use external resistance to adjust voltage. */ + +/* Data control (DATCTL) bit definitions */ + +#define DATCTL_PGADDR_INV (1 << 0) /* P1: Bit 0, Inverse display of the page address. */ +#define DATCTL_COLADDR_REV (1 << 1) /* P1: Bit 1, Reverse turn of column address. */ +#define DATCTL_ADDR_PGDIR (1 << 2) /* P1: Bit 2, Address-scan direction in page (vs column) direction. */ + +#define DATCTL_BGR (1 << 0) /* P2: Bit0, RGB->BGR */ + +#define DATCTL_8GRAY (1) /* P3: Bits 0-2 = 001, 8 gray-scale */ +#define DATCTL_16GRAY_A (2) /* P3: Bits 0-2 = 010, 16 gray-scale display type A */ +#define DATCTL_16GRAY_B (4) /* P3: Bits 0-2 = 100, 16 gray-scale display type B */ + +/* Status register bit definions (after reset or NOP) */ + +#define S1D15G10_SR_PARTIAL (1 << 0) /* Bit 0: Partial display */ +#define S1D15G10_SR_NORMAL (1 << 1) /* Bit 1: Normal (vs. inverse) display */ +#define S1D15G10_SR_EEPROM (1 << 2) /* Bit 2: EEPROM access */ +#define S1D15G10_SR_DISPON (1 << 3) /* Bit 3: Display on */ +#define S1D15G10_SR_COLSCAN (1 << 4) /* Bit 4: Column (vs. page) scan direction */ +#define S1D15G10_SR_RMW (1 << 5) /* Bit 5: Read modify write */ +#define S1D15G10_SR_SCROLL (3 << 6) /* Bits 6-7: Area scroll mode */ + +/* Status register bit definions (after EPSRRD1) */ + +#define S1D15G10_SR_VOLUME 0x3f /* Bits 0-5: Electronic volume control values */ + +/* Status register bit definions (after EPSRRD2) */ + +#define S1D15G10_SR_RRATIO 0x07 /* Bits 0-2: Built-in resistance ratio */ + #endif /* __DRIVERS_LCD_S1D15G10_H */ \ No newline at end of file diff --git a/nuttx/drivers/lcd/skeleton.c b/nuttx/drivers/lcd/skeleton.c index 1cb8b5955b..83aa92018c 100644 --- a/nuttx/drivers/lcd/skeleton.c +++ b/nuttx/drivers/lcd/skeleton.c @@ -2,7 +2,7 @@ * drivers/lcd/skeleton.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/lcd/ssd1305.h b/nuttx/drivers/lcd/ssd1305.h index 87c955de4d..34678fa80d 100644 --- a/nuttx/drivers/lcd/ssd1305.h +++ b/nuttx/drivers/lcd/ssd1305.h @@ -1,211 +1,211 @@ -/************************************************************************************** - * drivers/lcd/ssd1305.h - * Definitions for the Solomon Systech SSD1305 132x64 Dot Matrix OLED/PLED - * Segment/Common Driver with C - * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * References: SSD1305.pdf, "Solomon Systech SSD1305 132x64 Dot Matrix OLED/PLED - * Segment/Common Driver with Controller," Solomon Systech Limited, - * http://www.solomon-systech.com, May, 2008. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - **************************************************************************************/ - -#ifndef __DRIVERS_LCD_SSD1305_H -#define __DRIVERS_LCD_SSD1305_H - -/************************************************************************************** - * Included Files - **************************************************************************************/ - -/************************************************************************************** - * Pre-processor Definitions - **************************************************************************************/ -/* General Definitions ******************************************************/ - -#define SSD1305_COLORA 0 -#define SSD1305_COLORB 1 -#define SSD1305_COLORC 2 -#define SSD1305_COLORD 3 - -/* Fundamental Commands *****************************************************/ -#define SSD1305_SETCOLL 0x00 /* 0x00-0x0f: Set lower column address */ -# define SSD1305_COLL_MASK 0x0f -#define SSD1305_SETCOLH 0x10 /* 0x10-0x1f: Set higher column address */ -# define SSD1305_COLH_MASK 0x0f -#define SSD1305_ADDRMODE 0x20 /* 0x20: Set memory address mode */ -# define SSD1305_ADDRMODE_HOR 0x00 /* Data 1: Set horizontal address mode */ -# define SSD1305_ADDRMODE_VIRT 0x01 /* Data 1: Set virtal address mode */ -# define SSD1305_ADDRMODE_PAGE 0x02 /* Data 1: Set page address mode */ -#define SSD1305_SETCOLADDR 0x21 /* 0x21: Set column address */ - /* Data 1: Column start address: 0-131 */ - /* Data 2: Column end address: 0-131 */ -#define SSD1305_SETPAGEADDR 0x22 /* 0x22: Set page address */ - /* Data 1: Page start address: 0x00-0x7d */ - /* Data 2: Page end address: 0x00-0x7d */ -#define SSD1305_SETSTARTLINE 0x40 /* 0x40-7f: Set display start line */ -# define SSD1305_STARTLINE_MASK 0x3f - -#define SSD1305_SETCONTRAST 0x81 /* 0x81: Set contrast control */ - /* Data 1: Set 1 of 256 contrast steps */ -#define SSD1305_SETBRIGHTNESS 0x82 /* 0x82: Set brightness */ - /* Data 1: Set 1 of 256 contrast steps */ -#define SSD1305_SETLUT 0x91 /* 0x01: Set lookup table */ - /* Data 1: Pulse width: 31-63 */ - /* Data 2: Color A: 31-63 */ - /* Data 3: Color B: 31-63 */ - /* Data 4: Color C: 31-63 */ -#define SSD1305_SETBANKCOLOR1 0x92 /* 0x92: Set bank 1-16 color */ -# define SSD1305_SETBANK1(c) (c) /* Data 1, Bits 0-1: Bank 1 color */ -# define SSD1305_SETBANK2(c) (c << 2) /* Data 1, Bits 2-3: Bank 2 color */ -# define SSD1305_SETBANK3(c) (c << 4) /* Data 1, Bits 4-5: Bank 3 color */ -# define SSD1305_SETBANK4(c) (c << 6) /* Data 1, Bits 6-7: Bank 4 color */ -# define SSD1305_SETBANK5(c) (c) /* Data 2, Bits 0-1: Bank 5 color */ -# define SSD1305_SETBANK6(c) (c << 2) /* Data 2, Bits 2-3: Bank 6 color */ -# define SSD1305_SETBANK7(c) (c << 4) /* Data 2, Bits 4-5: Bank 7 color */ -# define SSD1305_SETBANK8(c) (c << 6) /* Data 2, Bits 6-7: Bank 8 color */ -# define SSD1305_SETBANK9(c) (c) /* Data 3, Bits 0-1: Bank 9 color */ -# define SSD1305_SETBANK10(c) (c << 2) /* Data 3, Bits 2-3: Bank 10 color */ -# define SSD1305_SETBANK11(c) (c << 4) /* Data 3, Bits 4-5: Bank 11 color */ -# define SSD1305_SETBANK12(c) (c << 6) /* Data 3, Bits 6-7: Bank 12 color */ -# define SSD1305_SETBANK13(c) (c) /* Data 4, Bits 0-1: Bank 13 color */ -# define SSD1305_SETBANK14(c) (c << 2) /* Data 4, Bits 2-3: Bank 14 color */ -# define SSD1305_SETBANK15(c) (c << 4) /* Data 4, Bits 4-5: Bank 15 color */ -# define SSD1305_SETBANK16(c) (c << 6) /* Data 4, Bits 6-7: Bank 16 color */ -#define SSD1305_SETBANKCOLOR2 0x93 /* 0x93: Set bank 17-32 color */ -# define SSD1305_SETBANK17(c) (c) /* Data 1, Bits 0-1: Bank 17 color */ -# define SSD1305_SETBANK18(c) (c << 2) /* Data 1, Bits 2-3: Bank 18 color */ -# define SSD1305_SETBANK19(c) (c << 4) /* Data 1, Bits 4-5: Bank 19 color */ -# define SSD1305_SETBANK20(c) (c << 6) /* Data 1, Bits 6-7: Bank 20 color */ -# define SSD1305_SETBANK21(c) (c) /* Data 2, Bits 0-1: Bank 21 color */ -# define SSD1305_SETBANK22(c) (c << 2) /* Data 2, Bits 2-3: Bank 22 color */ -# define SSD1305_SETBANK23(c) (c << 4) /* Data 2, Bits 4-5: Bank 23 color */ -# define SSD1305_SETBANK24(c) (c << 6) /* Data 2, Bits 6-7: Bank 24 color */ -# define SSD1305_SETBANK25(c) (c) /* Data 3, Bits 0-1: Bank 25 color */ -# define SSD1305_SETBANK26(c) (c << 2) /* Data 3, Bits 2-3: Bank 26 color */ -# define SSD1305_SETBANK27(c) (c << 4) /* Data 3, Bits 4-5: Bank 27 color */ -# define SSD1305_SETBANK28(c) (c << 6) /* Data 3, Bits 6-7: Bank 28 color */ -# define SSD1305_SETBANK29(c) (c) /* Data 4, Bits 0-1: Bank 29 color */ -# define SSD1305_SETBANK30(c) (c << 2) /* Data 4, Bits 2-3: Bank 30 color */ -# define SSD1305_SETBANK31(c) (c << 4) /* Data 4, Bits 4-5: Bank 31 color */ -# define SSD1305_SETBANK32(c) (c << 6) /* Data 4, Bits 6-7: Bank 32 color */ -#define SSD1305_MAPCOL0 0xa0 /* 0xa0: Column address 0 is mapped to SEG0 */ -#define SSD1305_MAPCOL131 0xa1 /* 0xa1: Column address 131 is mapped to SEG0 */ -#define SSD1305_DISPRAM 0xa4 /* 0xa4: Resume to RAM content display */ -#define SSD1305_DISPENTIRE 0xa5 /* 0xa5: Entire display ON */ -#define SSD1305_DISPNORMAL 0xa6 /* 0xa6: Normal display */ -#define SSD1305_DISPINVERTED 0xa7 /* 0xa7: Inverse display */ - -#define SSD1305_SETMUX 0xa8 /* 0xa8: Set Multiplex Ratio*/ - /* Data 1: MUX ratio -1: 15-63 */ -#define SSD1305_DIMMODE 0xab /* 0xab: Dim mode setting */ - /* Data 1: Reserverd, must be zero */ - /* Data 2: Contrast for bank1: 0-255 */ - /* Data 3: Brightness for color bank: 0-255 */ -#define SSD1305_MSTRCONFIG 0xad /* 0xad: Master configuration */ -# define SSD1305_MSTRCONFIG_EXTVCC 0x8e /* Data 1: Select external Vcc */ -#define SSD1305_DISPONDIM 0xac /* 0xac: Display ON in dim mode */ -#define SSD1305_DISPOFF 0xae /* 0xae: Display OFF (sleep mode) */ -#define SSD1305_DISPON 0xaf /* 0xaf: Display ON in normal mode */ -#define SSD1305_SETPAGESTART 0xb0 /* 0xb0-b7: Set page start address */ -# define SSD1305_PAGESTART_MASK 0x07 -#define SSD1305_SETCOMNORMAL 0xc0 /* 0xc0: Set COM output, normal mode */ -#define SSD1305_SETCOMREMAPPED 0xc8 /* 0xc8: Set COM output, remapped mode */ - -#define SSD1305_SETOFFSET 0xd3 /* 0xd3: Set display offset */ - /* Data 1: Vertical shift by COM: 0-63 */ -#define SSD1305_SETDCLK 0xd5 /* 0xd5: Set display clock divide ratio/oscillator */ -# define SSD1305_DCLKDIV_SHIFT (0) /* Data 1, Bits 0-3: DCLK divide ratio/frequency*/ -# define SSD1305_DCLKDIV_MASK 0x0f -# define SSD1305_DCLKFREQ_SHIFT (4) /* Data 1, Bits 4-7: DCLK divide oscillator frequency */ -# define SSD1305_DCLKFREQ_MASK 0xf0 -#define SSD1305_SETCOLORMODE 0xd8 /* 0xd: Set area color and low power display modes */ -# define SSD1305_COLORMODE_MONO 0x00 /* Data 1, Bits 4-5: 00=monochrome */ -# define SSD1305_COLORMODE_COLOR 0x30 /* Data 1, Bits 4-5: 11=area color enable */ -# define SSD1305_POWERMODE_NORMAL 0x00 /* Data 1, Bits 0,2: 00=normal power mode */ -# define SSD1305_POWERMODE_LOW 0x05 /* Data 1, Bits 0,2: 11=low power display mode */ -#define SSD1305_SETPRECHARGE 0xd9 /* 0xd9: Set pre-charge period */ -# define SSD1305_PHASE1_SHIFT (0) /* Data 1, Bits 0-3: Phase 1 period of up to 15 DCLK clocks */ -# define SSD1305_PHASE1_MASK 0x0f -# define SSD1305_PHASE2_SHIFT (4) /* Data 1, Bits 4-7: Phase 2 period of up to 15 DCLK clocks */ -# define SSD1305_PHASE2_MASK 0xf0 -#define SSD1305_SETCOMCONFIG 0xda /* 0xda: Set COM configuration */ -# define SSD1305_COMCONFIG_SEQ 0x02 /* Data 1, Bit 4: 0=Sequential COM pin configuration */ -# define SSD1305_COMCONFIG_ALT 0x12 /* Data 1, Bit 4: 1=Alternative COM pin configuration */ -# define SSD1305_COMCONFIG_NOREMAP 0x02 /* Data 1, Bit 5: 0=Disable COM Left/Right remap */ -# define SSD1305_COMCONFIG_REMAP 0x22 /* Data 1, Bit 5: 1=Enable COM Left/Right remap */ -#define SSD1305_SETVCOMHDESEL 0xdb /* 0xdb: Set VCOMH delselect level */ -# define SSD1305_VCOMH_x4p3 0x00 /* Data 1: ~0.43 x Vcc */ -# define SSD1305_VCOMH_x7p7 0x34 /* Data 1: ~0.77 x Vcc */ -# define SSD1305_VCOMH_x8p3 0x3c /* Data 1: ~0.83 x Vcc */ -#define SSD1305_ENTER_RMWMODE 0xe0 /* 0xe0: Enter the Read Modify Write mode */ -#define SSD1305_NOP 0xe3 /* 0xe3: NOP Command for no operation */ -#define SSD1305_EXIT_RMWMODE 0xee /* 0xee: Leave the Read Modify Write mode */ - -/* Graphic Acceleration Commands ********************************************/ - -#define SSD1305_HSCROLL_RIGHT 0x26 /* 0x26: Right horizontal scroll */ -#define SSD1305_HSCROLL_LEFT 0x27 /* 0x27: Left horizontal scroll */ - /* Data 1, Bits 0-2: Column scroll offset: 0-4 */ - /* Data 2, Bits 0-2: Start page address: 0-7 */ -#define SSD1305_HSCROLL_FRAMES6 0x00 /* Data 3, Bits 0-2: Timer interval, 000=6 frames */ -#define SSD1305_HSCROLL_FRAMES32 0x01 /* Data 3, Bits 0-2: Timer interval, 001=32 frames */ -#define SSD1305_HSCROLL_FRAMES64 0x02 /* Data 3, Bits 0-2: Timer interval, 010=64 frames */ -#define SSD1305_HSCROLL_FRAMES128 0x03 /* Data 3, Bits 0-2: Timer interval, 011=128 frames */ -#define SSD1305_HSCROLL_FRAMES3 0x04 /* Data 3, Bits 0-2: Timer interval, 100=3 frames */ -#define SSD1305_HSCROLL_FRAMES4 0x05 /* Data 3, Bits 0-2: Timer interval, 101=4 frames */ -#define SSD1305_HSCROLL_FRAMES2 0x06 /* Data 3, Bits 0-2: Timer interval, 110=2 frames */ - /* Data 4, Bits 0-2: End page address: 0-7 */ - -#define SSD1305_VSCROLL_RIGHT 0x29 /* 0x26: Vertical and right horizontal scroll */ -#define SSD1305_VSCROLL_LEFT 0x2a /* 0x27: Vertical and left horizontal scroll */ - /* Data 1, Bits 0-2: Column scroll offset: 0-4 */ - /* Data 2, Bits 0-2: Start page address: 0-7 */ -#define SSD1305_VSCROLL_FRAMES6 0x00 /* Data 3, Bits 0-2: Timer interval, 000=6 frames */ -#define SSD1305_VSCROLL_FRAMES32 0x01 /* Data 3, Bits 0-2: Timer interval, 001=32 frames */ -#define SSD1305_VSCROLL_FRAMES64 0x02 /* Data 3, Bits 0-2: Timer interval, 010=64 frames */ -#define SSD1305_VSCROLL_FRAMES128 0x03 /* Data 3, Bits 0-2: Timer interval, 011=128 frames */ -#define SSD1305_VSCROLL_FRAMES3 0x04 /* Data 3, Bits 0-2: Timer interval, 100=3 frames */ -#define SSD1305_VSCROLL_FRAMES4 0x05 /* Data 3, Bits 0-2: Timer interval, 101=4 frames */ -#define SSD1305_VSCROLL_FRAMES2 0x06 /* Data 3, Bits 0-2: Timer interval, 110=2 frames */ - /* Data 4, Bits 0-2: End page address: 0-7 */ - /* Data 5, Bits 0-5: Vertical scrolling offset: 0-63 */ -#define SSD1305_SCROLL_STOP 0x2e /* 0x2e: Deactivate scroll */ -#define SSD1305_SCROLL_START 0x2f /* 0x2f: Activate scroll */ -#define SSD1305_VSCROLL_AREA 0xa3 /* 0xa3: Set vertical scroll area */ - /* Data 1: Number of rows in the top fixed area */ - /* Data 1: Number of rows in the scroll area */ - -/* Status register bit definitions ******************************************/ - -#define SSD1305_STATUS_DISPOFF (1 << 6) /* Bit 6: 1=Display off */ - -#endif /* __DRIVERS_LCD_SSD1305_H */ +/************************************************************************************** + * drivers/lcd/ssd1305.h + * Definitions for the Solomon Systech SSD1305 132x64 Dot Matrix OLED/PLED + * Segment/Common Driver with C + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * References: SSD1305.pdf, "Solomon Systech SSD1305 132x64 Dot Matrix OLED/PLED + * Segment/Common Driver with Controller," Solomon Systech Limited, + * http://www.solomon-systech.com, May, 2008. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************************/ + +#ifndef __DRIVERS_LCD_SSD1305_H +#define __DRIVERS_LCD_SSD1305_H + +/************************************************************************************** + * Included Files + **************************************************************************************/ + +/************************************************************************************** + * Pre-processor Definitions + **************************************************************************************/ +/* General Definitions ******************************************************/ + +#define SSD1305_COLORA 0 +#define SSD1305_COLORB 1 +#define SSD1305_COLORC 2 +#define SSD1305_COLORD 3 + +/* Fundamental Commands *****************************************************/ +#define SSD1305_SETCOLL 0x00 /* 0x00-0x0f: Set lower column address */ +# define SSD1305_COLL_MASK 0x0f +#define SSD1305_SETCOLH 0x10 /* 0x10-0x1f: Set higher column address */ +# define SSD1305_COLH_MASK 0x0f +#define SSD1305_ADDRMODE 0x20 /* 0x20: Set memory address mode */ +# define SSD1305_ADDRMODE_HOR 0x00 /* Data 1: Set horizontal address mode */ +# define SSD1305_ADDRMODE_VIRT 0x01 /* Data 1: Set virtal address mode */ +# define SSD1305_ADDRMODE_PAGE 0x02 /* Data 1: Set page address mode */ +#define SSD1305_SETCOLADDR 0x21 /* 0x21: Set column address */ + /* Data 1: Column start address: 0-131 */ + /* Data 2: Column end address: 0-131 */ +#define SSD1305_SETPAGEADDR 0x22 /* 0x22: Set page address */ + /* Data 1: Page start address: 0x00-0x7d */ + /* Data 2: Page end address: 0x00-0x7d */ +#define SSD1305_SETSTARTLINE 0x40 /* 0x40-7f: Set display start line */ +# define SSD1305_STARTLINE_MASK 0x3f + +#define SSD1305_SETCONTRAST 0x81 /* 0x81: Set contrast control */ + /* Data 1: Set 1 of 256 contrast steps */ +#define SSD1305_SETBRIGHTNESS 0x82 /* 0x82: Set brightness */ + /* Data 1: Set 1 of 256 contrast steps */ +#define SSD1305_SETLUT 0x91 /* 0x01: Set lookup table */ + /* Data 1: Pulse width: 31-63 */ + /* Data 2: Color A: 31-63 */ + /* Data 3: Color B: 31-63 */ + /* Data 4: Color C: 31-63 */ +#define SSD1305_SETBANKCOLOR1 0x92 /* 0x92: Set bank 1-16 color */ +# define SSD1305_SETBANK1(c) (c) /* Data 1, Bits 0-1: Bank 1 color */ +# define SSD1305_SETBANK2(c) (c << 2) /* Data 1, Bits 2-3: Bank 2 color */ +# define SSD1305_SETBANK3(c) (c << 4) /* Data 1, Bits 4-5: Bank 3 color */ +# define SSD1305_SETBANK4(c) (c << 6) /* Data 1, Bits 6-7: Bank 4 color */ +# define SSD1305_SETBANK5(c) (c) /* Data 2, Bits 0-1: Bank 5 color */ +# define SSD1305_SETBANK6(c) (c << 2) /* Data 2, Bits 2-3: Bank 6 color */ +# define SSD1305_SETBANK7(c) (c << 4) /* Data 2, Bits 4-5: Bank 7 color */ +# define SSD1305_SETBANK8(c) (c << 6) /* Data 2, Bits 6-7: Bank 8 color */ +# define SSD1305_SETBANK9(c) (c) /* Data 3, Bits 0-1: Bank 9 color */ +# define SSD1305_SETBANK10(c) (c << 2) /* Data 3, Bits 2-3: Bank 10 color */ +# define SSD1305_SETBANK11(c) (c << 4) /* Data 3, Bits 4-5: Bank 11 color */ +# define SSD1305_SETBANK12(c) (c << 6) /* Data 3, Bits 6-7: Bank 12 color */ +# define SSD1305_SETBANK13(c) (c) /* Data 4, Bits 0-1: Bank 13 color */ +# define SSD1305_SETBANK14(c) (c << 2) /* Data 4, Bits 2-3: Bank 14 color */ +# define SSD1305_SETBANK15(c) (c << 4) /* Data 4, Bits 4-5: Bank 15 color */ +# define SSD1305_SETBANK16(c) (c << 6) /* Data 4, Bits 6-7: Bank 16 color */ +#define SSD1305_SETBANKCOLOR2 0x93 /* 0x93: Set bank 17-32 color */ +# define SSD1305_SETBANK17(c) (c) /* Data 1, Bits 0-1: Bank 17 color */ +# define SSD1305_SETBANK18(c) (c << 2) /* Data 1, Bits 2-3: Bank 18 color */ +# define SSD1305_SETBANK19(c) (c << 4) /* Data 1, Bits 4-5: Bank 19 color */ +# define SSD1305_SETBANK20(c) (c << 6) /* Data 1, Bits 6-7: Bank 20 color */ +# define SSD1305_SETBANK21(c) (c) /* Data 2, Bits 0-1: Bank 21 color */ +# define SSD1305_SETBANK22(c) (c << 2) /* Data 2, Bits 2-3: Bank 22 color */ +# define SSD1305_SETBANK23(c) (c << 4) /* Data 2, Bits 4-5: Bank 23 color */ +# define SSD1305_SETBANK24(c) (c << 6) /* Data 2, Bits 6-7: Bank 24 color */ +# define SSD1305_SETBANK25(c) (c) /* Data 3, Bits 0-1: Bank 25 color */ +# define SSD1305_SETBANK26(c) (c << 2) /* Data 3, Bits 2-3: Bank 26 color */ +# define SSD1305_SETBANK27(c) (c << 4) /* Data 3, Bits 4-5: Bank 27 color */ +# define SSD1305_SETBANK28(c) (c << 6) /* Data 3, Bits 6-7: Bank 28 color */ +# define SSD1305_SETBANK29(c) (c) /* Data 4, Bits 0-1: Bank 29 color */ +# define SSD1305_SETBANK30(c) (c << 2) /* Data 4, Bits 2-3: Bank 30 color */ +# define SSD1305_SETBANK31(c) (c << 4) /* Data 4, Bits 4-5: Bank 31 color */ +# define SSD1305_SETBANK32(c) (c << 6) /* Data 4, Bits 6-7: Bank 32 color */ +#define SSD1305_MAPCOL0 0xa0 /* 0xa0: Column address 0 is mapped to SEG0 */ +#define SSD1305_MAPCOL131 0xa1 /* 0xa1: Column address 131 is mapped to SEG0 */ +#define SSD1305_DISPRAM 0xa4 /* 0xa4: Resume to RAM content display */ +#define SSD1305_DISPENTIRE 0xa5 /* 0xa5: Entire display ON */ +#define SSD1305_DISPNORMAL 0xa6 /* 0xa6: Normal display */ +#define SSD1305_DISPINVERTED 0xa7 /* 0xa7: Inverse display */ + +#define SSD1305_SETMUX 0xa8 /* 0xa8: Set Multiplex Ratio*/ + /* Data 1: MUX ratio -1: 15-63 */ +#define SSD1305_DIMMODE 0xab /* 0xab: Dim mode setting */ + /* Data 1: Reserverd, must be zero */ + /* Data 2: Contrast for bank1: 0-255 */ + /* Data 3: Brightness for color bank: 0-255 */ +#define SSD1305_MSTRCONFIG 0xad /* 0xad: Master configuration */ +# define SSD1305_MSTRCONFIG_EXTVCC 0x8e /* Data 1: Select external Vcc */ +#define SSD1305_DISPONDIM 0xac /* 0xac: Display ON in dim mode */ +#define SSD1305_DISPOFF 0xae /* 0xae: Display OFF (sleep mode) */ +#define SSD1305_DISPON 0xaf /* 0xaf: Display ON in normal mode */ +#define SSD1305_SETPAGESTART 0xb0 /* 0xb0-b7: Set page start address */ +# define SSD1305_PAGESTART_MASK 0x07 +#define SSD1305_SETCOMNORMAL 0xc0 /* 0xc0: Set COM output, normal mode */ +#define SSD1305_SETCOMREMAPPED 0xc8 /* 0xc8: Set COM output, remapped mode */ + +#define SSD1305_SETOFFSET 0xd3 /* 0xd3: Set display offset */ + /* Data 1: Vertical shift by COM: 0-63 */ +#define SSD1305_SETDCLK 0xd5 /* 0xd5: Set display clock divide ratio/oscillator */ +# define SSD1305_DCLKDIV_SHIFT (0) /* Data 1, Bits 0-3: DCLK divide ratio/frequency*/ +# define SSD1305_DCLKDIV_MASK 0x0f +# define SSD1305_DCLKFREQ_SHIFT (4) /* Data 1, Bits 4-7: DCLK divide oscillator frequency */ +# define SSD1305_DCLKFREQ_MASK 0xf0 +#define SSD1305_SETCOLORMODE 0xd8 /* 0xd: Set area color and low power display modes */ +# define SSD1305_COLORMODE_MONO 0x00 /* Data 1, Bits 4-5: 00=monochrome */ +# define SSD1305_COLORMODE_COLOR 0x30 /* Data 1, Bits 4-5: 11=area color enable */ +# define SSD1305_POWERMODE_NORMAL 0x00 /* Data 1, Bits 0,2: 00=normal power mode */ +# define SSD1305_POWERMODE_LOW 0x05 /* Data 1, Bits 0,2: 11=low power display mode */ +#define SSD1305_SETPRECHARGE 0xd9 /* 0xd9: Set pre-charge period */ +# define SSD1305_PHASE1_SHIFT (0) /* Data 1, Bits 0-3: Phase 1 period of up to 15 DCLK clocks */ +# define SSD1305_PHASE1_MASK 0x0f +# define SSD1305_PHASE2_SHIFT (4) /* Data 1, Bits 4-7: Phase 2 period of up to 15 DCLK clocks */ +# define SSD1305_PHASE2_MASK 0xf0 +#define SSD1305_SETCOMCONFIG 0xda /* 0xda: Set COM configuration */ +# define SSD1305_COMCONFIG_SEQ 0x02 /* Data 1, Bit 4: 0=Sequential COM pin configuration */ +# define SSD1305_COMCONFIG_ALT 0x12 /* Data 1, Bit 4: 1=Alternative COM pin configuration */ +# define SSD1305_COMCONFIG_NOREMAP 0x02 /* Data 1, Bit 5: 0=Disable COM Left/Right remap */ +# define SSD1305_COMCONFIG_REMAP 0x22 /* Data 1, Bit 5: 1=Enable COM Left/Right remap */ +#define SSD1305_SETVCOMHDESEL 0xdb /* 0xdb: Set VCOMH delselect level */ +# define SSD1305_VCOMH_x4p3 0x00 /* Data 1: ~0.43 x Vcc */ +# define SSD1305_VCOMH_x7p7 0x34 /* Data 1: ~0.77 x Vcc */ +# define SSD1305_VCOMH_x8p3 0x3c /* Data 1: ~0.83 x Vcc */ +#define SSD1305_ENTER_RMWMODE 0xe0 /* 0xe0: Enter the Read Modify Write mode */ +#define SSD1305_NOP 0xe3 /* 0xe3: NOP Command for no operation */ +#define SSD1305_EXIT_RMWMODE 0xee /* 0xee: Leave the Read Modify Write mode */ + +/* Graphic Acceleration Commands ********************************************/ + +#define SSD1305_HSCROLL_RIGHT 0x26 /* 0x26: Right horizontal scroll */ +#define SSD1305_HSCROLL_LEFT 0x27 /* 0x27: Left horizontal scroll */ + /* Data 1, Bits 0-2: Column scroll offset: 0-4 */ + /* Data 2, Bits 0-2: Start page address: 0-7 */ +#define SSD1305_HSCROLL_FRAMES6 0x00 /* Data 3, Bits 0-2: Timer interval, 000=6 frames */ +#define SSD1305_HSCROLL_FRAMES32 0x01 /* Data 3, Bits 0-2: Timer interval, 001=32 frames */ +#define SSD1305_HSCROLL_FRAMES64 0x02 /* Data 3, Bits 0-2: Timer interval, 010=64 frames */ +#define SSD1305_HSCROLL_FRAMES128 0x03 /* Data 3, Bits 0-2: Timer interval, 011=128 frames */ +#define SSD1305_HSCROLL_FRAMES3 0x04 /* Data 3, Bits 0-2: Timer interval, 100=3 frames */ +#define SSD1305_HSCROLL_FRAMES4 0x05 /* Data 3, Bits 0-2: Timer interval, 101=4 frames */ +#define SSD1305_HSCROLL_FRAMES2 0x06 /* Data 3, Bits 0-2: Timer interval, 110=2 frames */ + /* Data 4, Bits 0-2: End page address: 0-7 */ + +#define SSD1305_VSCROLL_RIGHT 0x29 /* 0x26: Vertical and right horizontal scroll */ +#define SSD1305_VSCROLL_LEFT 0x2a /* 0x27: Vertical and left horizontal scroll */ + /* Data 1, Bits 0-2: Column scroll offset: 0-4 */ + /* Data 2, Bits 0-2: Start page address: 0-7 */ +#define SSD1305_VSCROLL_FRAMES6 0x00 /* Data 3, Bits 0-2: Timer interval, 000=6 frames */ +#define SSD1305_VSCROLL_FRAMES32 0x01 /* Data 3, Bits 0-2: Timer interval, 001=32 frames */ +#define SSD1305_VSCROLL_FRAMES64 0x02 /* Data 3, Bits 0-2: Timer interval, 010=64 frames */ +#define SSD1305_VSCROLL_FRAMES128 0x03 /* Data 3, Bits 0-2: Timer interval, 011=128 frames */ +#define SSD1305_VSCROLL_FRAMES3 0x04 /* Data 3, Bits 0-2: Timer interval, 100=3 frames */ +#define SSD1305_VSCROLL_FRAMES4 0x05 /* Data 3, Bits 0-2: Timer interval, 101=4 frames */ +#define SSD1305_VSCROLL_FRAMES2 0x06 /* Data 3, Bits 0-2: Timer interval, 110=2 frames */ + /* Data 4, Bits 0-2: End page address: 0-7 */ + /* Data 5, Bits 0-5: Vertical scrolling offset: 0-63 */ +#define SSD1305_SCROLL_STOP 0x2e /* 0x2e: Deactivate scroll */ +#define SSD1305_SCROLL_START 0x2f /* 0x2f: Activate scroll */ +#define SSD1305_VSCROLL_AREA 0xa3 /* 0xa3: Set vertical scroll area */ + /* Data 1: Number of rows in the top fixed area */ + /* Data 1: Number of rows in the scroll area */ + +/* Status register bit definitions ******************************************/ + +#define SSD1305_STATUS_DISPOFF (1 << 6) /* Bit 6: 1=Display off */ + +#endif /* __DRIVERS_LCD_SSD1305_H */ diff --git a/nuttx/drivers/lcd/ug-9664hswag01.c b/nuttx/drivers/lcd/ug-9664hswag01.c index bb49f20e6b..e0e8e8e3a0 100644 --- a/nuttx/drivers/lcd/ug-9664hswag01.c +++ b/nuttx/drivers/lcd/ug-9664hswag01.c @@ -4,7 +4,7 @@ * controller. * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Reference: "Product Specification, OEL Display Module, UG-9664HSWAG01", Univision * Technology Inc., SAS1-6020-B, January 3, 2008. diff --git a/nuttx/drivers/mmcsd/Kconfig b/nuttx/drivers/mmcsd/Kconfig index fc682e7068..c224f220af 100644 --- a/nuttx/drivers/mmcsd/Kconfig +++ b/nuttx/drivers/mmcsd/Kconfig @@ -40,7 +40,7 @@ config MMCSD_HAVECARDDETECT config MMCSD_SPI bool "MMC/SD spi transfer support" default y - + config MMCSD_SPICLOCK int "MMC/SD maximum SPI clock" default 20000000 diff --git a/nuttx/drivers/mmcsd/Make.defs b/nuttx/drivers/mmcsd/Make.defs index 48e5d4fb6e..8504565972 100644 --- a/nuttx/drivers/mmcsd/Make.defs +++ b/nuttx/drivers/mmcsd/Make.defs @@ -2,7 +2,7 @@ # drivers/mmcsd/Make.defs # # Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mmcsd/mmcsd_csd.h b/nuttx/drivers/mmcsd/mmcsd_csd.h index e35eacad5b..d5343aa841 100644 --- a/nuttx/drivers/mmcsd/mmcsd_csd.h +++ b/nuttx/drivers/mmcsd/mmcsd_csd.h @@ -2,7 +2,7 @@ * drivers/mmcsd/mmcsd_csd.h * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mmcsd/mmcsd_debug.c b/nuttx/drivers/mmcsd/mmcsd_debug.c index 03872f5cf9..0bd7f896eb 100644 --- a/nuttx/drivers/mmcsd/mmcsd_debug.c +++ b/nuttx/drivers/mmcsd/mmcsd_debug.c @@ -2,7 +2,7 @@ * drivers/mmcsd/mmcsd_debug.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mmcsd/mmcsd_internal.h b/nuttx/drivers/mmcsd/mmcsd_internal.h index 577ebbba93..ed669cdfac 100644 --- a/nuttx/drivers/mmcsd/mmcsd_internal.h +++ b/nuttx/drivers/mmcsd/mmcsd_internal.h @@ -2,7 +2,7 @@ * drivers/mmcsd/mmcsd_internal.h * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.c b/nuttx/drivers/mmcsd/mmcsd_sdio.c index 90c73261a2..d0bc6659cb 100644 --- a/nuttx/drivers/mmcsd/mmcsd_sdio.c +++ b/nuttx/drivers/mmcsd/mmcsd_sdio.c @@ -3171,7 +3171,9 @@ errout_with_buffers: rwb_uninitialize(&priv->rwbuffer); errout_with_hwinit: #endif - mmcsd_hwuninitialize(priv); + mmcsd_hwuninitialize(priv); /* This will free the private data structure */ + return ret; + errout_with_alloc: kfree(priv); return ret; diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.h b/nuttx/drivers/mmcsd/mmcsd_sdio.h index 75c97bd65a..9e3794e257 100644 --- a/nuttx/drivers/mmcsd/mmcsd_sdio.h +++ b/nuttx/drivers/mmcsd/mmcsd_sdio.h @@ -1,339 +1,339 @@ -/******************************************************************************************** - * drivers/mmcsd/mmcsd_sdio.h - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ********************************************************************************************/ - -#ifndef __DRIVERS_MMCSD_MMCSD_SDIO_H -#define __DRIVERS_MMCSD_MMCSD_SDIO_H - -/******************************************************************************************** - * Included Files - ********************************************************************************************/ - -#include -#include - -/******************************************************************************************** - * Pre-Processor Definitions - ********************************************************************************************/ - -/* CMD8 Argument: - * [31:12]: Reserved (shall be set to '0') - * [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V) - * [7:0]: Check Pattern (recommended 0xaa) - * CMD8 Response: R7 - */ - -#define MMCSD_CMD8VOLTAGE_SHIFT (8) /* Bits 8-11: Supply voltage */ -#define MMCSD_CMD8VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_CMD8VOLTAGE_SHIFT) -# define MMCSD_CMD8VOLTAGE_27 ((uint32_t)0x01 << MMCSD_CMD8VOLTAGE_SHIFT) /* 2.7-3.6V */ -#define MMCSD_CMD8ECHO_SHIFT (0) /* Bits 0-7: Check pattern */ -#define MMCSD_CMD8ECHO_MASK ((uint32_t)0xff << MMCSD_CMD8ECHO_SHIFT) -# define MMCSD_CMD8CHECKPATTERN ((uint32_t)0xaa << MMCSD_CMD8ECHO_SHIFT) - -/* ACMD6 argument */ - -#define MMCSD_ACMD6_BUSWIDTH_1 ((uint32_t)0) /* Bus width = 1-bit */ -#define MMCSD_ACMD6_BUSWIDTH_4 ((uint32_t)2) /* Bus width = 4-bit */ - -/* ACMD41 argument */ - -#define MMCSD_ACMD41_VOLTAGEWINDOW ((uint32_t)0x80100000) -#define MMCSD_ACMD41_HIGHCAPACITY ((uint32_t)1 << 30) -#define MMCSD_ACMD41_STDCAPACITY ((uint32_t)0) - -/* ACMD42 argument */ - -#define MMCSD_ACMD42_CD_DISCONNECT ((uint32_t)0) /* Disconnect card detection logic */ -#define MMCSD_ACMD42_CD_CONNECT ((uint32_t)1) /* Connect card detection logic */ - -/* R1 Card Status bit definitions */ - -#define MMCSD_R1_OUTOFRANGE ((uint32_t)1 << 31) /* Bad argument */ -#define MMCSD_R1_ADDRESSERROR ((uint32_t)1 << 30) /* Bad address */ -#define MMCSD_R1_BLOCKLENERROR ((uint32_t)1 << 29) /* Bad block length */ -#define MMCSD_R1_ERASESEQERROR ((uint32_t)1 << 28) /* Erase cmd error */ -#define MMCSD_R1_ERASEPARAM ((uint32_t)1 << 27) /* Bad write blocks */ -#define MMCSD_R1_WPVIOLATION ((uint32_t)1 << 26) /* Erase access failure */ -#define MMCSD_R1_CARDISLOCKED ((uint32_t)1 << 25) /* Card is locked */ -#define MMCSD_R1_LOCKUNLOCKFAILED ((uint32_t)1 << 24) /* Password error */ -#define MMCSD_R1_COMCRCERROR ((uint32_t)1 << 23) /* CRC error */ -#define MMCSD_R1_ILLEGALCOMMAND ((uint32_t)1 << 22) /* Bad command */ -#define MMCSD_R1_CARDECCFAILED ((uint32_t)1 << 21) /* Failed to correct data */ -#define MMCSD_R1_CCERROR ((uint32_t)1 << 20) /* Card controller error */ -#define MMCSD_R1_ERROR ((uint32_t)1 << 19) /* General error */ -#define MMCSD_R1_UNDERRUN ((uint32_t)1 << 18) /* Underrun (MMC only) */ -#define MMCSD_R1_OVERRRUN ((uint32_t)1 << 17) /* Overrun (MMC only) */ -#define MMCSD_R1_CIDCSDOVERWRITE ((uint32_t)1 << 16) /* CID/CSD error */ -#define MMCSD_R1_WPERASESKIP ((uint32_t)1 << 15) /* Not all erased */ -#define MMCSD_R1_CARDECCDISABLED ((uint32_t)1 << 14) /* Internal ECC not used */ -#define MMCSD_R1_ERASERESET ((uint32_t)1 << 13) /* Reset sequence cleared */ -#define MMCSD_R1_STATE_SHIFT (9) /* Current card state */ -#define MMCSD_R1_STATE_MASK ((uint32_t)15 << MMCSD_R1_STATE_SHIFT) - /* Card identification mode states */ -# define MMCSD_R1_STATE_IDLE ((uint32_t)0 << MMCSD_R1_STATE_SHIFT) /* 0=Idle state */ -# define MMCSD_R1_STATE_READY ((uint32_t)1 << MMCSD_R1_STATE_SHIFT) /* 1=Ready state */ -# define MMCSD_R1_STATE_IDENT ((uint32_t)2 << MMCSD_R1_STATE_SHIFT) /* 2=Identification state */ - /* Data transfer states */ -# define MMCSD_R1_STATE_STBY ((uint32_t)3 << MMCSD_R1_STATE_SHIFT) /* 3=Standby state */ -# define MMCSD_R1_STATE_TRAN ((uint32_t)4 << MMCSD_R1_STATE_SHIFT) /* 4=Transfer state */ -# define MMCSD_R1_STATE_DATA ((uint32_t)5 << MMCSD_R1_STATE_SHIFT) /* 5=Sending data state */ -# define MMCSD_R1_STATE_RCV ((uint32_t)6 << MMCSD_R1_STATE_SHIFT) /* 6=Receiving data state */ -# define MMCSD_R1_STATE_PRG ((uint32_t)7 << MMCSD_R1_STATE_SHIFT) /* 7=Programming state */ -# define MMCSD_R1_STATE_DIS ((uint32_t)8 << MMCSD_R1_STATE_SHIFT) /* 8=Disconnect state */ -#define MMCSD_R1_READYFORDATA ((uint32_t)1 << 8) /* Buffer empty */ -#define MMCSD_R1_APPCMD ((uint32_t)1 << 5) /* Next CMD is ACMD */ -#define MMCSD_R1_AKESEQERROR ((uint32_t)1 << 3) /* Authentication error */ -#define MMCSD_R1_ERRORMASK ((uint32_t)0xfdffe008) /* Error mask */ - -#define IS_STATE(v,s) ((((uint32_t)v)&MMCSD_R1_STATE_MASK)==(s)) - -/* R3 (OCR) */ - -#define MMC_VDD_20_36 ((uint32_t)0x00ffff00) /* VDD voltage 2.0-3.6 */ - -#define MMCSD_VDD_145_150 ((uint32_t)1 << 0) /* VDD voltage 1.45 - 1.50 */ -#define MMCSD_VDD_150_155 ((uint32_t)1 << 1) /* VDD voltage 1.50 - 1.55 */ -#define MMCSD_VDD_155_160 ((uint32_t)1 << 2) /* VDD voltage 1.55 - 1.60 */ -#define MMCSD_VDD_160_165 ((uint32_t)1 << 3) /* VDD voltage 1.60 - 1.65 */ -#define MMCSD_VDD_165_170 ((uint32_t)1 << 4) /* VDD voltage 1.65 - 1.70 */ -#define MMCSD_VDD_17_18 ((uint32_t)1 << 5) /* VDD voltage 1.7 - 1.8 */ -#define MMCSD_VDD_18_19 ((uint32_t)1 << 6) /* VDD voltage 1.8 - 1.9 */ -#define MMCSD_VDD_19_20 ((uint32_t)1 << 7) /* VDD voltage 1.9 - 2.0 */ -#define MMCSD_VDD_20_21 ((uint32_t)1 << 8) /* VDD voltage 2.0-2.1 */ -#define MMCSD_VDD_21_22 ((uint32_t)1 << 9) /* VDD voltage 2.1-2.2 */ -#define MMCSD_VDD_22_23 ((uint32_t)1 << 10) /* VDD voltage 2.2-2.3 */ -#define MMCSD_VDD_23_24 ((uint32_t)1 << 11) /* VDD voltage 2.3-2.4 */ -#define MMCSD_VDD_24_25 ((uint32_t)1 << 12) /* VDD voltage 2.4-2.5 */ -#define MMCSD_VDD_25_26 ((uint32_t)1 << 13) /* VDD voltage 2.5-2.6 */ -#define MMCSD_VDD_26_27 ((uint32_t)1 << 14) /* VDD voltage 2.6-2.7 */ -#define MMCSD_VDD_27_28 ((uint32_t)1 << 15) /* VDD voltage 2.7-2.8 */ -#define MMCSD_VDD_28_29 ((uint32_t)1 << 16) /* VDD voltage 2.8-2.9 */ -#define MMCSD_VDD_29_30 ((uint32_t)1 << 17) /* VDD voltage 2.9-3.0 */ -#define MMCSD_VDD_30_31 ((uint32_t)1 << 18) /* VDD voltage 3.0-3.1 */ -#define MMCSD_VDD_31_32 ((uint32_t)1 << 19) /* VDD voltage 3.1-3.2 */ -#define MMCSD_VDD_32_33 ((uint32_t)1 << 20) /* VDD voltage 3.2-3.3 */ -#define MMCSD_VDD_33_34 ((uint32_t)1 << 21) /* VDD voltage 3.3-3.4 */ -#define MMCSD_VDD_34_35 ((uint32_t)1 << 22) /* VDD voltage 3.4-3.5 */ -#define MMCSD_VDD_35_36 ((uint32_t)1 << 23) /* VDD voltage 3.5-3.6 */ -#define MMCSD_R3_HIGHCAPACITY ((uint32_t)1 << 30) /* true: Card supports block addressing */ -#define MMCSD_CARD_BUSY ((uint32_t)1 << 31) /* Card power-up busy bit */ - -/* R6 Card Status bit definitions */ - -#define MMCSD_R6_RCA_SHIFT (16) /* New published RCA */ -#define MMCSD_R6_RCA_MASK ((uint32_t)0xffff << MMCSD_R6_RCA_SHIFT) -#define MMCSD_R6_COMCRCERROR ((uint32_t)1 << 15) /* CRC error */ -#define MMCSD_R6_ILLEGALCOMMAND ((uint32_t)1 << 14) /* Bad command */ -#define MMCSD_R6_ERROR ((uint32_t)1 << 13) /* General error */ -#define MMCSD_R6_STATE_SHIFT (9) /* Current card state */ -#define MMCSD_R6_STATE_MASK ((uint32_t)15 << MMCSD_R6_STATE_SHIFT) - /* Card identification mode states */ -# define MMCSD_R6_STATE_IDLE ((uint32_t)0 << MMCSD_R6_STATE_SHIFT) /* 0=Idle state */ -# define MMCSD_R6_STATE_READY ((uint32_t)1 << MMCSD_R6_STATE_SHIFT) /* 1=Ready state */ -# define MMCSD_R6_STATE_IDENT ((uint32_t)2 << MMCSD_R6_STATE_SHIFT) /* 2=Identification state */ - /* Data transfer states */ -# define MMCSD_R6_STATE_STBY ((uint32_t)3 << MMCSD_R6_STATE_SHIFT) /* 3=Standby state */ -# define MMCSD_R6_STATE_TRAN ((uint32_t)4 << MMCSD_R6_STATE_SHIFT) /* 4=Transfer state */ -# define MMCSD_R6_STATE_DATA (5(uint32_t) << MMCSD_R6_STATE_SHIFT) /* 5=Sending data state */ -# define MMCSD_R6_STATE_RCV ((uint32_t)6 << MMCSD_R6_STATE_SHIFT) /* 6=Receiving data state */ -# define MMCSD_R6_STATE_PRG ((uint32_t)7 << MMCSD_R6_STATE_SHIFT) /* 7=Programming state */ -# define MMCSD_R6_STATE_DIS ((uint32_t) << MMCSD_R6_STATE_SHIFT) /* 8=Disconnect state */ -#define MMCSD_R6_ERRORMASK ((uint32_t)0x0000e000) /* Error mask */ - -/* SD Configuration Register (SCR) encoding */ - -#define MMCSD_SCR_BUSWIDTH_1BIT (1) -#define MMCSD_SCR_BUSWIDTH_2BIT (2) -#define MMCSD_SCR_BUSWIDTH_4BIT (4) -#define MMCSD_SCR_BUSWIDTH_8BIT (8) - -/* Last 4 bytes of the 48-bit R7 response */ - -#define MMCSD_R7VERSION_SHIFT (28) /* Bits 28-31: Command version number */ -#define MMCSD_R7VERSION_MASK ((uint32_t)0x0f << MMCSD_R7VERSION_SHIFT) -#define MMCSD_R7VOLTAGE_SHIFT (8) /* Bits 8-11: Voltage accepted */ -#define MMCSD_R7VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_R7VOLTAGE_SHIFT) -# define MMCSD_R7VOLTAGE_27 ((uint32_t)0x01 << MMCSD_R7VOLTAGE_SHIFT) /* 2.7-3.6V */ -#define MMCSD_R7ECHO_SHIFT (0) /* Bits 0-7: Echoed check pattern */ -#define MMCSD_R7ECHO_MASK ((uint32_t)0xff << MMCSD_R7ECHO_SHIFT) -# define MMCSD_R7CHECKPATTERN ((uint32_t)0xaa << MMCSD_R7ECHO_SHIFT) - -/******************************************************************************************** - * Public Types - ********************************************************************************************/ - -/* Decoded Card Identification (CID) register */ - -struct mmcsd_cid_s -{ - uint8_t mid; /* 127:120 8-bit Manufacturer ID */ - uint16_t oid; /* 119:104 16-bit OEM/Application ID (ascii) */ - uint8_t pnm[6]; /* 103:64 40-bit Product Name (ascii) + null terminator */ - uint8_t prv; /* 63:56 8-bit Product revision */ - uint32_t psn; /* 55:24 32-bit Product serial number */ - /* 23:20 4-bit (reserved) */ - uint16_t mdt; /* 19:8 12-bit Manufacturing date */ - uint8_t crc; /* 7:1 7-bit CRC7 */ - /* 0:0 1-bit (not used) */ -}; - -/* Decoded Card Specific Data (CSD) register */ - -struct mmcsd_csd_s -{ - uint8_t csdstructure; /* 127:126 CSD structure */ - uint8_t mmcspecvers; /* 125:122 MMC Spec version (MMC only) */ - - struct - { - uint8_t timeunit; /* 2:0 Time exponent */ - uint8_t timevalue; /* 6:3 Time mantissa */ - } taac; /* 119:112 Data read access-time-1 */ - - uint8_t nsac; /* 111:104 Data read access-time-2 in CLK cycle(NSAC*100) */ - - struct - { - uint8_t transferrateunit; /* 2:0 Rate exponent */ - uint8_t timevalue; /* 6:3 Rate mantissa */ - } transpeed; /* 103:96 Max. data transfer rate */ - - uint16_t ccc; /* 95:84 Card command classes */ - uint8_t readbllen; /* 83:80 Max. read data block length */ - uint8_t readblpartial; /* 79:79 Partial blocks for read allowed */ - uint8_t writeblkmisalign; /* 78:78 Write block misalignment */ - uint8_t readblkmisalign; /* 77:77 Read block misalignment */ - uint8_t dsrimp; /* 76:76 DSR implemented */ - - union - { -#ifdef CONFIG_MMCSD_MMCSUPPORT - struct - { - uint16_t csize; /* 73:62 Device size */ - uint8_t vddrcurrmin; /* 61:59 Max. read current at Vdd min */ - uint8_t vddrcurrmax; /* 58:56 Max. read current at Vdd max */ - uint8_t vddwcurrmin; /* 55:53 Max. write current at Vdd min */ - uint8_t vddwcurrmax; /* 52:50 Max. write current at Vdd max */ - uint8_t csizemult; /* 49:47 Device size multiplier */ - - union - { - struct /* MMC system specification version 3.1 */ - { - uint8_t ergrpsize; /* 46:42 Erase group size (MMC 3.1) */ - uint8_t ergrpmult; /* 41:37 Erase group multiplier (MMC 3.1) */ - } mmc31; - struct /* MMC system specification version 2.2 */ - { - uint8_t sectorsize; /* 46:42 Erase sector size (MMC 2.2) */ - uint8_t ergrpsize; /* 41:37 Erase group size (MMC 2.2) */ - } mmc22; - } er; - - uint8_t mmcwpgrpsize; /* 36:32 Write protect group size (MMC) */ - } mmc; -#endif - struct - { - uint16_t csize; /* 73:62 Device size */ - uint8_t vddrcurrmin; /* 61:59 Max. read current at Vdd min */ - uint8_t vddrcurrmax; /* 58:56 Max. read current at Vdd max */ - uint8_t vddwcurrmin; /* 55:53 Max. write current at Vdd min */ - uint8_t vddwcurrmax; /* 52:50 Max. write current at Vdd max */ - uint8_t csizemult; /* 49:47 Device size multiplier */ - uint8_t sderblen; /* 46:46 Erase single block enable (SD) */ - uint8_t sdsectorsize; /* 45:39 Erase sector size (SD) */ - uint8_t sdwpgrpsize; /* 38:32 Write protect group size (SD) */ - } sdbyte; - - struct - { - /* 73:70 (reserved) */ - uint32_t csize; /* 69:48 Device size */ - /* 47:47 (reserved) */ - uint8_t sderblen; /* 46:46 Erase single block enable (SD) */ - uint8_t sdsectorsize; /* 45:39 Erase sector size (SD) */ - uint8_t sdwpgrpsize; /* 38:32 Write protect group size (SD) */ - } sdblock; - } u; - - uint8_t wpgrpen; /* 31:31 Write protect group enable */ - uint8_t mmcdfltecc; /* 30:29 Manufacturer default ECC (MMC) */ - uint8_t r2wfactor; /* 28:26 Write speed factor */ - uint8_t writebllen; /* 25:22 Max. write data block length */ - uint8_t writeblpartial; /* 21:21 Partial blocks for write allowed */ - uint8_t fileformatgrp; /* 15:15 File format group */ - uint8_t copy; /* 14:14 Copy flag (OTP) */ - uint8_t permwriteprotect; /* 13:13 Permanent write protection */ - uint8_t tmpwriteprotect; /* 12:12 Temporary write protection */ - uint8_t fileformat; /* 10:11 File format */ - uint8_t mmcecc; /* 9:8 ECC (MMC) */ - uint8_t crc; /* 7:1 CRC */ - /* 0:0 Not used */ -}; - -struct mmcsd_scr_s -{ - uint8_t scrversion; /* 63:60 Version of SCR structure */ - uint8_t sdversion; /* 59:56 SD memory card physical layer version */ - uint8_t erasestate; /* 55:55 Data state after erase (1 or 0) */ - uint8_t security; /* 54:52 SD security support */ - uint8_t buswidth; /* 51:48 DAT bus widthes supported */ - /* 47:32 SD reserved space */ - uint32_t mfgdata; /* 31:0 Reserved for manufacturing data */ -}; - -/******************************************************************************************** - * Public Data - ********************************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/******************************************************************************************** - * Public Functions - ********************************************************************************************/ - - -#undef EXTERN -#if defined(__cplusplus) -} -#endif -#endif /* __DRIVERS_MMCSD_MMCSD_SDIO_H */ +/******************************************************************************************** + * drivers/mmcsd/mmcsd_sdio.h + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ********************************************************************************************/ + +#ifndef __DRIVERS_MMCSD_MMCSD_SDIO_H +#define __DRIVERS_MMCSD_MMCSD_SDIO_H + +/******************************************************************************************** + * Included Files + ********************************************************************************************/ + +#include +#include + +/******************************************************************************************** + * Pre-Processor Definitions + ********************************************************************************************/ + +/* CMD8 Argument: + * [31:12]: Reserved (shall be set to '0') + * [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V) + * [7:0]: Check Pattern (recommended 0xaa) + * CMD8 Response: R7 + */ + +#define MMCSD_CMD8VOLTAGE_SHIFT (8) /* Bits 8-11: Supply voltage */ +#define MMCSD_CMD8VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_CMD8VOLTAGE_SHIFT) +# define MMCSD_CMD8VOLTAGE_27 ((uint32_t)0x01 << MMCSD_CMD8VOLTAGE_SHIFT) /* 2.7-3.6V */ +#define MMCSD_CMD8ECHO_SHIFT (0) /* Bits 0-7: Check pattern */ +#define MMCSD_CMD8ECHO_MASK ((uint32_t)0xff << MMCSD_CMD8ECHO_SHIFT) +# define MMCSD_CMD8CHECKPATTERN ((uint32_t)0xaa << MMCSD_CMD8ECHO_SHIFT) + +/* ACMD6 argument */ + +#define MMCSD_ACMD6_BUSWIDTH_1 ((uint32_t)0) /* Bus width = 1-bit */ +#define MMCSD_ACMD6_BUSWIDTH_4 ((uint32_t)2) /* Bus width = 4-bit */ + +/* ACMD41 argument */ + +#define MMCSD_ACMD41_VOLTAGEWINDOW ((uint32_t)0x80100000) +#define MMCSD_ACMD41_HIGHCAPACITY ((uint32_t)1 << 30) +#define MMCSD_ACMD41_STDCAPACITY ((uint32_t)0) + +/* ACMD42 argument */ + +#define MMCSD_ACMD42_CD_DISCONNECT ((uint32_t)0) /* Disconnect card detection logic */ +#define MMCSD_ACMD42_CD_CONNECT ((uint32_t)1) /* Connect card detection logic */ + +/* R1 Card Status bit definitions */ + +#define MMCSD_R1_OUTOFRANGE ((uint32_t)1 << 31) /* Bad argument */ +#define MMCSD_R1_ADDRESSERROR ((uint32_t)1 << 30) /* Bad address */ +#define MMCSD_R1_BLOCKLENERROR ((uint32_t)1 << 29) /* Bad block length */ +#define MMCSD_R1_ERASESEQERROR ((uint32_t)1 << 28) /* Erase cmd error */ +#define MMCSD_R1_ERASEPARAM ((uint32_t)1 << 27) /* Bad write blocks */ +#define MMCSD_R1_WPVIOLATION ((uint32_t)1 << 26) /* Erase access failure */ +#define MMCSD_R1_CARDISLOCKED ((uint32_t)1 << 25) /* Card is locked */ +#define MMCSD_R1_LOCKUNLOCKFAILED ((uint32_t)1 << 24) /* Password error */ +#define MMCSD_R1_COMCRCERROR ((uint32_t)1 << 23) /* CRC error */ +#define MMCSD_R1_ILLEGALCOMMAND ((uint32_t)1 << 22) /* Bad command */ +#define MMCSD_R1_CARDECCFAILED ((uint32_t)1 << 21) /* Failed to correct data */ +#define MMCSD_R1_CCERROR ((uint32_t)1 << 20) /* Card controller error */ +#define MMCSD_R1_ERROR ((uint32_t)1 << 19) /* General error */ +#define MMCSD_R1_UNDERRUN ((uint32_t)1 << 18) /* Underrun (MMC only) */ +#define MMCSD_R1_OVERRRUN ((uint32_t)1 << 17) /* Overrun (MMC only) */ +#define MMCSD_R1_CIDCSDOVERWRITE ((uint32_t)1 << 16) /* CID/CSD error */ +#define MMCSD_R1_WPERASESKIP ((uint32_t)1 << 15) /* Not all erased */ +#define MMCSD_R1_CARDECCDISABLED ((uint32_t)1 << 14) /* Internal ECC not used */ +#define MMCSD_R1_ERASERESET ((uint32_t)1 << 13) /* Reset sequence cleared */ +#define MMCSD_R1_STATE_SHIFT (9) /* Current card state */ +#define MMCSD_R1_STATE_MASK ((uint32_t)15 << MMCSD_R1_STATE_SHIFT) + /* Card identification mode states */ +# define MMCSD_R1_STATE_IDLE ((uint32_t)0 << MMCSD_R1_STATE_SHIFT) /* 0=Idle state */ +# define MMCSD_R1_STATE_READY ((uint32_t)1 << MMCSD_R1_STATE_SHIFT) /* 1=Ready state */ +# define MMCSD_R1_STATE_IDENT ((uint32_t)2 << MMCSD_R1_STATE_SHIFT) /* 2=Identification state */ + /* Data transfer states */ +# define MMCSD_R1_STATE_STBY ((uint32_t)3 << MMCSD_R1_STATE_SHIFT) /* 3=Standby state */ +# define MMCSD_R1_STATE_TRAN ((uint32_t)4 << MMCSD_R1_STATE_SHIFT) /* 4=Transfer state */ +# define MMCSD_R1_STATE_DATA ((uint32_t)5 << MMCSD_R1_STATE_SHIFT) /* 5=Sending data state */ +# define MMCSD_R1_STATE_RCV ((uint32_t)6 << MMCSD_R1_STATE_SHIFT) /* 6=Receiving data state */ +# define MMCSD_R1_STATE_PRG ((uint32_t)7 << MMCSD_R1_STATE_SHIFT) /* 7=Programming state */ +# define MMCSD_R1_STATE_DIS ((uint32_t)8 << MMCSD_R1_STATE_SHIFT) /* 8=Disconnect state */ +#define MMCSD_R1_READYFORDATA ((uint32_t)1 << 8) /* Buffer empty */ +#define MMCSD_R1_APPCMD ((uint32_t)1 << 5) /* Next CMD is ACMD */ +#define MMCSD_R1_AKESEQERROR ((uint32_t)1 << 3) /* Authentication error */ +#define MMCSD_R1_ERRORMASK ((uint32_t)0xfdffe008) /* Error mask */ + +#define IS_STATE(v,s) ((((uint32_t)v)&MMCSD_R1_STATE_MASK)==(s)) + +/* R3 (OCR) */ + +#define MMC_VDD_20_36 ((uint32_t)0x00ffff00) /* VDD voltage 2.0-3.6 */ + +#define MMCSD_VDD_145_150 ((uint32_t)1 << 0) /* VDD voltage 1.45 - 1.50 */ +#define MMCSD_VDD_150_155 ((uint32_t)1 << 1) /* VDD voltage 1.50 - 1.55 */ +#define MMCSD_VDD_155_160 ((uint32_t)1 << 2) /* VDD voltage 1.55 - 1.60 */ +#define MMCSD_VDD_160_165 ((uint32_t)1 << 3) /* VDD voltage 1.60 - 1.65 */ +#define MMCSD_VDD_165_170 ((uint32_t)1 << 4) /* VDD voltage 1.65 - 1.70 */ +#define MMCSD_VDD_17_18 ((uint32_t)1 << 5) /* VDD voltage 1.7 - 1.8 */ +#define MMCSD_VDD_18_19 ((uint32_t)1 << 6) /* VDD voltage 1.8 - 1.9 */ +#define MMCSD_VDD_19_20 ((uint32_t)1 << 7) /* VDD voltage 1.9 - 2.0 */ +#define MMCSD_VDD_20_21 ((uint32_t)1 << 8) /* VDD voltage 2.0-2.1 */ +#define MMCSD_VDD_21_22 ((uint32_t)1 << 9) /* VDD voltage 2.1-2.2 */ +#define MMCSD_VDD_22_23 ((uint32_t)1 << 10) /* VDD voltage 2.2-2.3 */ +#define MMCSD_VDD_23_24 ((uint32_t)1 << 11) /* VDD voltage 2.3-2.4 */ +#define MMCSD_VDD_24_25 ((uint32_t)1 << 12) /* VDD voltage 2.4-2.5 */ +#define MMCSD_VDD_25_26 ((uint32_t)1 << 13) /* VDD voltage 2.5-2.6 */ +#define MMCSD_VDD_26_27 ((uint32_t)1 << 14) /* VDD voltage 2.6-2.7 */ +#define MMCSD_VDD_27_28 ((uint32_t)1 << 15) /* VDD voltage 2.7-2.8 */ +#define MMCSD_VDD_28_29 ((uint32_t)1 << 16) /* VDD voltage 2.8-2.9 */ +#define MMCSD_VDD_29_30 ((uint32_t)1 << 17) /* VDD voltage 2.9-3.0 */ +#define MMCSD_VDD_30_31 ((uint32_t)1 << 18) /* VDD voltage 3.0-3.1 */ +#define MMCSD_VDD_31_32 ((uint32_t)1 << 19) /* VDD voltage 3.1-3.2 */ +#define MMCSD_VDD_32_33 ((uint32_t)1 << 20) /* VDD voltage 3.2-3.3 */ +#define MMCSD_VDD_33_34 ((uint32_t)1 << 21) /* VDD voltage 3.3-3.4 */ +#define MMCSD_VDD_34_35 ((uint32_t)1 << 22) /* VDD voltage 3.4-3.5 */ +#define MMCSD_VDD_35_36 ((uint32_t)1 << 23) /* VDD voltage 3.5-3.6 */ +#define MMCSD_R3_HIGHCAPACITY ((uint32_t)1 << 30) /* true: Card supports block addressing */ +#define MMCSD_CARD_BUSY ((uint32_t)1 << 31) /* Card power-up busy bit */ + +/* R6 Card Status bit definitions */ + +#define MMCSD_R6_RCA_SHIFT (16) /* New published RCA */ +#define MMCSD_R6_RCA_MASK ((uint32_t)0xffff << MMCSD_R6_RCA_SHIFT) +#define MMCSD_R6_COMCRCERROR ((uint32_t)1 << 15) /* CRC error */ +#define MMCSD_R6_ILLEGALCOMMAND ((uint32_t)1 << 14) /* Bad command */ +#define MMCSD_R6_ERROR ((uint32_t)1 << 13) /* General error */ +#define MMCSD_R6_STATE_SHIFT (9) /* Current card state */ +#define MMCSD_R6_STATE_MASK ((uint32_t)15 << MMCSD_R6_STATE_SHIFT) + /* Card identification mode states */ +# define MMCSD_R6_STATE_IDLE ((uint32_t)0 << MMCSD_R6_STATE_SHIFT) /* 0=Idle state */ +# define MMCSD_R6_STATE_READY ((uint32_t)1 << MMCSD_R6_STATE_SHIFT) /* 1=Ready state */ +# define MMCSD_R6_STATE_IDENT ((uint32_t)2 << MMCSD_R6_STATE_SHIFT) /* 2=Identification state */ + /* Data transfer states */ +# define MMCSD_R6_STATE_STBY ((uint32_t)3 << MMCSD_R6_STATE_SHIFT) /* 3=Standby state */ +# define MMCSD_R6_STATE_TRAN ((uint32_t)4 << MMCSD_R6_STATE_SHIFT) /* 4=Transfer state */ +# define MMCSD_R6_STATE_DATA (5(uint32_t) << MMCSD_R6_STATE_SHIFT) /* 5=Sending data state */ +# define MMCSD_R6_STATE_RCV ((uint32_t)6 << MMCSD_R6_STATE_SHIFT) /* 6=Receiving data state */ +# define MMCSD_R6_STATE_PRG ((uint32_t)7 << MMCSD_R6_STATE_SHIFT) /* 7=Programming state */ +# define MMCSD_R6_STATE_DIS ((uint32_t) << MMCSD_R6_STATE_SHIFT) /* 8=Disconnect state */ +#define MMCSD_R6_ERRORMASK ((uint32_t)0x0000e000) /* Error mask */ + +/* SD Configuration Register (SCR) encoding */ + +#define MMCSD_SCR_BUSWIDTH_1BIT (1) +#define MMCSD_SCR_BUSWIDTH_2BIT (2) +#define MMCSD_SCR_BUSWIDTH_4BIT (4) +#define MMCSD_SCR_BUSWIDTH_8BIT (8) + +/* Last 4 bytes of the 48-bit R7 response */ + +#define MMCSD_R7VERSION_SHIFT (28) /* Bits 28-31: Command version number */ +#define MMCSD_R7VERSION_MASK ((uint32_t)0x0f << MMCSD_R7VERSION_SHIFT) +#define MMCSD_R7VOLTAGE_SHIFT (8) /* Bits 8-11: Voltage accepted */ +#define MMCSD_R7VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_R7VOLTAGE_SHIFT) +# define MMCSD_R7VOLTAGE_27 ((uint32_t)0x01 << MMCSD_R7VOLTAGE_SHIFT) /* 2.7-3.6V */ +#define MMCSD_R7ECHO_SHIFT (0) /* Bits 0-7: Echoed check pattern */ +#define MMCSD_R7ECHO_MASK ((uint32_t)0xff << MMCSD_R7ECHO_SHIFT) +# define MMCSD_R7CHECKPATTERN ((uint32_t)0xaa << MMCSD_R7ECHO_SHIFT) + +/******************************************************************************************** + * Public Types + ********************************************************************************************/ + +/* Decoded Card Identification (CID) register */ + +struct mmcsd_cid_s +{ + uint8_t mid; /* 127:120 8-bit Manufacturer ID */ + uint16_t oid; /* 119:104 16-bit OEM/Application ID (ascii) */ + uint8_t pnm[6]; /* 103:64 40-bit Product Name (ascii) + null terminator */ + uint8_t prv; /* 63:56 8-bit Product revision */ + uint32_t psn; /* 55:24 32-bit Product serial number */ + /* 23:20 4-bit (reserved) */ + uint16_t mdt; /* 19:8 12-bit Manufacturing date */ + uint8_t crc; /* 7:1 7-bit CRC7 */ + /* 0:0 1-bit (not used) */ +}; + +/* Decoded Card Specific Data (CSD) register */ + +struct mmcsd_csd_s +{ + uint8_t csdstructure; /* 127:126 CSD structure */ + uint8_t mmcspecvers; /* 125:122 MMC Spec version (MMC only) */ + + struct + { + uint8_t timeunit; /* 2:0 Time exponent */ + uint8_t timevalue; /* 6:3 Time mantissa */ + } taac; /* 119:112 Data read access-time-1 */ + + uint8_t nsac; /* 111:104 Data read access-time-2 in CLK cycle(NSAC*100) */ + + struct + { + uint8_t transferrateunit; /* 2:0 Rate exponent */ + uint8_t timevalue; /* 6:3 Rate mantissa */ + } transpeed; /* 103:96 Max. data transfer rate */ + + uint16_t ccc; /* 95:84 Card command classes */ + uint8_t readbllen; /* 83:80 Max. read data block length */ + uint8_t readblpartial; /* 79:79 Partial blocks for read allowed */ + uint8_t writeblkmisalign; /* 78:78 Write block misalignment */ + uint8_t readblkmisalign; /* 77:77 Read block misalignment */ + uint8_t dsrimp; /* 76:76 DSR implemented */ + + union + { +#ifdef CONFIG_MMCSD_MMCSUPPORT + struct + { + uint16_t csize; /* 73:62 Device size */ + uint8_t vddrcurrmin; /* 61:59 Max. read current at Vdd min */ + uint8_t vddrcurrmax; /* 58:56 Max. read current at Vdd max */ + uint8_t vddwcurrmin; /* 55:53 Max. write current at Vdd min */ + uint8_t vddwcurrmax; /* 52:50 Max. write current at Vdd max */ + uint8_t csizemult; /* 49:47 Device size multiplier */ + + union + { + struct /* MMC system specification version 3.1 */ + { + uint8_t ergrpsize; /* 46:42 Erase group size (MMC 3.1) */ + uint8_t ergrpmult; /* 41:37 Erase group multiplier (MMC 3.1) */ + } mmc31; + struct /* MMC system specification version 2.2 */ + { + uint8_t sectorsize; /* 46:42 Erase sector size (MMC 2.2) */ + uint8_t ergrpsize; /* 41:37 Erase group size (MMC 2.2) */ + } mmc22; + } er; + + uint8_t mmcwpgrpsize; /* 36:32 Write protect group size (MMC) */ + } mmc; +#endif + struct + { + uint16_t csize; /* 73:62 Device size */ + uint8_t vddrcurrmin; /* 61:59 Max. read current at Vdd min */ + uint8_t vddrcurrmax; /* 58:56 Max. read current at Vdd max */ + uint8_t vddwcurrmin; /* 55:53 Max. write current at Vdd min */ + uint8_t vddwcurrmax; /* 52:50 Max. write current at Vdd max */ + uint8_t csizemult; /* 49:47 Device size multiplier */ + uint8_t sderblen; /* 46:46 Erase single block enable (SD) */ + uint8_t sdsectorsize; /* 45:39 Erase sector size (SD) */ + uint8_t sdwpgrpsize; /* 38:32 Write protect group size (SD) */ + } sdbyte; + + struct + { + /* 73:70 (reserved) */ + uint32_t csize; /* 69:48 Device size */ + /* 47:47 (reserved) */ + uint8_t sderblen; /* 46:46 Erase single block enable (SD) */ + uint8_t sdsectorsize; /* 45:39 Erase sector size (SD) */ + uint8_t sdwpgrpsize; /* 38:32 Write protect group size (SD) */ + } sdblock; + } u; + + uint8_t wpgrpen; /* 31:31 Write protect group enable */ + uint8_t mmcdfltecc; /* 30:29 Manufacturer default ECC (MMC) */ + uint8_t r2wfactor; /* 28:26 Write speed factor */ + uint8_t writebllen; /* 25:22 Max. write data block length */ + uint8_t writeblpartial; /* 21:21 Partial blocks for write allowed */ + uint8_t fileformatgrp; /* 15:15 File format group */ + uint8_t copy; /* 14:14 Copy flag (OTP) */ + uint8_t permwriteprotect; /* 13:13 Permanent write protection */ + uint8_t tmpwriteprotect; /* 12:12 Temporary write protection */ + uint8_t fileformat; /* 10:11 File format */ + uint8_t mmcecc; /* 9:8 ECC (MMC) */ + uint8_t crc; /* 7:1 CRC */ + /* 0:0 Not used */ +}; + +struct mmcsd_scr_s +{ + uint8_t scrversion; /* 63:60 Version of SCR structure */ + uint8_t sdversion; /* 59:56 SD memory card physical layer version */ + uint8_t erasestate; /* 55:55 Data state after erase (1 or 0) */ + uint8_t security; /* 54:52 SD security support */ + uint8_t buswidth; /* 51:48 DAT bus widthes supported */ + /* 47:32 SD reserved space */ + uint32_t mfgdata; /* 31:0 Reserved for manufacturing data */ +}; + +/******************************************************************************************** + * Public Data + ********************************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/******************************************************************************************** + * Public Functions + ********************************************************************************************/ + + +#undef EXTERN +#if defined(__cplusplus) +} +#endif +#endif /* __DRIVERS_MMCSD_MMCSD_SDIO_H */ diff --git a/nuttx/drivers/mmcsd/mmcsd_spi.h b/nuttx/drivers/mmcsd/mmcsd_spi.h index 055862bebd..8c6f9bae71 100644 --- a/nuttx/drivers/mmcsd/mmcsd_spi.h +++ b/nuttx/drivers/mmcsd/mmcsd_spi.h @@ -2,7 +2,7 @@ * drivers/mmcsd/mmcsd_spi.h * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mtd/Kconfig b/nuttx/drivers/mtd/Kconfig index bda5afa84d..ae656c474e 100644 --- a/nuttx/drivers/mtd/Kconfig +++ b/nuttx/drivers/mtd/Kconfig @@ -36,19 +36,19 @@ config AT45DB_PWRSAVE bool "enables power save" default n depends on MTD_AT45DB - + config MTD_MP25P - bool "SPI-based M25P1 falsh" + bool "SPI-based M25P FLASH" default n select SPI config MP25P_SPIMODE - int "mp25p spi mode" + int "MP25P SPI mode" default 0 depends on MTD_MP25P config MP25P_MANUFACTURER - hex "mp25p manufacturers ID" + hex "MP25P manufacturers ID" default 0x20 depends on MTD_MP25P ---help--- @@ -66,3 +66,68 @@ config MTD_RAMTRON config MTD_RAM bool "Memory bus ram" default n + +config MTD_SST25 + bool "SPI-based SST25 FLASH" + default n + select SPI + +config SST25_SPIMODE + int "SST25 SPI Mode" + default 0 + depends on MTD_SST25 + +config SST25_SPIFREQUENCY + int "SST25 SPI Frequency" + default 20000000 + depends on MTD_SST25 + +config SST25_READONLY + bool "SST25 Read-Only FLASH" + default n + depends on MTD_SST25 + +config SST25_SECTOR512 + bool "Simulate 512 byte Erase Blocks" + default n + depends on MTD_SST25 + +config SST25_SLOWWRITE + bool + default y + depends on MTD_SST25 + +config SST25_SLOWREAD + bool + default n + depends on MTD_SST25 + +config MTD_W25 + bool "SPI-based W25 FLASH" + default n + select SPI + +config W25_SPIMODE + int "W25 SPI Mode" + default 0 + depends on MTD_W25 + +config W25_SPIFREQUENCY + int "W25 SPI Frequency" + default 20000000 + depends on MTD_W25 + +config W25_READONLY + bool "W25 Read-Only FLASH" + default n + depends on MTD_W25 + +config W25_SECTOR512 + bool "Simulate 512 byte Erase Blocks" + default n + depends on MTD_W25 + +config W25_SLOWREAD + bool + default n + depends on MTD_W25 diff --git a/nuttx/drivers/mtd/Make.defs b/nuttx/drivers/mtd/Make.defs index 866d7c713e..258e77ec91 100644 --- a/nuttx/drivers/mtd/Make.defs +++ b/nuttx/drivers/mtd/Make.defs @@ -47,6 +47,10 @@ ifeq ($(CONFIG_MTD_SST25),y) CSRCS += sst25.c endif +ifeq ($(CONFIG_MTD_W25),y) +CSRCS += w25.c +endif + # Include MTD driver support DEPPATH += --dep-path mtd diff --git a/nuttx/drivers/mtd/at45db.c b/nuttx/drivers/mtd/at45db.c index f4a695de01..f3c0c72c14 100644 --- a/nuttx/drivers/mtd/at45db.c +++ b/nuttx/drivers/mtd/at45db.c @@ -3,7 +3,7 @@ * Driver for SPI-based AT45DB161D (16Mbit) * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mtd/flash_eraseall.c b/nuttx/drivers/mtd/flash_eraseall.c index 77666ff03d..ce0cfe6491 100644 --- a/nuttx/drivers/mtd/flash_eraseall.c +++ b/nuttx/drivers/mtd/flash_eraseall.c @@ -2,7 +2,7 @@ * drivers/mtd/flash_eraseall.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mtd/ftl.c b/nuttx/drivers/mtd/ftl.c index b16397883f..cdb35aa5cd 100644 --- a/nuttx/drivers/mtd/ftl.c +++ b/nuttx/drivers/mtd/ftl.c @@ -2,7 +2,7 @@ * drivers/mtd/ftl.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mtd/skeleton.c b/nuttx/drivers/mtd/skeleton.c index 673ddadb35..a2fb982387 100644 --- a/nuttx/drivers/mtd/skeleton.c +++ b/nuttx/drivers/mtd/skeleton.c @@ -2,7 +2,7 @@ * drivers/mtd/skeleton.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/mtd/sst25.c b/nuttx/drivers/mtd/sst25.c index 01838f078e..66d201add2 100644 --- a/nuttx/drivers/mtd/sst25.c +++ b/nuttx/drivers/mtd/sst25.c @@ -1,5 +1,5 @@ /************************************************************************************ - * drivers/mtd/m25px.c + * drivers/mtd/sst25.c * Driver for SPI-based SST25 FLASH. * * Copyright (C) 2012 Gregory Nutt. All rights reserved. diff --git a/nuttx/drivers/mtd/w25.c b/nuttx/drivers/mtd/w25.c new file mode 100644 index 0000000000..0d7028fec1 --- /dev/null +++ b/nuttx/drivers/mtd/w25.c @@ -0,0 +1,1188 @@ +/************************************************************************************ + * drivers/mtd/w25.c + * Driver for SPI-based W25x16, x32, and x64 and W25q16, q32, q64, and q128 FLASH + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* Configuration ********************************************************************/ +/* Per the data sheet, the W25 parts can be driven with either SPI mode 0 (CPOL=0 + * and CPHA=0) or mode 3 (CPOL=1 and CPHA=1). But I have heard that other devices + * can operate in mode 0 or 1. So you may need to specify CONFIG_W25_SPIMODE to + * select the best mode for your device. If CONFIG_W25_SPIMODE is not defined, + * mode 0 will be used. + */ + +#ifndef CONFIG_W25_SPIMODE +# define CONFIG_W25_SPIMODE SPIDEV_MODE0 +#endif + +/* SPI Frequency. May be up to 25MHz. */ + +#ifndef CONFIG_W25_SPIFREQUENCY +# define CONFIG_W25_SPIFREQUENCY 20000000 +#endif + +/* W25 Instructions *****************************************************************/ +/* Command Value Description */ +/* */ +#define W25_WREN 0x06 /* Write enable */ +#define W25_WRDI 0x04 /* Write Disable */ +#define W25_RDSR 0x05 /* Read status register */ +#define W25_WRSR 0x01 /* Write Status Register */ +#define W25_RDDATA 0x03 /* Read data bytes */ +#define W25_FRD 0x0b /* Higher speed read */ +#define W25_FRDD 0x3b /* Fast read, dual output */ +#define W25_PP 0x02 /* Program page */ +#define W25_BE 0xd8 /* Block Erase (64KB) */ +#define W25_SE 0x20 /* Sector erase (4KB) */ +#define W25_CE 0xc7 /* Chip erase */ +#define W25_PD 0xb9 /* Power down */ +#define W25_PURDID 0xab /* Release PD, Device ID */ +#define W25_RDMFID 0x90 /* Read Manufacturer / Device */ +#define W25_JEDEC_ID 0x9f /* JEDEC ID read */ + +/* W25 Registers ********************************************************************/ +/* Read ID (RDID) register values */ + +#define W25_MANUFACTURER 0xef /* Winbond Serial Flash */ +#define W25X16_DEVID 0x14 /* W25X16 device ID (0xab, 0x90) */ +#define W25X32_DEVID 0x15 /* W25X16 device ID (0xab, 0x90) */ +#define W25X64_DEVID 0x16 /* W25X16 device ID (0xab, 0x90) */ + +/* JEDEC Read ID register values */ + +#define W25_JEDEC_MANUFACTURER 0xef /* SST manufacturer ID */ +#define W25X_JEDEC_MEMORY_TYPE 0x30 /* W25X memory type */ +#define W25Q_JEDEC_MEMORY_TYPE_A 0x40 /* W25Q memory type */ +#define W25Q_JEDEC_MEMORY_TYPE_B 0x60 /* W25Q memory type */ + +#define W25_JEDEC_CAPACITY_16MBIT 0x15 /* 512x4096 = 16Mbit memory capacity */ +#define W25_JEDEC_CAPACITY_32MBIT 0x16 /* 1024x4096 = 32Mbit memory capacity */ +#define W25_JEDEC_CAPACITY_64MBIT 0x17 /* 2048x4096 = 64Mbit memory capacity */ +#define W25_JEDEC_CAPACITY_128MBIT 0x18 /* 4096x4096 = 128Mbit memory capacity */ + +#define NSECTORS_16MBIT 512 /* 512 sectors x 4096 bytes/sector = 2Mb */ +#define NSECTORS_32MBIT 1024 /* 1024 sectors x 4096 bytes/sector = 4Mb */ +#define NSECTORS_64MBIT 2048 /* 2048 sectors x 4096 bytes/sector = 8Mb */ +#define NSECTORS_128MBIT 4096 /* 4096 sectors x 4096 bytes/sector = 16Mb */ + +/* Status register bit definitions */ + +#define W25_SR_BUSY (1 << 0) /* Bit 0: Write in progress */ +#define W25_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */ +#define W25_SR_BP_SHIFT (2) /* Bits 2-5: Block protect bits */ +#define W25_SR_BP_MASK (15 << W25_SR_BP_SHIFT) +# define W25X16_SR_BP_NONE (0 << W25_SR_BP_SHIFT) /* Unprotected */ +# define W25X16_SR_BP_UPPER32nd (1 << W25_SR_BP_SHIFT) /* Upper 32nd */ +# define W25X16_SR_BP_UPPER16th (2 << W25_SR_BP_SHIFT) /* Upper 16th */ +# define W25X16_SR_BP_UPPER8th (3 << W25_SR_BP_SHIFT) /* Upper 8th */ +# define W25X16_SR_BP_UPPERQTR (4 << W25_SR_BP_SHIFT) /* Upper quarter */ +# define W25X16_SR_BP_UPPERHALF (5 << W25_SR_BP_SHIFT) /* Upper half */ +# define W25X16_SR_BP_ALL (6 << W25_SR_BP_SHIFT) /* All sectors */ +# define W25X16_SR_BP_LOWER32nd (9 << W25_SR_BP_SHIFT) /* Lower 32nd */ +# define W25X16_SR_BP_LOWER16th (10 << W25_SR_BP_SHIFT) /* Lower 16th */ +# define W25X16_SR_BP_LOWER8th (11 << W25_SR_BP_SHIFT) /* Lower 8th */ +# define W25X16_SR_BP_LOWERQTR (12 << W25_SR_BP_SHIFT) /* Lower quarter */ +# define W25X16_SR_BP_LOWERHALF (13 << W25_SR_BP_SHIFT) /* Lower half */ + +# define W25X32_SR_BP_NONE (0 << W25_SR_BP_SHIFT) /* Unprotected */ +# define W25X32_SR_BP_UPPER64th (1 << W25_SR_BP_SHIFT) /* Upper 64th */ +# define W25X32_SR_BP_UPPER32nd (2 << W25_SR_BP_SHIFT) /* Upper 32nd */ +# define W25X32_SR_BP_UPPER16th (3 << W25_SR_BP_SHIFT) /* Upper 16th */ +# define W25X32_SR_BP_UPPER8th (4 << W25_SR_BP_SHIFT) /* Upper 8th */ +# define W25X32_SR_BP_UPPERQTR (5 << W25_SR_BP_SHIFT) /* Upper quarter */ +# define W25X32_SR_BP_UPPERHALF (6 << W25_SR_BP_SHIFT) /* Upper half */ +# define W25X32_SR_BP_ALL (7 << W25_SR_BP_SHIFT) /* All sectors */ +# define W25X32_SR_BP_LOWER64th (9 << W25_SR_BP_SHIFT) /* Lower 64th */ +# define W25X32_SR_BP_LOWER32nd (10 << W25_SR_BP_SHIFT) /* Lower 32nd */ +# define W25X32_SR_BP_LOWER16th (11 << W25_SR_BP_SHIFT) /* Lower 16th */ +# define W25X32_SR_BP_LOWER8th (12 << W25_SR_BP_SHIFT) /* Lower 8th */ +# define W25X32_SR_BP_LOWERQTR (13 << W25_SR_BP_SHIFT) /* Lower quarter */ +# define W25X32_SR_BP_LOWERHALF (14 << W25_SR_BP_SHIFT) /* Lower half */ + +# define W25X64_SR_BP_NONE (0 << W25_SR_BP_SHIFT) /* Unprotected */ +# define W25X64_SR_BP_UPPER64th (1 << W25_SR_BP_SHIFT) /* Upper 64th */ +# define W25X64_SR_BP_UPPER32nd (2 << W25_SR_BP_SHIFT) /* Upper 32nd */ +# define W25X64_SR_BP_UPPER16th (3 << W25_SR_BP_SHIFT) /* Upper 16th */ +# define W25X64_SR_BP_UPPER8th (4 << W25_SR_BP_SHIFT) /* Upper 8th */ +# define W25X64_SR_BP_UPPERQTR (5 << W25_SR_BP_SHIFT) /* Upper quarter */ +# define W25X64_SR_BP_UPPERHALF (6 << W25_SR_BP_SHIFT) /* Upper half */ +# define W25X46_SR_BP_ALL (7 << W25_SR_BP_SHIFT) /* All sectors */ +# define W25X64_SR_BP_LOWER64th (9 << W25_SR_BP_SHIFT) /* Lower 64th */ +# define W25X64_SR_BP_LOWER32nd (10 << W25_SR_BP_SHIFT) /* Lower 32nd */ +# define W25X64_SR_BP_LOWER16th (11 << W25_SR_BP_SHIFT) /* Lower 16th */ +# define W25X64_SR_BP_LOWER8th (12 << W25_SR_BP_SHIFT) /* Lower 8th */ +# define W25X64_SR_BP_LOWERQTR (13 << W25_SR_BP_SHIFT) /* Lower quarter */ +# define W25X64_SR_BP_LOWERHALF (14 << W25_SR_BP_SHIFT) /* Lower half */ + /* Bit 6: Reserved */ +#define W25_SR_SRP (1 << 7) /* Bit 7: Status register write protect */ + +#define W25_DUMMY 0xa5 + +/* Chip Geometries ******************************************************************/ +/* All members of the family support uniform 4K-byte sectors and 256 byte pages */ + +#define W25_SECTOR_SHIFT 12 /* Sector size 1 << 12 = 4Kb */ +#define W25_SECTOR_SIZE (1 << 12) /* Sector size 1 << 12 = 4Kb */ +#define W25_PAGE_SHIFT 8 /* Sector size 1 << 8 = 256b */ +#define W25_PAGE_SIZE (1 << 8) /* Sector size 1 << 8 = 256b */ + +#ifdef CONFIG_W25_SECTOR512 /* Simulate a 512 byte sector */ +# define W25_SECTOR512_SHIFT 9 /* Sector size 1 << 9 = 512 bytes */ +# define W25_SECTOR512_SIZE (1 << 9) /* Sector size 1 << 9 = 512 bytes */ +#endif + +#define W25_ERASED_STATE 0xff /* State of FLASH when erased */ + +/* Cache flags */ + +#define W25_CACHE_VALID (1 << 0) /* 1=Cache has valid data */ +#define W25_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */ +#define W25_CACHE_ERASED (1 << 2) /* 1=Backing FLASH is erased */ + +#define IS_VALID(p) ((((p)->flags) & W25_CACHE_VALID) != 0) +#define IS_DIRTY(p) ((((p)->flags) & W25_CACHE_DIRTY) != 0) +#define IS_ERASED(p) ((((p)->flags) & W25_CACHE_DIRTY) != 0) + +#define SET_VALID(p) do { (p)->flags |= W25_CACHE_VALID; } while (0) +#define SET_DIRTY(p) do { (p)->flags |= W25_CACHE_DIRTY; } while (0) +#define SET_ERASED(p) do { (p)->flags |= W25_CACHE_DIRTY; } while (0) + +#define CLR_VALID(p) do { (p)->flags &= ~W25_CACHE_VALID; } while (0) +#define CLR_DIRTY(p) do { (p)->flags &= ~W25_CACHE_DIRTY; } while (0) +#define CLR_ERASED(p) do { (p)->flags &= ~W25_CACHE_DIRTY; } while (0) + +/************************************************************************************ + * Private Types + ************************************************************************************/ + +/* This type represents the state of the MTD device. The struct mtd_dev_s must + * appear at the beginning of the definition so that you can freely cast between + * pointers to struct mtd_dev_s and struct w25_dev_s. + */ + +struct w25_dev_s +{ + struct mtd_dev_s mtd; /* MTD interface */ + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ + uint16_t nsectors; /* Number of erase sectors */ + +#if defined(CONFIG_W25_SECTOR512) && !defined(CONFIG_W25_READONLY) + uint8_t flags; /* Buffered sector flags */ + uint16_t esectno; /* Erase sector number in the cache*/ + FAR uint8_t *sector; /* Allocated sector data */ +#endif +}; + +/************************************************************************************ + * Private Function Prototypes + ************************************************************************************/ + +/* Helpers */ + +static void w25_lock(FAR struct spi_dev_s *spi); +static inline void w25_unlock(FAR struct spi_dev_s *spi); +static inline int w25_readid(FAR struct w25_dev_s *priv); +#ifndef CONFIG_W25_READONLY +static void w25_unprotect(FAR struct w25_dev_s *priv); +#endif +static uint8_t w25_waitwritecomplete(FAR struct w25_dev_s *priv); +static inline void w25_wren(FAR struct w25_dev_s *priv); +static inline void w25_wrdi(FAR struct w25_dev_s *priv); +static void w25_sectorerase(FAR struct w25_dev_s *priv, off_t offset); +static inline int w25_chiperase(FAR struct w25_dev_s *priv); +static void w25_byteread(FAR struct w25_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t nbytes); +#ifndef CONFIG_W25_READONLY +static void w25_pagewrite(FAR struct w25_dev_s *priv, FAR const uint8_t *buffer, + off_t address, size_t nbytes); +#endif +#ifdef CONFIG_W25_SECTOR512 +static void w25_cacheflush(struct w25_dev_s *priv); +static FAR uint8_t *w25_cacheread(struct w25_dev_s *priv, off_t sector); +static void w25_cacheerase(struct w25_dev_s *priv, off_t sector); +static void w25_cachewrite(FAR struct w25_dev_s *priv, FAR const uint8_t *buffer, + off_t sector, size_t nsectors); +#endif + +/* MTD driver methods */ + +static int w25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); +static ssize_t w25_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buf); +static ssize_t w25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buf); +static ssize_t w25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR uint8_t *buffer); +static int w25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: w25_lock + ************************************************************************************/ + +static void w25_lock(FAR struct spi_dev_s *spi) +{ + /* On SPI busses where there are multiple devices, it will be necessary to + * lock SPI to have exclusive access to the busses for a sequence of + * transfers. The bus should be locked before the chip is selected. + * + * This is a blocking call and will not return until we have exclusiv access to + * the SPI buss. We will retain that exclusive access until the bus is unlocked. + */ + + (void)SPI_LOCK(spi, true); + + /* After locking the SPI bus, the we also need call the setfrequency, setbits, and + * setmode methods to make sure that the SPI is properly configured for the device. + * If the SPI buss is being shared, then it may have been left in an incompatible + * state. + */ + + SPI_SETMODE(spi, CONFIG_W25_SPIMODE); + SPI_SETBITS(spi, 8); + (void)SPI_SETFREQUENCY(spi, CONFIG_W25_SPIFREQUENCY); +} + +/************************************************************************************ + * Name: w25_unlock + ************************************************************************************/ + +static inline void w25_unlock(FAR struct spi_dev_s *spi) +{ + (void)SPI_LOCK(spi, false); +} + +/************************************************************************************ + * Name: w25_readid + ************************************************************************************/ + +static inline int w25_readid(struct w25_dev_s *priv) +{ + uint16_t manufacturer; + uint16_t memory; + uint16_t capacity; + + fvdbg("priv: %p\n", priv); + + /* Lock the SPI bus, configure the bus, and select this FLASH part. */ + + w25_lock(priv->spi); + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send the "Read ID (RDID)" command and read the first three ID bytes */ + + (void)SPI_SEND(priv->spi, W25_JEDEC_ID); + manufacturer = SPI_SEND(priv->spi, W25_DUMMY); + memory = SPI_SEND(priv->spi, W25_DUMMY); + capacity = SPI_SEND(priv->spi, W25_DUMMY); + + /* Deselect the FLASH and unlock the bus */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + w25_unlock(priv->spi); + + fvdbg("manufacturer: %02x memory: %02x capacity: %02x\n", + manufacturer, memory, capacity); + + /* Check for a valid manufacturer and memory type */ + + if (manufacturer == W25_JEDEC_MANUFACTURER && + (memory == W25X_JEDEC_MEMORY_TYPE || + memory == W25Q_JEDEC_MEMORY_TYPE_A || + memory == W25Q_JEDEC_MEMORY_TYPE_B)) + { + /* Okay.. is it a FLASH capacity that we understand? If so, save + * the FLASH capacity. + */ + + /* 16M-bit / 2M-byte (2,097,152) + * + * W24X16, W25Q16BV, W25Q16CL, W25Q16CV, W25Q16DW + */ + + if (capacity == W25_JEDEC_CAPACITY_16MBIT) + { + priv->nsectors = NSECTORS_16MBIT; + } + + /* 32M-bit / M-byte (4,194,304) + * + * W25X32, W25Q32BV, W25Q32DW + */ + + else if (capacity == W25_JEDEC_CAPACITY_32MBIT) + { + priv->nsectors = NSECTORS_32MBIT; + } + + /* 64M-bit / 8M-byte (8,388,608) + * + * W25X64, W25Q64BV, W25Q64CV, W25Q64DW + */ + + else if (capacity == W25_JEDEC_CAPACITY_64MBIT) + { + priv->nsectors = NSECTORS_64MBIT; + } + + /* 128M-bit / 16M-byte (16,777,216) + * + * W25Q128BV + */ + + else if (capacity == W25_JEDEC_CAPACITY_128MBIT) + { + priv->nsectors = NSECTORS_128MBIT; + } + else + { + /* Nope.. we don't understand this capacity. */ + + return -ENODEV; + } + + return OK; + } + + /* We don't understand the manufacturer or the memory type */ + + return -ENODEV; +} + +/************************************************************************************ + * Name: w25_unprotect + ************************************************************************************/ + +#ifndef CONFIG_W25_READONLY +static void w25_unprotect(FAR struct w25_dev_s *priv) +{ + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Write enable (WREN)" */ + + w25_wren(priv); + + /* Re-select this FLASH part (This might not be necessary... but is it shown in + * the SST25 timing diagrams from which this code was leveraged.) + */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Write enable status (EWSR)" */ + + SPI_SEND(priv->spi, W25_WRSR); + + /* Following by the new status value */ + + SPI_SEND(priv->spi, 0); + SPI_SEND(priv->spi, 0); +} +#endif + +/************************************************************************************ + * Name: w25_waitwritecomplete + ************************************************************************************/ + +static uint8_t w25_waitwritecomplete(struct w25_dev_s *priv) +{ + uint8_t status; + + /* Are we the only device on the bus? */ + +#ifdef CONFIG_SPI_OWNBUS + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Read Status Register (RDSR)" command */ + + (void)SPI_SEND(priv->spi, W25_RDSR); + + /* Loop as long as the memory is busy with a write cycle */ + + do + { + /* Send a dummy byte to generate the clock needed to shift out the status */ + + status = SPI_SEND(priv->spi, W25_DUMMY); + } + while ((status & W25_SR_BUSY) != 0); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + +#else + + /* Loop as long as the memory is busy with a write cycle */ + + do + { + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Read Status Register (RDSR)" command */ + + (void)SPI_SEND(priv->spi, W25_RDSR); + + /* Send a dummy byte to generate the clock needed to shift out the status */ + + status = SPI_SEND(priv->spi, W25_DUMMY); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + + /* Given that writing could take up to few tens of milliseconds, and erasing + * could take more. The following short delay in the "busy" case will allow + * other peripherals to access the SPI bus. + */ + +#if 0 /* Makes writes too slow */ + if ((status & W25_SR_BUSY) != 0) + { + w25_unlock(priv->spi); + usleep(1000); + w25_lock(priv->spi); + } +#endif + } + while ((status & W25_SR_BUSY) != 0); +#endif + + return status; +} + +/************************************************************************************ + * Name: w25_wren + ************************************************************************************/ + +static inline void w25_wren(struct w25_dev_s *priv) +{ + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Write Enable (WREN)" command */ + + (void)SPI_SEND(priv->spi, W25_WREN); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); +} + +/************************************************************************************ + * Name: w25_wrdi + ************************************************************************************/ + +static inline void w25_wrdi(struct w25_dev_s *priv) +{ + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Write Disable (WRDI)" command */ + + (void)SPI_SEND(priv->spi, W25_WRDI); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); +} + +/************************************************************************************ + * Name: w25_sectorerase + ************************************************************************************/ + +static void w25_sectorerase(struct w25_dev_s *priv, off_t sector) +{ + off_t address = sector << W25_SECTOR_SHIFT; + + fvdbg("sector: %08lx\n", (long)sector); + + /* Wait for any preceding write or erase operation to complete. */ + + (void)w25_waitwritecomplete(priv); + + /* Send write enable instruction */ + + w25_wren(priv); + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send the "Sector Erase (SE)" instruction */ + + (void)SPI_SEND(priv->spi, W25_SE); + + /* Send the sector address high byte first. Only the most significant bits (those + * corresponding to the sector) have any meaning. + */ + + (void)SPI_SEND(priv->spi, (address >> 16) & 0xff); + (void)SPI_SEND(priv->spi, (address >> 8) & 0xff); + (void)SPI_SEND(priv->spi, address & 0xff); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); +} + +/************************************************************************************ + * Name: w25_chiperase + ************************************************************************************/ + +static inline int w25_chiperase(struct w25_dev_s *priv) +{ + fvdbg("priv: %p\n", priv); + + /* Wait for any preceding write or erase operation to complete. */ + + (void)w25_waitwritecomplete(priv); + + /* Send write enable instruction */ + + w25_wren(priv); + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send the "Chip Erase (CE)" instruction */ + + (void)SPI_SEND(priv->spi, W25_CE); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + fvdbg("Return: OK\n"); + return OK; +} + +/************************************************************************************ + * Name: w25_byteread + ************************************************************************************/ + +static void w25_byteread(FAR struct w25_dev_s *priv, FAR uint8_t *buffer, + off_t address, size_t nbytes) +{ + uint8_t status; + + fvdbg("address: %08lx nbytes: %d\n", (long)address, (int)nbytes); + + /* Wait for any preceding write or erase operation to complete. */ + + status = w25_waitwritecomplete(priv); + DEBUGASSERT((status & (W25_SR_WEL|W25_SR_BP_MASK)) == 0); + + /* Make sure that writing is disabled */ + + w25_wrdi(priv); + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send "Read from Memory " instruction */ + +#ifdef CONFIG_W25_SLOWREAD + (void)SPI_SEND(priv->spi, W25_RDDATA); +#else + (void)SPI_SEND(priv->spi, W25_FRD); +#endif + + /* Send the address high byte first. */ + + (void)SPI_SEND(priv->spi, (address >> 16) & 0xff); + (void)SPI_SEND(priv->spi, (address >> 8) & 0xff); + (void)SPI_SEND(priv->spi, address & 0xff); + + /* Send a dummy byte */ + +#ifndef CONFIG_W25_SLOWREAD + (void)SPI_SEND(priv->spi, W25_DUMMY); +#endif + + /* Then read all of the requested bytes */ + + SPI_RECVBLOCK(priv->spi, buffer, nbytes); + + /* Deselect the FLASH */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); +} + +/************************************************************************************ + * Name: w25_pagewrite + ************************************************************************************/ + +#ifndef CONFIG_W25_READONLY +static void w25_pagewrite(struct w25_dev_s *priv, FAR const uint8_t *buffer, + off_t address, size_t nbytes) +{ + uint8_t status; + + fvdbg("address: %08lx nwords: %d\n", (long)address, (int)nbytes); + DEBUGASSERT(priv && buffer && ((uintptr_t)buffer & 0xff) == 0 && + (nbytes & 0xff) == 0); + + for (; nbytes > 0; nbytes -= W25_PAGE_SIZE) + { + /* Wait for any preceding write or erase operation to complete. */ + + status = w25_waitwritecomplete(priv); + DEBUGASSERT((status & (W25_SR_WEL|W25_SR_BP_MASK)) == 0); + + /* Enable write access to the FLASH */ + + w25_wren(priv); + + /* Select this FLASH part */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, true); + + /* Send the "Page Program (W25_PP)" Command */ + + SPI_SEND(priv->spi, W25_PP); + + /* Send the address high byte first. */ + + (void)SPI_SEND(priv->spi, (address >> 16) & 0xff); + (void)SPI_SEND(priv->spi, (address >> 8) & 0xff); + (void)SPI_SEND(priv->spi, address & 0xff); + + /* Then send the page of data */ + + SPI_SNDBLOCK(priv->spi, buffer, W25_PAGE_SIZE); + + /* Deselect the FLASH and setup for the next pass through the loop */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH, false); + + /* Update addresses */ + + address += W25_PAGE_SIZE; + buffer += W25_PAGE_SIZE; + } + + /* Disable writing */ + + w25_wrdi(priv); +} +#endif + +/************************************************************************************ + * Name: w25_cacheflush + ************************************************************************************/ + +#if defined(CONFIG_W25_SECTOR512) && !defined(CONFIG_W25_READONLY) +static void w25_cacheflush(struct w25_dev_s *priv) +{ + /* If the cached is dirty (meaning that it no longer matches the old FLASH contents) + * or was erased (with the cache containing the correct FLASH contents), then write + * the cached erase block to FLASH. + */ + + if (IS_DIRTY(priv) || IS_ERASED(priv)) + { + /* Write entire erase block to FLASH */ + + w25_pagewrite(priv, priv->sector, (off_t)priv->esectno << W25_SECTOR_SHIFT, + W25_SECTOR_SIZE); + + /* The case is no long dirty and the FLASH is no longer erased */ + + CLR_DIRTY(priv); + CLR_ERASED(priv); + } +} +#endif + +/************************************************************************************ + * Name: w25_cacheread + ************************************************************************************/ + +#if defined(CONFIG_W25_SECTOR512) && !defined(CONFIG_W25_READONLY) +static FAR uint8_t *w25_cacheread(struct w25_dev_s *priv, off_t sector) +{ + off_t esectno; + int shift; + int index; + + /* Convert from the 512 byte sector to the erase sector size of the device. For + * exmample, if the actual erase sector size if 4Kb (1 << 12), then we first + * shift to the right by 3 to get the sector number in 4096 increments. + */ + + shift = W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT; + esectno = sector >> shift; + fvdbg("sector: %ld esectno: %d shift=%d\n", sector, esectno, shift); + + /* Check if the requested erase block is already in the cache */ + + if (!IS_VALID(priv) || esectno != priv->esectno) + { + /* No.. Flush any dirty erase block currently in the cache */ + + w25_cacheflush(priv); + + /* Read the erase block into the cache */ + + w25_byteread(priv, priv->sector, (esectno << W25_SECTOR_SHIFT), W25_SECTOR_SIZE); + + /* Mark the sector as cached */ + + priv->esectno = esectno; + + SET_VALID(priv); /* The data in the cache is valid */ + CLR_DIRTY(priv); /* It should match the FLASH contents */ + CLR_ERASED(priv); /* The underlying FLASH has not been erased */ + } + + /* Get the index to the 512 sector in the erase block that holds the argument */ + + index = sector & ((1 << shift) - 1); + + /* Return the address in the cache that holds this sector */ + + return &priv->sector[index << W25_SECTOR512_SHIFT]; +} +#endif + +/************************************************************************************ + * Name: w25_cacheerase + ************************************************************************************/ + +#if defined(CONFIG_W25_SECTOR512) && !defined(CONFIG_W25_READONLY) +static void w25_cacheerase(struct w25_dev_s *priv, off_t sector) +{ + FAR uint8_t *dest; + + /* First, make sure that the erase block containing the 512 byte sector is in + * the cache. + */ + + dest = w25_cacheread(priv, sector); + + /* Erase the block containing this sector if it is not already erased. + * The erased indicated will be cleared when the data from the erase sector + * is read into the cache and set here when we erase the block. + */ + + if (!IS_ERASED(priv)) + { + off_t esectno = sector >> (W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT); + fvdbg("sector: %ld esectno: %d\n", sector, esectno); + + w25_sectorerase(priv, esectno); + SET_ERASED(priv); + } + + /* Put the cached sector data into the erase state and mart the cache as dirty + * (but don't update the FLASH yet. The caller will do that at a more optimal + * time). + */ + + memset(dest, W25_ERASED_STATE, W25_SECTOR512_SIZE); + SET_DIRTY(priv); +} +#endif + +/************************************************************************************ + * Name: w25_cachewrite + ************************************************************************************/ + +#if defined(CONFIG_W25_SECTOR512) && !defined(CONFIG_W25_READONLY) +static void w25_cachewrite(FAR struct w25_dev_s *priv, FAR const uint8_t *buffer, + off_t sector, size_t nsectors) +{ + FAR uint8_t *dest; + + for (; nsectors > 0; nsectors--) + { + /* First, make sure that the erase block containing 512 byte sector is in + * memory. + */ + + dest = w25_cacheread(priv, sector); + + /* Erase the block containing this sector if it is not already erased. + * The erased indicated will be cleared when the data from the erase sector + * is read into the cache and set here when we erase the sector. + */ + + if (!IS_ERASED(priv)) + { + off_t esectno = sector >> (W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT); + fvdbg("sector: %ld esectno: %d\n", sector, esectno); + + w25_sectorerase(priv, esectno); + SET_ERASED(priv); + } + + /* Copy the new sector data into cached erase block */ + + memcpy(dest, buffer, W25_SECTOR512_SIZE); + SET_DIRTY(priv); + + /* Set up for the next 512 byte sector */ + + buffer += W25_SECTOR512_SIZE; + sector++; + } + + /* Flush the last erase block left in the cache */ + + w25_cacheflush(priv); +} +#endif + +/************************************************************************************ + * Name: w25_erase + ************************************************************************************/ + +static int w25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) +{ +#ifdef CONFIG_W25_READONLY + return -EACESS +#else + FAR struct w25_dev_s *priv = (FAR struct w25_dev_s *)dev; + size_t blocksleft = nblocks; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + /* Lock access to the SPI bus until we complete the erase */ + + w25_lock(priv->spi); + + while (blocksleft-- > 0) + { + /* Erase each sector */ + +#ifdef CONFIG_W25_SECTOR512 + w25_cacheerase(priv, startblock); +#else + w25_sectorerase(priv, startblock); +#endif + startblock++; + } + +#ifdef CONFIG_W25_SECTOR512 + /* Flush the last erase block left in the cache */ + + w25_cacheflush(priv); +#endif + + w25_unlock(priv->spi); + return (int)nblocks; +#endif +} + +/************************************************************************************ + * Name: w25_bread + ************************************************************************************/ + +static ssize_t w25_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR uint8_t *buffer) +{ +#ifdef CONFIG_W25_SECTOR512 + ssize_t nbytes; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + /* On this device, we can handle the block read just like the byte-oriented read */ + + nbytes = w25_read(dev, startblock << W25_SECTOR512_SHIFT, nblocks << W25_SECTOR512_SHIFT, buffer); + if (nbytes > 0) + { + return nbytes >> W25_SECTOR512_SHIFT; + } + + return (int)nbytes; +#else + FAR struct w25_dev_s *priv = (FAR struct w25_dev_s *)dev; + ssize_t nbytes; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + /* On this device, we can handle the block read just like the byte-oriented read */ + + nbytes = w25_read(dev, startblock << W25_SECTOR_SHIFT, nblocks << W25_SECTOR_SHIFT, buffer); + if (nbytes > 0) + { + return nbytes >> W25_SECTOR_SHIFT; + } + + return (int)nbytes; +#endif +} + +/************************************************************************************ + * Name: w25_bwrite + ************************************************************************************/ + +static ssize_t w25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, + FAR const uint8_t *buffer) +{ +#ifdef CONFIG_W25_READONLY + return -EACCESS; +#else + FAR struct w25_dev_s *priv = (FAR struct w25_dev_s *)dev; + + fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks); + + /* Lock the SPI bus and write all of the pages to FLASH */ + + w25_lock(priv->spi); + +#if defined(CONFIG_W25_SECTOR512) + w25_cachewrite(priv, buffer, startblock, nblocks); +#else + w25_pagewrite(priv, buffer, startblock << W25_SECTOR_SHIFT, + nblocks << W25_SECTOR_SHIFT); +#endif + w25_unlock(priv->spi); + + return nblocks; +#endif +} + +/************************************************************************************ + * Name: w25_read + ************************************************************************************/ + +static ssize_t w25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, + FAR uint8_t *buffer) +{ + FAR struct w25_dev_s *priv = (FAR struct w25_dev_s *)dev; + + fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes); + + /* Lock the SPI bus and select this FLASH part */ + + w25_lock(priv->spi); + w25_byteread(priv, buffer, offset, nbytes); + w25_unlock(priv->spi); + + fvdbg("return nbytes: %d\n", (int)nbytes); + return nbytes; +} + +/************************************************************************************ + * Name: w25_ioctl + ************************************************************************************/ + +static int w25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +{ + FAR struct w25_dev_s *priv = (FAR struct w25_dev_s *)dev; + int ret = -EINVAL; /* Assume good command with bad parameters */ + + fvdbg("cmd: %d \n", cmd); + + switch (cmd) + { + case MTDIOC_GEOMETRY: + { + FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg); + if (geo) + { + /* Populate the geometry structure with information need to know + * the capacity and how to access the device. + * + * NOTE: that the device is treated as though it where just an array + * of fixed size blocks. That is most likely not true, but the client + * will expect the device logic to do whatever is necessary to make it + * appear so. + */ + +#ifdef CONFIG_W25_SECTOR512 + geo->blocksize = (1 << W25_SECTOR512_SHIFT); + geo->erasesize = (1 << W25_SECTOR512_SHIFT); + geo->neraseblocks = priv->nsectors << (W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT); +#else + geo->blocksize = W25_SECTOR_SIZE; + geo->erasesize = W25_SECTOR_SIZE; + geo->neraseblocks = priv->nsectors; +#endif + ret = OK; + + fvdbg("blocksize: %d erasesize: %d neraseblocks: %d\n", + geo->blocksize, geo->erasesize, geo->neraseblocks); + } + } + break; + + case MTDIOC_BULKERASE: + { + /* Erase the entire device */ + + w25_lock(priv->spi); + ret = w25_chiperase(priv); + w25_unlock(priv->spi); + } + break; + + case MTDIOC_XIPBASE: + default: + ret = -ENOTTY; /* Bad command */ + break; + } + + fvdbg("return %d\n", ret); + return ret; +} + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: w25_initialize + * + * Description: + * Create an initialize MTD device instance. MTD devices are not registered + * in the file system, but are created as instances that can be bound to + * other functions (such as a block or character driver front end). + * + ************************************************************************************/ + +FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *spi) +{ + FAR struct w25_dev_s *priv; + int ret; + + fvdbg("spi: %p\n", spi); + + /* Allocate a state structure (we allocate the structure instead of using + * a fixed, static allocation so that we can handle multiple FLASH devices. + * The current implementation would handle only one FLASH part per SPI + * device (only because of the SPIDEV_FLASH definition) and so would have + * to be extended to handle multiple FLASH parts on the same SPI bus. + */ + + priv = (FAR struct w25_dev_s *)kzalloc(sizeof(struct w25_dev_s)); + if (priv) + { + /* Initialize the allocated structure */ + + priv->mtd.erase = w25_erase; + priv->mtd.bread = w25_bread; + priv->mtd.bwrite = w25_bwrite; + priv->mtd.read = w25_read; + priv->mtd.ioctl = w25_ioctl; + priv->spi = spi; + + /* Deselect the FLASH */ + + SPI_SELECT(spi, SPIDEV_FLASH, false); + + /* Identify the FLASH chip and get its capacity */ + + ret = w25_readid(priv); + if (ret != OK) + { + /* Unrecognized! Discard all of that work we just did and return NULL */ + + fdbg("Unrecognized\n"); + kfree(priv); + priv = NULL; + } + else + { + /* Make sure the the FLASH is unprotected so that we can write into it */ + +#ifndef CONFIG_W25_READONLY + w25_unprotect(priv); +#endif + +#ifdef CONFIG_W25_SECTOR512 /* Simulate a 512 byte sector */ + /* Allocate a buffer for the erase block cache */ + + priv->sector = (FAR uint8_t *)kmalloc(W25_SECTOR_SIZE); + if (!priv->sector) + { + /* Allocation failed! Discard all of that work we just did and return NULL */ + + fdbg("Allocation failed\n"); + kfree(priv); + priv = NULL; + } +#endif + } + } + + /* Return the implementation-specific state structure as the MTD device */ + + fvdbg("Return %p\n", priv); + return (FAR struct mtd_dev_s *)priv; +} diff --git a/nuttx/drivers/net/Kconfig b/nuttx/drivers/net/Kconfig index 988b96c948..d8878ecafd 100644 --- a/nuttx/drivers/net/Kconfig +++ b/nuttx/drivers/net/Kconfig @@ -25,6 +25,7 @@ config ENC28J60 References: ENC28J60 Data Sheet, Stand-Alone Ethernet Controller with SPI Interface, DS39662C, 2008 Microchip Technology Inc. + if ENC28J60 config ENC28J60_NINTERFACES int "Number of physical ENC28J60" @@ -36,9 +37,13 @@ config ENC28J60_NINTERFACES config ENC28J60_SPIMODE int "SPI mode" - default 2 + default 0 ---help--- - Controls the SPI mode + Controls the SPI mode. The ENC28J60 spec says that it supports SPI + mode 0,0 only: "The implementation used on this device supports SPI + mode 0,0 only. In addition, the SPI port requires that SCK be at Idle + in a low state; selectable clock polarity is not supported." + However, sometimes you need to tinker with these things. config ENC28J60_FREQUENCY int "SPI frequency" @@ -57,8 +62,23 @@ config ENC28J60_HALFDUPPLEX default n ---help--- Default is full duplex + +config ENC28J60_DUMPPACKET + bool "Dump Packets" + default n + ---help--- + If selected, the ENC28J60 driver will dump the contents of each + packet to the console. + +config ENC28J60_REGDEBUG + bool "Register-Level Debug" + default n + depends on DEBUG && DEBUG_NET + ---help--- + Enable very low-level register access debug. Depends on DEBUG and DEBUG_NET. + endif - + config NET_E1000 bool "E1000 support" default n diff --git a/nuttx/drivers/net/Make.defs b/nuttx/drivers/net/Make.defs index ab256cd8ae..bb0d6a7189 100644 --- a/nuttx/drivers/net/Make.defs +++ b/nuttx/drivers/net/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # drivers/net/Make.defs # -# Copyright (C) 2007, 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Copyright (C) 2007, 2010-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -47,7 +47,7 @@ ifeq ($(CONFIG_NET_CS89x0),y) CSRCS += cs89x0.c endif -ifeq ($(CONFIG_NET_ENC28J60),y) +ifeq ($(CONFIG_ENC28J60),y) CSRCS += enc28j60.c endif diff --git a/nuttx/drivers/net/cs89x0.c b/nuttx/drivers/net/cs89x0.c index 0f301ee003..22b9b87a5f 100644 --- a/nuttx/drivers/net/cs89x0.c +++ b/nuttx/drivers/net/cs89x0.c @@ -2,7 +2,7 @@ * drivers/net/cs89x0.c * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/net/cs89x0.h b/nuttx/drivers/net/cs89x0.h index c2073eb988..f6d99120ab 100644 --- a/nuttx/drivers/net/cs89x0.h +++ b/nuttx/drivers/net/cs89x0.h @@ -1,326 +1,326 @@ -/**************************************************************************** - * drivers/net/cs89x0.h - * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __DRIVERS_NET_CS89x0_H -#define __DRIVERS_NET_CS89x0_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* CONFIG_CS89x0_ALIGN16/32 determines if the 16-bit CS89x0 registers are - * aligned to 16-bit or 32-bit address boundaries. NOTE: If there multiple - * CS89x00 parts in the board architecture, we assume that the address - * alignment is the same for all implementations. If that is not the - * case, then it will be necessary to move a shift value into - * the cs89x0_driver_s structure and calculate the offsets dynamically in - * the putreg and getreg functions. - */ - -#if defined(CONFIG_CS89x0_ALIGN16) -# define CS89x0_RTDATA_OFFSET (0 << 1) -# define CS89x0_TxCMD_OFFSET (2 << 1) -# define CS89x0_TxLEN_OFFSET (3 << 1) -# define CS89x0_ISQ_OFFSET (4 << 1) -# define CS89x0_PPTR_OFFSET (5 << 1) -# define CS89x0_PDATA_OFFSET (6 << 1) -#elif defined(CONFIG_CS89x0_ALIGN32) -# define CS89x0_RTDATA_OFFSET (0 << 2) -# define CS89x0_TxCMD_OFFSET (2 << 2) -# define CS89x0_TxLEN_OFFSET (3 << 2) -# define CS89x0_ISQ_OFFSET (4 << 2) -# define CS89x0_PPTR_OFFSET (5 << 2) -# define CS89x0_PDATA_OFFSET (6 << 2) -#else -# error "CS89x00 address alignment is not defined" -#endif - -/* ISQ register bit definitions */ - -#define ISQ_EVENTMASK 0x003f /* Bits 0-5 indicate the status register */ -#define ISQ_RXEVENT 0x0004 -#define ISQ_TXEVENT 0x0008 -#define ISQ_BUFEVENT 0x000c -#define ISQ_RXMISSEVENT 0x0010 -#define ISQ_TXCOLEVENT 0x0012 - -/* ISQ register TxEVENT bit definitions*/ - -#define ISQ_RXEVENT_IAHASH (1 << 6) -#define ISQ_RXEVENT_DRIBBLE (1 << 7) -#define ISQ_RXEVENT_RXOK (1 << 8) -#define ISQ_RXEVENT_HASHED (1 << 9) -#define ISQ_RXEVENT_HASHNDX_SHIFT 10 -#define ISQ_RXEVENT_HASHNDX_MASK (0x3f << ISQ_RXEVENT_HASHNDX_SHIFT) - -/* ISQ register TxEVENT bit definitions*/ - -#define ISQ_TXEVENT_LOSSOFCRS (1 << 6) -#define ISQ_TXEVENT_SQEERROR (1 << 7) -#define ISQ_TXEVENT_TXOK (1 << 8) -#define ISQ_TXEVENT_OUTWINDOW (1 << 9) -#define ISQ_TXEVENT_JABBER (1 << 10) -#define ISQ_TXEVENT_NCOLLISION_SHIFT 11 -#define ISQ_TXEVENT_NCOLLISION_MASK (15 << ISQ_TXEVENT_NCOLLISION_SHIFT) -#define ISQ_TXEVENT_16COLL (1 << 15) - -/* ISQ register BufEVENT bit definitions */ - -#define ISQ_BUFEVENT_SWINT (1 << 6) -#define ISQ_BUFEVENT_RXDMAFRAME (1 << 7) -#define ISQ_BUFEVENT_RDY4TX (1 << 8) -#define ISQ_BUFEVENT_TXUNDERRUN (1 << 9) -#define ISQ_BUFEVENT_RXMISS (1 << 10) -#define ISQ_BUFEVENT_RX128 (1 << 11) -#define ISQ_BUFEVENT_RXDEST (1 << 15) - -/* Packet page register offsets *********************************************/ - -/* 0x0000 Bus interface registers */ - -#define PPR_CHIPID 0x0000 /* Chip identifier - must be 0x630E */ -#define PPR_CHIPREV 0x0002 /* Chip revision, model codes */ -#define PPR_IOBASEADDRESS 0x0020 /* I/O Base Address */ -#define PPR_INTREG 0x0022 /* Interrupt configuration */ -# define PPR_INTREG_IRQ0 0x0000 /* Use INTR0 pin */ -# define PPR_INTREG_IRQ1 0x0001 /* Use INTR1 pin */ -# define PPR_INTREG_IRQ2 0x0002 /* Use INTR2 pin */ -# define PPR_INTREG_IRQ3 0x0003 /* Use INTR3 pin */ - -#define PPR_DMACHANNELNUMBER 0x0024 /* DMA Channel Number (0,1, or 2) */ -#define PPR_DMASTARTOFFRAME 0x0026 /* DMA Start of Frame */ -#define PPR_DMAFRAMECOUNT 0x0028 /* DMA Frame Count (12-bits) */ -#define PPR_RXDMABYTECOUNT 0x002a /* Rx DMA Byte Count */ -#define PPR_MEMORYBASEADDRESS 0x002c /* Memory Base Address Register (20-bit) */ -#define PPR_BOOTPROMBASEADDRESS 0x0030 /* Boot PROM Base Address */ -#define PPR_BOOTPROMADDRESSMASK 0x0034 /* Boot PROM Address Mask */ -#define PPR_EEPROMCOMMAND 0x0040 /* EEPROM Command */ -#define PPR_EEPROMDATA 0x0042 /* EEPROM Data */ -#define PPR_RECVFRAMEBYTES 0x0050 /* Received Frame Byte Counter */ - -/* 0x0100 - Configuration and control registers */ - -#define PPR_RXCFG 0x0102 /* Receiver configuration */ -# define PPR_RXCFG_SKIP1 (1 << 6) /* Skip (discard) current frame */ -# define PPR_RXCFG_STREAM (1 << 7) /* Enable streaming mode */ -# define PPR_RXCFG_RXOK (1 << 8) /* RxOK interrupt enable */ -# define PPR_RxCFG_RxDMAonly (1 << 9) /* Use RxDMA for all frames */ -# define PPR_RxCFG_AutoRxDMA (1 << 10) /* Select RxDMA automatically */ -# define PPR_RxCFG_BufferCRC (1 << 11) /* Include CRC characters in frame */ -# define PPR_RxCFG_CRC (1 << 12) /* Enable interrupt on CRC error */ -# define PPR_RxCFG_RUNT (1 << 13) /* Enable interrupt on RUNT frames */ -# define PPR_RxCFG_EXTRA (1 << 14) /* Enable interrupt on frames with extra data */ - -#define PPR_RXCTL 0x0104 /* Receiver control */ -# define PPR_RXCTL_IAHASH (1 << 6) /* Accept frames that match hash */ -# define PPR_RXCTL_PROMISCUOUS (1 << 7) /* Accept any frame */ -# define PPR_RXCTL_RXOK (1 << 8) /* Accept well formed frames */ -# define PPR_RXCTL_MULTICAST (1 << 9) /* Accept multicast frames */ -# define PPR_RXCTL_IA (1 << 10) /* Accept frame that matches IA */ -# define PPR_RXCTL_BROADCAST (1 << 11) /* Accept broadcast frames */ -# define PPR_RXCTL_CRC (1 << 12) /* Accept frames with bad CRC */ -# define PPR_RXCTL_RUNT (1 << 13) /* Accept runt frames */ -# define PPR_RXCTL_EXTRA (1 << 14) /* Accept frames that are too long */ - -#define PPR_TXCFG 0x0106 /* Transmit configuration */ -# define PPR_TXCFG_CRS (1 << 6) /* Enable interrupt on loss of carrier */ -# define PPR_TXCFG_SQE (1 << 7) /* Enable interrupt on Signal Quality Error */ -# define PPR_TXCFG_TXOK (1 << 8) /* Enable interrupt on successful xmits */ -# define PPR_TXCFG_LATE (1 << 9) /* Enable interrupt on "out of window" */ -# define PPR_TXCFG_JABBER (1 << 10) /* Enable interrupt on jabber detect */ -# define PPR_TXCFG_COLLISION (1 << 11) /* Enable interrupt if collision */ -# define PPR_TXCFG_16COLLISIONS (1 << 15) /* Enable interrupt if > 16 collisions */ - -#define PPR_TXCMD 0x0108 /* Transmit command status */ -# define PPR_TXCMD_TXSTART5 (0 << 6) /* Start after 5 bytes in buffer */ -# define PPR_TXCMD_TXSTART381 (1 << 6) /* Start after 381 bytes in buffer */ -# define PPR_TXCMD_TXSTART1021 (2 << 6) /* Start after 1021 bytes in buffer */ -# define PPR_TXCMD_TXSTARTFULL (3 << 6) /* Start after all bytes loaded */ -# define PPR_TXCMD_FORCE (1 << 8) /* Discard any pending packets */ -# define PPR_TXCMD_ONECOLLISION (1 << 9) /* Abort after a single collision */ -# define PPR_TXCMD_NOCRC (1 << 12) /* Do not add CRC */ -# define PPR_TXCMD_NOPAD (1 << 13) /* Do not pad short packets */ - -#define PPR_BUFCFG 0x010a /* Buffer configuration */ -# define PPR_BUFCFG_SWI (1 << 6) /* Force interrupt via software */ -# define PPR_BUFCFG_RXDMA (1 << 7) /* Enable interrupt on Rx DMA */ -# define PPR_BUFCFG_TXRDY (1 << 8) /* Enable interrupt when ready for Tx */ -# define PPR_BUFCFG_TXUE (1 << 9) /* Enable interrupt in Tx underrun */ -# define PPR_BUFCFG_RXMISS (1 << 10) /* Enable interrupt on missed Rx packets */ -# define PPR_BUFCFG_RX128 (1 << 11) /* Enable Rx interrupt after 128 bytes */ -# define PPR_BUFCFG_TXCOL (1 << 12) /* Enable int on Tx collision ctr overflow */ -# define PPR_BUFCFG_MISS (1 << 13) /* Enable int on Rx miss ctr overflow */ -# define PPR_BUFCFG_RXDEST (1 << 15) /* Enable int on Rx dest addr match */ - -#define PPR_LINECTL 0x0112 /* Line control */ -# define PPR_LINECTL_RX (1 << 6) /* Enable receiver */ -# define PPR_LINECTL_TX (1 << 7) /* Enable transmitter */ -# define PPR_LINECTL_AUIONLY (1 << 8) /* AUI interface only */ -# define PPR_LINECTL_AUTOAUI10BT (1 << 9) /* Autodetect AUI or 10BaseT interface */ -# define PPR_LINECTL_MODBACKOFFE (1 << 11) /* Enable modified backoff algorithm */ -# define PPR_LINECTL_POLARITYDIS (1 << 12) /* Disable Rx polarity autodetect */ -# define PPR_LINECTL_2PARTDEFDIS (1 << 13) /* Disable two-part defferal */ -# define PPR_LINECTL_LORXSQUELCH (1 << 14) /* Reduce receiver squelch threshold */ - -#define PPR_SELFCTL 0x0114 /* Chip self control */ -# define PPR_SELFCTL_RESET (1 << 6) /* Self-clearing reset */ -# define PPR_SELFCTL_SWSUSPEND (1 << 8) /* Initiate suspend mode */ -# define PPR_SELFCTL_HWSLEEPE (1 << 9) /* Enable SLEEP input */ -# define PPR_SELFCTL_HWSTANDBYE (1 << 10) /* Enable standby mode */ -# define PPR_SELFCTL_HC0E (1 << 12) /* Use HCB0 for LINK LED */ -# define PPR_SELFCTL_HC1E (1 << 13) /* Use HCB1 for BSTATUS LED */ -# define PPR_SELFCTL_HCB0 (1 << 14) /* Control LINK LED if HC0E set */ -# define PPR_SELFCTL_HCB1 (1 << 15) /* Cntrol BSTATUS LED if HC1E set */ - -#define PPR_BUSCTL 0x0116 /* Bus control */ -# define PPR_BUSCTL_RESETRXDMA (1 << 6) /* Reset RxDMA pointer */ -# define PPR_BUSCTL_DMAEXTEND (1 << 8) /* Extend DMA cycle */ -# define PPR_BUSCTL_USESA (1 << 9) /* Assert MEMCS16 on address decode */ -# define PPR_BUSCTL_MEMORYE (1 << 10) /* Enable memory mode */ -# define PPR_BUSCTL_DMABURST (1 << 11) /* Limit DMA access burst */ -# define PPR_BUSCTL_IOCHRDYE (1 << 12) /* Set IOCHRDY high impedence */ -# define PPR_BUSCTL_RXDMASIZE (1 << 13) /* Set DMA buffer size 64KB */ -# define PPR_BUSCTL_ENABLEIRQ (1 << 15) /* Generate interrupt on interrupt event */ - -#define PPR_TESTCTL 0x0118 /* Test control */ -# define PPR_TESTCTL_DISABLELT (1 << 7) /* Disable link status */ -# define PPR_TESTCTL_ENDECLOOP (1 << 9) /* Internal loopback */ -# define PPR_TESTCTL_AUILOOP (1 << 10) /* AUI loopback */ -# define PPR_TESTCTL_DISBACKOFF (1 << 11) /* Disable backoff algorithm */ -# define PPR_TESTCTL_FDX (1 << 14) /* Enable full duplex mode */ - -/* 0x0120 - Status and Event Registers */ - -#define PPR_ISQ 0x0120 /* Interrupt Status Queue */ -#define PPR_RER 0x0124 /* Receive event */ -# define PPR_RER_IAHASH (1 << 6) /* Frame hash match */ -# define PPR_RER_DRIBBLE (1 << 7) /* Frame had 1-7 extra bits after last byte */ -# define PPR_RER_RXOK (1 << 8) /* Frame received with no errors */ -# define PPR_RER_HASHED (1 << 9) /* Frame address hashed OK */ -# define PPR_RER_IA (1 << 10) /* Frame address matched IA */ -# define PPR_RER_BROADCAST (1 << 11) /* Broadcast frame */ -# define PPR_RER_CRC (1 << 12) /* Frame had CRC error */ -# define PPR_RER_RUNT (1 << 13) /* Runt frame */ -# define PPR_RER_EXTRA (1 << 14) /* Frame was too long */ - -#define PPR_TER 0x0128 /* Transmit event */ -# define PPR_TER_CRS (1 << 6) /* Carrier lost */ -# define PPR_TER_SQE (1 << 7) /* Signal Quality Error */ -# define PPR_TER_TXOK (1 << 8) /* Packet sent without error */ -# define PPR_TER_LATE (1 << 9) /* Out of window */ -# define PPR_TER_JABBER (1 << 10) /* Stuck transmit? */ -# define PPR_TER_NUMCOLLISIONS_SHIFT 11 -# define PPR_TER_NUMCOLLISIONS_MASK (15 << PPR_TER_NUMCOLLISIONS_SHIFT) -# define PPR_TER_16COLLISIONS (1 << 15) /* > 16 collisions */ - -#define PPR_BER 0x012C /* Buffer event */ -# define PPR_BER_SWINT (1 << 6) /* Software interrupt */ -# define PPR_BER_RXDMAFRAME (1 << 7) /* Received framed DMAed */ -# define PPR_BER_RDY4TX (1 << 8) /* Ready for transmission */ -# define PPR_BER_TXUNDERRUN (1 << 9) /* Transmit underrun */ -# define PPR_BER_RXMISS (1 << 10) /* Received frame missed */ -# define PPR_BER_RX128 (1 << 11) /* 128 bytes received */ -# define PPR_BER_RXDEST (1 << 15) /* Received framed passed address filter */ - -#define PPR_RXMISS 0x0130 /* Receiver miss counter */ -#define PPR_TXCOL 0x0132 /* Transmit collision counter */ -#define PPR_LINESTAT 0x0134 /* Line status */ -# define PPR_LINESTAT_LINKOK (1 << 7) /* Line is connected and working */ -# define PPR_LINESTAT_AUI (1 << 8) /* Connected via AUI */ -# define PPR_LINESTAT_10BT (1 << 9) /* Connected via twisted pair */ -# define PPR_LINESTAT_POLARITY (1 << 12) /* Line polarity OK (10BT only) */ -# define PPR_LINESTAT_CRS (1 << 14) /* Frame being received */ - -#define PPR_SELFSTAT 0x0136 /* Chip self status */ -# define PPR_SELFSTAT_33VACTIVE (1 << 6) /* supply voltage is 3.3V */ -# define PPR_SELFSTAT_INITD (1 << 7) /* Chip initialization complete */ -# define PPR_SELFSTAT_SIBSY (1 << 8) /* EEPROM is busy */ -# define PPR_SELFSTAT_EEPROM (1 << 9) /* EEPROM present */ -# define PPR_SELFSTAT_EEPROMOK (1 << 10) /* EEPROM checks out */ -# define PPR_SELFSTAT_ELPRESENT (1 << 11) /* External address latch logic available */ -# define PPR_SELFSTAT_EESIZE (1 << 12) /* Size of EEPROM */ - -#define PPR_BUSSTAT 0x0138 /* Bus status */ -# define PPR_BUSSTAT_TXBID (1 << 7) /* Tx error */ -# define PPR_BUSSTAT_TXRDY (1 << 8) /* Ready for Tx data */ - -#define PPR_TDR 0x013C /* AUI Time Domain Reflectometer */ - -/* 0x0144 - Initiate transmit registers */ - -#define PPR_TXCOMMAND 0x0144 /* Tx Command */ -#define PPR_TXLENGTH 0x0146 /* Tx Length */ - -/* 0x0150 - Address filter registers */ - -#define PPR_LAF 0x0150 /* Logical address filter (6 bytes) */ -#define PPR_IA 0x0158 /* Individual address (MAC) */ - -/* 0x0400 - Frame location registers */ - -#define PPR_RXSTATUS 0x0400 /* Rx Status */ -#define PPR_RXLENGTH 0x0402 /* Rx Length */ -#define PPR_RXFRAMELOCATION 0x0404 /* Rx Frame Location */ -#define PPR_TXFRAMELOCATION 0x0a00 /* Tx Frame Location */ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __DRIVERS_NET_CS89x0_H */ +/**************************************************************************** + * drivers/net/cs89x0.h + * + * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __DRIVERS_NET_CS89x0_H +#define __DRIVERS_NET_CS89x0_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* CONFIG_CS89x0_ALIGN16/32 determines if the 16-bit CS89x0 registers are + * aligned to 16-bit or 32-bit address boundaries. NOTE: If there multiple + * CS89x00 parts in the board architecture, we assume that the address + * alignment is the same for all implementations. If that is not the + * case, then it will be necessary to move a shift value into + * the cs89x0_driver_s structure and calculate the offsets dynamically in + * the putreg and getreg functions. + */ + +#if defined(CONFIG_CS89x0_ALIGN16) +# define CS89x0_RTDATA_OFFSET (0 << 1) +# define CS89x0_TxCMD_OFFSET (2 << 1) +# define CS89x0_TxLEN_OFFSET (3 << 1) +# define CS89x0_ISQ_OFFSET (4 << 1) +# define CS89x0_PPTR_OFFSET (5 << 1) +# define CS89x0_PDATA_OFFSET (6 << 1) +#elif defined(CONFIG_CS89x0_ALIGN32) +# define CS89x0_RTDATA_OFFSET (0 << 2) +# define CS89x0_TxCMD_OFFSET (2 << 2) +# define CS89x0_TxLEN_OFFSET (3 << 2) +# define CS89x0_ISQ_OFFSET (4 << 2) +# define CS89x0_PPTR_OFFSET (5 << 2) +# define CS89x0_PDATA_OFFSET (6 << 2) +#else +# error "CS89x00 address alignment is not defined" +#endif + +/* ISQ register bit definitions */ + +#define ISQ_EVENTMASK 0x003f /* Bits 0-5 indicate the status register */ +#define ISQ_RXEVENT 0x0004 +#define ISQ_TXEVENT 0x0008 +#define ISQ_BUFEVENT 0x000c +#define ISQ_RXMISSEVENT 0x0010 +#define ISQ_TXCOLEVENT 0x0012 + +/* ISQ register TxEVENT bit definitions*/ + +#define ISQ_RXEVENT_IAHASH (1 << 6) +#define ISQ_RXEVENT_DRIBBLE (1 << 7) +#define ISQ_RXEVENT_RXOK (1 << 8) +#define ISQ_RXEVENT_HASHED (1 << 9) +#define ISQ_RXEVENT_HASHNDX_SHIFT 10 +#define ISQ_RXEVENT_HASHNDX_MASK (0x3f << ISQ_RXEVENT_HASHNDX_SHIFT) + +/* ISQ register TxEVENT bit definitions*/ + +#define ISQ_TXEVENT_LOSSOFCRS (1 << 6) +#define ISQ_TXEVENT_SQEERROR (1 << 7) +#define ISQ_TXEVENT_TXOK (1 << 8) +#define ISQ_TXEVENT_OUTWINDOW (1 << 9) +#define ISQ_TXEVENT_JABBER (1 << 10) +#define ISQ_TXEVENT_NCOLLISION_SHIFT 11 +#define ISQ_TXEVENT_NCOLLISION_MASK (15 << ISQ_TXEVENT_NCOLLISION_SHIFT) +#define ISQ_TXEVENT_16COLL (1 << 15) + +/* ISQ register BufEVENT bit definitions */ + +#define ISQ_BUFEVENT_SWINT (1 << 6) +#define ISQ_BUFEVENT_RXDMAFRAME (1 << 7) +#define ISQ_BUFEVENT_RDY4TX (1 << 8) +#define ISQ_BUFEVENT_TXUNDERRUN (1 << 9) +#define ISQ_BUFEVENT_RXMISS (1 << 10) +#define ISQ_BUFEVENT_RX128 (1 << 11) +#define ISQ_BUFEVENT_RXDEST (1 << 15) + +/* Packet page register offsets *********************************************/ + +/* 0x0000 Bus interface registers */ + +#define PPR_CHIPID 0x0000 /* Chip identifier - must be 0x630E */ +#define PPR_CHIPREV 0x0002 /* Chip revision, model codes */ +#define PPR_IOBASEADDRESS 0x0020 /* I/O Base Address */ +#define PPR_INTREG 0x0022 /* Interrupt configuration */ +# define PPR_INTREG_IRQ0 0x0000 /* Use INTR0 pin */ +# define PPR_INTREG_IRQ1 0x0001 /* Use INTR1 pin */ +# define PPR_INTREG_IRQ2 0x0002 /* Use INTR2 pin */ +# define PPR_INTREG_IRQ3 0x0003 /* Use INTR3 pin */ + +#define PPR_DMACHANNELNUMBER 0x0024 /* DMA Channel Number (0,1, or 2) */ +#define PPR_DMASTARTOFFRAME 0x0026 /* DMA Start of Frame */ +#define PPR_DMAFRAMECOUNT 0x0028 /* DMA Frame Count (12-bits) */ +#define PPR_RXDMABYTECOUNT 0x002a /* Rx DMA Byte Count */ +#define PPR_MEMORYBASEADDRESS 0x002c /* Memory Base Address Register (20-bit) */ +#define PPR_BOOTPROMBASEADDRESS 0x0030 /* Boot PROM Base Address */ +#define PPR_BOOTPROMADDRESSMASK 0x0034 /* Boot PROM Address Mask */ +#define PPR_EEPROMCOMMAND 0x0040 /* EEPROM Command */ +#define PPR_EEPROMDATA 0x0042 /* EEPROM Data */ +#define PPR_RECVFRAMEBYTES 0x0050 /* Received Frame Byte Counter */ + +/* 0x0100 - Configuration and control registers */ + +#define PPR_RXCFG 0x0102 /* Receiver configuration */ +# define PPR_RXCFG_SKIP1 (1 << 6) /* Skip (discard) current frame */ +# define PPR_RXCFG_STREAM (1 << 7) /* Enable streaming mode */ +# define PPR_RXCFG_RXOK (1 << 8) /* RxOK interrupt enable */ +# define PPR_RxCFG_RxDMAonly (1 << 9) /* Use RxDMA for all frames */ +# define PPR_RxCFG_AutoRxDMA (1 << 10) /* Select RxDMA automatically */ +# define PPR_RxCFG_BufferCRC (1 << 11) /* Include CRC characters in frame */ +# define PPR_RxCFG_CRC (1 << 12) /* Enable interrupt on CRC error */ +# define PPR_RxCFG_RUNT (1 << 13) /* Enable interrupt on RUNT frames */ +# define PPR_RxCFG_EXTRA (1 << 14) /* Enable interrupt on frames with extra data */ + +#define PPR_RXCTL 0x0104 /* Receiver control */ +# define PPR_RXCTL_IAHASH (1 << 6) /* Accept frames that match hash */ +# define PPR_RXCTL_PROMISCUOUS (1 << 7) /* Accept any frame */ +# define PPR_RXCTL_RXOK (1 << 8) /* Accept well formed frames */ +# define PPR_RXCTL_MULTICAST (1 << 9) /* Accept multicast frames */ +# define PPR_RXCTL_IA (1 << 10) /* Accept frame that matches IA */ +# define PPR_RXCTL_BROADCAST (1 << 11) /* Accept broadcast frames */ +# define PPR_RXCTL_CRC (1 << 12) /* Accept frames with bad CRC */ +# define PPR_RXCTL_RUNT (1 << 13) /* Accept runt frames */ +# define PPR_RXCTL_EXTRA (1 << 14) /* Accept frames that are too long */ + +#define PPR_TXCFG 0x0106 /* Transmit configuration */ +# define PPR_TXCFG_CRS (1 << 6) /* Enable interrupt on loss of carrier */ +# define PPR_TXCFG_SQE (1 << 7) /* Enable interrupt on Signal Quality Error */ +# define PPR_TXCFG_TXOK (1 << 8) /* Enable interrupt on successful xmits */ +# define PPR_TXCFG_LATE (1 << 9) /* Enable interrupt on "out of window" */ +# define PPR_TXCFG_JABBER (1 << 10) /* Enable interrupt on jabber detect */ +# define PPR_TXCFG_COLLISION (1 << 11) /* Enable interrupt if collision */ +# define PPR_TXCFG_16COLLISIONS (1 << 15) /* Enable interrupt if > 16 collisions */ + +#define PPR_TXCMD 0x0108 /* Transmit command status */ +# define PPR_TXCMD_TXSTART5 (0 << 6) /* Start after 5 bytes in buffer */ +# define PPR_TXCMD_TXSTART381 (1 << 6) /* Start after 381 bytes in buffer */ +# define PPR_TXCMD_TXSTART1021 (2 << 6) /* Start after 1021 bytes in buffer */ +# define PPR_TXCMD_TXSTARTFULL (3 << 6) /* Start after all bytes loaded */ +# define PPR_TXCMD_FORCE (1 << 8) /* Discard any pending packets */ +# define PPR_TXCMD_ONECOLLISION (1 << 9) /* Abort after a single collision */ +# define PPR_TXCMD_NOCRC (1 << 12) /* Do not add CRC */ +# define PPR_TXCMD_NOPAD (1 << 13) /* Do not pad short packets */ + +#define PPR_BUFCFG 0x010a /* Buffer configuration */ +# define PPR_BUFCFG_SWI (1 << 6) /* Force interrupt via software */ +# define PPR_BUFCFG_RXDMA (1 << 7) /* Enable interrupt on Rx DMA */ +# define PPR_BUFCFG_TXRDY (1 << 8) /* Enable interrupt when ready for Tx */ +# define PPR_BUFCFG_TXUE (1 << 9) /* Enable interrupt in Tx underrun */ +# define PPR_BUFCFG_RXMISS (1 << 10) /* Enable interrupt on missed Rx packets */ +# define PPR_BUFCFG_RX128 (1 << 11) /* Enable Rx interrupt after 128 bytes */ +# define PPR_BUFCFG_TXCOL (1 << 12) /* Enable int on Tx collision ctr overflow */ +# define PPR_BUFCFG_MISS (1 << 13) /* Enable int on Rx miss ctr overflow */ +# define PPR_BUFCFG_RXDEST (1 << 15) /* Enable int on Rx dest addr match */ + +#define PPR_LINECTL 0x0112 /* Line control */ +# define PPR_LINECTL_RX (1 << 6) /* Enable receiver */ +# define PPR_LINECTL_TX (1 << 7) /* Enable transmitter */ +# define PPR_LINECTL_AUIONLY (1 << 8) /* AUI interface only */ +# define PPR_LINECTL_AUTOAUI10BT (1 << 9) /* Autodetect AUI or 10BaseT interface */ +# define PPR_LINECTL_MODBACKOFFE (1 << 11) /* Enable modified backoff algorithm */ +# define PPR_LINECTL_POLARITYDIS (1 << 12) /* Disable Rx polarity autodetect */ +# define PPR_LINECTL_2PARTDEFDIS (1 << 13) /* Disable two-part defferal */ +# define PPR_LINECTL_LORXSQUELCH (1 << 14) /* Reduce receiver squelch threshold */ + +#define PPR_SELFCTL 0x0114 /* Chip self control */ +# define PPR_SELFCTL_RESET (1 << 6) /* Self-clearing reset */ +# define PPR_SELFCTL_SWSUSPEND (1 << 8) /* Initiate suspend mode */ +# define PPR_SELFCTL_HWSLEEPE (1 << 9) /* Enable SLEEP input */ +# define PPR_SELFCTL_HWSTANDBYE (1 << 10) /* Enable standby mode */ +# define PPR_SELFCTL_HC0E (1 << 12) /* Use HCB0 for LINK LED */ +# define PPR_SELFCTL_HC1E (1 << 13) /* Use HCB1 for BSTATUS LED */ +# define PPR_SELFCTL_HCB0 (1 << 14) /* Control LINK LED if HC0E set */ +# define PPR_SELFCTL_HCB1 (1 << 15) /* Cntrol BSTATUS LED if HC1E set */ + +#define PPR_BUSCTL 0x0116 /* Bus control */ +# define PPR_BUSCTL_RESETRXDMA (1 << 6) /* Reset RxDMA pointer */ +# define PPR_BUSCTL_DMAEXTEND (1 << 8) /* Extend DMA cycle */ +# define PPR_BUSCTL_USESA (1 << 9) /* Assert MEMCS16 on address decode */ +# define PPR_BUSCTL_MEMORYE (1 << 10) /* Enable memory mode */ +# define PPR_BUSCTL_DMABURST (1 << 11) /* Limit DMA access burst */ +# define PPR_BUSCTL_IOCHRDYE (1 << 12) /* Set IOCHRDY high impedence */ +# define PPR_BUSCTL_RXDMASIZE (1 << 13) /* Set DMA buffer size 64KB */ +# define PPR_BUSCTL_ENABLEIRQ (1 << 15) /* Generate interrupt on interrupt event */ + +#define PPR_TESTCTL 0x0118 /* Test control */ +# define PPR_TESTCTL_DISABLELT (1 << 7) /* Disable link status */ +# define PPR_TESTCTL_ENDECLOOP (1 << 9) /* Internal loopback */ +# define PPR_TESTCTL_AUILOOP (1 << 10) /* AUI loopback */ +# define PPR_TESTCTL_DISBACKOFF (1 << 11) /* Disable backoff algorithm */ +# define PPR_TESTCTL_FDX (1 << 14) /* Enable full duplex mode */ + +/* 0x0120 - Status and Event Registers */ + +#define PPR_ISQ 0x0120 /* Interrupt Status Queue */ +#define PPR_RER 0x0124 /* Receive event */ +# define PPR_RER_IAHASH (1 << 6) /* Frame hash match */ +# define PPR_RER_DRIBBLE (1 << 7) /* Frame had 1-7 extra bits after last byte */ +# define PPR_RER_RXOK (1 << 8) /* Frame received with no errors */ +# define PPR_RER_HASHED (1 << 9) /* Frame address hashed OK */ +# define PPR_RER_IA (1 << 10) /* Frame address matched IA */ +# define PPR_RER_BROADCAST (1 << 11) /* Broadcast frame */ +# define PPR_RER_CRC (1 << 12) /* Frame had CRC error */ +# define PPR_RER_RUNT (1 << 13) /* Runt frame */ +# define PPR_RER_EXTRA (1 << 14) /* Frame was too long */ + +#define PPR_TER 0x0128 /* Transmit event */ +# define PPR_TER_CRS (1 << 6) /* Carrier lost */ +# define PPR_TER_SQE (1 << 7) /* Signal Quality Error */ +# define PPR_TER_TXOK (1 << 8) /* Packet sent without error */ +# define PPR_TER_LATE (1 << 9) /* Out of window */ +# define PPR_TER_JABBER (1 << 10) /* Stuck transmit? */ +# define PPR_TER_NUMCOLLISIONS_SHIFT 11 +# define PPR_TER_NUMCOLLISIONS_MASK (15 << PPR_TER_NUMCOLLISIONS_SHIFT) +# define PPR_TER_16COLLISIONS (1 << 15) /* > 16 collisions */ + +#define PPR_BER 0x012C /* Buffer event */ +# define PPR_BER_SWINT (1 << 6) /* Software interrupt */ +# define PPR_BER_RXDMAFRAME (1 << 7) /* Received framed DMAed */ +# define PPR_BER_RDY4TX (1 << 8) /* Ready for transmission */ +# define PPR_BER_TXUNDERRUN (1 << 9) /* Transmit underrun */ +# define PPR_BER_RXMISS (1 << 10) /* Received frame missed */ +# define PPR_BER_RX128 (1 << 11) /* 128 bytes received */ +# define PPR_BER_RXDEST (1 << 15) /* Received framed passed address filter */ + +#define PPR_RXMISS 0x0130 /* Receiver miss counter */ +#define PPR_TXCOL 0x0132 /* Transmit collision counter */ +#define PPR_LINESTAT 0x0134 /* Line status */ +# define PPR_LINESTAT_LINKOK (1 << 7) /* Line is connected and working */ +# define PPR_LINESTAT_AUI (1 << 8) /* Connected via AUI */ +# define PPR_LINESTAT_10BT (1 << 9) /* Connected via twisted pair */ +# define PPR_LINESTAT_POLARITY (1 << 12) /* Line polarity OK (10BT only) */ +# define PPR_LINESTAT_CRS (1 << 14) /* Frame being received */ + +#define PPR_SELFSTAT 0x0136 /* Chip self status */ +# define PPR_SELFSTAT_33VACTIVE (1 << 6) /* supply voltage is 3.3V */ +# define PPR_SELFSTAT_INITD (1 << 7) /* Chip initialization complete */ +# define PPR_SELFSTAT_SIBSY (1 << 8) /* EEPROM is busy */ +# define PPR_SELFSTAT_EEPROM (1 << 9) /* EEPROM present */ +# define PPR_SELFSTAT_EEPROMOK (1 << 10) /* EEPROM checks out */ +# define PPR_SELFSTAT_ELPRESENT (1 << 11) /* External address latch logic available */ +# define PPR_SELFSTAT_EESIZE (1 << 12) /* Size of EEPROM */ + +#define PPR_BUSSTAT 0x0138 /* Bus status */ +# define PPR_BUSSTAT_TXBID (1 << 7) /* Tx error */ +# define PPR_BUSSTAT_TXRDY (1 << 8) /* Ready for Tx data */ + +#define PPR_TDR 0x013C /* AUI Time Domain Reflectometer */ + +/* 0x0144 - Initiate transmit registers */ + +#define PPR_TXCOMMAND 0x0144 /* Tx Command */ +#define PPR_TXLENGTH 0x0146 /* Tx Length */ + +/* 0x0150 - Address filter registers */ + +#define PPR_LAF 0x0150 /* Logical address filter (6 bytes) */ +#define PPR_IA 0x0158 /* Individual address (MAC) */ + +/* 0x0400 - Frame location registers */ + +#define PPR_RXSTATUS 0x0400 /* Rx Status */ +#define PPR_RXLENGTH 0x0402 /* Rx Length */ +#define PPR_RXFRAMELOCATION 0x0404 /* Rx Frame Location */ +#define PPR_TXFRAMELOCATION 0x0a00 /* Tx Frame Location */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __DRIVERS_NET_CS89x0_H */ diff --git a/nuttx/drivers/net/dm90x0.c b/nuttx/drivers/net/dm90x0.c index 15433e0f80..2f5b26abb6 100644 --- a/nuttx/drivers/net/dm90x0.c +++ b/nuttx/drivers/net/dm90x0.c @@ -2,7 +2,7 @@ * drivers/net/dm9x.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Davicom data sheets (DM9000-DS-F03-041906.pdf, * DM9010-DS-F01-103006.pdf) and looking at lots of other DM90x0 diff --git a/nuttx/drivers/net/enc28j60.c b/nuttx/drivers/net/enc28j60.c index 76b0f205b1..2346ee2d65 100644 --- a/nuttx/drivers/net/enc28j60.c +++ b/nuttx/drivers/net/enc28j60.c @@ -42,7 +42,8 @@ ****************************************************************************/ #include -#if defined(CONFIG_NET) && defined(CONFIG_NET_ENC28J60) + +#if defined(CONFIG_NET) && defined(CONFIG_ENC28J60) #include #include @@ -74,7 +75,7 @@ /* ENC28J60 Configuration Settings: * - * CONFIG_NET_ENC28J60 - Enabled ENC28J60 support + * CONFIG_ENC28J60 - Enabled ENC28J60 support * CONFIG_ENC28J60_SPIMODE - Controls the SPI mode * CONFIG_ENC28J60_FREQUENCY - Define to use a different bus frequency * CONFIG_ENC28J60_NINTERFACES - Specifies the number of physical ENC28J60 @@ -83,12 +84,15 @@ * CONFIG_ENC28J60_HALFDUPPLEX - Default is full duplex */ -/* The ENC28J60 spec says that is supports SPI mode 0,0 only. However, - * somtimes you need to tinker with these things. +/* The ENC28J60 spec says that it supports SPI mode 0,0 only: "The + * implementation used on this device supports SPI mode 0,0 only. In + * addition, the SPI port requires that SCK be at Idle in a low state; + * selectable clock polarity is not supported." However, sometimes you + * need to tinker with these things. */ #ifndef CONFIG_ENC28J60_SPIMODE -# define CONFIG_ENC28J60_SPIMODE SPIDEV_MODE2 +# define CONFIG_ENC28J60_SPIMODE SPIDEV_MODE0 #endif /* CONFIG_ENC28J60_NINTERFACES determines the number of physical interfaces @@ -107,7 +111,7 @@ /* We need to have the work queue to handle SPI interrupts */ -#if !defined(CONFIG_SCHED_WORKQUEUE) && !defined(CONFIG_SPI_OWNBUS) +#ifndef CONFIG_SCHED_WORKQUEUE # error "Worker thread support is required (CONFIG_SCHED_WORKQUEUE)" #endif @@ -119,6 +123,18 @@ # define enc_dumppacket(m,a,n) #endif +/* The ENC28J60 will not do interrupt level processing */ + +#ifndef CONFIG_NET_NOINTS +# warrning "CONFIG_NET_NOINTS should be set" +#endif + +/* Low-level register debug */ + +#if !defined(CONFIG_DEBUG) || !defined(CONFIG_DEBUG_NET) +# undef CONFIG_ENC28J60_REGDEBUG +#endif + /* Timing *******************************************************************/ /* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ @@ -141,7 +157,7 @@ #define ALIGNED_BUFSIZE ((CONFIG_NET_BUFSIZE + 255) & ~255) #define PKTMEM_TX_START 0x0000 /* Start TX buffer at 0 */ -#define PKTMEM_TX_ENDP1 ALIGNED_BUFSIZE /* Allow TX buffer for one frame + */ +#define PKTMEM_TX_ENDP1 ALIGNED_BUFSIZE /* Allow TX buffer for one frame */ #define PKTMEM_RX_START PKTMEM_TX_ENDP1 /* Followed by RX buffer */ #define PKTMEM_RX_END PKTMEM_END /* RX buffer goes to the end of SRAM */ @@ -160,10 +176,33 @@ #define BUF ((struct uip_eth_hdr *)priv->dev.d_buf) +/* Debug ********************************************************************/ + +#ifdef CONFIG_ENC28J60_REGDEBUG +# define enc_wrdump(a,v) lib_lowprintf("ENC28J60: %02x<-%02x\n", a, v); +# define enc_rddump(a,v) lib_lowprintf("ENC28J60: %02x->%02x\n", a, v); +# define enc_cmddump(c) lib_lowprintf("ENC28J60: CMD: %02x\n", c); +# define enc_bmdump(c,b,s) lib_lowprintf("ENC28J60: CMD: %02x buffer: %p length: %d\n", c,b,s); +#else +# define enc_wrdump(a,v) +# define enc_rddump(a,v) +# define enc_cmddump(c) +# define enc_bmdump(c,b,s) +#endif + /**************************************************************************** * Private Types ****************************************************************************/ +/* The state of the interface */ + +enum enc_state_e +{ + ENCSTATE_UNINIT = 0, /* The interface is in an uninitialized state */ + ENCSTATE_DOWN, /* The interface is down */ + ENCSTATE_UP /* The interface is up */ +}; + /* The enc_driver_s encapsulates all state information for a single hardware * interface */ @@ -172,23 +211,23 @@ struct enc_driver_s { /* Device control */ - bool bifup; /* true:ifup false:ifdown */ - uint8_t bank; /* Currently selected bank */ - uint16_t nextpkt; /* Next packet address */ - int irq; /* GPIO IRQ configured for the ENC28J60 */ + uint8_t ifstate; /* Interface state: See ENCSTATE_* */ + uint8_t bank; /* Currently selected bank */ + uint16_t nextpkt; /* Next packet address */ + FAR const struct enc_lower_s *lower; /* Low-level MCU-specific support */ /* Timing */ - WDOG_ID txpoll; /* TX poll timer */ - WDOG_ID txtimeout; /* TX timeout timer */ + WDOG_ID txpoll; /* TX poll timer */ + WDOG_ID txtimeout; /* TX timeout timer */ - /* We we don't own the SPI bus, then we cannot do SPI accesses from the + /* If we don't own the SPI bus, then we cannot do SPI accesses from the * interrupt handler. */ - -#ifndef CONFIG_SPI_OWNBUS - struct work_s work; /* Work queue support */ -#endif + + struct work_s irqwork; /* Interrupt continuation work queue support */ + struct work_s towork; /* Tx timeout work queue support */ + struct work_s pollwork; /* Poll timeout work queue support */ /* This is the contained SPI driver intstance */ @@ -196,12 +235,12 @@ struct enc_driver_s /* This holds the information visible to uIP/NuttX */ - struct uip_driver_s dev; /* Interface understood by uIP */ + struct uip_driver_s dev; /* Interface understood by uIP */ /* Statistics */ #ifdef CONFIG_ENC28J60_STATS - struct enc_stats_s stats; + struct enc_stats_s stats; #endif }; @@ -217,13 +256,14 @@ static struct enc_driver_s g_enc28j60[CONFIG_ENC28J60_NINTERFACES]; /* Low-level SPI helpers */ -static inline void enc_configspi(FAR struct spi_dev_s *spi); #ifdef CONFIG_SPI_OWNBUS -static inline void enc_select(FAR struct spi_dev_s *spi); -static inline void enc_deselect(FAR struct spi_dev_s *spi); +static inline void enc_configspi(FAR struct spi_dev_s *spi); +# define enc_lock(priv); +# define enc_unlock(priv); #else -static void enc_select(FAR struct spi_dev_s *spi); -static void enc_deselect(FAR struct spi_dev_s *spi); +# define enc_configspi(spi) +static void enc_lock(FAR struct enc_driver_s *priv); +static inline void enc_unlock(FAR struct enc_driver_s *priv); #endif /* SPI control register access */ @@ -231,18 +271,24 @@ static void enc_deselect(FAR struct spi_dev_s *spi); static uint8_t enc_rdgreg2(FAR struct enc_driver_s *priv, uint8_t cmd); static void enc_wrgreg2(FAR struct enc_driver_s *priv, uint8_t cmd, uint8_t wrdata); +static inline void enc_src(FAR struct enc_driver_s *priv); static void enc_setbank(FAR struct enc_driver_s *priv, uint8_t bank); static uint8_t enc_rdbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg); static void enc_wrbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, uint8_t wrdata); -static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, +static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, uint8_t bits, uint8_t value); +#if 0 /* Sometimes useful */ +static void enc_rxdump(FAR struct enc_driver_s *priv); +static void enc_txdump(FAR struct enc_driver_s *priv); +#endif + /* SPI buffer transfers */ static void enc_rdbuffer(FAR struct enc_driver_s *priv, FAR uint8_t *buffer, size_t buflen); -static void enc_wrbuffer(FAR struct enc_driver_s *priv, +static inline void enc_wrbuffer(FAR struct enc_driver_s *priv, FAR const uint8_t *buffer, size_t buflen); /* PHY register access */ @@ -263,15 +309,17 @@ static void enc_txif(FAR struct enc_driver_s *priv); static void enc_txerif(FAR struct enc_driver_s *priv); static void enc_txerif(FAR struct enc_driver_s *priv); static void enc_rxerif(FAR struct enc_driver_s *priv); -static void enc_rxdispath(FAR struct enc_driver_s *priv); +static void enc_rxdispatch(FAR struct enc_driver_s *priv); static void enc_pktif(FAR struct enc_driver_s *priv); -static void enc_worker(FAR void *arg); +static void enc_irqworker(FAR void *arg); static int enc_interrupt(int irq, FAR void *context); /* Watchdog timer expirations */ -static void enc_polltimer(int argc, uint32_t arg, ...); +static void enc_toworker(FAR void *arg); static void enc_txtimeout(int argc, uint32_t arg, ...); +static void enc_pollworker(FAR void *arg); +static void enc_polltimer(int argc, uint32_t arg, ...); /* NuttX callback functions */ @@ -310,23 +358,21 @@ static int enc_reset(FAR struct enc_driver_s *priv); * ****************************************************************************/ +#ifdef CONFIG_SPI_OWNBUS static inline void enc_configspi(FAR struct spi_dev_s *spi) { /* Configure SPI for the ENC28J60. But only if we own the SPI bus. * Otherwise, don't bother because it might change. */ -#ifdef CONFIG_SPI_OWNBUS SPI_SETMODE(spi, CONFIG_ENC28J60_SPIMODE); SPI_SETBITS(spi, 8); -#ifdef CONFIG_ENC28J60_FREQUENCY SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY) -#endif -#endif } +#endif /**************************************************************************** - * Function: enc_select + * Function: enc_lock * * Description: * Select the SPI, locking and re-configuring if necessary @@ -341,37 +387,27 @@ static inline void enc_configspi(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void enc_select(FAR struct spi_dev_s *spi) +#ifndef CONFIG_SPI_OWNBUS +static void enc_lock(FAR struct enc_driver_s *priv) { - /* We own the SPI bus, so just select the chip */ - - SPI_SELECT(spi, SPIDEV_ETHERNET, true); -} -#else -static void enc_select(FAR struct spi_dev_s *spi) -{ - /* Select ENC28J60 chip (locking the SPI bus in case there are multiple - * devices competing for the SPI bus + /* Lock the SPI bus in case there are multiple devices competing for the SPI + * bus. */ - SPI_LOCK(spi, true); - SPI_SELECT(spi, SPIDEV_ETHERNET, true); + SPI_LOCK(priv->spi, true); /* Now make sure that the SPI bus is configured for the ENC28J60 (it * might have gotten configured for a different device while unlocked) */ - SPI_SETMODE(spi, CONFIG_ENC28J60_SPIMODE); - SPI_SETBITS(spi, 8); -#ifdef CONFIG_ENC28J60_FREQUENCY - SPI_SETFREQUENCY(spi, CONFIG_ENC28J60_FREQUENCY); -#endif + SPI_SETMODE(priv->spi, CONFIG_ENC28J60_SPIMODE); + SPI_SETBITS(priv->spi, 8); + SPI_SETFREQUENCY(priv->spi, CONFIG_ENC28J60_FREQUENCY); } #endif /**************************************************************************** - * Function: enc_deselect + * Function: enc_unlock * * Description: * De-select the SPI @@ -386,20 +422,12 @@ static void enc_select(FAR struct spi_dev_s *spi) * ****************************************************************************/ -#ifdef CONFIG_SPI_OWNBUS -static inline void enc_deselect(FAR struct spi_dev_s *spi) +#ifndef CONFIG_SPI_OWNBUS +static inline void enc_unlock(FAR struct enc_driver_s *priv) { - /* We own the SPI bus, so just de-select the chip */ + /* Relinquish the lock on the bus. */ - SPI_SELECT(spi, SPIDEV_ETHERNET, false); -} -#else -static void enc_deselect(FAR struct spi_dev_s *spi) -{ - /* De-select ENC28J60 chip and relinquish the SPI bus. */ - - SPI_SELECT(spi, SPIDEV_ETHERNET, false); - SPI_LOCK(spi, false); + SPI_LOCK(priv->spi, false); } #endif @@ -423,26 +451,26 @@ static void enc_deselect(FAR struct spi_dev_s *spi) static uint8_t enc_rdgreg2(FAR struct enc_driver_s *priv, uint8_t cmd) { - FAR struct spi_dev_s *spi; uint8_t rddata; DEBUGASSERT(priv && priv->spi); - spi = priv->spi; /* Select ENC28J60 chip */ - enc_select(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; /* Send the read command and collect the data. The sequence requires * 16-clocks: 8 to clock out the cmd + 8 to clock in the data. */ - (void)SPI_SEND(spi, cmd); /* Clock out the command */ - rddata = SPI_SEND(spi, 0); /* Clock in the data */ + (void)SPI_SEND(priv->spi, cmd); /* Clock out the command */ + rddata = SPI_SEND(priv->spi, 0); /* Clock in the data */ /* De-select ENC28J60 chip */ - enc_deselect(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + + enc_rddump(cmd, rddata); return rddata; } @@ -468,25 +496,77 @@ static uint8_t enc_rdgreg2(FAR struct enc_driver_s *priv, uint8_t cmd) static void enc_wrgreg2(FAR struct enc_driver_s *priv, uint8_t cmd, uint8_t wrdata) { - FAR struct spi_dev_s *spi; - DEBUGASSERT(priv && priv->spi); - spi = priv->spi; /* Select ENC28J60 chip */ - enc_select(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; /* Send the write command and data. The sequence requires 16-clocks: * 8 to clock out the cmd + 8 to clock out the data. */ - (void)SPI_SEND(spi, cmd); /* Clock out the command */ - (void)SPI_SEND(spi, wrdata); /* Clock out the data */ + (void)SPI_SEND(priv->spi, cmd); /* Clock out the command */ + (void)SPI_SEND(priv->spi, wrdata); /* Clock out the data */ /* De-select ENC28J60 chip. */ - enc_deselect(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + enc_wrdump(cmd, wrdata); +} + +/**************************************************************************** + * Function: enc_src + * + * Description: + * Send the single byte system reset command (SRC). + * + * "The System Reset Command (SRC) allows the host controller to issue a + * System Soft Reset command. Unlike other SPI commands, the SRC is + * only a single byte command and does not operate on any register. The + * command is started by pulling the CS pin low. The SRC opcode is the + * sent, followed by a 5-bit Soft Reset command constant of 1Fh. The + * SRC operation is terminated by raising the CS pin." + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static inline void enc_src(FAR struct enc_driver_s *priv) +{ + DEBUGASSERT(priv && priv->spi); + + /* Select ENC28J60 chip */ + + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + + /* Send the system reset command. */ + + (void)SPI_SEND(priv->spi, ENC_SRC); + + /* Check CLKRDY bit to see when the reset is complete. There is an errata + * that says the CLKRDY may be invalid. We'll wait a couple of msec to + * workaround this condition. + * + * Also, "After a System Reset, all PHY registers should not be read or + * written to until at least 50 µs have passed since the Reset has ended. + * All registers will revert to their Reset default values. The dual + * port buffer memory will maintain state throughout the System Reset." + */ + + up_mdelay(2); + /* while ((enc_rdgreg(priv, ENC_ESTAT) & ESTAT_CLKRDY) != 0); */ + + /* De-select ENC28J60 chip. */ + + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + enc_cmddump(ENC_SRC); } /**************************************************************************** @@ -551,39 +631,39 @@ static void enc_setbank(FAR struct enc_driver_s *priv, uint8_t bank) static uint8_t enc_rdbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg) { - FAR struct spi_dev_s *spi; uint8_t rddata; DEBUGASSERT(priv && priv->spi); - spi = priv->spi; - - /* Select ENC28J60 chip */ - - enc_select(spi); /* Set the bank */ enc_setbank(priv, GETBANK(ctrlreg)); + /* Re-select ENC28J60 chip */ + + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + /* Send the RCR command and collect the data. How we collect the data * depends on if this is a PHY/CAN or not. The normal sequence requires * 16-clocks: 8 to clock out the cmd and 8 to clock in the data. */ - (void)SPI_SEND(spi, ENC_RCR | GETADDR(ctrlreg)); /* Clock out the command */ + (void)SPI_SEND(priv->spi, ENC_RCR | GETADDR(ctrlreg)); /* Clock out the command */ if (ISPHYMAC(ctrlreg)) { /* The PHY/MAC sequence requires 24-clocks: 8 to clock out the cmd, * 8 dummy bits, and 8 to clock in the PHY/MAC data. */ - (void)SPI_SEND(spi,0); /* Clock in the dummy byte */ + (void)SPI_SEND(priv->spi, 0); /* Clock in the dummy byte */ } - rddata = SPI_SEND(spi, 0); /* Clock in the data */ + + rddata = SPI_SEND(priv->spi, 0); /* Clock in the data */ /* De-select ENC28J60 chip */ - enc_deselect(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + enc_rddump(ENC_RCR | GETADDR(ctrlreg), rddata); return rddata; } @@ -610,29 +690,27 @@ static uint8_t enc_rdbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg) static void enc_wrbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, uint8_t wrdata) { - FAR struct spi_dev_s *spi; - DEBUGASSERT(priv && priv->spi); - spi = priv->spi; - - /* Select ENC28J60 chip */ - - enc_select(spi); /* Set the bank */ enc_setbank(priv, GETBANK(ctrlreg)); + /* Re-select ENC28J60 chip */ + + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; + /* Send the WCR command and data. The sequence requires 16-clocks: * 8 to clock out the cmd + 8 to clock out the data. */ - (void)SPI_SEND(spi, ENC_WCR | GETADDR(ctrlreg)); /* Clock out the command */ - (void)SPI_SEND(spi, wrdata); /* Clock out the data */ + (void)SPI_SEND(priv->spi, ENC_WCR | GETADDR(ctrlreg)); /* Clock out the command */ + (void)SPI_SEND(priv->spi, wrdata); /* Clock out the data */ /* De-select ENC28J60 chip. */ - enc_deselect(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + enc_wrdump(ENC_WCR | GETADDR(ctrlreg), wrdata); } /**************************************************************************** @@ -672,9 +750,82 @@ static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, elapsed = clock_systimer() - start; } while ((rddata & bits) != value || elapsed > ENC_POLLTIMEOUT); + return (rddata & bits) == value ? -ETIMEDOUT : OK; } +/**************************************************************************** + * Function: enc_txdump enc_rxdump + * + * Description: + * Dump registers associated with receiving or sending packets. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#if 0 /* Sometimes useful */ +static void enc_rxdump(FAR struct enc_driver_s *priv) +{ + lib_lowprintf("Rx Registers:\n"); + lib_lowprintf(" EIE: %02x EIR: %02x\n", + enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR)); + lib_lowprintf(" ESTAT: %02x ECON1: %02x ECON2: %02x\n", + enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1), + enc_rdgreg(priv, ENC_ECON2)); + lib_lowprintf(" ERXST: %02x %02x\n", + enc_rdbreg(priv, ENC_ERXSTH), enc_rdbreg(priv, ENC_ERXSTL)); + lib_lowprintf(" ERXND: %02x %02x\n", + enc_rdbreg(priv, ENC_ERXNDH), enc_rdbreg(priv, ENC_ERXNDL)); + lib_lowprintf(" ERXRDPT: %02x %02x\n", + enc_rdbreg(priv, ENC_ERXRDPTH), enc_rdbreg(priv, ENC_ERXRDPTL)); + lib_lowprintf(" ERXFCON: %02x EPKTCNT: %02x\n", + enc_rdbreg(priv, ENC_ERXFCON), enc_rdbreg(priv, ENC_EPKTCNT)); + lib_lowprintf(" MACON1: %02x MACON3: %02x\n", + enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3)); + lib_lowprintf(" MAMXFL: %02x %02x\n", + enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL)); + lib_lowprintf(" MAADR: %02x:%02x:%02x:%02x:%02x:%02x\n", + enc_rdbreg(priv, ENC_MAADR1), enc_rdbreg(priv, ENC_MAADR2), + enc_rdbreg(priv, ENC_MAADR3), enc_rdbreg(priv, ENC_MAADR4), + enc_rdbreg(priv, ENC_MAADR5), enc_rdbreg(priv, ENC_MAADR6)); +} +#endif + +#if 0 /* Sometimes useful */ +static void enc_txdump(FAR struct enc_driver_s *priv) +{ + lib_lowprintf("Tx Registers:\n"); + lib_lowprintf(" EIE: %02x EIR: %02x ESTAT: %02x\n", + enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR),); + lib_lowprintf(" ESTAT: %02x ECON1: %02x\n", + enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1)); + lib_lowprintf(" ETXST: %02x %02x\n", + enc_rdbreg(priv, ENC_ETXSTH), enc_rdbreg(priv, ENC_ETXSTL)); + lib_lowprintf(" ETXND: %02x %02x\n", + enc_rdbreg(priv, ENC_ETXNDH), enc_rdbreg(priv, ENC_ETXNDL)); + lib_lowprintf(" MACON1: %02x MACON3: %02x MACON4: %02x\n", + enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3), + enc_rdbreg(priv, ENC_MACON4)); + lib_lowprintf(" MACON1: %02x MACON3: %02x MACON4: %02x\n", + enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3), + enc_rdbreg(priv, ENC_MACON4)); + lib_lowprintf(" MABBIPG: %02x MAIPG %02x %02x\n", + enc_rdbreg(priv, ENC_MABBIPG), enc_rdbreg(priv, ENC_MAIPGH), + enc_rdbreg(priv, ENC_MAIPGL)); + lib_lowprintf(" MACLCON1: %02x MACLCON2: %02x\n", + enc_rdbreg(priv, ENC_MACLCON1), enc_rdbreg(priv, ENC_MACLCON2)); + lib_lowprintf(" MAMXFL: %02x %02x\n", + enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL)); +} +#endif + /**************************************************************************** * Function: enc_rdbuffer * @@ -697,26 +848,24 @@ static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, static void enc_rdbuffer(FAR struct enc_driver_s *priv, FAR uint8_t *buffer, size_t buflen) { - FAR struct spi_dev_s *spi; - DEBUGASSERT(priv && priv->spi); - spi = priv->spi; /* Select ENC28J60 chip */ - enc_select(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; /* Send the read buffer memory command (ignoring the response) */ - (void)SPI_SEND(spi, ENC_RBM); + (void)SPI_SEND(priv->spi, ENC_RBM); /* Then read the buffer data */ - SPI_RECVBLOCK(spi, buffer, buflen); + SPI_RECVBLOCK(priv->spi, buffer, buflen); /* De-select ENC28J60 chip. */ - enc_deselect(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + enc_bmdump(ENC_WBM, buffer, buflen); } /**************************************************************************** @@ -738,29 +887,68 @@ static void enc_rdbuffer(FAR struct enc_driver_s *priv, FAR uint8_t *buffer, * ****************************************************************************/ -static void enc_wrbuffer(FAR struct enc_driver_s *priv, - FAR const uint8_t *buffer, size_t buflen) +static inline void enc_wrbuffer(FAR struct enc_driver_s *priv, + FAR const uint8_t *buffer, size_t buflen) { - FAR struct spi_dev_s *spi; - DEBUGASSERT(priv && priv->spi); - spi = priv->spi; - /* Select ENC28J60 chip */ + /* Select ENC28J60 chip + * + * "The WBM command is started by lowering the CS pin. ..." + */ - enc_select(spi); + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, true);; - /* Send the write buffer memory command (ignoring the response) */ + /* Send the write buffer memory command (ignoring the response) + * + * "...The [3-bit]WBM opcode should then be sent to the ENC28J60, + * followed by the 5-bit constant, 1Ah." + */ - (void)SPI_SEND(spi, ENC_WBM); + (void)SPI_SEND(priv->spi, ENC_WBM); - /* Then send the buffer */ + /* "...the ENC28J60 requires a single per packet control byte to + * precede the packet for transmission." + * + * POVERRIDE: Per Packet Override bit (Not set): + * 1 = The values of PCRCEN, PPADEN and PHUGEEN will override the + * configuration defined by MACON3. + * 0 = The values in MACON3 will be used to determine how the packet + * will be transmitted + * PCRCEN: Per Packet CRC Enable bit (Set, but won't be used because + * POVERRIDE is zero). + * PPADEN: Per Packet Padding Enable bit (Set, but won't be used because + * POVERRIDE is zero). + * PHUGEEN: Per Packet Huge Frame Enable bit (Set, but won't be used + * because POVERRIDE is zero). + */ - SPI_SNDBLOCK(spi, buffer, buflen); + (void)SPI_SEND(priv->spi, + (PKTCTRL_PCRCEN | PKTCTRL_PPADEN | PKTCTRL_PHUGEEN)); - /* De-select ENC28J60 chip. */ + /* Then send the buffer + * + * "... After the WBM command and constant are sent, the data to + * be stored in the memory pointed to by EWRPT should be shifted + * out MSb first to the ENC28J60. After 8 data bits are received, + * the Write Pointer will automatically increment if AUTOINC is + * set. The host controller can continue to provide clocks on the + * SCK pin and send data on the SI pin, without raising CS, to + * keep writing to the memory. In this manner, with AUTOINC + * enabled, it is possible to continuously write sequential bytes + * to the buffer memory without any extra SPI command + * overhead. + */ - enc_deselect(spi); + SPI_SNDBLOCK(priv->spi, buffer, buflen); + + /* De-select ENC28J60 chip + * + * "The WBM command is terminated by bringing up the CS pin. ..." + */ + + SPI_SELECT(priv->spi, SPIDEV_ETHERNET, false); + enc_bmdump(ENC_WBM, buffer, buflen+1); } /**************************************************************************** @@ -784,24 +972,43 @@ static uint16_t enc_rdphy(FAR struct enc_driver_s *priv, uint8_t phyaddr) { uint16_t data = 0; - /* Set the PHY address (and start the PHY read operation) */ + /* "To read from a PHY register: + * + * 1. Write the address of the PHY register to read from into the MIREGADR + * register. + */ enc_wrbreg(priv, ENC_MIREGADR, phyaddr); + + /* 2. Set the MICMD.MIIRD bit. The read operation begins and the + * MISTAT.BUSY bit is set. + */ + enc_wrbreg(priv, ENC_MICMD, MICMD_MIIRD); - /* Wait until the PHY read completes */ + /* 3. Wait 10.24 µs. Poll the MISTAT.BUSY bit to be certain that the + * operation is complete. While busy, the host controller should not + * start any MIISCAN operations or write to the MIWRH register. + * + * When the MAC has obtained the register contents, the BUSY bit will + * clear itself. + */ + up_udelay(12); if (enc_waitbreg(priv, ENC_MISTAT, MISTAT_BUSY, 0x00) == OK); { - /* Terminate reading */ + /* 4. Clear the MICMD.MIIRD bit. */ enc_wrbreg(priv, ENC_MICMD, 0x00); - /* Get the PHY data */ + /* 5. Read the desired data from the MIRDL and MIRDH registers. The + * order that these bytes are accessed is unimportant." + */ data = (uint16_t)enc_rdbreg(priv, ENC_MIRDL); data |= (uint16_t)enc_rdbreg(priv, ENC_MIRDH) << 8; } + return data; } @@ -826,17 +1033,35 @@ static uint16_t enc_rdphy(FAR struct enc_driver_s *priv, uint8_t phyaddr) static void enc_wrphy(FAR struct enc_driver_s *priv, uint8_t phyaddr, uint16_t phydata) { - /* Set the PHY register address */ + /* "To write to a PHY register: + * + * 1. Write the address of the PHY register to write to into the + * MIREGADR register. + */ enc_wrbreg(priv, ENC_MIREGADR, phyaddr); - /* Write the PHY data */ + /* 2. Write the lower 8 bits of data to write into the MIWRL register. */ enc_wrbreg(priv, ENC_MIWRL, phydata); + + /* 3. Write the upper 8 bits of data to write into the MIWRH register. + * Writing to this register automatically begins the MIIM transaction, + * so it must be written to after MIWRL. The MISTAT.BUSY bit becomes + * set. + */ + enc_wrbreg(priv, ENC_MIWRH, phydata >> 8); - /* Wait until the PHY write completes */ + /* The PHY register will be written after the MIIM operation completes, + * which takes 10.24 µs. When the write operation has completed, the BUSY + * bit will clear itself. + * + * The host controller should not start any MIISCAN or MIIRD operations + * while busy." + */ + up_udelay(12); enc_waitbreg(priv, ENC_MISTAT, MISTAT_BUSY, 0x00); } @@ -887,22 +1112,28 @@ static int enc_transmit(FAR struct enc_driver_s *priv) enc_dumppacket("Transmit Packet", priv->dev.d_buf, priv->dev.d_len); + /* Set transmit buffer start (is this necessary?). */ + + enc_wrbreg(priv, ENC_ETXSTL, PKTMEM_TX_START & 0xff); + enc_wrbreg(priv, ENC_ETXSTH, PKTMEM_TX_START >> 8); + /* Reset the write pointer to start of transmit buffer */ enc_wrbreg(priv, ENC_EWRPTL, PKTMEM_TX_START & 0xff); enc_wrbreg(priv, ENC_EWRPTH, PKTMEM_TX_START >> 8); - /* Set the TX End pointer based on the size of the packet to send */ + /* Set the TX End pointer based on the size of the packet to send. Note + * that the offset accounts for the control byte at the beginning the + * buffer plus the size of the packet data. + */ txend = PKTMEM_TX_START + priv->dev.d_len; enc_wrbreg(priv, ENC_ETXNDL, txend & 0xff); enc_wrbreg(priv, ENC_ETXNDH, txend >> 8); - /* Write the per-packet control byte into the transmit buffer */ - - enc_wrgreg(priv, ENC_WBM, 0x00); - - /* Copy the packet itself into the transmit buffer */ + /* Send the WBM command and copy the packet itself into the transmit + * buffer at the position of the EWRPT register. + */ enc_wrbuffer(priv, priv->dev.d_buf, priv->dev.d_len); @@ -937,6 +1168,7 @@ static int enc_transmit(FAR struct enc_driver_s *priv) * OK on success; a negated errno on failure * * Assumptions: + * Interrupts are enabled but the caller holds the uIP lock. * ****************************************************************************/ @@ -1006,6 +1238,7 @@ static void enc_linkstatus(FAR struct enc_driver_s *priv) * None * * Assumptions: + * Interrupts are enabled but the caller holds the uIP lock. * ****************************************************************************/ @@ -1106,7 +1339,7 @@ static void enc_rxerif(FAR struct enc_driver_s *priv) } /**************************************************************************** - * Function: enc_rxdispath + * Function: enc_rxdispatch * * Description: * Give the newly received packet to uIP. @@ -1118,10 +1351,11 @@ static void enc_rxerif(FAR struct enc_driver_s *priv) * None * * Assumptions: + * Interrupts are enabled but the caller holds the uIP lock. * ****************************************************************************/ -static void enc_rxdispath(FAR struct enc_driver_s *priv) +static void enc_rxdispatch(FAR struct enc_driver_s *priv) { /* We only accept IP packets of the configured type and ARP packets */ @@ -1178,6 +1412,7 @@ static void enc_rxdispath(FAR struct enc_driver_s *priv) * None * * Assumptions: + * Interrupts are enabled but the caller holds the uIP lock. * ****************************************************************************/ @@ -1193,14 +1428,15 @@ static void enc_pktif(FAR struct enc_driver_s *priv) priv->stats.pktifs++; #endif - /* Set the read pointer to the start of the received packet */ + /* Set the read pointer to the start of the received packet (ERDPT) */ DEBUGASSERT(priv->nextpkt <= PKTMEM_RX_END); enc_wrbreg(priv, ENC_ERDPTL, (priv->nextpkt)); enc_wrbreg(priv, ENC_ERDPTH, (priv->nextpkt) >> 8); /* Read the next packet pointer and the 4 byte read status vector (RSV) - * at the beginning of the received packet + * at the beginning of the received packet. (ERDPT should auto-increment + * and wrap to the beginning of the read buffer as necessary) */ enc_rdbuffer(priv, rsv, 6); @@ -1218,7 +1454,9 @@ static void enc_pktif(FAR struct enc_driver_s *priv) priv->nextpkt = (uint16_t)rsv[1] << 8 | (uint16_t)rsv[0]; pktlen = (uint16_t)rsv[3] << 8 | (uint16_t)rsv[2]; rxstat = (uint16_t)rsv[5] << 8 | (uint16_t)rsv[4]; - nllvdbg("Receiving packet, pktlen: %d\n", pktlen); + + nllvdbg("Receiving packet, nextpkt: %04x pktlen: %d rxstat: %04x\n", + priv->nextpkt, pktlen, rxstat); /* Check if the packet was received OK */ @@ -1237,7 +1475,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) nlldbg("Bad packet size dropped (%d)\n", pktlen); #ifdef CONFIG_ENC28J60_STATS priv->stats.rxpktlen++; -#endif +#endif } /* Otherwise, read and process the packet */ @@ -1248,14 +1486,17 @@ static void enc_pktif(FAR struct enc_driver_s *priv) priv->dev.d_len = pktlen - 4; - /* Copy the data data from the receive buffer to priv->dev.d_buf */ + /* Copy the data data from the receive buffer to priv->dev.d_buf. + * ERDPT should be correctly positioned from the last call to to + * end_rdbuffer (above). + */ enc_rdbuffer(priv, priv->dev.d_buf, priv->dev.d_len); - enc_dumppacket("Received Packet", priv->ld_dev.d_buf, priv->ld_dev.d_len); + enc_dumppacket("Received Packet", priv->dev.d_buf, priv->dev.d_len); /* Dispatch the packet to uIP */ - enc_rxdispath(priv); + enc_rxdispatch(priv); } /* Move the RX read pointer to the start of the next received packet. @@ -1271,7 +1512,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) } /**************************************************************************** - * Function: enc_worker + * Function: enc_irqworker * * Description: * Perform interrupt handling logic outside of the interrupt handler (on @@ -1287,14 +1528,27 @@ static void enc_pktif(FAR struct enc_driver_s *priv) * ****************************************************************************/ -static void enc_worker(FAR void *arg) +static void enc_irqworker(FAR void *arg) { FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg; + uip_lock_t lock; uint8_t eir; DEBUGASSERT(priv); - /* Disable further interrupts by clearing the global interrup enable bit */ + /* Get exclusive access to both uIP and the SPI bus. */ + + lock = uip_lock(); + enc_lock(priv); + + /* Disable further interrupts by clearing the global interrupt enable bit. + * "After an interrupt occurs, the host controller should clear the global + * enable bit for the interrupt pin before servicing the interrupt. Clearing + * the enable bit will cause the interrupt pin to return to the non-asserted + * state (high). Doing so will prevent the host controller from missing a + * falling edge should another interrupt occur while the immediate interrupt + * is being serviced." + */ enc_bfcgreg(priv, ENC_EIE, EIE_INTIE); @@ -1306,9 +1560,12 @@ static void enc_worker(FAR void *arg) while ((eir = enc_rdgreg(priv, ENC_EIR) & EIR_ALLINTS) != 0) { /* Handle interrupts according to interrupt register register bit - * settings - * - * DMAIF: The DMA interrupt indicates that the DMA module has completed + * settings. + */ + + nllvdbg("EIR: %02x\n", eir); + + /* DMAIF: The DMA interrupt indicates that the DMA module has completed * its memory copy or checksum calculation. Additionally, this interrupt * will be caused if the host controller cancels a DMA operation by * manually clearing the DMAST bit. Once set, DMAIF can only be cleared @@ -1425,6 +1682,8 @@ static void enc_worker(FAR void *arg) uint8_t pktcnt = enc_rdbreg(priv, ENC_EPKTCNT); if (pktcnt > 0) { + nllvdbg("EPKTCNT: %02x\n", pktcnt); + #ifdef CONFIG_ENC28J60_STATS if (pktcnt > priv->stats.maxpktcnt) { @@ -1462,12 +1721,20 @@ static void enc_worker(FAR void *arg) enc_rxerif(priv); /* Handle the RX error */ enc_bfcgreg(priv, ENC_EIR, EIR_RXERIF); /* Clear the RXERIF interrupt */ } - } /* Enable Ethernet interrupts */ enc_bfsgreg(priv, ENC_EIE, EIE_INTIE); + + /* Release lock on the SPI bus and uIP */ + + enc_unlock(priv); + uip_unlock(lock); + + /* Enable GPIO interrupts */ + + priv->lower->enable(priv->lower); } /**************************************************************************** @@ -1491,17 +1758,6 @@ static int enc_interrupt(int irq, FAR void *context) { register FAR struct enc_driver_s *priv = &g_enc28j60[0]; - DEBUGASSERT(priv->irq == irq); - -#ifdef CONFIG_SPI_OWNBUS - /* In very simple environments, we own the SPI and can do data transfers - * from the interrupt handler. That is actually a very bad idea in any - * case because it keeps interrupts disabled for a long time. - */ - - enc_worker((FAR void*)priv); - return OK; -#else /* In complex environments, we cannot do SPI transfers from the interrupt * handler because semaphores are probably used to lock the SPI bus. In * this case, we will defer processing to the worker thread. This is also @@ -1509,8 +1765,71 @@ static int enc_interrupt(int irq, FAR void *context) * a good thing to do in any event. */ - return work_queue(&priv->work, enc_worker, (FAR void *)priv, 0); + DEBUGASSERT(work_available(&priv->irqwork)); + + /* Notice that further GPIO interrupts are disabled until the work is + * actually performed. This is to prevent overrun of the worker thread. + * Interrupts are re-enabled in enc_irqworker() when the work is completed. + */ + + priv->lower->disable(priv->lower); + return work_queue(HPWORK, &priv->irqwork, enc_irqworker, (FAR void *)priv, 0); +} + +/**************************************************************************** + * Function: enc_toworker + * + * Description: + * Our TX watchdog timed out. This is the worker thread continuation of + * the watchdog timer interrupt. Reset the hardware and start again. + * + * Parameters: + * arg - The reference to the driver structure (case to void*) + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void enc_toworker(FAR void *arg) +{ + FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg; + uip_lock_t lock; + int ret; + + nlldbg("Tx timeout\n"); + DEBUGASSERT(priv); + + /* Get exclusive access to both uIP and the SPI bus. */ + + lock = uip_lock(); + enc_lock(priv); + + /* Increment statistics and dump debug info */ + +#ifdef CONFIG_ENC28J60_STATS + priv->stats.txtimeouts++; #endif + + /* Then reset the hardware: Take the interface down, then bring it + * back up + */ + + ret = enc_ifdown(&priv->dev); + DEBUGASSERT(ret == OK); + ret = enc_ifup(&priv->dev); + DEBUGASSERT(ret == OK); + + /* Then poll uIP for new XMIT data */ + + (void)uip_poll(&priv->dev, enc_uiptxpoll); + + /* Release lock on the SPI bus and uIP */ + + enc_unlock(priv); + uip_unlock(lock); } /**************************************************************************** @@ -1518,7 +1837,7 @@ static int enc_interrupt(int irq, FAR void *context) * * Description: * Our TX watchdog timed out. Called from the timer interrupt handler. - * The last TX never completed. Reset the hardware and start again. + * The last TX never completed. Perform work on the worker thread. * * Parameters: * argc - The number of available arguments @@ -1536,25 +1855,76 @@ static void enc_txtimeout(int argc, uint32_t arg, ...) FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg; int ret; - /* Increment statistics and dump debug info */ - - nlldbg("Tx timeout\n"); -#ifdef CONFIG_ENC28J60_STATS - priv->stats.txtimeouts++; -#endif - - /* Then reset the hardware: Take the interface down, then bring it - * back up + /* In complex environments, we cannot do SPI transfers from the timout + * handler because semaphores are probably used to lock the SPI bus. In + * this case, we will defer processing to the worker thread. This is also + * much kinder in the use of system resources and is, therefore, probably + * a good thing to do in any event. */ - - ret = enc_ifdown(&priv->dev); - DEBUGASSERT(ret == OK); - ret = enc_ifup(&priv->dev); - DEBUGASSERT(ret == OK); - /* Then poll uIP for new XMIT data */ + DEBUGASSERT(priv && work_available(&priv->towork)); - (void)uip_poll(&priv->dev, enc_uiptxpoll); + /* Notice that Tx timeout watchdog is not active so further Tx timeouts + * can occur until we restart the Tx timeout watchdog. + */ + + ret = work_queue(HPWORK, &priv->towork, enc_toworker, (FAR void *)priv, 0); + DEBUGASSERT(ret == OK); +} + +/**************************************************************************** + * Function: enc_pollworker + * + * Description: + * Periodic timer handler continuation. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void enc_pollworker(FAR void *arg) +{ + FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg; + uip_lock_t lock; + + DEBUGASSERT(priv); + + /* Get exclusive access to both uIP and the SPI bus. */ + + lock = uip_lock(); + enc_lock(priv); + + /* Verify that the hardware is ready to send another packet. The driver + * start a transmission process by setting ECON1.TXRTS. When the packet is + * finished transmitting or is aborted due to an error/cancellation, the + * ECON1.TXRTS bit will be cleared. + */ + + if ((enc_rdgreg(priv, ENC_ECON1) & ECON1_TXRTS) == 0) + { + /* Yes.. update TCP timing states and poll uIP for new XMIT data. Hmmm.. + * looks like a bug here to me. Does this mean if there is a transmit + * in progress, we will missing TCP time state updates? + */ + + (void)uip_timer(&priv->dev, enc_uiptxpoll, ENC_POLLHSEC); + } + + /* Release lock on the SPI bus and uIP */ + + enc_unlock(priv); + uip_unlock(lock); + + /* Setup the watchdog poll timer again */ + + (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); } /**************************************************************************** @@ -1577,26 +1947,23 @@ static void enc_txtimeout(int argc, uint32_t arg, ...) static void enc_polltimer(int argc, uint32_t arg, ...) { FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg; + int ret; - /* Verify that the hardware is ready to send another packet. The driver - * start a transmission process by setting ECON1.TXRTS. When the packet is - * finished transmitting or is aborted due to an error/cancellation, the - * ECON1.TXRTS bit will be cleared. + /* In complex environments, we cannot do SPI transfers from the timout + * handler because semaphores are probably used to lock the SPI bus. In + * this case, we will defer processing to the worker thread. This is also + * much kinder in the use of system resources and is, therefore, probably + * a good thing to do in any event. */ - if ((enc_rdgreg(priv, ENC_ECON1) & ECON1_TXRTS) == 0) - { - /* Yes.. update TCP timing states and poll uIP for new XMIT data. Hmmm.. - * looks like a bug here to me. Does this mean if there is a transmit - * in progress, we will missing TCP time state updates? - */ + DEBUGASSERT(priv && work_available(&priv->pollwork)); - (void)uip_timer(&priv->dev, enc_uiptxpoll, ENC_POLLHSEC); - } + /* Notice that poll watchdog is not active so further poll timeouts can + * occur until we restart the poll timeout watchdog. + */ - /* Setup the watchdog poll timer again */ - - (void)wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, arg); + ret = work_queue(HPWORK, &priv->pollwork, enc_pollworker, (FAR void *)priv, 0); + DEBUGASSERT(ret == OK); } /**************************************************************************** @@ -1625,6 +1992,10 @@ static int enc_ifup(struct uip_driver_s *dev) dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + /* Lock the SPI bus so that we have exclusive access */ + + enc_lock(priv); + /* Initialize Ethernet interface, set the MAC address, and make sure that * the ENC28J80 is not in power save mode. */ @@ -1640,11 +2011,9 @@ static int enc_ifup(struct uip_driver_s *dev) */ enc_wrphy(priv, ENC_PHIE, PHIE_PGEIE | PHIE_PLNKIE); - enc_bfsgreg(priv, ENC_EIE, EIE_INTIE | EIE_PKTIE); - enc_bfsgreg(priv, ENC_EIR, EIR_DMAIF | EIR_LINKIF | EIR_TXIF | - EIR_TXERIF | EIR_RXERIF | EIR_PKTIF); - enc_wrgreg(priv, ENC_EIE, EIE_INTIE | EIE_PKTIE | EIE_LINKIE | - EIE_TXIE | EIE_TXERIE | EIE_RXERIE); + enc_bfcgreg(priv, ENC_EIR, EIR_ALLINTS); + enc_wrgreg(priv, ENC_EIE, EIE_INTIE | EIE_PKTIE | EIE_LINKIE | + EIE_TXIE | EIE_TXERIE | EIE_RXERIE); /* Enable the receiver */ @@ -1658,9 +2027,13 @@ static int enc_ifup(struct uip_driver_s *dev) * controller */ - priv->bifup = true; - up_enable_irq(priv->irq); + priv->ifstate = ENCSTATE_UP; + priv->lower->enable(priv->lower); } + + /* Un-lock the SPI bus */ + + enc_unlock(priv); return ret; } @@ -1687,13 +2060,17 @@ static int enc_ifdown(struct uip_driver_s *dev) int ret; nlldbg("Taking down: %d.%d.%d.%d\n", - dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + + /* Lock the SPI bus so that we have exclusive access */ + + enc_lock(priv); /* Disable the Ethernet interrupt */ flags = irqsave(); - up_disable_irq(priv->irq); + priv->lower->disable(priv->lower); /* Cancel the TX poll timer and TX timeout timers */ @@ -1705,8 +2082,12 @@ static int enc_ifdown(struct uip_driver_s *dev) ret = enc_reset(priv); enc_pwrsave(priv); - priv->bifup = false; + priv->ifstate = ENCSTATE_DOWN; irqrestore(flags); + + /* Un-lock the SPI bus */ + + enc_unlock(priv); return ret; } @@ -1734,11 +2115,14 @@ static int enc_txavail(struct uip_driver_s *dev) FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private; irqstate_t flags; - flags = irqsave(); + /* Lock the SPI bus so that we have exclusive access */ + + enc_lock(priv); /* Ignore the notification if the interface is not yet up */ - if (priv->bifup) + flags = irqsave(); + if (priv->ifstate == ENCSTATE_UP) { /* Check if the hardware is ready to send another packet. The driver * starts a transmission process by setting ECON1.TXRTS. When the packet is @@ -1754,7 +2138,10 @@ static int enc_txavail(struct uip_driver_s *dev) } } + /* Un-lock the SPI bus */ + irqrestore(flags); + enc_unlock(priv); return OK; } @@ -1781,9 +2168,17 @@ static int enc_addmac(struct uip_driver_s *dev, FAR const uint8_t *mac) { FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private; + /* Lock the SPI bus so that we have exclusive access */ + + enc_lock(priv); + /* Add the MAC address to the hardware multicast routing table */ #warning "Multicast MAC support not implemented" + + /* Un-lock the SPI bus */ + + enc_unlock(priv); return OK; } #endif @@ -1811,9 +2206,17 @@ static int enc_rmmac(struct uip_driver_s *dev, FAR const uint8_t *mac) { FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private; + /* Lock the SPI bus so that we have exclusive access */ + + enc_lock(priv); + /* Add the MAC address to the hardware multicast routing table */ #warning "Multicast MAC support not implemented" + + /* Un-lock the SPI bus */ + + enc_unlock(priv); return OK; } #endif @@ -1952,14 +2355,21 @@ static void enc_pwrfull(FAR struct enc_driver_s *priv) static void enc_setmacaddr(FAR struct enc_driver_s *priv) { - /* Program the hardware with it's MAC address (for filtering) */ + /* Program the hardware with it's MAC address (for filtering). + * MAADR1 MAC Address Byte 1 (MAADR<47:40>), OUI Byte 1 + * MAADR2 MAC Address Byte 2 (MAADR<39:32>), OUI Byte 2 + * MAADR3 MAC Address Byte 3 (MAADR<31:24>), OUI Byte 3 + * MAADR4 MAC Address Byte 4 (MAADR<23:16>) + * MAADR5 MAC Address Byte 5 (MAADR<15:8>) + * MAADR6 MAC Address Byte 6 (MAADR<7:0>) + */ - enc_wrbreg(priv, ENC_MAADR1, priv->dev.d_mac.ether_addr_octet[5]); - enc_wrbreg(priv, ENC_MAADR2, priv->dev.d_mac.ether_addr_octet[4]); - enc_wrbreg(priv, ENC_MAADR3, priv->dev.d_mac.ether_addr_octet[3]); - enc_wrbreg(priv, ENC_MAADR4, priv->dev.d_mac.ether_addr_octet[2]); - enc_wrbreg(priv, ENC_MAADR5, priv->dev.d_mac.ether_addr_octet[1]); - enc_wrbreg(priv, ENC_MAADR6, priv->dev.d_mac.ether_addr_octet[0]); + enc_wrbreg(priv, ENC_MAADR1, priv->dev.d_mac.ether_addr_octet[0]); + enc_wrbreg(priv, ENC_MAADR2, priv->dev.d_mac.ether_addr_octet[1]); + enc_wrbreg(priv, ENC_MAADR3, priv->dev.d_mac.ether_addr_octet[2]); + enc_wrbreg(priv, ENC_MAADR4, priv->dev.d_mac.ether_addr_octet[3]); + enc_wrbreg(priv, ENC_MAADR5, priv->dev.d_mac.ether_addr_octet[4]); + enc_wrbreg(priv, ENC_MAADR6, priv->dev.d_mac.ether_addr_octet[5]); } /**************************************************************************** @@ -1991,15 +2401,7 @@ static int enc_reset(FAR struct enc_driver_s *priv) /* Reset the ENC28J60 */ - enc_wrgreg(priv, ENC_SRC, ENC_SRC); - - /* Check CLKRDY bit to see when the reset is complete. There is an errata - * that says the CLKRDY may be invalid. We'll wait a couple of msec to - * workaround this condition. - */ - - up_mdelay(2); - /* while ((enc_rdgreg(priv, ENC_ESTAT) & ESTAT_CLKRDY) != 0); */ + enc_src(priv); /* Initialize ECON1: Clear ECON1 */ @@ -2045,6 +2447,7 @@ static int enc_reset(FAR struct enc_driver_s *priv) nlldbg("Bad Rev ID: %02x\n", regval); return -ENODEV; } + nllvdbg("Rev ID: %02x\n", regval); /* Set filter mode: unicast OR broadcast AND crc valid */ @@ -2079,7 +2482,7 @@ static int enc_reset(FAR struct enc_driver_s *priv) enc_wrbreg(priv, ENC_MAIPGL, 0x12); - /* Set ack-to-Back Inter-Packet Gap */ + /* Set Back-to-Back Inter-Packet Gap */ enc_wrbreg(priv, ENC_MABBIPG, 0x15); #endif @@ -2117,10 +2520,10 @@ static int enc_reset(FAR struct enc_driver_s *priv) * * Parameters: * spi - A reference to the platform's SPI driver for the ENC28J60 + * lower - The MCU-specific interrupt used to control low-level MCU + * functions (i.e., ENC28J60 GPIO interrupts). * devno - If more than one ENC28J60 is supported, then this is the * zero based number that identifies the ENC28J60; - * irq - The fully configured GPIO IRQ that ENC28J60 interrupts will be - * asserted on. This driver will attach and entable this IRQ. * * Returned Value: * OK on success; Negated errno on failure. @@ -2129,10 +2532,10 @@ static int enc_reset(FAR struct enc_driver_s *priv) * ****************************************************************************/ -int enc_initialize(FAR struct spi_dev_s *spi, unsigned int devno, unsigned int irq) +int enc_initialize(FAR struct spi_dev_s *spi, + FAR const struct enc_lower_s *lower, unsigned int devno) { - FAR struct enc_driver_s *priv ; - int ret; + FAR struct enc_driver_s *priv; DEBUGASSERT(devno < CONFIG_ENC28J60_NINTERFACES); priv = &g_enc28j60[devno]; @@ -2154,30 +2557,30 @@ int enc_initialize(FAR struct spi_dev_s *spi, unsigned int devno, unsigned int i priv->txpoll = wd_create(); /* Create periodic poll timer */ priv->txtimeout = wd_create(); /* Create TX timeout timer */ priv->spi = spi; /* Save the SPI instance */ - priv->irq = irq; /* Save the IRQ number */ + priv->lower = lower; /* Save the low-level MCU interface */ - /* Make sure that the interface is in the down state. NOTE: The MAC - * address will not be set up until ifup. That gives the app time to set - * the MAC address before bringing the interface up. + /* The interface should be in the down state. However, this function is called + * too early in initalization to perform the ENC28J60 reset in enc_ifdown. We + * are depending upon the fact that the application level logic will call enc_ifdown + * later to reset the ENC28J60. NOTE: The MAC address will not be set up until + * enc_ifup() is called. That gives the app time to set the MAC address before + * bringing the interface up. */ - ret = enc_ifdown(&priv->dev); - if (ret == OK) + priv->ifstate = ENCSTATE_UNINIT; + + /* Attach the interrupt to the driver (but don't enable it yet) */ + + if (lower->attach(lower, enc_interrupt)) { - /* Attach the IRQ to the driver (but don't enable it yet) */ + /* We could not attach the ISR to the interrupt */ - if (irq_attach(irq, enc_interrupt)) - { - /* We could not attach the ISR to the interrupt */ - - ret = -EAGAIN; - } - - /* Register the device with the OS so that socket IOCTLs can be performed */ - - (void)netdev_register(&priv->dev); + return -EAGAIN; } - return ret; + + /* Register the device with the OS so that socket IOCTLs can be performed */ + + return netdev_register(&priv->dev); } /**************************************************************************** diff --git a/nuttx/drivers/net/enc28j60.h b/nuttx/drivers/net/enc28j60.h index 408224b22d..6f7f8f4652 100644 --- a/nuttx/drivers/net/enc28j60.h +++ b/nuttx/drivers/net/enc28j60.h @@ -2,7 +2,7 @@ * drivers/net/enc28j60.h * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: * - ENC28J60 Data Sheet, Stand-Alone Ethernet Controller with SPI Interface, @@ -56,7 +56,7 @@ */ #define ENC_RCR (0x00) /* Read Control Register - * 000 | aaaaa | (Registe value returned)) */ + * 000 | aaaaa | (Register value returned)) */ #define ENC_RBM (0x3a) /* Read Buffer Memory * 001 | 11010 | (Read buffer data follows) */ #define ENC_WCR (0x40) /* Write Control Register @@ -131,10 +131,10 @@ #define ECON1_BSEL_SHIFT (0) /* Bits 0-1: Bank select */ #define ECON1_BSEL_MASK (3 << ECON1_BSEL_SHIFT) -# define ECON1_BSEL_BANK0 (0 << 0) /* Bank 0 */ -# define ECON1_BSEL_BANK1 (1 << 1) /* Bank 1 */ -# define ECON1_BSEL_BANK2 (2 << 0) /* Bank 2 */ -# define ECON1_BSEL_BANK3 (3 << 0) /* Bank 3 */ +# define ECON1_BSEL_BANK0 (0 << ECON1_BSEL_SHIFT) /* Bank 0 */ +# define ECON1_BSEL_BANK1 (1 << ECON1_BSEL_SHIFT) /* Bank 1 */ +# define ECON1_BSEL_BANK2 (2 << ECON1_BSEL_SHIFT) /* Bank 2 */ +# define ECON1_BSEL_BANK3 (3 << ECON1_BSEL_SHIFT) /* Bank 3 */ #define ECON1_RXEN (1 << 2) /* Bit 2: Receive Enable */ #define ECON1_TXRTS (1 << 3) /* Bit 3: Transmit Request to Send */ #define ECON1_CSUMEN (1 << 4) /* Bit 4: DMA Checksum Enable */ @@ -304,7 +304,7 @@ #define ENC_MAADR3 REGADDR(0x02, 3, 1) /* MAC Address Byte 3 (MAADR<31:24>), OUI Byte 3 */ #define ENC_MAADR4 REGADDR(0x03, 3, 1) /* MAC Address Byte 4 (MAADR<23:16>) */ #define ENC_MAADR1 REGADDR(0x04, 3, 1) /* MAC Address Byte 1 (MAADR<47:40>), OUI Byte 1 */ -#define ENC_MAADR2 REGADDR(0x05, 3, 1) /* MAC Address Byte 2 (MAADR<39:32>), OUI Byte */ +#define ENC_MAADR2 REGADDR(0x05, 3, 1) /* MAC Address Byte 2 (MAADR<39:32>), OUI Byte 2 */ #define ENC_EBSTSD REGADDR(0x06, 3, 0) /* Built-in Self-Test Fill Seed (EBSTSD<7:0>) */ #define ENC_EBSTCON REGADDR(0x07, 3, 0) /* Built-in Self-Test Control */ #define ENC_EBSTCSL REGADDR(0x08, 3, 0) /* Built-in Self-Test Checksum Low Byte (EBSTCS<7:0>) */ @@ -360,12 +360,12 @@ /* PHY Control Register 1 Register Bit Definitions */ -#define PHCON1_PDPXMD (1 << 8) /* Bit 8: PHY Power-Down */ +#define PHCON1_PDPXMD (1 << 8) /* Bit 8: PHY Duplex Mode */ #define PHCON1_PPWRSV (1 << 11) /* Bit 11: PHY Power-Down */ #define PHCON1_PLOOPBK (1 << 14) /* Bit 14: PHY Loopback */ #define PHCON1_PRST (1 << 15) /* Bit 15: PHY Software Reset */ -/* HY Status 1 Register Bit Definitions */ +/* PHY Status 1 Register Bit Definitions */ #define PHSTAT1_JBSTAT (1 << 1) /* Bit 1: PHY Latching Jabber Status */ #define PHSTAT1_LLSTAT (1 << 2) /* Bit 2: PHY Latching Link Status */ @@ -399,7 +399,6 @@ #define PHIR_PLNKIF (1 << 4) /* Bit 4: PHY Link Change Interrupt */ /* PHLCON Regiser Bit Definitions */ - /* Bit 0: Reserved */ #define PHLCON_STRCH (1 << 1) /* Bit 1: LED Pulse Stretching Enable */ #define PHLCON_LFRQ0 (1 << 2) /* Bit 2: LED Pulse Stretch Time Configuration */ diff --git a/nuttx/drivers/power/pm_activity.c b/nuttx/drivers/power/pm_activity.c index f52fc93ff3..d3c8a52e77 100644 --- a/nuttx/drivers/power/pm_activity.c +++ b/nuttx/drivers/power/pm_activity.c @@ -2,7 +2,7 @@ * drivers/power/pm_activity.c * * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/power/pm_update.c b/nuttx/drivers/power/pm_update.c index ae5e1f8409..4b6b58c550 100644 --- a/nuttx/drivers/power/pm_update.c +++ b/nuttx/drivers/power/pm_update.c @@ -328,7 +328,7 @@ void pm_update(int16_t accum) /* The work will be performed on the worker thread */ DEBUGASSERT(g_pmglobals.work.worker == NULL); - (void)work_queue(&g_pmglobals.work, pm_worker, (FAR void*)((intptr_t)accum), 0); + (void)work_queue(HPWORK, &g_pmglobals.work, pm_worker, (FAR void*)((intptr_t)accum), 0); } -#endif /* CONFIG_PM */ \ No newline at end of file +#endif /* CONFIG_PM */ diff --git a/nuttx/drivers/rwbuffer.c b/nuttx/drivers/rwbuffer.c index 1d924e2a05..076ebc7816 100644 --- a/nuttx/drivers/rwbuffer.c +++ b/nuttx/drivers/rwbuffer.c @@ -213,7 +213,7 @@ static void rwb_wrstarttimeout(FAR struct rwbuffer_s *rwb) */ int ticks = (CONFIG_FS_WRDELAY + CLK_TCK/2) / CLK_TCK; - (void)work_queue(&rwb->work, rwb_wrtimeout, (FAR void *)rwb, ticks); + (void)work_queue(LPWORK, &rwb->work, rwb_wrtimeout, (FAR void *)rwb, ticks); } /**************************************************************************** @@ -222,7 +222,7 @@ static void rwb_wrstarttimeout(FAR struct rwbuffer_s *rwb) static inline void rwb_wrcanceltimeout(struct rwbuffer_s *rwb) { - (void)work_cancel(&rwb->work); + (void)work_cancel(LPWORK, &rwb->work); } /**************************************************************************** diff --git a/nuttx/drivers/sensors/Make.defs b/nuttx/drivers/sensors/Make.defs index bd28ba0709..866ccb0536 100644 --- a/nuttx/drivers/sensors/Make.defs +++ b/nuttx/drivers/sensors/Make.defs @@ -2,7 +2,7 @@ # drivers/sensors/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -37,7 +37,10 @@ # These drivers depend on I2C support ifeq ($(CONFIG_I2C),y) + +ifeq ($(CONFIG_I2C_TRANSFER),y) CSRCS += lis331dl.c +endif ifeq ($(CONFIG_I2C_LM75),y) CSRCS += lm75.c diff --git a/nuttx/drivers/sensors/lm75.c b/nuttx/drivers/sensors/lm75.c index 8e1a0fb4b6..2d3346447b 100644 --- a/nuttx/drivers/sensors/lm75.c +++ b/nuttx/drivers/sensors/lm75.c @@ -3,7 +3,7 @@ * Character driver for the STMicro LM-75 Temperature Sensor * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/sercomm/Make.defs b/nuttx/drivers/sercomm/Make.defs index 3585f53146..0cf93d4c80 100644 --- a/nuttx/drivers/sercomm/Make.defs +++ b/nuttx/drivers/sercomm/Make.defs @@ -2,7 +2,7 @@ # drivers/serial/Make.defs # # Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/sercomm/README.txt b/nuttx/drivers/sercomm/README.txt old mode 100755 new mode 100644 diff --git a/nuttx/drivers/serial/Kconfig b/nuttx/drivers/serial/Kconfig index b8867bd3f7..43869fdeca 100644 --- a/nuttx/drivers/serial/Kconfig +++ b/nuttx/drivers/serial/Kconfig @@ -44,10 +44,10 @@ config 16550_UART0_BITS 16550 UART0 number of bits. Default: 8 config 16550_UART0_2STOP - bool "16550 UART0 two stop bits" - default n + int "16550 UART0 two stop bits" + default 0 ---help--- - 16550 UART0 two stop bits. Default: 1 + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit config 16550_UART0_RXBUFSIZE int "16550 UART0 Rx buffer size" @@ -94,10 +94,10 @@ config 16550_UART1_BITS 16550 UART1 number of bits. Default: 8 config 16550_UART1_2STOP - bool "16550 UART1 two stop bits" - default n + int "16550 UART1 two stop bits" + default 0 ---help--- - 16550 UART1 two stop bits. Default: 1 + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit config 16550_UART1_RXBUFSIZE int "16550 UART1 Rx buffer size" @@ -144,10 +144,10 @@ config 16550_UART2_BITS 16550 UART2 number of bits. Default: 8 config 16550_UART2_2STOP - bool "16550 UART2 two stop bits" - default n + int "16550 UART2 two stop bits" + default 0 ---help--- - 16550 UART2 two stop bits. Default: 1 + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit config 16550_UART2_RXBUFSIZE int "16550 UART2 Rx buffer size" @@ -194,10 +194,10 @@ config 16550_UART3_BITS 16550 UART3 number of bits. Default: 8 config 16550_UART3_2STOP - bool "16550 UART3 two stop bits" - default n + int "16550 UART3 two stop bits" + default 0 ---help--- - 16550 UART3 two stop bits. Default: 1 + 0=1 stop bit, 1=Two stop bits. Default: 1 stop bit config 16550_UART3_RXBUFSIZE int "16550 UART3 Rx buffer size" @@ -215,25 +215,25 @@ endif choice prompt "16550 Serial Console" - default NO_SERIAL_CONSOLE + default 16550_NO_SERIAL_CONSOLE -config UART0_SERIAL_CONSOLE +config 16550_UART0_SERIAL_CONSOLE bool "16550 UART0 serial console" depends on 16550_UART0 -config UART1_SERIAL_CONSOLE +config 16550_UART1_SERIAL_CONSOLE bool "16550 UART1 serial console" depends on 16550_UART1 -config UART2_SERIAL_CONSOLE +config 16550_UART2_SERIAL_CONSOLE bool "16550 UART2 serial console" depends on 16550_UART2 -config UART3_SERIAL_CONSOLE +config 16550_UART3_SERIAL_CONSOLE bool "16550 UART3 serial console" depends on 16550_UART3 -config NO_SERIAL_CONSOLE +config 16550_NO_SERIAL_CONSOLE bool "No 16550 serial console" endchoice @@ -267,19 +267,783 @@ config 16550_ADDRWIDTH endif -config STANDARD_SERIAL - bool "Standard serial" - default y if !LOWLEVEL_CONSOLE && !16550_UART +# +# MCU serial peripheral driver? +# + +config ARCH_HAVE_UART + bool +config ARCH_HAVE_UART0 + bool +config ARCH_HAVE_UART1 + bool +config ARCH_HAVE_UART2 + bool +config ARCH_HAVE_UART3 + bool +config ARCH_HAVE_UART4 + bool +config ARCH_HAVE_UART5 + bool +config ARCH_HAVE_UART6 + bool + +config ARCH_HAVE_USART0 + bool +config ARCH_HAVE_USART1 + bool +config ARCH_HAVE_USART2 + bool +config ARCH_HAVE_USART3 + bool +config ARCH_HAVE_USART4 + bool +config ARCH_HAVE_USART5 + bool +config ARCH_HAVE_USART6 + bool + +config MCU_SERIAL + bool + default y if ARCH_HAVE_UART || ARCH_HAVE_UART0 || ARCH_HAVE_USART0 || ARCH_HAVE_UART1 || ARCH_HAVE_USART1 || \ + ARCH_HAVE_UART2 || ARCH_HAVE_USART2 || ARCH_HAVE_UART3 || ARCH_HAVE_USART3 || \ + ARCH_HAVE_UART4 || ARCH_HAVE_USART4 || ARCH_HAVE_UART5 || ARCH_HAVE_USART5 || ARCH_HAVE_UART6 || ARCH_HAVE_USART6 + +# +# Standard serial driver configuration +# + +config STANDARD_SERIAL + bool "Enable standard \"upper-half\" serial driver" + default y if MCU_SERIAL + default n if !MCU_SERIAL + depends on !LOWLEVEL_CONSOLE + ---help--- + Enable the standard, upper-half serial driver used by most MCU serial peripherals. -if STANDARD_SERIAL config CONFIG_SERIAL_NPOLLWAITERS int "Number of poll threads" default 2 - depends on !DISABLE_POLL + depends on !DISABLE_POLL && STANDARD_SERIAL ---help--- Maximum number of threads than can be waiting for POLL events. Default: 2 -endif +# +# U[S]ARTn_XYZ settings for MCU serial drivers +# +choice + prompt "Serial console" + depends on MCU_SERIAL + default NO_SERIAL_CONSOLE +config UART_SERIAL_CONSOLE + bool "UART" + depends on ARCH_HAVE_UART + +config UART0_SERIAL_CONSOLE + bool "UART0" + depends on ARCH_HAVE_UART0 + +config USART0_SERIAL_CONSOLE + bool "USART0" + depends on ARCH_HAVE_USART0 + +config UART1_SERIAL_CONSOLE + bool "UART1" + depends on ARCH_HAVE_UART1 + +config USART1_SERIAL_CONSOLE + bool "USART1" + depends on ARCH_HAVE_USART1 + +config UART2_SERIAL_CONSOLE + bool "UART2" + depends on ARCH_HAVE_UART2 + +config USART2_SERIAL_CONSOLE + bool "USART2" + depends on ARCH_HAVE_USART2 + +config UART3_SERIAL_CONSOLE + bool "UART3" + depends on ARCH_HAVE_UART3 + +config USART3_SERIAL_CONSOLE + bool "USART3" + depends on ARCH_HAVE_USART3 + +config UART4_SERIAL_CONSOLE + bool "UART4" + depends on ARCH_HAVE_UART4 + +config USART4_SERIAL_CONSOLE + bool "USART4" + depends on ARCH_HAVE_USART4 + +config UART5_SERIAL_CONSOLE + bool "UART5" + depends on ARCH_HAVE_UART5 + +config USART5_SERIAL_CONSOLE + bool "USART5" + depends on ARCH_HAVE_USART5 + +config UART6_SERIAL_CONSOLE + bool "UART6" + depends on ARCH_HAVE_UART6 + +config USART6_SERIAL_CONSOLE + bool "USART6" + depends on ARCH_HAVE_USART6 + +config NO_SERIAL_CONSOLE + bool "No serial console" + +endchoice + +menu "UART Configuration" + depends on ARCH_HAVE_UART + +config UART_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART_2STOP + int "use 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART0 Configuration" + depends on ARCH_HAVE_UART0 + +config UART0_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART0_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART0_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART0_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART0_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART0_2STOP + int "use 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART0 Configuration" + depends on ARCH_HAVE_USART0 + +config USART0_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART0_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART0_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART0_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART0_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART0_2STOP + int "use 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART1 Configuration" + depends on ARCH_HAVE_UART1 + +config UART1_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART1_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART1_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART1_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART1_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART1_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART1 Configuration" + depends on ARCH_HAVE_USART1 + +config USART1_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART1_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART1_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART1_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART1_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART1_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART2 Configuration" + depends on ARCH_HAVE_UART2 + +config UART2_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART2_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART2_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART2_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART2_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART2_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART2 Configuration" + depends on ARCH_HAVE_USART2 + +config USART2_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART2_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART2_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART2_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART2_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART2_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART3 Configuration" + depends on ARCH_HAVE_UART3 + +config UART3_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART3_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART3_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART3_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART3_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART3_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART3 Configuration" + depends on ARCH_HAVE_USART3 + +config USART3_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART3_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART3_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART3_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART3_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART3_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART4 Configuration" + depends on ARCH_HAVE_UART4 + +config UART4_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART4_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART4_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART4_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART4_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART4_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART4 Configuration" + depends on ARCH_HAVE_USART4 + +config USART4_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART4_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART4_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART4_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART4_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART4_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART5 Configuration" + depends on ARCH_HAVE_UART5 + +config UART5_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART5_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART5_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART5_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART5_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART5_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART5 Configuration" + depends on ARCH_HAVE_USART5 + +config USART5_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART5_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART5_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART5_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART5_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART5_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "USART6 Configuration" + depends on ARCH_HAVE_USART6 + +config USART6_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config USART6_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config USART6_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the USART. + +config USART6_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config USART6_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config USART6_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu + +menu "UART6 Configuration" + depends on ARCH_HAVE_UART6 + +config UART6_RXBUFSIZE + int "receive buffer size" + default 256 + help + Characters are buffered as they are received. This specifies + the size of the receive buffer. + +config UART6_TXBUFSIZE + int "transmit buffer size" + default 256 + help + Characters are buffered before being sent. This specifies + the size of the transmit buffer. + +config UART6_BAUD + int "baud rate" + default 11520 + help + The configured BAUD of the UART. + +config UART6_BITS + int "character size" + default 8 + help + The number of bits. Must be either 7 or 8. + +config UART6_PARITY + int "parity setting" + default 0 + help + 0=no parity, 1=odd parity, 2=even parity + +config UART6_2STOP + int "uses 2 stop bits" + default 0 + help + 1=Two stop bits + +endmenu diff --git a/nuttx/drivers/serial/uart_16550.c b/nuttx/drivers/serial/uart_16550.c index ea7d944f3a..8fb71bfd23 100644 --- a/nuttx/drivers/serial/uart_16550.c +++ b/nuttx/drivers/serial/uart_16550.c @@ -128,20 +128,20 @@ struct uart_ops_s g_uart_ops = /* I/O buffers */ #ifdef CONFIG_16550_UART0 -static char g_uart0rxbuffer[CONFIG_UART0_RXBUFSIZE]; -static char g_uart0txbuffer[CONFIG_UART0_TXBUFSIZE]; +static char g_uart0rxbuffer[CONFIG_16550_UART0_RXBUFSIZE]; +static char g_uart0txbuffer[CONFIG_16550_UART0_TXBUFSIZE]; #endif #ifdef CONFIG_16550_UART1 -static char g_uart1rxbuffer[CONFIG_UART1_RXBUFSIZE]; -static char g_uart1txbuffer[CONFIG_UART1_TXBUFSIZE]; +static char g_uart1rxbuffer[CONFIG_16550_UART1_RXBUFSIZE]; +static char g_uart1txbuffer[CONFIG_16550_UART1_TXBUFSIZE]; #endif #ifdef CONFIG_16550_UART2 -static char g_uart2rxbuffer[CONFIG_UART1_RXBUFSIZE]; -static char g_uart2txbuffer[CONFIG_UART1_TXBUFSIZE]; +static char g_uart2rxbuffer[CONFIG_16550_UART2_RXBUFSIZE]; +static char g_uart2txbuffer[CONFIG_16550_UART2_TXBUFSIZE]; #endif #ifdef CONFIG_16550_UART3 -static char g_uart3rxbuffer[CONFIG_UART1_RXBUFSIZE]; -static char g_uart3txbuffer[CONFIG_UART1_TXBUFSIZE]; +static char g_uart3rxbuffer[CONFIG_16550_UART3_RXBUFSIZE]; +static char g_uart3txbuffer[CONFIG_16550_UART3_TXBUFSIZE]; #endif /* This describes the state of the LPC17xx uart0 port. */ @@ -151,16 +151,16 @@ static struct u16550_s g_uart0priv = { .uartbase = CONFIG_16550_UART0_BASE, #ifndef CONFIG_16550_SUPRESS_CONFIG - .baud = CONFIG_UART0_BAUD, + .baud = CONFIG_16550_UART0_BAUD, .uartclk = CONFIG_16550_UART0_CLOCK, #endif #ifndef CONFIG_SUPPRESS_SERIAL_INTS .irq = CONFIG_16550_UART0_IRQ, #endif #ifndef CONFIG_16550_SUPRESS_CONFIG - .parity = CONFIG_UART0_PARITY, - .bits = CONFIG_UART0_BITS, - .stopbits2 = CONFIG_UART0_2STOP, + .parity = CONFIG_16550_UART0_PARITY, + .bits = CONFIG_16550_UART0_BITS, + .stopbits2 = CONFIG_16550_UART0_2STOP, #endif }; @@ -168,12 +168,12 @@ static uart_dev_t g_uart0port = { .recv = { - .size = CONFIG_UART0_RXBUFSIZE, + .size = CONFIG_16550_UART0_RXBUFSIZE, .buffer = g_uart0rxbuffer, }, .xmit = { - .size = CONFIG_UART0_TXBUFSIZE, + .size = CONFIG_16550_UART0_TXBUFSIZE, .buffer = g_uart0txbuffer, }, .ops = &g_uart_ops, @@ -188,16 +188,16 @@ static struct u16550_s g_uart1priv = { .uartbase = CONFIG_16550_UART1_BASE, #ifndef CONFIG_16550_SUPRESS_CONFIG - .baud = CONFIG_UART1_BAUD, + .baud = CONFIG_16550_UART1_BAUD, .uartclk = CONFIG_16550_UART1_CLOCK, #endif #ifndef CONFIG_SUPPRESS_SERIAL_INTS .irq = CONFIG_16550_UART1_IRQ, #endif #ifndef CONFIG_16550_SUPRESS_CONFIG - .parity = CONFIG_UART1_PARITY, - .bits = CONFIG_UART1_BITS, - .stopbits2 = CONFIG_UART1_2STOP, + .parity = CONFIG_16550_UART1_PARITY, + .bits = CONFIG_16550_UART1_BITS, + .stopbits2 = CONFIG_16550_UART1_2STOP, #endif }; @@ -205,12 +205,12 @@ static uart_dev_t g_uart1port = { .recv = { - .size = CONFIG_UART1_RXBUFSIZE, + .size = CONFIG_16550_UART1_RXBUFSIZE, .buffer = g_uart1rxbuffer, }, .xmit = { - .size = CONFIG_UART1_TXBUFSIZE, + .size = CONFIG_16550_UART1_TXBUFSIZE, .buffer = g_uart1txbuffer, }, .ops = &g_uart_ops, @@ -225,16 +225,16 @@ static struct u16550_s g_uart2priv = { .uartbase = CONFIG_16550_UART2_BASE, #ifndef CONFIG_16550_SUPRESS_CONFIG - .baud = CONFIG_UART2_BAUD, + .baud = CONFIG_16550_UART2_BAUD, .uartclk = CONFIG_16550_UART2_CLOCK, #endif #ifndef CONFIG_SUPPRESS_SERIAL_INTS .irq = CONFIG_16550_UART2_IRQ, #endif #ifndef CONFIG_16550_SUPRESS_CONFIG - .parity = CONFIG_UART2_PARITY, - .bits = CONFIG_UART2_BITS, - .stopbits2 = CONFIG_UART2_2STOP, + .parity = CONFIG_16550_UART2_PARITY, + .bits = CONFIG_16550_UART2_BITS, + .stopbits2 = CONFIG_16550_UART2_2STOP, #endif }; @@ -242,12 +242,12 @@ static uart_dev_t g_uart2port = { .recv = { - .size = CONFIG_UART2_RXBUFSIZE, + .size = CONFIG_16550_UART2_RXBUFSIZE, .buffer = g_uart2rxbuffer, }, .xmit = { - .size = CONFIG_UART2_TXBUFSIZE, + .size = CONFIG_16550_UART2_TXBUFSIZE, .buffer = g_uart2txbuffer, }, .ops = &g_uart_ops, @@ -262,16 +262,16 @@ static struct u16550_s g_uart3priv = { .uartbase = CONFIG_16550_UART3_BASE, #ifndef CONFIG_16550_SUPRESS_CONFIG - .baud = CONFIG_UART3_BAUD, + .baud = CONFIG_16550_UART3_BAUD, .uartclk = CONFIG_16550_UART3_CLOCK, #endif #ifndef CONFIG_SUPPRESS_SERIAL_INTS .irq = CONFIG_16550_UART3_IRQ, #endif #ifndef CONFIG_16550_SUPRESS_CONFIG - .parity = CONFIG_UART3_PARITY, - .bits = CONFIG_UART3_BITS, - .stopbits2 = CONFIG_UART3_2STOP, + .parity = CONFIG_16550_UART3_PARITY, + .bits = CONFIG_16550_UART3_BITS, + .stopbits2 = CONFIG_16550_UART3_2STOP, #endif }; @@ -279,12 +279,12 @@ static uart_dev_t g_uart3port = { .recv = { - .size = CONFIG_UART3_RXBUFSIZE, + .size = CONFIG_16550_UART3_RXBUFSIZE, .buffer = g_uart3rxbuffer, }, .xmit = { - .size = CONFIG_UART3_TXBUFSIZE, + .size = CONFIG_16550_UART3_TXBUFSIZE, .buffer = g_uart3txbuffer, }, .ops = &g_uart_ops, @@ -294,7 +294,7 @@ static uart_dev_t g_uart3port = /* Which UART with be tty0/console and which tty1? tty2? tty3? */ -#if defined(CONFIG_UART0_SERIAL_CONSOLE) +#if defined(CONFIG_16550_UART0_SERIAL_CONSOLE) # define CONSOLE_DEV g_uart0port /* UART0=console */ # define TTYS0_DEV g_uart0port /* UART0=ttyS0 */ # ifdef CONFIG_16550_UART1 @@ -333,7 +333,7 @@ static uart_dev_t g_uart3port = # undef TTYS3_DEV /* No ttyS3 */ # endif # endif -#elif defined(CONFIG_UART1_SERIAL_CONSOLE) +#elif defined(CONFIG_16550_UART1_SERIAL_CONSOLE) # define CONSOLE_DEV g_uart1port /* UART1=console */ # define TTYS0_DEV g_uart1port /* UART1=ttyS0 */ # ifdef CONFIG_16550_UART @@ -372,7 +372,7 @@ static uart_dev_t g_uart3port = # undef TTYS3_DEV /* No ttyS3 */ # endif # endif -#elif defined(CONFIG_UART2_SERIAL_CONSOLE) +#elif defined(CONFIG_16550_UART2_SERIAL_CONSOLE) # define CONSOLE_DEV g_uart2port /* UART2=console */ # define TTYS0_DEV g_uart2port /* UART2=ttyS0 */ # ifdef CONFIG_16550_UART @@ -411,7 +411,7 @@ static uart_dev_t g_uart3port = # undef TTYS3_DEV /* No ttyS3 */ # endif # endif -#elif defined(CONFIG_UART3_SERIAL_CONSOLE) +#elif defined(CONFIG_16550_UART3_SERIAL_CONSOLE) # define CONSOLE_DEV g_uart3port /* UART3=console */ # define TTYS0_DEV g_uart3port /* UART3=ttyS0 */ # ifdef CONFIG_16550_UART @@ -1161,4 +1161,4 @@ int up_putc(int ch) } #endif -#endif /* CONFIG_UART_16550 */ +#endif /* CONFIG_16550_UART */ diff --git a/nuttx/drivers/usbdev/Kconfig b/nuttx/drivers/usbdev/Kconfig index 24b13f378b..70c7a04f05 100644 --- a/nuttx/drivers/usbdev/Kconfig +++ b/nuttx/drivers/usbdev/Kconfig @@ -2,12 +2,97 @@ # For a description of the syntax of this configuration file, # see misc/tools/kconfig-language.txt. # + +menu "Device Controller Driver Options" + +config USBDEV_ISOCHRONOUS + bool "Enable isochronous" + default n + ---help--- + Build in extra support for isochronous endpoints + +config USBDEV_DUALSPEED + bool "Enable high and full speed" + default n + ---help--- + Hardware handles high and full speed operation (USB 2.0) + +choice USBDEV_POWERED + prompt "Select USB device powered" + default USBDEV_SELFPOWERED + +config USBDEV_SELFPOWERED + bool "Self powered" + ---help--- + Will cause USB features to indicate that the device is self-powered + +config USBDEV_BUSPOWERED + bool "Bus powered" + ---help--- + Will cause USB features to indicate that the device is self-powered + +endchoice + +config USBDEV_MAXPOWER + int "Maximum power consumption in mA" + default 100 + depends on USBDEV_BUSPOWERED + ---help--- + Maximum power consumption in mA + +config USBDEV_DMA + bool "Enable DMA methods" + default n + ---help--- + Select this enable DMA-related methods in USB device controller driver + interface. These methods include the DMA buffer allocation methods: + allobuffer() and freebuffer(). + + The USB class driver allocates packet I/O buffers for data transfer by + calling the driver allocbuffer() and freebuffer() methods. Those methods + are only available if USBDEV_DMA is defined in the system configuration. + +config USBDEV_DMAMEMORY +bool "Board DMA Allocation Hooks" + default n + depends on USBDEV_DMA + ---help--- + The USB class driver allocates packet I/O buffers for data transfer by + calling the driver allocbuffer() and freebuffer() methods. Those methods + are only available if USBDEV_DMA is defined in the system configuration. + + If USBDEV_DMAMEMORY is also defined in the NuttX configuration, then + the driver implementations of the allocbuffer() and freebuffer() + methods may use board-specific usbdev_dma_alloc() and usbdev_dma_free(). + If USBDEV_DMA and USBDEV_DMAMEMORY are both defined, then the board- + specific logic must provide the functions usbdev_dma_alloc() and + usbdev_dma_free(): usbdev_dma_alloc() will allocate DMA-capable + memory of the specified size; usbdev_dma_free() is the corresponding + function that will be called to free the DMA-capable memory. + +config USBDEV_TRACE + bool "Enable USB tracing for debug" + default n + ---help--- + Enables USB tracing for debug + +config USBDEV_TRACE_NRECORDS + int "Number of trace entries to remember" + default 32 + depends on USBDEV_TRACE + ---help--- + Number of trace entries to remember + +endmenu + menuconfig USBDEV_COMPOSITE bool "USB composite device support" default n ---help--- Enables USB composite device support + if USBDEV_COMPOSITE + #config COMPOSITE_IAD # bool "" # default n @@ -62,59 +147,12 @@ config COMPOSITE_VERSIONNO Interface version number. endif -config USBDEV_ISOCHRONOUS - bool "Enable isochronous" - default n - ---help--- - Build in extra support for isochronous endpoints - -config USBDEV_DUALSPEED - bool "Enable high and full speed" - default n - ---help--- - Hardware handles high and full speed - operation (USB 2.0) - -choice USBDEV_POWERED - prompt "Select USB device powered" - default USBDEV_SELFPOWERED -config USBDEV_SELFPOWERED - bool "Self powerd" - ---help--- - Will cause USB features to indicate - that the device is self-powered - -config USBDEV_BUSPOWERED - bool "Bus powerd" - ---help--- - Will cause USB features to indicate - that the device is self-powered -endchoice -config USBDEV_MAXPOWER - int "Maximum power consumption in mA" - default 100 - depends on USBDEV_BUSPOWERED - ---help--- - Maximum power consumption in mA - -config USBDEV_TRACE - bool "Enable USB tracing for debug" - default n - ---help--- - Enables USB tracing for debug - -config USBDEV_TRACE_NRECORDS - int "Number of trace entries to remember" - default 32 - depends on USBDEV_TRACE - ---help--- - Number of trace entries to remember - menuconfig PL2303 bool "Emulates the Prolific PL2303 serial/USB converter" default n ---help--- This logic emulates the Prolific PL2303 serial/USB converter + if PL2303 config PL2303_EPINTIN int "Logical endpoint numbers" @@ -178,6 +216,7 @@ menuconfig CDCACM default n ---help--- Enables USB Modem (CDC ACM) support + if CDCACM config CDCACM_COMPOSITE bool "CDCACM composite support" @@ -443,6 +482,10 @@ config USBMSC_PRODUCTSTR string "Mass stroage product string" default "Mass stroage" +config USBMSC_VERSIONNO + hex "USB MSC Version Number" + default "0x399" + config USBMSC_REMOVABLE bool "Mass stroage remove able" default n diff --git a/nuttx/drivers/usbhost/Make.defs b/nuttx/drivers/usbhost/Make.defs index cc28e874d4..fd54ab53e7 100644 --- a/nuttx/drivers/usbhost/Make.defs +++ b/nuttx/drivers/usbhost/Make.defs @@ -2,7 +2,7 @@ # drivers/usbhost/Make.defs # # Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/usbhost/usbhost_enumerate.c b/nuttx/drivers/usbhost/usbhost_enumerate.c index 8e1cd80e71..26b93bf360 100644 --- a/nuttx/drivers/usbhost/usbhost_enumerate.c +++ b/nuttx/drivers/usbhost/usbhost_enumerate.c @@ -1,8 +1,8 @@ /******************************************************************************* * drivers/usbhost/usbhost_enumerate.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Authors: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -122,8 +123,8 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val) * *******************************************************************************/ -static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc, - struct usbhost_id_s *id) +static inline int usbhost_devdesc(FAR const struct usb_devdesc_s *devdesc, + FAR struct usbhost_id_s *id) { /* Clear the ID info */ @@ -131,7 +132,7 @@ static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc, /* Pick off the class ID info */ - id->base = devdesc->class; + id->base = devdesc->classid; id->subclass = devdesc->subclass; id->proto = devdesc->protocol; @@ -194,7 +195,7 @@ static inline int usbhost_configdesc(const uint8_t *configdesc, int cfglen, */ DEBUGASSERT(remaining >= sizeof(struct usb_ifdesc_s)); - id->base = ifdesc->class; + id->base = ifdesc->classid; id->subclass = ifdesc->subclass; id->proto = ifdesc->protocol; uvdbg("class:%d subclass:%d protocol:%d\n", @@ -317,7 +318,7 @@ int usbhost_enumerate(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, DEBUGASSERT(drvr && class); - /* Allocate TD buffers for use in this function. We will need two: + /* Allocate descriptor buffers for use in this function. We will need two: * One for the request and one for the data buffer. */ @@ -400,7 +401,7 @@ int usbhost_enumerate(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, udbg("ERROR: SETADDRESS DRVR_CTRLOUT returned %d\n", ret); goto errout; } - up_mdelay(2); + usleep(2*1000); /* Modify control pipe with the provided USB device address */ @@ -461,9 +462,9 @@ int usbhost_enumerate(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, goto errout; } - /* Free the TD that we were using for the request buffer. It is not needed - * further here but it may be needed by the class driver during its connection - * operations. + /* Free the descriptor buffer that we were using for the request buffer. + * It is not needed further here but it may be needed by the class driver + * during its connection operations. */ DRVR_FREE(drvr, (uint8_t*)ctrlreq); @@ -488,9 +489,9 @@ int usbhost_enumerate(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr, } } - /* Some devices may require this delay before initialization */ + /* Some devices may require some delay before initialization */ - up_mdelay(100); + usleep(100*1000); /* Parse the configuration descriptor and bind to the class instance for the * device. This needs to be the last thing done because the class driver diff --git a/nuttx/drivers/usbhost/usbhost_findclass.c b/nuttx/drivers/usbhost/usbhost_findclass.c index f08aff580e..3e38670cf8 100644 --- a/nuttx/drivers/usbhost/usbhost_findclass.c +++ b/nuttx/drivers/usbhost/usbhost_findclass.c @@ -2,7 +2,7 @@ * drivers/usbhost/usbhost_findclass.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/usbhost/usbhost_hidkbd.c b/nuttx/drivers/usbhost/usbhost_hidkbd.c index ce951e1e63..e69d68e7b2 100644 --- a/nuttx/drivers/usbhost/usbhost_hidkbd.c +++ b/nuttx/drivers/usbhost/usbhost_hidkbd.c @@ -2,7 +2,7 @@ * drivers/usbhost/usbhost_hidkbd.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -255,7 +255,9 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv); static inline uint16_t usbhost_getle16(const uint8_t *val); static inline void usbhost_putle16(uint8_t *dest, uint16_t val); static inline uint32_t usbhost_getle32(const uint8_t *val); +#if 0 /* Not used */ static void usbhost_putle32(uint8_t *dest, uint32_t val); +#endif /* Transfer descriptor memory management */ @@ -701,7 +703,7 @@ static int usbhost_kbdpoll(int argc, char *argv[]) #if defined(CONFIG_DEBUG_USB) && defined(CONFIG_DEBUG_VERBOSE) unsigned int npolls = 0; #endif - unsigned int nerrors; + unsigned int nerrors = 0; int ret; uvdbg("Started\n"); @@ -1381,6 +1383,7 @@ static inline uint32_t usbhost_getle32(const uint8_t *val) * ****************************************************************************/ +#if 0 /* Not used */ static void usbhost_putle32(uint8_t *dest, uint32_t val) { /* Little endian means LS halfword first in byte stream */ @@ -1388,6 +1391,7 @@ static void usbhost_putle32(uint8_t *dest, uint32_t val) usbhost_putle16(dest, (uint16_t)(val & 0xffff)); usbhost_putle16(dest+2, (uint16_t)(val >> 16)); } +#endif /**************************************************************************** * Name: usbhost_tdalloc @@ -1670,7 +1674,7 @@ static int usbhost_disconnected(struct usbhost_class_s *class) */ DEBUGASSERT(priv->work.worker == NULL); - (void)work_queue(&priv->work, usbhost_destroy, priv, 0); + (void)work_queue(HPWORK, &priv->work, usbhost_destroy, priv, 0); } return OK; diff --git a/nuttx/drivers/usbhost/usbhost_registerclass.c b/nuttx/drivers/usbhost/usbhost_registerclass.c index 76ef511af8..f4d1b64afb 100644 --- a/nuttx/drivers/usbhost/usbhost_registerclass.c +++ b/nuttx/drivers/usbhost/usbhost_registerclass.c @@ -2,7 +2,7 @@ * drivers/usbhost/usbhost_registerclass.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/usbhost/usbhost_registry.c b/nuttx/drivers/usbhost/usbhost_registry.c index 56c03e2dc5..fb2e900e26 100644 --- a/nuttx/drivers/usbhost/usbhost_registry.c +++ b/nuttx/drivers/usbhost/usbhost_registry.c @@ -2,7 +2,7 @@ * drivers/usbhost/usbhost_registry.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/usbhost/usbhost_registry.h b/nuttx/drivers/usbhost/usbhost_registry.h index 63436af5d6..759a1c66e7 100644 --- a/nuttx/drivers/usbhost/usbhost_registry.h +++ b/nuttx/drivers/usbhost/usbhost_registry.h @@ -2,7 +2,7 @@ * drivers/usbhost/usbdev_registry.h * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/usbhost/usbhost_skeleton.c b/nuttx/drivers/usbhost/usbhost_skeleton.c index 0a88a4f1ba..c44a265e80 100644 --- a/nuttx/drivers/usbhost/usbhost_skeleton.c +++ b/nuttx/drivers/usbhost/usbhost_skeleton.c @@ -1,8 +1,8 @@ /**************************************************************************** * drivers/usbhost/usbhost_skeleton.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -1015,7 +1015,7 @@ static int usbhost_disconnected(struct usbhost_class_s *class) uvdbg("Queuing destruction: worker %p->%p\n", priv->work.worker, usbhost_destroy); DEBUGASSERT(priv->work.worker == NULL); - (void)work_queue(&priv->work, usbhost_destroy, priv, 0); + (void)work_queue(HPWORK, &priv->work, usbhost_destroy, priv, 0); } else { diff --git a/nuttx/drivers/usbhost/usbhost_storage.c b/nuttx/drivers/usbhost/usbhost_storage.c index 2817c24462..2b14676d71 100644 --- a/nuttx/drivers/usbhost/usbhost_storage.c +++ b/nuttx/drivers/usbhost/usbhost_storage.c @@ -1,8 +1,8 @@ /**************************************************************************** * drivers/usbhost/usbhost_storage.c * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2010-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -123,7 +124,7 @@ struct usbhost_state_s struct usbhost_driver_s *drvr; /* The remainder of the fields are provide to the mass storage class */ - + char sdchar; /* Character identifying the /dev/sd[n] device */ volatile bool disconnected; /* TRUE: Device has been disconnected */ uint8_t ifno; /* Interface number */ @@ -217,7 +218,7 @@ static inline int usbhost_tfree(FAR struct usbhost_state_s *priv); static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *priv); /* struct usbhost_registry_s methods */ - + static struct usbhost_class_s *usbhost_create(FAR struct usbhost_driver_s *drvr, FAR const struct usbhost_id_s *id); @@ -248,7 +249,7 @@ static int usbhost_ioctl(FAR struct inode *inode, int cmd, * Private Data ****************************************************************************/ -/* This structure provides the registry entry ID informatino that will be +/* This structure provides the registry entry ID informatino that will be * used to associate the USB host mass storage class to a connected USB * device. */ @@ -416,7 +417,7 @@ static inline void usbhost_freeclass(FAR struct usbhost_state_s *class) flags = irqsave(); class->class.flink = g_freelist; g_freelist = class; - irqrestore(flags); + irqrestore(flags); } #else static inline void usbhost_freeclass(FAR struct usbhost_state_s *class) @@ -700,16 +701,16 @@ static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv) int result; /* Initialize a CBW (re-using the allocated transfer buffer) */ - + cbw = usbhost_cbwalloc(priv); if (!cbw) { udbg("ERROR: Failed to create CBW\n"); return -ENOMEM; } - + /* Construct and send the CBW */ - + usbhost_testunitreadycbw(cbw); result = DRVR_TRANSFER(priv->drvr, priv->bulkout, (uint8_t*)cbw, USBMSC_CBW_SIZEOF); @@ -724,6 +725,7 @@ static inline int usbhost_testunitready(FAR struct usbhost_state_s *priv) usbhost_dumpcsw((FAR struct usbmsc_csw_s *)priv->tbuffer); } } + return result; } @@ -733,7 +735,7 @@ static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv) int result; /* Initialize a CBW (re-using the allocated transfer buffer) */ - + cbw = usbhost_cbwalloc(priv); if (!cbw) { @@ -742,7 +744,7 @@ static inline int usbhost_requestsense(FAR struct usbhost_state_s *priv) } /* Construct and send the CBW */ - + usbhost_requestsensecbw(cbw); result = DRVR_TRANSFER(priv->drvr, priv->bulkout, (uint8_t*)cbw, USBMSC_CBW_SIZEOF); @@ -775,7 +777,7 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv) int result; /* Initialize a CBW (re-using the allocated transfer buffer) */ - + cbw = usbhost_cbwalloc(priv); if (!cbw) { @@ -784,7 +786,7 @@ static inline int usbhost_readcapacity(FAR struct usbhost_state_s *priv) } /* Construct and send the CBW */ - + usbhost_readcapacitycbw(cbw); result = DRVR_TRANSFER(priv->drvr, priv->bulkout, (uint8_t*)cbw, USBMSC_CBW_SIZEOF); @@ -823,7 +825,7 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv) int result; /* Initialize a CBW (re-using the allocated transfer buffer) */ - + cbw = usbhost_cbwalloc(priv); if (!cbw) { @@ -832,7 +834,7 @@ static inline int usbhost_inquiry(FAR struct usbhost_state_s *priv) } /* Construct and send the CBW */ - + usbhost_inquirycbw(cbw); result = DRVR_TRANSFER(priv->drvr, priv->bulkout, (uint8_t*)cbw, USBMSC_CBW_SIZEOF); @@ -885,7 +887,7 @@ static void usbhost_destroy(FAR void *arg) DEBUGASSERT(priv != NULL); uvdbg("crefs: %d\n", priv->crefs); - + /* Unregister the block driver */ usbhost_mkdevname(priv, devname); @@ -965,10 +967,10 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, uint8_t found = 0; int ret; - DEBUGASSERT(priv != NULL && + DEBUGASSERT(priv != NULL && configdesc != NULL && desclen >= sizeof(struct usb_cfgdesc_s)); - + /* Verify that we were passed a configuration descriptor */ cfgdesc = (FAR struct usb_cfgdesc_s *)configdesc; @@ -1004,7 +1006,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, case USB_DESC_TYPE_INTERFACE: { FAR struct usb_ifdesc_s *ifdesc = (FAR struct usb_ifdesc_s *)configdesc; - + uvdbg("Interface descriptor\n"); DEBUGASSERT(remaining >= USB_SIZEOF_IFDESC); @@ -1078,7 +1080,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, found |= USBHOST_BINFOUND; /* Save the bulk IN endpoint information */ - + bindesc.addr = epdesc->addr & USB_EP_ADDR_NUMBER_MASK; bindesc.in = 1; bindesc.funcaddr = funcaddr; @@ -1108,7 +1110,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, } /* Increment the address of the next descriptor */ - + configdesc += desc->len; remaining -= desc->len; } @@ -1116,7 +1118,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv, /* Sanity checking... did we find all of things that we need? Hmmm.. I wonder.. * can we work read-only or write-only if only one bulk endpoint found? */ - + if (found != USBHOST_ALLFOUND) { ulldbg("ERROR: Found IF:%s BIN:%s BOUT:%s\n", @@ -1195,14 +1197,16 @@ static inline int usbhost_initvolume(FAR struct usbhost_state_s *priv) uvdbg("Get max LUN\n"); ret = usbhost_maxlunreq(priv); - /* Wait for the unit to be ready */ - - for (retries = 0; retries < USBHOST_MAX_RETRIES && ret == OK; retries++) + for (retries = 0; retries < USBHOST_MAX_RETRIES /* && ret == OK */; retries++) { uvdbg("Test unit ready, retries=%d\n", retries); - /* Send TESTUNITREADY to see the unit is ready */ - + /* Wait just a bit */ + + usleep(50*1000); + + /* Send TESTUNITREADY to see if the unit is ready */ + ret = usbhost_testunitready(priv); if (ret == OK) { @@ -1585,7 +1589,7 @@ static FAR struct usbmsc_cbw_s *usbhost_cbwalloc(FAR struct usbhost_state_s *pri * Name: usbhost_create * * Description: - * This function implements the create() method of struct usbhost_registry_s. + * This function implements the create() method of struct usbhost_registry_s. * The create() method is a callback into the class implementation. It is * used to (1) create a new instance of the USB host class state and to (2) * bind a USB host driver "session" to the class instance. Use of this @@ -1644,9 +1648,9 @@ static FAR struct usbhost_class_s *usbhost_create(FAR struct usbhost_driver_s *d priv->drvr = drvr; /* NOTE: We do not yet know the geometry of the USB mass storage device */ - + /* Return the instance of the USB mass storage class */ - + return &priv->class; } } @@ -1701,7 +1705,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *class, FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)class; int ret; - DEBUGASSERT(priv != NULL && + DEBUGASSERT(priv != NULL && configdesc != NULL && desclen >= sizeof(struct usb_cfgdesc_s)); @@ -1722,7 +1726,7 @@ static int usbhost_connect(FAR struct usbhost_class_s *class, udbg("usbhost_initvolume() failed: %d\n", ret); } } - + return ret; } @@ -1782,7 +1786,7 @@ static int usbhost_disconnected(struct usbhost_class_s *class) uvdbg("Queuing destruction: worker %p->%p\n", priv->work.worker, usbhost_destroy); DEBUGASSERT(priv->work.worker == NULL); - (void)work_queue(&priv->work, usbhost_destroy, priv, 0); + (void)work_queue(HPWORK, &priv->work, usbhost_destroy, priv, 0); } else { @@ -1792,7 +1796,7 @@ static int usbhost_disconnected(struct usbhost_class_s *class) } } - irqrestore(flags); + irqrestore(flags); return OK; } @@ -1945,45 +1949,52 @@ static ssize_t usbhost_read(FAR struct inode *inode, unsigned char *buffer, ret = -ENOMEM; /* Initialize a CBW (re-using the allocated transfer buffer) */ - + cbw = usbhost_cbwalloc(priv); if (cbw) { - /* Assume some device failure */ + /* Loop in the event that EAGAIN is returned (mean that the + * transaction was NAKed and we should try again. + */ - ret = -ENODEV; - - /* Construct and send the CBW */ - - usbhost_readcbw(startsector, priv->blocksize, nsectors, cbw); - result = DRVR_TRANSFER(priv->drvr, priv->bulkout, - (uint8_t*)cbw, USBMSC_CBW_SIZEOF); - if (result == OK) + do { - /* Receive the user data */ + /* Assume some device failure */ - result = DRVR_TRANSFER(priv->drvr, priv->bulkin, - buffer, priv->blocksize * nsectors); + ret = -ENODEV; + + /* Construct and send the CBW */ + + usbhost_readcbw(startsector, priv->blocksize, nsectors, cbw); + result = DRVR_TRANSFER(priv->drvr, priv->bulkout, + (uint8_t*)cbw, USBMSC_CBW_SIZEOF); if (result == OK) { - /* Receive the CSW */ + /* Receive the user data */ result = DRVR_TRANSFER(priv->drvr, priv->bulkin, - priv->tbuffer, USBMSC_CSW_SIZEOF); + buffer, priv->blocksize * nsectors); if (result == OK) { - FAR struct usbmsc_csw_s *csw; + /* Receive the CSW */ - /* Check the CSW status */ - - csw = (FAR struct usbmsc_csw_s *)priv->tbuffer; - if (csw->status == 0) + result = DRVR_TRANSFER(priv->drvr, priv->bulkin, + priv->tbuffer, USBMSC_CSW_SIZEOF); + if (result == OK) { - ret = nsectors; + FAR struct usbmsc_csw_s *csw; + + /* Check the CSW status */ + + csw = (FAR struct usbmsc_csw_s *)priv->tbuffer; + if (csw->status == 0) + { + ret = nsectors; + } } } } - } + } while (result == -EAGAIN); } usbhost_givesem(&priv->exclsem); @@ -2037,7 +2048,7 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe ret = -ENOMEM; /* Initialize a CBW (re-using the allocated transfer buffer) */ - + cbw = usbhost_cbwalloc(priv); if (cbw) { @@ -2046,7 +2057,7 @@ static ssize_t usbhost_write(FAR struct inode *inode, const unsigned char *buffe ret = -ENODEV; /* Construct and send the CBW */ - + usbhost_writecbw(startsector, priv->blocksize, nsectors, cbw); result = DRVR_TRANSFER(priv->drvr, priv->bulkout, (uint8_t*)cbw, USBMSC_CBW_SIZEOF); diff --git a/nuttx/drivers/wireless/Make.defs b/nuttx/drivers/wireless/Make.defs index ac73c8d85e..f47f7666a5 100644 --- a/nuttx/drivers/wireless/Make.defs +++ b/nuttx/drivers/wireless/Make.defs @@ -2,7 +2,7 @@ # drivers/wireless/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/drivers/wireless/cc1101/cc1101.c b/nuttx/drivers/wireless/cc1101/cc1101.c old mode 100755 new mode 100644 diff --git a/nuttx/fs/fat/Kconfig b/nuttx/fs/fat/Kconfig index 30983799d7..1de613ce4b 100644 --- a/nuttx/fs/fat/Kconfig +++ b/nuttx/fs/fat/Kconfig @@ -11,12 +11,6 @@ config FS_FAT Enable FAT filesystem support if FS_FAT -config FAT_SECTORSIZE - int "FAT sector size" - default 512 - ---help--- - Max supported sector size - config FAT_LCNAMES bool "FAT upper/lower names" default n @@ -47,9 +41,26 @@ config FAT_MAXFNAME config FS_FATTIME bool "FAT timestamps" default n - ---help--- + ---help--- Support FAT date and time. NOTE: There is not much sense in supporting FAT date and time unless you have a hardware RTC or other way to get the time and date. +config FAT_DMAMEMORY + bool "DMA memory allocator" + default n + ---help--- + The FAT file system allocates two I/O buffers for data transfer, each + are the size of one device sector. One of the buffers is allocated + once for each FAT volume that is mounted; the other buffers are + allocated each time a FAT file is opened. + + Some hardware, however, may require special DMA-capable memory in + order to perform the the transfers. If FAT_DMAMEMORY is defined + then the architecture-specific hardware must provide the funtions + fat_dma_alloc() and fat_dma_free(): fat_dmalloc() will allocate + DMA-capable memory of the specified size; fat_dmafree() is the + corresponding function that will be called to free the DMA-capable + memory. + endif diff --git a/nuttx/fs/fat/Make.defs b/nuttx/fs/fat/Make.defs index 96be439614..136302b86f 100644 --- a/nuttx/fs/fat/Make.defs +++ b/nuttx/fs/fat/Make.defs @@ -2,7 +2,7 @@ # Make.defs # # Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/fs/fat/fs_configfat.c b/nuttx/fs/fat/fs_configfat.c index 3a55a5215c..2075caa9fa 100644 --- a/nuttx/fs/fat/fs_configfat.c +++ b/nuttx/fs/fat/fs_configfat.c @@ -2,7 +2,7 @@ * fs/fat/fs_configfat.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index 7b7ce1f5f7..0c28cea678 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -302,7 +302,7 @@ static int fat_open(FAR struct file *filep, const char *relpath, /* Create a file buffer to support partial sector accesses */ - ff->ff_buffer = (uint8_t*)kmalloc(fs->fs_hwsectorsize); + ff->ff_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize); if (!ff->ff_buffer) { ret = -ENOMEM; @@ -405,7 +405,7 @@ static int fat_close(FAR struct file *filep) if (ff->ff_buffer) { - kfree(ff->ff_buffer); + fat_io_free(ff->ff_buffer, fs->fs_hwsectorsize); } /* Then free the file structure itself. */ @@ -1651,8 +1651,9 @@ static int fat_unbind(void *handle, FAR struct inode **blkdriver) if (fs->fs_buffer) { - kfree(fs->fs_buffer); + fat_io_free(fs->fs_buffer, fs->fs_hwsectorsize); } + kfree(fs); } diff --git a/nuttx/fs/fat/fs_fat32.h b/nuttx/fs/fat/fs_fat32.h index 5b82ff7016..71a21333ba 100644 --- a/nuttx/fs/fat/fs_fat32.h +++ b/nuttx/fs/fat/fs_fat32.h @@ -48,6 +48,7 @@ #include #include +#include #include /**************************************************************************** @@ -676,6 +677,33 @@ #endif +/**************************************************************************** + * Name: fat_io_alloc and fat_io_free + * + * Description: + * The FAT file system allocates two I/O buffers for data transfer, each + * are the size of one device sector. One of the buffers is allocated + * once for each FAT volume that is mounted; the other buffers are + * allocated each time a FAT file is opened. + * + * Some hardware, however, may require special DMA-capable memory in + * order to perform the the transfers. If CONFIG_FAT_DMAMEMORY is defined + * then the architecture-specific hardware must provide the funtions + * fat_dma_alloc() and fat_dma_free() as prototyped below: fat_dmalloc() + * will allocate DMA-capable memory of the specified size; fat_dmafree() + * is the corresponding function that will be called to free the DMA- + * capable memory. + * + ****************************************************************************/ + +#ifdef CONFIG_FAT_DMAMEMORY +# define fat_io_alloc(s) fat_dma_alloc(s) +# define fat_io_free(m,s) fat_dma_free(m,s) +#else +# define fat_io_alloc(s) kmalloc(s) +# define fat_io_free(m,s) kfree(m) +#endif + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/nuttx/fs/fat/fs_fat32dirent.c b/nuttx/fs/fat/fs_fat32dirent.c index 742fa1eeb3..18cf678479 100644 --- a/nuttx/fs/fat/fs_fat32dirent.c +++ b/nuttx/fs/fat/fs_fat32dirent.c @@ -2,7 +2,7 @@ * fs/fat/fs_fat32dirent.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c index 397467c417..7231456d74 100644 --- a/nuttx/fs/fat/fs_fat32util.c +++ b/nuttx/fs/fat/fs_fat32util.c @@ -542,7 +542,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) /* Allocate a buffer to hold one hardware sector */ - fs->fs_buffer = (uint8_t*)kmalloc(fs->fs_hwsectorsize); + fs->fs_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize); if (!fs->fs_buffer) { ret = -ENOMEM; @@ -668,7 +668,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) return OK; errout_with_buffer: - kfree(fs->fs_buffer); + fat_io_free(fs->fs_buffer, fs->fs_hwsectorsize); fs->fs_buffer = 0; errout: fs->fs_mounted = false; @@ -1563,7 +1563,7 @@ int fat_ffcacheflush(struct fat_mountpt_s *fs, struct fat_file_s *ff) */ if (ff->ff_cachesector && - ff->ff_bflags && (FFBUFF_DIRTY|FFBUFF_VALID) == (FFBUFF_DIRTY|FFBUFF_VALID)) + (ff->ff_bflags & (FFBUFF_DIRTY|FFBUFF_VALID)) == (FFBUFF_DIRTY|FFBUFF_VALID)) { /* Write the dirty sector */ diff --git a/nuttx/fs/fat/fs_mkfatfs.c b/nuttx/fs/fat/fs_mkfatfs.c index 7a8b2ab921..384aa93567 100644 --- a/nuttx/fs/fat/fs_mkfatfs.c +++ b/nuttx/fs/fat/fs_mkfatfs.c @@ -2,7 +2,7 @@ * fs/fat/fs_writefat.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/fat/fs_mkfatfs.h b/nuttx/fs/fat/fs_mkfatfs.h index 214697c519..05801c92d7 100644 --- a/nuttx/fs/fat/fs_mkfatfs.h +++ b/nuttx/fs/fat/fs_mkfatfs.h @@ -2,7 +2,7 @@ * fs/fat/fs_mkfat.h * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/fat/fs_writefat.c b/nuttx/fs/fat/fs_writefat.c index 02d55d6258..564be5b50c 100644 --- a/nuttx/fs/fat/fs_writefat.c +++ b/nuttx/fs/fat/fs_writefat.c @@ -2,7 +2,7 @@ * fs/fat/fs_writefat.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c index ee6440bf5f..fd6aa88a8f 100644 --- a/nuttx/fs/fs_fdopen.c +++ b/nuttx/fs/fs_fdopen.c @@ -220,7 +220,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb) /* Allocate the IO buffer */ stream->fs_bufstart = kmalloc(CONFIG_STDIO_BUFFER_SIZE); - if (!stream) + if (!stream->fs_bufstart) { err = ENOMEM; goto errout_with_sem; diff --git a/nuttx/fs/mmap/Make.defs b/nuttx/fs/mmap/Make.defs index 2d3d006949..59857fe9c4 100644 --- a/nuttx/fs/mmap/Make.defs +++ b/nuttx/fs/mmap/Make.defs @@ -2,7 +2,7 @@ # fs/mmap/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/fs/mmap/README.txt b/nuttx/fs/mmap/README.txt old mode 100755 new mode 100644 diff --git a/nuttx/fs/mmap/fs_mmap.c b/nuttx/fs/mmap/fs_mmap.c index 5764b16f1d..85d796586a 100644 --- a/nuttx/fs/mmap/fs_mmap.c +++ b/nuttx/fs/mmap/fs_mmap.c @@ -2,7 +2,7 @@ * fs/mmap/fs_mmap.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/mmap/fs_munmap.c b/nuttx/fs/mmap/fs_munmap.c index a4b9dc6091..5d9416d454 100644 --- a/nuttx/fs/mmap/fs_munmap.c +++ b/nuttx/fs/mmap/fs_munmap.c @@ -2,7 +2,7 @@ * fs/mmap/fs_munmap.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/mmap/fs_rammap.c b/nuttx/fs/mmap/fs_rammap.c index 0eaf313b59..f43541cc9b 100644 --- a/nuttx/fs/mmap/fs_rammap.c +++ b/nuttx/fs/mmap/fs_rammap.c @@ -2,7 +2,7 @@ * fs/mmap/fs_rammmap.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -165,7 +165,7 @@ FAR void *rammap(int fd, size_t length, off_t offset) */ fdbg("Seek to position %d failed\n", (int)offset); - err = ENOMEM; + err = EINVAL; goto errout_with_region; } @@ -181,28 +181,35 @@ FAR void *rammap(int fd, size_t length, off_t offset) * signal. */ - if (nread != EINTR) + err = get_errno(); + if (err != EINTR) { /* All other read errors are bad. errno is already set. - * (but maybe should be forced to EINVAL?) + * (but maybe should be forced to EINVAL?). NOTE that if + * FS DEBUG is enabled, then the following fdbg() macro will + * destroy the errno value. */ - fdbg("Read failed: %d\n", (int)offset); + fdbg("Read failed: offset=%d errno=%d\n", (int)offset, err); +#ifdef CONFIG_DEBUG_FS + goto errout_with_region; +#else goto errout_with_errno; +#endif } - - /* Check for end of file. */ - - if (nread == 0) - { - break; - } - - /* Increment number of bytes read */ - - rdbuffer += nread; - length -= nread; } + + /* Check for end of file. */ + + if (nread == 0) + { + break; + } + + /* Increment number of bytes read */ + + rdbuffer += nread; + length -= nread; } /* Zero any memory beyond the amount read from the file */ @@ -227,7 +234,7 @@ FAR void *rammap(int fd, size_t length, off_t offset) errout_with_region: kfree(alloc); errout: - errno = err; + set_errno(err); return MAP_FAILED; errout_with_errno: diff --git a/nuttx/fs/mmap/fs_rammap.h b/nuttx/fs/mmap/fs_rammap.h index 9076d73432..293a91ffb1 100644 --- a/nuttx/fs/mmap/fs_rammap.h +++ b/nuttx/fs/mmap/fs_rammap.h @@ -2,7 +2,7 @@ * fs/mmap/rammap.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nfs/nfs_util.c b/nuttx/fs/nfs/nfs_util.c index 33c5f0a899..73fda72a7d 100644 --- a/nuttx/fs/nfs/nfs_util.c +++ b/nuttx/fs/nfs/nfs_util.c @@ -2,7 +2,7 @@ * fs/nfs/nfs_util.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/fs/nxffs/Make.defs b/nuttx/fs/nxffs/Make.defs index a73950c3f6..b67ae4472d 100644 --- a/nuttx/fs/nxffs/Make.defs +++ b/nuttx/fs/nxffs/Make.defs @@ -2,7 +2,7 @@ # fs/nxffs/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/fs/nxffs/README.txt b/nuttx/fs/nxffs/README.txt old mode 100755 new mode 100644 index a257351107..a10fb97a54 --- a/nuttx/fs/nxffs/README.txt +++ b/nuttx/fs/nxffs/README.txt @@ -154,7 +154,7 @@ Things to Do - The file name is always extracted and held in allocated, variable-length memory. The file name is not used during reading and eliminating the file name in the entry structure would improve performance. -- There is a big inefficient in reading. On each read, the logic searches +- There is a big inefficiency in reading. On each read, the logic searches for the read position from the beginning of the file each time. This may be necessary whenever an lseek() is done, but not in general. Read performance could be improved by keeping FLASH offset and read positional @@ -168,4 +168,13 @@ Things to Do FLASH. As the file system becomes more filled with fixed files at the front of the device, the level of wear on the blocks at the end of the FLASH increases. +- When the time comes to reorganization the FLASH, the system may be + inavailable for a long time. That is a bad behavior. What is needed, + I think, is a garbage collection task that runs periodically so that + when the big reorganizaiton event occurs, most of the work is already + done. That garbarge collection should search for valid blocks that no + longer contain valid data. It should pre-erase them, put them in + a good but empty state... all ready for file system re-organization. + + diff --git a/nuttx/fs/nxffs/nxffs_block.c b/nuttx/fs/nxffs/nxffs_block.c index a069048b89..6701b6e6be 100644 --- a/nuttx/fs/nxffs/nxffs_block.c +++ b/nuttx/fs/nxffs/nxffs_block.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_block.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_blockstats.c b/nuttx/fs/nxffs/nxffs_blockstats.c index 590aa2ad03..348374e670 100644 --- a/nuttx/fs/nxffs/nxffs_blockstats.c +++ b/nuttx/fs/nxffs/nxffs_blockstats.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_blockstats.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_cache.c b/nuttx/fs/nxffs/nxffs_cache.c index 5c5cbaa187..0cc97980ea 100644 --- a/nuttx/fs/nxffs/nxffs_cache.c +++ b/nuttx/fs/nxffs/nxffs_cache.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_cache.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_dirent.c b/nuttx/fs/nxffs/nxffs_dirent.c index 562a5320b9..221549438f 100644 --- a/nuttx/fs/nxffs/nxffs_dirent.c +++ b/nuttx/fs/nxffs/nxffs_dirent.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_dirent.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_dump.c b/nuttx/fs/nxffs/nxffs_dump.c index d816ba6ca9..6a89aaf1da 100644 --- a/nuttx/fs/nxffs/nxffs_dump.c +++ b/nuttx/fs/nxffs/nxffs_dump.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_dump.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_ioctl.c b/nuttx/fs/nxffs/nxffs_ioctl.c index 41fabfbeef..332878eb0c 100644 --- a/nuttx/fs/nxffs/nxffs_ioctl.c +++ b/nuttx/fs/nxffs/nxffs_ioctl.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_ioctl.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_open.c b/nuttx/fs/nxffs/nxffs_open.c index 339e25edc7..eb7817c57e 100644 --- a/nuttx/fs/nxffs/nxffs_open.c +++ b/nuttx/fs/nxffs/nxffs_open.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_open.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_read.c b/nuttx/fs/nxffs/nxffs_read.c index 6ba49ca72f..b638dbfd4f 100644 --- a/nuttx/fs/nxffs/nxffs_read.c +++ b/nuttx/fs/nxffs/nxffs_read.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_read.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_reformat.c b/nuttx/fs/nxffs/nxffs_reformat.c index cb10862ff0..d3c00893d1 100644 --- a/nuttx/fs/nxffs/nxffs_reformat.c +++ b/nuttx/fs/nxffs/nxffs_reformat.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_reformat.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_stat.c b/nuttx/fs/nxffs/nxffs_stat.c index afb18093ca..d4d58a72c9 100644 --- a/nuttx/fs/nxffs/nxffs_stat.c +++ b/nuttx/fs/nxffs/nxffs_stat.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_stat.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_unlink.c b/nuttx/fs/nxffs/nxffs_unlink.c index 9d0d5b49e3..73b0f360a3 100644 --- a/nuttx/fs/nxffs/nxffs_unlink.c +++ b/nuttx/fs/nxffs/nxffs_unlink.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_unlink.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/nxffs/nxffs_util.c b/nuttx/fs/nxffs/nxffs_util.c index ea2e97967e..f424e71e07 100644 --- a/nuttx/fs/nxffs/nxffs_util.c +++ b/nuttx/fs/nxffs/nxffs_util.c @@ -2,7 +2,7 @@ * fs/nxffs/nxffs_util.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/romfs/Make.defs b/nuttx/fs/romfs/Make.defs index 56b4c9862a..77de93c054 100644 --- a/nuttx/fs/romfs/Make.defs +++ b/nuttx/fs/romfs/Make.defs @@ -2,7 +2,7 @@ # fs/romfs/Make.defs # # Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/fs/romfs/fs_romfs.c b/nuttx/fs/romfs/fs_romfs.c index 8a2e696654..b95619d759 100644 --- a/nuttx/fs/romfs/fs_romfs.c +++ b/nuttx/fs/romfs/fs_romfs.c @@ -2,7 +2,7 @@ * rm/romfs/fs_romfs.h * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/romfs/fs_romfs.h b/nuttx/fs/romfs/fs_romfs.h index f89196ff7a..4081517fb8 100644 --- a/nuttx/fs/romfs/fs_romfs.h +++ b/nuttx/fs/romfs/fs_romfs.h @@ -2,7 +2,7 @@ * fs/romfs/fs_romfs.h * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * diff --git a/nuttx/fs/romfs/fs_romfsutil.c b/nuttx/fs/romfs/fs_romfsutil.c index ec009da89d..6ea114b5e1 100644 --- a/nuttx/fs/romfs/fs_romfsutil.c +++ b/nuttx/fs/romfs/fs_romfsutil.c @@ -2,7 +2,7 @@ * rm/romfs/fs_romfsutil.h * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * References: Linux/Documentation/filesystems/romfs.txt * @@ -351,7 +351,7 @@ static inline int romfs_searchdir(struct romfs_mountpt_s *rm, } while (next != 0); - /* There is nothing in this directoy with that name */ + /* There is nothing in this directory with that name */ return -ENOENT; } diff --git a/nuttx/graphics/nxbe/nxbe_clipper.c b/nuttx/graphics/nxbe/nxbe_clipper.c index 580c8bc4c8..cdbd421c05 100644 --- a/nuttx/graphics/nxbe/nxbe_clipper.c +++ b/nuttx/graphics/nxbe/nxbe_clipper.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_clipper.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_closewindow.c b/nuttx/graphics/nxbe/nxbe_closewindow.c index 3c583fcfbf..e632ebf011 100644 --- a/nuttx/graphics/nxbe/nxbe_closewindow.c +++ b/nuttx/graphics/nxbe/nxbe_closewindow.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_closewindow.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_colormap.c b/nuttx/graphics/nxbe/nxbe_colormap.c index 1443175190..e338773820 100644 --- a/nuttx/graphics/nxbe/nxbe_colormap.c +++ b/nuttx/graphics/nxbe/nxbe_colormap.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_colormap.c * * Copyright (C) 2008-2009,2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_fill.c b/nuttx/graphics/nxbe/nxbe_fill.c index f4aec74773..c2b4266b04 100644 --- a/nuttx/graphics/nxbe/nxbe_fill.c +++ b/nuttx/graphics/nxbe/nxbe_fill.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_fill.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_redraw.c b/nuttx/graphics/nxbe/nxbe_redraw.c index 3226ccf328..d52ff71e58 100644 --- a/nuttx/graphics/nxbe/nxbe_redraw.c +++ b/nuttx/graphics/nxbe/nxbe_redraw.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_redraw.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_setposition.c b/nuttx/graphics/nxbe/nxbe_setposition.c index f407eea3fa..6f680df040 100644 --- a/nuttx/graphics/nxbe/nxbe_setposition.c +++ b/nuttx/graphics/nxbe/nxbe_setposition.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_setposition.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_setsize.c b/nuttx/graphics/nxbe/nxbe_setsize.c index 367f5d7dc9..99775c715b 100644 --- a/nuttx/graphics/nxbe/nxbe_setsize.c +++ b/nuttx/graphics/nxbe/nxbe_setsize.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_setsize.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxbe/nxbe_visible.c b/nuttx/graphics/nxbe/nxbe_visible.c index 6b8b9291bb..ca62aeab6c 100644 --- a/nuttx/graphics/nxbe/nxbe_visible.c +++ b/nuttx/graphics/nxbe/nxbe_visible.c @@ -2,7 +2,7 @@ * graphics/nxbe/nxbe_redraw.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxconsole/nxcon_redraw.c b/nuttx/graphics/nxconsole/nxcon_redraw.c old mode 100755 new mode 100644 diff --git a/nuttx/graphics/nxfonts/Make.defs b/nuttx/graphics/nxfonts/Make.defs index 95665ad362..bc65d7ad7a 100644 --- a/nuttx/graphics/nxfonts/Make.defs +++ b/nuttx/graphics/nxfonts/Make.defs @@ -2,7 +2,7 @@ # graphics/nxfonts/Make.defs # # Copyright (C) 2008 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxfonts/Makefile.sources b/nuttx/graphics/nxfonts/Makefile.sources index 2867425798..f2aa87cafd 100644 --- a/nuttx/graphics/nxfonts/Makefile.sources +++ b/nuttx/graphics/nxfonts/Makefile.sources @@ -2,7 +2,7 @@ # graphics/nxfonts/Makefile.sources # # Copyright (C) 2008 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxfonts/nxfonts_bitmaps.c b/nuttx/graphics/nxfonts/nxfonts_bitmaps.c index 9b255b97a6..2efc34b87f 100644 --- a/nuttx/graphics/nxfonts/nxfonts_bitmaps.c +++ b/nuttx/graphics/nxfonts/nxfonts_bitmaps.c @@ -2,7 +2,7 @@ * graphics/nxfonts/nxfonts_bitmaps.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxfonts/nxfonts_convert.c b/nuttx/graphics/nxfonts/nxfonts_convert.c index 00cd61a6cd..a3c3199644 100644 --- a/nuttx/graphics/nxfonts/nxfonts_convert.c +++ b/nuttx/graphics/nxfonts/nxfonts_convert.c @@ -2,7 +2,7 @@ * graphics/nxfonts/nxfonts_convert.c * * Copyright (C) 2008-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxfonts/nxfonts_getfont.c b/nuttx/graphics/nxfonts/nxfonts_getfont.c index e17d3be310..23e5c44744 100644 --- a/nuttx/graphics/nxfonts/nxfonts_getfont.c +++ b/nuttx/graphics/nxfonts/nxfonts_getfont.c @@ -2,7 +2,7 @@ * graphics/nxfonts/nxfonts_getfont.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxfonts/nxfonts_internal.h b/nuttx/graphics/nxfonts/nxfonts_internal.h index fa7864170d..057200cd56 100644 --- a/nuttx/graphics/nxfonts/nxfonts_internal.h +++ b/nuttx/graphics/nxfonts/nxfonts_internal.h @@ -2,7 +2,7 @@ * graphics/nxfonts/nxfonts_internal.h * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/fb/nxglib_copyrectangle.c b/nuttx/graphics/nxglib/fb/nxglib_copyrectangle.c index 4ad792a4cb..bf9812ac37 100644 --- a/nuttx/graphics/nxglib/fb/nxglib_copyrectangle.c +++ b/nuttx/graphics/nxglib/fb/nxglib_copyrectangle.c @@ -2,7 +2,7 @@ * graphics/nxglib/fb/nxsglib_copyrectangle.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/fb/nxglib_fillrectangle.c b/nuttx/graphics/nxglib/fb/nxglib_fillrectangle.c index cb9483c989..777a906a4f 100644 --- a/nuttx/graphics/nxglib/fb/nxglib_fillrectangle.c +++ b/nuttx/graphics/nxglib/fb/nxglib_fillrectangle.c @@ -2,7 +2,7 @@ * graphics/nxglib/fb/nxglib_fillrectangle.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c b/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c index 988b6cb944..40989acef2 100644 --- a/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c +++ b/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c @@ -2,7 +2,7 @@ * graphics/nxglib/lcd/nxsglib_copyrectangle.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c b/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c index c1a30d66ff..b9554e1cc3 100644 --- a/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c +++ b/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c @@ -2,7 +2,7 @@ * graphics/nxglib/lcd/nxglib_fillrectangle.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c b/nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c index f82187ae3b..b46a17e61a 100644 --- a/nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c +++ b/nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c @@ -2,7 +2,7 @@ * graphics/nxglib/lcd/nxglib_moverectangle.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_bitblit.h b/nuttx/graphics/nxglib/nxglib_bitblit.h index a737a06474..0182337d1b 100644 --- a/nuttx/graphics/nxglib/nxglib_bitblit.h +++ b/nuttx/graphics/nxglib/nxglib_bitblit.h @@ -2,7 +2,7 @@ * graphics/nxglib/nxglib_bitblit.h * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_circlepts.c b/nuttx/graphics/nxglib/nxglib_circlepts.c index a6d59280d7..811953dfc6 100644 --- a/nuttx/graphics/nxglib/nxglib_circlepts.c +++ b/nuttx/graphics/nxglib/nxglib_circlepts.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxglib_circlepts.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_circletraps.c b/nuttx/graphics/nxglib/nxglib_circletraps.c index 7c2cd1d7b5..8ee287795f 100644 --- a/nuttx/graphics/nxglib/nxglib_circletraps.c +++ b/nuttx/graphics/nxglib/nxglib_circletraps.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxglib_circletraps.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_colorcopy.c b/nuttx/graphics/nxglib/nxglib_colorcopy.c index f99b995050..42c0d0d451 100644 --- a/nuttx/graphics/nxglib/nxglib_colorcopy.c +++ b/nuttx/graphics/nxglib/nxglib_colorcopy.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_colorcopy.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_copyrun.h b/nuttx/graphics/nxglib/nxglib_copyrun.h index b97372bf77..a52af22463 100644 --- a/nuttx/graphics/nxglib/nxglib_copyrun.h +++ b/nuttx/graphics/nxglib/nxglib_copyrun.h @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_copyrun.h * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_fillrun.h b/nuttx/graphics/nxglib/nxglib_fillrun.h index b1d8a3a7fb..1dcf85dd97 100644 --- a/nuttx/graphics/nxglib/nxglib_fillrun.h +++ b/nuttx/graphics/nxglib/nxglib_fillrun.h @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_fullrun.h * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_intersecting.c b/nuttx/graphics/nxglib/nxglib_intersecting.c index c495a9e3d9..e1370c1404 100644 --- a/nuttx/graphics/nxglib/nxglib_intersecting.c +++ b/nuttx/graphics/nxglib/nxglib_intersecting.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_intersecting.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_nonintersecting.c b/nuttx/graphics/nxglib/nxglib_nonintersecting.c index 9cb2ec29c5..d78da994e8 100644 --- a/nuttx/graphics/nxglib/nxglib_nonintersecting.c +++ b/nuttx/graphics/nxglib/nxglib_nonintersecting.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectnonintersecting.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectadd.c b/nuttx/graphics/nxglib/nxglib_rectadd.c index b53e6b04c6..f4eda341d5 100644 --- a/nuttx/graphics/nxglib/nxglib_rectadd.c +++ b/nuttx/graphics/nxglib/nxglib_rectadd.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectadd.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectcopy.c b/nuttx/graphics/nxglib/nxglib_rectcopy.c index 998f5b716f..67e5f6d691 100644 --- a/nuttx/graphics/nxglib/nxglib_rectcopy.c +++ b/nuttx/graphics/nxglib/nxglib_rectcopy.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectcopy.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectinside.c b/nuttx/graphics/nxglib/nxglib_rectinside.c index 1c1f17a2e3..6ca29ddb6e 100644 --- a/nuttx/graphics/nxglib/nxglib_rectinside.c +++ b/nuttx/graphics/nxglib/nxglib_rectinside.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectinside.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectintersect.c b/nuttx/graphics/nxglib/nxglib_rectintersect.c index 9616357104..6af24ee268 100644 --- a/nuttx/graphics/nxglib/nxglib_rectintersect.c +++ b/nuttx/graphics/nxglib/nxglib_rectintersect.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectintersect.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectoffset.c b/nuttx/graphics/nxglib/nxglib_rectoffset.c index 93481b0de5..2392d64486 100644 --- a/nuttx/graphics/nxglib/nxglib_rectoffset.c +++ b/nuttx/graphics/nxglib/nxglib_rectoffset.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectoffset.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectoverlap.c b/nuttx/graphics/nxglib/nxglib_rectoverlap.c index 75d7a46411..779951881b 100644 --- a/nuttx/graphics/nxglib/nxglib_rectoverlap.c +++ b/nuttx/graphics/nxglib/nxglib_rectoverlap.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_nulloverlap.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectsize.c b/nuttx/graphics/nxglib/nxglib_rectsize.c index 17a6c9214a..37d8635968 100644 --- a/nuttx/graphics/nxglib/nxglib_rectsize.c +++ b/nuttx/graphics/nxglib/nxglib_rectsize.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxglib_rectsize.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rectunion.c b/nuttx/graphics/nxglib/nxglib_rectunion.c index 8500c919cf..36c0968fa3 100644 --- a/nuttx/graphics/nxglib/nxglib_rectunion.c +++ b/nuttx/graphics/nxglib/nxglib_rectunion.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_rectunion.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_rgb2yuv.c b/nuttx/graphics/nxglib/nxglib_rgb2yuv.c index c439c4fe00..31eff23fa7 100644 --- a/nuttx/graphics/nxglib/nxglib_rgb2yuv.c +++ b/nuttx/graphics/nxglib/nxglib_rgb2yuv.c @@ -2,7 +2,7 @@ * graphics/color/nxglib_rgb2yuv.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_runcopy.c b/nuttx/graphics/nxglib/nxglib_runcopy.c index 4b5372f149..b6170638c2 100644 --- a/nuttx/graphics/nxglib/nxglib_runcopy.c +++ b/nuttx/graphics/nxglib/nxglib_runcopy.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_runcopy.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_runoffset.c b/nuttx/graphics/nxglib/nxglib_runoffset.c index f66d736741..0c569ce2f2 100644 --- a/nuttx/graphics/nxglib/nxglib_runoffset.c +++ b/nuttx/graphics/nxglib/nxglib_runoffset.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_runoffset.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_splitline.c b/nuttx/graphics/nxglib/nxglib_splitline.c index eff516db38..84892b67e3 100644 --- a/nuttx/graphics/nxglib/nxglib_splitline.c +++ b/nuttx/graphics/nxglib/nxglib_splitline.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxglib_splitline.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_trapcopy.c b/nuttx/graphics/nxglib/nxglib_trapcopy.c index 63bc0ecd81..f35da18e1e 100644 --- a/nuttx/graphics/nxglib/nxglib_trapcopy.c +++ b/nuttx/graphics/nxglib/nxglib_trapcopy.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_trapcopy.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_trapoffset.c b/nuttx/graphics/nxglib/nxglib_trapoffset.c index 872a310728..a90631f065 100644 --- a/nuttx/graphics/nxglib/nxglib_trapoffset.c +++ b/nuttx/graphics/nxglib/nxglib_trapoffset.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_trapoffset.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_vectoradd.c b/nuttx/graphics/nxglib/nxglib_vectoradd.c index b206effa60..7da5eb1371 100644 --- a/nuttx/graphics/nxglib/nxglib_vectoradd.c +++ b/nuttx/graphics/nxglib/nxglib_vectoradd.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_vectoradd.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_vectsubtract.c b/nuttx/graphics/nxglib/nxglib_vectsubtract.c index 81ffc86fb0..c830a1a33b 100644 --- a/nuttx/graphics/nxglib/nxglib_vectsubtract.c +++ b/nuttx/graphics/nxglib/nxglib_vectsubtract.c @@ -2,7 +2,7 @@ * graphics/nxglib/nxsglib_vectorsubtract.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxglib/nxglib_yuv2rgb.c b/nuttx/graphics/nxglib/nxglib_yuv2rgb.c index 9a3cb1f228..cb4bb9f2fb 100644 --- a/nuttx/graphics/nxglib/nxglib_yuv2rgb.c +++ b/nuttx/graphics/nxglib/nxglib_yuv2rgb.c @@ -2,7 +2,7 @@ * graphics/color/nxglib_yuv2rgb.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nx_drawcircle.c b/nuttx/graphics/nxmu/nx_drawcircle.c index 5a0780e1a0..22424c19d9 100644 --- a/nuttx/graphics/nxmu/nx_drawcircle.c +++ b/nuttx/graphics/nxmu/nx_drawcircle.c @@ -2,7 +2,7 @@ * graphics/nxmu/nx_drawcircle.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nx_drawline.c b/nuttx/graphics/nxmu/nx_drawline.c index 0267d8058b..7de0af1c1d 100644 --- a/nuttx/graphics/nxmu/nx_drawline.c +++ b/nuttx/graphics/nxmu/nx_drawline.c @@ -2,7 +2,7 @@ * graphics/nxmu/nx_drawline.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nx_eventnotify.c b/nuttx/graphics/nxmu/nx_eventnotify.c index 1892413618..556c9fa93b 100644 --- a/nuttx/graphics/nxmu/nx_eventnotify.c +++ b/nuttx/graphics/nxmu/nx_eventnotify.c @@ -2,7 +2,7 @@ * graphics/nxmu/nx_eventnotify.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nx_fillcircle.c b/nuttx/graphics/nxmu/nx_fillcircle.c index bfc1dc9e39..5c96716953 100644 --- a/nuttx/graphics/nxmu/nx_fillcircle.c +++ b/nuttx/graphics/nxmu/nx_fillcircle.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_fillcircle.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nxmu_openwindow.c b/nuttx/graphics/nxmu/nxmu_openwindow.c index 4cd6e661ce..395f0a7701 100644 --- a/nuttx/graphics/nxmu/nxmu_openwindow.c +++ b/nuttx/graphics/nxmu/nxmu_openwindow.c @@ -2,7 +2,7 @@ * graphics/nxmu/nxmu_openwindow.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nxmu_releasebkgd.c b/nuttx/graphics/nxmu/nxmu_releasebkgd.c index 3d1f24b792..4183b223d3 100644 --- a/nuttx/graphics/nxmu/nxmu_releasebkgd.c +++ b/nuttx/graphics/nxmu/nxmu_releasebkgd.c @@ -2,7 +2,7 @@ * graphics/nxmu/nxmu_releasebkgd.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nxmu_requestbkgd.c b/nuttx/graphics/nxmu/nxmu_requestbkgd.c index 0e69351e6f..47b1ad13fb 100644 --- a/nuttx/graphics/nxmu/nxmu_requestbkgd.c +++ b/nuttx/graphics/nxmu/nxmu_requestbkgd.c @@ -2,7 +2,7 @@ * graphics/nxmu/nxmu_requestbkgd.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxmu/nxmu_semtake.c b/nuttx/graphics/nxmu/nxmu_semtake.c index 10fd5bd4a6..164a099b87 100644 --- a/nuttx/graphics/nxmu/nxmu_semtake.c +++ b/nuttx/graphics/nxmu/nxmu_semtake.c @@ -2,7 +2,7 @@ * graphics/nxmu/nxmu_semtake.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_bitmap.c b/nuttx/graphics/nxsu/nx_bitmap.c index 696b94afe0..99fcbbb701 100644 --- a/nuttx/graphics/nxsu/nx_bitmap.c +++ b/nuttx/graphics/nxsu/nx_bitmap.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_bitmap.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_close.c b/nuttx/graphics/nxsu/nx_close.c index a3fa9b74d2..b48a2fca2d 100644 --- a/nuttx/graphics/nxsu/nx_close.c +++ b/nuttx/graphics/nxsu/nx_close.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_close.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_closewindow.c b/nuttx/graphics/nxsu/nx_closewindow.c index c5a2799eaf..879d049d4d 100644 --- a/nuttx/graphics/nxsu/nx_closewindow.c +++ b/nuttx/graphics/nxsu/nx_closewindow.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_closewindow.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_drawcircle.c b/nuttx/graphics/nxsu/nx_drawcircle.c index 8d5c124549..30b3072190 100644 --- a/nuttx/graphics/nxsu/nx_drawcircle.c +++ b/nuttx/graphics/nxsu/nx_drawcircle.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_drawcircle.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_drawline.c b/nuttx/graphics/nxsu/nx_drawline.c index ca4ddaf188..99e3494b9e 100644 --- a/nuttx/graphics/nxsu/nx_drawline.c +++ b/nuttx/graphics/nxsu/nx_drawline.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_drawline.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_fill.c b/nuttx/graphics/nxsu/nx_fill.c index 9075f82c01..037cb5e13b 100644 --- a/nuttx/graphics/nxsu/nx_fill.c +++ b/nuttx/graphics/nxsu/nx_fill.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_fill.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_fillcircle.c b/nuttx/graphics/nxsu/nx_fillcircle.c index 12c47f80a1..f3876057a2 100644 --- a/nuttx/graphics/nxsu/nx_fillcircle.c +++ b/nuttx/graphics/nxsu/nx_fillcircle.c @@ -2,7 +2,7 @@ * graphics/nxmu/nx_fillcircle.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_filltrapezoid.c b/nuttx/graphics/nxsu/nx_filltrapezoid.c index 869ce3e1a0..353b91f6e4 100644 --- a/nuttx/graphics/nxsu/nx_filltrapezoid.c +++ b/nuttx/graphics/nxsu/nx_filltrapezoid.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_filltrapezoid.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_getposition.c b/nuttx/graphics/nxsu/nx_getposition.c index 8760d84c16..acc6330871 100644 --- a/nuttx/graphics/nxsu/nx_getposition.c +++ b/nuttx/graphics/nxsu/nx_getposition.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_getposition.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_kbdchin.c b/nuttx/graphics/nxsu/nx_kbdchin.c index 7ecea5db95..f07462f229 100644 --- a/nuttx/graphics/nxsu/nx_kbdchin.c +++ b/nuttx/graphics/nxsu/nx_kbdchin.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_kbdchin.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_kbdin.c b/nuttx/graphics/nxsu/nx_kbdin.c index 9fc8460bdd..6acd96a72f 100644 --- a/nuttx/graphics/nxsu/nx_kbdin.c +++ b/nuttx/graphics/nxsu/nx_kbdin.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_kbdin.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_lower.c b/nuttx/graphics/nxsu/nx_lower.c index dbfd278c41..5c47185f8d 100644 --- a/nuttx/graphics/nxsu/nx_lower.c +++ b/nuttx/graphics/nxsu/nx_lower.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_lower.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_move.c b/nuttx/graphics/nxsu/nx_move.c index b16cf3525e..9fb303147a 100644 --- a/nuttx/graphics/nxsu/nx_move.c +++ b/nuttx/graphics/nxsu/nx_move.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_move.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_open.c b/nuttx/graphics/nxsu/nx_open.c index f5e07dc5ec..72a2db0589 100644 --- a/nuttx/graphics/nxsu/nx_open.c +++ b/nuttx/graphics/nxsu/nx_open.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_open.c * * Copyright (C) 2008-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_raise.c b/nuttx/graphics/nxsu/nx_raise.c index cf4e38b64c..e0ede54006 100644 --- a/nuttx/graphics/nxsu/nx_raise.c +++ b/nuttx/graphics/nxsu/nx_raise.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_raise.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_requestbkgd.c b/nuttx/graphics/nxsu/nx_requestbkgd.c index 5bd4554bc9..7f0ab12f25 100644 --- a/nuttx/graphics/nxsu/nx_requestbkgd.c +++ b/nuttx/graphics/nxsu/nx_requestbkgd.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_requestbkgd.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_setbgcolor.c b/nuttx/graphics/nxsu/nx_setbgcolor.c index d8c2159efa..5f9818855f 100644 --- a/nuttx/graphics/nxsu/nx_setbgcolor.c +++ b/nuttx/graphics/nxsu/nx_setbgcolor.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_setbgcolor.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nx_setsize.c b/nuttx/graphics/nxsu/nx_setsize.c index 171e26faed..4872abf034 100644 --- a/nuttx/graphics/nxsu/nx_setsize.c +++ b/nuttx/graphics/nxsu/nx_setsize.c @@ -2,7 +2,7 @@ * graphics/nxsu/nx_setsize.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nxfe.h b/nuttx/graphics/nxsu/nxfe.h index 59f5b7e61c..528224fc16 100644 --- a/nuttx/graphics/nxsu/nxfe.h +++ b/nuttx/graphics/nxsu/nxfe.h @@ -2,7 +2,7 @@ * graphics/nxsu/nxfe.h * * Copyright (C) 2008-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nxsu_redrawreq.c b/nuttx/graphics/nxsu/nxsu_redrawreq.c index 9efa828a51..21845f16fa 100644 --- a/nuttx/graphics/nxsu/nxsu_redrawreq.c +++ b/nuttx/graphics/nxsu/nxsu_redrawreq.c @@ -2,7 +2,7 @@ * graphics/nxsu/nxsu_redrawreq.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxsu/nxsu_reportposition.c b/nuttx/graphics/nxsu/nxsu_reportposition.c index d87dac0f6b..b795a81e63 100644 --- a/nuttx/graphics/nxsu/nxsu_reportposition.c +++ b/nuttx/graphics/nxsu/nxsu_reportposition.c @@ -2,7 +2,7 @@ * graphics/nxsu/nxsu_reportposition.c * * Copyright (C) 2008-2009,2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_bitmapwindow.c b/nuttx/graphics/nxtk/nxtk_bitmapwindow.c index a439f5f797..6847c44d46 100644 --- a/nuttx/graphics/nxtk/nxtk_bitmapwindow.c +++ b/nuttx/graphics/nxtk/nxtk_bitmapwindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_bitmapwindow.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_closetoolbar.c b/nuttx/graphics/nxtk/nxtk_closetoolbar.c index dff621a44f..7ad36f9d87 100644 --- a/nuttx/graphics/nxtk/nxtk_closetoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_closetoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_closetoolbar.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_closewindow.c b/nuttx/graphics/nxtk/nxtk_closewindow.c index e921f669e0..e80cd0c665 100644 --- a/nuttx/graphics/nxtk/nxtk_closewindow.c +++ b/nuttx/graphics/nxtk/nxtk_closewindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_closewindow.c * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_containerclip.c b/nuttx/graphics/nxtk/nxtk_containerclip.c index 3671851f17..a2fbcd0f8f 100644 --- a/nuttx/graphics/nxtk/nxtk_containerclip.c +++ b/nuttx/graphics/nxtk/nxtk_containerclip.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_containerclip.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_drawcircletoolbar.c b/nuttx/graphics/nxtk/nxtk_drawcircletoolbar.c index e9d9ca8ffb..a36ed32eef 100644 --- a/nuttx/graphics/nxtk/nxtk_drawcircletoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_drawcircletoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_drawcircletoolbar.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_drawcirclewindow.c b/nuttx/graphics/nxtk/nxtk_drawcirclewindow.c index f70c1c3515..080e802ec1 100644 --- a/nuttx/graphics/nxtk/nxtk_drawcirclewindow.c +++ b/nuttx/graphics/nxtk/nxtk_drawcirclewindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_drawcirclewindow.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_drawlinetoolbar.c b/nuttx/graphics/nxtk/nxtk_drawlinetoolbar.c index 4af8b37327..f2a559d690 100644 --- a/nuttx/graphics/nxtk/nxtk_drawlinetoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_drawlinetoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_drawlinetoolbar.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_drawlinewindow.c b/nuttx/graphics/nxtk/nxtk_drawlinewindow.c index 2dfd7e8452..a5534fa59e 100644 --- a/nuttx/graphics/nxtk/nxtk_drawlinewindow.c +++ b/nuttx/graphics/nxtk/nxtk_drawlinewindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_drawlinewindow.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_fillcircletoolbar.c b/nuttx/graphics/nxtk/nxtk_fillcircletoolbar.c index d0bb09edd2..92dee7e27f 100644 --- a/nuttx/graphics/nxtk/nxtk_fillcircletoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_fillcircletoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_fillcircletoolbar.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_fillcirclewindow.c b/nuttx/graphics/nxtk/nxtk_fillcirclewindow.c index 34c9458650..5f093e0354 100644 --- a/nuttx/graphics/nxtk/nxtk_fillcirclewindow.c +++ b/nuttx/graphics/nxtk/nxtk_fillcirclewindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_fillcirclewindow.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_filltoolbar.c b/nuttx/graphics/nxtk/nxtk_filltoolbar.c index c39199e6a8..931fa7decb 100644 --- a/nuttx/graphics/nxtk/nxtk_filltoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_filltoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_filltoolbar.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_filltraptoolbar.c b/nuttx/graphics/nxtk/nxtk_filltraptoolbar.c index 1f04e9b43e..7108f42eb6 100644 --- a/nuttx/graphics/nxtk/nxtk_filltraptoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_filltraptoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_filltraptoolbar.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_filltrapwindow.c b/nuttx/graphics/nxtk/nxtk_filltrapwindow.c index c84c055f88..c1032f1e75 100644 --- a/nuttx/graphics/nxtk/nxtk_filltrapwindow.c +++ b/nuttx/graphics/nxtk/nxtk_filltrapwindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_filltrapwindow.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_fillwindow.c b/nuttx/graphics/nxtk/nxtk_fillwindow.c index e971ce06bc..c76dbfbb46 100644 --- a/nuttx/graphics/nxtk/nxtk_fillwindow.c +++ b/nuttx/graphics/nxtk/nxtk_fillwindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_fillwindow.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_getposition.c b/nuttx/graphics/nxtk/nxtk_getposition.c index e6cce60262..7850f77144 100644 --- a/nuttx/graphics/nxtk/nxtk_getposition.c +++ b/nuttx/graphics/nxtk/nxtk_getposition.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_getposition.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_lower.c b/nuttx/graphics/nxtk/nxtk_lower.c index 256ed27dab..e37e020fc0 100644 --- a/nuttx/graphics/nxtk/nxtk_lower.c +++ b/nuttx/graphics/nxtk/nxtk_lower.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_lower.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_movetoolbar.c b/nuttx/graphics/nxtk/nxtk_movetoolbar.c index 088611382a..9170394f1d 100644 --- a/nuttx/graphics/nxtk/nxtk_movetoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_movetoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_movetoolbar.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_movewindow.c b/nuttx/graphics/nxtk/nxtk_movewindow.c index 4c45c101c5..83d95b3a4e 100644 --- a/nuttx/graphics/nxtk/nxtk_movewindow.c +++ b/nuttx/graphics/nxtk/nxtk_movewindow.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_movewindow.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_opentoolbar.c b/nuttx/graphics/nxtk/nxtk_opentoolbar.c index 56ca941b8f..e82dbed6fd 100644 --- a/nuttx/graphics/nxtk/nxtk_opentoolbar.c +++ b/nuttx/graphics/nxtk/nxtk_opentoolbar.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_opentoolbar.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_raise.c b/nuttx/graphics/nxtk/nxtk_raise.c index 1e35f3ab2a..f20b258992 100644 --- a/nuttx/graphics/nxtk/nxtk_raise.c +++ b/nuttx/graphics/nxtk/nxtk_raise.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_raise.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_setsize.c b/nuttx/graphics/nxtk/nxtk_setsize.c index aeeebf1500..332ea00b57 100644 --- a/nuttx/graphics/nxtk/nxtk_setsize.c +++ b/nuttx/graphics/nxtk/nxtk_setsize.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_setsize.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_setsubwindows.c b/nuttx/graphics/nxtk/nxtk_setsubwindows.c index 2510083610..143909ea4c 100644 --- a/nuttx/graphics/nxtk/nxtk_setsubwindows.c +++ b/nuttx/graphics/nxtk/nxtk_setsubwindows.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_setsubwindows.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_subwindowclip.c b/nuttx/graphics/nxtk/nxtk_subwindowclip.c index 4d453eecaf..2dbefb6481 100644 --- a/nuttx/graphics/nxtk/nxtk_subwindowclip.c +++ b/nuttx/graphics/nxtk/nxtk_subwindowclip.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_subwindowclip.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/graphics/nxtk/nxtk_subwindowmove.c b/nuttx/graphics/nxtk/nxtk_subwindowmove.c index ed6a264e73..a6fd9f5ddb 100644 --- a/nuttx/graphics/nxtk/nxtk_subwindowmove.c +++ b/nuttx/graphics/nxtk/nxtk_subwindowmove.c @@ -2,7 +2,7 @@ * graphics/nxtk/nxtk_subwindowmove.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/include/assert.h b/nuttx/include/assert.h index 89606b6f6a..31c9edf48d 100644 --- a/nuttx/include/assert.h +++ b/nuttx/include/assert.h @@ -91,6 +91,10 @@ #endif +#ifndef assert +#define assert ASSERT +#endif + /**************************************************************************** * Included Files ****************************************************************************/ diff --git a/nuttx/include/libgen.h b/nuttx/include/libgen.h index e659483768..0d42dc7782 100644 --- a/nuttx/include/libgen.h +++ b/nuttx/include/libgen.h @@ -55,8 +55,8 @@ extern "C" { #define EXTERN extern #endif -EXTERN char *basename(char *path); -EXTERN char *dirname(char *path); +EXTERN FAR char *basename(FAR char *path); +EXTERN FAR char *dirname(FAR char *path); #undef EXTERN #ifdef __cplusplus diff --git a/nuttx/include/netinet/ether.h b/nuttx/include/netinet/ether.h index f11fef6dbf..69b8fbba67 100644 --- a/nuttx/include/netinet/ether.h +++ b/nuttx/include/netinet/ether.h @@ -63,7 +63,7 @@ extern "C" { #define EXTERN extern #endif -EXTERN char *ether_ntoa(const struct ether_addr *addr); +EXTERN FAR char *ether_ntoa(FAR const struct ether_addr *addr); EXTERN struct ether_addr *ether_aton(const char *asc); EXTERN int ether_ntohost(char *hostname, const struct ether_addr *addr); EXTERN int ether_hostton(const char *hostname, struct ether_addr *addr); diff --git a/nuttx/include/nuttx/analog/adc.h b/nuttx/include/nuttx/analog/adc.h index 873f5d9da7..f654bff05e 100644 --- a/nuttx/include/nuttx/analog/adc.h +++ b/nuttx/include/nuttx/analog/adc.h @@ -47,6 +47,7 @@ ************************************************************************************/ #include +#include #include #include @@ -78,7 +79,7 @@ struct adc_msg_s { uint8_t am_channel; /* The 8-bit ADC Channel */ int32_t am_data; /* ADC convert result (4 bytes) */ -} __attribute__((__packed__)); +} packed_struct; struct adc_fifo_s { diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h index 733d58eec6..d74fcbea08 100644 --- a/nuttx/include/nuttx/compiler.h +++ b/nuttx/include/nuttx/compiler.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/compiler.h * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -92,6 +92,14 @@ # define reentrant_function # define naked_function +/* The inline_function attribute informs GCC that the function should always + * be inlined, regardless of the level of optimization. The noinline_function + * indicates that the function should never be inlined. + */ + +# define inline_function __attribute__ ((always_inline,no_instrument_function)) +# define noinline_function __attribute__ ((noinline)) + /* GCC has does not use storage classes to qualify addressing */ # define FAR @@ -224,10 +232,15 @@ # define noreturn_function # define packed_struct -/* SDCC does support "naked" function s*/ +/* SDCC does support "naked" functions */ # define naked_function __naked +/* SDCC does not support forced inlining. */ + +# define inline_function +# define noinline_function + /* The reentrant attribute informs SDCC that the function * must be reentrant. In this case, SDCC will store input * arguments on the stack to support reentrancy. @@ -320,11 +333,13 @@ # define weak_function # define weak_const_function -/* The Zilog compiler does not support the noreturn, packed, or naked attributes */ +/* The Zilog compiler does not support the noreturn, packed, naked attributes */ # define noreturn_function # define packed_struct # define naked_function +# define inline_function +# define noinline_function /* The Zilog compiler does not support the reentrant attribute */ @@ -406,7 +421,8 @@ # define packed_struct # define reentrant_function # define naked_function - +# define inline_function +# define noinline_function # define FAR # define NEAR diff --git a/nuttx/include/nuttx/fs/fat.h b/nuttx/include/nuttx/fs/fat.h index f69bd85713..ac85c502f4 100644 --- a/nuttx/include/nuttx/fs/fat.h +++ b/nuttx/include/nuttx/fs/fat.h @@ -40,6 +40,7 @@ * Included Files ****************************************************************************/ +#include #include /**************************************************************************** @@ -75,11 +76,44 @@ extern "C" { #define EXTERN extern #endif -/* Non-standard functions to get and set FAT file/directory attributes */ +/**************************************************************************** + * Name: fat_getattrib and fat_setattrib + * + * Description: + * Non-standard functions to get and set FAT file/directory attributes + * + ****************************************************************************/ EXTERN int fat_getattrib(const char *path, fat_attrib_t *attrib); EXTERN int fat_setattrib(const char *path, fat_attrib_t setbits, fat_attrib_t clearbits); +/**************************************************************************** + * Name: fat_dma_alloc and fat_dma_free + * + * Description: + * The FAT file system allocates two I/O buffers for data transfer, each + * are the size of one device sector. One of the buffers is allocated + * once for each FAT volume that is mounted; the other buffers are + * allocated each time a FAT file is opened. + * + * Some hardware, however, may require special DMA-capable memory in + * order to perform the the transfers. If CONFIG_FAT_DMAMEMORY is defined + * then the architecture-specific hardware must provide the funtions + * fat_dma_alloc() and fat_dma_free() as prototyped below: fat_dma_alloc() + * will allocate DMA-capable memory of the specified size; fat_dma_free() + * is the corresponding function that will be called to free the DMA- + * capable memory. + * + * This functions may be simple wrappers around gran_alloc() and gran_free() + * (See nuttx/gran.h). + * + ****************************************************************************/ + +#ifdef CONFIG_FAT_DMAMEMORY +EXTERN FAR void *fat_dma_alloc(size_t size); +EXTERN void fat_dma_free(FAR void *memory, size_t size); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/nuttx/include/nuttx/gran.h b/nuttx/include/nuttx/gran.h new file mode 100644 index 0000000000..5e980dd9cf --- /dev/null +++ b/nuttx/include/nuttx/gran.h @@ -0,0 +1,202 @@ +/**************************************************************************** + * include/nuttx/gran.h + * General purpose granule memory allocator. + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_GRAN_H +#define __INCLUDE_NUTTX_GRAN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#ifdef CONFIG_GRAN + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* CONFIG_GRAN - Enable granual allocator support + * CONFIG_GRAN_SINGLE - Select if there is only one instance of the + * granule allocator (i.e., gran_initialize will be called only once. + * In this case, (1) there are a few optimizations that can can be done + * and (2) the GRAN_HANDLE is not needed. + * CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator + * data is assured using a semaphore. If this option is set then, instead, + * mutual exclusion logic will disable interrupts. While this options is + * more invasive to system performance, it will also support use of the + * granule allocator from interrupt level logic. + * CONFIG_DEBUG_GRAN - Just like CONFIG_DEBUG_MM, but only generates ouput + * from the gran allocation logic. + */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef CONFIG_GRAN_SINGLE +typedef FAR void *GRAN_HANDLE; +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: gran_initialize + * + * Description: + * Set up one granule allocator instance. Allocations will be aligned to + * the alignment size (log2align; allocations will be in units of the + * granule size (log2gran). Larger granules will give better performance + * and less overhead but more losses of memory due to quantization waste. + * Additional memory waste can occur from alignment; log2align should be + * set to 0 unless you are using the granule allocator to manage DMA memory + * and your hardware has specific memory alignment requirements. + * + * Geneneral Usage Summary. This is an example using the GCC section + * attribute to position a DMA heap in memory (logic in the linker script + * would assign the section .dmaheap to the DMA memory. + * + * FAR uint32_t g_dmaheap[DMAHEAP_SIZE] __attribute__((section(.dmaheap))); + * + * The heap is created by calling gran_initialize. Here the granual size + * is set to 64 bytes and the alignment to 16 bytes: + * + * GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4); + * + * Then the GRAN_HANDLE can be used to allocate memory (There is no + * GRAN_HANDLE if CONFIG_GRAN_SINGLE=y): + * + * FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47); + * + * The actual memory allocates will be 64 byte (wasting 17 bytes) and + * will be aligned at least to (1 << log2align). + * + * NOTE: The current implementation also restricts the maximum allocation + * size to 32 granules. That restriction could be eliminated with some + * additional coding effort. + * + * Input Parameters: + * heapstart - Start of the granule allocation heap + * heapsize - Size of heap in bytes + * log2gran - Log base 2 of the size of one granule. 0->1 byte, + * 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. + * log2align - Log base 2 of required alignment. 0->1 byte, + * 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. Note that + * log2gran must be greater than or equal to log2align + * so that all contiguous granules in memory will meet + * the minimum alignment requirement. A value of zero + * would mean that no alignment is required. + * + * Returned Value: + * On success, a non-NULL handle is returned that may be used with other + * granual allocator interfaces. + * + ****************************************************************************/ + +#ifdef CONFIG_GRAN_SINGLE +EXTERN int gran_initialize(FAR void *heapstart, size_t heapsize, + uint8_t log2gran, uint8_t log2align); +#else +EXTERN GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize, + uint8_t log2gran, uint8_t log2align); +#endif + +/**************************************************************************** + * Name: gran_alloc + * + * Description: + * Allocate memory from the granule heap. + * + * NOTE: The current implementation also restricts the maximum allocation + * size to 32 granules. That restriction could be eliminated with some + * additional coding effort. + * + * Input Parameters: + * handle - The handle previously returned by gran_initialize + * size - The size of the memory region to allocate. + * + * Returned Value: + * On success, either a non-NULL pointer to the allocated memory (if + * CONFIG_GRAN_SINGLE) or zero (if !CONFIG_GRAN_SINGLE) is returned. + * + ****************************************************************************/ + +#ifdef CONFIG_GRAN_SINGLE +EXTERN FAR void *gran_alloc(size_t size); +#else +EXTERN FAR void *gran_alloc(GRAN_HANDLE handle, size_t size); +#endif + +/**************************************************************************** + * Name: gran_free + * + * Description: + * Return memory to the granule heap. + * + * Input Parameters: + * handle - The handle previously returned by gran_initialize + * memory - A pointer to memory previoiusly allocated by gran_alloc. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_GRAN_SINGLE +EXTERN void gran_free(FAR void *memory, size_t size); +#else +EXTERN void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size); +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_GRAN */ +#endif /* __INCLUDE_NUTTX_GRAN_H */ diff --git a/nuttx/include/nuttx/i2c.h b/nuttx/include/nuttx/i2c.h index b2238b1cf0..ef3d9a3883 100644 --- a/nuttx/include/nuttx/i2c.h +++ b/nuttx/include/nuttx/i2c.h @@ -325,6 +325,23 @@ EXTERN FAR struct i2c_dev_s *up_i2cinitialize(int port); EXTERN int up_i2cuninitialize(FAR struct i2c_dev_s * dev); +/**************************************************************************** + * Name: up_i2creset + * + * Description: + * Reset the port and the associated I2C bus. Useful when the bus or an + * attached slave has become wedged or unresponsive. + * + * Input Parameter: + * Device structure as returned by the up_i2cinitalize() + * + * Returned Value: + * OK on success, ERROR if the bus cannot be unwedged. + * + ****************************************************************************/ + +EXTERN int up_i2creset(FAR struct i2c_dev_s * dev); + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/include/nuttx/init.h b/nuttx/include/nuttx/init.h index ecdad702f5..2d1b3c693c 100644 --- a/nuttx/include/nuttx/init.h +++ b/nuttx/include/nuttx/init.h @@ -68,7 +68,7 @@ extern "C" { /* This entry point must be supplied by the application */ -EXTERN int user_start(int argc, char *argv[]); +EXTERN int CONFIG_USER_ENTRYPOINT(int argc, char *argv[]); /* Functions contained in os_task.c *****************************************/ diff --git a/nuttx/include/nuttx/mtd.h b/nuttx/include/nuttx/mtd.h index 5b955a45f4..44582c4124 100644 --- a/nuttx/include/nuttx/mtd.h +++ b/nuttx/include/nuttx/mtd.h @@ -220,6 +220,19 @@ EXTERN FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev); + +/**************************************************************************** + * Name: w25_initialize + * + * Description: + * Create an initialized MTD device instance. MTD devices are not registered + * in the file system, but are created as instances that can be bound to + * other functions (such as a block or character driver front end). + * + ****************************************************************************/ + +EXTERN FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev); + #undef EXTERN #ifdef __cplusplus } diff --git a/nuttx/include/nuttx/net/enc28j60.h b/nuttx/include/nuttx/net/enc28j60.h index 2507b1cf60..7d0d7c3e5c 100644 --- a/nuttx/include/nuttx/net/enc28j60.h +++ b/nuttx/include/nuttx/net/enc28j60.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/enc28j60.h * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,13 +43,15 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /* ENC28J60 Configuration Settings: * - * CONFIG_NET_ENC28J60 - Enabled ENC28J60 support + * CONFIG_ENC28J60 - Enabled ENC28J60 support * CONFIG_ENC28J60_SPIMODE - Controls the SPI mode * CONFIG_ENC28J60_FREQUENCY - Define to use a different bus frequency * CONFIG_ENC28J60_NINTERFACES - Specifies the number of physical ENC28J60 @@ -80,6 +82,34 @@ struct enc_stats_s }; #endif +/* The ENC28J60 normal provides interrupts to the MCU via a GPIO pin. The + * following structure provides an MCU-independent mechanixm for controlling + * the ENC28J60 GPIO interrupt. + * + * The ENC32J60 interrupt is an active low, *level* interrupt. "When an + * interrupt occurs, the interrupt flag is set. If the interrupt is enabled + * in the EIE register and the INTIE global interrupt enable bit is set, the + * INT pin will be driven low" + * + * "When an enabled interrupt occurs, the interrupt pin will remain low until + * all flags which are causing the interrupt are cleared or masked off + * (enable bit is cleared) by the host controller." However, the interrupt + * will behave like a falling edge interrupt because "After an interrupt + * occurs, the host controller [clears] the global enable bit for the + * interrupt pin before servicing the interrupt. Clearing the enable bit + * will cause the interrupt pin to return to the non-asserted state (high). + * Doing so will prevent the host controller from missing a falling edge + * should another interrupt occur while the immediate interrupt is being + * serviced." + */ + +struct enc_lower_s +{ + int (*attach)(FAR const struct enc_lower_s *lower, xcpt_t handler); + void (*enable)(FAR const struct enc_lower_s *lower); + void (*disable)(FAR const struct enc_lower_s *lower); +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -104,10 +134,10 @@ extern "C" { * * Parameters: * spi - A reference to the platform's SPI driver for the ENC28J60 + * lower - The MCU-specific interrupt used to control low-level MCU + * functions (i.e., ENC28J60 GPIO interrupts). * devno - If more than one ENC28J60 is supported, then this is the * zero based number that identifies the ENC28J60; - * irq - The fully configured GPIO IRQ that ENC28J60 interrupts will be - * asserted on. This driver will attach and entable this IRQ. * * Returned Value: * OK on success; Negated errno on failure. @@ -117,8 +147,9 @@ extern "C" { ****************************************************************************/ struct spi_dev_s; /* see nuttx/spi.h */ -EXTERN int enc_initialize(FAR struct spi_dev_s *spi, unsigned int devno, - unsigned int irq); +EXTERN int enc_initialize(FAR struct spi_dev_s *spi, + FAR const struct enc_lower_s *lower, + unsigned int devno); /**************************************************************************** * Function: enc_stats diff --git a/nuttx/include/nuttx/net/uip/uipopt.h b/nuttx/include/nuttx/net/uip/uipopt.h index 4eff56fe85..9797e0482b 100644 --- a/nuttx/include/nuttx/net/uip/uipopt.h +++ b/nuttx/include/nuttx/net/uip/uipopt.h @@ -296,7 +296,23 @@ /* The size of the TCP read buffer size */ #ifndef CONFIG_NET_TCP_READAHEAD_BUFSIZE -# define CONFIG_NET_TCP_READAHEAD_BUFSIZE UIP_TCP_MSS +# if CONFIG_NET_NTCP_READAHEAD_BUFFERS < 1 +# define CONFIG_NET_TCP_READAHEAD_BUFSIZE 0 +# else +# define CONFIG_NET_TCP_READAHEAD_BUFSIZE UIP_TCP_MSS +# endif +#endif + +/* Delay after receive to catch a following packet. No delay should be + * required if TCP/IP read-ahead buffering is enabled. + */ + +#ifndef CONFIG_NET_TCP_RECVDELAY +# if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +# define CONFIG_NET_TCP_RECVDELAY 0 +# else +# define CONFIG_NET_TCP_RECVDELAY 5 +# endif #endif /**************************************************************************** diff --git a/nuttx/include/nuttx/usb/cdc.h b/nuttx/include/nuttx/usb/cdc.h old mode 100755 new mode 100644 diff --git a/nuttx/include/nuttx/usb/usbdev.h b/nuttx/include/nuttx/usb/usbdev.h index 89813cac96..1270fe13ad 100644 --- a/nuttx/include/nuttx/usb/usbdev.h +++ b/nuttx/include/nuttx/usb/usbdev.h @@ -85,7 +85,7 @@ /* Allocate/free an I/O buffer. Should not be called from interrupt processing! */ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA # define EP_ALLOCBUFFER(ep,nb) (ep)->ops->alloc(ep,nb) # define EP_FREEBUFFER(ep,buff) (ep)->ops->free(ep,buf) #else @@ -234,7 +234,7 @@ struct usbdev_epops_s /* Allocate and free I/O buffers */ -#ifdef CONFIG_ARCH_USBDEV_DMA +#ifdef CONFIG_USBDEV_DMA FAR void *(*allocbuffer)(FAR struct usbdev_ep_s *ep, uint16_t nbytes); void (*freebuffer)(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif @@ -354,6 +354,37 @@ EXTERN int usbdev_register(FAR struct usbdevclass_driver_s *driver); EXTERN int usbdev_unregister(FAR struct usbdevclass_driver_s *driver); +/**************************************************************************** + * Name: usbdev_dma_alloc and usbdev_dma_free + * + * Description: + * The USB class driver allocates packet I/O buffers for data transfer by + * calling the driver allocbuffer() and freebuffer() methods. Those + * methods are only available if CONFIG_USBDEV_DMA is defined in the + * system configuration. + * + * If CONFIG_USBDEV_DMAMEMORY is also defined in the NuttX configuration, + * then the driver implementations of the allocbuffer() and freebuffer() + * methods may use board-specific usbdev_dma_alloc() and usbdev_dma_free(). + * If CONFIG_USBDEV_DMA and CONFIG_USBDEV_DMAMEMORY are both defined, + * then the board-specific logic must provide the functions + * usbdev_dma_alloc() and usbdev_dma_free() as prototyped below: + * usbdev_dma_alloc() will allocate DMA-capable memory of the specified + * size; usbdev_dma_free() is the corresponding function that will be + * called to free the DMA-capable memory. + * + * This functions may be simple wrappers around gran_alloc() and + * gran_free() (See nuttx/gran.h). Note that the gran_free() function + * does require the size of the allocation to be freed; that would need + * to be managed in the board-specific logic. + * + ****************************************************************************/ + +#if defined(CONFIG_USBDEV_DMA) && defined(CONFIG_USBDEV_DMAMEMORY) +EXTERN FAR void *usbdev_dma_alloc(size_t size); +EXTERN void usbdev_dma_free(FAR void *memory); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/include/nuttx/usb/usbhost.h b/nuttx/include/nuttx/usb/usbhost.h index 133fd4387a..acfe9a829f 100644 --- a/nuttx/include/nuttx/usb/usbhost.h +++ b/nuttx/include/nuttx/usb/usbhost.h @@ -1,7 +1,7 @@ /************************************************************************************ * include/nuttx/usb/usbhost.h * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -284,7 +284,7 @@ * Some hardware supports special memory in which request and descriptor data can * be accessed more efficiently. This method provides a mechanism to allocate * the request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to malloc. + * such "special" memory, this functions may simply map to kmalloc. * * This interface was optimized under a particular assumption. It was assumed * that the driver maintains a pool of small, pre-allocated buffers for descriptor @@ -317,7 +317,7 @@ * Some hardware supports special memory in which request and descriptor data can * be accessed more efficiently. This method provides a mechanism to free that * request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to free(). + * such "special" memory, this functions may simply map to kfree(). * * Input Parameters: * drvr - The USB host driver instance obtained as a parameter from the call to @@ -342,7 +342,7 @@ * Some hardware supports special memory in which larger IO buffers can * be accessed more efficiently. This method provides a mechanism to allocate * the request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to malloc. + * such "special" memory, this functions may simply map to kmalloc. * * This interface differs from DRVR_ALLOC in that the buffers are variable-sized. * @@ -371,7 +371,7 @@ * Some hardware supports special memory in which IO data can be accessed more * efficiently. This method provides a mechanism to free that IO buffer * memory. If the underlying hardware does not support such "special" memory, - * this functions may simply map to free(). + * this functions may simply map to kfree(). * * Input Parameters: * drvr - The USB host driver instance obtained as a parameter from the call to @@ -448,7 +448,13 @@ * * Returned Values: * On success, zero (OK) is returned. On a failure, a negated errno value is - * returned indicating the nature of the failure + * returned indicating the nature of the failure: + * + * EAGAIN - If devices NAKs the transfer (or NYET or other error where + * it may be appropriate to restart the entire transaction). + * EPERM - If the endpoint stalls + * EIO - On a TX or data toggle error + * EPIPE - Overrun errors * * Assumptions: * This function will *not* be called from an interrupt handler. @@ -553,7 +559,7 @@ struct usbhost_class_s }; /* This structure describes one endpoint. It is used as an input to the - * allocep() method. Most of this information comes from the endpoint + * epalloc() method. Most of this information comes from the endpoint * descriptor. */ @@ -562,12 +568,12 @@ struct usbhost_epdesc_s uint8_t addr; /* Endpoint address */ bool in; /* Direction: true->IN */ uint8_t funcaddr; /* USB address of function containing endpoint */ - uint8_t xfrtype; /* Transfer type. See SB_EP_ATTR_XFER_* in usb.h */ + uint8_t xfrtype; /* Transfer type. See USB_EP_ATTR_XFER_* in usb.h */ uint8_t interval; /* Polling interval */ uint16_t mxpacketsize; /* Max packetsize */ }; -/* This type represents one endpoint configured by the allocep() method. +/* This type represents one endpoint configured by the epalloc() method. * The actual form is know only internally to the USB host controller * (for example, for an OHCI driver, this would probably be a pointer * to an endpoint descriptor). @@ -615,7 +621,7 @@ struct usbhost_driver_s * be accessed more efficiently. The following methods provide a mechanism * to allocate and free the transfer descriptor memory. If the underlying * hardware does not support such "special" memory, these functions may - * simply map to malloc and free. + * simply map to kmalloc and kfree. * * This interface was optimized under a particular assumption. It was assumed * that the driver maintains a pool of small, pre-allocated buffers for descriptor @@ -630,7 +636,7 @@ struct usbhost_driver_s /* Some hardware supports special memory in which larger IO buffers can * be accessed more efficiently. This method provides a mechanism to allocate * the request/descriptor memory. If the underlying hardware does not support - * such "special" memory, this functions may simply map to malloc. + * such "special" memory, this functions may simply map to kmalloc. * * This interface differs from DRVR_ALLOC in that the buffers are variable-sized. */ diff --git a/nuttx/include/nuttx/vt100.h b/nuttx/include/nuttx/vt100.h index a0254e88a6..d834f48f0c 100644 --- a/nuttx/include/nuttx/vt100.h +++ b/nuttx/include/nuttx/vt100.h @@ -105,7 +105,7 @@ #define VT100_CURSORPOS(v,h) {ASCII_ESC, '[', (v), ';', (h), 'H'} /* Move cursor to screen location v,h */ #define VT100_HVHOME {ASCII_ESC, '[', 'f'} /* Move cursor to upper left corner */ -#define VT100_HVHOME_ {ASCII_ESC, '[', ;', 'f'} /* Move cursor to upper left corner */ +#define VT100_HVHOME_ {ASCII_ESC, '[', ';', 'f'} /* Move cursor to upper left corner */ #define VT100_HVPOS(v,h) {ASCII_ESC, '[', (v), ';', (h), 'f'} /* Move cursor to screen location v,h */ #define VT100_INDEX {ASCII_ESC, 'D'} /* Move/scroll window up one line */ #define VT100_REVINDEX {ASCII_ESC, 'M'} /* Move/scroll window down one line */ @@ -138,7 +138,7 @@ #define VT100_TERMNOK {ASCII_ESC, '3', 'n'} /* Response: terminal is not OK */ #define VT100_GETCURSOR {ASCII_ESC, '6', 'n'} /* Get cursor position */ -#define VT100_CURSORPOS {ASCII_ESC, (v), ';', (h), 'R'} /* Response: cursor is at v,h */ +#define VT100_CURSORPOSAT {ASCII_ESC, (v), ';', (h), 'R'} /* Response: cursor is at v,h */ #define VT100_IDENT {ASCII_ESC, '[', 'c'} /* Identify what terminal type */ #define VT100_IDENT_ {ASCII_ESC, '[', '0', 'c'} /* Identify what terminal type */ diff --git a/nuttx/include/nuttx/watchdog.h b/nuttx/include/nuttx/watchdog.h old mode 100755 new mode 100644 diff --git a/nuttx/include/nuttx/wqueue.h b/nuttx/include/nuttx/wqueue.h index dfd424c8dc..644585c56f 100644 --- a/nuttx/include/nuttx/wqueue.h +++ b/nuttx/include/nuttx/wqueue.h @@ -50,6 +50,75 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ +/* CONFIG_SCHED_WORKQUEUE. Create a dedicated "worker" thread to + * handle delayed processing from interrupt handlers. This feature + * is required for some drivers but, if there are not complaints, + * can be safely disabled. The worker thread also performs + * garbage collection -- completing any delayed memory deallocations + * from interrupt handlers. If the worker thread is disabled, + * then that clean will be performed by the IDLE thread instead + * (which runs at the lowest of priority and may not be appropriate + * if memory reclamation is of high priority). If CONFIG_SCHED_WORKQUEUE + * is enabled, then the following options can also be used: + * CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker + * thread. Default: 192 + * CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for + * work in units of microseconds. Default: 50*1000 (50 MS). + * CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker + * thread. Default: CONFIG_IDLETHREAD_STACKSIZE. + * CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up + * the worker thread. Default: 4 + * + * CONFIG_SCHED_LPWORK. If CONFIG_SCHED_WORKQUEUE is defined, then a single + * work queue is created by default. If CONFIG_SCHED_LPWORK is also defined + * then an additional, lower-priority work queue will also be created. This + * lower priority work queue is better suited for more extended processing + * (such as file system clean-up operations) + * CONFIG_SCHED_LPWORKPRIORITY - The execution priority of the lower priority + * worker thread. Default: 50 + * CONFIG_SCHED_LPWORKPERIOD - How often the lower priority worker thread + * checks for work in units of microseconds. Default: 50*1000 (50 MS). + * CONFIG_SCHED_LPWORKSTACKSIZE - The stack size allocated for the lower + * priority worker thread. Default: CONFIG_IDLETHREAD_STACKSIZE. + */ + +#ifndef CONFIG_SCHED_WORKPRIORITY +# define CONFIG_SCHED_WORKPRIORITY 192 +#endif + +#ifndef CONFIG_SCHED_WORKPERIOD +# define CONFIG_SCHED_WORKPERIOD (50*1000) /* 50 milliseconds */ +#endif + +#ifndef CONFIG_SCHED_WORKSTACKSIZE +# define CONFIG_SCHED_WORKSTACKSIZE CONFIG_IDLETHREAD_STACKSIZE +#endif + +#ifdef CONFIG_SCHED_LPWORK +# ifndef CONFIG_SCHED_LPWORKPRIORITY +# define CONFIG_SCHED_LPWORKPRIORITY 50 +# endif + +# ifndef CONFIG_SCHED_LPWORKPERIOD +# define CONFIG_SCHED_LPWORKPERIOD (50*1000) /* 50 milliseconds */ +# endif + +# ifndef CONFIG_SCHED_LPWORKSTACKSIZE +# define CONFIG_SCHED_LPWORKSTACKSIZE CONFIG_IDLETHREAD_STACKSIZE +# endif +#endif + +/* Work queue IDs (indices). These are both zero if there is only one work + * queue. + */ + +#define HPWORK 0 +#ifdef CONFIG_SCHED_LPWORK +# define LPWORK 1 +#else +# define LPWORK HPWORK +#endif /**************************************************************************** * Public Types @@ -86,10 +155,6 @@ extern "C" { #define EXTERN extern #endif -/* The task ID of the worker thread */ - -EXTERN pid_t g_worker; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -109,6 +174,7 @@ EXTERN pid_t g_worker; * and remove it from the work queue. * * Input parameters: + * qid - The work queue ID * work - The work structure to queue * worker - The worker callback to be invoked. The callback will invoked * on the worker thread of execution. @@ -122,7 +188,8 @@ EXTERN pid_t g_worker; * ****************************************************************************/ -EXTERN int work_queue(struct work_s *work, worker_t worker, FAR void *arg, uint32_t delay); +EXTERN int work_queue(int qid, FAR struct work_s *work, worker_t worker, + FAR void *arg, uint32_t delay); /**************************************************************************** * Name: work_cancel @@ -133,6 +200,7 @@ EXTERN int work_queue(struct work_s *work, worker_t worker, FAR void *arg, uint3 * again. * * Input parameters: + * qid - The work queue ID * work - The previously queue work structure to cancel * * Returned Value: @@ -140,7 +208,7 @@ EXTERN int work_queue(struct work_s *work, worker_t worker, FAR void *arg, uint3 * ****************************************************************************/ -EXTERN int work_cancel(struct work_s *work); +EXTERN int work_cancel(int qid, FAR struct work_s *work); /**************************************************************************** * Name: work_signal @@ -151,14 +219,14 @@ EXTERN int work_cancel(struct work_s *work); * user to force an immediate re-assessment of pending work. * * Input parameters: - * None + * qid - The work queue ID * * Returned Value: * Zero on success, a negated errno on failure * ****************************************************************************/ -#define work_signal() kill(g_worker, SIGWORK) +EXTERN int work_signal(int qid); /**************************************************************************** * Name: work_available diff --git a/nuttx/include/semaphore.h b/nuttx/include/semaphore.h index 85214b9c20..257a5826f3 100644 --- a/nuttx/include/semaphore.h +++ b/nuttx/include/semaphore.h @@ -60,16 +60,16 @@ extern "C" { * Public Type Declarations ****************************************************************************/ -/* This structure contains the holder of a semaphore */ +/* This structure contains information about the holder of a semaphore */ #ifdef CONFIG_PRIORITY_INHERITANCE struct semholder_s { #if CONFIG_SEM_PREALLOCHOLDERS > 0 - struct semholder_s *flink; /* Implements singly linked list */ + struct semholder_s *flink; /* Implements singly linked list */ #endif - void *holder; /* Holder TCB (actual type is _TCB) */ - int16_t counts; /* Number of counts owned by this holder */ + void *htcb; /* Holder TCB (actual type is _TCB) */ + int16_t counts; /* Number of counts owned by this holder */ }; #if CONFIG_SEM_PREALLOCHOLDERS > 0 @@ -83,12 +83,21 @@ struct semholder_s struct sem_s { - int16_t semcount; /* >0 -> Num counts available */ - /* <0 -> Num tasks waiting for semaphore */ + int16_t semcount; /* >0 -> Num counts available */ + /* <0 -> Num tasks waiting for semaphore */ + /* If priority inheritance is enabled, then we have to keep track of which + * tasks hold references to the semaphore. + */ + #ifdef CONFIG_PRIORITY_INHERITANCE - struct semholder_s hlist; /* List of holders of semaphore counts */ +# if CONFIG_SEM_PREALLOCHOLDERS > 0 + FAR struct semholder_s *hhead; /* List of holders of semaphore counts */ +# else + struct semholder_s holder; /* Single holder */ +# endif #endif }; + typedef struct sem_s sem_t; /* Initializers */ diff --git a/nuttx/include/stdio.h b/nuttx/include/stdio.h index 82bf0eaf6d..e9218046c5 100644 --- a/nuttx/include/stdio.h +++ b/nuttx/include/stdio.h @@ -128,6 +128,7 @@ EXTERN int sprintf(FAR char *buf, const char *format, ...); EXTERN int asprintf (FAR char **ptr, const char *fmt, ...); EXTERN int snprintf(FAR char *buf, size_t size, const char *format, ...); EXTERN int sscanf(const char *buf, const char *fmt, ...); +EXTERN void perror(FAR const char *s); EXTERN int ungetc(int c, FAR FILE *stream); EXTERN int vprintf(FAR const char *format, va_list ap); diff --git a/nuttx/include/sys/sendfile.h b/nuttx/include/sys/sendfile.h new file mode 100644 index 0000000000..0f3c05444a --- /dev/null +++ b/nuttx/include/sys/sendfile.h @@ -0,0 +1,123 @@ +/**************************************************************************** + * include/sys/sendfile.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SYS_SENDFILE_H +#define __INCLUDE_SYS_SENDFILE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_LIB_SENDFILE_BUFSIZE +# define CONFIG_LIB_SENDFILE_BUFSIZE 512 +#endif + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/************************************************************************ + * Name: sendfile + * + * Description: + * sendfile() copies data between one file descriptor and another. + * sendfile() basically just wraps a sequence of reads() and writes() + * to perform a copy. It serves a purpose in systems where there is + * a penalty for copies to between user and kernal space, but really + * nothing in NuttX but provide some Linux compatible (and adding + * another 'almost standard' interface). + * + * NOTE: This interface is *not* specified in POSIX.1-2001, or other + * standards. The implementation here is very similar to the Linux + * sendfile interface. Other UNIX systems implement sendfile() with + * different semantics and prototypes. sendfile() should not be used + * in portable programs. + * + * Input Parmeters: + * infd - A file (or socket) descriptor opened for reading + * outfd - A descriptor opened for writing. + * offset - If 'offset' is not NULL, then it points to a variable + * holding the file offset from which sendfile() will start + * reading data from 'infd'. When sendfile() returns, this + * variable will be set to the offset of the byte following + * the last byte that was read. If 'offset' is not NULL, + * then sendfile() does not modify the current file offset of + * 'infd'; otherwise the current file offset is adjusted to + * reflect the number of bytes read from 'infd.' + * + * If 'offset' is NULL, then data will be read from 'infd' + * starting at the current file offset, and the file offset + * will be updated by the call. + * count - The number of bytes to copy between the file descriptors. + * + * Returned Value: + * If the transfer was successful, the number of bytes written to outfd is + * returned. On error, -1 is returned, and errno is set appropriately. + * There error values are those returned by read() or write() plus: + * + * EINVAL - Bad input parameters. + * ENOMEM - Could not allocated an I/O buffer + * + ************************************************************************/ + +EXTERN ssize_t sendfile (int outfd, int infd, FAR off_t *offset, size_t count); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_SYS_SENDFILE_H */ diff --git a/nuttx/lib/Kconfig b/nuttx/lib/Kconfig index 9e60201c2f..69a55d09cf 100644 --- a/nuttx/lib/Kconfig +++ b/nuttx/lib/Kconfig @@ -23,7 +23,7 @@ config NUNGET_CHARS ---help--- Number of characters that can be buffered by ungetc() (Only if NFILE_STREAMS > 0) -config CONFIG_LIB_HOMEDIR +config LIB_HOMEDIR string "Home directory" default "/" depends on !DISABLE_ENVIRON @@ -51,26 +51,107 @@ config LIBC_FLOATINGPOINT By default, floating point support in printf, sscanf, etc. is disabled. +choice + prompt "Newline Options" + default EOL_IS_EITHER_CRLF + ---help--- + This selection determines the line terminating character that is used. + Some environments may return CR as end-of-line, others LF, and others + both. If not specified, the default is either CR or LF (but not both) + as the line terminating charactor. + +config EOL_IS_CR + bool "EOL is CR" + +config EOL_IS_LF + bool "EOL is LF" + +config EOL_IS_BOTH_CRLF + bool "EOL is CR and LF" + +config EOL_IS_EITHER_CRLF + bool "EOL is CR or LF" + +endchoice + +config LIBC_STRERROR + bool "Enable strerror" + default n + ---help--- + strerror() is useful because it decodes 'errno' values into a human readable + strings. But it can also require a lot of memory. If this option is selected, + strerror() will still exist in the build but it will not decode error values. + This option should be used by other logic to decide if it should use strerror() + or not. For example, the NSH application will not use strerror() if this + option is not selected; perror() will not use strerror() is this option is not + selected (see also NSH_STRERROR). + +config LIBC_STRERROR_SHORT + bool "Use short error descriptions in strerror()" + default n + depends on LIBC_STRERROR + ---help--- + If this option is selected, then strerror() will use a shortened string when + it decodes the error. Specifically, strerror() is simply use the string that + is the common name for the error. For example, the 'errno' value of 2 will + produce the string "No such file or directory" is LIBC_STRERROR_SHORT + is not defined but the string "ENOENT" is LIBC_STRERROR_SHORT is defined. + +config LIBC_PERROR_STDOUT + bool "perror() to stdout" + default n + ---help--- + POSIX requires that perror() provide its output on stderr. This option may + be defined, however, to provide perror() output that is serialized with + other stdout messages. + config ARCH_LOWPUTC bool "Low-level console output" default "y" ---help--- - architecture supports low-level, boot time console output - -config ENABLE_ARCH_OPTIMIZED_FUN + architecture supports low-level, boot time console output + +config LIB_SENDFILE_BUFSIZE + int "sendfile() buffer size" + default 512 + ---help--- + Size of the I/O buffer to allocate in sendfile(). Default: 512b + +config ARCH_ROMGETC + bool "Support for ROM string access" + default n + ---help--- + In Harvard architectures, data accesses and instruction accesses + occur on different busses, perhaps concurrently. All data accesses + are performed on the data bus unless special machine instructions + are used to read data from the instruction address space. Also, in + the typical MCU, the available SRAM data memory is much smaller that + the non-volatile FLASH instruction memory. So if the application + requires many constant strings, the only practical solution may be + to store those constant strings in FLASH memory where they can only + be accessed using architecture-specific machine instructions. + + If ARCH_ROMGETC is defined, then the architecture logic must export + the function up_romgetc(). up_romgetc() will simply read one byte + of data from the instruction space. + + If ARCH_ROMGETC, certain C stdio functions are effected: (1) All + format strings in printf, fprintf, sprintf, etc. are assumed to lie + in FLASH (string arguments for %s are still assumed to reside in SRAM). + And (2), the string argument to puts and fputs is assumed to reside + in FLASH. Clearly, these assumptions may have to modified for the + particular needs of your environment. There is no "one-size-fits-all" + solution for this problem. + +config ARCH_OPTIMIZED_FUNCTIONS bool "Enable arch optimized functions" default n ---help--- - Allow for architecture optimized implementations - - The architecture can provide optimized versions of the - following to improve system performance + Allow for architecture optimized implementations of certain library + functions. Architecture-specific implementations can improve overall + system performance. - The architecture may provide custom versions of certain - standard header files: - config ARCH_MATH_H, CONFIG_ARCH_STDBOOL_H, CONFIG_ARCH_STDINT_H - -if ENABLE_ARCH_OPTIMIZED_FUN +if ARCH_OPTIMIZED_FUNCTIONS config ARCH_MEMCPY bool "memcpy" default n diff --git a/nuttx/lib/README.txt b/nuttx/lib/README.txt index 62e2fcce2e..63d1c343c0 100644 --- a/nuttx/lib/README.txt +++ b/nuttx/lib/README.txt @@ -45,3 +45,40 @@ directory: misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h +Library Database +================ + +Information about functions available in the NuttX C library information is +maintained in a database. That "database" is implemented as a simple comma- +separated-value file, lib.csv. Most spreadsheets programs will accept this +format and can be used to maintain the library database. + +This library database will (eventually) be used to generate symbol library +symbol table information that can be exported to external applications. + +The format of the CSV file for each line is: + + Field 1: Function name + Field 2: The header file that contains the function prototype + Field 3: Condition for compilation + Field 4: The type of function return value. + Field 5 - N+5: The type of each of the N formal parameters of the function + +Each type field has a format as follows: + + type name: + For all simpler types + formal type | actual type: + For array types where the form of the formal (eg. int parm[2]) + differs from the type of actual passed parameter (eg. int*). This + is necessary because you cannot do simple casts to array types. + formal type | union member actual type | union member fieldname: + A similar situation exists for unions. For example, the formal + parameter type union sigval -- You cannot cast a uintptr_t to + a union sigval, but you can cast to the type of one of the union + member types when passing the actual paramter. Similarly, we + cannot cast a union sigval to a uinptr_t either. Rather, we need + to cast a specific union member fieldname to uintptr_t. + +NOTE: The tool mksymtab can be used to generate a symbol table from this CSV +file. See nuttx/tools/README.txt for further details about the use of mksymtab. diff --git a/nuttx/lib/lib.csv b/nuttx/lib/lib.csv new file mode 100644 index 0000000000..171f64e9b7 --- /dev/null +++ b/nuttx/lib/lib.csv @@ -0,0 +1,171 @@ +"_inet_ntoa","arpa/inet.h","!defined(CONFIG_NET_IPv6) && !defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","in_addr_t" +"abort","stdlib.h","","void" +"abs","stdlib.h","","int","int" +"asprintf","stdio.h","","int","FAR char **","const char *","..." +"avsprintf","stdio.h","","int","FAR char **","const char *","va_list" +"b16atan2","fixedmath.h","","b16_t","b16_t","b16_t" +"b16cos","fixedmath.h","","b16_t","b16_t" +"b16divb16","fixedmath.h","","b16_t","b16_t","b16_t" +"b16mulb16","fixedmath.h","","b16_t","b16_t","b16_t" +"b16sin","fixedmath.h","","b16_t","b16_t" +"b16sqr","fixedmath.h","","b16_t","b16_t" +"basename","libgen.h","","FAR char","FAR char *" +"cfgetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *" +"cfsetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t" +"chdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" +"crc32","crc32.h","","uint32_t","FAR const uint8_t *","size_t" +"crc32part","crc32.h","","uint32_t","FAR const uint8_t *","size_t","uint32_t" +"dbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG)","int","const char *","..." +"dbg_enable","debug.h","defined(CONFIG_DEBUG_ENABLE)","void","bool" +"dirname","libgen.h","","FAR char","FAR char *" +"dq_addafter","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" +"dq_addbefore","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" +"dq_addfirst","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" +"dq_addlast","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" +"dq_rem","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" +"dq_remfirst","queue.h","","FAR dq_entry_t","dq_queue_t *" +"dq_remlast","queue.h","","FAR dq_entry_t","dq_queue_t *" +"ether_ntoa","netinet/ether.h","","FAR char","FAR const struct ether_addr *" +"fclose","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" +"fdopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","int","FAR const char *" +"fflush","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" +"fgetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" +"fgetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *" +"fgets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *","int","FAR FILE *" +"fileno","stdio.h","","int","FAR FILE *" +"fopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","FAR const char *","FAR const char *" +"fprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR const char *","..." +"fputc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int c","FAR FILE *" +"fputs","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","FAR FILE *" +"fread","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR void *","size_t","size_t","FAR FILE *" +"fseek","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","long int","int" +"fsetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *" +"ftell","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","long","FAR FILE *" +"fwrite","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR const void *","size_t","size_t","FAR FILE *" +"getcwd","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","FAR char","FAR char *","size_t" +"getopt","unistd.h","","int","int","FAR char *const[]","FAR const char *" +"getoptargp","unistd.h","","FAR char *" +"getoptindp","unistd.h","","int" +"getoptoptp","unistd.h","","int" +"gets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *" +"gmtime","time.h","","struct tm","const time_t *" +"gmtime_r","time.h","","FAR struct tm","FAR const time_t *","FAR struct tm *" +"htonl","arpa/inet.h","","uint32_t","uint32_t" +"htons","arpa/inet.h","","uint16_t","uint16_t" +"imaxabs","stdlib.h","","intmax_t","intmax_t" +"inet_addr","arpa/inet.h","","in_addr_t","FAR const char " +"inet_ntoa","arpa/inet.h","!defined(CONFIG_NET_IPv6) && defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","struct in_addr" +"inet_ntop","arpa/inet.h","","FAR const char","int","FAR const void *","FAR char *","socklen_t" +"inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *" +"labs","stdlib.h","","long int","long int" +"lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int" +"lib_lowprintf","debug.h","","int","FAR const char *","..." +"lib_rawprintf","debug.h","","int","FAR const char *","..." +"llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" +"lldbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." +"llvdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." +"match","","","int","const char *","const char *" +"memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" +"memchr","string.h","","FAR void","FAR const void *","int c","size_t" +"memcmp","string.h","","int","FAR const void *","FAR const void *","size_t" +"memcpy","string.h","","FAR void","FAR void *","FAR const void *","size_t" +"memmove","string.h","","FAR void","FAR void *","FAR const void *","size_t" +"memset","string.h","","FAR void","FAR void *","int c","size_t" +"mktime","time.h","","time_t","const struct tm *" +"mq_getattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","struct mq_attr *" +"mq_setattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const struct mq_attr *","struct mq_attr *" +"ntohl","arpa/inet.h","","uint32_t","uint32_t" +"ntohs","arpa/inet.h","","uint16_t","uint16_t" +"perror","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","void","FAR const char *" +"printf","stdio.h","","int","const char *","..." +"pthread_attr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" +"pthread_attr_getinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR int *" +"pthread_attr_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR struct sched_param *" +"pthread_attr_getschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int *" +"pthread_attr_getstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR long *" +"pthread_attr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" +"pthread_attr_setinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int" +"pthread_attr_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR const struct sched_param *" +"pthread_attr_setschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int" +"pthread_attr_setstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","long" +"pthread_barrierattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *" +"pthread_barrierattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_barrierattr_t *","FAR int *" +"pthread_barrierattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *" +"pthread_barrierattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *","int" +"pthread_condattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" +"pthread_condattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" +"pthread_mutexattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" +"pthread_mutexattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","FAR int *" +"pthread_mutexattr_gettype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","const pthread_mutexattr_t *","int *" +"pthread_mutexattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" +"pthread_mutexattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","int " +"pthread_mutexattr_settype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","pthread_mutexattr_t *","int" +"puts","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *" +"qsort","stdlib.h","","void","void *","size_t","size_t","int(*)(const void *","const void *)" +"rand","stdlib.h","","int" +"readdir_r","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR *","FAR struct dirent *","FAR struct dirent **" +"rint","","","double_t","double_t" +"sched_get_priority_max","sched.h","","int","int" +"sched_get_priority_min","sched.h","","int","int" +"sem_getvalue","semaphore.h","","int","FAR sem_t *","FAR int *" +"sem_init","semaphore.h","","int","FAR sem_t *","int","unsigned int" +"sendfile","sys/sendfile.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","int","off_t","size_t" +"sigaddset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int" +"sigdelset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int" +"sigemptyset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" +"sigfillset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" +"sigismember","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t *","int" +"snprintf","stdio.h","","int","FAR char *","size_t","const char *","..." +"sprintf","stdio.h","","int","FAR char *","const char *","..." +"sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *" +"sq_addfirst","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" +"sq_addlast","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" +"sq_rem","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" +"sq_remafter","queue.h","","FAR sq_entry_t","FAR sq_entry_t *","sq_queue_t *" +"sq_remfirst","queue.h","","FAR sq_entry_t","sq_queue_t *" +"sq_remlast","queue.h","","FAR sq_entry_t","sq_queue_t *" +"srand","stdlib.h","","void","unsigned int" +"sscanf","stdio.h","","int","const char *","const char *","..." +"strcasecmp","string.h","","int","FAR const char *","FAR const char *" +"strcasestr","string.h","","FAR char","FAR const char *","FAR const char *" +"strcat","string.h","","FAR char","FAR char *","FAR const char *" +"strchr","string.h","","FAR char","FAR const char *","int" +"strcmp","string.h","","int","FAR const char *","FAR const char *" +"strcpy","string.h","","FAR char","char *","FAR const char *" +"strcspn","string.h","","size_t","FAR const char *","FAR const char *" +"strdup","string.h","","FAR char","FAR const char *" +"strerror","string.h","","FAR const char","int" +"strftime","time.h","","size_t","char *","size_t","const char *","const struct tm *" +"strlen","string.h","","size_t","FAR const char *" +"strncasecmp","string.h","","int","FAR const char *","FAR const char *","size_t" +"strncat","string.h","","FAR char","FAR char *","FAR const char *","size_t" +"strncmp","string.h","","int","FAR const char *","FAR const char *","size_t" +"strncpy","string.h","","FAR char","char *","FAR const char *","size_t" +"strndup","string.h","","FAR char","FAR const char *","size_t" +"strnlen","string.h","","size_t","FAR const char *","size_t" +"strpbrk","string.h","","FAR char","FAR const char *","FAR const char *" +"strrchr","string.h","","FAR char","FAR const char *","int" +"strspn","string.h","","size_t","FAR const char *","FAR const char *" +"strstr","string.h","","FAR char","FAR const char *","FAR const char *" +"strtod","stdlib.h","","double_t","const char *str","char **endptr" +"strtok","string.h","","FAR char","FAR char *","FAR const char *" +"strtok_r","string.h","","FAR char","FAR char *","FAR const char *","FAR char **" +"strtol","string.h","","long","const char *","char **","int" +"strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","const char *nptr","char **endptr","int base" +"strtoul","stdlib.h","","unsigned long","const char *","char **","int" +"strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","const char *","char **","int" +"tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int" +"tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" +"tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" +"telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR *" +"time","time.h","","time_t","time_t *" +"ub16divub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" +"ub16mulub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" +"ub16sqr","fixedmath.h","","ub16_t","ub16_t" +"ungetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int","FAR FILE *" +"vdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE)","int","const char *","..." +"vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","const char *","va_list" +"vprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","va_list" +"vsnprintf","stdio.h","","int","FAR char *","size_t","const char *","va_list" +"vsprintf","stdio.h","","int","FAR char *","const char *","va_list" +"vsscanf","stdio.h","","int","char *","const char *","va_list" diff --git a/nuttx/lib/libgen/lib_basename.c b/nuttx/lib/libgen/lib_basename.c index 5741d976a9..986c6b8520 100644 --- a/nuttx/lib/libgen/lib_basename.c +++ b/nuttx/lib/libgen/lib_basename.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/libgen/lib_basename.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -78,7 +78,7 @@ static char g_retchar[2]; * ****************************************************************************/ -char *basename(char *path) +FAR char *basename(FAR char *path) { char *p; int len; diff --git a/nuttx/lib/libgen/lib_dirname.c b/nuttx/lib/libgen/lib_dirname.c index c416d8aca3..248293a605 100644 --- a/nuttx/lib/libgen/lib_dirname.c +++ b/nuttx/lib/libgen/lib_dirname.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/libgen/lib_dirname.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -78,7 +78,7 @@ static char g_retchar[2]; * ****************************************************************************/ -char *dirname(char *path) +FAR char *dirname(FAR char *path) { char *p; int len; diff --git a/nuttx/lib/math/lib_b16atan2.c b/nuttx/lib/math/lib_b16atan2.c index a396524517..8792fa0879 100644 --- a/nuttx/lib/math/lib_b16atan2.c +++ b/nuttx/lib/math/lib_b16atan2.c @@ -2,7 +2,7 @@ * lib/math/lib_b16atan2.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/math/lib_b16cos.c b/nuttx/lib/math/lib_b16cos.c index 69cc610425..7547871f63 100644 --- a/nuttx/lib/math/lib_b16cos.c +++ b/nuttx/lib/math/lib_b16cos.c @@ -2,7 +2,7 @@ * lib/math/lib_b16cos.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/math/lib_b16sin.c b/nuttx/lib/math/lib_b16sin.c index fc4b5e5663..1eee179934 100644 --- a/nuttx/lib/math/lib_b16sin.c +++ b/nuttx/lib/math/lib_b16sin.c @@ -2,7 +2,7 @@ * lib/math/lib_b16sin.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/math/lib_fixedmath.c b/nuttx/lib/math/lib_fixedmath.c index b20158dc85..c1a710e739 100644 --- a/nuttx/lib/math/lib_fixedmath.c +++ b/nuttx/lib/math/lib_fixedmath.c @@ -2,7 +2,7 @@ * lib/math/lib_fixedmath.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -165,7 +165,7 @@ ub16_t ub16mulub16(ub16_t m1, ub16_t m2) } /**************************************************************************** - * Name: b16divb16 + * Name: b16sqr **************************************************************************/ b16_t b16sqr(b16_t a) diff --git a/nuttx/lib/math/lib_rint.c b/nuttx/lib/math/lib_rint.c index b122870b81..bd861ecedc 100644 --- a/nuttx/lib/math/lib_rint.c +++ b/nuttx/lib/math/lib_rint.c @@ -2,7 +2,7 @@ * lib/math/lib_rint.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/misc/Make.defs b/nuttx/lib/misc/Make.defs index 484f822d0f..c12533f754 100644 --- a/nuttx/lib/misc/Make.defs +++ b/nuttx/lib/misc/Make.defs @@ -37,9 +37,23 @@ CSRCS += lib_init.c lib_filesem.c +# Add C files that depend on file OR socket descriptors + ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) + +CSRCS += lib_sendfile.c ifneq ($(CONFIG_NFILE_STREAMS),0) CSRCS += lib_streamsem.c +endif + +else +ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) + +CSRCS += lib_sendfile.c +ifneq ($(CONFIG_NFILE_STREAMS),0) +CSRCS += lib_streamsem.c +endif + endif endif diff --git a/nuttx/lib/misc/lib_dbg.c b/nuttx/lib/misc/lib_dbg.c index 6f326bf4fc..aacdaa30a9 100644 --- a/nuttx/lib/misc/lib_dbg.c +++ b/nuttx/lib/misc/lib_dbg.c @@ -2,7 +2,7 @@ * lib/misc/lib_dbg.c * * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/misc/lib_dumpbuffer.c b/nuttx/lib/misc/lib_dumpbuffer.c index 1f1f54e8db..155468ca12 100644 --- a/nuttx/lib/misc/lib_dumpbuffer.c +++ b/nuttx/lib/misc/lib_dumpbuffer.c @@ -2,7 +2,7 @@ * lib/misc/lib_dumpbuffer.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/misc/lib_filesem.c b/nuttx/lib/misc/lib_filesem.c index e6a3fdb671..1d1f25c2fd 100644 --- a/nuttx/lib/misc/lib_filesem.c +++ b/nuttx/lib/misc/lib_filesem.c @@ -2,7 +2,7 @@ * lib/misc/lib_filesem.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/misc/lib_init.c b/nuttx/lib/misc/lib_init.c index fb246b1ad3..3403a837b9 100644 --- a/nuttx/lib/misc/lib_init.c +++ b/nuttx/lib/misc/lib_init.c @@ -2,7 +2,7 @@ * lib/misc/lib_init.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/misc/lib_sendfile.c b/nuttx/lib/misc/lib_sendfile.c new file mode 100644 index 0000000000..a82eb325e7 --- /dev/null +++ b/nuttx/lib/misc/lib_sendfile.c @@ -0,0 +1,297 @@ +/************************************************************************ + * lib/misc/lib_streamsem.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 + +/************************************************************************ + * Private types + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Public Variables + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: sendfile + * + * Description: + * sendfile() copies data between one file descriptor and another. + * sendfile() basically just wraps a sequence of reads() and writes() + * to perform a copy. It serves a purpose in systems where there is + * a penalty for copies to between user and kernal space, but really + * nothing in NuttX but provide some Linux compatible (and adding + * another 'almost standard' interface). + * + * NOTE: This interface is *not* specified in POSIX.1-2001, or other + * standards. The implementation here is very similar to the Linux + * sendfile interface. Other UNIX systems implement sendfile() with + * different semantics and prototypes. sendfile() should not be used + * in portable programs. + * + * Input Parmeters: + * infd - A file (or socket) descriptor opened for reading + * outfd - A descriptor opened for writing. + * offset - If 'offset' is not NULL, then it points to a variable + * holding the file offset from which sendfile() will start + * reading data from 'infd'. When sendfile() returns, this + * variable will be set to the offset of the byte following + * the last byte that was read. If 'offset' is not NULL, + * then sendfile() does not modify the current file offset of + * 'infd'; otherwise the current file offset is adjusted to + * reflect the number of bytes read from 'infd.' + * + * If 'offset' is NULL, then data will be read from 'infd' + * starting at the current file offset, and the file offset + * will be updated by the call. + * count - The number of bytes to copy between the file descriptors. + * + * Returned Value: + * If the transfer was successful, the number of bytes written to outfd is + * returned. On error, -1 is returned, and errno is set appropriately. + * There error values are those returned by read() or write() plus: + * + * EINVAL - Bad input parameters. + * ENOMEM - Could not allocated an I/O buffer + * + ************************************************************************/ + +ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) +{ + FAR uint8_t *iobuffer; + FAR uint8_t *wrbuffer; + off_t startpos = 0; + ssize_t nbytesread; + ssize_t nbyteswritten; + size_t ntransferred; + bool endxfr; + + /* Get the current file position. */ + + if (offset) + { + /* Use lseek to get the current file position */ + + startpos = lseek(infd, 0, SEEK_CUR); + if (startpos == (off_t)-1) + { + return ERROR; + } + + /* Use lseek again to set the new file position */ + + if (lseek(infd, *offset, SEEK_SET) == (off_t)-1) + { + return ERROR; + } + } + + /* Allocate an I/O buffer */ + + iobuffer = (FAR void *)malloc(CONFIG_LIB_SENDFILE_BUFSIZE); + if (!iobuffer) + { + set_errno(ENOMEM); + return ERROR; + } + + /* Now transfer 'count' bytes from the infd to the outfd */ + + for (ntransferred = 0, endxfr = false; ntransferred < count && !endxfr; ) + { + /* Loop until the read side of the transfer comes to some conclusion */ + + do + { + /* Read a buffer of data from the infd */ + + nbytesread = read(infd, iobuffer, CONFIG_LIB_SENDFILE_BUFSIZE); + + /* Check for end of file */ + + if (nbytesread == 0) + { + /* End of file. Break out and return current number of bytes + * transferred. + */ + + endxfr = true; + break; + } + + /* Check for a read ERROR. EINTR is a special case. This function + * should break out and return an error if EINTR is returned and + * no data has been transferred. But what should it do if some + * data has been transferred? I suppose just continue? + */ + + else if (nbytesread < 0) + { + /* EINTR is not an error (but will still stop the copy) */ + +#ifndef CONFIG_DISABLE_SIGNALS + if (errno != EINTR || ntransferred == 0) +#endif + { + /* Read error. Break out and return the error condition. */ + + ntransferred = ERROR; + endxfr = true; + break; + } + } + } + while (nbytesread < 0); + + /* Was anything read? */ + + if (!endxfr) + { + /* Yes.. Loop until the read side of the transfer comes to some + * conclusion. + */ + + wrbuffer = iobuffer; + do + { + /* Write the buffer of data to the outfd */ + + nbyteswritten = write(outfd, wrbuffer, nbytesread); + + /* Check for a complete (or parial) write. write() should not + * return zero. + */ + + if (nbyteswritten >= 0) + { + /* Advance the buffer pointer and decrement the number of bytes + * remaining in the iobuffer. Typically, nbytesread will now + * be zero. + */ + + wrbuffer += nbyteswritten; + nbytesread -= nbyteswritten; + + /* Increment the total number of bytes successfully transferred. */ + + ntransferred += nbyteswritten; + } + + /* Otherwise an error occurred */ + + else + { + /* Check for a read ERROR. EINTR is a special case. This + * function should break out and return an error if EINTR + * is returned and no data has been transferred. But what + * should it do if some data has been transferred? I + * suppose just continue? + */ + +#ifndef CONFIG_DISABLE_SIGNALS + if (errno != EINTR || ntransferred == 0) +#endif + { + /* Write error. Break out and return the error condition */ + + ntransferred = ERROR; + endxfr = true; + break; + } + } + } + while (nbytesread > 0); + } + } + + /* Release the I/O buffer */ + + free(iobuffer); + + /* Return the current file position */ + + if (offset) + { + /* Use lseek to get the current file position */ + + off_t curpos = lseek(infd, 0, SEEK_CUR); + if (curpos == (off_t)-1) + { + return ERROR; + } + + /* Return the current file position */ + + *offset = curpos; + + /* Use lseek again to restore the original file position */ + + if (lseek(infd, startpos, SEEK_SET) == (off_t)-1) + { + return ERROR; + } + } + + /* Finally return the number of bytes actually transferred (or ERROR + * if any failure occurred). + */ + + return ntransferred; +} + +#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 */ diff --git a/nuttx/lib/misc/lib_streamsem.c b/nuttx/lib/misc/lib_streamsem.c index 3d86ab280e..fdf494e751 100644 --- a/nuttx/lib/misc/lib_streamsem.c +++ b/nuttx/lib/misc/lib_streamsem.c @@ -2,7 +2,7 @@ * lib/misc/lib_streamsem.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/mqueue/mq_getattr.c b/nuttx/lib/mqueue/mq_getattr.c index 005ec0f245..9c9f47fdce 100644 --- a/nuttx/lib/mqueue/mq_getattr.c +++ b/nuttx/lib/mqueue/mq_getattr.c @@ -2,7 +2,7 @@ * lib/mqueue/mq_getattr.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/mqueue/mq_setattr.c b/nuttx/lib/mqueue/mq_setattr.c index 5d82299fe7..1276d64e8a 100644 --- a/nuttx/lib/mqueue/mq_setattr.c +++ b/nuttx/lib/mqueue/mq_setattr.c @@ -2,7 +2,7 @@ * lib/mqueue/mq_setattr.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/net/lib_etherntoa.c b/nuttx/lib/net/lib_etherntoa.c index 2535491833..f89f205a2e 100644 --- a/nuttx/lib/net/lib_etherntoa.c +++ b/nuttx/lib/net/lib_etherntoa.c @@ -2,7 +2,7 @@ * lib/net/lib_etherntoa.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,7 +58,7 @@ * ****************************************************************************/ -char *ether_ntoa(const struct ether_addr *addr) +FAR char *ether_ntoa(FAR const struct ether_addr *addr) { static char buffer[20]; sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x", diff --git a/nuttx/lib/net/lib_htonl.c b/nuttx/lib/net/lib_htonl.c index f43b525050..e4c3e53838 100644 --- a/nuttx/lib/net/lib_htonl.c +++ b/nuttx/lib/net/lib_htonl.c @@ -2,7 +2,7 @@ * lib/net/lib_ntohl.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/net/lib_htons.c b/nuttx/lib/net/lib_htons.c index 66d736a33f..b4117e1dc2 100644 --- a/nuttx/lib/net/lib_htons.c +++ b/nuttx/lib/net/lib_htons.c @@ -2,7 +2,7 @@ * lib/net/lib_htons.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrdestroy.c b/nuttx/lib/pthread/pthread_attrdestroy.c index fdadab7432..103528c7e1 100644 --- a/nuttx/lib/pthread/pthread_attrdestroy.c +++ b/nuttx/lib/pthread/pthread_attrdestroy.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrdestroy.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrgetinheritsched.c b/nuttx/lib/pthread/pthread_attrgetinheritsched.c index c1b764faa3..02d6e0b7c0 100644 --- a/nuttx/lib/pthread/pthread_attrgetinheritsched.c +++ b/nuttx/lib/pthread/pthread_attrgetinheritsched.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrgetinheritsched.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrgetschedparam.c b/nuttx/lib/pthread/pthread_attrgetschedparam.c index fa456f61a4..c6bf55dea8 100644 --- a/nuttx/lib/pthread/pthread_attrgetschedparam.c +++ b/nuttx/lib/pthread/pthread_attrgetschedparam.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrgetschedparam.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrgetschedpolicy.c b/nuttx/lib/pthread/pthread_attrgetschedpolicy.c index b4f762b519..c42b828c96 100644 --- a/nuttx/lib/pthread/pthread_attrgetschedpolicy.c +++ b/nuttx/lib/pthread/pthread_attrgetschedpolicy.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrgetschedpolicy.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrgetstacksize.c b/nuttx/lib/pthread/pthread_attrgetstacksize.c index 06e40b5fbe..2faa586ba8 100644 --- a/nuttx/lib/pthread/pthread_attrgetstacksize.c +++ b/nuttx/lib/pthread/pthread_attrgetstacksize.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrgetstacksize.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrinit.c b/nuttx/lib/pthread/pthread_attrinit.c index 7df73e54b4..d06a535d78 100644 --- a/nuttx/lib/pthread/pthread_attrinit.c +++ b/nuttx/lib/pthread/pthread_attrinit.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrinit.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrsetinheritsched.c b/nuttx/lib/pthread/pthread_attrsetinheritsched.c index ebdc9b3e45..df2c2fba33 100644 --- a/nuttx/lib/pthread/pthread_attrsetinheritsched.c +++ b/nuttx/lib/pthread/pthread_attrsetinheritsched.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrsetinheritsched.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrsetschedparam.c b/nuttx/lib/pthread/pthread_attrsetschedparam.c index 4f65bcd8cb..c2ab4d1c41 100644 --- a/nuttx/lib/pthread/pthread_attrsetschedparam.c +++ b/nuttx/lib/pthread/pthread_attrsetschedparam.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrsetschedparam.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrsetschedpolicy.c b/nuttx/lib/pthread/pthread_attrsetschedpolicy.c index b4b1fd0543..4e43e635de 100644 --- a/nuttx/lib/pthread/pthread_attrsetschedpolicy.c +++ b/nuttx/lib/pthread/pthread_attrsetschedpolicy.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrsetschedpolicy.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_attrsetstacksize.c b/nuttx/lib/pthread/pthread_attrsetstacksize.c index a2de8ac78d..8a826dd3ac 100644 --- a/nuttx/lib/pthread/pthread_attrsetstacksize.c +++ b/nuttx/lib/pthread/pthread_attrsetstacksize.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_attrsetstacksize.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_barrierattrdestroy.c b/nuttx/lib/pthread/pthread_barrierattrdestroy.c index 7498bc4f23..6d16b9cff8 100644 --- a/nuttx/lib/pthread/pthread_barrierattrdestroy.c +++ b/nuttx/lib/pthread/pthread_barrierattrdestroy.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_barrierattrdestroy.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_barrierattrgetpshared.c b/nuttx/lib/pthread/pthread_barrierattrgetpshared.c index f4b4f64c13..d29bc6dfc8 100644 --- a/nuttx/lib/pthread/pthread_barrierattrgetpshared.c +++ b/nuttx/lib/pthread/pthread_barrierattrgetpshared.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_barrierattrgetpshared.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_barrierattrinit.c b/nuttx/lib/pthread/pthread_barrierattrinit.c index 47bbb8eb42..b5f35ca917 100644 --- a/nuttx/lib/pthread/pthread_barrierattrinit.c +++ b/nuttx/lib/pthread/pthread_barrierattrinit.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_barrierattrinit.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_barrierattrsetpshared.c b/nuttx/lib/pthread/pthread_barrierattrsetpshared.c index a982eea393..d0eecbf5a4 100644 --- a/nuttx/lib/pthread/pthread_barrierattrsetpshared.c +++ b/nuttx/lib/pthread/pthread_barrierattrsetpshared.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_barrierattrsetpshared.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_condattrdestroy.c b/nuttx/lib/pthread/pthread_condattrdestroy.c index c55dcd4e3f..d6c3df5d1a 100644 --- a/nuttx/lib/pthread/pthread_condattrdestroy.c +++ b/nuttx/lib/pthread/pthread_condattrdestroy.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_condattrdestroy.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_condattrinit.c b/nuttx/lib/pthread/pthread_condattrinit.c index 75f01a11b6..5721c61593 100644 --- a/nuttx/lib/pthread/pthread_condattrinit.c +++ b/nuttx/lib/pthread/pthread_condattrinit.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_condattrinit.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_mutexattrdestroy.c b/nuttx/lib/pthread/pthread_mutexattrdestroy.c index 59e81528be..e9868df68b 100644 --- a/nuttx/lib/pthread/pthread_mutexattrdestroy.c +++ b/nuttx/lib/pthread/pthread_mutexattrdestroy.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_mutexattrdestroy.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_mutexattrgetpshared.c b/nuttx/lib/pthread/pthread_mutexattrgetpshared.c index e5e09bbbe1..bc6379db5f 100644 --- a/nuttx/lib/pthread/pthread_mutexattrgetpshared.c +++ b/nuttx/lib/pthread/pthread_mutexattrgetpshared.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_mutexattrgetpshared.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_mutexattrgettype.c b/nuttx/lib/pthread/pthread_mutexattrgettype.c index 93cbe36019..5fb10f3015 100644 --- a/nuttx/lib/pthread/pthread_mutexattrgettype.c +++ b/nuttx/lib/pthread/pthread_mutexattrgettype.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_mutexattrgettype.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_mutexattrinit.c b/nuttx/lib/pthread/pthread_mutexattrinit.c index 729b0b8e14..f815bf16c1 100644 --- a/nuttx/lib/pthread/pthread_mutexattrinit.c +++ b/nuttx/lib/pthread/pthread_mutexattrinit.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_mutexattrinit.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_mutexattrsetpshared.c b/nuttx/lib/pthread/pthread_mutexattrsetpshared.c index 752e9faa03..900476fdd2 100644 --- a/nuttx/lib/pthread/pthread_mutexattrsetpshared.c +++ b/nuttx/lib/pthread/pthread_mutexattrsetpshared.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_mutexattrsetpshared.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/pthread/pthread_mutexattrsettype.c b/nuttx/lib/pthread/pthread_mutexattrsettype.c index e095dd70c3..81427c757e 100644 --- a/nuttx/lib/pthread/pthread_mutexattrsettype.c +++ b/nuttx/lib/pthread/pthread_mutexattrsettype.c @@ -2,7 +2,7 @@ * lib/pthread/pthread_mutexattrsettype.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_addafter.c b/nuttx/lib/queue/dq_addafter.c index e9f0d9a3ec..bfbe0052d8 100644 --- a/nuttx/lib/queue/dq_addafter.c +++ b/nuttx/lib/queue/dq_addafter.c @@ -2,7 +2,7 @@ * lib/queue/dq_addafter.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_addbefore.c b/nuttx/lib/queue/dq_addbefore.c index c49dff78b7..d740ea8309 100644 --- a/nuttx/lib/queue/dq_addbefore.c +++ b/nuttx/lib/queue/dq_addbefore.c @@ -2,7 +2,7 @@ * lib/queue/dq_addbefore.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_addfirst.c b/nuttx/lib/queue/dq_addfirst.c index 27da2c491c..7c7312de3b 100644 --- a/nuttx/lib/queue/dq_addfirst.c +++ b/nuttx/lib/queue/dq_addfirst.c @@ -2,7 +2,7 @@ * lib/queue/dq_addfirst.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_addlast.c b/nuttx/lib/queue/dq_addlast.c index c7a0609612..745deb27d1 100644 --- a/nuttx/lib/queue/dq_addlast.c +++ b/nuttx/lib/queue/dq_addlast.c @@ -2,7 +2,7 @@ * lib/queue/dq_addlast.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_rem.c b/nuttx/lib/queue/dq_rem.c index adf99efed2..218427bf84 100644 --- a/nuttx/lib/queue/dq_rem.c +++ b/nuttx/lib/queue/dq_rem.c @@ -2,7 +2,7 @@ * lib/queue/dq_rem.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_remfirst.c b/nuttx/lib/queue/dq_remfirst.c index c42f3f2cc5..26c5fd7a67 100644 --- a/nuttx/lib/queue/dq_remfirst.c +++ b/nuttx/lib/queue/dq_remfirst.c @@ -2,7 +2,7 @@ * lib/queue/dq_remfirst.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/dq_remlast.c b/nuttx/lib/queue/dq_remlast.c index 6280a0e516..35adc73e2d 100644 --- a/nuttx/lib/queue/dq_remlast.c +++ b/nuttx/lib/queue/dq_remlast.c @@ -2,7 +2,7 @@ * lib/queue/dq_remlast.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_addafter.c b/nuttx/lib/queue/sq_addafter.c index 05e1157fd4..965ac28444 100644 --- a/nuttx/lib/queue/sq_addafter.c +++ b/nuttx/lib/queue/sq_addafter.c @@ -2,7 +2,7 @@ * lib/queue/sq_addafter.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_addfirst.c b/nuttx/lib/queue/sq_addfirst.c index 8f55053d41..8fc8e06199 100644 --- a/nuttx/lib/queue/sq_addfirst.c +++ b/nuttx/lib/queue/sq_addfirst.c @@ -2,7 +2,7 @@ * lib/queue/sq_addfirst.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_addlast.c b/nuttx/lib/queue/sq_addlast.c index 15054a7033..f9f9625cc0 100644 --- a/nuttx/lib/queue/sq_addlast.c +++ b/nuttx/lib/queue/sq_addlast.c @@ -2,7 +2,7 @@ * lib/queue/sq_addlast.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_rem.c b/nuttx/lib/queue/sq_rem.c index 972e8e1c32..6ba52354d4 100644 --- a/nuttx/lib/queue/sq_rem.c +++ b/nuttx/lib/queue/sq_rem.c @@ -2,7 +2,7 @@ * lib/queue/sq_rem.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_remafter.c b/nuttx/lib/queue/sq_remafter.c index 781a2b6ad2..4dcfb06e44 100644 --- a/nuttx/lib/queue/sq_remafter.c +++ b/nuttx/lib/queue/sq_remafter.c @@ -2,7 +2,7 @@ * lib/queue/sq_remafter.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_remfirst.c b/nuttx/lib/queue/sq_remfirst.c index 5a273ad6af..43df6de417 100644 --- a/nuttx/lib/queue/sq_remfirst.c +++ b/nuttx/lib/queue/sq_remfirst.c @@ -2,7 +2,7 @@ * lib/queue/sq_remfirst.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/queue/sq_remlast.c b/nuttx/lib/queue/sq_remlast.c index a66c6bcbb7..92cdbde985 100644 --- a/nuttx/lib/queue/sq_remlast.c +++ b/nuttx/lib/queue/sq_remlast.c @@ -2,7 +2,7 @@ * lib/queue/sq_remlast.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/sched/sched_getprioritymax.c b/nuttx/lib/sched/sched_getprioritymax.c index 8be45d7100..14b368dfc0 100644 --- a/nuttx/lib/sched/sched_getprioritymax.c +++ b/nuttx/lib/sched/sched_getprioritymax.c @@ -2,7 +2,7 @@ * lib/sched/sched_getprioritymax.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/sched/sched_getprioritymin.c b/nuttx/lib/sched/sched_getprioritymin.c index a590f1fc2e..86410cb0f6 100644 --- a/nuttx/lib/sched/sched_getprioritymin.c +++ b/nuttx/lib/sched/sched_getprioritymin.c @@ -2,7 +2,7 @@ * lib/sched/sched_getprioritymin.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/semaphore/sem_getvalue.c b/nuttx/lib/semaphore/sem_getvalue.c index 137eb90010..31c6bb7e06 100644 --- a/nuttx/lib/semaphore/sem_getvalue.c +++ b/nuttx/lib/semaphore/sem_getvalue.c @@ -2,7 +2,7 @@ * lib/semaphore/sem_getvalue.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/semaphore/sem_init.c b/nuttx/lib/semaphore/sem_init.c index ea1c6e84ea..bc14415f97 100644 --- a/nuttx/lib/semaphore/sem_init.c +++ b/nuttx/lib/semaphore/sem_init.c @@ -103,16 +103,17 @@ int sem_init(FAR sem_t *sem, int pshared, unsigned int value) { /* Initialize the seamphore count */ - sem->semcount = (int16_t)value; + sem->semcount = (int16_t)value; /* Initialize to support priority inheritance */ #ifdef CONFIG_PRIORITY_INHERITANCE # if CONFIG_SEM_PREALLOCHOLDERS > 0 - sem->hlist.flink = NULL; + sem->hhead = NULL; +# else + sem->holder.htcb = NULL; + sem->holder.counts = 0; # endif - sem->hlist.holder = NULL; - sem->hlist.counts = 0; #endif return OK; } diff --git a/nuttx/lib/signal/sig_addset.c b/nuttx/lib/signal/sig_addset.c index af9463aac8..19ba0cb6b6 100644 --- a/nuttx/lib/signal/sig_addset.c +++ b/nuttx/lib/signal/sig_addset.c @@ -2,7 +2,7 @@ * lib/signal/sig_addset.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/signal/sig_delset.c b/nuttx/lib/signal/sig_delset.c index 489c59afac..1c661d37f6 100644 --- a/nuttx/lib/signal/sig_delset.c +++ b/nuttx/lib/signal/sig_delset.c @@ -2,7 +2,7 @@ * lib/signal/sig_delset.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/signal/sig_emptyset.c b/nuttx/lib/signal/sig_emptyset.c index bfee588323..ac0c6b3e89 100644 --- a/nuttx/lib/signal/sig_emptyset.c +++ b/nuttx/lib/signal/sig_emptyset.c @@ -2,7 +2,7 @@ * lib/signal/sig_emptyset.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/signal/sig_fillset.c b/nuttx/lib/signal/sig_fillset.c index c660da0ad8..8697d7577f 100644 --- a/nuttx/lib/signal/sig_fillset.c +++ b/nuttx/lib/signal/sig_fillset.c @@ -2,7 +2,7 @@ * lib/signal/sig_fillset.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/signal/sig_ismember.c b/nuttx/lib/signal/sig_ismember.c index 88dc8d819b..c5bb091b7b 100644 --- a/nuttx/lib/signal/sig_ismember.c +++ b/nuttx/lib/signal/sig_ismember.c @@ -2,7 +2,7 @@ * lib/signal/sig_ismember.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/lib/stdio/Make.defs index 1165d53547..f88a5edd9e 100644 --- a/nuttx/lib/stdio/Make.defs +++ b/nuttx/lib/stdio/Make.defs @@ -50,7 +50,8 @@ CSRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \ lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \ lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \ lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \ - lib_fprintf.c lib_vfprintf.c lib_stdinstream.c lib_stdoutstream.c + lib_fprintf.c lib_vfprintf.c lib_stdinstream.c lib_stdoutstream.c \ + lib_perror.c endif endif diff --git a/nuttx/lib/stdio/lib_fflush.c b/nuttx/lib/stdio/lib_fflush.c index e0278d0d25..d0b5e0185d 100644 --- a/nuttx/lib/stdio/lib_fflush.c +++ b/nuttx/lib/stdio/lib_fflush.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fflush.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -97,22 +97,36 @@ int fflush(FAR FILE *stream) { + int ret; + /* Is the stream argument NULL? */ if (!stream) { /* Yes... then this is a request to flush all streams */ - return lib_flushall(sched_getstreams()); + ret = lib_flushall(sched_getstreams()); } - else if (lib_fflush(stream, true) != 0) + else { - /* An error occurred during the flush AND/OR we were unable to flush all - * of the buffered write data. Return EOF on failure. + ret = lib_fflush(stream, true); + } + + /* Check the return value */ + + if (ret < 0) + { + /* An error occurred during the flush AND/OR we were unable to flush + * all of the buffered write data. Set the errno value. */ + set_errno(-ret); + + /* And return EOF on failure. */ + return EOF; } + return OK; } diff --git a/nuttx/lib/stdio/lib_fgetc.c b/nuttx/lib/stdio/lib_fgetc.c index 4e521e8403..4b3d0ec44f 100644 --- a/nuttx/lib/stdio/lib_fgetc.c +++ b/nuttx/lib/stdio/lib_fgetc.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fgetc.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_fgetpos.c b/nuttx/lib/stdio/lib_fgetpos.c index af07f7387e..e9e9f4d102 100644 --- a/nuttx/lib/stdio/lib_fgetpos.c +++ b/nuttx/lib/stdio/lib_fgetpos.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fgetpos.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_fgets.c b/nuttx/lib/stdio/lib_fgets.c index e84e031f9e..a4f9089ed7 100644 --- a/nuttx/lib/stdio/lib_fgets.c +++ b/nuttx/lib/stdio/lib_fgets.c @@ -50,13 +50,32 @@ * Definitions ****************************************************************************/ /* Some environments may return CR as end-of-line, others LF, and others - * both. The logic here assumes either but not both. + * both. If not specified, the logic here assumes either (but not both) as + * the default. */ -#undef CONFIG_EOL_IS_CR -#undef CONFIG_EOL_IS_LF -#undef CONFIG_EOL_IS_BOTH_CRLF -#define CONFIG_EOL_IS_EITHER_CRLF 1 +#if defined(CONFIG_EOL_IS_CR) +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_LF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_BOTH_CRLF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_BOTH_CRLF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_EITHER_CRLF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +#else +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +# define CONFIG_EOL_IS_EITHER_CRLF 1 +#endif /**************************************************************************** * Private Type Declarations diff --git a/nuttx/lib/stdio/lib_fileno.c b/nuttx/lib/stdio/lib_fileno.c index ec25ce6d09..fca08fc0d4 100644 --- a/nuttx/lib/stdio/lib_fileno.c +++ b/nuttx/lib/stdio/lib_fileno.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fileno.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -63,6 +63,7 @@ int fileno(FAR FILE *stream) set_errno(EBADF); return ERROR; } + return ret; } #endif /* CONFIG_NFILE_STREAMS */ diff --git a/nuttx/lib/stdio/lib_fopen.c b/nuttx/lib/stdio/lib_fopen.c index 52e44c59de..29ff4569c2 100644 --- a/nuttx/lib/stdio/lib_fopen.c +++ b/nuttx/lib/stdio/lib_fopen.c @@ -64,7 +64,7 @@ enum open_mode_e MODE_A, /* "a" or "ab" open for writing, appending to file */ MODE_RPLUS, /* "r+", "rb+", or "r+b" open for update (reading and writing) */ MODE_WPLUS, /* "w+", "wb+", or "w+b" open for update, truncating or creating file */ - MODE_APLUS, /* "a+", "ab+", or "a+b" open for update, appending to file */ + MODE_APLUS /* "a+", "ab+", or "a+b" open for update, appending to file */ }; /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_fread.c b/nuttx/lib/stdio/lib_fread.c index cc652fab72..4a4b29256d 100644 --- a/nuttx/lib/stdio/lib_fread.c +++ b/nuttx/lib/stdio/lib_fread.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fread.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_fseek.c b/nuttx/lib/stdio/lib_fseek.c index a68de79fe2..7380f83b3b 100644 --- a/nuttx/lib/stdio/lib_fseek.c +++ b/nuttx/lib/stdio/lib_fseek.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fseek.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_fsetpos.c b/nuttx/lib/stdio/lib_fsetpos.c index ad3e672300..13d556521b 100644 --- a/nuttx/lib/stdio/lib_fsetpos.c +++ b/nuttx/lib/stdio/lib_fsetpos.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fsetpos.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_ftell.c b/nuttx/lib/stdio/lib_ftell.c index cd0e483687..9476481529 100644 --- a/nuttx/lib/stdio/lib_ftell.c +++ b/nuttx/lib/stdio/lib_ftell.c @@ -2,7 +2,7 @@ * lib/stdio/lib_ftell.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_fwrite.c b/nuttx/lib/stdio/lib_fwrite.c index 1b7be2ce5c..60e0017463 100644 --- a/nuttx/lib/stdio/lib_fwrite.c +++ b/nuttx/lib/stdio/lib_fwrite.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fwrite.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_libfflush.c b/nuttx/lib/stdio/lib_libfflush.c index fb5a8768e9..2a4fe29326 100644 --- a/nuttx/lib/stdio/lib_libfflush.c +++ b/nuttx/lib/stdio/lib_libfflush.c @@ -98,8 +98,8 @@ * bforce - flush must be complete. * * Return: - * ERROR on failure, otherwise the number of bytes remaining in the buffer. - * If bforce is set, then only the values ERROR and 0 will be returned. + * A negated errno value on failure, otherwise the number of bytes remaining + * in the buffer. * ****************************************************************************/ @@ -114,8 +114,7 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) if (stream->fs_filedes < 0 || (stream->fs_oflags & O_WROK) == 0) { - set_errno(EBADF); - return ERROR; + return -EBADF; } /* Make sure that we have exclusive access to the stream */ @@ -132,8 +131,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) if (stream->fs_bufread != stream->fs_bufstart) { - /* The buffer holds read data... just return zero */ + /* The buffer holds read data... just return zero meaning "no bytes + * remaining in the buffer." + */ + lib_give_semaphore(stream); return 0; } @@ -151,8 +153,12 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) bytes_written = write(stream->fs_filedes, src, nbuffer); if (bytes_written < 0) { + /* Write failed. The cause of the failure is in 'errno'. + * returned the negated errno value. + */ + lib_give_semaphore(stream); - return ERROR; + return -get_errno(); } /* Handle partial writes. fflush() must either return with diff --git a/nuttx/lib/stdio/lib_libflushall.c b/nuttx/lib/stdio/lib_libflushall.c index 8de0c33096..9d0a89e9c1 100644 --- a/nuttx/lib/stdio/lib_libflushall.c +++ b/nuttx/lib/stdio/lib_libflushall.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_libflushall.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -91,7 +91,7 @@ int lib_flushall(FAR struct streamlist *list) { int lasterrno = OK; - int ret = OK; + int ret; /* Make sure that there are streams associated with this thread */ @@ -115,25 +115,23 @@ int lib_flushall(FAR struct streamlist *list) { /* Flush the writable FILE */ - if (lib_fflush(stream, true) != 0) + ret = lib_fflush(stream, true); + if (ret < 0) { /* An error occurred during the flush AND/OR we were unable - * to flush all of the buffered write data. Return EOF on failure. + * to flush all of the buffered write data. Remember the + * last errcode. */ - lasterrno = get_errno(); - ret = ERROR; + lasterrno = ret; } } } + stream_semgive(list); } - /* If any flush failed, return that last failed flush */ + /* If any flush failed, return the errorcode of the last failed flush */ - if (ret != OK) - { - set_errno(lasterrno); - } - return ret; + return lasterrno; } diff --git a/nuttx/lib/stdio/lib_libfread.c b/nuttx/lib/stdio/lib_libfread.c index 4d402a42b4..03b47eda66 100644 --- a/nuttx/lib/stdio/lib_libfread.c +++ b/nuttx/lib/stdio/lib_libfread.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_libfread.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -88,6 +88,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) { unsigned char *dest = (unsigned char*)ptr; ssize_t bytes_read; + int ret; /* Make sure that reading from this stream is allowed */ @@ -127,9 +128,11 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) * buffered read/write access. */ - if (lib_wrflush(stream) != 0) + ret = lib_wrflush(stream); + if (ret < 0) { - return ERROR; + lib_give_semaphore(stream); + return ret; } /* Now get any other needed chars from the buffer or the file. */ @@ -176,15 +179,17 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) bytes_read = read(stream->fs_filedes, dest, count); if (bytes_read < 0) { - /* An error occurred on the read */ + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ - goto err_out; + goto errout_with_errno; } else if (bytes_read == 0) { /* We are at the end of the file */ - goto short_read; + goto shortread; } else { @@ -198,7 +203,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) { /* No. We must be at the end of file. */ - goto short_read; + goto shortread; } else { @@ -219,15 +224,17 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) bytes_read = read(stream->fs_filedes, stream->fs_bufread, buffer_available); if (bytes_read < 0) { - /* An error occurred on the read */ + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ - goto err_out; + goto errout_with_errno; } else if (bytes_read == 0) { /* We are at the end of the file */ - goto short_read; + goto shortread; } else { @@ -246,7 +253,11 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) bytes_read = read(stream->fs_filedes, dest, count); if (bytes_read < 0) { - goto err_out; + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ + + goto errout_with_errno; } else if (bytes_read == 0) { @@ -259,13 +270,21 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) } } #endif + /* Here after a successful (but perhaps short) read */ + #if CONFIG_STDIO_BUFFER_SIZE > 0 - short_read: + shortread: #endif bytes_read = dest - (unsigned char*)ptr; - err_out: - lib_give_semaphore(stream); } - return bytes_read; + + lib_give_semaphore(stream); + return bytes_read; + +/* Error exits */ + +errout_with_errno: + lib_give_semaphore(stream); + return -get_errno(); } diff --git a/nuttx/lib/stdio/lib_libsprintf.c b/nuttx/lib/stdio/lib_libsprintf.c index 04d5477541..2474a6f01d 100644 --- a/nuttx/lib/stdio/lib_libsprintf.c +++ b/nuttx/lib/stdio/lib_libsprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_libsprintf.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_lowinstream.c b/nuttx/lib/stdio/lib_lowinstream.c index c97a4721fd..499a647ea2 100644 --- a/nuttx/lib/stdio/lib_lowinstream.c +++ b/nuttx/lib/stdio/lib_lowinstream.c @@ -39,8 +39,6 @@ #include -#ifdef CONFIG_ARCH_LOWGETC - #include #include #include @@ -49,6 +47,8 @@ #include "lib_internal.h" +#ifdef CONFIG_ARCH_LOWGETC + /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/nuttx/lib/stdio/lib_perror.c b/nuttx/lib/stdio/lib_perror.c new file mode 100644 index 0000000000..867e113f98 --- /dev/null +++ b/nuttx/lib/stdio/lib_perror.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * lib/stdio/lib_perror.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* POSIX requires that perror provide its output on stderr. This option may + * be defined, however, to provide perror output that is serialized with + * other stdout messages. + */ + +#ifdef CONFIG_LIBC_PERROR_STDOUT +# define PERROR_STREAM stdout +#else +# define PERROR_STREAM stderr +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: perror + ****************************************************************************/ + +void perror(FAR const char *s) +{ + + /* If strerror() is not enabled, then just print the error number */ + +#ifdef CONFIG_LIBC_STRERROR + (void)fprintf(PERROR_STREAM, "%s: %s\n", s, strerror(errno)); +#else + (void)fprintf(PERROR_STREAM, "%s: Error %d\n", s, errno); +#endif +} + diff --git a/nuttx/lib/stdio/lib_rdflush.c b/nuttx/lib/stdio/lib_rdflush.c index 948dcce5da..35c5495c17 100644 --- a/nuttx/lib/stdio/lib_rdflush.c +++ b/nuttx/lib/stdio/lib_rdflush.c @@ -2,7 +2,7 @@ * lib/stdio/lib_rdflush.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_snprintf.c b/nuttx/lib/stdio/lib_snprintf.c index a4dcd399bd..e5ce7b0f02 100644 --- a/nuttx/lib/stdio/lib_snprintf.c +++ b/nuttx/lib/stdio/lib_snprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_snprintf.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_sprintf.c b/nuttx/lib/stdio/lib_sprintf.c index 6de019cc5f..89fd610330 100644 --- a/nuttx/lib/stdio/lib_sprintf.c +++ b/nuttx/lib/stdio/lib_sprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_sprintf.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_sscanf.c b/nuttx/lib/stdio/lib_sscanf.c index 3430aa0a02..01c96c21dd 100644 --- a/nuttx/lib/stdio/lib_sscanf.c +++ b/nuttx/lib/stdio/lib_sscanf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_sscanf.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -91,13 +91,13 @@ static const char spaces[] = " \t\n\r\f\v"; * ****************************************************************************/ -int sscanf(const char *buf, const char *fmt, ...) +int sscanf(FAR const char *buf, FAR const char *fmt, ...) { va_list ap; int count; va_start(ap, fmt); - count = vsscanf((char*)buf, fmt, ap); + count = vsscanf((FAR char*)buf, fmt, ap); va_end(ap); return count; } @@ -109,15 +109,15 @@ int sscanf(const char *buf, const char *fmt, ...) * ANSI standard vsscanf implementation. * ****************************************************************************/ -int vsscanf(char *buf, const char *s, va_list ap) +int vsscanf(FAR char *buf, FAR const char *s, va_list ap) { int count; int noassign; int width; int base = 10; int lflag; - char *tv; - const char *tc; + FAR char *tv; + FAR const char *tc; char tmp[MAXLN]; lvdbg("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, s); diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c index 7e47d794a5..21151b43a1 100644 --- a/nuttx/lib/stdio/lib_syslogstream.c +++ b/nuttx/lib/stdio/lib_syslogstream.c @@ -2,7 +2,7 @@ * lib/stdio/lib_syslogstream.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_ungetc.c b/nuttx/lib/stdio/lib_ungetc.c index 73e5917295..c10d4fba1a 100644 --- a/nuttx/lib/stdio/lib_ungetc.c +++ b/nuttx/lib/stdio/lib_ungetc.c @@ -2,7 +2,7 @@ * lib/stdio/lib_ungetc.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_vfprintf.c b/nuttx/lib/stdio/lib_vfprintf.c index 25c3954c08..1c3a2d7fc9 100644 --- a/nuttx/lib/stdio/lib_vfprintf.c +++ b/nuttx/lib/stdio/lib_vfprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_vfprintf.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_vprintf.c b/nuttx/lib/stdio/lib_vprintf.c index a2e31fa052..d085d58869 100644 --- a/nuttx/lib/stdio/lib_vprintf.c +++ b/nuttx/lib/stdio/lib_vprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_vprintf.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_vsnprintf.c b/nuttx/lib/stdio/lib_vsnprintf.c index da885977c7..c6f52092d1 100644 --- a/nuttx/lib/stdio/lib_vsnprintf.c +++ b/nuttx/lib/stdio/lib_vsnprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_vsnprintf.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_vsprintf.c b/nuttx/lib/stdio/lib_vsprintf.c index 72a829a794..5db46664e3 100644 --- a/nuttx/lib/stdio/lib_vsprintf.c +++ b/nuttx/lib/stdio/lib_vsprintf.c @@ -2,7 +2,7 @@ * lib/stdio/lib_vsprintf.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_wrflush.c b/nuttx/lib/stdio/lib_wrflush.c index c16109515b..39680da6ae 100644 --- a/nuttx/lib/stdio/lib_wrflush.c +++ b/nuttx/lib/stdio/lib_wrflush.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_wrflush.c * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -88,29 +88,47 @@ int lib_wrflush(FAR FILE *stream) { +#if CONFIG_STDIO_BUFFER_SIZE > 0 /* Verify that we were passed a valid (i.e., non-NULL) stream */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 - if (stream) +#ifdef CONFIG_DEBUG + if (!stream) { - /* Verify that the stream is opened for writing... lib_fflush will - * return an error if it is called for a stream that is not opened for - * writing. + return -EINVAL; + } +#endif + + /* Verify that the stream is opened for writing... lib_fflush will + * return an error if it is called for a stream that is not opened for + * writing. Check that first so that this function will not fail in + * that case. + */ + + if ((stream->fs_oflags & O_WROK) == 0) + { + /* Report that the success was successful if we attempt to flush a + * read-only stream. */ - if ((stream->fs_oflags & O_WROK) == 0 || - lib_fflush(stream, true) == 0) - { - /* Return success if there is no buffered write data -- i.e., that - * the stream is not opened for writing or, if it is, that all of - * the buffered write data was successfully flushed. - */ - - return OK; - } + return OK; } - return ERROR; + + /* Flush the stream. Return success if there is no buffered write data + * -- i.e., that the stream is opened for writing and that all of the + * buffered write data was successfully flushed by lib_fflush(). + */ + + return lib_fflush(stream, true); #else - return stream ? OK : ERROR; + /* Verify that we were passed a valid (i.e., non-NULL) stream */ + +#ifdef CONFIG_DEBUG + if (!stream) + { + return -EINVAL; + } +#endif + + return OK; #endif } diff --git a/nuttx/lib/stdio/lib_zeroinstream.c b/nuttx/lib/stdio/lib_zeroinstream.c index 27655b5475..39a6c22ef3 100644 --- a/nuttx/lib/stdio/lib_zeroinstream.c +++ b/nuttx/lib/stdio/lib_zeroinstream.c @@ -2,7 +2,7 @@ * lib/stdio/lib_zeroinstream.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdlib/lib_abs.c b/nuttx/lib/stdlib/lib_abs.c index 5c805d8579..1a0c1671cc 100644 --- a/nuttx/lib/stdlib/lib_abs.c +++ b/nuttx/lib/stdlib/lib_abs.c @@ -2,7 +2,7 @@ * lib/stdlib/lib_abs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdlib/lib_imaxabs.c b/nuttx/lib/stdlib/lib_imaxabs.c index d16791b268..c6e227c7de 100644 --- a/nuttx/lib/stdlib/lib_imaxabs.c +++ b/nuttx/lib/stdlib/lib_imaxabs.c @@ -2,7 +2,7 @@ * lib/stdlib//lib_abs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdlib/lib_labs.c b/nuttx/lib/stdlib/lib_labs.c index c9d9c19351..f7218ee833 100644 --- a/nuttx/lib/stdlib/lib_labs.c +++ b/nuttx/lib/stdlib/lib_labs.c @@ -2,7 +2,7 @@ * lib/stdlib/lib_labs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdlib/lib_llabs.c b/nuttx/lib/stdlib/lib_llabs.c index 24e26e9e11..db7d3dbe07 100644 --- a/nuttx/lib/stdlib/lib_llabs.c +++ b/nuttx/lib/stdlib/lib_llabs.c @@ -2,7 +2,7 @@ * lib/stdlib/lib_llabs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdlib/lib_qsort.c b/nuttx/lib/stdlib/lib_qsort.c index 13bca7499a..9dd5c00409 100644 --- a/nuttx/lib/stdlib/lib_qsort.c +++ b/nuttx/lib/stdlib/lib_qsort.c @@ -2,7 +2,7 @@ * lib/stdlib/lib_qsort.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Leveraged from: * diff --git a/nuttx/lib/stdlib/lib_rand.c b/nuttx/lib/stdlib/lib_rand.c index 537bc1aaee..7227c52d0d 100644 --- a/nuttx/lib/stdlib/lib_rand.c +++ b/nuttx/lib/stdlib/lib_rand.c @@ -2,7 +2,7 @@ * lib/stdlib/lib_rand.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/Make.defs b/nuttx/lib/string/Make.defs index 495634a9ee..6b21c7f146 100644 --- a/nuttx/lib/string/Make.defs +++ b/nuttx/lib/string/Make.defs @@ -36,13 +36,13 @@ # Add the string C files to the build CSRCS += lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \ - lib_memccpy.c lib_memcpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \ - lib_strcasecmp.c lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c \ - lib_strcspn.c lib_strdup.c lib_strerror.c lib_strlen.c lib_strnlen.c \ - lib_strncasecmp.c lib_strncat.c lib_strncmp.c lib_strncpy.c \ - lib_strndup.c lib_strcasestr.c lib_strpbrk.c lib_strrchr.c\ - lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c lib_strtol.c \ - lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtod.c + lib_memccpy.c lib_memcpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \ + lib_strcasecmp.c lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c \ + lib_strcspn.c lib_strdup.c lib_strerror.c lib_strlen.c lib_strnlen.c \ + lib_strncasecmp.c lib_strncat.c lib_strncmp.c lib_strncpy.c \ + lib_strndup.c lib_strcasestr.c lib_strpbrk.c lib_strrchr.c\ + lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c lib_strtol.c \ + lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtod.c # Add the string directory to the build diff --git a/nuttx/lib/string/lib_checkbase.c b/nuttx/lib/string/lib_checkbase.c index bec131b5c7..bc79ab2cec 100644 --- a/nuttx/lib/string/lib_checkbase.c +++ b/nuttx/lib/string/lib_checkbase.c @@ -2,7 +2,7 @@ * lib/string/lib_checkbase.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_isbasedigit.c b/nuttx/lib/string/lib_isbasedigit.c index 26426e8213..a2421bf2a4 100644 --- a/nuttx/lib/string/lib_isbasedigit.c +++ b/nuttx/lib/string/lib_isbasedigit.c @@ -2,7 +2,7 @@ * lib/string/lib_isbasedigit.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_memcmp.c b/nuttx/lib/string/lib_memcmp.c index cd874a85e4..eb2e1fd125 100644 --- a/nuttx/lib/string/lib_memcmp.c +++ b/nuttx/lib/string/lib_memcmp.c @@ -2,7 +2,7 @@ * lib/string/lib_memcmp.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_memmove.c b/nuttx/lib/string/lib_memmove.c index 97bac99ed9..ecaeb54cf2 100644 --- a/nuttx/lib/string/lib_memmove.c +++ b/nuttx/lib/string/lib_memmove.c @@ -2,7 +2,7 @@ * lib/string/lib_memmove.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_memset.c b/nuttx/lib/string/lib_memset.c index f3a5497a9a..916351b974 100644 --- a/nuttx/lib/string/lib_memset.c +++ b/nuttx/lib/string/lib_memset.c @@ -2,7 +2,7 @@ * lib/string/lib_memset.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_skipspace.c b/nuttx/lib/string/lib_skipspace.c index 826559efed..b4e6588e59 100644 --- a/nuttx/lib/string/lib_skipspace.c +++ b/nuttx/lib/string/lib_skipspace.c @@ -2,7 +2,7 @@ * lib/string/lib_skipspace.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strcasecmp.c b/nuttx/lib/string/lib_strcasecmp.c index ed5217831f..d4aa8cc031 100644 --- a/nuttx/lib/string/lib_strcasecmp.c +++ b/nuttx/lib/string/lib_strcasecmp.c @@ -2,7 +2,7 @@ * lib/string/lib_strcasecmp.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strcat.c b/nuttx/lib/string/lib_strcat.c index 2d12dd5a64..20350fec07 100644 --- a/nuttx/lib/string/lib_strcat.c +++ b/nuttx/lib/string/lib_strcat.c @@ -1,62 +1,62 @@ -/**************************************************************************** - * lib/string/lib_strcat.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -#ifndef CONFIG_ARCH_STRCAT -char *strcat(char *dest, const char *src) -{ - char *ret = dest; - - dest += strlen(dest); - while (*src != '\0') - { - *dest++ = *src++; - } - *dest = '\0'; - - return ret; -} -#endif +/**************************************************************************** + * lib/string/lib_strcat.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +#ifndef CONFIG_ARCH_STRCAT +char *strcat(char *dest, const char *src) +{ + char *ret = dest; + + dest += strlen(dest); + while (*src != '\0') + { + *dest++ = *src++; + } + *dest = '\0'; + + return ret; +} +#endif diff --git a/nuttx/lib/string/lib_strcmp.c b/nuttx/lib/string/lib_strcmp.c index 1d78cb0495..0e3eee8900 100644 --- a/nuttx/lib/string/lib_strcmp.c +++ b/nuttx/lib/string/lib_strcmp.c @@ -2,7 +2,7 @@ * lib/string/lib_strcmp.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strcpy.c b/nuttx/lib/string/lib_strcpy.c index 774e155347..e2f70b94e3 100644 --- a/nuttx/lib/string/lib_strcpy.c +++ b/nuttx/lib/string/lib_strcpy.c @@ -2,7 +2,7 @@ * lib/string/lib_strcpy.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strcspn.c b/nuttx/lib/string/lib_strcspn.c index b28f223431..9da89241c5 100644 --- a/nuttx/lib/string/lib_strcspn.c +++ b/nuttx/lib/string/lib_strcspn.c @@ -2,7 +2,7 @@ * lib/string/lib_strcspn.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strdup.c b/nuttx/lib/string/lib_strdup.c index a353c629da..44a0cbc0d8 100644 --- a/nuttx/lib/string/lib_strdup.c +++ b/nuttx/lib/string/lib_strdup.c @@ -2,7 +2,7 @@ * lib/string//lib_strdup.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strerror.c b/nuttx/lib/string/lib_strerror.c index 580974fa6c..249f695c1b 100644 --- a/nuttx/lib/string/lib_strerror.c +++ b/nuttx/lib/string/lib_strerror.c @@ -1,8 +1,8 @@ /************************************************************************ * lib/string/lib_strerror.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -61,6 +61,8 @@ struct errno_strmap_s * Private Data ************************************************************************/ +#ifdef CONFIG_LIBC_STRERROR + /* This table maps all error numbers to descriptive strings. * The only assumption that the code makes with regard to this * this table is that it is ordered by error number. @@ -70,6 +72,8 @@ struct errno_strmap_s * strings. */ +#ifndef CONFIG_LIBC_STRERROR_SHORT + static const struct errno_strmap_s g_errnomap[] = { { EPERM, EPERM_STR }, @@ -196,8 +200,140 @@ static const struct errno_strmap_s g_errnomap[] = { EMEDIUMTYPE, EMEDIUMTYPE_STR } }; +#else /* CONFIG_LIBC_STRERROR_SHORT */ + +static const struct errno_strmap_s g_errnomap[] = +{ + { EPERM, "EPERM" }, + { ENOENT, "ENOENT" }, + { ESRCH, "ESRCH" }, + { EINTR, "EINTR" }, + { EIO, "EIO" }, + { ENXIO, "ENXIO" }, + { E2BIG, "E2BIG" }, + { ENOEXEC, "ENOEXEC" }, + { EBADF, "EBADF" }, + { ECHILD, "ECHILD" }, + { EAGAIN, "EAGAIN" }, + { ENOMEM, "ENOMEM" }, + { EACCES, "EACCES" }, + { EFAULT, "EFAULT" }, + { ENOTBLK, "ENOTBLK" }, + { EBUSY, "EBUSY" }, + { EEXIST, "EEXIST" }, + { EXDEV, "EXDEV" }, + { ENODEV, "ENODEV" }, + { ENOTDIR, "ENOTDIR" }, + { EISDIR, "EISDIR" }, + { EINVAL, "EINVAL" }, + { ENFILE, "ENFILE" }, + { EMFILE, "EMFILE" }, + { ENOTTY, "ENOTTY" }, + { ETXTBSY, "ETXTBSY" }, + { EFBIG, "EFBIG" }, + { ENOSPC, "ENOSPC" }, + { ESPIPE, "ESPIPE" }, + { EROFS, "EROFS" }, + { EMLINK, "EMLINK" }, + { EPIPE, "EPIPE" }, + { EDOM, "EDOM" }, + { ERANGE, "ERANGE" }, + { EDEADLK, "EDEADLK" }, + { ENAMETOOLONG, "ENAMETOOLONG" }, + { ENOLCK, "ENOLCK" }, + { ENOSYS, "ENOSYS" }, + { ENOTEMPTY, "ENOTEMPTY" }, + { ELOOP, "ELOOP" }, + { ENOMSG, "ENOMSG" }, + { EIDRM, "EIDRM" }, + { ECHRNG, "ECHRNG" }, + { EL2NSYNC, "EL2NSYNC" }, + { EL3HLT, "EL3HLT" }, + { EL3RST, "EL3RST" }, + { EL3RST, "EL3RST" }, + { EUNATCH, "EUNATCH" }, + { ENOCSI, "ENOCSI" }, + { EL2HLT, "EL2HLT" }, + { EBADE, "EBADE" }, + { EBADR, "EBADR" }, + { EXFULL, "EXFULL" }, + { ENOANO, "ENOANO" }, + { EBADRQC, "EBADRQC" }, + { EBADSLT, "EBADSLT" }, + { EBFONT, "EBFONT" }, + { ENOSTR, "ENOSTR" }, + { ENODATA, "ENODATA" }, + { ETIME, "ETIME" }, + { ENOSR, "ENOSR" }, + { ENONET, "ENONET" }, + { ENOPKG, "ENOPKG" }, + { EREMOTE, "EREMOTE" }, + { ENOLINK, "ENOLINK" }, + { EADV, "EADV" }, + { ESRMNT, "ESRMNT" }, + { ECOMM, "ECOMM" }, + { EPROTO, "EPROTO" }, + { EMULTIHOP, "EMULTIHOP" }, + { EDOTDOT, "EDOTDOT" }, + { EBADMSG, "EBADMSG" }, + { EOVERFLOW, "EOVERFLOW" }, + { ENOTUNIQ, "ENOTUNIQ" }, + { EBADFD, "EBADFD" }, + { EREMCHG, "EREMCHG" }, + { ELIBACC, "ELIBACC" }, + { ELIBBAD, "ELIBBAD" }, + { ELIBSCN, "ELIBSCN" }, + { ELIBMAX, "ELIBMAX" }, + { ELIBEXEC, "ELIBEXEC" }, + { EILSEQ, "EILSEQ" }, + { ERESTART, "ERESTART" }, + { ESTRPIPE, "ESTRPIPE" }, + { EUSERS, "EUSERS" }, + { ENOTSOCK, "ENOTSOCK" }, + { EDESTADDRREQ, "EDESTADDRREQ" }, + { EMSGSIZE, "EMSGSIZE" }, + { EPROTOTYPE, "EPROTOTYPE" }, + { ENOPROTOOPT, "ENOPROTOOPT" }, + { EPROTONOSUPPORT, "EPROTONOSUPPORT" }, + { ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT" }, + { EOPNOTSUPP, "EOPNOTSUPP" }, + { EPFNOSUPPORT, "EPFNOSUPPORT" }, + { EAFNOSUPPORT, "EAFNOSUPPORT" }, + { EADDRINUSE, "EADDRINUSE" }, + { EADDRNOTAVAIL, "EADDRNOTAVAIL" }, + { ENETDOWN, "ENETDOWN" }, + { ENETUNREACH, "ENETUNREACH" }, + { ENETRESET, "ENETRESET" }, + { ECONNABORTED, "ECONNABORTED" }, + { ECONNRESET, "ECONNRESET" }, + { ENOBUFS, "ENOBUFS" }, + { EISCONN, "EISCONN" }, + { ENOTCONN, "ENOTCONN" }, + { ESHUTDOWN, "ESHUTDOWN" }, + { ETOOMANYREFS, "ETOOMANYREFS" }, + { ETIMEDOUT, "ETIMEDOUT" }, + { ECONNREFUSED, "ECONNREFUSED" }, + { EHOSTDOWN, "EHOSTDOWN" }, + { EHOSTUNREACH, "EHOSTUNREACH" }, + { EALREADY, "EALREADY" }, + { EINPROGRESS, "EINPROGRESS" }, + { ESTALE, "ESTALE" }, + { EUCLEAN, "EUCLEAN" }, + { ENOTNAM, "ENOTNAM" }, + { ENAVAIL, "ENAVAIL" }, + { EISNAM, "EISNAM" }, + { EREMOTEIO, "EREMOTEIO" }, + { EDQUOT, "EDQUOT" }, + { ENOMEDIUM, "ENOMEDIUM" }, + { EMEDIUMTYPE, "EMEDIUMTYPE" } +}; + +#endif /* CONFIG_LIBC_STRERROR_SHORT */ + #define NERRNO_STRS (sizeof(g_errnomap) / sizeof(struct errno_strmap_s)) +#endif /* CONFIG_LIBC_STRERROR */ + /************************************************************************ * Private Functions ************************************************************************/ @@ -210,8 +346,9 @@ static const struct errno_strmap_s g_errnomap[] = * Name: strerror ************************************************************************/ -const char *strerror(int errnum) +FAR const char *strerror(int errnum) { +#ifdef CONFIG_LIBC_STRERROR int ndxlow = 0; int ndxhi = NERRNO_STRS - 1; int ndxmid; @@ -233,5 +370,6 @@ const char *strerror(int errnum) } } while (ndxlow <= ndxhi); +#endif return "Unknown error"; } diff --git a/nuttx/lib/string/lib_strlen.c b/nuttx/lib/string/lib_strlen.c index ee964c1371..8333058091 100644 --- a/nuttx/lib/string/lib_strlen.c +++ b/nuttx/lib/string/lib_strlen.c @@ -2,7 +2,7 @@ * lib/string/lib_strlen.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strncasecmp.c b/nuttx/lib/string/lib_strncasecmp.c index 78b18a3fb8..be369cf0d8 100644 --- a/nuttx/lib/string/lib_strncasecmp.c +++ b/nuttx/lib/string/lib_strncasecmp.c @@ -2,7 +2,7 @@ * lib/string/lib_strncasecmp.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strncat.c b/nuttx/lib/string/lib_strncat.c index 6b7d54f816..af893e0f9b 100644 --- a/nuttx/lib/string/lib_strncat.c +++ b/nuttx/lib/string/lib_strncat.c @@ -2,7 +2,7 @@ * lib/string/lib_strncat.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strncmp.c b/nuttx/lib/string/lib_strncmp.c index 147dfc5369..ce22820249 100644 --- a/nuttx/lib/string/lib_strncmp.c +++ b/nuttx/lib/string/lib_strncmp.c @@ -2,7 +2,7 @@ * lib/lib_strncmp.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strncpy.c b/nuttx/lib/string/lib_strncpy.c index b5702cae21..149369d508 100644 --- a/nuttx/lib/string/lib_strncpy.c +++ b/nuttx/lib/string/lib_strncpy.c @@ -2,7 +2,7 @@ * lib/string/lib_strncpy.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strndup.c b/nuttx/lib/string/lib_strndup.c index 68b7c74c36..ffaf892eaa 100644 --- a/nuttx/lib/string/lib_strndup.c +++ b/nuttx/lib/string/lib_strndup.c @@ -2,7 +2,7 @@ * lib/string//lib_strndup.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strnlen.c b/nuttx/lib/string/lib_strnlen.c index c2ffc248e6..2b64fe9845 100644 --- a/nuttx/lib/string/lib_strnlen.c +++ b/nuttx/lib/string/lib_strnlen.c @@ -9,7 +9,7 @@ * Derives from the file lib/lib_strlen.c: * * Copyright (C) 2007, 2008, 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strpbrk.c b/nuttx/lib/string/lib_strpbrk.c index 1340587750..02e2ea2c70 100644 --- a/nuttx/lib/string/lib_strpbrk.c +++ b/nuttx/lib/string/lib_strpbrk.c @@ -2,7 +2,7 @@ * lib/string/lib_strpbrk.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use str source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strrchr.c b/nuttx/lib/string/lib_strrchr.c index e89b26d523..91243ce589 100644 --- a/nuttx/lib/string/lib_strrchr.c +++ b/nuttx/lib/string/lib_strrchr.c @@ -2,7 +2,7 @@ * lib/string/lib_strrchr.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strspn.c b/nuttx/lib/string/lib_strspn.c index e5cab9ad65..e7b5ea0a5b 100644 --- a/nuttx/lib/string/lib_strspn.c +++ b/nuttx/lib/string/lib_strspn.c @@ -2,7 +2,7 @@ * lib/string/lib_strspn.c * * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strstr.c b/nuttx/lib/string/lib_strstr.c index 27ca6e19bb..b8c896fa2e 100644 --- a/nuttx/lib/string/lib_strstr.c +++ b/nuttx/lib/string/lib_strstr.c @@ -2,7 +2,7 @@ * lib/string/lib_strstr.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use str source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strtod.c b/nuttx/lib/string/lib_strtod.c index 86719c5105..8fecd45713 100644 --- a/nuttx/lib/string/lib_strtod.c +++ b/nuttx/lib/string/lib_strtod.c @@ -37,10 +37,15 @@ * Included Files ****************************************************************************/ +#include +#include + #include #include #include +#ifdef CONFIG_HAVE_DOUBLE + /**************************************************************************** * Pre-processor definitions ****************************************************************************/ @@ -232,3 +237,5 @@ double_t strtod(const char *str, char **endptr) return number; } +#endif /* CONFIG_HAVE_DOUBLE */ + diff --git a/nuttx/lib/string/lib_strtok.c b/nuttx/lib/string/lib_strtok.c index bafa94853e..c409931359 100644 --- a/nuttx/lib/string/lib_strtok.c +++ b/nuttx/lib/string/lib_strtok.c @@ -2,7 +2,7 @@ * lib/string/lib_strtok.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strtokr.c b/nuttx/lib/string/lib_strtokr.c index 366a318198..1c571b6ae5 100644 --- a/nuttx/lib/string/lib_strtokr.c +++ b/nuttx/lib/string/lib_strtokr.c @@ -2,7 +2,7 @@ * lib/string/lib_strtokr.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -90,7 +90,7 @@ * ****************************************************************************/ -char *strtok_r(char *str, const char *delim, char **saveptr) +FAR char *strtok_r(FAR char *str, FAR const char *delim, FAR char **saveptr) { char *pbegin; char *pend = NULL; diff --git a/nuttx/lib/string/lib_strtol.c b/nuttx/lib/string/lib_strtol.c index 4f69047934..c17d87e635 100644 --- a/nuttx/lib/string/lib_strtol.c +++ b/nuttx/lib/string/lib_strtol.c @@ -2,7 +2,7 @@ * lib/string/lib_strtol.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strtoll.c b/nuttx/lib/string/lib_strtoll.c index 9c730b4310..242e025c07 100644 --- a/nuttx/lib/string/lib_strtoll.c +++ b/nuttx/lib/string/lib_strtoll.c @@ -2,7 +2,7 @@ * lib/string/lib_strtoll.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strtoul.c b/nuttx/lib/string/lib_strtoul.c index 2aacc7cea8..b0d2d090e6 100644 --- a/nuttx/lib/string/lib_strtoul.c +++ b/nuttx/lib/string/lib_strtoul.c @@ -2,7 +2,7 @@ * /lib/string/lib_strtoul.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/string/lib_strtoull.c b/nuttx/lib/string/lib_strtoull.c index 3341621481..6567457c0e 100644 --- a/nuttx/lib/string/lib_strtoull.c +++ b/nuttx/lib/string/lib_strtoull.c @@ -2,7 +2,7 @@ * /lib/string/lib_strtoull.c * * Copyright (C) 2009, 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_calendar2utc.c b/nuttx/lib/time/lib_calendar2utc.c index 642e23568a..e80c292fc6 100644 --- a/nuttx/lib/time/lib_calendar2utc.c +++ b/nuttx/lib/time/lib_calendar2utc.c @@ -2,7 +2,7 @@ * lib/time/lib_calendar2utc.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_daysbeforemonth.c b/nuttx/lib/time/lib_daysbeforemonth.c index 4312adaba2..8000b0e7a9 100644 --- a/nuttx/lib/time/lib_daysbeforemonth.c +++ b/nuttx/lib/time/lib_daysbeforemonth.c @@ -2,7 +2,7 @@ * lib/time/lib_daysbeforemonth.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_gmtime.c b/nuttx/lib/time/lib_gmtime.c index 7bce8391ed..99afeded9e 100644 --- a/nuttx/lib/time/lib_gmtime.c +++ b/nuttx/lib/time/lib_gmtime.c @@ -2,7 +2,7 @@ * lib/time/lib_gmtime.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_gmtimer.c b/nuttx/lib/time/lib_gmtimer.c index 146939e7a4..ba1c9724f1 100644 --- a/nuttx/lib/time/lib_gmtimer.c +++ b/nuttx/lib/time/lib_gmtimer.c @@ -2,7 +2,7 @@ * lib/time/lib_gmtimer.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_isleapyear.c b/nuttx/lib/time/lib_isleapyear.c index 24d7d6153d..966c248e01 100644 --- a/nuttx/lib/time/lib_isleapyear.c +++ b/nuttx/lib/time/lib_isleapyear.c @@ -2,7 +2,7 @@ * lib/time/lib_isleapyear.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_mktime.c b/nuttx/lib/time/lib_mktime.c index 2e8cfc119e..8c17e7c0ab 100644 --- a/nuttx/lib/time/lib_mktime.c +++ b/nuttx/lib/time/lib_mktime.c @@ -2,7 +2,7 @@ * lib/time/lib_mktime.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_strftime.c b/nuttx/lib/time/lib_strftime.c index c1ac345ee0..cd0804f55d 100644 --- a/nuttx/lib/time/lib_strftime.c +++ b/nuttx/lib/time/lib_strftime.c @@ -2,7 +2,7 @@ * lib/time/lib_strftime.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/time/lib_time.c b/nuttx/lib/time/lib_time.c index 02853132b0..106a04c366 100644 --- a/nuttx/lib/time/lib_time.c +++ b/nuttx/lib/time/lib_time.c @@ -2,7 +2,7 @@ * lib/time/lib_time.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/unistd/lib_chdir.c b/nuttx/lib/unistd/lib_chdir.c index f79b424ff0..3dd1333cec 100644 --- a/nuttx/lib/unistd/lib_chdir.c +++ b/nuttx/lib/unistd/lib_chdir.c @@ -2,7 +2,7 @@ * lib/unistd/lib_chdir.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/unistd/lib_getcwd.c b/nuttx/lib/unistd/lib_getcwd.c index 9bfa102fb6..b94823300b 100644 --- a/nuttx/lib/unistd/lib_getcwd.c +++ b/nuttx/lib/unistd/lib_getcwd.c @@ -2,7 +2,7 @@ * lib/unistd/lib_getcwd.c * * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/unistd/lib_getopt.c b/nuttx/lib/unistd/lib_getopt.c index 26a2c7fae4..832d287213 100644 --- a/nuttx/lib/unistd/lib_getopt.c +++ b/nuttx/lib/unistd/lib_getopt.c @@ -2,7 +2,7 @@ * lib/unistd/lib_getopt.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/unistd/lib_getoptargp.c b/nuttx/lib/unistd/lib_getoptargp.c index 4a483c051b..98a4850169 100644 --- a/nuttx/lib/unistd/lib_getoptargp.c +++ b/nuttx/lib/unistd/lib_getoptargp.c @@ -2,7 +2,7 @@ * lib/unistd/lib_getoptargp.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/unistd/lib_getoptindp.c b/nuttx/lib/unistd/lib_getoptindp.c index 002201aa94..7714f8e708 100644 --- a/nuttx/lib/unistd/lib_getoptindp.c +++ b/nuttx/lib/unistd/lib_getoptindp.c @@ -2,7 +2,7 @@ * lib/unistd/lib_getoptindp.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/unistd/lib_getoptoptp.c b/nuttx/lib/unistd/lib_getoptoptp.c index 2214f2d141..4805b7ac3b 100644 --- a/nuttx/lib/unistd/lib_getoptoptp.c +++ b/nuttx/lib/unistd/lib_getoptoptp.c @@ -2,7 +2,7 @@ * lib/unistd/lib_getoptoptp.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/libxx/Makefile b/nuttx/libxx/Makefile index f34a526000..4122931ac9 100644 --- a/nuttx/libxx/Makefile +++ b/nuttx/libxx/Makefile @@ -2,7 +2,7 @@ # libxx/Makefile # # Copyright (C) 2009 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/libxx/libxx_delete.cxx b/nuttx/libxx/libxx_delete.cxx index 223a7bea90..d9203a2280 100644 --- a/nuttx/libxx/libxx_delete.cxx +++ b/nuttx/libxx/libxx_delete.cxx @@ -2,7 +2,7 @@ // libxx/libxx_new.cxx // // Copyright (C) 2009 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt +// Author: Gregory Nutt // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions diff --git a/nuttx/libxx/libxx_deletea.cxx b/nuttx/libxx/libxx_deletea.cxx index 3c519bd2ce..e7cfee647b 100644 --- a/nuttx/libxx/libxx_deletea.cxx +++ b/nuttx/libxx/libxx_deletea.cxx @@ -2,7 +2,7 @@ // libxx/libxx_newa.cxx // // Copyright (C) 2009 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt +// Author: Gregory Nutt // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions diff --git a/nuttx/libxx/libxx_new.cxx b/nuttx/libxx/libxx_new.cxx index 8ec725ca8b..0563b65805 100644 --- a/nuttx/libxx/libxx_new.cxx +++ b/nuttx/libxx/libxx_new.cxx @@ -2,7 +2,7 @@ // libxx/libxx_new.cxx // // Copyright (C) 2009 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt +// Author: Gregory Nutt // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions diff --git a/nuttx/libxx/libxx_newa.cxx b/nuttx/libxx/libxx_newa.cxx index 855160c412..ad78068653 100644 --- a/nuttx/libxx/libxx_newa.cxx +++ b/nuttx/libxx/libxx_newa.cxx @@ -2,7 +2,7 @@ // libxx/libxx_newa.cxx // // Copyright (C) 2009 Gregory Nutt. All rights reserved. -// Author: Gregory Nutt +// Author: Gregory Nutt // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions diff --git a/nuttx/mm/Kconfig b/nuttx/mm/Kconfig index 000217dc5c..5da12b65e9 100644 --- a/nuttx/mm/Kconfig +++ b/nuttx/mm/Kconfig @@ -3,15 +3,6 @@ # see misc/tools/kconfig-language.txt. # -config MM_REGIONS - int "Number of memory regions" - default 1 - ---help--- - If the architecture includes multiple, non-contiguous regions of - memory to allocate from, this specifies the number of memory regions - that the memory manager must handle and enables the API - mm_addregion(start, end); - config MM_SMALL bool "Small memory model" default n @@ -24,3 +15,71 @@ config MM_SMALL have internal SRAM of size less than or equal to 64Kb. In this case, CONFIG_MM_SMALL can be defined so that those MCUs will also benefit from the smaller, 16-bit-based allocation overhead. + +config MM_REGIONS + int "Number of memory regions" + default 1 + ---help--- + If the architecture includes multiple, non-contiguous regions of + memory to allocate from, this specifies the number of memory regions + that the memory manager must handle and enables the API + mm_addregion(start, end); + +config ARCH_HAVE_HEAP2 + bool + +config HEAP2_BASE + hex "Start address of second heap region" + default 0x00000000 + depends on ARCH_HAVE_HEAP2 + ---help--- + The base address of the second heap region. + +config HEAP2_SIZE + int "Size of the second heap region" + default 0 + depends on ARCH_HAVE_HEAP2 + ---help--- + The size of the second heap region. + +config GRAN + bool "Enable Granule Allocator" + default n + ---help--- + Enable granual allocator support. Allocations will be aligned to the + granule size; allocations will be in units of the granule size. + Larger granules will give better performance and less overhead but + more losses of memory due to alignment and quantization waste. + + NOTE: The current implementation also restricts the maximum + allocation size to 32 granaules. That restriction could be + eliminated with some additional coding effort. + +config GRAN_SINGLE + bool "Single Granule Allocator" + default n + depends on GRAN + ---help--- + Select if there is only one instance of the granule allocator (i.e., + gran_initialize will be called only once. In this case, (1) there + are a few optimizations that can can be done and (2) the GRAN_HANDLE + is not needed. + +config GRAN_INTR + bool "Interrupt level support" + default n + depends on GRAN + ---help--- + Normally mutual exclusive access to granule allocator data is assured + using a semaphore. If this option is set then, instead, mutual + exclusion logic will disable interrupts. While this options is more + invasive to system performance, it will also support use of the granule + allocator from interrupt level logic. + +config DEBUG_GRAN + bool "Granule Allocator Debug" + default n + depends on GRAN && DEBUG + ---help--- + Just like CONFIG_DEBUG_MM, but only generates ouput from the gran + allocation logic. diff --git a/nuttx/mm/Makefile b/nuttx/mm/Makefile index 7e6eb68a75..0ccf5a09a9 100644 --- a/nuttx/mm/Makefile +++ b/nuttx/mm/Makefile @@ -1,7 +1,7 @@ ############################################################################ # mm/Makefile # -# Copyright (C) 2007 Gregory Nutt. All rights reserved. +# Copyright (C) 2007, 2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -36,10 +36,15 @@ -include $(TOPDIR)/Make.defs ASRCS = -AOBJS = $(ASRCS:.S=$(OBJEXT)) CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \ mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \ mm_memalign.c mm_free.c mm_mallinfo.c + +ifeq ($(CONFIG_GRAN),y) +CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c mm_grancritical.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) diff --git a/nuttx/mm/README.txt b/nuttx/mm/README.txt new file mode 100644 index 0000000000..2668432e3c --- /dev/null +++ b/nuttx/mm/README.txt @@ -0,0 +1,92 @@ +mm/README.txt +============= + +This directory contains the NuttX memory management logic. This include: + +1) The standard memory management functions as prototyped in stdlib.h as + specified in the Base definitions volume of IEEE Std 1003.1-2001. This + include the files: + + o Standard Interfaces: mm_malloc.c, mm_calloc.c, mm_realloc.c, + mm_memalign.c, mm_free.c + o Less-Standard Interfaces: mm_zalloc.c, mm_mallinfo.c + o Internal Implementation: mm_initialize.c mm_sem.c mm_addfreechunk.c + mm_size2ndx.c mm_shrinkchunk.c, mm_internal.h + o Build and Configuration files: Kconfig, Makefile + + Memory Models: + + o Small Memory Model. If the MCU supports only 16-bit data addressing + then the small memory model is automatically used. The maximum size + of the heap is then 64K. The small memory model can also be forced + MCUs with wider addressing by defining CONFIG_SMALL_MEMORY in the + NuttX configuration file. + o Large Memory Model. Otherwise, the allocator uses a model that + supports a heap of up to 4G. + + This implementation uses a variable length allocator with the following + properties: + + o Overhead: Either 8- or 4-bytes per allocation for large and small + models, respectively. + o Alignment: All allocations are aligned to 8- or 4-bytes for large + and small models, respectively. + +2) Test Program. There is also a host-best test program that can be + used to verify the memory manager. These are the file: + + Makefile.test, mm_test.c, and mm_environment.h. + + Build instructions: + + make -f Makefile.test + + The executable will be built in the top-level directory as nuttx/mm_text + (or mm_test.exe under Cygwin). + +3) Granule Allocator. A non-standard granule allocator is also available + in this directory The granule allocator allocates memory in units + of a fixed sized block ("granule"). Allocations may be aligned to a user- + provided address boundary. + + The granule allocator interfaces are defined in nuttx/include/nuttx/gran.h. + The granule allocator consists of these files in this directory: + + mm_gran.h, mm_granalloc.c, mm_grancritical.c, mm_granfree.c + mm_graninit.c + + The granule allocator is not used anywhere within the base NuttX code + as of this writing. The intent of the granule allocator is to provide + a tool to support platform-specific management of aligned DMA memory. + + NOTE: Because each granule may be aligned and each allocation is in + units of the granule size, selection of the granule size is important: + Larger granules will give better performance and less overhead but more + losses of memory due to quantization waste. Additional memory waste + can occur from alignment; Of course, heap alignment should no be + used unless (a) you are using the granule allocator to manage DMA memory + and (b) your hardware has specific memory alignment requirements. + + The current implementation also restricts the maximum allocation size + to 32 granules. That restriction could be eliminated with some + additional coding effort, but currently requires larger granule + sizes for larger allocations. + + Geneneral Usage Example. This is an example using the GCC section + attribute to position a DMA heap in memory (logic in the linker script + would assign the section .dmaheap to the DMA memory. + + FAR uint32_t g_dmaheap[DMAHEAP_SIZE] __attribute__((section(.dmaheap))); + + The heap is created by calling gran_initialize. Here the granual size + is set to 64 bytes and the alignment to 16 bytes: + + GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4); + + Then the GRAN_HANDLE can be used to allocate memory (There is no + GRAN_HANDLE if CONFIG_GRAN_SINGLE=y): + + FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47); + + The actual memory allocates will be 64 byte (wasting 17 bytes) and + will be aligned at least to (1 << log2align). diff --git a/nuttx/mm/mm_environment.h b/nuttx/mm/mm_environment.h index 70e611116a..d28fbf1d77 100644 --- a/nuttx/mm/mm_environment.h +++ b/nuttx/mm/mm_environment.h @@ -105,12 +105,16 @@ extern void mm_addregion(FAR void *heapstart, size_t heapsize); /* Debug macros are always on */ -# define CONFIG_DEBUG +# define CONFIG_DEBUG 1 # undef mdbg # define mdbg(format, arg...) printf(format, ##arg) # undef mvdg # define mvdbg(format, arg...) printf(format, ##arg) +# undef mlldbg +# define mlldbg(format, arg...) printf(format, ##arg) +# undef mllvdg +# define mllvdbg(format, arg...) printf(format, ##arg) #else # define mm_errno get_errno() diff --git a/nuttx/mm/mm_gran.h b/nuttx/mm/mm_gran.h new file mode 100644 index 0000000000..a4f51490d7 --- /dev/null +++ b/nuttx/mm/mm_gran.h @@ -0,0 +1,132 @@ +/**************************************************************************** + * mm/mm_gran.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __MM_MM_GRAN_H +#define __MM_MM_GRAN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Sizes of things */ + +#define SIZEOF_GAT(n) \ + ((n + 31) >> 5) +#define SIZEOF_GRAN_S(n) \ + (sizeof(struct gran_s) + sizeof(uint32_t) * (SIZEOF_GAT(n) - 1)) + +/* Debug */ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_DEBUG_GRAM +# define gramdbg(format, arg...) dbg(format, ##arg) +# define gramvdbg(format, arg...) vdbg(format, ##arg) +# else +# define gramdbg(format, arg...) mdbg(format, ##arg) +# define gramvdbg(format, arg...) mvdbg(format, ##arg) +# endif +#else +# ifdef CONFIG_DEBUG_GRAM +# define gramdbg dbg +# define gramvdbg vdbg +# else +# define gramdbg (void) +# define gramvdbg (void) +# endif +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This structure represents the state of on granual allocation */ + +struct gran_s +{ + uint8_t log2gran; /* Log base 2 of the size of one granule */ + uint16_t ngranules; /* The total number of (aligned) granules in the heap */ +#ifdef CONFIG_GRAN_INTR + irqstate_t irqstate; /* For exclusive access to the GAT */ +#else + sem_t exclsem; /* For exclusive access to the GAT */ +#endif + uintptr_t heapstart; /* The aligned start of the granule heap */ + uint32_t gat[1]; /* Start of the granule allocation table */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* State of the single GRAN allocator */ + +#ifdef CONFIG_GRAN_SINGLE +extern FAR struct gran_s *g_graninfo; +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_enter_critical and gran_leave_critical + * + * Description: + * Critical section management for the granule allocator. + * + * Input Parameters: + * priv - Pointer to the gran state + * + * Returned Value: + * None + * + ****************************************************************************/ + +void gran_enter_critical(FAR struct gran_s *priv); +void gran_leave_critical(FAR struct gran_s *priv); + +#endif /* __MM_MM_GRAN_H */ diff --git a/nuttx/mm/mm_granalloc.c b/nuttx/mm/mm_granalloc.c new file mode 100644 index 0000000000..e95709b31a --- /dev/null +++ b/nuttx/mm/mm_granalloc.c @@ -0,0 +1,358 @@ +/**************************************************************************** + * mm/mm_granalloc.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#include "mm_gran.h" + +#ifdef CONFIG_GRAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_common_alloc + * + * Description: + * Allocate memory from the granule heap. + * + * Input Parameters: + * priv - The granule heap state structure. + * alloc - The adress of the allocation. + * ngranules - The number of granules allocated + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline void gran_mark_allocated(FAR struct gran_s *priv, + uintptr_t alloc, + unsigned int ngranules) +{ + unsigned int granno; + unsigned int gatidx; + unsigned int gatbit; + unsigned int avail; + uint32_t gatmask; + + /* Determine the granule number of the allocation */ + + granno = (alloc - priv->heapstart) >> priv->log2gran; + + /* Determine the GAT table index associated with the allocation */ + + gatidx = granno >> 5; + gatbit = granno & 31; + + /* Mark bits in the GAT entry or entries */ + + avail = 32 - gatbit; + if (ngranules > avail) + { + /* Mark bits in the first GAT entry */ + + gatmask =0xffffffff << gatbit; + DEBUGASSERT((priv->gat[gatidx] & gatmask) == 0); + + priv->gat[gatidx] |= gatmask; + ngranules -= avail; + + /* Mark bits in the second GAT entry */ + + gatmask = 0xffffffff >> (32 - ngranules); + DEBUGASSERT((priv->gat[gatidx+1] & gatmask) == 0); + + priv->gat[gatidx+1] |= gatmask; + } + + /* Handle the case where where all of the granules come from one entry */ + + else + { + /* Mark bits in a single GAT entry */ + + gatmask = 0xffffffff >> (32 - ngranules); + gatmask <<= gatbit; + DEBUGASSERT((priv->gat[gatidx] & gatmask) == 0); + + priv->gat[gatidx] |= gatmask; + return; + } + +} + +/**************************************************************************** + * Name: gran_common_alloc + * + * Description: + * Allocate memory from the granule heap. + * + * Input Parameters: + * priv - The granule heap state structure. + * size - The size of the memory region to allocate. + * + * Returned Value: + * On success, a non-NULL pointer to the allocated memory is returned. + * + ****************************************************************************/ + +static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) +{ + unsigned int ngranules; + size_t tmpmask; + uintptr_t alloc; + uint32_t curr; + uint32_t next; + uint32_t mask; + int granidx; + int gatidx; + int bitidx; + int shift; + + DEBUGASSERT(priv && size <= 32 * (1 << priv->log2gran)); + + if (priv && size > 0) + { + /* Get exclusive access to the GAT */ + + gran_enter_critical(priv); + + /* How many contiguous granules we we need to find? */ + + tmpmask = (1 << priv->log2gran) - 1; + ngranules = (size + tmpmask) >> priv->log2gran; + + /* Then create mask for that number of granules */ + + DEBUGASSERT(ngranules <= 32); + mask = 0xffffffff >> (32 - ngranules); + + /* Now search the granule allocation table for that number of contiguous */ + + alloc = priv->heapstart; + + for (granidx = 0; granidx < priv->ngranules; granidx += 32) + { + /* Get the GAT index associated with the granule table entry */ + + gatidx = granidx >> 5; + curr = priv->gat[gatidx]; + + /* Handle the case where there are no free granules in the entry */ + + if (curr == 0xffffffff) + { + alloc += (32 << priv->log2gran); + continue; + } + + /* Get the next entry from the GAT to support a 64 bit shift */ + + if (granidx < priv->ngranules) + { + next = priv->gat[gatidx + 1]; + } + + /* Use all ones when are at the last entry in the GAT (meaning + * nothing can be allocated. + */ + + else + { + next = 0xffffffff; + } + + /* Search through the allocations in the 'curr' GAT entry + * to see if we can satisfy the allocation starting in that + * entry. + * + * This loop continues until either all of the bits have been + * examined (bitidx >= 32), or until there are insufficient + * granules left to satisfy the allocation. + */ + + for (bitidx = 0; + bitidx < 32 && (granidx + bitidx + ngranules) <= priv->ngranules; + ) + { + /* Break out if there are no further free bits in 'curr'. + * All of the zero bits might have gotten shifted out. + */ + + if (curr == 0xffffffff) + { + break; + } + + /* Check for the first zero bit in the lower or upper 16-bits. + * From the test above, we know that at least one of the 32- + * bits in 'curr' is zero. + */ + + else if ((curr & 0x0000ffff) == 0x0000ffff) + { + /* Not in the lower 16 bits. The first free bit must be + * in the upper 16 bits. + */ + + shift = 16; + } + + /* We know that the first free bit is now within the lower 16 + * bits of 'curr'. Is it in the upper or lower byte? + */ + + else if ((curr & 0x0000ff) == 0x000000ff) + { + /* Not in the lower 8 bits. The first free bit must be in + * the upper 8 bits. + */ + + shift = 8; + } + + /* We know that the first free bit is now within the lower 4 + * bits of 'curr'. Is it in the upper or lower nibble? + */ + + else if ((curr & 0x00000f) == 0x0000000f) + { + /* Not in the lower 4 bits. The first free bit must be in + * the upper 4 bits. + */ + + shift = 4; + } + + /* We know that the first free bit is now within the lower 4 bits + * of 'curr'. Is it in the upper or lower pair? + */ + + else if ((curr & 0x000003) == 0x00000003) + { + /* Not in the lower 2 bits. The first free bit must be in + * the upper 2 bits. + */ + + shift = 2; + } + + /* We know that the first free bit is now within the lower 4 bits + * of 'curr'. Check if we have the allocation at this bit position. + */ + + else if ((curr & mask) == 0) + { + /* Yes.. mark these granules allocated */ + + gran_mark_allocated(priv, alloc, ngranules); + + /* And return the allocation address */ + + gran_leave_critical(priv); + return (FAR void *)alloc; + } + + /* The free allocation does not start at this position */ + + else + { + shift = 1; + } + + /* Set up for the next time through the loop. Perform a 64 + * bit shift to move to the next gram position andi ncrement + * to the next candidate allocation address. + */ + + alloc += (shift << priv->log2gran); + curr = (curr >> shift) | (next << (32 - shift)); + next >>= shift; + bitidx += shift; + } + } + } + + gran_leave_critical(priv); + return NULL; +} + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_alloc + * + * Description: + * Allocate memory from the granule heap. + * + * NOTE: The current implementation also restricts the maximum allocation + * size to 32 granules. That restriction could be eliminated with some + * additional coding effort. + * + * Input Parameters: + * handle - The handle previously returned by gran_initialize + * size - The size of the memory region to allocate. + * + * Returned Value: + * On success, either a non-NULL pointer to the allocated memory (if + * CONFIG_GRAN_SINGLE) or zero (if !CONFIG_GRAN_SINGLE) is returned. + * + ****************************************************************************/ + +#ifdef CONFIG_GRAN_SINGLE +FAR void *gran_alloc(size_t size) +{ + return gran_common_alloc(g_graninfo, size); +} +#else +FAR void *gran_alloc(GRAN_HANDLE handle, size_t size) +{ + return gran_common_alloc((FAR struct gran_s *)handle, size); +} +#endif + +#endif /* CONFIG_GRAN */ diff --git a/nuttx/mm/mm_grancritical.c b/nuttx/mm/mm_grancritical.c new file mode 100644 index 0000000000..190aa3e7d4 --- /dev/null +++ b/nuttx/mm/mm_grancritical.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * mm/mm_grancritical.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "mm_gran.h" + +#ifdef CONFIG_GRAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_enter_critical and gran_leave_critical + * + * Description: + * Critical section management for the granule allocator. + * + * Input Parameters: + * priv - Pointer to the gran state + * + * Returned Value: + * None + * + ****************************************************************************/ + +void gran_enter_critical(FAR struct gran_s *priv) +{ +#ifdef CONFIG_GRAN_INTR + priv->irqstate = irqsave(); +#else + int ret; + + /* Continue waiting if we are awakened by a signal */ + + do + { + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + DEBUGASSERT(errno == EINTR); + } + } + while (ret < 0); +#endif +} + +void gran_leave_critical(FAR struct gran_s *priv) +{ +#ifdef CONFIG_GRAN_INTR + irqrestore(priv->irqstate); +#else + sem_post(&priv->exclsem); +#endif +} + + +#endif /* CONFIG_GRAN */ + + diff --git a/nuttx/mm/mm_granfree.c b/nuttx/mm/mm_granfree.c new file mode 100644 index 0000000000..fcab11af98 --- /dev/null +++ b/nuttx/mm/mm_granfree.c @@ -0,0 +1,170 @@ +/**************************************************************************** + * mm/mm_granfree.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#include "mm_gran.h" + +#ifdef CONFIG_GRAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_common_free + * + * Description: + * Return memory to the granule heap. + * + * Input Parameters: + * handle - The handle previously returned by gran_initialize + * memory - A pointer to memory previoiusly allocated by gran_alloc. + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline void gran_common_free(FAR struct gran_s *priv, + FAR void *memory, size_t size) +{ + unsigned int granno; + unsigned int gatidx; + unsigned int gatbit; + unsigned int granmask; + unsigned int ngranules; + unsigned int avail; + uint32_t gatmask; + + DEBUGASSERT(priv && memory && size <= 32 * (1 << priv->log2gran)); + + /* Get exclusive access to the GAT */ + + gran_enter_critical(priv); + + /* Determine the granule number of the first granule in the allocation */ + + granno = ((uintptr_t)memory - priv->heapstart) >> priv->log2gran; + + /* Determine the GAT table index and bit number associated with the + * allocation. + */ + + gatidx = granno >> 5; + gatbit = granno & 31; + + /* Determine the number of granules in the allocation */ + + granmask = (1 << priv->log2gran) - 1; + ngranules = (size + granmask) >> priv->log2gran; + + /* Clear bits in the GAT entry or entries */ + + avail = 32 - gatbit; + if (ngranules > avail) + { + /* Clear bits in the first GAT entry */ + + gatmask = (0xffffffff << gatbit); + DEBUGASSERT((priv->gat[gatidx] & gatmask) == gatmask); + + priv->gat[gatidx] &= ~gatmask; + ngranules -= avail; + + /* Clear bits in the second GAT entry */ + + gatmask = 0xffffffff >> (32 - ngranules); + DEBUGASSERT((priv->gat[gatidx+1] & gatmask) == gatmask); + + priv->gat[gatidx+1] &= ~gatmask; + } + + /* Handle the case where where all of the granules came from one entry */ + + else + { + /* Clear bits in a single GAT entry */ + + gatmask = 0xffffffff >> (32 - ngranules); + gatmask <<= gatbit; + DEBUGASSERT((priv->gat[gatidx] & gatmask) == gatmask); + + priv->gat[gatidx] &= ~gatmask; + } + + gran_leave_critical(priv); +} + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_free + * + * Description: + * Return memory to the granule heap. + * + * Input Parameters: + * handle - The handle previously returned by gran_initialize + * memory - A pointer to memory previoiusly allocated by gran_alloc. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_GRAN_SINGLE +void gran_free(FAR void *memory, size_t size) +{ + return gran_common_free(g_graninfo, memory, size); +} +#else +void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size) +{ + return gran_common_free((FAR struct gran_s *)handle, memory, size); +} +#endif + +#endif /* CONFIG_GRAN */ diff --git a/nuttx/mm/mm_graninit.c b/nuttx/mm/mm_graninit.c new file mode 100644 index 0000000000..e43839ad60 --- /dev/null +++ b/nuttx/mm/mm_graninit.c @@ -0,0 +1,230 @@ +/**************************************************************************** + * mm/mm_graninit.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "mm_gran.h" + +#ifdef CONFIG_GRAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* State of the single GRAN allocator */ + +#ifdef CONFIG_GRAN_SINGLE +FAR struct gran_s *g_graninfo; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_common_initialize + * + * Description: + * Perfrom common GRAN initialization. + * + * Input Parameters: + * info - Private granule data structure pointer + * heapstart - Start of the granule allocation heap + * heapsize - Size of heap in bytes + * log2gran - Log base 2 of the size of one granule. 0->1 byte, + * 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. + * log2align - Log base 2 of required alignment. 0->1 byte, + * 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. Note that + * log2gran must be greater than or equal to log2align + * so that all contiguous granules in memory will meet + * the minimum alignment requirement. A value of zero + * would mean that no alignment is required. + * + * Returned Value: + * On success, a non-NULL info structure is returned that may be used with + * other granule allocator interfaces. + * + ****************************************************************************/ + +static inline FAR struct gran_s * +gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, + uint8_t log2align) +{ + FAR struct gran_s *priv; + uintptr_t heapend; + uintptr_t alignedstart; + unsigned int mask; + unsigned int alignedsize; + unsigned int ngranules; + + /* Check parameters if debug is on. Note the the size of a granual is + * limited to 2**31 bytes and that the size of the granule must be greater + * than the alignment size. + */ + + DEBUGASSERT(heapstart && heapsize > 0 && + log2gran > 0 && log2gran < 32 && + log2gran > log2align); + + /* Get the aligned start of the heap */ + + mask = (1 << log2align) - 1; + alignedstart = ((uintptr_t)heapstart + mask) & ~mask; + + /* Determine the number of granules */ + + mask = (1 << log2gran) - 1; + heapend = (uintptr_t)heapstart + heapsize; + alignedsize = (heapend - alignedstart) & ~mask; + ngranules = alignedsize >> log2gran; + + /* Allocate the information structure with a granule table of the + * correct size. + */ + + priv = ( FAR struct gran_s *)zalloc(SIZEOF_GRAN_S(ngranules)); + if (priv) + { + /* Initialize non-zero elements of the granules heap info structure */ + + priv->log2gran = log2gran; + priv->ngranules = ngranules; + priv->heapstart = alignedstart; + + /* Initialize mutual exclusion support */ + +#ifndef CONFIG_GRAN_INTR + sem_init(&priv->exclsem, 0, 1); +#endif + } + + return priv; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gran_initialize + * + * Description: + * Set up one granule allocator instance. Allocations will be aligned to + * the alignment size (log2align; allocations will be in units of the + * granule size (log2gran). Larger granules will give better performance + * and less overhead but more losses of memory due to quantization waste. + * Additional memory waste can occur from alignment; log2align should be + * set to 0 unless you are using the granule allocator to manage DMA memory + * and your hardware has specific memory alignment requirements. + * + * Geneneral Usage Summary. This is an example using the GCC section + * attribute to position a DMA heap in memory (logic in the linker script + * would assign the section .dmaheap to the DMA memory. + * + * FAR uint32_t g_dmaheap[DMAHEAP_SIZE] __attribute__((section(.dmaheap))); + * + * The heap is created by calling gran_initialize(). Here the granual size + * is set to 64 bytes (2**6) and the alignment to 16 bytes (2**4): + * + * GRAN_HANDLE handle = gran_initialize(g_dmaheap, DMAHEAP_SIZE, 6, 4); + * + * Then the GRAN_HANDLE can be used to allocate memory (There is no + * GRAN_HANDLE if CONFIG_GRAN_SINGLE=y): + * + * FAR uint8_t *dma_memory = (FAR uint8_t *)gran_alloc(handle, 47); + * + * The actual memory allocates will be 64 byte (wasting 17 bytes) and + * will be aligned at least to (1 << log2align). + * + * NOTE: The current implementation also restricts the maximum allocation + * size to 32 granules. That restriction could be eliminated with some + * additional coding effort. + * + * Input Parameters: + * heapstart - Start of the granule allocation heap + * heapsize - Size of heap in bytes + * log2gran - Log base 2 of the size of one granule. 0->1 byte, + * 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. + * log2align - Log base 2 of required alignment. 0->1 byte, + * 1->2 bytes, 2->4 bytes, 3-> 8 bytes, etc. Note that + * log2gran must be greater than or equal to log2align + * so that all contiguous granules in memory will meet + * the minimum alignment requirement. A value of zero + * would mean that no alignment is required. + * + * Returned Value: + * On success, a non-NULL handle is returned that may be used with other + * granual allocator interfaces. + * + ****************************************************************************/ + +#ifdef CONFIG_GRAN_SINGLE +int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran, + uint8_t log2align) +int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran) +{ + g_graninfo = gran_common_initialize(heapstart, heapsize, log2gran, + log2align); + if (!g_graninfo) + { + return -ENOMEM; + } + + return OK; +} +#else +GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize, + uint8_t log2gran, uint8_t log2align) +{ + return (GRAN_HANDLE)gran_common_initialize(heapstart, heapsize, + log2gran, log2align); +} +#endif + +#endif /* CONFIG_GRAN */ diff --git a/nuttx/net/Kconfig b/nuttx/net/Kconfig index dc16150ba6..718b28b8fd 100644 --- a/nuttx/net/Kconfig +++ b/nuttx/net/Kconfig @@ -9,13 +9,32 @@ config NET ---help--- Enable or disable all network features +config ARCH_HAVE_PHY + bool + if NET +choice + prompt "Board PHY Selection" + depends on ARCH_HAVE_PHY + default PHY_KS8721 + +config PHY_KS8721 + bool "Micrel KS8721 PHY" + +config PHY_DP83848C + bool "National Semiconduction DP83848C PHY" + +config PHY_LAN8720 + bool "SMSC LAN8720 PHY" + +endchoice + config NET_NOINTS bool "Not interrupt driven" default n ---help--- - NET_NOINT indicates that uIP not called from the interrupt level. + NET_NOINT indicates that uIP is not called from the interrupt level. If NET_NOINTS is defined, critical sections will be managed with semaphores; Otherwise, it assumed that uIP will be called from interrupt level handling and critical sections will be managed by enabling and disabling interrupts. @@ -45,9 +64,10 @@ config NSOCKET_DESCRIPTORS config NET_NACTIVESOCKETS int "Max socket operations" + default 16 ---help--- Maximum number of concurrent socket operations (recv, send, etc.). - Default: NET_TCP_CONNS+NET_UCP_CONNS + Default: 16 config NET_SOCKOPTS bool "Socket options" @@ -93,16 +113,43 @@ config NET_MAX_LISTENPORTS Maximum number of listening TCP/IP ports (all tasks). Default: 20 config NET_TCP_READAHEAD_BUFSIZE - bool "TCP/IP read-ahead buffer size" + int "TCP/IP read-ahead buffer size" default 562 ---help--- - Size of TCP/IP read-ahead buffers + Read-ahead buffers allows buffering of TCP/IP packets when there is no + receive in place to catch the TCP packet. In that case, the packet + will be retained in the NuttX read-ahead buffers. + + This setting specifies the size of one TCP/IP read-ahead buffer. + This should best be a equal to the maximum packet size (NET_BUFSIZE). config NET_NTCP_READAHEAD_BUFFERS int "Number of TCP/IP read-ahead buffers" default 8 ---help--- - Number of TCP/IP read-ahead buffers (may be zero) + Read-ahead buffers allows buffering of TCP/IP packets when there is no + receive in place to catch the TCP packet. In that case, the packet + will be retained in the NuttX read-ahead buffers. + + This setting specifies the number of TCP/IP read-ahead buffers This + value can be set to zero to disable all TCP/IP read-ahead buffering. + You might want to disable TCP/IP read-ahead buffering on a highly + memory constained system that does not have any TCP/IP packet rate + issues. + +config NET_TCP_RECVDELAY + int "TCP Rx delay" + default 0 + ---help--- + If NET_NTCP_READAHEAD_BUFFERS is zero, then there will be no buffering + of TCP/IP packets: Any TCP/IP packet received will be ACKed, but its contents + will be dropped in the bit-bucket. + + One low-performance option is delay for a short period of time after a + TCP/IP packet is received to see if another comes right behind it. Then + the packet data from both can be combined. This option only makes since + if performance is not an issue and you need to handle short bursts of + small, back-to-back packets. The delay is in units of deciseconds. config NET_TCPBACKLOG bool "TCP/IP backlog support" @@ -192,8 +239,12 @@ config NET_STATISTICS config NET_RECEIVE_WINDOW int "Receive window size" + default 562 ---help--- - The size of the advertised receiver's window + The size of the advertised receiver's window. Should be set low + (i.e., to the size of the NET_BUFSIZE) if the application is slow + to process incoming data, or high (32768 bytes) if the application + processes data quickly. config NET_ARPTAB_SIZE int "ARP table size" @@ -214,11 +265,6 @@ config NET_MULTICAST ---help--- Outgoing multi-cast address support -config NET_FWCACHE_SIZE - int "FW cache size" - ---help--- - Number of packets to remember when looking for duplicates - config NET_SLIP bool "SLIP support" default n diff --git a/nuttx/net/listen.c b/nuttx/net/listen.c index bddb0ab080..5e3c62f692 100644 --- a/nuttx/net/listen.c +++ b/nuttx/net/listen.c @@ -2,7 +2,7 @@ * net/listen.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/net_arptimer.c b/nuttx/net/net_arptimer.c index 89db9f6562..2c5d33c914 100644 --- a/nuttx/net/net_arptimer.c +++ b/nuttx/net/net_arptimer.c @@ -2,7 +2,7 @@ * net/net_arptimer.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/net_checksd.c b/nuttx/net/net_checksd.c index 3da3cea62f..0a6975cad4 100644 --- a/nuttx/net/net_checksd.c +++ b/nuttx/net/net_checksd.c @@ -2,7 +2,7 @@ * net/net_checksd.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/net_dsec2timeval.c b/nuttx/net/net_dsec2timeval.c index c9d3aeb66f..0f570cb394 100644 --- a/nuttx/net/net_dsec2timeval.c +++ b/nuttx/net/net_dsec2timeval.c @@ -2,7 +2,7 @@ * net/net_dsec2timeval.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/net_dup.c b/nuttx/net/net_dup.c index 8465b7ce44..3004595445 100644 --- a/nuttx/net/net_dup.c +++ b/nuttx/net/net_dup.c @@ -2,7 +2,7 @@ * net/net_dup.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/net_dup2.c b/nuttx/net/net_dup2.c index b27bb69675..3403a70c31 100644 --- a/nuttx/net/net_dup2.c +++ b/nuttx/net/net_dup2.c @@ -2,7 +2,7 @@ * net/net_dup2.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/net_timeval2dsec.c b/nuttx/net/net_timeval2dsec.c index 4ca5ecb5f1..e0b25db981 100644 --- a/nuttx/net/net_timeval2dsec.c +++ b/nuttx/net/net_timeval2dsec.c @@ -2,7 +2,7 @@ * net/net_timeval2dsec.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/netdev_count.c b/nuttx/net/netdev_count.c index 17f0894da6..8db1191a29 100644 --- a/nuttx/net/netdev_count.c +++ b/nuttx/net/netdev_count.c @@ -2,7 +2,7 @@ * net/netdev_count.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/netdev_findbyaddr.c b/nuttx/net/netdev_findbyaddr.c index 50a246f67e..e8083e4d0c 100644 --- a/nuttx/net/netdev_findbyaddr.c +++ b/nuttx/net/netdev_findbyaddr.c @@ -2,7 +2,7 @@ * net/netdev_findbyaddr.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/netdev_findbyname.c b/nuttx/net/netdev_findbyname.c index a6ddf0452d..9f6f895aca 100644 --- a/nuttx/net/netdev_findbyname.c +++ b/nuttx/net/netdev_findbyname.c @@ -2,7 +2,7 @@ * net/netdev_findbyname.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/netdev_unregister.c b/nuttx/net/netdev_unregister.c index e1aec0e4d8..39927340a7 100644 --- a/nuttx/net/netdev_unregister.c +++ b/nuttx/net/netdev_unregister.c @@ -2,7 +2,7 @@ * net/netdev_unregister.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c index 741cd4c727..6bfbd31ad3 100644 --- a/nuttx/net/recvfrom.c +++ b/nuttx/net/recvfrom.c @@ -59,8 +59,6 @@ * Definitions ****************************************************************************/ -#define TCP_TIMEO 10 /* Deciseconds after data received before recv() returns */ - #define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) #define TCPBUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) @@ -354,31 +352,39 @@ static int recvfrom_timeout(struct recvfrom_s *pstate) FAR struct socket *psock = 0; socktimeo_t timeo = 0; - /* If this is a TCP socket that has already received some data, - * than we will always use a short timeout. + /* Check for a timeout configured via setsockopts(SO_RCVTIMEO). If none... + * we well let the read hang forever (except for the special case below). */ - if (pstate->rf_recvlen > 0) - { - /* Use the short timeout */ + /* Get the socket reference from the private data */ - timeo = TCP_TIMEO; + psock = pstate->rf_sock; + if (psock) + { + /* Recover the timeout value (zero if no timeout) */ + + timeo = psock->s_rcvtimeo; } - /* No.. check for a timeout configured via setsockopts(SO_RCVTIMEO). - * If none... we well let the read hang forever. + /* Use a fixed, configurable delay under the following circumstances: + * + * 1) This delay function has been enabled with CONFIG_NET_TCP_RECVDELAY > 0 + * 2) Some data has already been received from the socket. Since this can + * only be true for a TCP/IP socket, this logic applies only to TCP/IP + * sockets. And either + * 3) There is no configured receive timeout, or + * 4) The configured receive timeout is greater than than the delay */ - else +#if CONFIG_NET_TCP_RECVDELAY > 0 + if ((timeo == 0 || timeo > CONFIG_NET_TCP_RECVDELAY) && + pstate->rf_recvlen > 0) { - /* Get the socket reference from the private data */ + /* Use the configured timeout */ - psock = pstate->rf_sock; - if (psock) - { - timeo = psock->s_rcvtimeo; - } + timeo = CONFIG_NET_TCP_RECVDELAY; } +#endif /* Is there an effective timeout? */ @@ -389,7 +395,7 @@ static int recvfrom_timeout(struct recvfrom_s *pstate) return net_timeo(pstate->rf_starttime, timeo); } - /* No timeout */ + /* No timeout -- hang forever waiting for data. */ return FALSE; } @@ -489,9 +495,28 @@ static uint16_t recvfrom_tcpinterrupt(struct uip_driver_s *dev, void *conn, flags = (flags & ~UIP_NEWDATA) | UIP_SNDACK; - /* If the user buffer has been filled, then we are finished. */ + /* Check for transfer complete. We will consider the transfer + * complete in own of two different ways, depending on the setting + * of CONFIG_NET_TCP_RECVDELAY. + * + * 1) If CONFIG_NET_TCP_RECVDELAY == 0 then we will consider the + * TCP/IP transfer complete as soon as any data has been received. + * This is safe because if any additional data is received, it + * will be retained inthe TCP/IP read-ahead buffer until the + * next receive is performed. + * 2) CONFIG_NET_TCP_RECVDELAY > 0 may be set to wait a little + * bit to determine if more data will be received. You might + * do this if read-ahead buffereing is disabled and we want to + * minimize the loss of back-to-back packets. In this case, + * the transfer is complete when either a) the entire user buffer + * is full or 2) when the receive timeout occurs (below). + */ +#if CONFIG_NET_TCP_RECVDELAY > 0 if (pstate->rf_buflen == 0) +#else + if (pstate->rf_recvlen > 0) +#endif { nllvdbg("TCP resume\n"); @@ -571,9 +596,14 @@ static uint16_t recvfrom_tcpinterrupt(struct uip_driver_s *dev, void *conn, pstate->rf_cb->priv = NULL; pstate->rf_cb->event = NULL; - /* Report an error only if no data has been received */ + /* Report an error only if no data has been received. (If + * CONFIG_NET_TCP_RECVDELAY then rf_recvlen should always be + * zero). + */ +#if CONFIG_NET_TCP_RECVDELAY > 0 if (pstate->rf_recvlen == 0) +#endif { /* Report the timeout error */ @@ -812,7 +842,7 @@ static ssize_t recvfrom_result(int result, struct recvfrom_s *pstate) if (pstate->rf_result < 0) { - /* This might return EGAIN on a timeout or ENOTCONN on loss of + /* This might return EAGAIN on a timeout or ENOTCONN on loss of * connection (TCP only) */ @@ -1031,7 +1061,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, if (_SS_ISNONBLOCK(psock->s_flags)) { /* Return the number of bytes read from the read-ahead buffer if - * something was received (already in 'ret'); EGAIN if not. + * something was received (already in 'ret'); EAGAIN if not. */ if (ret <= 0) @@ -1049,7 +1079,26 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, else #endif + + /* We get here when we we decide that we need to setup the wait for incoming + * TCP/IP data. Just a few more conditions to check: + * + * 1) Make sure thet there is buffer space to receive additional data + * (state.rf_buflen > 0). This could be zero, for example, if read-ahead + * buffering was enabled and we filled the user buffer with data from + * the read-ahead buffers. Aand + * 2) if read-ahead buffering is enabled (CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0) + * and delay logic is disabled (CONFIG_NET_TCP_RECVDELAY == 0), then we + * not want to wait if we already obtained some data from the read-ahead + * buffer. In that case, return now with what we have (don't want for more + * because there may be no timeout). + */ + +#if CONFIG_NET_TCP_RECVDELAY == 0 && CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 + if (state.rf_recvlen == 0 && state.rf_buflen > 0) +#else if (state.rf_buflen > 0) +#endif { struct uip_conn *conn = (struct uip_conn *)psock->s_conn; diff --git a/nuttx/net/send.c b/nuttx/net/send.c index 950b3fc0bc..8a5154191e 100644 --- a/nuttx/net/send.c +++ b/nuttx/net/send.c @@ -268,7 +268,7 @@ static uint16_t send_interrupt(struct uip_driver_s *dev, void *pvconn, * then the send won't actually make it out... it will be replaced with * an ARP request. * - * NOTE 1: This could an expensive check if there are a lot of entries + * NOTE 1: This could be an expensive check if there are a lot of entries * in the ARP table. Hence, we only check on the first packet -- when * snd_sent is zero. * diff --git a/nuttx/net/uip/Make.defs b/nuttx/net/uip/Make.defs index 8bd8d18396..c5d915e614 100644 --- a/nuttx/net/uip/Make.defs +++ b/nuttx/net/uip/Make.defs @@ -2,7 +2,7 @@ # Make.defs # # Copyright (C) 2007, 2009-20010 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_arptab.c b/nuttx/net/uip/uip_arptab.c index 1a29f25df4..3dff970702 100644 --- a/nuttx/net/uip/uip_arptab.c +++ b/nuttx/net/uip/uip_arptab.c @@ -3,7 +3,7 @@ * Implementation of the ARP Address Resolution Protocol. * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Based originally on uIP which also has a BSD style license: * diff --git a/nuttx/net/uip/uip_callback.c b/nuttx/net/uip/uip_callback.c index 730aa7758c..0c8c3aaa01 100644 --- a/nuttx/net/uip/uip_callback.c +++ b/nuttx/net/uip/uip_callback.c @@ -2,7 +2,7 @@ * net/uip/uip_callback.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_icmppoll.c b/nuttx/net/uip/uip_icmppoll.c index ca1d684c01..bcf7fe94b3 100644 --- a/nuttx/net/uip/uip_icmppoll.c +++ b/nuttx/net/uip/uip_icmppoll.c @@ -2,7 +2,7 @@ * net/uip/uip_icmppoll.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_igmpgroup.c b/nuttx/net/uip/uip_igmpgroup.c old mode 100755 new mode 100644 index 220de047e5..b92db5476c --- a/nuttx/net/uip/uip_igmpgroup.c +++ b/nuttx/net/uip/uip_igmpgroup.c @@ -3,7 +3,7 @@ * IGMP group data structure management logic * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmpinit.c b/nuttx/net/uip/uip_igmpinit.c old mode 100755 new mode 100644 index 7954e7b3e8..740ddf44b5 --- a/nuttx/net/uip/uip_igmpinit.c +++ b/nuttx/net/uip/uip_igmpinit.c @@ -3,7 +3,7 @@ * IGMP initialization logic * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmpinput.c b/nuttx/net/uip/uip_igmpinput.c old mode 100755 new mode 100644 index 5b4fbefa42..40c1cf3ba2 --- a/nuttx/net/uip/uip_igmpinput.c +++ b/nuttx/net/uip/uip_igmpinput.c @@ -2,7 +2,7 @@ * net/uip/uip_igminput.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmpjoin.c b/nuttx/net/uip/uip_igmpjoin.c old mode 100755 new mode 100644 index eb6e888379..c02b0bb8f4 --- a/nuttx/net/uip/uip_igmpjoin.c +++ b/nuttx/net/uip/uip_igmpjoin.c @@ -2,7 +2,7 @@ * net/uip/uip_igmpjoin.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmpleave.c b/nuttx/net/uip/uip_igmpleave.c old mode 100755 new mode 100644 index 7e2a31a196..4e08df5767 --- a/nuttx/net/uip/uip_igmpleave.c +++ b/nuttx/net/uip/uip_igmpleave.c @@ -2,7 +2,7 @@ * net/uip/uip_igmpleave.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmpmsg.c b/nuttx/net/uip/uip_igmpmsg.c old mode 100755 new mode 100644 index 9ea3daa4eb..5209eaf7aa --- a/nuttx/net/uip/uip_igmpmsg.c +++ b/nuttx/net/uip/uip_igmpmsg.c @@ -2,7 +2,7 @@ * net/uip/uip_igmpmgs.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmppoll.c b/nuttx/net/uip/uip_igmppoll.c old mode 100755 new mode 100644 index cec2a5e1b7..e86eb687be --- a/nuttx/net/uip/uip_igmppoll.c +++ b/nuttx/net/uip/uip_igmppoll.c @@ -2,7 +2,7 @@ * net/uip/uip_igmppoll.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_igmpsend.c b/nuttx/net/uip/uip_igmpsend.c old mode 100755 new mode 100644 index 21fc2beb03..f22282b62a --- a/nuttx/net/uip/uip_igmpsend.c +++ b/nuttx/net/uip/uip_igmpsend.c @@ -2,7 +2,7 @@ * net/uip/uip_igmpsend.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_igmptimer.c b/nuttx/net/uip/uip_igmptimer.c old mode 100755 new mode 100644 index 27e2f9ff05..4655f3a2f3 --- a/nuttx/net/uip/uip_igmptimer.c +++ b/nuttx/net/uip/uip_igmptimer.c @@ -2,7 +2,7 @@ * net/uip/uip_igmptimer.c * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_initialize.c b/nuttx/net/uip/uip_initialize.c index 8839836c44..e737d646ed 100644 --- a/nuttx/net/uip/uip_initialize.c +++ b/nuttx/net/uip/uip_initialize.c @@ -2,7 +2,7 @@ * net/uip/uip_initialize.c * * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/net/uip/uip_listen.c b/nuttx/net/uip/uip_listen.c index 5f867fef2d..420fbb0706 100644 --- a/nuttx/net/uip/uip_listen.c +++ b/nuttx/net/uip/uip_listen.c @@ -2,7 +2,7 @@ * net/uip/uip_listen.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * A direct leverage of logic from uIP which also has b BSD style license * diff --git a/nuttx/net/uip/uip_lock.c b/nuttx/net/uip/uip_lock.c index 0e770cef79..5abcda2698 100644 --- a/nuttx/net/uip/uip_lock.c +++ b/nuttx/net/uip/uip_lock.c @@ -39,6 +39,7 @@ #include +#include #include #include #include diff --git a/nuttx/net/uip/uip_mcastmac.c b/nuttx/net/uip/uip_mcastmac.c old mode 100755 new mode 100644 index 7795becab5..9bd1461987 --- a/nuttx/net/uip/uip_mcastmac.c +++ b/nuttx/net/uip/uip_mcastmac.c @@ -2,7 +2,7 @@ * net/uip/uip_mcastmac.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * The NuttX implementation of IGMP was inspired by the IGMP add-on for the * lwIP TCP/IP stack by Steve Reynolds: diff --git a/nuttx/net/uip/uip_neighbor.h b/nuttx/net/uip/uip_neighbor.h index eac08f9382..b55835b74e 100644 --- a/nuttx/net/uip/uip_neighbor.h +++ b/nuttx/net/uip/uip_neighbor.h @@ -3,7 +3,7 @@ * to be used by future ARP code. * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * A direct leverage of logic from uIP which also has b BSD style license * diff --git a/nuttx/net/uip/uip_send.c b/nuttx/net/uip/uip_send.c index fd0f4f7da2..b26c799a04 100644 --- a/nuttx/net/uip/uip_send.c +++ b/nuttx/net/uip/uip_send.c @@ -2,7 +2,7 @@ * net/uip/uip_send.c * * Copyright (C) 2007i, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Based in part on uIP which also has a BSD stylie license: * diff --git a/nuttx/net/uip/uip_setipid.c b/nuttx/net/uip/uip_setipid.c index f9d13cc9d7..12a94860b8 100644 --- a/nuttx/net/uip/uip_setipid.c +++ b/nuttx/net/uip/uip_setipid.c @@ -2,7 +2,7 @@ * net/uip/uip_setipid.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/net/uip/uip_tcpappsend.c b/nuttx/net/uip/uip_tcpappsend.c index d8a1875034..dfddbcff9b 100644 --- a/nuttx/net/uip/uip_tcpappsend.c +++ b/nuttx/net/uip/uip_tcpappsend.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpappsend.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/net/uip/uip_tcpcallback.c b/nuttx/net/uip/uip_tcpcallback.c index 9ce8eb132a..8ac1351f70 100644 --- a/nuttx/net/uip/uip_tcpcallback.c +++ b/nuttx/net/uip/uip_tcpcallback.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpcallback.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_tcpconn.c b/nuttx/net/uip/uip_tcpconn.c index c2b64ad898..31e020f631 100644 --- a/nuttx/net/uip/uip_tcpconn.c +++ b/nuttx/net/uip/uip_tcpconn.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpconn.c * * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Large parts of this file were leveraged from uIP logic: * diff --git a/nuttx/net/uip/uip_tcppoll.c b/nuttx/net/uip/uip_tcppoll.c index 29cb6d4b43..ddc8ab029b 100644 --- a/nuttx/net/uip/uip_tcppoll.c +++ b/nuttx/net/uip/uip_tcppoll.c @@ -3,7 +3,7 @@ * Poll for the availability of TCP TX data * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/net/uip/uip_tcpreadahead.c b/nuttx/net/uip/uip_tcpreadahead.c index 21ed58b99c..a304925a87 100644 --- a/nuttx/net/uip/uip_tcpreadahead.c +++ b/nuttx/net/uip/uip_tcpreadahead.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpreadahead.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_tcpseqno.c b/nuttx/net/uip/uip_tcpseqno.c old mode 100755 new mode 100644 index eab3a054a6..2eca06e85b --- a/nuttx/net/uip/uip_tcpseqno.c +++ b/nuttx/net/uip/uip_tcpseqno.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpseqno.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Large parts of this file were leveraged from uIP logic: * diff --git a/nuttx/net/uip/uip_tcptimer.c b/nuttx/net/uip/uip_tcptimer.c index c95376ab0c..a0772136e8 100644 --- a/nuttx/net/uip/uip_tcptimer.c +++ b/nuttx/net/uip/uip_tcptimer.c @@ -3,7 +3,7 @@ * Poll for the availability of TCP TX data * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/net/uip/uip_udpcallback.c b/nuttx/net/uip/uip_udpcallback.c index f00c5e0f81..ef4b36e495 100644 --- a/nuttx/net/uip/uip_udpcallback.c +++ b/nuttx/net/uip/uip_udpcallback.c @@ -2,7 +2,7 @@ * net/uip/uip_udpcallback.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/uip/uip_udpinput.c b/nuttx/net/uip/uip_udpinput.c index 456c34799b..fa7bf8c41c 100644 --- a/nuttx/net/uip/uip_udpinput.c +++ b/nuttx/net/uip/uip_udpinput.c @@ -3,7 +3,7 @@ * Handling incoming UDP input * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/net/uip/uip_udppoll.c b/nuttx/net/uip/uip_udppoll.c index 984566ed46..05c2508bca 100644 --- a/nuttx/net/uip/uip_udppoll.c +++ b/nuttx/net/uip/uip_udppoll.c @@ -3,7 +3,7 @@ * Poll for the availability of UDP TX data * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/net/uip/uip_udpsend.c b/nuttx/net/uip/uip_udpsend.c index 1dc33bbd18..9ba8ec8f56 100644 --- a/nuttx/net/uip/uip_udpsend.c +++ b/nuttx/net/uip/uip_udpsend.c @@ -2,7 +2,7 @@ * net/uip/uip_udpsend.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Adapted for NuttX from logic in uIP which also has a BSD-like license: * diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index f822736387..4f7149595e 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -166,6 +166,39 @@ config SIG_SIGWORK The signal number that will be used to wake-up the worker thread. Default: 4 +config SCHED_LPWORK + bool "Enable a lower priority worker thread" + default n + depends on SCHED_WORKQUEUE + ---help--- + If SCHED_WORKQUEUE is defined, then a single work queue is created by + default. If SCHED_LPWORK is also defined then an additional, lower- + priority work queue will also be created. This lower priority work + queue is better suited for more extended processing (such as file system + clean-up operations) + +config SCHED_LPWORKPRIORITY + int "Lower priority worker thread priority" + default 50 + depends on SCHED_LPWORK + ---help--- + The execution priority of the lopwer priority worker thread. Default: 192 + +config SCHED_LPWORKPERIOD + int "Lower priority worker thread period" + default 50000 + depends on SCHED_LPWORK + ---help--- + How often the lower priority worker thread checks for work in units + of microseconds. Default: 50*1000 (50 MS). + +config SCHED_LPWORKSTACKSIZE + int "Lower priority worker thread stack size" + default 2048 + depends on SCHED_LPWORK + ---help--- + The stack size allocated for the lower priority worker thread. Default: 2K. + config SCHED_WAITPID bool "Enable waitpid() API" default n @@ -202,9 +235,17 @@ config SCHED_ONEXIT_MAX is supported. That number can be increased by defined this setting to the number that you require. +config USER_ENTRYPOINT + string "Application entry point" + default "user_start" + ---help--- + The name of the entry point for user applications. For the example + applications this is of the form 'app_main' where 'app' is the application + name. If not defined, USER_ENTRYPOINT defaults to "user_start." + config DISABLE_OS_API bool "Disable NuttX interfaces" - default n + default y ---help--- The following can be used to disable categories of APIs supported by the OS. If the compiler supports @@ -340,20 +381,6 @@ config PREALLOC_TIMERS comment "Stack and heap information" -config BOOT_RUNFROMFLASH - bool "boot run from flash" - default n - ---help--- - Some configurations support XIP operation from FLASH but must copy - initialized .data sections to RAM - -config BOOT_COPYTORAM - bool "boot copy to ram" - default n - ---help--- - Some configurations boot in FLASH - but copy themselves entirely into RAM for better performance. - config CUSTOM_STACK bool "Enable custom stack" default n @@ -362,11 +389,6 @@ config CUSTOM_STACK nuttx model. This is necessary for certain architectures that have have hardware stacks (such as the 8051 family). -config STACK_POINTER - hex "The initial stack pointer" - ---help--- - The initial stack pointer (arm7tdmi only). - config IDLETHREAD_STACKSIZE int "Idle thread stack size" default 1024 diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index dfdc6f68b6..1e0a55aeaf 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -141,7 +141,7 @@ TIMER_SRCS = timer_initialize.c timer_create.c timer_delete.c timer_getoverrun.c endif ifeq ($(CONFIG_SCHED_WORKQUEUE),y) -WORK_SRCS = work_thread.c work_queue.c work_cancel.c +WORK_SRCS = work_thread.c work_queue.c work_cancel.c work_signal.c endif ifeq ($(CONFIG_PAGING),y) diff --git a/nuttx/sched/os_bringup.c b/nuttx/sched/os_bringup.c index 646f491583..ec61528914 100644 --- a/nuttx/sched/os_bringup.c +++ b/nuttx/sched/os_bringup.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/os_bringup.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * With extensions by: @@ -47,6 +47,7 @@ #include #include +#include #include "os_internal.h" #ifdef CONFIG_PAGING @@ -71,12 +72,6 @@ * then the default entry point is user_start. */ -#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_USER_ENTRYPOINT) -# define USER_ENTRYPOINT (main_t)CONFIG_USER_ENTRYPOINT -#else -# define USER_ENTRYPOINT user_start -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -155,10 +150,23 @@ int os_bringup(void) #ifdef CONFIG_SCHED_WORKQUEUE svdbg("Starting worker thread\n"); - g_worker = KERNEL_THREAD("work", CONFIG_SCHED_WORKPRIORITY, - CONFIG_SCHED_WORKSTACKSIZE, - (main_t)work_thread, (const char **)NULL); - ASSERT(g_worker != ERROR); + g_work[HPWORK].pid = KERNEL_THREAD("work0", CONFIG_SCHED_WORKPRIORITY, + CONFIG_SCHED_WORKSTACKSIZE, + (main_t)work_hpthread, (const char **)NULL); + ASSERT(g_work[HPWORK].pid != ERROR); + + /* Start a lower priority worker thread for other, non-critical continuation + * tasks + */ + +#ifdef CONFIG_SCHED_LPWORK + svdbg("Starting worker thread\n"); + + g_work[LPWORK].pid = KERNEL_THREAD("work1", CONFIG_SCHED_LPWORKPRIORITY, + CONFIG_SCHED_LPWORKSTACKSIZE, + (main_t)work_lpthread, (const char **)NULL); + ASSERT(g_work[LPWORK].pid != ERROR); +#endif #endif /* Once the operating system has been initialized, the system must be @@ -175,11 +183,11 @@ int os_bringup(void) init_taskid = exec_namedapp(CONFIG_BUILTIN_APP_START, argv); #else - /* Start the default application at USER_ENTRYPOINT() */ + /* Start the default application at CONFIG_USER_ENTRYPOINT() */ init_taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, - (main_t)USER_ENTRYPOINT, (const char **)NULL); + (main_t)CONFIG_USER_ENTRYPOINT, (const char **)NULL); #endif ASSERT(init_taskid != ERROR); return OK; diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index 6cd508b8ca..c0b16236dd 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -289,6 +289,18 @@ void os_start(void) g_idletcb.flags = TCB_FLAG_TTYPE_KERNEL; up_initial_state(&g_idletcb); + /* Initialize the semaphore facility(if in link). This has to be done + * very early because many subsystems depend upon fully functional + * semaphores. + */ + +#ifdef CONFIG_HAVE_WEAKFUNCTIONS + if (sem_initialize != NULL) +#endif + { + sem_initialize(); + } + /* Initialize the memory manager */ #ifndef CONFIG_HEAP_BASE @@ -351,15 +363,6 @@ void os_start(void) } #endif - /* Initialize the semaphore facility. (if in link) */ - -#ifdef CONFIG_HAVE_WEAKFUNCTIONS - if (sem_initialize != NULL) -#endif - { - sem_initialize(); - } - /* Initialize the named message queue facility (if in link) */ #ifndef CONFIG_DISABLE_MQUEUE diff --git a/nuttx/sched/prctl.c b/nuttx/sched/prctl.c index b340d0ec88..d71a0e1746 100644 --- a/nuttx/sched/prctl.c +++ b/nuttx/sched/prctl.c @@ -91,7 +91,7 @@ int prctl(int option, ...) { /* Get the prctl arguments */ - char *name = va_arg(ap, char *); + FAR char *name = va_arg(ap, FAR char *); int pid = va_arg(ap, int); FAR _TCB *tcb; diff --git a/nuttx/sched/sched_free.c b/nuttx/sched/sched_free.c index 4df77b109a..e5e0bdacf0 100644 --- a/nuttx/sched/sched_free.c +++ b/nuttx/sched/sched_free.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/sched_free.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -99,7 +99,7 @@ void sched_free(FAR void *address) /* Signal the worker thread that is has some clean up to do */ #ifdef CONFIG_SCHED_WORKQUEUE - work_signal(); + work_signal(LPWORK); #endif irqrestore(saved_state); } diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c index 7f754e1514..fe0b14143d 100644 --- a/nuttx/sched/sched_setuptaskfiles.c +++ b/nuttx/sched/sched_setuptaskfiles.c @@ -148,8 +148,8 @@ static inline void sched_dupsockets(FAR _TCB *tcb) /* The parent task is the one at the head of the ready-to-run list */ FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - FAR struct sockets *parent; - FAR struct sockets *child; + FAR struct socket *parent; + FAR struct socket *child; int i; /* Duplicate the socket descriptors of all sockets opened by the parent diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index e8e2f61a23..692ef64102 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -178,7 +178,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { - _TCB *tcb = sched_gettcb(pid); + _TCB *tcb; bool mystat; int err; int ret; @@ -186,6 +186,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Disable pre-emption so that nothing changes in the following tests */ sched_lock(); + tcb = sched_gettcb(pid); if (!tcb) { err = ECHILD; diff --git a/nuttx/sched/sem_holder.c b/nuttx/sched/sem_holder.c index 6003c563dc..1bae37746f 100644 --- a/nuttx/sched/sem_holder.c +++ b/nuttx/sched/sem_holder.c @@ -99,32 +99,31 @@ static inline FAR struct semholder_s *sem_allocholder(sem_t *sem) * used to implement mutexes. */ - if (!sem->hlist.holder) +#if CONFIG_SEM_PREALLOCHOLDERS > 0 + pholder = g_freeholders; + if (pholder) { - pholder = &sem->hlist; + /* Remove the holder from the free list an put it into the semaphore's holder list */ + + g_freeholders = pholder->flink; + pholder->flink = sem->hhead; + sem->hhead = pholder; + + /* Make sure the initial count is zero */ + pholder->counts = 0; } +#else + if (!sem->holder.htcb) + { + pholder = &sem->holder; + pholder->counts = 0; + } +#endif else { -#if CONFIG_SEM_PREALLOCHOLDERS > 0 - pholder = g_freeholders; - if (pholder) - { - /* Remove the holder from the free list an put it into the semaphore's holder list */ - - g_freeholders = pholder->flink; - pholder->flink = sem->hlist.flink; - sem->hlist.flink = pholder; - - /* Make sure the initial count is zero */ - - pholder->counts = 0; - } - else -#else - pholder = NULL; -#endif sdbg("Insufficient pre-allocated holders\n"); + pholder = NULL; } return pholder; @@ -140,12 +139,13 @@ static FAR struct semholder_s *sem_findholder(sem_t *sem, FAR _TCB *htcb) /* Try to find the holder in the list of holders associated with this semaphore */ - pholder = &sem->hlist; #if CONFIG_SEM_PREALLOCHOLDERS > 0 - for (; pholder; pholder = pholder->flink) + for (pholder = sem->hhead; pholder; pholder = pholder->flink) +#else + pholder = &sem->holder; #endif { - if (pholder->holder == htcb) + if (pholder->htcb == htcb) { /* Got it! */ @@ -186,31 +186,33 @@ static inline void sem_freeholder(sem_t *sem, FAR struct semholder_s *pholder) /* Release the holder and counts */ - pholder->holder = 0; + pholder->htcb = NULL; pholder->counts = 0; #if CONFIG_SEM_PREALLOCHOLDERS > 0 - /* If this is the holder inside the semaphore, then do nothing more */ + /* Search the list for the matching holder */ - if (pholder != &sem->hlist) + for (prev = NULL, curr = sem->hhead; + curr && curr != pholder; + prev = curr, curr = curr->flink); + + if (curr) { - /* Otherwise, search the list for the matching holder */ + /* Remove the holder from the list */ - for (prev = &sem->hlist, curr = sem->hlist.flink; - curr && curr != pholder; - prev = curr, curr = curr->flink); - - if (curr) + if (prev) { - /* Remove the holder from the list */ - prev->flink = pholder->flink; - - /* And put it in the free list */ - - pholder->flink = g_freeholders; - g_freeholders = pholder; } + else + { + sem->hhead = pholder->flink; + } + + /* And put it in the free list */ + + pholder->flink = g_freeholders; + g_freeholders = pholder; } #endif } @@ -221,14 +223,16 @@ static inline void sem_freeholder(sem_t *sem, FAR struct semholder_s *pholder) static int sem_foreachholder(FAR sem_t *sem, holderhandler_t handler, FAR void *arg) { - FAR struct semholder_s *pholder = &sem->hlist; + FAR struct semholder_s *pholder; #if CONFIG_SEM_PREALLOCHOLDERS > 0 FAR struct semholder_s *next; #endif int ret = 0; #if CONFIG_SEM_PREALLOCHOLDERS > 0 - for (; pholder && ret == 0; pholder = next) + for (pholder = sem->hhead; pholder && ret == 0; pholder = next) +#else + pholder = &sem->holder; #endif { #if CONFIG_SEM_PREALLOCHOLDERS > 0 @@ -238,7 +242,7 @@ static int sem_foreachholder(FAR sem_t *sem, holderhandler_t handler, FAR void * #endif /* The initial "built-in" container may hold a NULL holder */ - if (pholder->holder) + if (pholder->htcb) { /* Call the handler */ @@ -268,13 +272,13 @@ static int sem_recoverholders(FAR struct semholder_s *pholder, FAR sem_t *sem, F static int sem_boostholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR _TCB *htcb = (FAR _TCB *)pholder->holder; + FAR _TCB *htcb = (FAR _TCB *)pholder->htcb; FAR _TCB *rtcb = (FAR _TCB*)arg; - /* Make sure that the thread is still active. If it exited without releasing - * its counts, then that would be a bad thing. But we can take no real - * action because we don't know know that the program is doing. Perhaps its - * plan is to kill a thread, then destroy the semaphore. + /* Make sure that the holder thread is still active. If it exited without + * releasing its counts, then that would be a bad thing. But we can take no + * real action because we don't know know that the program is doing. Perhaps + * its plan is to kill a thread, then destroy the semaphore. */ if (!sched_verifytcb(htcb)) @@ -299,15 +303,16 @@ static int sem_boostholderprio(FAR struct semholder_s *pholder, if (rtcb->sched_priority > htcb->sched_priority) { - /* If the current priority has already been boosted, then add the - * boost priority to the list of restoration priorities. When the - * higher priority thread gets its count, then we need to revert - * to this saved priority, not to the base priority. + /* If the current priority of holder thread has already been + * boosted, then add the boost priority to the list of restoration + * priorities. When the higher priority waiter thread gets its + * count, then we need to revert the holder thread to this saved + * priority (not to its base priority). */ if (htcb->sched_priority > htcb->base_priority) { - /* Save the current, boosted priority */ + /* Save the current, boosted priority of the holder thread. */ if (htcb->npend_reprio < CONFIG_SEM_NNESTPRIO) { @@ -320,10 +325,10 @@ static int sem_boostholderprio(FAR struct semholder_s *pholder, } } - /* Raise the priority of the holder of the semaphore. This - * cannot cause a context switch because we have preemption - * disabled. The task will be marked "pending" and the switch - * will occur during up_block_task() processing. + /* Raise the priority of the thread holding of the semaphore. + * This cannot cause a context switch because we have preemption + * disabled. The holder thread may be marked "pending" and the + * switch may occur during up_block_task() processing. */ (void)sched_setpriority(htcb, rtcb->sched_priority); @@ -371,7 +376,7 @@ static int sem_boostholderprio(FAR struct semholder_s *pholder, static int sem_verifyholder(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { #if 0 // Need to revisit this, but these assumptions seem to be untrue -- OR there is a bug??? - FAR _TCB *htcb = (FAR _TCB *)pholder->holder; + FAR _TCB *htcb = (FAR _TCB *)pholder->htcb; /* Called after a semaphore has been released (incremented), the semaphore * could is non-negative, and there is no thread waiting for the count. @@ -396,9 +401,9 @@ static int sem_dumpholder(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR v { #if CONFIG_SEM_PREALLOCHOLDERS > 0 dbg(" %08x: %08x %08x %04x\n", - pholder, pholder->flink, pholder->holder, pholder->counts); + pholder, pholder->flink, pholder->htcb, pholder->counts); #else - dbg(" %08x: %08x %04x\n", pholder, pholder->holder, pholder->counts); + dbg(" %08x: %08x %04x\n", pholder, pholder->htcb, pholder->counts); #endif return 0; } @@ -410,7 +415,7 @@ static int sem_dumpholder(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR v static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { - FAR _TCB *htcb = (FAR _TCB *)pholder->holder; + FAR _TCB *htcb = (FAR _TCB *)pholder->htcb; #if CONFIG_SEM_NNESTPRIO > 0 FAR _TCB *stcb = (FAR _TCB *)arg; int rpriority; @@ -418,10 +423,10 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem int j; #endif - /* Make sure that the thread is still active. If it exited without releasing - * its counts, then that would be a bad thing. But we can take no real - * action because we don't know know that the program is doing. Perhaps its - * plan is to kill a thread, then destroy the semaphore. + /* Make sure that the hdoler thread is still active. If it exited without + * releasing its counts, then that would be a bad thing. But we can take no + * real action because we don't know know that the program is doing. Perhaps + * its plan is to kill a thread, then destroy the semaphore. */ if (!sched_verifytcb(htcb)) @@ -430,8 +435,8 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem sem_freeholder(sem, pholder); } - /* Was the priority of this thread boosted? If so, then drop its priority - * back to the correct level. + /* Was the priority of the holder thread boosted? If so, then drop its + * priority back to the correct level. What is the correct level? */ else if (htcb->sched_priority != htcb->base_priority) @@ -441,23 +446,23 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem if (htcb->npend_reprio < 1) { - /* No... the thread has only been boosted once. Reset all priorities - * back to the base priority. + /* No... the holder thread has only been boosted once. Reset all + * priorities back to the base priority. */ - DEBUGASSERT(htcb->sched_priority == stcb->sched_priority && htcb->npend_reprio == 0); + //DEBUGASSERT(htcb->sched_priority == stcb->sched_priority && htcb->npend_reprio == 0); sched_reprioritize(htcb, htcb->base_priority); } - /* There are multiple pending priority levels. The thread's "boosted" + /* There are multiple pending priority levels. The holder thread's "boosted" * priority could greater than or equal to "stcb->sched_priority" (it could be - * greater if its priority we boosted becuase it also holds another semaphore. + * greater if its priority we boosted becuase it also holds another semaphore). */ else if (htcb->sched_priority <= stcb->sched_priority) { - /* The thread has been boosted to the same priority as the task - * that just received the count. We will simply reprioritized + /* The holder thread has been boosted to the same priority as the waiter + * thread that just received the count. We will simply reprioritize * to the next highest priority that we have in rpriority. */ @@ -488,9 +493,10 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem } else { - /* The thread has been boosted to a higher priority than the task. The - * pending priority should be in he list (unless it was lost because of - * of list overflow). + /* The holder thread has been boosted to a higher priority than the + * waiter task. The pending priority should be in the list (unless it + * was lost because of of list overflow or because the holder was + * reporioritize again unbeknownst to the priority inheritance logic). * * Search the list for the matching priority. */ @@ -510,6 +516,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem { htcb->pend_reprios[i] = htcb->pend_reprios[j]; } + htcb->npend_reprio = j; break; } @@ -517,7 +524,8 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem } #else /* There is no alternative restore priorities, drop the priority - * all the way back to the threads "base" priority. + * of the holder thread all the way back to the threads "base" + * priority. */ sched_reprioritize(htcb, htcb->base_priority); @@ -528,13 +536,18 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem } /**************************************************************************** - * Name: sem_restoreholderprioA & B + * Name: sem_restoreholderprioA + * + * Description: + * Reprioritize all holders except the currently executing task + * ****************************************************************************/ -static int sem_restoreholderprioA(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) +static int sem_restoreholderprioA(FAR struct semholder_s *pholder, + FAR sem_t *sem, FAR void *arg) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - if (pholder->holder != rtcb) + if (pholder->htcb != rtcb) { return sem_restoreholderprio(pholder, sem, arg); } @@ -542,10 +555,19 @@ static int sem_restoreholderprioA(FAR struct semholder_s *pholder, FAR sem_t *se return 0; } -static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) +/**************************************************************************** + * Name: sem_restoreholderprioB + * + * Description: + * Reprioritize only the currently executing task + * + ****************************************************************************/ + +static int sem_restoreholderprioB(FAR struct semholder_s *pholder, + FAR sem_t *sem, FAR void *arg) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - if (pholder->holder == rtcb) + if (pholder->htcb == rtcb) { (void)sem_restoreholderprio(pholder, sem, arg); return 1; @@ -554,6 +576,158 @@ static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *se return 0; } +/**************************************************************************** + * Name: sem_restorebaseprio_irq + * + * Description: + * This function is called after the an interrupt handler posts a count on + * the semaphore. It will check if we need to drop the priority of any + * threads holding a count on the semaphore. Their priority could have + * been boosted while they held the count. + * + * Parameters: + * stcb - The TCB of the task that was just started (if any). If the + * post action caused a count to be given to another thread, then stcb + * is the TCB that received the count. Note, just because stcb received + * the count, it does not mean that it it is higher priority than other + * threads. + * sem - A reference to the semaphore being posted. + * - If the semaphore count is <0 then there are still threads waiting + * for a count. stcb should be non-null and will be higher priority + * than all of the other threads still waiting. + * - If it is ==0 then stcb refers to the thread that got the last count; + * no other threads are waiting. + * - If it is >0 then there should be no threads waiting for counts and + * stcb should be null. + * + * Return Value: + * None + * + * Assumptions: + * The scheduler is locked. + * + ****************************************************************************/ + +static inline void sem_restorebaseprio_irq(FAR _TCB *stcb, FAR sem_t *sem) +{ + /* Perfom the following actions only if a new thread was given a count. + * The thread that received the count should be the highest priority + * of all threads waiting for a count from the semphore. So in that + * case, the priority of all holder threads should be dropped to the + * next highest pending priority. + */ + + if (stcb) + { + /* Drop the priority of all holder threads */ + + (void)sem_foreachholder(sem, sem_restoreholderprio, stcb); + } + + /* If there are no tasks waiting for available counts, then all holders + * should be at their base priority. + */ + +#ifdef CONFIG_DEBUG + else + { + (void)sem_foreachholder(sem, sem_verifyholder, NULL); + } +#endif +} + +/**************************************************************************** + * Name: sem_restorebaseprio_task + * + * Description: + * This function is called after the current running task releases a + * count on the semaphore. It will check if we need to drop the priority + * of any threads holding a count on the semaphore. Their priority could + * have been boosted while they held the count. + * + * Parameters: + * stcb - The TCB of the task that was just started (if any). If the + * post action caused a count to be given to another thread, then stcb + * is the TCB that received the count. Note, just because stcb received + * the count, it does not mean that it it is higher priority than other + * threads. + * sem - A reference to the semaphore being posted. + * - If the semaphore count is <0 then there are still threads waiting + * for a count. stcb should be non-null and will be higher priority + * than all of the other threads still waiting. + * - If it is ==0 then stcb refers to the thread that got the last count; + * no other threads are waiting. + * - If it is >0 then there should be no threads waiting for counts and + * stcb should be null. + * + * Return Value: + * None + * + * Assumptions: + * The scheduler is locked. + * + ****************************************************************************/ + +static inline void sem_restorebaseprio_task(FAR _TCB *stcb, FAR sem_t *sem) +{ + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + FAR struct semholder_s *pholder; + + /* Perfom the following actions only if a new thread was given a count. + * The thread that received the count should be the highest priority + * of all threads waiting for a count from the semphore. So in that + * case, the priority of all holder threads should be dropped to the + * next highest pending priority. + */ + + if (stcb) + { + /* The currently executed thread should be the lower priority + * thread that just posted the count and caused this action. + * However, we cannot drop the priority of the currently running + * thread -- becuase that will cause it to be suspended. + * + * So, do this in two passes. First, reprioritizing all holders + * except for the running thread. + */ + + (void)sem_foreachholder(sem, sem_restoreholderprioA, stcb); + + /* Now, find an reprioritize only the ready to run task */ + + (void)sem_foreachholder(sem, sem_restoreholderprioB, stcb); + } + + /* If there are no tasks waiting for available counts, then all holders + * should be at their base priority. + */ + +#ifdef CONFIG_DEBUG + else + { + (void)sem_foreachholder(sem, sem_verifyholder, NULL); + } +#endif + + /* In any case, the currently executing task should have an entry in the + * list. Its counts were previously decremented; if it now holds no + * counts, then we need to remove it from the list of holders. + */ + + pholder = sem_findholder(sem, rtcb); + if (pholder) + { + /* When no more counts are held, remove the holder from the list. The + * count was decremented in sem_releaseholder. + */ + + if (pholder->counts <= 0) + { + sem_freeholder(sem, pholder); + } + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -586,6 +760,7 @@ void sem_initholders(void) { g_holderalloc[i].flink = &g_holderalloc[i+1]; } + g_holderalloc[CONFIG_SEM_PREALLOCHOLDERS-1].flink = NULL; #endif } @@ -609,8 +784,8 @@ void sem_initholders(void) void sem_destroyholder(FAR sem_t *sem) { - /* It is an error is a semaphore is destroyed while there are any holders - * (except perhaps the thread releas the semaphore itself). Hmmm.. but + /* It is an error if a semaphore is destroyed while there are any holders + * (except perhaps the thread release the semaphore itself). Hmmm.. but * we actually have to assume that the caller knows what it is doing because * could have killed another thread that is the actual holder of the semaphore. * We cannot make any assumptions about the state of the semaphore or the @@ -621,18 +796,18 @@ void sem_destroyholder(FAR sem_t *sem) */ #if CONFIG_SEM_PREALLOCHOLDERS > 0 - if (sem->hlist.holder || sem->hlist.flink) + if (sem->hhead) { sdbg("Semaphore destroyed with holders\n"); (void)sem_foreachholder(sem, sem_recoverholders, NULL); } #else - if (sem->hlist.holder) + if (sem->holder.htcb) { sdbg("Semaphore destroyed with holder\n"); } - sem->hlist.holder = NULL; + sem->holder.htcb = NULL; #endif } @@ -664,7 +839,7 @@ void sem_addholder(FAR sem_t *sem) { /* Then set the holder and increment the number of counts held by this holder */ - pholder->holder = rtcb; + pholder->htcb = rtcb; pholder->counts++; } } @@ -737,9 +912,10 @@ void sem_releaseholder(FAR sem_t *sem) * * Description: * This function is called after the current running task releases a - * count on the semaphore. It will check if we need to drop the priority - * of any threads holding a count on the semaphore. Their priority could - * have been boosted while they held the count. + * count on the semaphore or an interrupt handler posts a new count. It + * will check if we need to drop the priority of any threads holding a + * count on the semaphore. Their priority could have been boosted while + * they held the count. * * Parameters: * stcb - The TCB of the task that was just started (if any). If the @@ -757,7 +933,7 @@ void sem_releaseholder(FAR sem_t *sem) * stcb should be null. * * Return Value: - * 0 (OK) or -1 (ERROR) if unsuccessful + * None * * Assumptions: * The scheduler is locked. @@ -766,61 +942,26 @@ void sem_releaseholder(FAR sem_t *sem) void sem_restorebaseprio(FAR _TCB *stcb, FAR sem_t *sem) { - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - FAR struct semholder_s *pholder; - /* Check our assumptions */ DEBUGASSERT((sem->semcount > 0 && stcb == NULL) || (sem->semcount <= 0 && stcb != NULL)); - /* Perfom the following actions only if a new thread was given a count. */ - - if (stcb) - { - /* The currently executed thread should be the low priority - * thread that just posted the count and caused this action. - * However, we cannot drop the priority of the currently running - * thread -- becuase that will cause it to be suspended. - * - * So, do this in two passes. First, reprioritizing all holders - * except for the running thread. - */ - - (void)sem_foreachholder(sem, sem_restoreholderprioA, stcb); - - /* Now, find an reprioritize only the ready to run task */ - - (void)sem_foreachholder(sem, sem_restoreholderprioB, stcb); - } - - /* If there are no tasks waiting for available counts, then all holders - * should be at their base priority. + /* Handler semaphore counts posed from an interrupt handler differently + * from interrupts posted from threads. The primary difference is that + * if the semaphore is posted from a thread, then the poster thread is + * a player in the priority inheritance scheme. The interrupt handler + * externally injects the new count without otherwise participating + * itself. */ -#ifdef CONFIG_DEBUG + if (up_interrupt_context()) + { + sem_restorebaseprio_irq(stcb, sem); + } else { - (void)sem_foreachholder(sem, sem_verifyholder, NULL); - } -#endif - - /* In any case, the currently execuing task should have an entry in the - * list. Its counts were previously decremented; if it now holds no - * counts, then we need to remove it from the list of holders. - */ - - pholder = sem_findholder(sem, rtcb); - if (pholder) - { - /* When no more counts are held, remove the holder from the list. The - * count was decremented in sem_releaseholder. - */ - - if (pholder->counts <= 0) - { - sem_freeholder(sem, pholder); - } + sem_restorebaseprio_task(stcb, sem); } } diff --git a/nuttx/sched/sem_post.c b/nuttx/sched/sem_post.c index b3780db1f6..1c694b68c6 100644 --- a/nuttx/sched/sem_post.c +++ b/nuttx/sched/sem_post.c @@ -123,17 +123,21 @@ int sem_post(FAR sem_t *sem) sem_releaseholder(sem); sem->semcount++; - /* If the result of of semaphore unlock is non-positive, then - * there must be some task waiting for the semaphore. - */ - #ifdef CONFIG_PRIORITY_INHERITANCE - /* Don't let it run until we complete the priority restoration - * steps. + /* Don't let any unblocked tasks run until we complete any priority + * restoration steps. Interrupts are disabled, but we do not want + * the head of the read-to-run list to be modified yet. + * + * NOTE: If this sched_lock is called from an interrupt handler, it + * will do nothing. */ sched_lock(); #endif + /* If the result of of semaphore unlock is non-positive, then + * there must be some task waiting for the semaphore. + */ + if (sem->semcount <= 0) { /* Check if there are any tasks in the waiting for semaphore diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 63dc28aa05..e94476f2a7 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -44,6 +44,7 @@ #include #include +#include #include #include "os_internal.h" @@ -180,6 +181,7 @@ static inline void task_onexit(FAR _TCB *tcb, int status) tcb->onexitfunc = NULL; } #endif +} #else # define task_onexit(tcb,status) #endif diff --git a/nuttx/sched/work_cancel.c b/nuttx/sched/work_cancel.c index c277f024d2..55df86f44f 100644 --- a/nuttx/sched/work_cancel.c +++ b/nuttx/sched/work_cancel.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/work_cancel.c * - * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010, 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -74,6 +74,7 @@ /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** * Name: work_cancel * @@ -83,6 +84,7 @@ * again. * * Input parameters: + * qid - The work queue ID * work - The previously queue work structure to cancel * * Returned Value: @@ -90,11 +92,12 @@ * ****************************************************************************/ -int work_cancel(struct work_s *work) +int work_cancel(int qid, FAR struct work_s *work) { + FAR struct wqueue_s *wqueue = &g_work[qid]; irqstate_t flags; - DEBUGASSERT(work != NULL); + DEBUGASSERT(work != NULL && (unsigned)qid < NWORKERS); /* Cancelling the work is simply a matter of removing the work structure * from the work queue. This must be done with interrupts disabled because @@ -104,14 +107,21 @@ int work_cancel(struct work_s *work) flags = irqsave(); if (work->worker != NULL) { - DEBUGASSERT(work->dq.flink || (FAR dq_entry_t *)work == g_work.head); - DEBUGASSERT(work->dq.blink || (FAR dq_entry_t *)work == g_work.tail); - dq_rem((FAR dq_entry_t *)work, &g_work); + /* A little test of the integrity of the work queue */ + DEBUGASSERT(work->dq.flink ||(FAR dq_entry_t *)work == wqueue->q.tail); + DEBUGASSERT(work->dq.blink ||(FAR dq_entry_t *)work == wqueue->q.head); + + /* Remove the entry from the work queue and make sure that it is + * mark as availalbe (i.e., the worker field is nullified). + */ + + dq_rem((FAR dq_entry_t *)work, &wqueue->q); work->worker = NULL; } irqrestore(flags); return OK; } + #endif /* CONFIG_SCHED_WORKQUEUE */ diff --git a/nuttx/sched/work_internal.h b/nuttx/sched/work_internal.h index 69b7bf5470..7f6c1a9373 100644 --- a/nuttx/sched/work_internal.h +++ b/nuttx/sched/work_internal.h @@ -51,51 +51,49 @@ /* Configuration ************************************************************/ -#ifndef CONFIG_SCHED_WORKPRIORITY -# define CONFIG_SCHED_WORKPRIORITY 50 -#endif - -#ifndef CONFIG_SCHED_WORKPERIOD -# define CONFIG_SCHED_WORKPERIOD (50*1000) /* 50 milliseconds */ -#endif - -#ifndef CONFIG_SCHED_WORKSTACKSIZE -# define CONFIG_SCHED_WORKSTACKSIZE CONFIG_IDLETHREAD_STACKSIZE -#endif - #ifdef CONFIG_DISABLE_SIGNALS # warning "Worker thread support requires signals" #endif +#ifdef CONFIG_SCHED_LPWORK +# define NWORKERS 2 +#else +# define NWORKERS 1 +#endif + /**************************************************************************** * Public Types ****************************************************************************/ #ifndef __ASSEMBLY__ +/* This structure defines the state on one work queue */ + +struct wqueue_s +{ + pid_t pid; /* The task ID of the worker thread */ + struct dq_queue_s q; /* The queue of pending work */ +}; + /**************************************************************************** * Public Data ****************************************************************************/ -/* The queue of pending work */ +/* The state of each work queue */ -extern struct dq_queue_s g_work; - -/* The task ID of the worker thread */ - -extern pid_t g_worker; +extern struct wqueue_s g_work[NWORKERS]; /**************************************************************************** * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: work_thread + * Name: work_hpthread and work_lpthread * * Description: - * This is the main worker thread that performs actions placed on the work - * queue. It also performs periodic garbage collection (that is performed - * by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined). + * These are the main worker threads that performs actions placed on the + * work lists. One thread also performs periodic garbage collection (that + * is performed by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined). * * Input parameters: * argc, argv (not used) @@ -105,7 +103,11 @@ extern pid_t g_worker; * ****************************************************************************/ -int work_thread(int argc, char *argv[]); +int work_hpthread(int argc, char *argv[]); + +#ifdef CONFIG_SCHED_LPWORK +int work_lpthread(int argc, char *argv[]); +#endif #endif /* __ASSEMBLY__ */ #endif /* CONFIG_SCHED_WORKQUEUE */ diff --git a/nuttx/sched/work_queue.c b/nuttx/sched/work_queue.c index beeac168dd..075f08a4d7 100644 --- a/nuttx/sched/work_queue.c +++ b/nuttx/sched/work_queue.c @@ -76,6 +76,7 @@ /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** * Name: work_queue * @@ -91,6 +92,7 @@ * and remove it from the work queue. * * Input parameters: + * qid - The work queue ID (index) * work - The work structure to queue * worker - The worker callback to be invoked. The callback will invoked * on the worker thread of execution. @@ -104,11 +106,13 @@ * ****************************************************************************/ -int work_queue(struct work_s *work, worker_t worker, FAR void *arg, uint32_t delay) +int work_queue(int qid, FAR struct work_s *work, worker_t worker, + FAR void *arg, uint32_t delay) { + FAR struct wqueue_s *wqueue = &g_work[qid]; irqstate_t flags; - DEBUGASSERT(work != NULL); + DEBUGASSERT(work != NULL && (unsigned)qid < NWORKERS); /* First, initialize the work structure */ @@ -123,8 +127,10 @@ int work_queue(struct work_s *work, worker_t worker, FAR void *arg, uint32_t del flags = irqsave(); work->qtime = clock_systimer(); /* Time work queued */ - dq_addlast((FAR dq_entry_t *)work, &g_work); - work_signal(); /* Wake up the worker thread */ + + dq_addlast((FAR dq_entry_t *)work, &wqueue->q); + kill(wqueue->pid, SIGWORK); /* Wake up the worker thread */ + irqrestore(flags); return OK; } diff --git a/nuttx/sched/work_signal.c b/nuttx/sched/work_signal.c new file mode 100644 index 0000000000..6e6838c695 --- /dev/null +++ b/nuttx/sched/work_signal.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * sched/work_signal.c + * + * Copyright (C) 2009-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "work_internal.h" + +#ifdef CONFIG_SCHED_WORKQUEUE + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ +/**************************************************************************** + * Name: work_signal + * + * Description: + * Signal the worker thread to process the work queue now. This function + * is used internally by the work logic but could also be used by the + * user to force an immediate re-assessment of pending work. + * + * Input parameters: + * qid - The work queue ID + * + * Returned Value: + * Zero on success, a negated errno on failure + * + ****************************************************************************/ + +int work_signal(int qid) +{ + DEBUGASSERT((unsigned)qid < NWORKERS); + return kill(g_work[qid].pid, SIGWORK); +} + +#endif /* CONFIG_SCHED_WORKQUEUE */ diff --git a/nuttx/sched/work_thread.c b/nuttx/sched/work_thread.c index fe14ae5e58..abd86f7710 100644 --- a/nuttx/sched/work_thread.c +++ b/nuttx/sched/work_thread.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/work_thread.c * - * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -67,15 +67,9 @@ * Public Variables ****************************************************************************/ -/* The queue of pending work */ +/* The state of each work queue */ -struct dq_queue_s g_work; - -/* The task ID of the worker thread */ - -#ifdef CONFIG_SCHED_WORKQUEUE -pid_t g_worker; -#endif +struct wqueue_s g_work[NWORKERS]; /**************************************************************************** * Private Variables @@ -85,16 +79,116 @@ pid_t g_worker; * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: work_process + * + * Description: + * This is the logic that performs actions placed on any work list. + * + * Input parameters: + * wqueue - Describes the work queue to be processed + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void work_process(FAR struct wqueue_s *wqueue) +{ + volatile FAR struct work_s *work; + worker_t worker; + irqstate_t flags; + FAR void *arg; + uint32_t elapsed; + uint32_t remaining; + uint32_t next; + + /* Then process queued work. We need to keep interrupts disabled while + * we process items in the work list. + */ + + next = CONFIG_SCHED_WORKPERIOD / USEC_PER_TICK; + flags = irqsave(); + work = (FAR struct work_s *)wqueue->q.head; + while (work) + { + /* Is this work ready? It is ready if there is no delay or if + * the delay has elapsed. qtime is the time that the work was added + * to the work queue. It will always be greater than or equal to + * zero. Therefore a delay of zero will always execute immediately. + */ + + elapsed = clock_systimer() - work->qtime; + if (elapsed >= work->delay) + { + /* Remove the ready-to-execute work from the list */ + + (void)dq_rem((struct dq_entry_s *)work, &wqueue->q); + + /* Extract the work description from the entry (in case the work + * instance by the re-used after it has been de-queued). + */ + + worker = work->worker; + arg = work->arg; + + /* Mark the work as no longer being queued */ + + work->worker = NULL; + + /* Do the work. Re-enable interrupts while the work is being + * performed... we don't have any idea how long that will take! + */ + + irqrestore(flags); + worker(arg); + + /* Now, unfortunately, since we re-enabled interrupts we don't + * know the state of the work list and we will have to start + * back at the head of the list. + */ + + flags = irqsave(); + work = (FAR struct work_s *)wqueue->q.head; + } + else + { + /* This one is not ready.. will it be ready before the next + * scheduled wakeup interval? + */ + + remaining = elapsed - work->delay; + if (remaining < next) + { + /* Yes.. Then schedule to wake up when the work is ready */ + + next = remaining; + } + + /* Then try the next in the list. */ + + work = (FAR struct work_s *)work->dq.flink; + } + } + + /* Wait awhile to check the work list. We will wait here until either + * the time elapses or until we are awakened by a signal. + */ + + usleep(next * USEC_PER_TICK); + irqrestore(flags); +} + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: work_thread + * Name: work_hpthread and work_lpthread * * Description: - * This is the main worker thread that performs actions placed on the work - * list. It also performs periodic garbage collection (that is performed - * by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined). + * These are the main worker threads that performs actions placed on the + * work lists. One thread also performs periodic garbage collection (that + * is performed by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined). * * Input parameters: * argc, argv (not used) @@ -104,30 +198,40 @@ pid_t g_worker; * ****************************************************************************/ -int work_thread(int argc, char *argv[]) +int work_hpthread(int argc, char *argv[]) { - volatile FAR struct work_s *work; - worker_t worker; - FAR void *arg; - uint32_t elapsed; - uint32_t remaining; - uint32_t next; - int usec; - irqstate_t flags; - /* Loop forever */ - usec = CONFIG_SCHED_WORKPERIOD; - flags = irqsave(); for (;;) { - /* Wait awhile to check the work list. We will wait here until either - * the time elapses or until we are awakened by a signal. + /* First, perform garbage collection. This cleans-up memory de-allocations + * that were queued because they could not be freed in that execution + * context (for example, if the memory was freed from an interrupt handler). + * NOTE: If the work thread is disabled, this clean-up is performed by + * the IDLE thread (at a very, very lower priority). */ - usleep(usec); - irqrestore(flags); +#ifdef CONFIG_SCHED_LPWORK + sched_garbagecollection(); +#endif + /* Then process queued work. We need to keep interrupts disabled while + * we process items in the work list. + */ + + work_process(&g_work[HPWORK]); + } + + return OK; /* To keep some compilers happy */ +} + +#ifdef CONFIG_SCHED_LPWORK +int work_lpthread(int argc, char *argv[]) +{ + /* Loop forever */ + + for (;;) + { /* First, perform garbage collection. This cleans-up memory de-allocations * that were queued because they could not be freed in that execution * context (for example, if the memory was freed from an interrupt handler). @@ -141,75 +245,12 @@ int work_thread(int argc, char *argv[]) * we process items in the work list. */ - next = CONFIG_SCHED_WORKPERIOD / USEC_PER_TICK; - flags = irqsave(); - work = (FAR struct work_s *)g_work.head; - while (work) - { - /* Is this work ready? It is ready if there is no delay or if - * the delay has elapsed. qtime is the time that the work was added - * to the work queue. It will always be greater than or equal to - * zero. Therefore a delay of zero will always execute immediately. - */ - - elapsed = clock_systimer() - work->qtime; - if (elapsed >= work->delay) - { - /* Remove the ready-to-execute work from the list */ - - (void)dq_rem((struct dq_entry_s *)work, &g_work); - - /* Extract the work description from the entry (in case the work - * instance by the re-used after it has been de-queued). - */ - - worker = work->worker; - arg = work->arg; - - /* Mark the work as no longer being queued */ - - work->worker = NULL; - - /* Do the work. Re-enable interrupts while the work is being - * performed... we don't have any idea how long that will take! - */ - - irqrestore(flags); - worker(arg); - - /* Now, unfortunately, since we re-enabled interrupts we don't - * know the state of the work list and we will have to start - * back at the head of the list. - */ - - flags = irqsave(); - work = (FAR struct work_s *)g_work.head; - } - else - { - /* This one is not ready.. will it be ready before the next - * scheduled wakeup interval? - */ - - remaining = elapsed - work->delay; - if (remaining < next) - { - /* Yes.. Then schedule to wake up when the work is ready */ - - next = remaining; - } - - /* Then try the next in the list. */ - - work = (FAR struct work_s *)work->dq.flink; - } - } - - /* Now calculate the microsecond delay we should wait */ - - usec = next * USEC_PER_TICK; + work_process(&g_work[LPWORK]); } return OK; /* To keep some compilers happy */ } + +#endif /* CONFIG_SCHED_LPWORK */ + #endif /* CONFIG_SCHED_WORKQUEUE */ diff --git a/nuttx/syscall/Makefile b/nuttx/syscall/Makefile index 7ef1a46295..88365759d1 100644 --- a/nuttx/syscall/Makefile +++ b/nuttx/syscall/Makefile @@ -2,7 +2,7 @@ # syscall/Makefile # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/syscall/README.txt b/nuttx/syscall/README.txt index 0b77f50bfc..ed5e6081d7 100644 --- a/nuttx/syscall/README.txt +++ b/nuttx/syscall/README.txt @@ -108,6 +108,10 @@ Each type field has a format as follows: cannot cast a union sigval to a uinptr_t either. Rather, we need to cast a specific union member fieldname to uintptr_t. +NOTE: This CSV file is used both to support the generate of trap information, +but also for the generation of symbol tables. See nuttx/tools/README.txt +and nuttx/lib/README.txt for further information. + Auto-Generated Files ==================== diff --git a/nuttx/syscall/proxies/Make.defs b/nuttx/syscall/proxies/Make.defs index abd6c01026..a14e3562e1 100644 --- a/nuttx/syscall/proxies/Make.defs +++ b/nuttx/syscall/proxies/Make.defs @@ -2,7 +2,7 @@ # syscall/proxies/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/syscall/stub_lookup.h b/nuttx/syscall/stub_lookup.h index 9b4a928144..1c749ee621 100644 --- a/nuttx/syscall/stub_lookup.h +++ b/nuttx/syscall/stub_lookup.h @@ -2,7 +2,7 @@ * syscall/stub_lookup.h * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/syscall/stubs/Make.defs b/nuttx/syscall/stubs/Make.defs index 10d10c08a2..0f40052c0a 100644 --- a/nuttx/syscall/stubs/Make.defs +++ b/nuttx/syscall/stubs/Make.defs @@ -2,7 +2,7 @@ # syscall/stubs/Make.defs # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/syscall/syscall.csv b/nuttx/syscall/syscall.csv index 22b45df9da..4ccd53f9d6 100644 --- a/nuttx/syscall/syscall.csv +++ b/nuttx/syscall/syscall.csv @@ -40,7 +40,7 @@ "open","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","int","..." "opendir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR DIR*","FAR const char*" "pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*" -"prctl", sys/prctl.h, "CONFIG_TASK_NAME_SIZE > 0","int","int","..." +"prctl","sys/prctl.h", "CONFIG_TASK_NAME_SIZE > 0","int","int","..." "clock_systimer","nuttx/clock.h","!defined(CONFIG_DISABLE_CLOCK)","uint32_t" "poll","poll.h","!defined(CONFIG_DISABLE_POLL) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","FAR struct pollfd*","nfds_t","int" "pthread_barrier_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrier_t*" @@ -135,7 +135,7 @@ #"up_assert","assert.h","","void" "up_assert_code","assert.h","","void","FAR const uint8_t*","int","int" #"up_assert_code","assert.h","","void","int" -"usleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","void","useconds_t" +"usleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","int","useconds_t" #"wait","sys/wait.h","","pid_t","int*" #"waitid","sys/wait.h","","int","idtype_t","id_t id","siginfo_t*","int" "waitpid","sys/wait.h","defined(CONFIG_SCHED_WAITPID)","pid_t","pid_t","int*","int" diff --git a/nuttx/tools/Config.mk b/nuttx/tools/Config.mk new file mode 100644 index 0000000000..3a82a19377 --- /dev/null +++ b/nuttx/tools/Config.mk @@ -0,0 +1,72 @@ +############################################################################ +# Config.mk +# Global build rules and macros. +# +# Author: Richard Cochran +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# These are configuration variables that are quoted by configuration tool +# but which must be unquoated when used in the build system. + +CONFIG_ARCH := $(patsubst "%",%,$(strip $(CONFIG_ARCH))) +CONFIG_ARCH_CHIP := $(patsubst "%",%,$(strip $(CONFIG_ARCH_CHIP))) +CONFIG_ARCH_BOARD := $(patsubst "%",%,$(strip $(CONFIG_ARCH_BOARD))) + +# Default build rules. + +define PREPROCESS + @echo "CPP: $1->$2" + $(Q) $(CPP) $(CPPFLAGS) $1 -o $2 +endef + +define COMPILE + @echo "CC: $1" + $(Q) $(CC) -c $(CFLAGS) $1 -o $2 +endef + +define COMPILEXX + @echo "CXX: $1" + $(Q) $(CXX) -c $(CXXFLAGS) $1 -o $2 +endef + +define ASSEMBLE + @echo "AS: $1" + $(Q) $(CC) -c $(AFLAGS) $1 -o $2 +endef + +define ARCHIVE + echo "AR: $2"; \ + $(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; } +endef + +define CLEAN + $(Q) rm -f *.o *.a +endef diff --git a/nuttx/tools/Makefile.export b/nuttx/tools/Makefile.export index fa2909972a..ce4842187a 100644 --- a/nuttx/tools/Makefile.export +++ b/nuttx/tools/Makefile.export @@ -2,7 +2,7 @@ # Makefile.export # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/Makefile.host b/nuttx/tools/Makefile.host index cf421aa3bf..33b7aaab2b 100644 --- a/nuttx/tools/Makefile.host +++ b/nuttx/tools/Makefile.host @@ -58,8 +58,13 @@ mkversion: mkconfig.c cfgparser.c # mksyscall - Convert a CSV file into syscall stubs and proxies -mksyscall: mksyscall.c - @gcc $(CFLAGS) -o mksyscall mksyscall.c +mksyscall: mksyscall.c csvparser.c + @gcc $(CFLAGS) -o mksyscall mksyscall.c csvparser.c + +# mksymtab - Convert a CSV file into a symbol table + +mksymtab: mksymtab.c csvparser.c + @gcc $(CFLAGS) -o mksymtab mksymtab.c csvparser.c # bdf-converter - Converts a BDF font to the NuttX font format diff --git a/nuttx/tools/README.txt b/nuttx/tools/README.txt old mode 100755 new mode 100644 index 39128fa1b0..5d52eaefff --- a/nuttx/tools/README.txt +++ b/nuttx/tools/README.txt @@ -17,6 +17,12 @@ configure.sh target board. See configs/README.txt or Documentation/NuttxPortingGuide.html for a description of how to configure NuttX with this script. +discover.py + + Example script for discovering devices in the local network. + It is the counter part to apps/netutils/discover + + mkconfig.c, cfgparser.c, and cfgparser.h These are Cs file that are used to build mkconfig program. The mkconfig @@ -44,6 +50,16 @@ mkexport.sh and Makefile.export Makefile.export is used only by the mkexport.sh script to parse out options from the top-level Make.defs file. +mkfsdata.pl + + This perl script is used to build the "fake" file system and CGI support + as needed for the apps/netutils/webserver. It is currently used only + by the Makefile at apps/examples/uip. That example serves as an example + of how to configure the uIP webserver "fake" file system. + + NOTE: This perl script comes from uIP and was (probably) written + by Adam Dunkels. uIP has a license that is compatible with NuttX. + mkversion.c, cfgparser.c, and cfgparser.h This is C file that is used to build mkversion program. The mkversion @@ -57,7 +73,7 @@ mkversion.c, cfgparser.c, and cfgparser.h .version file in the top level directory into include/nuttx/version.h. version.h provides version information that can be included by C files. -mksyscall.c +mksyscall.c, cvsparser.c, and cvsparser.h This is a C file that is used to build mksyscall program. The mksyscall program is used during the initial NuttX build by the logic in the top- @@ -79,6 +95,26 @@ mksyscall.c accept this CVS file as input and generate all of the required proxy or stub files as output. See syscall/README.txt for additonal information. +mksymtab.c, cvsparser.c, and cvsparser.h + + This is a C file that is used to build symbol tables from common-separated + value (CSV) files. This tool is not used during the NuttX build, but + can be used as needed to generate files. + + USAGE: ./mksymtab + + Where: + + : The path to the input CSV file + : The path to the output symbol table file + -d : Enable debug output + + Example: + + cd nuttx/tools + cat ../syscall/syscall.csv ../lib/lib.csv | sort >tmp.csv + ./mksymtab.exe tmp.csv tmp.c + pic32mx This directory contains build tools used only for PIC32MX platforms diff --git a/nuttx/tools/cfgparser.c b/nuttx/tools/cfgparser.c index 655fac5739..e49b29d5e4 100644 --- a/nuttx/tools/cfgparser.c +++ b/nuttx/tools/cfgparser.c @@ -52,21 +52,41 @@ char line[LINESIZE+1]; /**************************************************************************** + * Private Data + ****************************************************************************/ + +/* These are configuration variable name that are quoted by configuration tool + * but which must be unquoated when used in C code. + */ + +static const char *dequote_list[] = +{ + "CONFIG_USER_ENTRYPOINT", + NULL +}; + + /**************************************************************************** * Private Functions ****************************************************************************/ + /* Skip over any spaces */ + static char *skip_space(char *ptr) { while (*ptr && isspace((int)*ptr)) ptr++; return ptr; } +/* Find the end of a variable string */ + static char *find_name_end(char *ptr) { while (*ptr && (isalnum((int)*ptr) || *ptr == '_')) ptr++; return ptr; } +/* Find the end of a value string */ + static char *find_value_end(char *ptr) { while (*ptr && !isspace((int)*ptr)) @@ -84,6 +104,8 @@ static char *find_value_end(char *ptr) return ptr; } +/* Read the next line from the configuration file */ + static char *read_line(FILE *stream) { char *ptr; @@ -106,31 +128,127 @@ static char *read_line(FILE *stream) } } +/* Parse the line from the configuration file into a variable name + * string and a value string. + */ + static void parse_line(char *ptr, char **varname, char **varval) { - *varname = ptr; + /* Skip over any leading spaces */ + + ptr = skip_space(ptr); + + /* The first no-space is the beginning of the variable name */ + + *varname = skip_space(ptr); *varval = NULL; - ptr = find_name_end(ptr); - if (*ptr && *ptr != '=') + /* Parse to the end of the variable name */ + + ptr = find_name_end(ptr); + + /* An equal sign is expected next, perhaps after some white space */ + + if (*ptr && *ptr != '=') { + /* Some else follows the variable name. Terminate the variable + * name and skip over any spaces. + */ + *ptr = '\0'; ptr = skip_space(ptr + 1); } + /* Verify that the equal sign is present */ + if (*ptr == '=') { + /* Make sure that the variable name is terminated (this was already + * done if the name was followed by white space. + */ + *ptr = '\0'; + + /* The variable value should follow =, perhaps separated by some + * white space. + */ + ptr = skip_space(ptr + 1); if (*ptr) { + /* Yes.. a variable follows. Save the pointer to the start + * of the variable string. + */ + *varval = ptr; + + /* Find the end of the variable string and make sure that it + * is terminated. + */ + ptr = find_value_end(ptr); *ptr = '\0'; } } } +static char *dequote_value(const char *varname, char *varval) +{ + const char **dqnam; + char *dqval = varval; + int len; + + if (dqval) + { + /* Check if the variable name is in the list of strings to be dequoated */ + + for (dqnam = dequote_list; *dqnam; dqnam++) + { + if (strcmp(*dqnam, varname) == 0) + { + break; + } + } + + /* Did we find the variable name in the list of configuration variables + * to be dequoated? + */ + + if (*dqnam) + { + /* Yes... Check if there is a traiing quote */ + + len = strlen(dqval); + if (dqval[len-1] == '"') + { + /* Yes... replace it with a terminator */ + + dqval[len-1] = '\0'; + len--; + } + + /* Is there a leading quote? */ + + if (dqval[0] == '"') + { + /* Yes.. skip over the leading quote */ + + dqval++; + len--; + } + + /* Handle the case where nothing is left after dequoting */ + + if (len < 0) + { + dqval = NULL; + } + } + } + + return dqval; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -141,22 +259,47 @@ void parse_file(FILE *stream) char *varval; char *ptr; + /* Loop until the entire file has been parsed. */ + do { + /* Read the next line from the file */ + ptr = read_line(stream); if (ptr) { + /* Parse the line into a variable and a value field */ + parse_line(ptr, &varname, &varval); + + /* Was a variable name found? */ + if (varname) { + /* Yes.. dequote the value if necessary */ + + varval = dequote_value(varname, varval); + + /* If no value was provided or if the special value 'n' was provided, + * then undefine the configuration variable. + */ + if (!varval || strcmp(varval, "n") == 0) { printf("#undef %s\n", varname); } + + /* Simply define the configuration variable if it has the special + * value "y" + */ + else if (strcmp(varval, "y") == 0) { printf("#define %s 1\n", varname); } + + /* Otherwise, use the value as provided */ + else { printf("#define %s %s\n", varname, varval); diff --git a/nuttx/tools/cfgparser.h b/nuttx/tools/cfgparser.h index 02de42928b..b1c4bae762 100644 --- a/nuttx/tools/cfgparser.h +++ b/nuttx/tools/cfgparser.h @@ -2,7 +2,7 @@ * tools/cfgpaser.h * * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/tools/configure.sh b/nuttx/tools/configure.sh index 3aaed06817..3b68fe3f62 100755 --- a/nuttx/tools/configure.sh +++ b/nuttx/tools/configure.sh @@ -2,7 +2,7 @@ # configure.sh # # Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -101,21 +101,38 @@ if [ ! -d "${configpath}" ]; then fi if [ ! -r "${configpath}/Make.defs" ]; then - echo "File ${configpath}/Make.defs does not exist" + echo "File \"${configpath}/Make.defs\" does not exist" exit 4 fi if [ ! -r "${configpath}/setenv.sh" ]; then - echo "File ${configpath}/setenv.sh does not exist" + echo "File \"${configpath}/setenv.sh\" does not exist" exit 5 fi if [ ! -r "${configpath}/defconfig" ]; then - echo "File ${configpath}/defconfig does not exist" + echo "File \"${configpath}/defconfig\" does not exist" exit 6 fi -# Check for the apps/ dir in the usual place if appdir was not provided +# Extract values needed from the defconfig file. We need: +# (1) The CONFIG_NUTTX_NEWCONFIG setting to know if this is a "new" style +# configuration, and +# (2) The CONFIG_APPS_DIR to see if there is a configured location for the +# application directory. + +newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${configpath}/defconfig" | cut -d'=' -f2` + +defappdir=y +if [ -z "${appdir}" ]; then + quoted=`grep "^CONFIG_APPS_DIR=" "${configpath}/defconfig" | cut -d'=' -f2` + if [ ! -z "${appdir}" ]; then + appdir=`echo ${quoted} | sed -e "s/\"//g"` + defappdir=n + fi +fi + +# Check for the apps/ directory in the usual place if appdir was not provided if [ -z "${appdir}" ]; then @@ -140,7 +157,15 @@ if [ -z "${appdir}" ]; then fi fi -# Okay... setup the configuration +# If appsdir was provided (or discovered) then make sure that the apps/ +# directory exists + +if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${appdir}" ]; then + echo "Directory \"${TOPDIR}/${appdir}\" does not exist" + exit 7 +fi + +# Okay... Everything looks good. Setup the configuration install -C "${configpath}/Make.defs" "${TOPDIR}/." || \ { echo "Failed to copy ${configpath}/Make.defs" ; exit 7 ; } @@ -150,19 +175,28 @@ chmod 755 "${TOPDIR}/setenv.sh" install -C "${configpath}/defconfig" "${TOPDIR}/.configX" || \ { echo "Failed to copy ${configpath}/defconfig" ; exit 9 ; } -# Copy option appconfig +# If we did not use the CONFIG_APPS_DIR that was in the defconfig config file, +# then append the correct application information to the tail of the .config +# file -if [ ! -z "${appdir}" ]; then +if [ "X${defappdir}" = "Xy" ]; then + sed -i -e "/^CONFIG_APPS_DIR/d" "${TOPDIR}/.configX" + echo "" >> "${TOPDIR}/.configX" + echo "# Application configuration" >> "${TOPDIR}/.configX" + echo "" >> "${TOPDIR}/.configX" + echo "CONFIG_APPS_DIR=\"$appdir\"" >> "${TOPDIR}/.configX" +fi + +# Copy appconfig file. The appconfig file will be copied to ${appdir}/.config +# if both (1) ${appdir} is defined and (2) we are not using the new configuration +# (which does not require a .config file in the appsdir. + +if [ ! -z "${appdir}" -a "X${newconfig}" != "Xy" ]; then if [ ! -r "${configpath}/appconfig" ]; then echo "NOTE: No readable appconfig file found in ${configpath}" else install -C "${configpath}/appconfig" "${TOPDIR}/${appdir}/.config" || \ { echo "Failed to copy ${configpath}/appconfig" ; exit 10 ; } - - echo "" >> "${TOPDIR}/.configX" - echo "# Application configuration" >> "${TOPDIR}/.configX" - echo "" >> "${TOPDIR}/.configX" - echo "CONFIG_APPS_DIR=\"$appdir\"" >> "${TOPDIR}/.configX" fi fi diff --git a/nuttx/tools/csvparser.c b/nuttx/tools/csvparser.c new file mode 100644 index 0000000000..3f1916e2bf --- /dev/null +++ b/nuttx/tools/csvparser.c @@ -0,0 +1,234 @@ +/**************************************************************************** + * tools/csvparser.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "csvparser.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +bool g_debug; +char g_line[LINESIZE+1]; +char g_parm[MAX_FIELDS][MAX_PARMSIZE]; +int g_lineno; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: skip_space + ****************************************************************************/ + +static char *skip_space(char *ptr) +{ + while (*ptr && isspace((int)*ptr)) ptr++; + return ptr; +} + +/**************************************************************************** + * Name: copy_parm + ****************************************************************************/ + +static char *copy_parm(char *src, char *dest) +{ + char *start = src; + int i; + + /* De-quote the parameter and copy it into the parameter array */ + + for (i = 0; i < MAX_PARMSIZE; i++) + { + if (*src == '"') + { + *dest = '\0'; + return src; + } + else if (*src == '\n' || *src == '\0') + { + fprintf(stderr, "%d: Unexpected end of line: \"%s\"\n", g_lineno, start); + exit(4); + } + else + { + *dest++ = *src++; + } + } + + fprintf(stderr, "%d: Parameter too long: \"%s\"\n", g_lineno, start); + exit(3); +} + +/**************************************************************************** + * Name: find_parm + ****************************************************************************/ + +static char *find_parm(char *ptr) +{ + char *start = ptr; + + if (*ptr != '"') + { + fprintf(stderr, "%d: I'm confused: \"%s\"\n", g_lineno, start); + exit(5); + } + ptr++; + + ptr = skip_space(ptr); + if (*ptr == '\n' || *ptr == '\0') + { + return NULL; + } + else if (*ptr != ',') + { + fprintf(stderr, "%d: Expected ',': \"%s\"\n", g_lineno, start); + exit(6); + } + ptr++; + + ptr = skip_space(ptr); + if (*ptr != '"') + { + fprintf(stderr, "%d: Expected \": \"%s\"\n", g_lineno, start); + exit(7); + } + ptr++; + + return ptr; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: read_line + ****************************************************************************/ + +char *read_line(FILE *stream) +{ + char *ptr; + + for (;;) + { + g_line[LINESIZE] = '\0'; + if (!fgets(g_line, LINESIZE, stream)) + { + return NULL; + } + else + { + g_lineno++; + if (g_debug) + { + printf("Line: %s\n", g_line); + } + + ptr = skip_space(g_line); + if (*ptr && *ptr != '#' && *ptr != '\n') + { + return ptr; + } + } + } +} + +/**************************************************************************** + * Name: parse_csvline + ****************************************************************************/ + +int parse_csvline(char *ptr) +{ + int nparms; + int i; + + /* Format "arg1","arg2","arg3",... Spaces will be tolerated outside of the + * quotes. Any initial spaces have already been skipped so the first thing + * should be '"'. + */ + + if (*ptr != '"') + { + fprintf(stderr, "%d: Bad line: \"%s\"\n", g_lineno, g_line); + exit(2); + } + + ptr++; + nparms = 0; + + /* Copy each comma-separated value in an array (stripping quotes from each + * of the values). + */ + + do + { + ptr = copy_parm(ptr, &g_parm[nparms][0]); + nparms++; + ptr = find_parm(ptr); + } + while (ptr); + + /* If debug is enabled, show what we got */ + + if (g_debug) + { + printf("Parameters: %d\n", nparms); + for (i = 0; i < nparms; i++) + { + printf(" Parm%d: \"%s\"\n", i+1, g_parm[i]); + } + } + + return nparms; +} diff --git a/apps/fixedwing_control/pid.h b/nuttx/tools/csvparser.h similarity index 60% rename from apps/fixedwing_control/pid.h rename to nuttx/tools/csvparser.h index 2f85c6c30a..872dc3c020 100644 --- a/apps/fixedwing_control/pid.h +++ b/nuttx/tools/csvparser.h @@ -1,8 +1,8 @@ /**************************************************************************** - * pid.h + * tools/csvparser.h * - * Copyright (C) 2012 Ivan Ovinnikov. All rights reserved. - * Authors: Ivan Ovinnikov + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,14 +33,44 @@ * ****************************************************************************/ +#ifndef __TOOLS_CSVPARSER_H +#define __TOOLS_CSVPARSER_H + /**************************************************************************** * Included Files ****************************************************************************/ +#include +#include -#ifndef PID_H_ -#define PID_H_ +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ -static float pid(float error, float error_deriv, uint16_t dt, float scaler, float K_p, float K_i, float K_d, float intmax); +#define LINESIZE (PATH_MAX > 256 ? PATH_MAX : 256) -#endif /* PID_H_ */ +#define MAX_FIELDS 16 +#define MAX_PARMSIZE 128 +#define NAME_INDEX 0 +#define HEADER_INDEX 1 +#define COND_INDEX 2 +#define RETTYPE_INDEX 3 +#define PARM1_INDEX 4 + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +extern bool g_debug; +extern char g_line[LINESIZE+1]; +extern char g_parm[MAX_FIELDS][MAX_PARMSIZE]; +extern int g_lineno; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +char *read_line(FILE *stream); +int parse_csvline(char *ptr); + +#endif /* __TOOLS_CSVPARSER_H */ diff --git a/nuttx/tools/define.sh b/nuttx/tools/define.sh index 8b2b0e364c..c53cb92a83 100755 --- a/nuttx/tools/define.sh +++ b/nuttx/tools/define.sh @@ -2,7 +2,7 @@ # tools/define.sh # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/discover.py b/nuttx/tools/discover.py new file mode 100755 index 0000000000..cc82a0cad5 --- /dev/null +++ b/nuttx/tools/discover.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +############################################################################ +# tools/discover.py +# +# Copyright (C) 2012 Max Holtzberg. All rights reserved. +# Author: Max Holtzberg +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +import array +import time +from socket import * + +PORT = 96 + +DISCOVER_PROTO_ID = 0x99 +DISCOVER_ALL = 0xff # 0xff means all devices +DISCOVER_REQUEST = 0x01 +DISCOVER_RESPONSE = 0x02 +DISCOVER_REQUEST_SIZE = 4 +DISCOVER_RESPONSE_SIZE = 35 + +def check_sum(data): + chksum = 0 + for c in data[:-1]: + chksum -= c + return (chksum & 0xff) == data[-1] + +def send_discover(socket): + cmd = array.array('B', [0] * DISCOVER_REQUEST_SIZE) + cmd[0] = DISCOVER_PROTO_ID # Tag for identification of the protocol + cmd[1] = DISCOVER_REQUEST # Request command + cmd[2] = DISCOVER_ALL + chksum = 0 + for c in cmd[:3]: + chksum -= c; + cmd[3] = chksum & 0xff + + socket.sendto(cmd, ('', PORT)) + +def read_responses(socket): + res = [] + response = array.array('B', [0] * DISCOVER_RESPONSE_SIZE) + try: + while 1: + size, src = socket.recvfrom_into(response) + if (size == DISCOVER_RESPONSE_SIZE + and response[0] == DISCOVER_PROTO_ID + and response[1] == DISCOVER_RESPONSE + and check_sum(response)): + + dev = {} + dev['addr'] = src[0] + dev['descr'] = response[2:-1].tostring().rstrip('\0') + res.append(dev) + + except timeout: + return res + +if __name__ == '__main__': + print 'Sending discover...' + + s = socket(AF_INET, SOCK_DGRAM) + s.bind(('0.0.0.0', PORT)) + s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) + s.settimeout(1.0); + send_discover(s) + devices = read_responses(s) + socket.close(s) + + print devices diff --git a/nuttx/tools/indent.sh b/nuttx/tools/indent.sh index 938502e0f9..739b791bdc 100755 --- a/nuttx/tools/indent.sh +++ b/nuttx/tools/indent.sh @@ -3,7 +3,7 @@ # tools/indent.sh # # Copyright (C) 2008, 2010 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/link.sh b/nuttx/tools/link.sh index 7927d65c83..da1e6e7ae5 100755 --- a/nuttx/tools/link.sh +++ b/nuttx/tools/link.sh @@ -3,7 +3,7 @@ # tools/link.sh # # Copyright (C) 2008 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index 97e2a9c34c..2d2fff5c56 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -44,7 +44,7 @@ #include "cfgparser.h" /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ #define DEFCONFIG ".config" @@ -174,6 +174,12 @@ int main(int argc, char **argv, char **envp) printf("#ifndef CONFIG_MM_REGIONS\n"); printf("# define CONFIG_MM_REGIONS 1\n"); printf("#endif\n\n"); + printf("/* If the end of RAM is not specified then it is assumed to be the beginning\n"); + printf(" * of RAM plus the RAM size.\n"); + printf(" */\n\n"); + printf("#ifndef CONFIG_DRAM_END\n"); + printf("# define CONFIG_DRAM_END (CONFIG_DRAM_START+CONFIG_DRAM_SIZE)\n"); + printf("#endif\n\n"); printf("/* If no file streams are configured, then make certain that buffered I/O\n"); printf(" * support is disabled\n"); printf(" */\n\n"); @@ -256,8 +262,15 @@ int main(int argc, char **argv, char **envp) printf("# undef CONFIG_DEBUG_USB\n"); printf("# undef CONFIG_DEBUG_GRAPHICS\n"); printf("# undef CONFIG_DEBUG_GPIO\n"); + printf("# undef CONFIG_DEBUG_SPI\n"); printf("# undef CONFIG_DEBUG_STACK\n"); printf("#endif\n\n"); + printf("/* User entry point. This is provided as a fall-back to keep compatibility\n"); + printf(" * with existing code, for builds which do not define CONFIG_USER_ENTRYPOINT.\n"); + printf(" */\n\n"); + printf("#ifndef CONFIG_USER_ENTRYPOINT\n"); + printf("# define CONFIG_USER_ENTRYPOINT user_start\n"); + printf("#endif\n\n"); printf("#endif /* __INCLUDE_NUTTX_CONFIG_H */\n"); fclose(stream); return 0; diff --git a/nuttx/tools/mkdeps.sh b/nuttx/tools/mkdeps.sh index 6d83f2ca01..acb6001509 100755 --- a/nuttx/tools/mkdeps.sh +++ b/nuttx/tools/mkdeps.sh @@ -3,7 +3,7 @@ # tools/mkdeps.sh # # Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/mkfsdata.pl b/nuttx/tools/mkfsdata.pl new file mode 100755 index 0000000000..589ad5f085 --- /dev/null +++ b/nuttx/tools/mkfsdata.pl @@ -0,0 +1,115 @@ +#!/usr/bin/perl +# tools/mkfsdata.pl +# +# Extracted from uIP which has a license that is compatible with NuttX. +# There is no authorship, copyright, or licensing information in the +# original file. Possibly written by Adam Dunkels. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +open(OUTPUT, "> httpd_fsdata.c"); + +chdir("httpd-fs"); + +opendir(DIR, "."); +@files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR); +closedir(DIR); + +print(OUTPUT "#include \n\n"); +print(OUTPUT "#ifndef NULL\n#define NULL 0\n#endif\n\n"); + +foreach $file (@files) { + + if(-d $file && $file !~ /^\./) { + print "Processing directory $file\n"; + opendir(DIR, $file); + @newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR); + closedir(DIR); + printf "Adding files @newfiles\n"; + @files = (@files, map { $_ = "$file/$_" } @newfiles); + next; + } +} + +foreach $file (@files) { + if(-f $file) { + + print "Adding file $file\n"; + + open(FILE, $file) || die "Could not open file $file\n"; + + $file =~ s-^-/-; + $fvar = $file; + $fvar =~ s-/-_-g; + $fvar =~ s-\.-_-g; + # for AVR, add PROGMEM here + print(OUTPUT "static const unsigned char data".$fvar."[] =\n"); + print(OUTPUT "{\n /* $file */\n\n "); + for($j = 0; $j < length($file); $j++) { + printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1))); + } + printf(OUTPUT "0x00,\n "); + + $i = 0; + while(read(FILE, $data, 1)) { + printf(OUTPUT "%#02x, ", unpack("C", $data)); + $i++; + if($i == 10) { + print(OUTPUT "\n"); + $i = 0; + print(OUTPUT " "); + } + } + print(OUTPUT "0x00\n};\n\n"); + close(FILE); + push(@fvars, $fvar); + push(@pfiles, $file); + } +} + +for($i = 0; $i < @fvars; $i++) { + $file = $pfiles[$i]; + $fvar = $fvars[$i]; + + if($i == 0) { + $prevfile = "NULL"; + } else { + $prevfile = "file" . $fvars[$i - 1]; + } + if($i == @fvars-1) { + print(OUTPUT "const struct httpd_fsdata_file g_httpdfs_root[] =\n {{$prevfile, data$fvar, "); + } else { + print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] =\n {{$prevfile, data$fvar, "); + } + print(OUTPUT "data$fvar + ". (length($file) + 1) .", "); + print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n"); +} + +# print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n"); +print(OUTPUT "const int g_httpd_numfiles = $i;\n"); diff --git a/nuttx/tools/mknulldeps.sh b/nuttx/tools/mknulldeps.sh index 6dc3e9635b..033205e6fb 100755 --- a/nuttx/tools/mknulldeps.sh +++ b/nuttx/tools/mknulldeps.sh @@ -2,7 +2,7 @@ # tools/mknulldeps.sh # # Copyright (C) 2008 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/mkromfsimg.sh b/nuttx/tools/mkromfsimg.sh index b628d24196..b774119800 100755 --- a/nuttx/tools/mkromfsimg.sh +++ b/nuttx/tools/mkromfsimg.sh @@ -3,7 +3,7 @@ # tools/mkromfsimg.sh # # Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/mksymtab.c b/nuttx/tools/mksymtab.c new file mode 100644 index 0000000000..c5a46a92be --- /dev/null +++ b/nuttx/tools/mksymtab.c @@ -0,0 +1,289 @@ +/**************************************************************************** + * tools/mksymtab.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "csvparser.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define MAX_HEADER_FILES 500 +#define SYMTAB_NAME "g_symtab" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char *g_hdrfiles[MAX_HEADER_FILES]; +static int nhdrfiles; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void show_usage(const char *progname) +{ + fprintf(stderr, "USAGE: %s \n\n", progname); + fprintf(stderr, "Where:\n\n"); + fprintf(stderr, " : The path to the input CSV file\n"); + fprintf(stderr, " : The path to the output symbol table file\n"); + fprintf(stderr, " -d : Enable debug output\n"); + exit(EXIT_FAILURE); +} + +static bool check_hdrfile(const char *hdrfile) +{ + int i; + + for (i = 0; i < nhdrfiles; i++) + { + if (strcmp(g_hdrfiles[i], hdrfile) == 0) + { + return true; + } + } + + return false; +} + +static void add_hdrfile(const char *hdrfile) +{ + if (hdrfile && strlen(hdrfile) > 0) + { + if (!check_hdrfile(hdrfile)) + { + if (nhdrfiles > MAX_HEADER_FILES) + { + fprintf(stderr, "ERROR: Too man header files. Increase MAX_HEADER_FILES\n"); + exit(EXIT_FAILURE); + } + + g_hdrfiles[nhdrfiles] = strdup(hdrfile); + nhdrfiles++; + } + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv, char **envp) +{ + char *csvpath; + char *symtab; + char *nextterm; + char *finalterm; + char *ptr; + bool cond; + FILE *instream; + FILE *outstream; + int ch; + int i; + + /* Parse command line options */ + + g_debug = false; + + while ((ch = getopt(argc, argv, ":d")) > 0) + { + switch (ch) + { + case 'd' : + g_debug = true; + break; + + case '?' : + fprintf(stderr, "Unrecognized option: %c\n", optopt); + show_usage(argv[0]); + + case ':' : + fprintf(stderr, "Missing option argument, option: %c\n", optopt); + show_usage(argv[0]); + + break; + fprintf(stderr, "Unexpected option: %c\n", ch); + show_usage(argv[0]); + } + } + + if (optind >= argc) + { + fprintf(stderr, "Missing and \n"); + show_usage(argv[0]); + } + + csvpath = argv[optind]; + optind++; + + if (optind >= argc) + { + fprintf(stderr, "Missing \n"); + show_usage(argv[0]); + } + + symtab = argv[optind]; + optind++; + + if (optind < argc) + { + fprintf(stderr, "Unexpected garbage at the end of the line\n"); + show_usage(argv[0]); + } + + /* Open the CSV file for reading */ + + instream = fopen(csvpath, "r"); + if (!instream) + { + fprintf(stderr, "open %s failed: %s\n", csvpath, strerror(errno)); + exit(EXIT_FAILURE); + } + + /* Open the Symbol table file for writing */ + + outstream = fopen(symtab, "w"); + if (!outstream) + { + fprintf(stderr, "open %s failed: %s\n", csvpath, strerror(errno)); + exit(EXIT_FAILURE); + } + + /* Get all of the header files that we need to include */ + + while ((ptr = read_line(instream)) != NULL) + { + /* Parse the line from the CVS file */ + + int nargs = parse_csvline(ptr); + if (nargs < PARM1_INDEX) + { + fprintf(stderr, "Only %d arguments found: %s\n", nargs, g_line); + exit(EXIT_FAILURE); + } + + /* Add the header file to the list of header files we need to include */ + + add_hdrfile(g_parm[HEADER_INDEX]); + } + + /* Back to the beginning */ + + rewind(instream); + + /* Output up-front file boilerplate */ + + fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", symtab); + fprintf(outstream, "#include \n"); + fprintf(outstream, "#include \n\n"); + + /* Output all of the require header files */ + + for (i = 0; i < nhdrfiles; i++) + { + fprintf(outstream, "#include <%s>\n", g_hdrfiles[i]); + } + + /* Now the symbol table itself */ + + fprintf(outstream, "\nstruct symtab_s %s[] =\n", SYMTAB_NAME); + fprintf(outstream, "{\n"); + + /* Parse each line in the CVS file */ + + nextterm = ""; + finalterm = ""; + + while ((ptr = read_line(instream)) != NULL) + { + /* Parse the line from the CVS file */ + + int nargs = parse_csvline(ptr); + if (nargs < PARM1_INDEX) + { + fprintf(stderr, "Only %d arguments found: %s\n", nargs, g_line); + exit(EXIT_FAILURE); + } + + /* Output any conditional compilation */ + + cond = (g_parm[COND_INDEX] && strlen(g_parm[COND_INDEX]) > 0); + if (cond) + { + fprintf(outstream, "%s#if %s\n", nextterm, g_parm[COND_INDEX]); + nextterm = ""; + } + + /* Output the symbol table entry */ + + fprintf(outstream, "%s { \"%s\", (FAR const void *)%s }", + nextterm, g_parm[NAME_INDEX], g_parm[NAME_INDEX]); + + if (cond) + { + nextterm = ",\n#endif\n"; + finalterm = "\n#endif\n"; + } + else + { + nextterm = ",\n"; + finalterm = "\n"; + } + } + + fprintf(outstream, "%s};\n\n", finalterm); + fprintf(outstream, "#define NSYMBOLS (sizeof(%s) / sizeof (struct symtab_s))\n", SYMTAB_NAME); + + /* Close the CSV and symbol table files and exit */ + + fclose(instream); + fclose(outstream); + return EXIT_SUCCESS; +} diff --git a/nuttx/tools/mksyscall.c b/nuttx/tools/mksyscall.c index a8f2cf99b7..a75e82d280 100644 --- a/nuttx/tools/mksyscall.c +++ b/nuttx/tools/mksyscall.c @@ -1,8 +1,8 @@ /**************************************************************************** * tools/mksyscall.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,174 +41,26 @@ #include #include #include -#include -#include #include -#include #include +#include "csvparser.h" + /**************************************************************************** * Definitions ****************************************************************************/ -#define LINESIZE (PATH_MAX > 256 ? PATH_MAX : 256) - -#define MAX_FIELDS 16 -#define MAX_PARMSIZE 128 -#define NAME_INDEX 0 -#define HEADER_INDEX 1 -#define COND_INDEX 2 -#define RETTYPE_INDEX 3 -#define PARM1_INDEX 4 - /**************************************************************************** * Private Data ****************************************************************************/ -static bool g_debug; static bool g_inline; -static char g_line[LINESIZE+1]; -static char g_parm[MAX_FIELDS][MAX_PARMSIZE]; static FILE *g_stubstream; -static int g_lineno; /**************************************************************************** * Private Functions ****************************************************************************/ -static char *skip_space(char *ptr) -{ - while (*ptr && isspace(*ptr)) ptr++; - return ptr; -} - -static char *read_line(FILE *stream) -{ - char *ptr; - - for (;;) - { - g_line[LINESIZE] = '\0'; - if (!fgets(g_line, LINESIZE, stream)) - { - return NULL; - } - else - { - g_lineno++; - if (g_debug) - { - printf("Line: %s\n", g_line); - } - - ptr = skip_space(g_line); - if (*ptr && *ptr != '#' && *ptr != '\n') - { - return ptr; - } - } - } -} - -static char *copy_parm(char *src, char *dest) -{ - char *start = src; - int i; - - for (i = 0; i < MAX_PARMSIZE; i++) - { - if (*src == '"') - { - *dest = '\0'; - return src; - } - else if (*src == '\n' || *src == '\0') - { - fprintf(stderr, "%d: Unexpected end of line: \"%s\"\n", g_lineno, start); - exit(4); - } - else - { - *dest++ = *src++; - } - } - - fprintf(stderr, "%d: Parameter too long: \"%s\"\n", g_lineno, start); - exit(3); -} - -static char *find_parm(char *ptr) -{ - char *start = ptr; - - if (*ptr != '"') - { - fprintf(stderr, "%d: I'm confused: \"%s\"\n", g_lineno, start); - exit(5); - } - ptr++; - - ptr = skip_space(ptr); - if (*ptr == '\n' || *ptr == '\0') - { - return NULL; - } - else if (*ptr != ',') - { - fprintf(stderr, "%d: Expected ',': \"%s\"\n", g_lineno, start); - exit(6); - } - ptr++; - - ptr = skip_space(ptr); - if (*ptr != '"') - { - fprintf(stderr, "%d: Expected \": \"%s\"\n", g_lineno, start); - exit(7); - } - ptr++; - - return ptr; -} - -static int parse_csvline(char *ptr) -{ - int nparms; - int i; - - /* Format "arg1","arg2","arg3",... Spaces will be tolerated outside of the - * quotes. Any initial spaces have already been skipped so the first thing - * should be '"'. - */ - - if (*ptr != '"') - { - fprintf(stderr, "%d: Bad line: \"%s\"\n", g_lineno, g_line); - exit(2); - } - - ptr++; - nparms = 0; - - do - { - ptr = copy_parm(ptr, &g_parm[nparms][0]); - nparms++; - ptr = find_parm(ptr); - } - while (ptr); - - if (g_debug) - { - printf("Parameters: %d\n", nparms); - for (i = 0; i < nparms; i++) - { - printf(" Parm%d: \"%s\"\n", i+1, g_parm[i]); - } - } - return nparms; -} - static bool is_vararg(const char *type, int index, int nparms) { if (strcmp(type,"...") == 0) @@ -719,6 +571,7 @@ static void show_usage(const char *progname) fprintf(stderr, "\t-p : Generate proxies\n"); fprintf(stderr, "\t-s : Generate stubs\n"); fprintf(stderr, "\t-i : Generate proxies as static inline functions\n"); + fprintf(stderr, "\t-d : Enable debug output\n"); exit(1); } diff --git a/nuttx/tools/mkversion.c b/nuttx/tools/mkversion.c index f2086d13a5..32068df38b 100644 --- a/nuttx/tools/mkversion.c +++ b/nuttx/tools/mkversion.c @@ -2,7 +2,7 @@ * tools/mkversion.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/tools/unlink.sh b/nuttx/tools/unlink.sh index 47079f0852..485db36917 100755 --- a/nuttx/tools/unlink.sh +++ b/nuttx/tools/unlink.sh @@ -3,7 +3,7 @@ # tools/unlink.sh # # Copyright (C) 2008 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/version.sh b/nuttx/tools/version.sh index 7cad7ee032..d15adb186c 100755 --- a/nuttx/tools/version.sh +++ b/nuttx/tools/version.sh @@ -2,7 +2,7 @@ # version.sh # # Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/winlink.sh b/nuttx/tools/winlink.sh index c081cee35f..f79eda2bd7 100755 --- a/nuttx/tools/winlink.sh +++ b/nuttx/tools/winlink.sh @@ -3,7 +3,7 @@ # tools/winlink.sh # # Copyright (C) 2008 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/nuttx/tools/xmlrpc_test.py b/nuttx/tools/xmlrpc_test.py new file mode 100644 index 0000000000..64cc89dc99 --- /dev/null +++ b/nuttx/tools/xmlrpc_test.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +############################################################################ +# tools/xmlrpc_test.py +# +# Copyright (C) 2012 Max Holtzberg. All rights reserved. +# Author: Max Holtzberg +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +import sys +import xmlrpclib + +if __name__ == '__main__': + if len(sys.argv) != 2: + print 'Usage: %s ' % sys.argv[0] + quit(1) + + server_url = 'http://%s/device' % sys.argv[1] + server = xmlrpclib.ServerProxy(server_url) + result = server.get_device_stats("username", "password", 0) + print result diff --git a/nuttx/tools/zipme.sh b/nuttx/tools/zipme.sh index a10beaaab4..a8cd160ab3 100755 --- a/nuttx/tools/zipme.sh +++ b/nuttx/tools/zipme.sh @@ -2,7 +2,7 @@ # zipme.sh # # Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions