|
PebbleOS
|
Session structures, limits and wire format shared by the data logging service. More...
Data Structures | |
| struct | DataLoggingSessionStorage |
| Location of a session's data in its file. More... | |
| struct | DataLoggingSessionComm |
| Endpoint state of a session. More... | |
| struct | DataLoggingActiveState |
| State of an active session. More... | |
| struct | DataLoggingSession |
| Data logging session. More... | |
Macros | |
| #define | DLS_FILE_NAME_PREFIX "dls_storage_" |
| Prefix of session file names, followed by the decimal session ID. | |
| #define | DLS_MAX_DATA_BYTES (DLS_TOTAL_STORAGE_BYTES - (DLS_MAX_NUM_SESSIONS * DLS_FILE_INIT_SIZE_BYTES)) |
| Space available to session files beyond their initial size. | |
| #define | DLS_INVALID_FILE (-1) |
| Value of DataLoggingSessionStorage::fd when the session has no open file. | |
| #define | DLS_SESSION_MAX_BUFFERED_ITEM_SIZE 300U |
| Largest item size, and largest dls_log() write, for buffered sessions. | |
| #define | DLS_SESSION_MIN_BUFFER_SIZE (DLS_SESSION_MAX_BUFFERED_ITEM_SIZE + 1) |
| Size of a buffered session's buffer. | |
Enumerations | |
| enum | DataLoggingStatus { DataLoggingStatusActive = 0x01 , DataLoggingStatusInactive = 0x02 } |
| Session status. More... | |
| enum | DataLoggingEndpointCmd { DataLoggingEndpointCmdOpen = 0x01 , DataLoggingEndpointCmdData = 0x02 , DataLoggingEndpointCmdClose = 0x03 , DataLoggingEndpointCmdReport = 0x04 , DataLoggingEndpointCmdAck = 0x05 , DataLoggingEndpointCmdNack = 0x06 , DataLoggingEndpointCmdTimeout = 0x07 , DataLoggingEndpointCmdEmptySession = 0x08 , DataLoggingEndpointCmdGetSendEnableReq = 0x09 , DataLoggingEndpointCmdGetSendEnableRsp = 0x0A , DataLoggingEndpointCmdSetSendEnable = 0x0B } |
| Data logging endpoint commands. More... | |
| enum | DataLoggingSessionCommState { DataLoggingSessionCommStateOpening , DataLoggingSessionCommStateIdle , DataLoggingSessionCommStateSending } |
| Endpoint state of a session. More... | |
Functions | |
| bool | dls_private_send_session (DataLoggingSession *logging_session, bool empty) |
| Send the next chunk of a session's stored data to the phone. | |
| void | dls_private_handle_disconnect (void *data) |
| Reset the endpoint state of all sessions after a disconnection. | |
| int | dls_test_read (DataLoggingSession *logging_session, uint8_t *buffer, int num_bytes) |
| Read session data, for unit tests only. | |
| int | dls_test_consume (DataLoggingSession *logging_session, int num_bytes) |
| Consume session data, for unit tests only. | |
| int | dls_test_get_num_bytes (DataLoggingSession *logging_session) |
| Get the number of unread bytes, for unit tests only. | |
| int | dls_test_get_tag (DataLoggingSession *logging_session) |
| Get the session tag, for unit tests only. | |
| uint8_t | dls_test_get_session_id (DataLoggingSession *logging_session) |
| Get the session ID, for unit tests only. | |
Variables | |
| static const uint32_t | DLS_FILE_NAME_MAX_LEN = 20 |
| Size of a buffer holding a session file name. | |
| static const uint32_t | DLS_FILE_INIT_SIZE_BYTES = PBL_KIB(4) |
| Initial size of a session file. | |
| static const uint32_t | DLS_MIN_FILE_FREE_BYTES = PBL_KIB(8) |
| Minimum free space added when a session file grows. | |
| static const uint32_t | DLS_MAX_FILE_FREE_BYTES = PBL_KIB(100) |
| Maximum free space added when a session file grows. | |
| static const uint32_t | DLS_MIN_FREE_BYTES = PBL_KIB(1) |
| Free space left at the end of a session file below which the file is grown. | |
| static const uint32_t | DLS_MAX_NUM_SESSIONS = 20 |
| Maximum number of sessions. | |
| static const uint32_t | DLS_TOTAL_STORAGE_BYTES = PBL_KIB(640) |
| Maximum file system space used by all session files. | |
| static const uint8_t | DLS_ENDPOINT_CMD_MASK = 0x7f |
| Mask of the command in the first byte of an endpoint message. | |
| static const uint32_t | DLS_ENDPOINT_MAX_PAYLOAD |
| Largest data message payload, and largest item size for unbuffered sessions. | |
Session structures, limits and wire format shared by the data logging service.
| struct DataLoggingSessionStorage |
Location of a session's data in its file.
| Data Fields | ||
|---|---|---|
| int | fd | PFS file descriptor, or DLS_INVALID_FILE when not open. |
| uint32_t | num_bytes | Number of unread bytes. |
| uint32_t | read_offset | File offset of the next read. |
| uint32_t | write_offset | File offset of the next write. |
| struct DataLoggingSessionComm |
Endpoint state of a session.
| Data Fields | ||
|---|---|---|
| RtcTicks | ack_timeout | Time in RTC ticks at which the pending ack times out, 0 when not waiting for one. |
| uint8_t | nack_count | Number of times the phone nacked this session. |
| int | num_bytes_pending | Bytes sent to the phone and not acked yet. |
| uint8_t | session_id | Session ID, chosen by the watch and unique among its sessions. |
| DataLoggingSessionCommState | state: 8 | Endpoint state. |
| struct DataLoggingActiveState |
State of an active session.
| Data Fields | ||
|---|---|---|
| struct pbl_shared_cbuf | buffer | Circular buffer of a buffered session. |
| struct pbl_shared_cbuf_client | buffer_client | Reader of buffer, consumed by KernelBG. |
| bool | buffer_in_kernel_heap: 1 | buffer_storage is on the kernel heap, else on the heap of the dls_create() caller. |
| uint8_t * | buffer_storage | Storage of buffer, NULL for unbuffered sessions. |
| bool | inactivate_pending: 1 | Inactivate the session once its last lock is released, see dls_unlock_session(). |
| struct pbl_mutex | mutex | Session lock, see dls_lock_session(). |
| uint8_t | open_count |
Number of locks held, changed under the list mutex. The state is freed only at 0. |
| bool | write_request_pending: 1 | A flash write has been requested from KernelBG and not run yet. |
| struct DataLoggingSession |
Data logging session.
Data logging session handle.
| Data Fields | ||
|---|---|---|
| Uuid | app_uuid | Owner UUID. |
| DataLoggingSessionComm | comm | Endpoint state. |
| DataLoggingActiveState * | data | Active state, NULL for inactive sessions. |
| uint16_t | item_size | Item size in bytes. |
| DataLoggingItemType | item_type: 4 | Item type. |
| struct DataLoggingSession * | next | Next session in the list. |
| time_t | session_created_timestamp | Creation time. |
| DataLoggingStatus | status: 4 | Session status. |
| DataLoggingSessionStorage | storage | Flash storage state. |
| uint32_t | tag | Session tag. |
| PebbleTask | task | Task that created the session. |
| struct DataLoggingSendDataMessage |
Data message, sent with DataLoggingEndpointCmdData.
| Data Fields | ||
|---|---|---|
| uint8_t | bytes[] | Whole items. |
| uint8_t | command | DataLoggingEndpointCmdData. |
| uint32_t | crc32 | Legacy CRC-32 of bytes. |
| uint32_t | items_left_hereafter | Items left after this message; currently always 0xffff. |
| uint8_t | session_id | Session ID. |
| #define DLS_FILE_NAME_PREFIX "dls_storage_" |
Prefix of session file names, followed by the decimal session ID.
| #define DLS_INVALID_FILE (-1) |
Value of DataLoggingSessionStorage::fd when the session has no open file.
| #define DLS_MAX_DATA_BYTES (DLS_TOTAL_STORAGE_BYTES - (DLS_MAX_NUM_SESSIONS * DLS_FILE_INIT_SIZE_BYTES)) |
Space available to session files beyond their initial size.
| #define DLS_SESSION_MAX_BUFFERED_ITEM_SIZE 300U |
Largest item size, and largest dls_log() write, for buffered sessions.
| #define DLS_SESSION_MIN_BUFFER_SIZE (DLS_SESSION_MAX_BUFFERED_ITEM_SIZE + 1) |
Size of a buffered session's buffer.
One byte more than DLS_SESSION_MAX_BUFFERED_ITEM_SIZE, as needed by the circular buffer.
Data logging endpoint commands.
| Enumerator | |
|---|---|
| DataLoggingEndpointCmdOpen | Watch opens a session. |
| DataLoggingEndpointCmdData | Watch sends session data, see DataLoggingSendDataMessage. |
| DataLoggingEndpointCmdClose | Watch closes a session. |
| DataLoggingEndpointCmdReport | Phone reports the sessions it knows about. |
| DataLoggingEndpointCmdAck | Phone acknowledges an open or data message. |
| DataLoggingEndpointCmdNack | Phone rejects an open or data message. |
| DataLoggingEndpointCmdTimeout | Watch reports that an ack was not received in time. |
| DataLoggingEndpointCmdEmptySession | Phone asks to send a session's data now. |
| DataLoggingEndpointCmdGetSendEnableReq | Phone asks whether sending is enabled. |
| DataLoggingEndpointCmdGetSendEnableRsp | Watch answers DataLoggingEndpointCmdGetSendEnableReq. |
| DataLoggingEndpointCmdSetSendEnable | Phone enables or disables sending. |
Endpoint state of a session.
+----------+ Rx Ack +----------+ Tx Data +----------+
| Opening |----------->| Idle |+------------>| Sending |
+----------+ +----------+ +----------+
^ |
| Rx Ack |
+-------------------------+
| enum DataLoggingStatus |
| void dls_private_handle_disconnect | ( | void * | data | ) |
Reset the endpoint state of all sessions after a disconnection.
Must be called from KernelBG.
| data | Unused. |
| bool dls_private_send_session | ( | DataLoggingSession * | logging_session, |
| bool | empty | ||
| ) |
Send the next chunk of a session's stored data to the phone.
Must be called from KernelBG. Removes inactive sessions with no data left. Active sessions are only sent when they hold enough data, unless empty is set.
| logging_session | Session. |
| empty | Send even if little data is stored. |
| int dls_test_consume | ( | DataLoggingSession * | logging_session, |
| int | num_bytes | ||
| ) |
Consume session data, for unit tests only.
| logging_session | Session. |
| num_bytes | Number of bytes to consume. |
num_bytes. | int dls_test_get_num_bytes | ( | DataLoggingSession * | logging_session | ) |
Get the number of unread bytes, for unit tests only.
| logging_session | Session. |
| uint8_t dls_test_get_session_id | ( | DataLoggingSession * | logging_session | ) |
Get the session ID, for unit tests only.
| logging_session | Session. |
| int dls_test_get_tag | ( | DataLoggingSession * | logging_session | ) |
Get the session tag, for unit tests only.
| logging_session | Session. |
| int dls_test_read | ( | DataLoggingSession * | logging_session, |
| uint8_t * | buffer, | ||
| int | num_bytes | ||
| ) |
Read session data, for unit tests only.
| logging_session | Session. | |
| [out] | buffer | Destination. |
| num_bytes | Maximum number of bytes to read. |
|
static |
Mask of the command in the first byte of an endpoint message.
The top bit is set in commands from the phone and clear in commands from the watch.
|
static |
Largest data message payload, and largest item size for unbuffered sessions.
|
static |
Initial size of a session file.
|
static |
Size of a buffer holding a session file name.
|
static |
Maximum free space added when a session file grows.
|
static |
Maximum number of sessions.
|
static |
Minimum free space added when a session file grows.
A file grows by half its unread data, clamped to this and DLS_MAX_FILE_FREE_BYTES.
|
static |
Free space left at the end of a session file below which the file is grown.
|
static |
Maximum file system space used by all session files.