Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #13 from grf14003/dev
Updating master with the dev at the break in semesters
  • Loading branch information
grf14003 committed Dec 5, 2019
2 parents 27bfbf7 + 1eb01e1 commit e1557c3
Show file tree
Hide file tree
Showing 33 changed files with 728 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -1 +1,7 @@
.vs/*

# Excluding the build and executable folders
breadcrumbs/build/*
!breadcrumbs/build/.blank
breadcrumbs/bin/*
!breadcrumbs/bin/.blank
5 changes: 5 additions & 0 deletions README.md
@@ -0,0 +1,5 @@
# Sensory Biofeedback System
## Nich Chan, Greg Foss, Matt Scalzo & Nate Shaw


This is our Senior Design Project. Our goal is to create a system that can interpret 3D data and give meaningful feedback through a belt of tactile motors.
6 changes: 6 additions & 0 deletions breadcrumbs/CMakeConfig.h.in
@@ -0,0 +1,6 @@
// the configured options and settings for Tutorial

#define VERSION_MAJOR @Bfs_VERSION_MAJOR@
#define VERSION_MINOR @Bfs_VERSION_MINOR@

#define ALGORITHM_SERVER_PORT @Bfs_ALGORITHM_SERVER_PORT@
47 changes: 47 additions & 0 deletions breadcrumbs/CMakeLists.txt
@@ -0,0 +1,47 @@
# This file controls the build process. When you save it, VS figures out what types of executables that it builds.
# Then, you can switch the executable that you want to run at the top from the drop down and hit run to build and
# run it.
#

cmake_minimum_required (VERSION 2.6)

message("Starting CMAKE")
project (Breadcrumbs)
# The version number.
set (Bfs_VERSION_MAJOR 1)
set (Bfs_VERSION_MINOR 0)

# Setting paths
message("Setting paths...")
set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src) # Code directory
set(CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/build) # Object files and such (.o)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) # Compiled executables for execution and test (.exe)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) # Compiled libraries (.lib and .dll)
set(CMAKE_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/include) # Publicly accessible header files
message("Root directory: ${PROJECT_SOURCE_DIR}")
message("Source directory: ${CMAKE_SOURCE_DIR}")
message("Build directory: ${CMAKE_BINARY_DIR}")
message("Executable directory: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("Library directory: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
message("Header file directory: ${INCLUDES_DIRECTORY}")

# Configure a header file to pass some of the CMake settings to the source code
set (Bfs_ALGORITHM_SERVER_PORT \"27634\")

configure_file (
"${PROJECT_SOURCE_DIR}/CMakeConfig.h.in"
"${CMAKE_INCLUDE_PATH}/CMakeConfig.h"
)

# Adding public includes to include search path
include_directories("${CMAKE_INCLUDE_PATH}")
# Adding private include files from source tree
include_directories("${CMAKE_SOURCE_DIR}")

# puts all .cpp files inside src to the SOURCES variable
# TODO: replace this with a script for collecting cpp files
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/*.cpp")
message("Source files: ${SOURCES}")

# Adding executables
add_executable(Breadcrumbs ${SOURCES})
16 changes: 16 additions & 0 deletions breadcrumbs/CMakeSettings.json
@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "basic_build",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
}
]
}
Empty file removed breadcrumbs/bfs/out_proc/.blank
Empty file.
Empty file removed breadcrumbs/bfs/scripts/.blank
Empty file.
File renamed without changes.
20 changes: 20 additions & 0 deletions breadcrumbs/doc/style/style.cpp
@@ -0,0 +1,20 @@
/*
This file correspondes to style.hpp and is an example of
the .cpp files that would correspond to the .hpp file.
*/


#include "style.hpp"


char TestClass::attrTwoTimesTwo()
{
return c_attrTwo << 1
}

int TestClass::getAttrSum()
{
return c_attrTwo + i_attrOne
}
39 changes: 39 additions & 0 deletions breadcrumbs/doc/style/style.hpp
@@ -0,0 +1,39 @@
/*
*
* This file contains the style of each programming construct
* to use in this project.
*
* It should be followed to the letter! All spaces are
* necessary! Make sure to take note of camel case and other
* variable naming schemes!
*
*/

#ifndef STYLE_HPP
#define STYLE_HPP

#include <stdio.h>

#include "style.hpp"

// Header File:
class TestClass
{
public:
// Constructors
TestClass(int AttrOne, char AttrTwo);
// Mutator methods
int getAttrSum();
char attrTwoTimesTwo();
void setAttrOne(int newAttrOne) { i_attrOne = newAttrOne }
void setAttrTwo(char newAttrTwo) { c_attrTwo = newAttrTwo }
// Accessor methods
int getAttrOne() { return i_attrOne }
char getAttrTwo() { return c_attrTwo }
private:
// Private variables
int i_attrOne = 0;
char c_attrTwo;
};

#endif
Empty file removed breadcrumbs/in_procs/.blank
Empty file.
18 changes: 18 additions & 0 deletions breadcrumbs/include/AlgoBreadcrumbs.hpp
@@ -0,0 +1,18 @@

#ifndef ALGO_BREADCRUMBS_HPP
#define ALGO_BREADCRUMBS_HPP

#include "Algorithm.hpp"

class AlgoBreadcrumbs : public Algorithm
{
public:
using Algorithm::Algorithm;

void loop();
bool loopCondition();
private:
INT iterations = 1;
};

#endif
20 changes: 20 additions & 0 deletions breadcrumbs/include/Algorithm.hpp
@@ -0,0 +1,20 @@

#ifndef ALGORITHM_HPP
#define ALGORITHM_HPP

#include "AlgorithmServer.hpp"

class Algorithm
{
public:
explicit Algorithm(size_t numProcs);
~Algorithm();

virtual void loop() = 0;
virtual bool loopCondition() { return false; };
private:
size_t numIoProcs = 0;
AlgorithmServer* server;
};

#endif
53 changes: 53 additions & 0 deletions breadcrumbs/include/AlgorithmServer.hpp
@@ -0,0 +1,53 @@

#ifndef ALGORITHM_SERVER_HPP
#define ALGORITHM_SERVER_HPP


#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>

#include "CMakeConfig.h"
#include "DataSyncThread.hpp"

#define ALGORITHM_PORT "10101"
#define MAX_ACCEPT_FAILURES 5

#pragma comment (lib, "Ws2_32.lib")

class AlgorithmServer
{
public:
AlgorithmServer(size_t numClients);
~AlgorithmServer();

void serverThreadRuntime();
static DWORD serverThreadInit(LPVOID pThreadArgs)
{
AlgorithmServer* pAlgorithmServerThread = (AlgorithmServer*)pThreadArgs;
pAlgorithmServerThread->serverThreadRuntime();
return NULL;
}

// Updates Algorithm key/value store with IO key/value updates
void pollForUpdates();
void startServer();
void stopServer();

private:
HANDLE hThread;
DWORD dwThreadId;
bool continueThread = false;

size_t numClients;
std::vector<DataSyncThread> clientThreads;
};

#endif
10 changes: 10 additions & 0 deletions breadcrumbs/include/Attribute.hpp
@@ -0,0 +1,10 @@

#ifndef ATTRIBUTE_HPP
#define ATTRIBUTE_HPP

typedef struct BinaryAttributeStructure {
char key[8];
unsigned char length[2];
} bAttrib;

#endif
6 changes: 6 additions & 0 deletions breadcrumbs/include/CMakeConfig.h
@@ -0,0 +1,6 @@
// the configured options and settings for Tutorial

#define VERSION_MAJOR 1
#define VERSION_MINOR 0

#define ALGORITHM_SERVER_PORT "27634"
51 changes: 51 additions & 0 deletions breadcrumbs/include/DataSyncThread.hpp
@@ -0,0 +1,51 @@

#ifndef DATA_SYNC_THREAD_HPP
#define DATA_SYNC_THREAD_HPP

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>

#include "Attribute.hpp"
#include "CMakeConfig.h"

// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")

/*
This class contains the thread for communicating back and forth along a socket to sync attributes
*/
class DataSyncThread
{
private:
SOCKET sock;
HANDLE hThread;
DWORD dwThreadId;
bool continueThread = false;
public:
DataSyncThread(SOCKET s) { sock = s; };

// Synchronous functions
void threadRuntime();
static DWORD threadInit(LPVOID pThreadArgs)
{
DataSyncThread* pDataSyncThread = (DataSyncThread*)pThreadArgs;
pDataSyncThread->threadRuntime();
return NULL;
}
int recvBytes(void* buffer, size_t numBytes);

// Async control
void startComms();
bool stopComms();
int connectToAlgorithm(char* serverName);
};

#endif
26 changes: 26 additions & 0 deletions breadcrumbs/include/IOProcessor.hpp
@@ -0,0 +1,26 @@

#ifndef IO_PROCESSOR_HPP
#define IO_PROCESSOR_HPP


#include <stdio.h>
#include <Windows.h>


/*
This class is the class that abstracts the io processor side of the data exchange between
IO processors and algorithms
*/
class IOProcessor
{
public:
IOProcessor() {};

// Async control
unsigned int startComms();
bool stopComms();

};

#endif
19 changes: 19 additions & 0 deletions breadcrumbs/include/VirtualOutputProcessor.hpp
@@ -0,0 +1,19 @@

#ifndef VIRTUAL_OUTPUT_PROCESSOR_HPP
#define VIRTUAL_OUTPUT_PROCESSOR_HPP


#include <stdio.h>

#include "IOProcessor.hpp"


class VirtualOutputProcessor : public IOProcessor
{
public:
using IOProcessor::IOProcessor;

void threadRuntime(IOProcessor* ioProc);
};

#endif
Empty file removed breadcrumbs/out_procs/.blank
Empty file.
24 changes: 24 additions & 0 deletions breadcrumbs/scripts/startbfs.py
@@ -0,0 +1,24 @@

import os
import multiprocessing as mp
import subprocess


def start_program(command):
cmd_list = command.split(" ")
return subprocess.call(cmd_list)


def start_program_no_hang(command):
print("Running %s from cwd %s" % (command, os.getcwd()))
proc = mp.Process(target=start_program, args=(command,))
proc.start()
return proc


def main():
start_program_no_hang("start cmd.exe /k \"..\\bin\\Breadcrumbs.exe\"")


if __name__ == "__main__":
main()

0 comments on commit e1557c3

Please sign in to comment.