Skip to content

Commit 03dfc94

Browse files
committed
send_raw major impovements
1 parent bcb3d4a commit 03dfc94

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/Pelco_And_Arduino.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,39 @@ int PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
176176
return messFromcamera[4]; //Returns MSB
177177
}
178178

179-
void PelcoCam::send_raw(uint8_t raw_command[]){
180-
if(raw_command[0]!=0xFF) return;
179+
void PelcoCam::send_raw(String hex_string){
180+
hex_string.replace(" ", ""); //Replace spaces
181181

182+
int size = hex_string.length()/2; //Size of the string without space
183+
byte raw_command[size]; //the final command
184+
char buffer[3]; //A buffer, to convert the string into an array of char
185+
186+
for(int i=0; i<=size; i++){ //Loops to every char in in the string
187+
hex_string.substring(i*2, i*2+2).toCharArray(buffer, sizeof(buffer));//Slices the string into 2 pair of "bytes" and convert them into char arry
188+
raw_command[i] = (byte) strtol(buffer, NULL, 16); //conversion into byte
189+
}
190+
191+
192+
if(raw_command[0]!=0xFF) return; //Check sync byte
193+
194+
/////Check checksum
182195
uint8_t checksum = (raw_command[1] + raw_command[2] + raw_command[3] + raw_command[4] + raw_command[5])%0x100;
183196
if(checksum != raw_command[6]){
184197
if(log_messages_) Serial.println("Wrong chacksum, updating to right checksum");
185198

186199
raw_command[6] = checksum;
187200
}
188201

189-
SerialCam.write(messToCamera, sizeof(messToCamera));
202+
if(log_messages_){
203+
Serial.print("Sending message: ");
204+
for(int i=0; i<size; i++){
205+
Serial.printf("%02X", raw_command[i]);
206+
Serial.print(" ");
207+
}
208+
Serial.println();
209+
}
210+
//write the command to the camera
211+
SerialCam.write(raw_command, sizeof(raw_command));
190212
}
191213

192214
/*!

src/Pelco_And_Arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class PelcoCam {
103103
void begin();
104104
void send_command(uint8_t command, uint8_t params=0x00, uint8_t params2=0x00);
105105
int send_request(uint8_t request, uint timeout = 1000, uint max_buffer=20);
106-
void send_raw(uint8_t raw_command[]);
106+
void send_raw(String hex_string);
107107

108108
};
109109

0 commit comments

Comments
 (0)