Send bytes to the WinKeyer within microHam device
| 592 | // Send bytes to the WinKeyer within microHam device |
| 593 | // |
| 594 | static void writeWkey(const unsigned char *bytes, int len) |
| 595 | { |
| 596 | unsigned char seq[12]; |
| 597 | int i; |
| 598 | DEBUG("%10d:Send WinKey data: ", TIME); |
| 599 | |
| 600 | for (i = 0; i < len; i++) { DEBUG(" %02x", (int) bytes[i]); } |
| 601 | |
| 602 | DEBUG(".\n"); |
| 603 | // Winkey data is in the third frame of a sequence, |
| 604 | // So send two no-ops first. Include statusbyte in first frame |
| 605 | getlock(); |
| 606 | |
| 607 | for (i = 0; i < len; i++) |
| 608 | { |
| 609 | int ret; |
| 610 | |
| 611 | seq[ 0] = 0x08; |
| 612 | seq[ 1] = 0x80; |
| 613 | seq[ 2] = 0x80; |
| 614 | seq[ 3] = 0X80 | statusbyte; |
| 615 | seq[ 4] = 0x40; |
| 616 | seq[ 5] = 0x80; |
| 617 | seq[ 6] = 0x80; |
| 618 | seq[ 7] = 0x80; |
| 619 | seq[ 8] = 0x48; |
| 620 | seq[ 9] = 0x80; |
| 621 | seq[10] = 0x80; |
| 622 | seq[11] = 0x80 | bytes[i]; |
| 623 | |
| 624 | if (statusbyte & 0x80) |
| 625 | { |
| 626 | seq[ 0] |= 0x01; |
| 627 | } |
| 628 | |
| 629 | if (bytes[i] & 0x80) |
| 630 | { |
| 631 | seq[ 8] |= 0x01; |
| 632 | } |
| 633 | |
| 634 | if ((ret = write(uh_device_fd, seq, 12)) < 12) |
| 635 | { |
| 636 | MYERROR("WriteWINKEY failed with %d\n", ret); |
| 637 | |
| 638 | if (ret < 0) |
| 639 | { |
| 640 | perror("WriteWinkeyError:"); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | freelock(); |
| 646 | } |
| 647 | #endif /* HAVE_SELECT */ |
| 648 | |
| 649 |