Skip to content

Commit

Permalink
Feature: Device firmware update (#12)
Browse files Browse the repository at this point in the history
Updated version
Updated copyright
Added clang-format
Formatted source files according to clang-format rules
Fixed Last will and testament initialized, but not enabled
Improved 'firmware_update_unpersist_firmware_version_t' Doxygen documentation
Corrected MQTT_PACKET_SIZE and PAYLOAD_SIZE

CMakeLists:
Added missing math link

JsonParser:
Inferring size of payload, and topic buffer via strlen is not reliable,
hence sizes of these are passed as argument to `deserialize_actuator_command`
  • Loading branch information
svranesevic committed Feb 5, 2018
1 parent a7bc5af commit 861529d
Show file tree
Hide file tree
Showing 61 changed files with 4,010 additions and 1,382 deletions.
23 changes: 23 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 4
UseTab: Never
BreakBeforeBraces: Linux
AlwaysBreakBeforeMultilineStrings: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
IndentCaseLabels: false
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AlignAfterOpenBracket: true
SpaceAfterCStyleCast: false
MaxEmptyLinesToKeep: 2
BreakBeforeBinaryOperators: NonAssignment
BreakStringLiterals: false
SortIncludes: true
ContinuationIndentWidth: 4
ColumnLimit: 120
PointerAlignment: Left
52 changes: 40 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2017 WolkAbout Technology s.r.o.
# Copyright 2018 WolkAbout Technology s.r.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,21 +15,42 @@
#

cmake_minimum_required(VERSION 2.8)
project(WolkAboutConnector)
project(WolkAboutConnector C)
set(CMAKE_C_STANDARD 99)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes \
-Wmissing-declarations -Wno-switch-enum -Wcast-align -Wno-bad-function-cast \
-Wnested-externs -Wunreachable-code -Wfloat-equal -Winline -Wundef \
-Wno-redundant-decls -Wold-style-definition -Wcast-qual -Wno-conversion -Wshadow \
-Wparentheses -Wsequence-point -Wno-declaration-after-statement -Wuninitialized \
-Wcast-align")

set(LIBRARY_NAME "WolkConnector_c")

include_directories(dependencies/MQTTPacket/src)
add_subdirectory(dependencies/MQTTPacket/src)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic \
-Wall \
-Wextra \
-Wstrict-prototypes \
-Wpointer-arith \
-Wmissing-declarations \
-Wno-switch-enum \
-Wno-bad-function-cast \
-Wnested-externs \
-Wunreachable-code \
-Wfloat-equal \
-Winline \
-Wundef \
-Wno-redundant-decls \
-Wold-style-definition \
-Wno-conversion \
-Wshadow \
-Wparentheses \
-Wsequence-point \
-Wno-declaration-after-statement \
-Wuninitialized \
-Wcast-align \
-Wshadow \
-Wcast-qual \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wconversion")

set(LIBRARY_NAME "WolkConnector_c")

include_directories("sources")
file(GLOB_RECURSE HEADER_FILES "sources/*.h")
file(GLOB_RECURSE SOURCE_FILES "sources/*.c")
Expand All @@ -38,7 +59,14 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/lib")

add_library(${LIBRARY_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${LIBRARY_NAME} paho-embed-mqtt3c)
target_link_libraries(${LIBRARY_NAME} paho-embed-mqtt3c m)

# Format code
add_custom_target(format
COMMAND "/usr/local/bin/clang-format" -i -sort-includes -style=file ${HEADER_FILES} ${SOURCE_FILES}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "[Formatting source code]"
VERBATIM)

# Example
add_subdirectory(examples)
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,29 @@ wolk_init_custom_persistence(&wolk,
persistence_is_empty_impl);
```
For more info on persistence mechanism see persistence.h and in_memory_persistence.h files
For more info on persistence mechanism see persistence.h and in_memory_persistence.h files.
**Firmware Update:**
WolkAbout C Connector provides mechanism for updating device firmware.
By default this feature is disabled.
See code snippet below on how to enable device firmware update.
```c
wolk_init_firmware_update(&wolk,
"1.0.0", // Current firmware version
128 * 1024 * 1024, // Maximum acceptable size of firmware file, in bytes
256, // Size of firmware file transfer chunk, in bytes
firmware_update_start, // Prepares device for receiving firmware file
firmware_chunk_write, // Writes received firmware file chunk
firmware_chunk_read, // Reads requested firmware file chunk
firmware_update_abort, // Aborts firmware update sequence
firmware_update_finalize, // Reboots device
firmware_update_persist_firmware_version, // Places given firmware version to persistent storage
firmware_update_unpersist_firmware_version, // Reads persisted firmware version from persistent storage
NULL, // Optional custom download handler that obtains file from URL
NULL) // Reports URL download state (in progress | done), and it's result (success | failure)
```

For more info on device firmware update mechanism see firmware_update.h file.
4 changes: 2 additions & 2 deletions dependencies/MQTTPacket/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ add_library(paho-embed-mqtt3c ${SOURCES})

target_compile_definitions(paho-embed-mqtt3c PRIVATE MQTT_SERVER MQTT_CLIENT)

add_library(MQTTPacketClient SHARED MQTTFormat MQTTPacket
add_library(MQTTPacketClient STATIC MQTTFormat MQTTPacket
MQTTSerializePublish MQTTDeserializePublish
MQTTConnectClient MQTTSubscribeClient MQTTUnsubscribeClient transport)
target_compile_definitions(MQTTPacketClient PRIVATE MQTT_CLIENT)

add_library(MQTTPacketServer SHARED MQTTFormat MQTTPacket
add_library(MQTTPacketServer STATIC MQTTFormat MQTTPacket
MQTTSerializePublish MQTTDeserializePublish
MQTTConnectServer MQTTSubscribeServer MQTTUnsubscribeServer)
target_compile_definitions(MQTTPacketServer PRIVATE MQTT_SERVER)
Loading

0 comments on commit 861529d

Please sign in to comment.