1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <bfin_pflags.h>
#include <edevice.h>
char * pProgName; /* Variable used to store program name availble in argv[0] in main function. */
char * numDes;
char * mySMS;
char * myCommandCMGS;
/********************************************************************
* Display on stdout how to call the program.
*
* ******************************************************************/
static void usage ()
{
printf("Usage: %s <uartSpeed>\n", pProgName);
}
/********************************************************************
* Envoi d'un SMS
* ******************************************************************/
static int sendSMS(int tty)
{
int ttyCmd_result;
char buf[128];
char tmpstr[32];
char * cmgs = NULL;
/* Send "AT\r" command to GPRS module ("OK" answer expected). */
if((edCommand_tty(tty, "AT\r" , "OK", buf, sizeof buf,5)) != 0)
{ /* No OK answer received. */
sleep(1); /* Wait for 1 sec. */
/* Send +++ in case the GPRS module still be in data mode. */
edCommand_tty(tty, "+++", "", buf, sizeof buf,5);
sleep(10); /* Wait 10 seconds. */
/* Send a second "\r" command to GPRS module (no answer expected). */
edCommand_tty(tty, "\r","", buf, sizeof buf,5);
/* Send a second "AT\r" command to GPRS module ("OK" answer expected). */
if((ttyCmd_result = (edCommand_tty(tty, "AT\r" , "OK", buf, sizeof buf,5))) != 0)
{ /* No OK answer received. */
return ttyCmd_result; /* return edCommand_tty() result. */
}
}
if((edCommand_tty (tty, "AT+CMGF=1\n\r", "OK", buf, sizeof(buf), 5))!=0)
{
edLog("Passage en mode Texte");
}
else edLog("Deja en mode texte");
/* Construction de la commande AT */
strcat(myCommandCMGS, "AT+CMGS=\"");
strcat(myCommandCMGS, numDes);
strcat(myCommandCMGS, "\"");
strcat(myCommandCMGS, "\n\r");
if(edCommand_tty(tty, myCommandCMGS , ">", buf, sizeof buf,5)!=0);
{
edLog("SMSSend buf 0 : %s", buf);
edCommand_tty(tty, "titi\x1A" , "+CMGS: ", buf, sizeof buf,10);
edLog("SMSSend buf 1 : %s", buf);
cmgs = strstr(buf, "+CMGS: ");
if(cmgs != NULL)
{ /* "+WMBS: " is found in AT+WMBS? cmd answer. */
if(strlen(cmgs) >= 8) /* 10 = length of "+WMBS: X,0" */
{ /* GSM band value is present in the answer. */
cmgs = cmgs + 7;
edLog("SMSSend : AT+CMGS?=%s", cmgs);
}
else
{ /* No correct value can be retrieved from answer. */
edLog("SMSSend : AT+CMGS?=%s", " 1 NO Correct Value");
return 2;
}
}
else
{ /* No correct value can be retrieved from answer. */
edLog("SMSSend : AT+CMGS?=%s", " 2 NO Correct Value");
edLog("SMSSend buf 2 : %s", buf);
return 2;
}
}
return 0; /* return OK. */
}
int main (int argc, char **argv)
{
int tty;
int retValue = 0;
pProgName = argv[0];
/* Open edevice Log with module_ed_Server name. */
edOpenLog(argv[0], LOG_PID, LOG_LOCAL1);
mySMS = malloc (sizeof(char) * 160);
myCommandCMGS = malloc( sizeof(char) * 23);
numDes = malloc( sizeof(char) * 10);
if (argc != 4)
{
edLog("Main%c Bad arguments on command line", ':');
usage();
edCloseLog(); /* Close edevice Log. */
return 1;
}
else
{
if((tty = edOpenChangeAttr(atoi(argv[1]))) < 0)
{ /* Impossible to open /dev/ttyBF1. */
if(tty == -1)
{ /* No baud field of baudtable[] is equal to the parameter given to the program. */
usage(argv[0]); /* Display on stdout how to use this program. */
}
edCloseLog(); /* Close edevice Log. */
return 1; /* Return Error. */
}
strcpy(numDes,argv[2]);
strcpy(mySMS,argv[3]);
strcat(mySMS,"\032");
}
retValue = sendSMS(tty);
/* Close tty and reinitialize Termio with value saved in edOpenChangeAttr() call. */
edCloseResetAttr(tty);
edCloseLog(); /* Close edevice Log. */
return(retValue);
} |
Partager