public static void Put(BasicTypeSerializerContext context, UInt32 data)
 {
     Put(context, (byte)(data >> 24));
     Put(context, (byte)(data >> 16));
     Put(context, (byte)(data >> 8));
     Put(context, (byte)data);
 }
 public static void Put(BasicTypeSerializerContext context, byte[] bytes)
 {
     Put(context, (ushort)bytes.Length);
     foreach (var b in bytes)
     {
         Put(context, b);
     }
 }
 public static void Put(BasicTypeSerializerContext context, UInt64[] array)
 {
     Put(context, (ushort)array.Length);
     foreach (var e in array)
     {
         Put(context, e);
     }
 }
示例#4
0
        public static void Main() {
            tft.Initialize();

#if DRAWTOFILE
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
            var file = new FileStream(@"SD\VirtualCanvas.bin", FileMode.Create);
            var context = new BasicTypeSerializerContext(file);
#else
            var context = new BasicTypeSerializerContext();
#endif
            var virtualCanvas = new VirtualCanvas(context);
            var fontDejaVuSansBold9 = new DejaVuSansBold9();
            var fontDejaVuSans9 = new DejaVuSans9();
            var fontDejaVuSansMono8 = new DejaVuSansMono8();

            virtualCanvas.DrawFill(ColorBackground);

            virtualCanvas.DrawString(5, 10, BasicColor.Black, fontDejaVuSansBold9.GetFontInfo(), "DejaVu Sans 9 Bold");
            virtualCanvas.DrawString(5, 30, BasicColor.Black, fontDejaVuSans9.GetFontInfo(), "DejaVu Sans 9");
            virtualCanvas.DrawString(5, 50, BasicColor.Black, fontDejaVuSansMono8.GetFontInfo(), "DejaVu Sans Mono 8");

            // Check if the screen orientation can be changed
            if (tft.GetProperties().Orientation == true) {
                // Change the orientation
                virtualCanvas.SetOrientation(LCD.Orientation.Landscape);
                // Render some text in the new orientation
                virtualCanvas.DrawString(5, 10, BasicColor.Black, new DejaVuSans9().GetFontInfo(), "DejaVu Sans 9 (Rotated)");
                // Change the orientation back
                virtualCanvas.SetOrientation(LCD.Orientation.Portrait);
            }

            RenderPrimitiveShapes(virtualCanvas);
            RenderCompoundShapes(virtualCanvas, fontDejaVuSans9.GetFontInfo());
            RenderIcons(virtualCanvas);

            var localCanvas = new Canvas(tft);

#if DRAWTOFILE
            file.Flush();
            file.Close();
            localCanvas.Replay(new BasicTypeDeSerializerContext(new FileStream(@"SD\VirtualCanvas.bin", FileMode.Open)));
            StorageDevice.Unmount("SD");
#else
            //localCanvas.Replay(new BasicTypeDeSerializerContext(context.GetBuffer()));

            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
            var file = new FileStream(@"SD\VirtualCanvas.bin", FileMode.Create);
            
            int contentSize = 0;
            byte[] buffer = context.GetBuffer(ref contentSize);

            file.Write(buffer, 0, contentSize);
            file.Flush();
            file.Close();
            StorageDevice.Unmount("SD");
#endif
        }
 public static void Put(BasicTypeSerializerContext context, string text, bool ConvertToASCII = false)
 {
     Put(context, (byte)(ConvertToASCII ? 1 : 0));
     if (ConvertToASCII)
     {
         Put(context, Encoding.UTF8.GetBytes(text));
         Put(context, (byte)0);  // terminate the string with a null byte
     }
     else
     {
         Put(context, (ushort)text.Length);
         foreach (var c in text)
         {
             Put(context, c);
         }
         Put(context, (ushort)0); // terminate the unicode string with a null short
     }
 }
        public static unsafe void Put(BasicTypeSerializerContext context, float data)
        {
            var temp = new byte[4];

            Utility.InsertValueIntoArray(temp, 0, 4, *((uint *)&data));
            if (context.IsLittleEndian)
            {
                // Store the float in network byte order (Big Endian)
                Put(context, temp[3]);
                Put(context, temp[2]);
                Put(context, temp[1]);
                Put(context, temp[0]);
            }
            else
            {
                // Already in network byte order
                Put(context, temp[0]);
                Put(context, temp[1]);
                Put(context, temp[2]);
                Put(context, temp[3]);
            }
        }
 public static void Put(BasicTypeSerializerContext context, byte data) {
     context.Store(data);
 }
 public static void Put(BasicTypeSerializerContext context, UInt64[] array) {
     Put(context, (ushort)array.Length);
     foreach (var e in array) {
         Put(context, e);
     }
 }
 public static void Put(BasicTypeSerializerContext context, byte[] bytes) {
     Put(context, (ushort)bytes.Length);
     foreach (var b in bytes) {
         Put(context, b);
     }
 }
 public static void Put(BasicTypeSerializerContext context, string text, bool ConvertToASCII = false) {
     Put(context, (byte)(ConvertToASCII ? 1 : 0));
     if (ConvertToASCII) {
         Put(context, Encoding.UTF8.GetBytes(text));
         Put(context, (byte) 0); // terminate the string with a null byte
     } else {
         Put(context, (ushort)text.Length);
         foreach (var c in text) {
             Put(context, c);
         }
         Put(context, (ushort)0); // terminate the unicode string with a null short
     }
 }
 public static void Put(BasicTypeSerializerContext context, UInt16 data)
 {
     Put(context, (Int16)data);
 }
 public static void Put(BasicTypeSerializerContext context, UInt32 data) {
     Put(context, (byte)(data >> 24));
     Put(context, (byte)(data >> 16));
     Put(context, (byte)(data >> 8));
     Put(context, (byte)data);
 }
 public static void Put(BasicTypeSerializerContext context, Int64 data)
 {
     Put(context, (UInt64)data);
 }
 public static void Put(BasicTypeSerializerContext context, Int16 data)
 {
     Put(context, (byte)(data >> 8));
     Put(context, (byte)data);
 }
 public static void Put(BasicTypeSerializerContext context, UInt16 data) {
     Put(context, (Int16) data);
 }
 public static void Put(BasicTypeSerializerContext context, Int16 data) {
     Put(context, (byte)(data >> 8));
     Put(context, (byte)data);
 }
 public static void Put(BasicTypeSerializerContext context, byte data)
 {
     context.Store(data);
 }
 public static void Put(BasicTypeSerializerContext context, Int32 data) {
     Put(context, (UInt32)data);
 }
 public static unsafe void Put(BasicTypeSerializerContext context, float data) {
     var temp = new byte[4];
     Utility.InsertValueIntoArray(temp, 0, 4, *((uint*)&data));
     if (context.IsLittleEndian) {
         // Store the float in network byte order (Big Endian)
         Put(context, temp[3]);
         Put(context, temp[2]);
         Put(context, temp[1]);
         Put(context, temp[0]);
     } else {
         // Already in network byte order
         Put(context, temp[0]);
         Put(context, temp[1]);
         Put(context, temp[2]);
         Put(context, temp[3]);
     }
 }
示例#20
0
 public VirtualCanvas(BasicTypeSerializerContext context) {
     Context = context;
 }
示例#21
0
        public static void Main() {
            var contextSerializer = new BasicTypeSerializerContext();
            BasicTypeSerializer.Put(contextSerializer,(byte)byte.MaxValue);
            BasicTypeSerializer.Put(contextSerializer,(UInt16)UInt16.MaxValue);
            BasicTypeSerializer.Put(contextSerializer,(Int16)Int16.MinValue);
            BasicTypeSerializer.Put(contextSerializer,(UInt32)UInt32.MaxValue);
            BasicTypeSerializer.Put(contextSerializer,(Int32)Int32.MinValue);
            BasicTypeSerializer.Put(contextSerializer,(UInt64)UInt64.MaxValue);
            BasicTypeSerializer.Put(contextSerializer,(Int64)Int64.MinValue);
            BasicTypeSerializer.Put(contextSerializer,(float)float.MaxValue);
            BasicTypeSerializer.Put(contextSerializer,(float)float.MinValue);
            BasicTypeSerializer.Put(contextSerializer,"Unicode String");
            BasicTypeSerializer.Put(contextSerializer,"ASCII String",true);
            BasicTypeSerializer.Put(contextSerializer,new byte[] { byte.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, byte.MaxValue });
            BasicTypeSerializer.Put(contextSerializer,new ushort[] { ushort.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, UInt16.MaxValue });
            BasicTypeSerializer.Put(contextSerializer,new UInt32[] { UInt32.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, UInt32.MaxValue });
            BasicTypeSerializer.Put(contextSerializer,new UInt64[] { UInt64.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, UInt64.MaxValue });

            byte byteValue = 0;
            UInt16 UInt16Value = 0;
            Int16 Int16Value = 0;
            UInt32 UInt32Value = 0;
            Int32 Int32Value = 0;
            UInt64 UInt64Value = 0;
            Int64 Int64Value = 0;
            float floatValue = 0.0F;
            string UnicodeString = null;
            string AsciiString = null;
            byte[] byteArray = null;
            ushort[] ushortArray = null;
            UInt32[] UInt32Array = null;
            UInt64[] UInt64Array = null;

            Debug.Print("sizeof(byte)=" + sizeof(byte));
            Debug.Print("sizeof(UInt16)=" + sizeof(UInt16));
            Debug.Print("sizeof(Int16)=" + sizeof(Int16));
            Debug.Print("sizeof(UInt32)=" + sizeof(UInt32));
            Debug.Print("sizeof(Int32)=" + sizeof(Int32));
            Debug.Print("sizeof(UInt64)=" + sizeof(UInt64));
            Debug.Print("sizeof(Int64)=" + sizeof(Int64));
            Debug.Print("sizeof(float)=" + sizeof(float)); 
            Debug.Print("sizeof(double)=" + sizeof(double));

            var contextDeserializer = new BasicTypeDeSerializerContext(contextSerializer.GetBuffer());

            byteValue = BasicTypeDeSerializer.Get(contextDeserializer);
            if (byteValue != byte.MaxValue) throw new ApplicationException("byteValue");

            UInt16Value = BasicTypeDeSerializer.Get(contextDeserializer, UInt16Value);
            if (UInt16Value != UInt16.MaxValue) throw new ApplicationException("UInt16Value");

            Int16Value = BasicTypeDeSerializer.Get(contextDeserializer, Int16Value);
            if (Int16Value != Int16.MinValue) throw new ApplicationException("Int16Value");

            UInt32Value = BasicTypeDeSerializer.Get(contextDeserializer, UInt32Value);
            if (UInt32Value != UInt32.MaxValue) throw new ApplicationException("UInt32Value");

            Int32Value = BasicTypeDeSerializer.Get(contextDeserializer, Int32Value);
            if (Int32Value != Int32.MinValue) throw new ApplicationException("Int32Value");

            UInt64Value = BasicTypeDeSerializer.Get(contextDeserializer, UInt64Value);
            if (UInt64Value != UInt64.MaxValue) throw new ApplicationException("UInt64Value");

            Int64Value = BasicTypeDeSerializer.Get(contextDeserializer, Int64Value);
            if (Int64Value != Int64.MinValue) throw new ApplicationException("Int64Value");

            floatValue = BasicTypeDeSerializer.Get(contextDeserializer, floatValue);
            if (floatValue != float.MaxValue) throw new ApplicationException("floatValue");
            floatValue = BasicTypeDeSerializer.Get(contextDeserializer, floatValue);
            if (floatValue != float.MinValue) throw new ApplicationException("floatValue");

            UnicodeString = BasicTypeDeSerializer.Get(contextDeserializer, "");
            if (UnicodeString != "Unicode String") throw new ApplicationException("UnicodeString");

            AsciiString = BasicTypeDeSerializer.Get(contextDeserializer, "");
            if (AsciiString != "ASCII String") throw new ApplicationException("AsciiString");

            byteArray = BasicTypeDeSerializer.Get(contextDeserializer, byteArray);
            if (byteArray[0] != byte.MinValue || byteArray[15] != byte.MaxValue) throw new ApplicationException("byteArray");

            ushortArray = BasicTypeDeSerializer.Get(contextDeserializer, ushortArray);
            if (ushortArray[0] != ushort.MinValue || ushortArray[15] != ushort.MaxValue) throw new ApplicationException("ushortArray");

            UInt32Array = BasicTypeDeSerializer.Get(contextDeserializer, UInt32Array);
            if (UInt32Array[0] != UInt32.MinValue || UInt32Array[15] != UInt32.MaxValue) throw new ApplicationException("UInt32Array");

            UInt64Array = BasicTypeDeSerializer.Get(contextDeserializer, UInt64Array);
            if (UInt64Array[0] != UInt64.MinValue || UInt64Array[15] != UInt64.MaxValue) throw new ApplicationException("UInt64Array");
        }