Skip to content

Commit

Permalink
Add get versions command support
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3154 committed Nov 18, 2023
1 parent ccbfd86 commit 585462c
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 69 deletions.
64 changes: 57 additions & 7 deletions include/ServerMainComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class ServerMainComponent : public juce::Component
, public isobus::VirtualTerminalServer
, public Timer
, public ApplicationCommandTarget
, public MenuBarModel
{
public:
ServerMainComponent(std::shared_ptr<isobus::InternalControlFunction> serverControlFunction);
Expand All @@ -32,7 +34,7 @@ class ServerMainComponent : public juce::Component
std::uint8_t &numberOfRanges,
std::vector<std::uint8_t> &wideCharRangeArray) override;

std::vector<std::uint8_t> get_versions(isobus::NAME clientNAME) override;
std::vector<std::array<std::uint8_t, 7>> get_versions(isobus::NAME clientNAME) override;
std::vector<std::uint8_t> get_supported_objects() const override;

/// @brief This function is called when the client wants the server to load a previously stored object pool.
Expand All @@ -41,7 +43,7 @@ class ServerMainComponent : public juce::Component
/// @param[in] versionLabel The object pool version to load for the given client NAME
/// @param[in] clientNAME The client requesting the object pool
/// @returns The requested object pool associated with the version label.
virtual std::vector<std::uint8_t> load_version(const std::vector<std::uint8_t> &versionLabel, isobus::NAME clientNAME) override;
std::vector<std::uint8_t> load_version(const std::vector<std::uint8_t> &versionLabel, isobus::NAME clientNAME) override;

/// @brief This function is called when the client wants the server to save an object pool
/// to the VT's non-volatile memory.
Expand All @@ -52,35 +54,83 @@ class ServerMainComponent : public juce::Component
/// @param[in] versionLabel The object pool version to save for the given client NAME
/// @param[in] clientNAME The client requesting the object pool
/// @returns The requested object pool associated with the version label.
virtual bool save_version(const std::vector<std::uint8_t> &objectPool, const std::vector<std::uint8_t> &versionLabel, isobus::NAME clientNAME) override;
bool save_version(const std::vector<std::uint8_t> &objectPool, const std::vector<std::uint8_t> &versionLabel, isobus::NAME clientNAME) override;

/// @brief This function is called when the client wants the server to delete a stored object pool.
/// All object pool files matching the specified version label should then be deleted from the VT's
/// non-volatile storage.
/// @param[in] versionLabel The version label for the object pool(s) to delete
/// @param[in] clientNAME The NAME of the client that is requesting deletion
/// @returns True if the version was deleted from VT non-volatile storage, otherwise false.
bool delete_version(const std::vector<std::uint8_t> &versionLabel, isobus::NAME clientNAME) override;

/// @brief This function is called when the client wants the server to delete ALL stored object pools associated to it's NAME.
/// All object pool files matching the specified client NAME should then be deleted from the VT's
/// non-volatile storage.
/// @param[in] clientNAME The NAME of the client that is requesting deletion
/// @returns True if all relevant object pools were deleted from VT non-volatile storage, otherwise false.
bool delete_all_versions(isobus::NAME clientNAME) override;

void timerCallback() override;

void paint(juce::Graphics &g) override;
void resized() override;

ApplicationCommandTarget *getNextCommandTarget() override;
void getAllCommands(juce::Array<juce::CommandID> &allCommands) override;
void getCommandInfo(juce::CommandID commandID, ApplicationCommandInfo &result) override;
bool perform(const InvocationInfo &info) override;
StringArray getMenuBarNames() override;
PopupMenu getMenuForIndex(int, const juce::String &) override;
void menuItemSelected(int, int) override;

std::shared_ptr<isobus::ControlFunction> get_client_control_function_for_working_set(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet) const;

void change_selected_working_set(std::uint8_t index);

void repaint_on_next_update();

private:
// Your private member variables go here...
enum class CommandIDs : int
{
NoCommand = 0, /// 0 Is an invalid command ID
About,
ConfigureLanguageCommand,
ConfigureReportedVersion
};

class LanguageCommandConfigClosed
{
public:
void operator()(int result) const noexcept;
ServerMainComponent &mParent;

private:
};
friend class LanguageCommandConfigClosed;

std::size_t number_of_iop_files_in_directory(std::filesystem::path path);

void on_change_active_mask_callback(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> affectedWorkingSet, std::uint16_t workingSet, std::uint16_t newMask);
void on_change_numeric_value_callback(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> affectedWorkingSet, std::uint16_t objectID, std::uint32_t value);
void on_change_string_value_callback(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> affectedWorkingSet, std::uint16_t objectID, std::string value);
void on_change_child_position_callback(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> affectedWorkingSet, std::uint16_t parentObjectID, std::uint16_t objectID, std::uint16_t newX, std::uint16_t newY);
void repaint_data_and_soft_key_mask();
void check_load_settings();
void save_settings();

const std::string ISO_DATA_PATH = "iso_data";

juce::ApplicationCommandManager mCommandManager;
WorkingSetSelectorComponent workingSetSelector;
DataMaskRenderAreaComponent dataMaskRenderer;
SoftKeyMaskRenderAreaComponent softKeyMaskRenderer;
MenuBarComponent menuBar;
LoggerComponent logger;
Viewport loggerViewport;
SoundPlayer mSoundPlayer;
AudioDeviceManager mAudioDeviceManager;
std::unique_ptr<AlertWindow> popupMenu;
std::uint8_t numberOfPoolsToRender = 0;
VTVersion versionToReport = VTVersion::Version5;
bool needToRepaint = false;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ServerMainComponent)
};
6 changes: 5 additions & 1 deletion include/WorkingSetSelectorComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

#include <vector>

class ServerMainComponent;

class WorkingSetSelectorComponent : public Component
{
public:
WorkingSetSelectorComponent();
explicit WorkingSetSelectorComponent(ServerMainComponent &server);

void add_working_set_to_draw(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);
void remove_working_set(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void paint(Graphics &g) override;
void resized() override;
void mouseUp(const MouseEvent &event) override;

void redraw();

Expand All @@ -36,6 +39,7 @@ class WorkingSetSelectorComponent : public Component
std::vector<std::shared_ptr<Component>> childComponents;
};
std::vector<SELECTOR_CHILD_OBJECTS_STRUCT> children;
ServerMainComponent &parentServer;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WorkingSetSelectorComponent);
};
Expand Down
4 changes: 2 additions & 2 deletions src/OutputRectangleComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void OutputRectangleComponent::paint(Graphics &g)

case isobus::FillAttributes::FillType::FillWithLineColor:
{
for (std::uint16_t i = 0; i < get_number_children(); i++)
for (std::uint16_t j = 0; j < get_number_children(); j++)
{
auto childLineAttributes = get_object_by_id(get_child_id(i));
auto childLineAttributes = get_object_by_id(get_child_id(j));

if ((nullptr != childLineAttributes) && (isobus::VirtualTerminalObjectType::LineAttributes == childLineAttributes->get_object_type()))
{
Expand Down
Loading

0 comments on commit 585462c

Please sign in to comment.