/** @return <code>true</code> wenn Message zu Protokol paßt */
@SuppressWarnings("unchecked")
@Override
public boolean addMessage(final GarminMessage message) {
if (_linkProtocol.getType(message).equals(DataTypeName.ACKNOWLEDGE)) {
final CommandId cmd = message.getData().getCommandId();
if (cmd.getId() == _linkProtocol.getId(_typeSent)) {
if (_typeSent.equals(DataTypeName.RECORDS)) {
_packageIndex = 0;
final TypedData d = _packageData[_packageIndex++];
_typeSent = d.getType();
_linkProtocol.sendPackage(d.getType(), d.getData(), false);
}
else if (_typeSent.equals(DataTypeName.WPT_DATA)) {
if (_packageIndex < _packageData.length) {
final TypedData d = _packageData[_packageIndex++];
_typeSent = d.getType();
_linkProtocol.sendPackage(d.getType(), d.getData(), false);
}
else {
final GarminData gd = new GarminData(new byte[2]);
gd.setInt(0, _linkProtocol.getId(_typeToSend));
_typeSent = DataTypeName.XFER_CMPLT;
_linkProtocol.sendPackage(DataTypeName.XFER_CMPLT, gd, false);
}
}
else if (_typeSent.equals(DataTypeName.XFER_CMPLT))
_complete = true;
return true;
}
return false;
}
else if (_linkProtocol.getType(message).equals(DataTypeName.RECORDS)) {
_result = new ArrayList<Integer>(message.getData().getInt(0));
final CommandId cmd = new CommandId(_linkProtocol.getId(DataTypeName.RECORDS));
_linkProtocol.sendPackage(DataTypeName.ACKNOWLEDGE, cmd.getData(), false);
return true;
}
else if (_linkProtocol.getType(message).equals(DataTypeName.XFER_CMPLT)) {
CommandId cmd = message.getData().getCommandId();
final CommandName type = _deviceCommandProtocol.getType(cmd.getId());
if (!type.equals(_command))
System.err.println("incompatible type " + type + " != " + _command);
_complete = true;
_result =
_builder.buildResult(parseSequence(_linkProtocol, (List<GarminMessage>) _result));
cmd = new CommandId(message.getId());
_linkProtocol.sendPackage(DataTypeName.ACKNOWLEDGE, cmd.getData(), false);
return true;
}
((List<GarminMessage>) _result).add(message);
final CommandId cmd = new CommandId(message.getId());
_linkProtocol.sendPackage(DataTypeName.ACKNOWLEDGE, cmd.getData(), false);
return true;
}