(6) OBEX application - file transfer section
Basic OBEX app is divided into mobile phone data transmission
l file transfer
l IRMC synchronization
File transfer can be subdivided into the following basic operations
l Initialize connection
l Disconnected
l Set the path
l acquistent catalog information
l Create a directory
l Upload download file
l Delete files or empty directories
Obex is designed in the author's software, which contains all the above basic operations. Also designed with the specificity of the server of the M55, renamed, acquired disk space information, move, copy file function. Please refer to the source code for details.
The details of each operation will be described below.
l Initialize connection
The initialization connection includes a series of processes that make the phone enter the OBEX state to send the Connect directive. Specific process reference views.
Atæat ^ SQWE = 0æat ^ SQWE = 3æconnectæ Connect to Folder-Listing Service
Where AT ^ SQWE = 0 and AT ^ SQWe = 3 are Siemens unique hidden AT instructions, even in the official AT instruction set. Its role is to initialize your mobile phone to OBEX mode.
Send the Connect instruction to receive the phone reply after determining parameters such as MAX Packet LENGTH. Finally connect to the folder-listing service for file operation. If IRMC synchronization is required, connect directly to the IRMC Sync Service after Connect, and the phone immediately enters the synchronization mode, all applications exit.
In the author's program, use the AT command to determine the current work of the phone, if the timeout, try to send and wait 1 second to exit from the abnormal OBEX state. Then, the AT is sent here, and then the file operation is performed, otherwise an error is triggered.
l Disconnected
The disconnected connection here refers to an exit from the OBEX mode to the AT state. In the AT instruction, three 0x2b continuously sends three 0x2b then wait for a second to exit the data mode to enter the regular AT mode.
l Set the path
Use the setPath operation setting path in the program. It should be noted that the process of two styles can be designed: one uses an absolute path, and another relative path is used.
For mobile phones, the scriptures have proven that the use of absolute paths are more convenient than using relative paths, and more accurate, but efficient, especially in the case of multi-layer directories. Since the phone does not return to the current path, the relative path is generally difficult to control, and only errors are extremely easier to control by program control. So it is recommended to use an absolute path.
If the absolute path is used, the path name will present / path1 / path2. First go back to the root directory, then the first level will arrive at the purpose. In the author's Obex class, you can see the BackToroot process. The role is to switch the current procedure path to the root directory to avoid confusion.
l acquistent catalog information
The file information to get a directory can be used to send a GET instruction. The GET instruction requires a TypeHeader, its value is X-OBEX / Folder-Listing
The server will then return an XML file to include information about the entire directory. For example, subdirectories, file names, size, and final modification time. The directory information will be obtained after the XML parsing is analyzed.
l Create a directory
When setPath's Flags bit1 is set to 1 and cannot find a directory, the server creates this directory and enters.
Note, use setPath again and set the FLAGS bit0 to 1 Return to the upper directory, otherwise it is easy to cause confusion.
l Upload download file
Using the PUT and Get commands to upload and download files. Note that all file operations are performed in the directory specified by SetPath.
When you upload using the PUT command, you need to provide NameHeader, BodyHeader, generally to provide LengthHeader, DateTimeHeader. Big file transmission needs to properly handle the bodyheader, cannot exceed the size of the Packet that the server can receive, otherwise an error will occur. It should be noted that if the current file exists, the PUT command does not overwrite the existing file but append, causing an error. You need to delete the same name file before transferring a file.
When you use the get command to implement, you only need to provide NameHeader. Specific example refer to the previous section.
l Delete files or empty directories
Using the PUT command, its namehead is specified as a file name or directory name and sets the bodyheader to an empty.
The non-empty directory cannot be deleted, and an error will be returned.
Siemens mobile phones also have functions such as moving, copying, etc., please refer to OBEX source code.