/* * NetX.hh * * Created on: 30 ����. 2021 �. * Author: titov */ #ifndef UMLIBRARY_DRIVER_NETX_NETX_HH_ #define UMLIBRARY_DRIVER_NETX_NETX_HH_ #include #include #include #include #include #include #include #include #include "../../peripheral/ProtectedMemory.hh" #include "../../peripheral/IMemoryAccess.hh" #include "../../systemic/IProcess.hh" #include "../../communication/IMessageServer.hh" #include "../../communication/format/BinaryDataPublisher.hh" #include "../../communication/format/BinaryDataCollector.hh" #include "lowcifx/HilscherDualPortMemoryMap.hh" #include "lowcifx/HilscherPacket.hh" namespace driver { namespace netx { class NetX { public: NetX( std::pair name, std::pair dpm ); static bool isReady( peripheral::protected_char * dpm_origin ); bool isReady() const; bool isError() const; void reset(); class CommunicationChannel { public: enum ChannelId { CH0, CH1, CH2, CH3 }; typedef uint32_t ErrorCode; struct Info { uint16_t id; //!< uint16_t type; //!, std::pmr::polymorphic_allocator< std::pair > > Servers; HandshakeData & receive; HandshakeData & transmit; Servers servers; enum State { RequestRegisterApplication, WaitRegisterApplication, ConfirmationRegisterApplication, AcceptRegisterApplication, WaitReceive, ReadHeader, ReadData, AcceptReceive, RequestServer, WaitSend, WriteHeader, WriteData, AcceptSend, Stop, } state; bool application_registred; struct Packet { packet::HIL_PACKET_HEADER header; std::vector< char, std::pmr::polymorphic_allocator > data; Packet( std::pmr::memory_resource * buffer ); } request, response; struct Client : public communication::IMessageClient { Client( std::vector< char, std::pmr::polymorphic_allocator > & data ); std::vector< char, std::pmr::polymorphic_allocator > & data; bool response( const char * data, std::size_t size ); bool flag = false; }; public: MailboxHandler( HandshakeData & receive, HandshakeData & transmit, std::pmr::memory_resource * description, std::pmr::memory_resource * buffer ); void attach(communication::IMessageServer * server, ServerId id ); void start(); bool stop(); void process(); const bool & enable() const; } mailbox_handler; friend NetX; peripheral::protected_char * handshake; peripheral::protected_char * channel; bool board_ready_status; mutable std::pair< uint32_t, bool> cos_cache; Info self_info; void setBoardReadyStatus( bool ready_status ); void updateAppCos( uint32_t set, uint32_t clear = 0 ); uint32_t readNetXCos() const; }; CommunicationChannel * open( CommunicationChannel::ChannelId id, std::pmr::memory_resource * allocator, std::pmr::memory_resource * description, std::pmr::memory_resource * buffer ); private: typedef uint32_t ErrorCode; typedef uint32_t ServerId; static const std::size_t NETX_COMM_CHANNELS_NUM = 4; static const std::size_t NETX_APP_CHANNELS_NUM = 2; static const uint32_t NETX_DPM_COOKIE = 0x5874656E; struct DpmLayout { struct { std::pair channel; std::pair handshake; std::pair mailbox_send; std::pair mailbox_receive; } system; struct { std::pair channel; } handshake; struct { std::pair channel; std::pair handshake; std::pair cyclic_in; std::pair cyclic_out; std::pair mailbox_send; std::pair mailbox_receive; uint16_t type; uint16_t protocol; uint16_t conformance; } communications[NETX_COMM_CHANNELS_NUM]; struct { std::pair channel; std::pair handshake; } applications[NETX_APP_CHANNELS_NUM]; } layout; struct Dpm { peripheral::protected_char * base; std::size_t size; } dpm; struct Info { uint16_t dip_address; //!< uint16_t device_class; //!< uint32_t device_number; //!< uint32_t serial_number; //!< } device_info; struct Channel { enum Id { System, Handshake, CommunicationAlfa, CommunicationBeta, CommunicationGamma, CommunicationDelta, ApplicationZero, ApplicationOne }; static const std::size_t num_channels = 8; static peripheral::protected_char * handshake( peripheral::protected_char * base, Id id ); static peripheral::protected_char * status( peripheral::protected_char * base, Id id ); }; mutable bool ready_status; CommunicationChannel * communication_channels[NETX_COMM_CHANNELS_NUM]; mutable ErrorCode errors[Channel::num_channels]; void resetSystem(); static bool checkDpmCookie( peripheral::protected_char * dpm_origin ); bool hasDefaultDpmLayout() const; bool isChannelReady( Channel::Id channel ) const; bool isChannelRunning( Channel::Id channel ) const; bool isChannelCommunicating( Channel::Id channel ) const; void notifyChannels( bool new_ready_status ) const; std::pair checkChannelError( Channel::Id channel ) const; }; } /* namespace netx */ } /* namespace driver */ #endif /* UMLIBRARY_DRIVER_NETX_NETX_HH_ */