Write a control string to the microHam device
| 651 | // Write a control string to the microHam device |
| 652 | // |
| 653 | static void writeControl(const unsigned char *data, int len) |
| 654 | { |
| 655 | int i; |
| 656 | unsigned char seq[8]; |
| 657 | |
| 658 | DEBUG("%10d:WriteControl:", TIME); |
| 659 | |
| 660 | for (i = 0; i < len; i++) { DEBUG(" %02x", data[i]); } |
| 661 | |
| 662 | DEBUG(".\n"); |
| 663 | // Control data is in the second frame of a sequence, |
| 664 | // So send a no-op first. Include statusbyte in first frame. |
| 665 | // First and last byte of the control message is NOT marked "valid" |
| 666 | getlock(); |
| 667 | |
| 668 | for (i = 0; i < len; i++) |
| 669 | { |
| 670 | int ret; |
| 671 | |
| 672 | // encode statusbyte in first frame |
| 673 | seq[0] = 0x08; |
| 674 | seq[1] = 0x80; |
| 675 | seq[2] = 0x80; |
| 676 | seq[3] = 0x80 | statusbyte; |
| 677 | seq[4] = 0x48; // marked valid |
| 678 | seq[5] = 0x80; |
| 679 | seq[6] = 0x80; |
| 680 | seq[7] = 0x80 | data[i]; |
| 681 | |
| 682 | if (statusbyte & 0x80) |
| 683 | { |
| 684 | seq[0] |= 1; |
| 685 | } |
| 686 | |
| 687 | if (i == 0 || i == len - 1) |
| 688 | { |
| 689 | seq[4] = 0x40; // un-mark valid |
| 690 | } |
| 691 | |
| 692 | if (data[i] & 0x80) |
| 693 | { |
| 694 | seq[4] |= 0x01; |
| 695 | } |
| 696 | |
| 697 | if ((ret = write(uh_device_fd, seq, 8)) < 8) |
| 698 | { |
| 699 | MYERROR("WriteControl failed, ret=%d\n", ret); |
| 700 | |
| 701 | if (ret < 0) |
| 702 | { |
| 703 | perror("WriteControlError:"); |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | freelock(); |
| 709 | } |
| 710 |
no outgoing calls
no test coverage detected