1/* $NetBSD: printscmd.c,v 1.1 2021/12/07 17:39:55 brad Exp $ */ 2 3/* 4 * Copyright (c) 2021 Brad Spencer <brad@anduin.eldar.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#ifdef __RCSID 20__RCSID("$NetBSD: printscmd.c,v 1.1 2021/12/07 17:39:55 brad Exp $"); 21#endif 22 23/* Functions to print stuff returned from get calls mostly */ 24 25#include <inttypes.h> 26#include <stdbool.h> 27#include <stdio.h> 28#include <stdlib.h> 29#include <unistd.h> 30#include <err.h> 31#include <fcntl.h> 32#include <string.h> 33#include <limits.h> 34#include <termios.h> 35 36#include <dev/ic/scmdreg.h> 37 38#define EXTERN extern 39#include "scmdctl.h" 40#include "responses.h" 41#include "common.h" 42 43#undef EXTERN 44#define EXTERN 45#include "printscmd.h" 46 47void 48print_identify(struct scmd_identify_response *r) 49{ 50 printf("ID (ID):\t\t\t%d (0x%02X)\n",r->id,r->id); 51 printf("Firmware version (FID):\t\t%d\n",r->fwversion); 52 printf("Config bits (CONFIG_BITS):\t%d (0x%02X)\n",r->config_bits,r->config_bits); 53 if (r->slv_i2c_address >= SCMD_REMOTE_ADDR_LOW && 54 r->slv_i2c_address <= SCMD_REMOTE_ADDR_HIGH) 55 printf("Slave address (SLAVE_ADDR):\t0x%02X\n",r->slv_i2c_address); 56 else 57 printf("Slave address (SLAVE_ADDR):\tMaster (0x%02X)\n",r->slv_i2c_address); 58} 59 60 61void 62print_diag(struct scmd_diag_response *r) 63{ 64 const char *outputs[] = { 65 "Read errors USER port (U_I2C_RD_ERR):\t\t", 66 "Write errors USER port (U_I2C_WR_ERR):\t\t", 67 "Too much data (U_BUF_DUMPED):\t\t\t", 68 "Read errors SLAVE port (E_I2C_RD_ERR):\t\t", 69 "Write errors SLAVE port (E_I2C_WR_ERR):\t\t", 70 "Main loop (LOOP_TIME):\t\t\t\t", 71 "Number of slave polls (SLV_POOL_CNT):\t\t", 72 "Highest slave address (SLV_TOP_ADDR):\t\t", 73 "Master count SLAVE port errors (MST_E_ERR):\t", 74 "Status master board (MST_E_STATUS):\t\t", 75 "Failsafe faults (FSAFE_FAULTS):\t\t\t", 76 "Out of range register attempts (REG_OOR_CNT):\t", 77 "Write lock attempts (REG_RO_WRITE_CNT):\t\t", 78 "General test word (GEN_TEST_WORD):\t\t" 79 }; 80 81 for(int n = 0; n < 14;n++) { 82 printf("%s%d (0x%02X)\n",outputs[n],r->diags[n],r->diags[n]); 83 } 84} 85 86const char *edu_outputs[] = { 87 "Disabled", 88 "Enabled", 89 "Unknown" 90}; 91 92void 93print_motor(struct scmd_motor_response *r) 94{ 95 int x; 96 97 if (r->driver <= 0x01) 98 x = r->driver; 99 else 100 x = 2; 101 printf("Driver enable/disable: %s (0x%02X)\n",edu_outputs[x],r->driver); 102 for(int n = 0; n < 34;n++) { 103 if (r->motorlevels[n] != SCMD_NO_MOTOR) { 104 printf("Module %d motor %c: %d (0x%02X) %s %s %s\n", 105 n / 2, 106 (n & 0x01 ? 'B' : 'A'), 107 decode_motor_level(r->motorlevels[n]), 108 r->motorlevels[n], 109 (r->motorlevels[n] < 128 ? "(reverse)" : "(forward)"), 110 (r->invert[n] == true ? "(inverted)" : "(not inverted)"), 111 (r->bridge[n / 2] == true ? "(bridged)" : "(not bridged)") 112 ); 113 } 114 } 115} 116