microbit_scpi_pass_fail
Fork of microbit-hello-world by
main.cpp@1:aa0af9cf4f28, 2018-11-06 (annotated)
- Committer:
- jancumps
- Date:
- Tue Nov 06 20:58:04 2018 +0000
- Revision:
- 1:aa0af9cf4f28
- Parent:
- 0:0041f35b0c4c
Function complete first version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LancasterUniversity | 0:0041f35b0c4c | 1 | /* |
LancasterUniversity | 0:0041f35b0c4c | 2 | The MIT License (MIT) |
LancasterUniversity | 0:0041f35b0c4c | 3 | |
LancasterUniversity | 0:0041f35b0c4c | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
LancasterUniversity | 0:0041f35b0c4c | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
LancasterUniversity | 0:0041f35b0c4c | 6 | |
LancasterUniversity | 0:0041f35b0c4c | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
LancasterUniversity | 0:0041f35b0c4c | 8 | copy of this software and associated documentation files (the "Software"), |
LancasterUniversity | 0:0041f35b0c4c | 9 | to deal in the Software without restriction, including without limitation |
LancasterUniversity | 0:0041f35b0c4c | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
LancasterUniversity | 0:0041f35b0c4c | 11 | and/or sell copies of the Software, and to permit persons to whom the |
LancasterUniversity | 0:0041f35b0c4c | 12 | Software is furnished to do so, subject to the following conditions: |
LancasterUniversity | 0:0041f35b0c4c | 13 | |
LancasterUniversity | 0:0041f35b0c4c | 14 | The above copyright notice and this permission notice shall be included in |
LancasterUniversity | 0:0041f35b0c4c | 15 | all copies or substantial portions of the Software. |
LancasterUniversity | 0:0041f35b0c4c | 16 | |
LancasterUniversity | 0:0041f35b0c4c | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
LancasterUniversity | 0:0041f35b0c4c | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
LancasterUniversity | 0:0041f35b0c4c | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
LancasterUniversity | 0:0041f35b0c4c | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
LancasterUniversity | 0:0041f35b0c4c | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
LancasterUniversity | 0:0041f35b0c4c | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
LancasterUniversity | 0:0041f35b0c4c | 23 | DEALINGS IN THE SOFTWARE. |
LancasterUniversity | 0:0041f35b0c4c | 24 | */ |
LancasterUniversity | 0:0041f35b0c4c | 25 | |
LancasterUniversity | 0:0041f35b0c4c | 26 | #include "MicroBit.h" |
jancumps | 1:aa0af9cf4f28 | 27 | #include "MicroBitSerial.h" |
jancumps | 1:aa0af9cf4f28 | 28 | |
LancasterUniversity | 0:0041f35b0c4c | 29 | |
LancasterUniversity | 0:0041f35b0c4c | 30 | MicroBit uBit; |
jancumps | 1:aa0af9cf4f28 | 31 | MicroBitSerial serial(USBTX, USBRX); |
LancasterUniversity | 0:0041f35b0c4c | 32 | |
jancumps | 1:aa0af9cf4f28 | 33 | |
jancumps | 1:aa0af9cf4f28 | 34 | |
jancumps | 1:aa0af9cf4f28 | 35 | |
jancumps | 1:aa0af9cf4f28 | 36 | /*- |
jancumps | 1:aa0af9cf4f28 | 37 | * BSD 2-Clause License |
jancumps | 1:aa0af9cf4f28 | 38 | * |
jancumps | 1:aa0af9cf4f28 | 39 | * Copyright (c) 2012-2018, Jan Breuer |
jancumps | 1:aa0af9cf4f28 | 40 | * All rights reserved. |
jancumps | 1:aa0af9cf4f28 | 41 | * |
jancumps | 1:aa0af9cf4f28 | 42 | * Redistribution and use in source and binary forms, with or without |
jancumps | 1:aa0af9cf4f28 | 43 | * modification, are permitted provided that the following conditions are met: |
jancumps | 1:aa0af9cf4f28 | 44 | * |
jancumps | 1:aa0af9cf4f28 | 45 | * * Redistributions of source code must retain the above copyright notice, this |
jancumps | 1:aa0af9cf4f28 | 46 | * list of conditions and the following disclaimer. |
jancumps | 1:aa0af9cf4f28 | 47 | * |
jancumps | 1:aa0af9cf4f28 | 48 | * * Redistributions in binary form must reproduce the above copyright notice, |
jancumps | 1:aa0af9cf4f28 | 49 | * this list of conditions and the following disclaimer in the documentation |
jancumps | 1:aa0af9cf4f28 | 50 | * and/or other materials provided with the distribution. |
jancumps | 1:aa0af9cf4f28 | 51 | * |
jancumps | 1:aa0af9cf4f28 | 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
jancumps | 1:aa0af9cf4f28 | 53 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
jancumps | 1:aa0af9cf4f28 | 54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
jancumps | 1:aa0af9cf4f28 | 55 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
jancumps | 1:aa0af9cf4f28 | 56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
jancumps | 1:aa0af9cf4f28 | 57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
jancumps | 1:aa0af9cf4f28 | 58 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
jancumps | 1:aa0af9cf4f28 | 59 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
jancumps | 1:aa0af9cf4f28 | 60 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
jancumps | 1:aa0af9cf4f28 | 61 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
jancumps | 1:aa0af9cf4f28 | 62 | */ |
jancumps | 1:aa0af9cf4f28 | 63 | |
jancumps | 1:aa0af9cf4f28 | 64 | /** |
jancumps | 1:aa0af9cf4f28 | 65 | * @file main.c |
jancumps | 1:aa0af9cf4f28 | 66 | * @date Thu Nov 15 10:58:45 UTC 2012 |
jancumps | 1:aa0af9cf4f28 | 67 | * |
jancumps | 1:aa0af9cf4f28 | 68 | * @brief SCPI parser test |
jancumps | 1:aa0af9cf4f28 | 69 | * |
jancumps | 1:aa0af9cf4f28 | 70 | * |
jancumps | 1:aa0af9cf4f28 | 71 | */ |
jancumps | 1:aa0af9cf4f28 | 72 | |
jancumps | 1:aa0af9cf4f28 | 73 | #include <stdio.h> |
jancumps | 1:aa0af9cf4f28 | 74 | #include <stdlib.h> |
jancumps | 1:aa0af9cf4f28 | 75 | #include <string.h> |
jancumps | 1:aa0af9cf4f28 | 76 | #include "scpi/scpi.h" |
jancumps | 1:aa0af9cf4f28 | 77 | #include "scpi-def.h" |
jancumps | 1:aa0af9cf4f28 | 78 | |
jancumps | 1:aa0af9cf4f28 | 79 | |
jancumps | 1:aa0af9cf4f28 | 80 | |
jancumps | 1:aa0af9cf4f28 | 81 | size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
jancumps | 1:aa0af9cf4f28 | 82 | (void) context; |
jancumps | 1:aa0af9cf4f28 | 83 | return serial.send((uint8_t *)data, len); |
jancumps | 1:aa0af9cf4f28 | 84 | } |
jancumps | 1:aa0af9cf4f28 | 85 | |
jancumps | 1:aa0af9cf4f28 | 86 | scpi_result_t SCPI_Flush(scpi_t * context) { |
jancumps | 1:aa0af9cf4f28 | 87 | (void) context; |
jancumps | 1:aa0af9cf4f28 | 88 | |
jancumps | 1:aa0af9cf4f28 | 89 | return SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 90 | } |
jancumps | 1:aa0af9cf4f28 | 91 | |
jancumps | 1:aa0af9cf4f28 | 92 | int SCPI_Error(scpi_t * context, int_fast16_t err) { |
jancumps | 1:aa0af9cf4f28 | 93 | (void) context; |
jancumps | 1:aa0af9cf4f28 | 94 | |
jancumps | 1:aa0af9cf4f28 | 95 | // fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (int16_t) err, SCPI_ErrorTranslate(err)); |
jancumps | 1:aa0af9cf4f28 | 96 | return 0; |
jancumps | 1:aa0af9cf4f28 | 97 | } |
jancumps | 1:aa0af9cf4f28 | 98 | |
jancumps | 1:aa0af9cf4f28 | 99 | scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { |
jancumps | 1:aa0af9cf4f28 | 100 | (void) context; |
jancumps | 1:aa0af9cf4f28 | 101 | |
jancumps | 1:aa0af9cf4f28 | 102 | if (SCPI_CTRL_SRQ == ctrl) { |
jancumps | 1:aa0af9cf4f28 | 103 | // fprintf(stderr, "**SRQ: 0x%X (%d)\r\n", val, val); |
jancumps | 1:aa0af9cf4f28 | 104 | } else { |
jancumps | 1:aa0af9cf4f28 | 105 | // fprintf(stderr, "**CTRL %02x: 0x%X (%d)\r\n", ctrl, val, val); |
jancumps | 1:aa0af9cf4f28 | 106 | } |
jancumps | 1:aa0af9cf4f28 | 107 | return SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 108 | } |
jancumps | 1:aa0af9cf4f28 | 109 | |
jancumps | 1:aa0af9cf4f28 | 110 | scpi_result_t SCPI_Reset(scpi_t * context) { |
jancumps | 1:aa0af9cf4f28 | 111 | (void) context; |
jancumps | 1:aa0af9cf4f28 | 112 | |
jancumps | 1:aa0af9cf4f28 | 113 | // fprintf(stderr, "**Reset\r\n"); |
jancumps | 1:aa0af9cf4f28 | 114 | return SCPI_RES_OK; |
jancumps | 1:aa0af9cf4f28 | 115 | } |
jancumps | 1:aa0af9cf4f28 | 116 | |
jancumps | 1:aa0af9cf4f28 | 117 | |
jancumps | 1:aa0af9cf4f28 | 118 | |
jancumps | 1:aa0af9cf4f28 | 119 | /* |
jancumps | 1:aa0af9cf4f28 | 120 | * |
jancumps | 1:aa0af9cf4f28 | 121 | */ |
jancumps | 1:aa0af9cf4f28 | 122 | int main(int argc, char** argv) { |
jancumps | 1:aa0af9cf4f28 | 123 | (void) argc; |
jancumps | 1:aa0af9cf4f28 | 124 | (void) argv; |
jancumps | 1:aa0af9cf4f28 | 125 | int result; |
jancumps | 1:aa0af9cf4f28 | 126 | |
jancumps | 1:aa0af9cf4f28 | 127 | int character; |
jancumps | 1:aa0af9cf4f28 | 128 | |
jancumps | 1:aa0af9cf4f28 | 129 | SCPI_Init(&scpi_context, |
jancumps | 1:aa0af9cf4f28 | 130 | scpi_commands, |
jancumps | 1:aa0af9cf4f28 | 131 | &scpi_interface, |
jancumps | 1:aa0af9cf4f28 | 132 | scpi_units_def, |
jancumps | 1:aa0af9cf4f28 | 133 | SCPI_IDN1, SCPI_IDN2, SCPI_IDN3, SCPI_IDN4, |
jancumps | 1:aa0af9cf4f28 | 134 | scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH, |
jancumps | 1:aa0af9cf4f28 | 135 | scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE); |
jancumps | 1:aa0af9cf4f28 | 136 | |
jancumps | 1:aa0af9cf4f28 | 137 | |
jancumps | 1:aa0af9cf4f28 | 138 | |
LancasterUniversity | 0:0041f35b0c4c | 139 | // Initialise the micro:bit runtime. |
LancasterUniversity | 0:0041f35b0c4c | 140 | uBit.init(); |
jancumps | 1:aa0af9cf4f28 | 141 | uBit.io.P0.setDigitalValue(0); |
jancumps | 1:aa0af9cf4f28 | 142 | uBit.io.P1.setDigitalValue(0); |
jancumps | 1:aa0af9cf4f28 | 143 | |
LancasterUniversity | 0:0041f35b0c4c | 144 | |
jancumps | 1:aa0af9cf4f28 | 145 | |
LancasterUniversity | 0:0041f35b0c4c | 146 | |
jancumps | 1:aa0af9cf4f28 | 147 | |
jancumps | 1:aa0af9cf4f28 | 148 | while(1) { // the device goes into low power when no characters arrive |
jancumps | 1:aa0af9cf4f28 | 149 | character = serial.read(SYNC_SLEEP); |
jancumps | 1:aa0af9cf4f28 | 150 | SCPI_Input(&scpi_context, (const char *) (&character), 1); |
jancumps | 1:aa0af9cf4f28 | 151 | } |
jancumps | 1:aa0af9cf4f28 | 152 | |
jancumps | 1:aa0af9cf4f28 | 153 | |
jancumps | 1:aa0af9cf4f28 | 154 | |
LancasterUniversity | 0:0041f35b0c4c | 155 | release_fiber(); |
jancumps | 1:aa0af9cf4f28 | 156 | |
jancumps | 1:aa0af9cf4f28 | 157 | |
jancumps | 1:aa0af9cf4f28 | 158 | return (EXIT_SUCCESS); |
LancasterUniversity | 0:0041f35b0c4c | 159 | } |
LancasterUniversity | 0:0041f35b0c4c | 160 | |
jancumps | 1:aa0af9cf4f28 | 161 | |
jancumps | 1:aa0af9cf4f28 | 162 |