S&B Volcano vaporizer remote control with Pi Pico W
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * models.c
  3. *
  4. * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stddef.h>
  19. #include <string.h>
  20. #include "config.h"
  21. #include "log.h"
  22. #include "util.h"
  23. #include "models.h"
  24. enum known_devices models_filter_name(const char *name) {
  25. if (name == NULL) {
  26. return DEV_UNKNOWN;
  27. } else if (strcmp(name, "S&B VOLCANO H") == 0) {
  28. return DEV_VOLCANO;
  29. } else if (strcmp(name, "STORZ&BICKEL") == 0) {
  30. return DEV_CRAFTY;
  31. } else if (str_startswith(name, "S&B VY")) {
  32. return DEV_VENTY;
  33. } else {
  34. return DEV_UNKNOWN;
  35. }
  36. }
  37. int8_t models_get_serial(enum known_devices dev, const char *name,
  38. const uint8_t *data, size_t data_len,
  39. char *buff, size_t buff_len) {
  40. if ((name == NULL) || (data == NULL)
  41. || (buff == NULL) || (buff_len <= 0)) {
  42. return -1;
  43. }
  44. size_t serial_len, serial_off, src_len;
  45. const uint8_t *src;
  46. switch (dev) {
  47. case DEV_VOLCANO:
  48. case DEV_CRAFTY:
  49. serial_len = 8;
  50. serial_off = 2;
  51. src = data;
  52. src_len = data_len;
  53. break;
  54. case DEV_VENTY:
  55. serial_len = 8;
  56. serial_off = 4;
  57. src = (const uint8_t *)name;
  58. src_len = strlen(name);
  59. break;
  60. default:
  61. return -2;
  62. }
  63. if ((src_len < (serial_len + serial_off)) || (buff_len < (serial_len + 1))) {
  64. return -3;
  65. }
  66. memcpy(buff, src + serial_off, serial_len);
  67. buff[serial_len] = '\0';
  68. return 0;
  69. }