/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 Alexandre Normand
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.glukit.dexcom.sync;

import java.util.Map;

import static com.google.common.collect.Maps.newHashMap;

/**
 * All possible receiver commands.
 *
 * @author alexandre.normand
 */
public enum ReceiverCommand {
  Ack((byte) 1),
  EnterFirmwareUpgradeMode((byte) 50),
  EnterSambaAccessMode((byte) 0x35),
  EraseDatabase((byte) 0x2d),
  IncompletePacketReceived((byte) 5),
  InvalidCommand((byte) 3),
  InvalidMode((byte) 7),
  InvalidParam((byte) 4),
  MaxCommand((byte) 0x3b),
  MaxPossibleCommand((byte) 0xff),
  Nak((byte) 2),
  Null((byte) 0),
  Ping((byte) 10),
  ReadBatteryLevel((byte) 0x21),
  ReadBatteryState((byte) 0x30),
  ReadBlindedMode((byte) 0x27),
  ReadClockMode((byte) 0x29),
  ReadDatabasePageHeader((byte) 0x12),
  ReadDatabasePageRange((byte) 0x10),
  ReadDatabasePages((byte) 0x11),
  ReadDatabaseParitionInfo((byte) 15),
  ReadDeviceMode((byte) 0x2b),
  ReadDisplayTimeOffset((byte) 0x1d),
  ReadEnableSetUpWizardFlag((byte) 0x37),
  ReadFirmwareHeader((byte) 11),
  ReadFirmwareSettings((byte) 0x36),
  ReadFlashPage((byte) 0x33),
  ReadGlucoseUnit((byte) 0x25),
  ReadHardwareBoardId((byte) 0x31),
  ReadLanguage((byte) 0x1b),
  ReadRTC((byte) 0x1f),
  ReadSetUpWizardState((byte) 0x39),
  ReadSystemTime((byte) 0x22),
  ReadSystemTimeOffset((byte) 0x23),
  ReadTransmitterID((byte) 0x19),
  ReceiverError((byte) 6),
  ResetReceiver((byte) 0x20),
  ShutdownReceiver((byte) 0x2e),
  WriteBlindedMode((byte) 40),
  WriteClockMode((byte) 0x2a),
  WriteDisplayTimeOffset((byte) 30),
  WriteEnableSetUpWizardFlag((byte) 0x38),
  WriteFlashPage((byte) 0x34),
  WriteGlucoseUnit((byte) 0x26),
  WriteLanguage((byte) 0x1c),
  WritePCParameters((byte) 0x2f),
  WriteSetUpWizardState((byte) 0x3a),
  WriteSystemTime((byte) 0x24),
  WriteTransmitterID((byte) 0x1a);

  private byte id;
  private static Map<Byte, ReceiverCommand> mappings;

  private ReceiverCommand(byte id) {
    this.id = id;
    addMapping(id, this);
  }

  private static void addMapping(byte id, ReceiverCommand receiverCommand) {
    if (mappings == null) {
      mappings = newHashMap();
    }
    mappings.put(id, receiverCommand);
  }

  public static ReceiverCommand fromId(byte id) {
    return mappings.get(id);
  }

  public byte getId() {
    return id;
  }
}

@@ -1373,16 +1373,19 @@
 ((byte) 
+0x0
 1),%0A  En
@@ -1418,10 +1418,12 @@
 te) 
-5
 0
+x32
 ),%0A 
@@ -1522,16 +1522,19 @@
 ((byte) 
+0x0
 5),%0A  In
@@ -1553,16 +1553,19 @@
 ((byte) 
+0x0
 3),%0A  In
@@ -1581,16 +1581,19 @@
 ((byte) 
+0x0
 7),%0A  In
@@ -1610,16 +1610,19 @@
 ((byte) 
+0x0
 4),%0A  Ma
@@ -1692,16 +1692,19 @@
 ((byte) 
+0x0
 2),%0A  Nu
@@ -1713,16 +1713,19 @@
 ((byte) 
+0x0
 0),%0A  Pi
@@ -1734,18 +1734,20 @@
 ((byte) 
-1
 0
+x0A
 ),%0A  Rea
@@ -2018,10 +2018,12 @@
 te) 
-15
+0x0F
 ),%0A 
@@ -2160,18 +2160,20 @@
 ((byte) 
-11
+0x0B
 ),%0A  Rea
@@ -2517,16 +2517,19 @@
 ((byte) 
+0x0
 6),%0A  Re
@@ -2617,10 +2617,12 @@
 te) 
-4
 0
+x28
 ),%0A 
@@ -2683,18 +2683,20 @@
 ((byte) 
-3
 0
+x1E
 ),%0A  Wri

Make all ReceiverCommands be Hex values.