gsmopen: works05
This commit is contained in:
parent
5b98e04e49
commit
d1446cd91c
|
@ -536,6 +536,8 @@ struct private_object {
|
|||
int controldev_audio_dead;
|
||||
switch_mutex_t *controldev_audio_lock;
|
||||
|
||||
ctb::IOBase* device_serial_audio;
|
||||
ctb::SerialPort* serialPort_serial_audio;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -4051,7 +4051,7 @@ int gsmopen_serial_getstatus_AT(private_t * tech_pvt)
|
|||
}
|
||||
|
||||
|
||||
int gsmopen_serial_init_audio_port(private_t * tech_pvt, speed_t controldevice_audio_speed)
|
||||
int oldgsmopen_serial_init_audio_port(private_t * tech_pvt, speed_t controldevice_audio_speed)
|
||||
{
|
||||
int fd;
|
||||
int rt;
|
||||
|
@ -4127,7 +4127,7 @@ int gsmopen_serial_init_audio_port(private_t * tech_pvt, speed_t controldevice_a
|
|||
|
||||
return (fd);
|
||||
}
|
||||
int serial_audio_init(private_t * tech_pvt)
|
||||
int old_serial_audio_init(private_t * tech_pvt)
|
||||
{
|
||||
int res;
|
||||
int err;
|
||||
|
@ -4149,13 +4149,132 @@ int serial_audio_init(private_t * tech_pvt)
|
|||
|
||||
return err;
|
||||
}
|
||||
int gsmopen_serial_init_audio_port(private_t * tech_pvt, speed_t controldevice_audio_speed)
|
||||
{
|
||||
|
||||
//#ifdef NOTDEF
|
||||
/***********************************/
|
||||
|
||||
tech_pvt->device_serial_audio = NULL;
|
||||
tech_pvt->serialPort_serial_audio = new ctb::SerialPort();
|
||||
|
||||
if( tech_pvt->serialPort_serial_audio->Open( "/dev/ttyUSB2", 115200, "8N1", ctb::SerialPort::NoFlowControl ) >= 0 ) {
|
||||
|
||||
//tech_pvt->device_serial_audio = tech_pvt->serialPort_serial_audio;
|
||||
ERRORA("port SUCCESS open\n", GSMOPEN_P_LOG);
|
||||
|
||||
} else {
|
||||
|
||||
ERRORA("port NOT open\n", GSMOPEN_P_LOG);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
/***********************************/
|
||||
//#endif// NOTDEF
|
||||
|
||||
#ifdef NOTDEF
|
||||
|
||||
|
||||
int fd;
|
||||
int rt;
|
||||
struct termios tp;
|
||||
unsigned int status = 0;
|
||||
unsigned int flags = TIOCM_DTR;
|
||||
|
||||
/* if there is a file descriptor, close it. But it is probably just an old value, so don't check for close success*/
|
||||
fd = tech_pvt->controldev_audio_fd;
|
||||
if (fd) {
|
||||
close(fd);
|
||||
}
|
||||
/* open the serial port */
|
||||
//#ifdef __CYGWIN__
|
||||
fd = open(tech_pvt->controldevice_audio_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
sleep(1);
|
||||
close(fd);
|
||||
//#endif /* __CYGWIN__ */
|
||||
fd = open(tech_pvt->controldevice_audio_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
if (fd == -1) {
|
||||
perror("AUDIO open error ");
|
||||
DEBUGA_GSMOPEN("AUDIO serial error: %s\n", GSMOPEN_P_LOG, strerror(errno));
|
||||
tech_pvt->controldev_audio_fd = fd;
|
||||
return -1;
|
||||
}
|
||||
/* flush it */
|
||||
rt = tcflush(fd, TCIFLUSH);
|
||||
if (rt == -1) {
|
||||
ERRORA("AUDIO serial error: %s", GSMOPEN_P_LOG, strerror(errno));
|
||||
}
|
||||
/* attributes */
|
||||
tp.c_cflag = B0 | CS8 | CLOCAL | CREAD | HUPCL;
|
||||
tp.c_iflag = IGNPAR;
|
||||
tp.c_cflag &= ~CRTSCTS;
|
||||
tp.c_oflag = 0;
|
||||
tp.c_lflag = 0;
|
||||
tp.c_cc[VMIN] = 1;
|
||||
tp.c_cc[VTIME] = 0;
|
||||
/* set controldevice_audio_speed */
|
||||
rt = cfsetispeed(&tp, tech_pvt->controldevice_audio_speed);
|
||||
if (rt == -1) {
|
||||
ERRORA("AUDIO serial error: %s, speed was: %d", GSMOPEN_P_LOG, strerror(errno), tech_pvt->controldevice_audio_speed);
|
||||
}
|
||||
rt = cfsetospeed(&tp, tech_pvt->controldevice_audio_speed);
|
||||
if (rt == -1) {
|
||||
ERRORA("AUDIO serial error: %s", GSMOPEN_P_LOG, strerror(errno));
|
||||
}
|
||||
/* set port attributes */
|
||||
if (tcsetattr(fd, TCSADRAIN, &tp) == -1) {
|
||||
ERRORA("AUDIO serial error: %s", GSMOPEN_P_LOG, strerror(errno));
|
||||
}
|
||||
rt = tcsetattr(fd, TCSANOW, &tp);
|
||||
if (rt == -1) {
|
||||
ERRORA("AUDIO serial error: %s", GSMOPEN_P_LOG, strerror(errno));
|
||||
}
|
||||
#ifndef __CYGWIN__
|
||||
ioctl(fd, TIOCMGET, &status);
|
||||
status |= TIOCM_DTR; /* Set DTR high */
|
||||
status &= ~TIOCM_RTS; /* Set RTS low */
|
||||
ioctl(fd, TIOCMSET, &status);
|
||||
ioctl(fd, TIOCMGET, &status);
|
||||
ioctl(fd, TIOCMBIS, &flags);
|
||||
flags = TIOCM_RTS;
|
||||
ioctl(fd, TIOCMBIC, &flags);
|
||||
ioctl(fd, TIOCMGET, &status);
|
||||
#else /* __CYGWIN__ */
|
||||
ioctl(fd, TIOCMGET, &status);
|
||||
status |= TIOCM_DTR; /* Set DTR high */
|
||||
status &= ~TIOCM_RTS; /* Set RTS low */
|
||||
ioctl(fd, TIOCMSET, &status);
|
||||
#endif /* __CYGWIN__ */
|
||||
tech_pvt->controldev_audio_fd = fd;
|
||||
|
||||
return (fd);
|
||||
#endif //NOTDEF
|
||||
}
|
||||
|
||||
int serial_audio_init(private_t * tech_pvt)
|
||||
{
|
||||
int res;
|
||||
int err;
|
||||
|
||||
res=gsmopen_serial_init_audio_port(tech_pvt, tech_pvt->controldevice_audio_speed);
|
||||
ERRORA("serial_audio_init res=%d\n", GSMOPEN_P_LOG, res);
|
||||
|
||||
if(res == 0)
|
||||
err=0;
|
||||
else
|
||||
err=1;
|
||||
|
||||
return err;
|
||||
}
|
||||
int serial_audio_shutdown(private_t * tech_pvt)
|
||||
{
|
||||
|
||||
int res;
|
||||
int err;
|
||||
|
||||
res = close(tech_pvt->controldev_audio_fd);
|
||||
//res = close(tech_pvt->controldev_audio_fd);
|
||||
res = tech_pvt->serialPort_serial_audio->Close();
|
||||
ERRORA("serial_audio_shutdown res=%d (controldev_audio_fd is %d)\n", GSMOPEN_P_LOG, res, tech_pvt->controldev_audio_fd);
|
||||
tech_pvt->controldev_audio_fd = -1;
|
||||
|
||||
|
|
|
@ -883,7 +883,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
|||
#endif// GSMOPEN_PORTAUDIO
|
||||
|
||||
//sent = write(tech_pvt->controldev_audio_fd, (short *) frame->data, (int) (frame->datalen));
|
||||
if ((samples = read(tech_pvt->controldev_audio_fd, (short *) tech_pvt->read_frame.data, 320)) >0)
|
||||
//if ((samples = read(tech_pvt->controldev_audio_fd, (short *) tech_pvt->read_frame.data, 320)) >0)
|
||||
if ((samples = tech_pvt->serialPort_serial_audio->Read((char *) tech_pvt->read_frame.data, 320)) >0)
|
||||
{
|
||||
|
||||
#ifdef GSMOPEN_PORTAUDIO
|
||||
|
@ -923,7 +924,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
|||
|
||||
*frame = &tech_pvt->read_frame;
|
||||
|
||||
if ((samples2 = read(tech_pvt->controldev_audio_fd, (short *) buffer2, 320)) >0){
|
||||
//if ((samples2 = read(tech_pvt->controldev_audio_fd, (short *) buffer2, 320)) >0){
|
||||
if ((samples2 = tech_pvt->serialPort_serial_audio->Read((char *) tech_pvt->read_frame.data, 320)) >0){
|
||||
WARNINGA("samples2=%d\n", GSMOPEN_P_LOG, samples2);
|
||||
|
||||
}
|
||||
|
@ -1093,7 +1095,8 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
|
|||
#endif //WANT_SPEEX
|
||||
#endif // GSMOPEN_PORTAUDIO
|
||||
|
||||
sent = write(tech_pvt->controldev_audio_fd, (short *) frame->data, (int) (frame->datalen));
|
||||
sent = tech_pvt->serialPort_serial_audio->Write((char *) frame->data, (int) (frame->datalen));
|
||||
//sent = write(tech_pvt->controldev_audio_fd, (short *) frame->data, (int) (frame->datalen));
|
||||
//DEBUGA_GSMOPEN("sent=%d \n", GSMOPEN_P_LOG, sent);
|
||||
|
||||
if (sent && sent != frame->datalen && sent != -1) {
|
||||
|
@ -2153,6 +2156,7 @@ static switch_status_t load_config(int reload_type)
|
|||
DEBUGA_GSMOPEN("gsmopen_serial_sync_period=%d\n", GSMOPEN_P_LOG, (int)globals.GSMOPEN_INTERFACES[i].gsmopen_serial_sync_period);
|
||||
DEBUGA_GSMOPEN("controldevice_audio_name=%s\n", GSMOPEN_P_LOG, globals.GSMOPEN_INTERFACES[i].controldevice_audio_name);
|
||||
/***********************************/
|
||||
#ifdef NOTDEF
|
||||
|
||||
ctb::IOBase* device = NULL;
|
||||
|
||||
|
@ -2175,6 +2179,7 @@ static switch_status_t load_config(int reload_type)
|
|||
ERRORA("port NOT open\n", GSMOPEN_P_LOG);
|
||||
}
|
||||
|
||||
#endif// NOTDEF
|
||||
|
||||
/***********************************/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue