Advertisement
FrayxRulez

Untitled

Dec 4th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. package com.getpebble.android.framework.protocol.outbound;
  2.  
  3. import com.getpebble.android.framework.protocol.EndpointId;
  4. import com.getpebble.android.framework.util.ByteUtils;
  5.  
  6. public class PblOutboundRegistryMessage extends PblOutboundMessage
  7. {
  8.   private final byte[] mByteValue;
  9.   private final RegistryCommand mCommand;
  10.   private final RegistryKey mKey;
  11.   private final RegistryType mType;
  12.  
  13.   public PblOutboundRegistryMessage(RegistryKey paramRegistryKey, int paramInt, RegistryType paramRegistryType, RegistryCommand paramRegistryCommand)
  14.   {
  15.     super(paramRegistryType.getEndpointId());
  16.     this.mKey = paramRegistryKey;
  17.     this.mByteValue = ByteUtils.int2bytes(paramInt);
  18.     this.mType = paramRegistryType;
  19.     this.mCommand = paramRegistryCommand;
  20.   }
  21.  
  22.   public byte[] getBytes()
  23.   {
  24.     try
  25.     {
  26.       if (!areBytesCached())
  27.       {
  28.         Byte[] arrayOfByte1 = new Byte[1];
  29.         arrayOfByte1[0] = Byte.valueOf((byte)this.mCommand.getId());
  30.         addBytes(arrayOfByte1);
  31.         Byte[] arrayOfByte2 = new Byte[1];
  32.         arrayOfByte2[0] = Byte.valueOf((byte)(0xFF & this.mKey.getString().length()));
  33.         addBytes(arrayOfByte2);
  34.         if (this.mCommand == RegistryCommand.WRITE)
  35.         {
  36.           Byte[] arrayOfByte3 = new Byte[1];
  37.           arrayOfByte3[0] = Byte.valueOf((byte)(0xFF & this.mByteValue.length));
  38.           addBytes(arrayOfByte3);
  39.         }
  40.         ByteUtils.writeFixedLengthString(this, this.mKey.getString(), this.mKey.getString().length());
  41.         if (this.mCommand == RegistryCommand.WRITE)
  42.           addBytes(this.mByteValue);
  43.       }
  44.       byte[] arrayOfByte = super.getBytes();
  45.       return arrayOfByte;
  46.     }
  47.     finally
  48.     {
  49.     }
  50.   }
  51.  
  52.   public static enum RegistryCommand
  53.   {
  54.     private final int id;
  55.  
  56.     static
  57.     {
  58.       REMOVE = new RegistryCommand("REMOVE", 2, 4);
  59.       RegistryCommand[] arrayOfRegistryCommand = new RegistryCommand[3];
  60.       arrayOfRegistryCommand[0] = READ;
  61.       arrayOfRegistryCommand[1] = WRITE;
  62.       arrayOfRegistryCommand[2] = REMOVE;
  63.     }
  64.  
  65.     private RegistryCommand(int paramInt)
  66.     {
  67.       this.id = paramInt;
  68.     }
  69.  
  70.     public int getId()
  71.     {
  72.       return this.id;
  73.     }
  74.   }
  75.  
  76.   public static enum RegistryKey
  77.   {
  78.     private final String mKeyCode;
  79.  
  80.     static
  81.     {
  82.       MISC = new RegistryKey("MISC", 3, "mfg_misc");
  83.       FUNC_TEST = new RegistryKey("FUNC_TEST", 4, "mfg_functest");
  84.       COLOR = new RegistryKey("COLOR", 5, "mfg_color");
  85.       FAC_MODE = new RegistryKey("FAC_MODE", 6, "mfg_facmode");
  86.       RegistryKey[] arrayOfRegistryKey = new RegistryKey[7];
  87.       arrayOfRegistryKey[0] = PCB_TEST_DATE;
  88.       arrayOfRegistryKey[1] = RTC_FREQ;
  89.       arrayOfRegistryKey[2] = TEST_RESULT;
  90.       arrayOfRegistryKey[3] = MISC;
  91.       arrayOfRegistryKey[4] = FUNC_TEST;
  92.       arrayOfRegistryKey[5] = COLOR;
  93.       arrayOfRegistryKey[6] = FAC_MODE;
  94.     }
  95.  
  96.     private RegistryKey(String paramString)
  97.     {
  98.       this.mKeyCode = paramString;
  99.     }
  100.  
  101.     public String getString()
  102.     {
  103.       return this.mKeyCode;
  104.     }
  105.   }
  106.  
  107.   public static enum RegistryType
  108.   {
  109.     private final EndpointId mEndpointId;
  110.  
  111.     static
  112.     {
  113.       FACTORY = new RegistryType("FACTORY", 1, EndpointId.FCT_REG);
  114.       RegistryType[] arrayOfRegistryType = new RegistryType[2];
  115.       arrayOfRegistryType[0] = SYSTEM;
  116.       arrayOfRegistryType[1] = FACTORY;
  117.     }
  118.  
  119.     private RegistryType(EndpointId paramEndpointId)
  120.     {
  121.       this.mEndpointId = paramEndpointId;
  122.     }
  123.  
  124.     public EndpointId getEndpointId()
  125.     {
  126.       return this.mEndpointId;
  127.     }
  128.   }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement