// The operation method which simulates the car system. public void operate() { ignition_state = ignition.get_key_status(); if (ignition_state == IgnitionState.withdrawn_key) { engineinterface.engine_turn_off(); } else { // Get the current levels of the petrol and oil sensors. petrol_state = petrolmonitor.get_petrol_level(); oil_pressure_state = oilmonitor.get_pressure_level(); oil_temperature_state = oilmonitor.get_temperature_level(); if (petrol_state == PetrolState.petrol_low) { dashboard.petrol_light_on(); } // Explicit to let CC know??? else { dashboard.petrol_light_off(); } // Check Oil Pressure State if (oil_pressure_state == OilPressureState.oil_pressure_high) { dashboard.oil_pressure_light_on(); } else { dashboard.oil_pressure_light_off(); } // Check Oil Temperature State if (oil_temperature_state == OilTemperatureState.oil_temperature_high) { dashboard.oil_temperature_light_on(); } else { dashboard.oil_temperature_light_off(); } // Turn on engine if it is off engineinterface.check_engine_state(); if (engineinterface.engine_state == EngineState.engine_off && engineinterface.engine_good) { engineinterface.engine_turn_on(); } // Check the state of the engine, brakes and the two set of pedals. engineinterface.check_engine_state(); brakeinterface.check_brake_state(); accelerator_state = pedals.get_accelerator_status(); brake_pedal_state = pedals.get_brake_pedal_status(); // If the engine has failed or the brake pedals have been pressed -> apply the brakes aslong has they haven't failed if ((engineinterface.engine_good == false || brake_pedal_state == PedalState.pedal_pressed) && brakeinterface.brakes_good) { brakeinterface.apply_brakes(); Console.WriteLine("Decreasing speed"); engineinterface.decrease_speed(1); } // If the brakes have failed if (brakeinterface.brakes_good == false) { engineinterface.engine_turn_off(); Contract.Assert(engineinterface.engine_state == EngineState.engine_off && brakeinterface.brakes_good == false); } else // Brakes are good, engine might still have failed though -> check whether to increase or decrease the speed { // Only release the brakes if the engine hasen't failed if (brake_pedal_state == PedalState.pedal_released && engineinterface.engine_good) { brakeinterface.release_brakes(); } if (accelerator_state == PedalState.pedal_released) { engineinterface.decrease_speed(1); } // Increase speed if the accelerator is pressed and the engine is on if (accelerator_state == PedalState.pedal_pressed && engineinterface.engine_state == EngineState.engine_on) { engineinterface.increase_speed(1); } } } }
public void oil_pressure_high_dashboard_light_test() { oil_pressure_state = OilPressureState.oil_pressure_high; dashboard.oil_pressure_light_on(); }