<commit_before>#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <getopt.h>

#include "bmpsensor/bmp180.h"

#include "routines.h"
#include "msg.h"


int ret;
int background = 0;
int stop = 0;
int bs_err = 0;
int initialized = 0;

int connected = 0;
int sock = 0;
char sock_path[256] = "127.0.0.1";
int portno = 1030;
struct sockaddr_in address;
struct hostent *server;

int verbose = 0;
int delay;

void reset() {
	connected = 0;
	close(sock);
	delay = 2500;
}

int sendMsg(int t, int v) {
	static unsigned char buf[3];
	buf[0] = t;
	packi16(buf+1,v);
	if (write(sock, buf, 3) < 0) {
		perror("writing");
		reset();
		return -1;
	}
	return 0;
}

void recvMsgs() {
	static int sel=0,i=0,ret=0;
	static unsigned char buf[4];
	static struct s_msg m;

	static fd_set fds;
	static struct timeval timeout;

	do {
		FD_ZERO(&fds);
		FD_SET(sock,&fds);
		timeout.tv_sec = 0;
		timeout.tv_usec = 0;
		sel = select( sock + 1 , &fds , NULL , NULL , &timeout);
		if ((sel<0) && (errno!=EINTR)) {
			perror("select");
			reset();
		}
		else if (sel && !stop && FD_ISSET(sock, &fds)) {
			ret = read(sock,buf+i,4-i);
			if (ret<0) {
				perror("reading");
				reset();
			}
			else {
				i+=ret;
				if (i==4) {
					if (buf[0] == 1) {
						if (verbose) printf("Disconnect request.\n");
						i = 0;
						reset();
					} else {
						m.t = buf[1];
						m.v = unpacki16(buf+2);
						if (verbose==3) printf("Received msg: %u %i\n",m.t,m.v);
						i = 0;
					}
				}
			}
		}
	} while (!stop && connected && sel && ret>0); //no error happened; select picked up socket state change; read got some data back
}

void catch_signal(int sig)
{
	printf("signal: %i\n",sig);
	stop = 1;
}

long dt_ms = 0;
static struct timespec ts,t1,t2,*dt;

unsigned long c = 0,k = 0;

void avrconnect() {
	/* Create socket on which to send. */
	sock = socket(AF_INET, SOCK_STREAM, 0);
	if (sock < 0) {
		perror("opening socket");<commit_msg>Zero altitude when AVR starts<commit_after>#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <getopt.h>

#include "bmpsensor/bmp180.h"

#include "routines.h"
#include "msg.h"


int ret;
int background = 0;
int stop = 0;
int bs_err = 0;
int initialized = 0;

int connected = 0;
int sock = 0;
char sock_path[256] = "127.0.0.1";
int portno = 1030;
struct sockaddr_in address;
struct hostent *server;

int verbose = 0;
int delay;

void reset() {
	connected = 0;
	close(sock);
	delay = 2500;
}

int sendMsg(int t, int v) {
	static unsigned char buf[3];
	buf[0] = t;
	packi16(buf+1,v);
	if (write(sock, buf, 3) < 0) {
		perror("writing");
		reset();
		return -1;
	}
	return 0;
}

void recvMsgs() {
	static int sel=0,i=0,ret=0;
	static unsigned char buf[4];
	static struct s_msg m;

	static fd_set fds;
	static struct timeval timeout;

	do {
		FD_ZERO(&fds);
		FD_SET(sock,&fds);
		timeout.tv_sec = 0;
		timeout.tv_usec = 0;
		sel = select( sock + 1 , &fds , NULL , NULL , &timeout);
		if ((sel<0) && (errno!=EINTR)) {
			perror("select");
			reset();
		}
		else if (sel && !stop && FD_ISSET(sock, &fds)) {
			ret = read(sock,buf+i,4-i);
			if (ret<0) {
				perror("reading");
				reset();
			}
			else {
				i+=ret;
				if (i==4) {
					i = 0;
					if (buf[0] == 1) {
						if (verbose) printf("Disconnect request.\n");
						reset();
					} else {
						m.t = buf[1];
						m.v = unpacki16(buf+2);
						if (verbose==3) printf("Received msg: %u %i\n",m.t,m.v);
						if (m.t==255 && m.v==1) bs.p0=bs.p;
					}
				}
			}
		}
	} while (!stop && connected && sel && ret>0); //no error happened; select picked up socket state change; read got some data back
}

void catch_signal(int sig)
{
	printf("signal: %i\n",sig);
	stop = 1;
}

long dt_ms = 0;
static struct timespec ts,t1,t2,*dt;

unsigned long c = 0,k = 0;

void avrconnect() {
	/* Create socket on which to send. */
	sock = socket(AF_INET, SOCK_STREAM, 0);
	if (sock < 0) {
		perror("opening socket");
{'fraction_non_alphanumeric': 0.18070652173913043, 'fraction_numerical': 0.030797101449275364, 'mean_word_length': 3.2635135135135136, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5780261', 'n_tokens_mistral': 2113, 'n_tokens_neox': 1832, 'n_words': 487}