Compare commits

...

9 Commits
v1.0.0 ... main

Author SHA1 Message Date
DrMaxNix 369c13f9f9 📝 migrate to git.tjdev.de 2023-03-22 20:21:49 +01:00
DrMaxNix 66f207399f 🎨 fix inconsistent indentation 2022-09-16 18:01:51 +02:00
DrMaxNix f624a2ed7e
🔖 bump version badge to v1.0.2 2022-04-29 19:23:20 +02:00
DrMaxNix e37b471763
🔖 bump version to v1.0.2 2022-04-29 19:22:34 +02:00
DrMaxNix 315baa70cf
🔖 bump version to v1.0.2 2022-04-29 19:19:40 +02:00
DrMaxNix b4f5170269
🏷️ change some more counter type 2022-04-29 19:18:54 +02:00
DrMaxNix a5d1ecb3aa
🏷️ optimize counter type for `optind` loop 2022-04-29 19:09:38 +02:00
DrMaxNix bf39c2a60b
🏷️ make booleans have correct type 2022-04-29 18:52:56 +02:00
DrMaxNix ba3511c4e7
📝 adapt to new version format 2022-04-27 18:49:31 +02:00
2 changed files with 15 additions and 15 deletions

View File

@ -1,6 +1,6 @@
# phoenix-upshid
[![GitHub release](https://img.shields.io/badge/release-v1.0.1-orange)](https://github.com/DrMaxNix/phoenix-upshid/releases/tag/1.0.1)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/DrMaxNix/phoenix-upshid/blob/main/LICENSE)
[![Release](https://img.shields.io/badge/release-v1.0.2-orange)](https://git.tjdev.de/DrMaxNix/phoenix-upshid/releases/tag/v1.0.2)
[![License](https://img.shields.io/badge/license-MIT-green)](https://git.tjdev.de/DrMaxNix/phoenix-upshid/src/branch/main/LICENSE)
[![Maintaner](https://img.shields.io/badge/maintainer-DrMaxNix-blue)](https://www.drmaxnix.de)
Simple driver for reading data from Phoenixtec ("Amazon Basics") UPSes written in c
@ -14,16 +14,16 @@ I tried multiple drivers for it, but they all had their problems:
So I tried writing dirty fixes for both of those drivers, which would reset the USB connection when detecting such problem. But it wasn't as stable as I had hoped.
At the end I [reverse-engineered](https://github.com/DrMaxNix/phoenix-upshid/blob/main/nut-reverseengineering.md) the USB-HID protocol of the UPS and wrote my own driver for it in c, which has the reset-capability built-in. I'm not at all into c driver development, so use this at your own risk, as the license already states: "WITHOUT WARRANTY OF ANY KIND"!
At the end I [reverse-engineered](https://git.tjdev.de/DrMaxNix/phoenix-upshid/src/branch/main/nut-reverseengineering.md) the USB-HID protocol of the UPS and wrote my own driver for it in c, which has the reset-capability built-in. I'm not at all into c driver development, so use this at your own risk, as the license already states: "WITHOUT WARRANTY OF ANY KIND"!
## How to use
Download and extract source and compile:
```console
$ wget https://github.com/DrMaxNix/phoenix-upshid/archive/refs/tags/1.0.1.tar.gz
$ tar xf 1.0.1.tar.gz
$ cd phoenix-upshid-1.0.1
$ wget https://git.tjdev.de/DrMaxNix/phoenix-upshid/archive/v1.0.2.tar.gz
$ tar xf v1.0.2.tar.gz
$ cd phoenix-upshid
$ gcc -o phoenix-upshid phoenix-upshid.c
```

View File

@ -58,7 +58,7 @@ void print_version();
// PUBLIC FLAGS //
int auto_usbreset = false;
bool auto_usbreset = false;
uint16_t vendor_id;
uint16_t product_id;
@ -108,7 +108,7 @@ int main(int argc, char **argv){
}
// parse
for(size_t q = optind; q < argc; q++){
for(int q = optind; q < argc; q++){
if(q == optind){
// make sure string has a collon in it
char *arg_id = argv[q];
@ -396,7 +396,7 @@ void output_data(){
// charge and remaining time
int values_res;
char values_buffer[64];
for(size_t q = 0; q <= 1; q++){
for(int q = 0; q <= 1; q++){
values_buffer[0] = 0x06;
values_res = ioctl(hid, HIDIOCGFEATURE(256), values_buffer);
if(values_res >= 4){
@ -421,7 +421,7 @@ void output_data(){
// flaggs (charging, discharging, line power, low battery)
int flaggs_res;
char flaggs_buffer[64];
for(size_t q = 0; q <= 1; q++){
for(int q = 0; q <= 1; q++){
flaggs_buffer[0] = 0x01;
flaggs_res = ioctl(hid, HIDIOCGFEATURE(256), flaggs_buffer);
if(flaggs_res >= 5){
@ -482,22 +482,22 @@ void usbreset(){
// DO RESET //
// send command
if(ioctl(bus, USBDEVFS_RESET, 0) < 0){
fprintf(stderr, "[WARN ] Unable to do usbreset\n");
fprintf(stderr, "[WARN ] Unable to do usbreset\n");
return;
}
}
// success!
fprintf(stderr, "[INFO ] Usbreset successful\n");
fprintf(stderr, "[INFO ] Usbreset successful\n");
// close file
close(bus);
close(bus);
}
/*
HELPER: Print version and exit
*/
void print_version(){
printf("phoenix-upshid v1.0.1 | (c) DrMaxNix 2022 | www.drmaxnix.de/phoenix-upshid\n");
printf("phoenix-upshid v1.0.2 | (c) DrMaxNix 2022 | www.drmaxnix.de/phoenix-upshid\n");
exit(0);
}