summaryrefslogtreecommitdiff
path: root/branches/sm-unittesting/src/org/reprap/comms/port/testhandlers/TestStepper.java
blob: 6b41affb5a6190c266954e6812593258246654c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.reprap.comms.port.testhandlers;

import java.io.PipedOutputStream;

import org.reprap.comms.snap.SNAPPacket;
import org.reprap.devices.GenericStepperMotor;

public class TestStepper extends TestDevice {
	protected boolean notifications = false;
	
	public void receivePacket(PipedOutputStream out, SNAPPacket packet) throws Exception {
		byte payload [] = packet.getPayload();
		switch(payload[0]) {
		case GenericStepperMotor.MSG_GetPosition:
			reply(out, packet, new byte[] { GenericStepperMotor.MSG_GetPosition, 0, 0 });
			return;
		case GenericStepperMotor.MSG_SetNotification:
			notifications = (payload[1] != 255);
			System.out.println("Notifications " + notifications);
			return;
		case GenericStepperMotor.MSG_SetSyncMode:
		case GenericStepperMotor.MSG_SetPower:
			// Ignore these
			return;
		case GenericStepperMotor.MSG_DDAMaster:
			if (notifications)
				// For now, just reply with movement completion 
				reply(out, packet, new byte[] { GenericStepperMotor.MSG_DDAMaster, 0, 0 });				
			return;
		}

		super.receivePacket(out, packet);
	}
	

}