#define LOG_TAG "AT"
#include <utils/Log.h>
-#ifdef HAVE_ANDROID_OS
-/* for IOCTL's */
-#include <linux/omap_csmi.h>
-#endif /*HAVE_ANDROID_OS*/
-
#include "misc.h"
-#ifdef HAVE_ANDROID_OS
-#define USE_NP 1
-#endif /* HAVE_ANDROID_OS */
-
#define NUM_ELEMS(x) (sizeof(x)/sizeof(x[0]))
static char s_ATBuffer[MAX_AT_RESPONSE+1];
static char *s_ATBufferCur = s_ATBuffer;
-static int s_ackPowerIoctl; /* true if TTY has android byte-count
- handshake for low power*/
-static int s_readCount = 0;
-
#if AT_DEBUG
void AT_DUMP(const char* prefix, const char* buff, int len)
{
if (len < 0)
len = strlen(buff);
- ALOGD("%.*s", len, buff);
+ RLOGD("%.*s", len, buff);
}
#endif
static int writeCtrlZ (const char *s);
static int writeline (const char *s);
-#ifndef USE_NP
+#define NS_PER_S 1000000000
static void setTimespecRelative(struct timespec *p_ts, long long msec)
{
struct timeval tv;
gettimeofday(&tv, (struct timezone *) NULL);
- /* what's really funny about this is that I know
- pthread_cond_timedwait just turns around and makes this
- a relative time again */
p_ts->tv_sec = tv.tv_sec + (msec / 1000);
p_ts->tv_nsec = (tv.tv_usec + (msec % 1000) * 1000L ) * 1000L;
+ /* assuming tv.tv_usec < 10^6 */
+ if (p_ts->tv_nsec >= NS_PER_S) {
+ p_ts->tv_sec++;
+ p_ts->tv_nsec -= NS_PER_S;
+ }
}
-#endif /*USE_NP*/
static void sleepMsec(long long msec)
{
break;
default: /* this should never be reached */
- ALOGE("Unsupported AT command type %d\n", s_type);
+ RLOGE("Unsupported AT command type %d\n", s_type);
handleUnsolicited(line);
break;
}
while (p_eol == NULL) {
if (0 == MAX_AT_RESPONSE - (p_read - s_ATBuffer)) {
- ALOGE("ERROR: Input line exceeded buffer\n");
+ RLOGE("ERROR: Input line exceeded buffer\n");
/* ditch buffer and start over again */
s_ATBufferCur = s_ATBuffer;
*s_ATBufferCur = '\0';
if (count > 0) {
AT_DUMP( "<< ", p_read, count );
- s_readCount += count;
p_read[count] = '\0';
} else if (count <= 0) {
/* read error encountered or EOF reached */
if(count == 0) {
- ALOGD("atchannel: EOF reached");
+ RLOGD("atchannel: EOF reached");
} else {
- ALOGD("atchannel: read error %s", strerror(errno));
+ RLOGD("atchannel: read error %s", strerror(errno));
}
return NULL;
}
s_ATBufferCur = p_eol + 1; /* this will always be <= p_read, */
/* and there will be a \0 at *p_read */
- ALOGD("AT< %s\n", ret);
+ RLOGD("AT< %s\n", ret);
return ret;
}
}
-static void *readerLoop(void *arg)
+static void *readerLoop(void *arg __unused)
{
for (;;) {
const char * line;
line2 = readline();
if (line2 == NULL) {
+ free(line1);
break;
}
} else {
processLine(line);
}
-
-#ifdef HAVE_ANDROID_OS
- if (s_ackPowerIoctl > 0) {
- /* acknowledge that bytes have been read and processed */
- ioctl(s_fd, OMAP_CSMI_TTY_ACK, &s_readCount);
- s_readCount = 0;
- }
-#endif /*HAVE_ANDROID_OS*/
}
onReaderClosed();
return AT_ERROR_CHANNEL_CLOSED;
}
- ALOGD("AT> %s\n", s);
+ RLOGD("AT> %s\n", s);
AT_DUMP( ">> ", s, strlen(s) );
return AT_ERROR_CHANNEL_CLOSED;
}
- ALOGD("AT> %s^Z\n", s);
+ RLOGD("AT> %s^Z\n", s);
AT_DUMP( ">* ", s, strlen(s) );
s_smsPDU = NULL;
sp_response = NULL;
- /* Android power control ioctl */
-#ifdef HAVE_ANDROID_OS
-#ifdef OMAP_CSMI_POWER_CONTROL
- ret = ioctl(fd, OMAP_CSMI_TTY_ENABLE_ACK);
- if(ret == 0) {
- int ack_count;
- int read_count;
- int old_flags;
- char sync_buf[256];
- old_flags = fcntl(fd, F_GETFL, 0);
- fcntl(fd, F_SETFL, old_flags | O_NONBLOCK);
- do {
- ioctl(fd, OMAP_CSMI_TTY_READ_UNACKED, &ack_count);
- read_count = 0;
- do {
- ret = read(fd, sync_buf, sizeof(sync_buf));
- if(ret > 0)
- read_count += ret;
- } while(ret > 0 || (ret < 0 && errno == EINTR));
- ioctl(fd, OMAP_CSMI_TTY_ACK, &ack_count);
- } while(ack_count > 0 || read_count > 0);
- fcntl(fd, F_SETFL, old_flags);
- s_readCount = 0;
- s_ackPowerIoctl = 1;
- }
- else
- s_ackPowerIoctl = 0;
-
-#else // OMAP_CSMI_POWER_CONTROL
- s_ackPowerIoctl = 0;
-
-#endif // OMAP_CSMI_POWER_CONTROL
-#endif /*HAVE_ANDROID_OS*/
-
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
long long timeoutMsec, ATResponse **pp_outResponse)
{
int err = 0;
-#ifndef USE_NP
struct timespec ts;
-#endif /*USE_NP*/
if(sp_response != NULL) {
err = AT_ERROR_COMMAND_PENDING;
s_smsPDU = smspdu;
sp_response = at_response_new();
-#ifndef USE_NP
if (timeoutMsec != 0) {
setTimespecRelative(&ts, timeoutMsec);
}
-#endif /*USE_NP*/
while (sp_response->finalResponse == NULL && s_readerClosed == 0) {
if (timeoutMsec != 0) {
-#ifdef USE_NP
- err = pthread_cond_timeout_np(&s_commandcond, &s_commandmutex, timeoutMsec);
-#else
err = pthread_cond_timedwait(&s_commandcond, &s_commandmutex, &ts);
-#endif /*USE_NP*/
} else {
err = pthread_cond_wait(&s_commandcond, &s_commandmutex);
}