Code Monkey home page Code Monkey logo

onemessagecpp's Introduction

OneMessageCPP

本仓库为OneMessage的C++封装,多数API在初始化时会动态申请内存。使用时请对照OneMessage文档。


USAGE

请参照OneMessage中的 Readme.md 编写om_config.h文件。

om_config.h

om_config.h中需要另外声明一个函数,如果在中断中调用此函数,应当返回true,否则返回false。在linux等平台可以直接返回false。

#include <stdbool.h>
static inline bool om_in_isr() {
    ...
}

CMake

作为CMake子模块编译

CMakeList.txt

# OneMessageCPP_directory 为OneMessageCPP所在目录
# om_config_file_directory 为om_config.h所在目录

add_subdirectory(OneMessageCPP_directory)

target_include_directories(
    OneMessage
    PUBLIC om_config_file_directory
    ...
)

API

template <typename Data> class Topic

构造函数:

Topic可以直接隐式类型转换为om_topic_t*

新创建一个Topic,cached为false代表不拷贝数据,只传递指针

Topic(const char *name, bool cached = false);

拷贝一个已有的topic,不允许重复创建同名topic。

Topic(om_topic_t *topic);

队列:

template <uint32_t Len>
class Queue{
    Queue(topic_t* topic);

     uint32_t Size();

      bool Read(Data& buff);

      bool Reads(Data* buff, uint32_t len);

      bool Pop();

      void Reset();
}

链接:

bool Link(Topic &source);

bool Link(om_topic_t *source);

bool Link(const char *source_name);

查找topic:

om_topic_t *Find(const char *name);

加锁:

bool Lock();

void Unlock();

高级过滤器:

void RangeDivide(Topic &topic, uint32_t length, uint32_t offset, uint32_t scope, uint32_t start, uint32_t num);

void ListDivide(Topic &topic, uint32_t length, uint32_t offset, uint32_t scope, void *temp);

void DecomposeDivide(Topic &topic, uint32_t length, uint32_t offset, uint32_t scope);

注册回调:

//Fun的类型应当为bool (*)(Data &, Arg)

template <typename Fun, typename Arg>
void RegisterFilter(Fun fun, Arg arg);


template <typename Fun, typename Arg>
void RegisterCallback(Fun fun, Arg arg);

发布:

bool Publish(Data &data, bool in_isr = om_in_isr());

打包数据:

    bool PackData(RemoteData &data);

template <typename Data> class Subscriber

构造:

构造时需要传入订阅的话题名,如果目标话题未创建,会等待timeout时间后返回。

Subscriber(const char *name uint32_t timeout = UINT32_MAX);

如果能够获取到对应话题,可以使用以下构造函数:

    Subscriber(om_topic_t *topic);

    Subscriber(Topic<Data> &topic);

是否创建成功:

    bool Ready();

是否有新数据:

    bool Available();

导出数据到绑定的变量:

    bool DumpData(Data& buff, bool in_isr = om_in_isr());

class Remote

能够解析打包的话题数据。

构造函数:

    Remote(uint32_t buff_size, uint32_t topic_num);

添加可解析的话题:

    void AddTopic(const char *topic_name);

    void AddTopic(om_topic_t *topic);

解析数据:

    bool PraseData(uint8_t *data, uint32_t size,, bool in_isr = om_in_isr());

class Event

构造函数:

    Event(const char *name);

    Event(om_event_group_t *group);

查找事件组:

    om_event_group_t *FindEvent(const char *name);

注册事件:

    bool Register(uint32_t event, Status status, void (*callback)(uint32_t event, void *arg), void *arg);

激活事件:

    bool Active(uint32_t event, bool in_isr = om_in_isr());

onemessagecpp's People

Contributors

jiu-xiao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.