Program that uses the QuickStart Library to interface a SmartMesh IP mote: Connects to the default network and starts publishing a random walk value every 5 seconds.
Fork of QSL_SimplePublish by
QSL SimplePublish
SmartMesh IP QuickStart Library
- GitHub repository
- Current release used: REL-1.0.2.2
- Documentation
- Discussion
sm_clib/dn_ipmt.c@1:89766ea2e99d, 2016-09-01 (annotated)
- Committer:
- jhbr
- Date:
- Thu Sep 01 15:00:28 2016 +0000
- Revision:
- 1:89766ea2e99d
- Parent:
- dn_ipmt.c@0:d3f5fdf2e6da
Moved QSL and C Library files to separate folders
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhbr | 0:d3f5fdf2e6da | 1 | /* |
jhbr | 0:d3f5fdf2e6da | 2 | Copyright (c) 2015, Dust Networks. All rights reserved. |
jhbr | 0:d3f5fdf2e6da | 3 | |
jhbr | 0:d3f5fdf2e6da | 4 | C library to connect to a SmartMesh IP Mote. |
jhbr | 0:d3f5fdf2e6da | 5 | |
jhbr | 0:d3f5fdf2e6da | 6 | \license See attached DN_LICENSE.txt. |
jhbr | 0:d3f5fdf2e6da | 7 | */ |
jhbr | 0:d3f5fdf2e6da | 8 | |
jhbr | 0:d3f5fdf2e6da | 9 | #include "dn_ipmt.h" |
jhbr | 0:d3f5fdf2e6da | 10 | #include "dn_lock.h" |
jhbr | 0:d3f5fdf2e6da | 11 | #include "dn_serial_mt.h" |
jhbr | 0:d3f5fdf2e6da | 12 | |
jhbr | 0:d3f5fdf2e6da | 13 | //=========================== variables ======================================= |
jhbr | 0:d3f5fdf2e6da | 14 | |
jhbr | 0:d3f5fdf2e6da | 15 | typedef struct { |
jhbr | 0:d3f5fdf2e6da | 16 | // sending requests |
jhbr | 0:d3f5fdf2e6da | 17 | uint8_t outputBuf[MAX_FRAME_LENGTH]; |
jhbr | 0:d3f5fdf2e6da | 18 | bool busyTx; |
jhbr | 0:d3f5fdf2e6da | 19 | uint8_t cmdId; |
jhbr | 0:d3f5fdf2e6da | 20 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 21 | // receiving replies |
jhbr | 0:d3f5fdf2e6da | 22 | dn_ipmt_reply_cbt replyCb; |
jhbr | 0:d3f5fdf2e6da | 23 | uint8_t* replyContents; |
jhbr | 0:d3f5fdf2e6da | 24 | // receiving notifications |
jhbr | 0:d3f5fdf2e6da | 25 | dn_ipmt_notif_cbt notifCb; |
jhbr | 0:d3f5fdf2e6da | 26 | uint8_t* notifBuf; |
jhbr | 0:d3f5fdf2e6da | 27 | uint8_t notifBufLen; |
jhbr | 0:d3f5fdf2e6da | 28 | } dn_ipmt_vars_t; |
jhbr | 0:d3f5fdf2e6da | 29 | |
jhbr | 0:d3f5fdf2e6da | 30 | dn_ipmt_vars_t dn_ipmt_vars; |
jhbr | 0:d3f5fdf2e6da | 31 | |
jhbr | 0:d3f5fdf2e6da | 32 | //=========================== prototypes ====================================== |
jhbr | 0:d3f5fdf2e6da | 33 | |
jhbr | 0:d3f5fdf2e6da | 34 | // API |
jhbr | 0:d3f5fdf2e6da | 35 | void dn_ipmt_setParameter_macAddress_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 36 | void dn_ipmt_setParameter_joinKey_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 37 | void dn_ipmt_setParameter_networkId_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 38 | void dn_ipmt_setParameter_txPower_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 39 | void dn_ipmt_setParameter_joinDutyCycle_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 40 | void dn_ipmt_setParameter_eventMask_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 41 | void dn_ipmt_setParameter_OTAPLockout_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 42 | void dn_ipmt_setParameter_routingMode_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 43 | void dn_ipmt_setParameter_powerSrcInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 44 | void dn_ipmt_setParameter_advKey_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 45 | void dn_ipmt_setParameter_autoJoin_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 46 | void dn_ipmt_getParameter_macAddress_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 47 | void dn_ipmt_getParameter_networkId_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 48 | void dn_ipmt_getParameter_txPower_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 49 | void dn_ipmt_getParameter_joinDutyCycle_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 50 | void dn_ipmt_getParameter_eventMask_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 51 | void dn_ipmt_getParameter_moteInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 52 | void dn_ipmt_getParameter_netInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 53 | void dn_ipmt_getParameter_moteStatus_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 54 | void dn_ipmt_getParameter_time_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 55 | void dn_ipmt_getParameter_charge_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 56 | void dn_ipmt_getParameter_testRadioRxStats_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 57 | void dn_ipmt_getParameter_OTAPLockout_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 58 | void dn_ipmt_getParameter_moteId_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 59 | void dn_ipmt_getParameter_ipv6Address_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 60 | void dn_ipmt_getParameter_routingMode_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 61 | void dn_ipmt_getParameter_appInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 62 | void dn_ipmt_getParameter_powerSrcInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 63 | void dn_ipmt_getParameter_autoJoin_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 64 | void dn_ipmt_join_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 65 | void dn_ipmt_disconnect_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 66 | void dn_ipmt_reset_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 67 | void dn_ipmt_lowPowerSleep_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 68 | void dn_ipmt_testRadioRx_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 69 | void dn_ipmt_clearNV_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 70 | void dn_ipmt_requestService_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 71 | void dn_ipmt_getServiceInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 72 | void dn_ipmt_openSocket_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 73 | void dn_ipmt_closeSocket_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 74 | void dn_ipmt_bindSocket_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 75 | void dn_ipmt_sendTo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 76 | void dn_ipmt_search_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 77 | void dn_ipmt_testRadioTxExt_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 78 | void dn_ipmt_zeroize_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 79 | void dn_ipmt_socketInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 80 | |
jhbr | 0:d3f5fdf2e6da | 81 | // serial RX |
jhbr | 0:d3f5fdf2e6da | 82 | void dn_ipmt_rxSerialRequest(uint8_t cmdId, uint8_t flags, uint8_t* payload, uint8_t len); |
jhbr | 0:d3f5fdf2e6da | 83 | |
jhbr | 0:d3f5fdf2e6da | 84 | //=========================== public ========================================== |
jhbr | 0:d3f5fdf2e6da | 85 | |
jhbr | 0:d3f5fdf2e6da | 86 | //========== admin |
jhbr | 0:d3f5fdf2e6da | 87 | |
jhbr | 0:d3f5fdf2e6da | 88 | /** |
jhbr | 0:d3f5fdf2e6da | 89 | \brief Setting up the instance. |
jhbr | 0:d3f5fdf2e6da | 90 | */ |
jhbr | 0:d3f5fdf2e6da | 91 | void dn_ipmt_init(dn_ipmt_notif_cbt notifCb, uint8_t* notifBuf, uint8_t notifBufLen, dn_ipmt_reply_cbt replyCb) { |
jhbr | 0:d3f5fdf2e6da | 92 | |
jhbr | 0:d3f5fdf2e6da | 93 | // reset local variables |
jhbr | 0:d3f5fdf2e6da | 94 | memset(&dn_ipmt_vars,0,sizeof(dn_ipmt_vars)); |
jhbr | 0:d3f5fdf2e6da | 95 | |
jhbr | 0:d3f5fdf2e6da | 96 | // store params |
jhbr | 0:d3f5fdf2e6da | 97 | dn_ipmt_vars.notifCb = notifCb; |
jhbr | 0:d3f5fdf2e6da | 98 | dn_ipmt_vars.notifBuf = notifBuf; |
jhbr | 0:d3f5fdf2e6da | 99 | dn_ipmt_vars.notifBufLen = notifBufLen; |
jhbr | 0:d3f5fdf2e6da | 100 | dn_ipmt_vars.replyCb = replyCb; |
jhbr | 0:d3f5fdf2e6da | 101 | |
jhbr | 0:d3f5fdf2e6da | 102 | // initialize the serial connection |
jhbr | 0:d3f5fdf2e6da | 103 | dn_serial_mt_init(dn_ipmt_rxSerialRequest); |
jhbr | 0:d3f5fdf2e6da | 104 | } |
jhbr | 0:d3f5fdf2e6da | 105 | |
jhbr | 0:d3f5fdf2e6da | 106 | void dn_ipmt_cancelTx() { |
jhbr | 0:d3f5fdf2e6da | 107 | |
jhbr | 0:d3f5fdf2e6da | 108 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 109 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 110 | |
jhbr | 0:d3f5fdf2e6da | 111 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 112 | |
jhbr | 0:d3f5fdf2e6da | 113 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 114 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 115 | } |
jhbr | 0:d3f5fdf2e6da | 116 | |
jhbr | 0:d3f5fdf2e6da | 117 | |
jhbr | 0:d3f5fdf2e6da | 118 | |
jhbr | 0:d3f5fdf2e6da | 119 | //========== API |
jhbr | 0:d3f5fdf2e6da | 120 | |
jhbr | 0:d3f5fdf2e6da | 121 | //===== setParameter_macAddress |
jhbr | 0:d3f5fdf2e6da | 122 | |
jhbr | 0:d3f5fdf2e6da | 123 | /** |
jhbr | 0:d3f5fdf2e6da | 124 | This command allows user to overwrite the manufacturer-assigned MAC address of |
jhbr | 0:d3f5fdf2e6da | 125 | the mote. The new value takes effect after the mote resets. |
jhbr | 0:d3f5fdf2e6da | 126 | */ |
jhbr | 0:d3f5fdf2e6da | 127 | dn_err_t dn_ipmt_setParameter_macAddress(uint8_t* macAddress, dn_ipmt_setParameter_macAddress_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 128 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 129 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 130 | |
jhbr | 0:d3f5fdf2e6da | 131 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 132 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 133 | |
jhbr | 0:d3f5fdf2e6da | 134 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 135 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 136 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 137 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 138 | |
jhbr | 0:d3f5fdf2e6da | 139 | // return |
jhbr | 0:d3f5fdf2e6da | 140 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 141 | } |
jhbr | 0:d3f5fdf2e6da | 142 | |
jhbr | 0:d3f5fdf2e6da | 143 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 144 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 145 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 146 | dn_ipmt_vars.paramId = PARAMID_MACADDRESS; |
jhbr | 0:d3f5fdf2e6da | 147 | |
jhbr | 0:d3f5fdf2e6da | 148 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 149 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 150 | |
jhbr | 0:d3f5fdf2e6da | 151 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 152 | dn_ipmt_vars.outputBuf[0] = PARAMID_MACADDRESS; |
jhbr | 0:d3f5fdf2e6da | 153 | memcpy(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_MACADDRESS_REQ_OFFS_MACADDRESS],macAddress,8); |
jhbr | 0:d3f5fdf2e6da | 154 | |
jhbr | 0:d3f5fdf2e6da | 155 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 156 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 157 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 158 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 159 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 160 | DN_SETPARAMETER_MACADDRESS_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 161 | dn_ipmt_setParameter_macAddress_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 162 | ); |
jhbr | 0:d3f5fdf2e6da | 163 | |
jhbr | 0:d3f5fdf2e6da | 164 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 165 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 166 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 167 | } |
jhbr | 0:d3f5fdf2e6da | 168 | |
jhbr | 0:d3f5fdf2e6da | 169 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 170 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 171 | |
jhbr | 0:d3f5fdf2e6da | 172 | return rc; |
jhbr | 0:d3f5fdf2e6da | 173 | |
jhbr | 0:d3f5fdf2e6da | 174 | } |
jhbr | 0:d3f5fdf2e6da | 175 | |
jhbr | 0:d3f5fdf2e6da | 176 | void dn_ipmt_setParameter_macAddress_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 177 | dn_ipmt_setParameter_macAddress_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 178 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 179 | |
jhbr | 0:d3f5fdf2e6da | 180 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 181 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 182 | return; |
jhbr | 0:d3f5fdf2e6da | 183 | } |
jhbr | 0:d3f5fdf2e6da | 184 | |
jhbr | 0:d3f5fdf2e6da | 185 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 186 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 187 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 188 | return; |
jhbr | 0:d3f5fdf2e6da | 189 | } |
jhbr | 0:d3f5fdf2e6da | 190 | |
jhbr | 0:d3f5fdf2e6da | 191 | // verify length |
jhbr | 0:d3f5fdf2e6da | 192 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_MACADDRESS_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 193 | return; |
jhbr | 0:d3f5fdf2e6da | 194 | } |
jhbr | 0:d3f5fdf2e6da | 195 | |
jhbr | 0:d3f5fdf2e6da | 196 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 197 | reply = (dn_ipmt_setParameter_macAddress_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 198 | |
jhbr | 0:d3f5fdf2e6da | 199 | // store RC |
jhbr | 0:d3f5fdf2e6da | 200 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 201 | |
jhbr | 0:d3f5fdf2e6da | 202 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 203 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 204 | |
jhbr | 0:d3f5fdf2e6da | 205 | } |
jhbr | 0:d3f5fdf2e6da | 206 | |
jhbr | 0:d3f5fdf2e6da | 207 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 208 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 209 | |
jhbr | 0:d3f5fdf2e6da | 210 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 211 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 212 | } |
jhbr | 0:d3f5fdf2e6da | 213 | |
jhbr | 0:d3f5fdf2e6da | 214 | //===== setParameter_joinKey |
jhbr | 0:d3f5fdf2e6da | 215 | |
jhbr | 0:d3f5fdf2e6da | 216 | /** |
jhbr | 0:d3f5fdf2e6da | 217 | The setParameter<joinKey> command may be used to set the join key in mote's |
jhbr | 0:d3f5fdf2e6da | 218 | persistent storage. Join keys are used by motes to establish secure connection |
jhbr | 0:d3f5fdf2e6da | 219 | with the network. The join key is used at next join. |
jhbr | 0:d3f5fdf2e6da | 220 | |
jhbr | 0:d3f5fdf2e6da | 221 | Reading the joinKey parameter is prohibited for security reasons. |
jhbr | 0:d3f5fdf2e6da | 222 | */ |
jhbr | 0:d3f5fdf2e6da | 223 | dn_err_t dn_ipmt_setParameter_joinKey(uint8_t* joinKey, dn_ipmt_setParameter_joinKey_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 224 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 225 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 226 | |
jhbr | 0:d3f5fdf2e6da | 227 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 228 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 229 | |
jhbr | 0:d3f5fdf2e6da | 230 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 231 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 232 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 233 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 234 | |
jhbr | 0:d3f5fdf2e6da | 235 | // return |
jhbr | 0:d3f5fdf2e6da | 236 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 237 | } |
jhbr | 0:d3f5fdf2e6da | 238 | |
jhbr | 0:d3f5fdf2e6da | 239 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 240 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 241 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 242 | dn_ipmt_vars.paramId = PARAMID_JOINKEY; |
jhbr | 0:d3f5fdf2e6da | 243 | |
jhbr | 0:d3f5fdf2e6da | 244 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 245 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 246 | |
jhbr | 0:d3f5fdf2e6da | 247 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 248 | dn_ipmt_vars.outputBuf[0] = PARAMID_JOINKEY; |
jhbr | 0:d3f5fdf2e6da | 249 | memcpy(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_JOINKEY_REQ_OFFS_JOINKEY],joinKey,16); |
jhbr | 0:d3f5fdf2e6da | 250 | |
jhbr | 0:d3f5fdf2e6da | 251 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 252 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 253 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 254 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 255 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 256 | DN_SETPARAMETER_JOINKEY_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 257 | dn_ipmt_setParameter_joinKey_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 258 | ); |
jhbr | 0:d3f5fdf2e6da | 259 | |
jhbr | 0:d3f5fdf2e6da | 260 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 261 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 262 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 263 | } |
jhbr | 0:d3f5fdf2e6da | 264 | |
jhbr | 0:d3f5fdf2e6da | 265 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 266 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 267 | |
jhbr | 0:d3f5fdf2e6da | 268 | return rc; |
jhbr | 0:d3f5fdf2e6da | 269 | |
jhbr | 0:d3f5fdf2e6da | 270 | } |
jhbr | 0:d3f5fdf2e6da | 271 | |
jhbr | 0:d3f5fdf2e6da | 272 | void dn_ipmt_setParameter_joinKey_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 273 | dn_ipmt_setParameter_joinKey_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 274 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 275 | |
jhbr | 0:d3f5fdf2e6da | 276 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 277 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 278 | return; |
jhbr | 0:d3f5fdf2e6da | 279 | } |
jhbr | 0:d3f5fdf2e6da | 280 | |
jhbr | 0:d3f5fdf2e6da | 281 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 282 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 283 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 284 | return; |
jhbr | 0:d3f5fdf2e6da | 285 | } |
jhbr | 0:d3f5fdf2e6da | 286 | |
jhbr | 0:d3f5fdf2e6da | 287 | // verify length |
jhbr | 0:d3f5fdf2e6da | 288 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_JOINKEY_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 289 | return; |
jhbr | 0:d3f5fdf2e6da | 290 | } |
jhbr | 0:d3f5fdf2e6da | 291 | |
jhbr | 0:d3f5fdf2e6da | 292 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 293 | reply = (dn_ipmt_setParameter_joinKey_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 294 | |
jhbr | 0:d3f5fdf2e6da | 295 | // store RC |
jhbr | 0:d3f5fdf2e6da | 296 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 297 | |
jhbr | 0:d3f5fdf2e6da | 298 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 299 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 300 | |
jhbr | 0:d3f5fdf2e6da | 301 | } |
jhbr | 0:d3f5fdf2e6da | 302 | |
jhbr | 0:d3f5fdf2e6da | 303 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 304 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 305 | |
jhbr | 0:d3f5fdf2e6da | 306 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 307 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 308 | } |
jhbr | 0:d3f5fdf2e6da | 309 | |
jhbr | 0:d3f5fdf2e6da | 310 | //===== setParameter_networkId |
jhbr | 0:d3f5fdf2e6da | 311 | |
jhbr | 0:d3f5fdf2e6da | 312 | /** |
jhbr | 0:d3f5fdf2e6da | 313 | This command may be used to set the Network ID of the mote. This setting is |
jhbr | 0:d3f5fdf2e6da | 314 | persistent and is used on next join attempt. |
jhbr | 0:d3f5fdf2e6da | 315 | |
jhbr | 0:d3f5fdf2e6da | 316 | As of version 1.4.x, a network ID of 0xFFFF can be used to indicate that the |
jhbr | 0:d3f5fdf2e6da | 317 | mote should join the first network heard. |
jhbr | 0:d3f5fdf2e6da | 318 | |
jhbr | 0:d3f5fdf2e6da | 319 | 0xFFFF is never used over the air as a valid network ID - you should not set |
jhbr | 0:d3f5fdf2e6da | 320 | the Manager's network ID to 0xFFFF. |
jhbr | 0:d3f5fdf2e6da | 321 | */ |
jhbr | 0:d3f5fdf2e6da | 322 | dn_err_t dn_ipmt_setParameter_networkId(uint16_t networkId, dn_ipmt_setParameter_networkId_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 323 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 324 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 325 | |
jhbr | 0:d3f5fdf2e6da | 326 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 327 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 328 | |
jhbr | 0:d3f5fdf2e6da | 329 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 330 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 331 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 332 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 333 | |
jhbr | 0:d3f5fdf2e6da | 334 | // return |
jhbr | 0:d3f5fdf2e6da | 335 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 336 | } |
jhbr | 0:d3f5fdf2e6da | 337 | |
jhbr | 0:d3f5fdf2e6da | 338 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 339 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 340 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 341 | dn_ipmt_vars.paramId = PARAMID_NETWORKID; |
jhbr | 0:d3f5fdf2e6da | 342 | |
jhbr | 0:d3f5fdf2e6da | 343 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 344 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 345 | |
jhbr | 0:d3f5fdf2e6da | 346 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 347 | dn_ipmt_vars.outputBuf[0] = PARAMID_NETWORKID; |
jhbr | 0:d3f5fdf2e6da | 348 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_NETWORKID_REQ_OFFS_NETWORKID],networkId); |
jhbr | 0:d3f5fdf2e6da | 349 | |
jhbr | 0:d3f5fdf2e6da | 350 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 351 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 352 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 353 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 354 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 355 | DN_SETPARAMETER_NETWORKID_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 356 | dn_ipmt_setParameter_networkId_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 357 | ); |
jhbr | 0:d3f5fdf2e6da | 358 | |
jhbr | 0:d3f5fdf2e6da | 359 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 360 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 361 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 362 | } |
jhbr | 0:d3f5fdf2e6da | 363 | |
jhbr | 0:d3f5fdf2e6da | 364 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 365 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 366 | |
jhbr | 0:d3f5fdf2e6da | 367 | return rc; |
jhbr | 0:d3f5fdf2e6da | 368 | |
jhbr | 0:d3f5fdf2e6da | 369 | } |
jhbr | 0:d3f5fdf2e6da | 370 | |
jhbr | 0:d3f5fdf2e6da | 371 | void dn_ipmt_setParameter_networkId_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 372 | dn_ipmt_setParameter_networkId_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 373 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 374 | |
jhbr | 0:d3f5fdf2e6da | 375 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 376 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 377 | return; |
jhbr | 0:d3f5fdf2e6da | 378 | } |
jhbr | 0:d3f5fdf2e6da | 379 | |
jhbr | 0:d3f5fdf2e6da | 380 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 381 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 382 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 383 | return; |
jhbr | 0:d3f5fdf2e6da | 384 | } |
jhbr | 0:d3f5fdf2e6da | 385 | |
jhbr | 0:d3f5fdf2e6da | 386 | // verify length |
jhbr | 0:d3f5fdf2e6da | 387 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_NETWORKID_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 388 | return; |
jhbr | 0:d3f5fdf2e6da | 389 | } |
jhbr | 0:d3f5fdf2e6da | 390 | |
jhbr | 0:d3f5fdf2e6da | 391 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 392 | reply = (dn_ipmt_setParameter_networkId_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 393 | |
jhbr | 0:d3f5fdf2e6da | 394 | // store RC |
jhbr | 0:d3f5fdf2e6da | 395 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 396 | |
jhbr | 0:d3f5fdf2e6da | 397 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 398 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 399 | |
jhbr | 0:d3f5fdf2e6da | 400 | } |
jhbr | 0:d3f5fdf2e6da | 401 | |
jhbr | 0:d3f5fdf2e6da | 402 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 403 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 404 | |
jhbr | 0:d3f5fdf2e6da | 405 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 406 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 407 | } |
jhbr | 0:d3f5fdf2e6da | 408 | |
jhbr | 0:d3f5fdf2e6da | 409 | //===== setParameter_txPower |
jhbr | 0:d3f5fdf2e6da | 410 | |
jhbr | 0:d3f5fdf2e6da | 411 | /** |
jhbr | 0:d3f5fdf2e6da | 412 | The setParameter<txPower> command sets the mote output power. This setting is |
jhbr | 0:d3f5fdf2e6da | 413 | persistent. The command may be issued at any time and takes effect on next |
jhbr | 0:d3f5fdf2e6da | 414 | transmission. Refer to product datasheets for supported RF output power values. |
jhbr | 0:d3f5fdf2e6da | 415 | For example, if the mote has a typical RF output power of +8 dBm when the power |
jhbr | 0:d3f5fdf2e6da | 416 | amplifier (PA) is enabled, then set the txPower parameter to 8 to enable the |
jhbr | 0:d3f5fdf2e6da | 417 | PA. Similarly, if the mote has a typical RF output power of 0 dBm when the PA |
jhbr | 0:d3f5fdf2e6da | 418 | is disabled, then set the txPower parameter to 0 to turn off the PA. |
jhbr | 0:d3f5fdf2e6da | 419 | */ |
jhbr | 0:d3f5fdf2e6da | 420 | dn_err_t dn_ipmt_setParameter_txPower(int8_t txPower, dn_ipmt_setParameter_txPower_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 421 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 422 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 423 | |
jhbr | 0:d3f5fdf2e6da | 424 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 425 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 426 | |
jhbr | 0:d3f5fdf2e6da | 427 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 428 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 429 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 430 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 431 | |
jhbr | 0:d3f5fdf2e6da | 432 | // return |
jhbr | 0:d3f5fdf2e6da | 433 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 434 | } |
jhbr | 0:d3f5fdf2e6da | 435 | |
jhbr | 0:d3f5fdf2e6da | 436 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 437 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 438 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 439 | dn_ipmt_vars.paramId = PARAMID_TXPOWER; |
jhbr | 0:d3f5fdf2e6da | 440 | |
jhbr | 0:d3f5fdf2e6da | 441 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 442 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 443 | |
jhbr | 0:d3f5fdf2e6da | 444 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 445 | dn_ipmt_vars.outputBuf[0] = PARAMID_TXPOWER; |
jhbr | 0:d3f5fdf2e6da | 446 | dn_ipmt_vars.outputBuf[DN_SETPARAMETER_TXPOWER_REQ_OFFS_TXPOWER] = (int8_t)txPower; |
jhbr | 0:d3f5fdf2e6da | 447 | |
jhbr | 0:d3f5fdf2e6da | 448 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 449 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 450 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 451 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 452 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 453 | DN_SETPARAMETER_TXPOWER_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 454 | dn_ipmt_setParameter_txPower_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 455 | ); |
jhbr | 0:d3f5fdf2e6da | 456 | |
jhbr | 0:d3f5fdf2e6da | 457 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 458 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 459 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 460 | } |
jhbr | 0:d3f5fdf2e6da | 461 | |
jhbr | 0:d3f5fdf2e6da | 462 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 463 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 464 | |
jhbr | 0:d3f5fdf2e6da | 465 | return rc; |
jhbr | 0:d3f5fdf2e6da | 466 | |
jhbr | 0:d3f5fdf2e6da | 467 | } |
jhbr | 0:d3f5fdf2e6da | 468 | |
jhbr | 0:d3f5fdf2e6da | 469 | void dn_ipmt_setParameter_txPower_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 470 | dn_ipmt_setParameter_txPower_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 471 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 472 | |
jhbr | 0:d3f5fdf2e6da | 473 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 474 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 475 | return; |
jhbr | 0:d3f5fdf2e6da | 476 | } |
jhbr | 0:d3f5fdf2e6da | 477 | |
jhbr | 0:d3f5fdf2e6da | 478 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 479 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 480 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 481 | return; |
jhbr | 0:d3f5fdf2e6da | 482 | } |
jhbr | 0:d3f5fdf2e6da | 483 | |
jhbr | 0:d3f5fdf2e6da | 484 | // verify length |
jhbr | 0:d3f5fdf2e6da | 485 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_TXPOWER_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 486 | return; |
jhbr | 0:d3f5fdf2e6da | 487 | } |
jhbr | 0:d3f5fdf2e6da | 488 | |
jhbr | 0:d3f5fdf2e6da | 489 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 490 | reply = (dn_ipmt_setParameter_txPower_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 491 | |
jhbr | 0:d3f5fdf2e6da | 492 | // store RC |
jhbr | 0:d3f5fdf2e6da | 493 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 494 | |
jhbr | 0:d3f5fdf2e6da | 495 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 496 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 497 | |
jhbr | 0:d3f5fdf2e6da | 498 | } |
jhbr | 0:d3f5fdf2e6da | 499 | |
jhbr | 0:d3f5fdf2e6da | 500 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 501 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 502 | |
jhbr | 0:d3f5fdf2e6da | 503 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 504 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 505 | } |
jhbr | 0:d3f5fdf2e6da | 506 | |
jhbr | 0:d3f5fdf2e6da | 507 | //===== setParameter_joinDutyCycle |
jhbr | 0:d3f5fdf2e6da | 508 | |
jhbr | 0:d3f5fdf2e6da | 509 | /** |
jhbr | 0:d3f5fdf2e6da | 510 | The setParameter<joinDutyCycle> command allows the microprocessor to control |
jhbr | 0:d3f5fdf2e6da | 511 | the ratio of active listen time to doze time (a low-power radio state) during |
jhbr | 0:d3f5fdf2e6da | 512 | the period when the mote is searching for the network. If you desire a faster |
jhbr | 0:d3f5fdf2e6da | 513 | join time at the risk of higher power consumption, use the |
jhbr | 0:d3f5fdf2e6da | 514 | setParameter<joinDutyCycle> command to increase the join duty cycle up to 100%. |
jhbr | 0:d3f5fdf2e6da | 515 | This setting is persistent and takes effect immediately if the device is |
jhbr | 0:d3f5fdf2e6da | 516 | searching for network. |
jhbr | 0:d3f5fdf2e6da | 517 | */ |
jhbr | 0:d3f5fdf2e6da | 518 | dn_err_t dn_ipmt_setParameter_joinDutyCycle(uint8_t dutyCycle, dn_ipmt_setParameter_joinDutyCycle_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 519 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 520 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 521 | |
jhbr | 0:d3f5fdf2e6da | 522 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 523 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 524 | |
jhbr | 0:d3f5fdf2e6da | 525 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 526 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 527 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 528 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 529 | |
jhbr | 0:d3f5fdf2e6da | 530 | // return |
jhbr | 0:d3f5fdf2e6da | 531 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 532 | } |
jhbr | 0:d3f5fdf2e6da | 533 | |
jhbr | 0:d3f5fdf2e6da | 534 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 535 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 536 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 537 | dn_ipmt_vars.paramId = PARAMID_JOINDUTYCYCLE; |
jhbr | 0:d3f5fdf2e6da | 538 | |
jhbr | 0:d3f5fdf2e6da | 539 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 540 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 541 | |
jhbr | 0:d3f5fdf2e6da | 542 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 543 | dn_ipmt_vars.outputBuf[0] = PARAMID_JOINDUTYCYCLE; |
jhbr | 0:d3f5fdf2e6da | 544 | dn_ipmt_vars.outputBuf[DN_SETPARAMETER_JOINDUTYCYCLE_REQ_OFFS_DUTYCYCLE] = dutyCycle; |
jhbr | 0:d3f5fdf2e6da | 545 | |
jhbr | 0:d3f5fdf2e6da | 546 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 547 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 548 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 549 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 550 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 551 | DN_SETPARAMETER_JOINDUTYCYCLE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 552 | dn_ipmt_setParameter_joinDutyCycle_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 553 | ); |
jhbr | 0:d3f5fdf2e6da | 554 | |
jhbr | 0:d3f5fdf2e6da | 555 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 556 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 557 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 558 | } |
jhbr | 0:d3f5fdf2e6da | 559 | |
jhbr | 0:d3f5fdf2e6da | 560 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 561 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 562 | |
jhbr | 0:d3f5fdf2e6da | 563 | return rc; |
jhbr | 0:d3f5fdf2e6da | 564 | |
jhbr | 0:d3f5fdf2e6da | 565 | } |
jhbr | 0:d3f5fdf2e6da | 566 | |
jhbr | 0:d3f5fdf2e6da | 567 | void dn_ipmt_setParameter_joinDutyCycle_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 568 | dn_ipmt_setParameter_joinDutyCycle_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 569 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 570 | |
jhbr | 0:d3f5fdf2e6da | 571 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 572 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 573 | return; |
jhbr | 0:d3f5fdf2e6da | 574 | } |
jhbr | 0:d3f5fdf2e6da | 575 | |
jhbr | 0:d3f5fdf2e6da | 576 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 577 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 578 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 579 | return; |
jhbr | 0:d3f5fdf2e6da | 580 | } |
jhbr | 0:d3f5fdf2e6da | 581 | |
jhbr | 0:d3f5fdf2e6da | 582 | // verify length |
jhbr | 0:d3f5fdf2e6da | 583 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_JOINDUTYCYCLE_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 584 | return; |
jhbr | 0:d3f5fdf2e6da | 585 | } |
jhbr | 0:d3f5fdf2e6da | 586 | |
jhbr | 0:d3f5fdf2e6da | 587 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 588 | reply = (dn_ipmt_setParameter_joinDutyCycle_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 589 | |
jhbr | 0:d3f5fdf2e6da | 590 | // store RC |
jhbr | 0:d3f5fdf2e6da | 591 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 592 | |
jhbr | 0:d3f5fdf2e6da | 593 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 594 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 595 | |
jhbr | 0:d3f5fdf2e6da | 596 | } |
jhbr | 0:d3f5fdf2e6da | 597 | |
jhbr | 0:d3f5fdf2e6da | 598 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 599 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 600 | |
jhbr | 0:d3f5fdf2e6da | 601 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 602 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 603 | } |
jhbr | 0:d3f5fdf2e6da | 604 | |
jhbr | 0:d3f5fdf2e6da | 605 | //===== setParameter_eventMask |
jhbr | 0:d3f5fdf2e6da | 606 | |
jhbr | 0:d3f5fdf2e6da | 607 | /** |
jhbr | 0:d3f5fdf2e6da | 608 | The setParameter<eventMask> command allows the microprocessor to selectively |
jhbr | 0:d3f5fdf2e6da | 609 | subscribe to event notifications. The default value of eventMask at mote reset |
jhbr | 0:d3f5fdf2e6da | 610 | is all 1s - all events are enabled. This setting is not persistent. |
jhbr | 0:d3f5fdf2e6da | 611 | |
jhbr | 0:d3f5fdf2e6da | 612 | New event type may be added in future revisions of mote software. It is |
jhbr | 0:d3f5fdf2e6da | 613 | recommended that the client code only subscribe to known events and gracefully |
jhbr | 0:d3f5fdf2e6da | 614 | ignore all unknown events. |
jhbr | 0:d3f5fdf2e6da | 615 | */ |
jhbr | 0:d3f5fdf2e6da | 616 | dn_err_t dn_ipmt_setParameter_eventMask(uint32_t eventMask, dn_ipmt_setParameter_eventMask_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 617 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 618 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 619 | |
jhbr | 0:d3f5fdf2e6da | 620 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 621 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 622 | |
jhbr | 0:d3f5fdf2e6da | 623 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 624 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 625 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 626 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 627 | |
jhbr | 0:d3f5fdf2e6da | 628 | // return |
jhbr | 0:d3f5fdf2e6da | 629 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 630 | } |
jhbr | 0:d3f5fdf2e6da | 631 | |
jhbr | 0:d3f5fdf2e6da | 632 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 633 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 634 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 635 | dn_ipmt_vars.paramId = PARAMID_EVENTMASK; |
jhbr | 0:d3f5fdf2e6da | 636 | |
jhbr | 0:d3f5fdf2e6da | 637 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 638 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 639 | |
jhbr | 0:d3f5fdf2e6da | 640 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 641 | dn_ipmt_vars.outputBuf[0] = PARAMID_EVENTMASK; |
jhbr | 0:d3f5fdf2e6da | 642 | dn_write_uint32_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_EVENTMASK_REQ_OFFS_EVENTMASK],eventMask); |
jhbr | 0:d3f5fdf2e6da | 643 | |
jhbr | 0:d3f5fdf2e6da | 644 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 645 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 646 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 647 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 648 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 649 | DN_SETPARAMETER_EVENTMASK_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 650 | dn_ipmt_setParameter_eventMask_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 651 | ); |
jhbr | 0:d3f5fdf2e6da | 652 | |
jhbr | 0:d3f5fdf2e6da | 653 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 654 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 655 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 656 | } |
jhbr | 0:d3f5fdf2e6da | 657 | |
jhbr | 0:d3f5fdf2e6da | 658 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 659 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 660 | |
jhbr | 0:d3f5fdf2e6da | 661 | return rc; |
jhbr | 0:d3f5fdf2e6da | 662 | |
jhbr | 0:d3f5fdf2e6da | 663 | } |
jhbr | 0:d3f5fdf2e6da | 664 | |
jhbr | 0:d3f5fdf2e6da | 665 | void dn_ipmt_setParameter_eventMask_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 666 | dn_ipmt_setParameter_eventMask_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 667 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 668 | |
jhbr | 0:d3f5fdf2e6da | 669 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 670 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 671 | return; |
jhbr | 0:d3f5fdf2e6da | 672 | } |
jhbr | 0:d3f5fdf2e6da | 673 | |
jhbr | 0:d3f5fdf2e6da | 674 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 675 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 676 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 677 | return; |
jhbr | 0:d3f5fdf2e6da | 678 | } |
jhbr | 0:d3f5fdf2e6da | 679 | |
jhbr | 0:d3f5fdf2e6da | 680 | // verify length |
jhbr | 0:d3f5fdf2e6da | 681 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_EVENTMASK_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 682 | return; |
jhbr | 0:d3f5fdf2e6da | 683 | } |
jhbr | 0:d3f5fdf2e6da | 684 | |
jhbr | 0:d3f5fdf2e6da | 685 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 686 | reply = (dn_ipmt_setParameter_eventMask_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 687 | |
jhbr | 0:d3f5fdf2e6da | 688 | // store RC |
jhbr | 0:d3f5fdf2e6da | 689 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 690 | |
jhbr | 0:d3f5fdf2e6da | 691 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 692 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 693 | |
jhbr | 0:d3f5fdf2e6da | 694 | } |
jhbr | 0:d3f5fdf2e6da | 695 | |
jhbr | 0:d3f5fdf2e6da | 696 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 697 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 698 | |
jhbr | 0:d3f5fdf2e6da | 699 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 700 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 701 | } |
jhbr | 0:d3f5fdf2e6da | 702 | |
jhbr | 0:d3f5fdf2e6da | 703 | //===== setParameter_OTAPLockout |
jhbr | 0:d3f5fdf2e6da | 704 | |
jhbr | 0:d3f5fdf2e6da | 705 | /** |
jhbr | 0:d3f5fdf2e6da | 706 | This command allows the microprocessor to control whether Over-The-Air |
jhbr | 0:d3f5fdf2e6da | 707 | Programming (OTAP) of motes is allowed. This setting is persistent and takes |
jhbr | 0:d3f5fdf2e6da | 708 | effect immediately. |
jhbr | 0:d3f5fdf2e6da | 709 | */ |
jhbr | 0:d3f5fdf2e6da | 710 | dn_err_t dn_ipmt_setParameter_OTAPLockout(bool mode, dn_ipmt_setParameter_OTAPLockout_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 711 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 712 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 713 | |
jhbr | 0:d3f5fdf2e6da | 714 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 715 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 716 | |
jhbr | 0:d3f5fdf2e6da | 717 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 718 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 719 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 720 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 721 | |
jhbr | 0:d3f5fdf2e6da | 722 | // return |
jhbr | 0:d3f5fdf2e6da | 723 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 724 | } |
jhbr | 0:d3f5fdf2e6da | 725 | |
jhbr | 0:d3f5fdf2e6da | 726 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 727 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 728 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 729 | dn_ipmt_vars.paramId = PARAMID_OTAPLOCKOUT; |
jhbr | 0:d3f5fdf2e6da | 730 | |
jhbr | 0:d3f5fdf2e6da | 731 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 732 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 733 | |
jhbr | 0:d3f5fdf2e6da | 734 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 735 | dn_ipmt_vars.outputBuf[0] = PARAMID_OTAPLOCKOUT; |
jhbr | 0:d3f5fdf2e6da | 736 | dn_ipmt_vars.outputBuf[DN_SETPARAMETER_OTAPLOCKOUT_REQ_OFFS_MODE] = mode; |
jhbr | 0:d3f5fdf2e6da | 737 | |
jhbr | 0:d3f5fdf2e6da | 738 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 739 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 740 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 741 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 742 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 743 | DN_SETPARAMETER_OTAPLOCKOUT_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 744 | dn_ipmt_setParameter_OTAPLockout_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 745 | ); |
jhbr | 0:d3f5fdf2e6da | 746 | |
jhbr | 0:d3f5fdf2e6da | 747 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 748 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 749 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 750 | } |
jhbr | 0:d3f5fdf2e6da | 751 | |
jhbr | 0:d3f5fdf2e6da | 752 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 753 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 754 | |
jhbr | 0:d3f5fdf2e6da | 755 | return rc; |
jhbr | 0:d3f5fdf2e6da | 756 | |
jhbr | 0:d3f5fdf2e6da | 757 | } |
jhbr | 0:d3f5fdf2e6da | 758 | |
jhbr | 0:d3f5fdf2e6da | 759 | void dn_ipmt_setParameter_OTAPLockout_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 760 | dn_ipmt_setParameter_OTAPLockout_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 761 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 762 | |
jhbr | 0:d3f5fdf2e6da | 763 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 764 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 765 | return; |
jhbr | 0:d3f5fdf2e6da | 766 | } |
jhbr | 0:d3f5fdf2e6da | 767 | |
jhbr | 0:d3f5fdf2e6da | 768 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 769 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 770 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 771 | return; |
jhbr | 0:d3f5fdf2e6da | 772 | } |
jhbr | 0:d3f5fdf2e6da | 773 | |
jhbr | 0:d3f5fdf2e6da | 774 | // verify length |
jhbr | 0:d3f5fdf2e6da | 775 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_OTAPLOCKOUT_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 776 | return; |
jhbr | 0:d3f5fdf2e6da | 777 | } |
jhbr | 0:d3f5fdf2e6da | 778 | |
jhbr | 0:d3f5fdf2e6da | 779 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 780 | reply = (dn_ipmt_setParameter_OTAPLockout_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 781 | |
jhbr | 0:d3f5fdf2e6da | 782 | // store RC |
jhbr | 0:d3f5fdf2e6da | 783 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 784 | |
jhbr | 0:d3f5fdf2e6da | 785 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 786 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 787 | |
jhbr | 0:d3f5fdf2e6da | 788 | } |
jhbr | 0:d3f5fdf2e6da | 789 | |
jhbr | 0:d3f5fdf2e6da | 790 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 791 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 792 | |
jhbr | 0:d3f5fdf2e6da | 793 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 794 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 795 | } |
jhbr | 0:d3f5fdf2e6da | 796 | |
jhbr | 0:d3f5fdf2e6da | 797 | //===== setParameter_routingMode |
jhbr | 0:d3f5fdf2e6da | 798 | |
jhbr | 0:d3f5fdf2e6da | 799 | /** |
jhbr | 0:d3f5fdf2e6da | 800 | This command allows the microprocessor to control whether the mote will become |
jhbr | 0:d3f5fdf2e6da | 801 | a router once joined the network. If disabled, the manager will keep the mote a |
jhbr | 0:d3f5fdf2e6da | 802 | leaf node. |
jhbr | 0:d3f5fdf2e6da | 803 | */ |
jhbr | 0:d3f5fdf2e6da | 804 | dn_err_t dn_ipmt_setParameter_routingMode(bool mode, dn_ipmt_setParameter_routingMode_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 805 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 806 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 807 | |
jhbr | 0:d3f5fdf2e6da | 808 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 809 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 810 | |
jhbr | 0:d3f5fdf2e6da | 811 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 812 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 813 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 814 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 815 | |
jhbr | 0:d3f5fdf2e6da | 816 | // return |
jhbr | 0:d3f5fdf2e6da | 817 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 818 | } |
jhbr | 0:d3f5fdf2e6da | 819 | |
jhbr | 0:d3f5fdf2e6da | 820 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 821 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 822 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 823 | dn_ipmt_vars.paramId = PARAMID_ROUTINGMODE; |
jhbr | 0:d3f5fdf2e6da | 824 | |
jhbr | 0:d3f5fdf2e6da | 825 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 826 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 827 | |
jhbr | 0:d3f5fdf2e6da | 828 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 829 | dn_ipmt_vars.outputBuf[0] = PARAMID_ROUTINGMODE; |
jhbr | 0:d3f5fdf2e6da | 830 | dn_ipmt_vars.outputBuf[DN_SETPARAMETER_ROUTINGMODE_REQ_OFFS_MODE] = mode; |
jhbr | 0:d3f5fdf2e6da | 831 | |
jhbr | 0:d3f5fdf2e6da | 832 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 833 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 834 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 835 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 836 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 837 | DN_SETPARAMETER_ROUTINGMODE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 838 | dn_ipmt_setParameter_routingMode_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 839 | ); |
jhbr | 0:d3f5fdf2e6da | 840 | |
jhbr | 0:d3f5fdf2e6da | 841 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 842 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 843 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 844 | } |
jhbr | 0:d3f5fdf2e6da | 845 | |
jhbr | 0:d3f5fdf2e6da | 846 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 847 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 848 | |
jhbr | 0:d3f5fdf2e6da | 849 | return rc; |
jhbr | 0:d3f5fdf2e6da | 850 | |
jhbr | 0:d3f5fdf2e6da | 851 | } |
jhbr | 0:d3f5fdf2e6da | 852 | |
jhbr | 0:d3f5fdf2e6da | 853 | void dn_ipmt_setParameter_routingMode_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 854 | dn_ipmt_setParameter_routingMode_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 855 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 856 | |
jhbr | 0:d3f5fdf2e6da | 857 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 858 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 859 | return; |
jhbr | 0:d3f5fdf2e6da | 860 | } |
jhbr | 0:d3f5fdf2e6da | 861 | |
jhbr | 0:d3f5fdf2e6da | 862 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 863 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 864 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 865 | return; |
jhbr | 0:d3f5fdf2e6da | 866 | } |
jhbr | 0:d3f5fdf2e6da | 867 | |
jhbr | 0:d3f5fdf2e6da | 868 | // verify length |
jhbr | 0:d3f5fdf2e6da | 869 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_ROUTINGMODE_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 870 | return; |
jhbr | 0:d3f5fdf2e6da | 871 | } |
jhbr | 0:d3f5fdf2e6da | 872 | |
jhbr | 0:d3f5fdf2e6da | 873 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 874 | reply = (dn_ipmt_setParameter_routingMode_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 875 | |
jhbr | 0:d3f5fdf2e6da | 876 | // store RC |
jhbr | 0:d3f5fdf2e6da | 877 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 878 | |
jhbr | 0:d3f5fdf2e6da | 879 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 880 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 881 | |
jhbr | 0:d3f5fdf2e6da | 882 | } |
jhbr | 0:d3f5fdf2e6da | 883 | |
jhbr | 0:d3f5fdf2e6da | 884 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 885 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 886 | |
jhbr | 0:d3f5fdf2e6da | 887 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 888 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 889 | } |
jhbr | 0:d3f5fdf2e6da | 890 | |
jhbr | 0:d3f5fdf2e6da | 891 | //===== setParameter_powerSrcInfo |
jhbr | 0:d3f5fdf2e6da | 892 | |
jhbr | 0:d3f5fdf2e6da | 893 | /** |
jhbr | 0:d3f5fdf2e6da | 894 | This command allows the microprocessor to configure power source information on |
jhbr | 0:d3f5fdf2e6da | 895 | the device. This setting is persistent and is used at network join time. |
jhbr | 0:d3f5fdf2e6da | 896 | */ |
jhbr | 0:d3f5fdf2e6da | 897 | dn_err_t dn_ipmt_setParameter_powerSrcInfo(uint16_t maxStCurrent, uint8_t minLifetime, uint16_t currentLimit_0, uint16_t dischargePeriod_0, uint16_t rechargePeriod_0, uint16_t currentLimit_1, uint16_t dischargePeriod_1, uint16_t rechargePeriod_1, uint16_t currentLimit_2, uint16_t dischargePeriod_2, uint16_t rechargePeriod_2, dn_ipmt_setParameter_powerSrcInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 898 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 899 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 900 | |
jhbr | 0:d3f5fdf2e6da | 901 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 902 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 903 | |
jhbr | 0:d3f5fdf2e6da | 904 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 905 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 906 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 907 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 908 | |
jhbr | 0:d3f5fdf2e6da | 909 | // return |
jhbr | 0:d3f5fdf2e6da | 910 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 911 | } |
jhbr | 0:d3f5fdf2e6da | 912 | |
jhbr | 0:d3f5fdf2e6da | 913 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 914 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 915 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 916 | dn_ipmt_vars.paramId = PARAMID_POWERSRCINFO; |
jhbr | 0:d3f5fdf2e6da | 917 | |
jhbr | 0:d3f5fdf2e6da | 918 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 919 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 920 | |
jhbr | 0:d3f5fdf2e6da | 921 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 922 | dn_ipmt_vars.outputBuf[0] = PARAMID_POWERSRCINFO; |
jhbr | 0:d3f5fdf2e6da | 923 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_MAXSTCURRENT],maxStCurrent); |
jhbr | 0:d3f5fdf2e6da | 924 | dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_MINLIFETIME] = minLifetime; |
jhbr | 0:d3f5fdf2e6da | 925 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_CURRENTLIMIT_0],currentLimit_0); |
jhbr | 0:d3f5fdf2e6da | 926 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_DISCHARGEPERIOD_0],dischargePeriod_0); |
jhbr | 0:d3f5fdf2e6da | 927 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_RECHARGEPERIOD_0],rechargePeriod_0); |
jhbr | 0:d3f5fdf2e6da | 928 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_CURRENTLIMIT_1],currentLimit_1); |
jhbr | 0:d3f5fdf2e6da | 929 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_DISCHARGEPERIOD_1],dischargePeriod_1); |
jhbr | 0:d3f5fdf2e6da | 930 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_RECHARGEPERIOD_1],rechargePeriod_1); |
jhbr | 0:d3f5fdf2e6da | 931 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_CURRENTLIMIT_2],currentLimit_2); |
jhbr | 0:d3f5fdf2e6da | 932 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_DISCHARGEPERIOD_2],dischargePeriod_2); |
jhbr | 0:d3f5fdf2e6da | 933 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_POWERSRCINFO_REQ_OFFS_RECHARGEPERIOD_2],rechargePeriod_2); |
jhbr | 0:d3f5fdf2e6da | 934 | |
jhbr | 0:d3f5fdf2e6da | 935 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 936 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 937 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 938 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 939 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 940 | DN_SETPARAMETER_POWERSRCINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 941 | dn_ipmt_setParameter_powerSrcInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 942 | ); |
jhbr | 0:d3f5fdf2e6da | 943 | |
jhbr | 0:d3f5fdf2e6da | 944 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 945 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 946 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 947 | } |
jhbr | 0:d3f5fdf2e6da | 948 | |
jhbr | 0:d3f5fdf2e6da | 949 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 950 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 951 | |
jhbr | 0:d3f5fdf2e6da | 952 | return rc; |
jhbr | 0:d3f5fdf2e6da | 953 | |
jhbr | 0:d3f5fdf2e6da | 954 | } |
jhbr | 0:d3f5fdf2e6da | 955 | |
jhbr | 0:d3f5fdf2e6da | 956 | void dn_ipmt_setParameter_powerSrcInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 957 | dn_ipmt_setParameter_powerSrcInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 958 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 959 | |
jhbr | 0:d3f5fdf2e6da | 960 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 961 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 962 | return; |
jhbr | 0:d3f5fdf2e6da | 963 | } |
jhbr | 0:d3f5fdf2e6da | 964 | |
jhbr | 0:d3f5fdf2e6da | 965 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 966 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 967 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 968 | return; |
jhbr | 0:d3f5fdf2e6da | 969 | } |
jhbr | 0:d3f5fdf2e6da | 970 | |
jhbr | 0:d3f5fdf2e6da | 971 | // verify length |
jhbr | 0:d3f5fdf2e6da | 972 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_POWERSRCINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 973 | return; |
jhbr | 0:d3f5fdf2e6da | 974 | } |
jhbr | 0:d3f5fdf2e6da | 975 | |
jhbr | 0:d3f5fdf2e6da | 976 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 977 | reply = (dn_ipmt_setParameter_powerSrcInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 978 | |
jhbr | 0:d3f5fdf2e6da | 979 | // store RC |
jhbr | 0:d3f5fdf2e6da | 980 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 981 | |
jhbr | 0:d3f5fdf2e6da | 982 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 983 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 984 | |
jhbr | 0:d3f5fdf2e6da | 985 | } |
jhbr | 0:d3f5fdf2e6da | 986 | |
jhbr | 0:d3f5fdf2e6da | 987 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 988 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 989 | |
jhbr | 0:d3f5fdf2e6da | 990 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 991 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 992 | } |
jhbr | 0:d3f5fdf2e6da | 993 | |
jhbr | 0:d3f5fdf2e6da | 994 | //===== setParameter_advKey |
jhbr | 0:d3f5fdf2e6da | 995 | |
jhbr | 0:d3f5fdf2e6da | 996 | /** |
jhbr | 0:d3f5fdf2e6da | 997 | Sets the Advertisement MIC key - this key is used to authenticate |
jhbr | 0:d3f5fdf2e6da | 998 | advertisements, and can be set per vendor/installation to prevent unauthorized |
jhbr | 0:d3f5fdf2e6da | 999 | devices from being able to respond to advertisements. If changed, it must match |
jhbr | 0:d3f5fdf2e6da | 1000 | that set on the corresponding AP (using mset on the manager CLI) in order for |
jhbr | 0:d3f5fdf2e6da | 1001 | the mote to join. It can be reset to default via the clearNV command. |
jhbr | 0:d3f5fdf2e6da | 1002 | */ |
jhbr | 0:d3f5fdf2e6da | 1003 | dn_err_t dn_ipmt_setParameter_advKey(uint8_t* advKey, dn_ipmt_setParameter_advKey_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1004 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1005 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1006 | |
jhbr | 0:d3f5fdf2e6da | 1007 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1008 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1009 | |
jhbr | 0:d3f5fdf2e6da | 1010 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1011 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1012 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1013 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1014 | |
jhbr | 0:d3f5fdf2e6da | 1015 | // return |
jhbr | 0:d3f5fdf2e6da | 1016 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1017 | } |
jhbr | 0:d3f5fdf2e6da | 1018 | |
jhbr | 0:d3f5fdf2e6da | 1019 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1020 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1021 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1022 | dn_ipmt_vars.paramId = PARAMID_ADVKEY; |
jhbr | 0:d3f5fdf2e6da | 1023 | |
jhbr | 0:d3f5fdf2e6da | 1024 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1025 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1026 | |
jhbr | 0:d3f5fdf2e6da | 1027 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1028 | dn_ipmt_vars.outputBuf[0] = PARAMID_ADVKEY; |
jhbr | 0:d3f5fdf2e6da | 1029 | memcpy(&dn_ipmt_vars.outputBuf[DN_SETPARAMETER_ADVKEY_REQ_OFFS_ADVKEY],advKey,16); |
jhbr | 0:d3f5fdf2e6da | 1030 | |
jhbr | 0:d3f5fdf2e6da | 1031 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1032 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1033 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1034 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1035 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1036 | DN_SETPARAMETER_ADVKEY_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1037 | dn_ipmt_setParameter_advKey_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1038 | ); |
jhbr | 0:d3f5fdf2e6da | 1039 | |
jhbr | 0:d3f5fdf2e6da | 1040 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1041 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1042 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1043 | } |
jhbr | 0:d3f5fdf2e6da | 1044 | |
jhbr | 0:d3f5fdf2e6da | 1045 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1046 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1047 | |
jhbr | 0:d3f5fdf2e6da | 1048 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1049 | |
jhbr | 0:d3f5fdf2e6da | 1050 | } |
jhbr | 0:d3f5fdf2e6da | 1051 | |
jhbr | 0:d3f5fdf2e6da | 1052 | void dn_ipmt_setParameter_advKey_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1053 | dn_ipmt_setParameter_advKey_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1054 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1055 | |
jhbr | 0:d3f5fdf2e6da | 1056 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1057 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1058 | return; |
jhbr | 0:d3f5fdf2e6da | 1059 | } |
jhbr | 0:d3f5fdf2e6da | 1060 | |
jhbr | 0:d3f5fdf2e6da | 1061 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1062 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1063 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1064 | return; |
jhbr | 0:d3f5fdf2e6da | 1065 | } |
jhbr | 0:d3f5fdf2e6da | 1066 | |
jhbr | 0:d3f5fdf2e6da | 1067 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1068 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_ADVKEY_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1069 | return; |
jhbr | 0:d3f5fdf2e6da | 1070 | } |
jhbr | 0:d3f5fdf2e6da | 1071 | |
jhbr | 0:d3f5fdf2e6da | 1072 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1073 | reply = (dn_ipmt_setParameter_advKey_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1074 | |
jhbr | 0:d3f5fdf2e6da | 1075 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1076 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1077 | |
jhbr | 0:d3f5fdf2e6da | 1078 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1079 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1080 | |
jhbr | 0:d3f5fdf2e6da | 1081 | } |
jhbr | 0:d3f5fdf2e6da | 1082 | |
jhbr | 0:d3f5fdf2e6da | 1083 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1084 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1085 | |
jhbr | 0:d3f5fdf2e6da | 1086 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1087 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1088 | } |
jhbr | 0:d3f5fdf2e6da | 1089 | |
jhbr | 0:d3f5fdf2e6da | 1090 | //===== setParameter_autoJoin |
jhbr | 0:d3f5fdf2e6da | 1091 | |
jhbr | 0:d3f5fdf2e6da | 1092 | /** |
jhbr | 0:d3f5fdf2e6da | 1093 | This command allows the microprocessor to change between automatic and manual |
jhbr | 0:d3f5fdf2e6da | 1094 | joining by the mote's networking stack. In manual mode, an explicit join |
jhbr | 0:d3f5fdf2e6da | 1095 | command from the application is required to initiate joining. This setting is |
jhbr | 0:d3f5fdf2e6da | 1096 | persistent and takes effect after mote reset. |
jhbr | 0:d3f5fdf2e6da | 1097 | |
jhbr | 0:d3f5fdf2e6da | 1098 | Note that auto join mode must not be set if the application is also configured |
jhbr | 0:d3f5fdf2e6da | 1099 | to join (e.g combining 'auto join' with 'master' mode will result in mote not |
jhbr | 0:d3f5fdf2e6da | 1100 | joining). |
jhbr | 0:d3f5fdf2e6da | 1101 | */ |
jhbr | 0:d3f5fdf2e6da | 1102 | dn_err_t dn_ipmt_setParameter_autoJoin(bool mode, dn_ipmt_setParameter_autoJoin_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1103 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1104 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1105 | |
jhbr | 0:d3f5fdf2e6da | 1106 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1107 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1108 | |
jhbr | 0:d3f5fdf2e6da | 1109 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1110 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1111 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1112 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1113 | |
jhbr | 0:d3f5fdf2e6da | 1114 | // return |
jhbr | 0:d3f5fdf2e6da | 1115 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1116 | } |
jhbr | 0:d3f5fdf2e6da | 1117 | |
jhbr | 0:d3f5fdf2e6da | 1118 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1119 | dn_ipmt_vars.cmdId = CMDID_SETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1120 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1121 | dn_ipmt_vars.paramId = PARAMID_AUTOJOIN; |
jhbr | 0:d3f5fdf2e6da | 1122 | |
jhbr | 0:d3f5fdf2e6da | 1123 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1124 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1125 | |
jhbr | 0:d3f5fdf2e6da | 1126 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1127 | dn_ipmt_vars.outputBuf[0] = PARAMID_AUTOJOIN; |
jhbr | 0:d3f5fdf2e6da | 1128 | dn_ipmt_vars.outputBuf[DN_SETPARAMETER_AUTOJOIN_REQ_OFFS_MODE] = mode; |
jhbr | 0:d3f5fdf2e6da | 1129 | |
jhbr | 0:d3f5fdf2e6da | 1130 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1131 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1132 | CMDID_SETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1133 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1134 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1135 | DN_SETPARAMETER_AUTOJOIN_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1136 | dn_ipmt_setParameter_autoJoin_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1137 | ); |
jhbr | 0:d3f5fdf2e6da | 1138 | |
jhbr | 0:d3f5fdf2e6da | 1139 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1140 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1141 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1142 | } |
jhbr | 0:d3f5fdf2e6da | 1143 | |
jhbr | 0:d3f5fdf2e6da | 1144 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1145 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1146 | |
jhbr | 0:d3f5fdf2e6da | 1147 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1148 | |
jhbr | 0:d3f5fdf2e6da | 1149 | } |
jhbr | 0:d3f5fdf2e6da | 1150 | |
jhbr | 0:d3f5fdf2e6da | 1151 | void dn_ipmt_setParameter_autoJoin_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1152 | dn_ipmt_setParameter_autoJoin_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1153 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1154 | |
jhbr | 0:d3f5fdf2e6da | 1155 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1156 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1157 | return; |
jhbr | 0:d3f5fdf2e6da | 1158 | } |
jhbr | 0:d3f5fdf2e6da | 1159 | |
jhbr | 0:d3f5fdf2e6da | 1160 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1161 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1162 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1163 | return; |
jhbr | 0:d3f5fdf2e6da | 1164 | } |
jhbr | 0:d3f5fdf2e6da | 1165 | |
jhbr | 0:d3f5fdf2e6da | 1166 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1167 | if (rc==DN_SERIAL_RC_OK && len<DN_SETPARAMETER_AUTOJOIN_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1168 | return; |
jhbr | 0:d3f5fdf2e6da | 1169 | } |
jhbr | 0:d3f5fdf2e6da | 1170 | |
jhbr | 0:d3f5fdf2e6da | 1171 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1172 | reply = (dn_ipmt_setParameter_autoJoin_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1173 | |
jhbr | 0:d3f5fdf2e6da | 1174 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1175 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1176 | |
jhbr | 0:d3f5fdf2e6da | 1177 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1178 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1179 | |
jhbr | 0:d3f5fdf2e6da | 1180 | } |
jhbr | 0:d3f5fdf2e6da | 1181 | |
jhbr | 0:d3f5fdf2e6da | 1182 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1183 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1184 | |
jhbr | 0:d3f5fdf2e6da | 1185 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1186 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1187 | } |
jhbr | 0:d3f5fdf2e6da | 1188 | |
jhbr | 0:d3f5fdf2e6da | 1189 | //===== getParameter_macAddress |
jhbr | 0:d3f5fdf2e6da | 1190 | |
jhbr | 0:d3f5fdf2e6da | 1191 | /** |
jhbr | 0:d3f5fdf2e6da | 1192 | This command returns the MAC address of the device. By default, the MAC address |
jhbr | 0:d3f5fdf2e6da | 1193 | returned is the EUI64 address of the device assigned by mote manufacturer, but |
jhbr | 0:d3f5fdf2e6da | 1194 | it may be overwritten using the setParameter<macAddress> command. |
jhbr | 0:d3f5fdf2e6da | 1195 | */ |
jhbr | 0:d3f5fdf2e6da | 1196 | dn_err_t dn_ipmt_getParameter_macAddress(dn_ipmt_getParameter_macAddress_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1197 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1198 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1199 | |
jhbr | 0:d3f5fdf2e6da | 1200 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1201 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1202 | |
jhbr | 0:d3f5fdf2e6da | 1203 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1204 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1205 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1206 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1207 | |
jhbr | 0:d3f5fdf2e6da | 1208 | // return |
jhbr | 0:d3f5fdf2e6da | 1209 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1210 | } |
jhbr | 0:d3f5fdf2e6da | 1211 | |
jhbr | 0:d3f5fdf2e6da | 1212 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1213 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1214 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1215 | dn_ipmt_vars.paramId = PARAMID_MACADDRESS; |
jhbr | 0:d3f5fdf2e6da | 1216 | |
jhbr | 0:d3f5fdf2e6da | 1217 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1218 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1219 | |
jhbr | 0:d3f5fdf2e6da | 1220 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1221 | dn_ipmt_vars.outputBuf[0] = PARAMID_MACADDRESS; |
jhbr | 0:d3f5fdf2e6da | 1222 | |
jhbr | 0:d3f5fdf2e6da | 1223 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1224 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1225 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1226 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1227 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1228 | DN_GETPARAMETER_MACADDRESS_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1229 | dn_ipmt_getParameter_macAddress_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1230 | ); |
jhbr | 0:d3f5fdf2e6da | 1231 | |
jhbr | 0:d3f5fdf2e6da | 1232 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1233 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1234 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1235 | } |
jhbr | 0:d3f5fdf2e6da | 1236 | |
jhbr | 0:d3f5fdf2e6da | 1237 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1238 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1239 | |
jhbr | 0:d3f5fdf2e6da | 1240 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1241 | |
jhbr | 0:d3f5fdf2e6da | 1242 | } |
jhbr | 0:d3f5fdf2e6da | 1243 | |
jhbr | 0:d3f5fdf2e6da | 1244 | void dn_ipmt_getParameter_macAddress_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1245 | dn_ipmt_getParameter_macAddress_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1246 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1247 | |
jhbr | 0:d3f5fdf2e6da | 1248 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1249 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1250 | return; |
jhbr | 0:d3f5fdf2e6da | 1251 | } |
jhbr | 0:d3f5fdf2e6da | 1252 | |
jhbr | 0:d3f5fdf2e6da | 1253 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1254 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1255 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1256 | return; |
jhbr | 0:d3f5fdf2e6da | 1257 | } |
jhbr | 0:d3f5fdf2e6da | 1258 | |
jhbr | 0:d3f5fdf2e6da | 1259 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1260 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_MACADDRESS_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1261 | return; |
jhbr | 0:d3f5fdf2e6da | 1262 | } |
jhbr | 0:d3f5fdf2e6da | 1263 | |
jhbr | 0:d3f5fdf2e6da | 1264 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1265 | reply = (dn_ipmt_getParameter_macAddress_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1266 | |
jhbr | 0:d3f5fdf2e6da | 1267 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1268 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1269 | |
jhbr | 0:d3f5fdf2e6da | 1270 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1271 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1272 | |
jhbr | 0:d3f5fdf2e6da | 1273 | memcpy(&reply->macAddress[0],&payload[DN_GETPARAMETER_MACADDRESS_REPLY_OFFS_MACADDRESS],8); |
jhbr | 0:d3f5fdf2e6da | 1274 | } |
jhbr | 0:d3f5fdf2e6da | 1275 | |
jhbr | 0:d3f5fdf2e6da | 1276 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1277 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1278 | |
jhbr | 0:d3f5fdf2e6da | 1279 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1280 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1281 | } |
jhbr | 0:d3f5fdf2e6da | 1282 | |
jhbr | 0:d3f5fdf2e6da | 1283 | //===== getParameter_networkId |
jhbr | 0:d3f5fdf2e6da | 1284 | |
jhbr | 0:d3f5fdf2e6da | 1285 | /** |
jhbr | 0:d3f5fdf2e6da | 1286 | This command returns the network id stored in mote's persistent storage. |
jhbr | 0:d3f5fdf2e6da | 1287 | */ |
jhbr | 0:d3f5fdf2e6da | 1288 | dn_err_t dn_ipmt_getParameter_networkId(dn_ipmt_getParameter_networkId_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1289 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1290 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1291 | |
jhbr | 0:d3f5fdf2e6da | 1292 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1293 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1294 | |
jhbr | 0:d3f5fdf2e6da | 1295 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1296 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1297 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1298 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1299 | |
jhbr | 0:d3f5fdf2e6da | 1300 | // return |
jhbr | 0:d3f5fdf2e6da | 1301 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1302 | } |
jhbr | 0:d3f5fdf2e6da | 1303 | |
jhbr | 0:d3f5fdf2e6da | 1304 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1305 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1306 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1307 | dn_ipmt_vars.paramId = PARAMID_NETWORKID; |
jhbr | 0:d3f5fdf2e6da | 1308 | |
jhbr | 0:d3f5fdf2e6da | 1309 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1310 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1311 | |
jhbr | 0:d3f5fdf2e6da | 1312 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1313 | dn_ipmt_vars.outputBuf[0] = PARAMID_NETWORKID; |
jhbr | 0:d3f5fdf2e6da | 1314 | |
jhbr | 0:d3f5fdf2e6da | 1315 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1316 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1317 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1318 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1319 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1320 | DN_GETPARAMETER_NETWORKID_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1321 | dn_ipmt_getParameter_networkId_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1322 | ); |
jhbr | 0:d3f5fdf2e6da | 1323 | |
jhbr | 0:d3f5fdf2e6da | 1324 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1325 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1326 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1327 | } |
jhbr | 0:d3f5fdf2e6da | 1328 | |
jhbr | 0:d3f5fdf2e6da | 1329 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1330 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1331 | |
jhbr | 0:d3f5fdf2e6da | 1332 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1333 | |
jhbr | 0:d3f5fdf2e6da | 1334 | } |
jhbr | 0:d3f5fdf2e6da | 1335 | |
jhbr | 0:d3f5fdf2e6da | 1336 | void dn_ipmt_getParameter_networkId_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1337 | dn_ipmt_getParameter_networkId_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1338 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1339 | |
jhbr | 0:d3f5fdf2e6da | 1340 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1341 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1342 | return; |
jhbr | 0:d3f5fdf2e6da | 1343 | } |
jhbr | 0:d3f5fdf2e6da | 1344 | |
jhbr | 0:d3f5fdf2e6da | 1345 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1346 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1347 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1348 | return; |
jhbr | 0:d3f5fdf2e6da | 1349 | } |
jhbr | 0:d3f5fdf2e6da | 1350 | |
jhbr | 0:d3f5fdf2e6da | 1351 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1352 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_NETWORKID_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1353 | return; |
jhbr | 0:d3f5fdf2e6da | 1354 | } |
jhbr | 0:d3f5fdf2e6da | 1355 | |
jhbr | 0:d3f5fdf2e6da | 1356 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1357 | reply = (dn_ipmt_getParameter_networkId_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1358 | |
jhbr | 0:d3f5fdf2e6da | 1359 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1360 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1361 | |
jhbr | 0:d3f5fdf2e6da | 1362 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1363 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1364 | |
jhbr | 0:d3f5fdf2e6da | 1365 | dn_read_uint16_t(&reply->networkId,&payload[DN_GETPARAMETER_NETWORKID_REPLY_OFFS_NETWORKID]); |
jhbr | 0:d3f5fdf2e6da | 1366 | } |
jhbr | 0:d3f5fdf2e6da | 1367 | |
jhbr | 0:d3f5fdf2e6da | 1368 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1369 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1370 | |
jhbr | 0:d3f5fdf2e6da | 1371 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1372 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1373 | } |
jhbr | 0:d3f5fdf2e6da | 1374 | |
jhbr | 0:d3f5fdf2e6da | 1375 | //===== getParameter_txPower |
jhbr | 0:d3f5fdf2e6da | 1376 | |
jhbr | 0:d3f5fdf2e6da | 1377 | /** |
jhbr | 0:d3f5fdf2e6da | 1378 | Get the radio output power in dBm, excluding any antenna gain. |
jhbr | 0:d3f5fdf2e6da | 1379 | */ |
jhbr | 0:d3f5fdf2e6da | 1380 | dn_err_t dn_ipmt_getParameter_txPower(dn_ipmt_getParameter_txPower_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1381 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1382 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1383 | |
jhbr | 0:d3f5fdf2e6da | 1384 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1385 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1386 | |
jhbr | 0:d3f5fdf2e6da | 1387 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1388 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1389 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1390 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1391 | |
jhbr | 0:d3f5fdf2e6da | 1392 | // return |
jhbr | 0:d3f5fdf2e6da | 1393 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1394 | } |
jhbr | 0:d3f5fdf2e6da | 1395 | |
jhbr | 0:d3f5fdf2e6da | 1396 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1397 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1398 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1399 | dn_ipmt_vars.paramId = PARAMID_TXPOWER; |
jhbr | 0:d3f5fdf2e6da | 1400 | |
jhbr | 0:d3f5fdf2e6da | 1401 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1402 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1403 | |
jhbr | 0:d3f5fdf2e6da | 1404 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1405 | dn_ipmt_vars.outputBuf[0] = PARAMID_TXPOWER; |
jhbr | 0:d3f5fdf2e6da | 1406 | |
jhbr | 0:d3f5fdf2e6da | 1407 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1408 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1409 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1410 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1411 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1412 | DN_GETPARAMETER_TXPOWER_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1413 | dn_ipmt_getParameter_txPower_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1414 | ); |
jhbr | 0:d3f5fdf2e6da | 1415 | |
jhbr | 0:d3f5fdf2e6da | 1416 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1417 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1418 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1419 | } |
jhbr | 0:d3f5fdf2e6da | 1420 | |
jhbr | 0:d3f5fdf2e6da | 1421 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1422 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1423 | |
jhbr | 0:d3f5fdf2e6da | 1424 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1425 | |
jhbr | 0:d3f5fdf2e6da | 1426 | } |
jhbr | 0:d3f5fdf2e6da | 1427 | |
jhbr | 0:d3f5fdf2e6da | 1428 | void dn_ipmt_getParameter_txPower_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1429 | dn_ipmt_getParameter_txPower_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1430 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1431 | |
jhbr | 0:d3f5fdf2e6da | 1432 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1433 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1434 | return; |
jhbr | 0:d3f5fdf2e6da | 1435 | } |
jhbr | 0:d3f5fdf2e6da | 1436 | |
jhbr | 0:d3f5fdf2e6da | 1437 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1438 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1439 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1440 | return; |
jhbr | 0:d3f5fdf2e6da | 1441 | } |
jhbr | 0:d3f5fdf2e6da | 1442 | |
jhbr | 0:d3f5fdf2e6da | 1443 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1444 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_TXPOWER_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1445 | return; |
jhbr | 0:d3f5fdf2e6da | 1446 | } |
jhbr | 0:d3f5fdf2e6da | 1447 | |
jhbr | 0:d3f5fdf2e6da | 1448 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1449 | reply = (dn_ipmt_getParameter_txPower_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1450 | |
jhbr | 0:d3f5fdf2e6da | 1451 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1452 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1453 | |
jhbr | 0:d3f5fdf2e6da | 1454 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1455 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1456 | |
jhbr | 0:d3f5fdf2e6da | 1457 | reply->txPower = (int8_t)payload[DN_GETPARAMETER_TXPOWER_REPLY_OFFS_TXPOWER]; |
jhbr | 0:d3f5fdf2e6da | 1458 | } |
jhbr | 0:d3f5fdf2e6da | 1459 | |
jhbr | 0:d3f5fdf2e6da | 1460 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1461 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1462 | |
jhbr | 0:d3f5fdf2e6da | 1463 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1464 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1465 | } |
jhbr | 0:d3f5fdf2e6da | 1466 | |
jhbr | 0:d3f5fdf2e6da | 1467 | //===== getParameter_joinDutyCycle |
jhbr | 0:d3f5fdf2e6da | 1468 | |
jhbr | 0:d3f5fdf2e6da | 1469 | /** |
jhbr | 0:d3f5fdf2e6da | 1470 | This command allows user to retrieve current value of joinDutyCycle parameter. |
jhbr | 0:d3f5fdf2e6da | 1471 | */ |
jhbr | 0:d3f5fdf2e6da | 1472 | dn_err_t dn_ipmt_getParameter_joinDutyCycle(dn_ipmt_getParameter_joinDutyCycle_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1473 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1474 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1475 | |
jhbr | 0:d3f5fdf2e6da | 1476 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1477 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1478 | |
jhbr | 0:d3f5fdf2e6da | 1479 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1480 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1481 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1482 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1483 | |
jhbr | 0:d3f5fdf2e6da | 1484 | // return |
jhbr | 0:d3f5fdf2e6da | 1485 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1486 | } |
jhbr | 0:d3f5fdf2e6da | 1487 | |
jhbr | 0:d3f5fdf2e6da | 1488 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1489 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1490 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1491 | dn_ipmt_vars.paramId = PARAMID_JOINDUTYCYCLE; |
jhbr | 0:d3f5fdf2e6da | 1492 | |
jhbr | 0:d3f5fdf2e6da | 1493 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1494 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1495 | |
jhbr | 0:d3f5fdf2e6da | 1496 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1497 | dn_ipmt_vars.outputBuf[0] = PARAMID_JOINDUTYCYCLE; |
jhbr | 0:d3f5fdf2e6da | 1498 | |
jhbr | 0:d3f5fdf2e6da | 1499 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1500 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1501 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1502 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1503 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1504 | DN_GETPARAMETER_JOINDUTYCYCLE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1505 | dn_ipmt_getParameter_joinDutyCycle_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1506 | ); |
jhbr | 0:d3f5fdf2e6da | 1507 | |
jhbr | 0:d3f5fdf2e6da | 1508 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1509 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1510 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1511 | } |
jhbr | 0:d3f5fdf2e6da | 1512 | |
jhbr | 0:d3f5fdf2e6da | 1513 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1514 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1515 | |
jhbr | 0:d3f5fdf2e6da | 1516 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1517 | |
jhbr | 0:d3f5fdf2e6da | 1518 | } |
jhbr | 0:d3f5fdf2e6da | 1519 | |
jhbr | 0:d3f5fdf2e6da | 1520 | void dn_ipmt_getParameter_joinDutyCycle_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1521 | dn_ipmt_getParameter_joinDutyCycle_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1522 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1523 | |
jhbr | 0:d3f5fdf2e6da | 1524 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1525 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1526 | return; |
jhbr | 0:d3f5fdf2e6da | 1527 | } |
jhbr | 0:d3f5fdf2e6da | 1528 | |
jhbr | 0:d3f5fdf2e6da | 1529 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1530 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1531 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1532 | return; |
jhbr | 0:d3f5fdf2e6da | 1533 | } |
jhbr | 0:d3f5fdf2e6da | 1534 | |
jhbr | 0:d3f5fdf2e6da | 1535 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1536 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_JOINDUTYCYCLE_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1537 | return; |
jhbr | 0:d3f5fdf2e6da | 1538 | } |
jhbr | 0:d3f5fdf2e6da | 1539 | |
jhbr | 0:d3f5fdf2e6da | 1540 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1541 | reply = (dn_ipmt_getParameter_joinDutyCycle_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1542 | |
jhbr | 0:d3f5fdf2e6da | 1543 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1544 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1545 | |
jhbr | 0:d3f5fdf2e6da | 1546 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1547 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1548 | |
jhbr | 0:d3f5fdf2e6da | 1549 | reply->joinDutyCycle = payload[DN_GETPARAMETER_JOINDUTYCYCLE_REPLY_OFFS_JOINDUTYCYCLE]; |
jhbr | 0:d3f5fdf2e6da | 1550 | } |
jhbr | 0:d3f5fdf2e6da | 1551 | |
jhbr | 0:d3f5fdf2e6da | 1552 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1553 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1554 | |
jhbr | 0:d3f5fdf2e6da | 1555 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1556 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1557 | } |
jhbr | 0:d3f5fdf2e6da | 1558 | |
jhbr | 0:d3f5fdf2e6da | 1559 | //===== getParameter_eventMask |
jhbr | 0:d3f5fdf2e6da | 1560 | |
jhbr | 0:d3f5fdf2e6da | 1561 | /** |
jhbr | 0:d3f5fdf2e6da | 1562 | getParameter<eventMask> allows the microprocessor to read the currently |
jhbr | 0:d3f5fdf2e6da | 1563 | subscribed-to event types. |
jhbr | 0:d3f5fdf2e6da | 1564 | */ |
jhbr | 0:d3f5fdf2e6da | 1565 | dn_err_t dn_ipmt_getParameter_eventMask(dn_ipmt_getParameter_eventMask_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1566 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1567 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1568 | |
jhbr | 0:d3f5fdf2e6da | 1569 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1570 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1571 | |
jhbr | 0:d3f5fdf2e6da | 1572 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1573 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1574 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1575 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1576 | |
jhbr | 0:d3f5fdf2e6da | 1577 | // return |
jhbr | 0:d3f5fdf2e6da | 1578 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1579 | } |
jhbr | 0:d3f5fdf2e6da | 1580 | |
jhbr | 0:d3f5fdf2e6da | 1581 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1582 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1583 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1584 | dn_ipmt_vars.paramId = PARAMID_EVENTMASK; |
jhbr | 0:d3f5fdf2e6da | 1585 | |
jhbr | 0:d3f5fdf2e6da | 1586 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1587 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1588 | |
jhbr | 0:d3f5fdf2e6da | 1589 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1590 | dn_ipmt_vars.outputBuf[0] = PARAMID_EVENTMASK; |
jhbr | 0:d3f5fdf2e6da | 1591 | |
jhbr | 0:d3f5fdf2e6da | 1592 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1593 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1594 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1595 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1596 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1597 | DN_GETPARAMETER_EVENTMASK_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1598 | dn_ipmt_getParameter_eventMask_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1599 | ); |
jhbr | 0:d3f5fdf2e6da | 1600 | |
jhbr | 0:d3f5fdf2e6da | 1601 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1602 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1603 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1604 | } |
jhbr | 0:d3f5fdf2e6da | 1605 | |
jhbr | 0:d3f5fdf2e6da | 1606 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1607 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1608 | |
jhbr | 0:d3f5fdf2e6da | 1609 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1610 | |
jhbr | 0:d3f5fdf2e6da | 1611 | } |
jhbr | 0:d3f5fdf2e6da | 1612 | |
jhbr | 0:d3f5fdf2e6da | 1613 | void dn_ipmt_getParameter_eventMask_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1614 | dn_ipmt_getParameter_eventMask_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1615 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1616 | |
jhbr | 0:d3f5fdf2e6da | 1617 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1618 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1619 | return; |
jhbr | 0:d3f5fdf2e6da | 1620 | } |
jhbr | 0:d3f5fdf2e6da | 1621 | |
jhbr | 0:d3f5fdf2e6da | 1622 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1623 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1624 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1625 | return; |
jhbr | 0:d3f5fdf2e6da | 1626 | } |
jhbr | 0:d3f5fdf2e6da | 1627 | |
jhbr | 0:d3f5fdf2e6da | 1628 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1629 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_EVENTMASK_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1630 | return; |
jhbr | 0:d3f5fdf2e6da | 1631 | } |
jhbr | 0:d3f5fdf2e6da | 1632 | |
jhbr | 0:d3f5fdf2e6da | 1633 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1634 | reply = (dn_ipmt_getParameter_eventMask_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1635 | |
jhbr | 0:d3f5fdf2e6da | 1636 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1637 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1638 | |
jhbr | 0:d3f5fdf2e6da | 1639 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1640 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1641 | |
jhbr | 0:d3f5fdf2e6da | 1642 | dn_read_uint32_t(&reply->eventMask,&payload[DN_GETPARAMETER_EVENTMASK_REPLY_OFFS_EVENTMASK]); |
jhbr | 0:d3f5fdf2e6da | 1643 | } |
jhbr | 0:d3f5fdf2e6da | 1644 | |
jhbr | 0:d3f5fdf2e6da | 1645 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1646 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1647 | |
jhbr | 0:d3f5fdf2e6da | 1648 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1649 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1650 | } |
jhbr | 0:d3f5fdf2e6da | 1651 | |
jhbr | 0:d3f5fdf2e6da | 1652 | //===== getParameter_moteInfo |
jhbr | 0:d3f5fdf2e6da | 1653 | |
jhbr | 0:d3f5fdf2e6da | 1654 | /** |
jhbr | 0:d3f5fdf2e6da | 1655 | The getParameter<moteInfo> command returns static information about the |
jhbr | 0:d3f5fdf2e6da | 1656 | moteshardware and network stack software. |
jhbr | 0:d3f5fdf2e6da | 1657 | */ |
jhbr | 0:d3f5fdf2e6da | 1658 | dn_err_t dn_ipmt_getParameter_moteInfo(dn_ipmt_getParameter_moteInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1659 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1660 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1661 | |
jhbr | 0:d3f5fdf2e6da | 1662 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1663 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1664 | |
jhbr | 0:d3f5fdf2e6da | 1665 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1666 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1667 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1668 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1669 | |
jhbr | 0:d3f5fdf2e6da | 1670 | // return |
jhbr | 0:d3f5fdf2e6da | 1671 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1672 | } |
jhbr | 0:d3f5fdf2e6da | 1673 | |
jhbr | 0:d3f5fdf2e6da | 1674 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1675 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1676 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1677 | dn_ipmt_vars.paramId = PARAMID_MOTEINFO; |
jhbr | 0:d3f5fdf2e6da | 1678 | |
jhbr | 0:d3f5fdf2e6da | 1679 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1680 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1681 | |
jhbr | 0:d3f5fdf2e6da | 1682 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1683 | dn_ipmt_vars.outputBuf[0] = PARAMID_MOTEINFO; |
jhbr | 0:d3f5fdf2e6da | 1684 | |
jhbr | 0:d3f5fdf2e6da | 1685 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1686 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1687 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1688 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1689 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1690 | DN_GETPARAMETER_MOTEINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1691 | dn_ipmt_getParameter_moteInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1692 | ); |
jhbr | 0:d3f5fdf2e6da | 1693 | |
jhbr | 0:d3f5fdf2e6da | 1694 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1695 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1696 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1697 | } |
jhbr | 0:d3f5fdf2e6da | 1698 | |
jhbr | 0:d3f5fdf2e6da | 1699 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1700 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1701 | |
jhbr | 0:d3f5fdf2e6da | 1702 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1703 | |
jhbr | 0:d3f5fdf2e6da | 1704 | } |
jhbr | 0:d3f5fdf2e6da | 1705 | |
jhbr | 0:d3f5fdf2e6da | 1706 | void dn_ipmt_getParameter_moteInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1707 | dn_ipmt_getParameter_moteInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1708 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1709 | |
jhbr | 0:d3f5fdf2e6da | 1710 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1711 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1712 | return; |
jhbr | 0:d3f5fdf2e6da | 1713 | } |
jhbr | 0:d3f5fdf2e6da | 1714 | |
jhbr | 0:d3f5fdf2e6da | 1715 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1716 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1717 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1718 | return; |
jhbr | 0:d3f5fdf2e6da | 1719 | } |
jhbr | 0:d3f5fdf2e6da | 1720 | |
jhbr | 0:d3f5fdf2e6da | 1721 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1722 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_MOTEINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1723 | return; |
jhbr | 0:d3f5fdf2e6da | 1724 | } |
jhbr | 0:d3f5fdf2e6da | 1725 | |
jhbr | 0:d3f5fdf2e6da | 1726 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1727 | reply = (dn_ipmt_getParameter_moteInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1728 | |
jhbr | 0:d3f5fdf2e6da | 1729 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1730 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1731 | |
jhbr | 0:d3f5fdf2e6da | 1732 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1733 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1734 | |
jhbr | 0:d3f5fdf2e6da | 1735 | reply->apiVersion = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_APIVERSION]; |
jhbr | 0:d3f5fdf2e6da | 1736 | memcpy(&reply->serialNumber[0],&payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_SERIALNUMBER],8); |
jhbr | 0:d3f5fdf2e6da | 1737 | reply->hwModel = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_HWMODEL]; |
jhbr | 0:d3f5fdf2e6da | 1738 | reply->hwRev = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_HWREV]; |
jhbr | 0:d3f5fdf2e6da | 1739 | reply->swVerMajor = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_SWVERMAJOR]; |
jhbr | 0:d3f5fdf2e6da | 1740 | reply->swVerMinor = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_SWVERMINOR]; |
jhbr | 0:d3f5fdf2e6da | 1741 | reply->swVerPatch = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_SWVERPATCH]; |
jhbr | 0:d3f5fdf2e6da | 1742 | dn_read_uint16_t(&reply->swVerBuild,&payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_SWVERBUILD]); |
jhbr | 0:d3f5fdf2e6da | 1743 | reply->bootSwVer = payload[DN_GETPARAMETER_MOTEINFO_REPLY_OFFS_BOOTSWVER]; |
jhbr | 0:d3f5fdf2e6da | 1744 | } |
jhbr | 0:d3f5fdf2e6da | 1745 | |
jhbr | 0:d3f5fdf2e6da | 1746 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1747 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1748 | |
jhbr | 0:d3f5fdf2e6da | 1749 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1750 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1751 | } |
jhbr | 0:d3f5fdf2e6da | 1752 | |
jhbr | 0:d3f5fdf2e6da | 1753 | //===== getParameter_netInfo |
jhbr | 0:d3f5fdf2e6da | 1754 | |
jhbr | 0:d3f5fdf2e6da | 1755 | /** |
jhbr | 0:d3f5fdf2e6da | 1756 | The getParameter<networkInfo> command may be used to retrieve the mote's |
jhbr | 0:d3f5fdf2e6da | 1757 | network-related parameters. |
jhbr | 0:d3f5fdf2e6da | 1758 | */ |
jhbr | 0:d3f5fdf2e6da | 1759 | dn_err_t dn_ipmt_getParameter_netInfo(dn_ipmt_getParameter_netInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1760 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1761 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1762 | |
jhbr | 0:d3f5fdf2e6da | 1763 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1764 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1765 | |
jhbr | 0:d3f5fdf2e6da | 1766 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1767 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1768 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1769 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1770 | |
jhbr | 0:d3f5fdf2e6da | 1771 | // return |
jhbr | 0:d3f5fdf2e6da | 1772 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1773 | } |
jhbr | 0:d3f5fdf2e6da | 1774 | |
jhbr | 0:d3f5fdf2e6da | 1775 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1776 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1777 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1778 | dn_ipmt_vars.paramId = PARAMID_NETINFO; |
jhbr | 0:d3f5fdf2e6da | 1779 | |
jhbr | 0:d3f5fdf2e6da | 1780 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1781 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1782 | |
jhbr | 0:d3f5fdf2e6da | 1783 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1784 | dn_ipmt_vars.outputBuf[0] = PARAMID_NETINFO; |
jhbr | 0:d3f5fdf2e6da | 1785 | |
jhbr | 0:d3f5fdf2e6da | 1786 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1787 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1788 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1789 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1790 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1791 | DN_GETPARAMETER_NETINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1792 | dn_ipmt_getParameter_netInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1793 | ); |
jhbr | 0:d3f5fdf2e6da | 1794 | |
jhbr | 0:d3f5fdf2e6da | 1795 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1796 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1797 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1798 | } |
jhbr | 0:d3f5fdf2e6da | 1799 | |
jhbr | 0:d3f5fdf2e6da | 1800 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1801 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1802 | |
jhbr | 0:d3f5fdf2e6da | 1803 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1804 | |
jhbr | 0:d3f5fdf2e6da | 1805 | } |
jhbr | 0:d3f5fdf2e6da | 1806 | |
jhbr | 0:d3f5fdf2e6da | 1807 | void dn_ipmt_getParameter_netInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1808 | dn_ipmt_getParameter_netInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1809 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1810 | |
jhbr | 0:d3f5fdf2e6da | 1811 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1812 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1813 | return; |
jhbr | 0:d3f5fdf2e6da | 1814 | } |
jhbr | 0:d3f5fdf2e6da | 1815 | |
jhbr | 0:d3f5fdf2e6da | 1816 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1817 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1818 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1819 | return; |
jhbr | 0:d3f5fdf2e6da | 1820 | } |
jhbr | 0:d3f5fdf2e6da | 1821 | |
jhbr | 0:d3f5fdf2e6da | 1822 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1823 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_NETINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1824 | return; |
jhbr | 0:d3f5fdf2e6da | 1825 | } |
jhbr | 0:d3f5fdf2e6da | 1826 | |
jhbr | 0:d3f5fdf2e6da | 1827 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1828 | reply = (dn_ipmt_getParameter_netInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1829 | |
jhbr | 0:d3f5fdf2e6da | 1830 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1831 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1832 | |
jhbr | 0:d3f5fdf2e6da | 1833 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1834 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1835 | |
jhbr | 0:d3f5fdf2e6da | 1836 | memcpy(&reply->macAddress[0],&payload[DN_GETPARAMETER_NETINFO_REPLY_OFFS_MACADDRESS],8); |
jhbr | 0:d3f5fdf2e6da | 1837 | dn_read_uint16_t(&reply->moteId,&payload[DN_GETPARAMETER_NETINFO_REPLY_OFFS_MOTEID]); |
jhbr | 0:d3f5fdf2e6da | 1838 | dn_read_uint16_t(&reply->networkId,&payload[DN_GETPARAMETER_NETINFO_REPLY_OFFS_NETWORKID]); |
jhbr | 0:d3f5fdf2e6da | 1839 | dn_read_uint16_t(&reply->slotSize,&payload[DN_GETPARAMETER_NETINFO_REPLY_OFFS_SLOTSIZE]); |
jhbr | 0:d3f5fdf2e6da | 1840 | } |
jhbr | 0:d3f5fdf2e6da | 1841 | |
jhbr | 0:d3f5fdf2e6da | 1842 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1843 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1844 | |
jhbr | 0:d3f5fdf2e6da | 1845 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1846 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1847 | } |
jhbr | 0:d3f5fdf2e6da | 1848 | |
jhbr | 0:d3f5fdf2e6da | 1849 | //===== getParameter_moteStatus |
jhbr | 0:d3f5fdf2e6da | 1850 | |
jhbr | 0:d3f5fdf2e6da | 1851 | /** |
jhbr | 0:d3f5fdf2e6da | 1852 | The getParameter<moteStatus> command is used to retrieve current mote state |
jhbr | 0:d3f5fdf2e6da | 1853 | andother dynamic information. |
jhbr | 0:d3f5fdf2e6da | 1854 | */ |
jhbr | 0:d3f5fdf2e6da | 1855 | dn_err_t dn_ipmt_getParameter_moteStatus(dn_ipmt_getParameter_moteStatus_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1856 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1857 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1858 | |
jhbr | 0:d3f5fdf2e6da | 1859 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1860 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1861 | |
jhbr | 0:d3f5fdf2e6da | 1862 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1863 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1864 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1865 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1866 | |
jhbr | 0:d3f5fdf2e6da | 1867 | // return |
jhbr | 0:d3f5fdf2e6da | 1868 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1869 | } |
jhbr | 0:d3f5fdf2e6da | 1870 | |
jhbr | 0:d3f5fdf2e6da | 1871 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1872 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1873 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1874 | dn_ipmt_vars.paramId = PARAMID_MOTESTATUS; |
jhbr | 0:d3f5fdf2e6da | 1875 | |
jhbr | 0:d3f5fdf2e6da | 1876 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1877 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1878 | |
jhbr | 0:d3f5fdf2e6da | 1879 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1880 | dn_ipmt_vars.outputBuf[0] = PARAMID_MOTESTATUS; |
jhbr | 0:d3f5fdf2e6da | 1881 | |
jhbr | 0:d3f5fdf2e6da | 1882 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1883 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1884 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1885 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1886 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1887 | DN_GETPARAMETER_MOTESTATUS_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1888 | dn_ipmt_getParameter_moteStatus_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1889 | ); |
jhbr | 0:d3f5fdf2e6da | 1890 | |
jhbr | 0:d3f5fdf2e6da | 1891 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1892 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1893 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1894 | } |
jhbr | 0:d3f5fdf2e6da | 1895 | |
jhbr | 0:d3f5fdf2e6da | 1896 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1897 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1898 | |
jhbr | 0:d3f5fdf2e6da | 1899 | return rc; |
jhbr | 0:d3f5fdf2e6da | 1900 | |
jhbr | 0:d3f5fdf2e6da | 1901 | } |
jhbr | 0:d3f5fdf2e6da | 1902 | |
jhbr | 0:d3f5fdf2e6da | 1903 | void dn_ipmt_getParameter_moteStatus_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 1904 | dn_ipmt_getParameter_moteStatus_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 1905 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 1906 | |
jhbr | 0:d3f5fdf2e6da | 1907 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 1908 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 1909 | return; |
jhbr | 0:d3f5fdf2e6da | 1910 | } |
jhbr | 0:d3f5fdf2e6da | 1911 | |
jhbr | 0:d3f5fdf2e6da | 1912 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 1913 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 1914 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 1915 | return; |
jhbr | 0:d3f5fdf2e6da | 1916 | } |
jhbr | 0:d3f5fdf2e6da | 1917 | |
jhbr | 0:d3f5fdf2e6da | 1918 | // verify length |
jhbr | 0:d3f5fdf2e6da | 1919 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_MOTESTATUS_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 1920 | return; |
jhbr | 0:d3f5fdf2e6da | 1921 | } |
jhbr | 0:d3f5fdf2e6da | 1922 | |
jhbr | 0:d3f5fdf2e6da | 1923 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 1924 | reply = (dn_ipmt_getParameter_moteStatus_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 1925 | |
jhbr | 0:d3f5fdf2e6da | 1926 | // store RC |
jhbr | 0:d3f5fdf2e6da | 1927 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 1928 | |
jhbr | 0:d3f5fdf2e6da | 1929 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 1930 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 1931 | |
jhbr | 0:d3f5fdf2e6da | 1932 | reply->state = payload[DN_GETPARAMETER_MOTESTATUS_REPLY_OFFS_STATE]; |
jhbr | 0:d3f5fdf2e6da | 1933 | reply->reserved_0 = payload[DN_GETPARAMETER_MOTESTATUS_REPLY_OFFS_RESERVED_0]; |
jhbr | 0:d3f5fdf2e6da | 1934 | dn_read_uint16_t(&reply->reserved_1,&payload[DN_GETPARAMETER_MOTESTATUS_REPLY_OFFS_RESERVED_1]); |
jhbr | 0:d3f5fdf2e6da | 1935 | reply->numParents = payload[DN_GETPARAMETER_MOTESTATUS_REPLY_OFFS_NUMPARENTS]; |
jhbr | 0:d3f5fdf2e6da | 1936 | dn_read_uint32_t(&reply->alarms,&payload[DN_GETPARAMETER_MOTESTATUS_REPLY_OFFS_ALARMS]); |
jhbr | 0:d3f5fdf2e6da | 1937 | reply->reserved_2 = payload[DN_GETPARAMETER_MOTESTATUS_REPLY_OFFS_RESERVED_2]; |
jhbr | 0:d3f5fdf2e6da | 1938 | } |
jhbr | 0:d3f5fdf2e6da | 1939 | |
jhbr | 0:d3f5fdf2e6da | 1940 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 1941 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 1942 | |
jhbr | 0:d3f5fdf2e6da | 1943 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 1944 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 1945 | } |
jhbr | 0:d3f5fdf2e6da | 1946 | |
jhbr | 0:d3f5fdf2e6da | 1947 | //===== getParameter_time |
jhbr | 0:d3f5fdf2e6da | 1948 | |
jhbr | 0:d3f5fdf2e6da | 1949 | /** |
jhbr | 0:d3f5fdf2e6da | 1950 | The getParameter<time> command may be used to request the current time on the |
jhbr | 0:d3f5fdf2e6da | 1951 | mote. The mote reports time at the moment it is processing the command, so the |
jhbr | 0:d3f5fdf2e6da | 1952 | information includes variable delay. For more precise time information consider |
jhbr | 0:d3f5fdf2e6da | 1953 | using TIMEn pin (see timeIndication). |
jhbr | 0:d3f5fdf2e6da | 1954 | */ |
jhbr | 0:d3f5fdf2e6da | 1955 | dn_err_t dn_ipmt_getParameter_time(dn_ipmt_getParameter_time_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 1956 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 1957 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 1958 | |
jhbr | 0:d3f5fdf2e6da | 1959 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 1960 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 1961 | |
jhbr | 0:d3f5fdf2e6da | 1962 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 1963 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 1964 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1965 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1966 | |
jhbr | 0:d3f5fdf2e6da | 1967 | // return |
jhbr | 0:d3f5fdf2e6da | 1968 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 1969 | } |
jhbr | 0:d3f5fdf2e6da | 1970 | |
jhbr | 0:d3f5fdf2e6da | 1971 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 1972 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 1973 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 1974 | dn_ipmt_vars.paramId = PARAMID_TIME; |
jhbr | 0:d3f5fdf2e6da | 1975 | |
jhbr | 0:d3f5fdf2e6da | 1976 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1977 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 1978 | |
jhbr | 0:d3f5fdf2e6da | 1979 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 1980 | dn_ipmt_vars.outputBuf[0] = PARAMID_TIME; |
jhbr | 0:d3f5fdf2e6da | 1981 | |
jhbr | 0:d3f5fdf2e6da | 1982 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 1983 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 1984 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 1985 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 1986 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 1987 | DN_GETPARAMETER_TIME_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 1988 | dn_ipmt_getParameter_time_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 1989 | ); |
jhbr | 0:d3f5fdf2e6da | 1990 | |
jhbr | 0:d3f5fdf2e6da | 1991 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 1992 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 1993 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 1994 | } |
jhbr | 0:d3f5fdf2e6da | 1995 | |
jhbr | 0:d3f5fdf2e6da | 1996 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 1997 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 1998 | |
jhbr | 0:d3f5fdf2e6da | 1999 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2000 | |
jhbr | 0:d3f5fdf2e6da | 2001 | } |
jhbr | 0:d3f5fdf2e6da | 2002 | |
jhbr | 0:d3f5fdf2e6da | 2003 | void dn_ipmt_getParameter_time_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2004 | dn_ipmt_getParameter_time_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2005 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2006 | |
jhbr | 0:d3f5fdf2e6da | 2007 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2008 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2009 | return; |
jhbr | 0:d3f5fdf2e6da | 2010 | } |
jhbr | 0:d3f5fdf2e6da | 2011 | |
jhbr | 0:d3f5fdf2e6da | 2012 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2013 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2014 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2015 | return; |
jhbr | 0:d3f5fdf2e6da | 2016 | } |
jhbr | 0:d3f5fdf2e6da | 2017 | |
jhbr | 0:d3f5fdf2e6da | 2018 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2019 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_TIME_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2020 | return; |
jhbr | 0:d3f5fdf2e6da | 2021 | } |
jhbr | 0:d3f5fdf2e6da | 2022 | |
jhbr | 0:d3f5fdf2e6da | 2023 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2024 | reply = (dn_ipmt_getParameter_time_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2025 | |
jhbr | 0:d3f5fdf2e6da | 2026 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2027 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2028 | |
jhbr | 0:d3f5fdf2e6da | 2029 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2030 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2031 | |
jhbr | 0:d3f5fdf2e6da | 2032 | dn_read_uint32_t(&reply->upTime,&payload[DN_GETPARAMETER_TIME_REPLY_OFFS_UPTIME]); |
jhbr | 0:d3f5fdf2e6da | 2033 | memcpy(&reply->utcSecs[0],&payload[DN_GETPARAMETER_TIME_REPLY_OFFS_UTCSECS],8); |
jhbr | 0:d3f5fdf2e6da | 2034 | dn_read_uint32_t(&reply->utcUsecs,&payload[DN_GETPARAMETER_TIME_REPLY_OFFS_UTCUSECS]); |
jhbr | 0:d3f5fdf2e6da | 2035 | memcpy(&reply->asn[0],&payload[DN_GETPARAMETER_TIME_REPLY_OFFS_ASN],5); |
jhbr | 0:d3f5fdf2e6da | 2036 | dn_read_uint16_t(&reply->asnOffset,&payload[DN_GETPARAMETER_TIME_REPLY_OFFS_ASNOFFSET]); |
jhbr | 0:d3f5fdf2e6da | 2037 | } |
jhbr | 0:d3f5fdf2e6da | 2038 | |
jhbr | 0:d3f5fdf2e6da | 2039 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2040 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2041 | |
jhbr | 0:d3f5fdf2e6da | 2042 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2043 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2044 | } |
jhbr | 0:d3f5fdf2e6da | 2045 | |
jhbr | 0:d3f5fdf2e6da | 2046 | //===== getParameter_charge |
jhbr | 0:d3f5fdf2e6da | 2047 | |
jhbr | 0:d3f5fdf2e6da | 2048 | /** |
jhbr | 0:d3f5fdf2e6da | 2049 | The getParameter<charge> command retrieves the charge consumption of the |
jhbr | 0:d3f5fdf2e6da | 2050 | motesince the last reset. |
jhbr | 0:d3f5fdf2e6da | 2051 | */ |
jhbr | 0:d3f5fdf2e6da | 2052 | dn_err_t dn_ipmt_getParameter_charge(dn_ipmt_getParameter_charge_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2053 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2054 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2055 | |
jhbr | 0:d3f5fdf2e6da | 2056 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2057 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2058 | |
jhbr | 0:d3f5fdf2e6da | 2059 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2060 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2061 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2062 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2063 | |
jhbr | 0:d3f5fdf2e6da | 2064 | // return |
jhbr | 0:d3f5fdf2e6da | 2065 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2066 | } |
jhbr | 0:d3f5fdf2e6da | 2067 | |
jhbr | 0:d3f5fdf2e6da | 2068 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2069 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2070 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2071 | dn_ipmt_vars.paramId = PARAMID_CHARGE; |
jhbr | 0:d3f5fdf2e6da | 2072 | |
jhbr | 0:d3f5fdf2e6da | 2073 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2074 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2075 | |
jhbr | 0:d3f5fdf2e6da | 2076 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2077 | dn_ipmt_vars.outputBuf[0] = PARAMID_CHARGE; |
jhbr | 0:d3f5fdf2e6da | 2078 | |
jhbr | 0:d3f5fdf2e6da | 2079 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2080 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2081 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2082 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2083 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2084 | DN_GETPARAMETER_CHARGE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2085 | dn_ipmt_getParameter_charge_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2086 | ); |
jhbr | 0:d3f5fdf2e6da | 2087 | |
jhbr | 0:d3f5fdf2e6da | 2088 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2089 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2090 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2091 | } |
jhbr | 0:d3f5fdf2e6da | 2092 | |
jhbr | 0:d3f5fdf2e6da | 2093 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2094 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2095 | |
jhbr | 0:d3f5fdf2e6da | 2096 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2097 | |
jhbr | 0:d3f5fdf2e6da | 2098 | } |
jhbr | 0:d3f5fdf2e6da | 2099 | |
jhbr | 0:d3f5fdf2e6da | 2100 | void dn_ipmt_getParameter_charge_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2101 | dn_ipmt_getParameter_charge_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2102 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2103 | |
jhbr | 0:d3f5fdf2e6da | 2104 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2105 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2106 | return; |
jhbr | 0:d3f5fdf2e6da | 2107 | } |
jhbr | 0:d3f5fdf2e6da | 2108 | |
jhbr | 0:d3f5fdf2e6da | 2109 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2110 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2111 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2112 | return; |
jhbr | 0:d3f5fdf2e6da | 2113 | } |
jhbr | 0:d3f5fdf2e6da | 2114 | |
jhbr | 0:d3f5fdf2e6da | 2115 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2116 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_CHARGE_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2117 | return; |
jhbr | 0:d3f5fdf2e6da | 2118 | } |
jhbr | 0:d3f5fdf2e6da | 2119 | |
jhbr | 0:d3f5fdf2e6da | 2120 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2121 | reply = (dn_ipmt_getParameter_charge_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2122 | |
jhbr | 0:d3f5fdf2e6da | 2123 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2124 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2125 | |
jhbr | 0:d3f5fdf2e6da | 2126 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2127 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2128 | |
jhbr | 0:d3f5fdf2e6da | 2129 | dn_read_uint32_t(&reply->qTotal,&payload[DN_GETPARAMETER_CHARGE_REPLY_OFFS_QTOTAL]); |
jhbr | 0:d3f5fdf2e6da | 2130 | dn_read_uint32_t(&reply->upTime,&payload[DN_GETPARAMETER_CHARGE_REPLY_OFFS_UPTIME]); |
jhbr | 0:d3f5fdf2e6da | 2131 | reply->tempInt = (int8_t)payload[DN_GETPARAMETER_CHARGE_REPLY_OFFS_TEMPINT]; |
jhbr | 0:d3f5fdf2e6da | 2132 | reply->tempFrac = payload[DN_GETPARAMETER_CHARGE_REPLY_OFFS_TEMPFRAC]; |
jhbr | 0:d3f5fdf2e6da | 2133 | } |
jhbr | 0:d3f5fdf2e6da | 2134 | |
jhbr | 0:d3f5fdf2e6da | 2135 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2136 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2137 | |
jhbr | 0:d3f5fdf2e6da | 2138 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2139 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2140 | } |
jhbr | 0:d3f5fdf2e6da | 2141 | |
jhbr | 0:d3f5fdf2e6da | 2142 | //===== getParameter_testRadioRxStats |
jhbr | 0:d3f5fdf2e6da | 2143 | |
jhbr | 0:d3f5fdf2e6da | 2144 | /** |
jhbr | 0:d3f5fdf2e6da | 2145 | The getParameter<testRadioRxStats> command retrieves statistics for the latest |
jhbr | 0:d3f5fdf2e6da | 2146 | radio test performed using the testRadioRx command. The statistics show the |
jhbr | 0:d3f5fdf2e6da | 2147 | number of good and bad packets (CRC failures) received during the test |
jhbr | 0:d3f5fdf2e6da | 2148 | */ |
jhbr | 0:d3f5fdf2e6da | 2149 | dn_err_t dn_ipmt_getParameter_testRadioRxStats(dn_ipmt_getParameter_testRadioRxStats_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2150 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2151 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2152 | |
jhbr | 0:d3f5fdf2e6da | 2153 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2154 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2155 | |
jhbr | 0:d3f5fdf2e6da | 2156 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2157 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2158 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2159 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2160 | |
jhbr | 0:d3f5fdf2e6da | 2161 | // return |
jhbr | 0:d3f5fdf2e6da | 2162 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2163 | } |
jhbr | 0:d3f5fdf2e6da | 2164 | |
jhbr | 0:d3f5fdf2e6da | 2165 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2166 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2167 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2168 | dn_ipmt_vars.paramId = PARAMID_TESTRADIORXSTATS; |
jhbr | 0:d3f5fdf2e6da | 2169 | |
jhbr | 0:d3f5fdf2e6da | 2170 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2171 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2172 | |
jhbr | 0:d3f5fdf2e6da | 2173 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2174 | dn_ipmt_vars.outputBuf[0] = PARAMID_TESTRADIORXSTATS; |
jhbr | 0:d3f5fdf2e6da | 2175 | |
jhbr | 0:d3f5fdf2e6da | 2176 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2177 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2178 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2179 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2180 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2181 | DN_GETPARAMETER_TESTRADIORXSTATS_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2182 | dn_ipmt_getParameter_testRadioRxStats_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2183 | ); |
jhbr | 0:d3f5fdf2e6da | 2184 | |
jhbr | 0:d3f5fdf2e6da | 2185 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2186 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2187 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2188 | } |
jhbr | 0:d3f5fdf2e6da | 2189 | |
jhbr | 0:d3f5fdf2e6da | 2190 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2191 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2192 | |
jhbr | 0:d3f5fdf2e6da | 2193 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2194 | |
jhbr | 0:d3f5fdf2e6da | 2195 | } |
jhbr | 0:d3f5fdf2e6da | 2196 | |
jhbr | 0:d3f5fdf2e6da | 2197 | void dn_ipmt_getParameter_testRadioRxStats_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2198 | dn_ipmt_getParameter_testRadioRxStats_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2199 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2200 | |
jhbr | 0:d3f5fdf2e6da | 2201 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2202 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2203 | return; |
jhbr | 0:d3f5fdf2e6da | 2204 | } |
jhbr | 0:d3f5fdf2e6da | 2205 | |
jhbr | 0:d3f5fdf2e6da | 2206 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2207 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2208 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2209 | return; |
jhbr | 0:d3f5fdf2e6da | 2210 | } |
jhbr | 0:d3f5fdf2e6da | 2211 | |
jhbr | 0:d3f5fdf2e6da | 2212 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2213 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_TESTRADIORXSTATS_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2214 | return; |
jhbr | 0:d3f5fdf2e6da | 2215 | } |
jhbr | 0:d3f5fdf2e6da | 2216 | |
jhbr | 0:d3f5fdf2e6da | 2217 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2218 | reply = (dn_ipmt_getParameter_testRadioRxStats_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2219 | |
jhbr | 0:d3f5fdf2e6da | 2220 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2221 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2222 | |
jhbr | 0:d3f5fdf2e6da | 2223 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2224 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2225 | |
jhbr | 0:d3f5fdf2e6da | 2226 | dn_read_uint16_t(&reply->rxOk,&payload[DN_GETPARAMETER_TESTRADIORXSTATS_REPLY_OFFS_RXOK]); |
jhbr | 0:d3f5fdf2e6da | 2227 | dn_read_uint16_t(&reply->rxFailed,&payload[DN_GETPARAMETER_TESTRADIORXSTATS_REPLY_OFFS_RXFAILED]); |
jhbr | 0:d3f5fdf2e6da | 2228 | } |
jhbr | 0:d3f5fdf2e6da | 2229 | |
jhbr | 0:d3f5fdf2e6da | 2230 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2231 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2232 | |
jhbr | 0:d3f5fdf2e6da | 2233 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2234 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2235 | } |
jhbr | 0:d3f5fdf2e6da | 2236 | |
jhbr | 0:d3f5fdf2e6da | 2237 | //===== getParameter_OTAPLockout |
jhbr | 0:d3f5fdf2e6da | 2238 | |
jhbr | 0:d3f5fdf2e6da | 2239 | /** |
jhbr | 0:d3f5fdf2e6da | 2240 | This command reads the current state of OTAP lockout, i.e. whether over-the-air |
jhbr | 0:d3f5fdf2e6da | 2241 | upgrades of software are permitted on this mote. |
jhbr | 0:d3f5fdf2e6da | 2242 | */ |
jhbr | 0:d3f5fdf2e6da | 2243 | dn_err_t dn_ipmt_getParameter_OTAPLockout(dn_ipmt_getParameter_OTAPLockout_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2244 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2245 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2246 | |
jhbr | 0:d3f5fdf2e6da | 2247 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2248 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2249 | |
jhbr | 0:d3f5fdf2e6da | 2250 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2251 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2252 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2253 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2254 | |
jhbr | 0:d3f5fdf2e6da | 2255 | // return |
jhbr | 0:d3f5fdf2e6da | 2256 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2257 | } |
jhbr | 0:d3f5fdf2e6da | 2258 | |
jhbr | 0:d3f5fdf2e6da | 2259 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2260 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2261 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2262 | dn_ipmt_vars.paramId = PARAMID_OTAPLOCKOUT; |
jhbr | 0:d3f5fdf2e6da | 2263 | |
jhbr | 0:d3f5fdf2e6da | 2264 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2265 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2266 | |
jhbr | 0:d3f5fdf2e6da | 2267 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2268 | dn_ipmt_vars.outputBuf[0] = PARAMID_OTAPLOCKOUT; |
jhbr | 0:d3f5fdf2e6da | 2269 | |
jhbr | 0:d3f5fdf2e6da | 2270 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2271 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2272 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2273 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2274 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2275 | DN_GETPARAMETER_OTAPLOCKOUT_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2276 | dn_ipmt_getParameter_OTAPLockout_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2277 | ); |
jhbr | 0:d3f5fdf2e6da | 2278 | |
jhbr | 0:d3f5fdf2e6da | 2279 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2280 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2281 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2282 | } |
jhbr | 0:d3f5fdf2e6da | 2283 | |
jhbr | 0:d3f5fdf2e6da | 2284 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2285 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2286 | |
jhbr | 0:d3f5fdf2e6da | 2287 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2288 | |
jhbr | 0:d3f5fdf2e6da | 2289 | } |
jhbr | 0:d3f5fdf2e6da | 2290 | |
jhbr | 0:d3f5fdf2e6da | 2291 | void dn_ipmt_getParameter_OTAPLockout_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2292 | dn_ipmt_getParameter_OTAPLockout_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2293 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2294 | |
jhbr | 0:d3f5fdf2e6da | 2295 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2296 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2297 | return; |
jhbr | 0:d3f5fdf2e6da | 2298 | } |
jhbr | 0:d3f5fdf2e6da | 2299 | |
jhbr | 0:d3f5fdf2e6da | 2300 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2301 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2302 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2303 | return; |
jhbr | 0:d3f5fdf2e6da | 2304 | } |
jhbr | 0:d3f5fdf2e6da | 2305 | |
jhbr | 0:d3f5fdf2e6da | 2306 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2307 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_OTAPLOCKOUT_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2308 | return; |
jhbr | 0:d3f5fdf2e6da | 2309 | } |
jhbr | 0:d3f5fdf2e6da | 2310 | |
jhbr | 0:d3f5fdf2e6da | 2311 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2312 | reply = (dn_ipmt_getParameter_OTAPLockout_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2313 | |
jhbr | 0:d3f5fdf2e6da | 2314 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2315 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2316 | |
jhbr | 0:d3f5fdf2e6da | 2317 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2318 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2319 | |
jhbr | 0:d3f5fdf2e6da | 2320 | reply->mode = payload[DN_GETPARAMETER_OTAPLOCKOUT_REPLY_OFFS_MODE]; |
jhbr | 0:d3f5fdf2e6da | 2321 | } |
jhbr | 0:d3f5fdf2e6da | 2322 | |
jhbr | 0:d3f5fdf2e6da | 2323 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2324 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2325 | |
jhbr | 0:d3f5fdf2e6da | 2326 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2327 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2328 | } |
jhbr | 0:d3f5fdf2e6da | 2329 | |
jhbr | 0:d3f5fdf2e6da | 2330 | //===== getParameter_moteId |
jhbr | 0:d3f5fdf2e6da | 2331 | |
jhbr | 0:d3f5fdf2e6da | 2332 | /** |
jhbr | 0:d3f5fdf2e6da | 2333 | This command retrieves the mote's Mote ID. If the mote is not in the network, |
jhbr | 0:d3f5fdf2e6da | 2334 | value of 0 is returned. |
jhbr | 0:d3f5fdf2e6da | 2335 | */ |
jhbr | 0:d3f5fdf2e6da | 2336 | dn_err_t dn_ipmt_getParameter_moteId(dn_ipmt_getParameter_moteId_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2337 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2338 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2339 | |
jhbr | 0:d3f5fdf2e6da | 2340 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2341 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2342 | |
jhbr | 0:d3f5fdf2e6da | 2343 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2344 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2345 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2346 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2347 | |
jhbr | 0:d3f5fdf2e6da | 2348 | // return |
jhbr | 0:d3f5fdf2e6da | 2349 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2350 | } |
jhbr | 0:d3f5fdf2e6da | 2351 | |
jhbr | 0:d3f5fdf2e6da | 2352 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2353 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2354 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2355 | dn_ipmt_vars.paramId = PARAMID_MOTEID; |
jhbr | 0:d3f5fdf2e6da | 2356 | |
jhbr | 0:d3f5fdf2e6da | 2357 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2358 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2359 | |
jhbr | 0:d3f5fdf2e6da | 2360 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2361 | dn_ipmt_vars.outputBuf[0] = PARAMID_MOTEID; |
jhbr | 0:d3f5fdf2e6da | 2362 | |
jhbr | 0:d3f5fdf2e6da | 2363 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2364 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2365 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2366 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2367 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2368 | DN_GETPARAMETER_MOTEID_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2369 | dn_ipmt_getParameter_moteId_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2370 | ); |
jhbr | 0:d3f5fdf2e6da | 2371 | |
jhbr | 0:d3f5fdf2e6da | 2372 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2373 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2374 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2375 | } |
jhbr | 0:d3f5fdf2e6da | 2376 | |
jhbr | 0:d3f5fdf2e6da | 2377 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2378 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2379 | |
jhbr | 0:d3f5fdf2e6da | 2380 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2381 | |
jhbr | 0:d3f5fdf2e6da | 2382 | } |
jhbr | 0:d3f5fdf2e6da | 2383 | |
jhbr | 0:d3f5fdf2e6da | 2384 | void dn_ipmt_getParameter_moteId_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2385 | dn_ipmt_getParameter_moteId_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2386 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2387 | |
jhbr | 0:d3f5fdf2e6da | 2388 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2389 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2390 | return; |
jhbr | 0:d3f5fdf2e6da | 2391 | } |
jhbr | 0:d3f5fdf2e6da | 2392 | |
jhbr | 0:d3f5fdf2e6da | 2393 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2394 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2395 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2396 | return; |
jhbr | 0:d3f5fdf2e6da | 2397 | } |
jhbr | 0:d3f5fdf2e6da | 2398 | |
jhbr | 0:d3f5fdf2e6da | 2399 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2400 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_MOTEID_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2401 | return; |
jhbr | 0:d3f5fdf2e6da | 2402 | } |
jhbr | 0:d3f5fdf2e6da | 2403 | |
jhbr | 0:d3f5fdf2e6da | 2404 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2405 | reply = (dn_ipmt_getParameter_moteId_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2406 | |
jhbr | 0:d3f5fdf2e6da | 2407 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2408 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2409 | |
jhbr | 0:d3f5fdf2e6da | 2410 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2411 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2412 | |
jhbr | 0:d3f5fdf2e6da | 2413 | dn_read_uint16_t(&reply->moteId,&payload[DN_GETPARAMETER_MOTEID_REPLY_OFFS_MOTEID]); |
jhbr | 0:d3f5fdf2e6da | 2414 | } |
jhbr | 0:d3f5fdf2e6da | 2415 | |
jhbr | 0:d3f5fdf2e6da | 2416 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2417 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2418 | |
jhbr | 0:d3f5fdf2e6da | 2419 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2420 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2421 | } |
jhbr | 0:d3f5fdf2e6da | 2422 | |
jhbr | 0:d3f5fdf2e6da | 2423 | //===== getParameter_ipv6Address |
jhbr | 0:d3f5fdf2e6da | 2424 | |
jhbr | 0:d3f5fdf2e6da | 2425 | /** |
jhbr | 0:d3f5fdf2e6da | 2426 | This command allows the microprocessor to read IPV6 address assigned to the |
jhbr | 0:d3f5fdf2e6da | 2427 | mote. Before the mote has an assigned address it will return all 0s. |
jhbr | 0:d3f5fdf2e6da | 2428 | */ |
jhbr | 0:d3f5fdf2e6da | 2429 | dn_err_t dn_ipmt_getParameter_ipv6Address(dn_ipmt_getParameter_ipv6Address_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2430 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2431 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2432 | |
jhbr | 0:d3f5fdf2e6da | 2433 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2434 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2435 | |
jhbr | 0:d3f5fdf2e6da | 2436 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2437 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2438 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2439 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2440 | |
jhbr | 0:d3f5fdf2e6da | 2441 | // return |
jhbr | 0:d3f5fdf2e6da | 2442 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2443 | } |
jhbr | 0:d3f5fdf2e6da | 2444 | |
jhbr | 0:d3f5fdf2e6da | 2445 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2446 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2447 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2448 | dn_ipmt_vars.paramId = PARAMID_IPV6ADDRESS; |
jhbr | 0:d3f5fdf2e6da | 2449 | |
jhbr | 0:d3f5fdf2e6da | 2450 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2451 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2452 | |
jhbr | 0:d3f5fdf2e6da | 2453 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2454 | dn_ipmt_vars.outputBuf[0] = PARAMID_IPV6ADDRESS; |
jhbr | 0:d3f5fdf2e6da | 2455 | |
jhbr | 0:d3f5fdf2e6da | 2456 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2457 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2458 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2459 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2460 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2461 | DN_GETPARAMETER_IPV6ADDRESS_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2462 | dn_ipmt_getParameter_ipv6Address_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2463 | ); |
jhbr | 0:d3f5fdf2e6da | 2464 | |
jhbr | 0:d3f5fdf2e6da | 2465 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2466 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2467 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2468 | } |
jhbr | 0:d3f5fdf2e6da | 2469 | |
jhbr | 0:d3f5fdf2e6da | 2470 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2471 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2472 | |
jhbr | 0:d3f5fdf2e6da | 2473 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2474 | |
jhbr | 0:d3f5fdf2e6da | 2475 | } |
jhbr | 0:d3f5fdf2e6da | 2476 | |
jhbr | 0:d3f5fdf2e6da | 2477 | void dn_ipmt_getParameter_ipv6Address_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2478 | dn_ipmt_getParameter_ipv6Address_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2479 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2480 | |
jhbr | 0:d3f5fdf2e6da | 2481 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2482 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2483 | return; |
jhbr | 0:d3f5fdf2e6da | 2484 | } |
jhbr | 0:d3f5fdf2e6da | 2485 | |
jhbr | 0:d3f5fdf2e6da | 2486 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2487 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2488 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2489 | return; |
jhbr | 0:d3f5fdf2e6da | 2490 | } |
jhbr | 0:d3f5fdf2e6da | 2491 | |
jhbr | 0:d3f5fdf2e6da | 2492 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2493 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_IPV6ADDRESS_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2494 | return; |
jhbr | 0:d3f5fdf2e6da | 2495 | } |
jhbr | 0:d3f5fdf2e6da | 2496 | |
jhbr | 0:d3f5fdf2e6da | 2497 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2498 | reply = (dn_ipmt_getParameter_ipv6Address_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2499 | |
jhbr | 0:d3f5fdf2e6da | 2500 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2501 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2502 | |
jhbr | 0:d3f5fdf2e6da | 2503 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2504 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2505 | |
jhbr | 0:d3f5fdf2e6da | 2506 | memcpy(&reply->ipv6Address[0],&payload[DN_GETPARAMETER_IPV6ADDRESS_REPLY_OFFS_IPV6ADDRESS],16); |
jhbr | 0:d3f5fdf2e6da | 2507 | } |
jhbr | 0:d3f5fdf2e6da | 2508 | |
jhbr | 0:d3f5fdf2e6da | 2509 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2510 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2511 | |
jhbr | 0:d3f5fdf2e6da | 2512 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2513 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2514 | } |
jhbr | 0:d3f5fdf2e6da | 2515 | |
jhbr | 0:d3f5fdf2e6da | 2516 | //===== getParameter_routingMode |
jhbr | 0:d3f5fdf2e6da | 2517 | |
jhbr | 0:d3f5fdf2e6da | 2518 | /** |
jhbr | 0:d3f5fdf2e6da | 2519 | This command allows the microprocessor to retrieve the current routing mode of |
jhbr | 0:d3f5fdf2e6da | 2520 | the mote. |
jhbr | 0:d3f5fdf2e6da | 2521 | */ |
jhbr | 0:d3f5fdf2e6da | 2522 | dn_err_t dn_ipmt_getParameter_routingMode(dn_ipmt_getParameter_routingMode_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2523 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2524 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2525 | |
jhbr | 0:d3f5fdf2e6da | 2526 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2527 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2528 | |
jhbr | 0:d3f5fdf2e6da | 2529 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2530 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2531 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2532 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2533 | |
jhbr | 0:d3f5fdf2e6da | 2534 | // return |
jhbr | 0:d3f5fdf2e6da | 2535 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2536 | } |
jhbr | 0:d3f5fdf2e6da | 2537 | |
jhbr | 0:d3f5fdf2e6da | 2538 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2539 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2540 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2541 | dn_ipmt_vars.paramId = PARAMID_ROUTINGMODE; |
jhbr | 0:d3f5fdf2e6da | 2542 | |
jhbr | 0:d3f5fdf2e6da | 2543 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2544 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2545 | |
jhbr | 0:d3f5fdf2e6da | 2546 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2547 | dn_ipmt_vars.outputBuf[0] = PARAMID_ROUTINGMODE; |
jhbr | 0:d3f5fdf2e6da | 2548 | |
jhbr | 0:d3f5fdf2e6da | 2549 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2550 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2551 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2552 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2553 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2554 | DN_GETPARAMETER_ROUTINGMODE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2555 | dn_ipmt_getParameter_routingMode_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2556 | ); |
jhbr | 0:d3f5fdf2e6da | 2557 | |
jhbr | 0:d3f5fdf2e6da | 2558 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2559 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2560 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2561 | } |
jhbr | 0:d3f5fdf2e6da | 2562 | |
jhbr | 0:d3f5fdf2e6da | 2563 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2564 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2565 | |
jhbr | 0:d3f5fdf2e6da | 2566 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2567 | |
jhbr | 0:d3f5fdf2e6da | 2568 | } |
jhbr | 0:d3f5fdf2e6da | 2569 | |
jhbr | 0:d3f5fdf2e6da | 2570 | void dn_ipmt_getParameter_routingMode_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2571 | dn_ipmt_getParameter_routingMode_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2572 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2573 | |
jhbr | 0:d3f5fdf2e6da | 2574 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2575 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2576 | return; |
jhbr | 0:d3f5fdf2e6da | 2577 | } |
jhbr | 0:d3f5fdf2e6da | 2578 | |
jhbr | 0:d3f5fdf2e6da | 2579 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2580 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2581 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2582 | return; |
jhbr | 0:d3f5fdf2e6da | 2583 | } |
jhbr | 0:d3f5fdf2e6da | 2584 | |
jhbr | 0:d3f5fdf2e6da | 2585 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2586 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_ROUTINGMODE_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2587 | return; |
jhbr | 0:d3f5fdf2e6da | 2588 | } |
jhbr | 0:d3f5fdf2e6da | 2589 | |
jhbr | 0:d3f5fdf2e6da | 2590 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2591 | reply = (dn_ipmt_getParameter_routingMode_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2592 | |
jhbr | 0:d3f5fdf2e6da | 2593 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2594 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2595 | |
jhbr | 0:d3f5fdf2e6da | 2596 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2597 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2598 | |
jhbr | 0:d3f5fdf2e6da | 2599 | reply->routingMode = payload[DN_GETPARAMETER_ROUTINGMODE_REPLY_OFFS_ROUTINGMODE]; |
jhbr | 0:d3f5fdf2e6da | 2600 | } |
jhbr | 0:d3f5fdf2e6da | 2601 | |
jhbr | 0:d3f5fdf2e6da | 2602 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2603 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2604 | |
jhbr | 0:d3f5fdf2e6da | 2605 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2606 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2607 | } |
jhbr | 0:d3f5fdf2e6da | 2608 | |
jhbr | 0:d3f5fdf2e6da | 2609 | //===== getParameter_appInfo |
jhbr | 0:d3f5fdf2e6da | 2610 | |
jhbr | 0:d3f5fdf2e6da | 2611 | /** |
jhbr | 0:d3f5fdf2e6da | 2612 | Get the application (as opposed to the network stack) version information. |
jhbr | 0:d3f5fdf2e6da | 2613 | */ |
jhbr | 0:d3f5fdf2e6da | 2614 | dn_err_t dn_ipmt_getParameter_appInfo(dn_ipmt_getParameter_appInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2615 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2616 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2617 | |
jhbr | 0:d3f5fdf2e6da | 2618 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2619 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2620 | |
jhbr | 0:d3f5fdf2e6da | 2621 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2622 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2623 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2624 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2625 | |
jhbr | 0:d3f5fdf2e6da | 2626 | // return |
jhbr | 0:d3f5fdf2e6da | 2627 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2628 | } |
jhbr | 0:d3f5fdf2e6da | 2629 | |
jhbr | 0:d3f5fdf2e6da | 2630 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2631 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2632 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2633 | dn_ipmt_vars.paramId = PARAMID_APPINFO; |
jhbr | 0:d3f5fdf2e6da | 2634 | |
jhbr | 0:d3f5fdf2e6da | 2635 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2636 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2637 | |
jhbr | 0:d3f5fdf2e6da | 2638 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2639 | dn_ipmt_vars.outputBuf[0] = PARAMID_APPINFO; |
jhbr | 0:d3f5fdf2e6da | 2640 | |
jhbr | 0:d3f5fdf2e6da | 2641 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2642 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2643 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2644 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2645 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2646 | DN_GETPARAMETER_APPINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2647 | dn_ipmt_getParameter_appInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2648 | ); |
jhbr | 0:d3f5fdf2e6da | 2649 | |
jhbr | 0:d3f5fdf2e6da | 2650 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2651 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2652 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2653 | } |
jhbr | 0:d3f5fdf2e6da | 2654 | |
jhbr | 0:d3f5fdf2e6da | 2655 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2656 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2657 | |
jhbr | 0:d3f5fdf2e6da | 2658 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2659 | |
jhbr | 0:d3f5fdf2e6da | 2660 | } |
jhbr | 0:d3f5fdf2e6da | 2661 | |
jhbr | 0:d3f5fdf2e6da | 2662 | void dn_ipmt_getParameter_appInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2663 | dn_ipmt_getParameter_appInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2664 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2665 | |
jhbr | 0:d3f5fdf2e6da | 2666 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2667 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2668 | return; |
jhbr | 0:d3f5fdf2e6da | 2669 | } |
jhbr | 0:d3f5fdf2e6da | 2670 | |
jhbr | 0:d3f5fdf2e6da | 2671 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2672 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2673 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2674 | return; |
jhbr | 0:d3f5fdf2e6da | 2675 | } |
jhbr | 0:d3f5fdf2e6da | 2676 | |
jhbr | 0:d3f5fdf2e6da | 2677 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2678 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_APPINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2679 | return; |
jhbr | 0:d3f5fdf2e6da | 2680 | } |
jhbr | 0:d3f5fdf2e6da | 2681 | |
jhbr | 0:d3f5fdf2e6da | 2682 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2683 | reply = (dn_ipmt_getParameter_appInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2684 | |
jhbr | 0:d3f5fdf2e6da | 2685 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2686 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2687 | |
jhbr | 0:d3f5fdf2e6da | 2688 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2689 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2690 | |
jhbr | 0:d3f5fdf2e6da | 2691 | dn_read_uint16_t(&reply->vendorId,&payload[DN_GETPARAMETER_APPINFO_REPLY_OFFS_VENDORID]); |
jhbr | 0:d3f5fdf2e6da | 2692 | reply->appId = payload[DN_GETPARAMETER_APPINFO_REPLY_OFFS_APPID]; |
jhbr | 0:d3f5fdf2e6da | 2693 | memcpy(&reply->appVer[0],&payload[DN_GETPARAMETER_APPINFO_REPLY_OFFS_APPVER],5); |
jhbr | 0:d3f5fdf2e6da | 2694 | } |
jhbr | 0:d3f5fdf2e6da | 2695 | |
jhbr | 0:d3f5fdf2e6da | 2696 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2697 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2698 | |
jhbr | 0:d3f5fdf2e6da | 2699 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2700 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2701 | } |
jhbr | 0:d3f5fdf2e6da | 2702 | |
jhbr | 0:d3f5fdf2e6da | 2703 | //===== getParameter_powerSrcInfo |
jhbr | 0:d3f5fdf2e6da | 2704 | |
jhbr | 0:d3f5fdf2e6da | 2705 | /** |
jhbr | 0:d3f5fdf2e6da | 2706 | This command allows the microprocessor to read a mote's power source settings. |
jhbr | 0:d3f5fdf2e6da | 2707 | */ |
jhbr | 0:d3f5fdf2e6da | 2708 | dn_err_t dn_ipmt_getParameter_powerSrcInfo(dn_ipmt_getParameter_powerSrcInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2709 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2710 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2711 | |
jhbr | 0:d3f5fdf2e6da | 2712 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2713 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2714 | |
jhbr | 0:d3f5fdf2e6da | 2715 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2716 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2717 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2718 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2719 | |
jhbr | 0:d3f5fdf2e6da | 2720 | // return |
jhbr | 0:d3f5fdf2e6da | 2721 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2722 | } |
jhbr | 0:d3f5fdf2e6da | 2723 | |
jhbr | 0:d3f5fdf2e6da | 2724 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2725 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2726 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2727 | dn_ipmt_vars.paramId = PARAMID_POWERSRCINFO; |
jhbr | 0:d3f5fdf2e6da | 2728 | |
jhbr | 0:d3f5fdf2e6da | 2729 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2730 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2731 | |
jhbr | 0:d3f5fdf2e6da | 2732 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2733 | dn_ipmt_vars.outputBuf[0] = PARAMID_POWERSRCINFO; |
jhbr | 0:d3f5fdf2e6da | 2734 | |
jhbr | 0:d3f5fdf2e6da | 2735 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2736 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2737 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2738 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2739 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2740 | DN_GETPARAMETER_POWERSRCINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2741 | dn_ipmt_getParameter_powerSrcInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2742 | ); |
jhbr | 0:d3f5fdf2e6da | 2743 | |
jhbr | 0:d3f5fdf2e6da | 2744 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2745 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2746 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2747 | } |
jhbr | 0:d3f5fdf2e6da | 2748 | |
jhbr | 0:d3f5fdf2e6da | 2749 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2750 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2751 | |
jhbr | 0:d3f5fdf2e6da | 2752 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2753 | |
jhbr | 0:d3f5fdf2e6da | 2754 | } |
jhbr | 0:d3f5fdf2e6da | 2755 | |
jhbr | 0:d3f5fdf2e6da | 2756 | void dn_ipmt_getParameter_powerSrcInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2757 | dn_ipmt_getParameter_powerSrcInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2758 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2759 | |
jhbr | 0:d3f5fdf2e6da | 2760 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2761 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2762 | return; |
jhbr | 0:d3f5fdf2e6da | 2763 | } |
jhbr | 0:d3f5fdf2e6da | 2764 | |
jhbr | 0:d3f5fdf2e6da | 2765 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2766 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2767 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2768 | return; |
jhbr | 0:d3f5fdf2e6da | 2769 | } |
jhbr | 0:d3f5fdf2e6da | 2770 | |
jhbr | 0:d3f5fdf2e6da | 2771 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2772 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_POWERSRCINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2773 | return; |
jhbr | 0:d3f5fdf2e6da | 2774 | } |
jhbr | 0:d3f5fdf2e6da | 2775 | |
jhbr | 0:d3f5fdf2e6da | 2776 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2777 | reply = (dn_ipmt_getParameter_powerSrcInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2778 | |
jhbr | 0:d3f5fdf2e6da | 2779 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2780 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2781 | |
jhbr | 0:d3f5fdf2e6da | 2782 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2783 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2784 | |
jhbr | 0:d3f5fdf2e6da | 2785 | dn_read_uint16_t(&reply->maxStCurrent,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_MAXSTCURRENT]); |
jhbr | 0:d3f5fdf2e6da | 2786 | reply->minLifetime = payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_MINLIFETIME]; |
jhbr | 0:d3f5fdf2e6da | 2787 | dn_read_uint16_t(&reply->currentLimit_0,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_CURRENTLIMIT_0]); |
jhbr | 0:d3f5fdf2e6da | 2788 | dn_read_uint16_t(&reply->dischargePeriod_0,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_DISCHARGEPERIOD_0]); |
jhbr | 0:d3f5fdf2e6da | 2789 | dn_read_uint16_t(&reply->rechargePeriod_0,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_RECHARGEPERIOD_0]); |
jhbr | 0:d3f5fdf2e6da | 2790 | dn_read_uint16_t(&reply->currentLimit_1,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_CURRENTLIMIT_1]); |
jhbr | 0:d3f5fdf2e6da | 2791 | dn_read_uint16_t(&reply->dischargePeriod_1,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_DISCHARGEPERIOD_1]); |
jhbr | 0:d3f5fdf2e6da | 2792 | dn_read_uint16_t(&reply->rechargePeriod_1,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_RECHARGEPERIOD_1]); |
jhbr | 0:d3f5fdf2e6da | 2793 | dn_read_uint16_t(&reply->currentLimit_2,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_CURRENTLIMIT_2]); |
jhbr | 0:d3f5fdf2e6da | 2794 | dn_read_uint16_t(&reply->dischargePeriod_2,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_DISCHARGEPERIOD_2]); |
jhbr | 0:d3f5fdf2e6da | 2795 | dn_read_uint16_t(&reply->rechargePeriod_2,&payload[DN_GETPARAMETER_POWERSRCINFO_REPLY_OFFS_RECHARGEPERIOD_2]); |
jhbr | 0:d3f5fdf2e6da | 2796 | } |
jhbr | 0:d3f5fdf2e6da | 2797 | |
jhbr | 0:d3f5fdf2e6da | 2798 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2799 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2800 | |
jhbr | 0:d3f5fdf2e6da | 2801 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2802 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2803 | } |
jhbr | 0:d3f5fdf2e6da | 2804 | |
jhbr | 0:d3f5fdf2e6da | 2805 | //===== getParameter_autoJoin |
jhbr | 0:d3f5fdf2e6da | 2806 | |
jhbr | 0:d3f5fdf2e6da | 2807 | /** |
jhbr | 0:d3f5fdf2e6da | 2808 | This command allows the microprocessor to retrieve the current autoJoin |
jhbr | 0:d3f5fdf2e6da | 2809 | setting. |
jhbr | 0:d3f5fdf2e6da | 2810 | */ |
jhbr | 0:d3f5fdf2e6da | 2811 | dn_err_t dn_ipmt_getParameter_autoJoin(dn_ipmt_getParameter_autoJoin_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2812 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2813 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2814 | |
jhbr | 0:d3f5fdf2e6da | 2815 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2816 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2817 | |
jhbr | 0:d3f5fdf2e6da | 2818 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2819 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2820 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2821 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2822 | |
jhbr | 0:d3f5fdf2e6da | 2823 | // return |
jhbr | 0:d3f5fdf2e6da | 2824 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2825 | } |
jhbr | 0:d3f5fdf2e6da | 2826 | |
jhbr | 0:d3f5fdf2e6da | 2827 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2828 | dn_ipmt_vars.cmdId = CMDID_GETPARAMETER; |
jhbr | 0:d3f5fdf2e6da | 2829 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2830 | dn_ipmt_vars.paramId = PARAMID_AUTOJOIN; |
jhbr | 0:d3f5fdf2e6da | 2831 | |
jhbr | 0:d3f5fdf2e6da | 2832 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2833 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2834 | |
jhbr | 0:d3f5fdf2e6da | 2835 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2836 | dn_ipmt_vars.outputBuf[0] = PARAMID_AUTOJOIN; |
jhbr | 0:d3f5fdf2e6da | 2837 | |
jhbr | 0:d3f5fdf2e6da | 2838 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2839 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2840 | CMDID_GETPARAMETER, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2841 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2842 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2843 | DN_GETPARAMETER_AUTOJOIN_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2844 | dn_ipmt_getParameter_autoJoin_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2845 | ); |
jhbr | 0:d3f5fdf2e6da | 2846 | |
jhbr | 0:d3f5fdf2e6da | 2847 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2848 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2849 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2850 | } |
jhbr | 0:d3f5fdf2e6da | 2851 | |
jhbr | 0:d3f5fdf2e6da | 2852 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2853 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2854 | |
jhbr | 0:d3f5fdf2e6da | 2855 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2856 | |
jhbr | 0:d3f5fdf2e6da | 2857 | } |
jhbr | 0:d3f5fdf2e6da | 2858 | |
jhbr | 0:d3f5fdf2e6da | 2859 | void dn_ipmt_getParameter_autoJoin_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2860 | dn_ipmt_getParameter_autoJoin_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2861 | uint8_t paramId; |
jhbr | 0:d3f5fdf2e6da | 2862 | |
jhbr | 0:d3f5fdf2e6da | 2863 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2864 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2865 | return; |
jhbr | 0:d3f5fdf2e6da | 2866 | } |
jhbr | 0:d3f5fdf2e6da | 2867 | |
jhbr | 0:d3f5fdf2e6da | 2868 | // verify I'm expecting this paramId |
jhbr | 0:d3f5fdf2e6da | 2869 | paramId = payload[0]; |
jhbr | 0:d3f5fdf2e6da | 2870 | if (paramId!=dn_ipmt_vars.paramId) { |
jhbr | 0:d3f5fdf2e6da | 2871 | return; |
jhbr | 0:d3f5fdf2e6da | 2872 | } |
jhbr | 0:d3f5fdf2e6da | 2873 | |
jhbr | 0:d3f5fdf2e6da | 2874 | // verify length |
jhbr | 0:d3f5fdf2e6da | 2875 | if (rc==DN_SERIAL_RC_OK && len<DN_GETPARAMETER_AUTOJOIN_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 2876 | return; |
jhbr | 0:d3f5fdf2e6da | 2877 | } |
jhbr | 0:d3f5fdf2e6da | 2878 | |
jhbr | 0:d3f5fdf2e6da | 2879 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2880 | reply = (dn_ipmt_getParameter_autoJoin_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2881 | |
jhbr | 0:d3f5fdf2e6da | 2882 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2883 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2884 | |
jhbr | 0:d3f5fdf2e6da | 2885 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2886 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2887 | |
jhbr | 0:d3f5fdf2e6da | 2888 | reply->autoJoin = payload[DN_GETPARAMETER_AUTOJOIN_REPLY_OFFS_AUTOJOIN]; |
jhbr | 0:d3f5fdf2e6da | 2889 | } |
jhbr | 0:d3f5fdf2e6da | 2890 | |
jhbr | 0:d3f5fdf2e6da | 2891 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2892 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2893 | |
jhbr | 0:d3f5fdf2e6da | 2894 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2895 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2896 | } |
jhbr | 0:d3f5fdf2e6da | 2897 | |
jhbr | 0:d3f5fdf2e6da | 2898 | //===== join |
jhbr | 0:d3f5fdf2e6da | 2899 | |
jhbr | 0:d3f5fdf2e6da | 2900 | /** |
jhbr | 0:d3f5fdf2e6da | 2901 | The join command requests that mote start searching for the network and attempt |
jhbr | 0:d3f5fdf2e6da | 2902 | to join.The mote must be in the Idle state or the Promiscuous Listen state(see |
jhbr | 0:d3f5fdf2e6da | 2903 | search) for this command to be valid. Note that the join time will be affected |
jhbr | 0:d3f5fdf2e6da | 2904 | by the maximum current setting. |
jhbr | 0:d3f5fdf2e6da | 2905 | */ |
jhbr | 0:d3f5fdf2e6da | 2906 | dn_err_t dn_ipmt_join(dn_ipmt_join_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2907 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2908 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2909 | |
jhbr | 0:d3f5fdf2e6da | 2910 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2911 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2912 | |
jhbr | 0:d3f5fdf2e6da | 2913 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2914 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2915 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2916 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2917 | |
jhbr | 0:d3f5fdf2e6da | 2918 | // return |
jhbr | 0:d3f5fdf2e6da | 2919 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 2920 | } |
jhbr | 0:d3f5fdf2e6da | 2921 | |
jhbr | 0:d3f5fdf2e6da | 2922 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 2923 | dn_ipmt_vars.cmdId = CMDID_JOIN; |
jhbr | 0:d3f5fdf2e6da | 2924 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 2925 | |
jhbr | 0:d3f5fdf2e6da | 2926 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2927 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 2928 | |
jhbr | 0:d3f5fdf2e6da | 2929 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 2930 | |
jhbr | 0:d3f5fdf2e6da | 2931 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 2932 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 2933 | CMDID_JOIN, // cmdId |
jhbr | 0:d3f5fdf2e6da | 2934 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 2935 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 2936 | DN_JOIN_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 2937 | dn_ipmt_join_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 2938 | ); |
jhbr | 0:d3f5fdf2e6da | 2939 | |
jhbr | 0:d3f5fdf2e6da | 2940 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 2941 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 2942 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 2943 | } |
jhbr | 0:d3f5fdf2e6da | 2944 | |
jhbr | 0:d3f5fdf2e6da | 2945 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2946 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 2947 | |
jhbr | 0:d3f5fdf2e6da | 2948 | return rc; |
jhbr | 0:d3f5fdf2e6da | 2949 | |
jhbr | 0:d3f5fdf2e6da | 2950 | } |
jhbr | 0:d3f5fdf2e6da | 2951 | |
jhbr | 0:d3f5fdf2e6da | 2952 | void dn_ipmt_join_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 2953 | dn_ipmt_join_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 2954 | |
jhbr | 0:d3f5fdf2e6da | 2955 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 2956 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 2957 | return; |
jhbr | 0:d3f5fdf2e6da | 2958 | } |
jhbr | 0:d3f5fdf2e6da | 2959 | |
jhbr | 0:d3f5fdf2e6da | 2960 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 2961 | |
jhbr | 0:d3f5fdf2e6da | 2962 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 2963 | reply = (dn_ipmt_join_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 2964 | |
jhbr | 0:d3f5fdf2e6da | 2965 | // store RC |
jhbr | 0:d3f5fdf2e6da | 2966 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 2967 | |
jhbr | 0:d3f5fdf2e6da | 2968 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 2969 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 2970 | |
jhbr | 0:d3f5fdf2e6da | 2971 | } |
jhbr | 0:d3f5fdf2e6da | 2972 | |
jhbr | 0:d3f5fdf2e6da | 2973 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 2974 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 2975 | |
jhbr | 0:d3f5fdf2e6da | 2976 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 2977 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 2978 | } |
jhbr | 0:d3f5fdf2e6da | 2979 | |
jhbr | 0:d3f5fdf2e6da | 2980 | //===== disconnect |
jhbr | 0:d3f5fdf2e6da | 2981 | |
jhbr | 0:d3f5fdf2e6da | 2982 | /** |
jhbr | 0:d3f5fdf2e6da | 2983 | The disconnect command requests that the mote initiate disconnection from the |
jhbr | 0:d3f5fdf2e6da | 2984 | network. After disconnection completes, the mote will generate a disconnected |
jhbr | 0:d3f5fdf2e6da | 2985 | event, and proceed to reset. If the mote is not in the network, the |
jhbr | 0:d3f5fdf2e6da | 2986 | disconnected event will be generated immediately. This command may be issued at |
jhbr | 0:d3f5fdf2e6da | 2987 | any time. |
jhbr | 0:d3f5fdf2e6da | 2988 | */ |
jhbr | 0:d3f5fdf2e6da | 2989 | dn_err_t dn_ipmt_disconnect(dn_ipmt_disconnect_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 2990 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 2991 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 2992 | |
jhbr | 0:d3f5fdf2e6da | 2993 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 2994 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 2995 | |
jhbr | 0:d3f5fdf2e6da | 2996 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 2997 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 2998 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 2999 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3000 | |
jhbr | 0:d3f5fdf2e6da | 3001 | // return |
jhbr | 0:d3f5fdf2e6da | 3002 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3003 | } |
jhbr | 0:d3f5fdf2e6da | 3004 | |
jhbr | 0:d3f5fdf2e6da | 3005 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3006 | dn_ipmt_vars.cmdId = CMDID_DISCONNECT; |
jhbr | 0:d3f5fdf2e6da | 3007 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3008 | |
jhbr | 0:d3f5fdf2e6da | 3009 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3010 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3011 | |
jhbr | 0:d3f5fdf2e6da | 3012 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3013 | |
jhbr | 0:d3f5fdf2e6da | 3014 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3015 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3016 | CMDID_DISCONNECT, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3017 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3018 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3019 | DN_DISCONNECT_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3020 | dn_ipmt_disconnect_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3021 | ); |
jhbr | 0:d3f5fdf2e6da | 3022 | |
jhbr | 0:d3f5fdf2e6da | 3023 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3024 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3025 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3026 | } |
jhbr | 0:d3f5fdf2e6da | 3027 | |
jhbr | 0:d3f5fdf2e6da | 3028 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3029 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3030 | |
jhbr | 0:d3f5fdf2e6da | 3031 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3032 | |
jhbr | 0:d3f5fdf2e6da | 3033 | } |
jhbr | 0:d3f5fdf2e6da | 3034 | |
jhbr | 0:d3f5fdf2e6da | 3035 | void dn_ipmt_disconnect_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3036 | dn_ipmt_disconnect_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3037 | |
jhbr | 0:d3f5fdf2e6da | 3038 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3039 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3040 | return; |
jhbr | 0:d3f5fdf2e6da | 3041 | } |
jhbr | 0:d3f5fdf2e6da | 3042 | |
jhbr | 0:d3f5fdf2e6da | 3043 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3044 | |
jhbr | 0:d3f5fdf2e6da | 3045 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3046 | reply = (dn_ipmt_disconnect_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3047 | |
jhbr | 0:d3f5fdf2e6da | 3048 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3049 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3050 | |
jhbr | 0:d3f5fdf2e6da | 3051 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3052 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3053 | |
jhbr | 0:d3f5fdf2e6da | 3054 | } |
jhbr | 0:d3f5fdf2e6da | 3055 | |
jhbr | 0:d3f5fdf2e6da | 3056 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3057 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3058 | |
jhbr | 0:d3f5fdf2e6da | 3059 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3060 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3061 | } |
jhbr | 0:d3f5fdf2e6da | 3062 | |
jhbr | 0:d3f5fdf2e6da | 3063 | //===== reset |
jhbr | 0:d3f5fdf2e6da | 3064 | |
jhbr | 0:d3f5fdf2e6da | 3065 | /** |
jhbr | 0:d3f5fdf2e6da | 3066 | The reset command initiates a soft-reset of the device. The device will |
jhbr | 0:d3f5fdf2e6da | 3067 | initiate the reset sequence shortly after sending out the response to this |
jhbr | 0:d3f5fdf2e6da | 3068 | command. Resetting a mote directly can adversely impact its descendants; to |
jhbr | 0:d3f5fdf2e6da | 3069 | disconnect gracefully from the network, use the disconnect command |
jhbr | 0:d3f5fdf2e6da | 3070 | */ |
jhbr | 0:d3f5fdf2e6da | 3071 | dn_err_t dn_ipmt_reset(dn_ipmt_reset_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3072 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3073 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3074 | |
jhbr | 0:d3f5fdf2e6da | 3075 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3076 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3077 | |
jhbr | 0:d3f5fdf2e6da | 3078 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3079 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3080 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3081 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3082 | |
jhbr | 0:d3f5fdf2e6da | 3083 | // return |
jhbr | 0:d3f5fdf2e6da | 3084 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3085 | } |
jhbr | 0:d3f5fdf2e6da | 3086 | |
jhbr | 0:d3f5fdf2e6da | 3087 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3088 | dn_ipmt_vars.cmdId = CMDID_RESET; |
jhbr | 0:d3f5fdf2e6da | 3089 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3090 | |
jhbr | 0:d3f5fdf2e6da | 3091 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3092 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3093 | |
jhbr | 0:d3f5fdf2e6da | 3094 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3095 | |
jhbr | 0:d3f5fdf2e6da | 3096 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3097 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3098 | CMDID_RESET, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3099 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3100 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3101 | DN_RESET_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3102 | dn_ipmt_reset_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3103 | ); |
jhbr | 0:d3f5fdf2e6da | 3104 | |
jhbr | 0:d3f5fdf2e6da | 3105 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3106 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3107 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3108 | } |
jhbr | 0:d3f5fdf2e6da | 3109 | |
jhbr | 0:d3f5fdf2e6da | 3110 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3111 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3112 | |
jhbr | 0:d3f5fdf2e6da | 3113 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3114 | |
jhbr | 0:d3f5fdf2e6da | 3115 | } |
jhbr | 0:d3f5fdf2e6da | 3116 | |
jhbr | 0:d3f5fdf2e6da | 3117 | void dn_ipmt_reset_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3118 | dn_ipmt_reset_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3119 | |
jhbr | 0:d3f5fdf2e6da | 3120 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3121 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3122 | return; |
jhbr | 0:d3f5fdf2e6da | 3123 | } |
jhbr | 0:d3f5fdf2e6da | 3124 | |
jhbr | 0:d3f5fdf2e6da | 3125 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3126 | |
jhbr | 0:d3f5fdf2e6da | 3127 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3128 | reply = (dn_ipmt_reset_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3129 | |
jhbr | 0:d3f5fdf2e6da | 3130 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3131 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3132 | |
jhbr | 0:d3f5fdf2e6da | 3133 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3134 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3135 | |
jhbr | 0:d3f5fdf2e6da | 3136 | } |
jhbr | 0:d3f5fdf2e6da | 3137 | |
jhbr | 0:d3f5fdf2e6da | 3138 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3139 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3140 | |
jhbr | 0:d3f5fdf2e6da | 3141 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3142 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3143 | } |
jhbr | 0:d3f5fdf2e6da | 3144 | |
jhbr | 0:d3f5fdf2e6da | 3145 | //===== lowPowerSleep |
jhbr | 0:d3f5fdf2e6da | 3146 | |
jhbr | 0:d3f5fdf2e6da | 3147 | /** |
jhbr | 0:d3f5fdf2e6da | 3148 | The lowPowerSleep command shuts down all peripherals and places the mote into |
jhbr | 0:d3f5fdf2e6da | 3149 | deep sleep mode. The command executes after the mote sends its response. The |
jhbr | 0:d3f5fdf2e6da | 3150 | mote enters deep sleep within two seconds after the command executes. The |
jhbr | 0:d3f5fdf2e6da | 3151 | command may be issued at any time and will cause the mote to interrupt all |
jhbr | 0:d3f5fdf2e6da | 3152 | in-progress network operation. To achieve a graceful disconnect, use the |
jhbr | 0:d3f5fdf2e6da | 3153 | disconnect command before using the lowPowerSleep command. A hardware reset is |
jhbr | 0:d3f5fdf2e6da | 3154 | required to bring a mote out of deep sleep mode. |
jhbr | 0:d3f5fdf2e6da | 3155 | */ |
jhbr | 0:d3f5fdf2e6da | 3156 | dn_err_t dn_ipmt_lowPowerSleep(dn_ipmt_lowPowerSleep_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3157 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3158 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3159 | |
jhbr | 0:d3f5fdf2e6da | 3160 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3161 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3162 | |
jhbr | 0:d3f5fdf2e6da | 3163 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3164 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3165 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3166 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3167 | |
jhbr | 0:d3f5fdf2e6da | 3168 | // return |
jhbr | 0:d3f5fdf2e6da | 3169 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3170 | } |
jhbr | 0:d3f5fdf2e6da | 3171 | |
jhbr | 0:d3f5fdf2e6da | 3172 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3173 | dn_ipmt_vars.cmdId = CMDID_LOWPOWERSLEEP; |
jhbr | 0:d3f5fdf2e6da | 3174 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3175 | |
jhbr | 0:d3f5fdf2e6da | 3176 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3177 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3178 | |
jhbr | 0:d3f5fdf2e6da | 3179 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3180 | |
jhbr | 0:d3f5fdf2e6da | 3181 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3182 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3183 | CMDID_LOWPOWERSLEEP, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3184 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3185 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3186 | DN_LOWPOWERSLEEP_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3187 | dn_ipmt_lowPowerSleep_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3188 | ); |
jhbr | 0:d3f5fdf2e6da | 3189 | |
jhbr | 0:d3f5fdf2e6da | 3190 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3191 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3192 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3193 | } |
jhbr | 0:d3f5fdf2e6da | 3194 | |
jhbr | 0:d3f5fdf2e6da | 3195 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3196 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3197 | |
jhbr | 0:d3f5fdf2e6da | 3198 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3199 | |
jhbr | 0:d3f5fdf2e6da | 3200 | } |
jhbr | 0:d3f5fdf2e6da | 3201 | |
jhbr | 0:d3f5fdf2e6da | 3202 | void dn_ipmt_lowPowerSleep_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3203 | dn_ipmt_lowPowerSleep_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3204 | |
jhbr | 0:d3f5fdf2e6da | 3205 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3206 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3207 | return; |
jhbr | 0:d3f5fdf2e6da | 3208 | } |
jhbr | 0:d3f5fdf2e6da | 3209 | |
jhbr | 0:d3f5fdf2e6da | 3210 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3211 | |
jhbr | 0:d3f5fdf2e6da | 3212 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3213 | reply = (dn_ipmt_lowPowerSleep_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3214 | |
jhbr | 0:d3f5fdf2e6da | 3215 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3216 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3217 | |
jhbr | 0:d3f5fdf2e6da | 3218 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3219 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3220 | |
jhbr | 0:d3f5fdf2e6da | 3221 | } |
jhbr | 0:d3f5fdf2e6da | 3222 | |
jhbr | 0:d3f5fdf2e6da | 3223 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3224 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3225 | |
jhbr | 0:d3f5fdf2e6da | 3226 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3227 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3228 | } |
jhbr | 0:d3f5fdf2e6da | 3229 | |
jhbr | 0:d3f5fdf2e6da | 3230 | //===== testRadioRx |
jhbr | 0:d3f5fdf2e6da | 3231 | |
jhbr | 0:d3f5fdf2e6da | 3232 | /** |
jhbr | 0:d3f5fdf2e6da | 3233 | The testRadioRx command clears all previously collected statistics and |
jhbr | 0:d3f5fdf2e6da | 3234 | initiates a test of radio reception for the specified channel and duration. |
jhbr | 0:d3f5fdf2e6da | 3235 | During the test, the mote keeps statistics about the number of packets received |
jhbr | 0:d3f5fdf2e6da | 3236 | (with and without error). The test results may be retrieved using the |
jhbr | 0:d3f5fdf2e6da | 3237 | getParameter<testRadioRxStats> command. The testRadioRx command may only be |
jhbr | 0:d3f5fdf2e6da | 3238 | issued in Idle mode. The mote must be reset (either hardware or software reset) |
jhbr | 0:d3f5fdf2e6da | 3239 | after radio tests are complete and prior to joining. |
jhbr | 0:d3f5fdf2e6da | 3240 | |
jhbr | 0:d3f5fdf2e6da | 3241 | Station ID is available in IP mote >= 1.4, and WirelessHART mote >= 1.1.2. The |
jhbr | 0:d3f5fdf2e6da | 3242 | station ID is a user selectable value used to isolate traffic if multiple tests |
jhbr | 0:d3f5fdf2e6da | 3243 | are running in the same radio space. It must be set to match the station ID |
jhbr | 0:d3f5fdf2e6da | 3244 | used by the transmitter. |
jhbr | 0:d3f5fdf2e6da | 3245 | |
jhbr | 0:d3f5fdf2e6da | 3246 | |
jhbr | 0:d3f5fdf2e6da | 3247 | |
jhbr | 0:d3f5fdf2e6da | 3248 | Channel numbering is 0-15, corresponding to IEEE 2.4 GHz channels 11-26. |
jhbr | 0:d3f5fdf2e6da | 3249 | */ |
jhbr | 0:d3f5fdf2e6da | 3250 | dn_err_t dn_ipmt_testRadioRx(uint16_t channelMask, uint16_t time, uint8_t stationId, dn_ipmt_testRadioRx_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3251 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3252 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3253 | |
jhbr | 0:d3f5fdf2e6da | 3254 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3255 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3256 | |
jhbr | 0:d3f5fdf2e6da | 3257 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3258 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3259 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3260 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3261 | |
jhbr | 0:d3f5fdf2e6da | 3262 | // return |
jhbr | 0:d3f5fdf2e6da | 3263 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3264 | } |
jhbr | 0:d3f5fdf2e6da | 3265 | |
jhbr | 0:d3f5fdf2e6da | 3266 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3267 | dn_ipmt_vars.cmdId = CMDID_TESTRADIORX; |
jhbr | 0:d3f5fdf2e6da | 3268 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3269 | |
jhbr | 0:d3f5fdf2e6da | 3270 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3271 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3272 | |
jhbr | 0:d3f5fdf2e6da | 3273 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3274 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIORX_REQ_OFFS_CHANNELMASK],channelMask); |
jhbr | 0:d3f5fdf2e6da | 3275 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIORX_REQ_OFFS_TIME],time); |
jhbr | 0:d3f5fdf2e6da | 3276 | dn_ipmt_vars.outputBuf[DN_TESTRADIORX_REQ_OFFS_STATIONID] = stationId; |
jhbr | 0:d3f5fdf2e6da | 3277 | |
jhbr | 0:d3f5fdf2e6da | 3278 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3279 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3280 | CMDID_TESTRADIORX, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3281 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3282 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3283 | DN_TESTRADIORX_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3284 | dn_ipmt_testRadioRx_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3285 | ); |
jhbr | 0:d3f5fdf2e6da | 3286 | |
jhbr | 0:d3f5fdf2e6da | 3287 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3288 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3289 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3290 | } |
jhbr | 0:d3f5fdf2e6da | 3291 | |
jhbr | 0:d3f5fdf2e6da | 3292 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3293 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3294 | |
jhbr | 0:d3f5fdf2e6da | 3295 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3296 | |
jhbr | 0:d3f5fdf2e6da | 3297 | } |
jhbr | 0:d3f5fdf2e6da | 3298 | |
jhbr | 0:d3f5fdf2e6da | 3299 | void dn_ipmt_testRadioRx_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3300 | dn_ipmt_testRadioRx_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3301 | |
jhbr | 0:d3f5fdf2e6da | 3302 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3303 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3304 | return; |
jhbr | 0:d3f5fdf2e6da | 3305 | } |
jhbr | 0:d3f5fdf2e6da | 3306 | |
jhbr | 0:d3f5fdf2e6da | 3307 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3308 | |
jhbr | 0:d3f5fdf2e6da | 3309 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3310 | reply = (dn_ipmt_testRadioRx_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3311 | |
jhbr | 0:d3f5fdf2e6da | 3312 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3313 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3314 | |
jhbr | 0:d3f5fdf2e6da | 3315 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3316 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3317 | |
jhbr | 0:d3f5fdf2e6da | 3318 | } |
jhbr | 0:d3f5fdf2e6da | 3319 | |
jhbr | 0:d3f5fdf2e6da | 3320 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3321 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3322 | |
jhbr | 0:d3f5fdf2e6da | 3323 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3324 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3325 | } |
jhbr | 0:d3f5fdf2e6da | 3326 | |
jhbr | 0:d3f5fdf2e6da | 3327 | //===== clearNV |
jhbr | 0:d3f5fdf2e6da | 3328 | |
jhbr | 0:d3f5fdf2e6da | 3329 | /** |
jhbr | 0:d3f5fdf2e6da | 3330 | The clearNV command resets the motes non-volatile memory (NV) to its |
jhbr | 0:d3f5fdf2e6da | 3331 | factory-default state. See User Guide for detailed information about the |
jhbr | 0:d3f5fdf2e6da | 3332 | default values. Since many parameters are read by the mote only at power-up, |
jhbr | 0:d3f5fdf2e6da | 3333 | this command should be followed up by mote reset. |
jhbr | 0:d3f5fdf2e6da | 3334 | */ |
jhbr | 0:d3f5fdf2e6da | 3335 | dn_err_t dn_ipmt_clearNV(dn_ipmt_clearNV_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3336 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3337 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3338 | |
jhbr | 0:d3f5fdf2e6da | 3339 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3340 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3341 | |
jhbr | 0:d3f5fdf2e6da | 3342 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3343 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3344 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3345 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3346 | |
jhbr | 0:d3f5fdf2e6da | 3347 | // return |
jhbr | 0:d3f5fdf2e6da | 3348 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3349 | } |
jhbr | 0:d3f5fdf2e6da | 3350 | |
jhbr | 0:d3f5fdf2e6da | 3351 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3352 | dn_ipmt_vars.cmdId = CMDID_CLEARNV; |
jhbr | 0:d3f5fdf2e6da | 3353 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3354 | |
jhbr | 0:d3f5fdf2e6da | 3355 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3356 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3357 | |
jhbr | 0:d3f5fdf2e6da | 3358 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3359 | |
jhbr | 0:d3f5fdf2e6da | 3360 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3361 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3362 | CMDID_CLEARNV, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3363 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3364 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3365 | DN_CLEARNV_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3366 | dn_ipmt_clearNV_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3367 | ); |
jhbr | 0:d3f5fdf2e6da | 3368 | |
jhbr | 0:d3f5fdf2e6da | 3369 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3370 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3371 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3372 | } |
jhbr | 0:d3f5fdf2e6da | 3373 | |
jhbr | 0:d3f5fdf2e6da | 3374 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3375 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3376 | |
jhbr | 0:d3f5fdf2e6da | 3377 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3378 | |
jhbr | 0:d3f5fdf2e6da | 3379 | } |
jhbr | 0:d3f5fdf2e6da | 3380 | |
jhbr | 0:d3f5fdf2e6da | 3381 | void dn_ipmt_clearNV_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3382 | dn_ipmt_clearNV_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3383 | |
jhbr | 0:d3f5fdf2e6da | 3384 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3385 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3386 | return; |
jhbr | 0:d3f5fdf2e6da | 3387 | } |
jhbr | 0:d3f5fdf2e6da | 3388 | |
jhbr | 0:d3f5fdf2e6da | 3389 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3390 | |
jhbr | 0:d3f5fdf2e6da | 3391 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3392 | reply = (dn_ipmt_clearNV_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3393 | |
jhbr | 0:d3f5fdf2e6da | 3394 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3395 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3396 | |
jhbr | 0:d3f5fdf2e6da | 3397 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3398 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3399 | |
jhbr | 0:d3f5fdf2e6da | 3400 | } |
jhbr | 0:d3f5fdf2e6da | 3401 | |
jhbr | 0:d3f5fdf2e6da | 3402 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3403 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3404 | |
jhbr | 0:d3f5fdf2e6da | 3405 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3406 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3407 | } |
jhbr | 0:d3f5fdf2e6da | 3408 | |
jhbr | 0:d3f5fdf2e6da | 3409 | //===== requestService |
jhbr | 0:d3f5fdf2e6da | 3410 | |
jhbr | 0:d3f5fdf2e6da | 3411 | /** |
jhbr | 0:d3f5fdf2e6da | 3412 | The requestService command may be used to request a new or changed service |
jhbr | 0:d3f5fdf2e6da | 3413 | level to a destination device in the mesh. This command may only be used to |
jhbr | 0:d3f5fdf2e6da | 3414 | update the service to a device with an existing connection (session). |
jhbr | 0:d3f5fdf2e6da | 3415 | |
jhbr | 0:d3f5fdf2e6da | 3416 | Whenever a change in bandwidth assignment occurs, the application receives a |
jhbr | 0:d3f5fdf2e6da | 3417 | serviceChanged event that it can use as a trigger to read the new service |
jhbr | 0:d3f5fdf2e6da | 3418 | allocation. |
jhbr | 0:d3f5fdf2e6da | 3419 | */ |
jhbr | 0:d3f5fdf2e6da | 3420 | dn_err_t dn_ipmt_requestService(uint16_t destAddr, uint8_t serviceType, uint32_t value, dn_ipmt_requestService_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3421 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3422 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3423 | |
jhbr | 0:d3f5fdf2e6da | 3424 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3425 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3426 | |
jhbr | 0:d3f5fdf2e6da | 3427 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3428 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3429 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3430 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3431 | |
jhbr | 0:d3f5fdf2e6da | 3432 | // return |
jhbr | 0:d3f5fdf2e6da | 3433 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3434 | } |
jhbr | 0:d3f5fdf2e6da | 3435 | |
jhbr | 0:d3f5fdf2e6da | 3436 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3437 | dn_ipmt_vars.cmdId = CMDID_REQUESTSERVICE; |
jhbr | 0:d3f5fdf2e6da | 3438 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3439 | |
jhbr | 0:d3f5fdf2e6da | 3440 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3441 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3442 | |
jhbr | 0:d3f5fdf2e6da | 3443 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3444 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_REQUESTSERVICE_REQ_OFFS_DESTADDR],destAddr); |
jhbr | 0:d3f5fdf2e6da | 3445 | dn_ipmt_vars.outputBuf[DN_REQUESTSERVICE_REQ_OFFS_SERVICETYPE] = serviceType; |
jhbr | 0:d3f5fdf2e6da | 3446 | dn_write_uint32_t(&dn_ipmt_vars.outputBuf[DN_REQUESTSERVICE_REQ_OFFS_VALUE],value); |
jhbr | 0:d3f5fdf2e6da | 3447 | |
jhbr | 0:d3f5fdf2e6da | 3448 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3449 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3450 | CMDID_REQUESTSERVICE, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3451 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3452 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3453 | DN_REQUESTSERVICE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3454 | dn_ipmt_requestService_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3455 | ); |
jhbr | 0:d3f5fdf2e6da | 3456 | |
jhbr | 0:d3f5fdf2e6da | 3457 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3458 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3459 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3460 | } |
jhbr | 0:d3f5fdf2e6da | 3461 | |
jhbr | 0:d3f5fdf2e6da | 3462 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3463 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3464 | |
jhbr | 0:d3f5fdf2e6da | 3465 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3466 | |
jhbr | 0:d3f5fdf2e6da | 3467 | } |
jhbr | 0:d3f5fdf2e6da | 3468 | |
jhbr | 0:d3f5fdf2e6da | 3469 | void dn_ipmt_requestService_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3470 | dn_ipmt_requestService_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3471 | |
jhbr | 0:d3f5fdf2e6da | 3472 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3473 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3474 | return; |
jhbr | 0:d3f5fdf2e6da | 3475 | } |
jhbr | 0:d3f5fdf2e6da | 3476 | |
jhbr | 0:d3f5fdf2e6da | 3477 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3478 | |
jhbr | 0:d3f5fdf2e6da | 3479 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3480 | reply = (dn_ipmt_requestService_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3481 | |
jhbr | 0:d3f5fdf2e6da | 3482 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3483 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3484 | |
jhbr | 0:d3f5fdf2e6da | 3485 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3486 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3487 | |
jhbr | 0:d3f5fdf2e6da | 3488 | } |
jhbr | 0:d3f5fdf2e6da | 3489 | |
jhbr | 0:d3f5fdf2e6da | 3490 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3491 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3492 | |
jhbr | 0:d3f5fdf2e6da | 3493 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3494 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3495 | } |
jhbr | 0:d3f5fdf2e6da | 3496 | |
jhbr | 0:d3f5fdf2e6da | 3497 | //===== getServiceInfo |
jhbr | 0:d3f5fdf2e6da | 3498 | |
jhbr | 0:d3f5fdf2e6da | 3499 | /** |
jhbr | 0:d3f5fdf2e6da | 3500 | The getServiceInfo command returns information about the service currently |
jhbr | 0:d3f5fdf2e6da | 3501 | allocated to the mote. |
jhbr | 0:d3f5fdf2e6da | 3502 | */ |
jhbr | 0:d3f5fdf2e6da | 3503 | dn_err_t dn_ipmt_getServiceInfo(uint16_t destAddr, uint8_t type, dn_ipmt_getServiceInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3504 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3505 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3506 | |
jhbr | 0:d3f5fdf2e6da | 3507 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3508 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3509 | |
jhbr | 0:d3f5fdf2e6da | 3510 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3511 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3512 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3513 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3514 | |
jhbr | 0:d3f5fdf2e6da | 3515 | // return |
jhbr | 0:d3f5fdf2e6da | 3516 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3517 | } |
jhbr | 0:d3f5fdf2e6da | 3518 | |
jhbr | 0:d3f5fdf2e6da | 3519 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3520 | dn_ipmt_vars.cmdId = CMDID_GETSERVICEINFO; |
jhbr | 0:d3f5fdf2e6da | 3521 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3522 | |
jhbr | 0:d3f5fdf2e6da | 3523 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3524 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3525 | |
jhbr | 0:d3f5fdf2e6da | 3526 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3527 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_GETSERVICEINFO_REQ_OFFS_DESTADDR],destAddr); |
jhbr | 0:d3f5fdf2e6da | 3528 | dn_ipmt_vars.outputBuf[DN_GETSERVICEINFO_REQ_OFFS_TYPE] = type; |
jhbr | 0:d3f5fdf2e6da | 3529 | |
jhbr | 0:d3f5fdf2e6da | 3530 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3531 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3532 | CMDID_GETSERVICEINFO, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3533 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3534 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3535 | DN_GETSERVICEINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3536 | dn_ipmt_getServiceInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3537 | ); |
jhbr | 0:d3f5fdf2e6da | 3538 | |
jhbr | 0:d3f5fdf2e6da | 3539 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3540 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3541 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3542 | } |
jhbr | 0:d3f5fdf2e6da | 3543 | |
jhbr | 0:d3f5fdf2e6da | 3544 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3545 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3546 | |
jhbr | 0:d3f5fdf2e6da | 3547 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3548 | |
jhbr | 0:d3f5fdf2e6da | 3549 | } |
jhbr | 0:d3f5fdf2e6da | 3550 | |
jhbr | 0:d3f5fdf2e6da | 3551 | void dn_ipmt_getServiceInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3552 | dn_ipmt_getServiceInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3553 | |
jhbr | 0:d3f5fdf2e6da | 3554 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3555 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3556 | return; |
jhbr | 0:d3f5fdf2e6da | 3557 | } |
jhbr | 0:d3f5fdf2e6da | 3558 | |
jhbr | 0:d3f5fdf2e6da | 3559 | // verify length |
jhbr | 0:d3f5fdf2e6da | 3560 | if (rc==DN_SERIAL_RC_OK && len<DN_GETSERVICEINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 3561 | return; |
jhbr | 0:d3f5fdf2e6da | 3562 | } |
jhbr | 0:d3f5fdf2e6da | 3563 | |
jhbr | 0:d3f5fdf2e6da | 3564 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3565 | reply = (dn_ipmt_getServiceInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3566 | |
jhbr | 0:d3f5fdf2e6da | 3567 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3568 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3569 | |
jhbr | 0:d3f5fdf2e6da | 3570 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3571 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3572 | |
jhbr | 0:d3f5fdf2e6da | 3573 | dn_read_uint16_t(&reply->destAddr,&payload[DN_GETSERVICEINFO_REPLY_OFFS_DESTADDR]); |
jhbr | 0:d3f5fdf2e6da | 3574 | reply->type = payload[DN_GETSERVICEINFO_REPLY_OFFS_TYPE]; |
jhbr | 0:d3f5fdf2e6da | 3575 | reply->state = payload[DN_GETSERVICEINFO_REPLY_OFFS_STATE]; |
jhbr | 0:d3f5fdf2e6da | 3576 | dn_read_uint32_t(&reply->value,&payload[DN_GETSERVICEINFO_REPLY_OFFS_VALUE]); |
jhbr | 0:d3f5fdf2e6da | 3577 | } |
jhbr | 0:d3f5fdf2e6da | 3578 | |
jhbr | 0:d3f5fdf2e6da | 3579 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3580 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3581 | |
jhbr | 0:d3f5fdf2e6da | 3582 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3583 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3584 | } |
jhbr | 0:d3f5fdf2e6da | 3585 | |
jhbr | 0:d3f5fdf2e6da | 3586 | //===== openSocket |
jhbr | 0:d3f5fdf2e6da | 3587 | |
jhbr | 0:d3f5fdf2e6da | 3588 | /** |
jhbr | 0:d3f5fdf2e6da | 3589 | The openSocket command creates an endpoint for IP communication and returns an |
jhbr | 0:d3f5fdf2e6da | 3590 | ID for the socket. |
jhbr | 0:d3f5fdf2e6da | 3591 | */ |
jhbr | 0:d3f5fdf2e6da | 3592 | dn_err_t dn_ipmt_openSocket(uint8_t protocol, dn_ipmt_openSocket_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3593 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3594 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3595 | |
jhbr | 0:d3f5fdf2e6da | 3596 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3597 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3598 | |
jhbr | 0:d3f5fdf2e6da | 3599 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3600 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3601 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3602 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3603 | |
jhbr | 0:d3f5fdf2e6da | 3604 | // return |
jhbr | 0:d3f5fdf2e6da | 3605 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3606 | } |
jhbr | 0:d3f5fdf2e6da | 3607 | |
jhbr | 0:d3f5fdf2e6da | 3608 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3609 | dn_ipmt_vars.cmdId = CMDID_OPENSOCKET; |
jhbr | 0:d3f5fdf2e6da | 3610 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3611 | |
jhbr | 0:d3f5fdf2e6da | 3612 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3613 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3614 | |
jhbr | 0:d3f5fdf2e6da | 3615 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3616 | dn_ipmt_vars.outputBuf[DN_OPENSOCKET_REQ_OFFS_PROTOCOL] = protocol; |
jhbr | 0:d3f5fdf2e6da | 3617 | |
jhbr | 0:d3f5fdf2e6da | 3618 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3619 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3620 | CMDID_OPENSOCKET, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3621 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3622 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3623 | DN_OPENSOCKET_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3624 | dn_ipmt_openSocket_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3625 | ); |
jhbr | 0:d3f5fdf2e6da | 3626 | |
jhbr | 0:d3f5fdf2e6da | 3627 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3628 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3629 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3630 | } |
jhbr | 0:d3f5fdf2e6da | 3631 | |
jhbr | 0:d3f5fdf2e6da | 3632 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3633 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3634 | |
jhbr | 0:d3f5fdf2e6da | 3635 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3636 | |
jhbr | 0:d3f5fdf2e6da | 3637 | } |
jhbr | 0:d3f5fdf2e6da | 3638 | |
jhbr | 0:d3f5fdf2e6da | 3639 | void dn_ipmt_openSocket_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3640 | dn_ipmt_openSocket_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3641 | |
jhbr | 0:d3f5fdf2e6da | 3642 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3643 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3644 | return; |
jhbr | 0:d3f5fdf2e6da | 3645 | } |
jhbr | 0:d3f5fdf2e6da | 3646 | |
jhbr | 0:d3f5fdf2e6da | 3647 | // verify length |
jhbr | 0:d3f5fdf2e6da | 3648 | if (rc==DN_SERIAL_RC_OK && len<DN_OPENSOCKET_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 3649 | return; |
jhbr | 0:d3f5fdf2e6da | 3650 | } |
jhbr | 0:d3f5fdf2e6da | 3651 | |
jhbr | 0:d3f5fdf2e6da | 3652 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3653 | reply = (dn_ipmt_openSocket_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3654 | |
jhbr | 0:d3f5fdf2e6da | 3655 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3656 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3657 | |
jhbr | 0:d3f5fdf2e6da | 3658 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3659 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3660 | |
jhbr | 0:d3f5fdf2e6da | 3661 | reply->socketId = payload[DN_OPENSOCKET_REPLY_OFFS_SOCKETID]; |
jhbr | 0:d3f5fdf2e6da | 3662 | } |
jhbr | 0:d3f5fdf2e6da | 3663 | |
jhbr | 0:d3f5fdf2e6da | 3664 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3665 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3666 | |
jhbr | 0:d3f5fdf2e6da | 3667 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3668 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3669 | } |
jhbr | 0:d3f5fdf2e6da | 3670 | |
jhbr | 0:d3f5fdf2e6da | 3671 | //===== closeSocket |
jhbr | 0:d3f5fdf2e6da | 3672 | |
jhbr | 0:d3f5fdf2e6da | 3673 | /** |
jhbr | 0:d3f5fdf2e6da | 3674 | Close the previously open socket. |
jhbr | 0:d3f5fdf2e6da | 3675 | */ |
jhbr | 0:d3f5fdf2e6da | 3676 | dn_err_t dn_ipmt_closeSocket(uint8_t socketId, dn_ipmt_closeSocket_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3677 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3678 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3679 | |
jhbr | 0:d3f5fdf2e6da | 3680 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3681 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3682 | |
jhbr | 0:d3f5fdf2e6da | 3683 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3684 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3685 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3686 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3687 | |
jhbr | 0:d3f5fdf2e6da | 3688 | // return |
jhbr | 0:d3f5fdf2e6da | 3689 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3690 | } |
jhbr | 0:d3f5fdf2e6da | 3691 | |
jhbr | 0:d3f5fdf2e6da | 3692 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3693 | dn_ipmt_vars.cmdId = CMDID_CLOSESOCKET; |
jhbr | 0:d3f5fdf2e6da | 3694 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3695 | |
jhbr | 0:d3f5fdf2e6da | 3696 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3697 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3698 | |
jhbr | 0:d3f5fdf2e6da | 3699 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3700 | dn_ipmt_vars.outputBuf[DN_CLOSESOCKET_REQ_OFFS_SOCKETID] = socketId; |
jhbr | 0:d3f5fdf2e6da | 3701 | |
jhbr | 0:d3f5fdf2e6da | 3702 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3703 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3704 | CMDID_CLOSESOCKET, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3705 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3706 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3707 | DN_CLOSESOCKET_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3708 | dn_ipmt_closeSocket_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3709 | ); |
jhbr | 0:d3f5fdf2e6da | 3710 | |
jhbr | 0:d3f5fdf2e6da | 3711 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3712 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3713 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3714 | } |
jhbr | 0:d3f5fdf2e6da | 3715 | |
jhbr | 0:d3f5fdf2e6da | 3716 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3717 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3718 | |
jhbr | 0:d3f5fdf2e6da | 3719 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3720 | |
jhbr | 0:d3f5fdf2e6da | 3721 | } |
jhbr | 0:d3f5fdf2e6da | 3722 | |
jhbr | 0:d3f5fdf2e6da | 3723 | void dn_ipmt_closeSocket_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3724 | dn_ipmt_closeSocket_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3725 | |
jhbr | 0:d3f5fdf2e6da | 3726 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3727 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3728 | return; |
jhbr | 0:d3f5fdf2e6da | 3729 | } |
jhbr | 0:d3f5fdf2e6da | 3730 | |
jhbr | 0:d3f5fdf2e6da | 3731 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3732 | |
jhbr | 0:d3f5fdf2e6da | 3733 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3734 | reply = (dn_ipmt_closeSocket_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3735 | |
jhbr | 0:d3f5fdf2e6da | 3736 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3737 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3738 | |
jhbr | 0:d3f5fdf2e6da | 3739 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3740 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3741 | |
jhbr | 0:d3f5fdf2e6da | 3742 | } |
jhbr | 0:d3f5fdf2e6da | 3743 | |
jhbr | 0:d3f5fdf2e6da | 3744 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3745 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3746 | |
jhbr | 0:d3f5fdf2e6da | 3747 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3748 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3749 | } |
jhbr | 0:d3f5fdf2e6da | 3750 | |
jhbr | 0:d3f5fdf2e6da | 3751 | //===== bindSocket |
jhbr | 0:d3f5fdf2e6da | 3752 | |
jhbr | 0:d3f5fdf2e6da | 3753 | /** |
jhbr | 0:d3f5fdf2e6da | 3754 | Bind a previously opened socket to a port. When a socket is created, it is only |
jhbr | 0:d3f5fdf2e6da | 3755 | given a protocol family, but not assigned a port. This association must be |
jhbr | 0:d3f5fdf2e6da | 3756 | performed before the socket can accept connections from other hosts. |
jhbr | 0:d3f5fdf2e6da | 3757 | */ |
jhbr | 0:d3f5fdf2e6da | 3758 | dn_err_t dn_ipmt_bindSocket(uint8_t socketId, uint16_t port, dn_ipmt_bindSocket_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3759 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3760 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3761 | |
jhbr | 0:d3f5fdf2e6da | 3762 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3763 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3764 | |
jhbr | 0:d3f5fdf2e6da | 3765 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3766 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3767 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3768 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3769 | |
jhbr | 0:d3f5fdf2e6da | 3770 | // return |
jhbr | 0:d3f5fdf2e6da | 3771 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3772 | } |
jhbr | 0:d3f5fdf2e6da | 3773 | |
jhbr | 0:d3f5fdf2e6da | 3774 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3775 | dn_ipmt_vars.cmdId = CMDID_BINDSOCKET; |
jhbr | 0:d3f5fdf2e6da | 3776 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3777 | |
jhbr | 0:d3f5fdf2e6da | 3778 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3779 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3780 | |
jhbr | 0:d3f5fdf2e6da | 3781 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3782 | dn_ipmt_vars.outputBuf[DN_BINDSOCKET_REQ_OFFS_SOCKETID] = socketId; |
jhbr | 0:d3f5fdf2e6da | 3783 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_BINDSOCKET_REQ_OFFS_PORT],port); |
jhbr | 0:d3f5fdf2e6da | 3784 | |
jhbr | 0:d3f5fdf2e6da | 3785 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3786 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3787 | CMDID_BINDSOCKET, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3788 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3789 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3790 | DN_BINDSOCKET_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3791 | dn_ipmt_bindSocket_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3792 | ); |
jhbr | 0:d3f5fdf2e6da | 3793 | |
jhbr | 0:d3f5fdf2e6da | 3794 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3795 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3796 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3797 | } |
jhbr | 0:d3f5fdf2e6da | 3798 | |
jhbr | 0:d3f5fdf2e6da | 3799 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3800 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3801 | |
jhbr | 0:d3f5fdf2e6da | 3802 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3803 | |
jhbr | 0:d3f5fdf2e6da | 3804 | } |
jhbr | 0:d3f5fdf2e6da | 3805 | |
jhbr | 0:d3f5fdf2e6da | 3806 | void dn_ipmt_bindSocket_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3807 | dn_ipmt_bindSocket_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3808 | |
jhbr | 0:d3f5fdf2e6da | 3809 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3810 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3811 | return; |
jhbr | 0:d3f5fdf2e6da | 3812 | } |
jhbr | 0:d3f5fdf2e6da | 3813 | |
jhbr | 0:d3f5fdf2e6da | 3814 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3815 | |
jhbr | 0:d3f5fdf2e6da | 3816 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3817 | reply = (dn_ipmt_bindSocket_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3818 | |
jhbr | 0:d3f5fdf2e6da | 3819 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3820 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3821 | |
jhbr | 0:d3f5fdf2e6da | 3822 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3823 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3824 | |
jhbr | 0:d3f5fdf2e6da | 3825 | } |
jhbr | 0:d3f5fdf2e6da | 3826 | |
jhbr | 0:d3f5fdf2e6da | 3827 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3828 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3829 | |
jhbr | 0:d3f5fdf2e6da | 3830 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3831 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3832 | } |
jhbr | 0:d3f5fdf2e6da | 3833 | |
jhbr | 0:d3f5fdf2e6da | 3834 | //===== sendTo |
jhbr | 0:d3f5fdf2e6da | 3835 | |
jhbr | 0:d3f5fdf2e6da | 3836 | /** |
jhbr | 0:d3f5fdf2e6da | 3837 | Send a packet into the network. If the command returns RC_OK, the mote has |
jhbr | 0:d3f5fdf2e6da | 3838 | accepted the packet and hasqueuedit up for transmission. A txDone notification |
jhbr | 0:d3f5fdf2e6da | 3839 | will be issued when the packet has been sent, if and only if the packet ID |
jhbr | 0:d3f5fdf2e6da | 3840 | passed in this command is different from 0xffff. You can set the packet ID to |
jhbr | 0:d3f5fdf2e6da | 3841 | any value. The notification will contain the packet ID of the packet just sent, |
jhbr | 0:d3f5fdf2e6da | 3842 | allowing association of the notification with a particular packet. The |
jhbr | 0:d3f5fdf2e6da | 3843 | destination port should be in the range 0xF0B8-F0BF (61624-61631) to maximize |
jhbr | 0:d3f5fdf2e6da | 3844 | payload. |
jhbr | 0:d3f5fdf2e6da | 3845 | */ |
jhbr | 0:d3f5fdf2e6da | 3846 | dn_err_t dn_ipmt_sendTo(uint8_t socketId, uint8_t* destIP, uint16_t destPort, uint8_t serviceType, uint8_t priority, uint16_t packetId, uint8_t* payload, uint8_t payloadLen, dn_ipmt_sendTo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3847 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3848 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3849 | |
jhbr | 0:d3f5fdf2e6da | 3850 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3851 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3852 | |
jhbr | 0:d3f5fdf2e6da | 3853 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3854 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3855 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3856 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3857 | |
jhbr | 0:d3f5fdf2e6da | 3858 | // return |
jhbr | 0:d3f5fdf2e6da | 3859 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3860 | } |
jhbr | 0:d3f5fdf2e6da | 3861 | |
jhbr | 0:d3f5fdf2e6da | 3862 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3863 | dn_ipmt_vars.cmdId = CMDID_SENDTO; |
jhbr | 0:d3f5fdf2e6da | 3864 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3865 | |
jhbr | 0:d3f5fdf2e6da | 3866 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3867 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3868 | |
jhbr | 0:d3f5fdf2e6da | 3869 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3870 | dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_SOCKETID] = socketId; |
jhbr | 0:d3f5fdf2e6da | 3871 | memcpy(&dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_DESTIP],destIP,16); |
jhbr | 0:d3f5fdf2e6da | 3872 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_DESTPORT],destPort); |
jhbr | 0:d3f5fdf2e6da | 3873 | dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_SERVICETYPE] = serviceType; |
jhbr | 0:d3f5fdf2e6da | 3874 | dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_PRIORITY] = priority; |
jhbr | 0:d3f5fdf2e6da | 3875 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_PACKETID],packetId); |
jhbr | 0:d3f5fdf2e6da | 3876 | memcpy(&dn_ipmt_vars.outputBuf[DN_SENDTO_REQ_OFFS_PAYLOAD],payload,payloadLen); |
jhbr | 0:d3f5fdf2e6da | 3877 | |
jhbr | 0:d3f5fdf2e6da | 3878 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3879 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3880 | CMDID_SENDTO, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3881 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3882 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3883 | DN_SENDTO_REQ_LEN+payloadLen, // length |
jhbr | 0:d3f5fdf2e6da | 3884 | dn_ipmt_sendTo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3885 | ); |
jhbr | 0:d3f5fdf2e6da | 3886 | |
jhbr | 0:d3f5fdf2e6da | 3887 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3888 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3889 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3890 | } |
jhbr | 0:d3f5fdf2e6da | 3891 | |
jhbr | 0:d3f5fdf2e6da | 3892 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3893 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3894 | |
jhbr | 0:d3f5fdf2e6da | 3895 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3896 | |
jhbr | 0:d3f5fdf2e6da | 3897 | } |
jhbr | 0:d3f5fdf2e6da | 3898 | |
jhbr | 0:d3f5fdf2e6da | 3899 | void dn_ipmt_sendTo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3900 | dn_ipmt_sendTo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3901 | |
jhbr | 0:d3f5fdf2e6da | 3902 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3903 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3904 | return; |
jhbr | 0:d3f5fdf2e6da | 3905 | } |
jhbr | 0:d3f5fdf2e6da | 3906 | |
jhbr | 0:d3f5fdf2e6da | 3907 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3908 | |
jhbr | 0:d3f5fdf2e6da | 3909 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3910 | reply = (dn_ipmt_sendTo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3911 | |
jhbr | 0:d3f5fdf2e6da | 3912 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3913 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3914 | |
jhbr | 0:d3f5fdf2e6da | 3915 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3916 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 3917 | |
jhbr | 0:d3f5fdf2e6da | 3918 | } |
jhbr | 0:d3f5fdf2e6da | 3919 | |
jhbr | 0:d3f5fdf2e6da | 3920 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 3921 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 3922 | |
jhbr | 0:d3f5fdf2e6da | 3923 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 3924 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 3925 | } |
jhbr | 0:d3f5fdf2e6da | 3926 | |
jhbr | 0:d3f5fdf2e6da | 3927 | //===== search |
jhbr | 0:d3f5fdf2e6da | 3928 | |
jhbr | 0:d3f5fdf2e6da | 3929 | /** |
jhbr | 0:d3f5fdf2e6da | 3930 | The search command requests that mote start listening for advertisements and |
jhbr | 0:d3f5fdf2e6da | 3931 | report those heard from any network withoutattempting to join. This is called |
jhbr | 0:d3f5fdf2e6da | 3932 | the Promiscuous Listen state. The mote must be in the Idle state for this |
jhbr | 0:d3f5fdf2e6da | 3933 | command to be valid. The search state can be exited by issuing the join command |
jhbr | 0:d3f5fdf2e6da | 3934 | or the reset command. |
jhbr | 0:d3f5fdf2e6da | 3935 | */ |
jhbr | 0:d3f5fdf2e6da | 3936 | dn_err_t dn_ipmt_search(dn_ipmt_search_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 3937 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 3938 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 3939 | |
jhbr | 0:d3f5fdf2e6da | 3940 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 3941 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 3942 | |
jhbr | 0:d3f5fdf2e6da | 3943 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 3944 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 3945 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3946 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3947 | |
jhbr | 0:d3f5fdf2e6da | 3948 | // return |
jhbr | 0:d3f5fdf2e6da | 3949 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 3950 | } |
jhbr | 0:d3f5fdf2e6da | 3951 | |
jhbr | 0:d3f5fdf2e6da | 3952 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 3953 | dn_ipmt_vars.cmdId = CMDID_SEARCH; |
jhbr | 0:d3f5fdf2e6da | 3954 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 3955 | |
jhbr | 0:d3f5fdf2e6da | 3956 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3957 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 3958 | |
jhbr | 0:d3f5fdf2e6da | 3959 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 3960 | |
jhbr | 0:d3f5fdf2e6da | 3961 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 3962 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 3963 | CMDID_SEARCH, // cmdId |
jhbr | 0:d3f5fdf2e6da | 3964 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 3965 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 3966 | DN_SEARCH_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 3967 | dn_ipmt_search_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 3968 | ); |
jhbr | 0:d3f5fdf2e6da | 3969 | |
jhbr | 0:d3f5fdf2e6da | 3970 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 3971 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 3972 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 3973 | } |
jhbr | 0:d3f5fdf2e6da | 3974 | |
jhbr | 0:d3f5fdf2e6da | 3975 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 3976 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 3977 | |
jhbr | 0:d3f5fdf2e6da | 3978 | return rc; |
jhbr | 0:d3f5fdf2e6da | 3979 | |
jhbr | 0:d3f5fdf2e6da | 3980 | } |
jhbr | 0:d3f5fdf2e6da | 3981 | |
jhbr | 0:d3f5fdf2e6da | 3982 | void dn_ipmt_search_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 3983 | dn_ipmt_search_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 3984 | |
jhbr | 0:d3f5fdf2e6da | 3985 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 3986 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 3987 | return; |
jhbr | 0:d3f5fdf2e6da | 3988 | } |
jhbr | 0:d3f5fdf2e6da | 3989 | |
jhbr | 0:d3f5fdf2e6da | 3990 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 3991 | |
jhbr | 0:d3f5fdf2e6da | 3992 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 3993 | reply = (dn_ipmt_search_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 3994 | |
jhbr | 0:d3f5fdf2e6da | 3995 | // store RC |
jhbr | 0:d3f5fdf2e6da | 3996 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 3997 | |
jhbr | 0:d3f5fdf2e6da | 3998 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 3999 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 4000 | |
jhbr | 0:d3f5fdf2e6da | 4001 | } |
jhbr | 0:d3f5fdf2e6da | 4002 | |
jhbr | 0:d3f5fdf2e6da | 4003 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 4004 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 4005 | |
jhbr | 0:d3f5fdf2e6da | 4006 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 4007 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 4008 | } |
jhbr | 0:d3f5fdf2e6da | 4009 | |
jhbr | 0:d3f5fdf2e6da | 4010 | //===== testRadioTxExt |
jhbr | 0:d3f5fdf2e6da | 4011 | |
jhbr | 0:d3f5fdf2e6da | 4012 | /** |
jhbr | 0:d3f5fdf2e6da | 4013 | The testRadioTxExt command allows the microprocessor to initiate a radio |
jhbr | 0:d3f5fdf2e6da | 4014 | transmission test. This command may only be issued prior to the mote joining |
jhbr | 0:d3f5fdf2e6da | 4015 | the network. Three types of transmission tests are supported: |
jhbr | 0:d3f5fdf2e6da | 4016 | |
jhbr | 0:d3f5fdf2e6da | 4017 | - Packet transmission |
jhbr | 0:d3f5fdf2e6da | 4018 | - Continuous modulation |
jhbr | 0:d3f5fdf2e6da | 4019 | - Continuous wave (unmodulated signal) |
jhbr | 0:d3f5fdf2e6da | 4020 | |
jhbr | 0:d3f5fdf2e6da | 4021 | In a packet transmission test, the mote generates a repeatCnt number of packet |
jhbr | 0:d3f5fdf2e6da | 4022 | sequences. Each sequence consists of up to 10 packets with configurable size |
jhbr | 0:d3f5fdf2e6da | 4023 | and delays. Each packet starts with a PHY preamble (5 bytes), followed by a PHY |
jhbr | 0:d3f5fdf2e6da | 4024 | length field (1 byte), followed by data payload of up to 125 bytes, and finally |
jhbr | 0:d3f5fdf2e6da | 4025 | a 2-byte 802.15.4 CRC at the end. Byte 0 of the payload contains stationId of |
jhbr | 0:d3f5fdf2e6da | 4026 | the sender. Bytes 1 and 2 contain the packet number (in big-endian format) that |
jhbr | 0:d3f5fdf2e6da | 4027 | increments with every packet transmitted. Bytes 3..N contain a counter (from |
jhbr | 0:d3f5fdf2e6da | 4028 | 0..N-3) that increments with every byte inside payload. Transmissions occur on |
jhbr | 0:d3f5fdf2e6da | 4029 | the set of channels defined by chanMask , selected inpseudo-randomorder. |
jhbr | 0:d3f5fdf2e6da | 4030 | |
jhbr | 0:d3f5fdf2e6da | 4031 | In a continuous modulation test, the mote generates continuous pseudo-random |
jhbr | 0:d3f5fdf2e6da | 4032 | modulated signal, centered at the specified channel. The test is stopped by |
jhbr | 0:d3f5fdf2e6da | 4033 | resetting the mote. |
jhbr | 0:d3f5fdf2e6da | 4034 | |
jhbr | 0:d3f5fdf2e6da | 4035 | In a continuous wave test, the mote generates an unmodulated tone, centered at |
jhbr | 0:d3f5fdf2e6da | 4036 | the specified channel. The test tone is stopped by resetting the mote. |
jhbr | 0:d3f5fdf2e6da | 4037 | |
jhbr | 0:d3f5fdf2e6da | 4038 | The testRadioTxExt command may only be issued when the mote is in Idle mode, |
jhbr | 0:d3f5fdf2e6da | 4039 | prior to its joining the network. The mote must be reset (either hardware or |
jhbr | 0:d3f5fdf2e6da | 4040 | software reset) after radio tests are complete and prior to joining. |
jhbr | 0:d3f5fdf2e6da | 4041 | |
jhbr | 0:d3f5fdf2e6da | 4042 | The station ID is a user selectable value. It is used in packet tests so that a |
jhbr | 0:d3f5fdf2e6da | 4043 | receiver can identify packets from this device in cases where there may be |
jhbr | 0:d3f5fdf2e6da | 4044 | multiple tests running in the same radio space. This field is not used for CM |
jhbr | 0:d3f5fdf2e6da | 4045 | or CW tests. See testRadioRX (SmartMesh IP) or testRadioRxExt (SmartMesh WirelessHART). |
jhbr | 0:d3f5fdf2e6da | 4046 | |
jhbr | 0:d3f5fdf2e6da | 4047 | |
jhbr | 0:d3f5fdf2e6da | 4048 | |
jhbr | 0:d3f5fdf2e6da | 4049 | Channel numbering is 0-15, corresponding to IEEE 2.4 GHz channels 11-26. |
jhbr | 0:d3f5fdf2e6da | 4050 | */ |
jhbr | 0:d3f5fdf2e6da | 4051 | dn_err_t dn_ipmt_testRadioTxExt(uint8_t testType, uint16_t chanMask, uint16_t repeatCnt, int8_t txPower, uint8_t seqSize, uint8_t pkLen_1, uint16_t delay_1, uint8_t pkLen_2, uint16_t delay_2, uint8_t pkLen_3, uint16_t delay_3, uint8_t pkLen_4, uint16_t delay_4, uint8_t pkLen_5, uint16_t delay_5, uint8_t pkLen_6, uint16_t delay_6, uint8_t pkLen_7, uint16_t delay_7, uint8_t pkLen_8, uint16_t delay_8, uint8_t pkLen_9, uint16_t delay_9, uint8_t pkLen_10, uint16_t delay_10, uint8_t stationId, dn_ipmt_testRadioTxExt_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 4052 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 4053 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 4054 | |
jhbr | 0:d3f5fdf2e6da | 4055 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 4056 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 4057 | |
jhbr | 0:d3f5fdf2e6da | 4058 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 4059 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 4060 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 4061 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 4062 | |
jhbr | 0:d3f5fdf2e6da | 4063 | // return |
jhbr | 0:d3f5fdf2e6da | 4064 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 4065 | } |
jhbr | 0:d3f5fdf2e6da | 4066 | |
jhbr | 0:d3f5fdf2e6da | 4067 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 4068 | dn_ipmt_vars.cmdId = CMDID_TESTRADIOTXEXT; |
jhbr | 0:d3f5fdf2e6da | 4069 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 4070 | |
jhbr | 0:d3f5fdf2e6da | 4071 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 4072 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 4073 | |
jhbr | 0:d3f5fdf2e6da | 4074 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 4075 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_TESTTYPE] = testType; |
jhbr | 0:d3f5fdf2e6da | 4076 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_CHANMASK],chanMask); |
jhbr | 0:d3f5fdf2e6da | 4077 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_REPEATCNT],repeatCnt); |
jhbr | 0:d3f5fdf2e6da | 4078 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_TXPOWER] = (int8_t)txPower; |
jhbr | 0:d3f5fdf2e6da | 4079 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_SEQSIZE] = seqSize; |
jhbr | 0:d3f5fdf2e6da | 4080 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_1] = pkLen_1; |
jhbr | 0:d3f5fdf2e6da | 4081 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_1],delay_1); |
jhbr | 0:d3f5fdf2e6da | 4082 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_2] = pkLen_2; |
jhbr | 0:d3f5fdf2e6da | 4083 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_2],delay_2); |
jhbr | 0:d3f5fdf2e6da | 4084 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_3] = pkLen_3; |
jhbr | 0:d3f5fdf2e6da | 4085 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_3],delay_3); |
jhbr | 0:d3f5fdf2e6da | 4086 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_4] = pkLen_4; |
jhbr | 0:d3f5fdf2e6da | 4087 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_4],delay_4); |
jhbr | 0:d3f5fdf2e6da | 4088 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_5] = pkLen_5; |
jhbr | 0:d3f5fdf2e6da | 4089 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_5],delay_5); |
jhbr | 0:d3f5fdf2e6da | 4090 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_6] = pkLen_6; |
jhbr | 0:d3f5fdf2e6da | 4091 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_6],delay_6); |
jhbr | 0:d3f5fdf2e6da | 4092 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_7] = pkLen_7; |
jhbr | 0:d3f5fdf2e6da | 4093 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_7],delay_7); |
jhbr | 0:d3f5fdf2e6da | 4094 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_8] = pkLen_8; |
jhbr | 0:d3f5fdf2e6da | 4095 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_8],delay_8); |
jhbr | 0:d3f5fdf2e6da | 4096 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_9] = pkLen_9; |
jhbr | 0:d3f5fdf2e6da | 4097 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_9],delay_9); |
jhbr | 0:d3f5fdf2e6da | 4098 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_PKLEN_10] = pkLen_10; |
jhbr | 0:d3f5fdf2e6da | 4099 | dn_write_uint16_t(&dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_DELAY_10],delay_10); |
jhbr | 0:d3f5fdf2e6da | 4100 | dn_ipmt_vars.outputBuf[DN_TESTRADIOTXEXT_REQ_OFFS_STATIONID] = stationId; |
jhbr | 0:d3f5fdf2e6da | 4101 | |
jhbr | 0:d3f5fdf2e6da | 4102 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 4103 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 4104 | CMDID_TESTRADIOTXEXT, // cmdId |
jhbr | 0:d3f5fdf2e6da | 4105 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 4106 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 4107 | DN_TESTRADIOTXEXT_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 4108 | dn_ipmt_testRadioTxExt_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 4109 | ); |
jhbr | 0:d3f5fdf2e6da | 4110 | |
jhbr | 0:d3f5fdf2e6da | 4111 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 4112 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 4113 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 4114 | } |
jhbr | 0:d3f5fdf2e6da | 4115 | |
jhbr | 0:d3f5fdf2e6da | 4116 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 4117 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 4118 | |
jhbr | 0:d3f5fdf2e6da | 4119 | return rc; |
jhbr | 0:d3f5fdf2e6da | 4120 | |
jhbr | 0:d3f5fdf2e6da | 4121 | } |
jhbr | 0:d3f5fdf2e6da | 4122 | |
jhbr | 0:d3f5fdf2e6da | 4123 | void dn_ipmt_testRadioTxExt_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 4124 | dn_ipmt_testRadioTxExt_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 4125 | |
jhbr | 0:d3f5fdf2e6da | 4126 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 4127 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 4128 | return; |
jhbr | 0:d3f5fdf2e6da | 4129 | } |
jhbr | 0:d3f5fdf2e6da | 4130 | |
jhbr | 0:d3f5fdf2e6da | 4131 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 4132 | |
jhbr | 0:d3f5fdf2e6da | 4133 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 4134 | reply = (dn_ipmt_testRadioTxExt_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 4135 | |
jhbr | 0:d3f5fdf2e6da | 4136 | // store RC |
jhbr | 0:d3f5fdf2e6da | 4137 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 4138 | |
jhbr | 0:d3f5fdf2e6da | 4139 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 4140 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 4141 | |
jhbr | 0:d3f5fdf2e6da | 4142 | } |
jhbr | 0:d3f5fdf2e6da | 4143 | |
jhbr | 0:d3f5fdf2e6da | 4144 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 4145 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 4146 | |
jhbr | 0:d3f5fdf2e6da | 4147 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 4148 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 4149 | } |
jhbr | 0:d3f5fdf2e6da | 4150 | |
jhbr | 0:d3f5fdf2e6da | 4151 | //===== zeroize |
jhbr | 0:d3f5fdf2e6da | 4152 | |
jhbr | 0:d3f5fdf2e6da | 4153 | /** |
jhbr | 0:d3f5fdf2e6da | 4154 | Zeroize (zeroise) command erases flash area that is used to store configuration |
jhbr | 0:d3f5fdf2e6da | 4155 | parameters, such as join keys. This command is intended to satisfy zeroization |
jhbr | 0:d3f5fdf2e6da | 4156 | requirement of FIPS-140 standard. After the command executes, the mote should |
jhbr | 0:d3f5fdf2e6da | 4157 | be reset. Available in mote >= 1.4.x |
jhbr | 0:d3f5fdf2e6da | 4158 | |
jhbr | 0:d3f5fdf2e6da | 4159 | The zeroize command will render the mote inoperable. It must be re-programmed |
jhbr | 0:d3f5fdf2e6da | 4160 | via SPI or JTAG in order to be useable. |
jhbr | 0:d3f5fdf2e6da | 4161 | */ |
jhbr | 0:d3f5fdf2e6da | 4162 | dn_err_t dn_ipmt_zeroize(dn_ipmt_zeroize_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 4163 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 4164 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 4165 | |
jhbr | 0:d3f5fdf2e6da | 4166 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 4167 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 4168 | |
jhbr | 0:d3f5fdf2e6da | 4169 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 4170 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 4171 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 4172 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 4173 | |
jhbr | 0:d3f5fdf2e6da | 4174 | // return |
jhbr | 0:d3f5fdf2e6da | 4175 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 4176 | } |
jhbr | 0:d3f5fdf2e6da | 4177 | |
jhbr | 0:d3f5fdf2e6da | 4178 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 4179 | dn_ipmt_vars.cmdId = CMDID_ZEROIZE; |
jhbr | 0:d3f5fdf2e6da | 4180 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 4181 | |
jhbr | 0:d3f5fdf2e6da | 4182 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 4183 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 4184 | |
jhbr | 0:d3f5fdf2e6da | 4185 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 4186 | |
jhbr | 0:d3f5fdf2e6da | 4187 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 4188 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 4189 | CMDID_ZEROIZE, // cmdId |
jhbr | 0:d3f5fdf2e6da | 4190 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 4191 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 4192 | DN_ZEROIZE_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 4193 | dn_ipmt_zeroize_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 4194 | ); |
jhbr | 0:d3f5fdf2e6da | 4195 | |
jhbr | 0:d3f5fdf2e6da | 4196 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 4197 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 4198 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 4199 | } |
jhbr | 0:d3f5fdf2e6da | 4200 | |
jhbr | 0:d3f5fdf2e6da | 4201 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 4202 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 4203 | |
jhbr | 0:d3f5fdf2e6da | 4204 | return rc; |
jhbr | 0:d3f5fdf2e6da | 4205 | |
jhbr | 0:d3f5fdf2e6da | 4206 | } |
jhbr | 0:d3f5fdf2e6da | 4207 | |
jhbr | 0:d3f5fdf2e6da | 4208 | void dn_ipmt_zeroize_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 4209 | dn_ipmt_zeroize_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 4210 | |
jhbr | 0:d3f5fdf2e6da | 4211 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 4212 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 4213 | return; |
jhbr | 0:d3f5fdf2e6da | 4214 | } |
jhbr | 0:d3f5fdf2e6da | 4215 | |
jhbr | 0:d3f5fdf2e6da | 4216 | // do NOT verify length (no return fields expected) |
jhbr | 0:d3f5fdf2e6da | 4217 | |
jhbr | 0:d3f5fdf2e6da | 4218 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 4219 | reply = (dn_ipmt_zeroize_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 4220 | |
jhbr | 0:d3f5fdf2e6da | 4221 | // store RC |
jhbr | 0:d3f5fdf2e6da | 4222 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 4223 | |
jhbr | 0:d3f5fdf2e6da | 4224 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 4225 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 4226 | |
jhbr | 0:d3f5fdf2e6da | 4227 | } |
jhbr | 0:d3f5fdf2e6da | 4228 | |
jhbr | 0:d3f5fdf2e6da | 4229 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 4230 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 4231 | |
jhbr | 0:d3f5fdf2e6da | 4232 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 4233 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 4234 | } |
jhbr | 0:d3f5fdf2e6da | 4235 | |
jhbr | 0:d3f5fdf2e6da | 4236 | //===== socketInfo |
jhbr | 0:d3f5fdf2e6da | 4237 | |
jhbr | 0:d3f5fdf2e6da | 4238 | /** |
jhbr | 0:d3f5fdf2e6da | 4239 | Retrieve information about a socket. (Available in IP Mote >= 1.4.0) |
jhbr | 0:d3f5fdf2e6da | 4240 | */ |
jhbr | 0:d3f5fdf2e6da | 4241 | dn_err_t dn_ipmt_socketInfo(uint8_t index, dn_ipmt_socketInfo_rpt* reply) { |
jhbr | 0:d3f5fdf2e6da | 4242 | uint8_t extraFlags; |
jhbr | 0:d3f5fdf2e6da | 4243 | dn_err_t rc; |
jhbr | 0:d3f5fdf2e6da | 4244 | |
jhbr | 0:d3f5fdf2e6da | 4245 | // lock the module |
jhbr | 0:d3f5fdf2e6da | 4246 | dn_lock(); |
jhbr | 0:d3f5fdf2e6da | 4247 | |
jhbr | 0:d3f5fdf2e6da | 4248 | // verify no ongoing transmissions |
jhbr | 0:d3f5fdf2e6da | 4249 | if (dn_ipmt_vars.busyTx) { |
jhbr | 0:d3f5fdf2e6da | 4250 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 4251 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 4252 | |
jhbr | 0:d3f5fdf2e6da | 4253 | // return |
jhbr | 0:d3f5fdf2e6da | 4254 | return DN_ERR_BUSY; |
jhbr | 0:d3f5fdf2e6da | 4255 | } |
jhbr | 0:d3f5fdf2e6da | 4256 | |
jhbr | 0:d3f5fdf2e6da | 4257 | // store callback information |
jhbr | 0:d3f5fdf2e6da | 4258 | dn_ipmt_vars.cmdId = CMDID_SOCKETINFO; |
jhbr | 0:d3f5fdf2e6da | 4259 | dn_ipmt_vars.replyContents = (uint8_t*)reply; |
jhbr | 0:d3f5fdf2e6da | 4260 | |
jhbr | 0:d3f5fdf2e6da | 4261 | // extraFlags |
jhbr | 0:d3f5fdf2e6da | 4262 | extraFlags = 0x00; |
jhbr | 0:d3f5fdf2e6da | 4263 | |
jhbr | 0:d3f5fdf2e6da | 4264 | // build outputBuf |
jhbr | 0:d3f5fdf2e6da | 4265 | dn_ipmt_vars.outputBuf[DN_SOCKETINFO_REQ_OFFS_INDEX] = index; |
jhbr | 0:d3f5fdf2e6da | 4266 | |
jhbr | 0:d3f5fdf2e6da | 4267 | // send outputBuf |
jhbr | 0:d3f5fdf2e6da | 4268 | rc = dn_serial_mt_sendRequest( |
jhbr | 0:d3f5fdf2e6da | 4269 | CMDID_SOCKETINFO, // cmdId |
jhbr | 0:d3f5fdf2e6da | 4270 | extraFlags, // extraFlags |
jhbr | 0:d3f5fdf2e6da | 4271 | dn_ipmt_vars.outputBuf, // payload |
jhbr | 0:d3f5fdf2e6da | 4272 | DN_SOCKETINFO_REQ_LEN, // length |
jhbr | 0:d3f5fdf2e6da | 4273 | dn_ipmt_socketInfo_reply // replyCb |
jhbr | 0:d3f5fdf2e6da | 4274 | ); |
jhbr | 0:d3f5fdf2e6da | 4275 | |
jhbr | 0:d3f5fdf2e6da | 4276 | if (rc==DN_ERR_NONE) { |
jhbr | 0:d3f5fdf2e6da | 4277 | // I'm now busy transmitting |
jhbr | 0:d3f5fdf2e6da | 4278 | dn_ipmt_vars.busyTx = TRUE; |
jhbr | 0:d3f5fdf2e6da | 4279 | } |
jhbr | 0:d3f5fdf2e6da | 4280 | |
jhbr | 0:d3f5fdf2e6da | 4281 | // unlock the module |
jhbr | 0:d3f5fdf2e6da | 4282 | dn_unlock(); |
jhbr | 0:d3f5fdf2e6da | 4283 | |
jhbr | 0:d3f5fdf2e6da | 4284 | return rc; |
jhbr | 0:d3f5fdf2e6da | 4285 | |
jhbr | 0:d3f5fdf2e6da | 4286 | } |
jhbr | 0:d3f5fdf2e6da | 4287 | |
jhbr | 0:d3f5fdf2e6da | 4288 | void dn_ipmt_socketInfo_reply(uint8_t cmdId, uint8_t rc, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 4289 | dn_ipmt_socketInfo_rpt* reply; |
jhbr | 0:d3f5fdf2e6da | 4290 | |
jhbr | 0:d3f5fdf2e6da | 4291 | // verify I'm expecting this answer |
jhbr | 0:d3f5fdf2e6da | 4292 | if (dn_ipmt_vars.busyTx==FALSE || dn_ipmt_vars.cmdId!=cmdId) { |
jhbr | 0:d3f5fdf2e6da | 4293 | return; |
jhbr | 0:d3f5fdf2e6da | 4294 | } |
jhbr | 0:d3f5fdf2e6da | 4295 | |
jhbr | 0:d3f5fdf2e6da | 4296 | // verify length |
jhbr | 0:d3f5fdf2e6da | 4297 | if (rc==DN_SERIAL_RC_OK && len<DN_SOCKETINFO_REPLY_LEN) { |
jhbr | 0:d3f5fdf2e6da | 4298 | return; |
jhbr | 0:d3f5fdf2e6da | 4299 | } |
jhbr | 0:d3f5fdf2e6da | 4300 | |
jhbr | 0:d3f5fdf2e6da | 4301 | // cast the replyContent |
jhbr | 0:d3f5fdf2e6da | 4302 | reply = (dn_ipmt_socketInfo_rpt*)dn_ipmt_vars.replyContents; |
jhbr | 0:d3f5fdf2e6da | 4303 | |
jhbr | 0:d3f5fdf2e6da | 4304 | // store RC |
jhbr | 0:d3f5fdf2e6da | 4305 | reply->RC = rc; |
jhbr | 0:d3f5fdf2e6da | 4306 | |
jhbr | 0:d3f5fdf2e6da | 4307 | // parse returned value (iff RC==0) |
jhbr | 0:d3f5fdf2e6da | 4308 | if (rc==DN_SERIAL_RC_OK) { |
jhbr | 0:d3f5fdf2e6da | 4309 | |
jhbr | 0:d3f5fdf2e6da | 4310 | reply->index = payload[DN_SOCKETINFO_REPLY_OFFS_INDEX]; |
jhbr | 0:d3f5fdf2e6da | 4311 | reply->socketId = payload[DN_SOCKETINFO_REPLY_OFFS_SOCKETID]; |
jhbr | 0:d3f5fdf2e6da | 4312 | reply->protocol = payload[DN_SOCKETINFO_REPLY_OFFS_PROTOCOL]; |
jhbr | 0:d3f5fdf2e6da | 4313 | reply->bindState = payload[DN_SOCKETINFO_REPLY_OFFS_BINDSTATE]; |
jhbr | 0:d3f5fdf2e6da | 4314 | dn_read_uint16_t(&reply->port,&payload[DN_SOCKETINFO_REPLY_OFFS_PORT]); |
jhbr | 0:d3f5fdf2e6da | 4315 | } |
jhbr | 0:d3f5fdf2e6da | 4316 | |
jhbr | 0:d3f5fdf2e6da | 4317 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 4318 | dn_ipmt_vars.replyCb(cmdId); |
jhbr | 0:d3f5fdf2e6da | 4319 | |
jhbr | 0:d3f5fdf2e6da | 4320 | // I'm not busy transmitting anymore |
jhbr | 0:d3f5fdf2e6da | 4321 | dn_ipmt_vars.busyTx=FALSE; |
jhbr | 0:d3f5fdf2e6da | 4322 | } |
jhbr | 0:d3f5fdf2e6da | 4323 | |
jhbr | 0:d3f5fdf2e6da | 4324 | //========== serialRX |
jhbr | 0:d3f5fdf2e6da | 4325 | |
jhbr | 0:d3f5fdf2e6da | 4326 | void dn_ipmt_rxSerialRequest(uint8_t cmdId, uint8_t flags, uint8_t* payload, uint8_t len) { |
jhbr | 0:d3f5fdf2e6da | 4327 | dn_ipmt_timeIndication_nt* notif_timeIndication; |
jhbr | 0:d3f5fdf2e6da | 4328 | dn_ipmt_events_nt* notif_events; |
jhbr | 0:d3f5fdf2e6da | 4329 | dn_ipmt_receive_nt* notif_receive; |
jhbr | 0:d3f5fdf2e6da | 4330 | dn_ipmt_macRx_nt* notif_macRx; |
jhbr | 0:d3f5fdf2e6da | 4331 | dn_ipmt_txDone_nt* notif_txDone; |
jhbr | 0:d3f5fdf2e6da | 4332 | dn_ipmt_advReceived_nt* notif_advReceived; |
jhbr | 0:d3f5fdf2e6da | 4333 | |
jhbr | 0:d3f5fdf2e6da | 4334 | // parse notification |
jhbr | 0:d3f5fdf2e6da | 4335 | switch(cmdId) { |
jhbr | 0:d3f5fdf2e6da | 4336 | case CMDID_TIMEINDICATION: |
jhbr | 0:d3f5fdf2e6da | 4337 | |
jhbr | 0:d3f5fdf2e6da | 4338 | // verify length payload received |
jhbr | 0:d3f5fdf2e6da | 4339 | if (len<23) { |
jhbr | 0:d3f5fdf2e6da | 4340 | return; |
jhbr | 0:d3f5fdf2e6da | 4341 | } |
jhbr | 0:d3f5fdf2e6da | 4342 | |
jhbr | 0:d3f5fdf2e6da | 4343 | // verify length notifBuf |
jhbr | 0:d3f5fdf2e6da | 4344 | if (len>dn_ipmt_vars.notifBufLen) { |
jhbr | 0:d3f5fdf2e6da | 4345 | return; |
jhbr | 0:d3f5fdf2e6da | 4346 | } |
jhbr | 0:d3f5fdf2e6da | 4347 | |
jhbr | 0:d3f5fdf2e6da | 4348 | // cast notifBuf |
jhbr | 0:d3f5fdf2e6da | 4349 | notif_timeIndication = (dn_ipmt_timeIndication_nt*)dn_ipmt_vars.notifBuf; |
jhbr | 0:d3f5fdf2e6da | 4350 | |
jhbr | 0:d3f5fdf2e6da | 4351 | // parse the notification |
jhbr | 0:d3f5fdf2e6da | 4352 | dn_read_uint32_t(¬if_timeIndication->uptime,&payload[DN_TIMEINDICATION_NOTIF_OFFS_UPTIME]); |
jhbr | 0:d3f5fdf2e6da | 4353 | memcpy(¬if_timeIndication->utcSecs[0],&payload[DN_TIMEINDICATION_NOTIF_OFFS_UTCSECS],8); |
jhbr | 0:d3f5fdf2e6da | 4354 | dn_read_uint32_t(¬if_timeIndication->utcUsecs,&payload[DN_TIMEINDICATION_NOTIF_OFFS_UTCUSECS]); |
jhbr | 0:d3f5fdf2e6da | 4355 | memcpy(¬if_timeIndication->asn[0],&payload[DN_TIMEINDICATION_NOTIF_OFFS_ASN],5); |
jhbr | 0:d3f5fdf2e6da | 4356 | dn_read_uint16_t(¬if_timeIndication->asnOffset,&payload[DN_TIMEINDICATION_NOTIF_OFFS_ASNOFFSET]); |
jhbr | 0:d3f5fdf2e6da | 4357 | break; |
jhbr | 0:d3f5fdf2e6da | 4358 | case CMDID_EVENTS: |
jhbr | 0:d3f5fdf2e6da | 4359 | |
jhbr | 0:d3f5fdf2e6da | 4360 | // verify length payload received |
jhbr | 0:d3f5fdf2e6da | 4361 | if (len<9) { |
jhbr | 0:d3f5fdf2e6da | 4362 | return; |
jhbr | 0:d3f5fdf2e6da | 4363 | } |
jhbr | 0:d3f5fdf2e6da | 4364 | |
jhbr | 0:d3f5fdf2e6da | 4365 | // verify length notifBuf |
jhbr | 0:d3f5fdf2e6da | 4366 | if (len>dn_ipmt_vars.notifBufLen) { |
jhbr | 0:d3f5fdf2e6da | 4367 | return; |
jhbr | 0:d3f5fdf2e6da | 4368 | } |
jhbr | 0:d3f5fdf2e6da | 4369 | |
jhbr | 0:d3f5fdf2e6da | 4370 | // cast notifBuf |
jhbr | 0:d3f5fdf2e6da | 4371 | notif_events = (dn_ipmt_events_nt*)dn_ipmt_vars.notifBuf; |
jhbr | 0:d3f5fdf2e6da | 4372 | |
jhbr | 0:d3f5fdf2e6da | 4373 | // parse the notification |
jhbr | 0:d3f5fdf2e6da | 4374 | dn_read_uint32_t(¬if_events->events,&payload[DN_EVENTS_NOTIF_OFFS_EVENTS]); |
jhbr | 0:d3f5fdf2e6da | 4375 | notif_events->state = payload[DN_EVENTS_NOTIF_OFFS_STATE]; |
jhbr | 0:d3f5fdf2e6da | 4376 | dn_read_uint32_t(¬if_events->alarmsList,&payload[DN_EVENTS_NOTIF_OFFS_ALARMSLIST]); |
jhbr | 0:d3f5fdf2e6da | 4377 | break; |
jhbr | 0:d3f5fdf2e6da | 4378 | case CMDID_RECEIVE: |
jhbr | 0:d3f5fdf2e6da | 4379 | |
jhbr | 0:d3f5fdf2e6da | 4380 | // verify length payload received |
jhbr | 0:d3f5fdf2e6da | 4381 | if (len<19) { |
jhbr | 0:d3f5fdf2e6da | 4382 | return; |
jhbr | 0:d3f5fdf2e6da | 4383 | } |
jhbr | 0:d3f5fdf2e6da | 4384 | |
jhbr | 0:d3f5fdf2e6da | 4385 | // verify length notifBuf |
jhbr | 0:d3f5fdf2e6da | 4386 | if (len>dn_ipmt_vars.notifBufLen) { |
jhbr | 0:d3f5fdf2e6da | 4387 | return; |
jhbr | 0:d3f5fdf2e6da | 4388 | } |
jhbr | 0:d3f5fdf2e6da | 4389 | |
jhbr | 0:d3f5fdf2e6da | 4390 | // cast notifBuf |
jhbr | 0:d3f5fdf2e6da | 4391 | notif_receive = (dn_ipmt_receive_nt*)dn_ipmt_vars.notifBuf; |
jhbr | 0:d3f5fdf2e6da | 4392 | |
jhbr | 0:d3f5fdf2e6da | 4393 | // parse the notification |
jhbr | 0:d3f5fdf2e6da | 4394 | notif_receive->socketId = payload[DN_RECEIVE_NOTIF_OFFS_SOCKETID]; |
jhbr | 0:d3f5fdf2e6da | 4395 | memcpy(¬if_receive->srcAddr[0],&payload[DN_RECEIVE_NOTIF_OFFS_SRCADDR],16); |
jhbr | 0:d3f5fdf2e6da | 4396 | dn_read_uint16_t(¬if_receive->srcPort,&payload[DN_RECEIVE_NOTIF_OFFS_SRCPORT]); |
jhbr | 0:d3f5fdf2e6da | 4397 | notif_receive->payloadLen = len-DN_RECEIVE_NOTIF_OFFS_PAYLOAD; |
jhbr | 0:d3f5fdf2e6da | 4398 | memcpy(¬if_receive->payload[0],&payload[DN_RECEIVE_NOTIF_OFFS_PAYLOAD],len-DN_RECEIVE_NOTIF_OFFS_PAYLOAD); |
jhbr | 0:d3f5fdf2e6da | 4399 | break; |
jhbr | 0:d3f5fdf2e6da | 4400 | case CMDID_MACRX: |
jhbr | 0:d3f5fdf2e6da | 4401 | |
jhbr | 0:d3f5fdf2e6da | 4402 | // verify length notifBuf |
jhbr | 0:d3f5fdf2e6da | 4403 | if (len>dn_ipmt_vars.notifBufLen) { |
jhbr | 0:d3f5fdf2e6da | 4404 | return; |
jhbr | 0:d3f5fdf2e6da | 4405 | } |
jhbr | 0:d3f5fdf2e6da | 4406 | |
jhbr | 0:d3f5fdf2e6da | 4407 | // cast notifBuf |
jhbr | 0:d3f5fdf2e6da | 4408 | notif_macRx = (dn_ipmt_macRx_nt*)dn_ipmt_vars.notifBuf; |
jhbr | 0:d3f5fdf2e6da | 4409 | |
jhbr | 0:d3f5fdf2e6da | 4410 | // parse the notification |
jhbr | 0:d3f5fdf2e6da | 4411 | memcpy(¬if_macRx->payload[0],&payload[DN_MACRX_NOTIF_OFFS_PAYLOAD],len-DN_MACRX_NOTIF_OFFS_PAYLOAD); |
jhbr | 0:d3f5fdf2e6da | 4412 | break; |
jhbr | 0:d3f5fdf2e6da | 4413 | case CMDID_TXDONE: |
jhbr | 0:d3f5fdf2e6da | 4414 | |
jhbr | 0:d3f5fdf2e6da | 4415 | // verify length payload received |
jhbr | 0:d3f5fdf2e6da | 4416 | if (len<3) { |
jhbr | 0:d3f5fdf2e6da | 4417 | return; |
jhbr | 0:d3f5fdf2e6da | 4418 | } |
jhbr | 0:d3f5fdf2e6da | 4419 | |
jhbr | 0:d3f5fdf2e6da | 4420 | // verify length notifBuf |
jhbr | 0:d3f5fdf2e6da | 4421 | if (len>dn_ipmt_vars.notifBufLen) { |
jhbr | 0:d3f5fdf2e6da | 4422 | return; |
jhbr | 0:d3f5fdf2e6da | 4423 | } |
jhbr | 0:d3f5fdf2e6da | 4424 | |
jhbr | 0:d3f5fdf2e6da | 4425 | // cast notifBuf |
jhbr | 0:d3f5fdf2e6da | 4426 | notif_txDone = (dn_ipmt_txDone_nt*)dn_ipmt_vars.notifBuf; |
jhbr | 0:d3f5fdf2e6da | 4427 | |
jhbr | 0:d3f5fdf2e6da | 4428 | // parse the notification |
jhbr | 0:d3f5fdf2e6da | 4429 | dn_read_uint16_t(¬if_txDone->packetId,&payload[DN_TXDONE_NOTIF_OFFS_PACKETID]); |
jhbr | 0:d3f5fdf2e6da | 4430 | notif_txDone->status = payload[DN_TXDONE_NOTIF_OFFS_STATUS]; |
jhbr | 0:d3f5fdf2e6da | 4431 | break; |
jhbr | 0:d3f5fdf2e6da | 4432 | case CMDID_ADVRECEIVED: |
jhbr | 0:d3f5fdf2e6da | 4433 | |
jhbr | 0:d3f5fdf2e6da | 4434 | // verify length payload received |
jhbr | 0:d3f5fdf2e6da | 4435 | if (len<6) { |
jhbr | 0:d3f5fdf2e6da | 4436 | return; |
jhbr | 0:d3f5fdf2e6da | 4437 | } |
jhbr | 0:d3f5fdf2e6da | 4438 | |
jhbr | 0:d3f5fdf2e6da | 4439 | // verify length notifBuf |
jhbr | 0:d3f5fdf2e6da | 4440 | if (len>dn_ipmt_vars.notifBufLen) { |
jhbr | 0:d3f5fdf2e6da | 4441 | return; |
jhbr | 0:d3f5fdf2e6da | 4442 | } |
jhbr | 0:d3f5fdf2e6da | 4443 | |
jhbr | 0:d3f5fdf2e6da | 4444 | // cast notifBuf |
jhbr | 0:d3f5fdf2e6da | 4445 | notif_advReceived = (dn_ipmt_advReceived_nt*)dn_ipmt_vars.notifBuf; |
jhbr | 0:d3f5fdf2e6da | 4446 | |
jhbr | 0:d3f5fdf2e6da | 4447 | // parse the notification |
jhbr | 0:d3f5fdf2e6da | 4448 | dn_read_uint16_t(¬if_advReceived->netId,&payload[DN_ADVRECEIVED_NOTIF_OFFS_NETID]); |
jhbr | 0:d3f5fdf2e6da | 4449 | dn_read_uint16_t(¬if_advReceived->moteId,&payload[DN_ADVRECEIVED_NOTIF_OFFS_MOTEID]); |
jhbr | 0:d3f5fdf2e6da | 4450 | notif_advReceived->rssi = (int8_t)payload[DN_ADVRECEIVED_NOTIF_OFFS_RSSI]; |
jhbr | 0:d3f5fdf2e6da | 4451 | notif_advReceived->joinPri = payload[DN_ADVRECEIVED_NOTIF_OFFS_JOINPRI]; |
jhbr | 0:d3f5fdf2e6da | 4452 | break; |
jhbr | 0:d3f5fdf2e6da | 4453 | default: |
jhbr | 0:d3f5fdf2e6da | 4454 | // unknown cmdID |
jhbr | 0:d3f5fdf2e6da | 4455 | return; |
jhbr | 0:d3f5fdf2e6da | 4456 | } |
jhbr | 0:d3f5fdf2e6da | 4457 | |
jhbr | 0:d3f5fdf2e6da | 4458 | // call the callback |
jhbr | 0:d3f5fdf2e6da | 4459 | dn_ipmt_vars.notifCb(cmdId,DN_SUBCMDID_NONE); |
jhbr | 0:d3f5fdf2e6da | 4460 | } |
jhbr | 0:d3f5fdf2e6da | 4461 | |
jhbr | 0:d3f5fdf2e6da | 4462 | //=========================== helpers ========================================= |
jhbr | 0:d3f5fdf2e6da | 4463 | |
jhbr | 0:d3f5fdf2e6da | 4464 |