Subversion Repositories HomeAutomation

Rev

Rev 142 | Rev 145 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 142 Rev 144
Line 1... Line 1...
1
/**
1
/**
-
 
2
 * CAN Test. This program sends a CAN message once every second. The ID of the
2
 * CAN test program.
3
 * message is increased each time for testing purposes.
3
 *
4
 *
4
 * @target  AVR
-
 
5
 * @date    2006-10-29
5
 * @date    2006-11-21
6
 * @author  Jimmy Myhrman
6
 * @author  Jimmy Myhrman
7
 *  
7
 *  
8
 */
8
 */
9
 
9
 
10
/*-----------------------------------------------------------------------------
10
/*-----------------------------------------------------------------------------
Line 17... Line 17...
17
#include <stdio.h>
17
#include <stdio.h>
18
/* lib files */
18
/* lib files */
19
#include <can.h>
19
#include <can.h>
20
#include <uart.h>
20
#include <uart.h>
21
#include <timebase.h>
21
#include <timebase.h>
22
#include <protocol.h>
-
 
23
 
22
 
24
 
23
 
25
/*-----------------------------------------------------------------------------
24
/*-----------------------------------------------------------------------------
26
 * Main Program
25
 * Main Program
27
 *---------------------------------------------------------------------------*/
26
 *---------------------------------------------------------------------------*/
28
int main(void) {
27
int main(void) {
29
    Timebase_Init();
28
    Timebase_Init();
30
    Uart_Init();
29
    Uart_Init();
31
    sei();
30
    sei();
32
   
31
   
33
    printf("\n------------------------------\n");
32
    printf("\n------------------------------------------------------------\n");
34
    printf("   CAN Monitor\n");
33
    printf(  "   CAN Test: Periodic Transmission\n");
35
    printf("------------------------------\n");
34
    printf(  "------------------------------------------------------------\n");
36
   
35
   
37
    printf("CanInit...");
36
    printf("CanInit...");
38
    if (Can_Init() != CAN_OK) {
37
    if (Can_Init() != CAN_OK) {
39
        printf("FAILED!\n");
38
        printf("FAILED!\n");
40
    }
39
    }
Line 60... Line 59...
60
        /* send CAN message and check for CAN errors once every second */
59
        /* send CAN message and check for CAN errors once every second */
61
        if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
60
        if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
62
            timeStamp = Timebase_CurrentTime();
61
            timeStamp = Timebase_CurrentTime();
63
            /* send txMsg */
62
            /* send txMsg */
64
            txMsg.Id++;
63
            txMsg.Id++;
65
            //Can_Send(&txMsg);
64
            Can_Send(&txMsg);
66
            printf(".");
-
 
67
        }
65
        }
68
       
66
       
69
        /* check if any messages have been received */
67
        /* check if any messages have been received */
70
        while (Can_Receive(&rxMsg) == CAN_OK) {
68
        while (Can_Receive(&rxMsg) == CAN_OK) {
71
            //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));
69
            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));
72
            //printf("data={ ");
70
            printf("data={ ");
73
            /*for (uint8_t i=0; i<rxMsg.DataLength; i++) {
71
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
74
                printf("%x ", rxMsg.Data.bytes[i]);
72
                printf("%x ", rxMsg.Data.bytes[i]);
75
            }*/
-
 
76
            //printf("}\n");
-
 
77
            if (Can_Send(&rxMsg) != CAN_OK) {
-
 
78
                break;
-
 
79
            }
73
            }
-
 
74
            printf("}\n");
80
        }
75
        }
81
    }
76
    }
82
   
77
   
83
    return 0;
78
    return 0;
84
}
79
}