Sensor with Web Server

Dependencies:   EthernetInterface mbed-rpc mbed-rtos mbed

Committer:
afilipem
Date:
Tue Apr 08 12:13:32 2014 +0000
Revision:
0:c385e589a779
1 version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
afilipem 0:c385e589a779 1 /*
afilipem 0:c385e589a779 2 * OneWireCRC. This is a port to mbed of Jim Studt's Adruino One Wire
afilipem 0:c385e589a779 3 * library. Please see additional copyrights below this one, including
afilipem 0:c385e589a779 4 * references to other copyrights.
afilipem 0:c385e589a779 5 *
afilipem 0:c385e589a779 6 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
afilipem 0:c385e589a779 7 *
afilipem 0:c385e589a779 8 * This file is part of OneWireCRC.
afilipem 0:c385e589a779 9 *
afilipem 0:c385e589a779 10 * OneWireCRC is free software: you can redistribute it and/or modify
afilipem 0:c385e589a779 11 * it under the terms of the GNU General Public License as published by
afilipem 0:c385e589a779 12 * the Free Software Foundation, either version 3 of the License, or
afilipem 0:c385e589a779 13 * (at your option) any later version.
afilipem 0:c385e589a779 14 *
afilipem 0:c385e589a779 15 * OneWireCRC is distributed in the hope that it will be useful,
afilipem 0:c385e589a779 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
afilipem 0:c385e589a779 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
afilipem 0:c385e589a779 18 * GNU General Public License for more details.
afilipem 0:c385e589a779 19 *
afilipem 0:c385e589a779 20 * You should have received a copy of the GNU General Public License
afilipem 0:c385e589a779 21 * along with OneWireCRC. If not, see <http://www.gnu.org/licenses/>.
afilipem 0:c385e589a779 22 */
afilipem 0:c385e589a779 23 /*
afilipem 0:c385e589a779 24 Copyright (c) 2007, Jim Studt
afilipem 0:c385e589a779 25
afilipem 0:c385e589a779 26 Updated to work with arduino-0008 and to include skip() as of
afilipem 0:c385e589a779 27 2007/07/06. --RJL20
afilipem 0:c385e589a779 28
afilipem 0:c385e589a779 29 Modified to calculate the 8-bit CRC directly, avoiding the need for
afilipem 0:c385e589a779 30 the 256-byte lookup table to be loaded in RAM. Tested in arduino-0010
afilipem 0:c385e589a779 31 -- Tom Pollard, Jan 23, 2008
afilipem 0:c385e589a779 32
afilipem 0:c385e589a779 33 Permission is hereby granted, free of charge, to any person obtaining
afilipem 0:c385e589a779 34 a copy of this software and associated documentation files (the
afilipem 0:c385e589a779 35 "Software"), to deal in the Software without restriction, including
afilipem 0:c385e589a779 36 without limitation the rights to use, copy, modify, merge, publish,
afilipem 0:c385e589a779 37 distribute, sublicense, and/or sell copies of the Software, and to
afilipem 0:c385e589a779 38 permit persons to whom the Software is furnished to do so, subject to
afilipem 0:c385e589a779 39 the following conditions:
afilipem 0:c385e589a779 40
afilipem 0:c385e589a779 41 The above copyright notice and this permission notice shall be
afilipem 0:c385e589a779 42 included in all copies or substantial portions of the Software.
afilipem 0:c385e589a779 43
afilipem 0:c385e589a779 44 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
afilipem 0:c385e589a779 45 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
afilipem 0:c385e589a779 46 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
afilipem 0:c385e589a779 47 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
afilipem 0:c385e589a779 48 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
afilipem 0:c385e589a779 49 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
afilipem 0:c385e589a779 50 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
afilipem 0:c385e589a779 51
afilipem 0:c385e589a779 52 Much of the code was inspired by Derek Yerger's code, though I don't
afilipem 0:c385e589a779 53 think much of that remains. In any event that was..
afilipem 0:c385e589a779 54 (copyleft) 2006 by Derek Yerger - Free to distribute freely.
afilipem 0:c385e589a779 55
afilipem 0:c385e589a779 56 The CRC code was excerpted and inspired by the Dallas Semiconductor
afilipem 0:c385e589a779 57 sample code bearing this copyright.
afilipem 0:c385e589a779 58 */
afilipem 0:c385e589a779 59 //---------------------------------------------------------------------------
afilipem 0:c385e589a779 60 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
afilipem 0:c385e589a779 61 //
afilipem 0:c385e589a779 62 // Permission is hereby granted, free of charge, to any person obtaining a
afilipem 0:c385e589a779 63 // copy of this software and associated documentation files (the "Software"),
afilipem 0:c385e589a779 64 // to deal in the Software without restriction, including without limitation
afilipem 0:c385e589a779 65 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
afilipem 0:c385e589a779 66 // and/or sell copies of the Software, and to permit persons to whom the
afilipem 0:c385e589a779 67 // Software is furnished to do so, subject to the following conditions:
afilipem 0:c385e589a779 68 //
afilipem 0:c385e589a779 69 // The above copyright notice and this permission notice shall be included
afilipem 0:c385e589a779 70 // in all copies or substantial portions of the Software.
afilipem 0:c385e589a779 71 //
afilipem 0:c385e589a779 72 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
afilipem 0:c385e589a779 73 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
afilipem 0:c385e589a779 74 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
afilipem 0:c385e589a779 75 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
afilipem 0:c385e589a779 76 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
afilipem 0:c385e589a779 77 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
afilipem 0:c385e589a779 78 // OTHER DEALINGS IN THE SOFTWARE.
afilipem 0:c385e589a779 79 //
afilipem 0:c385e589a779 80 // Except as contained in this notice, the name of Dallas Semiconductor
afilipem 0:c385e589a779 81 // shall not be used except as stated in the Dallas Semiconductor
afilipem 0:c385e589a779 82 // Branding Policy.
afilipem 0:c385e589a779 83 //--------------------------------------------------------------------------
afilipem 0:c385e589a779 84
afilipem 0:c385e589a779 85 #ifndef SNATCH59_ONEWIRECRC_H
afilipem 0:c385e589a779 86 #define SNATCH59_ONEWIRECRC_H
afilipem 0:c385e589a779 87
afilipem 0:c385e589a779 88 #include <mbed.h>
afilipem 0:c385e589a779 89
afilipem 0:c385e589a779 90 // Select the table-lookup method of computing the 8-bit CRC by setting this to 1
afilipem 0:c385e589a779 91 #ifndef ONEWIRE_CRC8_TABLE
afilipem 0:c385e589a779 92 #define ONEWIRE_CRC8_TABLE 1
afilipem 0:c385e589a779 93 #endif
afilipem 0:c385e589a779 94
afilipem 0:c385e589a779 95 typedef unsigned char BYTE; // used to be uint8_t : something a byte wide, whatever ....
afilipem 0:c385e589a779 96
afilipem 0:c385e589a779 97 enum eSpeed {OVERDRIVE, STANDARD};
afilipem 0:c385e589a779 98
afilipem 0:c385e589a779 99 class OneWireCRC
afilipem 0:c385e589a779 100 {
afilipem 0:c385e589a779 101 public:
afilipem 0:c385e589a779 102 OneWireCRC(PinName oneWire, eSpeed);
afilipem 0:c385e589a779 103
afilipem 0:c385e589a779 104 // reset, read, write functions
afilipem 0:c385e589a779 105 int reset();
afilipem 0:c385e589a779 106 void writeByte(int data);
afilipem 0:c385e589a779 107 int readByte();
afilipem 0:c385e589a779 108 int touchByte(int data);
afilipem 0:c385e589a779 109 void block(BYTE* data, int data_len);
afilipem 0:c385e589a779 110 int overdriveSkip(BYTE* data, int data_len);
afilipem 0:c385e589a779 111
afilipem 0:c385e589a779 112 // address functions
afilipem 0:c385e589a779 113 void matchROM(BYTE rom[8]);
afilipem 0:c385e589a779 114 void skipROM();
afilipem 0:c385e589a779 115
afilipem 0:c385e589a779 116 // address search functions
afilipem 0:c385e589a779 117 void resetSearch();
afilipem 0:c385e589a779 118 BYTE search(BYTE* newAddr);
afilipem 0:c385e589a779 119
afilipem 0:c385e589a779 120 // CRC check functions
afilipem 0:c385e589a779 121 static BYTE crc8(BYTE* addr, BYTE len);
afilipem 0:c385e589a779 122 static unsigned short crc16(unsigned short* data, unsigned short len);
afilipem 0:c385e589a779 123
afilipem 0:c385e589a779 124 private:
afilipem 0:c385e589a779 125 const int* timing;
afilipem 0:c385e589a779 126
afilipem 0:c385e589a779 127 BYTE address[8];
afilipem 0:c385e589a779 128 int searchJunction; // so we can set to it -1 somewhere
afilipem 0:c385e589a779 129 bool searchExhausted;
afilipem 0:c385e589a779 130
afilipem 0:c385e589a779 131 DigitalInOut oneWirePort;
afilipem 0:c385e589a779 132
afilipem 0:c385e589a779 133 // read/write bit functions
afilipem 0:c385e589a779 134 void writeBit(int bit);
afilipem 0:c385e589a779 135 int readBit();
afilipem 0:c385e589a779 136 };
afilipem 0:c385e589a779 137
afilipem 0:c385e589a779 138 #endif