First bits for an GSM emulator implementation
Not clear yet if we will use this or not.
This commit is contained in:
parent
7dc6f8d0bc
commit
fb4f424325
12 changed files with 454 additions and 2 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
#include "anbox/support/sensors_message_processor.h"
|
#include "anbox/support/sensors_message_processor.h"
|
||||||
#include "anbox/support/camera_message_processor.h"
|
#include "anbox/support/camera_message_processor.h"
|
||||||
#include "anbox/support/fingerprint_message_processor.h"
|
#include "anbox/support/fingerprint_message_processor.h"
|
||||||
|
#include "anbox/support/gsm_message_processor.h"
|
||||||
|
|
||||||
namespace ba = boost::asio;
|
namespace ba = boost::asio;
|
||||||
|
|
||||||
|
|
@ -56,8 +57,6 @@ void QemuPipeConnectionCreator::create_connection_for(
|
||||||
messenger, messenger, next_id(), connections_, processor);
|
messenger, messenger, next_id(), connections_, processor);
|
||||||
connections_->add(connection);
|
connections_->add(connection);
|
||||||
connection->read_next_message();
|
connection->read_next_message();
|
||||||
|
|
||||||
DEBUG("id %i", connection->id());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QemuPipeConnectionCreator::client_type QemuPipeConnectionCreator::identify_client(
|
QemuPipeConnectionCreator::client_type QemuPipeConnectionCreator::identify_client(
|
||||||
|
|
@ -94,6 +93,8 @@ QemuPipeConnectionCreator::client_type QemuPipeConnectionCreator::identify_clien
|
||||||
return client_type::qemud_camera;
|
return client_type::qemud_camera;
|
||||||
else if (utils::string_starts_with(identifier_and_args, "pipe:qemud:fingerprintlisten"))
|
else if (utils::string_starts_with(identifier_and_args, "pipe:qemud:fingerprintlisten"))
|
||||||
return client_type::qemud_fingerprint;
|
return client_type::qemud_fingerprint;
|
||||||
|
else if (utils::string_starts_with(identifier_and_args, "pipe:qemud:gsm"))
|
||||||
|
return client_type::qemud_gsm;
|
||||||
|
|
||||||
return client_type::invalid;
|
return client_type::invalid;
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +112,8 @@ std::shared_ptr<MessageProcessor> QemuPipeConnectionCreator::create_processor(co
|
||||||
return std::make_shared<support::CameraMessageProcessor>(messenger);
|
return std::make_shared<support::CameraMessageProcessor>(messenger);
|
||||||
else if (type == client_type::qemud_fingerprint)
|
else if (type == client_type::qemud_fingerprint)
|
||||||
return std::make_shared<support::FingerprintMessageProcessor>(messenger);
|
return std::make_shared<support::FingerprintMessageProcessor>(messenger);
|
||||||
|
else if (type == client_type::qemud_gsm)
|
||||||
|
return std::make_shared<support::GsmMessageProcessor>(messenger);
|
||||||
|
|
||||||
return std::make_shared<support::NullMessageProcessor>();
|
return std::make_shared<support::NullMessageProcessor>();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ public:
|
||||||
qemud_sensors,
|
qemud_sensors,
|
||||||
qemud_camera,
|
qemud_camera,
|
||||||
qemud_fingerprint,
|
qemud_fingerprint,
|
||||||
|
qemud_gsm,
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
74
src/anbox/support/at_parser.cpp
Normal file
74
src/anbox/support/at_parser.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "anbox/support/at_parser.h"
|
||||||
|
#include "anbox/utils.h"
|
||||||
|
#include "anbox/logger.h"
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace support {
|
||||||
|
AtParser::AtParser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtParser::register_command(const std::string &command, CommandHandler handler) {
|
||||||
|
handlers_.insert({ command, handler });
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtParser::process_data(std::vector<std::uint8_t> &data) {
|
||||||
|
size_t bytes_processed = 0;
|
||||||
|
for (size_t pos = 0; pos < data.size(); ) {
|
||||||
|
const auto byte = data.at(pos);
|
||||||
|
if (byte == '\n' || byte == '\r') {
|
||||||
|
std::string command;
|
||||||
|
command.insert(0, reinterpret_cast<const char*>(data.data()) + bytes_processed, pos - bytes_processed);
|
||||||
|
bytes_processed += (pos - bytes_processed) + 1;
|
||||||
|
processs_command(command);
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.erase(data.begin(), data.begin() + bytes_processed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtParser::processs_command(const std::string &command) {
|
||||||
|
if (!utils::string_starts_with(command, "AT")) {
|
||||||
|
WARNING("Invalid AT command: '%s'", command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip AT prefix from command
|
||||||
|
auto real_command = command.substr(2, command.length() - 2);
|
||||||
|
|
||||||
|
DEBUG("command: %s", real_command);
|
||||||
|
|
||||||
|
CommandHandler handler = nullptr;
|
||||||
|
for (const auto &iter : handlers_) {
|
||||||
|
if (utils::string_starts_with(real_command, iter.first)) {
|
||||||
|
handler = iter.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handler) {
|
||||||
|
WARNING("No handler for command '%s' available", real_command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handler(real_command);
|
||||||
|
}
|
||||||
|
} // namespace support
|
||||||
|
} // namespace anbox
|
||||||
48
src/anbox/support/at_parser.h
Normal file
48
src/anbox/support/at_parser.h
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANBOX_SUPPORT_AT_PARSER_H_
|
||||||
|
#define ANBOX_SUPPORT_AT_PARSER_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "anbox/do_not_copy_or_move.h"
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace support {
|
||||||
|
class AtParser {
|
||||||
|
public:
|
||||||
|
typedef std::function<void(const std::string&)> CommandHandler;
|
||||||
|
|
||||||
|
AtParser();
|
||||||
|
|
||||||
|
void register_command(const std::string &command, CommandHandler handler);
|
||||||
|
|
||||||
|
void process_data(std::vector<std::uint8_t> &data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void processs_command(const std::string &command);
|
||||||
|
|
||||||
|
std::map<std::string,CommandHandler> handlers_;
|
||||||
|
};
|
||||||
|
} // namespace support
|
||||||
|
} // namespace anbox
|
||||||
|
|
||||||
|
#endif
|
||||||
111
src/anbox/support/gsm_message_processor.cpp
Normal file
111
src/anbox/support/gsm_message_processor.cpp
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "anbox/logger.h"
|
||||||
|
#include "anbox/support/gsm_message_processor.h"
|
||||||
|
#include "anbox/support/at_parser.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace support {
|
||||||
|
GsmMessageProcessor::GsmMessageProcessor(const std::shared_ptr<network::SocketMessenger> &messenger) :
|
||||||
|
messenger_(messenger),
|
||||||
|
parser_(std::make_shared<AtParser>()) {
|
||||||
|
|
||||||
|
auto ok_reply = [&](const std::string&) { send_reply("OK"); };
|
||||||
|
|
||||||
|
parser_->register_command("E0Q0V1", ok_reply);
|
||||||
|
parser_->register_command("S0=0", ok_reply);
|
||||||
|
parser_->register_command("+CTEC", std::bind(&GsmMessageProcessor::handle_ctec, this, _1));
|
||||||
|
parser_->register_command("+CMEE=1", ok_reply);
|
||||||
|
parser_->register_command("+CCWA=1", ok_reply);
|
||||||
|
parser_->register_command("+CMOD=0", ok_reply);
|
||||||
|
parser_->register_command("+CMUT=0", ok_reply);
|
||||||
|
parser_->register_command("+CSSN=0,1", ok_reply);
|
||||||
|
parser_->register_command("+COLP=0", ok_reply);
|
||||||
|
parser_->register_command("+CSCS=\"HEX\"", ok_reply);
|
||||||
|
parser_->register_command("+CUSD=1", ok_reply);
|
||||||
|
parser_->register_command("+CGEREP=1,0", ok_reply);
|
||||||
|
parser_->register_command("+CMGF", std::bind(&GsmMessageProcessor::handle_cmgf, this, _1));
|
||||||
|
parser_->register_command("%CPI=3", ok_reply);
|
||||||
|
parser_->register_command("%CSTAT=1", ok_reply);
|
||||||
|
parser_->register_command("+CREG", std::bind(&GsmMessageProcessor::handle_creg, this, _1));
|
||||||
|
parser_->register_command("+CGREG", std::bind(&GsmMessageProcessor::handle_cgreg, this, _1));
|
||||||
|
parser_->register_command("+CFUN", std::bind(&GsmMessageProcessor::handle_cfun, this, _1));
|
||||||
|
}
|
||||||
|
|
||||||
|
GsmMessageProcessor::~GsmMessageProcessor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GsmMessageProcessor::process_data(const std::vector<std::uint8_t> &data) {
|
||||||
|
for (const auto &byte : data)
|
||||||
|
buffer_.push_back(byte);
|
||||||
|
|
||||||
|
parser_->process_data(buffer_);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GsmMessageProcessor::send_reply(const std::string &message) {
|
||||||
|
auto reply = utils::string_format("%s\rOK\n", message);
|
||||||
|
std::vector<std::uint8_t> data;
|
||||||
|
std::copy(reply.begin(), reply.end(), std::back_inserter(data));
|
||||||
|
messenger_->send(reinterpret_cast<const char*>(data.data()), data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GsmMessageProcessor::handle_ctec(const std::string &command) {
|
||||||
|
if (command == "+CTEC=?")
|
||||||
|
send_reply("+CTEC: 0,1,2,3");
|
||||||
|
else if (command == "+CTEC?")
|
||||||
|
send_reply(utils::string_format("+CTEC: %d,%x", static_cast<unsigned int>(technology::gsm), 0x0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GsmMessageProcessor::handle_cmgf(const std::string &command) {
|
||||||
|
DEBUG("command %s", command);
|
||||||
|
if (command == "+CMGF=0")
|
||||||
|
send_reply("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GsmMessageProcessor::handle_creg(const std::string &command) {
|
||||||
|
if (command == "+CREG=?")
|
||||||
|
send_reply("+CREG: (0-2)");
|
||||||
|
else if (command == "+CREG?")
|
||||||
|
send_reply(utils::string_format("+CREF: %d,%d", 0, 0));
|
||||||
|
else if (utils::string_starts_with(command, "+CREG="))
|
||||||
|
send_reply("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GsmMessageProcessor::handle_cgreg(const std::string &command) {
|
||||||
|
if (command == "+CGREG=?")
|
||||||
|
send_reply("+CGREG: (0-2)");
|
||||||
|
else if (command == "+CGREG?")
|
||||||
|
send_reply(utils::string_format("+CGREG: %d,%d", 0, 0));
|
||||||
|
else if (utils::string_starts_with(command, "+CGREG="))
|
||||||
|
send_reply("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GsmMessageProcessor::handle_cfun(const std::string &command) {
|
||||||
|
if (command == "+CFUN?")
|
||||||
|
send_reply(utils::string_format("+CFUN: %d", 1));
|
||||||
|
else if (utils::string_starts_with(command, "+CFUN="))
|
||||||
|
send_reply("");
|
||||||
|
}
|
||||||
|
} // namespace support
|
||||||
|
} // namespace anbox
|
||||||
59
src/anbox/support/gsm_message_processor.h
Normal file
59
src/anbox/support/gsm_message_processor.h
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANBOX_SUPPORT_GSM_MESSAGE_PROCESSOR_H_
|
||||||
|
#define ANBOX_SUPPORT_GSM_MESSAGE_PROCESSOR_H_
|
||||||
|
|
||||||
|
#include "anbox/network/message_processor.h"
|
||||||
|
#include "anbox/network/socket_messenger.h"
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace support {
|
||||||
|
class AtParser;
|
||||||
|
class GsmMessageProcessor : public network::MessageProcessor {
|
||||||
|
public:
|
||||||
|
GsmMessageProcessor(const std::shared_ptr<network::SocketMessenger> &messenger);
|
||||||
|
~GsmMessageProcessor();
|
||||||
|
|
||||||
|
bool process_data(const std::vector<std::uint8_t> &data) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class technology {
|
||||||
|
gsm = 0,
|
||||||
|
wcdm,
|
||||||
|
cdma,
|
||||||
|
evdo,
|
||||||
|
lte,
|
||||||
|
unknown,
|
||||||
|
};
|
||||||
|
|
||||||
|
void send_reply(const std::string &message);
|
||||||
|
|
||||||
|
void handle_ctec(const std::string &command);
|
||||||
|
void handle_cmgf(const std::string &command);
|
||||||
|
void handle_creg(const std::string &command);
|
||||||
|
void handle_cgreg(const std::string &command);
|
||||||
|
void handle_cfun(const std::string &command);
|
||||||
|
|
||||||
|
std::shared_ptr<network::SocketMessenger> messenger_;
|
||||||
|
std::vector<std::uint8_t> buffer_;
|
||||||
|
std::shared_ptr<AtParser> parser_;
|
||||||
|
};
|
||||||
|
} // namespace graphics
|
||||||
|
} // namespace anbox
|
||||||
|
|
||||||
|
#endif
|
||||||
38
src/anbox/support/telephony_manager.cpp
Normal file
38
src/anbox/support/telephony_manager.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "anbox/support/telephony_manager.h"
|
||||||
|
#include "anbox/dbus/ofono.h"
|
||||||
|
#include "anbox/logger.h"
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace support {
|
||||||
|
TelephonyManager::TelephonyManager(const core::dbus::Bus::Ptr &bus) :
|
||||||
|
bus_(bus) {
|
||||||
|
ofono_ = core::dbus::Service::use_service(bus_, "org.ofono");
|
||||||
|
modem_ = ofono_->object_for_path({"/ril_0"});
|
||||||
|
|
||||||
|
auto netreg_prop_changed = modem_->get_signal<org::ofono::NetworkRegistration::Signals::PropertyChanged>();
|
||||||
|
netreg_prop_changed->connect([&](const org::ofono::NetworkRegistration::Signals::PropertyChanged::ArgumentType &arguments) {
|
||||||
|
DEBUG("org::ofono::NetworkRegistration::PropertyChanged");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TelephonyManager::~TelephonyManager() {
|
||||||
|
}
|
||||||
|
} // namespace support
|
||||||
|
} // namespace anbox
|
||||||
40
src/anbox/support/telephony_manager.h
Normal file
40
src/anbox/support/telephony_manager.h
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANBOX_SUPPORT_TELEPHONY_MANAGER_H_
|
||||||
|
#define ANBOX_SUPPORT_TELEPHONY_MANAGER_H_
|
||||||
|
|
||||||
|
#include <core/dbus/bus.h>
|
||||||
|
#include <core/dbus/service.h>
|
||||||
|
#include <core/dbus/object.h>
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace support {
|
||||||
|
class TelephonyManager {
|
||||||
|
public:
|
||||||
|
TelephonyManager(const core::dbus::Bus::Ptr &bus);
|
||||||
|
~TelephonyManager();
|
||||||
|
|
||||||
|
private:
|
||||||
|
core::dbus::Bus::Ptr bus_;
|
||||||
|
core::dbus::Service::Ptr ofono_;
|
||||||
|
core::dbus::Object::Ptr modem_;
|
||||||
|
};
|
||||||
|
} // namespace support
|
||||||
|
} // namespace anbox
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
include_directories(
|
||||||
|
${Boost_INCLUDE_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
macro(ANBOX_ADD_TEST test_name src)
|
||||||
|
add_executable(
|
||||||
|
${test_name}
|
||||||
|
${src}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
${test_name}
|
||||||
|
|
||||||
|
anbox-core
|
||||||
|
|
||||||
|
gmock
|
||||||
|
gmock_main
|
||||||
|
|
||||||
|
${ARGN}
|
||||||
|
|
||||||
|
${Boost_LIBRARIES}
|
||||||
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(${test_name} ${CMAKE_CURRENT_BINARY_DIR}/${test_name} --gtest_filter=*-*requires*)
|
||||||
|
endmacro(ANBOX_ADD_TEST)
|
||||||
|
|
||||||
|
add_subdirectory(anbox)
|
||||||
1
tests/anbox/CMakeLists.txt
Normal file
1
tests/anbox/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
add_subdirectory(support)
|
||||||
1
tests/anbox/support/CMakeLists.txt
Normal file
1
tests/anbox/support/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ANBOX_ADD_TEST(at_parser_tests at_parser_tests.cpp)
|
||||||
47
tests/anbox/support/at_parser_tests.cpp
Normal file
47
tests/anbox/support/at_parser_tests.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 3, as published
|
||||||
|
* by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||||
|
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "anbox/support/at_parser.h"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
TEST(AtParser, BasicCommands) {
|
||||||
|
anbox::support::AtParser parser;
|
||||||
|
|
||||||
|
std::string command = "ATE0Q0V1\nATE0Q0V1\n";
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
std::copy(command.begin(), command.end(), std::back_inserter(data));
|
||||||
|
|
||||||
|
int commands_expected = 0;
|
||||||
|
int commands_found = 0;
|
||||||
|
auto assert_at_command = [&](const std::string &expected_command) {
|
||||||
|
commands_expected++;
|
||||||
|
return [&](const std::string &command) {
|
||||||
|
commands_found++;
|
||||||
|
ASSERT_STRCASEEQ(expected_command.c_str(), command.c_str());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
parser.register_command("E0Q0V1", assert_at_command("E0Q0V1"));
|
||||||
|
parser.register_command("E0Q0V1", assert_at_command("E0Q0V1"));
|
||||||
|
|
||||||
|
parser.process_data(data);
|
||||||
|
|
||||||
|
ASSERT_EQ(commands_expected, commands_found);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue