SCPI parser and status register model implementation (device side) written in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scpi_parser/main.c

89 lines
1.6 KiB

9 years ago
#include <stdio.h>
#include <string.h>
9 years ago
#include <stdlib.h>
9 years ago
#include "source/scpi_parser.h"
// ------- TESTING ----------
int main()
{
scpi_handle_string("*IDN?\n");
scpi_handle_string("*SRE 4\n");
scpi_handle_string("FOO:BAR:BAZ\n");
scpi_handle_string("SYST:ERR:COUNT?\n");
scpi_handle_string("SYST:ERR?\n");
scpi_handle_string("SYST:ERR?\n");
scpi_handle_string("DATA:BLOB #216abcdefghijklmnop\n");
scpi_handle_string("SYST:ERR?\n");
}
// ---- Test device impl ----
void scpi_send_byte_impl(uint8_t b)
{
putchar(b); // device sends a byte
}
const char *scpi_device_identifier(void)
{
return "FEL CVUT,DDS1,0,0.1";
}
void scpi_service_request_impl(void)
{
printf("[SRQ]\n");
}
// ---- COMMANDS ----
void cmd_APPL_SIN_cb(const SCPI_argval_t *args)
{
printf("cb APPLy:SINe %d, %f, %f\n", args[0].INT, args[0].FLOAT, args[0].FLOAT);
}
9 years ago
void cmd_DISP_TEXT_cb(const SCPI_argval_t *args)
9 years ago
{
printf("cb DISPlay:TEXT %s\n", args[0].STRING);
9 years ago
}
void cmd_DATA_BLOB_cb(const SCPI_argval_t *args)
9 years ago
{
printf("cb DATA:BLOB <%d>\n", args[1].BLOB_LEN);
9 years ago
}
void cmd_DATA_BLOB_data(const uint8_t *bytes)
9 years ago
{
printf("blob item: %s\n", bytes);
9 years ago
}
const SCPI_command_t scpi_commands[] = {
9 years ago
{
.levels = {"APPLy", "SINe"},
.params = {SCPI_DT_INT, SCPI_DT_FLOAT, SCPI_DT_FLOAT},
9 years ago
.callback = cmd_APPL_SIN_cb
},
{
.levels = {"DISPlay", "TEXT"},
.params = {SCPI_DT_STRING},
.callback = cmd_DISP_TEXT_cb
},
{
.levels = {"DATA", "BLOB"},
.params = {SCPI_DT_BLOB},
.callback = cmd_DATA_BLOB_cb,
.blob_chunk = 4,
.blob_callback = cmd_DATA_BLOB_data
},
{0} // end marker
9 years ago
};