use of com.eveningoutpost.dexdrip.cgm.medtrum.messages.AuthRx in project xDrip by NightscoutFoundation.
the class MedtrumCollectionService method parseInboundPacket.
// /
private void parseInboundPacket(byte[] packet) {
if (packet == null) {
UserError.Log.e(TAG, "Was passed null in parseInbound");
return;
}
if (packet.length < 2) {
UserError.Log.e(TAG, "Packet too short");
return;
}
final int opcode = packet[1] & 0xff;
switch(opcode) {
case OPCODE_AUTH_REPLY:
final AuthRx authrx = new AuthRx(packet);
if (authrx.isValid()) {
status("Authenticated");
} else {
errorStatus("AUTHENTICATION FAILED!");
if (JoH.ratelimit("medtrum-auth-fail", 600)) {
UserError.Log.wtf(TAG, "Auth packet failure: " + serial + authrx.toS());
}
}
changeState(state.next());
break;
case OPCODE_STAT_REPLY:
final StatusRx statusrx = new StatusRx(packet);
UserError.Log.d(TAG, statusrx.toS());
boolean asking_backfill = false;
if (statusrx.isValid()) {
lastAnnex = statusrx.getAnnex();
statusrx.getAnnex().processForTimeKeeper(serial);
createRecordFromAnnexData(statusrx.getAnnex());
asking_backfill = backFillIfNeeded(statusrx.getAnnex());
}
changeState(state.next(), asking_backfill ? 1500 : DEFAULT_AUTOMATA_DELAY);
break;
case OPCODE_TIME_REPLY:
final TimeRx timeRx = new TimeRx(packet);
final String msg = "Got time set reply: " + (timeRx.isValid() ? "VALID" : "INVALID");
if (timeRx.isValid()) {
status("Set time");
UserError.Log.d(TAG, msg);
} else {
status("Error setting time");
UserError.Log.e(TAG, msg);
}
changeState(SET_CONN_PARAM);
break;
case OPCODE_CONN_REPLY:
UserError.Log.d(TAG, "Got connection parameter reply");
final ConnParamRx connParamRx = new ConnParamRx(packet);
status("Parameter reply");
if (!connParamRx.isValid()) {
UserError.Log.e(TAG, "Got invalid connection parameter reply msg");
}
changeState(state.next());
break;
case OPCODE_CALI_REPLY:
UserError.Log.d(TAG, "Got calibration reply");
Medtrum.clearCalibration();
final CalibrateRx calibrateRx = new CalibrateRx(packet);
String thismsg;
if (calibrateRx.isOk()) {
thismsg = "Calibration OK";
} else {
thismsg = "Calibration Error " + calibrateRx.getErrorCode();
}
status(thismsg);
UserError.Log.ueh(TAG, thismsg);
JoH.static_toast_long(thismsg);
changeState(state.next());
break;
case OPCODE_BACK_REPLY:
UserError.Log.d(TAG, "Got backfill reply");
status("Got back fill");
processBackFillPacket(packet);
break;
default:
UserError.Log.d(TAG, "Unknown inbound opcode: " + opcode);
UserError.Log.e(TAG, "Received unknown inbound packet: " + HexDump.dumpHexString(packet));
}
}
use of com.eveningoutpost.dexdrip.cgm.medtrum.messages.AuthRx in project xDrip-plus by jamorham.
the class MedtrumCollectionService method parseInboundPacket.
// /
private void parseInboundPacket(byte[] packet) {
if (packet == null) {
UserError.Log.e(TAG, "Was passed null in parseInbound");
return;
}
if (packet.length < 2) {
UserError.Log.e(TAG, "Packet too short");
return;
}
final int opcode = packet[1] & 0xff;
switch(opcode) {
case OPCODE_AUTH_REPLY:
final AuthRx authrx = new AuthRx(packet);
if (authrx.isValid()) {
status("Authenticated");
} else {
errorStatus("AUTHENTICATION FAILED!");
if (JoH.ratelimit("medtrum-auth-fail", 600)) {
UserError.Log.wtf(TAG, "Auth packet failure: " + serial + authrx.toS());
}
}
changeState(state.next());
break;
case OPCODE_STAT_REPLY:
final StatusRx statusrx = new StatusRx(packet);
UserError.Log.d(TAG, statusrx.toS());
boolean asking_backfill = false;
if (statusrx.isValid()) {
lastAnnex = statusrx.getAnnex();
statusrx.getAnnex().processForTimeKeeper(serial);
createRecordFromAnnexData(statusrx.getAnnex());
asking_backfill = backFillIfNeeded(statusrx.getAnnex());
}
changeState(state.next(), asking_backfill ? 1500 : DEFAULT_AUTOMATA_DELAY);
break;
case OPCODE_TIME_REPLY:
final TimeRx timeRx = new TimeRx(packet);
final String msg = "Got time set reply: " + (timeRx.isValid() ? "VALID" : "INVALID");
if (timeRx.isValid()) {
status("Set time");
UserError.Log.d(TAG, msg);
} else {
status("Error setting time");
UserError.Log.e(TAG, msg);
}
changeState(SET_CONN_PARAM);
break;
case OPCODE_CONN_REPLY:
UserError.Log.d(TAG, "Got connection parameter reply");
final ConnParamRx connParamRx = new ConnParamRx(packet);
status("Parameter reply");
if (!connParamRx.isValid()) {
UserError.Log.e(TAG, "Got invalid connection parameter reply msg");
}
changeState(state.next());
break;
case OPCODE_CALI_REPLY:
UserError.Log.d(TAG, "Got calibration reply");
Medtrum.clearCalibration();
final CalibrateRx calibrateRx = new CalibrateRx(packet);
String thismsg;
if (calibrateRx.isOk()) {
thismsg = "Calibration OK";
} else {
thismsg = "Calibration Error " + calibrateRx.getErrorCode();
}
status(thismsg);
UserError.Log.ueh(TAG, thismsg);
JoH.static_toast_long(thismsg);
changeState(state.next());
break;
case OPCODE_BACK_REPLY:
UserError.Log.d(TAG, "Got backfill reply");
status("Got back fill");
processBackFillPacket(packet);
break;
default:
UserError.Log.d(TAG, "Unknown inbound opcode: " + opcode);
UserError.Log.e(TAG, "Received unknown inbound packet: " + HexDump.dumpHexString(packet));
}
}
Aggregations