silenius

Untitled

Feb 10th, 2021 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "heltec.h"
  2.  
  3.  
  4. //long lastReceiveTime = 0;
  5. unsigned int counter = 0;
  6. float snr = 0;
  7. String nema;
  8. short rssi;
  9. short packSize;
  10. String packet;
  11. double latconv = 0;
  12. double longconv = 0;
  13. float dirtylong = 0;
  14. float dirtylat = 0;
  15.  
  16. void setup(){
  17.   Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
  18.   LoRa.setSpreadingFactor(12);
  19.   LoRa.onReceive(onReceive);
  20.   LoRa.receive();
  21. }
  22.  
  23. void loop(){
  24.   delay(1000);
  25.   LoRa.receive();
  26.   displaySendReceive();
  27. }
  28.  
  29. void displaySendReceive()
  30. {
  31.   Heltec.display -> drawString(0, 0, "Received Size " + String(packSize));
  32.   Heltec.display -> drawString(0, 10, String(latconv,10));
  33.   Heltec.display -> drawString(0, 20, String(longconv,10));
  34.   Heltec.display -> drawString(0, 40, "RSSI" + String(rssi) + "db " + "  SNR " + String(snr, 2));
  35.   Heltec.display -> drawString(0, 50, "Counter:  " + (String)(counter-1));
  36.   Heltec.display -> display();
  37.   Heltec.display -> clear();
  38. }
  39.  
  40. void onReceive(int packetSize){
  41.   packet = "";
  42.   packSize = packetSize;
  43.   while (LoRa.available()){
  44.     packet += (char) LoRa.read();
  45.   }
  46.   snr = LoRa.packetSnr();
  47.   rssi = LoRa.packetRssi();
  48.   convert();
  49.   counter++;
  50.  
  51.   makestring();
  52.  
  53. }
  54.  
  55. void convert(){
  56.   short degLo = 0;
  57.   short degLat =0;
  58.   double minLat = 0;
  59.   double minLo = 0;
  60.   unsigned long latitude = 0;
  61.   unsigned long longitude = 0;
  62.  
  63.   latitude = uint8_t(packet[0])*65536 + uint8_t(packet[1])*256 + uint8_t(packet[2]);
  64.   latconv = (latitude / 93206.75) - 90;
  65.   degLat = latconv;
  66.   minLat = (latconv - degLat)*60;
  67.   dirtylat = (degLat*100) + minLat;
  68.   longitude = uint8_t(packet[3])*65536 + uint8_t(packet[4])*256 + uint8_t(packet[5]);
  69.   longconv = (longitude / 46603.375) - 180;
  70.   degLo = longconv;
  71.   minLo = (longconv - degLo)*60;
  72.   dirtylong = (degLo*100) + minLo;
  73. }
  74.  
  75. void makestring(){
  76.   char toSend[90];
  77.   int Time = 0; //time, what is time
  78.   int ndx=0;
  79.   char lat[9];
  80.   char lon[11];
  81.   // dtostrf(altf, 1, 1, alt);                  //skipping that for now
  82.   dtostrf(dirtylat, 1, 6, lat);
  83.   dtostrf(dirtylong, 1, 5, lon);
  84.  
  85.  
  86.   toSend[ndx++] = '§';
  87.   toSend[ndx++] = 'G';
  88.   toSend[ndx++] = 'P';
  89.   toSend[ndx++] = 'G';
  90.   toSend[ndx++] = 'G';
  91.   toSend[ndx++] = 'A';
  92.   toSend[ndx++] = ',';
  93.    
  94.   short hours = Time/3600;                      //all that time bollocks
  95.   if(hours>9){
  96.     toSend[ndx++] = '0' +(hours/10);
  97.     toSend[ndx++] = '0' +(hours%10);
  98.   }
  99.   else{
  100.     toSend[ndx++] = '0';
  101.     toSend[ndx++] = '0' + hours;
  102.   }
  103.   short minutes = (Time%3600)/60;
  104.   if(minutes>9){
  105.     toSend[ndx++] = '0' +(minutes/10);
  106.     toSend[ndx++] = '0' +(minutes%10);
  107.   }
  108.   else{
  109.     toSend[ndx++] = '0';
  110.     toSend[ndx++] = '0' + minutes;
  111.   }
  112.   short seconds = (Time%60);
  113.   if(seconds>9){
  114.     toSend[ndx++] = '0' +(seconds/10);
  115.     toSend[ndx++] = '0' +(seconds%10);
  116.   }  
  117.   else{
  118.     toSend[ndx++] = '0';
  119.     toSend[ndx++] = '0' + seconds;
  120.   }
  121.   toSend[ndx++]='.';
  122.   for(int i = 0;i<2;i++){
  123.     toSend[ndx++] = '0';
  124.   }
  125.   toSend[ndx++]= ',';
  126.  
  127.    
  128.   if(dirtylat<1000){                              //latitude:     first see if we need to add a zero
  129.     toSend[ndx++] = '0';
  130.   }
  131.   if(dirtylat<100){                              //and maybe another
  132.     toSend[ndx++] = '0';
  133.   }
  134.   if(dirtylat<10){                              //while we are at it..
  135.     toSend[ndx++] = '0';
  136.   }
  137.   for(int i = 0;i<8;i++){                    
  138.     toSend[ndx++] = lat[i];
  139.   }
  140.   toSend[ndx++] = ',';
  141.   toSend[ndx++] = 'N';                         //I'm gonna hardcode north because lazy
  142.   toSend[ndx++] = ',';
  143.  
  144.  
  145.   if(dirtylong<10000){                          //same for long
  146.     toSend[ndx++] = '0';
  147.   }
  148.   if(dirtylong<1000){                              
  149.     toSend[ndx++] = '0';
  150.   }
  151.   if(dirtylong<100){                              
  152.     toSend[ndx++] = '0';
  153.   }
  154.     if(dirtylong<10){                            
  155.     toSend[ndx++] = '0';
  156.   }
  157.   for(int i = 0; i<10; i++){                    
  158.     if(lon[i]!=NULL){
  159.       toSend[ndx++] = lon[i];
  160.     }
  161.   }
  162.   toSend[ndx++] = ',';
  163.   toSend[ndx++] = 'E';                           //hardcoded as well
  164.   toSend[ndx++] = ',';
  165.   toSend[ndx++] = '1';
  166.   toSend[ndx++] = ',';
  167.   toSend[ndx++] = '5';          //next up is the number of satellites, anything between 4 and 10 willl do
  168.   toSend[ndx++] = ',';
  169.   toSend[ndx++] = '1';          //now we send the relative accuracy. 1.5 is common
  170.   toSend[ndx++] = '.';
  171.   toSend[ndx++]= '5';
  172.   toSend[ndx++]= ',';
  173.   //for(int i = 0; i<10;i++){  //heres this biggie. the altitude in meters
  174.   //  if(alt[i]!=NULL){
  175.   //    toSend[ndx++] = alt[i];
  176.   //  }
  177.   //}
  178.  /* toSend[ndx++] = '2';      // jk, I'm gonna hardcode that as well
  179.   toSend[ndx++] = '0';
  180.   toSend[ndx++] = '.';
  181.   toSend[ndx++] = '0';
  182.   toSend[ndx++] = '0';
  183.   toSend[ndx++] = ',';
  184.   toSend[ndx++] = 'M';
  185.   toSend[ndx++] = ',';
  186.   toSend[ndx++] = '-';         //next up is the altitude above elisoidal. -34.2 seems to be the standard.
  187.   toSend[ndx++] = '3';
  188.   toSend[ndx++] = '4';
  189.   toSend[ndx++] = '.';
  190.   toSend[ndx++] = '2';
  191.   toSend[ndx++] = ',';
  192.   toSend[ndx++] = 'M';
  193.   toSend[ndx++] = ',';
  194.   toSend[ndx++] = '0';
  195.   toSend[ndx++] = '.';
  196.   toSend[ndx++] = '1';
  197.   toSend[ndx++] = ',';
  198.   for(int i = ndx; i<90;i++){ //remove empty chars
  199.     toSend[i] = NULL;
  200.   }
  201. */
  202.  
  203.  Serial.println(toSend);
  204.  
  205.  
  206.  
  207.    /*
  208.   makeCheck(toSend, ndx);   //do checksum
  209.   ndx+=3;
  210.   toSend[ndx] = '\0';
  211.   */
  212.   // nema = String(toSend);
  213. }
  214.  
  215.  
  216. 08:09:40.486 -> Core 1 register dump:
  217. 08:09:40.486 -> PC      : 0x400d1340  PS      : 0x00060231  A0      : 0x800d1554  A1      : 0x3ffbe770  
  218. 08:09:40.486 -> A2      : 0x3ffc128c  A3      : 0x00000001  A4      : 0x3ffbfea8  A5      : 0x00000000  
  219. 08:09:40.486 -> A6      : 0x3ffbff38  A7      : 0x3ffb0060  A8      : 0xffffffa7  A9      : 0x3ffbe7f0  
  220. 08:09:40.520 -> A10     : 0x3ffbe847  A11     : 0x3ffbe851  A12     : 0x00000001  A13     : 0x00000005  
  221. 08:09:40.520 -> A14     : 0x0000002e  A15     : 0x00000000  SAR     : 0x00000014  EXCCAUSE: 0x00000004  
  222. 08:09:40.520 -> EXCVADDR: 0x00000000  LBEG    : 0x400029ac  LEND    : 0x400029cb  LCOUNT  : 0x00000000  
  223. 08:09:40.520 -> Core 1 was running in ISR context:
  224. 08:09:40.520 -> EPC1    : 0x400d1340  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x40082cc7
  225. 08:09:40.553 ->
  226. 08:09:40.553 -> ELF file SHA256: 0000000000000000
  227. 08:09:40.553 ->
  228. 08:09:40.553 -> Backtrace: 0x400d1340:0x3ffbe770 0x400d1551:0x3ffbe8d0 0x400d20f4:0x3ffbe8f0 0x400d210a:0x3ffbe910 0x40080f5d:0x3ffbe930 0x40081ec1:0x3ffbe950 0x400ed303:0x3ffbc650 0x400d8757:0x3ffbc670 0x400881c6:0x3ffbc690 0x400863c5:0x3ffbc6b0
  229.  
  230. PC: 0x400d1340: makestring() at C:\Users\chaos\Documents\Arduino\gps_receiver/gps_receiver.ino line 129
  231. EXCVADDR: 0x00000000
  232.  
  233. Decoding stack results
  234. 0x400d1340: makestring() at C:\Users\chaos\Documents\Arduino\gps_receiver/gps_receiver.ino line 129
  235. 0x400d1551: onReceive(int) at C:\Users\chaos\Documents\Arduino\gps_receiver/gps_receiver.ino line 52
  236. 0x400d20f4: LoRaClass::handleDio0Rise() at C:\Users\chaos\Documents\Arduino\libraries\Heltec_ESP32_Dev-Boards\src\lora\LoRa.cpp line 518
  237. 0x400d210a: LoRaClass::onDio0Rise() at C:\Users\chaos\Documents\Arduino\libraries\Heltec_ESP32_Dev-Boards\src\lora\LoRa.cpp line 548
  238. 0x40080f5d: __onPinInterrupt at C:\Users\chaos\Documents\Arduino\hardware\heltec\esp32\cores\esp32\esp32-hal-gpio.c line 220
  239. 0x400ed303: esp_pm_impl_waiti at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/pm_esp32.c line 492
  240. 0x400d8757: esp_vApplicationIdleHook at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/freertos_hooks.c line 63
  241. 0x400881c6: prvIdleTask at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/tasks.c line 3382
  242. 0x400863c5: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143
  243.  
  244.  
  245.  
Add Comment
Please, Sign In to add comment