correct includes
This commit is contained in:
parent
a685866fbc
commit
b15892d0a0
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -83,6 +83,7 @@ install_manifest.txt
|
|||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
build
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code from the following github repo: https://github.com/ControlEverythingCommunity/TSL2561/blob/master/C/TSL2561.c
|
||||
#include "include/TSL2561.h"
|
||||
#include "./Include/TSL2561.h"
|
||||
|
||||
void printSpectrum(int file)
|
||||
{
|
||||
|
@ -8,15 +8,15 @@ void printSpectrum(int file)
|
|||
char reg[1] = {0x0C | 0x80};
|
||||
write(file, reg, 1);
|
||||
char data[4] = {0};
|
||||
if(read(file, data, 4) != 4)
|
||||
if (read(file, data, 4) != 4)
|
||||
{
|
||||
printf("Erorr : Input/output Erorr \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the data
|
||||
float ch0 = (data[1] * 256 + data[0]); //Full Spectrum(IR + Visible)
|
||||
float ch1 = (data[3] * 256 + data[2]); //Infrared Value
|
||||
float ch0 = (data[1] * 256 + data[0]); // Full Spectrum(IR + Visible)
|
||||
float ch1 = (data[3] * 256 + data[2]); // Infrared Value
|
||||
// Output data to screen
|
||||
printf("Full Spectrum(IR + Visible) : %.1f lux \n", ch0);
|
||||
printf("Infrared Value : %.1f lux \n", ch1);
|
||||
|
@ -31,14 +31,14 @@ float getFullSpectrum(int file)
|
|||
char reg[1] = {0x0C | 0x80};
|
||||
write(file, reg, 1);
|
||||
char data[4] = {0};
|
||||
if(read(file, data, 4) != 4)
|
||||
if (read(file, data, 4) != 4)
|
||||
{
|
||||
printf("Erorr : Input/output Erorr \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the data
|
||||
float ch0 = (data[1] * 256 + data[0]); //Full Spectrum(IR + Visible)
|
||||
float ch0 = (data[1] * 256 + data[0]); // Full Spectrum(IR + Visible)
|
||||
return ch0;
|
||||
}
|
||||
}
|
||||
|
@ -50,14 +50,14 @@ float getInfraredLight(int file)
|
|||
char reg[1] = {0x0C | 0x80};
|
||||
write(file, reg, 1);
|
||||
char data[4] = {0};
|
||||
if(read(file, data, 4) != 4)
|
||||
if (read(file, data, 4) != 4)
|
||||
{
|
||||
printf("Erorr : Input/output Erorr \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the data
|
||||
float ch1 = (data[3] * 256 + data[2]); //Infrared Value
|
||||
float ch1 = (data[3] * 256 + data[2]); // Infrared Value
|
||||
return ch1;
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ float getInfraredLight(int file)
|
|||
int init_TSL2561(char *bus)
|
||||
{
|
||||
int file;
|
||||
if((file = open(bus, O_RDWR)) < 0)
|
||||
if ((file = open(bus, O_RDWR)) < 0)
|
||||
{
|
||||
printf("Failed to open the bus. \n");
|
||||
exit(1);
|
||||
|
@ -92,16 +92,17 @@ void TSL2561()
|
|||
int fe = 1;
|
||||
int file;
|
||||
file = init_TSL2561(bus);
|
||||
while(1)
|
||||
while (1)
|
||||
{
|
||||
sleep(1/fe);
|
||||
sleep(1 / fe);
|
||||
float a = getFullSpectrum(file);
|
||||
float b = getInfraredLight(file);
|
||||
printf("%.1f\n",a);
|
||||
printf("%.1f\n",b);
|
||||
printf("%.1f\n", a);
|
||||
printf("%.1f\n", b);
|
||||
printSpectrum(file);
|
||||
}
|
||||
}
|
||||
void main(){
|
||||
void main()
|
||||
{
|
||||
TSL2561();
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
#include "include/average.h"
|
||||
#include "include/getArray.h"
|
||||
#include "include/fileGestion.h"
|
||||
#include "include/initialParameters.h"
|
||||
#include "include/queue.h"
|
||||
#include "./Include/average.h"
|
||||
#include "./Include/getArray.h"
|
||||
#include "./Include/fileGestion.h"
|
||||
#include "./Include/initialParameters.h"
|
||||
#include "./Include/queue.h"
|
||||
/**
|
||||
* @brief realize the average calcul
|
||||
*
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "include/b2hd.h"
|
||||
#include "./Include/b2hd.h"
|
||||
#include <time.h>
|
||||
|
||||
|
||||
|
||||
int64_t millis(){
|
||||
//struct timespec now;
|
||||
struct timespec *now = (struct timespec *) malloc(sizeof(struct timespec));
|
||||
//timespec_get(&now, TIME_UTC);
|
||||
int64_t millis()
|
||||
{
|
||||
// struct timespec now;
|
||||
struct timespec *now = (struct timespec *)malloc(sizeof(struct timespec));
|
||||
// timespec_get(&now, TIME_UTC);
|
||||
timespec_get(now, TIME_UTC);
|
||||
|
||||
//#ifdef __USE_ISOC11 ????
|
||||
int64_t tmp = (((int64_t) now->tv_sec) * 1000 + ((int64_t) now->tv_nsec) / ((int64_t) 1000000));
|
||||
// #ifdef __USE_ISOC11 ????
|
||||
int64_t tmp = (((int64_t)now->tv_sec) * 1000 + ((int64_t)now->tv_nsec) / ((int64_t)1000000));
|
||||
free(now);
|
||||
return tmp;
|
||||
}
|
||||
|
@ -29,37 +28,46 @@ void b2hd()
|
|||
uint32_t valbin[8];
|
||||
quartet value;
|
||||
|
||||
while (fread(&buff, 26, 1, stdin)) {
|
||||
fprintf(stdout , "%ld,", millis());
|
||||
for (int i = 1; i < 9; i++){
|
||||
while (fread(&buff, 26, 1, stdin))
|
||||
{
|
||||
fprintf(stdout, "%ld,", millis());
|
||||
for (int i = 1; i < 9; i++)
|
||||
{
|
||||
/*buff[25] = '\0';*/
|
||||
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
|
||||
if (!(fread(&buff2, 18, 1, stdin))) {
|
||||
if (strncmp(buff, "#################\n", (size_t)18) == 0)
|
||||
{
|
||||
if (!(fread(&buff2, 18, 1, stdin)))
|
||||
{
|
||||
fprintf(stderr, "Erreur lesture après ###...#");
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/*buff2[17] = '\0';*/
|
||||
strncpy(buff, &buff[18], 8);
|
||||
strncpy(&buff[8], buff2, 18);
|
||||
}
|
||||
}
|
||||
value.octet1 = buff[3*i+1];
|
||||
value.octet2 = buff[3*i+2];
|
||||
value.octet3 = buff[3*i+3];
|
||||
value.octet1 = buff[3 * i + 1];
|
||||
value.octet2 = buff[3 * i + 2];
|
||||
value.octet3 = buff[3 * i + 3];
|
||||
value.octet4 = 0;
|
||||
/*memcpy(&values[i], &value, sizeof(quartet));*/
|
||||
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
|
||||
valbin[i] = buff[3 * i + 1] * 256 * 256 * 256 + buff[3 * i + 2] * 256 * 256 + buff[3 * i + 3] * 256;
|
||||
memcpy(&values[i], &valbin[i], sizeof(uint32_t));
|
||||
if(i<8){
|
||||
fprintf(stdout, "%d,", values[i]/256);
|
||||
if (i < 8)
|
||||
{
|
||||
fprintf(stdout, "%d,", values[i] / 256);
|
||||
}
|
||||
else{
|
||||
fprintf(stdout, "%d\n", values[i]/256);
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "%d\n", values[i] / 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc , char** argv){
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
b2hd();
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void writeCaptorNumber(int N)
|
||||
{
|
||||
fprintf(stdout ,"{\n\"captorNumber\" : %d , " , N);
|
||||
}
|
||||
|
||||
void writeTimeArray()
|
||||
{
|
||||
while
|
||||
}
|
||||
|
||||
void writeValuesArray(int N)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
}
|
|
@ -5,14 +5,14 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "include/fileGestion.h"
|
||||
#include "include/getArray.h"
|
||||
#include "include/growthRate.h"
|
||||
#include "include/power.h"
|
||||
#include "include/simulateFlux.h"
|
||||
#include "include/queue.h"
|
||||
#include "include/average.h"
|
||||
//#include "b2hd.h"
|
||||
#include "./Include/fileGestion.h"
|
||||
#include "./Include/getArray.h"
|
||||
#include "./Include/growthRate.h"
|
||||
#include "./Include/power.h"
|
||||
#include "./Include/simulateFlux.h"
|
||||
#include "./Include/queue.h"
|
||||
#include "./Include/average.h"
|
||||
// #include "b2hd.h"
|
||||
|
||||
bool rawDataWriteFlag;
|
||||
int nRowRawData = 500;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "include/fileGestion.h"
|
||||
#include "./Include/fileGestion.h"
|
||||
|
||||
/**
|
||||
* @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "include/getArray.h"
|
||||
#include "include/fileGestion.h"
|
||||
#include "include/initialParameters.h"
|
||||
#include "./Include/getArray.h"
|
||||
#include "./Include/fileGestion.h"
|
||||
#include "./Include/initialParameters.h"
|
||||
// #include <string.h>
|
||||
|
||||
long **getlongArray(int N, int M) /* Allocate the array */
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
#include "include/initialParameters.h"
|
||||
#include "include/fileGestion.h"
|
||||
#include "include/getArray.h"
|
||||
#include "include/growthRate.h"
|
||||
#include "./Include/initialParameters.h"
|
||||
#include "./Include/fileGestion.h"
|
||||
#include "./Include/getArray.h"
|
||||
#include "./Include/growthRate.h"
|
||||
/**
|
||||
* @brief calculate de growth rate between to point next to each other
|
||||
*
|
||||
* @param dataArray array with data of points next to each other for each captor (dim : 2 * nCols)
|
||||
* @param gRateArray array that contaigns results of the growth ratecalculation
|
||||
*/
|
||||
void growthRateCalculation(double **dataArray , double *gRateArray){
|
||||
for(int i = 0 ; i < nCol-1 ; i++){
|
||||
void growthRateCalculation(double **dataArray, double *gRateArray)
|
||||
{
|
||||
for (int i = 0; i < nCol - 1; i++)
|
||||
{
|
||||
gRateArray[i] = (dataArray[0][i] - dataArray[1][i]) / period;
|
||||
}
|
||||
}
|
||||
|
@ -18,17 +20,21 @@ void growthRateCalculation(double **dataArray , double *gRateArray){
|
|||
*
|
||||
* @param dataLign
|
||||
*/
|
||||
void growthRateFunction(double **dataLign , char* fileName){
|
||||
double gRateArray[nCol-1];
|
||||
growthRateCalculation(dataLign , gRateArray);
|
||||
appendDataInFile(fileName,gRateArray , nCol-1);
|
||||
void growthRateFunction(double **dataLign, char *fileName)
|
||||
{
|
||||
double gRateArray[nCol - 1];
|
||||
growthRateCalculation(dataLign, gRateArray);
|
||||
appendDataInFile(fileName, gRateArray, nCol - 1);
|
||||
}
|
||||
|
||||
void sumColArray(long **p, double res[] , int N , int M){
|
||||
for(int i = 1; i < M; i++){
|
||||
void sumColArray(long **p, double res[], int N, int M)
|
||||
{
|
||||
for (int i = 1; i < M; i++)
|
||||
{
|
||||
int j = 0;
|
||||
res[i] = 0;
|
||||
while(j < N){
|
||||
while (j < N)
|
||||
{
|
||||
res[i] += p[i][j];
|
||||
j++;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "include/simulateFlux.h"
|
||||
#include "include/power.h"
|
||||
#include "include/initialParameters.h"
|
||||
#include "include/queue.h"
|
||||
#include "include/average.h"
|
||||
#include "include/growthRate.h"
|
||||
#include "include/getArray.h"
|
||||
#include "./Include/simulateFlux.h"
|
||||
#include "./Include/power.h"
|
||||
#include "./Include/initialParameters.h"
|
||||
#include "./Include/queue.h"
|
||||
#include "./Include/average.h"
|
||||
#include "./Include/growthRate.h"
|
||||
#include "./Include/getArray.h"
|
||||
|
||||
bool rawDataWriteFlag;
|
||||
int nRowRawData = 5000;
|
||||
|
@ -146,8 +146,10 @@ int main(int argc, char **argv)
|
|||
}
|
||||
printf("%d", nCol);
|
||||
|
||||
for(int i = 0 ; i < 8 ; i++){
|
||||
if(selectionCaptors[i]){
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (selectionCaptors[i])
|
||||
{
|
||||
nCol++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "include/power.h"
|
||||
#include "include/getArray.h"
|
||||
#include "include/fileGestion.h"
|
||||
#include "include/initialParameters.h"
|
||||
#include "include/queue.h"
|
||||
#include "./Include/power.h"
|
||||
#include "./Include/getArray.h"
|
||||
#include "./Include/fileGestion.h"
|
||||
#include "./Include/initialParameters.h"
|
||||
#include "./Include/queue.h"
|
||||
|
||||
/**
|
||||
* @brief realize the powerThreadFunction calcul
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "include/queue.h"
|
||||
#include "./Include/queue.h"
|
||||
|
||||
/**
|
||||
* @brief struct queue struct used for queueing string name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "include/simulateFlux.h"
|
||||
#include "include/initialParameters.h"
|
||||
#include "include/queue.h"
|
||||
#include "./Include/simulateFlux.h"
|
||||
#include "./Include/initialParameters.h"
|
||||
#include "./Include/queue.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
@ -212,7 +212,7 @@ void *threadSimulateFlux(void *vargp)
|
|||
// prepare next file now
|
||||
fileName = createNewRawDataFileName();
|
||||
rawDataFile = fopen(fileName, "w+");
|
||||
//add test to get p then print it here // p is gotten from fileName file
|
||||
// add test to get p then print it here // p is gotten from fileName file
|
||||
}
|
||||
}
|
||||
rawDataWriteFlag = false;
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
##Imports
|
||||
|
||||
import sqlite3 as sql
|
||||
import pandas as pd
|
||||
import os
|
||||
import datetime
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
def createMetadataTable():
|
||||
"""Create the db table which contaign all data """
|
||||
db = sql.connect("robotgowestdb.db")
|
||||
c = db.cursor()
|
||||
|
||||
requestCreate = '''CREATE TABLE IF NOT EXISTS METADATA_TABLE (
|
||||
[Id] INTEGER PRIMARY KEY,
|
||||
[Place] TEXT,
|
||||
[Start] TEXT
|
||||
)'''
|
||||
c.execute(requestCreate)
|
||||
db.commit()
|
||||
|
||||
def insertMetadataElement(place : str , start : datetime):
|
||||
"""Insert a new element in the metadat table
|
||||
|
||||
Args:
|
||||
currency (str): name of the currency to fetch its metadata with the yFinance API
|
||||
"""
|
||||
db = sql.connect("robotgowestdb.db")
|
||||
c = db.cursor()
|
||||
request = f'''INSERT INTO METADATA_TABLE (Place,Start)
|
||||
VALUES (
|
||||
'{place}',
|
||||
'{start}'
|
||||
)'''
|
||||
c.execute(request)
|
||||
db.commit()
|
||||
|
||||
createMetadataTable()
|
||||
insertMetadataElement("ici", datetime.datetime.now())
|
124
Db-Script/database.c
Normal file
124
Db-Script/database.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
#include "./database.h"
|
||||
|
||||
int openDb(sqlite3 *db)
|
||||
{
|
||||
|
||||
int rc = sqlite3_open("robotgowest.db", &db);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int initializeTrailsAndCaptorMetadataTables()
|
||||
{
|
||||
sqlite3 *db;
|
||||
char *err_msg = 0;
|
||||
int rc;
|
||||
if (!openDb(db))
|
||||
{
|
||||
char *sql = "DROP TABLE IF EXISTS Trials;"
|
||||
"DROP TABLE IF EXISTS CaptorMetadata;"
|
||||
"CREATE TABLE Trials(Id INTEGER PRIMARY KEY AUTOINCREMENT, Position TEXT, Start INT, Frequency NUMBER, Duration INT);"
|
||||
"CREATE TABLE CaptorMetadata(Id INTEGER PRIMARY KEY AUTOINCREMENT, CaptorNumber INT, TrialId INT, FOREIGN KEY (TrialId) REFERENCES Trials(Id));";
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql, 0, 0, &err_msg);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
|
||||
fprintf(stderr, "SQL error: %s\n", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int createCaptorDataTable(int trialId, int captorNumber)
|
||||
{
|
||||
sqlite3 *db;
|
||||
char *err_msg = 0;
|
||||
int rc;
|
||||
|
||||
// Create Table Name
|
||||
char tableName[8];
|
||||
strcpy(tableName, "T");
|
||||
strcat(tableName, convertIntegerToChar(trialId));
|
||||
strcat(tableName, "C");
|
||||
strcat(tableName, convertIntegerToChar(captorNumber));
|
||||
strcat(tableName, "Data");
|
||||
|
||||
if (!openDb(db))
|
||||
{
|
||||
char sql[101] = "CREATE TABLE ";
|
||||
strcat(sql, tableName);
|
||||
strcat(sql, " (Id INTEGER PRIMARY KEY AUTOINCREMENT, Lux NUMBER, Mean NUMBER , Power NUMBER);");
|
||||
rc = sqlite3_exec(db, sql, 0, 0, &err_msg);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
printf("Error code : %i", rc);
|
||||
fprintf(stderr, "SQL error: %s\n", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief convert an interger N into a char*
|
||||
*
|
||||
* @param N
|
||||
* @return char*
|
||||
*/
|
||||
char *convertIntegerToChar(int N)
|
||||
{
|
||||
// Count digits in number N
|
||||
int m = N;
|
||||
int digit = 0;
|
||||
while (m)
|
||||
{
|
||||
digit++;
|
||||
m /= 10;
|
||||
}
|
||||
char *arr;
|
||||
char arr1[digit];
|
||||
arr = (char *)malloc(digit * sizeof(char));
|
||||
int index = 0;
|
||||
while (N)
|
||||
{
|
||||
arr1[++index] = N % 10 + '0';
|
||||
N /= 10;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < index; i++)
|
||||
{
|
||||
arr[i] = arr1[index - i];
|
||||
}
|
||||
arr[i] = '\0';
|
||||
return (char *)arr;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
initializeTrailsAndCaptorMetadataTables();
|
||||
// createCaptorDataTable(1, 1);
|
||||
}
|
14
Db-Script/database.h
Normal file
14
Db-Script/database.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <sqlite3.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Duplication from simulFlux.c
|
||||
|
||||
/**
|
||||
* @brief convert an interger N into a char*
|
||||
*
|
||||
* @param N
|
||||
* @return char*
|
||||
*/
|
||||
char *convertIntegerToChar(int N);
|
1
Db-Script/database.py
Normal file
1
Db-Script/database.py
Normal file
|
@ -0,0 +1 @@
|
|||
##This mist include all fetch function and also init and insert function for nn training annd testing result
|
BIN
Db-Script/db
Executable file
BIN
Db-Script/db
Executable file
Binary file not shown.
0
Db-Script/robotgowest.db
Normal file
0
Db-Script/robotgowest.db
Normal file
Loading…
Reference in a new issue