Skip to content

CPP SDK Documentation

Devrath Iyer edited this page Aug 18, 2021 · 1 revision

Karl::KarlSensorSDK

Class that represents a Karl sensor.

Instance Variables

Type Name Description
public std::string sensor_token Token assigned to sensor by controller on registration
private std::unique_ptr<KarlController::Stub> stub_ Stub representing controller as a GPRC service

Methods

KarlSensorSDK::KarlSensorSDK(std::shared_ptr<Channel>)

Constructor for KarlSensorSDK object. Takes in a single std::shared_ptr<Channel> representing a connection to the controller.
Example:

#include <grpcpp/grpcpp.h>
KarlSensorSDK karl(grpc::CreateChannel("localhost:59582", grpc::InsecureChannelCredentials()));

KarlSensorSDK::KarlSensorSDK(std::shared_ptr<Channel>)

Alternate constructor for KarlSensorSDK object. Takes in a shared_ptr<Channel> representing a connection to the controller and an sensor token. Used to instantiate already registered sensor.
Example:

#include <grpcpp/grpcpp.h>
KarlSensorSDK karl("PcmCl1R9AUWLmjddBP6jZpPs3070UO3D", grpc::CreateChannel("localhost:59582", grpc::InsecureChannelCredentials()));

request::SensorRegisterResult KarlSensorSDK::SensorRegister(string global_sensor_id, vector<string> keys, vector<string> returns, vector<int> app)

Method to register sensor with controller. Takes in a string global_sensor_id representing the id for the sensor, and vectors of strings and ints representing the keys, returns, and apps. Returns a SensorRegisterResult which contains strings sensor_token and sensor_id.
Example:

request::SensorRegisterResult result = karl.sensorRegister("camera", {"firmware","livestream"}, {"motion","streaming"}, {});

void KarlSensorSDK::push(string param, vector<char> data)

Method to push byte data to the data sink. Takes in a string param to denote the label for the data and a vector<char> for the data itself.
See examples/cpp/example.cc for complete example.

std::unique_ptr<ClientReader<request::StateChangePair>> connectState()

Returns a pointer to a Reader which will read state updates from the controller.
Example:

    unique_ptr<ClientReader<StateChangePair>> reader = karl.connectState();
    StateChangePair pair;
    while(reader->Read(&pair)) {
        // Can read pair.key() and/or pair.value()
        ...