| 1063 | */ |
| 1064 | |
| 1065 | int HAMLIB_API write_block(hamlib_port_t *p, const unsigned char *txbuffer, |
| 1066 | size_t count) |
| 1067 | { |
| 1068 | int ret; |
| 1069 | |
| 1070 | if (p->fd < 0) |
| 1071 | { |
| 1072 | rig_debug(RIG_DEBUG_ERR, "%s: port not open\n", __func__); |
| 1073 | return (-RIG_EIO); |
| 1074 | } |
| 1075 | |
| 1076 | #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY |
| 1077 | |
| 1078 | if (p->post_write_date.tv_sec != 0) |
| 1079 | { |
| 1080 | signed int date_delay; /* in us */ |
| 1081 | struct timeval tv; |
| 1082 | |
| 1083 | /* FIXME in Y2038 ... */ |
| 1084 | gettimeofday(&tv, NULL); |
| 1085 | date_delay = p->post_write_delay * 1000 - |
| 1086 | ((tv.tv_sec - p->post_write_date.tv_sec) * 1000000 + |
| 1087 | (tv.tv_usec - p->post_write_date.tv_usec)); |
| 1088 | |
| 1089 | if (date_delay > 0) |
| 1090 | { |
| 1091 | /* |
| 1092 | * optional delay after last write |
| 1093 | */ |
| 1094 | hl_sleep(date_delay); |
| 1095 | } |
| 1096 | |
| 1097 | p->post_write_date.tv_sec = 0; |
| 1098 | } |
| 1099 | |
| 1100 | #endif |
| 1101 | |
| 1102 | if (p->write_delay > 0) |
| 1103 | { |
| 1104 | int i; |
| 1105 | |
| 1106 | for (i = 0; i < count; i++) |
| 1107 | { |
| 1108 | ret = port_write(p, txbuffer + i, 1); |
| 1109 | |
| 1110 | if (ret != 1) |
| 1111 | { |
| 1112 | rig_debug(RIG_DEBUG_ERR, |
| 1113 | "%s():%d failed %d - %s\n", |
| 1114 | __func__, |
| 1115 | __LINE__, |
| 1116 | ret, |
| 1117 | strerror(errno)); |
| 1118 | |
| 1119 | return -RIG_EIO; |
| 1120 | } |
| 1121 | |
| 1122 | if (p->write_delay > 0) { hl_usleep(p->write_delay * 1000); } |
no test coverage detected