Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | |
| 7 | unsigned char g_sensortype [][2] = { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 8 | {0xC3, 0x01}, |
| 9 | {0x07, 0x02}, |
| 10 | {0x0F, 0x05}, |
| 11 | {0x0c, 0x1F}, |
| 12 | {0xFF ,0xff} |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 13 | }; |
| 14 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 15 | uint8_t find_sensor(uint8_t sensor_number) { |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 16 | |
| 17 | int i=0; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 18 | uint8_t rc; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 19 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 20 | while (g_sensortype[i][0] != 0xff) { |
| 21 | if (g_sensortype[i][1] == sensor_number) { |
| 22 | break; |
| 23 | } else { |
| 24 | i++; |
| 25 | } |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 26 | } |
| 27 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 28 | rc = g_sensortype[i][0]; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 29 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 30 | if (rc == 0xFF) { |
| 31 | rc = 0; |
| 32 | } |
| 33 | return rc; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 36 | char g_results_method[64]; |
| 37 | char g_results_value[64]; |
| 38 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 39 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 40 | int set_sensor_dbus_state_v(uint8_t number, const char *method, char *value) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 41 | printf("Attempting to log Variant Sensor 0x%02x via %s with a value of %s\n", |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 42 | number, method, value); |
| 43 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 44 | strcpy(g_results_method, method); |
| 45 | strcpy(g_results_value, value); |
| 46 | |
| 47 | return 0; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 50 | int set_sensor_dbus_state(uint8_t number, const char *method, const char *value) { |
| 51 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 52 | printf("Attempting to log Sensor 0x%02x via %s with a value of %s\n", |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 53 | number, method, value); |
| 54 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 55 | strcpy(g_results_method, method); |
| 56 | strcpy(g_results_value, value); |
| 57 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | extern int updateSensorRecordFromSSRAESC(const void *record); |
| 63 | |
| 64 | |
| 65 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 66 | // DIMM Present |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 67 | uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 68 | |
| 69 | // DIMM Not present |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 70 | uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}; |
| 71 | |
| 72 | // DIMM Not present |
| 73 | uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; |
| 74 | |
| 75 | // Virtual Sensor 5, setting a Value of 0h |
| 76 | uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00}; |
| 77 | |
| 78 | // Virtual Sensor setting a boot count |
| 79 | uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 80 | |
| 81 | // Invalid sensor number |
| 82 | uint8_t testrec_invalidnumber[]= {0x35, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00}; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 83 | |
| 84 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 85 | int check_results(int rc, const char *method, const char *value) { |
| 86 | if (strcmp(g_results_method, method)) { |
| 87 | printf("ERROR: Method Failed, expect %s found %s\n", method, g_results_method); |
| 88 | return -1; |
| 89 | } |
| 90 | if (strcmp(g_results_value, value)) { |
| 91 | printf("ERROR: Value failed, expected %s found %s\n", value, g_results_value); |
| 92 | return -2; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | void testprep(void) { |
| 99 | memset(g_results_method, 0, sizeof(g_results_method)); |
| 100 | memset(g_results_value, 0, sizeof(g_results_value)); |
| 101 | } |
| 102 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 103 | |
| 104 | int main() { |
| 105 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 106 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress), "setValue", "FW Progress, Docking station attachment"); |
| 107 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent", "True"); |
| 108 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent", "False"); |
| 109 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault", "False"); |
| 110 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue", "3"); |
| 111 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", ""); |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 112 | |
| 113 | return 0; |
| 114 | } |