How to stop a flow?


#1

Hi everyone,

I am having problems stopping a flow from UART2 to UART1. I have created a command to start the flow “AT+U2=1” but I can’t stop the flow with “AT+U2=0”. The only way that I can stop it is when I issue the command “AT+WOPEN=0”.

When I use the command “AT+U2=1” it returns the following output on the Terminal Emulator:

at+u2=1

OK
(AtUart2LoopBackCmdHandler) Enter.
AT+WMFM=0,0,2: Start
AT+WMFM=0,0,2:
OK
AT+WMFM=0,1,2: Start
AT+WMFM=0,1,2
OK
AT+IPR=4800: Start
AT+IPR=4800:
OK
Before: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE
Before: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE
adl_fcmSubscribe(ADL_PORT_UART1) success. returnValue = 0
adl_fcmSubscribe(ADL_PORT_UART2) success. returnValue = 1
After: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE
After: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE
AT+ICF=3,4: Start
AT+IFC=2,2: Start
AT&W: Start
(Uart1ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED
(Uart1ControlHandler) adl_fcmSwitchV24State(ADL_FCE_V24_STATE_DATA) success
(Uart2ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED
(Uart2ControlHandler) adl_fcmSwitchV24State(ADL_FCE_V24_STATE_DATA) success
(Uart1ControlHandler) Handle: ADL_FCM_V24_DATA_MODE
(Uart2ControlHandler) Handle: ADL_FCM_V24_DATA_MODE
(Uart2DataHandler) adl_fcmSendData() failed. returnValue = -21
(Uart1ControlHandler) Handle: ADL_FCM_EVENT_RESUME

I then issue the “AT+U2=0” and I recieve the following TE Output.

at+u2=0

OK
(AtUart2LoopBackCmdHandler) Enter.
(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart1FcmHandle) failed. returnValue = -8
(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart2FcmHandle) failed. returnValue = -8

at+wopen=0

I have looked at the list of Errors at the end of the AUG_OpenAT_ADL_Development_Guide-004.pdf document and it doesn’t list the error for -8.

My code I have copied from this forum (See http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?f=5&t=733) and edited for my needs :

bool HandleWmfmSetBaudRate(adl_atResponse_t *response){
    
    bool isFcmAvailable;
    s8 returnValue;
    char string[100];
    
    SEND_TRACE("AT+IPR=4800: ");
    SEND_TRACE(response->StrData);
    
    /* check UART1 is available */
    isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART1);
    if (isFcmAvailable){
        SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE\r\n");
    } else {
        SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART1) == FALSE\r\n");
    }
    
    /* check UART2 is available */
    isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART2);
    if (isFcmAvailable){
        SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE\r\n");
    } else {
        SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART2) == FALSE\r\n");
    }
    
    /* subscribing to UART1 for flow control */
    uart1FcmHandle = adl_fcmSubscribe(ADL_PORT_UART1, Uart1ControlHandler, Uart1DataHandler);
    if (uart1FcmHandle < 0){        
        wm_sprintf(string, "ERROR: adl_fcmSubscribe(ADL_PORT_UART1) failed. returnValue = %d\r\n", uart1FcmHandle);
        SEND_TRACE(string);
    } else {
        wm_sprintf(string, "adl_fcmSubscribe(ADL_PORT_UART1) success. returnValue = %d\r\n", uart1FcmHandle);
        SEND_TRACE(string);
    }
    
    /* subscribing to UART2 for flow control */   
    uart2FcmHandle = adl_fcmSubscribe(ADL_PORT_UART2, Uart2ControlHandler, Uart2DataHandler);
    if (uart2FcmHandle < 0){
        wm_sprintf(string, "ERROR: adl_fcmSubscribe(ADL_PORT_UART2) failed. returnValue = %d\r\n", uart2FcmHandle);
        SEND_TRACE(string);
    } else {
        wm_sprintf(string, "adl_fcmSubscribe(ADL_PORT_UART2) success. returnValue = %d\r\n", uart2FcmHandle);
        SEND_TRACE(string);
    }
    
    /* check UART1 is available */   
    isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART1);
    if (isFcmAvailable){
        SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE\r\n");
    } else {
        SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART1) == FALSE\r\n");
    }
    
    /* check UART2 is available */
    isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART2);
    if (isFcmAvailable){
        SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE\r\n");
    } else {
        SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART2) == FALSE\r\n");
    }
    
    /* set character framing */
    SEND_TRACE("AT+ICF=3,4: Start\r\n");
    returnValue = adl_atCmdCreate("AT+ICF=3,4", TRUE, (adl_atRspHandler_t)NULL, NULL);
    if (returnValue != OK){
        wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+ICF=3,4) returned %d\r\n", returnValue);
        SEND_TRACE(string);
    }
    
    /* set flow control */
    SEND_TRACE("AT+IFC=2,2: Start\r\n");
    returnValue = adl_atCmdCreate("AT+IFC=2,2", TRUE, (adl_atRspHandler_t)NULL, NULL);
    if (returnValue != OK){
        wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+IFC=2,2) returned %d\r\n", returnValue);
        SEND_TRACE(string);
    }
    
    /* write settings to ROM */
    SEND_TRACE("AT&W: Start\r\n");
    returnValue = adl_atCmdCreate("AT&W", TRUE, (adl_atRspHandler_t)NULL, NULL);
    if (returnValue != OK){
        wm_sprintf(string, "ERROR: adl_atCmdCreate(AT&W) returned %d\r\n", returnValue);
        SEND_TRACE(string);
    }
    return FALSE;
}

void WorkAroundTitmerHandler(u8 whatever){
    s8 returnValue;
    char string[100];
        
    /* set baud rate */
    SEND_TRACE("AT+IPR=4800: Start\r\n");
    returnValue = adl_atCmdCreate("AT+IPR=4800", ADL_AT_PORT_TYPE(ADL_PORT_UART2, FALSE), HandleWmfmSetBaudRate, "*", NULL);
    if (returnValue != OK){
        wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+IPR=4800) returned %d\r\n", returnValue);
        SEND_TRACE(string);
    }
}

#define COMMAND_BUG 1

bool HandleWmfmUart2Enable(adl_atResponse_t *response){
    SEND_TRACE("AT+WMFM=0,1,2");
    SEND_TRACE(response->StrData);
    
#if COMMAND_BUG
    adl_tmrSubscribe(FALSE, 1, ADL_TMR_TYPE_100MS, WorkAroundTitmerHandler);
#else
    workAroundTitmerHandler(0);
#endif

    return FALSE;
}

bool HandleWmfmUart2Disable(adl_atResponse_t *response){
    s8 returnValue;
    char string[100];
    
    SEND_TRACE("AT+WMFM=0,0,2:");
    SEND_TRACE(response->StrData);;
    
    /* Open UART2 */
    SEND_TRACE("AT+WMFM=0,1,2: Start\r\n");
    returnValue = adl_atCmdCreate("AT+WMFM=0,1,2", FALSE, HandleWmfmUart2Enable, "*", NULL);
    if (returnValue != OK){
        wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+WMFM=0,1,2) returned %d\r\n", returnValue);
        SEND_TRACE(string);
    }
    return FALSE;
}

void AtUart2LoopBackCmdHandler(adl_atCmdPreParser_t *parser){
    s8 returnValue;
    char *parameter;
    int startStop;
    char string[100];
    
    SEND_TRACE("(AtUart2LoopBackCmdHandler) Enter.\r\n");
    
    /* Extracting Parameter */
    parameter = wm_lstGetItem(parser->ParaList, 0);
    startStop = atoi(parameter);
    if (startStop == 1){ /* i.e. 'AT+U2=1' */
        enableU2 = TRUE; 
        if (uart1FcmHandle != -1 || uart2FcmHandle != -1){
            SEND_TRACE("Application Active: UART1 or UART2 still has an active handle.\r\n");
            return;
        }
        
        /* closing UART2 */
        SEND_TRACE("AT+WMFM=0,0,2: Start\r\n");
        adl_atCmdCreate("AT+WMFM=0,0,2", FALSE, HandleWmfmUart2Disable, "*", NULL);
    } else if (startStop == 0){ /* i.e. 'AT+U2=0' */
        /* Disable Timer1 */
        /* adl_tmrUnSubscribe(tmr1, mcs_TimerHandler_1,ADL_TMR_TYPE_100MS);
        SEND_TRACE("Timer1 Disabled\r\n"); */                     
        if (uart1FcmHandle > -1) {
            returnValue = adl_fcmUnsubscribe(uart1FcmHandle);
            if (returnValue != OK){
                wm_sprintf(string, "(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart1FcmHandle) failed. returnValue = %d\r\n", returnValue);
                SEND_TRACE(string);
            } else {
                enableU2 = FALSE;
                uart1FcmHandle = -1;
            }
        } else {
            SEND_TRACE("UART1 Already Unsubscribed.\r\n");
        }
        if (uart2FcmHandle > -1) {
            returnValue = adl_fcmUnsubscribe(uart2FcmHandle);
            if (returnValue != OK){
                wm_sprintf(string, "(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart2FcmHandle) failed. returnValue = %d\r\n", returnValue);
                SEND_TRACE(string);
            } else {
                enableU2 = FALSE;
                uart2FcmHandle = -1;
            }
        } else {
            SEND_TRACE("UART2 Already Unsubscribed");
        }
     } else {
        adl_atSendResponse(ADL_AT_RSP, "\r\nERROR\r\n");
        return;
     }
     adl_atSendResponse(ADL_AT_RSP, "\r\nOK\r\n");
}

...

bool mcs_run ( u8 Port ){ // using the MultiApp Library start see mcs_init(...)
    
    ...
    
    s16 returnValue;
    s8 retVal;
    char string[50];  
       
     ...
    
    /* Subscribe to the 'AT+U2' Command*/
    SEND_TRACE("Subscribing to the 'AT+U2' Command\r\n");
    returnValue = adl_atCmdSubscribe("AT+U2", AtUart2LoopBackCmdHandler, ADL_CMD_TYPE_PARA | 0x0011);
    if (returnValue < 0){
        wm_sprintf(string, "ERROR: adl_atCmdSubscribe('AT+U2', ...) returned %d\r\n", returnValue);
        SEND_TRACE(string);
    }
    
    ...
    
    /* COMMENT: these lines are taken care of in the above functions
     * adl_atCmdCreate("AT+WMFM=0,1,2", FALSE, (adl_atRspHandler_t)NULL, NULL);
     * adl_atCmdCreate("AT+IPR=4800\r", ADL_AT_PORT_TYPE(ADL_AT_UART2, FALSE), (adl_atRspHandler_t)NULL, NULL);
     * adl_atCmdCreate("AT&W", TRUE, (adl_atRspHandler_t)NULL, NULL);
     * uart2FcmHandle = adl_fcmSubscribe(ADL_PORT_UART2, Uart2ControlHandler, Uart2DataHandler);
     * uart1FcmHandle = adl_fcmSubscribe(ADL_PORT_UART1, Uart1ControlHandler, Uart1DataHandler);
     */
            
    return TRUE;
}

void mcs_stop ( void ){ // using the MultiApp Library stop see mcs_init(...)
    ...

    /* Unsubscribe from the 'AT+U2' command */
    SEND_TRACE("Unsubscribing from 'AT+U2' Command\r\n");
    adl_atCmdUnSubscribe ( "AT+U2", AtUart2LoopBackCmdHandler );
                 
 ...
    
    /* COMMENT: Handle for UART2 is unsubscribed in AtUart2LoopBackCmdHandler*/
     /*SEND_TRACE("Unsubscribing UART1 FCM Handle\r\n");
     adl_fcmUnsubscribe(uart1FcmHandle);
     
     SEND_TRACE("Unsubscribing UART2 FCM Handle\r\n");
     adl_fcmUnsubscribe(uart2FcmHandle);*/
     
}

void mcs_init ( adl_InitType_e InitType, ascii * PinCode, ma_Element_t * ApplicationData ){
    
    mcs_TraceLevel = ApplicationData->AppTrcID;
       
   ...

    // Fill application data structure
    ApplicationData->AppName = mcs_NameBuffer;
    ApplicationData->AppCmd = MCS_CMD_START;
    ApplicationData->ObjRange = TELE_OBJECT_FLASH_TEL;
    ApplicationData->AppStart = mcs_run;
    ApplicationData->AppStop = mcs_stop;   
    ...
}

I would appreciate if someone can point out where I may have gone wrong or point me in the right direction i.e. a similar thread.

Thank you.

Francis.


#2

Are you sure?

Hint: it’s a General code - not FCMspecific…


#3

Thanks again Aveneil for the hint.

ADL_RET_ERR_BAD_STATE -8.

Regards,

Francis.