GithubHelp home page GithubHelp logo

dataguru's Introduction

本工程用Intellij Idea开发,采用Maven构建工具,运行环境JDK1.7,源程序位于src/main/java 中,测试代码位于src/test/java中,测试用例 src\test\java\dataguru\codec\reader\DecodeTest.java 与 src\test\java\dataguru\codec\reader\ReaderTest.java,测试数据src\test\resources

数据源读取位于 src\main\java\dataguru\codec\reader NmeaObject位于 src\main\java\dataguru\codec\message 编解码器位于 src\main\java\dataguru\codec\manager 封装语句解析位于 src\main\java\dataguru\codec\sentence

读取参数语句进行解析 Readers读取数据后调用CodecManager解析,判断不同语句使用工厂CodecFactory调用不同解析器解析,解析完后使用观察者模式返回给观察者结果 AbstractDataSource reader = Readers.createReaderFromFile("src/test/resources/small_example.txt"); reader.setPacketHandler(new Consumer() { @Override public void accept(String str) { System.out.println(str); } }); reader.start(); reader.join();

封装语句读取解析 读取数据后,使用SentenceLine分析语句,使用Vdm分析语句是否结束,如果结束返回解析数据,创建一个新的Vdm解析数据; 如果未结束,用当前Vdm继续分析后面的数据 // Open file URL url = ClassLoader.getSystemResource("stream_example.txt"); Assert.assertNotNull(url); try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) { Assert.assertNotNull(in); String line;

        // Prepare message classes

// AisMessage message; Vdm vdm = new Vdm();

        while ((line = in.readLine()) != null) {

            // Ignore everything else than sentences
            if (!line.startsWith("$") && !line.startsWith("!")) {
                continue;
            }


            // Handle VDM/VDO line
            try {
                int result = vdm.parse(new SentenceLine(line));
                // LOG.info("result = " + result);
                if (result == 0) {
                    LOG.info(vdm.getBinArray().toString());

                    // Message ready for handling

                } else if (result == 1) {
                    LOG.info("wait for more data");
                    // Wait for more data
                    continue;
                } else {
                    LOG.error("Failed to parse line: " + line + " result = " + result);
                    Assert.assertTrue(false);
                }

            } catch (Exception e) {
                LOG.info("VDM failed: " + e.getMessage() + " line: " + line  );
                Assert.assertTrue(false);
            }

            // Create new VDM
            vdm = new Vdm();

// tags.clear(); } }

dataguru's People

Contributors

lgj573 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.