Ticket #5905: fw_tester.2.patch
File fw_tester.2.patch, 4.7 KB (added by , 15 years ago) |
---|
-
mythtv/contrib/development/firewire_tester/firewire_tester.c
19 19 #define ACTION_TEST_P2P 1 20 20 #define ACTION_FIX_BCAST 2 21 21 #define ACTION_RESET_BUS 3 22 #define ACTION_OUTPUT_P2P 4 22 23 23 24 #define SYNC_BYTE 0x47 24 25 #define MIN_PACKETS 25 … … 29 30 int verbose = 0; 30 31 int sync_failed = 0; 31 32 int nodata = 0; 33 int run = 0; 32 34 33 35 static int read_packet (unsigned char *tspacket, int len, 34 36 unsigned int dropped, void *callback_data) … … 51 53 return 1; 52 54 } 53 55 56 static int fwrite_packet (unsigned char *tspacket, int len, 57 unsigned int dropped, void *callback_data) 58 { 59 int n; 60 FILE *fp = (FILE *) callback_data; 61 62 if (dropped) 63 { 64 fprintf(stderr, "Dropped %d packet(s).\n", dropped); 65 return 0; 66 } 67 68 if (tspacket[0] != SYNC_BYTE) 69 { 70 sync_failed = 1; 71 return 0; 72 } 73 nodata = 0; 74 n = fwrite(tspacket, sizeof(char), 188, fp); 75 //fprintf(stderr, "fwrite_packets: wrote %d of %d\n", n, len); 76 return(n == len ? 0 : 1); 77 } 78 54 79 int test_connection(raw1394handle_t handle, int channel) 55 80 { 56 81 int count = 0; … … 210 235 return 0; 211 236 } 212 237 238 // create and test a p2p connection, copy packets to stdout 239 // returns 1 on success, 0 on failure 240 int output_p2p(raw1394handle_t handle, nodeid_t node) { 241 int channel, count, success = 0; 242 int retry = 0; 243 FILE *fp = stdout; 244 iec61883_mpeg2_t mpeg; 245 struct timeval tv; 246 fd_set rfds; 247 channel = node; 248 int fd = raw1394_get_fd(handle); 249 250 sync_failed = 0; 251 252 VERBOSE("P2P: Creating, node %d, channel %d\n", node, channel); 253 fflush(stdout); 254 255 // make connection 256 if (iec61883_cmp_create_p2p_output(handle, node | 0xffc0, 0, channel, 257 1 /* fix me, speed */ ) != 0) 258 { 259 fprintf(stderr, "iec61883_cmp_create_p2p_output failed\n"); 260 return 0; 261 } 262 mpeg = iec61883_mpeg2_recv_init(handle, fwrite_packet, (void*) fp); 263 run = 1; 264 iec61883_mpeg2_recv_start(mpeg, channel); 265 while(run && retry < 2 && !sync_failed && nodata < MAX_NODATA) 266 { 267 FD_ZERO(&rfds); 268 FD_SET(fd, &rfds); 269 tv.tv_sec = 1; 270 tv.tv_usec = 0; 271 272 if (select(fd + 1, &rfds, NULL, NULL, &tv) > 0) 273 { 274 nodata++; 275 raw1394_loop_iterate(handle); 276 } 277 else 278 { 279 retry++; 280 } 281 } 282 iec61883_mpeg2_recv_stop(mpeg); 283 iec61883_mpeg2_close(mpeg); 284 285 if (sync_failed) 286 return 0; 287 288 return count; 289 290 VERBOSE("P2P: Disconnecting.\n"); 291 iec61883_cmp_disconnect(handle, node | 0xffc0, 0, 292 raw1394_get_local_id (handle), 293 -1, channel, 0); 294 return success; 295 } 296 213 297 void usage(void) { 214 298 printf("firewire_tester <action> -n <node> [-P <port>] [-r <n>] [-v]\n"); 215 299 printf(" Actions: (one is required)\n"); … … 219 303 printf(" -R - reset the firewire bus\n"); 220 304 printf(" Options\n"); 221 305 printf(" -n <node> - firewire node, required\n"); 306 printf(" -o - write packets to stdout using p2p connection\n"); 222 307 printf(" -P <port> - firewire port, default 0\n"); 223 308 printf(" -r <n> - run action <n> times, default 1\n"); 224 309 printf(" -v - verbose\n"); … … 234 319 int action = ACTION_NONE; 235 320 236 321 opterr = 0; 237 while ((c = getopt(argc, argv, "Bbn: pP:r:Rv")) != -1)322 while ((c = getopt(argc, argv, "Bbn:opP:r:Rv")) != -1) 238 323 { 239 324 switch (c) 240 325 { … … 269 354 } 270 355 break; 271 356 357 // output packets using p2p connection 358 case 'o': 359 if (action != ACTION_NONE) 360 { 361 printf("Invalid command line\n"); 362 usage(); 363 } 364 action = ACTION_OUTPUT_P2P; 365 break; 366 272 367 // set the port, optional 273 368 case 'P': 274 369 port = atoi(optarg); … … 368 463 printf("Bus reset failed: %d\n", errno); 369 464 } 370 465 break; 466 case ACTION_OUTPUT_P2P: 467 runs = 1; 468 fprintf(stderr, 469 "Action: Output P2P packets using node %d, channel %d\n", 470 node, node); 471 success = output_p2p(handle, node); 472 break; 371 473 } 372 474 373 475 VERBOSE("raw1394: Releasing handle.\n");