Skip to content

Commit

Permalink
Merge pull request #155 from electux/dev
Browse files Browse the repository at this point in the history
[microhil] Added microhil commander, updated docs
  • Loading branch information
vroncevic committed Oct 14, 2023
2 parents bfe9d5b + 2ebb4a3 commit 92036c5
Show file tree
Hide file tree
Showing 522 changed files with 2,816 additions and 6,830 deletions.
1 change: 1 addition & 0 deletions sw/microhildesk/build/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOURCES = \
../view/microhil_view_slots.cc \
../view/microhil_view_map.cc \
../view/microhil_view.cc \
../commander/microhil_commander.cc \
../view/home/microhil_view_home_utils.cc \
../view/home/microhil_view_home_signals.cc \
../view/home/microhil_view_home_slots.cc \
Expand Down
30 changes: 0 additions & 30 deletions sw/microhildesk/commander/microhil_channel_control.cc

This file was deleted.

46 changes: 0 additions & 46 deletions sw/microhildesk/commander/microhil_channel_control.h

This file was deleted.

30 changes: 0 additions & 30 deletions sw/microhildesk/commander/microhil_channel_id.cc

This file was deleted.

46 changes: 0 additions & 46 deletions sw/microhildesk/commander/microhil_channel_id.h

This file was deleted.

37 changes: 0 additions & 37 deletions sw/microhildesk/commander/microhil_channel_version.cc

This file was deleted.

46 changes: 0 additions & 46 deletions sw/microhildesk/commander/microhil_channel_version.h

This file was deleted.

114 changes: 114 additions & 0 deletions sw/microhildesk/commander/microhil_commander.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* -*- Mode: CC; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* microhil_commander.h
* Copyright (C) 2023 Vladimir Roncevic <elektron.ronca@gmail.com>
*
* microhildesk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* microhildesk is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "microhil_commander.h"

namespace
{
////////////////////////////////////////////////////////////////////////
/// MicroHIL command for getting HW id
constexpr const char kId[]{"<mh#ch#id#end>"};

////////////////////////////////////////////////////////////////////////
/// MicroHIL command for getting FW version
constexpr const char kVersion[]{"<mh#ch#version#end>"};

////////////////////////////////////////////////////////////////////////
/// MicroHIL channel control begin
constexpr const char kChannelBegin[]{"<mh#ch#"};

////////////////////////////////////////////////////////////////////////
/// MicroHIL all channels control begin
constexpr const char kChannelsBegin[]{"<mh#ch#all#"};

////////////////////////////////////////////////////////////////////////
/// MicroHIL hash
constexpr const char kHash[]{"#"};

////////////////////////////////////////////////////////////////////////
/// MicroHIL control end
constexpr const char kEnd[]{"#end>"};
} // namespace

MHCommander::MHCommander(SPtr<IMHCom> serial)
: m_serial{serial}
{
}

void MHCommander::executeCommand(const int id, const std::string &onoff)
{
switch (id)
{
case 0:
getId();
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
setChannel(id, onoff);
break;
case 9:
setAllChannel(onoff);
break;
case 10:
getVersion();
break;
default:;
}
}

void MHCommander::getId()
{
std::string command = kId;
const VecByte data(command.begin(), command.end());
m_serial->write(data);
}

void MHCommander::getVersion()
{
std::string command = kVersion;
const VecByte data(command.begin(), command.end());
m_serial->write(data);
}

void MHCommander::setChannel(const int id, const std::string &onoff)
{
std::string command;
command.append(kChannelBegin);
command.append(std::to_string(id));
command.append(kHash);
command.append(onoff);
command.append(kEnd);
const VecByte data(command.begin(), command.end());
m_serial->write(data);
}

void MHCommander::setAllChannel(const std::string &onoff)
{
std::string command;
command.append(kChannelsBegin);
command.append(onoff);
command.append(kEnd);
const VecByte data(command.begin(), command.end());
m_serial->write(data);
}

0 comments on commit 92036c5

Please sign in to comment.