asyn-rs 0.25.0

Rust port of EPICS asyn - async device I/O framework
Documentation
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//! Record field tables generated from the vendored EPICS `.dbd` record
//! declarations — the machine-readable spec every `FieldDesc` used to be
//! hand-copied from.
//!
//! @generated by `tools/dbd-codegen` from `crates/asyn-rs/dbd/*.dbd`.
//! DO NOT EDIT. Re-run `cargo run -p dbd-codegen -- --write` after changing a
//! vendored `.dbd`. Drift is caught by `dbd_codegen::tests::generated_files_are_not_stale`,
//! which `cargo nextest run` executes — locally and in CI — so a stale table
//! is a failing test, not a comment asking you to remember.
//!
//! What is *not* here, and why:
//!
//! * **`dbCommon` fields.** The port models them once in
//!   [`CommonFields`](epics_base_rs::server::record::CommonFields), so splicing them
//!   into every record table would double-declare them. Base's table emits
//!   them separately as `DB_COMMON_FIELDS` so the two models can be reconciled
//!   (and so a `dbCommon` addition is a diff, not a silent gap).
//! * **`DBF_NOACCESS` fields** (`RSET`, `DPVT`, `MLOK`, `BPTR`, `PPN`, ...).
//!   These are C-internal pointers with no CA/PVA representation — C's
//!   `mapDBFToDBR` sends them to `DBR_NOACCESS` and `dbChannelCreate` refuses
//!   a channel on them. A Rust port has no pointer to expose, so they are
//!   dropped rather than invented; the count is reported by the generator.

#![allow(clippy::all)]

use epics_base_rs::server::record::DbLinkType;
use epics_base_rs::server::record::FieldDesc;

// ---------------------------------------------------------------------
// `menu(...)` choice tables. The index is the stored `epicsEnum16` and is
// wire-visible (a `DBF_MENU` field is served as `DBR_ENUM`), so the order
// here is the `.dbd` declaration order, verbatim.
// ---------------------------------------------------------------------

/// Every `menu()` declared by a vendored `.dbd`, keyed by its EPICS name.
///
/// This is the table `get_enum_strs` answers a `DBF_MENU` field from: the
/// field's [`FieldDesc::menu`] already points at its choices, and this map
/// exists for the by-name lookups (`.db` loading, `dbpr`).
pub fn menu_choices(menu: &str) -> Option<&'static [&'static str]> {
    let _ = menu;
    None
}

// ---------------------------------------------------------------------
// Per-record-type field tables. Record-*own* fields only: `dbCommon` is
// modelled separately (see the module docs).
// ---------------------------------------------------------------------

// ---------------------------------------------------------------------
// Per-record-type device menus (C `dbDeviceMenu`), in `.dbd` declaration
// order. The index is wire-visible: it IS the value of the DTYP field.
// ---------------------------------------------------------------------

/// `device(aai, ...)` choices, in declaration order.
pub static DEVICE_MENU_AAI: &[&str] = &[
    "asynInt8ArrayIn",
    "asynInt16ArrayIn",
    "asynInt32ArrayIn",
    "asynFloat32ArrayIn",
    "asynFloat64ArrayIn",
    "asynInt64ArrayIn",
];

/// `device(aao, ...)` choices, in declaration order.
pub static DEVICE_MENU_AAO: &[&str] = &[
    "asynInt8ArrayOut",
    "asynInt16ArrayOut",
    "asynInt32ArrayOut",
    "asynFloat32ArrayOut",
    "asynFloat64ArrayOut",
    "asynInt64ArrayOut",
];

/// `device(ai, ...)` choices, in declaration order.
pub static DEVICE_MENU_AI: &[&str] = &[
    "asynInt32",
    "asynInt32Average",
    "asynFloat64",
    "asynFloat64Average",
    "asynInt64",
];

/// `device(ao, ...)` choices, in declaration order.
pub static DEVICE_MENU_AO: &[&str] = &["asynInt32", "asynFloat64", "asynInt64"];

/// `device(bi, ...)` choices, in declaration order.
pub static DEVICE_MENU_BI: &[&str] = &["asynInt32", "asynUInt32Digital"];

/// `device(bo, ...)` choices, in declaration order.
pub static DEVICE_MENU_BO: &[&str] = &["asynInt32", "asynUInt32Digital"];

/// `device(int64in, ...)` choices, in declaration order.
pub static DEVICE_MENU_INT64IN: &[&str] = &["asynInt64"];

/// `device(int64out, ...)` choices, in declaration order.
pub static DEVICE_MENU_INT64OUT: &[&str] = &["asynInt64"];

/// `device(longin, ...)` choices, in declaration order.
pub static DEVICE_MENU_LONGIN: &[&str] = &["asynInt32", "asynUInt32Digital", "asynInt64"];

/// `device(longout, ...)` choices, in declaration order.
pub static DEVICE_MENU_LONGOUT: &[&str] = &["asynInt32", "asynUInt32Digital", "asynInt64"];

/// `device(lsi, ...)` choices, in declaration order.
pub static DEVICE_MENU_LSI: &[&str] = &[
    "asynOctetCmdResponse",
    "asynOctetWriteRead",
    "asynOctetRead",
];

/// `device(lso, ...)` choices, in declaration order.
pub static DEVICE_MENU_LSO: &[&str] = &["asynOctetWrite"];

/// `device(mbbi, ...)` choices, in declaration order.
pub static DEVICE_MENU_MBBI: &[&str] = &["asynInt32", "asynUInt32Digital"];

/// `device(mbbiDirect, ...)` choices, in declaration order.
pub static DEVICE_MENU_MBBIDIRECT: &[&str] = &["asynUInt32Digital"];

/// `device(mbbo, ...)` choices, in declaration order.
pub static DEVICE_MENU_MBBO: &[&str] = &["asynInt32", "asynUInt32Digital"];

/// `device(mbboDirect, ...)` choices, in declaration order.
pub static DEVICE_MENU_MBBODIRECT: &[&str] = &["asynUInt32Digital"];

/// `device(printf, ...)` choices, in declaration order.
pub static DEVICE_MENU_PRINTF: &[&str] = &["asynOctetWrite"];

/// `device(stringin, ...)` choices, in declaration order.
pub static DEVICE_MENU_STRINGIN: &[&str] = &[
    "asynOctetCmdResponse",
    "asynOctetWriteRead",
    "asynOctetRead",
];

/// `device(stringout, ...)` choices, in declaration order.
pub static DEVICE_MENU_STRINGOUT: &[&str] = &["asynOctetWrite"];

/// `device(waveform, ...)` choices, in declaration order.
pub static DEVICE_MENU_WAVEFORM: &[&str] = &[
    "asynOctetCmdResponse",
    "asynOctetWriteRead",
    "asynOctetRead",
    "asynOctetWrite",
    "asynOctetWriteBinary",
    "asynInt8ArrayIn",
    "asynInt8ArrayOut",
    "asynInt16ArrayIn",
    "asynInt16ArrayOut",
    "asynInt32ArrayIn",
    "asynInt32ArrayOut",
    "asynFloat32ArrayIn",
    "asynFloat32ArrayOut",
    "asynFloat64ArrayIn",
    "asynFloat64ArrayOut",
    "asynInt32TimeSeries",
    "asynFloat64TimeSeries",
    "asynInt64ArrayIn",
    "asynInt64ArrayOut",
    "asynInt64TimeSeries",
];

/// The device menu for a record type — the choices its `DTYP` field selects
/// among, in `.dbd` declaration order. `None` for a record type that declares
/// no device support: C has no `dbDeviceMenu` for it, and its DTYP renders as
/// the empty string.
pub fn device_menu(record_type: &str) -> Option<&'static [&'static str]> {
    Some(match record_type {
        "aai" => DEVICE_MENU_AAI,
        "aao" => DEVICE_MENU_AAO,
        "ai" => DEVICE_MENU_AI,
        "ao" => DEVICE_MENU_AO,
        "bi" => DEVICE_MENU_BI,
        "bo" => DEVICE_MENU_BO,
        "int64in" => DEVICE_MENU_INT64IN,
        "int64out" => DEVICE_MENU_INT64OUT,
        "longin" => DEVICE_MENU_LONGIN,
        "longout" => DEVICE_MENU_LONGOUT,
        "lsi" => DEVICE_MENU_LSI,
        "lso" => DEVICE_MENU_LSO,
        "mbbi" => DEVICE_MENU_MBBI,
        "mbbiDirect" => DEVICE_MENU_MBBIDIRECT,
        "mbbo" => DEVICE_MENU_MBBO,
        "mbboDirect" => DEVICE_MENU_MBBODIRECT,
        "printf" => DEVICE_MENU_PRINTF,
        "stringin" => DEVICE_MENU_STRINGIN,
        "stringout" => DEVICE_MENU_STRINGOUT,
        "waveform" => DEVICE_MENU_WAVEFORM,
        _ => return None,
    })
}

/// The record types [`device_menu`] returns `Some` for, in `.dbd` name order.
pub static DEVICE_MENU_RECORD_TYPES: &[&str] = &[
    "aai",
    "aao",
    "ai",
    "ao",
    "bi",
    "bo",
    "int64in",
    "int64out",
    "longin",
    "longout",
    "lsi",
    "lso",
    "mbbi",
    "mbbiDirect",
    "mbbo",
    "mbboDirect",
    "printf",
    "stringin",
    "stringout",
    "waveform",
];

// ---------------------------------------------------------------------
// Per-(record type, DTYP) device LINK TYPE (C `devSup::link_type`), the
// half of the `device()` declaration `dbCanSetLink` enforces.
// ---------------------------------------------------------------------

/// `device(aai, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_AAI: &[(&str, DbLinkType)] = &[
    ("asynInt8ArrayIn", DbLinkType::InstIo),
    ("asynInt16ArrayIn", DbLinkType::InstIo),
    ("asynInt32ArrayIn", DbLinkType::InstIo),
    ("asynFloat32ArrayIn", DbLinkType::InstIo),
    ("asynFloat64ArrayIn", DbLinkType::InstIo),
    ("asynInt64ArrayIn", DbLinkType::InstIo),
];

/// `device(aao, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_AAO: &[(&str, DbLinkType)] = &[
    ("asynInt8ArrayOut", DbLinkType::InstIo),
    ("asynInt16ArrayOut", DbLinkType::InstIo),
    ("asynInt32ArrayOut", DbLinkType::InstIo),
    ("asynFloat32ArrayOut", DbLinkType::InstIo),
    ("asynFloat64ArrayOut", DbLinkType::InstIo),
    ("asynInt64ArrayOut", DbLinkType::InstIo),
];

/// `device(ai, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_AI: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynInt32Average", DbLinkType::InstIo),
    ("asynFloat64", DbLinkType::InstIo),
    ("asynFloat64Average", DbLinkType::InstIo),
    ("asynInt64", DbLinkType::InstIo),
];

/// `device(ao, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_AO: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynFloat64", DbLinkType::InstIo),
    ("asynInt64", DbLinkType::InstIo),
];

/// `device(bi, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_BI: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynUInt32Digital", DbLinkType::InstIo),
];

/// `device(bo, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_BO: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynUInt32Digital", DbLinkType::InstIo),
];

/// `device(int64in, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_INT64IN: &[(&str, DbLinkType)] = &[("asynInt64", DbLinkType::InstIo)];

/// `device(int64out, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_INT64OUT: &[(&str, DbLinkType)] = &[("asynInt64", DbLinkType::InstIo)];

/// `device(longin, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_LONGIN: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynUInt32Digital", DbLinkType::InstIo),
    ("asynInt64", DbLinkType::InstIo),
];

/// `device(longout, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_LONGOUT: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynUInt32Digital", DbLinkType::InstIo),
    ("asynInt64", DbLinkType::InstIo),
];

/// `device(lsi, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_LSI: &[(&str, DbLinkType)] = &[
    ("asynOctetCmdResponse", DbLinkType::InstIo),
    ("asynOctetWriteRead", DbLinkType::InstIo),
    ("asynOctetRead", DbLinkType::InstIo),
];

/// `device(lso, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_LSO: &[(&str, DbLinkType)] = &[("asynOctetWrite", DbLinkType::InstIo)];

/// `device(mbbi, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_MBBI: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynUInt32Digital", DbLinkType::InstIo),
];

/// `device(mbbiDirect, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_MBBIDIRECT: &[(&str, DbLinkType)] =
    &[("asynUInt32Digital", DbLinkType::InstIo)];

/// `device(mbbo, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_MBBO: &[(&str, DbLinkType)] = &[
    ("asynInt32", DbLinkType::InstIo),
    ("asynUInt32Digital", DbLinkType::InstIo),
];

/// `device(mbboDirect, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_MBBODIRECT: &[(&str, DbLinkType)] =
    &[("asynUInt32Digital", DbLinkType::InstIo)];

/// `device(printf, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_PRINTF: &[(&str, DbLinkType)] =
    &[("asynOctetWrite", DbLinkType::InstIo)];

/// `device(stringin, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_STRINGIN: &[(&str, DbLinkType)] = &[
    ("asynOctetCmdResponse", DbLinkType::InstIo),
    ("asynOctetWriteRead", DbLinkType::InstIo),
    ("asynOctetRead", DbLinkType::InstIo),
];

/// `device(stringout, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_STRINGOUT: &[(&str, DbLinkType)] =
    &[("asynOctetWrite", DbLinkType::InstIo)];

/// `device(waveform, LINK_TYPE, ...)` — the link type each DTYP choice demands.
pub static DEVICE_LINK_TYPES_WAVEFORM: &[(&str, DbLinkType)] = &[
    ("asynOctetCmdResponse", DbLinkType::InstIo),
    ("asynOctetWriteRead", DbLinkType::InstIo),
    ("asynOctetRead", DbLinkType::InstIo),
    ("asynOctetWrite", DbLinkType::InstIo),
    ("asynOctetWriteBinary", DbLinkType::InstIo),
    ("asynInt8ArrayIn", DbLinkType::InstIo),
    ("asynInt8ArrayOut", DbLinkType::InstIo),
    ("asynInt16ArrayIn", DbLinkType::InstIo),
    ("asynInt16ArrayOut", DbLinkType::InstIo),
    ("asynInt32ArrayIn", DbLinkType::InstIo),
    ("asynInt32ArrayOut", DbLinkType::InstIo),
    ("asynFloat32ArrayIn", DbLinkType::InstIo),
    ("asynFloat32ArrayOut", DbLinkType::InstIo),
    ("asynFloat64ArrayIn", DbLinkType::InstIo),
    ("asynFloat64ArrayOut", DbLinkType::InstIo),
    ("asynInt32TimeSeries", DbLinkType::InstIo),
    ("asynFloat64TimeSeries", DbLinkType::InstIo),
    ("asynInt64ArrayIn", DbLinkType::InstIo),
    ("asynInt64ArrayOut", DbLinkType::InstIo),
    ("asynInt64TimeSeries", DbLinkType::InstIo),
];

/// The link type the named `DTYP` of `record_type` demands of its `INP`/`OUT`.
///
/// `None` when no vendored `.dbd` declares that `device()` — a downstream
/// crate registering its device support at runtime (asyn, motor) brings no
/// `.dbd`, so there is no declaration to enforce and none is invented.
pub fn device_link_type(record_type: &str, dtyp: &str) -> Option<DbLinkType> {
    let table = match record_type {
        "aai" => DEVICE_LINK_TYPES_AAI,
        "aao" => DEVICE_LINK_TYPES_AAO,
        "ai" => DEVICE_LINK_TYPES_AI,
        "ao" => DEVICE_LINK_TYPES_AO,
        "bi" => DEVICE_LINK_TYPES_BI,
        "bo" => DEVICE_LINK_TYPES_BO,
        "int64in" => DEVICE_LINK_TYPES_INT64IN,
        "int64out" => DEVICE_LINK_TYPES_INT64OUT,
        "longin" => DEVICE_LINK_TYPES_LONGIN,
        "longout" => DEVICE_LINK_TYPES_LONGOUT,
        "lsi" => DEVICE_LINK_TYPES_LSI,
        "lso" => DEVICE_LINK_TYPES_LSO,
        "mbbi" => DEVICE_LINK_TYPES_MBBI,
        "mbbiDirect" => DEVICE_LINK_TYPES_MBBIDIRECT,
        "mbbo" => DEVICE_LINK_TYPES_MBBO,
        "mbboDirect" => DEVICE_LINK_TYPES_MBBODIRECT,
        "printf" => DEVICE_LINK_TYPES_PRINTF,
        "stringin" => DEVICE_LINK_TYPES_STRINGIN,
        "stringout" => DEVICE_LINK_TYPES_STRINGOUT,
        "waveform" => DEVICE_LINK_TYPES_WAVEFORM,
        _ => return None,
    };
    table
        .iter()
        .find(|(name, _)| name.eq_ignore_ascii_case(dtyp))
        .map(|(_, lt)| *lt)
}

/// The record-own field table for a record type name, or `None` for a type
/// no vendored `.dbd` declares.
pub fn record_fields(record_type: &str) -> Option<&'static [FieldDesc]> {
    let _ = record_type;
    None
}

/// Every record type a vendored `.dbd` declares, in `.dbd` name order.
pub static RECORD_TYPES: &[&str] = &[];