![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
Diff: xDotBridge/src/BaseboardIO.cpp
- Revision:
- 63:e1efbe3402d9
- Parent:
- 62:9751a8504c82
- Child:
- 74:dc969906f1f7
diff -r 9751a8504c82 -r e1efbe3402d9 xDotBridge/src/BaseboardIO.cpp --- a/xDotBridge/src/BaseboardIO.cpp Tue Mar 14 08:32:55 2017 -0600 +++ b/xDotBridge/src/BaseboardIO.cpp Tue Mar 14 09:54:04 2017 -0600 @@ -6,9 +6,9 @@ */ #include "BaseboardIO.h" -#include "MTSLog.h" #include "dot_util.h" // FIXME just need the reference to dot somehow #include "xdot_low_power.h" +#include "MyLog.h" // Original //const float COIL_ON_TIME = 0.030; // 30 ms @@ -64,37 +64,37 @@ uint8_t val; // Setup port expanders if (readInfoFromNVM() == cmdSuccess && !overwriteNvm) { - logInfo("Stored ROM0 Addr: %02x:%02x:%02x:%02x:%02x:%02x:%02x%02x found.", - mNvmObj.mPortExpanderROM0[7], - mNvmObj.mPortExpanderROM0[6], - mNvmObj.mPortExpanderROM0[5], - mNvmObj.mPortExpanderROM0[4], - mNvmObj.mPortExpanderROM0[3], - mNvmObj.mPortExpanderROM0[2], - mNvmObj.mPortExpanderROM0[1], - mNvmObj.mPortExpanderROM0[0]); - logInfo("Stored ROM1 Addr: %02x:%02x:%02x:%02x:%02x:%02x:%02x%02x found.", - mNvmObj.mPortExpanderROM1[7], - mNvmObj.mPortExpanderROM1[6], - mNvmObj.mPortExpanderROM1[5], - mNvmObj.mPortExpanderROM1[4], - mNvmObj.mPortExpanderROM1[3], - mNvmObj.mPortExpanderROM1[2], - mNvmObj.mPortExpanderROM1[1], - mNvmObj.mPortExpanderROM1[0]); - logInfo("BaseboardIO parameters successfully loaded from NVM"); + myLogInfo("Stored ROM0 Addr: %02x:%02x:%02x:%02x:%02x:%02x:%02x%02x found.", + mNvmObj.mPortExpanderROM0[7], + mNvmObj.mPortExpanderROM0[6], + mNvmObj.mPortExpanderROM0[5], + mNvmObj.mPortExpanderROM0[4], + mNvmObj.mPortExpanderROM0[3], + mNvmObj.mPortExpanderROM0[2], + mNvmObj.mPortExpanderROM0[1], + mNvmObj.mPortExpanderROM0[0]); + myLogInfo("Stored ROM1 Addr: %02x:%02x:%02x:%02x:%02x:%02x:%02x%02x found.", + mNvmObj.mPortExpanderROM1[7], + mNvmObj.mPortExpanderROM1[6], + mNvmObj.mPortExpanderROM1[5], + mNvmObj.mPortExpanderROM1[4], + mNvmObj.mPortExpanderROM1[3], + mNvmObj.mPortExpanderROM1[2], + mNvmObj.mPortExpanderROM1[1], + mNvmObj.mPortExpanderROM1[0]); + myLogInfo("BaseboardIO parameters successfully loaded from NVM"); // Check that the ROM Addresses are correct and valid uint8_t portEx0Ctrl, portEx1Ctrl; mPortEx0 = new DS2408(&mOWMaster, mNvmObj.mPortExpanderROM0); mPortEx0->registerReadReliable(0x8D, portEx0Ctrl); // Gets 0xFF if it is not the correct address - logInfo("PortEx0 Control register reads %02X", portEx0Ctrl); + myLogInfo("PortEx0 Control register reads %02X", portEx0Ctrl); mPortEx1 = new DS2408(&mOWMaster, mNvmObj.mPortExpanderROM1); mPortEx1->registerReadReliable(0x8D, portEx1Ctrl); - logInfo("PortEx1 Control register reads %02X", portEx1Ctrl); + myLogInfo("PortEx1 Control register reads %02X", portEx1Ctrl); if ((portEx0Ctrl == 0xFF) || (portEx1Ctrl == 0xFF)) { - logError("Stored port expander ROM check failed. Set EEPROM to defaults."); + myLogError("Stored port expander ROM check failed. Set EEPROM to defaults."); } else { storedROMsGood = true; @@ -106,37 +106,37 @@ // Find ROM address and test which one is which. Requires user // switches to be in known state. if (identifyPortExpanders() != cmdSuccess) { - logError("Error identifying port expanders"); + myLogError("Error identifying port expanders"); return cmdError; } if (writeInfoToNVM() == cmdSuccess) { - logInfo("Baseboard config saved to NVM"); + myLogInfo("Baseboard config saved to NVM"); } else { - logError("Baseboard config failed to save to NVM"); + myLogError("Baseboard config failed to save to NVM"); } mPortEx0 = new DS2408(&mOWMaster, mNvmObj.mPortExpanderROM0); mPortEx0->registerReadReliable(0x8D, val); // Gets 0xFF if it is not the correct address - logInfo("PortEx0 Control register reads %02X", val); + myLogInfo("PortEx0 Control register reads %02X", val); mPortEx1 = new DS2408(&mOWMaster, mNvmObj.mPortExpanderROM1); mPortEx1->registerReadReliable(0x8D, val); - logInfo("PortEx1 Control register reads %02X", val); + myLogInfo("PortEx1 Control register reads %02X", val); } if (sampleUserSwitches() != cmdSuccess) { - logError("Error sampling user switches"); + myLogError("Error sampling user switches"); return cmdError; } // Put relay in known state if (relayNormal() != cmdSuccess) { - logError("Error setting relay during init"); + myLogError("Error setting relay during init"); return cmdError; } ledOff(); - logInfo("Baseboard IO initialization successful"); + myLogInfo("Baseboard IO initialization successful"); return cmdSuccess; } @@ -180,12 +180,12 @@ wait(0.001); // Wait 1 ms if (mPortEx0->pioLogicReliableRead(mPortExpanderVal0) != cmdSuccess) { disableSwitchedIO(); - logError("Error reading port expander 0."); + myLogError("Error reading port expander 0."); return cmdError; } if (mPortEx1->pioLogicReliableRead(mPortExpanderVal1) != cmdSuccess) { disableSwitchedIO(); - logError("Error reading port expander 1."); + myLogError("Error reading port expander 1."); return cmdError; } disableSwitchedIO(); @@ -296,7 +296,7 @@ { uint8_t val; if (mPortEx0 == NULL) { - logError("Error enabling 232. Port expanders not initialized."); + myLogError("Error enabling 232. Port expanders not initialized."); return cmdError; } mPortEx0->pioLogicReliableRead(val); @@ -310,7 +310,7 @@ } if (mPortEx0->pioLogicReliableWrite(val | ~pEx0OutMask) != cmdSuccess) { - logError("Error enabling 232"); + myLogError("Error enabling 232"); return cmdError; } return cmdSuccess; @@ -319,7 +319,7 @@ { uint8_t val; if (mPortEx0 == NULL) { - logError("Error enabling 232 TX. Port expanders not initialized."); + myLogError("Error enabling 232 TX. Port expanders not initialized."); return cmdError; } mPortEx0->pioLogicReliableRead(val); @@ -333,7 +333,7 @@ } if (mPortEx0->pioLogicReliableWrite(val | ~pEx0OutMask) != cmdSuccess) { - logError("Error enabling 232 TX"); + myLogError("Error enabling 232 TX"); return cmdError; } return cmdSuccess; @@ -353,11 +353,11 @@ mNvmObj.fromBytes(data, BASEBOARDIO_NVM_SIZE); delete [] data; if (!mNvmObj.validBaseboardIOFlag()) { - logWarning("Invalid BaseboardIO Flag. Using default values."); + myLogWarning("Invalid BaseboardIO Flag. Using default values."); return cmdError; } else if (!mNvmObj.validBaseboardIORev()) { - logWarning("Invalid BaseboardIO Rev. Using default values."); + myLogWarning("Invalid BaseboardIO Rev. Using default values."); return cmdError; } else { @@ -381,7 +381,7 @@ int i; // Search Bus - logInfo("Starting OneWire Search"); + myLogInfo("Starting OneWire Search"); enableSwitchedIO(); for (int j=0;j<10;j++) { // Try 5 times i=0; @@ -394,7 +394,7 @@ if (result != 1) { break; } - logInfo("ROM Addr: %02x:%02x:%02x:%02x:%02x:%02x:%02x%02x found.", + myLogInfo("ROM Addr: %02x:%02x:%02x:%02x:%02x:%02x:%02x%02x found.", addr[7],addr[6],addr[5],addr[4],addr[3],addr[2],addr[1],addr[0]); if (i == 0) { std::memcpy(mNvmObj.mPortExpanderROM0, addr, sizeof(mNvmObj.mPortExpanderROM0)); @@ -410,9 +410,9 @@ } } - logInfo("Finished OneWire Search"); + myLogInfo("Finished OneWire Search"); if (i != 2) { - logError("Incorrect Number of OneWire devices (Got %d. Expected 2) OneWire port expanders found.", i); + myLogError("Incorrect Number of OneWire devices (Got %d. Expected 2) OneWire port expanders found.", i); return cmdError; } @@ -426,14 +426,14 @@ enableSwitchedIO(); if (mPortEx0->pioLogicReliableRead(mPortExpanderVal0) != cmdSuccess) { - logError("Error during port expander ID. Read failed."); + myLogError("Error during port expander ID. Read failed."); disableSwitchedIO(); delete mPortEx0; delete mPortEx1; return cmdError; } if (mPortEx1->pioLogicReliableRead(mPortExpanderVal1) != cmdSuccess) { - logError("Error during port expander ID. Read failed."); + myLogError("Error during port expander ID. Read failed."); disableSwitchedIO(); delete mPortEx0; delete mPortEx1; @@ -442,16 +442,16 @@ disableSwitchedIO(); if ((mPortExpanderVal0 == 0xFF) and (mPortExpanderVal1 == 0xF0)) { // Luckily got it right - logInfo("ROMS Swap Not Needed."); + myLogInfo("ROMS Swap Not Needed."); } else if ((mPortExpanderVal0 == 0xF0) and (mPortExpanderVal1 == 0xFF)) { // Just need to swap std::memcpy(addr, mNvmObj.mPortExpanderROM0, sizeof(addr)); // Store Orig ROM0 -> addr std::memcpy(mNvmObj.mPortExpanderROM0, mNvmObj.mPortExpanderROM1, sizeof(mNvmObj.mPortExpanderROM0)); // Store Orig ROM1 -> ROM0 std::memcpy(mNvmObj.mPortExpanderROM1, addr, sizeof(mNvmObj.mPortExpanderROM1)); // Store Orig ROM0 (addr) -> ROM1 - logInfo("Swapped ROMS."); + myLogInfo("Swapped ROMS."); } else { - logError("Error during port expander ID. Port expanders not in " + myLogError("Error during port expander ID. Port expanders not in " "expected states (0xFF and 0xF0). Check user switches. Got %02X and %02X", mPortExpanderVal0, mPortExpanderVal1); delete mPortEx0; @@ -476,7 +476,7 @@ val |= pEx1RlyA; // Turn Relay A off val |= pEx1RlyB; // Turn Relay B off mPortEx1->pioLogicReliableWrite(val | ~pEx1OutMask); // Write a non assert value just to try to overcome an error - logError ("Error turning on coil. Turning both coils off."); + myLogError ("Error turning on coil. Turning both coils off."); return cmdError; } @@ -487,7 +487,7 @@ if (mPortEx1->pioLogicReliableWrite(val | ~pEx1OutMask) != cmdSuccess) { mPortEx1->pioLogicReliableWrite(val | ~pEx1OutMask); - logError ("Error turning off coils. Trying again."); + myLogError ("Error turning off coils. Trying again."); return cmdError; } @@ -504,7 +504,7 @@ val |= pEx1RlyA; // Turn Relay A off val |= pEx1RlyB; // Turn Relay B off mPortEx1->pioLogicReliableWrite(val | ~pEx1OutMask); // Write a non assert value just to try to overcome an error - logError ("Error turning on coil. Turning both coils off."); + myLogError ("Error turning on coil. Turning both coils off."); return cmdError; } @@ -515,7 +515,7 @@ if (mPortEx1->pioLogicReliableWrite(val | ~pEx1OutMask) != cmdSuccess) { mPortEx1->pioLogicReliableWrite(val | ~pEx1OutMask); - logError ("Error turning off coils. Trying again."); + myLogError ("Error turning off coils. Trying again."); return cmdError; }