Subversion Repositories HomeAutomation

Rev

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

Rev 493 Rev 498
Line 11... Line 11...
11
 *  Transmitts: DATA: <temperature low byte> <temperature high byte> <relay status> <failsafe mode>
11
 *  Transmitts: DATA: <temperature low byte> <temperature high byte> <relay status> <failsafe mode>
12
 *
12
 *
13
 *
13
 *
14
 */
14
 */
15
 
15
 
16
#define TWO_BUTTON_MODE 0 /* If using two (or just one but nothing more) auxiliary buttons */
-
 
17
 
16
 
18
/*-----------------------------------------------------------------------------
17
/*-----------------------------------------------------------------------------
19
 * Includes
18
 * Includes
20
 *---------------------------------------------------------------------------*/
19
 *---------------------------------------------------------------------------*/
21
/* system files */
20
/* system files */
Line 24... Line 23...
24
#include <stdio.h>
23
#include <stdio.h>
25
/* lib files */
24
/* lib files */
26
#include <config.h>
25
#include <config.h>
27
#include <bios.h>
26
#include <bios.h>
28
#include <drivers/timer/timebase.h>
27
#include <drivers/timer/timebase.h>
-
 
28
#include <drivers/sensor/tc1047/tc1047.h>
-
 
29
 
29
//#include <funcdefs.h>
30
#include "settings.h"
30
 
31
 
31
/* defines */
32
/* defines */
32
#define RELAY_OFF           0x01
33
#define RELAY_OFF           0x01
33
#define RELAY_ON            0x02
34
#define RELAY_ON            0x02
34
#define FAILSAFE_MODE       0x0F
35
#define FAILSAFE_MODE       0x0F
Line 42... Line 43...
42
#define STATUS_SEND_PERIOD  10000UL /* milliseconds */
43
#define STATUS_SEND_PERIOD  10000UL /* milliseconds */
43
#define FAILSAFE_SEND_PERIOD    10000UL /* milliseconds */
44
#define FAILSAFE_SEND_PERIOD    10000UL /* milliseconds */
44
#define BOUNCE_TIME         10 /* milliseconds */
45
#define BOUNCE_TIME         10 /* milliseconds */
45
#define BUTTON1             1
46
#define BUTTON1             1
46
#define BUTTON2             2
47
#define BUTTON2             2
47
 
-
 
48
#define THISRELAYID         NODE_ID     /* application software should not depend on the id of the physical node
-
 
49
                                            but for now lets do it like this */
-
 
50
 
48
 
51
#define APP_TYPE    CAN_APPTYPES_RELAY
49
#define APP_TYPE    CAN_APPTYPES_RELAY
52
#define APP_VERSION 0x0001
50
#define APP_VERSION 0x0001
53
 
51
 
54
/*-------------------------------------------------------------------------
52
/*-------------------------------------------------------------------------
Line 62... Line 60...
62
 
60
 
63
 
61
 
64
/*----------------------------------------------------------------------------
62
/*----------------------------------------------------------------------------
65
 * Functions
63
 * Functions
66
 * -------------------------------------------------------------------------*/
64
 * -------------------------------------------------------------------------*/
67
uint8_t relayOff();
65
uint8_t relayOff(void);
68
uint8_t relayOn();
66
uint8_t relayOn(void);
69
void relayFailsafe();
67
void relayFailsafe(void);
70
void sendStatus();
68
void sendStatus(void);
71
 
69
 
72
void can_receive(Can_Message_t *msg)
70
void can_receive(Can_Message_t *msg)
73
{ // CAN callback function
71
{ // CAN callback function
74
    if (!rxMsgFull) {
72
    if (!rxMsgFull) {
75
        memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
73
        memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
Line 124... Line 122...
124
            // Send relay status to CAN
122
            // Send relay status to CAN
125
            sendStatus();
123
            sendStatus();
126
        }
124
        }
127
 
125
 
128
        if (rxMsgFull) {
126
        if (rxMsgFull) {
129
            uint8_t acttype;
127
            uint16_t acttype;
130
            uint16_t relayid;
128
            uint8_t relayid;
131
       
129
       
132
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT){
130
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT){
133
                // Actuator package
131
                // Actuator package
134
                acttype =(uint8_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE);
132
                acttype =(uint16_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE);
135
                relayid = (uint16_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID);
133
                relayid = (uint8_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID);
136
               
134
               
137
                if ((acttype == ACT_TYPE_RELAY) && (relayid == THISRELAYID)) {
135
                if ((acttype == ACT_TYPE_RELAY) && (relayid == THISRELAYID)) {
138
                    // This is a message for this relay
136
                    // This is a message for this relay
139
                    if (rxMsg.Data.bytes[0] == RELAY_CMD_RESET) {
137
                    if (rxMsg.Data.bytes[0] == RELAY_CMD_RESET) {
140
                        // Return to normal operation
138
                        // Return to normal operation