BDS Public
Beam-lib  2.16.3
This is the Beam C++ class library.
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) 2018 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef BoapMc1_h
8 #define BoapMc1_h
9 
10 #include <BTypes.h>
11 #include <BMutex.h>
12 #include <BSemaphore.h>
13 #include <BQueue.h>
14 #include <BFifo.h>
15 #include <BComms.h>
16 
17 // Main BOAP Types
18 const BUInt16 BoapMc1Magic = 0x5542;
19 enum BoapMc1Type { BoapMc1TypeRequest = 0x0000, BoapMc1TypeReply = 0x8000 };
20 
21 // BoapMc1 packet header
30 } __attribute__((aligned(8),packed));
31 
32 // BoapMc1 packet
34 public:
36  char data[8];
37 } __attribute__((aligned(8),packed));
38 
39 struct BoapMc1Error {
41  char string[32];
42 } __attribute__((aligned(8),packed));
43 
45  return ((len + 3) & ~3);
46 }
47 
48 /*******************************************************************************
49  * Base for bidirectional communications objects
50  *******************************************************************************
51  */
52 
53 class BoapMc1Comms {
54 public:
55  BoapMc1Comms(Bool threaded = 0, BUInt reqSize = 512);
56  virtual ~BoapMc1Comms();
57 
58  void setCommsMode(Bool halfDuplex);
59  void setComms(BComms& comms);
60  void setComms(BComms* comms);
63  BUInt32 setTimeout(BUInt32 timeoutUs);
64 
65  virtual BError validate();
67 
68  virtual BError processRx();
69 
70 protected:
71  // Communications functions
72  virtual BError processRequests();
73  virtual BError processRequest();
74 
75  BError packetTx(BDataChunk* chunks, BUInt nChunks, BUInt16 waitCmdReply);
76 
77 #ifdef ZAP_IDEAS
78  BError packetRxWait(BUInt num, char** data);
79  BError packetRxWait(BUInt16 cmd);
80 #endif
81 
82  BError packetRxData(void* data, BUInt nBytes);
84 
95 
104 };
105 
106 
107 #endif
BUInt32 checksum
Packet checksum, when used.
Definition: BoapMc1.h:29
BUInt32 oapiVersion
Definition: BoapMc1.h:90
Definition: BoapMc1.h:39
void setComms(BComms &comms)
Sets the communications interface to use.
Definition: BoapMc1.cpp:68
BInt16 number
The error number.
Definition: BoapMc1.h:40
BUInt16 cmd
The RPC command or reply number.
Definition: BoapMc1.h:27
BUInt16 addressFrom
Address packet is from.
Definition: BoapMc1.h:26
BUInt16 oaddressTo
Definition: BoapMc1.h:93
Semaphore class.
Definition: BSemaphore.h:15
BUInt32 otimeout
The timeout in us for calls.
Definition: BoapMc1.h:92
virtual ~BoapMc1Comms()
Definition: BoapMc1.cpp:61
BError packetRxEnd()
Definition: BoapMc1.cpp:164
virtual BError processRequest()
Check and process any request.
Definition: BoapMc1.cpp:254
Definition: BoapMc1.h:19
BoapMc1Comms(Bool threaded=0, BUInt reqSize=512)
Definition: BoapMc1.cpp:47
BoapMc1Packet * opacketTx
The TX packet.
Definition: BoapMc1.h:99
BInt16 error
Error number.
Definition: BoapMc1.h:28
int16_t BInt16
Definition: BTypes.h:18
BMutex olockTx
Lock for TX.
Definition: BoapMc1.h:88
BUInt16 addressTo
Address to send to.
Definition: BoapMc1.h:21
bool Bool
Definition: BTypes.h:15
BoapMc1Type
Definition: BoapMc1.h:19
BSemaphore opacketRpcSema
Wait RPC reply semaphore.
Definition: BoapMc1.h:101
BUInt opacketRpcCmd
Waiting for RPC reply to cmd.
Definition: BoapMc1.h:100
Definition: BoapMc1.h:19
BoapMc1Packet opacketRxBase
Definition: BoapMc1.h:96
BMutex olockCall
Lock for RPC calls. Only one at a time.
Definition: BoapMc1.h:87
Bool ohalfDuplex
Half duplex mode.
Definition: BoapMc1.h:91
Definition: BoapMc1.h:53
BUInt32 oreqSize
The maximum request size.
Definition: BoapMc1.h:86
BoapMc1PacketHead head
Definition: BoapMc1.h:35
BoapMc1Error oerror
The call return error;.
Definition: BoapMc1.h:103
const BUInt16 BoapMc1Magic
Definition: BoapMc1.h:18
BUInt32 boapMc1CommsRoundupLen(BUInt32 len)
Definition: BoapMc1.h:44
Bool othreaded
Threaded operation.
Definition: BoapMc1.h:85
BoapMc1Packet * packetRx()
Returns a reference to the current RX packet.
Definition: BoapMc1.cpp:97
BUInt16 cmd
The RPC command or reply number.
Definition: BoapMc1.h:23
BSemaphore opacketRpcDoneSema
Wait RPC complete semaphore.
Definition: BoapMc1.h:102
BUInt32 BUInt
Definition: BTypes.h:30
void setCommsMode(Bool halfDuplex)
Sets half duplex mode.
Definition: BoapMc1.cpp:64
uint32_t BUInt32
Definition: BTypes.h:21
Definition: BComms.h:14
BUInt16 oaddressFrom
Definition: BoapMc1.h:94
BError packetTx(BDataChunk *chunks, BUInt nChunks, BUInt16 waitCmdReply)
Definition: BoapMc1.cpp:101
BUInt16 addressFrom
Address packet is from.
Definition: BoapMc1.h:22
char data[8]
Definition: BoapMc1.h:36
BError packetRxData(void *data, BUInt nBytes)
Definition: BoapMc1.cpp:142
BoapMc1Packet opacketTxBase
Definition: BoapMc1.h:98
Definition: BMutex.h:14
Definition: BTypes.h:91
BComms * ocomms
Definition: BoapMc1.h:89
char data[8]
Definition: BoapMc1.h:21
void setAddress(BUInt16 addressTo, BUInt16 addressFrom)
Sets the to and from addresses.
Definition: BoapMc1.cpp:76
uint16_t BUInt16
Definition: BTypes.h:19
BUInt32 setTimeout(BUInt32 timeoutUs)
Sets the call timeout returning the current value.
Definition: BoapMc1.cpp:85
Definition: BoapMc1.h:33
BUInt16 magic
Packet magic pattern.
Definition: BoapMc1.h:23
BoapMc1Packet * opacketRx
The RX packet.
Definition: BoapMc1.h:97
virtual BError processRequests()
Check and process any requests.
Definition: BoapMc1.cpp:266
class BoapMc1Comms __attribute__
BUInt32 getApiVersion()
Returns the API version.
Definition: BoapMc1.cpp:81
Definition: BError.h:25
Definition: BoapMc1.h:22
BUInt16 length
Total packet length including the header.
Definition: BoapMc1.h:24
BUInt16 addressTo
Address to send to.
Definition: BoapMc1.h:25
virtual BError validate()
Validate the request.
Definition: BoapMc1.cpp:93
virtual BError processRx()
Process any RX packets queuing them as needed.
Definition: BoapMc1.cpp:173