2
2
* Module to add and remove Python scripts into and from a MicroPython hex.
3
3
*/
4
4
import MemoryMap from 'nrf-intel-hex' ;
5
+ import { bytesToStr , strToBytes } from './common' ;
5
6
6
7
const enum UserCodeBlock {
7
8
/** User script located at specific flash address. */
@@ -27,34 +28,6 @@ const enum UserCodeBlock {
27
28
*/
28
29
const HEX_INSERTION_POINT = ':::::::::::::::::::::::::::::::::::::::::::\n' ;
29
30
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
-
58
31
/**
59
32
* Removes the old insertion line the input Intel Hex string contains it.
60
33
* @param intelHex String with the intel hex lines.
0 commit comments