Home AMX User Forum NetLinx Studio

Extracting a variable from a string

Hi all.

I'm Trying to extract a variable from a string to define a CallId. I'm Working With a Tandberg C60.

The string i'm trying to get is sent to me in a string with much information. All i want to do is to extract The word: Call followed by up to 5 digits. Then remove Call and make the digits that can be everthing from 1 to 65000 (something) into an integer.

The string i send to the codec is this:
SEND_STRING dvTandberg, "'xCommand DTMFSend CallId:',nCallId,'DTMFString:',DATA.TEXT,$0D"

The nCallId is the integer representing the variable.

My problem is that when say i want 5 digits i only get one , i also receive alot of crap i dont want, and the the codec doesn't recognise the CallID.

And when i specify that i only want one digit, i'm out when the counter reaches 10.

Thanks for any help that leads me in the right direction. Examples are wery much appiciated.

Comments

  • ericmedleyericmedley Posts: 4,177
    post your code and we'll see if we can help.
  • Didn't bother to post it since it wasn't working anyway:P

    DATA_EVENT[dvTandberg]
    {
        STRING:
        {
            stack_var char sIncMsg[50]
            while(find_string(data.text,"$0D,$0A",1))
    	{
    	    sIncMsg = remove_string(data.text,"$0D,$0A",1);
    	    SELECT
    	    {	
    		ACTIVE(FIND_STRING(sIncMsg,'*s Call    ',1)):
    		{
    		    remove_string(sIncMsg,'*s Call',1);
    		    nCallId = ITOA(ATOI(sIncMsg));
    		}	
    	    }	 
    	}
        }
    }
    
  • ericmedleyericmedley Posts: 4,177
    Didn't bother to post it since it wasn't working anyway:P

    DATA_EVENT[dvTandberg]
    {
        STRING:
        {
            stack_var char sIncMsg[50]
            while(find_string(data.text,"$0D,$0A",1))
    	{
    	    sIncMsg = remove_string(data.text,"$0D,$0A",1);
    	    SELECT
    	    {	
    		ACTIVE(FIND_STRING(sIncMsg,'*s Call    ',1)):
    		{
    		    remove_string(sIncMsg,'*s Call',1);
    		    nCallId = ITOA(ATOI(sIncMsg));
    		}	
    	    }	 
    	}
        }
    }
    

    what kind of variable is nCallId ? can you post the declaration of it?
  • ericmedley wrote: »
    what kind of variable is nCallId ? can you post the declaration of it?
    Define Variable
    
    INTEGER nCallId;
    
  • ericmedleyericmedley Posts: 4,177
    Define Variable
    
    INTEGER nCallId;
    


    take out the itoa


    nCallId = ITOA(ATOI(sIncMsg));

    make it nCallId = ATOI(sIncMsg)
  • ericmedley wrote: »
    take out the itoa


    nCallId = ITOA(ATOI(sIncMsg));

    make it nCallId = ATOI(sIncMsg)



    I Belive i tried that aswell. I'm not sure why, but when i do it like this the nCallId is 3 when its really 34.
  • The string from the Tandberg continues after the call XX parameter.

    Like this.

    Call 34 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    In theory the string can be:

    Call 4006 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA
  • ericmedleyericmedley Posts: 4,177
    The string from the Tandberg continues after the call XX parameter.

    Like this.

    Call 34 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    In theory the string can be:

    Call 4006 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    Well, that string is too long to fit in your 50 char buffer. Perhaps make the buffer size large enough to hold it and see.
  • a_riot42a_riot42 Posts: 1,624
    The string from the Tandberg continues after the call XX parameter.

    Like this.

    Call 34 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    In theory the string can be:

    Call 4006 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    If that is your actual string you could use atoi() on the whole string and it will ignore all non numerical parts of the string and just give you the digits. That would require that no other numbers show up in your data though. Otherwise I think I would use

    remove_string(sIncMsg,'Call ',1)
    atoi(remove_string(sIncMsg,' ',1))

    Paul
  • a_riot42 wrote: »
    If that is your actual string you could use atoi() on the whole string and it will ignore all non numerical parts of the string and just give you the digits. That would require that no other numbers show up in your data though. Otherwise I think I would use

    remove_string(sIncMsg,'Call ',1)
    atoi(remove_string(sIncMsg,' ',1))

    Paul

    This is what the actual string looks like
    ACTIVE(FIND_STRING(sIncMsg,'*s Call 46 Status: Connected$0D$0A*s Call 46 Direction: Outgoing',1)):
    
  • viningvining Posts: 4,368
    Put SEND_STRING 0,"DATA.TEXT" ; in your string handler to show what you're are actually receiving form the device. It would definitely help if we could actually see what's coming in before suggesting how best to handle it.

    Now based on this:
    Like this.

    Call 34 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    In theory the string can be:

    Call 4006 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA

    I would try this:
    DATA_EVENT[dvTandberg]
         {
         STRING:
    	  {
    	  stack_var integer nFBS ;
    	  stack_var char sIncMsg[256] ;
    	  
    	  SEND_STRING 0,"DATA.TEXT" ;
    	  while(find_string(data.text,"$0D,$0A",1))
    	       {
    	       sIncMsg = remove_string(data.text,"$0D,$0A",1);
    	       SELECT
    		    {	
    		    ACTIVE(FIND_STRING(sIncMsg,'Call',1)):
    			 {
    			 remove_string(sIncMsg,'Call',1);
    			 nFBS = find_string(DATA.TEXT,'status=',1) ;
    			 if(nFBS)//found
    			      {
    			      nCallId = atoi(GET_BUFFER_STRING(data.text,nFBS-1) ;
    			      }
    			 else
    			      {
    			      SEND_STRING 0,"'Bummer, didn''t find what I''m looking for!'" ;
    			      }
    			 }	
    		    }	 
    	       }
    	  }
         }
    
    Also in your code example:
    ACTIVE(FIND_STRING(sIncMsg,'*s Call    ',1)):
    		{
    		    remove_string(sIncMsg,'*s Call',1);
    
    You're looking for a string with *s and you example above doesn't show that which is why using the send_string 0 to show what you actually get is very helpful. Also when I use find_string and then use remove_string I always make the strings identical. You have spaces called for in your find_string but not your remove string and it is always possible that there may be a "Call" before a "Call " followed by spaces in the returned string and that will really screw with you head until you realize what's going on.
  • Thanks for the answers so far.

    I dont have access to a c-series codec right now so i'll have to wait a few days before i can post the acctual string.

    I believe the *s is the correct beginning of the string, is just me trying out different stuff.

    Lets say the String looks like this:
    *s Call NA status=NA, type=NA, protocol=NA, direction=NA, logTag=NA
    

    All the NA are variables and will change from call to call, it can be both letters and numbers. I want to get the string, then dispose *s Call and everything from status to the end of the string. Then i will be left with the call-id regardless of how many digits it made of.

    Does this sound correct?

    When i send the string to 0, where do i read that string?
  • viningvining Posts: 4,368
    the diagnostic tab opens the diagnostic window in NS. right click and enable.

    Are they always in the same order?

    Are they always seperated by commas as in your example.

    Do the send_string 0 and let's see what and how strings come in.
  • Here is the string direct from the diagnostics window.

    String From [5001:3:1]-[*s Call 8 Status: Connected$0D$0A*s Call 8 Direction: Outgoing$0D$0A*s C]
    String From [5001:3:1]-[all 8 Protocol: "h323"$0D$0A*s Call 8 CallType: Video$0D$0A*s Call 8 Rem]
    String From [5001:3:1]-[oteNumber: "21625200"$0D$0A*s Call 8 CallbackNumber: "h323:21625200"]
    String From [5001:3:1]-[$0D$0A*s Call 8 DisplayName: "HCB-CVCE003"$0D$0A*s Call 8 TransmitCallRa]
    String From [5001:3:1]-[te: 768$0D$0A*s Call 8 ReceiveCallRate: 768$0D$0A*s Call 8 Encryption Ty]
    String From [5001:3:1]-[pe: "None"$0D$0A*s Call 8 PlacedOnHold: False$0D$0A*s Call 8 Duration: 5]
    String From [5001:3:1]-[85$0D$0A** end$0D$0A$0D$0AOK$0D$0A]
  • viningvining Posts: 4,368
    You can see by the send_string 0 returns that you're not always receiving a complete beginning *s and end $0D,$0A so you must create a local var and append your incoming data.text to it. This will ensure that you don't miss parts of your strings being returned form the device.

    There were errors in the previous example so that shouldn't have worked anyway. Based on what the send_string 0's returned this example should (if it actually compiles) be pretty close to what you want.
    DATA_EVENT[dvTandberg]
         {
         STRING:
    	  {
    	  STACK_VAR CHAR cRxBuff[512] ;
    	  
    	  SEND_STRING 0,"'Rx data :',DATA.TEXT" ;
    	  
    	  cRxBuff = "cRxBuff,DATA.TEXT" ;
    	  while(find_string(cRxBuff,"$0D,$0A",1))
    	       {
    	       stack_var integer nFBS ;
    	       stack_var char sIncMsg[256] ;
    	       
    	       sIncMsg = REMOVE_STRING((cRxBuff,"$0D,$0A",1);
    	       SET_LENGTH_STRING(sIncMsg,length_string(sIncMsg)-2) ;//removes the trailing $0D,$0A
    	       nFBS = find_string(sIncMsg,"'*s'",1) ;
    	       if(nFBS)
    		    {
    		    STACK_VAR INTEGER nCnt ;
    		    STACK_VAR CHAR cData[5][64] ;
    		    
    		    if(nFBS > 1)
    			 {
    			 GET_BUFFER_STRING(sIncMsg,nFBS - 1) ;// somehow junks in front so remove
    			 }
    		    WHILE(find_string(sIncMsg,"' '",1))
    			 {
    			 nCnt++ ;
    			 cData[nCnt] = REMOVE_STRING(sIncMsg,"' '",1) ;
    			 SET_LENGTH_STRING(cData[nCnt],length_string(cData[nCnt])-1) ;//removes the trailing ' ' (space)
    			 }
    		    cData[nCnt] = sIncMsg ;
    		    fnProcessData(cData) ; ///create a function to process data ot just handle it here
    		    }
    	       else
    		    {
    		    SEND_STRING 0,"'ERR! received bad format str: [ ',sIncMsg,' ]'" ;
    		    REMOVE_STRING(sIncMsg,"$0D,$0A",1)
    		    }
    	       }
    	  }
         }
    
    Hope this helps.

    I've been trying to code in UNIX (shell) and Perl this past week and I've found that life would be alot easier if there were decent examples available (googling) instead of trying to read a bunch of cryptic manuals that just make my eyes glaze over. If I can see how it's done I can usually understand but trying to figure $**** out from scratch just sucks.
Sign In or Register to comment.