Skip to content

Commit bcb3d4a

Browse files
committed
send_raw added and QoF impovements
1 parent 5f1c5df commit bcb3d4a

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/Pelco_And_Arduino.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void PelcoCam::send_command(uint8_t command, uint8_t params, uint8_t params2){
103103
* @return true if succeded, false if an error occured
104104
*/
105105

106-
bool PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
106+
int PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
107107
byte response_command;
108108

109109
if(request == QUERY_PAN){response_command == RESP_PAN;}
@@ -112,15 +112,15 @@ bool PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
112112
else if(request == QUERY_FOCUS){response_command = RESP_FOCUS;}
113113
else{
114114
if(log_messages_) Serial.println("No valid request provided");
115-
return false;
115+
return -1;
116116
}
117117

118118
send_command(request); //Send the query
119119

120120
while (!SerialCam.available()){//Wait for the first bit
121121
if (timeout==0){ //If timeout is reached
122122
if(log_messages_) Serial.print("ERROR timout reached");
123-
return false;
123+
return -1;
124124
}
125125
timeout--;
126126
delayMicroseconds(10);
@@ -148,7 +148,7 @@ bool PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
148148
|| command_index < 3 //Checks if the reponse byte is in the right place
149149
){
150150
if(log_messages_)Serial.println("Warn: no reponse from camera");
151-
return false;
151+
return -1;
152152
}
153153

154154
//Checksum is sum of everything except sync modulo 0x100
@@ -158,7 +158,7 @@ bool PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
158158
if(buffer[command_index-3] != 0xFF &&
159159
buffer[command_index-2 != 00] &&
160160
!checksum){
161-
return false;
161+
return -1;
162162
}
163163

164164
for(int i=0; i<7; i++){
@@ -173,7 +173,20 @@ bool PelcoCam::send_request(uint8_t request, uint timeout, uint maxbuffer){
173173
Serial.println();
174174
}
175175

176-
return true;
176+
return messFromcamera[4]; //Returns MSB
177+
}
178+
179+
void PelcoCam::send_raw(uint8_t raw_command[]){
180+
if(raw_command[0]!=0xFF) return;
181+
182+
uint8_t checksum = (raw_command[1] + raw_command[2] + raw_command[3] + raw_command[4] + raw_command[5])%0x100;
183+
if(checksum != raw_command[6]){
184+
if(log_messages_) Serial.println("Wrong chacksum, updating to right checksum");
185+
186+
raw_command[6] = checksum;
187+
}
188+
189+
SerialCam.write(messToCamera, sizeof(messToCamera));
177190
}
178191

179192
/*!

src/Pelco_And_Arduino.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const uint8_t PROGMEM SET_ZOOM_SPEED = 0x25; //Param from 00 to 03
3535
const uint8_t PROGMEM FOCUS_F = 0x80;
3636
const uint8_t PROGMEM FOCUS_N = 0x01;//!!!!not byte 4 but 3
3737
const uint8_t PROGMEM SET_FOCUS_SPEED = 0x27; //Param from 00 to 03
38-
const uint8_t PROGMEM AUTO_FOCUS = 0x2B; //Param from 00 to 02
38+
const uint8_t PROGMEM AUTO_FOCUS = 0x2B; //Param from 00 to 02 (auto/on/off)
3939

4040
const uint8_t PROGMEM STOP = 0x00;
4141

@@ -102,7 +102,8 @@ class PelcoCam {
102102
PelcoCam(uint8_t Address, int baud, int txPin, int rxPin, bool log_messages);
103103
void begin();
104104
void send_command(uint8_t command, uint8_t params=0x00, uint8_t params2=0x00);
105-
bool send_request(uint8_t request, uint timeout = 1000, uint max_buffer=20);
105+
int send_request(uint8_t request, uint timeout = 1000, uint max_buffer=20);
106+
void send_raw(uint8_t raw_command[]);
106107

107108
};
108109

0 commit comments

Comments
 (0)