Problems with FCM



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) {
	inputDataBuffer = tempbuff;
// finished received data when \n or \r is received
	if (strstr(inputDataBuffer,"\n")!= NULL || strstr(inputDataBuffer,"\r")!= NULL) {		
		if (inputData != NULL) {
		inputData = adl_memGet(wm_strlen(inputDataBuffer));
		if (inputDataBuffer != NULL) {
		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){
			// switching to data mode
            adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_DATA);
			adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_AT);
			// back in AT mode when +++ is received
    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?



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!


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!


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?


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?


No - see the documentation in the ADL User Guide.

That is the documented behaviour!


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


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…?


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…


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