2014-09-09 01:26:13 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file gps9maghandler.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
|
|
|
* @brief handles GPSV9 onboard magnetometer and sends its data.
|
|
|
|
* --
|
|
|
|
* @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 <pios_struct_helper.h>
|
|
|
|
#include <pios_helpers.h>
|
|
|
|
#include <ubx_utils.h>
|
|
|
|
#include <pios_hmc5x83.h>
|
|
|
|
#include "inc/gps9protocol.h"
|
2014-10-01 02:07:46 +02:00
|
|
|
#define MAG_RATE_HZ 30
|
2014-09-09 01:26:13 +02:00
|
|
|
extern pios_hmc5x83_dev_t onboard_mag;
|
|
|
|
|
|
|
|
void handleMag()
|
|
|
|
{
|
2014-10-01 02:07:46 +02:00
|
|
|
#ifdef PIOS_HMC5X83_HAS_GPIOS
|
2014-09-09 01:26:13 +02:00
|
|
|
if (!PIOS_HMC5x83_NewDataAvailable(onboard_mag)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-01 02:07:46 +02:00
|
|
|
#else
|
|
|
|
static uint32_t lastUpdate = 0;
|
2014-10-03 11:41:26 +02:00
|
|
|
if (PIOS_DELAY_DiffuS(lastUpdate) < (1000000 / MAG_RATE_HZ)) {
|
2014-10-01 02:07:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastUpdate = PIOS_DELAY_GetRaw();
|
|
|
|
#endif
|
2014-09-09 01:26:13 +02:00
|
|
|
static int16_t mag[3];
|
|
|
|
|
|
|
|
if (PIOS_HMC5x83_ReadMag(onboard_mag, mag) == 0) {
|
|
|
|
MagUbxPkt magPkt;
|
|
|
|
// swap axis so that if side with connector is aligned to revo side with connectors, mags data are aligned
|
|
|
|
magPkt.fragments.data.X = -mag[1];
|
|
|
|
magPkt.fragments.data.Y = mag[0];
|
|
|
|
magPkt.fragments.data.Z = mag[2];
|
|
|
|
magPkt.fragments.data.status = 1;
|
|
|
|
ubx_buildPacket(&magPkt.packet, UBX_OP_CUST_CLASS, UBX_OP_MAG, sizeof(MagData));
|
2014-09-20 20:58:40 +02:00
|
|
|
PIOS_COM_SendBuffer(pios_com_main_id, magPkt.packet.binarystream, sizeof(MagUbxPkt));
|
2014-09-09 01:26:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|