silenius

Untitled

Feb 9th, 2021
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Arduino.h"
  2. #include "heltec.h"
  3.  
  4.  
  5. long lastReceiveTime = 0;
  6. unsigned int counter = 0;
  7. float snr = 0;
  8. String nema;
  9. int rssi;
  10. String packSize = "--";
  11. String packet;
  12. double latconv = 0;
  13. double longconv = 0;
  14. float dirtylong = 0;
  15. float dirtylat = 0;
  16.  
  17. void setup(){
  18.   Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
  19.   LoRa.setSpreadingFactor(12);
  20.   LoRa.onReceive(onReceive);
  21.   LoRa.receive();
  22. }
  23.  
  24. void loop(){
  25.   delay(1000);
  26.   LoRa.receive();
  27.   displaySendReceive();
  28. }
  29.  
  30. void displaySendReceive()
  31. {
  32.   Heltec.display -> drawString(0, 0, "Received Size " + String(packSize));
  33.   Heltec.display -> drawString(0, 10, String(latconv,10));
  34.   Heltec.display -> drawString(0, 20, String(longconv,20));
  35.   Heltec.display -> drawString(0, 40, "RSSI" + String(rssi) + "db " + "  SNR " + String(snr, 2));
  36.   Heltec.display -> drawString(0, 50, "Counter:  " + (String)(counter-1));
  37.   Heltec.display -> display();
  38.   Heltec.display -> clear();
  39. }
  40.  
  41. void onReceive(int packetSize){
  42.   packet = "";
  43.   packSize = String(packetSize,DEC);
  44.   while (LoRa.available()){
  45.     packet += (char) LoRa.read();
  46.   }
  47.   snr = LoRa.packetSnr();
  48.   rssi = LoRa.packetRssi();
  49.   convert();
  50.   counter++;
  51.   makestring();
  52. }
  53.  
  54. void convert(){
  55.   short degLo = 0;
  56.   short degLat =0;
  57.   double minLat = 0;
  58.   double minLo = 0;
  59.   unsigned long latitude = 0;
  60.   unsigned long longitude = 0;
  61.  
  62.   latitude = uint8_t(packet[0])*65536 + uint8_t(packet[1])*256 + uint8_t(packet[2]);
  63.   latconv = (latitude / 93206.75) - 90;
  64.   degLat = latconv;
  65.   minLat = (latconv - degLat)*60;
  66.   dirtylat = (degLat*100) + minLat;
  67.   longitude = uint8_t(packet[3])*65536 + uint8_t(packet[4])*256 + uint8_t(packet[5]);
  68.   longconv = (longitude / 46603.375) - 180;
  69.   degLo = longconv;
  70.   minLo = (longconv - degLo)*60;
  71.   dirtylong = (degLo*100) + minLo;
  72. }
  73.  
  74. void makestring(){
  75.   char toSend[100];
  76.   int Time = 0; //time, what is time
  77.   int ndx=0;
  78.   char lat[9];
  79.   char lon[11];
  80.   // dtostrf(altf, 1, 1, alt);                  //skipping that for now
  81.   dtostrf(dirtylat, 1, 6, lat);
  82.   dtostrf(dirtylong, 1, 5, lon);
  83.  
  84.  
  85.   toSend[ndx++] = 'ยง';
  86.   toSend[ndx++] = 'G';
  87.   toSend[ndx++] = 'P';
  88.   toSend[ndx++] = 'R';
  89.   toSend[ndx++] = 'M';
  90.   toSend[ndx++] = 'C';
  91.   toSend[ndx++] = ',';
  92.    
  93.   int hours = Time/3600;                      //all that time bollocks
  94.   if(hours>9){
  95.     toSend[ndx++] = '0' +(hours/10);
  96.     toSend[ndx++] = '0' +(hours%10);
  97.   }
  98.   else{
  99.     toSend[ndx++] = '0';
  100.     toSend[ndx++] = '0' + hours;
  101.   }
  102.   int minutes = (Time%3600)/60;
  103.   if(minutes>9){
  104.     toSend[ndx++] = '0' +(minutes/10);
  105.     toSend[ndx++] = '0' +(minutes%10);
  106.   }
  107.   else{
  108.     toSend[ndx++] = '0';
  109.     toSend[ndx++] = '0' + minutes;
  110.   }
  111.   int seconds = (Time%60);
  112.   if(seconds>9){
  113.     toSend[ndx++] = '0' +(seconds/10);
  114.     toSend[ndx++] = '0' +(seconds%10);
  115.   }  
  116.   else{
  117.     toSend[ndx++] = '0';
  118.     toSend[ndx++] = '0' + seconds;
  119.   }
  120.   toSend[ndx++]='.';
  121.   for(int i = 0;i<2;i++){
  122.     toSend[ndx++] = '0';
  123.   }
  124.   toSend[ndx++]= ',';
  125.  
  126.    
  127.   if(dirtylat<1000){                              //latitude:     first see if we need to add a zero
  128.     toSend[ndx++] = '0';
  129.   }
  130.   if(dirtylat<100){                              //and maybe another
  131.     toSend[ndx++] = '0';
  132.   }
  133.   if(dirtylat<10){                              //while we are at it..
  134.     toSend[ndx++] = '0';
  135.   }
  136.   for(int i = 0;i<8;i++){                    
  137.     toSend[ndx++] = lat[i];
  138.   }
  139.   toSend[ndx++] = ',';
  140.   toSend[ndx++] = 'N';                         //I'm gonna hardcode north because lazy
  141.   toSend[ndx++] = ',';
  142.  
  143.  
  144.   if(dirtylong<10000){                          //same for long
  145.     toSend[ndx++] = '0';
  146.   }
  147.   if(dirtylong<1000){                              
  148.     toSend[ndx++] = '0';
  149.   }
  150.   if(dirtylong<100){                              
  151.     toSend[ndx++] = '0';
  152.   }
  153.     if(dirtylong<10){                            
  154.     toSend[ndx++] = '0';
  155.   }
  156.   for(int i = 0; i<10; i++){                    
  157.     if(lon[i]!=NULL){
  158.       toSend[ndx++] = lon[i];
  159.     }
  160.   }
  161.   toSend[ndx++] = ',';
  162.   toSend[ndx++] = 'E';                           //hardcoded as well
  163.   toSend[ndx++] = ',';
  164.   toSend[ndx++] = '1';
  165.   toSend[ndx++] = ',';
  166.   toSend[ndx++] = '5';          //next up is the number of satellites, anything between 4 and 10 willl do
  167.   toSend[ndx++] = ',';
  168.   toSend[ndx++] = '1';          //now we send the relative accuracy. 1.5 is common
  169.   toSend[ndx++] = '.';
  170.   toSend[ndx++]= '5';
  171.   toSend[ndx++]= ',';
  172.   //for(int i = 0; i<10;i++){  //heres this biggie. the altitude in meters
  173.   //  if(alt[i]!=NULL){
  174.   //    toSend[ndx++] = alt[i];
  175.   //  }
  176.   //}
  177.   toSend[ndx++] = '2';      // jk, I'm gonna hardcode that as well
  178.   toSend[ndx++] = '0';
  179.   toSend[ndx++] = '.';
  180.   toSend[ndx++] = '0';
  181.   toSend[ndx++] = '0';
  182.   toSend[ndx++] = ',';
  183.   toSend[ndx++] = 'M';
  184.   toSend[ndx++] = ',';
  185.   toSend[ndx++] = '-';         //next up is the altitude above elisoidal. -34.2 seems to be the standard.
  186.   toSend[ndx++] = '3';
  187.   toSend[ndx++] = '4';
  188.   toSend[ndx++] = '.';
  189.   toSend[ndx++] = '2';
  190.   toSend[ndx++] = ',';
  191.   toSend[ndx++] = 'M';
  192.   toSend[ndx++] = ',';
  193.   toSend[ndx++] = '0';
  194.   toSend[ndx++] = '.';
  195.   toSend[ndx++] = '1';
  196.   toSend[ndx++] = ',';
  197.  
  198.   //Serial.println(String(toSend));
  199.   /*
  200.   for(int i = ndx; i<100;i++){ //remove empty chars
  201.     toSend[i] = NULL;
  202.   }
  203.  
  204.   */
  205.    /*
  206.  makeCheck(toSend, ndx);   //do checksum
  207.   ndx+=3;
  208.   toSend[ndx] = '\0';
  209.   */
  210. }
  211.  
Advertisement
Add Comment
Please, Sign In to add comment