mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Device: Add network mutex support
This commit is contained in:
committed by
Kyle Schwarz
parent
bf311ebe30
commit
c2f1022858
@@ -0,0 +1,21 @@
|
||||
#ifndef CLIENT_ID_MESSAGE_H_
|
||||
#define CLIENT_ID_MESSAGE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class ClientIdMessage : public Message {
|
||||
public:
|
||||
ClientIdMessage() : Message(Message::Type::ClientId) {}
|
||||
static std::shared_ptr<ClientIdMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream);
|
||||
|
||||
std::optional<uint32_t> clientId;
|
||||
};
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
GPTPStatus = 0x8013,
|
||||
EthernetStatus = 0x8014,
|
||||
LogData = 0x8015,
|
||||
NetworkMutex = 0x8016,
|
||||
ClientId = 0x8017,
|
||||
};
|
||||
|
||||
Message(Type t) : type(t) {}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef __NETWORKMUTEXMESSAGE_H_
|
||||
#define __NETWORKMUTEXMESSAGE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/extendedresponsemessage.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
enum class NetworkMutexType : uint8_t {
|
||||
Shared = 0,
|
||||
TxExclusive = 1,
|
||||
ExternalExclusive = 2,
|
||||
FullyExclusive = 3,
|
||||
};
|
||||
|
||||
enum class NetworkMutexEvent : uint8_t {
|
||||
Released = 0,
|
||||
Expired = 1,
|
||||
Preempted = 2,
|
||||
Queued = 3,
|
||||
Acquired = 4,
|
||||
};
|
||||
|
||||
class NetworkMutexMessage : public Message
|
||||
{
|
||||
public:
|
||||
NetworkMutexMessage() : Message(Message::Type::NetworkMutex) {}
|
||||
|
||||
static std::shared_ptr<NetworkMutexMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream);
|
||||
static std::vector<uint8_t> EncodeArgumentsForLock(uint32_t client_id, NetworkMutexType type, uint32_t priority, uint32_t ttlMs, const std::set<Network::NetID>& networks, const device_eventhandler_t& report);
|
||||
static std::vector<uint8_t> EncodeArgumentsForLockAll(uint32_t client_id, NetworkMutexType type, uint32_t priority, uint32_t ttlMs, const device_eventhandler_t& report);
|
||||
static std::vector<uint8_t> EncodeArgumentsForUnlock(uint32_t client_id, const std::set<Network::NetID>& networks, const device_eventhandler_t& report);
|
||||
static std::vector<uint8_t> EncodeArgumentsForUnlockAll(uint32_t client_id, const device_eventhandler_t& report);
|
||||
static std::vector<uint8_t> EncodeArgumentsForStatus(Network::NetID network, const device_eventhandler_t& report);
|
||||
|
||||
static const char* GetNetworkMutexTypeString(NetworkMutexType type) {
|
||||
switch(type) {
|
||||
case icsneo::NetworkMutexType::Shared:
|
||||
return "Shared";
|
||||
case icsneo::NetworkMutexType::TxExclusive:
|
||||
return "TxExclusive";
|
||||
case icsneo::NetworkMutexType::ExternalExclusive:
|
||||
return "ExternalExclusive";
|
||||
case icsneo::NetworkMutexType::FullyExclusive:
|
||||
return "FullyExclusive";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static const char* GetNetworkMutexEventString(NetworkMutexEvent event) {
|
||||
switch(event) {
|
||||
case icsneo::NetworkMutexEvent::Acquired:
|
||||
return "Acquired";
|
||||
case icsneo::NetworkMutexEvent::Released:
|
||||
return "Released";
|
||||
case icsneo::NetworkMutexEvent::Preempted:
|
||||
return "Preempted";
|
||||
case icsneo::NetworkMutexEvent::Expired:
|
||||
return "Expired";
|
||||
case icsneo::NetworkMutexEvent::Queued:
|
||||
return "Queued";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<uint32_t> owner_id;
|
||||
std::optional<NetworkMutexType> type;
|
||||
std::optional<uint32_t> priority;
|
||||
std::optional<uint32_t> ttlMs;
|
||||
std::set<Network::NetID> networks;
|
||||
std::optional<NetworkMutexEvent> event;
|
||||
};
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef TRANSMIT_MESSAGE_H_
|
||||
#define TRANSMIT_MESSAGE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct TransmitMessage {
|
||||
static std::vector<uint8_t> EncodeFromMessage(std::shared_ptr<Frame> message, uint32_t client_id, const device_eventhandler_t& report);
|
||||
|
||||
constexpr static size_t messageOptionsOffset = 0;
|
||||
constexpr static size_t messageOptionsSize = 20; // todo determine max
|
||||
constexpr static size_t messageCommonHeaderOffset = messageOptionsOffset + messageOptionsSize;
|
||||
constexpr static size_t messageCommonHeaderSize = 28; // CoreminiMsgExtendedHdr
|
||||
#pragma pack(push,1)
|
||||
struct
|
||||
{
|
||||
uint32_t clientId;
|
||||
uint32_t networkId;
|
||||
uint32_t reserved[3]; // set to 0
|
||||
} options;
|
||||
uint8_t commonHeader[messageCommonHeaderSize];
|
||||
#pragma pack(pop)
|
||||
};
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // TRANSMIT_MESSAGE_H_
|
||||
Reference in New Issue
Block a user