Skip to content

Commit

Permalink
Merge pull request #20 from bitcraze/krichardsson/cpx-version
Browse files Browse the repository at this point in the history
Added CPX version
  • Loading branch information
krichardsson committed Mar 21, 2023
2 parents 43a20c7 + 94cbca8 commit 5fa8c93
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions main/cpx.c
@@ -1,19 +1,25 @@
#include "cpx.h"
#include "freertos/FreeRTOS.h"

void cpxInitRoute(const CPXTarget_t source, const CPXTarget_t destination, const CPXFunction_t function, CPXRouting_t* route) {
route->source = source;
route->destination = destination;
route->function = function;
route->version = CPX_VERSION;
}

void cpxRouteToPacked(const CPXRouting_t* route, CPXRoutingPacked_t* packed) {
packed->source = route->source;
packed->destination = route->destination;
packed->function = route->function;
packed->version = route->version;
packed->lastPacket = route->lastPacket;
}

void cpxPackedToRoute(const CPXRoutingPacked_t* packed, CPXRouting_t* route) {
assert(CPX_VERSION == packed->version);

route->version = packed->version;
route->source = packed->source;
route->destination = packed->destination;
route->function = packed->function;
Expand Down
6 changes: 5 additions & 1 deletion main/cpx.h
Expand Up @@ -27,6 +27,8 @@
#include <stdint.h>
#include <stdbool.h>

#define CPX_VERSION (0)

// This enum is used to identify source and destination for CPX routing information
typedef enum {
CPX_T_STM32 = 1, // The STM in the Crazyflie
Expand All @@ -50,6 +52,7 @@ typedef struct {
CPXTarget_t source;
bool lastPacket;
CPXFunction_t function;
uint8_t version;
} CPXRouting_t;

// This struct contains routing information in a packed format. This struct
Expand All @@ -60,7 +63,8 @@ typedef struct {
CPXTarget_t source : 3;
bool lastPacket : 1;
bool reserved : 1;
CPXFunction_t function : 8;
CPXFunction_t function : 6;
uint8_t version : 2;
} __attribute__((packed)) CPXRoutingPacked_t;

#define CPX_ROUTING_PACKED_SIZE (sizeof(CPXRoutingPacked_t))
Expand Down
3 changes: 3 additions & 0 deletions main/router.c
Expand Up @@ -94,6 +94,9 @@ static void route(Receiver_t receive, CPXRoutablePacket_t* rxp, RouteContext_t*
while(1) {
receive(rxp);

// The version should already be checked when we receive packets. Do it again to make sure.
assert(CPX_VERSION == rxp->route.version);

const CPXTarget_t source = rxp->route.source;
const CPXTarget_t destination = rxp->route.destination;
const uint16_t cpxDataLength = rxp->dataLength;
Expand Down

0 comments on commit 5fa8c93

Please sign in to comment.