int main(void) { // Start by running the main initialization init(); // Record the current tick count for time-keeping ticks_t start = timer_clock(); #if MP1_USE_TX_QUEUE ticks_t frameQueued = 0; #endif // Go into ye good ol' infinite loop while (1) { // First we instruct the protocol to check for // incoming data mp1Poll(&mp1); // If there was actually some data waiting for us // there, let's se what it tastes like :) 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 < MP1_MAX_DATA_SIZE) && (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 < MP1_MAX_DATA_SIZE-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; } } // Check whether we should send data in our serial buffer if (sertx) { #if MP1_USE_TX_QUEUE mp1QueueFrame(&mp1, serialBuffer, serialLen); frameQueued = timer_clock(); sertx = false; serialLen = 0; #else // Wait until incoming packets are done if (!mp1CarrierSense(&mp1)) { // And then send the data mp1Send(&mp1, serialBuffer, serialLen); // Reset the transmission flag and length counter sertx = false; serialLen = 0; } #endif } #if MP1_USE_TX_QUEUE // We first wait a little to see if more // frames are coming in. if (timer_clock() - frameQueued > ms_to_ticks(MP1_QUEUE_TX_WAIT)) { if (!ser_available(&ser) && !mp1CarrierSense(&mp1)) { // And if not, we send process the frame // queue if possible. mp1ProcessQueue(&mp1); } } #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; }