Subversion Repositories HomeAutomation

Rev

Rev 1125 | Rev 1557 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1125 Rev 1446
1
 
1
 
2
#include "<template>.h"
2
#include "<template>.h"
3
 
3
 
4
#ifdef <template>_USEEEPROM
4
#ifdef <template>_USEEEPROM
5
#include "<template>_eeprom.h"
5
#include "<template>_eeprom.h"
6
struct eeprom_<template> EEMEM eeprom_<template> =
6
struct eeprom_<template> EEMEM eeprom_<template> =
7
{
7
{
8
    {
8
    {
9
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file. 
9
        ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file.
10
        0xAB,   // x
10
        0xAB,   // x
11
        0x1234  // y
11
        0x1234  // y
12
    },
12
    },
13
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
13
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
14
};
14
};
15
#endif
15
#endif
16
 
16
 
17
void <template>_Init(void)
17
void <template>_Init(void)
18
{
18
{
19
#ifdef <template>_USEEEPROM
19
#ifdef <template>_USEEEPROM
20
    if (EEDATA_OK)
20
    if (EEDATA_OK)
21
    {
21
    {
22
      ///TODO: Use stored data to set initial values for the module
22
      ///TODO: Use stored data to set initial values for the module
23
      blablaX = eeprom_read_byte(EEDATA.x);
23
      blablaX = eeprom_read_byte(EEDATA.x);
24
      blablaY = eeprom_read_word(EEDATA.y);
24
      blablaY = eeprom_read_word(EEDATA16.y);
25
    } else
25
    } else
26
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
26
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
27
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
27
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
28
      eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC);
28
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
29
      EEDATA_UPDATE_CRC;
29
      EEDATA_UPDATE_CRC;
30
    }
30
    }
31
#endif  
31
#endif
32
    ///TODO: Initialize hardware etc here
32
    ///TODO: Initialize hardware etc here
33
 
33
 
34
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
34
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
35
    // Pcint_SetCallbackPin(<template>_PCINT, EXP_C , &<template>_pcint_callback);
35
    // Pcint_SetCallbackPin(<template>_PCINT, EXP_C , &<template>_pcint_callback);
36
 
36
 
37
}
37
}
38
 
38
 
39
void <template>_Process(void)
39
void <template>_Process(void)
40
{
40
{
41
    ///TODO: Stuff that needs doing is done here
41
    ///TODO: Stuff that needs doing is done here
42
}
42
}
43
 
43
 
44
void <template>_HandleMessage(StdCan_Msg_t *rxMsg)
44
void <template>_HandleMessage(StdCan_Msg_t *rxMsg)
45
{
45
{
46
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_xyz && ///TODO: Change this to the actual class type
46
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_xyz && ///TODO: Change this to the actual class type
47
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
47
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
48
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_xyz && ///TODO: Change this to the actual module type
48
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_xyz && ///TODO: Change this to the actual module type
49
        rxMsg->Header.ModuleId == <template>_ID)
49
        rxMsg->Header.ModuleId == <template>_ID)
50
    {
50
    {
51
        switch (rxMsg->Header.Command)
51
        switch (rxMsg->Header.Command)
52
        {
52
        {
53
        case CAN_CMD_MODULE_DUMMY:
53
        case CAN_CMD_MODULE_DUMMY:
54
        ///TODO: Do something dummy
54
        ///TODO: Do something dummy
55
        break;
55
        break;
56
        }
56
        }
57
    }
57
    }
58
}
58
}
59
 
59
 
60
void <template>_List(uint8_t ModuleSequenceNumber)
60
void <template>_List(uint8_t ModuleSequenceNumber)
61
{
61
{
62
    StdCan_Msg_t txMsg;
62
    StdCan_Msg_t txMsg;
63
   
63
 
64
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_xyz); ///TODO: Change this to the actual class type
64
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_xyz); ///TODO: Change this to the actual class type
65
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
65
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
66
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_xyz; ///TODO: Change this to the actual module type
66
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_xyz; ///TODO: Change this to the actual module type
67
    txMsg.Header.ModuleId = <template>_ID;
67
    txMsg.Header.ModuleId = <template>_ID;
68
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
68
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
69
    txMsg.Length = 6;
69
    txMsg.Length = 6;
70
 
70
 
71
    txMsg.Data[0] = NODE_HW_ID_BYTE0;
71
    txMsg.Data[0] = NODE_HW_ID_BYTE0;
72
    txMsg.Data[1] = NODE_HW_ID_BYTE1;
72
    txMsg.Data[1] = NODE_HW_ID_BYTE1;
73
    txMsg.Data[2] = NODE_HW_ID_BYTE2;
73
    txMsg.Data[2] = NODE_HW_ID_BYTE2;
74
    txMsg.Data[3] = NODE_HW_ID_BYTE3;
74
    txMsg.Data[3] = NODE_HW_ID_BYTE3;
75
   
75
 
76
    txMsg.Data[4] = NUMBER_OF_MODULES;
76
    txMsg.Data[4] = NUMBER_OF_MODULES;
77
    txMsg.Data[5] = ModuleSequenceNumber;
77
    txMsg.Data[5] = ModuleSequenceNumber;
78
   
78
 
79
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
79
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
80
}
80
}
81
 
81