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;
}

}
}

最新文章

  1. web前后端框架整理
  2. sqlite与多线程
  3. node.js整理 01代码的组织和部署
  4. map/reduce of python
  5. 如何查看postfix的版本
  6. Android NDK 构建 以及一些错误
  7. eth0: error fetching interface information: Device not found
  8. WPF 策略模式
  9. display:inline-block 在IE6中实现{转}
  10. Oracle物理的体系结构
  11. (转)RPC原理详解
  12. php DOMDocument 递归 格式化缩进HTML文档
  13. spring MVC做form提交Neither BindingResult nor plain target object for bean name 'command' available
  14. C#中关于DBNULL的处理方法
  15. iphone缩小uIImage图片
  16. 如何使用cygwin去编译cocos2dx项目中的C++文件
  17. StreamCQL编写jstorm拓扑任务入门
  18. Xcode7 真机免证书调试Cocos2D游戏
  19. [Swift]LeetCode128. 最长连续序列 | Longest Consecutive Sequence
  20. 媒体查询@media 屏幕适配

热门文章

  1. HihoCoder - 1339 Dice Possibility(概率dp)
  2. 特别好用的swagger ui 封装
  3. 调试ASP.NET网站IIS环境问题解决方法汇总
  4. UILable 的 属性设置
  5. 【META http-equiv="Content-Type" Content="text/html; Charset=*】意义详解
  6. Metasploit – 内网连接
  7. C++ vector 多次删除第一个元素
  8. 【bzoj1009】[HNOI2008]GT考试(矩阵快速幂优化dp+kmp)
  9. Hibernate常见优化策略
  10. PAT1054. The Dominant Color (20)