-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from anthonypayne-GM/someip-input-plugin
Someip input plugin
- Loading branch information
Showing
18 changed files
with
3,801 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[SERVICE] | ||
# Flush | ||
# ===== | ||
# Set an interval of seconds before to flush records to a destination | ||
Flush 5 | ||
|
||
# Daemon | ||
# ====== | ||
# Instruct Fluent Bit to run in foreground or background mode. | ||
Daemon Off | ||
|
||
# Log_Level | ||
# ========= | ||
# Set the verbosity level of the service, values can be: | ||
# | ||
# - error | ||
# - warning | ||
# - info | ||
# - debug | ||
# - trace | ||
# | ||
# By default 'info' is set, that means it includes 'error' and 'warning'. | ||
Log_Level trace | ||
|
||
# HTTP Monitoring Server | ||
# ====================== | ||
# | ||
# HTTP_Monitor: enable/disable the HTTP Server to monitor | ||
# Fluent Bit internals. | ||
# HTTP_Port : specify the TCP port of the HTTP Server | ||
HTTP_Monitor Off | ||
HTTP_Port 2020 | ||
|
||
[INPUT] | ||
Name someip | ||
Tag in.someip | ||
|
||
# Events to subscribe to. | ||
# Each event should have form: | ||
# Event <service id>,<instance id>,<event id>,<event group 1>,... | ||
# | ||
# Each event must have at least one event group | ||
Event 4,1,32768,1 | ||
Event 4,1,32769,2 | ||
|
||
# RPC to send on startup | ||
# Each RPC entry should have form: | ||
# RPC <service id>,<instance id>,<method id>,<Request Payload> | ||
# | ||
# Request payload should be base64 encoded | ||
RPC 4,1,1,CgAQAw== | ||
[OUTPUT] | ||
Name stdout | ||
Match * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
project(someipc CXX) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
vsomeip3 | ||
GIT_REPOSITORY https://github.com/COVESA/vsomeip | ||
GIT_TAG 0b83e24d16e1611958194e9b727136522f46556b # 3.5.1 | ||
) | ||
FetchContent_MakeAvailable(vsomeip3) | ||
|
||
find_package(vsomeip3 REQUIRED) | ||
|
||
add_library(someip-c SHARED src/someip_wrapper.cc) | ||
target_include_directories(someip-c PUBLIC include) | ||
target_link_libraries(someip-c PRIVATE vsomeip3 vsomeip3-sd vsomeip3-cfg vsomeip3-e2e) | ||
target_link_options(someip-c PUBLIC "-Wl,--disable-new-dtags") | ||
|
||
add_subdirectory(example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
add_executable(someip_test_service test_service.cc) | ||
target_link_libraries(someip_test_service PRIVATE someip-c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* Fluent Bit | ||
* ========== | ||
* Copyright (C) 2015-2024 The Fluent Bit Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "someip_api.h" | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <chrono> | ||
#include <sstream> | ||
#include <thread> | ||
|
||
/* Class declaration */ | ||
class TestService { | ||
public: | ||
bool Initialize(); | ||
void Teardown(); | ||
void HandleRequest(const struct some_ip_request* request_ptr); | ||
void SendEvent(const int num); | ||
private: | ||
uint16_t client_id_{0}; | ||
}; | ||
|
||
namespace { | ||
constexpr auto NAME = "Test Service"; | ||
constexpr uint16_t SERVICE_ID = 4; | ||
constexpr uint16_t INSTANCE_ID = 1; | ||
constexpr uint16_t METHOD_ID = 1; | ||
constexpr uint16_t EVENT_ID = 0x8000U; | ||
constexpr uint16_t EVENT_GROUP_ID = 1; | ||
|
||
void RequestCallback(void* cookie, struct some_ip_request* request_ptr) { | ||
if (cookie == nullptr) { | ||
return; | ||
} | ||
auto service_pointer{static_cast<TestService*>(cookie)}; | ||
service_pointer->HandleRequest(request_ptr); | ||
} | ||
} | ||
|
||
bool TestService::Initialize() { | ||
auto ret = someip_initialize(NAME, &client_id_); | ||
if (ret != SOMEIP_RET_SUCCESS) { | ||
std::cout << "Failed to initialize SOME/IP: " << ret << std::endl; | ||
return false; | ||
} | ||
|
||
/* Register Request Handler */ | ||
auto request_handler{[this](struct some_ip_request* request_ptr) { | ||
HandleRequest(request_ptr); | ||
}}; | ||
ret = someip_register_request_handler(client_id_, SERVICE_ID, INSTANCE_ID, | ||
METHOD_ID, this, RequestCallback); | ||
|
||
if (ret != SOMEIP_RET_SUCCESS) { | ||
std::cout << "Failed to register request handler: " << ret << std::endl; | ||
someip_shutdown(client_id_); | ||
return false; | ||
} | ||
|
||
/* Offer Event */ | ||
ret = someip_offer_event(client_id_, SERVICE_ID, INSTANCE_ID, EVENT_ID, const_cast<uint16_t*>(&EVENT_GROUP_ID), 1); | ||
if (ret != SOMEIP_RET_SUCCESS) { | ||
std::cout << "Failed to Offer Event: " << ret << std::endl; | ||
someip_shutdown(client_id_); | ||
return false; | ||
} | ||
|
||
/* Offer Service */ | ||
ret = someip_offer_service(client_id_, SERVICE_ID, INSTANCE_ID); | ||
if (ret != SOMEIP_RET_SUCCESS) { | ||
std::cout << "Failed to Offer Service: " << ret << std::endl; | ||
someip_shutdown(client_id_); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void TestService::Teardown() { | ||
someip_shutdown(client_id_); | ||
} | ||
|
||
void TestService::HandleRequest(const struct some_ip_request* request_ptr) { | ||
if (request_ptr == nullptr) { | ||
return; | ||
} | ||
std::cout << "Received request (method = " << request_ptr->method_id << ")" << std::endl; | ||
std::cout << "Payload length = " << request_ptr->payload_len << std::endl; | ||
|
||
/* Normal service would Parse the request and perform/initiate some actions on it*/ | ||
/* For this example just send back a canned response */ | ||
auto response{"This is the response to the request"}; | ||
const auto ret = someip_send_response(client_id_, request_ptr->request_id.client_request_id, | ||
const_cast<char*>(response), strlen(response)); | ||
if (ret != SOMEIP_RET_SUCCESS) { | ||
std::cout << "Failed to send response: %d" << ret << std::endl; | ||
} | ||
} | ||
|
||
void TestService::SendEvent(const int num) { | ||
std::stringstream ss; | ||
ss << "Event Number " << num; | ||
const auto message = ss.str(); | ||
|
||
auto ret = someip_send_event(client_id_, SERVICE_ID, INSTANCE_ID, EVENT_ID, | ||
message.data(), message.size()); | ||
} | ||
|
||
|
||
int main() { | ||
TestService service; | ||
if (!service.Initialize()) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
auto num_events{10}; | ||
|
||
for (auto i = 0; i < num_events; ++i) { | ||
service.SendEvent(i); | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
} | ||
|
||
service.Teardown(); | ||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.