//GAVE UP ON THIS FOR NOW. WOKWI apparently doesn't allow two MCUs to be simulated at same time
notImplementedException("Can't simulate multiple MCU's with WOKWI");
#define PRINT_SERVER_DEBUG_STATEMENTS
#define PRINT_CLIENT_DEBUG_STATEMENTS
#define IS_SERVER_GPIO_PIN 0
#define IS_CLIENT_GPIO_PIN 1
#define SHOULD_READ_PIN 2
#define CAN_TRANSMIT_PIN 3
#define SERVER_CAN_CLIENT_1_TRANSMIT 4
#define SERVER_CAN_CLIENT_2_TRANSMIT 5
void printDebug(char* debugMessage)
{
Serial.println(debugMessage);;
}
void printDebugFreeHeap()
{
//These system calls maybe should be put into interrupt handler (ISR).
//Pretty new to that so will need to research but don't think Serial.println should be used in ISRs.
//free stack not sure what the ESP.systemFunction equivalent of uxTaskGetStackHighWaterMark
//is for free stack memroy and intellisense not working in this web IDE
Serial.printf("DEBUG: Free Stack: %d\n", uxTaskGetStackHighWaterMark(NULL));
Serial.printf("DEBUG: Free Heap: %d\n", ESP.getFreeHeap());
}
void printServerDebug(char* debugMessage)
{
#ifdef PRINT_SERVER_DEBUG_STATEMENTS
printDebug(debugMessage);
#endif
}
void initializeServer()
{
printServerDebug("START initializeServer");
printServerDebug("FINISH initializeServer");
}
void printClientDebug(char* debugMessage)
{
#ifdef PRINT_CLIENT_DEBUG_STATEMENTS
printDebug(debugMessage);
#endif
}
void initializeClient()
{
printClientDebug("START initializeClient");
printClientDebug("FINISH initializeClient");
}
bool isServer = false;
bool isClient = false;
void setup()
{
Serial.begin(115200);
pinMode(IS_SERVER_GPIO_PIN, INPUT);
pinMode(IS_CLIENT_GPIO_PIN, INPUT);
delay(100);
if(digitalRead(IS_SERVER_GPIO_PIN) == HIGH)
{
isServer = true;
}
if(digitalRead(IS_CLIENT_GPIO_PIN) == HIGH)
{
isClient = true;
}
if(isServer)
{
initializeServer();
}
if(isClient)
{
initializeClient();
}
}
void loop()
{
//printDebugFreeHeap();
delay(10); // this speeds up the simulation
}