X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Factuator.c;h=759fffca476ecefc846dd1d636e302ec211d694e;hb=235b49b220dfb282d009f8bcaab02be911e5c4d6;hp=9c21eb718eae8a639456601a1e119a49bf541b1f;hpb=19050f4340b649460080c5a3c4cd2e3a2de22ecc;p=matches%2FMCTX3420.git diff --git a/server/actuator.c b/server/actuator.c index 9c21eb7..759fffc 100644 --- a/server/actuator.c +++ b/server/actuator.c @@ -106,7 +106,7 @@ void * Actuator_Loop(void * arg) pthread_mutex_unlock(&(a->mutex)); if (!a->activated) break; - + Log(LOGDEBUG, "About to Setvalue"); Actuator_SetValue(a, a->control.value); } @@ -127,6 +127,7 @@ void Actuator_SetControl(Actuator * a, ActuatorControl * c) if (c != NULL) a->control = *c; a->control_changed = true; + Log(LOGDEBUG, "About to broadcast"); pthread_cond_broadcast(&(a->cond)); pthread_mutex_unlock(&(a->mutex)); @@ -144,23 +145,30 @@ void Actuator_SetValue(Actuator * a, double value) gettimeofday(&t, NULL); DataPoint d = {TIMEVAL_DIFF(t, g_options.start_time), value}; + Log(LOGDEBUG, "id: %d", a->id); //TODO: Set actuator switch (a->id) { - case ACTUATOR_TEST0: //LED actuator test code, should blink onboard LED next to Ethernet port - FILE *LEDHandle = NULL; //code reference: http://learnbuildshare.wordpress.com/2013/05/19/beaglebone-black-controlling-user-leds-using-c/ - char *LEDBrightness = "/sys/class/leds/beaglebone\:green\:usr0/brightness"; - if(value == 1) { - if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL) { - fwrite("1", sizeof(char), 1, LEDHandle); - fclose(LEDHandle); + case ACTUATOR_TEST0: + {//LED actuator test code, should blink onboard LED next to Ethernet port + FILE *LEDHandle = NULL; //code reference: http://learnbuildshare.wordpress.com/2013/05/19/beaglebone-black-controlling-user-leds-using-c/ + char *LEDBrightness = "/sys/class/leds/beaglebone:green:usr3/brightness"; + int val = (!!(int)value); + Log(LOGDEBUG, "Val: %d", val); + if(val == 1) { + if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL) { + fwrite("1", sizeof(char), 1, LEDHandle); + fclose(LEDHandle); + } else perror("fail"); + } + else if(val == 0) { + if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL) { + fwrite("0", sizeof(char), 1, LEDHandle); + fclose(LEDHandle); + } } - else if(value == 0) { - if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL) { - fwrite("0", sizeof(char), 1, LEDHandle); - fclose(LEDHandle); + else perror("Pin value should be 1 or 0"); } - else perror("Pin value should be 1 or 0"); break; case ACTUATOR_TEST1: break; @@ -172,6 +180,7 @@ void Actuator_SetValue(Actuator * a, double value) Data_Save(&(a->data_file), &d, 1); } + /** * Helper: Begin Actuator response in a given format * @param context - the FCGIContext @@ -233,7 +242,7 @@ void Actuator_Handler(FCGIContext * context, char * params) // key/value pairs FCGIValue values[] = { - {"id", &id, FCGI_REQUIRED(FCGI_LONG_T)}, + {"id", &id, FCGI_REQUIRED(FCGI_INT_T)}, {"set", &set, FCGI_DOUBLE_T}, {"start_time", &start_time, FCGI_DOUBLE_T}, {"end_time", &end_time, FCGI_DOUBLE_T},