Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP Implementation? #1

Open
pasleto opened this issue Dec 1, 2023 · 2 comments
Open

CP Implementation? #1

pasleto opened this issue Dec 1, 2023 · 2 comments

Comments

@pasleto
Copy link

pasleto commented Dec 1, 2023

Hi,

Would CP mode be possible with you approach? If so, could you provide basic example?

Thanks!

@vk2tds
Copy link
Owner

vk2tds commented Dec 1, 2023

Greetings.... To be honest I think the CP would work this way, but I can't see any decent examples in the original library of CP usage. [CP being of course Control Panel]. Python is likely the most comprehensive example for CP, and it is not that much more extensive than the others.

What I have not uploaded yet on this code is the command handler for the PD. My code appears below as an aide to show you how I am doing things.

My personal code is working well, with multiple virtual PD's and multiple wiegand readers working on a STM32F411 rather well. I must say that I am occasionally get a repeated packet from the InnerRange Inception which causes the secure channel (SC) to drop out. I think I know the cause, but am working on it. I suspect that the Inception is doing something different from the library when packets are repeated. Doing a test right now. I am looking at turning my code into a product. But we will see.

I can't see any reason why CP wouldnt work.

`int pd_command_handler(void *self, struct osdp_cmd *cmd)
{
// need to cast *self
// int8_t index = self->id.version; TODO
int8_t index = 0;

switch (cmd->id){
case OSDP_CMD_MFG:
//Serial.println ("MFG");
return -9; // We dont know any user defined commands
break;
case OSDP_CMD_OUTPUT:
Serial.println ("***** OUTPUT - NOT YET IMPLEMENTED *");
return 0;
break;
case OSDP_CMD_SENTINEL:
Serial.println ("
SENTINEL - NOT YET IMPLEMENTED ******");
return 0;
break;

case OSDP_CMD_KEYSET:
  Serial.println ("***** KEYSET - NOT YET EXTENSIVELY TESTED ******");
  // ToDo: Check length
  if (cmd->keyset.type == 1){ // only key_type == 1 (SCBK) and key_len == 16 is supported
    for (int8_t i = 0; i < cmd->keyset.length; i++){
      settings.scbk[i] = cmd->keyset.data[i];
      //if (cmd->keyset.data[i]<0x10) {Serial.print("0");}
      //Serial.print (cmd->keyset.data[i],HEX);
    }
    //Serial.println("");

  settings_save();
    
  }
  return 0;
  break;



case OSDP_CMD_LED:
  // Compliance 0 = On/Off. 1 = Timed. 2 = Plus bi-colored LED. 3 = plus tri-coloured LED
  Serial.println ("LED");


  switch (cmd->led.temporary.control_code){
    case 0:
      // ignore
      break;
    case 1:
      // cancel temp and immediate perm
      reader[0].LED_temp.trigger( reader[0].LED_temp.EVT_OFF );
      reader[0].LED_perm.trigger( reader[0].LED_perm.EVT_START );
      //set_perm_led (0);
      break;
    case 2:
      // set temp and start
      reader[0].LED_temp.blink(
        cmd->led.temporary.on_count * 100, 
        cmd->led.temporary.off_count * 100, 
        cmd->led.temporary.timer_count / (cmd->led.temporary.off_count + cmd->led.temporary.on_count))
        .start()
        .onFinish (reader[0].LED_perm, reader[0].LED_temp.EVT_BLINK);
      //reader[0].LED.trigger( reader[0].LED.EVT_OFF );
      break;
  }

  switch (cmd->led.permanent.control_code){
    case 0:
      // ignore
      break;
    case 1:
      // set LED start
      int8_t on_c = cmd->led.permanent.on_color;
      int8_t off_c = cmd->led.permanent.off_color;
      // set LED start
      reader[0].LED_temp.trigger( reader[index].LED_temp.EVT_OFF );
      if ((on_c == 0) & (off_c == 0)){
        cmd->led.permanent.on_count = 0;
        cmd->led.permanent.off_count = 10;
      } else if ((on_c == 1) & (off_c == 1)){ // Hack for InnerRange Inception
        cmd->led.permanent.on_count = 0;
        cmd->led.permanent.off_count = 10;
      } else if (on_c == off_c) {
        cmd->led.permanent.on_count = 10;
        cmd->led.permanent.off_count = 0;
      }
      reader[index].LED_perm.blink(
          cmd->led.permanent.on_count * 100, 
          cmd->led.permanent.off_count * 100)
          .start();
      reader[index].LED_on_count = cmd->led.permanent.on_count;
      reader[index].LED_off_count = cmd->led.permanent.off_count;
      break;
  }

  
  
case OSDP_CMD_BUZZER:
  switch (cmd->buzzer.control_code){
    case 0:
    case 1:
      reader[0].buzzer.trigger( reader[0].buzzer.EVT_OFF );
      break;
    case 2:
      reader[0].buzzer.blink(cmd->buzzer.on_count * 100, cmd->buzzer.off_count * 100, cmd->buzzer.rep_count).start();
      break;
  }
  return 0;
  break;
case OSDP_CMD_COMSET:
  // Ignore change in baud rate
  if (cmd->comset.address != settings.osdp_address[0]){
    settings.osdp_address[0] = cmd->comset.address;
    Serial.println ("Address changed!!!");
    settings_save();
  }
default:
  Serial.println ("***** UNKNOWN - NOT YET IMPLEMENTED******");
  Serial.print ("Unknown CMD: ");
  Serial.println (cmd->id);

}
return 0;
}

`

@pasleto
Copy link
Author

pasleto commented Dec 18, 2023

Thank you for your response! After your comment i have managed to create PoC for CP implementation with HID reader and ESP32. Not quite working as intended yet, but atleast something. You are right about the examples on libosdp repo, they are not that useful. But the documentation and inspecting your code helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants