Testing out the PPD42 Air Quality Sensor, with an MSP430 Launchpad and graphing the data with GNUplot.
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.

230 lines
4.9 KiB

5 years ago
  1. /*------------------------------------------------------------------------
  2. | Zystem is a native interface for message reporting in java.
  3. | Copyright 2003-2004 by Trent Jarvi taj@www.linux.org.uk.
  4. |
  5. | This library is free software; you can redistribute it and/or
  6. | modify it under the terms of the GNU Library General Public
  7. | License as published by the Free Software Foundation; either
  8. | version 2 of the License, or (at your option) any later version.
  9. |
  10. | This library is distributed in the hope that it will be useful,
  11. | but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. | Library General Public License for more details.
  14. |
  15. | You should have received a copy of the GNU Library General Public
  16. | License along with this library; if not, write to the Free
  17. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. --------------------------------------------------------------------------*/
  19. package gnu.io;
  20. import java.io.RandomAccessFile;
  21. public class Zystem
  22. {
  23. public static final int SILENT_MODE = 0;
  24. public static final int FILE_MODE = 1;
  25. public static final int NET_MODE = 2;
  26. public static final int MEX_MODE = 3;
  27. public static final int PRINT_MODE = 4;
  28. public static final int J2EE_MSG_MODE = 5;
  29. static int mode;
  30. static
  31. {
  32. /*
  33. The rxtxZystem library uses Python code and is not
  34. included with RXTX. A seperate library will be released
  35. to avoid potential license conflicts.
  36. Trent Jarvi taj@www.linux.org.uk
  37. */
  38. //System.loadLibrary( "rxtxZystem" );
  39. mode = SILENT_MODE;
  40. }
  41. private static String target;
  42. public Zystem( int m ) throws UnSupportedLoggerException
  43. {
  44. mode = m;
  45. startLogger( "asdf" );
  46. }
  47. public void startLogger( ) throws UnSupportedLoggerException
  48. {
  49. if ( mode == SILENT_MODE || mode == PRINT_MODE )
  50. {
  51. //nativeNetInit( );
  52. return;
  53. }
  54. throw new UnSupportedLoggerException( "Target Not Allowed" );
  55. }
  56. /* accept the host or file to log to. */
  57. public void startLogger( String t ) throws UnSupportedLoggerException
  58. {
  59. target = t;
  60. /*
  61. if ( mode == NET_MODE )
  62. {
  63. nativeNetInit( );
  64. }
  65. if ( nativeInit( ) )
  66. {
  67. throw new UnSupportedLoggerException(
  68. "Port initializion failed" );
  69. }
  70. */
  71. return;
  72. }
  73. public void finalize()
  74. {
  75. /*
  76. if ( mode == NET_MODE )
  77. {
  78. nativeNetFinalize( );
  79. }
  80. nativeFinalize();
  81. */
  82. mode = SILENT_MODE;
  83. target = null;
  84. }
  85. public void filewrite( String s )
  86. {
  87. try {
  88. RandomAccessFile w =
  89. new RandomAccessFile( target, "rw" );;
  90. w.seek( w.length() );
  91. w.writeBytes( s );
  92. w.close();
  93. } catch ( Exception e ) {
  94. System.out.println("Debug output file write failed");
  95. }
  96. }
  97. public boolean report( String s)
  98. {
  99. if ( mode == NET_MODE )
  100. {
  101. // return( nativeNetReportln( s ) );
  102. }
  103. else if ( mode == PRINT_MODE )
  104. {
  105. System.out.println( s );
  106. return( true );
  107. }
  108. else if ( mode == MEX_MODE )
  109. {
  110. // return( nativeMexReport( s ) );
  111. }
  112. else if ( mode == SILENT_MODE )
  113. {
  114. return( true );
  115. }
  116. else if ( mode == FILE_MODE )
  117. {
  118. filewrite( s );
  119. }
  120. else if ( mode == J2EE_MSG_MODE )
  121. {
  122. return( false );
  123. }
  124. return( false );
  125. }
  126. public boolean reportln( )
  127. {
  128. boolean b;
  129. if ( mode == NET_MODE )
  130. {
  131. // b= nativeNetReportln( "\n" );
  132. // return(b);
  133. }
  134. else if ( mode == PRINT_MODE )
  135. {
  136. System.out.println( );
  137. return( true );
  138. }
  139. else if ( mode == MEX_MODE )
  140. {
  141. // b = nativeMexReportln( "\n" );
  142. // return(b);
  143. }
  144. else if ( mode == SILENT_MODE )
  145. {
  146. return( true );
  147. }
  148. else if ( mode == FILE_MODE )
  149. {
  150. filewrite( "\n" );
  151. }
  152. else if ( mode == J2EE_MSG_MODE )
  153. {
  154. return( false );
  155. }
  156. return( false );
  157. }
  158. public boolean reportln( String s)
  159. {
  160. boolean b;
  161. if ( mode == NET_MODE )
  162. {
  163. // b= nativeNetReportln( s + "\n" );
  164. // return(b);
  165. }
  166. else if ( mode == PRINT_MODE )
  167. {
  168. System.out.println( s );
  169. return( true );
  170. }
  171. else if ( mode == MEX_MODE )
  172. {
  173. // b = nativeMexReportln( s + "\n" );
  174. // return(b);
  175. }
  176. else if ( mode == SILENT_MODE )
  177. {
  178. return( true );
  179. }
  180. else if ( mode == FILE_MODE )
  181. {
  182. filewrite( s + "\n" );
  183. }
  184. else if ( mode == J2EE_MSG_MODE )
  185. {
  186. return( false );
  187. }
  188. return( false );
  189. }
  190. /*
  191. private native boolean nativeInit( );
  192. private native void nativeFinalize();
  193. */
  194. /* open and close the socket */
  195. /*
  196. private native boolean nativeNetInit( );
  197. private native void nativeNetFinalize();
  198. */
  199. /* dumping to a remote machine */
  200. /*
  201. public native boolean nativeNetReport( String s );
  202. public native boolean nativeNetReportln( String s );
  203. */
  204. /* specific to Matlab */
  205. /*
  206. public native boolean nativeMexReport( String s );
  207. public native boolean nativeMexReportln( String s );
  208. */
  209. }