zoukankan      html  css  js  c++  java
  • BaseCommand

    import java.io.Serializable;

    import android.util.Log;

    public class BaseCommand implements Serializable {

    /**
    *
    */
    private static final long serialVersionUID = 2677660408587776109L;

    private String head;
    private String id;
    private String size;
    private String data;
    private String crc;

    public BaseCommand() {

    }

    public BaseCommand(String head, String id, String data) {
    this.head = head;
    this.id = id;
    this.data = data;
    /*if (null != this.head && null != this.id && null != this.data) {
    this.size = CommandHelper.intToHexString(head.length() / 2
    + id.length() / 2 + data.length() / 2 + 2);
    Log.d("SerialPort", "size = " + size);
    }*/
    }

    public String getHead() {
    return this.head;
    }

    public void setHead(String head) {
    this.head = head;
    }

    public String getId() {
    return this.id;
    }

    public void setId(String id) {
    this.id = id;
    }

    public String getCrc() {
    if(null != crc){
    return crc;
    } else {
    return "";
    }
    }

    public void setCrc(String crc){
    this.crc = crc;
    }

    public String getCommand() {
    if (null != this.head && null != this.id && null != this.data) {
    String result = head + id;
    if(null != size){
    result = result + size;
    }
    result = result + data;
    if(null != crc){
    result = result + crc;
    }
    return result;
    } else {
    return "";
    }
    }

    /*
    * public String getSize(){ return this.size; }
    *
    * public void setSize(String size){ this.size = size; }
    */

    public String getData() {
    return this.data;
    }

    public void setData(String data) {
    this.data = data;
    if (null != this.head && null != this.id && null != this.data) {
    /*this.size = CommandHelper.intToHexString(head.length() / 2
    + id.length() / 2 + data.length() / 2 + 2);
    Log.d("SerialPort", "size = " + size);*/
    }
    }

    public void caculateSize(){
    if (null != this.head && null != this.id && null != this.data) {
    this.size = CommandHelper.intToHexString(head.length() / 2
    + id.length() / 2 + data.length() / 2 + 2);
    Log.d("SerialPort", "size = " + size);
    }
    }

    public boolean caculateCrc() {
    if (null == this.head || null == this.id
    || null == this.data || (data.length() % 2 != 0)) {
    Log.d("SerialPort", "content null");
    return false;
    }
    this.crc = CommandHelper.crcValue(head, id, size, data);
    if (null != this.crc) {
    Log.d("SerialPort", "crc is not null");
    return true;
    } else {
    Log.d("SerialPort", "crc is null");
    return false;
    }

    }
    }

    请注明出处,此文档来自“善思善学”。
  • 相关阅读:
    JVM Ecosystem Report 2020
    TiDB 简介
    Docker镜像分层打包方案
    Promethues + Grafana + AlertManager使用总结
    Spring Boot自动注入原理
    Spring Boot 2.x 自定义Endpoint
    Oracle 等待事件 Enq: CF
    1000行MySQL学习笔记
    PostgreSQL DBA常用SQL查询语句
    MongoDB DBA常用的NoSQL语句
  • 原文地址:https://www.cnblogs.com/gtgl/p/4685126.html
Copyright © 2011-2022 走看看