| 1169 | } |
| 1170 | |
| 1171 | static int read_block_generic(hamlib_port_t *p, unsigned char *rxbuffer, |
| 1172 | size_t count, int direct) |
| 1173 | { |
| 1174 | struct timeval start_time, end_time, elapsed_time; |
| 1175 | int total_count = 0; |
| 1176 | |
| 1177 | rig_debug(RIG_DEBUG_VERBOSE, "%s called, direct=%d\n", __func__, direct); |
| 1178 | |
| 1179 | if (!p->asyncio && !direct) |
| 1180 | { |
| 1181 | return -RIG_EINTERNAL; |
| 1182 | } |
| 1183 | |
| 1184 | /* Store the time of the read loop start */ |
| 1185 | gettimeofday(&start_time, NULL); |
| 1186 | |
| 1187 | short timeout_retries = p->timeout_retry; |
| 1188 | |
| 1189 | while (count > 0) |
| 1190 | { |
| 1191 | int result; |
| 1192 | int rd_count; |
| 1193 | |
| 1194 | result = port_wait_for_data(p, direct); |
| 1195 | |
| 1196 | if (result == -RIG_ETIMEOUT) |
| 1197 | { |
| 1198 | if (timeout_retries > 0) |
| 1199 | { |
| 1200 | timeout_retries--; |
| 1201 | rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%dms\n", |
| 1202 | __func__, __LINE__, |
| 1203 | p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout); |
| 1204 | hl_usleep(10 * 1000); |
| 1205 | continue; |
| 1206 | } |
| 1207 | |
| 1208 | /* Record timeout time and calculate elapsed time */ |
| 1209 | gettimeofday(&end_time, NULL); |
| 1210 | timersub(&end_time, &start_time, &elapsed_time); |
| 1211 | |
| 1212 | if (direct) |
| 1213 | { |
| 1214 | dump_hex((unsigned char *) rxbuffer, total_count); |
| 1215 | } |
| 1216 | |
| 1217 | rig_debug(RIG_DEBUG_WARN, |
| 1218 | "%s(): Timed out %d.%d seconds after %d chars, direct=%d\n", |
| 1219 | __func__, |
| 1220 | (int)elapsed_time.tv_sec, |
| 1221 | (int)elapsed_time.tv_usec, |
| 1222 | total_count, |
| 1223 | direct); |
| 1224 | |
| 1225 | return -RIG_ETIMEOUT; |
| 1226 | } |
| 1227 | |
| 1228 | if (result < 0) |
no test coverage detected