send the second message as a response (instead of after a fixed delay) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 20 Dec 2020 01:00:15 +0100
branchv_0
changeset 7889b4b8737bd
parent 6 bddcf2bf29f2
child 8 87dfa7c89294
send the second message as a response (instead of after a fixed delay)
DJMFix.cpp
     1.1 --- a/DJMFix.cpp	Sat Dec 19 23:59:39 2020 +0100
     1.2 +++ b/DJMFix.cpp	Sun Dec 20 01:00:15 2020 +0100
     1.3 @@ -119,7 +119,10 @@
     1.4  		std::cerr << "DJMFixImpl::receive(): size = " << midiMessage.size() << " data = " << toString(midiMessage) << std::endl; // TODO: do not mess STDIO
     1.5  		std::lock_guard<std::recursive_mutex> lock(midiMutex);
     1.6  
     1.7 -		if (midiMessage.size() == 54 && midiMessage[9] == 0x13 && midiMessage[33] == 0x04 && midiMessage[43] == 0x03) {
     1.8 +
     1.9 +		if (midiMessage.size() == 12 && midiMessage[9] == 0x11) {
    1.10 +			send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x12, 0x2a, 0x01, 0x0b, 0x50, 0x69, 0x6f, 0x6e, 0x65, 0x65, 0x72, 0x44, 0x4a, 0x02, 0x0b, 0x72, 0x65, 0x6b, 0x6f, 0x72, 0x64, 0x62, 0x6f, 0x78, 0x03, 0x12, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0xf7});
    1.11 +		} else if (midiMessage.size() == 54 && midiMessage[9] == 0x13 && midiMessage[33] == 0x04 && midiMessage[43] == 0x03) {
    1.12  			Bytes hash1(midiMessage.begin() + 35, midiMessage.begin() + 35 + 8);
    1.13  			Bytes seed2(midiMessage.begin() + 45, midiMessage.begin() + 45 + 8);
    1.14  			hash1 = normalize(hash1);
    1.15 @@ -146,8 +149,6 @@
    1.16  
    1.17  		// TODO: methods for parsing and constructing messages from parts (TLV)
    1.18  		send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x50, 0x01, 0xf7});
    1.19 -		std::this_thread::sleep_for(std::chrono::milliseconds(30)); // TODO: wait until we got the response
    1.20 -		send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x12, 0x2a, 0x01, 0x0b, 0x50, 0x69, 0x6f, 0x6e, 0x65, 0x65, 0x72, 0x44, 0x4a, 0x02, 0x0b, 0x72, 0x65, 0x6b, 0x6f, 0x72, 0x64, 0x62, 0x6f, 0x78, 0x03, 0x12, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0xf7});
    1.21  
    1.22  		keepAliveThread = std::thread(&DJMFixImpl::run, this);
    1.23  		running = true;