BDS Public
Beamlib 3.3.4
This is the Beam C++ class library.
Loading...
Searching...
No Matches
BoapMc1.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BoapMc1.h BoapMc1 RPC protocol
3 * T.Barnaby, BEAM Ltd, 2018-06-21
4 * Copyright (c) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5 * For license see LICENSE.txt at the root of the beamlib source tree.
6 *******************************************************************************
7 */
8#ifndef BoapMc1_h
9#define BoapMc1_h
10
11#include <BTypes.h>
12#include <BMutex.h>
13#include <BSemaphore.h>
14#include <BQueue.h>
15#include <BFifo.h>
16#include <BComms.h>
17
18// Main BOAP Types
19const BUInt16 BoapMc1Magic = 0x5542;
21
22// BoapMc1 packet header
31} __attribute__((aligned(8),packed));
32
33// BoapMc1 packet
35public:
37 char data[8];
38} __attribute__((aligned(8),packed));
39
42 char string[32];
43} __attribute__((aligned(8),packed));
44
46 return ((len + 3) & ~3);
47}
48
49/*******************************************************************************
50 * Base for bidirectional communications objects
51 *******************************************************************************
52 */
53
55public:
56 BoapMc1Comms(Bool threaded = 0, BUInt reqSize = 512);
57 virtual ~BoapMc1Comms();
58
59 void setCommsMode(Bool halfDuplex);
60 void setComms(BComms& comms);
61 void setComms(BComms* comms);
64 BUInt32 setTimeout(BUInt32 timeoutUs);
65
66 virtual BError validate();
68
69 virtual BError processRx();
70
71protected:
72 // Communications functions
73 virtual BError processRequests();
74 virtual BError processRequest();
75
76 BError packetTx(BDataChunk* chunks, BUInt nChunks, BUInt16 waitCmdReply);
77
78#ifdef ZAP_IDEAS
79 BError packetRxWait(BUInt num, char** data);
80 BError packetRxWait(BUInt16 cmd);
81#endif
82
83 BError packetRxData(void* data, BUInt nBytes);
85
96
106
107
108#endif
int16_t BInt16
Definition BTypes.h:21
uint16_t BUInt16
Definition BTypes.h:22
BUInt32 BUInt
Definition BTypes.h:33
uint32_t BUInt32
Definition BTypes.h:24
bool Bool
Definition BTypes.h:18
BUInt16 addressTo
Address to send to.
Definition BoapMc1.h:2
BUInt16 cmd
The RPC command or reply number.
Definition BoapMc1.h:4
BUInt32 boapMc1CommsRoundupLen(BUInt32 len)
Definition BoapMc1.h:45
class BoapMc1Comms __attribute__
BUInt16 addressFrom
Address packet is from.
Definition BoapMc1.h:3
const BUInt16 BoapMc1Magic
Definition BoapMc1.h:19
BoapMc1Type
Definition BoapMc1.h:20
@ BoapMc1TypeReply
Definition BoapMc1.h:20
@ BoapMc1TypeRequest
Definition BoapMc1.h:20
char data[8]
Definition BoapMc1.h:2
A base class for communications classes having a generic API.
Definition BComms.h:17
A chunk of data allowing writes of multiple chunks of segmented data.
Definition BTypes.h:94
Error return class. This class is used to return the error status from a function....
Definition BError.h:31
Mutex class. Note these are recursive Mutexes and so you need to make sure the number of unlocks equa...
Definition BMutex.h:14
Base Semaphore class.
Definition BSemaphore.h:16
Definition BoapMc1.h:54
BMutex olockCall
Lock for RPC calls. Only one at a time.
Definition BoapMc1.h:88
virtual BError processRequests()
Check and process any requests.
Definition BoapMc1.cpp:273
BUInt32 getApiVersion()
Returns the API version.
Definition BoapMc1.cpp:82
BSemaphore opacketRpcSema
Wait RPC reply semaphore.
Definition BoapMc1.h:102
BSemaphore opacketRpcDoneSema
Wait RPC complete semaphore.
Definition BoapMc1.h:103
virtual BError validate()
Validate the request.
Definition BoapMc1.cpp:94
void setAddress(BUInt16 addressTo, BUInt16 addressFrom)
Sets the to and from addresses.
Definition BoapMc1.cpp:77
BUInt32 oreqSize
The maximum request size.
Definition BoapMc1.h:87
BError packetTx(BDataChunk *chunks, BUInt nChunks, BUInt16 waitCmdReply)
Definition BoapMc1.cpp:102
BoapMc1Packet * packetRx()
Returns a reference to the current RX packet.
Definition BoapMc1.cpp:98
BoapMc1Packet * opacketTx
The TX packet.
Definition BoapMc1.h:100
virtual BError processRequest()
Check and process any request.
Definition BoapMc1.cpp:261
void setCommsMode(Bool halfDuplex)
Sets half duplex mode.
Definition BoapMc1.cpp:65
BComms * ocomms
Definition BoapMc1.h:90
virtual ~BoapMc1Comms()
Definition BoapMc1.cpp:62
BMutex olockTx
Lock for TX.
Definition BoapMc1.h:89
virtual BError processRx()
Process any RX packets queuing them as needed.
Definition BoapMc1.cpp:180
BoapMc1Packet opacketRxBase
Definition BoapMc1.h:97
BUInt32 setTimeout(BUInt32 timeoutUs)
Sets the call timeout returning the current value.
Definition BoapMc1.cpp:86
Bool othreaded
Threaded operation.
Definition BoapMc1.h:86
BUInt16 oaddressFrom
Definition BoapMc1.h:95
BoapMc1Packet * opacketRx
The RX packet.
Definition BoapMc1.h:98
BError packetRxEnd()
Definition BoapMc1.cpp:171
BUInt32 oapiVersion
Definition BoapMc1.h:91
Bool ohalfDuplex
Half duplex mode.
Definition BoapMc1.h:92
BUInt opacketRpcCmd
Waiting for RPC reply to cmd.
Definition BoapMc1.h:101
void setComms(BComms &comms)
Sets the communications interface to use.
Definition BoapMc1.cpp:69
BUInt16 oaddressTo
Definition BoapMc1.h:94
BoapMc1Packet opacketTxBase
Definition BoapMc1.h:99
BError packetRxData(void *data, BUInt nBytes)
Definition BoapMc1.cpp:149
BUInt32 otimeout
The timeout in us for calls.
Definition BoapMc1.h:93
BoapMc1Error oerror
The call return error;.
Definition BoapMc1.h:104
Definition BoapMc1.h:34
char data[8]
Definition BoapMc1.h:37
BoapMc1PacketHead head
Definition BoapMc1.h:36
Definition BoapMc1.h:40
BInt16 number
The error number.
Definition BoapMc1.h:41
Definition BoapMc1.h:23
BInt16 error
Error number.
Definition BoapMc1.h:29
BUInt16 addressFrom
Address packet is from.
Definition BoapMc1.h:27
BUInt16 magic
Packet magic pattern.
Definition BoapMc1.h:24
BUInt16 addressTo
Address to send to.
Definition BoapMc1.h:26
BUInt16 cmd
The RPC command or reply number.
Definition BoapMc1.h:28
BUInt32 checksum
Packet checksum, when used.
Definition BoapMc1.h:30
BUInt16 length
Total packet length including the header.
Definition BoapMc1.h:25