Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

how to unpack MACRO

Hello,

Could you help me to unpack this MACRO? It's hard to understand how it works, and it is impossible to debug!

here they are: SH_SENS_CHANNEL_CONFIG_DEF(...); SH_SENS_PROFILE_CONFIG_DEF(...); SH_SENS_CHANNEL_CONFIG(...); SH_SENS_PROFILE_CONFIG(...);

#define HRM_SENS_CHANNEL_CONFIG_DEF(NAME,					\
	CHANNEL_NUMBER,		\
	TRANSMISSION_TYPE,	\
	DEVICE_NUMBER,		\
	NETWORK_NUMBER)		\
	static const ant_channel_config_t   CONCAT_2(NAME,_channel_hrm_sens_config)={	\
	.channel_number    = (CHANNEL_NUMBER),			\
	.channel_type      = HRM_SENS_CHANNEL_TYPE,	\
	.ext_assign        = HRM_EXT_ASSIGN,				\
	.rf_freq           = HRM_ANTPLUS_RF_FREQ,		\
	.transmission_type = (TRANSMISSION_TYPE),		\
	.device_type       = HRM_DEVICE_TYPE,			\
	.device_number     = (DEVICE_NUMBER),			\
	.channel_period    = HRM_MSG_PERIOD_4Hz,		\
	.network_number    = (NETWORK_NUMBER),			\
}

#define HRM_SENS_PROFILE_CONFIG_DEF(NAME,								\
	PAGE_1_PRESENT,					\
	MAIN_PAGE_NUMBER,				\
	EVT_HANDLER)						\
static ant_hrm_sens_cb_t            CONCAT_2(NAME,_hrm_sens_cb);	\
static const ant_hrm_sens_config_t  CONCAT_2(NAME,_profile_hrm_sens_config) ={	\
	.page_1_present     = (PAGE_1_PRESENT),				\
	.main_page_number   = (MAIN_PAGE_NUMBER),				\
	.p_cb               = &CONCAT_2(NAME,_hrm_sens_cb),	\
	.evt_handler        = (EVT_HANDLER),					\
}

#define HRM_SENS_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME,_channel_hrm_sens_config)
#define HRM_SENS_PROFILE_CONFIG(NAME) &CONCAT_2(NAME,_profile_hrm_sens_config)

static ant_hrm_profile_t m_ant_hrm;
static void ant_hrm_evt_handler( ant_hrm_profile_t *p_profile, ant_hrm_evt_t event );	// forward declaration
HRM_SENS_CHANNEL_CONFIG_DEF( m_ant_hrm, HRM_CHANNEL_NUM, CHAN_ID_TRANS_TYPE, CHAN_ID_DEV_NUM, ANTPLUS_NETWORK_NUM );
HRM_SENS_PROFILE_CONFIG_DEF( m_ant_hrm, true, ANT_HRM_PAGE_0, ant_hrm_evt_handler );

void foo( void ) {
	ret_code_t err_code;
		err_code = ant_hrm_sens_init( &m_ant_hrm,
										  HRM_SENS_CHANNEL_CONFIG( m_ant_hrm ),
										  HRM_SENS_PROFILE_CONFIG( m_ant_hrm ) );
	APP_ERROR_CHECK( err_code );
return;

Thanks!

Parents Reply Children
  • Hi,

    I will not be doing this manually, but if you use the macro and check in a debugger you will see the result, and then you will know how it looks and can change it on your end. If for instance you want to look at the ant_channel_config_t that is made by HRM_SENS_CHANNEL_CONFIG_DEF, check this in the debugger and you will see everything (of course you also have this type definition from the header file to start with, and nest form there). That is my advice. You are of course also free to work your way from the macro definitions. I understand that this is a bit tedious work, but unfortunately it is up to you.

    Edit: you can also observe the preprocessor output if that is easier. For instance, if using GCC you can add use the -save-temps option.

Related