54 #define RUNICAST_CHANNEL SHELL_RIME_CHANNEL_DOWNLOAD
55 #define RUCB_CHANNEL (SHELL_RIME_CHANNEL_DOWNLOAD+1)
56 #define MAX_RETRANSMISSIONS 8
61 #define PRINTF(...) printf(__VA_ARGS__)
67 PROCESS(shell_download_process,
"download");
68 PROCESS(shell_download_server_process,
"download server");
71 "download <node addr> <filename>: download file from remote node",
72 &shell_download_process);
74 static struct runicast_conn runicast;
75 static struct rucb_conn rucb;
76 static uint8_t downloading;
77 static uint8_t req_seq_counter;
78 static uint8_t req_last_seq;
82 write_chunk(
struct rucb_conn *c,
int offset,
int flag,
char *data,
int datalen)
86 data, datalen,
NULL, 0);
87 PRINTF(
"write_chunk %d at %d bytes\n", datalen, offset);
90 if(flag == RUCB_FLAG_NEWFILE) {
91 PRINTF(
"RUCB_FLAG_NEWFILE\n");
92 }
else if(flag == RUCB_FLAG_NONE) {
93 PRINTF(
"RUCB_FLAG_NONE\n");
95 if(flag == RUCB_FLAG_LASTCHUNK) {
96 PRINTF(
"RUCB_FLAG_LASTCHUNK\n");
103 read_chunk(
struct rucb_conn *c,
int offset,
char *to,
int maxsize)
108 leds_off(LEDS_GREEN);
113 ret = cfs_read(fd, to, maxsize);
114 PRINTF(
"read_chunk %d bytes at %d\n", ret, offset);
117 PRINTF(
"read_chunk DONE\n");
126 timedout(
struct rucb_conn *c)
130 static const struct rucb_callbacks rucb_call = { write_chunk, read_chunk, timedout };
135 static linkaddr_t
addr;
143 if(nextptr == data || *nextptr !=
'.') {
145 "download <node addr> <filename>: need node address",
"");
152 while(nextptr[0] ==
' ') {
155 len = strlen(nextptr);
161 snprintf(buf,
sizeof(buf),
"%d", len);
170 rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
175 PRINTF(
"requesting '%s'\n", nextptr);
176 runicast_send(&runicast, &addr, MAX_RETRANSMISSIONS);
190 request_recv(
struct runicast_conn *c,
const linkaddr_t *from, uint8_t seqno)
192 const char *filename;
197 printf(
"download: bad filename request (null)\n");
202 if(seq == req_last_seq) {
203 PRINTF(
"download: ignoring duplicate request\n");
209 PRINTF(
"file requested: '%s'\n", filename);
218 printf(
"download: bad filename request (no read access): %s\n", filename);
220 PRINTF(
"download: sending file: %s\n", filename);
224 rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
225 rucb_send(&rucb, from);
229 request_sent(
struct runicast_conn *c,
const linkaddr_t *to,
230 uint8_t retransmissions)
236 request_timedout(
struct runicast_conn *c,
const linkaddr_t *to,
237 uint8_t retransmissions)
244 static const struct runicast_callbacks runicast_callbacks =
245 {request_recv, request_sent, request_timedout};
253 runicast_open(&runicast, RUNICAST_CHANNEL, &runicast_callbacks);
260 shell_download_init(
void)
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int cfs_open(const char *name, int flags)
Open a file.
void process_poll(struct process *p)
Request a process to be polled.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
void cfs_close(int fd)
Close an open file.
void packetbuf_clear(void)
Clear and reset the packetbuf.
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
Main header file for the Contiki shell
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_EXIT()
Exit the currently running process.
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_EXITHANDLER(handler)
Specify an action when a process exits.
Header file for the Rime stack
#define NULL
The null pointer.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void process_start(struct process *p, process_data_t data)
Start a process.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
#define PROCESS_WAIT_UNTIL(c)
Wait for a condition to occur.
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.