add sockets
This commit is contained in:
@@ -3,13 +3,13 @@
|
|||||||
char *action_name[8] = {"LEFT", "CENTER", "RIGHT"};
|
char *action_name[8] = {"LEFT", "CENTER", "RIGHT"};
|
||||||
|
|
||||||
float reLU(float x){
|
float reLU(float x){
|
||||||
if(x>10) return 10;
|
// if(x>10) return 10;
|
||||||
if(x>0) return x;
|
if(x>0) return x;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float d_reLU(float x){
|
float d_reLU(float x){
|
||||||
if (x>10) return 0;
|
// if (x>10) return 0;
|
||||||
if (x>0) return 1;
|
if (x>0) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ float distance2_coordinate(coordinate *c0, coordinate *c1){
|
|||||||
diStep_sensor->x[0] += step_sensor * cos(direction_radian);\
|
diStep_sensor->x[0] += step_sensor * cos(direction_radian);\
|
||||||
diStep_sensor->x[1] -= step_sensor * sin(direction_radian);\
|
diStep_sensor->x[1] -= step_sensor * sin(direction_radian);\
|
||||||
}\
|
}\
|
||||||
dist = (distance2_coordinate(diStep_sensor, v->coord)/5);\
|
dist = (distance2_coordinate(diStep_sensor, v->coord)/10/*5*/);\
|
||||||
/*printf("| dist :%f | ",dist);*/\
|
/*printf("| dist :%f | ",dist);*/\
|
||||||
v->sensor->x[position] = (float)(MIN((SUBDIVISION-1),dist))/SUBDIVISION ;\
|
v->sensor->x[position] = (float)(MIN((SUBDIVISION-1),dist))/SUBDIVISION ;\
|
||||||
|
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ TEST(first_learn_vehicle_rev50_8){
|
|||||||
int randomRange = 500;
|
int randomRange = 500;
|
||||||
size_t nb_prod_thread = 2;
|
size_t nb_prod_thread = 2;
|
||||||
size_t nb_calc_thread = 4;
|
size_t nb_calc_thread = 4;
|
||||||
float learning_rate =0.00001 /*0.001*/;
|
float learning_rate = 0.001; // 0.00001 /*0.001*/;
|
||||||
struct networks_qlearning *nnetworks = create_nework_qlearning(
|
struct networks_qlearning *nnetworks = create_nework_qlearning(
|
||||||
pconf,
|
pconf,
|
||||||
randomize, minR, maxR, randomRange,
|
randomize, minR, maxR, randomRange,
|
||||||
@@ -465,8 +465,8 @@ TEST(first_learn_vehicle_rev50_8){
|
|||||||
learning_rate
|
learning_rate
|
||||||
);
|
);
|
||||||
|
|
||||||
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->main_net, weight_in, ".ff_main_20240717_01h42m16s_5300.txt");
|
//EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->main_net, weight_in, ".ff_main_20240717_01h42m16s_5300.txt");
|
||||||
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->target_net, weight_in, ".ff_target_20240717_01h42m16s_5300.txt");
|
//EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, nnetworks->target_net, weight_in, ".ff_target_20240717_01h42m16s_5300.txt");
|
||||||
|
|
||||||
struct status_qlearning *qlstatus = create_status_qlearning ();
|
struct status_qlearning *qlstatus = create_status_qlearning ();
|
||||||
struct delay_params *dly = create_delay_params (
|
struct delay_params *dly = create_delay_params (
|
||||||
@@ -478,7 +478,7 @@ struct status_qlearning *qlstatus = create_status_qlearning ();
|
|||||||
0.95/*float gamma*/,
|
0.95/*float gamma*/,
|
||||||
learning_rate,
|
learning_rate,
|
||||||
0 /* (not used!)float discount_factor*/,
|
0 /* (not used!)float discount_factor*/,
|
||||||
0.0001 /* 0.99*/ /*float exploration_factor*/,
|
0.99, // 0.0001 /* 0.99*/ /*float exploration_factor*/,
|
||||||
20/*long int nb_training_before_update_weight_in_target*/,
|
20/*long int nb_training_before_update_weight_in_target*/,
|
||||||
10000/*size_t number_episodes*/
|
10000/*size_t number_episodes*/
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -399,6 +399,11 @@ void print_tensor_msg_##type(tensor_##type *T,char *msg) {\
|
|||||||
printf(" |#%ld]: %s, ",i,val);\
|
printf(" |#%ld]: %s, ",i,val);\
|
||||||
/*printf(" %s, ",val);*/\
|
/*printf(" %s, ",val);*/\
|
||||||
free(val); val=NULL;\
|
free(val); val=NULL;\
|
||||||
|
if(T->x[i] != T->x[i]){\
|
||||||
|
printf("\nALERT NAN\n");\
|
||||||
|
char c;\
|
||||||
|
scanf("%c",&c);\
|
||||||
|
}\
|
||||||
if(coord[begin]==(T->dim)->perm[begin]-1){\
|
if(coord[begin]==(T->dim)->perm[begin]-1){\
|
||||||
size_t count=0;\
|
size_t count=0;\
|
||||||
for(long int j=begin; cond(j,end); j = iter(j)){\
|
for(long int j=begin; cond(j,end); j = iter(j)){\
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# lib: -lysocket
|
||||||
|
PROJECT_LIB=libysocket.so
|
||||||
|
CC=gcc
|
||||||
|
INCLUDE_DIRS=$(PWD)
|
||||||
|
SOCDIR=$(PWD)
|
||||||
|
#$(wildcard $(PWD)/**/include)
|
||||||
|
|
||||||
|
|
||||||
|
INCLUDE=-I$(PWD)/include
|
||||||
|
CFLAGS=-g -lpthread -Wall -Werror -fpic $(INCLUDE) #"-D DEBUG=1"
|
||||||
|
#LDFLAGS=
|
||||||
|
|
||||||
|
TOPTARGETS := all clean #update_headers
|
||||||
|
|
||||||
|
#SRC=$(wildcard y*/src/**/**/*.c)
|
||||||
|
SRC=$(wildcard src/*/*.c)
|
||||||
|
OBJ=$(SRC:.c=.o)
|
||||||
|
|
||||||
|
#SUBDIRS :=$(wildcard y*) $(TOOLDIR) $(BARPDIR)
|
||||||
|
|
||||||
|
#export
|
||||||
|
|
||||||
|
|
||||||
|
#$(TOPTARGETS): $(SUBDIRS)
|
||||||
|
|
||||||
|
all: $(PROJECT_LIB)
|
||||||
|
|
||||||
|
#update_headers
|
||||||
|
|
||||||
|
|
||||||
|
$(PROJECT_LIB): $(OBJ)
|
||||||
|
echo $(OBJ)
|
||||||
|
#$(CC) -shared -o $@ $^ $(INCLUDE) $(LDFLAGS)
|
||||||
|
#$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||||
|
$(CC) -shared -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
$(SUBDIRS):
|
||||||
|
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||||
|
|
||||||
|
|
||||||
|
# .PHONY: $(TOPTARGETS) $(SUBDIRS)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(PROJECT_LIB)
|
||||||
|
|
||||||
|
install:
|
||||||
|
cp libytest.so /usr/lib/
|
||||||
|
@if [ -d /usr/local/include ] ; then\
|
||||||
|
echo "copy include to /usr/local/include/" ;\
|
||||||
|
cp -r include/* /usr/local/include/;\
|
||||||
|
else\
|
||||||
|
echo "copy include to /usr/include/" ;\
|
||||||
|
cp -r include/* /usr/include/;\
|
||||||
|
fi
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm /usr/lib/libytest.so
|
||||||
|
@if [ -d /usr/local/include ] ; then\
|
||||||
|
echo "remove from /usr/local/include/" ;\
|
||||||
|
rm -r /usr/local/include/y_socket ;\
|
||||||
|
else\
|
||||||
|
echo "remove from /usr/include/" ;\
|
||||||
|
rm -r /usr/include/y_socket ;\
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#SRC_test=test/is_good.c
|
||||||
|
|
||||||
|
#compile: $(SRC_test) $(PROJECT_LIB)
|
||||||
|
# $(CC) -o launch_is_good_m $< -L. test/src/permutation_t/permutation_t.o test/src/set_theoric_t/set_theoric_t.o -lytest -I./test/src -I./include_ytest
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef Y_CLIENT_H__C
|
||||||
|
#define Y_CLIENT_H__C
|
||||||
|
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "y_socket/y_socket.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct y_client{
|
||||||
|
size_t id;
|
||||||
|
struct y_socket_t *socket;
|
||||||
|
int nb_threads;
|
||||||
|
pthread_t *thread_client;
|
||||||
|
pthread_mutex_t *mut_client;
|
||||||
|
|
||||||
|
void *(*launch)(void*);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* Y_CLIENT_H__C */
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef __Y_QUEUE_T_H__
|
||||||
|
#define __Y_QUEUE_T_H__
|
||||||
|
|
||||||
|
#include "y_socket/y_threads.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*__Y_QUEUE_T_H__*/
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef Y_SERVER_H__C
|
||||||
|
#define Y_SERVER_H__C
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "y_socket/y_socket.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct y_server_t{
|
||||||
|
struct y_socket_t *socket;
|
||||||
|
// struct y_client_t *client;
|
||||||
|
// int nb_clients;
|
||||||
|
|
||||||
|
|
||||||
|
// int max_length_queue; //backlog;// max connexion
|
||||||
|
|
||||||
|
pthread_t *thread_server;
|
||||||
|
pthread_mutex_t *mut_server;
|
||||||
|
int nb_threads;
|
||||||
|
|
||||||
|
|
||||||
|
void *(*launch)(void*);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* Y_SERVER_H__C */
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef Y_SOCKET_H__C
|
||||||
|
#define Y_SOCKET_H__C
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
struct y_socket_t{
|
||||||
|
int fd; /* Socket descriptor, */
|
||||||
|
int domain; /*AF_INET, AF_INET6 */
|
||||||
|
int service; /*type: SOCK_STREAM: TCP, SOCK_DGRAM: UDP */
|
||||||
|
int protocol; /* 0 */
|
||||||
|
u_long interface;
|
||||||
|
int port;
|
||||||
|
int backlog;/*max_queue */
|
||||||
|
|
||||||
|
struct sockaddr_in *address; /* INADDR_ANY or */
|
||||||
|
int address_len;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct y_socket_t * socket_create(int domain, int service, int protocol, u_long interface,
|
||||||
|
int port, int backlog);
|
||||||
|
|
||||||
|
void socket_destroy(struct y_socket_t *socket);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* Y_SOCKET_H__C */
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef __Y_THREAD_H__
|
||||||
|
#define __Y_THREAD_H__
|
||||||
|
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "y_socket/y_queue.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct y_threadpool{
|
||||||
|
int nb_threads;
|
||||||
|
pthread_cond_t cond_;
|
||||||
|
pthread_mutex_t mut_;
|
||||||
|
pthread_t *thread;
|
||||||
|
void *(*launch)(void* arg);
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif /*__Y_THREAD_H__*/
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#include "y_socket/y_client.h"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#include "y_socket/y_queue.h"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "y_socket/y_server.h"
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "y_socket/y_socket.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
struct y_server_t server;
|
||||||
|
|
||||||
|
void close_server(struct y_server_t server){
|
||||||
|
char *message ="HTTP/1.1 201 OK\r\n"
|
||||||
|
"Connection: close";
|
||||||
|
|
||||||
|
for(int i=0; i<server.nb_clients;++i){
|
||||||
|
|
||||||
|
pthread_mutex_lock(server.client[i].mut_client);
|
||||||
|
write(server.client[i].id, message, strlen(message));
|
||||||
|
pthread_mutex_unlock(server.client[i].mut_client);
|
||||||
|
|
||||||
|
close(server.client[i].id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
close(server.sock);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void func_sig_Handler(int sig){
|
||||||
|
if(sig==SIGINT){
|
||||||
|
close_server(server);
|
||||||
|
|
||||||
|
sigaction(SIGINT, &old, NULL); /* equivalent à .sa_falg = SA_RESETHAND , i.e. 1 seul new_action, puis on revient à l'ancien*/
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#include "y_socket/y_threads.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TEST=is_good
|
||||||
|
CC=gcc
|
||||||
|
ROOT_DIR=$(PWD)
|
||||||
|
YTESTDIR=$(PWD)/../../ytest_t
|
||||||
|
|
||||||
|
SOCDIR=$(PWD)/..
|
||||||
|
INCLUDE_DIR=$(PWD)/../include
|
||||||
|
CFLAGS=-I$(INCLUDE_DIR) #"-D DEBUG=1"
|
||||||
|
LDFLAGS=-L$(YTESTDIR) -lytest -lOpenCL
|
||||||
|
|
||||||
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
SRC=$(wildcard **/**/*.c)
|
||||||
|
#HEADS=$(OBJS:.o=.h)
|
||||||
|
TEST_DIR=$(PWD)
|
||||||
|
|
||||||
|
EXECSRC=$(NAME_TEST).c
|
||||||
|
#EXECSRC=openF.c
|
||||||
|
|
||||||
|
EXEC=launch_$(NAME_TEST)_m
|
||||||
|
|
||||||
|
SOCRC=$(SOCDIR)/src/y_socket/y_socket.c
|
||||||
|
SOCSRC=$(wildcard ../src/*/*.c)
|
||||||
|
SOCSRC_O=$(SOCSRC:.c=.o)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TOPTARGETS := all clean
|
||||||
|
|
||||||
|
DEPS=$(YTESTDIR) $(SOCDIR)
|
||||||
|
|
||||||
|
OBJ=$(SOCSRC_O)
|
||||||
|
|
||||||
|
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||||
|
|
||||||
|
|
||||||
|
$(TOPTARGETS): $(DEPS)
|
||||||
|
|
||||||
|
$(DEPS):
|
||||||
|
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||||
|
|
||||||
|
|
||||||
|
#PERMSRC_O=$(PERMSRC:.c=.o)
|
||||||
|
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
|
||||||
|
#SETTSRC_O=$(SETTSRC:.c=.o)
|
||||||
|
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||||
|
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||||
|
|
||||||
|
|
||||||
|
all: $(EXEC) $(LIB_YTEST)
|
||||||
|
|
||||||
|
$(EXEC): $(EXECSRC) $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean mrproper
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(EXEC)
|
||||||
|
|
||||||
|
run: $(EXEC)
|
||||||
|
$(EXEC) -h
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// for sleep !
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ftest/ftest.h"
|
||||||
|
#include "ftest/ftest_array.h"
|
||||||
|
#include "fmock/fmock.h"
|
||||||
|
|
||||||
|
|
||||||
|
//#include "permutation_t/permutation_t.h"
|
||||||
|
#include "y_socket/y_socket.h"
|
||||||
|
|
||||||
|
#define VALGRIND_ 1
|
||||||
|
|
||||||
|
TEST(first){
|
||||||
|
|
||||||
|
LOG("hey%s\n"," you");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
|
||||||
|
run_all_tests_args(argc, argv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user