Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gen4] support built-in GNSS in NCP client. #2733

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hal-dynalib/src/hal_gnss.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "hal_platform.h"

#if HAL_PLATFORM_GNSS
#include "hal_dynalib_gnss.h"
#endif // HAL_PLATFORM_GNSS

38 changes: 38 additions & 0 deletions hal/inc/gnss_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GNSS_HAL_H
#define GNSS_HAL_H

#include "hal_platform.h"

#ifdef __cplusplus
extern "C" {
#endif

#if HAL_PLATFORM_GNSS

int hal_gnss_init(void* reserved);
int hal_gnss_pos(void* reserved);

#endif // HAL_PLATFORM_GNSS

#ifdef __cplusplus
}
#endif

#endif /* GNSS_HAL_H */
43 changes: 43 additions & 0 deletions hal/inc/hal_dynalib_gnss.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "hal_platform.h"
#include "dynalib.h"

#if HAL_PLATFORM_GNSS

#ifdef DYNALIB_EXPORT
#include "gnss_hal.h"
#endif

// WARNING
// The order of functions must not be changed or older applications will break
// when used with newer system firmware.
// Function signatures shouldn't be changed other than changing pointer types.
// New HAL functions must be added to the end of this list.
// GNINRAW

DYNALIB_BEGIN(hal_gnss)

DYNALIB_FN(0, hal_gnss, hal_gnss_init, int(void*))
DYNALIB_FN(1, hal_gnss, hal_gnss_pos, int(void*))

DYNALIB_END(hal_gnss)

#endif // HAL_PLATFORM_GNSS
8 changes: 8 additions & 0 deletions hal/inc/hal_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,12 @@
#define HAL_PLATFORM_AUTOMATIC_CONNECTION_MANAGEMENT (0)
#endif // HAL_PLATFORM_AUTOMATIC_CONNECTION_MANAGEMENT

#ifndef HAL_PLATFORM_GNSS
#define HAL_PLATFORM_GNSS (0)
#endif // HAL_PLATFORM_GNSS

#ifndef HAL_PLATFORM_GPS_ONE_XTRA
#define HAL_PLATFORM_GPS_ONE_XTRA (0)
#endif // HAL_PLATFORM_GPS_ONE_XTRA

#endif /* HAL_PLATFORM_H */
60 changes: 60 additions & 0 deletions hal/network/ncp/gnss/gnss_hal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHAN'TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include "check.h"
#include "delay_hal.h"
#include "service_debug.h"
#include "logging.h"
#include "gnss_hal.h"

#if HAL_PLATFORM_GNSS

#include "network/ncp/cellular/cellular_network_manager.h"
#include "network/ncp/cellular/cellular_ncp_client.h"
#include "network/ncp/cellular/ncp.h"
#include "network/ncp_client/quectel/quectel_ncp_client.h"

using namespace particle;

// Just for testing purposes
int hal_gnss_init(void* reserved) {
const auto mgr = cellularNetworkManager();
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
const auto client = reinterpret_cast<QuectelNcpClient*>(mgr->ncpClient());
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);

GnssNcpClientConfig config = {};
config.enableGpsOneXtra(true);
client->gnssConfig(config);
client->gnssOn();
client->acquireNmeaSentences(GNSS_NMEA_TYPE_GNS, nullptr, 0);

return 0;
}

int hal_gnss_pos(void* reserved) {
const auto mgr = cellularNetworkManager();
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
const auto client = reinterpret_cast<QuectelNcpClient*>(mgr->ncpClient());
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);

GnssPositioningInfo info = {};
client->acquirePositioningInfo(&info);
return 0;
}

#endif // HAL_PLATFORM_GNSS
100 changes: 100 additions & 0 deletions hal/network/ncp/gnss/gnss_ncp_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2024 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "time.h"
#include "ncp_client.h"
#include "hal_platform.h"

#if HAL_PLATFORM_GNSS

namespace particle {

enum GnssState {
GNSS_STATE_DISABLED = 0,
GNSS_STATE_INIT = 1,
GNSS_STATE_ON = 2,
GNSS_STATE_OFF = 3,
GNSS_STATE_MAX = 4
};

enum GnssNmeaType {
GNSS_NMEA_TYPE_GGA = 0,
GNSS_NMEA_TYPE_RMC = 1,
GNSS_NMEA_TYPE_GSV = 2,
GNSS_NMEA_TYPE_GSA = 3,
GNSS_NMEA_TYPE_VTG = 4,
GNSS_NMEA_TYPE_GNS = 5,
GNSS_NMEA_TYPE_MAX = 6
};

struct GnssPositioningInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add error estimates and DOPs

uint16_t version;
uint16_t size;
double latitude;
double longitude;
float accuracy;
float altitude;
float cog;
float speedKmph;
float speedKnots;
struct tm utcTime;
int satsInView;
bool locked;
int posMode;
};

class GnssNcpClientConfig {
public:
GnssNcpClientConfig()
: enableGpsOneXtra_(false) {
}

GnssNcpClientConfig& enableGpsOneXtra(bool enable) {
enableGpsOneXtra_ = enable;
return *this;
}

bool isGpsOneXtraEnabled() const {
return enableGpsOneXtra_;
}

private:
bool enableGpsOneXtra_;
};

class GnssNcpClient {
public:
virtual int gnssConfig(const GnssNcpClientConfig& conf) = 0;
virtual int gnssOn() = 0;
virtual int gnssOff() = 0;
virtual int acquirePositioningInfo(GnssPositioningInfo* info) = 0;
virtual int acquireNmeaSentences(GnssNmeaType type, char* buf, size_t len) = 0;
virtual uint32_t getTtff() = 0;
virtual GnssState gnssState() = 0;

#if HAL_PLATFORM_GPS_ONE_XTRA
virtual int injectGpsOneXtraTimeAndData(const uint8_t* buf, size_t size) = 0;
virtual bool isGpsOneXtraEnabled() = 0;
virtual bool isGpsOneXtraDataValid() = 0;
#endif // HAL_PLATFORM_GPS_ONE_XTRA
};

} // particle

#endif // HAL_PLATFORM_GNSS
Loading