Hoi,

ik ben met een project bezig waarmee we gebruik maken van een wavecom modem die een atmega2560 bij één van de c-codes ben ik tegen een probleem aangelopen en ik zou wat hulp kunnen gebruiken.

#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <ctype.h>

#include "include/main.h"
#include "include/modemconnection.h"
#include "include/util.h"
#include "include/terminalconnection.h"
#include "include/delay_x.h"

/**************************************************************************************
 **************************************************************************************
 *               WARNING   WARNING   WARNING
 *
 * When using the modem function with your own SIM card, please expect unexpected
 * behaviour! Your saved text messages aren't safe, they could be erased! Take special
 * care for SIM cards with a PIN number. If your SIM card has a PIN number please
 * search this file for "1234" and replace it. Don't risk blocking your SIM!!
 *
 **************************************************************************************
 **************************************************************************************
 */

//This code communicates with the Wavecom modem. The problem (or one of the problems)
//with this is that the modem works asynchrous with the Atmel. Therefore we have to
//introduce states for each function. If a request is currently being executed (getting
//the sms info for example) and new request is submitted (ie. get network status)
//the latter is placed on an execution stack. As soon as the first request is completely
//processed, the next one is pop-ed from the stack and executed.

#define BAUDRATE   		115200
#define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16L)-1)

static void _pushCommand(int command, void *data);
static void _processCommands();
static char _handleATcommand();
static char _handleWriteSMS();
static char _handleReadSMS();
static char _handlePIN();
static void _mc_flushInputBuffer();

#define UCSRA 			UCSR0A
#define UCSRB			UCSR0B
#define RXCIE			RXCIE0
#define TXCIE			TXCIE0
#define RXEN			RXEN0
#define TXEN			TXEN0
#define UBRRH			UBRR0H
#define UBRRL			UBRR0L
#define UDR				UDR0
#define UDRIE			UDRIE0
#define SIG_USART_RECV	SIG_USART0_RECV
#define SIG_USART_DATA	SIG_USART0_DATA

#define UPE 	2
#define OVR		3
#define FE 		4
#define UDRE 	5

#define FRAMING_ERROR 			(1<<FE)
#define PARITY_ERROR 			(1<<UPE)
#define DATA_OVERRUN 			(1<<OVR)
#define DATA_REGISTER_EMPTY 	(1<<UDRE)
#define RX_COMPLETE 			(1<<RXC)

// USART Receiver buffer
#define RX_BUF_SIZE 		255
static char rx_buf[RX_BUF_SIZE];

#if RX_BUF_SIZE<256
static unsigned char rx_wr_idx, rx_rd_idx;
static volatile unsigned char rx_cnt;
#else
static unsigned int rx_wr_idx, rx_rd_idx;
static volatile unsigned int rx_cnt;
#endif

// USART Transmitter buffer
#define TX_BUF_SIZE 128
static char tx_buf[TX_BUF_SIZE];

#if TX_BUF_SIZE<256
static unsigned char tx_wr_idx, tx_rd_idx;
static volatile unsigned char tx_cnt;
#else
static unsigned int tx_wr_idx, tx_rd_idx;
static volatile unsigned int tx_cnt;
#endif

//Defines the different states the modem can be in
#define STATE_INIT 					0
#define STATE_WAIT_FOR_RESPONSE		1
#define STATE_ACTIVE 				2
#define STATE_RESET					3
#define STATE_WAIT_FOR_PIN			4

static uint64_t mInitTimer;
static uint64_t mSmsPollTimer;
static uint64_t _mTimer;
static unsigned char mState;
static unsigned char mSubState;
static volatile char mLinesReceived;

//Defines the different functions we can execute on the modem
#define CMD_AT						1
#define CMD_SENDSMS					2
#define CMD_READSMS					3
#define CMD_PIN						4

struct SMS {
	char *phoneNumber;
	char *message;
};

struct COMMAND {
	unsigned char cmd;
	void* data;
	struct COMMAND* next;
};

static struct COMMAND* mCommandStack;
static char mResponseReceived;
static char mQualityToggle;

int modemconnection_mCommandsPending;

struct PARSEINFO {
	char *msg;
	char done;
};

//local functions (needed for forward declarations)
static char _mc_getc();
static inline char _mc_dataAvailable();

DATETIME mNow;

//------------------------------------------------------------------------------------------------
void modemconnection_initialize()
{
    UCSRA = 0x00; //Clear send and receive flags

    UBRRH = (unsigned char)(UART_BAUD_SELECT(BAUDRATE, F_CPU)>>8);
    UBRRL = (unsigned char)UART_BAUD_SELECT(BAUDRATE, F_CPU);
    UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXEN);

	SET_OUTPUT(OUT_MODEM_ON, TRUE);
	SET_OUTPUT(OUT_MODEM_RTS, TRUE); //disable me first?

	mCommandStack = NULL;
	modemconnection_mCommandsPending = 0;
	mQualityToggle = FALSE;

	mInitTimer = main_getTime() + 8000;
	mSubState = 0;
	mLinesReceived = 0;
	mState = STATE_INIT;
}

//------------------------------------------------------------------------------------------------
void modemconnection_reset()
{
	//This will trigger the reset line of the modem and will reset the software
	//initialization as well
	SET_OUTPUT(OUT_MODEM_RESET, TRUE);
	mInitTimer = main_getTime() + 2000;
	mState = STATE_RESET;
}

//------------------------------------------------------------------------------------------------
char modemconnection_isActive()
{
	//Can be used to test if it makes sense to use the modem
	return mState == STATE_ACTIVE;
}

void _goToActive()
{
	terminalconnection_sendP(PSTR("log\tModem is now active."));
	mState = STATE_ACTIVE;
}

//------------------------------------------------------------------------------------------------
void modemconnection_update()
{
	//This function should be called by the main program each program loop.

	//Deal with any pending command
	_processCommands();

	switch (mState)
	{
	case STATE_INIT:
		//We have just (re)booted, wait a while and then send some initializer
		//commands to the modem.
		if (main_timerExpired(mInitTimer))
		{
			_mc_flushInputBuffer();
			//Reset and disable echoing
			modemconnection_sendATcommand("\r\n\r\natz\r\nate0\r\n");
			mState = STATE_WAIT_FOR_RESPONSE;
		}
		break;

	case STATE_WAIT_FOR_RESPONSE:
		//We have just sent some stuff to the modem, see if anything comes back
		if (mResponseReceived)
		{
			mSubState = 0;
			_pushCommand(CMD_AT, "AT+CGREG?\r\n");
			terminalconnection_sendP(PSTR("log\tAttempting to establish GPRS connection..."));
			_pushCommand(CMD_PIN, NULL);
			mState = STATE_WAIT_FOR_PIN;
			terminalconnection_sendP(PSTR("log\tModem is now active."));
			mState = STATE_ACTIVE;
		}
		break;

	case STATE_WAIT_FOR_PIN:
		// We're just waiting for _handlePIN() to finish
		break;

	case STATE_ACTIVE:
		//Poll for incoming SMS messages every other 30 seconds
		if (main_timerExpired(mSmsPollTimer))
		{
			_pushCommand(CMD_READSMS, NULL);
			mSmsPollTimer = main_getTime() + 30000;
		}
		break;

	case STATE_RESET:
		//Modem is resetting, when done re-initialze
		if (main_timerExpired(mInitTimer))
		{
			SET_OUTPUT(OUT_MODEM_RESET, FALSE);
			mInitTimer = main_getTime() + 8000;
			mSubState = 0;
			mState = STATE_INIT;
		}
		break;
	}
}

//------------------------------------------------------------------------------------------------
static void _pushCommand(int command, void *data)
{
	//Each request to the modem is executed sequentially. One first need to be finished completely
	//before the next can be excuted.
	//Limit the amount of commands we buffer. If you get a buffer overflow on of the previous
	//commands is probably not terminated properly
	if (modemconnection_mCommandsPending >= 10)
	{
		terminalconnection_send("log\tModem command %d rejected (stack overflow).", command);
		return;
	}

	//Create a container for this command to put on the stack
	struct COMMAND* previous = NULL;
	struct COMMAND* ptr = mCommandStack;

	struct COMMAND* new = malloc(sizeof(struct COMMAND));

	if (new == NULL)
	{
		terminalconnection_sendP(PSTR("log\tUnable to allocate space for modem command."));
		return;
	}

	//The 'stack' we use is actually a linked list. Add the new command to the end of the linked
	//list

	new->cmd = command;
	new->data = data;
	new->next = NULL;

	while (ptr != NULL)
	{
		previous = ptr;
		ptr = ptr->next;
	}

	if (previous != NULL)
	{
		previous->next = new;
	}
	else
	{
		mCommandStack = new;
	}

	modemconnection_mCommandsPending++;
}

//------------------------------------------------------------------------------------------------
static void _popCommand()
{
	//Remove the first element from the linked list (if any)

	if (mCommandStack != NULL)
	{
		struct COMMAND* next = mCommandStack->next;
		free(mCommandStack->data);
		free(mCommandStack);
		mCommandStack = next;

		modemconnection_mCommandsPending--;
	}
}

//------------------------------------------------------------------------------------------------
static void _processCommands()
{
	static uint64_t delayTimer;
	static char reset = TRUE;
	//If command stack points to NULL, there are no commands pending
	if (mCommandStack != NULL  && main_timerExpired(delayTimer))
	{
		char done = FALSE;

		if (reset)
		{
			//Clear every modem output that is left by the previous command
			mSubState = 0;
			_mc_flushInputBuffer();
			reset = FALSE;
		}
		else
		{
			//For each possible command we have a command handler. This actually
			//should be a function pointer in the COMMAND struct to make it more
			//generic (and less ugly)
			switch (mCommandStack->cmd)
			{
				case CMD_AT:
					done = _handleATcommand();
					break;
				case CMD_SENDSMS:
					done = _handleWriteSMS();
					break;
				case CMD_READSMS:
					done = _handleReadSMS();
					break;
				case CMD_PIN:
					done = _handlePIN();
					break;
				default:
					terminalconnection_sendP(PSTR("log\tUnknown modem command on stack."));
					done = TRUE;
			}

			if (done /*|| main_mTime >= mTimeOutTime*/)
			{
				_popCommand();
				delayTimer = main_getTime() + 1500;
				reset = TRUE;
			}
		}
	}
}

//------------------------------------------------------------------------------------------------
// USART Receiver interrupt service routine
SIGNAL(SIG_USART_RECV)
{
	static char previousData = 0;
	char data = UDR;
	unsigned char uart_error = UCSRA & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN);

	if (uart_error == 0)
	{
		if (rx_cnt < RX_BUF_SIZE)
		{
			//Add the received byte to the input buffer
			rx_buf[rx_wr_idx] = data;
			rx_wr_idx++;
			if (rx_wr_idx >= RX_BUF_SIZE)
			{
				rx_wr_idx = 0;
			}
			rx_cnt++;
			if (rx_cnt >= (RX_BUF_SIZE*80/100))
			{
				//SET_OUTPUT(OUT_MODEM_RTS, FALSE);
			}

			//The next lines help us detecting a complete line has been output
			//by the modem
			if (data == 10 && previousData == 13)
			{
				mLinesReceived++;
			}
			previousData = data;
		}
	}
	else
	{
		//error |= uart_error;
	}
}


//------------------------------------------------------------------------------------------------
// USART Data register empty interrupt service routine
SIGNAL(SIG_USART_DATA)
{
	if (tx_cnt)
	{
		//There is stuff left to send, send it
		UDR = tx_buf[tx_rd_idx];
		tx_rd_idx++;
		if (tx_rd_idx >= TX_BUF_SIZE)
		{
			tx_rd_idx = 0;
		}
		tx_cnt--;
	}
	else
	{
		//Nothing more to send, disable the interrupt
		UCSRB &= ~_BV(UDRIE);
	}
}

//------------------------------------------------------------------------------------------------
// Write a character to the USART Transmitter buffer
static void _mc_putc(char c)
{
	while (tx_cnt >= TX_BUF_SIZE);
	//TODO: Add a break out mechanism here

	if (tx_cnt || ((UCSRA & DATA_REGISTER_EMPTY)==0))
	{
		tx_buf[tx_wr_idx] = c;
		tx_wr_idx++;
		if (tx_wr_idx >= TX_BUF_SIZE)
		{
			tx_wr_idx = 0;
		}
		UCSRB &= ~_BV(UDRIE); //Might not be necessary
		tx_cnt++;
	}
	else
	{
		UDR = c;
	}
	UCSRB |= _BV(UDRIE);
}

//------------------------------------------------------------------------------------------------
static inline char _mc_dataAvailable()
{
	return rx_cnt>0;
}

//------------------------------------------------------------------------------------------------
static void _mc_flushInputBuffer()
{
	//TODO: Test me with only disabling the RX interrupt for this UART
	//UCSRB &= ~ _BV(RXCIE);
	cli();
	rx_rd_idx = 0;
	rx_wr_idx = 0;
	rx_cnt = 0;
	sei();
	//UCSRB |= _BV(RXCIE);
}

//------------------------------------------------------------------------------------------------
static char _mc_getc()
{
	char c;

	while (rx_cnt == 0)
	{
		//TODO: Avoid this!!!!
	}

	c = rx_buf[rx_rd_idx];
	if (++rx_rd_idx == RX_BUF_SIZE)
	{
		rx_rd_idx = 0;
	}
	cli();
	rx_cnt--;
	sei();

	if (rx_cnt <= (RX_BUF_SIZE*60/100))
	{
		//TODO Fix and test RTS/CTS things here
		//SET_OUTPUT(OUT_MODEM_RTS, FALSE);
	}

	return c;
}

//------------------------------------------------------------------------------------------------
static void _sendStringToModem(const char *s)
{
    while (*s)
    {
    	_mc_putc(*s++);
    }
}

//------------------------------------------------------------------------------------------------
//test function to send data direct to modem
void modem_sendStringDirect(char *data)
{
	char msg[250];
	strcpy(msg, data);
	strcat(msg, "\r\n");
	_sendStringToModem(msg);
}

//------------------------------------------------------------------------------------------------
void modemconnection_sendATcommand(const char *s)
{
	//Send an AT command to the modem. This function will add cr/lf to the command.
	char *data = malloc(strlen(s) + 3);
	if (data == NULL)
	{
		terminalconnection_sendP(PSTR("log\tUnable to allocate space for AT command."));
		return;
	}

	strcpy(data, s);
	strcat(data, "\r\n");
	mResponseReceived = FALSE;
	_pushCommand(CMD_AT, data);
}

//------------------------------------------------------------------------------------------------
void modemconnection_sendSMS(char *phoneNumbers, char *msg)
{
	//Don't send if the modem is not active (was a problem is machine starts up with
	//an error condition)
	if (mState != STATE_ACTIVE)
	{
		return;
	}
/*
 * AT+CMGS=&#8221;+33146290800&#8221;<CR>
Please call me soon, Fred. <ctrl-Z>
 */
    const char delimiters[] = " ,;";
    char *token, *last;
    char *phoneNumbersCopy;
    struct SMS* data;

	if (strlen(msg) == 0 || strlen(phoneNumbers) == 0)
	{
		terminalconnection_sendP(PSTR("log\tUnable to send SMS, no message or phonenumber is defined."));
		return;
	}

	phoneNumbersCopy = malloc(strlen(phoneNumbers) + 1);
	strcpy(phoneNumbersCopy, phoneNumbers);

    //send sms for each phonenumber
    token = strtok_r(phoneNumbersCopy, delimiters, &last);
    while (token != NULL && strlen(token) > 3)
    {
    	data = malloc(sizeof (struct SMS));
    	if (data == NULL)
    	{
    		terminalconnection_sendP(PSTR("log\tUnable to allocate space for SMS."));
    		return;
    	}
    	data->phoneNumber = malloc(strlen(token)+1);
    	data->message = malloc(strlen(msg)+1);
    	if (data->phoneNumber == NULL || data->message == NULL)
    	{
    		terminalconnection_sendP(PSTR("log\tUnable to allocate space for SMS content."));
    		return;
    	}

    	strcpy(data->phoneNumber, token);
    	strcpy(data->message, msg);
    	_pushCommand(CMD_SENDSMS, data);

    	terminalconnection_send("log\tScheduling message %s to nr %s", msg, token);

    	token = strtok_r(NULL, delimiters, &last);
    }
}

//------------------------------------------------------------------------------------------------
static char _handleATcommand()
{
	//Function to send an AT command to the modem and receive the response
	static char response[50];
	static int idx = 0;
	char *data = mCommandStack->data;
	static char lastResponse;

	if (mSubState == 0)
	{
		_sendStringToModem(data);
		lastResponse = 0;
		mSubState = 1;
	}
	else
	{
		//
		while (_mc_dataAvailable())
		{
			char c = _mc_getc();
			if (idx < 49)
			{
				response[idx++] = c;
			}

			//TODO make this better using mLinesReceived and some sort of time out

			if (c == '\n' && lastResponse == '\r')
			{
				response[idx>2?idx-2:idx] = 0;
				idx = 0;
				terminalconnection_send("log\tModem: %s", response);
				_delay_ms(15); //yuck
				if (!_mc_dataAvailable())
				{
					terminalconnection_sendP(PSTR("log\tDone handling AT command."));
					mResponseReceived = TRUE;
					return TRUE;
				}
			}
			lastResponse = c;
		}
	}

	return FALSE;
}

//------------------------------------------------------------------------------------------------
static char _handleWriteSMS()
{
	//Function that deals with the sending of an SMS message
	static char previousChar = 0;
	struct SMS* data = mCommandStack->data;

	switch (mSubState)
	{

	case 0:
		//Start by sending the AT command and the phonenumber
		terminalconnection_send("log\tSending phonenr %s.", data->phoneNumber);
		_sendStringToModem("AT+CMGS=\"");
		_sendStringToModem(data->phoneNumber);
		_sendStringToModem("\"\r");
		mSubState = 1;
		break;

	case 1:
		//Wait for an incoming '>'
		//TODO What if the '>' never comes? Make this better
		while (_mc_dataAvailable())
		{
			char c = _mc_getc();

#if 0
			if (c >= ' ' && c <= 'z')
			{
				terminalconnection_send("log\tReceived: %c", c);
			}
			else
			{
				terminalconnection_send("log\tReceived: #%d#", (int)c);
			}
#endif
			if (c == '>')
			{
				_mTimer = main_getTime() + 1000;
				mSubState = 2;
			}
		}
		break;

	case 2:
		//Send the message
		if (main_timerExpired(_mTimer))
		{
			char error = FALSE;
			if (_mc_dataAvailable())
			{
				//Didn't expect input in this stage
				char c = _mc_getc();
				if (c == 10)
				{
					error = TRUE;
				}
			}
			if (error)
			{
				//Modem sent something while we are supposed to send something
				//Most likely ERROR
				//terminalconnection_sendP(PSTR("log\tUnexpected modem response."));
			}
			else
			{
				terminalconnection_send("log\tSending message %s.", data->message);
				_sendStringToModem(data->message);
				_sendStringToModem("\x1a\r\n");
			}
			free(data->message);
			free(data->phoneNumber);
			previousChar = 0;
			mSubState = 3;
		}
		break;

	case 3:
		//Wait for response
		while (_mc_dataAvailable())
		{
			char c = _mc_getc();

			if (c == 10 && previousChar == 13)
			{
				_mTimer = main_getTime() + 2000;
				mSubState = 4;
				break;
			}
			previousChar = c;
		}
		break;

	case 4:
		//Wait some time for command to be done
		if (main_timerExpired(_mTimer))
		{
			if (_mc_dataAvailable())
			{
				mSubState = 3;
			}
		}
		else
		{
			//terminalconnection_sendP(PSTR("log\tDone with SMS."));
			mSubState = 5;
		}
	}

	return mSubState == 5;
}

//------------------------------------------------------------------------------------------------
static char _handlePIN()
{
	// Handles requesting of and authenticating with the PIN of the SIM card

	// receive buffer and index
	static char resp[20];
	static unsigned char idx;

	if (mSubState == 0)
	{
		// Start off by requesting PIN status
		_sendStringToModem("AT+CPIN?\r\n");
		idx = 0;
		memset(resp, 0, 20);
		mSubState = 1;

		return FALSE;
	}
	else
	{
		while (_mc_dataAvailable())
		{
			char c = _mc_getc();

			//Avoid sscanf tripping over the comma
			resp[idx++] = c==','?' ':c;

			if (idx >= 20)
			{
				// Buffer full

				terminalconnection_send("log\tPIN failed (buffer overflow).");
				return TRUE;
			}

			if (mSubState == 1)
			{
				// If we're waiting for a response on AT+CPIN?

				if (strstr(resp, "+CPIN: READY\r\n"))
				{
					// No PIN required, so just go to STATE_ACTIVE

					terminalconnection_send("log\tPIN succeeded (no PIN required).");
					_goToActive();
					return TRUE;
				}
				else if (strstr(resp, "+CPIN: SIM PIN\r\n"))
				{
					// A PIN is required, so get it from the parameter and send it to modem

					char cpin[25]; // max 21 chars long, I think?
					sprintf(cpin, "AT+CPIN=\"%s\"\r\n", "4126");
					_sendStringToModem(cpin);
					idx = 0;
					memset(resp, 0, 20);
					mSubState = 2;

					return FALSE;
				}
			}
			else
			{
				// Sent PIN before, so waiting for a response to see if it was correct

				if (strstr(resp, "OK\r\n"))
				{
					// The PIN was correct and accepted by the modem, so go to STATE_ACTIVE

					terminalconnection_send("log\tPIN succeeded (PIN entered).");

					_goToActive();
					return TRUE;
				}
				else if (strstr(resp, "ERROR\r\n"))
				{
					// Some error occurred, probably a wrong PIN

					terminalconnection_send("log\tPIN failed (incorrect PIN).");
					return TRUE;
				}
			}
		}
	}

	return FALSE;
}

//------------------------------------------------------------------------------------------------
static char _readLine(char *buf, int max)
{
	//Helper function to read one single (complete) line of response from the modem.
	//Usually used in combination with mLinesReceived in the ISR
	char prevData = 0;
	char data;
	int idx = 0;

	while (_mc_dataAvailable())
	{
		data = _mc_getc();
		if (idx < max-1)
		{
			buf[idx++] = data;
		}

		if (data == 10 && prevData == 13)
		{
			buf[idx-2] = 0;
			buf[idx-1] = 0;
			break;
		}
		prevData = data;
	}
	buf[idx] = 0;

	return strstr(buf, "OK\r\n") || strstr(buf, "ERROR\r\n");
}

//------------------------------------------------------------------------------------------------
static char _handleReadSMS()
{
	//Function to deal with incoming SMS messages
	static uint64_t timeOut;
	static int entry;
	static char phonenr[25];

	switch (mSubState)
	{

	case 0:
		//Query the modem for received SMS messages
		//terminalconnection_sendP(PSTR("log\tchecking for incoming sms messages."));
		_sendStringToModem("AT+CMGL=\"ALL\"\r\n");
		mLinesReceived = 0;
		timeOut = main_getTime() + 10000;
		mSubState = 1;
		break;

	case 1:
		if (main_timerExpired(timeOut))
		{
			//Time out if nothing happend
			//terminalconnection_send("log\ttimeout1");
			return TRUE;
		}
		else
		{
			//Wait for a complete line to come in
			if (mLinesReceived > 0)
			{
				char line[250];


				if (_readLine(line, 250))
				{
					//terminalconnection_send("log\tdone1");
					return TRUE;
				}

				else if (strstr(line, "+CMGL:"))
				{
					//This is a response to our query
					sscanf(line, "+CMGL: %d,\"%*[^\"]\",\"%[^\"]", &entry, phonenr);

					mSubState = 2;
				}
				mLinesReceived--;
			}
		}
		break;

	case 2:
		DDRA=0x01;
		//The next line should contain an incoming SMS message
		if (main_timerExpired(timeOut))
		{
			return TRUE;
		}
		if (mLinesReceived > 0)
		{
			char response[20];
			char line[250];
			if (_readLine(line, 250))
			{
				return TRUE;
			}

			// You can call a method here to parse the SMS message
			terminalconnection_send("log\tReceived SMS from %s: %s", phonenr, line);

			if(strstr(phonenr, "+33134500787", !null)){
				if(strstr(line, "hek open",!null)){
					PORTA=0x01;
					_delay_ms(20000);
					PORTA=0x00;
				}

			}


			sprintf(response, "AT+CMGD=%d", entry);
			modemconnection_sendATcommand(response);
			mSubState = 3;
		}
		break;

	}

	return mSubState == 3;
}

het gaat dan om dit stukje:

 if(strstr(phonenr, "+33134500787", !null)){
				if(strstr(line, "hek open",!null)){
					PORTA=0x01;
					_delay_ms(20000);
					PORTA=0x00;
				}

hier geeft hij een aantal errors:

C:/Users/Patrick/Desktop/Inodus/Ambitie/modemconnection.c:943: error: 'null' undeclared (first use in this function)
C:/Users/Patrick/Desktop/Inodus/Ambitie/modemconnection.c:943: error: (Each undeclared identifier is reported only once
C:/Users/Patrick/Desktop/Inodus/Ambitie/modemconnection.c:943: error: for each function it appears in.)
C:/Users/Patrick/Desktop/Inodus/Ambitie/modemconnection.c:943: error: too many arguments to function 'strstr'
C:/Users/Patrick/Desktop/Inodus/Ambitie/modemconnection.c:944: error: too many arguments to function 'strstr'

enig idee?

Alvast Bedankt

Mvg

Patrick van der Veen

null kent hij niet, de rest is een vervolg

En met deze include?

#include <stddef.h>

"!null" meegeven als argument is al vrij ongebruikelijk, maar "error: too many arguments to function 'strstr'" zegt toch wel duidelijk dat je teveel argumenten geeft..

Kijk eens naar de declaratie van 'strstr' en pas dan je source code aan..

PS: niemand gaat die lap source code lezen en aangezien je al het belangrijke eruit hebt gehaald, zou ik die hele lap weglaten.

Wellicht is stddef.h includen ok.

degene die die lap text qoute krijgt ruzie met een mod denk ik.
liever volgende keer ff ergens uploaden.

Doe gewoon "man 3 strstr" en je krijgt dit:


NAME
strstr, strcasestr - locate a substring  
SYNOPSIS

#include <string.h>

char *strstr(const char *haystack, const char *needle);

DESCRIPTION
The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating '\0' characters are not compared.

Wat die rare "!null" in die broncode staat te niksen, is mij ook niet duidelijk, Haal ze er uit, en probeer opnieuw.

@driessens_nl: zoiets zal het wel zijn, ja. Misschien meteen "NULL" van maken ipv "null"?

lijkt mij een simpele codings fout


			if(strstr(phonenr, "+33134500787", !null)){
				if(strstr(line, "hek open",!null)){

zou moeten zijn


			if(strstr(phonenr, "+33134500787") != null){
				if(strstr(line, "hek open") != null){

Weet uiteraard niet of de rest van de programmatuur correct is.

Bedankt voor alle hulp!

Ik zal er volgende keer opletten dat ik niet teveel code stuur .

Ik heb nu alleen een ander probleem, wij werken met een modem waar we een sms naartoe sturen. Hiervoor gebruiken we die string string zodat deze een bepaalde poort kan open zetten zodra er in de sms hek open staat.
Alleen nu krijgt hij de sms wel binnen, alleen verwerkt hij het niet. En na wat getest is er uit gekomen dat hij het telefoonnummer al niet leest terwijl hij precies zo per sms binnenkomt. Het betreft het volgende stukje code:

// You can call a method here to parse the SMS message
			terminalconnection_send("log\tReceived SMS from %s: %s", phonenr, line);

			if(strstr(phonenr, "+31634500787") !=NULL ){
				terminalconnection_send("log\t nrklopt");


				if(strstr(line, "hek open") !=NULL){
					PORTA=0x01;
					terminalconnection_send("log\t Hek geopend!");
					_delay_ms(20000);
					PORTA=0x00;
					terminalconnection_send("log\t Hek gesloten!");
				}
			}

Alvast Bedankt!

Zit er niet een pincode op het modem?

die staat correct ingevuld, sms krijgt hij ook binnen alleen het verwerken van die informatie die erin staat lukt niet...

Probeer het eens met een stuk uit telefoonnummer bijv "4500"
Misschien gaat het fout als de zoekstring en de string waarin gezocht moet worden gelijk zijn.
Kan zo anders ook niets verzinnen.
Je weet ook zeker dat de functie terminalconnection_send niet iets veranderd aan de < phonenr > ?