// This is the method to run when the timer is raised. private void UartTimerProcessor(object sender, EventArgs e) { // NOTE: this timer works on the GUI thread debugMsg("Enter UartTimerProcessor(), current state is " + this.CurrState); // clean up, the device isn't responding this.myFileSender = null; switch (this.CurrState) { case RunState.ReadBootLoader: case RunState.ReadBootLoaderComplete: case RunState.Done: // Take no action. There is no timeout in these states break; case RunState.UpdateSoftwareFlashWriter: case RunState.UpdateSoftwareFirmware: case RunState.LoadFlashBoot: case RunState.ReadSoftwareVersion: // Operation failed SetStatusLabelText("Operation timed out"); CurrState = RunState.Done; SetButtonsAvailability(true, false); break; } }
public int Calculate(IProgrammer programmerFrom, IProgrammer programmer) { if (programmerFrom == programmer) { return(0); } var toProcess = new Queue <Tuple <int, IProgrammer> >(); toProcess.Enqueue(new Tuple <int, IProgrammer>(1, programmerFrom)); while (toProcess.Count > 0) { var programmerToProcess = toProcess.Dequeue(); if (HasRecommended(programmerToProcess, programmer)) { return(programmerToProcess.Item1); } if (IsRecommendedBy(programmerToProcess, programmer)) { return(programmerToProcess.Item1); } AddRecommendationsTo(toProcess, programmerToProcess.Item1 + 1, programmerToProcess.Item2); AddRecommendedBysTo(toProcess, programmerToProcess.Item1 + 1, programmerToProcess.Item2); } throw new ProgrammersNotConnectedException(); }
public decimal CalculateRank(IProgrammer programmer) { var _recommendedBys = programmer.RecommendedBys; // (1 - d) + d(PR(T1)/C(T1)) + ... + d(PR(Tn)/C(Tn)) return(_recommendedBys .Aggregate(1m - 0.85m, (current, p) => current + 0.85m * p.ProgrammerRankShare)); }
private decimal MemberStrength(IProgrammer member) { var rank = member.Details.Rank; var skillIndex = Array.IndexOf(member.Details.Skills.ToArray(), _language) + 1; var leader = _members.First(); var degreesOfSeparation = leader.Equals(member) ? 1 : _degreesOfSeparation.Between(leader, member); return(rank / (skillIndex * degreesOfSeparation)); }
private static bool VerifyBlocks(IProgrammer programmer, HexBlocks blocks, AvrMemoryType memType, DeviceOperation op) { if (blocks.Blocks.All(block => VerifyBlock(programmer, block, memType, op))) { return(true); } op.Complete(); op.Status = DeviceOperationStatus.Error; return(false); }
public int Between(IProgrammer programmerFrom, IProgrammer programmerTo) { if (programmerFrom.Equals(programmerTo)) { return(0); } var parents = BuildParentPointers(programmerFrom); return(ShortestPath(programmerFrom, programmerTo, parents)); }
/// <summary> /// Send the specified binary file to the device through the serial port via xmodem (checksum). /// </summary> /// <param name="fileName">Name of the file to be sent</param> /// <param name="image">Bytes of the file to be sent</param> private void SendXmodem(String fileName, byte[] image) { myFileSender = new XmodemSender(fileName, image); SetStatusLabelText("Downloading " + fileName); myFileSender.eUpdateMessage = debugMsg; myFileSender.eSendBytes = SendData; myFileSender.eSendByte = SendData; myFileSender.eFlush = Flush; myFileSender.eTransferComplete = fileTransferComplete; myFileSender.SendFile(); }
/// <summary> /// Send the specified stewie file to the device through the serial port. /// </summary> /// <param name="fileName">Name of the file to be sent</param> /// <param name="image">Bytes of the file to be sent</param> /// <param name="c">Synchronization character</param> private void SendStewie(String fileName, byte[] image, char c) { myFileSender = new StewieFileSender(fileName, image, c); SetStatusLabelText("Downloading " + fileName); myFileSender.eUpdateMessage = debugStewie; myFileSender.eSendBytes = SendData; myFileSender.eSendByte = SendData; myFileSender.eFlush = Flush; myFileSender.eTransferComplete = fileTransferComplete; myFileSender.SendFile(); }
private static int ShortestPath(IProgrammer programmerFrom, IProgrammer programmerTo, Dictionary <IProgrammer, IProgrammer> parents) { var degreesOfSeparation = 0; IProgrammer parentProgrammer = programmerTo; while (!programmerFrom.Equals(parentProgrammer)) { parentProgrammer = parents[parentProgrammer]; degreesOfSeparation++; } return(degreesOfSeparation); }
static void Main(string[] args) { IProgrammer programmer = null; programmer = ApplicationContext.UnityContainer.Resolve <IProgrammer>("CSharper"); programmer.Work(); programmer = ApplicationContext.UnityContainer.Resolve <IProgrammer>("VBer"); programmer.Work(); programmer = ApplicationContext.UnityContainer.Resolve <IProgrammer>("Pythoner"); programmer.Work(); programmer = ApplicationContext.UnityContainer.Resolve <IProgrammer>("Pythoner"); programmer.Work(); Console.ReadKey(); }
private Dictionary <IProgrammer, IProgrammer> BuildParentPointers(IProgrammer programmerFrom) { var parents = new Dictionary <IProgrammer, IProgrammer>(); var queue = new Queue <IProgrammer>(); queue.Enqueue(programmerFrom); while (queue.Count() > 0) { AddAdjacentNodes(parents, queue); queue.Dequeue(); } return(parents); }
private static bool VerifyBlock(IProgrammer programmer, HexBlock block, AvrMemoryType memType, DeviceOperation op) { var actualData = new byte[block.Data.Length]; programmer.ReadPage(block.Address, memType, actualData, 0, actualData.Length); for (var i = 0; i < block.Data.Length; i++) { var actual = actualData[i]; var expected = block.Data[i]; var address = i + block.Address; if (!op.Device.Verify(memType, address, actual, expected)) { op.CurrentState = string.Format("Verification failed at {0}:0x{1:x4}.\r\nExpected 0x{2:x2} but was 0x{3:x2}", memType, i + block.Address, expected, actual); return(false); } } return(true); }
public ProgrammingSession(IProgrammer programmer) { _programmer = programmer; }
public ProgressTrackerProgrammer(IProgrammer inner, DeviceOperation deviceOperation) { _inner = inner; _deviceOperation = deviceOperation; }
public ProgManagerAdapter(IProgrammer programmer) { _programmer = programmer; }
public void AddRecommendedBysTo(Queue <Tuple <int, IProgrammer> > queue, int degreeOfSeparation, IProgrammer processed) { foreach (var recommendedBy in processed.RecommendedBys) { if (processed != recommendedBy) { queue.Enqueue(new Tuple <int, IProgrammer>(degreeOfSeparation, recommendedBy)); } } }
public bool IsRecommendedBy(Tuple <int, IProgrammer> programmerToProcess, IProgrammer programmer) { return(programmerToProcess.Item2.RecommendedBys.Contains(programmer)); }
public bool HasRecommended(Tuple <int, IProgrammer> programmerToProcess, IProgrammer programmer) { return(programmerToProcess.Item2.Recommendations.Contains(programmer)); }
public static Task ProgramHexFile(this IProgrammer programmer, string path) { using (var fileStream = File.OpenRead(path)) return(programmer.ProgramHexFile(fileStream)); }
private static void AddNode(Dictionary <IProgrammer, IProgrammer> parents, Queue <IProgrammer> queue, IProgrammer parent, IProgrammer programmer) { if (!parents.ContainsKey(programmer)) { queue.Enqueue(programmer); parents.Add(programmer, parent); } }
private Tuple <int, IProgrammer> BuildTuple(int degreeOfSeparation, IProgrammer programmer) { return(new Tuple <int, IProgrammer>(degreeOfSeparation, programmer)); }