-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor canbus_iotbridge to passthru_iotbridge. Replace awsiot_clien…
…t with passthru_shadow. Add file logger.
- Loading branch information
Jeremy Hahn
committed
May 4, 2016
1 parent
d666d3f
commit 25c75c4
Showing
19 changed files
with
573 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "canbus_filelogger.h" | ||
|
||
void *canbus_filelogger_thread(void *ptr) { | ||
|
||
syslog(LOG_DEBUG, "canbus_filelogger_thread: running"); | ||
|
||
canbus_log_open(); | ||
|
||
logger *pLogger = (logger *)ptr; | ||
|
||
int can_frame_len = sizeof(struct can_frame); | ||
struct can_frame frame; | ||
memset(&frame, 0, can_frame_len); | ||
|
||
int data_len = can_frame_len + 25; | ||
char data[data_len]; | ||
memset(data, 0, data_len); | ||
|
||
while((pLogger->canbus->state & CANBUS_STATE_CONNECTED) && | ||
canbus_read(pLogger->canbus, &frame) > 0) { | ||
|
||
memset(data, 0, data_len); | ||
canbus_framecpy(&frame, data); | ||
|
||
if(frame.can_id & CAN_ERR_FLAG) { | ||
syslog(LOG_ERR, "canbus_filelogger_thread: CAN ERROR: %s", data); | ||
continue; | ||
} | ||
|
||
canbus_log_write(data); | ||
} | ||
|
||
canbus_log_close(); | ||
syslog(LOG_DEBUG, "canbus_filelogger_thread: stopping"); | ||
return NULL; | ||
} | ||
|
||
unsigned int canbus_filelogger_run(logger *logger) { | ||
canbus_connect(logger->canbus); | ||
if(!canbus_isconnected(logger->canbus)) { | ||
syslog(LOG_CRIT, "canbus_filelogger_run: unable to connect to CAN"); | ||
return 1; | ||
} | ||
pthread_create(&logger->canbus_thread, NULL, canbus_filelogger_thread, (void *)logger); | ||
pthread_join(logger->canbus_thread, NULL); | ||
syslog(LOG_DEBUG, "canbus_filelogger_run: logger closed"); | ||
return 0; | ||
} | ||
|
||
unsigned int canbus_filelogger_cancel(logger *logger) { | ||
return pthread_cancel(logger->canbus_thread); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef CANBUSFILELOGGER_H | ||
#define CANBUSFILELOGGER_H | ||
|
||
#include "canbus_logger_interface.h" | ||
|
||
unsigned int canbus_filelogger_run(logger *logger); | ||
unsigned int canbus_filelogger_cancel(logger *logger); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "canbus_log.h" | ||
|
||
//FILE *canbus_log; | ||
|
||
char* canbus_log_datestamp() { | ||
char buf[1000]; | ||
time_t now = time(0); | ||
struct tm tm = *gmtime(&now); | ||
strftime(buf, sizeof buf, "%a, %d %b %Y %H:%M:%S %Z", &tm); | ||
return buf; | ||
} | ||
|
||
void canbus_log_open() { | ||
char filename[1050]; | ||
snprintf(filename, 1000, canbus_log_datestamp()); | ||
strcat(filename, ".log"); | ||
canbus_log = fopen(filename, "w"); | ||
if(canbus_log == NULL) { | ||
syslog(LOG_ERR, "canbus_log_open: Unable to open log file: %s", filename); | ||
return; | ||
} | ||
} | ||
|
||
int canbus_log_write(char *data) { | ||
return fprintf(canbus_log, data); | ||
} | ||
|
||
void canbus_log_close() { | ||
fclose(canbus_log); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef CANBUSLOG_H | ||
#define CANBUSLOG_H | ||
|
||
#include <stdio.h> | ||
#include <syslog.h> | ||
#include <time.h> | ||
|
||
FILE *canbus_log; | ||
|
||
void canbus_log_open(); | ||
int canbus_log_write(char *data); | ||
void canbus_log_close(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "canbus_logger.h" | ||
|
||
unsigned int canbus_logger_run(logger *logger) { | ||
canbus_filelogger_run(logger); | ||
} | ||
|
||
unsigned int canbus_logger_cancel(logger *logger) { | ||
canbus_filelogger_run(logger); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef CANBUSLOGGER_H | ||
#define CANBUSLOGGER_H | ||
|
||
#include "canbus_logger_interface.h" | ||
|
||
unsigned int canbus_logger_run(logger *logger); | ||
unsigned int canbus_logger_cancel(logger *logger); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* ecutools: IoT Automotive Tuning, Diagnostics & Analytics | ||
* Copyright (C) 2014 Jeremy Hahn | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef CANBUSLOGGERINTERFACE_H | ||
#define CANBUSLOGGERINTERFACE_H | ||
|
||
#include <stdint.h> | ||
#include <pthread.h> | ||
#include "canbus.h" | ||
|
||
typedef struct _logger { | ||
uint8_t canbus_flags; | ||
pthread_t canbus_thread; | ||
struct canbus_filter *filters[10]; | ||
canbus_client *canbus; | ||
} logger; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.