chg: clean up

This commit is contained in:
iceman1001 2018-01-17 00:30:43 +01:00
commit d60721d131

View file

@ -51,14 +51,17 @@ int ukbhit(void) {
#endif #endif
// log files functions // log files functions
void AddLogLine(char *file, char *extData, char *c) {
// open, appped and close logfile
void AddLogLine(char *fn, char *data, char *c) {
FILE *f = NULL; FILE *f = NULL;
char filename[FILE_PATH_SIZE] = {0x00}; char filename[FILE_PATH_SIZE] = {0x00};
int len = 0; int len = 0;
len = strlen(file); len = strlen(fn);
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; if (len > FILE_PATH_SIZE)
memcpy(filename, file, len); len = FILE_PATH_SIZE;
memcpy(filename, fn, len);
f = fopen(filename, "a"); f = fopen(filename, "a");
if (!f) { if (!f) {
@ -66,42 +69,47 @@ void AddLogLine(char *file, char *extData, char *c) {
return; return;
} }
fprintf(f, "%s", extData); fprintf(f, "%s", data);
fprintf(f, "%s\n", c); fprintf(f, "%s\n", c);
fflush(f); fflush(f);
fclose(f); fclose(f);
} }
void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len){ void AddLogHex(char *fn, char *extData, const uint8_t * data, const size_t len){
AddLogLine(fileName, extData, sprint_hex(data, len)); AddLogLine(fn, extData, sprint_hex(data, len));
} }
void AddLogUint64(char *fileName, char *extData, const uint64_t data) { void AddLogUint64(char *fn, char *data, const uint64_t value) {
char buf[20] = {0}; char buf[20] = {0};
memset(buf, 0x00, sizeof(buf)); memset(buf, 0x00, sizeof(buf));
sprintf(buf, "%016" PRIx64 "", data); sprintf(buf, "%016" PRIx64 "", value);
AddLogLine(fileName, extData, buf); AddLogLine(fn, data, buf);
} }
void AddLogCurrentDT(char *fileName) { void AddLogCurrentDT(char *fn) {
char buf[20]; char buf[20];
memset(buf, 0x00, sizeof(buf)); memset(buf, 0x00, sizeof(buf));
struct tm *curTime; struct tm *curTime;
time_t now = time(0); time_t now = time(0);
curTime = gmtime(&now); curTime = gmtime(&now);
strftime (buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", curTime); strftime (buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", curTime);
AddLogLine(fileName, "\nanticollision: ", buf); AddLogLine(fn, "\nanticollision: ", buf);
} }
void FillFileNameByUID(char *fileName, uint8_t *uid, char *ext, int byteCount) { // create filename on hex uid.
if ( fileName == NULL || uid == NULL || ext == NULL ){ // param *fn - pointer to filename char array
printf("error: parameter is NULL\n"); // param *uid - pointer to uid byte array
// param *ext - ".log"
// param uidlen - length of uid array.
void FillFileNameByUID(char *fn, uint8_t *uid, char *ext, int uidlen) {
if ( fn == NULL || uid == NULL || ext == NULL ){
printf("[!] error parameter is NULL\n");
return; return;
} }
char * fnameptr = fileName; char *fnameptr = fn;
memset(fileName, 0x00, FILE_PATH_SIZE); memset(fn, 0x00, FILE_PATH_SIZE);
for (int j = 0; j < byteCount; j++, fnameptr += 2) for (int j = 0; j < uidlen; j++, fnameptr += 2)
sprintf(fnameptr, "%02X", uid[j]); sprintf(fnameptr, "%02X", uid[j]);
sprintf(fnameptr, "%s", ext); sprintf(fnameptr, "%s", ext);
} }
@ -140,7 +148,6 @@ void print_hex(const uint8_t * data, const size_t len) {
} }
void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) { void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) {
int rownum = 0; int rownum = 0;
printf("[%02d] | ", rownum); printf("[%02d] | ", rownum);
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
@ -158,17 +165,13 @@ void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) {
char *sprint_hex(const uint8_t *data, const size_t len) { char *sprint_hex(const uint8_t *data, const size_t len) {
static char buf[1025] = {0}; static char buf[1025] = {0};
hex_to_buffer((uint8_t *)buf, data, len, sizeof(buf) - 1, 0, 1, true); hex_to_buffer((uint8_t *)buf, data, len, sizeof(buf) - 1, 0, 1, true);
return buf; return buf;
} }
char *sprint_hex_inrow_ex(const uint8_t *data, const size_t len, const size_t min_str_len) { char *sprint_hex_inrow_ex(const uint8_t *data, const size_t len, const size_t min_str_len) {
static char buf[1025] = {0}; static char buf[1025] = {0};
hex_to_buffer((uint8_t *)buf, data, len, sizeof(buf) - 1, min_str_len, 0, true); hex_to_buffer((uint8_t *)buf, data, len, sizeof(buf) - 1, min_str_len, 0, true);
return buf; return buf;
} }