Ejemplo n.º 1
0
 public static void PROCESS_instructionPacket(C_Packet lastSent)
 {
     if (IS_packetChangingValue(lastSent) == true)
     {
         if (lastSent.byteId != C_DynAdd.ID_BROADCAST)
         {
             C_MotorControl.ACTUALIZE_motorRegister(
                 lastSent.rotMotor,
                 e_regByteType.sentValue, // as we written them just now
                 lastSent.Par);
             LOG_instruPacket(string.Format(
                                  "Written OK (blind) - actualizing motor [{1}] register sentValue: \t{0}",
                                  lastSent.PacketBytes_toString, lastSent.rotMotor));
         }
         else
         {
             // parse it and process each part alone
             //LOG_instruPacket(string.Format(
             //    "Written OK (blind) - actualizing motors (broadcast) register sentValue: \t{0}",
             //    lastSent.PacketBytes_toString));
             LOG_instruPacket(string.Format(
                                  "Written OK (blind) - NOT actualizing motors (broadcast) register sentValue: \t{0}",
                                  lastSent.PacketBytes_toString));
         }
     }
 }
Ejemplo n.º 2
0
        public static bool FIND_bestPairInLastSentQueues(C_Packet received, ref C_Packet paired)
        {
            // return through ref the best pairedPacket
            e_rot rot;
            bool  foundMotor = C_MotorControl.GET_motorRotFromId(received.ByteId, out rot);
            int   rotMot     = (int)rot;

            if (foundMotor == true)
            {
                lock (queueSent_locker)
                {
                    if (queueSent[rotMot].Count > 0)
                    {
                        List <C_Packet> listSent      = (queueSent[rotMot]).ToList();
                        bool            foundBestPair = FIND_bestPairInQueue(received, ref paired, ref listSent);
                        queueSent[rotMot]       = new Queue <C_Packet>(listSent);
                        queueSent_Count[rotMot] = listSent.Count;
                        C_MotorControl.ACTUALIZE_queueCounts(queueSent);
                        return(foundBestPair);
                    }
                    else
                    {
                        LOG_debug(string.Format("lastSent queue of this motor[{0}] was empty!", rot));
                        return(false);
                    }
                }
            }
            else
            {
                LOG_debug("Did not found any motor connected with this StatusPacket id : "
                          + received.ByteId.ToString());
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static void ACTUALIZE_motorRegistersFromStatusPacket(C_Packet received, C_Packet pairedLastSent)
        {
            try
            {
                if (received.byteId == pairedLastSent.byteId)
                {
                    // we have no error in statusPacket
                    if (pairedLastSent.byteInstructionOrError == C_DynAdd.INS_WRITE)
                    {
                        // actualize the parameters which were written into motors - and we know they were written good
                        C_MotorControl.ACTUALIZE_motorRegister(
                            pairedLastSent.rotMotor,
                            e_regByteType.seenValue, // as we received statusMessage after we written the value
                            pairedLastSent.Par);
                    }
                    else if (pairedLastSent.byteInstructionOrError == C_DynAdd.INS_READ)
                    {
                        // actualize the parameters which were read from motors

                        C_MotorControl.ACTUALIZE_motorRegister(
                            pairedLastSent.rotMotor,
                            e_regByteType.seenValue,
                            C_CONV.listOfObjects2listOfBytes(new List <object>()
                        {
                            pairedLastSent.Par[0], received.Par
                        })
                            );
                    }
                    else
                    {
                        C_SPI.LOG_debug(string.Format(
                                            "lastSent packet: {0}\nPaired with: {1}\n{2}",
                                            pairedLastSent.PacketBytes_toString,
                                            received.PacketBytes_toString,
                                            "wasn't read neither write and yet still it was supposed to be processed as a statusPacket. Not processing!"
                                            ));
                    }
                }
                else
                {
                    LOG_statusPacket(string.Format(
                                         "The received status packet :\t{0}\nDoes not belong to the lastSent: \t{1}",
                                         received.PacketBytes_toString, pairedLastSent.PacketBytes_toString
                                         ));
                }
            }
            catch (Exception e)
            {
                C_SPI.LOG_debug("tak tady to padá! " + e.Message);
            }
        }
Ejemplo n.º 4
0
        public static void QUEUE_PacketSent(C_Packet instructionPacket)
        {
            int rotMot = (int)instructionPacket.rotMotor;

            if (C_Packet.IS_statusPacketFollowing(instructionPacket) == true)
            {
                lock (queueSent_locker)
                {
                    instructionPacket.sentTime = DateTime.Now;
                    queueSent[rotMot].Enqueue(instructionPacket);
                    queueSent_Count[rotMot] = queueSent[rotMot].Count;
                    C_MotorControl.ACTUALIZE_queueCounts(queueSent);
                }
            }
        }
Ejemplo n.º 5
0
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        #region properies
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        #endregion properies
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        #region INIT
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        public void INIT_allMotors()
        {
            Ms = new C_MotorControl();
            //Ms.INIT_individualMotors();

            // set slider limits
            SET_allSlidersLimits();

            // Examples
            INIT_examples();

            // update position
            UPDATE_slidersFromMotors();

            lsChosenMotor.SelectedIndex = 0;
            lsCmdEx.SelectedIndex       = 0;

            INIT_dgMotorData();
            C_State.mot = e_stateMotor.ready;
            //UPDATE_motorsFromSliders();
            //UPDATE_slidersFromMotors();
        }
Ejemplo n.º 6
0
 public static bool UPDATE_portName()
 {
     // returns false if no COM port is found
     string[] portNames = SerialPort.GetPortNames();
     if (portNames == null)
     {
         return(false);
     }
     else
     {
         // select the last one
         spi.PortName = portNames[portNames.Length - 1];
         if (spi.PortName == "COM6")
         {
             C_MotorControl.INIT_groupSettings();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }