Skip to content

Commit

Permalink
Add timestamp disabling on exit and some other minor things
Browse files Browse the repository at this point in the history
Signed-off-by: Casper Andersson <[email protected]>
  • Loading branch information
cappe987 committed Mar 7, 2024
1 parent e40063c commit ad5f626
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,40 @@ add_custom_target(test
# ============= Configure ===============
configure_file(include/version.h.in include/version.h)


#project(tcalign VERSION 1.0)
##set(PROJECT_NAME_VERSION "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}")


## ---- PROJECT SETUP ----
##set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wpedantic -Wextra")

## ---- BUILD ----
#find_library (LIBNL_LIBRARY nl-3)
#find_library (LIBNL_GENL_LIBRARY nl-genl-3)

#set(LIBNL_LIBRARIES ${LIBNL_LIBRARY} ${LIBNL_GENL_LIBRARY})
#set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

##set(CMAKE_C_FLAGS
##"${CMAKE_C_FLAGS} -Wall -Wpedantic -Wextra"
##)

#find_path (LIBNL_INCLUDE_DIR NAMES netlink/netlink.h PATH_SUFFIXES libnl3)
#include_directories(include ${LIBNL_INCLUDE_DIR})




#add_executable(tcalign)
#target_sources(tcalign PRIVATE src/tcalign.c)

#install(TARGETS tcalign
#CONFIGURATIONS Debug
#RUNTIME DESTINATION bin)
#install(TARGETS tcalign
#CONFIGURATIONS Release
#RUNTIME DESTINATION bin)

#target_link_libraries(tcalign PUBLIC gpiod ${LIBNL_LIBRARIES})

1 change: 1 addition & 0 deletions include/timestamping.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static unsigned char p2p_dst_mac[] = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E };
int sk_receive(int fd, void *buf, int buflen, struct address *addr, struct hw_timestamp *hwts,
int flags);
int raw_send(int fd, enum transport_event event, void *buf, int len, struct hw_timestamp *hwts);
int sk_timestamping_destroy(int fd, const char *device);
int sk_timestamping_init(int fd, const char *device, enum timestamp_type type,
enum transport_type transport, int vclock);
//int socket_init_raw(char *interface);
Expand Down
6 changes: 3 additions & 3 deletions src/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/* TODO:
* - Implement mmedian_sample delay filter (ptp4l delay_filter)
* - Implement E2E
* - Set twoStepFlag correctly
*/

Expand Down Expand Up @@ -342,9 +342,9 @@ int delay_parse_opt(int argc, char **argv, struct delay_cfg *cfg)
case 'v':
if (optarg == NULL)
printf("bad version input\n");
else if (strncmp(optarg, "2.1", 3) == 0)
else if (strncmp(optarg, "2.1", 3) == 0 && strlen(optarg) == 3)
cfg->version = 2 | (1 << 4);
else if (strncmp(optarg, "2", 1) == 0)
else if (strncmp(optarg, "2", 1) == 0 && strlen(optarg) == 1)
cfg->version = 2;
else
printf("bad version input\n");
Expand Down
15 changes: 14 additions & 1 deletion src/pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <getopt.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>

#include "net_tstamp_cpy.h"

Expand All @@ -18,6 +19,8 @@
*
*/

int pkt_running = 1;

#ifndef SO_TIMESTAMPING
#define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING
Expand Down Expand Up @@ -81,12 +84,18 @@ Options:\n\
-c <frame counts>. Set to 0 to send until stopped\n\
-l <0|1>. 0: Never fetch timestamp. 1: Always fetch timestamp (even for types that might not have)\n\
-d Enable debug output\n\
-v <2|2.1> PTP version of the packet\n\
-h help\n\
--transportSpecific <value>. Set value for the transportSpecific field\n\
--twoStepFlag <0|1>. Force if twoStepFlag should be set or not. Default is automatic\n\
\n");
}

static void sig_handler(int sig)
{
pkt_running = 0;
}

void set_two_step_flag(struct pkt_cfg *cfg, struct ptp_header *hdr, int type)
{
int twoStepFlag = 0x00;
Expand Down Expand Up @@ -199,7 +208,7 @@ int rx_mode(struct pkt_cfg *cfg, int sock, struct hw_timestamp *hwts)

rx_msg = (union Message *)buf;

while (1) {
while (pkt_running) {
sk_receive(sock, rx_msg, 1600, NULL, hwts, 0);
printf("Type: %s. ", ptp_type2str(rx_msg->hdr.tsmt & 0xF));
print_ts("TS: ", hwts->ts.ns);
Expand Down Expand Up @@ -353,6 +362,8 @@ int run_pkt_mode(int argc, char **argv)
/*return EINVAL;*/
/*}*/

signal(SIGINT, sig_handler);

if (!cfg.count)
cfg.nonstop_flag = 1;

Expand All @@ -379,5 +390,7 @@ int run_pkt_mode(int argc, char **argv)
else
tx_mode(&cfg, sock, &hwts);

sk_timestamping_destroy(sock, cfg.interface);

return 0;
}
5 changes: 5 additions & 0 deletions src/timestamping.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ int raw_send(int fd, enum transport_event event, void *buf, int len, struct hw_t
return event == TRANS_EVENT ? sk_receive(fd, pkt, len, NULL, hwts, MSG_ERRQUEUE) : cnt;
}

int sk_timestamping_destroy(int fd, const char *device)
{
return hwts_init(fd, device, 0, 0, HWTSTAMP_TX_OFF);
}

int sk_timestamping_init(int fd, const char *device, enum timestamp_type type,
enum transport_type transport, int vclock)
{
Expand Down

0 comments on commit ad5f626

Please sign in to comment.