| 274 | #include <sys/stat.h> |
| 275 | #include <glob.h> |
| 276 | static void finddevices() |
| 277 | { |
| 278 | struct stat st; |
| 279 | glob_t gbuf; |
| 280 | int i, j; |
| 281 | struct termios TTY; |
| 282 | int fd; |
| 283 | |
| 284 | uh_device_fd = -1; // indicates "no device is found" |
| 285 | |
| 286 | // |
| 287 | // Check ALL device special files that might be relevant, |
| 288 | // |
| 289 | for (i = 0; i < NUMUHTYPES; i++) |
| 290 | { |
| 291 | DEBUG("Checking for %s device\n", uhtypes[i].device); |
| 292 | glob(uhtypes[i].device, 0, NULL, &gbuf); |
| 293 | |
| 294 | for (j = 0; j < gbuf.gl_pathc; j++) |
| 295 | { |
| 296 | DEBUG("Found file: %s\n", gbuf.gl_pathv[j]); |
| 297 | |
| 298 | if (!stat(gbuf.gl_pathv[j], &st)) |
| 299 | { |
| 300 | if (S_ISCHR(st.st_mode)) |
| 301 | { |
| 302 | // found a character special device with correct name |
| 303 | if (strlen(gbuf.gl_pathv[j]) >= PATH_MAX) |
| 304 | { |
| 305 | // I do not know if this can happen, but if it happens, we just skip the device. |
| 306 | MYERROR("Name too long: %s\n", gbuf.gl_pathv[j]); |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | DEBUG("%s is a character special file\n", gbuf.gl_pathv[j]); |
| 311 | strcpy(uh_device_path, gbuf.gl_pathv[j]); |
| 312 | TRACE("Found a %s, Device=%s\n", uhtypes[i].name, uh_device_path); |
| 313 | |
| 314 | fd = open(uh_device_path, O_RDWR | O_NONBLOCK | O_NOCTTY); |
| 315 | |
| 316 | if (fd < 0) |
| 317 | { |
| 318 | MYERROR("Cannot open serial port %s\n", uh_device_path); |
| 319 | perror("Open:"); |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | tcflush(fd, TCIFLUSH); |
| 324 | |
| 325 | if (tcgetattr(fd, &TTY)) |
| 326 | { |
| 327 | MYERROR("Cannot get comm params\n"); |
| 328 | close(fd); |
| 329 | continue; |
| 330 | } |
| 331 | |
| 332 | // microHam devices always use 230400 baud, 8N1, only TxD/RxD is used (no h/w handshake) |
| 333 | // 8 data bits |
no test coverage detected