Example #1
0
        void SendCmd(WORD wDevID, BYTE wCmdOrAck, int nParam)
        {
            CMD_PKT pkt = new CMD_PKT();

            BYTE[] pktBuffer = new BYTE[12];

            pkt.Head1   = (BYTE)COMMAND_START_CODE1;
            pkt.Head2   = (BYTE)COMMAND_START_CODE2;
            pkt.wDevId0 = (byte)(wDevID & 0xFF);
            pkt.wDevId1 = (byte)(wDevID >> 8);
            pkt.nParam0 = (byte)(nParam & 0xFF);
            pkt.nParam1 = (byte)((nParam & 0xFF00) >> 8);
            pkt.nParam2 = (byte)((nParam & 0xFF0000) >> 16);
            pkt.nParam3 = (byte)((nParam & 0xFF000000) >> 24);
            pkt.wCmd0   = wCmdOrAck;
            pkt.wCmd1   = 0x00;
            WORD chksum = CalcChkSumOfCmd(ref pkt);

            pkt.wChkSum0 = (byte)(chksum % 256);
            pkt.wChkSum1 = (byte)(chksum >> 8);

            pktBuffer = PktToByteArray(ref pkt);

            serial.Write(pktBuffer, 0, PKT_SIZE);
        }
Example #2
0
        // C2FORMAT.TXT line 180ff
        //STAFF (Notenzeile)
        //  LIEDTEXT
        //  BOOL        fActiveVoice
        //  INT         Stimme  (0 = Einzelzeile, 1 = erste Stimme, 2 = zweite Stimme)
        //  INT         zusaetzlicher Abstand nach oben (in Notenlinien)
        //  INT         zusaetzlicher Abstand nach unten (in Notenlinien)
        //  BYTE        Layout-Zeilennummer
        //  UINT        countAccords
        //  CHAR[countAccords]    Akkordinformationen (siehe Abschnitt 5)
        //  INT         n (Anzahl Akkorde+1)
        //  INT[n+1]    Akkordindizes (Indizes der Akkordbeschreibungen in den Daten.
        //              Beispiel: Akkordindizes[2] = 17 bedeutet, dass die Beschreibung
        //              des 3. Akkords (Zaehlung ab 0) bei Byte 17 der Akkordinformationen
        //              beginnt.
        //end
        private void ReadSTAFF(byte[] buffer, ref uint position, int measureIndex)
        {
            // read complete STAFF data
            this.ReadLIEDTEXT(buffer, ref position, out string text);
            Read(buffer, ref position, out BOOL activeVoice);
            Read(buffer, ref position, out INT voiceNumber);
            Read(buffer, ref position, out INT topMargin);
            Read(buffer, ref position, out INT bottomMargin);
            Read(buffer, ref position, out BYTE staffNumber);
            Read(buffer, ref position, out UINT countAccords);
            var accords = new BYTE[countAccords];

            for (uint i = 0; i < countAccords; i++)
            {
                Read(buffer, ref position, out accords[i]);
            }

            Read(buffer, ref position, out INT n);
            var indexes = new INT[n + 1];

            for (uint i = 0; i < n + 1; i++)
            {
                Read(buffer, ref position, out indexes[i]);
            }

            // read completed

            // process read data
            this.ProcessAccords(staffNumber, measureIndex, voiceNumber, accords, indexes, text);
        }
Example #3
0
 public MSG_S2C_CHAR_LIST()
 {
     MsgHeader            = new MSG_S2C_HEADER_578();
     MsgHeader.dwSize     = GetSize();//0x3BF;
     MsgHeader.dwProtocol = 0x1105;
     byUnknow             = new BYTE[0x05];
 }
Example #4
0
        int open()
        {
            serial.Open();
            status = true;

            if (executeCmd(CMD_OPEN, 1) < 0)
            {
                return(COMM_ERR);
            }

            Thread.Sleep(100);

            BYTE[] Data = new BYTE[6];

            if (ReceiveData(uwDevID, ref Data, 6, 100) < 0)
            {
                return(COMM_ERR);
            }

            firmwareYear  = Data[0] * 100 + Data[1];
            firmwareMonth = Data[2];
            firmwareDay   = Data[3];

            return(0);
        }
Example #5
0
 private BLENDFUNCTION(byte blendOp, byte blendFlags, byte sourceConstantAlpha, byte alphaFormat)
 {
     BlendOp             = blendOp;
     BlendFlags          = blendFlags;
     SourceConstantAlpha = sourceConstantAlpha;
     AlphaFormat         = alphaFormat;
 }
Example #6
0
 public MSG_S2C_1105_578()
 {
     MsgHeader            = new MSG_S2C_HEADER_578();
     MsgHeader.dwSize     = GetSize();//0x3BF;
     MsgHeader.dwProtocol = 0x1105;
     byUnknow             = new BYTE[0x05];
     CharInfo             = new CHARACTER_INFO562[5];
 }
Example #7
0
 int executeCmd(BYTE wCmd, int nCmdParam)
 {
     SendCmd(uwDevID, wCmd, nCmdParam);
     Thread.Sleep(100);
     if (ReceiveCmd(uwDevID, ref gwLastAck, ref gwLastAckParam) < 0)
     {
         return(COMM_ERR);
     }
     return(0);
 }
Example #8
0
        public bool UnPackPacket(uint uMaxDecompressedSize)
        {
            Debug.Assert(prot == Opcodes.OP_PACKEDPROT || prot == Opcodes.OP_KADEMLIAPACKEDPROT);
            uint nNewSize = size * 10 + 300;

            if (nNewSize > uMaxDecompressedSize)
            {
                //ASSERT(0);
                nNewSize = uMaxDecompressedSize;
            }
            byte[] unpack       = null;
            uLongf unpackedsize = 0;
            uint   result       = 0;

            do
            {
                delete[] unpack;
                unpack       = new BYTE[nNewSize];
                unpackedsize = nNewSize;
                result       = uncompress(unpack, &unpackedsize, (BYTE *)pBuffer, size);
                nNewSize    *= 2; // size for the next try if needed
            } while (result == Z_BUF_ERROR && nNewSize < uMaxDecompressedSize);

            if (result == Z_OK)
            {
                Debug.Assert(completebuffer == null);
                Debug.Assert(pBuffer != null);
                size = unpackedsize;
                delete[] pBuffer;
                pBuffer = (byte[])unpack;
                if (prot == Opcodes.OP_KADEMLIAPACKEDPROT)
                {
                    prot = Opcodes.OP_KADEMLIAHEADER;
                }
                else
                {
                    prot = Opcodes.OP_EMULEPROT;
                }
                return(true);
            }
            delete[] unpack;
            return(false);
        }
Example #9
0
        int ReceiveData(WORD wDevID, ref BYTE[] pBuf, int nSize, DWORD timeout)
        {
            WORD wReceivedChkSum, wChkSum;

            BYTE[] CommBuf;
            int    nReceivedBytes;

            if (pBuf == null)
            {
                return(PKT_PARAM_ERR);
            }

            CommBuf        = new BYTE[nSize + HEADER_SIZE + DEV_ID_SIZE + CHK_SUM_SIZE];
            nReceivedBytes = serial.Read(CommBuf, 0, nSize + HEADER_SIZE + DEV_ID_SIZE + CHK_SUM_SIZE);
            if (nReceivedBytes != nSize + HEADER_SIZE + DEV_ID_SIZE + CHK_SUM_SIZE)
            {
                return(PKT_COMM_ERR);
            }

            wReceivedChkSum = (WORD)((WORD)(CommBuf[nSize + HEADER_SIZE + DEV_ID_SIZE + 1] << 0x08) | (WORD)(CommBuf[nSize + HEADER_SIZE + DEV_ID_SIZE]));

            if ((CommBuf[0] != DATA_START_CODE1) || (CommBuf[1] != DATA_START_CODE2))
            {
                return(PKT_HDR_ERR);
            }

            for (int i = 0; i < nSize; i++)
            {
                pBuf[i] = CommBuf[i + HEADER_SIZE + DEV_ID_SIZE];
            }

            wChkSum = CalcChkSumOfDataPkt(ref CommBuf, HEADER_SIZE + DEV_ID_SIZE + nSize);

            if (wChkSum != wReceivedChkSum)
            {
                return(PKT_CHK_SUM_ERR);
            }
            return(0);
        }
Example #10
0
        int ReceiveCmd(WORD wDevID, ref WORD wCmd, ref int nParam)
        {
            CMD_PKT pkt;

            BYTE[] CommBuf;
            int    nReceivedBytes;

            CommBuf        = new BYTE[12];
            nReceivedBytes = serial.Read(CommBuf, 0, PKT_SIZE);
            if (nReceivedBytes != PKT_SIZE)
            {
                return(PKT_COMM_ERR);
            }

            if ((CommBuf[0] != COMMAND_START_CODE1) || (CommBuf[1] != COMMAND_START_CODE2))
            {
                return(PKT_HDR_ERR);
            }

            pkt = ByteArrayToPkt(ref CommBuf);

            WORD chksum = CalcChkSumOfCmd(ref pkt);

            pkt.wChkSum0 = (byte)(chksum % 256);
            pkt.wChkSum1 = (byte)(chksum >> 8);

            if ((pkt.wChkSum0 != (byte)(chksum % 256)) ||
                (pkt.wChkSum1 != (byte)(chksum >> 8)))
            {
                return(PKT_CHK_SUM_ERR);
            }

            wCmd   = (WORD)(pkt.wCmd1 << 8 | pkt.wCmd0);
            nParam = pkt.nParam1 << 8 | pkt.nParam0;

            return(0);
        }
Example #11
0
 public static string GetIP_V4_Address()
 {
     return(BYTE.RandPick(4).Join("."));
 }
Example #12
0
 public static byte LOBYTE(BYTE w)
 {
     return(w);
 }
Example #13
0
        // C2FORMAT.TXT line 85ff
        //LAYOUT (Beschreibung der Partitur-Formatvorlage)
        //  if Dateikennung >= V2.1
        //    BYTE    topDist
        //    CHAR    Ersatzzeichen fuer geschuetztes Leerzeichen ('\0' --> '$')
        //    BYTE    interDist
        //    CHAR    Ersatzzeichen fuer geschuetzten Bindestrich ('\0' --> '#')
        //  else
        //    INT     topDist
        //    INT     interDist
        //  endif
        //  BYTE    beamMode
        //  FONT    txtFont
        //  BYTE    txtAlign
        //  BOOL    allaBreve
        //  UINT    tempo
        //  INT     staves
        //  if Dateikennung >= V2.1
        //    BYTE[16] nSound  (Klang fuer Kanal 1 bis 16
        //                      im 1. Byte ist hoechstes Bit gesetzt!)
        //    BYTE[16] nVolume (Lautstaerke fuer Kanal 1 bis 16)
        //  else (Version 2.0)
        //    BYTE[9] nSound   (Klang fuer Kanal 1 bis 9)
        //    BYTE[9] nVolume  (Lautstaerke fuer Kanal 1 bis 9)
        //  endif
        //  STAFF_LAYOUT[staves]
        //end
        private void ReadLAYOUT(byte[] buffer, ref uint position)
        {
            if (this.version >= FileVersion.V21)
            {
                Read(buffer, ref position, out BYTE topDist);
                Read(buffer, ref position, out CHAR spaceReplacement);
                Read(buffer, ref position, out BYTE interDist);
                Read(buffer, ref position, out CHAR dashReplacement);
            }
            else
            {
                Read(buffer, ref position, out INT topDist);
                Read(buffer, ref position, out INT interDist);
            }

            Read(buffer, ref position, out BYTE beamMode);
            this.ReadFONT(buffer, ref position);
            Read(buffer, ref position, out BYTE txtAlign);
            Read(buffer, ref position, out BOOL allaBreve);
            Read(buffer, ref position, out UINT tempo);
            Read(buffer, ref position, out INT staveCount);
            if (this.version >= FileVersion.V21)
            {
                var soundValues  = new BYTE[16];
                var volumeValues = new BYTE[16];
                for (int i = 0; i < 16; i++)
                {
                    Read(buffer, ref position, out soundValues[i]);
                }

                for (int i = 0; i < 16; i++)
                {
                    Read(buffer, ref position, out volumeValues[i]);
                }
            }
            else
            {
                var soundValues  = new BYTE[9];
                var volumeValues = new BYTE[9];
                for (int i = 0; i < 9; i++)
                {
                    Read(buffer, ref position, out soundValues[i]);
                }

                for (int i = 0; i < 9; i++)
                {
                    Read(buffer, ref position, out volumeValues[i]);
                }
            }

            // TODO hier hatte ich zuerst ein partlist-Array. R# hat eine Co-Varianz-Warnung angezeigt. Daher nun object-Array.
            this.Document.partlist = new partlist {
                Items = new object[staveCount]
            };
            this.Document.part = new scorepartwisePart[staveCount];

            this.InitStaves(staveCount);

            for (int i = 0; i < staveCount; i++)
            {
                // initialite partDescription structures for current staff
                var partDescription = new scorepart();
                this.Document.partlist.Items[i] = partDescription;
                partDescription.id = "P" + (i + 1).ToString(CultureInfo.InvariantCulture);
                var partData = new scorepartwisePart {
                    id = partDescription.id
                };
                this.Document.part[i] = partData;

                var firstMeasure = new scorepartwisePartMeasure();
                this.measures[i].Add(firstMeasure);
                firstMeasure.number = "1";

                attributes att = firstMeasure.GetAttributes();

                // 32 corresponds with duration values in readSTAFF()
                att.divisions          = 32;
                att.divisionsSpecified = true;

                this.ReadSTAFFLAYOUT(buffer, ref position, i, partDescription);

                firstMeasure.AddClef(
                    this.currentKeyForm[i],
                    this.currentKeyLine[i],
                    this.currentKeyOctavation[i]);
            }
        }
Example #14
0
            private static FIELD CreateNewField(BinaryReader br, int index, int fieldOffset, int dataOrDataOffset, GffFieldType fieldType)
            {
                FIELD data;

                switch (fieldType)
                {
                case GffFieldType.BYTE:
                    data = new BYTE(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.CHAR:
                    data = new CHAR(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.WORD:
                    data = new WORD(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.SHORT:
                    data = new SHORT(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.DWORD:
                    data = new DWORD(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.INT:
                    data = new INT(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.DWORD64:
                    data = new DWORD64(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.INT64:
                    data = new INT64(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.FLOAT:
                    data = new FLOAT(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.DOUBLE:
                    data = new DOUBLE(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.CExoString:
                    data = new CExoString(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.ResRef:
                    data = new ResRef(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.CExoLocString:
                    data = new CExoLocString(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.VOID:
                    data = new VOID(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.Struct:
                    int lbl_index = br.ReadInt32();
                    data = new STRUCT(br, br.ReadInt32(), lbl_index);
                    break;

                case GffFieldType.List:
                    data = new LIST(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.Orientation:
                    data = new Orientation(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.Vector:
                    data = new Vector(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                case GffFieldType.StrRef:
                    data = new StrRef(br, fieldOffset + dataOrDataOffset * 12);
                    break;

                default:
                    throw new Exception(string.Format("UNEXPECTED FIELD TYPE \"{0}\", IN STRUCT INDEX \"{1}\"", fieldType, index));
                }

                return(data);
            }