001/* Copyright (C) Cross The Road Electronics 2024 */
002/*
003 *  Software License Agreement
004 *
005 * Copyright (C) Cross The Road Electronics.  All rights
006 * reserved.
007 *
008 * Cross The Road Electronics (CTRE) licenses to you the right to
009 * use, publish, and distribute copies of CRF (Cross The Road) firmware files (*.crf) and Software
010 * API Libraries ONLY when in use with Cross The Road Electronics hardware products.
011 *
012 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
013 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
014 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
015 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
016 * CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
017 * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
018 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
019 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
020 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
021 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
022 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE
023 */
024package com.ctre.phoenix.sensors;
025import com.ctre.phoenix.ErrorCode;
026import com.ctre.phoenix.ParamEnum;
027import com.ctre.phoenix.motorcontrol.can.TalonSRX;
028import com.ctre.phoenix.ErrorCollection;
029import com.ctre.phoenix.CustomParamConfigUtil;
030
031//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
032//import edu.wpi.first.wpilibj.hal.HAL;
033
034/**
035 * Pigeon IMU Class. Class supports communicating over CANbus and over
036 * ribbon-cable (CAN Talon SRX).
037 */
038public class BasePigeon {
039        private long m_handle;
040        private BasePigeonSimCollection m_simCollection;
041
042        private int m_deviceNumber = 0;
043        
044        /**
045         * Create a Pigeon object that communicates with Pigeon on CAN Bus.
046         *
047         * @param deviceNumber
048         *            CAN Device Id of Pigeon [0,62]
049         * @param version Version of the PigeonIMU
050         * @param canbus Name of the CANbus; can be a SocketCAN interface (on Linux),
051         *               or a CANivore device name or serial number
052         */
053        public BasePigeon(int deviceNumber, String version, String canbus) {
054                m_handle = PigeonImuJNI.JNI_new_PigeonImu(deviceNumber, version, canbus);
055                m_deviceNumber = deviceNumber;
056                m_simCollection = new BasePigeonSimCollection(this, false);
057        }
058
059        /**
060         * Create a Pigeon object that communicates with Pigeon on CAN Bus.
061         *
062         * @param deviceNumber
063         *            CAN Device Id of Pigeon [0,62]
064         * @param version Version of the PigeonIMU
065         */
066        public BasePigeon(int deviceNumber, String version) {
067                this(deviceNumber, version, "");
068        }
069
070        protected BasePigeon(TalonSRX talonSrx) {
071                m_handle = PigeonImuJNI.JNI_new_PigeonImu_Talon(talonSrx.getDeviceID(), "v1");
072                m_deviceNumber = talonSrx.getDeviceID();
073                m_simCollection = new BasePigeonSimCollection(this, true);
074        }
075
076        /**
077         * Destructor for Pigeon
078         * @return Error Code generated by function. 0 indicates no error.
079         */
080    public ErrorCode DestroyObject() {
081        return ErrorCode.valueOf(PigeonImuJNI.JNI_destroy_PigeonImu(m_handle));
082    }
083
084    //public static void DestroyAllBasePigeons() {
085    //    PigeonImuJNI.JNI_destroy_AllBasePigeons();
086    //}
087
088        /**
089         * @return object that can set simulation inputs.
090         */
091        public BasePigeonSimCollection getSimCollection(){ return m_simCollection;}
092
093        /**
094         * Sets the Yaw register to the specified value.
095         *
096         * @param angleDeg  New yaw in degrees [+/- 368,640 degrees]
097         * @param timeoutMs
098     *            Timeout value in ms. If nonzero, function will wait for
099     *            config success and report an error if it times out.
100     *            If zero, no blocking or checking is performed.
101         * @return Error Code generated by function. 0 indicates no error.
102         */
103        public ErrorCode setYaw(double angleDeg, int timeoutMs) {
104                int retval = PigeonImuJNI.JNI_SetYaw(m_handle, angleDeg, timeoutMs);
105                return ErrorCode.valueOf(retval);
106        }
107        /**
108         * Sets the Yaw register to the specified value.
109         *
110         * @param angleDeg  New yaw in degrees [+/- 368,640 degrees]
111         * @return Error Code generated by function. 0 indicates no error.
112         */
113        public ErrorCode setYaw(double angleDeg) {
114                int timeoutMs = 0;
115                return setYaw( angleDeg,  timeoutMs);
116        }
117        /**
118         * Atomically add to the Yaw register.
119         *
120         * @param angleDeg  Degrees to add to the Yaw register.
121         * @param timeoutMs
122     *            Timeout value in ms. If nonzero, function will wait for
123     *            config success and report an error if it times out.
124     *            If zero, no blocking or checking is performed.
125         * @return Error Code generated by function. 0 indicates no error.
126         */
127        public ErrorCode addYaw(double angleDeg, int timeoutMs) {
128                int retval = PigeonImuJNI.JNI_AddYaw(m_handle, angleDeg, timeoutMs);
129                return ErrorCode.valueOf(retval);
130        }
131        /**
132         * Atomically add to the Yaw register.
133         *
134         * @param angleDeg  Degrees to add to the Yaw register.
135         * @return Error Code generated by function. 0 indicates no error.
136         */
137        public ErrorCode addYaw(double angleDeg) {
138                int timeoutMs = 0;
139                return addYaw( angleDeg,  timeoutMs);   
140        }
141        /**
142         * Sets the Yaw register to match the current compass value.
143         *
144         * @param timeoutMs
145     *            Timeout value in ms. If nonzero, function will wait for
146     *            config success and report an error if it times out.
147     *            If zero, no blocking or checking is performed.
148         * @return Error Code generated by function. 0 indicates no error.
149         */
150        public ErrorCode setYawToCompass(int timeoutMs) {
151                int retval = PigeonImuJNI.JNI_SetYawToCompass(m_handle, timeoutMs);
152                return ErrorCode.valueOf(retval);
153        }
154        /**
155         * Sets the Yaw register to match the current compass value.
156         *
157         * @return Error Code generated by function. 0 indicates no error.
158         */
159        public ErrorCode setYawToCompass() {
160                int timeoutMs = 0;
161                return setYawToCompass(timeoutMs);
162        }
163        /**
164         * Sets the AccumZAngle.
165         *
166         * @param angleDeg  Degrees to set AccumZAngle to.
167         * @param timeoutMs
168     *            Timeout value in ms. If nonzero, function will wait for
169     *            config success and report an error if it times out.
170     *            If zero, no blocking or checking is performed.
171         * @return Error Code generated by function. 0 indicates no error.
172         */
173        public ErrorCode setAccumZAngle(double angleDeg, int timeoutMs) {
174                int retval = PigeonImuJNI.JNI_SetAccumZAngle(m_handle, angleDeg, timeoutMs);
175                return ErrorCode.valueOf(retval);
176        }
177        /**
178         * Sets the AccumZAngle.
179         *
180         * @param angleDeg  Degrees to set AccumZAngle to.
181         * @return Error Code generated by function. 0 indicates no error.
182         */
183        public ErrorCode setAccumZAngle(double angleDeg) {
184                int timeoutMs = 0;
185                return setAccumZAngle(angleDeg, timeoutMs);
186        }
187
188        // ----------------------- General Error status -----------------------//
189        /**
190         * Call GetLastError() generated by this object.
191         * Not all functions return an error code but can
192         * potentially report errors.
193         *
194         * This function can be used to retrieve those error codes.
195         *
196         * @return The last ErrorCode generated.
197         */
198        public ErrorCode getLastError() {
199                int retval = PigeonImuJNI.JNI_GetLastError(m_handle);
200                return ErrorCode.valueOf(retval);
201        }
202
203        // ----------------------- Strongly typed Signal decoders
204        // -----------------------//
205        /**
206         * Get 6d Quaternion data.
207         *
208         * @param wxyz Array to fill with quaternion data w[0], x[1], y[2], z[3]
209         * @return The last ErrorCode generated.
210         */
211        public ErrorCode get6dQuaternion(double[] wxyz) {
212                int retval = PigeonImuJNI.JNI_Get6dQuaternion(m_handle, wxyz);
213                return ErrorCode.valueOf(retval);
214        }
215        /**
216         * Get Yaw, Pitch, and Roll data.
217         *
218         * @param ypr_deg Array to fill with yaw[0], pitch[1], and roll[2] data.
219         *                                      Yaw is within [-368,640, +368,640] degrees.
220         *                                      Pitch is within [-90,+90] degrees.
221         *                                      Roll is within [-90,+90] degrees.
222         * @return The last ErrorCode generated.
223         */
224        public ErrorCode getYawPitchRoll(double[] ypr_deg) {
225                int retval = PigeonImuJNI.JNI_GetYawPitchRoll(m_handle, ypr_deg);
226                return ErrorCode.valueOf(retval);
227        }
228
229        /**
230         * Get the yaw from the Pigeon
231         * @return Yaw
232         */
233        public double getYaw() {
234                return PigeonImuJNI.JNI_GetYaw(m_handle);
235        }
236        /**
237         * Get the pitch from the Pigeon
238         * @return Pitch
239         */
240        public double getPitch() {
241                return PigeonImuJNI.JNI_GetPitch(m_handle);
242        }
243        /**
244         * Get the roll from the Pigeon
245         * @return Roll
246         */
247        public double getRoll() {
248                return PigeonImuJNI.JNI_GetRoll(m_handle);
249        }
250        /**
251         * Get AccumGyro data.
252         * AccumGyro is the integrated gyro value on each axis.
253         *
254         * @param xyz_deg Array to fill with x[0], y[1], and z[2] AccumGyro data
255         * @return The last ErrorCode generated.
256         */
257        public ErrorCode getAccumGyro(double[] xyz_deg) {
258                int retval = PigeonImuJNI.JNI_GetAccumGyro(m_handle, xyz_deg);
259                return ErrorCode.valueOf(retval);
260        }
261
262        /**
263         * Get the absolute compass heading.
264         * @return compass heading [0,360) degrees.
265         */
266        public double getAbsoluteCompassHeading() {
267                double retval = PigeonImuJNI.JNI_GetAbsoluteCompassHeading(m_handle);
268                return retval;
269        }
270
271        /**
272         * Get the continuous compass heading.
273         * @return continuous compass heading [-23040, 23040) degrees. Use
274         *         SetCompassHeading to modify the wrap-around portion.
275         */
276        public double getCompassHeading() {
277                double retval = PigeonImuJNI.JNI_GetCompassHeading(m_handle);
278                return retval;
279        }
280
281        /**
282         * Gets the compass' measured magnetic field strength.
283         * @return field strength in Microteslas (uT).
284         */
285        public double getCompassFieldStrength() {
286                double retval = PigeonImuJNI.JNI_GetCompassFieldStrength(m_handle);
287                return retval;
288        }
289        /**
290         * Gets the temperature of the pigeon.
291         *
292         * @return Temperature in ('C)
293         */
294        public double getTemp() {
295                double retval = PigeonImuJNI.JNI_GetTemp(m_handle);
296                return retval;
297        }
298
299        /**
300         * Gets the current Pigeon uptime.
301         *
302         * @return How long has Pigeon been running in whole seconds. Value caps at
303         *         255.
304         */
305        public int getUpTime() {
306                int retval = PigeonImuJNI.JNI_GetUpTime(m_handle);
307                return retval;
308        }
309        /**
310         * Get Raw Magnetometer data.
311         *
312         * @param rm_xyz Array to fill with x[0], y[1], and z[2] data
313         *                              Number is equal to 0.6 microTeslas per unit.
314         * @return The last ErrorCode generated.
315         */
316        public ErrorCode getRawMagnetometer(short[] rm_xyz) {
317                int retval = PigeonImuJNI.JNI_GetRawMagnetometer(m_handle, rm_xyz);
318                return ErrorCode.valueOf(retval);
319        }
320        /**
321         * Get Biased Magnetometer data.
322         *
323         * @param bm_xyz Array to fill with x[0], y[1], and z[2] data
324         *                              Number is equal to 0.6 microTeslas per unit.
325         * @return The last ErrorCode generated.
326         */
327        public ErrorCode getBiasedMagnetometer(short[] bm_xyz) {
328                int retval = PigeonImuJNI.JNI_GetBiasedMagnetometer(m_handle, bm_xyz);
329                return ErrorCode.valueOf(retval);
330        }
331        /**
332         * Get Biased Accelerometer data.
333         *
334         * @param ba_xyz Array to fill with x[0], y[1], and z[2] data.
335         *                      These are in fixed point notation Q2.14.  eg. 16384 = 1G
336         * @return The last ErrorCode generated.
337         */
338        public ErrorCode getBiasedAccelerometer(short[] ba_xyz) {
339                int retval = PigeonImuJNI.JNI_GetBiasedAccelerometer(m_handle, ba_xyz);
340                return ErrorCode.valueOf(retval);
341        }
342        /**
343         * Get Raw Gyro data.
344         *
345         * @param xyz_dps Array to fill with x[0], y[1], and z[2] data in degrees per second.
346         * @return The last ErrorCode generated.
347         */
348        public ErrorCode getRawGyro(double[] xyz_dps) {
349                int retval = PigeonImuJNI.JNI_GetRawGyro(m_handle, xyz_dps);
350                return ErrorCode.valueOf(retval);
351        }
352
353        /**
354         * @return number of times Pigeon Reset
355         */
356        public int getResetCount() {
357                int k = PigeonImuJNI.JNI_GetResetCount(m_handle);
358                return k;
359        }
360        /**
361         * @return Reset flags for Pigeon
362         */
363        public int getResetFlags() {
364                int k = PigeonImuJNI.JNI_GetResetFlags(m_handle);
365                return k;
366        }
367        /**
368         * Gets the firmware version of the device.
369         *
370         * @return param holds the firmware version of the device. Device must be powered
371         * cycled at least once.
372         */
373        public int getFirmwareVersion() {
374                int k = PigeonImuJNI.JNI_GetFirmwareVersion(m_handle);
375                return k;
376        }
377
378        /**
379         * @return true iff a reset has occurred since last call.
380         */
381        public boolean hasResetOccurred() {
382                boolean k = PigeonImuJNI.JNI_HasResetOccurred(m_handle);
383                return k;
384        }
385
386        /**
387         * Sets the value of a custom parameter. This is for arbitrary use.
388     *
389     * Sometimes it is necessary to save calibration/declination/offset
390     * information in the device. Particularly if the
391     * device is part of a subsystem that can be replaced.
392         *
393         * @param newValue
394         *            Value for custom parameter.
395         * @param paramIndex
396         *            Index of custom parameter. [0-1]
397         * @param timeoutMs
398     *            Timeout value in ms. If nonzero, function will wait for
399     *            config success and report an error if it times out.
400     *            If zero, no blocking or checking is performed.
401         * @return Error Code generated by function. 0 indicates no error.
402         */
403        public ErrorCode configSetCustomParam(int newValue, int paramIndex, int timeoutMs) {
404                int retval = PigeonImuJNI.JNI_ConfigSetCustomParam(m_handle, newValue, paramIndex, timeoutMs);
405                return ErrorCode.valueOf(retval);
406        }
407        /**
408         * Sets the value of a custom parameter. This is for arbitrary use.
409     *
410     * Sometimes it is necessary to save calibration/declination/offset
411     * information in the device. Particularly if the
412     * device is part of a subsystem that can be replaced.
413         *
414         * @param newValue
415         *            Value for custom parameter.
416         * @param paramIndex
417         *            Index of custom parameter. [0-1]
418         * @return Error Code generated by function. 0 indicates no error.
419         */
420        public ErrorCode configSetCustomParam(int newValue, int paramIndex ) {
421                int timeoutMs = 0;
422                return configSetCustomParam( newValue,  paramIndex, timeoutMs);
423        }
424
425        /**
426         * Gets the value of a custom parameter. This is for arbitrary use.
427     *
428     * Sometimes it is necessary to save calibration/declination/offset
429     * information in the device. Particularly if the
430     * device is part of a subsystem that can be replaced.
431         *
432         * @param paramIndex
433         *            Index of custom parameter. [0-1]
434         * @param timoutMs
435         *            Timeout value in ms. If nonzero, function will wait for
436         *            config success and report an error if it times out.
437         *            If zero, no blocking or checking is performed.
438         * @return Value of the custom param.
439         */
440        public int configGetCustomParam(int paramIndex, int timoutMs) {
441                int retval = PigeonImuJNI.JNI_ConfigGetCustomParam(m_handle, paramIndex, timoutMs);
442                return retval;
443        }
444        /**
445         * Gets the value of a custom parameter. This is for arbitrary use.
446     *
447     * Sometimes it is necessary to save calibration/declination/offset
448     * information in the device. Particularly if the
449     * device is part of a subsystem that can be replaced.
450         *
451         * @param paramIndex
452         *            Index of custom parameter. [0-1]
453         * @return Value of the custom param.
454         */
455        public int configGetCustomParam(int paramIndex) {
456                int timeoutMs = 0;
457                return configGetCustomParam(paramIndex,timeoutMs);
458        }
459
460        /**
461         * Sets a parameter. Generally this is not used.
462     * This can be utilized in
463     * - Using new features without updating API installation.
464     * - Errata workarounds to circumvent API implementation.
465     * - Allows for rapid testing / unit testing of firmware.
466         *
467         * @param param
468         *            Parameter enumeration.
469         * @param value
470         *            Value of parameter.
471         * @param subValue
472         *            Subvalue for parameter. Maximum value of 255.
473         * @param ordinal
474         *            Ordinal of parameter.
475         * @param timeoutMs
476         *            Timeout value in ms. If nonzero, function will wait for
477         *            config success and report an error if it times out.
478         *            If zero, no blocking or checking is performed.
479         * @return Error Code generated by function. 0 indicates no error.
480         */
481        public ErrorCode configSetParameter(ParamEnum param, double value, int subValue, int ordinal, int timeoutMs) {
482                return configSetParameter(param.value, value, subValue, ordinal, timeoutMs);
483        }
484        /**
485         * Sets a parameter. Generally this is not used.
486     * This can be utilized in
487     * - Using new features without updating API installation.
488     * - Errata workarounds to circumvent API implementation.
489     * - Allows for rapid testing / unit testing of firmware.
490         *
491         * @param param
492         *            Parameter enumeration.
493         * @param value
494         *            Value of parameter.
495         * @param subValue
496         *            Subvalue for parameter. Maximum value of 255.
497         * @param ordinal
498         *            Ordinal of parameter.
499         * @return Error Code generated by function. 0 indicates no error.
500         */
501        public ErrorCode configSetParameter(ParamEnum param, double value, int subValue, int ordinal) {
502                int timeoutMs = 0;
503                return configSetParameter(param,  value,  subValue,  ordinal, timeoutMs);
504        }
505        /**
506         * Sets a parameter. Generally this is not used.
507     * This can be utilized in
508     * - Using new features without updating API installation.
509     * - Errata workarounds to circumvent API implementation.
510     * - Allows for rapid testing / unit testing of firmware.
511         *
512         * @param param
513         *            Parameter enumeration.
514         * @param value
515         *            Value of parameter.
516         * @param subValue
517         *            Subvalue for parameter. Maximum value of 255.
518         * @param ordinal
519         *            Ordinal of parameter.
520         * @param timeoutMs
521         *            Timeout value in ms. If nonzero, function will wait for
522         *            config success and report an error if it times out.
523         *            If zero, no blocking or checking is performed.
524         * @return Error Code generated by function. 0 indicates no error.
525         */
526        public ErrorCode configSetParameter(int param, double value, int subValue, int ordinal, int timeoutMs) {
527                int retval = PigeonImuJNI.JNI_ConfigSetParameter(m_handle, param, value, subValue, ordinal,
528                                timeoutMs);
529                return ErrorCode.valueOf(retval);
530        }
531        /**
532         * Sets a parameter. Generally this is not used.
533     * This can be utilized in
534     * - Using new features without updating API installation.
535     * - Errata workarounds to circumvent API implementation.
536     * - Allows for rapid testing / unit testing of firmware.
537         *
538         * @param param
539         *            Parameter enumeration.
540         * @param value
541         *            Value of parameter.
542         * @param subValue
543         *            Subvalue for parameter. Maximum value of 255.
544         * @param ordinal
545         *            Ordinal of parameter.
546         * @return Error Code generated by function. 0 indicates no error.
547         */
548        public ErrorCode configSetParameter(int param, double value, int subValue, int ordinal) {
549                int timeoutMs = 0;
550                return  configSetParameter( param,  value,  subValue,  ordinal, timeoutMs);
551        }
552        /**
553         * Gets a parameter. Generally this is not used.
554     * This can be utilized in
555     * - Using new features without updating API installation.
556     * - Errata workarounds to circumvent API implementation.
557     * - Allows for rapid testing / unit testing of firmware.
558         *
559         * @param param
560         *            Parameter enumeration.
561         * @param ordinal
562         *            Ordinal of parameter.
563         * @param timeoutMs
564         *            Timeout value in ms. If nonzero, function will wait for
565         *            config success and report an error if it times out.
566         *            If zero, no blocking or checking is performed.
567         * @return Value of parameter.
568         */
569        public double configGetParameter(ParamEnum param, int ordinal, int timeoutMs) {
570                return configGetParameter(param.value, ordinal, timeoutMs);
571        }
572        /**
573         * Gets a parameter. Generally this is not used.
574     * This can be utilized in
575     * - Using new features without updating API installation.
576     * - Errata workarounds to circumvent API implementation.
577     * - Allows for rapid testing / unit testing of firmware.
578         *
579         * @param param
580         *            Parameter enumeration.
581         * @param ordinal
582         *            Ordinal of parameter.
583         * @return Value of parameter.
584         */
585        public double configGetParameter(ParamEnum param, int ordinal ) {
586                int timeoutMs = 0;
587                return configGetParameter(param,  ordinal, timeoutMs);
588        }
589        /**
590         * Gets a parameter.
591         *
592         * @param param
593         *            Parameter enumeration.
594         * @param ordinal
595         *            Ordinal of parameter.
596         * @param timeoutMs
597         *            Timeout value in ms. If nonzero, function will wait for
598         *            config success and report an error if it times out.
599         *            If zero, no blocking or checking is performed.
600         * @return Value of parameter.
601         */
602        public double configGetParameter(int param, int ordinal, int timeoutMs) {
603                return PigeonImuJNI.JNI_ConfigGetParameter(m_handle, param, ordinal, timeoutMs);
604        }
605        /**
606         * Gets a parameter.
607         *
608         * @param param
609         *            Parameter enumeration.
610         * @param ordinal
611         *            Ordinal of parameter.
612         * @return Value of parameter.
613         */
614        public double configGetParameter(int param, int ordinal) {
615                int timeoutMs = 0;
616                return configGetParameter( param,  ordinal, timeoutMs);
617        }
618        /**
619         * Sets the period of the given status frame.
620         *
621         * @param statusFrame
622         *            Frame whose period is to be changed.
623         * @param periodMs
624         *            Period in ms for the given frame.
625         * @param timeoutMs
626         *            Timeout value in ms. If nonzero, function will wait for
627         *            config success and report an error if it times out.
628         *            If zero, no blocking or checking is performed.
629         * @return Error Code generated by function. 0 indicates no error.
630         */
631        public ErrorCode setStatusFramePeriod(PigeonIMU_StatusFrame statusFrame, int periodMs, int timeoutMs) {
632                int retval = PigeonImuJNI.JNI_SetStatusFramePeriod(m_handle, statusFrame.value, periodMs, timeoutMs);
633                return ErrorCode.valueOf(retval);
634        }
635        /**
636         * Sets the period of the given status frame.
637         *
638         * @param statusFrame
639         *            Frame whose period is to be changed.
640         * @param periodMs
641         *            Period in ms for the given frame.
642         * @return Error Code generated by function. 0 indicates no error.
643         */
644        public ErrorCode setStatusFramePeriod(PigeonIMU_StatusFrame statusFrame, int periodMs) {
645                int timeoutMs = 0;
646                return setStatusFramePeriod( statusFrame,  periodMs, timeoutMs);
647        }
648        /**
649         * Sets the period of the given status frame.
650         *
651         * @param statusFrame
652         *            Frame whose period is to be changed.
653         * @param periodMs
654         *            Period in ms for the given frame.
655         * @param timeoutMs
656         *            Timeout value in ms. If nonzero, function will wait for
657         *            config success and report an error if it times out.
658         *            If zero, no blocking or checking is performed.
659         * @return Error Code generated by function. 0 indicates no error.
660         */
661        public ErrorCode setStatusFramePeriod(int statusFrame, int periodMs, int timeoutMs) {
662                int retval = PigeonImuJNI.JNI_SetStatusFramePeriod(m_handle, statusFrame, periodMs, timeoutMs);
663                return ErrorCode.valueOf(retval);
664        }
665        /**
666         * Sets the period of the given status frame.
667         *
668         * @param statusFrame
669         *            Frame whose period is to be changed.
670         * @param periodMs
671         *            Period in ms for the given frame.
672         * @return Error Code generated by function. 0 indicates no error.
673         */
674        public ErrorCode setStatusFramePeriod(int statusFrame, int periodMs) {
675                int timeoutMs = 0;
676                return setStatusFramePeriod( statusFrame,  periodMs, timeoutMs);
677        }
678
679        /**
680         * Gets the period of the given status frame.
681         *
682         * @param frame
683         *            Frame to get the period of.
684         * @param timeoutMs
685         *            Timeout value in ms. If nonzero, function will wait for
686         *            config success and report an error if it times out.
687         *            If zero, no blocking or checking is performed.
688         * @return Period of the given status frame.
689         */
690        public int getStatusFramePeriod(PigeonIMU_StatusFrame frame, int timeoutMs) {
691                return PigeonImuJNI.JNI_GetStatusFramePeriod(m_handle, frame.value, timeoutMs);
692        }
693        /**
694         * Gets the period of the given status frame.
695         *
696         * @param frame
697         *            Frame to get the period of.
698         * @return Period of the given status frame.
699         */
700        public int getStatusFramePeriod(PigeonIMU_StatusFrame frame) {
701                int timeoutMs = 0;
702                return getStatusFramePeriod(frame, timeoutMs);
703        }
704        /**
705         * Sets the period of the given control frame.
706         *
707         * @param frame
708         *            Frame whose period is to be changed.
709         * @param periodMs
710         *            Period in ms for the given frame.
711         * @return Error Code generated by function. 0 indicates no error.
712         */
713        public ErrorCode setControlFramePeriod(PigeonIMU_ControlFrame frame, int periodMs) {
714                int retval = PigeonImuJNI.JNI_SetControlFramePeriod(m_handle, frame.value, periodMs);
715                return ErrorCode.valueOf(retval);
716        }
717        /**
718         * Sets the period of the given control frame.
719         *
720         * @param frame
721         *            Frame whose period is to be changed.
722         * @param periodMs
723         *            Period in ms for the given frame.
724         * @return Error Code generated by function. 0 indicates no error.
725         */
726        public ErrorCode setControlFramePeriod(int frame, int periodMs) {
727                int retval = PigeonImuJNI.JNI_SetControlFramePeriod(m_handle, frame, periodMs);
728                return ErrorCode.valueOf(retval);
729        }
730
731        // ------ Faults ----------//
732        /**
733         * Clears the Sticky Faults
734         *
735         * @param timeoutMs
736         *            Timeout value in ms. If nonzero, function will wait for
737         *            config success and report an error if it times out.
738         *            If zero, no blocking or checking is performed.
739         * @return Error Code generated by function. 0 indicates no error.
740         */
741        public ErrorCode clearStickyFaults(int timeoutMs) {
742                int retval = PigeonImuJNI.JNI_ClearStickyFaults(m_handle, timeoutMs);
743                return ErrorCode.valueOf(retval);
744        }
745        /**
746         * Clears the Sticky Faults
747         *
748         * @return Error Code generated by function. 0 indicates no error.
749         */
750        public ErrorCode clearStickyFaults() {
751                int timeoutMs = 0;
752                return clearStickyFaults(timeoutMs);
753        }
754
755        /**
756         * @return The Device Number
757         */
758        public int getDeviceID(){
759                return m_deviceNumber;
760        }
761    /**
762     * Configures all persistent settings.
763     *
764         * @param allConfigs        Object with all of the persistant settings
765     * @param timeoutMs
766     *              Timeout value in ms. If nonzero, function will wait for
767     *              config success and report an error if it times out.
768     *              If zero, no blocking or checking is performed.
769     *
770     * @return Error Code generated by function. 0 indicates no error. 
771     */
772        public ErrorCode configAllSettings(PigeonIMUConfiguration allConfigs, int timeoutMs) {
773        ErrorCollection errorCollection = new ErrorCollection();
774                
775                errorCollection.NewError(configFactoryDefault(timeoutMs));
776                
777                if(CustomParamConfigUtil.customParam0Different(allConfigs))
778                        errorCollection.NewError(configSetCustomParam(allConfigs.customParam0, 0, timeoutMs));
779                if(CustomParamConfigUtil.customParam1Different(allConfigs))
780                        errorCollection.NewError(configSetCustomParam(allConfigs.customParam1, 1, timeoutMs));
781        
782
783        return errorCollection._worstError;
784
785        }
786    /**
787     * Configures all persistent settings (overloaded so timeoutMs is 50 ms).
788     *
789         * @param allConfigs        Object with all of the persistant settings
790     *
791     * @return Error Code generated by function. 0 indicates no error. 
792     */
793        public ErrorCode configAllSettings(PigeonIMUConfiguration allConfigs) {
794                int timeoutMs = 0;
795                return  configAllSettings(allConfigs, timeoutMs);
796        }
797    /**
798     * Gets all persistant settings.
799     *
800         * @param allConfigs        Object with all of the persistant settings
801     * @param timeoutMs
802     *              Timeout value in ms. If nonzero, function will wait for
803     *              config success and report an error if it times out.
804     *              If zero, no blocking or checking is performed.
805     */
806    public void getAllConfigs(PigeonIMUConfiguration allConfigs, int timeoutMs) {
807
808        allConfigs.customParam0 = (int) configGetParameter(ParamEnum.eCustomParam, 0,  timeoutMs);
809        allConfigs.customParam1 = (int) configGetParameter(ParamEnum.eCustomParam, 1,  timeoutMs);
810    }
811    /**
812     * Gets all persistant settings (overloaded so timeoutMs is 50 ms).
813     *
814         * @param allConfigs        Object with all of the persistant settings
815     */
816    public void getAllConfigs(PigeonIMUConfiguration allConfigs) {
817        int timeoutMs = 50;
818        getAllConfigs(allConfigs, timeoutMs);
819    }   
820    /**
821     * Configures all persistent settings to defaults.
822     *
823     * @param timeoutMs
824     *              Timeout value in ms. If nonzero, function will wait for
825     *              config success and report an error if it times out.
826     *              If zero, no blocking or checking is performed.
827     *
828     * @return Error Code generated by function. 0 indicates no error. 
829     */
830        public ErrorCode configFactoryDefault(int timeoutMs) {
831                return ErrorCode.valueOf(PigeonImuJNI.JNI_ConfigFactoryDefault(m_handle, timeoutMs));
832        }
833    /**
834     * Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms).
835     *
836     * @return Error Code generated by function. 0 indicates no error. 
837     */
838        public ErrorCode configFactoryDefault() {
839                int timeoutMs = 50;
840                return configFactoryDefault(timeoutMs);
841                
842        }
843
844        public long getHandle() { return m_handle; }
845
846}