IRSOL
C++ code implementing socket server for interacting with Baumer camera.
irsol::server::handlers::AssignmentIntegrationTimeHandler Class Reference

Handler for assignment of the camera integration time (exposure). More...

#include <assignment_integration_time.hpp>

Inheritance diagram for irsol::server::handlers::AssignmentIntegrationTimeHandler:
irsol::server::handlers::internal::HandlerBase< T, >

Public Member Functions

 AssignmentIntegrationTimeHandler (std::shared_ptr< Context > ctx)
 Constructs the AssignmentIntegrationTimeHandler.
 
- Public Member Functions inherited from irsol::server::handlers::internal::HandlerBase< T, >
virtual std::vector< out_message_toperator() (const irsol::types::client_id_t &clientId, T &&message)
 Invokes the handler for a given client and message.
 

Protected Member Functions

std::vector< out_message_tprocess (std::shared_ptr< irsol::server::ClientSession > session, protocol::Assignment &&message) final override
 Processes an assignment message to set the integration time.
 
- Protected Member Functions inherited from irsol::server::handlers::internal::HandlerBase< T, >
 HandlerBase (std::shared_ptr< Context > ctx)
 Constructs the handler base.
 
virtual std::vector< out_message_tprocess (std::shared_ptr< irsol::server::ClientSession > session, T &&message)=0
 Processes the protocol message for the given session.
 

Additional Inherited Members

- Protected Attributes inherited from irsol::server::handlers::internal::HandlerBase< T, >
std::shared_ptr< Contextctx
 Handler context (provides access to app and utilities).
 

Detailed Description

Handler for assignment of the camera integration time (exposure).

Processes assignment messages to set the camera's integration time.

Definition at line 24 of file assignment_integration_time.hpp.

Constructor & Destructor Documentation

◆ AssignmentIntegrationTimeHandler()

irsol::server::handlers::AssignmentIntegrationTimeHandler::AssignmentIntegrationTimeHandler ( std::shared_ptr< Context ctx)

Constructs the AssignmentIntegrationTimeHandler.

Parameters
ctxHandler context.

Definition at line 10 of file assignment_integration_time.cpp.

12{}
std::shared_ptr< Context > ctx
Handler context (provides access to app and utilities).
Definition base.hpp:81
internal::HandlerBase< protocol::Assignment > AssignmentHandler
Handler type for assignment messages.
Definition base.hpp:88

Member Function Documentation

◆ process()

std::vector< out_message_t > irsol::server::handlers::AssignmentIntegrationTimeHandler::process ( std::shared_ptr< irsol::server::ClientSession session,
protocol::Assignment &&  message 
)
finaloverrideprotected

Processes an assignment message to set the integration time.

Parameters
sessionThe client session.
messageThe assignment message.
Returns
Vector of outbound messages (success or error).

Definition at line 15 of file assignment_integration_time.cpp.

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>",
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}
#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
std::string toString(const InMessage &msg)
Converts an incoming message variant to a human-readable string.
Definition variants.cpp:19
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
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

The documentation for this class was generated from the following files: