| | 1 | = Managing DBT Files with PACPUS = |
| | 2 | |
| | 3 | Pacpus framework offers a way to record data through DBT files. This is a binary format with timestamping functionalities. |
| | 4 | |
| | 5 | == Important notes == |
| | 6 | |
| | 7 | [=#point1 (1)] For this tutorial we will work with the trunk version of the pacpusframework repository. If you are using a specific tag or branch please change '''''trunk''''' by your specific '''''branch or tag path''''' for each link below. |
| | 8 | |
| | 9 | [=#point2 (2)] To deal with DBT files you need to link you application with !FileLib library. The source code can be found in [source:trunk/src/FileLib this] folder. |
| | 10 | |
| | 11 | == How to create a new DBT file == |
| | 12 | |
| | 13 | === Step 1: identify the type and the structure of the data === |
| | 14 | |
| | 15 | First you must identify the type of your data in this file [source:trunk/include/Pacpus/kernel/DbiteFileTypes.h DbiteFileTypes.h]. Remember note [#point1 (1)] and modify the path to fit with your installation of pacpusframework. If the type is already known by PACPUS, it is recommended to use it, else you need to create a new entry in this file. |
| | 16 | |
| | 17 | For example, if you need to add a support BMP images, you can change this code block: |
| | 18 | |
| | 19 | {{{ |
| | 20 | #!cpp |
| | 21 | enum BasicType |
| | 22 | { |
| | 23 | FILE_IMAGE = 0 |
| | 24 | , FILE_CAN |
| | 25 | , FILE_TEXT |
| | 26 | , FILE_IMAGE3D |
| | 27 | , FILE_DBT_UNKNOWN ///< Unknown file type |
| | 28 | , FILE_JPEG |
| | 29 | , STREAM8POSITION = 100 |
| | 30 | }; |
| | 31 | }}} |
| | 32 | |
| | 33 | in: |
| | 34 | |
| | 35 | {{{ |
| | 36 | #!cpp |
| | 37 | enum BasicType |
| | 38 | { |
| | 39 | FILE_IMAGE = 0 |
| | 40 | , FILE_CAN |
| | 41 | , FILE_TEXT |
| | 42 | , FILE_IMAGE3D |
| | 43 | , FILE_DBT_UNKNOWN ///< Unknown file type |
| | 44 | , FILE_JPEG |
| | 45 | , FILE_MYSTRUCT ///< New MYSTRUCT file format (remark: the number of the ID will be 6 here) |
| | 46 | , STREAM8POSITION = 100 |
| | 47 | }; |
| | 48 | }}} |
| | 49 | |
| | 50 | ''Warning, take care of using a free number in the file.'' |
| | 51 | |
| | 52 | After this, you need to create the new structure of your data. It is a just a header file containing the C structure of the data. It is recommended to use standard types like uint32_t, int8_t, ... This types are available via [source:trunk/include/Pacpus/kernel/cstdint.h cstdint.h] file. |
| | 53 | |
| | 54 | {{{ |
| | 55 | #!cpp |
| | 56 | struct MYSTRUCT { |
| | 57 | uint32_t data1; |
| | 58 | int16_t data2; |
| | 59 | uint8_t data3; |
| | 60 | }; |
| | 61 | }}} |
| | 62 | |
| | 63 | === Step 2: creation of DBT file === |
| | 64 | |
| | 65 | First we create an instance of pacpus::!DbiteFile. |
| | 66 | |
| | 67 | {{{ |
| | 68 | #!cpp |
| | 69 | pacpus::DbiteFile dbtFile_; //!< DBT file. |
| | 70 | }}} |
| | 71 | |
| | 72 | After we open the DBT file in writing mode with this code: |
| | 73 | |
| | 74 | {{{ |
| | 75 | #!cpp |
| | 76 | try { |
| | 77 | dbtFile_.open("my_struct_file.dbt", WriteMode, FILE_MYSTRUCT, sizeof(MYSTRUCT)); |
| | 78 | } catch (DbiteException & e) { |
| | 79 | cerr << "error opening dbt file: "<< kSickDbtFileName << ", " << e.what() << endl; |
| | 80 | return; |
| | 81 | } |
| | 82 | }}} |
| | 83 | |
| | 84 | The my_struct_file.dbt file will be created in current path of the application (often it is the folder where you launched the application PacpusSensor). |
| | 85 | |