[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paparazzi-commits] [4757] test in sim
From: |
Pascal Brisset |
Subject: |
[paparazzi-commits] [4757] test in sim |
Date: |
Mon, 29 Mar 2010 15:45:52 +0000 |
Revision: 4757
http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4757
Author: hecto
Date: 2010-03-29 15:45:52 +0000 (Mon, 29 Mar 2010)
Log Message:
-----------
test in sim
Modified Paths:
--------------
paparazzi3/trunk/sw/airborne/modules/gsm/gsm.c
Modified: paparazzi3/trunk/sw/airborne/modules/gsm/gsm.c
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/gsm/gsm.c 2010-03-29 15:44:46 UTC
(rev 4756)
+++ paparazzi3/trunk/sw/airborne/modules/gsm/gsm.c 2010-03-29 15:45:52 UTC
(rev 4757)
@@ -39,6 +39,7 @@
#include "autopilot.h"
#include "estimator.h"
#include "common_nav.h"
+#include "settings.h"
#ifndef GSM_LINK
#define GSM_LINK Uart3100
@@ -60,18 +61,15 @@
#define DATA_MAXLEN 128
#define CMTI "+CMTI:"
+#define MAXLEN_CMTI_ANSWER 32
+#define MAXLEN_SMS_CONTENT DATA_MAXLEN
static bool gsm_line_received;
static bool prompt_received;
-static bool wait_data; /* Waiting for message content after header */
-static bool is_receiving; /* +CMTI has been received, true until contents has
been parsed */
static bool waiting_for_reply; /* An AT command has been sent and an answer is
expected */
-static bool init_done;
-static bool waiting_prompt;
-static bool msg_sent;
-static char msg_status[16];
-static char msg_date[32];
+// static char msg_status[16];
+// static char msg_date[32];
static char expected_ack[10];
static char gsm_buf[GSM_MAX_PAYLOAD] __attribute__ ((aligned));
@@ -87,9 +85,13 @@
#define STATUS_SEND_CNMI 5
#define STATUS_SEND_CPMS 6
#define STATUS_RECEPTION_SMS2 7
+#define STATUS_WAITING_DATA 8
+#define STATUS_IDLE 9
+#define STATUS_WAITING_PROMPT 10
+#define STATUS_DELETE_SMS 11
+
static uint8_t gsm_status = STATUS_NONE;
-static uint8_t nb_received_lines = 0;
static uint8_t index_msg;
static void Send_AT(void);
@@ -103,10 +105,10 @@
static void gsm_got_prompt(void);
static void gsm_receive_content(void);
static void request_for_msg(void);
-static void Extraction(char source[], char char_dbt, int nb_occurence1, int
decalage1, char char_fin, int nb_occurence2, int decalage2, char destination[]);
static void Send_CSQ(void);
static void Send(const char string[]);
static void parse_msg_header(void);
+static char* indexn(char*, char, uint8_t);
@@ -116,17 +118,16 @@
void gsm_init(void) {
gsm_buf_idx = 0;
gsm_line_received = false;
- init_done = false;
- waiting_prompt = false;
- msg_sent = true;
Send_AT();
+ gsm_status = STATUS_SEND_AT;
}
void gsm_event(void) {
- if (GSMBuffer())
+ if (GSMBuffer()) {
ReadGSMBuffer();
+ }
if (gsm_line_received) {
gsm_got_line();
@@ -141,17 +142,22 @@
// A line of length gsm_buf_len is available in the gsm_buf buffer
static void gsm_got_line(void)
{
- if (wait_data) { // Currently receiving a SMS
+ if (gsm_status == STATUS_WAITING_DATA) { // Currently receiving a SMS
gsm_receive_content();
- } else if ((strncmp(CMTI, gsm_buf, strlen(CMTI)) == 0)
- && (!is_receiving)) { /* A SMS is available */
-
+ Suppr_SMS(index_msg);
+ gsm_status = STATUS_DELETE_SMS;
+ } else if (gsm_status == STATUS_IDLE
+ && strncmp(CMTI, gsm_buf, strlen(CMTI)) == 0) {
+ /* A SMS is available */
+ /***/printf("CMTI: %s\n", gsm_buf);
/* Extracting the index of the message */
- char first_comma = index(gsm_buf, ',');
+ char * first_comma = indexn(gsm_buf, ',',MAXLEN_CMTI_ANSWER);
+ /***/printf("CMTI: com=%d\n", first_comma - gsm_buf);
if (first_comma) {
index_msg = atoi(first_comma+1);
- is_receiving = true;
+ /***/printf("CMTI: index=%d\n", index_msg);
request_for_msg();
+ gsm_status = STATUS_REQUESTING_MESSAGE;
}
} else if (waiting_for_reply) { // Other cases
// Do we get what we were expecting
@@ -163,33 +169,41 @@
switch(gsm_status) {
case STATUS_CSQ :
gsm_send_report_continue();
+ gsm_status = STATUS_WAITING_PROMPT;
break;
case STATUS_REQUESTING_MESSAGE:
parse_msg_header();
- wait_data = true;
+ gsm_status = STATUS_WAITING_DATA;
break;
case STATUS_SEND_AT :
gsm_answer = false;
Send_CMGF();
+ gsm_status = STATUS_SEND_CMGF;
break;
case STATUS_SEND_CMGF :
gsm_answer = false;
Send_CNMI();
+ gsm_status = STATUS_SEND_CNMI;
break;
case STATUS_SEND_CNMI :
gsm_answer = false;
Send_CPMS();
+ gsm_status = STATUS_SEND_CPMS;
break;
case STATUS_SEND_CPMS :
gsm_answer = false;
- init_done = true;
+ gsm_status = STATUS_IDLE;
break;
+ case STATUS_DELETE_SMS :
+ gsm_status = STATUS_IDLE;
+ break;
+
default:
break;
}
@@ -204,11 +218,10 @@
// Receiving a SMS, first step: asking for a given message
static void request_for_msg(void)
{
- char demande_lecture_SMS[10];
+ char demande_lecture_SMS[16];
strcpy(expected_ack, "+CMGR");
sprintf(demande_lecture_SMS, "AT+CMGR=%d", index_msg);
- gsm_status = STATUS_REQUESTING_MESSAGE;
waiting_for_reply = true;
Send(demande_lecture_SMS);
}
@@ -221,38 +234,34 @@
*/
static void gsm_receive_content(void)
{
- char instruction[15], index_block[2];
-
- wait_data = false;
-
// ?????? sprintf(data_to_send, "%d %s %s %s %s", index_msg, flag,
expediteur, dateheure, data_recue);
// ?????? Send(data_to_send);
// Checking the number of the sender
- if (strncmp((char*)GCS_NUMBER, origin, strlen(GCS_NUMBER)) == 0) {
+ if (true || strncmp((char*)GCS_NUMBER, origin, strlen(GCS_NUMBER)) == 0) {
// Decoding the message ...
// Search for the instruction
switch (gsm_buf[0]) {
- case 'B' :
+ case 'B' : {
uint8_t block_index = atoi(gsm_buf+1);
if (block_index > 0) /* Warning: no way to go to the first block */
nav_goto_block(block_index);
break;
-
- case 'S' :
+ }
+ case 'S' : {
uint8_t var_index = atoi(gsm_buf+1);
if (var_index > 0) {
- float value = atof(index(gsm_buf, ' ')+1);
+ float value = atof(indexn(gsm_buf, ' ',MAXLEN_SMS_CONTENT)+1);
DlSetting(var_index, value);
}
+ }
default:
+ // Report an error ???
+ break;
}
}
- Suppr_SMS(index_msg);
-
- is_receiving = false;
}
@@ -263,29 +272,22 @@
sprintf(demande_suppression, "AT+CMGD=%d", index_);
strcpy(expected_ack, "OK");
+ waiting_for_reply = true;
Send(demande_suppression);
}
-// Sending a SMS, first step: send the number and wait for the prompt
-static void Send_Msg(void)
-{
- waiting_prompt = true;
-
- Send("AT+CMGS=\"+33617802096\"\0");
-}
-
// We just have received a prompt ">" (we are sending a SMS)
static void gsm_got_prompt(void)
{
- if (waiting_prompt) { // We were waiting for a prompt
+ if (gsm_status == STATUS_WAITING_PROMPT) { // We were waiting for a prompt
char string[strlen(data_to_send) +3];
sprintf(string, "%s%c", data_to_send, CTRLZ);
Send(string);
}
- waiting_prompt = false;
+ gsm_status = STATUS_IDLE;
}
/** Message header in gsm_bug
@@ -296,10 +298,10 @@
/** Extraction(buffer2, '"', 1, 1, '"', 1, 0, msg_status); */
/* Extraction de l'expediteur*/
- Extraction(buffer2, '"', 2, 1, '"', 1, 0, origin);
+ // Extraction(buffer2, '"', 2, 1, '"', 1, 0, origin);
/* Extraction de date heure*/
- Extraction(buffer2, '"', 4, 1, '"', 1, 0, msg_date);
+ // Extraction(buffer2, '"', 4, 1, '"', 1, 0, msg_date);
//pb d'ecriture du flag => solution de fortune (pb si flag != rec unread)
//??????? strncpy(flag, flag, 10);
@@ -310,11 +312,11 @@
// Periodic message, first step (called every 60s)
void gsm_send_report()
{
- if(init_done && msg_sent) {
- msg_sent = false;
-
+ /***/printf("send_report: %d\n", gsm_status);
+ if(gsm_status == STATUS_IDLE) {
// Checking the network coverage
Send_CSQ();
+ gsm_status = STATUS_CSQ;
}
}
@@ -322,22 +324,19 @@
// Sending a message, second step; we have asked for network quality
void gsm_send_report_continue(void)
{
- char qualite_signal_GSM[5];
-
- //We got "+CSQ:" (and we expect "ok" on the second line ???)
- Extraction(gsm_buf, ':', 1, 2, '\r', 1, 0, qualite_signal_GSM);
-
- qualite_signal_GSM[4] = '\0';
+ //We got "+CSQ: <rssi>,<ber>" <rssi> and <ber> on 2 digits (cf 3.5.4.4.4)
+ // and we expect "OK" on the second line
+ uint8_t rssi = atoi(gsm_buf + strlen("+CSQ: "));
// Donnee GPS :ne sont pas envoyes gps_mode, gps_itow, gps_utm_zone,
gps_nb_ovrn
// Donnees batterie (seuls vsupply et estimator_flight_time sont envoyes)
// concatenation de toutes les infos en un seul message à transmettre
- sprintf(data_to_send, "%ld %ld %d %ld %d %d %d %d %s", gps_utm_east,
gps_utm_north, gps_course, gps_alt, gps_gspeed, gps_climb, vsupply,
estimator_flight_time, qualite_signal_GSM);
-
- // Envoi du SMS
- Send_Msg();
-
- msg_sent = true;
+ sprintf(data_to_send, "%d %d %d %d %d %d %d %d %d", gps_utm_east,
gps_utm_north, gps_course, gps_alt, gps_gspeed, gps_climb, vsupply,
estimator_flight_time, rssi);
+
+ // send the number and wait for the prompt
+ char buf[32];
+ sprintf(buf, "AT+CMGS=\"%s\"", GCS_NUMBER);
+ Send(buf);
}
@@ -346,7 +345,6 @@
static void Send_AT(void)
{
strcpy(expected_ack, "OK");
- gsm_status = STATUS_SEND_AT;
waiting_for_reply = true;
Send("AT");
@@ -355,15 +353,13 @@
static void Send_CMGF(void)
{
strcpy(expected_ack, "OK");
- gsm_status = STATUS_SEND_CMGF;
waiting_for_reply = true;
Send("AT+CMGF=1");
}
static void Send_CSQ(void)
{
- strcpy(expected_ack, "OK");
- gsm_status = STATUS_CSQ;
+ strcpy(expected_ack, "+CSQ:");
waiting_for_reply = true;
Send("AT+CSQ");
}
@@ -371,7 +367,6 @@
static void Send_CNMI(void)
{
strcpy(expected_ack, "OK");
- gsm_status = STATUS_SEND_CNMI;
waiting_for_reply = true;
Send("AT+CNMI=1,1,0,0,0");
}
@@ -379,37 +374,16 @@
static void Send_CPMS(void)
{
strcpy(expected_ack, "+CPMS:");
- gsm_status = STATUS_SEND_CPMS;
waiting_for_reply = true;
Send("AT+CPMS=\"SM\"");
}
-static uint8_t indexn(const char* string, char c, int nb_occ)
-{
- uint8_t nb_trouve = 0, i = 0;
-
- while(string[i] && nb_trouve < nb_occ) {
- if(string[i] == c) {
- nb_trouve++;
- }
- i++;
- }
-
- if (nb_trouve == nb_occ)
- return i-1;
- else
- return -1;
-}
-
-
-
static void gsm_parse(uint8_t c) {
+ /*** fprintf(stderr, "gsm_parse:%c\n", c); ***/
switch(c) {
- case '\n':
- /* ignore */
- break;
- case '\r':
+ case GSM_CR:
+ gsm_buf[gsm_buf_idx] = '\0';
gsm_line_received = true;
gsm_buf_len = gsm_buf_idx;
gsm_buf_idx=0;
@@ -433,31 +407,16 @@
int i = 0;
while(string[i])
- GSMTransmit(string[i]);
- GSMTransmit('\r');
+ GSMTransmit(string[i++]);
+ GSMTransmit(GSM_CR);
}
-static void Extraction(char source[], char char_dbt, int nb_occurence1, int
decalage1, char char_fin, int nb_occurence2, int decalage2, char destination[])
-{
- int indice_debut, indice_fin, i, rch1, rch2;
-
- rch1 = indexn(source, char_dbt, nb_occurence1);
-
- if(rch1 == -1)
- strncpy(destination, "0", 1);
- else {
- indice_debut = rch1 + decalage1;
- for(i=0; i<strlen(source); i++)
- source[i] = source[i+indice_debut];
-
- rch2 = indexn(source, char_fin, nb_occurence2);
-
- if(rch2 == -1)
- strncpy(destination, "0", 1);
- else {
- indice_fin = rch2 + decalage2;
- strncpy(destination, source, indice_fin);
- destination[indice_fin] = '\0';
- }
+/* Returns a pointer to the first occurrence of the character c in the firtn
+ n chars of string s. Return NULL if not found */
+static char* indexn(char* s, char c, uint8_t n) {
+ while(n && (*s != c)) {
+ n--;
+ s++;
}
+ return (n ? s : NULL);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paparazzi-commits] [4757] test in sim,
Pascal Brisset <=