📄 nokiaplugin.vb
字号:
Throw New ApplicationException("Can't get your Own number")
End If
End Function
''' <summary>
''' Get quality of service
''' </summary>
''' <returns>QoS in unit -mdB, smaller is better</returns>
''' <remarks></remarks>
Public Function GetQualityOfService() As Integer Implements PhoneControllerSDK.IPhoneController.GetQualityOfService
Dim rst As String = mATCmd.SendCommand("AT+CSQ")
Dim regex As Regex = New Regex( _
"\+CSQ:\s(?<LEVEL>\d*),(?<BER>\d*)", _
RegexOptions.None _
)
Dim m As Match = regex.Match(rst)
If m.Success Then
Dim level As Integer = CInt(m.Groups("LEVEL").Value)
Select Case level
Case 0
Return -113
Case 1
Return -111
Case 2 To 30
Return -109 + level * 2
Case 31
Return -51
Case 99
Return 0
End Select
Else
Throw New ApplicationException("Can't get your quality of service")
End If
End Function
''' <summary>
''' Get your current phonebook status
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetPhonebookStatus() As PhoneControllerSDK.PhonebookStatus Implements PhoneControllerSDK.IPhoneController.GetPhonebookStatus
'Get phone book capacity
Dim regexReadEntirePb As Regex = New Regex( _
"\+CPBS:\s""(?<MEM>\w*)"",(?<USED>\d+),(?<CAPACITY>\d+)")
Dim rst As String = mATCmd.SendCommand("AT+CPBS?")
If ATCommandBase.CheckResponse(rst) = False Then Throw New ApplicationException("Can't execute AT+CPBS?")
Dim m As Match = regexReadEntirePb.Match(rst)
Dim result As PhonebookStatus
result.Used = CInt(m.Groups("USED").Value)
result.Capacity = CInt(m.Groups("CAPACITY").Value)
Return result
End Function
''' <summary>
''' Read all phonebook entry
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function ReadAllPhonebookEntry() As PhoneControllerSDK.PhonebookEntry() Implements PhoneControllerSDK.IPhoneController.ReadAllPhonebookEntry
Dim pbStatus As PhonebookStatus = GetPhonebookStatus()
Dim result(pbStatus.Used - 1) As PhonebookEntry
Dim i As Integer = 1, j As Integer = 1
Do Until j > pbStatus.Used
Dim entry As PhonebookEntry = ReadPhonebookEntry(i)
If entry.Index <> 0 Then
result(j - 1) = entry
j += 1
End If
'Added at 10/2/2005
If mCancel = True Then
ReDim Preserve result(j - 2)
End If
i += 1
Loop
Return result
End Function
''' <summary>
''' Read phonebook entry
''' </summary>
''' <param name="index"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ReadPhonebookEntry(ByVal index As Integer) As PhoneControllerSDK.PhonebookEntry Implements PhoneControllerSDK.IPhoneController.ReadPhonebookEntry
Dim regexCPBSIndex As Regex = New Regex( _
"\+CPBR:\s(?<Index>\d*),""(?<Num>(\w|\+|\*)*)"",(?<Type>\d*),""(?<Nam" _
+ "e>\w*)""")
Dim rst As String = mATCmd.SendCommand("AT+CPBR=" & index)
If ATCommandBase.CheckResponse(rst) = False Then Throw New ApplicationException("Can't execute AT+CPBR=<index>")
Dim m As Match = regexCPBSIndex.Match(rst)
If m.Success = False Then Return New PhonebookEntry
Dim pbEntry As PhonebookEntry = New PhonebookEntry
With pbEntry
.Index = CInt(m.Groups("Index").Value)
.SIMNumber = m.Groups("Num").Value
Select Case currentCharactorSet
Case CharactorSet.ASCII
.Name = m.Groups("Name").Value
Case CharactorSet.UCS2
.Name = DecodeUnicode(m.Groups("Name").Value)
End Select
End With
Return pbEntry
End Function
''' <summary>
''' Read SMS By index
''' </summary>
''' <param name="index"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ReadSMSByIndex(ByVal index As Integer) As PhoneControllerSDK.SMSRead Implements PhoneControllerSDK.IPhoneController.ReadSMSByIndex
Dim rsp As String = mATCmd.SendCommand("AT+CMGR=" & index)
rsp = rsp.Replace(vbCrLf, vbLf)
rsp = rsp.Replace(vbLf, vbCrLf)
Dim match As Match = regexCMGR.Match(rsp)
Dim ATSMS As New AT_SMS_Response
'Return if no sms found. Length value will be zero
If match.Groups("length").Value = "0" Then
Return Nothing
End If
ATSMS.Index = index
Select Case CInt(match.Groups("stat").Value)
Case 0
ATSMS.Status = ATSMSStatus.REC_UNREAD
Case 1
ATSMS.Status = ATSMSStatus.REC_READ
Case 2
ATSMS.Status = ATSMSStatus.STO_UNSENT
Case 3
ATSMS.Status = ATSMSStatus.STO_SENT
End Select
ATSMS.PDUCode = match.Groups("PDU").Value
Dim SMS() As SMSRead
SMS = New SMSRead() {DecodeSMS(ATSMS.Index, ATSMS.PDUCode)}
Return SMS(0)
End Function
''' <summary>
''' Read SMS By Status
''' </summary>
''' <param name="status"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ReadSMSByStatus(ByVal status As PhoneControllerSDK.ATSMSStatus) As PhoneControllerSDK.SMSRead() Implements PhoneControllerSDK.IPhoneController.ReadSMSByStatus
Dim oldTimeOut As Integer = mATCmd.TimeOut
'Set a longer timeout to wait for AT+CMGL in low speed irDA Connection.
Dim newTimeOut As Integer = oldTimeOut * 20
mATCmd.TimeOut = newTimeOut
Dim rsp As String = mATCmd.SendCommand("AT+CMGL=" & status)
rsp = rsp.Replace(vbCrLf, vbLf)
rsp = rsp.Replace(vbLf, vbCrLf)
'Added at 10/2/2005
If mCancel = True Then Return Nothing
mATCmd.TimeOut = oldTimeOut
Dim matchCol As MatchCollection = regexCMGL.Matches(rsp)
If matchCol.Count = 0 Then
Dim r(-1) As SMSRead
Return r
End If
Dim ATSMS() As AT_SMS_Response
Dim i As Integer
For Each match As Match In matchCol
ReDim Preserve ATSMS(i)
ATSMS(i) = New AT_SMS_Response
ATSMS(i).Index = CInt(match.Groups("index").Value)
Select Case CInt(match.Groups("stat").Value)
Case 0
ATSMS(i).Status = ATSMSStatus.REC_UNREAD
Case 1
ATSMS(i).Status = ATSMSStatus.REC_READ
Case 2
ATSMS(i).Status = ATSMSStatus.STO_UNSENT
Case 3
ATSMS(i).Status = ATSMSStatus.STO_SENT
End Select
ATSMS(i).PDUCode = match.Groups("PDU").Value
i += 1
Next
Dim SMS(ATSMS.Length - 1) As SMSRead
For i = 0 To SMS.Length - 1
SMS(i) = DecodeSMS(ATSMS(i).Index, ATSMS(i).PDUCode)
Next
Return SMS
End Function
''' <summary>
''' Select phonebook type
''' </summary>
''' <param name="phonebookType"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function SelectPhonebookType(ByVal phonebookType As PhoneControllerSDK.PhonebookType) As Boolean Implements PhoneControllerSDK.IPhoneController.SelectPhonebookType
Select Case phonebookType
Case PhoneControllerSDK.PhonebookType.AddressBook
Return ATCommandBase.CheckResponse(mATCmd.SendCommand("AT+CPBS=""ME"""))
Case PhoneControllerSDK.PhonebookType.SIMCard
Return ATCommandBase.CheckResponse(mATCmd.SendCommand("AT+CPBS=""SM"""))
End Select
End Function
''' <summary>
''' Select where SMS stored
''' </summary>
''' <param name="mem1">Memory from which messages are read and deleted</param>
''' <param name="mem2">Messages will be written and sent to this memory storage</param>
''' <param name="mem3">Memory in which received messages are preferred to be stored, if routing to TE is not set (see AT+CNMI command with parameter mt=2</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function SelectSMSStorage(ByVal mem1 As PhoneControllerSDK.SMSStorage, ByVal mem2 As PhoneControllerSDK.SMSStorage, ByVal mem3 As PhoneControllerSDK.SMSStorage) As Boolean Implements PhoneControllerSDK.IPhoneController.SelectSMSStorage
Dim cmd As String = "AT+CPMS="
Select Case mem1
Case SMSStorage.MobileEquipment
cmd += """ME"","
Case SMSStorage.MobileTerminal
Throw New NotSupportedException("Memory1 can't support MobileTerminal")
cmd += """MT"","
Case SMSStorage.SIMCard
cmd += """SM"","
End Select
Select Case mem2
Case SMSStorage.MobileEquipment
cmd += """ME"","
Case SMSStorage.MobileTerminal
Throw New NotSupportedException("Memory2 can't support to MobileTerminal")
cmd += """MT"","
Case SMSStorage.SIMCard
cmd += """SM"","
End Select
Select Case mem3
Case SMSStorage.MobileEquipment
Throw New NotSupportedException("Memory2 can't support to MobileEquiment")
cmd += """ME"""
Case SMSStorage.MobileTerminal
cmd += """MT"""
Case SMSStorage.SIMCard
Throw New NotSupportedException("Memory2 can't support to SIM card")
cmd += """SM"""
End Select
Return ATCommandBase.CheckResponse(mATCmd.SendCommand(cmd))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -