Commit 27f727e0f7b05f77c6a0a66accbeab4e4f13f3bf
0 parents
Init
Showing
87 changed files
with
8963 additions
and
0 deletions
.idea/artifacts/gb32960_server_war.xml
0 → 100644
| 1 | +++ a/.idea/artifacts/gb32960_server_war.xml | ||
| 1 | +<component name="ArtifactManager"> | ||
| 2 | + <artifact type="war" name="gb32960_server:war"> | ||
| 3 | + <output-path>$PROJECT_DIR$/target</output-path> | ||
| 4 | + <properties id="maven-jee-properties"> | ||
| 5 | + <options> | ||
| 6 | + <module>gb32960_server</module> | ||
| 7 | + <packaging>war</packaging> | ||
| 8 | + </options> | ||
| 9 | + </properties> | ||
| 10 | + <root id="archive" name="transport_server-0.0.1-SNAPSHOT.war"> | ||
| 11 | + <element id="artifact" artifact-name="gb32960_server:war exploded" /> | ||
| 12 | + </root> | ||
| 13 | + </artifact> | ||
| 14 | +</component> | ||
| 0 | \ No newline at end of file | 15 | \ No newline at end of file |
.idea/artifacts/gb32960_server_war_exploded.xml
0 → 100644
| 1 | +++ a/.idea/artifacts/gb32960_server_war_exploded.xml | ||
| 1 | +<component name="ArtifactManager"> | ||
| 2 | + <artifact type="exploded-war" name="gb32960_server:war exploded"> | ||
| 3 | + <output-path>$PROJECT_DIR$/target/transport_server-0.0.1-SNAPSHOT</output-path> | ||
| 4 | + <properties id="maven-jee-properties"> | ||
| 5 | + <options> | ||
| 6 | + <exploded>true</exploded> | ||
| 7 | + <module>gb32960_server</module> | ||
| 8 | + <packaging>war</packaging> | ||
| 9 | + </options> | ||
| 10 | + </properties> | ||
| 11 | + <root id="root"> | ||
| 12 | + <element id="directory" name="WEB-INF"> | ||
| 13 | + <element id="directory" name="classes"> | ||
| 14 | + <element id="module-output" name="gb32960_server" /> | ||
| 15 | + </element> | ||
| 16 | + <element id="directory" name="lib"> | ||
| 17 | + <element id="library" level="project" name="Maven: javax.servlet:servlet-api:2.5" /> | ||
| 18 | + <element id="library" level="project" name="Maven: javax.servlet.jsp:jsp-api:2.1" /> | ||
| 19 | + <element id="library" level="project" name="Maven: javax.servlet:jstl:1.2" /> | ||
| 20 | + <element id="library" level="project" name="Maven: taglibs:standard:1.1.2" /> | ||
| 21 | + <element id="library" level="project" name="Maven: org.apache.mina:mina-core:2.0.13" /> | ||
| 22 | + <element id="library" level="project" name="Maven: org.springframework:spring-core:3.0.6.RELEASE" /> | ||
| 23 | + <element id="library" level="project" name="Maven: org.springframework:spring-asm:3.0.6.RELEASE" /> | ||
| 24 | + <element id="library" level="project" name="Maven: commons-logging:commons-logging:1.1.1" /> | ||
| 25 | + <element id="library" level="project" name="Maven: org.springframework:spring-beans:3.0.6.RELEASE" /> | ||
| 26 | + <element id="library" level="project" name="Maven: org.springframework:spring-context:3.0.6.RELEASE" /> | ||
| 27 | + <element id="library" level="project" name="Maven: org.springframework:spring-expression:3.0.6.RELEASE" /> | ||
| 28 | + <element id="library" level="project" name="Maven: org.springframework:spring-aop:3.0.6.RELEASE" /> | ||
| 29 | + <element id="library" level="project" name="Maven: aopalliance:aopalliance:1.0" /> | ||
| 30 | + <element id="library" level="project" name="Maven: org.springframework:spring-orm:3.0.6.RELEASE" /> | ||
| 31 | + <element id="library" level="project" name="Maven: org.springframework:spring-tx:3.0.6.RELEASE" /> | ||
| 32 | + <element id="library" level="project" name="Maven: org.springframework:spring-jdbc:3.0.6.RELEASE" /> | ||
| 33 | + <element id="library" level="project" name="Maven: org.springframework:spring-web:3.0.6.RELEASE" /> | ||
| 34 | + <element id="library" level="project" name="Maven: org.springframework:spring-webmvc:3.0.6.RELEASE" /> | ||
| 35 | + <element id="library" level="project" name="Maven: org.springframework:spring-context-support:3.0.6.RELEASE" /> | ||
| 36 | + <element id="library" level="project" name="Maven: org.aspectj:aspectjweaver:1.6.8" /> | ||
| 37 | + <element id="library" level="project" name="Maven: cglib:cglib-nodep:2.2" /> | ||
| 38 | + <element id="library" level="project" name="Maven: commons-dbcp:commons-dbcp:1.3" /> | ||
| 39 | + <element id="library" level="project" name="Maven: commons-pool:commons-pool:1.5.4" /> | ||
| 40 | + <element id="library" level="project" name="Maven: commons-codec:commons-codec:1.3" /> | ||
| 41 | + <element id="library" level="project" name="Maven: commons-io:commons-io:1.3.2" /> | ||
| 42 | + <element id="library" level="project" name="Maven: commons-beanutils:commons-beanutils:1.8.3" /> | ||
| 43 | + <element id="library" level="project" name="Maven: commons-fileupload:commons-fileupload:1.2.1" /> | ||
| 44 | + <element id="library" level="project" name="Maven: mysql:mysql-connector-java:5.1.38" /> | ||
| 45 | + <element id="library" level="project" name="Maven: org.slf4j:slf4j-api:1.7.21" /> | ||
| 46 | + <element id="library" level="project" name="Maven: org.apache.logging.log4j:log4j-api:2.7" /> | ||
| 47 | + <element id="library" level="project" name="Maven: org.apache.logging.log4j:log4j-core:2.7" /> | ||
| 48 | + <element id="library" level="project" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.7" /> | ||
| 49 | + <element id="library" level="project" name="Maven: com.lmax:disruptor:3.0.1" /> | ||
| 50 | + <element id="library" level="project" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.11" /> | ||
| 51 | + <element id="library" level="project" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.11" /> | ||
| 52 | + <element id="library" level="project" name="Maven: org.quartz-scheduler:quartz:1.8.5" /> | ||
| 53 | + <element id="library" level="project" name="Maven: javax.transaction:jta:1.1" /> | ||
| 54 | + <element id="library" level="project" name="Maven: joda-time:joda-time:2.8.2" /> | ||
| 55 | + </element> | ||
| 56 | + </element> | ||
| 57 | + <element id="directory" name="META-INF"> | ||
| 58 | + <element id="file-copy" path="$PROJECT_DIR$/target/transport_server-0.0.1-SNAPSHOT/META-INF/MANIFEST.MF" /> | ||
| 59 | + </element> | ||
| 60 | + <element id="javaee-facet-resources" facet="gb32960_server/web/Web" /> | ||
| 61 | + </root> | ||
| 62 | + </artifact> | ||
| 63 | +</component> | ||
| 0 | \ No newline at end of file | 64 | \ No newline at end of file |
.idea/jarRepositories.xml
0 → 100644
| 1 | +++ a/.idea/jarRepositories.xml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project version="4"> | ||
| 3 | + <component name="RemoteRepositoriesConfiguration"> | ||
| 4 | + <remote-repository> | ||
| 5 | + <option name="id" value="public-snapshots" /> | ||
| 6 | + <option name="name" value="public-snapshots" /> | ||
| 7 | + <option name="url" value="http://104.224.181.229:8081/repository/maven-snapshots/" /> | ||
| 8 | + </remote-repository> | ||
| 9 | + <remote-repository> | ||
| 10 | + <option name="id" value="central" /> | ||
| 11 | + <option name="name" value="Central Repository" /> | ||
| 12 | + <option name="url" value="http://104.224.181.229:8081/repository/maven-public" /> | ||
| 13 | + </remote-repository> | ||
| 14 | + <remote-repository> | ||
| 15 | + <option name="id" value="central" /> | ||
| 16 | + <option name="name" value="Maven Central repository" /> | ||
| 17 | + <option name="url" value="https://repo1.maven.org/maven2" /> | ||
| 18 | + </remote-repository> | ||
| 19 | + <remote-repository> | ||
| 20 | + <option name="id" value="jboss.community" /> | ||
| 21 | + <option name="name" value="JBoss Community repository" /> | ||
| 22 | + <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> | ||
| 23 | + </remote-repository> | ||
| 24 | + <remote-repository> | ||
| 25 | + <option name="id" value="central" /> | ||
| 26 | + <option name="name" value="Central Repository" /> | ||
| 27 | + <option name="url" value="https://maven.aliyun.com/repository/central" /> | ||
| 28 | + </remote-repository> | ||
| 29 | + <remote-repository> | ||
| 30 | + <option name="id" value="public-snapshots" /> | ||
| 31 | + <option name="name" value="public-snapshots" /> | ||
| 32 | + <option name="url" value="http://public-snapshots" /> | ||
| 33 | + </remote-repository> | ||
| 34 | + </component> | ||
| 35 | +</project> | ||
| 0 | \ No newline at end of file | 36 | \ No newline at end of file |
.idea/uiDesigner.xml
0 → 100644
| 1 | +++ a/.idea/uiDesigner.xml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project version="4"> | ||
| 3 | + <component name="Palette2"> | ||
| 4 | + <group name="Swing"> | ||
| 5 | + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 6 | + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> | ||
| 7 | + </item> | ||
| 8 | + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 9 | + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> | ||
| 10 | + </item> | ||
| 11 | + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 12 | + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> | ||
| 13 | + </item> | ||
| 14 | + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> | ||
| 15 | + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> | ||
| 16 | + </item> | ||
| 17 | + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 18 | + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> | ||
| 19 | + <initial-values> | ||
| 20 | + <property name="text" value="Button" /> | ||
| 21 | + </initial-values> | ||
| 22 | + </item> | ||
| 23 | + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 24 | + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | ||
| 25 | + <initial-values> | ||
| 26 | + <property name="text" value="RadioButton" /> | ||
| 27 | + </initial-values> | ||
| 28 | + </item> | ||
| 29 | + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 30 | + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | ||
| 31 | + <initial-values> | ||
| 32 | + <property name="text" value="CheckBox" /> | ||
| 33 | + </initial-values> | ||
| 34 | + </item> | ||
| 35 | + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 36 | + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> | ||
| 37 | + <initial-values> | ||
| 38 | + <property name="text" value="Label" /> | ||
| 39 | + </initial-values> | ||
| 40 | + </item> | ||
| 41 | + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 42 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | ||
| 43 | + <preferred-size width="150" height="-1" /> | ||
| 44 | + </default-constraints> | ||
| 45 | + </item> | ||
| 46 | + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 47 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | ||
| 48 | + <preferred-size width="150" height="-1" /> | ||
| 49 | + </default-constraints> | ||
| 50 | + </item> | ||
| 51 | + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 52 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | ||
| 53 | + <preferred-size width="150" height="-1" /> | ||
| 54 | + </default-constraints> | ||
| 55 | + </item> | ||
| 56 | + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 57 | + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | ||
| 58 | + <preferred-size width="150" height="50" /> | ||
| 59 | + </default-constraints> | ||
| 60 | + </item> | ||
| 61 | + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 62 | + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | ||
| 63 | + <preferred-size width="150" height="50" /> | ||
| 64 | + </default-constraints> | ||
| 65 | + </item> | ||
| 66 | + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 67 | + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | ||
| 68 | + <preferred-size width="150" height="50" /> | ||
| 69 | + </default-constraints> | ||
| 70 | + </item> | ||
| 71 | + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 72 | + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> | ||
| 73 | + </item> | ||
| 74 | + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 75 | + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | ||
| 76 | + <preferred-size width="150" height="50" /> | ||
| 77 | + </default-constraints> | ||
| 78 | + </item> | ||
| 79 | + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 80 | + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> | ||
| 81 | + <preferred-size width="150" height="50" /> | ||
| 82 | + </default-constraints> | ||
| 83 | + </item> | ||
| 84 | + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 85 | + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | ||
| 86 | + <preferred-size width="150" height="50" /> | ||
| 87 | + </default-constraints> | ||
| 88 | + </item> | ||
| 89 | + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 90 | + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | ||
| 91 | + <preferred-size width="200" height="200" /> | ||
| 92 | + </default-constraints> | ||
| 93 | + </item> | ||
| 94 | + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 95 | + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | ||
| 96 | + <preferred-size width="200" height="200" /> | ||
| 97 | + </default-constraints> | ||
| 98 | + </item> | ||
| 99 | + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> | ||
| 100 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | ||
| 101 | + </item> | ||
| 102 | + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 103 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | ||
| 104 | + </item> | ||
| 105 | + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 106 | + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> | ||
| 107 | + </item> | ||
| 108 | + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 109 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> | ||
| 110 | + </item> | ||
| 111 | + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 112 | + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> | ||
| 113 | + <preferred-size width="-1" height="20" /> | ||
| 114 | + </default-constraints> | ||
| 115 | + </item> | ||
| 116 | + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | ||
| 117 | + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> | ||
| 118 | + </item> | ||
| 119 | + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | ||
| 120 | + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> | ||
| 121 | + </item> | ||
| 122 | + </group> | ||
| 123 | + </component> | ||
| 124 | +</project> | ||
| 0 | \ No newline at end of file | 125 | \ No newline at end of file |
README.md
0 → 100644
gb32960_server.iml
0 → 100644
| 1 | +++ a/gb32960_server.iml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<module version="4"> | ||
| 3 | + <component name="FacetManager"> | ||
| 4 | + <facet type="jpa" name="JPA"> | ||
| 5 | + <configuration> | ||
| 6 | + <setting name="validation-enabled" value="true" /> | ||
| 7 | + <datasource-mapping> | ||
| 8 | + <factory-entry name="gb32960_server" /> | ||
| 9 | + <factory-entry name="transport_server" /> | ||
| 10 | + </datasource-mapping> | ||
| 11 | + <naming-strategy-map /> | ||
| 12 | + </configuration> | ||
| 13 | + </facet> | ||
| 14 | + <facet type="Spring" name="Spring"> | ||
| 15 | + <configuration /> | ||
| 16 | + </facet> | ||
| 17 | + </component> | ||
| 18 | +</module> | ||
| 0 | \ No newline at end of file | 19 | \ No newline at end of file |
pom.xml
0 → 100644
| 1 | +++ a/pom.xml | ||
| 1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 2 | + <modelVersion>4.0.0</modelVersion> | ||
| 3 | + <groupId>gb32960_server</groupId> | ||
| 4 | + <artifactId>gb32960_server</artifactId> | ||
| 5 | + <version>0.0.1-SNAPSHOT</version> | ||
| 6 | + <packaging>jar</packaging> | ||
| 7 | + <parent> | ||
| 8 | + <groupId>org.springframework.boot</groupId> | ||
| 9 | + <artifactId>spring-boot-starter-parent</artifactId> | ||
| 10 | + <version>2.5.14</version> | ||
| 11 | + </parent> | ||
| 12 | + | ||
| 13 | + <properties> | ||
| 14 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 15 | + <mina.version>2.0.13</mina.version> | ||
| 16 | + <spring.version>3.0.6.RELEASE</spring.version> | ||
| 17 | + </properties> | ||
| 18 | + <dependencies> | ||
| 19 | + <dependency> | ||
| 20 | + <groupId>org.springframework.boot</groupId> | ||
| 21 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 22 | + </dependency> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>org.springframework.kafka</groupId> | ||
| 25 | + <artifactId>spring-kafka</artifactId> | ||
| 26 | + </dependency> | ||
| 27 | + <dependency> | ||
| 28 | + <groupId>org.springframework.boot</groupId> | ||
| 29 | + <artifactId>spring-boot-starter-jdbc</artifactId> | ||
| 30 | + </dependency> | ||
| 31 | + | ||
| 32 | + <dependency> | ||
| 33 | + <groupId>org.apache.mina</groupId> | ||
| 34 | + <artifactId>mina-core</artifactId> | ||
| 35 | + <version>${mina.version}</version> | ||
| 36 | + </dependency> | ||
| 37 | + | ||
| 38 | + <dependency> | ||
| 39 | + <groupId>joda-time</groupId> | ||
| 40 | + <artifactId>joda-time</artifactId> | ||
| 41 | + <version>2.10.2</version> | ||
| 42 | + </dependency> | ||
| 43 | + | ||
| 44 | + <dependency> | ||
| 45 | + <groupId>commons-codec</groupId> | ||
| 46 | + <artifactId>commons-codec</artifactId> | ||
| 47 | + <version>1.3</version> | ||
| 48 | + </dependency> | ||
| 49 | + | ||
| 50 | + <dependency> | ||
| 51 | + <groupId>commons-io</groupId> | ||
| 52 | + <artifactId>commons-io</artifactId> | ||
| 53 | + <version>1.3.2</version> | ||
| 54 | + </dependency> | ||
| 55 | + | ||
| 56 | + <dependency> | ||
| 57 | + <groupId>commons-beanutils</groupId> | ||
| 58 | + <artifactId>commons-beanutils</artifactId> | ||
| 59 | + <version>1.8.3</version> | ||
| 60 | + </dependency> | ||
| 61 | + | ||
| 62 | + <dependency> | ||
| 63 | + <groupId>commons-fileupload</groupId> | ||
| 64 | + <artifactId>commons-fileupload</artifactId> | ||
| 65 | + <version>1.2.1</version> | ||
| 66 | + </dependency> | ||
| 67 | + | ||
| 68 | + <dependency> | ||
| 69 | + <groupId>mysql</groupId> | ||
| 70 | + <artifactId>mysql-connector-java</artifactId> | ||
| 71 | + </dependency> | ||
| 72 | + </dependencies> | ||
| 73 | + <build> | ||
| 74 | + <plugins> | ||
| 75 | + <plugin> | ||
| 76 | + <artifactId>maven-war-plugin</artifactId> | ||
| 77 | + </plugin> | ||
| 78 | + <plugin> | ||
| 79 | + <artifactId>maven-compiler-plugin</artifactId> | ||
| 80 | + <configuration> | ||
| 81 | + <source>1.8</source> | ||
| 82 | + <target>1.8</target> | ||
| 83 | + </configuration> | ||
| 84 | + </plugin> | ||
| 85 | + <plugin> | ||
| 86 | + <groupId>org.springframework.boot</groupId> | ||
| 87 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 88 | + <configuration> | ||
| 89 | + <mainClass>com.bsth.Application</mainClass> | ||
| 90 | + </configuration> | ||
| 91 | + <executions> | ||
| 92 | + <execution> | ||
| 93 | + <goals> | ||
| 94 | + <goal>repackage</goal> | ||
| 95 | + </goals> | ||
| 96 | + </execution> | ||
| 97 | + </executions> | ||
| 98 | + </plugin> | ||
| 99 | + </plugins> | ||
| 100 | + </build> | ||
| 101 | +</project> | ||
| 0 | \ No newline at end of file | 102 | \ No newline at end of file |
src/main/java/com/bsth/Application.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/Application.java | ||
| 1 | +package com.bsth; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.AppProperties; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.boot.SpringApplication; | ||
| 6 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + */ | ||
| 11 | +@SpringBootApplication | ||
| 12 | +public class Application { | ||
| 13 | + | ||
| 14 | + @Autowired | ||
| 15 | + private AppProperties appProperties; | ||
| 16 | + | ||
| 17 | + public static void main(String[] args) throws Exception { | ||
| 18 | + SpringApplication.run(Application.class, args); | ||
| 19 | + } | ||
| 20 | +} |
src/main/java/com/bsth/DataSourceConfig.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/DataSourceConfig.java | ||
| 1 | +package com.bsth; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Qualifier; | ||
| 4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 5 | +import org.springframework.boot.jdbc.DataSourceBuilder; | ||
| 6 | +import org.springframework.context.annotation.Bean; | ||
| 7 | +import org.springframework.context.annotation.Configuration; | ||
| 8 | +import org.springframework.context.annotation.Primary; | ||
| 9 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 10 | + | ||
| 11 | +import javax.sql.DataSource; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * @author Hill | ||
| 15 | + */ | ||
| 16 | +@Configuration | ||
| 17 | +public class DataSourceConfig { | ||
| 18 | + @Bean(name = "controlDataSource") | ||
| 19 | + @Qualifier("controlDataSource") | ||
| 20 | + @ConfigurationProperties(prefix = "spring.datasource.control") | ||
| 21 | + public DataSource controlDataSource(){ | ||
| 22 | + return DataSourceBuilder.create().build(); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + @Bean(name = "msDataSource") | ||
| 26 | + @Qualifier("msDataSource") | ||
| 27 | + @Primary | ||
| 28 | + @ConfigurationProperties(prefix = "spring.datasource.ms") | ||
| 29 | + | ||
| 30 | + public DataSource msDataSource(){ | ||
| 31 | + return DataSourceBuilder.create().build(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Bean(name = "controlJdbcTemplate") | ||
| 35 | + public JdbcTemplate controlJdbcTemplate(@Qualifier("controlDataSource")DataSource dataSource){ | ||
| 36 | + return new JdbcTemplate(dataSource); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Bean(name = "msJdbcTemplate") | ||
| 40 | + public JdbcTemplate msJdbcTemplate(@Qualifier("msDataSource")DataSource dataSource){ | ||
| 41 | + return new JdbcTemplate(dataSource); | ||
| 42 | + } | ||
| 43 | +} |
src/main/java/com/bsth/constant/Constant.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/constant/Constant.java | ||
| 1 | +package com.bsth.constant; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + */ | ||
| 6 | +public class Constant { | ||
| 7 | + | ||
| 8 | + public final static int BYTE_INT = 0xFF; | ||
| 9 | + | ||
| 10 | + public final static int SHORT_INT = 0xFFFF; | ||
| 11 | + | ||
| 12 | + public final static long INT_LONG = 0xFFFFFFFF; | ||
| 13 | + | ||
| 14 | + public final static byte ACK_FLAG_SUCCESS = (byte)0x01; | ||
| 15 | + | ||
| 16 | + public final static byte ACK_FLAG_FAILURE = (byte)0x02; | ||
| 17 | + | ||
| 18 | + public final static byte ACK_FLAG_DUPLICATE_VIN = (byte)0x03; | ||
| 19 | + | ||
| 20 | + public final static byte ACK_FLAG_COMMAND = (byte)0xFE; | ||
| 21 | +} |
src/main/java/com/bsth/entity/AlarmData.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/AlarmData.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import com.bsth.socket.protocol.Message0207; | ||
| 4 | +import org.springframework.beans.BeanUtils; | ||
| 5 | + | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author Hill | ||
| 11 | + * 报警数据 | ||
| 12 | + */ | ||
| 13 | +public class AlarmData extends Data { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 最高警报等级 0-3(亦可自定义) | ||
| 17 | + * 0 无故障 | ||
| 18 | + * 1 级故障,不影响车辆行驶的故障 | ||
| 19 | + * 2 级故障,影响车辆性能,需驾驶员限制行驶的故障 | ||
| 20 | + * 3 级故障,停车待援 | ||
| 21 | + * 0xfe 异常 | ||
| 22 | + * 0xff 无效 | ||
| 23 | + */ | ||
| 24 | + private short maxAlarmLevel; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 通用报警标志 | ||
| 28 | + * 0位 0正常 1温度差异 1位 电池高温 2位 车载储能装置类型过压 3位 车载储能装置类型欠压 | ||
| 29 | + * 4位 SOC低 5位 单体电池过压 6位 单体电池欠压 7位 SOC过高 | ||
| 30 | + * 8位 SOC跳变 9位 可充电储能系统不匹配 10位 电池单体一致性差 11位 绝缘 | ||
| 31 | + * 12位 DC-DC温度 13位 制动系统 14位 DC-DC状态 15位 驱动电机控制器温度 | ||
| 32 | + * 16位 高压互锁状态 17位 驱动电机温度 18位 车载储能装置类型过充 | ||
| 33 | + * 19-31位 保留 | ||
| 34 | + */ | ||
| 35 | + private int commonAlarmFlag; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 储能装置数量 0-252 | ||
| 39 | + * N1 | ||
| 40 | + * 0xfe 异常 | ||
| 41 | + * 0xff 无效 | ||
| 42 | + */ | ||
| 43 | + private short energyStorageDeviceQuantity; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 储能装置报警情况(自定义) | ||
| 47 | + * N1 * 4 | ||
| 48 | + */ | ||
| 49 | + private int[] esdAlarms; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 驱动电机数量 0-252 | ||
| 53 | + * N2 | ||
| 54 | + * 0xfe 异常 | ||
| 55 | + * 0xff 无效 | ||
| 56 | + */ | ||
| 57 | + private short electricMotorQuantity; | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 驱动电机报警情况(自定义) | ||
| 61 | + * N2 * 4 | ||
| 62 | + */ | ||
| 63 | + private int[] emAlarms; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 发动机数量 0-252 | ||
| 67 | + * N3 | ||
| 68 | + * 0xfe 异常 | ||
| 69 | + * 0xff 无效 | ||
| 70 | + */ | ||
| 71 | + private short engineQuantity; | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 发动机报警情况(自定义) | ||
| 75 | + * N3 * 4 | ||
| 76 | + */ | ||
| 77 | + private int[] engineAlarms; | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 其它故障 0-252 | ||
| 81 | + * N4 | ||
| 82 | + * 0xfe 异常 | ||
| 83 | + * 0xff 无效 | ||
| 84 | + */ | ||
| 85 | + private short otherQuantity; | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 扩展故障详细 | ||
| 89 | + */ | ||
| 90 | + private List<String> troubles = new ArrayList<>(); | ||
| 91 | + | ||
| 92 | + public AlarmData() { | ||
| 93 | + | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public AlarmData(Message0207 message0207) { | ||
| 97 | + BeanUtils.copyProperties(message0207, this); | ||
| 98 | + this.maxAlarmLevel &= (short) 0xFF; | ||
| 99 | + this.energyStorageDeviceQuantity &= (short) 0xFF; | ||
| 100 | + this.electricMotorQuantity &= (short) 0xFF; | ||
| 101 | + this.engineQuantity &= (short) 0xFF; | ||
| 102 | + this.otherQuantity &= (short) 0xFF; | ||
| 103 | + for (Message0207.Trouble trouble : message0207.getTroubleList()) { | ||
| 104 | + troubles.add(trouble.toString()); | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public short getMaxAlarmLevel() { | ||
| 109 | + return maxAlarmLevel; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public void setMaxAlarmLevel(short maxAlarmLevel) { | ||
| 113 | + this.maxAlarmLevel = maxAlarmLevel; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public int getCommonAlarmFlag() { | ||
| 117 | + return commonAlarmFlag; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public void setCommonAlarmFlag(int commonAlarmFlag) { | ||
| 121 | + this.commonAlarmFlag = commonAlarmFlag; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public short getEnergyStorageDeviceQuantity() { | ||
| 125 | + return energyStorageDeviceQuantity; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setEnergyStorageDeviceQuantity(short energyStorageDeviceQuantity) { | ||
| 129 | + this.energyStorageDeviceQuantity = energyStorageDeviceQuantity; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public int[] getEsdAlarms() { | ||
| 133 | + return esdAlarms; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public void setEsdAlarms(int[] esdAlarms) { | ||
| 137 | + this.esdAlarms = esdAlarms; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public short getElectricMotorQuantity() { | ||
| 141 | + return electricMotorQuantity; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public void setElectricMotorQuantity(short electricMotorQuantity) { | ||
| 145 | + this.electricMotorQuantity = electricMotorQuantity; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public int[] getEmAlarms() { | ||
| 149 | + return emAlarms; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public void setEmAlarms(int[] emAlarms) { | ||
| 153 | + this.emAlarms = emAlarms; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public short getEngineQuantity() { | ||
| 157 | + return engineQuantity; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public void setEngineQuantity(short engineQuantity) { | ||
| 161 | + this.engineQuantity = engineQuantity; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public int[] getEngineAlarms() { | ||
| 165 | + return engineAlarms; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public void setEngineAlarms(int[] engineAlarms) { | ||
| 169 | + this.engineAlarms = engineAlarms; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public short getOtherQuantity() { | ||
| 173 | + return otherQuantity; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public void setOtherQuantity(short otherQuantity) { | ||
| 177 | + this.otherQuantity = otherQuantity; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public List<String> getTroubles() { | ||
| 181 | + return troubles; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public void setTroubles(List<String> troubles) { | ||
| 185 | + this.troubles = troubles; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + @Override | ||
| 189 | + public String toString() { | ||
| 190 | + StringBuilder sb = new StringBuilder(); | ||
| 191 | + sb.append(" 最大报警级别: ").append(maxAlarmLevel) | ||
| 192 | + .append(" 通用报警标志: ").append(commonAlarmFlag) | ||
| 193 | + .append(" 储能设备报警数: ").append(energyStorageDeviceQuantity) | ||
| 194 | + .append(" 电机报警数: ").append(electricMotorQuantity) | ||
| 195 | + .append(" 发动机报警数: ").append(engineQuantity) | ||
| 196 | + .append(" 其它报警数: ").append(otherQuantity) | ||
| 197 | + .append(" 自定义报警详情: "); | ||
| 198 | + | ||
| 199 | + for (String trouble : troubles) { | ||
| 200 | + sb.append(trouble); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + return sb.toString(); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + @Override | ||
| 207 | + public String getType() { | ||
| 208 | + return "alarm_data"; | ||
| 209 | + } | ||
| 210 | +} |
src/main/java/com/bsth/entity/CarParkInfo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/CarParkInfo.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import com.bsth.geo.Point; | ||
| 6 | + | ||
| 7 | +public class CarParkInfo { | ||
| 8 | + | ||
| 9 | + private int id; | ||
| 10 | + private String parkCode; | ||
| 11 | + private String parkName; | ||
| 12 | + private Point point; | ||
| 13 | + private String shapesType; | ||
| 14 | + private int radius; | ||
| 15 | + private List<Point> points; | ||
| 16 | + | ||
| 17 | + public int getId() { | ||
| 18 | + return id; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void setId(int id) { | ||
| 22 | + this.id = id; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public String getParkCode() { | ||
| 26 | + return parkCode; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public void setParkCode(String parkCode) { | ||
| 30 | + this.parkCode = parkCode; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public String getParkName() { | ||
| 34 | + return parkName; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void setParkName(String parkName) { | ||
| 38 | + this.parkName = parkName; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public Point getPoint() { | ||
| 42 | + return point; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public void setPoint(Point point) { | ||
| 46 | + this.point = point; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public String getShapesType() { | ||
| 50 | + return shapesType; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public void setShapesType(String shapesType) { | ||
| 54 | + this.shapesType = shapesType; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public int getRadius() { | ||
| 58 | + return radius; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setRadius(int radius) { | ||
| 62 | + this.radius = radius; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public List<Point> getPoints() { | ||
| 66 | + return points; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public void setPoints(List<Point> points) { | ||
| 70 | + this.points = points; | ||
| 71 | + } | ||
| 72 | +} |
src/main/java/com/bsth/entity/Data.java
0 → 100644
src/main/java/com/bsth/entity/DeviceAbnormal.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/DeviceAbnormal.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +public class DeviceAbnormal { | ||
| 4 | + | ||
| 5 | + private int id; | ||
| 6 | + | ||
| 7 | + private String deviceId; | ||
| 8 | + | ||
| 9 | + // 掉线次数 | ||
| 10 | + private int offline; | ||
| 11 | + | ||
| 12 | + // 漂移次数 | ||
| 13 | + private int drift; | ||
| 14 | + | ||
| 15 | + // 协议错误次数 | ||
| 16 | + private int protocol; | ||
| 17 | + | ||
| 18 | + // 数据是否存在于数据库 | ||
| 19 | + private boolean exists = true; | ||
| 20 | + | ||
| 21 | + public int getId() { | ||
| 22 | + return id; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void setId(int id) { | ||
| 26 | + this.id = id; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public String getDeviceId() { | ||
| 30 | + return deviceId; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setDeviceId(String deviceId) { | ||
| 34 | + this.deviceId = deviceId; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public int getOffline() { | ||
| 38 | + return offline; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setOffline(int offline) { | ||
| 42 | + this.offline = offline; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public int getDrift() { | ||
| 46 | + return drift; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setDrift(int drift) { | ||
| 50 | + this.drift = drift; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public int getProtocol() { | ||
| 54 | + return protocol; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setProtocol(int protocol) { | ||
| 58 | + this.protocol = protocol; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public boolean isExists() { | ||
| 62 | + return exists; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setExists(boolean exists) { | ||
| 66 | + this.exists = exists; | ||
| 67 | + } | ||
| 68 | +} |
src/main/java/com/bsth/entity/DeviceSimMapping.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/DeviceSimMapping.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +public class DeviceSimMapping { | ||
| 4 | + | ||
| 5 | + private String deviceId; | ||
| 6 | + | ||
| 7 | + private String sim; | ||
| 8 | + | ||
| 9 | + // 0 A模块为主 1 B模块为主 | ||
| 10 | + private int extEnabled; | ||
| 11 | + | ||
| 12 | + public String getDeviceId() { | ||
| 13 | + return deviceId; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public void setDeviceId(String deviceId) { | ||
| 17 | + this.deviceId = deviceId; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public String getSim() { | ||
| 21 | + return sim; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public void setSim(String sim) { | ||
| 25 | + this.sim = sim; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public int getExtEnabled() { | ||
| 29 | + return extEnabled; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setExtEnabled(int extEnabled) { | ||
| 33 | + this.extEnabled = extEnabled; | ||
| 34 | + } | ||
| 35 | +} |
src/main/java/com/bsth/entity/GridInfo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/GridInfo.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +public class GridInfo { | ||
| 4 | + | ||
| 5 | + private double minLon; | ||
| 6 | + | ||
| 7 | + private double maxLon; | ||
| 8 | + | ||
| 9 | + private double minLat; | ||
| 10 | + | ||
| 11 | + private double maxLat; | ||
| 12 | + | ||
| 13 | + private int row; | ||
| 14 | + | ||
| 15 | + private int column; | ||
| 16 | + | ||
| 17 | + private SectionGrid[][] grid; | ||
| 18 | + | ||
| 19 | + public double getMinLon() { | ||
| 20 | + return minLon; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setMinLon(double minLon) { | ||
| 24 | + this.minLon = minLon; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public double getMaxLon() { | ||
| 28 | + return maxLon; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setMaxLon(double maxLon) { | ||
| 32 | + this.maxLon = maxLon; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public double getMinLat() { | ||
| 36 | + return minLat; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setMinLat(double minLat) { | ||
| 40 | + this.minLat = minLat; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public double getMaxLat() { | ||
| 44 | + return maxLat; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setMaxLat(double maxLat) { | ||
| 48 | + this.maxLat = maxLat; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public int getRow() { | ||
| 52 | + return row; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setRow(int row) { | ||
| 56 | + this.row = row; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public int getColumn() { | ||
| 60 | + return column; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setColumn(int column) { | ||
| 64 | + this.column = column; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public SectionGrid[][] getGrid() { | ||
| 68 | + return grid; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setGrid(SectionGrid[][] grid) { | ||
| 72 | + this.grid = grid; | ||
| 73 | + } | ||
| 74 | +} |
src/main/java/com/bsth/entity/HistoryArrival.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/HistoryArrival.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | + | ||
| 5 | +public class HistoryArrival { | ||
| 6 | + | ||
| 7 | + private int id; | ||
| 8 | + private String deviceId; | ||
| 9 | + private int lineId; | ||
| 10 | + private String stopNo; | ||
| 11 | + private long timestamp; | ||
| 12 | + private int upDown; | ||
| 13 | + private int upDown1; | ||
| 14 | + // 0进站 1出站 | ||
| 15 | + private int inOut = -1; | ||
| 16 | + private Date createDate; | ||
| 17 | + private float totalMiles; | ||
| 18 | + private float lon; | ||
| 19 | + private float lat; | ||
| 20 | + | ||
| 21 | + // true场内 false场外 | ||
| 22 | + private boolean state; | ||
| 23 | + | ||
| 24 | + // 特殊情况下进站也是出站 | ||
| 25 | + private String lastStopNo; | ||
| 26 | + private int lastUpDown; | ||
| 27 | + | ||
| 28 | + public boolean getState() { | ||
| 29 | + return state; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setState(boolean state) { | ||
| 33 | + this.state = state; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public int getInOut() { | ||
| 37 | + return inOut; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public void setInOut(int inOut) { | ||
| 41 | + this.inOut = inOut; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public float getLon() { | ||
| 45 | + return lon; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setLon(float lon) { | ||
| 49 | + this.lon = lon; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public float getLat() { | ||
| 53 | + return lat; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setLat(float lat) { | ||
| 57 | + this.lat = lat; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public float getTotalMiles() { | ||
| 61 | + return totalMiles; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setTotalMiles(float totalMiles) { | ||
| 65 | + this.totalMiles = totalMiles; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public int getId() { | ||
| 69 | + return id; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setId(int id) { | ||
| 73 | + this.id = id; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public String getDeviceId() { | ||
| 77 | + return deviceId; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setDeviceId(String deviceId) { | ||
| 81 | + this.deviceId = deviceId; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public int getLineId() { | ||
| 85 | + return lineId; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public void setLineId(int lineId) { | ||
| 89 | + this.lineId = lineId; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public String getStopNo() { | ||
| 93 | + return stopNo; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setStopNo(String stopNo) { | ||
| 97 | + this.stopNo = stopNo; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public long getTimestamp() { | ||
| 101 | + return timestamp; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setTimestamp(long timestamp) { | ||
| 105 | + this.timestamp = timestamp; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public int getUpDown() { | ||
| 109 | + return upDown; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public void setUpDown(int upDown) { | ||
| 113 | + this.upDown = upDown; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public int getUpDown1() { | ||
| 117 | + return upDown1; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public void setUpDown1(int upDown1) { | ||
| 121 | + this.upDown1 = upDown1; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public Date getCreateDate() { | ||
| 125 | + return createDate; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setCreateDate(Date createDate) { | ||
| 129 | + this.createDate = createDate; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public String getLastStopNo() { | ||
| 133 | + return lastStopNo; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public void setLastStopNo(String lastStopNo) { | ||
| 137 | + this.lastStopNo = lastStopNo; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public int getLastUpDown() { | ||
| 141 | + return lastUpDown; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public void setLastUpDown(int lastUpDown) { | ||
| 145 | + this.lastUpDown = lastUpDown; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public String toString() { | ||
| 149 | + return "deviceID" + deviceId + "stopNo" + stopNo + "timestamp" + new Date(timestamp) + "inout" + inOut; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public boolean equals(Object obj) { | ||
| 154 | + HistoryArrival temp = (HistoryArrival)obj; | ||
| 155 | + return temp.getTimestamp() == this.getTimestamp() && temp.getLon() == this.getLon() && temp.getLat() == this.getLat(); | ||
| 156 | + } | ||
| 157 | +} |
src/main/java/com/bsth/entity/HistoryGps.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/HistoryGps.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +public class HistoryGps { | ||
| 4 | + | ||
| 5 | + private int cityCode; | ||
| 6 | + private int industryCode; | ||
| 7 | + private int companyCode; | ||
| 8 | + private int lineId; | ||
| 9 | + private String deviceId; | ||
| 10 | + private int driverNo; | ||
| 11 | + private short carparkSerialNo; | ||
| 12 | + private String carparkNo; | ||
| 13 | + private short stopSerialNo; | ||
| 14 | + private String stopNo; | ||
| 15 | + private float lon; | ||
| 16 | + private float lat; | ||
| 17 | + private long timestamp; | ||
| 18 | + private float speedSensor; | ||
| 19 | + private float speedGps; | ||
| 20 | + private float direction; | ||
| 21 | + private byte inTemp; | ||
| 22 | + private long serviceState; | ||
| 23 | + private long controlState; | ||
| 24 | + private float totalMiles; | ||
| 25 | + private byte waterTemp; | ||
| 26 | + private float oilConsumption; | ||
| 27 | + private int engineSpeed; | ||
| 28 | + private byte inOutStop; | ||
| 29 | + | ||
| 30 | + private long serverTimestamp; | ||
| 31 | + private String sectionCode; | ||
| 32 | + | ||
| 33 | + public String getSectionCode() { | ||
| 34 | + return sectionCode; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void setSectionCode(String sectionCode) { | ||
| 38 | + this.sectionCode = sectionCode; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public long getServerTimestamp() { | ||
| 42 | + return serverTimestamp; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public void setServerTimestamp(long serverTimestamp) { | ||
| 46 | + this.serverTimestamp = serverTimestamp; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public int getCityCode() { | ||
| 50 | + return cityCode; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public void setCityCode(int cityCode) { | ||
| 54 | + this.cityCode = cityCode; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public int getIndustryCode() { | ||
| 58 | + return industryCode; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setIndustryCode(int industryCode) { | ||
| 62 | + this.industryCode = industryCode; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public int getCompanyCode() { | ||
| 66 | + return companyCode; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public void setCompanyCode(int companyCode) { | ||
| 70 | + this.companyCode = companyCode; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public int getLineId() { | ||
| 74 | + return lineId; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public void setLineId(int lineId) { | ||
| 78 | + this.lineId = lineId; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public String getDeviceId() { | ||
| 82 | + return deviceId; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public void setDeviceId(String deviceId) { | ||
| 86 | + this.deviceId = deviceId; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public int getDriverNo() { | ||
| 90 | + return driverNo; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public void setDriverNo(int driverNo) { | ||
| 94 | + this.driverNo = driverNo; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public short getCarparkSerialNo() { | ||
| 98 | + return carparkSerialNo; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void setCarparkSerialNo(short carparkSerialNo) { | ||
| 102 | + this.carparkSerialNo = carparkSerialNo; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public String getCarparkNo() { | ||
| 106 | + return carparkNo; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public void setCarparkNo(String carparkNo) { | ||
| 110 | + this.carparkNo = carparkNo; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public short getStopSerialNo() { | ||
| 114 | + return stopSerialNo; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public void setStopSerialNo(short stopSerialNo) { | ||
| 118 | + this.stopSerialNo = stopSerialNo; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public String getStopNo() { | ||
| 122 | + return stopNo; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public void setStopNo(String stopNo) { | ||
| 126 | + this.stopNo = stopNo; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public float getLon() { | ||
| 130 | + return lon; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public void setLon(float lon) { | ||
| 134 | + this.lon = lon; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public float getLat() { | ||
| 138 | + return lat; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void setLat(float lat) { | ||
| 142 | + this.lat = lat; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public long getTimestamp() { | ||
| 146 | + return timestamp; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public void setTimestamp(long timestamp) { | ||
| 150 | + this.timestamp = timestamp; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public float getSpeedSensor() { | ||
| 154 | + return speedSensor; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public void setSpeedSensor(float speedSensor) { | ||
| 158 | + this.speedSensor = speedSensor; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public float getSpeedGps() { | ||
| 162 | + return speedGps; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public void setSpeedGps(float speedGps) { | ||
| 166 | + this.speedGps = speedGps; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public float getDirection() { | ||
| 170 | + return direction; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public void setDirection(float direction) { | ||
| 174 | + this.direction = direction; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + public byte getInTemp() { | ||
| 178 | + return inTemp; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public void setInTemp(byte inTemp) { | ||
| 182 | + this.inTemp = inTemp; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + public long getServiceState() { | ||
| 186 | + return serviceState; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + public void setServiceState(long serviceState) { | ||
| 190 | + this.serviceState = serviceState; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + public long getControlState() { | ||
| 194 | + return controlState; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + public void setControlState(long controlState) { | ||
| 198 | + this.controlState = controlState; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + public float getTotalMiles() { | ||
| 202 | + return totalMiles; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + public void setTotalMiles(float totalMiles) { | ||
| 206 | + this.totalMiles = totalMiles; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + public byte getWaterTemp() { | ||
| 210 | + return waterTemp; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + public void setWaterTemp(byte waterTemp) { | ||
| 214 | + this.waterTemp = waterTemp; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + public float getOilConsumption() { | ||
| 218 | + return oilConsumption; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public void setOilConsumption(float oilConsumption) { | ||
| 222 | + this.oilConsumption = oilConsumption; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + public int getEngineSpeed() { | ||
| 226 | + return engineSpeed; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + public void setEngineSpeed(int engineSpeed) { | ||
| 230 | + this.engineSpeed = engineSpeed; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + public byte getInOutStop() { | ||
| 234 | + return inOutStop; | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + public void setInOutStop(byte inOutStop) { | ||
| 238 | + this.inOutStop = inOutStop; | ||
| 239 | + } | ||
| 240 | +} |
src/main/java/com/bsth/entity/LineInfo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/LineInfo.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Hill | ||
| 8 | + */ | ||
| 9 | +public class LineInfo { | ||
| 10 | + | ||
| 11 | + private final static double SPEEDING_LIMIT = 60; | ||
| 12 | + | ||
| 13 | + private int id; | ||
| 14 | + private int lineId; | ||
| 15 | + private String lineName; | ||
| 16 | + private int startStation; | ||
| 17 | + private String startStationName; | ||
| 18 | + private String startStationFirstTime; | ||
| 19 | + private String startStationEndTime; | ||
| 20 | + private int endStation; | ||
| 21 | + private String endStationName; | ||
| 22 | + private String endStationFirstTime; | ||
| 23 | + private String endStationEndTime; | ||
| 24 | + private String company; | ||
| 25 | + private String brancheCompany; | ||
| 26 | + private double length; | ||
| 27 | + private String telephone; | ||
| 28 | + private double speedLimit; | ||
| 29 | + private int linePlayType; | ||
| 30 | + private int inUse; | ||
| 31 | + // 上行分段路段 | ||
| 32 | + private List<SectionInfo> sectionsUp = new ArrayList<SectionInfo>(); | ||
| 33 | + // 下行分段路段 | ||
| 34 | + private List<SectionInfo> sectionsDown = new ArrayList<SectionInfo>(); | ||
| 35 | + // 上行站点 | ||
| 36 | + private List<StopInfo> stopsUp = new ArrayList<StopInfo>(); | ||
| 37 | + // 下行站点 | ||
| 38 | + private List<StopInfo> stopsDown = new ArrayList<StopInfo>(); | ||
| 39 | + // 回环站点 | ||
| 40 | + private List<SpecialStation> specailStation = new ArrayList<SpecialStation>(); | ||
| 41 | + | ||
| 42 | + public double getSpeedLimit() { | ||
| 43 | + if (speedLimit > 0) return speedLimit; | ||
| 44 | + else return SPEEDING_LIMIT; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setSpeedLimit(double speedLimit) { | ||
| 48 | + this.speedLimit = speedLimit; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public List<SectionInfo> getSectionsUp() { | ||
| 52 | + return sectionsUp; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setSectionsUp(List<SectionInfo> sectionsUp) { | ||
| 56 | + this.sectionsUp = sectionsUp; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public List<SectionInfo> getSectionsDown() { | ||
| 60 | + return sectionsDown; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setSectionsDown(List<SectionInfo> sectionsDown) { | ||
| 64 | + this.sectionsDown = sectionsDown; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public List<StopInfo> getStopsUp() { | ||
| 68 | + return stopsUp; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setStopsUp(List<StopInfo> stopsUp) { | ||
| 72 | + this.stopsUp = stopsUp; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public List<StopInfo> getStopsDown() { | ||
| 76 | + return stopsDown; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setStopsDown(List<StopInfo> stopsDown) { | ||
| 80 | + this.stopsDown = stopsDown; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public List<SpecialStation> getSpecailStation() { | ||
| 84 | + return specailStation; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setSpecailStation(List<SpecialStation> specailStation) { | ||
| 88 | + this.specailStation = specailStation; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public int getId() { | ||
| 92 | + return id; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setId(int id) { | ||
| 96 | + this.id = id; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public int getLineId() { | ||
| 100 | + return lineId; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setLineId(int lineId) { | ||
| 104 | + this.lineId = lineId; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public String getLineName() { | ||
| 108 | + return lineName; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setLineName(String lineName) { | ||
| 112 | + this.lineName = lineName; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public int getStartStation() { | ||
| 116 | + return startStation; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public void setStartStation(int startStation) { | ||
| 120 | + this.startStation = startStation; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + public String getStartStationName() { | ||
| 124 | + return startStationName; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public void setStartStationName(String startStationName) { | ||
| 128 | + this.startStationName = startStationName; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public String getStartStationFirstTime() { | ||
| 132 | + return startStationFirstTime; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + public void setStartStationFirstTime(String startStationFirstTime) { | ||
| 136 | + this.startStationFirstTime = startStationFirstTime; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public String getStartStationEndTime() { | ||
| 140 | + return startStationEndTime; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public void setStartStationEndTime(String startStationEndTime) { | ||
| 144 | + this.startStationEndTime = startStationEndTime; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + public int getEndStation() { | ||
| 148 | + return endStation; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public void setEndStation(int endStation) { | ||
| 152 | + this.endStation = endStation; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + public String getEndStationName() { | ||
| 156 | + return endStationName; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public void setEndStationName(String endStationName) { | ||
| 160 | + this.endStationName = endStationName; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + public String getEndStationFirstTime() { | ||
| 164 | + return endStationFirstTime; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + public void setEndStationFirstTime(String endStationFirstTime) { | ||
| 168 | + this.endStationFirstTime = endStationFirstTime; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + public String getEndStationEndTime() { | ||
| 172 | + return endStationEndTime; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + public void setEndStationEndTime(String endStationEndTime) { | ||
| 176 | + this.endStationEndTime = endStationEndTime; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + public String getCompany() { | ||
| 180 | + return company; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + public void setCompany(String company) { | ||
| 184 | + this.company = company; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + public String getBrancheCompany() { | ||
| 188 | + return brancheCompany; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + public void setBrancheCompany(String brancheCompany) { | ||
| 192 | + this.brancheCompany = brancheCompany; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + public double getLength() { | ||
| 196 | + return length; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + public void setLength(double length) { | ||
| 200 | + this.length = length; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + public String getTelephone() { | ||
| 204 | + return telephone; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + public void setTelephone(String telephone) { | ||
| 208 | + this.telephone = telephone; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + public int getLinePlayType() { | ||
| 212 | + return linePlayType; | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + public void setLinePlayType(int linePlayType) { | ||
| 216 | + this.linePlayType = linePlayType; | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + public int getInUse() { | ||
| 220 | + return inUse; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + public void setInUse(int inUse) { | ||
| 224 | + this.inUse = inUse; | ||
| 225 | + } | ||
| 226 | +} |
src/main/java/com/bsth/entity/LineStandInfo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/LineStandInfo.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +public class LineStandInfo { | ||
| 4 | + | ||
| 5 | + private int id; | ||
| 6 | + private String type; | ||
| 7 | + private String earlyStartTime; | ||
| 8 | + private String earlyEndTime; | ||
| 9 | + private String lateStartTime; | ||
| 10 | + private String lateEndTime; | ||
| 11 | + /* 大间隔start */ | ||
| 12 | + private double earlyInterval; | ||
| 13 | + private double lateInterval; | ||
| 14 | + private double interval; | ||
| 15 | + /* 大间隔end */ | ||
| 16 | + /* 限速start */ | ||
| 17 | + private double speedLimit; | ||
| 18 | + private double rainSpeedLimit; | ||
| 19 | + private double fogSpeedLimit; | ||
| 20 | + private double snowSpeedLimit; | ||
| 21 | + private double festivalSpeedLimit; | ||
| 22 | + /* 限速end */ | ||
| 23 | + | ||
| 24 | + public int getId() { | ||
| 25 | + return id; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setId(int id) { | ||
| 29 | + this.id = id; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public String getType() { | ||
| 33 | + return type; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public void setType(String type) { | ||
| 37 | + this.type = type; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public String getEarlyStartTime() { | ||
| 41 | + return earlyStartTime; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public void setEarlyStartTime(String earlyStartTime) { | ||
| 45 | + this.earlyStartTime = earlyStartTime; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public String getEarlyEndTime() { | ||
| 49 | + return earlyEndTime; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setEarlyEndTime(String earlyEndTime) { | ||
| 53 | + this.earlyEndTime = earlyEndTime; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getLateStartTime() { | ||
| 57 | + return lateStartTime; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setLateStartTime(String lateStartTime) { | ||
| 61 | + this.lateStartTime = lateStartTime; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public String getLateEndTime() { | ||
| 65 | + return lateEndTime; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setLateEndTime(String lateEndTime) { | ||
| 69 | + this.lateEndTime = lateEndTime; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public double getEarlyInterval() { | ||
| 73 | + return earlyInterval; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setEarlyInterval(double earlyInterval) { | ||
| 77 | + this.earlyInterval = earlyInterval; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public double getLateInterval() { | ||
| 81 | + return lateInterval; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setLateInterval(double lateInterval) { | ||
| 85 | + this.lateInterval = lateInterval; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public double getInterval() { | ||
| 89 | + return interval; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setInterval(double interval) { | ||
| 93 | + this.interval = interval; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public double getSpeedLimit() { | ||
| 97 | + return speedLimit; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public void setSpeedLimit(double speedLimit) { | ||
| 101 | + this.speedLimit = speedLimit; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public double getRainSpeedLimit() { | ||
| 105 | + return rainSpeedLimit; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setRainSpeedLimit(double rainSpeedLimit) { | ||
| 109 | + this.rainSpeedLimit = rainSpeedLimit; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public double getFogSpeedLimit() { | ||
| 113 | + return fogSpeedLimit; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setFogSpeedLimit(double fogSpeedLimit) { | ||
| 117 | + this.fogSpeedLimit = fogSpeedLimit; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public double getSnowSpeedLimit() { | ||
| 121 | + return snowSpeedLimit; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public void setSnowSpeedLimit(double snowSpeedLimit) { | ||
| 125 | + this.snowSpeedLimit = snowSpeedLimit; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public double getFestivalSpeedLimit() { | ||
| 129 | + return festivalSpeedLimit; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public void setFestivalSpeedLimit(double festivalSpeedLimit) { | ||
| 133 | + this.festivalSpeedLimit = festivalSpeedLimit; | ||
| 134 | + } | ||
| 135 | +} |
src/main/java/com/bsth/entity/OfflineData.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/OfflineData.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | + | ||
| 5 | +public class OfflineData { | ||
| 6 | + | ||
| 7 | + private int id; | ||
| 8 | + private String vehicle; | ||
| 9 | + private int line; | ||
| 10 | + private int upDown; | ||
| 11 | + private float lon; | ||
| 12 | + private float lat; | ||
| 13 | + private long timestamp; | ||
| 14 | + private Date createDate; | ||
| 15 | + | ||
| 16 | + public OfflineData() { | ||
| 17 | + | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public OfflineData(RealTimeGps gps) { | ||
| 21 | + vehicle = gps.getVehicle(); | ||
| 22 | + line = gps.getLineId(); | ||
| 23 | + upDown = gps.getUpDown(); | ||
| 24 | + lon = gps.getLon(); | ||
| 25 | + lat = gps.getLat(); | ||
| 26 | + timestamp = gps.getTimestamp(); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public int getId() { | ||
| 30 | + return id; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setId(int id) { | ||
| 34 | + this.id = id; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getVehicle() { | ||
| 38 | + return vehicle; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setVehicle(String vehicle) { | ||
| 42 | + this.vehicle = vehicle; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public int getLine() { | ||
| 46 | + return line; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setLine(int line) { | ||
| 50 | + this.line = line; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public int getUpDown() { | ||
| 54 | + return upDown; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setUpDown(int upDown) { | ||
| 58 | + this.upDown = upDown; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public float getLon() { | ||
| 62 | + return lon; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setLon(float lon) { | ||
| 66 | + this.lon = lon; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public float getLat() { | ||
| 70 | + return lat; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public void setLat(float lat) { | ||
| 74 | + this.lat = lat; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public long getTimestamp() { | ||
| 78 | + return timestamp; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public void setTimestamp(long timestamp) { | ||
| 82 | + this.timestamp = timestamp; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public Date getCreateDate() { | ||
| 86 | + return createDate; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public void setCreateDate(Date createDate) { | ||
| 90 | + this.createDate = createDate; | ||
| 91 | + } | ||
| 92 | +} |
src/main/java/com/bsth/entity/OutboundData.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/OutboundData.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | + | ||
| 5 | +public class OutboundData { | ||
| 6 | + | ||
| 7 | + private int id; | ||
| 8 | + private String vehicle; | ||
| 9 | + private int line; | ||
| 10 | + private int upDown; | ||
| 11 | + private float lon; | ||
| 12 | + private float lat; | ||
| 13 | + private String location; | ||
| 14 | + private long timestamp; | ||
| 15 | + private Date createDate; | ||
| 16 | + | ||
| 17 | + public OutboundData() { | ||
| 18 | + | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public OutboundData(RealTimeGps gps) { | ||
| 22 | + vehicle = gps.getVehicle(); | ||
| 23 | + line = gps.getLineId(); | ||
| 24 | + upDown = gps.getUpDown(); | ||
| 25 | + lon = gps.getLon(); | ||
| 26 | + lat = gps.getLat(); | ||
| 27 | + timestamp = gps.getTimestamp(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public int getId() { | ||
| 31 | + return id; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void setId(int id) { | ||
| 35 | + this.id = id; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public String getVehicle() { | ||
| 39 | + return vehicle; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setVehicle(String vehicle) { | ||
| 43 | + this.vehicle = vehicle; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public int getLine() { | ||
| 47 | + return line; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public void setLine(int line) { | ||
| 51 | + this.line = line; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public int getUpDown() { | ||
| 55 | + return upDown; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public void setUpDown(int upDown) { | ||
| 59 | + this.upDown = upDown; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public float getLon() { | ||
| 63 | + return lon; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setLon(float lon) { | ||
| 67 | + this.lon = lon; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public float getLat() { | ||
| 71 | + return lat; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setLat(float lat) { | ||
| 75 | + this.lat = lat; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public String getLocation() { | ||
| 79 | + return location; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public void setLocation(String location) { | ||
| 83 | + this.location = location; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public long getTimestamp() { | ||
| 87 | + return timestamp; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public void setTimestamp(long timestamp) { | ||
| 91 | + this.timestamp = timestamp; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public Date getCreateDate() { | ||
| 95 | + return createDate; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public void setCreateDate(Date createDate) { | ||
| 99 | + this.createDate = createDate; | ||
| 100 | + } | ||
| 101 | +} |
src/main/java/com/bsth/entity/PeakData.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/PeakData.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import com.bsth.socket.protocol.Message0206; | ||
| 4 | +import org.springframework.beans.BeanUtils; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Hill | ||
| 8 | + * 极值数据 | ||
| 9 | + */ | ||
| 10 | +public class PeakData extends Data { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 最高电压电池子系统代码 1-250 | ||
| 14 | + * 0xfe 异常 | ||
| 15 | + * 0xff 无效 | ||
| 16 | + */ | ||
| 17 | + private short maxVoltageSubSysCode; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 最高电压电池单体代码 1-250 | ||
| 21 | + * 0xfe 异常 | ||
| 22 | + * 0xff 无效 | ||
| 23 | + */ | ||
| 24 | + private short maxVoltageSubCode; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 电池单体电压最高值 0-15000 | ||
| 28 | + * 分辨率0.001v | ||
| 29 | + * 0xff 0xfe 异常 | ||
| 30 | + * 0xff 0xff 无效 | ||
| 31 | + */ | ||
| 32 | + private short maxVoltage; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 最低电压电池子系统代码 1-250 | ||
| 36 | + * 0xfe 异常 | ||
| 37 | + * 0xff 无效 | ||
| 38 | + */ | ||
| 39 | + private short minVoltageSubSysCode; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 最低电压电池单体代码 1-250 | ||
| 43 | + * 0xfe 异常 | ||
| 44 | + * 0xff 无效 | ||
| 45 | + */ | ||
| 46 | + private short minVoltageSubCode; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 电池单体电压最低值 0-15000 | ||
| 50 | + * 分辨率0.001v | ||
| 51 | + * 0xff 0xfe 异常 | ||
| 52 | + * 0xff 0xff 无效 | ||
| 53 | + */ | ||
| 54 | + private short minVoltage; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 最高温度子系统代码 1-250 | ||
| 58 | + * 0xfe 异常 | ||
| 59 | + * 0xff 无效 | ||
| 60 | + */ | ||
| 61 | + private short maxTempSubSysCode; | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * 最高温度探针代码 1-250 | ||
| 65 | + * 0xfe 异常 | ||
| 66 | + * 0xff 无效 | ||
| 67 | + */ | ||
| 68 | + private short maxTempSensorCode; | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 最高温度值 0-250 | ||
| 72 | + * 分辨率1℃ 偏移量-40 | ||
| 73 | + * 0xfe 异常 | ||
| 74 | + * 0xff 无效 | ||
| 75 | + */ | ||
| 76 | + private short maxTemp; | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 最低温度子系统代码 1-250 | ||
| 80 | + * 0xfe 异常 | ||
| 81 | + * 0xff 无效 | ||
| 82 | + */ | ||
| 83 | + private short minTempSubSysCode; | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 最低温度探针代码 1-250 | ||
| 87 | + * 0xfe 异常 | ||
| 88 | + * 0xff 无效 | ||
| 89 | + */ | ||
| 90 | + private short minTempSensorCode; | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * 最低温度值 0-250 | ||
| 94 | + * 分辨率1℃ 偏移量-40 | ||
| 95 | + * 0xfe 异常 | ||
| 96 | + * 0xff 无效 | ||
| 97 | + */ | ||
| 98 | + private short minTemp; | ||
| 99 | + | ||
| 100 | + public PeakData() { | ||
| 101 | + | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public PeakData(Message0206 message0206) { | ||
| 105 | + BeanUtils.copyProperties(message0206, this); | ||
| 106 | + this.maxVoltageSubSysCode &= (short) 0xFF; | ||
| 107 | + this.maxVoltageSubCode &= (short) 0xFF; | ||
| 108 | + this.minVoltageSubSysCode &= (short) 0xFF; | ||
| 109 | + this.minVoltageSubCode &= (short) 0xFF; | ||
| 110 | + this.maxTempSubSysCode &= (short) 0xFF; | ||
| 111 | + this.maxTempSensorCode &= (short) 0xFF; | ||
| 112 | + this.maxTemp -= 40; | ||
| 113 | + this.minTempSubSysCode &= (short) 0xFF; | ||
| 114 | + this.minTempSensorCode &= (short) 0xFF; | ||
| 115 | + this.minTemp -= 40; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public short getMaxVoltageSubSysCode() { | ||
| 119 | + return maxVoltageSubSysCode; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public void setMaxVoltageSubSysCode(short maxVoltageSubSysCode) { | ||
| 123 | + this.maxVoltageSubSysCode = maxVoltageSubSysCode; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public short getMaxVoltageSubCode() { | ||
| 127 | + return maxVoltageSubCode; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public void setMaxVoltageSubCode(short maxVoltageSubCode) { | ||
| 131 | + this.maxVoltageSubCode = maxVoltageSubCode; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public short getMaxVoltage() { | ||
| 135 | + return maxVoltage; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public void setMaxVoltage(short maxVoltage) { | ||
| 139 | + this.maxVoltage = maxVoltage; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public short getMinVoltageSubSysCode() { | ||
| 143 | + return minVoltageSubSysCode; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public void setMinVoltageSubSysCode(short minVoltageSubSysCode) { | ||
| 147 | + this.minVoltageSubSysCode = minVoltageSubSysCode; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + public short getMinVoltageSubCode() { | ||
| 151 | + return minVoltageSubCode; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + public void setMinVoltageSubCode(short minVoltageSubCode) { | ||
| 155 | + this.minVoltageSubCode = minVoltageSubCode; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public short getMinVoltage() { | ||
| 159 | + return minVoltage; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + public void setMinVoltage(short minVoltage) { | ||
| 163 | + this.minVoltage = minVoltage; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public short getMaxTempSubSysCode() { | ||
| 167 | + return maxTempSubSysCode; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public void setMaxTempSubSysCode(short maxTempSubSysCode) { | ||
| 171 | + this.maxTempSubSysCode = maxTempSubSysCode; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + public short getMaxTempSensorCode() { | ||
| 175 | + return maxTempSensorCode; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + public void setMaxTempSensorCode(short maxTempSensorCode) { | ||
| 179 | + this.maxTempSensorCode = maxTempSensorCode; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + public short getMaxTemp() { | ||
| 183 | + return maxTemp; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public void setMaxTemp(short maxTemp) { | ||
| 187 | + this.maxTemp = maxTemp; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public short getMinTempSubSysCode() { | ||
| 191 | + return minTempSubSysCode; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + public void setMinTempSubSysCode(short minTempSubSysCode) { | ||
| 195 | + this.minTempSubSysCode = minTempSubSysCode; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + public short getMinTempSensorCode() { | ||
| 199 | + return minTempSensorCode; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + public void setMinTempSensorCode(short minTempSensorCode) { | ||
| 203 | + this.minTempSensorCode = minTempSensorCode; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + public short getMinTemp() { | ||
| 207 | + return minTemp; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + public void setMinTemp(short minTemp) { | ||
| 211 | + this.minTemp = minTemp; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + @Override | ||
| 215 | + public String toString() { | ||
| 216 | + StringBuilder sb = new StringBuilder(); | ||
| 217 | + sb.append(" 最大电压子系统编码: ").append(maxVoltageSubSysCode) | ||
| 218 | + .append(" 最大电压子单体代号: ").append(maxVoltageSubCode) | ||
| 219 | + .append(" 电池单体电压最高值: ").append(maxVoltage) | ||
| 220 | + .append(" 最低电压子系统编码: ").append(minVoltageSubSysCode) | ||
| 221 | + .append(" 最低电压子单体代号: ").append(minVoltageSubCode) | ||
| 222 | + .append(" 电池单体电压最低值: ").append(minVoltage) | ||
| 223 | + .append(" 最高温度子系统代码: ").append(maxTempSubSysCode) | ||
| 224 | + .append(" 最高温度探针代码: ").append(maxTempSensorCode) | ||
| 225 | + .append(" 最高温度值: ").append(maxTemp) | ||
| 226 | + .append(" 最低温度子系统代码: ").append(maxTempSubSysCode) | ||
| 227 | + .append(" 最低温度探针代码: ").append(maxTempSensorCode) | ||
| 228 | + .append(" 最低温度值: ").append(maxTemp); | ||
| 229 | + | ||
| 230 | + return sb.toString(); | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + @Override | ||
| 234 | + public String getType() { | ||
| 235 | + return "peak_data"; | ||
| 236 | + } | ||
| 237 | +} |
src/main/java/com/bsth/entity/RealTimeGps.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/RealTimeGps.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +public class RealTimeGps implements Serializable { | ||
| 6 | + | ||
| 7 | + private static final long serialVersionUID = -8996943161741177815L; | ||
| 8 | + private int companyCode; | ||
| 9 | + private int lineId; | ||
| 10 | + private String deviceId; | ||
| 11 | + private String carparkNo; | ||
| 12 | + private String stopNo; | ||
| 13 | + private float lon; | ||
| 14 | + private float lat; | ||
| 15 | + private long timestamp; | ||
| 16 | + private float speed; | ||
| 17 | + private float direction; | ||
| 18 | + // 营运状态 | ||
| 19 | + private byte state = (byte)-1; | ||
| 20 | + // 上下行 -1无效 0上行 1下行 | ||
| 21 | + private byte upDown; | ||
| 22 | + // 站内外 -1无效 0站外 1站内 | ||
| 23 | + private byte inOrOutStation; | ||
| 24 | + // 场内外 -1无效 0场外 1场内 | ||
| 25 | + private byte inOrOutCarpark; | ||
| 26 | + // 车辆内部编码 | ||
| 27 | + private String vehicle; | ||
| 28 | + | ||
| 29 | + private byte valid = (byte)0; | ||
| 30 | + // 版本号 | ||
| 31 | + private short version; | ||
| 32 | + | ||
| 33 | + private String insideCode; | ||
| 34 | + | ||
| 35 | + private long serverTimestamp; | ||
| 36 | + private String sectionCode; | ||
| 37 | + | ||
| 38 | + public String getSectionCode() { | ||
| 39 | + return sectionCode; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setSectionCode(String sectionCode) { | ||
| 43 | + this.sectionCode = sectionCode; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public short getVersion() { | ||
| 47 | + return version; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public void setVersion(short version) { | ||
| 51 | + this.version = version; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public long getServerTimestamp() { | ||
| 55 | + return serverTimestamp; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public void setServerTimestamp(long serverTimestamp) { | ||
| 59 | + this.serverTimestamp = serverTimestamp; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public byte getValid() { | ||
| 63 | + return valid; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setValid(byte valid) { | ||
| 67 | + this.valid = valid; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public String getVehicle() { | ||
| 71 | + return vehicle; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setVehicle(String vehicle) { | ||
| 75 | + this.vehicle = vehicle; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public byte getInOrOutStation() { | ||
| 79 | + return inOrOutStation; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public void setInOrOutStation(byte inOrOutStation) { | ||
| 83 | + this.inOrOutStation = inOrOutStation; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public byte getInOrOutCarpark() { | ||
| 87 | + return inOrOutCarpark; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public void setInOrOutCarpark(byte inOrOutCarpark) { | ||
| 91 | + this.inOrOutCarpark = inOrOutCarpark; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public int getCompanyCode() { | ||
| 95 | + return companyCode; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public void setCompanyCode(int companyCode) { | ||
| 99 | + this.companyCode = companyCode; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public int getLineId() { | ||
| 103 | + return lineId; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public void setLineId(int lineId) { | ||
| 107 | + this.lineId = lineId; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public String getDeviceId() { | ||
| 111 | + return deviceId; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setDeviceId(String deviceId) { | ||
| 115 | + this.deviceId = deviceId; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public String getCarparkNo() { | ||
| 119 | + return carparkNo; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public void setCarparkNo(String carparkNo) { | ||
| 123 | + this.carparkNo = carparkNo; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public String getStopNo() { | ||
| 127 | + return stopNo; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public void setStopNo(String stopNo) { | ||
| 131 | + this.stopNo = stopNo; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public float getLon() { | ||
| 135 | + return lon; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public void setLon(float lon) { | ||
| 139 | + this.lon = lon; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public float getLat() { | ||
| 143 | + return lat; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public void setLat(float lat) { | ||
| 147 | + this.lat = lat; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + public long getTimestamp() { | ||
| 151 | + return timestamp; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + public void setTimestamp(long timestamp) { | ||
| 155 | + this.timestamp = timestamp; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public float getSpeed() { | ||
| 159 | + return speed; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + public void setSpeed(float speed) { | ||
| 163 | + this.speed = speed; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public float getDirection() { | ||
| 167 | + return direction; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public void setDirection(float direction) { | ||
| 171 | + this.direction = direction; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + public byte getState() { | ||
| 175 | + return state; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + public void setState(byte state) { | ||
| 179 | + this.state = state; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + public byte getUpDown() { | ||
| 183 | + return upDown; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public void setUpDown(byte upDown) { | ||
| 187 | + this.upDown = upDown; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public String getInsideCode() { | ||
| 191 | + return insideCode; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + public void setInsideCode(String insideCode) { | ||
| 195 | + this.insideCode = insideCode; | ||
| 196 | + } | ||
| 197 | +} |
src/main/java/com/bsth/entity/SectionGrid.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/SectionGrid.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.HashSet; | ||
| 4 | +import java.util.Set; | ||
| 5 | + | ||
| 6 | +public class SectionGrid { | ||
| 7 | + | ||
| 8 | + private Set<SectionInfo> secs = new HashSet<SectionInfo>(); | ||
| 9 | + | ||
| 10 | + public Set<SectionInfo> getSecs() { | ||
| 11 | + return secs; | ||
| 12 | + } | ||
| 13 | +} |
src/main/java/com/bsth/entity/SectionInfo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/SectionInfo.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import com.bsth.geo.Point; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author Hill | ||
| 9 | + */ | ||
| 10 | +public class SectionInfo { | ||
| 11 | + | ||
| 12 | + private final static double SPEEDING_LIMIT = 60; | ||
| 13 | + | ||
| 14 | + private int id; | ||
| 15 | + private String sectionCode; | ||
| 16 | + private String roadCoding; | ||
| 17 | + private String sectionName; | ||
| 18 | + private double sectionDistance; | ||
| 19 | + private double speedLimit; | ||
| 20 | + private List<Point> points; | ||
| 21 | + | ||
| 22 | + private int lineId; | ||
| 23 | + private int lineCode; | ||
| 24 | + private int directions; | ||
| 25 | + | ||
| 26 | + private int isRoadeSpeed; | ||
| 27 | + | ||
| 28 | + public int getIsRoadeSpeed() { | ||
| 29 | + return isRoadeSpeed; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setIsRoadeSpeed(int isRoadeSpeed) { | ||
| 33 | + this.isRoadeSpeed = isRoadeSpeed; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public int getDirections() { | ||
| 37 | + return directions; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public void setDirections(int directions) { | ||
| 41 | + this.directions = directions; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public int getLineId() { | ||
| 45 | + return lineId; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setLineId(int lineId) { | ||
| 49 | + this.lineId = lineId; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public List<Point> getPoints() { | ||
| 53 | + return points; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setPoints(List<Point> points) { | ||
| 57 | + this.points = points; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public int getId() { | ||
| 61 | + return id; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setId(int id) { | ||
| 65 | + this.id = id; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public String getSectionCode() { | ||
| 69 | + return sectionCode; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setSectionCode(String sectionCode) { | ||
| 73 | + this.sectionCode = sectionCode; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public String getRoadCoding() { | ||
| 77 | + return roadCoding; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setRoadCoding(String roadCoding) { | ||
| 81 | + this.roadCoding = roadCoding; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public String getSectionName() { | ||
| 85 | + return sectionName; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public void setSectionName(String sectionName) { | ||
| 89 | + this.sectionName = sectionName; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public double getSectionDistance() { | ||
| 93 | + return sectionDistance; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setSectionDistance(double sectionDistance) { | ||
| 97 | + this.sectionDistance = sectionDistance; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public double getSpeedLimit() { | ||
| 101 | + if (speedLimit > 0) return speedLimit; | ||
| 102 | + else return SPEEDING_LIMIT; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void setSpeedLimit(double speedLimit) { | ||
| 106 | + this.speedLimit = speedLimit; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public int getLineCode() { | ||
| 110 | + return lineCode; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public void setLineCode(int lineCode) { | ||
| 114 | + this.lineCode = lineCode; | ||
| 115 | + } | ||
| 116 | +} |
src/main/java/com/bsth/entity/SpecialStation.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/SpecialStation.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 对付线路回环的情况(如起点站->第四站->起点站) | ||
| 5 | + * @author Hill | ||
| 6 | + * | ||
| 7 | + */ | ||
| 8 | +public class SpecialStation { | ||
| 9 | + | ||
| 10 | + private int lineId; | ||
| 11 | + | ||
| 12 | + private String stopNo; | ||
| 13 | + | ||
| 14 | + private String lastStopNo; | ||
| 15 | + | ||
| 16 | + public int getLineId() { | ||
| 17 | + return lineId; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public void setLineId(int lineId) { | ||
| 21 | + this.lineId = lineId; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public String getStopNo() { | ||
| 25 | + return stopNo; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setStopNo(String stopNo) { | ||
| 29 | + this.stopNo = stopNo; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public String getLastStopNo() { | ||
| 33 | + return lastStopNo; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public void setLastStopNo(String lastStopNo) { | ||
| 37 | + this.lastStopNo = lastStopNo; | ||
| 38 | + } | ||
| 39 | +} |
src/main/java/com/bsth/entity/SpeedingData.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/SpeedingData.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | + | ||
| 5 | +public class SpeedingData { | ||
| 6 | + | ||
| 7 | + private int id; | ||
| 8 | + private String vehicle; | ||
| 9 | + private int line; | ||
| 10 | + private int upDown; | ||
| 11 | + private float lon; | ||
| 12 | + private float lat; | ||
| 13 | + private float speed; | ||
| 14 | + private long timestamp; | ||
| 15 | + private Date createDate; | ||
| 16 | + | ||
| 17 | + public SpeedingData() { | ||
| 18 | + | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public SpeedingData(RealTimeGps gps) { | ||
| 22 | + vehicle = gps.getVehicle(); | ||
| 23 | + line = gps.getLineId(); | ||
| 24 | + upDown = gps.getUpDown(); | ||
| 25 | + lon = gps.getLon(); | ||
| 26 | + lat = gps.getLat(); | ||
| 27 | + speed = gps.getSpeed(); | ||
| 28 | + timestamp = gps.getTimestamp(); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public int getId() { | ||
| 32 | + return id; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setId(int id) { | ||
| 36 | + this.id = id; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public String getVehicle() { | ||
| 40 | + return vehicle; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setVehicle(String vehicle) { | ||
| 44 | + this.vehicle = vehicle; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public int getLine() { | ||
| 48 | + return line; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setLine(int line) { | ||
| 52 | + this.line = line; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public int getUpDown() { | ||
| 56 | + return upDown; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setUpDown(int upDown) { | ||
| 60 | + this.upDown = upDown; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public float getLon() { | ||
| 64 | + return lon; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setLon(float lon) { | ||
| 68 | + this.lon = lon; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public float getLat() { | ||
| 72 | + return lat; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setLat(float lat) { | ||
| 76 | + this.lat = lat; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public float getSpeed() { | ||
| 80 | + return speed; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void setSpeed(float speed) { | ||
| 84 | + this.speed = speed; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public long getTimestamp() { | ||
| 88 | + return timestamp; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setTimestamp(long timestamp) { | ||
| 92 | + this.timestamp = timestamp; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public Date getCreateDate() { | ||
| 96 | + return createDate; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public void setCreateDate(Date createDate) { | ||
| 100 | + this.createDate = createDate; | ||
| 101 | + } | ||
| 102 | +} |
src/main/java/com/bsth/entity/StopInfo.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/StopInfo.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import com.bsth.geo.Point; | ||
| 6 | + | ||
| 7 | +public class StopInfo { | ||
| 8 | + | ||
| 9 | + private int id; | ||
| 10 | + private String stationCod; | ||
| 11 | + private String stationName; | ||
| 12 | + private String stationType; | ||
| 13 | + private String roadCoding; | ||
| 14 | + private Point point; | ||
| 15 | + private String shapesType; | ||
| 16 | + private int radius; | ||
| 17 | + private List<Point> points; | ||
| 18 | + private double distances; | ||
| 19 | + | ||
| 20 | + private int lineId; | ||
| 21 | + private int lineCode; | ||
| 22 | + private int directions; | ||
| 23 | + | ||
| 24 | + public double getDistances() { | ||
| 25 | + return distances; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setDistances(double distances) { | ||
| 29 | + this.distances = distances; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public int getRadius() { | ||
| 33 | + return radius; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public void setRadius(int radius) { | ||
| 37 | + this.radius = radius; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public List<Point> getPoints() { | ||
| 41 | + return points; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public void setPoints(List<Point> points) { | ||
| 45 | + this.points = points; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public String getShapesType() { | ||
| 49 | + return shapesType; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setShapesType(String shapesType) { | ||
| 53 | + this.shapesType = shapesType; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public int getDirections() { | ||
| 57 | + return directions; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setDirections(int directions) { | ||
| 61 | + this.directions = directions; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public int getLineId() { | ||
| 65 | + return lineId; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setLineId(int lineId) { | ||
| 69 | + this.lineId = lineId; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public Point getPoint() { | ||
| 73 | + return point; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setPoint(Point point) { | ||
| 77 | + this.point = point; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public int getId() { | ||
| 81 | + return id; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setId(int id) { | ||
| 85 | + this.id = id; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public String getStationCod() { | ||
| 89 | + return stationCod; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setStationCod(String stationCod) { | ||
| 93 | + this.stationCod = stationCod; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public String getStationName() { | ||
| 97 | + return stationName; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public void setStationName(String stationName) { | ||
| 101 | + this.stationName = stationName; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public String getStationType() { | ||
| 105 | + return stationType; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setStationType(String stationType) { | ||
| 109 | + this.stationType = stationType; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public String getRoadCoding() { | ||
| 113 | + return roadCoding; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setRoadCoding(String roadCoding) { | ||
| 117 | + this.roadCoding = roadCoding; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public int getLineCode() { | ||
| 121 | + return lineCode; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public void setLineCode(int lineCode) { | ||
| 125 | + this.lineCode = lineCode; | ||
| 126 | + } | ||
| 127 | +} |
src/main/java/com/bsth/entity/VehicleData.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/entity/VehicleData.java | ||
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import com.bsth.socket.protocol.Message0201; | ||
| 4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 5 | +import com.fasterxml.jackson.annotation.JsonProperty; | ||
| 6 | +import org.springframework.beans.BeanUtils; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + * 整车数据 | ||
| 11 | + */ | ||
| 12 | +public class VehicleData extends Data { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 车辆状态 | ||
| 16 | + * 0x01 车辆启动 | ||
| 17 | + * 0x02 车辆熄火 | ||
| 18 | + * 0x03 其它 | ||
| 19 | + * 0xFE 异常 | ||
| 20 | + * 0xFF 无效 | ||
| 21 | + */ | ||
| 22 | + private byte vehicleState; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 充电状态 | ||
| 26 | + * 0x01 停车充电 | ||
| 27 | + * 0x02 行驶充电 | ||
| 28 | + * 0x03 未充电 | ||
| 29 | + * 0x04 充电完成 | ||
| 30 | + * 0xFE 异常 | ||
| 31 | + * 0xFF 无效 | ||
| 32 | + */ | ||
| 33 | + private byte chargeState; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 运行模式 | ||
| 37 | + * 0x01 纯电 | ||
| 38 | + * 0x02 混动 | ||
| 39 | + * 0x03 燃油 | ||
| 40 | + * 0xFE 异常 | ||
| 41 | + * 0xFF 无效 | ||
| 42 | + */ | ||
| 43 | + private byte runMode; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 车速 0-2200 | ||
| 47 | + * 分辨率0.1km/h | ||
| 48 | + * 0xff 0xfe 异常 | ||
| 49 | + * 0xff 0xff 无效 | ||
| 50 | + */ | ||
| 51 | + private short speed; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 累计里程 0-9999999 | ||
| 55 | + * 分辨率0.1km/h | ||
| 56 | + * 0xff 0xff 0xff 0xfe 异常 | ||
| 57 | + * 0xff 0xff 0xff 0xff 无效 | ||
| 58 | + */ | ||
| 59 | + private int totalMiles; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 总电压 0-10000 | ||
| 63 | + * 分辨率0.1v | ||
| 64 | + * 0xff 0xfe 异常 | ||
| 65 | + * 0xff 0xff 无效 | ||
| 66 | + */ | ||
| 67 | + private short totalVoltage; | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 总电流 0-20000 | ||
| 71 | + * 分辨率0.1a | ||
| 72 | + * 0xff 0xfe 异常 | ||
| 73 | + * 0xff 0xff 无效 | ||
| 74 | + */ | ||
| 75 | + private short totalCurrent; | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * soc 0-100% | ||
| 79 | + * 分辨率1% | ||
| 80 | + * 0xFE 异常 | ||
| 81 | + * 0xFF 无效 | ||
| 82 | + */ | ||
| 83 | + private byte soc; | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * dc-dc状态 | ||
| 87 | + * 0x01 工作 | ||
| 88 | + * 0x02 断开 | ||
| 89 | + * 0xFE 异常 | ||
| 90 | + * 0xFF 无效 | ||
| 91 | + */ | ||
| 92 | + private byte dcState; | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 挡位 | ||
| 96 | + */ | ||
| 97 | + @JsonIgnore | ||
| 98 | + private byte gear; | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 驱动力 | ||
| 102 | + */ | ||
| 103 | + private boolean drivingForce; | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * 制动力 | ||
| 107 | + */ | ||
| 108 | + private boolean brakingForce; | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 挡位(json) | ||
| 112 | + */ | ||
| 113 | + @JsonProperty("gear") | ||
| 114 | + private byte gear1; | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * 绝缘电阻 0-60000 | ||
| 118 | + * 分辨率 1k欧 | ||
| 119 | + */ | ||
| 120 | + private int insulationResistance; | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 加速踏板行程值 0-100% | ||
| 124 | + * 分辨率1% | ||
| 125 | + * 0xFE 异常 | ||
| 126 | + * 0xFF 无效 | ||
| 127 | + */ | ||
| 128 | + private byte acceleratorState; | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * 制动踏板状态 0-100% | ||
| 132 | + * 分辨率1% 在无具体行程值情况下,用“101”表示制动有效状态 | ||
| 133 | + * 0xFE 异常 | ||
| 134 | + * 0xFF 无效 | ||
| 135 | + */ | ||
| 136 | + private byte brakePedalState; | ||
| 137 | + | ||
| 138 | + public VehicleData() { | ||
| 139 | + | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public VehicleData(Message0201 message0201) { | ||
| 143 | + BeanUtils.copyProperties(message0201, this); | ||
| 144 | + this.drivingForce = (gear & 32) == 32 ? true : false; | ||
| 145 | + this.drivingForce = (gear & 16) == 16 ? true : false; | ||
| 146 | + this.gear1 = (byte) (gear & 15); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public byte getVehicleState() { | ||
| 150 | + return vehicleState; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public void setVehicleState(byte vehicleState) { | ||
| 154 | + this.vehicleState = vehicleState; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public byte getChargeState() { | ||
| 158 | + return chargeState; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public void setChargeState(byte chargeState) { | ||
| 162 | + this.chargeState = chargeState; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public byte getRunMode() { | ||
| 166 | + return runMode; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public void setRunMode(byte runMode) { | ||
| 170 | + this.runMode = runMode; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public short getSpeed() { | ||
| 174 | + return speed; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + public void setSpeed(short speed) { | ||
| 178 | + this.speed = speed; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public int getTotalMiles() { | ||
| 182 | + return totalMiles; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + public void setTotalMiles(int totalMiles) { | ||
| 186 | + this.totalMiles = totalMiles; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + public short getTotalVoltage() { | ||
| 190 | + return totalVoltage; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + public void setTotalVoltage(short totalVoltage) { | ||
| 194 | + this.totalVoltage = totalVoltage; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + public short getTotalCurrent() { | ||
| 198 | + return totalCurrent; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + public void setTotalCurrent(short totalCurrent) { | ||
| 202 | + this.totalCurrent = totalCurrent; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + public byte getSoc() { | ||
| 206 | + return soc; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + public void setSoc(byte soc) { | ||
| 210 | + this.soc = soc; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + public byte getDcState() { | ||
| 214 | + return dcState; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + public void setDcState(byte dcState) { | ||
| 218 | + this.dcState = dcState; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public byte getGear() { | ||
| 222 | + return gear; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + public void setGear(byte gear) { | ||
| 226 | + this.gear = gear; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + public boolean isDrivingForce() { | ||
| 230 | + return drivingForce; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + public void setDrivingForce(boolean drivingForce) { | ||
| 234 | + this.drivingForce = drivingForce; | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + public boolean isBrakingForce() { | ||
| 238 | + return brakingForce; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + public void setBrakingForce(boolean brakingForce) { | ||
| 242 | + this.brakingForce = brakingForce; | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + public byte getGear1() { | ||
| 246 | + return gear1; | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + public void setGear1(byte gear1) { | ||
| 250 | + this.gear1 = gear1; | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + public int getInsulationResistance() { | ||
| 254 | + return insulationResistance; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + public void setInsulationResistance(int insulationResistance) { | ||
| 258 | + this.insulationResistance = insulationResistance; | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + public byte getAcceleratorState() { | ||
| 262 | + return acceleratorState; | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + public void setAcceleratorState(byte acceleratorState) { | ||
| 266 | + this.acceleratorState = acceleratorState; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + public byte getBrakePedalState() { | ||
| 270 | + return brakePedalState; | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + public void setBrakePedalState(byte brakePedalState) { | ||
| 274 | + this.brakePedalState = brakePedalState; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + @Override | ||
| 278 | + public String toString() { | ||
| 279 | + StringBuilder sb = new StringBuilder(); | ||
| 280 | + sb.append("车辆状态: ").append(vehicleState) | ||
| 281 | + .append(" 充电状态: ").append(chargeState) | ||
| 282 | + .append(" 运行模式: ").append(runMode) | ||
| 283 | + .append(" 车速: ").append(speed) | ||
| 284 | + .append(" 累计里程: ").append(totalMiles) | ||
| 285 | + .append(" 总电压: ").append(totalVoltage) | ||
| 286 | + .append(" 总电流: ").append(totalCurrent) | ||
| 287 | + .append(" soc: ").append(soc) | ||
| 288 | + .append(" dc-dc状态: ").append(dcState) | ||
| 289 | + .append(" 挡位: ").append(gear) | ||
| 290 | + .append(" 绝缘电阻: ").append(insulationResistance) | ||
| 291 | + .append(" 加速踏板行程值: ").append(acceleratorState) | ||
| 292 | + .append(" 制动踏板状态: ").append(brakePedalState); | ||
| 293 | + | ||
| 294 | + return sb.toString(); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + @Override | ||
| 298 | + public String getType() { | ||
| 299 | + return "vehicle_data"; | ||
| 300 | + } | ||
| 301 | +} |
src/main/java/com/bsth/geo/Bounds.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/geo/Bounds.java | ||
| 1 | +package com.bsth.geo; | ||
| 2 | + | ||
| 3 | +public final class Bounds { | ||
| 4 | + | ||
| 5 | + private Point northEast; | ||
| 6 | + private Point southWest; | ||
| 7 | + | ||
| 8 | + public Bounds(Point min, Point max) { | ||
| 9 | + this.southWest = min; | ||
| 10 | + this.northEast = max; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public Point getNorthEast() { | ||
| 14 | + return northEast; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public Point getSouthWest() { | ||
| 18 | + return southWest; | ||
| 19 | + } | ||
| 20 | +} |
src/main/java/com/bsth/geo/Circle.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/geo/Circle.java | ||
| 1 | +package com.bsth.geo; | ||
| 2 | + | ||
| 3 | +public final class Circle { | ||
| 4 | + | ||
| 5 | + private Point center; | ||
| 6 | + private double radius; | ||
| 7 | + | ||
| 8 | + public Circle(Point c, double r) { | ||
| 9 | + this.center = c; | ||
| 10 | + this.radius = r; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public Point getCenter() { | ||
| 14 | + return center; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public double getRadius() { | ||
| 18 | + return radius; | ||
| 19 | + } | ||
| 20 | +} |
src/main/java/com/bsth/geo/Point.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/geo/Point.java | ||
| 1 | +package com.bsth.geo; | ||
| 2 | + | ||
| 3 | +public class Point { | ||
| 4 | + | ||
| 5 | + private double lon; | ||
| 6 | + private double lat; | ||
| 7 | + | ||
| 8 | + public Point(double lon, double lat) { | ||
| 9 | + this.lon = lon; | ||
| 10 | + this.lat = lat; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public double getLon() { | ||
| 14 | + return lon; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public double getLat() { | ||
| 18 | + return lat; | ||
| 19 | + } | ||
| 20 | +} |
src/main/java/com/bsth/geo/Polygon.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/geo/Polygon.java | ||
| 1 | +package com.bsth.geo; | ||
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +public final class Polygon { | ||
| 7 | + | ||
| 8 | + private List<Point> points; | ||
| 9 | + private Bounds bounds; | ||
| 10 | + | ||
| 11 | + public Polygon(List<Point> ps) { | ||
| 12 | + this.points = new ArrayList<Point>(ps); | ||
| 13 | + double minlon = 200, minlat = 200, maxlon = -1, maxlat = -1; | ||
| 14 | + for (Point p : ps) { | ||
| 15 | + minlon = p.getLon() < minlon ? p.getLon() : minlon; | ||
| 16 | + minlat = p.getLat() < minlat ? p.getLat() : minlat; | ||
| 17 | + maxlon = p.getLon() > maxlon ? p.getLon() : maxlon; | ||
| 18 | + maxlat = p.getLat() > maxlat ? p.getLat() : maxlat; | ||
| 19 | + } | ||
| 20 | + bounds = new Bounds(new Point(minlon, minlat), new Point(maxlon, maxlat)); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public List<Point> getPoints() { | ||
| 24 | + return new ArrayList<Point>(points); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public Bounds getBounds() { | ||
| 28 | + return bounds; | ||
| 29 | + } | ||
| 30 | +} |
src/main/java/com/bsth/service/BasicDataService.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/service/BasicDataService.java | ||
| 1 | +package com.bsth.service; | ||
| 2 | + | ||
| 3 | +import java.sql.ResultSet; | ||
| 4 | +import java.sql.SQLException; | ||
| 5 | +import java.util.ArrayList; | ||
| 6 | +import java.util.Calendar; | ||
| 7 | +import java.util.HashMap; | ||
| 8 | +import java.util.List; | ||
| 9 | +import java.util.Map; | ||
| 10 | +import java.util.concurrent.Executors; | ||
| 11 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 12 | +import java.util.concurrent.ThreadFactory; | ||
| 13 | +import java.util.concurrent.TimeUnit; | ||
| 14 | +import java.util.regex.Matcher; | ||
| 15 | +import java.util.regex.Pattern; | ||
| 16 | + | ||
| 17 | +import org.slf4j.Logger; | ||
| 18 | +import org.slf4j.LoggerFactory; | ||
| 19 | +import org.springframework.beans.factory.DisposableBean; | ||
| 20 | +import org.springframework.beans.factory.InitializingBean; | ||
| 21 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 22 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 23 | +import org.springframework.jdbc.core.RowMapper; | ||
| 24 | +import org.springframework.stereotype.Service; | ||
| 25 | + | ||
| 26 | +import com.bsth.entity.CarParkInfo; | ||
| 27 | +import com.bsth.entity.DeviceSimMapping; | ||
| 28 | +import com.bsth.entity.GridInfo; | ||
| 29 | +import com.bsth.entity.HistoryArrival; | ||
| 30 | +import com.bsth.entity.LineInfo; | ||
| 31 | +import com.bsth.entity.SectionGrid; | ||
| 32 | +import com.bsth.entity.SectionInfo; | ||
| 33 | +import com.bsth.entity.SpecialStation; | ||
| 34 | +import com.bsth.entity.StopInfo; | ||
| 35 | +import com.bsth.geo.Point; | ||
| 36 | + | ||
| 37 | +@Service | ||
| 38 | +public class BasicDataService implements InitializingBean, DisposableBean { | ||
| 39 | + | ||
| 40 | + private final static Logger log = LoggerFactory.getLogger(BasicDataService.class); | ||
| 41 | + | ||
| 42 | + @Autowired | ||
| 43 | + private JdbcTemplate msJdbcTemplate; | ||
| 44 | + @Autowired | ||
| 45 | + private JdbcTemplate controlJdbcTemplate; | ||
| 46 | + private static Map<Integer, LineInfo> id_info = new HashMap<Integer, LineInfo>(); | ||
| 47 | + private static List<CarParkInfo> parks = new ArrayList<CarParkInfo>(); | ||
| 48 | + private static List<Integer> sline = new ArrayList<Integer>(); | ||
| 49 | + private static Map<String, DeviceSimMapping> mapping = new HashMap<String, DeviceSimMapping>(); | ||
| 50 | + private static Map<String, String> sim_device = new HashMap<String, String>(); | ||
| 51 | + private static Map<String, String> device_sim = new HashMap<String, String>(); | ||
| 52 | + private static GridInfo ginfo = new GridInfo(); | ||
| 53 | + private static int year = 0; | ||
| 54 | + private ScheduledExecutorService sexec = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public Thread newThread(Runnable r) { | ||
| 58 | + // TODO Auto-generated method stub | ||
| 59 | + Thread t = new Thread(r); | ||
| 60 | + t.setName("BasicDataServiceScheduled"); | ||
| 61 | + return t; | ||
| 62 | + } | ||
| 63 | + }); | ||
| 64 | + | ||
| 65 | + public synchronized void loadBasicData() { | ||
| 66 | + Map<Integer, LineInfo> id_info = new HashMap<Integer, LineInfo>(); | ||
| 67 | + List<CarParkInfo> parks = new ArrayList<CarParkInfo>(); | ||
| 68 | + List<Integer> sline = new ArrayList<Integer>(); | ||
| 69 | + Map<String, DeviceSimMapping> mapping = new HashMap<String, DeviceSimMapping>(); | ||
| 70 | + Map<String, String> sim_device = new HashMap<String, String>(); | ||
| 71 | + Map<String, String> device_sim = new HashMap<String, String>(); | ||
| 72 | + | ||
| 73 | + String qline = "select a.id,in_use,line_code,name,start_station_name,start_station_first_time,start_station_end_time,end_station_name,end_station_first_time,end_station_end_time,company,branche_company,length,telephone,speed_limit,line_play_type from bsth_c_line a left join bsth_c_line_information b on a.id = b.line where a.destroy = 0"; | ||
| 74 | + // 查询完整路段 | ||
| 75 | + // 改 查询路段 只有分段路段了 | ||
| 76 | + String qsection = "select b.id,b.section_code,b.section_name,b.section_distance,b.speed_limit,AsText(b.gsection_vector) as gsection_vector,a.line,a.line_code,a.directions,a.is_roade_speed from bsth_c_sectionroute a join bsth_c_section b on a.section = b.id where line is not null and a.destroy = 0 order by a.line,a.directions,a.sectionroute_code"; | ||
| 77 | + // 查询分段路段 | ||
| 78 | + //String qsection = "select b.id,b.road_code as section_code,b.road_name as section_name,0 as section_distance,b.speed as speed_limit,AsText(b.groad_vector) as gsection_vector,a.line,a.line_code,a.directions,-1 as is_roade_speed from bsth_c_sectionspeed a join bsth_c_road b on a.road = b.id order by a.line,a.directions,a.code"; | ||
| 79 | + String qstop = "select b.id,b.station_cod,b.station_name,b.road_coding,b.g_lonx,b.g_laty,b.shapes_type,b.radius,AsText(b.g_polygon_grid) as g_polygon_grid,a.line,a.line_code,a.directions,a.distances from bsth_c_stationroute a join bsth_c_station b on a.station = b.id where a.destroy = 0 order by a.line,a.directions,a.station_route_code"; | ||
| 80 | + String qcarpark = "select b.id,b.park_code,b.park_name,b.shapes_type,b.radius,b.g_center_point,AsText(b.g_park_point) as g_polygon_grid from bsth_c_car_park b where b.destroy = 0"; | ||
| 81 | + // 查询特定线路ID | ||
| 82 | + String qsline = "select line_id from bsth_c_special_line"; | ||
| 83 | + // 查询设备号和小模块映射信息 | ||
| 84 | + String qmapping = "select device_id, sim, ext_enabled from bsth_c_device_sim_mapping"; | ||
| 85 | + // 查询最后的到离站信息 | ||
| 86 | + String qlastarr = "select device_id, line_id, stop_no, ts, up_down, up_down1, in_out, state, last_stop_no, last_up_down from bsth_c_last_arrival"; | ||
| 87 | + // 查询特殊站点(回环二次进站) | ||
| 88 | + String qsstation = "select line_id, stop_no, last_stop_no from bsth_c_special_station order by line_id"; | ||
| 89 | + List<LineInfo> lines = controlJdbcTemplate.query(qline, new RowMapperLineInfo()); | ||
| 90 | + List<SectionInfo> secs = controlJdbcTemplate.query(qsection, new RowMapperSectionInfo()); | ||
| 91 | + List<StopInfo> stops = controlJdbcTemplate.query(qstop, new RowMapperStopInfo()); | ||
| 92 | + parks = controlJdbcTemplate.query(qcarpark, new RowMapperCarParkInfo()); | ||
| 93 | + sline = msJdbcTemplate.queryForList(qsline, Integer.class); | ||
| 94 | + List<DeviceSimMapping> dsms = msJdbcTemplate.query(qmapping, new RowMapperDeviceSimMapping()); | ||
| 95 | + List<HistoryArrival> lastarrs = msJdbcTemplate.query(qlastarr, new RowMapperHistoryArrival()); | ||
| 96 | + List<SpecialStation> sstations = msJdbcTemplate.query(qsstation, new RowMapperSpecialStation()); | ||
| 97 | + // 缓存设备和小模块映射信息 | ||
| 98 | + for (DeviceSimMapping dsm : dsms) { | ||
| 99 | + mapping.put(dsm.getDeviceId(), dsm); | ||
| 100 | + sim_device.put(dsm.getSim(), dsm.getDeviceId()); | ||
| 101 | + device_sim.put(dsm.getDeviceId(), dsm.getSim()); | ||
| 102 | + } | ||
| 103 | + // 缓存线路基本信息 | ||
| 104 | + for (LineInfo line : lines) { | ||
| 105 | + id_info.put(line.getLineId(), line); | ||
| 106 | + } | ||
| 107 | + int oldId = -1; | ||
| 108 | + LineInfo line = null; | ||
| 109 | + // 线路信息中添加回环站点信息 | ||
| 110 | + for (SpecialStation ss : sstations) { | ||
| 111 | + if (ss.getLineId() != oldId) { | ||
| 112 | + oldId = ss.getLineId(); | ||
| 113 | + line = id_info.get(oldId); | ||
| 114 | + } | ||
| 115 | + if (line != null) { | ||
| 116 | + line.getSpecailStation().add(ss); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + // 线路信息中添加分段的上下行路段信息 | ||
| 120 | + oldId = -1; | ||
| 121 | + line = null; | ||
| 122 | + double minLon = 180, maxLon = 0, minLat = 180, maxLat = 0; | ||
| 123 | + for (SectionInfo sec : secs) { | ||
| 124 | + if (sec.getLineCode() != oldId) { | ||
| 125 | + oldId = sec.getLineCode(); | ||
| 126 | + line = id_info.get(oldId); | ||
| 127 | + } | ||
| 128 | + if (line != null) { | ||
| 129 | + if (sec.getDirections() == 0) line.getSectionsUp().add(sec); | ||
| 130 | + else line.getSectionsDown().add(sec); | ||
| 131 | + } | ||
| 132 | + for (Point p : sec.getPoints()) { | ||
| 133 | + minLon = Math.min(p.getLon(), minLon); | ||
| 134 | + maxLon = Math.max(p.getLon(), maxLon); | ||
| 135 | + minLat = Math.min(p.getLat(), minLat); | ||
| 136 | + maxLat = Math.max(p.getLat(), maxLat); | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + log.info("minLon:" + minLon + " maxLon:" + maxLon + " minLat:" + minLat + " maxLat:" + maxLat); | ||
| 140 | + int row = (int)Math.ceil((maxLon - minLon)/.001), column = (int)Math.ceil((maxLat - minLat)/.001); | ||
| 141 | + ginfo.setMinLon(minLon); | ||
| 142 | + ginfo.setMaxLon(maxLon); | ||
| 143 | + ginfo.setMinLat(minLat); | ||
| 144 | + ginfo.setMaxLat(maxLat); | ||
| 145 | + ginfo.setRow(row + 1); | ||
| 146 | + ginfo.setColumn(column + 1); | ||
| 147 | + ginfo.setGrid(new SectionGrid[row + 1][column + 1]); | ||
| 148 | + for (SectionInfo sec : secs) { | ||
| 149 | + for (Point p : sec.getPoints()) { | ||
| 150 | + int r = (int)Math.ceil((p.getLon() - minLon)/.001), c = (int)Math.ceil((p.getLat() - minLat)/.001); | ||
| 151 | + SectionGrid sg = ginfo.getGrid()[r][c]; | ||
| 152 | + if (sg == null) { | ||
| 153 | + sg = new SectionGrid(); | ||
| 154 | + ginfo.getGrid()[r][c] = sg; | ||
| 155 | + } | ||
| 156 | + sg.getSecs().add(sec); | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + // 线路信息中添加上下行站点信息 | ||
| 160 | + oldId = -1; | ||
| 161 | + line = null; | ||
| 162 | + for (StopInfo stop : stops) { | ||
| 163 | + if (stop.getLineCode() != oldId) { | ||
| 164 | + oldId = stop.getLineCode(); | ||
| 165 | + line = id_info.get(oldId); | ||
| 166 | + } | ||
| 167 | + if (line != null) { | ||
| 168 | + if (stop.getDirections() == 0) line.getStopsUp().add(stop); | ||
| 169 | + else line.getStopsDown().add(stop); | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + if (id_info.size() > 0) BasicDataService.id_info = id_info; | ||
| 174 | + if (parks.size() > 0) BasicDataService.parks = parks; | ||
| 175 | + if (sline.size() > 0) BasicDataService.sline = sline; | ||
| 176 | + if (mapping.size() > 0) BasicDataService.mapping = mapping; | ||
| 177 | + if (sim_device.size() > 0) BasicDataService.sim_device = sim_device; | ||
| 178 | + if (device_sim.size() > 0) BasicDataService.device_sim = device_sim; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + @Override | ||
| 182 | + public void afterPropertiesSet() throws Exception { | ||
| 183 | + // TODO Auto-generated method stub | ||
| 184 | + /*try { | ||
| 185 | + jdbcTemplate.execute("create table if not exists `bsth_c_gps_info` (`city_code` int(6) NOT NULL,`industry_code` int(5) NOT NULL,`company_code` int(5) NOT NULL,`line_id` int(6) NOT NULL,`device_id` varchar(8) NOT NULL,`driver_no` int(8) NOT NULL,`carpark_serial_no` smallint(5) unsigned NOT NULL,`carpark_no` varchar(255) NOT NULL,`stop_serial_no` smallint(5) unsigned NOT NULL,`stop_no` varchar(255) NOT NULL,`lon` float(10,6) NOT NULL,`lat` float(10,6) NOT NULL,`ts` bigint(20) NOT NULL,`speed_sensor` float(7,1) NOT NULL,`speed_gps` float(7,1) NOT NULL,`direction` float(7,1) NOT NULL,`in_temp` tinyint(4) NOT NULL,`service_state` bigint(20) NOT NULL,`control_state` bigint(20) NOT NULL,`total_miles` float(8,2) NOT NULL,`water_temp` tinyint(4) NOT NULL,`oil_consumption` float(4,1) NOT NULL,`engine_speed` int(11) NOT NULL,`inout_stop` tinyint(4) NOT NULL,`days_year` smallint(4) NOT NULL,`hours_day` tinyint(4) NOT NULL,`server_ts` bigint(20),`create_date` timestamp default CURRENT_TIMESTAMP,`section_code` varchar(255) NOT NULL,KEY `idx_test` (`days_year`,`device_id`,`ts`,`line_id`,`lon`,`lat`,`inout_stop`,`server_ts`,`section_code`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 PARTITION by hash(days_year) PARTITIONS 366"); | ||
| 186 | + log.info("历史gps服务初始化完成。。。"); | ||
| 187 | + } catch(Exception e) { | ||
| 188 | + //e.printStackTrace(); | ||
| 189 | + log.warn("历史gps服务初始化异常。。。", e); | ||
| 190 | + } | ||
| 191 | + try { | ||
| 192 | + jdbcTemplate.execute("create table if not exists `bsth_c_arrival_info` (`device_id` varchar(8) NOT NULL,`line_id` int(11) NOT NULL,`stop_no` varchar(32) NOT NULL,`ts` bigint(20) NOT NULL,`up_down` int(11) NOT NULL,`in_out` int(11) NOT NULL,`create_date` bigint(20) NOT NULL,`weeks_year` tinyint(4) NOT NULL,`create_timestamp` bigint(20),KEY `idx_test` (`weeks_year`,`device_id`,`ts`,`create_date`,`create_timestamp`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 PARTITION by hash(weeks_year) PARTITIONS 53"); | ||
| 193 | + log.info("历史到离站服务初始化完成。。。"); | ||
| 194 | + } catch (Exception e) { | ||
| 195 | + log.warn("历史到离站服务初始化异常。。。", e); | ||
| 196 | + }*/ | ||
| 197 | + try { | ||
| 198 | + loadBasicData(); | ||
| 199 | + } catch (Exception e) { | ||
| 200 | + log.error("BasicDataService初始化时加载基础数据异常", e); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + // 开启调度 | ||
| 204 | + sexec.scheduleAtFixedRate(new Runnable() { | ||
| 205 | + | ||
| 206 | + @Override | ||
| 207 | + public void run() { | ||
| 208 | + // TODO Auto-generated method stub | ||
| 209 | + try { | ||
| 210 | + loadBasicData(); | ||
| 211 | + } catch (Exception e) { | ||
| 212 | + log.error("BasicDataService加载基础数据异常", e); | ||
| 213 | + } | ||
| 214 | + } | ||
| 215 | + }, 1, 1, TimeUnit.HOURS); | ||
| 216 | + sexec.scheduleAtFixedRate(new SplitTableChecker(), 0, 10, TimeUnit.SECONDS); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + final class RowMapperSectionInfo implements RowMapper<SectionInfo> { | ||
| 220 | + | ||
| 221 | + private final Pattern p = Pattern.compile("(\\d+(\\.\\d+)?) (\\d+(\\.\\d+)?)"); | ||
| 222 | + | ||
| 223 | + @Override | ||
| 224 | + public SectionInfo mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 225 | + // TODO Auto-generated method stub | ||
| 226 | + SectionInfo section = new SectionInfo(); | ||
| 227 | + section.setId(rs.getInt("id")); | ||
| 228 | + section.setSectionCode(rs.getString("section_code")); | ||
| 229 | + section.setSectionName(rs.getString("section_name")); | ||
| 230 | + section.setSectionDistance(rs.getDouble("section_distance")); | ||
| 231 | + section.setSpeedLimit(rs.getDouble("speed_limit")); | ||
| 232 | + List<Point> points = new ArrayList<Point>(); | ||
| 233 | + String gstr = rs.getString("gsection_vector"); | ||
| 234 | + if (gstr != null) { | ||
| 235 | + Matcher m = p.matcher(gstr); | ||
| 236 | + while (m.find()) { | ||
| 237 | + points.add(new Point(Float.parseFloat(m.group(1)), Float.parseFloat(m.group(3)))); | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + section.setPoints(points); | ||
| 241 | + section.setLineId(rs.getInt("line")); | ||
| 242 | + section.setLineCode(rs.getInt("line_code")); | ||
| 243 | + section.setDirections(rs.getInt("directions")); | ||
| 244 | + section.setIsRoadeSpeed(rs.getInt("is_roade_speed")); | ||
| 245 | + return section; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + final class RowMapperLineInfo implements RowMapper<LineInfo> { | ||
| 251 | + | ||
| 252 | + @Override | ||
| 253 | + public LineInfo mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 254 | + // TODO Auto-generated method stub | ||
| 255 | + LineInfo line = new LineInfo(); | ||
| 256 | + line.setId(rs.getInt("id")); | ||
| 257 | + line.setInUse(rs.getInt("in_use")); | ||
| 258 | + line.setLineId(rs.getInt("line_code")); | ||
| 259 | + line.setLineName(rs.getString("name")); | ||
| 260 | + //line.setStartStation(rs.getInt("start_station")); | ||
| 261 | + line.setStartStationName(rs.getString("start_station_name")); | ||
| 262 | + line.setStartStationFirstTime(rs.getString("start_station_first_time")); | ||
| 263 | + line.setStartStationEndTime(rs.getString("start_station_end_time")); | ||
| 264 | + //line.setEndStation(rs.getInt("end_station")); | ||
| 265 | + line.setEndStationName(rs.getString("end_station_name")); | ||
| 266 | + line.setEndStationFirstTime(rs.getString("end_station_first_time")); | ||
| 267 | + line.setEndStationEndTime(rs.getString("end_station_end_time")); | ||
| 268 | + line.setCompany(rs.getString("company")); | ||
| 269 | + line.setBrancheCompany(rs.getString("branche_company")); | ||
| 270 | + line.setTelephone(rs.getString("telephone")); | ||
| 271 | + line.setSpeedLimit(rs.getDouble("speed_limit")); | ||
| 272 | + line.setLinePlayType(rs.getInt("line_play_type")); | ||
| 273 | + return line; | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + final class RowMapperStopInfo implements RowMapper<StopInfo> { | ||
| 279 | + | ||
| 280 | + private final Pattern p = Pattern.compile("(\\d+(\\.\\d+)?) (\\d+(\\.\\d+)?)"); | ||
| 281 | + @Override | ||
| 282 | + public StopInfo mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 283 | + // TODO Auto-generated method stub | ||
| 284 | + StopInfo stop = new StopInfo(); | ||
| 285 | + stop.setId(rs.getInt("id")); | ||
| 286 | + stop.setStationCod(rs.getString("station_cod")); | ||
| 287 | + stop.setStationName(rs.getString("station_name")); | ||
| 288 | + //stop.setStationType(rs.getString("station_type")); | ||
| 289 | + stop.setRoadCoding(rs.getString("road_coding")); | ||
| 290 | + float lon = rs.getFloat("g_lonx"); | ||
| 291 | + float lat = rs.getFloat("g_laty"); | ||
| 292 | + stop.setPoint(new Point(lon, lat)); | ||
| 293 | + stop.setLineId(rs.getInt("line")); | ||
| 294 | + stop.setLineCode(rs.getInt("line_code")); | ||
| 295 | + stop.setDirections(rs.getInt("directions")); | ||
| 296 | + stop.setShapesType(rs.getString("shapes_type")); | ||
| 297 | + stop.setRadius(rs.getInt("radius")); | ||
| 298 | + List<Point> points = new ArrayList<Point>(); | ||
| 299 | + String gstr = rs.getString("g_polygon_grid"); | ||
| 300 | + if (gstr != null) { | ||
| 301 | + Matcher m = p.matcher(gstr); | ||
| 302 | + while (m.find()) { | ||
| 303 | + points.add(new Point(Float.parseFloat(m.group(1)), Float.parseFloat(m.group(3)))); | ||
| 304 | + } | ||
| 305 | + } | ||
| 306 | + stop.setPoints(points); | ||
| 307 | + stop.setDistances(rs.getDouble("distances")*1000); | ||
| 308 | + return stop; | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + final class RowMapperCarParkInfo implements RowMapper<CarParkInfo> { | ||
| 314 | + | ||
| 315 | + private final Pattern p = Pattern.compile("(\\d+(\\.\\d+)?) (\\d+(\\.\\d+)?)"); | ||
| 316 | + @Override | ||
| 317 | + public CarParkInfo mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 318 | + // TODO Auto-generated method stub | ||
| 319 | + CarParkInfo park = new CarParkInfo(); | ||
| 320 | + park.setId(rs.getInt("id")); | ||
| 321 | + park.setParkCode(rs.getString("park_code")); | ||
| 322 | + park.setParkName(rs.getString("park_name")); | ||
| 323 | + String gstr = rs.getString("g_center_point"); | ||
| 324 | + if (gstr != null) { | ||
| 325 | + Matcher m = p.matcher(gstr); | ||
| 326 | + while (m.find()) { | ||
| 327 | + park.setPoint(new Point(Float.parseFloat(m.group(1)), Float.parseFloat(m.group(3)))); | ||
| 328 | + } | ||
| 329 | + } | ||
| 330 | + park.setShapesType(rs.getString("shapes_type")); | ||
| 331 | + park.setRadius(rs.getInt("radius")); | ||
| 332 | + List<Point> points = new ArrayList<Point>(); | ||
| 333 | + gstr = rs.getString("g_polygon_grid"); | ||
| 334 | + if (gstr != null) { | ||
| 335 | + Matcher m = p.matcher(gstr); | ||
| 336 | + while (m.find()) { | ||
| 337 | + points.add(new Point(Float.parseFloat(m.group(1)), Float.parseFloat(m.group(3)))); | ||
| 338 | + } | ||
| 339 | + } | ||
| 340 | + park.setPoints(points); | ||
| 341 | + return park; | ||
| 342 | + } | ||
| 343 | + | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + final class RowMapperDeviceSimMapping implements RowMapper<DeviceSimMapping> { | ||
| 347 | + | ||
| 348 | + @Override | ||
| 349 | + public DeviceSimMapping mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 350 | + // TODO Auto-generated method stub | ||
| 351 | + DeviceSimMapping dsm = new DeviceSimMapping(); | ||
| 352 | + dsm.setDeviceId(rs.getString("device_id")); | ||
| 353 | + dsm.setSim(rs.getString("sim")); | ||
| 354 | + dsm.setExtEnabled(rs.getInt("ext_enabled")); | ||
| 355 | + | ||
| 356 | + return dsm; | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | + final class RowMapperHistoryArrival implements RowMapper<HistoryArrival> { | ||
| 362 | + | ||
| 363 | + @Override | ||
| 364 | + public HistoryArrival mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 365 | + // TODO Auto-generated method stub | ||
| 366 | + HistoryArrival ha = new HistoryArrival(); | ||
| 367 | + ha.setDeviceId(rs.getString("device_id")); | ||
| 368 | + ha.setLineId(rs.getInt("line_id")); | ||
| 369 | + ha.setStopNo(rs.getString("stop_no")); | ||
| 370 | + ha.setTimestamp(rs.getLong("ts")); | ||
| 371 | + ha.setUpDown(rs.getInt("up_down")); | ||
| 372 | + ha.setUpDown1(rs.getInt("up_down1")); | ||
| 373 | + ha.setInOut(rs.getInt("in_out")); | ||
| 374 | + ha.setState(rs.getInt("state") == 1 ? true : false); | ||
| 375 | + ha.setLastStopNo(rs.getString("last_stop_no")); | ||
| 376 | + ha.setLastUpDown(rs.getInt("last_up_down")); | ||
| 377 | + | ||
| 378 | + return ha; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + final class RowMapperSpecialStation implements RowMapper<SpecialStation> { | ||
| 384 | + | ||
| 385 | + @Override | ||
| 386 | + public SpecialStation mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 387 | + // TODO Auto-generated method stub | ||
| 388 | + SpecialStation ss = new SpecialStation(); | ||
| 389 | + ss.setLineId(rs.getInt("line_id")); | ||
| 390 | + ss.setStopNo(rs.getString("stop_no")); | ||
| 391 | + ss.setLastStopNo(rs.getString("last_stop_no")); | ||
| 392 | + | ||
| 393 | + return ss; | ||
| 394 | + } | ||
| 395 | + | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + final class SplitTableChecker implements Runnable { | ||
| 399 | + | ||
| 400 | + private long nextTime = 0; | ||
| 401 | + | ||
| 402 | + @Override | ||
| 403 | + public void run() { | ||
| 404 | + // TODO Auto-generated method stub | ||
| 405 | + try { | ||
| 406 | + long now = System.currentTimeMillis(); | ||
| 407 | + Calendar c = Calendar.getInstance(); | ||
| 408 | + c.setTimeInMillis(now); | ||
| 409 | + if (nextTime < now) { | ||
| 410 | + nextTime = getNextTime(now); | ||
| 411 | + year = c.get(Calendar.YEAR); | ||
| 412 | + } | ||
| 413 | + } catch (Exception e) { | ||
| 414 | + log.error("SplitTableChecker schedule exception", e); | ||
| 415 | + } | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + private long getNextTime(long now) { | ||
| 421 | + Calendar c = Calendar.getInstance(); | ||
| 422 | + c.setTimeInMillis(now); | ||
| 423 | + c.add(Calendar.YEAR, 1); | ||
| 424 | + c.set(Calendar.MONTH, 0); | ||
| 425 | + c.set(Calendar.DAY_OF_MONTH, 1); | ||
| 426 | + c.set(Calendar.HOUR_OF_DAY, 0); | ||
| 427 | + c.set(Calendar.MINUTE, 0); | ||
| 428 | + c.set(Calendar.SECOND, 0); | ||
| 429 | + c.set(Calendar.MILLISECOND, 0); | ||
| 430 | + | ||
| 431 | + return c.getTimeInMillis(); | ||
| 432 | + } | ||
| 433 | + | ||
| 434 | + public static LineInfo getLineById(int id) { | ||
| 435 | + return id_info.get(id); | ||
| 436 | + } | ||
| 437 | + | ||
| 438 | + public static List<CarParkInfo> getCarParks() { | ||
| 439 | + return parks; | ||
| 440 | + } | ||
| 441 | + | ||
| 442 | + public static GridInfo getGinfo() { | ||
| 443 | + return ginfo; | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + public static List<Integer> getSpecialLine() { | ||
| 447 | + return sline; | ||
| 448 | + } | ||
| 449 | + | ||
| 450 | + public static DeviceSimMapping getMappingByDeviceId(String deviceId) { | ||
| 451 | + return mapping.get(deviceId); | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + public static String getDeviceIdBySim(String sim) { | ||
| 455 | + return sim_device.get(sim); | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + public static String getSimByDeviceId(String deviceId) { | ||
| 459 | + return device_sim.get(deviceId); | ||
| 460 | + } | ||
| 461 | + | ||
| 462 | + public static int getYear() { | ||
| 463 | + return year; | ||
| 464 | + } | ||
| 465 | + | ||
| 466 | + @Override | ||
| 467 | + public void destroy() throws Exception { | ||
| 468 | + // TODO Auto-generated method stub | ||
| 469 | + sexec.shutdown(); | ||
| 470 | + } | ||
| 471 | +} |
src/main/java/com/bsth/service/DownProtocolDataService.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/service/DownProtocolDataService.java | ||
| 1 | +package com.bsth.service; | ||
| 2 | + | ||
| 3 | +import java.io.BufferedOutputStream; | ||
| 4 | +import java.io.File; | ||
| 5 | +import java.io.FileNotFoundException; | ||
| 6 | +import java.io.FileOutputStream; | ||
| 7 | +import java.io.IOException; | ||
| 8 | +import java.text.SimpleDateFormat; | ||
| 9 | +import java.util.Date; | ||
| 10 | + | ||
| 11 | +import com.bsth.util.AppProperties; | ||
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @author Hill | ||
| 17 | + */ | ||
| 18 | +public class DownProtocolDataService { | ||
| 19 | + | ||
| 20 | + private final static Logger log = LoggerFactory.getLogger(DownProtocolDataService.class); | ||
| 21 | + | ||
| 22 | + private static DownProtocolDataService service = new DownProtocolDataService(); | ||
| 23 | + | ||
| 24 | + private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH"); | ||
| 25 | + | ||
| 26 | + private String dir = AppProperties.getDowndir(); | ||
| 27 | + | ||
| 28 | + private Date cur = new Date(); | ||
| 29 | + /** | ||
| 30 | + * 下次切换写文件时间节点 | ||
| 31 | + */ | ||
| 32 | + private long nextTime; | ||
| 33 | + | ||
| 34 | + private BufferedOutputStream out; | ||
| 35 | + | ||
| 36 | + private String fileName; | ||
| 37 | + | ||
| 38 | + private DownProtocolDataService() { | ||
| 39 | + File file = new File(dir); | ||
| 40 | + Date now = new Date(); | ||
| 41 | + if (!file.exists()) { file.mkdirs(); } | ||
| 42 | + fileName = sdf.format(now); | ||
| 43 | + nextTime = now.getTime() + 3600000 - now.getTime() % 3600000; | ||
| 44 | + try { | ||
| 45 | + out = new BufferedOutputStream(new FileOutputStream(dir + fileName, true)); | ||
| 46 | + } catch (FileNotFoundException e) { | ||
| 47 | + // TODO Auto-generated catch block | ||
| 48 | + log.error(dir + fileName + "文件未找到"); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public static DownProtocolDataService getInstance() { | ||
| 53 | + return service; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void write(byte[] bytes) throws IOException { | ||
| 57 | + long now = System.currentTimeMillis(); | ||
| 58 | + if (nextTime < now) { | ||
| 59 | + cur.setTime(now); | ||
| 60 | + rollOver(now); | ||
| 61 | + } | ||
| 62 | + out.write(bytes); | ||
| 63 | + out.flush(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + private synchronized void rollOver(long now) throws IOException { | ||
| 67 | + if (now < nextTime) { | ||
| 68 | + return; | ||
| 69 | + } | ||
| 70 | + BufferedOutputStream os = out; | ||
| 71 | + try { | ||
| 72 | + fileName = sdf.format(cur); | ||
| 73 | + File file = new File(dir + fileName); | ||
| 74 | + out = new BufferedOutputStream(new FileOutputStream(file, true)); | ||
| 75 | + nextTime = getNextTime(now); | ||
| 76 | + } catch (FileNotFoundException e) { | ||
| 77 | + // TODO Auto-generated catch block | ||
| 78 | + log.error(dir + fileName + "文件未找到"); | ||
| 79 | + } finally { | ||
| 80 | + os.flush(); | ||
| 81 | + os.close(); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + private long getNextTime(long now) { | ||
| 86 | + return now + 3600000 - now % 3600000; | ||
| 87 | + } | ||
| 88 | +} |
src/main/java/com/bsth/service/MessageService.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/service/MessageService.java | ||
| 1 | +package com.bsth.service; | ||
| 2 | + | ||
| 3 | +import java.io.ByteArrayOutputStream; | ||
| 4 | +import java.io.IOException; | ||
| 5 | +import java.io.InputStream; | ||
| 6 | +import java.io.OutputStream; | ||
| 7 | +import java.net.HttpURLConnection; | ||
| 8 | +import java.net.URL; | ||
| 9 | +import java.util.Map; | ||
| 10 | +import java.util.Queue; | ||
| 11 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 12 | +import java.util.concurrent.ConcurrentLinkedQueue; | ||
| 13 | +import java.util.concurrent.ExecutorService; | ||
| 14 | +import java.util.concurrent.Executors; | ||
| 15 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 16 | +import java.util.concurrent.ThreadFactory; | ||
| 17 | +import java.util.concurrent.TimeUnit; | ||
| 18 | + | ||
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 20 | +import org.apache.commons.io.IOUtils; | ||
| 21 | +import org.slf4j.Logger; | ||
| 22 | +import org.slf4j.LoggerFactory; | ||
| 23 | +import org.springframework.beans.factory.DisposableBean; | ||
| 24 | +import org.springframework.beans.factory.InitializingBean; | ||
| 25 | +import org.springframework.stereotype.Service; | ||
| 26 | + | ||
| 27 | +import com.bsth.socket.protocol.Message; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * @author Hill | ||
| 31 | + */ | ||
| 32 | +@Service | ||
| 33 | +public class MessageService implements InitializingBean, DisposableBean { | ||
| 34 | + | ||
| 35 | + private final static Logger log = LoggerFactory.getLogger(MessageService.class); | ||
| 36 | + | ||
| 37 | + private Map<String, Queue<Message>> device_msgs = new ConcurrentHashMap<String, Queue<Message>>(); | ||
| 38 | + private ScheduledExecutorService sexec = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public Thread newThread(Runnable r) { | ||
| 42 | + // TODO Auto-generated method stub | ||
| 43 | + Thread t = new Thread(r); | ||
| 44 | + t.setName("MessageServiceExecutor"); | ||
| 45 | + return t; | ||
| 46 | + } | ||
| 47 | + }); | ||
| 48 | + private ConcurrentLinkedQueue<Message> queue = new ConcurrentLinkedQueue<>(); | ||
| 49 | + private ExecutorService exec = Executors.newFixedThreadPool(5, new ThreadFactory() { | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public Thread newThread(Runnable r) { | ||
| 53 | + // TODO Auto-generated method stub | ||
| 54 | + Thread t = new Thread(r); | ||
| 55 | + t.setName("MessageUpPool"); | ||
| 56 | + return t; | ||
| 57 | + } | ||
| 58 | + }); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 消息下发 | ||
| 62 | + * @param msg | ||
| 63 | + */ | ||
| 64 | + public void down(Message msg) { | ||
| 65 | + // 0x64协议在下发时缓存此消息 以便确认时对应 | ||
| 66 | + /*if (msg.getCommandType() == 0x64) { | ||
| 67 | + String deviceId = msg.getMessageBody().getDeviceId(); | ||
| 68 | + Queue<Message> msgs = device_msgs.get(deviceId); | ||
| 69 | + if (msgs == null) { | ||
| 70 | + msgs = new ConcurrentLinkedQueue<>(); | ||
| 71 | + device_msgs.put(deviceId, msgs); | ||
| 72 | + } | ||
| 73 | + msgs.add(msg); | ||
| 74 | + } | ||
| 75 | + MessageSender.getInstance().send(msg);*/ | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public void up(Message msg) { | ||
| 79 | + if (msg != null) queue.add(msg); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 消息上传(包括应答) | ||
| 84 | + * @param msg | ||
| 85 | + */ | ||
| 86 | + private void upHandle(Message msg) { | ||
| 87 | + | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @SuppressWarnings("unchecked") | ||
| 91 | + public Map<String, Object> request(Map<String, Object> map, String url) { | ||
| 92 | + InputStream in = null; | ||
| 93 | + OutputStream out = null; | ||
| 94 | + HttpURLConnection con = null; | ||
| 95 | + try { | ||
| 96 | + con = (HttpURLConnection)new URL(url).openConnection(); | ||
| 97 | + con.setRequestMethod("POST"); | ||
| 98 | + con.setRequestProperty("keep-alive", "true"); | ||
| 99 | + con.setRequestProperty("Connection", "Close"); | ||
| 100 | + con.setRequestProperty("accept", "*/*"); | ||
| 101 | + con.setDoInput(true); | ||
| 102 | + con.setDoOutput(true); | ||
| 103 | + con.setReadTimeout(2500); | ||
| 104 | + con.setConnectTimeout(2500); | ||
| 105 | + out = con.getOutputStream(); | ||
| 106 | + out.write("json=".getBytes()); | ||
| 107 | + out.write(new ObjectMapper().writeValueAsBytes(map)); | ||
| 108 | + out.flush(); | ||
| 109 | + if (con.getResponseCode() == 200) { | ||
| 110 | + in = con.getInputStream(); | ||
| 111 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 112 | + IOUtils.copy(in, bout); bout.close(); | ||
| 113 | + log.info("Message:" + new String(bout.toByteArray())); | ||
| 114 | + return new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 115 | + } | ||
| 116 | + } catch (IOException e) { | ||
| 117 | + // TODO Auto-generated catch block | ||
| 118 | + log.error("调用消息上传接口时发生异常|" + map, e); | ||
| 119 | + } finally { | ||
| 120 | + try { | ||
| 121 | + if (in != null) in.close(); | ||
| 122 | + if (out != null) out.close(); | ||
| 123 | + } catch (IOException e) { | ||
| 124 | + // TODO Auto-generated catch block | ||
| 125 | + log.error("", e); | ||
| 126 | + } | ||
| 127 | + con.disconnect(); | ||
| 128 | + } | ||
| 129 | + return null; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @SuppressWarnings("unchecked") | ||
| 133 | + public Map<String, Object> requestJson(Map<String, Object> map, String url) { | ||
| 134 | + InputStream in = null; | ||
| 135 | + OutputStream out = null; | ||
| 136 | + HttpURLConnection con = null; | ||
| 137 | + try { | ||
| 138 | + con = (HttpURLConnection)new URL(url).openConnection(); | ||
| 139 | + con.setRequestMethod("POST"); | ||
| 140 | + con.setRequestProperty("keep-alive", "true"); | ||
| 141 | + con.setRequestProperty("Connection", "Close"); | ||
| 142 | + con.setRequestProperty("accept", "application/json"); | ||
| 143 | + con.setRequestProperty("content-type", "application/json"); | ||
| 144 | + con.setDoInput(true); | ||
| 145 | + con.setDoOutput(true); | ||
| 146 | + con.setReadTimeout(2500); | ||
| 147 | + con.setConnectTimeout(2500); | ||
| 148 | + out = con.getOutputStream(); | ||
| 149 | + out.write(new ObjectMapper().writeValueAsBytes(map)); | ||
| 150 | + out.flush(); | ||
| 151 | + if (con.getResponseCode() == 200) { | ||
| 152 | + in = con.getInputStream(); | ||
| 153 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 154 | + IOUtils.copy(in, bout); bout.close(); | ||
| 155 | + log.info("Message:" + new String(bout.toByteArray())); | ||
| 156 | + return new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 157 | + } | ||
| 158 | + } catch (IOException e) { | ||
| 159 | + // TODO Auto-generated catch block | ||
| 160 | + log.error("调用消息上传接口时发生异常|" + map, e); | ||
| 161 | + } finally { | ||
| 162 | + try { | ||
| 163 | + if (in != null) in.close(); | ||
| 164 | + if (out != null) out.close(); | ||
| 165 | + } catch (IOException e) { | ||
| 166 | + // TODO Auto-generated catch block | ||
| 167 | + log.error("", e); | ||
| 168 | + } | ||
| 169 | + con.disconnect(); | ||
| 170 | + } | ||
| 171 | + return null; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + public Queue<Message> getMessageByDevice(String deviceId) { | ||
| 175 | + return device_msgs.get(deviceId); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + @Override | ||
| 179 | + public void afterPropertiesSet() throws Exception { | ||
| 180 | + // TODO Auto-generated method stub | ||
| 181 | + //ShareExecutors.count.set(5); | ||
| 182 | + sexec.scheduleAtFixedRate(new MessageWorker(), 30, 30, TimeUnit.SECONDS); | ||
| 183 | + exec.submit(new MessageUpWorker()); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + final class MessageWorker implements Runnable { | ||
| 187 | + | ||
| 188 | + @Override | ||
| 189 | + public void run() { | ||
| 190 | + // TODO Auto-generated method stub | ||
| 191 | + | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + final class MessageUpWorker implements Runnable { | ||
| 196 | + | ||
| 197 | + @Override | ||
| 198 | + public void run() { | ||
| 199 | + // TODO Auto-generated method stub | ||
| 200 | + while (true) { | ||
| 201 | + try { | ||
| 202 | + final Message msg = queue.poll(); | ||
| 203 | + if (msg == null) { | ||
| 204 | + try { | ||
| 205 | + Thread.sleep(50); | ||
| 206 | + } catch (InterruptedException e) { | ||
| 207 | + log.error("sleep", e); | ||
| 208 | + } | ||
| 209 | + continue; | ||
| 210 | + } | ||
| 211 | + exec.submit(new Runnable() { | ||
| 212 | + | ||
| 213 | + @Override | ||
| 214 | + public void run() { | ||
| 215 | + // TODO Auto-generated method stub | ||
| 216 | + try { | ||
| 217 | + upHandle(msg); | ||
| 218 | + } catch(Exception e) { | ||
| 219 | + log.error("MessageUpWorker handle exception|" + msg, e); | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + }); | ||
| 223 | + } catch (Exception e) { | ||
| 224 | + log.error("MessageUpPool handle exception", e); | ||
| 225 | + } | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + @Override | ||
| 231 | + public void destroy() throws Exception { | ||
| 232 | + // TODO Auto-generated method stub | ||
| 233 | + exec.shutdown(); | ||
| 234 | + sexec.shutdown(); | ||
| 235 | + } | ||
| 236 | +} |
src/main/java/com/bsth/service/ServerService.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/service/ServerService.java | ||
| 1 | +package com.bsth.service; | ||
| 2 | + | ||
| 3 | +import java.lang.reflect.Field; | ||
| 4 | +import java.net.InetSocketAddress; | ||
| 5 | +import java.nio.channels.SelectionKey; | ||
| 6 | +import java.util.Collection; | ||
| 7 | +import java.util.concurrent.Executors; | ||
| 8 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 9 | +import java.util.concurrent.ThreadFactory; | ||
| 10 | +import java.util.concurrent.TimeUnit; | ||
| 11 | + | ||
| 12 | +import com.bsth.socket.handler.ServerHandler; | ||
| 13 | +import com.bsth.util.AppProperties; | ||
| 14 | +import org.apache.mina.core.session.IdleStatus; | ||
| 15 | +import org.apache.mina.core.session.IoSession; | ||
| 16 | +import org.apache.mina.core.session.IoSessionConfig; | ||
| 17 | +import org.apache.mina.filter.codec.ProtocolCodecFilter; | ||
| 18 | +import org.apache.mina.filter.executor.ExecutorFilter; | ||
| 19 | +import org.apache.mina.filter.logging.LogLevel; | ||
| 20 | +import org.apache.mina.filter.logging.LoggingFilter; | ||
| 21 | +import org.apache.mina.transport.socket.nio.NioSocketAcceptor; | ||
| 22 | +import org.slf4j.Logger; | ||
| 23 | +import org.slf4j.LoggerFactory; | ||
| 24 | +import org.springframework.beans.factory.DisposableBean; | ||
| 25 | +import org.springframework.beans.factory.InitializingBean; | ||
| 26 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 27 | +import org.springframework.stereotype.Service; | ||
| 28 | + | ||
| 29 | +import com.bsth.socket.codec.MessageCodecFactory; | ||
| 30 | +import com.bsth.socket.manager.MessageSessionManager; | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * @author Hill | ||
| 34 | + */ | ||
| 35 | +@Service | ||
| 36 | +public class ServerService implements InitializingBean, DisposableBean { | ||
| 37 | + | ||
| 38 | + private final static Logger log = LoggerFactory.getLogger(ServerService.class); | ||
| 39 | + | ||
| 40 | + @Autowired | ||
| 41 | + private ServerHandler serverHandler; | ||
| 42 | + | ||
| 43 | + private NioSocketAcceptor dataAccepter; | ||
| 44 | + | ||
| 45 | + private ScheduledExecutorService sexec = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public Thread newThread(Runnable r) { | ||
| 49 | + // TODO Auto-generated method stub | ||
| 50 | + Thread t = new Thread(r); | ||
| 51 | + t.setName("DeadSessionCheckExecutor"); | ||
| 52 | + return t; | ||
| 53 | + } | ||
| 54 | + }); | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public void afterPropertiesSet() throws Exception { | ||
| 58 | + // TODO Auto-generated method stub | ||
| 59 | + sexec.scheduleAtFixedRate(new DeadSessionChecker(), 5, 5, TimeUnit.MINUTES); | ||
| 60 | + int port = AppProperties.getPort(); | ||
| 61 | + try { | ||
| 62 | + dataAccepter = new NioSocketAcceptor(); | ||
| 63 | + | ||
| 64 | + LoggingFilter logger = new LoggingFilter(); | ||
| 65 | + logger.setMessageReceivedLogLevel(LogLevel.DEBUG); | ||
| 66 | + logger.setSessionClosedLogLevel(LogLevel.WARN); | ||
| 67 | + dataAccepter.getFilterChain().addLast("logger", logger); | ||
| 68 | + | ||
| 69 | + dataAccepter.getFilterChain().addLast("codec", | ||
| 70 | + new ProtocolCodecFilter(new MessageCodecFactory())); | ||
| 71 | + | ||
| 72 | + dataAccepter.getFilterChain().addLast("threadPool", new ExecutorFilter()); | ||
| 73 | + | ||
| 74 | + IoSessionConfig config = dataAccepter.getSessionConfig(); | ||
| 75 | + | ||
| 76 | + config.setReadBufferSize(4096); | ||
| 77 | + config.setWriteTimeout(10); | ||
| 78 | + config.setIdleTime(IdleStatus.BOTH_IDLE, 50); | ||
| 79 | + | ||
| 80 | + dataAccepter.setHandler(serverHandler); | ||
| 81 | + | ||
| 82 | + dataAccepter.setReuseAddress(true); | ||
| 83 | + // 8899 | ||
| 84 | + dataAccepter.bind(new InetSocketAddress(port)); | ||
| 85 | + log.info("数据服务器启动成功!端口号:" + port); | ||
| 86 | + } catch (Exception e) { | ||
| 87 | + log.error("服务器启动失败:" + e.getMessage(), e); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @Override | ||
| 92 | + public void destroy() throws Exception { | ||
| 93 | + // TODO Auto-generated method stub | ||
| 94 | + if (dataAccepter != null) { | ||
| 95 | + dataAccepter.unbind(); | ||
| 96 | + dataAccepter.getFilterChain().clear(); | ||
| 97 | + dataAccepter.dispose(); | ||
| 98 | + dataAccepter = null; | ||
| 99 | + } | ||
| 100 | + sexec.shutdown(); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + final class DeadSessionChecker implements Runnable { | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public void run() { | ||
| 107 | + // TODO Auto-generated method stub | ||
| 108 | + try { | ||
| 109 | + long now = System.currentTimeMillis(); | ||
| 110 | + MessageSessionManager manager = MessageSessionManager.getInstance(); | ||
| 111 | + log.warn("转发设备号:" + manager.getAllForwardDevice() + " cost:" + (System.currentTimeMillis() - now)); | ||
| 112 | + | ||
| 113 | + Collection<IoSession> sessions = dataAccepter.getManagedSessions().values(); | ||
| 114 | + for (IoSession session : sessions) { | ||
| 115 | + if (!session.isActive() && session.getLastIoTime() < System.currentTimeMillis() - 300000 || session.getWriteRequestQueue().size() > 6000) { | ||
| 116 | + session.getWriteRequestQueue().clear(session); | ||
| 117 | + dataAccepter.getListeners().fireSessionDestroyed(session); | ||
| 118 | + | ||
| 119 | + Class<?> clazzS = session.getClass(); | ||
| 120 | + Field key = clazzS.getDeclaredField("key"); | ||
| 121 | + key.setAccessible(true); | ||
| 122 | + SelectionKey sk = (SelectionKey)key.get(session); | ||
| 123 | + sk.cancel(); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + } catch (Exception e) { | ||
| 127 | + log.error("DeadSessionChecker异常", e); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | +} |
src/main/java/com/bsth/service/UpProtocolDataService.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/service/UpProtocolDataService.java | ||
| 1 | +package com.bsth.service; | ||
| 2 | + | ||
| 3 | +import java.io.BufferedOutputStream; | ||
| 4 | +import java.io.File; | ||
| 5 | +import java.io.FileNotFoundException; | ||
| 6 | +import java.io.FileOutputStream; | ||
| 7 | +import java.io.IOException; | ||
| 8 | +import java.text.SimpleDateFormat; | ||
| 9 | +import java.util.Date; | ||
| 10 | + | ||
| 11 | +import com.bsth.util.AppProperties; | ||
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @author Hill | ||
| 17 | + */ | ||
| 18 | +public class UpProtocolDataService { | ||
| 19 | + | ||
| 20 | + private final static Logger log = LoggerFactory.getLogger(UpProtocolDataService.class); | ||
| 21 | + | ||
| 22 | + private static UpProtocolDataService service = new UpProtocolDataService(); | ||
| 23 | + | ||
| 24 | + private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH"); | ||
| 25 | + | ||
| 26 | + private String dir = AppProperties.getUpdir(); | ||
| 27 | + | ||
| 28 | + private Date cur = new Date(); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 下次切换写文件时间节点 | ||
| 32 | + */ | ||
| 33 | + private long nextTime; | ||
| 34 | + | ||
| 35 | + private BufferedOutputStream out; | ||
| 36 | + | ||
| 37 | + private String fileName; | ||
| 38 | + | ||
| 39 | + private UpProtocolDataService() { | ||
| 40 | + File file = new File(dir); | ||
| 41 | + Date now = new Date(); | ||
| 42 | + if (!file.exists()) { | ||
| 43 | + file.mkdirs(); | ||
| 44 | + } | ||
| 45 | + fileName = sdf.format(now); | ||
| 46 | + nextTime = now.getTime() + 3600000 - now.getTime() % 3600000; | ||
| 47 | + try { | ||
| 48 | + out = new BufferedOutputStream(new FileOutputStream(dir + fileName, true)); | ||
| 49 | + } catch (FileNotFoundException e) { | ||
| 50 | + // TODO Auto-generated catch block | ||
| 51 | + log.error(dir + fileName + "文件未找到"); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static UpProtocolDataService getInstance() { | ||
| 56 | + return service; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void write(byte[] bytes) throws IOException { | ||
| 60 | + long now = System.currentTimeMillis(); | ||
| 61 | + if (now >= nextTime) { | ||
| 62 | + cur.setTime(now); | ||
| 63 | + rollOver(now); | ||
| 64 | + } | ||
| 65 | + out.write(bytes); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + private synchronized void rollOver(long now) throws IOException { | ||
| 69 | + if (now < nextTime) { | ||
| 70 | + return; | ||
| 71 | + } | ||
| 72 | + BufferedOutputStream os = out; | ||
| 73 | + try { | ||
| 74 | + fileName = sdf.format(cur); | ||
| 75 | + File file = new File(dir + fileName); | ||
| 76 | + out = new BufferedOutputStream(new FileOutputStream(file, true)); | ||
| 77 | + nextTime = getNextTime(now); | ||
| 78 | + } catch (FileNotFoundException e) { | ||
| 79 | + // TODO Auto-generated catch block | ||
| 80 | + log.error(dir + fileName + "文件未找到"); | ||
| 81 | + } finally { | ||
| 82 | + os.flush(); | ||
| 83 | + os.close(); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + private long getNextTime(long now) { | ||
| 88 | + return now + 3600000 - now % 3600000; | ||
| 89 | + } | ||
| 90 | +} |
src/main/java/com/bsth/socket/codec/MessageCodecFactory.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/codec/MessageCodecFactory.java | ||
| 1 | +package com.bsth.socket.codec; | ||
| 2 | + | ||
| 3 | +import org.apache.mina.core.session.IoSession; | ||
| 4 | +import org.apache.mina.filter.codec.ProtocolCodecFactory; | ||
| 5 | +import org.apache.mina.filter.codec.ProtocolDecoder; | ||
| 6 | +import org.apache.mina.filter.codec.ProtocolEncoder; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + */ | ||
| 11 | +public class MessageCodecFactory implements ProtocolCodecFactory { | ||
| 12 | + | ||
| 13 | + private ProtocolEncoder encoder; | ||
| 14 | + private ProtocolDecoder decoder; | ||
| 15 | + | ||
| 16 | + public MessageCodecFactory() { | ||
| 17 | + encoder = new MessageEncoder(); | ||
| 18 | + decoder = new MessageDecoder(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public ProtocolEncoder getEncoder(IoSession session) throws Exception { | ||
| 23 | + // TODO Auto-generated method stub | ||
| 24 | + return encoder; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public ProtocolDecoder getDecoder(IoSession session) throws Exception { | ||
| 29 | + // TODO Auto-generated method stub | ||
| 30 | + return decoder; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | +} |
src/main/java/com/bsth/socket/codec/MessageDecoder.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/codec/MessageDecoder.java | ||
| 1 | +package com.bsth.socket.codec; | ||
| 2 | + | ||
| 3 | +import com.bsth.socket.protocol.Message; | ||
| 4 | +import com.bsth.service.UpProtocolDataService; | ||
| 5 | +import com.bsth.util.AppProperties; | ||
| 6 | +import org.apache.mina.core.buffer.IoBuffer; | ||
| 7 | +import org.apache.mina.core.session.IoSession; | ||
| 8 | +import org.apache.mina.filter.codec.CumulativeProtocolDecoder; | ||
| 9 | +import org.apache.mina.filter.codec.ProtocolDecoderOutput; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | + | ||
| 13 | +import java.nio.ByteBuffer; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * @author Hill | ||
| 17 | + */ | ||
| 18 | +public class MessageDecoder extends CumulativeProtocolDecoder { | ||
| 19 | + | ||
| 20 | + private final static Logger log = LoggerFactory.getLogger(MessageDecoder.class); | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + protected boolean doDecode(IoSession session, IoBuffer in, | ||
| 24 | + ProtocolDecoderOutput out) throws Exception { | ||
| 25 | + // TODO Auto-generated method stub | ||
| 26 | + while (in.remaining() > 1) { | ||
| 27 | + in.mark(); | ||
| 28 | + byte start1 = in.get(); | ||
| 29 | + if (start1 == 0x23) { | ||
| 30 | + byte start2 = in.get(); | ||
| 31 | + if (start2 == 0x23) { | ||
| 32 | + if (in.remaining() > 21) { | ||
| 33 | + byte[] bytes1 = new byte[22]; | ||
| 34 | + in.get(bytes1); | ||
| 35 | + byte lenHigh = bytes1[20], lenLow = bytes1[21]; | ||
| 36 | + int len = ((lenHigh & 0xff) << 8) + (lenLow & 0xff); | ||
| 37 | + if (in.remaining() > len) { | ||
| 38 | + ByteBuffer buffer = ByteBuffer.allocate(len + 25); | ||
| 39 | + byte[] bytes2 = new byte[len + 1]; | ||
| 40 | + in.get(bytes2); | ||
| 41 | + buffer.put(start1).put(start2).put(bytes1).put(bytes2); | ||
| 42 | + try { | ||
| 43 | + Message msg = new Message(); | ||
| 44 | + msg.read(buffer.array()); | ||
| 45 | + out.write(msg); | ||
| 46 | + } catch (Exception e) { | ||
| 47 | + StringBuilder sb = new StringBuilder(); | ||
| 48 | + sb.append(" 协议解析异常:").append(buffer.array()); | ||
| 49 | + | ||
| 50 | + log.error(sb.toString(), e); | ||
| 51 | + } finally { | ||
| 52 | + if (AppProperties.isUprecord()) { | ||
| 53 | + UpProtocolDataService.getInstance().write(buffer.array()); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + } else { | ||
| 57 | + in.reset(); | ||
| 58 | + return false; | ||
| 59 | + } | ||
| 60 | + } else { | ||
| 61 | + in.reset(); | ||
| 62 | + return false; | ||
| 63 | + } | ||
| 64 | + } else { | ||
| 65 | + in.reset(); | ||
| 66 | + in.get(); | ||
| 67 | + } | ||
| 68 | + } else { | ||
| 69 | + if (AppProperties.isUprecord()) { | ||
| 70 | + UpProtocolDataService.getInstance().write(new byte[]{ start1 }); | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + return false; | ||
| 75 | + } | ||
| 76 | +} |
src/main/java/com/bsth/socket/codec/MessageEncoder.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/codec/MessageEncoder.java | ||
| 1 | +package com.bsth.socket.codec; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.AppProperties; | ||
| 4 | +import org.apache.mina.core.buffer.IoBuffer; | ||
| 5 | +import org.apache.mina.core.session.IoSession; | ||
| 6 | +import org.apache.mina.filter.codec.ProtocolEncoderAdapter; | ||
| 7 | +import org.apache.mina.filter.codec.ProtocolEncoderOutput; | ||
| 8 | + | ||
| 9 | +import com.bsth.service.DownProtocolDataService; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * @author Hill | ||
| 13 | + */ | ||
| 14 | +public class MessageEncoder extends ProtocolEncoderAdapter { | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public void encode(IoSession session, Object message, | ||
| 18 | + ProtocolEncoderOutput out) throws Exception { | ||
| 19 | + // TODO Auto-generated method stub | ||
| 20 | + IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true); | ||
| 21 | + buf.put((byte[])message); | ||
| 22 | + buf.flip(); | ||
| 23 | + out.write(buf); | ||
| 24 | + if (AppProperties.isDownrecord()) { | ||
| 25 | + DownProtocolDataService.getInstance().write((byte[])message); | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | +} |
src/main/java/com/bsth/socket/handler/ServerHandler.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/handler/ServerHandler.java | ||
| 1 | +package com.bsth.socket.handler; | ||
| 2 | + | ||
| 3 | +import java.io.IOException; | ||
| 4 | +import java.util.Date; | ||
| 5 | + | ||
| 6 | +import com.bsth.socket.protocol.Message01; | ||
| 7 | +import org.apache.mina.core.service.IoHandlerAdapter; | ||
| 8 | +import org.apache.mina.core.session.IdleStatus; | ||
| 9 | +import org.apache.mina.core.session.IoSession; | ||
| 10 | +import org.apache.mina.transport.socket.SocketSessionConfig; | ||
| 11 | +import org.slf4j.Logger; | ||
| 12 | +import org.slf4j.LoggerFactory; | ||
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 14 | +import org.springframework.stereotype.Service; | ||
| 15 | + | ||
| 16 | +import com.bsth.socket.manager.MessageProcessor; | ||
| 17 | +import com.bsth.socket.manager.MessageSessionManager; | ||
| 18 | +import com.bsth.socket.protocol.IMessageBody; | ||
| 19 | +import com.bsth.socket.protocol.Message; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @author Hill | ||
| 23 | + */ | ||
| 24 | +@Service | ||
| 25 | +public class ServerHandler extends IoHandlerAdapter{ | ||
| 26 | + | ||
| 27 | + private final static Logger log = LoggerFactory.getLogger(ServerHandler.class); | ||
| 28 | + @Autowired | ||
| 29 | + private MessageProcessor processor; | ||
| 30 | + | ||
| 31 | + public MessageProcessor getProcessor() { | ||
| 32 | + return this.processor; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public void sessionCreated(IoSession session) throws Exception { | ||
| 37 | + SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig(); | ||
| 38 | + cfg.setTcpNoDelay(true); | ||
| 39 | + cfg.setSoLinger(0); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public void sessionOpened(IoSession session) throws Exception { | ||
| 44 | + | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void sessionClosed(IoSession session) throws Exception { | ||
| 49 | + String deviceId = (String)session.getAttribute("deviceId"); | ||
| 50 | + if (deviceId != null && session == MessageSessionManager.getInstance().getSession(deviceId)) { | ||
| 51 | + MessageSessionManager.getInstance().unregister(deviceId); | ||
| 52 | + log.warn("vin:" + deviceId + "断开连接"); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public void sessionIdle(IoSession session, IdleStatus status) throws Exception { | ||
| 58 | + log.warn("idle 关闭连接, vin " + session.getAttribute("deviceId") + " status " + status + ",lastIo:" + new Date(session.getLastIoTime()) + ",now:" + new Date(System.currentTimeMillis())); | ||
| 59 | + session.closeNow(); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public void exceptionCaught(IoSession session, Throwable cause) throws Exception { | ||
| 64 | + if (cause instanceof IOException) { | ||
| 65 | + log.warn("handler exceptionCaught 关闭连接,vin " + session.getAttribute("deviceId")); | ||
| 66 | + } | ||
| 67 | + log.error("MessageServerHandler捕获异常", cause); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public void messageReceived(IoSession session, Object message) throws Exception { | ||
| 72 | + Message msg = (Message)message; | ||
| 73 | + IMessageBody body = msg.getMessageBody(); | ||
| 74 | + String sDeviceId = (String)session.getAttribute("deviceId"); | ||
| 75 | + if (body != null) { | ||
| 76 | + String vin = msg.getVin(); | ||
| 77 | + log.warn("msg.getVin():" + vin); | ||
| 78 | + if (Message01.COMMAND == msg.getCommand()) { | ||
| 79 | + if (sDeviceId == null) { | ||
| 80 | + MessageSessionManager.getInstance().register(vin, session); | ||
| 81 | + log.warn("vin:" + vin + "建立连接"); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + processor.process(msg); | ||
| 85 | + } else { | ||
| 86 | + log.warn("异常协议命令字:" + msg.getCommand()); | ||
| 87 | + if (sDeviceId == null) { | ||
| 88 | + log.warn("未登入"); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public void messageSent(IoSession session, Object message) throws Exception { | ||
| 95 | + | ||
| 96 | + } | ||
| 97 | +} |
src/main/java/com/bsth/socket/manager/MessageProcessor.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/manager/MessageProcessor.java | ||
| 1 | +package com.bsth.socket.manager; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.bsth.socket.protocol.Message; | ||
| 5 | +import com.bsth.socket.protocol.Message02; | ||
| 6 | +import com.bsth.util.ProtocolConverter; | ||
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | +import org.springframework.beans.factory.InitializingBean; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.kafka.core.KafkaTemplate; | ||
| 13 | +import org.springframework.kafka.support.SendResult; | ||
| 14 | +import org.springframework.stereotype.Service; | ||
| 15 | +import org.springframework.util.concurrent.ListenableFuture; | ||
| 16 | +import org.springframework.util.concurrent.ListenableFutureCallback; | ||
| 17 | + | ||
| 18 | +import java.util.Map; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @author Hill | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +public class MessageProcessor { | ||
| 25 | + | ||
| 26 | + @Autowired | ||
| 27 | + private KafkaTemplate kafkaTemplate; | ||
| 28 | + | ||
| 29 | + private final static Logger log = LoggerFactory.getLogger(MessageProcessor.class); | ||
| 30 | + | ||
| 31 | + private ObjectMapper mapper = new ObjectMapper(); | ||
| 32 | + | ||
| 33 | + private KafkaCallback callback = new KafkaCallback(); | ||
| 34 | + | ||
| 35 | + public void process(Message msg) { | ||
| 36 | + try { | ||
| 37 | + if (msg.getCommand() == 0x02 || msg.getCommand() == 0x03) { | ||
| 38 | + Map<String, Object> data = ProtocolConverter.convert(msg); | ||
| 39 | + String json = mapper.writeValueAsString(data); | ||
| 40 | + ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("LGGJ_ELEC_VEHICLE", json); | ||
| 41 | + future.addCallback(callback); | ||
| 42 | + } | ||
| 43 | + MessageSender.getInstance().ack(msg); | ||
| 44 | + } catch (Exception e) { | ||
| 45 | + log.error("Processor msg:" + msg, e); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + private final static class KafkaCallback implements ListenableFutureCallback<SendResult<String, String>> { | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public void onSuccess(SendResult<String, String> result) { | ||
| 53 | + log.info(result.getProducerRecord().value()); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public void onFailure(Throwable ex) { | ||
| 58 | + log.error("kafka发送电车数据异常", ex); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | +} |
src/main/java/com/bsth/socket/manager/MessageSender.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/manager/MessageSender.java | ||
| 1 | +package com.bsth.socket.manager; | ||
| 2 | + | ||
| 3 | +import java.util.concurrent.ConcurrentLinkedQueue; | ||
| 4 | +import java.util.concurrent.ExecutorService; | ||
| 5 | +import java.util.concurrent.Executors; | ||
| 6 | +import java.util.concurrent.ThreadFactory; | ||
| 7 | + | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | + | ||
| 11 | +import com.bsth.socket.protocol.Message; | ||
| 12 | +import com.bsth.util.AckUtil; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @author Hill | ||
| 16 | + */ | ||
| 17 | +public class MessageSender { | ||
| 18 | + | ||
| 19 | + private final static Logger log = LoggerFactory.getLogger(MessageSender.class); | ||
| 20 | + | ||
| 21 | + private static MessageSender sender = new MessageSender(); | ||
| 22 | + private ConcurrentLinkedQueue<Message> queue = new ConcurrentLinkedQueue<Message>(); | ||
| 23 | + private ExecutorService exec = Executors.newFixedThreadPool(5, new ThreadFactory() { | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public Thread newThread(Runnable r) { | ||
| 27 | + // TODO Auto-generated method stub | ||
| 28 | + Thread t = new Thread(r); | ||
| 29 | + t.setName("MessageSendPool"); | ||
| 30 | + return t; | ||
| 31 | + } | ||
| 32 | + }); | ||
| 33 | + | ||
| 34 | + private MessageSender() { | ||
| 35 | + exec.submit(new MessageSendWorker()); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public static MessageSender getInstance() { | ||
| 39 | + return sender; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void ack(Message msg) { | ||
| 43 | + Message ack = AckUtil.generateAckMessage(msg); | ||
| 44 | + if (ack.getMessageBody() != null) { | ||
| 45 | + queue.add(ack); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void send(Message msg) { | ||
| 50 | + queue.add(msg); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + final class MessageSendWorker implements Runnable { | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public void run() { | ||
| 57 | + // TODO Auto-generated method stub | ||
| 58 | + while (true) { | ||
| 59 | + try { | ||
| 60 | + final Message msg = queue.poll(); | ||
| 61 | + if (msg == null) { | ||
| 62 | + try { | ||
| 63 | + Thread.sleep(50); | ||
| 64 | + } catch (InterruptedException e) { | ||
| 65 | + log.error("sender sleep", e); | ||
| 66 | + } | ||
| 67 | + continue; | ||
| 68 | + } | ||
| 69 | + exec.submit(new Runnable() { | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void run() { | ||
| 73 | + // TODO Auto-generated method stub | ||
| 74 | + try { | ||
| 75 | + if (MessageSessionManager.getInstance().getSession(msg.getVin()) != null) | ||
| 76 | + MessageSessionManager.getInstance().getSession(msg.getVin()).write(msg.write()); | ||
| 77 | + else { | ||
| 78 | + StringBuilder sb = new StringBuilder(); | ||
| 79 | + sb.append(" vin:") | ||
| 80 | + .append(msg.getVin()) | ||
| 81 | + .append(" 无会话信息,不发送消息.消息:") | ||
| 82 | + .append(msg.toString()); | ||
| 83 | + | ||
| 84 | + log.warn(sb.toString()); | ||
| 85 | + } | ||
| 86 | + } catch (Exception e) { | ||
| 87 | + log.error("MessageSendWorker handle exception|" + msg , e); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + }); | ||
| 91 | + } catch (Exception e) { | ||
| 92 | + log.error("MessageSendPool handle exception"); | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | +} |
src/main/java/com/bsth/socket/manager/MessageSessionManager.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/manager/MessageSessionManager.java | ||
| 1 | +package com.bsth.socket.manager; | ||
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.List; | ||
| 5 | +import java.util.Map; | ||
| 6 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 7 | + | ||
| 8 | +import com.bsth.util.AppProperties; | ||
| 9 | +import org.apache.mina.core.session.IoSession; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * @author Hill | ||
| 15 | + */ | ||
| 16 | +public class MessageSessionManager { | ||
| 17 | + | ||
| 18 | + private final static Logger log = LoggerFactory.getLogger(MessageSessionManager.class); | ||
| 19 | + | ||
| 20 | + private static MessageSessionManager sessionManager = new MessageSessionManager(); | ||
| 21 | + private Map<String, IoSession> deviceSession = new ConcurrentHashMap<String, IoSession>(); | ||
| 22 | + private Map<String, IoSession> forwardDevice = new ConcurrentHashMap<String, IoSession>(); | ||
| 23 | + | ||
| 24 | + private MessageSessionManager() { | ||
| 25 | + | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public static MessageSessionManager getInstance() { | ||
| 29 | + return sessionManager; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void register(String deviceId, IoSession session) { | ||
| 33 | + session.setAttribute("deviceId", deviceId); | ||
| 34 | + if (deviceId.startsWith(AppProperties.getForwarddevice())) { | ||
| 35 | + forwardDevice.put(deviceId, session); | ||
| 36 | + return; | ||
| 37 | + } | ||
| 38 | + deviceSession.put(deviceId, session); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void unregister(String deviceId) { | ||
| 42 | + IoSession session = null; | ||
| 43 | + if (deviceId.startsWith(AppProperties.getForwarddevice())) { | ||
| 44 | + session = forwardDevice.remove(deviceId); | ||
| 45 | + if (session != null) session.removeAttribute("deviceId"); | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + session = deviceSession.remove(deviceId); | ||
| 49 | + if (session != null) session.removeAttribute("deviceId"); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public IoSession getSession(String deviceId) { | ||
| 53 | + if (deviceId.startsWith(AppProperties.getForwarddevice())) { | ||
| 54 | + return forwardDevice.get(deviceId); | ||
| 55 | + } | ||
| 56 | + return deviceSession.get(deviceId); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public List<String> getAllDevice() { | ||
| 60 | + return new ArrayList<>(deviceSession.keySet()); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public List<IoSession> getAllSession() { | ||
| 64 | + return new ArrayList<>(deviceSession.values()); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public IoSession getForwardSession(String deviceId) { | ||
| 68 | + return forwardDevice.get(deviceId); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public List<String> getAllForwardDevice() { | ||
| 72 | + return new ArrayList<>(forwardDevice.keySet()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public List<IoSession> getAllForwardSession() { | ||
| 76 | + return new ArrayList<>(forwardDevice.values()); | ||
| 77 | + } | ||
| 78 | +} |
src/main/java/com/bsth/socket/protocol/IMessage82Param.java
0 → 100644
src/main/java/com/bsth/socket/protocol/IMessageBody.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/IMessageBody.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + */ | ||
| 6 | +public interface IMessageBody { | ||
| 7 | + | ||
| 8 | + public void read(byte[] bytes); | ||
| 9 | + | ||
| 10 | + public byte[] write(); | ||
| 11 | + | ||
| 12 | + public void setTimestamp(long timestamp); | ||
| 13 | +} |
src/main/java/com/bsth/socket/protocol/IMessageBody02.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/IMessageBody02.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + */ | ||
| 6 | +public interface IMessageBody02 { | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * 根据字节数组组装实时信息体数据 | ||
| 10 | + * @param bytes 字节数组 | ||
| 11 | + */ | ||
| 12 | + public void read(byte[] bytes, int idx); | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 获取实时信息体内容字节长度 | ||
| 16 | + * @return 实时信息体内容字节长度 | ||
| 17 | + */ | ||
| 18 | + public int getByteLen(); | ||
| 19 | +} |
src/main/java/com/bsth/socket/protocol/Message.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import com.bsth.util.CrcUtil; | ||
| 5 | + | ||
| 6 | +import java.nio.ByteBuffer; | ||
| 7 | +import java.util.Arrays; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author Hill | ||
| 11 | + */ | ||
| 12 | +public class Message { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 协议起始符 | ||
| 16 | + */ | ||
| 17 | + private String start = "##"; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 命令标识 | ||
| 21 | + */ | ||
| 22 | + private byte command; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 应答标志 | ||
| 26 | + * 0x01 成功 | ||
| 27 | + * 0x02 设置识别 | ||
| 28 | + * 0x03 vin重复 | ||
| 29 | + * 0xFE 命令 | ||
| 30 | + */ | ||
| 31 | + private byte ackFlag; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 车辆识别码(常规vin,可自定义唯一码) | ||
| 35 | + */ | ||
| 36 | + private String vin = "\0"; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 加密方式 | ||
| 40 | + */ | ||
| 41 | + private byte encryption; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 数据长度 | ||
| 45 | + */ | ||
| 46 | + private short dataLength; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 数据体 | ||
| 50 | + */ | ||
| 51 | + private IMessageBody messageBody; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 校验码(BBC) | ||
| 55 | + */ | ||
| 56 | + private byte crc; | ||
| 57 | + | ||
| 58 | + public void read(byte[] data) { | ||
| 59 | + int idx = 2, len = data.length; | ||
| 60 | + command = data[idx]; idx++; | ||
| 61 | + ackFlag = data[idx]; idx++; | ||
| 62 | + vin = ConvertUtil.ascii2string(data, idx, 17); idx += 17; | ||
| 63 | + encryption = data[idx]; idx += 3; | ||
| 64 | + byte[] temp = Arrays.copyOfRange(data, idx, len - 1); | ||
| 65 | + crc = data[len - 1]; | ||
| 66 | + byte sum = CrcUtil.bbc(data, 2, len - 2); | ||
| 67 | + if (sum == crc) { | ||
| 68 | + System.out.println(ConvertUtil.toHexString(data)); | ||
| 69 | + messageBody = MessageFactory.create(command, temp); | ||
| 70 | + } else { | ||
| 71 | + throw new ProtocolException("校验未通过" + ConvertUtil.toHexString(data)); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public byte[] write() { | ||
| 76 | + byte[] bytes = messageBody.write(); | ||
| 77 | + ByteBuffer buf = ByteBuffer.allocate(bytes.length + 25); | ||
| 78 | + buf.put(start.getBytes()); | ||
| 79 | + buf.put(command); | ||
| 80 | + buf.put(ackFlag); | ||
| 81 | + buf.put(vin.getBytes()); | ||
| 82 | + buf.put(encryption); | ||
| 83 | + buf.putShort((short)bytes.length); | ||
| 84 | + buf.put(bytes); | ||
| 85 | + byte[] data = buf.array(); | ||
| 86 | + crc = CrcUtil.bbc(data, 2, data.length - 2); | ||
| 87 | + buf.put(crc); | ||
| 88 | + | ||
| 89 | + return buf.array(); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public String getStart() { | ||
| 93 | + return start; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setStart(String start) { | ||
| 97 | + this.start = start; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public byte getCommand() { | ||
| 101 | + return command; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setCommand(byte command) { | ||
| 105 | + this.command = command; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public byte getAckFlag() { | ||
| 109 | + return ackFlag; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public void setAckFlag(byte ackFlag) { | ||
| 113 | + this.ackFlag = ackFlag; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public String getVin() { | ||
| 117 | + return vin; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public void setVin(String vin) { | ||
| 121 | + this.vin = vin; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public byte getEncryption() { | ||
| 125 | + return encryption; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setEncryption(byte encryption) { | ||
| 129 | + this.encryption = encryption; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public short getDataLength() { | ||
| 133 | + return dataLength; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public void setDataLength(short dataLength) { | ||
| 137 | + this.dataLength = dataLength; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public IMessageBody getMessageBody() { | ||
| 141 | + return messageBody; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public void setMessageBody(IMessageBody messageBody) { | ||
| 145 | + this.messageBody = messageBody; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public byte getCrc() { | ||
| 149 | + return crc; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public void setCrc(byte crc) { | ||
| 153 | + this.crc = crc; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + @Override | ||
| 157 | + public String toString() { | ||
| 158 | + StringBuilder sb = new StringBuilder(); | ||
| 159 | + sb.append(" 起始符号:").append(start) | ||
| 160 | + .append(" 命令标识:").append(command) | ||
| 161 | + .append(" 应答标志:").append(ackFlag) | ||
| 162 | + .append(" vin:").append(vin) | ||
| 163 | + .append(" 加密方式:").append(encryption) | ||
| 164 | + .append(" 报文主体:(").append(messageBody).append(" )") | ||
| 165 | + .append(" 报文校验和:").append(crc); | ||
| 166 | + | ||
| 167 | + return sb.toString(); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public static void main(String args[]) { | ||
| 171 | + // (byte)0x11,(byte)0x64,(byte)0x47,(byte)0x00,(byte)0x33,(byte)0x31,(byte)0x44,(byte)0x51,(byte)0x33,(byte)0x38,(byte)0x33,(byte)0x31,(byte)0x17,(byte)0x07,(byte)0x26,(byte)0x16,(byte)0x54,(byte)0x24,(byte)0x00,(byte)0x00,(byte)0x45,(byte)0x4e,(byte)0x07,(byte)0x1a,(byte)0x10,(byte)0x37,(byte)0x51 | ||
| 172 | + // (byte)0x11,(byte)0x5e,(byte)0x46,(byte)0x00,(byte)0x33,(byte)0x31,(byte)0x44,(byte)0x51,(byte)0x33,(byte)0x38,(byte)0x33,(byte)0x31,(byte)0x17,(byte)0x07,(byte)0x26,(byte)0x16,(byte)0x53,(byte)0x33,(byte)0x60,(byte)0x00,(byte)0x00,(byte)0x45,(byte)0x4e,(byte)0x07,(byte)0x1a,(byte)0x10,(byte)0x37,(byte)0xb8 | ||
| 173 | + byte[] bytes = new byte[]{(byte)0x23,(byte)0x23,(byte)0x02,(byte)0xFE,(byte)0x4C,(byte)0x53,(byte)0x46,(byte)0x44,(byte)0x31,(byte)0x33,(byte)0x32,(byte)0x30,(byte)0x30,(byte)0x50,(byte)0x43,(byte)0x30,(byte)0x30,(byte)0x30,(byte)0x32,(byte)0x35,(byte)0x35,(byte)0x01,(byte)0x00,(byte)0x7F,(byte)0x17,(byte)0x07,(byte)0x04,(byte)0x09,(byte)0x39,(byte)0x26,(byte)0x01,(byte)0x01,(byte)0x03,(byte)0x01,(byte)0x01,(byte)0x7B,(byte)0x00,(byte)0x00,(byte)0x27,(byte)0xEC,(byte)0x17,(byte)0x39,(byte)0x2A,(byte)0x04,(byte)0x54,(byte)0xFF,(byte)0x0E,(byte)0x19,(byte)0x64,(byte)0x14,(byte)0x00,(byte)0x02,(byte)0x01,(byte)0x01,(byte)0x01,(byte)0x56,(byte)0x53,(byte)0x43,(byte)0x57,(byte)0x26,(byte)0x65,(byte)0x17,(byte)0x28,(byte)0x29,(byte)0x54,(byte)0x05,(byte)0x01,(byte)0x07,(byte)0x44,(byte)0x28,(byte)0x25,(byte)0x01,(byte)0xD7,(byte)0x30,(byte)0x37,(byte)0x06,(byte)0x01,(byte)0x02,(byte)0x0C,(byte)0xED,(byte)0x01,(byte)0x45,(byte)0x0C,(byte)0xE6,(byte)0x01,(byte)0x01,(byte)0x4C,(byte)0x01,(byte)0x37,(byte)0x4A,(byte)0x07,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x80,(byte)0x00,(byte)0x30,(byte)0xDC,(byte)0xDC,(byte)0x36,(byte)0x04,(byte)0xFA,(byte)0x04,(byte)0xEC,(byte)0x57,(byte)0x57,(byte)0xF6,(byte)0x53,(byte)0xF4,(byte)0x54,(byte)0xF4,(byte)0x54,(byte)0xF6,(byte)0x55,(byte)0xF7,(byte)0x56,(byte)0xF8,(byte)0x56,(byte)0x17,(byte)0x3A,(byte)0x2A,(byte)0x04,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x30,(byte)0x69,(byte)0x00,(byte)0x00,(byte)0x27,(byte)0x2A,(byte)0x01,(byte)0xA0,(byte)0x19,(byte)0x64,(byte)0x19,(byte)0x64,(byte)0x57,(byte)0xFF,(byte)0x00,(byte)0xFF,(byte)0x80,(byte)0x4B,(byte)0x02,(byte)0xC7}; | ||
| 174 | + Message msg= new Message(); | ||
| 175 | + msg.read(bytes); | ||
| 176 | + System.out.println(msg); | ||
| 177 | + //System.out.println(bytes[bytes.length - 1]); | ||
| 178 | + //System.out.println(CrcUtil.bbc(bytes, 2, bytes.length - 2)); | ||
| 179 | + | ||
| 180 | + //byte[] bytes1 = new byte[]{(byte)0x17,(byte)0x03,(byte)0x10,(byte)0x09,(byte)0x0a,(byte)0x12}; | ||
| 181 | + //System.out.println(new DateTime(ConvertUtil.bytes2timestamp(bytes1, 0)).toString("yyyy-MM-dd HH:mm:ss")); | ||
| 182 | + } | ||
| 183 | +} |
src/main/java/com/bsth/socket/protocol/Message01.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message01.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.joda.time.DateTime; | ||
| 5 | + | ||
| 6 | +import java.util.Arrays; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + * 车辆登入 | ||
| 11 | + */ | ||
| 12 | +public class Message01 implements IMessageBody { | ||
| 13 | + | ||
| 14 | + public static final byte COMMAND = 0x01; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * byte[6] | ||
| 18 | + * 数据采集时间 | ||
| 19 | + */ | ||
| 20 | + private long timestamp; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 登入流水号 | ||
| 24 | + */ | ||
| 25 | + private short loginSerialNo; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * string(20) | ||
| 29 | + * sim卡iccid | ||
| 30 | + */ | ||
| 31 | + private String iccid; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 可充电储能子系统数n | ||
| 35 | + */ | ||
| 36 | + private byte subSystemQuantity; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 可充电储能子系统编码长度m | ||
| 40 | + */ | ||
| 41 | + private byte subSystemCodeLen; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 可充电储能系统编码n*m | ||
| 45 | + */ | ||
| 46 | + private byte[] subBytes; | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public void read(byte[] bytes) { | ||
| 50 | + // TODO Auto-generated method stub | ||
| 51 | + int idx = 0; | ||
| 52 | + timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6; | ||
| 53 | + loginSerialNo = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 54 | + iccid = ConvertUtil.ascii2string(bytes, idx, 20); idx += 20; | ||
| 55 | + subSystemQuantity = bytes[idx]; idx++; | ||
| 56 | + subSystemCodeLen = bytes[idx]; idx++; | ||
| 57 | + subBytes = Arrays.copyOfRange(bytes, idx, idx + subSystemQuantity * subSystemCodeLen); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public byte[] write() { | ||
| 62 | + // TODO Auto-generated method stub | ||
| 63 | + return ConvertUtil.timestamp2bytes(timestamp); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public long getTimestamp() { | ||
| 67 | + return timestamp; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public void setTimestamp(long timestamp) { | ||
| 72 | + this.timestamp = timestamp; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public short getLoginSerialNo() { | ||
| 76 | + return loginSerialNo; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setLoginSerialNo(short loginSerialNo) { | ||
| 80 | + this.loginSerialNo = loginSerialNo; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public String getIccid() { | ||
| 84 | + return iccid; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setIccid(String iccid) { | ||
| 88 | + this.iccid = iccid; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public byte getSubSystemQuantity() { | ||
| 92 | + return subSystemQuantity; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setSubSystemQuantity(byte subSystemQuantity) { | ||
| 96 | + this.subSystemQuantity = subSystemQuantity; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public byte getSubSystemCodeLen() { | ||
| 100 | + return subSystemCodeLen; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setSubSystemCodeLen(byte subSystemCodeLen) { | ||
| 104 | + this.subSystemCodeLen = subSystemCodeLen; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public byte[] getSubBytes() { | ||
| 108 | + return subBytes; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setSubBytes(byte[] subBytes) { | ||
| 112 | + this.subBytes = subBytes; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + @Override | ||
| 116 | + public String toString() { | ||
| 117 | + StringBuilder sb = new StringBuilder(); | ||
| 118 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 119 | + .append(" 登入流水号:").append(loginSerialNo) | ||
| 120 | + .append(" iccid:").append(iccid) | ||
| 121 | + .append(" 可充电储能子系统数:").append(subSystemQuantity) | ||
| 122 | + .append(" 可充电储能子系统编码长度:").append(subSystemCodeLen); | ||
| 123 | + | ||
| 124 | + return sb.toString(); | ||
| 125 | + } | ||
| 126 | +} |
src/main/java/com/bsth/socket/protocol/Message02.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message02.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.joda.time.DateTime; | ||
| 5 | + | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author Hill | ||
| 11 | + * 实时信息上报 | ||
| 12 | + */ | ||
| 13 | +public class Message02 implements IMessageBody { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * byte[6] | ||
| 17 | + * 数据采集时间 | ||
| 18 | + */ | ||
| 19 | + private long timestamp; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 数据体 | ||
| 23 | + */ | ||
| 24 | + private List<IMessageBody02> body02List = new ArrayList<>(); | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 缓存标志 | ||
| 28 | + */ | ||
| 29 | + private boolean cache; | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public void read(byte[] bytes) { | ||
| 33 | + // TODO Auto-generated method stub | ||
| 34 | + int idx = 0; | ||
| 35 | + timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6; | ||
| 36 | + while (idx < bytes.length - 1) { | ||
| 37 | + IMessageBody02 body02 = Message02Factory.create(bytes[idx] & 0xff, bytes, idx); | ||
| 38 | + body02List.add(body02); | ||
| 39 | + idx += body02.getByteLen(); | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public byte[] write() { | ||
| 45 | + // TODO Auto-generated method stub | ||
| 46 | + return ConvertUtil.timestamp2bytes(timestamp); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public long getTimestamp() { | ||
| 50 | + return timestamp; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public void setTimestamp(long timestamp) { | ||
| 55 | + this.timestamp = timestamp; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public List<IMessageBody02> getBody02List() { | ||
| 59 | + return body02List; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setBody02List(List<IMessageBody02> body02List) { | ||
| 63 | + this.body02List = body02List; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public boolean isCache() { | ||
| 67 | + return cache; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public void setCache(boolean cache) { | ||
| 71 | + this.cache = cache; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public String toString() { | ||
| 76 | + StringBuilder sb = new StringBuilder(); | ||
| 77 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")); | ||
| 78 | + for (IMessageBody02 body02 : body02List) { | ||
| 79 | + sb.append(body02.toString()).append(" \n"); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + return sb.toString(); | ||
| 83 | + } | ||
| 84 | +} |
src/main/java/com/bsth/socket/protocol/Message0201.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0201.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 整车数据 | ||
| 8 | + */ | ||
| 9 | +public class Message0201 implements IMessageBody02 { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * 信息类型 | ||
| 13 | + * 默认应该为0x01 | ||
| 14 | + */ | ||
| 15 | + private byte infoType; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 车辆状态 | ||
| 19 | + * 0x01 车辆启动 | ||
| 20 | + * 0x02 车辆熄火 | ||
| 21 | + * 0x03 其它 | ||
| 22 | + * 0xFE 异常 | ||
| 23 | + * 0xFF 无效 | ||
| 24 | + */ | ||
| 25 | + private byte vehicleState; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 充电状态 | ||
| 29 | + * 0x01 停车充电 | ||
| 30 | + * 0x02 行驶充电 | ||
| 31 | + * 0x03 未充电 | ||
| 32 | + * 0x04 充电完成 | ||
| 33 | + * 0xFE 异常 | ||
| 34 | + * 0xFF 无效 | ||
| 35 | + */ | ||
| 36 | + private byte chargeState; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 运行模式 | ||
| 40 | + * 0x01 纯电 | ||
| 41 | + * 0x02 混动 | ||
| 42 | + * 0x03 燃油 | ||
| 43 | + * 0xFE 异常 | ||
| 44 | + * 0xFF 无效 | ||
| 45 | + */ | ||
| 46 | + private byte runMode; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 车速 0-2200 | ||
| 50 | + * 分辨率0.1km/h | ||
| 51 | + * 0xff 0xfe 异常 | ||
| 52 | + * 0xff 0xff 无效 | ||
| 53 | + */ | ||
| 54 | + private short speed; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 累计里程 0-9999999 | ||
| 58 | + * 分辨率0.1km/h | ||
| 59 | + * 0xff 0xff 0xff 0xfe 异常 | ||
| 60 | + * 0xff 0xff 0xff 0xff 无效 | ||
| 61 | + */ | ||
| 62 | + private int totalMiles; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * 总电压 0-10000 | ||
| 66 | + * 分辨率0.1v | ||
| 67 | + * 0xff 0xfe 异常 | ||
| 68 | + * 0xff 0xff 无效 | ||
| 69 | + */ | ||
| 70 | + private short totalVoltage; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 总电流 0-20000 | ||
| 74 | + * 分辨率0.1a | ||
| 75 | + * 0xff 0xfe 异常 | ||
| 76 | + * 0xff 0xff 无效 | ||
| 77 | + */ | ||
| 78 | + private short totalCurrent; | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * soc 0-100% | ||
| 82 | + * 分辨率1% | ||
| 83 | + * 0xFE 异常 | ||
| 84 | + * 0xFF 无效 | ||
| 85 | + */ | ||
| 86 | + private byte soc; | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * dc-dc状态 | ||
| 90 | + * 0x01 工作 | ||
| 91 | + * 0x02 断开 | ||
| 92 | + * 0xFE 异常 | ||
| 93 | + * 0xFF 无效 | ||
| 94 | + */ | ||
| 95 | + private byte dcState; | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 挡位 | ||
| 99 | + */ | ||
| 100 | + private byte gear; | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 绝缘电阻 0-60000 | ||
| 104 | + * 分辨率 1k欧 | ||
| 105 | + */ | ||
| 106 | + private short insulationResistance; | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 加速踏板行程值 0-100% | ||
| 110 | + * 分辨率1% | ||
| 111 | + * 0xFE 异常 | ||
| 112 | + * 0xFF 无效 | ||
| 113 | + */ | ||
| 114 | + private byte acceleratorState; | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * 制动踏板状态 0-100% | ||
| 118 | + * 分辨率1% 在无具体行程值情况下,用“101”表示制动有效状态 | ||
| 119 | + * 0xFE 异常 | ||
| 120 | + * 0xFF 无效 | ||
| 121 | + */ | ||
| 122 | + private byte brakePedalState; | ||
| 123 | + | ||
| 124 | + @Override | ||
| 125 | + public void read(byte[] bytes, int idx) { | ||
| 126 | + // TODO Auto-generated method stub | ||
| 127 | + infoType = bytes[idx]; idx++; | ||
| 128 | + vehicleState = bytes[idx]; idx++; | ||
| 129 | + chargeState = bytes[idx]; idx++; | ||
| 130 | + runMode = bytes[idx]; idx++; | ||
| 131 | + speed = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 132 | + totalMiles = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 133 | + totalVoltage = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 134 | + totalCurrent = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 135 | + soc = bytes[idx]; idx++; | ||
| 136 | + dcState = bytes[idx]; idx++; | ||
| 137 | + gear = bytes[idx]; idx++; | ||
| 138 | + insulationResistance = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 139 | + acceleratorState = bytes[idx]; idx++; | ||
| 140 | + brakePedalState = bytes[idx]; idx++; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Override | ||
| 144 | + public int getByteLen() { | ||
| 145 | + return 21; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public byte getInfoType() { | ||
| 149 | + return infoType; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public void setInfoType(byte infoType) { | ||
| 153 | + this.infoType = infoType; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public byte getVehicleState() { | ||
| 157 | + return vehicleState; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public void setVehicleState(byte vehicleState) { | ||
| 161 | + this.vehicleState = vehicleState; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public byte getChargeState() { | ||
| 165 | + return chargeState; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public void setChargeState(byte chargeState) { | ||
| 169 | + this.chargeState = chargeState; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public byte getRunMode() { | ||
| 173 | + return runMode; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public void setRunMode(byte runMode) { | ||
| 177 | + this.runMode = runMode; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public short getSpeed() { | ||
| 181 | + return speed; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public void setSpeed(short speed) { | ||
| 185 | + this.speed = speed; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public int getTotalMiles() { | ||
| 189 | + return totalMiles; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public void setTotalMiles(int totalMiles) { | ||
| 193 | + this.totalMiles = totalMiles; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public short getTotalVoltage() { | ||
| 197 | + return totalVoltage; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + public void setTotalVoltage(short totalVoltage) { | ||
| 201 | + this.totalVoltage = totalVoltage; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + public short getTotalCurrent() { | ||
| 205 | + return totalCurrent; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + public void setTotalCurrent(short totalCurrent) { | ||
| 209 | + this.totalCurrent = totalCurrent; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + public byte getSoc() { | ||
| 213 | + return soc; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + public void setSoc(byte soc) { | ||
| 217 | + this.soc = soc; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + public byte getDcState() { | ||
| 221 | + return dcState; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + public void setDcState(byte dcState) { | ||
| 225 | + this.dcState = dcState; | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + public byte getGear() { | ||
| 229 | + return gear; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public void setGear(byte gear) { | ||
| 233 | + this.gear = gear; | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + public short getInsulationResistance() { | ||
| 237 | + return insulationResistance; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + public void setInsulationResistance(short insulationResistance) { | ||
| 241 | + this.insulationResistance = insulationResistance; | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + public byte getAcceleratorState() { | ||
| 245 | + return acceleratorState; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + public void setAcceleratorState(byte acceleratorState) { | ||
| 249 | + this.acceleratorState = acceleratorState; | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + public byte getBrakePedalState() { | ||
| 253 | + return brakePedalState; | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + public void setBrakePedalState(byte brakePedalState) { | ||
| 257 | + this.brakePedalState = brakePedalState; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + @Override | ||
| 261 | + public String toString() { | ||
| 262 | + StringBuilder sb = new StringBuilder(); | ||
| 263 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 264 | + .append(" 车辆状态: ").append(vehicleState) | ||
| 265 | + .append(" 充电状态: ").append(chargeState) | ||
| 266 | + .append(" 运行模式: ").append(runMode) | ||
| 267 | + .append(" 车速: ").append(speed) | ||
| 268 | + .append(" 累计里程: ").append(totalMiles) | ||
| 269 | + .append(" 总电压: ").append(totalVoltage) | ||
| 270 | + .append(" 总电流: ").append(totalCurrent) | ||
| 271 | + .append(" soc: ").append(soc) | ||
| 272 | + .append(" dc-dc状态: ").append(dcState) | ||
| 273 | + .append(" 挡位: ").append(gear) | ||
| 274 | + .append(" 绝缘电阻: ").append(insulationResistance) | ||
| 275 | + .append(" 加速踏板行程值: ").append(acceleratorState) | ||
| 276 | + .append(" 制动踏板状态: ").append(brakePedalState); | ||
| 277 | + | ||
| 278 | + return sb.toString(); | ||
| 279 | + } | ||
| 280 | +} |
src/main/java/com/bsth/socket/protocol/Message0202.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0202.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.util.ConvertUtil; | ||
| 5 | + | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author Hill | ||
| 11 | + * 驱动电机数据 | ||
| 12 | + */ | ||
| 13 | +public class Message0202 implements IMessageBody02 { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 信息类型 | ||
| 17 | + * 默认应该为0x02 | ||
| 18 | + */ | ||
| 19 | + private byte infoType; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 驱动电机数量 1-253 | ||
| 23 | + */ | ||
| 24 | + private byte electricMotorQuantity; | ||
| 25 | + | ||
| 26 | + private List<ElectricMotor> electricMotorList = new ArrayList<>(); | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public void read(byte[] bytes, int idx) { | ||
| 30 | + // TODO Auto-generated method stub | ||
| 31 | + infoType = bytes[idx]; idx++; | ||
| 32 | + electricMotorQuantity = bytes[idx]; idx++; | ||
| 33 | + int quantity = electricMotorQuantity & Constant.BYTE_INT; | ||
| 34 | + if (idx + quantity * ElectricMotor.BYTE_LEN < bytes.length - 1) { | ||
| 35 | + for (int i = 0;i < quantity;i ++) { | ||
| 36 | + ElectricMotor electricMotor = new ElectricMotor(); | ||
| 37 | + electricMotor.read(bytes, idx); idx += ElectricMotor.BYTE_LEN; | ||
| 38 | + electricMotorList.add(electricMotor); | ||
| 39 | + } | ||
| 40 | + } else { | ||
| 41 | + throw new IllegalArgumentException("异常的驱动电机数据"); | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public byte getInfoType() { | ||
| 46 | + return infoType; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setInfoType(byte infoType) { | ||
| 50 | + this.infoType = infoType; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public byte getElectricMotorQuantity() { | ||
| 54 | + return electricMotorQuantity; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setElectricMotorQuantity(byte electricMotorQuantity) { | ||
| 58 | + this.electricMotorQuantity = electricMotorQuantity; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public List<ElectricMotor> getElectricMotorList() { | ||
| 62 | + return electricMotorList; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setElectricMotorList(List<ElectricMotor> electricMotorList) { | ||
| 66 | + this.electricMotorList = electricMotorList; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public int getByteLen() { | ||
| 71 | + return electricMotorList.size() * ElectricMotor.BYTE_LEN + 2; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public String toString() { | ||
| 76 | + StringBuilder sb = new StringBuilder(); | ||
| 77 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 78 | + .append(" 驱动电机数量: ").append(electricMotorQuantity); | ||
| 79 | + | ||
| 80 | + for (ElectricMotor electricMotor : electricMotorList) { | ||
| 81 | + sb.append(electricMotor.toString()); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + return sb.toString(); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public static class ElectricMotor { | ||
| 88 | + | ||
| 89 | + private final static int BYTE_LEN = 12; | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * 驱动电机序号 1-253 | ||
| 93 | + */ | ||
| 94 | + private byte serialNo; | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * 驱动电机状态 1-253 | ||
| 98 | + * 0x01 耗电 | ||
| 99 | + * 0x02 发电 | ||
| 100 | + * 0x03 关闭 | ||
| 101 | + * 0x04 准备 | ||
| 102 | + * 0xFE 异常 | ||
| 103 | + * 0xFF 无效 | ||
| 104 | + */ | ||
| 105 | + private byte state; | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 驱动电机控制器温度 0-250 | ||
| 109 | + * 分辨率1℃ 偏移量-40 | ||
| 110 | + * 0xFE 异常 | ||
| 111 | + * 0xFF 无效 | ||
| 112 | + */ | ||
| 113 | + private byte controllerTemperature; | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 电机转速 0-65531 | ||
| 117 | + * 分辨率1r/min 偏移量-20000 | ||
| 118 | + * 0xFF 0xFE 异常 | ||
| 119 | + * 0xFF 0xFF 无效 | ||
| 120 | + */ | ||
| 121 | + private short speed; | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * 电机扭矩 0-65531 | ||
| 125 | + * 分辨率0.1N.m 偏移量-20000 | ||
| 126 | + * 0xFF 0xFE 异常 | ||
| 127 | + * 0xFF 0xFF 无效 | ||
| 128 | + */ | ||
| 129 | + private short torsion; | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 驱动电机温度 0-250 | ||
| 133 | + * 分辨率1℃ 偏移量-40 | ||
| 134 | + * 0xFE 异常 | ||
| 135 | + * 0xFF 无效 | ||
| 136 | + */ | ||
| 137 | + private byte temperature; | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * 电机控制器电压 0-60000 | ||
| 141 | + * 分辨率0.1v | ||
| 142 | + * 0xFF 0xFE 异常 | ||
| 143 | + * 0xFF 0xFF 无效 | ||
| 144 | + */ | ||
| 145 | + private short controllerVoltage; | ||
| 146 | + | ||
| 147 | + /** | ||
| 148 | + * 电机控制器电流 0-20000 | ||
| 149 | + * 分辨率0.1a | ||
| 150 | + * 0xFF 0xFE 异常 | ||
| 151 | + * 0xFF 0xFF 无效 | ||
| 152 | + */ | ||
| 153 | + private short controllerCurrent; | ||
| 154 | + | ||
| 155 | + public void read(byte[] bytes, int idx) { | ||
| 156 | + serialNo = bytes[idx]; idx ++; | ||
| 157 | + state = bytes[idx]; idx ++; | ||
| 158 | + controllerTemperature = bytes[idx]; idx ++; | ||
| 159 | + speed = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 160 | + torsion = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 161 | + temperature = bytes[idx]; idx ++; | ||
| 162 | + controllerVoltage = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 163 | + controllerCurrent = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public byte getSerialNo() { | ||
| 167 | + return serialNo; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public void setSerialNo(byte serialNo) { | ||
| 171 | + this.serialNo = serialNo; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + public byte getState() { | ||
| 175 | + return state; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + public void setState(byte state) { | ||
| 179 | + this.state = state; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + public byte getControllerTemperature() { | ||
| 183 | + return controllerTemperature; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public void setControllerTemperature(byte controllerTemperature) { | ||
| 187 | + this.controllerTemperature = controllerTemperature; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public short getSpeed() { | ||
| 191 | + return speed; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + public void setSpeed(short speed) { | ||
| 195 | + this.speed = speed; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + public short getTorsion() { | ||
| 199 | + return torsion; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + public void setTorsion(short torsion) { | ||
| 203 | + this.torsion = torsion; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + public byte getTemperature() { | ||
| 207 | + return temperature; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + public void setTemperature(byte temperature) { | ||
| 211 | + this.temperature = temperature; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + public short getControllerVoltage() { | ||
| 215 | + return controllerVoltage; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + public void setControllerVoltage(short controllerVoltage) { | ||
| 219 | + this.controllerVoltage = controllerVoltage; | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + public short getControllerCurrent() { | ||
| 223 | + return controllerCurrent; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + public void setControllerCurrent(short controllerCurrent) { | ||
| 227 | + this.controllerCurrent = controllerCurrent; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + @Override | ||
| 231 | + public String toString() { | ||
| 232 | + StringBuilder sb = new StringBuilder(); | ||
| 233 | + sb.append(" 驱动电机序号: ").append(serialNo) | ||
| 234 | + .append(" 驱动电机状态: ").append(state) | ||
| 235 | + .append(" 驱动控制器温度: ").append(controllerTemperature) | ||
| 236 | + .append(" 驱动电机转速: ").append(speed) | ||
| 237 | + .append(" 电机扭矩: ").append(torsion) | ||
| 238 | + .append(" 驱动电机温度: ").append(temperature) | ||
| 239 | + .append(" 控制器电压: ").append(controllerVoltage) | ||
| 240 | + .append(" 控制器电流: ").append(controllerCurrent) | ||
| 241 | + .append(" \n"); | ||
| 242 | + | ||
| 243 | + return sb.toString(); | ||
| 244 | + } | ||
| 245 | + } | ||
| 246 | +} |
src/main/java/com/bsth/socket/protocol/Message0203.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0203.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.util.ConvertUtil; | ||
| 5 | + | ||
| 6 | +import java.util.Arrays; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + * 燃料电池数据 | ||
| 11 | + */ | ||
| 12 | +public class Message0203 implements IMessageBody02 { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 信息类型 | ||
| 16 | + * 默认应该为0x03 | ||
| 17 | + */ | ||
| 18 | + private byte infoType; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 电池电压 0-20000 | ||
| 22 | + * 分辨率0.1v | ||
| 23 | + * 0xff 0xfe 异常 | ||
| 24 | + * 0xff 0xff 无效 | ||
| 25 | + */ | ||
| 26 | + private short voltage; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 电池电流 0-20000 | ||
| 30 | + * 分辨率0.1v | ||
| 31 | + * 0xff 0xfe 异常 | ||
| 32 | + * 0xff 0xff 无效 | ||
| 33 | + */ | ||
| 34 | + private short current; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 燃料消耗率 0-60000 | ||
| 38 | + * 分辨率0.01kg/100km | ||
| 39 | + * 0xff 0xfe 异常 | ||
| 40 | + * 0xff 0xff 无效 | ||
| 41 | + */ | ||
| 42 | + private short fuelConsumeRate; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 电池温度探针数量 0-65531 | ||
| 46 | + * n | ||
| 47 | + * 0xff 0xfe 异常 | ||
| 48 | + * 0xff 0xff 无效 | ||
| 49 | + */ | ||
| 50 | + private short tempProbeQuantity; | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 累计里程 0-240 | ||
| 54 | + * 分辨率1℃ 偏移量-40 n*1 | ||
| 55 | + * 0xff 0xff 0xff 0xfe 异常 | ||
| 56 | + * 0xff 0xff 0xff 0xff 无效 | ||
| 57 | + */ | ||
| 58 | + private byte[] temps; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 氢系统中最高温度值 0-2400 | ||
| 62 | + * 分辨率0.1℃ 偏移量-400 | ||
| 63 | + * 0xff 0xfe 异常 | ||
| 64 | + * 0xff 0xff 无效 | ||
| 65 | + */ | ||
| 66 | + private short hydrogenMaxTemp; | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 氢系统最高温度探针代号 1-252 | ||
| 70 | + * 0xfe 异常 | ||
| 71 | + * 0xff 无效 | ||
| 72 | + */ | ||
| 73 | + private byte maxTempSensorCode; | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 氢气最大浓度 0-60000 | ||
| 77 | + * 分辨率1mg/kg | ||
| 78 | + * 0xFF 0xFE 异常 | ||
| 79 | + * 0xFF 0xFF 无效 | ||
| 80 | + */ | ||
| 81 | + private short hydrogenMaxConcentration; | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 氢气最大浓度传感器代号 1-252 | ||
| 85 | + * 0xfe 异常 | ||
| 86 | + * 0xff 无效 | ||
| 87 | + */ | ||
| 88 | + private byte maxConcentrationSensorCode; | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 氢气最高压力 0-1000 | ||
| 92 | + * 分辨率0.1MPa | ||
| 93 | + * 0xFF 0xFE 异常 | ||
| 94 | + * 0xFF 0xFF 无效 | ||
| 95 | + */ | ||
| 96 | + private short hydrogenMaxPressure; | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * 氢气最大浓度传感器代号 1-252 | ||
| 100 | + * 0xfe 异常 | ||
| 101 | + * 0xff 无效 | ||
| 102 | + */ | ||
| 103 | + private byte maxPressureSensorCode; | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * dc-dc状态 | ||
| 107 | + * 0x01 工作 | ||
| 108 | + * 0x02 断开 | ||
| 109 | + * 0xFE 异常 | ||
| 110 | + * 0xFF 无效 | ||
| 111 | + */ | ||
| 112 | + private byte dcState; | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public void read(byte[] bytes, int idx) { | ||
| 116 | + // TODO Auto-generated method stub | ||
| 117 | + infoType = bytes[idx]; idx++; | ||
| 118 | + voltage = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 119 | + current = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 120 | + fuelConsumeRate = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 121 | + tempProbeQuantity = bytes[idx]; idx++; | ||
| 122 | + temps = Arrays.copyOfRange(bytes, idx, idx + (tempProbeQuantity & Constant.BYTE_INT)); idx += tempProbeQuantity & Constant.BYTE_INT; | ||
| 123 | + hydrogenMaxTemp = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 124 | + maxTempSensorCode = bytes[idx]; idx++; | ||
| 125 | + hydrogenMaxConcentration = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 126 | + maxConcentrationSensorCode = bytes[idx]; idx++; | ||
| 127 | + hydrogenMaxPressure = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 128 | + maxPressureSensorCode = bytes[idx]; idx++; | ||
| 129 | + dcState = bytes[idx]; idx++; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public int getByteLen() { | ||
| 134 | + return 19 + temps.length; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public byte getInfoType() { | ||
| 138 | + return infoType; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void setInfoType(byte infoType) { | ||
| 142 | + this.infoType = infoType; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public short getVoltage() { | ||
| 146 | + return voltage; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public void setVoltage(short voltage) { | ||
| 150 | + this.voltage = voltage; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public short getCurrent() { | ||
| 154 | + return current; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public void setCurrent(short current) { | ||
| 158 | + this.current = current; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public short getFuelConsumeRate() { | ||
| 162 | + return fuelConsumeRate; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public void setFuelConsumeRate(short fuelConsumeRate) { | ||
| 166 | + this.fuelConsumeRate = fuelConsumeRate; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public short getTempProbeQuantity() { | ||
| 170 | + return tempProbeQuantity; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public void setTempProbeQuantity(short tempProbeQuantity) { | ||
| 174 | + this.tempProbeQuantity = tempProbeQuantity; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + public byte[] getTemps() { | ||
| 178 | + return temps; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public void setTemps(byte[] temps) { | ||
| 182 | + this.temps = temps; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + public short getHydrogenMaxTemp() { | ||
| 186 | + return hydrogenMaxTemp; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + public void setHydrogenMaxTemp(short hydrogenMaxTemp) { | ||
| 190 | + this.hydrogenMaxTemp = hydrogenMaxTemp; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + public byte getMaxTempSensorCode() { | ||
| 194 | + return maxTempSensorCode; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + public void setMaxTempSensorCode(byte maxTempSensorCode) { | ||
| 198 | + this.maxTempSensorCode = maxTempSensorCode; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + public short getHydrogenMaxConcentration() { | ||
| 202 | + return hydrogenMaxConcentration; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + public void setHydrogenMaxConcentration(short hydrogenMaxConcentration) { | ||
| 206 | + this.hydrogenMaxConcentration = hydrogenMaxConcentration; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + public byte getMaxConcentrationSensorCode() { | ||
| 210 | + return maxConcentrationSensorCode; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + public void setMaxConcentrationSensorCode(byte maxConcentrationSensorCode) { | ||
| 214 | + this.maxConcentrationSensorCode = maxConcentrationSensorCode; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + public short getHydrogenMaxPressure() { | ||
| 218 | + return hydrogenMaxPressure; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public void setHydrogenMaxPressure(short hydrogenMaxPressure) { | ||
| 222 | + this.hydrogenMaxPressure = hydrogenMaxPressure; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + public byte getMaxPressureSensorCode() { | ||
| 226 | + return maxPressureSensorCode; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + public void setMaxPressureSensorCode(byte maxPressureSensorCode) { | ||
| 230 | + this.maxPressureSensorCode = maxPressureSensorCode; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + public byte getDcState() { | ||
| 234 | + return dcState; | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + public void setDcState(byte dcState) { | ||
| 238 | + this.dcState = dcState; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + @Override | ||
| 242 | + public String toString() { | ||
| 243 | + StringBuilder sb = new StringBuilder(); | ||
| 244 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 245 | + .append(" 电池电压: ").append(voltage) | ||
| 246 | + .append(" 电池电流: ").append(current) | ||
| 247 | + .append(" 燃料消耗率: ").append(fuelConsumeRate) | ||
| 248 | + .append(" 电池温度探针数量: ").append(tempProbeQuantity) | ||
| 249 | + .append(" 氢系统最高温度值: ").append(hydrogenMaxTemp) | ||
| 250 | + .append(" 氢系统最高温度探针代号: ").append(maxTempSensorCode) | ||
| 251 | + .append(" 氢气最大浓度: ").append(hydrogenMaxConcentration) | ||
| 252 | + .append(" 氢气最大浓度传感器代号: ").append(maxConcentrationSensorCode) | ||
| 253 | + .append(" 氢气最高压力: ").append(hydrogenMaxPressure) | ||
| 254 | + .append(" 氢气最高压力传感器代号: ").append(maxPressureSensorCode) | ||
| 255 | + .append(" dc-dc状态: ").append(dcState); | ||
| 256 | + | ||
| 257 | + return sb.toString(); | ||
| 258 | + } | ||
| 259 | +} |
src/main/java/com/bsth/socket/protocol/Message0204.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0204.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 发动机数据 | ||
| 8 | + */ | ||
| 9 | +public class Message0204 implements IMessageBody02 { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * 信息类型 | ||
| 13 | + * 默认应该为0x04 | ||
| 14 | + */ | ||
| 15 | + private byte infoType; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 发动机状态 | ||
| 19 | + * 0x01 启动 | ||
| 20 | + * 0x02 关闭 | ||
| 21 | + * 0xfe 异常 | ||
| 22 | + * 0xff 无效 | ||
| 23 | + */ | ||
| 24 | + private byte engineState; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 发动机曲轴转速 0-60000 | ||
| 28 | + * 分辨率1r/min | ||
| 29 | + * 0xff 0xfe 异常 | ||
| 30 | + * 0xff 0xff 无效 | ||
| 31 | + */ | ||
| 32 | + private short engineSpeed; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 燃料消耗率 0-60000 | ||
| 36 | + * 分辨率0.01L/100km | ||
| 37 | + * 0xff 0xfe 异常 | ||
| 38 | + * 0xff 0xff 无效 | ||
| 39 | + */ | ||
| 40 | + private short fuelConsumeRate; | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public void read(byte[] bytes, int idx) { | ||
| 44 | + // TODO Auto-generated method stub | ||
| 45 | + infoType = bytes[idx]; idx++; | ||
| 46 | + engineState = bytes[idx]; idx++; | ||
| 47 | + engineSpeed = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 48 | + fuelConsumeRate = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public int getByteLen() { | ||
| 53 | + return 6; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public byte getInfoType() { | ||
| 57 | + return infoType; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setInfoType(byte infoType) { | ||
| 61 | + this.infoType = infoType; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public byte getEngineState() { | ||
| 65 | + return engineState; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setEngineState(byte engineState) { | ||
| 69 | + this.engineState = engineState; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public short getEngineSpeed() { | ||
| 73 | + return engineSpeed; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setEngineSpeed(short engineSpeed) { | ||
| 77 | + this.engineSpeed = engineSpeed; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public short getFuelConsumeRate() { | ||
| 81 | + return fuelConsumeRate; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setFuelConsumeRate(short fuelConsumeRate) { | ||
| 85 | + this.fuelConsumeRate = fuelConsumeRate; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public String toString() { | ||
| 90 | + StringBuilder sb = new StringBuilder(); | ||
| 91 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 92 | + .append(" 发动机状态: ").append(engineState) | ||
| 93 | + .append(" 发动机曲轴转速: ").append(engineSpeed) | ||
| 94 | + .append(" 燃料消耗率: ").append(fuelConsumeRate); | ||
| 95 | + | ||
| 96 | + return sb.toString(); | ||
| 97 | + } | ||
| 98 | +} |
src/main/java/com/bsth/socket/protocol/Message0205.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0205.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 车辆位置数据 | ||
| 8 | + */ | ||
| 9 | +public class Message0205 implements IMessageBody02 { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * 信息类型 | ||
| 13 | + * 默认应该为0x05 | ||
| 14 | + */ | ||
| 15 | + private byte infoType; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 定位状态 | ||
| 19 | + * 位0 0有效 1无效 | ||
| 20 | + * 位1 0北纬 1南纬 | ||
| 21 | + * 位2 0东经 1西经 | ||
| 22 | + * 位3-7 保留 | ||
| 23 | + */ | ||
| 24 | + private byte locationState; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 经度 | ||
| 28 | + * 分辨率0.000001 | ||
| 29 | + */ | ||
| 30 | + private int lon; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 纬度 | ||
| 34 | + * 分辨率0.000001 | ||
| 35 | + */ | ||
| 36 | + private int lat; | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + public void read(byte[] bytes, int idx) { | ||
| 40 | + // TODO Auto-generated method stub | ||
| 41 | + infoType = bytes[idx]; idx++; | ||
| 42 | + locationState = bytes[idx]; idx++; | ||
| 43 | + lon = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 44 | + lat = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public int getByteLen() { | ||
| 49 | + return 10; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public byte getInfoType() { | ||
| 53 | + return infoType; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void setInfoType(byte infoType) { | ||
| 57 | + this.infoType = infoType; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public byte getLocationState() { | ||
| 61 | + return locationState; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public void setLocationState(byte locationState) { | ||
| 65 | + this.locationState = locationState; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public int getLon() { | ||
| 69 | + return lon; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setLon(int lon) { | ||
| 73 | + this.lon = lon; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public int getLat() { | ||
| 77 | + return lat; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setLat(int lat) { | ||
| 81 | + this.lat = lat; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public String toString() { | ||
| 86 | + StringBuilder sb = new StringBuilder(); | ||
| 87 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 88 | + .append(" 定位状态: ").append(locationState) | ||
| 89 | + .append(" 经度: ").append(lon) | ||
| 90 | + .append(" 纬度: ").append(lat); | ||
| 91 | + | ||
| 92 | + return sb.toString(); | ||
| 93 | + } | ||
| 94 | +} |
src/main/java/com/bsth/socket/protocol/Message0206.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0206.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 极值数据 | ||
| 8 | + */ | ||
| 9 | +public class Message0206 implements IMessageBody02 { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * 信息类型 | ||
| 13 | + * 默认应该为0x06 | ||
| 14 | + */ | ||
| 15 | + private byte infoType; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 最高电压电池子系统代码 1-250 | ||
| 19 | + * 0xfe 异常 | ||
| 20 | + * 0xff 无效 | ||
| 21 | + */ | ||
| 22 | + private byte maxVoltageSubSysCode; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 最高电压电池单体代码 1-250 | ||
| 26 | + * 0xfe 异常 | ||
| 27 | + * 0xff 无效 | ||
| 28 | + */ | ||
| 29 | + private byte maxVoltageSubCode; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 电池单体电压最高值 0-15000 | ||
| 33 | + * 分辨率0.001v | ||
| 34 | + * 0xff 0xfe 异常 | ||
| 35 | + * 0xff 0xff 无效 | ||
| 36 | + */ | ||
| 37 | + private short maxVoltage; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 最低电压电池子系统代码 1-250 | ||
| 41 | + * 0xfe 异常 | ||
| 42 | + * 0xff 无效 | ||
| 43 | + */ | ||
| 44 | + private byte minVoltageSubSysCode; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 最低电压电池单体代码 1-250 | ||
| 48 | + * 0xfe 异常 | ||
| 49 | + * 0xff 无效 | ||
| 50 | + */ | ||
| 51 | + private byte minVoltageSubCode; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 电池单体电压最低值 0-15000 | ||
| 55 | + * 分辨率0.001v | ||
| 56 | + * 0xff 0xfe 异常 | ||
| 57 | + * 0xff 0xff 无效 | ||
| 58 | + */ | ||
| 59 | + private short minVoltage; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 最高温度子系统代码 1-250 | ||
| 63 | + * 0xfe 异常 | ||
| 64 | + * 0xff 无效 | ||
| 65 | + */ | ||
| 66 | + private byte maxTempSubSysCode; | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 最高温度探针代码 1-250 | ||
| 70 | + * 0xfe 异常 | ||
| 71 | + * 0xff 无效 | ||
| 72 | + */ | ||
| 73 | + private byte maxTempSensorCode; | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 最高温度值 0-250 | ||
| 77 | + * 分辨率1℃ 偏移量-40 | ||
| 78 | + * 0xfe 异常 | ||
| 79 | + * 0xff 无效 | ||
| 80 | + */ | ||
| 81 | + private byte maxTemp; | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 最低温度子系统代码 1-250 | ||
| 85 | + * 0xfe 异常 | ||
| 86 | + * 0xff 无效 | ||
| 87 | + */ | ||
| 88 | + private byte minTempSubSysCode; | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 最低温度探针代码 1-250 | ||
| 92 | + * 0xfe 异常 | ||
| 93 | + * 0xff 无效 | ||
| 94 | + */ | ||
| 95 | + private byte minTempSensorCode; | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 最低温度值 0-250 | ||
| 99 | + * 分辨率1℃ 偏移量-40 | ||
| 100 | + * 0xfe 异常 | ||
| 101 | + * 0xff 无效 | ||
| 102 | + */ | ||
| 103 | + private byte minTemp; | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public void read(byte[] bytes, int idx) { | ||
| 107 | + // TODO Auto-generated method stub | ||
| 108 | + infoType = bytes[idx]; idx++; | ||
| 109 | + maxVoltageSubSysCode = bytes[idx]; idx++; | ||
| 110 | + maxVoltageSubCode = bytes[idx]; idx++; | ||
| 111 | + maxVoltage = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 112 | + minVoltageSubSysCode = bytes[idx]; idx++; | ||
| 113 | + minVoltageSubCode = bytes[idx]; idx++; | ||
| 114 | + minVoltage = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 115 | + maxTempSubSysCode = bytes[idx]; idx++; | ||
| 116 | + maxTempSensorCode = bytes[idx]; idx++; | ||
| 117 | + maxTemp = bytes[idx]; idx++; | ||
| 118 | + minTempSubSysCode = bytes[idx]; idx++; | ||
| 119 | + minTempSensorCode = bytes[idx]; idx++; | ||
| 120 | + minTemp = bytes[idx]; idx++; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + @Override | ||
| 124 | + public int getByteLen() { | ||
| 125 | + return 15; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public byte getInfoType() { | ||
| 129 | + return infoType; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public void setInfoType(byte infoType) { | ||
| 133 | + this.infoType = infoType; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public byte getMaxVoltageSubSysCode() { | ||
| 137 | + return maxVoltageSubSysCode; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public void setMaxVoltageSubSysCode(byte maxVoltageSubSysCode) { | ||
| 141 | + this.maxVoltageSubSysCode = maxVoltageSubSysCode; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public byte getMaxVoltageSubCode() { | ||
| 145 | + return maxVoltageSubCode; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public void setMaxVoltageSubCode(byte maxVoltageSubCode) { | ||
| 149 | + this.maxVoltageSubCode = maxVoltageSubCode; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public short getMaxVoltage() { | ||
| 153 | + return maxVoltage; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public void setMaxVoltage(short maxVoltage) { | ||
| 157 | + this.maxVoltage = maxVoltage; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public byte getMinVoltageSubSysCode() { | ||
| 161 | + return minVoltageSubSysCode; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public void setMinVoltageSubSysCode(byte minVoltageSubSysCode) { | ||
| 165 | + this.minVoltageSubSysCode = minVoltageSubSysCode; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public byte getMinVoltageSubCode() { | ||
| 169 | + return minVoltageSubCode; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public void setMinVoltageSubCode(byte minVoltageSubCode) { | ||
| 173 | + this.minVoltageSubCode = minVoltageSubCode; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public short getMinVoltage() { | ||
| 177 | + return minVoltage; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public void setMinVoltage(short minVoltage) { | ||
| 181 | + this.minVoltage = minVoltage; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public byte getMaxTempSubSysCode() { | ||
| 185 | + return maxTempSubSysCode; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public void setMaxTempSubSysCode(byte maxTempSubSysCode) { | ||
| 189 | + this.maxTempSubSysCode = maxTempSubSysCode; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public byte getMaxTempSensorCode() { | ||
| 193 | + return maxTempSensorCode; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public void setMaxTempSensorCode(byte maxTempSensorCode) { | ||
| 197 | + this.maxTempSensorCode = maxTempSensorCode; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + public byte getMaxTemp() { | ||
| 201 | + return maxTemp; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + public void setMaxTemp(byte maxTemp) { | ||
| 205 | + this.maxTemp = maxTemp; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + public byte getMinTempSubSysCode() { | ||
| 209 | + return minTempSubSysCode; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + public void setMinTempSubSysCode(byte minTempSubSysCode) { | ||
| 213 | + this.minTempSubSysCode = minTempSubSysCode; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + public byte getMinTempSensorCode() { | ||
| 217 | + return minTempSensorCode; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + public void setMinTempSensorCode(byte minTempSensorCode) { | ||
| 221 | + this.minTempSensorCode = minTempSensorCode; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + public byte getMinTemp() { | ||
| 225 | + return minTemp; | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + public void setMinTemp(byte minTemp) { | ||
| 229 | + this.minTemp = minTemp; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + @Override | ||
| 233 | + public String toString() { | ||
| 234 | + StringBuilder sb = new StringBuilder(); | ||
| 235 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 236 | + .append(" 最大电压子系统编码: ").append(maxVoltageSubSysCode) | ||
| 237 | + .append(" 最大电压子单体代号: ").append(maxVoltageSubCode) | ||
| 238 | + .append(" 电池单体电压最高值: ").append(maxVoltage) | ||
| 239 | + .append(" 最低电压子系统编码: ").append(minVoltageSubSysCode) | ||
| 240 | + .append(" 最低电压子单体代号: ").append(minVoltageSubCode) | ||
| 241 | + .append(" 电池单体电压最低值: ").append(minVoltage) | ||
| 242 | + .append(" 最高温度子系统代码: ").append(maxTempSubSysCode) | ||
| 243 | + .append(" 最高温度探针代码: ").append(maxTempSensorCode) | ||
| 244 | + .append(" 最高温度值: ").append(maxTemp) | ||
| 245 | + .append(" 最低温度子系统代码: ").append(maxTempSubSysCode) | ||
| 246 | + .append(" 最低温度探针代码: ").append(maxTempSensorCode) | ||
| 247 | + .append(" 最低温度值: ").append(maxTemp); | ||
| 248 | + | ||
| 249 | + return sb.toString(); | ||
| 250 | + } | ||
| 251 | +} |
src/main/java/com/bsth/socket/protocol/Message0207.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0207.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.util.ConvertUtil; | ||
| 5 | + | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author Hill | ||
| 11 | + * 报警数据 | ||
| 12 | + */ | ||
| 13 | +public class Message0207 implements IMessageBody02 { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 信息类型 | ||
| 17 | + * 默认应该为0x07 | ||
| 18 | + */ | ||
| 19 | + private byte infoType; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 最高警报等级 0-3(亦可自定义) | ||
| 23 | + * 0 无故障 | ||
| 24 | + * 1 级故障,不影响车辆行驶的故障 | ||
| 25 | + * 2 级故障,影响车辆性能,需驾驶员限制行驶的故障 | ||
| 26 | + * 3 级故障,停车待援 | ||
| 27 | + * 0xfe 异常 | ||
| 28 | + * 0xff 无效 | ||
| 29 | + */ | ||
| 30 | + private byte maxAlarmLevel; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 通用报警标志 | ||
| 34 | + * 0位 0正常 1温度差异 1位 电池高温 2位 车载储能装置类型过压 3位 车载储能装置类型欠压 | ||
| 35 | + * 4位 SOC低 5位 单体电池过压 6位 单体电池欠压 7位 SOC过高 | ||
| 36 | + * 8位 SOC跳变 9位 可充电储能系统不匹配 10位 电池单体一致性差 11位 绝缘 | ||
| 37 | + * 12位 DC-DC温度 13位 制动系统 14位 DC-DC状态 15位 驱动电机控制器温度 | ||
| 38 | + * 16位 高压互锁状态 17位 驱动电机温度 18位 车载储能装置类型过充 | ||
| 39 | + * 19-31位 保留 | ||
| 40 | + */ | ||
| 41 | + private int commonAlarmFlag; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 储能装置数量 0-252 | ||
| 45 | + * N1 | ||
| 46 | + * 0xfe 异常 | ||
| 47 | + * 0xff 无效 | ||
| 48 | + */ | ||
| 49 | + private byte energyStorageDeviceQuantity; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 储能装置报警情况(自定义) | ||
| 53 | + * N1 * 4 | ||
| 54 | + */ | ||
| 55 | + private int[] esdAlarms; | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 驱动电机数量 0-252 | ||
| 59 | + * N2 | ||
| 60 | + * 0xfe 异常 | ||
| 61 | + * 0xff 无效 | ||
| 62 | + */ | ||
| 63 | + private byte electricMotorQuantity; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 驱动电机报警情况(自定义) | ||
| 67 | + * N2 * 4 | ||
| 68 | + */ | ||
| 69 | + private int[] emAlarms; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 发动机数量 0-252 | ||
| 73 | + * N3 | ||
| 74 | + * 0xfe 异常 | ||
| 75 | + * 0xff 无效 | ||
| 76 | + */ | ||
| 77 | + private byte engineQuantity; | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 发动机报警情况(自定义) | ||
| 81 | + * N3 * 4 | ||
| 82 | + */ | ||
| 83 | + private int[] engineAlarms; | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 其它故障 0-252 | ||
| 87 | + * N4 | ||
| 88 | + * 0xfe 异常 | ||
| 89 | + * 0xff 无效 | ||
| 90 | + */ | ||
| 91 | + private byte otherQuantity; | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 扩展故障详细 | ||
| 95 | + */ | ||
| 96 | + private List<Trouble> troubleList = new ArrayList<>(); | ||
| 97 | + | ||
| 98 | + @Override | ||
| 99 | + public void read(byte[] bytes, int idx) { | ||
| 100 | + // TODO Auto-generated method stub | ||
| 101 | + infoType = bytes[idx]; idx++; | ||
| 102 | + maxAlarmLevel = bytes[idx]; idx++; | ||
| 103 | + commonAlarmFlag = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 104 | + energyStorageDeviceQuantity = bytes[idx]; idx++; | ||
| 105 | + int count = energyStorageDeviceQuantity & Constant.BYTE_INT; | ||
| 106 | + if (count == 0xFE || count == 0xFF) { | ||
| 107 | + count = 0; | ||
| 108 | + } | ||
| 109 | + esdAlarms = new int[count]; | ||
| 110 | + for (int i = 0;i < count;i++) { | ||
| 111 | + esdAlarms[i] = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 112 | + } | ||
| 113 | + electricMotorQuantity = bytes[idx]; idx++; | ||
| 114 | + count = electricMotorQuantity & Constant.BYTE_INT; | ||
| 115 | + if (count == 0xFE || count == 0xFF) { | ||
| 116 | + count = 0; | ||
| 117 | + } | ||
| 118 | + emAlarms = new int[count]; | ||
| 119 | + for (int i = 0;i < count;i++) { | ||
| 120 | + emAlarms[i] = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 121 | + } | ||
| 122 | + engineQuantity = bytes[idx]; idx++; | ||
| 123 | + count = engineQuantity & Constant.BYTE_INT; | ||
| 124 | + if (count == 0xFE || count == 0xFF) { | ||
| 125 | + count = 0; | ||
| 126 | + } | ||
| 127 | + engineAlarms = new int[count]; | ||
| 128 | + for (int i = 0;i < count;i++) { | ||
| 129 | + engineAlarms[i] = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4; | ||
| 130 | + } | ||
| 131 | + otherQuantity = bytes[idx]; idx++; | ||
| 132 | + count = otherQuantity & Constant.BYTE_INT; | ||
| 133 | + if (count == 0xFF) { | ||
| 134 | + count = 0; | ||
| 135 | + } | ||
| 136 | + if (idx + count * Trouble.BYTE_LEN < bytes.length - 1) { | ||
| 137 | + for (int i = 0;i < count;i ++) { | ||
| 138 | + Trouble trouble = new Trouble(); | ||
| 139 | + trouble.read(bytes, idx); idx += Trouble.BYTE_LEN; | ||
| 140 | + troubleList.add(trouble); | ||
| 141 | + } | ||
| 142 | + } else { | ||
| 143 | + throw new IllegalArgumentException("异常的扩展故障数据"); | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public int getByteLen() { | ||
| 149 | + return 10 + (esdAlarms.length + emAlarms.length + engineAlarms.length + troubleList.size()) * 4; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public byte getInfoType() { | ||
| 153 | + return infoType; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public void setInfoType(byte infoType) { | ||
| 157 | + this.infoType = infoType; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public byte getMaxAlarmLevel() { | ||
| 161 | + return maxAlarmLevel; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public void setMaxAlarmLevel(byte maxAlarmLevel) { | ||
| 165 | + this.maxAlarmLevel = maxAlarmLevel; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public int getCommonAlarmFlag() { | ||
| 169 | + return commonAlarmFlag; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public void setCommonAlarmFlag(int commonAlarmFlag) { | ||
| 173 | + this.commonAlarmFlag = commonAlarmFlag; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public byte getEnergyStorageDeviceQuantity() { | ||
| 177 | + return energyStorageDeviceQuantity; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public void setEnergyStorageDeviceQuantity(byte energyStorageDeviceQuantity) { | ||
| 181 | + this.energyStorageDeviceQuantity = energyStorageDeviceQuantity; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public int[] getEsdAlarms() { | ||
| 185 | + return esdAlarms; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public void setEsdAlarms(int[] esdAlarms) { | ||
| 189 | + this.esdAlarms = esdAlarms; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public byte getElectricMotorQuantity() { | ||
| 193 | + return electricMotorQuantity; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public void setElectricMotorQuantity(byte electricMotorQuantity) { | ||
| 197 | + this.electricMotorQuantity = electricMotorQuantity; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + public int[] getEmAlarms() { | ||
| 201 | + return emAlarms; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + public void setEmAlarms(int[] emAlarms) { | ||
| 205 | + this.emAlarms = emAlarms; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + public byte getEngineQuantity() { | ||
| 209 | + return engineQuantity; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + public void setEngineQuantity(byte engineQuantity) { | ||
| 213 | + this.engineQuantity = engineQuantity; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + public int[] getEngineAlarms() { | ||
| 217 | + return engineAlarms; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + public void setEngineAlarms(int[] engineAlarms) { | ||
| 221 | + this.engineAlarms = engineAlarms; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + public byte getOtherQuantity() { | ||
| 225 | + return otherQuantity; | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + public void setOtherQuantity(byte otherQuantity) { | ||
| 229 | + this.otherQuantity = otherQuantity; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public List<Trouble> getTroubleList() { | ||
| 233 | + return troubleList; | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + public void setTroubleList(List<Trouble> troubleList) { | ||
| 237 | + this.troubleList = troubleList; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + @Override | ||
| 241 | + public String toString() { | ||
| 242 | + StringBuilder sb = new StringBuilder(); | ||
| 243 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 244 | + .append(" 最大报警级别: ").append(maxAlarmLevel) | ||
| 245 | + .append(" 通用报警标志: ").append(commonAlarmFlag) | ||
| 246 | + .append(" 储能设备报警数: ").append(energyStorageDeviceQuantity) | ||
| 247 | + .append(" 电机报警数: ").append(electricMotorQuantity) | ||
| 248 | + .append(" 发动机报警数: ").append(engineQuantity) | ||
| 249 | + .append(" 其它报警数: ").append(otherQuantity) | ||
| 250 | + .append(" 自定义报警详情: "); | ||
| 251 | + | ||
| 252 | + for (Trouble trouble : troubleList) { | ||
| 253 | + sb.append(trouble.toString()); | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + return sb.toString(); | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + public static class Trouble { | ||
| 260 | + | ||
| 261 | + private final static int BYTE_LEN = 4; | ||
| 262 | + | ||
| 263 | + /** | ||
| 264 | + * 故障类型 | ||
| 265 | + */ | ||
| 266 | + private byte type; | ||
| 267 | + | ||
| 268 | + /** | ||
| 269 | + * 故障代码 | ||
| 270 | + */ | ||
| 271 | + private short code; | ||
| 272 | + | ||
| 273 | + /** | ||
| 274 | + * 故障级别 | ||
| 275 | + */ | ||
| 276 | + private byte level; | ||
| 277 | + | ||
| 278 | + public void read(byte[] bytes, int idx) { | ||
| 279 | + type = bytes[idx]; idx++; | ||
| 280 | + code = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 281 | + level = bytes[idx]; idx++; | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | + public byte getType() { | ||
| 285 | + return type; | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + public void setType(byte type) { | ||
| 289 | + this.type = type; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + public short getCode() { | ||
| 293 | + return code; | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + public void setCode(short code) { | ||
| 297 | + this.code = code; | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + public byte getLevel() { | ||
| 301 | + return level; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + public void setLevel(byte level) { | ||
| 305 | + this.level = level; | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + @Override | ||
| 309 | + public String toString() { | ||
| 310 | + return String.format("%02x%04x%02x\n", type, code, level); | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | +} |
src/main/java/com/bsth/socket/protocol/Message0280.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0280.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 扩展数据 | ||
| 8 | + */ | ||
| 9 | +public class Message0280 implements IMessageBody02 { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * 信息类型 | ||
| 13 | + * 默认应该为0x80 | ||
| 14 | + */ | ||
| 15 | + private byte infoType; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 自定义数据长度 1-65531 | ||
| 19 | + * 默认34 | ||
| 20 | + */ | ||
| 21 | + private short customDataLen; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 蓄电池电压 0-32 | ||
| 25 | + * 分辨率0.5v/bit | ||
| 26 | + * 0xfe 异常 | ||
| 27 | + * 0xff 无效 | ||
| 28 | + */ | ||
| 29 | + private byte storageBatteryVoltage; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 左前轮胎压力 0-250 | ||
| 33 | + * 分辨率 4kPa | ||
| 34 | + * 0xfe 异常 | ||
| 35 | + * 0xff 无效 | ||
| 36 | + */ | ||
| 37 | + private byte lfTirePressure; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 左前轮胎温度 0-250 | ||
| 41 | + * 分辨率 1℃ | ||
| 42 | + * 0xfe 异常 | ||
| 43 | + * 0xff 无效 | ||
| 44 | + */ | ||
| 45 | + private byte lfTireTemp; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 右前轮胎压力 0-250 | ||
| 49 | + * 分辨率 4kPa | ||
| 50 | + * 0xfe 异常 | ||
| 51 | + * 0xff 无效 | ||
| 52 | + */ | ||
| 53 | + private byte rfTirePressure; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 右前轮胎温度 0-250 | ||
| 57 | + * 分辨率 1℃ | ||
| 58 | + * 0xfe 异常 | ||
| 59 | + * 0xff 无效 | ||
| 60 | + */ | ||
| 61 | + private byte rfTireTemp; | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * 左后轮胎1压力 0-250 | ||
| 65 | + * 分辨率 4kPa | ||
| 66 | + * 0xfe 异常 | ||
| 67 | + * 0xff 无效 | ||
| 68 | + */ | ||
| 69 | + private byte lrTirePressure1; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 左后轮胎1温度 0-250 | ||
| 73 | + * 分辨率 1℃ | ||
| 74 | + * 0xfe 异常 | ||
| 75 | + * 0xff 无效 | ||
| 76 | + */ | ||
| 77 | + private byte lrTireTemp1; | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 左后轮胎2压力 0-250 | ||
| 81 | + * 分辨率 4kPa | ||
| 82 | + * 0xfe 异常 | ||
| 83 | + * 0xff 无效 | ||
| 84 | + */ | ||
| 85 | + private byte lrTirePressure2; | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 左后轮胎2温度 0-250 | ||
| 89 | + * 分辨率 1℃ | ||
| 90 | + * 0xfe 异常 | ||
| 91 | + * 0xff 无效 | ||
| 92 | + */ | ||
| 93 | + private byte lrTireTemp2; | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 右后轮胎1压力 0-250 | ||
| 97 | + * 分辨率 4kPa | ||
| 98 | + * 0xfe 异常 | ||
| 99 | + * 0xff 无效 | ||
| 100 | + */ | ||
| 101 | + private byte rrTirePressure1; | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 右后轮胎1温度 0-250 | ||
| 105 | + * 分辨率 1℃ | ||
| 106 | + * 0xfe 异常 | ||
| 107 | + * 0xff 无效 | ||
| 108 | + */ | ||
| 109 | + private byte rrTireTemp1; | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * 右后轮胎2压力 0-250 | ||
| 113 | + * 分辨率 4kPa | ||
| 114 | + * 0xfe 异常 | ||
| 115 | + * 0xff 无效 | ||
| 116 | + */ | ||
| 117 | + private byte rrTirePressure2; | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 右后轮胎2温度 0-250 | ||
| 121 | + * 分辨率 1℃ | ||
| 122 | + * 0xfe 异常 | ||
| 123 | + * 0xff 无效 | ||
| 124 | + */ | ||
| 125 | + private byte rrTireTemp2; | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 无法定义 | ||
| 129 | + * 用了其中2,3位作为手刹状态 | ||
| 130 | + * 0无信号 1有信号 2异常 3无效 | ||
| 131 | + */ | ||
| 132 | + private byte unknown; | ||
| 133 | + | ||
| 134 | + @Override | ||
| 135 | + public void read(byte[] bytes, int idx) { | ||
| 136 | + // TODO Auto-generated method stub | ||
| 137 | + infoType = bytes[idx]; idx++; | ||
| 138 | + customDataLen = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 139 | + // 预留2 | ||
| 140 | + idx += 2; | ||
| 141 | + storageBatteryVoltage = bytes[idx]; idx++; | ||
| 142 | + // 预留6 | ||
| 143 | + idx += 6; | ||
| 144 | + lfTirePressure = bytes[idx]; idx++; | ||
| 145 | + lfTireTemp = bytes[idx]; idx++; | ||
| 146 | + rfTirePressure = bytes[idx]; idx++; | ||
| 147 | + rfTireTemp = bytes[idx]; idx++; | ||
| 148 | + lrTirePressure1 = bytes[idx]; idx++; | ||
| 149 | + lrTireTemp1 = bytes[idx]; idx++; | ||
| 150 | + lrTirePressure2 = bytes[idx]; idx++; | ||
| 151 | + lrTireTemp2 = bytes[idx]; idx++; | ||
| 152 | + rrTirePressure1 = bytes[idx]; idx++; | ||
| 153 | + rrTireTemp1 = bytes[idx]; idx++; | ||
| 154 | + rrTirePressure2 = bytes[idx]; idx++; | ||
| 155 | + rrTireTemp2 = bytes[idx]; idx++; | ||
| 156 | + // 预留15 | ||
| 157 | + idx += 26; | ||
| 158 | + unknown = bytes[idx]; idx++; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + @Override | ||
| 162 | + public int getByteLen() { | ||
| 163 | + return customDataLen + 3; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public byte getInfoType() { | ||
| 167 | + return infoType; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public void setInfoType(byte infoType) { | ||
| 171 | + this.infoType = infoType; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + public short getCustomDataLen() { | ||
| 175 | + return customDataLen; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + public void setCustomDataLen(short customDataLen) { | ||
| 179 | + this.customDataLen = customDataLen; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + public byte getStorageBatteryVoltage() { | ||
| 183 | + return storageBatteryVoltage; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public void setStorageBatteryVoltage(byte storageBatteryVoltage) { | ||
| 187 | + this.storageBatteryVoltage = storageBatteryVoltage; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public byte getLfTirePressure() { | ||
| 191 | + return lfTirePressure; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + public void setLfTirePressure(byte lfTirePressure) { | ||
| 195 | + this.lfTirePressure = lfTirePressure; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + public byte getLfTireTemp() { | ||
| 199 | + return lfTireTemp; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + public void setLfTireTemp(byte lfTireTemp) { | ||
| 203 | + this.lfTireTemp = lfTireTemp; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + public byte getRfTirePressure() { | ||
| 207 | + return rfTirePressure; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + public void setRfTirePressure(byte rfTirePressure) { | ||
| 211 | + this.rfTirePressure = rfTirePressure; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + public byte getRfTireTemp() { | ||
| 215 | + return rfTireTemp; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + public void setRfTireTemp(byte rfTireTemp) { | ||
| 219 | + this.rfTireTemp = rfTireTemp; | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + public byte getLrTirePressure1() { | ||
| 223 | + return lrTirePressure1; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + public void setLrTirePressure1(byte lrTirePressure1) { | ||
| 227 | + this.lrTirePressure1 = lrTirePressure1; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + public byte getLrTireTemp1() { | ||
| 231 | + return lrTireTemp1; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + public void setLrTireTemp1(byte lrTireTemp1) { | ||
| 235 | + this.lrTireTemp1 = lrTireTemp1; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + public byte getLrTirePressure2() { | ||
| 239 | + return lrTirePressure2; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + public void setLrTirePressure2(byte lrTirePressure2) { | ||
| 243 | + this.lrTirePressure2 = lrTirePressure2; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + public byte getLrTireTemp2() { | ||
| 247 | + return lrTireTemp2; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + public void setLrTireTemp2(byte lrTireTemp2) { | ||
| 251 | + this.lrTireTemp2 = lrTireTemp2; | ||
| 252 | + } | ||
| 253 | + | ||
| 254 | + public byte getRrTirePressure1() { | ||
| 255 | + return rrTirePressure1; | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + public void setRrTirePressure1(byte rrTirePressure1) { | ||
| 259 | + this.rrTirePressure1 = rrTirePressure1; | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + public byte getRrTireTemp1() { | ||
| 263 | + return rrTireTemp1; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + public void setRrTireTemp1(byte rrTireTemp1) { | ||
| 267 | + this.rrTireTemp1 = rrTireTemp1; | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + public byte getRrTirePressure2() { | ||
| 271 | + return rrTirePressure2; | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + public void setRrTirePressure2(byte rrTirePressure2) { | ||
| 275 | + this.rrTirePressure2 = rrTirePressure2; | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + public byte getRrTireTemp2() { | ||
| 279 | + return rrTireTemp2; | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + public void setRrTireTemp2(byte rrTireTemp2) { | ||
| 283 | + this.rrTireTemp2 = rrTireTemp2; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + @Override | ||
| 287 | + public String toString() { | ||
| 288 | + StringBuilder sb = new StringBuilder(); | ||
| 289 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)) | ||
| 290 | + .append(" 自定义数据长度: ").append(customDataLen) | ||
| 291 | + .append(" 蓄电池电压: ").append(storageBatteryVoltage) | ||
| 292 | + .append(" 左前轮压力: ").append(lfTirePressure) | ||
| 293 | + .append(" 左前轮温度: ").append(lfTireTemp) | ||
| 294 | + .append(" 右前轮压力: ").append(rfTirePressure) | ||
| 295 | + .append(" 右前轮温度: ").append(rfTireTemp) | ||
| 296 | + .append(" 左后轮1压力: ").append(lrTirePressure1) | ||
| 297 | + .append(" 左后轮1温度: ").append(lrTireTemp1) | ||
| 298 | + .append(" 左后轮2压力: ").append(lrTirePressure2) | ||
| 299 | + .append(" 左后轮2温度: ").append(lrTireTemp2) | ||
| 300 | + .append(" 右后轮1压力: ").append(rrTirePressure1) | ||
| 301 | + .append(" 右后轮1温度: ").append(rrTireTemp1) | ||
| 302 | + .append(" 右后轮2压力: ").append(rrTirePressure2) | ||
| 303 | + .append(" 右后轮2温度: ").append(rrTireTemp2) | ||
| 304 | + .append(" 手刹状态: ").append(unknown); | ||
| 305 | + | ||
| 306 | + return sb.toString(); | ||
| 307 | + } | ||
| 308 | +} |
src/main/java/com/bsth/socket/protocol/Message0281.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message0281.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +import java.util.ArrayList; | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + * 车载终端秒采集10秒发送数据 | ||
| 11 | + */ | ||
| 12 | +public class Message0281 implements IMessageBody02 { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 信息类型 | ||
| 16 | + * 默认应该为0x81 | ||
| 17 | + */ | ||
| 18 | + private byte infoType; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 车载终端每10秒数据 | ||
| 22 | + */ | ||
| 23 | + private List<TenSecondsPerData> dataList = new ArrayList<>(); | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public void read(byte[] bytes, int idx) { | ||
| 27 | + // TODO Auto-generated method stub | ||
| 28 | + infoType = bytes[idx]; idx++; | ||
| 29 | + while (idx < bytes.length - 1) { | ||
| 30 | + TenSecondsPerData data = new TenSecondsPerData(); | ||
| 31 | + data.read(bytes, idx); idx += TenSecondsPerData.BYTE_LEN; | ||
| 32 | + dataList.add(data); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public byte getInfoType() { | ||
| 37 | + return infoType; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public void setInfoType(byte infoType) { | ||
| 41 | + this.infoType = infoType; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public List<TenSecondsPerData> getDataList() { | ||
| 45 | + return dataList; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setDataList(List<TenSecondsPerData> dataList) { | ||
| 49 | + this.dataList = dataList; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public int getByteLen() { | ||
| 54 | + return 1 + dataList.size() * TenSecondsPerData.BYTE_LEN; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public String toString() { | ||
| 59 | + StringBuilder sb = new StringBuilder(); | ||
| 60 | + sb.append(" 信息类型: ").append(String.format("%02x", infoType)); | ||
| 61 | + for (TenSecondsPerData data : dataList) { | ||
| 62 | + sb.append(data.toString()); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + return sb.toString(); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public static class TenSecondsPerData { | ||
| 69 | + | ||
| 70 | + private final static int BYTE_LEN = 10; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 加速踏板标识类型 | ||
| 74 | + * 默认应该为0x01 | ||
| 75 | + */ | ||
| 76 | + private byte acceleratorFlag; | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 加速踏板行程值 0-100% | ||
| 80 | + * 分辨率1% | ||
| 81 | + * 0xFE 异常 | ||
| 82 | + * 0xFF 无效 | ||
| 83 | + */ | ||
| 84 | + private byte acceleratorState; | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 制动踏板标识类型 | ||
| 88 | + * 默认应该为0x02 | ||
| 89 | + */ | ||
| 90 | + private byte brakePedalFlag; | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * 制动踏板状态 0-100% | ||
| 94 | + * 分辨率1% 在无具体行程值情况下,用“101”表示制动有效状态 | ||
| 95 | + * 0xFE 异常 | ||
| 96 | + * 0xFF 无效 | ||
| 97 | + */ | ||
| 98 | + private byte brakePedalState; | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 车速标识类型 | ||
| 102 | + * 默认应该为0x03 | ||
| 103 | + */ | ||
| 104 | + private byte speedFlag; | ||
| 105 | + | ||
| 106 | + /** | ||
| 107 | + * 车速 0-2200 | ||
| 108 | + * 分辨率0.1km/h | ||
| 109 | + * 0xff 0xfe 异常 | ||
| 110 | + * 0xff 0xff 无效 | ||
| 111 | + */ | ||
| 112 | + private short speed; | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * 总电流标识类型 | ||
| 116 | + * 默认应该为0x04 | ||
| 117 | + */ | ||
| 118 | + private byte totalCurrentFlag; | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 总电流 0-20000 | ||
| 122 | + * 分辨率0.1a | ||
| 123 | + * 0xff 0xfe 异常 | ||
| 124 | + * 0xff 0xff 无效 | ||
| 125 | + */ | ||
| 126 | + private short totalCurrent; | ||
| 127 | + | ||
| 128 | + public void read(byte[] bytes, int idx) { | ||
| 129 | + // TODO Auto-generated method stub | ||
| 130 | + acceleratorFlag = bytes[idx]; idx++; | ||
| 131 | + acceleratorState = bytes[idx]; idx++; | ||
| 132 | + brakePedalFlag = bytes[idx]; idx++; | ||
| 133 | + brakePedalState = bytes[idx]; idx++; | ||
| 134 | + speedFlag = bytes[idx]; idx++; | ||
| 135 | + speed = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 136 | + totalCurrentFlag = bytes[idx]; idx++; | ||
| 137 | + totalCurrent = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public byte getAcceleratorFlag() { | ||
| 141 | + return acceleratorFlag; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public void setAcceleratorFlag(byte acceleratorFlag) { | ||
| 145 | + this.acceleratorFlag = acceleratorFlag; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public byte getAcceleratorState() { | ||
| 149 | + return acceleratorState; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public void setAcceleratorState(byte acceleratorState) { | ||
| 153 | + this.acceleratorState = acceleratorState; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public byte getBrakePedalFlag() { | ||
| 157 | + return brakePedalFlag; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public void setBrakePedalFlag(byte brakePedalFlag) { | ||
| 161 | + this.brakePedalFlag = brakePedalFlag; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public byte getBrakePedalState() { | ||
| 165 | + return brakePedalState; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public void setBrakePedalState(byte brakePedalState) { | ||
| 169 | + this.brakePedalState = brakePedalState; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + public byte getSpeedFlag() { | ||
| 173 | + return speedFlag; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public void setSpeedFlag(byte speedFlag) { | ||
| 177 | + this.speedFlag = speedFlag; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public short getSpeed() { | ||
| 181 | + return speed; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public void setSpeed(short speed) { | ||
| 185 | + this.speed = speed; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public byte getTotalCurrentFlag() { | ||
| 189 | + return totalCurrentFlag; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public void setTotalCurrentFlag(byte totalCurrentFlag) { | ||
| 193 | + this.totalCurrentFlag = totalCurrentFlag; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public short getTotalCurrent() { | ||
| 197 | + return totalCurrent; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + public void setTotalCurrent(short totalCurrent) { | ||
| 201 | + this.totalCurrent = totalCurrent; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + @Override | ||
| 205 | + public String toString() { | ||
| 206 | + StringBuilder sb = new StringBuilder(); | ||
| 207 | + sb.append(" 加速踏板标识类型: ").append(acceleratorFlag) | ||
| 208 | + .append(" 加速踏板行程值: ").append(acceleratorState) | ||
| 209 | + .append(" 制动踏板标识类型: ").append(brakePedalFlag) | ||
| 210 | + .append(" 制动踏板状态: ").append(brakePedalState) | ||
| 211 | + .append(" 车速标识类型: ").append(speedFlag) | ||
| 212 | + .append(" 车速: ").append(speed) | ||
| 213 | + .append(" 总电流标识类型: ").append(totalCurrentFlag) | ||
| 214 | + .append(" 总电流: ").append(totalCurrent) | ||
| 215 | + .append("\n"); | ||
| 216 | + | ||
| 217 | + return sb.toString(); | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | +} |
src/main/java/com/bsth/socket/protocol/Message02Factory.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message02Factory.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.slf4j.Logger; | ||
| 5 | +import org.slf4j.LoggerFactory; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author Hill | ||
| 9 | + */ | ||
| 10 | +public class Message02Factory { | ||
| 11 | + | ||
| 12 | + private final static Logger log = LoggerFactory.getLogger(Message02Factory.class); | ||
| 13 | + | ||
| 14 | + public static IMessageBody02 create(int commandType, byte[] data, int idx) { | ||
| 15 | + String pkgName = Message02Factory.class.getPackage().getName(); | ||
| 16 | + IMessageBody02 body = null; | ||
| 17 | + try { | ||
| 18 | + System.out.println(pkgName + ".Message02" + String.format("%02x", commandType)); | ||
| 19 | + Class<?> cls = Class.forName(pkgName + ".Message02" + String.format("%02x", commandType)); | ||
| 20 | + body = (IMessageBody02)cls.newInstance(); | ||
| 21 | + body.read(data, idx); | ||
| 22 | + } catch (Exception e) { | ||
| 23 | + // TODO Auto-generated catch block | ||
| 24 | + log.error("Message02Factory create: " + ConvertUtil.toHexString(data), e); | ||
| 25 | + throw new RuntimeException(); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + return body; | ||
| 29 | + } | ||
| 30 | +} |
src/main/java/com/bsth/socket/protocol/Message04.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message04.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.joda.time.DateTime; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Hill | ||
| 8 | + * 车辆登出 | ||
| 9 | + */ | ||
| 10 | +public class Message04 implements IMessageBody { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * byte[6] | ||
| 14 | + * 数据采集时间 | ||
| 15 | + */ | ||
| 16 | + private long timestamp; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 登出流水号 | ||
| 20 | + * 应对应登入流水号 | ||
| 21 | + */ | ||
| 22 | + private short logoutSerialNo; | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public void read(byte[] bytes) { | ||
| 26 | + // TODO Auto-generated method stub | ||
| 27 | + int idx = 0; | ||
| 28 | + timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6; | ||
| 29 | + logoutSerialNo = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public byte[] write() { | ||
| 34 | + // TODO Auto-generated method stub | ||
| 35 | + return ConvertUtil.timestamp2bytes(timestamp); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public long getTimestamp() { | ||
| 39 | + return timestamp; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public void setTimestamp(long timestamp) { | ||
| 44 | + this.timestamp = timestamp; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public short getLogoutSerialNo() { | ||
| 48 | + return logoutSerialNo; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setLogoutSerialNo(short logoutSerialNo) { | ||
| 52 | + this.logoutSerialNo = logoutSerialNo; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public String toString() { | ||
| 57 | + StringBuilder sb = new StringBuilder(); | ||
| 58 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 59 | + .append(" 登出流水号:").append(logoutSerialNo); | ||
| 60 | + | ||
| 61 | + return sb.toString(); | ||
| 62 | + } | ||
| 63 | +} |
src/main/java/com/bsth/socket/protocol/Message07.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message07.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + * 心跳 | ||
| 6 | + */ | ||
| 7 | +public class Message07 implements IMessageBody { | ||
| 8 | + | ||
| 9 | + @Override | ||
| 10 | + public void read(byte[] bytes) { | ||
| 11 | + // TODO Auto-generated method stub | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public byte[] write() { | ||
| 16 | + // TODO Auto-generated method stub | ||
| 17 | + return new byte[0]; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void setTimestamp(long timestamp) { | ||
| 22 | + | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public String toString() { | ||
| 27 | + return "心跳无数据体"; | ||
| 28 | + } | ||
| 29 | +} |
src/main/java/com/bsth/socket/protocol/Message08.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message08.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + * 终端校时 | ||
| 6 | + */ | ||
| 7 | +public class Message08 implements IMessageBody { | ||
| 8 | + | ||
| 9 | + @Override | ||
| 10 | + public void read(byte[] bytes) { | ||
| 11 | + // TODO Auto-generated method stub | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public byte[] write() { | ||
| 16 | + // TODO Auto-generated method stub | ||
| 17 | + return new byte[0]; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void setTimestamp(long timestamp) { | ||
| 22 | + | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public String toString() { | ||
| 27 | + return "终端校时无数据体"; | ||
| 28 | + } | ||
| 29 | +} |
src/main/java/com/bsth/socket/protocol/Message80.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message80.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.util.ConvertUtil; | ||
| 5 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 7 | +import org.joda.time.DateTime; | ||
| 8 | + | ||
| 9 | +import java.util.LinkedHashMap; | ||
| 10 | +import java.util.Map; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * @author Hill | ||
| 14 | + * 参数查询应答 | ||
| 15 | + */ | ||
| 16 | +public class Message80 implements IMessageBody { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * byte[6] | ||
| 20 | + * 数据采集时间 | ||
| 21 | + */ | ||
| 22 | + private long timestamp; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 参数总数 | ||
| 26 | + * n | ||
| 27 | + */ | ||
| 28 | + private byte paramNum; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 参数具体数据 | ||
| 32 | + */ | ||
| 33 | + private Map<Integer, Object> params = new LinkedHashMap<>(); | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public void read(byte[] bytes) { | ||
| 37 | + // TODO Auto-generated method stub | ||
| 38 | + int idx = 0; | ||
| 39 | + timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6; | ||
| 40 | + paramNum = bytes[idx]; idx++; | ||
| 41 | + for (int i = 0;i < (paramNum & Constant.BYTE_INT);i++) { | ||
| 42 | + idx += analyzeParam(bytes, idx); | ||
| 43 | + } | ||
| 44 | + System.out.println("aaa"); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public byte[] write() { | ||
| 49 | + // TODO Auto-generated method stub | ||
| 50 | + return new byte[0]; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + private int analyzeParam(byte[] bytes, int idx) { | ||
| 54 | + int result = 1, len = 0; | ||
| 55 | + int type = bytes[idx] & Constant.BYTE_INT; | ||
| 56 | + switch (type) { | ||
| 57 | + case 0x01: | ||
| 58 | + case 0x02: | ||
| 59 | + case 0x03: | ||
| 60 | + case 0x06: | ||
| 61 | + case 0x0A: | ||
| 62 | + case 0x0B: | ||
| 63 | + case 0x0F: | ||
| 64 | + params.put(type, (short) ConvertUtil.bytes2int(bytes, ++ idx, 2)); | ||
| 65 | + result += 2; | ||
| 66 | + break; | ||
| 67 | + case 0x04: | ||
| 68 | + case 0x09: | ||
| 69 | + case 0x0C: | ||
| 70 | + case 0x0D: | ||
| 71 | + case 0x10: | ||
| 72 | + params.put(type, bytes[++ idx]); | ||
| 73 | + result ++; | ||
| 74 | + break; | ||
| 75 | + case 0x05: | ||
| 76 | + case 0x0E: | ||
| 77 | + len = ((Byte) params.get(type - 1)).byteValue() & Constant.BYTE_INT; | ||
| 78 | + params.put(type, ConvertUtil.ascii2string(bytes, ++ idx, len)); | ||
| 79 | + result += len; | ||
| 80 | + break; | ||
| 81 | + case 0x07: | ||
| 82 | + case 0x08: | ||
| 83 | + params.put(type, ConvertUtil.ascii2string(bytes, ++ idx, 5)); | ||
| 84 | + result += 5; | ||
| 85 | + break; | ||
| 86 | + default: | ||
| 87 | + break; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + return result; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public long getTimestamp() { | ||
| 94 | + return timestamp; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public void setTimestamp(long timestamp) { | ||
| 99 | + this.timestamp = timestamp; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public byte getParamNum() { | ||
| 103 | + return paramNum; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public void setParamNum(byte paramNum) { | ||
| 107 | + this.paramNum = paramNum; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public Map<Integer, Object> getParams() { | ||
| 111 | + return params; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setParams(Map<Integer, Object> params) { | ||
| 115 | + this.params = params; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + @Override | ||
| 119 | + public String toString() { | ||
| 120 | + StringBuilder sb = new StringBuilder(); | ||
| 121 | + try { | ||
| 122 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 123 | + .append(" 参数数量:").append(paramNum) | ||
| 124 | + .append(" 参数命令IDS:").append(new ObjectMapper().writeValueAsString(params)); | ||
| 125 | + } catch (JsonProcessingException e) { | ||
| 126 | + e.printStackTrace(); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + return sb.toString(); | ||
| 130 | + } | ||
| 131 | +} |
src/main/java/com/bsth/socket/protocol/Message80Cmd.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message80Cmd.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.util.ConvertUtil; | ||
| 5 | +import org.joda.time.DateTime; | ||
| 6 | + | ||
| 7 | +import java.nio.ByteBuffer; | ||
| 8 | +import java.util.Arrays; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * @author Hill | ||
| 12 | + * 参数查询 | ||
| 13 | + */ | ||
| 14 | +public class Message80Cmd implements IMessageBody { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * byte[6] | ||
| 18 | + * 数据采集时间 | ||
| 19 | + */ | ||
| 20 | + private long timestamp; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 参数总数 | ||
| 24 | + * n | ||
| 25 | + */ | ||
| 26 | + private byte paramNum; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 参数命令ID | ||
| 30 | + * n*1 | ||
| 31 | + */ | ||
| 32 | + private byte[] paramIds; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void read(byte[] bytes) { | ||
| 36 | + // TODO Auto-generated method stub | ||
| 37 | + int idx = 0; | ||
| 38 | + timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6; | ||
| 39 | + paramNum = bytes[idx]; idx++; | ||
| 40 | + int len = paramNum & Constant.BYTE_INT; | ||
| 41 | + Arrays.copyOfRange(bytes, idx, idx + len); idx += len; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + public byte[] write() { | ||
| 46 | + // TODO Auto-generated method stub | ||
| 47 | + ByteBuffer buf = ByteBuffer.allocate(7 + paramIds.length); | ||
| 48 | + buf.put(ConvertUtil.timestamp2bytes(timestamp)); | ||
| 49 | + buf.put(paramNum); | ||
| 50 | + buf.put(paramIds); | ||
| 51 | + | ||
| 52 | + return buf.array(); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public long getTimestamp() { | ||
| 56 | + return timestamp; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public void setTimestamp(long timestamp) { | ||
| 61 | + this.timestamp = timestamp; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public byte getParamNum() { | ||
| 65 | + return paramNum; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setParamNum(byte paramNum) { | ||
| 69 | + this.paramNum = paramNum; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public byte[] getParamIds() { | ||
| 73 | + return paramIds; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setParamIds(byte[] paramIds) { | ||
| 77 | + this.paramIds = paramIds; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public String toString() { | ||
| 82 | + StringBuilder sb = new StringBuilder(); | ||
| 83 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 84 | + .append(" 参数数量:").append(paramNum) | ||
| 85 | + .append(" 参数命令IDS:").append(ConvertUtil.toHexString(paramIds)); | ||
| 86 | + | ||
| 87 | + return sb.toString(); | ||
| 88 | + } | ||
| 89 | +} |
src/main/java/com/bsth/socket/protocol/Message81.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message81.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.joda.time.DateTime; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Hill | ||
| 8 | + * 参数设置应答 | ||
| 9 | + */ | ||
| 10 | +public class Message81 implements IMessageBody { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * byte[6] | ||
| 14 | + * 数据采集时间 | ||
| 15 | + */ | ||
| 16 | + private long timestamp; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 参数总数 | ||
| 20 | + * n | ||
| 21 | + */ | ||
| 22 | + private byte paramNum; | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public void read(byte[] bytes) { | ||
| 26 | + // TODO Auto-generated method stub | ||
| 27 | + int idx = 0; | ||
| 28 | + timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6; | ||
| 29 | + paramNum = bytes[idx]; idx++; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public byte[] write() { | ||
| 34 | + // TODO Auto-generated method stub | ||
| 35 | + return new byte[0]; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public long getTimestamp() { | ||
| 39 | + return timestamp; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public void setTimestamp(long timestamp) { | ||
| 44 | + this.timestamp = timestamp; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public byte getParamNum() { | ||
| 48 | + return paramNum; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setParamNum(byte paramNum) { | ||
| 52 | + this.paramNum = paramNum; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public String toString() { | ||
| 57 | + StringBuilder sb = new StringBuilder(); | ||
| 58 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 59 | + .append(" 参数数量:").append(paramNum); | ||
| 60 | + | ||
| 61 | + return sb.toString(); | ||
| 62 | + } | ||
| 63 | +} |
src/main/java/com/bsth/socket/protocol/Message81Cmd.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message81Cmd.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.joda.time.DateTime; | ||
| 5 | + | ||
| 6 | +import java.nio.ByteBuffer; | ||
| 7 | +import java.util.*; | ||
| 8 | +import java.util.concurrent.atomic.AtomicInteger; | ||
| 9 | +import java.util.function.Function; | ||
| 10 | +import java.util.stream.Collectors; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * @author Hill | ||
| 14 | + * 参数设置 | ||
| 15 | + */ | ||
| 16 | +public class Message81Cmd implements IMessageBody { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * byte[6] | ||
| 20 | + * 数据采集时间 | ||
| 21 | + */ | ||
| 22 | + private long timestamp; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 参数总数 | ||
| 26 | + * n | ||
| 27 | + */ | ||
| 28 | + private byte paramNum; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 参数具体数据 | ||
| 32 | + */ | ||
| 33 | + private Map<Byte, Object> params = new LinkedHashMap<>(); | ||
| 34 | + | ||
| 35 | + private static Map<Byte, Byte> sizes; | ||
| 36 | + | ||
| 37 | + static { | ||
| 38 | + AtomicInteger atomicInteger = new AtomicInteger(1); | ||
| 39 | + List<Byte> byteList = Arrays.asList((byte) 2, (byte) 2, (byte) 2, (byte) 1, (byte) 0, (byte) 2, (byte) 5, (byte) 5, (byte) 1, (byte) 2, (byte) 2, (byte) 1, (byte) 1, (byte) 0, (byte) 2, (byte) 1); | ||
| 40 | + sizes = byteList.stream().collect(Collectors.toMap(val -> (byte) atomicInteger.getAndIncrement(), val -> val)); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public static void main(String[] args) { | ||
| 44 | + System.out.println("aaa"); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void read(byte[] bytes) { | ||
| 49 | + // TODO Auto-generated method stub | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public byte[] write() { | ||
| 55 | + // TODO Auto-generated method stub | ||
| 56 | + int len = 0; | ||
| 57 | + for (Map.Entry<Byte, Object> entry : params.entrySet()) { | ||
| 58 | + Byte key = entry.getKey(); | ||
| 59 | + Byte size = sizes.get(entry.getKey()); | ||
| 60 | + if (size == 0) { | ||
| 61 | + size = (Byte) params.get((byte) (key - 1)); | ||
| 62 | + if (size == null) { | ||
| 63 | + throw new RuntimeException("参数设置中参数不符合协议规范"); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + len += size; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + ByteBuffer buf = ByteBuffer.allocate(7 + paramNum + len); | ||
| 70 | + buf.put(ConvertUtil.timestamp2bytes(timestamp)); | ||
| 71 | + buf.put(paramNum); | ||
| 72 | + | ||
| 73 | + for (Map.Entry<Byte, Object> entry : params.entrySet()) { | ||
| 74 | + generateParam(buf, entry.getKey(), entry.getValue()); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + return buf.array(); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + private void generateParam(ByteBuffer buf, Byte type, Object value) { | ||
| 81 | + buf.put(type); | ||
| 82 | + switch (type) { | ||
| 83 | + case 0x01: | ||
| 84 | + case 0x02: | ||
| 85 | + case 0x03: | ||
| 86 | + case 0x06: | ||
| 87 | + case 0x0A: | ||
| 88 | + case 0x0B: | ||
| 89 | + case 0x0F: | ||
| 90 | + buf.putShort((Short) value); | ||
| 91 | + break; | ||
| 92 | + case 0x04: | ||
| 93 | + case 0x09: | ||
| 94 | + case 0x0C: | ||
| 95 | + case 0x0D: | ||
| 96 | + case 0x10: | ||
| 97 | + buf.put((Byte) value); | ||
| 98 | + break; | ||
| 99 | + case 0x05: | ||
| 100 | + case 0x0E: | ||
| 101 | + String val = (String) value; | ||
| 102 | + buf.put(ConvertUtil.string2ascii(val, val.length())); | ||
| 103 | + break; | ||
| 104 | + case 0x07: | ||
| 105 | + case 0x08: | ||
| 106 | + buf.put(ConvertUtil.string2ascii((String) value, 5)); | ||
| 107 | + break; | ||
| 108 | + default: | ||
| 109 | + break; | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public long getTimestamp() { | ||
| 114 | + return timestamp; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @Override | ||
| 118 | + public void setTimestamp(long timestamp) { | ||
| 119 | + this.timestamp = timestamp; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public byte getParamNum() { | ||
| 123 | + return paramNum; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public void setParamNum(byte paramNum) { | ||
| 127 | + this.paramNum = paramNum; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public Map<Byte, Object> getParams() { | ||
| 131 | + return params; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public void setParams(Map<Byte, Object> params) { | ||
| 135 | + this.params = params; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + @Override | ||
| 139 | + public String toString() { | ||
| 140 | + StringBuilder sb = new StringBuilder(); | ||
| 141 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 142 | + .append(" 参数数量:").append(paramNum) | ||
| 143 | + .append(" 参数命令IDS:").append(params.size()); | ||
| 144 | + | ||
| 145 | + return sb.toString(); | ||
| 146 | + } | ||
| 147 | +} |
src/main/java/com/bsth/socket/protocol/Message82.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message82.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import org.joda.time.DateTime; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 车载终端控制 | ||
| 8 | + */ | ||
| 9 | +public class Message82 implements IMessageBody { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * byte[6] | ||
| 13 | + * 数据采集时间 | ||
| 14 | + */ | ||
| 15 | + private long timestamp; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 命令ID | ||
| 19 | + */ | ||
| 20 | + private byte commandId; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 命令参数 | ||
| 24 | + */ | ||
| 25 | + private IMessage82Param message82Param; | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public void read(byte[] bytes) { | ||
| 29 | + // TODO Auto-generated method stub | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public byte[] write() { | ||
| 35 | + // TODO Auto-generated method stub | ||
| 36 | + return new byte[0]; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public long getTimestamp() { | ||
| 40 | + return timestamp; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public void setTimestamp(long timestamp) { | ||
| 45 | + this.timestamp = timestamp; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public byte getCommandId() { | ||
| 49 | + return commandId; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setCommandId(byte commandId) { | ||
| 53 | + this.commandId = commandId; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public IMessage82Param getMessage82Param() { | ||
| 57 | + return message82Param; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setMessage82Param(IMessage82Param message82Param) { | ||
| 61 | + this.message82Param = message82Param; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public String toString() { | ||
| 66 | + StringBuilder sb = new StringBuilder(); | ||
| 67 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 68 | + .append(" 命令ID:").append(String.format("%02x", commandId)) | ||
| 69 | + .append(" 命令参数:").append(message82Param); | ||
| 70 | + | ||
| 71 | + return sb.toString(); | ||
| 72 | + } | ||
| 73 | +} |
src/main/java/com/bsth/socket/protocol/Message82Cmd.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Message82Cmd.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.joda.time.DateTime; | ||
| 5 | + | ||
| 6 | +import java.nio.ByteBuffer; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Hill | ||
| 10 | + * 车载终端控制 | ||
| 11 | + */ | ||
| 12 | +public class Message82Cmd implements IMessageBody { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * byte[6] | ||
| 16 | + * 数据采集时间 | ||
| 17 | + */ | ||
| 18 | + private long timestamp; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 命令ID | ||
| 22 | + */ | ||
| 23 | + private byte commandId; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 命令参数 | ||
| 27 | + */ | ||
| 28 | + private IMessage82Param message82Param; | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public void read(byte[] bytes) { | ||
| 32 | + // TODO Auto-generated method stub | ||
| 33 | + | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public byte[] write() { | ||
| 38 | + // TODO Auto-generated method stub | ||
| 39 | + byte[] bytes = new byte[0]; | ||
| 40 | + if (message82Param != null) { | ||
| 41 | + bytes = message82Param.write(); | ||
| 42 | + } | ||
| 43 | + ByteBuffer buf = ByteBuffer.allocate(7 + bytes.length); | ||
| 44 | + buf.put(ConvertUtil.timestamp2bytes(timestamp)); | ||
| 45 | + buf.put(commandId); | ||
| 46 | + buf.put(bytes); | ||
| 47 | + | ||
| 48 | + return buf.array(); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public long getTimestamp() { | ||
| 52 | + return timestamp; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setTimestamp(long timestamp) { | ||
| 56 | + this.timestamp = timestamp; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public byte getCommandId() { | ||
| 60 | + return commandId; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setCommandId(byte commandId) { | ||
| 64 | + this.commandId = commandId; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public IMessage82Param getMessage82Param() { | ||
| 68 | + return message82Param; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setMessage82Param(IMessage82Param message82Param) { | ||
| 72 | + this.message82Param = message82Param; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + public String toString() { | ||
| 77 | + StringBuilder sb = new StringBuilder(); | ||
| 78 | + sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss")) | ||
| 79 | + .append(" 命令ID:").append(commandId) | ||
| 80 | + .append(" 命令参数:").append(message82Param); | ||
| 81 | + | ||
| 82 | + return sb.toString(); | ||
| 83 | + } | ||
| 84 | +} |
src/main/java/com/bsth/socket/protocol/MessageFactory.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/MessageFactory.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | +import org.slf4j.Logger; | ||
| 5 | +import org.slf4j.LoggerFactory; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author Hill | ||
| 9 | + */ | ||
| 10 | +public class MessageFactory { | ||
| 11 | + | ||
| 12 | + private final static Logger log = LoggerFactory.getLogger(MessageFactory.class); | ||
| 13 | + | ||
| 14 | + public static IMessageBody create(byte commandType, byte[] data) { | ||
| 15 | + String pkgName = MessageFactory.class.getPackage().getName(); | ||
| 16 | + IMessageBody body = null; | ||
| 17 | + try { | ||
| 18 | + boolean cache = false; | ||
| 19 | + if (commandType == 0x03) { | ||
| 20 | + commandType = 0x02; | ||
| 21 | + cache = true; | ||
| 22 | + } | ||
| 23 | + Class<?> cls = Class.forName(pkgName + ".Message" + String.format("%02x", commandType)); | ||
| 24 | + body = (IMessageBody)cls.newInstance(); | ||
| 25 | + body.read(data); | ||
| 26 | + if (cache) { | ||
| 27 | + ((Message02) body).setCache(cache); | ||
| 28 | + } | ||
| 29 | + } catch (Exception e) { | ||
| 30 | + // TODO Auto-generated catch block | ||
| 31 | + log.error("MessageFactory create", e); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + return body; | ||
| 35 | + } | ||
| 36 | +} |
src/main/java/com/bsth/socket/protocol/Param01.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Param01.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import com.bsth.util.ConvertUtil; | ||
| 4 | + | ||
| 5 | +import java.nio.ByteBuffer; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author Hill | ||
| 9 | + * 车载终端控制 | ||
| 10 | + * 0x01 远程升级命令参数 | ||
| 11 | + */ | ||
| 12 | +public class Param01 implements IMessage82Param { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 升级url地址 | ||
| 16 | + */ | ||
| 17 | + private String url; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 拨号点名称 | ||
| 21 | + */ | ||
| 22 | + private String dialName; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 拨号用户名 | ||
| 26 | + */ | ||
| 27 | + private String dialUsername; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 拨号密码 | ||
| 31 | + */ | ||
| 32 | + private String dialPassword; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 地址(IP或域名 实际应该只能用IPV6或IPV4) 6 | ||
| 36 | + * IPV4时前两个字节为0 | ||
| 37 | + */ | ||
| 38 | + private byte[] address = new byte[6]; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 端口 0-65531 | ||
| 42 | + */ | ||
| 43 | + private short port; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 生产厂商代码 4 | ||
| 47 | + * 大写英文字母、数字组合 | ||
| 48 | + */ | ||
| 49 | + private String companyCode; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 硬件版本 5 | ||
| 53 | + */ | ||
| 54 | + private String hardwareVer; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 固件版本 5 | ||
| 58 | + */ | ||
| 59 | + private String firmwareVer; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 连接到升级服务器时限 0-60000 | ||
| 63 | + * 分辨率 1min | ||
| 64 | + * 在时限前应连回远程服务与管理平台 | ||
| 65 | + */ | ||
| 66 | + private short timeLimit; | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public byte[] write() { | ||
| 70 | + byte[] urlBytes = url == null ? new byte[0] : url.getBytes(); | ||
| 71 | + byte[] dialNameBytes = dialName == null ? new byte[0] : dialName.getBytes(); | ||
| 72 | + byte[] dialUsernameBytes = dialUsername == null ? new byte[0] : dialUsername.getBytes(); | ||
| 73 | + byte[] dialPasswordBytes = dialPassword == null ? new byte[0] : dialPassword.getBytes(); | ||
| 74 | + ByteBuffer buf = ByteBuffer.allocate(33 + urlBytes.length + dialNameBytes.length + dialUsernameBytes.length + dialPasswordBytes.length); | ||
| 75 | + buf.put(urlBytes); | ||
| 76 | + buf.putChar(';'); | ||
| 77 | + buf.put(dialNameBytes); | ||
| 78 | + buf.putChar(';'); | ||
| 79 | + buf.put(dialUsernameBytes); | ||
| 80 | + buf.putChar(';'); | ||
| 81 | + buf.put(dialPasswordBytes); | ||
| 82 | + buf.putChar(';'); | ||
| 83 | + buf.put(address); | ||
| 84 | + buf.putShort(port); | ||
| 85 | + buf.put(ConvertUtil.string2ascii(companyCode, 4)); | ||
| 86 | + buf.put(ConvertUtil.string2ascii(hardwareVer, 5)); | ||
| 87 | + buf.put(ConvertUtil.string2ascii(firmwareVer, 5)); | ||
| 88 | + buf.putShort(timeLimit); | ||
| 89 | + | ||
| 90 | + return buf.array(); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public String getUrl() { | ||
| 94 | + return url; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setUrl(String url) { | ||
| 98 | + this.url = url; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public String getDialName() { | ||
| 102 | + return dialName; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void setDialName(String dialName) { | ||
| 106 | + this.dialName = dialName; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public String getDialUsername() { | ||
| 110 | + return dialUsername; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public void setDialUsername(String dialUsername) { | ||
| 114 | + this.dialUsername = dialUsername; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public String getDialPassword() { | ||
| 118 | + return dialPassword; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void setDialPassword(String dialPassword) { | ||
| 122 | + this.dialPassword = dialPassword; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public byte[] getAddress() { | ||
| 126 | + return address; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public void setAddress(byte[] address) { | ||
| 130 | + this.address = address; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public short getPort() { | ||
| 134 | + return port; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setPort(short port) { | ||
| 138 | + this.port = port; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public String getCompanyCode() { | ||
| 142 | + return companyCode; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public void setCompanyCode(String companyCode) { | ||
| 146 | + this.companyCode = companyCode; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public String getHardwareVer() { | ||
| 150 | + return hardwareVer; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public void setHardwareVer(String hardwareVer) { | ||
| 154 | + this.hardwareVer = hardwareVer; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public String getFirmwareVer() { | ||
| 158 | + return firmwareVer; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public void setFirmwareVer(String firmwareVer) { | ||
| 162 | + this.firmwareVer = firmwareVer; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public short getTimeLimit() { | ||
| 166 | + return timeLimit; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public void setTimeLimit(short timeLimit) { | ||
| 170 | + this.timeLimit = timeLimit; | ||
| 171 | + } | ||
| 172 | +} |
src/main/java/com/bsth/socket/protocol/Param06.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/Param06.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +import java.nio.ByteBuffer; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 车载终端控制 | ||
| 8 | + * 0x06 报警/预警命令参数 | ||
| 9 | + */ | ||
| 10 | +public class Param06 implements IMessage82Param { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 警告等级 | ||
| 14 | + * 0x00 无警告 0x01 一级警报 | ||
| 15 | + * 0x02 二级警报 0x03 三级警报(最高) | ||
| 16 | + * 0xFF 无效 | ||
| 17 | + */ | ||
| 18 | + private byte alarmLevel; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 警告信息 | ||
| 22 | + */ | ||
| 23 | + private String alarmMessage; | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public byte[] write() { | ||
| 27 | + byte[] alarmMessageBytes = alarmMessage.getBytes(); | ||
| 28 | + ByteBuffer buf = ByteBuffer.allocate(1 + alarmMessageBytes.length); | ||
| 29 | + buf.put(alarmLevel); | ||
| 30 | + buf.put(alarmMessageBytes); | ||
| 31 | + | ||
| 32 | + return buf.array(); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public byte getAlarmLevel() { | ||
| 36 | + return alarmLevel; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setAlarmLevel(byte alarmLevel) { | ||
| 40 | + this.alarmLevel = alarmLevel; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public String getAlarmMessage() { | ||
| 44 | + return alarmMessage; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setAlarmMessage(String alarmMessage) { | ||
| 48 | + this.alarmMessage = alarmMessage; | ||
| 49 | + } | ||
| 50 | +} |
src/main/java/com/bsth/socket/protocol/ProtocolException.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/socket/protocol/ProtocolException.java | ||
| 1 | +package com.bsth.socket.protocol; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + */ | ||
| 6 | +public class ProtocolException extends RuntimeException { | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | + private static final long serialVersionUID = 1L; | ||
| 12 | + | ||
| 13 | + public ProtocolException(String s) { | ||
| 14 | + super(s); | ||
| 15 | + } | ||
| 16 | +} |
src/main/java/com/bsth/util/AckUtil.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/util/AckUtil.java | ||
| 1 | +package com.bsth.util; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.socket.protocol.Message; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Hill | ||
| 8 | + */ | ||
| 9 | +public class AckUtil { | ||
| 10 | + | ||
| 11 | + public static Message generateAckMessage(Message msg) { | ||
| 12 | + Message ack = new Message(); | ||
| 13 | + // 非命令标志 | ||
| 14 | + if (msg.getAckFlag() == Constant.ACK_FLAG_COMMAND) { | ||
| 15 | + msg.setAckFlag((byte)0x01); | ||
| 16 | + //msg.getMessageBody().setTimestamp(System.currentTimeMillis()); | ||
| 17 | + | ||
| 18 | + return msg; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + return ack; | ||
| 22 | + } | ||
| 23 | +} |
src/main/java/com/bsth/util/AppProperties.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/util/AppProperties.java | ||
| 1 | +package com.bsth.util; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Value; | ||
| 4 | +import org.springframework.stereotype.Component; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author Hill | ||
| 8 | + */ | ||
| 9 | +@Component | ||
| 10 | +public class AppProperties { | ||
| 11 | + | ||
| 12 | + private static int port = 7611; | ||
| 13 | + | ||
| 14 | + private static boolean uprecord; | ||
| 15 | + | ||
| 16 | + private static String updir; | ||
| 17 | + | ||
| 18 | + private static boolean downrecord; | ||
| 19 | + | ||
| 20 | + private static String downdir; | ||
| 21 | + | ||
| 22 | + private static String forwarddevice; | ||
| 23 | + | ||
| 24 | + public static int getPort() { | ||
| 25 | + return port; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Value("${gb.server.port}") | ||
| 29 | + public void setPort(int port) { | ||
| 30 | + AppProperties.port = port; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public static boolean isUprecord() { | ||
| 34 | + return uprecord; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Value("${gb.server.uprecord}") | ||
| 38 | + public void setUprecord(boolean uprecord) { | ||
| 39 | + AppProperties.uprecord = uprecord; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public static String getUpdir() { | ||
| 43 | + return updir; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Value("${gb.server.updir}") | ||
| 47 | + public void setUpdir(String updir) { | ||
| 48 | + AppProperties.updir = updir; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public static boolean isDownrecord() { | ||
| 52 | + return downrecord; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Value("${gb.server.downrecord}") | ||
| 56 | + public void setDownrecord(boolean downrecord) { | ||
| 57 | + AppProperties.downrecord = downrecord; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public static String getDowndir() { | ||
| 61 | + return downdir; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Value("${gb.server.downdir}") | ||
| 65 | + public void setDowndir(String downdir) { | ||
| 66 | + AppProperties.downdir = downdir; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public static String getForwarddevice() { | ||
| 70 | + return forwarddevice; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Value("${gb.server.forwarddevice}") | ||
| 74 | + public void setForwarddevice(String forwarddevice) { | ||
| 75 | + AppProperties.forwarddevice = forwarddevice; | ||
| 76 | + } | ||
| 77 | +} |
src/main/java/com/bsth/util/ConvertUtil.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/util/ConvertUtil.java | ||
| 1 | +package com.bsth.util; | ||
| 2 | + | ||
| 3 | +import java.text.ParseException; | ||
| 4 | +import java.util.Arrays; | ||
| 5 | +import java.util.Calendar; | ||
| 6 | +import java.util.Date; | ||
| 7 | + | ||
| 8 | +import org.joda.time.DateTime; | ||
| 9 | +import org.joda.time.format.DateTimeFormat; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | + | ||
| 13 | +public class ConvertUtil { | ||
| 14 | + | ||
| 15 | + private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class); | ||
| 16 | + | ||
| 17 | + private static int parse(char c) { | ||
| 18 | + if (c >= 'a') { | ||
| 19 | + return c - 'a' + 10 & 0xF; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + if (c >= 'A') { | ||
| 23 | + return c - 'A' + 10 & 0xF; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + return c - '0' & 0xF; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public static String bcd2string(byte[] bytes, int start, int len) { | ||
| 30 | + String temp = ""; | ||
| 31 | + for (int i = 0;i < len;i++) { | ||
| 32 | + int val = bytes[start + i] & 0xff; | ||
| 33 | + if (val < 10) temp += 0; | ||
| 34 | + temp += Integer.toHexString(val); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + return temp; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static byte[] string2bcd(String hexstr) { | ||
| 41 | + int len = hexstr.length() % 2 == 0 ? hexstr.length() / 2 : hexstr.length() / 2 + 1; | ||
| 42 | + byte[] b = new byte[len]; | ||
| 43 | + int j = 0; | ||
| 44 | + | ||
| 45 | + for (int i = 0; i < b.length; i++) { | ||
| 46 | + char c0 = hexstr.charAt(j++); | ||
| 47 | + char c1 = hexstr.charAt(j++); | ||
| 48 | + | ||
| 49 | + b[i] = ((byte) (parse(c0) << 4 | parse(c1))); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return b; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static int bcd2int(byte[] bytes, int start, int len) { | ||
| 56 | + if (len > 4 || len == 0) | ||
| 57 | + throw new IllegalArgumentException("bcd2int 字节数不符合要求"); | ||
| 58 | + String temp = ""; | ||
| 59 | + for (int i = 0;i < len;i++) { | ||
| 60 | + int val = bytes[start + i] & 0xff; | ||
| 61 | + if (val < 10) temp += 0; | ||
| 62 | + temp += Integer.toHexString(val); | ||
| 63 | + } | ||
| 64 | + return Integer.parseInt(temp); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public static byte[] int2bcd(int val, int len) { | ||
| 68 | + if (len > 4 || len == 0) | ||
| 69 | + throw new IllegalArgumentException("int2bcd 字节数不符合要求"); | ||
| 70 | + byte[] result = new byte[len]; | ||
| 71 | + for (int i = len - 1;i > -1;i--) { | ||
| 72 | + result[i] = (byte)Integer.parseInt(val%100 + "", 16); | ||
| 73 | + val = val/100; | ||
| 74 | + } | ||
| 75 | + return result; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public static long bcd2long(byte[] bytes, int start, int len) { | ||
| 79 | + if (len > 8 || len == 0) | ||
| 80 | + throw new IllegalArgumentException("bcd2long 字节数不符合要求"); | ||
| 81 | + String temp = ""; | ||
| 82 | + for (int i = 0;i < len;i++) { | ||
| 83 | + int val = bytes[start + i] & 0xff; | ||
| 84 | + if (val < 10) temp += 0; | ||
| 85 | + temp += Integer.toHexString(val); | ||
| 86 | + } | ||
| 87 | + return Long.parseLong(temp); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public static byte[] long2bcd(long val, int len) { | ||
| 91 | + if (len > 8 || len == 0) | ||
| 92 | + throw new IllegalArgumentException("long2bcd 字节数不符合要求"); | ||
| 93 | + byte[] result = new byte[len]; | ||
| 94 | + for (int i = len - 1;i > -1;i--) { | ||
| 95 | + result[i] = (byte)Integer.parseInt(val%100 + "", 16); | ||
| 96 | + val = val/100; | ||
| 97 | + } | ||
| 98 | + return result; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public static String ascii2string(byte[] bytes, int start, int len) { | ||
| 102 | + return new String(Arrays.copyOfRange(bytes, start, start + len)); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public static byte[] string2ascii(String val, int len) { | ||
| 106 | + byte[] result = new byte[len]; | ||
| 107 | + byte[] bytes = val.getBytes(); | ||
| 108 | + if (bytes.length > len && len != 0) | ||
| 109 | + throw new IllegalArgumentException("string2ascii 参数不符合要求"); | ||
| 110 | + if (len != 0) | ||
| 111 | + for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i]; | ||
| 112 | + else return bytes; | ||
| 113 | + return result; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public static long bcd2timestamp(byte[] bytes, int start) { | ||
| 117 | + String temp = "20"; | ||
| 118 | + for (int i = 0;i < 6;i++) { | ||
| 119 | + int val = bytes[start + i] & 0xff; | ||
| 120 | + if (val < 10) temp += 0; | ||
| 121 | + temp += Integer.toHexString(val); | ||
| 122 | + } | ||
| 123 | + Date date = null; | ||
| 124 | + try { | ||
| 125 | + date = DateTime.parse(temp, DateTimeFormat.forPattern("yyyyMMddHHmmss")).toDate(); | ||
| 126 | + } catch (Exception e) { | ||
| 127 | + log.error("协议中时间数据异常:" + temp); | ||
| 128 | + } | ||
| 129 | + if (date != null) return date.getTime(); | ||
| 130 | + return -1; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public static byte[] timestamp2bcd(long val) { | ||
| 134 | + byte[] result = new byte[6]; | ||
| 135 | + Calendar c = Calendar.getInstance(); | ||
| 136 | + c.setTime(new Date(val)); | ||
| 137 | + result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16)); | ||
| 138 | + result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16)); | ||
| 139 | + result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16); | ||
| 140 | + result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16); | ||
| 141 | + result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16); | ||
| 142 | + result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16); | ||
| 143 | + return result; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public static byte[] int2hex(int val, int len) { | ||
| 147 | + if (len < 1) | ||
| 148 | + throw new IllegalArgumentException("int2hex len 参数不符合要求"); | ||
| 149 | + byte[] result = new byte[len]; | ||
| 150 | + for (int i = 0;i < len;i++) { | ||
| 151 | + result[len - 1 - i] = (byte)(val%100); | ||
| 152 | + val = val/100; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + return result; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public static long bytes2timestamp(byte[] bytes, int start) { | ||
| 159 | + StringBuilder temp = new StringBuilder("20"); | ||
| 160 | + for (int i = 0;i < 6;i++) { | ||
| 161 | + int val = bytes[start + i] & 0xff; | ||
| 162 | + if (val < 10) { temp.append(0); } | ||
| 163 | + temp.append(val); | ||
| 164 | + } | ||
| 165 | + Date date = null; | ||
| 166 | + try { | ||
| 167 | + date = DateTime.parse(temp.toString(), DateTimeFormat.forPattern("yyyyMMddHHmmss")).toDate(); | ||
| 168 | + } catch (Exception e) { | ||
| 169 | + log.error("协议中时间数据异常:" + temp); | ||
| 170 | + } | ||
| 171 | + if (date != null) { return date.getTime(); } | ||
| 172 | + | ||
| 173 | + return -1; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public static byte[] timestamp2bytes(long val) { | ||
| 177 | + byte[] result = new byte[6]; | ||
| 178 | + Calendar c = Calendar.getInstance(); | ||
| 179 | + c.setTime(new Date(val)); | ||
| 180 | + result[0] = (byte)(c.get(Calendar.YEAR)%100); | ||
| 181 | + result[1] = (byte)(c.get(Calendar.MONTH) + 1); | ||
| 182 | + result[2] = (byte)c.get(Calendar.DAY_OF_MONTH); | ||
| 183 | + result[3] = (byte)c.get(Calendar.HOUR_OF_DAY); | ||
| 184 | + result[4] = (byte)c.get(Calendar.MINUTE); | ||
| 185 | + result[5] = (byte)c.get(Calendar.SECOND); | ||
| 186 | + | ||
| 187 | + return result; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public static int bytes2int(byte[] bytes, int start, int len) { | ||
| 191 | + if (len > 4) { throw new IllegalArgumentException("bytes2int len 参数不符合要求"); } | ||
| 192 | + if (len == 0) { len = 4; } | ||
| 193 | + int result = 0; | ||
| 194 | + for (int i = 0;i < len;i++) { | ||
| 195 | + result += (bytes[start + i] & 0xff) << (len - i - 1) * 8; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + return result; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + public static String toHexString(byte[] bytes) { | ||
| 202 | + StringBuilder sb = new StringBuilder(); | ||
| 203 | + for (byte b : bytes) { | ||
| 204 | + sb.append(String.format("0x%02x ", b)); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + return sb.toString(); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + public static void main(String args[]) { | ||
| 211 | + for (byte b : int2hex(2231605, 4)){ | ||
| 212 | + System.out.println(b); | ||
| 213 | + } | ||
| 214 | + } | ||
| 215 | +} |
src/main/java/com/bsth/util/CrcUtil.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/util/CrcUtil.java | ||
| 1 | +package com.bsth.util; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + */ | ||
| 6 | +public class CrcUtil { | ||
| 7 | + | ||
| 8 | + public static byte bbc(byte[] bytes, int start, int end) { | ||
| 9 | + if (start > end) { | ||
| 10 | + throw new IllegalArgumentException("无效的参数"); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + byte crc = 0; | ||
| 14 | + for (int i = start;i <= end;i++) { | ||
| 15 | + crc ^= bytes[i]; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + return crc; | ||
| 19 | + } | ||
| 20 | +} |
src/main/java/com/bsth/util/ProtocolConverter.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/util/ProtocolConverter.java | ||
| 1 | +package com.bsth.util; | ||
| 2 | + | ||
| 3 | +import com.bsth.entity.AlarmData; | ||
| 4 | +import com.bsth.entity.Data; | ||
| 5 | +import com.bsth.entity.PeakData; | ||
| 6 | +import com.bsth.entity.VehicleData; | ||
| 7 | +import com.bsth.socket.protocol.*; | ||
| 8 | + | ||
| 9 | +import java.util.HashMap; | ||
| 10 | +import java.util.LinkedHashMap; | ||
| 11 | +import java.util.Map; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * @author Hill | ||
| 15 | + */ | ||
| 16 | +public class ProtocolConverter { | ||
| 17 | + | ||
| 18 | + public static Map<String, Object> convert(Message message) { | ||
| 19 | + Map<String, Object> result = new LinkedHashMap<>(); | ||
| 20 | + IMessageBody messageBody = message.getMessageBody(); | ||
| 21 | + | ||
| 22 | + if (messageBody instanceof Message02) { | ||
| 23 | + for (IMessageBody02 messageBody02 : ((Message02) messageBody).getBody02List()) { | ||
| 24 | + Data data = convert(messageBody02); | ||
| 25 | + if (data != null) { | ||
| 26 | + result.put(data.getType(), data); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + if (result.size() > 0) { | ||
| 31 | + result.put("vin", message.getVin()); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + return result; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public static Data convert(IMessageBody02 messageBody02) { | ||
| 39 | + | ||
| 40 | + if (messageBody02 instanceof Message0201) { | ||
| 41 | + return new VehicleData((Message0201) messageBody02); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + if (messageBody02 instanceof Message0206) { | ||
| 45 | + return new PeakData((Message0206) messageBody02); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + if (messageBody02 instanceof Message0207) { | ||
| 49 | + return new AlarmData((Message0207) messageBody02); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return null; | ||
| 53 | + } | ||
| 54 | +} |
src/main/java/com/bsth/web/BasicDataController.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/web/BasicDataController.java | ||
| 1 | +package com.bsth.web; | ||
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.stereotype.Controller; | ||
| 10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 11 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 12 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
| 13 | + | ||
| 14 | +import com.bsth.service.BasicDataService; | ||
| 15 | + | ||
| 16 | +//@Controller | ||
| 17 | +@RequestMapping("/basic/*") | ||
| 18 | +public class BasicDataController { | ||
| 19 | + | ||
| 20 | + private final static Logger log = LoggerFactory.getLogger(BasicDataController.class); | ||
| 21 | + | ||
| 22 | + @Autowired | ||
| 23 | + private BasicDataService basicDataService; | ||
| 24 | + | ||
| 25 | + @RequestMapping(value = "/refresh") | ||
| 26 | + public @ResponseBody Map<String, Object> refresh(@RequestParam Map<String, Object> map) { | ||
| 27 | + Map<String, Object> result = new HashMap<String, Object>(); | ||
| 28 | + try { | ||
| 29 | + basicDataService.loadBasicData(); | ||
| 30 | + result.put("errCode", 0); | ||
| 31 | + } catch (Exception e) { | ||
| 32 | + result.put("errCode", 1); | ||
| 33 | + result.put("errMsg", "刷新基础数据异常"); | ||
| 34 | + log.error("刷新基础数据异常", e); | ||
| 35 | + } | ||
| 36 | + return result; | ||
| 37 | + } | ||
| 38 | +} |
src/main/java/com/bsth/web/MessageController.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/web/MessageController.java | ||
| 1 | +package com.bsth.web; | ||
| 2 | + | ||
| 3 | +import com.bsth.constant.Constant; | ||
| 4 | +import com.bsth.socket.manager.MessageSender; | ||
| 5 | +import com.bsth.socket.protocol.Message80Cmd; | ||
| 6 | +import com.bsth.socket.protocol.Message; | ||
| 7 | +import com.bsth.service.MessageService; | ||
| 8 | +import com.bsth.socket.protocol.Message81Cmd; | ||
| 9 | +import com.bsth.util.ConvertUtil; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | +import org.springframework.stereotype.Controller; | ||
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 16 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
| 17 | + | ||
| 18 | +import javax.servlet.http.HttpServletRequest; | ||
| 19 | +import java.io.IOException; | ||
| 20 | +import java.io.InputStream; | ||
| 21 | +import java.util.HashMap; | ||
| 22 | +import java.util.Map; | ||
| 23 | + | ||
| 24 | +@Controller | ||
| 25 | +@RequestMapping("/message/*") | ||
| 26 | +public class MessageController { | ||
| 27 | + | ||
| 28 | + private final static Logger log = LoggerFactory.getLogger(MessageController.class); | ||
| 29 | + @Autowired | ||
| 30 | + private MessageService messageService; | ||
| 31 | + | ||
| 32 | + @SuppressWarnings("unchecked") | ||
| 33 | + @RequestMapping(value = "/", method = RequestMethod.GET) | ||
| 34 | + public @ResponseBody Map<String, Object> down(HttpServletRequest request) { | ||
| 35 | + Map<String, Object> res = new HashMap<String, Object>(); | ||
| 36 | + InputStream in = null; | ||
| 37 | + Map<String, Object> param = null; | ||
| 38 | + try { | ||
| 39 | + /*in = request.getInputStream(); | ||
| 40 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 41 | + IOUtils.copy(in, bout); | ||
| 42 | + param = new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 43 | + log.info(param == null ? "null" : param.toString()); | ||
| 44 | + log.info(new String(bout.toByteArray(), "GBK"));*/ | ||
| 45 | + Message message = new Message(); | ||
| 46 | + Message80Cmd traffic80Cmd = new Message80Cmd(); | ||
| 47 | + message.setCommand((byte) 0x80); | ||
| 48 | + message.setAckFlag(Constant.ACK_FLAG_COMMAND); | ||
| 49 | + message.setVin("12345678901234567"); | ||
| 50 | + message.setEncryption((byte) 1); | ||
| 51 | + message.setMessageBody(traffic80Cmd); | ||
| 52 | + traffic80Cmd.setTimestamp(System.currentTimeMillis()); | ||
| 53 | + traffic80Cmd.setParamNum((byte)16); | ||
| 54 | + byte[] paramIds = new byte[16]; | ||
| 55 | + for (int i = 0;i < paramIds.length;i++) { | ||
| 56 | + paramIds[i] = (byte) (i + 1); | ||
| 57 | + } | ||
| 58 | + traffic80Cmd.setParamIds(paramIds); | ||
| 59 | + System.out.println("0x80cmd: " + ConvertUtil.toHexString(message.write())); | ||
| 60 | + MessageSender.getInstance().send(message); | ||
| 61 | + } catch (Exception e) { | ||
| 62 | + // TODO Auto-generated catch block | ||
| 63 | + log.error(param == null ? "null" : param.toString()); | ||
| 64 | + log.error("消息下发异常", e); | ||
| 65 | + res.put("errCode", 1); | ||
| 66 | + res.put("errMsg", "服务端错误"); | ||
| 67 | + } finally { | ||
| 68 | + try { | ||
| 69 | + if (in != null) in.close(); | ||
| 70 | + } catch (IOException e) { | ||
| 71 | + // TODO Auto-generated catch block | ||
| 72 | + log.error("", e); | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + log.info(res.toString()); | ||
| 76 | + return res; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @RequestMapping(value = "/81", method = RequestMethod.GET) | ||
| 80 | + public @ResponseBody Map<String, Object> down81(HttpServletRequest request) { | ||
| 81 | + Map<String, Object> res = new HashMap<String, Object>(); | ||
| 82 | + InputStream in = null; | ||
| 83 | + Map<String, Object> param = null; | ||
| 84 | + try { | ||
| 85 | + Message message = new Message(); | ||
| 86 | + Message81Cmd traffic81Cmd = new Message81Cmd(); | ||
| 87 | + message.setCommand((byte) 0x81); | ||
| 88 | + message.setAckFlag(Constant.ACK_FLAG_COMMAND); | ||
| 89 | + message.setVin("12345678901234567"); | ||
| 90 | + message.setEncryption((byte) 1); | ||
| 91 | + message.setMessageBody(traffic81Cmd); | ||
| 92 | + traffic81Cmd.setTimestamp(System.currentTimeMillis()); | ||
| 93 | + traffic81Cmd.getParams().put((byte) 1, (short) 500); | ||
| 94 | + traffic81Cmd.getParams().put((byte) 2, (short) 20); | ||
| 95 | + traffic81Cmd.getParams().put((byte) 3, (short) 10000); | ||
| 96 | + //traffic81Cmd.getParams().put((byte) 5, "11111111111111111111"); | ||
| 97 | + traffic81Cmd.getParams().put((byte) 9, (byte) 30); | ||
| 98 | + traffic81Cmd.setParamNum((byte) traffic81Cmd.getParams().size()); | ||
| 99 | + System.out.println("0x81cmd: " + ConvertUtil.toHexString(message.write())); | ||
| 100 | + MessageSender.getInstance().send(message); | ||
| 101 | + } catch (Exception e) { | ||
| 102 | + // TODO Auto-generated catch block | ||
| 103 | + log.error(param == null ? "null" : param.toString()); | ||
| 104 | + log.error("消息下发异常", e); | ||
| 105 | + res.put("errCode", 1); | ||
| 106 | + res.put("errMsg", "服务端错误"); | ||
| 107 | + } finally { | ||
| 108 | + try { | ||
| 109 | + if (in != null) in.close(); | ||
| 110 | + } catch (IOException e) { | ||
| 111 | + // TODO Auto-generated catch block | ||
| 112 | + log.error("", e); | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + log.info(res.toString()); | ||
| 116 | + return res; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @RequestMapping(value = "/up", method = RequestMethod.GET) | ||
| 120 | + public @ResponseBody Map<String, Object> up(HttpServletRequest request) { | ||
| 121 | + messageService.up(null); | ||
| 122 | + return new HashMap<>(); | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | + |
src/main/java/com/bsth/web/SessionController.java
0 → 100644
| 1 | +++ a/src/main/java/com/bsth/web/SessionController.java | ||
| 1 | +package com.bsth.web; | ||
| 2 | + | ||
| 3 | +import java.net.InetSocketAddress; | ||
| 4 | +import java.util.ArrayList; | ||
| 5 | +import java.util.HashMap; | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | +import org.apache.mina.core.session.IoSession; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.stereotype.Controller; | ||
| 13 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 16 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
| 17 | + | ||
| 18 | +import com.bsth.socket.manager.MessageSessionManager; | ||
| 19 | + | ||
| 20 | +@Controller | ||
| 21 | +@RequestMapping("/session/*") | ||
| 22 | +public class SessionController { | ||
| 23 | + | ||
| 24 | + private final static Logger log = LoggerFactory.getLogger(SessionController.class); | ||
| 25 | + | ||
| 26 | + @RequestMapping(value = "/") | ||
| 27 | + public @ResponseBody List<Map<String, Object>> allSession() { | ||
| 28 | + List<Map<String, Object>> result = new ArrayList<>(); | ||
| 29 | + try { | ||
| 30 | + List<IoSession> sessions = MessageSessionManager.getInstance().getAllSession(); | ||
| 31 | + if (sessions != null) { | ||
| 32 | + for (IoSession session : sessions) { | ||
| 33 | + Map<String, Object> map = new HashMap<>(); | ||
| 34 | + InetSocketAddress remoteAddr = (InetSocketAddress)session.getRemoteAddress(); | ||
| 35 | + InetSocketAddress localAddr = (InetSocketAddress)session.getLocalAddress(); | ||
| 36 | + | ||
| 37 | + map.put("deviceId", session.getAttribute("deviceId")); | ||
| 38 | + map.put("remoteAddr", remoteAddr.getAddress().getHostAddress() + ":" + remoteAddr.getPort()); | ||
| 39 | + map.put("localAddr", localAddr.getAddress().getHostAddress() + ":" + localAddr.getPort()); | ||
| 40 | + map.put("isActive", session.isActive()); | ||
| 41 | + map.put("lastIoTime", session.getLastIoTime()); | ||
| 42 | + result.add(map); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + } catch (Exception e) { | ||
| 46 | + log.error("获取所有设备会话数据异常", e); | ||
| 47 | + } | ||
| 48 | + return result; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @RequestMapping(value = "/{deviceId}") | ||
| 52 | + public @ResponseBody Map<String, Object> session(@RequestParam Map<String, Object> map, @PathVariable("deviceId") String deviceId) { | ||
| 53 | + Map<String, Object> result = new HashMap<String, Object>(); | ||
| 54 | + try { | ||
| 55 | + IoSession session = MessageSessionManager.getInstance().getSession(deviceId); | ||
| 56 | + result.put("errCode", 0); | ||
| 57 | + if (session != null) { | ||
| 58 | + InetSocketAddress remoteAddr = (InetSocketAddress)session.getRemoteAddress(); | ||
| 59 | + InetSocketAddress localAddr = (InetSocketAddress)session.getLocalAddress(); | ||
| 60 | + | ||
| 61 | + result.put("deviceId", deviceId); | ||
| 62 | + map.put("remoteAddr", remoteAddr.getAddress().getHostAddress() + ":" + remoteAddr.getPort()); | ||
| 63 | + map.put("localAddr", localAddr.getAddress().getHostAddress() + ":" + localAddr.getPort()); | ||
| 64 | + result.put("isActive", session.isActive()); | ||
| 65 | + result.put("lastIoTime", session.getLastIoTime()); | ||
| 66 | + } | ||
| 67 | + } catch (Exception e) { | ||
| 68 | + result.put("errCode", 1); | ||
| 69 | + result.put("errMsg", "获取设备会话数据异常"); | ||
| 70 | + log.error("获取设备会话数据异常", e); | ||
| 71 | + } | ||
| 72 | + return result; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @RequestMapping(value = "/offline/{deviceId}") | ||
| 76 | + public @ResponseBody Map<String, Object> offline(@RequestParam Map<String, Object> map, @PathVariable("deviceId") String deviceId) { | ||
| 77 | + Map<String, Object> result = new HashMap<String, Object>(); | ||
| 78 | + try { | ||
| 79 | + IoSession session = MessageSessionManager.getInstance().getSession(deviceId); | ||
| 80 | + result.put("errCode", 0); | ||
| 81 | + if (session != null) { | ||
| 82 | + result.put("deviceId", deviceId); | ||
| 83 | + result.put("errMsg", "掉线"); | ||
| 84 | + session.closeNow(); | ||
| 85 | + } | ||
| 86 | + } catch (Exception e) { | ||
| 87 | + result.put("errCode", 1); | ||
| 88 | + result.put("errMsg", "获取设备会话数据异常"); | ||
| 89 | + log.error("刷新基础数据异常", e); | ||
| 90 | + } | ||
| 91 | + return result; | ||
| 92 | + } | ||
| 93 | +} |
src/main/resources/application-dev.properties
0 → 100644
| 1 | +++ a/src/main/resources/application-dev.properties | ||
| 1 | +#DATABASE | ||
| 2 | +spring.jpa.database= MYSQL | ||
| 3 | +spring.jpa.show-sql= true | ||
| 4 | +spring.datasource.control.driver-class-name= com.mysql.cj.jdbc.Driver | ||
| 5 | +spring.datasource.control.jdbc-url= jdbc:mysql://10.10.150.103/control?useUnicode=true&characterEncoding=utf-8 | ||
| 6 | +spring.datasource.control.username= root | ||
| 7 | +spring.datasource.control.password= Aa123456 | ||
| 8 | +#DATASOURCE | ||
| 9 | +spring.datasource.control.max-active=100 | ||
| 10 | +spring.datasource.control.max-idle=8 | ||
| 11 | +spring.datasource.control.min-idle=8 | ||
| 12 | +spring.datasource.control.initial-size=5 | ||
| 13 | + | ||
| 14 | +spring.datasource.control.test-on-borrow=true | ||
| 15 | +spring.datasource.control.test-on-connect=true | ||
| 16 | +spring.datasource.control.test-on-return=true | ||
| 17 | +spring.datasource.control.test-while-idle=true | ||
| 18 | +spring.datasource.control.validation-query=select 1 | ||
| 19 | + | ||
| 20 | +spring.datasource.ms.hikari.driver-class-name= com.mysql.cj.jdbc.Driver | ||
| 21 | +spring.datasource.ms.jdbc-url= jdbc:mysql://10.10.150.103/ms?useUnicode=true&characterEncoding=utf-8 | ||
| 22 | +spring.datasource.ms.username= root | ||
| 23 | +spring.datasource.ms.password= Aa123456 | ||
| 24 | +#DATASOURCE | ||
| 25 | +spring.datasource.ms.max-active=100 | ||
| 26 | +spring.datasource.ms.max-idle=8 | ||
| 27 | +spring.datasource.ms.min-idle=8 | ||
| 28 | +spring.datasource.ms.initial-size=5 | ||
| 29 | + | ||
| 30 | +spring.datasource.ms.test-on-borrow=true | ||
| 31 | +spring.datasource.ms.test-on-connect=true | ||
| 32 | +spring.datasource.ms.test-on-return=true | ||
| 33 | +spring.datasource.ms.test-while-idle=true | ||
| 34 | +spring.datasource.ms.validation-query=select 1 | ||
| 0 | \ No newline at end of file | 35 | \ No newline at end of file |
src/main/resources/application.properties
0 → 100644
| 1 | +++ a/src/main/resources/application.properties | ||
| 1 | +spring.profiles.active= dev | ||
| 2 | + | ||
| 3 | +spring.kafka.bootstrap-servers= 10.10.200.203:9092 | ||
| 4 | +spring.kafka.producer.key-serializer= org.apache.kafka.common.serialization.StringSerializer | ||
| 5 | +spring.kafka.producer.value-serializer= org.apache.kafka.common.serialization.StringSerializer | ||
| 6 | +spring.kafka.producer.buffer-memory= 33554432 | ||
| 7 | +spring.kafka.producer.acks= all | ||
| 8 | + | ||
| 9 | +gb.server.port= 7611 | ||
| 10 | +gb.server.uprecord= true | ||
| 11 | +gb.server.updir= /home/control/protocol_32960/up/ | ||
| 12 | +gb.server.downrecord= true | ||
| 13 | +gb.server.downdir= /home/control/protocol_32960/down/ | ||
| 14 | +gb.server.forwarddevice= client | ||
| 0 | \ No newline at end of file | 15 | \ No newline at end of file |
src/main/resources/logback.xml
0 → 100644
| 1 | +++ a/src/main/resources/logback.xml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd"> --> | ||
| 3 | +<configuration> | ||
| 4 | + | ||
| 5 | + <!-- <property resource="application.properties" /> --> | ||
| 6 | + <property name="LOG_BASE" value="E:/logs_gb32960" /> | ||
| 7 | + <!-- 控制台输出 --> | ||
| 8 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| 9 | + | ||
| 10 | + <layout class="ch.qos.logback.classic.PatternLayout"> | ||
| 11 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> | ||
| 12 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | ||
| 13 | + </pattern> | ||
| 14 | + </layout> | ||
| 15 | + </appender> | ||
| 16 | + | ||
| 17 | + <!-- 主日志文件 --> | ||
| 18 | + <appender name="FILE" | ||
| 19 | + class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| 20 | + <file>${LOG_BASE}/main/main.log</file> | ||
| 21 | + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| 22 | + <fileNamePattern>${LOG_BASE}/main/main-%d{yyyy-MM-dd}.%i.log</fileNamePattern> | ||
| 23 | + <timeBasedFileNamingAndTriggeringPolicy | ||
| 24 | + class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> | ||
| 25 | + <maxFileSize>100MB</maxFileSize> | ||
| 26 | + </timeBasedFileNamingAndTriggeringPolicy> | ||
| 27 | + </rollingPolicy> | ||
| 28 | + <encoder> | ||
| 29 | + <pattern>%msg%n</pattern> | ||
| 30 | + </encoder> | ||
| 31 | + | ||
| 32 | + <layout class="ch.qos.logback.classic.PatternLayout"> | ||
| 33 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> | ||
| 34 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | ||
| 35 | + </pattern> | ||
| 36 | + </layout> | ||
| 37 | + </appender> | ||
| 38 | + | ||
| 39 | + <!-- 日志输出级别 --> | ||
| 40 | + <root level="info"> | ||
| 41 | + <appender-ref ref="STDOUT" /> | ||
| 42 | + <appender-ref ref="FILE" /> | ||
| 43 | + </root> | ||
| 44 | +</configuration> | ||
| 0 | \ No newline at end of file | 45 | \ No newline at end of file |
src/main/webapp/WEB-INF/web.xml
0 → 100644
| 1 | +++ a/src/main/webapp/WEB-INF/web.xml | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<web-app version="3.0" | ||
| 3 | + xmlns="http://java.sun.com/xml/ns/javaee" | ||
| 4 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 5 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | ||
| 6 | + http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> | ||
| 7 | + | ||
| 8 | + <listener> | ||
| 9 | + <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | ||
| 10 | + </listener> | ||
| 11 | + <context-param> | ||
| 12 | + <param-name>contextConfigLocation</param-name> | ||
| 13 | + <param-value> | ||
| 14 | + classpath:spring-application.xml; | ||
| 15 | +<!-- classpath:spring-quartz.xml; --> | ||
| 16 | + </param-value> | ||
| 17 | + </context-param> | ||
| 18 | + <filter> | ||
| 19 | + <filter-name>encode</filter-name> | ||
| 20 | + <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> | ||
| 21 | + <init-param> | ||
| 22 | + <param-name>encoding</param-name> | ||
| 23 | + <param-value>UTF-8</param-value> | ||
| 24 | + </init-param> | ||
| 25 | + <init-param> | ||
| 26 | + <param-name>forceEncoding</param-name> | ||
| 27 | + <param-value>true</param-value> | ||
| 28 | + </init-param> | ||
| 29 | + </filter> | ||
| 30 | + <filter-mapping> | ||
| 31 | + <filter-name>encode</filter-name> | ||
| 32 | + <url-pattern>/*</url-pattern> | ||
| 33 | + </filter-mapping> | ||
| 34 | + <servlet> | ||
| 35 | + <servlet-name>springmvc</servlet-name> | ||
| 36 | + <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | ||
| 37 | + <init-param> | ||
| 38 | + <param-name>contextConfigLocation</param-name> | ||
| 39 | + <param-value>classpath:spring-servlet.xml</param-value> | ||
| 40 | + </init-param> | ||
| 41 | + <load-on-startup>1</load-on-startup> | ||
| 42 | + </servlet> | ||
| 43 | + <servlet-mapping> | ||
| 44 | + <servlet-name>springmvc</servlet-name> | ||
| 45 | + <url-pattern>/*</url-pattern> | ||
| 46 | + </servlet-mapping> | ||
| 47 | + <display-name></display-name> | ||
| 48 | + <welcome-file-list> | ||
| 49 | + <welcome-file>index.jsp</welcome-file> | ||
| 50 | + </welcome-file-list> | ||
| 51 | +</web-app> |