unsigned char* Hex2Bin(char * values,unsigned char* ___Hex2Bin) { int i ; unsigned char temp[3]; for ( i =0;i<strlen(values )/2;i++) { ___Hex2Bin[i] = ( unsigned char)strToHex(Substring(values,i*2,2,temp)); } return ___Hex2Bin; }
/* Change the text in a given block to hex. */ void UsbConsole::charToHex(QTextCursor *c) { QString str = c->block().text(); QString hexes; int len = str.length(); for(int i = 0; i < len; i++) { c->deleteChar(); hexes += strToHex(str.left(1)); str.remove(0,1); } while(!c->atBlockEnd()) // remove c->deleteChar(); c->insertText(hexes); }
/* Send the contents of the commandLine to the serial port, and add them to the output console */ void UsbConsole::onCommandLine( ) { if(port->isOpen() && !commandLine->currentText().isEmpty()) { if(port->write(commandLine->currentText().toUtf8()) < 0) closeDevice(); else { QTextBlockFormat format; format.setBackground(QColor(229, 237, 247, 255)); // light blue if(currentView == "Characters") outputConsole->appendPlainText(commandLine->currentText()); // insert the message else if(currentView == "Hex") outputConsole->appendPlainText(strToHex(commandLine->currentText())); outputConsole->moveCursor(QTextCursor::End); // move the cursor to the end outputConsole->textCursor().setBlockFormat(format); outputConsole->insertPlainText("\n"); format.setBackground(Qt::white); // reset the format to white for any subsequent messages received outputConsole->textCursor().setBlockFormat(format); } commandLine->clear(); } }
/* * Core routine to convert a single string token to a uint32. Incoming token can * be in the form of a string from the specified MDSNameValuePair table or a literal * number, either in hex (prefix "0x") or decimal. Tokens in any form may be * prefixed by "<<" indicating the value is to be shifted left by 16 bits. */ CSSM_RETURN MDSAttrNameToValue( const char *name, const MDSNameValuePair *table, // optional, string must be decimal or hex if NULL uint32 &value) // RETURNED { if(name == NULL) { return CSSMERR_CSSM_MDS_ERROR; } if(*name == '\0') { /* empty string, legal */ value = 0; return CSSM_OK; } /* prefixed by "<<"? */ bool shiftBy16 = false; if((name != NULL) && (name[0] == '<') && (name[1] == '<')) { shiftBy16 = true; name += 2; } /* attempt to find the string in lookup table */ if(table != NULL) { while(table->name != NULL) { if(!strcmp(table->name, name)) { value = table->value; if(shiftBy16) { value <<= 16; } return CSSM_OK; } table++; } } /* not found - is the string a number? */ if(isdigit(name[0])) { bool isNum; bool isHex = false; if((name[0] == '0') && (name[1] == 'x')) { /* hex - skip first two chars */ isHex = true; name += 2; isNum = isNumericStr(name, true); } else { isNum = isNumericStr(name, false); } if(!isNum) { return CSSMERR_CSSM_MDS_ERROR; } if(isHex) { value = strToHex(name); } else { value = atoi(name); } if(shiftBy16) { value <<= 16; } return CSSM_OK; } else { /* not a number */ return CSSMERR_CSSM_MDS_ERROR; } }