Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Jun 6, 2024
2 parents 562b351 + 4b385b6 commit a47ec7f
Show file tree
Hide file tree
Showing 34 changed files with 1,888 additions and 1,163 deletions.
915 changes: 626 additions & 289 deletions Doxyfile

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ v1.11.0
-------
* Modbus::, ILC::ILCBusList classes. Communication code moved from ModbusBuffer
to FPGA class.
* Improved documentation.
* Public constants to explain meaning of the numbers
* mpuCommands redesign

v1.10.1
-------
Expand Down
121 changes: 78 additions & 43 deletions include/ILC/ILCBusList.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,54 @@

namespace ILC {

enum Mode { Standby = 0, Disabled = 1, Enabled = 2, FirmwareUpdate = 3, Fault = 4, ClearFaults = 5 };
enum Mode { Standby = 0, Disabled = 1, Enabled = 2, Bootloader = 3, Fault = 4, ClearFaults = 5 };

/**
* Handles basic ILC communication. Provides methods to run ILC functions and
* callback for responses.
* Handles basic @glos{ILC} communication. Provides methods to run @glos{ILC}
* functions and callback for responses.
*
* ILCs are on a bus identified by the bus number. The details how bus commands
* are transferred to FPGA and replies are receieved is left on the FPGA
* handling class. As transfer is ussually done through some @glos{FIFO}s, the
* number of busses is limited by number of target-host FIFOs in the FPGA.a
*/
class ILCBusList : public Modbus::BusList {
public:
/**
* Construct new bus list.
*
* @param bus FPGA ILC bus number.
*/
ILCBusList(uint8_t bus);

/**
* Destroy ILC bus instance.
*/
virtual ~ILCBusList();

/**
* Calls function 17 (0x11), ask for ILC identity.
* Return the FPGA bus ILCs operates on.
*
* @return FPGA ILC bus indentificator
*/
const uint8_t getBus() { return _bus; }

/**
* Calls function 17 (0x11), ask for @glos{ILC} identity.
*
* @param address ILC address
* @param address @glos{ICL} address
*/
void reportServerID(uint8_t address) { callFunction(address, 17, 835); }
void reportServerID(uint8_t address) { callFunction(address, ILC_CMD::SERVER_ID, 835); }

/**
* Calls function 18 (0x12), ask for ILC status.
* Calls function 18 (0x12), ask for @glos{ILC} status.
*
* @param address ILC address
* @param address @glos{ICL} address
*/
void reportServerStatus(uint8_t address) { callFunction(address, 18, 270); }
void reportServerStatus(uint8_t address) { callFunction(address, ILC_CMD::SERVER_STATUS, 270); }

/**
* Change ILC mode. Calls function 65 (0x41). Supported ILC modes are:
* Change @glos{ILC} mode. Calls function 65 (0x41). Supported @glos{ILC} modes are:
*
* Mode | Supported by | Description
* ---- | ------------ | ------------------------------------
Expand All @@ -69,27 +90,40 @@ class ILCBusList : public Modbus::BusList {
* where all is Electromechanical (Hard-Point), Pneumatic, Thermal and
* Hardpoint Monitoring ILC. HM is Hardpoint Monitoring.
*
* @param address ILC address
* @param mode new ILC mode - see above
* @param address @glos{ICL} address
* @param mode new @glos{ILC} mode - see above
*/
void changeILCMode(uint8_t address, uint16_t mode);

/**
* Set temporary ILC address. ILC must be address-less (attached to address
* 255). Can be used only if one ILC on a bus failed to read its address
* Set temporary @glos{ICL} address. @glos{ILC} must be address-less (attached to address
* 255). Can be used only if one @glos{ILC} on a bus failed to read its address
* from its network connection and therefore adopts the failure address
* 255.
*
* @param temporaryAddress new ILC address
* @param temporaryAddress new @glos{ICL} address
*/
void setTempILCAddress(uint8_t temporaryAddress) { callFunction(255, 72, 250, temporaryAddress); }
void setTempILCAddress(uint8_t temporaryAddress) {
callFunction(255, ILC_CMD::SET_TEMP_ADDRESS, 250, temporaryAddress);
}

/**
* Reset ILC. Calls function 107 (0x6b).
*
* @param address ILC address
* @param address @glos{ICL} address
*/
void resetServer(uint8_t address) { callFunction(address, ILC_CMD::RESET_SERVER, 86840); }

/**
* ILC commands numbers. See LTS-346 and LTS-646 for details.
*/
void resetServer(uint8_t address) { callFunction(address, 107, 86840); }
enum ILC_CMD {
SERVER_ID = 17,
SERVER_STATUS = 18,
CHANGE_MODE = 65,
SET_TEMP_ADDRESS = 72,
RESET_SERVER = 107
};

protected:
/**
Expand All @@ -102,7 +136,7 @@ class ILCBusList : public Modbus::BusList {
* @param counter broadcast counter. ModBus provides method to retrieve this
* in unicast function to verify the broadcast was received and processed
* @param data function parameters. Usually device's bus ID indexed array
* of values to pass to the devices
_
*/
void broadcastFunction(uint8_t address, uint8_t func, uint32_t delay, uint8_t counter,
std::vector<uint8_t> data);
Expand All @@ -124,7 +158,7 @@ class ILCBusList : public Modbus::BusList {
/**
* Return string with current mode description.
*
* @param mode ILC mode, as returned by function 18.
* @param mode @glos{ILC} mode, as returned by function 18.
*
* @return status description (enabled, standby,..).
*/
Expand All @@ -142,20 +176,20 @@ class ILCBusList : public Modbus::BusList {
enum ILCStatus { MajorFault = 0x0001, MinorFault = 0x0002, FaultOverride = 0x0008 };

/**
* Returns last know mode (state) of the ILC at the address.
* Returns last know mode (state) of the @glos{ILC} at the address.
*
* @param address ILC node address
* @param address @glos{ILC} node address
*
* @return last know ILC state
* @return last know @glos{ILC} state
*
* @throw std::out_of_range when ILC mode is not known
* @throw std::out_of_range when @glos{ILC} mode is not known
*/
uint8_t getLastMode(uint8_t address) { return _lastMode.at(address); }

/**
* Return ILC fault textual description.
* Return @glos{ILC} fault textual description.
*
* @param fault ILC faults returned by function 18.
* @param fault @glos{ILC} faults returned by function 18.
*
* @return vector of strings with fault description
*/
Expand Down Expand Up @@ -239,15 +273,15 @@ class ILCBusList : public Modbus::BusList {
* </tr>
* </table>
*
* @param address ILC address
* @param uniqueID ILC unigue ID
* @param ilcAppType ILC App (Firmware) Type. See Types table for values
* @param networkNodeType ILC Network Node (TEDS) Type. See Types table for values
* @param ilcSelectedOptions ILC Selected Options. See Selected Options table for values
* @param networkNodeOptions ILC Network Node (TEDS) Options. See Selected Options table for values
* @param address @glos{ICL} address
* @param uniqueID @glos{ILC} unigue ID
* @param ilcAppType @glos{ILC} App (Firmware) Type. See Types table for values
* @param networkNodeType @glos{ILC} Network Node (TEDS) Type. See Types table for values
* @param ilcSelectedOptions @glos{ILC} Selected Options. See Selected Options table for values
* @param networkNodeOptions @glos{ILC} Network Node (TEDS) Options. See Selected Options table for values
* @param majorRev Firmware major revision number
* @param minorRev Firmware minor revision number
* @param firmwareName ASCII name string for ILC firmware
* @param firmwareName ASCII name string for @glos{ILC} firmware
*/
virtual void processServerID(uint8_t address, uint64_t uniqueID, uint8_t ilcAppType,
uint8_t networkNodeType, uint8_t ilcSelectedOptions,
Expand All @@ -257,18 +291,18 @@ class ILCBusList : public Modbus::BusList {
/**
* Callback for server status reply.
*
* @param address ILC address
* @param mode ILC mode
* @param status ILC status
* @param faults ILC faults
* @param address @glos{ICL} address
* @param mode @glos{ILC{ mode
* @param status @glos{ILC} status
* @param faults @glos{ILC} faults
*/
virtual void processServerStatus(uint8_t address, uint8_t mode, uint16_t status, uint16_t faults) = 0;

/**
* Callback for change ILC mode reply.
* Callback for change @glos{ILC} mode reply.
*
* @param address ILC address
* @param mode new (current) ILC mode
* @param address @glos{ICL} address
* @param mode new (current) @glos{ILC} mode
*/
virtual void processChangeILCMode(uint8_t address, uint16_t mode) = 0;

Expand All @@ -283,13 +317,14 @@ class ILCBusList : public Modbus::BusList {
/**
* Callback for reply from server reset.
*
* @param address ILC address
* @param address @glos{ICL} address
*/
virtual void processResetServer(uint8_t address) = 0;

private:
// last know ILC mode
std::map<uint8_t, uint8_t> _lastMode;
const int _bus;

std::map<uint8_t, uint8_t> _lastMode; ///< last know @glos{ILC} mode
uint8_t _broadcastCounter = 0;
};

Expand Down
67 changes: 59 additions & 8 deletions include/Modbus/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@
#include <stdexcept>
#include <vector>

/***
* 24 bit type integer.This is used to pass some parameters to ILC calls.
namespace Modbus {

/**
* 24 bit (3 bytes) integer. This is used to pass some parameters to ILC calls.
*/
class int24_t {
public:
int32_t value;
int32_t value; ///< value stored in the class

/**
* Construct int24_t value.
*
* @param v integer value
*/
int24_t(int32_t v) { value = v; }
};

namespace Modbus {

/**
* Thrown when ModBus error response is received.
*/
Expand All @@ -61,7 +66,16 @@ class Exception : public std::runtime_error {
*/
class Buffer : public std::vector<uint8_t> {
public:
/**
* Construct an empty buffer.
*/
Buffer();

/**
* Fill newly constructed buffer with data.
*
* @param data Buffer's data
*/
Buffer(std::vector<uint8_t> data) : std::vector<uint8_t>(data) {}

/**
Expand All @@ -70,12 +84,16 @@ class Buffer : public std::vector<uint8_t> {
*
* @param address ModBus address on subnet
* @param func ModBus function to call
* @param params ModBus command arguments.
*/
template <typename... dt>
Buffer(uint8_t address, uint8_t func, const dt&... params) {
callFunction(address, func, params...);
}

/**
* Destruct buffer instance.
*/
virtual ~Buffer();

/**
Expand All @@ -89,6 +107,13 @@ class Buffer : public std::vector<uint8_t> {
template <typename dt>
void write(dt data);

template <typename vt>
inline void writeVector(std::vector<vt> data) {
for (auto d : data) {
write<vt>(d);
}
}

/**
* Writes 24bit signed integer.
*
Expand All @@ -111,7 +136,20 @@ class Buffer : public std::vector<uint8_t> {
*/
void writeCRC();

/**
* Return address stored in the Modbus buffer. Essentially returns the
* first byte.
*
* @return Buffer command address
*/
uint8_t address() { return at(0); }

/**
* Return function call stored in the Modbus buffer. Essentially returns
* the second byte.
*
* @return Function call code
*/
uint8_t func() { return at(1); }

/**
Expand Down Expand Up @@ -160,11 +198,21 @@ class Buffer : public std::vector<uint8_t> {
}
};

/**
* Write 8 bit signed integer to the end of the buffer.
*
* @param data 8 bit signed integer to write
*/
template <>
inline void Buffer::write(int8_t data) {
pushBuffer(reinterpret_cast<uint8_t*>(&data), 1);
}

/**
* Write 16 bit signed integer to the end of the buffer.
*
* @param data 16 bit signed integer to write
*/
template <>
inline void Buffer::write(int16_t data) {
int16_t d = htons(data);
Expand Down Expand Up @@ -213,9 +261,12 @@ inline void Buffer::write(float data) {

template <>
inline void Buffer::write(std::vector<uint8_t> data) {
for (auto d : data) {
write<uint8_t>(d);
}
writeVector<uint8_t>(data);
}

template <>
inline void Buffer::write(std::vector<uint16_t> data) {
writeVector<uint16_t>(data);
}

} // namespace Modbus
Expand Down
Loading

0 comments on commit a47ec7f

Please sign in to comment.