static void test_track(void) { struct peak_tracks *tracker; struct peak_packet packet; struct netaddr usr1, usr2; struct peak_track _flow; struct peak_track *flow; memset(&packet, 0, sizeof(packet)); netaddr4(&usr1, 0); netaddr4(&usr2, 1); tracker = peak_track_init(2); assert(tracker); packet.net_saddr = usr1; packet.net_daddr = usr2; packet.flow_sport = 80; packet.flow_dport = 51000; TRACK_KEY(&_flow, &packet); flow = peak_track_acquire(tracker, &_flow); assert(flow); assert(flow == peak_track_acquire(tracker, &_flow)); assert(flow == peak_track_acquire(tracker, flow)); packet.net_saddr = usr2; packet.net_daddr = usr1; packet.flow_sport = 51000; packet.flow_dport = 80; TRACK_KEY(&_flow, &packet); assert(flow == peak_track_acquire(tracker, &_flow)); packet.net_saddr = usr1; packet.net_daddr = usr2; packet.flow_sport = 51000; packet.flow_dport = 80; TRACK_KEY(&_flow, &packet); assert(flow != peak_track_acquire(tracker, &_flow)); packet.net_saddr = usr1; packet.net_daddr = usr2; packet.flow_sport = 51000; packet.flow_dport = 80; packet.net_type = 1; TRACK_KEY(&_flow, &packet); assert(peak_track_acquire(tracker, &_flow)); peak_track_exit(tracker); }
uint8 ir_peak_track(uint16 sample,uint16 red_dc,uint16 ir_dc ) { if(!struct_init) peak_track_init(); if(sample > ir_track.max_value[ir_track.maxi]) { ir_track.max_value[ir_track.maxi]=sample; } if(sample <ir_track.min_value[ir_track.mini]) { ir_track.min_value[ir_track.mini]=sample; } if(ir_track.track) { if(sample < (ir_track.max_value[ir_track.maxi] - DELTA )) { ir_track.min_value[ir_track.mini]= ir_track.max_value[ir_track.maxi]; ir_track.maxi= (ir_track.maxi+1) % COUNT; ir_track.track=false; } } else { if(sample > (ir_track.min_value[ir_track.mini] + DELTA )) { ir_track.max_value[ir_track.maxi]= ir_track.min_value[ir_track.mini]; ir_track.mini= (ir_track.mini+1) % COUNT; ir_track.track=true; } if(ir_track.maxi==0 & ir_track.mini==0) ir_track.found=true; } if(red_track.found && ir_track.found) { return(spo2(red_dc,ir_dc)); } else return 0; }
void red_peak_track(uint16 sample) { if(!struct_init) peak_track_init(); if(sample > red_track.max_value[red_track.maxi]) { red_track.max_value[red_track.maxi]=sample; } if(sample <red_track.min_value[red_track.mini]) { red_track.min_value[red_track.mini]=sample; } if(red_track.track) { if(sample < (red_track.max_value[red_track.maxi] - DELTA )) { red_track.min_value[red_track.mini]= red_track.max_value[red_track.maxi]; red_track.maxi= (red_track.maxi+1) % COUNT; red_track.track=false; } } else { if(sample > (red_track.min_value[red_track.mini] + DELTA )) { red_track.max_value[red_track.maxi]= red_track.min_value[red_track.mini]; red_track.mini= (red_track.mini+1) % COUNT; red_track.track=true; } if(red_track.maxi==0 & red_track.mini==0) red_track.found=true; } }
int main(int argc, char **argv) { struct peak_tracks *peek; struct peak_load *trace; timeslice_t timer; int c; while ((c = getopt(argc, argv, "AafNnt")) != -1) { switch (c) { case 'A': use_print[use_count++] = USE_APP_LEN; break; case 'a': use_print[use_count++] = USE_APP; break; case 'f': use_print[use_count++] = USE_FLOW; break; case 'N': use_print[use_count++] = USE_IP_LEN; break; case 'n': use_print[use_count++] = USE_IP_TYPE; break; case 't': use_print[use_count++] = USE_TIME; break; default: usage(); /* NOTREACHED */ } if (use_count > USE_MAX) { usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc < 1) { usage(); /* NOTREACHED */ } if (!use_count) { /* set the default output (as used by tests) */ use_print[use_count++] = USE_FLOW; use_print[use_count++] = USE_IP_TYPE; use_print[use_count++] = USE_IP_LEN; use_print[use_count++] = USE_APP; use_print[use_count++] = USE_TIME; } trace = peak_load_init(argv[0]); if (!trace) { panic("cannot init file loader\n"); } peek = peak_track_init(10000, 1); if (!peek) { panic("cannot init flow tracker\n"); } TIMESLICE_INIT(&timer); if (peak_load_packet(trace)) { TIMESLICE_CALIBRATE(&timer, &trace->ts); do { TIMESLICE_ADVANCE(&timer, &trace->ts); peek_packet(peek, &timer, trace->buf, trace->len, trace->ll); } while (peak_load_packet(trace)); } peak_track_exit(peek); peak_load_exit(trace); return (0); }