Skip to content
Snippets Groups Projects
Commit 38eaa9b0 authored by burneykb's avatar burneykb
Browse files

Ready for commands to be added to complete functionality

parent f01552ea
No related branches found
No related tags found
No related merge requests found
# Declaration of variables
GCC=gcc
GXX=g++
CFLAGS= -Wall -pedantic -std=c99 -g
CPPFLAGS= -Wall -pedantic -std=c++11 -g
CFLAGS= -Wall -std=c99 -g
CPPFLAGS= -Wall -std=c++11 -g
INCLUDES = $(foreach dir, $(INCDIR), -I$(dir))
# Directories
......@@ -47,8 +47,6 @@ clean_logs:
clean:
rm -f $(EXE) $(OBJECTS)
rm -rf src/vrpn/build
debug:
@echo $(COBJECTS)
......
#
# Default log header
# Everything after '#'`s will be printed as is in the processed logs.
#
#
# Default log header
# Everything after '#'`s will be printed as is in the processed logs.
#
#
# Default log header
# Everything after '#'`s will be printed as is in the processed logs.
#
#
# Default log header
# Everything after '#'`s will be printed as is in the processed logs.
#
#
# Default log header
# Everything after '#'`s will be printed as is in the processed logs.
#
This diff is collapsed.
......@@ -2,7 +2,8 @@
*
* Logger file for holding functions pertaining to loging to a file.
*/
#include "logger.h"
#include "logger.h"
#include <stdio.h>
int quadlog_file;
......@@ -44,13 +45,13 @@ int createLogFile(int argc, char* argv)
}
}
int updateLogFile(struct ucart_vrpn_TrackerData * td)
int updateLogFile(const struct ucart_vrpn_TrackerData * td)
{
return dprintf(quadlog_file, "FPS: %lf Pos (xyz): (%lf %lf %lf) Att (pry): (%lf %lf %lf)\n",
td->fps, td->x, td->y, td->z, td->pitch, td->roll, td->yaw);
}
int writeLogHeader(const char * header)
int writeStringToLog(const char * string)
{
return dprintf(quadlog_file, "%s", header);
return dprintf(quadlog_file, "%s", string);
}
......@@ -13,8 +13,8 @@
#include "vrpn_tracker.hpp"
int createLogFile(int, char*);
int writeLogHeader(const char*);
int updateLogFile(struct ucart_vrpn_TrackerData* );
int writeStringToLog(const char*);
int updateLogFile(const struct ucart_vrpn_TrackerData* );
#endif
\ No newline at end of file
......@@ -51,9 +51,6 @@ pthread_mutex_t quadResponseMutex, cliInputMutex ;
unsigned char *respBuf, *commandBuf;
int newQuadResponse = 0, newCliInput = 0;
// Callback to be ran whenever the tracker receives data.
// Currently doing much more than it should. It will be slimmed down
// in the future.
......@@ -95,15 +92,15 @@ void *handleQuadResponse() {
memcpy(respBuf, buffer, 255);
pthread_mutex_unlock(&quadResponseMutex);
//parse_packet(buffer, &respBuf, &metadata);
fprintf(stderr, "CLI QUAD: %s\n", buffer);
// fprintf(stderr, "CLI QUAD: %s\n", buffer);
}
pthread_exit(NULL);
}
void *handleCliInput() {
sleep(1);
while(keepRunning)
{
char userCommand[CMD_MAX_LENGTH] = {};
......@@ -129,7 +126,6 @@ void *handleCliInput() {
memcpy(commandBuf, &userCommand, CMD_MAX_LENGTH);
pthread_mutex_unlock(&cliInputMutex);
fprintf(stderr, "$microcart> ");
memset(userCommand, 0, CMD_MAX_LENGTH);
......@@ -145,13 +141,13 @@ int main(int argc, char **argv)
respBuf = malloc(1024);
commandBuf = malloc(CMD_MAX_LENGTH);
signal(SIGINT, killHandler);
if ((zyboSocket = connectToZybo()) < 0)
{
perror("Error connecting to Zybo...");
free(respBuf);
free(commandBuf);
exit(1);
}
......@@ -163,27 +159,28 @@ int main(int argc, char **argv)
pthread_create(&quadResponse, NULL, handleQuadResponse, NULL);
fprintf(stderr, "CLI: Thread quad receiving started.\n");
// Retrieve user command input
fprintf(stderr, "CLI: Starting cli input thread...\n");
pthread_create(&cliInput, NULL, handleCliInput, NULL);
fprintf(stderr, "CLI: Thread Cli input started.\n");
// open the log file
// if( (status = createLogFile(argc, argv[1])) < 0)
// {
// perror("Error creating log file...");
// exit(1);
// }
// writeLogHeader(logHeader);
if( (status = createLogFile(argc, argv[1])) < 0)
{
perror("Error creating log file...");
exit(1);
}
writeStringToLog(logHeader);
//tell the quad we are ready to send it vrpn data
// printf("sending Start Packet...\n");
// sendStartPacket();
printf("sending Start Packet...\n");
sendStartPacket();
// this function will be called whenever tracker receives data
// ucart_vrpn_tracker_addCallback(tracker, cb);
// ucart_vrpn_tracker_addCallback(tracker, cb);
int updatePrompt = 0;
while(1)
while(keepRunning)
{
char tmpRespBuf[1024];
char tmpCommandBuf[CMD_MAX_LENGTH];
......@@ -192,42 +189,43 @@ int main(int argc, char **argv)
if(updatePrompt)
{
fprintf(stderr, "$microcart> ");
updatePrompt = !updatePrompt;
updatePrompt = 0;
}
//check for user input via cli
if(atomic_check(&newCliInput, &cliInputMutex))
{
pthread_mutex_lock(&cliInputMutex);
newCliInput = 0;
newCliInput = !newCliInput;
memcpy(tmpCommandBuf, commandBuf, CMD_MAX_LENGTH);
pthread_mutex_unlock(&cliInputMutex);
// I can use printf becuase the command was gathered using fgets.
fprintf(stderr, "\rINPUT FOUND via CLI: '%s'\n", tmpCommandBuf);
updatePrompt = 1;
updatePrompt = !updatePrompt;
}
//check for update/response from quad
if(atomic_check(&newQuadResponse, &quadResponseMutex))
{
pthread_mutex_lock(&quadResponseMutex);
newQuadResponse = 0;
newQuadResponse = !newQuadResponse;
memcpy(tmpRespBuf, respBuf, 1024);
pthread_mutex_unlock(&quadResponseMutex);
fprintf(stderr, "\rINPUT FOUND via QUAD: '");
fwrite(tmpRespBuf, 1024, 1, stdout);
fprintf(stderr, "'\n");
updatePrompt = 1;
char buf[1025];
memcpy(buf, tmpRespBuf, 1024);
buf[1025] = '\0';
//fprintf(stderr, "\rINPUT FOUND via QUAD: '%s'\n", buf);
writeStringToLog(buf);
updatePrompt = !updatePrompt;
}
usleep(10000);
}
ucart_vrpn_tracker_freeInstance(tracker);
//ucart_vrpn_tracker_freeInstance(tracker);
//free(vrpnData);
free(respBuf);
free(commandBuf);
......
......@@ -57,7 +57,6 @@ namespace microcart
{
while (1) {
remote.mainloop();
{
std::lock_guard<std::mutex> guard(vrpn_mutex);
......@@ -94,7 +93,7 @@ namespace microcart
auto td = trackerData;
std::for_each(cb_vector.begin(), cb_vector.end(),
[&td](std::function<void(const TrackerData &)> &fn){
[td](std::function<void(const TrackerData &)> &fn){
fn(td);
});
}
......
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