Jump to content

DualCam Communication Protocol: Difference between revisions

No edit summary
 
(44 intermediate revisions by 6 users not shown)
Line 1: Line 1:
==Server side configuration source code==
'''NOTE: This is a "test server" version, dedicated for initial functionality testing (which could also be done via cloudview platform) with 1-2 cameras. Multithreaded (and multiple device) handling on the server side is up to the client to do additional development and/or necessary optimizations and modifications, to support more than 1-2 cameras at the same server instance.'''
Optionally - platforms that already support camera integrations could be used.
Together with the communication protocol, this server side source code can be downloaded and implemented upon personal servers for the ease of use and configuration, please see index.js, debug.js and protocol.js which can be copied into the server.
Server files & source code can be downloaded here:
* [[Media:Camera Server files for Video Solutions.zip|Camera Server files]]
Please see index.js, debug.js and protocol.js files. These files contain required support for camera downloads and they can be inserted straight into server. The folder can also be run as server and will work with file downloads, so if personal server is not available, there is always a possibility to use this default server.
[[File:Server123.png|center]]
All that is required is an open Port on the computer and that port has to be written in run_server.bat file. Also by clicking on Readme file, you will be able to see the settings which you can enter into that run_server.bat file by right clicking the mouse button on it and choosing edit option. These settings include choices like DualCam download, ADAS file download or Auto mode, Metadata inclusion and etc.
[[File:Server edit.png|center]]
In this case, Notepad++ is chosen but you can choose any text editor in order to update the file.
==Camera file transfer reconnection==
==Camera file transfer reconnection==
If FMU1YX device has bad reception, server is not reachable or wrong server details are configured, then the device tries to open a link to a camera server few consecutive times. If no connection was possible to be established, then the connection is postponed for 30 minutes and tried again (or tried every configured sending interval if periodic image sending is enabled).
If FMU1YX device has bad reception, server is not reachable or wrong server details are configured, then the device tries to open a link to a camera server few consecutive times. If no connection was possible to be established, then the connection is postponed for 30 minutes and tried again (or tried every configured sending interval if periodic image sending is enabled).
Line 190: Line 212:
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |...
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |...
|}
|}
A File data is split into 1024 byte parts, each part wrapped into a DATA command and is sent. <br>
The file is sent in chunks of 1024 bytes, but the server may receive it in various packet sizes depending on a modem and provider packet forming procedures. . <br>
Note: ''if a command with a bad CRC is received, RESUME command should be sent with the last valid file offset, after receiving a RESUME command, the server will stop sending DATA commands and continue communication from'' '''“Resume file transfer”''' ''step.''<br>
Note: ''if a command with a bad CRC is received, RESUME command should be sent with the last valid file offset, after receiving a RESUME command, the server will stop sending DATA commands and continue communication from'' '''“Resume file transfer”''' ''step.''<br>
CRC polynomial expression: 0x8408
CRC polynomial expression: 0x8408
Line 265: Line 287:
<br>
<br>


'''File metadata response  (CMD ID 0x000B)'''<br>
'''File metadata response  (CMD ID 0x000B) From From 03.29.00.Rev.534 metadata version can be configured.'''<br>
0x000B is a response command to the request command 0x000A.
0x000B is a response command to the request command 0x000A.


Line 278: Line 300:
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Trigger (1 byte)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Trigger (1 byte)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Video length (2 bytes)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Video length (2 bytes)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Framerate (1 bytes)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Time Zone (2 bytes)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Latitude (8 bytes)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Longitude (8 bytes)'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Trigger Timestamp (8 bytes)'''
|-  
|-  
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0x000B
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0x000B
Line 283: Line 310:
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFFFFFFFFFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFFFFFFFFFFFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFFFFFFFFFFFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFFFFFFFFFFFFFF
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |0xFFFFFFFFFFFFFFFF
|-  
|-  
|}
|}


'''Note: 0x000B command was added since 03.27.04.Rev.104 firmware version and would not work with older versions.'''
'''Note: 0x000B command was added since 03.27.04.Rev.104 firmware version and would not work with older versions.'''
<br>
<br>
Response command meta data:
Response command meta data:
{| class="wikitable"
{| class="wikitable"
Line 298: Line 330:
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Description'''
! rowspan="1" style="width: 400px; background: #0054A6; color: white;" |'''Description'''
|-
|-
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Command  version
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" | Command  version
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Iteration  of the command itself to determine to parse of the data
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Iteration  of the command itself to determine to parse of the data
|-
|-
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |File  type
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |File  type
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Media type for confirming which file’s metadata is received. Byte structure is the  same as byte 3 in the initialization packet settings data  
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Media type for confirming which file’s metadata is received. Byte structure is the  same as byte 3 in the initialization packet settings data
|-
|-
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Timestamp
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Timestamp
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Timestamp at the time of the trigger. Same used in a corresponding SOS record
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Timestamp at the time of the video file being finalized.
|-
|-
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Trigger
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Trigger
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Trigger values. Same values as video sending trigger in SOS record.
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" | Trigger values. Same values as video sending trigger in SOS record.
|-
|-
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Video  length
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Video  length
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Duration of the video in seconds. If the file type is a photo, this value is 0x0000.
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Duration of the video in seconds. If the file type is a photo, this value is 0x0000.
|-
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Trigger Timestamp
| rowspan="1" style="text-align: center; style=" width: 150px; background: white; color: black;" |Timestamp at the time of the trigger. The same value is used in the corresponding event record.
|-  
|-  
|}
|}
'''Metadata command response version changes:'''
* Version 1 - added metadata response command.
* Version 2 - added frame rate setting.
* Version 3 - added time zone and coordinates.
* Version 4 - added trigger timestamp value in milliseconds (available from 03.29.00.Rev.534 FW version)
==Converting Latitude and Longitude values to decimal ==
Latitude and Longitude values are being sent in HEX format, but to correctly parse them conversation from <b>HEX</b> to <b>Double</b>. Example:<br>
The received value in HEX is 404B59A74E8E028D<br>
<ol>
<li>Convert the hexadecimal value to binary. The hex value <b>404B59A74E8E028D</b> can be converted to binary as <b>0100000001001011010110011010011101001110100011101110000001010001101</b>. </li>
<li>Determine the sign bit. The sign bit is the leftmost bit of the binary representation. A value of 0 indicates a positive number, while a value of 1 indicates a negative number. </li>
<li>Determine the exponent. The exponent is the next 11 bits after the sign bit. Subtract 1023 from the exponent value to obtain the actual exponent. In our example, the exponent bits "10000000100" correspond to the exponent value of 1028 (i.e., 2^10 + 2^3 = 1024 + 8 = 1032, and 1032 - 4 = 1028, since the bias for double precision is 1023). </li>
<li>Determine the significand. The significand is the remaining 52 bits after the sign bit and exponent. Add an implicit leading 1 to the significand to obtain a value between 1 and 2. In our example, the significand bits 0101101001110100011101010111010011100110000000010 correspond to a significand value of 1.3582693302319776. </li>
<li>Calculate the final value. The final value is determined by combining the sign bit, exponent, and significand according to the IEEE 754 standard for double-precision floating-point numbers. The formula is: (-1)^signbit x significand x 2^(exponent-1023). In our example, the final value is (-1)^0 x 1.3582693302319776 x 2^(1028-1023) = 54.7004183. <br>
Therefore, the hexadecimal value 404B59A74E8E028D is equivalent to the double-precision floating-point value of approximately <b>54.7004183</b>. </ol>


==CRC-16 calculation==
[[File:HexToDecimal.png]]
 
== CRC-16 calculation ==
CRC is calculated with using 3 input variables:
CRC is calculated with using 3 input variables:


Line 342: Line 400:
  }
  }


CRC (Cyclic Redundancy Check) is an error-detecting code using for detect accidental changes to RAW data. The algorithm how to calculate CRC-16 (also known as CRC-16/IBM) you will find below.
CRC (Cyclic Redundancy Check) is an error - detecting code using for detect accidental changes to RAW data.
The algorithm how to calculate CRC - 16 (also known as CRC - 16 / IBM) you will find below.


  var crc = {
  var crc = {
    extractCRC: function(message){
    extractCRC: function (message) {
        crcData = message.slice(message.length-2,message.length);
        crcData = message.slice(message.length - 2, message.length);
        return crcData[0] * 256 + crcData[1];
        return crcData[0] * 256 + crcData[1];
    },<br>
    },
    crcCam: function(message, previous_crc){
    calculateCRC: function(message, previous_crc) {
        payload = message.slice(2, message.length-2);
        let crc_poly = 0x8408;
        crc = 0x0000;
        let idx = 0;
        bitOne = 0x0001;
        let crc = 0x0000;
        crcpoly = 0x8408;
        idx = 0;<br>
        /* the payload length is calculated with removing size of header and CRC (4 + 2 bytes) */
        /*At this point you should start with the init value for CRC calculation. Init value for
        let payload_length = message.length - 6;  
        * the first packet is zero and for the upcoming packets it is the CRC value of the previous package
        */
        /* the payload is separated from the message header and CRC (4 bytes ofset + length)*/
        crc = previous_crc<br>
        let payload = message.slice(4, 4 + payload_length);
        while (idx < payload.length) {
            /* Use XOR operation for initial value and payload */
        /* Init value for the first message is zero and for the upcoming messages it is the CRC value of the previous message */
            crc ^= payload[idx];
        crc = previous_crc;
            bitcounter = 0;<br>
            while (bitcounter < 8) {
        for (idx = 0; idx < payload_length; idx++) {
                crcFirstBit = crc & bitOne;
            let bit;
                crc >>= 1;<br>
            /* Use XOR operation for initial value and payload */
                if (crcFirstBit) {
            crc ^= payload[idx];
                    crc ^= crcpoly;
                }
            for (bit = 0; bit < 8; bit++) {
            }
                let carry_bit = crc & 0x01;
            idx = idx + 1;
                crc >>= 0x01;
        }
        return crc;
                if (carry_bit != 0) {
    }
                    crc ^= crc_poly;
                }
            }
        }      
        return crc;
    }
  };
  };
  exports.crc = crc;
  exports.crc = crc;
Line 383: Line 447:
For converting DualCam h265 videos to a more popular mp4 video format, a free open-source converter FFmpeg is used in the example. Although any other converter from h265 would work as well.
For converting DualCam h265 videos to a more popular mp4 video format, a free open-source converter FFmpeg is used in the example. Although any other converter from h265 would work as well.


To convert DualCam video properly, the converter has to know the frame rate of the video. The frame rate is configured as Config Id: 66003 and could be either 20, 25, or 30 FPS. That same value could be obtained by using the metadata command (see more details at [[Teltonika_DualCam#Communication_protocol|File metadata response]] ('''CMD ID 0x000B''')).
To convert DualCam video properly, the converter has to know the frame rate of the video. The frame rate is configured as Config Id: 66003 and could be either 20, 25, or 30 FPS. That same value could be obtained by using the metadata command (see more details at File metadata response) ('''CMD ID 0x000B''').


Recommended parameters using the FFmpeg for the conversion:
Recommended parameters using the FFmpeg for the conversion:
Line 394: Line 458:


<output> - file name of the video that will be converted to mp4.
<output> - file name of the video that will be converted to mp4.
==Additional audio converting from video file==
This information is only for cameras that support sound recording
Please find attached files required for video converting, so there is also audio.
[https://drive.teltonika.lt/f/fd842e86a16344e681d8/?dl=1 Here]
When you receive a *.h265 file, you will need to convert it to *.mp4, by using the “VideoConverter.exe”.
There is a *.bat file with an example.
The principle use is very simple. Instead of converting with the FFMPEG library, you just use the “VideoConverter.exe”:
ZmConverter\VideoConverter.exe '''codec''' "path_to_input_file.h265" "path_to_converted_file.mp4"
Will receive with h265 codec:
[[File:Gauni_su_h265s.jpg|alt=|frameless|653x653px]]
To have the h264 codec:
[[File:H264s.jpg|alt=|frameless|660x660px]]
In the end, you will have this:
[[File:End_of_codec.jpg|alt=|frameless|658x658px]]


==Video files and conversion==
==Video files and conversion==
Videos downloaded from the camera are in the raw h265 format. By default, they could be viewed using the ZMVideoPlayer program in the h265 format. If the videos are needed in a more common format, they can be converted.
Videos downloaded from the camera are in the raw h265 format. By default, they could be viewed using the ZMVideoPlayer program in the h265 format. If the videos are needed in a more common format, they can be converted.


[[Category:Test Dual Cam wiki]]
[[Category:Teltonika DualCam]]