Commit 0b4996ec authored by Aurelio Colosimo's avatar Aurelio Colosimo

diagnostic macros defined and used to substitute old DBG/DBGV

The 'FIXME: diag' issues still needs to be uncommented
parent 93aa0cfa
...@@ -18,6 +18,8 @@ void posix_main_loop(struct pp_instance *ppi) ...@@ -18,6 +18,8 @@ void posix_main_loop(struct pp_instance *ppi)
{ {
int delay_ms; int delay_ms;
pp_diag_verbosity = 1;
set_TimeInternal(&ppi->last_rcv_time, 0, 0); set_TimeInternal(&ppi->last_rcv_time, 0, 0);
/* /*
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <pptp/diag.h> #include <pptp/diag.h>
#include "posix.h" #include "posix.h"
int pp_diag_verbosity = 0;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct pp_instance *ppi; struct pp_instance *ppi;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#ifndef __PTP_DIAG_H__ #ifndef __PTP_DIAG_H__
#define __PTP_DIAG_H__ #define __PTP_DIAG_H__
#include <pptp/pptp.h>
/* /*
* The diagnostic functions (diag-yes.c and diag-no.c). * The diagnostic functions (diag-yes.c and diag-no.c).
* *
...@@ -28,22 +29,4 @@ extern int pp_vprintf(const char *fmt, va_list args) ...@@ -28,22 +29,4 @@ extern int pp_vprintf(const char *fmt, va_list args)
extern int pp_vsprintf(char *buf, const char *, va_list) extern int pp_vsprintf(char *buf, const char *, va_list)
__attribute__ ((format (printf, 2, 0))); __attribute__ ((format (printf, 2, 0)));
/*
* Temporarily, define DBGV. I should get __attribute__((deprecated))
* at some point, and then disappear over time.
*/
static inline void DBGV(const char *msg) /* most DBGV are constant strings */
{
pp_printf("%s", msg);
}
static inline void DBGV_ARGS(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
pp_vprintf(fmt, args);
va_end(args);
}
#endif /* __PTP_DIAG_H__ */ #endif /* __PTP_DIAG_H__ */
...@@ -12,6 +12,17 @@ ...@@ -12,6 +12,17 @@
#include <pptp/ieee1588_types.h> #include <pptp/ieee1588_types.h>
#include <pptp/constants.h> #include <pptp/constants.h>
/* Macros for diagnostic prints. Set pp_diag_verbosity as 0 or 1 (PP_V macros
* disabled/enabled) */
extern int pp_diag_verbosity;
#define PP_FSM(ppi,seq,len) pp_diag_fsm(ppi,seq,len)
#define PP_VFSM(ppi,seq,len) if (pp_diag_verbosity) pp_diag_fsm(ppi,seq,len)
#define PP_VTR(ppi,f,l) if (pp_diag_verbosity) pp_diag_trace(ppi,f,l)
#define PP_ERR(ppi,err) if pp_diag_error(ppi,err)
#define PP_ERR2(ppi,s1,s2) if pp_diag_error_str2(ppi,s1,s2)
#define PP_FATAL(ppi,s1,s2) if pp_diag_fatal(ppi,s1,s2)
#define PP_PRINTF(...) pp_printf(__VA_ARGS__)
#define PP_VPRINTF(...) if (pp_diag_verbosity) pp_printf(__VA_ARGS__)
/* /*
* Runtime options. Default values can be overridden by command line. * Runtime options. Default values can be overridden by command line.
......
...@@ -117,7 +117,7 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -117,7 +117,7 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
short comp = 0; short comp = 0;
Octet *ppci; Octet *ppci;
DBGV("Data set comparison\n"); PP_VPRINTF("BMC: in bmc_dataset_cmp\n");
/* Identity comparison */ /* Identity comparison */
if (!pp_memcmp(ann_a->grandmasterIdentity, if (!pp_memcmp(ann_a->grandmasterIdentity,
...@@ -266,29 +266,26 @@ UInteger8 bmc_state_decision( struct pp_instance *ppi, ...@@ -266,29 +266,26 @@ UInteger8 bmc_state_decision( struct pp_instance *ppi,
hdr, ann); hdr, ann);
if (DSDEF(ppi)->clockQuality.clockClass < 128) { if (DSDEF(ppi)->clockQuality.clockClass < 128) {
if (cmpres < 0) { if (cmpres < 0) {
m1(ppi); m1(ppi);
return PPS_MASTER; return PPS_MASTER;
} else if (cmpres > 0) { } else if (cmpres > 0) {
s1(ppi, hdr, ann); s1(ppi, hdr, ann);
return PPS_PASSIVE; return PPS_PASSIVE;
} else {
/* FIXME DBG("Error in bmcDataSetComparison..\n"); */
} }
} else { } else {
if (cmpres < 0) { if (cmpres < 0) {
m1(ppi); m1(ppi);
return PPS_MASTER; return PPS_MASTER;
} else if (cmpres > 0) { } else if (cmpres > 0) {
s1(ppi, hdr, ann); s1(ppi, hdr, ann);
return PPS_SLAVE; return PPS_SLAVE;
} else {
/* FIXME DBG("Error in bmcDataSetComparison..\n"); */
} }
}
if (cmpres == 0) {
PP_PRINTF("Error in bmcDataSetComparison.\n");
} }
/* MB: Is this the return code below correct? */ /* MB: Is this the return code below correct? */
...@@ -317,7 +314,7 @@ UInteger8 bmc(struct pp_instance *ppi, struct pp_frgn_master *frgn_master, ...@@ -317,7 +314,7 @@ UInteger8 bmc(struct pp_instance *ppi, struct pp_frgn_master *frgn_master,
&frgn_master[best].ann) < 0) &frgn_master[best].ann) < 0)
best = i; best = i;
DBGV_ARGS("Best record : %d\n", best); PP_VPRINTF("bmc, best record : %d\n", best);
ppi->foreign_record_best = best; ppi->foreign_record_best = best;
return bmc_state_decision(ppi, &frgn_master[best].hdr, return bmc_state_decision(ppi, &frgn_master[best].hdr,
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
int st_com_execute_slave(struct pp_instance *ppi) int st_com_execute_slave(struct pp_instance *ppi)
{ {
if (pp_timer_expired(ppi->timers[PP_TIMER_ANN_RECEIPT])) { if (pp_timer_expired(ppi->timers[PP_TIMER_ANN_RECEIPT])) {
DBGV("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n"); PP_VPRINTF("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n");
ppi->number_foreign_records = 0; ppi->number_foreign_records = 0;
ppi->foreign_record_i = 0; ppi->foreign_record_i = 0;
if (!DSDEF(ppi)->slaveOnly && if (!DSDEF(ppi)->slaveOnly &&
...@@ -25,13 +25,13 @@ int st_com_execute_slave(struct pp_instance *ppi) ...@@ -25,13 +25,13 @@ int st_com_execute_slave(struct pp_instance *ppi)
if (ppi->rt_opts->e2e_mode) { if (ppi->rt_opts->e2e_mode) {
if (pp_timer_expired(ppi->timers[PP_TIMER_DELAYREQ])) { if (pp_timer_expired(ppi->timers[PP_TIMER_DELAYREQ])) {
DBGV("TODO: event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n"); PP_VPRINTF("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
return msg_issue_delay_req(ppi); return msg_issue_delay_req(ppi);
} }
} else { } else {
if (pp_timer_expired(ppi->timers[PP_TIMER_PDELAYREQ])) if (pp_timer_expired(ppi->timers[PP_TIMER_PDELAYREQ]))
{ {
DBGV("TODO: event PDELAYREQ_INTERVAL_TOUT_EXPIRES\n"); PP_VPRINTF("event PDELAYREQ_INTERVAL_TOUT_EXPIRES\n");
return msg_issue_pdelay_req(ppi); return msg_issue_pdelay_req(ppi);
} }
} }
...@@ -52,7 +52,7 @@ void st_com_restart_annrec_timer(struct pp_instance *ppi) ...@@ -52,7 +52,7 @@ void st_com_restart_annrec_timer(struct pp_instance *ppi)
int st_com_check_record_update(struct pp_instance *ppi) int st_com_check_record_update(struct pp_instance *ppi)
{ {
if (ppi->record_update) { if (ppi->record_update) {
DBGV("event STATE_DECISION_EVENT\n"); PP_VPRINTF("event STATE_DECISION_EVENT\n");
ppi->record_update = FALSE; ppi->record_update = FALSE;
ppi->next_state = bmc(ppi, ppi->frgn_master, ppi->rt_opts); ppi->next_state = bmc(ppi, ppi->frgn_master, ppi->rt_opts);
...@@ -83,7 +83,8 @@ void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf) ...@@ -83,7 +83,8 @@ void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
*/ */
ppi->frgn_master[j].ann_messages++; ppi->frgn_master[j].ann_messages++;
found = 1; found = 1;
DBGV("addForeign : AnnounceMessage incremented \n"); PP_VPRINTF("st_com_add_foreign: ann_messages: %d\n",
ppi->frgn_master[j].ann_messages);
msg_copy_header(&ppi->frgn_master[j].hdr, hdr); msg_copy_header(&ppi->frgn_master[j].hdr, hdr);
msg_unpack_announce(buf, &ppi->frgn_master[j].ann); msg_unpack_announce(buf, &ppi->frgn_master[j].ann);
...@@ -121,7 +122,7 @@ void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf) ...@@ -121,7 +122,7 @@ void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
msg_unpack_announce(buf, &ppi->frgn_master[j].ann); msg_unpack_announce(buf, &ppi->frgn_master[j].ann);
DBGV("New foreign Master added \n"); PP_VPRINTF("New foreign Master added \n");
ppi->foreign_record_i = (ppi->foreign_record_i+1) % ppi->foreign_record_i = (ppi->foreign_record_i+1) %
ppi->max_foreign_records; ppi->max_foreign_records;
...@@ -230,17 +231,17 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf, ...@@ -230,17 +231,17 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
return -1; return -1;
if (!ppi->is_from_cur_par) { if (!ppi->is_from_cur_par) {
DBGV("SequenceID doesn't match last Sync message\n"); PP_VPRINTF("SequenceID doesn't match last Sync message\n");
return 0; return 0;
} }
if (!ppi->waiting_for_follow) { if (!ppi->waiting_for_follow) {
DBGV("Slave was not waiting a follow up message\n"); PP_VPRINTF("Slave was not waiting a follow up message\n");
return 0; return 0;
} }
if (ppi->recv_sync_sequence_id != hdr->sequenceId) { if (ppi->recv_sync_sequence_id != hdr->sequenceId) {
DBGV("Follow up message is not from current parent\n"); PP_VPRINTF("Follow up message is not from current parent\n");
return 0; return 0;
} }
...@@ -305,11 +306,11 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf, ...@@ -305,11 +306,11 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
return -1; return -1;
if (ppi->is_from_self) { if (ppi->is_from_self) {
DBGV("HandleAnnounce : Ignore message from self\n"); PP_VPRINTF("master handle_announce: ignore msg from self\n");
return 0; return 0;
} }
DBGV("Announce message from another foreign master\n"); PP_VPRINTF("Announce message from another foreign master\n");
st_com_add_foreign(ppi, buf); st_com_add_foreign(ppi, buf);
......
...@@ -33,7 +33,10 @@ int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv) ...@@ -33,7 +33,10 @@ int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv)
/* TODO: Check how to parse cmdline. We can not rely on getopt() /* TODO: Check how to parse cmdline. We can not rely on getopt()
* function. Which are the really useful parameters? * function. Which are the really useful parameters?
* Every parameter should be contained in ppi->rt_opts and set here * Every parameter should be contained in ppi->rt_opts and set here
* Temporarly set verbosity to 1 (for test), but it should be read
* from the command line.
*/ */
pp_diag_verbosity = 1;
return 0; return 0;
} }
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
*/ */
#include <pptp/pptp.h> #include <pptp/pptp.h>
#include <pptp/diag.h>
void pp_init_clock(struct pp_instance *ppi) void pp_init_clock(struct pp_instance *ppi)
{ {
/* FIXME diag DBG("initClock\n"); */ PP_PRINTF("SERVO init clock\n");
/* clear vars */ /* clear vars */
set_TimeInternal(&SRV(ppi)->m_to_s_dly, 0, 0); set_TimeInternal(&SRV(ppi)->m_to_s_dly, 0, 0);
......
...@@ -117,8 +117,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -117,8 +117,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
hdr->logMessageInterval; hdr->logMessageInterval;
} else { } else {
DBGV("TODO: HandledelayResp : " PP_VPRINTF("pp_slave : "
"delayResp doesn't match delayReq.\n"); "Delay Resp doesn't match Delay Req\n");
} }
break; break;
...@@ -190,8 +190,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -190,8 +190,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
pp_update_peer_delay(ppi,& correction_field, 0); pp_update_peer_delay(ppi,& correction_field, 0);
} }
} else { } else {
DBGV("TODO: HandlePdelayResp : Pdelayresp doesn't " PP_VPRINTF("pp_slave : PDelay Resp doesn't "
"match PdelayReq.\n"); "match PDelay Req.\n");
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment