Can we connect to the DR through TCP instead of UDP?
Posted: Thu 26. Jul 2018, 03:34
I was able to communicate to the PCAN Ethernet DR using UDP, but can we do the same with TCP instead?
Support, Knowledge Base, and FAQ
https://forum.peak-system.com/
Code: Select all
/*******************************************************************************
local function prototypes
******************************************************************************/
static void print_usage(char *name);
static void print_args(void);
static void printSWinfo(char *name, S_SW_VERSION_INFO *p_info);
static int init_application(void);
static void exit_application(void);
static void signal_handler(int s);
static int handle_loc_cmd(int fd);
int priv_openSocketOut(int port, char* p_ip, int type);
int priv_closeSocket(int sock);
static void init_outgoing_data_socket(void);
Code: Select all
//------------------------------------------------------------------------------
// static int handle_loc_cmd(int fd)
//------------------------------------------------------------------------------
//! @brief handles commands from given file descriptor
//------------------------------------------------------------------------------
//! @param ind file descriptor to read from
//------------------------------------------------------------------------------
//! @return <0 in case of errors or any return value from called command handler
//------------------------------------------------------------------------------
static int handle_loc_cmd(int fd){
char cmdbuf[MAX_LOC_CMD_LEN+1];
int len=0, i=0;
if (fd != STDIN_FILENO) /* not STDIN_FILENO */
return -1;
len = read(fd, &cmdbuf[len], MAX_LOC_CMD_LEN - len);
if (verbose > 3) {
printf("got %d chars:\n ", len);
for (i = 0; i < len; i++)
printf("%0x2 ", cmdbuf[i]);
}
if (len == 0) {
if (verbose > 1)
printf("%s(): nothing to read on %d\n", __func__, fd);
return -2;
} else if (len == MAX_LOC_CMD_LEN) {
if (verbose > 1) {
printf("%s(): maybe more then %d chars to read on %d\n", __func__,
MAX_LOC_CMD_LEN, fd);
return -1;
}
}
cmdbuf[len] = 0;
if (verbose > 3)
printf("%s(): cmd line=%s\n", __func__, cmdbuf);
i = 0;
while (loc_cmds[i].cmd_text) {
if (strstr(cmdbuf, loc_cmds[i].cmd_text))
break;
else
i++;
}
if (!loc_cmds[i].cmd_text) {
if (verbose > 2)
printf("%s(): no such command found: %s\n", __func__, cmdbuf);
return -3;
}
if (!loc_cmds[i].cmd_handler) {
if (verbose > 2)
printf("%s(): no handler defined for command: %s\n", __func__,
cmdbuf);
return -4;
}
return loc_cmds[i].cmd_handler(&cmdbuf[strlen(loc_cmds[i].cmd_text)]);
}