Skip to content
Snippets Groups Projects
frontend_getpid.c 860 B
Newer Older
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

burneykb's avatar
burneykb committed
#include "frontend_getpid.h"
#include "pid_common.h"
burneykb's avatar
burneykb committed

/* Get a specified PID.
 *
 * Example:
 *
 * struct frontend_pid_data pid_data;
 * pid_data.pid = PITCH;
 * if (frontend_getpid(conn, &pid_data)) {
 * 		error
 * } else {
 * 		pid_data.p, pid_data.i, and pid_data.d are filled
 * }
 *
 * Returns 0 on success, 1 on error
 */
int frontend_getpid(
		struct backend_conn * conn, struct frontend_pid_data * pid_data) {
	char line[100];
	switch (pid_data->pid) {
		case PITCH :
			strncpy(line, "getpitchp\ngetpitchd\n\0", 21);
			strncpy(line, "getrollp\ngetrolld\n\0", 19);
			strncpy(line, "getyawp\ngetyawd\n\0", 17);
			break;
		default :
			return 1;
	}

	int size;
	if((size = ucart_backendWrite(conn, line)) < 0 ) {
		return 1;
	}

burneykb's avatar
burneykb committed
	return 0;