Line data Source code
1 : #ifndef FELIX_FROMHOST_ENCODER_H_ 2 : #define FELIX_FROMHOST_ENCODER_H_ 3 : 4 : #include "device.hpp" 5 : 6 : /** 7 : * Encodes network messages into FromHost blocks. 8 : * */ 9 : class Encoder { 10 : 11 : public: 12 : 13 : /** 14 : * @brief Encoder default contructor. 15 : */ 16 5 : Encoder() = default; 17 : 18 : /** 19 : * @brief Sets the data format of the encoder. 20 : * @param format FromHost data format supported by firmware. 21 : */ 22 : void set_data_format(int format); 23 : 24 : /** 25 : * @brief set address and size of buffer where encoded messages are written. 26 : * @param dest_start start address of output buffer. 27 : * @param dest_size size of output buffer. 28 : */ 29 : void set_destination_parameters(uint8_t* dest_start, uint32_t dest_size); 30 : 31 : /** 32 : * @param size input message size. 33 : * @return size of encoded message. 34 : */ 35 : [[nodiscard]] size_t compute_max_msg_occupancy(size_t size) const; 36 : 37 : /** 38 : * @param size input message size. 39 : * @return number of full FromHost blocks. 40 : */ 41 : [[nodiscard]] int compute_full_blocks(size_t size) const; 42 : 43 : /** 44 : * @param size input message size. 45 : * @return number of bytes in the last block of the encoded message. 46 : */ 47 : [[nodiscard]] size_t compute_final_bytes(size_t size) const; 48 : 49 : /** 50 : * @return FromHost block size. 51 : */ 52 20499 : [[nodiscard]] size_t get_block_size() const {return m_block_bytes;}; 53 : 54 : /** 55 : * @brief encodes the input and write it in the output buffer. 56 : * @param elink of the incoming message. 57 : * @param source address of the incoming message. 58 : * @param size of the incoming message. 59 : * @param dest_offset current write pointer offset in the output buffer. 60 : * @return new write pointer as byte index. 61 : */ 62 : [[nodiscard]] uint64_t encode_and_write_msg(uint64_t elink, const uint8_t *source, size_t size, uint32_t dest_offset); 63 : 64 : private: 65 : uint8_t* m_dest_start{nullptr}; 66 : uint32_t m_dest_size{0}; 67 : 68 : //Default: FROMHOST_FORMAT_HDR32_PACKET32_8B (rm- >=5.1 PCIe Gen3) 69 : int m_header_size{4}; 70 : int m_block_bytes{32}; 71 : int m_payload_bytes{28}; 72 : int m_length_mask{TOFLX_LENGTH_MASK_HDR32_8B}; 73 : int m_elink_shift{TOFLX_ELINK_SHIFT_HDR32_8B}; 74 : }; 75 : 76 : #endif /* FELIX_FROMHOST_ENCODER_H_ */