Problems with FCM


#1

Hi,

I am trying to receive some data using the serial port ; Data that along with GPS data is then send by GPRS to my server(GPS postion is sent even if no data received by serial port). The problem i am facing is that when i run my application in DEBUG (during development) no problems appear, everything is working as expected; data is received on serial port, i process it and send it via GPRS.
When I write my application to the device, if any data is received on serial port the application resets. If no data is received the application no longer send anything by GPRS (even if in DEBUG mode it is sending)
See bellow how do i handle the FCM flow:

s8 fcmHandle;
ascii* inputDataBuffer;
ascii* inputData;
bool dataAvailable = FALSE;

bool FcmDataHandler (u16 DataLen, u8 * receivedData){
	ascii *tempbuff;
	if (inputDataBuffer != NULL){
		tempbuff = adl_memGet(DataLen + wm_strlen(inputDataBuffer));
	} else {
		tempbuff = adl_memGet(DataLen);
	}
	*(receivedData + DataLen)=0;
	if (inputDataBuffer != NULL){
		wm_strcpy(tempbuff, inputDataBuffer);
		wm_strcat(tempbuff, receivedData);
	} else {
		wm_strcpy(tempbuff, receivedData);
	}
	if (inputDataBuffer != NULL) {
		adl_memRelease(inputDataBuffer);
	}	
	inputDataBuffer = tempbuff;
// finished received data when \n or \r is received
	if (strstr(inputDataBuffer,"\n")!= NULL || strstr(inputDataBuffer,"\r")!= NULL) {		
		if (inputData != NULL) {
			adl_memRelease(inputData);
		}
		inputData = adl_memGet(wm_strlen(inputDataBuffer));
		wm_strcpy(inputData,inputDataBuffer);
		*(inputDataBuffer)=0;
		if (inputDataBuffer != NULL) {
			adl_memRelease(inputDataBuffer);
		}
		dataAvailable = TRUE;
	}
    return TRUE;
}

ascii* serialReader_getData(void)
{
    dataAvailable = FALSE;	
    return inputData;
}

bool serialReader_dataIsAvailable(void){
    return dataAvailable;
}

bool FcmCtrlHandler (adl_fcmEvent_e Event){
    switch (Event){
        case ADL_FCM_EVENT_FLOW_OPENNED:{
			// switching to data mode
            adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_DATA);
			break;
        }		
		case ADL_FCM_EVENT_V24_AT_MODE_EXT: {
			adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_AT);
			adl_fcmUnsubscribe(fcmHandle);
			// back in AT mode when +++ is received
			break;
		}
      break;
    }
    return TRUE;
}

void serialReader_init(void){
	fcmHandle = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART1, FcmCtrlHandler, FcmDataHandler);
	dataAvailable = FALSE;
}

Am I missing something regarding the way FCM is working. Why in DEBUG mode everything is ok and on the device nothing is working?

Thanks


#2

I take it you mean [b]Remote /b mode here?

and Target mode here?

Yes, you are: the data supplied to the handler is not a ‘C’ string!


#3

You are also not checking the return value from adl_memGet before you use it.

You must always check return values - especially for dynamc memory allocation!


#4

Thanks for opening my eyes :slight_smile:

So actually when the handler is triggered we always receive only one character? While in RTE mode sometimes i receive a bunch of characters, what’s up with that?


#5

I think my C i a little rusty so please correct my if i am wrong. Actually u8 * receivedData points to the start of the received string and DataLen si the actual length of the string, so actually i need to do iterate from
receivedData to receivedData+DataLen to get the entire received string? Don’t strcat and strcpy cover this iteration?


#6

No - see the documentation in the ADL User Guide.

That is the documented behaviour!


#7

It does if you put NULL character at DataLen position of receivedData.


#8

It is not a ‘C’ string.

The term “string” has a specific meaning in the ‘C’ language - check your ‘C’ textbook for details.

Again, it is not a ‘C’ string.

If it were a ‘C’ string, there would be no need for a length parameter - as the length could easily be found with strlen, couldn’t it?

Think about it: how do they know when to stop…?


#9

You must not do that here: FCM gives you a pointer to a buffer, and its length - you must not write beyond that length!! :open_mouth:

Also, this assumes that the data will not itself contain NUL characters…


#10

You are right. I’m just get used to statically allocated buffers with known length.