├── README.md
├── .gitignore
├── src
└── main
│ ├── resources
│ ├── YC.properties
│ ├── YX.properties
│ ├── cause.properties
│ ├── rabbitmq.properties
│ ├── typeId.properties
│ ├── log4j.properties
│ ├── database.properties
│ ├── yx.json
│ └── yc.json
│ └── java
│ └── com
│ └── visenergy
│ └── iec104
│ ├── IeQuality.java
│ ├── IeQualifierOfInterrogation.java
│ ├── IeSinglePointWithQuality.java
│ ├── InformationElement.java
│ ├── IeShortFloat.java
│ ├── Init.java
│ ├── util
│ ├── FileUtils.java
│ ├── RabbitMqUtils.java
│ └── ChangeUtils.java
│ ├── IeAbstractQuality.java
│ ├── DataProcessPool.java
│ ├── Test.java
│ ├── InformationObject.java
│ ├── Apdu.java
│ ├── YxStatusObject.java
│ ├── Asdu.java
│ ├── ServerTest.java
│ ├── YxObject.java
│ ├── GenerateYxStatus.java
│ ├── Client.java
│ └── YcObject.java
└── pom.xml
/README.md:
--------------------------------------------------------------------------------
1 | # IEC104
2 | 用于与光伏之间进行通信
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | .idea
3 | IEC104.iml
4 | target
5 | logs/
6 |
--------------------------------------------------------------------------------
/src/main/resources/YC.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huarda/IEC104-1/HEAD/src/main/resources/YC.properties
--------------------------------------------------------------------------------
/src/main/resources/YX.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huarda/IEC104-1/HEAD/src/main/resources/YX.properties
--------------------------------------------------------------------------------
/src/main/resources/cause.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huarda/IEC104-1/HEAD/src/main/resources/cause.properties
--------------------------------------------------------------------------------
/src/main/resources/rabbitmq.properties:
--------------------------------------------------------------------------------
1 | host=rabbitmq
2 | port=5672
3 | username=admin
4 | password=123456
5 | virtualhost=/
--------------------------------------------------------------------------------
/src/main/resources/typeId.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huarda/IEC104-1/HEAD/src/main/resources/typeId.properties
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #根日志配置,级别是info,控制台输出
2 | log4j.rootLogger=debug,stdout,file
3 | #控制台输出格式
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
6 | log4j.appender.stdout.layout.conversionPattern=%5p %d [%t] - %m%n
7 | #文件输出格式
8 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
9 | log4j.appender.file.File=logs/flying_
10 | log4j.appender.file.DatePattern=yyyy-MM-dd'.log'
11 | log4j.appender.file.MaxFileSize=10MB
12 | log4j.appender.file.MaxBackupIndex=0
13 | log4j.appender.file.layout=org.apache.log4j.SimpleLayout
14 | log4j.appender.file.layout.ConversionPattern=[ssh] %p %t %c - %m%n
15 | #
--------------------------------------------------------------------------------
/src/main/resources/database.properties:
--------------------------------------------------------------------------------
1 | !oracle
2 | !driver=oracle.jdbc.driver.OracleDriver
3 | !url=jdbc:oracle:thin:@27.17.26.93:1521:ORCL
4 | !url=jdbc:oracle:thin:@localhost:1521:ORCL
5 | !username=szhd
6 | !password=szhd
7 |
8 | !sql server
9 | !driver=net.sourceforge.jtds.jdbc.Driver
10 | !url=jdbc:jtds:sqlserver://192.168.88.157:1433/Dsideal_Training_DB
11 | !username=sa
12 | !password=dsideal
13 |
14 | !mysql
15 | driver=com.mysql.jdbc.Driver
16 | url=jdbc:mysql://mysql:3306/emanagenew?useUnicode=true&characterEncoding=UTF-8&useSSL=false
17 | username=root
18 | password=123456
19 | !url=jdbc:mysql://192.168.210.4:3306/guankoustation?useUnicode=true&characterEncoding=UTF-8
20 | !username=visDB1
21 | !password=Visenergy2015
22 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/IeQuality.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.IOException;
5 |
6 | /**
7 | * 品质描述
8 | *
9 | */
10 | public class IeQuality extends IeAbstractQuality {
11 |
12 | public IeQuality(boolean overflow, boolean blocked, boolean substituted, boolean notTopical, boolean invalid) {
13 | super(blocked, substituted, notTopical, invalid);
14 |
15 | if (overflow) {
16 | value |= 0x01;
17 | }
18 | }
19 |
20 | IeQuality(DataInputStream is) throws IOException {
21 | super(is);
22 | }
23 |
24 | public boolean isOverflow() {
25 | return (value & 0x01) == 0x01;
26 | }
27 |
28 | @Override
29 | public String toString() {
30 | return "品质描述, 溢出: " + isOverflow() + ", " + super.toString();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/IeQualifierOfInterrogation.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.IOException;
5 |
6 | public class IeQualifierOfInterrogation extends InformationElement {
7 |
8 | private final int value;
9 |
10 | public IeQualifierOfInterrogation(int value) {
11 | this.value = value;
12 | }
13 |
14 | public IeQualifierOfInterrogation(DataInputStream is) throws IOException {
15 | value = (is.readByte() & 0xff);
16 | }
17 |
18 | @Override
19 | public int encode(byte[] buffer, int i) {
20 | buffer[i] = (byte) value;
21 | return 1;
22 | }
23 |
24 | public int getValue() {
25 | return value;
26 | }
27 |
28 | @Override
29 | public String toString() {
30 | return "Qualifier of interrogation: " + value;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/IeSinglePointWithQuality.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.IOException;
5 |
6 | /**
7 | * 单点信息
8 | *
9 | */
10 | public class IeSinglePointWithQuality extends IeAbstractQuality {
11 |
12 | public IeSinglePointWithQuality(boolean on, boolean blocked, boolean substituted, boolean notTopical,
13 | boolean invalid) {
14 | super(blocked, substituted, notTopical, invalid);
15 |
16 | if (on) {
17 | value |= 0x01;
18 | }
19 | }
20 |
21 | public IeSinglePointWithQuality(DataInputStream is) throws IOException {
22 | super(is);
23 | }
24 |
25 | public boolean isOn() {
26 | return (value & 0x01) == 0x01;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "单点, 是否开闸: " + isOn() + ", " + super.toString();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/InformationElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-17 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package com.visenergy.iec104;
22 |
23 | public abstract class InformationElement {
24 |
25 | public abstract int encode(byte[] buffer, int i);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/IeShortFloat.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.IOException;
5 |
6 | /**
7 | * 类型标识,测量值,短浮点数
8 | * 遥测
9 | */
10 | public class IeShortFloat extends InformationElement {
11 |
12 | private final float value;
13 |
14 | public IeShortFloat(float value) {
15 | this.value = value;
16 | }
17 |
18 | public IeShortFloat(DataInputStream is) throws IOException {
19 | value = Float.intBitsToFloat((is.readByte() & 0xff) | ((is.readByte() & 0xff) << 8)
20 | | ((is.readByte() & 0xff) << 16) | ((is.readByte() & 0xff) << 24));
21 | }
22 |
23 | @Override
24 | public int encode(byte[] buffer, int i) {
25 |
26 | int tempVal = Float.floatToIntBits(value);
27 | buffer[i++] = (byte) tempVal;
28 | buffer[i++] = (byte) (tempVal >> 8);
29 | buffer[i++] = (byte) (tempVal >> 16);
30 | buffer[i] = (byte) (tempVal >> 24);
31 |
32 | return 4;
33 | }
34 |
35 | public float getValue() {
36 | return value;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "短浮点数值: " + value;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/Init.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import com.flying.jdbc.SqlHelper;
4 | import com.flying.jdbc.util.DBConnectionPool;
5 | import com.visenergy.iec104.util.FileUtils;
6 | import net.sf.json.JSONObject;
7 | import org.apache.commons.logging.Log;
8 | import org.apache.commons.logging.LogFactory;
9 |
10 | import java.util.Properties;
11 |
12 | /**
13 | * Created by Administrator on 2017/7/25 0025.
14 | */
15 | public class Init {
16 | private static Log log = LogFactory.getLog(Init.class);
17 |
18 | public static Properties typeIdProp = null;
19 | public static Properties causeProp = null;
20 | public static JSONObject ycJsonObj = null;
21 | public static JSONObject yxJsonObj = null;
22 |
23 | public static void start(){
24 | initDb();
25 | initBusinessData();
26 | DataProcessPool.initPool();
27 | }
28 |
29 | public static void initDb(){
30 | log.debug("建立数据库连接池,连接数量是10");
31 | SqlHelper.connPool = new DBConnectionPool(10);
32 | }
33 |
34 | public static void initBusinessData(){
35 | try {
36 | log.debug("解析配置文件");
37 | typeIdProp = FileUtils.loadPropFile("typeId.properties");
38 | causeProp = FileUtils.loadPropFile("cause.properties");
39 | ycJsonObj = FileUtils.loadJsonFile("yc.json");
40 | yxJsonObj = FileUtils.loadJsonFile("yx.json");
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/util/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104.util;
2 |
3 | import net.sf.json.JSONObject;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 | import java.util.Properties;
10 |
11 | /**
12 | * Created by Fuxudong on 2017-6-12.
13 | * @Description 加载property配置文件
14 | */
15 | public class FileUtils {
16 | public static Properties loadPropFile(String filePath) throws Exception{
17 | InputStream is = FileUtils.class.getClassLoader().getResourceAsStream(filePath);
18 | InputStreamReader isr = new InputStreamReader(is, "GBK");
19 | Properties properties = new Properties();
20 | try {
21 | properties.load(isr);
22 | }catch (IOException ex){
23 | ex.printStackTrace();
24 | }finally {
25 | is.close();
26 | isr.close();
27 | }
28 | return properties;
29 | }
30 |
31 | public static JSONObject loadJsonFile(String filePath) throws Exception{
32 | InputStream is = FileUtils.class.getClassLoader().getResourceAsStream(filePath);
33 | BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
34 | StringBuffer jsonStrBuff = new StringBuffer();
35 | String brStr = null;
36 | while ((brStr =br.readLine()) != null){
37 | jsonStrBuff.append(brStr);
38 | }
39 | return JSONObject.fromObject(jsonStrBuff.toString());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/IeAbstractQuality.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.IOException;
5 |
6 | /**
7 | * 品质描述
8 | */
9 | abstract class IeAbstractQuality extends InformationElement {
10 |
11 | protected int value;
12 |
13 | public IeAbstractQuality(boolean blocked, boolean substituted, boolean notTopical, boolean invalid) {
14 |
15 | value = 0;
16 |
17 | if (blocked) {
18 | value |= 0x10;
19 | }
20 | if (substituted) {
21 | value |= 0x20;
22 | }
23 | if (notTopical) {
24 | value |= 0x40;
25 | }
26 | if (invalid) {
27 | value |= 0x80;
28 | }
29 |
30 | }
31 |
32 | public IeAbstractQuality(DataInputStream is) throws IOException {
33 | value = (is.readByte() & 0xff);
34 | }
35 |
36 | @Override
37 | public int encode(byte[] buffer, int i) {
38 | buffer[i] = (byte) value;
39 | return 1;
40 | }
41 |
42 | public boolean isBlocked() {
43 | return (value & 0x10) == 0x10;
44 | }
45 |
46 | public boolean isSubstituted() {
47 | return (value & 0x20) == 0x20;
48 | }
49 |
50 | public boolean isNotTopical() {
51 | return (value & 0x40) == 0x40;
52 | }
53 |
54 | public boolean isInvalid() {
55 | return (value & 0x80) == 0x80;
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return "被封锁: " + isBlocked() + ", 被取代: " + isSubstituted() + ", 非当前值: " + isNotTopical()
61 | + ", 是否有效: " + isInvalid();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/visenergy/iec104/DataProcessPool.java:
--------------------------------------------------------------------------------
1 | package com.visenergy.iec104;
2 |
3 | import com.flying.jdbc.SqlHelper;
4 | import com.flying.jdbc.data.CommandType;
5 | import com.flying.jdbc.util.DBConnection;
6 | import org.apache.commons.logging.Log;
7 | import org.apache.commons.logging.LogFactory;
8 |
9 | import java.util.HashMap;
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | /**
14 | * Created by zhonghuan on 2017/7/25.
15 | */
16 | public class DataProcessPool {
17 | private static Log log = LogFactory.getLog(DataProcessPool.class);
18 |
19 | public static Map ycPool = new HashMap();
20 | public static Map yxPool = new HashMap();
21 | public static Map yxsPool = new HashMap();
22 |
23 |
24 | public static void initPool(){
25 | log.debug("初始化对象池对象");
26 | DBConnection conn = SqlHelper.connPool.getConnection();
27 | try {
28 | //查询所有逆变器的序列号、ID、所属楼宇ID
29 | String sql = "SELECT A.INVERTER_ID,A.SERIAL,A.BUILDING_ID FROM T_PVMANAGE_INVERTER A";
30 | List