static void Main(string[] args) { Stream outp; Stream inp; int msg_no = 0; if (args.Length == 2) { inp = new FileStream(args[0], FileMode.Open, FileAccess.Read); outp = new FileStream(args[1], FileMode.OpenOrCreate, FileAccess.Write); } else if (args.Length == 1) { inp = new FileStream(args[0], FileMode.Open, FileAccess.Read); outp = Console.OpenStandardOutput(); } else { inp = Console.OpenStandardInput(); outp = Console.OpenStandardOutput(); } while (true) { /* read message header */ byte[] hdr = new byte[LLRPBinaryDecoder.MIN_HDR]; int how_many = inp.Read(hdr, 0, LLRPBinaryDecoder.MIN_HDR); if (how_many == 0) { break; } else if (how_many < LLRPBinaryDecoder.MIN_HDR) { throw new MalformedPacket("Header fragment at end-of-file"); } /* get the full message */ LLRPBinaryDecoder.LLRP_Envelope env; LLRPBinaryDecoder.Decode_Envelope(hdr, out env); byte[] packet; read_msg(inp, hdr, ref env, out packet); Message msg; try { LLRPBinaryDecoder.Decode(ref packet, out msg); } catch (Exception e) { String desc = "Decode failure on Packet #" + msg_no + ", " + e.Message; Console.Error.WriteLine(desc); String err_msg = "<ERROR_MESSAGE MessageID=\"0\" Version=\"0\">\r\n" + " <LLRPStatus>\r\n" + " <StatusCode>R_DeviceError</StatusCode>\r\n" + " <ErrorDescription>" + desc + "</ErrorDescription>\r\n" + " </LLRPStatus>\r\n" + "</ERROR_MESSAGE>\r\n"; ENUM_LLRP_MSG_TYPE dummy; LLRPXmlParser.ParseXMLToLLRPMessage(err_msg, out msg, out dummy); } try { packet = Util.ConvertBitArrayToByteArray(msg.ToBitArray()); outp.Write(packet, 0, packet.Length); } catch (Exception e) { String desc = "Encode failure on packet #" + msg_no + ", " + e.Message; Console.Error.WriteLine(desc); } } msg_no++; }
static void Main(string[] args) { Stream s; if (args.GetLength(0) == 1) { s = new FileStream(args[0], FileMode.Open, FileAccess.Read); } else { s = Console.OpenStandardInput(); } UInt32 msg_no = 0; while (true) { /* read message header */ byte[] hdr = new byte[LLRPBinaryDecoder.MIN_HDR]; int how_many = s.Read(hdr, 0, LLRPBinaryDecoder.MIN_HDR); if (how_many == 0) { break; } else if (how_many < LLRPBinaryDecoder.MIN_HDR) { throw new MalformedPacket("Header fragment at end-of-file"); } /* get the full message */ LLRPBinaryDecoder.LLRP_Envelope env; LLRPBinaryDecoder.Decode_Envelope(hdr, out env); byte[] packet; read_msg(s, hdr, ref env, out packet); Message msg; try { LLRPBinaryDecoder.Decode(ref packet, out msg); try { Console.Write(msg.ToString() + "\r\n"); } catch (Exception e) { Console.WriteLine(e.Message + "\r\nAt: " + e.StackTrace); Console.Write( "<ERROR_MESSAGE MessageID=\"0\" Version=\"0\">\r\n" + " <LLRPStatus>\r\n" + " <StatusCode>M_Success</StatusCode>\r\n" + " <ErrorDescription>ToString failure on Packet #" + msg_no + "</ErrorDescription>\r\n" + " </LLRPStatus>\r\n" + "</ERROR_MESSAGE>\r\n" ); } } catch (Exception e) { Console.WriteLine(e.Message + "\r\nAt: " + e.StackTrace); Console.Write( "<ERROR_MESSAGE MessageID=\"0\" Version=\"0\">\r\n" + " <LLRPStatus>\r\n" + " <StatusCode>M_Success</StatusCode>\r\n" + " <ErrorDescription>Decode failure on Packet #" + msg_no + "</ErrorDescription>\r\n" + " </LLRPStatus>\r\n" + "</ERROR_MESSAGE>\r\n" ); } msg_no++; } }
static void Main(string[] args) { Stream s; UInt32 byteCount = 0; TextWriter errorWriter = Console.Error; if (args.GetLength(0) >= 1) { s = new FileStream(args[0], FileMode.Open, FileAccess.Read); } else { s = Console.OpenStandardInput(); } Console.WriteLine("<packetSequence>\r\n"); UInt32 msg_no = 0; while (true) { /* read message header */ byte[] hdr = new byte[LLRPBinaryDecoder.MIN_HDR]; int how_many = s.Read(hdr, 0, LLRPBinaryDecoder.MIN_HDR); if (how_many == 0) { break; } else if (how_many < LLRPBinaryDecoder.MIN_HDR) { throw new MalformedPacket("Header fragment at end-of-file"); } /* get the full message */ LLRPBinaryDecoder.LLRP_Envelope env; LLRPBinaryDecoder.Decode_Envelope(hdr, out env); // turn me on to find out where each packet starts //errorWriter.Write("packet {0} offset {1}({1:x}) ", msg_no, byteCount); //errorWriter.Write(env.msg_type.ToString() + "\n"); byte[] packet; read_msg(s, hdr, ref env, out packet); byteCount += env.msg_len; Message msg; try { LLRPBinaryDecoder.Decode(ref packet, out msg); try { Console.Write(msg.ToString() + "\r\n"); } catch (Exception e) { Console.WriteLine(e.Message + "\r\nAt: " + e.StackTrace); Console.Write( "<ERROR_MESSAGE MessageID=\"0\" Version=\"0\">\r\n" + " <LLRPStatus>\r\n" + " <StatusCode>R_DeviceError</StatusCode>\r\n" + " <ErrorDescription>ToString failure on Packet #" + msg_no + "</ErrorDescription>\r\n" + " </LLRPStatus>\r\n" + "</ERROR_MESSAGE>\r\n" ); } } catch (Exception e) { Console.WriteLine(e.Message + "\r\nAt: " + e.StackTrace); Console.Write( "<ERROR_MESSAGE MessageID=\"0\" Version=\"0\">\r\n" + " <LLRPStatus>\r\n" + " <StatusCode>R_DeviceError</StatusCode>\r\n" + " <ErrorDescription>Decode failure on Packet #" + msg_no + "</ErrorDescription>\r\n" + " </LLRPStatus>\r\n" + "</ERROR_MESSAGE>\r\n" ); } msg_no++; } Console.WriteLine("</packetSequence>\r\n"); }