コード例 #1
0
//Called by main
//Initializes all the other modules and goes to eternal for loop
func RunLift(quitCh chan bool) {
	var buttonPress = make(chan driver.Button, 5)
	var status = make(chan driver.LiftStatus, 5)
	myID = udp.NetInit(toNetwork, fromNetwork, quitCh)
	fsmelev.Init(floorOrder, setLight, status, buttonPress, motorStopCh, quitCh)
	restoreBackup()
	liftStatus = <-status
	ticker1 := time.NewTicker(10 * time.Millisecond).C
	ticker2 := time.NewTicker(5 * time.Millisecond).C
	log.Println("Network UP \n Driver UP \n My id:", myID)
	for {
		select {
		case button = <-buttonPress:
			newKeyPress(button)
		case liftStatus = <-status:
			runQueue(liftStatus, floorOrder)
		case message = <-fromNetwork:
			newMessage(message)
			orderLight(message)
		case <-ticker1:
			checkTimeout()
		case <-ticker2:
			runQueue(liftStatus, floorOrder)
		case <-quitCh:
			return
		}
	}
}
コード例 #2
0
func TestUdpModule(t *testing.T) {
	var id int
	toNetwork := make(chan udp.Message, 10)
	fromNetwork := make(chan udp.Message, 10)
	quit := make(chan bool)
	id = udp.NetInit(toNetwork, fromNetwork, quit)
	fmt.Println("id is: ", id)
	count := 0
	for {
		message := udp.Message{
			LiftId:    111,
			Floor:     111,
			Direction: true,
			Status:    udp.New,
			Weight:    5,
			TimeRecv:  time.Now()}
		toNetwork <- message

		time.Sleep(time.Second * 1)
		select {
		case recv := <-fromNetwork:
			fmt.Println("received message", recv.LiftId)
		default:
			fmt.Println("no message")
		}
		count++
		if count > 5 {
			break
		}
	}
}