Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes in .h to work with ofxEtherdream #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 0 additions & 89 deletions driver/libetherdream/etherdream.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,98 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define _POSIX_C_SOURCE 199309L
#define _DARWIN_C_SOURCE 1

#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#ifdef __MACH__
#include <mach/mach.h>
#include <mach/mach_time.h>
#endif

#include <protocol.h>
#include "etherdream.h"

#define BUFFER_POINTS_PER_FRAME 16000
#define BUFFER_NFRAMES 2
#define MAX_LATE_ACKS 64
#define MIN_SEND_POINTS 40
#define DEFAULT_TIMEOUT 2000000
#define DEBUG_THRESHOLD_POINTS 800

struct etherdream_conn {
int dc_sock;
char dc_read_buf[1024];
int dc_read_buf_size;
struct dac_response resp;
long long dc_last_ack_time;

struct {
struct queue_command queue;
struct data_command_header header;
struct dac_point data[1000];
} __attribute__((packed)) dc_local_buffer;

int dc_begin_sent;
int ackbuf[MAX_LATE_ACKS];
int ackbuf_prod;
int ackbuf_cons;
int unacked_points;
int pending_meta_acks;
};

struct buffer_item {
struct dac_point data[BUFFER_POINTS_PER_FRAME];
int points;
int pps;
int repeatcount;
int idx;
};

enum dac_state {
ST_DISCONNECTED,
ST_READY,
ST_RUNNING,
ST_BROKEN,
ST_SHUTDOWN
};

struct etherdream {
pthread_mutex_t mutex;
pthread_cond_t loop_cond;

struct buffer_item buffer[BUFFER_NFRAMES];
int frame_buffer_read;
int frame_buffer_fullness;
int bounce_count;

pthread_t workerthread;

struct in_addr addr;
struct etherdream_conn conn;
unsigned long dac_id;
int sw_revision;
char mac_address[6];
char version[32];

enum dac_state state;

struct etherdream * next;
};

static FILE *trace_fp = NULL;
#if __MACH__
Expand Down
98 changes: 98 additions & 0 deletions driver/libetherdream/etherdream.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ extern "C" {

#include <stdint.h>


#define _POSIX_C_SOURCE 199309L
#define _DARWIN_C_SOURCE 1

#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#ifdef __MACH__
#include <mach/mach.h>
#include <mach/mach_time.h>
#endif

#include <protocol.h>

#define BUFFER_POINTS_PER_FRAME 16000
#define BUFFER_NFRAMES 2
#define MAX_LATE_ACKS 64
#define MIN_SEND_POINTS 40
#define DEFAULT_TIMEOUT 2000000
#define DEBUG_THRESHOLD_POINTS 800

struct etherdream_point {
int16_t x;
int16_t y;
Expand All @@ -18,6 +51,71 @@ struct etherdream_point {
uint16_t u2;
};

enum dac_state {
ST_DISCONNECTED,
ST_READY,
ST_RUNNING,
ST_BROKEN,
ST_SHUTDOWN
};

struct etherdream_conn {
int dc_sock;
char dc_read_buf[1024];
int dc_read_buf_size;
struct dac_response resp;
long long dc_last_ack_time;

struct {
struct queue_command queue;
struct data_command_header header;
struct dac_point data[1000];
} __attribute__((packed)) dc_local_buffer;

int dc_begin_sent;
int ackbuf[MAX_LATE_ACKS];
int ackbuf_prod;
int ackbuf_cons;
int unacked_points;
int pending_meta_acks;
};





struct buffer_item {
struct dac_point data[BUFFER_POINTS_PER_FRAME];
int points;
int pps;
int repeatcount;
int idx;
};


struct etherdream {
pthread_mutex_t mutex;
pthread_cond_t loop_cond;

struct buffer_item buffer[BUFFER_NFRAMES];
int frame_buffer_read;
int frame_buffer_fullness;
int bounce_count;

pthread_t workerthread;

struct in_addr addr;
struct etherdream_conn conn;
unsigned long dac_id;
int sw_revision;
char mac_address[6];
char version[32];

enum dac_state state;

struct etherdream * next;
};

struct etherdream;

/* etherdream_lib_start()
Expand Down