| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- # include <stdio.h>
- # include <stdint.h>
- # include <stdlib.h>
- # include <unistd.h>
- # include <string.h>
- # include <errno.h>
- # include <sys/types.h>
- # include <sys/stat.h>
- # include <fcntl.h>
- # include <arpa/inet.h>
- # include <getopt.h>
- struct fpv
- {
- uint32_t len;
- uint8_t type;
- uint32_t ms;
- uint8_t pad[8];
- } __attribute__((packed));
- struct cpu
- {
- uint8_t load;
- uint8_t temp;
- } __attribute__((packed));
- struct air
- {
- struct
- {
- int8_t rssi;
- uint32_t lost;
- } __attribute__((packed)) uplink;
- struct
- {
- int8_t rssi;
- uint32_t lost;
- } __attribute__((packed)) rc;
- struct cpu cpu;
- uint32_t blocks;
- uint32_t skipped;
- uint32_t failed;
- long long time;
- uint16_t bitrate;
- uint16_t measured_bitrate;
- uint8_t cts;
- uint8_t undervoltage;
- } __attribute__((packed));
- struct gnd
- {
- uint32_t broken;
- uint32_t lost;
- uint32_t skipped;
- uint32_t received;
- uint32_t real_bitrate;
- uint32_t measured_bitrate;
- uint32_t bitrate;
- uint32_t uplink_lost;
- uint32_t downlink_lost;
- uint32_t unused[3];
- int8_t air_rssi;
- int8_t joystick;
- struct
- {
- struct cpu gnd;
- struct cpu air;
- } __attribute__((packed)) cpu;
- uint32_t nics;
- struct
- {
- uint32_t packets;
- int8_t rssi;
- int8_t type;
- } __attribute__((packed)) nic[6];
- } __attribute__((packed));
- static const char short_options[] = "s:e:";
- static const struct option long_options[] =
- {
- { "start", required_argument, NULL, 's' },
- { "end", required_argument, NULL, 'e' },
- { 0, 0, NULL, 0 }
- };
- static int opt_s = 0;
- static int opt_e = 0;
- size_t in(int fd, uint8_t *data, size_t len)
- {
- int res = 0;
- while (len > 0) {
- size_t n = read(fd, data, len);
- if (n > 0) {
- len -= n;
- data += n;
- res += n;
- } else {
- if (n < 0) {
- if (errno != EAGAIN) {
- printf("read: %s\n", strerror(errno));
- } else {
- continue;
- }
- }
- break;
- }
- }
- return res;
- }
- int main(int argc, char *argv[])
- {
- struct fpv fpv;
- static uint8_t data[8 * 1024 * 1024];
- int i;
- for (;;) {
- int c;
- if ((c = getopt_long_only(argc, argv, short_options, long_options, &i)) == -1) {
- break;
- }
- switch (c) {
- case 's':
- opt_s = atoi(optarg);
- break;
- case 'e':
- opt_e = atoi(optarg);
- break;
- case 0:
- break;
- default:
- return 1;
- }
- }
- if ((argc - optind) < 1) {
- return 1;
- }
- for (i = 0; (optind + i) < argc; i++) {
- int fd = open(argv[optind + i], O_RDONLY);
- if (fd >= 0) {
- while (1) {
- if (in(fd, (uint8_t*)&fpv, sizeof(fpv)) > 0) {
- if (in(fd, data, fpv.len) > 0) {
- switch (fpv.type) {
- case 5:
- {
- struct gnd *gnd = (struct gnd *)data;
- for (i = 0; i < gnd->nics; i++) {
- printf(" %5d", gnd->nic[i].rssi);
- }
- printf(" %5d", gnd->lost);
- printf(" %5d", gnd->broken);
- printf(" %5d", gnd->air_rssi);
- printf(" %5d", gnd->uplink_lost);
- printf(" %5d", gnd->uplink_lost);
- printf(" %5d", gnd->cpu.air.load);
- printf(" %5d", gnd->cpu.air.temp);
- printf(" %5d", gnd->cpu.gnd.load);
- printf(" %5d", gnd->cpu.gnd.temp);
- printf("\n");
- continue;
- }
- break;
- default:
- continue;
- }
- }
- }
- break;
- }
- close(fd);
- }
- }
- return 0;
- }
|