gsmopen: continue cleaning
This commit is contained in:
parent
2239dee1b7
commit
51b6315e98
|
@ -1,46 +1,13 @@
|
|||
#include "gsmopen.h"
|
||||
//#include <iostream.h>
|
||||
|
||||
#ifndef NO_GSMLIB
|
||||
#include <gsmlib/gsm_sms.h>
|
||||
#ifdef WIN32
|
||||
#include <gsmlib/gsm_win32_serial.h>
|
||||
#else
|
||||
#include <gsmlib/gsm_unix_serial.h>
|
||||
#endif
|
||||
#include <gsmlib/gsm_me_ta.h>
|
||||
#include <iostream>
|
||||
extern int running; //FIXME
|
||||
int gsmopen_dir_entry_extension = 1; //FIXME
|
||||
int option_debug = 100; //FIXME
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace gsmlib;
|
||||
#endif// NO_GSMLIB
|
||||
|
||||
#ifdef ASTERISK
|
||||
#define gsmopen_sleep usleep
|
||||
#define gsmopen_strncpy strncpy
|
||||
#define tech_pvt p
|
||||
extern int gsmopen_debug;
|
||||
extern char *gsmopen_console_active;
|
||||
#else /* FREESWITCH */
|
||||
#define gsmopen_sleep switch_sleep
|
||||
#define gsmopen_strncpy switch_copy_string
|
||||
extern switch_memory_pool_t *gsmopen_module_pool;
|
||||
extern switch_endpoint_interface_t *gsmopen_endpoint_interface;
|
||||
#endif /* ASTERISK */
|
||||
//int samplerate_gsmopen = SAMPLERATE_GSMOPEN;
|
||||
|
||||
extern int running;
|
||||
int gsmopen_dir_entry_extension = 1;
|
||||
|
||||
int option_debug = 100;
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define GSMLIBGIO
|
||||
#else //WIN32
|
||||
#undef GSMLIBGIO
|
||||
#endif //WIN32
|
||||
|
||||
#ifdef WIN32
|
||||
/***************/
|
||||
|
@ -88,327 +55,6 @@ int gettimeofday(struct timeval *tv, struct sk_timezone *tz)
|
|||
/***************/
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef GSMOPEN_PORTAUDIO
|
||||
#include "pablio.h"
|
||||
|
||||
#ifndef GIOVA48
|
||||
#define SAMPLES_PER_FRAME 160
|
||||
#else // GIOVA48
|
||||
#define SAMPLES_PER_FRAME 960
|
||||
#endif // GIOVA48
|
||||
|
||||
int gsmopen_portaudio_devlist(private_t *tech_pvt)
|
||||
{
|
||||
int i, numDevices;
|
||||
const PaDeviceInfo *deviceInfo;
|
||||
|
||||
numDevices = Pa_GetDeviceCount();
|
||||
if (numDevices < 0) {
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < numDevices; i++) {
|
||||
deviceInfo = Pa_GetDeviceInfo(i);
|
||||
NOTICA
|
||||
("Found PORTAUDIO device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n",
|
||||
GSMOPEN_P_LOG, i, deviceInfo->name, deviceInfo->maxInputChannels,
|
||||
deviceInfo->maxOutputChannels);
|
||||
}
|
||||
|
||||
return numDevices;
|
||||
}
|
||||
|
||||
int gsmopen_portaudio_init(private_t *tech_pvt)
|
||||
{
|
||||
PaError err;
|
||||
int c;
|
||||
PaStreamParameters inputParameters, outputParameters;
|
||||
int numdevices;
|
||||
const PaDeviceInfo *deviceInfo;
|
||||
|
||||
#ifndef GIOVA48
|
||||
setenv("PA_ALSA_PLUGHW", "1", 1);
|
||||
#endif // GIOVA48
|
||||
|
||||
err = Pa_Initialize();
|
||||
if (err != paNoError)
|
||||
return err;
|
||||
|
||||
numdevices = gsmopen_portaudio_devlist(tech_pvt);
|
||||
|
||||
if (tech_pvt->portaudiocindex > (numdevices - 1)) {
|
||||
ERRORA("Portaudio Capture id=%d is out of range: valid id are from 0 to %d\n",
|
||||
GSMOPEN_P_LOG, tech_pvt->portaudiocindex, (numdevices - 1));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tech_pvt->portaudiopindex > (numdevices - 1)) {
|
||||
ERRORA("Portaudio Playback id=%d is out of range: valid id are from 0 to %d\n",
|
||||
GSMOPEN_P_LOG, tech_pvt->portaudiopindex, (numdevices - 1));
|
||||
return -1;
|
||||
}
|
||||
//inputParameters.device = 0;
|
||||
if (tech_pvt->portaudiocindex != -1) {
|
||||
inputParameters.device = tech_pvt->portaudiocindex;
|
||||
} else {
|
||||
inputParameters.device = Pa_GetDefaultInputDevice();
|
||||
}
|
||||
deviceInfo = Pa_GetDeviceInfo(inputParameters.device);
|
||||
NOTICA
|
||||
("Using INPUT PORTAUDIO device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n",
|
||||
GSMOPEN_P_LOG, inputParameters.device, deviceInfo->name,
|
||||
deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
|
||||
if (deviceInfo->maxInputChannels == 0) {
|
||||
ERRORA
|
||||
("No INPUT channels on device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n",
|
||||
GSMOPEN_P_LOG, inputParameters.device, deviceInfo->name,
|
||||
deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
|
||||
return -1;
|
||||
}
|
||||
inputParameters.channelCount = 1;
|
||||
inputParameters.sampleFormat = paInt16;
|
||||
//inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultHighInputLatency;
|
||||
inputParameters.suggestedLatency = 0.1;
|
||||
inputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
//outputParameters.device = 3;
|
||||
if (tech_pvt->portaudiopindex != -1) {
|
||||
outputParameters.device = tech_pvt->portaudiopindex;
|
||||
} else {
|
||||
outputParameters.device = Pa_GetDefaultOutputDevice();
|
||||
}
|
||||
deviceInfo = Pa_GetDeviceInfo(outputParameters.device);
|
||||
NOTICA
|
||||
("Using OUTPUT PORTAUDIO device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n",
|
||||
GSMOPEN_P_LOG, outputParameters.device, deviceInfo->name,
|
||||
deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
|
||||
if (deviceInfo->maxOutputChannels == 0) {
|
||||
ERRORA
|
||||
("No OUTPUT channels on device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n",
|
||||
GSMOPEN_P_LOG, inputParameters.device, deviceInfo->name,
|
||||
deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
|
||||
return -1;
|
||||
}
|
||||
#ifndef GIOVA48
|
||||
outputParameters.channelCount = 1;
|
||||
#else // GIOVA48
|
||||
outputParameters.channelCount = 2;
|
||||
#endif // GIOVA48
|
||||
outputParameters.sampleFormat = paInt16;
|
||||
//outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultHighOutputLatency;
|
||||
outputParameters.suggestedLatency = 0.1;
|
||||
outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
/* build the pipe that will be polled on by pbx */
|
||||
c = pipe(tech_pvt->audiopipe);
|
||||
if (c) {
|
||||
ERRORA("Unable to create audio pipe\n", GSMOPEN_P_LOG);
|
||||
return -1;
|
||||
}
|
||||
fcntl(tech_pvt->audiopipe[0], F_SETFL, O_NONBLOCK);
|
||||
fcntl(tech_pvt->audiopipe[1], F_SETFL, O_NONBLOCK);
|
||||
|
||||
err =
|
||||
#ifndef GIOVA48
|
||||
OpenAudioStream(&tech_pvt->stream, &inputParameters, &outputParameters, 8000,
|
||||
paClipOff|paDitherOff, SAMPLES_PER_FRAME, 0);
|
||||
//&tech_pvt->speexecho, &tech_pvt->speexpreprocess, &tech_pvt->owner);
|
||||
|
||||
#else // GIOVA48
|
||||
OpenAudioStream(&tech_pvt->stream, &inputParameters, &outputParameters, 48000,
|
||||
paDitherOff | paClipOff, SAMPLES_PER_FRAME, tech_pvt->audiopipe[1],
|
||||
&tech_pvt->speexecho, &tech_pvt->speexpreprocess, &tech_pvt->owner);
|
||||
|
||||
|
||||
#endif// GIOVA48
|
||||
if (err != paNoError) {
|
||||
ERRORA("Unable to open audio stream: %s\n", GSMOPEN_P_LOG, Pa_GetErrorText(err));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* the pipe is our audio fd for pbx to poll on */
|
||||
tech_pvt->gsmopen_sound_capt_fd = tech_pvt->audiopipe[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
//int gsmopen_portaudio_write(private_t *tech_pvt, struct ast_frame *f)
|
||||
int gsmopen_portaudio_write(private_t * tech_pvt, short *data, int datalen)
|
||||
{
|
||||
int samples;
|
||||
#ifdef GIOVA48
|
||||
//short buf[GSMOPEN_FRAME_SIZE * 2];
|
||||
short buf[3840];
|
||||
short *buf2;
|
||||
|
||||
//ERRORA("1 f->datalen=: %d\n", GSMOPEN_P_LOG, f->datalen);
|
||||
|
||||
|
||||
|
||||
|
||||
memset(buf, '\0', GSMOPEN_FRAME_SIZE *2);
|
||||
|
||||
buf2 = f->data;
|
||||
|
||||
int i=0, a=0;
|
||||
|
||||
for(i=0; i< f->datalen / sizeof(short); i++){
|
||||
//stereo, 2 chan 48 -> mono 8
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
buf[a] = buf2[i];
|
||||
a++;
|
||||
/*
|
||||
*/
|
||||
}
|
||||
f->data = &buf;
|
||||
f->datalen = f->datalen * 6;
|
||||
//ERRORA("2 f->datalen=: %d\n", GSMOPEN_P_LOG, f->datalen);
|
||||
//f->datalen = f->datalen;
|
||||
#endif // GIOVA48
|
||||
|
||||
|
||||
samples =
|
||||
WriteAudioStream(tech_pvt->stream, (short *) data, (int) (datalen / sizeof(short)), &tech_pvt->timer_write);
|
||||
|
||||
if (samples != (int) (datalen / sizeof(short)))
|
||||
ERRORA("WriteAudioStream wrote: %d of %d\n", GSMOPEN_P_LOG, samples,
|
||||
(int) (datalen / sizeof(short)));
|
||||
|
||||
return samples;
|
||||
}
|
||||
//struct ast_frame *gsmopen_portaudio_read(private_t *tech_pvt)
|
||||
#define AST_FRIENDLY_OFFSET 0
|
||||
int gsmopen_portaudio_read(private_t * tech_pvt, short *data, int datalen)
|
||||
{
|
||||
#if 0
|
||||
//static struct ast_frame f;
|
||||
static short __buf[GSMOPEN_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
|
||||
short *buf;
|
||||
static short __buf2[GSMOPEN_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
|
||||
short *buf2;
|
||||
int samples;
|
||||
//char c;
|
||||
|
||||
memset(__buf, '\0', (GSMOPEN_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2));
|
||||
|
||||
buf = __buf + AST_FRIENDLY_OFFSET / 2;
|
||||
|
||||
memset(__buf2, '\0', (GSMOPEN_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2));
|
||||
|
||||
buf2 = __buf2 + AST_FRIENDLY_OFFSET / 2;
|
||||
|
||||
#if 0
|
||||
f.frametype = AST_FRAME_NULL;
|
||||
f.subclass = 0;
|
||||
f.samples = 0;
|
||||
f.datalen = 0;
|
||||
|
||||
#ifdef ASTERISK_VERSION_1_6_1
|
||||
f.data.ptr = NULL;
|
||||
#else
|
||||
f.data = NULL;
|
||||
#endif /* ASTERISK_VERSION_1_6_1 */
|
||||
f.offset = 0;
|
||||
f.src = gsmopen_type;
|
||||
f.mallocd = 0;
|
||||
f.delivery.tv_sec = 0;
|
||||
f.delivery.tv_usec = 0;
|
||||
#endif //0
|
||||
|
||||
//if ((samples = ReadAudioStream(tech_pvt->stream, buf, SAMPLES_PER_FRAME)) == 0)
|
||||
//if ((samples = ReadAudioStream(tech_pvt->stream, data, datalen/sizeof(short))) == 0)
|
||||
if (samples = ReadAudioStream(tech_pvt->stream, (short *)data, datalen, &tech_pvt->timer_read) == 0) {
|
||||
//do nothing
|
||||
} else {
|
||||
#ifdef GIOVA48
|
||||
int i=0, a=0;
|
||||
|
||||
samples = samples / 6;
|
||||
for(i=0; i< samples; i++){
|
||||
buf2[i] = buf[a];
|
||||
a = a + 6; //mono, 1 chan 48 -> 8
|
||||
}
|
||||
buf = buf2;
|
||||
|
||||
#if 0
|
||||
/* A real frame */
|
||||
f.frametype = AST_FRAME_VOICE;
|
||||
f.subclass = AST_FORMAT_SLINEAR;
|
||||
f.samples = GSMOPEN_FRAME_SIZE/6;
|
||||
f.datalen = GSMOPEN_FRAME_SIZE * 2/6;
|
||||
#endif //0
|
||||
#else// GIOVA48
|
||||
#if 0
|
||||
/* A real frame */
|
||||
f.frametype = AST_FRAME_VOICE;
|
||||
f.subclass = AST_FORMAT_SLINEAR;
|
||||
f.samples = GSMOPEN_FRAME_SIZE;
|
||||
f.datalen = GSMOPEN_FRAME_SIZE * 2;
|
||||
#endif //0
|
||||
#endif// GIOVA48
|
||||
|
||||
#if 0
|
||||
#ifdef ASTERISK_VERSION_1_6_1
|
||||
f.data.ptr = buf;
|
||||
#else
|
||||
f.data = buf;
|
||||
#endif /* ASTERISK_VERSION_1_6_1 */
|
||||
f.offset = AST_FRIENDLY_OFFSET;
|
||||
f.src = gsmopen_type;
|
||||
f.mallocd = 0;
|
||||
#endif //0
|
||||
}
|
||||
|
||||
#if 0
|
||||
read(tech_pvt->audiopipe[0], &c, 1);
|
||||
|
||||
return &f;
|
||||
#endif //0
|
||||
#endif //0
|
||||
|
||||
int samples;
|
||||
samples = ReadAudioStream(tech_pvt->stream, (short *)data, datalen, &tech_pvt->timer_read);
|
||||
//WARNINGA("samples=%d\n", GSMOPEN_P_LOG, samples);
|
||||
|
||||
return samples;
|
||||
}
|
||||
int gsmopen_portaudio_shutdown(private_t *tech_pvt)
|
||||
{
|
||||
PaError err;
|
||||
|
||||
err = CloseAudioStream(tech_pvt->stream);
|
||||
|
||||
if (err != paNoError)
|
||||
ERRORA("not able to CloseAudioStream\n", GSMOPEN_P_LOG);
|
||||
|
||||
Pa_Terminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // GSMOPEN_PORTAUDIO
|
||||
#ifndef GSMLIBGIO
|
||||
int gsmopen_serial_init(private_t * tech_pvt, speed_t controldevice_speed)
|
||||
{
|
||||
int fd;
|
||||
|
@ -490,63 +136,6 @@ int gsmopen_serial_init(private_t * tech_pvt, speed_t controldevice_speed)
|
|||
}
|
||||
return (fd);
|
||||
}
|
||||
#else //GSMLIBGIO
|
||||
#ifdef WIN32
|
||||
int gsmopen_serial_init(private_t * tech_pvt, int controldevice_speed)
|
||||
#else
|
||||
int gsmopen_serial_init(private_t * tech_pvt, speed_t controldevice_speed)
|
||||
#endif //WIN32
|
||||
{
|
||||
int i;
|
||||
string ciapa;
|
||||
SMSMessageRef sms;
|
||||
char content2[1000];
|
||||
int size;
|
||||
|
||||
#ifdef WIN32
|
||||
Ref <Port> port = new Win32SerialPort((string) tech_pvt->controldevice_name, 38400);
|
||||
#else
|
||||
//Ref<Port> port = new UnixSerialPort((string)argv[1], B38400);
|
||||
Ref < Port > port = new UnixSerialPort((string) tech_pvt->controldevice_name, B115200);
|
||||
#endif
|
||||
MeTa m(port);
|
||||
|
||||
//cout << "Creating GsmAt object" << endl;
|
||||
Ref <GsmAt> gsmat = new GsmAt(m);
|
||||
|
||||
//cout << "Using GsmAt object" << endl;
|
||||
//cout << gsmat->chat("AT", "OK", false, false) << endl;
|
||||
//cout << gsmat->chat("D3472665618;") << endl;
|
||||
gsmat->putLine("AT+cgmm", true);
|
||||
for (i = 0; i < 4; i++) {
|
||||
ciapa = gsmat->getLine();
|
||||
//cout << "PRESO: |||" << ciapa << "|||" << endl;
|
||||
NOTICA("PRESO %d |||%s|||\n", GSMOPEN_P_LOG, i, ciapa.c_str());
|
||||
//gsmopen_sleep(5000);
|
||||
}
|
||||
|
||||
sms = SMSMessage::decode("079194710167120004038571F1390099406180904480A0D41631067296EF7390383D07CD622E58CD95CB81D6EF39BDEC66BFE7207A794E2FBB4320AFB82C07E56020A8FC7D9687DBED32285C9F83A06F769A9E5EB340D7B49C3E1FA3C3663A0B24E4CBE76516680A7FCBE920725A5E5ED341F0B21C346D4E41E1BA790E4286DDE4BC0BD42CA3E5207258EE1797E5A0BA9B5E9683C86539685997EBEF61341B249BC966"); // dataCodingScheme = 0
|
||||
NOTICA("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
|
||||
sms = SMSMessage::decode("0791934329002000040C9193432766658100009001211133318004D4F29C0E"); // dataCodingScheme = 0
|
||||
NOTICA("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
|
||||
sms = SMSMessage::decode("0791934329002000040C919343276665810008900121612521801600CC00E800E900F900F200E00020006300690061006F"); // dataCodingScheme = 8
|
||||
NOTICA("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
|
||||
sms = SMSMessage::decode("0791934329002000040C919343276665810008900172002293404C006300690061006F0020003100320033002000620065006C00E80020043D043E0432043E044104420438002005DC05E7002005E805D005EA0020FE8EFEE0FEA0FEE4FECBFE9300204EBA5927"); // dataCodingScheme = 8 , text=ciao 123 belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大
|
||||
NOTICA("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
|
||||
sms = SMSMessage::decode("07911497941902F00414D0E474989D769F5DE4320839001040122151820000"); // dataCodingScheme = 0
|
||||
NOTICA("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
|
||||
|
||||
#if 0
|
||||
size = MultiByteToWideChar(CP_OEMCP, 0, username, strlen(username)+1, UserName, 0);
|
||||
UserName=(wchar_t*)GlobalAlloc(GME M_ZEROINIT, size);
|
||||
ret = MultiByteToWideChar(CP_OEMCP, 0, username, strlen(username)+1, UserName, size);
|
||||
if(ret == 0)
|
||||
getError(GetLastError());
|
||||
#endif //0
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#endif //GSMLIBGIO
|
||||
|
||||
|
||||
int gsmopen_serial_read(private_t * tech_pvt)
|
||||
|
|
Loading…
Reference in New Issue