コード例 #1
0
void
Micro_adsb_device::Write_cmd(const std::string& cmd)
{
    write_ops.emplace(stream->Write(
            ugcs::vsm::Io_buffer::Create(cmd + "\r"),
            Make_write_callback(
                    &Micro_adsb_device::On_write_completed,
                    Shared_from_this()),
            adsb_worker));
}
コード例 #2
0
/** [Define processor enable disable] */
void
Sample_processor::On_enable()
{
    ugcs::vsm::Request_processor::On_enable();
    def_comp_ctx = ugcs::vsm::Request_completion_context::Create("Completion context");
    def_comp_ctx->Enable();
    worker = ugcs::vsm::Request_worker::Create("Worker",
        std::initializer_list<ugcs::vsm::Request_container::Ptr>{Shared_from_this(), def_comp_ctx});
    worker->Enable();
}
コード例 #3
0
void
Micro_adsb_device::Read_version_try()
{
    Write_cmd("#00");
    /* Example output: #00-00-0E-04-00-00-00-00-00-00-00-00-00-00-00-00 */
    filter->Add_entry(
            regex::regex("#00-[:xdigit:][:xdigit:]-([:xdigit:][:xdigit:])-04([:xdigit:]|-)*"),
            ugcs::vsm::Text_stream_filter::Make_match_handler(
                    &Micro_adsb_device::Read_version_handler_cb,
                    Shared_from_this()),
                    CMD_RESPONSE_TIMEOUT);
    read_version_attempts++;
}
コード例 #4
0
void
Micro_adsb_device::Init_heartbeat_try() {
	/* Set timed requests for heartbeat */
	ugcs::vsm::Timer_processor::Ptr timer = ugcs::vsm::Timer_processor::Get_instance();
	LOG_DEBUG("Timer instance received.");
	Micro_adsb_device::Ptr me = Shared_from_this();

    filter->Add_entry(
            regex::regex("#00-[:xdigit:][:xdigit:]-([:xdigit:][:xdigit:])-04([:xdigit:]|-)*"),
            ugcs::vsm::Text_stream_filter::Make_match_handler(
                    &Micro_adsb_device::Heartbeat_response_handler,
                    Shared_from_this()),
                    std::chrono::milliseconds(500));

	heartbeat_timer = ugcs::vsm::Timer_processor::Get_instance()->Create_timer(
		std::chrono::milliseconds(500),
		ugcs::vsm::Make_callback(
					&Micro_adsb_device::On_heartbeat_request,
					Shared_from_this()),
			adsb_worker);
	LOG_DEBUG("Heartbeat request service initialized for MicroADSB.");

}
コード例 #5
0
/** [Define sample api call] */
ugcs::vsm::Operation_waiter
Sample_processor::Sample_api_method(int param,
                                    Handler handler,
                                    ugcs::vsm::Request_completion_context::Ptr comp_ctx)
{
    ugcs::vsm::Request::Ptr req = ugcs::vsm::Request::Create();
    req->Set_processing_handler(
        ugcs::vsm::Make_callback(&Sample_processor::Process_api_call, Shared_from_this(),
                           param, req, handler));
    req->Set_completion_handler(comp_ctx ? comp_ctx : def_comp_ctx,
                                handler);
    Submit_request(req);
    return req;
}
コード例 #6
0
void
Red_button_processor::On_enable()
{
    ugcs::vsm::Request_processor::On_enable();
    comp_ctx->Enable();
    worker = ugcs::vsm::Request_worker::Create(
        "Red button worker",
        std::initializer_list<Request_container::Ptr>{Shared_from_this(), comp_ctx});
    worker->Enable();

    if (Delayed_connect()) {
        Schedule_connect();
    }
}
コード例 #7
0
void
Micro_adsb_device::On_enable()
{
    //filter->Set_line_handler(ugcs::vsm::Text_stream_filter::Make_line_handler(&line_handler));
    /* Example output: @00011AD59C088D3C675558BF01CB5A44478EC142;#0000001A;
     *                 @000123993F78200017B070DE22;#000000D8;
     *
     * Frames are always being read and pushed to the device.
     */
	filter = ugcs::vsm::Text_stream_filter::Create(stream, Get_completion_context());
    filter->Add_entry(
            regex::regex("@(([:xdigit:]){12})(([:xdigit:][:xdigit:])+);#(([:xdigit:]){8,});"),
            ugcs::vsm::Text_stream_filter::Make_match_handler(
                    &Micro_adsb_device::Read_frame_handler_cb,
                    Shared_from_this()));

    filter->Enable();

}
コード例 #8
0
void
Micro_adsb_device::Init_frames_receiving_try()
{
    /* We want time stamp and frame counter. */
    Write_cmd("#43-33");
    Write_cmd("#43-33");
    //Write_cmd("#43-34");
    //Write_cmd("#39-02-");
    Write_cmd("#39-02-05-64");
    //Command above is to set MicroADSB to show nearby aircraft (by default it filters anything too close)
    /* Example output: #43-EF-00-00-00-00-00-00-00-00-00-00-00-00-00-00- */
    filter->Add_entry(
            regex::regex("#43-[:xdigit:][:xdigit:]-00-([:xdigit:]|-)*"),
            ugcs::vsm::Text_stream_filter::Make_match_handler(
                    &Micro_adsb_device::Init_frames_receiving_handler_cb,
                    Shared_from_this()),
                    CMD_RESPONSE_TIMEOUT);
    init_frames_receiving_attempts++;
}
コード例 #9
0
ugcs::vsm::Operation_waiter
Micro_adsb_device::Init_frames_receiving(
        Init_frames_receiving_handler handler,
        ugcs::vsm::Request_completion_context::Ptr ctx)
{
    if (init_frames_receiving_handler) {
        VSM_EXCEPTION(ugcs::vsm::Invalid_op_exception, "Init frames receiving already in progress");
    }
    init_frames_receiving_handler = handler;
    init_frames_receiving_attempts = 0;
    ASSERT(!init_frames_receiving_request);

    init_frames_receiving_request = ugcs::vsm::Request::Create();
    init_frames_receiving_request->Set_processing_handler(
            ugcs::vsm::Make_callback(
                    &Micro_adsb_device::On_init_frames_receiving,
                    Shared_from_this()));

    init_frames_receiving_request->Set_completion_handler(ctx, handler);
    Get_processor()->Submit_request(init_frames_receiving_request);

    return init_frames_receiving_request;
}
コード例 #10
0
ugcs::vsm::Operation_waiter
Micro_adsb_device::Read_version(
        Read_version_handler handler,
        ugcs::vsm::Request_completion_context::Ptr ctx)
{
    if (read_version_handler) {
        VSM_EXCEPTION(ugcs::vsm::Invalid_op_exception, "Read version already in progress");
    }
    read_version_handler = handler;
    read_version_attempts = 0;
    ASSERT(!read_version_request);

    read_version_request = ugcs::vsm::Request::Create();
    read_version_request->Set_processing_handler(
            ugcs::vsm::Make_callback(
                    &Micro_adsb_device::On_read_version,
                    Shared_from_this()));

    read_version_request->Set_completion_handler(ctx, handler);
    Get_processor()->Submit_request(read_version_request);

    return read_version_request;
}