Skip to content

Commit

Permalink
Merge pull request MightyPork#6 from marcelnabeck/demo-build
Browse files Browse the repository at this point in the history
Demo build
  • Loading branch information
marcelnabeck authored Aug 26, 2022
2 parents 0f63d2f + ac9d39c commit 9f936ab
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 212 deletions.
33 changes: 21 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
cmake_minimum_required(VERSION 3.7)
project(tf)
project(TinyFramePlusPlus)

# This is a dummy CMakeLists file for CLion, which still doesn't understand Makefiles.
# Do not try to build the library using this file, it's here only for static analysis.

if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()

set(CMAKE_CXX_STANDARD 14)

set(SOURCES_TINYFRAME
Expand All @@ -13,21 +19,24 @@ set(SOURCES_TINYFRAME
TinyFrame_Types.hpp
)

set(SOURCES_DEMO
set(SOURCES_UTILS
demo/utils.cpp
demo/utils.hpp
)

add_executable(Tests ${SOURCES_TINYFRAME} tests/TF_SimpleTest.cpp)

add_executable(demo.simple ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/simple/test.cpp)
add_executable(demo.simple_custom_cksum ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/simple_custom_cksum/test.cpp)
add_executable(demo.simple_long_payload ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/simple_long_payload/test.cpp)
add_executable(demo.simple_multipart ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/simple_multipart/test.cpp)
add_executable(demo.socket_demo.master ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/socket_demo/master.cpp)
add_executable(demo.socket_demo.slave ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/socket_demo/slave.cpp)

add_executable(Demo ${SOURCES_TINYFRAME} ${SOURCES_DEMO} demo/demo.hpp demo/demo.cpp)
set(SOURCES_DEMO
demo/demo.cpp
demo/demo.hpp
)

add_executable(Tests ${SOURCES_TINYFRAME} tests/TF_SimpleTest.cpp)

add_executable(demo.simple ${SOURCES_TINYFRAME} ${SOURCES_UTILS} demo/simple/test.cpp)
add_executable(demo.simple_custom_cksum ${SOURCES_TINYFRAME} ${SOURCES_UTILS} demo/simple_custom_cksum/test.cpp)
add_executable(demo.simple_long_payload ${SOURCES_TINYFRAME} ${SOURCES_UTILS} demo/simple_long_payload/test.cpp)
add_executable(demo.simple_multipart ${SOURCES_TINYFRAME} ${SOURCES_UTILS} demo/simple_multipart/test.cpp)

if (UNIX)
add_executable(demo.socket_demo.master ${SOURCES_TINYFRAME} ${SOURCES_UTILS} ${SOURCES_DEMO} demo/socket_demo/master.cpp)
add_executable(demo.socket_demo.slave ${SOURCES_TINYFRAME} ${SOURCES_UTILS} ${SOURCES_DEMO} demo/socket_demo/slave.cpp)
endif (UNIX)
27 changes: 22 additions & 5 deletions TinyFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

//---------------------------------------------------------------------------
#include <string>
#include <new>
//---------------------------------------------------------------------------

#include "TinyFrame_Types.hpp"
Expand Down Expand Up @@ -84,7 +85,7 @@ class TinyFrame{

// ------------------------ TO BE IMPLEMENTED BY USER ------------------------

const struct RequiredCallbacks{
struct RequiredCallbacks{
/**
* 'Write bytes' function that sends data to UART
*
Expand All @@ -94,17 +95,17 @@ class TinyFrame{

void (*Error)(std::string message);

}tfCallbacks_Required; // variable definition
}; // variable definition

const struct OptionalCallbacks{
struct OptionalCallbacks{

/** Claim the TX interface before composing and sending a frame */
bool (*ClaimTx)();

/** Free the TX interface after composing and sending a frame */
void (*ReleaseTx)();

}tfCallbacks_Optional; // variable definition
}; // variable definition

struct IdListener_ {
ID id;
Expand All @@ -125,6 +126,8 @@ class TinyFrame{
Listener fn;
};

const RequiredCallbacks tfCallbacks_Required;
const OptionalCallbacks tfCallbacks_Optional;
const TinyFrameConfig_t tfConfig;

struct{
Expand Down Expand Up @@ -185,7 +188,7 @@ class TinyFrame{
*/
static inline void ClearMsg(Msg *msg)
{
msg = {};
*msg = {};
}

// ---------------------------------- API CALLS --------------------------------------
Expand Down Expand Up @@ -1317,6 +1320,20 @@ void _FN TinyFrame<TEMPLATE_PARMS>::Tick()
}
}

/*
* Allocate object during runtime within buffer using placement new
* @param buf buffer where the object will be placed
* @param cb TinyFrame required callbacks to be registered
* @param config TinyFrame configuration to be used for this object
* @param peer configuration which peer this object will represent
*/
template<TEMPLATE_ARGS>
static TinyFrame<TEMPLATE_PARMS> tinyFrameCreate_Static(char buf[sizeof(TinyFrame<TEMPLATE_PARMS>)], const struct TinyFrame<TEMPLATE_PARMS>::RequiredCallbacks& cb, const TinyFrameConfig_t& config, const Peer peer = Peer::SLAVE){
return new(buf) TinyFrame<TEMPLATE_PARMS>(cb, config, peer);
}

} // TinyFrame_n

using TinyFrameDefault=TinyFrame_n::TinyFrame<>;

#endif // TinyFrameH
5 changes: 4 additions & 1 deletion TinyFrame_CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ CKSUM<CKSUM_t::NONE> CksumStart<CKSUM_t::NONE>(void)

template<>
CKSUM<CKSUM_t::NONE> CksumAdd<CKSUM_t::NONE>(CKSUM<CKSUM_t::NONE> cksum, uint8_t byte)
{ return cksum; }
{
(void) byte;
return cksum;
}

template<>
CKSUM<CKSUM_t::NONE> CksumEnd<CKSUM_t::NONE>(CKSUM<CKSUM_t::NONE> cksum)
Expand Down
Loading

0 comments on commit 9f936ab

Please sign in to comment.