async protected static void ReadThread(BluetoothService_test a, System.IO.Stream stm) { while (!cts.IsCancellationRequested) { try { byte[] at = new byte[1024]; Task <int> readTask = stm.ReadAsync(at, 0, 1024); using (cts.Token.Register(() => stm.Close())) { readTask.Wait(cts.Token); int iRead = await readTask; BTMessage msg = new BTMessage(); msg.type = 0; msg.length = iRead; msg.data = at; a.RecvMessage(a, msg); } } catch (System.OperationCanceledException) { //Handle the cancelled task. string text = int.MaxValue.ToString(); } catch (System.Exception e) { string text = e.ToString(); } } }
private void phasingMSRdata(byte valData) { byte val1 = 0x02; byte val2 = valData; /* * valData 별 MSR 타입과 데이터 길이 * 1. 0x43 * a. 12T = prefix(2) + other_prefix(3) + data(76) + postfix(4) = 2 + 83 * b. 23T = prefix(2) + other_prefix(3) + data(37) + postfix(4) = 2 + 44 * c. 123T = prefix(2) + other_prefix(3) + data(76) + postfix(4) = 2 + 83 * * 2. 0x44 * a. 12T = prefix(2) + other_prefix(3) + data(37) + postfix(3) = 2 + 43 * b. 23T = prefix(2) + other_prefix(3) + data(104) + postfix(3) = 2 + 110 * c. 123T = prefix(2) + other_prefix(3) + data(37) + postfix(3) = 2 + 43 * * 3. 0x45 * a. 12T = prefix(2) + other_prefix(4) + data(76) + gap(1) + data(37) + postfix(4) = 2 + 122 * b. 23T = prefix(2) + other_prefix(4) + data(37) + gap(1) + data(104) + postfix(4) = 2 + 150 * c. 123T = prefix(2) + other_prefix(4) + data(76) + gap(1) + data(37) + postfix(4) = 2 + 122 * * 4. 0x46 (123T only) * a. 123T = prefix(2) + other_prefix(4) + data(76) + gap(1) + data(37) + gap(1) + data(104) + postfix(4) + = 2 + 227 * * 5. 0x47 (123T only) * a. 123T = prefix(2) + other_prefix(3) + data(104) + postfix(3) = 2 + 110 */ byte[] containedData = new byte[2 + que.getUseSpace()]; containedData[0] = val1; containedData[1] = val2; int cnt = que.getUseSpace(); byte[] test = que.DeQueue(cnt); Buffer.BlockCopy(test, 0, containedData, 2, test.Length); BTMessage data = new BTMessage(); data.type = BTMessage.MSR_Response_Type; data.length = containedData.Length; data.data = containedData; RecvMessage(this, data); }
//정상 파싱 처리하지 않는 데이터 private void passingUnKownData(byte[] val1) { byte[] containedData = new byte[val1.Length + que.getUseSpace()]; Buffer.BlockCopy(val1, 0, containedData, 0, val1.Length); int cnt = que.getUseSpace(); byte[] test = que.DeQueue(cnt); Buffer.BlockCopy(test, 0, containedData, val1.Length, test.Length); BTMessage data = new BTMessage(); data.type = BTMessage.UnKnown_Response_Type; data.length = containedData.Length; data.data = containedData; RecvMessage(this, data); }