Skip to content
Snippets Groups Projects
frontend_setsetpoint.c 942 B
Newer Older
burneykb's avatar
burneykb committed
#include <err.h>
#include <stdio.h>

#include "frontend_setsetpoint.h"
#include "setpoint_common.h"
#include "frontend_common.h"

int frontend_setsetpoint(
		struct backend_conn * conn,
		struct frontend_setpoint_data * setpoint_data,
		int mask)
{
	if (conn == NULL) {
		return -1;
	}

	char buffer[2048];
	/* Set the P, I, and D */
	if (mask & SET_HEIGHT) {
burneykb's avatar
burneykb committed
		if (snprintf(buffer, 2048,
					"setheight %f\n",  
					setpoint_data->height) >= 2048) {
burneykb's avatar
burneykb committed
			errx(0, "Buffer to small to format!");
		}
		ucart_backendWrite(conn, buffer);
	}
	if (mask & SET_LAT) {
burneykb's avatar
burneykb committed
		if (snprintf(buffer, 2048,
					"setlat %f\n",
					setpoint_data->lat) >= 2048) {
burneykb's avatar
burneykb committed
			errx(0, "Buffer to small to format!");
		}
		ucart_backendWrite(conn, buffer);
	}
	if (mask & SET_LONG) {
burneykb's avatar
burneykb committed
		if (snprintf(buffer, 2048,
					"setlong %f\n",
					setpoint_data->longg) >= 2048) {
burneykb's avatar
burneykb committed
			errx(0, "Buffer to small to format!");
		}
		ucart_backendWrite(conn, buffer);
	}

	return 0;
}