/* Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2008, 2011, 2013 Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2008, 2011 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include struct timespec t_int; char *tracename; static void handler_interval(struct trace *trace, struct timespec *interval, enum trace_interval_type type) { memcpy(&t_int, interval, sizeof(struct timespec)); printf("interval: %ld.%09ld\n", interval->tv_sec, interval->tv_nsec); } static void handler_value(struct trace *trace, int channel, struct trace_value *value) { switch (trace->type) { case TRACE_VALUE_TYPE_FLOAT: printf("%ld.%09ld %e\n", value->t.tv_sec, value->t.tv_nsec, value->value.f); break; case TRACE_VALUE_TYPE_BOOL: printf("%ld.%09ld %d\n", value->t.tv_sec, value->t.tv_nsec, value->value.b); break; case TRACE_VALUE_TYPE_UINT8: printf("%ld.%09ld %u\n", value->t.tv_sec, value->t.tv_nsec, value->value.u8); break; case TRACE_VALUE_TYPE_UINT16: printf("%ld.%09ld %u\n", value->t.tv_sec, value->t.tv_nsec, value->value.u16); break; case TRACE_VALUE_TYPE_UINT32: printf("%ld.%09ld %u\n", value->t.tv_sec, value->t.tv_nsec, value->value.u32); break; case TRACE_VALUE_TYPE_SINT8: printf("%ld.%09ld %d\n", value->t.tv_sec, value->t.tv_nsec, value->value.s8); break; case TRACE_VALUE_TYPE_SINT16: printf("%ld.%09ld %d\n", value->t.tv_sec, value->t.tv_nsec, value->value.s16); break; case TRACE_VALUE_TYPE_SINT32: printf("%ld.%09ld %d\n", value->t.tv_sec, value->t.tv_nsec, value->value.s32); break; } } int main(int argc, char **argv) { struct trace *trace; struct trace_pkt *pkt; if (argc < 4) { printf("Usage:\n\n"); printf("%s [host] [port] [trace]\n", argv[0]); return 0; } tracename = argv[3]; trace = trace_open(argv[1], atoi(argv[2])); trace->handler_interval = handler_interval; trace->handler_value = handler_value; while (trace_state_get(trace) == TRACE_STATE_CONNECTED) { fd_set fdrx; int high = 0; FD_ZERO(&fdrx); trace_fd_set(trace, &fdrx, &high); select(high + 1, &fdrx, NULL, NULL, NULL); trace_handle(trace, &fdrx); } printf("Connection ready for tracing\n"); pkt = trace_packet_new(); trace_packet_interval_set(pkt, &t_int, TRACE_INTERVAL_TYPE_CHANGED); trace_packet_write(trace, pkt); trace_packet_put(pkt); pkt = trace_packet_new(); trace_packet_name_set(pkt, 0, tracename); trace_packet_write(trace, pkt); trace_packet_put(pkt); printf("Wait for data\n"); while (trace_state_get(trace) == TRACE_STATE_RECEIVING || trace_state_get(trace) == TRACE_STATE_READY) { fd_set fdrx; int high = 0; FD_ZERO(&fdrx); trace_fd_set(trace, &fdrx, &high); select(high + 1, &fdrx, NULL, NULL, NULL); trace_handle(trace, &fdrx); } return 0; }