Skip to content

Commit

Permalink
Updated to be compatible with Firmware 5.88 (indilib#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmneo authored Jan 3, 2023
1 parent 78258ec commit f1d3af5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
28 changes: 25 additions & 3 deletions indi-aagcloudwatcher-ng/CloudWatcherController_ng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)
int internalSupplyVoltage[NUMBER_OF_READS] = {0};
int ambientTemperature[NUMBER_OF_READS] = {0};
int ldrValue[NUMBER_OF_READS] = {0};
int ldrFreqValue[NUMBER_OF_READS] = {0};
int rainSensorTemperature[NUMBER_OF_READS] = {0};
int windSpeed[NUMBER_OF_READS] = {0};
int humidity[NUMBER_OF_READS] = {0};
Expand Down Expand Up @@ -162,7 +163,7 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)
return false;
}

check = getValues(&internalSupplyVoltage[i], &ambientTemperature[i], &ldrValue[i], &rainSensorTemperature[i]);
check = getValues(&internalSupplyVoltage[i], &ambientTemperature[i], &ldrValue[i], &ldrFreqValue[i], &rainSensorTemperature[i]);

if (!check)
{
Expand Down Expand Up @@ -215,6 +216,7 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)
cwd->supply = aggregateInts(internalSupplyVoltage, NUMBER_OF_READS);
cwd->ambient = aggregateInts(ambientTemperature, NUMBER_OF_READS);
cwd->ldr = aggregateInts(ldrValue, NUMBER_OF_READS);
cwd->ldrFreq = aggregateInts(ldrFreqValue, NUMBER_OF_READS);
cwd->rainTemperature = aggregateInts(rainSensorTemperature, NUMBER_OF_READS);
cwd->windSpeed = aggregateInts(windSpeed, NUMBER_OF_READS);
if (m_FirmwareVersion >= 5.6)
Expand Down Expand Up @@ -739,7 +741,7 @@ bool CloudWatcherController::getPressure(int *pressure)
return true;
}

bool CloudWatcherController::getValues(int *internalSupplyVoltage, int *ambientTemperature, int *ldrValue,
bool CloudWatcherController::getValues(int *internalSupplyVoltage, int *ambientTemperature, int *ldrValue, int *ldrFreqValue,
int *rainSensorTemperature)
{
sendCloudwatcherCommand("C!");
Expand All @@ -748,8 +750,27 @@ bool CloudWatcherController::getValues(int *internalSupplyVoltage, int *ambientT
int ambTemp = -10000;
int ldrRes;
int rainSensTemp;
int ldrFreq = -10000;

if (m_FirmwareVersion >= 3)
if (m_FirmwareVersion >= 5.88)
{
char inputBuffer[BLOCK_SIZE * 4];

int r = getCloudWatcherAnswer(inputBuffer, 5);

if (!r)
{
return false;
}

int res = sscanf(inputBuffer, "!6 %d!4 %d!8 %d!5 %d", &zenerV, &ldrRes, &ldrFreq, &rainSensTemp);

if (res != 4)
{
return false;
}
}
else if (m_FirmwareVersion >= 3)
{
char inputBuffer[BLOCK_SIZE * 4];

Expand Down Expand Up @@ -791,6 +812,7 @@ bool CloudWatcherController::getValues(int *internalSupplyVoltage, int *ambientT
*ambientTemperature = ambTemp;
*ldrValue = ldrRes;
*rainSensorTemperature = rainSensTemp;
*ldrFreqValue = ldrFreq;

return true;
}
Expand Down
6 changes: 4 additions & 2 deletions indi-aagcloudwatcher-ng/CloudWatcherController_ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct CloudWatcherData
int rainHeater; ///< PWM Duty Cycle
int rainTemperature; ///< Rain sensor temperature (used as ambient temperature in models where there is no ambient temperature sensor)
int ldr; ///< Ambient light sensor
int ldrFreq; ///< Ambient light sensor in K
float readCycle; ///< Time used in the readings
int totalReadings; ///< Total number of readings taken by the Cloud Watcher Controller
int internalErrors; ///< Total number of internal errors
Expand Down Expand Up @@ -372,11 +373,12 @@ class CloudWatcherController
* and Rain Sensor Temperature values of the AAG Cloud Watcher
* @param internalSupplyVoltage where the sensor value will be stored
* @param ambientTemperature where the sensor value will be stored
* @param ldrValue where the sensor value will be stored
* @param ldrValue where the sensor value will be
* @param ldrFreqValue where the sensor value in K will be stored, if Firmware >= 5.88
* @param rainSensorTemperature where the sensor value will be stored
* @return true if succesfully read. false otherwise.
*/
bool getValues(int *internalSupplyVoltage, int *ambientTemperature, int *ldrValue, int *rainSensorTemperature);
bool getValues(int *internalSupplyVoltage, int *ambientTemperature, int *ldrValue, int *ldrFreqValue, int *rainSensorTemperature);

/**
* Reads the current PWM Duty Cycle value of the AAG Cloud Watcher
Expand Down
40 changes: 30 additions & 10 deletions indi-aagcloudwatcher-ng/indi_aagcloudwatcher_ng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ bool AAGCloudWatcher::Handshake()
LOG_INFO("Connected to AAG Cloud Watcher");
sendConstants();

if (m_FirmwareVersion >= 5.6)
if (m_FirmwareVersion >= 5.6) {
addParameter("WEATHER_HUMIDITY", "Relative Humidity (%)", 0, 100, 10);
setCriticalParameter("WEATHER_HUMIDITY");
}

return true;
}
else
Expand Down Expand Up @@ -99,6 +102,7 @@ bool AAGCloudWatcher::initProperties()
setCriticalParameter("WEATHER_WIND_SPEED");
setCriticalParameter("WEATHER_RAIN");
setCriticalParameter("WEATHER_CLOUD");


addDebugControl();

Expand Down Expand Up @@ -592,6 +596,7 @@ bool AAGCloudWatcher::sendData()
nvp->np[RAW_SENSOR_RAIN_HEATER].value = data.rainHeater;
nvp->np[RAW_SENSOR_RAIN_TEMPERATURE].value = data.rainTemperature;
nvp->np[RAW_SENSOR_LDR].value = data.ldr;
nvp->np[RAW_SENSOR_LDR_FREQ].value = data.ldrFreq;
nvp->np[RAW_SENSOR_READ_CYCLES].value = data.readCycle;
lastReadPeriod = data.readCycle;
nvp->np[RAW_SENSOR_WIND_SPEED].value = data.windSpeed;
Expand Down Expand Up @@ -638,21 +643,36 @@ bool AAGCloudWatcher::sendData()
rainSensorHeater = 100.0 * rainSensorHeater / 1023.0;
nvpS->np[SENSOR_RAIN_SENSOR_HEATER].value = rainSensorHeater;

float ambientLight = float(data.ldr);
if (ambientLight > 1022.0)
{
ambientLight = 1022.0;

INumberVectorProperty *nvpSqmLimit = getNumber("sqmLimit");
float sqmLimit = getNumberValueFromVector(nvpSqmLimit, "sqmLimit");

float ambientTemperature = data.ambient;

float ambientLight;
if( data.ldrFreq >= 0 ) {
double sqm = ( 250000.0 / double(data.ldrFreq) );

sqm = sqmLimit - 2.5 * log10( sqm );

ambientLight = float( sqm );
}
if (ambientLight < 1)
{
ambientLight = 1.0;
else {
ambientLight = float(data.ldr);
if (ambientLight > 1022.0)
{
ambientLight = 1022.0;
}
if (ambientLight < 1)
{
ambientLight = 1.0;
}
ambientLight = constants.ldrPullUpResistance / ((1023.0 / ambientLight) - 1.0);
}
ambientLight = constants.ldrPullUpResistance / ((1023.0 / ambientLight) - 1.0);
nvpS->np[SENSOR_BRIGHTNESS_SENSOR].value = ambientLight;

setParameterValue("WEATHER_BRIGHTNESS", ambientLight);

float ambientTemperature = data.ambient;

if (ambientTemperature == -10000)
{
Expand Down
3 changes: 2 additions & 1 deletion indi-aagcloudwatcher-ng/indi_aagcloudwatcher_ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ class AAGCloudWatcher : public INDI::Weather
RAW_SENSOR_RAIN_HEATER,
RAW_SENSOR_RAIN_TEMPERATURE,
RAW_SENSOR_LDR,
RAW_SENSOR_LDR_FREQ,
RAW_SENSOR_READ_CYCLES,
RAW_SENSOR_WIND_SPEED,
RAW_SENSOR_RELATIVE_HUMIDITY,
RAW_SENSOR_PRESSURE,
RAW_SENSOR_TOTAL_READINGS
};

enum
enum
{
SENSOR_INFRARED_SKY, //skyTemperature
SENSOR_CORRECTED_INFRARED_SKY, //correctedTemperature
Expand Down
6 changes: 5 additions & 1 deletion indi-aagcloudwatcher-ng/indi_aagcloudwatcher_ng_sk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<defNumber name="k5" label="K5" format="%.0f" min="-999" max="999" step="0">100</defNumber>
</defNumberVector>

<defNumberVector device="AAG Cloud Watcher NG" name="sqmLimit" label="SQM Limit" group="Options" state="Idle" perm="rw" timeout="0">
<defNumber name="sqmLimit" label="SQM Limit" format="%.2f" min="0" max="30" step="0">19</defNumber>
</defNumberVector>

<defSwitchVector device="AAG Cloud Watcher NG" name="anemometerType" label="Anemometer Type" group="Options" state="Idle" perm="rw" rule="OneOfMany" timeout="0">
<defSwitch name="GRAY" label="Gray (old)">Off</defSwitch>
Expand All @@ -22,7 +25,7 @@
<defNumber name="rainSensor" label="Rain Sensor (cycles)" format="%.0f" min="0" max="100000" step="0">0</defNumber>
<defNumber name="rainSensorTemperature" label="Rain Sensor Temperature (ºC)" format="%.1f" min="-50" max="100" step="0">0</defNumber>
<defNumber name="rainSensorHeater" label="Rain Sensor Heater (%)" format="%.1f" min="0" max="100" step="0">0</defNumber>
<defNumber name="brightnessSensor" label="Brightness Sensor (K)" format="%.0f" min="0" max="1000000" step="0">0</defNumber>
<defNumber name="brightnessSensor" label="Brightness Sensor (K)" format="%.2f" min="0" max="1000000" step="0">0</defNumber>
<defNumber name="ambientTemperatureSensor" label="Ambient Temp. Sensor (ºC)" format="%.1f" min="-50" max="100" step="0">0</defNumber>
<defNumber name="windSpeed" label="Wind Speed (Km/H)" format="%.0f" min="0" max="1000" step="0">0</defNumber>
<defNumber name="humidity" label="Relative Humidity (%)" format="%.1f" min="0" max="100" step="0">0</defNumber>
Expand Down Expand Up @@ -71,6 +74,7 @@
<defNumber name="rainHeater" label="Rain Heater" format="%f" min="-1" max="1023" step="0">0</defNumber>
<defNumber name="rainTemp" label="Rain Temp." format="%.1f" min="-200000" max="200000" step="0">0</defNumber>
<defNumber name="LDR" label="LDR" format="%.1f" min="0" max="1000000" step="0">0</defNumber>
<defNumber name="ldrFreq" label="LDR frequency" format="%.1f" min="0" max="1000000" step="0">0</defNumber>
<defNumber name="readCycle" label="Read Cycle (s)" format="%.3f" min="-200000" max="200000" step="0">0</defNumber>
<defNumber name="windSpeed" label="Wind Speed" format="%.0f" min="0" max="20000000" step="0">0</defNumber>
<defNumber name="humidity" label="Relative Humidity" format="%.1f" min="0" max="100" step="0">0</defNumber>
Expand Down
1 change: 1 addition & 0 deletions indi-aagcloudwatcher-ng/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int /*argc*/, char ** /*argv*/)
std::cout << "Supply: " << cwd.supply << "\n";
std::cout << "Ambient: " << cwd.ambient << "\n";
std::cout << "LDR: " << cwd.ldr << "\n";
std::cout << "LDR Freq: " << cwd.ldrFreq << "\n";
std::cout << "Rain Temperature: " << cwd.rainTemperature << "\n";
std::cout << "Read Cycle: " << cwd.readCycle << "\n";
std::cout << "Wind Speed: " << cwd.windSpeed << "\n";
Expand Down

0 comments on commit f1d3af5

Please sign in to comment.