Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
FileInterface.h@13:2b51f5267c92, 2014-08-13 (annotated)
- Committer:
- dan_ackme
- Date:
- Wed Aug 13 03:14:30 2014 -0700
- Revision:
- 13:2b51f5267c92
- Parent:
- 11:ea484e1b7fc4
- Child:
- 16:7f1d6d359787
doc updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan_ackme | 0:ea85c4bb5e1f | 1 | /* |
dan_ackme | 0:ea85c4bb5e1f | 2 | * Copyright 2014, ACKme Networks |
dan_ackme | 0:ea85c4bb5e1f | 3 | * All Rights Reserved. |
dan_ackme | 0:ea85c4bb5e1f | 4 | * |
dan_ackme | 0:ea85c4bb5e1f | 5 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; |
dan_ackme | 0:ea85c4bb5e1f | 6 | * the contents of this file may not be disclosed to third parties, copied |
dan_ackme | 0:ea85c4bb5e1f | 7 | * or duplicated in any form, in whole or in part, without the prior |
dan_ackme | 0:ea85c4bb5e1f | 8 | * written permission of ACKme Networks. |
dan_ackme | 0:ea85c4bb5e1f | 9 | */ |
dan_ackme | 0:ea85c4bb5e1f | 10 | |
dan_ackme | 0:ea85c4bb5e1f | 11 | #pragma once |
dan_ackme | 0:ea85c4bb5e1f | 12 | |
dan_ackme | 0:ea85c4bb5e1f | 13 | #include "mbed.h" |
dan_ackme | 0:ea85c4bb5e1f | 14 | |
dan_ackme | 0:ea85c4bb5e1f | 15 | #include "WiconnectTypes.h" |
dan_ackme | 0:ea85c4bb5e1f | 16 | #include "types/FileList.h" |
dan_ackme | 0:ea85c4bb5e1f | 17 | |
dan_ackme | 0:ea85c4bb5e1f | 18 | |
dan_ackme | 11:ea484e1b7fc4 | 19 | /** |
dan_ackme | 11:ea484e1b7fc4 | 20 | * @ingroup api_file_macro |
dan_ackme | 11:ea484e1b7fc4 | 21 | * @brief The maximum filename size of a file on the WiConnect WiFi module filesystem |
dan_ackme | 11:ea484e1b7fc4 | 22 | */ |
dan_ackme | 0:ea85c4bb5e1f | 23 | #define FILE_NAME_MAX_SIZE 96 |
dan_ackme | 11:ea484e1b7fc4 | 24 | |
dan_ackme | 11:ea484e1b7fc4 | 25 | /** |
dan_ackme | 11:ea484e1b7fc4 | 26 | * @ingroup api_file_macro |
dan_ackme | 11:ea484e1b7fc4 | 27 | * @def FILE_MAKE_VERSION(major, minor, patch, rc) |
dan_ackme | 11:ea484e1b7fc4 | 28 | * @brief Combine <\a major>.<\a minor>.<\a patch>.<\a rc> and create version as a uint32_t |
dan_ackme | 11:ea484e1b7fc4 | 29 | */ |
dan_ackme | 0:ea85c4bb5e1f | 30 | #define FILE_MAKE_VERSION(major, minor, patch, rc) ((unsigned int)((major) << 27)|(unsigned int)((minor) << 21)|(unsigned int)((patch) << 8)|(unsigned int)((rc) << 0)) |
dan_ackme | 11:ea484e1b7fc4 | 31 | /** |
dan_ackme | 11:ea484e1b7fc4 | 32 | * @ingroup api_file_macro |
dan_ackme | 11:ea484e1b7fc4 | 33 | * @def FILE_VERSION_ARGS(version) |
dan_ackme | 11:ea484e1b7fc4 | 34 | * @brief Given a uint32_t \a version, return arguments for a variable argument function such as printf(). The format string is: %d.%d.%d.%d |
dan_ackme | 11:ea484e1b7fc4 | 35 | */ |
dan_ackme | 0:ea85c4bb5e1f | 36 | #define FILE_VERSION_ARGS(version) (unsigned int)((version >> 27) & 0x1F),(unsigned int)((version >> 21) & 0x3F),(unsigned int)((version >> 8) & 0x1FFF),(unsigned int)(version & 0xFF) |
dan_ackme | 0:ea85c4bb5e1f | 37 | |
dan_ackme | 0:ea85c4bb5e1f | 38 | |
dan_ackme | 0:ea85c4bb5e1f | 39 | namespace wiconnect { |
dan_ackme | 0:ea85c4bb5e1f | 40 | |
dan_ackme | 0:ea85c4bb5e1f | 41 | |
dan_ackme | 11:ea484e1b7fc4 | 42 | /** |
dan_ackme | 13:2b51f5267c92 | 43 | * @ingroup api_file_types |
dan_ackme | 11:ea484e1b7fc4 | 44 | * |
dan_ackme | 11:ea484e1b7fc4 | 45 | * @brief The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. |
dan_ackme | 11:ea484e1b7fc4 | 46 | * A client socket connects to a remote server. |
dan_ackme | 11:ea484e1b7fc4 | 47 | * |
dan_ackme | 13:2b51f5267c92 | 48 | * @note This class is an interface to the Wiconnect class. It should never be |
dan_ackme | 13:2b51f5267c92 | 49 | * independently instantiated or the parent of another class. |
dan_ackme | 11:ea484e1b7fc4 | 50 | */ |
dan_ackme | 0:ea85c4bb5e1f | 51 | class FileInterface |
dan_ackme | 0:ea85c4bb5e1f | 52 | { |
dan_ackme | 0:ea85c4bb5e1f | 53 | public: |
dan_ackme | 11:ea484e1b7fc4 | 54 | /** |
dan_ackme | 13:2b51f5267c92 | 55 | * @ingroup api_file_methods |
dan_ackme | 13:2b51f5267c92 | 56 | * |
dan_ackme | 13:2b51f5267c92 | 57 | * @brief Create a file on the Wiconnect WiFi module filesystem. |
dan_ackme | 13:2b51f5267c92 | 58 | * |
dan_ackme | 13:2b51f5267c92 | 59 | * This creates a file on the module's filesystem. The file's name and size are required. |
dan_ackme | 13:2b51f5267c92 | 60 | * Optionally specify the version, type and if it's essential (i.e. if it should never be automatically deleted, careful with |
dan_ackme | 13:2b51f5267c92 | 61 | * this optional as it could cause the the module to not be able to update its firmware). |
dan_ackme | 11:ea484e1b7fc4 | 62 | * |
dan_ackme | 13:2b51f5267c92 | 63 | * When this method is executed, the file is created on the module then the 'reader' parameter callback is |
dan_ackme | 13:2b51f5267c92 | 64 | * called until all the file data is read from the HOST and written to the module file. |
dan_ackme | 13:2b51f5267c92 | 65 | * |
dan_ackme | 13:2b51f5267c92 | 66 | * @param[in] reader Callback to be executed until all file data has been read from the HOST and written to the module |
dan_ackme | 13:2b51f5267c92 | 67 | * @param[in] user This is supplied to the @ref ReaderFunc callback. It is not used by the library. Leave NULL if not needed. |
dan_ackme | 13:2b51f5267c92 | 68 | * @param[in] name The name of the file to create |
dan_ackme | 13:2b51f5267c92 | 69 | * @param[in] size The size in bytes of the file |
dan_ackme | 13:2b51f5267c92 | 70 | * @param[in] version Optional, the version of the file, defaults to 1.0.0.0 |
dan_ackme | 13:2b51f5267c92 | 71 | * @param[in] type Optional, the file type, defaults to FILE_TYPE_MISC_FIX_LEN |
dan_ackme | 13:2b51f5267c92 | 72 | * @param[in] isEssential Optional, specify if the file should never be automatically deleted during a firmware upgrade |
dan_ackme | 13:2b51f5267c92 | 73 | * @param[in] checksum The CRC16 checksum of the file data. The module verifies the written data against this checksum |
dan_ackme | 13:2b51f5267c92 | 74 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 75 | */ |
dan_ackme | 0:ea85c4bb5e1f | 76 | WiconnectResult createFile(const ReaderFunc &reader, void *user, const char *name, uint32_t size, uint32_t version = 0, FileType type = FILE_TYPE_ANY, bool isEssential = false, int32_t checksum = -1); |
dan_ackme | 11:ea484e1b7fc4 | 77 | |
dan_ackme | 11:ea484e1b7fc4 | 78 | /** |
dan_ackme | 13:2b51f5267c92 | 79 | * @ingroup api_file_methods |
dan_ackme | 13:2b51f5267c92 | 80 | * |
dan_ackme | 13:2b51f5267c92 | 81 | * @brief Open a file on the Wiconnect WiFi module filesystem for reading. |
dan_ackme | 11:ea484e1b7fc4 | 82 | * |
dan_ackme | 13:2b51f5267c92 | 83 | * Once opened, the returned @ref File object may only be read. |
dan_ackme | 13:2b51f5267c92 | 84 | * |
dan_ackme | 13:2b51f5267c92 | 85 | * @param[out] file The @ref File object to read data from |
dan_ackme | 13:2b51f5267c92 | 86 | * @param[in] name The name of the file to open |
dan_ackme | 13:2b51f5267c92 | 87 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 88 | */ |
dan_ackme | 0:ea85c4bb5e1f | 89 | WiconnectResult openFile(File &file, const char *name); |
dan_ackme | 11:ea484e1b7fc4 | 90 | |
dan_ackme | 11:ea484e1b7fc4 | 91 | /** |
dan_ackme | 13:2b51f5267c92 | 92 | * @ingroup api_file_methods |
dan_ackme | 11:ea484e1b7fc4 | 93 | * |
dan_ackme | 13:2b51f5267c92 | 94 | * @brief Delete a file for the Wiconnect WiFi module filesystem. |
dan_ackme | 13:2b51f5267c92 | 95 | * |
dan_ackme | 13:2b51f5267c92 | 96 | * @param[in] name The name of the file to delete |
dan_ackme | 13:2b51f5267c92 | 97 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 98 | */ |
dan_ackme | 0:ea85c4bb5e1f | 99 | WiconnectResult deleteFile(const char *name); |
dan_ackme | 11:ea484e1b7fc4 | 100 | |
dan_ackme | 11:ea484e1b7fc4 | 101 | /** |
dan_ackme | 13:2b51f5267c92 | 102 | * @ingroup api_file_methods |
dan_ackme | 11:ea484e1b7fc4 | 103 | * |
dan_ackme | 13:2b51f5267c92 | 104 | * @brief Delete a file for the Wiconnect WiFi module filesystem. |
dan_ackme | 13:2b51f5267c92 | 105 | * |
dan_ackme | 13:2b51f5267c92 | 106 | * @param[in] file The @ref File object of the file to delete |
dan_ackme | 13:2b51f5267c92 | 107 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 108 | */ |
dan_ackme | 0:ea85c4bb5e1f | 109 | WiconnectResult deleteFile(const File &file); |
dan_ackme | 11:ea484e1b7fc4 | 110 | |
dan_ackme | 11:ea484e1b7fc4 | 111 | /** |
dan_ackme | 13:2b51f5267c92 | 112 | * @ingroup api_file_methods |
dan_ackme | 13:2b51f5267c92 | 113 | * |
dan_ackme | 13:2b51f5267c92 | 114 | * @brief List the files on the Wiconnect WiFi module filesystem. |
dan_ackme | 11:ea484e1b7fc4 | 115 | * |
dan_ackme | 13:2b51f5267c92 | 116 | * This lists all the files on the filesystem. |
dan_ackme | 13:2b51f5267c92 | 117 | * Optionally filter by one or more parameters: |
dan_ackme | 13:2b51f5267c92 | 118 | * * name - list files only with given name. If the name started with the wildcard character '*', then |
dan_ackme | 13:2b51f5267c92 | 119 | * only the characters after it are used for filter. |
dan_ackme | 13:2b51f5267c92 | 120 | * Example: |
dan_ackme | 13:2b51f5267c92 | 121 | * @code |
dan_ackme | 13:2b51f5267c92 | 122 | * wiconnect.listFiles(fileList, "*.txt"); // only list files with '.txt' extension |
dan_ackme | 13:2b51f5267c92 | 123 | * @endcode |
dan_ackme | 13:2b51f5267c92 | 124 | * * type - only list files with given type |
dan_ackme | 13:2b51f5267c92 | 125 | * * version - only list file with given version |
dan_ackme | 13:2b51f5267c92 | 126 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 127 | */ |
dan_ackme | 0:ea85c4bb5e1f | 128 | WiconnectResult listFiles(FileList &list, const char *name = NULL, FileType type = FILE_TYPE_ANY, uint32_t version = 0); |
dan_ackme | 0:ea85c4bb5e1f | 129 | |
dan_ackme | 11:ea484e1b7fc4 | 130 | |
dan_ackme | 11:ea484e1b7fc4 | 131 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 132 | |
dan_ackme | 11:ea484e1b7fc4 | 133 | |
dan_ackme | 11:ea484e1b7fc4 | 134 | /** |
dan_ackme | 11:ea484e1b7fc4 | 135 | * @ingroup conversion_util |
dan_ackme | 11:ea484e1b7fc4 | 136 | * |
dan_ackme | 11:ea484e1b7fc4 | 137 | * @brief Convert file version uint32 to string. |
dan_ackme | 11:ea484e1b7fc4 | 138 | */ |
dan_ackme | 0:ea85c4bb5e1f | 139 | static const char* fileVersionIntToStr(uint32_t version, bool verbose = true, char *buffer = NULL); |
dan_ackme | 11:ea484e1b7fc4 | 140 | |
dan_ackme | 11:ea484e1b7fc4 | 141 | /** |
dan_ackme | 11:ea484e1b7fc4 | 142 | * @ingroup conversion_util |
dan_ackme | 11:ea484e1b7fc4 | 143 | * |
dan_ackme | 11:ea484e1b7fc4 | 144 | * @brief Convert string to file version uint32. |
dan_ackme | 11:ea484e1b7fc4 | 145 | */ |
dan_ackme | 0:ea85c4bb5e1f | 146 | static bool fileVersionStrToInt(const char *versionStr, uint32_t *versionIntPtr); |
dan_ackme | 11:ea484e1b7fc4 | 147 | |
dan_ackme | 11:ea484e1b7fc4 | 148 | /** |
dan_ackme | 11:ea484e1b7fc4 | 149 | * @ingroup conversion_util |
dan_ackme | 11:ea484e1b7fc4 | 150 | * |
dan_ackme | 11:ea484e1b7fc4 | 151 | * Convert @ref FileType to string. |
dan_ackme | 11:ea484e1b7fc4 | 152 | */ |
dan_ackme | 0:ea85c4bb5e1f | 153 | static const char* fileTypeToStr(FileType type); |
dan_ackme | 11:ea484e1b7fc4 | 154 | |
dan_ackme | 11:ea484e1b7fc4 | 155 | /** |
dan_ackme | 11:ea484e1b7fc4 | 156 | * @ingroup conversion_util |
dan_ackme | 11:ea484e1b7fc4 | 157 | * |
dan_ackme | 11:ea484e1b7fc4 | 158 | * @brief Convert @ref FileFlags to string. |
dan_ackme | 11:ea484e1b7fc4 | 159 | */ |
dan_ackme | 0:ea85c4bb5e1f | 160 | static const char* fileFlagsToStr(FileFlags flags, char *buffer = NULL); |
dan_ackme | 0:ea85c4bb5e1f | 161 | |
dan_ackme | 0:ea85c4bb5e1f | 162 | protected: |
dan_ackme | 1:6ec9998427ad | 163 | FileInterface(Wiconnect *wiconnect); |
dan_ackme | 1:6ec9998427ad | 164 | |
dan_ackme | 0:ea85c4bb5e1f | 165 | WiconnectResult processFileList(char *responseStr, FileList &list, const char *name, FileType type, uint32_t version); |
dan_ackme | 0:ea85c4bb5e1f | 166 | private: |
dan_ackme | 0:ea85c4bb5e1f | 167 | Wiconnect *wiconnect; |
dan_ackme | 0:ea85c4bb5e1f | 168 | }; |
dan_ackme | 0:ea85c4bb5e1f | 169 | |
dan_ackme | 0:ea85c4bb5e1f | 170 | } |