Rev 281 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 281 | Rev 379 | ||
|---|---|---|---|
| Line 32... | Line 32... | ||
| 32 | static uint8_t myip[4] = {193,11,254,22}; |
32 | static uint8_t myip[4] = {193,11,254,22}; |
| 33 | static uint16_t rmDumperPrt =1200; // remote port for dumping data |
33 | static uint16_t rmDumperPrt =1200; // remote port for dumping data |
| 34 | static uint16_t rmCan2SerPrt =1100; // remote port for Can2Serial-data |
34 | static uint16_t rmCan2SerPrt =1100; // remote port for Can2Serial-data |
| 35 | static uint16_t locDumperPrt =1200; // listen port |
35 | static uint16_t locDumperPrt =1200; // listen port |
| 36 | static uint16_t locCan2SerPrt =1100; // listen port for Can2Serial-data |
36 | static uint16_t locCan2SerPrt =1100; // listen port for Can2Serial-data |
| 37 | static uint8_t |
37 | static uint8_t gotdumpserver = 0; |
| - | 38 | static uint8_t gotcan2serserver = 0; |
|
| 38 | 39 | ||
| 39 | // how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX |
40 | // how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX |
| 40 | 41 | ||
| 41 | static uint8_t remotemac[6]; |
42 | static uint8_t remotemac[6]; |
| 42 | static uint8_t remoteip[4]; |
43 | static uint8_t remoteip[4]; |
| - | 44 | ||
| - | 45 | static uint8_t prgremotemac[6]; |
|
| - | 46 | static uint8_t prgremoteip[4]; |
|
| 43 | 47 | ||
| 44 | #define BUFFER_SIZE 250 |
48 | #define BUFFER_SIZE 250 |
| 45 | static uint8_t buf[BUFFER_SIZE+1]; |
49 | static uint8_t buf[BUFFER_SIZE+1]; |
| 46 | 50 | ||
| 47 | #define SEND_BUFFER_SIZE 20 |
51 | #define SEND_BUFFER_SIZE 20 |
| Line 56... | Line 60... | ||
| 56 | * Implements a small buffer, sends packet over udp if buffer is full or |
60 | * Implements a small buffer, sends packet over udp if buffer is full or |
| 57 | * \n-char is sent. |
61 | * \n-char is sent. |
| 58 | * Needs a timeout to force send. |
62 | * Needs a timeout to force send. |
| 59 | *--------------------------------------------------------------------------*/ |
63 | *--------------------------------------------------------------------------*/ |
| 60 | int udp_putchar(char c, FILE* stream) { |
64 | int udp_putchar(char c, FILE* stream) { |
| 61 | if ( |
65 | if (gotdumpserver != 0) { |
| 62 | sendbuf[buffpoint] = c; |
66 | sendbuf[buffpoint] = c; |
| 63 | buffpoint++; |
67 | buffpoint++; |
| 64 | 68 | ||
| 65 | if (c == '\n' || buffpoint > SEND_BUFFER_SIZE) { |
69 | if (c == '\n' || buffpoint > SEND_BUFFER_SIZE) { |
| 66 | send_udp(buf, sendbuf, buffpoint, rmDumperPrt, remotemac, remoteip); |
70 | send_udp(buf, sendbuf, buffpoint, rmDumperPrt, remotemac, remoteip); |
| Line 161... | Line 165... | ||
| 161 | } |
165 | } |
| 162 | 166 | ||
| 163 | /* check if any messages have been received */ |
167 | /* check if any messages have been received */ |
| 164 | while (Can_Receive(&rxMsg) == CAN_OK) { |
168 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 165 | uint8_t i; |
169 | uint8_t i; |
| - | 170 | ||
| - | 171 | if (gotdumpserver != 0) { |
|
| 166 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
172 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
| 167 | printf("data={ "); |
173 | printf("data={ "); |
| 168 | for (i=0; i<rxMsg.DataLength; i++) { |
174 | for (i=0; i<rxMsg.DataLength; i++) { |
| 169 | printf("%x ", rxMsg.Data.bytes[i]); |
175 | printf("%x ", rxMsg.Data.bytes[i]); |
| 170 | } |
176 | } |
| 171 | printf("}\n"); |
177 | printf("}\n"); |
| - | 178 | } |
|
| 172 | 179 | ||
| - | 180 | if (gotcan2serserver != 0) { |
|
| 173 | //skicka |
181 | //skicka ocks� som udppaket till rmCan2SerPrt |
| 174 | char sendbuf2[17]; |
182 | char sendbuf2[17]; |
| - | 183 | ||
| 175 | sendbuf2[0] = C2S_START_BYTE; |
184 | sendbuf2[0] = C2S_START_BYTE; |
| 176 | sendbuf2[1] = (uint8_t)rxMsg.Id; |
185 | sendbuf2[1] = (uint8_t)rxMsg.Id; |
| 177 | sendbuf2[2] = (uint8_t)(rxMsg.Id>>8); |
186 | sendbuf2[2] = (uint8_t)(rxMsg.Id>>8); |
| 178 | sendbuf2[3] = (uint8_t)(rxMsg.Id>>16); |
187 | sendbuf2[3] = (uint8_t)(rxMsg.Id>>16); |
| 179 | sendbuf2[4] = (uint8_t)(rxMsg.Id>>24); |
188 | sendbuf2[4] = (uint8_t)(rxMsg.Id>>24); |
| 180 | sendbuf2[5] = rxMsg.ExtendedFlag; |
189 | sendbuf2[5] = rxMsg.ExtendedFlag; |
| 181 | sendbuf2[6] = rxMsg.RemoteFlag; |
190 | sendbuf2[6] = rxMsg.RemoteFlag; |
| 182 | sendbuf2[7] = rxMsg.DataLength; |
191 | sendbuf2[7] = rxMsg.DataLength; |
| 183 | for |
192 | for (i=0; i<8; i++) { |
| 184 | sendbuf2[8+i] = rxMsg.Data.bytes[i]; |
193 | sendbuf2[8+i] = rxMsg.Data.bytes[i]; |
| 185 | } |
194 | } |
| 186 | sendbuf2[16] = C2S_END_BYTE; |
195 | sendbuf2[16] = C2S_END_BYTE; |
| - | 196 | ||
| 187 | send_udp(buf, sendbuf2, |
197 | send_udp(buf, sendbuf2, 18, rmCan2SerPrt, prgremotemac, prgremoteip); |
| - | 198 | } |
|
| 188 | } |
199 | } |
| 189 | 200 | ||
| 190 | //test-debug-kod |
201 | //test-debug-kod |
| 191 | if ((enc28j60Read(EIR) & EIR_TXERIF)) { |
202 | if ((enc28j60Read(EIR) & EIR_TXERIF)) { |
| 192 | //printf("EIR_TXERIF set!\n"); |
203 | //printf("EIR_TXERIF set!\n"); |
| 193 | if ((enc28j60Read(ECON1) & ECON1_TXRTS)) { |
204 | if ((enc28j60Read(ECON1) & ECON1_TXRTS)) { |
| 194 | //printf("ECON1_TXRTS set!\n"); |
205 | //printf("ECON1_TXRTS set!\n"); |
| Line 225... | Line 236... | ||
| 225 | //Can_Send(&txMsg); |
236 | //Can_Send(&txMsg); |
| 226 | 237 | ||
| 227 | } |
238 | } |
| 228 | if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){ |
239 | if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){ |
| 229 | payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN; |
240 | payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN; |
| - | 241 | uint8_t i = 0; |
|
| - | 242 | ||
| 230 | // |
243 | //om port 1100 (programmeringsporten) |
| 231 | if ((buf[UDP_DST_PORT_H_P]==((locCan2SerPrt>>8) & 0xff)) && (buf[UDP_DST_PORT_L_P] == (locCan2SerPrt & 0xff))) { |
244 | if ((buf[UDP_DST_PORT_H_P]==((locCan2SerPrt>>8) & 0xff)) && (buf[UDP_DST_PORT_L_P] == (locCan2SerPrt & 0xff))) { |
| - | 245 | while(i<6){ |
|
| 232 |
|
246 | prgremotemac[i]=buf[ETH_SRC_MAC +i]; |
| - | 247 | i++; |
|
| - | 248 | } |
|
| - | 249 | i=0; |
|
| - | 250 | while(i<4){ |
|
| - | 251 | prgremoteip[i]=buf[IP_SRC_P +i]; |
|
| - | 252 | i++; |
|
| - | 253 | } |
|
| - | 254 | gotcan2serserver = 1; |
|
| - | 255 | ||
| 233 |
|
256 | if ((buf[UDP_DATA_P]==C2S_START_BYTE) && (buf[UDP_DATA_P+16]==C2S_END_BYTE) && (payloadlen==17)) { |
| 234 |
|
257 | Can_Message_t cm; |
| 235 |
|
258 | //cm.Id = 0; |
| 236 |
|
259 | cm.DataLength = buf[UDP_DATA_P+7]; |
| 237 |
|
260 | cm.RemoteFlag = buf[UDP_DATA_P+6]; |
| 238 |
|
261 | cm.ExtendedFlag = buf[UDP_DATA_P+5]; |
| 239 |
|
262 | cm.Id = (uint32_t)buf[UDP_DATA_P+1] + ((uint32_t)buf[UDP_DATA_P+2] << 8) + ((uint32_t)buf[UDP_DATA_P+3] << 16) + ((uint32_t)buf[UDP_DATA_P+4] << 24); |
| 240 |
|
263 | uint8_t i; |
| 241 |
|
264 | for (i = 0; i < cm.DataLength; i++) { |
| 242 |
|
265 | cm.Data.bytes[i] = buf[UDP_DATA_P+8+i]; |
| - | 266 | } |
|
| - | 267 | Can_Send(&cm); |
|
| - | 268 | ||
| - | 269 | if (gotdumpserver != 0) { |
|
| - | 270 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", cm.Id, (uint16_t)(cm.DataLength), (uint16_t)(cm.ExtendedFlag), (uint16_t)(cm.RemoteFlag)); |
|
| - | 271 | printf("data={ "); |
|
| - | 272 | for (i=0; i<cm.DataLength; i++) { |
|
| - | 273 | printf("%x ", cm.Data.bytes[i]); |
|
| 243 | } |
274 | } |
| 244 |
|
275 | printf("}\n"); |
| 245 | } |
276 | } |
| 246 | printf("hoj\n"); |
- | |
| 247 | } |
277 | } |
| 248 |
|
278 | //om port 1200 (dumparporten) |
| 249 |
|
279 | } else if ((buf[UDP_DST_PORT_H_P]==((locDumperPrt>>8) & 0xff)) && (buf[UDP_DST_PORT_L_P] == (locDumperPrt & 0xff))) { |
| 250 | if ( |
280 | if (gotdumpserver == 0) { |
| 251 | while(i<6){ |
281 | while(i<6){ |
| 252 | remotemac[i]=buf[ETH_SRC_MAC +i]; |
282 | remotemac[i]=buf[ETH_SRC_MAC +i]; |
| 253 | i++; |
283 | i++; |
| 254 | } |
284 | } |
| 255 | i=0; |
285 | i=0; |
| Line 257... | Line 287... | ||
| 257 | remoteip[i]=buf[IP_SRC_P +i]; |
287 | remoteip[i]=buf[IP_SRC_P +i]; |
| 258 | i++; |
288 | i++; |
| 259 | } |
289 | } |
| 260 | i=0; |
290 | i=0; |
| 261 | 291 | ||
| 262 |
|
292 | gotdumpserver = 1; |
| 263 | make_udp_reply_from_request(buf,"Got server",10,rmDumperPrt); |
293 | make_udp_reply_from_request(buf,"Got server",10,rmDumperPrt); |
| 264 | } else { |
294 | } else { |
| 265 | make_udp_reply_from_request(buf,"Already got server",18,rmDumperPrt); |
295 | make_udp_reply_from_request(buf,"Already got server",18,rmDumperPrt); |
| 266 | } |
296 | } |
| 267 | } |
297 | } |