microbit_scpi_pass_fail
Fork of microbit-hello-world by
scpi-def.cpp@1:aa0af9cf4f28, 2018-11-06 (annotated)
- Committer:
- jancumps
- Date:
- Tue Nov 06 20:58:04 2018 +0000
- Revision:
- 1:aa0af9cf4f28
Function complete first version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jancumps | 1:aa0af9cf4f28 | 1 | /*- |
jancumps | 1:aa0af9cf4f28 | 2 | * BSD 2-Clause License |
jancumps | 1:aa0af9cf4f28 | 3 | * |
jancumps | 1:aa0af9cf4f28 | 4 | * Copyright (c) 2012-2018, Jan Breuer |
jancumps | 1:aa0af9cf4f28 | 5 | * All rights reserved. |
jancumps | 1:aa0af9cf4f28 | 6 | * |
jancumps | 1:aa0af9cf4f28 | 7 | * Redistribution and use in source and binary forms, with or without |
jancumps | 1:aa0af9cf4f28 | 8 | * modification, are permitted provided that the following conditions are met: |
jancumps | 1:aa0af9cf4f28 | 9 | * |
jancumps | 1:aa0af9cf4f28 | 10 | * * Redistributions of source code must retain the above copyright notice, this |
jancumps | 1:aa0af9cf4f28 | 11 | * list of conditions and the following disclaimer. |
jancumps | 1:aa0af9cf4f28 | 12 | * |
jancumps | 1:aa0af9cf4f28 | 13 | * * Redistributions in binary form must reproduce the above copyright notice, |
jancumps | 1:aa0af9cf4f28 | 14 | * this list of conditions and the following disclaimer in the documentation |
jancumps | 1:aa0af9cf4f28 | 15 | * and/or other materials provided with the distribution. |
jancumps | 1:aa0af9cf4f28 | 16 | * |
jancumps | 1:aa0af9cf4f28 | 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
jancumps | 1:aa0af9cf4f28 | 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
jancumps | 1:aa0af9cf4f28 | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
jancumps | 1:aa0af9cf4f28 | 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
jancumps | 1:aa0af9cf4f28 | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
jancumps | 1:aa0af9cf4f28 | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
jancumps | 1:aa0af9cf4f28 | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
jancumps | 1:aa0af9cf4f28 | 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
jancumps | 1:aa0af9cf4f28 | 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
jancumps | 1:aa0af9cf4f28 | 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
jancumps | 1:aa0af9cf4f28 | 27 | */ |
jancumps | 1:aa0af9cf4f28 | 28 | |
jancumps | 1:aa0af9cf4f28 | 29 | /** |
jancumps | 1:aa0af9cf4f28 | 30 | * @file scpi-def.c |
jancumps | 1:aa0af9cf4f28 | 31 | * @date Thu Nov 15 10:58:45 UTC 2012 |
jancumps | 1:aa0af9cf4f28 | 32 | * |
jancumps | 1:aa0af9cf4f28 | 33 | * @brief SCPI parser test |
jancumps | 1:aa0af9cf4f28 | 34 | * |
jancumps | 1:aa0af9cf4f28 | 35 | * |
jancumps | 1:aa0af9cf4f28 | 36 | */ |
jancumps | 1:aa0af9cf4f28 | 37 | |
jancumps | 1:aa0af9cf4f28 | 38 | #include <stdio.h> |
jancumps | 1:aa0af9cf4f28 | 39 | #include <stdlib.h> |
jancumps | 1:aa0af9cf4f28 | 40 | #include <string.h> |
jancumps | 1:aa0af9cf4f28 | 41 | #include "scpi/scpi.h" |
jancumps | 1:aa0af9cf4f28 | 42 | #include "scpi-def.h" |
jancumps | 1:aa0af9cf4f28 | 43 | |
jancumps | 1:aa0af9cf4f28 | 44 | #include "MicroBit.h" |
jancumps | 1:aa0af9cf4f28 | 45 | |
jancumps | 1:aa0af9cf4f28 | 46 | extern MicroBit uBit; |
jancumps | 1:aa0af9cf4f28 | 47 | MicroBitImage imgPass("0, 0, 255, 0, 0\n0, 0, 255, 0, 0\n255, 255, 255, 255, 255\n0, 0, 255, 0, 0\n0, 0, 255, 0, 0\n"); // plus |
jancumps | 1:aa0af9cf4f28 | 48 | MicroBitImage imgFail("255, 0, 0, 0, 255\n0, 255, 0, 255, 0\n0, 0, 255, 0, 0\n0, 255, 0, 255, 0\n255, 0, 0, 0, 255\n"); // X |
jancumps | 1:aa0af9cf4f28 | 49 | |
jancumps | 1:aa0af9cf4f28 | 50 | |
jancumps | 1:aa0af9cf4f28 | 51 | enum scpi_state_t { |
jancumps | 1:aa0af9cf4f28 | 52 | SCPI_STATE_PASS, |
jancumps | 1:aa0af9cf4f28 | 53 | SCPI_STATE_FAIL, |
jancumps | 1:aa0af9cf4f28 | 54 | SCPI_STATE_CLEAR |
jancumps | 1:aa0af9cf4f28 | 55 | }; |
jancumps | 1:aa0af9cf4f28 | 56 | |
jancumps | 1:aa0af9cf4f28 | 57 | const scpi_choice_def_t scpi_state_def[] = { |
jancumps | 1:aa0af9cf4f28 | 58 | {/* name */ "PASs", /* type */ SCPI_STATE_PASS }, |
jancumps | 1:aa0af9cf4f28 | 59 | {/* name */ "FAIl", /* type */ SCPI_STATE_FAIL }, |
jancumps | 1:aa0af9cf4f28 | 60 | {/* name */ "CLEar", /* type */ SCPI_STATE_CLEAR }, |
jancumps | 1:aa0af9cf4f28 | 61 | SCPI_CHOICE_LIST_END, |
jancumps | 1:aa0af9cf4f28 | 62 | }; |
jancumps | 1:aa0af9cf4f28 | 63 | |
jancumps | 1:aa0af9cf4f28 | 64 | |
jancumps | 1:aa0af9cf4f28 | 65 | /** |
jancumps | 1:aa0af9cf4f28 | 66 | * Reimplement IEEE488.2 *TST? |
jancumps | 1:aa0af9cf4f28 | 67 | * |
jancumps | 1:aa0af9cf4f28 | 68 | * Result should be 0 if everything is ok |
jancumps | 1:aa0af9cf4f28 | 69 | * Result should be 1 if something goes wrong |
jancumps | 1:aa0af9cf4f28 | 70 | * |
jancumps | 1:aa0af9cf4f28 | 71 | * Return SCPI_RES_OK |
jancumps | 1:aa0af9cf4f28 | 72 | */ |
jancumps | 1:aa0af9cf4f28 | 73 | static scpi_result_t My_CoreTstQ(scpi_t * context) { |
jancumps | 1:aa0af9cf4f28 | 74 | |
jancumps | 1:aa0af9cf4f28 | 75 | SCPI_ResultInt32(context, 0); |
jancumps | 1:aa0af9cf4f28 | 76 | |
jancumps | 1:aa0af9cf4f28 | 77 | return SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 78 | } |
jancumps | 1:aa0af9cf4f28 | 79 | |
jancumps | 1:aa0af9cf4f28 | 80 | static scpi_result_t setState(scpi_t * context) { |
jancumps | 1:aa0af9cf4f28 | 81 | |
jancumps | 1:aa0af9cf4f28 | 82 | int32_t param1; |
jancumps | 1:aa0af9cf4f28 | 83 | scpi_bool_t result; |
jancumps | 1:aa0af9cf4f28 | 84 | scpi_result_t retval; |
jancumps | 1:aa0af9cf4f28 | 85 | |
jancumps | 1:aa0af9cf4f28 | 86 | result = SCPI_ParamChoice( context, scpi_state_def, ¶m1, TRUE ); |
jancumps | 1:aa0af9cf4f28 | 87 | if ( false == result ) |
jancumps | 1:aa0af9cf4f28 | 88 | { |
jancumps | 1:aa0af9cf4f28 | 89 | return SCPI_RES_ERR; |
jancumps | 1:aa0af9cf4f28 | 90 | } |
jancumps | 1:aa0af9cf4f28 | 91 | else |
jancumps | 1:aa0af9cf4f28 | 92 | { |
jancumps | 1:aa0af9cf4f28 | 93 | switch (param1) { |
jancumps | 1:aa0af9cf4f28 | 94 | case SCPI_STATE_PASS: |
jancumps | 1:aa0af9cf4f28 | 95 | uBit.io.P1.setDigitalValue(0); |
jancumps | 1:aa0af9cf4f28 | 96 | uBit.io.P0.setDigitalValue(1); |
jancumps | 1:aa0af9cf4f28 | 97 | uBit.display.clear(); |
jancumps | 1:aa0af9cf4f28 | 98 | uBit.display.print(imgPass); |
jancumps | 1:aa0af9cf4f28 | 99 | retval = SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 100 | break; |
jancumps | 1:aa0af9cf4f28 | 101 | case SCPI_STATE_FAIL: |
jancumps | 1:aa0af9cf4f28 | 102 | uBit.io.P0.setDigitalValue(0); |
jancumps | 1:aa0af9cf4f28 | 103 | uBit.io.P1.setDigitalValue(1); |
jancumps | 1:aa0af9cf4f28 | 104 | uBit.display.clear(); |
jancumps | 1:aa0af9cf4f28 | 105 | uBit.display.print(imgFail); |
jancumps | 1:aa0af9cf4f28 | 106 | retval = SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 107 | break; |
jancumps | 1:aa0af9cf4f28 | 108 | case SCPI_STATE_CLEAR: |
jancumps | 1:aa0af9cf4f28 | 109 | uBit.io.P0.setDigitalValue(0); |
jancumps | 1:aa0af9cf4f28 | 110 | uBit.io.P1.setDigitalValue(0); |
jancumps | 1:aa0af9cf4f28 | 111 | uBit.display.clear(); |
jancumps | 1:aa0af9cf4f28 | 112 | retval = SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 113 | break; |
jancumps | 1:aa0af9cf4f28 | 114 | default: |
jancumps | 1:aa0af9cf4f28 | 115 | SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); |
jancumps | 1:aa0af9cf4f28 | 116 | retval = SCPI_RES_ERR; |
jancumps | 1:aa0af9cf4f28 | 117 | } |
jancumps | 1:aa0af9cf4f28 | 118 | } |
jancumps | 1:aa0af9cf4f28 | 119 | |
jancumps | 1:aa0af9cf4f28 | 120 | return retval; |
jancumps | 1:aa0af9cf4f28 | 121 | } |
jancumps | 1:aa0af9cf4f28 | 122 | |
jancumps | 1:aa0af9cf4f28 | 123 | const scpi_command_t scpi_commands[] = { |
jancumps | 1:aa0af9cf4f28 | 124 | /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */ |
jancumps | 1:aa0af9cf4f28 | 125 | /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */ |
jancumps | 1:aa0af9cf4f28 | 126 | { .pattern = "*CLS", .callback = SCPI_CoreCls,}, |
jancumps | 1:aa0af9cf4f28 | 127 | { .pattern = "*ESE", .callback = SCPI_CoreEse,}, |
jancumps | 1:aa0af9cf4f28 | 128 | { .pattern = "*ESE?", .callback = SCPI_CoreEseQ,}, |
jancumps | 1:aa0af9cf4f28 | 129 | { .pattern = "*ESR?", .callback = SCPI_CoreEsrQ,}, |
jancumps | 1:aa0af9cf4f28 | 130 | { .pattern = "*IDN?", .callback = SCPI_CoreIdnQ,}, |
jancumps | 1:aa0af9cf4f28 | 131 | { .pattern = "*OPC", .callback = SCPI_CoreOpc,}, |
jancumps | 1:aa0af9cf4f28 | 132 | { .pattern = "*OPC?", .callback = SCPI_CoreOpcQ,}, |
jancumps | 1:aa0af9cf4f28 | 133 | { .pattern = "*RST", .callback = SCPI_CoreRst,}, |
jancumps | 1:aa0af9cf4f28 | 134 | { .pattern = "*SRE", .callback = SCPI_CoreSre,}, |
jancumps | 1:aa0af9cf4f28 | 135 | { .pattern = "*SRE?", .callback = SCPI_CoreSreQ,}, |
jancumps | 1:aa0af9cf4f28 | 136 | { .pattern = "*STB?", .callback = SCPI_CoreStbQ,}, |
jancumps | 1:aa0af9cf4f28 | 137 | { .pattern = "*TST?", .callback = My_CoreTstQ,}, |
jancumps | 1:aa0af9cf4f28 | 138 | { .pattern = "*WAI", .callback = SCPI_CoreWai,}, |
jancumps | 1:aa0af9cf4f28 | 139 | |
jancumps | 1:aa0af9cf4f28 | 140 | /* Required SCPI commands (SCPI std V1999.0 4.2.1) */ |
jancumps | 1:aa0af9cf4f28 | 141 | {.pattern = "SYSTem:ERRor[:NEXT]?", .callback = SCPI_SystemErrorNextQ,}, |
jancumps | 1:aa0af9cf4f28 | 142 | {.pattern = "SYSTem:ERRor:COUNt?", .callback = SCPI_SystemErrorCountQ,}, |
jancumps | 1:aa0af9cf4f28 | 143 | {.pattern = "SYSTem:VERSion?", .callback = SCPI_SystemVersionQ,}, |
jancumps | 1:aa0af9cf4f28 | 144 | |
jancumps | 1:aa0af9cf4f28 | 145 | {.pattern = "[:INDicator]:STAte", .callback = setState,}, |
jancumps | 1:aa0af9cf4f28 | 146 | |
jancumps | 1:aa0af9cf4f28 | 147 | |
jancumps | 1:aa0af9cf4f28 | 148 | SCPI_CMD_LIST_END |
jancumps | 1:aa0af9cf4f28 | 149 | }; |
jancumps | 1:aa0af9cf4f28 | 150 | |
jancumps | 1:aa0af9cf4f28 | 151 | scpi_interface_t scpi_interface = { |
jancumps | 1:aa0af9cf4f28 | 152 | /*.error = */ SCPI_Error, |
jancumps | 1:aa0af9cf4f28 | 153 | /*.write = */ SCPI_Write, |
jancumps | 1:aa0af9cf4f28 | 154 | /*.control = */ SCPI_Control, |
jancumps | 1:aa0af9cf4f28 | 155 | /*.flush = */ SCPI_Flush, |
jancumps | 1:aa0af9cf4f28 | 156 | /*.reset = */ SCPI_Reset, |
jancumps | 1:aa0af9cf4f28 | 157 | }; |
jancumps | 1:aa0af9cf4f28 | 158 | |
jancumps | 1:aa0af9cf4f28 | 159 | char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH]; |
jancumps | 1:aa0af9cf4f28 | 160 | scpi_error_t scpi_error_queue_data[SCPI_ERROR_QUEUE_SIZE]; |
jancumps | 1:aa0af9cf4f28 | 161 | |
jancumps | 1:aa0af9cf4f28 | 162 | scpi_t scpi_context; |