コード例 #1
0
        /// <summary>
        /// Primary Constructor for a TransferManager. Expected to work with one lynx
        /// </summary>
        /// <param name="tagger">used to initiate event handlers in TransferManager</param>
        /// <param name="FrameReporter">used to initiate event handlers in TransferManager</param>
        /// <param name="anticipatedLynx">the id of the lynx this TransferManager is intended to handle</param>
        public TransferManager(TagVisualizer tagger, Grid FrameReporter, int anticipatedLynx)
        {
            lynx          = new Lynx(anticipatedLynx); //TEMP
            sendBuffer    = new byte[512];             //size is arbitrary
            receiveBuffer = new byte[4098];
            toSend        = 0;
            sIndex        = 0;
            rIndex        = 0;
            toReceive     = 0;
            lightMatrix   = new int[16];

            length     = -1;
            currentRID = -1;
            flags      = -1;
            type       = sendType.String;
            checksum   = 0;

            headerInProgress = false;
            offset           = 0;

            hasRead        = false;
            hasWritten     = false;
            lynxHasRead    = false;
            lynxHasWritten = true;

            addTagListener(tagger);
            addFrameReporter(FrameReporter);
            //tempTestStop = true;
            LynxAvailable = false;
            DataReset     = false;
        }
コード例 #2
0
ファイル: Connection.cs プロジェクト: foxbot/GoogBot-Recode
        private void SendMessage(string message, Command command, sendType type)
        {
            string destination;

            if (command.channelMessage)
            {
                destination = command.channel.channelName;
            }
            else
            {
                destination = command.nick;
            }

            switch (type)
            {
            case sendType.message:
                client.SendMessage(message, destination);
                break;

            case sendType.action:
                client.SendAction(message, destination);
                break;
                // Implement notices once upgraded to the new version
            }
        }
コード例 #3
0
 public Packet(pType packetType, sendType typeOfSend, object obj = null)
 {
     this.packetType     = packetType;
     this.packetSendType = typeOfSend;
     if (obj != null)
     {
         SetPacketData(obj);
     }
 }
コード例 #4
0
        public logPatientFlowCls(sendType type, int tpr_id, int tps_id, int mhs_id, string mrd_ename, string mut_username, DateTime?StartProcressTime = null)
        {
            try
            {
                using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                {
                    DateTime          dateNow         = Program.GetServerDateTime();
                    trn_patient_queue newPatientQueue = cdc.trn_patient_queues.Where(x => x.tpr_id == tpr_id &&
                                                                                     ((x.tps_status == "NS" && x.tps_ns_status == "QL") ||
                                                                                      (x.tps_status == "NS" && x.tps_ns_status == "WL") ||
                                                                                      x.tps_status == "WK"))
                                                        .OrderByDescending(x => x.tps_id).FirstOrDefault();
                    int?nextTpsID = null;
                    if (newPatientQueue != null)
                    {
                        nextTpsID = newPatientQueue.tps_id;
                    }
                    int countFlow = cdc.log_patient_flows.Where(x => x.tpr_id == tpr_id).Count();

                    log_patient_flow log = new log_patient_flow()
                    {
                        log_time     = dateNow,
                        mhs_id       = mhs_id,
                        mrd_ename    = mrd_ename,
                        mut_username = mut_username,
                        send_type    = type.ToString(),
                        seq_id       = countFlow + 1,
                        tpr_id       = tpr_id,
                        tps_id       = tps_id,
                        next_tps_id  = nextTpsID,
                        process_time = StartProcressTime == null ? 0 : Convert.ToInt64((DateTime.Now - StartProcressTime.Value).TotalMilliseconds)
                                       // nextTpsID
                    };
                    cdc.log_patient_flows.InsertOnSubmit(log);
                    cdc.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Program.MessageError("logPatientFlowCls", "logPatientFlowCls", ex, false);
            }
        }
コード例 #5
0
        public LynxReceivedArgs(dynamic receivedData, sendType t)
        {
            switch (t)
            {
            case sendType.Char:
                type = "char";
                data = (char)receivedData;
                break;

            case sendType.Double:
                type = "double";
                data = (double)receivedData;
                break;

            case sendType.Float:
                type = "float";
                data = (float)receivedData;
                break;

            case sendType.Int:
                type = "int";
                data = (int)receivedData;
                break;

            case sendType.NULLTYPE:
                type = "null";
                data = null;
                break;

            case sendType.Object:
                type = "object";
                data = receivedData;
                break;

            case sendType.String:
                type = "string";
                data = (string)receivedData;
                break;
            }
        }
コード例 #6
0
        /*
         * IMPORTANT: header generates padding to fit in 8-bit chucks. Remember to restart shift after sending header
         * */
        private void formHeader(int length, sendType t, int partialCheck)
        {
            sendBuffer[(sIndex + toSend) % sendBuffer.Length] = (byte)((lynx.id << 4) + ((int)t >> 2));
            partialCheck += sendBuffer[sIndex + toSend++];

            sendBuffer[(sIndex + toSend) % sendBuffer.Length] = (byte)((((int)t & 3) << 6) + (length >> 4));
            partialCheck += sendBuffer[sIndex + toSend++];

            sendBuffer[(sIndex + toSend) % sendBuffer.Length] = (byte)((length & 15) << 4);
            partialCheck += sendBuffer[sIndex + toSend++];

            while (partialCheck > 255)
            {
                partialCheck = (partialCheck >> 8) + (partialCheck & 255);
            }
            for (int i = 0; i < 8; i++)
            {
                partialCheck = partialCheck ^ (1 << i);
            }

            sendBuffer[sIndex + toSend - 1] += (byte)(partialCheck >> 4);
            sendBuffer[sIndex + toSend++]    = (byte)((partialCheck & 15) << 4);
        }
コード例 #7
0
        private void translateBinary()
        {
            int check;

            switch (type)
            {
            case sendType.String:

                String returnString = "";
                check = 0;

                for (int i = 4; i < length; i++)
                {
                    returnString = returnString + (char)receiveBuffer[i];
                    check       += receiveBuffer[i];
                }

                check += receiveBuffer[0] + receiveBuffer[1] + (receiveBuffer[2] & 240);
                while (check > 255)
                {
                    check = (check & 255) + (check >> 8);
                }
                for (int i = 0; i < 8; i++)     //XOR check not necessary
                {
                    check = check ^ (1 << i);
                }

                Console.Write("fire\n");
                if (((byte)check ^ checksum) == 0)
                {
                    if (ReceivedData != null)
                    {
                        ReceivedData(this, new LynxReceivedArgs(returnString, type));
                    }
                    Console.Write(returnString);
                }
                else
                {
                    if (ReceivedError != null)
                    {
                        ReceivedError(this, new LynxErrorArgs(checksum, (byte)check));
                    }
                    Console.Write("Error\n");
                }
                break;

            case sendType.Char:
                check = receiveBuffer[0] + receiveBuffer[1] + receiveBuffer[2] & 240 + receiveBuffer[4];
                char returnChar = (char)receiveBuffer[4];

                while (checksum > 255)
                {
                    check = check & 255 + check >> 8;
                }
                for (int i = 0; i < 8; i++)
                {
                    check = check ^ (1 << i);
                }

                if (((byte)check ^ checksum) == 0)
                {
                    if (ReceivedData != null)
                    {
                        ReceivedData(this, new LynxReceivedArgs(returnChar, type));
                    }
                }
                else
                if (ReceivedError != null)
                {
                    ReceivedError(this, new LynxErrorArgs(checksum, (byte)check));
                }
                break;
            }
            rIndex        = 0;
            type          = sendType.NULLTYPE;
            flags         = -1;
            length        = -1;
            currentRID    = -1;
            offset        = 0;
            sendingOffset = 0;
        }
コード例 #8
0
        /// <summary>
        /// Recieves stuff.
        /// </summary>
        public void receive()
        {
            byte h1 = calculateByte(0);
            byte h2 = calculateByte(8);

            if (length < 0 || headerInProgress == true)
            {
                if (headerInProgress == true)
                {
                    length          += ((h1 & 126) >> 1) + 4;
                    checksum         = (byte)(((h1 & 1) << 7) + (h2 & 127));
                    headerInProgress = false;
                }
                else
                {
                    currentRID       = (h1 & 120) >> 3;
                    flags            = (h1 & 6) >> 1;
                    type             = (sendType)(((h1 & 1) << 3) + (byte)((h2 & 112) >> 4));
                    length           = (h2 & 15) << 6;
                    headerInProgress = true;
                }
            }
            if (length - toReceive >= 0 || headerInProgress == true) // ADD INITIAL CASE!!!!
            {
                //shift h1
                if (offset != 7)
                {
                    receiveBuffer[rIndex] += (byte)((h1 & (127 ^ (127 >> offset))) >> (7 - offset));//add least significant bits to previous byte
                }
                else
                {
                    receiveBuffer[rIndex] += (byte)(h1 & 127);
                }
                if (offset != 0)
                {
                    rIndex++;
                    toReceive++;
                }
                receiveBuffer[rIndex] = (byte)((h1 & (127 >> offset)) << (offset + 1)); //add most significatnt bits to current byte
                offset = (offset + 1) % 8;
                //end shift h1


                //shift h2
                if (offset != 7)
                {
                    receiveBuffer[rIndex] += (byte)((h2 & (127 ^ (127 >> offset))) >> (7 - offset));//add least significant bits to previous byte
                }
                else
                {
                    receiveBuffer[rIndex] += (byte)(h2 & 127);
                }
                if (offset != 0)
                {
                    rIndex++;
                    toReceive++;
                }
                receiveBuffer[rIndex] = (byte)((h2 & (127 >> offset)) << (offset + 1)); //add most significatnt bits to current byte
                offset = (offset + 1) % 8;
                //end shift h2
            }
            else if (length - toReceive < 0)
            {
                toReceive = 0;
                translateBinary();
            }
        }
コード例 #9
0
 public Packet(pType packetType, sendType typeOfSend, byte[] obj)
 {
     this.packetType     = packetType;
     this.packetSendType = typeOfSend;
     packetData          = obj;
 }
コード例 #10
0
 public Packet(pType packetType, sendType typeOfSend, byte b)
 {
     this.packetType     = packetType;
     this.packetSendType = typeOfSend;
     SetPacketData(new byte[] { b });
 }