Example #1
0
        private void stateListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            MState state = (MState)stateListBox.SelectedItem;

            textBox11.Text = state.id.ToString("X2");
            textBox12.Text = state.cubeClass.ToString("X2");
            textBox13.Text = state.timestamp.ToString();
            textBox14.Text = state.channel.ToString("X2");
            textBox15.Text = state.value.ToString();
        }
Example #2
0
        public void openMMFile(string filename)
        {
            FileStream strm;

            strm = new FileStream(filename, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(strm);

            cubecount = br.ReadByte();

            for (int cubecounter = 0; cubecounter < cubecount; cubecounter++)
            {
                MCube newCube = new MCube();
                newCube.id        = br.ReadByte();
                newCube.cubeClass = br.ReadByte();
                newCube.numLinks  = br.ReadByte();
                for (int linkcounter = 0; linkcounter < newCube.numLinks; linkcounter++)
                {
                    MLink newLink = new MLink();
                    newLink.selfID        = br.ReadByte();
                    newLink.selfClass     = br.ReadByte();
                    newLink.selfSide      = br.ReadByte();
                    newLink.selfOrient    = br.ReadByte();
                    newLink.neighborID    = br.ReadByte();
                    newLink.neighborClass = br.ReadByte();
                    newLink.neighborSide  = br.ReadByte();
                    newCube.links.Add(newLink);
                }
                cubes.Add(newCube);
            }

            byte chksum = br.ReadByte(); // foolishly throw away checksum

            if (chksum != calcCubesChecksum(cubecount, cubes))
            {
                throw new InvalidOperationException("Calculated Cube Checksum Does Not Match File");
            }


            statecount = br.ReadInt32();

            for (int statecounter = 0; statecounter < statecount; statecounter++)
            {
                MState newState = new MState();
                newState.id        = br.ReadByte();
                newState.cubeClass = br.ReadByte();
                newState.timestamp = br.ReadInt32();
                newState.channel   = br.ReadByte();
                newState.value     = br.ReadInt32();
                states.Add(newState);
            }

            chksum = br.ReadByte(); // foolishly throw away checksum

            // Read vs Calculated State Checksums aren't working correctly, bug fixed on
            // controller side which might improve this
            Console.WriteLine(chksum + " " + calcStateChecksum(statecount, states));
            //if (chksum != calcStateChecksum(statecount, states))
            //    throw new InvalidOperationException("Calculated Cube Checksum Does Not Match File");

            strm.Close();
        }