]> rtime.felk.cvut.cz Git - can-benchmark.git/commitdiff
Detect received messages with invalid index to msg_info table
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 17 Dec 2010 15:57:37 +0000 (16:57 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 17 Dec 2010 15:57:37 +0000 (16:57 +0100)
latester/latester.c

index bdd539c2ebebdafaf4609a5ded90607998e8d1ef..b7bb38b49bea7489d0bbe3a08d060155dc6e98d0 100644 (file)
@@ -83,6 +83,7 @@ struct {
        unsigned lost;
        struct timespec tic, tac;
        unsigned timeouts;
        unsigned lost;
        struct timespec tic, tac;
        unsigned timeouts;
+       unsigned invalid_frame;
 } stats;
 
 int num_interfaces = 0;
 } stats;
 
 int num_interfaces = 0;
@@ -334,11 +335,16 @@ static inline void trace_off(int ret)
                write(trace_fd, "0", 1);
 }
 
                write(trace_fd, "0", 1);
 }
 
-void msg_info_free(struct msg_info *mi)
+static inline void msg_info_free(struct msg_info *mi)
 {
        mi->id = -1;
 }
 
 {
        mi->id = -1;
 }
 
+static inline bool msg_info_used(struct msg_info *mi)
+{
+       return mi->id != -1;
+}
+
 int send_frame(int socket)
 {
        struct can_frame frame;
 int send_frame(int socket)
 {
        struct can_frame frame;
@@ -350,7 +356,7 @@ int send_frame(int socket)
 
        MEMSET_ZERO(frame);
        i = curr_msg+1;
 
        MEMSET_ZERO(frame);
        i = curr_msg+1;
-       while (msg_infos[i].id != -1 && i != curr_msg) {
+       while (msg_info_used(&msg_infos[i]) && i != curr_msg) {
                i++;
                if (i >= MAX_INFOS)
                        i = 0;
                i++;
                if (i >= MAX_INFOS)
                        i = 0;
@@ -479,8 +485,11 @@ void process_on_wire_rx(int s)
        struct msg_info *mi;
        receive(s, &frame, &ts_kern, &ts_user);
        mi = frame2info(&frame);
        struct msg_info *mi;
        receive(s, &frame, &ts_kern, &ts_user);
        mi = frame2info(&frame);
-       mi->ts_rx_onwire_kern = ts_kern;
-       mi->ts_rx_onwire = ts_user;
+       if (msg_info_used(mi)) {
+               mi->ts_rx_onwire_kern = ts_kern;
+               mi->ts_rx_onwire = ts_user;
+       } else
+               stats.invalid_frame++;
 }
 
 
 }
 
 
@@ -809,6 +818,9 @@ int main(int argc, const char *argv[])
        fprintf(opt.f_stat, "timeouts=%d\n", stats.timeouts);
        if (stats.timeouts && !opt.quiet)
                printf("timeouts=%d\n", stats.timeouts);
        fprintf(opt.f_stat, "timeouts=%d\n", stats.timeouts);
        if (stats.timeouts && !opt.quiet)
                printf("timeouts=%d\n", stats.timeouts);
+       fprintf(opt.f_stat, "invalid_frame=%d\n", stats.timeouts);
+       if (stats.timeouts && !opt.quiet)
+               printf("invalid_frame=%d\n", stats.timeouts);
 
        fclose(opt.f_stat);
 
 
        fclose(opt.f_stat);