59 #define PRINTF(...) printf(__VA_ARGS__)
66 PROCESS(shell_bin2hex_process,
"bin2hex");
69 "bin2hex: binary to hexadecimal",
70 &shell_bin2hex_process);
71 PROCESS(shell_hex2bin_process,
"hex2bin");
74 "hex2bin: hexadecimal to binary",
75 &shell_hex2bin_process);
76 PROCESS(shell_crc_process,
"crc");
79 "crc: append per-block crc",
82 PROCESS(shell_crcvalidate_process,
"crc-v");
85 "crc-v: verify crc and output if valid",
86 &shell_crcvalidate_process);
90 fromhexchar(
unsigned char c)
93 if(c >=
'0' && c <=
'9') {
95 }
else if(c >=
'a' && c <=
'f') {
97 }
else if(c >=
'A' && c <=
'F') {
100 PRINTF(
"Bad hex input: %c", c);
107 fromhex(
unsigned char c1,
unsigned char c2)
109 return (fromhexchar(c1)<<4) + fromhexchar(c2);
125 if(input->len1 + input->len2 == 0) {
129 buf = alloca((input->len1 + input->len2)*2);
132 for(i = 0; i < input->len1; i++) {
133 bufptr += sprintf(bufptr,
"%02x", 0xff&((
char*)input->data1)[i]);
135 for(i = 0; i < input->len2; i++) {
136 bufptr += sprintf(bufptr,
"%02x", 0xff&((
char*)input->data2)[i]);
141 buf, ((input->len1 + input->len2)*2),
"", 0);
161 if(input->len1 + input->len2 == 0) {
165 if(input->len1 % 2 != 0) {
166 PRINTF(
"Bad input length 1: %d\n", input->len1);
169 if(input->len2 % 2 != 0) {
170 PRINTF(
"Bad input length 2: %d\n", input->len2);
174 buf = alloca((input->len1 + input->len2)/2+1);
177 for(i = 0; i < input->len1; i += 2) {
178 buf[cnt++] = fromhex(
179 ((
char*)input->data1)[i],
180 ((
char*)input->data1)[i+1]);
182 for(i = 0; i < input->len2; i += 2) {
183 buf[cnt++] = fromhex(
184 ((
char*)input->data2)[i],
185 ((
char*)input->data2)[i+1]);
209 if(input->len1 + input->len2 == 0) {
215 for(i = 0; i < input->len1; i++) {
216 crc =
crc16_add(((
char*)(input->data1))[i], crc);
218 for(i = 0; i < input->len2; i++) {
219 crc =
crc16_add(((
char*)(input->data2))[i], crc);
223 buf = alloca(input->len2+2);
225 memcpy(buf, input->data2, input->len2);
226 buf[input->len2] = crc&0xff;
227 buf[input->len2+1] = (crc>>8)&0xff;
229 shell_output(&crc_command, input->data1, input->len1, buf, input->len2+2);
241 uint16_t crc, crc_footer;
252 if(input->len1 + input->len2 == 0) {
256 if(input->len1 + input->len2 < 2) {
258 PRINTF(
"Too short input: %d+%d\n", input->len1, input->len2);
262 if(input->len2 == 1) {
263 crc1 = ((
char*)input->data1)[input->len1-1];
264 crc2 = ((
char*)input->data2)[input->len2-1];
267 }
else if(input->len2 >= 2) {
268 crc1 = ((
char*)input->data2)[input->len2-2];
269 crc2 = ((
char*)input->data2)[input->len2-1];
272 crc1 = ((
char*)input->data1)[input->len1-2];
273 crc2 = ((
char*)input->data1)[input->len1-1];
279 for(i = 0; i < input->len1; i++) {
280 crc =
crc16_add(((
char*)(input->data1))[i], crc);
282 for(i = 0; i < input->len2; i++) {
283 crc =
crc16_add(((
char*)(input->data2))[i], crc);
287 crc_footer = ((0xff&crc2)<<8) | (0xff&crc1);
290 if(crc_footer == crc) {
292 &crcvalidate_command,
293 input->data1, input->len1, input->data2, input->len2);
Main header file for the Contiki shell
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
static void input(void)
Process a received 6lowpan packet.
#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 SHELL_COMMAND(name, command, description, process)
Define a shell command.
int shell_event_input
The event number for shell input data.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
Structure for shell input data.
unsigned short crc16_add(unsigned char b, unsigned short acc)
Update an accumulated CRC16 checksum with one byte.
Header file for the CRC16 calculcation
#define PROCESS_BEGIN()
Define the beginning of a process.