46#if OPENMRN_FEATURE_EXECUTOR_SELECT
47#include "utils/HubDeviceSelect.hxx"
131 HubPort *skip_member,
int double_bytes)
139 const int cnt = config_gridconnect_bridge_max_outgoing_packets();
162 const int cnt = config_gridconnect_bridge_max_outgoing_packets();
164 bool state_pool =
true;
167 state_pool = (int(
ownedPool_->free_items()) == cnt);
169 return state_delay && state_pool;
182 GET_CAN_FRAME_ID_EFF(*
message()->data()));
185 size_t size = (end -
dbuf_);
194 target_buffer->
data()->resize(size);
195 memcpy((
char *)target_buffer->
data()->data(),
dbuf_, size);
203 LOG(
INFO,
"gc generate failed.");
208 Action buffer_accepted()
251 int max_frames_to_parse =
252 config_gridconnect_bridge_max_incoming_packets();
253 if (max_frames_to_parse > 1) {
264 int max_frames_to_parse =
265 config_gridconnect_bridge_max_incoming_packets();
266 if (max_frames_to_parse > 1)
268 if (frameAllocator_->free_items() < (
size_t)max_frames_to_parse)
338 std::unique_ptr<LimitedPool> frameAllocator_;
361 return new GCAdapter(gc_side, can_side, double_bytes);
369 return new GCAdapter(gc_side_read, gc_side_write, can_side, double_bytes);
405#if defined(__linux__) || defined(__MACH__)
407 gettimeofday(&tv,
nullptr);
409 localtime_r(&tv.tv_sec, &t);
410 fprintf(stderr,
"%04d-%02d-%02d %02d:%02d:%02d:%06ld [%p] ",
411 t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min,
412 t.tm_sec, (
long)tv.tv_usec, message->data()->skipMember_);
415 fprintf(stderr,
"%s", str);
416 if (config_gc_generate_newlines() != 1)
418 fprintf(stderr,
"\n");
432GcPacketPrinter::~GcPacketPrinter()
452 :
gcHub_(can_hub->service())
459#ifndef OPENMRN_FEATURE_EXECUTOR_SELECT
460 DIE(
"select is not supported");
511 LOG(
INFO,
"GCHubPort: Shutting down gridconnect port %d. (%p)",
528 new GcHubPort(can_hub, fd, on_exit, use_select);
DynamicPool * mainBufferPool
main buffer pool instance
std::unique_ptr< Buffer< T >, BufferDelete< T > > AutoReleaseBuffer
This class will automatically unref a Buffer when going out of scope.
void create_gc_port_for_can_hub(CanHubFlow *can_hub, int fd, Notifiable *on_exit, bool use_select)
Creates a new port on a CAN hub in gridconnect format for a select-compatible file descriptor.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
BarrierNotifiable * reset(Notifiable *done)
Resets the barrier. Returns &*this. Asserts that is_done().
void set_done(BarrierNotifiable *done)
Specifies that a given BarrierNotifiable must be called when the Buffer is deallocated (unreffed to z...
A wrapper class around a string-based Hub Port that buffers the outgoing bytes for a specified delay ...
Base class for all QMember types that hold data in an expandable format.
T * data()
get a pointer to the start of the data.
An object that can be scheduled on an executor to run.
virtual void add(Executable *action, unsigned priority=UINT_MAX)=0
Send a message to this Executor's queue.
HubPort that connects a raw device to a strongly typed Hub.
Publicly visible API for the gridconnect-to-CAN bridge.
static GCAdapterBase * CreateGridConnectAdapter(HubFlow *gc_side, CanHubFlow *can_side, bool double_bytes)
This function connects an ASCII (GridConnect-format) CAN adapter to a binary CAN adapter,...
HubPort (on a CAN-typed hub) that turns a binary CAN packet into a string-formatted CAN packet,...
Pool * pool() override
The dispatcher will be using this pool to allocate frames when a hub needs to make a copy for an outg...
int double_bytes_
Non-zero if doubling was requested.
Pool * pool_
The allocation buffer pool to use for outgoing frames.
std::unique_ptr< LimitedPool > ownedPool_
If we want frame limits, this pool can do that for us.
Action entry() override
Entry into the StateFlow activity.
HubPort * skipMember_
The pipe member that should be sent as "source".
BinaryToGCMember(Service *service, HubFlow *destination, HubPort *skip_member, int double_bytes)
Constructor.
char dbuf_[56]
Destination buffer (characters).
BarrierNotifiable bn_
Helper object.
BufferPort delayPort_
Helper class that assembles larger outgoing packets from the individual packets by delaying data a li...
HubFlow * destination_
Pipe to send data to.
HubPort (on a string hub) that turns a gridconnect-formatted CAN packet into a binary CAN packet,...
CanHubFlow * destination()
size_t inBufSize_
The remaining number of characters in inBuf_.
GcStreamParser streamSegmenter_
Holds the state of the incoming characters and the boundary.
Action parse_more_data()
Matches the incoming characters to the pattern to form incoming frames.
Action entry() override
Takes more characters from the pending incoming buffer.
CanHubPortInterface * skipMember_
The pipe member that should be sent as "source".
Action parse_to_output_frame()
Takes the completed frame in cbuf_, parses it into the allocation result (a can pipe buffer) and send...
const char * inBuf_
The incoming characters.
CanHubFlow * destination_
Pipe to send data to.
GCToBinaryMember(Service *service, CanHubFlow *destination, CanHubPort *skip_member)
Constructor.
Actual implementation for the gridconnect bridge between a string-typed Hub and a CAN-frame-typed Hub...
GCToBinaryMember parser_
PipeMember doing the parsing.
GCAdapter(HubFlow *gc_side, CanHubFlow *can_side, bool double_bytes)
Constructor.
BinaryToGCMember formatter_
PipeMember doing the formatting.
bool shutdown() OVERRIDE
Unregisters *this from the pipes.
unsigned isRegistered_
1 if the flows are registered.
GCAdapter(HubFlow *gc_side_read, HubFlow *gc_side_write, CanHubFlow *can_side, bool double_bytes)
Constructor.
GcPacketPrinter(CanHubFlow *can_hub, bool timestamped)
constructor
Parses a sequence of characters; finds GridConnect protocol packet boundaries in the sequence of pack...
bool consume_byte(char c)
Adds the next character from the source stream.
bool parse_frame_to_output(struct can_frame *output_frame)
Parses the current contents of the frame buffer to a can_frame struct.
void register_port(port_type *port)
Adds a new port.
void unregister_port(port_type *port)
Removes a previously added port.
HubPort that connects a select-aware device to a strongly typed Hub.
Implementation of a Pool interface that takes memory from mainBufferPool (configurable) but limits th...
An object that can schedule itself on an executor to run.
virtual void notify()=0
Generic callback.
Pool of previously allocated, but currently unused, items.
void alloc(Buffer< BufferType > **result, Executable *flow=NULL)
Get a free item out of the pool.
Collection of related state machines that pend on incoming messages.
ExecutorBase * executor()
Return type for a state flow callback.
Service * service()
Return a pointer to the service I am bound to.
Action allocate_and_call(FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
Allocates a buffer from a pool and proceed to the next state when allocation is successful.
Buffer< T > * get_allocation_result(FlowInterface< Buffer< T > > *target_flow)
Takes the result of the asynchronous allocation.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action exit()
Terminates the processing of this flow.
Action release_and_exit()
Terminates the processing of the current message.
State flow with a given typed input queue.
void release() OVERRIDE
Unrefs the current buffer.
void send(MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
Sends a message to the state flow for processing.
Action call_immediately(Callback c)
Imediately call the next state upon return.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int VERBOSE
Loglevel that is usually not printed, reporting debugging information.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define DIE(MSG)
Unconditionally terminates the current process with a message.
#define USEC_TO_NSEC(_usec)
Convert a microsecond value to a nanosecond value.
Implementation class that adds a device to a CAN hub with dynamic translation of the packets to/from ...
std::unique_ptr< GCAdapterBase > bridge_
Translates packets between the can-hub of the device and the char-hub of this port.
void notify() OVERRIDE
Callback in case the connection is closed due to error.
GcHubPort(CanHubFlow *can_hub, int fd, Notifiable *on_exit, bool use_select)
Constructor.
void run() OVERRIDE
Entry point.
std::unique_ptr< FdHubPortInterface > gcWrite_
Reads the characters from the char-hub and sends them to the fd.
HubFlow gcHub_
This hub sees the character-based representation of the packets.
Notifiable * onExit_
If not null, this notifiable will be called when the device is closed.
Implementation for the gridconnect bridge.
bool timestamped_
Whether we are printing timestamps of the packets.
void send(Buffer< CanHubData > *message, unsigned priority) OVERRIDE
Overridden entry method to send binary data to this hub.
Impl(CanHubFlow *can_hub, bool timestamped)
Constructor.
CanHubFlow * canHub_
Which hun are we registered to.