MCPcopy Create free account
hub / github.com/aster94/Keyword-Protocol-2000 / configureKline

Method configureKline

src/KWP2000.cpp:1900–2011  ·  view source on GitHub ↗

* @brief Configure the K-Line behaviour from the keybytes received by the ECU */

Source from the content-addressed store, hash-verified

1898 * @brief Configure the K-Line behaviour from the keybytes received by the ECU
1899 */
1900void KWP2000::configureKline()
1901{
1902 // get the key bytes
1903 if (_response[_response_data_start + 2] != 0x8F)
1904 {
1905 setError(EE_CONFIG);
1906 }
1907
1908 uint16_t key_bytes = _response[_response_data_start + 2] << 8 | _response[_response_data_start + 1];
1909
1910 // length byte
1911 uint8_t AL0 = bitRead(key_bytes, 0);
1912 uint8_t AL1 = bitRead(key_bytes, 1);
1913 if (AL1 == 1 && AL0 == 1)
1914 {
1915 // both are possible, so choose the faster one
1916 _use_length_byte = false;
1917 }
1918 else if (AL1 == 1 && AL0 == 0)
1919 {
1920 // length byte must be present
1921 _use_length_byte = true;
1922 }
1923 else if (AL1 == 0 && AL0 == 1)
1924 {
1925 // length byte not needed
1926 _use_length_byte = false;
1927 }
1928
1929 // target and source
1930 uint8_t HB0 = bitRead(key_bytes, 2);
1931 uint8_t HB1 = bitRead(key_bytes, 3);
1932 if (HB1 == 1 && HB0 == 1)
1933 {
1934 // both are possible, so choose the faster one
1935 _use_target_source_address = false;
1936 }
1937 else if (HB1 == 1 && HB0 == 0)
1938 {
1939 // target and source address bytes must be present
1940 _use_target_source_address = true;
1941 }
1942 else if (HB1 == 0 && HB0 == 1)
1943 {
1944 // target and source address bytes not needed
1945 _use_target_source_address = false;
1946 }
1947
1948 // timing
1949 uint8_t TP0 = bitRead(key_bytes, 4);
1950 uint8_t TP1 = bitRead(key_bytes, 5);
1951 if (TP1 == 1 && TP0 == 1)
1952 {
1953 setError(EE_CONFIG);
1954 }
1955 else if (TP1 == 1 && TP0 == 0)
1956 {
1957 _timing_parameter = true; // normal

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected