ladianchad / LachaCom

communcation( Serial, Socket, I2C ...) c++ pakage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Communication C++ Package

Setting

sudo usermod -aG dialout $USER

Requirements

requiered os

ubuntu 22.04 ubuntu 21.04

required packages

cmake | wget | nlohmann-json | libspdlog

install requirements

  sudo apt install build-essential cmake wget nlohmann-json3-dev libspdlog-dev

Install

git clone https://github.com/ladianchad/LachaCom.git
cd LachaCom
mkdir build && cd build
sudo cmake --build --install ..

CONFIGURATION

Configuration

Use

C style

#include <communication/interface.hpp>
#include <communication/interfaces/uart.hpp>
#include <stdio.h>

void onSysPoll(const char in){
  printf("read : %c", in);
}

int main(int argc, char const *argv[])
{
  using namespace communication;

  Logger::set_level(Logger::level::debug);
  InterfaceInitParam param({
    {UART::USE_SYS_POLLING, true},
    {UART::PORT, "/dev/ttyUSB0"},
    {UART::BAUDRATE, 115200}
  });

  UART uart;
  uart.init(param);
  uart.setSysPollingCallback(onSysPoll);
  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  return 0;
}

C++ Style

#include <communication/interface.hpp>
#include <communication/interfaces/uart.hpp>
#include <iostream>

int main(int argc, char const *argv[])
{
  using namespace communication;

  Logger::set_level(Logger::level::debug);
  InterfaceInitParam param({
    {UART::USE_SYS_POLLING, true},
    {UART::PORT, "/dev/ttyUSB0"},
    {UART::BAUDRATE, 115200}
  });

  UART uart;
  uart.init(param);
  uart.setSysPollingCallback([&](const char c){
    std::cout<<"read : "<<c<<std::endl;
  });
  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  return 0;
}

CMakeLists

cmake_minimum_required(VERSION 3.0.2)
project(your project)

findpackage(LaChaCom REQUIRED)

add_executable(${your_executable})
target_link_library(${your_executable} LaChaCom::LaChaCom)

Now Exist

  • Serial

TODO

  • Socket
  • I2C

About

communcation( Serial, Socket, I2C ...) c++ pakage


Languages

Language:C++ 77.7%Language:CMake 19.7%Language:Dockerfile 2.7%