void DumpPacket(void) { int i, j; if (!DebugModeEnabled) return; Debug_Print("(Protocol = 0x"); Debug_PrintHex(PacketProtocol / 256); Debug_PrintHex(PacketProtocol & 255); Debug_Print("):\r\n"); for (i = 0; i < uip_len; i += 16) { Debug_PrintHex(i / 256); Debug_PrintHex(i & 255); Debug_Print(": "); for (j = 0; j < 16; j++) { if ((i + j) >= uip_len) break; Debug_PrintHex(*(uip_buf + i + j)); Debug_PrintChar(' '); } Debug_Print("\r\n "); for (j = 0; j < 16; j++) { if ((i + j) >= uip_len) break; if (*(uip_buf + i + j) >= 0x20 && *(uip_buf + i + j) <= 0x7e) { Debug_PrintChar(' '); Debug_PrintChar(*(uip_buf + i + j)); Debug_PrintChar(' '); } else Debug_Print(" . "); } Debug_Print("\r\n"); } }
// Read the dial commands and send them to the modem. Wait for the expected response then move on to the next command. // Returns true if the last dial command has been processed. static bool LinkManagement_DialConnection(const char** DialCommands) { static char* ResponsePtr = NULL; char* CommandPtr = NULL; static uint8_t CharsMatched = 0; char c; if (USB_HostState != HOST_STATE_Configured) return false; while (!RingBuffer_IsEmpty(&Modem_ReceiveBuffer)) // Read back the response { c = RingBuffer_Remove(&Modem_ReceiveBuffer); Debug_PrintChar(c); if (c == *(ResponsePtr + CharsMatched)) // Match the response character by character with the expected response CharsMatched++; else CharsMatched = 0; if (CharsMatched != 0 && CharsMatched == strlen(ResponsePtr)) // Look for the expected response { DialSteps += 2; // Move on to the next dial command CharsMatched = 0; } } if (SystemTicks > 100) // Space each command by 1 second { CommandPtr = (char*)DialCommands[DialSteps]; ResponsePtr = (char*)DialCommands[DialSteps + 1]; if (CommandPtr == NULL || ResponsePtr == NULL) // No more dial commands { DialSteps = 0; return true; // Finished dialling } SystemTicks = 0; Debug_Print("Send: "); Debug_Print(CommandPtr); Debug_Print("(Expect: "); Debug_Print(ResponsePtr); Debug_Print(")\r\n"); while (*CommandPtr) RingBuffer_Insert(&Modem_SendBuffer, *(CommandPtr++)); // Send the command to the modem } return false; // Haven't finished dialling }
void TCPIP_TCPIPTask(void) { if (timer_expired(&Periodic_Timer)) { timer_reset(&Periodic_Timer); Debug_PrintChar('*'); for (uint8_t i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if (uip_len > 0) // If the above function invocation resulted in data that should be sent out on the network, network_send(IP); //the global variable uip_len is set to a value > 0. } } }
void Debug_PrintLn(char* c){ Debug_PrintChar(c); Debug_PrintChar("\n"); }