ds2401toieeeeui64c.nc
来自「tinyos-2.x.rar」· NC 代码 · 共 64 行
NC
64 行
// $Id: Ds2401ToIeeeEui64C.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
* Copyright (c) 2007, Vanderbilt University
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author: Janos Sallai
*/
#include "Ds2401.h"
#include "IeeeEui64.h"
#include "PlatformIeeeEui64.h"
/**
* Convert silicon serial ID to IEEE EUI 64, according to Application Note
* 186 - Creating Global Identifiers Using 1-Wire Devices from Dallas/Maxim.
*/
module Ds2401ToIeeeEui64C {
uses interface HplDs2401 as Hpl;
provides interface LocalIeeeEui64;
} implementation {
command ieee_eui64_t LocalIeeeEui64.getId() {
ds2401_serial_t rom;
ieee_eui64_t eui;
atomic {
call Hpl.read(&rom);
}
// company ID
eui.data[0] = IEEE_EUI64_COMPANY_ID_0;
eui.data[1] = IEEE_EUI64_COMPANY_ID_1;
eui.data[2] = IEEE_EUI64_COMPANY_ID_2;
// 16 bits of the ID is generated by software
// could be used for hardware model id and revision, for example
eui.data[3] = IEEE_EUI64_SERIAL_ID_0;
eui.data[4] = IEEE_EUI64_SERIAL_ID_1;
// 24 least significant bits of the serial ID read from the DS2401
eui.data[5] = rom.data[3];
eui.data[6] = rom.data[2];
eui.data[7] = rom.data[1];
return eui;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?