32 #include <arpa/inet.h> 36 #pragma comment(lib, "Ws2_32.lib") 39 unsigned sleep(
unsigned seconds)
62 #define AS3_BITMAPDATA_LEN 640 * 480 * 4 82 unsigned sleep(
unsigned seconds)
116 for(x = 0; x < depth_mode.
width; x++){
117 for(y = 0; y < depth_mode.
height; y++){
118 i = x + (y * depth_mode.
width);
119 j = (depth_mode.
width - x - 1) + (y * depth_mode.
width);
120 tmp_depth[i] = depth[j];
126 for (i=0; i< depth_mode.
width * depth_mode.
height; i++) {
128 buf_depth[3 * i + 0] = 0x00;
129 buf_depth[3 * i + 1] = 0x00;
130 buf_depth[3 * i + 2] = 0x00;
132 buf_depth[4 * i + 0] = 0x00;
133 buf_depth[4 * i + 1] = 0x00;
134 buf_depth[4 * i + 2] = 0x00;
135 buf_depth[4 * i + 3] = 0xFF;
138 unsigned char l = 0xFF - ((depth[i] -
_min_depth) & 0xFF);
140 buf_depth[3 * i + 0] = l;
141 buf_depth[3 * i + 1] = l;
142 buf_depth[3 * i + 2] = l;
144 buf_depth[4 * i + 0] = l;
145 buf_depth[4 * i + 1] = l;
146 buf_depth[4 * i + 2] = l;
147 buf_depth[4 * i + 3] = 0xFF;
153 unsigned long len = 0;
156 free(compressed_buff);
162 printf(
"Error sending depth\n");
163 client_connected = 0;
175 unsigned char *char_depth = (
unsigned char *) malloc(depth_mode.
bytes);
178 for(x = 0; x < depth_mode.
width; x++){
179 for(y = 0; y < depth_mode.
height; y++){
180 i = x + (y * depth_mode.
width);
181 j = (depth_mode.
width - x - 1) + (y * depth_mode.
width);
182 tmp_depth[i] = depth[j];
188 for (i=0; i<640 * 480; i++) {
189 memcpy(char_depth + (i*2), &depth[i], 2);
195 printf(
"Error sending raw depth\n");
196 client_connected = 0;
211 for(x = 0; x < video_mode.
width; x++){
212 for(y = 0; y < video_mode.
height; y++){
213 i = x + (y * video_mode.
width);
217 j = (video_mode.
width - x - 1) + (y * video_mode.
width);
219 buf_rgb[3 * i + 2] = rgb[3 * j + 2];
220 buf_rgb[3 * i + 1] = rgb[3 * j + 1];
221 buf_rgb[3 * i + 0] = rgb[3 * j + 0];
223 buf_rgb[4 * i + 0] = rgb[3 * j + 2];
224 buf_rgb[4 * i + 1] = rgb[3 * j + 1];
225 buf_rgb[4 * i + 2] = rgb[3 * j + 0];
226 buf_rgb[4 * i + 3] = 0x00;
232 unsigned long len = 0;
235 free(compressed_buff);
241 printf(
"Error sending Video\n");
242 client_connected = 0;
250 unsigned char buffer_send[3*2+3*8];
257 memcpy(&buffer_send,&ax,
sizeof(
int16_t));
258 memcpy(&buffer_send[2],&ay,
sizeof(
int16_t));
259 memcpy(&buffer_send[4],&az,
sizeof(
int16_t));
260 memcpy(&buffer_send[6],&dx,
sizeof(
double));
261 memcpy(&buffer_send[14],&dy,
sizeof(
double));
262 memcpy(&buffer_send[22],&dz,
sizeof(
double));
266 printf(
"Error sending Accelerometers\n");
267 client_connected = 0;
275 char *buff = (
char*)malloc(len);
277 while(client_connected) {
280 if(len > 0 && len % 6 == 0){
285 for(i = 0; i < max; i++){
286 memcpy(&value, &buff[2 + (i*6)],
sizeof(
int));
287 value = ntohl(value);
289 switch(buff[0 + (i*6)]){
291 switch(buff[1 + (i*6)]){
305 _video_mirrored = value;
322 switch(buff[1 + (i*6)]){
337 if(!die) printf(
"got bad command (%d)\n", len );
338 client_connected = 0;
342 printf(
"Disconecting client...\n");
351 printf(
"###### Got client\n");
354 client_connected = 1;
356 fprintf(stderr,
"Error on pthread_create() for SERVER\n");
367 printf(
"clean exit called\n");
373 int main(
int argc,
char **argv)
375 printf(
"as3kinect server %s\n", _current_version);
380 signal (SIGINT, SIG_IGN);
384 signal (SIGTSTP, SIG_IGN);
399 free(buf_depth_temp);
404 printf(
"\n[as3-server] cleanup done!\n");
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt)
void * connection_handler(void *arg)
void freenect_get_mks_accel(freenect_raw_tilt_state *state, double *x, double *y, double *z)
#define AS3_BITMAPDATA_LEN
void sendAccelerometers()
void freenect_network_wait()
void freenect_network_read(char *buff, int *len)
uint8_t buf_depth[AS3_BITMAPDATA_LEN]
int freenect_sync_set_tilt_degs(int angle, int index)
int freenect_sync_get_tilt_state(freenect_raw_tilt_state **state, int index)
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
void freenect_network_close()
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
pthread_t connection_thread
void freenect_sync_stop(void)
uint8_t buf_rgb[AS3_BITMAPDATA_LEN]
Data from the tilt motor and accelerometer.
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt)
int freenect_network_init(callback cb)
void send_policy_file(int child)
int freenect_sync_set_led(freenect_led_options led, int index)
int freenect_network_sendMessage(int first, int second, unsigned char *data, int len)
int RGB_2_JPEG(unsigned char *buffer, unsigned char **compressed, long unsigned int *new_len, int quality)
int main(int argc, char **argv)