Buchempfehlung
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
"Der" Petzold, das über 1000 Seiten starke Standardwerk zum Win32-API - besonders nützlich u. a. bei der GUI-Programmierung in FreeBASIC! [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

gsm.bas

Uploader:MitgliedThePuppetMaster
Datum/Zeit:18.08.2009 15:03:46

'##############################################################################################################
'##############################################################################################################
' gsm.bas --- GSM Command Modul Example Application
'##############################################################################################################
'##############################################################################################################
' 2009 By.: /_\ DeltaLab's Germany - Experimental Computing
' Autor: Martin Wiemann
'##############################################################################################################
' "Do What The Fuck U Want" Licence
'##############################################################################################################
'##############################################################################################################





'####################################################################################################################################
#include once "GSM_ACM.bi"                  'Include GSM Command Modul





'####################################################################################################################################
'Build Callback's for autonomus GSM_Event's
Sub GSMACM_IncommingSMS(V_DeviceID as Integer, V_SMSID as UInteger, V_CallerID as String, V_ReceiveTime as Double, V_Message as String)
Print "Incomming SMS! DeviceID: "; V_DeviceID; "   SMSID: "; V_SMSID; "   CallerID: "; V_CallerID; "   ReceiveTime: "; Format(V_ReceiveTime, "yyyy.mm.dd - mmmm - dddd - hh:nn:ss"); "   Message: "; V_Message
End Sub

'------------------------------------------------------------------------------------------------------------------------------------
Sub GSMACM_IncommingCall(V_DeviceID as Integer, V_CallerID as String)
Print "Incomming call from DeviceID: "; V_DeviceID; "   CallerID: "; V_CallerID
GSMACM_Call_Denied(V_DeviceID)
Print "Calling was denied! -> HangUp"
End Sub

'------------------------------------------------------------------------------------------------------------------------------------
Sub GSMACM_NetworkStateChange(V_DeviceID as Integer, V_NewNetworkState as GSMACM_NetworkState_Enum)
Print "New Network State from DeviceID: "; V_DeviceID; "   New State: ";
Select Case V_NewNetworkState
    Case GSMACM_NS_NoLogin_NoNetsearch: Print "Not logged on. No network search."
    Case GSMACM_NS_Login_Homenet:       Print "Logged on into homenetwork."
    Case GSMACM_NS_NoLogin_Netsearch:   Print "Not logged on. Searching network."
    Case GSMACM_NS_NoLogin_LoginDenied: Print "Not logged on. Login denied."
    Case GSMACM_NS_Unknown:             Print "Unknown network state."
    Case GSMACM_NS_Login_AnotherNet:    Print "Logged on into another network."
    Case Else:                          Print "unknown"
End Select
End Sub





'####################################################################################################################################
Dim XDeviceID as Integer
Dim RV as GSMACM_GuruCode
RV = GSMACM_Open(0, 115200, XDeviceID)              'Open Com-Port "0" and return (if no error) the DeviceID for this Interface.
If RV <> GSMACM_NoError Then                      'On Error ...
    Print "[ERROR] "; GSMACM_GetGURUCode(RV)      '... Print the error-description ...
    End -1                                          '... and termiante the application
End If


Print
Dim XLoadState as UByte
Dim XLoadLevel as UByte
RV = GSMACM_Get_BatteryState(XDeviceID, XLoadState, XLoadLevel)
If RV = GSMACM_NoError Then
    Print "Current battery loading state: ";
    If XLoadState = 0 Then
        Print "Don't loading!"
    Else
        Print "Loading battery..."
    End If
    Print "Current battery load level in percent: "; Str(XLoadLevel); "%"
Else: Print "[ERROR] BatteryState: "; GSMACM_GetGURUCode(RV)
End If



Dim XTime as Double
RV = GSMACM_Get_Time(XDeviceID, XTime)
If RV = GSMACM_NoError Then
    Print "Current phone time: "; Format(XTime, "yyyy.mm.dd - mmmm - dddd - hh:nn:ss")
Else: Print "[ERROR] Time: "; GSMACM_GetGURUCode(RV)
End If



Dim XManufacture as String
RV = GSMACM_Get_Manufacturer(XDeviceID, XManufacture)
If RV = GSMACM_NoError Then
    Print "Phone manufacture: "; XManufacture
Else: Print "[ERROR] Manufacture: "; GSMACM_GetGURUCode(RV)
End If



Dim XModelname as String
RV = GSMACM_Get_Model(XDeviceID, XModelname)
If RV = GSMACM_NoError Then
    Print "Phone model: "; XModelname
Else: Print "[ERROR] Model: "; GSMACM_GetGURUCode(RV)
End If



Dim XRevision as String
RV = GSMACM_Get_Revision(XDeviceID, XRevision)
If RV = GSMACM_NoError Then
    Print "Phone revision: "; XRevision
Else: Print "[ERROR] Revision: "; GSMACM_GetGURUCode(RV)
End If



Dim XIMEI as String
RV = GSMACM_Get_IMEI(XDeviceID, XIMEI)
If RV = GSMACM_NoError Then
    Print "Phone IMEI: "; XIMEI
Else: Print "[ERROR] IMEI: "; GSMACM_GetGURUCode(RV)
End If



Dim XIMSI as String
RV = GSMACM_Get_IMSI(XDeviceID, XIMSI)
If RV = GSMACM_NoError Then
    Print "Phone IMSI: "; XIMSI
Else: Print "[ERROR] IMSI: "; GSMACM_GetGURUCode(RV)
End If



Dim XSignalID as UByte
Dim XdBm as String
RV = GSMACM_Get_RSSI(XDeviceID, XSignalID, XdBm)
If RV = GSMACM_NoError Then
    Print "Signal Level: "; XdBm; "dBm"
    Print "Signal Level (SignalID): "; Str(XSignalID)
Else: Print "[ERROR] Signal Level: "; GSMACM_GetGURUCode(RV)
End If



Dim XNetworkstate as GSMACM_NetworkState_Enum
RV = GSMACM_Get_NetworkState(XDeviceID, XNetworkstate)
If RV = GSMACM_NoError Then
    Print "Network State: ";
    Select Case XNetworkstate
        Case GSMACM_NS_NoLogin_NoNetsearch: Print "Not logged on. No network search."
        Case GSMACM_NS_Login_Homenet:       Print "Logged on into homenetwork."
        Case GSMACM_NS_NoLogin_Netsearch:   Print "Not logged on. Searching network."
        Case GSMACM_NS_NoLogin_LoginDenied: Print "Not logged on. Login denied."
        Case GSMACM_NS_Unknown:             Print "Unknown network state."
        Case GSMACM_NS_Login_AnotherNet:    Print "Logged on into another network."
        Case Else:                          Print "unknown"
    End Select
Else: Print "[ERROR] Network State: "; GSMACM_GetGURUCode(RV)
End If



Dim XSMSCount as UInteger
RV = GSMACM_SMS_GetCount(XDeviceID, XSMSCount)
If RV = GSMACM_NoError Then
    Print "Number of SMS in phone: "; Str(XSMSCount)
Else: Print "[ERROR] SMS count: "; GSMACM_GetGURUCode(RV)
End If



Dim XSMSListC as UInteger
Dim XSMSListD() as UInteger
RV = GSMACM_SMS_GetIDList(XDeviceID, XSMSListD(), XSMSListC)
If RV = GSMACM_NoError Then
    Print "SMS IDList. Number of SMS in phone: "; XSMSListC
    For X as UInteger = 1 to XSMSListC
        Print " "; Str(X); "   ID: "; Str(XSMSListD(X))
    Next
Else: Print "[ERROR] SMS list: "; GSMACM_GetGURUCode(RV)
End If



Dim XSMSState as UInteger
Dim XSMSCallerID as String
Dim XSMSTime as Double
Dim XSMSMessage as String
For X as UInteger = 1 to XSMSListC
    RV = GSMACM_SMS_GetData(XDeviceID, XSMSListD(X), XSMSState, XSMSCallerID, XSMSTime, XSMSMessage)
    If RV = GSMACM_NoError Then
        Print "SMS Data. SMSID: "; XSMSListD(X); "   State: ";
        Select Case XSMSState
            Case GSMACM_SMSS_RecUnread:     Print "Received and unread!";
            Case GSMACM_SMSS_RecRead:       Print "Received and read!";
            Case GSMACM_SMSS_StoUnsent:     Print "Stored and unsent!";
            Case GSMACM_SMSS_StoSent:       Print "Stored and sent!";
            Case GSMACM_SMSS_All:           Print "All messages!";
            Case Else:                      Print "unknown";
        End Select
        Print "   CallerID: "; XSMSCallerID; "   ReceiveTime: "; Format(XSMSTime, "yyyy.mm.dd - mmmm - dddd - hh:nn:ss"); "   Message: >"; XSMSMessage; "<"
    Else: Print "[ERROR] SMS data (" & Str(X) & ": "; GSMACM_GetGURUCode(RV)
    End If
Next



'For X as UInteger = 1 to XSMSListC
'   RV = GSMACM_Get_SMS_Delete(XDeviceID, XSMSListD(X))
'   If RV = GSMACM_NoError Then
'       Print "SMS Delete. SMSID: "; XSMSListD(X)
'   Else: Print "[ERROR] SMS delete (" & Str(X) & ": "; GSMACM_GetGURUCode(RV)
'   End If
'Next


'Set Callbacks for autonomus event signing
'Last parameter "0" are for the NON Deleting of new SMS Event
GSMACM_RegistCallback(XDeviceID, @GSMACM_IncommingSMS, @GSMACM_IncommingCall, @GSMACM_NetworkStateChange, 0)




Do Until InKey() = Chr(27)                          'Wait until ESC pushed
    Sleep 1, 1                                      'Sleep a little bit to give the modul time to check the device state and create Event's
Loop

Print "Device close: "; GSMACM_GetGURUCode(GSMACM_Close(XDeviceID)) 'Close the Device before end the application
End 0                                               'Terminate Application (whisout errors)