This class provides an API to communicate with a u-blox GNSS chip. The files here were originally part of the C027_Support library (https://developer.mbed.org/teams/ublox/code/C027_Support/ at revision 138:dafbbf31bf76) but have been separated out, primarily for use on the u-blox C030 board where the cellular interace portion of the C027_Support library will instead be provided through the new mbed Cellular API.
Dependents: example-ublox-at-cellular-interface-ext example-low-power-sleep example-C030-out-of-box-demo example-C030-out-of-box-demo ... more
Revision 12:a04f7eeece23, committed 2018-05-31
- Comitter:
- Bilal Qamar
- Date:
- Thu May 31 10:59:11 2018 +0500
- Parent:
- 11:514ea8bf1dc8
- Child:
- 13:10108cd3ad23
- Commit message:
- GNSS Operations class added
Changed in this revision
--- a/gnss.cpp Tue May 29 15:17:31 2018 +0500 +++ b/gnss.cpp Thu May 31 10:59:11 2018 +0500 @@ -295,54 +295,7 @@ conf = conf - 1; } } - if(conf == 0) - { - return 1; - } - - unsigned char enable_ubx_nav_pvt[]={0x01, 0x07, 0x01}; - conf = RETRY; - while(conf) - { - - length = sendUbx(0x06, 0x01, enable_ubx_nav_pvt, sizeof(enable_ubx_nav_pvt)); - if(length >= (int)(sizeof(enable_ubx_nav_pvt) + UBX_FRAME_SIZE)) - { - wait(5); - break; - } - else - { - conf = conf - 1; - } - } - if(conf == 0) - { - return 1; - } - - unsigned char ubx_cfg_cfg[] = { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}; - conf = RETRY; - while(conf) - { - length = sendUbx(0x06, 0x09, ubx_cfg_cfg, sizeof(ubx_cfg_cfg)); - if(length >= (int)(sizeof(ubx_cfg_cfg) + UBX_FRAME_SIZE)) - { - wait(5); - break; - } - else - { - conf = conf - 1; - } - } - if(conf == 0) - { - return 1; - } - - return 0; + return (conf == 0) ? 0 : 1; } eUBX_MESSAGE GnssParser::get_ubx_message(char *buff) {
--- a/gnss.h Tue May 29 15:17:31 2018 +0500 +++ b/gnss.h Thu May 31 10:59:11 2018 +0500 @@ -94,8 +94,8 @@ uint8_t flags; uint32_t bufSize; uint32_t notifThrs; - uint8_tpioId; - uint8_treserved1; + uint8_t pioId; + uint8_t reserved1; }tUBX_CFG_BATCH; @@ -216,7 +216,7 @@ /** Enable UBX messages. * @param none - * @return 0 if successful, false otherwise. + * @return 1 if successful, false otherwise. */ int enable_ubx();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnss_operations.cpp Thu May 31 10:59:11 2018 +0500 @@ -0,0 +1,407 @@ +#include "gnss_operations.h" + +#define FIRST_BYTE 0x000000FF +#define SECOND_BYTE 0x0000FF00 +#define THIRD_BYTE 0x00FF0000 +#define FOURTH_BYTE 0xFF000000 +#define RETRY 5 + +#define EXTRACT_BYTE(INDEX, BYTE, VALUE) ((VALUE & BYTE) >> (INDEX*8)) + +/** + * + * Enable UBX-NAV-PVT using UBX-CFG-MSG + * @param return SUCCESS: 1 + * FAILURE: 0 + */ +int GnssOperations::enable_ubx_nav_pvt() +{ + int conf = RETRY; + unsigned char enable_ubx_nav_pvt[]={0x01, 0x07, 0x01}; + conf = RETRY; + int length =0; + + while(conf) + { + + length = GnssSerial::sendUbx(0x06, 0x01, enable_ubx_nav_pvt, sizeof(enable_ubx_nav_pvt)); + if(length >= (int)(sizeof(enable_ubx_nav_pvt) + UBX_FRAME_SIZE)) + { + printf("UBX-NAV-PVT was enabled\r\n"); + printf("\r\nmessage length: %i\r\n\r\n", length); + wait(5); + break; + } + else + { + printf("enabling UBX-NAV-PVT...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} + +/** + * + * Disable UBX-NAV-PVT + * @param return SUCCESS: 1 + * FAILURE: 0 + */ +int GnssOperations::disable_ubx_nav_pvt() +{ + int conf = RETRY; + unsigned char enable_ubx_nav_pvt[]={0x01, 0x07, 0x00}; + conf = RETRY; + int length =0; + + while(conf) + { + + length = GnssSerial::sendUbx(0x06, 0x01, enable_ubx_nav_pvt, sizeof(enable_ubx_nav_pvt)); + if(length >= (int)(sizeof(enable_ubx_nav_pvt) + UBX_FRAME_SIZE)) + { + printf("UBX-NAV-PVT was disabled\r\n"); + printf("\r\nmessage length: %i\r\n\r\n", length); + wait(5); + break; + } + else + { + printf("disabling UBX-NAV-PVT...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} + +int GnssOperations::enable_ubx_nav5(unsigned int acc) +{ + int conf = RETRY; + conf = RETRY; + int length =0; + //convert unsigned int acc to hex + //ask if positioning mask or time accuracy mask + unsigned char ubx_cfg_nav5[]={0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, EXTRACT_BYTE(0, FIRST_BYTE, acc), EXTRACT_BYTE(1, SECOND_BYTE, acc), + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00}; + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x24, ubx_cfg_nav5, sizeof(ubx_cfg_nav5)); + if(length >= (int)(sizeof(ubx_cfg_nav5) + UBX_FRAME_SIZE)) + { + printf("ubx_cfg_nav5 was enabled\r\n"); + wait(5); + break; + } + else + { + printf("enabling ubx_cfg_nav5...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} + +/** + * Enabling UBX-ODOMETER using UBX-CFG-ODO + * @param return SUCCESS: 1 + * FAILURE: 0 + * + */ +int GnssOperations::enable_ubx_odo() +{ + int conf = RETRY; + unsigned char ubx_cfg_odo[]={0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x19, 0x46, 0x19, 0x66, 0x0A, 0x32, 0x00, + 0x00, 0x99, 0x4C, 0x00, 0x00}; + conf = RETRY; + int length =0; + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x1E, ubx_cfg_odo, sizeof(ubx_cfg_odo)); + if(length >= (int)(sizeof(ubx_cfg_odo) + UBX_FRAME_SIZE)) + { + printf("UBX-ODO was enabled\r\n"); + wait(5); + break; + } + else + { + printf("enabling UBX-ODO...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} + +int GnssOperations::disable_ubx_odo() +{ + int conf = RETRY; + unsigned char ubx_cfg_odo[]={0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x19, 0x46, 0x19, 0x66, 0x0A, 0x32, 0x00, + 0x00, 0x99, 0x4C, 0x00, 0x00}; + conf = RETRY; + int length =0; + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x1E, ubx_cfg_odo, sizeof(ubx_cfg_odo)); + if(length >= (int)(sizeof(ubx_cfg_odo) + UBX_FRAME_SIZE)) + { + printf("UBX-ODO was disabled\r\n"); + wait(5); + break; + } + else + { + printf("disabling UBX-ODO...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} +/** + * Enabling UBX-NAV-ODO messages using UBX-CFG-MSG + * @param return SUCCESS: 1 + * FAILURE: 0 + * + */ +int GnssOperations::enable_ubx_nav_odo() +{ + int conf = RETRY; + unsigned char ubx_nav_odo[]={0x01, 0x09, 0x01}; + conf = RETRY; + int length =0; + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x01, ubx_nav_odo, sizeof(ubx_nav_odo)); + if(length >= (int)(sizeof(ubx_nav_odo) + UBX_FRAME_SIZE)) + { + printf("UBX-NAV-ODO was enabled\r\n"); + wait(5); + break; + } + else + { + printf("enabling UBX-NAV-ODO...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} + +/** + * Disabling UBX-NAV-ODO messages using UBX-CFG-MSG + * @param return SUCCESS: 1 + * FAILURE: 0 + * + */ +int GnssOperations::disable_ubx_nav_odo() +{ + int conf = RETRY; + unsigned char ubx_nav_odo[]={0x01, 0x09, 0x00}; + conf = RETRY; + int length =0; + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x01, ubx_nav_odo, sizeof(ubx_nav_odo)); + if(length >= (int)(sizeof(ubx_nav_odo) + UBX_FRAME_SIZE)) + { + printf("UBX-NAV-ODO was disabled\r\n"); + wait(5); + break; + } + else + { + printf("disabling UBX-NAV-ODO...\r\n"); + conf = conf - 1; + } + } + + return (conf == 0) ? 0 : 1; +} + +int GnssOperations::enable_ubx_batch_feature() +{ + int conf = RETRY; + unsigned char enable_ubx_log_batch[]={0x00, 0x0D, 0x0A, 0x00, 0x07, 0x00, 0x00, 0x01}; + conf = RETRY; + int length =0; + + //Disable NAV-ODO and NAV-PVT + disable_ubx_nav_odo(); + disable_ubx_nav_pvt(); + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x93, enable_ubx_log_batch, sizeof(enable_ubx_log_batch)); + if(length >= (int)(sizeof(enable_ubx_log_batch) + UBX_FRAME_SIZE)) + { + printf("UBX_LOG_BATCH was enabled\r\n"); + wait(5); + break; + } + else + { + printf("enable ubx_batch_log...\r\n"); + conf = conf - 1; + } + } + return (conf == 0) ? 0 : 1; +} + +int GnssOperations::disable_ubx_batch_feature() +{ + int conf = RETRY; + unsigned char enable_ubx_log_batch[]={0x00, 0x0C, 0x0A, 0x00, 0x07, 0x00, 0x00, 0x01}; + conf = RETRY; + int length =0; + + //Enable NAV-ODO and NAV-PVT + enable_ubx_nav_odo(); + enable_ubx_nav_pvt(); + + while(conf) + { + length = GnssSerial::sendUbx(0x06, 0x93, enable_ubx_log_batch, sizeof(enable_ubx_log_batch)); + if(length >= (int)(sizeof(enable_ubx_log_batch) + UBX_FRAME_SIZE)) + { + printf("UBX_LOG_BATCH was enabled\r\n"); + wait(5); + break; + } + else + { + printf("enable ubx_batch_log...\r\n"); + conf = conf - 1; + } + } + return (conf == 0) ? 0 : 1; +} + +/** + * + * Configuring UBX-LOG-BATCH with UBX-CFG-BATCH + * + * @param obj struct containing the data to be send in payload + * @param return SUCCESS: 1 + * FAIL: 0 + * + */ +int GnssOperations::cfg_batch_feature(tUBX_CFG_BATCH *obj) +{ + int length =0; + const unsigned char cfg_batch_feature[] = {0x00, 0x01, EXTRACT_BYTE(0, FIRST_BYTE, obj->bufSize), + EXTRACT_BYTE(1, SECOND_BYTE, obj->bufSize), EXTRACT_BYTE(0, FIRST_BYTE, obj->notifThrs), + EXTRACT_BYTE(1, SECOND_BYTE, obj->notifThrs), obj->pioId, 0x00}; + + length = GnssSerial::sendUbx(0x06, 0x93, cfg_batch_feature, sizeof(cfg_batch_feature)); + + return (length >= (int)(sizeof(cfg_batch_feature) + UBX_FRAME_SIZE)) ? 1 : 0; +} + +/* + * Power mode configuration for GNSS receiver + * + * Pending: Need to send extended power management configuration messages (UBX-CFG-PM2) + * + * + */ +int GnssOperations::cfg_power_mode(int power_mode) +{ + int length = 0; + unsigned char semi_continuous_pms[] = {0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char semi_continuous_pm2[] = {0x02, 0x06, 0x00, 0x00, 0x02, 0x00, 0x43, 0x01, 0x10, 0x27, 0x00, 0x00, 0x10, + 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x2C, 0x01, 0x00, 0x00, 0xCF, 0x40, 0x00, + 0x00, 0x87, 0x5A, 0xA4, 0x46, 0xFE, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char semi_continuous_rate[] = {0xE8, 0x03, 0x01, 0x00, 0x01, 0x00}; + + unsigned char aggresive_continuous_pms[] = {0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char aggresive_continuous_pm2[] = {0x02, 0x06, 0x00, 0x00, 0x02, 0x00, 0x43, 0x01, 0xE8, 0x03, 0x00, 0x00, + 0x10, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x2C, 0x01, 0x00, 0x00, 0xCF, 0x40, + 0x00, 0x00, 0x87, 0x5A, 0xA4, 0x46, 0xFE, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char aggressive_continuous_rate[] = {0xE8, 0x03, 0x01, 0x00, 0x01, 0x00}; + + unsigned char conservative_continuous_pms[] = {0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char conservative_continuous_pm2[] = {0x02, 0x06, 0x00, 0x00, 0x00, 0x00, 0x43, 0x01, 0xE8, 0x03, 0x00, 0x00, + 0x10, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x2C, 0x01, 0x00, 0x00, 0xCF, 0x41, + 0x00, 0x00, 0x88, 0x6A, 0xA4, 0x46, 0xFE, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char conservative_continuous_rate[] = {0xE8, 0x03, 0x01, 0x00, 0x01, 0x00}; + + unsigned char full_power_pms[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char full_power_rate[] = {0x06, 0x00, 0xE8, 0x03, 0x01, 0x00, 0x01, 0x00}; + + switch (power_mode) + { + case SEMI_CONTINOUS: + length = GnssSerial::sendUbx(0x06, 0x86, semi_continuous_pms, sizeof(semi_continuous_pms)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x3B, semi_continuous_pm2, sizeof(semi_continuous_pm2)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x08, semi_continuous_rate, sizeof(semi_continuous_rate)); + break; + + case AGGRESSIVE_CONTINUOS: + length = GnssSerial::sendUbx(0x06, 0x86, aggresive_continuous_pms, sizeof(aggresive_continuous_pms)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x3B, aggresive_continuous_pm2, sizeof(aggresive_continuous_pm2)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x08, aggressive_continuous_rate, sizeof(aggressive_continuous_rate)); + break; + + case CONSERVATIVE_CONTINOUS: + length = GnssSerial::sendUbx(0x06, 0x86, conservative_continuous_pms, sizeof(conservative_continuous_pms)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x3B, conservative_continuous_pm2, sizeof(conservative_continuous_pm2)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x08, conservative_continuous_rate, sizeof(conservative_continuous_rate)); + break; + + case FULL_POWER: + length = GnssSerial::sendUbx(0x06, 0x86, full_power_pms, sizeof(full_power_pms)); + wait(5); + length = GnssSerial::sendUbx(0x06, 0x08, full_power_rate, sizeof(full_power_rate)); + break; + } + return (length >= (int)(sizeof(semi_continuous_pms) + UBX_FRAME_SIZE)) ? 1 : 0; +} + +/** + * GNSS start modes (Hot/Warm/Cold start) + * + * @param return SUCCESS: 1 + * FAILURE: 0 + * + */ +int GnssOperations::start_mode(int start_mode) +{ + int length = 0; + unsigned char hot_start[] = {0x00, 0x00, 0x02, 0x00}; + unsigned char warm_start[] = {0x01, 0x00, 0x02, 0x00}; + unsigned char cold_start[] = {0xFF, 0xFF, 0x02, 0x00}; + + switch (start_mode) + { + case HOT: + length = GnssSerial::sendUbx(0x06, 0x04, hot_start, sizeof(hot_start)); + break; + + case WARM: + length = GnssSerial::sendUbx(0x06, 0x04, warm_start, sizeof(warm_start)); + break; + + case COLD: + length = GnssSerial::sendUbx(0x06, 0x04, cold_start, sizeof(cold_start)); + break; + } + + return (length >= (int)(sizeof(hot_start) + UBX_FRAME_SIZE)) ? 1 : 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnss_operations.h Thu May 31 10:59:11 2018 +0500 @@ -0,0 +1,63 @@ + +#include "gnss.h" + +#define UBX_FRAME_SIZE 8 +#ifdef __cplusplus +extern "C" { +#endif + +/** Enums +*/ + enum Command{ + POWER_ON, + POWER_OFF, + MON_VER, + ENABLE_UBX, + RESTART, // mbed conflict with RESET + CUSTOMER, + AVAILABLE_CONFIG + }; + /** The reset modes + */ + enum Start{ + HOT, + WARM, + COLD, + AMOUNT_MODE + }; + + /** The operation modes + */ + enum Powermodes{ + SEMI_CONTINOUS, + AGGRESSIVE_CONTINUOS, + CONSERVATIVE_CONTINOUS, + FULL_POWER, + AVAILABLE_OPERATION + }; + +class GnssOperations : public GnssSerial{ + + //GnssSerial constructor can be called here to configure different baud rate + //Constructor not required at the moment + //GnssOperations(); + +public: + + int enable_ubx_nav_pvt(); + int disable_ubx_nav_pvt(); + int enable_ubx_nav5(unsigned int acc); + int enable_ubx_odo(); + int disable_ubx_odo(); + int enable_ubx_nav_odo(); + int disable_ubx_nav_odo(); + int enable_ubx_batch_feature(); + int disable_ubx_batch_feature(); + int cfg_batch_feature(tUBX_CFG_BATCH *obj); + int cfg_power_mode(int power_mode); + int start_mode(int start_mode); + +}; +#ifdef __cplusplus +} +#endif