X13.Periphery.TWIDriver.BMP180.Recv C# (CSharp) Method

Recv() public method

public Recv ( byte buf ) : bool
buf byte
return bool
      public override bool Recv(byte[] buf) {
        if(buf[0]==ADDR) {
          if(buf[1]==0x10) {
            if(_st==-1 && buf.Length==26) {
              _pt=DateTime.Now;
              _st=0;
              _ac1=(short)((buf[4]<<8) | buf[5]);
              _ac2=(short)((buf[6]<<8) | buf[7]);
              _ac3=(short)((buf[8]<<8) | buf[9]);
              _ac4=(ushort)((buf[10]<<8) | buf[11]);
              _ac5=(ushort)((buf[12]<<8) | buf[13]);
              _ac6=(ushort)((buf[14]<<8) | buf[15]);
              _b1=(short)((buf[16]<<8) | buf[17]);
              _b2=(short)((buf[18]<<8) | buf[19]);
              _mb=(short)((buf[20]<<8) | buf[21]);
              _mc=(short)((buf[22]<<8) | buf[23]);
              _md=(short)((buf[24]<<8) | buf[25]);
            } else if((_st==2 || _st==3) && buf.Length==6) {
              _ut=(buf[4]<<8) | buf[5];
              _pt=DateTime.Now.AddMilliseconds(-1);
              _st++;
            } else if(_st==5 && buf.Length==7) {
              // Calculate temperature
              int x1 = (((int)_ut - _ac6) * _ac5) >> 15;
              int x2 = (_mc << 11) / (x1 + _md);
              int b5 = x1 + x2;
              _T.value=Math.Round((b5 + 8)/160.0, 2);

              int up=((buf[4]<<16) | (buf[5]<<8) | buf[6])>>(8-BMP180_OSS);
              int b6 = b5 - 4000;
              //  calculate B3
              x1 = (b6 * b6)>>12;
              x1 *= _b2;
              x1 >>= 11;
              x2 = _ac2 * b6;
              x2 >>= 11;
              int x3 = x1 + x2;
              int b3 = (((_ac1 * 4 + x3) << BMP180_OSS) + 2) >> 2;
              // calculate B4
              x1 = (_ac3 * b6) >> 13;
              x2 = (_b1 * ((b6*b6) >> 12)) >> 16;
              x3 = ((x1 + x2) + 2) >> 2;
              uint b4 = (_ac4 * (uint)(x3 + 32768)) >> 15;
              uint b7 = ((uint)(up - b3) * (50000>>BMP180_OSS));
              int p;
              if(b7 < 0x80000000) {
                p = (int)(b7*2/b4);
              } else {
                p = (int)(b7 / b4)*2;
              }
              x1 = (p >> 8);
              x1 *= x1;
              x1 = (x1 * 3038) >> 16;
              x2 = (p * -7357) >> 16;
              p += (x1 + x2 + 3791) >> 4;
              _P.value=p;

              _present.value=true;
              _pt=DateTime.Now.AddSeconds(_rand.Next(45, 75));
              _st=0;
            } else {
              _present.value=false;
              Reset();
            }
          } else {
            _present.value=false;
            if(TWIDriver._verbose) {
              Log.Error("{0}.recv - {1}", _T.path, (AckFlags)buf[1]);
            }
            _pt=DateTime.Now.AddSeconds(_rand.Next(135, 165));
            _st=0;
          }
          return true;
        }
        return false;
      }
      public override bool Poll(out byte[] buf) {