| | |
| | | * @return number of bytes written |
| | | */ |
| | | static size_t writeData(scpi_t * context, const char * data, size_t len) { |
| | | return context->interface->write(context, data, len); |
| | | if (len > 0) { |
| | | return context->interface->write(context, data, len); |
| | | } else { |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | size_t SCPI_ResultText(scpi_t * context, const char * data) { |
| | | size_t result = 0; |
| | | size_t len = strlen(data); |
| | | const char * quote; |
| | | result += writeDelimiter(context); |
| | | result += writeData(context, "\"", 1); |
| | | // TODO: convert " to "" |
| | | result += writeData(context, data, strlen(data)); |
| | | while (quote = strnpbrk(data, len, "\"")) { |
| | | result += writeData(context, data, quote - data + 1); |
| | | result += writeData(context, "\"", 1); |
| | | len -= quote - data + 1; |
| | | data = quote + 1; |
| | | } |
| | | result += writeData(context, data, len); |
| | | result += writeData(context, "\"", 1); |
| | | context->output_count++; |
| | | return result; |
| | |
| | | * @param count |
| | | * @param item_size |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | static size_t parserResultArrayBinary(scpi_t * context, const void * array, size_t count, size_t item_size, scpi_array_format_t format) { |
| | | |
| | |
| | | break; |
| | | case 2: |
| | | for (i = 0; i < count; i++) { |
| | | uint16_t val = SCPI_Swap16(((uint16_t*)array)[i]); |
| | | uint16_t val = SCPI_Swap16(((uint16_t*) array)[i]); |
| | | result += SCPI_ResultArbitraryBlockData(context, &val, item_size); |
| | | } |
| | | break; |
| | | case 4: |
| | | for (i = 0; i < count; i++) { |
| | | uint32_t val = SCPI_Swap32(((uint32_t*)array)[i]); |
| | | uint32_t val = SCPI_Swap32(((uint32_t*) array)[i]); |
| | | result += SCPI_ResultArbitraryBlockData(context, &val, item_size); |
| | | } |
| | | break; |
| | | case 8: |
| | | for (i = 0; i < count; i++) { |
| | | uint64_t val = SCPI_Swap64(((uint64_t*)array)[i]); |
| | | uint64_t val = SCPI_Swap64(((uint64_t*) array)[i]); |
| | | result += SCPI_ResultArbitraryBlockData(context, &val, item_size); |
| | | } |
| | | break; |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayInt16(scpi_t * context, const int16_t * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultInt16); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayUInt16(scpi_t * context, const uint16_t * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultUInt16); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayInt32(scpi_t * context, const int32_t * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultInt32); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayUInt32(scpi_t * context, const uint32_t * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultUInt32); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayInt64(scpi_t * context, const int64_t * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultInt64); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayUInt64(scpi_t * context, const uint64_t * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultUInt64); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayFloat(scpi_t * context, const float * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultFloat); |
| | |
| | | * @param array |
| | | * @param count |
| | | * @param format |
| | | * @return |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultArrayDouble(scpi_t * context, const double * array, size_t count, scpi_array_format_t format) { |
| | | RESULT_ARRAY(SCPI_ResultDouble); |