diff options
Diffstat (limited to 'controller.c')
-rw-r--r-- | controller.c | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/controller.c b/controller.c index 6efcb7e..a95d82b 100644 --- a/controller.c +++ b/controller.c @@ -1,19 +1,73 @@ #include "lib/controller.h" +#include "lib/common.h" + +typedef struct { + int id; + + char* task; + size_t task_size; +} task_t; + +task_t* tasks; + +const size_t TASKS = 100; +const long double A = -5; +const long double B = 10; +const long double EPS = 1e-3; + +void divide_and_yield_tasks() { + tasks = calloc(TASKS, sizeof(*tasks)); + long double delta = (B - A) / TASKS; + for (size_t i = 0; i < TASKS; i++) { + tasks[i].task = calloc(3, sizeof(long double)); + long double* args = (long double*) tasks[i].task; + + args[0] = A + delta * i; + args[1] = A + delta * (i + 1); + args[2] = EPS; + + tasks[i].task_size = 3 * sizeof(long double); + + tasks[i].id = controller_yield_task(tasks[i].task, tasks[i].task_size); + printf("%d task id\n", tasks[i].id); + } +} + +void combine_results_and_print() { + long double sum = 0; + + size_t cnt = 0; + while (cnt < TASKS) { + const char* res; + size_t sz; + printf("%lu taskid %d\n", cnt, controller_get_result(&res, &sz)); + + if (sz == 0) { + printf("fuck\n"); + break; + } + + const long double* resp = (const long double*) res; + printf("%lu %.10Lf\n", cnt, *resp); + sum += *resp; + cnt++; + } + + printf("%.10Lf\n", sum); +} int32_t main() { controller_init("127.0.0.1", "33554", 1, 4); + configure_timeout(100); controller_start(); - printf("%d\n", controller_yield_task("test", 4)); - printf("%d\n", controller_yield_task("task", 4)); + divide_and_yield_tasks(); controller_wait(); - const char* c; - size_t sz; - printf("%d\n", controller_get_result(&c, &sz)); - printf("%d\n", controller_get_result(&c, &sz)); + combine_results_and_print(); + printf("expected:\n313064450.892857\n"); controller_finish(); - printf("OK\n"); + return 0; } |