KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
|
Handles MCF packed messages from the higher protocol layer. More...
#include "errorcode.h"
#include "cfg_msg.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "util/databuffer.h"
#include "kernel/err.h"
#include "net/net.h"
#include "net/mcf.h"
Go to the source code of this file.
Data Structures | |
struct | MsgId |
If defined, events will not require an acknowledge. More... | |
Macros | |
#define | E_MSG_TYPE_UNKNOWN ( E_MSG + 0x01 ) |
Message unknown. | |
#define | E_MSG_TYPE_UNKNOWN_DESCR "Unknown message" |
#define | E_MSG_FUNCTION ( E_MSG + 0x02 ) |
Message function returned false. | |
#define | E_MSG_FUNCTION_DESCR "Function error" |
#define | E_MSG_CLASS_UNSUPPORT ( E_MSG + 0x03 ) |
Message class received not supported. | |
#define | E_MSG_CLASS_UNSUPPORT_DESCR "Class not supported" |
#define | MSG_CMD(CMD_TYPE, CMD_STUB) bool _msg ## CMD_STUB (MsgId * id, DataBuffer * buf); |
Generate all message callbacks. | |
#define | MSG_EVT(EVT_TYPE, EVT_STUB) void _evt ## EVT_STUB (MsgId * id, DataBuffer * buf); |
Functions | |
void | msgRx (SockAddr *addr, uint8_t *data, int len) |
Receive a packet with data as a command. More... | |
void | _msgRxCmd (MsgId id, DataBuffer *buf) |
Invoked when a command is received. More... | |
bool | msgTxReply (MsgId *id, DataBuffer *buf) |
Invoke to send a reply. More... | |
static bool | msgTxReplyAck (MsgId *id) |
Replies a simple ACK with no content. More... | |
void | msgSetEvtTarget (SockAddr *sockAddr) |
Set the target for all events, or pass NULL to unset. More... | |
void | msgGetEvtTarget (SockAddr *sockAddr) |
Returns the event target address. More... | |
bool | msgTxEvent (int msgType, DataBuffer *buf) |
Invoked to send an event. More... | |
bool | msgTxError (MsgId *id, int errCode, const char *errMsg, const char *name) |
Invoke to send an error response. More... | |
static bool | msgTxCurError (MsgId *id) |
Invoke to reply the current global error. More... | |
bool | msgStartStoreCmds (SockAddr *client, DataBuffer *target) |
Indicates that the next commands received should be stored. More... | |
bool | msgStopStoreCmds () |
Stops the storage of commands. More... | |
bool | msgExecCmds (SockAddr client, DataBuffer *commands, DataBuffer *replies) |
Executes the given commands in the databuffer as if they where send by the 'client' address. More... | |
bool | msgRxBufCheck (DataBuffer *buf) |
Checks the received buffer, and logs an error if there is something wrong. More... | |
void | _msgTx (SockAddr *addr, uint8_t *data, int len) |
Stub function, invoked by RMT when sending a MCF packet. More... | |
bool | _msgBusRead (MsgId *id, DataBuffer *buf) |
Reads an address. | |
bool | _msgBusWrite (MsgId *id, DataBuffer *buf) |
Writes one or more addresses. | |
bool | _msgI2CRead (MsgId *id, DataBuffer *buf) |
bool | _msgI2CWrite (MsgId *id, DataBuffer *buf) |
bool | _msgUartTx (MsgId *id, DataBuffer *buf) |
bool | _msgUartRx (MsgId *id, DataBuffer *buf) |
bool | _msgFlashRead (MsgId *id, DataBuffer *buf) |
bool | _msgRxPktLogRead (MsgId *id, DataBuffer *buf) |
bool | _msgRxPktLogReset (MsgId *id, DataBuffer *buf) |
bool | _msgPing (MsgId *id, DataBuffer *buf) |
Reads an address. | |
bool | _msgDateRev (MsgId *id, DataBuffer *buf) |
bool | _msgEvtTarget (MsgId *id, DataBuffer *buf) |
bool | _msgReset (MsgId *id, DataBuffer *buf) |
bool | _msgSysUpdateStart (MsgId *id, DataBuffer *buf) |
bool | _msgSysUpdateRecv (MsgId *id, DataBuffer *buf) |
bool | _msgSysUpdateEnd (MsgId *id, DataBuffer *buf) |
bool | _msgSysUpdateVerify (MsgId *id, DataBuffer *buf) |
bool | _msgBoot (MsgId *id, DataBuffer *buf) |
bool | _msgGoldenStop (MsgId *id, DataBuffer *buf) |
bool | _msgGoldenUnlock (MsgId *id, DataBuffer *buf) |
bool | _msgLogGet (MsgId *id, DataBuffer *buf) |
bool | _msgPLogGet (MsgId *id, DataBuffer *buf) |
bool | _msgImgGet (MsgId *id, DataBuffer *buf) |
bool | _msgCoreDumpClr (MsgId *id, DataBuffer *buf) |
bool | _msgConTunInit (MsgId *id, DataBuffer *buf) |
bool | _msgConTunSend (MsgId *id, DataBuffer *buf) |
bool | _msgRtConfig (MsgId *id, DataBuffer *buf) |
bool | _msgClbGetState (MsgId *id, DataBuffer *buf) |
bool | _msgClbEvent (MsgId *id, DataBuffer *buf) |
bool | _msgClbGetVars (MsgId *id, DataBuffer *buf) |
bool | _msgClbSetVars (MsgId *id, DataBuffer *buf) |
bool | _msgClbSubVars (MsgId *id, DataBuffer *buf) |
bool | _msgClbUnSubVars (MsgId *id, DataBuffer *buf) |
bool | _msgClbExtUpdate (MsgId *id, DataBuffer *buf) |
bool | _msgClbClrErrState (MsgId *id, DataBuffer *buf) |
bool | _msgClbSubVarsRate (MsgId *id, DataBuffer *buf) |
bool | _msgNetMuxDest (MsgId *id, DataBuffer *buf) |
bool | _msgNetWlTuneInfo (MsgId *id, DataBuffer *buf) |
Request the wavelength tuning subsystem state. | |
bool | _msgNetWlTuneSet (MsgId *id, DataBuffer *buf) |
Set the wavelength tuning word. | |
bool | _msgNetWlTuneAck (MsgId *id, DataBuffer *buf) |
Acknowledge the wavelength tuning. | |
bool | _msgInsAHRSSetReg (MsgId *id, DataBuffer *buf) |
Writes a register of the AHRS. | |
bool | _msgInsAHRSGetReg (MsgId *id, DataBuffer *buf) |
Reads a register of the AHRS. | |
bool | _msgInsAHRSGetRegEx (MsgId *id, DataBuffer *buf) |
bool | _msgBseConfigure (MsgId *id, DataBuffer *buf) |
bool | _msgBseReset (MsgId *id, DataBuffer *buf) |
bool | _msgBseEdfaDbgCmd (MsgId *id, DataBuffer *buf) |
bool | _msgBseEdfaDbgCmdRply (MsgId *id, DataBuffer *buf) |
bool | _msgBseBpsDbgCmdRply (MsgId *id, DataBuffer *buf) |
void | _evtSysUpdateRecv (MsgId *id, DataBuffer *buf) |
void | _evtConTunRecv (MsgId *id, DataBuffer *buf) |
Handles MCF packed messages from the higher protocol layer.
From the lower-level protocol layer (in this case SRP, but it might just as well be TCP/IP), the _msgRx() command is invoked. The received packets are unpacked, and its contents decoded.
For each command a function prototype is generated, which should be implemented by the higher level functions. These commands get a message identifier and a DataBuffer containing the content of the message.
For example, the ReadAddr message is defined as follows: MSG_CMD(GROUP_DEBUG, 1, ReadAddr)
The message module will then generate a stub-signature as follows:
However, the implementation is left to the higher-level layers.
There are 3 ways in which you can generate a reply:
Which to take depends on the situation, however, take care with option 1, since it will stall the network stack.
Synchronous replies are replies which yield a result immediately. They will be used most common situations.
For example, the following code returns a number of memory addresses read.
However, it is not required to generate a reply inside the processing function. Functions which require some asynchronous processing, but don't take more than a second, can use asynchronous processing.
An event reply is used when the function takes even more time. For simplicity sake we will use the same code as before, and modify it to be an event.
First of all the code immediately generates an OK reply. Second the function msgTxReplyEvent is used instead of msgTxReply. Those are the only differences at this side.
In practice what will happen on the shore-station side is that the function is invoked, and returns immediately, later on the reply will be passed to the shore-station API and returned through an asynchronous listener.
The Msg module can also be used to generate periodic stand-alone events. These can be used to communicate status updates, or maybe unexpected failures.
However, the address to send the event to should be known before hand. To do this we first need to configure the receiver. For this we have defined the 'ConfStatusReceiver' command which takes the sender of the command to be the receiver for asynchronous events. This command should be invoked by the shore station before events can be send.
Once this is done, we can schedule a periodic function to create status messages.
Message Container Format is just what it is, a format. It does not imply any kind of protocol. The Msg module, however, uses it to parse and format messages. Still on the remote side it is expected that a command always yields a reply within a specified time. Care must be taken by the higher-level layer, that is, a command implementation, to always generate a reply. In its simplest form this is done by returning false in the stub function. Failure to do so will cause time-out's on the shore-station, and may hold-up processes.
Definition in file msg.h.
void _msgRxCmd | ( | MsgId | id, |
DataBuffer * | buf | ||
) |
Invoked when a command is received.
id | |
buf |
void _msgTx | ( | SockAddr * | addr, |
uint8_t * | message, | ||
int | len | ||
) |
bool msgExecCmds | ( | SockAddr | client, |
DataBuffer * | commands, | ||
DataBuffer * | replies | ||
) |
Executes the given commands in the databuffer as if they where send by the 'client' address.
client | Address from which the commands appear to be executed. |
commands | A buffer containing the commands |
true | Commands where executed. |
false | Commands could not be executed. See errCode() for more information. |
void msgGetEvtTarget | ( | SockAddr * | sockAddr | ) |
void msgRx | ( | SockAddr * | addr, |
uint8_t * | data, | ||
int | len | ||
) |
bool msgRxBufCheck | ( | DataBuffer * | buf | ) |
Checks the received buffer, and logs an error if there is something wrong.
Must be invoked after all data has been read.
buf | The buffer to check |
true | The buffer is OK, and all content has been processed. |
false | The buffer is not OK, or not all commands have been processed. |
void msgSetEvtTarget | ( | SockAddr * | sockAddr | ) |
bool msgStartStoreCmds | ( | SockAddr * | client, |
DataBuffer * | target | ||
) |
Indicates that the next commands received should be stored.
client | The client address to receive from. All others will be executed, not stored. |
store | true - Store, false - Do not queue received commands. |
true | Storage of commands started |
false | Storage of commands not started, see errCode() for more info. |
bool msgStopStoreCmds | ( | ) |
Stops the storage of commands.
true | Storage of commands succesfully stopped |
false | Storage of commands failed. |
|
inlinestatic |
bool msgTxError | ( | MsgId * | id, |
int | errCode, | ||
const char * | errMsg, | ||
const char * | name | ||
) |
bool msgTxEvent | ( | int | msgType, |
DataBuffer * | buf | ||
) |
bool msgTxReply | ( | MsgId * | id, |
DataBuffer * | buf | ||
) |