Skip to content

Commit

Permalink
Fill api params based on device type
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery committed Nov 20, 2023
1 parent 42c2ef7 commit cbd367d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define RESOURCE_TYPE "CSICamera"
#define API_NAMESPACE "viam"
#define API_TYPE "camera"
#define API_SUBTYPE "csi"
#define DEFAULT_API_SUBTYPE "csi"

// GST
#define GST_GET_STATE_TIMEOUT 1
Expand All @@ -23,12 +23,14 @@
#define DEFAULT_OUTPUT_MIMETYPE "image/jpeg"

// Jetson
#define JETSON_API_SUBTYPE "csi"
#define JETSON_INPUT_SOURCE "nvarguscamerasrc"
#define JETSON_INPUT_FORMAT "video/x-raw(memory:NVMM)"
#define JETSON_VIDEO_CONVERTER "nvvidconv"
#define JETSON_OUTPUT_ENCODER "nvjpegenc"

// Pi
#define PI_API_SUBTYPE "csi-pi"
#define PI_INPUT_SOURCE "libcamerasrc"
#define PI_INPUT_FORMAT "video/x-raw"
#define PI_VIDEO_CONVERTER "videoconvert"
Expand Down
9 changes: 7 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "constraints.h"
#include "csi_camera.h"
#include "utils.h"

using namespace viam::sdk;

Expand All @@ -24,18 +25,22 @@ int serve(const std::string& socket_path) {
return EXIT_FAILURE;
}

// Device type and params
auto device = get_device_type();
auto api_params = get_api_params(device);

// Model registration
auto module_registration = std::make_shared<ModelRegistration>(
ResourceType{RESOURCE_TYPE},
Camera::static_api(),
Model{API_NAMESPACE, API_TYPE, API_SUBTYPE},
Model{api_params.api_namespace, api_params.api_type, api_params.api_subtype},
[](Dependencies, ResourceConfig resource_config) -> std::shared_ptr<Resource> {
return std::make_shared<CSICamera>(resource_config.name(), resource_config.attributes());
});

try {
Registry::register_model(module_registration);
std::cout << "registered model: " << API_NAMESPACE << ":" << API_TYPE << ":" << API_SUBTYPE << std::endl;
std::cout << "registered model: " << api_params.api_namespace << ":" << api_params.api_type << ":" << api_params.api_subtype << std::endl;
} catch (const std::runtime_error& e) {
std::cerr << "error registering model: " << e.what() << std::endl;
return EXIT_FAILURE;
Expand Down
23 changes: 23 additions & 0 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,26 @@ device_params get_device_params(device_type device) {
};
}
}

api_params get_api_params(device_type device) {
switch (device.value) {
case device_type::jetson:
return api_params {
.api_namespace = API_NAMESPACE,
.api_type = API_TYPE,
.api_subtype = JETSON_API_SUBTYPE
};
case device_type::pi:
return api_params {
.api_namespace = API_NAMESPACE,
.api_type = API_TYPE,
.api_subtype = PI_API_SUBTYPE
};
default:
return api_params {
.api_namespace = API_NAMESPACE,
.api_type = API_TYPE,
.api_subtype = DEFAULT_API_SUBTYPE
};
}
}
7 changes: 7 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ struct device_type {
device_type(type value, std::string name) : value(value), name(name) {}
};

struct api_params {
std::string api_namespace;
std::string api_type;
std::string api_subtype;
};

struct device_params {
std::string input_source;
std::string input_format;
Expand All @@ -28,3 +34,4 @@ struct device_params {

device_type get_device_type();
device_params get_device_params(device_type device);
api_params get_api_params(device_type device);

0 comments on commit cbd367d

Please sign in to comment.