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.

53 lines
1.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('uartPort.php');
  3. class gpsController extends Thread {
  4. var $_uart_port = '';
  5. var $_thread_state = 0;
  6. function __construct( $port ){
  7. $this->_uart_port = $port;
  8. $this->start();
  9. }
  10. function __destruct(){
  11. if( $this->_thread_state > 1 ){
  12. $this->_thread_state = 3;
  13. while( $this->_thread_state == 3 ) usleep( 10 );
  14. };
  15. }
  16. function init_gps(){
  17. return true;
  18. }
  19. private function parse_message( $msg ){
  20. echo $msg . "\n";
  21. }
  22. public function run(){
  23. $uart = new uartPort();
  24. if( $uart ){
  25. if( $uart->deviceSet( $this->_uart_port ) ){
  26. $uart->confBaudRate(9600);
  27. $uart->confParity("none");
  28. $uart->confCharacterLength(8);
  29. $uart->confStopBits(1);
  30. $uart->confFlowControl("none");
  31. if( $uart->deviceOpen() ){
  32. $this->_thread_state = 2;
  33. echo "Thread Started\n";
  34. while( $this->_thread_state < 3 ){
  35. $read = trim( $uart->readPort() );
  36. if( $read != '' ){
  37. $this->parse_message( $read );
  38. };
  39. usleep(10);
  40. };
  41. $uart->deviceClose();
  42. };
  43. };
  44. };
  45. echo "Thread Finished\n";
  46. $this->_thread_state = 4;
  47. }
  48. }
  49. ?>