Real-time control software design the second week of work

Source: Internet
Author: User

State analysis

Described by the topic, there are only two different events, one is vehicle entry, one is vehicle departure, and the corresponding sensor signal, landing bar signal, the signal is changed together, so can be simplified into two composite states.

Code implementation

Sensor header File

////Created by Zhuhaihao on 2016/12/4.//#ifndef Statemachine_statemachine_h#defineStatemachine_statemachine_hclassSensor { Public: Sensor (); Sensor (BOOLState ); BOOLGetState ()Const; voidSetState (BOOLnewstate); voidrestore ();Private:    //here, a state is used to indicate that the vehicle enters the sensor signal and the vehicle leaves the sensor signal.//If True indicates vehicle entry false indicates the vehicle is leaving    BOOLState ;};#endif //Statemachine_statemachine_h

Sensor implementation

////Created by Zhuhaihao on 2016/12/4.//#include".. /header/sensor.h"#include<iostream>using  namespacestd; Sensor::sensor () { state=false;} Sensor::sensor (BOOLState ) {     This->state =State ;}BOOLSensor::getstate ()Const {    return  This-State ;}voidSensor::setstate (BOOLnewstate) {     This->state =newstate;}voidSensor::restore () { This->state =false;}

The code for the remaining parts is similar to the sensor. All the code here https://github.com/hacktw/RTCSD2016

////Created by Zhuhaihao on 2016/12/4.//#include".. /header/gurdsystem.h"#include<iostream>using namespacestd;voidGurdsystem::carin () { This->sensor.setstate (true); cout<<"Now the car is comming in ..."<<Endl; if( ! This-lifter.getstate ()) {         This-lifter.action (); cout<<"Lifter up ..."<<Endl; }    if( ! This-light.getstate ()) {         This-light.action (); cout<<"Light Green ..."<<Endl; }}voidgurdsystem::carout () { This->sensor.setstate (false); cout<<"Now the car is comming out ..."<<Endl; if( This-lifter.getstate ()) {         This-lifter.action (); cout<<"Lifter down ..."<<Endl; }    if( This-light.getstate ()) {         This-light.action (); cout<<"Light Red ..."<<Endl; }}

Test

Real-time control software design the second week of work

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.