/Designs/MRAKOMER4/SW/irmrak4.c/irmrak4.c
1,5 → 1,5
/**** IR Mrakomer 4 ****/
#define VERSION "4.0"
#define VERSION "4.1"
#define ID "$Id$"
 
#include "irmrak4.h"
49,21 → 49,16
char REV[50]=ID; // Buffer for concatenate of a version string
 
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0;
printf("\n\r\n\r# Mrakomer %s (C) 2007 KAKL\n\r",VER); // Welcome message
printf("#%s\n\r",&REV[4]);
printf("#\n\r");
printf("# h - Switch On Heating for 20s.\n\r");
printf("# c - Need Colder. Switch Off Heating.\n\r");
printf("# o - Open the Dome for 20s.\n\r");
printf("# l - Lock the Dome.\n\r");
printf("# x - Open the Dome and switch On Heating.\n\r");
printf("# i - Print this Information.\n\r");
printf("# r - Repeat measure every second.\n\r");
printf("# s - Single measure.\n\r");
printf("# u - Update firmware. Go to the Boot Loader.\n\r");
printf("#\n\r");
printf("# <sequence> <ambient[1/100 C]> <sky[1/100 C]> ");
printf("<heating[s]> <dome[s]> <check>\n\r\n\r");
printf("\r\n\r\n# Mrakomer %s (C) 2007 UST\n\r",VER); // Welcome message
printf("#%s\r\n",&REV[4]);
// printf("#\r\n");
printf("# commands: h, c, o, l, x, i, r, a, s, u\r\n");
// printf("# h_eat, c_old, o_pen, l_ock, x_open, ");
// printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n");
// printf("#\r\n");
printf("# ver seq in[1/100 C] sky[1/100 C] sky[1/100 C] ");
printf("out[1/100 C] heat[s] dome[s] check\r\n\r\n");
 
//---WDT
restart_wdt();
}
70,6 → 65,7
 
 
#include "smb.c" // System Management Bus driver
#include "TOUCH.C"
 
 
// Read sensor's RAM
103,14 → 99,48
return temp;
}
 
// compute CRC
// *sn - pointer to the byte array
// num - length of array
inline int8 TM_check_CRC(unsigned int8 *sn, unsigned int8 num)
{
// CRC table
const int8 TouchCRC[256]= {
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53};
 
int8 CRC;
int8 i;
 
CRC=0;
for(i=0;i<num;i++) CRC=TouchCRC[CRC ^ *(sn+i)];
return(CRC);
}
 
 
/*-------------------------------- MAIN --------------------------------------*/
void main()
{
unsigned int16 seq, temp, tempa;
signed int16 ta, to;
signed int16 ta, to1, to2, tTouch;
int8 tLSB,tMSB; // Temperatures from TouchMemory
int8 safety_counter;
int1 repeat;
int1 repeat; // Status flags
int1 automatic;
 
output_high(DOME); // Close Dome
output_low(HEATING); // Heating off
122,11 → 152,15
heat=0;
open=0;
repeat=TRUE;
automatic=FALSE;
 
welcome();
 
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read
temp=ReadTemp(SA, RAM_Tobj1);
touch_present(); //Issues a reset of Touch Memory device
touch_write_byte(0xCC);
touch_write_byte(0x44);
 
delay_ms(1000);
//---WDT
165,23 → 199,28
{
case 'h':
heat=MAXHEAT; // Need heating
automatic=FALSE;
break;
 
case 'c':
heat=0; // Need colder
automatic=FALSE;
break;
 
case 'o':
open=MAXOPEN; // Open the dome
automatic=FALSE;
break;
 
case 'x':
open=MAXOPEN; // Open the dome
heat=MAXHEAT; // Need heating
automatic=FALSE;
break;
 
case 'l':
open=0; // Lock the dome
automatic=FALSE;
break;
 
case 'i':
190,27 → 229,71
 
case 'r':
repeat=TRUE; // Repeated measure mode
automatic=FALSE;
break;
 
case 's':
repeat=FALSE; // Single measure mode
automatic=FALSE;
break;
 
case 'a':
repeat=TRUE; // Automatic mode
automatic=TRUE;
break;
 
case 'u':
reset_cpu(); // Update firmware
}
}
// while(kbhit()) getc(); // Flush USART buffer
CREN=0; CREN=1; // Reinitialise USART
 
seq++; // Increment the number of measurement
 
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor
ta=tempa*2-27315; // °K -> °C
 
temp=ReadTemp(SA, RAM_Tobj1);
if (temp>0x48E1) {to1=-27315;} else {to1=temp*2-27315;}
temp=ReadTemp(SA, RAM_Tobj2);
if (temp>0x48E1) {to2=-27315;} else {to2=temp*2-27315;}
 
ta=tempa*2-27315; // °K -> °C
to=temp*2-27315;
touch_present(); //Issues a reset of Touch Memory device
touch_write_byte(0xCC);
touch_write_byte(0x44);
//---WDT
restart_wdt();
delay(MEASURE_DELAY); // Delay to a next measurement
 
{
int8 SN[10];
int8 n;
 
touch_present(); //Issues a reset and returns true if the touch device is there.
touch_write_byte(0xCC);
touch_write_byte(0xBE);
for(n=0;n<9;n++) SN[n]=touch_read_byte();
tLSB=SN[0];
tMSB=SN[1];
if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error
{
tTouch=make16(tMSB,tLSB);
tTouch=tTouch*6+tTouch/4; // 1bit = 0,0625gradC recalculate to 1/100gradC
}
else
{
tTouch=-27315;
}
}
if(automatic) // Solve automatic mode
{
if(ta<1800) heat=MAXHEAT; // Need heating
if((abs(to1-to2)<80)&&(tTouch>to1)&&(abs(tTouch-to1)>1500))
open=MAXOPEN; // Open the dome
}
 
{ // printf
char output[8]; // Output buffer
int8 j; // String pointer
219,24 → 302,27
delay(SEND_DELAY);
putc('$');
delay(SEND_DELAY);
sprintf(output,"M%s ",VER);
sprintf(output,"M%s \0",VER);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Lu ", seq);
sprintf(output,"%Lu \0", seq);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", ta);
sprintf(output,"%Ld \0", ta);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", to);
sprintf(output,"%Ld \0", to1);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u ", heat);
sprintf(output,"%Ld \0", to2);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u ", open);
sprintf(output,"%Ld \0",tTouch);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"*%X\n\r\0", check);
sprintf(output,"%u \0", heat);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u \0", open);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"*%X\r\n\0", check);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); }
delay(SEND_DELAY);
}
 
delay(MEASURE_DELAY); // Delay to a next measurement
//---WDT
restart_wdt();
}