added icsneo_message_get_type_name
parent
780e0245b8
commit
7c4a3d3077
|
|
@ -115,6 +115,12 @@ ICSNEO_API icsneo_error_t icsneo_get_error_code(icsneo_error_t error_code, const
|
||||||
case icsneo_error_sync_rtc_failed:
|
case icsneo_error_sync_rtc_failed:
|
||||||
error = "Syncronizing RTC failed";
|
error = "Syncronizing RTC failed";
|
||||||
break;
|
break;
|
||||||
|
case icsneo_error_get_messages_failed:
|
||||||
|
error = "Getting messages failed";
|
||||||
|
break;
|
||||||
|
case icsneo_error_invalid_type:
|
||||||
|
error = "Invalid type";
|
||||||
|
break;
|
||||||
case icsneo_error_rtc_failure:
|
case icsneo_error_rtc_failure:
|
||||||
error = "RTC failure";
|
error = "RTC failure";
|
||||||
break;
|
break;
|
||||||
|
|
@ -474,6 +480,15 @@ ICSNEO_API icsneo_error_t icsneo_message_get_type(icsneo_device_t* device, icsne
|
||||||
return icsneo_error_success;
|
return icsneo_error_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_message_get_type_name(icsneo_msg_type_t msg_type, const char* value, uint32_t* value_length) {
|
||||||
|
if (!value || !value_length) {
|
||||||
|
return icsneo_error_invalid_parameters;
|
||||||
|
}
|
||||||
|
// TODO: Check if message is valid
|
||||||
|
// Copy the string into value
|
||||||
|
return safe_str_copy(value, value_length, Message::getMsgTypeName(msg_type)) ? icsneo_error_success : icsneo_error_string_copy_failed;
|
||||||
|
}
|
||||||
|
|
||||||
ICSNEO_API icsneo_error_t icsneo_message_get_bus_type(icsneo_device_t* device, icsneo_message_t* message, icsneo_msg_bus_type_t* bus_type) {
|
ICSNEO_API icsneo_error_t icsneo_message_get_bus_type(icsneo_device_t* device, icsneo_message_t* message, icsneo_msg_bus_type_t* bus_type) {
|
||||||
if (!device || !message || !bus_type) {
|
if (!device || !message || !bus_type) {
|
||||||
return icsneo_error_invalid_parameters;
|
return icsneo_error_invalid_parameters;
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,13 @@ typedef uint16_t neomessagetype_t;
|
||||||
#include "icsneo/communication/network.h"
|
#include "icsneo/communication/network.h"
|
||||||
#include "icsneo/icsneotypes.h"
|
#include "icsneo/icsneotypes.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace icsneo {
|
namespace icsneo {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractMessage {
|
class AbstractMessage {
|
||||||
public:
|
public:
|
||||||
virtual const icsneo_msg_type_t getMsgType() const = 0;
|
virtual const icsneo_msg_type_t getMsgType() const = 0;
|
||||||
|
|
@ -21,6 +25,28 @@ class Message : public AbstractMessage {
|
||||||
public:
|
public:
|
||||||
virtual const icsneo_msg_type_t getMsgType() const { return icsneo_msg_type_device; }
|
virtual const icsneo_msg_type_t getMsgType() const { return icsneo_msg_type_device; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the string representation of the message type
|
||||||
|
*
|
||||||
|
* @return String representation of the message type
|
||||||
|
*
|
||||||
|
* @see AbstractMessage::getMsgType()
|
||||||
|
*/
|
||||||
|
static std::string getMsgTypeName(icsneo_msg_type_t msg_type) {
|
||||||
|
switch (msg_type) {
|
||||||
|
case icsneo_msg_type_device:
|
||||||
|
return "Device";
|
||||||
|
case icsneo_msg_type_internal:
|
||||||
|
return "Internal";
|
||||||
|
case icsneo_msg_type_bus:
|
||||||
|
return "Bus";
|
||||||
|
// Don't default here so we can rely on the compiler to warn us about missing cases
|
||||||
|
};
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Unknown (" << (int)msg_type << ")";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
enum class Type : neomessagetype_t {
|
enum class Type : neomessagetype_t {
|
||||||
BusMessage = 0,
|
BusMessage = 0,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,8 @@ typedef enum _icsneo_error_t {
|
||||||
icsneo_error_transmit_messages_failed,
|
icsneo_error_transmit_messages_failed,
|
||||||
// Failed to copy string to buffer
|
// Failed to copy string to buffer
|
||||||
icsneo_error_string_copy_failed
|
icsneo_error_string_copy_failed
|
||||||
|
|
||||||
|
// NOTE: Any new values added here should be updated in icsneo_get_error_code
|
||||||
} _icsneo_error_t;
|
} _icsneo_error_t;
|
||||||
|
|
||||||
/** @brief Integer representation of _icsneo_error_t enum.
|
/** @brief Integer representation of _icsneo_error_t enum.
|
||||||
|
|
@ -343,6 +345,17 @@ ICSNEO_API icsneo_error_t icsneo_message_is_valid(icsneo_device_t* device, icsne
|
||||||
*/
|
*/
|
||||||
ICSNEO_API icsneo_error_t icsneo_message_get_type(icsneo_device_t* device, icsneo_message_t* message, icsneo_msg_type_t* msg_type);
|
ICSNEO_API icsneo_error_t icsneo_message_get_type(icsneo_device_t* device, icsneo_message_t* message, icsneo_msg_type_t* msg_type);
|
||||||
|
|
||||||
|
/** @brief Get the message type string for a icsneo_msg_bus_type_t.
|
||||||
|
*
|
||||||
|
* @param[in] icsneo_device_t* device The device to check against.
|
||||||
|
* @param[in] icsneo_message_t* message The message to check.
|
||||||
|
* @param[out] const char* value Pointer to a buffer to copy the description into. Null terminated.
|
||||||
|
* @param[in,out] uint32_t* value_length Size of the value buffer. Modified with the length of the description.
|
||||||
|
*
|
||||||
|
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||||
|
*/
|
||||||
|
ICSNEO_API icsneo_error_t icsneo_message_get_type_name(icsneo_msg_type_t msg_type, const char* value, uint32_t* value_length);
|
||||||
|
|
||||||
/** @brief Get the type of a bus message
|
/** @brief Get the type of a bus message
|
||||||
*
|
*
|
||||||
* @param[in] icsneo_device_t* device The device to check against.
|
* @param[in] icsneo_device_t* device The device to check against.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue