diff options
Diffstat (limited to 'mbglib/common/extiohlp.c')
-rw-r--r-- | mbglib/common/extiohlp.c | 275 |
1 files changed, 275 insertions, 0 deletions
diff --git a/mbglib/common/extiohlp.c b/mbglib/common/extiohlp.c new file mode 100644 index 0000000..8fa84c6 --- /dev/null +++ b/mbglib/common/extiohlp.c @@ -0,0 +1,275 @@ + +/************************************************************************** + * + * $Id: extiohlp.c 1.3.1.4.1.2 2015/01/21 13:24:44 marvin TEST $ + * + * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany + * + * Description: + * Device configuration helper functions. This is an extension to + * mbgextio.c providing useful functions to simplify reading/writing + * complex device configuration structure sets. + * + * Warning: + * These functions should not be implemented in a DLL / shared library + * since the parameter sizes might vary with different versions + * of the API calls, which which would make different versions of + * precompiled libraries incompatible to each other. + * + * ----------------------------------------------------------------------- + * $Log: extiohlp.c $ + * Revision 1.3.1.4.1.2 2015/01/21 13:24:44 marvin + * Added XBP Adress specifier to mbgextio functions. + * Revision 1.3.1.4.1.1 2014/10/31 12:04:45Z martin + * Started to support XBP addressing. + * Revision 1.3.1.4 2014/10/30 14:50:00 martin + * Generally return Meinberg error codes only. + * Updated doxygen stuff. + * Updated function prototypes. + * Revision 1.3.1.3 2013/12/19 09:20:12 martin + * Revision 1.3.1.2 2013/12/17 14:57:48Z martin + * Revision 1.3.1.1 2013/09/25 11:10:49Z marvin + * Added function for all_ptp_cfg_info. + * Revision 1.3 2013/02/01 15:49:59Z martin + * Updated doxygen comments. + * Cleanup. + * Revision 1.2 2012/03/09 08:32:58Z martin + * Cleanup. + * Revision 1.1 2011/09/21 15:59:59 martin + * Initial revision. + * + **************************************************************************/ + +#define _EXTIOHLP + #include <extiohlp.h> +#undef _EXTIOHLP + +#include <mbggeo.h> + + + +/*HDR*/ +/** + * @brief Read all serial port settings and supported configuration parameters + * + * @note The function mbgextio_setup_receiver_info() must have been called before, + * and the returned ::RECEIVER_INFO has to be passed to this function. + * + * The complementary function mbgextio_save_serial_settings() should + * be used to write a modified port configuration back to the device. + * + * @param pmctl Pointer to a valid message control structure + * @param p_addr Pointer to XBP address specifier + * @param p_cfg Pointer to a ::RECEIVER_PORT_CFG structure to be set up + * @param p_ri Pointer to a valid ::RECEIVER_INFO structure + * + * @return One of the @ref MBG_RETURN_CODES + * + * @see ::mbgextio_save_serial_settings + * @see ::mbgextio_get_receiver_info + */ +int mbgextio_get_serial_settings( MBG_MSG_CTL *pmctl, XBP_ADDR *p_addr, + RECEIVER_PORT_CFG *p_cfg, const RECEIVER_INFO *p_ri ) +{ + int rc = 0; + + memset( p_cfg, 0, sizeof( *p_cfg ) ); + + if ( p_ri->model_code != GPS_MODEL_UNKNOWN ) + { + rc = mbgextio_get_all_port_info( pmctl, p_addr, p_cfg->pii, p_ri ); + + if ( rc != MBG_SUCCESS ) + goto out; + + rc = mbgextio_get_all_str_type_info( pmctl, p_addr, p_cfg->stii, p_ri ); + } + else + { + #if 0 // TODO ##+++++++ provide some symbols + uint16_t i; + + rc = mbgextio_get_port_parm( pmctl, p_addr, &p_cfg->tmp_pp ); + + if ( rc != MBG_SUCCESS ) + goto out; + + for ( i = 0; i < p_ri->n_com_ports; i++ ) + { + PORT_INFO_IDX *p_pii = &p_cfg->pii[i]; + PORT_INFO *p_pi = &p_pii->port_info; + + p_pii->idx = i; + port_settings_from_port_parm( &p_pi->port_settings, + i, &p_cfg->tmp_pp, 1 ); + + p_pi->supp_baud_rates = DEFAULT_GPS_BAUD_RATES_C166; + p_pi->supp_framings = DEFAULT_GPS_FRAMINGS_C166; + p_pi->supp_str_types = DEFAULT_SUPP_STR_TYPES_GPS; + } + + for ( i = 0; i < p_ri->n_str_type; i++ ) + { + STR_TYPE_INFO_IDX *stip = &p_cfg->stii[i]; + stip->idx = i; + stip->str_type_info = default_str_type_info[i]; + } + + rc = MBG_SUCCESS; + #endif + } + +out: + return rc; + +} // mbgextio_get_serial_settings + + + +/*HDR*/ +/** + * @brief Send the configuration settings for a single serial port to a device + * + * @note The function mbgextio_setup_receiver_info() must have been called before, + * and the returned ::RECEIVER_INFO has to be passed to this function as well as + * to mbgextio_get_serial_settings() which should have been called before to read + * the current settings and supported features for each port. + * + * @param pmctl Pointer to a valid message control structure + * @param p_addr Pointer to XBP address specifier + * @param pcfg Pointer to a ::RECEIVER_PORT_CFG structure + * @param port_idx Index of the serial port to be saved + * + * @return One of the @ref MBG_RETURN_CODES + * + * @see ::mbgextio_get_serial_settings + * @see ::mbgextio_get_receiver_info + */ +int mbgextio_save_serial_settings( MBG_MSG_CTL *pmctl, XBP_ADDR *p_addr, + const RECEIVER_PORT_CFG *pcfg, uint16_t port_idx ) +{ + int rc; + + rc = mbgextio_set_port_settings_idx( pmctl, p_addr, + &pcfg->pii[port_idx].port_info.port_settings, port_idx ); + + return rc; //##++ MBG_SUCCESS or < 0 on error + +} // mbgextio_save_serial_settings + + + +/*HDR*/ +/** + * @brief Read all PTP configuration in ::ALL_PTP_CFG_INFO format + * + * @note Only supported if ::GPS_HAS_PTP + * + * @param pmctl Pointer to a valid message control structure + * @param p_addr Pointer to XBP address specifier + * @param p Pointer to the data structure to return the received data + * + * @return One of the @ref MBG_RETURN_CODES + * + * @see //##++++++++++++++++++++++++++++++ + * @see ::mbgextio_get_receiver_info + */ +_NO_MBG_API_ATTR int _MBG_API mbgextio_get_all_ptp_cfg_info( MBG_MSG_CTL *pmctl, + XBP_ADDR *p_addr, + ALL_PTP_CFG_INFO *p ) +{ + int rc = mbgextio_get_ptp_cfg_info( pmctl, p_addr, &p->ptp_cfg_info ); + + if ( rc != MBG_SUCCESS ) + goto out; + + if ( p->ptp_cfg_info.supp_flags & PTP_CFG_MSK_SUPPORT_PTP_UNICAST ) + { + rc = mbgextio_get_ptp_uc_master_cfg_limits( pmctl, p_addr, + &p->ptp_uc_master_cfg_limits ); + + if ( rc != MBG_SUCCESS ) + goto out; + + if ( p->ptp_uc_master_cfg_limits.n_supp_master > MAX_PARM_PTP_UC_MASTER ) + { + // The number of PTP unicast masters supported by this device + // exceeds the number of unicast masters supporterd by this driver. + rc = MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP; + goto out; + } + + rc = mbgextio_get_all_ptp_uc_master_info( pmctl, p_addr, + p->all_ptp_uc_master_info_idx, &p->ptp_uc_master_cfg_limits ); + + if ( rc != MBG_SUCCESS ) + goto out; + } + +out: + return rc; + +} // mbgextio_get_all_ptp_cfg_info + + +//#warning mbgextio_save_all_ptp_cfg_settings missing + + +/*HDR*/ +/** + * @brief Convert a mathematical angle [rad] to a geographic angle [degree, minute, second] + * + * @note This has been copied from mbggeo.c, so mbggeo.h should + * provide the same prototype. + */ +void rad_to_dms( const double *rad, DMS *dms, const char prefix ) +{ + static const double r2d = 180.0 / PI; + + double r; + + if ( prefix == 'E' ) + dms->prefix = ( *rad < 0.0 ) ? 'W' : 'E'; + else + dms->prefix = ( *rad < 0.0 ) ? 'S' : 'N'; + + r = *rad * r2d; + + if ( r < 0 ) + r = -r; + + dms->deg = (int) r; + + r -= dms->deg; + r *= 60; + + dms->min = (int) r; + + r -= dms->min; + r *= 60; + + dms->sec = r; + +} /* rad_to_dms */ + + + +/*HDR*/ +/** + * @brief Convert mathematic coords to to geographic coords + * + * Mathematic coords are (longitude, latitude in [rad]), geographic coords + * are (longitude, latitude in [degree, minute, second]) + * + * @note This has been copied from mbggeo.c, so mbggeo.h should + * provide the same prototype. + */ +void lla_to_dms( POS *pos ) +{ + rad_to_dms( &pos->lla[LON], &pos->longitude, 'E' ); + rad_to_dms( &pos->lla[LAT], &pos->latitude, 'N' ); + +} /* lla_to_dms */ + + + |