Skip to content

Commit

Permalink
Add some E1.33 helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Jan 2, 2024
1 parent 7c44c8b commit eb97fb4
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/ola/e133/E133Helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* E133Helper.h
* Various misc E1.33 functions.
* Copyright (C) 2024 Peter Newman
*/

#ifndef INCLUDE_OLA_E133_E133HELPER_H_
#define INCLUDE_OLA_E133_E133HELPER_H_

#include <stdint.h>
#include <ola/e133/E133Enums.h>
#include <string>

namespace ola {
namespace e133 {

bool IntToRPTClientType(uint8_t input,
ola::e133::E133RPTClientTypeCode *client_type);
std::string RPTClientTypeToString(uint8_t type);
} // namespace e133
} // namespace ola
#endif // INCLUDE_OLA_E133_E133HELPER_H_
1 change: 1 addition & 0 deletions include/ola/e133/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if INSTALL_E133
olae133include_HEADERS = \
include/ola/e133/DeviceManager.h \
include/ola/e133/E133Enums.h \
include/ola/e133/E133Helper.h \
include/ola/e133/E133Receiver.h \
include/ola/e133/E133StatusHelper.h \
include/ola/e133/E133URLParser.h \
Expand Down
73 changes: 73 additions & 0 deletions tools/e133/E133Helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* E133Helper.cpp
* Various misc E1.33 functions.
* Copyright (C) 2024 Peter Newman
*
* At some point we may want to localize this file.
*/

#include <sstream>
#include <string>
#include <vector>
#include "ola/e133/E133Enums.h"
#include "ola/e133/E133Helper.h"
#include "ola/StringUtils.h"

namespace ola {
namespace e133 {

using std::ostringstream;
using std::string;
using std::vector;


/**
* Verify that the int is a valid E1.33 RPT Client Type.
*/
bool IntToRPTClientType(uint8_t input,
ola::e133::E133RPTClientTypeCode *client_type) {
switch (input) {
case ola::e133::RPT_CLIENT_TYPE_DEVICE:
*client_type = ola::e133::RPT_CLIENT_TYPE_DEVICE;
return true;
case ola::e133::RPT_CLIENT_TYPE_CONTROLLER:
*client_type = ola::e133::RPT_CLIENT_TYPE_CONTROLLER;
return true;
default:
return false;
}
}


/**
* Convert a uint8_t representing an RPT client type to a human-readable string.
* @param type the RPT client type value
*/
string RPTClientTypeToString(uint8_t type) {
switch (type) {
case RPT_CLIENT_TYPE_DEVICE:
return "Device";
case RPT_CLIENT_TYPE_CONTROLLER:
return "Controller";
default:
ostringstream str;
str << "Unknown, was " << static_cast<int>(type);
return str.str();
}
}
} // namespace e133
} // namespace ola
1 change: 1 addition & 0 deletions tools/e133/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ endif
tools_e133_libolae133common_la_SOURCES = \
tools/e133/E133HealthCheckedConnection.cpp \
tools/e133/E133HealthCheckedConnection.h \
tools/e133/E133Helper.cpp \
tools/e133/E133Receiver.cpp \
tools/e133/E133StatusHelper.cpp \
tools/e133/MessageBuilder.cpp
Expand Down

0 comments on commit eb97fb4

Please sign in to comment.