]> rtime.felk.cvut.cz Git - can-benchmark.git/commitdiff
Merge branch 'master' of rtime.felk.cvut.cz:/can-benchmark
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 17 Dec 2010 16:18:32 +0000 (17:18 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 17 Dec 2010 16:18:32 +0000 (17:18 +0100)
1  2 
latester/latester.c

diff --combined latester/latester.c
index e4185b2e9047251d9aa76bbf684cdb19febd58ed,b7bb38b49bea7489d0bbe3a08d060155dc6e98d0..61b2b433f45afe5c20bba5bc5830ff82a99ca83a
@@@ -83,6 -83,7 +83,7 @@@ struct 
        unsigned lost;
        struct timespec tic, tac;
        unsigned timeouts;
+       unsigned invalid_frame;
  } stats;
  
  int num_interfaces = 0;
@@@ -132,7 -133,7 +133,7 @@@ void sprint_canframe(char *buf , struc
                }
  }
  
 -static inline struct msg_info *frame2info(struct can_frame *frame)
 +static inline uint16_t frame_index(struct can_frame *frame)
  {
        uint16_t idx;
        if (frame->can_dlc >= 2) {
  
                error(1, 0, "%s error", __FUNCTION__);
        }
 -      return &msg_infos[idx];
 +      return idx;
 +}
 +
 +static inline struct msg_info *frame2info(struct can_frame *frame)
 +{
 +      return &msg_infos[frame_index(frame)];
  }
  
  static inline char *tstamp_str(const void *ctx, struct timespec *tstamp)
@@@ -339,11 -335,16 +340,16 @@@ static inline void trace_off(int ret
                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;
  }
  
+ static inline bool msg_info_used(struct msg_info *mi)
+ {
+       return mi->id != -1;
+ }
  int send_frame(int socket)
  {
        struct can_frame frame;
  
        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;
@@@ -484,8 -485,11 +490,11 @@@ void process_on_wire_rx(int s
        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++;
  }
  
  
@@@ -602,15 -606,13 +611,15 @@@ void *measure_thread(void *arg
                        }
                        pfd[0].revents = 0;
  
 -                      if (num_interfaces == 3 && pfd[1].revents != 0) {
 +                      if (num_interfaces == 3 && pfd[1].revents & POLLIN) {
                                process_on_wire_rx(pfd[1].fd);
                                pfd[1].revents = 0;
                        }
 +                      if (num_interfaces == 3 && pfd[1].revents & ~POLLIN)
 +                              error(1, 0, "Unexpected pfd[1].revents: 0x%04x\n", pfd[1].revents);
  
                        i = (num_interfaces == 2) ? 1 : 2;
 -                      if (pfd[i].revents != 0) {
 +                      if (pfd[i].revents & POLLIN) {
                                consecutive_timeouts = 0;
                                process_final_rx(pfd[i].fd);
                                msg_in_progress--;
                                        SEND();
                                }
                        }
 +                      if (pfd[i].revents & ~POLLIN)
 +                              error(1, 0, "Unexpected pfd[%d].revents: 0x%04x\n", pfd[i].revents);
                }
        }
  
@@@ -818,6 -818,9 +827,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, "invalid_frame=%d\n", stats.timeouts);
+       if (stats.timeouts && !opt.quiet)
+               printf("invalid_frame=%d\n", stats.timeouts);
  
        fclose(opt.f_stat);