Post

Parse Shearwater Dive Log

Instructions to parse Shearwater dive logs

Parse Shearwater Dive Log

Introduction

This guide provides instructions on how to parse blob data or whole dive log source file from Shearwater.

To get the blob data, you can use Export Databases to export sqlitedb files from the Shearwater Cloud Desktop application.

To get the whole dive log source file, you can use Export as Source File to export .swlogdata files from Shearwater Cloud Desktop application.

There are 2 formats of the BLOB data located in the table log_data of the exported sqlite db:

  • sw-clouddb
  • sw-pnf

For sw-clouddb format, the BLOB data is stored in column data_bytes_1 and data_bytes_2.

For sw-pnf format, the BLOB data is stored in column data_bytes_1.

Preparing the Environment

Steps to Parse Dive Log

  • Create a C# Console Application in Visual Studio with .NET Framework 4.8.1

  • Add reference to the following DLLs from Shearwater Cloud Desktop installation directory, usually C:\Program Files (x86)\Shearwater Research\Shearwater Cloud Desktop\ShearwaterCloudDesktop_Data\Managed
    • Assembly-CSharp.dll
    • CoreParserUtilities.dll
    • DiveLogModels.dll
    • DiveLogParser.dll
    • ShearwaterUtils.dll
  • Install the following NuGet packages:
    • Newtonsoft.Json 13.0.4
    • SharpZipLib 1.3.3
  • Use the following code snippet to parse the dive log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Assets.Scripts.Extensions;
using Assets.Scripts.Persistence.LocalCache.Schema;
using DiveLogModels;
using DiveLogParser;
using Newtonsoft.Json;
using System.IO;
using System.Text;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Parse whole shearwater source file
            byte[] bin = File.ReadAllBytes("<Path to .swlogdata file>");
            IDiveLogParser parser = RawDiveLogParserDecider.Decide(bin);
            DiveLog log = parser.GetDiveLog(bin);

            // Parse log_data.data_bytes_1 and log_data.data_bytes_2 blobs from shearwater exported sqlite db with type sw-clouddb
            byte[] bin1 = File.ReadAllBytes("<Path to data_bytes_1.bin>").FromCompressedByteArray();
            dive_logs info = JsonConvert.DeserializeObject<dive_logs>(Encoding.Default.GetString(bin1));

            byte[] bin2 = File.ReadAllBytes("<Path to data_bytes_2.bin>").FromCompressedByteArray();
            dive_log_records[] samples = JsonConvert.DeserializeObject<dive_log_records[]>(Encoding.Default.GetString(bin2));

            // Parse log_data.data_bytes_1 blob from shearwater exported sqlite db with type sw-pnf
            byte[] bin3 = File.ReadAllBytes("<Path to data_bytes_1.bin>").FromCompressedByteArray();
            RawDiveLogType type3 = RawDiveLogDescriminator.WhatKindIsThis(bin3);
            DiveLog rawLog3 = RawDiveLogParserDecider.Decide(bin).GetDiveLog(bin3);
        }
    }
}
This post is licensed under CC BY 4.0 by the author.