Esempio n. 1
0
int 
parsebf(char *buf)
{
   double rainrate, raintot;

   if (!sumcheck(buf, SIZEBF)) {
      errlog(8, "Checksum failure for BF block.");
      return (-1);
   }
   rainrate = (xDtoint(buf[2]) * 100) + DDtoint(buf[1]);
   raintot = (xDtoint(buf[6]) * 100) + DDtoint(buf[5]);

   correct(rainrate, current_cal.rain_rate_mul, current_cal.rain_rate_offs);
   correct(raintot, current_cal.rain_tot_mul, current_cal.rain_tot_offs);

   pthread_mutex_lock(&current_obs_lock);
   if (raintot < current_obs.rain_tot) {
      current_obs.rtot_offset += current_obs.rain_tot;
   }
   pthread_mutex_unlock(&current_obs_lock);

   update(current_obs.rain_rate, rainrate, RAINRATE);
   update(current_obs.rain_tot, raintot, RAINTOT);

   errlog2(9, "Rain rate %g mm/hr, Rain tot %g mm", rainrate, raintot);
}
Esempio n. 2
0
int 
parseaf(char *buf)
{
   double baro, dewpt_in, dewpt_out;

   if (!sumcheck(buf, SIZEAF)) {
      errlog(8, "Checksum failure for AF block.");
      return (-1);
   }
   baro = DDtoint(buf[3]) + (DDtoint(buf[4]) * 100.0) + (xDtoint(buf[5]) * 10000.0);
   baro /= 10;

   dewpt_in = DDtoint(buf[7]);
   dewpt_out = DDtoint(buf[18]);

   correct(dewpt_in, current_cal.dp_in_mul, current_cal.dp_in_offs);
   correct(dewpt_out, current_cal.dp_out_mul, current_cal.dp_out_offs);
   correct(baro, current_cal.barometer_mul, current_cal.barometer_offs);

   update(current_obs.dp_in, dewpt_in, DEWIN);
   update(current_obs.dp_out, dewpt_out, DEWOUT);
   update(current_obs.barometer, baro, BARO);


   errlog1(9, "Barometer: %g mb", baro);
   errlog2(9, "Indoor dewpoint: %gC, Outdoor dewpoint: %gC", dewpt_in, dewpt_out);

}
Esempio n. 3
0
int 
parse9f(char *buf)
{
   double temp_in, temp_out;

   if (!sumcheck(buf, SIZE9F)) {
      errlog(8, "Checksum failure for 9F block.");
      return (-1);
   }
   temp_in = ((xDtoint(buf[2] & 0x07) * 100) + (DDtoint(buf[1]))) / 10;
   if (buf[2] & 0x08) {
      temp_in = -1.0 * temp_in;
   }
   temp_out = ((xDtoint(buf[17] & 0x07) * 100) + (DDtoint(buf[16]))) / 10;
   if (buf[17] & 0x08) {
      temp_out = -1.0 * temp_out;
   }

   if ((temp_out < -50.0) || (temp_in < -50.0)) return; /*Bad data*/

   correct(temp_in, current_cal.temp_in_mul, current_cal.temp_in_offs);
   correct(temp_out, current_cal.temp_out_mul, current_cal.temp_out_offs);

   update(current_obs.temp_in, temp_in, TEMPIN);
   update(current_obs.temp_out, temp_out, TEMPOUT);

   errlog2(9, "Indoor temp: %gC, Outdoor temp: %gC", temp_in, temp_out);
}
Esempio n. 4
0
int 
parse8f(char *buf)
{
   int hour, min, sec, day, mon;
   double hum_in, hum_out;
   if (!sumcheck(buf, SIZE8F)) {
      errlog(8, "Checksum failure for 8F block.");
      return (-1);
   }
   sec = DDtoint(buf[1]);
   min = DDtoint(buf[2]);
   hour = DDtoint(buf[3]);
   mon = xDtoint(buf[5]);
   day = DDtoint(buf[4]);
   hum_in = DDtoint(buf[8]);
   hum_out = DDtoint(buf[20]);

   current_obs.sec = sec;
   current_obs.min = min;
   current_obs.hour = hour;
   current_obs.month = mon;
   current_obs.day = day;

   correct(hum_in, current_cal.rh_in_mul, current_cal.rh_in_offs);
   correct(hum_out, current_cal.rh_out_mul, current_cal.rh_out_offs);

   update(current_obs.rh_in, hum_in, HUMIN);
   update(current_obs.rh_out, hum_out, HUMOUT);

   errlog5(9, "%s %d %.2d:%.2d:%.2d", month[mon], day, hour, min, sec);
   errlog2(9, "Indoor hum: %g%%, Outdoor hum: %g%%", hum_in, hum_out);
}
Esempio n. 5
0
int 
parsecf(char *buf)
{
   double gust, avg, chill, hum_out;
   double avg_dir, gust_dir;

   if (!sumcheck(buf, SIZECF)) {
      errlog(9, "Checksum failure for CF block.");
      return (-1);
   }
   gust = ((xDtoint(buf[2]) * 100) + DDtoint(buf[1])) / 10;
   gust_dir = (Dxtoint(buf[2])) + (DDtoint(buf[3]) * 10);

   avg = ((xDtoint(buf[5]) * 100) + DDtoint(buf[4])) / 10;
   avg_dir = (Dxtoint(buf[5])) + (DDtoint(buf[6]) * 10);

   chill = DDtoint(buf[16]);
   if (buf[21] & 0x20) {
      chill = -1.0 * chill;
   }

#if 0
   pthread_mutex_lock(&current_obs_lock);
   if (((chill - current_obs.temp_out) > 0.5) && (avg > 0 || gust > 0)) {
      chill = -1.0 * chill;
   }
   pthread_mutex_unlock(&current_obs_lock);
#endif

   correct(chill, current_cal.chill_mul, current_cal.chill_offs);
   correct(gust, current_cal.gust_spd_mul, current_cal.gust_spd_offs);

   correct(gust_dir, current_cal.gust_dir_mul, current_cal.gust_dir_offs);
   correct(avg_dir, current_cal.wavg_dir_mul, current_cal.wavg_dir_offs);

   gust_dir = (gust_dir < 0) ? 360 + ((int) gust_dir % 360) : (int) gust_dir % 360;

   correct(avg, current_cal.wavg_spd_mul, current_cal.wavg_spd_offs);
   avg_dir = (avg_dir < 0) ? 360 + ((int) avg_dir % 360) : (int) avg_dir % 360;


   update(current_obs.gust, gust, GUST);
   update(current_obs.wavg, avg, WAVG);
   update(current_obs.gust_dir, gust_dir, GUSTDIR);
   update(current_obs.wavg_dir, avg_dir, WAVGDIR);
   update(current_obs.chill, chill, WCHILL);

   errlog2(9, "Wind gust %g m/s, direction: %g", gust, gust_dir);
   errlog2(9, "Wind avg  %g m/s, direction: %g", avg, avg_dir);
   errlog1(9, "Wind chill %g C", chill);
}
Esempio n. 6
0
int main(int argc, char *argv[])
{



    // ASCII header
    printf("    [===============================================]\r\n");
    printf("    |    FLYSKY FS-i6 CUSTOM FIRMWARE UPLOADER      |\r\n");
    printf("    |    by Thom				    |\r\n");
    printf("    | 					            |\r\n");
    printf("    |    check out my blog for more:		    |\r\n");
    printf("    |    basejunction.wordpress.com	            |\r\n");
    printf("    [===============================================]\r\n\r\n");
    printf("\n!!! Please make sure the firmware file comes from basejunction.wordpress.com !!!\n\n");

    HANDLE hdlr = NULL; //port handle
    int n_com=1;
    int n_baudrate=115200;

    char arg1[256],arg2[256],arg3[256],arg4[256],arg5[256];
    char cmd[256]="";

    if(argc>=2)
        n_com=(int)strtol(argv[1],NULL,10);
    if(argc>=3)
        n_baudrate=(int)strtol(argv[2],NULL,10);

    //init
    printf("Opening COM%d at %d bauds : ",n_com,n_baudrate);
    if(openCom(n_com,n_baudrate,&hdlr))
        printf("SUCCESS");
    else
        printf("FAILED - verify your COM port number and baudrate settings");
    printf("\n\n");



    //main loop
    do
    {

        printf(">> ");
        fgets(cmd, sizeof(cmd), stdin);

        sscanf(cmd,"%s %s %s %s %s",arg1,arg2,arg3,arg4,arg5);



        if(!strcmp(arg1,"help")|| !strcmp(arg1,"h"))
        {
            printf("-- open [port] [baudrate] : open com port number [port] at [baudrate] bauds\n");
            printf("-- readb : read byte \n");
            printf("-- readf : read frame \n");
            printf("-- sendb [format] [byte] : send [byte] with [format{-b,-d,-h}]\n");
            printf("-- write [filename] [offset:h] [nbytes:d] : write [nbytes](decimal) bytes page at [offset](hex)\n");
            printf("-- flash [filename] : program [filename] firmware into TX flash memory (bootloader untouched)\n");
            printf("-- ping : send a ping request\n");
            printf("-- reset : send a reset TX request\n");
            printf("-- quit : quit the updater\n");

        }

        else if(!strcmp(arg1,"readb"))
        {
            unsigned char byte=0;
            if(readByte(&byte,&hdlr))
                printf("%x \n",byte);
            else
                printf("ERROR - reading byte from serial buffer\n");
        }
        else if(!strcmp(arg1,"readf"))
        {
            unsigned short size=0;
            unsigned short checksum=0;
            unsigned char frame[256];
            if(!readFramedbg(&size,&checksum,frame,&hdlr))
                printf("ERROR - reading frame from serial buffer\n");
            if(!sumcheck(frame,size))
                printf("ERROR - checksum mismatch\n");

        }
        else if(!strcmp(arg1,"sendb"))
        {
            unsigned char msg=0;
            if(!strcmp(arg2,"-h"))
                msg=(unsigned char)strtoul(arg3,NULL,16);
            if(!strcmp(arg2,"-d"))
                msg=(unsigned char)strtoul(arg3,NULL,10);
            if(!strcmp(arg2,"-b"))
                msg=(unsigned char)strtoul(arg3,NULL,2);
            printf("Sending byte: %d 0x%x\n",msg,msg);
            if(!sendByte(&msg,&hdlr))
                printf("ERROR - sending byte in serial buffer\n");
        }
        else if(!strcmp(arg1,"reset"))
        {
            printf("reset . . . \n");
            unsigned char msg[]={0x06,0x00,0xC1,0x00,0xFF,0xFF};//38FF
            sendFrame(msg,sizeof(msg),&hdlr);
        }
        else if(!strcmp(arg1,"ping"))
        {
            unsigned char msg[]={0x05,0x00,0xC0,0x3A,0xFF};
            unsigned short size=0;
            unsigned short checksum=0;
            unsigned char frame[256];

            printf("ping . . . \n");
            sendFrame(msg,sizeof(msg),&hdlr);

            if(!readFrame(&size,&checksum,frame,&hdlr))
                printf("ERROR - reading frame from serial buffer\n");
            if(!sumcheck(frame,size))
                printf("ERROR - checksum mismatch\n");
            printf("\nConnected : FLYSKY i6 \nFirmware version : %d.%d \n",frame[6],frame[4]);
        }
        else if(!strcmp(arg1,"write"))
        {
            unsigned int offset=strtoul(arg3,NULL,16);
            unsigned char msg[256];
            if(!readPage(msg,arg2,offset,256))
                printf("ERROR - reading file\n");
            writePage(msg,sizeof(msg),offset,&hdlr);
        }
        else if(!strcmp(arg1,"flash"))
        {
            BOOL cont = TRUE;
            unsigned char msg[256];
            int i=0x1800;
            for(i=0x1800;(i<0xF300)&&cont;i=i+0x100)
            {
                //11 00 C2 00 18 00 09 00 00 00 00 00 00 00 00 0B FF
                unsigned char msg2[17]={0x11,0x00,0xC2,0xFF,0xFF,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
                unsigned short reply_size=0;
                unsigned short reply_checksum=0;
                unsigned char reply[19];
                //55 13 00 C2 80 00 18 00 09 00 00 00 00 00 00 00 00 34 FE

                msg2[3]=(unsigned char)i;
                msg2[4]=(unsigned char)(i>>8);
                sendFrame(msg2,sizeof(msg2),&hdlr);

                unsigned char ok_reply[19]={0x55,0x13,0x00,0xC2,0x80,0xFF,0xFF,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
                ok_reply[5]=(unsigned char)i;
                ok_reply[6]=(unsigned char)(i>>8);


                unsigned int checksum=0xFFFF;
                int j=0;
                for(j=0;j<19-2;j++)
                {
                    checksum=checksum-ok_reply[j];
                }

                ok_reply[19-2]=(unsigned char)checksum;
                ok_reply[19-1]=(unsigned char)(checksum>>8);


                readFrame(&reply_size,&reply_checksum,reply,&hdlr);

                unsigned char reply_s[19];
                memcpy(reply_s,reply,reply_size);

                // compare received reply with correct one
                if(memcmp(reply_s,ok_reply,sizeof(reply_s))!=0)
                {
                    printf("ERROR - bad reply from TX\n");
                    cont=FALSE;
                }

                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
                i=i+0x100;
                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
                i=i+0x100;
                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
                i=i+0x100;
                if(!readPage(msg,arg2,i,256))
                {
                    printf("ERROR - reading file\n");
                    cont=FALSE;
                }
                writePage(msg,sizeof(msg),i,&hdlr);
            }
            //reset
            if(cont)
            {
                printf("Reset . . .\n");
                unsigned char msg3[]={0x06,0x00,0xC1,0x00,0xFF,0xFF};//38FF
                sendFrame(msg3,sizeof(msg3),&hdlr);
            }

        }

        else if(!strcmp(arg1,"open"))
        {
            closeCom(&hdlr);
            unsigned int n_com=strtoul(arg2,NULL,10);
            unsigned int n_baudrate=strtoul(arg3,NULL,10);
            printf("Opening COM%d at %d bauds : ",n_com,n_baudrate);
            if(openCom(n_com,n_baudrate,&hdlr))
                printf("SUCCESS");
            else
                printf("FAILED - verify your COM port number and baudrate settings");
            printf("\n\n");
        }

        else if(strcmp(arg1,"quit"))
        {
            printf("-- Unknown command \"%s\"\n",arg1);
            printf("-- Type \"help\" for a command list\n");
        }
    }while(strcmp(arg1,"quit"));