Skip to content

Commit

Permalink
Merge pull request #8 from gabryelreyes/dev
Browse files Browse the repository at this point in the history
Fixed compatibility issues with AVR compiler.
  • Loading branch information
gabryelreyes authored Nov 22, 2023
2 parents 5664f72 + 25e7b2d commit 499b5fe
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 24 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Relase Script

# Controls when the action will run.
on:
release:
# A release, pre-release, or draft of a release is published.
types: [published]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# The introduction just shows some useful informations.
intro:
# The type of runner that the job will run on.
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job.
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "The name of the branch is ${{ github.ref }} and the repository is ${{ github.repository }}."

publish:
# The type of runner that the job will run on.
runs-on: ubuntu-latest
# Intro must run first
needs: intro
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Deploy Package to Registry
env:
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
run: |
TAG=$(git describe --exact-match --tags)
curl -LO $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/$TAG/SerialMuxProt-$TAG.zip
pio package publish SerialMuxProt-$TAG.zip --non-interactive
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef union _Frame
/** Channel ID */
uint8_t m_channel;

/** Channel ID */
/** Channel DLC */
uint8_t m_dlc;

/** Frame Checksum */
Expand Down Expand Up @@ -100,15 +100,13 @@ typedef union _Frame
- The Application can publish or subscribe to any of these channels using the channel's name.
- Client suscribes to a channel using [Channel 0](#control-channel-channel-0).

#### DLC Field
#### Data Length Code (DLC) Field

- Contains the size of the payload contained by the frame.

#### Checksum Field

- Simple Checksum.
- Applied to previous fields.
- checksum = sum(Channel + Data Bytes) % UINT8_MAX
- checksum = sum(Channel + DLC + Data Bytes) % UINT8_MAX

### Payload Field

Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ The following example is written for testing the SerialMuxProt with two microcon
## Installation

- Install the library, depending on your IDE.
- Compile `main.cpp` from SideA and flash it onto the first board.
- Compile `main.cpp` from SideB and flash it onto the second board.
- Compile `main.cpp` from ServerA and flash it onto the first board.
- Compile `main.cpp` from ServerB and flash it onto the second board.
- Connect the UART peripherals of both boards with each other:
- Rx from Board 1 with Tx from Board 2
- Tx from Board 1 with Rx from Board 2
Expand Down
16 changes: 8 additions & 8 deletions src/SerialMuxProtCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SOFTWARE.
#define CONTROL_CHANNEL_NUMBER (0U)

/** DLC of Control Channel Payload. */
#define CONTROL_CHANNEL_PAYLOAD_LENGTH (sizeof(Command))
#define CONTROL_CHANNEL_PAYLOAD_LENGTH (sizeof(ControlChannelPayload))

/** Period of Heartbeat when Synced. */
#define HEATBEAT_PERIOD_SYNCED (5000U)
Expand Down Expand Up @@ -168,15 +168,15 @@ enum COMMANDS : uint8_t
};

/**
* Command Channel Payload Structure.
* Control Channel Payload Structure.
*/
typedef struct _Command
typedef struct _ControlChannelPayload
{
uint8_t commandByte; /**< Command Byte */
uint32_t timestamp; /**< Timestamp */
uint8_t channelNumber; /**< Channel Number */
char channelName[CHANNEL_NAME_MAX_LEN]; /**< Channel Name */
} __attribute__((packed)) Command; /**< Command */
uint8_t commandByte = 0U; /**< Command Byte */
uint32_t timestamp = 0U; /**< Timestamp */
uint8_t channelNumber = 0U; /**< Channel Number */
char channelName[CHANNEL_NAME_MAX_LEN] = {0U}; /**< Channel Name */
} __attribute__((packed)) ControlChannelPayload; /**< ControlChannelPayload */

#endif /* SERIALMUXPROT_COMMON_H_ */
/** @} */
25 changes: 16 additions & 9 deletions src/SerialMuxProtServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ class SerialMuxProtServer
*/
void cmdSYNC(const uint32_t rcvTimestamp)
{
Command output = {.commandByte = COMMANDS::SYNC_RSP, .timestamp = rcvTimestamp};
ControlChannelPayload output;
output.commandByte = COMMANDS::SYNC_RSP;
output.timestamp = rcvTimestamp;

/* Ignore return as SYNC_RSP can fail */
(void)send(CONTROL_CHANNEL_NUMBER, &output, sizeof(Command));
(void)send(CONTROL_CHANNEL_NUMBER, &output, sizeof(ControlChannelPayload));
}

/**
Expand Down Expand Up @@ -301,15 +303,17 @@ class SerialMuxProtServer
*/
void cmdSCRB(const char* channelName)
{
Command output = {.commandByte = COMMANDS::SCRB_RSP, .channelNumber = getTxChannelNumber(channelName)};
ControlChannelPayload output;
output.commandByte = COMMANDS::SCRB_RSP;
output.channelNumber = getTxChannelNumber(channelName);

/* Using strnlen in case the name is not null-terminated. */
uint8_t nameLength = strnlen(channelName, CHANNEL_NAME_MAX_LEN);

/* Name is always sent back. */
memcpy(output.channelName, channelName, nameLength);

if (false == send(CONTROL_CHANNEL_NUMBER, &output, sizeof(Command)))
if (false == send(CONTROL_CHANNEL_NUMBER, &output, sizeof(ControlChannelPayload)))
{
/* Fall out of sync if failed to send. */
m_isSynced = false;
Expand Down Expand Up @@ -367,7 +371,7 @@ class SerialMuxProtServer
{
if ((nullptr != payload) && (CONTROL_CHANNEL_PAYLOAD_LENGTH == payloadSize))
{
const Command* parsedPayload = reinterpret_cast<const Command*>(payload);
const ControlChannelPayload* parsedPayload = reinterpret_cast<const ControlChannelPayload*>(payload);

switch (parsedPayload->commandByte)
{
Expand Down Expand Up @@ -514,9 +518,11 @@ class SerialMuxProtServer
}

/* Send SYNC Command. */
Command payload = {.commandByte = COMMANDS::SYNC, .timestamp = currentTimestamp};
ControlChannelPayload payload;
payload.commandByte = COMMANDS::SYNC;
payload.timestamp = currentTimestamp;

if (true == send(CONTROL_CHANNEL_NUMBER, &payload, sizeof(Command)))
if (true == send(CONTROL_CHANNEL_NUMBER, &payload, sizeof(ControlChannelPayload)))
{
m_lastSyncCommand = currentTimestamp;
}
Expand All @@ -537,10 +543,11 @@ class SerialMuxProtServer
/* Suscribe to channel. */
/* Using strnlen in case the name is not null-terminated. */
uint8_t nameLength = strnlen(m_pendingSuscribeChannels[idx].m_name, CHANNEL_NAME_MAX_LEN);
Command output = {.commandByte = COMMANDS::SCRB};
ControlChannelPayload output;
output.commandByte = COMMANDS::SCRB;
memcpy(output.channelName, m_pendingSuscribeChannels[idx].m_name, nameLength);

if (false == send(CONTROL_CHANNEL_NUMBER, &output, sizeof(Command)))
if (false == send(CONTROL_CHANNEL_NUMBER, &output, sizeof(ControlChannelPayload)))
{
/* Out-of-Sync on failed send. */
m_isSynced = false;
Expand Down

0 comments on commit 499b5fe

Please sign in to comment.