IRSOL
C++ code implementing socket server for interacting with Baumer camera.
assignment_integration_time.cpp
Go to the documentation of this file.
2
5#include "irsol/utils.hpp"
6
7namespace irsol {
8namespace server {
9namespace handlers {
13
14std::vector<out_message_t>
16 std::shared_ptr<irsol::server::ClientSession> session,
18{
19 // Try to set the integration time (exposure) according to the message
20 if(!message.hasInt() && !message.hasDouble()) {
22 session->id(),
23 "Expected integer/double for integration time, got type {}: '{}'",
24 message.hasString() ? "<string>" : "<unknown>",
25 message.toString());
26 return {};
27 }
29 if(message.hasInt()) {
31 } else {
32 IRSOL_ASSERT_ERROR(message.hasDouble());
34 }
35 irsol::types::duration_t integrationTime = std::chrono::microseconds(integrationTimeMs * 1000);
37 session->id(),
38 "Setting camera integration time to {}",
40 auto& cam = session->app().camera();
41 auto resultingExposure = cam.setExposure(integrationTime);
42
43 int resultingExposureMs = static_cast<int>(
44 1.0 * std::chrono::duration_cast<std::chrono::microseconds>(resultingExposure).count() / 1000);
45
46 // Broadcast the new integration time to all clients
48
49 // Don't return anything to the current client, as the client is automatically notified via the
50 // above broadcast
51 return {};
52}
53} // namespace handlers
54} // namespace server
55} // namespace irsol
Main server application managing client connections and camera streaming.
Declaration of the AssignmentIntegrationTimeHandler class.
std::vector< out_message_t > process(std::shared_ptr< irsol::server::ClientSession > session, protocol::Assignment &&message) final override
Processes an assignment message to set the integration time.
AssignmentIntegrationTimeHandler(std::shared_ptr< Context > ctx)
Constructs the AssignmentIntegrationTimeHandler.
Generic handler base class for protocol messages.
Definition base.hpp:39
std::shared_ptr< Context > ctx
Handler context (provides access to app and utilities).
Definition base.hpp:81
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
Definition assert.hpp:134
#define IRSOL_NAMED_LOG_INFO(name,...)
Logs an info-level message using a named logger.
Definition logging.hpp:176
#define IRSOL_NAMED_LOG_ERROR(name,...)
Logs an error-level message using a named logger.
Definition logging.hpp:180
constexpr auto makeHandler(std::shared_ptr< Context > ctx, Args &&... args)
Constructs a handler instance of the given type.
Definition factory.hpp:28
clock_t::duration duration_t
Alias for a duration of time as defined by clock_t.
Definition types.hpp:128
double toDouble(const irsol::types::protocol_value_t &x)
Converts a protocol value to a double.
Definition utils.hpp:55
int toInt(const irsol::types::protocol_value_t &x)
Converts a protocol value to an integer.
Definition utils.hpp:39
std::string durationToString(irsol::types::duration_t dr)
Converts a duration to a human-readable string.
Definition utils.cpp:133
Declaration of the ClientSession class.
Represents an assignment operation in the protocol.
static Success from(const Assignment &msg, std::optional< irsol::types::protocol_value_t > overrideValue=std::nullopt)
Creates a success message from an Assignment.
Definition success.hpp:75
General utility functions used throughout the irsol library.