message.h
来自「SOS操作系统用于无线传感器网络节点的源代码」· C头文件 代码 · 共 227 行
H
227 行
#ifndef MESSAGE_H
#define MESSAGE_H
#include "sos_types.h"
#include "pid.h"
#include "message_types.h"
/**
* @brief Post a message
* @param e Message pointer
* @return errno
*/
extern int8_t post(Message *e);
/**
* @brief Post message over an IO Link
* @param did Destination Module ID
* @param sid Source Module ID
* @param type Message Type
* @param len Message Payload Length
* @param data Pointer to message payload
* @param flag Message Options
* @param daddr Destination Node Address
* @return errno
*/
extern int8_t post_link(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t len,
void* data,
uint16_t flag,
uint16_t daddr);
/**
* @brief Post message over the right link select by the system
* @param did Destination Module ID
* @param sid Source Module ID
* @param type Message Type
* @param len Message Payload Length
* @param data Pointer to message payload
* @param flag Message Options
* @param daddr Destination Node Address
* @return errno
*/
static inline int8_t post_auto(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t len,
void* data,
uint16_t flag,
uint16_t daddr) {
return post_link(did, sid, type, len, data, flag | SOS_MSG_ALL_LINK_IO | SOS_MSG_LINK_AUTO, daddr);
}
/**
* @brief Post message over Radio Link
* @param did Destination Module ID
* @param sid Source Module ID
* @param type Message Type
* @param len Message Payload Length
* @param data Pointer to message payload
* @param flag Message Options
* @param daddr Destination Node Address
* @return errno
*/
static inline int8_t post_net(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t len,
void *data,
uint16_t flag,
uint16_t daddr){
return post_link(did, sid, type, len, data, flag|SOS_MSG_RADIO_IO, daddr);
}
/**
* @brief Post message over UART Link
* @param did Destination Module ID
* @param sid Source Module ID
* @param type Message Type
* @param len Message Payload Length
* @param data Pointer to message payload
* @param flag Message Options
* @param daddr Destination Node Address
* @return errno
*/
static inline int8_t post_uart(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t length,
void *data,
uint16_t flag,
uint16_t daddr){
return post_link(did, sid, type, length, data, flag|SOS_MSG_UART_IO, daddr);
}
/**
* @brief Post message over I2C Link
* @param did Destination Module ID
* @param sid Source Module ID
* @param type Message Type
* @param len Message Payload Length
* @param data Pointer to message payload
* @param flag Message Options
* @param daddr Destination Node Address
* @return errno
*/
static inline int8_t post_i2c(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t length,
void *data,
uint16_t flag,
uint16_t daddr){
return post_link(did, sid, type, length, data, flag|SOS_MSG_I2C_IO, daddr);
}
/**
* @brief Post message over SPI Link
* @param did Destination Module ID
* @param sid Source Module ID
* @param type Message Type
* @param len Message Payload Length
* @param data Pointer to message payload
* @param flag Message Options
* @param daddr Destination Node Address
* @return errno
*/
static inline int8_t post_spi(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t length,
void *data,
uint16_t flag,
uint16_t daddr){
return post_link(did, sid, type, length, data, flag|SOS_MSG_SPI_IO, daddr);
}
/**
* @brief post buffered short message
* @param did destination module id
* @param sid source module id
* @param type message type
* @param byte one byte data
* @param word two byte data
* @param flag message flag
* @return errno
*
* this is useful for posting message upto two parameters
*/
extern int8_t post_short(
sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t byte,
uint16_t word,
uint16_t flag);
/**
* @brief post buffered long message
* @param did destination module id
* @param sid source module id
* @param type message type
* @param len size of data
* @param data data in the message
* @param flag message options
* @return errno
*
*/
extern int8_t post_long(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t len,
void *data,
uint16_t flag);
/**
* @brief post buffered longer message
* @param did destination module id
* @param sid source module id
* @param type message type
* @param len size of data
* @param data data in the message
* @param flag message options
* @param saddr source address (comes in handy for routing messages)
* @return errno
*
*/
extern int8_t post_longer(sos_pid_t did,
sos_pid_t sid,
uint8_t type,
uint8_t len,
void *data,
uint16_t flag,
uint16_t saddr);
/**
* @brief get the data from message
* @param pid module pid
* @param msg Message
* @return the pointer to data, or NULL for failure.
*
* ker_msg_take_data tries to get the data from message
* When the message is dynamically allocated, it will detach data from
* message. Otherwise, it will attempt to ker_malloc a buffer and copy
* the data. Therefore, when there is no memory, it is possible that this
* call may fail.
*
* ker_msg_take_data will check whether message type is MSG_PKT_SENDDONE.
* If so, data will be taken from inner message. When trying to take data
* from MSG_PKT_SENDDONE, use the pointer of outter message.
*
*/
extern uint8_t *ker_msg_take_data(sos_pid_t pid, Message *msg);
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?