public static void Main()
var blat = BitConverter.GetBytes(lat);
var blon = BitConverter.GetBytes(lon);
var balt = BitConverter.GetBytes(alt);
var bdir = BitConverter.GetBytes(direction);
var bhdop = BitConverter.GetBytes(hdop);
var block = BitConverter.GetBytes(true);
var bdock = BitConverter.GetBytes(true);
int unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var bunixTs = BitConverter.GetBytes(unixTimestamp);
var bSessionId = BitConverter.GetBytes(sessionId);
var bcharge = BitConverter.GetBytes(true);
var bks = BitConverter.GetBytes(keystate);
var bchargekeystate = new HalvedByte(keystate,charger_state);
var b42v = Convert.ToByte(true);
var bswitch = Convert.ToByte(true);
var v42_battery = new HalvedByte(bswitch, b42v);
string dock_uid = "12ABC34";
var bdockuid = System.Text.Encoding.ASCII.GetBytes(dock_uid);
byte[] request = new byte[37] {
blat[0],blat[1],blat[2],blat[3],
blon[0],blon[1],blon[2],blon[3],
balt[0],balt[1],balt[2],balt[3],
bunixTs[0], bunixTs[1], bunixTs[2], bunixTs[3],
bSessionId[0], bSessionId[1], bSessionId[2], bSessionId[3],
bdockuid[0],bdockuid[1],bdockuid[2],bdockuid[3],bdockuid[4],bdockuid[5],bdockuid[6]};
var bstring = Convert.ToBase64String(request);
Console.WriteLine(bstring);
public byte Full { get; set; }
get { return (byte)(Full & 15); }
throw new ArithmeticException("Value must be between 0 and 16.");
Full = (byte)((High << 4) | (value & 15));
get { return (byte)(Full >> 4); }
throw new ArithmeticException("Value must be between 0 and 16.");
Full = (byte)((value << 4) | Low);
public HalvedByte(byte full) : this()
public HalvedByte(byte low, byte high) : this()
if (low >= 16 || high >= 16)
throw new ArithmeticException("Values must be between 0 and 16.");
Full = (byte)((high << 4) | low);