Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions can-full/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,21 @@ authentication. `../nodes/full/zelosfull.cid` is its station file. Each data
object reads with its value, quality and time: `XSWI1`-`XSWI8` `Pos`,
`PTRC1`-`PTRC8` `Tr`, `EmcyGGIO1` `IntIn1` for the PDU; `OutMMDC1` `Vol` and
`Amp`, `InMMDC1` `Amp`, `STMP1` `Tmp`, `CycGGIO1` `CntVal1` for the DC-DC. The
data sets are GOOSE's own, one report control block each:
data sets `ds_pdu` and `ds_dcdc` are GOOSE's own; `ds_pos` lists the channels'
`Pos` as whole data objects. One report control block each:

| Report control block | Kind | Data set | Reports |
|---|---|---|---|
| `LLN0$BR$brcb_pdu01` | buffered | `ds_pdu` | a PDU change as it happens; the last 32 kept while no client is connected and replayed to one that resumes from its last EntryID |
| `LLN0$RP$urcb_dcdc01` | unbuffered | `ds_dcdc` | the DC-DC's members that moved, every 100 ms |
| `LLN0$BR$brcb_pos01` | buffered | `ds_pos` | a channel's `Pos` with its quality and time when it switches; kept and replayed as `brcb_pdu01`'s |

Both start with data change, quality change and general interrogation as
All start with data change, quality change and general interrogation as
triggers and no integrity period; a client sets its own. The node has no clock:
time stamps are time since boot, flagged clock not synchronized. No controls,
files or setting groups.
time stamps are time since boot, flagged clock not synchronized. UDS routine
`0x6186`, in the extended session, gives it one for a test: the TimeQuality
octet, then UTC in ms since 1970 (6 bytes, big-endian), 0 for time since boot
again. No controls, files or setting groups.

As an AUTOSAR ECU it sends what `../arxml/can-full.arxml` (an AUTOSAR R19-11
System Template of this bench, `bench.dbc` included) describes: E2E profiles 1,
Expand Down Expand Up @@ -243,7 +247,7 @@ limit, `0x1003` for a wrong key, `0x1` for any other command.
| `../testing/suites/doip` | DC-DC | Its UDS server as a DoIP entity (ISO 13400-2, `../lib/doip`), checked with a client written from the standard and with zelos-can's (doipclient), as the UDS and OBD extensions connect: vehicle identification by plain request, EID and VIN, answered within 500 ms, and one responder to a broadcast; entity status, power mode, header NACKs; routing activation's codes (0x10, 0x00, 0x02, 0x03 and 0x01 decided by alive checks, 0x06), initial inactivity; diagnostic messages acknowledged, NACKed (0x02, 0x03, 0x04 above MDS) or answered; three announcements 500 ms apart after a reset. The UDS conformance suite, unchanged, over DoIP. One server, two transports: a CAN tester's session gives the DoIP tester 0x21 and only OBD, and S3 still ends it; a closed DoIP owner's output returns at once; a pending routine answers its own tester. Core: ztests in `../tests/lib/doip` |
| `../testing/suites/someip` | DC-DC | Its SOME/IP service (DcdcService `0x5A00`, `../lib/someip`) and its SD, checked with a client written from the PRS: offers every second with TTL 3 and the service's UDP endpoint (where the SD group reaches the host: on this bench, not on the hardware bench, whose switch forwards it to IGMPv2 members only); FindService answered unicast within 100 ms; a subscription acknowledged, the Setpoint field's value at once, then DcdcStatus every 100 ms with none missing, each equal, within the frame's resolution, to the DCDC_Status of the same Counter; the getter equal to DID `0x0200`, and the notifier within 150 ms of a write over UDS; 0x28 stops the events, not SD or the getter; error codes; StopOffer at a reset, and the Reboot flag after it. Core: ztests in `../tests/lib/someip` |
| `../testing/suites/goose` | DC-DC, PDU | Its GOOSE (`../lib/goose`) captured raw on the host interface on the node's subnet and decoded by a BER walk written from IEC 61850-8-1 Annex A: both control blocks with their destinations, references, goID and data set sizes; timeAllowedtoLive twice the period, or one of the on-change ladder's; stNum and sqNum in sequence, none missed; `gcb_dcdc` every 100 ms (within 5 % on hardware). Needs CAP_NET_RAW, which the bench's tester has. Core: ztests in `../tests/lib/goose` |
| `../testing/suites/mms` | DC-DC, PDU | Its MMS server (`../lib/mms`) with an MMS client on the host: the data sets and report control blocks the station file declares; a data object read with its quality and time; the unbuffered block reporting the DC-DC every 100 ms, none missed; a PDU channel switched over CANopen reported by the buffered block, and a change made while no client was connected replayed to the client that resumes. Core: ztests in `../tests/lib/mms` |
| `../testing/suites/mms` | DC-DC, PDU | Its MMS server (`../lib/mms`) with an MMS client on the host: the data sets and report control blocks the station file declares; a data object read with its quality and time; the unbuffered block reporting the DC-DC every 100 ms, none missed; a PDU channel switched over CANopen reported by the buffered block, and a change made while no client was connected replayed to the client that resumes; a channel's `Pos` reported whole, its time by the clock set over UDS. Core: ztests in `../tests/lib/mms` |
| `../testing/suites/full` | all three | Every protocol at once for `--soak-s` (120 s here, 10 s on hardware): XCP DAQ, a UDS 64 KiB download and upload loop, CANopen operational with SYNC every 10 ms and RPDO1, J1939 and DCDC_Status. No EMCY, no DAQ sample lost, periods kept, and the node's counters (UDS DID `0x0110`) show no TX queue overflow, TX error or RX FIFO overrun |

The suites drive the other nodes' roles themselves when those nodes are absent,
Expand Down
82 changes: 68 additions & 14 deletions include/zelos/mms.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@
* reads from it and reports its changes. They are read when poked, every
* scan_ms, and before a read is served. A quality leaf without a value is
* always good. A time leaf is core-owned: when a value of its data object last
* changed, as time since boot from 1970-01-01 with the quality "clock not
* synchronized"; 0 until the first change.
* changed, by the clock as it was then (zelos_mms_clock()); 0 until the first
* change. Without a clock it is time since boot from 1970-01-01 with the
* quality "clock not synchronized".
*
* A data set lists data attributes or, with objects set, whole data objects
* (functionally constrained data): such a member is named to its data object
* and is the structure a read of it gives, t included.
*
* Report control blocks (IEC 61850-7-2), attributes in the order of 8-1:
* RptID, RptEna, Resv (unbuffered only), DatSet, ConfRev, OptFlds, BufTm,
Expand All @@ -50,7 +55,9 @@
* buffered one with ResvTms above 0 stays reserved that many seconds for
* a client of the same address. ResvTms -1 is not used.
* - Triggers: data change (a value leaf), quality change (a quality leaf),
* integrity every IntgPd ms, general interrogation. Changes within BufTm
* integrity every IntgPd ms, general interrogation. A data object is
* reported whole when a leaf of it triggers, with that leaf's reason, or
* both. Changes within BufTm
* ms of the first go in one report; a member changing twice sends the
* first report at once. SqNum starts at 0 when enabled and wraps at 8
* bits unbuffered, 16 buffered.
Expand All @@ -70,8 +77,13 @@
* without a client they would push the changes out of the ring.
* - Writing an attribute the value it has purges nothing. Changing RptID,
* DatSet, BufTm, TrgOps or IntgPd purges the buffer, as does PurgeBuf.
* - TimeofEntry is a BINARY-TIME, which cannot hold a date before 1984: it
* is time since boot from 1984-01-01.
* - TimeofEntry is a BINARY-TIME, which cannot hold a date before 1984:
* without a clock it is time since boot from 1984-01-01.
*
* Test knob: UDS RoutineControl ZELOS_MMS_ROUTINE (extended session; with
* lib/uds) sets the clock. Option record: the TimeQuality octet, then UTC in
* ms since 1970-01-01 (6 bytes, big-endian), 0 for time since boot. Result:
* the same two as the node has them.
*
* A send that fails closes that connection. The core never waits on a client;
* the socket layer's send may, for half a second at most.
Expand Down Expand Up @@ -104,6 +116,13 @@
#define ZELOS_MMS_BURST 8
/* A leaf without a value: a quality that is always good, or a time. */
#define ZELOS_MMS_NO_VALUE 0xFF
/* TimeQuality (IEC 61850-7-2): two of its flags, and the fraction's accuracy unspecified. */
#define ZELOS_MMS_CLOCK_FAILURE 0x40
#define ZELOS_MMS_CLOCK_NOT_SYNCHRONIZED 0x20
#define ZELOS_MMS_ACCURACY_UNSPECIFIED 0x1F
#define ZELOS_MMS_NO_CLOCK (ZELOS_MMS_CLOCK_NOT_SYNCHRONIZED | ZELOS_MMS_ACCURACY_UNSPECIFIED)
#define ZELOS_MMS_ROUTINE 0x6186
#define ZELOS_MMS_ROUTINE_OPTION 7
/* A report control block without a data set. */
#define ZELOS_MMS_NO_DATA_SET 0xFF

Expand Down Expand Up @@ -144,11 +163,15 @@ struct zelos_mms_leaf {
uint8_t value;
};

/* A data set: "LLN0$ds", its members as indices into the leaves. */
/*
* A data set: "LLN0$ds", its members as indices into the leaves. With objects,
* each is the first leaf of a data object, and the member is that object.
*/
struct zelos_mms_data_set {
const char *name;
const uint8_t *members;
uint8_t count;
bool objects;
};

/* A report control block: "LLN0", "brcb01". Its logical node must have a leaf. */
Expand All @@ -165,7 +188,8 @@ struct zelos_mms_rcb {
* The server's model: one logical device. The leaves go depth first: those of
* one logical node together, of one functional constraint within it together,
* and so on down the path. A time leaf stamps the values of its own data
* object (the path's first part). Data set members are not time leaves.
* object (the path's first part). A data attribute listed in a data set is
* not a time leaf.
*/
struct zelos_mms_model {
/* The logical device: the MMS domain. */
Expand Down Expand Up @@ -198,6 +222,15 @@ int zelos_mms_start(const struct zelos_mms_model *model);
/* A value may have changed: read them within 10 ms and report what did. Any context. */
void zelos_mms_poke(void);

/*
* The node's clock: UTC now in ms since 1970-01-01, and its TimeQuality.
* Changes from here on are stamped by it. Any context.
*/
void zelos_mms_clock(int64_t utc_ms, uint8_t quality);

/* The UDS routine ZELOS_MMS_ROUTINE: option as above; returns the result's length. */
uint8_t zelos_mms_routine(const uint8_t *option, uint8_t *result);

#endif /* CONFIG_ZELOS_MMS */

/*
Expand Down Expand Up @@ -258,14 +291,28 @@ struct zelos_mms_conn {
uint8_t buf[ZELOS_MMS_SPDU_MAX];
};

/* One report as a buffered block keeps it; members by their place in the data set. */
/* The values as read; when each last changed, UTC ms, and the clock's quality then. */
struct zelos_mms_values {
union zelos_mms_value value[ZELOS_MMS_VALUES_MAX];
int64_t changed[ZELOS_MMS_VALUES_MAX];
uint8_t quality[ZELOS_MMS_VALUES_MAX];
};

/* Members of a data set, by their place in it: those a value's change includes, a quality's. */
struct zelos_mms_hits {
uint32_t dchg;
uint32_t qchg;
};

/* One report as a buffered block keeps it: its members and the values as they were. */
struct zelos_mms_entry {
uint64_t id;
/* UTC ms. */
int64_t time;
uint32_t inclusion;
struct zelos_mms_hits hits;
/* Every member's reason for inclusion, or 0: each one's own change. */
uint8_t reason;
union zelos_mms_value value[ZELOS_MMS_MEMBERS_MAX];
struct zelos_mms_values at;
};

struct zelos_mms_ring {
Expand Down Expand Up @@ -303,7 +350,7 @@ struct zelos_mms_rcb_state {
/* A general interrogation is due. */
bool gi;
/* Members changed and not reported yet, since when, and when BufTm ends. */
uint32_t pending;
struct zelos_mms_hits pending;
int64_t pending_since;
int64_t pending_until;
int64_t integrity_at;
Expand All @@ -321,9 +368,13 @@ struct zelos_mms_core {
struct zelos_mms_conn conn[ZELOS_MMS_SOCKETS];
struct zelos_mms_rcb_state rcb[ZELOS_MMS_RCBS_MAX];
struct zelos_mms_ring ring[ZELOS_MMS_BUFFERED_MAX];
/* The values as last read, and when each last changed. */
union zelos_mms_value last[ZELOS_MMS_VALUES_MAX];
int64_t changed[ZELOS_MMS_VALUES_MAX];
/* UTC less now, ms, and the TimeQuality of a change stamped now. */
int64_t ahead;
uint8_t time_quality;
/* The values as last read. */
struct zelos_mms_values last;
/* The report being made: kept off the stack. */
struct zelos_mms_entry entry;
uint8_t out[ZELOS_MMS_FRAME_MAX];
};

Expand Down Expand Up @@ -358,6 +409,9 @@ int64_t zelos_mms_core_tick(struct zelos_mms_core *mms, int64_t now);
/** A value may have changed: read them now, then as zelos_mms_core_tick(). */
int64_t zelos_mms_core_poke(struct zelos_mms_core *mms, int64_t now);

/** The clock: UTC is `ahead` ms ahead of `now`, with this TimeQuality. */
void zelos_mms_core_clock(struct zelos_mms_core *mms, int64_t ahead, uint8_t quality);

/* Associated clients. */
uint8_t zelos_mms_core_clients(const struct zelos_mms_core *mms);

Expand Down
2 changes: 1 addition & 1 deletion include/zelos/uds.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct zelos_uds_io {
};

#define ZELOS_UDS_ROUTINE_RESULT_MAX 8
#define ZELOS_UDS_ROUTINE_OPTION_MAX 4
#define ZELOS_UDS_ROUTINE_OPTION_MAX 8

/*
* A node's routine: started with 0x31 0x01 and an option record of exactly
Expand Down
9 changes: 8 additions & 1 deletion lib/mms/core/mms_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,20 @@ int zelos_mms_core_init(struct zelos_mms_core *mms, const struct zelos_mms_model
mms->model = model;
mms->ops = ops;
mms->ctx = ctx;
mms->time_quality = ZELOS_MMS_NO_CLOCK;
/* The values at start, before any block looks at them: no change, no report. */
mms_scan(mms);
memset(mms->changed, 0, sizeof(mms->changed));
memset(mms->last.changed, 0, sizeof(mms->last.changed));
mms_rcb_init(mms, boot);
return 0;
}

void zelos_mms_core_clock(struct zelos_mms_core *mms, int64_t ahead, uint8_t quality)
{
mms->ahead = ahead;
mms->time_quality = quality;
}

int zelos_mms_core_accept(struct zelos_mms_core *mms, const uint8_t *peer, size_t peer_len,
int64_t now)
{
Expand Down
19 changes: 15 additions & 4 deletions lib/mms/core/mms_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ size_t mms_join(char *out, size_t cap, const char *a, char sep, const char *b);
size_t mms_leaf_name(const struct zelos_mms_model *model, uint8_t leaf, char *out);
/* The data set named item, or -1. */
int mms_data_set(const struct zelos_mms_model *model, const uint8_t *item, size_t len);
/* One past the last leaf of a data set's member m: its one leaf, or its data object's. */
uint8_t mms_member_end(const struct zelos_mms_model *model, const struct zelos_mms_data_set *ds,
size_t m);
/* The member's item name, a data object's without its attributes; its length. */
size_t mms_member_name(const struct zelos_mms_model *model, const struct zelos_mms_data_set *ds,
size_t m, char *out);

enum {
MMS_NONE,
Expand All @@ -140,11 +146,16 @@ enum {
/* What item names: MMS_LEAF fills *at. */
int mms_lookup(const struct zelos_mms_core *mms, const uint8_t *item, size_t len,
struct mms_object *at);
/* The object item names, as Data or as a TypeSpecification. MMS_NONE writes nothing. */
/*
* The object item names, as a TypeSpecification or as Data from the values at.
* MMS_NONE writes nothing.
*/
int mms_object(const struct zelos_mms_core *mms, struct mms_enc *e, const uint8_t *item, size_t len,
bool type);
/* A model leaf's value as Data. */
void mms_leaf_value(const struct zelos_mms_core *mms, struct mms_enc *e, uint8_t leaf);
bool type, const struct zelos_mms_values *at);
/* A data set member's value as Data, from the values at. */
void mms_member_value(const struct zelos_mms_core *mms, struct mms_enc *e,
const struct zelos_mms_data_set *ds, size_t m,
const struct zelos_mms_values *at);

const char *mms_rcb_attr(uint8_t attr);
bool mms_rcb_has(const struct zelos_mms_rcb *rcb, uint8_t attr);
Expand Down
Loading
Loading