/dongfang_FC_rewrite_tool/src/dongfang/mkt/RequestFrameVisitor.java |
---|
10,6 → 10,8 |
import dongfang.mkt.frames.ExternalControlRequestFrame; |
import dongfang.mkt.frames.LoopbackTestRequestFrame; |
import dongfang.mkt.frames.MotorTestRequestFrame; |
import dongfang.mkt.frames.OSDDataRequestFrame; |
import dongfang.mkt.frames.ReadExternalControlRequestFrame; |
import dongfang.mkt.frames.ResetRequestFrame; |
import dongfang.mkt.frames.SetCompassHeadingRequestFrame; |
import dongfang.mkt.frames.SingleDisplayRequestFrame; |
35,4 → 37,6 |
void visit(UniversalReadParamSetRequestFrame f) throws IOException; |
void visit(UniversalWriteParamSetRequestFrame f) throws IOException; |
void visit(SetCompassHeadingRequestFrame f) throws IOException; |
void visit(ReadExternalControlRequestFrame f) throws IOException; |
void visit(OSDDataRequestFrame f) throws IOException; |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ConfigSet.java |
---|
3,9 → 3,7 |
import java.io.File; |
import java.io.IOException; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
261,7 → 259,7 |
// It does not parse the section and default information, which could be |
// useful for GUIs etc. |
public static ConfigSet parseXMLConfigSet(int version) throws IOException { |
String fileName = "v" + version + ".xml"; |
String fileName = "configsets/templates/v" + version + ".xml"; |
File f = new File(fileName); |
DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
saxfac.setValidating(false); |
271,7 → 269,7 |
XPath xpath = XPathFactory.newInstance().newXPath(); |
String s_eepromVersion = xpath.evaluate( |
"/parameterconfig/@eepromVersion", doc); |
"/parametertemplate/@eepromVersion", doc); |
int eepromVersion = Integer.parseInt(s_eepromVersion); |
if (eepromVersion != version) { |
278,7 → 276,7 |
throw new IOException( |
"Version mismatch between file name (" |
+ fileName |
+ ") and the version in the parameterconfig/@eepromVersion attribute(" |
+ ") and the version in the parametertemplate/@eepromVersion attribute(" |
+ s_eepromVersion + ")"); |
} |
285,35 → 283,31 |
ConfigSet result = new ConfigSet(eepromVersion); |
NodeList sectionNodes = (NodeList) xpath.evaluate( |
"/section", doc, XPathConstants.NODESET); |
"/parametertemplate/section", doc, XPathConstants.NODESET); |
for (int i = 0; i < sectionNodes.getLength(); i++) { |
Element e = (Element) sectionNodes.item(i); |
Section section = new Section(e.getAttribute("name"), e.getAttribute("title")); |
Element sectionNode = (Element) sectionNodes.item(i); |
Section section = new Section(sectionNode.getAttribute("name"), sectionNode.getAttribute("title")); |
result.declaredSections.add(section); |
} |
NodeList parameterNodes = (NodeList) xpath.evaluate( |
"/parameterconfig/parameter", doc, XPathConstants.NODESET); |
"parameter", sectionNode, XPathConstants.NODESET); |
Section rest = new Section("others", "Entries without a declared section"); |
for (int i = 0; i < parameterNodes.getLength(); i++) { |
Element e = (Element) parameterNodes.item(i); |
for (int j=0; j<parameterNodes.getLength(); j++) { |
Element parameterNode = (Element) parameterNodes.item(j); |
Map<String, Section> sectionMap = new HashMap<String, Section>(); |
ConfigEntry entry; |
if (!e.hasAttribute("name")) { |
throw new IOException("A parameter element (the " + i |
+ "th) had no name attribute!"); |
if (!sectionNode.hasAttribute("name")) { |
throw new IOException("A parameter element (the " + j |
+ "th in section "+sectionNode.getAttribute("name")+") had no name attribute!"); |
} |
String s_name = e.getAttribute("name"); |
String s_section = e.getAttribute("section"); |
String s_name = parameterNode.getAttribute("name"); |
String s_type; |
if (e.hasAttribute("type")) { |
s_type = e.getAttribute("type"); |
if (parameterNode.hasAttribute("type")) { |
s_type = parameterNode.getAttribute("type"); |
} else { |
s_type = "static"; |
} |
323,30 → 317,24 |
} else if ("dynamic".equals(s_type)) { |
entry = new ConfigSet.ByteEntry(s_name, true); |
} else if ("bitset".equals(s_type)) { |
NodeList bitNodes = (NodeList) xpath.evaluate("bit", e, |
XPathConstants.NODESET); |
NodeList bitNodes = (NodeList) xpath.evaluate("bit", parameterNode, XPathConstants.NODESET); |
String[] bitNames = new String[8]; |
for (int j = 0; j < 8; j++) { |
Element bitNode = (Element) bitNodes.item(j); |
for (int k=0; k<8; k++) { |
Element bitNode = (Element) bitNodes.item(k); |
if (bitNode != null) { |
bitNames[j] = bitNode.getAttribute("name"); |
bitNames[k] = bitNode.getAttribute("name"); |
} else { |
bitNames[j] = "Unused"; |
bitNames[k] = "Unused"; |
} |
} |
entry = new ConfigSet.BitSetEntry(s_name, |
bitNames); |
entry = new ConfigSet.BitSetEntry(s_name, bitNames); |
} else { |
throw new IOException("Unknown parameter type: " + s_type); |
} |
result.entries.add(entry); |
Section section = sectionMap.get(s_section); |
if (section==null) section = rest; |
section.addConfigEntry(entry); |
} |
if (!rest.getEntries().isEmpty()) { |
result.declaredSections.add(rest); |
} |
result.name = "" + version; |
return result; |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/OSDDataRequestFrame.java |
---|
0,0 → 1,26 |
package dongfang.mkt.frames; |
import java.io.IOException; |
import dongfang.mkt.RequestFrameVisitor; |
public class OSDDataRequestFrame extends RequestFrame { |
private int autoSendInterval; |
public OSDDataRequestFrame() { |
super(NC_ADDRESS); |
} |
public int getAutoSendInterval() { |
return autoSendInterval; |
} |
public void setAutoSendInterval(int autoSendInterval) { |
this.autoSendInterval = autoSendInterval; |
} |
@Override |
public void accept(RequestFrameVisitor o) throws IOException { |
o.visit(this); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/OSDDataResponseFrame.java |
---|
0,0 → 1,278 |
package dongfang.mkt.frames; |
public class OSDDataResponseFrame extends ResponseFrame { |
public static class GPSPosition { |
int longitude; // in 1E-7 degrees. 32 bit signed. |
int latitude; // in 1E-7 degrees. 32 bit signed. |
long altitude; // in mm. 32 bit signed. |
int status; |
public int getLongitude() { |
return longitude; |
} |
public int getLatitude() { |
return latitude; |
} |
public long getAltitude() { |
return altitude; |
} |
public int getStatus() { |
return status; |
} |
public void setLongitude(int longitude) { |
this.longitude = longitude; |
} |
public void setLatitude(int latitude) { |
this.latitude = latitude; |
} |
public void setAltitude(long altitude) { |
this.altitude = altitude; |
} |
public void setStatus(int status) { |
this.status = status; |
} |
} |
public static class GPSDistanceAndBearing { |
int distance; // in m/10. 16 bit unsigned. |
int bearing; // in degrees. 16 bit signed. |
public int getDistance() { |
return distance; |
} |
public int getBearing() { |
return bearing; |
} |
public void setDistance(int distance) { |
this.distance = distance; |
} |
public void setBearing(int bearing) { |
this.bearing = bearing; |
} |
} |
private int version; |
private GPSPosition currentPosition; |
private GPSPosition targetPosition; |
private GPSDistanceAndBearing currentToTarget; |
private GPSPosition homePosition; |
private GPSDistanceAndBearing currentToHome; |
private int waypointIndex; |
private int waypointCount; |
private int numberOfSatellites; |
private int heightByPressure; // 16 bit signed. |
private int verticalVelocityByPressure; // 16 bit signed. |
private int flightTime; // in secs. 16 bit unsigned. |
private int batteryVoltage; // in 0.1 volts. |
private int groundSpeed; // in cm/s. 16 bit unsigned. |
private int heading; // of movement. 16 bit signed. |
private int compassHeading;// 16 bit signed. |
private int pitchAngle; |
private int rollAngle; |
private int rcQuality; |
private int fcFlags; |
private int ncFlags; |
private int errorCode; |
private int operatingRadius; |
private int verticalVelocityByGPS; // 16 bit signed. |
private int targetLoiterTime; |
private int fcFlags2; |
private int setpointForAltitude; // 16 bit signed. |
private int throttle; |
private int current; // 16 bit unsigned. |
private int capacityUsed; // 16 bit unsigned. |
public OSDDataResponseFrame(int address) { |
super(address); |
} |
public int getVersion() { |
return version; |
} |
public GPSPosition getCurrentPosition() { |
return currentPosition; |
} |
public GPSPosition getTargetPosition() { |
return targetPosition; |
} |
public GPSDistanceAndBearing getCurrentToTarget() { |
return currentToTarget; |
} |
public GPSPosition getHomePosition() { |
return homePosition; |
} |
public GPSDistanceAndBearing getCurrentToHome() { |
return currentToHome; |
} |
public int getWaypointIndex() { |
return waypointIndex; |
} |
public int getWaypointCount() { |
return waypointCount; |
} |
public int getNumberOfSatellites() { |
return numberOfSatellites; |
} |
public int getHeightByPressure() { |
return heightByPressure; |
} |
public int getVerticalVelocityByPressure() { |
return verticalVelocityByPressure; |
} |
public int getFlightTime() { |
return flightTime; |
} |
public int getBatteryVoltage() { |
return batteryVoltage; |
} |
public int getGroundSpeed() { |
return groundSpeed; |
} |
public int getHeading() { |
return heading; |
} |
public int getCompassHeading() { |
return compassHeading; |
} |
public int getPitchAngle() { |
return pitchAngle; |
} |
public int getRollAngle() { |
return rollAngle; |
} |
public int getRcQuality() { |
return rcQuality; |
} |
public int getFcFlags() { |
return fcFlags; |
} |
public int getNcFlags() { |
return ncFlags; |
} |
public int getErrorCode() { |
return errorCode; |
} |
public int getOperatingRadius() { |
return operatingRadius; |
} |
public int getVerticalVelocityByGPS() { |
return verticalVelocityByGPS; |
} |
public int getTargetLoiterTime() { |
return targetLoiterTime; |
} |
public int getFcFlags2() { |
return fcFlags2; |
} |
public int getSetpointForAltitude() { |
return setpointForAltitude; |
} |
public int getThrottle() { |
return throttle; |
} |
public int getCurrent() { |
return current; |
} |
public int getCapacityUsed() { |
return capacityUsed; |
} |
public void setVersion(int version) { |
this.version = version; |
} |
public void setCurrentPosition(GPSPosition currentPosition) { |
this.currentPosition = currentPosition; |
} |
public void setTargetPosition(GPSPosition targetPosition) { |
this.targetPosition = targetPosition; |
} |
public void setCurrentToTarget(GPSDistanceAndBearing currentToTarget) { |
this.currentToTarget = currentToTarget; |
} |
public void setHomePosition(GPSPosition homePosition) { |
this.homePosition = homePosition; |
} |
public void setCurrentToHome(GPSDistanceAndBearing currentToHome) { |
this.currentToHome = currentToHome; |
} |
public void setWaypointIndex(int waypointIndex) { |
this.waypointIndex = waypointIndex; |
} |
public void setWaypointCount(int waypointCount) { |
this.waypointCount = waypointCount; |
} |
public void setNumberOfSatellites(int numberOfSatellites) { |
this.numberOfSatellites = numberOfSatellites; |
} |
public void setHeightByPressure(int heightByPressure) { |
this.heightByPressure = heightByPressure; |
} |
public void setVerticalVelocityByPressure(int verticalVelocityByPressure) { |
this.verticalVelocityByPressure = verticalVelocityByPressure; |
} |
public void setFlightTime(int flightTime) { |
this.flightTime = flightTime; |
} |
public void setBatteryVoltage(int batteryVoltage) { |
this.batteryVoltage = batteryVoltage; |
} |
public void setGroundSpeed(int groundSpeed) { |
this.groundSpeed = groundSpeed; |
} |
public void setHeading(int heading) { |
this.heading = heading; |
} |
public void setCompassHeading(int compassHeading) { |
this.compassHeading = compassHeading; |
} |
public void setPitchAngle(int pitchAngle) { |
this.pitchAngle = pitchAngle; |
} |
public void setRollAngle(int rollAngle) { |
this.rollAngle = rollAngle; |
} |
public void setRcQuality(int rcQuality) { |
this.rcQuality = rcQuality; |
} |
public void setFcFlags(int fcFlags) { |
this.fcFlags = fcFlags; |
} |
public void setNcFlags(int ncFlags) { |
this.ncFlags = ncFlags; |
} |
public void setErrorCode(int errorCode) { |
this.errorCode = errorCode; |
} |
public void setOperatingRadius(int operatingRadius) { |
this.operatingRadius = operatingRadius; |
} |
public void setVerticalVelocityByGPS(int verticalVelocityByGPS) { |
this.verticalVelocityByGPS = verticalVelocityByGPS; |
} |
public void setTargetLoiterTime(int targetLoiterTime) { |
this.targetLoiterTime = targetLoiterTime; |
} |
public void setFcFlags2(int fcFlags2) { |
this.fcFlags2 = fcFlags2; |
} |
public void setSetpointForAltitude(int setpointForAltitude) { |
this.setpointForAltitude = setpointForAltitude; |
} |
public void setThrottle(int throttle) { |
this.throttle = throttle; |
} |
public void setCurrent(int current) { |
this.current = current; |
} |
public void setCapacityUsed(int capacityUsed) { |
this.capacityUsed = capacityUsed; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/ReadExternalControlRequestFrame.java |
---|
0,0 → 1,17 |
package dongfang.mkt.frames; |
import java.io.IOException; |
import dongfang.mkt.RequestFrameVisitor; |
public class ReadExternalControlRequestFrame extends RequestFrame { |
public ReadExternalControlRequestFrame(int address) { |
super(address); |
} |
@Override |
public void accept(RequestFrameVisitor o) throws IOException { |
o.visit(this); |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/frames/ReadExternalControlResponseFrame.java |
---|
0,0 → 1,104 |
package dongfang.mkt.frames; |
public class ReadExternalControlResponseFrame extends ResponseFrame { |
int[] digital = new int[2];// unsigned byte. |
int remoteButtons; // unsigned byte. |
int pitch; // signed byte. |
int roll; // signed byte. |
int yaw; // signed byte. |
int throttle; // unsigned byte. |
int height; // signed byte (!). |
int command; // unsigned byte. Called "free" in MK code. |
int frameNum; // unsigned byte. |
int argument; // unsigned byte. Called "config" in MK code. |
public ReadExternalControlResponseFrame(int address) { |
super(address); |
} |
public int[] getDigital() { |
return digital; |
} |
public void setDigital(int[] digital) { |
this.digital = digital; |
} |
public int getRemoteButtons() { |
return remoteButtons; |
} |
public void setRemoteButtons(int remoteButtons) { |
this.remoteButtons = remoteButtons; |
} |
public int getPitch() { |
return pitch; |
} |
public void setPitch(int pitch) { |
this.pitch = pitch; |
} |
public int getRoll() { |
return roll; |
} |
public void setRoll(int roll) { |
this.roll = roll; |
} |
public int getYaw() { |
return yaw; |
} |
public void setYaw(int yaw) { |
this.yaw = yaw; |
} |
public int getThrottle() { |
return throttle; |
} |
public void setThrottle(int throttle) { |
this.throttle = throttle; |
} |
public int getHeight() { |
return height; |
} |
public void setHeight(int height) { |
this.height = height; |
} |
public int getCommand() { |
return command; |
} |
public void setCommand(int command) { |
this.command = command; |
} |
public int getFrameNum() { |
return frameNum; |
} |
public void setFrameNum(int frameNum) { |
this.frameNum = frameNum; |
} |
public int getArgument() { |
return argument; |
} |
public void setArgument(int argument) { |
this.argument = argument; |
} |
@Override |
public boolean isResponseTo(RequestFrame r) { |
return r instanceof ReadExternalControlRequestFrame; |
} |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/main/UniversalConfigurator.java |
---|
31,7 → 31,7 |
private static void configure(UniversalWriteParamSetRequestFrame frame, |
int parameterSetNumber) throws IOException { |
MKCommPort port = new RXTXSerialPort(); |
port.init("COM10"); |
port.init(null); |
FrameQueue q = new FrameQueue(port); |
frame.setConfigurationSetNumber(parameterSetNumber); |
61,7 → 61,31 |
configure(frame, parameterSetNumber); |
} |
private static ConfigSet readConfiguration(int parameterSetNumber) |
private static ConfigSet readConfiguration(int parameterSetNumber) throws IOException { |
MKCommPort port = new RXTXSerialPort(); |
port.init(null); |
FrameQueue q = new FrameQueue(port); |
ConfigSet cs = null; |
UniversalReadParamSetRequestFrame frame = new UniversalReadParamSetRequestFrame(); |
frame.setConfigurationSetNumber(parameterSetNumber); |
q.sendRequest(frame); |
UniversalReadParamSetResponseFrame r = (UniversalReadParamSetResponseFrame) q.getResponseFor(frame, 3000); |
if (r == null) { |
System.err.println("ERROR. Timeout waiting for response."); |
} else { |
int paramSetVersion = r.getConfigurationVersion(); |
int[] data = r.getData(); |
cs = ConfigSet.parseXMLConfigSet(paramSetVersion); |
cs.setData(data); |
System.out.println(cs.toXML()); |
} |
q.kill(); |
return cs; |
} |
/* |
private static ConfigSet simpleReadConfiguration(int parameterSetNumber) |
throws IOException { |
MKCommPort port = new RXTXSerialPort(); |
port.init(null); |
78,14 → 102,13 |
} else { |
int paramSetVersion = r.getConfigurationVersion(); |
int[] data = r.getData(); |
cs = ConfigSet.parseXMLConfigSet(paramSetVersion); |
cs.setData(data); |
// System.out.println(cs.toXML()); |
for (int i=0; i<data.length; i++) |
System.out.println(data[i]); |
} |
q.kill(); |
return cs; |
} |
*/ |
private static void readConfiguration(String s_parameterSetNumber, |
String fileName) throws IOException { |
210,7 → 233,7 |
} |
public static void main(String[] args) throws IOException { |
if (args.length != 3 || (!"r".equals(args[0]) && !"w".equals(args[0]))) { |
if (("w".equals(args[0]) && args.length != 3) || ("r".equals(args[0]) && args.length != 2)) { |
System.err |
.println("Usage: UniversalConfigurator r [parameter set number to read from] [filename to write to]"); |
System.err |
219,7 → 242,7 |
} |
if ("r".equals(args[0])) { |
readConfiguration(args[1], args[2]); |
readConfiguration(Integer.parseInt(args[1])); |
} else { |
writeConfiguration(args[1], args[2]); |
} |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/serial/MKInputStream.java |
---|
11,6 → 11,10 |
import dongfang.mkt.frames.ConfirmFrame; |
import dongfang.mkt.frames.DebugResponseFrame; |
import dongfang.mkt.frames.MotorTestResponseFrame; |
import dongfang.mkt.frames.OSDDataResponseFrame; |
import dongfang.mkt.frames.OSDDataResponseFrame.GPSDistanceAndBearing; |
import dongfang.mkt.frames.OSDDataResponseFrame.GPSPosition; |
import dongfang.mkt.frames.ReadExternalControlResponseFrame; |
import dongfang.mkt.frames.ResponseFrame; |
import dongfang.mkt.frames.SetCompassHeadingResponseFrame; |
import dongfang.mkt.frames.UniversalReadParamSetResponseFrame; |
17,7 → 21,6 |
import dongfang.mkt.frames.UniversalWriteParamSetResponseFrame; |
import dongfang.mkt.frames.VariablesResponseFrame; |
import dongfang.mkt.frames.VersionResponseFrame; |
import dongfang.mkt.main.UniversalConfigurator; |
public class MKInputStream extends InputStream { |
int readByteCnt; |
53,10 → 56,15 |
return outbuf[outbufptr++]; |
} |
public int readSignedByte() throws IOException { |
byte result = (byte)readByte(); |
return result; |
} |
public int readWord() throws IOException { |
int byte2 = readByte(); |
int byte0 = readByte(); |
int byte1 = readByte(); |
return (byte1 << 8) | byte2; |
return (byte1 << 8) | byte0; |
} |
public int readSignedWord() throws IOException { |
65,6 → 73,14 |
word = word - 65536; |
return word; |
} |
public int readSignedDWord() throws IOException { |
int byte0 = readByte(); |
int byte1 = readByte(); |
int byte2 = readByte(); |
int byte3 = readByte(); |
return (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0; |
} |
public int[] readBytes(int length) throws IOException { |
int[] result = new int[length]; |
94,7 → 110,7 |
} |
} |
MKDataInputStream dis = new MKDataInputStream(); |
MKDataInputStream base64InputStream = new MKDataInputStream(); |
OutputStream nonPacketSpillway = null; //System.err; |
final InputStream is; |
121,7 → 137,7 |
} |
public MKDataInputStream getBase64InputStream() { |
return dis; |
return base64InputStream; |
} |
public ResponseFrame getNextFrame() throws IOException { |
132,7 → 148,7 |
nonPacketSpillway.write(c); |
} |
crc = '#'; |
dis.reset(); |
base64InputStream.reset(); |
int address = readByte() - 'a'; |
int iid = readByte(); |
readByteCnt = 0; |
141,23 → 157,23 |
switch (iid) { |
case 'A': { |
AnalogDebugLabelResponseFrame f = new AnalogDebugLabelResponseFrame(address); |
f.setChannel(getBase64InputStream().readByte()); |
f.setLabel(getBase64InputStream().readChars(16)); |
f.setChannel(base64InputStream.readByte()); |
f.setLabel(base64InputStream.readChars(16)); |
result = f; |
break; |
} |
case 'B': { |
ConfirmFrame f = new ConfirmFrame(address); |
f.setFrameNum(getBase64InputStream().readByte()); |
f.setFrameNum(base64InputStream.readByte()); |
result = f; |
break; |
} |
case 'C': { |
AttitudeDataResponseFrame f = new AttitudeDataResponseFrame(address); |
f.setPitch(getBase64InputStream().readSignedWord()); |
f.setRoll(getBase64InputStream().readSignedWord()); |
f.setHeading(getBase64InputStream().readSignedWord()); |
f.setExpansion(getBase64InputStream().readBytes(8)); |
f.setPitch(base64InputStream.readSignedWord()); |
f.setRoll(base64InputStream.readSignedWord()); |
f.setHeading(base64InputStream.readSignedWord()); |
f.setExpansion(base64InputStream.readBytes(8)); |
result = f; |
break; |
} |
164,37 → 180,119 |
case 'D': { |
DebugResponseFrame f = new DebugResponseFrame(address); |
for (int i=0; i<2; i++) |
f.setDigital(i, getBase64InputStream().readByte()); |
f.setDigital(i, base64InputStream.readByte()); |
for (int i=0; i<32; i++) |
f.setAnalog(i, getBase64InputStream().readSignedWord()); |
f.setAnalog(i, base64InputStream.readSignedWord()); |
result = f; |
break; |
} |
case 'F': { |
ChangeParameterSetResponseFrame f = new ChangeParameterSetResponseFrame(address); |
f.setParameterSetNumber(getBase64InputStream().readByte()); |
f.setParameterSetNumber(base64InputStream.readByte()); |
result = f; |
break; |
} |
case 'G': { |
ReadExternalControlResponseFrame f = new ReadExternalControlResponseFrame(address); |
f.setDigital(base64InputStream.readBytes(2)); |
f.setRemoteButtons(base64InputStream.readByte()); |
f.setPitch(base64InputStream.readByte()); |
f.setRoll(base64InputStream.readByte()); |
f.setYaw(base64InputStream.readByte()); |
f.setThrottle(base64InputStream.readByte()); |
f.setHeight(base64InputStream.readByte()); |
f.setCommand(base64InputStream.readByte()); |
f.setFrameNum(base64InputStream.readByte()); |
f.setArgument(base64InputStream.readByte()); |
result = f; |
break; |
} |
case 'H': { |
AllDisplaysResponseFrame f = new AllDisplaysResponseFrame(address); |
f.setLine(getBase64InputStream().readByte()); |
f.setLine(base64InputStream.readByte()); |
//f.setMaxItem(getDataInputStream().readByte()); |
f.setText(getBase64InputStream().readChars(20)); |
f.setText(base64InputStream.readChars(20)); |
result = f; |
break; |
} |
case 'L': { |
AllDisplaysResponseFrame f = new AllDisplaysResponseFrame(address); |
f.setItem(getBase64InputStream().readByte()); |
f.setItem(base64InputStream.readByte()); |
// f.setMaxItem(getDataInputStream().readByte()); |
f.setText(getBase64InputStream().readChars(80)); |
f.setText(base64InputStream.readChars(80)); |
result = f; |
break; |
} |
case 'O': { |
OSDDataResponseFrame f = new OSDDataResponseFrame(address); |
f.setVersion(base64InputStream.readByte()); |
GPSPosition pos = new GPSPosition(); |
pos.setLongitude(base64InputStream.readSignedDWord()); |
pos.setLatitude(base64InputStream.readSignedDWord()); |
pos.setAltitude(base64InputStream.readSignedDWord()); |
pos.setStatus(base64InputStream.readByte()); |
f.setCurrentPosition(pos); |
pos = new GPSPosition(); |
pos.setLongitude(base64InputStream.readSignedDWord()); |
pos.setLatitude(base64InputStream.readSignedDWord()); |
pos.setAltitude(base64InputStream.readSignedDWord()); |
pos.setStatus(base64InputStream.readByte()); |
f.setTargetPosition(pos); |
GPSDistanceAndBearing rnb = new GPSDistanceAndBearing(); |
rnb.setDistance(base64InputStream.readWord()); |
rnb.setBearing(base64InputStream.readSignedWord()); |
f.setCurrentToTarget(rnb); |
pos = new GPSPosition(); |
pos.setLongitude(base64InputStream.readSignedDWord()); |
pos.setLatitude(base64InputStream.readSignedDWord()); |
pos.setAltitude(base64InputStream.readSignedDWord()); |
pos.setStatus(base64InputStream.readByte()); |
f.setHomePosition(pos); |
rnb = new GPSDistanceAndBearing(); |
rnb.setDistance(base64InputStream.readWord()); |
rnb.setBearing(base64InputStream.readSignedWord()); |
f.setCurrentToHome(rnb); |
f.setWaypointIndex(base64InputStream.readByte()); |
f.setWaypointCount(base64InputStream.readByte()); |
f.setNumberOfSatellites(base64InputStream.readByte()); |
f.setHeightByPressure(base64InputStream.readSignedWord()); |
f.setVerticalVelocityByPressure(base64InputStream.readSignedWord()); |
f.setFlightTime(base64InputStream.readWord()); |
f.setBatteryVoltage(base64InputStream.readByte()); |
f.setGroundSpeed(base64InputStream.readWord()); |
f.setHeading(base64InputStream.readSignedWord()); |
f.setCompassHeading(base64InputStream.readSignedWord()); |
f.setPitchAngle(base64InputStream.readSignedByte()); |
f.setRollAngle(base64InputStream.readSignedByte()); |
f.setRcQuality(base64InputStream.readByte()); |
f.setFcFlags(base64InputStream.readByte()); |
f.setNcFlags(base64InputStream.readByte()); |
f.setErrorCode(base64InputStream.readByte()); |
f.setOperatingRadius(base64InputStream.readByte()); |
f.setVerticalVelocityByGPS(base64InputStream.readSignedWord()); |
f.setTargetLoiterTime(base64InputStream.readByte()); |
f.setFcFlags2(base64InputStream.readByte()); |
f.setSetpointForAltitude(base64InputStream.readSignedWord()); |
f.setThrottle(base64InputStream.readByte()); |
f.setCurrent(base64InputStream.readWord()); |
f.setCapacityUsed(base64InputStream.readWord()); |
result = f; |
break; |
} |
case 'S': { |
UniversalWriteParamSetResponseFrame f = new UniversalWriteParamSetResponseFrame(address); |
f.setParameterSetNumber(getBase64InputStream().readByte()); |
f.setParameterSetNumber(base64InputStream.readByte()); |
result = f; |
break; |
} |
216,12 → 314,12 |
*/ |
case 'V': { |
VersionResponseFrame f = new VersionResponseFrame(address); |
f.setSWMajor(getBase64InputStream().readByte()); |
f.setSWMinor(getBase64InputStream().readByte()); |
f.setProtoMajor(getBase64InputStream().readByte()); |
f.setProtoMinor(getBase64InputStream().readByte()); |
f.setSWPatch(getBase64InputStream().readByte()); |
f.setHardwareErrors(getBase64InputStream().readBytes(5)); |
f.setSWMajor(base64InputStream.readByte()); |
f.setSWMinor(base64InputStream.readByte()); |
f.setProtoMajor(base64InputStream.readByte()); |
f.setProtoMinor(base64InputStream.readByte()); |
f.setSWPatch(base64InputStream.readByte()); |
f.setHardwareErrors(base64InputStream.readBytes(5)); |
result = f; |
break; |
} |
229,7 → 327,7 |
// This is my own creation. The ID collides with the waypoint one of FC. |
case 'X': { |
VariablesResponseFrame f = new VariablesResponseFrame(address); |
f.setVariables(getBase64InputStream().readWords(8)); |
f.setVariables(base64InputStream.readWords(8)); |
result = f; |
break; |
} |
244,16 → 342,16 |
ToMk3Mag.CalState = compassCalState; |
*/ |
// Waste 8 bytes to make CRC match. |
getBase64InputStream().readBytes(8); |
base64InputStream.readBytes(8); |
result = f; |
break; |
} |
case 'Q': |
UniversalReadParamSetResponseFrame f = new UniversalReadParamSetResponseFrame(address); |
f.setConfigurationSetNumber(getBase64InputStream().readByte()); |
f.setConfigurationVersion(getBase64InputStream().readByte()); |
int length = getBase64InputStream().readByte(); |
f.setData(getBase64InputStream().readBytes(length)); |
f.setConfigurationSetNumber(base64InputStream.readByte()); |
f.setConfigurationVersion(base64InputStream.readByte()); |
int length = base64InputStream.readByte(); |
f.setData(base64InputStream.readBytes(length)); |
result = f; |
break; |
default: |
/dongfang_FC_rewrite_tool/src/dongfang/mkt/serial/MKOutputStream.java |
---|
12,6 → 12,8 |
import dongfang.mkt.frames.ExternalControlRequestFrame; |
import dongfang.mkt.frames.LoopbackTestRequestFrame; |
import dongfang.mkt.frames.MotorTestRequestFrame; |
import dongfang.mkt.frames.OSDDataRequestFrame; |
import dongfang.mkt.frames.ReadExternalControlRequestFrame; |
import dongfang.mkt.frames.RequestFrame; |
import dongfang.mkt.frames.ResetRequestFrame; |
import dongfang.mkt.frames.SetCompassHeadingRequestFrame; |
163,7 → 165,7 |
} |
public void visit(ExternalControlRequestFrame f) throws IOException { |
writeByte('y'); |
writeByte('b'); |
base64OutputStream.writeByte(f.getDigital()[0]); |
base64OutputStream.writeByte(f.getDigital()[1]); |
base64OutputStream.writeByte(f.getRemoteButtons()); |
176,6 → 178,10 |
base64OutputStream.writeByte(f.getFrameNum()); |
base64OutputStream.writeByte(f.getArgument()); |
} |
public void visit(ReadExternalControlRequestFrame f) throws IOException { |
writeByte('g'); |
} |
public void visit(LoopbackTestRequestFrame f) throws IOException { |
writeByte('0'); |
199,4 → 205,9 |
public void visit(SetCompassHeadingRequestFrame f) throws IOException { |
writeByte('K'); |
} |
public void visit(OSDDataRequestFrame f) throws IOException { |
writeByte('o'); |
base64OutputStream.writeByte(f.getAutoSendInterval()); |
} |
} |