int main(int argc, char *argv[]) { if (argc == 1) { // if no arguments are specified run in Interactive mode // prints initial prompt printf("mysh> "); // Interactive loop to keep asking user for input execShell(stdin, 0); } else if (argc == 2) { // batch mode in case of arguments // replace stdin stream with batchFile stream FILE *batchFile = freopen(argv[1], "r", stdin); if (batchFile == NULL ) { // unable to open filename displayError(); exit(1); } execShell(batchFile, BATCH_MODE); exit(0); } else { // invalid number of args (n>2) displayError(); //exit gracefully exit(EXIT_FAILURE); } return (0); }
void createVehicleInfo(){ //Open VI. Once complete, rename VI.txt. File vinfo = FileSystem.open("/mnt/sd/VI", FILE_APPEND); //Get VIN char vin[VIN_LENGTH]; #ifdef DEBUG for(byte i = 0; i < VIN_LENGTH; i++) vin[i] = 48; //'a' #else if(!obd.getVIN(vin, VIN_LENGTH)) error(F("Could not read VIN")); #endif //Write VIN to file. //byte writeSize = vinfo.write(reinterpret_cast<const byte*>(vin), VIN_LENGTH); //Convert from char (from OBD reader) to const unsigned char (for file write) digitalWrite(13, HIGH); byte writeSize = vinfo.write((byte*)vin, VIN_LENGTH); //Convert from char (from OBD reader) to const unsigned char (for file write) vinfo.flush(); digitalWrite(13, LOW); #ifdef DEBUG if(writeSize != VIN_LENGTH) error(F("VIN not printed to file properly")); #endif //for each possible PID, check if the request is successful. //if so, store it in validPIDs and increment validPIDCount validPIDs = (byte*)malloc(NUM_PIDS); int result; validPIDCount = 0; for(byte i = 0; i < NUM_PIDS; i++){ byte PID = allPIDs[i]; if(PIDisValid(PID)){ vinfo.write(PID); validPIDs[validPIDCount] = PID; ++validPIDCount; } } vinfo.close(); if(validPIDCount == 0) error(F("No valid PIDs on vinfo creation")); execShell("mv /mnt/sd/VI /mnt/sd/VI.txt"); }
void checkDebugModeSwitch(){ //Empty file debug exists if we last ran in debug mode bool prevState = FileSystem.exists("/mnt/sd/flags/debug"); #ifdef DEBUG if(prevState == false){ execShell(F("touch /mnt/sd/flags/debug")); FileSystem.remove("/mnt/sd/VI.txt"); } #else if(prevState == true){ FileSystem.remove("/mnt/sd/flags/debug"); FileSystem.remove("/mnt/sd/VI.txt"); } #endif }