📄 onewirecontainer21.java
字号:
result [1] = ( int ) lower + ( int ) upper * 10; /* now grab the hours. The lower half is single hours again, but the upper half of the byte is determined by the 2nd bit - specifying 12/24 hour time. */ lower = state [timeReg++]; upper = ( byte ) ((lower >>> 4) & 0x07); lower = ( byte ) (lower & 0x0f); int hours; // if the 2nd bit is 1, convert 12 hour time to 24 hour time. if ((upper >>> 2) != 0) { // extract the AM/PM byte (PM is indicated by a 1) byte PM = ( byte ) (((upper << 6) >>> 7) & 0x01); // isolate the 10s place upper = ( byte ) (upper & 0x01); hours = upper * 10 + PM * 12; } else hours = upper * 10; // already in 24 hour format hours += lower; result [2] = hours; return result; } /** * Set the time in the DS1921 time register format. */ private void setTime (int timeReg, int hours, int minutes, int seconds, boolean AMPM, byte[] state) { byte upper, lower; /* format in bytes and write seconds */ upper = ( byte ) (seconds / 10); upper = ( byte ) ((upper << 4) & 0xf0); lower = ( byte ) (seconds % 10); lower = ( byte ) (lower & 0x0f); state [timeReg & 31] = ( byte ) (upper | lower); timeReg++; /* format in bytes and write minutes */ upper = ( byte ) (minutes / 10); upper = ( byte ) ((upper << 4) & 0xf0); lower = ( byte ) (minutes % 10); lower = ( byte ) (lower & 0x0f); state [timeReg & 31] = ( byte ) (upper | lower); timeReg++; /* format in bytes and write hours/(12/24) bit */ if (AMPM) { upper = ( byte ) 0x04; if (hours > 11) upper = ( byte ) (upper | 0x02); // this next function simply checks for a decade hour if (((hours % 12) == 0) || ((hours % 12) > 9)) upper = ( byte ) (upper | 0x01); if (hours > 12) hours = hours - 12; if (hours == 0) lower = ( byte ) 0x02; else lower = ( byte ) ((hours % 10) & 0x0f); } else { upper = ( byte ) (hours / 10); lower = ( byte ) (hours % 10); } upper = ( byte ) ((upper << 4) & 0xf0); lower = ( byte ) (lower & 0x0f); state [timeReg & 31] = ( byte ) (upper | lower); timeReg++; } /** * Set the current date in the DS1921's real time clock. * * year - The year to set to, i.e. 2001. * month - The month to set to, i.e. 1 for January, 12 for December. * day - The day of month to set to, i.e. 1 to 31 in January, 1 to 30 in April. */ private void setDate (int year, int month, int day, byte[] state) { byte upper, lower; /* write the day byte (the upper holds 10s of days, lower holds single days) */ upper = ( byte ) (day / 10); upper = ( byte ) ((upper << 4) & 0xf0); lower = ( byte ) (day % 10); lower = ( byte ) (lower & 0x0f); state [0x04] = ( byte ) (upper | lower); /* write the month bit in the same manner, with the MSBit indicating the century (1 for 2000, 0 for 1900) */ upper = ( byte ) (month / 10); upper = ( byte ) ((upper << 4) & 0xf0); lower = ( byte ) (month % 10); lower = ( byte ) (lower & 0x0f); if (year > 1999) { upper = ( byte ) (upper | 128); //go ahead and fix up the year too while i'm at it year = year - 2000; } else year = year - 1900; state [0x05] = ( byte ) (upper | lower); // now write the year upper = ( byte ) (year / 10); upper = ( byte ) ((upper << 4) & 0xf0); lower = ( byte ) (year % 10); lower = ( byte ) (lower & 0x0f); state [0x06] = ( byte ) (upper | lower); } ////////////////////////////////////////////////////////////// // // Public methods // ////////////////////////////////////////////////////////////// /** * Returns the maximum speed this iButton device can * communicate at. * * @return maximum speed * @see DSPortAdapter#setSpeed */ public int getMaxSpeed () { return DSPortAdapter.SPEED_OVERDRIVE; } /** * Gets the Dallas Semiconductor part number of the iButton * or 1-Wire Device as a <code>java.lang.String</code>. * For example "DS1992". * * @return iButton or 1-Wire device name */ public String getName () { return partNumber; } /** * Retrieves the alternate Dallas Semiconductor part numbers or names. * A 'family' of MicroLAN devices may have more than one part number * depending on packaging. There can also be nicknames such as * "Crypto iButton". * * @return the alternate names for this iButton or 1-Wire device */ public String getAlternateNames () { return "Thermochron"; } /** * Gets a short description of the function of this iButton * or 1-Wire Device type. * * @return device description */ public String getDescription () { // put the DS1921's characteristics together in a string format. String characteristics = ""; if (partNumber != "DS1921") { // get the physical range as a string String strPhysicalRange = Convert.toString(getPhysicalRangeLowTemperature(),1) + " to " + Convert.toString(getPhysicalRangeHighTemperature(),1) + " degrees Celsius."; // get the operating range as a string String strOperatingRange = Convert.toString(getOperatingRangeLowTemperature(),1) + " to " + Convert.toString(getOperatingRangeHighTemperature(),1) + " degrees Celsius."; characteristics = " The operating range for this device is: " + strOperatingRange + " The physical range for this device is: " + strPhysicalRange + " The resolution is " + Convert.toString(getTemperatureResolution(),3) + " degrees Celsius, and the histogram bin width is " + Convert.toString(getHistogramBinWidth(),3) + " degrees Celsius."; } String returnString = "Rugged, self-sufficient 1-Wire device that, once setup for " + "a mission, will measure the temperature and record the result in " + "a protected memory section. It stores up to 2048 temperature " + "measurements and will take measurements at a user-specified " + "rate. The thermochron also records the number of times the temperature " + "falls on a given degree range (temperature bin), and stores the " + "data in histogram format." + characteristics; return returnString; } /** * Directs the container to avoid the calls to doSpeed() in methods that communicate * with the Thermocron. To ensure that all parts can talk to the 1-Wire bus * at their desired speed, each method contains a call * to <code>doSpeed()</code>. However, this is an expensive operation. * If a user manages the bus speed in an * application, call this method with <code>doSpeedCheck</code> * as <code>false</code>. The default behavior is * to call <code>doSpeed()</code>. * * @param doSpeedCheck <code>true</code> for <code>doSpeed()</code> to be called before every * 1-Wire bus access, <code>false</code> to skip this expensive call * * @see OneWireContainer#doSpeed() */ public synchronized void setSpeedCheck (boolean doSpeedCheck) { doSpeedEnable = doSpeedCheck; } /** * This method returns the low temperature of * the thermochron's physical temperature range. * The physical range is the range of temperatures * that the thermochron can record. * * The following is a list of physical ranges in * degrees Celsius: * * DS1921L-F5X = physical range -40 to +85 * * DS1921H = physical range 15 to 46 * * DS1921Z = physical range -5 to 26 * * @return the physical range low temperature in degrees Celsius */ public double getPhysicalRangeLowTemperature() { return temperatureRangeLow; } /** * This method returns the high temperature of * the thermochron's physical temperature range. * The physical range is the range of temperatures * that the thermochron can record. * * The following is a list of physical ranges in * degrees Celsius: * * DS1921L-F5X = physical range -40 to +85 * * DS1921H = physical range 15 to 46 * * DS1921Z = physical range -5 to 26 * * @return the physical range low temperature in degrees Celsius */ public double getPhysicalRangeHighTemperature() { return temperatureRangeHigh; } /** * This method returns the low temperature of * the thermochron's operating temperature range. * The operating range is the range of temperatures * for which the thermochron can function properly. * * The following is a list of operating ranges in * degrees Celsius: * * DS1921L-F50 = operating range -40 to +85. * DS1921L-F51 = operating range -10 to +85. * DS1921L-F52 = operating range -20 to +85. * DS1921L-F53 = operating range -30 to +85. * * DS1921H = operating range -40 to +85 * DS1921Z = operating range -40 to +85 * * @return the operating range low temperature in degrees Celsius */ public double getOperatingRangeLowTemperature() { return temperatureOperatingRangeLow; } /** * This method returns the high temperature of * the thermochron's operating temperature range. * The operating range is the range of temperatures * for which the thermochron can function properly. * * The following is a list of operating ranges in * degrees Celsius: * * DS1921L-F50 = operating range -40 to +85. * DS1921L-F51 = operating range -10 to +85. * DS1921L-F52 = operating range -20 to +85. * DS1921L-F53 = operating range -30 to +85. * * DS1921H = operating range -40 to +85 * DS1921Z = operating range -40 to +85 * * @return the operating range high temperature in degrees Celsius */ public double getOperatingRangeHighTemperature() { return temperatureOperatingRangeHigh; } /** * Retrieves the resolution with which the thermochron takes * temperatures in degrees Celsius. * * @return the temperature resolution of this thermochron. */ public double getTemperatureResolution() { return temperatureResolution; } /** * Retrieves the lowest temperature of the first histogram bin * in degrees Celsius. * * @return the lowest histogram bin temperature. */ public double getHistogramLowTemperature() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -