static int cmd_time(const char *args[]) { uint64_t sec; uint32_t nsec; shw_pps_gen_get_time(&sec, &nsec); if (args[2] && !strcasecmp(args[0], "set")) { if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) { shw_pps_gen_set_time((uint64_t) atoi(args[1]), atoi(args[2]), PPSG_SET_ALL); return 0; } else return -EBUSY; } else if (args[0] && !strcasecmp(args[0], "setsec")) { if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) { shw_pps_gen_set_time((int64_t) atoi(args[1]), 0, PPSG_SET_SEC); return 0; } } else if (args[0] && !strcasecmp(args[0], "setnsec")) { if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) { shw_pps_gen_set_time(0, atoi(args[1]), PPSG_SET_NSEC); return 0; } } else if (args[0] && !strcasecmp(args[0], "raw")) { mprintf("%d %d\n", (uint32_t) sec, nsec); return 0; } mprintf("%s +%d nanoseconds.\n", format_time(sec), nsec); /* fixme: clock freq is not always 125 MHz */ return 0; }
/* syslog: a tx-only socket: no queue is there */ static struct wrpc_socket __static_syslog_socket = { .queue.buff = NULL, .queue.size = 0, }; static struct wrpc_socket *syslog_socket; static struct wr_udp_addr syslog_addr; unsigned char syslog_mac[6]; static uint32_t tics, tics_zero; void syslog_init(void) { syslog_socket = ptpd_netif_create_socket(&__static_syslog_socket, NULL, PTPD_SOCK_UDP, 514 /* time */); syslog_addr.sport = syslog_addr.dport = htons(514); tics_zero = timer_get_tics(); } static int cmd_syslog(const char *args[]) { char b1[32], b2[32]; if (args[0] && !strcmp(args[0], "off")) { syslog_addr.daddr = 0; return 0; } if (!args[1]) { pp_printf("use: syslog <ipaddr> <macaddr> (or just \"off\"\n"); return -1; } decode_ip(args[0], (void *)&syslog_addr.daddr); decode_mac(args[1], syslog_mac); pp_printf("Syslog parameters: %s, %s\n", format_ip(b1, (void *)&syslog_addr.daddr), format_mac(b2, syslog_mac)); tics = 0; /* send the first frame immediately to the new host */ return 0; } DEFINE_WRC_COMMAND(syslog) = { .name = "syslog", .exec = cmd_syslog, }; #define SYSLOG_DEFAULT_LEVEL 14 /* 8 == user + 6 ==info */ static int syslog_header(char *buf, int level, unsigned char ip[4]) { uint64_t secs; char b[32]; int len; shw_pps_gen_get_time(&secs, NULL); getIP(ip); len = pp_sprintf(buf + UDP_END, "<%i> %s %s ", level, format_time(secs, TIME_FORMAT_SYSLOG), format_ip(b, ip)); return len + UDP_END; }