Skip to content

Commit

Permalink
Merge pull request MightyPork#16 from marcelnabeck/15-correct-handlin…
Browse files Browse the repository at this point in the history
…g-of-undefined-claimtx-and-releasetx

15 correct handling of undefined claimtx and releasetx
  • Loading branch information
marcelnabeck authored Aug 31, 2022
2 parents 8cf9c94 + 53cea10 commit 36b1f05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 9 additions & 5 deletions TinyFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ size_t _FN TinyFrame<TEMPLATE_PARMS>::ComposeTail(uint8_t *outbuff, CKSUM<CKSUM_
template<TEMPLATE_ARGS>
bool _FN TinyFrame<TEMPLATE_PARMS>::SendFrame_Begin(Msg *msg, Listener listener, Listener_Timeout ftimeout, TICKS timeout)
{
if(this->tfCallbacks_Optional.ClaimTx != nullptr){
if (this->internal.tfCallbacks_Optional_registered) {
TRY(this->tfCallbacks_Optional.ClaimTx());
}else{
TRY(this->ClaimTx_Internal());
Expand All @@ -1107,13 +1107,13 @@ bool _FN TinyFrame<TEMPLATE_PARMS>::SendFrame_Begin(Msg *msg, Listener listener,

if (listener) {
if(!this->AddIdListener(msg, listener, ftimeout, timeout)) {
if(this->tfCallbacks_Optional.ReleaseTx != nullptr){
if (this->internal.tfCallbacks_Optional_registered) {
TRY(this->tfCallbacks_Optional.ClaimTx());
}else{
TRY(this->ClaimTx_Internal());
}
return false;
}
return false;
}
}

CKSUM_RESET(this->internal.tx_cksum);
Expand Down Expand Up @@ -1170,7 +1170,11 @@ void _FN TinyFrame<TEMPLATE_PARMS>::SendFrame_End()
}

this->tfCallbacks_Required.WriteImpl((const uint8_t *) this->internal.sendbuf, this->internal.tx_pos);
this->tfCallbacks_Optional.ReleaseTx();
if (this->internal.tfCallbacks_Optional_registered) {
this->tfCallbacks_Optional.ReleaseTx();
} else {
this->ReleaseTx_Internal();
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions demo/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ void dumpFrame(const uint8_t *buff, size_t len)
void dumpFrameInfo(Msg *msg)
{
printf("\033[33mFrame info\n"
" type: %0zXh\n"
" type: 0x%Xh\n"
" data: \"%.*s\"\n"
" len: %zu\n"
" id: %zXh\033[0m\n\n",
(size_t)msg->type, (int)msg->len, msg->data, (size_t)msg->len, (size_t)msg->frame_id);
" len: 0x%X\n"
" id: 0x%Xh\033[0m\n\n",
(int)msg->type, (int)msg->len, msg->data, (int)msg->len, (int)msg->frame_id);
}
} // TinyFrame_n
3 changes: 2 additions & 1 deletion tests/TF_SimpleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../TinyFrame_CRC.hpp"

#include <iostream>
#include <cstring>
#include <cassert>

using TinyFrame_CRC16 = TinyFrame_n::TinyFrame<TinyFrame_n::CKSUM_t::CRC16>;
Expand Down Expand Up @@ -170,7 +171,7 @@ TinyFrame_CRC16 tf_2(callbacks_2, TinyFrame_n::Peer::SLAVE);

int main(){

printf("size tf_1: %llu\n\n", sizeof(tf_1));
printf("size tf_1: 0x%X\n\n", (int)sizeof(tf_1));

uint8_t messageData[] = "Hello TinyFrame!";

Expand Down

0 comments on commit 36b1f05

Please sign in to comment.