Rev 167 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 167 | Rev 169 | ||
|---|---|---|---|
| Line 25... | Line 25... | ||
| 25 | 25 | ||
| 26 | #include <onewire.h> |
26 | #include <onewire.h> |
| 27 | #include <ds18x20.h> |
27 | #include <ds18x20.h> |
| 28 | 28 | ||
| 29 | #include <delay.h> |
29 | #include <delay.h> |
| 30 | #include <inttypes.h> |
- | |
| 31 | 30 | ||
| 32 | #include <eqlazer_funcdefs.h> |
- | |
| - | 31 | ||
| 33 | 32 | ||
| 34 | #define MAXSENSORS 4 |
33 | #define MAXSENSORS 4 |
| 35 | 34 | ||
| 36 | uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE]; |
35 | uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE]; |
| 37 | 36 | ||
| Line 66... | Line 65... | ||
| 66 | nSensors++; |
65 | nSensors++; |
| 67 | } |
66 | } |
| 68 | 67 | ||
| 69 | return nSensors; |
68 | return nSensors; |
| 70 | } |
69 | } |
| - | 70 | ||
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | /*----------------------------------------------------------------------------- |
73 | /*----------------------------------------------------------------------------- |
| 74 | * Main Program |
74 | * Main Program |
| 75 | *---------------------------------------------------------------------------*/ |
75 | *---------------------------------------------------------------------------*/ |
| Line 103... | Line 103... | ||
| 103 | if (Can_Init() != CAN_OK) { |
103 | if (Can_Init() != CAN_OK) { |
| 104 | printf("FAILED!\n"); |
104 | printf("FAILED!\n"); |
| 105 | } |
105 | } |
| 106 | else { |
106 | else { |
| 107 | printf("OK!\n"); |
107 | printf("OK!\n"); |
| 108 | } |
108 | } |
| 109 | 109 | ||
| 110 | uint32_t timeStamp = 0; |
110 | uint32_t timeStamp = 0; |
| 111 | 111 | ||
| 112 | Can_Message_t txMsg; |
112 | Can_Message_t txMsg; |
| 113 | Can_Message_t rxMsg; |
113 | Can_Message_t rxMsg; |
| 114 | 114 | ||
| 115 | txMsg.DataLength = 2; |
115 | txMsg.DataLength = 2; |
| 116 | txMsg.Id = 0; |
116 | txMsg.Id = 0; |
| 117 | txMsg.RemoteFlag = 0; |
117 | txMsg.RemoteFlag = 0; |
| 118 | txMsg.ExtendedFlag = 1; |
118 | txMsg.ExtendedFlag = 1; |
| 119 | - | ||
| 120 | // txMsg.Id = txMsg.Id | NODE_SENSOR_1 | (NID << 9) | (FUNCC_SENSORS_TEMPERATURE_INSIDE << 15) | (FUNCT_SENSORS << 25); |
- | |
| 121 | // txMsg.Id = 0x02010A0F; |
- | |
| 122 | 119 | ||
| 123 | /* main loop */ |
120 | /* main loop */ |
| 124 | while (1) { |
121 | while (1) { |
| 125 | /* service the CAN routines */ |
122 | /* service the CAN routines */ |
| 126 | Can_Service(); |
123 | Can_Service(); |
| 127 | 124 | ||
| 128 | /* check if any messages have been received */ |
125 | /* check if any messages have been received */ |
| 129 | while (Can_Receive(&rxMsg) == CAN_OK) { |
126 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 130 | /* 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)); |
- | |
| 131 |
|
127 | |
| 132 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
- | |
| 133 | printf("%x ", rxMsg.Data.bytes[i]); |
- | |
| 134 | } |
128 | } |
| 135 | printf("}\n"); |
- | |
| 136 | */ } |
- | |
| 137 | 129 | ||
| 138 | /* check temperature and send on CAN once every other second */ |
130 | /* check temperature and send on CAN once every other second */ |
| 139 | if (Timebase_PassedTimeMillis(timeStamp) >= 2000) { |
131 | if (Timebase_PassedTimeMillis(timeStamp) >= 2000) { |
| 140 | timeStamp = Timebase_CurrentTime(); |
132 | timeStamp = Timebase_CurrentTime(); |
| 141 | 133 | ||
| 142 | if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) { |
134 | if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) { |
| 143 | printf("Measuring temperature... |
135 | printf("Measuring temperature... "); |
| 144 | delay_ms(DS18B20_TCONV_12BIT); |
136 | delay_ms(DS18B20_TCONV_12BIT); |
| 145 | for ( i=0; i<nSensors; i++ ) { |
137 | for ( i=0; i<nSensors; i++ ) { |
| 146 | if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero, |
138 | if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero, |
| 147 | &cel, &cel_frac_bits) == DS18X20_OK ) { |
139 | &cel, &cel_frac_bits) == DS18X20_OK ) { |
| 148 | 140 | ||
| 149 | //txMsg.Data.bytes[0] = subzero; |
141 | //txMsg.Data.bytes[0] = subzero; |
| 150 | if (subzero) { |
142 | if (subzero) { |
| 151 | txMsg.Data.bytes[ |
143 | txMsg.Data.bytes[i*2] = -cel; |
| 152 | } else { |
- | |
| 153 | txMsg.Data.bytes[0] = cel; |
- | |
| 154 | } |
- | |
| 155 | /* if (subzero) { |
- | |
| 156 |
|
144 | txMsg.Data.bytes[i*2+1] = ~(cel_frac_bits<<4); |
| 157 | } else { |
145 | } else { |
| 158 | txMsg.Data.bytes[i*2] = cel; |
146 | txMsg.Data.bytes[i*2] = cel; |
| - | 147 | txMsg.Data.bytes[i*2+1] = (cel_frac_bits<<4); |
|
| 159 | } |
148 | } |
| 160 |
|
149 | |
| 161 | txMsg.Data.bytes[1] = (cel_frac_bits<<4); |
- | |
| 162 | // txMsg.Data.bytes[i*2+1] = (cel_frac_bits<<4); |
- | |
| 163 |
|
150 | } |
| 164 | txMsg.Id = 0x02020A0F; |
- | |
| 165 | // printf("freezer\n"); |
- | |
| 166 | }else if(i==1){ // outside |
- | |
| 167 | txMsg.Id = 0x0201FA0F; |
- | |
| 168 |
|
151 | else printf("CRC Error (lost connection?)\n"); |
| 169 | }else if(i==2){ // inside |
- | |
| 170 | txMsg.Id = 0x02010A0F; |
- | |
| 171 | // printf("inside\n"); |
- | |
| 172 | }else{ |
- | |
| 173 | txMsg.Id = 0x00000003; |
- | |
| 174 | } |
152 | } |
| 175 | 153 | ||
| - | 154 | txMsg.DataLength = nSensors*2; |
|
| 176 | printf("sending...\n"); |
155 | printf("sending...\n"); |
| - | 156 | /* send txMsg */ |
|
| 177 | Can_Send(&txMsg); |
157 | Can_Send(&txMsg); |
| 178 | } |
- | |
| 179 | else printf("CRC Error (lost connection?)\n"); |
- | |
| 180 | } |
- | |
| 181 | } |
158 | } |
| 182 | else printf("Start meas. failed (short circuit?)\n"); |
159 | else printf("Start meas. failed (short circuit?)\n"); |
| 183 | 160 | ||
| 184 | // txMsg.DataLength = nSensors*2; |
- | |
| 185 | // printf("sending...\n"); |
- | |
| 186 | /* send txMsg */ |
- | |
| 187 | // Can_Send(&txMsg); |
- | |
| 188 | } |
161 | } |
| 189 | } |
162 | } |
| 190 | 163 | ||
| 191 | return 0; |
164 | return 0; |
| 192 | } |
165 | } |