1 / 24

Design of Software Systems

Design of Software Systems. Self-Documenting Code. 이용자를 위한 Comment 유효한 입력 자료의 형태는 ? 어떠한 출력이 가능한가 ? 어떠한 일을 하는 소프트웨어 인가 ? 해당 모듈을 Call 하는 방법은 ? 에러가 발생할 조건은 ? 개발자를 위한 Comment 소프트웨어가 어떻게 동작 하나 ? 어떠한 알고리즘이 사용되었나 ? 어떻게 소프트웨어가 테스트 되었나 ? 어떻게 소프트웨어를 변경할 수 있나 ?. Self-Documenting Code.

charla
Télécharger la présentation

Design of Software Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design of Software Systems

  2. Self-Documenting Code • 이용자를 위한 Comment • 유효한 입력 자료의 형태는? • 어떠한 출력이 가능한가? • 어떠한 일을 하는 소프트웨어 인가? • 해당 모듈을 Call 하는 방법은? • 에러가 발생할 조건은? • 개발자를 위한 Comment • 소프트웨어가 어떻게 동작 하나? • 어떠한 알고리즘이 사용되었나? • 어떻게 소프트웨어가 테스트 되었나? • 어떻게 소프트웨어를 변경할 수 있나?

  3. Self-Documenting Code • 나쁜 Comment 예 • X=X+4; /* add 4 to x */ • Flag = 0; /* set Flag = 0 */ • 좋은 Comment 예 • X=X+4; /* 4 is added to correct for the offset (mV) in the transducer */ • Flag = 0; /* mean no key has been typed */

  4. Self-Documenting Code • Subroutine 과 Function의 Comment • 이용자를 위한 Comment • 어떻게 Function이 사용 되는가? • 어떻게 Parameters가 Pass 되는가? • 어떤 종류의 에러가 발생될 수 있는 가? • 어떻게 결과가 Return 되는가? • 개발자를 위한 Comment • 어떻게 함수가 동작하는가? • Comment 의 위치 • 이용자를 위한 Comment • C 언어인 경우 : *.h file 에 작성 • Assembly 언어 인 경우 : Function의 시작 전에 작성 • 개발자를 위한 Comment • C 언어인 경우 : *.cfile 에 작성 • Assembly 언어 인 경우 : Function의 Body에 작성

  5. Self-Documenting Code • 이해하기 쉽고 변경하기 쉬운 소프트웨어의 작성 • #define 문 이용한 이해하기 쉽고 변경하기 쉬운 소프트웨어의 작성 • #define 문의 부적절한 사용 예

  6. Self-Documenting Code • #define 문의 적절한 사용 예

  7. Module 이용자에게 필요한 Comment • Purpose of the module • Input parameters • How passed (call by value, call by reference) • 적정한 범위(입력이 적정한 범위에 있는가?) • Format(8 bit/16 bit, signed/unsigned, etc) • Output parameters • How passed (return by value, return by reference) • Format(8 bit/16 bit, signed/unsigned, etc) • Example input and output • Error condition • Example calling sequence • Local variables 와 그들의 의미

  8. Naming Convention • 의미 있는 Name을 사용하라. • 모호한(혼동의 우려가 있는) name을 사용 하지 마라. • Data type 을 알 수 있도록 하라. • 같은 type의 Object에 같은(유사한) 이름을 사용 하라. • Public object 를 구분할 수 있는 접두사를 사용하라. • 대문자와 소문자를 사용하여 Object의 Scope를 구분하라. 대문자 사용 소문자 로 시작 대문자로 구분 대 문자로 시작 대 문자로 구분 _ 로 구분

  9. Software Abstraction • Software Abstraction 은 복잡한 시스템을 잘 정의된 추상화된 기본 모듈을 사용 구성 한다. 그 결과 • 개발 기간이 단축되고, • 미리 개발된 많은 Building Block을 사용 • 이해하기 쉽고, • 보수 유지가 용이 하고, • 최적화가 용이한 소프트웨어 시스템을 설계할 수 있다.

  10. Software Abstraction • Software Abstraction의 대표적인 예는 • Finite-State Machine(FSM) • Moore FSM • Output은 오직 현재의 State에 의하여만 결정 된다. • Input은 State Transition에 만 영향을 준다. • Mealy FSM • 현재의 상태와 Input에 의하여 Output이 결정된다. • Proportion Integral Derivative (PDI) Digital Controller • Fuzzy Logic Digital Controller • Neural Network • Linear System of Differential Equation

  11. Moore Finite-State Machine Traffic Light Controller • 2개의 입력 센서 사용 • 0 0 : 북,동쪽 모두 차량이 없음 • 0 1 : 동쪽 길에만 차량 있음 • 1 0 : 북쪽 길에만 차량 있음 • 1 1 : 양쪽 길에 모두 차량 있음 북쪽 센서 동쪽 센서 PD1 PD0 PF5 PF4 PF3 PF2 PF1 PF0 Atmega 128

  12. Moore Finite-State Machine Traffic Light Controller • Output State • goN : 100001 동쪽 신호 Red ,북쪽 신호 Green • wateN : 100010 동쪽 신호 Red , 북쪽 신호 Yellow • goE : 001100 동쪽 신호 Green, 북쪽 신호 Red • wateE : 010100 동쪽 신호 Yellow, 북쪽 신호 Red MSB : 동쪽 신호Red, Yellow, Green북쪽 신호Red, Yellow, GreenLSB • 교통 신호의 동작 기술 • 양방향 모두 차가 없는 경우 현재의 Green 상태 유지 • Green에서 Red로 변경 시 5초간 황색 신호 유지 • Green 신호는 최소 30초간 유지 • 만약 차가 한 방향에서만 오는 경우 그 방향의 Green 신호 를 계속 유지 • 양 방향에서 차가 오는 경우 4 상태를 순차적 이동

  13. Moore Finite-State Machine Traffic Light Controller 0 출력 Table 2.12 Tabular form of Moore FSM that implements a traffic light.

  14. Moore Finite-State Machine Traffic Light Controller • First Step : Operation Sequence 의 결정 • Timer와 I/O Port 의 초기화 • 초기 상태 설정 • FSM 제어기 구현 • 현재 상태에 따른 신호 상태를 출력 • 현재 상태에 따른 Delay 실현 • 입력 Sensor로부터 입력 • 현재 상태와 입력에 따라 다음 상태로 천이

  15. Moore Finite-State Machine Traffic Light Controller • Second Step : Data Structure 정의 • C 언어 프로그래밍 예

  16. // Table implementation conststruct State { unsigned char Out; unsigned short Time; unsigned char Next[4];}; typedefconststruct State STyp; #define goN 0 #define waitN 1 #define goE 2 #define waitE 3 STyp FSM[4]={ {0x21,3000,{goN,waitN,goN,waitN}}, {0x22, 500,{goE,goE,goE,goE}}, {0x0C,3000,{goE,goE,waitE,waitE}}, {0x14, 500,{goN,goN,goN,goN}} }; void main(void){ unsigned char n; // state number unsigned char Input; Timer_Init(); PORTF = 0x00; DDRF = 0xFF; DDRD &= ~0x03; n = goN; while(1){ PORTF = FSM[n].Out; Timer_Wait10ms(FSM[n].Time); Input = (~PORTD) & 0x03; n = FSM[n].Next[Input]; } } • C 언어 프로그래밍 예: Table implementation

  17. // Pointer implementation conststruct State { unsigned char Out; unsigned short Time; conststruct State *Next[4];}; typedefconststruct State STyp; #define goN &FSM[0] #define waitN &FSM[1] #define goE &FSM[2] #define waitE &FSM[3] STyp FSM[4]={ {0x21,3000,{goN,waitN,goN,waitN}}, {0x22, 500,{goE,goE,goE,goE}}, {0x0C,3000,{goE,goE,waitE,waitE}}, {0x14, 500,{goN,goN,goN,goN}} }; void main(void){ STyp *Pt; // state pointer unsigned char Input; Timer_Init(); PORTF = 0x00; DDRF = 0xFF; DDRD &= ~0x03; Pt = goN; while(1){ PORTF = Pt->Out; Timer_Wait10ms(Pt->Time); Input = (~PORTD) & 0x03; Pt = Pt->Next[Input]; } } Program 2.11. Two 6812 C implementations of a Moore FSM. : Pointer implementation

  18. Mealy Finite-State Machine Robot Controller PD1 PD0 PF3 PF2 Pf1 Pf0 AVR 128 • Robot은 Mood 센서 Port A를 통하여을 4가지의 가능한 입력 상태를 갖는다. • 00 : Ok, 현재 상태로 기분 좋음. • 01 : Tired, 피곤하기 때문에 현재 보다 편한 상태를 원함. • 10 : Curious, 주변에 대하여 관심을 보이는 상태, 이 상태에서는 않거나서있는 상태에 있어야 한다. • 11 : Anxious, 위험을 감지함. 현재보다 긴장된 상태로 돌입하여야 함.

  19. Mealy Finite-State Machine Robot Controller • Robot은 Standing, Sitting, Sleeping 3가지 상태를 갖는다. • Robot은 4가지 상태의 출력을 갖는다. • PB3 SitDown, 현재 서있는 상태에서 앉아 있는 상태로 • PB2 StandUp, 현재 앉아 있는 상태에서 서있는 상태로 • PB1 LieDown, 현재 앉아 있는 상태에서 누운 상태로 • PB0 SitUp, 현재 누운 상태에서 앉아 있는 상태로 입력 출력

  20. Mealy Finite-State Machine Robot Controller • Software Design의 첫 단계에서는 동작의 순서를 결정함. • Input/Output Port를 초기화함. • 초기 상태를 기술함. • FSM Controller 를 구현함 • Sensors Input • 현재 상태와 입력에 따라 Robot 에 Output • 현재 상태와 입력에 따라 상태를 천이 한다. • 둘째 단계에서는 Linked data structure를 사용하여 FSM Graph를 정의한다.

  21. C Implementation of a Mealy Finite State Machine. • Output defined as numbers // outputs defined as numbers conststruct State{ unsigned char Out[4]; // outputs conststruct State *Next[4]; // Next }; typedefconststruct State StateType; #define Standing &fsm[0] #define Sitting &fsm[1] #define Sleeping &fsm[2] #define None 0x00 #define SitDown 0x08 // pulse on PF3 #define StandUp 0x04 // pulse on PF2 #define LieDown 0x02 // pulse on PF1 #define SitUp 0x01 // pulse on PF0 StateType FSM[3]={ {{None,SitDown,None,None}, //Standing {Standing,Sitting,Standing,Standing}}, {{None,LieDown,None,StandUp}, //Sitting {Sitting,Sleeping,Sitting,Standing }}, {{None,None,SitUp,SitUp}, //Sleeping {Sleeping,Sleeping,Sitting,Sitting}} }; void main(void){ StatePtr *Pt; // Current State unsigned char Input; DDRF = 0xFF; // Output to robot DDRD &= ~0x03; // Input from sensor Pt = Standing; // Initial State while(1){ Input = (~PORTD) & 0x03; // Input=0-3 PORTF =Pt->Out[Input]; // Pt= Pt->Next[Input]; // next state } }

  22. C Implementation of a Mealy Finite State Machine. • Output defined as functions // outputs defined as functions conststruct State{ void (*CmdPt)[4](void); // outputs conststruct State *Next[4]; // Next }; typedefconststruct State StateType; TypedefStateType * StatePtr; #define Standing &fsm[0] #define Sitting &fsm[1] #define Sleeping &fsm[2] void None(void){}; void SitDown(void){ PORTF=0x08;} // PF3 void StandUp(void){ PORTF=0x04; PORTB=0;} // PF2 void LieDown(void){ PORTF=0x02; PORTB=0;} // PF1 void SitUp(void) { PORTF=0x01; PORTB=0;} // PF0 StateType FSM[3]={ {{&None,&SitDown,&None,&None}, //Standing {Standing,Sitting,Standing,Standing}}, {{&None,&LieDown,&None,&StandUp},//Sitting {Sitting,Sleeping,Sitting,Standing }}, {{&None,&None,&SitUp,&SitUp}, //Sleeping {Sleeping,Sleeping,Sitting,Sitting}} }; void main(void){ StatePtr Pt; // Current State unsigned char Input; DDRF = 0xFF; // Output to robot DDRD &= ~0x03; // Input from sensor Pt = Standing; // Initial State while(1){ Input = (~PORTD) & 0x03; // Input=0-3 (*Pt->CmdPt[Input])(); // function Pt = Pt->Next[Input]; // next state } }

  23. M1500 M2000 W2000 W1000 M1000 W1500 500원 출력 None None None 캔출력 None W캔출력 M0 W500 M500 None None None None Vending Machine(Moore Finite-State Machine) 입력에 관계없이 언제나 • Vending Machine은 센서 Port A를 통 하여 3가지의 가능한 입력 상태를 갖고 캔의 가격은 1500원 이다. • 00 : 입력 없음. • 01 : 500원 동전 입력 상태. • 10 : 1000원 동전 입력 상태. • 11 : 불가능한 입력. 500원 입력 100원 입력

  24. Vending Machine(Moore Finite-State Machine) • Program 예

More Related