' GPRSMIB
' This example shows how to read variables from the
' Sarian MIB.
' This program reads the GPRS MIB variables every 10 secs
' The information is formatted and displayed.
' Loops 10 times
' Use "basic 0 kill" to stop it

' This function uses the mib() function to read
' a MIB variable. It then breaks up the resultant
' string and returns the value of the variable.
'
function mib_val(var_name)
    local a
    split chomp(mib(var_name)) by "=" to junk, a
    mib_val = a
end function

'
' Main program starts here
'

' string constant for a newline
'
const nl = "\r\n"

' This causes execution to jump to our error
' handling label if any statement causes an
' error to be raised
'
on error goto ErrorLabel

' the following codes are used for registration status
reg_str[0] = "not registered, not searching"
reg_str[1] = "registered home network"
reg_str[2] = "not registered, searching"
reg_str[3] = "registration denied"
reg_str[4] = "unknown"
reg_str[5] = "registered, roaming"

' The main loop collects the MIB variables and
' formats the results
'
for i = 1 to 10

' collect the GPRS info
'
    gprs_signal = mib_val("gprs.0.stats.signal")
    gprs_registration = mib_val("gprs.0.stats.registered")
    gprs_attachment = mib_val("gprs.0.stats.attached")

' format and display the data
'
    print FormatDate("0H:0m:0s, 0D-MON-YEAR ",GmTime()),nl
    print "Signal       = ", gprs_signal, " dBm", nl
    reg_val = val(gprs_registration)
    if reg_val < 0 or reg_val > 5 then
        reg_val = 4
    endif
    print "Registration = ", gprs_registration, " (", reg_str[reg_val], ")", nl
    if val(gprs_attachment) = 1 then
        print "Attachment   = ", gprs_attachment, " (attached)", nl
    else
        print "Attachment   = ", gprs_attachment, " (not attached)", nl
    endif
    print nl

' sleep for 10 secs before looping
'
    sleep(10)

next i

print "Test complete", nl
stop

ErrorLabel:
print "An Error occured: ", error$, "\r\n"
