public static void ACTUALIZE_motorRegister(e_rot rot, e_regByteType type, List <byte> pars) { if (pars.Count > 0) { byte addressByte = pars[0]; byte[] parValues = pars.Skip(1).ToArray(); C_Packet.LOG_statusPacket(string.Format( "Status OK - actualizing mot[{0}] register type[{1}]: From address[{2}]=[{3}], these values[{4}]", rot, type, addressByte, MainWindow.Ms[rot].Reg.GET_name(addressByte), C_CONV.byteArray2strHex_space(parValues))); foreach (byte byteValue in parValues) { C_SPI.LOG_unimportant(string.Format( "going to acualize mot[{0}] register on address [{1}]", rot, addressByte )); MainWindow.Ms[rot].ACTUALIZE_register(addressByte, byteValue, type); addressByte++; } } }
public static bool FIND_bestPairInQueue(C_Packet received, ref C_Packet pairedPacket, ref List <C_Packet> listLastSent) { // go through whole queue // find the best suitable pair for this packet in this queue: (id, read bytes wanted, timeSpan freshness) // remove it from his queue and return it // if you found echo -> remove it from queue, log it, and continue with search List <int> suitableIndexes = new List <int>(); List <TimeSpan> age = new List <TimeSpan>(); for (int q = 0; q < listLastSent.Count(); q++) { if (received == listLastSent[q]) // echo - possibly from uart2usb converter { C_Packet.LOG_statusPacket(string.Format( "Processed echo of : [{0}] which was sent at [{1}]", C_Packet.GET_packetInfo(listLastSent[q]), listLastSent[q].sentTime.ToString("HH:mm:ss.fff") )); if (C_Packet.IS_statusPacketFollowing(listLastSent[q]) == false) { // if there is not supposed to be more packets comming (not mentioning this echo) // for this lastSent packet - remove it from the listLastSent // (why it was there in the first place then?) - to be removed here listLastSent.RemoveAt(q); } return(false); // found that this is echo of last sent - best pair, // but pairing is just deleting from listLastSent! - for now } if (listLastSent[q].IS_fresh(received.statusReceivedTime) == true) // suitability { if (received.IS_answerOf(listLastSent[q]) == true) { // this is probably the one as the not fresh ones are already dead suitableIndexes.Add(q); age.Add(listLastSent[q].GET_freshness(received.statusReceivedTime)); } else { // just not suitable for this status, but maybe will be for another } } else { listLastSent.RemoveAt(q); // it is too old - remove it q--; // and analyse new lastSent on this index continue; // possibly kills correct ones (if they are too old) } } // find the freshest from the suitable if (age.Count > 0) { // from the suitable ones get the most fresh one - // - return it as through ref as Paired and leave the other one in the listSent (which is also ref) int minimumValueIndex = age.IndexOf(age.Min()); pairedPacket = listLastSent[minimumValueIndex]; listLastSent.RemoveAt(minimumValueIndex); if (age.Count > 1) { LOG_debug(string.Format( "[{0}] packets suitable pairs in the motor.listLastSent for this status, but only one was selceted. (age={1}ms)", suitableIndexes.Count - 1, age[minimumValueIndex] )); } return(true); } else { return(false); } }