Subversion Repositories HomeAutomation

Rev

Rev 1147 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
833 linlun 1
 
2
#include "sns_FOST02.h"
3
 
4
 
5
 
6
void GetTemperature(void);
7
void GetTemperature_callback(uint8_t timer);
854 linlun 8
void GetHumidity(void);
9
void GetHumidity_callback(uint8_t timer);
833 linlun 10
 
854 linlun 11
uint8_t FlagGetTemperature = 0, FlagGetHumidity = 0, byte1 = 0, byte2 = 0;
833 linlun 12
 
13
void GetTemperature_callback(uint8_t timer)
14
{
15
    FlagGetTemperature = 1;
854 linlun 16
    sendCommand(0x03);
833 linlun 17
}
18
 
854 linlun 19
void GetHumidity_callback(uint8_t timer)
833 linlun 20
{
854 linlun 21
    FlagGetHumidity = 1;
22
    sendCommand(0x05);
833 linlun 23
}
24
 
25
void GetTemperature(void)
26
{
854 linlun 27
    uint16_t TmpV;
833 linlun 28
    if (getFOST02PinStatus() == 0) {
29
        StdCan_Msg_t txMsg;
955 runge 30
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
31
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
32
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_FOST02;
854 linlun 33
        txMsg.Header.ModuleId = sns_FOST02_ID;
955 runge 34
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
1146 linlun 35
        txMsg.Length = 3;
854 linlun 36
        txMsg.Data[0] = FOST02_ID;
833 linlun 37
 
854 linlun 38
        getFOST02DataByte(&byte1, &byte2);
39
        TmpV = (uint16_t) (byte1<<8) + byte2;
40
        TmpV = TmpV << 4;
1147 linlun 41
        TmpV = TmpV/5;
1146 linlun 42
        TmpV = TmpV << 2;
1147 linlun 43
        TmpV = TmpV/5;
1146 linlun 44
        TmpV = TmpV-(40*64);
1145 linlun 45
        txMsg.Data[2]= (uint8_t) (TmpV & 0xFF);
46
        txMsg.Data[1]= (uint8_t) ((TmpV >> 8) & 0xFF);
833 linlun 47
        StdCan_Put(&txMsg);
854 linlun 48
 
49
        FlagGetTemperature = 0;
50
    }
833 linlun 51
 
52
}
53
 
854 linlun 54
void GetHumidity(void)
833 linlun 55
{
854 linlun 56
    uint16_t TmpV;
57
    if (getFOST02PinStatus() == 0) {
58
        StdCan_Msg_t txMsg;
955 runge 59
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
60
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
61
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_FOST02;
854 linlun 62
        txMsg.Header.ModuleId = sns_FOST02_ID;
955 runge 63
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_HUMIDITY_PERCENT;
854 linlun 64
        txMsg.Length = 3;
65
        txMsg.Data[0] = FOST02_ID;
833 linlun 66
 
854 linlun 67
        getFOST02DataByte(&byte1, &byte2);
68
        TmpV = HumidityTable[byte2];
866 linlun 69
        txMsg.Data[2]= (uint8_t) ((TmpV>>2) & 0x00FF);
70
        txMsg.Data[1]= (uint8_t) ((TmpV >> 10) & 0x00FF);
833 linlun 71
 
854 linlun 72
        StdCan_Put(&txMsg);
833 linlun 73
 
854 linlun 74
        FlagGetHumidity = 0;
833 linlun 75
    }
76
}
77
 
854 linlun 78
void InitTemp_callback(uint8_t timer)
833 linlun 79
{
854 linlun 80
    Timer_SetTimeout(sns_FOST02_TEMP_TIMER, sns_FOST02_TEMP_SEND_PERIOD , TimerTypeFreeRunning, &GetTemperature_callback);
833 linlun 81
}
82
 
83
void sns_FOST02_Init(void)
84
{
85
    FlagGetTemperature = 0;
854 linlun 86
    FlagGetHumidity = 0;
833 linlun 87
    FOST02Init();
88
 
854 linlun 89
    Timer_SetTimeout(sns_FOST02_HYDRO_TIMER, sns_FOST02_HYDRO_SEND_PERIOD , TimerTypeFreeRunning, &GetHumidity_callback);
90
    // The reson for using sns_FOST02_HYDRO_SEND_PERIOD/2 as time out for this is to spread out the communication with the sensor if
91
    // both temp and humi has the same send period time.
92
    Timer_SetTimeout(sns_FOST02_TEMP_TIMER, sns_FOST02_HYDRO_SEND_PERIOD/2 , TimerTypeFreeRunning, &InitTemp_callback);
833 linlun 93
}
94
 
95
void sns_FOST02_Process(void)
96
{
97
 
854 linlun 98
    if (FlagGetHumidity)
833 linlun 99
    {
854 linlun 100
        GetHumidity();
833 linlun 101
    }
102
 
854 linlun 103
    if (FlagGetTemperature)
833 linlun 104
    {
854 linlun 105
        GetTemperature();
833 linlun 106
    }
107
}
108
 
109
void sns_FOST02_HandleMessage(StdCan_Msg_t *rxMsg)
110
{
111
}
112
 
113
void sns_FOST02_List(uint8_t ModuleSequenceNumber)
114
{
115
    StdCan_Msg_t txMsg;
116
 
955 runge 117
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
118
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
119
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_FOST02;
854 linlun 120
    txMsg.Header.ModuleId = sns_FOST02_ID;
955 runge 121
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
833 linlun 122
    txMsg.Length = 6;
123
 
1910 arune 124
    uint32_t HwId=BIOS_GetHwId();
125
    txMsg.Data[0] = HwId&0xff;
126
    txMsg.Data[1] = (HwId>>8)&0xff;
127
    txMsg.Data[2] = (HwId>>16)&0xff;
128
    txMsg.Data[3] = (HwId>>24)&0xff;
833 linlun 129
 
130
    txMsg.Data[4] = NUMBER_OF_MODULES;
131
    txMsg.Data[5] = ModuleSequenceNumber;
132
 
967 runge 133
    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
833 linlun 134
}