yaesufc-40control
Differences
This shows you the differences between two versions of the page.
| yaesufc-40control [2026/07/15 03:35] – created admin | yaesufc-40control [2026/07/15 04:01] (current) – admin | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| <file C++ fc40diagnostics.ino> | <file C++ fc40diagnostics.ino> | ||
| /* | /* | ||
| - | * FC-40 / Yaesu-protocol tuner probe & listener | + | * FC-40 / Yaesu-protocol |
| - | * Target: | + | * ------------------------------------------------------ |
| + | * Target: | ||
| + | | ||
| * | * | ||
| - | | + | |
| - | | + | |
| * | * | ||
| * WIRING (uses FC-40 SERVICE MANUAL pin numbers): | * WIRING (uses FC-40 SERVICE MANUAL pin numbers): | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| * | * | ||
| - | | + | |
| - | | + | |
| - | | + | |
| * | * | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| * | * | ||
| * CONSOLE COMMANDS (type in Serial Monitor, newline to send): | * CONSOLE COMMANDS (type in Serial Monitor, newline to send): | ||
| Line 31: | Line 31: | ||
| | | ||
| | | ||
| - | | + | |
| | | ||
| - | | + | |
| * | * | ||
| - | | + | |
| - | | + | * Bytes we transmit print without brackets. |
| + | * | ||
| + | * ------------------------------------------------------ | ||
| + | * Acknowledgement: | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | * ------------------------------------------------------ | ||
| */ | */ | ||
| - | #include < | + | // ---- optional indicator |
| - | + | #define USE_LED_A1 | |
| - | // ---- pins ---- | + | const uint8_t |
| - | const uint8_t PIN_TUNER_RX = 10; // <- tuner DATA OUT | + | |
| - | const uint8_t | + | |
| - | const uint8_t PIN_GREEN | + | |
| - | const uint8_t PIN_RED | + | |
| - | const uint8_t PIN_BUTTON | + | |
| - | + | ||
| - | SoftwareSerial tuner(PIN_TUNER_RX, | + | |
| // ---- protocol bytes ---- | // ---- protocol bytes ---- | ||
| Line 61: | Line 62: | ||
| const uint16_t WAKE_GAP_MS = 50; // observed ~50ms between 0xFF and command body | const uint16_t WAKE_GAP_MS = 50; // observed ~50ms between 0xFF and command body | ||
| - | // ---- timestamp clock (mirrors the WA2FZW logger) | + | // ---- timestamp clock ---- |
| uint32_t t0 = 0; | uint32_t t0 = 0; | ||
| uint32_t lastActivity = 0; | uint32_t lastActivity = 0; | ||
| const uint32_t IDLE_RESET_MS = 14000; | const uint32_t IDLE_RESET_MS = 14000; | ||
| - | // ---- A1 tracking | + | // ---- A1 tracking |
| - | uint8_t | + | uint8_t |
| - | uint32_t | + | |
| - | // ---- green LED one-shot ---- | + | // ---- LED one-shot ---- |
| - | uint32_t | + | uint32_t |
| char lineBuf[48]; | char lineBuf[48]; | ||
| Line 78: | Line 78: | ||
| // ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
| void setup() { | void setup() { | ||
| - | Serial.begin(115200); | + | Serial.begin(115200); |
| - | | + | |
| + | Serial1.begin(4800, SERIAL_8N1); | ||
| - | pinMode(PIN_GREEN, | + | #if USE_LED_A1 |
| - | pinMode(PIN_RED, | + | pinMode(PIN_LED, OUTPUT); |
| - | | + | |
| + | #endif | ||
| - | Serial.println(F(" | + | Serial.println(F(" |
| - | Serial.println(F(" | + | Serial.println(F(" |
| Serial.println(F(" | Serial.println(F(" | ||
| resetClock(); | resetClock(); | ||
| Line 93: | Line 95: | ||
| // ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
| void loop() { | void loop() { | ||
| - | drainTuner(); | + | drainTuner(); |
| - | handleConsole(); | + | handleConsole(); |
| - | | + | |
| - | serviceLeds(); | + | idleReset(); |
| - | idleReset(); | + | |
| } | } | ||
| // ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
| - | // Stamp helper: prints " | ||
| uint32_t stamp() { | uint32_t stamp() { | ||
| uint32_t now = millis(); | uint32_t now = millis(); | ||
| Line 124: | Line 124: | ||
| // ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
| - | // Read everything | + | // Everything from the tuner prints |
| void drainTuner() { | void drainTuner() { | ||
| - | while (tuner.available()) { | + | while (Serial1.available()) { |
| - | uint8_t b = tuner.read(); | + | uint8_t b = Serial1.read(); |
| uint32_t ts = stamp(); | uint32_t ts = stamp(); | ||
| Line 140: | Line 140: | ||
| case RESP_A1: | case RESP_A1: | ||
| a1Count++; | a1Count++; | ||
| - | | + | // AUTO mode: a single A1 means the cycle STARTED, not that it |
| - | | + | // succeeded. COMMAND mode: A1 #1 = key now, A1 #2 = done/unkey. |
| - | // "cycle STARTED", not "succeeded" - do not read green as "done". | + | |
| - | | + | |
| if (a1Count == 1) | if (a1Count == 1) | ||
| - | Serial.print(F(" | + | Serial.print(F(" |
| else | else | ||
| Serial.print(F(" | Serial.print(F(" | ||
| break; | break; | ||
| // case RESP_FAIL: | // case RESP_FAIL: | ||
| - | // | ||
| // | // | ||
| // | // | ||
| Line 161: | Line 159: | ||
| // ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
| - | void greenOn(uint32_t ms) { | + | void ledBlip(uint32_t ms) { |
| - | digitalWrite(PIN_GREEN, HIGH); | + | #if USE_LED_A1 |
| - | | + | digitalWrite(PIN_LED, HIGH); |
| + | | ||
| + | #else | ||
| + | (void)ms; | ||
| + | #endif | ||
| } | } | ||
| - | void serviceLeds() { | + | void serviceLed() { |
| - | if (greenOffAt | + | #if USE_LED_A1 |
| - | digitalWrite(PIN_GREEN, LOW); | + | if (ledOffAt |
| - | | + | digitalWrite(PIN_LED, LOW); |
| + | | ||
| } | } | ||
| + | #endif | ||
| } | } | ||
| // ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||
| - | // Transmit helpers. | + | // Bytes we send echo to the console WITHOUT brackets. |
| void txByte(uint8_t b) { | void txByte(uint8_t b) { | ||
| - | | + | |
| uint32_t ts = stamp(); | uint32_t ts = stamp(); | ||
| char buf[24]; | char buf[24]; | ||
| Line 182: | Line 186: | ||
| } | } | ||
| - | // Send 0xFF, wait the observed gap, then a 3-byte command body. | + | // 0xFF, wait the observed gap, then a 3-byte command body. |
| void sendCommand(uint8_t op, uint8_t hi, uint8_t lo) { | void sendCommand(uint8_t op, uint8_t hi, uint8_t lo) { | ||
| txByte(WAKEUP); | txByte(WAKEUP); | ||
| - | | + | |
| delay(WAKE_GAP_MS); | delay(WAKE_GAP_MS); | ||
| txByte(op); | txByte(op); | ||
| txByte(hi); | txByte(hi); | ||
| txByte(lo); | txByte(lo); | ||
| - | | + | |
| } | } | ||
| - | // MHz (float) | + | // MHz -> two BCD bytes at 10 kHz resolution. |
| - | // | + | // |
| - | // | + | // |
| - | // | + | // 14.25 -> 0x14 0x25 |
| bool mhzToBcd(float mhz, uint8_t &hi, uint8_t &lo) { | bool mhzToBcd(float mhz, uint8_t &hi, uint8_t &lo) { | ||
| long units = lround(mhz * 100.0); | long units = lround(mhz * 100.0); | ||
| Line 209: | Line 213: | ||
| } | } | ||
| - | // ------------------------------------------------------------------- | + | // Mimic a radio' |
| - | void handleButton() { | + | // Watch for: [A1] (key here) ... [A0] ... [A1] (done). |
| - | static uint32_t lastPress = 0; | + | |
| - | static bool prev = HIGH; | + | |
| - | bool now = digitalRead(PIN_BUTTON); | + | |
| - | if (prev == HIGH && now == LOW && (millis() - lastPress) > 250) { | + | |
| - | lastPress = millis(); | + | |
| - | Serial.println(F(" | + | |
| - | commandedProbe(14.25); | + | |
| - | } | + | |
| - | prev = now; | + | |
| - | } | + | |
| - | + | ||
| - | // Mimic the radio' | + | |
| - | // You watch for: [A1] (key here) ... [A0] ... [A1] (done). | + | |
| void commandedProbe(float mhz) { | void commandedProbe(float mhz) { | ||
| uint8_t hi, lo; | uint8_t hi, lo; | ||
| Line 229: | Line 220: | ||
| a1Count = 0; | a1Count = 0; | ||
| sendCommand(OP_DISABLE, | sendCommand(OP_DISABLE, | ||
| - | delay(400); | + | delay(400); |
| sendCommand(OP_TUNE, | sendCommand(OP_TUNE, | ||
| } | } | ||
| Line 252: | Line 243: | ||
| if (*s == 0) return; | if (*s == 0) return; | ||
| - | if (!strcmp(s, " | + | if (!strcmp(s, " |
| - | if (!strcmp(s, " | + | if (!strcmp(s, " |
| - | if (!strcmp(s, " | + | if (!strcmp(s, " |
| - | if (!strcmp(s, " | + | if (!strcmp(s, " |
| if (!strncmp(s, | if (!strncmp(s, | ||
yaesufc-40control.txt · Last modified: by admin
