Line 97... |
Line 97... |
*
|
*
|
* If it does not exist then you are dealing with some kind of virtual tty
|
* If it does not exist then you are dealing with some kind of virtual tty
|
* device (virtual console port, ptmx, etc...) and you can discard it.
|
* device (virtual console port, ptmx, etc...) and you can discard it.
|
* If it exists then retain serial port foo.
|
* If it exists then retain serial port foo.
|
*/
|
*/
|
void ComPortService::getSerialPortList(AttributeType *list) {
|
void ComPortService::getListOfPorts(AttributeType *list) {
|
int n;
|
int n;
|
struct dirent **namelist;
|
struct dirent **namelist;
|
const char* sysdir = "/sys/class/tty/";
|
const char* sysdir = "/sys/class/tty/";
|
AttributeType jsonPortInfo;
|
AttributeType jsonPortInfo;
|
list->make_list(0);
|
list->make_list(0);
|
Line 142... |
Line 142... |
// serial8250-devices must be probe to check for validity
|
// serial8250-devices must be probe to check for validity
|
//probe_serial8250_comports(comList, comList8250);
|
//probe_serial8250_comports(comList, comList8250);
|
}
|
}
|
|
|
|
|
int ComPortService::openSerialPort(const char *port, int baud, void *hdl) {
|
int ComPortService::openPort(const char *port, AttributeType settings) {
|
*((int *)hdl) = 0;
|
closePort();
|
int fd = open(port, O_RDWR | O_NOCTTY);// | O_NONBLOCK);// | O_NDELAY );
|
int fd = open(port, O_RDWR | O_NOCTTY);// | O_NONBLOCK);// | O_NDELAY );
|
//fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
|
//fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
|
if (fd < 0) {
|
if (fd < 0) {
|
RISCV_error("fopen() failed", NULL);
|
RISCV_error("fopen() failed", NULL);
|
return -1;
|
return -1;
|
Line 234... |
Line 234... |
return -1;
|
return -1;
|
}
|
}
|
|
|
// Empty buffers
|
// Empty buffers
|
tcflush(fd, TCIOFLUSH);
|
tcflush(fd, TCIOFLUSH);
|
*((int *)hdl) = fd;
|
prtHandler_ = fd;
|
return 0 ;
|
return 0 ;
|
}
|
}
|
|
|
void ComPortService::closeSerialPort(void *hdl) {
|
void ComPortService::closePort() {
|
close(*((int *)hdl));
|
if (prtHandler_) {
|
|
close(prtHandler_);
|
|
}
|
|
prtHandler_ = 0;
|
}
|
}
|
|
|
int ComPortService::readSerialPort(void *hdl, char *buf, int bufsz) {
|
int ComPortService::readSerialPort(void *hdl, char *buf, int bufsz) {
|
return read(*((int *)hdl), buf, bufsz-1);
|
int sz = read(*((int *)hdl), buf, bufsz-1);
|
|
buf[sz] = 0;
|
|
return sz;
|
}
|
}
|
|
|
int ComPortService::writeSerialPort(void *hdl, char *buf, int bufsz) {
|
int ComPortService::writeSerialPort(void *hdl, char *buf, int bufsz) {
|
return write(*((int *)hdl), buf, bufsz);
|
return write(*((int *)hdl), buf, bufsz);
|
}
|
}
|