void main() { auto int nIn1, nIn2; auto char cOut; brdInit(); //initialize board for this demo serCopen(_232BAUD); serBopen(_232BAUD); serCwrFlush(); serCrdFlush(); serBwrFlush(); serBrdFlush(); serMode(0); //enable serial device while (1) { for (cOut='a';cOut<='z';++cOut) { serCputc (cOut); // Send lowercase byte while ((nIn1=serBgetc()) == -1); // Wait for echo serBputc (toupper(nIn1)); // Send the converted upper case byte while ((nIn2=serCgetc()) == -1); // Wait for echo printf ("Serial C sent %c, serial B sent %c, serial C received %c\n", cOut, toupper(nIn1), nIn2); } } }
main() { auto int nIn1, nIn2; auto char cOut; serCopen(_232BAUD); serDopen(_232BAUD); serCwrFlush(); serCrdFlush(); serDwrFlush(); serDrdFlush(); while (1) { for (cOut='a';cOut<='z';++cOut) { serCputc (cOut); // Send lowercase byte while ((nIn1=serDgetc()) == -1); // Wait for echo serDputc (toupper(nIn1)); // Send the converted upper case byte while ((nIn2=serCgetc()) == -1); // Wait for echo printf ("Serial C sent %c, serial D sent %c, serial C received %c\n", cOut, toupper(nIn1), nIn2); } } }
void task1(void* pdata) { auto INT8U err; while(1) { // wait for a byte to arrive at serial port. This semaphore // will be signaled by the task aware isr for serial port C // at the end of this file. OSSemPend(serCsem, 0, &err); // if byte matches byte transmitted, count it. if(serCgetc() == 'Z') bytesreceived++; } }
void main() { auto int nIn; auto char cOut; auto char inkey; brdInit(); keypadDef(); serCopen(_232BAUD); serMode(0); serCwrFlush(); serCrdFlush(); while (1) { costate { // Process Keypad Press/Hold/Release keyProcess(); waitfor(DelayMs(10)); } costate { if ((inkey = keyGet()) != 0) { // Wait for Keypress dispPrintf ("%c", inkey); // Display Byte serCputc(inkey); // Transmit byte } waitfor(DelayMs(10)); } costate { if ((nIn=serCgetc()) != -1) // Wait for receive byte dispPrintf ("%c", nIn); // Display Byte waitfor(DelayMs(10)); } } }
void main() { //temp variable useful for loops int i; //temp variables for serial communication int c; unsigned int bytesRead; //variables for wifi communication int newMode; int interfacePacketRecieved; int network; #GLOBAL_INIT { setMode(ROBOT_ENABLE); rx.state = WAIT; /*********************** Initialization of Packets ***********************/ // Initialize software version aPacket[1] = SOFTWARE_VERSION_ID >> 8; aPacket[2] = SOFTWARE_VERSION_ID & 0xFF; // Initialize UDP response packets gPacket[0] = 'G'; gPacket[1] = ROBOTMODE; gPacket[2] = SOFTWARE_VERSION_ID >> 8; gPacket[3] = SOFTWARE_VERSION_ID & 0xFF; gPacket[4] = 0; // user version id gPacket[5] = 0; gPacket[6] = 0; // battery voltage gPacket[7] = 0; // Initialize J packet values to 0 memset(jPacket, 0, J_PACKET_LENGTH); // Initialize X default packet (autonomous mode dummy packet) to 0 memset(xPacketDefaultValues, 0, X_PACKET_LENGTH); } ///////////////////////////////////////////////////////////////////////// // Configure Port D -- Leave PD4-PD7 untouched (used for other purposes) ///////////////////////////////////////////////////////////////////////// WrPortI(PDCR, &PDCRShadow, RdPortI(PDCR) & 0xF0); // clear bits to pclk/2 WrPortI(PDFR, &PDFRShadow, RdPortI(PDFR) & 0xF0); // no special functions WrPortI(PDDCR, &PDDCRShadow, RdPortI(PDDCR) & 0xF0); // clear bits to drive // high and low WrPortI(PDDR, &PDDRShadow, RdPortI(PDDR) | 0x0D); // set outputs high WrPortI(PDDDR, &PDDDRShadow, RdPortI(PDDDR) | 0x0D); // set inputs and // outputs //Initialize serial communication serialInit(); //Initialize controls as neutral //memset(interface.axis, 127, sizeof(interface.axis)); //memset(interface.btn, 0, sizeof(interface.btn)); //Decide which router to connect to if (BitRdPortI(PDDR, 1) == 1) { //USER settings BitWrPortI(PDDR, &PDDRShadow, 1, 0); // turn off user LED network = USER_ROUTER; printf("USER\n"); } else { //COMPETITION Settings BitWrPortI(PDDR, &PDDRShadow, 0, 0); // turn on user LED network = COMP_ROUTER; setMode(ROBOT_DISABLE); printf("COMPETITION\n"); } // */ printf("Robot Mode: %d \n", ROBOTMODE); // Wait for X2 handshake (to learn team #) before attempting connection printf("Waiting for X2...\n"); while (x2Connection != X2_CONN_ESTABLISHED) { if ((c = serCgetc()) != -1) { byteReceived(c); } } printf("X2 connection established\n"); sendPacket('F', F_PACKET_LENGTH, fPacket); ConnectToNetwork(network, teamNo); //Main Loop while(1) { // Receive field, interface & X2 reply packets as they come costate { //Check to see if we have new field communication if (udpRecieveFieldPacket()) { newMode = ProcessFieldPacket(); if (newMode != -1) { // Set robot mode flags setMode(newMode); // If disable flag set: zero motor values if (newMode & ROBOT_DISABLE) disableRobot(); // Send X2 packet with new mode flags sendPacket('F', F_PACKET_LENGTH, fPacket); // Send back response packet with our robot mode flags // and code versions sendFieldSocket(gPacket, G_PACKET_LENGTH); //printf("Robot Mode: %d \n", ROBOTMODE); } } //Check to see if we have new field commuication, and we can use it if (udpRecieveInterfacePacket()) { if (interBuf[0] == 'I') { udpNewData = TRUE; } } // Receive X2 serial data in bursts of up to X2_RX_BURST_LENGTH bytesRead = 0; while ((c = serCgetc()) != -1 && bytesRead <= X2_RX_BURST_LENGTH) { byteReceived((unsigned char)c); bytesRead += 1; } } // */ // Time out if no UDP packets received after 500 ms // TODO: Update the interface to send an enable packet. In the meantime // this feature is only activated in competition mode costate { if (network == COMP_ROUTER) { waitfor( udpNewData || DelayMs(500) ); if (!udpNewData) disableRobot(); } } // Send X2 packets costate { // FOR TESTING // udpNewData = TRUE; waitfor( udpNewData ); // Check that disable bit is not set if (!(ROBOTMODE & ROBOT_DISABLE)) { // If in autonomous mode, send a dummy 'X' packet to keep the // motor refreshing, but do not send actual joystick values if (ROBOTMODE & ROBOT_AUTON) sendPacket('X', X_PACKET_LENGTH, xPacketDefaultValues); // Otherwise in enable mode, send the received joystick values else sendPacket('X', X_PACKET_LENGTH, interBuf+1); x2OkToSend = FALSE; udpNewData = FALSE; // Wait for reply before sending another packet waitfor( x2OkToSend || DelayMs(500) ); if (!x2OkToSend) { // no reply came within 500ms timeout //printf("disable"); disableRobot(); } } } costate { // If auto bit is set, blink the LED fast if (ROBOTMODE & ROBOT_AUTON) { BitWrPortI(PDDR, &PDDRShadow, 0, 0); // turn on user LED waitfor (DelayMs(100)); BitWrPortI(PDDR, &PDDRShadow, 1, 0); // turn off user LED waitfor (DelayMs(100)); // Otherwise if disable bit is set, blink the LED slowly } else if (ROBOTMODE & ROBOT_DISABLE) { BitWrPortI(PDDR, &PDDRShadow, 0, 0); // turn on user LED waitfor (DelayMs(500)); BitWrPortI(PDDR, &PDDRShadow, 1, 0); // turn off user LED waitfor (DelayMs(500)); } } } // while(1) } // main
void main() { int c,i,n,g, rvalue; auto int nIn; auto char cOut; brdInit(); serCopen(9600); // serPORT(9600); //serCopen(BAUDGPS); serMode(0); serCrdFlush();// main loop serCwrFlush(); serCrdFlush(); serCputc('t'); serCputc('e'); printf("starting the loop"); memset(sentence,0x00,sizeof(sentence)); while(1) { c = serCgetc(); if( c == -1){ printf("nothing recieved\n"); } else{ printf("recieved: %c\n",serCgetc()); } // this costate will check if the GPS has sent some data or not and // call the appropriate functions to process the data costate GPSRead always_on { // wait until gps mode is engaged and a gps string has been recieved waitfor(serCrdUsed() > 0); //printf("gps read: "); // read until finding the beginning of a gps string then wait while(1) { //int test2; c = serCgetc(); printf("%c\n",c); if (c == -1) { serCrdFlush(); abort; } else { i = 0; sentence[i++] = c; waitfor(DelayMs(10)); //should only take 5ms or so at 115200 baud break; } }//end while(1) // now that 20 ms have passed, read in the gps string (it must all // be there by now, since so much time has passed //serCwrFlush(); //serCrdFlush(); //serCrdFlush(); //i = 0; while((nIn=serCgetc()) != -1){ sentence[i++] = nIn; } for(n = 0; n<i;n++){ serCputc(sentence[n]); } sentence[i] = '\0'; printf("%s\n",sentence); memset(sentence,0x00,sizeof(sentence)); }//end costate }// end while(1) }//end main()
void main() { char outString[MAX_TX_LEN], inString[MAX_TX_LEN]; int i, j, ch, out_string_len; brdInit(); // The brdInit for this board sets pins that are not initially assigned to // hardware as outputs, such as the serial port Rx pins. The Rx pin for // serial port D is not set to an input because it is not used in this // sample. BitWrPortI(PCDDR, &PCDDRShadow, 0, 3); // set serial port C Rx as input serDopen(BAUDRATE); serCopen(BAUDRATE); #ifdef DIGITAL_IO_ACCESSORY InitIO(); #endif // Initialize DS1 LED (PDO) to output BitWrPortI(PDDDR, &PDDDRShadow, 0, 1); // Initialize DS1 LED (PDO) to output BitWrPortI(PDDDR, &PDDDRShadow, 1, 0); // Make sure PD0 not set to alternate function BitWrPortI(PDFR, &PDFRShadow, 0, 1); // Make sure PD0 not set to alternate function BitWrPortI(PDFR, &PDFRShadow, 0, 0); j = 0; while(1) { costate { // Bits for switches and LEDs correspond for (i = S1; i <= S4; i++) { #ifdef DIGITAL_IO_ACCESSORY if (!BitRdPortI(PBDR, i)) #else if (!BitRdPortI(PDDR, i)) #endif { // Delay so we don't output too many times waitfor(DelayMs(300)); // Light corresponding LED #ifdef DIGITAL_IO_ACCESSORY BitWrPortI(PADR, &PADRShadow, LEDON, i); #else BitWrPortI(PDDR, &PDDRShadow, LEDON, i-1); #endif sprintf(outString, "Switch %d is on\n", i-S1+1); out_string_len = strlen(outString); // Make sure there's room in ouput buffer waitfor(serDwrFree() > out_string_len); // Write string out serDwrite(outString, out_string_len); } else { #ifdef DIGITAL_IO_ACCESSORY BitWrPortI(PADR, &PADRShadow, LEDOFF, i); // LED off #else BitWrPortI(PDDR, &PDDRShadow, LEDOFF, i-1); #endif } } } // Wait for any ASCII input // serCgetc() returns -1 (0xFFFF) if no chars available if ( (ch = serCgetc()) != -1 ) { inString[j] = ch; j++; if (j >= MAX_TX_LEN) // Make sure we don't overflow { // array bounds in case 0x0A j = 0; // gets dropped. } else if (ch == '\n') // Check for new line as delimiter { inString[j] = 0; // NULL terminate printf("%s",inString); j = 0; } } } }
main() { auto int i, ch; auto char buffer[64]; //buffer used for serial data auto int sw1, sw2, led1, led2; static const char string1[] = {"This message has been Rcv'd from serial port D !!!\n\n\r"}; static const char string2[] = {"This message has been Rcv'd from serial port C !!!\n\n\r"}; //--------------------------------------------------------------------- // Initialize the controller //--------------------------------------------------------------------- brdInit(); //initialize board for this demo led1=led2=1; //initialize led to off value sw1=sw2=0; //initialize switch to false value // Initialize serial port D, set baud rate to 19200 serDopen(19200); serDwrFlush(); serDrdFlush(); // Initialize serial portC, set baud rate to 19200 serCopen(19200); serCwrFlush(); serCrdFlush(); // Clear data buffer memset(buffer, 0x00, sizeof(buffer)); printf("\nStart of Sample Program!!!\n\n\n\r"); //--------------------------------------------------------------------- // Do continuous loop transmitting data between serial ports D and C //--------------------------------------------------------------------- for(;;) { costate { if (pbRdSwitch(S2)) //wait for switch S2 press abort; waitfor(DelayMs(50)); if (pbRdSwitch(S2)) //wait for switch release { sw1=!sw1; abort; } } costate { if (pbRdSwitch(S3)) //wait for switch S3 press abort; waitfor(DelayMs(50)); if (pbRdSwitch(S3)) //wait for switch release { sw2=!sw2; abort; } } costate { // toggle DS1 upon valid S2 press/release if (sw1) { pbWrLed(DS1, ON); //turn on DS1 led sw1=!sw1; // Transmit an ascii string from serial port C to serial port D memcpy(buffer, string2, strlen(string2)); serCputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by port C i = 0; while((ch = serDgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port C printf("%s", buffer); // Clear buffer memset(buffer, 0x00, sizeof(buffer)); pbWrLed(DS1, OFF); //turn off DS1 } } costate { // toggle DS2 upon valid S3 press/release if (sw2) { pbWrLed(DS2, ON); //turn on DS2 led sw2=!sw2; // Transmit an ascii string from serial port D to serial port C memcpy(buffer, string1, strlen(string1)); serDputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by serial port D i = 0; while((ch = serCgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port D printf("%s", buffer); pbWrLed(DS2, OFF); //turn off DS2 } //endif } //endcostate } //endfor }
main() { auto int i, ch; auto char buffer[64]; //buffer used for serial data auto int sw1, sw2; static const char string1[] = {"This message has been Rcv'd from serial port C !!!\n\n\r"}; static const char string2[] = {"This message has been Rcv'd from serial port D !!!\n\n\r"}; sw1 = sw2 = 0; //initialize switch to false value // Initialize serial port C, set baud rate to 19200 serCopen(19200); serCwrFlush(); serCrdFlush(); // Initialize serial port D, set baud rate to 19200 serDopen(19200); serDwrFlush(); serDrdFlush(); // Clear data buffer memset(buffer, 0x00, sizeof(buffer)); printf("\nStart of Sample Program!!!\n\n\n\r"); //--------------------------------------------------------------------- // Do continuous loop transmitting data between serial ports C and D //--------------------------------------------------------------------- while(1) { costate { if (BitRdPortI(S2_PORT, S2_BIT)) //wait for switch press abort; waitfor(DelayMs(50)); if (BitRdPortI(S2_PORT, S2_BIT)) { //wait for switch release sw1 = !sw1; abort; } } costate { if (BitRdPortI(S3_PORT, S3_BIT)) //wait for switch press abort; waitfor(DelayMs(50)); if (BitRdPortI(S3_PORT, S3_BIT)) { //wait for switch release sw2 = !sw2; abort; } } costate { // toggle led upon valid switch press/release if (sw1) { sw1 = !sw1; // The switch is attached the the serial port, so we need to read // the junk it sends serCrdFlush(); // Transmit an ascii string from serial port D to serial port C memcpy(buffer, string2, strlen(string2)); serDputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by port D i = 0; while((ch = serCgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port D printf("%s", buffer); // Clear buffer memset(buffer, 0x00, sizeof(buffer)); } } costate { // toggle led upon valid switch press/release if (sw2) { sw2=!sw2; // The switch is attached the the serial port, so we need to read // the junk it sends serDrdFlush(); // Transmit an ascii string from serial port C to serial port D memcpy(buffer, string1, strlen(string1)); serCputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by serial port C i = 0; while((ch = serDgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port C printf("%s", buffer); } //endif } //endcostate } //endwhile }
void main() { auto int i, ch; auto char buffer[64]; //buffer used for serial data static const char string1[] = "Rcv'd data on serial port C from serial port B\n\r"; static const char string2[] = "Rcv'd data on serial port B from serial Port C\n\r"; brdInit(); //required for BL2000 series boards // initialize serial portB, set baud rate to 19200 serBopen(19200); serBwrFlush(); serBrdFlush(); // initialize serial portC, set baud rate to 19200 serCopen(19200); serCwrFlush(); serCrdFlush(); serMode(0); //required for BL2000 series bds...must be done after serXopen function(s) //clear data buffer memset(buffer, 0x00, sizeof(buffer)); printf("\nStart of Sample Program!!!\n\n\n\r"); for(;;) { //transmit an ascii string from serial port B to serial port C memcpy(buffer, string1, strlen(string1)); serBputs(buffer); memset(buffer, 0x00, sizeof(buffer)); //get the data string that was transmitted by serial port B i = 0; while((ch = serCgetc()) != '\r') { if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // display ascii string received from serial port B printf("%s", buffer); //transmit an ascii string from serial port C to serial port B memcpy(buffer, string2, strlen(string2)); serCputs(buffer); memset(buffer, 0x00, sizeof(buffer)); //get the data string that was transmitted by port C i = 0; while((ch = serBgetc()) != '\r') { if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // display ascii string received from serial port C printf("%s", buffer); } }
void main() { auto int chan, ang, rvalue; auto float dist; auto int pwm, r_head, r_head2, head; auto long freq; auto char tmpbuf[128], c; char gpsString[MAX_SENTENCE]; GPSPosition testPoint, testPoint_old; brdInit(); serPORT(BAUDGPS); //serCopen(BAUDGPS); serMode(0); serCrdFlush();// main loop initGPS(); freq = pwm_init(450ul); printf("pick heading: "); r_head = atoi(gets(tmpbuf)); //while(1) // { /*goal.lat_degrees = 43; goal.lat_minutes = 7036; goal.lon_degrees = 72; goal.lon_minutes = 2811; goal.lat_direction = 'N'; goal.lon_direction = 'W'; goal.sog = 0; //goal.tog = */ if ((r_head > 90) || (r_head < -90)) { printf("\nbad heading "); } else { while (1) { costate GPSRead always_on { // wait until gps mode is engaged and a gps string has been recieved waitfor(serCrdUsed() > 0); //printf("gps read: "); // read until finding the beginning of a gps string then wait while(1) { //int test2; c = serCgetc(); if (c == -1) { serCrdFlush(); abort; } else if (c == '$') { waitfor(DelayMs(20)); //should only take 5ms or so at 115200 baud break; } }//end while(1) // now that 20 ms have passed, read in the gps string (it must all // be there by now, since so much time has passed getgps(gpsString); rvalue = gps_get_position(&testPoint,gpsString); if( rvalue != -1) { printGPSPosition(&testPoint); } //printf("gps: %u \n",strlen(test2)); printf("gps: %s ",gpsString); //printGPSPosition(&testPoint); //puts(gpsString); //puts(": end gps \n"); //dist = gps_ground_distance(&testPoint, &testPoint_old); //head = (int)gps_bearing(&testPoint, &testPoint_old, dist); //testPoint_old = testPoint; head = testPoint.tog; // grab current heading r_head2 = r_head-head; pwm = set_angle(0, r_head2); printf("angle: %d, head %d \n",pwm, head); }//end costate } // end while } // end else //} // end first while } // end main