diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fb5a43e --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/README.md b/README.md index b10b51d..ae72f08 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ typedef union _Frame /** Channel ID */ uint8_t m_channel; - /** Channel ID */ + /** Channel DLC */ uint8_t m_dlc; /** Frame Checksum */ @@ -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 diff --git a/examples/README.md b/examples/README.md index 07a014d..563248c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 diff --git a/src/SerialMuxProtCommon.hpp b/src/SerialMuxProtCommon.hpp index f3b64fa..6baf3f4 100644 --- a/src/SerialMuxProtCommon.hpp +++ b/src/SerialMuxProtCommon.hpp @@ -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) @@ -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_ */ /** @} */ diff --git a/src/SerialMuxProtServer.hpp b/src/SerialMuxProtServer.hpp index ec2fa6d..8d5d41e 100644 --- a/src/SerialMuxProtServer.hpp +++ b/src/SerialMuxProtServer.hpp @@ -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)); } /** @@ -301,7 +303,9 @@ 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); @@ -309,7 +313,7 @@ class SerialMuxProtServer /* 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; @@ -367,7 +371,7 @@ class SerialMuxProtServer { if ((nullptr != payload) && (CONTROL_CHANNEL_PAYLOAD_LENGTH == payloadSize)) { - const Command* parsedPayload = reinterpret_cast(payload); + const ControlChannelPayload* parsedPayload = reinterpret_cast(payload); switch (parsedPayload->commandByte) { @@ -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; } @@ -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;