private void cubeListBox_SelectedIndexChanged(object sender, EventArgs e) { MCube cube = (MCube)cubeListBox.SelectedItem; textBox3.Text = cube.id.ToString("X2"); textBox2.Text = cube.cubeClass.ToString("X2"); textBox1.Text = cube.numLinks.ToString(); linkListBox.Items.Clear(); foreach (MLink link in cube.links) { linkListBox.Items.Add(link); } clearListDetails(); }
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(); }