├── .gitattributes ├── README ├── README.md ├── README1 ├── __pycache__ ├── sparkplug_b.cpython-36.pyc └── sparkplug_b_pb2.cpython-36.pyc ├── client_libraries ├── c │ ├── Makefile │ ├── include │ │ ├── pb.h │ │ ├── pb_common.h │ │ ├── pb_decode.h │ │ ├── pb_encode.h │ │ ├── tahu.h │ │ └── tahu.pb.h │ ├── readme.txt │ ├── src │ │ ├── pb_common.c │ │ ├── pb_decode.c │ │ ├── pb_encode.c │ │ ├── tahu.c │ │ ├── tahu.pb │ │ ├── tahu.pb.c │ │ └── tahu.pb.h │ ├── tahu.options │ ├── test.sh │ └── test │ │ ├── .gitignore │ │ └── test.c ├── c_sharp │ ├── readme.txt │ └── src │ │ └── SparkplugBCSharp.cs ├── java │ ├── pom.xml │ ├── readme.txt │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── eclipse │ │ │ │ └── tahu │ │ │ │ ├── SparkplugException.java │ │ │ │ ├── SparkplugInvalidTypeException.java │ │ │ │ ├── SparkplugParsingException.java │ │ │ │ ├── json │ │ │ │ ├── DataSetDeserializer.java │ │ │ │ ├── DeserializerModifier.java │ │ │ │ ├── DeserializerModule.java │ │ │ │ ├── FileSerializer.java │ │ │ │ ├── JsonValidator.java │ │ │ │ └── MetricDeserializer.java │ │ │ │ ├── message │ │ │ │ ├── PayloadDecoder.java │ │ │ │ ├── PayloadEncoder.java │ │ │ │ ├── SparkplugBPayloadDecoder.java │ │ │ │ ├── SparkplugBPayloadEncoder.java │ │ │ │ └── model │ │ │ │ │ ├── DataSet.java │ │ │ │ │ ├── DataSetDataType.java │ │ │ │ │ ├── File.java │ │ │ │ │ ├── Message.java │ │ │ │ │ ├── MessageType.java │ │ │ │ │ ├── MetaData.java │ │ │ │ │ ├── Metric.java │ │ │ │ │ ├── MetricDataType.java │ │ │ │ │ ├── Parameter.java │ │ │ │ │ ├── ParameterDataType.java │ │ │ │ │ ├── PropertyDataType.java │ │ │ │ │ ├── PropertySet.java │ │ │ │ │ ├── PropertyValue.java │ │ │ │ │ ├── Row.java │ │ │ │ │ ├── SparkplugBPayload.java │ │ │ │ │ ├── Template.java │ │ │ │ │ ├── Topic.java │ │ │ │ │ └── Value.java │ │ │ │ ├── protobuf │ │ │ │ └── SparkplugBProto.java │ │ │ │ └── util │ │ │ │ ├── CompressionAlgorithm.java │ │ │ │ ├── GZipUtil.java │ │ │ │ ├── MessageUtil.java │ │ │ │ ├── PayloadUtil.java │ │ │ │ ├── TopicUtil.java │ │ │ │ └── ValidationUtils.java │ │ └── resources │ │ │ └── payload.json │ │ └── test │ │ └── java │ │ └── org │ │ └── eclipse │ │ └── tahu │ │ ├── test │ │ └── SparkplugTest.java │ │ └── util │ │ └── PayloadUtilTest.java ├── javascript │ ├── node-red-contrib-sparkplug │ │ ├── README.md │ │ ├── package.json │ │ └── sparkplug │ │ │ ├── sparkplug.html │ │ │ └── sparkplug.js │ ├── sparkplug-client │ │ ├── LICENSE │ │ ├── README.md │ │ ├── index.js │ │ └── package.json │ └── sparkplug-payload │ │ ├── README.md │ │ ├── index.js │ │ ├── lib │ │ └── sparkplugbpayload.js │ │ └── package.json └── python │ ├── __init__.py │ ├── __pycache__ │ ├── sparkplug_b.cpython-36.pyc │ └── sparkplug_b_pb2.cpython-36.pyc │ ├── readme.txt │ ├── sparkplug_b.py │ ├── sparkplug_b.pyc │ ├── sparkplug_b_pb2.py │ └── sparkplug_b_pb2.pyc ├── common ├── FPS.py ├── __init__.py ├── __init__.pyc ├── __pycache__ │ ├── FPS.cpython-36.pyc │ ├── __init__.cpython-36.pyc │ ├── bus_call.cpython-36.pyc │ ├── is_aarch_64.cpython-36.pyc │ └── utils.cpython-36.pyc ├── bus_call.py ├── bus_call.pyc ├── is_aarch_64.py ├── is_aarch_64.pyc └── utils.py ├── config_infer_primary_yoloV2.txt ├── config_infer_primary_yoloV2_tiny.txt ├── config_infer_primary_yoloV3.txt ├── config_infer_primary_yoloV3_tiny.txt ├── config_infer_primary_yoloV3x.txt ├── darknet_19.trt ├── deepstream_app_config_yoloV2.txt ├── deepstream_app_config_yoloV2_tiny.txt ├── deepstream_app_config_yoloV3.txt ├── deepstream_app_config_yoloV3_tiny.txt ├── deepstream_ignition_IP_File_rtsp_yolo.py ├── deepstream_ignition_IP_File_yolo.py ├── deepstream_ignition_usb_rtsp_yolo.py ├── deepstream_ignition_usb_yolo.py ├── dstest1_pgie_config.txt ├── dstest1_pgie_config_rtsp.txt ├── labels.txt ├── nvdsinfer_custom_impl_Yolo ├── Makefile ├── kernels.cu ├── kernels.o ├── libnvdsinfer_custom_impl_Yolo.so ├── nvdsinfer_yolo_engine.cpp ├── nvdsinfer_yolo_engine.o ├── nvdsparsebbox_Yolo.cpp ├── nvdsparsebbox_Yolo.o ├── trt_utils.cpp ├── trt_utils.h ├── trt_utils.o ├── yolo.cpp ├── yolo.h ├── yolo.o ├── yoloPlugins.cpp ├── yoloPlugins.h └── yoloPlugins.o ├── nx_2021-01-29_1525.zip ├── prebuild.sh ├── sparkplug_b.py ├── sparkplug_b.pyc ├── sparkplug_b ├── raspberry_pi_examples │ ├── java │ │ ├── THIRD-PARTY.txt │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── eclipse │ │ │ │ └── tahu │ │ │ │ ├── SparkplugRaspberryPiExample.java │ │ │ │ ├── pi │ │ │ │ ├── dio │ │ │ │ │ ├── DigitalOutputPin.java │ │ │ │ │ ├── DioException.java │ │ │ │ │ ├── DioLibrary.java │ │ │ │ │ ├── DioPin.java │ │ │ │ │ ├── PinDirection.java │ │ │ │ │ └── Pins.java │ │ │ │ └── system │ │ │ │ │ ├── BoardModels.java │ │ │ │ │ ├── SystemInfo.java │ │ │ │ │ └── SystemInfoException.java │ │ │ │ └── pibrella │ │ │ │ ├── Pibrella.java │ │ │ │ ├── PibrellaButton.java │ │ │ │ ├── PibrellaBuzzer.java │ │ │ │ ├── PibrellaInputPin.java │ │ │ │ ├── PibrellaInputPins.java │ │ │ │ ├── PibrellaLED.java │ │ │ │ ├── PibrellaLEDs.java │ │ │ │ ├── PibrellaOutputPin.java │ │ │ │ ├── PibrellaOutputPins.java │ │ │ │ └── PibrellaPins.java │ │ │ └── resources │ │ │ └── libdio.so │ └── python │ │ └── example.py ├── sparkplug_b.json ├── sparkplug_b.proto ├── sparkplug_b_c_sharp.proto ├── stand_alone_examples │ ├── c │ │ ├── template_as_custom_props │ │ │ ├── Makefile │ │ │ └── example.c │ │ └── udt_example │ │ │ ├── Makefile │ │ │ └── example.c │ ├── java │ │ ├── THIRD-PARTY.txt │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── eclipse │ │ │ └── tahu │ │ │ └── SparkplugExample.java │ ├── java_device_timestamp │ │ ├── THIRD-PARTY.txt │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── eclipse │ │ │ └── tahu │ │ │ └── SparkplugExample.java │ ├── java_edge_node_control │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── eclipse │ │ │ └── tahu │ │ │ └── SparkplugExample.java │ ├── java_records │ │ ├── THIRD-PARTY.txt │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── eclipse │ │ │ └── tahu │ │ │ └── SparkplugRecordsExample.java │ ├── java_udt │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── eclipse │ │ │ └── tahu │ │ │ └── SparkplugExample.java │ ├── js │ │ ├── example.js │ │ └── package.json │ ├── nodered │ │ ├── emulated-device.js │ │ └── package.json │ └── python │ │ ├── THIRD-PARTY.txt │ │ ├── example (copy).py │ │ └── example.py └── tools │ └── java_sparkplug_b_listener │ ├── THIRD-PARTY.txt │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── org │ │ └── eclipse │ │ └── tahu │ │ └── SparkplugListener.java │ └── resources │ └── log4j.properties ├── sparkplug_b_pb2.py ├── sparkplug_b_pb2.pyc ├── yolov2-tiny.cfg ├── yolov2.cfg ├── yolov3-calibration.table.trt7.0 ├── yolov3-tiny.cfg ├── yolov3-tiny.weights └── yolov3.cfg /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | Prequisites: 24 | - DeepStreamSDK 5.0 25 | - Python 3.6 26 | - Gst-python 27 | - GstRtspServer 28 | 29 | Installing GstRtspServer and instrospection typelib 30 | =================================================== 31 | $ sudo apt update 32 | $ sudo apt-get install libgstrtspserver-1.0-0 gstreamer1.0-rtsp 33 | For gst-rtsp-server (and other GStreamer stuff) to be accessible in 34 | Python through gi.require_version(), it needs to be built with 35 | gobject-introspection enabled (libgstrtspserver-1.0-0 is already). 36 | Yet, we need to install the introspection typelib package: 37 | $ sudo apt-get install libgirepository1.0-dev 38 | $ sudo apt-get install gobject-introspection gir1.2-gst-rtsp-server-1.0 39 | 40 | To get test app usage information: 41 | $ python3 deepstream_test1_rtsp_out.py -h 42 | 43 | To run the test app with default settings: 44 | $ python3 deepstream_test1_rtsp_out.py -i 45 | 46 | Default RTSP streaming location: 47 | rtsp://:8554/ds-test 48 | 49 | This document shall describe the sample deepstream-test1-rtsp-out application. 50 | 51 | It is meant for simple demonstration of how to use the various DeepStream SDK 52 | elements in the pipeline and extract meaningful insights from a video stream. 53 | The output video data with inference output overlayed is encoded and streamed 54 | using GstRtspServer. 55 | 56 | This sample creates instance of "nvinfer" element. Instance of 57 | the "nvinfer" uses TensorRT API to execute inferencing on a model. Using a 58 | correct configuration for a nvinfer element instance is therefore very 59 | important as considerable behaviors of the instance are parameterized 60 | through these configs. 61 | 62 | For reference, here are the config files used for this sample : 63 | 1. The 4-class detector (referred to as pgie in this sample) uses 64 | dstest1_pgie_config.txt 65 | 66 | In this sample, we first create one instance of "nvinfer", referred as the pgie. 67 | This is our 4 class detector and it detects for "Vehicle , RoadSign, TwoWheeler, 68 | Person". 69 | nvinfer element attach some MetaData to the buffer. By attaching 70 | the probe function at the end of the pipeline, one can extract meaningful 71 | information from this inference. Please refer the "osd_sink_pad_buffer_probe" 72 | function in the sample code. For details on the Metadata format, refer to the 73 | file "gstnvdsmeta.h" 74 | 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deepstream IGN Maker YOLO 2 | Nvidia Deepstream YOLO Python App 3 | 4 | Here is the code and the Python apps I used to Run the Nvidia Deepstream YOLO Object detector app. 5 | 6 | The Ignition maker app for ignition designer is also included in this Repo incase you want to import it into Ignition designer. 7 | 8 | This Repo also contains sparkplug stuff and Deepstream YOLO Config files. 9 | 10 | If you clone this Repo and install it on youre Nano or Xavier NX at this location. 11 | 12 | /opt/nvidia/deepstream/deepstream-5.0/sources/deepstream_python_apps/apps 13 | 14 | It should be able to run out of that folder. 15 | 16 | 17 | # 1. python3 deepstream_ignition_IP_File_yolo.py 18 | 19 | Will run a I.P. camera or a MP4 file and display the Video stream on youre XavierNX or nano 20 | 21 | and also send metadata via sparkplug to the Ignition Maker app. 22 | 23 | I.P. Example:python3 deepstream_ignition_IP_File_yolo.py 'rtsp://172.16.2.157:554/user=admin&password=&channel=1&stream=0.sdp?' 24 | 25 | MP4 file example:python3 deepstream_ignition_IP_File_yolo.py file:////opt/nvidia/deepstream/deepstream=5.0/samples/streams/video.mp4 26 | 27 | 28 | # 2. python3 deepstream_ignition_usb_yolo.py 29 | 30 | Will run a webcam and display the Video stream on youre XavierNX or nano 31 | 32 | and also send metadata via sparkplug to the Ignition Maker app. 33 | 34 | webcam example:python3 deepstream_ignition_usb_yolo.py /dev/video0 35 | 36 | 37 | # 3. python3 deepstream_ignition_IP_File_rtsp_yolo.py 38 | 39 | Will run a I.P. camera or a MP4 file and and stream out a RTSP stream 40 | 41 | and also send metadata via sparkplug to the Ignition Maker app. 42 | 43 | I.P. Example:python3 deepstream_ignition_IP_File_rtsp_yolo.py 'rtsp://172.16.2.157:554/user=admin&password=&channel=1&stream=0.sdp?' 44 | 45 | MP4 file example:python3 deepstream_ignition_IP_File_rtsp_yolo.py file:////opt/nvidia/deepstream/deepstream=5.0/samples/streams/video.mp4 46 | 47 | 48 | 49 | # 4. python3 deepstream_ignition_usb_rtsp_yolo.py 50 | 51 | Will run a webcam and and and stream out a RTSP stream 52 | 53 | and also send metadata via sparkplug to the Ignition Maker app. 54 | 55 | webcam example:python3 deepstream_ignition_usb_rtsp_yolo.py /dev/video0 56 | 57 | 58 | # 5. nx_2021-01-29_1525 59 | Is the ignition maker app you can import into ignition designer 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /README1: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | Prerequisites: 24 | - DeepStreamSDK 5.0 25 | - Python 3.6 26 | - Gst-python 27 | 28 | To run: 29 | $ python3 deepstream_test_3.py [uri2] ... [uriN] 30 | e.g. 31 | $ python3 deepstream_test_3.py file:///home/ubuntu/video1.mp4 file:///home/ubuntu/video2.mp4 32 | $ python3 deepstream_test_3.py rtsp://127.0.0.1/video1 rtsp://127.0.0.1/video2 33 | 34 | This document describes the sample deepstream-test3 application. 35 | 36 | This sample builds on top of the deepstream-test1 sample to demonstrate how to: 37 | 38 | * Use multiple sources in the pipeline. 39 | * Use a uridecodebin so that any type of input (e.g. RTSP/File), any GStreamer 40 | supported container format, and any codec can be used as input. 41 | * Configure the stream-muxer to generate a batch of frames and infer on the 42 | batch for better resource utilization. 43 | * Extract the stream metadata, which contains useful information about the 44 | frames in the batched buffer. 45 | 46 | Refer to the deepstream-test1 sample documentation for an example of simple 47 | single-stream inference, bounding-box overlay, and rendering. 48 | 49 | This sample accepts one or more H.264/H.265 video streams as input. It creates 50 | a source bin for each input and connects the bins to an instance of the 51 | "nvstreammux" element, which forms the batch of frames. The batch of 52 | frames is fed to "nvinfer" for batched inferencing. The batched buffer is 53 | composited into a 2D tile array using "nvmultistreamtiler." The rest of the 54 | pipeline is similar to the deepstream-test1 sample. 55 | 56 | The "width" and "height" properties must be set on the stream-muxer to set the 57 | output resolution. If the input frame resolution is different from 58 | stream-muxer's "width" and "height", the input frame will be scaled to muxer's 59 | output resolution. 60 | 61 | The stream-muxer waits for a user-defined timeout before forming the batch. The 62 | timeout is set using the "batched-push-timeout" property. If the complete batch 63 | is formed before the timeout is reached, the batch is pushed to the downstream 64 | element. If the timeout is reached before the complete batch can be formed 65 | (which can happen in case of rtsp sources), the batch is formed from the 66 | available input buffers and pushed. Ideally, the timeout of the stream-muxer 67 | should be set based on the framerate of the fastest source. It can also be set 68 | to -1 to make the stream-muxer wait infinitely. 69 | 70 | The "nvmultistreamtiler" composite streams based on their stream-ids in 71 | row-major order (starting from stream 0, left to right across the top row, then 72 | across the next row, etc.). 73 | -------------------------------------------------------------------------------- /__pycache__/sparkplug_b.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/__pycache__/sparkplug_b.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/sparkplug_b_pb2.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/__pycache__/sparkplug_b_pb2.cpython-36.pyc -------------------------------------------------------------------------------- /client_libraries/c/Makefile: -------------------------------------------------------------------------------- 1 | #/******************************************************************************** 2 | # * Copyright (c) 2014-2019 Cirrus Link Solutions and others 3 | # * 4 | # * This program and the accompanying materials are made available under the 5 | # * terms of the Eclipse Public License 2.0 which is available at 6 | # * http://www.eclipse.org/legal/epl-2.0. 7 | # * 8 | # * SPDX-License-Identifier: EPL-2.0 9 | # * 10 | # * Contributors: 11 | # * Cirrus Link Solutions - initial implementation 12 | # ********************************************************************************/ 13 | 14 | CC := gcc 15 | NAME := tahu 16 | SNAME := lib/lib$(NAME).a 17 | DNAME := lib/lib$(NAME).so 18 | SRC := $(wildcard src/*.c) 19 | OBJ := $(SRC:.c=.o) 20 | #CFLAGS := -Wall -g3 -fPIC -Iinclude/ 21 | CFLAGS := -g -g3 -fPIC -Iinclude/ 22 | LDFLAGS := -L. 23 | #LDLIBS := -l$(...) 24 | 25 | TEST := test 26 | TEST_OBJ := test/test.c 27 | LD_TEST := -Llib -L/usr/local/lib -l$(NAME) 28 | 29 | .PHONY: all clean test re 30 | 31 | all: $(SNAME) $(DNAME) $(TEST) 32 | 33 | $(SNAME): $(OBJ) 34 | mkdir -p lib 35 | $(AR) $(ARFLAGS) $@ $^ 36 | 37 | $(DNAME): LDFLAGS += -shared 38 | $(DNAME): $(OBJ) 39 | $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) 40 | 41 | $(TEST): 42 | $(CC) $(CFLAGS) -o test/test_static $(TEST_OBJ) $(SNAME) -lmosquitto 43 | $(CC) $(CFLAGS) $(LD_TEST) -o test/test_dynamic $(TEST_OBJ) -l$(NAME) -lmosquitto 44 | 45 | clean: 46 | $(RM) $(OBJ) 47 | $(RM) $(SNAME) $(DNAME) 48 | $(RM) test/test_static test/test_dynamic 49 | 50 | re: clean all 51 | -------------------------------------------------------------------------------- /client_libraries/c/include/pb_common.h: -------------------------------------------------------------------------------- 1 | /* pb_common.h: Common support functions for pb_encode.c and pb_decode.c. 2 | * These functions are rarely needed by applications directly. 3 | */ 4 | 5 | #ifndef PB_COMMON_H_INCLUDED 6 | #define PB_COMMON_H_INCLUDED 7 | 8 | #include "pb.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /* Iterator for pb_field_t list */ 15 | struct pb_field_iter_s { 16 | const pb_field_t *start; /* Start of the pb_field_t array */ 17 | const pb_field_t *pos; /* Current position of the iterator */ 18 | unsigned required_field_index; /* Zero-based index that counts only the required fields */ 19 | void *dest_struct; /* Pointer to start of the structure */ 20 | void *pData; /* Pointer to current field value */ 21 | void *pSize; /* Pointer to count/has field */ 22 | }; 23 | typedef struct pb_field_iter_s pb_field_iter_t; 24 | 25 | /* Initialize the field iterator structure to beginning. 26 | * Returns false if the message type is empty. */ 27 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct); 28 | 29 | /* Advance the iterator to the next field. 30 | * Returns false when the iterator wraps back to the first field. */ 31 | bool pb_field_iter_next(pb_field_iter_t *iter); 32 | 33 | /* Advance the iterator until it points at a field with the given tag. 34 | * Returns false if no such field exists. */ 35 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag); 36 | 37 | #ifdef __cplusplus 38 | } /* extern "C" */ 39 | #endif 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /client_libraries/c/readme.txt: -------------------------------------------------------------------------------- 1 | #/******************************************************************************** 2 | # * Copyright (c) 2014-2019 Cirrus Link Solutions and others 3 | # * 4 | # * This program and the accompanying materials are made available under the 5 | # * terms of the Eclipse Public License 2.0 which is available at 6 | # * http://www.eclipse.org/legal/epl-2.0. 7 | # * 8 | # * SPDX-License-Identifier: EPL-2.0 9 | # * 10 | # * Contributors: 11 | # * Cirrus Link Solutions - initial implementation 12 | # ********************************************************************************/ 13 | 14 | # To generate the base protobuf tahu NanoPB C library (using Protoc v2.6.1 and Nanopb v0.3.5) 15 | protoc --proto_path=../../ -otahu.pb ../../sparkplug_b/sparkplug_b.proto 16 | ~/nanopb/nanopb-0.3.5-linux-x86/generator/nanopb_generator.py -f tahu.options tahu.pb 17 | mv tahu.pb src/ 18 | mv tahu.pb.c src/ 19 | mv tahu.pb.h include/ 20 | -------------------------------------------------------------------------------- /client_libraries/c/src/pb_common.c: -------------------------------------------------------------------------------- 1 | /* pb_common.c: Common support functions for pb_encode.c and pb_decode.c. 2 | * 3 | * 2014 Petteri Aimonen 4 | */ 5 | 6 | #include "pb_common.h" 7 | 8 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct) 9 | { 10 | iter->start = fields; 11 | iter->pos = fields; 12 | iter->required_field_index = 0; 13 | iter->dest_struct = dest_struct; 14 | iter->pData = (char*)dest_struct + iter->pos->data_offset; 15 | iter->pSize = (char*)iter->pData + iter->pos->size_offset; 16 | 17 | return (iter->pos->tag != 0); 18 | } 19 | 20 | bool pb_field_iter_next(pb_field_iter_t *iter) 21 | { 22 | const pb_field_t *prev_field = iter->pos; 23 | 24 | if (prev_field->tag == 0) 25 | { 26 | /* Handle empty message types, where the first field is already the terminator. 27 | * In other cases, the iter->pos never points to the terminator. */ 28 | return false; 29 | } 30 | 31 | iter->pos++; 32 | 33 | if (iter->pos->tag == 0) 34 | { 35 | /* Wrapped back to beginning, reinitialize */ 36 | (void)pb_field_iter_begin(iter, iter->start, iter->dest_struct); 37 | return false; 38 | } 39 | else 40 | { 41 | /* Increment the pointers based on previous field size */ 42 | size_t prev_size = prev_field->data_size; 43 | 44 | if (PB_HTYPE(prev_field->type) == PB_HTYPE_ONEOF && 45 | PB_HTYPE(iter->pos->type) == PB_HTYPE_ONEOF) 46 | { 47 | /* Don't advance pointers inside unions */ 48 | prev_size = 0; 49 | iter->pData = (char*)iter->pData - prev_field->data_offset; 50 | } 51 | else if (PB_ATYPE(prev_field->type) == PB_ATYPE_STATIC && 52 | PB_HTYPE(prev_field->type) == PB_HTYPE_REPEATED) 53 | { 54 | /* In static arrays, the data_size tells the size of a single entry and 55 | * array_size is the number of entries */ 56 | prev_size *= prev_field->array_size; 57 | } 58 | else if (PB_ATYPE(prev_field->type) == PB_ATYPE_POINTER) 59 | { 60 | /* Pointer fields always have a constant size in the main structure. 61 | * The data_size only applies to the dynamically allocated area. */ 62 | prev_size = sizeof(void*); 63 | } 64 | 65 | if (PB_HTYPE(prev_field->type) == PB_HTYPE_REQUIRED) 66 | { 67 | /* Count the required fields, in order to check their presence in the 68 | * decoder. */ 69 | iter->required_field_index++; 70 | } 71 | 72 | iter->pData = (char*)iter->pData + prev_size + iter->pos->data_offset; 73 | iter->pSize = (char*)iter->pData + iter->pos->size_offset; 74 | return true; 75 | } 76 | } 77 | 78 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag) 79 | { 80 | const pb_field_t *start = iter->pos; 81 | 82 | do { 83 | if (iter->pos->tag == tag && 84 | PB_LTYPE(iter->pos->type) != PB_LTYPE_EXTENSION) 85 | { 86 | /* Found the wanted field */ 87 | return true; 88 | } 89 | 90 | (void)pb_field_iter_next(iter); 91 | } while (iter->pos != start); 92 | 93 | /* Searched all the way back to start, and found nothing. */ 94 | return false; 95 | } 96 | 97 | 98 | -------------------------------------------------------------------------------- /client_libraries/c/src/tahu.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/client_libraries/c/src/tahu.pb -------------------------------------------------------------------------------- /client_libraries/c/tahu.options: -------------------------------------------------------------------------------- 1 | org.eclipse.tahu.protobuf.Payload.body type:FT_POINTER 2 | org.eclipse.tahu.protobuf.Payload.metrics type:FT_POINTER 3 | org.eclipse.tahu.protobuf.Payload.uuid type:FT_POINTER 4 | org.eclipse.tahu.protobuf.Payload.DataSet.columns type:FT_POINTER 5 | org.eclipse.tahu.protobuf.Payload.DataSet.rows type:FT_POINTER 6 | org.eclipse.tahu.protobuf.Payload.DataSet.types type:FT_POINTER 7 | org.eclipse.tahu.protobuf.Payload.DataSet.DataSetValue.string_value type:FT_POINTER 8 | org.eclipse.tahu.protobuf.Payload.DataSet.Row.elements type:FT_POINTER 9 | org.eclipse.tahu.protobuf.Payload.MetaData.content_type type:FT_POINTER 10 | org.eclipse.tahu.protobuf.Payload.MetaData.description type:FT_POINTER 11 | org.eclipse.tahu.protobuf.Payload.MetaData.file_name type:FT_POINTER 12 | org.eclipse.tahu.protobuf.Payload.MetaData.file_type type:FT_POINTER 13 | org.eclipse.tahu.protobuf.Payload.MetaData.md5 type:FT_POINTER 14 | org.eclipse.tahu.protobuf.Payload.Metric.bytes_value type:FT_POINTER 15 | org.eclipse.tahu.protobuf.Payload.Metric.name type:FT_POINTER 16 | org.eclipse.tahu.protobuf.Payload.Metric.string_value type:FT_POINTER 17 | org.eclipse.tahu.protobuf.Payload.PropertySet.keys type:FT_POINTER 18 | org.eclipse.tahu.protobuf.Payload.PropertySet.values type:FT_POINTER 19 | org.eclipse.tahu.protobuf.Payload.PropertySetList.propertyset type:FT_POINTER 20 | org.eclipse.tahu.protobuf.Payload.PropertyValue.string_value type:FT_POINTER 21 | org.eclipse.tahu.protobuf.Payload.Template.metrics type:FT_POINTER 22 | org.eclipse.tahu.protobuf.Payload.Template.template_ref type:FT_POINTER 23 | org.eclipse.tahu.protobuf.Payload.Template.version type:FT_POINTER 24 | org.eclipse.tahu.protobuf.Payload.Template.parameters type:FT_POINTER 25 | org.eclipse.tahu.protobuf.Payload.Template.Parameter.name type:FT_POINTER 26 | org.eclipse.tahu.protobuf.Payload.Template.Parameter.string_value type:FT_POINTER 27 | -------------------------------------------------------------------------------- /client_libraries/c/test.sh: -------------------------------------------------------------------------------- 1 | #/******************************************************************************** 2 | # * Copyright (c) 2014-2019 Cirrus Link Solutions and others 3 | # * 4 | # * This program and the accompanying materials are made available under the 5 | # * terms of the Eclipse Public License 2.0 which is available at 6 | # * http://www.eclipse.org/legal/epl-2.0. 7 | # * 8 | # * SPDX-License-Identifier: EPL-2.0 9 | # * 10 | # * Contributors: 11 | # * Cirrus Link Solutions - initial implementation 12 | # ********************************************************************************/ 13 | 14 | #!/bin/sh 15 | 16 | #echo "Running static example..." 17 | #./test/test_static 18 | 19 | echo "" 20 | echo "Running dynamic example..." 21 | #echo "Starting LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}" 22 | PWD=`pwd` 23 | export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD}/lib 24 | #echo "New LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}" 25 | ./test/test_dynamic 26 | -------------------------------------------------------------------------------- /client_libraries/c/test/.gitignore: -------------------------------------------------------------------------------- 1 | test_dynamic.dSYM 2 | test_static.dSYM 3 | -------------------------------------------------------------------------------- /client_libraries/c_sharp/readme.txt: -------------------------------------------------------------------------------- 1 | # To generate the base protobuf sparkplug_b Java library 2 | protoc --proto_path=../../ --csharp_out=src --csharp_opt=base_namespace=Org.Eclipse.Tahu.Protobuf ../../sparkplug_b/sparkplug_b_c_sharp.proto 3 | -------------------------------------------------------------------------------- /client_libraries/java/pom.xml: -------------------------------------------------------------------------------- 1 | 14 | 16 | 4.0.0 17 | 18 | 19 | org.eclipse.tahu 20 | tahu 21 | 0.5.8 22 | ../../pom.xml 23 | 24 | 25 | tahu-java 26 | jar 27 | Maven Quick Start Archetype 28 | http://maven.apache.org 29 | 30 | 31 | 32 | org.apache.commons 33 | commons-compress 34 | 1.18 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.codehaus.mojo 42 | license-maven-plugin 43 | 1.8 44 | 45 | 46 | add-third-party 47 | package 48 | 49 | add-third-party 50 | download-licenses 51 | 52 | 53 | true 54 | test 55 | (org.eclipse.tahu*) 56 | 57 | 58 | The Apache Software License, Version 59 | 2.0|Apache License, Version 2.0|Apache Public License 60 | 2.0|Apache License 2.0|Apache Software License - 61 | Version 2.0 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /client_libraries/java/readme.txt: -------------------------------------------------------------------------------- 1 | # To generate the base protobuf sparkplug_b Java library 2 | protoc --proto_path=../../ --java_out=src/main/java ../../sparkplug_b/sparkplug_b.proto 3 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/SparkplugException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu; 15 | 16 | /** 17 | * A Sparkplug Exception 18 | */ 19 | public class SparkplugException extends Exception { 20 | 21 | /** 22 | * Default constructor. 23 | */ 24 | public SparkplugException() { 25 | } 26 | 27 | /** 28 | * Constructor 29 | * 30 | * @param message an error message 31 | */ 32 | public SparkplugException(String message) { 33 | super(message); 34 | } 35 | 36 | /** 37 | * Constructor 38 | * 39 | * @param message an error message 40 | * @param exception an underlying exception 41 | */ 42 | public SparkplugException(String message, Throwable exception) { 43 | super(message, exception); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/SparkplugInvalidTypeException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu; 15 | 16 | /** 17 | * An Exception caused by an invalid type. 18 | */ 19 | public class SparkplugInvalidTypeException extends SparkplugException { 20 | 21 | private Class type; 22 | 23 | public SparkplugInvalidTypeException(Class type) { 24 | super("Invalid type " + type); 25 | this.type = type; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/SparkplugParsingException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu; 15 | 16 | /** 17 | * An Exception thrown if an error is encountered while parsing a payload or topic. 18 | */ 19 | public class SparkplugParsingException extends SparkplugException { 20 | 21 | /** 22 | * Constructor 23 | * 24 | * @param message an error message 25 | */ 26 | public SparkplugParsingException(String message) { 27 | super(message); 28 | } 29 | 30 | /** 31 | * Constructor 32 | * 33 | * @param message an error message 34 | * @param exception an underlying exception 35 | */ 36 | public SparkplugParsingException(String message, Throwable exception) { 37 | super(message, exception); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/json/DeserializerModifier.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2017, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.json; 15 | 16 | import org.eclipse.tahu.message.model.Metric; 17 | 18 | import com.fasterxml.jackson.databind.BeanDescription; 19 | import com.fasterxml.jackson.databind.DeserializationConfig; 20 | import com.fasterxml.jackson.databind.JsonDeserializer; 21 | import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; 22 | 23 | /** 24 | * 25 | */ 26 | public class DeserializerModifier extends BeanDeserializerModifier { 27 | 28 | @Override 29 | public JsonDeserializer modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, 30 | JsonDeserializer deserializer) { 31 | if (Metric.class.equals(beanDesc.getBeanClass())) { 32 | return new MetricDeserializer(deserializer); 33 | } 34 | 35 | return super.modifyDeserializer(config, beanDesc, deserializer); 36 | } 37 | } -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/json/DeserializerModule.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2017, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.json; 15 | 16 | import com.fasterxml.jackson.core.Version; 17 | import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; 18 | import com.fasterxml.jackson.databind.module.SimpleModule; 19 | 20 | /** 21 | * Used to register the {@link DeserializerModifier} instance. 22 | */ 23 | public class DeserializerModule extends SimpleModule { 24 | 25 | private BeanDeserializerModifier deserializerModifier; 26 | 27 | public DeserializerModule(BeanDeserializerModifier deserializerModifier) { 28 | super("DeserializerModule", Version.unknownVersion()); 29 | this.deserializerModifier = deserializerModifier; 30 | } 31 | 32 | @Override 33 | public void setupModule(SetupContext context) { 34 | super.setupModule(context); 35 | context.addBeanDeserializerModifier(deserializerModifier); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/json/FileSerializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2017, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.json; 15 | 16 | import java.io.IOException; 17 | 18 | import org.eclipse.paho.client.mqttv3.internal.websocket.Base64; 19 | import org.eclipse.tahu.message.model.File; 20 | 21 | import com.fasterxml.jackson.core.JsonGenerator; 22 | import com.fasterxml.jackson.databind.SerializerProvider; 23 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; 24 | 25 | /** 26 | * Serializes a {@link File} instance. 27 | */ 28 | public class FileSerializer extends StdSerializer { 29 | 30 | /** 31 | * Constructor. 32 | */ 33 | protected FileSerializer() { 34 | super(File.class); 35 | } 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param clazz class. 41 | */ 42 | protected FileSerializer(Class clazz) { 43 | super(clazz); 44 | } 45 | 46 | @Override 47 | public void serialize(File value, JsonGenerator generator, SerializerProvider provider) throws IOException { 48 | generator.writeString(Base64.encodeBytes(value.getBytes())); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/json/JsonValidator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2017, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.json; 15 | 16 | /** 17 | * Validates JSON. 18 | */ 19 | public class JsonValidator { 20 | 21 | protected static final String JSON_SCHEMA_FILENAME = "payload.json"; 22 | 23 | private static JsonValidator instance = null; 24 | 25 | /** 26 | * Constructor. 27 | */ 28 | protected JsonValidator() { 29 | } 30 | 31 | /** 32 | * Returns the {@link JsonValidator} instance. 33 | * 34 | * @return the {@link JsonValidator} instance. 35 | */ 36 | public static JsonValidator getInstance() { 37 | if (instance == null) { 38 | instance = new JsonValidator(); 39 | } 40 | return instance; 41 | } 42 | 43 | /** 44 | * Returns loads and returns the {@link JsonSchema} instance associated with this validator. 45 | * 46 | * @return the {@link JsonSchema} instance associated with this validator. 47 | * @throws IOException 48 | * @throws ProcessingException 49 | */ 50 | // protected JsonSchema getSchema() throws IOException, ProcessingException { 51 | // // Get file from resources folder 52 | // ClassLoader classLoader = getClass().getClassLoader(); 53 | // File schemaFile = new File(classLoader.getResource(JSON_SCHEMA_FILENAME).getFile()); 54 | // return JsonSchemaFactory.byDefault().getJsonSchema(JsonLoader.fromFile(schemaFile)); 55 | // } 56 | 57 | /** 58 | * Returns true if the supplied JSON text is valid, false otherwise. 59 | * 60 | * @param jsonText a {@link String} representing JSON text. 61 | * @return true if the supplied JSON text is valid, false otherwise. 62 | * @throws ProcessingException 63 | * @throws IOException 64 | */ 65 | // public boolean isJsonValid(String jsonText) throws ProcessingException, IOException { 66 | // return getSchema().validate(JsonLoader.fromString(jsonText)).isSuccess(); 67 | // } 68 | } 69 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/json/MetricDeserializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.json; 15 | 16 | import java.io.IOException; 17 | import java.util.Base64; 18 | 19 | import org.eclipse.tahu.message.model.File; 20 | import org.eclipse.tahu.message.model.MetaData; 21 | import org.eclipse.tahu.message.model.Metric; 22 | import org.eclipse.tahu.message.model.MetricDataType; 23 | 24 | import com.fasterxml.jackson.core.JsonParser; 25 | import com.fasterxml.jackson.core.JsonProcessingException; 26 | import com.fasterxml.jackson.databind.DeserializationContext; 27 | import com.fasterxml.jackson.databind.JsonDeserializer; 28 | import com.fasterxml.jackson.databind.JsonMappingException; 29 | import com.fasterxml.jackson.databind.deser.ResolvableDeserializer; 30 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 31 | 32 | /** 33 | * A custom JSON deserializer for {@link Metric} instances. 34 | */ 35 | public class MetricDeserializer extends StdDeserializer implements ResolvableDeserializer { 36 | 37 | private final JsonDeserializer defaultDeserializer; 38 | 39 | /** 40 | * Constructor. 41 | */ 42 | protected MetricDeserializer(JsonDeserializer defaultDeserializer) { 43 | super(Metric.class); 44 | this.defaultDeserializer = defaultDeserializer; 45 | } 46 | 47 | @Override 48 | public Metric deserialize(JsonParser parser, DeserializationContext ctxt) 49 | throws IOException, JsonProcessingException { 50 | 51 | Metric metric = (Metric) defaultDeserializer.deserialize(parser, ctxt); 52 | 53 | // Check if the data type is a File 54 | if (metric.getDataType().equals(MetricDataType.File)) { 55 | // Perform the custom logic for File types by building up the File object. 56 | MetaData metaData = metric.getMetaData(); 57 | String fileName = metaData == null ? null : metaData.getFileName(); 58 | File file = new File(fileName, Base64.getDecoder().decode((String) metric.getValue())); 59 | metric.setValue(file); 60 | } 61 | return metric; 62 | } 63 | 64 | @Override 65 | public void resolve(DeserializationContext ctxt) throws JsonMappingException { 66 | ((ResolvableDeserializer) defaultDeserializer).resolve(ctxt); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/PayloadDecoder.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message; 15 | 16 | /** 17 | * An interface for decoding payloads. 18 | * 19 | * @param

the type of payload. 20 | */ 21 | public interface PayloadDecoder

{ 22 | 23 | /** 24 | * Builds a payload from a supplied byte array. 25 | * 26 | * @param bytes the bytes representing the payload 27 | * @return a payload object built from the byte array 28 | * @throws Exception 29 | */ 30 | public P buildFromByteArray(byte[] bytes) throws Exception; 31 | } 32 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/PayloadEncoder.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message; 15 | 16 | import java.io.IOException; 17 | 18 | /** 19 | * An interface for encoding payloads. 20 | * 21 | * @param

the type of payload. 22 | */ 23 | public interface PayloadEncoder

{ 24 | 25 | /** 26 | * Converts a payload object into a byte array. 27 | * 28 | * @param payload a payload object 29 | * @return the byte array representing the payload 30 | * @throws IOException 31 | */ 32 | public byte[] getBytes(P payload) throws IOException; 33 | } 34 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/DataSetDataType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.math.BigInteger; 17 | import java.util.Date; 18 | 19 | import org.eclipse.tahu.SparkplugInvalidTypeException; 20 | 21 | /** 22 | * A enumeration of data types of values in a {@link DataSet} 23 | */ 24 | public enum DataSetDataType { 25 | 26 | // Basic Types 27 | Int8(1, Byte.class), 28 | Int16(2, Short.class), 29 | Int32(3, Integer.class), 30 | Int64(4, Long.class), 31 | UInt8(5, Short.class), 32 | UInt16(6, Integer.class), 33 | UInt32(7, Long.class), 34 | UInt64(8, BigInteger.class), 35 | Float(9, Float.class), 36 | Double(10, Double.class), 37 | Boolean(11, Boolean.class), 38 | String(12, String.class), 39 | DateTime(13, Date.class), 40 | Text(14, String.class), 41 | 42 | // Unknown 43 | Unknown(0, Object.class); 44 | 45 | private Class clazz = null; 46 | private int intValue = 0; 47 | 48 | private DataSetDataType(int intValue, Class clazz) { 49 | this.intValue = intValue; 50 | this.clazz = clazz; 51 | } 52 | 53 | public void checkType(Object value) throws SparkplugInvalidTypeException { 54 | if (value != null && !clazz.isAssignableFrom(value.getClass())) { 55 | throw new SparkplugInvalidTypeException(value.getClass()); 56 | } 57 | } 58 | 59 | /** 60 | * Returns an integer representation of the data type. 61 | * 62 | * @return an integer representation of the data type. 63 | */ 64 | public int toIntValue() { 65 | return this.intValue; 66 | } 67 | 68 | /** 69 | * Converts the integer representation of the data type into a {@link DataSetDataType} instance. 70 | * 71 | * @param i the integer representation of the data type. 72 | * @return a {@link DataSetDataType} instance. 73 | */ 74 | public static DataSetDataType fromInteger(int i) { 75 | switch (i) { 76 | case 1: 77 | return Int8; 78 | case 2: 79 | return Int16; 80 | case 3: 81 | return Int32; 82 | case 4: 83 | return Int64; 84 | case 5: 85 | return UInt8; 86 | case 6: 87 | return UInt16; 88 | case 7: 89 | return UInt32; 90 | case 8: 91 | return UInt64; 92 | case 9: 93 | return Float; 94 | case 10: 95 | return Double; 96 | case 11: 97 | return Boolean; 98 | case 12: 99 | return String; 100 | case 13: 101 | return DateTime; 102 | case 14: 103 | return Text; 104 | default: 105 | return Unknown; 106 | } 107 | } 108 | 109 | /** 110 | * Returns the class type for this DataType 111 | * 112 | * @return the class type for this DataType 113 | */ 114 | public Class getClazz() { 115 | return clazz; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/File.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.util.Arrays; 17 | 18 | import org.eclipse.tahu.json.FileSerializer; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | 23 | @JsonIgnoreProperties(value = { "fileName" }) 24 | @JsonSerialize(using = FileSerializer.class) 25 | public class File { 26 | 27 | private String fileName; 28 | private byte[] bytes; 29 | 30 | public File() { 31 | super(); 32 | } 33 | 34 | public File(String fileName, byte[] bytes) { 35 | super(); 36 | this.fileName = fileName == null 37 | ? null 38 | : fileName.replace("/", System.getProperty("file.separator")).replace("\\", 39 | System.getProperty("file.separator")); 40 | this.bytes = Arrays.copyOf(bytes, bytes.length); 41 | } 42 | 43 | public String getFileName() { 44 | return fileName; 45 | } 46 | 47 | public void setFileName(String fileName) { 48 | this.fileName = fileName; 49 | } 50 | 51 | public byte[] getBytes() { 52 | return bytes; 53 | } 54 | 55 | public void setBytes(byte[] bytes) { 56 | this.bytes = bytes; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | StringBuilder builder = new StringBuilder(); 62 | builder.append("File [fileName="); 63 | builder.append(fileName); 64 | builder.append(", bytes="); 65 | builder.append(Arrays.toString(bytes)); 66 | builder.append("]"); 67 | return builder.toString(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/Message.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | /** 17 | * A class to represent a Message. 18 | */ 19 | public class Message { 20 | 21 | private Topic topic; 22 | 23 | private SparkplugBPayload payload; 24 | 25 | /** 26 | * @param topic 27 | * @param payload 28 | */ 29 | private Message(Topic topic, SparkplugBPayload payload) { 30 | super(); 31 | this.topic = topic; 32 | this.payload = payload; 33 | } 34 | 35 | public Topic getTopic() { 36 | return topic; 37 | } 38 | 39 | public SparkplugBPayload getPayload() { 40 | return payload; 41 | } 42 | 43 | /** 44 | * A builder for creating a {@link SparkplugBPayload} instance. 45 | */ 46 | public static class MessageBuilder { 47 | 48 | private Topic topic; 49 | 50 | private SparkplugBPayload payload; 51 | 52 | public MessageBuilder(Topic topic, SparkplugBPayload payload) { 53 | this.topic = topic; 54 | this.payload = payload; 55 | } 56 | 57 | public MessageBuilder() { 58 | } 59 | 60 | public MessageBuilder topic(Topic topic) { 61 | this.topic = topic; 62 | return this; 63 | } 64 | 65 | public MessageBuilder payload(SparkplugBPayload payload) { 66 | this.payload = payload; 67 | return this; 68 | } 69 | 70 | public Message build() { 71 | return new Message(this.topic, this.payload); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/MessageType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import org.eclipse.tahu.SparkplugParsingException; 17 | 18 | /** 19 | * An enumeration of Sparkplug MQTT message types. The type provides an indication as to what the MQTT Payload of 20 | * message will contain. 21 | */ 22 | public enum MessageType { 23 | 24 | /** 25 | * Birth certificate for MQTT Edge of Network (EoN) Nodes. 26 | */ 27 | NBIRTH, 28 | 29 | /** 30 | * Death certificate for MQTT Edge of Network (EoN) Nodes. 31 | */ 32 | NDEATH, 33 | 34 | /** 35 | * Birth certificate for MQTT Devices. 36 | */ 37 | DBIRTH, 38 | 39 | /** 40 | * Death certificate for MQTT Devices. 41 | */ 42 | DDEATH, 43 | 44 | /** 45 | * Edge of Network (EoN) Node data message. 46 | */ 47 | NDATA, 48 | 49 | /** 50 | * Device data message. 51 | */ 52 | DDATA, 53 | 54 | /** 55 | * Edge of Network (EoN) Node command message. 56 | */ 57 | NCMD, 58 | 59 | /** 60 | * Device command message. 61 | */ 62 | DCMD, 63 | 64 | /** 65 | * Critical application state message. 66 | */ 67 | STATE, 68 | 69 | /** 70 | * Device record message. 71 | */ 72 | DRECORD, 73 | 74 | /** 75 | * Edge of Network (EoN) Node record message. 76 | */ 77 | NRECORD; 78 | 79 | public static MessageType parseMessageType(String type) throws SparkplugParsingException { 80 | for (MessageType messageType : MessageType.values()) { 81 | if (messageType.name().equals(type)) { 82 | return messageType; 83 | } 84 | } 85 | throw new SparkplugParsingException("Invalid message type: " + type); 86 | } 87 | 88 | public boolean isDeath() { 89 | return this.equals(DDEATH) || this.equals(NDEATH); 90 | } 91 | 92 | public boolean isCommand() { 93 | return this.equals(DCMD) || this.equals(NCMD); 94 | } 95 | 96 | public boolean isData() { 97 | return this.equals(DDATA) || this.equals(NDATA); 98 | } 99 | 100 | public boolean isBirth() { 101 | return this.equals(DBIRTH) || this.equals(NBIRTH); 102 | } 103 | 104 | public boolean isRecord() { 105 | return this.equals(DRECORD) || this.equals(NRECORD); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/MetricDataType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.math.BigInteger; 17 | import java.util.Date; 18 | 19 | import org.apache.log4j.LogManager; 20 | import org.apache.log4j.Logger; 21 | import org.eclipse.tahu.SparkplugInvalidTypeException; 22 | 23 | /** 24 | * An enumeration of data types associated with the value of a {@link Metric} 25 | */ 26 | public enum MetricDataType { 27 | 28 | // Basic Types 29 | Int8(1, Byte.class), 30 | Int16(2, Short.class), 31 | Int32(3, Integer.class), 32 | Int64(4, Long.class), 33 | UInt8(5, Short.class), 34 | UInt16(6, Integer.class), 35 | UInt32(7, Long.class), 36 | UInt64(8, BigInteger.class), 37 | Float(9, Float.class), 38 | Double(10, Double.class), 39 | Boolean(11, Boolean.class), 40 | String(12, String.class), 41 | DateTime(13, Date.class), 42 | Text(14, String.class), 43 | 44 | // Custom Types for Metrics 45 | UUID(15, String.class), 46 | DataSet(16, DataSet.class), 47 | Bytes(17, byte[].class), 48 | File(18, File.class), 49 | Template(19, Template.class), 50 | 51 | // Unknown 52 | Unknown(0, Object.class); 53 | 54 | private static Logger logger = LogManager.getLogger(MetricDataType.class.getName()); 55 | 56 | private Class clazz = null; 57 | private int intValue = 0; 58 | 59 | private MetricDataType(int intValue, Class clazz) { 60 | this.intValue = intValue; 61 | this.clazz = clazz; 62 | } 63 | 64 | public void checkType(Object value) throws SparkplugInvalidTypeException { 65 | if (value != null && !clazz.isAssignableFrom(value.getClass())) { 66 | logger.warn( 67 | "Failed type check - " + clazz + " != " + ((value != null) ? value.getClass().toString() : "null")); 68 | throw new SparkplugInvalidTypeException(value.getClass()); 69 | } 70 | } 71 | 72 | /** 73 | * Returns an integer representation of the data type. 74 | * 75 | * @return an integer representation of the data type. 76 | */ 77 | public int toIntValue() { 78 | return this.intValue; 79 | } 80 | 81 | /** 82 | * Converts the integer representation of the data type into a {@link MetricDataType} instance. 83 | * 84 | * @param i the integer representation of the data type. 85 | * @return a {@link MetricDataType} instance. 86 | */ 87 | public static MetricDataType fromInteger(int i) { 88 | switch (i) { 89 | case 1: 90 | return Int8; 91 | case 2: 92 | return Int16; 93 | case 3: 94 | return Int32; 95 | case 4: 96 | return Int64; 97 | case 5: 98 | return UInt8; 99 | case 6: 100 | return UInt16; 101 | case 7: 102 | return UInt32; 103 | case 8: 104 | return UInt64; 105 | case 9: 106 | return Float; 107 | case 10: 108 | return Double; 109 | case 11: 110 | return Boolean; 111 | case 12: 112 | return String; 113 | case 13: 114 | return DateTime; 115 | case 14: 116 | return Text; 117 | case 15: 118 | return UUID; 119 | case 16: 120 | return DataSet; 121 | case 17: 122 | return Bytes; 123 | case 18: 124 | return File; 125 | case 19: 126 | return Template; 127 | default: 128 | return Unknown; 129 | } 130 | } 131 | 132 | /** 133 | * Returns the class type for this DataType 134 | * 135 | * @return the class type for this DataType 136 | */ 137 | public Class getClazz() { 138 | return clazz; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/Parameter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.util.Objects; 17 | 18 | import org.eclipse.tahu.SparkplugInvalidTypeException; 19 | 20 | import com.fasterxml.jackson.annotation.JsonGetter; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import com.fasterxml.jackson.annotation.JsonSetter; 23 | 24 | /** 25 | * A class to represent a parameter associated with a template. 26 | */ 27 | public class Parameter { 28 | 29 | /** 30 | * The name of the parameter 31 | */ 32 | @JsonProperty("name") 33 | private String name; 34 | 35 | /** 36 | * The data type of the parameter 37 | */ 38 | @JsonProperty("type") 39 | private ParameterDataType type; 40 | 41 | /** 42 | * The value of the parameter 43 | */ 44 | @JsonProperty("value") 45 | private Object value; 46 | 47 | public Parameter() { 48 | } 49 | 50 | /** 51 | * Constructs a Parameter instance. 52 | * 53 | * @param name The name of the parameter. 54 | * @param type The type of the parameter. 55 | * @param value The value of the parameter. 56 | * @throws SparkplugInvalidTypeException 57 | */ 58 | public Parameter(String name, ParameterDataType type, Object value) throws SparkplugInvalidTypeException { 59 | this.name = name; 60 | this.type = type; 61 | this.value = value; 62 | this.type.checkType(value); 63 | } 64 | 65 | @JsonGetter("name") 66 | public String getName() { 67 | return name; 68 | } 69 | 70 | @JsonSetter("name") 71 | public void setName(String name) { 72 | this.name = name; 73 | } 74 | 75 | public ParameterDataType getType() { 76 | return type; 77 | } 78 | 79 | public void setType(ParameterDataType type) { 80 | this.type = type; 81 | } 82 | 83 | public Object getValue() { 84 | return value; 85 | } 86 | 87 | public void setValue(Object value) { 88 | this.value = value; 89 | } 90 | 91 | @Override 92 | public boolean equals(Object object) { 93 | if (this == object) { 94 | return true; 95 | } 96 | if (object == null || this.getClass() != object.getClass()) { 97 | return false; 98 | } 99 | Parameter param = (Parameter) object; 100 | return Objects.equals(name, param.getName()) && Objects.equals(type, param.getType()) 101 | && Objects.equals(value, param.getValue()); 102 | } 103 | 104 | @Override 105 | public String toString() { 106 | StringBuilder builder = new StringBuilder(); 107 | builder.append("Parameter [name="); 108 | builder.append(name); 109 | builder.append(", type="); 110 | builder.append(type); 111 | builder.append(", value="); 112 | builder.append(value); 113 | builder.append("]"); 114 | return builder.toString(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/ParameterDataType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.math.BigInteger; 17 | import java.util.Date; 18 | 19 | import org.apache.log4j.LogManager; 20 | import org.apache.log4j.Logger; 21 | import org.eclipse.tahu.SparkplugInvalidTypeException; 22 | 23 | /** 24 | * An enumeration of data types for the value of a {@link Parameter} for a {@link Template} 25 | */ 26 | public enum ParameterDataType { 27 | 28 | // Basic Types 29 | Int8(1, Byte.class), 30 | Int16(2, Short.class), 31 | Int32(3, Integer.class), 32 | Int64(4, Long.class), 33 | UInt8(5, Short.class), 34 | UInt16(6, Integer.class), 35 | UInt32(7, Long.class), 36 | UInt64(8, BigInteger.class), 37 | Float(9, Float.class), 38 | Double(10, Double.class), 39 | Boolean(11, Boolean.class), 40 | String(12, String.class), 41 | DateTime(13, Date.class), 42 | Text(14, String.class), 43 | 44 | // Unknown 45 | Unknown(0, Object.class); 46 | 47 | private static Logger logger = LogManager.getLogger(ParameterDataType.class.getName()); 48 | 49 | private Class clazz = null; 50 | private int intValue = 0; 51 | 52 | private ParameterDataType(int intValue, Class clazz) { 53 | this.intValue = intValue; 54 | this.clazz = clazz; 55 | } 56 | 57 | public void checkType(Object value) throws SparkplugInvalidTypeException { 58 | if (value != null && !clazz.isAssignableFrom(value.getClass())) { 59 | logger.warn("Failed type check - " + clazz + " != " + value.getClass().toString()); 60 | throw new SparkplugInvalidTypeException(value.getClass()); 61 | } 62 | } 63 | 64 | /** 65 | * Returns an integer representation of the data type. 66 | * 67 | * @return an integer representation of the data type. 68 | */ 69 | public int toIntValue() { 70 | return this.intValue; 71 | } 72 | 73 | /** 74 | * Converts the integer representation of the data type into a {@link ParameterDataType} instance. 75 | * 76 | * @param i the integer representation of the data type. 77 | * @return a {@link ParameterDataType} instance. 78 | */ 79 | public static ParameterDataType fromInteger(int i) { 80 | switch (i) { 81 | case 1: 82 | return Int8; 83 | case 2: 84 | return Int16; 85 | case 3: 86 | return Int32; 87 | case 4: 88 | return Int64; 89 | case 5: 90 | return UInt8; 91 | case 6: 92 | return UInt16; 93 | case 7: 94 | return UInt32; 95 | case 8: 96 | return UInt64; 97 | case 9: 98 | return Float; 99 | case 10: 100 | return Double; 101 | case 11: 102 | return Boolean; 103 | case 12: 104 | return String; 105 | case 13: 106 | return DateTime; 107 | case 14: 108 | return Text; 109 | default: 110 | return Unknown; 111 | } 112 | } 113 | 114 | /** 115 | * Returns the class type for this DataType 116 | * 117 | * @return the class type for this DataType 118 | */ 119 | public Class getClazz() { 120 | return clazz; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/PropertyDataType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.math.BigInteger; 17 | import java.util.Date; 18 | import java.util.List; 19 | 20 | import org.apache.log4j.LogManager; 21 | import org.apache.log4j.Logger; 22 | import org.eclipse.tahu.SparkplugInvalidTypeException; 23 | 24 | /** 25 | * An enumeration of data types for values of a {@link PropertySet} 26 | */ 27 | public enum PropertyDataType { 28 | 29 | // Basic Types 30 | Int8(1, Byte.class), 31 | Int16(2, Short.class), 32 | Int32(3, Integer.class), 33 | Int64(4, Long.class), 34 | UInt8(5, Short.class), 35 | UInt16(6, Integer.class), 36 | UInt32(7, Long.class), 37 | UInt64(8, BigInteger.class), 38 | Float(9, Float.class), 39 | Double(10, Double.class), 40 | Boolean(11, Boolean.class), 41 | String(12, String.class), 42 | DateTime(13, Date.class), 43 | Text(14, String.class), 44 | 45 | // Custom Types for PropertySets 46 | PropertySet(20, PropertySet.class), 47 | PropertySetList(21, List.class), 48 | 49 | // Unknown 50 | Unknown(0, Object.class); 51 | 52 | private static Logger logger = LogManager.getLogger(PropertyDataType.class.getName()); 53 | 54 | private Class clazz = null; 55 | private int intValue = 0; 56 | 57 | private PropertyDataType(int intValue, Class clazz) { 58 | this.intValue = intValue; 59 | this.clazz = clazz; 60 | } 61 | 62 | public void checkType(Object value) throws SparkplugInvalidTypeException { 63 | if (value != null && !clazz.isAssignableFrom(value.getClass())) { 64 | if (clazz == List.class && value instanceof List) { 65 | // Allow List subclasses 66 | } else { 67 | logger.warn("Failed type check - " + clazz + " != " + value.getClass().toString()); 68 | throw new SparkplugInvalidTypeException(value.getClass()); 69 | } 70 | } 71 | } 72 | 73 | /** 74 | * Returns an integer representation of the data type. 75 | * 76 | * @return an integer representation of the data type. 77 | */ 78 | public int toIntValue() { 79 | return this.intValue; 80 | } 81 | 82 | /** 83 | * Converts the integer representation of the data type into a {@link PropertyDataType} instance. 84 | * 85 | * @param i the integer representation of the data type. 86 | * @return a {@link PropertyDataType} instance. 87 | */ 88 | public static PropertyDataType fromInteger(int i) { 89 | switch (i) { 90 | case 1: 91 | return Int8; 92 | case 2: 93 | return Int16; 94 | case 3: 95 | return Int32; 96 | case 4: 97 | return Int64; 98 | case 5: 99 | return UInt8; 100 | case 6: 101 | return UInt16; 102 | case 7: 103 | return UInt32; 104 | case 8: 105 | return UInt64; 106 | case 9: 107 | return Float; 108 | case 10: 109 | return Double; 110 | case 11: 111 | return Boolean; 112 | case 12: 113 | return String; 114 | case 13: 115 | return DateTime; 116 | case 14: 117 | return Text; 118 | case 20: 119 | return PropertySet; 120 | case 21: 121 | return PropertySetList; 122 | default: 123 | return Unknown; 124 | } 125 | } 126 | 127 | /** 128 | * Returns the class type for this DataType 129 | * 130 | * @return the class type for this DataType 131 | */ 132 | public Class getClazz() { 133 | return clazz; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/PropertyValue.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.util.Objects; 17 | 18 | import org.eclipse.tahu.SparkplugInvalidTypeException; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnore; 21 | 22 | /** 23 | * The value of a property in a {@link PropertySet}. 24 | */ 25 | public class PropertyValue { 26 | 27 | private PropertyDataType type; 28 | private Object value; 29 | private Boolean isNull = null; 30 | 31 | public PropertyValue() { 32 | } 33 | 34 | /** 35 | * A constructor. 36 | * 37 | * @param type the property type 38 | * @param value the property value 39 | * @throws SparkplugInvalidTypeException 40 | */ 41 | public PropertyValue(PropertyDataType type, Object value) throws SparkplugInvalidTypeException { 42 | this.type = type; 43 | this.value = value; 44 | isNull = (value == null) ? true : false; 45 | type.checkType(value); 46 | } 47 | 48 | public PropertyDataType getType() { 49 | return type; 50 | } 51 | 52 | public void setType(PropertyDataType type) { 53 | this.type = type; 54 | } 55 | 56 | public Object getValue() { 57 | return value; 58 | } 59 | 60 | public void setValue(Object value) { 61 | this.value = value; 62 | isNull = (value == null) ? true : false; 63 | } 64 | 65 | @JsonIgnore 66 | public Boolean isNull() { 67 | return isNull; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object object) { 72 | if (this == object) { 73 | return true; 74 | } 75 | if (object == null || this.getClass() != object.getClass()) { 76 | return false; 77 | } 78 | PropertyValue propValue = (PropertyValue) object; 79 | return Objects.equals(type, propValue.getType()) && Objects.equals(value, propValue.getValue()); 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | StringBuilder builder = new StringBuilder(); 85 | builder.append("PropertyValue [type="); 86 | builder.append(type); 87 | builder.append(", value="); 88 | builder.append(value); 89 | builder.append(", isNull="); 90 | builder.append(isNull); 91 | builder.append("]"); 92 | return builder.toString(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/Row.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.List; 19 | 20 | /** 21 | * A class for representing a row of a data set. 22 | */ 23 | public class Row { 24 | 25 | private List> values; 26 | 27 | public Row() { 28 | this.values = new ArrayList<>(); 29 | } 30 | 31 | public Row(List> values) { 32 | this.values = values; 33 | } 34 | 35 | public List> getValues() { 36 | return values; 37 | } 38 | 39 | public void setValues(List> values) { 40 | this.values = values; 41 | } 42 | 43 | public void addValue(Value value) { 44 | this.values.add(value); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Row [values=" + values + "]"; 50 | } 51 | 52 | /** 53 | * Converts a {@link Row} instance to a {@link List} of Objects representing the values. 54 | * 55 | * @param row a {@link Row} instance. 56 | * @return a {@link List} of Objects. 57 | */ 58 | public static List toValues(Row row) { 59 | List list = new ArrayList(row.getValues().size()); 60 | for (Value value : row.getValues()) { 61 | list.add(value.getValue()); 62 | } 63 | return list; 64 | } 65 | 66 | /** 67 | * A builder for creating a {@link Row} instance. 68 | */ 69 | public static class RowBuilder { 70 | 71 | private List> values; 72 | 73 | public RowBuilder() { 74 | this.values = new ArrayList>(); 75 | } 76 | 77 | public RowBuilder(Row row) { 78 | this.values = new ArrayList>(row.getValues()); 79 | } 80 | 81 | public RowBuilder addValue(Value value) { 82 | this.values.add(value); 83 | return this; 84 | } 85 | 86 | public RowBuilder addValues(Collection> values) { 87 | this.values.addAll(values); 88 | return this; 89 | } 90 | 91 | public Row createRow() { 92 | return new Row(values); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/Topic.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | import com.fasterxml.jackson.annotation.JsonInclude; 17 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 18 | 19 | /** 20 | * A Sparkplug MQTT Topic 21 | */ 22 | @JsonInclude(Include.NON_NULL) 23 | public class Topic { 24 | 25 | /** 26 | * The Sparkplug namespace version. 27 | */ 28 | private String namespace; 29 | 30 | /** 31 | * The ID of the logical grouping of Edge of Network (EoN) Nodes and devices. 32 | */ 33 | private String groupId; 34 | 35 | /** 36 | * The ID of the Edge of Network (EoN) Node. 37 | */ 38 | private String edgeNodeId; 39 | 40 | /** 41 | * The ID of the device. 42 | */ 43 | private String deviceId; 44 | 45 | /** 46 | * The message type. 47 | */ 48 | private MessageType type; 49 | 50 | /** 51 | * A Constructor. 52 | * 53 | * @param namespace the namespace. 54 | * @param groupId the group ID. 55 | * @param edgeNodeId the edge node ID. 56 | * @param deviceId the device ID. 57 | * @param type the message type. 58 | */ 59 | public Topic(String namespace, String groupId, String edgeNodeId, String deviceId, MessageType type) { 60 | super(); 61 | this.namespace = namespace; 62 | this.groupId = groupId; 63 | this.edgeNodeId = edgeNodeId; 64 | this.deviceId = deviceId; 65 | this.type = type; 66 | } 67 | 68 | /** 69 | * A Constructor. 70 | * 71 | * @param namespace the namespace. 72 | * @param groupId the group ID. 73 | * @param edgeNodeId the edge node ID. 74 | * @param type the message type. 75 | */ 76 | public Topic(String namespace, String groupId, String edgeNodeId, MessageType type) { 77 | super(); 78 | this.namespace = namespace; 79 | this.groupId = groupId; 80 | this.edgeNodeId = edgeNodeId; 81 | this.deviceId = null; 82 | this.type = type; 83 | } 84 | 85 | /** 86 | * Returns the Sparkplug namespace version. 87 | * 88 | * @return the namespace 89 | */ 90 | public String getNamespace() { 91 | return namespace; 92 | } 93 | 94 | /** 95 | * Returns the ID of the logical grouping of Edge of Network (EoN) Nodes and devices. 96 | * 97 | * @return the group ID 98 | */ 99 | public String getGroupId() { 100 | return groupId; 101 | } 102 | 103 | /** 104 | * Returns the ID of the Edge of Network (EoN) Node. 105 | * 106 | * @return the edge node ID 107 | */ 108 | public String getEdgeNodeId() { 109 | return edgeNodeId; 110 | } 111 | 112 | /** 113 | * Returns the ID of the device. 114 | * 115 | * @return the device ID 116 | */ 117 | public String getDeviceId() { 118 | return deviceId; 119 | } 120 | 121 | /** 122 | * Returns the message type. 123 | * 124 | * @return the message type 125 | */ 126 | public MessageType getType() { 127 | return type; 128 | } 129 | 130 | @Override 131 | public String toString() { 132 | StringBuilder sb = new StringBuilder(getNamespace()).append("/").append(getGroupId()).append("/") 133 | .append(getType()).append("/").append(getEdgeNodeId()); 134 | if (getDeviceId() != null) { 135 | sb.append("/").append(getDeviceId()); 136 | } 137 | return sb.toString(); 138 | } 139 | 140 | /** 141 | * Returns true if this topic's type matches the passes in type, false otherwise. 142 | * 143 | * @param type the type to check 144 | * @return true if this topic's type matches the passes in type, false otherwise 145 | */ 146 | public boolean isType(MessageType type) { 147 | return this.type != null && this.type.equals(type); 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/message/model/Value.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.message.model; 15 | 16 | public class Value { 17 | 18 | private DataSetDataType type; 19 | private V value; 20 | 21 | public Value() { 22 | super(); 23 | } 24 | 25 | public Value(DataSetDataType type, V value) { 26 | super(); 27 | this.type = type; 28 | this.value = value; 29 | } 30 | 31 | public DataSetDataType getType() { 32 | return type; 33 | } 34 | 35 | public void setType(DataSetDataType type) { 36 | this.type = type; 37 | } 38 | 39 | public V getValue() { 40 | return value; 41 | } 42 | 43 | public void setValue(V value) { 44 | this.value = value; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | StringBuilder builder = new StringBuilder(); 50 | builder.append("Value [type="); 51 | builder.append(type); 52 | builder.append(", value="); 53 | builder.append(value); 54 | builder.append("]"); 55 | return builder.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/util/CompressionAlgorithm.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2017, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.util; 15 | 16 | /** 17 | * An enumeration of supported payload compression algorithms 18 | */ 19 | public enum CompressionAlgorithm { 20 | 21 | GZIP, 22 | DEFLATE; 23 | 24 | public static CompressionAlgorithm parse(String algorithm) { 25 | return CompressionAlgorithm.valueOf(algorithm.toUpperCase()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/util/GZipUtil.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.util; 15 | 16 | import java.io.ByteArrayInputStream; 17 | import java.io.ByteArrayOutputStream; 18 | import java.util.zip.GZIPInputStream; 19 | import java.util.zip.GZIPOutputStream; 20 | 21 | public class GZipUtil { 22 | 23 | public static byte[] decompress(byte[] compressedData) throws Exception { 24 | ByteArrayInputStream bais = new ByteArrayInputStream(compressedData); 25 | GZIPInputStream gis = null; 26 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 27 | byte[] decompressedData = null; 28 | int bufferSize = 1024; 29 | 30 | try { 31 | gis = new GZIPInputStream(bais); 32 | byte[] buffer = new byte[bufferSize]; 33 | int bytesRead = -1; 34 | while ((bytesRead = gis.read(buffer, 0, bufferSize)) != -1) { 35 | baos.write(buffer, 0, bytesRead); 36 | } 37 | 38 | baos.flush(); 39 | decompressedData = baos.toByteArray(); 40 | } finally { 41 | if (gis != null) { 42 | gis.close(); 43 | } 44 | if (bais != null) { 45 | bais.close(); 46 | } 47 | if (baos != null) { 48 | baos.close(); 49 | } 50 | } 51 | return decompressedData; 52 | } 53 | 54 | public static byte[] compress(byte[] uncompressedData) throws Exception { 55 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 56 | GZIPOutputStream gos = null; 57 | byte[] compressedData = null; 58 | 59 | try { 60 | gos = new GZIPOutputStream(baos); 61 | gos.write(uncompressedData, 0, uncompressedData.length); 62 | gos.finish(); 63 | gos.flush(); 64 | baos.flush(); 65 | compressedData = baos.toByteArray(); 66 | } finally { 67 | if (gos != null) { 68 | gos.close(); 69 | } 70 | if (baos != null) { 71 | baos.close(); 72 | } 73 | } 74 | return compressedData; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /client_libraries/java/src/main/java/org/eclipse/tahu/util/TopicUtil.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2016, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu.util; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import org.eclipse.tahu.SparkplugParsingException; 20 | import org.eclipse.tahu.message.model.MessageType; 21 | import org.eclipse.tahu.message.model.Topic; 22 | 23 | import com.fasterxml.jackson.core.JsonProcessingException; 24 | import com.fasterxml.jackson.databind.ObjectMapper; 25 | 26 | /** 27 | * Provides utility methods for handling Sparkplug MQTT message topics. 28 | */ 29 | public class TopicUtil { 30 | 31 | private static final Map SPLIT_TOPIC_CACHE = new HashMap(); 32 | 33 | public static String[] getSplitTopic(String topic) { 34 | String[] splitTopic = SPLIT_TOPIC_CACHE.get(topic); 35 | if (splitTopic == null) { 36 | splitTopic = topic.split("/"); 37 | SPLIT_TOPIC_CACHE.put(topic, splitTopic); 38 | } 39 | 40 | return splitTopic; 41 | } 42 | 43 | /** 44 | * Serializes a {@link Topic} instance in to a JSON string. 45 | * 46 | * @param topic a {@link Topic} instance 47 | * @return a JSON string 48 | * @throws JsonProcessingException 49 | */ 50 | public static String toJsonString(Topic topic) throws JsonProcessingException { 51 | ObjectMapper mapper = new ObjectMapper(); 52 | return mapper.writeValueAsString(topic); 53 | } 54 | 55 | /** 56 | * Parses a Sparkplug MQTT message topic string and returns a {@link Topic} instance. 57 | * 58 | * @param topic a topic string 59 | * @return a {@link Topic} instance 60 | * @throws SparkplugParsingException if an error occurs while parsing 61 | */ 62 | public static Topic parseTopic(String topic) throws SparkplugParsingException { 63 | return parseTopic(TopicUtil.getSplitTopic(topic)); 64 | } 65 | 66 | /** 67 | * Parses a Sparkplug MQTT message topic string and returns a {@link Topic} instance. 68 | * 69 | * @param splitTopic a topic split into tokens 70 | * @return a {@link Topic} instance 71 | * @throws SparkplugParsingException if an error occurs while parsing 72 | */ 73 | @SuppressWarnings("incomplete-switch") 74 | public static Topic parseTopic(String[] splitTopic) throws SparkplugParsingException { 75 | MessageType type; 76 | String namespace, edgeNodeId, groupId; 77 | int length = splitTopic.length; 78 | 79 | if (length < 4 || length > 5) { 80 | throw new SparkplugParsingException("Invalid number of topic elements: " + length); 81 | } 82 | 83 | namespace = splitTopic[0]; 84 | groupId = splitTopic[1]; 85 | type = MessageType.parseMessageType(splitTopic[2]); 86 | edgeNodeId = splitTopic[3]; 87 | 88 | if (length == 4) { 89 | // A node topic 90 | switch (type) { 91 | case STATE: 92 | case NBIRTH: 93 | case NCMD: 94 | case NDATA: 95 | case NDEATH: 96 | case NRECORD: 97 | return new Topic(namespace, groupId, edgeNodeId, type); 98 | } 99 | } else { 100 | // A device topic 101 | switch (type) { 102 | case STATE: 103 | case DBIRTH: 104 | case DCMD: 105 | case DDATA: 106 | case DDEATH: 107 | case DRECORD: 108 | return new Topic(namespace, groupId, edgeNodeId, splitTopic[4], type); 109 | } 110 | } 111 | throw new SparkplugParsingException("Invalid number of topic elements " + length + " for topic type " + type); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /client_libraries/javascript/node-red-contrib-sparkplug/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-red-contrib-sparkplug", 3 | "version": "2.1.1", 4 | "description": "A Sparkplug node for Node-RED", 5 | "license": "EPL-2.0", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/eclipse/tahu.git" 9 | }, 10 | "node-red": { 11 | "nodes": { 12 | "sparkplug": "sparkplug/sparkplug.js" 13 | } 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/eclipse/tahu/issues" 17 | }, 18 | "homepage": "https://github.com/eclipse/tahu", 19 | "main": "sparkplug.js", 20 | "keywords": [ 21 | "tahu", 22 | "mqtt", 23 | "sparkplug", 24 | "node-red" 25 | ], 26 | "author": "Chad Kienle (http://www.cirrus-link.com)", 27 | "dependencies": { 28 | "sparkplug-client": "^3.0.0" 29 | }, 30 | "files": [ 31 | "sparkplug/sparkplug.html", 32 | "sparkplug/sparkplug.js", 33 | "LICENSE", 34 | "README.md" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /client_libraries/javascript/sparkplug-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sparkplug-client", 3 | "version": "3.2.2", 4 | "description": "A client module for MQTT communication using the Sparkplug specification from Cirrus Link Solutions", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/eclipse/tahu.git" 9 | }, 10 | "keywords": [ 11 | "tahu", 12 | "mqtt", 13 | "sparkplug" 14 | ], 15 | "author": "Chad Kienle (http://www.cirrus-link.com)", 16 | "license": "EPL-2.0", 17 | "bugs": { 18 | "url": "https://github.com/eclipse/tahu/issues" 19 | }, 20 | "homepage": "https://github.com/eclipse/tahu", 21 | "files": [ 22 | "index.js", 23 | "README.md", 24 | "LICENSE" 25 | ], 26 | "dependencies": { 27 | "mqtt": "^2.16.0", 28 | "sparkplug-payload": "^1.0.1", 29 | "pako": "^1.0.6", 30 | "winston": "^2.4.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client_libraries/javascript/sparkplug-payload/README.md: -------------------------------------------------------------------------------- 1 | Sparkplug Payload 2 | ========= 3 | 4 | A library that provides tools for encoding and decoding payload objects using 5 | the Sparkplug Google Protocol Buffer Schema described in the Sparkplug 6 | Specification from Cirrus Link Solutions. 7 | 8 | https://s3.amazonaws.com/cirrus-link-com/Sparkplug+Topic+Namespace+and+State+ManagementV2.1+Apendix++Payload+B+format.pdf 9 | 10 | ## Installation 11 | 12 | npm install sparkplug-b-payload 13 | 14 | ## Usage 15 | 16 | This library supports the Sparkplug Google Protocol Buffer Schemas for the 17 | following Sparkplug namespaces: 18 | 19 | * spBv1.0 20 | * spAv1.0 (deprecated) 21 | 22 | 23 | ### Encoding a payload 24 | 25 | Here is a code example of encoding a payload: 26 | 27 | ```javascript 28 | var sparkplug = require('sparkplug-payload').get("spBv1.0"), 29 | payload = { 30 | "timestamp" : new Date().getTime(), 31 | "metrics" : [ 32 | { 33 | "name" : "intMetric", 34 | "value" : 1, 35 | "type" : "Int32" 36 | } 37 | ] 38 | }, 39 | encoded = sparkplug.encodePayload(payload); 40 | ``` 41 | 42 | ### Decoding a payload 43 | 44 | Here is a code example of decoding an encoded payload: 45 | 46 | ```javascript 47 | var decoded = sparkplug.decodePayload(encoded); 48 | ``` 49 | 50 | ## Release History 51 | 52 | * 1.0.0 Initial release 53 | 54 | ## License 55 | 56 | Copyright (c) 2017 Cirrus Link Solutions 57 | 58 | All rights reserved. This program and the accompanying materials 59 | are made available under the terms of the Eclipse Public License v1.0 60 | which accompanies this distribution, and is available at 61 | http://www.eclipse.org/legal/epl-v10.html 62 | 63 | Contributors: Cirrus Link Solutions 64 | -------------------------------------------------------------------------------- /client_libraries/javascript/sparkplug-payload/index.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2017, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | var sparkplugbpayload = require('./lib/sparkplugbpayload.js'); 15 | 16 | exports.get = function(namespace) { 17 | if (namespace !== undefined && namespace !== null) { 18 | if (namespace === "spBv1.0") { 19 | return sparkplugbpayload; 20 | } 21 | } 22 | return null; 23 | }; 24 | -------------------------------------------------------------------------------- /client_libraries/javascript/sparkplug-payload/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sparkplug-payload", 3 | "version": "1.0.1", 4 | "description": "A library for encoding and decoding Sparkplug payloads", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/eclipse/tahu.git" 9 | }, 10 | "keywords": [ 11 | "tahu", 12 | "mqtt", 13 | "sparkplug", 14 | "payload" 15 | ], 16 | "author": "Chad Kienle (http://www.cirrus-link.com)", 17 | "license": "EPL-2.0", 18 | "bugs": { 19 | "url": "https://github.com/eclipse/tahu/issues" 20 | }, 21 | "homepage": "https://github.com/eclipse/tahu", 22 | "files": [ 23 | "index.js", 24 | "lib/sparkplugbpayload.js", 25 | "README.md", 26 | "LICENSE" 27 | ], 28 | "dependencies": { 29 | "protobufjs": "^6.8.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client_libraries/python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/client_libraries/python/__init__.py -------------------------------------------------------------------------------- /client_libraries/python/__pycache__/sparkplug_b.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/client_libraries/python/__pycache__/sparkplug_b.cpython-36.pyc -------------------------------------------------------------------------------- /client_libraries/python/__pycache__/sparkplug_b_pb2.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/client_libraries/python/__pycache__/sparkplug_b_pb2.cpython-36.pyc -------------------------------------------------------------------------------- /client_libraries/python/readme.txt: -------------------------------------------------------------------------------- 1 | # To generate the base protobuf sparkplug_b Python library 2 | protoc -I=../../sparkplug_b/ --python_out=. ../../sparkplug_b/sparkplug_b.proto 3 | -------------------------------------------------------------------------------- /client_libraries/python/sparkplug_b.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/client_libraries/python/sparkplug_b.pyc -------------------------------------------------------------------------------- /client_libraries/python/sparkplug_b_pb2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/client_libraries/python/sparkplug_b_pb2.pyc -------------------------------------------------------------------------------- /common/FPS.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | import time 24 | start_time=time.time() 25 | frame_count=0 26 | 27 | class GETFPS: 28 | def __init__(self,stream_id): 29 | global start_time 30 | self.start_time=start_time 31 | self.is_first=True 32 | global frame_count 33 | self.frame_count=frame_count 34 | self.stream_id=stream_id 35 | def get_fps(self): 36 | end_time=time.time() 37 | if(self.is_first): 38 | self.start_time=end_time 39 | self.is_first=False 40 | if(end_time-self.start_time>5): 41 | print("**********************FPS*****************************************") 42 | print("Fps of stream",self.stream_id,"is ", float(self.frame_count)/5.0) 43 | self.frame_count=0 44 | self.start_time=end_time 45 | else: 46 | self.frame_count=self.frame_count+1 47 | def print_data(self): 48 | print('frame_count=',self.frame_count) 49 | print('start_time=',self.start_time) 50 | 51 | -------------------------------------------------------------------------------- /common/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__init__.py -------------------------------------------------------------------------------- /common/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__init__.pyc -------------------------------------------------------------------------------- /common/__pycache__/FPS.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__pycache__/FPS.cpython-36.pyc -------------------------------------------------------------------------------- /common/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /common/__pycache__/bus_call.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__pycache__/bus_call.cpython-36.pyc -------------------------------------------------------------------------------- /common/__pycache__/is_aarch_64.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__pycache__/is_aarch_64.cpython-36.pyc -------------------------------------------------------------------------------- /common/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /common/bus_call.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | import gi 24 | import sys 25 | gi.require_version('Gst', '1.0') 26 | from gi.repository import GObject, Gst 27 | def bus_call(bus, message, loop): 28 | t = message.type 29 | if t == Gst.MessageType.EOS: 30 | sys.stdout.write("End-of-stream\n") 31 | loop.quit() 32 | elif t==Gst.MessageType.WARNING: 33 | err, debug = message.parse_warning() 34 | sys.stderr.write("Warning: %s: %s\n" % (err, debug)) 35 | elif t == Gst.MessageType.ERROR: 36 | err, debug = message.parse_error() 37 | sys.stderr.write("Error: %s: %s\n" % (err, debug)) 38 | loop.quit() 39 | return True 40 | -------------------------------------------------------------------------------- /common/bus_call.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/bus_call.pyc -------------------------------------------------------------------------------- /common/is_aarch_64.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | import platform 24 | import sys 25 | 26 | 27 | def is_aarch64(): 28 | return platform.uname()[4] == 'aarch64' 29 | 30 | sys.path.append('/opt/nvidia/deepstream/deepstream/lib') 31 | -------------------------------------------------------------------------------- /common/is_aarch_64.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/common/is_aarch_64.pyc -------------------------------------------------------------------------------- /common/utils.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | import ctypes 24 | import sys 25 | sys.path.append('/opt/nvidia/deepstream/deepstream/lib') 26 | 27 | def long_to_int(l): 28 | value = ctypes.c_int(l & 0xffffffff).value 29 | return value 30 | -------------------------------------------------------------------------------- /config_infer_primary_yoloV2.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8), model-file-format 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | #0=RGB, 1=BGR 64 | model-color-format=0 65 | custom-network-config=yolov2.cfg 66 | model-file=yolov2.weights 67 | #model-engine-file=yolov2_b1_gpu0_fp32.engine 68 | labelfile-path=labels.txt 69 | ## 0=FP32, 1=INT8, 2=FP16 mode 70 | network-mode=0 71 | num-detected-classes=80 72 | gie-unique-id=1 73 | network-type=0 74 | is-classifier=0 75 | ## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering) 76 | cluster-mode=2 77 | maintain-aspect-ratio=1 78 | parse-bbox-func-name=NvDsInferParseCustomYoloV2 79 | custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so 80 | engine-create-func-name=NvDsInferYoloCudaEngineGet 81 | #scaling-filter=0 82 | #scaling-compute-hw=0 83 | 84 | [class-attrs-all] 85 | nms-iou-threshold=0.3 86 | threshold=0.6 87 | -------------------------------------------------------------------------------- /config_infer_primary_yoloV2_tiny.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8), model-file-format 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | #0=RGB, 1=BGR 64 | model-color-format=0 65 | custom-network-config=yolov2-tiny.cfg 66 | model-file=yolov2-tiny.weights 67 | #model-engine-file=yolov2-tiny_b1_gpu0_fp32.engine 68 | labelfile-path=labels.txt 69 | ## 0=FP32, 1=INT8, 2=FP16 mode 70 | network-mode=0 71 | num-detected-classes=80 72 | gie-unique-id=1 73 | network-type=0 74 | is-classifier=0 75 | ## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering) 76 | cluster-mode=2 77 | maintain-aspect-ratio=1 78 | parse-bbox-func-name=NvDsInferParseCustomYoloV2Tiny 79 | custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so 80 | engine-create-func-name=NvDsInferYoloCudaEngineGet 81 | #scaling-filter=0 82 | #scaling-compute-hw=0 83 | 84 | [class-attrs-all] 85 | nms-iou-threshold=0.2 86 | threshold=0.6 -------------------------------------------------------------------------------- /config_infer_primary_yoloV3.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8), model-file-format 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | #0=RGB, 1=BGR 64 | model-color-format=0 65 | custom-network-config=yolov3.cfg 66 | model-file=yolov3.weights 67 | #model-engine-file=yolov3_b1_gpu0_int8.engine 68 | labelfile-path=labels.txt 69 | int8-calib-file=yolov3-calibration.table.trt7.0 70 | ## 0=FP32, 1=INT8, 2=FP16 mode 71 | network-mode=1 72 | num-detected-classes=80 73 | gie-unique-id=1 74 | network-type=0 75 | is-classifier=0 76 | ## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering) 77 | cluster-mode=2 78 | maintain-aspect-ratio=1 79 | parse-bbox-func-name=NvDsInferParseCustomYoloV3 80 | custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so 81 | engine-create-func-name=NvDsInferYoloCudaEngineGet 82 | #scaling-filter=0 83 | #scaling-compute-hw=0 84 | 85 | [tracker] 86 | enable=1 87 | tracker-width=640 88 | tracker-height=384 89 | ll-lib-file=/opt/nvidia/deepstream/deepstream-5.0/lib/libnvds_mot_klt.s 90 | 91 | [class-attrs-all] 92 | nms-iou-threshold=0.3 93 | threshold=0.7 94 | -------------------------------------------------------------------------------- /config_infer_primary_yoloV3_tiny.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8), model-file-format 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | #0=RGB, 1=BGR 64 | model-color-format=0 65 | custom-network-config=yolov3-tiny.cfg 66 | model-file=yolov3-tiny.weights 67 | #model-engine-file=yolov3-tiny_b1_gpu0_fp32.engine 68 | labelfile-path=labels.txt 69 | ## 0=FP32, 1=INT8, 2=FP16 mode 70 | network-mode=0 71 | num-detected-classes=80 72 | gie-unique-id=1 73 | network-type=0 74 | is-classifier=0 75 | ## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering) 76 | cluster-mode=2 77 | maintain-aspect-ratio=1 78 | parse-bbox-func-name=NvDsInferParseCustomYoloV3Tiny 79 | custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so 80 | engine-create-func-name=NvDsInferYoloCudaEngineGet 81 | #scaling-filter=0 82 | #scaling-compute-hw=0 83 | 84 | [class-attrs-all] 85 | nms-iou-threshold=0.3 86 | threshold=0.7 87 | -------------------------------------------------------------------------------- /config_infer_primary_yoloV3x.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8), model-file-format 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | #0=RGB, 1=BGR 64 | model-color-format=0 65 | custom-network-config=yolov3.cfg 66 | model-file=yolov3.weights 67 | #model-engine-file=yolov3_b1_gpu0_int8.engine 68 | labelfile-path=labels.txt 69 | int8-calib-file=yolov3-calibration.table.trt7.0 70 | ## 0=FP32, 1=INT8, 2=FP16 mode 71 | network-mode=1 72 | num-detected-classes=80 73 | gie-unique-id=1 74 | network-type=0 75 | is-classifier=0 76 | ## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering) 77 | cluster-mode=2 78 | maintain-aspect-ratio=1 79 | parse-bbox-func-name=NvDsInferParseCustomYoloV3 80 | custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so 81 | engine-create-func-name=NvDsInferYoloCudaEngineGet 82 | #scaling-filter=0 83 | #scaling-compute-hw=0 84 | 85 | [class-attrs-all] 86 | nms-iou-threshold=0.3 87 | threshold=0.7 -------------------------------------------------------------------------------- /darknet_19.trt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/darknet_19.trt -------------------------------------------------------------------------------- /deepstream_app_config_yoloV2.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | [application] 24 | enable-perf-measurement=1 25 | perf-measurement-interval-sec=5 26 | #gie-kitti-output-dir=streamscl 27 | 28 | [tiled-display] 29 | enable=1 30 | rows=1 31 | columns=1 32 | width=1280 33 | height=720 34 | gpu-id=0 35 | #(0): nvbuf-mem-default - Default memory allocated, specific to particular platform 36 | #(1): nvbuf-mem-cuda-pinned - Allocate Pinned/Host cuda memory, applicable for Tesla 37 | #(2): nvbuf-mem-cuda-device - Allocate Device cuda memory, applicable for Tesla 38 | #(3): nvbuf-mem-cuda-unified - Allocate Unified cuda memory, applicable for Tesla 39 | #(4): nvbuf-mem-surface-array - Allocate Surface Array memory, applicable for Jetson 40 | nvbuf-memory-type=0 41 | 42 | [source0] 43 | enable=1 44 | #Type - 1=CameraV4L2 2=URI 3=MultiURI 45 | type=3 46 | uri=file://../../samples/streams/sample_1080p_h264.mp4 47 | num-sources=1 48 | gpu-id=0 49 | # (0): memtype_device - Memory type Device 50 | # (1): memtype_pinned - Memory type Host Pinned 51 | # (2): memtype_unified - Memory type Unified 52 | cudadec-memtype=0 53 | 54 | [sink0] 55 | enable=1 56 | #Type - 1=FakeSink 2=EglSink 3=File 57 | type=2 58 | sync=0 59 | source-id=0 60 | gpu-id=0 61 | nvbuf-memory-type=0 62 | 63 | [osd] 64 | enable=1 65 | gpu-id=0 66 | border-width=1 67 | text-size=15 68 | text-color=1;1;1;1; 69 | text-bg-color=0.3;0.3;0.3;1 70 | font=Serif 71 | show-clock=0 72 | clock-x-offset=800 73 | clock-y-offset=820 74 | clock-text-size=12 75 | clock-color=1;0;0;0 76 | nvbuf-memory-type=0 77 | 78 | [streammux] 79 | gpu-id=0 80 | ##Boolean property to inform muxer that sources are live 81 | live-source=0 82 | batch-size=1 83 | ##time out in usec, to wait after the first buffer is available 84 | ##to push the batch even if the complete batch is not formed 85 | batched-push-timeout=40000 86 | ## Set muxer output width and height 87 | width=1920 88 | height=1080 89 | ##Enable to maintain aspect ratio wrt source, and allow black borders, works 90 | ##along with width, height properties 91 | enable-padding=0 92 | nvbuf-memory-type=0 93 | 94 | # config-file property is mandatory for any gie section. 95 | # Other properties are optional and if set will override the properties set in 96 | # the infer config file. 97 | [primary-gie] 98 | enable=1 99 | gpu-id=0 100 | #model-engine-file=model_b1_gpu0_fp32.engine 101 | labelfile-path=labels.txt 102 | batch-size=1 103 | #Required by the app for OSD, not a plugin property 104 | bbox-border-color0=1;0;0;1 105 | bbox-border-color1=0;1;1;1 106 | bbox-border-color2=0;0;1;1 107 | bbox-border-color3=0;1;0;1 108 | interval=2 109 | gie-unique-id=1 110 | nvbuf-memory-type=0 111 | config-file=config_infer_primary_yoloV2.txt 112 | 113 | [tracker] 114 | enable=1 115 | tracker-width=640 116 | tracker-height=384 117 | ll-lib-file=/opt/nvidia/deepstream/deepstream-5.0/lib/libnvds_mot_klt.so 118 | 119 | [tests] 120 | file-loop=0 121 | -------------------------------------------------------------------------------- /deepstream_app_config_yoloV2_tiny.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | [application] 24 | enable-perf-measurement=1 25 | perf-measurement-interval-sec=5 26 | #gie-kitti-output-dir=streamscl 27 | 28 | [tiled-display] 29 | enable=1 30 | rows=1 31 | columns=1 32 | width=1280 33 | height=720 34 | gpu-id=0 35 | #(0): nvbuf-mem-default - Default memory allocated, specific to particular platform 36 | #(1): nvbuf-mem-cuda-pinned - Allocate Pinned/Host cuda memory, applicable for Tesla 37 | #(2): nvbuf-mem-cuda-device - Allocate Device cuda memory, applicable for Tesla 38 | #(3): nvbuf-mem-cuda-unified - Allocate Unified cuda memory, applicable for Tesla 39 | #(4): nvbuf-mem-surface-array - Allocate Surface Array memory, applicable for Jetson 40 | nvbuf-memory-type=0 41 | 42 | [source0] 43 | enable=1 44 | #Type - 1=CameraV4L2 2=URI 3=MultiURI 45 | type=3 46 | uri=file://../../samples/streams/sample_1080p_h264.mp4 47 | num-sources=1 48 | gpu-id=0 49 | # (0): memtype_device - Memory type Device 50 | # (1): memtype_pinned - Memory type Host Pinned 51 | # (2): memtype_unified - Memory type Unified 52 | cudadec-memtype=0 53 | 54 | [sink0] 55 | enable=1 56 | #Type - 1=FakeSink 2=EglSink 3=File 57 | type=2 58 | sync=0 59 | source-id=0 60 | gpu-id=0 61 | nvbuf-memory-type=0 62 | 63 | [osd] 64 | enable=1 65 | gpu-id=0 66 | border-width=1 67 | text-size=15 68 | text-color=1;1;1;1; 69 | text-bg-color=0.3;0.3;0.3;1 70 | font=Serif 71 | show-clock=0 72 | clock-x-offset=800 73 | clock-y-offset=820 74 | clock-text-size=12 75 | clock-color=1;0;0;0 76 | nvbuf-memory-type=0 77 | 78 | [streammux] 79 | gpu-id=0 80 | ##Boolean property to inform muxer that sources are live 81 | live-source=0 82 | batch-size=1 83 | ##time out in usec, to wait after the first buffer is available 84 | ##to push the batch even if the complete batch is not formed 85 | batched-push-timeout=40000 86 | ## Set muxer output width and height 87 | width=1920 88 | height=1080 89 | ##Enable to maintain aspect ratio wrt source, and allow black borders, works 90 | ##along with width, height properties 91 | enable-padding=0 92 | nvbuf-memory-type=0 93 | 94 | # config-file property is mandatory for any gie section. 95 | # Other properties are optional and if set will override the properties set in 96 | # the infer config file. 97 | [primary-gie] 98 | enable=1 99 | gpu-id=0 100 | #model-engine-file=model_b1_gpu0_fp32.engine 101 | labelfile-path=labels.txt 102 | batch-size=1 103 | #Required by the app for OSD, not a plugin property 104 | bbox-border-color0=1;0;0;1 105 | bbox-border-color1=0;1;1;1 106 | bbox-border-color2=0;0;1;1 107 | bbox-border-color3=0;1;0;1 108 | interval=2 109 | gie-unique-id=1 110 | nvbuf-memory-type=0 111 | config-file=config_infer_primary_yoloV2_tiny.txt 112 | 113 | [tracker] 114 | enable=1 115 | tracker-width=640 116 | tracker-height=384 117 | ll-lib-file=/opt/nvidia/deepstream/deepstream-5.0/lib/libnvds_mot_klt.so 118 | 119 | [tests] 120 | file-loop=0 121 | -------------------------------------------------------------------------------- /deepstream_app_config_yoloV3.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | [application] 24 | enable-perf-measurement=1 25 | perf-measurement-interval-sec=5 26 | #gie-kitti-output-dir=streamscl 27 | 28 | [tiled-display] 29 | enable=1 30 | rows=1 31 | columns=1 32 | width=1280 33 | height=720 34 | gpu-id=0 35 | #(0): nvbuf-mem-default - Default memory allocated, specific to particular platform 36 | #(1): nvbuf-mem-cuda-pinned - Allocate Pinned/Host cuda memory, applicable for Tesla 37 | #(2): nvbuf-mem-cuda-device - Allocate Device cuda memory, applicable for Tesla 38 | #(3): nvbuf-mem-cuda-unified - Allocate Unified cuda memory, applicable for Tesla 39 | #(4): nvbuf-mem-surface-array - Allocate Surface Array memory, applicable for Jetson 40 | nvbuf-memory-type=0 41 | 42 | [source0] 43 | enable=1 44 | #Type - 1=CameraV4L2 2=URI 3=MultiURI 45 | type=3 46 | uri=file://../../samples/streams/bird1.mp4 47 | num-sources=1 48 | gpu-id=0 49 | # (0): memtype_device - Memory type Device 50 | # (1): memtype_pinned - Memory type Host Pinned 51 | # (2): memtype_unified - Memory type Unified 52 | cudadec-memtype=0 53 | 54 | [sink0] 55 | enable=1 56 | #Type - 1=FakeSink 2=EglSink 3=File 57 | type=2 58 | sync=0 59 | source-id=0 60 | gpu-id=0 61 | nvbuf-memory-type=0 62 | 63 | [osd] 64 | enable=1 65 | gpu-id=0 66 | border-width=1 67 | text-size=15 68 | text-color=1;1;1;1; 69 | text-bg-color=0.3;0.3;0.3;1 70 | font=Serif 71 | show-clock=0 72 | clock-x-offset=800 73 | clock-y-offset=820 74 | clock-text-size=12 75 | clock-color=1;0;0;0 76 | nvbuf-memory-type=0 77 | 78 | [streammux] 79 | gpu-id=0 80 | ##Boolean property to inform muxer that sources are live 81 | live-source=0 82 | batch-size=1 83 | ##time out in usec, to wait after the first buffer is available 84 | ##to push the batch even if the complete batch is not formed 85 | batched-push-timeout=40000 86 | ## Set muxer output width and height 87 | width=1920 88 | height=1080 89 | ##Enable to maintain aspect ratio wrt source, and allow black borders, works 90 | ##along with width, height properties 91 | enable-padding=0 92 | nvbuf-memory-type=0 93 | 94 | # config-file property is mandatory for any gie section. 95 | # Other properties are optional and if set will override the properties set in 96 | # the infer config file. 97 | [primary-gie] 98 | enable=1 99 | gpu-id=0 100 | #model-engine-file=model_b1_gpu0_int8.engine 101 | labelfile-path=labels.txt 102 | batch-size=1 103 | #Required by the app for OSD, not a plugin property 104 | bbox-border-color0=1;0;0;1 105 | bbox-border-color1=0;1;1;1 106 | bbox-border-color2=0;0;1;1 107 | bbox-border-color3=0;1;0;1 108 | interval=2 109 | gie-unique-id=1 110 | nvbuf-memory-type=0 111 | config-file=config_infer_primary_yoloV3.txt 112 | 113 | [tracker] 114 | enable=1 115 | tracker-width=640 116 | tracker-height=384 117 | ll-lib-file=/opt/nvidia/deepstream/deepstream-5.0/lib/libnvds_mot_klt.so 118 | 119 | [tests] 120 | file-loop=0 121 | -------------------------------------------------------------------------------- /dstest1_pgie_config.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8) 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path, 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | model-file=../../../../samples/models/Primary_Detector/resnet10.caffemodel 64 | proto-file=../../../../samples/models/Primary_Detector/resnet10.prototxt 65 | model-engine-file=../../../../samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine 66 | labelfile-path=../../../../samples/models/Primary_Detector/labels.txt 67 | int8-calib-file=../../../../samples/models/Primary_Detector/cal_trt.bin 68 | force-implicit-batch-dim=1 69 | batch-size=1 70 | network-mode=1 71 | num-detected-classes=4 72 | interval=0 73 | gie-unique-id=1 74 | output-blob-names=conv2d_bbox;conv2d_cov/Sigmoid 75 | #scaling-filter=0 76 | #scaling-compute-hw=0 77 | 78 | [class-attrs-all] 79 | pre-cluster-threshold=0.2 80 | eps=0.2 81 | group-threshold=1 82 | -------------------------------------------------------------------------------- /dstest1_pgie_config_rtsp.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | # Following properties are mandatory when engine files are not specified: 24 | # int8-calib-file(Only in INT8) 25 | # Caffemodel mandatory properties: model-file, proto-file, output-blob-names 26 | # UFF: uff-file, input-dims, uff-input-blob-name, output-blob-names 27 | # ONNX: onnx-file 28 | # 29 | # Mandatory properties for detectors: 30 | # num-detected-classes 31 | # 32 | # Optional properties for detectors: 33 | # cluster-mode(Default=Group Rectangles), interval(Primary mode only, Default=0) 34 | # custom-lib-path, 35 | # parse-bbox-func-name 36 | # 37 | # Mandatory properties for classifiers: 38 | # classifier-threshold, is-classifier 39 | # 40 | # Optional properties for classifiers: 41 | # classifier-async-mode(Secondary mode only, Default=false) 42 | # 43 | # Optional properties in secondary mode: 44 | # operate-on-gie-id(Default=0), operate-on-class-ids(Defaults to all classes), 45 | # input-object-min-width, input-object-min-height, input-object-max-width, 46 | # input-object-max-height 47 | # 48 | # Following properties are always recommended: 49 | # batch-size(Default=1) 50 | # 51 | # Other optional properties: 52 | # net-scale-factor(Default=1), network-mode(Default=0 i.e FP32), 53 | # model-color-format(Default=0 i.e. RGB) model-engine-file, labelfile-path, 54 | # mean-file, gie-unique-id(Default=0), offsets, process-mode (Default=1 i.e. primary), 55 | # custom-lib-path, network-mode(Default=0 i.e FP32) 56 | # 57 | # The values in the config file are overridden by values set through GObject 58 | # properties. 59 | 60 | [property] 61 | gpu-id=0 62 | net-scale-factor=0.0039215697906911373 63 | model-file=../../../../samples/models/Primary_Detector/resnet10.caffemodel 64 | proto-file=../../../../samples/models/Primary_Detector/resnet10.prototxt 65 | model-engine-file=../../../../samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine 66 | labelfile-path=../../../../samples/models/Primary_Detector/labels.txt 67 | int8-calib-file=../../../../samples/models/Primary_Detector/cal_trt.bin 68 | force-implicit-batch-dim=1 69 | batch-size=1 70 | network-mode=1 71 | num-detected-classes=4 72 | interval=0 73 | gie-unique-id=1 74 | output-blob-names=conv2d_bbox;conv2d_cov/Sigmoid 75 | #scaling-filter=0 76 | #scaling-compute-hw=0 77 | 78 | [class-attrs-all] 79 | pre-cluster-threshold=0.2 80 | eps=0.2 81 | group-threshold=1 82 | -------------------------------------------------------------------------------- /labels.txt: -------------------------------------------------------------------------------- 1 | person 2 | bicycle 3 | car 4 | motorbike 5 | aeroplane 6 | bus 7 | train 8 | truck 9 | boat 10 | traffic light 11 | fire hydrant 12 | stop sign 13 | parking meter 14 | bench 15 | bird 16 | cat 17 | dog 18 | horse 19 | sheep 20 | cow 21 | elephant 22 | bear 23 | zebra 24 | giraffe 25 | backpack 26 | umbrella 27 | handbag 28 | tie 29 | suitcase 30 | frisbee 31 | skis 32 | snowboard 33 | sports ball 34 | kite 35 | baseball bat 36 | baseball glove 37 | skateboard 38 | surfboard 39 | tennis racket 40 | bottle 41 | wine glass 42 | cup 43 | fork 44 | knife 45 | spoon 46 | bowl 47 | banana 48 | apple 49 | sandwich 50 | orange 51 | broccoli 52 | carrot 53 | hot dog 54 | pizza 55 | donut 56 | cake 57 | chair 58 | sofa 59 | pottedplant 60 | bed 61 | diningtable 62 | toilet 63 | tvmonitor 64 | laptop 65 | mouse 66 | remote 67 | keyboard 68 | cell phone 69 | microwave 70 | oven 71 | toaster 72 | sink 73 | refrigerator 74 | book 75 | clock 76 | vase 77 | scissors 78 | teddy bear 79 | hair drier 80 | toothbrush 81 | -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | ################################################################################ 22 | 23 | CUDA_VER?= 24 | ifeq ($(CUDA_VER),) 25 | $(error "CUDA_VER is not set") 26 | endif 27 | CC:= g++ 28 | NVCC:=/usr/local/cuda-$(CUDA_VER)/bin/nvcc 29 | 30 | CFLAGS:= -Wall -std=c++11 -shared -fPIC -Wno-error=deprecated-declarations 31 | CFLAGS+= -I../../includes -I/usr/local/cuda-$(CUDA_VER)/include 32 | 33 | LIBS:= -lnvinfer_plugin -lnvinfer -lnvparsers -L/usr/local/cuda-$(CUDA_VER)/lib64 -lcudart -lcublas -lstdc++fs 34 | LFLAGS:= -shared -Wl,--start-group $(LIBS) -Wl,--end-group 35 | 36 | INCS:= $(wildcard *.h) 37 | SRCFILES:= nvdsinfer_yolo_engine.cpp \ 38 | nvdsparsebbox_Yolo.cpp \ 39 | yoloPlugins.cpp \ 40 | trt_utils.cpp \ 41 | yolo.cpp \ 42 | kernels.cu 43 | TARGET_LIB:= libnvdsinfer_custom_impl_Yolo.so 44 | 45 | TARGET_OBJS:= $(SRCFILES:.cpp=.o) 46 | TARGET_OBJS:= $(TARGET_OBJS:.cu=.o) 47 | 48 | all: $(TARGET_LIB) 49 | 50 | %.o: %.cpp $(INCS) Makefile 51 | $(CC) -c -o $@ $(CFLAGS) $< 52 | 53 | %.o: %.cu $(INCS) Makefile 54 | $(NVCC) -c -o $@ --compiler-options '-fPIC' $< 55 | 56 | $(TARGET_LIB) : $(TARGET_OBJS) 57 | $(CC) -o $@ $(TARGET_OBJS) $(LFLAGS) 58 | 59 | clean: 60 | rm -rf $(TARGET_LIB) 61 | -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/kernels.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved. 3 | * 4 | * NVIDIA Corporation and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA Corporation is strictly prohibited. 9 | * 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | inline __device__ float sigmoidGPU(const float& x) { return 1.0f / (1.0f + __expf(-x)); } 19 | 20 | __global__ void gpuYoloLayerV3(const float* input, float* output, const uint gridSize, const uint numOutputClasses, 21 | const uint numBBoxes) 22 | { 23 | uint x_id = blockIdx.x * blockDim.x + threadIdx.x; 24 | uint y_id = blockIdx.y * blockDim.y + threadIdx.y; 25 | uint z_id = blockIdx.z * blockDim.z + threadIdx.z; 26 | 27 | if ((x_id >= gridSize) || (y_id >= gridSize) || (z_id >= numBBoxes)) 28 | { 29 | return; 30 | } 31 | 32 | const int numGridCells = gridSize * gridSize; 33 | const int bbindex = y_id * gridSize + x_id; 34 | 35 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)] 36 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]); 37 | 38 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)] 39 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]); 40 | 41 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)] 42 | = __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]); 43 | 44 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)] 45 | = __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]); 46 | 47 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)] 48 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]); 49 | 50 | for (uint i = 0; i < numOutputClasses; ++i) 51 | { 52 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))] 53 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]); 54 | } 55 | } 56 | 57 | cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize, 58 | const uint& numOutputClasses, const uint& numBBoxes, 59 | uint64_t outputSize, cudaStream_t stream); 60 | 61 | cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize, 62 | const uint& numOutputClasses, const uint& numBBoxes, 63 | uint64_t outputSize, cudaStream_t stream) 64 | { 65 | dim3 threads_per_block(16, 16, 4); 66 | dim3 number_of_blocks((gridSize / threads_per_block.x) + 1, 67 | (gridSize / threads_per_block.y) + 1, 68 | (numBBoxes / threads_per_block.z) + 1); 69 | for (unsigned int batch = 0; batch < batchSize; ++batch) 70 | { 71 | gpuYoloLayerV3<<>>( 72 | reinterpret_cast(input) + (batch * outputSize), 73 | reinterpret_cast(output) + (batch * outputSize), gridSize, numOutputClasses, 74 | numBBoxes); 75 | } 76 | return cudaGetLastError(); 77 | } 78 | -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/kernels.o -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/nvdsinfer_yolo_engine.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/nvdsinfer_yolo_engine.o -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/nvdsparsebbox_Yolo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/nvdsparsebbox_Yolo.o -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/trt_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | 24 | #ifndef __TRT_UTILS_H__ 25 | #define __TRT_UTILS_H__ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "NvInfer.h" 36 | 37 | #define UNUSED(expr) (void)(expr) 38 | #define DIVUP(n, d) ((n) + (d)-1) / (d) 39 | 40 | std::string trim(std::string s); 41 | float clamp(const float val, const float minVal, const float maxVal); 42 | bool fileExists(const std::string fileName, bool verbose = true); 43 | std::vector loadWeights(const std::string weightsFilePath, const std::string& networkType); 44 | std::string dimsToString(const nvinfer1::Dims d); 45 | void displayDimType(const nvinfer1::Dims d); 46 | int getNumChannels(nvinfer1::ITensor* t); 47 | uint64_t get3DTensorVolume(nvinfer1::Dims inputDims); 48 | 49 | // Helper functions to create yolo engine 50 | nvinfer1::ILayer* netAddMaxpool(int layerIdx, std::map& block, 51 | nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network); 52 | nvinfer1::ILayer* netAddConvLinear(int layerIdx, std::map& block, 53 | std::vector& weights, 54 | std::vector& trtWeights, int& weightPtr, 55 | int& inputChannels, nvinfer1::ITensor* input, 56 | nvinfer1::INetworkDefinition* network); 57 | nvinfer1::ILayer* netAddConvBNLeaky(int layerIdx, std::map& block, 58 | std::vector& weights, 59 | std::vector& trtWeights, int& weightPtr, 60 | int& inputChannels, nvinfer1::ITensor* input, 61 | nvinfer1::INetworkDefinition* network); 62 | nvinfer1::ILayer* netAddUpsample(int layerIdx, std::map& block, 63 | std::vector& weights, 64 | std::vector& trtWeights, int& inputChannels, 65 | nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network); 66 | void printLayerInfo(std::string layerIndex, std::string layerName, std::string layerInput, 67 | std::string layerOutput, std::string weightPtr); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/trt_utils.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/trt_utils.o -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/yolo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _YOLO_H_ 24 | #define _YOLO_H_ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "NvInfer.h" 32 | #include "trt_utils.h" 33 | 34 | #include "nvdsinfer_custom_impl.h" 35 | 36 | /** 37 | * Holds all the file paths required to build a network. 38 | */ 39 | struct NetworkInfo 40 | { 41 | std::string networkType; 42 | std::string configFilePath; 43 | std::string wtsFilePath; 44 | std::string deviceType; 45 | std::string inputBlobName; 46 | }; 47 | 48 | /** 49 | * Holds information about an output tensor of the yolo network. 50 | */ 51 | struct TensorInfo 52 | { 53 | std::string blobName; 54 | uint stride{0}; 55 | uint gridSize{0}; 56 | uint numClasses{0}; 57 | uint numBBoxes{0}; 58 | uint64_t volume{0}; 59 | std::vector masks; 60 | std::vector anchors; 61 | int bindingIndex{-1}; 62 | float* hostBuffer{nullptr}; 63 | }; 64 | 65 | class Yolo : public IModelParser { 66 | public: 67 | Yolo(const NetworkInfo& networkInfo); 68 | ~Yolo() override; 69 | bool hasFullDimsSupported() const override { return false; } 70 | const char* getModelName() const override { 71 | return m_ConfigFilePath.empty() ? m_NetworkType.c_str() 72 | : m_ConfigFilePath.c_str(); 73 | } 74 | NvDsInferStatus parseModel(nvinfer1::INetworkDefinition& network) override; 75 | 76 | nvinfer1::ICudaEngine *createEngine (nvinfer1::IBuilder* builder); 77 | 78 | protected: 79 | const std::string m_NetworkType; 80 | const std::string m_ConfigFilePath; 81 | const std::string m_WtsFilePath; 82 | const std::string m_DeviceType; 83 | const std::string m_InputBlobName; 84 | std::vector m_OutputTensors; 85 | std::vector> m_ConfigBlocks; 86 | uint m_InputH; 87 | uint m_InputW; 88 | uint m_InputC; 89 | uint64_t m_InputSize; 90 | 91 | // TRT specific members 92 | std::vector m_TrtWeights; 93 | 94 | private: 95 | NvDsInferStatus buildYoloNetwork( 96 | std::vector& weights, nvinfer1::INetworkDefinition& network); 97 | std::vector> parseConfigFile( 98 | const std::string cfgFilePath); 99 | void parseConfigBlocks(); 100 | void destroyNetworkUtils(); 101 | }; 102 | 103 | #endif // _YOLO_H_ 104 | -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/yolo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/yolo.o -------------------------------------------------------------------------------- /nvdsinfer_custom_impl_Yolo/yoloPlugins.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nvdsinfer_custom_impl_Yolo/yoloPlugins.o -------------------------------------------------------------------------------- /nx_2021-01-29_1525.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/nx_2021-01-29_1525.zip -------------------------------------------------------------------------------- /prebuild.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a 7 | # copy of this software and associated documentation files (the "Software"), 8 | # to deal in the Software without restriction, including without limitation 9 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | # and/or sell copies of the Software, and to permit persons to whom the 11 | # Software is furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in 14 | # all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | # DEALINGS IN THE SOFTWARE. 23 | ################################################################################ 24 | 25 | # Download yolo weights 26 | # For yolo v2, 27 | echo "Downloading yolov2 config and weights files ... " 28 | wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2.cfg -q --show-progress 29 | wget https://pjreddie.com/media/files/yolov2.weights -q --show-progress 30 | 31 | # For yolo v2 tiny, 32 | echo "Downloading yolov2-tiny config and weights files ... " 33 | wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2-tiny.cfg -q --show-progress 34 | wget https://pjreddie.com/media/files/yolov2-tiny.weights -q --show-progress 35 | 36 | # For yolo v3, 37 | echo "Downloading yolov3 config and weights files ... " 38 | wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg -q --show-progress 39 | wget https://pjreddie.com/media/files/yolov3.weights -q --show-progress 40 | 41 | # For yolo v3 tiny, 42 | echo "Downloading yolov3-tiny config and weights files ... " 43 | wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3-tiny.cfg -q --show-progress 44 | wget https://pjreddie.com/media/files/yolov3-tiny.weights -q --show-progress 45 | -------------------------------------------------------------------------------- /sparkplug_b.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/sparkplug_b.pyc -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/THIRD-PARTY.txt: -------------------------------------------------------------------------------- 1 | 2 | Lists of 5 third-party dependencies. 3 | (New BSD license) Protocol Buffer Java API (com.google.protobuf:protobuf-java:2.6.1 - https://developers.google.com/protocol-buffers/) 4 | (The Apache Software License, Version 2.0) Apache Log4j (log4j:log4j:1.2.17 - http://logging.apache.org/log4j/1.2/) 5 | (Eclipse Public License - Version 1.0) org.eclipse.paho.client.mqttv3 (org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 - http://www.eclipse.org/paho/org.eclipse.paho.client.mqttv3) 6 | (MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.5 - http://www.slf4j.org) 7 | (MIT License) SLF4J LOG4J-12 Binding (org.slf4j:slf4j-log4j12:1.7.5 - http://www.slf4j.org) 8 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/dio/DigitalOutputPin.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.dio; 14 | 15 | /** 16 | * Defines digital output pin 17 | */ 18 | public class DigitalOutputPin extends DioPin { 19 | 20 | public DigitalOutputPin(String name) { 21 | super(name); 22 | } 23 | 24 | /** 25 | * Sets pin high 26 | * 27 | * @throws DioException 28 | */ 29 | public void setHigh() throws DioException { 30 | try { 31 | getGpioPin().setValue(true); 32 | } catch (Exception e) { 33 | throw new DioException("failed to set " + getPinName() + " HIGH", e); 34 | } 35 | } 36 | 37 | /** 38 | * Sets pin low 39 | * 40 | * @throws DioException 41 | */ 42 | public void setLow() throws DioException { 43 | try { 44 | getGpioPin().setValue(false); 45 | } catch (Exception e) { 46 | throw new DioException("failed to set " + getPinName() + " LOW", e); 47 | } 48 | } 49 | 50 | /** 51 | * Sets pin state 52 | * 53 | * @param state - pin state as {@link boolean} 54 | * @throws DioException 55 | */ 56 | public void setState(boolean state) throws DioException { 57 | try { 58 | getGpioPin().setValue(state); 59 | } catch (Exception e) { 60 | throw new DioException("failed to set state of " + getPinName() + " to " + state, e); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/dio/DioException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.dio; 14 | 15 | /** 16 | * Defines DIO Exception 17 | */ 18 | public class DioException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public DioException(String msg) { 23 | super(msg); 24 | } 25 | 26 | public DioException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/dio/DioPin.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.dio; 14 | 15 | import jdk.dio.DeviceManager; 16 | import jdk.dio.gpio.GPIOPin; 17 | import jdk.dio.gpio.GPIOPinConfig; 18 | 19 | /** 20 | * Defines digital I/O pin 21 | */ 22 | public class DioPin { 23 | 24 | private String pinName; 25 | private GPIOPin gpioPin; 26 | 27 | public DioPin(String name) { 28 | this.pinName = name; 29 | } 30 | 31 | /** 32 | * Reports pin name 33 | * 34 | * @return pin name as {@link String} 35 | */ 36 | public String getPinName() { 37 | return this.pinName; 38 | } 39 | 40 | /** 41 | * Gets GPIO pin 42 | * 43 | * @return GPIO pin as {@link GPIOPin} 44 | */ 45 | public GPIOPin getGpioPin() { 46 | return this.gpioPin; 47 | } 48 | 49 | /** 50 | * Sets GPIO pin 51 | * 52 | * @param gpioPin - GPIO pin as {@link GPIOPin} 53 | */ 54 | public void setGpioPin(GPIOPin gpioPin) { 55 | this.gpioPin = gpioPin; 56 | } 57 | 58 | public static GPIOPin open(String pinName, GPIOPinConfig gpioPinConfig) throws DioException { 59 | GPIOPin pin; 60 | try { 61 | pin = DeviceManager.open(GPIOPin.class, gpioPinConfig); 62 | } catch (Exception e) { 63 | throw new DioException("failed to open GPIO pin: " + pinName, e); 64 | } 65 | return pin; 66 | } 67 | 68 | /** 69 | * Closes GPIO pin 70 | * 71 | * @throws DioException 72 | */ 73 | public void close() throws DioException { 74 | try { 75 | if (this.gpioPin.isOpen()) { 76 | this.gpioPin.close(); 77 | } 78 | } catch (Exception e) { 79 | throw new DioException("failed to close " + this.pinName, e); 80 | } 81 | } 82 | 83 | /** 84 | * Reports if GPIO pin state 85 | * 86 | * @return GPIO pin state as {@link boolean} 87 | * @throws DioException 88 | */ 89 | public boolean isHigh() throws DioException { 90 | boolean ret = false; 91 | try { 92 | ret = this.gpioPin.getValue(); 93 | } catch (Exception e) { 94 | throw new DioException("Failed obtain a state of " + this.pinName, e); 95 | } 96 | return ret; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/dio/PinDirection.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.dio; 14 | 15 | /** 16 | * Enumerates DPIO pin directions 17 | */ 18 | public enum PinDirection { 19 | INPUT, OUTPUT; 20 | } 21 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/dio/Pins.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.dio; 14 | 15 | /** 16 | * Enumerates Raspbery Pi pins 17 | */ 18 | public enum Pins { 19 | P3(2, "GPIO2 (SDA1, I2C)"), 20 | P5(3, "GPIO3 (SCL1, I2C)"), 21 | P7(4, "GPIO4 (GPIO_GCLK)"), 22 | P8(14, "GPIO14 (TXD0)"), 23 | P10(15, "GPIO15 (RXD0)"), 24 | P11(17, "GPIO17 (GPIO_GEN0)"), 25 | P12(18, "GPIO18 (GPIO_GEN1)"), 26 | P13(27, "GPIO27 (GPIO_GEN2)"), 27 | P15(22, "GPIO22 (GPIO_GEN3)"), 28 | P16(23, "GPIO23 (GPIO_GEN4)"), 29 | P18(24, "GPIO24 (GPIO_GEN5)"), 30 | P19(10, "GPIO10, (SPI_MOSI)"), 31 | P21(9, "GPIO9, (SPI_MISO)"), 32 | P22(25, "GPIO25, (GPIO_GEN6)"), 33 | P23(11, "GPIO11 (SPI_CLK)"), 34 | P24(8, "GPIO8 (SPI_CE0_N)"), 35 | P26(7, "GPIO7 (SPI_CE1_N)"), 36 | P27(0, "ID_SD (I2C ID EEPROM)"), 37 | P28(1, "ID_SC (I2C ID EEPROM)"), 38 | P29(5, "GPIO5"), 39 | P31(6, "GPIO6"), 40 | P32(12, "GPIO12"), 41 | P33(13, "GPIO13"), 42 | P35(19, "GPIO19"), 43 | P36(16, "GPIO16"), 44 | P337(26, "GPIO26"), 45 | P38(20, "GPIO20"), 46 | P40(21, "GPIO21"); 47 | 48 | private int gpio; 49 | private String name; 50 | 51 | private Pins (int gpio, String name) { 52 | this.gpio = gpio; 53 | this.name = name; 54 | } 55 | 56 | public int getGPIO() { 57 | return this.gpio; 58 | } 59 | 60 | public String getName() { 61 | return this.name; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/system/BoardModels.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.system; 14 | 15 | /** 16 | * Enumerates Raspberry Pi board models 17 | */ 18 | public enum BoardModels { 19 | // Obtained from https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md 20 | CODE_900021("900021", Constants.A_PLUS, 1.1f, 512, Constants.SONY_UK), 21 | CODE_900032("900032", Constants.B_PLUS, 1.2f, 512, Constants.SONY_UK), 22 | CODE_900092("900092", Constants.ZERO, 1.2f, 512, Constants.SONY_UK), 23 | CODE_920092("920092", Constants.ZERO, 1.2f, 512, Constants.EMBEST), 24 | CODE_900093("900093", Constants.ZERO, 1.3f, 512, Constants.SONY_UK), 25 | CODE_9000C1("9000c1", Constants.ZERO_W, 1.1f, 512, Constants.SONY_UK), 26 | CODE_920093("920093", Constants.ZERO, 1.3f, 512, Constants.SONY_UK), 27 | CODE_A01040("a01040", Constants.B2, 1.0f, 10124, Constants.SONY_UK), 28 | CODE_A01041("a01041", Constants.B2, 1.1f, 1024, Constants.SONY_UK), 29 | CODE_A02082("a02082", Constants.B3, 1.2f, 1024, Constants.SONY_UK), 30 | CODE_A020A0("a020a0", Constants.CM3, 1.0f, 1024, Constants.SONY_UK), 31 | CODE_A21041("a21041", Constants.B2, 1.1f, 1024, Constants.EMBEST), 32 | CODE_A22042("a22042", Constants.B2_BCM2837, 1.2f, 1024, Constants.EMBEST), 33 | CODE_A22082("a22082", Constants.B3, 1.2f, 1024, Constants.EMBEST), 34 | CODE_A32082("a32082", Constants.B3, 1.2f, 1024, Constants.SONY_JAPAN), 35 | CODE_A52082("a52082", Constants.B3, 1.2f, 1024, Constants.STADIUM), 36 | CODE_A020D3("a020d3", Constants.B3_PLUS, 1.3f, 10124, Constants.SONY_UK), 37 | CODE_9020E0("9020e0", Constants.A3_PLUS, 1.0f, 512, Constants.SONY_UK); 38 | 39 | private String code; 40 | private String model; 41 | private float revision; 42 | private int ramSize; 43 | private String manufacturer; 44 | 45 | private BoardModels(String code, String model, float revision, int ramSize, String manufacturer) { 46 | this.code = code; 47 | this.model = model; 48 | this.revision = revision; 49 | this.ramSize = ramSize; 50 | this.manufacturer = manufacturer; 51 | } 52 | 53 | public String getCode() { 54 | return code; 55 | } 56 | 57 | public String getModel() { 58 | return this.model; 59 | } 60 | 61 | public float getRevision() { 62 | return this.revision; 63 | } 64 | 65 | public int getRamSize() { 66 | return this.ramSize; 67 | } 68 | 69 | public String getManufacturer() { 70 | return this.manufacturer; 71 | } 72 | 73 | private static class Constants { 74 | private static final String A_PLUS = "A+"; 75 | private static final String B_PLUS = "B+"; 76 | private static final String ZERO = "Zero"; 77 | private static final String ZERO_W = "Zero W"; 78 | private static final String B2 = "2B"; 79 | private static final String B3 = "3B"; 80 | private static final String CM3 = "CM3"; 81 | private static final String B2_BCM2837 = "2B (with BCM2837)"; 82 | private static final String A3_PLUS = "3A+"; 83 | private static final String B3_PLUS = "3B+"; 84 | 85 | private static final String SONY_UK = "Sony UK"; 86 | private static final String EMBEST = "Embest"; 87 | private static final String SONY_JAPAN = "Sony Japan"; 88 | private static final String STADIUM = "Stadium"; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pi/system/SystemInfoException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pi.system; 14 | 15 | /** 16 | * Defines SystemInfoException 17 | */ 18 | public class SystemInfoException extends Exception { 19 | private static final long serialVersionUID = 1L; 20 | 21 | public SystemInfoException(String msg) { 22 | super(msg); 23 | } 24 | 25 | public SystemInfoException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/Pibrella.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import java.io.IOException; 16 | import java.util.EnumMap; 17 | import java.util.Map; 18 | 19 | import org.eclipse.tahu.pi.dio.DioException; 20 | 21 | import jdk.dio.gpio.GPIOPin; 22 | 23 | /** 24 | * Defines Pibrella class 25 | */ 26 | public class Pibrella { 27 | 28 | private static Pibrella instance; 29 | 30 | // Pibrella I/O pins 31 | private Map pins; 32 | 33 | private Pibrella() { 34 | this.pins = new EnumMap<>(PibrellaPins.class); 35 | } 36 | 37 | /** 38 | * Gets an instance of Pibrella class 39 | * 40 | * @return an instance of Pibrella class as {@link Pibrella} 41 | */ 42 | public static Pibrella getInstance() { 43 | if (instance == null) { 44 | instance = new Pibrella(); 45 | } 46 | return instance; 47 | } 48 | 49 | /** 50 | * Gets registered Pibrella I/O pins 51 | * 52 | * @return a map of registered Pibrella I/O pins as {@link Map} 53 | */ 54 | public Map getRegisteredPins() { 55 | return this.pins; 56 | } 57 | 58 | /** 59 | * Registers specified Pibrella I/O pin 60 | * 61 | * @param pin - Pibrella pin as {@link PibrellaPins} 62 | * @param gpioPin - GPIO pin as {@link GPIOPin} 63 | */ 64 | public void registerPin(PibrellaPins pin, GPIOPin gpioPin) { 65 | this.pins.put(pin, gpioPin); 66 | } 67 | 68 | /** 69 | * Gets specified Pibrella input 70 | * 71 | * @param input - Pibrella input pin as {@link PibrellaInputPins} 72 | * @return Pibrella Input pin as {@link PibrellaInputPin} 73 | * @throws DioException 74 | */ 75 | public PibrellaInputPin getInput(PibrellaInputPins input) throws DioException { 76 | return PibrellaInputPin.getInstance(input); 77 | } 78 | 79 | /** 80 | * Gets specified Pibrella output 81 | * 82 | * @param output Pibrella output pin as {@link PibrellaOutputPins} 83 | * @return Pibrella output pin as {@link PibrellaOutputPin} 84 | * @throws DioException 85 | */ 86 | public PibrellaOutputPin getOutput(PibrellaOutputPins output) throws DioException { 87 | return PibrellaOutputPin.getInstance(output); 88 | } 89 | 90 | /** 91 | * Gets Pibrella button 92 | * 93 | * @return Pibrella button as {@link PibrellaButton} 94 | * @throws DioException 95 | */ 96 | public PibrellaButton getButton() throws DioException { 97 | return PibrellaButton.getInstance(); 98 | } 99 | 100 | /** 101 | * Gets Pibrella buzzer 102 | * 103 | * @return Pibrella buzzer as {@link PibrellaBuzzer} 104 | * @throws DioException 105 | */ 106 | public PibrellaBuzzer getBuzzer() throws DioException { 107 | return PibrellaBuzzer.getInstance(); 108 | } 109 | 110 | /** 111 | * Gets specified Pibrella LED 112 | * 113 | * @param led - Pibrella LED as {@link PibrellaLEDs} 114 | * @return Pibrella LED as {@link PibrellaLED} 115 | * @throws DioException 116 | */ 117 | public PibrellaLED getLED(PibrellaLEDs led) throws DioException { 118 | return PibrellaLED.getInstance(led); 119 | } 120 | 121 | /** 122 | * Closes all Pibrella I/O pins 123 | */ 124 | public void closeAllIOpins() { 125 | this.pins.keySet().forEach(pin -> { 126 | GPIOPin gpioPin = this.pins.get(pin); 127 | try { 128 | gpioPin.close(); 129 | } catch (IOException e) { 130 | System.out.println("Failed ot close Pibrella pin: " + pin.getDescription()); 131 | } 132 | }); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaButton.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import org.eclipse.tahu.pi.dio.DioException; 16 | import org.eclipse.tahu.pi.dio.DioPin; 17 | 18 | import jdk.dio.DeviceConfig; 19 | import jdk.dio.gpio.GPIOPin; 20 | import jdk.dio.gpio.GPIOPinConfig; 21 | 22 | /** 23 | * Defines Pibrella button 24 | */ 25 | public class PibrellaButton extends DioPin { 26 | 27 | private static PibrellaButton instance; 28 | 29 | private PibrellaButton() { 30 | super(PibrellaPins.BUTTON.getName()); 31 | } 32 | 33 | /** 34 | * Gets an instance of Pibrella button 35 | * 36 | * @return instance of Pibrella button as {@link PibrellaButton} 37 | * @throws DioException 38 | */ 39 | public static PibrellaButton getInstance() throws DioException { 40 | if (instance == null) { 41 | instance = new PibrellaButton(); 42 | } 43 | GPIOPin gpioPin = Pibrella.getInstance().getRegisteredPins().get(PibrellaPins.BUTTON); 44 | if (gpioPin == null || !gpioPin.isOpen()) { 45 | gpioPin = open(PibrellaPins.BUTTON.getName(), 46 | new GPIOPinConfig(DeviceConfig.DEFAULT, PibrellaPins.BUTTON.getGPIO(), GPIOPinConfig.DIR_INPUT_ONLY, 47 | GPIOPinConfig.MODE_INPUT_PULL_DOWN, GPIOPinConfig.TRIGGER_BOTH_EDGES, false)); 48 | instance.setGpioPin(gpioPin); 49 | Pibrella.getInstance().registerPin(PibrellaPins.BUTTON, gpioPin); 50 | } 51 | return instance; 52 | } 53 | 54 | /** 55 | * Reports if button is pressed 56 | * 57 | * @return button state as {@link boolean} 58 | * @throws DioException 59 | */ 60 | public boolean isPressed() throws DioException { 61 | return isHigh(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaBuzzer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import org.eclipse.tahu.pi.dio.DigitalOutputPin; 16 | import org.eclipse.tahu.pi.dio.DioException; 17 | 18 | import jdk.dio.DeviceConfig; 19 | import jdk.dio.gpio.GPIOPin; 20 | import jdk.dio.gpio.GPIOPinConfig; 21 | 22 | /** 23 | * Defines Pibrella buzzer 24 | */ 25 | public class PibrellaBuzzer extends DigitalOutputPin { 26 | 27 | private static PibrellaBuzzer instance; 28 | private Object lock = new Object(); 29 | 30 | private PibrellaBuzzer() { 31 | super(PibrellaPins.BUZZER.getName()); 32 | } 33 | 34 | /** 35 | * Gets an instance of Pibrella buzzer 36 | * 37 | * @return instance of Pibrella buzzer as {@link PibrellaBuzzer} 38 | * @throws DioException 39 | */ 40 | public static PibrellaBuzzer getInstance() throws DioException { 41 | if (instance == null) { 42 | instance = new PibrellaBuzzer(); 43 | } 44 | GPIOPin gpioPin = Pibrella.getInstance().getRegisteredPins().get(PibrellaPins.BUZZER); 45 | if (gpioPin == null || !gpioPin.isOpen()) { 46 | gpioPin = open(PibrellaPins.BUZZER.getName(), 47 | new GPIOPinConfig(DeviceConfig.DEFAULT, PibrellaPins.BUZZER.getGPIO(), 48 | GPIOPinConfig.DIR_OUTPUT_ONLY, GPIOPinConfig.MODE_OUTPUT_PUSH_PULL, 49 | GPIOPinConfig.TRIGGER_NONE, false)); 50 | instance.setGpioPin(gpioPin); 51 | Pibrella.getInstance().registerPin(PibrellaPins.BUZZER, gpioPin); 52 | } 53 | return instance; 54 | } 55 | 56 | /** 57 | * Starts the buzzer at specified frequency for a specified duration (in milliseconds) 58 | * 59 | * @param frequency as {@link int} 60 | * @param duration number of milliseconds as {@link int} 61 | */ 62 | public void buzz(int frequency, int duration) { 63 | new Buzzer(frequency, duration).start(); 64 | } 65 | 66 | /* 67 | * Defines buzzer 68 | */ 69 | private class Buzzer extends Thread { 70 | 71 | private int frequency; 72 | private int duration; 73 | 74 | private Buzzer(int frequency, int duration) { 75 | this.frequency = frequency; 76 | this.duration = duration; 77 | } 78 | 79 | @Override 80 | public void run() { 81 | synchronized (lock) { 82 | long startTime = System.currentTimeMillis(); 83 | int halfPeriod = 1000 / (2 * this.frequency); 84 | while ((System.currentTimeMillis() - startTime) < this.duration) { 85 | try { 86 | setHigh(); 87 | lock.wait(halfPeriod); 88 | setLow(); 89 | } catch (Exception e) { 90 | System.out.println("failed to buzz"); 91 | break; 92 | } 93 | } 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaInputPin.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import java.util.EnumMap; 16 | import java.util.Map; 17 | 18 | import org.eclipse.tahu.pi.dio.DioException; 19 | import org.eclipse.tahu.pi.dio.DioPin; 20 | 21 | import jdk.dio.DeviceConfig; 22 | import jdk.dio.gpio.GPIOPin; 23 | import jdk.dio.gpio.GPIOPinConfig; 24 | 25 | /** 26 | * Defines Pibrella input pin 27 | */ 28 | public class PibrellaInputPin extends DioPin { 29 | 30 | private static Map inputs = new EnumMap<>(PibrellaInputPins.class); 31 | 32 | private PibrellaInputPin(PibrellaInputPins input) { 33 | super(input.getName()); 34 | } 35 | 36 | /** 37 | * Gets an instance of PibrellaInputPin class 38 | * 39 | * @param input - pibrella input pin 40 | * @return instance of PibrellaInputPin class as {@link PibrellaInputPin} 41 | * @throws DioException 42 | */ 43 | public static PibrellaInputPin getInstance(PibrellaInputPins input) throws DioException { 44 | PibrellaInputPin pibrellaInput = inputs.get(input); 45 | if (inputs.get(input) == null) { 46 | pibrellaInput = new PibrellaInputPin(input); 47 | inputs.put(input, pibrellaInput); 48 | } 49 | GPIOPin gpioPin = Pibrella.getInstance().getRegisteredPins().get(input.getPin()); 50 | if (gpioPin == null || !gpioPin.isOpen()) { 51 | gpioPin = open(input.getName(), 52 | new GPIOPinConfig(DeviceConfig.DEFAULT, input.getPin().getGPIO(), GPIOPinConfig.DIR_INPUT_ONLY, 53 | GPIOPinConfig.MODE_INPUT_PULL_DOWN, GPIOPinConfig.TRIGGER_BOTH_EDGES, false)); 54 | pibrellaInput.setGpioPin(gpioPin); 55 | Pibrella.getInstance().registerPin(input.getPin(), gpioPin); 56 | } 57 | return pibrellaInput; 58 | } 59 | 60 | /** 61 | * Closes all Pibrella input pins 62 | */ 63 | public static void closeAll() { 64 | inputs.values().forEach(input -> { 65 | try { 66 | input.close(); 67 | } catch (Exception e) { 68 | System.out.println("failed to close " + input.getPinName()); 69 | } 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaInputPins.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | /** 16 | * Enumerates Pibrella input pins 17 | */ 18 | public enum PibrellaInputPins { 19 | A(PibrellaPins.INA), 20 | B(PibrellaPins.INB), 21 | C(PibrellaPins.INC), 22 | D(PibrellaPins.IND); 23 | 24 | private PibrellaPins pin; 25 | 26 | private PibrellaInputPins(PibrellaPins pin) { 27 | this.pin = pin; 28 | } 29 | 30 | public PibrellaPins getPin() { 31 | return this.pin; 32 | } 33 | 34 | public int getGPIO() { 35 | return this.pin.getGPIO(); 36 | } 37 | 38 | public String getName() { 39 | return this.getPin().getName(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaLED.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import java.util.EnumMap; 16 | import java.util.Map; 17 | 18 | import org.eclipse.tahu.pi.dio.DigitalOutputPin; 19 | import org.eclipse.tahu.pi.dio.DioException; 20 | 21 | import jdk.dio.DeviceConfig; 22 | import jdk.dio.gpio.GPIOPin; 23 | import jdk.dio.gpio.GPIOPinConfig; 24 | 25 | /** 26 | * Defines Pibrella LED 27 | */ 28 | public class PibrellaLED extends DigitalOutputPin { 29 | 30 | private static Map leds = new EnumMap<>(PibrellaLEDs.class); 31 | 32 | private PibrellaLED(PibrellaLEDs led) { 33 | super(led.getName()); 34 | } 35 | 36 | /** 37 | * Gets an instance of PibrellaLED class 38 | * 39 | * @param led - Pibrellas LED 40 | * @return instance of PibrellaLED class as {@link PibrellaLED} 41 | * @throws DioException 42 | */ 43 | public static PibrellaLED getInstance(PibrellaLEDs led) throws DioException { 44 | PibrellaLED pibrellaLED = leds.get(led); 45 | if (leds.get(led) == null) { 46 | pibrellaLED = new PibrellaLED(led); 47 | leds.put(led, pibrellaLED); 48 | } 49 | GPIOPin gpioPin = Pibrella.getInstance().getRegisteredPins().get(led.getPin()); 50 | if (gpioPin == null || !gpioPin.isOpen()) { 51 | gpioPin = open(led.getName(), 52 | new GPIOPinConfig(DeviceConfig.DEFAULT, led.getPin().getGPIO(), GPIOPinConfig.DIR_OUTPUT_ONLY, 53 | GPIOPinConfig.MODE_OUTPUT_PUSH_PULL, GPIOPinConfig.TRIGGER_NONE, false)); 54 | pibrellaLED.setGpioPin(gpioPin); 55 | Pibrella.getInstance().registerPin(led.getPin(), gpioPin); 56 | } 57 | return pibrellaLED; 58 | } 59 | 60 | /** 61 | * Closes all LEDs 62 | */ 63 | public static void closeAll() { 64 | leds.values().forEach(led -> { 65 | try { 66 | led.close(); 67 | } catch (Exception e) { 68 | System.out.println("failed to close " + led.getPinName()); 69 | } 70 | }); 71 | } 72 | 73 | /** 74 | * Turns LED on 75 | * 76 | * @throws DioException 77 | */ 78 | public void turnOn() throws DioException { 79 | setHigh(); 80 | } 81 | 82 | /** 83 | * Turns LED off 84 | * 85 | * @throws DioException 86 | */ 87 | public void turnOff() throws DioException { 88 | setLow(); 89 | } 90 | 91 | /** 92 | * Reports if LED is on 93 | * 94 | * @return LED state as {@link boolean} 95 | * @throws DioException 96 | */ 97 | public boolean isOn() throws DioException { 98 | return isHigh(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaLEDs.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | /** 16 | * Enumerates Pibrella LEDs 17 | */ 18 | public enum PibrellaLEDs { 19 | GREEN (PibrellaPins.LEDG), 20 | YELLOW (PibrellaPins.LEDY), 21 | RED (PibrellaPins.LEDR); 22 | 23 | private PibrellaPins pin; 24 | 25 | private PibrellaLEDs(PibrellaPins pin) { 26 | this.pin = pin; 27 | } 28 | 29 | public PibrellaPins getPin() { 30 | return this.pin; 31 | } 32 | 33 | public int getGPIO() { 34 | return this.pin.getGPIO(); 35 | } 36 | 37 | public String getName() { 38 | return this.getPin().getName(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaOutputPin.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import java.util.EnumMap; 16 | import java.util.Map; 17 | 18 | import org.eclipse.tahu.pi.dio.DigitalOutputPin; 19 | import org.eclipse.tahu.pi.dio.DioException; 20 | 21 | import jdk.dio.DeviceConfig; 22 | import jdk.dio.gpio.GPIOPin; 23 | import jdk.dio.gpio.GPIOPinConfig; 24 | 25 | /** 26 | * Defines Pibrella output pin 27 | */ 28 | public class PibrellaOutputPin extends DigitalOutputPin { 29 | 30 | private static Map outputs = new EnumMap<>(PibrellaOutputPins.class); 31 | 32 | private PibrellaOutputPin(PibrellaOutputPins output) { 33 | super(output.getName()); 34 | } 35 | 36 | /** 37 | * Gets an instance of PibrellaOutputPin class 38 | * 39 | * @param output - Pibrella output pin 40 | * @return instance of PibrellaOutputPin class as {@link PibrellaOutputPin} 41 | * @throws DioException 42 | */ 43 | public static PibrellaOutputPin getInstance(PibrellaOutputPins output) throws DioException { 44 | PibrellaOutputPin pibrellaOutput = outputs.get(output); 45 | if (outputs.get(output) == null) { 46 | pibrellaOutput = new PibrellaOutputPin(output); 47 | outputs.put(output, pibrellaOutput); 48 | } 49 | GPIOPin gpioPin = Pibrella.getInstance().getRegisteredPins().get(output.getPin()); 50 | if (gpioPin == null || !gpioPin.isOpen()) { 51 | gpioPin = open(output.getName(), 52 | new GPIOPinConfig(DeviceConfig.DEFAULT, output.getPin().getGPIO(), GPIOPinConfig.DIR_OUTPUT_ONLY, 53 | GPIOPinConfig.MODE_OUTPUT_PUSH_PULL, GPIOPinConfig.TRIGGER_NONE, false)); 54 | pibrellaOutput.setGpioPin(gpioPin); 55 | Pibrella.getInstance().registerPin(output.getPin(), gpioPin); 56 | } 57 | return pibrellaOutput; 58 | } 59 | 60 | /** 61 | * Closes all Pibrella output pins 62 | */ 63 | public static void closeAll() { 64 | outputs.values().forEach(output -> { 65 | try { 66 | output.close(); 67 | } catch (Exception e) { 68 | System.out.println("failed to close " + output.getPinName()); 69 | } 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaOutputPins.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | /** 16 | * Enumerates Pibrella output pins 17 | */ 18 | public enum PibrellaOutputPins { 19 | E(PibrellaPins.OUTE), 20 | F(PibrellaPins.OUTF), 21 | G(PibrellaPins.OUTG), 22 | H(PibrellaPins.OUTH); 23 | 24 | private PibrellaPins pin; 25 | 26 | private PibrellaOutputPins(PibrellaPins pin) { 27 | this.pin = pin; 28 | } 29 | 30 | public PibrellaPins getPin() { 31 | return this.pin; 32 | } 33 | 34 | public int getGPIO() { 35 | return this.pin.getGPIO(); 36 | } 37 | 38 | public String getName() { 39 | return this.getPin().getName(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/java/org/eclipse/tahu/pibrella/PibrellaPins.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | package org.eclipse.tahu.pibrella; 14 | 15 | import org.eclipse.tahu.pi.dio.PinDirection; 16 | import org.eclipse.tahu.pi.dio.Pins; 17 | 18 | /** 19 | * Enumerates Pibrella I/O pins 20 | */ 21 | public enum PibrellaPins { 22 | INA(Pins.P21, PinDirection.INPUT, "Input A", "Inputs/a"), 23 | INB(Pins.P26, PinDirection.INPUT, "Input B", "Inputs/b"), 24 | INC(Pins.P24, PinDirection.INPUT, "Input C", "Inputs/c"), 25 | IND(Pins.P19, PinDirection.INPUT, "Input D", "Inputs/d"), 26 | BUTTON(Pins.P23, PinDirection.INPUT, "Button", "button"), 27 | OUTE(Pins.P15, PinDirection.OUTPUT, "Output E", "Outputs/e"), 28 | OUTF(Pins.P16, PinDirection.OUTPUT, "Output F", "Outputs/f"), 29 | OUTG(Pins.P18, PinDirection.OUTPUT, "Output G", "Outputs/g"), 30 | OUTH(Pins.P22, PinDirection.OUTPUT, "Output H", "Outputs/h"), 31 | LEDG(Pins.P7, PinDirection.OUTPUT, "Green LED", "Outputs/LEDs/green"), 32 | LEDY(Pins.P11, PinDirection.OUTPUT, "Yellow LED", "Outputs/LEDs/yellow"), 33 | LEDR(Pins.P13, PinDirection.OUTPUT, "Red LED", "Outputs/LEDs/red"), 34 | BUZZER(Pins.P12, PinDirection.OUTPUT, "Buzzer", "buzzer"); 35 | 36 | private Pins pin; 37 | private PinDirection direction; 38 | private String name; 39 | private String description; 40 | 41 | private PibrellaPins(Pins pin, PinDirection direction, String name, String description) { 42 | this.pin = pin; 43 | this.direction = direction; 44 | this.name = name; 45 | this.description = description; 46 | } 47 | 48 | public Pins getPin() { 49 | return this.pin; 50 | } 51 | 52 | public int getGPIO() { 53 | return this.pin.getGPIO(); 54 | } 55 | 56 | public PinDirection getDirection() { 57 | return this.direction; 58 | } 59 | 60 | public String getName() { 61 | return this.name; 62 | } 63 | 64 | public String getDescription() { 65 | return this.description; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sparkplug_b/raspberry_pi_examples/java/src/main/resources/libdio.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/sparkplug_b/raspberry_pi_examples/java/src/main/resources/libdio.so -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/c/template_as_custom_props/Makefile: -------------------------------------------------------------------------------- 1 | #/******************************************************************************** 2 | # * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | # * 4 | # * This program and the accompanying materials are made available under the 5 | # * terms of the Eclipse Public License 2.0 which is available at 6 | # * http://www.eclipse.org/legal/epl-2.0. 7 | # * 8 | # * SPDX-License-Identifier: EPL-2.0 9 | # * 10 | # * Contributors: 11 | # * Cirrus Link Solutions - initial implementation 12 | # ********************************************************************************/ 13 | 14 | TARGET = example 15 | LIBS = ../../../../client_libraries/c/lib/libsparkplug_b.a -Llib -L/usr/local/lib -lmosquitto 16 | CC = gcc 17 | CFLAGS = -g -Wall -I../../../../client_libraries/c/include/ 18 | 19 | .PHONY: default all clean 20 | 21 | default: $(TARGET) 22 | all: default 23 | 24 | OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) 25 | HEADERS = $(wildcard *.h) 26 | 27 | %.o: %.c $(HEADERS) 28 | $(CC) $(CFLAGS) -c $< -o $@ 29 | 30 | .PRECIOUS: $(TARGET) $(OBJECTS) 31 | 32 | $(TARGET): $(OBJECTS) 33 | $(CC) $(OBJECTS) -Wall $(LIBS) -o $@ 34 | 35 | clean: 36 | -rm -f *.o 37 | -rm -f $(TARGET) 38 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/c/udt_example/Makefile: -------------------------------------------------------------------------------- 1 | #/******************************************************************************** 2 | # * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | # * 4 | # * This program and the accompanying materials are made available under the 5 | # * terms of the Eclipse Public License 2.0 which is available at 6 | # * http://www.eclipse.org/legal/epl-2.0. 7 | # * 8 | # * SPDX-License-Identifier: EPL-2.0 9 | # * 10 | # * Contributors: 11 | # * Cirrus Link Solutions - initial implementation 12 | # ********************************************************************************/ 13 | 14 | TARGET = example 15 | LIBS = ../../../../client_libraries/c/lib/libsparkplug_b.a -Llib -L/usr/local/lib -lmosquitto 16 | CC = gcc 17 | CFLAGS = -g -Wall -I../../../../client_libraries/c/include/ 18 | 19 | .PHONY: default all clean 20 | 21 | default: $(TARGET) 22 | all: default 23 | 24 | OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) 25 | HEADERS = $(wildcard *.h) 26 | 27 | %.o: %.c $(HEADERS) 28 | $(CC) $(CFLAGS) -c $< -o $@ 29 | 30 | .PRECIOUS: $(TARGET) $(OBJECTS) 31 | 32 | $(TARGET): $(OBJECTS) 33 | $(CC) $(OBJECTS) -Wall $(LIBS) -o $@ 34 | 35 | clean: 36 | -rm -f *.o 37 | -rm -f $(TARGET) 38 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/java/THIRD-PARTY.txt: -------------------------------------------------------------------------------- 1 | 2 | Lists of 5 third-party dependencies. 3 | (New BSD license) Protocol Buffer Java API (com.google.protobuf:protobuf-java:2.6.1 - https://developers.google.com/protocol-buffers/) 4 | (The Apache Software License, Version 2.0) Apache Log4j (log4j:log4j:1.2.17 - http://logging.apache.org/log4j/1.2/) 5 | (Eclipse Public License - Version 1.0) org.eclipse.paho.client.mqttv3 (org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 - http://www.eclipse.org/paho/org.eclipse.paho.client.mqttv3) 6 | (MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.5 - http://www.slf4j.org) 7 | (MIT License) SLF4J LOG4J-12 Binding (org.slf4j:slf4j-log4j12:1.7.5 - http://www.slf4j.org) 8 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/java_device_timestamp/THIRD-PARTY.txt: -------------------------------------------------------------------------------- 1 | 2 | Lists of 5 third-party dependencies. 3 | (New BSD license) Protocol Buffer Java API (com.google.protobuf:protobuf-java:2.6.1 - https://developers.google.com/protocol-buffers/) 4 | (The Apache Software License, Version 2.0) Apache Log4j (log4j:log4j:1.2.17 - http://logging.apache.org/log4j/1.2/) 5 | (Eclipse Public License - Version 1.0) org.eclipse.paho.client.mqttv3 (org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 - http://www.eclipse.org/paho/org.eclipse.paho.client.mqttv3) 6 | (MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.5 - http://www.slf4j.org) 7 | (MIT License) SLF4J LOG4J-12 Binding (org.slf4j:slf4j-log4j12:1.7.5 - http://www.slf4j.org) 8 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/java_records/THIRD-PARTY.txt: -------------------------------------------------------------------------------- 1 | 2 | Lists of 5 third-party dependencies. 3 | (New BSD license) Protocol Buffer Java API (com.google.protobuf:protobuf-java:2.6.1 - https://developers.google.com/protocol-buffers/) 4 | (The Apache Software License, Version 2.0) Apache Log4j (log4j:log4j:1.2.17 - http://logging.apache.org/log4j/1.2/) 5 | (Eclipse Public License - Version 1.0) org.eclipse.paho.client.mqttv3 (org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 - http://www.eclipse.org/paho/org.eclipse.paho.client.mqttv3) 6 | (MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.5 - http://www.slf4j.org) 7 | (MIT License) SLF4J LOG4J-12 Binding (org.slf4j:slf4j-log4j12:1.7.5 - http://www.slf4j.org) 8 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/js/package.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name" : "example", 4 | "version" : "1.0.1-SNAPSHOT", 5 | "description" : "An example Sparkplug B module written in JavaScript", 6 | "license" : "EPL-1.0", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/Cirrus-Link/Sparkplug.git" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/nodered/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "example", 3 | "version" : "1.0.0-SNAPSHOT", 4 | "description" : "An example Sparkplug B Node-RED node", 5 | "license" : "EPL-1.0", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/Cirrus-Link/Sparkplug.git" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sparkplug_b/stand_alone_examples/python/THIRD-PARTY.txt: -------------------------------------------------------------------------------- 1 | (1) Eclipse Paho Client 2 | Copyright © 2014 Eclipse Paho. All Rights Reserved. 3 | The Software contains Eclipse Paho Client, which is protected under the Eclipse Public License, Version 1.0. 4 | You can get the full source code for Eclipse Paho Client at: https://repo.eclipse.org/content/repositories/paho-releases. 5 | A copy of the Eclipse Public License, Version 1.0 is available at http://www.eclipse.org/legal/epl-v10.html 6 | 7 | (2) Google Protocol Buffers 8 | Copyright 2014, Google Inc. All rights reserved. 9 | The Software contains Google Protocol Buffers, which is protected under a BSD style license. 10 | You can get the full source code for Google Protocol Buffers at: https://github.com/google/protobuf. 11 | A copy of the license is available at https://github.com/google/protobuf/blob/master/LICENSE 12 | -------------------------------------------------------------------------------- /sparkplug_b/tools/java_sparkplug_b_listener/THIRD-PARTY.txt: -------------------------------------------------------------------------------- 1 | 2 | Lists of 5 third-party dependencies. 3 | (New BSD license) Protocol Buffer Java API (com.google.protobuf:protobuf-java:2.6.1 - https://developers.google.com/protocol-buffers/) 4 | (The Apache Software License, Version 2.0) Apache Log4j (log4j:log4j:1.2.17 - http://logging.apache.org/log4j/1.2/) 5 | (Eclipse Public License - Version 1.0) org.eclipse.paho.client.mqttv3 (org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 - http://www.eclipse.org/paho/org.eclipse.paho.client.mqttv3) 6 | (MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.5 - http://www.slf4j.org) 7 | (MIT License) SLF4J LOG4J-12 Binding (org.slf4j:slf4j-log4j12:1.7.5 - http://www.slf4j.org) 8 | -------------------------------------------------------------------------------- /sparkplug_b/tools/java_sparkplug_b_listener/src/main/java/org/eclipse/tahu/SparkplugListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License 2.0 which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | * 10 | * Contributors: 11 | * Cirrus Link Solutions - initial implementation 12 | ********************************************************************************/ 13 | 14 | package org.eclipse.tahu; 15 | 16 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; 17 | import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; 18 | import org.eclipse.paho.client.mqttv3.MqttClient; 19 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; 20 | import org.eclipse.paho.client.mqttv3.MqttMessage; 21 | import org.eclipse.tahu.message.SparkplugBPayloadDecoder; 22 | import org.eclipse.tahu.message.model.SparkplugBPayload; 23 | import org.eclipse.tahu.message.model.Topic; 24 | import org.eclipse.tahu.util.TopicUtil; 25 | 26 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 27 | import com.fasterxml.jackson.databind.ObjectMapper; 28 | 29 | public class SparkplugListener implements MqttCallbackExtended { 30 | 31 | // Configuration 32 | private String serverUrl = "tcp://localhost:1883"; 33 | private String clientId = "SparkplugBListenerEdgeNode"; 34 | private String username = "admin"; 35 | private String password = "changeme"; 36 | private MqttClient client; 37 | 38 | public static void main(String[] args) { 39 | SparkplugListener listener = new SparkplugListener(); 40 | listener.run(); 41 | } 42 | 43 | public void run() { 44 | try { 45 | // Connect to the MQTT Server 46 | MqttConnectOptions options = new MqttConnectOptions(); 47 | options.setAutomaticReconnect(true); 48 | options.setCleanSession(true); 49 | options.setConnectionTimeout(30); 50 | options.setKeepAliveInterval(30); 51 | options.setUserName(username); 52 | options.setPassword(password.toCharArray()); 53 | client = new MqttClient(serverUrl, clientId); 54 | client.setTimeToWait(5000); // short timeout on failure to connect 55 | client.connect(options); 56 | client.setCallback(this); 57 | 58 | // Just listen to all DDATA messages on spAv1.0 topics and wait for inbound messages 59 | client.subscribe("spBv1.0/#", 0); 60 | } catch(Exception e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | @Override 66 | public void connectComplete(boolean reconnect, String serverURI) { 67 | System.out.println("Connected!"); 68 | } 69 | 70 | @Override 71 | public void connectionLost(Throwable cause) { 72 | System.out.println("The MQTT Connection was lost! - will auto-reconnect"); 73 | } 74 | 75 | @Override 76 | public void messageArrived(String topic, MqttMessage message) throws Exception { 77 | Topic sparkplugTopic = TopicUtil.parseTopic(topic); 78 | ObjectMapper mapper = new ObjectMapper(); 79 | mapper.setSerializationInclusion(Include.NON_NULL); 80 | 81 | System.out.println("Message Arrived on Sparkplug topic " + sparkplugTopic.toString()); 82 | 83 | SparkplugBPayloadDecoder decoder = new SparkplugBPayloadDecoder(); 84 | SparkplugBPayload inboundPayload = decoder.buildFromByteArray(message.getPayload()); 85 | 86 | // Convert the message to JSON and print to system.out 87 | try { 88 | String payloadString = mapper.writeValueAsString(inboundPayload); 89 | System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inboundPayload)); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | } 93 | } 94 | 95 | @Override 96 | public void deliveryComplete(IMqttDeliveryToken token) { 97 | System.out.println("Published message: " + token); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /sparkplug_b/tools/java_sparkplug_b_listener/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #/******************************************************************************** 2 | # * Copyright (c) 2014, 2018 Cirrus Link Solutions and others 3 | # * 4 | # * This program and the accompanying materials are made available under the 5 | # * terms of the Eclipse Public License 2.0 which is available at 6 | # * http://www.eclipse.org/legal/epl-2.0. 7 | # * 8 | # * SPDX-License-Identifier: EPL-2.0 9 | # * 10 | # * Contributors: 11 | # * Cirrus Link Solutions - initial implementation 12 | # ********************************************************************************/ 13 | 14 | # Root logger option 15 | log4j.rootLogger=ERROR, stdout 16 | 17 | # Direct log messages to stdout 18 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 19 | log4j.appender.stdout.Target=System.out 20 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /sparkplug_b_pb2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/sparkplug_b_pb2.pyc -------------------------------------------------------------------------------- /yolov2-tiny.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | # Testing 3 | batch=1 4 | subdivisions=1 5 | # Training 6 | # batch=64 7 | # subdivisions=2 8 | width=416 9 | height=416 10 | channels=3 11 | momentum=0.9 12 | decay=0.0005 13 | angle=0 14 | saturation = 1.5 15 | exposure = 1.5 16 | hue=.1 17 | 18 | learning_rate=0.001 19 | burn_in=1000 20 | max_batches = 500200 21 | policy=steps 22 | steps=400000,450000 23 | scales=.1,.1 24 | 25 | [convolutional] 26 | batch_normalize=1 27 | filters=16 28 | size=3 29 | stride=1 30 | pad=1 31 | activation=leaky 32 | 33 | [maxpool] 34 | size=2 35 | stride=2 36 | 37 | [convolutional] 38 | batch_normalize=1 39 | filters=32 40 | size=3 41 | stride=1 42 | pad=1 43 | activation=leaky 44 | 45 | [maxpool] 46 | size=2 47 | stride=2 48 | 49 | [convolutional] 50 | batch_normalize=1 51 | filters=64 52 | size=3 53 | stride=1 54 | pad=1 55 | activation=leaky 56 | 57 | [maxpool] 58 | size=2 59 | stride=2 60 | 61 | [convolutional] 62 | batch_normalize=1 63 | filters=128 64 | size=3 65 | stride=1 66 | pad=1 67 | activation=leaky 68 | 69 | [maxpool] 70 | size=2 71 | stride=2 72 | 73 | [convolutional] 74 | batch_normalize=1 75 | filters=256 76 | size=3 77 | stride=1 78 | pad=1 79 | activation=leaky 80 | 81 | [maxpool] 82 | size=2 83 | stride=2 84 | 85 | [convolutional] 86 | batch_normalize=1 87 | filters=512 88 | size=3 89 | stride=1 90 | pad=1 91 | activation=leaky 92 | 93 | [maxpool] 94 | size=2 95 | stride=1 96 | 97 | [convolutional] 98 | batch_normalize=1 99 | filters=1024 100 | size=3 101 | stride=1 102 | pad=1 103 | activation=leaky 104 | 105 | ########### 106 | 107 | [convolutional] 108 | batch_normalize=1 109 | size=3 110 | stride=1 111 | pad=1 112 | filters=512 113 | activation=leaky 114 | 115 | [convolutional] 116 | size=1 117 | stride=1 118 | pad=1 119 | filters=425 120 | activation=linear 121 | 122 | [region] 123 | anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 124 | bias_match=1 125 | classes=80 126 | coords=4 127 | num=5 128 | softmax=1 129 | jitter=.2 130 | rescore=0 131 | 132 | object_scale=5 133 | noobject_scale=1 134 | class_scale=1 135 | coord_scale=1 136 | 137 | absolute=1 138 | thresh = .6 139 | random=1 140 | -------------------------------------------------------------------------------- /yolov2.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | # Testing 3 | batch=1 4 | subdivisions=1 5 | # Training 6 | # batch=64 7 | # subdivisions=8 8 | width=608 9 | height=608 10 | channels=3 11 | momentum=0.9 12 | decay=0.0005 13 | angle=0 14 | saturation = 1.5 15 | exposure = 1.5 16 | hue=.1 17 | 18 | learning_rate=0.001 19 | burn_in=1000 20 | max_batches = 500200 21 | policy=steps 22 | steps=400000,450000 23 | scales=.1,.1 24 | 25 | [convolutional] 26 | batch_normalize=1 27 | filters=32 28 | size=3 29 | stride=1 30 | pad=1 31 | activation=leaky 32 | 33 | [maxpool] 34 | size=2 35 | stride=2 36 | 37 | [convolutional] 38 | batch_normalize=1 39 | filters=64 40 | size=3 41 | stride=1 42 | pad=1 43 | activation=leaky 44 | 45 | [maxpool] 46 | size=2 47 | stride=2 48 | 49 | [convolutional] 50 | batch_normalize=1 51 | filters=128 52 | size=3 53 | stride=1 54 | pad=1 55 | activation=leaky 56 | 57 | [convolutional] 58 | batch_normalize=1 59 | filters=64 60 | size=1 61 | stride=1 62 | pad=1 63 | activation=leaky 64 | 65 | [convolutional] 66 | batch_normalize=1 67 | filters=128 68 | size=3 69 | stride=1 70 | pad=1 71 | activation=leaky 72 | 73 | [maxpool] 74 | size=2 75 | stride=2 76 | 77 | [convolutional] 78 | batch_normalize=1 79 | filters=256 80 | size=3 81 | stride=1 82 | pad=1 83 | activation=leaky 84 | 85 | [convolutional] 86 | batch_normalize=1 87 | filters=128 88 | size=1 89 | stride=1 90 | pad=1 91 | activation=leaky 92 | 93 | [convolutional] 94 | batch_normalize=1 95 | filters=256 96 | size=3 97 | stride=1 98 | pad=1 99 | activation=leaky 100 | 101 | [maxpool] 102 | size=2 103 | stride=2 104 | 105 | [convolutional] 106 | batch_normalize=1 107 | filters=512 108 | size=3 109 | stride=1 110 | pad=1 111 | activation=leaky 112 | 113 | [convolutional] 114 | batch_normalize=1 115 | filters=256 116 | size=1 117 | stride=1 118 | pad=1 119 | activation=leaky 120 | 121 | [convolutional] 122 | batch_normalize=1 123 | filters=512 124 | size=3 125 | stride=1 126 | pad=1 127 | activation=leaky 128 | 129 | [convolutional] 130 | batch_normalize=1 131 | filters=256 132 | size=1 133 | stride=1 134 | pad=1 135 | activation=leaky 136 | 137 | [convolutional] 138 | batch_normalize=1 139 | filters=512 140 | size=3 141 | stride=1 142 | pad=1 143 | activation=leaky 144 | 145 | [maxpool] 146 | size=2 147 | stride=2 148 | 149 | [convolutional] 150 | batch_normalize=1 151 | filters=1024 152 | size=3 153 | stride=1 154 | pad=1 155 | activation=leaky 156 | 157 | [convolutional] 158 | batch_normalize=1 159 | filters=512 160 | size=1 161 | stride=1 162 | pad=1 163 | activation=leaky 164 | 165 | [convolutional] 166 | batch_normalize=1 167 | filters=1024 168 | size=3 169 | stride=1 170 | pad=1 171 | activation=leaky 172 | 173 | [convolutional] 174 | batch_normalize=1 175 | filters=512 176 | size=1 177 | stride=1 178 | pad=1 179 | activation=leaky 180 | 181 | [convolutional] 182 | batch_normalize=1 183 | filters=1024 184 | size=3 185 | stride=1 186 | pad=1 187 | activation=leaky 188 | 189 | 190 | ####### 191 | 192 | [convolutional] 193 | batch_normalize=1 194 | size=3 195 | stride=1 196 | pad=1 197 | filters=1024 198 | activation=leaky 199 | 200 | [convolutional] 201 | batch_normalize=1 202 | size=3 203 | stride=1 204 | pad=1 205 | filters=1024 206 | activation=leaky 207 | 208 | [route] 209 | layers=-9 210 | 211 | [convolutional] 212 | batch_normalize=1 213 | size=1 214 | stride=1 215 | pad=1 216 | filters=64 217 | activation=leaky 218 | 219 | [reorg] 220 | stride=2 221 | 222 | [route] 223 | layers=-1,-4 224 | 225 | [convolutional] 226 | batch_normalize=1 227 | size=3 228 | stride=1 229 | pad=1 230 | filters=1024 231 | activation=leaky 232 | 233 | [convolutional] 234 | size=1 235 | stride=1 236 | pad=1 237 | filters=425 238 | activation=linear 239 | 240 | 241 | [region] 242 | anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 243 | bias_match=1 244 | classes=80 245 | coords=4 246 | num=5 247 | softmax=1 248 | jitter=.3 249 | rescore=1 250 | 251 | object_scale=5 252 | noobject_scale=1 253 | class_scale=1 254 | coord_scale=1 255 | 256 | absolute=1 257 | thresh = .6 258 | random=1 259 | -------------------------------------------------------------------------------- /yolov3-tiny.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | # Testing 3 | batch=1 4 | subdivisions=1 5 | # Training 6 | # batch=64 7 | # subdivisions=2 8 | width=416 9 | height=416 10 | channels=3 11 | momentum=0.9 12 | decay=0.0005 13 | angle=0 14 | saturation = 1.5 15 | exposure = 1.5 16 | hue=.1 17 | 18 | learning_rate=0.001 19 | burn_in=1000 20 | max_batches = 500200 21 | policy=steps 22 | steps=400000,450000 23 | scales=.1,.1 24 | 25 | [convolutional] 26 | batch_normalize=1 27 | filters=16 28 | size=3 29 | stride=1 30 | pad=1 31 | activation=leaky 32 | 33 | [maxpool] 34 | size=2 35 | stride=2 36 | 37 | [convolutional] 38 | batch_normalize=1 39 | filters=32 40 | size=3 41 | stride=1 42 | pad=1 43 | activation=leaky 44 | 45 | [maxpool] 46 | size=2 47 | stride=2 48 | 49 | [convolutional] 50 | batch_normalize=1 51 | filters=64 52 | size=3 53 | stride=1 54 | pad=1 55 | activation=leaky 56 | 57 | [maxpool] 58 | size=2 59 | stride=2 60 | 61 | [convolutional] 62 | batch_normalize=1 63 | filters=128 64 | size=3 65 | stride=1 66 | pad=1 67 | activation=leaky 68 | 69 | [maxpool] 70 | size=2 71 | stride=2 72 | 73 | [convolutional] 74 | batch_normalize=1 75 | filters=256 76 | size=3 77 | stride=1 78 | pad=1 79 | activation=leaky 80 | 81 | [maxpool] 82 | size=2 83 | stride=2 84 | 85 | [convolutional] 86 | batch_normalize=1 87 | filters=512 88 | size=3 89 | stride=1 90 | pad=1 91 | activation=leaky 92 | 93 | [maxpool] 94 | size=2 95 | stride=1 96 | 97 | [convolutional] 98 | batch_normalize=1 99 | filters=1024 100 | size=3 101 | stride=1 102 | pad=1 103 | activation=leaky 104 | 105 | ########### 106 | 107 | [convolutional] 108 | batch_normalize=1 109 | filters=256 110 | size=1 111 | stride=1 112 | pad=1 113 | activation=leaky 114 | 115 | [convolutional] 116 | batch_normalize=1 117 | filters=512 118 | size=3 119 | stride=1 120 | pad=1 121 | activation=leaky 122 | 123 | [convolutional] 124 | size=1 125 | stride=1 126 | pad=1 127 | filters=255 128 | activation=linear 129 | 130 | 131 | 132 | [yolo] 133 | mask = 3,4,5 134 | anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 135 | classes=80 136 | num=6 137 | jitter=.3 138 | ignore_thresh = .7 139 | truth_thresh = 1 140 | random=1 141 | 142 | [route] 143 | layers = -4 144 | 145 | [convolutional] 146 | batch_normalize=1 147 | filters=128 148 | size=1 149 | stride=1 150 | pad=1 151 | activation=leaky 152 | 153 | [upsample] 154 | stride=2 155 | 156 | [route] 157 | layers = -1, 8 158 | 159 | [convolutional] 160 | batch_normalize=1 161 | filters=256 162 | size=3 163 | stride=1 164 | pad=1 165 | activation=leaky 166 | 167 | [convolutional] 168 | size=1 169 | stride=1 170 | pad=1 171 | filters=255 172 | activation=linear 173 | 174 | [yolo] 175 | mask = 0,1,2 176 | anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 177 | classes=80 178 | num=6 179 | jitter=.3 180 | ignore_thresh = .7 181 | truth_thresh = 1 182 | random=1 183 | -------------------------------------------------------------------------------- /yolov3-tiny.weights: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valdivj/Deepstream-IGN-Maker-YOLO/f38ece731e9797a525da932c3da2de77e48f45af/yolov3-tiny.weights --------------------------------------------------------------------------------