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;
}
}
}
最新文章
- web前后端框架整理
- sqlite与多线程
- node.js整理 01代码的组织和部署
- map/reduce of python
- 如何查看postfix的版本
- Android NDK 构建 以及一些错误
- eth0: error fetching interface information: Device not found
- WPF 策略模式
- display:inline-block 在IE6中实现{转}
- Oracle物理的体系结构
- (转)RPC原理详解
- php DOMDocument 递归 格式化缩进HTML文档
- spring MVC做form提交Neither BindingResult nor plain target object for bean name 'command' available
- C#中关于DBNULL的处理方法
- iphone缩小uIImage图片
- 如何使用cygwin去编译cocos2dx项目中的C++文件
- StreamCQL编写jstorm拓扑任务入门
- Xcode7 真机免证书调试Cocos2D游戏
- [Swift]LeetCode128. 最长连续序列 | Longest Consecutive Sequence
- 媒体查询@media 屏幕适配
热门文章
- HihoCoder - 1339 Dice Possibility(概率dp)
- 特别好用的swagger ui 封装
- 调试ASP.NET网站IIS环境问题解决方法汇总
- UILable 的 属性设置
- 【META http-equiv=";Content-Type"; Content=";text/html; Charset=*】意义详解
- Metasploit – 内网连接
- C++ vector 多次删除第一个元素
- 【bzoj1009】[HNOI2008]GT考试(矩阵快速幂优化dp+kmp)
- Hibernate常见优化策略
- PAT1054. The Dominant Color (20)