From 0731747d84587c6e75fb25a7abacd681d2673ea1 Mon Sep 17 00:00:00 2001 From: fredericg Date: Sun, 13 Jun 2010 17:21:31 +0000 Subject: [PATCH] new object: FlightBatteryState git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@762 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/OpenPilot/Makefile | 5 +- .../OpenPilot/Modules/MK/MKSerial/MKSerial.c | 7 ++ .../OpenPilot/UAVObjects/flightbatterystate.c | 102 ++++++++++++++++++ .../UAVObjects/inc/flightbatterystate.h | 80 ++++++++++++++ flight/OpenPilot/UAVObjects/uavobjectsinit.c | 2 + 5 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 flight/OpenPilot/UAVObjects/flightbatterystate.c create mode 100644 flight/OpenPilot/UAVObjects/inc/flightbatterystate.h diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 1292a74e1..9a58c7783 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -45,9 +45,9 @@ FLASH_TOOL = OPENOCD USE_THUMB_MODE = YES # List of modules to include -MODULES = Telemetry GPS ManualControl Actuator Altitude Attitude +#MODULES = Telemetry GPS ManualControl Actuator Altitude Attitude #MODULES = Telemetry Example -#MODULES = Telemetry MK/MKSerial +MODULES = Telemetry MK/MKSerial # MCU name, submodel and board @@ -149,6 +149,7 @@ SRC += $(OPUAVOBJ)/stabilizationsettings.c SRC += $(OPUAVOBJ)/altitudeactual.c SRC += $(OPUAVOBJ)/attitudeactual.c SRC += $(OPUAVOBJ)/attitudesettings.c +SRC += $(OPUAVOBJ)/flightbatterystate.c endif ## PIOS Hardware (STM32F10x) diff --git a/flight/OpenPilot/Modules/MK/MKSerial/MKSerial.c b/flight/OpenPilot/Modules/MK/MKSerial/MKSerial.c index 48159a7eb..05ae71a2e 100644 --- a/flight/OpenPilot/Modules/MK/MKSerial/MKSerial.c +++ b/flight/OpenPilot/Modules/MK/MKSerial/MKSerial.c @@ -28,6 +28,8 @@ #include "attitudeactual.h" // object that will be updated by the module #include "positionactual.h" +#include "flightbatterystate.h" + // @@ -481,11 +483,13 @@ static void DoConnectedToNC(void) GpsPosition_t pos; AttitudeActualData attitudeData; PositionActualData positionData; + FlightBatteryStateData flightBatteryData; DEBUG_MSG("NC\n\r"); memset(&attitudeData, 0, sizeof(attitudeData)); memset(&positionData, 0, sizeof(positionData)); + memset(&flightBatteryData, 0, sizeof(flightBatteryData)); // Configure NC for fast reporting of the osd-message SendMsgPar8(MK_ADDR_ALL, MSGCMD_GET_OSD, 10); @@ -512,6 +516,9 @@ static void DoConnectedToNC(void) positionData.Satellites = msg.pars[OSD_MSG_NB_SATS_IDX]; positionData.Status = POSITIONACTUAL_STATUS_FIX3D; // FIXME PositionActualSet(&positionData); + + flightBatteryData.Tension = (uint32_t)msg.pars[OSD_MSG_BATT_IDX]*100; + FlightBatteryStateSet(&flightBatteryData); } else { diff --git a/flight/OpenPilot/UAVObjects/flightbatterystate.c b/flight/OpenPilot/UAVObjects/flightbatterystate.c new file mode 100644 index 000000000..32029a419 --- /dev/null +++ b/flight/OpenPilot/UAVObjects/flightbatterystate.c @@ -0,0 +1,102 @@ +/** + ****************************************************************************** + * + * @file flightbatterystate.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the FlightBatteryState object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: flightbatterystate.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "openpilot.h" +#include "flightbatterystate.h" + +// Private variables +static UAVObjHandle handle; + +// Private functions +static void setDefaults(UAVObjHandle obj, uint16_t instId); + +/** + * Initialize object. + * \return 0 Success + * \return -1 Failure + */ +int32_t FlightBatteryStateInitialize() +{ + // Register object with the object manager + handle = UAVObjRegister(FLIGHTBATTERYSTATE_OBJID, FLIGHTBATTERYSTATE_NAME, FLIGHTBATTERYSTATE_METANAME, 0, + FLIGHTBATTERYSTATE_ISSINGLEINST, FLIGHTBATTERYSTATE_ISSETTINGS, FLIGHTBATTERYSTATE_NUMBYTES, &setDefaults); + + // Done + if (handle != 0) + { + return 0; + } + else + { + return -1; + } +} + +/** + * Initialize object fields and metadata with the default values. + * If a default value is not specified the object fields + * will be initialized to zero. + */ +static void setDefaults(UAVObjHandle obj, uint16_t instId) +{ + FlightBatteryStateData data; + UAVObjMetadata metadata; + + // Initialize object fields to their default values + UAVObjGetInstanceData(obj, instId, &data); + memset(&data, 0, sizeof(FlightBatteryStateData)); + + UAVObjSetInstanceData(obj, instId, &data); + + // Initialize object metadata to their default values + metadata.access = ACCESS_READWRITE; + metadata.gcsAccess = ACCESS_READONLY; + metadata.telemetryAcked = 0; + metadata.telemetryUpdateMode = UPDATEMODE_PERIODIC; + metadata.telemetryUpdatePeriod = 1000; + metadata.gcsTelemetryAcked = 0; + metadata.gcsTelemetryUpdateMode = UPDATEMODE_MANUAL; + metadata.gcsTelemetryUpdatePeriod = 0; + metadata.loggingUpdateMode = UPDATEMODE_NEVER; + metadata.loggingUpdatePeriod = 0; + UAVObjSetMetadata(obj, &metadata); +} + +/** + * Get object handle + */ +UAVObjHandle FlightBatteryStateHandle() +{ + return handle; +} + + + diff --git a/flight/OpenPilot/UAVObjects/inc/flightbatterystate.h b/flight/OpenPilot/UAVObjects/inc/flightbatterystate.h new file mode 100644 index 000000000..06be06265 --- /dev/null +++ b/flight/OpenPilot/UAVObjects/inc/flightbatterystate.h @@ -0,0 +1,80 @@ +/** + ****************************************************************************** + * + * @file flightbatterystate.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the FlightBatteryState object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: flightbatterystate.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef FLIGHTBATTERYSTATE_H +#define FLIGHTBATTERYSTATE_H + +// Object constants +#define FLIGHTBATTERYSTATE_OBJID 553396562U +#define FLIGHTBATTERYSTATE_NAME "FlightBatteryState" +#define FLIGHTBATTERYSTATE_METANAME "FlightBatteryStateMeta" +#define FLIGHTBATTERYSTATE_ISSINGLEINST 1 +#define FLIGHTBATTERYSTATE_ISSETTINGS 0 +#define FLIGHTBATTERYSTATE_NUMBYTES sizeof(FlightBatteryStateData) + +// Object access macros +#define FlightBatteryStateGet(dataOut) UAVObjGetData(FlightBatteryStateHandle(), dataOut) +#define FlightBatteryStateSet(dataIn) UAVObjSetData(FlightBatteryStateHandle(), dataIn) +#define FlightBatteryStateInstGet(instId, dataOut) UAVObjGetInstanceData(FlightBatteryStateHandle(), instId, dataOut) +#define FlightBatteryStateInstSet(instId, dataIn) UAVObjSetInstanceData(FlightBatteryStateHandle(), instId, dataIn) +#define FlightBatteryStateConnectQueue(queue) UAVObjConnectQueue(FlightBatteryStateHandle(), queue, EV_MASK_ALL_UPDATES) +#define FlightBatteryStateConnectCallback(cb) UAVObjConnectCallback(FlightBatteryStateHandle(), cb, EV_MASK_ALL_UPDATES) +#define FlightBatteryStateCreateInstance() UAVObjCreateInstance(FlightBatteryStateHandle()) +#define FlightBatteryStateRequestUpdate() UAVObjRequestUpdate(FlightBatteryStateHandle()) +#define FlightBatteryStateRequestInstUpdate(instId) UAVObjRequestInstanceUpdate(FlightBatteryStateHandle(), instId) +#define FlightBatteryStateUpdated() UAVObjUpdated(FlightBatteryStateHandle()) +#define FlightBatteryStateInstUpdated(instId) UAVObjUpdated(FlightBatteryStateHandle(), instId) +#define FlightBatteryStateGetMetadata(dataOut) UAVObjGetMetadata(FlightBatteryStateHandle(), dataOut) +#define FlightBatteryStateSetMetadata(dataIn) UAVObjSetMetadata(FlightBatteryStateHandle(), dataIn) + +// Object data +typedef struct { + uint32_t Tension; + uint32_t Current; + uint32_t ConsumedEnergy; + uint32_t MinimumTension; + uint32_t Capacity; + +} __attribute__((packed)) FlightBatteryStateData; + +// Field information +// Field Tension information +// Field Current information +// Field ConsumedEnergy information +// Field MinimumTension information +// Field Capacity information + + +// Generic interface functions +int32_t FlightBatteryStateInitialize(); +UAVObjHandle FlightBatteryStateHandle(); + +#endif // FLIGHTBATTERYSTATE_H diff --git a/flight/OpenPilot/UAVObjects/uavobjectsinit.c b/flight/OpenPilot/UAVObjects/uavobjectsinit.c index 059d1bb03..343e0c1d9 100644 --- a/flight/OpenPilot/UAVObjects/uavobjectsinit.c +++ b/flight/OpenPilot/UAVObjects/uavobjectsinit.c @@ -38,6 +38,7 @@ #include "exampleobject1.h" #include "exampleobject2.h" #include "examplesettings.h" +#include "flightbatterystate.h" #include "flighttelemetrystats.h" #include "gcstelemetrystats.h" #include "manualcontrolcommand.h" @@ -67,6 +68,7 @@ void UAVObjectsInitializeAll() ExampleObject1Initialize(); ExampleObject2Initialize(); ExampleSettingsInitialize(); + FlightBatteryStateInitialize(); FlightTelemetryStatsInitialize(); GCSTelemetryStatsInitialize(); ManualControlCommandInitialize();