mirror of
https://github.com/eddyem/BTA_utils.git
synced 2025-12-06 10:45:14 +03:00
some fixes with meteo
This commit is contained in:
parent
a00200af3c
commit
478ad21c7a
@ -82,18 +82,20 @@ static int crc_check(uint8_t *buffer, int length){
|
|||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
uint16_t crc = 0xFFFF;
|
uint16_t crc = 0xFFFF;
|
||||||
int valid_crc;
|
int valid_crc;
|
||||||
|
/*
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
printf("buffer: ");
|
printf("buffer: ");
|
||||||
for(int i = 0; i < length; ++i) printf("%02x ", buffer[i]);
|
for(int i = 0; i < length; ++i) printf("%02x ", buffer[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
while (length-- > 2) {
|
while (length-- > 2) {
|
||||||
byte = *buffer++ ^ crc;
|
byte = *buffer++ ^ crc;
|
||||||
crc >>= 8;
|
crc >>= 8;
|
||||||
crc ^= crc16_table[byte];
|
crc ^= crc16_table[byte];
|
||||||
}
|
}
|
||||||
valid_crc = (crc >> 8) == buffer[1] && (crc & 0xFF) == buffer[0];
|
valid_crc = (crc >> 8) == buffer[1] && (crc & 0xFF) == buffer[0];
|
||||||
DBG("CRC %s", valid_crc ? "OK" : "bad");
|
if(!valid_crc) DBG("CRC BAD");
|
||||||
return valid_crc;
|
return valid_crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,12 +152,12 @@ params_ans check_meteo_params(){
|
|||||||
if(portfd < 0) return ANS_LOSTCONN;
|
if(portfd < 0) return ANS_LOSTCONN;
|
||||||
int n_bytes = -1, res, size = 0;
|
int n_bytes = -1, res, size = 0;
|
||||||
uint8_t meteoflags = 0;
|
uint8_t meteoflags = 0;
|
||||||
uint16_t lastpar = 0;
|
static uint16_t lastpar = 0;
|
||||||
unsigned char buffer[MODBUS_MAX_PACKET_SIZE];
|
unsigned char buffer[MODBUS_MAX_PACKET_SIZE];
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
fd_set set;
|
fd_set set;
|
||||||
time_t tstart = time(NULL);
|
//time_t tstart = time(NULL);
|
||||||
int ctr = 50; // max 50 tries
|
int ctr = 30; // max 30 tries
|
||||||
while(ctr--){
|
while(ctr--){
|
||||||
FD_ZERO(&set);
|
FD_ZERO(&set);
|
||||||
FD_SET(portfd, &set);
|
FD_SET(portfd, &set);
|
||||||
@ -173,13 +175,21 @@ params_ans check_meteo_params(){
|
|||||||
}
|
}
|
||||||
size += n_bytes;
|
size += n_bytes;
|
||||||
if(n_bytes) continue;
|
if(n_bytes) continue;
|
||||||
|
}else if(size == 0){
|
||||||
|
//DBG("no data");
|
||||||
|
return ANS_NODATA;
|
||||||
}
|
}
|
||||||
|
DBG("Ctr=%d, size=%d, res=%d", ctr, size, res);
|
||||||
// read all or end of packet
|
// read all or end of packet
|
||||||
if(size > 0 && res == 0 && (size == REQ_LEN || size == ANS_LEN)){
|
if(size > 0 && res == 0 && (size == REQ_LEN || size == ANS_LEN)){
|
||||||
if(crc_check(buffer, size)){
|
if(crc_check(buffer, size)){
|
||||||
if(size == REQ_LEN){
|
if(size == REQ_LEN){
|
||||||
|
DBG("request");
|
||||||
|
ctr = 30;
|
||||||
lastpar = buffer[2] << 8 | buffer[3];
|
lastpar = buffer[2] << 8 | buffer[3];
|
||||||
}else if(size == ANS_LEN){
|
}else if(size == ANS_LEN){
|
||||||
|
ctr = 30;
|
||||||
|
DBG("answer");
|
||||||
uint16_t val = buffer[3] << 8 | buffer[4];
|
uint16_t val = buffer[3] << 8 | buffer[4];
|
||||||
int prval = 1;
|
int prval = 1;
|
||||||
float f = (float)val / 10.f;
|
float f = (float)val / 10.f;
|
||||||
@ -231,19 +241,26 @@ params_ans check_meteo_params(){
|
|||||||
default:
|
default:
|
||||||
prval = 0;
|
prval = 0;
|
||||||
}
|
}
|
||||||
if(prval) DBG("=%.1f\n", f);
|
|
||||||
lastpar = 0;
|
lastpar = 0;
|
||||||
|
if(prval){
|
||||||
|
DBG("=%.1f\n", f);
|
||||||
|
return ANS_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if(meteoflags == ALLFLAGS){
|
if(meteoflags == ALLFLAGS){
|
||||||
DBG("Got all data");
|
DBG("Got all data");
|
||||||
return ANS_OK;
|
return ANS_OK;
|
||||||
}
|
}
|
||||||
if(time(NULL) - tstart >= METEO_TIMEOUT) return ANS_NOTFULL;
|
if(time(NULL) - tstart >= METEO_TIMEOUT){
|
||||||
|
DBG("Timeout, not all data meteoflags=0x%02X instead of 0x%02X", meteoflags, ALLFLAGS);
|
||||||
|
return ANS_NODATA;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
return ANS_NOTFULL;
|
return ANS_NODATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,12 +20,13 @@
|
|||||||
#define BTA_METEO_MODBUS_H__
|
#define BTA_METEO_MODBUS_H__
|
||||||
|
|
||||||
// data reading timeout (in seconds)
|
// data reading timeout (in seconds)
|
||||||
#define METEO_TIMEOUT 5
|
#define METEO_TIMEOUT 15
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
ANS_OK, // all OK
|
ANS_OK, // all OK
|
||||||
ANS_LOSTCONN, // lost connection
|
ANS_LOSTCONN, // lost connection
|
||||||
ANS_NOTFULL // got not full dataset (or nothing at all)
|
ANS_NODATA, // no data yet
|
||||||
|
// ANS_NOTFULL // got not full dataset (or nothing at all)
|
||||||
} params_ans;
|
} params_ans;
|
||||||
|
|
||||||
int connect2tty();
|
int connect2tty();
|
||||||
|
|||||||
@ -114,7 +114,7 @@ int main(int argc, char *argv[]){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
params_ans a = check_meteo_params();
|
params_ans a = check_meteo_params();
|
||||||
DBG("chk_meteo: %d", a);
|
if(a != ANS_NODATA) DBG("chk_meteo: %d", a);
|
||||||
if(a == ANS_LOSTCONN){
|
if(a == ANS_LOSTCONN){
|
||||||
LOG("Lost connection with device, reconnect!");
|
LOG("Lost connection with device, reconnect!");
|
||||||
clear_flags();
|
clear_flags();
|
||||||
|
|||||||
@ -67,19 +67,18 @@ static void myabort(int sig) {
|
|||||||
char ss[10], tmp[80];
|
char ss[10], tmp[80];
|
||||||
signal(sig,SIG_IGN);
|
signal(sig,SIG_IGN);
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case SIGHUP : strcpy(ss,"SIGHUP"); break;
|
case SIGHUP : strcpy(ss,"SIGHUP"); break;
|
||||||
case SIGINT : strcpy(ss,"SIGINT"); break;
|
case SIGINT : strcpy(ss,"SIGINT"); break;
|
||||||
case SIGQUIT: strcpy(ss,"SIGQUIT"); break;
|
case SIGQUIT: strcpy(ss,"SIGQUIT"); break;
|
||||||
case SIGFPE : strcpy(ss,"SIGFPE"); break;
|
case SIGFPE : strcpy(ss,"SIGFPE"); break;
|
||||||
case SIGPIPE: strcpy(ss,"SIGPIPE"); break;
|
case SIGPIPE: strcpy(ss,"SIGPIPE"); break;
|
||||||
case SIGSEGV: strcpy(ss,"SIGSEGV"); break;
|
case SIGSEGV: strcpy(ss,"SIGSEGV"); break;
|
||||||
case SIGTERM: strcpy(ss,"SIGTERM"); break;
|
case SIGTERM: strcpy(ss,"SIGTERM"); break;
|
||||||
default: sprintf(ss,"SIG_%d",sig); break;
|
default: sprintf(ss,"SIG_%d",sig); break;
|
||||||
}
|
}
|
||||||
print_date(stderr);
|
print_date(stderr);
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
default:
|
default:
|
||||||
|
|
||||||
case SIGHUP :
|
case SIGHUP :
|
||||||
case SIGINT :
|
case SIGINT :
|
||||||
fprintf(stderr,"%s: %s - Ignore .....\n",myname,ss);
|
fprintf(stderr,"%s: %s - Ignore .....\n",myname,ss);
|
||||||
@ -102,8 +101,7 @@ static void myabort(int sig) {
|
|||||||
static int rxpnt;
|
static int rxpnt;
|
||||||
static double rxtime;
|
static double rxtime;
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[]){
|
||||||
{
|
|
||||||
double tcurr, tlast, tok, twndok;
|
double tcurr, tlast, tok, twndok;
|
||||||
char msg[60];
|
char msg[60];
|
||||||
double t0=0., t;
|
double t0=0., t;
|
||||||
@ -139,200 +137,169 @@ int main (int argc, char *argv[])
|
|||||||
t0 = tcurr = tlast = tok = twndok = dtime();
|
t0 = tcurr = tlast = tok = twndok = dtime();
|
||||||
tok -= 600.;
|
tok -= 600.;
|
||||||
|
|
||||||
while (1) {
|
while (1){
|
||||||
char *pep = "RK";
|
char *pep = "RK";
|
||||||
int nch = 0;
|
int nch = 0;
|
||||||
dsleep(0.2);
|
dsleep(0.2);
|
||||||
tcurr = dtime();
|
tcurr = dtime();
|
||||||
if(PEP_A_On && PEP_R_On) {
|
if(PEP_A_On && PEP_R_On){
|
||||||
if(!stop_prog && !start && tcurr-tok>15.) {
|
if(!stop_prog && !start && tcurr-tok>15.) {
|
||||||
idt = 0x447;
|
idt = 0x447;
|
||||||
dlen=6;
|
dlen=6;
|
||||||
tdata[0] = 7;
|
tdata[0] = 7;
|
||||||
tdata[2] = 50; /* 0.5s */
|
tdata[2] = 50; /* 0.5s */
|
||||||
tdata[3] = 1;
|
tdata[3] = 1;
|
||||||
tdata[4] = 0; tdata[5] = 50; /* 0.5s */
|
tdata[4] = 0; tdata[5] = 50; /* 0.5s */
|
||||||
for(i=0; i<8; i++) {
|
for(i=0; i<8; i++) {
|
||||||
if(i==2||i==3||i==5||i==6) /* T-ÚÅÒËÁÌÁ, ×ÅÔÅÒ, ×ÌÁÖÎÏÓÔØ, T ÎÁ ÍÅÔÅÏ-ÍÁÞÔÅ */
|
if(i==2||i==4|i==3||i==5||i==6) /* T-ÚÅÒËÁÌÁ, ×ÅÔÅÒ, ÄÁ×ÌÅÎÉÅ, ×ÌÁÖÎÏÓÔØ, T ÎÁ ÍÅÔÅÏ-ÍÁÞÔÅ */
|
||||||
continue; /* ÐÏËÁ ÎÅ ÉÓÐÏÌØÚÕÀÔÓÑ (ÚÁÍÅÎÅÎÙ) */
|
continue; /* ÐÏËÁ ÎÅ ÉÓÐÏÌØÚÕÀÔÓÑ (ÚÁÍÅÎÅÎÙ) */
|
||||||
if(i==4) { /*×ÒÅÍÅÎÎÏ: ÐÏËÁ áãð4 ÉÄÅÔ Ó PEP-A (ÄÁ×ÌÅÎÉÅ)*/
|
pep = "RK";
|
||||||
pep = "A";
|
idt = 0x447; /* PEP-RK */
|
||||||
idt = 0x40f; /* PEP-A */
|
tdata[1] = nch = i; /* áãð/i */
|
||||||
tdata[1] = nch = 4; /* áãð/4 */
|
print_date(stderr);
|
||||||
} else {
|
if(can_send_frame(idt, dlen, tdata)<=0) {
|
||||||
pep = "RK";
|
fprintf(stderr, "Can't send command \"Start ADC%d\" to PEP-%s!\n", nch,pep);
|
||||||
idt = 0x447; /* PEP-RK */
|
} else if(tcurr-tlast<70.)
|
||||||
tdata[1] = nch = i; /* áãð/i */
|
fprintf(stderr, "Send command \"Start ADC%d\" to PEP-%s.\n", nch,pep);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
start=1;
|
||||||
|
tok = tcurr;
|
||||||
}
|
}
|
||||||
print_date(stderr);
|
if(stop_prog || (start && tcurr-tok>5.)) {
|
||||||
if(can_send_frame(idt, dlen, tdata)<=0) {
|
if(!stop_prog) {
|
||||||
fprintf(stderr,"Can't send command \"Start ADC%d\" to PEP-%s!\n",nch,pep);
|
print_date(stderr);
|
||||||
} else if(tcurr-tlast<70.)
|
fprintf(stderr,"PEP-RK: ADC(0,1,7) (or PEP-A ADC4) timeout!\n");
|
||||||
fprintf(stderr,"Send command \"Start ADC%d\" to PEP-%s.\n",nch,pep);
|
}
|
||||||
fflush(stderr);
|
MeteoMode &= ~SENSOR_T2;
|
||||||
}
|
idt = 0x447;
|
||||||
start=1;
|
dlen=6;
|
||||||
tok = tcurr;
|
tdata[0] = 7;
|
||||||
}
|
tdata[2] = tdata[3] = tdata[4] = tdata[5] = 0;
|
||||||
if(stop_prog || (start && tcurr-tok>5.)) {
|
for(i=0; i<8; i++) {
|
||||||
if(!stop_prog) {
|
if(i==2||i==3||i==5||i==6) /* T-ÚÅÒËÁÌÁ, ×ÅÔÅÒ, ×ÌÁÖÎÏÓÔØ, T ÎÁ ÍÅÔÅÏ-ÍÁÞÔÅ */
|
||||||
print_date(stderr);
|
continue; /* ÐÏËÁ ÎÅ ÉÓÐÏÌØÚÕÀÔÓÑ (ÚÁÍÅÎÅÎÙ) */
|
||||||
fprintf(stderr,"PEP-RK: ADC(0,1,7) (or PEP-A ADC4) timeout!\n");
|
if(i==4) { /*×ÒÅÍÅÎÎÏ: ÐÏËÁ áãð4 ÉÄÅÔ Ó PEP-A (ÄÁ×ÌÅÎÉÅ)*/
|
||||||
}
|
pep = "A";
|
||||||
#if 0
|
idt = 0x40f; /* PEP-A */
|
||||||
MeteoMode &= ~SENSOR_T2;
|
tdata[1] = nch = 4; /* áãð/4 */
|
||||||
idt = 0x447;
|
} else {
|
||||||
dlen=6;
|
pep = "RK";
|
||||||
tdata[0] = 7;
|
idt = 0x447; /* PEP-RK */
|
||||||
tdata[2] = tdata[3] = tdata[4] = tdata[5] = 0;
|
tdata[1] = nch = i; /* áãð/i */
|
||||||
for(i=0; i<8; i++) {
|
}
|
||||||
if(i==2||i==3||i==5||i==6) /* T-ÚÅÒËÁÌÁ, ×ÅÔÅÒ, ×ÌÁÖÎÏÓÔØ, T ÎÁ ÍÅÔÅÏ-ÍÁÞÔÅ */
|
print_date(stderr);
|
||||||
continue; /* ÐÏËÁ ÎÅ ÉÓÐÏÌØÚÕÀÔÓÑ (ÚÁÍÅÎÅÎÙ) */
|
if(can_send_frame(idt, dlen, tdata)<=0) {
|
||||||
if(i==4) { /*×ÒÅÍÅÎÎÏ: ÐÏËÁ áãð4 ÉÄÅÔ Ó PEP-A (ÄÁ×ÌÅÎÉÅ)*/
|
fprintf(stderr,"Can't send command \"Stop ADC%d\" to PEP-%s!\n",nch,pep);
|
||||||
pep = "A";
|
} else if(tcurr-tlast<70.)
|
||||||
idt = 0x40f; /* PEP-A */
|
fprintf(stderr,"Send command \"Stop ADC%d\" to PEP-%s.\n",nch,pep);
|
||||||
tdata[1] = nch = 4; /* áãð/4 */
|
fflush(stderr);
|
||||||
} else {
|
}
|
||||||
pep = "RK";
|
if(stop_prog) can_exit(0);
|
||||||
idt = 0x447; /* PEP-RK */
|
start=0;
|
||||||
tdata[1] = nch = i; /* áãð/i */
|
tok = tcurr;
|
||||||
}
|
}
|
||||||
print_date(stderr);
|
} else {
|
||||||
if(can_send_frame(idt, dlen, tdata)<=0) {
|
if(stop_prog) can_exit(0);
|
||||||
fprintf(stderr,"Can't send command \"Stop ADC%d\" to PEP-%s!\n",nch,pep);
|
else {
|
||||||
} else if(tcurr-tlast<70.)
|
static int tpr = 0;
|
||||||
fprintf(stderr,"Send command \"Stop ADC%d\" to PEP-%s.\n",nch,pep);
|
if(tcurr-tpr>600.) {
|
||||||
fflush(stderr);
|
if(PEP_R_Off) {
|
||||||
}
|
print_date(stderr);
|
||||||
#endif
|
fprintf(stderr,"PEP-RK (ADC0/1/7) turned off!\n");
|
||||||
if(stop_prog) can_exit(0);
|
}
|
||||||
start=0;
|
if(PEP_A_Off) {
|
||||||
tok = tcurr;
|
print_date(stderr);
|
||||||
}
|
fprintf(stderr,"PEP-A (ADC4) turned off!\n");
|
||||||
} else {
|
}
|
||||||
if(stop_prog) can_exit(0);
|
tpr=tcurr;
|
||||||
else {
|
}
|
||||||
static int tpr = 0;
|
if(PEP_R_Off) {
|
||||||
if(tcurr-tpr>600.) {
|
if((MeteoMode & NET_T2)==0)
|
||||||
if(PEP_R_Off) {
|
MeteoMode &= ~SENSOR_T2;
|
||||||
print_date(stderr);
|
}
|
||||||
fprintf(stderr,"PEP-RK (ADC0/1/7) turned off!\n");
|
|
||||||
}
|
}
|
||||||
if(PEP_A_Off) {
|
}
|
||||||
print_date(stderr);
|
while(can_recv_frame(&rxpnt, &rxtime, &idr, &dlen, rdata)) {
|
||||||
fprintf(stderr,"PEP-A (ADC4) turned off!\n");
|
int rcode = 0;
|
||||||
|
t = rxtime;
|
||||||
|
if((idr&0xff8)==0x220) { /* ËÏÄ ÏÔ áãð PEP-RK */
|
||||||
|
static double T2 = 0.;
|
||||||
|
static int terr=0;
|
||||||
|
int chan, code;
|
||||||
|
double volt,T,b,w,h;
|
||||||
|
adc_pep_rk:
|
||||||
|
if(dlen!=3) {
|
||||||
|
static double last_print = 0.;
|
||||||
|
wrong_frame:
|
||||||
|
if(tcurr-last_print > 60.) {
|
||||||
|
print_date(stderr);
|
||||||
|
fprintf(stderr,"Wrong CAN-frame id=0x%x len=%d < ",idr,dlen);
|
||||||
|
for(i=0; i<dlen; i++) fprintf(stderr,"%02x ",rdata[i]);
|
||||||
|
fprintf(stderr,">\n");
|
||||||
|
fflush(stderr);
|
||||||
|
last_print = tcurr;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
chan = idr&7;
|
||||||
|
code = (unsigned int)rdata[0]<<8|rdata[1];
|
||||||
|
volt = (double)code/4096.*5.; /* ADC 12bit 0-5V */
|
||||||
|
if(chan == 1){ /* áãð1 - T-ÐÏÄËÕÐÏÌØÎÏÇÏ */
|
||||||
|
T = zeroT2 + (volt-zeroV)*scaleT;
|
||||||
|
/*t2=T;*/
|
||||||
|
if(T >= -20. && T <= 30.) {
|
||||||
|
if((MeteoMode & SENSOR_T2) && fabs(T2-T)<5.) {
|
||||||
|
if(fabs(T2-T)>0.1)
|
||||||
|
T2 += (T2>T)? -0.005 : 0.005;
|
||||||
|
else
|
||||||
|
T2 = 0.9*T2 + 0.1*T;
|
||||||
|
} else {
|
||||||
|
T2=T;
|
||||||
|
MeteoMode |= SENSOR_T2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
terr |= 2;
|
||||||
|
if(T<-20.) T2=-20.;
|
||||||
|
else if(T>30.) T2=30.;
|
||||||
|
MeteoMode &= ~SENSOR_T2;
|
||||||
|
}
|
||||||
|
if((MeteoMode & INPUT_T2)== 0 && (MeteoMode & SENSOR_T2))
|
||||||
|
val_T2 = T2;
|
||||||
|
//printf("Get T=%.1f\n", T2);
|
||||||
|
tok = t;
|
||||||
|
}
|
||||||
|
tok = tlast = t;
|
||||||
|
}else if(idr==0x21){ /* ÐÒÉÎÑÔ ËÏÄ RK ÏÔ PEP-ËÏÎÔÒÏÌÌÅÒÁ */
|
||||||
|
static double off_time = 0.;
|
||||||
|
static double last_msg_time = 0.;
|
||||||
|
static char msg[30] = " ôÕÍÁÎ ÉÌÉ ÏÓÁÄËÉ.";
|
||||||
|
static int o_rcode = 0;
|
||||||
|
rcode = ((unsigned int)rdata[0]<<16)|((unsigned int)rdata[1]<<8)|rdata[2];
|
||||||
|
if(rcode & RK_Precipitations){
|
||||||
|
if(o_rcode & RK_Precipitations){ // ÄÁÔÞÉË ÏÓÁÄËÏ× ÉÍÅÎÉ äÁÎÉÌÏ×Á ÎÁ ÍÅÔÅÏ-ÍÁÞÔÅ
|
||||||
|
if(fabs(M_time-Precip_time>60.)){ // ÄÁÔÞÉË ÏÓÁÄËÏ× ×ËÌÀÞÅÎ 2 ÓÞÉÔÙ×ÁÎÉÑ ÐÏÄÒÑÄ
|
||||||
|
if(Tel_State!=Stopping && Dome_State!=D_Off && fabs(M_time-last_msg_time>30.)){ // ÒÅÁÇÉÒÏ×ÁÔØ ÎÁ ÎÅÇÏ ÎÅ ÞÁÝÅ ÒÁÚÁ × ÍÉÎÕÔÕ
|
||||||
|
*msg = MesgFault; // ×ÙÄÁÔØ ÓÏÏÂÝÅÎÉÅ ÅÓÌÉ ÉÄÕÔ ÒÅÁÌØÎÙÅ ÎÁÂÌÀÄÅÎÉÑ
|
||||||
|
SendMessage(msg);
|
||||||
|
last_msg_time = M_time;
|
||||||
|
}
|
||||||
|
if(fabs(M_time-off_time)>3.){ // ÐÏÓÔÏÑÎÎÏ ×ËÌÀÞÅÎ ÍÉÎÉÍÕÍ 3ÓÅË
|
||||||
|
Precip_time = M_time; /* ÉÎÆÏÒÍÉÒÏ×ÁÔØ ÄÒÕÇÉÅ ÐÒÏÇÒÁÍÍÙ */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ // ÄÁÔÞÉË ÏÓÁÄËÏ× ÔÏÌØËÏ ÞÔÏ ×ËÌÀÞÉÌÓÑ
|
||||||
|
if(fabs(M_time-last_msg_time>600.)){ // ×ÙÄÁ×ÁÔØ ÓÏÏÂÝÅÎÉÅ ÒÁÚ × 10 ÍÉÎ
|
||||||
|
*msg = MesgWarn;
|
||||||
|
SendMessage(msg);
|
||||||
|
last_msg_time = M_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else off_time = M_time;
|
||||||
|
o_rcode = rcode;
|
||||||
}
|
}
|
||||||
tpr=tcurr;
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
if(PEP_R_Off) {
|
if(stop_prog) can_exit(0);
|
||||||
if((MeteoMode & NET_T2)==0)
|
|
||||||
MeteoMode &= ~SENSOR_T2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(can_recv_frame(&rxpnt, &rxtime, &idr, &dlen, rdata)) {
|
|
||||||
int rcode = 0;
|
|
||||||
t = rxtime;
|
|
||||||
if(idr==0x447||idr==0x40f) {
|
|
||||||
pep = (idr==0x40f)? "A" : "RK";
|
|
||||||
if(rdata[0]==7) {
|
|
||||||
if(rdata[2] == 0 && rdata[3] == 0)
|
|
||||||
fprintf(stderr,"%s PEP-%s: Echo command \"Stop ADC%d\"\n", time2asc(rxtime-timezone),pep,rdata[1]);
|
|
||||||
else
|
|
||||||
fprintf(stderr,"%s PEP-%s: Echo command \"Start ADC%d\"\n", time2asc(rxtime-timezone),pep,rdata[1]);
|
|
||||||
} else if(rdata[0]==8) {
|
|
||||||
fprintf(stderr,"%s PEP-%s: Echo command \"Stop all ADC\"\n", time2asc(rxtime-timezone),pep);
|
|
||||||
start=0;
|
|
||||||
}
|
|
||||||
fflush(stderr);
|
|
||||||
} else if(idr==0x20c) { /* ×ÒÅÍÅÎÎÏ: ËÏÄ áãð4 PEP-A - ÄÁ×ÌÅÎÉÅ */
|
|
||||||
if(dlen!=3)
|
|
||||||
goto wrong_frame;
|
|
||||||
idr = 0x224; /* ×ÒÅÍÅÎÎÏ: ÉÍÉÔÁÃÉÑ áãð4 PEP-RK */
|
|
||||||
goto adc_pep_rk;
|
|
||||||
} else if((idr&0xff8)==0x220) { /* ËÏÄ ÏÔ áãð PEP-RK */
|
|
||||||
static double T2 = 0.;
|
|
||||||
static int ctm=0;
|
|
||||||
static int terr=0;
|
|
||||||
int chan, code;
|
|
||||||
double volt,T,b,w,h;
|
|
||||||
adc_pep_rk:
|
|
||||||
if(dlen!=3) {
|
|
||||||
static double last_print = 0.;
|
|
||||||
wrong_frame:
|
|
||||||
if(tcurr-last_print > 60.) {
|
|
||||||
print_date(stderr);
|
|
||||||
fprintf(stderr,"Wrong CAN-frame id=0x%x len=%d < ",idr,dlen);
|
|
||||||
for(i=0; i<dlen; i++) fprintf(stderr,"%02x ",rdata[i]);
|
|
||||||
fprintf(stderr,">\n");
|
|
||||||
fflush(stderr);
|
|
||||||
last_print = tcurr;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
chan = idr&7;
|
|
||||||
code = (unsigned int)rdata[0]<<8|rdata[1];
|
|
||||||
volt = (double)code/4096.*5.; /* ADC 12bit 0-5V */
|
|
||||||
if(chan == 1){ /* áãð1 - T-ÐÏÄËÕÐÏÌØÎÏÇÏ */
|
|
||||||
ctm |= 2; /* áãð1 - T-ÐÏÄËÕÐÏÌØÎÏÇÏ */
|
|
||||||
T = zeroT2 + (volt-zeroV)*scaleT;
|
|
||||||
/*t2=T;*/
|
|
||||||
if(T >= -20. && T <= 30.) {
|
|
||||||
if((MeteoMode & SENSOR_T2) && fabs(T2-T)<5.) {
|
|
||||||
if(fabs(T2-T)>0.1)
|
|
||||||
T2 += (T2>T)? -0.005 : 0.005;
|
|
||||||
else
|
|
||||||
T2 = 0.9*T2 + 0.1*T;
|
|
||||||
} else {
|
|
||||||
T2=T;
|
|
||||||
MeteoMode |= SENSOR_T2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
terr |= 2;
|
|
||||||
if(T<-20.) T2=-20.;
|
|
||||||
else if(T>30.) T2=30.;
|
|
||||||
MeteoMode &= ~SENSOR_T2;
|
|
||||||
}
|
|
||||||
if((MeteoMode & INPUT_T2)== 0 && (MeteoMode & SENSOR_T2))
|
|
||||||
val_T2 = T2;
|
|
||||||
//printf("Get T=%.1f\n", T2);
|
|
||||||
tok = t;
|
|
||||||
}
|
|
||||||
if(chan<3 && (ctm&0x93) == 0x93) { /* áãð-0,1,4,7 - Ok */
|
|
||||||
tok = t;
|
|
||||||
ctm=0;
|
|
||||||
}
|
|
||||||
tlast=t;
|
|
||||||
}else if(idr==0x21){ /* ÐÒÉÎÑÔ ËÏÄ RK ÏÔ PEP-ËÏÎÔÒÏÌÌÅÒÁ */
|
|
||||||
static double off_time = 0.;
|
|
||||||
static double last_msg_time = 0.;
|
|
||||||
static char msg[30] = " ôÕÍÁÎ ÉÌÉ ÏÓÁÄËÉ.";
|
|
||||||
static int o_rcode = 0;
|
|
||||||
rcode = ((unsigned int)rdata[0]<<16)|((unsigned int)rdata[1]<<8)|rdata[2];
|
|
||||||
if(rcode & RK_Precipitations){
|
|
||||||
if(o_rcode & RK_Precipitations){ // ÄÁÔÞÉË ÏÓÁÄËÏ× ÉÍÅÎÉ äÁÎÉÌÏ×Á ÎÁ ÍÅÔÅÏ-ÍÁÞÔÅ
|
|
||||||
if(fabs(M_time-Precip_time>60.)){ // ÄÁÔÞÉË ÏÓÁÄËÏ× ×ËÌÀÞÅÎ 2 ÓÞÉÔÙ×ÁÎÉÑ ÐÏÄÒÑÄ
|
|
||||||
if(Tel_State!=Stopping && Dome_State!=D_Off && fabs(M_time-last_msg_time>30.)){ // ÒÅÁÇÉÒÏ×ÁÔØ ÎÁ ÎÅÇÏ ÎÅ ÞÁÝÅ ÒÁÚÁ × ÍÉÎÕÔÕ
|
|
||||||
*msg = MesgFault; // ×ÙÄÁÔØ ÓÏÏÂÝÅÎÉÅ ÅÓÌÉ ÉÄÕÔ ÒÅÁÌØÎÙÅ ÎÁÂÌÀÄÅÎÉÑ
|
|
||||||
SendMessage(msg);
|
|
||||||
last_msg_time = M_time;
|
|
||||||
}
|
|
||||||
if(fabs(M_time-off_time)>3.){ // ÐÏÓÔÏÑÎÎÏ ×ËÌÀÞÅÎ ÍÉÎÉÍÕÍ 3ÓÅË
|
|
||||||
Precip_time = M_time; /* ÉÎÆÏÒÍÉÒÏ×ÁÔØ ÄÒÕÇÉÅ ÐÒÏÇÒÁÍÍÙ */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{ // ÄÁÔÞÉË ÏÓÁÄËÏ× ÔÏÌØËÏ ÞÔÏ ×ËÌÀÞÉÌÓÑ
|
|
||||||
if(fabs(M_time-last_msg_time>600.)){ // ×ÙÄÁ×ÁÔØ ÓÏÏÂÝÅÎÉÅ ÒÁÚ × 10 ÍÉÎ
|
|
||||||
*msg = MesgWarn;
|
|
||||||
SendMessage(msg);
|
|
||||||
last_msg_time = M_time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else off_time = M_time;
|
|
||||||
o_rcode = rcode;
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
if(stop_prog) can_exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user