Files

225 lines
13 KiB
C

//**********************************************************************************************************************************************************************************
// Fichier GNSS.C
//
// Contient toutes les fonctions liées à la gestion du GNSS sur ShiBase V2 (GNSS indépedant du gnss de ShipBaseV1)
//**********************************************************************************************************************************************************************************/
#define __DEBUG_GNSS //Décommenter cette ligne pour avoir les messages de debug du GNSS
// Includes :
#include "main.h"
// Prototypes :
int8_t init_gnss(void);
void gestion_gnss(void);
// Variables globales :
struct Struct_gnss gnss;
/**********************************************************************************************************************************************************************************
Fonction INIT_GNSS
Fonction d'initialisation du GNSS
**********************************************************************************************************************************************************************************/
int8_t init_gnss(void)
{
if ((systeme.generation_shipbase == GENERATION_SHIPBASE_V2) || (systeme.generation_shipbase == GENERATION_SHIPBASE_V3))
{
gnss.etat = OFF; // Par défaut.
// ecriture_sortie(TYPE_SORTIE_GPIO, 0, CM3P_DO_MOD_WKUP, ON); // Activation immédiate de la sortie DTR qui n'est pas utilisée mais qui doit être positionnée à 1 pour pouvoir fonctionner
gnss.sequenceur.etat = ETAT_SEQUENCEUR_GNSS_INIT;
gnss.sequenceur.compteur = GNSS_TEMPO_INIT;
gnss.sequenceur.compteur_time_out = 0; // Permet de forcer une mise à l'heure dès la première réception d'une date/heure valide
// Affichage du message de débug :
affichage_debug(__FILE__, __LINE__, "Initialisation du GNSS\t\t: OK", TYPE_MESSAGE_DEBUG_OK);
}
else
{
// Affichage du message de débug :
affichage_debug(__FILE__, __LINE__, "Initialisation du GNSS\t\t: Devalidé car non valide sur cette version de ShipBase", TYPE_MESSAGE_DEBUG_WARNING);
}
return(0);
}
//==================================================================================================================================================================
// Fonction : Appelée en tâche de fond, cette fonction gère les fonctions du Gnss ZOE-M8Q dans son ensemble. Il s'appuie sur les fonctions G-Bus et G_commandes pour y accéder.
// Reçoit : Rien
// Renvoit : Rien
//==================================================================================================================================================================
void gestion_gnss(void)
{
uint16_t i;
uint8_t cde[G_BUS_MAX_TAILLE_CDE];
uint16_t lg_cde;
char tmp[MAX_LONGUEUR_BUFFER_TEMPORAIRE_DEBUG];
if (systeme.generation_shipbase != GENERATION_SHIPBASE_V2) return;
switch(gnss.sequenceur.etat)
{
//----------------------------------------------------------------------------------------------------------------------------------------------------------
case ETAT_SEQUENCEUR_GNSS_INIT :
//----------------------------------------------------------------------------------------------------------------------------------------------------------
{
if (gnss.sequenceur.compteur == 0)
{
// Activation de la sortie DO_GNSS_EXTINT :
// NB : l'usage de cette sortie n'est pas évident lors des essais d'avril 2023...
ecriture_sortie(TYPE_SORTIE_GPIO, 0, CM4_DO_GNSS_EXTINT, ON); // 0 est l'adresse de ShipBase
// Au démarrage, le GNSS émet en NMEA toutes les secondes. La priorité est de stopper ces émissions afin de ne laisser accessible sur l'UART que le protocole µBX.
//----------------------------------------------
// Commande de suppression des émissions NMEA :
//----------------------------------------------
// Cf Page 243 : 32.10.25.2 Port configuration for UART ports
lg_cde = 0;
cde[lg_cde ++] = 1; // 0=DDC (I2C), 1=UART, 3=USB, 4=SPI
cde[lg_cde ++] = 0; // Reserved
cde[lg_cde ++] = 0; // TxReady LSB b0=Enable, etc...
cde[lg_cde ++] = 0; // TxReady MSB
cde[lg_cde ++] = 0b11000000; // Mode LLSB b6 & b7 = baud rate (0b11=8 bits)
cde[lg_cde ++] = 0b00001000; // Mode LSB b1, b2 & b3 = parity (0b10x=No_parity), b4 & b5 = stop bit (0b00=1_stop_bit)
cde[lg_cde ++] = 0; // Mode MSB reserved
cde[lg_cde ++] = 0; // Mode MMSB reserved
cde[lg_cde ++] = 0x80; // Baud rate LLSB 9600b/s = 0x0000 2580
cde[lg_cde ++] = 0x25; // Baud rate LSB
cde[lg_cde ++] = 0x00; // Baud rate MSB
cde[lg_cde ++] = 0x00; // Baud rate MMSB
cde[lg_cde ++] = 0b00000001; // Masque protocoles In LSB b0 = UBX, b1=NMEA
cde[lg_cde ++] = 0; // Masque protocoles In MSB reserved
//cde[lg_cde ++] = 0b00000011; // Masque protocoles Out LSB b0 = UBX, b1=NMEA
cde[lg_cde ++] = 0b00000001; // Masque protocoles Out LSB b0 = UBX, b1=NMEA
cde[lg_cde ++] = 0; // Masque protocoles Out MSB reserved
cde[lg_cde ++] = 0; // Flag bits LSB
cde[lg_cde ++] = 0; // Flag bits MSB
cde[lg_cde ++] = 0; // Reserved
cde[lg_cde ++] = 0; // Reserved
if (g_bus_down_commande_libre(G_COMMANDE_CLASSE_CFG, G_COMMANDE_UBX_CFG_PRT, cde, lg_cde, M_BUS_PROTOCOLE_NORMAL, 0, -1) == 0) affichage_debug(__FILE__, __LINE__, "L'UART du GNSS est passé en mode µBX uniquement", TYPE_MESSAGE_DEBUG_PAR_DEFAUT);
else affichage_debug(__FILE__, __LINE__, "Le passage de l'UART du GNSS en mode µBX uniquement a échoué", TYPE_MESSAGE_DEBUG_ERREUR);
//----------------------------------------------
// Commande lecture de la configuration du GNSS :
//----------------------------------------------
lg_cde = 0;
if (g_bus_down_commande_libre(G_COMMANDE_CLASSE_MON, G_COMMANDE_UBX_MON_VER, cde, lg_cde, M_BUS_PROTOCOLE_NORMAL, 0, -1) == 0) affichage_debug(__FILE__, __LINE__, "La commande de lecture de la version du GNSS a été effectuée avec succés", TYPE_MESSAGE_DEBUG_PAR_DEFAUT);
else affichage_debug(__FILE__, __LINE__, "La commande de lecture de la version du GNSS a échoué", TYPE_MESSAGE_DEBUG_ERREUR);
/* //----------------------------------------------
// Commande de configuration étendue du power management :
//----------------------------------------------
// Cf Page 235 : 32.10.23.1 Extended power management configuration
lg_cde = 0;
cde[lg_cde ++] = 0x01; // Message version (0x01 for this version)
cde[lg_cde ++] = 0; // Reserved
cde[lg_cde ++] = 0; // Maximum time to spend in Acquisition state. If 0: bound disabled (see maxStartupStateDur)
cde[lg_cde ++] = 0; // Reserved
cde[lg_cde ++] = 0b01100000; // PSM config flag LLSB b4 = ExtintSel : 0 (Extint0) ou 1 (Extint1), b5 = ExtintWake : 0 (disabled) ou 1 (enabled), b6 = ExtintBackup : 0 (disabled) ou 1 (enabled)
cde[lg_cde ++] = 0b00000000; // PSM config flag LSB b0 & b1 = LimitPeakCurrent : 00 (disabled) ou 01 (enabled) ou 10/11 (reserved), b2 = WaitTimeFix : 0 (wait for normal fix OK before starting on time) ou (1) wait for time fix OK before starting on time, b3 = UpdateRTC : 0 (do not wake up to update RTC. RTC is updated during normal on-time) ou 1 (update RTC. The receiver adds extra wake-up cycles to update the RTC), b4 = UpdateEPH = b4 : 0 (do not wake up to update Ephemeris data) ou 1 (update Ephemeris. The receiver adds extra wake-up cycles to update the Ephemeris data)
cde[lg_cde ++] = 0b00000010; // PSM config flag MSB b0 = DoNotEnterOFff : 0 (receiver enters [Inactive] Awaiting next search state) ou 1 (receiver does not enter [Inactive] Awaiting next search state but keeps trying to acquire a fix instead), b1 & b2 = Mode : 00 ON/OFF operation ou 01 cyclic tracking operation (PSMCT) ou 10/11 reserved
cde[lg_cde ++] = 0; // PSM config flag MMSB reserved
cde[lg_cde ++] = 0xE8; // Position Update period LLSB (Uint32_t) en ms 1000ms = 0x0000 03E8
cde[lg_cde ++] = 0x03; // Position Update period LSB (Uint32_t) en ms
cde[lg_cde ++] = 0x00; // Position Update period MSB (Uint32_t) en ms
cde[lg_cde ++] = 0x00; // Position Update period MMSB (Uint32_t) en ms
cde[lg_cde ++] = 0x64; // Acquiisition retry period LLSB (Uint32_t) en ms 100ms = 0x0000 0064
cde[lg_cde ++] = 0x00; // Acquiisition retry period LSB (Uint32_t) en ms
cde[lg_cde ++] = 0x00; // Acquiisition retry period MSB (Uint32_t) en ms
cde[lg_cde ++] = 0x00; // Acquiisition retry period MMSB (Uint32_t) en ms
cde[lg_cde ++] = 0x00; // Grids offset relative to GPS start of week LLSB (Uint32_t) en ms Not used...
cde[lg_cde ++] = 0x00; // Acquiisition retry period LSB (Uint32_t)
cde[lg_cde ++] = 0x00; // Acquiisition retry period MSB (Uint32_t)
cde[lg_cde ++] = 0x00; // Acquiisition retry period MMSB (Uint32_t)
cde[lg_cde ++] = 0x05; // Ontime - time to stay in TRACKING State LSB (uint16_t) en s
cde[lg_cde ++] = 0x00; // Ontime - time to stay in TRACKING State MSB (uint16_t) en s
cde[lg_cde ++] = 0x05; // Minimal search time LSB (uint16_t) en s
cde[lg_cde ++] = 0x00; // Minimal search time MSB (uint16_t)
for (i = 0; i < 20; i ++) cde[lg_cde ++] = 0; // Reserved
if (g_bus_down_commande_libre(G_COMMANDE_CLASSE_CFG, G_COMMANDE_UBX_CFG_PM2, cde, lg_cde, M_BUS_PROTOCOLE_NORMAL, 0, -1) == 0) affichage_debug(__FILE__, __LINE__, "Le mode de pilotage du GNSS a ét configuré ", TYPE_MESSAGE_DEBUG_PAR_DEFAUT);
else affichage_debug(__FILE__, __LINE__, "La configuration du mode de pilotage du GNSS a échoué", TYPE_MESSAGE_DEBUG_ERREUR);
*/
//----------------------------------------------
// Commande de configuration du Power Mode :
//----------------------------------------------
// Cf Page 242 : 32.10.24.1 Power Mode Setup
lg_cde = 0;
cde[lg_cde ++] = 0; // Version (0x00 for this version)
cde[lg_cde ++] = 0x03; // Power setup value : 0x00 = Full power, 0x01 = Balanced, 0x02 = Interval, 0x03 = Aggressive with 1 Hz, 0x04 = Aggressive with 2 Hz, 0x05 = Aggressive with 4 Hz, 0xFF = Invalid (only when polling)
cde[lg_cde ++] = 0x00; // LSB Position update period and search period (en secondes). Recommended minimum period is 10 s, although the receiver accepts any value bigger than 5 s. Only valid when powerSetupValue set to Interval, otherwise must be set to '0'.
cde[lg_cde ++] = 0x00; // MSB ...
cde[lg_cde ++] = 0x00; // LSB Duration of the ON phase, must be smaller than the period. Only valid when powerSetupValue set to Interval, otherwise must be set to '0'.
cde[lg_cde ++] = 0x00; // MSB ...
for (i = 0; i < 2; i ++) cde[lg_cde ++] = 0; // Reserved
if (g_bus_down_commande_libre(G_COMMANDE_CLASSE_CFG, G_COMMANDE_UBX_CFG_PMS, cde, lg_cde, M_BUS_PROTOCOLE_NORMAL, 0, -1) == 0) affichage_debug(__FILE__, __LINE__, "Le mode de pilotage du GNSS a été configuré ", TYPE_MESSAGE_DEBUG_PAR_DEFAUT);
else affichage_debug(__FILE__, __LINE__, "La configuration du mode de pilotage du GNSS a échoué", TYPE_MESSAGE_DEBUG_ERREUR);
gnss.sequenceur.compteur = GNSS_TEMPO_ATTENTE_FIN_INIT;
gnss.sequenceur.etat = ETAT_SEQUENCEUR_GNSS_REPOS;
}
break;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
case ETAT_SEQUENCEUR_GNSS_REPOS :
//----------------------------------------------------------------------------------------------------------------------------------------------------------
{
if (gnss.sequenceur.compteur == 0)
{
gnss.sequenceur.compteur = GNSS_PERIODE_MESURES;
//----------------------------------------------
// Commande de lecture de la position :
//----------------------------------------------
lg_cde = 0;
if (g_bus_down_commande_libre(G_COMMANDE_CLASSE_NAV, G_COMMANDE_UBX_NAV_PVT, cde, lg_cde, M_BUS_PROTOCOLE_NORMAL, G_BUS_TIME_OUT_COMMANDE_UBX_NAV_PVT, -1) == 0) ;//affichage_debug(__FILE__, __LINE__, "La commande de lecture de la position GNSS a été effectuée avec succés", TYPE_MESSAGE_DEBUG_PAR_DEFAUT);
else affichage_debug(__FILE__, __LINE__, "La commande de lecture de la position GNSS a échoué", TYPE_MESSAGE_DEBUG_ERREUR);
}
break;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
default :
//----------------------------------------------------------------------------------------------------------------------------------------------------------
{
sprintf(tmp, "L'état du séquenceur GNSS est inconnu [%i]. Il est repositionné au REPOS", gnss.sequenceur.etat);
affichage_debug(__FILE__, __LINE__, tmp, TYPE_MESSAGE_DEBUG_ERREUR);
gnss.sequenceur.etat = ETAT_SEQUENCEUR_GNSS_REPOS;
break;
}
}
}