FCM problem in getting data from sensor


#1

Hi to all,
here is my problem. I have a Q2686H and i want to get data from a sensor. In order to get the data i have to send to the sensor the command “go” and then enter (ascii 13 or 10).
here is my code.

#define UART2_CLOSED 0
#define UART2_GETTING_STATUS 1
#define UART2_CLOSED_WAITING_OK 2
#define UART2_OPENING_WAITING_OK 3
#define UART2_OPEN_WAITING_OK 4
#define UART2_OPEN 5
#define UART2_CHANGING_SPEED 6
#define UART2_OPENING_FCM 7
#define UART2_READY 8

#include "adl_global.h"
#include "adl_fcm.h"

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

#define SEND_TRACE(x)   TRACE(( 1, x )); adl_atSendResponse ( ADL_AT_UNS, x );
#define FLH_HANDLER "FLH_TEST_HDLR"

s8 FCM_UART2_handle;
u8 uart2Status = UART2_CLOSED; // to manage to the starting of UART2
typedef enum
{
UART_MODE_AT,
UART_MODE_DATA
} uartModeType_e;

bool b_canSendDataToUart2 = TRUE;
u8 uart2Mode = UART_MODE_AT;

s8 DataBlock="go\r\n";

void Cmd_flashread_Handler(adl_atCmdPreParser_t *paras);
void getStatus_tmrHandler(u8 Id);


bool FCM_UART2_CtrlHandler (adl_fcmEvent_e Event)
{
	s8 resultat;
	s8 res;
	SEND_TRACE("FCM_UART2_CtrlHandler\r\n" );

switch(Event)
{
case ADL_FCM_EVENT_FLOW_OPENNED:
	SEND_TRACE("ADL_FCM_EVENT_FLOW_OPENNED\r\n" );
resultat = adl_fcmSwitchV24State(FCM_UART2_handle, ADL_FCM_V24_STATE_DATA);
break;

case ADL_FCM_EVENT_FLOW_CLOSED:
	SEND_TRACE("ADL_FCM_EVENT_FLOW_CLOSED\r\n" );
break;

case ADL_FCM_EVENT_V24_DATA_MODE:
	SEND_TRACE("ADL_FCM_EVENT_V24_DATA_MODE\r\n" );
uart2Mode = UART_MODE_DATA;
uart2Status = UART2_READY; // UART2 is now completely initialised
res=adl_fcmSendData (FCM_UART2_handle, "go\r", 3);
//res=adl_fcmSendData (FCM_UART2_handle, "res?\r", 5);
break;

case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
	SEND_TRACE("ADL_FCM_EVENT_V24_DATA_MODE_EXT\r\n" );
break;

case ADL_FCM_EVENT_V24_AT_MODE:
	SEND_TRACE("ADL_FCM_EVENT_V24_AT_MODE\r\n" );
uart2Mode = UART_MODE_AT;
break;

case ADL_FCM_EVENT_V24_AT_MODE_EXT:
	SEND_TRACE("ADL_FCM_EVENT_V24_AT_MODE_EXT\r\n" );
break;

case ADL_FCM_EVENT_RESUME:
	SEND_TRACE("ADL_FCM_EVENT_RESUME\r\n" );
break;

case ADL_FCM_EVENT_MEM_RELEASE:
	SEND_TRACE("ADL_FCM_EVENT_MEM_RELEASE\r\n" );
break;

case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
	SEND_TRACE("ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL\r\n" );
break;

case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
	SEND_TRACE("ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL\r\n" );
break;

default:
	SEND_TRACE("DEFAULT\r\n" );
break;
}

return(FALSE);
}

bool FCM_UART2_DataHandler (u16 DataSize, u8 * Data)
{
 u16 i;
u8 * pData = Data;
char * string[100];
// TRACE (( TRACE_LEVEL_FCT, "FCM_UART2_DataHandler" ));
wm_sprintf(string, "Datasize: %d\r\n", DataSize);
SEND_TRACE(string);
//TRACE (( 1, "Datasize: %d", DataSize));

return(TRUE);
}

void tmrHandler_startFcmUart2( u8 ID )
{
	char *string[100];
// Subscribe to the FCM for UART2
FCM_UART2_handle = adl_fcmSubscribe ( ADL_FCM_FLOW_V24_UART2, FCM_UART2_CtrlHandler, FCM_UART2_DataHandler );

wm_sprintf(string, "adl_fcmSubscribe UART2 return value: %d\r\n", FCM_UART2_handle);
SEND_TRACE(string);

if(FCM_UART2_handle < 0)
{
SEND_TRACE("adl_fcmSubscribe UART2 failed\r\n");
}
}


bool cmd_RspHandler_IPR(adl_atResponse_t * params)
{
	ascii buf[30];
	SEND_TRACE("cmd_RspHandler_IPR\r\n");
	wm_strRemoveCRLF(buf, params->StrData, params->StrLength);
	if ((!wm_strcmp(buf, "OK")) && (uart2Status == UART2_CHANGING_SPEED))
	{
		uart2Status = UART2_OPENING_FCM;
		// Must wait before subscribing to the FCM for UART 2,
		// otherwise the UART2 parameters are not set correctly
		// and the UART2 is not synchronised to the incomming data.
		adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_100MS, tmrHandler_startFcmUart2 );
	}
return (TRUE);
}

bool cmd_RspHandler_WMFM(adl_atResponse_t * params)
{
    ascii buf[30];
	wm_strRemoveCRLF(buf, params->StrData, params->StrLength);
	switch(uart2Status)
	{
	case UART2_GETTING_STATUS:
		if(buf[13] == '0') // "+WMFM: 0,2,x,0" ==> Closed
		{
			uart2Status = UART2_CLOSED_WAITING_OK;
		}
		else if(buf[13] == '1') // "+WMFM: 0,2,x,1" ==> Open
		{
			uart2Status = UART2_OPEN_WAITING_OK;
		}
	break;
	case UART2_CLOSED_WAITING_OK:
		if(!wm_strcmp(buf, "OK"))
		{
			uart2Status = UART2_OPENING_WAITING_OK;
			// By default, only UART 1 is open. UART 2 must be explicitly opened
			adl_atCmdCreate( "AT+WMFM=0,1,2", FALSE, ( adl_atRspHandler_t ) cmd_RspHandler_WMFM, "*", NULL );
		}
	break;
	case UART2_OPEN_WAITING_OK:
		if(!wm_strcmp(buf, "OK"))
		{
			uart2Status = UART2_CHANGING_SPEED;
			adl_atCmdCreate("AT+IFC=0,0", 1, NULL, NULL);
			adl_atCmdCreate("AT+ICF=3,4", 1, NULL, NULL);
			// Set default speed for UART 2
			adl_atCmdCreate("AT+IPR=9600", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t) cmd_RspHandler_IPR, "*", NULL);
		}
	break;
	case UART2_OPENING_WAITING_OK:
		if(!wm_strcmp(buf, "OK"))
		{
			uart2Status = UART2_GETTING_STATUS;
		}
	break;
	}
	return FALSE;
}
void init_uart2()
{
	SEND_TRACE("startUart2: get status UART2\r\n" );
uart2Status = UART2_GETTING_STATUS;
adl_atCmdCreate( "AT+WMFM=0,2,2", FALSE, ( adl_atRspHandler_t ) cmd_RspHandler_WMFM, "*", NULL );
	
}
void adl_main ( adl_InitType_e InitType )
{
SEND_TRACE("Embedded Application : Main\r\n" );
	init_uart2();
}

after the “GO” command nothing happens. The sensor doesn’t send anything.

can anyone help me please. it is very urgent

Thanks


#2

What is the output of the Traces? Maybe the answer is there?


#3

the traces are:
Embedded Application : Main
startUart2: get status UART2

+WIND: 13

+WIND: 12,0

+WIND: 12,1

+WIND: 1

+WIND: 7
cmd_RspHandler_IPR
adl_fcmSubscribe UART2 return value: 0
FCM_UART2_CtrlHandler
ADL_FCM_EVENT_FLOW_OPENNED
FCM_UART2_CtrlHandler
ADL_FCM_EVENT_V24_DATA_MODE
FCM_UART2_CtrlHandler
ADL_FCM_EVENT_MEM_RELEASE

and then nothing.
The sensor is a flow sensor, and even if i blow no data come to the UART2


#4

Does the sensor receive the GO command?

Does the sensor send any data?


#5

No it doesn’t receive the GO command because when i blow i don’t get any response.
as a matter if fact i have an oscilloscope and i connected it to the TX pin of UART2 in order to see if the command gets to the UART2 .
unfortunately no signal at all.

Do you find that the code needs some correction? is it something else wrong? The firmware of the q2686 is 663g. I don’t know if this plays any role but I just mention it.

thanks
Eleni


#6

did you check res after function call res=adl_fcmSendData (FCM_UART2_handle, “go\r”, 3); ?


#7

Have you enabled UART2 with AT+WMFM :question:


#8

Yes it gives res=0.


#9

I think i did that

the command is there:
adl_atCmdCreate( “AT+WMFM=0,1,2”, FALSE, ( adl_atRspHandler_t ) cmd_RspHandler_WMFM, “*”, NULL );


#10

I have managed to open the sensor from my computer, and then i connected it to the q2686.
When the status of the uart2 became ADL_FCM_EVENT_V24_DATA_MODE the data handler responded in the incoming data.
So the question now is : when do i send the command “go\r\n” to the uart2?
Apparently after ADL_FCM_EVENT_V24_DATA_MODE is wrong.
Can anyone tell?
thanks


#11

I thought that place should be OK… But you could try to start a timer with a short interval, just to give some time to the OS, and in the timer callback do the adl_fcmSendData().

Do you need to send “go\r\n”? the code does only send “go\r”. but that would not explain why you did not see anything on the scope…


#12

I need to send “go” and then enter (ascii 10 or 13). i believe the “\r\n” is the same. Wright??

i post the traces i get from data handler:
fcm data 0 Datasize: 32
fcm data 0 Datasize: 15
fcm data 0 Datasize: 32
fcm data 0 Datasize: 15
fcm data 0 Datasize: 32
fcm data 0 Datasize: 15
ADL_FCM_EVENT_MEM_RELEASE
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 34
fcm data 0 Datasize: 124
fcm data 0 Datasize: 17
fcm data 0 Datasize: 32
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 43
fcm data 0 Datasize: 94
fcm data 0 Datasize: 124
fcm data 0 Datasize: 17
fcm data 0 Datasize: 94
fcm data 0 Datasize: 94
fcm data 0 Datasize: 32
fcm data 0 Datasize: 15
fcm data 0 Datasize: 94
fcm data 0 Datasize: 32

why can’t I see the Data? why it’s always 0?? and the datasize varies.


#13

depends on what your device requires… Enter is a key on the keyboard. On the serial port there are ASCII characters CR or LF or both… what to use really depends on the spec. of the sensor.

The traces with “Datasize:” are sent within function FCM_UART2_DataHandler? Then that IS data you received!
does 0 maybe mean OK (that there was no error). I thought it should return the size that was sent… but I could be wrong…


#14

I put the timer, and yet nothing happens.
i even tried to send “s” command which stops the sensor to measure. Nothing happened. the data keep coming (that is good from one point of view) but then the flowbuffer is filling up with zeros

fcm data 0.000000 Datasize: 18
fcm data 0.000000 Datasize: 32
fcm data 0.000000 Datasize: 18
fcm data 0.000000 Datasize: 32
fcm data 0.000000 Datasize: 16

bool FCM_UART2_DataHandler (u16 DataSize, u8 * Data)
{
 //u16 i;
//u8 * pData = Data;
char * string[100];
 flowbuffer = adl_memGet(DataSize * 2 + 1); // if you want it to be really robust, check that the return value is not equal to NULL
    wm_memset(flowbuffer, 0, DataSize * 2 + 1); // check the syntax here, maybe the last two parameters should be swapped
      wm_ibuftohexa(flowbuffer, Data, DataSize);


// TRACE (( TRACE_LEVEL_FCT, "FCM_UART2_DataHandler" ));
wm_sprintf(string, "fcm data %f",*Data);
SEND_TRACE(string);
wm_sprintf(string, "  Datasize: %d\r\n", DataSize);
SEND_TRACE(string);
//TRACE (( 1, "Datasize: %d", DataSize));

return(TRUE);
}

and the code is the above. what am I doing wrong? Why can’t i get the data.

they should normally are something like
-0.1626 sccm
-0.0646 sccm
-0.0646 sccm
+0.0332 sccm
-0.0646 sccm
+0.0332 sccm
-0.0646 sccm
-0.0646 sccm
+0.0332 sccm
-0.1624 sccm
+0.0332 sccm
-0.0646 sccm
-0.0646 sccm
-0.0646 sccm
-0.0646 sccm
-0.0646 sccm
-0.0646 sccm
+0.0332 sccm
-0.0646 sccm
-0.0646 sccm


#15

the specification of the sensor says either 10 or 13 it’s the same. in the program i made in visual studio 2008 for my computer i send “go\r” and the sensor opens and sends data.

as you can see from my other post i managed to open the sensor from the computer and now sends data continuously. but unfortunately they are 0s whereas they should be

-0.1626 sccm
-0.0646 sccm
-0.0646 sccm
+0.0332 sccm
-0.0646 sccm
+0.0332 sccm
-0.0646 sccm
-0.0646 sccm
+0.0332 sccm
-0.1624 sccm


#16

Is that data supposed to come in binary in floating point values?

*Data gives you a u8 not a float value…

I would try to print the first couple of values (Data[0], Data[1], Data[2]…) with %d to see what is in there…


#17

I followed your advice wm_sprintf(string, “fcm data %d”,Data[0]);
and i got

fcm data 0 Datasize: 32
fcm data 0 Datasize: 16
fcm data 0 Datasize: 32
fcm data 0 Datasize: 15
fcm data 0 Datasize: 32
fcm data 0 Datasize: 16
adl_fcmSendData UART2 return value: 0
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124

when i changed the command in wm_sprintf(string, “fcm data %s”,Data[0]);
i got
fcm data (null) Datasize: 47
fcm data (null) Datasize: 32
fcm data (null) Datasize: 16
fcm data (null) Datasize: 47
fcm data (null) Datasize: 32
fcm data (null) Datasize: 15
fcm data (null) Datasize: 48
fcm data (null) Datasize: 32
fcm data (null) Datasize: 15
fcm data (null) Datasize: 95


#18

So it seems that always the first received byte is 0… could it be that the other elements in Data are non-zero?


#19

i checked the Data[5] and still

fcm data 0 Datasize: 17
fcm data 0 Datasize: 32
fcm data 0 Datasize: 62
fcm data 0 Datasize: 32
fcm data 0 Datasize: 15
ADL_FCM_EVENT_MEM_RELEASE
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 21
fcm data 0 Datasize: 124
fcm data 0 Datasize: 17
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 124
fcm data 0 Datasize: 4
fcm data 0 Datasize: 94

it’s so annoying.
and i need to show this data to an LCD. but again i stumble on the fcm send data thing!


#20

Hii

I read your post and i feel something is wrong with the code which you have written coz FCM works fine as far as i know…
Please check if the FCM( “duplex_data”) sample given in the ADL OS samples is of any help or not… Try to put traces in proper places in your application to check where the exact problem is occuring coz that might help in debugging the application…

regards, Paruthiv