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 | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 40 | int set_sensor_dbus_state_s(unsigned char number, const char *member, const char *value) { |
| 41 | printf("Attempting to log 0x%02x via %s with a value of %s\n", |
| 42 | number, member, value); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 43 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 44 | strcpy(g_results_method, member); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 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 | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 50 | int set_sensor_dbus_state_y(unsigned char number, char const* member, uint8_t value) { |
| 51 | |
| 52 | char val[2]; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 53 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 54 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 55 | printf("Attempting to log Variant Sensor 0x%02x via %s with a value of 0x%02x\n", |
| 56 | number, member, value); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 57 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 58 | |
| 59 | snprintf(val, 2, "%d", value); |
| 60 | |
| 61 | strcpy(g_results_method, member); |
| 62 | strcpy(g_results_value, val); |
| 63 | |
| 64 | return 0; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | extern int updateSensorRecordFromSSRAESC(const void *record); |
| 69 | |
| 70 | |
| 71 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 72 | // DIMM Present |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 73 | 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] | 74 | |
| 75 | // DIMM Not present |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 76 | uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}; |
| 77 | |
| 78 | // DIMM Not present |
| 79 | uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; |
| 80 | |
| 81 | // Virtual Sensor 5, setting a Value of 0h |
| 82 | uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00}; |
| 83 | |
| 84 | // Virtual Sensor setting a boot count |
| 85 | uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 86 | |
| 87 | // Invalid sensor number |
| 88 | 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] | 89 | |
| 90 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 91 | int check_results(int rc, const char *method, const char *value) { |
| 92 | if (strcmp(g_results_method, method)) { |
| 93 | printf("ERROR: Method Failed, expect %s found %s\n", method, g_results_method); |
| 94 | return -1; |
| 95 | } |
| 96 | if (strcmp(g_results_value, value)) { |
| 97 | printf("ERROR: Value failed, expected %s found %s\n", value, g_results_value); |
| 98 | return -2; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | void testprep(void) { |
| 105 | memset(g_results_method, 0, sizeof(g_results_method)); |
| 106 | memset(g_results_value, 0, sizeof(g_results_value)); |
| 107 | } |
| 108 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 109 | |
| 110 | int main() { |
| 111 | |
Chris Austen | 1864155 | 2015-12-10 18:44:07 -0600 | [diff] [blame] | 112 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress), "setValue", "FW Progress, Docking station attachment"); |
| 113 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent", "True"); |
| 114 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent", "False"); |
| 115 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault", "False"); |
| 116 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue", "3"); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 117 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", ""); |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |