Git Product home page Git Product logo

recorder's Introduction

Recorder

This project aims to read simulated sensor data and write it to a log file.

Building

This project requires a compiler supporting C++17 and uses CMake or Bazel for building. asio is used for network communication and json is used to encode to JSON. Google Test is used for testing.

It has been tested with GCC 7 and Clang 9 on Ubuntu 18.04 and GCC 9 and AppleClang 11 on macOS 10.15.

With CMake

To build

oliver@canopus:~/repos/recorder$ git submodule update --init --recursive --recommend-shallow
oliver@canopus:~/repos/recorder$ cmake -S . -B build
oliver@canopus:~/repos/recorder$ cmake --build build

To run tests

oliver@canopus:~/repos/recorder$ cd build
oliver@canopus:~/repos/recorder/build$ GTEST_COLOR=1 ctest -V

With Bazel

To build all

oliver@canopus:~/repos/recorder$ bazel build //...

To build binaries and exclude tests

oliver@canopus:~/repos/recorder$ bazel build -- //... -//tests/...

To run tests

oliver@canopus:~/repos/recorder$ bazel test //...

User specified Bazel configuration settings will be loaded from user.bazelrc. This file is ignored by Git.

Usage

Here's a simple usage example.

If building with bazel, binaries can be found in the bazel-bin directory.

Start the log server first

oliver@canopus:~/repos/recorder$ ./build/bin/logger 12345

Connect to the log server with a reader client

oliver@canopus:~/repos/recorder$ <sensor-simulator-bin> | ./build/bin/reader localhost 12345

The sensor data is piped to the reader client, which then forwards data to the remote log server.

The server accepts connections from multiple clients simultaneously. Status messages are also displayed when clients connect or disconnect.

Here's an example of logger output with two connections:

oliver@canopus:~/repos/recorder$ ./build/bin/logger 12345
Starting logger on port 12345
[127.0.0.1:56184] Established connection
{
    "humidity": 80.80000305175781,
    "name": "e74bb50f-5a1e-4742-8827-20bc80a17297",
    "temperature": 3161.130126953125,
    "timestamp": "2020-06-28T16:51:50.240+0200"
}
{
    "humidity": 67.9000015258789,
    "name": "e74bb50f-5a1e-4742-8827-20bc80a17297",
    "temperature": 2731.8701171875,
    "timestamp": "2020-06-28T16:51:54.732+0200"
}
{
    "name": "e74bb50f-5a1e-4742-8827-20bc80a17297",
    "timestamp": "2020-06-28T16:51:59.570+0200"
}
[127.0.0.1:56185] Established connection
{
    "humidity": 17.799999237060547,
    "name": "héllö",
    "timestamp": "2020-06-28T16:52:04.006+0200"
}
{
    "name": "e74bb50f-5a1e-4742-8827-20bc80a17297",
    "temperature": 3479.840087890625,
    "timestamp": "2020-06-28T16:52:03.403+0200"
}
{
    "name": "héllö",
    "temperature": 3440.93017578125,
    "timestamp": "2020-06-28T16:52:05.613+0200"
}
{
    "humidity": 85.9000015258789,
    "name": "e74bb50f-5a1e-4742-8827-20bc80a17297",
    "temperature": 2462.35009765625,
    "timestamp": "2020-06-28T16:52:05.668+0200"
}
[127.0.0.1:56184] Terminating connection
{
    "humidity": 5.5,
    "name": "héllö",
    "temperature": 732.1300048828125,
    "timestamp": "2020-06-28T16:52:09.358+0200"
}

To log to a file, redirect the output of the logger:

oliver@canopus:~/repos/recorder$ ./build/bin/logger 12345 > sensor.log

Note that status messages are written to stderr.

Notes

The sensors transmit a timestamp without an associated timezone. The log process uses the machine local timezone.

recorder's People

Contributors

oliverlee avatar

Watchers

James Cloos avatar  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.