/* * slog - Log exiting process. Function takes arguments and saves * log in file if LOGTOFILE flag is enabled from config. Otherwise * it just prints log without saveing in file. Argument level is * logging level and flag is slog flags defined in slog.h header. */ void slog(int level, int flag, const char *msg, ...) { /* Used variables */ SystemDate mdate; char string[MAXMSG]; char prints[MAXMSG]; char *output; /* Initialise system date */ get_system_date(&mdate); /* Read args */ va_list args; va_start(args, msg); vsprintf(string, msg, args); va_end(args); /* Check logging levels */ if(level <= slg.level) { /* Handle flags */ switch(flag) { case 1: sprintf(prints, "[მიმდინარე] %s", string); break; case 2: sprintf(prints, "[%s] %s", strclr(1, "ინფორმაცია"), string); break; case 3: sprintf(prints, "[%s] %s", strclr(3, "გაფრთხილება"), string); break; case 4: sprintf(prints, "[%s] %s", strclr(4, "დებაგი"), string); break; case 5: sprintf(prints, "[%s] %s", strclr(2, "შეცდომა"), string); break; case 6: sprintf(prints, "[%s] %s", strclr(2, "ფატალური"), string); break; case 7: sprintf(prints, "%s", string); break; default: break; } /* Print output */ printf("%s", ret_slog("%s\n", prints)); /* Save log in file */ if (slg.to_file) { output = ret_slog("%s\n", string); log_to_file(output, slg.fname, &mdate); } } }
static char * get_map_value ( char *map_file, /* Name of map file */ char *request_point /* Point coordinates */ ) { static char buffer [LINE_MAX], /* Buffer for map file line */ url [LINE_MAX], /* Buffer to store URL */ default_url [LINE_MAX]; /* Default URL value for the map */ char *full_uri; /* Full URI */ FILE *file; int point_x = 0, /* Used only for sscanf */ point_y = 0; ASSERT (map_file); strclr (url); strclr (default_url); file = file_open (map_file, 'r'); if (file) { /* Get the coodinates of point */ if (request_point) sscanf (request_point, "%d,%d", &point_x, &point_y); /* Note: The first line of map sets the value url_def */ while (file_readn (file, buffer, LINE_MAX)) { /* Ignore comments and blank lines */ if ((buffer [0] == '#') || strnull (buffer)) continue; point_in_map_element (buffer, url, point_x, point_y, default_url); if (strused (url)) break; } /* If not found a URL, set the return with the default value */ if (strnull (url)) strcpy (url, default_url); file_close (file); } /* Return final URL string, or NULL if we did not find anything */ if (strused (url)) { full_uri = build_full_url (url, map_file); strcpy (url, full_uri); mem_free (full_uri); return (url); } else return (NULL); }
MODULE write_text_body (THREAD *thread) { char *body_buffer; int body_size; tcb = thread-> tcb; /* Point to thread's context */ smtp_msg = tcb-> message; /* only for readability */ if (smtp_msg-> msg_body && *smtp_msg-> msg_body) { START_BODY body_size = strlen (smtp_msg-> msg_body) + extra_characters_required (smtp_msg-> msg_body); body_buffer = (char *) mem_alloc (body_size + 1); RAISE_EXC_IF (!body_buffer, memory_error_event); strclr (body_buffer); append_msg_body (body_buffer, smtp_msg-> msg_body); send_smtsock_writeh( &sockq, 0, /* Timeout in sec, zero = none */ tcb-> sock_handle, /* Socket to write to */ (qbyte)strlen(body_buffer), /* Amount of data to write */ (byte*)body_buffer, /* Block of data to write */ FALSE, /* Whether to always reply */ (void *) SOCK_TAG_WRITE); /* User-defined request tag */ TRACE_SMTP (body_buffer); mem_free (body_buffer); END_BODY }
MODULE get_user_command_input (THREAD *thread) { static struct { char *name; event_t event; } keywords [] = { { "LIST", list_event }, { "STATUS", status_event }, { "START", start_event }, { "PAUSE", pause_event }, { "STOP", stop_event }, { "HALT", halt_event }, { "EXIT", exit_event }, { "QUIT", exit_event }, { "HELP", help_event }, { "VERSION", version_event }, { "REFRESH", refresh_event }, { NULL, 0 } }; int keyword_nbr; /* If we got a command from the user, use it, else prompt */ if (command && strused (command)) { strncpy (input_line, command, LINE_MAX); input_line [LINE_MAX] = '\0'; /* Ensure delimited, if looong */ command = "exit"; /* Next time treat as Exit */ } else { /* Show syscli prompt and wait for user command */ printf ("syscli> "); fflush (stdout); if (fgets (input_line, LINE_MAX, stdin) == NULL) strclr (input_line); /* Treat EOF as empty */ } if (token_list) tok_free (token_list); token_list = tok_split (input_line); /* Get event corresponding to user command */ if (token_list [0] && *token_list [0]) { the_next_event = error_event; strupc (token_list [0]); for (keyword_nbr = 0; keywords [keyword_nbr].name; keyword_nbr++) if (streq (token_list [0], keywords [keyword_nbr].name)) { the_next_event = keywords [keyword_nbr].event; break; } /* Specific handling for stop command without arguments */ if (the_next_event == stop_event && token_list [1] == NULL) the_next_event = stop_all_event; } else the_next_event = empty_event; }
MODULE get_user_command_input (THREAD *thread) { static char input_line [LINE_MAX + 1]; static struct { char *name; event_t event; } keywords [] = { { "LIST", list_event }, { "START", start_event }, { "STOP", stop_event }, { "STATUS", status_event }, { "HALT", halt_event }, { "EXIT", exit_event }, { "QUIT", exit_event }, { "HELP", help_event }, { "VERSION", version_event }, { NULL, 0 } }; int keyword_nbr; /* If we got function arguments, use those, else prompt the user */ if (args && strused (args)) { strncpy (input_line, args, LINE_MAX); input_line [LINE_MAX] = '\0'; /* Ensure delimited, if looong */ args = "exit"; /* Next time treat as Exit */ } else { /* Show upmc prompt and wait for user command */ printf ("upmc> "); fflush (stdout); if (fgets (input_line, LINE_MAX, stdin) == NULL) strclr (input_line); /* Treat EOF as empty */ } if (token_list) tok_free (token_list); token_list = tok_split (input_line); /* Get event corresponding to user command */ if (token_list [0] && *token_list [0]) { the_next_event = error_event; strupc (token_list [0]); for (keyword_nbr = 0; keywords [keyword_nbr].name; keyword_nbr++) if (streq (token_list [0], keywords [keyword_nbr].name)) { the_next_event = keywords [keyword_nbr].event; break; } } else the_next_event = empty_event; }
/* * clean_prog - Cleanup on exit. Function handles exit signal * and terminates the program. Argument sig is signal value. */ void clean_prog(int sig) { /* Handle signals */ if (sig == SIGILL || sig == SIGSEGV) slog(0, SLOG_NONE, "[%s] Incorrect data!\n", strclr(2, "FATAL")); slog(0, SLOG_LIVE, "Cleaning up..."); exit(-1); }
static u16 showValueU32U32(char *str1, u32 value1, char *str2, u32 value2, u16 pos) { char s[64]; strclr(s); addValueU32(s, str1, value1); addValueU32(s, str2, value2); VDP_drawText(s, 0, pos); return pos + 1; }
int main() { /* Used variables */ char char_arg[32]; int int_arg; /* Init args */ strcpy(char_arg, "test string"); int_arg = 69; /* Greet users */ greet(); /* * slog_init - Initialise slog * First argument is log filename * Second argument is config file * Third argument is max log level * Fouth is thread safe flag. */ slog_init("example", "slog.cfg", 3, 1); /* Log and print something with level 0 */ slog(0, SLOG_LIVE, "Test message with level 0"); /* Log and print something with level 1 */ slog(1, SLOG_WARN, "Warn message with level 1"); /* Log and print something with level 2 */ slog(2, SLOG_INFO, "Info message with level 2"); /* Log and print something with level 3 */ slog(3, SLOG_LIVE, "Test message with level 3"); /* Log and print something with char argument */ slog(0, SLOG_DEBUG, "Debug message with char argument: %s", char_arg); /* Log and print something with int argument */ slog(0, SLOG_ERROR, "Error message with int argument: %d", int_arg); /* Test log with higher level than log max value * This will never be printed while log level argument is higher than max log level */ slog(4, SLOG_NONE, "[LIVE] Test log with higher level than log max value"); /* Print something with our own colorized line */ slog(0, SLOG_NONE, "[%s] This is our own colorized string", strclr(CLR_GREEN, "TEST")); return 0; }
MODULE get_confirmation_for_stop (THREAD *thread) { printf ("Do you really want to stop all tasks (n)? "); fflush (stdout); if (fgets (input_line, LINE_MAX, stdin) == NULL) strclr (input_line); /* Treat EOF as empty */ strlwc (input_line); if (input_line [0] == 'y') the_next_event = ok_event; else { the_next_event = cancel_event; printf ("syscli> 211 - cancelled\n"); } }
/* stores an error code and message in thread context. */ static void set_error (TCB *ctxt, int code, char *msg, ...) { const char *src_ptr; va_list va; size_t msg_size; /* Size of concatenated strings */ ctxt-> last_error_code = code; if (ctxt-> last_error_msg) { mem_free(ctxt-> last_error_msg); ctxt-> last_error_msg = NULL; } va_start (va, msg); /* Start variable args processing */ src_ptr = msg; msg_size = 0; while (src_ptr) { msg_size += strlen (src_ptr); src_ptr = va_arg (va, char *); } va_end (va); /* End variable args processing */ ctxt-> last_error_msg = (char *) mem_alloc (msg_size+1); if (ctxt-> last_error_msg == NULL) { raise_exception (memory_error_event); return; /* Not enough memory */ } /* Now copy strings into destination buffer */ va_start (va, msg); /* Start variable args processing */ src_ptr = msg; strclr (ctxt-> last_error_msg); while (src_ptr) { strcat (ctxt-> last_error_msg, src_ptr); src_ptr = va_arg (va, char *); } va_end (va); /* End variable args processing */ ctxt-> last_error_msg[msg_size] = 0; }
/* * printclr - Function takes color value and * string and prints colorized string with printf. * First argument clr is color value and second is string * with va_list of arguments which one we want to print. */ void printclr(int clr, char* str, ...) { /* Used variables */ char string[MAXMSG]; char* colorized; /* Read args */ va_list args; va_start(args, str); vsprintf(string, str, args); va_end(args); /* Print colorized string */ colorized = strclr(clr, string); if (colorized != NULL) printf("%s", colorized); }
static u16 showStackState(u16 pos) { char s[64]; u16 y = pos; u32 *sp = (u32*) registerState[15]; u16 i = 0; while(i < 24) { strclr(s); addValueU8(s, "SP+", i); strcat(s, " "); y = showValueU32U32(s, *(sp + (i + 0)), " ", *(sp + (i + 1)), y); i += 2; } return y; }
/* * randclr - Random colorize. Function returns colorized string * with random color. Argument str is string with va_list of * arguments which one we want to colorize with random color. */ char* randclr(char* str, ...) { /* Used variables */ char string[MAXMSG]; char* colorized; /* Read args */ va_list args; va_start(args, str); vsprintf(string, str, args); va_end(args); /* Print random color */ srand(time(NULL)); int r = rand() % 8; colorized = strclr(r, string); return colorized; }
asl_field_t * asl_field_new_ ( char * file, // Source file for call size_t line // Line number for call ) { asl_field_t * self = NULL; // Object reference self = asl_field_alloc_ (file, line); if (self) { self->object_tag = ASL_FIELD_ALIVE; self->links = 1; self->zombie = FALSE; #if defined (DEBUG) || defined (BASE_HISTORY) || defined (BASE_HISTORY_ASL_FIELD) self->history_last = 0; // Track possession operation in history self->history_file [0] = file; self->history_line [0] = line; self->history_type [0] = "new"; self->history_links [0] = self->links; #endif #if defined (DEBUG) icl_mem_set_callback (self, asl_field_show_); #endif self->list_next = self; self->list_prev = self; self->list_head = NULL; strclr (self->name); self->type = 0; self->decimals = 0; self->integer = 0; self->string = NULL; } return (self); }
MODULE init_left_and_right_expr (void) { strclr (lexpr); strclr (rexpr); }
/* * slog - Log exiting process. Function takes arguments and saves * log in file if LOGTOFILE flag is enabled from config. Otherwise * it just prints log without saveing in file. Argument level is * logging level and flag is slog flags defined in slog.h header. */ void slog(int level, int flag, const char *msg, ...) { /* Lock for safe */ if (slg.td_safe) { if (pthread_mutex_lock(&slog_mutex)) { printf("<%s:%d> %s: [ERROR] Can not lock mutex: %d\n", __FILE__, __LINE__, __FUNCTION__, errno); exit(EXIT_FAILURE); } } /* Used variables */ SlogDate mdate; char string[MAXMSG]; char prints[MAXMSG]; char color[32], alarm[32]; char *output; slog_get_date(&mdate); bzero(string, sizeof(string)); bzero(prints, sizeof(prints)); bzero(color, sizeof(color)); bzero(alarm, sizeof(alarm)); /* Read args */ va_list args; va_start(args, msg); vsprintf(string, msg, args); va_end(args); /* Check logging levels */ if(!level || level <= slg.level || level <= slg.file_level) { /* Handle flags */ switch(flag) { case SLOG_LIVE: strncpy(color, CLR_NORMAL, sizeof(color)); strncpy(alarm, "LIVE", sizeof(alarm)); break; case SLOG_INFO: strncpy(color, CLR_GREEN, sizeof(color)); strncpy(alarm, "INFO", sizeof(alarm)); break; case SLOG_WARN: strncpy(color, CLR_YELLOW, sizeof(color)); strncpy(alarm, "WARN", sizeof(alarm)); break; case SLOG_DEBUG: strncpy(color, CLR_BLUE, sizeof(color)); strncpy(alarm, "DEBUG", sizeof(alarm)); break; case SLOG_ERROR: strncpy(color, CLR_RED, sizeof(color)); strncpy(alarm, "ERROR", sizeof(alarm)); break; case SLOG_FATAL: strncpy(color, CLR_RED, sizeof(color)); strncpy(alarm, "FATAL", sizeof(alarm)); break; case SLOG_PANIC: strncpy(color, CLR_WHITE, sizeof(color)); strncpy(alarm, "PANIC", sizeof(alarm)); break; case SLOG_NONE: strncpy(prints, string, sizeof(string)); break; default: strncpy(prints, string, sizeof(string)); flag = SLOG_NONE; break; } /* Print output */ if (level <= slg.level || slg.pretty) { if (flag != SLOG_NONE) sprintf(prints, "[%s] %s", strclr(color, alarm), string); if (level <= slg.level) printf("%s", slog_get(&mdate, "%s\n", prints)); } /* Save log in file */ if (slg.to_file && level <= slg.file_level) { if (slg.pretty) output = slog_get(&mdate, "%s\n", prints); else { if (flag != SLOG_NONE) sprintf(prints, "[%s] %s", alarm, string); output = slog_get(&mdate, "%s\n", prints); } /* Add log line to file */ slog_to_file(output, slg.fname, &mdate); } } /* Done, unlock mutex */ if (slg.td_safe) { if (pthread_mutex_unlock(&slog_mutex)) { printf("<%s:%d> %s: [ERROR] Can not deinitialize mutex: %d\n", __FILE__, __LINE__, __FUNCTION__, errno); exit(EXIT_FAILURE); } } }
char * conv_date_pict ( long date, const char *picture) { static char *month_name [] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }, *day_name [] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }, formatted [FORMAT_MAX + 1]; /* Formatted return string */ int century, /* Century component of date */ year, /* Year component of date */ month, /* Month component of date */ day, /* Day component of date */ cursize; /* Size of current component */ char *dest, /* Store formatted data here */ ch, /* Next character in picture */ lastch = '0'; /* Last character we output */ long full_date = date; conv_reason = 0; /* No conversion errors so far */ /* Zero date is returned as empty string */ if (date == 0) { strclr (formatted); return (formatted); } default_century (&full_date); century = GET_CENTURY (full_date); year = GET_YEAR (full_date); month = GET_MONTH (full_date); day = GET_DAY (full_date); ASSERT (month > 0 && month <= 12); ASSERT (day > 0 && day <= 31); /* Scan through picture, converting each component */ dest = formatted; *dest = 0; /* string is empty */ while (*picture) { /* Get character and count number of occurences */ ch = *picture++; for (cursize = 1; *picture == ch; cursize++) picture++; switch (ch) { /* cc century 2 digits, 01-99 */ case 'c': if (cursize == 2) sprintf (dest, "%02d", century); break; /* y day of year, 1-366 */ /* yy year 2 digits, 00-99 */ /* yyyy year 4 digits, 0100-9999 */ case 'y': /* y = day of year */ if (cursize == 1) sprintf (dest, "%d", julian_date (full_date)); else if (cursize == 2) sprintf (dest, "%02d", year); else if (cursize == 4) sprintf (dest, "%02d%02d", century, year); break; /* m month, 1-12 */ /* mm month, 01-12 */ /* mmm month, 3 letters */ /* mmmm month, full name */ case 'm': if (cursize == 1) sprintf (dest, (isdigit (lastch)? "%2d": "%d"), month); else if (cursize == 2) sprintf (dest, "%02d", month); else if (cursize == 3) { memcpy (dest, month_name [month - 1], 3); dest [3] = 0; } else if (cursize == 4) strcpy (dest, month_name [month - 1]); break; /* MMM month, 3-letters, ucase */ /* MMMM month, full name, ucase */ case 'M': if (cursize == 3) { memcpy (dest, month_name [month - 1], 3); dest [3] = 0; strupc (dest); } else if (cursize == 4) { strcpy (dest, month_name [month - 1]); strupc (dest); } break; /* d day, 1-31 */ /* dd day, 01-31 */ /* ddd day of week, Sun-Sat */ /* dddd day of week, Sunday-Saturday */ case 'd': if (cursize == 1) sprintf (dest, (isdigit (lastch)? "%2d": "%d"), day); else if (cursize == 2) sprintf (dest, "%02d", day); else if (cursize == 3) { memcpy (dest, day_name [day_of_week (full_date)], 3); dest [3] = 0; } else if (cursize == 4) strcpy (dest, day_name [day_of_week (full_date)]); break; /* DDD day of week, SUN-SAT */ /* DDDD day of week, SUNDAY-SATURDAY */ case 'D': if (cursize == 3) { memcpy (dest, day_name [day_of_week (full_date)], 3); dest [3] = 0; strupc (dest); } else if (cursize == 4) { strcpy (dest, day_name [day_of_week (full_date)]); strupc (dest); } break; /* w day of week, 1-7 (1=Sunday) */ /* ww week of year, 1-53 */ case 'w': if (cursize == 1) sprintf (dest, "%d", day_of_week (full_date) + 1); else if (cursize == 2) sprintf (dest, "%d", week_of_year (full_date)); break; /* q year quarter, 1-4 */ case 'q': if (cursize == 1) sprintf (dest, "%d", year_quarter (full_date)); break; /* \x literal character x */ case '\\': ch = *picture++; } if (*dest) /* If something was output, */ while (*dest) /* skip to end of string */ dest++; else while (cursize--) /* Else output ch once or more */ *dest++ = ch; /* and bump dest pointer */ lastch = *(dest - 1); /* Get previous character */ *dest = 0; /* Terminate the string nicely */ } return (formatted); }
int ini_dyn_save ( SYMTAB *symtab, const char *filename) { FILE *inifile, *wrkfile; SYMBOL *symbol; /* Next symbol in table */ Bool header_found; /* Did we find a file header? */ int count; /* How many symbols did we save? */ char *colon, /* Points to ':' in symbol name */ *outchar, /* Output character pointer */ *valchar; /* Symbol value character pointer */ ASSERT (filename); ASSERT (symtab); /* Copy ini file header to temporary file */ wrkfile = ftmp_open (NULL); header_found = FALSE; if ((inifile = file_open (filename, 'r')) != NULL) { while (file_read (inifile, iniline)) { if (streq (iniline, "#*END")) { header_found = TRUE; break; } file_write (wrkfile, iniline); } file_close (inifile); } /* Now rewrite ini file */ if ((inifile = file_open (filename, 'w')) == NULL) { ftmp_close (wrkfile); return (-1); /* No permission to write file */ } if (header_found) { fseek (wrkfile, 0, SEEK_SET); while (file_read (wrkfile, iniline)) file_write (inifile, iniline); } ftmp_close (wrkfile); /* Finished with temporary file */ /* Output ini file values */ file_write (inifile, "#*END"); strclr (ini_section); /* Current section */ count = 0; sym_sort_table (symtab, NULL); /* Sort table by symbol name */ for (symbol = symtab-> symbols; symbol; symbol = symbol-> next) { /* Output symbols formatted as key:name */ colon = strrchr (symbol-> name, ':'); if (colon) { memcpy (ini_value, symbol-> name, colon - symbol-> name); ini_value [colon - symbol-> name] = '\0'; strcpy (ini_keyword, colon + 1); /* If we start a new section, output the section header */ *ini_value = toupper (*ini_value); *ini_keyword = toupper (*ini_keyword); if (strneq (ini_section, ini_value)) { strcpy (ini_section, ini_value); snprintf (iniline, sizeof (iniline), "[%s]", ini_section); file_write (inifile, ""); file_write (inifile, iniline); } /* We always put quotes around values when writing */ snprintf (iniline, sizeof (iniline), " %s = \"", ini_keyword); outchar = iniline + strlen (iniline); for (valchar = symbol-> value; *valchar; valchar++) { /* If line is too long, break it */ if (outchar - iniline > 75) { *outchar++ = '-'; *outchar++ = '\0'; file_write (inifile, iniline); strclr (iniline); outchar = iniline; continue; } /* Escape ", \, ( and newlines. We escape ( so that $(xxx) * in the value is not replaced on input. */ if (*valchar == '\n') { *outchar++ = '\\'; *outchar++ = 'n'; } else if (*valchar == '"' || *valchar == '\\' || *valchar == '(') { *outchar++ = '\\'; *outchar++ = *valchar; } else *outchar++ = *valchar; } *outchar++ = '"'; *outchar++ = '\0'; file_write (inifile, iniline); } } file_close (inifile); return (count); }
BOOL FileGetName (HWND hWndParent, int nStringResourceID, LPTSTR lpFileName) { OPENFILENAME ofn ; TCHAR szFileSpec [256] ; TCHAR szFileTitle [80] ; TCHAR szDialogTitle [80] ; TCHAR aszOpenFilter[LongTextLen] ; int StringLength ; if (lpFileName) { if (nStringResourceID != IDS_EXPORTFILE) { // get the file extension strings LoadString (hInstance, nStringResourceID, aszOpenFilter, sizeof(aszOpenFilter) / sizeof(TCHAR) ) ; StringLength = lstrlen (aszOpenFilter) + 1 ; LoadString (hInstance, nStringResourceID+1, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; // get all file extension strings LoadString (hInstance, IDS_ALLFILES, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; LoadString (hInstance, IDS_ALLFILESEXT, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; } // setup the end strings StringLength += lstrlen (&aszOpenFilter[StringLength]) ; aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ; strclr (szFileSpec) ; strclr (szFileTitle) ; dwCurrentDlgID = HC_PM_idDlgFileSaveAs ; StringLoad (IDS_SAVEAS_TITLE, szDialogTitle) ; memset (&ofn, 0, sizeof(OPENFILENAME)) ; ofn.lStructSize = sizeof(OPENFILENAME) ; ofn.hwndOwner = hWndParent ; ofn.hInstance = hInstance; ofn.lpstrTitle = szDialogTitle ; ofn.lpstrFilter = aszOpenFilter ; ofn.nFilterIndex = 1L ; ofn.lpstrFile = szFileSpec; ofn.nMaxFile = sizeof(szFileSpec); ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof(szFileTitle); ofn.Flags = OptionsOFNStyle ; ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ; if (!GetSaveFileName(&ofn)) { dwCurrentDlgID = 0 ; return (FALSE) ; } dwCurrentDlgID = 0 ; } else { return (FALSE) ; } lstrcpy (lpFileName, ofn.lpstrFile) ; return (TRUE) ; } // FileGetName
int main (int argc, char *argv []) { int argn; /* Argument number */ Bool args_ok = TRUE, /* Were the arguments okay? */ quiet_mode = FALSE; /* -q means suppress messages */ char *port, /* Port to connect to */ **argparm; /* Argument parameter to pick-up */ static char command [LINE_MAX]; /* Command to pass to agent */ /* These are the arguments we may get on the command line */ port = NULL; strclr (command); argparm = NULL; /* Argument parameter to pick-up */ for (argn = 1; argn < argc; argn++) { /* If argparm is set, we have to collect an argument parameter */ if (argparm) { if (*argv [argn] != '-') /* Parameter can't start with '-' */ { *argparm = strdupl (argv [argn]); argparm = NULL; } else { args_ok = FALSE; break; } } else if (*argv [argn] == '-') { switch (argv [argn][1]) { /* These switches take a parameter */ case 'p': argparm = &port; break; /* These switches have an immediate effect */ case 'q': quiet_mode = TRUE; break; case 't': smtsock_trace (TRUE); break; case 'v': coprintf ("Syscli %s", SYSCLI_VERSION); coprintf (PRODUCT); coprintf (BUILDMODEL); coprintf (COPYRIGHT); coprintf ("Built on: %s", BUILDDATE); exit (EXIT_SUCCESS); case 'h': coprintf ("Syscli %s", SYSCLI_VERSION); coprintf (COPYRIGHT); coprintf (USAGE); exit (EXIT_SUCCESS); /* Anything else is an error */ default: args_ok = FALSE; } } else { strcat (command, " "); strcat (command, argv [argn]); } } /* If there was a missing parameter or an argument error, quit */ if (argparm) { puts ("Argument missing - type 'syscli -h' for help"); exit (EXIT_FAILURE); } else if (!args_ok) { puts ("Invalid arguments - type 'syscli -h' for help"); exit (EXIT_FAILURE); } /* Handle the remaining arguments we got */ if (!port) port = SYSMAN_DEFAULT_PORT; if (quiet_mode) { fclose (stdout); /* Kill standard output */ fclose (stderr); /* and standard error */ } else { puts ("Syscli " SYSCLI_VERSION); puts (COPYRIGHT); } smt_init (); /* Initialise SMT kernel */ sysclia_init (command, port); /* Initialise SYSMAN client agent */ smt_exec_full (); /* Run until completed */ smt_term (); /* Shut-down SMT kernel */ mem_assert (); /* Assert memory is clean */ return (0); }
BOOL FileOpen (HWND hWndParent, int nStringResourceID, LPTSTR lpInputFileName) { OPENFILENAME ofn ; TCHAR szFileSpec [256] ; TCHAR szFileTitle [80] ; TCHAR szDialogTitle [80] ; HANDLE hFile ; PERFFILEHEADER FileHeader ; TCHAR aszOpenFilter[LongTextLen] ; int StringLength ; BOOL retCode ; LPTSTR pFileName = NULL ; if (strempty(lpInputFileName)) { dwCurrentDlgID = HC_PM_idDlgFileOpen ; // get the file extension strings LoadString (hInstance, nStringResourceID, aszOpenFilter, sizeof(aszOpenFilter) / sizeof(TCHAR)) ; StringLength = lstrlen (aszOpenFilter) + 1 ; LoadString (hInstance, nStringResourceID+1, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; #ifdef ADVANCED_PERFMON // get workspace file extension strings LoadString (hInstance, IDS_WORKSPACEFILE, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; LoadString (hInstance, IDS_WORKSPACEFILEEXT, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1; #endif // get all file extension strings LoadString (hInstance, IDS_ALLFILES, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; LoadString (hInstance, IDS_ALLFILESEXT, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) ; // setup the end strings aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ; strclr (szFileSpec) ; strclr (szFileTitle) ; StringLoad (IDS_FILEOPEN_TITLE, szDialogTitle) ; memset (&ofn, 0, sizeof(OPENFILENAME)) ; ofn.lStructSize = sizeof(OPENFILENAME) ; ofn.hwndOwner = hWndParent ; ofn.hInstance = hInstance; ofn.lpstrTitle = szDialogTitle ; ofn.lpstrFilter = aszOpenFilter ; ofn.nFilterIndex = 1L ; ofn.lpstrFile = szFileSpec; ofn.nMaxFile = sizeof(szFileSpec); ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof(szFileTitle); ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK ; ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ; if (!GetOpenFileName(&ofn)) { dwCurrentDlgID = 0 ; return (FALSE) ; } dwCurrentDlgID = 0 ; hFile = FileHandleOpen (szFileSpec) ; pFileName = szFileSpec ; } // NULL lpFileName else { // open the input file hFile = FileHandleOpen (lpInputFileName) ; if (hFile && hFile != INVALID_HANDLE_VALUE && SearchPath (NULL, lpInputFileName, NULL, sizeof(szFileSpec)/sizeof(TCHAR) - 1, szFileSpec, &pFileName)) { pFileName = szFileSpec ; } else { pFileName = NULL ; } } if (!hFile || hFile == INVALID_HANDLE_VALUE) { return (FALSE) ; } if (!FileRead (hFile, &FileHeader, sizeof (FileHeader))) { CloseHandle (hFile) ; if (strempty(lpInputFileName)) { DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ; } return (FALSE) ; } //=============================// // Chart File? // //=============================// if (strsame (FileHeader.szSignature, szPerfChartSignature)) { retCode = OpenChart (hWndGraph, hFile, FileHeader.dwMajorVersion, FileHeader.dwMinorVersion, TRUE) ; if (retCode) { ChangeSaveFileName (pFileName, IDM_VIEWCHART) ; } else { goto ErrExit ; } return (retCode) ; } //=============================// // Unknown file type // //=============================// CloseHandle (hFile) ; ErrExit: DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ; return (FALSE) ; } // FileOpen
char * conv_date_str ( long date, int flags, int format, int order, char datesep, int width) { static char *format_table [] = { "ymd", "dmy", "mdy", /* DATE_YMD_COMPACT */ "y/m/d", "d/m/y", "m/d/y", /* DATE_YMD_DELIM */ "y m d", "d m y", "m d y", /* DATE_YMD_SPACE */ "y, m d", "d m, y", "m d, y", /* DATE_YMD_COMMA */ "ym", "my", "my", /* DATE_YM_COMPACT */ "y/m", "m/y", "m/y", /* DATE_YM_DELIM */ "y m", "m y", "m y", /* DATE_YM_SPACE */ "md", "dm", "md", /* DATE_MD_COMPACT */ "m/d", "d/m", "m/d", /* DATE_MD_DELIM */ "m d", "d m", "m d" /* DATE_MD_SPACE */ }; char *format_ptr, /* Scan through format string */ delim [2], /* Delimiter character */ picture [14], /* Largest picture: dd mmmm, yyyy */ ch; /* Next char in format string */ int index, date_order = order; /* Order to use */ ASSERT (format >= DATE_FORMAT_FIRST && format <= DATE_FORMAT_LAST); ASSERT (order >= DATE_ORDER_FIRST && order <= DATE_ORDER_LAST); conv_reason = 0; /* No conversion errors so far */ if (flags & FLAG_D_ORDER_YMD) date_order = DATE_ORDER_YMD; else if (flags & FLAG_D_ORDER_DMY) date_order = DATE_ORDER_DMY; else if (flags & FLAG_D_ORDER_MDY) date_order = DATE_ORDER_MDY; /* Get index into table */ index = format * 3 + date_order - 1; /* Now build-up picture according to format string */ strclr (picture); for (format_ptr = format_table [index]; *format_ptr; format_ptr++) { ch = *format_ptr; switch (ch) { case 'y': strcat (picture, flags & FLAG_D_CENTURY? "yyyy": "yy"); break; case 'm': if (flags & FLAG_D_MONTH_ABC) if (width > 16) strcat (picture, flags & FLAG_D_UPPER? "MMMM": "mmmm"); else strcat (picture, flags & FLAG_D_UPPER? "MMM": "mmm"); else strcat (picture, flags & FLAG_D_MM_AS_M? "m": "mm"); break; case 'd': strcat (picture, flags & FLAG_D_DD_AS_D? "d": "dd"); break; case '/': ch = datesep; /* Use supplied date separator */ default: delim [0] = ch; delim [1] = 0; strcat (picture, delim); } } format_ptr = conv_date_pict (date, picture); if (strlen (format_ptr) > (unsigned) width) { conv_reason = CONV_ERR_DATE_OVERFLOW; return (NULL); } else return (format_ptr); }
int main(void) { DDRF = 0; char GPS[100]; char dylos[10]; char GPS_line = 0; char dylos_line = 0; char sd_buff[150]; char buffer[30]; int GPS_data[15]; int dylos_data[2]; int C3H8, CH4, CO, H2S, F; char new_GPS_data = 0; char new_dylos_data = 0; FRESULT fr; int ppm2[151]; ppm2[0] = 10478; ppm2[1] = 9706; ppm2[2] = 9015; ppm2[3] = 8394; ppm2[4] = 7834; ppm2[5] = 7327; ppm2[6] = 6868; ppm2[7] = 6449; ppm2[8] = 6068; ppm2[9] = 5718; ppm2[10] = 5398; ppm2[11] = 5103; ppm2[12] = 4831; ppm2[13] = 4581; ppm2[14] = 4349; ppm2[15] = 4133; ppm2[16] = 3934; ppm2[17] = 3748; ppm2[18] = 3575; ppm2[19] = 3413; ppm2[20] = 3262; ppm2[21] = 3121; ppm2[22] = 2988; ppm2[23] = 2864; ppm2[24] = 2747; ppm2[25] = 2637; ppm2[26] = 2533; ppm2[27] = 2435; ppm2[28] = 2343; ppm2[29] = 2256; ppm2[30] = 2173; ppm2[31] = 2095; ppm2[32] = 2021; ppm2[33] = 1951; ppm2[34] = 1884; ppm2[35] = 1821; ppm2[36] = 1760; ppm2[37] = 1703; ppm2[38] = 1648; ppm2[39] = 1596; ppm2[40] = 1546; ppm2[41] = 1499; ppm2[42] = 1454; ppm2[43] = 1410; ppm2[44] = 1369; ppm2[45] = 1329; ppm2[46] = 1291; ppm2[47] = 1254; ppm2[48] = 1220; ppm2[49] = 1186; ppm2[50] = 1154; ppm2[51] = 1123; ppm2[52] = 1093; ppm2[53] = 1065; ppm2[54] = 1037; ppm2[55] = 1011; ppm2[56] = 985; ppm2[57] = 961; ppm2[58] = 937; ppm2[59] = 914; ppm2[60] = 892; ppm2[61] = 871; ppm2[62] = 851; ppm2[63] = 831; ppm2[64] = 812; ppm2[65] = 793; ppm2[66] = 775; ppm2[67] = 758; ppm2[68] = 741; ppm2[69] = 725; ppm2[70] = 710; ppm2[71] = 694; ppm2[72] = 680; ppm2[73] = 667; ppm2[74] = 652; ppm2[75] = 638; ppm2[76] = 625; ppm2[77] = 613; ppm2[78] = 601; ppm2[79] = 589; ppm2[80] = 577; ppm2[81] = 566; ppm2[82] = 555; ppm2[83] = 545; ppm2[84] = 534; ppm2[85] = 524; ppm2[86] = 515; ppm2[87] = 505; ppm2[88] = 496; ppm2[89] = 487; ppm2[90] = 478; ppm2[91] = 470; ppm2[92] = 461; ppm2[93] = 453; ppm2[94] = 446; ppm2[95] = 438; ppm2[96] = 430; ppm2[97] = 423; ppm2[98] = 416; ppm2[99] = 409; ppm2[100] = 402; ppm2[101] = 396; ppm2[102] = 389; ppm2[103] = 383; ppm2[104] = 377; ppm2[105] = 371; ppm2[106] = 365; ppm2[107] = 359; ppm2[108] = 354; ppm2[109] = 348; ppm2[110] = 343; ppm2[111] = 338; ppm2[112] = 333; ppm2[113] = 328; ppm2[114] = 323; ppm2[115] = 318; ppm2[116] = 313; ppm2[117] = 309; ppm2[118] = 304; ppm2[119] = 300; ppm2[120] = 296; ppm2[121] = 292; ppm2[122] = 287; ppm2[123] = 283; ppm2[124] = 279; ppm2[125] = 276; ppm2[126] = 272; ppm2[127] = 268; ppm2[128] = 265; ppm2[129] = 261; ppm2[130] = 257; ppm2[131] = 254; ppm2[132] = 251; ppm2[133] = 247; ppm2[134] = 244; ppm2[135] = 241; ppm2[136] = 238; ppm2[137] = 235; ppm2[138] = 232; ppm2[139] = 229; ppm2[140] = 226; ppm2[141] = 223; ppm2[142] = 220; ppm2[143] = 218; ppm2[144] = 215; ppm2[145] = 212; ppm2[146] = 210; ppm2[147] = 207; ppm2[148] = 205; ppm2[149] = 202; ppm2[150] = 200; int ppm5[151]; ppm5[0] = 9867; ppm5[1] = 9291; ppm5[2] = 8760; ppm5[3] = 8271; ppm5[4] = 7819; ppm5[5] = 7400; ppm5[6] = 7012; ppm5[7] = 6652; ppm5[8] = 6317; ppm5[9] = 6005; ppm5[10] = 5714; ppm5[11] = 5443; ppm5[12] = 5189; ppm5[13] = 4951; ppm5[14] = 4728; ppm5[15] = 4518; ppm5[16] = 4322; ppm5[17] = 4137; ppm5[18] = 3963; ppm5[19] = 3799; ppm5[20] = 3644; ppm5[21] = 3498; ppm5[22] = 3360; ppm5[23] = 3229; ppm5[24] = 3106; ppm5[25] = 2988; ppm5[26] = 2772; ppm5[27] = 2672; ppm5[28] = 2577; ppm5[29] = 2486; ppm5[30] = 2400; ppm5[31] = 2318; ppm5[32] = 2240; ppm5[33] = 2165; ppm5[34] = 2094; ppm5[35] = 2026; ppm5[36] = 1961; ppm5[37] = 1899; ppm5[38] = 1839; ppm5[39] = 1783; ppm5[40] = 1728; ppm5[41] = 1676; ppm5[42] = 1626; ppm5[43] = 1578; ppm5[44] = 1532; ppm5[45] = 1488; ppm5[46] = 1446; ppm5[47] = 1405; ppm5[48] = 1366; ppm5[49] = 1328; ppm5[50] = 1292; ppm5[51] = 1257; ppm5[52] = 1223; ppm5[53] = 1191; ppm5[54] = 1160; ppm5[55] = 1130; ppm5[56] = 1101; ppm5[57] = 1073; ppm5[58] = 1046; ppm5[59] = 1020; ppm5[60] = 995; ppm5[61] = 971; ppm5[62] = 947; ppm5[63] = 924; ppm5[64] = 903; ppm5[65] = 881; ppm5[66] = 861; ppm5[67] = 841; ppm5[68] = 822; ppm5[69] = 803; ppm5[70] = 785; ppm5[71] = 768; ppm5[72] = 751; ppm5[73] = 734; ppm5[74] = 718; ppm5[75] = 703; ppm5[76] = 688; ppm5[77] = 673; ppm5[78] = 659; ppm5[79] = 645; ppm5[80] = 632; ppm5[81] = 619; ppm5[82] = 606; ppm5[83] = 594; ppm5[84] = 582; ppm5[85] = 571; ppm5[86] = 559; ppm5[87] = 549; ppm5[88] = 538; ppm5[89] = 528; ppm5[90] = 517; ppm5[91] = 508; ppm5[92] = 498; ppm5[93] = 489; ppm5[94] = 480; ppm5[95] = 471; ppm5[96] = 462; ppm5[97] = 454; ppm5[98] = 446; ppm5[99] = 438; ppm5[100] = 430; ppm5[101] = 422; ppm5[102] = 415; ppm5[103] = 408; ppm5[104] = 401; ppm5[105] = 394; ppm5[106] = 387; ppm5[107] = 380; ppm5[108] = 374; ppm5[109] = 368; ppm5[110] = 362; ppm5[111] = 356; ppm5[112] = 350; ppm5[113] = 344; ppm5[114] = 339; ppm5[115] = 333; ppm5[116] = 328; ppm5[117] = 323; ppm5[118] = 317; ppm5[119] = 312; ppm5[120] = 308; ppm5[121] = 303; ppm5[122] = 298; ppm5[123] = 294; ppm5[124] = 289; ppm5[125] = 285; ppm5[126] = 280; ppm5[127] = 276; ppm5[128] = 272; ppm5[129] = 268; ppm5[130] = 264; ppm5[131] = 260; ppm5[132] = 256; ppm5[133] = 253; ppm5[134] = 249; ppm5[135] = 246; ppm5[136] = 242; ppm5[137] = 239; ppm5[138] = 235; ppm5[139] = 232; ppm5[140] = 229; ppm5[141] = 226; ppm5[142] = 222; ppm5[143] = 219; ppm5[144] = 216; ppm5[145] = 214; ppm5[146] = 211; ppm5[147] = 208; ppm5[148] = 205; ppm5[149] = 202; ppm5[150] = 200; int ppm7[151]; ppm7[0] = 4112; ppm7[1] = 3495; ppm7[2] = 3017; ppm7[3] = 2638; ppm7[4] = 2332; ppm7[5] = 2080; ppm7[6] = 1870; ppm7[7] = 1692; ppm7[8] = 1541; ppm7[9] = 1411; ppm7[10] = 1298; ppm7[11] = 1199; ppm7[12] = 1112; ppm7[13] = 1035; ppm7[14] = 967; ppm7[15] = 905; ppm7[16] = 850; ppm7[17] = 800; ppm7[18] = 755; ppm7[19] = 714; ppm7[20] = 676; ppm7[21] = 641; ppm7[22] = 610; ppm7[23] = 581; ppm7[24] = 554; ppm7[25] = 529; ppm7[26] = 506; ppm7[27] = 484; ppm7[28] = 464; ppm7[29] = 445; ppm7[30] = 428; ppm7[31] = 412; ppm7[32] = 396; ppm7[33] = 382; ppm7[34] = 368; ppm7[35] = 355; ppm7[36] = 343; ppm7[37] = 332; ppm7[38] = 321; ppm7[39] = 311; ppm7[40] = 301; ppm7[41] = 292; ppm7[42] = 283; ppm7[43] = 275; ppm7[44] = 267; ppm7[45] = 259; ppm7[46] = 252; ppm7[47] = 245; ppm7[48] = 238; ppm7[49] = 232; ppm7[50] = 226; ppm7[51] = 220; ppm7[52] = 215; ppm7[53] = 209; ppm7[54] = 204; ppm7[55] = 199; ppm7[56] = 195; ppm7[57] = 190; ppm7[58] = 186; ppm7[59] = 181; ppm7[60] = 177; ppm7[61] = 174; ppm7[62] = 170; ppm7[63] = 166; ppm7[64] = 163; ppm7[65] = 159; ppm7[66] = 156; ppm7[67] = 153; ppm7[68] = 150; ppm7[69] = 147; ppm7[70] = 144; ppm7[71] = 141; ppm7[72] = 139; ppm7[73] = 136; ppm7[74] = 133; ppm7[75] = 131; ppm7[76] = 129; ppm7[77] = 126; ppm7[78] = 124; ppm7[79] = 122; ppm7[80] = 120; ppm7[81] = 118; ppm7[82] = 116; ppm7[83] = 114; ppm7[84] = 112; ppm7[85] = 110; ppm7[86] = 108; ppm7[87] = 107; ppm7[88] = 105; ppm7[89] = 103; ppm7[90] = 102; ppm7[91] = 100; ppm7[92] = 99; ppm7[93] = 97; ppm7[94] = 96; ppm7[95] = 94; ppm7[96] = 93; ppm7[97] = 91; ppm7[98] = 90; ppm7[99] = 89; ppm7[100] = 88; ppm7[101] = 86; ppm7[102] = 85; ppm7[103] = 84; ppm7[104] = 83; ppm7[105] = 82; ppm7[106] = 81; ppm7[107] = 80; ppm7[108] = 79; ppm7[109] = 78; ppm7[110] = 77; ppm7[111] = 76; ppm7[112] = 75; ppm7[113] = 74; ppm7[114] = 73; ppm7[115] = 72; ppm7[116] = 71; ppm7[117] = 70; ppm7[118] = 69; ppm7[119] = 68; ppm7[120] = 68; ppm7[121] = 67; ppm7[122] = 66; ppm7[123] = 65; ppm7[124] = 64; ppm7[125] = 64; ppm7[126] = 63; ppm7[127] = 62; ppm7[128] = 62; ppm7[129] = 61; ppm7[130] = 60; ppm7[131] = 60; ppm7[132] = 59; ppm7[133] = 58; ppm7[134] = 58; ppm7[135] = 57; ppm7[136] = 56; ppm7[137] = 56; ppm7[138] = 55; ppm7[139] = 55; ppm7[140] = 54; ppm7[141] = 54; ppm7[142] = 53; ppm7[143] = 52; ppm7[144] = 52; ppm7[145] = 51; ppm7[146] = 51; ppm7[147] = 50; ppm7[148] = 50; ppm7[149] = 49; ppm7[150] = 49; int ppm136[161]; ppm136[0] = 199; ppm136[1] = 194; ppm136[2] = 188; ppm136[3] = 183; ppm136[4] = 178; ppm136[5] = 173; ppm136[6] = 168; ppm136[7] = 163; ppm136[8] = 159; ppm136[9] = 154; ppm136[10] = 150; ppm136[11] = 146; ppm136[12] = 142; ppm136[13] = 139; ppm136[14] = 135; ppm136[15] = 131; ppm136[16] = 128; ppm136[17] = 125; ppm136[18] = 122; ppm136[19] = 119; ppm136[20] = 116; ppm136[21] = 113; ppm136[22] = 110; ppm136[23] = 107; ppm136[24] = 105; ppm136[25] = 102; ppm136[26] = 100; ppm136[27] = 97; ppm136[28] = 95; ppm136[29] = 93; ppm136[30] = 91; ppm136[31] = 89; ppm136[32] = 86; ppm136[33] = 84; ppm136[34] = 83; ppm136[35] = 81; ppm136[36] = 79; ppm136[37] = 77; ppm136[38] = 75; ppm136[39] = 74; ppm136[40] = 72; ppm136[41] = 71; ppm136[42] = 69; ppm136[43] = 68; ppm136[44] = 66; ppm136[45] = 65; ppm136[46] = 63; ppm136[47] = 62; ppm136[48] = 61; ppm136[49] = 59; ppm136[50] = 58; ppm136[51] = 57; ppm136[52] = 56; ppm136[53] = 55; ppm136[54] = 54; ppm136[55] = 53; ppm136[56] = 52; ppm136[57] = 50; ppm136[58] = 49; ppm136[59] = 49; ppm136[60] = 48; ppm136[61] = 47; ppm136[62] = 46; ppm136[63] = 45; ppm136[64] = 44; ppm136[65] = 43; ppm136[66] = 42; ppm136[67] = 42; ppm136[68] = 41; ppm136[69] = 40; ppm136[70] = 39; ppm136[71] = 39; ppm136[72] = 38; ppm136[73] = 37; ppm136[74] = 37; ppm136[75] = 36; ppm136[76] = 35; ppm136[77] = 35; ppm136[78] = 34; ppm136[79] = 33; ppm136[80] = 33; ppm136[81] = 32; ppm136[82] = 32; ppm136[83] = 31; ppm136[84] = 31; ppm136[85] = 30; ppm136[86] = 30; ppm136[87] = 29; ppm136[88] = 29; ppm136[89] = 28; ppm136[90] = 28; ppm136[91] = 27; ppm136[92] = 27; ppm136[93] = 26; ppm136[94] = 26; ppm136[95] = 25; ppm136[96] = 25; ppm136[97] = 25; ppm136[98] = 24; ppm136[99] = 24; ppm136[100] = 23; ppm136[101] = 23; ppm136[102] = 23; ppm136[103] = 22; ppm136[104] = 22; ppm136[105] = 22; ppm136[106] = 21; ppm136[107] = 21; ppm136[108] = 21; ppm136[109] = 20; ppm136[110] = 20; ppm136[111] = 20; ppm136[112] = 19; ppm136[113] = 19; ppm136[114] = 19; ppm136[115] = 19; ppm136[116] = 18; ppm136[117] = 18; ppm136[118] = 18; ppm136[119] = 17; ppm136[120] = 17; ppm136[121] = 17; ppm136[122] = 17; ppm136[123] = 16; ppm136[124] = 16; ppm136[125] = 16; ppm136[126] = 16; ppm136[127] = 16; ppm136[128] = 15; ppm136[129] = 15; ppm136[130] = 15; ppm136[131] = 15; ppm136[132] = 14; ppm136[133] = 14; ppm136[134] = 14; ppm136[135] = 14; ppm136[136] = 14; ppm136[137] = 14; ppm136[138] = 13; ppm136[139] = 13; ppm136[140] = 13; ppm136[141] = 13; ppm136[142] = 13; ppm136[143] = 12; ppm136[144] = 12; ppm136[145] = 12; ppm136[146] = 12; ppm136[147] = 12; ppm136[148] = 12; ppm136[149] = 12; ppm136[150] = 11; ppm136[151] = 11; ppm136[152] = 11; ppm136[153] = 11; ppm136[154] = 11; ppm136[155] = 11; ppm136[156] = 11; ppm136[157] = 10; ppm136[158] = 10; ppm136[159] = 10; ppm136[160] = 10; TCNT1 = 57723; TCCR1B = (1<<CS12) | (1<<CS10); TIMSK1 = (1<<TOIE1); usart_init(0); usart_init(1); usart_init(2); usart_init(3); init_GPS(); F = 0; int f_num = 0; char tick = 10; char sd_valid = 0; f_mount(&FatFs, "", 0); /* Give a work area to the default drive */ sei(); while (1) { if(sd_valid == 0) { sprintf(fil_nm, "data%d.txt",f_num); if((fr = f_open(&Fil, fil_nm, FA_WRITE | FA_CREATE_NEW)) && f_num < 9999) f_num++; else sd_valid = 1; } if(rec_dylos_flag == 1) { rec_dylos_flag = 0; new_dylos_data = 1; tick = 0; if(rec_dylos[strlen(rec_dylos) - 1] == '\n') { dylos_line = 1; strncpy(dylos, rec_dylos, strlen(rec_dylos)); strclr(rec_dylos); } } if(rec_GPS_flag == 1) { rec_GPS_flag = 0; new_GPS_data = 1; if(rec_GPS[strlen(rec_GPS) - 1] == '\n') { GPS_line = 1; strncpy(GPS, rec_GPS, strlen(rec_GPS)); strclr(rec_GPS); } } if(dylos_line == 1) { parse_dylos(dylos, dylos_data); dylos_line = 0; } if(GPS_line == 1) { parse_GPS(GPS, GPS_data); GPS_line = 0; } if(ov_flag == 1) { ov_flag = 0; tick++; if(new_GPS_data == 1) { if(GPS_data[9] == 1) { sprintf(sd_buff, "Date: %.2d/%.2d/%.2d\nTime: %.2d:%.2d:%.2d\nLatitude: %d %d.%d\nLongitude: %d %d.%d\nAltitude %d.%d\n", GPS_data[12], GPS_data[13], GPS_data[14], GPS_data[0], GPS_data[1], GPS_data[2], GPS_data[3], GPS_data[4], GPS_data[5], GPS_data[6], GPS_data[7], GPS_data[8], GPS_data[10], GPS_data[11]); sprintf(buffer,"%.2d:%.2d:%.2d,%d,%d.%d,%d,%d.%d,%d.%d,",GPS_data[0], GPS_data[1], GPS_data[2], GPS_data[3], GPS_data[4], GPS_data[5], GPS_data[6], GPS_data[7], GPS_data[8], GPS_data[10], GPS_data[11]); } else { sprintf(sd_buff, "Time: %.2d:%.2d:%.2d\nNO GPS DATA AVAILABLE\n", GPS_data[0], GPS_data[1], GPS_data[2]); sprintf(buffer,"%.2d:%.2d:%.2d,0,0.0,0,0.0,0.0,", GPS_data[0], GPS_data[1], GPS_data[2]); } sd_write(sd_buff, &Fil, fil_nm, sd_valid); usart_send(3, buffer); new_GPS_data = 0; } else usart_send(3,"00:00:00,0,0.0,0,0.0,0.0,"); if(new_dylos_data == 1 || tick < 8) { sprintf(sd_buff, "Small: %d\nLarge: %d\n", dylos_data[0], dylos_data[1]); sprintf(buffer, "%d,%d,", dylos_data[0], dylos_data[1]); usart_send(3, buffer); sd_write(sd_buff, &Fil, fil_nm, sd_valid); new_dylos_data = 0; } else usart_send(3,"0,0,"); F = read_temp(); sprintf(sd_buff, "Temperature %dF\n", F); sprintf(buffer, "%d,", F); usart_send(3, buffer); sd_write(sd_buff, &Fil, fil_nm, sd_valid); C3H8 = read_MQ2(); if(C3H8 < -1) { usart_send(3, "-1,"); sd_write("C3H8: ERROR - MQ2 reading out of range\n", &Fil, fil_nm, sd_valid); } else if(C3H8 == -1) { sprintf(sd_buff, "C3H8: %d ppm \n",0); usart_send(3, "0,"); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } else { sprintf(sd_buff, "C3H8: %d ppm \n",ppm2[C3H8]); sprintf(buffer, "%d,", ppm2[C3H8]); usart_send(3, buffer); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } CH4 = read_MQ5(); if(CH4 < -1) { usart_send(3, "-1,"); sd_write("CH4 : ERROR - MQ5 reading out of range\n", &Fil, fil_nm, sd_valid); } else if(CH4 == -1) { sprintf(sd_buff, "CH4 : %d ppm \n",0); usart_send(3, "0,"); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } else { sprintf(sd_buff, "CH4 : %d ppm \n",ppm5[CH4]); sprintf(buffer, "%d,", ppm5[CH4]); usart_send(3, buffer); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } CO = read_MQ7(); if(CO < -1) { usart_send(3, "-1,"); sd_write("CO : ERROR - MQ7 reading out of range\n", &Fil, fil_nm, sd_valid); } else if(CO == -1) { sprintf(sd_buff, "CO : %d ppm \n",0); usart_send(3, "0,"); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } else { sprintf(sd_buff, "CO : %d ppm \n",ppm7[CO]); sprintf(buffer, "%d,", ppm7[CO]); usart_send(3, buffer); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } H2S = read_MQ136(); if(H2S < -1) { usart_send(3, "-1\n"); sd_write("H2S : ERROR - MQ136 reading out of range\n\n", &Fil, fil_nm, sd_valid); } else if(H2S == -1) { sprintf(sd_buff, "H2S : %d ppm \n\n",0); usart_send(3, "0\n"); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } else { sprintf(sd_buff, "H2S : %d ppm \n\n",ppm136[H2S]); sprintf(buffer, "%d\n", ppm136[H2S]); usart_send(3, buffer); sd_write(sd_buff, &Fil, fil_nm, sd_valid); } } } return 0; }