Beispiel #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));
         }
     }
 }
Beispiel #2
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);
            }
        }