51 #define FILENAME_LEN 20
53 static struct rudolph0_conn rudolph0_conn;
54 static char filename[FILENAME_LEN];
55 static int receiving_file;
56 static struct pt recvnetfilept;
58 PROCESS(shell_netfile_process,
"netfile");
61 "netfile: send file to entire network",
62 &shell_netfile_process);
63 PROCESS(shell_recvnetfile_process,
"recvnetfile");
66 "recvnetfile: receive file from network and print to output",
67 &shell_recvnetfile_process);
70 write_chunk_pt(
struct rudolph0_conn *c,
int offset,
int flag,
71 uint8_t *data,
int datalen)
83 shell_output(&recvnetfile_command, data, datalen,
"", 0);
87 }
while(flag != RUDOLPH0_FLAG_LASTCHUNK);
89 shell_output(&recvnetfile_command, data, datalen,
"", 0);
99 write_chunk(
struct rudolph0_conn *c,
int offset,
int flag,
100 uint8_t *data,
int datalen)
102 write_chunk_pt(c, offset, flag, data, datalen);
106 read_chunk(
struct rudolph0_conn *c,
int offset, uint8_t *to,
int maxsize)
114 ret = cfs_read(fd, to, maxsize);
133 strncpy(filename, data, FILENAME_LEN);
136 shell_output_str(&netfile_command,
"netfile: could not open file ", filename);
158 if(input->len1 + input->len2 == 0) {
162 }
else if(receiving_file == 0) {
170 shell_netfile_init(
void)
176 rudolph0_open(&rudolph0_conn, SHELL_RIME_CHANNEL_NETFILE,
177 &rudolph0_callbacks);
#define CC_CONST_FUNCTION
Configure if the C compiler have problems with const function pointers.
int cfs_open(const char *name, int flags)
Open a file.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define LEDS_RED
LED1 (Red) -> PC0.
#define PROCESS_EXIT()
Exit the currently running process.
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PT_YIELD(pt)
Yield from the current protothread.
#define NULL
The null pointer.
#define PT_INIT(pt)
Initialize a protothread.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
A brief description of what this file is.
Header file for the single-hop reliable bulk data transfer module
Header file for the Rime stack
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
#define LEDS_YELLOW
LED2 (Yellow) -> PC1.
#define PT_WAIT_UNTIL(pt, condition)
Block and wait until condition is true.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
Structure for shell input data.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PT_BEGIN(pt)
Declare the start of a protothread inside the C function implementing the protothread.
#define PROCESS(name, strname)
Declare a process.
int shell_event_input
The event number for shell input data.
#define PT_END(pt)
Declare the end of a protothread.
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
void cfs_close(int fd)
Close an open file.
#define CLOCK_SECOND
A second, measured in system clock time.