File: guessdevs.cpp

package info (click to toggle)
obdgpslogger 0.16-1.3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 5,160 kB
  • ctags: 7,498
  • sloc: ansic: 73,206; cpp: 2,055; php: 407; sh: 51; makefile: 4
file content (59 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright 2009 Gary Briggs

This file is part of obdgpslogger.

obdgpslogger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

obdgpslogger is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with obdgpslogger.  If not, see <http://www.gnu.org/licenses/>.
*/

/** \file
 \brief Guess likely serial device names
 */

#include <stdio.h>
#include <string.h>
#include <glob.h>
#include <FL/Fl_Input_Choice.H>

#include "guessdevs.h"

int populateSerialDevs(Fl_Input_Choice *addto, const char *def) {
	glob_t names;

	addto->clear();
	if(NULL != def && 0 < strlen(def)) {
		addto->add(def);
		addto->value(0);
	}

	// Just take a bunch of semi-educated guesses:

	// This is the OSX standard way of doing things
	glob("/dev/cu.*", 0, NULL, &names);
	// Linux bluetooth
	glob("/dev/rfcomm*", GLOB_APPEND, NULL, &names);
	// Linux USB
	glob("/dev/ttyUSB*", GLOB_APPEND, NULL, &names);
	// Good ol' fashioned serial port
	glob("/dev/ttyS*", GLOB_APPEND, NULL, &names);

	size_t i;
	for(i=0; i<names.gl_pathc; i++) {
		addto->add(names.gl_pathv[i]);
	}
	
	globfree(&names);

	return 0;
}