/* * Timeout, - if we don't send something to the ECU it will timeout * soon, so send it a keepalive message now. */ static void diag_l2_proto_vag_timeout(struct diag_l2_conn *d_l2_conn) { //struct diag_l2_vag *dp; struct diag_msg msg= {0}; uint8_t data[256]; /* int rv;*/ //dp = (struct diag_l2_vag *)d_l2_conn->diag_l2_proto_data; //not used? if (diag_l2_debug & DIAG_DEBUG_TIMER) { fprintf(stderr, FLFMT "timeout impending for %p\n", FL, (void *)d_l2_conn); } msg.data = data; /* * There is no point in checking for errors, or checking * the received response as we cant pass an error back * from here */ /* Send it, important to use l2_send as it updates the timers */ (void)diag_l2_send(d_l2_conn, &msg); /* Get the response in p2max, we use p3min to be more flexible */ (void)diag_l2_recv(d_l2_conn, d_l2_conn->diag_l2_p3min, NULL, NULL); }
//cmd_watch : this creates a diag_l3_conn //TODO: "press any key to stop" ... static int cmd_watch(int argc, char **argv) { int rv; struct diag_l2_conn *d_l2_conn; struct diag_l3_conn *d_l3_conn=NULL; struct diag_l0_device *dl0d; int rawmode = 0; int nodecode = 0; int nol3 = 0; if (argc > 1) { if (strcasecmp(argv[1], "raw") == 0) rawmode = 1; else if (strcasecmp(argv[1], "nodecode") == 0) nodecode = 1; else if (strcasecmp(argv[1], "nol3") == 0) nol3 = 1; else { printf("Don't understand \"%s\"\n", argv[1]); return CMD_USAGE; } } rv = diag_init(); if (rv != 0) { fprintf(stderr, "diag_init failed\n"); diag_end(); return CMD_FAILED; } dl0d = diag_l2_open(l0_names[set_interface_idx].longname, set_subinterface, global_cfg.L1proto); if (dl0d == NULL) { rv = diag_geterr(); printf("Failed to open hardware interface, "); if (rv == DIAG_ERR_PROTO_NOTSUPP) printf("does not support requested L1 protocol\n"); else if (rv == DIAG_ERR_BADIFADAPTER) printf("adapter probably not connected\n"); else printf("%s\n",diag_errlookup(rv)); return CMD_FAILED; } if (rawmode) { d_l2_conn = diag_l2_StartCommunications(dl0d, DIAG_L2_PROT_RAW, 0, global_cfg.speed, global_cfg.tgt, global_cfg.src); } else { d_l2_conn = diag_l2_StartCommunications(dl0d, global_cfg.L2proto, DIAG_L2_TYPE_MONINIT, global_cfg.speed, global_cfg.tgt, global_cfg.src); } if (d_l2_conn == NULL) { printf("Failed to connect to hardware in monitor mode\n"); diag_l2_close(dl0d); return CMD_FAILED; } //here we have a valid d_l2_conn over dl0d. if (rawmode == 0) { /* Put the SAE J1979 stack on top of the ISO device */ if (nol3 == 0) { d_l3_conn = diag_l3_start("SAEJ1979", d_l2_conn); if (d_l3_conn == NULL) { printf("Failed to enable SAEJ1979 mode\n"); diag_l2_StopCommunications(d_l2_conn); diag_l2_close(dl0d); return CMD_FAILED; } } else { d_l3_conn = NULL; } printf("Waiting for data to be received\n"); while (1) { if (d_l3_conn != NULL) { rv = diag_l3_recv(d_l3_conn, 10000, j1979_watch_rcv, (nodecode) ? NULL:(void *)d_l3_conn); } else { rv = diag_l2_recv(d_l2_conn, 10000, j1979_watch_rcv, NULL); } if (rv == 0) continue; if (rv == DIAG_ERR_TIMEOUT) continue; } } else { //rawmode !=0 here /* * And just read stuff, callback routine will print out the data */ printf("Waiting for data to be received\n"); while (1) { rv = diag_l2_recv(d_l2_conn, 10000, j1979_data_rcv, (void *)&_RQST_HANDLE_WATCH); if (rv == 0) continue; if (rv == DIAG_ERR_TIMEOUT) continue; printf("recv returns %d\n", rv); break; } } if (d_l3_conn != NULL) diag_l3_stop(d_l3_conn); diag_l2_StopCommunications(d_l2_conn); diag_l2_close(dl0d); return CMD_OK; }
/* * Timeout, - if we don't send something to the ECU it will timeout * soon, so send it a keepalive message now. */ static void diag_l2_proto_14230_timeout(struct diag_l2_conn *d_l2_conn) { struct diag_l2_14230 *dp; struct diag_msg msg={0}; uint8_t data[256]; unsigned int timeout; int debug_l2_orig=diag_l2_debug; //save debug flags; disable them for this procedure int debug_l1_orig=diag_l1_debug; int debug_l0_orig=diag_l0_debug; dp = (struct diag_l2_14230 *)d_l2_conn->diag_l2_proto_data; /* XXX fprintf not async-signal-safe */ if (diag_l2_debug & DIAG_DEBUG_TIMER) { fprintf(stderr, FLFMT "\ntimeout impending for dl2c=%pd\n", FL, (void *)d_l2_conn); } diag_l2_debug=0; //disable diag_l1_debug=0; diag_l0_debug=0; msg.data = data; /* Prepare the "keepalive" message */ if (dp->modeflags & ISO14230_IDLE_J1978) { /* Idle using J1978 / J1979 keep alive message : SID 1 PID 0 */ msg.len = 2; data[0] = 1; data[1] = 0; } else { /* Idle using ISO "Tester Present" message */ msg.len = 1; msg.dest = 0; /* Use default */ msg.src = 0; /* Use default */ data[0] = DIAG_KW2K_SI_TP; } /* * There is no point in checking for errors, or checking * the received response as we can't pass an error back * from here * TODO: we could at least if NEGRESP was received and warn the user... */ /* Send it, important to use l2_send as it updates the timers */ (void)diag_l2_send(d_l2_conn, &msg); /* * Get the response in p2max, we allow longer, and even * longer on "smart" L2 interfaces */ timeout = d_l2_conn->diag_l2_p2max; if (d_l2_conn->diag_link->l1flags & DIAG_L1_DOESL2FRAME) { if (timeout < SMART_TIMEOUT) timeout += SMART_TIMEOUT; } (void)diag_l2_recv(d_l2_conn, timeout, NULL, NULL); diag_l2_debug=debug_l2_orig; //restore debug flags diag_l1_debug=debug_l1_orig; diag_l0_debug=debug_l0_orig; }