Skip to content

Commit 327157b

Browse files
committed
Add block size default
Block size for file transfer should be configurable from 256 bytes to 128 KB. Issue: #24
1 parent 0875dd6 commit 327157b

9 files changed

+106
-20
lines changed

.github/memory_statistics_config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"source/include",
1414
"coreJSON/source/include",
1515
"tinycbor/src"
16+
],
17+
"compiler_flags": [
18+
"MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG"
1619
]
17-
}
20+
}

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ In AWS IoT, a **stream** is a publicly addressable resource that is an abstracti
44

55
More information about streams and MQTT based file delivery can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/mqtt-based-file-delivery.html)
66

7+
## MQTT File Streams Config File
8+
9+
The MQTT file streams library exposes build configuration macros that are required for
10+
building the library. A list of all the configurations and their default values
11+
are defined in
12+
[MQTTFileDownloader_defaults.h](source/include/MQTTFileDownloader_defaults.h). To
13+
provide custom values for the configuration macros, a custom config file named
14+
`MQTTFileDownloader_config.h` can be provided by the application to the library.
15+
16+
By default, a `MQTTFileDownloader_config.h` custom config is required to build the
17+
library. To disable this requirement and build the library with default
18+
configuration values, provide `MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG` as a compile time
19+
preprocessor macro.
20+
21+
**Thus, the MQTT library can be built by either**:
22+
23+
- Defining a `MQTTFileDownloader_config.h` file in the application, and adding it to the
24+
include directories list of the library
25+
**OR**
26+
- Defining the `MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG` preprocessor macro for the
27+
library build.
28+
729
### MQTT File Streams library workflow
830

931
![alt text](./docs/doxygen/images/MqttStreams_flowChart.jpg)

source/MQTTFileDownloader.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string.h>
2323

2424
#include "MQTTFileDownloader.h"
25+
#include "MQTTFileDownloader_defaults.h"
2526
#include "MQTTFileDownloader_base64.h"
2627
#include "MQTTFileDownloader_cbor.h"
2728
#include "core_json.h"

source/include/MQTTFileDownloader.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,36 @@
2525
* These first few are topic extensions to the dynamic base topic that includes
2626
* the Thing name.
2727
*/
28-
#define MQTT_API_THINGS "$aws/things/" /*!< Topic prefix for thing APIs. */
29-
#define MQTT_API_STREAMS "/streams/" /*!< Stream API identifier. */
30-
#define MQTT_API_DATA_CBOR "/data/cbor" /*!< Stream API suffix. */
31-
#define MQTT_API_GET_CBOR "/get/cbor" /*!< Stream API suffix. */
32-
#define MQTT_API_DATA_JSON "/data/json" /*!< JSON DATA Stream API suffix. */
33-
#define MQTT_API_GET_JSON "/get/json" /*!< JSON GET Stream API suffix. */
28+
#define MQTT_API_THINGS "$aws/things/" /*!< Topic prefix for thing APIs. */
29+
#define MQTT_API_STREAMS "/streams/" /*!< Stream API identifier. */
30+
#define MQTT_API_DATA_CBOR "/data/cbor" /*!< Stream API suffix. */
31+
#define MQTT_API_GET_CBOR "/get/cbor" /*!< Stream API suffix. */
32+
#define MQTT_API_DATA_JSON "/data/json" /*!< JSON DATA Stream API suffix. */
33+
#define MQTT_API_GET_JSON "/get/json" /*!< JSON GET Stream API suffix. */
3434

3535
/**
3636
* @ingroup mqtt_file_downloader_const_types
3737
* Maximum stream name length.
3838
*/
39-
#define STREAM_NAME_MAX_LEN 44U
39+
#define STREAM_NAME_MAX_LEN 44U
4040

4141
/**
4242
* @ingroup mqtt_file_downloader_const_types
4343
* Length of NULL character. Used in calculating lengths of MQTT topics.
4444
*/
45-
#define NULL_CHAR_LEN 1U
45+
#define NULL_CHAR_LEN 1U
4646

4747
/**
4848
* @ingroup mqtt_file_downloader_const_types
4949
* Maximum thing name length.
5050
*/
51-
#define MAX_THINGNAME_LEN 128U
51+
#define MAX_THINGNAME_LEN 128U
5252

5353
/**
5454
* @ingroup mqtt_file_downloader_const_types
5555
* Stream Request Buffer Size
5656
*/
57-
#define GET_STREAM_REQUEST_BUFFER_SIZE 256U
58-
59-
/**
60-
* @ingroup mqtt_file_downloader_const_types
61-
* @brief Configure the Maximum size of the data payload.
62-
*/
63-
#define mqttFileDownloader_CONFIG_BLOCK_SIZE 256U
57+
#define GET_STREAM_REQUEST_BUFFER_SIZE 256U
6458

6559
/**
6660
* @brief Macro to calculate string length.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* AWS IoT Core MQTT File Streams Embedded C v1.1.0
3+
* Copyright (C) 2023 Amazon.com, Inc. and its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Licensed under the MIT License. See the LICENSE accompanying this file
7+
* for the specific language governing permissions and limitations under
8+
* the License.
9+
*/
10+
11+
/**
12+
* @file MQTTFileDownloader_defaults.h
13+
* @brief Default values for various MQTT stream macros.
14+
*/
15+
16+
#ifndef MQTT_FILE_DOWNLOADER_DEFAULT_H
17+
#define MQTT_FILE_DOWNLOADER_DEFAULT_H
18+
19+
#include <stdint.h>
20+
21+
/* MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG allows building the MQTT
22+
* streams library without a custom config. If a custom config is
23+
* provided, the MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG macro should not
24+
* be defined. */
25+
#ifndef MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG
26+
/* Include custom config file before other, non-standard headers. */
27+
#include "MQTTFileDownloader_config.h"
28+
#endif
29+
30+
/**
31+
* @ingroup mqtt_file_downloader_const_types
32+
* @brief Configure the Maximum size of the data payload. The
33+
* smallest value is 256 bytes, maximum is 128KB. For more see
34+
* https://docs.aws.amazon.com/general/latest/gr/iot-core.html
35+
*/
36+
#ifndef mqttFileDownloader_CONFIG_BLOCK_SIZE
37+
#define mqttFileDownloader_CONFIG_BLOCK_SIZE 4096U
38+
#endif
39+
40+
#endif /* #ifndef MQTT_FILE_DOWNLOADER_DEFAULT_H */

test/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ if( COV_ANALYSIS )
8080
# JOBS public include path.
8181
target_include_directories( coverity_analysis PUBLIC ${MQTT_FILE_DOWNLOADER_INCLUDES} )
8282

83+
# Build MQTT streams library target without custom config dependency.
84+
target_compile_definitions( coverity_analysis PUBLIC MQTT_STREAMS_DO_NOT_USE_CUSTOM_CONFIG=1 )
85+
8386
# Build HTTP library target without logging
8487
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
8588

@@ -132,8 +135,7 @@ if( UNITTEST )
132135
# Include build configuration for unit tests.
133136
add_subdirectory(unit-test)
134137

135-
# ==================================== Coverage Analysis configuration
136-
# ========================================
138+
# ================= Coverage Analysis configuration =================
137139

138140
# Add a target for running coverage on tests.
139141
add_custom_target(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* AWS IoT Core MQTT File Streams Embedded C v1.1.0
3+
* Copyright (C) 2023 Amazon.com, Inc. and its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Licensed under the MIT License. See the LICENSE accompanying this file
7+
* for the specific language governing permissions and limitations under
8+
* the License.
9+
*/
10+
11+
/**
12+
* @file MQTTFileDownloader_config.h
13+
* @brief Testing values for various MQTT stream macros.
14+
*/
15+
16+
#ifndef MQTT_FILE_DOWNLOADER_CONFIG_H
17+
#define MQTT_FILE_DOWNLOADER_CONFIG_H
18+
19+
#include <stdint.h>
20+
21+
#define mqttFileDownloader_CONFIG_BLOCK_SIZE 256U
22+
23+
#endif /* #ifndef MQTT_FILE_DOWNLOADER_CONFIG_H */

test/unit-test/downloader_base64_utest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "unity.h"
1616
#include "MQTTFileDownloader.h"
17-
17+
#include "MQTTFileDownloader_defaults.h"
1818
#include "MQTTFileDownloader_base64.h"
1919

2020
#define GET_STREAM_REQUEST_BUFFER_SIZE 256U

test/unit-test/downloader_utest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mock_MQTTFileDownloader_cbor.h"
1818

1919
#include "MQTTFileDownloader.h"
20+
#include "MQTTFileDownloader_defaults.h"
2021

2122
#define GET_STREAM_REQUEST_BUFFER_SIZE 256U
2223

0 commit comments

Comments
 (0)