You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

pl2303_gps.ino 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* USB Host to PL2303-based USB GPS unit interface */
  2. /* Navibee GM720 receiver - Sirf Star III */
  3. /* USB support */
  4. #include <usbhub.h>
  5. /* CDC support */
  6. #include <cdcacm.h>
  7. #include <cdcprolific.h>
  8. // Satisfy the IDE, which needs to see the include statment in the ino too.
  9. #ifdef dobogusinclude
  10. #include <spi4teensy3.h>
  11. #include <SPI.h>
  12. #endif
  13. class PLAsyncOper : public CDCAsyncOper {
  14. public:
  15. uint8_t OnInit(ACM *pacm);
  16. };
  17. uint8_t PLAsyncOper::OnInit(ACM *pacm) {
  18. uint8_t rcode;
  19. // Set DTR = 1
  20. rcode = pacm->SetControlLineState(1);
  21. if(rcode) {
  22. ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
  23. return rcode;
  24. }
  25. LINE_CODING lc;
  26. lc.dwDTERate = 4800; //default serial speed of GPS unit
  27. lc.bCharFormat = 0;
  28. lc.bParityType = 0;
  29. lc.bDataBits = 8;
  30. rcode = pacm->SetLineCoding(&lc);
  31. if(rcode)
  32. ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
  33. return rcode;
  34. }
  35. USB Usb;
  36. USBHub Hub(&Usb);
  37. PLAsyncOper AsyncOper;
  38. PL2303 Pl(&Usb, &AsyncOper);
  39. uint32_t read_delay;
  40. #define READ_DELAY 100
  41. void setup() {
  42. Serial.begin(115200);
  43. #if !defined(__MIPSEL__)
  44. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  45. #endif
  46. Serial.println("Start");
  47. if(Usb.Init() == -1)
  48. Serial.println("OSCOKIRQ failed to assert");
  49. delay(200);
  50. }
  51. void loop() {
  52. uint8_t rcode;
  53. uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
  54. uint16_t rcvd = 64;
  55. Usb.Task();
  56. if(Pl.isReady()) {
  57. /* reading the GPS */
  58. if((long)(millis() - read_delay) >= 0L) {
  59. read_delay += READ_DELAY;
  60. rcode = Pl.RcvData(&rcvd, buf);
  61. if(rcode && rcode != hrNAK)
  62. ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
  63. if(rcvd) { //more than zero bytes received
  64. for(uint16_t i = 0; i < rcvd; i++) {
  65. Serial.print((char)buf[i]); //printing on the screen
  66. }//for( uint16_t i=0; i < rcvd; i++...
  67. }//if( rcvd
  68. }//if( read_delay > millis()...
  69. }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
  70. }