-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_write_block.cpp
More file actions
58 lines (47 loc) · 1.18 KB
/
cmd_write_block.cpp
File metadata and controls
58 lines (47 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* cmd_write_block.cpp
*
* Created on: Feb 27, 2020
* Author: raltmeyer
*
* Implements a command
*
*/
#include "28c_programmer.h"
#include <Arduino.h>
const static char msg_ok[] PROGMEM = "#WRBK_OK";
const static char msg_dataerror[] PROGMEM = "#ERROR_DATA_ERROR";
//*********
//* Write a sequence of N bytes stating on address
//* WRBK:address:data1:data2:....:data16
//* WRBK:0000:01:02:...:16
void cmd_write_block(char buffer[]) {
int param = 0;
unsigned int address = 0;
char *tok;
// Parse command and parameters
tok = strtok(buffer, ":");
SDPmode(0); // disable data protection
while ((tok != NULL)) {
// Address
if (param == 1) {
address = strtoul(tok, NULL, 16);
// Read data com parameter and write to flash
} else if (param >= 2) {
byte data;
if (!checkAddress(address)) {
return;
}
if (strlen(tok) == 0) {
Serial.println(getProgMemString(msg_dataerror));
}
data = strtoul(tok, NULL, 16);
flashWrite(address, data);
address++;
}
tok = strtok(NULL, ":");
param++;
}
SDPmode(1); // re-enable data protection
Serial.println(getProgMemString(msg_ok));
}