. NET mobile Software development (VI) OBEX application--File Transfer section

Source: Internet
Author: User
Tags exit empty connect relative requires root directory
(vi) OBEX Applications-File Transfer section

In the mobile phone data transmission Basic OBEX application is divided into

L File Transfer

L IRMC Sync

File transfer can be subdivided into the following basic operations

• Initializing connections

L Disconnect

L Set the path

L Get directory information

L Create a directory

L Upload Download file

L Delete files or empty directories

In the author's software design Obex This class, which contains all the above basic operations. In addition, it also designed the function of renaming, obtaining disk space information, moving and copying files for the particularity of M55 's service end. Please refer to source code for details.

The details of each operation are described below.

• Initializing connections

The initialization connection includes a sequence of processes that allow the phone to enter the OBEX state and then send the Connect command. The detailed process refer to the following figure.

Atæat^sqwe=0æat^sqwe=3æconnectæ Connect to Folder-listing Service

Among them, at^sqwe=0 and at^sqwe=3 are the unique hidden at instructions of Siemens, not even in the official at instruction set. Its role is to initialize the mobile phone to OBEX mode.

Send Connect command after receiving the phone reply to determine max Packet length parameters. Finally, connect to the Folder-listing service for file operation. If you need IRMC sync, connect directly to the IRMC Sync service after connect, the phone immediately into the sync mode, all the applications exit.

In the author's program first use the AT command to determine the current mobile phone work, if time out, try to send +++ and wait 1 seconds for the phone to exit from the abnormal OBEX state. The at is then sent here, the file operation is successful, or an error is raised.

L Disconnect

The disconnect here refers to the exit from Obex mode to the at state. In the at instruction, send three consecutive 0x2b and wait more than one second to exit the data mode into regular at mode.

L Set the path

Program to set the path using the SetPath action. Note that you can design two styles: one using an absolute path and the other using a relative path.

For mobile phone, the author has proved that using absolute path is more convenient than using relative path, and more accurate, but less efficient, especially in the case of multi-layer directory. Because the mobile phone is not able to return the current path of the method, so the relative path is always difficult to control, only through program management, very prone to errors. Therefore, it is recommended that you use absolute paths.

If you use an absolute path, the path name renders \path1\path2 this form. First, go back to the root directory, and then reach the goal at one level. In the author's Obex class, you can see backtoroot this process. The effect is to switch the current program path to the root directory so as not to cause confusion.

L Get directory information

To obtain file information for a directory, you can send a get instruction. The get instruction requires a typeheader whose value is x-obex/folder-listing

The server then returns an XML file that contains information for the entire directory. such as subdirectory name, filename, size, last modified time. After parsing the XML, the directory information is obtained.

L Create a directory

When the SetPath flags Bit1 set to 1 and the directory cannot be found, the server creates the directory and enters it.

Note that it is confusing to use SetPath again and set the flags ' Bit0 to 1 to return to the upper directory.

L Upload Download file

Upload and download files can be implemented using the put and get commands. Note that all file operations are performed in the directory specified by SetPath.

When uploading using the put command, you need to provide at least nameheader,bodyheader, and generally provide lengthheader,datetimeheader. Large file transfer requires proper handling of bodyheader, not exceeding the maximum size of the packet that can be received by the server, or there will be an error.

Note that if the current file exists, the put command does not overwrite the existing file but append it, causing an error. You need to delete files with the same name before transferring files.

When you use the GET command to implement a download, you only need to provide nameheader. Specific examples refer to the previous section.

L Delete files or empty directories

Using the put command, its nameheader is specified as a filename or directory name and the Bodyheader is set to null.

A non-empty directory cannot be deleted and an error is returned.



Siemens mobile phones also have mobile, copy and other functions, the specific implementation of the method see Obex source code.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.