Revision 483
removed very old code
trunk/code/projects/colonet/utilities/sendpacket/sendpacket.c | ||
---|---|---|
1 |
/* Eugene Marinelli |
|
2 |
* 10/5/06 |
|
3 |
* sendpacket - sends a packet through the xbee dongle |
|
4 |
*/ |
|
5 |
|
|
6 |
#include <stdio.h> |
|
7 |
#include <string.h> |
|
8 |
|
|
9 |
#include "wireless.h" |
|
10 |
|
|
11 |
#define SERIAL_PORT "/dev/ttyS0" |
|
12 |
#define SERVER_ID 213 |
|
13 |
|
|
14 |
int message_length = 15; |
|
15 |
|
|
16 |
int main(int argc, char** argv){ |
|
17 |
FILE* serial = fopen(SERIAL_PORT, "w"); |
|
18 |
WL_Packet pkt; |
|
19 |
int i; |
|
20 |
|
|
21 |
if(argc < 2){ |
|
22 |
fprintf(stderr, "Error: no packet content specified.\n"); |
|
23 |
return -1; |
|
24 |
} |
|
25 |
|
|
26 |
fprintf(stderr, "Sending message: %s\n", argv[1]); |
|
27 |
|
|
28 |
wl_create_packet(argv[1], SERVER_ID, GLOBAL_DEST, &pkt); |
|
29 |
|
|
30 |
printf("%x %x %x %x\n", pkt.prefix[0], pkt.prefix[1], pkt.src, pkt.dest); |
|
31 |
|
|
32 |
fprintf(serial, "%c%c%c%c", pkt.prefix[0], pkt.prefix[1], pkt.src, pkt.dest); |
|
33 |
|
|
34 |
for(i = 0; i < message_length; i++){ |
|
35 |
fprintf(serial, "%c", pkt.msg[i]); |
|
36 |
} |
|
37 |
|
|
38 |
fprintf(serial, "%c", pkt.checksum); |
|
39 |
|
|
40 |
fclose(serial); |
|
41 |
|
|
42 |
return 0; |
|
43 |
} |
|
44 |
|
|
45 |
char wl_get_checksum(WL_Packet* packet){ |
|
46 |
char checksum = 0; |
|
47 |
int i; |
|
48 |
|
|
49 |
checksum += packet->src; |
|
50 |
checksum += packet->dest; |
|
51 |
for(i = 0; i < message_length; i++) { |
|
52 |
checksum += packet->msg[i]; |
|
53 |
} |
|
54 |
|
|
55 |
return checksum; |
|
56 |
} |
|
57 |
|
|
58 |
int wl_create_packet(char* msg, char src, char dest, WL_Packet* packet){ |
|
59 |
packet->prefix[0] = 'R'; |
|
60 |
packet->prefix[1] = 'C'; |
|
61 |
|
|
62 |
packet->src = src; |
|
63 |
packet->dest = dest; |
|
64 |
|
|
65 |
memset(packet->msg, 0, message_length); |
|
66 |
strcpy(packet->msg, msg); |
|
67 |
|
|
68 |
packet->checksum = wl_get_checksum(packet); |
|
69 |
|
|
70 |
printf("checksum: %d\n", packet->checksum); |
|
71 |
|
|
72 |
return 0; |
|
73 |
} |
Also available in: Unified diff