Firmware for Raw 1-Wire Interface

Dependencies:   mbed OneWire max32630fthr USBDevice

Committer:
mfruge
Date:
Tue Aug 13 14:49:35 2019 +0000
Revision:
0:06aa90721d89
Complete Firmware for 1-Wire interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfruge 0:06aa90721d89 1 /*******************************************************************************
mfruge 0:06aa90721d89 2 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved.
mfruge 0:06aa90721d89 3 *
mfruge 0:06aa90721d89 4 * This software is protected by copyright laws of the United States and
mfruge 0:06aa90721d89 5 * of foreign countries. This material may also be protected by patent laws
mfruge 0:06aa90721d89 6 * and technology transfer regulations of the United States and of foreign
mfruge 0:06aa90721d89 7 * countries. This software is furnished under a license agreement and/or a
mfruge 0:06aa90721d89 8 * nondisclosure agreement and may only be used or reproduced in accordance
mfruge 0:06aa90721d89 9 * with the terms of those agreements. Dissemination of this information to
mfruge 0:06aa90721d89 10 * any party or parties not specified in the license agreement and/or
mfruge 0:06aa90721d89 11 * nondisclosure agreement is expressly prohibited.
mfruge 0:06aa90721d89 12 *
mfruge 0:06aa90721d89 13 * The above copyright notice and this permission notice shall be included
mfruge 0:06aa90721d89 14 * in all copies or substantial portions of the Software.
mfruge 0:06aa90721d89 15 *
mfruge 0:06aa90721d89 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
mfruge 0:06aa90721d89 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
mfruge 0:06aa90721d89 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
mfruge 0:06aa90721d89 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
mfruge 0:06aa90721d89 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
mfruge 0:06aa90721d89 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
mfruge 0:06aa90721d89 22 * OTHER DEALINGS IN THE SOFTWARE.
mfruge 0:06aa90721d89 23 *
mfruge 0:06aa90721d89 24 * Except as contained in this notice, the name of Maxim Integrated
mfruge 0:06aa90721d89 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
mfruge 0:06aa90721d89 26 * Products, Inc. Branding Policy.
mfruge 0:06aa90721d89 27 *
mfruge 0:06aa90721d89 28 * The mere transfer of this software does not imply any licenses
mfruge 0:06aa90721d89 29 * of trade secrets, proprietary technology, copyrights, patents,
mfruge 0:06aa90721d89 30 * trademarks, maskwork rights, or any other form of intellectual
mfruge 0:06aa90721d89 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
mfruge 0:06aa90721d89 32 * ownership rights.
mfruge 0:06aa90721d89 33 *******************************************************************************
mfruge 0:06aa90721d89 34 */
mfruge 0:06aa90721d89 35
mfruge 0:06aa90721d89 36
mfruge 0:06aa90721d89 37
mfruge 0:06aa90721d89 38 /* Included Libraries */
mfruge 0:06aa90721d89 39 #include "mbed.h"
mfruge 0:06aa90721d89 40 #include "OneWire.h"
mfruge 0:06aa90721d89 41 #include "max32630fthr.h"
mfruge 0:06aa90721d89 42 #include "USBSerial.h"
mfruge 0:06aa90721d89 43 #include "string"
mfruge 0:06aa90721d89 44 #include "sstream"
mfruge 0:06aa90721d89 45 #include "vector"
mfruge 0:06aa90721d89 46
mfruge 0:06aa90721d89 47
mfruge 0:06aa90721d89 48 /* Define Constants */
mfruge 0:06aa90721d89 49 #define BUF_SIZE_BYTES 1024
mfruge 0:06aa90721d89 50
mfruge 0:06aa90721d89 51 #define STRING_DATA_BEGIN 3
mfruge 0:06aa90721d89 52 #define BYTES_IN_ROM_ID 8
mfruge 0:06aa90721d89 53 #define SCRATCHPAD_WRITE_BYTES 3
mfruge 0:06aa90721d89 54
mfruge 0:06aa90721d89 55 #define ALARM_SEARCH_CMD 0xEC
mfruge 0:06aa90721d89 56
mfruge 0:06aa90721d89 57 /* Define the Flags */
mfruge 0:06aa90721d89 58 #define USB_RECEIVED_FLAG 0x00000002
mfruge 0:06aa90721d89 59
mfruge 0:06aa90721d89 60 using namespace OneWire;
mfruge 0:06aa90721d89 61 using namespace RomCommands;
mfruge 0:06aa90721d89 62 using namespace std;
mfruge 0:06aa90721d89 63
mfruge 0:06aa90721d89 64
mfruge 0:06aa90721d89 65 /****************** Global Variables ******************/
mfruge 0:06aa90721d89 66
mfruge 0:06aa90721d89 67 float VersionNumber = 1.01;
mfruge 0:06aa90721d89 68
mfruge 0:06aa90721d89 69 /* Buffer for what is read in from Serial */
mfruge 0:06aa90721d89 70 string InitComp = "INIT";
mfruge 0:06aa90721d89 71 string ReadBuffer = "";
mfruge 0:06aa90721d89 72 bool StringReceived = false;
mfruge 0:06aa90721d89 73 bool OutputRomID;
mfruge 0:06aa90721d89 74 int CmdData;
mfruge 0:06aa90721d89 75
mfruge 0:06aa90721d89 76
mfruge 0:06aa90721d89 77 /* Flag variable used for interrupts */
mfruge 0:06aa90721d89 78 uint32_t int_flag;
mfruge 0:06aa90721d89 79 uint32_t cmd_flag;
mfruge 0:06aa90721d89 80
mfruge 0:06aa90721d89 81 /* Set up and configure lights */
mfruge 0:06aa90721d89 82 DigitalOut rLED(LED1, LED_OFF);
mfruge 0:06aa90721d89 83 DigitalOut gLED(LED2, LED_OFF);
mfruge 0:06aa90721d89 84 DigitalOut bLED(LED3, LED_OFF);
mfruge 0:06aa90721d89 85
mfruge 0:06aa90721d89 86 /* Set up virtual Serial Port */
mfruge 0:06aa90721d89 87 USBSerial microUSB;
mfruge 0:06aa90721d89 88
mfruge 0:06aa90721d89 89 /* One Wire Master pointer and CmdResult */
mfruge 0:06aa90721d89 90 MCU_OWM* owm_ptr;
mfruge 0:06aa90721d89 91 vector<RomId> RomIDs;
mfruge 0:06aa90721d89 92 int DeviceCount;
mfruge 0:06aa90721d89 93 int mostRecentIdx;
mfruge 0:06aa90721d89 94 SearchState search_state;
mfruge 0:06aa90721d89 95
mfruge 0:06aa90721d89 96 OneWireMaster::OWLevel NextLevel;
mfruge 0:06aa90721d89 97 OneWireMaster::OWLevel CurrLevel;
mfruge 0:06aa90721d89 98 OneWireMaster::OWSpeed NextSpeed;
mfruge 0:06aa90721d89 99 OneWireMaster::OWSpeed CurrSpeed;
mfruge 0:06aa90721d89 100
mfruge 0:06aa90721d89 101
mfruge 0:06aa90721d89 102 /* Error Messages */
mfruge 0:06aa90721d89 103 string ROM_Error = "Not a recognized ROM command";
mfruge 0:06aa90721d89 104 string Speed_Error = "Not a recognized Speed command";
mfruge 0:06aa90721d89 105 string Pullup_Error = "Cannot configure Pullup";
mfruge 0:06aa90721d89 106 string RW_Error = "Cannot parse R/W string";
mfruge 0:06aa90721d89 107
mfruge 0:06aa90721d89 108
mfruge 0:06aa90721d89 109 /************** Function Definitions ***************/
mfruge 0:06aa90721d89 110
mfruge 0:06aa90721d89 111 /**
mfruge 0:06aa90721d89 112 * @brief Sets flag for main to process DataIn from USB Serial Port
mfruge 0:06aa90721d89 113 * @version 1.0
mfruge 0:06aa90721d89 114 * @post Sets bit in int_flag
mfruge 0:06aa90721d89 115 *****************************************************************************/
mfruge 0:06aa90721d89 116 void USB_Received();
mfruge 0:06aa90721d89 117
mfruge 0:06aa90721d89 118 /**
mfruge 0:06aa90721d89 119 * @brief Processes the data recieved through the serial port and calls the corresponding One Wire functions
mfruge 0:06aa90721d89 120 * @param[in] cmd: The string containing the data read from the serial port
mfruge 0:06aa90721d89 121 * @param[in] owm: Pointer to the OneWireMaster object that preforms the operations
mfruge 0:06aa90721d89 122 * @version 1.0
mfruge 0:06aa90721d89 123 * @notes Requires 'string' and 'OneWire.h'
mfruge 0:06aa90721d89 124 * @pre owm must be initialized and cmd must not be 'null'
mfruge 0:06aa90721d89 125 * @post Depending on specific contents of cmd, could change:
mfruge 0:06aa90721d89 126 OutputRomID, RomIDs, search_state, NextLevel, CurrLevel, NextSpeed, CurrSpeed
mfruge 0:06aa90721d89 127 *****************************************************************************/
mfruge 0:06aa90721d89 128 void Parse_and_Execute(string cmd, MCU_OWM* owm);
mfruge 0:06aa90721d89 129
mfruge 0:06aa90721d89 130 /**
mfruge 0:06aa90721d89 131 * @brief Converts a string to a uint8_t
mfruge 0:06aa90721d89 132 * @version 1.0
mfruge 0:06aa90721d89 133 * @param[in] _string: String containing characters '0'-'9' to be converted
mfruge 0:06aa90721d89 134 * @param[out] The equivalent value of the string
mfruge 0:06aa90721d89 135 *****************************************************************************/
mfruge 0:06aa90721d89 136 uint8_t StringtoDecimal(string _string);
mfruge 0:06aa90721d89 137
mfruge 0:06aa90721d89 138 /**
mfruge 0:06aa90721d89 139 * @brief Initializes the owm to be used, cycles red LED if not able to initialize
mfruge 0:06aa90721d89 140 * @version 1.0
mfruge 0:06aa90721d89 141 * @param[in] owm: OneWireMaster structure to be initialized
mfruge 0:06aa90721d89 142 *****************************************************************************/
mfruge 0:06aa90721d89 143 void OWM_Initialize(MCU_OWM owm);
mfruge 0:06aa90721d89 144
mfruge 0:06aa90721d89 145 /**
mfruge 0:06aa90721d89 146 * @brief Searches the bus for any one wire devices on the bus
mfruge 0:06aa90721d89 147 * @version 1.0
mfruge 0:06aa90721d89 148 * @param[in/out] owm: Reference to owm to conduct the search
mfruge 0:06aa90721d89 149 * @param[in/out] search_state: SearchState structure to use to conduct the search
mfruge 0:06aa90721d89 150 * @param[out] Returns the result of the command
mfruge 0:06aa90721d89 151 * @post Populates the RomIDs vector with the RomID of every device on the bus
mfruge 0:06aa90721d89 152 * @notes Requires 'OneWire.h'
mfruge 0:06aa90721d89 153 *****************************************************************************/
mfruge 0:06aa90721d89 154 OneWireMaster::CmdResult FindAllRomIDs(MCU_OWM & owm, SearchState &search_state);
mfruge 0:06aa90721d89 155
mfruge 0:06aa90721d89 156 /**
mfruge 0:06aa90721d89 157 * @brief Conducts an AlarmSearch on the devices on the bus
mfruge 0:06aa90721d89 158 * @version 1.0
mfruge 0:06aa90721d89 159 * @param[in/out] owm: Reference to owm to conduct the search
mfruge 0:06aa90721d89 160 * @param[in/out] search_state: SearchState structure to use to conduct the search
mfruge 0:06aa90721d89 161 * @param[out] Returns the result of the command
mfruge 0:06aa90721d89 162 * @notes Requires 'OneWire.h'
mfruge 0:06aa90721d89 163 *****************************************************************************/
mfruge 0:06aa90721d89 164 OneWireMaster::CmdResult AlarmSearchBus(MCU_OWM &owm, SearchState &search_state);
mfruge 0:06aa90721d89 165
mfruge 0:06aa90721d89 166
mfruge 0:06aa90721d89 167
mfruge 0:06aa90721d89 168 int main()
mfruge 0:06aa90721d89 169 {
mfruge 0:06aa90721d89 170 /* Initialize the Board */
mfruge 0:06aa90721d89 171 MAX32630FTHR feather;
mfruge 0:06aa90721d89 172 feather.init(MAX32630FTHR::VIO_3V3);
mfruge 0:06aa90721d89 173
mfruge 0:06aa90721d89 174 /* Initialize OWM and other OWM related variables */
mfruge 0:06aa90721d89 175 MCU_OWM owm(false, true);
mfruge 0:06aa90721d89 176 OWM_Initialize(owm);
mfruge 0:06aa90721d89 177 NextLevel = OneWireMaster::NormalLevel;
mfruge 0:06aa90721d89 178 NextSpeed = OneWireMaster::StandardSpeed;
mfruge 0:06aa90721d89 179 owm.OWSetLevel(NextLevel);
mfruge 0:06aa90721d89 180 owm.OWSetSpeed(NextSpeed);
mfruge 0:06aa90721d89 181 CurrLevel = NextLevel;
mfruge 0:06aa90721d89 182 CurrSpeed = NextSpeed;
mfruge 0:06aa90721d89 183 search_state.reset();
mfruge 0:06aa90721d89 184
mfruge 0:06aa90721d89 185 DeviceCount = 0;
mfruge 0:06aa90721d89 186
mfruge 0:06aa90721d89 187 bool InitReceived = false;
mfruge 0:06aa90721d89 188
mfruge 0:06aa90721d89 189 /* Initialize Serial Interface */
mfruge 0:06aa90721d89 190 microUSB.attach(&USB_Received);
mfruge 0:06aa90721d89 191
mfruge 0:06aa90721d89 192 /* Temporary Variable Storage */
mfruge 0:06aa90721d89 193 volatile char BufIn;
mfruge 0:06aa90721d89 194
mfruge 0:06aa90721d89 195 while(1) {
mfruge 0:06aa90721d89 196 if(!int_flag) {
mfruge 0:06aa90721d89 197 // Go to sleep
mfruge 0:06aa90721d89 198 }
mfruge 0:06aa90721d89 199
mfruge 0:06aa90721d89 200 /* Get from USB into Buffer */
mfruge 0:06aa90721d89 201 if(int_flag & USB_RECEIVED_FLAG) {
mfruge 0:06aa90721d89 202 int_flag &= !(USB_RECEIVED_FLAG);
mfruge 0:06aa90721d89 203
mfruge 0:06aa90721d89 204 while(microUSB.readable()) {
mfruge 0:06aa90721d89 205 BufIn = microUSB.getc();
mfruge 0:06aa90721d89 206 if(BufIn == '\r' || BufIn == '\0' || BufIn == '\n') {
mfruge 0:06aa90721d89 207 StringReceived = true;
mfruge 0:06aa90721d89 208 gLED = !gLED;
mfruge 0:06aa90721d89 209 /* Detects the GUI initialization, resets the Firmware to keep it in sync */
mfruge 0:06aa90721d89 210 if(ReadBuffer == InitComp){
mfruge 0:06aa90721d89 211 microUSB.printf("Version %f\r\n", VersionNumber);
mfruge 0:06aa90721d89 212 InitReceived = true;
mfruge 0:06aa90721d89 213 owm.OWSetLevel(OneWireMaster::NormalLevel);
mfruge 0:06aa90721d89 214 owm.OWSetSpeed(OneWireMaster::StandardSpeed);
mfruge 0:06aa90721d89 215 search_state.reset();
mfruge 0:06aa90721d89 216 RomIDs.clear();
mfruge 0:06aa90721d89 217 gLED = LED_ON;
mfruge 0:06aa90721d89 218 rLED = LED_OFF;
mfruge 0:06aa90721d89 219 bLED = LED_OFF;
mfruge 0:06aa90721d89 220 }
mfruge 0:06aa90721d89 221 }
mfruge 0:06aa90721d89 222 if(!StringReceived) {
mfruge 0:06aa90721d89 223 ReadBuffer += BufIn;
mfruge 0:06aa90721d89 224 }
mfruge 0:06aa90721d89 225 }
mfruge 0:06aa90721d89 226
mfruge 0:06aa90721d89 227 /* String is now in Buffer */
mfruge 0:06aa90721d89 228 StringReceived = false;
mfruge 0:06aa90721d89 229
mfruge 0:06aa90721d89 230 if(!InitReceived){
mfruge 0:06aa90721d89 231 Parse_and_Execute(ReadBuffer, &owm);
mfruge 0:06aa90721d89 232 }
mfruge 0:06aa90721d89 233 ReadBuffer ="";
mfruge 0:06aa90721d89 234 bLED = !bLED;
mfruge 0:06aa90721d89 235 InitReceived = false;
mfruge 0:06aa90721d89 236 }
mfruge 0:06aa90721d89 237 }
mfruge 0:06aa90721d89 238
mfruge 0:06aa90721d89 239 return 0;
mfruge 0:06aa90721d89 240 }
mfruge 0:06aa90721d89 241
mfruge 0:06aa90721d89 242
mfruge 0:06aa90721d89 243 /***************** Functions ********************/
mfruge 0:06aa90721d89 244
mfruge 0:06aa90721d89 245 void USB_Received()
mfruge 0:06aa90721d89 246 {
mfruge 0:06aa90721d89 247 int_flag |= USB_RECEIVED_FLAG;
mfruge 0:06aa90721d89 248 }
mfruge 0:06aa90721d89 249
mfruge 0:06aa90721d89 250 void Parse_and_Execute(string cmd, MCU_OWM* _owm)
mfruge 0:06aa90721d89 251 {
mfruge 0:06aa90721d89 252 /* Variable Declarations */
mfruge 0:06aa90721d89 253 string::iterator i;
mfruge 0:06aa90721d89 254 string temp = "";
mfruge 0:06aa90721d89 255 string c;
mfruge 0:06aa90721d89 256 char ch;
mfruge 0:06aa90721d89 257 string RomIDstr;
mfruge 0:06aa90721d89 258 string CmdResponse;
mfruge 0:06aa90721d89 259 uint8_t num;
mfruge 0:06aa90721d89 260 uint32_t word;
mfruge 0:06aa90721d89 261 char* strend;
mfruge 0:06aa90721d89 262 long int hex_val;
mfruge 0:06aa90721d89 263 int j;
mfruge 0:06aa90721d89 264 int k;
mfruge 0:06aa90721d89 265 bool Read_Ret = false;
mfruge 0:06aa90721d89 266 bool RomID_Ret = false;
mfruge 0:06aa90721d89 267 uint8_t Scratchpad_Data [SCRATCHPAD_WRITE_BYTES];
mfruge 0:06aa90721d89 268 uint8_t ReadBytes[BUF_SIZE_BYTES];
mfruge 0:06aa90721d89 269 uint8_t ReadCount = 0;
mfruge 0:06aa90721d89 270 RomId romId;
mfruge 0:06aa90721d89 271 bool AddROM = false;
mfruge 0:06aa90721d89 272 bool AlarmSearch = false;
mfruge 0:06aa90721d89 273 size_t strpos = 0;
mfruge 0:06aa90721d89 274 vector<bool> RomIDMatches(RomIDs.size(), true);
mfruge 0:06aa90721d89 275
mfruge 0:06aa90721d89 276 MCU_OWM* owm = _owm;
mfruge 0:06aa90721d89 277 OneWireMaster::CmdResult result;
mfruge 0:06aa90721d89 278
mfruge 0:06aa90721d89 279 /* Initialize result to Fail */
mfruge 0:06aa90721d89 280 result = OneWireMaster::OperationFailure;
mfruge 0:06aa90721d89 281
mfruge 0:06aa90721d89 282 i=cmd.begin();
mfruge 0:06aa90721d89 283 /* Decode the commands based on 'Family Code' and parse the data */
mfruge 0:06aa90721d89 284 switch(*i)
mfruge 0:06aa90721d89 285 {
mfruge 0:06aa90721d89 286 /* ROM commands */
mfruge 0:06aa90721d89 287 case 'R':
mfruge 0:06aa90721d89 288 //microUSB.printf("1: ROM command \r\n");
mfruge 0:06aa90721d89 289 i++;
mfruge 0:06aa90721d89 290 switch(*i)
mfruge 0:06aa90721d89 291 {
mfruge 0:06aa90721d89 292 case 'M':
mfruge 0:06aa90721d89 293 // microUSB.printf("2: Match ROM command \r\n");
mfruge 0:06aa90721d89 294 i++;
mfruge 0:06aa90721d89 295 if( *i == 'T')
mfruge 0:06aa90721d89 296 {
mfruge 0:06aa90721d89 297 RomIDstr = cmd.substr(3); // Obtains the string after the 3 CMD characters (The ROM ID we are looking for)
mfruge 0:06aa90721d89 298 if(RomIDstr == ""){
mfruge 0:06aa90721d89 299 microUSB.printf("Please select a Rom ID from the Devices on the Bus\r\n");
mfruge 0:06aa90721d89 300 break;
mfruge 0:06aa90721d89 301 }
mfruge 0:06aa90721d89 302
mfruge 0:06aa90721d89 303 for(j=0; j<BYTES_IN_ROM_ID; j++){
mfruge 0:06aa90721d89 304 strpos = 2*j;
mfruge 0:06aa90721d89 305 temp = RomIDstr.substr(strpos, 2);
mfruge 0:06aa90721d89 306 num = strtol(temp.c_str(), &strend, 16);
mfruge 0:06aa90721d89 307 for(k=0; k<RomIDs.size(); k++){
mfruge 0:06aa90721d89 308 // First, check to make sure that the RomID we are checking still matches
mfruge 0:06aa90721d89 309 if(!RomIDMatches[k]){
mfruge 0:06aa90721d89 310 break;
mfruge 0:06aa90721d89 311 }
mfruge 0:06aa90721d89 312 // If the byte in num does not match the byte in the RomID, set the corresponding index in 'matches' to false
mfruge 0:06aa90721d89 313 if(num != RomIDs[k].buffer[(BYTES_IN_ROM_ID - 1) - j]){
mfruge 0:06aa90721d89 314 RomIDMatches[k] = false;
mfruge 0:06aa90721d89 315 break;
mfruge 0:06aa90721d89 316 }
mfruge 0:06aa90721d89 317 }
mfruge 0:06aa90721d89 318 }
mfruge 0:06aa90721d89 319 j=0; // Reset the loop variables
mfruge 0:06aa90721d89 320 k=0;
mfruge 0:06aa90721d89 321 // Now, there should only be 1 or 0 'true' values in RomIDMatches, so use that index for the MatchROM
mfruge 0:06aa90721d89 322 while(!RomIDMatches[j] && j<RomIDs.size()){
mfruge 0:06aa90721d89 323 j++;
mfruge 0:06aa90721d89 324 }
mfruge 0:06aa90721d89 325 // Now we have determined that the jth index of the RomIDs vector contains the RomID given by the user,
mfruge 0:06aa90721d89 326 romId = RomIDs[j];
mfruge 0:06aa90721d89 327 result = OWMatchRom(*owm, romId);
mfruge 0:06aa90721d89 328 CmdResponse = "Match ROM";
mfruge 0:06aa90721d89 329 RomID_Ret = true;
mfruge 0:06aa90721d89 330 ReadCount = BYTES_IN_ROM_ID;
mfruge 0:06aa90721d89 331 }
mfruge 0:06aa90721d89 332 break;
mfruge 0:06aa90721d89 333
mfruge 0:06aa90721d89 334 case 'O':
mfruge 0:06aa90721d89 335 //its an OVERDRIVE command
mfruge 0:06aa90721d89 336 i++;
mfruge 0:06aa90721d89 337 switch(*i)
mfruge 0:06aa90721d89 338 {
mfruge 0:06aa90721d89 339 case 'M':
mfruge 0:06aa90721d89 340 RomIDstr = cmd.substr(3); // Obtains the string after the 3 CMD characters (The ROM ID we are looking for)
mfruge 0:06aa90721d89 341 if(RomIDstr == ""){
mfruge 0:06aa90721d89 342 microUSB.printf("Please select a Rom ID from the Devices on the Bus\r\n");
mfruge 0:06aa90721d89 343 break;
mfruge 0:06aa90721d89 344 }
mfruge 0:06aa90721d89 345 for(j=0; j<BYTES_IN_ROM_ID; j++){
mfruge 0:06aa90721d89 346 strpos = 2*j;
mfruge 0:06aa90721d89 347 temp = RomIDstr.substr(strpos, 2);
mfruge 0:06aa90721d89 348 num = strtol(temp.c_str(), &strend, 16);
mfruge 0:06aa90721d89 349 for(k=0; k<RomIDs.size(); k++){
mfruge 0:06aa90721d89 350 // First, check to make sure that the RomID we are checking still matches
mfruge 0:06aa90721d89 351 if(!RomIDMatches[k]){
mfruge 0:06aa90721d89 352 break;
mfruge 0:06aa90721d89 353 }
mfruge 0:06aa90721d89 354 // If the byte in num does not match the byte in the RomID, set the corresponding index in 'matches' to false
mfruge 0:06aa90721d89 355 if(num != RomIDs[k].buffer[(BYTES_IN_ROM_ID - 1) - j]){
mfruge 0:06aa90721d89 356 RomIDMatches[k] = false;
mfruge 0:06aa90721d89 357 break;
mfruge 0:06aa90721d89 358 }
mfruge 0:06aa90721d89 359 }
mfruge 0:06aa90721d89 360 }
mfruge 0:06aa90721d89 361 j=0; // Reset the loop variables
mfruge 0:06aa90721d89 362 k=0;
mfruge 0:06aa90721d89 363 // Now, there should only be 1 or 0 'true' values in RomIDMatches, so use that index for the MatchROM
mfruge 0:06aa90721d89 364 while(!RomIDMatches[j] && j<RomIDs.size()){
mfruge 0:06aa90721d89 365 j++;
mfruge 0:06aa90721d89 366 }
mfruge 0:06aa90721d89 367 // Now we have determined that the jth index of the RomIDs vector contains the RomID given by the user,
mfruge 0:06aa90721d89 368 romId = RomIDs[j];
mfruge 0:06aa90721d89 369 result = OWOverdriveMatchRom(*owm, romId);
mfruge 0:06aa90721d89 370 CmdResponse = "Overdrive Match ROM";
mfruge 0:06aa90721d89 371 RomID_Ret = true;
mfruge 0:06aa90721d89 372 ReadCount = BYTES_IN_ROM_ID;
mfruge 0:06aa90721d89 373 break;
mfruge 0:06aa90721d89 374
mfruge 0:06aa90721d89 375 case 'S':
mfruge 0:06aa90721d89 376 // microUSB.printf("3: Its an OD Skip ROM\r\n");
mfruge 0:06aa90721d89 377 result = OWOverdriveSkipRom(*owm);
mfruge 0:06aa90721d89 378 CmdResponse = "Overdrive Skip ROM";
mfruge 0:06aa90721d89 379 break;
mfruge 0:06aa90721d89 380
mfruge 0:06aa90721d89 381 default:
mfruge 0:06aa90721d89 382 microUSB.printf("%s \r\n", ROM_Error.c_str());
mfruge 0:06aa90721d89 383 break;
mfruge 0:06aa90721d89 384 }
mfruge 0:06aa90721d89 385 break;
mfruge 0:06aa90721d89 386
mfruge 0:06aa90721d89 387 case 'R':
mfruge 0:06aa90721d89 388 // It's a Resume OR ReadROM
mfruge 0:06aa90721d89 389 // microUSB.printf("2: Res or Read ROM command \r\n");
mfruge 0:06aa90721d89 390 i++;
mfruge 0:06aa90721d89 391 switch(*i) {
mfruge 0:06aa90721d89 392 case 'D':
mfruge 0:06aa90721d89 393 // microUSB.printf("3: Its a Read ROM\r\n");
mfruge 0:06aa90721d89 394 result = OWReadRom(*owm, romId);
mfruge 0:06aa90721d89 395 RomID_Ret = true;
mfruge 0:06aa90721d89 396 ReadCount = 8;
mfruge 0:06aa90721d89 397 CmdResponse = "Read ROM";
mfruge 0:06aa90721d89 398 break;
mfruge 0:06aa90721d89 399 case 'S':
mfruge 0:06aa90721d89 400 // microUSB.printf("3: Its a Resume\r\n");
mfruge 0:06aa90721d89 401 result = OWResume(*owm);
mfruge 0:06aa90721d89 402 CmdResponse = "Resume";
mfruge 0:06aa90721d89 403 break;
mfruge 0:06aa90721d89 404 case 'I':
mfruge 0:06aa90721d89 405 /* Preforms a search finidng all devices on the bus */
mfruge 0:06aa90721d89 406 result = FindAllRomIDs(*owm, search_state);
mfruge 0:06aa90721d89 407 CmdResponse = "Standard Search";
mfruge 0:06aa90721d89 408 break;
mfruge 0:06aa90721d89 409 default:
mfruge 0:06aa90721d89 410 microUSB.printf("%s \r\n", ROM_Error.c_str());
mfruge 0:06aa90721d89 411 break;
mfruge 0:06aa90721d89 412 }
mfruge 0:06aa90721d89 413 break;
mfruge 0:06aa90721d89 414
mfruge 0:06aa90721d89 415 case 'S':
mfruge 0:06aa90721d89 416 // It's a Search rom (f or n) OR a SkipROM
mfruge 0:06aa90721d89 417 // microUSB.printf("2: Search or skip ROM command \r\n");
mfruge 0:06aa90721d89 418 i++;
mfruge 0:06aa90721d89 419 switch(*i) {
mfruge 0:06aa90721d89 420 case 'K':
mfruge 0:06aa90721d89 421 // microUSB.printf("3: Skip-ROM issued\r\n");
mfruge 0:06aa90721d89 422 result = OWSkipRom(*owm);
mfruge 0:06aa90721d89 423 CmdResponse = "Skip ROM";
mfruge 0:06aa90721d89 424 break;
mfruge 0:06aa90721d89 425
mfruge 0:06aa90721d89 426 default:
mfruge 0:06aa90721d89 427 microUSB.printf("%s \r\n", ROM_Error.c_str());
mfruge 0:06aa90721d89 428 break;
mfruge 0:06aa90721d89 429 }
mfruge 0:06aa90721d89 430 break;
mfruge 0:06aa90721d89 431
mfruge 0:06aa90721d89 432 case 'A':
mfruge 0:06aa90721d89 433 // It's an alarm search
mfruge 0:06aa90721d89 434 i++;
mfruge 0:06aa90721d89 435 if(*i == 'S'){
mfruge 0:06aa90721d89 436 result = AlarmSearchBus(*owm, search_state);
mfruge 0:06aa90721d89 437 CmdResponse = "Alarm Search";
mfruge 0:06aa90721d89 438 }
mfruge 0:06aa90721d89 439 else{
mfruge 0:06aa90721d89 440 microUSB.printf(" %s \r\n", ROM_Error.c_str());
mfruge 0:06aa90721d89 441 }
mfruge 0:06aa90721d89 442 break;
mfruge 0:06aa90721d89 443
mfruge 0:06aa90721d89 444 default:
mfruge 0:06aa90721d89 445 microUSB.printf("%s \r\n", ROM_Error.c_str());
mfruge 0:06aa90721d89 446 break;
mfruge 0:06aa90721d89 447 }
mfruge 0:06aa90721d89 448 break;
mfruge 0:06aa90721d89 449
mfruge 0:06aa90721d89 450 case 'S':
mfruge 0:06aa90721d89 451 // microUSB.printf("1: Speed command \r\n");
mfruge 0:06aa90721d89 452 // it is a speed command
mfruge 0:06aa90721d89 453 i++;
mfruge 0:06aa90721d89 454 switch(*i) {
mfruge 0:06aa90721d89 455 case 'N':
mfruge 0:06aa90721d89 456 NextSpeed = OneWireMaster::StandardSpeed;
mfruge 0:06aa90721d89 457 // microUSB.printf("2: Standard Speed command issued\r\n");
mfruge 0:06aa90721d89 458 if(CurrSpeed == NextSpeed) {
mfruge 0:06aa90721d89 459 microUSB.printf("Already in Standard Speed Mode \r\n");
mfruge 0:06aa90721d89 460 result = OneWireMaster::Success;
mfruge 0:06aa90721d89 461 } else {
mfruge 0:06aa90721d89 462 result = owm->OWSetSpeed(NextSpeed);
mfruge 0:06aa90721d89 463 CurrSpeed = NextSpeed;
mfruge 0:06aa90721d89 464 CmdResponse = "Normal Speed";
mfruge 0:06aa90721d89 465 }
mfruge 0:06aa90721d89 466 break;
mfruge 0:06aa90721d89 467 case 'O':
mfruge 0:06aa90721d89 468 NextSpeed = OneWireMaster::OverdriveSpeed;
mfruge 0:06aa90721d89 469 // microUSB.printf("2: Overdrive speed command issued\r\n");
mfruge 0:06aa90721d89 470 if(CurrSpeed == NextSpeed) {
mfruge 0:06aa90721d89 471 microUSB.printf("Already in Overdrive Speed Mode\r\n");
mfruge 0:06aa90721d89 472 result = OneWireMaster::Success;
mfruge 0:06aa90721d89 473 } else {
mfruge 0:06aa90721d89 474 result = owm->OWSetSpeed(NextSpeed);
mfruge 0:06aa90721d89 475 CurrSpeed = NextSpeed;
mfruge 0:06aa90721d89 476 CmdResponse = "Overdrive Speed";
mfruge 0:06aa90721d89 477 }
mfruge 0:06aa90721d89 478 break;
mfruge 0:06aa90721d89 479 default:
mfruge 0:06aa90721d89 480 microUSB.printf("%s \r\n", Speed_Error.c_str());
mfruge 0:06aa90721d89 481 break;
mfruge 0:06aa90721d89 482 }
mfruge 0:06aa90721d89 483 break;
mfruge 0:06aa90721d89 484
mfruge 0:06aa90721d89 485 case 'W':
mfruge 0:06aa90721d89 486 // it is a R/W cmd
mfruge 0:06aa90721d89 487 i++;
mfruge 0:06aa90721d89 488 switch(*i) {
mfruge 0:06aa90721d89 489
mfruge 0:06aa90721d89 490 case 'R':
mfruge 0:06aa90721d89 491 // Its a read cmd
mfruge 0:06aa90721d89 492 i++;
mfruge 0:06aa90721d89 493 switch(*i) {
mfruge 0:06aa90721d89 494 case 'I':
mfruge 0:06aa90721d89 495 // Read single bit command
mfruge 0:06aa90721d89 496 result = owm->OWTouchBitSetLevel(*ReadBytes, CurrLevel);
mfruge 0:06aa90721d89 497 Read_Ret = true;
mfruge 0:06aa90721d89 498 ReadCount = 1;
mfruge 0:06aa90721d89 499 CmdResponse = "Read Bit";
mfruge 0:06aa90721d89 500 break;
mfruge 0:06aa90721d89 501
mfruge 0:06aa90721d89 502 case 'Y':
mfruge 0:06aa90721d89 503 // Read X Bytes
mfruge 0:06aa90721d89 504 // microUSB.printf("3: Read byte command \r\n");
mfruge 0:06aa90721d89 505 /* Extract the data from the CMD string */
mfruge 0:06aa90721d89 506 temp = cmd.substr(3);
mfruge 0:06aa90721d89 507 /* Convert the string to the corresponding int */
mfruge 0:06aa90721d89 508 ReadCount = StringtoDecimal(temp);
mfruge 0:06aa90721d89 509 result = owm->OWReadBlock(ReadBytes, (size_t)ReadCount);
mfruge 0:06aa90721d89 510 Read_Ret = true;
mfruge 0:06aa90721d89 511 CmdResponse = "Read " + temp + " Bytes";
mfruge 0:06aa90721d89 512 break;
mfruge 0:06aa90721d89 513
mfruge 0:06aa90721d89 514 default:
mfruge 0:06aa90721d89 515 microUSB.printf("%s \r\n", RW_Error.c_str());
mfruge 0:06aa90721d89 516 break;
mfruge 0:06aa90721d89 517 }
mfruge 0:06aa90721d89 518 break;
mfruge 0:06aa90721d89 519
mfruge 0:06aa90721d89 520 case 'W':
mfruge 0:06aa90721d89 521 // Its a write command
mfruge 0:06aa90721d89 522 // microUSB.printf("2: Write Command\r\n");
mfruge 0:06aa90721d89 523 i++;
mfruge 0:06aa90721d89 524 switch(*i) {
mfruge 0:06aa90721d89 525 case 'I':
mfruge 0:06aa90721d89 526 // microUSB.printf("3:Write bit command \r\n");
mfruge 0:06aa90721d89 527 //Write a single bit
mfruge 0:06aa90721d89 528 i++;
mfruge 0:06aa90721d89 529 c = *i; // Get the 1/0 needed as a string
mfruge 0:06aa90721d89 530 //microUSB.printf("The string obtained is: '%s' and it has 0x%02X characters\r\n", c, c.length());
mfruge 0:06aa90721d89 531 num = StringtoDecimal(c); //convert to decimal
mfruge 0:06aa90721d89 532 // microUSB.printf("Issuing a Write %d command\r\n", num);
mfruge 0:06aa90721d89 533 result = owm->OWTouchBitSetLevel(num, CurrLevel);
mfruge 0:06aa90721d89 534 CmdResponse = "Write Bit";
mfruge 0:06aa90721d89 535 break;
mfruge 0:06aa90721d89 536
mfruge 0:06aa90721d89 537 case 'Y':
mfruge 0:06aa90721d89 538 // Write multiple bytes
mfruge 0:06aa90721d89 539 // microUSB.printf("3:Write Byte command \r\n");
mfruge 0:06aa90721d89 540 temp = cmd.substr(3);
mfruge 0:06aa90721d89 541
mfruge 0:06aa90721d89 542 if((temp.length()%2) != 0){
mfruge 0:06aa90721d89 543 microUSB.printf("Please enter a Byte Alligned Value\r\n");
mfruge 0:06aa90721d89 544 return;
mfruge 0:06aa90721d89 545 }
mfruge 0:06aa90721d89 546
mfruge 0:06aa90721d89 547 /* Throws an error and returns if input is not formatted correctly */
mfruge 0:06aa90721d89 548 for(j=0; j<temp.length(); j++){
mfruge 0:06aa90721d89 549 ch= temp[j];
mfruge 0:06aa90721d89 550
mfruge 0:06aa90721d89 551 if((ch < '0' || ch > '9') && (ch < 'A' || ch > 'F')){
mfruge 0:06aa90721d89 552 microUSB.printf("Please ensure that you enter hex values\r\n");
mfruge 0:06aa90721d89 553 return;
mfruge 0:06aa90721d89 554 }
mfruge 0:06aa90721d89 555 }
mfruge 0:06aa90721d89 556
mfruge 0:06aa90721d89 557 for(j=0; j<(temp.length()+1)/2; j++){
mfruge 0:06aa90721d89 558 strpos = 2*j;
mfruge 0:06aa90721d89 559 c = temp.substr(strpos, 2);
mfruge 0:06aa90721d89 560 hex_val = strtol(c.c_str(), &strend, 16);
mfruge 0:06aa90721d89 561 num = (uint8_t) hex_val;
mfruge 0:06aa90721d89 562 Scratchpad_Data[j] = num;
mfruge 0:06aa90721d89 563 }
mfruge 0:06aa90721d89 564 microUSB.printf("Wrote '0x%s'\r\n", temp);
mfruge 0:06aa90721d89 565 result = owm->OWWriteBlock(Scratchpad_Data, (temp.length()+1)/2);
mfruge 0:06aa90721d89 566 CmdResponse = "Write";
mfruge 0:06aa90721d89 567 break;
mfruge 0:06aa90721d89 568 default:
mfruge 0:06aa90721d89 569 microUSB.printf("Unrecognized Command\r\n");
mfruge 0:06aa90721d89 570 break;
mfruge 0:06aa90721d89 571 }
mfruge 0:06aa90721d89 572 break;
mfruge 0:06aa90721d89 573 }
mfruge 0:06aa90721d89 574 break;
mfruge 0:06aa90721d89 575
mfruge 0:06aa90721d89 576 case 'P':
mfruge 0:06aa90721d89 577 // microUSB.printf("1: Power command \r\n");
mfruge 0:06aa90721d89 578 i++;
mfruge 0:06aa90721d89 579 switch(*i) {
mfruge 0:06aa90721d89 580 case 'N':
mfruge 0:06aa90721d89 581 // microUSB.printf("2: Normal PWR command \r\n");
mfruge 0:06aa90721d89 582 i++;
mfruge 0:06aa90721d89 583 if(*i == 'O') {
mfruge 0:06aa90721d89 584 // microUSB.printf("3: Further Normal PWR command \r\n");
mfruge 0:06aa90721d89 585 NextLevel = OneWireMaster::NormalLevel;
mfruge 0:06aa90721d89 586 if(NextLevel == CurrLevel) {
mfruge 0:06aa90721d89 587 microUSB.printf("Normal Power\r\n");
mfruge 0:06aa90721d89 588 } else {
mfruge 0:06aa90721d89 589 microUSB.printf("Normal Power\r\n");
mfruge 0:06aa90721d89 590 result = owm->OWSetLevel(NextLevel);
mfruge 0:06aa90721d89 591 CurrLevel = NextLevel;
mfruge 0:06aa90721d89 592 CmdResponse = "Normal Power";
mfruge 0:06aa90721d89 593 }
mfruge 0:06aa90721d89 594 }
mfruge 0:06aa90721d89 595
mfruge 0:06aa90721d89 596 else microUSB.printf("Unrecognizable\r\n");
mfruge 0:06aa90721d89 597 break;
mfruge 0:06aa90721d89 598
mfruge 0:06aa90721d89 599 case 'W':
mfruge 0:06aa90721d89 600 // Strong pullup after writing...
mfruge 0:06aa90721d89 601 // microUSB.printf("2: Power Write command \r\n");
mfruge 0:06aa90721d89 602 i++;
mfruge 0:06aa90721d89 603 if(NextLevel == OneWireMaster::StrongLevel) {
mfruge 0:06aa90721d89 604 microUSB.printf("Already in Strong Pull-Up Mode\r\n");
mfruge 0:06aa90721d89 605 result = OneWireMaster::Success;
mfruge 0:06aa90721d89 606 break;
mfruge 0:06aa90721d89 607 }
mfruge 0:06aa90721d89 608 NextLevel = OneWireMaster::StrongLevel;
mfruge 0:06aa90721d89 609 switch(*i) {
mfruge 0:06aa90721d89 610 case 'I':
mfruge 0:06aa90721d89 611 // microUSB.printf("3: Power Write bit command \r\n");
mfruge 0:06aa90721d89 612 temp = cmd.substr(3);
mfruge 0:06aa90721d89 613 num = atoi(temp.c_str());
mfruge 0:06aa90721d89 614 if(temp == "1" || temp == "0") {
mfruge 0:06aa90721d89 615 //microUSB.printf("Issuing strong Pullup after writing %d \r\n", num);
mfruge 0:06aa90721d89 616 result = owm->OWWriteBitPower(num);
mfruge 0:06aa90721d89 617 microUSB.printf("Switching to Strong Pull-Up Mode\r\n");
mfruge 0:06aa90721d89 618 CurrLevel = NextLevel;
mfruge 0:06aa90721d89 619 CmdResponse = "Strong Pullup After Writing Bit";
mfruge 0:06aa90721d89 620 microUSB.printf("Wrote '0x%s'\r\n", temp);
mfruge 0:06aa90721d89 621 }
mfruge 0:06aa90721d89 622 else {
mfruge 0:06aa90721d89 623 microUSB.printf("Incorrect formatting error. Decoded data as 0x%02X, expecting 1 or 0 \r\n", num);
mfruge 0:06aa90721d89 624 }
mfruge 0:06aa90721d89 625 break;
mfruge 0:06aa90721d89 626
mfruge 0:06aa90721d89 627 case 'Y':
mfruge 0:06aa90721d89 628
mfruge 0:06aa90721d89 629 // microUSB.printf("3: Issuing Strong Pullup after writing Byte\r\n");
mfruge 0:06aa90721d89 630 temp = cmd.substr(3);
mfruge 0:06aa90721d89 631 hex_val = strtol(temp.c_str(), &strend, 16);
mfruge 0:06aa90721d89 632
mfruge 0:06aa90721d89 633 result = owm->OWWriteByteSetLevel(hex_val, NextLevel);
mfruge 0:06aa90721d89 634 microUSB.printf("Switching to Strong Power Mode\r\n");
mfruge 0:06aa90721d89 635 CurrLevel = NextLevel;
mfruge 0:06aa90721d89 636 CmdResponse = "Strong Pullup After Writing Byte";
mfruge 0:06aa90721d89 637 microUSB.printf("Wrote '%s'\r\n", temp);
mfruge 0:06aa90721d89 638 break;
mfruge 0:06aa90721d89 639
mfruge 0:06aa90721d89 640 default:
mfruge 0:06aa90721d89 641 microUSB.printf("Could not identify that command\r\n");
mfruge 0:06aa90721d89 642 break;
mfruge 0:06aa90721d89 643 }
mfruge 0:06aa90721d89 644 break;
mfruge 0:06aa90721d89 645 default:
mfruge 0:06aa90721d89 646 microUSB.printf("%s\r\n", Pullup_Error.c_str());
mfruge 0:06aa90721d89 647 }
mfruge 0:06aa90721d89 648 break;
mfruge 0:06aa90721d89 649 case 'Z':
mfruge 0:06aa90721d89 650 result = owm->OWReset();
mfruge 0:06aa90721d89 651 CmdResponse = "Reset";
mfruge 0:06aa90721d89 652 break;
mfruge 0:06aa90721d89 653
mfruge 0:06aa90721d89 654 default:
mfruge 0:06aa90721d89 655 microUSB.printf("Cannot Parse Command\r\n");
mfruge 0:06aa90721d89 656 break;
mfruge 0:06aa90721d89 657 } // End of switch
mfruge 0:06aa90721d89 658
mfruge 0:06aa90721d89 659 /* For loop to print out the 8 byte Rom ID and add it to the 'RomIDs' vector*/
mfruge 0:06aa90721d89 660 if(RomID_Ret && result == OneWireMaster::Success) {
mfruge 0:06aa90721d89 661 /* Flag to add to vector or not */
mfruge 0:06aa90721d89 662 AddROM = true;
mfruge 0:06aa90721d89 663
mfruge 0:06aa90721d89 664 /* Printing */
mfruge 0:06aa90721d89 665 microUSB.printf("RomID: ");
mfruge 0:06aa90721d89 666 for(j=ReadCount-1; j>=0; j--) {
mfruge 0:06aa90721d89 667 microUSB.printf("%02X ",romId.buffer[j]);
mfruge 0:06aa90721d89 668 }
mfruge 0:06aa90721d89 669 microUSB.printf("\r\n");
mfruge 0:06aa90721d89 670
mfruge 0:06aa90721d89 671 /* Add the Rom ID to the vector if not in there already, and update the most recent RomID index used */
mfruge 0:06aa90721d89 672 for(j=0; j<RomIDs.size(); j++){
mfruge 0:06aa90721d89 673 if(RomIDs[j] == romId){
mfruge 0:06aa90721d89 674 AddROM = false;
mfruge 0:06aa90721d89 675 mostRecentIdx = j;
mfruge 0:06aa90721d89 676 break;
mfruge 0:06aa90721d89 677 }
mfruge 0:06aa90721d89 678 }
mfruge 0:06aa90721d89 679
mfruge 0:06aa90721d89 680 if(AddROM){
mfruge 0:06aa90721d89 681 /* If we need to add the RomID to the vector, that means it was the most recent one that was used/found, so update the mostRecentIdx */
mfruge 0:06aa90721d89 682 RomIDs.push_back(romId);
mfruge 0:06aa90721d89 683 mostRecentIdx = RomIDs.size() - 1;
mfruge 0:06aa90721d89 684 microUSB.printf("Added RomID to array\r\n");
mfruge 0:06aa90721d89 685 }
mfruge 0:06aa90721d89 686
mfruge 0:06aa90721d89 687 if(search_state.last_device_flag && AddROM && !AlarmSearch){
mfruge 0:06aa90721d89 688 microUSB.printf("Obtained RomID's for all devices on the bus\r\n");
mfruge 0:06aa90721d89 689 }
mfruge 0:06aa90721d89 690 }
mfruge 0:06aa90721d89 691
mfruge 0:06aa90721d89 692 /*Return bytes that were read from the device */
mfruge 0:06aa90721d89 693 if(Read_Ret && result == OneWireMaster::Success) {
mfruge 0:06aa90721d89 694 microUSB.printf("Result: ");
mfruge 0:06aa90721d89 695 for(j=0; j<ReadCount; j++) {
mfruge 0:06aa90721d89 696 microUSB.printf("%02X ",ReadBytes[j]);
mfruge 0:06aa90721d89 697 }
mfruge 0:06aa90721d89 698 microUSB.printf("\r\n");
mfruge 0:06aa90721d89 699 }
mfruge 0:06aa90721d89 700
mfruge 0:06aa90721d89 701 if(result == OneWireMaster::Success) {
mfruge 0:06aa90721d89 702 microUSB.printf("The %s was successful\r\n", CmdResponse);
mfruge 0:06aa90721d89 703 } else if (result == OneWireMaster::CommunicationWriteError){
mfruge 0:06aa90721d89 704 microUSB.printf("Command not issued, Communication Write Error\r\n");
mfruge 0:06aa90721d89 705 } else if (result == OneWireMaster::CommunicationReadError){
mfruge 0:06aa90721d89 706 microUSB.printf("Command not issued, Communication Read Error\r\n");
mfruge 0:06aa90721d89 707 } else if (result == OneWireMaster::TimeoutError) {
mfruge 0:06aa90721d89 708 microUSB.printf("The device timed out before the command could be issued\r\n");
mfruge 0:06aa90721d89 709 } else {
mfruge 0:06aa90721d89 710 microUSB.printf("Operation Failed\r\n");
mfruge 0:06aa90721d89 711 }
mfruge 0:06aa90721d89 712 }
mfruge 0:06aa90721d89 713
mfruge 0:06aa90721d89 714
mfruge 0:06aa90721d89 715 uint8_t StringtoDecimal(string _string) {
mfruge 0:06aa90721d89 716 uint8_t number;
mfruge 0:06aa90721d89 717 number = atoi(_string.c_str());
mfruge 0:06aa90721d89 718 return number;
mfruge 0:06aa90721d89 719 }
mfruge 0:06aa90721d89 720
mfruge 0:06aa90721d89 721 void OWM_Initialize(MCU_OWM owm) {
mfruge 0:06aa90721d89 722 rLED = LED_ON;
mfruge 0:06aa90721d89 723 OneWireMaster::CmdResult result = owm.OWInitMaster();
mfruge 0:06aa90721d89 724 while(result != OneWireMaster::Success) {
mfruge 0:06aa90721d89 725 microUSB.printf("Failed to init OWM...\r\n\r\n");
mfruge 0:06aa90721d89 726 result = owm.OWInitMaster();
mfruge 0:06aa90721d89 727 wait(0.5);
mfruge 0:06aa90721d89 728 rLED = !rLED;
mfruge 0:06aa90721d89 729 }
mfruge 0:06aa90721d89 730 rLED = LED_OFF;
mfruge 0:06aa90721d89 731 }
mfruge 0:06aa90721d89 732
mfruge 0:06aa90721d89 733
mfruge 0:06aa90721d89 734 OneWireMaster::CmdResult AlarmSearchBus(MCU_OWM & owm, SearchState & search_state){
mfruge 0:06aa90721d89 735 int numAlarms = 0;
mfruge 0:06aa90721d89 736 RomId RetRom;
mfruge 0:06aa90721d89 737 OneWireMaster::CmdResult res;
mfruge 0:06aa90721d89 738 search_state.reset();
mfruge 0:06aa90721d89 739 while(!search_state.last_device_flag){
mfruge 0:06aa90721d89 740 res = OWAlarmSearch(owm, search_state);
mfruge 0:06aa90721d89 741 if(res == OneWireMaster::Success){
mfruge 0:06aa90721d89 742 numAlarms++;
mfruge 0:06aa90721d89 743 RetRom = search_state.romId;
mfruge 0:06aa90721d89 744 microUSB.printf("Active Alarms: ");
mfruge 0:06aa90721d89 745 for(int j=BYTES_IN_ROM_ID-1; j>=0; j--) {
mfruge 0:06aa90721d89 746 microUSB.printf("%02X ",RetRom.buffer[j]);
mfruge 0:06aa90721d89 747 }
mfruge 0:06aa90721d89 748 microUSB.printf("\r\n");
mfruge 0:06aa90721d89 749 }
mfruge 0:06aa90721d89 750 }
mfruge 0:06aa90721d89 751 return res;
mfruge 0:06aa90721d89 752 }
mfruge 0:06aa90721d89 753
mfruge 0:06aa90721d89 754
mfruge 0:06aa90721d89 755
mfruge 0:06aa90721d89 756 OneWireMaster::CmdResult FindAllRomIDs(MCU_OWM & owm, SearchState &search_state){
mfruge 0:06aa90721d89 757 int numDevices = 0;
mfruge 0:06aa90721d89 758 RomId romId;
mfruge 0:06aa90721d89 759 OneWireMaster::CmdResult res;
mfruge 0:06aa90721d89 760
mfruge 0:06aa90721d89 761 RomIDs.clear();
mfruge 0:06aa90721d89 762 search_state.reset();
mfruge 0:06aa90721d89 763
mfruge 0:06aa90721d89 764 /* Identify next Device on the bus, and print out its ROM ID so GUI can parse it, and add it to the FW array */
mfruge 0:06aa90721d89 765 while(!search_state.last_device_flag){
mfruge 0:06aa90721d89 766 res = OWSearch(owm, search_state);
mfruge 0:06aa90721d89 767 if(res == OneWireMaster::Success){
mfruge 0:06aa90721d89 768 numDevices++;
mfruge 0:06aa90721d89 769 romId = search_state.romId;
mfruge 0:06aa90721d89 770 microUSB.printf("RomID: ");
mfruge 0:06aa90721d89 771 for(int j=BYTES_IN_ROM_ID-1; j>=0; j--) {
mfruge 0:06aa90721d89 772 microUSB.printf("%02X ",romId.buffer[j]);
mfruge 0:06aa90721d89 773 }
mfruge 0:06aa90721d89 774 microUSB.printf("\r\n");
mfruge 0:06aa90721d89 775 RomIDs.push_back(romId);
mfruge 0:06aa90721d89 776 }
mfruge 0:06aa90721d89 777 }
mfruge 0:06aa90721d89 778 return res;
mfruge 0:06aa90721d89 779 }