scpi-parser, adopted from github

Dependents:   scpi_parser_test

Committer:
iesensor
Date:
Fri Nov 14 01:07:59 2014 +0000
Revision:
0:d8aca47812e0
tested on K64F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iesensor 0:d8aca47812e0 1 /*-
iesensor 0:d8aca47812e0 2 * Copyright (c) 2012-2013 Jan Breuer,
iesensor 0:d8aca47812e0 3 *
iesensor 0:d8aca47812e0 4 * All Rights Reserved
iesensor 0:d8aca47812e0 5 *
iesensor 0:d8aca47812e0 6 * Redistribution and use in source and binary forms, with or without
iesensor 0:d8aca47812e0 7 * modification, are permitted provided that the following conditions are
iesensor 0:d8aca47812e0 8 * met:
iesensor 0:d8aca47812e0 9 * 1. Redistributions of source code must retain the above copyright notice,
iesensor 0:d8aca47812e0 10 * this list of conditions and the following disclaimer.
iesensor 0:d8aca47812e0 11 * 2. Redistributions in binary form must reproduce the above copyright
iesensor 0:d8aca47812e0 12 * notice, this list of conditions and the following disclaimer in the
iesensor 0:d8aca47812e0 13 * documentation and/or other materials provided with the distribution.
iesensor 0:d8aca47812e0 14 *
iesensor 0:d8aca47812e0 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
iesensor 0:d8aca47812e0 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
iesensor 0:d8aca47812e0 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
iesensor 0:d8aca47812e0 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
iesensor 0:d8aca47812e0 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
iesensor 0:d8aca47812e0 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
iesensor 0:d8aca47812e0 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
iesensor 0:d8aca47812e0 22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
iesensor 0:d8aca47812e0 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
iesensor 0:d8aca47812e0 24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
iesensor 0:d8aca47812e0 25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
iesensor 0:d8aca47812e0 26 */
iesensor 0:d8aca47812e0 27
iesensor 0:d8aca47812e0 28 /**
iesensor 0:d8aca47812e0 29 * @file scpi_minimal.c
iesensor 0:d8aca47812e0 30 * @date Thu Nov 15 10:58:45 UTC 2012
iesensor 0:d8aca47812e0 31 *
iesensor 0:d8aca47812e0 32 * @brief SCPI minimal implementation
iesensor 0:d8aca47812e0 33 *
iesensor 0:d8aca47812e0 34 *
iesensor 0:d8aca47812e0 35 */
iesensor 0:d8aca47812e0 36
iesensor 0:d8aca47812e0 37
iesensor 0:d8aca47812e0 38 #include "scpi/parser.h"
iesensor 0:d8aca47812e0 39 #include "scpi/minimal.h"
iesensor 0:d8aca47812e0 40 #include "scpi/constants.h"
iesensor 0:d8aca47812e0 41 #include "scpi/error.h"
iesensor 0:d8aca47812e0 42 #include "scpi/ieee488.h"
iesensor 0:d8aca47812e0 43
iesensor 0:d8aca47812e0 44 /**
iesensor 0:d8aca47812e0 45 * Command stub function
iesensor 0:d8aca47812e0 46 * @param context
iesensor 0:d8aca47812e0 47 * @return
iesensor 0:d8aca47812e0 48 */
iesensor 0:d8aca47812e0 49 scpi_result_t SCPI_Stub(scpi_t * context) {
iesensor 0:d8aca47812e0 50 (void) context;
iesensor 0:d8aca47812e0 51 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 52 }
iesensor 0:d8aca47812e0 53
iesensor 0:d8aca47812e0 54 /**
iesensor 0:d8aca47812e0 55 * Query command stub function
iesensor 0:d8aca47812e0 56 * @param context
iesensor 0:d8aca47812e0 57 * @return
iesensor 0:d8aca47812e0 58 */
iesensor 0:d8aca47812e0 59 scpi_result_t SCPI_StubQ(scpi_t * context) {
iesensor 0:d8aca47812e0 60 SCPI_ResultString(context, "");
iesensor 0:d8aca47812e0 61 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 62 }
iesensor 0:d8aca47812e0 63
iesensor 0:d8aca47812e0 64 /**
iesensor 0:d8aca47812e0 65 * SYSTem:VERSion?
iesensor 0:d8aca47812e0 66 * @param context
iesensor 0:d8aca47812e0 67 * @return
iesensor 0:d8aca47812e0 68 */
iesensor 0:d8aca47812e0 69 scpi_result_t SCPI_SystemVersionQ(scpi_t * context) {
iesensor 0:d8aca47812e0 70 SCPI_ResultString(context, SCPI_STD_VERSION_REVISION);
iesensor 0:d8aca47812e0 71 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 72 }
iesensor 0:d8aca47812e0 73
iesensor 0:d8aca47812e0 74 /**
iesensor 0:d8aca47812e0 75 * SYSTem:ERRor[:NEXT]?
iesensor 0:d8aca47812e0 76 * @param context
iesensor 0:d8aca47812e0 77 * @return
iesensor 0:d8aca47812e0 78 */
iesensor 0:d8aca47812e0 79 scpi_result_t SCPI_SystemErrorNextQ(scpi_t * context) {
iesensor 0:d8aca47812e0 80 int16_t err = SCPI_ErrorPop(context);
iesensor 0:d8aca47812e0 81
iesensor 0:d8aca47812e0 82 SCPI_ResultInt(context, err);
iesensor 0:d8aca47812e0 83 SCPI_ResultText(context, SCPI_ErrorTranslate(err));
iesensor 0:d8aca47812e0 84
iesensor 0:d8aca47812e0 85 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 86 }
iesensor 0:d8aca47812e0 87
iesensor 0:d8aca47812e0 88 /**
iesensor 0:d8aca47812e0 89 * SYSTem:ERRor:COUNt?
iesensor 0:d8aca47812e0 90 * @param context
iesensor 0:d8aca47812e0 91 * @return
iesensor 0:d8aca47812e0 92 */
iesensor 0:d8aca47812e0 93 scpi_result_t SCPI_SystemErrorCountQ(scpi_t * context) {
iesensor 0:d8aca47812e0 94 SCPI_ResultInt(context, SCPI_ErrorCount(context));
iesensor 0:d8aca47812e0 95
iesensor 0:d8aca47812e0 96 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 97 }
iesensor 0:d8aca47812e0 98
iesensor 0:d8aca47812e0 99 /**
iesensor 0:d8aca47812e0 100 * STATus:QUEStionable[:EVENt]?
iesensor 0:d8aca47812e0 101 * @param context
iesensor 0:d8aca47812e0 102 * @return
iesensor 0:d8aca47812e0 103 */
iesensor 0:d8aca47812e0 104 scpi_result_t SCPI_StatusQuestionableEventQ(scpi_t * context) {
iesensor 0:d8aca47812e0 105 /* return value */
iesensor 0:d8aca47812e0 106 SCPI_ResultInt(context, SCPI_RegGet(context, SCPI_REG_QUES));
iesensor 0:d8aca47812e0 107
iesensor 0:d8aca47812e0 108 /* clear register */
iesensor 0:d8aca47812e0 109 SCPI_RegSet(context, SCPI_REG_QUES, 0);
iesensor 0:d8aca47812e0 110
iesensor 0:d8aca47812e0 111 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 112 }
iesensor 0:d8aca47812e0 113
iesensor 0:d8aca47812e0 114 /**
iesensor 0:d8aca47812e0 115 * STATus:QUEStionable:ENABle?
iesensor 0:d8aca47812e0 116 * @param context
iesensor 0:d8aca47812e0 117 * @return
iesensor 0:d8aca47812e0 118 */
iesensor 0:d8aca47812e0 119 scpi_result_t SCPI_StatusQuestionableEnableQ(scpi_t * context) {
iesensor 0:d8aca47812e0 120 /* return value */
iesensor 0:d8aca47812e0 121 SCPI_ResultInt(context, SCPI_RegGet(context, SCPI_REG_QUESE));
iesensor 0:d8aca47812e0 122
iesensor 0:d8aca47812e0 123 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 124 }
iesensor 0:d8aca47812e0 125
iesensor 0:d8aca47812e0 126 /**
iesensor 0:d8aca47812e0 127 * STATus:QUEStionable:ENABle
iesensor 0:d8aca47812e0 128 * @param context
iesensor 0:d8aca47812e0 129 * @return
iesensor 0:d8aca47812e0 130 */
iesensor 0:d8aca47812e0 131 scpi_result_t SCPI_StatusQuestionableEnable(scpi_t * context) {
iesensor 0:d8aca47812e0 132 int32_t new_QUESE;
iesensor 0:d8aca47812e0 133 if (SCPI_ParamInt(context, &new_QUESE, TRUE)) {
iesensor 0:d8aca47812e0 134 SCPI_RegSet(context, SCPI_REG_QUESE, new_QUESE);
iesensor 0:d8aca47812e0 135 }
iesensor 0:d8aca47812e0 136 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 137 }
iesensor 0:d8aca47812e0 138
iesensor 0:d8aca47812e0 139 /**
iesensor 0:d8aca47812e0 140 * STATus:PRESet
iesensor 0:d8aca47812e0 141 * @param context
iesensor 0:d8aca47812e0 142 * @return
iesensor 0:d8aca47812e0 143 */
iesensor 0:d8aca47812e0 144 scpi_result_t SCPI_StatusPreset(scpi_t * context) {
iesensor 0:d8aca47812e0 145 /* clear STATUS:... */
iesensor 0:d8aca47812e0 146 SCPI_RegSet(context, SCPI_REG_QUES, 0);
iesensor 0:d8aca47812e0 147 return SCPI_RES_OK;
iesensor 0:d8aca47812e0 148 }