Code Monkey home page Code Monkey logo

uartdriver's Introduction

UartDriver use

It's a uart driver to fast development.

Your can use this code to fast fit common uart protocal.

EXAMPLE

There are five kind type in UartDriver.h enum type { frame_header, frame_end, frame_data, frame_cnt, frame_check };

  • frame_header : common use of the header of frame , you can also use it to fixed data. So you can have multiple frame_header.
  • frame_end : common use of the end of frame. Note that once you receive the frame_end, however if the data is right ,the frame will be end.
  • frame_data : common use of the data. When you need add multiple data. Use the AddLayer Function like AddLayer(MyUartDriver::frame_data,cnt). The cnt represent the data number you want to add.
  • frame_cnt : Represent the not fix number of data. Your will receive frame_cnt data.
  • frame_check : like frame_data. Your need to check the data after your receive a whole frame.

example0.

0x11 , data1 , data2 , 0x10

#include <iostream>
#include "UartDriver.h"
#include <cmath>

std::vector<uint8_t> test_data={0x10,0x11,0x2,0x13,0x10,0x2,0x13,0x11};

int main() {

  MyUartDriver::UartDriver example0;
  example0.AddLayer(MyUartDriver::frame_header,0x11);
  example0.AddLayer(MyUartDriver::frame_data,2);
  example0.AddLayer(MyUartDriver::frame_end,0x10);

  for(auto i:test_data) {
    if(example0.GetOneByte(i)) {
      std::cout << "receive complete" << std::endl;
      std:: cout << "receive buf: ";
      for (auto data:example0.buf) {
        std:: cout << +data << " ";
      }
    }
  }

  return 0;
}

print out :

receive complete
receive buf: 16 17 2 19 

example1.

0x11 , 0x12 , data1 , data2 , data3 , data4 , sum_check

INIT:
MyUartDriver::UartDriver example1;
example1.AddLayer(MyUartDriver::frame_header,0x11);
example1.AddLayer(MyUartDriver::frame_header,0x11);
example1.AddLayer(MyUartDriver::frame_data,4);
example1.AddLayer(MyUartDriver::frame_check);

USE:
if(example1.GetOneByte(INPUT_DATA))
{
    DEAL_CODE:
}

example2.

0xFF , data_cnt , ***(data_cnt) , sum_check1 , sum_check2

INIT:
MyUartDriver::UartDriver example2;
example2.AddLayer(MyUartDriver::frame_header,0xFF);
example2.AddLayer(MyUartDriver::frame_cnt);
example2.AddLayer(MyUartDriver::frame_check);
example2.AddLayer(MyUartDriver::frame_check);

USE:
if(example2.GetOneByte(INPUT_DATA))
{
    DEAL_CODE:
}

uartdriver's People

Contributors

gxt-kt avatar

Watchers

 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.