Exemplo n.º 1
0
        /// <summary>
        /// Creates C type header declaration for this realtime object file
        /// </summary>
        /// <param name="in_parser_parameters"></param>
        public void CreateHeaderFiles(ParserRealtimeObjectExchange.ParserParameters in_parser_parameters)
        {
            string file_name = Path.GetFileNameWithoutExtension(in_parser_parameters.HeaderFileName);

            // create C style header file
            in_parser_parameters.HeaderFile = new StreamWriter(in_parser_parameters.HeaderFileName, false);

            // start of file
            string define_name = "__" + file_name.ToUpper() + "_H";

            in_parser_parameters.HeaderFile.WriteLine("///////////////////////////////////////////////////////////////////////////////");
            in_parser_parameters.HeaderFile.WriteLine("// This header file was generated by the ROXParser");
            in_parser_parameters.HeaderFile.WriteLine("// at " + DateTime.Now.ToString());
            in_parser_parameters.HeaderFile.WriteLine();
            in_parser_parameters.HeaderFile.WriteLine("#ifndef " + define_name);
            in_parser_parameters.HeaderFile.WriteLine("#define " + define_name);
            in_parser_parameters.HeaderFile.WriteLine();

            in_parser_parameters.HeaderFile.WriteLine("/*****************************************************************************/");
            in_parser_parameters.HeaderFile.WriteLine("/* Packet types                                                              */");
            in_parser_parameters.HeaderFile.WriteLine("/*****************************************************************************/");

            // process packet type defines
            for (int i = 0; i < ((ParserRealtimeObjectCollection)m_root_class).Objects.Count; i++)
            {
                in_parser_parameters.HeaderFile.WriteLine("#define roxPT_" + ((ParserRealtimeObjectCollection)m_root_class).Objects[i].Name + " " + ((ParserRealtimeObjectCollection)m_root_class).Objects[i].PacketID.ToString());
            }
            in_parser_parameters.HeaderFile.WriteLine();

            // packet declarations
            in_parser_parameters.HeaderFile.WriteLine("/*****************************************************************************/");
            in_parser_parameters.HeaderFile.WriteLine("/* Packets                                                                   */");
            in_parser_parameters.HeaderFile.WriteLine("/*****************************************************************************/");
            in_parser_parameters.HeaderFile.WriteLine();

            // process objects
            foreach (ParserRealtimeObject obj in ((ParserRealtimeObjectCollection)m_root_class).Objects)
            {
                obj.CreateObjectDeclaration(in_parser_parameters);
            }

            // end of file
            in_parser_parameters.HeaderFile.WriteLine();
            in_parser_parameters.HeaderFile.WriteLine("#endif");
            in_parser_parameters.HeaderFile.WriteLine();

            in_parser_parameters.HeaderFile.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates type information file
        /// </summary>
        /// <param name="in_parser_parameters"></param>
        public void CreateTypeInfoFile(ParserRealtimeObjectExchange.ParserParameters in_parser_parameters)
        {
            // check file name
            if (string.IsNullOrEmpty(in_parser_parameters.TypeInfoFileName))
            {
                return;
            }

            List <int>   type_offset = new List <int>();
            MemoryStream type_array  = new MemoryStream();
            int          i;

            // process packet type defines
            type_offset.Add(0);             // there is no zero indentifier object
            for (i = 0; i < ((ParserRealtimeObjectCollection)m_root_class).Objects.Count; i++)
            {
                type_offset.Add((int)type_array.Position);
                ((ParserRealtimeObjectCollection)m_root_class).Objects[i].CreateTypeInformation(type_array);
            }


            // store type info data
            HexTextFileWriter file = new HexTextFileWriter(in_parser_parameters.TypeInfoFileName);

            // write packet count
            file.WriteHexByte((byte)type_offset.Count);

            // write offset
            for (i = 0; i < type_offset.Count; i++)
            {
                file.WriteHexByte((byte)(type_offset[i] & 0xff));
                file.WriteHexByte((byte)(type_offset[i] >> 8));
            }

            // write type info
            type_array.Seek(0, SeekOrigin.Begin);
            for (i = 0; i < type_array.Length; i++)
            {
                file.WriteHexByte((byte)type_array.ReadByte());
            }

            file.Close();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates C type declaration header for this object
        /// </summary>
        /// <param name="in_header_file"></param>
        public void CreateObjectDeclaration(ParserRealtimeObjectExchange.ParserParameters in_parameters)
        {
            // declaration header
            in_parameters.HeaderFile.WriteLine("///////////////////////////////////////////////////////////////////////////////");
            in_parameters.HeaderFile.WriteLine("// " + m_name);

            in_parameters.HeaderFile.WriteLine("typedef struct");
            in_parameters.HeaderFile.WriteLine("{");
            in_parameters.HeaderFile.WriteLine(in_parameters.Typedefs.PacketHeaderDeclaration);
            in_parameters.HeaderFile.WriteLine();

            // object members
            foreach (ParserRealtimeObjectMember member in m_members)
            {
                member.CreateMemberDeclaration(in_parameters);
            }

            // declaration end
            in_parameters.HeaderFile.WriteLine("} rox" + m_name + ";");
            in_parameters.HeaderFile.WriteLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates default values for packet enable array
        /// </summary>
        /// <param name="in_parser_parameters"></param>
        public void CreateDefaultPacketEnabledFile(ParserRealtimeObjectExchange.ParserParameters in_parser_parameters)
        {
            byte[] enabled_bitfield = new byte[PacketConstants.MaxRealtimePacketCount / 8];
            string attribute_value;
            int    i;
            byte   packet_id;

            // create enabled bitfield
            for (i = 0; i < PacketConstants.MaxRealtimePacketCount / 8; i++)
            {
                enabled_bitfield[i] = 0;
            }

            // process packet type defines
            for (i = 0; i < ((ParserRealtimeObjectCollection)m_root_class).Objects.Count; i++)
            {
                attribute_value = ((ParserRealtimeObjectCollection)m_root_class).Objects[i].GetAttribute("EnabledByDefault");
                if (attribute_value != null && attribute_value == "1")
                {
                    packet_id = ((ParserRealtimeObjectCollection)m_root_class).Objects[i].PacketID;
                    enabled_bitfield[packet_id / 8] |= (byte)(1 << (packet_id % 8));
                }
            }

            // store enabled bitfield
            TextWriter file = new StreamWriter(in_parser_parameters.DefaultPacketEnableFileName, false);

            for (i = 0; i < PacketConstants.MaxRealtimePacketCount / 8; i++)
            {
                if (i != 0)
                {
                    file.Write(",");
                }

                file.Write(string.Format("0x{0:X2}", enabled_bitfield[i]));
            }

            file.Close();
        }
        /// <summary>
        /// Creates C type header declaration of this member
        /// </summary>
        /// <param name="in_header_file"></param>
        public void CreateMemberDeclaration(ParserRealtimeObjectExchange.ParserParameters in_parameters)
        {
            string typestring = in_parameters.Typedefs[m_member_type];

            in_parameters.HeaderFile.WriteLine("  " + typestring + " " + m_name + ";");
        }