From cc86923abd3557c3cea8bb525c89401d0adda4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiesner=20Andr=C3=A1s?= Date: Sun, 16 Apr 2023 22:53:03 +0200 Subject: [PATCH] residual code errors fixed --- clock_utils.c | 26 ++++++++++++++++++++++++++ clock_utils.h | 1 + ptp_core.c | 6 +++--- ptp_msg_tx.c | 4 ++-- ptp_msg_tx.h | 2 +- settings_interface.c | 5 +++++ settings_interface.h | 1 + task_ptp.c | 2 +- 8 files changed, 40 insertions(+), 7 deletions(-) diff --git a/clock_utils.c b/clock_utils.c index 606b671..12d5295 100644 --- a/clock_utils.c +++ b/clock_utils.c @@ -32,3 +32,29 @@ void ptp_create_clock_identity() ptp_print_clock_identity(S.hwoptions.clockIdentity); MSG("\n"); } + +// convert string clock id to 64-bit number +uint64_t hextoclkid(const char *str) +{ + size_t len = strlen(str); + uint64_t clkid = 0; + for (size_t i = 0; i < len; i++) { + char digit = tolower(str[i]); + if (digit >= '0' && digit <= '9') { + digit = digit - '0'; + } else if (digit >= 'a' && digit <= 'f') { + digit = digit - 'a' + 10; + } else { + break; + } + + clkid += (uint64_t) digit *((uint64_t) 1 << (4 * i)); + } + uint8_t *p = NULL; + for (size_t i = 0; i < 8; i++) { + p = ((uint8_t *) & clkid) + i; + *p = ((*p & 0x0F) << 4) | ((*p & 0xF0) >> 4); + } + + return clkid; +} diff --git a/clock_utils.h b/clock_utils.h index c9b59dc..f13d7f6 100644 --- a/clock_utils.h +++ b/clock_utils.h @@ -4,6 +4,7 @@ #include void ptp_print_clock_identity(uint64_t clockID); // print clock identity +uint64_t hextoclkid(const char *str); // convert hexadecimal string to 64-bit clock id void ptp_create_clock_identity(); // create clock identity based on MAC address diff --git a/ptp_core.c b/ptp_core.c index 71cfcd6..ab91445 100644 --- a/ptp_core.c +++ b/ptp_core.c @@ -85,10 +85,10 @@ void ptp_delete_timers() // initialize Delay_Req header void ptp_init_delay_req_header() { - sDelayReqHeader.messageType = S.profile.delayMechanism == PTP_DM_E2E ? PTP_MT_Delay_Req : PTP_MT_PDelay_Req; + sDelayReqHeader.messageType = PTP_MT_Delay_Req; sDelayReqHeader.transportSpecific = (uint8_t) S.profile.transportSpecific; sDelayReqHeader.versionPTP = 2; // PTPv2 - sDelayReqHeader.messageLength = PTP_HEADER_LENGTH + PTP_TIMESTAMP_LENGTH + (S.profile.delayMechanism == PTP_DM_P2P ? PTP_TIMESTAMP_LENGTH : 0); + sDelayReqHeader.messageLength = PTP_HEADER_LENGTH + PTP_TIMESTAMP_LENGTH; sDelayReqHeader.domainNumber = S.profile.domainNumber; ptp_clear_flags(&(sDelayReqHeader.flags)); // no flags sDelayReqHeader.correction_ns = 0; @@ -98,7 +98,7 @@ void ptp_init_delay_req_header() sDelayReqHeader.sourcePortID = 1; // TODO? No more ports... sDelayReqHeader.sequenceID = 0; // will change in every sync cycle - sDelayReqHeader.control = S.profile.delayMechanism == PTP_DM_E2E ? PTP_CON_Delay_Req : PTP_CON_Other; + sDelayReqHeader.control = PTP_CON_Delay_Req; sDelayReqHeader.logMessagePeriod = 0; } diff --git a/ptp_msg_tx.c b/ptp_msg_tx.c index cfd8506..99d55ca 100644 --- a/ptp_msg_tx.c +++ b/ptp_msg_tx.c @@ -18,9 +18,9 @@ static struct { static const uint16_t sPortLut[2] = { PTP_PORT_EVENT, PTP_PORT_GENERAL }; static ip4_addr_t sIpLut[2] = { 0 }; -static const uint8_t *sEthLut[2] = { PTP_ETHERNET_PRIMARY, PTP_ETHERNET_PEER_DELAY }; +static const uint8_t *sEthLut[2] = { PTP_ETHERNET_PRIMARY }; -void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG,) +void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG) { sPcbLut.pPri_Ev = pPriE; sPcbLut.pPri_Gen = pPriG; diff --git a/ptp_msg_tx.h b/ptp_msg_tx.h index bf01dee..0f97ab6 100644 --- a/ptp_msg_tx.h +++ b/ptp_msg_tx.h @@ -3,7 +3,7 @@ #include "ptp_types.h" -void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG,); // initialize PTP transmitter +void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG); // initialize PTP transmitter void ptp_transmit_msg(RawPtpMessage * pMsg); // transmit PTP message bool ptp_transmit_enqueue(const RawPtpMessage * pMsg); // enqueue message TODO: refactor... diff --git a/settings_interface.c b/settings_interface.c index 21e0f6f..560e602 100644 --- a/settings_interface.c +++ b/settings_interface.c @@ -58,6 +58,11 @@ uint32_t ptp_get_addend() return S.hwclock.addend; } +PtpTransportType ptp_get_transport_type() +{ + return S.profile.transportType; +} + void ptp_time(TimestampU * pT) { PTP_HW_GET_TIME(pT); diff --git a/settings_interface.h b/settings_interface.h index 17c9d32..7018758 100644 --- a/settings_interface.h +++ b/settings_interface.h @@ -15,6 +15,7 @@ void ptp_set_domain(uint8_t domain); // set PTP domain uint8_t ptp_get_domain(); // get PTP domain void ptp_set_addend(uint32_t addend); // set hardware clock addend (frequency tuning!) uint32_t ptp_get_addend(); // get hardware clock addend +PtpTransportType ptp_get_transport_type(); // get PTP transport type void ptp_time(TimestampU * pT); // get time diff --git a/task_ptp.c b/task_ptp.c index 6808ec5..af63543 100644 --- a/task_ptp.c +++ b/task_ptp.c @@ -126,7 +126,7 @@ void reg_task_ptp() join_ptp_igmp_groups(); // enter PTP IGMP groups create_ptp_listeners(); // create listeners #ifndef SIMULATION - ptp_transmit_init(spPTP_PRIMARY_EVENT_pcb, spPTP_PRIMARY_GENERAL_pcb,); // initialize transmit function*/ + ptp_transmit_init(spPTP_PRIMARY_EVENT_pcb, spPTP_PRIMARY_GENERAL_pcb); // initialize transmit function*/ #endif // create task