X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fsensor.c;h=c0c3ab1773664f2c5ed351660dbbe9fca4f4ae89;hb=1a5cb99a6e794b4d51815aad67a73ae3f3c5b659;hp=f58daa59140beb9b02e0b51a0e0868b7e721820e;hpb=0f827545e0eb6846608da4aaf4dc8047478070a4;p=matches%2FMCTX3420.git diff --git a/server/sensor.c b/server/sensor.c index f58daa5..c0c3ab1 100644 --- a/server/sensor.c +++ b/server/sensor.c @@ -11,14 +11,18 @@ /** Array of sensors, initialised by Sensor_Init **/ static Sensor g_sensors[NUMSENSORS]; //global to this file -static const char * g_sensor_names[] = {"analog_test0", "analog_test1", "digital_test0", "digital_test1"}; +const char * g_sensor_names[NUMSENSORS] = { + "analog_test0", "analog_test1", + "digital_test0", "digital_test1" +}; + /** * Read a data value from a sensor; block until value is read * @param sensor_id - The ID of the sensor * @param d - DataPoint to set * @returns NULL for digital sensors when data is unchanged, otherwise d */ -DataPoint * GetData(int sensor_id, DataPoint * d) +DataPoint * GetData(SensorId sensor_id, DataPoint * d) { // switch based on the sensor_id at the moment for testing; // might be able to just directly access ADC from sensor_id? @@ -104,9 +108,6 @@ void Init(Sensor * s, int id) } - - - /** * Run the main sensor polling loop * @param arg - Cast to Sensor* - Sensor that the thread will handle @@ -270,7 +271,7 @@ void Sensor_Handler(FCGIContext *context, char * params) if (status == STATUS_ERROR) { - FCGI_RejectJSON(context); + FCGI_RejectJSON(context, "Invalid input parameters"); return; } @@ -278,7 +279,10 @@ void Sensor_Handler(FCGIContext *context, char * params) { case DUMP: { - FCGI_PrintRaw("Content-type: text/plain\r\n\r\n"); + //Force download with content-disposition + FCGI_PrintRaw("Content-type: text/plain\r\n" + "Content-disposition: attachment;filename=%d.csv\r\n\r\n", + sensor->id); //CRITICAL SECTION pthread_mutex_lock(&(sensor->mutex)); fseek(sensor->file, 0, SEEK_SET); @@ -290,7 +294,7 @@ void Sensor_Handler(FCGIContext *context, char * params) { FCGI_PrintRaw("%f\t%f\n", buffer[i].time_stamp, buffer[i].value); } - + } while (amount_read == SENSOR_QUERYBUFSIZ); pthread_mutex_unlock(&(sensor->mutex));