New functions scan_hex ...
FossilOrigin-Name: 9e672fa96f74307bac2cb2e3797697dddca25bb98e3c26d2c560e4a168c620af
This commit is contained in:
		@ -15,6 +15,8 @@
 | 
				
			|||||||
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
					    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @file
 | 
					 * @file
 | 
				
			||||||
 * @brief Implementation of various format functions.
 | 
					 * @brief Implementation of various format functions.
 | 
				
			||||||
@ -57,5 +59,54 @@ int cw_format_hex_bytes(char *dst, const char *format, const char *delim,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Read hex bytes from a string to an uint8_t array
 | 
				
			||||||
 | 
					 * @param dst destination array
 | 
				
			||||||
 | 
					 * @param s string to read
 | 
				
			||||||
 | 
					 * @param len length of string
 | 
				
			||||||
 | 
					 * @return 0 if all was ok \n 1 if an error has occured.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int cw_format_scan_hex_bytes(uint8_t *dst,const char *s, int len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc ;
 | 
				
			||||||
 | 
						int err=0;
 | 
				
			||||||
 | 
						int val;
 | 
				
			||||||
 | 
						int c;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ( len & 1){
 | 
				
			||||||
 | 
							rc = sscanf(s,"%01X",&c);
 | 
				
			||||||
 | 
							if (rc!=1){
 | 
				
			||||||
 | 
								c=0;
 | 
				
			||||||
 | 
								err=1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							*dst++=c;
 | 
				
			||||||
 | 
							s++;
 | 
				
			||||||
 | 
							len--;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i=0; i<len; i++){
 | 
				
			||||||
 | 
							rc = sscanf(s+i,"%01X",&c);
 | 
				
			||||||
 | 
							if (rc!=1){
 | 
				
			||||||
 | 
								c=0;
 | 
				
			||||||
 | 
								err=1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!(i&1)) {
 | 
				
			||||||
 | 
								val = c<<4;	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else{
 | 
				
			||||||
 | 
								val |= c;
 | 
				
			||||||
 | 
								*dst++=val;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user