@@ -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/* !
0 commit comments