cleanup old code
This commit is contained in:
68
gpio.c
68
gpio.c
@@ -224,74 +224,6 @@ int gpio_initrelay(unsigned int relay, cfg_bool_t relayinvert){
|
||||
}
|
||||
|
||||
|
||||
//void timerhandler(int signal){
|
||||
// if (signal == SIGALRM) {
|
||||
//relayswitchflag = 1;
|
||||
//displaytime = 0;
|
||||
// printf("Timer handler\n");
|
||||
|
||||
// }else{
|
||||
// char *log;
|
||||
// if(asprintf(&log, "Timerhandler: wrong signal returned: %d\n", signal) > 0 ){
|
||||
// writesyslog(LOG_ERR, log);
|
||||
// }
|
||||
// free(log);
|
||||
// }
|
||||
//}
|
||||
|
||||
//void starttimer(unsigned int switchtime){
|
||||
// if(switchtime > 0){
|
||||
// if (signal(SIGALRM, timerhandler) == SIG_ERR){
|
||||
// writesyslog(LOG_ERR, "starttimer - can't catch SIGALRM\n");
|
||||
// }
|
||||
// alarm(switchtime);
|
||||
// }else{
|
||||
//relayswitchflag = 1;
|
||||
// }
|
||||
//}
|
||||
|
||||
//int gpio_switchrelay(int state, unsigned int relay, cfg_bool_t relayinvert){
|
||||
// if(state == RELAY_ON){
|
||||
// if (relayinvert == cfg_false){
|
||||
//#ifdef TEST
|
||||
// printf("Relay %d - HIGH\n", relay);
|
||||
//#endif
|
||||
// if(GPIOWrite(relaypin[relay], HIGH) < 0){
|
||||
// return(-1);
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
//#ifdef TEST
|
||||
// printf("Relay %d - LOW\n", relay);
|
||||
//#endif
|
||||
// if(GPIOWrite(relaypin[relay], LOW) < 0){
|
||||
// return(-1);
|
||||
// }
|
||||
// }//
|
||||
// }
|
||||
// else{
|
||||
// if (relayinvert == cfg_false){
|
||||
//#ifdef TEST
|
||||
// printf("Relay %d - LOW\n", relay);
|
||||
//#endif
|
||||
// if(GPIOWrite(relaypin[relay], LOW) < 0){
|
||||
// return(-1);
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
//#ifdef TEST
|
||||
// printf("Relay %d - HIGH\n", relay);
|
||||
//#endif
|
||||
// if(GPIOWrite(relaypin[relay], HIGH) < 0){
|
||||
// return(-1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return(0);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
unsigned int inputsysfs[9] = {0, 2, 2, 2, 2, 2, 2, 2, 2}; //SYSFS export number
|
||||
unsigned int inputpin[9] = {0, 2, 2, 2, 2, 2, 2, 2, 2}; //PortA number
|
||||
|
||||
8
inputs.c
8
inputs.c
@@ -101,17 +101,13 @@ void *readinputs(void *ptr){
|
||||
clear_display();
|
||||
write_display(ln[1], 0, 0, "Manual open");
|
||||
char *ln2;
|
||||
asprintf(&ln2, "In: %ld - Relay: %ld",config->manualinput, config->relay);
|
||||
asprintf(&ln2, "In: %ld - Relay: %ld", config->manualinput, config->relay);
|
||||
write_display(ln[2], 0, 0, ln2);
|
||||
free(ln2);
|
||||
display_timer(config->switchtime);
|
||||
|
||||
writesyslog(LOG_INFO, "Manual open");
|
||||
server_send_log(config, "Manual open");
|
||||
|
||||
//wait
|
||||
//sleep((unsigned int)config->switchtime);
|
||||
|
||||
//clear_display();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
log.c
8
log.c
@@ -5,7 +5,6 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <json-c/json.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include "config.h"
|
||||
@@ -110,11 +109,6 @@ void write_display(int line, int pos, int invert, char *txt){
|
||||
}
|
||||
|
||||
void display_timer_handler(union sigval arg){
|
||||
printf("display timer handler\n");
|
||||
//struct config_t *config = (struct config_t *)arg.sival_ptr;
|
||||
//printf("relay: %ld\n", config->relay);
|
||||
//printf("relay invert: %d\n", config->relayinvert);
|
||||
//relay_switch(RELAY_OFF, 0, config);
|
||||
clear_display();
|
||||
}
|
||||
|
||||
@@ -124,8 +118,6 @@ void display_timer(int time){
|
||||
struct sigevent se;
|
||||
|
||||
se.sigev_notify = SIGEV_THREAD;
|
||||
//se.sigev_value.sival_ptr = config;
|
||||
|
||||
se.sigev_notify_function = display_timer_handler;
|
||||
se.sigev_notify_attributes = NULL;
|
||||
|
||||
|
||||
81
main.c
81
main.c
@@ -1,16 +1,10 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <sys/file.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include "runtime.h"
|
||||
#include "config.h"
|
||||
@@ -26,38 +20,6 @@
|
||||
|
||||
#define STARTMSG "Starting acsreader version " VERSION
|
||||
|
||||
//volatile unsigned int dooropenflag = 0;
|
||||
//volatile unsigned int relayswitchflag = 0;
|
||||
//volatile int displaytime;
|
||||
|
||||
//void timerhandler(int signal){
|
||||
// if (signal == SIGALRM) {
|
||||
// relayswitchflag = 1;
|
||||
// displaytime = 0;
|
||||
// }else{
|
||||
// char *log;
|
||||
// if(asprintf(&log, "Timerhandler: wrong signal returned: %d\n", signal) > 0 ){
|
||||
// writesyslog(LOG_ERR, log);
|
||||
// }
|
||||
// free(log);
|
||||
// }
|
||||
//}
|
||||
|
||||
//void starttimer(unsigned int switchtime){
|
||||
// if(switchtime > 0){
|
||||
// if (signal(SIGALRM, timerhandler) == SIG_ERR){
|
||||
// writesyslog(LOG_ERR, "starttimer - can't catch SIGALRM\n");
|
||||
// }
|
||||
// alarm(switchtime);
|
||||
// }else{
|
||||
// relayswitchflag = 1;
|
||||
// }
|
||||
//}
|
||||
|
||||
//void set_displaytime(int time){
|
||||
// displaytime = time;
|
||||
//}
|
||||
|
||||
/*********************************/
|
||||
/* MAIN */
|
||||
/**********************************/
|
||||
@@ -66,7 +28,7 @@ int main(int argc, char **argv){
|
||||
clear_display();
|
||||
write_display(ln[1], 0, 0, "Starting");
|
||||
write_display(ln[2], 0, 0, "ACSreader");
|
||||
//set_displaytime(100);
|
||||
display_timer(5);
|
||||
|
||||
createpidfile("/var/run/acsreader.pid");
|
||||
sighandlerinit();
|
||||
@@ -153,24 +115,24 @@ int main(int argc, char **argv){
|
||||
pthread_mutex_init(&sharedbuffermutex, NULL);
|
||||
pthread_cond_init (&sharedbuffersignal, NULL);
|
||||
|
||||
int ret = pthread_create( &watchthread, NULL, serialdatawatch, (void*) &config);
|
||||
int ret = pthread_create(&watchthread, NULL, serialdatawatch, (void*) &config);
|
||||
if(ret){
|
||||
printf("Error - pthread_create() return code: %d\n",ret);
|
||||
printf("Error - watchthread pthread_create() return code: %d\n",ret);
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
ret = pthread_create( &serialthread1, NULL, readserialport, (void*) &serial1);
|
||||
ret = pthread_create(&serialthread1, NULL, readserialport, (void*) &serial1);
|
||||
if(ret){
|
||||
printf("Error - pthread_create() return code: %d\n",ret);
|
||||
printf("Error - serialthread1 pthread_create() return code: %d\n",ret);
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
ret = pthread_create( &serialthread2, NULL, readserialport, (void*) &serial2);
|
||||
ret = pthread_create(&serialthread2, NULL, readserialport, (void*) &serial2);
|
||||
if(ret){
|
||||
printf("Error - pthread_create() return code: %d\n",ret);
|
||||
printf("Error - serialthread2 pthread_create() return code: %d\n",ret);
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
ret = pthread_create( &inputsthread, NULL, readinputs, (void*) &config);
|
||||
ret = pthread_create(&inputsthread, NULL, readinputs, (void*) &config);
|
||||
if(ret){
|
||||
printf("Error - pthread_create() return code: %d\n",ret);
|
||||
printf("Error - imputsthread pthread_create() return code: %d\n",ret);
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -179,32 +141,7 @@ int main(int argc, char **argv){
|
||||
pthread_join(serialthread2, NULL);
|
||||
pthread_join(inputsthread, NULL);
|
||||
|
||||
//
|
||||
do {
|
||||
printf("can not happen\n");
|
||||
|
||||
//relay switch action
|
||||
//if(relayswitchflag == 1){
|
||||
//if(gpio_switchrelay(RELAY_OFF, (unsigned int)config.relay, config.relayinvert) == ERROR){
|
||||
// exitprogram(EXIT_FAILURE);
|
||||
//}
|
||||
// if(mf700_controlcommand(&serial1.fd, EVERYLEDOFF) == ERROR){
|
||||
// exitprogram(EXIT_FAILURE);
|
||||
// }
|
||||
// if(mf700_controlcommand(&serial2.fd, EVERYLEDOFF) == ERROR){
|
||||
// exitprogram(EXIT_FAILURE);
|
||||
// }
|
||||
// server_send_lockstate(&config, LOCKED);
|
||||
// relayswitchflag = 0;
|
||||
// dooropenflag = 0;
|
||||
//}
|
||||
|
||||
//display timer
|
||||
//if(displaytime == 0){
|
||||
// clear_display();
|
||||
// displaytime = -1;
|
||||
//}else if(displaytime > 0){
|
||||
// displaytime--;
|
||||
//}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
9
mf700.c
9
mf700.c
@@ -12,15 +12,11 @@
|
||||
|
||||
|
||||
void mf700_timer_handler(union sigval arg){
|
||||
//printf("mf700 timer_handler\n");
|
||||
//printf("mf700 sigval ptr %p\n", arg.sival_ptr);
|
||||
|
||||
int *serial = (int *)arg.sival_ptr;
|
||||
mf700_controlcommand(serial, 0, EVERYLEDOFF);
|
||||
free(serial);
|
||||
}
|
||||
|
||||
|
||||
void mf700_timer(unsigned int i, int *serial){
|
||||
timer_t timer_id;
|
||||
struct itimerspec ts;
|
||||
@@ -29,11 +25,6 @@ void mf700_timer(unsigned int i, int *serial){
|
||||
int *ptr = malloc(sizeof(int *));
|
||||
*ptr = *serial;
|
||||
|
||||
//printf("serial pointer: %p\n", (void *)serial);
|
||||
//printf("serial data: %d\n", *serial);
|
||||
//printf("ptr pointer: %p\n", (void *)ptr);
|
||||
//printf("ptr data: %d\n", *ptr);
|
||||
|
||||
se.sigev_notify = SIGEV_THREAD;
|
||||
se.sigev_value.sival_ptr = ptr;
|
||||
se.sigev_notify_function = mf700_timer_handler;
|
||||
|
||||
15
reader.c
15
reader.c
@@ -24,18 +24,13 @@ void readerrequest(struct reader_t *reader, struct config_t *config){
|
||||
server_credential_request(reader, config);
|
||||
|
||||
#ifdef TEST
|
||||
//printf("retdata Device: %s\n", retdata.device);
|
||||
//printf("retdata UID: %s\n", retdata.uid);
|
||||
printf("Cardnumber: %d\n", reader->cardnumber);
|
||||
//printf("retdata Sectorkey: %s\n", retdata.sectorkey);
|
||||
printf("Opentime: %d\n", reader->opentime);
|
||||
printf("State: %d\n", reader->state);
|
||||
printf("server: %s\n", reader->config->serveraddress);
|
||||
#endif
|
||||
|
||||
int state = reader->state;
|
||||
|
||||
if(state == ACCESSGRANTED){
|
||||
if(reader->state == ACCESSGRANTED){
|
||||
if(mf700_controlcommand(&reader->fd, (unsigned int)reader->opentime, GREENLED1BEEP) == ERROR){
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
@@ -56,7 +51,7 @@ void readerrequest(struct reader_t *reader, struct config_t *config){
|
||||
}
|
||||
free(log);
|
||||
}
|
||||
else if(state == ACCESSDENIED){
|
||||
else if(reader->state == ACCESSDENIED){
|
||||
if(mf700_controlcommand(&reader->fd, 2, REDLED3BEEPS) == ERROR){
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
@@ -74,7 +69,7 @@ void readerrequest(struct reader_t *reader, struct config_t *config){
|
||||
}
|
||||
free(log);
|
||||
}
|
||||
else if (state == UNKNOWNERROR || state == CONNECTIONTIMEOUT || state == RESOLVEERROR || state == SERVERERROR || state == CREDENTIALERROR){
|
||||
else if (reader->state == UNKNOWNERROR || reader->state == CONNECTIONTIMEOUT || reader->state == RESOLVEERROR || reader->state == SERVERERROR || reader->state == CREDENTIALERROR){
|
||||
if(mf700_controlcommand(&reader->fd, 0, EVERYLEDON) == ERROR){
|
||||
exitprogram(EXIT_FAILURE);
|
||||
}
|
||||
@@ -85,7 +80,7 @@ void readerrequest(struct reader_t *reader, struct config_t *config){
|
||||
char *log;
|
||||
char *ln1, *ln2;
|
||||
int len = 0;
|
||||
switch(state){
|
||||
switch(reader->state){
|
||||
case UNKNOWNERROR:
|
||||
len = asprintf(&log, "Unknown error");
|
||||
asprintf(&ln1, "Unknown error");
|
||||
@@ -128,7 +123,7 @@ void readerrequest(struct reader_t *reader, struct config_t *config){
|
||||
free(log);
|
||||
}else{
|
||||
char *log;
|
||||
if(asprintf(&log, "Unknown state from server: %d\n", state) > 0 ){
|
||||
if(asprintf(&log, "Unknown state from server: %d\n", reader->state) > 0 ){
|
||||
writesyslog(LOG_ERR, log);
|
||||
}
|
||||
free(log);
|
||||
|
||||
4
relay.c
4
relay.c
@@ -9,7 +9,6 @@
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include "gpio.h"
|
||||
#include "log.h"
|
||||
@@ -21,10 +20,7 @@
|
||||
|
||||
void relay_timer_handler(union sigval arg){
|
||||
struct config_t *config = (struct config_t *)arg.sival_ptr;
|
||||
//printf("relay: %ld\n", config->relay);
|
||||
//printf("relay invert: %d\n", config->relayinvert);
|
||||
relay_switch(RELAY_OFF, 0, config);
|
||||
//server_send_lockstate(config, UNLOCKED);
|
||||
}
|
||||
|
||||
void relay_timer(int time, struct config_t *config){
|
||||
|
||||
20
serial.c
20
serial.c
@@ -114,19 +114,6 @@ void *serialdatawatch(void *ptr){
|
||||
//wait for signal from serial read
|
||||
pthread_cond_wait(&sharedbuffersignal, &sharedbuffermutex);
|
||||
|
||||
//printf("buffer watch %s\n", sharedbuffer.buff);
|
||||
//printf("reader %d\n", sharedbuffer.reader);
|
||||
//printf("server = %s\n", config->serveraddress);
|
||||
//procesReaderData(buffer, &config, &serial->fd);
|
||||
|
||||
//struct reader_t *reader = malloc(sizeof(struct reader_t));
|
||||
//reader->fd = sharedbuffer.fd;
|
||||
//reader->reader = sharedbuffer.reader;
|
||||
//reader->config = config;
|
||||
//memcpy(reader->buff, sharedbuffer.buff, sizeof(reader->buff));
|
||||
|
||||
//readerrequest(reader, config);
|
||||
|
||||
struct reader_t reader;
|
||||
reader.fd = sharedbuffer.fd;
|
||||
reader.reader = sharedbuffer.reader;
|
||||
@@ -135,15 +122,8 @@ void *serialdatawatch(void *ptr){
|
||||
|
||||
readerrequest(&reader, config);
|
||||
|
||||
//if(mf700_controlcommand(&sharedbuffer.fd, GREENLED1BEEP) == ERROR){
|
||||
// exitprogram(EXIT_FAILURE);
|
||||
//}
|
||||
//if(gpio_switchrelay(RELAY_ON, (unsigned int)config->relay, config->relayinvert) == ERROR){
|
||||
// exitprogram(EXIT_FAILURE);
|
||||
//}
|
||||
//remove all credential data from buffer
|
||||
memset(&sharedbuffer, 0, sizeof(struct serialport_t));
|
||||
//free(reader);
|
||||
|
||||
pthread_mutex_unlock(&sharedbuffermutex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user