WIP: somethings wrong.. #19
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <framework/devicehandlers/CommunicationMessage.h>
|
#include <framework/devicehandlers/CommunicationMessage.h>
|
||||||
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
CommunicationMessage::CommunicationMessage(): uninitialized(true) {
|
CommunicationMessage::CommunicationMessage(): uninitialized(true) {
|
||||||
@ -23,19 +24,23 @@ void CommunicationMessage::setSendRequestFromPointer(uint32_t address,
|
|||||||
void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) {
|
void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) {
|
||||||
setMessageType(SEND_DATA_FROM_IPC_STORE);
|
setMessageType(SEND_DATA_FROM_IPC_STORE);
|
||||||
setAddress(address);
|
setAddress(address);
|
||||||
setStoreId(storeId);
|
setStoreId(storeId.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length) {
|
void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length,
|
||||||
|
uint16_t sendBufferPosition) {
|
||||||
setMessageType(SEND_DATA_RAW);
|
setMessageType(SEND_DATA_RAW);
|
||||||
setAddress(address);
|
setAddress(address);
|
||||||
setDataLen(length);
|
setDataLen(length);
|
||||||
|
if(sendBufferPosition != 0) {
|
||||||
|
setBufferPosition(sendBufferPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) {
|
void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) {
|
||||||
setMessageType(REPLY_DATA_IPC_STORE);
|
setMessageType(REPLY_DATA_IPC_STORE);
|
||||||
setAddress(address);
|
setAddress(address);
|
||||||
setStoreId(storeId);
|
setStoreId(storeId.raw);
|
||||||
}
|
}
|
||||||
void CommunicationMessage::setDataReplyFromPointer(uint32_t address,
|
void CommunicationMessage::setDataReplyFromPointer(uint32_t address,
|
||||||
uint32_t dataLen, uint8_t *data) {
|
uint32_t dataLen, uint8_t *data) {
|
||||||
@ -51,7 +56,7 @@ void CommunicationMessage::setDataReplyRaw(uint32_t address,
|
|||||||
setAddress(address);
|
setAddress(address);
|
||||||
setDataLen(length);
|
setDataLen(length);
|
||||||
if(receiveBufferPosition != 0) {
|
if(receiveBufferPosition != 0) {
|
||||||
setReceiveBufferPosition(receiveBufferPosition);
|
setBufferPosition(receiveBufferPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,61 +65,137 @@ void CommunicationMessage::setMessageType(messageType status) {
|
|||||||
memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8));
|
memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setAddress(uint32_t address) {
|
void CommunicationMessage::setAddress(address_t address) {
|
||||||
memcpy(getData(),&address,sizeof(address));
|
memcpy(getData(),&address,sizeof(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setReceiveBufferPosition(uint16_t bufferPosition) {
|
address_t CommunicationMessage::getAddress() const {
|
||||||
memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t),
|
address_t address;
|
||||||
|
memcpy(&address,getData(),sizeof(address));
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommunicationMessage::setBufferPosition(uint16_t bufferPosition) {
|
||||||
|
memcpy(getData() + sizeof(uint32_t) + sizeof(uint16_t),
|
||||||
&bufferPosition, sizeof(bufferPosition));
|
&bufferPosition, sizeof(bufferPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t CommunicationMessage::getBufferPosition() const {
|
||||||
|
uint16_t bufferPosition;
|
||||||
|
memcpy(&bufferPosition,
|
||||||
|
getData() + sizeof(uint32_t) + sizeof(uint16_t), sizeof(bufferPosition));
|
||||||
|
return bufferPosition;
|
||||||
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataPointer(const void * data) {
|
void CommunicationMessage::setDataPointer(const void * data) {
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t));
|
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setStoreId(store_address_t storeId) {
|
void CommunicationMessage::setStoreId(store_address_t storeId) {
|
||||||
memcpy(getData() + 2 * sizeof(uint32_t), &storeId, sizeof(store_address_t));
|
memcpy(getData() + 2 * sizeof(uint32_t), &storeId.raw, sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
store_address_t CommunicationMessage::getStoreId() const{
|
||||||
|
store_address_t temp;
|
||||||
|
memcpy(&temp.raw,getData() + 2 * sizeof(uint32_t), sizeof(uint32_t));
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataLen(uint32_t length) {
|
void CommunicationMessage::setDataLen(uint32_t length) {
|
||||||
memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length));
|
memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setData(uint32_t data) {
|
uint32_t CommunicationMessage::getDataLen() const {
|
||||||
|
uint32_t len;
|
||||||
|
memcpy(&len, getData() + 2 * sizeof(uint32_t), sizeof(len));
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommunicationMessage::setUint32Data(uint32_t data) {
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data));
|
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataByte1(uint8_t byte1) {
|
uint32_t CommunicationMessage::getUint32Data() const{
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t), &byte1, sizeof(byte1));
|
uint32_t data;
|
||||||
|
memcpy(&data,getData() + 3 * sizeof(uint32_t), sizeof(data));
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataByte2(uint8_t byte2) {
|
void CommunicationMessage::setDataByte(uint8_t byte, uint8_t position) {
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t) + sizeof(uint8_t), &byte2, sizeof(byte2));
|
if(0 <= position && position <= 3) {
|
||||||
|
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), &byte, sizeof(byte));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error << "Comm Message: Invalid byte position" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataByte3(uint8_t byte3) {
|
uint8_t CommunicationMessage::getDataByte(uint8_t position) const {
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t) + 2* sizeof(uint8_t), &byte3, sizeof(byte3));
|
if(0 <= position && position <= 3) {
|
||||||
|
uint8_t byte;
|
||||||
|
memcpy(&byte, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), sizeof(byte));
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
error << "Comm Message: Invalid byte position" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataByte4(uint8_t byte4) {
|
void CommunicationMessage::setDataUint16(uint16_t data, uint8_t position) {
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t) + 3* sizeof(uint8_t), &byte4, sizeof(byte4));
|
if(position == 0 || position == 1) {
|
||||||
|
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), &data, sizeof(data));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error << "Comm Message: Invalid byte position" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataUINT16_1(uint16_t data1) {
|
uint16_t CommunicationMessage::getDataUint16(uint8_t position) const{
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t), &data1, sizeof(data1));
|
if(position == 0 || position == 1) {
|
||||||
|
uint16_t data;
|
||||||
|
memcpy(&data, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), sizeof(data));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
error << "Comm Message: Invalid byte position" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationMessage::setDataUINT16_2(uint16_t data2) {
|
CommunicationMessage::messageType CommunicationMessage::getMessageType() const{
|
||||||
memcpy(getData() + 3 * sizeof(uint32_t) + sizeof(uint16_t), &data2, sizeof(data2));
|
|
||||||
}
|
|
||||||
|
|
||||||
CommunicationMessage::messageType CommunicationMessage::getMessageType() {
|
|
||||||
messageType messageType;
|
messageType messageType;
|
||||||
memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t));
|
memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t));
|
||||||
return messageType;
|
return messageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommunicationMessage::setMessageId(uint8_t messageId) {
|
||||||
|
memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), &messageId, sizeof(messageId));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CommunicationMessage::getMessageId() const {
|
||||||
|
uint8_t messageId;
|
||||||
|
memcpy(&messageId, getData() + sizeof(uint32_t) + sizeof(uint8_t), sizeof(messageId));
|
||||||
|
return messageId;
|
||||||
|
}
|
||||||
|
|
||||||
void CommunicationMessage::clearCommunicationMessage() {
|
void CommunicationMessage::clearCommunicationMessage() {
|
||||||
messageType messageType = getMessageType();
|
messageType messageType = getMessageType();
|
||||||
|
switch(messageType) {
|
||||||
|
case(messageType::REPLY_DATA_IPC_STORE):
|
||||||
|
case(messageType::SEND_DATA_FROM_IPC_STORE): {
|
||||||
|
store_address_t storeId = getStoreId();
|
||||||
|
StorageManagerIF *ipcStore = objectManager->
|
||||||
|
get<StorageManagerIF>(objects::IPC_STORE);
|
||||||
|
if (ipcStore != NULL) {
|
||||||
|
ipcStore->deleteData(storeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* NO BREAK falls through*/
|
||||||
|
default:
|
||||||
|
memset(getData(),0,4*sizeof(uint32_t));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <framework/ipc/MessageQueueMessage.h>
|
#include <framework/ipc/MessageQueueMessage.h>
|
||||||
#include <framework/storagemanager/StorageManagerIF.h>
|
#include <framework/storagemanager/StorageManagerIF.h>
|
||||||
|
#include <framework/devicehandlers/DeviceHandlerBase.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Used to pass communication information between tasks
|
* @brief Used to pass communication information between tasks
|
||||||
@ -26,6 +27,7 @@
|
|||||||
class CommunicationMessage: public MessageQueueMessage {
|
class CommunicationMessage: public MessageQueueMessage {
|
||||||
public:
|
public:
|
||||||
enum messageType {
|
enum messageType {
|
||||||
|
NONE,
|
||||||
SEND_DATA_FROM_POINTER,
|
SEND_DATA_FROM_POINTER,
|
||||||
SEND_DATA_FROM_IPC_STORE,
|
SEND_DATA_FROM_IPC_STORE,
|
||||||
SEND_DATA_RAW,
|
SEND_DATA_RAW,
|
||||||
@ -41,6 +43,24 @@ public:
|
|||||||
CommunicationMessage();
|
CommunicationMessage();
|
||||||
virtual ~CommunicationMessage();
|
virtual ~CommunicationMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message Type is stored as the fifth byte of the message data
|
||||||
|
* @param status
|
||||||
|
*/
|
||||||
|
void setMessageType(messageType status);
|
||||||
|
messageType getMessageType() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a unique ID which can be used to handle different kinds of messages.
|
||||||
|
* For example, the same interface (e.g. SPI) could be used to exchange raw data
|
||||||
|
* (e.g. sensor values) and data stored in the IPC store.
|
||||||
|
* The ID can be used to distinguish the messages in child implementations.
|
||||||
|
* The message ID is stored as the sixth byte of the message data.
|
||||||
|
* @param messageId
|
||||||
|
*/
|
||||||
|
void setMessageId(uint8_t messageId);
|
||||||
|
uint8_t getMessageId() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send requests with pointer to the data to be sent and send data length
|
* Send requests with pointer to the data to be sent and send data length
|
||||||
* @param address Target Address, first four bytes
|
* @param address Target Address, first four bytes
|
||||||
@ -65,7 +85,8 @@ public:
|
|||||||
* @param data Pointer to data to send
|
* @param data Pointer to data to send
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void setSendRequestRaw(uint32_t address, uint32_t length);
|
void setSendRequestRaw(uint32_t address, uint32_t length,
|
||||||
|
uint16_t sendBufferPosition = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data message with data stored in IPC store
|
* Data message with data stored in IPC store
|
||||||
@ -97,31 +118,27 @@ public:
|
|||||||
* First four bytes of message data
|
* First four bytes of message data
|
||||||
* @param address
|
* @param address
|
||||||
*/
|
*/
|
||||||
void setAddress(uint32_t address);
|
void setAddress(address_t address);
|
||||||
|
|
||||||
|
address_t getAddress() const;
|
||||||
|
/**
|
||||||
|
* Set byte as position of 4 byte data field
|
||||||
|
* @param byte
|
||||||
|
* @param position Position, 0 to 3 possible
|
||||||
|
*/
|
||||||
|
void setDataByte(uint8_t byte, uint8_t position);
|
||||||
|
uint8_t getDataByte(uint8_t position) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message Type is stored as the fifth byte of the message data
|
* Set 2 byte value at position 1 or 2 of data field
|
||||||
* @param status
|
* @param data
|
||||||
|
* @param position 0 or 1 possible
|
||||||
*/
|
*/
|
||||||
void setMessageType(messageType status);
|
void setDataUint16(uint16_t data, uint8_t position);
|
||||||
messageType getMessageType();
|
uint16_t getDataUint16(uint8_t position) const;
|
||||||
|
|
||||||
void setMessageId(uint8_t messageId);
|
void setUint32Data(uint32_t data);
|
||||||
messageType getMessageId();
|
uint32_t getUint32Data() const;
|
||||||
|
|
||||||
/*
|
|
||||||
* The following functions can be used to
|
|
||||||
* set the data field (4 bytes possible);
|
|
||||||
*/
|
|
||||||
void setDataByte1(uint8_t byte1);
|
|
||||||
void setDataByte2(uint8_t byte2);
|
|
||||||
void setDataByte3(uint8_t byte3);
|
|
||||||
void setDataByte4(uint8_t byte4);
|
|
||||||
|
|
||||||
void setDataUINT16_1(uint16_t data1);
|
|
||||||
void setDataUINT16_2(uint16_t data2);
|
|
||||||
|
|
||||||
void setData(uint32_t data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stored in Bytes 13-16 of message data
|
* Stored in Bytes 13-16 of message data
|
||||||
@ -129,6 +146,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setDataLen(uint32_t length);
|
void setDataLen(uint32_t length);
|
||||||
|
|
||||||
|
uint32_t getDataLen() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stored in last four bytes (Bytes 17-20) of message data
|
* Stored in last four bytes (Bytes 17-20) of message data
|
||||||
* @param sendData
|
* @param sendData
|
||||||
@ -136,19 +155,22 @@ public:
|
|||||||
void setDataPointer(const void * data);
|
void setDataPointer(const void * data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer Position is stored as the seventh and eigth byte of
|
* In case the send request data or reply data is to be stored in a buffer,
|
||||||
|
* a buffer Position can be stored here as the seventh and eigth byte of
|
||||||
* the message, so the receive buffer can't be larger than sizeof(uint16_t) for now.
|
* the message, so the receive buffer can't be larger than sizeof(uint16_t) for now.
|
||||||
* @param bufferPosition
|
* @param bufferPosition In case the data is stored in a buffer, the position can be supplied here
|
||||||
*/
|
*/
|
||||||
void setReceiveBufferPosition(uint16_t bufferPosition);
|
void setBufferPosition(uint16_t bufferPosition);
|
||||||
|
uint16_t getBufferPosition() const;
|
||||||
void setStoreId(store_address_t storeId);
|
void setStoreId(store_address_t storeId);
|
||||||
|
store_address_t getStoreId() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the message
|
* Clear the message. Deletes IPC Store data
|
||||||
|
* and sets all data to 0. Also sets message type to NONE
|
||||||
*/
|
*/
|
||||||
void clearCommunicationMessage();
|
void clearCommunicationMessage();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool uninitialized; //!< Could be used to warn if data has not been set.
|
bool uninitialized; //!< Could be used to warn if data has not been set.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,10 +73,15 @@ public:
|
|||||||
|
|
||||||
virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0;
|
virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by DHB in the SEND_WRITE doSendRead().
|
||||||
|
* @param cookie
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
virtual ReturnValue_t requestReceiveMessage(Cookie *cookie) = 0;
|
virtual ReturnValue_t requestReceiveMessage(Cookie *cookie) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by DHB in the GET_WIRTE doGetRead().
|
* Called by DHB in the GET_WRITE doGetRead().
|
||||||
* This function is used to receive data from the physical device
|
* This function is used to receive data from the physical device
|
||||||
* by implementing and calling related drivers or wrapper functions.
|
* by implementing and calling related drivers or wrapper functions.
|
||||||
* @param cookie
|
* @param cookie
|
||||||
|
Loading…
Reference in New Issue
Block a user