Exemplo n.º 1
0
int16_t parse_cmd_ntp_status(char *cmd, char *output, uint16_t len)
{
    uint32_t last_sync = clock_last_sync();
    int16_t  last_delta = clock_last_delta();
    uint16_t ntp_timer = clock_last_ntp();
    uint16_t dcf_counter = clock_dcf_count();
    uint16_t ntp_counter = clock_ntp_count();
    return ECMD_FINAL(snprintf_P(output,len,PSTR("Update:%lu\ndelta:%d\nOCR1A:%u\nDCF/NTP:%d/%d\nResyn:%d"), last_sync, last_delta, OCR1A, dcf_counter, ntp_counter, ntp_timer));
}
Exemplo n.º 2
0
int16_t parse_cmd_ntp_status(char *cmd, char *output, uint16_t len)
{
    /* trick: use bytes on cmd as "connection specific static variables" */
    if (cmd[0] != ECMD_STATE_MAGIC) {	/* indicator flag: real invocation:  0 */
	cmd[0] = ECMD_STATE_MAGIC;	/*                 continuing call: 23 */
	cmd[1] = 0;			/* counter for output lines */
    }
    else {
	cmd[1]++;	/* iterate to next output line */
    }

    enum {
	CNT_UPDATE = 0,
	CNT_DELTA,
	CNT_OCR1A,
	CNT_DCFNTP,
	CNT_RESYN,
	CNT_LAST = CNT_RESYN
    };

    switch (cmd[1]) {
	case CNT_UPDATE:
	    return ECMD_AGAIN(snprintf_P(output, len, PSTR("Update:  %lu"),
					 clock_last_sync()));
	case CNT_DELTA:
	    return ECMD_AGAIN(snprintf_P(output, len, PSTR("Delta:   %+d"),
					 clock_last_delta()));
	case CNT_OCR1A:
	    return ECMD_AGAIN(snprintf_P(output, len, PSTR("OCR1A:   %u"), TC1_COUNTER_COMPARE));
	case CNT_DCFNTP:
	    return ECMD_AGAIN(snprintf_P(output, len, PSTR("DCF/NTP: %u/%u"),
					 clock_dcf_count(), clock_ntp_count()));
	case CNT_RESYN:
	    return ECMD_FINAL(snprintf_P(output, len, PSTR("Resync:  %u"),
					 clock_last_ntp()));
    }
    return ECMD_FINAL_OK;	/* never reached */
}