Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.76 KB | None | 0 0
  1. //--------------------------------------------------------------------------------------
  2. //        Robert Worland: 08011047       Luke Gee: 09018018
  3. //        Date: 03/10
  4. //        10 char messaging system
  5. //--------------------------------------------------------------------------------------
  6. package worksheet1;
  7.  
  8. public class JavaLan {
  9.  
  10.   private static int pendindex = 0;
  11.   private static SerialPortHandler sio;
  12.   private static Term terminal;
  13.   private static final int LOGIN = 0,
  14.           ADDRPENDING = 1,
  15.           MENU = 2,
  16.           GETADDR = 3,
  17.           INPUTMESS = 4;
  18.   private static int kindex;
  19.   private static final int PACKETSIZE = 16;
  20.   private static char myaddr = 0;
  21.   private static char kbdpacket[] = new char[PACKETSIZE];
  22.   private static char rxpacket[] = new char[PACKETSIZE];
  23.   private static char txpacket[] = new char[PACKETSIZE];
  24.   private static final int PENDTABLE_SIZE = 26;
  25.   private static final int DELAY = 10000;
  26.   private static final int WAITING = 0,
  27.           RECEIVING = 1,
  28.           ARRIVED = 2,
  29.           DECODING = 3;
  30.   private static int rxindex = WAITING;
  31.   private static PendtableRecord[] pendtable = new PendtableRecord[PENDTABLE_SIZE];
  32.   private static final int SOM = 0,
  33.           DEST = 1,
  34.           SRC = 2,
  35.           TYPE = 3,
  36.           CHKSM = 14,
  37.           EOM = 15;
  38.   private static int keycount, inum;
  39.  
  40.   public static char[] clearpacket(char[] packet) {
  41.     char[] p = new char[PACKETSIZE];
  42.     for (int i = 0; i < packet.length; i++) {
  43.       packet[i] = ' ';
  44.       p[i] = ' ';
  45.  
  46.     }
  47.     p[SOM] = packet[SOM] = '{'; // sets start char to {
  48.     p[EOM] = packet[EOM] = '}'; // sets end to }
  49.  
  50.     return p;
  51.   }
  52.  
  53.  
  54.  
  55.   public static void setchsum(char[] packet) {
  56.  packet[CHKSM] = 'S';
  57. //    int chksm = 0, i;
  58. //    for (i = 0; i < 16; i++) chksm += kbdpacket[i]; {
  59. //
  60. //      kbdpacket[CHKSM] = (char) ~(chksm % 128);
  61. //      kbdpacket[CHKSM] |= 0x80;
  62. //    }
  63.   }//checksum set END
  64.  
  65. //--------------------------------------------------------------------------------------
  66. //       Start of main method
  67. //       Sets up COM port handler and Terminal
  68. //       Loops userinput, transmitter and reciever until system exit
  69. //--------------------------------------------------------------------------------------
  70.   public static void main(String[] args) {
  71.  
  72.     sio = new SerialPortHandler(SerialPortHandler.COM1);
  73.  
  74.     terminal = new Term();
  75.  
  76.     welcome("Rob and Luke");
  77.  
  78.  
  79.     for (int i = 0; i < PENDTABLE_SIZE; i++) {
  80.       pendtable[i] = new PendtableRecord();
  81.     }
  82.  
  83.     while (true) {   // Stops output window looping
  84.       userInput();
  85.       transmitter();
  86.       receiver();
  87.     } // loops forever
  88.  
  89.  
  90.   }// main
  91.  
  92. //--------------------------------------------------------------------------------------
  93. //      User input state switch
  94. //       allows keyboard input
  95. //--------------------------------------------------------------------------------------
  96.   private static void userInput() {
  97.  
  98.     char key = 0;
  99.  
  100. //-------------------------------------------------------------------------------------------
  101. //      Login case: sets the users login to the character that is input through the keyboard
  102. //-------------------------------------------------------------------------------------------
  103.  
  104.     switch (kindex) {
  105.  
  106.       case LOGIN:
  107.  
  108.         if (terminal.kbhit()) {
  109.           key = terminal.getChar();
  110.           key = Character.toUpperCase(key);        //takes the character and changes it to uppercase
  111.           if (key >= 'A' && key <= 'Z') {          //checks that the letter is from A-Z
  112.             terminal.putChar(key);
  113.             terminal.putChar('\n');
  114.  
  115.             myaddr = key;
  116.  
  117.             kbdpacket = clearpacket(kbdpacket);     //clears the packet ready for building
  118.             kbdpacket[DEST] = myaddr;               //sets the destination of the packet to your desired address
  119.             kbdpacket[SRC] = myaddr;                //sets the source to your address
  120.             kbdpacket[TYPE] = 'L';                  //sets the packet to a 'Login' packet
  121.             setchsum(kbdpacket);                    //sets the checksum at the end of the packet
  122.             System.out.println(kbdpacket);
  123.  
  124.  
  125.             for (int i = 0; i < PENDTABLE_SIZE; i++) {              //
  126.               pendtable[i].setLoggedin(0);                        //
  127.               pendtable[i].setPending(0);                         //
  128.               pendtable[i].setDelay(0);                           //     sends the packet to the comm port
  129.             }                                                       //
  130.             pendtable[myaddr - 'A'].setPacket(kbdpacket);           //
  131.             pendtable[myaddr - 'A'].setPending(5);                  //
  132.             pendtable[myaddr - 'A'].setDelay(DELAY);                //
  133.  
  134.             kindex = ADDRPENDING;                   // program jumps to 'ADDRPENDING'
  135.  
  136.  
  137.           }
  138.         }//if(terminal.kbhit()) END
  139.         break;
  140. //--------------------------------------------------------------------------------------
  141. //      Set login to the character
  142. //      Display menu on terminal
  143. //--------------------------------------------------------------------------------------
  144.       case ADDRPENDING:
  145.         if (pendtable[myaddr - 'A'].getLoggedin() == -1) {
  146. //            System.out.println("" + myaddr);
  147. //            pendtable[myaddr - 'A'].setLoggedin(-1);
  148.  
  149.           for (int i = 0; i < 26; i++) {
  150.             int j = pendtable[i].getLoggedin();
  151.             System.out.println("" + j);
  152.           }
  153.  
  154.  
  155.           pendtable[myaddr - 'A'].setPending(0);
  156.  
  157. //             if (pendtable[myaddr - 'A'].getLoggedin() == -1) {
  158.           terminal.println("Your node id is now set to: " + myaddr);
  159.  
  160.           menu();                 //displays the menu
  161.           kindex = MENU;          //program jumps to 'MENU'
  162.         }//if END
  163.         // }
  164.         break;
  165.  
  166. //--------------------------------------------------------------------------------------
  167. //      Takes instruction form the user input and moves to the appropriate selection
  168. //
  169. //--------------------------------------------------------------------------------------
  170.       case MENU:
  171.         if (terminal.kbhit()) {
  172.  
  173.           key = terminal.getChar();
  174.           key = Character.toUpperCase(key);
  175.           if (key == 'D' || key == 'S' || key == 'C' || key == 'L') {                 //checks to see if the key pressed is D,S,C or L
  176.  
  177.             switch (key) {
  178.               case 'D':                                                         //
  179.                 terminal.print("Choose a destination address: ");             //if D is presssed jumps to 'GETADDR'
  180.                 kindex = GETADDR;                                             //where user sets destination address
  181.                 break;
  182.               case 'S':                                                         //if S is selected
  183.                 if (kbdpacket[1] > 0) {
  184.                   terminal.println("You chose: " + key);                    //
  185.                   pendtable[kbdpacket[1] - 'A'].setPending(1);              //
  186.                   for (int i = 0; i < PENDTABLE_SIZE; i++) {                //
  187.                     pendtable[i].setLoggedin(0);                          //
  188.                     pendtable[i].setPending(0);                           // sends the packet with the message in.
  189.                     pendtable[i].setDelay(0);                             //
  190.                   }                                                         //
  191.                   pendtable[myaddr - 'A'].setPacket(kbdpacket);             //
  192.                   pendtable[myaddr - 'A'].setPending(1);                    //
  193.                   pendtable[myaddr - 'A'].setDelay(DELAY);                  //
  194.                   clearpacket(kbdpacket);
  195.                   clearpacket(rxpacket);
  196.                   terminal.println("Packet Sent");
  197.                   terminal.println("");
  198.                   System.out.println("this should be empty packet: " + kbdpacket);
  199.                   menu();                       //displays the menu
  200.  
  201.                 }
  202.                 kindex = MENU;         // ERROR!!         SHOULD THIS GO TO MENU???
  203.                 break;
  204.  
  205.               case 'C':                                                          //
  206.                 terminal.println("You chose: " + key);                         //
  207.                 clearpacket(txpacket);                                         //
  208.                 terminal.println("Packet Cleared");                            //      when c is selected it clears the packet
  209.                 terminal.println("");                                          //
  210.                 System.out.println(txpacket);                                  //
  211.                 terminal.println("Please choose another option: ");            //
  212.                 menu();                                                        // displays the menu
  213.                 break;
  214.  
  215.               case 'L':
  216.                 terminal.println("\nYou are now logged out.\n");
  217.                 terminal.print("Please enter you next login: ");
  218.                 clearpacket(kbdpacket);                                         //cleared the packet
  219.                 kbdpacket[1] = myaddr;                                          //sets the first letter to users address
  220.                 kbdpacket[2] = myaddr;                                          //sets the second letter to users address
  221.                 kbdpacket[3] = 'X';                                             //set the packet type to 'X' (logout)
  222.                 setchsum(kbdpacket);                                            //sets the checksum at the end of the packet
  223.                 System.out.println(kbdpacket);
  224.  
  225.                 for (int i = 0; i < PENDTABLE_SIZE; i++) {                       //
  226.                   pendtable[i].setLoggedin(0);                                 //
  227.                   pendtable[i].setPending(0);                                  //fdssends the logout packet
  228.                   pendtable[i].setDelay(0);                                    //sets the logout packet ready for sending
  229.                 }                                                            //
  230.                 pendtable[myaddr - 'A'].setPacket(kbdpacket);                    //
  231.                 pendtable[myaddr - 'A'].setPending(1);                           //
  232.                 pendtable[myaddr - 'A'].setDelay(DELAY);                         //
  233.  
  234.                 if (pendtable[myaddr - 'A'].getPending() == 0) {
  235.                   System.out.println("gettiong heerer");
  236.                   System.arraycopy(pendtable[myaddr - 'A'].getPacket(), 0, kbdpacket, 0, 16); //changed from txpacket
  237.                   pendtable[myaddr - 'A'].setPending(1);
  238.                 }
  239.  
  240.                 for (int i = 0; i < 26; i++) {
  241.                   pendtable[i].setLoggedin(0);
  242.                 }
  243.  
  244.                 for (int i = 0; i < 26; i++) {
  245.                   int j = pendtable[i].getLoggedin();
  246.                   System.out.println("" + j);
  247.                 }
  248.  
  249.                 myaddr = 0;
  250.                 kindex = LOGIN;
  251.                 break;
  252.               default:
  253.                 break;
  254.             }// case END
  255.           }//if D,S,C or L END
  256.         }//if terminal.kbhit END
  257.  
  258. //--------------------------------------------------------------------------------------
  259. //      Sets the address for the destination of the packet set by the user
  260. //      Print out the menu before moving back to allow another selection
  261. //--------------------------------------------------------------------------------------
  262.  
  263.       case GETADDR:
  264.         // System.out.println("getting here");
  265.         if (terminal.kbhit()) {
  266.  
  267.           key = terminal.getChar();
  268.           key = Character.toUpperCase(key);
  269.           terminal.putChar(key);
  270.           terminal.print("\n");
  271.           // if (pendtable[key - 'A'].getLoggedin() == 0) {
  272.           menu();
  273.           kindex = MENU;
  274.           //  } else {
  275.           clearpacket(kbdpacket); //set up packet
  276.           //clearpacket(rxpacket);
  277.           // clearpacket(txpacket);
  278.           kbdpacket[1] = key;     //dest addr set
  279.           kbdpacket[2] = myaddr;  //sets source
  280.           kbdpacket[3] = 'D';
  281.           setchsum(kbdpacket);
  282.  
  283.           System.out.println(kbdpacket);
  284.           keycount = 4;
  285.  
  286.           terminal.println("You chose: " + key);
  287.           terminal.println("Please enter your message (up to 10 characters): ");
  288.  
  289.           System.out.println(kbdpacket);
  290.           kindex = INPUTMESS;
  291.           // }
  292.         }//if(terminal.kbhit()) END
  293.  
  294.         break;
  295.  
  296. //--------------------------------------------------------------------------------------
  297. //      Allows the user to input a 10 character long message to be entered
  298. //--------------------------------------------------------------------------------------
  299.       case INPUTMESS:
  300.  
  301.         if (terminal.kbhit()) {
  302.           key = terminal.getChar();
  303.  
  304.           terminal.putChar(key);
  305.  
  306.           if (keycount <= 13 && key != '\n' && key > 0) {      //if the keycount is less than 14, the letter is not a new line and is a valid character
  307.             kbdpacket[keycount++] = key;                       //add 1 to the keycount
  308.             System.out.println(kbdpacket);
  309.             System.out.println("keycount: " + keycount);
  310.  
  311.  
  312.  
  313.           } else {                                                //when 10 chars or enter has occoured
  314.             //keycount=15;
  315.             terminal.println("");
  316.             terminal.println("End of message!");
  317.             setchsum(kbdpacket);                                // set the checksum
  318.  
  319.  
  320.             if (pendtable[kbdpacket[1] - 'A'].getPending() == 0) {
  321.               System.arraycopy(pendtable[myaddr - 'A'].getPacket(), 0, kbdpacket, 0, 16);
  322.             }
  323.             kindex = MENU;                                      // go to the menu
  324.             menu();
  325.  
  326.           }//if keycount<14 END
  327.         }// if terminal.kbhit END
  328.  
  329.         break;
  330.       default:
  331.         terminal.println("Error in keyboard user state machine!!"); // shouldnt get here!!!!
  332.         break;
  333.     }//switch(kindex) END
  334.     }//public static void () END
  335.  
  336. //--------------------------------------------------------------------------------------
  337. //      Transmits the packets from the pendtable through the COM port,
  338. //--------------------------------------------------------------------------------------
  339.   private static void transmitter() {
  340.  
  341.     if (++pendindex > ('Z' - 'A')) {
  342.       pendindex = 0;
  343.     }
  344.     if (pendtable[pendindex].getPending() > 0) {
  345.       if (pendtable[pendindex].getDelay() == DELAY) {
  346.         sio.sendpacket(pendtable[pendindex].getPacket());
  347.       }
  348.     }
  349.  
  350.     pendtable[pendindex].decDelay();
  351.     if (pendtable[pendindex].getDelay() == 0) {
  352.       pendtable[pendindex].decPending();
  353.       if (pendtable[pendindex].getPending() > 0) {
  354.       }
  355.     }
  356.   }//transmitter END
  357. //--------------------------------------------------------------------------------------
  358. //      Starts the receiving process
  359. //--------------------------------------------------------------------------------------
  360.  
  361.   private static void receiver() {
  362.  
  363.     char letter = 0;
  364.     switch (rxindex) {
  365.  
  366. //--------------------------------------------------------------------------------------
  367. //      While there is no incoming transmission.
  368. //      detects incoming transmission and moves to the recieving case
  369. //--------------------------------------------------------------------------------------
  370.  
  371.  
  372.       case WAITING:
  373.  
  374.         //char letter = 0;
  375.         letter = sio.getChar();
  376.  
  377.         if (letter == '{') {  // when '{' is recognised... packet arriving
  378.           System.out.println("getting here!!!");
  379.           inum = 0;
  380.           rxpacket[inum++] = letter;        // first letter only
  381.           rxindex = RECEIVING;                  //goes to 'RECEIVING'
  382.         }
  383.  
  384.         break;
  385.  
  386. //--------------------------------------------------------------------------------------
  387. //      If there is an incoming message, checks packet length
  388. //      moves to arrived case
  389. //--------------------------------------------------------------------------------------
  390.       case RECEIVING:
  391.  
  392.         letter = sio.getChar();
  393.         if (letter > 0) {
  394.  
  395.           rxpacket[inum++] = letter;
  396.  
  397.           if (inum > 15) {                //when the packet length has reached 15
  398.             System.out.println(rxpacket);
  399.             rxindex = ARRIVED;        // it will jump to 'ARRIVED'
  400.           }
  401.         }
  402.         break;
  403.  
  404. //--------------------------------------------------------------------------------------
  405. //      indicates that a packet has been recieved
  406. //      continues sending the packet on
  407. //      moves on to Decoding case
  408. //--------------------------------------------------------------------------------------
  409.  
  410.       case ARRIVED:
  411.         //terminal.println("\nRecieved Packet: "+rxpacket[4]+rxpacket[5]+rxpacket[6]+rxpacket[7]+rxpacket[8]+rxpacket[9]+rxpacket[10]+rxpacket[11]+rxpacket[12]+rxpacket[13]);
  412.         txpacket = clearpacket(txpacket);
  413.         System.out.println("junk????????????? : " + txpacket);
  414.         //check checksum if else
  415.         rxindex = DECODING;
  416.         break;
  417.  
  418. //--------------------------------------------------------------------------------------
  419. //      Allows the system to recognise who the packet is from, what type of packet it is
  420. //      and who the desired destination is.
  421. //--------------------------------------------------------------------------------------
  422.  
  423.       case DECODING:
  424.         fromMeToMe();
  425.         fromMeToYou();
  426.         fromYouToMe();
  427.         fromYouToYou();
  428.         rxindex = WAITING;
  429.         break;
  430.       default:
  431.         break;
  432.  
  433.     }//switch(rxindex) END
  434. //  }
  435.     }//public static void receiver () END
  436.  
  437.   private static void fromMeToMe() {
  438.  
  439.     if (rxpacket[SRC] == myaddr) {
  440.       if (rxpacket[DEST] == myaddr) {
  441.         switch (rxpacket[TYPE]) {
  442.           case 'L':
  443.             terminal.println("Recived Login Packet for: " + myaddr);
  444.            // if(rxpacket[CHKSM] == txpacket[CHKSM]){
  445.             if (pendtable[myaddr - 'A'].getLoggedin() == 0) {
  446.               pendtable[myaddr - 'A'].setLoggedin(-1);
  447.               pendtable[myaddr - 'A'].setPending(0);
  448.             }//}
  449.            // else{
  450.             //  terminal.println("checksum error");
  451.           //  }
  452.             break;
  453.           case 'R': //illegal! -- clear the packet/leave to overwrite, remove entry in pendtable
  454.             pendtable[myaddr - 'A'].setPending(-1); // could be 0
  455.             break;
  456.           case 'D': // test msg to myself, ACK it -- print the message
  457.            //if(rxpacket[CHKSM] == txpacket[CHKSM]){
  458.             terminal.println("\nRecieved Message: " + rxpacket[4] + rxpacket[5] + rxpacket[6] + rxpacket[7] + rxpacket[8] + rxpacket[9] + rxpacket[10] + rxpacket[11] + rxpacket[12] + rxpacket[13]);
  459.             menu();
  460.         //}
  461. //           else{
  462. //              terminal.println("checksum error");
  463. //           }
  464.             rxindex = MENU;
  465.             break;
  466.           case 'A': // got ACK to my msg
  467.             pendtable[myaddr - 'A'].setPending(-1);//could be 0
  468.             break;
  469.           case 'N':// got NAK to my msg, ket try again!-- left blank
  470.             break;
  471.           case 'X':// my logout
  472.             pendtable[myaddr - 'A'].setLoggedin(0);     //
  473.             for (int i = 0; i < 26; i++) {                   //   sets this terminal to logged out
  474.               pendtable[i].setLoggedin(0);               //   sets value in the pendtable to 0
  475.  
  476.             }
  477.             break;
  478.           default:
  479.             break;
  480.  
  481.         } //switch END
  482.       }//if rxpacket[DEST] END
  483.     }//if rxpacket[SRC] END
  484.     }//from me to me END
  485.  
  486.   private static void fromMeToYou() {
  487.     if (rxpacket[SRC] == myaddr) {
  488.       if (rxpacket[DEST] != myaddr) { //change to destination address
  489.         switch (rxpacket[TYPE]) {
  490.           case 'L'://illegal
  491.             pendtable[myaddr - 'A'].setPending(-1);
  492.             break;
  493.           case 'R': //error where has he gone now?
  494.             break;
  495.           case 'D': // rx failed, del packet, re tx from pendtable-- left blank
  496.             break;
  497.           case 'A': // rx failed delete packet
  498.             pendtable[myaddr - 'A'].setPending(-1); // could be 0
  499.             break;
  500.           case 'N':// rx failed delete packet
  501.             pendtable[myaddr - 'A'].setPending(-1); // could be 0
  502.             break;
  503.           case 'X':// illegal
  504.             pendtable[myaddr - 'A'].setPending(-1);
  505.             break;
  506.           default:
  507.             break;
  508.         }//switch END
  509.       }//if rxpacket[DEST] END
  510.     }//if rxpacket[SRC] END
  511.     }// from me to you END
  512.  
  513.   private static void fromYouToMe() {
  514.     if (rxpacket[SRC] != myaddr) { // change to source destination
  515.       if (rxpacket[DEST] == myaddr) {
  516.         switch (rxpacket[TYPE]) {
  517.           case 'L'://illegal
  518.             pendtable[myaddr - 'A'].setPending(-1);
  519.             break;
  520.           case 'R': //error where has he gone now?
  521.             break;
  522.           case 'D': // rx failed, del packet, re tx from pendtable
  523.             terminal.println("\nRecieved Message: " + rxpacket[4] + rxpacket[5] + rxpacket[6] + rxpacket[7] + rxpacket[8] + rxpacket[9] + rxpacket[10] + rxpacket[11] + rxpacket[12] + rxpacket[13]);
  524.             break;
  525.           case 'A': // rx failed delete packet
  526.             pendtable[myaddr - 'A'].setPending(-1); // could be 0
  527.             break;
  528.           case 'N':// rx failed delete packet
  529.             pendtable[myaddr - 'A'].setPending(-1); // could be 0
  530.             break;
  531.           case 'X':// illegal
  532.             pendtable[myaddr - 'A'].setPending(-1);
  533.             break;
  534.           default:
  535.             break;
  536.         }//switch END
  537.       }//if rxpacket[DEST] END
  538.     }//if rxpacket[SRC] END
  539.     }//from you to me END
  540.  
  541.   private static void fromYouToYou() {
  542.     if (rxpacket[SRC] != myaddr) { //src address
  543.       if (rxpacket[DEST] != myaddr) { //destination address
  544.         switch (rxpacket[TYPE]) {
  545.           case 'L'://re txpacket, update pending, send R
  546.             System.out.println("getting here!!!!!");                  //
  547.             pendtable[myaddr - 'A'].setPacket(rxpacket);             //
  548.             pendtable[myaddr - 'A'].setPending(1);                    //
  549.             pendtable[myaddr - 'A'].setDelay(DELAY);                  //
  550.             break;
  551.           case 'R': //illegal
  552.             pendtable[myaddr - 'A'].setPending(-1);
  553.             break;
  554.           case 'D': // re-tx packet
  555.             //rxpacket to where it needs to go
  556.             for (int i = 0; i < PENDTABLE_SIZE; i++) {                //
  557.               pendtable[i].setLoggedin(0);                          //possibly set to -1???
  558.               pendtable[i].setPending(0);                           // sends the packet with the message in.
  559.               pendtable[i].setDelay(0);                             //
  560.             }                                                         //
  561.             pendtable[myaddr - 'A'].setPacket(rxpacket);             //
  562.             pendtable[myaddr - 'A'].setPending(1);                    //
  563.             pendtable[myaddr - 'A'].setDelay(DELAY);
  564.             break;
  565.           case 'A': // re-tx packet
  566.             for (int i = 0; i < PENDTABLE_SIZE; i++) {                //
  567.               pendtable[i].setLoggedin(0);                          //possibly set to -1???
  568.               pendtable[i].setPending(0);                           // sends the packet with the message in.
  569.               pendtable[i].setDelay(0);                             //
  570.             }                                                         //
  571.             pendtable[myaddr - 'A'].setPacket(rxpacket);             //
  572.             pendtable[myaddr - 'A'].setPending(1);                    //
  573.             pendtable[myaddr - 'A'].setDelay(DELAY);
  574.             break;
  575.           case 'N':// re-tx packet
  576.             for (int i = 0; i < PENDTABLE_SIZE; i++) {                //
  577.               pendtable[i].setLoggedin(0);                          //possibly set to -1???
  578.               pendtable[i].setPending(0);                           // sends the packet with the message in.
  579.               pendtable[i].setDelay(0);                             //
  580.             }                                                         //
  581.             pendtable[myaddr - 'A'].setPacket(rxpacket);             //
  582.             pendtable[myaddr - 'A'].setPending(1);                    //
  583.             pendtable[myaddr - 'A'].setDelay(DELAY);
  584.             break;
  585.           case 'X':// re-tx packet, ammend pendtable
  586.             break;
  587.           default:
  588.             break;
  589.         }//switch END
  590.       }//if rxpacket[DEST] END
  591.     }//if rxpacket[SRC] END
  592.     }//from you to you END
  593.  
  594.   private static void welcome(String name) {                                          //WELCOME MESSAGE
  595.     terminal.println("\tWelcome to " + name + "s Serial JavaLan\n");
  596.     terminal.println("Once logged in you can send TEN characters");
  597.     terminal.println("message to anyone else who is logged in.\n\n");
  598.     terminal.print("To login hit a character (A - Z): ");
  599.     terminal.println(" ");
  600.   }//welcome END
  601.  
  602.   private static void menu() {                                                            //MENU MESSAGE
  603.  
  604.     terminal.println(" ");
  605.     terminal.println("Choose an option: ");
  606.     terminal.println("                    D: Set destination");
  607.     terminal.println("                    S: send packet");
  608.     terminal.println("                    C: Clear packet");
  609.     terminal.println("                    L: Logout");
  610.     terminal.println(" ");
  611.  
  612.   }//menu END
  613.  
  614.   private static void ack() {
  615.     clearpacket(kbdpacket); //set up packet
  616.     kbdpacket[1] = rxpacket[2];     //dest addr set
  617.     kbdpacket[2] = myaddr;  //sets source
  618.     kbdpacket[3] = 'A';
  619.     setchsum(kbdpacket);
  620.   }
  621. }//class END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement