Beispiel #1
0
 public static int Create(byte[] protoPacket, int packetSize, ref kowhai_protocol_t protocol, out int bytesRequired)
 {
     GCHandle h = GCHandle.Alloc(protoPacket, GCHandleType.Pinned);
     int result = kowhai_protocol_create(h.AddrOfPinnedObject(), packetSize, ref protocol, out bytesRequired);
     h.Free();
     return result;
 }
Beispiel #2
0
 public static int Create(byte[] protoPacket, int packetSize, ref kowhai_protocol_t protocol, Kowhai.kowhai_symbol_t[] symbols, out int bytesRequired)
 {
     protocol.payload.spec.data.symbols.count = (uint8_t)symbols.Length;
     GCHandle h = GCHandle.Alloc(symbols, GCHandleType.Pinned);
     protocol.payload.spec.data.symbols.array_ = h.AddrOfPinnedObject();
     int result = Create(protoPacket, packetSize, ref protocol, out bytesRequired);
     h.Free();
     return result;
 }
Beispiel #3
0
 public static uint8_t[] GetBuffer(kowhai_protocol_t prot)
 {
     byte[] buffer;
     if (IsDescriptorCommand(prot.header.command))
         buffer = new byte[prot.payload.spec.descriptor.size];
     else
         buffer = new byte[prot.payload.spec.data.memory.size];
     Marshal.Copy(prot.payload.buffer, buffer, 0, buffer.Length);
     return buffer;
 }
Beispiel #4
0
 public static int Create(byte[] protoPacket, int packetSize, ref kowhai_protocol_t protocol, Kowhai.kowhai_symbol_t[] symbols, byte[] buffer, uint16_t offset, out int bytesRequired)
 {
     protocol.payload.spec.data.memory.size = (uint16_t)buffer.Length;
     protocol.payload.spec.data.memory.offset = offset;
     GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
     protocol.payload.buffer = h.AddrOfPinnedObject();
     int result = Create(protoPacket, packetSize, ref protocol, symbols, out bytesRequired);
     h.Free();
     return result;
 }
Beispiel #5
0
 public static int CreateCallFunctionPacket(byte[] protoPacket, int packetSize, ref kowhai_protocol_t protocol, byte[] buffer, uint16_t offset, out int bytesRequired)
 {
     protocol.payload.spec.function_call.offset = offset;
     if (buffer != null)
     {
         protocol.payload.spec.function_call.size = (uint16_t)buffer.Length;
         GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
         protocol.payload.buffer = h.AddrOfPinnedObject();
         int result = CreateBasicPacket(protoPacket, packetSize, ref protocol, out bytesRequired);
         h.Free();
         return result;
     }
     else
         protocol.payload.spec.function_call.size = 0;
     return CreateBasicPacket(protoPacket, packetSize, ref protocol, out bytesRequired);
 }
Beispiel #6
0
 public static int Parse(byte[] protoPacket, int packetSize, out kowhai_protocol_t protocol)
 {
     GCHandle h = GCHandle.Alloc(protoPacket, GCHandleType.Pinned);
     int result = kowhai_protocol_parse(h.AddrOfPinnedObject(), packetSize, out protocol);
     h.Free();
     return result;
 }
Beispiel #7
0
 public static extern int kowhai_protocol_parse(IntPtr proto_packet, int packet_size, out kowhai_protocol_t protocol);
Beispiel #8
0
 public static extern int kowhai_protocol_get_overhead(ref kowhai_protocol_t protocol, out int overhead);
Beispiel #9
0
 public static extern int kowhai_protocol_create(IntPtr proto_packet, int packet_size, ref kowhai_protocol_t protocol, out int bytes_required);
Beispiel #10
0
 public static int Parse(byte[] protoPacket, int packetSize, out kowhai_protocol_t protocol, out Kowhai.kowhai_symbol_t[] symbols)
 {
     GCHandle h = GCHandle.Alloc(protoPacket, GCHandleType.Pinned);
     int result = kowhai_protocol_parse(h.AddrOfPinnedObject(), packetSize, out protocol);
     h.Free();
     if (result == Kowhai.STATUS_OK && !IsDescriptorCommand(protocol.header.command))
     {
         symbols = new Kowhai.kowhai_symbol_t[protocol.payload.spec.data.symbols.count];
         h = GCHandle.Alloc(symbols, GCHandleType.Pinned);
         CopyIntPtrs(h.AddrOfPinnedObject(), protocol.payload.spec.data.symbols.array_, Marshal.SizeOf(typeof(Kowhai.kowhai_symbol_t)) * symbols.Length);
         h.Free();
     }
     else
         symbols = null;
     return result;
 }
Beispiel #11
0
 public static uint8_t[] GetBuffer(kowhai_protocol_t prot)
 {
     byte[] buffer;
     if (IsDescriptorCommand(prot.header.command))
         buffer = new byte[prot.payload.spec.descriptor.size];
     else if (IsSymbolCommand(prot.header.command))
         buffer = new byte[prot.payload.spec.data.memory.size];
     else if (IsFunctionResultCommand(prot.header.command))
         buffer = new byte[prot.payload.spec.function_call.size];
     else if (IsEventCommand(prot.header.command))
         buffer = new byte[prot.payload.spec.event_.size];
     else if (IsStringListResultCommand(prot.header.command))
         buffer = new byte[prot.payload.spec.string_list.size];
     else
         return null;
     Marshal.Copy(prot.payload.buffer, buffer, 0, buffer.Length);
     return buffer;
 }