PageRenderTime 77ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/org/xtce/toolkit/examples/ProcessEcssHousekeepingExample.java

https://gitlab.com/dovereem/xtcetools
Java | 367 lines | 92 code | 57 blank | 218 comment | 9 complexity | a4b5561d80d9ff28f04a7ea264178f47 MD5 | raw file
  1. /* Copyright 2015 David Overeem (dovereem@startmail.com)
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. *
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.xtce.toolkit.examples;
  18. import java.io.File;
  19. import java.util.List;
  20. import java.util.ArrayList;
  21. import org.xtce.toolkit.XTCEContainerContentEntry;
  22. import org.xtce.toolkit.XTCEContainerContentModel;
  23. import org.xtce.toolkit.XTCEContainerEntryValue;
  24. import org.xtce.toolkit.XTCEDatabase;
  25. import org.xtce.toolkit.XTCETMContainer;
  26. import org.xtce.toolkit.XTCEParameter;
  27. import org.omg.space.xtce.ValueEnumerationType;
  28. /** This class is an executable main that loads an XTCE database file and dumps
  29. * the contents of all the ECSS PUS Housekeeping packets in Service 3,
  30. * Subservice 25 to STDOUT based on iterating through the "Structure IDs" where
  31. * a parameter SID_SWITCH_PARAMETER_NAME is an Enumerated Parameter containing
  32. * all the SIDs and a value of NONE.
  33. *
  34. * <P>The following is an example based on this demonstration class file. The
  35. * class main() uses a built-in example database file in this larger package,
  36. * instead of the "myfile.xml" used in the example code below.</P>
  37. *
  38. * <pre>
  39. * {@code
  40. * try {
  41. *
  42. * System.out.println( "Loading the database" );
  43. *
  44. * // load the satellite database
  45. *
  46. * XTCEDatabase db = new XTCEDatabase( new File( "myfile.xml" ),
  47. * false, // skip XSD validation
  48. * true, // apply the XIncludes
  49. * true ); // ReadOnly
  50. *
  51. * System.out.println( "Done Loading" );
  52. *
  53. * // replace the parameter name here with the ECCS "Structure ID"
  54. * // parameter name. It is assumed for this example that the SID is
  55. * // used in the packet with conditional ContainerRefEntry elements.
  56. *
  57. * List<XTCEParameter> sidParameters =
  58. * db.getTelemetryParameters( "SID_SWITCH_PARAMETER_NAME" );
  59. *
  60. * // only 1 SID parameter should have been returned.
  61. *
  62. * if ( sidParameters.size() != 1 ) {
  63. * System.out.println( "oops - size is " + sidParameters.size() );
  64. * return;
  65. * }
  66. *
  67. * // get the list of all the SID (structure ID) conditional parameters
  68. * // that can exist in the PUS(3,25) packet structure.
  69. *
  70. * List<ValueEnumerationType> sidEnums =
  71. * sidParameters.get( 0 ).getEnumerations();
  72. *
  73. * // get the specific container in XTCE that represents the PUS(3,25)
  74. *
  75. * XTCETMContainer container =
  76. * db.getContainer( "/PROGRAM_NAME/PACKETS/SERVICE_003_025" );
  77. *
  78. * // loop through the SID enumerations for SERVICE_003_025 and apply
  79. * // the conditional for each evaluation to get the unique packet
  80. * // structure, which ends up resulting in the size being available,
  81. * // as well as the content.
  82. *
  83. * for ( ValueEnumerationType sidEnum : sidEnums ) {
  84. *
  85. * // skip the SID value equal to NONE because it doesn't exist
  86. *
  87. * if ( sidEnum.getLabel().equals( "NONE" ) == true ) {
  88. * continue;
  89. * }
  90. *
  91. * // make a message to indicate starting a specific packet
  92. *
  93. * System.out.println( "SERVICE_003_025 with SID " +
  94. * sidEnum.getLabel() );
  95. *
  96. * // make a list of 1 "user value" to pass to the processContainer
  97. * // method in order to get a specific evaluation of the packet.
  98. *
  99. * XTCEContainerEntryValue valueObj =
  100. * new XTCEContainerEntryValue( sidParameters.get( 0 ),
  101. * sidEnum.getLabel(),
  102. * "==",
  103. * "Calibrated" );
  104. *
  105. * ArrayList<XTCEContainerEntryValue> values = new ArrayList<>();
  106. * values.add( valueObj );
  107. *
  108. * // evaluate the contents of the packet in this specific case.
  109. *
  110. * XTCEContainerContentModel model =
  111. * db.processContainer( container, values, false );
  112. *
  113. * // get the size (very easy...)
  114. *
  115. * long sizeInBytes = model.getTotalSize();
  116. *
  117. * // for demonstration, get the parameters in the container and
  118. * // all of their positional information like start bit, length,
  119. * // etc. see the Javadoc for all that is available.
  120. *
  121. * List<XTCEContainerContentEntry> entries = model.getContentList();
  122. *
  123. * // loop through all the parameters in the packet
  124. *
  125. * for ( XTCEContainerContentEntry entry : entries ) {
  126. *
  127. * // skip content entries that are not actually used because
  128. * // the conditional include is false
  129. *
  130. * if ( entry.isCurrentlyInUse() == false ) {
  131. * continue;
  132. * }
  133. *
  134. * // print a message based on the type of entry. in reality,
  135. * // TM packets can only have PARAMETER and CONTAINER, but the
  136. * // XTCEContainerContentEntry supports TM containers and also TC
  137. * // containers.
  138. *
  139. * switch ( entry.getEntryType() ) {
  140. *
  141. * case PARAMETER:
  142. * System.out.println( entry.getEntryTypeString() +
  143. * ": " +
  144. * entry.getParameter().getName() +
  145. * " (" +
  146. * entry.getParameter().getAlias( "SCS" ) +
  147. * ")" );
  148. * break;
  149. *
  150. * case ARGUMENT:
  151. * System.out.println( entry.getEntryTypeString() +
  152. * ": " +
  153. * entry.getArgument().getName() +
  154. * " (" +
  155. * entry.getArgument().getAlias( "SCS" ) +
  156. * ")" );
  157. * break;
  158. *
  159. * case CONSTANT:
  160. * System.out.println( entry.getEntryTypeString() +
  161. * ": " +
  162. * entry.getValue() );
  163. * break;
  164. *
  165. * case CONTAINER:
  166. * // ignore for this purpose
  167. * break;
  168. *
  169. * default:
  170. * break;
  171. *
  172. * } // end of switch/case statement
  173. *
  174. * } // end of container content entry loop
  175. *
  176. * System.out.println( "Total Size: " +
  177. * Long.toString( sizeInBytes ) +
  178. * " bytes" );
  179. *
  180. * } // end of SID (structure ID) loop
  181. *
  182. * System.out.println( "Done" );
  183. *
  184. * } catch ( Exception ex ) {
  185. *
  186. * System.out.println( "Exception: " + ex.getLocalizedMessage() );
  187. * ex.printStackTrace();
  188. *
  189. * } // end of try block
  190. * }
  191. * </pre>
  192. *
  193. * @author b1053583
  194. *
  195. */
  196. public class ProcessEcssHousekeepingExample {
  197. /** Everything is in main for this example.
  198. *
  199. * @param args the command line arguments.
  200. *
  201. */
  202. public static void main( String[] args ) {
  203. try {
  204. System.out.println( "Loading the database" );
  205. // load the satellite database
  206. XTCEDatabase db = new XTCEDatabase( new File( "myfile.xml" ),
  207. false, // skip XSD validation
  208. true, // apply the XIncludes
  209. true ); // ReadOnly
  210. System.out.println( "Done Loading" );
  211. // replace the parameter name here with the ECCS "Structure ID"
  212. // parameter name. It is assumed for this example that the SID is
  213. // used in the packet with conditional ContainerRefEntry elements.
  214. List<XTCEParameter> sidParameters =
  215. db.getTelemetryParameters( "SID_SWITCH_PARAMETER_NAME" );
  216. // only 1 SID parameter should have been returned.
  217. if ( sidParameters.size() != 1 ) {
  218. System.out.println( "oops - size is " + sidParameters.size() );
  219. return;
  220. }
  221. // get the list of all the SID (structure ID) conditional parameters
  222. // that can exist in the PUS(3,25) packet structure.
  223. List<ValueEnumerationType> sidEnums =
  224. sidParameters.get( 0 ).getEnumerations();
  225. // get the specific container in XTCE that represents the PUS(3,25)
  226. XTCETMContainer container =
  227. db.getContainer( "/PROGRAM_NAME/PACKETS/SERVICE_003_025" );
  228. // loop through the SID enumerations for SERVICE_003_025 and apply
  229. // the conditional for each evaluation to get the unique packet
  230. // structure, which ends up resulting in the size being available,
  231. // as well as the content.
  232. for ( ValueEnumerationType sidEnum : sidEnums ) {
  233. // skip the SID value equal to NONE because it doesn't exist
  234. if ( sidEnum.getLabel().equals( "NONE" ) == true ) {
  235. continue;
  236. }
  237. // make a message to indicate starting a specific packet
  238. System.out.println( "SERVICE_003_025 with SID " +
  239. sidEnum.getLabel() );
  240. // make a list of 1 "user value" to pass to the processContainer
  241. // method in order to get a specific evaluation of the packet.
  242. XTCEContainerEntryValue valueObj =
  243. new XTCEContainerEntryValue( sidParameters.get( 0 ),
  244. sidEnum.getLabel(),
  245. "==",
  246. "Calibrated" );
  247. ArrayList<XTCEContainerEntryValue> values = new ArrayList<>();
  248. values.add( valueObj );
  249. // evaluate the contents of the packet in this specific case.
  250. XTCEContainerContentModel model =
  251. db.processContainer( container, values, false );
  252. // get the size (very easy...)
  253. long sizeInBytes = model.getTotalSize();
  254. // for demonstration, get the parameters in the container and
  255. // all of their positional information like start bit, length,
  256. // etc. see the Javadoc for all that is available.
  257. List<XTCEContainerContentEntry> entries = model.getContentList();
  258. // loop through all the parameters in the packet
  259. for ( XTCEContainerContentEntry entry : entries ) {
  260. // skip content entries that are not actually used because
  261. // the conditional include is false
  262. if ( entry.isCurrentlyInUse() == false ) {
  263. continue;
  264. }
  265. // print a message based on the type of entry. in reality,
  266. // TM packets can only have PARAMETER and CONTAINER, but the
  267. // XTCEContainerContentEntry supports TM containers and also TC
  268. // containers.
  269. switch ( entry.getEntryType() ) {
  270. case PARAMETER:
  271. System.out.println( entry.getEntryTypeString() +
  272. ": " +
  273. entry.getParameter().getName() +
  274. " (" +
  275. entry.getParameter().getAlias( "SCS" ) +
  276. ")" );
  277. break;
  278. case ARGUMENT:
  279. System.out.println( entry.getEntryTypeString() +
  280. ": " +
  281. entry.getArgument().getName() +
  282. " (" +
  283. entry.getArgument().getAlias( "SCS" ) +
  284. ")" );
  285. break;
  286. case CONSTANT:
  287. System.out.println( entry.getEntryTypeString() +
  288. ": " +
  289. entry.getValue() );
  290. break;
  291. case CONTAINER:
  292. // ignore for this purpose
  293. break;
  294. default:
  295. break;
  296. } // end of switch/case statement
  297. } // end of container content entry loop
  298. System.out.println( "Total Size: " +
  299. Long.toString( sizeInBytes ) +
  300. " bytes" );
  301. } // end of SID (structure ID) loop
  302. System.out.println( "Done" );
  303. } catch ( Exception ex ) {
  304. System.out.println( "Exception: " + ex.getLocalizedMessage() );
  305. ex.printStackTrace();
  306. System.exit( -1 );
  307. } // end of try block
  308. System.exit( 0 );
  309. } // end of main() function
  310. }