//------------------------------------------------------------------------------------------- void LCD::toggleSplash() { //turns the splash screen on and off, the 1 second delay at startup stays either way. serial.write(0x7C); serial.write(0x13); //CTRL s }
void report(int *ranges){ for(int i = 0; i < maxSteps; i++){ Serial.print(String(ranges[i]) + ',' + String(i) + '\n'); // Convert ping time to distance in cm and print result (0 = outside set distance range) } mySerial.print("SCANEND"); }
/*! * function definitions */ void sport_init(void) { sportSerial.begin(SPORT_BAUD); }
// Function to update Number of Satellites used, HDOP, Altitude etc. // from the incoming $GPGGA string boolean dGPS::updategga(){ comandoGPG[0] = '$'; // initialization comandoGPG[1] = 'G'; comandoGPG[2] = 'P'; comandoGPG[3] = 'G'; comandoGPG[4] = 'G'; comandoGPG[5] = 'A'; while(true){ int byteGPS=-1; byteGPS=gpsSerial.read(); //read a byte from the serial port if (byteGPS == -1) { // See if the port is empty yet delay(5); } else { linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer conta++; if (byteGPS==13){ // If the received byte is = to 13, end of transmission cont=0; bien=0; for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPGGA if (linea[i]==comandoGPG[i-1]){ bien++; } } if(bien==6){ // If yes, continue and process the data Serial.print(""); // For some reason, this needs to be here or you won't populate variables. If anyone solves this problem, let us know. Serial.print(""); Serial.print("-"); /*Serial.println(linea); //Print out the GPGGA string (just for reference)*/ //------------------------------------------ // Get Number of satellites in use char *data = ""; memset(data, 0, sizeof(data)); data = dGPS::subStr(linea, ",", 8); fSat = atoi(data); delay(5); //------------------------------------------ // Get HDOP memset(data, 0, sizeof(data)); data = dGPS::subStr(linea, ",", 9); hDop = atof(data); delay(5); //------------------------------------------ // Get Altitude above sea-level (meters) memset(data, 0, sizeof(data)); data = dGPS::subStr(linea, ",", 10); fAlt = atof(data); delay(5); conta=0; // Reset the buffer memset(linea, 0, sizeof(linea)); break; } conta=0; // Reset the buffer memset(linea, 0, sizeof(linea)); } } } // END WHILE STATEMENT return true; }
// * Receiving the lenght of bytes from Serial port void HerkulexClass::readData(int size) { int i = 0; int beginsave=0; int Time_Counter=0; switch (port) { case SSerial: while((SwSerial.available() < size) & (Time_Counter < TIME_OUT)){ Time_Counter++; delayMicroseconds(1000); //wait 1 millisecond for 10 times } while (SwSerial.available() > 0){ byte inchar = (byte)SwSerial.read(); if ( (inchar == 0xFF) & ((byte)SwSerial.peek() == 0xFF) ){ beginsave=1; i=0; // if found new header, begin again } if (beginsave==1 && i<size) { dataEx[i] = inchar; i++; } } SwSerial.flush(); break; #if defined (__AVR_ATmega1280__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega2560__) case HSerial1: while((Serial1.available() < size) & (Time_Counter < TIME_OUT)){ Time_Counter++; delayMicroseconds(1000); } while (Serial1.available() > 0){ byte inchar = (byte)Serial1.read(); //printHexByte(inchar); if ( (inchar == 0xFF) & ((byte)Serial1.peek() == 0xFF) ){ beginsave=1; i=0; } if (beginsave==1 && i<size) { dataEx[i] = inchar; i++; } } break; case HSerial2: while((Serial2.available() < size) & (Time_Counter < TIME_OUT)){ Time_Counter++; delayMicroseconds(1000); } while (Serial2.available() > 0){ byte inchar = (byte)Serial2.read(); if ( (inchar == 0xFF) & ((byte)Serial2.peek() == 0xFF) ){ beginsave=1; i=0; } if (beginsave==1 && i<size) { dataEx[i] = inchar; i++; } } break; case HSerial3: while((Serial3.available() < size) & (Time_Counter < TIME_OUT)){ Time_Counter++; delayMicroseconds(1000); } while (Serial3.available() > 0){ byte inchar = (byte)Serial3.read(); if ( (inchar == 0xFF) & ((byte)Serial3.peek() == 0xFF) ){ beginsave=1; i=0; } if (beginsave==1 && i<size) { dataEx[i] = inchar; i++; } } break; #elif (__AVR_ATmega32U4__) case HSerial1: while((Serial1.available() < size) & (Time_Counter < TIME_OUT)){ Time_Counter++; delayMicroseconds(1000); } while (Serial1.available() > 0){ byte inchar = (byte)Serial1.read(); //printHexByte(inchar); if ( (inchar == 0xFF) & ((byte)Serial1.peek() == 0xFF) ){ beginsave=1; i=0; } if (beginsave==1 && i<size) { dataEx[i] = inchar; i++; } } break; #endif } }
void Pro_W2D_ErrorCmdHandle(Error_PacketsTypeDef Error_Type, uint8_t flag) { Pro_ErrorCmdTypeDef Pro_ErrorCmdStruct; //4.7 ?????? memcpy(&Pro_ErrorCmdStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_ErrorCmdStruct)); if(flag == 1) { goto Print_O; } Pro_ErrorCmdStruct.Pro_HeadPart.Head[0] = 0xFF; Pro_ErrorCmdStruct.Pro_HeadPart.Head[1] = 0xFF; Pro_ErrorCmdStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_ErrorCmdStruct) - 4); Pro_ErrorCmdStruct.Pro_HeadPart.Cmd = Pro_D2W_ErrorPackage_Ack_Cmd; Pro_ErrorCmdStruct.Error_Packets = Error_Type; Pro_ErrorCmdStruct.Sum = CheckSum((uint8_t *)&Pro_ErrorCmdStruct, sizeof(Pro_ErrorCmdStruct)); Pro_UART_SendBuf((uint8_t *)&Pro_ErrorCmdStruct, sizeof(Pro_ErrorCmdStruct), 0); #if(DEBUG==1) mySerial.print(F("Error :")); mySerial.println(Error_Type, HEX); mySerial.print("[");mySerial.print(SystemTimeCount,DEC);mySerial.print("]");mySerial.print(" MCU :"); for(uint8_t i = 0; i < (sizeof(Pro_ErrorCmdStruct)); i++) { mySerial.print(" "); mySerial.print(*((uint8_t *)&Pro_ErrorCmdStruct + i),HEX); } mySerial.println(""); #endif return; Print_O: /*************************错误类型*****************************/ switch (Pro_ErrorCmdStruct.Error_Packets) { case Error_AckSum: #if(DEBUG==1) mySerial.println(F("ACK : Error_AckSum OK")); #endif break; case Error_Cmd: #if(DEBUG==1) mySerial.println(F("ACK : Error_Cmd OK")); #endif break; case Error_Other: #if(DEBUG==1) mySerial.println(F("ACK : Error_Other OK")); #endif break; default: #if(DEBUG==1) mySerial.println(F("ACK : Error! ")); #endif break; } }
void ncArduinoPutData( ncPackageDataPtr_t ncPackageDataPtr, ncPackageLength_t ncPackageLength) { mySerial.write(ncPackageDataPtr, ncPackageLength); }
void ICACHE_FLASH_ATTR GlobalsClass::ResetAlarms() { ResetTimeCheck = 0; qCon.println("/set?al=0,0,0,0,0,0,0,0"); delay(comdelay); }
//RS485 Schreibroutine void fWrite (const byte what) { rs485.write (what); }
bool S4GPS::getGPS(char* gps) { char c; uint8_t sum; while (gpsSerial.available()) // this might break it. { c = gpsSerial.read(); if (bufferidx == 0) { while (c != '$') { c = gpsSerial.read(); } } buffer[bufferidx] = c; if (c == '\n') { buffer[bufferidx-1] = '\0'; // delete end line buffer[bufferidx+1] = 0; // terminate it if (buffer[bufferidx-4] != '*') { bufferidx = 0; // return; } sum = parseHex(buffer[bufferidx-3]) * 16; sum += parseHex(buffer[bufferidx-2]); for (i=1; i < (bufferidx-4); i++) { sum ^= buffer[i]; } if (sum != 0) { bufferidx = 0; // return; } bufferidx++; //Serial.print(buffer); for(int i = 0; i < 90; i++) { gps[i] = buffer[i]; } bufferidx = 0; return true; } bufferidx++; if (bufferidx == BUFFSIZE-1) { bufferidx = 0; } } }
void loop() { mySerial.print("Mode: "); char mode = mySerial.read(); // ------------------ SET MODE ------------------ if(mode == 'S'){ //Set Command - Digital Support Only mySerial.print("Set Digital: "); int digital = ( int(mySerial.read()) - 48 ); mySerial.print(digital); if(digital == 1){ //Digital Pins mySerial.print(" PinNum: "); char pinTens = mySerial.read(); char pinOnes = mySerial.read(); int pinNum = (int(pinOnes) - 48) + ( (int(pinTens) - 48) * 10 ); mySerial.print(pinNum); mySerial.print(" Value: "); int pinVal = int(mySerial.read() - 48); mySerial.print(pinVal); setDigital(pinNum, pinVal); mySerial.println(" - OK"); }else if(digital == 0){ //Analog Pins mySerial.println(" Analog pins unsupported."); }else{ //Invalid Input mySerial.println("Invalid Input"); } // ------------------ READ MODE ------------------ }else if(mode == 'R'){ //Read Command - Digital Support Only mySerial.print("Read Digital: "); int digital = ( int(mySerial.read()) - 48 ); mySerial.print(digital); if(digital == 1){ //Digital Pins mySerial.print(" PinNum: "); char pinTens = mySerial.read(); char pinOnes = mySerial.read(); int pinNum = (int(pinOnes) -48) + ( (int(pinTens) - 48) * 10 ); mySerial.print(pinNum); int pinVal = digitalRead(pinNum); mySerial.print(" Value: "); mySerial.print(pinVal); mySerial.println(" - OK"); }else if(digital == 0){ //Analog Pins mySerial.print(" PinNum: "); char pinOnes = mySerial.read(); int pinNum = (int(pinOnes) -48); mySerial.print(pinNum); int pinVal = analogRead(pinNum); mySerial.print(" Value: "); mySerial.print(pinVal); mySerial.println(" - OK"); }else{ //Invalid Input mySerial.println(" Invalid Input"); } }else if(mode == 'V'){ mySerial.print(" Information Kernel: "); mySerial.print(KERNEL_VERSION); }else{ mySerial.println("Invalid Input"); } }
void S4GPS::begin(int BaudRate) { gpsSerial.begin(BaudRate); Configure(); }
void loop() { // initialize http service if(count%10 == 0){ count= 0 ; gprsSerial.flush(); Serial.flush(); gprsSerial.println("AT+CIPSHUT"); delay(100); toSerial(); gprsSerial.println("AT+CGATT?"); delay(100); toSerial(); // attach or detach from GPRS service gprsSerial.println("AT+CGATT=1"); delay(100); toSerial(); // bearer settings gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""); delay(2000); toSerial(); // bearer settings gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\""); delay(2000); toSerial(); // bearer settings gprsSerial.println("AT+SAPBR=1,1"); delay(2000); toSerial(); } count++; Receive_GPS_Data(); gprsSerial.println("AT+HTTPINIT"); delay(2000); toSerial(); // set http param value gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://shuttletracker.hostei.com/?lat="+save_lati+"&long="+save_lg+"&speed="+save_spd+"\""); delay(2000); toSerial(); // set http action type 0 = GET, 1 = POST, 2 = HEAD gprsSerial.println("AT+HTTPACTION=0"); delay(6000); toSerial(); // read server response gprsSerial.println("AT+HTTPREAD"); delay(1000); toSerial(); gprsSerial.println(""); gprsSerial.println("AT+HTTPTERM"); toSerial(); delay(300); gprsSerial.println(""); delay(30000); finish=0;pos_cnt = 0; }
//------------------------------------------------------------------------------------------- void LCD::setBaud(byte baud) { //changes the baud rate. serial.write(0x7C); serial.write(0x07); //CTRL g serial.write(baud); //send a value of 49 - 54 delay(100); /* “1” = 4800bps - 0x31 = 49 “2” = 9600bps - 0x32 = 50 “3” = 19,200bps - 0x33 = 51 “4” = 38,400bps - 0x34 = 52 “5” = 57,600bps - 0x35 = 53 “6” = 115,200bps - 0x36 = 54 */ //these statements change the SoftwareSerial baud rate to match the baud rate of the LCD. if(baud == 49) { serial.end(); serial.begin(4800); } if(baud == 50) { serial.end(); serial.begin(9600); } if(baud == 51) { serial.end(); serial.begin(19200); } if(baud == 52) { serial.end(); serial.begin(38400); } if(baud == 53) { serial.end(); serial.begin(57600); } if(baud == 54) { serial.end(); serial.begin(115200); } }
// xbee receive ISR code void XBee_receive(){ // check if data came in from XBee if(XBee.available()){ // read start byte in data XBee.read(); // read MSB and LSB data int MSB = XBee.read(); int LSB = XBee.read(); // create dynamic array unsigned char *frame_data = (unsigned char) malloc(LSB-5 * sizeof(unsigned char)); // variable for the array head address unsigned char *data_array_head = frame_data; // variable for the array tail address unsigned char *data_array_tail; // variable for the room module address of the data unsigned char RM_address; // variable for the sum of data bytes unsigned char byte_sum = 0x00; // loop through data bytes after LSB for(int i=0; i<LSB; i++){ if(i==5) RM_address = XBee.read(); if(i>5){ *frame_data = XBee.read(); frame_data++; } byte_sum += XBee.read(); } data_array_tail = frame_data; // variable for calculating checksum unsigned char checksum = (0xFF - (byte_sum & 0xFF)); // if checksum is equal to 0xFF, proceed if(checksum==0xFF){ frame_data = data_array_head; // if data address is equal to room module address, proceed if(*frame_data==EEPROM.read(0)){ frame_data++; if(packet_format==0x00) Test_function(data_array_head++, data_array_tail); else if(packet_format==0x01) Change_relay_status(data_array_head++, data_array_tail); else if(packet_format==0x02) Sync_date_time(data_array_head++, data_array_tail); } } // send acknowledgement to the sender Send_ACK(); } }
//RS485 Prüfroutine int fAvailable () { return rs485.available (); }
/******************************************************************************* * Function Name : MessageHandle * Description : * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ uint8_t GizWits_MessageHandle(uint8_t * Message_Buf, uint8_t Length_buf) { Pro_HeadPartTypeDef * Recv_HeadPart = NULL; uint8_t ret = 0; //抓取一包 Pro_GetFrame(); //ACK超时重发机制 ret = GizWits_D2W_Resend_AckCmdHandle(); if(ret == 1) { #if(DEBUG==1) mySerial.println(F("Give up Resend!")); #endif } else if(ret == 2) { #if(DEBUG==1) mySerial.print(F("[Resend ACK --> Time / Num: "));mySerial.print(Wait_AckStruct.SendTime,DEC);mySerial.print(" / ");mySerial.print(Wait_AckStruct.SendNum,DEC);mySerial.print("]"); mySerial.println(""); #endif } if(packageFlag) { //验证校验码 if(CheckSum(UART_HandleStruct.Message_Buf, UART_HandleStruct.Message_Len) != UART_HandleStruct.Message_Buf[UART_HandleStruct.Message_Len - 1]) { Pro_W2D_ErrorCmdHandle(Error_AckSum, 0); packageFlag = 0; return 2; } //检测返回ACK状态 ret = GizWits_W2D_AckCmdHandle(); if(ret == 1) { #if(DEBUG==1) mySerial.println(F("ACK: SUCCESS! ...")); #endif } else if(ret == 2) { #if(DEBUG==1) mySerial.println(F("ACK: Report Again! ...")); #endif } else if(ret == 3) { #if(DEBUG==1) mySerial.println(F("ACK: SUCCESS--but--Time out! ...")); #endif } Recv_HeadPart = (Pro_HeadPartTypeDef *)UART_HandleStruct.Message_Buf; switch (Recv_HeadPart->Cmd) { case Pro_W2D_GetDeviceInfo_Cmd: Pro_W2D_GetMcuInfo(); break; case Pro_W2D_P0_Cmd: { switch(UART_HandleStruct.Message_Buf[sizeof(Pro_HeadPartTypeDef)]) { case P0_W2D_Control_Devce_Action: { Pro_W2D_CommonCmdHandle(); memcpy(Message_Buf, UART_HandleStruct.Message_Buf+sizeof(Pro_HeadPartP0CmdTypeDef), Length_buf); memset(&UART_HandleStruct.Message_Buf, 0, UART_HandleStruct.Message_Len); packageFlag = 0; return 0; } case P0_W2D_ReadDevStatus_Action: Pro_W2D_ReadDevStatusHandle(); break; default: break; } } break; case Pro_W2D_P0_Ack_Cmd: break; case Pro_W2D_Heartbeat_Cmd: Pro_W2D_CommonCmdHandle(); break; case Pro_W2D_ControlWifi_Config_Ack_Cmd: break; case Pro_W2D_ResetWifi_Ack_Cmd: break; case Pro_W2D_ReportWifiStatus_Cmd: Pro_W2D_WifiStatusHandle(); break; case Pro_W2D_ReportMCUReset_Cmd: Pr0_W2D_RequestResetDeviceHandle(); break; case Pro_W2D_ErrorPackage_Cmd: Pro_W2D_ErrorCmdHandle(Error_Other, 1); break; default: Pro_W2D_ErrorCmdHandle(Error_Cmd, 0); break; } memset(&UART_HandleStruct.Message_Buf, 0, UART_HandleStruct.Message_Len); packageFlag = 0; } return 1; }
//RS485 Leseroutine int fRead () { return rs485.read (); }
void setup() { Serial.begin(115200); #ifdef DEBUG Serial.println(F("Starting")); Serial.print(F("Free memory: ")); Serial.println(wifly.getFreeMemory(),DEC); #endif wifiSerial.begin(9600); if (!wifly.begin(&wifiSerial, &Serial)) { #ifdef DEBUG Serial.println(F("Failed to start wifly")); #endif wifly.terminal(); } wifly.leave(); delay(1000); wifly.scan(scanbuf, sizeof(scanbuf)); #ifdef DEBUG Serial.println(scanbuf); #endif snprintf_P(scanbuf, sizeof(scanbuf), PSTR("%s b 13 -71 c 00:1c:58:10:1c:90 | a b 10 -93 c 00:12:43:8a:ea:22 | a b 11 -92 c d8:30:62:5f:f2:b1"), "a"); /* Join wifi network if not already associated */ if (!wifly.isAssociated()) { /* Setup the WiFly to connect to a wifi network */ #ifdef DEBUG Serial.println(F("Joining network")); #endif wifly.setSSID(mySSID); wifly.setPassphrase(myPassword); wifly.enableDHCP(); wifly.setDHCP(1); wifly.save(); if (wifly.join()) { #ifdef DEBUG Serial.println(F("Joined wifi network")); #endif } else { #ifdef DEBUG Serial.println(F("Failed to join wifi network")); #endif wifly.terminal(); } } else { #ifdef DEBUG Serial.println(F("Already joined network")); #endif } wifly.setBroadcastInterval(0); // Turn off UPD broadcast #ifdef DEBUG Serial.print(F("MAC: ")); Serial.println(wifly.getMAC(macaddr, sizeof(macaddr))); Serial.print(F("IP: ")); Serial.println(wifly.getIP(buf, sizeof(buf))); #endif wifly.setDeviceID("Wifly-WebServer"); if (wifly.isConnected()) { #ifdef DEBUG Serial.println(F("Old connection active. Closing")); #endif wifly.close(); } wifly.setProtocol(WIFLY_PROTOCOL_TCP | WIFLY_PROTOCOL_UDP); if (wifly.getPort() != 80) { wifly.setPort(80); wifly.save(); #ifdef DEBUG Serial.println(F("Set port to 80, rebooting to make it work")); #endif wifly.reboot(); delay(3000); } Serial.println(F("Ready")); }
int Teleinfos::read(SoftwareSerial &cptSerial, Print &debug) { #ifdef DEBUG debug << F(">>getTeleinfo") << endl; #endif uint32_t startMillis = millis(); if ((lastRefresh !=0) && (startMillis - lastRefresh < VALID_FOR)) { return 1; } cptSerial.begin(1200); /* vider les infos de la dernière trame lue */ memset(Ligne,'\0',sizeof(Ligne)); int trameComplete=0; reset(); while (!trameComplete) { while(CaractereRecu != 0x02) { if (millis()-startMillis > EDF_TIMEOUT) { cptSerial.end(); return ERROR; } // boucle jusqu'a "Start Text 002" début de la trame if (cptSerial.available()) { CaractereRecu = cptSerial.read() & 0x7F; } } while (CaractereRecu != 0x03) { i=0; while(CaractereRecu != 0x03 && CaractereRecu != 0x0D /* fin de ligne */) { if (millis()-startMillis > EDF_TIMEOUT) { cptSerial.end(); return ERROR; } // Tant qu'on est pas arrivé à "EndText 003" Fin de trame ou que la trame est incomplète int available = cptSerial.available(); #ifdef DEBUG if (available > SERIAL_BUFFER_OVERFLOW) { debug << "O " << available << endl; } #endif if (available) { CaractereRecu = cptSerial.read() & 0x7F; Ligne[i++]=CaractereRecu; } } if (i > 0) { Ligne[i++] = '\0'; #ifdef DEBUGLIGNE debug << Ligne << endl; #endif decodeLigne(Ligne, debug); memset(Ligne,'\0',sizeof(Ligne)); // on vide la ligne pour la lecture suivante if (CaractereRecu == 0x0D) { CaractereRecu = '\0'; } } } // on vérifie si on a une trame complète ou non trameComplete = isTrameComplete(debug); #ifdef DEBUG debug << F("complete ? ") << trameComplete << endl; #endif } #ifdef DEBUG debug << F("<<getTeleinfo") << endl; #endif cptSerial.end(); lastRefresh = millis(); return millis() - startMillis; }
// update all the fields from the incoming $GPRMC string boolean dGPS::update(float desLat, float desLon){ while(true){ int byteGPS=-1; byteGPS=gpsSerial.read(); //read a byte from the serial port if (byteGPS == -1) { // See if the port is empty yet delay(5); } else { linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer conta++; if (byteGPS==13){ // If the received byte is = to 13, end of transmission cont=0; bien=0; for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR if (linea[i]==comandoGPR[i-1]){ bien++; } } if(bien==6){ // If yes, continue and process the data Serial.print(""); // For some reason, this needs to be here or you won't populate variables. If anyone solves this problem, let us know. Serial.print(""); Serial.print("-"); /*Serial.println(linea); //Print out the incoming GPRMC string (just for reference)*/ //------------------------------------------ // Get Time (UTC) char *data = ""; memset(data, 0, sizeof(data)); data = dGPS::subStr(linea, ",", 2); fTime = atol(data); delay(5); //------------------------------------------ // Get Status memset(data, 0, sizeof(data)); cStatus = dGPS::subStr(linea, ",", 3); delay(5); //------------------------------------------ // Get Latitude (degrees) char *hemi; memset(data, 0, sizeof(data)); char *cLat = ""; cLat = dGPS::subStr(linea, ",", 4); fLat = strtod(cLat, NULL); fLat = conv_coords(fLat); hemi = subStr(linea, ",", 5); // Gets the hemisphere. if(*hemi == 'S') {fLat = fLat*-1;} // Setting the Latitude. delay(5); //------------------------------------------ // Get Longitude (degrees) memset(data, 0, sizeof(data)); char *cLon = ""; cLon = dGPS::subStr(linea, ",", 6); fLon = strtod(cLon, NULL); fLon = conv_coords(fLon); hemi = subStr(linea, ",", 7); // Gets the hemisphere. if(*hemi == 'W') {fLon = fLon*-1;} // Setting the Longitude. delay(5); //------------------------------------------ // Get Velocity (knots) memset(data, 0, sizeof(data)); char *cVel = ""; cVel = dGPS::subStr(linea, ",", 8); fVel = strtod(cVel, NULL); delay(5); //------------------------------------------ // Get Heading (degrees) memset(data, 0, sizeof(data)); char *cHead = ""; cHead = dGPS::subStr(linea, ",", 9); fHead = strtod(cHead, NULL); delay(5); //------------------------------------------ // Get Date (UTC) memset(data, 0, sizeof(data)); char *cDate = ""; cDate = dGPS::subStr(linea, ",", 10); lDate = strtod(cDate, NULL); delay(5); //------------------------------------------ // Get Distance between current location and destination coordinates (kilometers) float t=((desLon-fLon)*22)/1260; // difference between the longitudes in radians float cdist=acos(cos(((90-desLat)*22)/1260)*cos(((90-fLat)*22)/1260)+sin(((90-desLat)*22)/1260)*sin(((90-fLat)*22)/1260)*cos(t)); //angular distance fdist=6378.1*cdist; // distance= radius of earth * angular distance //------------------------------------------ // Get Azimuth of the destination from current location float cazimuth=asin((sin(((90-desLat)*22)/1260)*sin(t))/sin(cdist)); // temporary azimuth(in radians) fazimuth=((cazimuth*1260)/22); // azimuth in degrees //------------------------------------------ // Get Mode Indicator memset(data, 0, sizeof(data)); char *cstr= subStr(linea,",",11); // Takes the whole substring at the end of the GPRMC string (eg:A*0C) //Serial.println(cstr); mode=subStr(cstr, "*", 1); // picks up mode indicator A from A*0C delay(5); //------------------------------------------ // Get Checksum value from packet and compute checksum from packet. // used only if user entered Y or y for filtering out only valid data memset(data, 0, sizeof(data)); checkSum = subStr(cstr, "*", 2); // picks up checksum 0C from A*0C delay(5); computedSum=Csum(linea); // compute checksum from the incoming string conta=0; // Reset the buffer memset(linea, 0, sizeof(linea)); break; } conta=0; // Reset the buffer memset(linea, 0, sizeof(linea)); } } } // END WHILE STATEMENT return true; }
void set_bt_device_name() { serial.write('A'); delay(100); serial.write('T'); delay(100); serial.write('N'); delay(100); serial.write('='); delay(100); serial.write('p'); delay(100); serial.write('e'); delay(100); serial.write('n'); delay(100); serial.write('t'); delay(100); serial.write('i'); delay(100); serial.write('k'); delay(100); serial.write('e'); delay(100); serial.write(' '); delay(100); serial.write('l'); delay(100); serial.write('e'); delay(100); serial.write('d'); delay(100); serial.write('\r'); delay(200); }
void dGPS::init(){ gpsSerial.begin(9600); //start serial for communication with GPS memset(linea, ' ', sizeof(linea)); }
LoRaModem::LoRaModem() { _LoRaSerial.begin(9600); _LoRaSerial.setTimeout(100); };
void setup() { mySerial.begin(19200); Serial.begin(19200); delay(500); }
void LoRaModem::_sendSerial(String message) { DEBUG_PRINT("> " + message); _LoRaSerial.read(); _LoRaSerial.println(message); };
void setup() { Serial.begin(9600); mySerial1.begin(9600); mySerial2.begin(9600); }
// function to send acknowledgement to sender void Send_ACK(){ unsigned char ack = {0x7E, 0x00, 0x06, 0x01, 0x00, x, x, 0x01, 0xFF, 0xFD}; // send acknowledgment data to the sender XBee.write(ack, sizeof(ack)); }
void NTGRFIDReader::NTGRFIDReaderSetup(){ //Set serial connection. softwareSerial.begin(9600); }
//------------------------------------------------------------------------------------------- void LCD::toggleReverseMode() { //Everything that was black is now white and vise versa serial.write(0x7C); serial.write(0x12); //CTRL r }