Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
127 | ligi | 1 | #include "fc.h" |
2 | |||
3 | |||
4 | unsigned char TxBuffer[150]; |
||
5 | unsigned char _TxBuffer[150]; |
||
6 | |||
7 | |||
8 | int mk_socket; |
||
9 | |||
10 | |||
11 | void AddCRC(unsigned int wieviele) |
||
12 | { |
||
13 | unsigned int tmpCRC = 0,i; |
||
14 | for(i = 0; i < wieviele;i++) |
||
15 | { |
||
16 | tmpCRC += TxBuffer[i]; |
||
17 | } |
||
18 | tmpCRC %= 4096; |
||
19 | TxBuffer[i++] = '=' + tmpCRC / 64; |
||
20 | TxBuffer[i++] = '=' + tmpCRC % 64; |
||
21 | TxBuffer[i++] = '\r'; |
||
22 | } |
||
23 | |||
24 | |||
25 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
||
26 | { |
||
27 | int status =0; |
||
28 | unsigned int pt = 0; |
||
29 | unsigned char a,b,c; |
||
30 | unsigned char ptr = 0; |
||
31 | |||
32 | TxBuffer[pt++] = '#'; // Startzeichen |
||
33 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
||
34 | TxBuffer[pt++] = cmd; // Commando |
||
35 | |||
36 | while(len) |
||
37 | { |
||
38 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
||
39 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
||
40 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
||
41 | TxBuffer[pt++] = '=' + (a >> 2); |
||
42 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
43 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
44 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
||
45 | } |
||
46 | |||
47 | |||
48 | |||
49 | AddCRC(pt); |
||
50 | printf("Sending to MK %d \n" , pt); |
||
51 | |||
52 | status = send(mk_socket,"\r" , 1, 0); |
||
53 | |||
54 | |||
55 | // for (c=0;c<pt+2;c++) |
||
56 | // { |
||
57 | status = write(mk_socket,&TxBuffer , pt+3); |
||
58 | // printf("Send to MK %d \n" , TxBuffer[c] ); |
||
59 | // } |
||
60 | /*while(TxBuffer[i] !='\r' && i<150) |
||
61 | { |
||
62 | // TxBuffer[i]='#'; |
||
63 | status = send(s,&TxBuffer[i] , 1, 0); |
||
64 | printf(" +%d%c ",i,TxBuffer[i]); |
||
65 | i++; |
||
66 | } |
||
67 | |||
68 | status = send(s,"\r" , 1, 0); |
||
69 | */ |
||
70 | // status = send(s,"\r" , 1, 0); |
||
71 | printf("\n"); |
||
72 | } |
||
73 | |||
74 | /* |
||
75 | |||
76 | int connect_mk_bluetooth(char dest[18]) |
||
77 | { |
||
78 | |||
79 | |||
80 | |||
81 | struct sockaddr_rc addr ; |
||
82 | |||
83 | // allocate a socket |
||
84 | mk_socket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
||
85 | |||
86 | // set the connection parameters (who to connect to) |
||
87 | addr.rc_family = AF_BLUETOOTH; |
||
88 | addr.rc_channel = 1; |
||
89 | str2ba( dest, &addr.rc_bdaddr ); |
||
90 | |||
91 | // connect to server |
||
92 | status = connect(mk_socket, (struct sockaddr *)&addr, sizeof(addr)); |
||
93 | |||
94 | return status; |
||
95 | |||
96 | } |
||
97 | |||
98 | */ |
||
99 | |||
100 | |||
101 | int connect_mk_localhost_socket(int port) |
||
102 | { |
||
103 | |||
104 | int status; |
||
105 | struct sockaddr_in sa; |
||
106 | |||
107 | sa.sin_family = AF_INET; |
||
108 | sa.sin_addr.s_addr = htonl(0x0); |
||
109 | sa.sin_port = htons(port); |
||
110 | |||
111 | // allocate a socket |
||
112 | // s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
||
113 | mk_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
||
114 | //); |
||
115 | |||
116 | // set the connection parameters (who to connect to) |
||
117 | |||
118 | // connect to server |
||
119 | // status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
||
120 | status = connect(mk_socket,(struct sockaddr*) &sa, sizeof(struct sockaddr_in)); |
||
121 | |||
122 | return status; |
||
123 | |||
124 | } |
||
125 |