Last year, I contacted China Unicom's "Positioning Star" value-added business, the client is PHP's PHP (said PHP, I really found that I did too little to see PHP, the function is still very powerful, huh, huh), because Unicom does not open the development test, So I wrote this simulator, which is very simple, purely for testing communication.
Tony said nonsense, the source code is posted (the old rules of the shell shell, not much notes)
frmmain.frm
VERSION 5.00Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D} # 1.0 # 0"; "MSWINSCK.OCX" Begin VB.Form frmMain BorderStyle = 1 'Fixed Single Caption = "L1 Protocol GateWay" ClientHeight = 5430 ClientLeft = 45 ClientTop = 330 ClientWidth = 7995 Icon = "frmMain.frx": 0000 LinkTopic = "Form1" MaxButton = 0 'False ScaleHeight = 5430 ScaleWidth = 7995 StartUpPosition = 2' CenterScreen Begin VB.Timer tmrTimeOut Interval = 1000 Left = 7560 Top = 4980 End Begin VB.CommandButton cmdExit Caption = "E & xit" Height = 495 Left = 6660 TabIndex = 5 Top = 4800 Width = 1215 End Begin VB.CommandButton cmdStop Caption = "S & top" Height = 495 Left = 6660 TabIndex = 4 Top = 4200 Width = 1215 End Begin VB.CommandButton cmdLTRTask Caption = "& LTR Task" Height = 495 Left = 5340 TabIndex = 3 Top = 4800 Width = 1215 End Begin VB.CommandButton cmdStart Caption = "& Start" Height = 495 Left = 5340 TabIndex = 2 TOP = 4200 width =
1215 End Begin VB.TextBox txtLTR Height = 1095 Left = 120 MultiLine = -1 'True ScrollBars = 2' Vertical TabIndex = 1 Top = 4200 Width = 5115 End Begin VB.TextBox txtLog Height = 3975 Left = 120 MultiLine = -1 ' true ScrollBars = 2 'Vertical TabIndex = 0 Top = 120 Width = 7755 End Begin MSWinsockLib.Winsock sckServer Index = 0 Left = 0 Top = 0 _ExtentX = 741 _ExtentY = 741 _Version = 393216 EndEndAttribute VB_Name = "frmMain" Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = Falsettribute vb_predeclaredid = trueattribute vb_exposed = falseOption Explicitdim INTCURIDX AS INTEGER
Private subdexit_click () unload mend Sub
Private sub cmdstart_click () Sckserver (0) .localport = SVRPORT SCKSERVER (0) .Listen Call Writelog ("Start ..." & VBCRLF) End Sub
Private sub cmdstop_click () Sckserver (0) .close Call Writelog ("Stop ..." & VBCRLF) End Sub
Private sub form_load () redim lcsclient (1) with lcsclient (0) .ip = "61.181.74.13" .password = "12345" .Username = "TTA" .port = 2001 End with
Redim Client (0) Redim Closelist (0)
INTCURIDX = 0
SVRPORT = 2000END SUB
Private Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer) EndEnd SubPrivate Sub sckServer_ConnectionRequest (Index As Integer, ByVal requestID As Long) Dim i As Integer If Index <> 0 Then Exit Sub For i = 1 To intCurIdx If Not IsObject (sckServer ( I))) Sckserver (i) .accept requestid client (i) .IP = SCKSERVER (i) .Remotehostip Call Writelog (Sckserver (i) .Remotehostip & "IS Connected ..." & VBCRLF) EXIT SUB ELSE IF SCKSERVER (i) .State = Sckclosed The Sckserver (i) .accept requestid client (i) .IP = Sckserver (i) .Remotehostip Call Writelog (Sckserver (i) .Remotehostip & "IS Connected ..." & "IS Connected ..." & vbCrLf) Exit Sub End If End If Next intCurIdx = intCurIdx 1 Load sckServer (intCurIdx) sckServer (intCurIdx) .Accept requestID ReDim Preserve Client (intCurIdx) With Client (intCurIdx). IP = SCKSERVER (INTCURIDX) .Remotehostip End with call Writelog (INTCURIDX) .Remotehostip & "IS Connected ..." & VBCRLF) End Sub
Private Sub sckServer_DataArrival (Index As Integer, ByVal bytesTotal As Long) Dim str As String If Index = 0 Then Exit Sub sckServer (Index) .GetData str txtLog.Text = txtLog.Text & str & vbCrLf txtLog.SelStart = Len (txtLog. IF Left (STR, 4) <> "post" TEN CALL Sendmsg (INDEX, "Couldn't Support the Operation") Call RemoveClient (Index) EXIT SUB End if Do Str = MID (Str, INSTR (STR, VBCRLF ) 2) Loop while INSTR (STR, VBCRLF) <> 1 Str = MID (Str, INSTR (STR, VBCRLF) 2) Call Parsexml (INDEX, STR) txtlog.text = txtlog.text & "Send Complete" & " vbCrLfEnd SubPrivate Sub sckServer_Error (Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) If Index = 0 Then sckServer (0 ) .Localport = SVRPORT SCKSERVER (0) .Listen Exit Sub end if Sckserver (Index) .State <> S CKClosed the Sckserver (Index) .closend Sub
Private sub sckserver_sendcomplete (index as integer) DIM i as integer for i = 0 to Ubound (closelist) - 1 if Closelist (i) = index damserver (index) .close Exit Sub End if Nextend SUB
Modmain.bas
Attribute vb_name = "modmain" option expedition
Private Type TypeClient IP As String Socketidx As Integered Typepublic Client () As TypeClient
Private TypelcsClient UserName As String Password AS String IP As String Port As Stringend TypePublic Lcsclient () AS TypelcsClient
Public clooselist () AS Integer
Public const Maxcon as byte = 5public Svrport AS String
Public Sub ParseXML (ByVal idx As Integer, ByVal str As String) Dim xml As MSXML.DOMDocument Dim nodeREQ As IXMLDOMNode Dim nodeCLIENT As IXMLDOMNode Dim nodeORIGINATOR As IXMLDOMNode Dim nodeLIR As IXMLDOMNode Dim nodeLTR As IXMLDOMNode Dim nodeLCTR As IXMLDOMNode Set xml = New MSXML. Domdocument if not Xml.LoadXML (STR) THEN CALL Sendmsg (IDX, "Not Valid XML") EXIT SUB End IF 'Take the Req Node Set Nodereq = Xml.selectsinglenode ("Req") if Nodereq is nothing then' No Req node, returns an error Call SendMsg (idx, "could not support the operation") Exit Sub End If 'taken CLIENT node Set nodeCLIENT = nodeREQ.selectSingleNode ( "CLIENT") If nodeCLIENT Is Nothing Then' no CLIENT node returns an error Call SendMsg ( idx, "could not support the operation") Exit Sub End If 'authentication Dim nodeLCSCLIENTID As IXMLDOMNode Dim nodePASSWORD As IXMLDOMNode Set nodeLCSCLIENTID = nodeCLIENT.selectSingleNode ( "LCSCLIENTID") Set nodeP ASSWORD = nodeCLIENT.selectSingleNode ( "PASSWORD") If nodeCLIENT Is Nothing Or nodePASSWORD Is Nothing Then Call SendMsg (idx, "could not support the operation") Exit Sub End If If Not IsValidSP (nodeLCSCLIENTID.Text, nodePASSWORD.Text, frmMain .sckServer (idx) .RemoteHostIP) Then Call SendMsg (idx, "access defined") Exit Sub End If 'fetch Set nodeORIGINATOR = nodeREQ.selectSingleNode ( "ORIGINATOR") Set nodeLIR = nodeREQ.selectSingleNode ( "LIR") Set nodeLTR = nodereq.selectsinglenode ("LTR") set nodelctr =
nodeREQ.selectSingleNode ( "LCTR") If nodeORIGINATOR Is Nothing Then 'LCTR If nodeLCTR Is Nothing Then Call SendMsg (idx, "could not support the operation") Exit Sub End If Dim nodeREQ_ID As IXMLDOMNode Set nodeREQ_ID = nodeLCTR.selectSingleNode ( " ReQ_ID ") if nodereq_id is nothing then call sendmsg (IDX," HAS NO REQ_ID ") EXIT SUB END IF ELSE 'LIR OR LTR IF (Nodeltor Is Nothing) OR (NOT Nodelir Is Nothing) And (Not nodeLTR Is Nothing)) Then Call SendMsg (idx, "could not support the operation") Exit Sub End If If nodeLTR Is Nothing Then 'LIR Dim nodeORID As IXMLDOMNode Set nodeORID = nodeORIGINATOR.selectSingleNode ( "ORID") If Nodeorid Is Nothing Then Call Sendmsg (IDX, "HAS NO Orid") EXIT SUB END IF DIM NODEPQ OS As IXMLDOMNode Set nodePQOS = nodeLIR.selectSingleNode ( "PQOS") If nodePQOS Is Nothing Then Call SendMsg (idx, "PQOS Field missing") Exit Sub End If Dim nodeRESPTIMER As IXMLDOMNode Set nodeRESPTIMER = nodePQOS.selectSingleNode ( "RESP_TIMER") Dim WT as long wt = clng (noderesptimer.text) frmmain.txtLog.text = frmmain.txtlog.text & "wait" & wt & "sec ..." & vbcrlf Dim o as long o = Timer Do Until Timer - O>
wt DoEvents Loop frmMain.txtLog.Text = frmMain.txtLog.Text & "send xml" & vbCrLf Dim strLIA As String strLIA = createLIA (nodeLCSCLIENTID.Text, nodeORID.Text) frmMain.txtLog.Text = frmMain.txtLog.Text & vbCrLf & strlia & vbcrlf & vbcrlf call sendmsg (idx, strlia) else 'LTR is not written, actually there is almost no such need, after all, system resources, it seems that China Unicom does not support, I don't know how I have end ifund subpublic subsendmsg now. ByVal idx As Integer, ByVal str As String) If IsObject (frmMain.sckServer (idx)) Then If frmMain.sckServer (idx) .State <> sckClosed Then frmMain.sckServer (idx) .SendData str ReDim Preserve CloseList (UBound (CloseList ) 1) Closelist (Ubound (closelist) - 1) = idx end if end ifend sub
Public Sub RemoveClient (ByVal socket As Integer) If IsObject (frmMain.sckServer (socket)) Then If frmMain.sckServer (socket) .State <> sckClosed Then frmMain.sckServer (socket) .Close End IfEnd Sub
Public Sub Writelog (Byval Str As String) frmmain.txtlog.text = frmmain.txtlog.text & strend sub
Private Function IsValidSP (ByVal uid As String, ByVal pwd As String, ByVal cip As String) As Boolean Dim i As Integer For i = 0 To UBound (LCSClient) - 1 If LCSClient (i) .UserName = uid And LCSClient (i) .Password = pwd and lcsclient (i) .IP = CIP THEN isvalidsp = true exit function end if next isvalidsp = false
Public Function createLIA (ByVal lcscid As String, ByVal orid As String) As String Dim xml As MSXML.DOMDocument Dim strHeader As String Dim strLIA As String Dim sngLatitude As Single, sngLongitude As Single Randomize Timer strHeader = " Xml version =" " 1.0 "" "" "Locans.dtd"> "strlia ="
_ " Lia>" & _ " ANS>" SET XML = new msxml.domdocument Xml.LoadXML strlia Xml.selectsinglenode ("/ ANS / LCSCSCLIENTID"). Text = lcscid Xml.selectsinglenode ("/ ANS / Orid) ") .Text = orid Xml.selectsinglenode (" / ANS / LIA / POSIS / POSI / MSID "). Text = Orid Xml.selectsinglenode (" / ANS / LIA / POSIS / POSI / LOCALTIME "). Text = Format (now , "yyyymmddhhmmss") sngLatitude = Rnd * 100000000/1000 xml.selectSingleNode ( "/ ANS / LIA / POSINFOS / POSINFO / LATITUDE"). Text = sngLatitude sngLongitude = Rnd * 100000000/1000 xml.selectSingleNode ( "/ ANS / LIA / Posinfos / posinfo / longitude "). Text = SNGLONGITUDE CREATELIA = strheader & xml.xmlend function
Introduction to the L1 agreement
1 Overview
1.1 L1 interface
According to PN4747, L
1 Interface is an interface between the CDMA Mobile Location Center (MPC) and the location service client (LCS Client).
L
1 Interface Protocol (CDMA Mobile Location Protocol) is an Application Level Protocol for a communication interface for MPC and SP position applications when locating the CDMA wireless positioning technique. This article describes the core set of the operation of the Movement Center (MPC) should be able to perform.
1.2 carrying method
L
1 Move positioning bearer protocol adopts HTTP / XML, ensuring the security of data transmission via SSL. XML (EXTENSIBLE MARKUP LANGUAGE) is an extended or extended tag language that is the advantage of defining the interface between the SP and MPC according to the designs, the interface between SP and MPCs often defines the parameters according to the needs of the function or service. This language can define the label on your own, and the establishment of data is very flexible.
The MPC sets two HTTP ports for SP, one by SSL to ensure data security, one does not need to use SSL. The former mainly provides users with non-trust domains, non-safe domains, such as users accessible by Internet secure data security; the latter provides users with trust domains, security domains, such as users accessible through the LAN, while not using SSL It can improve the data transfer speed.
You can choose two port number code as the recommended standard port. The port should be registered by IANA (INTERNET specified by the number). The recommendations for the two port number used in CDMA are as follows:
700 for SSL transmission
· 701 for non-secure transmission
MPC and location servers can select secure transmission based on technical or HTTP transparent technology based on other ports. However, no matter which technology used, the above two ports cannot be used.
The HTTP version is 1.1. For HTTP, see:
http://www.w3.org.
1.3 L1 syntax
1.3.1 agreed
Special symbol identification:
Enter (ASCII code is 13) CR
Renewal (ASCII code 10) LF
Space (ASCII code 32) SP
[A-Z] indicates that can be used for all lowercase letters
[A-Z] indicates that you can be all uppercase letters
[0-9] Indicates any number from 0 to 9
{min, max} represents the length between min and max
[A-Z, A-Z, 0-9] Indicates that all lowercase letters, all uppercase letters, 0 to 9 all numbers
Example:
[0-9] {7, 8} represents a digital string of length 7 or 8 bits, such as 8787767, in line with the requirements, and 119 does not meet the requirements.
[B-D] {3, 4} represents a string of B-D of 3 or 4 bits, such as BBC meets the requirements, BBCCD and ABC do not meet the requirements.
[A, C, 7-9] {1} indicates that may be A or C or 7 or 8 or 9
1.3.2 DTD grammar
Greater than or equal to 1
* Greater than or equal to 0
? 0 or 1
() A set of labels
| Or
, With, but have a presence