Bonjour à tous,

Je poste sur le forum parce que je suis désespéré.
Voilà 3 jours que je cherche une solution à mon problème mais je ne l'ai toujours pas trouvé, peut être pourrez vous m'aider.

Je suis en stage et je suis en train de développer un serverSMS.

Pour cela, je suis en train de faire un programme en C tout simple qui récupère 2 arguments, le numéro et le message texte.

Dans le protocole SMS, pour envoyer un SMS par un module GSM il suffit de faire les commandes AT+CMGS ="mon num" [ENTER]
un prompt apparait ">" taper son SMS et le finir par [CTRL Z]

Je fais ça sur un µCLinux sur un BlackFin.

Je mets mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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);
}
edCommand_tty communique avec le port RS232, avec le num du port, la commande, la réponse de la commande, un buffer qui récupère la réponse, la taille du buf, et un timeout d'attente.

edLog est utilisé pour récupéré dans un fichier texte les logs...

Donc quand je lance mon application je reçois ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: send AT^M
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: wait for answer OK to AT^M
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: got AT^M^M OK^M 
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: send AT+CMGF=1 ^M
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: wait for answer OK to AT+CMGF=1 ^M
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: got AT+CMGF=1 ^M^M OK^M 
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: Deja en mode texte
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: send AT+CMGS="lenuméro" ^M
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: wait for answer > to AT+CMGS="lenuméro" ^M
Jan  1 04:56:42 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: got AT+CMGS="lenuméro" ^M^M > ^M 
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: SMSSend buf 0 : AT+CMGS="lenuméro" ^M^M > ^M 
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: send titi^Z
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: wait for answer +CMGS:  to titi^Z
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: edCommand_tty: got ERROR^M 
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: SMSSend buf 1 : ERROR^M 
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: SMSSend : AT+CMGS?= 2 NO Correct Value
Jan  1 04:56:43 routeD230 local1.debug ./bin/serverSMS[230]: SMSSend buf 2 : ERROR^M
j'ai mis mon SMS en dur pour les tests.

Sauriez vous comment envoyer le contrôle Z autrement ?

J'ai même modifié la communication avec le RS232 : quand on tape stty -a < /dev/ttyBF1

il mets que le SUSP = <undef> donc que le CTRL Z n'est plus pris comme une commande système qui pourrait bloquer mon application.

Je perds énormément de temps la dessus. Si quelqu'un peut m'aider, je l'en remercierai de 100 000 bisous.

Sylvanocry