| 773 | } |
| 774 | |
| 775 | void fxSetTime(txSerialTool self, txSerialMachine machine) |
| 776 | { |
| 777 | time_t time; |
| 778 | int gmt = 0; |
| 779 | int dst = 0; |
| 780 | char out[32]; |
| 781 | |
| 782 | if (self->traceCommands) |
| 783 | fprintf(stderr, "### set time\n"); |
| 784 | |
| 785 | #if mxWindows |
| 786 | { |
| 787 | struct _timeb tb; |
| 788 | _ftime(&tb); |
| 789 | time = (long)tb.time; |
| 790 | gmt = -tb.timezone * 60; |
| 791 | if (tb.dstflag) { |
| 792 | dst = 60 * 60; |
| 793 | } |
| 794 | } |
| 795 | #else |
| 796 | { |
| 797 | struct timeval tv; |
| 798 | struct tm *tm; |
| 799 | gettimeofday(&tv, NULL); |
| 800 | time = tv.tv_sec; |
| 801 | tm = localtime(&time); |
| 802 | gmt = tm->tm_gmtoff; |
| 803 | if (tm->tm_isdst) { |
| 804 | dst = 60 * 60; |
| 805 | gmt -= dst; |
| 806 | } |
| 807 | } |
| 808 | #endif |
| 809 | |
| 810 | sprintf(out, "\r\n<?xs#%8.8X?>", machine->value); |
| 811 | fxWriteSerial(self, out, strlen(out)); |
| 812 | |
| 813 | out[0] = 0; |
| 814 | out[1] = 15; // length |
| 815 | out[2] = 9; // set time |
| 816 | out[3] = 0; |
| 817 | out[4] = 0; |
| 818 | out[5] = (time >> 24) & 255; |
| 819 | out[6] = (time >> 16) & 255; |
| 820 | out[7] = (time >> 8) & 255; |
| 821 | out[8] = time & 255; |
| 822 | out[9] = (gmt >> 24) & 255; |
| 823 | out[10] = (gmt >> 16) & 255; |
| 824 | out[11] = (gmt >> 8) & 255; |
| 825 | out[12] = gmt & 255; |
| 826 | out[13] = (dst >> 24) & 255; |
| 827 | out[14] = (dst >> 16) & 255; |
| 828 | out[15] = (dst >> 8) & 255; |
| 829 | out[16] = dst & 255; |
| 830 | fxWriteSerial(self, out, 17); |
| 831 | } |
| 832 |
no test coverage detected