Skip to main content

gondola_core/
constants.rs

1//! The following file is part of gaps-online-software and published 
2//! under the GPLv3 license
3//! Global constants for TOF operations
4//!
5//! ISSUES:
6//! * there might be constants defined elsewhere,
7//!   also we are defining constants in .toml files
8//!   now. There is an active issue #18
9//!
10
11/// A generic pattern for online files, matching most types 
12pub static GENERIC_ONLINE_FILE_PATTERN : &str = r"Run\d+_\d+\.(\d{6})_(\d{6})(UTC)?(\.tofsum|\.tof)?\.gaps$";
13pub static GENERIC_ONLINE_FILE_PATTERN_CAPTURE : &str = r"Run(?P<run>\d+)_(?P<subrun>\d+)\.(?P<utctime>\d{6}_\d{6})(UTC)?(\.tofsum|\.tof)?\.gaps$";
14pub static GENERIC_TELEMETRY_FILE_PATTERN_CAPTURE : &str = r"RAW(?P<utctime>\d{6}_\d{6})(UTC)?.bin$";
15
16/// The TimeStamp format for Human readable timestamps
17pub static HUMAN_TIMESTAMP_FORMAT : &str = "%y%m%d_%H%M%S%Z"; 
18
19/// Reference time for un-wrapping the 48bit GPS timestamps
20/// (MTB timestamp16/timestamp32, 10ns ticks since the UNIX epoch).
21///
22/// Only the lower 48 bits are transmitted, which wrap every 
23/// 2^48 * 10ns = 32.58 days. The upper bits are chosen such 
24/// that the timestamp is the one closest to this reference. 
25/// Timestamps are therefore only valid within +- 16.29 days
26/// around it.
27///
28/// Value: 2025-12-28 00:00:00 UTC (middle of the 2025/26 flight,
29/// 2025-12-15 - 2026-01-09) -> valid window is 
30/// 2025-12-11 17:03 UTC - 2026-01-13 06:56 UTC 
31///
32/// <div class="warning">This MUST be changed for any data taken outside 
33/// of that window (e.g. the next flight)!</div>
34pub const GPS_TIMESTAMP48_REFERENCE : u64 = 1766880000 * 100_000_000;
35
36/// Expand a 48bit GPS timestamp (10ns ticks) to the full
37/// timestamp since the UNIX epoch, by choosing the 
38/// 2^48 period which is closest to GPS_TIMESTAMP48_REFERENCE
39pub const fn expand_gps_timestamp48(ts48 : u64) -> u64 {
40  const PERIOD : u64 = 1 << 48;
41  let ts48 = ts48 & (PERIOD - 1);
42  let full = (GPS_TIMESTAMP48_REFERENCE & !(PERIOD - 1)) | ts48;
43  if full > GPS_TIMESTAMP48_REFERENCE + PERIOD/2 {
44    full - PERIOD
45  } else if full + PERIOD/2 < GPS_TIMESTAMP48_REFERENCE {
46    full + PERIOD
47  } else {
48    full
49  }
50}
51
52#[test]
53fn expand_gps_timestamp48_flight() {
54  const PERIOD : u64 = 1 << 48;
55  // 2025-12-15 00:00 UTC (before the rollover on 2026-01-06 01:27 UTC)
56  let t0 : u64 = 1765756800 * 100_000_000;
57  assert_eq!(expand_gps_timestamp48(t0 % PERIOD), t0);
58  // 2026-01-09 23:59:59 UTC (after the rollover)
59  let t1 : u64 = 1768003199 * 100_000_000;
60  assert_eq!(expand_gps_timestamp48(t1 % PERIOD), t1);
61  // just before and after the rollover
62  let tr : u64 = 0x274 * PERIOD;
63  assert_eq!(expand_gps_timestamp48((tr - 1) % PERIOD), tr - 1);
64  assert_eq!(expand_gps_timestamp48(tr % PERIOD), tr);
65}
66
67/// Speed of light in the scintillator paddles
68/// (divine number from the TOF team)
69/// This value is in cm/ns
70pub const C_LIGHT_PADDLE : f32 = 15.4; 
71
72/// Speed of light in the harting cables
73/// (divine number from the TOF team)
74/// This value is in cm/ns
75pub const C_LIGHT_CABLE : f32 = 24.6;
76
77/// Number of AVAILABLE slots for LocalTriggerBoards
78pub const N_LTBS : usize = 25;
79
80/// Number of AVAILABLE channels per each LocalTriggerBoard
81pub const N_CHN_PER_LTB : usize = 16;
82
83/// Number of Channels on the readoutboards
84pub const NCHN          : usize = 9;  
85
86/// Number of entries for each waveform (voltage and timing each)
87pub const NWORDS        : usize = 1024;
88
89/// Masks for 32 bits commands (byte packets)
90///
91pub const MASK_CMD_8BIT  : u32 = 0x000000FF;
92pub const MASK_CMD_16BIT : u32 = 0x0000FFFF;
93pub const MASK_CMD_24BIT : u32 = 0x00FFFFFF;
94pub const MASK_CMD_32BIT : u32 = 0xFFFFFFFF;
95/// Padding for 32 bits commands (byte packets)
96///
97pub const PAD_CMD_32BIT  : u32 = 0x00000000;
98
99/// Si(Li) wafer detector radius, with guardring and all
100pub const SILI_RADIUS : f32 = 5.0;
101
102// These are just for fun 
103
104/// Make a nice ASCII logo for the liftof of flight code
105pub const LIFTOF_LOGO_SHOW  : &str  = "
106                                  ___                         ___           ___     
107                                 /\\__\\                       /\\  \\         /\\__\\    
108                    ___         /:/ _/_         ___         /::\\  \\       /:/ _/_   
109                   /\\__\\       /:/ /\\__\\       /\\__\\       /:/\\:\\  \\     /:/ /\\__\\  
110    ___     ___   /:/__/      /:/ /:/  /      /:/  /      /:/  \\:\\  \\   /:/ /:/  /  
111   /\\  \\   /\\__\\ /::\\  \\     /:/_/:/  /      /:/__/      /:/__/ \\:\\__\\ /:/_/:/  /   
112   \\:\\  \\ /:/  / \\/\\:\\  \\__  \\:\\/:/  /      /::\\  \\      \\:\\  \\ /:/  / \\:\\/:/  /    
113    \\:\\  /:/  /   ~~\\:\\/\\__\\  \\::/__/      /:/\\:\\  \\      \\:\\  /:/  /   \\::/__/     
114     \\:\\/:/  /       \\::/  /   \\:\\  \\      \\/__\\:\\  \\      \\:\\/:/  /     \\:\\  \\     
115      \\::/  /        /:/  /     \\:\\__\\          \\:\\__\\      \\::/  /       \\:\\__\\    
116       \\/__/         \\/__/       \\/__/           \\/__/       \\/__/         \\/__/    
117
118          (LIFTOF - liftof is for tof, Version 0.11.x 'PAKII', Aug 2025)
119          >> with undying support from the Hawaiian islands \u{1f30a}\u{1f308}\u{1f965}\u{1f334}
120
121          * Documentation
122          ==> GitHub   https://github.com/GAPS-Collab/gaps-online-software/tree/PAKII-0.11
123          ==> API docs https://gaps-collab.github.io/gaps-online-software/
124
125  ";
126
127
128
129