Skip to content

Commit 5efddf1

Browse files
committed
Merge pull request #183 from mfine/mfine-file-io
New file_io messages
2 parents 1252dcd + 378aa82 commit 5efddf1

File tree

5 files changed

+462
-92
lines changed

5 files changed

+462
-92
lines changed

c/include/libsbp/file_io.h

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,75 @@
3535
#include "common.h"
3636

3737

38-
/** Read file from the file system (host <=> device)
38+
/** Read file from the file system (host => device)
3939
*
4040
* The file read message reads a certain length (up to 255 bytes)
4141
* from a given offset into a file, and returns the data in a
42-
* MSG_FILEIO_READ message where the message length field indicates
43-
* how many bytes were succesfully read. If the message is invalid,
44-
* a followup MSG_PRINT message will print "Invalid fileio read
45-
* message".
42+
* MSG_FILEIO_READ_RESPONSE message where the message length field
43+
* indicates how many bytes were succesfully read. If the message is
44+
* invalid, a followup MSG_PRINT message will print "Invalid fileio
45+
* read message".
4646
*/
47-
#define SBP_MSG_FILEIO_READ 0x00A8
47+
#define SBP_MSG_FILEIO_READ_REQUEST 0x00A8
4848
typedef struct __attribute__((packed)) {
4949
u32 offset; /**< File offset [bytes] */
5050
u8 chunk_size; /**< Chunk size to read [bytes] */
5151
char filename[20]; /**< Name of the file to read from (NULL padded) */
52-
} msg_fileio_read_t;
52+
} msg_fileio_read_request_t;
53+
54+
55+
/** File read from the file system (host <= device)
56+
*
57+
* The file read message reads a certain length (up to 255 bytes)
58+
* from a given offset into a file, and returns the data in a
59+
* message where the message length field indicates how many bytes
60+
* were succesfully read.
61+
*/
62+
#define SBP_MSG_FILEIO_READ_RESPONSE 0x00A3
63+
typedef struct __attribute__((packed)) {
64+
u32 offset; /**< File offset [bytes] */
65+
u8 chunk_size; /**< Chunk size read [bytes] */
66+
char filename[20]; /**< Name of the file read from (NULL padded) */
67+
u8 contents[0]; /**< Contents of read file */
68+
} msg_fileio_read_response_t;
5369

5470

55-
/** List files in a directory (host <=> device)
71+
/** List files in a directory (host => device)
5672
*
5773
* The read directory message lists the files in a directory on the
5874
* device's onboard flash file system. The offset parameter can be
5975
* used to skip the first n elements of the file list. Returns a
60-
* MSG_FILEIO_READ_DIR message containing the directory listings as
61-
* a NULL delimited list. The listing is chunked over multiple SBP
62-
* packets and the end of the list is identified by an entry
63-
* containing just the character 0xFF. If message is invalid, a
76+
* MSG_FILEIO_READ_DIR_RESPONSE message containing the directory
77+
* listings as a NULL delimited list. The listing is chunked over
78+
* multiple SBP packets and the end of the list is identified by an
79+
* entry containing just the character 0xFF. If message is invalid, a
6480
* followup MSG_PRINT message will print "Invalid fileio read
6581
* message".
6682
*/
67-
#define SBP_MSG_FILEIO_READ_DIR 0x00A9
83+
#define SBP_MSG_FILEIO_READ_DIR_REQUEST 0x00A9
6884
typedef struct __attribute__((packed)) {
6985
u32 offset; /**< The offset to skip the first n elements of the file list
7086
*/
7187
char dirname[20]; /**< Name of the directory to list (NULL padded) */
72-
} msg_fileio_read_dir_t;
88+
} msg_fileio_read_dir_request_t;
89+
90+
91+
/** Files listed in a directory (host <= device)
92+
*
93+
* The read directory message lists the files in a directory on the
94+
* device's onboard flash file system. The offset parameter can be
95+
* used to skip the first n elements of the file list. Message contains
96+
* the directory listings as a NULL delimited list. The listing is
97+
* chunked over multiple SBP packets and the end of the list is
98+
* identified by an entry containing just the character 0xFF.
99+
*/
100+
#define SBP_MSG_FILEIO_READ_DIR_RESPONSE 0x00AA
101+
typedef struct __attribute__((packed)) {
102+
u32 offset; /**< The offset to skip the first n elements of the file list
103+
*/
104+
char dirname[20]; /**< Name of the directory to list (NULL padded) */
105+
u8 contents[0]; /**< Contents of read directory */
106+
} msg_fileio_read_dir_response_t;
73107

74108

75109
/** Delete a file from the file system (host => device)
@@ -78,26 +112,41 @@ typedef struct __attribute__((packed)) {
78112
* message is invalid, a followup MSG_PRINT message will print
79113
* "Invalid fileio remove message".
80114
*/
81-
#define SBP_MSG_FILEIO_REMOVE 0x00AC
115+
#define SBP_MSG_FILEIO_REMOVE 0x00AC
82116
typedef struct __attribute__((packed)) {
83117
char filename[20]; /**< Name of the file to delete (NULL padded) */
84118
} msg_fileio_remove_t;
85119

86120

87-
/** Write to file (host <=> device)
121+
/** Write to file (host => device)
88122
*
89123
* The file write message writes a certain length (up to 255 bytes)
90124
* of data to a file at a given offset. Returns a copy of the
91-
* original MSG_FILEIO_WRITE message to check integrity of the
92-
* write. If message is invalid, a followup MSG_PRINT message will
93-
* print "Invalid fileio write message".
125+
* original MSG_FILEIO_WRITE_RESPONSE message to check integrity of
126+
* the write. If message is invalid, a followup MSG_PRINT message
127+
* will print "Invalid fileio write message".
128+
*/
129+
#define SBP_MSG_FILEIO_WRITE_REQUEST 0x00AD
130+
typedef struct __attribute__((packed)) {
131+
char filename[20]; /**< Name of the file to write to (NULL padded) */
132+
u32 offset; /**< Offset into the file at which to start writing in bytes [bytes] */
133+
u8 data[0]; /**< Variable-length array of data to write */
134+
} msg_fileio_write_request_t;
135+
136+
137+
/** File written to (host <= device)
138+
*
139+
* The file write message writes a certain length (up to 255 bytes)
140+
* of data to a file at a given offset. The message is a copy of the
141+
* original MSG_FILEIO_WRITE_REQUEST message to check integrity of the
142+
* write.
94143
*/
95-
#define SBP_MSG_FILEIO_WRITE 0x00AD
144+
#define SBP_MSG_FILEIO_WRITE_RESPONSE 0x00AB
96145
typedef struct __attribute__((packed)) {
97146
char filename[20]; /**< Name of the file to write to (NULL padded) */
98147
u32 offset; /**< Offset into the file at which to start writing in bytes [bytes] */
99148
u8 data[0]; /**< Variable-length array of data to write */
100-
} msg_fileio_write_t;
149+
} msg_fileio_write_response_t;
101150

102151

103152
/** \} */

c/include/libsbp/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
/** Protocol major version. */
2424
#define SBP_MAJOR_VERSION 0
2525
/** Protocol minor version. */
26-
#define SBP_MINOR_VERSION 45
26+
#define SBP_MINOR_VERSION 47
2727

2828
/** \} */
2929

3030

31-
#endif /* LIBSBP_VERSION_H */
31+
#endif /* LIBSBP_VERSION_H */

0 commit comments

Comments
 (0)