X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fsensor.c;h=bfa8b66cae1ec2e6727faf46719d91137d14a004;hb=989a1d2ff5f5afc20f78738f57cc829ae9d11e99;hp=e429958168019beb5c8e90320e90efc9d30a41eb;hpb=a21a946c4358cdeb8228fef7a8031c1ad25d6dd1;p=matches%2FMCTX3420.git diff --git a/server/sensor.c b/server/sensor.c index e429958..bfa8b66 100644 --- a/server/sensor.c +++ b/server/sensor.c @@ -45,13 +45,13 @@ void Sensor_Init() Data_Init(&(g_sensors[i].data_file)); } - // Get the ADCs - ADC_Export(); + // Get the required ADCs + ADC_Export(0); // GPIO1_28 used as a pulse for sampling - GPIO_Export(GPIO1_28); + //GPIO_Export(GPIO1_28); // GPIO0_30 toggled during sampling - GPIO_Export(GPIO0_30); + //GPIO_Export(GPIO0_30); } /** @@ -144,13 +144,13 @@ void Sensor_CheckData(SensorId id, double value) { if( value > thresholds[id].max_error || value < thresholds[id].min_error) { - Log(LOGERR, "Sensor %s is above or below its safety value of %f or %f\n", g_sensor_names[id],thresholds[id].max_error, thresholds[id].min_error); + Log(LOGERR, "Sensor %s at %f is above or below its safety value of %f or %f\n", value, g_sensor_names[id],thresholds[id].max_error, thresholds[id].min_error); //new function that stops actuators? //Control_SetMode(CONTROL_EMERGENCY, NULL) } else if( value > thresholds[id].max_warn || value < thresholds[id].min_warn) { - Log(LOGWARN, "Sensor %s is above or below its warning value of %f or %f\n", g_sensor_names[id],thresholds[id].max_warn, thresholds[id].min_warn); + Log(LOGWARN, "Sensor %s at %f is above or below its warning value of %f or %f\n", value, g_sensor_names[id],thresholds[id].max_warn, thresholds[id].min_warn); } } @@ -175,16 +175,19 @@ bool Sensor_Read(Sensor * s, DataPoint * d) // Read value based on Sensor Id switch (s->id) { - case ANALOG_REALTEST: + case 2: { static bool set = false; - - GPIO_Set(GPIO0_30, true); - d->value = (double)ADC_Read(ADC0); //ADC #0 on the Beaglebone + int raw_adc = 0; + //GPIO_Set(GPIO0_30, true); + ADC_Read(ADC0, &raw_adc); + d->value = (double)raw_adc; //ADC #0 on the Beaglebone //Log(LOGDEBUG, "Got value %f from ADC0", d->value); - GPIO_Set(GPIO0_30, false); + //GPIO_Set(GPIO0_30, false); set = !set; - GPIO_Set(GPIO1_28, set); + //GPIO_Set(GPIO1_28, set); + + usleep(100000); break; } @@ -222,6 +225,7 @@ bool Sensor_Read(Sensor * s, DataPoint * d) break; case DIGITAL_REALTEST: { + d->value = 0; //d->value must be something... valgrind... // Can pass pin as argument, just using 20 as an example here // Although since pins will be fixed, can just define it here if we need to //d->value = pinRead(20); //Pin 20 on the Beaglebone @@ -249,6 +253,11 @@ bool Sensor_Read(Sensor * s, DataPoint * d) s->newest_data.time_stamp = d->time_stamp; s->newest_data.value = d->value; } + +#ifdef _BBB + //Not all cases have usleep, easiest here. + usleep(1000000); +#endif return result; }