Mesotech_SMB: Kongsberg Mesotech SM2000 / DDS9001 (.smb) Tuple Stream Parser
Overview & Purpose
Mesotech_SMB (Mesotech_SMB.c / Mesotech_SMB.h) provides low-level binary synchronization and tuple framing extraction for Kongsberg Mesotech SM2000 and Defence R&D Canada (DRDC) DDS9001 .smb sonar data files. Written by John E. Hughes Clarke in March 2019, this module scans raw .smb byte streams, hunts for tuple synchronization markers, validates header fields against corruption, verifies matching header and footer payload lengths, and extracts the tuple data payload for downstream decoding.
Key Data Structures & Constants
Tuple Header & Footer Structures
#define SMB_TUPLE_HEADER_SIZE 16
typedef struct {
unsigned short Sync; /* Synchronization word: 32768 (0x8000) */
unsigned short SourceType; /* Sensor/source type identifier (valid: 0..200) */
unsigned short SourceID; /* Sensor instance ID (valid: 0..1000) */
unsigned short DataType; /* Tuple payload type (e.g., 4006 for large sonar records) */
unsigned int DataTime; /* Milliseconds within the day (valid: 0..86,400,000) */
unsigned short sDataSize1; /* 16-bit payload size (used when DataType != 4006) */
unsigned int iDataSize1; /* 32-bit payload size (used when DataType == 4006, or promoted from sDataSize1) */
} SMB_Tuple_Header;
#define SMB_TUPLE_FOOTER_SIZE 4
typedef struct {
unsigned short sDataSize2; /* 16-bit trailing payload size check */
unsigned int iDataSize2; /* 32-bit trailing payload size check */
} SMB_Tuple_Footer;
Public Functions & Signatures
int jSMB_get_next_tuple_header(FILE *file, SMB_Tuple_Header *head, SMB_Tuple_Footer *foot, char *data)
Locates, validates, and reads the next complete SMB tuple record from file.
Parameters
file: OpenFILE *stream positioned within an.smbbinary file.head: Pointer to anSMB_Tuple_Headerstruct populated with the tuple metadata.foot: Pointer to anSMB_Tuple_Footerstruct populated with the trailing size verification field.data: Caller-allocated buffer into which the tuple body (head->iDataSize1bytes) is read.
Algorithmic Workflow
- Sync Hunting (
hunt_for_sync): Reads 2 bytes at a time, sliding a 1-byte window forward until the 16-bitSyncword equals32768(0x8000in little-endian byte order). - Header Parsing: Rewinds 2 bytes to the start of the sync marker and reads
Sync,SourceType,SourceID,DataType, andDataTime. - Variable-Width Size Handling:
- If
head->DataType == 4006(large acoustic/beamforming tuple), reads a 32-bit integeriDataSize1(4 bytes). - For all other
DataTypevalues, reads a 16-bit unsigned shortsDataSize1(2 bytes) and assignshead->iDataSize1 = head->sDataSize1.
- If
- Sanity & Corruption Checks: Validates that:
0 <= SourceType <= 2000 <= SourceID <= 10000 <= DataType <= 100000 <= DataTime <= 86400000(milliseconds in 24 hours) If any check fails, the header is treated as a false sync match; the file pointer advances 2 bytes pastwhere_we_startand jumps back tohunt_for_sync.
- Footer Verification & Payload Read: Seeks forward by
head->iDataSize1bytes to read the footer size (iDataSize2orsDataSize2). Iffoot->iDataSize2 == head->iDataSize1, rewinds to the start of the payload, readshead->iDataSize1bytes intodata, and advances past the footer ready for the next call.- Returns:
1upon reading a tuple header.
- Returns:
How It Fits Into the OMG Architecture
Mesotech_SMB serves as the low-level transport/framing layer for .smb sonar logs. It is used directly by code/M3/DDSsmb_read.c (DDSsmb_read), which decodes the extracted tuple payloads (data) into OMG HDCS bathymetry and water-column structures.