Subversion Repositories HomeAutomation

Rev

Rev 212 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 212 Rev 280
Line 1... Line 1...
1
/**
1
/**
2
 * CAN Test. This program sends a CAN message once every second. The ID of the
-
 
3
 * message is increased each time for testing purposes.
-
 
-
 
2
 *
-
 
3
 *
4
 *
4
 *
5
 * @date    2006-11-21
5
 * @date    2006-11-21
6
 * @author  Jimmy Myhrman
6
 * @author  Jimmy Myhrman, Anders Runeson
7
 *  
7
 *  
8
 */
8
 */
9
 
9
 
10
/*-----------------------------------------------------------------------------
10
/*-----------------------------------------------------------------------------
11
 * Includes
11
 * Includes
Line 15... Line 15...
15
#include <avr/interrupt.h>
15
#include <avr/interrupt.h>
16
#include <avr/wdt.h>
16
#include <avr/wdt.h>
17
#include <stdio.h>
17
#include <stdio.h>
18
/* lib files */
18
/* lib files */
19
#include <can.h>
19
#include <can.h>
20
#include <serial.h>
20
//#include <serial.h>
21
#include <timebase.h>
21
#include <timebase.h>
22
#include <ip_arp_udp_tcp.h>
22
#include <ip_arp_udp_tcp.h>
23
#include <enc28j60.h>
23
#include <enc28j60.h>
24
#include <timeout.h>
24
#include <timeout.h>
25
#include <avr_compat.h>
25
#include <avr_compat.h>
Line 28... Line 28...
28
// please modify the following two lines. mac and ip have to be unique
28
// please modify the following two lines. mac and ip have to be unique
29
// in your local area network. You can not have the same numbers in
29
// in your local area network. You can not have the same numbers in
30
// two devices:
30
// two devices:
31
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
31
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
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
-
 
34
static uint16_t rmCan2SerPrt =1100; // remote port for Can2Serial-data
33
static uint16_t remoteport =1200; // listen port for udp
35
static uint16_t locDumperPrt =1200; // listen port 
-
 
36
static uint16_t locCan2SerPrt =1100; // listen port for Can2Serial-data
34
static uint8_t gotserver = 0;
37
static uint8_t gotserver = 0;
35
 
38
 
36
// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX
39
// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX
37
 
40
 
38
static uint8_t remotemac[6];
41
static uint8_t remotemac[6];
Line 55... Line 58...
55
    if (gotserver != 0) {
58
    if (gotserver != 0) {
56
        sendbuf[buffpoint] = c;
59
        sendbuf[buffpoint] = c;
57
        buffpoint++;
60
        buffpoint++;
58
       
61
       
59
        if (c == '\n' || buffpoint > SEND_BUFFER_SIZE) {
62
        if (c == '\n' || buffpoint > SEND_BUFFER_SIZE) {
60
            send_udp(buf, sendbuf, buffpoint, remoteport, remotemac, remoteip);
63
            send_udp(buf, sendbuf, buffpoint, rmDumperPrt, remotemac, remoteip);
61
            buffpoint = 0;
64
            buffpoint = 0;
62
        }
65
        }
63
    }
66
    }
64
    return 0;
67
    return 0;
65
}
68
}
Line 88... Line 91...
88
 
91
 
89
    uint32_t timeStamp = 0;
92
    uint32_t timeStamp = 0;
90
   
93
   
91
    Mcu_Init();
94
    Mcu_Init();
92
    Timebase_Init();
95
    Timebase_Init();
93
    Serial_Init();
96
    //Serial_Init();
94
 
97
 
95
    //alla printf ska skriva till udp
98
    //alla printf ska skriva till udp
96
    stdout = &mystdout;    //set the output stream 
99
    stdout = &mystdout;    //set the output stream 
97
   
100
   
98
    sei();
101
    sei();
Line 203... Line 206...
203
                            //Can_Send(&txMsg);
206
                            //Can_Send(&txMsg);
204
                           
207
                           
205
                    }
208
                    }
206
                    if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
209
                    if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
207
                        payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
210
                        payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
-
 
211
                            printf("hej %x %x\n", buf[UDP_DST_PORT_H_P], buf[UDP_DST_PORT_L_P]);
-
 
212
                        if ((buf[UDP_DST_PORT_H_P]==((locCan2SerPrt>>8) & 0xff)) && (buf[UDP_DST_PORT_L_P] == (locCan2SerPrt & 0xff))) {
-
 
213
                            printf("hoj\n");
208
                        if (buf[UDP_DATA_P]=='t' && payloadlen==5){
214
                        } else if (buf[UDP_DATA_P]=='t' && payloadlen==5){
209
                            uint8_t i=0;
215
                            uint8_t i=0;
210
                            if (gotserver == 0) {
216
                            if (gotserver == 0) {
211
                                while(i<6){
217
                                while(i<6){
212
                                    remotemac[i]=buf[ETH_SRC_MAC +i];
218
                                    remotemac[i]=buf[ETH_SRC_MAC +i];
213
                                    i++;
219
                                    i++;
Line 218... Line 224...
218
                                    i++;
224
                                    i++;
219
                                }
225
                                }
220
                                i=0;
226
                                i=0;
221
                               
227
                               
222
                                gotserver = 1;
228
                                gotserver = 1;
223
                                make_udp_reply_from_request(buf,"Got server",10,remoteport);
229
                                make_udp_reply_from_request(buf,"Got server",10,rmDumperPrt);
224
                            } else {
230
                            } else {
225
                                make_udp_reply_from_request(buf,"Already got server",18,remoteport);
231
                                make_udp_reply_from_request(buf,"Already got server",18,rmDumperPrt);
226
                            }
232
                            }
227
                        }
233
                        }
228
                    }                      
234
                    }                      
229
                }
235
                }
230
            }
236
            }