Simple way to get string of chars from terminal


#1

I am looking for a simple way to take from the terminal emulator string of numbers and save it to the flash memory.
so i was trying to make a custom AT command but the i understood that i must use AT sequence before i enter the string,
so then i was trying this standard c method :
while ((c = getchar()) != “\n”)
bigbuf[i++] = c;

but then the WCPU will take all the garbage into this buffer while waiting for a string to be entered or maybe just enter zeroes inside this buffer.


#2

How did you implement your getchar() :question:

If you don’t want to make a custom AT command, you will have to use FCM (the Flow Control Manager) and put the UART into Data mode…


#3

The getchar() is implemented in stdio.h so i used it as is within the while loop to retrieve chars from the open port.
Regarding the FCM, I assume that I need to use the adl_fcmSubscribe api
, is there any specific sample in open at that i can have reference for this purpose?


#4

i was tryning to subscribe fcm and retreve the data in timer handler that will waits 60 seconds and then get back to AT mode.
The question is if can retreive the numbers that i wish to enter the application( and save it into a buffer) in data mode charecter by charecter with the following format:

void TimerHandler ( u8 ID, ascii * Context )
{
    TRACE (( 1, "Inside Timer : Finish wait 1 sec   " ));     
    int j;    
    char datain;  
      
    TRACE (( 1, "start recieve" ));
        do{
        
        datain = * Context; 
         
            if ( 0x30 < datain > 0x39 )
            {
                bigbuf [counter] = datain;    
                counter++;
                TRACE (( 1, "recieved" ));
            }
            
        } while ((* Context != 0x0d ) || (* Context != 0x0A) );
 
    adl_fcmSwitchV24State ( Handle, ADL_FCM_V24_STATE_AT );      
    
    TRACE (( 1, "Inside Timer : change to AT MODE  " ));

}

#5

You are over complicating it!

Once you subscribe to the UART in FCM, then switch it to Data mode, any and all incoming bytes will be delivered via the Data Event.

The timeout for switching back to AT mode is entirely independent of FCM…


#6

ok , i subscribed to FCM and switched to data mode inside data handler,
but never got into the data handler when placing beakpoint when running the debugger.

void enter_nmbr( void )
{
        TRACE (( 1, "Inside ENTER NMBR" ));
        
        adl_atSendResponse ( ADL_AT_UNS, "\r\nPlease Enter Number\r\n" );
        
        adl_fcmSubscribe ( ADL_FCM_FLOW_V24_UART1, CtrlHandler, DataHandler );
         
}
bool DataHandler ( u16 DataSize, u8 * Data )
{
     adl_fcmSwitchV24State ( Handle, ADL_FCM_V24_STATE_DATA );
     int j;    
     u8 datain; 
      do{     /////////// never reach this breakpoint 
             datain = * Data; 
            if ( 0x30 < datain > 0x39 )
            {
                bigbuf [counter] = datain;    
                counter++;
                TRACE (( 1, "recieved" ));
            }
            
        } while (( datain != 0x0d ) || ( datain != 0x0A) );
 
    adl_fcmSwitchV24State ( Handle, ADL_FCM_V24_STATE_AT );      
    TRACE (( 1, "Inside Timer : change to AT MODE  " ));   
    return TRUE;
}


bool CtrlHandler ( adl_fcmEvent_e Event )
{
    switch (Event)
    case ADL_FCM_EVENT_FLOW_OPENNED:
        TRACE((1,"ADL_FCM_EVENT_FLOW_OPENNED"));
          break;
    case ADL_FCM_EVENT_V24_DATA_MODE:
        TRACE((1,"ADL_FCM_EVENT_DATA"));
        break;
    case ADL_FCM_V24_STATE_DATA:
        TRACE((1,"ADL_FCM_V24_STATE_DATA"));
        break;

    return FALSE;
}

i received the trace : ADL_FCM_EVENT_FLOW_OPENNED and the debugger did not enter to the data handler.
Am i missing somthing on the way ?


#7

You haven’t showed how you switch to Data mode.

You have to wait for the flow to open, then switch to Data mode.

eg, see: viewtopic.php?f=5&t=1638&p=5937&hilit=ADL_FCM_EVENT_FLOW_OPENNED+adl_fcmSwitchV24State#p5937


#8

thanks , i think i solved the problem.