/*
* Copyright 2022 Pnoker All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
Part of Libnodave, a free communication libray for Siemens S7
(C) Thomas Hergenhahn ([email protected]) 2005.
Libnodave is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Libnodave is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package io.github.pnoker.driver.api.impl.nodave;
import io.github.pnoker.driver.api.DaveArea;
/**
* @author Thomas Rudin
*/
public final class PDU {
/**
* known function codes
*/
public final static byte FUNC_READ = 4;
public final static byte FUNC_WRITE = 5;
public int data;
int dlen;
int error;
int header; // the position of the header;
int hlen;
byte[] mem;
public int param; // the position of the parameters;
public int plen;
public int udata;
public int udlen;
/**
* set up the PDU information
*/
public PDU(final byte[] mem, final int pos) {
this.mem = mem;
this.header = pos;
}
public int addBitVarToReadRequest(final int area, final int DBnum, final int start, final int len) {
final byte pa[] = {0x12, 0x0a, 0x10, 0x01, /* single bits */
0x00, 0x1A, /* insert length in bytes here */
0x00, 0x0B, /* insert DB number here */
(byte) 0x84, /* change this to real area code */
0x00, 0x00, (byte) 0xC0 /* insert start address in bits */
};
Nodave.setUSBEWord(pa, 4, len);
Nodave.setUSBEWord(pa, 6, DBnum);
Nodave.setUSBELong(pa, 8, start);
Nodave.setUSByte(pa, 8, area);
this.mem[this.param + 1]++;
System.arraycopy(pa, 0, this.mem, this.param + this.plen, pa.length);
this.plen += pa.length;
Nodave.setUSBEWord(this.mem, this.header + 6, this.plen);
return 0;
}
public void addBitVarToWriteRequest(final DaveArea area, final int DBnum, final int start, final int byteCount,
final byte[] buffer) {
final byte da[] = {0, 3, 0, 0,};
final byte pa[] = {0x12, 0x0a, 0x10, 0x01, /* single bit */
0, 0, /* insert length in bytes here */
0, 0, /* insert DB number here */
0, /* change this to real area code */
0, 0, 0 /* insert start address in bits */
};
if ((area == DaveArea.TIMER) || (area == DaveArea.COUNTER) || (area == DaveArea.TIMER200)
|| (area == DaveArea.COUNTER200)) {
pa[3] = (byte) area.getCode();
pa[4] = (byte) (((byteCount + 1) / 2) / 0x100);
pa[5] = (byte) (((byteCount + 1) / 2) & 0xff);
} else if ((area == DaveArea.ANALOGINPUTS200) || (area == DaveArea.ANALOGOUTPUTS200)) {
pa[3] = 4;
pa[4] = (byte) (((byteCount + 1) / 2) / 0x100);
pa[5] = (byte) (((byteCount + 1) / 2) & 0xff);
} else {
pa[4] = (byte) (byteCount / 0x100);
pa[5] = (byte) (byteCount & 0xff);
}
pa[6] = (byte) (DBnum / 256);
pa[7] = (byte) (DBnum & 0xff);
pa[8] = (byte) area.getCode();
pa[11] = (byte) (start & 0xff);
pa[10] = (byte) ((start / 0x100) & 0xff);
pa[9] = (byte) (start / 0x10000);
if ((this.dlen % 2) != 0) {
this.addData(da, 1);
}
this.mem[this.param + 1]++;
if (this.dlen > 0) {
final byte[] saveData = new byte[this.dlen];
System.arraycopy(this.mem, this.data, saveData, 0, this.dlen);
System.arraycopy(saveData, 0, this.mem, this.data + pa.length, this.dlen);
}
System.arraycopy(pa, 0, this.mem, this.param + this.plen, pa.length);
this.plen += pa.length;
Nodave.setUSBEWord(this.mem, this.header + 6, this.plen);
this.data = this.param + this.plen;
this.addData(da);
this.addValue(buffer);
}
/**
* Add data after parameters, set dlen as needed. Needs valid header and
* parameters
*/
void addData(final byte[] newData) {
final int appPos = this.data + this.dlen; // append to this position
this.dlen += newData.length;
System.arraycopy(newData, 0, this.mem, appPos, newData.length);
Nodave.setUSBEWord(this.mem, this.header + 8, this.dlen);
}
/**
* Add len bytes of len after parameters from a maybe longer block of bytes.
* Set dlen as needed. Needs valid header and parameters
*/
public void addData(final byte[] newData, final int len) {
final int appPos = this.data + this.dlen; // append to this position
this.dlen += len;
System.arraycopy(newData, 0, this.mem, appPos, len);
Nodave.setUSBEWord(this.mem, this.header + 8, this.dlen);
}
public void addParam(final byte[] pa) {
this.plen = pa.length;
System.arraycopy(pa, 0, this.mem, this.param, this.plen);
Nodave.setUSBEWord(this.mem, this.header + 6, this.plen);
// mem[header + 6] = (byte) (pa.length / 256);
// mem[header + 7] = (byte) (pa.length % 256);
this.data = this.param + this.plen;
this.dlen = 0;
}
/*
* add data in user data. Add a user data header, if not yet present.
*/
public void addUserData(final byte[] da) {
final byte udh[] = {(byte) 0xff, 9, 0, 0};
if (this.dlen == 0) {
this.addData(udh);
}
this.addValue(da);
}
/**
* Add values after value header in data, adjust dlen and data count. Needs
* valid header,parameters,data,dlen
*/
void addValue(final byte[] values) {
int valCount = (0x100 * this.mem[this.data + 2]) + this.mem[this.data + 3];
if (this.mem[this.data + 1] == 4) { // bit data, length is in bits
valCount += 8 * values.length;
} else if (this.mem[this.data + 1] == 9) { // byte data, length is in
// bytes
valCount += values.length;
} else {
// XXX
}
if (this.udata == 0) {
this.udata = this.data + 4;
}
this.udlen += values.length;
Nodave.setUSBEWord(this.mem, this.data + 2, valCount);
this.addData(values);
}
public int addVarToReadRequest(final DaveArea area, final int DBnum, int start, final int len) {
final byte[] pa = {0x12, 0x0a, 0x10,
0x02, /* 1=single bit, 2=byte, 4=word */
0x00, 0x1A, /* length in bytes */
0x00, 0x0B, /* DB number */
(byte) 0x84, // * area code */
0x00, 0x00, (byte) 0xC0 /* start address in bits */
};
if ((area == DaveArea.ANALOGINPUTS200) || (area == DaveArea.ANALOGOUTPUTS200)) {
pa[3] = 4;
start *= 8; /* bits */
} else if ((area == DaveArea
没有合适的资源?快使用搜索试试~ 我知道了~
iot-dc3-master.zip
共1028个文件
java:467个
png:133个
yml:84个
0 下载量 123 浏览量
2023-03-11
09:51:19
上传
评论
收藏 24.43MB ZIP 举报
温馨提示
DC3是一个基于Spring Cloud的开源的、分布式的物联网(IOT)平台,用于快速开发物联网项目和管理物联设备,是一整套物联系统解决方案。
资源推荐
资源详情
资源评论
收起资源包目录
iot-dc3-master.zip (1028个子文件)
CNAME 12B
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
redis.conf 92KB
emqx.conf 69KB
emqx.conf 69KB
emqx.conf 69KB
emqx.conf 68KB
rabbitmq.conf 35KB
rabbitmq.conf 35KB
rabbitmq.conf 35KB
emqx_exproto.conf 10KB
emqx_lwm2m.conf 6KB
emqx_bridge_mqtt.conf 5KB
emqx_auth_http.conf 5KB
emqx_dashboard.conf 5KB
emqx_dashboard.conf 5KB
emqx_dashboard.conf 5KB
emqx_auth_mongo.conf 5KB
emqx_dashboard.conf 5KB
emqx_stomp.conf 4KB
emqx_coap.conf 4KB
emqx_management.conf 3KB
emqx_management.conf 3KB
emqx_management.conf 3KB
emqx_auth_mysql.conf 3KB
emqx_management.conf 3KB
emqx_auth_pgsql.conf 3KB
emqx_web_hook.conf 3KB
emqx_auth_redis.conf 3KB
emqx_rule_engine.conf 2KB
emqx_sn.conf 2KB
emqx_auth_ldap.conf 2KB
mongo.conf 2KB
mongo.conf 2KB
mongo.conf 2KB
emqx_retainer.conf 2KB
keepalived.conf 1KB
emqx_auth_jwt.conf 1KB
config.conf 1KB
config.conf 1KB
config.conf 1KB
rabbitmq-env.conf 1KB
rabbitmq-env.conf 1KB
rabbitmq-env.conf 1KB
emqx_telemetry.conf 1KB
emqx_auth_clientid.conf 1KB
emqx_auth_mnesia.conf 1KB
emqx_extension_hook.conf 1KB
emqx_prometheus.conf 1020B
emqx_reloader.conf 982B
rabbitmq.conf 814B
emqx_lua_hook.conf 757B
emqx_recon.conf 755B
mongos.conf 728B
mongos.conf 728B
mongos.conf 728B
emqx_psk_file.conf 646B
emqx_sasl.conf 596B
advanced.config 3KB
advanced.config 3KB
advanced.config 3KB
server.crt 1KB
ca.crt 1KB
ca.crt 1KB
server.crt 1KB
ca.crt 1KB
server.crt 1KB
ca.crt 1KB
client.crt 1KB
server.crt 1KB
client.crt 1KB
ca.crt 1KB
ca.crt 1KB
client.crt 1KB
fx.crt 1KB
client.csr 972B
server.csr 972B
fx.csr 968B
wro.css 166KB
bootstrap.min.css 152KB
font-awesome.css 37KB
templatemo-art-factory.css 27KB
flex-slider.css 7KB
owl-carousel.css 5KB
dc3-group.db 156KB
dc3-listening-virtual 2KB
dc3-modbus 2KB
dc3-mqtt 1KB
dc3-opcda 2KB
dc3-opcua 1KB
dc3-plcs7 2KB
dc3-virtual 2KB
Dockerfile 2KB
共 1028 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功