Exemplo n.º 1
0
 // Private function
 private void StartNewProcess()
 {
     BlockMessageInProcess.ClearBlockMessage();
     ExpectedDataListLen = 0;
     msg_field_index     = 0;
     Format_ID           = FORMAT_ID.WAIT_FOR_ZERO;
 }
Exemplo n.º 2
0
        private bool ProcessFormat3(byte next_byte)
        {
            bool bRet = false;

            switch ((MSG_STAGE_FORMAT_03)msg_field_index)
            {
            case MSG_STAGE_FORMAT_03.FMT:
                BlockMessageInProcess.SetFmt(next_byte);
//                   ExpectedDataListLen = (next_byte & 0x3f) - 1;       // minus SID byte
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                msg_field_index++;
                break;

            case MSG_STAGE_FORMAT_03.Len:
                BlockMessageInProcess.SetLenByte(next_byte);
                ExpectedDataListLen = next_byte - 1;           // minus SID byte
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                msg_field_index++;
                break;

            case MSG_STAGE_FORMAT_03.SID:
                BlockMessageInProcess.SetSID(next_byte);
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                if (ExpectedDataListLen > 0)
                {
                    msg_field_index++;
                }
                else
                {
                    msg_field_index += 2;
                }
                break;

            case MSG_STAGE_FORMAT_03.Data:
                BlockMessageInProcess.AddToDataList(next_byte);
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                if (BlockMessageInProcess.GetDataListLen() >= ExpectedDataListLen)
                {
                    msg_field_index++;
                }
                break;

            case MSG_STAGE_FORMAT_03.CS:
                byte current_checksum = BlockMessageInProcess.GetCheckSum();
                bRet            = (current_checksum == next_byte) ? true : false; // data available if checksum is ok
                Format_ID       = FORMAT_ID.NEW;
                msg_field_index = 0;
                break;
            }
            return(bRet);
        }
Exemplo n.º 3
0
        public bool ProcessNextByte(byte next_byte)
        {
            bool bRet = false;

            switch (Format_ID)
            {
            case FORMAT_ID.WAIT_FOR_ZERO:
                if (next_byte == 0)
                {
                    Format_ID       = FORMAT_ID.NEW;
                    msg_field_index = 0;
                }
                break;

            case FORMAT_ID.NEW:
                if (CheckAndClearP3Timeout() == true)
                {
                    // Already timeout, must be a zero for a valid data
                    if (next_byte != 0)
                    {
                        Format_ID = FORMAT_ID.WAIT_FOR_ZERO;
                    }
                    else
                    {
                        msg_field_index = 0;
                    }
                }
                else if (next_byte == 0)
                {
                    msg_field_index = 0;
                }
                else
                {
                    BlockMessageInProcess.ClearBlockMessage();
                    MSG_A1A0_MODE mode_info = (MSG_A1A0_MODE)((next_byte & 0xc0) >> 6);
                    switch (mode_info)
                    {
                    case MSG_A1A0_MODE.NO_ADDRESS_INFO:              // No Address Information
                        if ((next_byte & 0x3f) == 0)
                        {
                            Format_ID = FORMAT_ID.ID3;
                            ProcessFormat3(next_byte);
                        }
                        else
                        {
                            Format_ID = FORMAT_ID.ID1;
                            ProcessFormat1(next_byte);
                        }
                        break;

                    case MSG_A1A0_MODE.CARB_MODE:
                        // CARB mode - to be checked & implemented
                        Format_ID = FORMAT_ID.OUT_OF_RANGE;
                        break;

                    case MSG_A1A0_MODE.WITH_ADDRESS_INFO:
                        if ((next_byte & 0x3f) == 0)
                        {
                            Format_ID = FORMAT_ID.ID4;
                            ProcessFormat4(next_byte);
                        }
                        else
                        {
                            Format_ID = FORMAT_ID.ID2;
                            ProcessFormat2(next_byte);
                        }
                        break;

                    case MSG_A1A0_MODE.FUNCTIONAL_ADDRESSING:
                        // Functional Addressing mode are not supported here
                        Format_ID = FORMAT_ID.OUT_OF_RANGE;
                        break;
                    }
                }
                break;

            case FORMAT_ID.ID1:
                bRet = ProcessFormat1(next_byte);
                break;

            case FORMAT_ID.ID2:
                bRet = ProcessFormat2(next_byte);
                break;

            case FORMAT_ID.ID3:
                bRet = ProcessFormat3(next_byte);
                break;

            case FORMAT_ID.ID4:
                bRet = ProcessFormat4(next_byte);
                break;

            default:
                if (next_byte == 0)
                {
                    Format_ID       = FORMAT_ID.NEW;
                    msg_field_index = 0;
                }
                break;
            }
            if (bRet == true)
            {
                SetP3Timer();
            }
            return(bRet);
        }
Exemplo n.º 4
0
        private bool ProcessFormat2(byte next_byte)
        {
            bool bRet = false;

            switch ((MSG_STAGE_FORMAT_02)msg_field_index)
            {
            case MSG_STAGE_FORMAT_02.FMT:
                BlockMessageInProcess.SetFmt(next_byte);
                ExpectedDataListLen = (next_byte & 0x3f) - 1;               // minus SID byte
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                msg_field_index++;
                break;

            case MSG_STAGE_FORMAT_02.TA:
                BlockMessageInProcess.SetTA(next_byte);
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                msg_field_index++;
                break;

            case MSG_STAGE_FORMAT_02.SA:
                BlockMessageInProcess.SetSA(next_byte);
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                msg_field_index++;
                break;

            case MSG_STAGE_FORMAT_02.SID:
                BlockMessageInProcess.SetSID(next_byte);
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                if (ExpectedDataListLen > 0)
                {
                    msg_field_index++;
                }
                else
                {
                    msg_field_index += 2;
                }
                break;

            case MSG_STAGE_FORMAT_02.Data:
                BlockMessageInProcess.AddToDataList(next_byte);
                BlockMessageInProcess.UpdateCheckSum(next_byte);
                if (BlockMessageInProcess.GetDataListLen() >= ExpectedDataListLen)
                {
                    msg_field_index++;
                }
                break;

            case MSG_STAGE_FORMAT_02.CS:
                byte current_checksum = BlockMessageInProcess.GetCheckSum();
                Format_ID       = FORMAT_ID.NEW;
                msg_field_index = 0;
                if (current_checksum == next_byte)
                {
                    bRet = true;
                }
                else
                {
                    bRet = false;
                }
                break;
            }
            return(bRet);
        }