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

MCP39F511N metrics provider #429

Merged
merged 4 commits into from
Oct 20, 2023
Merged

MCP39F511N metrics provider #429

merged 4 commits into from
Oct 20, 2023

Conversation

ArneTR
Copy link
Member

@ArneTR ArneTR commented Aug 16, 2023

@ribalba Can you give the C code a quick read.

As said in the file: I am including a library of unknown original origin.

This file is mostly copied from https://github.com/osmhpi/pinpoint/blob/master/src/data_sources/mcp_com.c
Credits to Sven Köhler and the OSM group from the HPI

In case the file is not original work: Possible prior origins of the file are unknown. However it is an implementation
of the protocol defined here:
- https://www.microchip.com/en-us/development-tool/ADM00706
- https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20005473B.pdf

@ArneTR ArneTR requested a review from ribalba August 16, 2023 08:37
@github-actions
Copy link

Eco-CI Output:

Label 🖥 avg. CPU utilization [%] 🔋 Total Energy [Joules] 🔌 avg. Power [Watts] Duration [Seconds]
Total Run 21.1555 2286 3.00394 771
Measurement #1 21.2793 2286 3.00394 764

📈 Energy graph:

 
 5.89 ┤                                        ╭╮                     ╭╮                                                                            ╭───╮                      ╭──────╮   ╭───╮╭─╮
 5.47 ┤            ╭╮                          ││                 ╭╮  ││                                                                            │   ╰╮   ╭─╮╭╮             │      ╰╮  │   ││ │
 5.04 ┤            │╰╮  ╭─╮              ╭╮╭╮ ╭╯│          ╭╮╭╮ ╭─╯│ ╭╯│         ╭╮      ╭──╮   ╭╮╭╮    ╭─╮               ╭╮   ╭╮     ╭╮   ╭╮       │    ╰╮╭─╯ ╰╯╰╮            │       ╰╮ │   ╰╯ ╰╮       ╭╮  ╭──╮                                                                                                                                      ╭╮                                            ╭╮            ╭╮                                                                            ╭╮                           ╭╮                                                                                  ╭╮                     ╭╮                                ╭╮              ╭╮                                                                 ╭╮ ╭╮                          ╭
 4.62 ┤      ╭╮╭╮ ╭╯ │╭─╯ ╰───────────╮╭─╯╰╯╰─╯ ╰──────────╯╰╯╰─╯  ╰─╯ ╰╮╭─────╮╭╯╰─────╮│  ╰───╯╰╯│    │ │╭╮ ╭╮╭─────────╯╰───╯╰─────╯╰───╯╰───────╯     ││      │            │        │ │       │       │╰╮ │  ╰─╮                           ╭╮                     ╭╮                      ╭╮         ╭─╮                                            ││          ╭╮                                ││          ╭─╯│                         ╭╮                                                 ││                           ││                         ╭──╮                         ╭─╮          ╭╮╭╮        ╭╮ │╰╮                    ││                                ││           ╭╮ ││╭╮                       ╭╮                        ╭╮            ││ ││                         ╭╯
 4.20 ┤      ││││ │  ╰╯               ╰╯                                ││     ╰╯       ││         ╰╮╭╮ │ ╰╯╰─╯╰╯                                         ╰╯      │           ╭╯        │╭╯       │       │ │╭╯    │                          ╭╯│         ╭╮          ││         ╭─╮         ╭╯│         │ │                     ╭╮         ╭─╮         │╰╮         ││         ╭╮          ╭╮         ││          │  │         ╭╮           ╭─╮││                     ╭───╮                  ╭╮ ╭╮││          ╭╮╭╮        ╭╮ ╭─╯│          ╭╮          ╭╮ │  │         ╭╮              │ │          ││││        ││ │ │                    ││                                │╰╮          ││ ││││          ╭─╮          ││            ╭╮          ││            │╰╮││          ╭╮          ╭╮ │
 3.78 ┤      │││╰─╯                                                     ││              ╰╯          │││ │                                                         │╭╮         │         ╰╯        │       │ ││     │          ╭╮╭╮        ╭╮ ╭╯ │         ││         ╭╯│         │ │         │ │         │ │         ╭─╮         ││         │ │         │ │         ││         ││          ││         │╰╮         │  │         ││        ╭╮ │ ╰╯│                  ╭╮ │   │                  ││ │╰╯│          ││││        ││ │  │          ││╭╮        ││ │  │         │╰╮         ╭─╮╭╯ ╰╮         ││││        ││ │ │         ╭╮         │╰╮                               │ │          │╰╮││││          │ │         ╭╯│╭╮          ││         ╭╯│            │ ╰╯│          ││╭╮        ││ │
 3.36 ┤    ╭─╯╰╯                                                        ╰╯                          ╰╯│╭╯                                                         ╰╯│        ╭╯                   │      ╭╯ ╰╯     ╰╮       ╭─╯╰╯╰╮       │╰╮│  │         ││         │ ╰╮        │ │         │ ╰╮        │ ╰╮        │ │         │╰╮        │ │         │ │         │╰╮        │╰╮        ╭╯│         │ │         │  ╰╮        │╰╮       │╰╮│   │         ╭╮       │╰╮│   │        ╭╮        │╰╮│  ╰╮       ╭─╯╰╯╰╮       │╰╮│  ╰╮       ╭─╯╰╯│        ││ │  │        ╭╯ ╰─╮       │ ││   │       ╭─╯│││        ││ │ │         ││         │ │         ╭╮         ╭╮        ╭╯ │        ╭─╯ ╰╯│││        ╭╮│ │        ╭╯ │││         ╭╯│        ╭╯ │╭╮       ╭╮ │   ╰╮       ╭─╯│││       ╭╯│ │
 2.93 ┤    │                                                                                          ╰╯                                                            │    ╭─╮ │                    │      │          │       │     │       │ ││  │         │╰╮        │  │        │ ╰╮        │  │        │  │        │ │        ╭╯ │        │ │         │ │         │ │        │ │        │ │         │ │         │   │        │ │       │ ││   │        ╭╯│       │ ││   │        │╰╮       │ ││   │       │     │       │ ││   │       │    │       ╭╯│ │  │       ╭╯    │       │ ││   │       │  ╰╯│        ││ │ │         ││        ╭╯ │        ╭╯│        ╭╯│        │  ╰╮       │     │││        │││ │        │  ││╰╮      ╭╮│ ╰╮       │  │││       ││╭╯    │       │  ╰╯│       │ │╭╯
 2.51 ┤    │                                                                                                                                                        │    │ │ │                    ╰╮     │          │       │     │       │ ││  │         │ │ ╭╮     │  │        │  │        │  │       ╭╯  │        │ │        │  │        │ │         │ │         │ │        │ │        │ │         │ ╰╮        │   │       ╭╯ │       │ ││   │        │ │       │ ││   │        │ │       │ ││   │       │     │       │ ││   │       │    │       │ ╰─╯  │       │     │       │ ││   │       │    │        │╰╮│ │         ││        │  │        │ │        │ │        │   │       │     │││       ╭╯││ ╰╮       │  ││ │      │││  │       │  ╰╯│       │││     │       │    │       │ ││
 2.09 ┼╮  ╭╯                                                                                                                                                        ╰────╯ │ │                     │     │          ╰─╮     │     │   ╭╮╭╮│ ╰╯  ╰╮╭╮╭╮  ╭─╯ ╰╮││     │  ╰─╮   ╭╮╭╯  │       ╭╯  │   ╭╮╭╮│   │   ╭╮╭╮╭╯ │  ╭╮   ╭╯  │╭╮     ╭╯ ╰╮╭╮      │ │ ╭╮  ╭──╮│ ╰╮╭╮    ╭╯ │    ╭╮ ╭╯ │╭╮     ╭╮│  │╭╮  ╭╮ ╭╯   ╰╮ ╭╮ ╭╮│  │      ╭╯ ╰╯   ╰╮╭╮    ╭╯ │    ╭╮ │ ││   │╭╮   ╭─╮│ │ ╭─╮  ╭╯ ││   │       │     ╰╮╭╮ ╭╮╭╯ ││   ╰──╮  ╭╮│    ╰╮    ╭╮│      │╭╮╭─╮  │     ╰╮      │ ││   │ ╭─╮╭╮╭╯    ╰╮   ╭╮ ╭╯ ╰╯ ╰╮╭╮     ╭╯╰╮╭╮   ╭─╯  ╰─╮╭╮    │ │  ╭╮   ╭╯ │ ╭╮  ╭╮╭╯   ╰─╮  ╭╮ │     ╰╯╰╮ ╭──╮ │ ││  ╰╮ ╭╮   │  ╰╯ │     ╭╯││  │╭╮╭─╮  │    │╭─╮╭╮╭╮│││     │  ╭╮   │    │ ╭╮ ╭╮╭╯ ││
 1.67 ┤╰──╯                                                                                                                                                                ╰─╯                     ╰─────╯            ╰─────╯     ╰───╯╰╯╰╯      ╰╯╰╯╰──╯    ╰╯╰─────╯    ╰───╯╰╯   ╰───────╯   ╰───╯╰╯╰╯   ╰───╯╰╯╰╯  ╰──╯╰───╯   ╰╯╰─────╯   ╰╯╰──────╯ ╰─╯╰──╯  ╰╯  ╰╯╰────╯  ╰────╯╰─╯  ╰╯╰─────╯╰╯  ╰╯╰──╯╰─╯     ╰─╯╰─╯╰╯  ╰──────╯        ╰╯╰────╯  ╰────╯╰─╯ ╰╯   ╰╯╰───╯ ╰╯ ╰─╯ ╰──╯  ╰╯   ╰───────╯      ╰╯╰─╯╰╯  ╰╯      ╰──╯╰╯     ╰────╯╰╯      ╰╯╰╯ ╰──╯      ╰──────╯ ╰╯   ╰─╯ ╰╯╰╯      ╰───╯╰─╯      ╰╯╰─────╯  ╰╯╰───╯      ╰╯╰────╯ ╰──╯╰───╯  ╰─╯╰──╯╰╯      ╰──╯╰─╯        ╰─╯  ╰─╯ ╰╯   ╰─╯╰───╯     ╰─────╯ ╰╯  ╰╯╰╯ ╰──╯    ╰╯ ╰╯╰╯╰╯╰╯     ╰──╯╰───╯    ╰─╯╰─╯╰╯  ╰╯
                                                                                                                                                                                                                                                                                                                                                                                            Watts over time

Copy link
Member

@ribalba ribalba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an initial quick read. Is this something we want to maintain for the future? The I would probably refactor it. I can do this :)

printf("\t-i : specifies the milliseconds sleep time that will be slept between measurements\n\n");
exit(0);
case 'i':
msleep_time = atoi(optarg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is msleep_time global and not in main?

sizeof(f511_set_accumulation_interval),
(unsigned char *)&reply, fd);
if(res < 0) return res;
return fd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is fd defined? Or is this the global fd? Why return it then?


setvbuf(stdout, NULL, _IONBF, 0);

long fd = f511_init("/dev/ttyACM0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function returns an int but is long here? And fd is already defined globally?


command_packet[0] = 0xa5;
command_packet[1] = cmd_length + 3;
memcpy(command_packet + 2, cmd, cmd_length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd and cmd_length are not checked if they fit into cmd

for (i = 0; i < cmd_length + 2; i++) {
checksum += command_packet[i];
}
command_packet[i] = checksum;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why if cmd_length is > 80

}
command_packet[i] = checksum;
tcflush(fd, TCIOFLUSH);
len = write(fd, command_packet, cmd_length + 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is fd passed as a parameter if it is defined globally?


const unsigned char f511_read_active_power[] = { 0x41, 0x0, 0x16, 0x4E, 8 };
const unsigned char f511_read_active_power1[] = { 0x41, 0x0, 0x16, 0x4E, 4 };
const unsigned char f511_read_active_power2[] = { 0x41, 0x0, 0x1a, 0x4E, 4 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between these read power chars?

* main: (103 commits)
  Removing some noise debug
  BCC typos
  Bump actions/checkout from 3 to 4 (#450)
  Bump orjson from 3.9.7 to 3.9.9 (#506)
  Bump fastapi from 0.103.2 to 0.104.0 (#511)
  Added BCC functionality for email sending (#510)
  Refactors the system checkers (#507)
  Bump psutil from 5.9.5 to 5.9.6 (#508)
  FIXME disabled in Pylint
  Added simple HTML5 validation to request.html
  Network key is optional for HOG
  Clarified error message and clarified actual exception caught
  extends the install script to have a random password option (#504)
  Jobs.py now sends email when old jobs are present; Bugfixes in SQL query
  Flow process runtime bumped to 60+ minutes
  Sorting must be additionaly done by table to show indicator
  Repositories generated table also shall show sorting indicators
  Removing legacy datatable includes for energy-timeline
  Removed 'sortable' class where we are using datatables and not jQuery-Sort
  Bugifx: If Jobs object is not set do not access
  ...
@github-actions
Copy link

Eco-CI Output:

Label 🖥 avg. CPU utilization [%] 🔋 Total Energy [Joules] 🔌 avg. Power [Watts] Duration [Seconds]
Total Run 18.4406 1743.41 2.3948 735
Measurement #1 18.5379 1743.41 2.3948 729

📈 Energy graph:

 
 7.07 ┤                                                                                         ╭╮                                                     ╭╮
 6.53 ┤                                                                                         ││                                                     ││
 5.99 ┤                                                                                         ││                 ╭─╮                    ╭╮╭╮     ╭─╮ ││
 5.45 ┤                                                        ╭╮                              ╭╯│                 │ ╰╮                   │││╰──╮  │ ╰─╯│
 4.91 ┤      ╭╮                                              ╭╮││   ╭╮                         │ │                ╭╯  │   ╭────╮          │╰╯   ╰╮ │    │
 4.37 ┤     ╭╯│                ╭──╮                        ╭╮│││╰╮  ││                         │ ╰╮      ╭╮       │   ╰╮╭─╯    │          │      │╭╯    │         ╭╮╭╮                                                                                                                                                                                          ╭╮                                                                                        ╭╮                          ╭╮                                                      ╭╮
 3.83 ┤     │ ╰────╮╭─────────╮│  ╰╮ ╭──────────╮╭─────────╯││││ │  ││╭───╮╭─╮   ╭────────────╮│  ╰──────╯╰───────╯    ││      │          │      ││     │        ╭╯│││ ╭─╮                        ╭╮                                   ╭╮          ╭╮          ╭╮                                                                                  ╭╮           ││         ╭─╮                    ╭╮   ╭╮                       ╭╮                    ╭╮  ││                      ╭╮ ╭╯│                          ╭╮                         ╭╯│                         ╭╮                                                         ╭╮                                                                              ╭──╮╭╮                     ╭╮
 3.29 ┤    ╭╯      ╰╯         ╰╯   ╰─╯          ╰╯          ╰╯╰╯ │  │╰╯   ╰╯ ╰───╯            ││                       ││      ╰╮         │      ││     │        │ │││ │ │         ╭╮          ╭╮ │╰╮          ╭╮         ╭─╮          │╰╮         │╰╮         │╰╮          ╭╮         ╭─╮         ╭─╮         ╭─╮          ╭╮         ╭─╮         │╰╮         ╭╯│         │ ╰╮                   ││ ╭─╯╰╮                  ╭╮ ╭╯╰╮                   ││ ╭╯╰╮         ╭╮          ││ │ ╰╮         ╭╮             ╭╯╰╮         ╭╮          ╭╮ │ ╰╮         ╭╮          ╭╮ │╰╮         ╭╮          ╭─╮         ╭╮         ╭╮          │╰╮         ╭──╮             ╭╮                       ╭─╮         ╭╮            │  ╰╯│                     ││ ╭─╮
 2.75 ┤    │                                                     │╭─╯                         ││                       ╰╯       │╭╮      ╭╯      ╰╯     ╰╮       │ ╰╯╰─╯ │        ╭╯│╭╮        ││ │ ╰╮        ╭╯│         │ ╰╮        ╭╯ │         │ │         │ │         ╭╯│         │ │         │ │         │ ╰╮        ╭╯│         │ │         │ │         │ │         │  │         ╭╮        ││ │   │                  ││ │  ╰╮        ╭╮        ││ │  │         ││╭╮        ││ │  │        ╭╯│╭╮       ╭─╮╭╯  │         ││╭╮        ││ │  │        ╭╯│╭╮        ││ │ │         │╰╮        ╭╯ │         ││         │╰╮        ╭╯ │         │  │╭╮          ╭╯╰╮        ╭─╮           │ │        ╭╯│            │    ╰╮        ╭─╮         ││ │ ╰╮       ╭
 2.21 ┤    │                                                     ╰╯                           ╰╯                                │││      │               │      ╭╯       │        │ │││       ╭╯│╭╯  │        │ ╰╮        │  │        │  │   ╭╮    │ ╰╮        │ ╰╮        │ ╰╮        │ │         │ ╰╮        │  │        │ ╰╮        │ │         │ │        ╭╯ ╰╮        │  ╰╮        ││        ││ │   │        ╭╮        │╰╮│   │        ││        ││ │  ╰╮       ╭╯╰╯│        ││ │  │        │ │││       │ ││   │       ╭─╯│││       ╭╯│╭╯  │        │ │││       ╭╯│╭╯ │         │ │        │  │        ╭╯│         │ │        │  ╰╮       ╭╯  ╰╯│        ╭╮│  │       ╭╯ ╰╮          │ │        │ ╰─╮       ╭╮╭╯     │    ╭╮ ╭╯ ╰╮        ││ │  │       │
 1.67 ┼────╯                                                                                                                    ╰╯╰──────╯               ╰──────╯        ╰────────╯ ╰╯╰───────╯ ╰╯   ╰────────╯  ╰────────╯  ╰────────╯  ╰───╯╰────╯  ╰────────╯  ╰────────╯  ╰────────╯ ╰─────────╯  ╰────────╯  ╰────────╯  ╰────────╯ ╰─────────╯ ╰────────╯   ╰────────╯   ╰────────╯╰────────╯╰─╯   ╰────────╯╰────────╯ ╰╯   ╰────────╯╰────────╯╰─╯   ╰───────╯   ╰────────╯╰─╯  ╰────────╯ ╰╯╰───────╯ ╰╯   ╰───────╯  ╰╯╰───────╯ ╰╯   ╰────────╯ ╰╯╰───────╯ ╰╯  ╰─────────╯ ╰────────╯  ╰────────╯ ╰─────────╯ ╰────────╯   ╰───────╯     ╰────────╯╰╯  ╰───────╯   ╰──────────╯ ╰────────╯   ╰───────╯╰╯      ╰────╯╰─╯   ╰────────╯╰─╯  ╰───────╯
                                                                                                                                                                                                                                                                                                                                                                           Watts over time

@ArneTR
Copy link
Member Author

ArneTR commented Oct 20, 2023

Updated. @ribalba Can you give it another look?

I clarified in the code what the original author is doing, although some implementations are not documented and cannot be checked completely

@ArneTR
Copy link
Member Author

ArneTR commented Oct 20, 2023

I will merge it in for now, please put your comments in here if you have any

@ArneTR ArneTR merged commit 984a854 into main Oct 20, 2023
4 checks passed
@ArneTR ArneTR deleted the MCP39F511N branch October 20, 2023 13:45
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

Successfully merging this pull request may close these issues.

2 participants