61 #define MAX_RESPONSE_LENGTH 32 63 #define DLT_NODE_CONNECT 1 64 #define DLT_NODE_DISCONNECT 0 65 #define DLT_NODE_CONNECT_UNDEF 999 67 #define DLT_GATEWAY_CONNECTED 2 68 #define DLT_NODE_CONNECTED_STR "Connected" 69 #define DLT_NODE_DISCONNECTED_STR "Disconnected" 108 pr_error(
"Connection status %u invalid\n", s);
117 pr_error(
"node identifier is NULL\n");
137 DltServicePassiveNodeConnectionInfo *info)
147 printf(
"\nPassive Node connection status:\n" 148 "---------------------------------\n");
149 for(i = 0; i < info->num_connections; i++)
160 printf(
"%.4s: %s\n", &info->node_id[i *
DLT_ID_SIZE], status);
184 if (answer ==
NULL || payload ==
NULL)
194 pr_verbose(
"Response received: '%s'\n", answer);
195 pr_verbose(
"Response expected: '%s'\n", resp_ok);
197 if (strncmp(answer, resp_ok, strlen(resp_ok)) == 0)
203 if ((
int)
sizeof(DltServicePassiveNodeConnectionInfo) > len)
205 pr_error(
"Received payload is smaller than expected\n");
207 sizeof(DltServicePassiveNodeConnectionInfo),
213 DltServicePassiveNodeConnectionInfo *info =
214 (DltServicePassiveNodeConnectionInfo *) (payload);
217 fprintf(stderr,
"Received response is NULL\n");
245 mb->
data = calloc(1,
sizeof(DltServicePassiveNodeConnect));
251 mb->
size =
sizeof(DltServicePassiveNodeConnect);
252 DltServicePassiveNodeConnect *serv = (DltServicePassiveNodeConnect *)
261 mb->
data = calloc(1,
sizeof(DltServicePassiveNodeConnectionInfo));
268 mb->
size =
sizeof(DltServicePassiveNodeConnectionInfo);
269 DltServicePassiveNodeConnectionInfo *serv =
270 (DltServicePassiveNodeConnectionInfo *) mb->
data;
282 if (msg_body ==
NULL)
289 free(msg_body->
data);
308 pr_error(
"Failed to initialize connection with the daemon.\n");
316 if (msg_body ==
NULL)
318 pr_error(
"Data for Dlt Message body is NULL\n");
333 printf(
"Usage: dlt-passive-node-ctrl [options]\n");
334 printf(
"Send a trigger to DLT daemon to (dis)connect a passive node " 335 "or get current passive node status \n");
337 printf(
"Options:\n");
338 printf(
" -c Connection status (1 - connect, 0 - disconnect)\n");
339 printf(
" -h Usage\n");
340 printf(
" -n passive Node identifier (e.g. ECU2)\n");
341 printf(
" -s Show passive node(s) connection status\n");
342 printf(
" -t Specify connection timeout (Default: %ds)\n",
344 printf(
" -v Set verbose flag (Default:%d)\n",
get_verbosity());
364 while ((c = getopt(argc, argv,
"c:hn:stv")) != -1)
369 state = (int)strtol(optarg,
NULL, 10);
377 pr_error(
"unknown connection state: %d\n", state);
400 pr_error(
"Unknown option -%c.\n", optopt);
404 pr_error(
"Unknown option character \\x%x.\n", optopt);
409 pr_error(
"Try %s -h for more information.\n", argv[0]);
426 int main(
int argc,
char *argv[])
444 pr_error(
"No valid parameter configuration given!\n");
449 pr_verbose(
"Sending command to DLT daemon.\n");
static int dlt_passive_node_analyze_response(char *answer, void *payload, int len)
Analyze received DLT Daemon response.
void set_verbosity(int v)
void set_connection_state(unsigned int s)
void dlt_passive_node_destroy_message_body(DltControlMsgBody *msg_body)
Destroy message body.
static void dlt_print_passive_node_status(DltServicePassiveNodeConnectionInfo *info)
Print passive node status information.
void set_node_id(char *id)
int dlt_control_deinit(void)
Control communication clean-up.
static struct PassiveNodeOptions g_options
static int parse_args(int argc, char *argv[])
Parse application arguments.
void set_command(unsigned int c)
char node_id[DLT_ID_SIZE]
#define DLT_NODE_DISCONNECT
#define DLT_NODE_CONNECT_UNDEF
#define pr_error(fmt,...)
#define DLT_NODE_DISCONNECTED_STR
unsigned int get_connection_state(void)
int main(int argc, char *argv[])
Entry point.
static int dlt_passive_node_ctrl_single_request()
Send a single command to DLT daemon and wait for response.
#define MAX_RESPONSE_LENGTH
#define DLT_NODE_CONNECTED_STR
int dlt_control_send_message(DltControlMsgBody *body, int timeout)
Send a message to the daemon and wait for the asynchronous answer.
DltControlMsgBody * dlt_passive_node_prepare_message_body()
Prepare message body to be send to DLT Daemon.
#define DLT_GATEWAY_CONNECTED
#define DLT_SERVICE_ID_PASSIVE_NODE_CONNECT
#define pr_verbose(fmt,...)
int dlt_control_init(int(*response_analyzer)(char *, void *, int), char *ecuid, int verbosity)
Control communication initialization.
unsigned int connection_state
#define DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS
unsigned int get_command(void)
void set_ecuid(char *ecuid)