Skip to content

Commit

Permalink
Fixed API build
Browse files Browse the repository at this point in the history
  • Loading branch information
IliTheButterfly committed Apr 11, 2024
1 parent f5279a7 commit 8a8f4a7
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 51 deletions.
39 changes: 30 additions & 9 deletions src/rove_control_board/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include <capra_comm.h>

// --- ENUMS ---
// --- STRUCTS ---
struct Void
{
euint8_t pad0;
Expand All @@ -19,16 +21,31 @@ static_assert(sizeof(Vector2D) == 8);

struct State
{
euint8_t state;
eboolean_t state;
};
static_assert(sizeof(State) == 1);

struct Status
{
euint32_t statusCode;
euint8_t statusCode;
};
static_assert(sizeof(Status) == 4);
static_assert(sizeof(Status) == 1);

struct UInt8
{
euint8_t value;
};
static_assert(sizeof(UInt8) == 1);

struct RGB
{
efloat_t r;
efloat_t g;
efloat_t b;
};
static_assert(sizeof(RGB) == 12);

// --- COMMANDS ---
Status ledOn(Void);
static_assert((sizeof(Void)+1) == 2);

Expand All @@ -38,15 +55,19 @@ static_assert((sizeof(Void)+1) == 2);
Status setLedState(State);
static_assert((sizeof(State)+1) == 2);

State loopback(State);
static_assert((sizeof(State)+1) == 2);
UInt8 loopback(UInt8);
static_assert((sizeof(UInt8)+1) == 2);

State patate(Status);
static_assert((sizeof(Status)+1) == 2);

BaseFunction_ptr commands[] = {
new Function<Status, Void>(&ledOn),
new Function<Status, Void>(&ledOff),
new Function<Status, State>(&setLedState),
new Function<State, State>(&loopback),
new Function<UInt8, UInt8>(&loopback),
new Function<State, Status>(&patate),
};
#define COMMANDS_COUNT 4
#define MAX_DECODED_SIZE 9
#define MAX_ENCODED_SIZE 13
#define COMMANDS_COUNT 5
#define MAX_DECODED_SIZE 13
#define MAX_ENCODED_SIZE 21
52 changes: 39 additions & 13 deletions src/rove_control_board/rove_control_board/api.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
from enum import Enum
from typing import Callable, Optional
from rove_control_board.capra_micro_comm import BinaryData, SerialCommandManager, Void, CommandManager

manager = SerialCommandManager()

@manager.struct('ff')
class Vector2D(BinaryData):
def __init__(self, x:float=0, y:float=0):
super().__init__('ff', x=x, y=y)
super().__init__(x=x, y=y)
self.x:float
self.y:float

@manager.struct('?')
class State(BinaryData):
def __init__(self, state:bool=False):
super().__init__('B', state=state)
super().__init__(state=state)
self.state:bool

@manager.struct('B')
class Status(BinaryData):
def __init__(self, statusCode:int=0):
super().__init__('I', statusCode=statusCode)
def __init__(self, statusCode:int = 0):
super().__init__(statusCode=statusCode)
self.statusCode:int

@manager.struct('B')
class UInt8(BinaryData):
def __init__(self, value:int = 0):
super().__init__(value=value)
self.value:int

@manager.struct('fff')
class RGB(BinaryData):
def __init__(self, r:float=0,g:float=0,b:float=0):
super().__init__(r=r,g=g,b=b)
self.r:float
self.g:float
self.b:float

@manager.binaryFunction(Void, Status)
@manager.command(Void, Status)
def ledOn():
print("on")

@manager.binaryFunction(Void, Status)
@manager.command(Void, Status)
def ledOff():
print("off")

@manager.binaryFunction(State, Status)
@manager.command(State, Status)
def setLedState(state:State):
print('on' if state.state else 'off')

Expand All @@ -34,14 +56,18 @@ def ledStatus(status:Status):
print(f"code: {status.statusCode}")


@manager.binaryFunction(State, State)
def loopback(state:State) -> State:
@manager.command(UInt8, UInt8)
def loopback(state:UInt8) -> UInt8:
pass

@loopback.preCall
def preLoop(state:State):
print(f"Sending {state.state}")
def preLoop(state:UInt8):
print(f"Sending {state.value}")

@loopback.postCall
def postLoop(state:State):
print(f"Recieving {state.state}")
def postLoop(state:UInt8):
print(f"Recieving {state.value}")

@manager.command(Status, State)
def patate(s:Status):
pass
Loading

0 comments on commit 8a8f4a7

Please sign in to comment.