X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=server%2Fsensor.c;h=c0c3ab1773664f2c5ed351660dbbe9fca4f4ae89;hb=1a5cb99a6e794b4d51815aad67a73ae3f3c5b659;hp=2e0749e584b244cb9a14f932ef3c5d32558d504d;hpb=17d812fec1b76fb6042e10067e34eb296bc5280b;p=matches%2FMCTX3420.git diff --git a/server/sensor.c b/server/sensor.c index 2e0749e..c0c3ab1 100644 --- a/server/sensor.c +++ b/server/sensor.c @@ -1,10 +1,9 @@ /** * @file sensor.c - * @purpose Implementation of sensor thread + * @brief Implementation of sensor thread * TODO: Finalise implementation */ - #include "common.h" #include "sensor.h" #include "options.h" @@ -12,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? @@ -105,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 @@ -271,7 +271,7 @@ void Sensor_Handler(FCGIContext *context, char * params) if (status == STATUS_ERROR) { - FCGI_RejectJSON(context); + FCGI_RejectJSON(context, "Invalid input parameters"); return; } @@ -279,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); @@ -291,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));