(27.02.2021, 11:50)MHz000 schrieb: Beim googlen nach dbgprint bekomme ich nur Antworten zu Dbgprint was ja wohl was anderes ist.
Kannst du mir bitte einen Tipp geben. Vielen Dank!
Hallo,
googlen brauchst Du gar nicht, die Funktion dbgprint stammt vom Autor des ESP32Radios selbst, in main.cpp findet man die Deklaration und Definition:
PHP-Code:
//**************************************************************************************************
// D B G P R I N T *
//**************************************************************************************************
// Send a line of info to serial output. Works like vsprintf(), but checks the DEBUG flag. *
// Print only if DEBUG flag is true. Always returns the formatted string. *
//**************************************************************************************************
char* dbgprint ( const char* format, ... )
{
static char sbuf[DEBUG_BUFFER_SIZE] ; // For debug lines
va_list varArgs ; // For variable number of params
va_start ( varArgs, format ) ; // Prepare parameters
vsnprintf ( sbuf, sizeof(sbuf), format, varArgs ) ; // Format the message
va_end ( varArgs ) ; // End of using parameters
if ( DEBUG ) // DEBUG on?
{
Serial.print ( "D: " ) ; // Yes, print prefix
Serial.println ( sbuf ) ; // and the info
}
return sbuf ; // Return stored string
}
Die Anwendung dieser Funktion ist eigentlich sehr logisch, ich zitiere hier mal zwei Aufrufe aus dem Quellcode des Radios:
PHP-Code:
// print the list of networks seen:
dbgprint ( "Number of available networks: %d",numSsid ) ;
und
PHP-Code:
dbgprint ( "%2d - %-25s Signal: %3d dBm, Encryption %4s, %s",
i + 1, WiFi.SSID(i).c_str(), WiFi.RSSI(i),
getEncryptionType ( encryption ),
acceptable ) ;
Durchschaut? Du kannst also einfach eine Zeichenkette ausgeben, aber auch eine beliebige Liste von Variablen, die durch einen Formatstring sogar noch zurechtgestutzt werden kann.
Wenn es der Empfänger bis in die isr_IR() schafft, ist das ja schon mal was. Warum kommt es dennoch nicht zur Anzeige eines rawcodes auch wenn wir ein Debugbuild haben? Nun schauen wir uns die Sache mal an.
Die Ausgabe des rawcodes wird ja in der scanIR()-Funktion erledigt, hier nochmal der Quellecode der scanIR():
Code:
//**************************************************************************************************
// S C A N I R *
//**************************************************************************************************
// See if IR input is available. Execute the programmed command. *
//**************************************************************************************************
void scanIR()
{
char mykey[20] ; // For numerated key
String val ; // Contents of preference entry
const char* reply ; // Result of analyzeCmd
if ( ir_value ) // Any input?
{
sprintf ( mykey, "ir_%04X", ir_value ) ; // Form key in preferences
if ( nvssearch ( mykey ) )
{
val = nvsgetstr ( mykey ) ; // Get the contents
dbgprint ( "IR code %04X received. Will execute %s",
ir_value, val.c_str() ) ;
reply = analyzeCmd ( val.c_str() ) ; // Analyze command and handle it
dbgprint ( reply ) ; // Result for debugging
}
else
{
dbgprint ( "IR code %04X received, but not found in preferences! Timing %d/%d",
ir_value, ir_0, ir_1 ) ;
}
ir_value = 0 ; // Reset IR code received
}
}
Damit wir überhaupt in den Codebereich kommen, wo eine Ausgabe erzeugt wird, müssen wir an
if ( ir_value ) // Any input?
vorbei. Das passiert wenn ir_value true/wahr ist, also einen Wert ungleich 0 annimmt. Anmerkung: Wir sehen ja auch das ir_value nach Durchlauf immer wieder auf 0 gesetzt wird.
Wo wird die globale Variable ir_value also auf true gesetzt? Klar, in der Interrupt Service Routine isr_IR(), also da wo Du mit deinem Empfänger schon reinkommst. Schauen wir uns den Quellcode der isr_IR() nochmal an:
Code:
void IRAM_ATTR isr_IR()
{
sv uint32_t t0 = 0 ; // To get the interval
sv uint32_t ir_locvalue = 0 ; // IR code
sv int ir_loccount = 0 ; // Length of code
uint32_t t1, intval ; // Current time and interval since last change
uint32_t mask_in = 2 ; // Mask input for conversion
uint16_t mask_out = 1 ; // Mask output for conversion
t1 = micros() ; // Get current time
intval = t1 - t0 ; // Compute interval
t0 = t1 ; // Save for next compare
if ( ( intval > 300 ) && ( intval < 800 ) ) // Short pulse?
{
ir_locvalue = ir_locvalue << 1 ; // Shift in a "zero" bit
ir_loccount++ ; // Count number of received bits
ir_0 = ( ir_0 * 3 + intval ) / 4 ; // Compute average durartion of a short pulse
}
else if ( ( intval > 1400 ) && ( intval < 1900 ) ) // Long pulse?
{
ir_locvalue = ( ir_locvalue << 1 ) + 1 ; // Shift in a "one" bit
ir_loccount++ ; // Count number of received bits
ir_1 = ( ir_1 * 3 + intval ) / 4 ; // Compute average durartion of a short pulse
}
else if ( ir_loccount == 65 ) // Value is correct after 65 level changes
{
while ( mask_in ) // Convert 32 bits to 16 bits
{
if ( ir_locvalue & mask_in ) // Bit set in pattern?
{
ir_value |= mask_out ; // Set set bit in result
}
mask_in <<= 2 ; // Shift input mask 2 positions
mask_out <<= 1 ; // Shift output mask 1 position
}
ir_loccount = 0 ; // Ready for next input
}
else
{
ir_locvalue = 0 ; // Reset decoding
ir_loccount = 0 ;
}
}
ir_value wird hier in diesem Teil gesetzt, wenn folgende Bedingungen wahr sind:
Code:
else if ( ir_loccount == 65 ) // Value is correct after 65 level changes
{
while ( mask_in ) // Convert 32 bits to 16 bits
{
if ( ir_locvalue & mask_in ) // Bit set in pattern?
{
ir_value |= mask_out ; // Set set bit in result
ir_loccount muss also 65 sein, es muss also ein IR-Code mit der Länge von 65 bit empfangen wurden sein. Ist das der Fall? Stimmen die Zeiten für die Low/High-Pulse, so dass ir_loccount überhaupt incrementiert wird? Passen die Pulszeiten der Fernbedienung überhaupt zum Quellcode oder müssen die Pulszeiten vielleicht für das von deiner Fernbedienung benutzte Protokoll angepasst werden? Es gibt da ja haufenweise Protokolle die von Fernbedienungen "gesprochen" werden, hier eine Übersicht:
https://www.mikrocontroller.net/articles/IRMP
Erst wenn das alles passt, wird ein Flag gesetzt und scanIR erzeugt eine Ausgabe eines rawcodes deiner Fernbedienung auf der seriellen Schnittstelle bzw. Console.
Viele Grüße
B45
Ansprechpartner für Umbau oder Modernisierung von Röhrenradios mittels SDR,DAB+,Internetradio,Firmwareentwicklung.
Unser Open-Source Softwarebaukasten für Internetradios gibt es auf der Github-Seite! Projekt: BM45/iRadio (Google "github BM45/iRadio")