Skip to content
Snippets Groups Projects
Commit 9e5f1e26 authored by burneykb's avatar burneykb
Browse files

Fixed backend and getpid communication

parent 0134d66e
No related branches found
No related tags found
No related merge requests found
......@@ -567,6 +567,7 @@ static void client_recv(int fd) {
}
buffer[len_pre + r] = '\0';
int index = 0;
/* Parse buffer and handle commands */
while (1) {
/* not using strtok because reasons */
......@@ -584,31 +585,20 @@ static void client_recv(int fd) {
break;
}
buffer[newline] = '\0';
printf("Client(%d) : '%s'\n",fd, buffer);
unsigned char * packet;
// printf("newline =%li, Client sent: '%s'\n", newline, buffer);
if(formatCommand(buffer, &packet) == -1) {
printf("Could not recognize command '%s'\n", buffer);
} else {
int datalen = (packet[6] << 8) | (packet[5]);
writeQuad((char *) packet, datalen +7);
}
int datalen = (packet[6] << 8) | (packet[5]);
printf("data length = %d\n", datalen);
printf("packet = '");
for (int i = 0; i < datalen+7+1; ++i)
{
printf("%x ", packet[i]);
}
printf("'\n");
writeQuad((char *) packet, datalen +7);
//free(packet);
char * rest = &buffer[newline] + 1;
size_t restLen = (strlen(rest) == 0) ? 1 : strlen(rest);
/* Delete parsed data and move the rest to the left */
memmove(buffer, rest, restLen);
break;
memmove(buffer, rest, restLen + 1);
}
}
......
......@@ -182,7 +182,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
{
data_checksum ^= (*formattedCommand)[i];
}
printf("checksum = %x\n", (unsigned )data_checksum);
(*formattedCommand)[7 + metadata->data_len] = data_checksum;
return 0;
......
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <unistd.h>
#include "cli.h"
......@@ -47,7 +46,6 @@ int main(int argc, char **argv)
}else {
(*cli_functions[0]) (conn, argc-1, &argv[1]);
}
sleep(1);
ucart_backendDisconnect(conn);
return 0;
......
......@@ -75,6 +75,8 @@ int getValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) {
return 1;
}
return 0;
switch(pid_data->pid) {
case PITCH :
printf("Pitch Constants: P = %f\tI = %f\tD = %f\n",
......
......@@ -22,22 +22,23 @@
int frontend_getpid(
struct backend_conn * conn, struct frontend_pid_data * pid_data) {
char line[100];
char line[100] = "";
switch (pid_data->pid) {
case PITCH :
strncpy(line, "getpitchp\ngetpitchd\n\0", 21);
strncpy(line, "getpitchp\ngetpitchd\n", 20);
break;
case ROLL :
strncpy(line, "getrollp\ngetrolld\n\0", 19);
strncpy(line, "getrollp\ngetrolld\n", 18);
break;
case YAW :
strncpy(line, "getyawp\ngetyawd\n\0", 17);
strncpy(line, "getyawp\ngetyawd\n", 17);
break;
default :
return 1;
}
int size;
printf("sending '%s'\n",line);
if((size = ucart_backendWrite(conn, line)) < 0 ) {
return 1;
}
......
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