trivial change for gyro fix

This commit is contained in:
Philip Rosedale 2013-02-18 16:42:19 -08:00
commit fd151fb7bc
14 changed files with 153 additions and 175 deletions

View file

@ -2,9 +2,12 @@ cmake_minimum_required(VERSION 2.8)
project(domain)
# grab the implementation / header files
file(GLOB DOMAIN_SRCS src/*.cpp src/*.h)
# add an executable with the source files
add_executable(domain ${DOMAIN_SRCS})
# link the shared hifi library
include(../LinkHifiShared.cmake)
link_hifi_shared_library(domain)

View file

@ -43,9 +43,9 @@ struct AgentList {
char agentType;
uint32_t ip;
in_addr public_sin_addr;
in_port_t public_port;
unsigned short public_port;
char *private_addr;
in_port_t private_port;
unsigned short private_port;
float x, y, z;
bool active;
timeval time, connectTime;
@ -70,7 +70,12 @@ int addAgent(uint32_t ip, in_port_t port, char *private_ip, unsigned short priva
while ((ip != agents[i].ip || port != agents[i].public_port) && (i < num_agents)) {
i++;
}
if ((i == num_agents) || (agents[i].active == false)) is_new = 1;
if ((i == num_agents) || (agents[i].active == false)) {
is_new = 1;
agents[i].private_addr = new char[255];
}
agents[i].ip = ip;
agents[i].x = x;
agents[i].y = y;
@ -78,7 +83,7 @@ int addAgent(uint32_t ip, in_port_t port, char *private_ip, unsigned short priva
agents[i].active = true;
agents[i].public_sin_addr.s_addr = ip;
agents[i].public_port = port;
agents[i].private_addr = private_ip;
strcpy(agents[i].private_addr, private_ip);
agents[i].private_port = private_port;
agents[i].agentType = agentType;
gettimeofday(&agents[i].time, NULL);

View file

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8)
# setup for find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
set(GLM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
set(LODEPNG_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/LodePNG)
@ -8,36 +9,48 @@ set(PORTAUDIO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/portaudio)
project(interface)
if (APPLE)
# link in required OS X frameworks and include the right GL headers
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework CoreServices -framework Carbon")
set(GL_HEADERS "#include <GLUT/glut.h>\n#include <OpenGL/glext.h>")
else (APPLE)
# include the right GL headers for UNIX
set(GL_HEADERS "#include <GL/gl.h>\n#include <GL/glut.h>\n#include <GL/glext.h>")
endif (APPLE)
# create the InterfaceConfig.h file based on GL_HEADERS above
configure_file(InterfaceConfig.h.in ${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h)
# grab the implementation and header files from src dir
file(GLOB INTERFACE_SRCS src/*.cpp src/*.h)
# For Apple set the icns file containing icons
IF(APPLE)
# set how it shows up in the Info.plist file
if (APPLE)
# set how the icon shows up in the Info.plist file
SET(MACOSX_BUNDLE_ICON_FILE interface.icns)
# set where in the bundle to put the icns file
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/interface.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# include the icns file in the target
SET(INTERFACE_SRCS ${INTERFACE_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/interface.icns)
ENDIF(APPLE)
# grab the image and audio files
FILE(GLOB INTERFACE_RES_DIRS resources/*)
set(INTERFACE_RSRCS ${INTERFACE_RES_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/interface.icns)
# set where in the bundle to put the resources file
SET_SOURCE_FILES_PROPERTIES(${INTERFACE_RSRCS} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# include the icns file and resource files in the target
SET(INTERFACE_SRCS ${INTERFACE_SRCS} ${INTERFACE_RSRCS})
endif (APPLE)
# create the executable, make it a bundle on OS X
add_executable(interface MACOSX_BUNDLE ${INTERFACE_SRCS})
# link in the hifi shared library
include(../LinkHifiShared.cmake)
link_hifi_shared_library(interface)
# find required libraries
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLM REQUIRED)
find_package(LodePNG REQUIRED)
# include headers for external libraries and InterfaceConfig.
include_directories(
${PROJECT_BINARY_DIR}/includes
${OPENGL_INCLUDE_DIRS}
@ -46,12 +59,14 @@ include_directories(
${LODEPNG_INCLUDE_DIRS}
)
# link target to external libraries
target_link_libraries(interface
${OPENGL_LIBRARY}
${GLUT_LIBRARY}
${LODEPNG_LIBRARY}
)
# include PortAudio as external project
include(ExternalProject)
set(PORTAUDIO_PROJ_DIR external/portaudio)
ExternalProject_Add(
@ -63,13 +78,18 @@ ExternalProject_Add(
BUILD_COMMAND make
)
ExternalProject_Get_Property(portaudio binary_dir)
ExternalProject_Get_Property(portaudio source_dir)
include_directories(${source_dir}/include)
# make PortAudio a dependency of the interface executable
add_dependencies(interface portaudio)
# include the PortAudio headers
ExternalProject_Get_Property(portaudio source_dir)
include_directories(${source_dir}/include)
# link the PortAudio library
ExternalProject_Get_Property(portaudio binary_dir)
target_link_libraries(interface ${binary_dir}/lib/.libs/libportaudio.a)
# link required libraries on UNIX
if (UNIX AND NOT APPLE)
find_package(Threads REQUIRED)
find_package(Librt REQUIRED)
@ -84,6 +104,7 @@ if (UNIX AND NOT APPLE)
)
endif (UNIX AND NOT APPLE)
# install command for OS X bundle
INSTALL(TARGETS interface
BUNDLE DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime
RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime

View file

@ -19,7 +19,7 @@
#include "UDPSocket.h"
#include "Audio.h"
const int AGENT_UDP_PORT = 40103;
const unsigned short AGENT_UDP_PORT = 40103;
int update_agents(char * data, int length);
int add_agent(char * address, unsigned short port, char *private_address, unsigned short private_port, char agentType);

View file

@ -27,7 +27,7 @@ char serial_buffer[MAX_BUFFER];
int serial_buffer_pos = 0;
const int ZERO_OFFSET = 2048;
const short NO_READ_MAXIMUM = 10;
const short NO_READ_MAXIMUM_MSECS = 3000;
const short SAMPLES_TO_DISCARD = 100;
void SerialInterface::pair() {
@ -166,14 +166,12 @@ void SerialInterface::readData() {
int initialSamples = totalSamples;
while (read(serial_fd, &bufchar, 1) > 0)
{
while (read(serial_fd, &bufchar, 1) > 0) {
//std::cout << bufchar[0];
serial_buffer[serial_buffer_pos] = bufchar[0];
serial_buffer_pos++;
// Have we reached end of a line of input?
if ((bufchar[0] == '\n') || (serial_buffer_pos >= MAX_BUFFER))
{
if ((bufchar[0] == '\n') || (serial_buffer_pos >= MAX_BUFFER)) {
std::string serialLine(serial_buffer, serial_buffer_pos-1);
//std::cout << serialLine << "\n";
int spot;
@ -203,28 +201,28 @@ void SerialInterface::readData() {
serial_buffer_pos = 0;
}
}
/*
if (initialSamples == totalSamples) {
noReadCount++;
std::cout << "#" << noReadCount << " blank read from serial.\n";
if (initialSamples == totalSamples) {
timeval now;
gettimeofday(&now, NULL);
if (noReadCount >= NO_READ_MAXIMUM) {
if (diffclock(&lastGoodRead, &now) > NO_READ_MAXIMUM_MSECS) {
std::cout << "No data coming over serial. Shutting down SerialInterface.\n";
resetSerial();
}
} else {
gettimeofday(&lastGoodRead, NULL);
}
*/
}
void SerialInterface::resetSerial() {
std::cout << "Reached maximum blank read count. Shutting down serial.\n";
active = false;
noReadCount = 0;
totalSamples = 0;
gettimeofday(&lastGoodRead, NULL);
// Clear the measured and average channel data
for (int i = 0; i < NUM_CHANNELS; i++)
{
for (int i = 0; i < NUM_CHANNELS; i++) {
lastMeasured[i] = 0;
trailingAverage[i] = 0.0;
}

View file

@ -49,8 +49,8 @@ private:
float trailingAverage[NUM_CHANNELS];
int samplesAveraged;
int LED;
int noReadCount;
int totalSamples;
timeval lastGoodRead;
};
#endif

View file

@ -184,11 +184,7 @@ double elapsedTime;
// Particles
// To add a new texture:
// 1. Add to the XCode project in the Resources/images group
// (ensure "Copy file" is checked
// 2. Add to the "Copy files" build phase in the project
char texture_filename[] = "./int-texture256-v4.png";
char texture_filename[] = "images/int-texture256-v4.png";
unsigned int texture_width = 256;
unsigned int texture_height = 256;
@ -231,7 +227,7 @@ void Timer(int extra)
// Send a message to the domainserver telling it we are ALIVE
//
char output[100];
sprintf(output, "%c %f,%f,%f,%s %hd", 'I', location[0], location[1], location[2], localAddressBuffer, (unsigned short) AGENT_UDP_PORT);
sprintf(output, "%c %f,%f,%f,%s %hd", 'I', location[0], location[1], location[2], localAddressBuffer, AGENT_UDP_PORT);
std::cout << "sending " << output << " to domain server\n";
int packet_size = strlen(output);
agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size);
@ -311,7 +307,7 @@ void initDisplay(void)
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
//load_png_as_texture(texture_filename);
// load_png_as_texture(texture_filename);
if (fullscreen) glutFullScreen();
}

View file

@ -2,15 +2,16 @@ cmake_minimum_required(VERSION 2.8)
project(mixer)
# grab the implemenation and header files
file(GLOB MIXER_SRCS src/*.cpp src/*.h)
# add the mixer executable
add_executable(mixer ${MIXER_SRCS})
# link the shared hifi library
include(../LinkHifiShared.cmake)
link_hifi_shared_library(mixer)
# link the threads library
find_package(Threads REQUIRED)
target_link_libraries(mixer
${CMAKE_THREAD_LIBS_INIT}
${HIFI_SHARED_LIBRARY}
)
target_link_libraries(mixer ${CMAKE_THREAD_LIBS_INIT})

View file

@ -18,7 +18,7 @@
const int MAX_AGENTS = 1000;
const int LOGOFF_CHECK_INTERVAL = 1000;
const int MIXER_LISTEN_PORT = 55443;
const unsigned short MIXER_LISTEN_PORT = 55443;
const int BUFFER_LENGTH_BYTES = 1024;
const int BUFFER_LENGTH_SAMPLES = BUFFER_LENGTH_BYTES / sizeof(int16_t);

View file

@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 2.8)
project(shared)
# grab the implemenation and header files
file(GLOB HIFI_SHARED_SRCS src/*.h src/*.cpp)
# create a library and set the property so it can be referenced later
add_library(HifiShared ${HIFI_SHARED_SRCS})
set(HIFI_SHARED_LIBRARY HifiShared)

2
space/example.data.txt Normal file
View file

@ -0,0 +1,2 @@
0 00000100001011101110 domain4.highfidelity.co domain4
0 00000100110100010001 domain3.highfidelity.co domain3

View file

@ -14,6 +14,7 @@ TreeNode::TreeNode() {
for (int i = 0; i < CHILDREN_PER_NODE; ++i) {
child[i] = NULL;
}
hostname = &EMPTY_STRING;
nickname = &EMPTY_STRING;
hostname = NULL;
nickname = NULL;
}

View file

@ -18,8 +18,8 @@ public:
TreeNode();
TreeNode *child[CHILDREN_PER_NODE];
std::string *hostname;
std::string *nickname;
char *hostname;
char *nickname;
int domain_id;
};

View file

@ -7,82 +7,53 @@
//
#include <iostream>
#include <fstream>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <stack>
#include <bitset>
#include "TreeNode.h"
#include "UDPSocket.h"
const char *CONFIG_FILE = "/etc/below92/spaceserver.data.txt";
const int SPACE_LISTENING_PORT = 55551;
std::vector< std::vector<std::string> > configData;
sockaddr_in address, destAddress;
socklen_t destLength = sizeof(destAddress);
const char *CONFIG_FILE = "/Users/birarda/code/worklist/checkouts/hifi/space/example.data.txt";
const unsigned short SPACE_LISTENING_PORT = 55551;
const short MAX_NAME_LENGTH = 63;
std::string ROOT_HOSTNAME = "root.highfidelity.co";
std::string ROOT_NICKNAME = "root";
std::string *LAST_KNOWN_HOSTNAME = new std::string();
const char ROOT_HOSTNAME[] = "root.highfidelity.co";
const char ROOT_NICKNAME[] = "root";
const size_t PACKET_LENGTH_BYTES = 1024;
sockaddr_in destAddress;
socklen_t destLength = sizeof(destAddress);
char *lastKnownHostname;
TreeNode rootNode;
UDPSocket spaceSocket(SPACE_LISTENING_PORT);
void printBinaryValue(char element) {
std::bitset<8> x(element);
std::cout << "Printing binary value: " << x << std::endl;
}
TreeNode *findOrCreateNode(unsigned long lengthInBits,
TreeNode *findOrCreateNode(int lengthInBits,
unsigned char *addressBytes,
std::string *hostname,
std::string *nickname,
int domain_id) {
char *hostname,
char *nickname,
int domainID) {
TreeNode *currentNode = &rootNode;
for (int i = 0; i < lengthInBits; i += 3) {
unsigned char octetA;
unsigned char octetB;
unsigned char octet;
/*
* @TODO Put those shifts into a nice single statement, leaving as is for now
*/
if (i%8 < 6) {
octetA = addressBytes[i/8] << i%8;
octet = octetA >> (5);
octet = addressBytes[i/8] << i%8 >> (5);
} else {
octetA = addressBytes[i/8] << i;
octetA = octetA >> (11 - i);
octetB = addressBytes[i/8 + 1] >> (11 - i + 2);
octet = octetA | octetB;
octet = (addressBytes[i/8] << i >> (11 - i)) | (addressBytes[i/8 + 1] >> (11 - i + 2));
}
if (currentNode->child[octet] == NULL) {
currentNode->child[octet] = new TreeNode;
} else if (!currentNode->child[octet]->hostname->empty()) {
LAST_KNOWN_HOSTNAME = currentNode->child[octet]->hostname;
} else if (currentNode->child[octet]->hostname != NULL) {
lastKnownHostname = currentNode->child[octet]->hostname;
}
currentNode = currentNode->child[octet];
}
if (currentNode->hostname->empty()) {
if (currentNode->hostname == NULL) {
currentNode->hostname = hostname;
currentNode->nickname = nickname;
}
@ -91,73 +62,59 @@ TreeNode *findOrCreateNode(unsigned long lengthInBits,
};
bool loadSpaceData(void) {
std::ifstream configFile(CONFIG_FILE);
std::string line;
FILE *configFile = std::fopen(CONFIG_FILE, "r");
char formatString[10];
if (configFile.is_open()) {
while (getline(configFile, line)) {
std::istringstream iss(line);
std::vector<std::string> thisEntry;
copy(std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>(),
std::back_inserter(thisEntry));
configData.push_back(thisEntry);
thisEntry.clear();
}
} else {
std::cout << "Unable to load config file\n";
if (configFile == NULL) {
std::cout << "Unable to load config file!\n";
return false;
}
} else {
char *lengthBitString = new char[8];
int itemsRead = 0;
while ((itemsRead = fscanf(configFile, "0 %8c", lengthBitString)) > 0) {
// calculate the number of bits in the address and bits required for padding
unsigned long threeBitCodes = strtoul(lengthBitString, NULL, 2);
int bitsInAddress = threeBitCodes * 3;
int paddingBits = 8 - (bitsInAddress % 8);
int addressByteLength = (bitsInAddress + paddingBits) / 8;
// create an unsigned char * to hold the padded address
unsigned char *paddedAddress = new unsigned char[addressByteLength];
char *fullByteBitString = new char[8];
for (int c = 0; c < addressByteLength; c++) {
if (c + 1 == addressByteLength && paddingBits > 0) {
// this is the last byte, and we need some padding bits
// pull as many bits as are left
int goodBits = 8 - paddingBits;
sprintf(formatString, "%%%dc", goodBits);
fscanf(configFile, formatString, fullByteBitString);
// fill out the rest with zeros
memset(fullByteBitString + goodBits, '0', paddingBits);
} else {
// pull 8 bits (which will be one byte) from the file
fscanf(configFile, "%8c", fullByteBitString);
}
// set the corresponding value in the unsigned char array
*(paddedAddress + c) = strtoul(fullByteBitString, NULL, 2);
}
for (std::vector< std::vector<std::string> >::iterator it = configData.begin(); it != configData.end(); ++it) {
std::string *thisAddress = &(*it)[1];
std::string *thisHostname = &(*it)[2];
std::string *thisNickname = &(*it)[3];
char lengthByteString[8];
unsigned long lengthByte;
unsigned long bitsInAddress;
std::size_t bytesForAddress;
std::size_t lengthByteSlice = (*thisAddress).copy(lengthByteString, 8, 0);
lengthByteString[lengthByteSlice] = '\0';
lengthByte = strtoul(lengthByteString, NULL, 2);
bitsInAddress = lengthByte * 3;
bytesForAddress = (((bitsInAddress + 7) & ~7));
char *addressBitStream = new char();
std::size_t addressBitSlice = (*thisAddress).copy(addressBitStream, (*thisAddress).length(), 8);
if (bitsInAddress != addressBitSlice) {
std::cout << "[FATAL] Mismatching byte length: " << bitsInAddress
<< " and address bits: " << sizeof(addressBitStream) << std::endl;
return false;
char *nodeHostname = new char[MAX_NAME_LENGTH];
char *nodeNickname = new char[MAX_NAME_LENGTH];
fscanf(configFile, "%s %s\n", nodeHostname, nodeNickname);
findOrCreateNode(bitsInAddress, paddedAddress, nodeHostname, nodeNickname, 0);
}
char paddedBitString[bytesForAddress];
strcpy(paddedBitString, addressBitStream);
for (unsigned long i = addressBitSlice; i < bytesForAddress; ++i ) {
paddedBitString[i] = '0';
}
paddedBitString[bytesForAddress] = '\0';
std::fclose(configFile);
std::string byteBufferHolder = *new std::string(paddedBitString);
unsigned char addressBytes[bytesForAddress / 8];
addressBytes[bytesForAddress / 8] = '\0';
int j = 0;
for (unsigned long i = 0; i < bytesForAddress; i += 8) {
char *byteHolder = new char;
unsigned long thisByte;
byteBufferHolder.copy(byteHolder, 8, i);
thisByte = strtoul(byteHolder, NULL, 2);
addressBytes[j] = thisByte;
++j;
}
findOrCreateNode(bitsInAddress, addressBytes, thisHostname, thisNickname, 0);
return true;
}
return true;
}
int main (int argc, const char *argv[]) {
@ -165,8 +122,11 @@ int main (int argc, const char *argv[]) {
unsigned char packetData[PACKET_LENGTH_BYTES];
ssize_t receivedBytes = 0;
rootNode.hostname = &ROOT_HOSTNAME;
rootNode.nickname = &ROOT_NICKNAME;
rootNode.hostname = new char[MAX_NAME_LENGTH];
rootNode.nickname = new char[MAX_NAME_LENGTH];
strcpy(rootNode.hostname, ROOT_HOSTNAME);
strcpy(rootNode.nickname, ROOT_NICKNAME);
loadSpaceData();
@ -181,24 +141,13 @@ int main (int argc, const char *argv[]) {
for (int i = 0; i < sizeof(packetData)-1; ++i) {
addressData[i] = packetData[i+1];
}
std::string thisHostname;
std::string thisNickname;
std::string hostnameHolder;
int domain_id = 0;
TreeNode thisNode = *findOrCreateNode(lengthInBits, addressData, &thisHostname, &thisNickname, domain_id);
TreeNode *thisNode = findOrCreateNode(lengthInBits, addressData, NULL, NULL, 0);
char *hostnameToSend = (thisNode->hostname == NULL)
? lastKnownHostname
: thisNode->hostname;
if (thisNode.hostname->empty()) {
hostnameHolder = *LAST_KNOWN_HOSTNAME;
} else {
hostnameHolder = *thisNode.hostname;
}
char hostname[hostnameHolder.size() + 1];
std::copy(hostnameHolder.begin(), hostnameHolder.end(), hostname);
hostname[hostnameHolder.size()] = '\0';
spaceSocket.send(&destAddress, &hostname, PACKET_LENGTH_BYTES);
spaceSocket.send(&destAddress, &hostnameToSend, sizeof(hostnameToSend));
}
}
}