I'm developing a program that send at-command to GSM modem and I want to read the response.
Some programmers advice me to use atinout
program in this link.
so I ported to android and simplify the code to this C code, because I don't want to use files (input and output):
JNIEXPORT jstring JNICALL Java_com_marakana_NativeLib_hello(JNIEnv * env, jobject obj)
{
FILE *modem;
char *line="AT\r";
bool success;
int res;
modem = fopen("/dev/smd0", "r+b");
if (modem == NULL)
return (*env)->NewStringUTF(env, "2fopen() failed: /dev/smd0\n");
res = fputs(line, modem);
if (res < 0)
return (*env)->NewStringUTF(env, ("5failed to send '%s' to modem res = " + res,line));
line = fgets(buf, (int)sizeof(buf), modem);
if (line == NULL)
return (*env)->NewStringUTF(env, "6EOF from modem\n");
strcpy(buf2, line);
strip_cr(buf2);
res = fclose(modem);
if (res != 0)
return (*env)->NewStringUTF(env, ("9closing modem failed: %s\n", strerror(errno)));
return (*env)->NewStringUTF(env, buf2);
}
static void strip_cr(char *s)
{
char *from, *to;
from = to = s;
while (*from != '\0') {
if (*from == '\r') {
from++;
continue;
}
*to++ = *from++;
}
*to = '\0';
}
The problem is:
The modem response is the same request. That mean I received AT
from the function.
note: my mobile is Samsung Galaxy Win Duos.
Is the problem in the modem of my mobile. or in my code? how can I get the response of at command?