#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_DEPRECATE #pragma warning(disable : 4115) #include "stdafx.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "phidget21.h" #include "def.h" #include "temp.h" #include "Dome.h" #include "com_port.h" #include "ExternDef.h" t_RG11Registers RG11Registers = {0}; #define RG11_REG_CNT (sizeof (RG11Registers) / sizeof (unsigned short)) #define RG11_RX_CHAR_SIZE 256 unsigned short RG11Index = 0; int RG11RxByteRead, RG11RxByte; int RG11InitStatus = -1, RG11RxStatus, RG11TxStatus, RG11StatusFail = COM_FAIL_MAX, RG11Handle = -1, RG11DataChange = 0; char *RG11RxData; void RG11Init(int Connect) { static int fpass = 1; if (fpass) { fpass = 0; RG11RxData = (char *)malloc(RG11_RX_CHAR_SIZE); if (RG11RxData == NULL) { printf("Could not allocate sufficient memory"); exit(1); } RG11ToDisk(); } // CCD cooling serial port setup ComPortHandler(&RG11Handle, COM_RG11, "RG11", &RG11InitStatus, &RG11StatusFail, Connect, COM_NO_BUFFERING, 1200); } void RG11Exit() { //if (RG11Handle >= 0) { Win32CloseComPort(RG11Handle); RG11Handle = -1; RG11RxStatus = RG11TxStatus = RG11StatusFail = COM_FAIL_MAX; } ComPortHandler(&RG11Handle, COM_RG11, "RG11", &RG11InitStatus, &RG11StatusFail, DEV_DISCONNECT, COM_NO_BUFFERING, 1200); } void RG11Comm() { // Supports Hydreon RG11 rain gauge: http://www.rainsensors.com/ // protocol derived from: http://www.rainsensors.com/docs/RG-11_12.ser char *ByteStr = "00\0"; if (RG11Handle >= 0) { RG11RxStatus = Win32ComRx(RG11Handle, RG11RxData, RG11_RX_CHAR_SIZE, &RG11RxByteRead); if ((RG11RxStatus == COM_SUCCESS) && RG11RxByteRead) { int i; RG11StatusFail = 0; for (i=0; i= 0) && (RegSlowIndex < 16)) { switch (RegSlowIndex) { case 0: if (RG11Registers.RevLevel != Byte) { RG11Registers.RevLevel = Byte; } break; case 1: if (RG11Registers.EmLevel != Byte) { RG11Registers.EmLevel = Byte; RG11DataChange = 1; } break; case 2: if (RG11Registers.RecEmStr != Byte) { RG11Registers.RecEmStr = Byte; RG11DataChange = 1; } break; case 3: if (RG11Registers.ABLevel != Byte) { RG11Registers.ABLevel = Byte; RG11DataChange = 0; } break; case 4: if (RG11Registers.TmprtrF != Byte) { RG11Registers.TmprtrF = Byte; RG11DataChange = 1; } break; case 5: if (RG11Registers.PUGain != Byte) { RG11Registers.PUGain = Byte; RG11DataChange = 0; } break; case 6: if (RG11Registers.ClearTR != Byte) { RG11Registers.ClearTR = Byte; RG11DataChange = 0; } break; case 7: if (RG11Registers.AmbLight != Byte) { RG11Registers.AmbLight = Byte; RG11DataChange = 0; } break; case 8: if (RG11Registers.Bucket != Byte) { RG11Registers.Bucket = Byte; RG11DataChange = 1; } break; case 9: if (RG11Registers.Barrel != Byte) { RG11Registers.Barrel = Byte; RG11DataChange = 0; } break; case 10: if (RG11Registers.RGConfig != Byte) { RG11Registers.RGConfig = Byte; RG11DataChange = 0; } break; case 11: if (RG11Registers.DwellT != Byte) { RG11Registers.DwellT = Byte; RG11DataChange = 1; } break; case 12: if (RG11Registers.SinceRn != Byte) { RG11Registers.SinceRn = Byte; RG11DataChange = 0; } break; case 13: if (RG11Registers.MonoStb != Byte) { RG11Registers.MonoStb = Byte; RG11DataChange = 0; } break; case 14: if (RG11Registers.LightAD != Byte) { RG11Registers.LightAD = Byte; RG11DataChange = 1; } break; case 15: if (RG11Registers.RainThr != Byte) { RG11Registers.RainThr = Byte; RG11DataChange = 0; } break; } } } RG11Index++; break; } NibblePosn =!NibblePosn; } } } } } void RG11ToDisk() { static int fpass = 1, IgnoreCount = RG11_REG_CNT; static char Str[STRING_BUF_SIZE], File[STRING_BUF_SIZE]; if (fpass) { fpass = 0; sprintf(Str, "Time_of_day,PeakRS,RainAD8,LRA,TransRat,PkOverThr,Raining,EmLevel,RecEmStr,TemperatureF_degC,BucketTipCount,DwellTime,LightAD\n"); Log(Str, DATA1_NEW); } else if (IgnoreCount > 0) IgnoreCount--; else { sprintf(Str, "%9.5f,%d,%d,%d,%d,%d,%d,%d,%d,%5.1f,%d,%d,%d\n", (float)GetDate(), (int)RG11Registers.PeakRS, (int)RG11Registers.RainAD8, (int)RG11Registers.LRA, (int)RG11Registers.TransRat, (int)RG11Registers.PkOverThr, (int)RG11Registers.Raining, (int)RG11Registers.EmLevel, (int)RG11Registers.RecEmStr, (((float)RG11Registers.TmprtrF-32.f)*5.f/9.f), (int)RG11Registers.Bucket, (int)RG11Registers.DwellT, (int)RG11Registers.LightAD); Log(Str, DATA1); } }