int main (void) { init(); #if SERIAL_PROTOCOL == PROTOCOL_KISS while (true) { ax25_poll(&AX25); if (serial_available(0)) { char sbyte = uart0_getchar_nowait(); kiss_serialCallback(sbyte); } } #endif #if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL ticks_t start = timer_clock(); while (1) { ax25_poll(&AX25); if (!sertx && serial_available(0)) { sbyte = uart0_getchar_nowait(); #if SERIAL_DEBUG if ((serialLen < AX25_MAX_FRAME_LEN) && (sbyte != 10)) { serialBuffer[serialLen] = sbyte; serialLen++; } else { sertx = true; } #else if (serialLen < AX25_MAX_FRAME_LEN-1) { serialBuffer[serialLen] = sbyte; serialLen++; } else { serialBuffer[serialLen] = sbyte; serialLen++; sertx = true; } start = timer_clock(); #endif } else { if (!SERIAL_DEBUG && serialLen > 0 && timer_clock() - start > ms_to_ticks(TX_MAXWAIT)) { sertx = true; } } if (sertx) { ss_serialCallback(serialBuffer, serialLen, &AX25); sertx = false; serialLen = 0; } } #endif return(0); }
int main(void) { // Start by running the main initialization init(); // Record the current tick count for time-keeping ticks_t start = timer_clock(); // Go into ye good ol' infinite loop while (1) { // First we instruct the protocol to check for // incoming data ax25_poll(&ax25); // Poll for incoming serial data if (!sertx && ser_available(&ser)) { // We then read a byte from the serial port. // Notice that we use "_nowait" since we can't // have this blocking execution until a byte // comes in. sbyte = ser_getchar_nowait(&ser); // If SERIAL_DEBUG is specified we'll handle // serial data as direct human input and only // transmit when we get a LF character #if SERIAL_DEBUG // If we have not yet surpassed the maximum frame length // and the byte is not a "transmit" (newline) character, // we should store it for transmission. if ((serialLen < CONFIG_AX25_FRAME_BUF_LEN) && (sbyte != 10)) { // Put the read byte into the buffer; serialBuffer[serialLen] = sbyte; // Increment the read length counter serialLen++; } else { // If one of the above conditions were actually the // case, it means we have to transmit, se we set // transmission flag to true. sertx = true; } #else // Otherwise we assume the modem is running // in automated mode, and we push out data // as it becomes available. We either transmit // immediately when the max frame length has // been reached, or when we get no input for // a certain amount of time. if (serialLen < CONFIG_AX25_FRAME_BUF_LEN-1) { // Put the read byte into the buffer; serialBuffer[serialLen] = sbyte; // Increment the read length counter serialLen++; } else { // If max frame length has been reached // we need to transmit. serialBuffer[serialLen] = sbyte; serialLen++; sertx = true; } start = timer_clock(); #endif } else { if (!SERIAL_DEBUG && serialLen > 0 && timer_clock() - start > ms_to_ticks(TX_MAXWAIT)) { sertx = true; } } if (sertx) { ss_serialCallback(serialBuffer, serialLen, &ser, &ax25); sertx = false; serialLen = 0; } } return 0; }