Skip to content
Snippets Groups Projects
Commit 1b14a015 authored by dawehr's avatar dawehr
Browse files

Merge branch 'master' of git.ece.iastate.edu:danc/MicroCART_17-18

parents a7a9fe3d 25b3bf9d
No related branches found
No related tags found
No related merge requests found
Showing
with 248 additions and 66 deletions
......@@ -42,3 +42,10 @@ logs
BackEnd
obj
Cli
#symlinks
getpid
monitor
setpid
setsetpoint
getsetpoint
......@@ -23,7 +23,7 @@ CLIBINARY=Cli
CLISRCDIR=src/cli
CLISOURCES := $(wildcard $(CLISRCDIR)/*.c)
CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o)
SYMLINKS=monitor setpid getpid setsetpoint
SYMLINKS=monitor setpid getpid setsetpoint getsetpoint
# Frontend-common stuff
FESRCDIR=src/frontend
......
......@@ -195,7 +195,6 @@ int main(int argc, char **argv)
perror("Error creating log file...");
exit(1);
}
// writeStringToLog(logHeader);
// watch for input from stdin (fd 0) to see when it has input
safe_fd_set(fileno(stdin), &rfds_master, &max_fd);
......@@ -328,8 +327,8 @@ void sendVrpnPacket(struct ucart_vrpn_TrackerData *info) {
memcpy(&packet[11], &(info->y), 4);
memcpy(&packet[15], &(info->x), 4);
memcpy(&packet[19], &(info->z), 4);
memcpy(&packet[23], &(info->pitch), 4);
memcpy(&packet[27], &(info->roll), 4);
memcpy(&packet[23], &(info->roll), 4);
memcpy(&packet[27], &(info->pitch), 4);
memcpy(&packet[31], &(info->yaw), 4);
char checksum = 0;
......@@ -482,6 +481,9 @@ static ssize_t writeQuad(const char * buf, size_t count) {
static ssize_t readQuad(char * buf, size_t count) {
ssize_t retval;
if (getenv(NOQUAD_ENV)) {
return count;
}
if (pthread_mutex_lock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__);
}
......@@ -626,7 +628,7 @@ static void client_recv(int fd) {
if (tracker == NULL) {
char * dummy = TD_MAGIC " 1.0 2.0 3.0 4.0 5.0 6.0\n";
write(fd, dummy, strlen(dummy));
}else if (ucart_vrpn_tracker_getData(tracker, &td)) {
} else if (ucart_vrpn_tracker_getData(tracker, &td)) {
write(fd, TD_MAGIC " ERROR\n", strlen(TD_MAGIC " ERROR\n"));
} else {
/* more than sufficient buffer */
......@@ -651,17 +653,19 @@ static void client_recv(int fd) {
}
}
} else {
if(clientAddPendResponses(fd, packet) == -1) {
warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n");
} else {
int datalen = (packet[6] << 8) | (packet[5]);
printf("sending %lf '", getFloat(packet, 7));
for(int i = 0; i < datalen + 8; ++i) {
printf(" 0x%x", (signed) packet[i]);
if (packet[1] == 0x02) {
if (clientAddPendResponses(fd, packet) == -1) {
warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n");
}
printf("'\n");
writeQuad((char *) packet, datalen +8);
}
int datalen = (packet[6] << 8) | (packet[5]);
printf("sending %lf '", getFloat(packet, 7));
for(int i = 0; i < datalen + 8; ++i) {
printf(" 0x%.2x", (signed) packet[i]);
}
printf("'\n");
writeQuad((char *) packet, datalen +8);
}
char * rest = &buffer[newline] + 1;
......@@ -707,17 +711,23 @@ static void quad_recv() {
respBufLen = 0;
return;
}
/* Get datalen */
size_t datalen = metadata.data_len;
if (respBufLen < datalen + 8) {
/* Packet not yet fully read */
return;
}
if (datalen > CMD_MAX_LENGTH - 8) {
/* Very invalid packet. Nuke that shit */
warnx("data len is over the maximum packet length. Try reducing the data in the packet sent to the groundstation.\n");
respBufLen = 0;
return;
}
if (respBufLen < datalen + 8) {
/* Packet not yet fully read */
if(validPacket == -2) {
fprintf(stderr, "Checksums did not match (Parse Packet)\n");
return;
}
......@@ -726,10 +736,18 @@ static void quad_recv() {
char * cmdText = MessageTypes[(int)metadata.msg_type].subtypes[(int)metadata.msg_subtype].cmdText;
float value = getFloat((unsigned char *)respBuf, 7);
//printf("Quad : %s, %lf\n", cmdText, value);
/*
Assuming the quad sends the correct info.. This hasn't been tested yet due to a lack of
quad software. We can check how to format by the cmdText and pass to every client.
*/
if(strncmp(cmdText, "log", strlen(cmdText)) == 0) {
char log_text[datalen+1];
strncpy(log_text, (char *) data, datalen);
log_text[datalen] = '\0';
printf("log='%s'\n", log_text);
}
char buffer[1048];
sprintf(buffer, "%s %lf\n", cmdText, value);
......@@ -738,8 +756,6 @@ static void quad_recv() {
write(fd, buffer, datalen + 8);
}
}
} else {
warnx("Checksum mismatch!");
}
memmove(respBuf, respBuf + datalen + 8, respBufLen - (datalen + 8));
respBufLen -= datalen + 8;
......
#ifndef __callbacks_h
#define __callbacks_h
#ifndef __CALLBACKS_H
#define __CALLBACKS_H
/* Grab some stupid stuff from legacy code */
#include "type_def.h"
......@@ -8,4 +8,4 @@
typedef void (command_cb)(unsigned char *command,
int dataLen, modular_structs_t *structs);
#endif
#endif /* __CALLBACKS_H */
#ifndef __CB_DEFAULT_H
#define __CB_DEFAULT_H
#include "commands.h"
/* The cb_default used on the groundStation. This file MUST NOT BE INCLUDED
......@@ -8,3 +11,5 @@ int cb_default(unsigned char * command, int dataLen, modular_structs_t *structs)
{
return 0;
}
#endif /* __CB_DEFAULT_H */
\ No newline at end of file
#ifndef _COMMANDS_H
#define _COMMANDS_H
#ifndef __COMMANDS_H
#define __COMMANDS_H
#include <stdio.h>
#include <stdlib.h>
......@@ -48,4 +48,4 @@ float getFloat(unsigned char* str, int pos);
int getInt(unsigned char* str, int pos);
/* end legacy crap */
#endif
#endif /* __COMMANDS_H */
\ No newline at end of file
......@@ -177,7 +177,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
// Checksum
// receive data and calculate checksum
int i;
char data_checksum;
char data_checksum = 0;
for(i = 0; i < 7 + metadata->data_len; i++)
{
data_checksum ^= (*formattedCommand)[i];
......@@ -230,14 +230,13 @@ int parse_packet(unsigned char * packet, unsigned char ** data, metadata_t * met
// calculate checksum
unsigned char calculated_checksum = 0;
for(i = 0; i < meta_data->data_len + 7; i++)
for(i = 0; i < meta_data->data_len + 7 - 1; i++)
{
calculated_checksum ^= packet[i];
}
// compare checksum
if(packet_checksum != calculated_checksum) {
fprintf(stderr, "Checksums did not match (Parse Packet): 0x%02x\t0x%02x\n", packet_checksum, calculated_checksum);
return -2;
}
......
#ifndef _COMMUNICATION_H
#define _COMMUNICATION_H
#ifndef __COMMUNICATION_H
#define __COMMUNICATION_H
#include <stdio.h>
#include <string.h>
......@@ -16,4 +16,4 @@ int parse_packet(unsigned char * packet, unsigned char ** data, metadata_t * met
int processCommand(unsigned char *command, modular_structs_t *structs);
int logData(unsigned char *log_msg, unsigned char *formattedCommand);
#endif
\ No newline at end of file
#endif /* __COMMUNICATION_H */
\ No newline at end of file
......@@ -17,4 +17,4 @@
#define QUAD_PORT_ENV "UCART_QUAD_PORT"
#define QUAD_PORT_DEFAULT 8080
#endif
#endif /* __CONFIG_H */
\ No newline at end of file
......@@ -2,8 +2,8 @@
*
* Logger header file for holding info pertaining to loging to a file.
*/
#ifndef _LOGGER_H
#define _LOGGER_H
#ifndef __LOGGER_H
#define __LOGGER_H
#include <fcntl.h>
#include <time.h>
......@@ -18,4 +18,4 @@ int updateLogFile(const struct ucart_vrpn_TrackerData* );
void closeLogFile();
#endif
#endif /* __LOGGER_H */
\ No newline at end of file
......@@ -5,8 +5,8 @@
* Author: ucart
*/
#ifndef TYPE_DEF_H_
#define TYPE_DEF_H_
#ifndef __TYPE_DEF_H
#define __TYPE_DEF_H
/**
* @brief
......@@ -358,4 +358,4 @@ typedef struct {
//////// END MAIN MODULAR STRUCTS
#endif /* TYPE_DEF_H_ */
#endif /* __TYPE_DEF_H */
......@@ -76,6 +76,8 @@ int main(int argc, char **argv)
needCommandHelp = 1;
}
}
printf("made it\n");
/**
* I the user has asked for help, and we have already found
......
......@@ -2,6 +2,7 @@
#define __CLI_H
#include "cli_setsetpoint.h"
#include "cli_getsetpoint.h"
#include "cli_monitor.h"
#include "cli_setpid.h"
#include "cli_getpid.h"
......@@ -13,6 +14,7 @@ enum CommandNameIds{
CMD_SETPID,
CMD_GETIMU,
CMD_SETSETPOINT,
CMD_GETSETPOINT,
MAX_COMMANDS
};
......@@ -22,7 +24,8 @@ static cli_function_ptr cli_functions[] = {
&cli_getpid,
&cli_setpid,
&cli_getimu,
&cli_setsetpoint
&cli_setsetpoint,
&cli_getsetpoint
};
static char* commandNames[MAX_COMMANDS] = {
......@@ -30,7 +33,8 @@ static char* commandNames[MAX_COMMANDS] = {
"getpid",
"setpid",
"getimu",
"setsetpoint"
"setsetpoint",
"getsetpoint"
};
#endif
#endif /* __CLI_H */
\ No newline at end of file
#ifndef CLI_GETIMU_H
#define CLI_GETIMU_H
#ifndef __CLI_GETIMU_H
#define __CLI_GETIMU_H
#include "frontend_getimu.h"
int cli_getimu(struct backend_conn * conn, int argc, char ** argv);
#endif
\ No newline at end of file
#endif /* __CLI_GETIMU_H */
\ No newline at end of file
......@@ -62,62 +62,62 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) {
if(getAll) {
for(int i = 0; i < PID_NUM_PIDS; ++i) {
pid_data.controller = i;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
} else {
if(getPitch) {
pid_data.controller = PID_PITCH;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getRoll) {
pid_data.controller = PID_ROLL;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getYaw) {
pid_data.controller = PID_YAW;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getPitchV) {
pid_data.controller = PID_PITCH_RATE;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getRollV) {
pid_data.controller = PID_ROLL_RATE;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getYawV) {
pid_data.controller = PID_YAW_RATE;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getHeight) {
pid_data.controller = PID_HEIGHT;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getLat) {
pid_data.controller = PID_LAT;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
if(getLong) {
pid_data.controller = PID_LONG;
if ((result = getValues(conn, &pid_data))) {
if ((result = getPidValues(conn, &pid_data))) {
return result;
}
}
......@@ -127,7 +127,7 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) {
return 0;
}
int getValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) {
int getPidValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) {
if(frontend_getpid(conn, pid_data)) {
return 1;
}
......
#ifndef CLI_GETPID_H
#define CLI_GETPID_H
#ifndef __CLI_GETPID_H
#define __CLI_GETPID_H
#include "frontend_getpid.h"
int getValues(struct backend_conn *, struct frontend_pid_data *);
int getPidValues(struct backend_conn *, struct frontend_pid_data *);
int cli_getpid(struct backend_conn * conn, int argc, char ** argv);
#endif
\ No newline at end of file
#endif /* __CLI_GETPID_H */
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include "cli_getsetpoint.h"
int cli_getsetpoint(struct backend_conn * conn, int argc, char **argv) {
int c;
static int getheight = 0, getlat = 0, getlong = 0;
static int getpitch = 0, getroll = 0, getyaw = 0;
struct frontend_setpoint_data setpoint_data;
static int needHelp = 0;
static int mask;
static struct option long_options[] = {
/* These options don’t set a flag. We distinguish them by their indices. */
{"help", no_argument, &needHelp, 1},
{"height", no_argument, &getheight, 1},
{"long", no_argument, &getlong, 1},
{"lat", no_argument, &getlat, 1},
{"pitch", no_argument, &getpitch, 1},
{"roll", no_argument, &getroll, 1},
{"yaw", no_argument, &getyaw, 1},
{0, 0, 0, 0}
};
while (1)
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long(argc, argv, "a", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
if (c == 'a') {
getheight = 1;
getlat = 1;
getlong = 1;
getpitch = 1;
getroll = 1;
getyaw = 1;
}
}
if (needHelp) {
printf("Getsetpoint gets the height, lat, long, pitch, roll and yaw set point values for the quad.\n");
printf("Usage Syntax : \n\t./Cli getsetpoint [options...]\n");
printf("Symlink Usage Syntax : \n\t./getsetpoint [options...]\n\n");
printf("Available options include the following\n");
printf("\t[-a] : Gets all of the following setpoints\n");
printf("\t[--height] : Gets the height setpoint\n");
printf("\t[--lat] : Gets the latitude setpoint\n");
printf("\t[--long] : Gets the longitude setpoint\n");
printf("\t[--pitch] : Gets the pitch setpoint\n");
printf("\t[--roll] : Gets the roll setpoint\n");
printf("\t[--yaw] : Gets the yaw setpoint\n");
return 0;
}
if (argc < 2) {
printf("Incorrect Usage, run './cli getsetpoint --help' for correct usage.\n");
return 1;
}
int result;
if(getheight) {
if ((result = getSetPointValues(conn, &setpoint_data, HEIGHT))) {
return result;
}
}
if(getlat) {
if ((result = getSetPointValues(conn, &setpoint_data, LAT))) {
return result;
}
}
if(getlong) {
if ((result = getSetPointValues(conn, &setpoint_data, LONGG))) {
return result;
}
}
if(getpitch) {
if ((result = getSetPointValues(conn, &setpoint_data, PITCH))) {
return result;
}
}
if(getroll) {
if ((result = getSetPointValues(conn, &setpoint_data, ROLL))) {
return result;
}
}
if(getyaw) {
if ((result = getSetPointValues(conn, &setpoint_data, YAW))) {
return result;
}
}
return 0;
}
int getSetPointValues(struct backend_conn * conn, struct frontend_setpoint_data * setpoint_data, int type) {
if(frontend_getsetpoint(conn, setpoint_data, type)) {
return 1;
}
switch(type) {
case HEIGHT :
printf("Height: %f\n",
setpoint_data->height);
break;
case LAT :
printf("Latitude: %f\n",
setpoint_data->lat);
case LONGG :
printf("Longitude: %f\n",
setpoint_data->longg);
case PITCH :
printf("Pitch: %f\n",
setpoint_data->pitch);
break;
case ROLL :
printf("Roll: %f\n",
setpoint_data->roll);
case YAW :
printf("Yaw: %f\n",
setpoint_data->yaw);
default :
break;
}
return 0;
}
#ifndef __CLI_GETSETPOINT_H
#define __CLI_GETSETPOINT_H
#include "frontend_getsetpoint.h"
enum {
HEIGHT,
LAT,
LONGG,
PITCH,
ROLL,
YAW
};
int getSetPointValues(struct backend_conn *, struct frontend_setpoint_data *, int type);
int cli_getsetpoint(struct backend_conn * conn, int argc, char ** argv);
#endif /* __CLI_GETSETPOINT_H */
\ No newline at end of file
#ifndef CLI_MONITOR_H
#define CLI_MONITOR_H
#ifndef __CLI_MONITOR_H
#define __CLI_MONITOR_H
#include <time.h>
......@@ -11,4 +11,4 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv);
// Return 0 on success and 1 otherwise
int monitor(struct backend_conn * conn);
#endif
\ No newline at end of file
#endif /* __CLI_MONITOR_H */
\ No newline at end of file
#ifndef CLI_SETPID_H
#define CLI_SETPID_H
#ifndef __CLI_SETPID_H
#define __CLI_SETPID_H
#include "frontend_setpid.h"
int cli_setpid(struct backend_conn * conn, int argc, char ** argv);
#endif
#endif /* __CLI_SETPID_H */
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment