[Asterisk-biz] gotta be a better way

Bill Michaelson bill at cosi.com
Tue Nov 22 17:17:36 MST 2005


Sorry, I intended to post to users, but realized it went to biz 
afterward.  Long story as to why.  I thought it would be silly to post a 
retraction too.

Since you've answered (thanks), I might as well complete the thread.  I 
am not trying to determine the device type.  I am trying to determine 
the device identification, like say, "SIP/12345", or whatever.  I use it 
to associate configurable attributes with physical stations.  I noticed 
that channel names are comprised of this device ID with five more 
characters appended, presumably for uniqueness.  My code removes these 
last five characters, and it does in fact work as intended in my 
application.

But as I implied, I think it is less than elegant.  And it seems that 
there ought to be a variable that directly represents the value I want, 
but I hadn't found it documented.

Hence my inquiry.

Thanks again for your input.

C F wrote:

>This belongs at asterisk users, if you want some real help you should
>try that list.
>Your code doesn't make sense to me, if all your trying to see is what
>device type is making the call then this will do:
>
>set(DTYPE=${CHANNEL:0:4}) should give you either SIP/ or ZAP/ for those 2 types.
>
>if you want everyting after the slash ('/') then this will do for
>
No, I want everything before the last hyphen, which seems to mean that I 
want to omit the last 5 characters.

>local, sip, and zap:
>exten => 807,1,GotoIf($[${CHANNEL:0:5} = Local]?20)
>exten => 807,2,GotoIf($[${CHANNEL:0:3} = Zap]?30)
>exten => 807,3,Noop(not zap or local so must be sip)
>exten => 807,4,Set(DEVICE=${CHANNEL:4})
>exten => 807,5,Noop(${DEVICE})
>exten => 807,20,Set(DEVICE=${CHANNEL:6})
>exten => 807,21,Noop(${DEVICE})
>exten => 807,30,Set(DEVICE=${CHANNEL:4})
>exten => 807,31,Noop(${DEVICE})
>
>if you want the above but that device should never contain the hex
>value for the SIP calls, so that all you get is the device from
>sip.conf and not the -abc3:
>
This is closer to what I am seeking.

>exten => 807,1,GotoIf($[${CHANNEL:0:5} = Local]?20)
>exten => 807,2,GotoIf($[${CHANNEL:0:3} = Zap]?30)
>exten => 807,3,Noop(not zap or local so must be sip)
>exten => 807,4,Set(DEVICE=${CHANNEL:4:$[${LEN(${CHANNEL})} - 9]})
>exten => 807,5,Noop(${DEVICE})
>exten => 807,20,Set(DEVICE=${CHANNEL:6})
>exten => 807,21,Noop(${DEVICE})
>exten => 807,30,Set(DEVICE=${CHANNEL:4})
>exten => 807,31,Noop(${DEVICE})
>
>The above should give you 1324 for a channel that holds SIP/1234-abc3
>
>On 11/22/05, Bill Michaelson <bill at cosi.com> wrote:
>  
>
>>Based on what I've read about Asterisk variables, I'm considering this
>>ugly snippet to determine the device from which a call originates in
>>order to drive further processing...
>>
>>exten => 807,1,Set(L=${LEN(${CHANNEL})})
>>exten => 807,2,set(L=${MATH(${L}-5)})
>>exten => 807,3,noop(${L})
>>exten => 807,4,set(DEVICE=${CHANNEL:0:${L}}) ; chop off 5 chars
>>
>>
>>I strongly suspect that there is a better way.
>>
>>Eh?
>>
>>
>>_______________________________________________
>>Asterisk-Biz mailing list
>>Asterisk-Biz at lists.digium.com
>>http://lists.digium.com/mailman/listinfo/asterisk-biz
>>
>>    
>>
>_______________________________________________
>Asterisk-Biz mailing list
>Asterisk-Biz at lists.digium.com
>http://lists.digium.com/mailman/listinfo/asterisk-biz
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-biz/attachments/20051122/68093a0e/attachment.htm


More information about the asterisk-biz mailing list