22 * Module to add and remove Python scripts into and from a MicroPython hex.
33 */
44import MemoryMap from 'nrf-intel-hex' ;
5+ import { bytesToStr , strToBytes } from './common' ;
56
67const enum UserCodeBlock {
78 /** User script located at specific flash address. */
@@ -27,34 +28,6 @@ const enum UserCodeBlock {
2728 */
2829const HEX_INSERTION_POINT = ':::::::::::::::::::::::::::::::::::::::::::\n' ;
2930
30- /**
31- * Converts a string into a byte array of characters.
32- * TODO: Update to encode to UTF-8 correctly.
33- * @param str - String to convert to bytes.
34- * @returns A byte array with the encoded data.
35- */
36- function strToBytes ( str : string ) : Uint8Array {
37- const data : Uint8Array = new Uint8Array ( str . length ) ;
38- for ( let i : number = 0 ; i < str . length ; i ++ ) {
39- // TODO: This will only keep the LSB from the UTF-16 code points
40- data [ i ] = str . charCodeAt ( i ) ;
41- }
42- return data ;
43- }
44-
45- /**
46- * Converts a byte array into a string of characters.
47- * TODO: This currently only deals with single byte characters, so needs to
48- * be expanded to support UTF-8 characters longer than 1 byte.
49- * @param byteArray - Array of bytes to convert.
50- * @returns String output from the conversion.
51- */
52- function bytesToStr ( byteArray : Uint8Array ) : string {
53- const result : string [ ] = [ ] ;
54- byteArray . forEach ( ( element ) => result . push ( String . fromCharCode ( element ) ) ) ;
55- return result . join ( '' ) ;
56- }
57-
5831/**
5932 * Removes the old insertion line the input Intel Hex string contains it.
6033 * @param intelHex String with the intel hex lines.
0 commit comments