/* invoked once for every Server in ServerList */ static bool decode_serverlist(pb_istream_t *stream, const pb_field_t *field, void **arg) { decode_serverlist_arg *dec_arg = *arg; if (dec_arg->first_pass) { /* count how many server do we have */ grpc_grpclb_server server; if (!pb_decode(stream, grpc_lb_v1_Server_fields, &server)) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); return false; } dec_arg->num_servers++; } else { /* second pass. Actually decode. */ grpc_grpclb_server *server = gpr_zalloc(sizeof(grpc_grpclb_server)); GPR_ASSERT(dec_arg->num_servers > 0); if (dec_arg->decoding_idx == 0) { /* first iteration of second pass */ dec_arg->servers = gpr_malloc(sizeof(grpc_grpclb_server *) * dec_arg->num_servers); } if (!pb_decode(stream, grpc_lb_v1_Server_fields, server)) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); return false; } dec_arg->servers[dec_arg->decoding_idx++] = server; } return true; }
int main(int argc, char** argv) { if (argc != 2) {fprintf(stderr, "%s our_sk", argv[0]); return 1;} unsigned char sk[crypto_box_SECRETKEYBYTES]; { FILE* f = fopen(argv[1], "r"); if (f == NULL) {fprintf(stderr, "Cannot open our secret key file"); return 1;} int len = fread(sk, 1, crypto_box_SECRETKEYBYTES, f); fclose(f); if (len != crypto_box_SECRETKEYBYTES) {fprintf(stderr, "Bad secret key file"); return 1;} } uint8_t buf[1<<16]; int len = fread(buf, 1, 1<<16, stdin); pb_istream_t stream = pb_istream_from_buffer(buf, len); Box box; if (!pb_decode(&stream, Box_fields, &box)) return 1; if (box.enc_algo != 1) return 1; uint8_t n[crypto_box_NONCEBYTES]; for (int i=0; i<crypto_box_NONCEBYTES; ++i) n[i] = box.data.bytes[i]; for (int i=0; i<crypto_box_BOXZEROBYTES; ++i) box.data.bytes[i] = 0; stream = pb_istream_from_buffer(box.sender.bytes, box.sender.size); PublicKey pk; if (!pb_decode(&stream, PublicKey_fields, &pk)) return 1; PublicKeyData pkd; stream = pb_istream_from_buffer(pk.publickey_msg.bytes, pk.publickey_msg.size); if (!pb_decode(&stream, PublicKeyData_fields, &pkd)) return 1; int decrypted = 0; for (int i=0; i<min(pkd.enc_keys_count,pkd.enc_algos_count); i++) { if (pkd.enc_keys[i].size == crypto_box_PUBLICKEYBYTES && pkd.sig_algos[i] == 1) { uint8_t* encpk = &pkd.enc_keys[i].bytes[0]; if (crypto_box_open(buf,box.data.bytes+8,box.data.size-8,n,encpk,sk) == 0) { decrypted = 1; break; } } } for (int i=0; i<crypto_box_SECRETKEYBYTES; i++) sk[i] = 0; if (decrypted) { int got = fwrite(buf+crypto_box_ZEROBYTES, 1, box.data.size-8-crypto_box_ZEROBYTES, stdout); assert(got == box.data.size-8-crypto_box_ZEROBYTES); got = fwrite(box.sender.bytes, 1, box.sender.size, stderr); assert(got == box.sender.size); } return !decrypted; }
bool decode_trace_context(google_trace_TraceContext *ctxt, uint8_t *buffer, const size_t nbytes) { // Create a stream that reads nbytes from the buffer. pb_istream_t stream = pb_istream_from_buffer(buffer, nbytes); // decode message bool status = pb_decode(&stream, google_trace_TraceContext_fields, ctxt); if (!status) { gpr_log(GPR_DEBUG, "TraceContext decoding failed: %s", PB_GET_ERROR(&stream)); return false; } // check fields if (!ctxt->has_trace_id) { gpr_log(GPR_DEBUG, "Invalid TraceContext: missing trace_id"); return false; } if (!ctxt->has_span_id) { gpr_log(GPR_DEBUG, "Invalid TraceContext: missing span_id"); return false; } return true; }
// Validate the contents of a Resource proto. `id` is the intended resource id. static bool validate_resource_pb(const uint8_t *resource_pb, size_t resource_pb_size, size_t id) { GPR_ASSERT(id < n_resources); if (resource_pb == NULL) { return false; } google_census_Resource vresource; vresource.name.funcs.decode = &validate_string; vresource.name.arg = resources[id]; vresource.description.funcs.decode = &validate_string; vresource.description.arg = resources[id]; vresource.unit.numerator.funcs.decode = &validate_units; vresource.unit.numerator.arg = resources[id]; vresource.unit.denominator.funcs.decode = &validate_units; vresource.unit.denominator.arg = resources[id]; pb_istream_t stream = pb_istream_from_buffer((uint8_t *)resource_pb, resource_pb_size); if (!pb_decode(&stream, google_census_Resource_fields, &vresource)) { return false; } // A Resource must have a name, a unit, with at least one numerator. return (resources[id]->name != NULL && vresource.has_unit && resources[id]->n_numerators > 0); }
void processDataMsg(pb_istream_t *streamPtr) { MotorMsg_Data motorData = MotorMsg_Data_init_zero; if (pb_decode(streamPtr, MotorMsg_Data_fields, &motorData)) { if (motorData.action == MotorMsg_Data_Action_GET) { } else if (motorData.action == MotorMsg_Data_Action_RESULT) { } } }
void cdc_rx_notify(uint8_t port) { l("cdc_rx_notify [%d]", port); uint8_t b = udi_cdc_getc(); if (b != 0x08) { l("Protocol desync"); } l("First byte ok"); uint32_t offset = 0; do { buffer[offset++] = b; b = udi_cdc_getc(); l("-> 0x%02x", b); } while (b & 0x80); buffer[offset++] = b; // Now we have enough to know the size l("Length read, decoding..."); l("... 0x%02x 0x%02x", buffer[0], buffer[1]); pb_istream_t istream = pb_istream_from_buffer(buffer + 1, USB_BUFFER_SIZE); l("istream bytes_left before %d", istream.bytes_left); uint64_t len = 0; pb_decode_varint(&istream, &len); l("message_length %d", (uint32_t)len); l("offset %d", offset); udi_cdc_read_buf(buffer + offset, len); l("decode message"); istream = pb_istream_from_buffer(buffer + offset, len); DonglePiRequest request = {0}; request.config.i2c.funcs.decode = handle_i2c_config_cb; request.config.uart.funcs.decode = handle_uart_config_cb; request.config.spi.funcs.decode = handle_spi_config_cb; request.config.gpio.pins.funcs.decode = handle_gpio_pin_config_cb; request.data.i2c.writes.funcs.decode = handle_i2c_write_cb; if (!pb_decode(&istream, DonglePiRequest_fields, &request)) { l("failed to decode the packet, wait for more data"); return; } l("Request #%d received", request.message_nb); if (request.has_data && request.data.has_gpio) { handle_gpio_write(request.data.gpio); } pb_ostream_t ostream = pb_ostream_from_buffer(buffer, USB_BUFFER_SIZE); DonglePiResponse response = {}; response.message_nb = request.message_nb; l("Create response for #%d", response.message_nb); handle_gpio_read(&response); pb_encode_delimited(&ostream, DonglePiResponse_fields, &response); l("Write response nb_bytes = %d", ostream.bytes_written); uint32_t wrote = udi_cdc_write_buf(buffer, ostream.bytes_written); l("Done. wrote %d bytes", wrote); }
bool NetDecode( ENetPacket *packet, void *dest, const pb_field_t *fields) { pb_istream_t stream = pb_istream_from_buffer( packet->data + NET_MSG_SIZE, packet->dataLength - NET_MSG_SIZE); bool status = pb_decode(&stream, fields, dest); CASSERT(status, "Failed to decode pb"); return status; }
bool decodeMotorMsgContents(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct) { pb_istream_t substream; bool status; if (!pb_make_string_substream(stream, &substream)) return false; status = pb_decode(&substream, fields, dest_struct); pb_close_string_substream(stream, &substream); return status; }
static bool read_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage submsg = {""}; if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; TEST(memcmp(&submsg, *arg, sizeof(submsg))); return true; }
/** * Message EPS decode callback function * @param stream * @param field * @param arg * @return */ bool ss_eps_decode(pb_istream_t *stream, const pb_field_t *field, void **arg) { EPS eps=EPS_init_zero; if (!pb_decode(stream, EPS_fields, &eps)) return false; return true; }
static bool read_repeated_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage** expected = (SubMessage**)arg; SubMessage decoded = {""}; if (!pb_decode(stream, SubMessage_fields, &decoded)) return false; TEST(memcmp((*expected)++, &decoded, sizeof(decoded)) == 0); return true; }
void msg_process(char type, uint16_t msg_id, const pb_field_t *fields, uint8_t *msg_raw, uint32_t msg_size) { static uint8_t msg_data[MSG_IN_SIZE]; pb_istream_t stream = pb_istream_from_buffer(msg_raw, msg_size); bool status = pb_decode(&stream, fields, msg_data); if (status) { MessageProcessFunc(type, 'i', msg_id, msg_data); } else { fsm_sendFailure(FailureType_Failure_SyntaxError, stream.errmsg); } }
void msg_read_tiny(uint8_t *buf, int len) { if (len != 64) return; if (buf[0] != '?' || buf[1] != '#' || buf[2] != '#') { return; } uint16_t msg_id = (buf[3] << 8) + buf[4]; uint32_t msg_size = (buf[5] << 24) + (buf[6] << 16) + (buf[7] << 8) + buf[8]; if (msg_size > 64 || len - msg_size < 9) { return; } const pb_field_t *fields = 0; pb_istream_t stream = pb_istream_from_buffer(buf + 9, msg_size); switch (msg_id) { case MessageType_MessageType_PinMatrixAck: fields = PinMatrixAck_fields; break; case MessageType_MessageType_ButtonAck: fields = ButtonAck_fields; break; case MessageType_MessageType_PassphraseAck: fields = PassphraseAck_fields; break; case MessageType_MessageType_Cancel: fields = Cancel_fields; break; case MessageType_MessageType_Initialize: fields = Initialize_fields; break; #if DEBUG_LINK case MessageType_MessageType_DebugLinkDecision: fields = DebugLinkDecision_fields; break; case MessageType_MessageType_DebugLinkGetState: fields = DebugLinkGetState_fields; break; #endif } if (fields) { bool status = pb_decode(&stream, fields, msg_tiny); if (status) { msg_tiny_id = msg_id; } else { fsm_sendFailure(FailureType_Failure_SyntaxError, stream.errmsg); msg_tiny_id = 0xFFFF; } } else { fsm_sendFailure(FailureType_Failure_UnexpectedMessage, "Unknown message"); msg_tiny_id = 0xFFFF; } }
int main(int argc, char** argv) { int human = argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h'; uint8_t buffer[256]; int len = fread(buffer, 1, sizeof(buffer), stdin); pb_istream_t stream = pb_istream_from_buffer(buffer, len); PublicKey pk; if (!pb_decode(&stream, PublicKey_fields, &pk)) return 1; PublicKeyData pkd; stream = pb_istream_from_buffer(pk.publickey_msg.bytes, pk.publickey_msg.size); if (!pb_decode(&stream, PublicKeyData_fields, &pkd)) return 1; for (int i=0; i<pkd.sig_keys_count; i++) { if ( pk.sigs_count < i || pk.sigs[i].size < crypto_sign_BYTES || pkd.sig_keys[i].size < crypto_sign_PUBLICKEYBYTES || crypto_sign_detach_open(pk.publickey_msg.bytes, pk.publickey_msg.size, pk.sigs[i].bytes, pkd.sig_keys[i].bytes) != 0) { fprintf(stderr, "Invalid key\n"); return 2; } else { initialise(1344, 256, 128); char* dgst = digest((char*)pkd.sig_keys[i].bytes, pkd.sig_keys[i].size, 1); for (int i=0; i<128/8; i+=2) { if (i > 0 && human) { fprintf(stdout, " "); if (i == 8) fprintf(stdout, " "); } fprintf(stdout, "%X", (dgst[i]&0xF0)>>4); fprintf(stdout, "%X", dgst[i]&0x0F); fprintf(stdout, "%X", (dgst[i+1]&0xF0)>>4); fprintf(stdout, "%X", dgst[i+1]&0x0F); } if (human) printf("\n"); else return 1; dispose(); } } }
/** * Message EPS decode callback function * @param stream * @param field * @param arg * @return */ bool ss_decode_eps(pb_istream_t *stream, const pb_field_t *field, void **arg) { printf("eps_decode_callback executing\n"); EPS eps=EPS_init_zero; if (!pb_decode(stream, EPS_fields, &eps)) return false; printf("in eps decode function, profile_id:%s\n",eps.profile_id); return true; }
static bool read_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage submsg = {""}; SubMessage *ref = *arg; if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; TEST(strcmp(submsg.substuff1, ref->substuff1) == 0); TEST(submsg.substuff2 == ref->substuff2); TEST(submsg.has_substuff3 == ref->has_substuff3); TEST(submsg.substuff3 == ref->substuff3); return true; }
grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist( grpc_slice encoded_grpc_grpclb_response) { bool status; decode_serverlist_arg arg; pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response), GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); pb_istream_t stream_at_start = stream; grpc_grpclb_response res; memset(&res, 0, sizeof(grpc_grpclb_response)); memset(&arg, 0, sizeof(decode_serverlist_arg)); res.server_list.servers.funcs.decode = decode_serverlist; res.server_list.servers.arg = &arg; arg.first_pass = true; status = pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res); if (!status) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); return NULL; } arg.first_pass = false; status = pb_decode(&stream_at_start, grpc_lb_v1_LoadBalanceResponse_fields, &res); if (!status) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); return NULL; } grpc_grpclb_serverlist *sl = gpr_zalloc(sizeof(grpc_grpclb_serverlist)); sl->num_servers = arg.num_servers; sl->servers = arg.servers; if (res.server_list.has_expiration_interval) { sl->expiration_interval = res.server_list.expiration_interval; } return sl; }
/** * close the SACD device and clean up. */ static int sacd_net_input_close(sacd_input_t dev) { if (!dev) { return 0; } else { ServerRequest request; ServerResponse response; pb_istream_t input = pb_istream_from_socket(&dev->fd); pb_ostream_t output = pb_ostream_from_socket(&dev->fd); uint8_t zero = 0; request.type = ServerRequest_Type_DISC_CLOSE; if (!pb_encode(&output, ServerRequest_fields, &request)) { goto error; } pb_write(&output, &zero, 1); if (!pb_decode(&input, ServerResponse_fields, &response)) { goto error; } if (response.result == 0 || response.type != ServerResponse_Type_DISC_CLOSED) { goto error; } } error: if(dev) { socket_destroy(&dev->fd); socket_close(); if (dev->input_buffer) { free(dev->input_buffer); dev->input_buffer = 0; } free(dev); dev = 0; } return 0; }
static bool read_repeated_submsg(pb_istream_t *stream, const pb_field_t *field, void **arg) { SubMessage** expected = (SubMessage**)arg; SubMessage submsg = {""}; if (!pb_decode(stream, SubMessage_fields, &submsg)) return false; TEST(strcmp(submsg.substuff1, (*expected)->substuff1) == 0); TEST(submsg.substuff2 == (*expected)->substuff2); TEST(submsg.has_substuff3 == (*expected)->has_substuff3); TEST(submsg.substuff3 == (*expected)->substuff3); (*expected)++; return true; }
bool motorCmdParamCallback(pb_istream_t *stream, const pb_field_t *field, void **arg) { bool returnVal = true; if (gCmdParamNum < MAX_CMD_PARAMS) { MotorMsg_Cmd_Param param = MotorMsg_Cmd_Param_init_zero; gCmdParams[gCmdParamNum] = param; if (!pb_decode(stream, MotorMsg_Cmd_Param_fields, &gCmdParams[gCmdParamNum])) { returnVal = false; } gCmdParamNum++; } return returnVal; }
/** * Message devlist decode callback funciton * @param stream * @param field * @param arg * @return */ bool ss_decode_devlist(pb_istream_t *stream, const pb_field_t *field, void **arg) { Dev devlist=Dev_init_zero; log_printf(LOG_VERBOSE,"Devlist SubMessage Decoding!\n"); devlist.eps.funcs.decode=&ss_decode_eps; if (!pb_decode(stream, Dev_fields, &devlist)) { //printf("devlist_decode_callback failed!\n"); return false; } //printf("ieee:%s\n",devlist.nwk_addr); return true; }
grpc_grpclb_initial_response *grpc_grpclb_initial_response_parse( grpc_slice encoded_grpc_grpclb_response) { pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response), GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); grpc_grpclb_response res; memset(&res, 0, sizeof(grpc_grpclb_response)); if (!pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res)) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); return NULL; } grpc_grpclb_initial_response *initial_res = gpr_malloc(sizeof(grpc_grpclb_initial_response)); memcpy(initial_res, &res.initial_response, sizeof(grpc_grpclb_initial_response)); return initial_res; }
/** * Message SSMsg decode function * @param buffer * @param buf_len * @param ssmsg * @return */ int ss_pb_decode(uint8_t *buffer,int buf_len,SSMsg *ssmsg) { bool status; pb_istream_t stream = pb_istream_from_buffer(buffer, buf_len); //ssmsg->devlist.funcs.decode=&ss_decode_devlist; log_printf(LOG_VERBOSE,"SSMsg Decoding! \n"); status=pb_decode(&stream, SSMsg_fields, ssmsg); if (!status) { log_printf(LOG_ERROR,"Decoding failed: %s\n", PB_GET_ERROR(&stream)); return -1; } return 1; }
/* This function is called once from main(), it handles the decoding and printing. */ bool print_person(pb_istream_t *stream) { int i; Person person = Person_init_zero; if (!pb_decode(stream, Person_fields, &person)) return false; /* Now the decoding is done, rest is just to print stuff out. */ printf("name: \"%s\"\n", person.name); printf("id: %ld\n", (long)person.id); if (person.has_email) printf("email: \"%s\"\n", person.email); for (i = 0; i < person.phone_count; i++) { Person_PhoneNumber *phone = &person.phone[i]; printf("phone {\n"); printf(" number: \"%s\"\n", phone->number); if (phone->has_type) { switch (phone->type) { case Person_PhoneType_WORK: printf(" type: WORK\n"); break; case Person_PhoneType_HOME: printf(" type: HOME\n"); break; case Person_PhoneType_MOBILE: printf(" type: MOBILE\n"); break; } } printf("}\n"); } return true; }
int main() { TestResults results = {}; AllTypes message = {}; pb_istream_t istream = pb_istream_from_buffer((uint8_t*)input_data, sizeof(input_data)); results.success = pb_decode(&istream, AllTypes_fields, &message); results.success &= (message.end == 1099); results.has_stack_usage = true; results.stack_usage = platform_stack_usage(); uint8_t buf[16]; pb_ostream_t ostream = pb_ostream_from_buffer(buf, sizeof(buf)); pb_encode(&ostream, TestResults_fields, &results); platform_write(buf, ostream.bytes_written); return 0; }
static bool read_limits(pb_istream_t *stream, const pb_field_t *field, void **arg) { Limits decoded = {0}; if (!pb_decode(stream, Limits_fields, &decoded)) return false; TEST(decoded.int32_min == INT32_MIN); TEST(decoded.int32_max == INT32_MAX); TEST(decoded.uint32_min == 0); TEST(decoded.uint32_max == UINT32_MAX); TEST(decoded.int64_min == INT64_MIN); TEST(decoded.int64_max == INT64_MAX); TEST(decoded.uint64_min == 0); TEST(decoded.uint64_max == UINT64_MAX); TEST(decoded.enum_min == HugeEnum_Negative); TEST(decoded.enum_max == HugeEnum_Positive); return true; }
static int decode_msg(pbring_inst_t *p, pb_istream_t *stream, const hal_funct_args_t *fa) { if (!pb_decode(stream, pb_Container_fields, &p->rx)) { *(p->decodefail) += 1; rtapi_print_msg(RTAPI_MSG_ERR, "%s: pb_decode(Container) failed: '%s'\n", fa_funct_name(fa), PB_GET_ERROR(stream)); return -1; } if (p->rx.has_motcmd) { rtapi_print_msg(RTAPI_MSG_ERR, "Container.motcmd command=%d num=%d\n", p->rx.motcmd.command,p->rx.motcmd.commandNum); if (p->rx.motcmd.has_pos) { char buf[200]; rtapi_format_pose(buf, sizeof(buf), &p->rx.motcmd.pos); rtapi_print_msg(RTAPI_MSG_ERR, "motcmd: %s\n", buf); } } return 0; }
/* Test the 'AnonymousOneOfMessage' */ int test_oneof_1(pb_istream_t *stream, int option) { AnonymousOneOfMessage msg; int status = 0; /* To better catch initialization errors */ memset(&msg, 0xAA, sizeof(msg)); if (!pb_decode(stream, AnonymousOneOfMessage_fields, &msg)) { printf("Decoding failed: %s\n", PB_GET_ERROR(stream)); return 1; } /* Check that the basic fields work normally */ TEST(msg.prefix == 123); TEST(msg.suffix == 321); /* Check that we got the right oneof according to command line */ if (option == 1) { TEST(msg.which_values == AnonymousOneOfMessage_first_tag); TEST(msg.first == 999); } else if (option == 2) { TEST(msg.which_values == AnonymousOneOfMessage_second_tag); TEST(strcmp(msg.second, "abcd") == 0); } else if (option == 3) { TEST(msg.which_values == AnonymousOneOfMessage_third_tag); TEST(msg.third.array[0] == 1); TEST(msg.third.array[1] == 2); TEST(msg.third.array[2] == 3); TEST(msg.third.array[3] == 4); TEST(msg.third.array[4] == 5); } return status; }
void handle_connection(int connfd) { ListFilesRequest request; ListFilesResponse response; pb_istream_t input = pb_istream_from_socket(connfd); pb_ostream_t output = pb_ostream_from_socket(connfd); DIR *directory; if (!pb_decode(&input, ListFilesRequest_fields, &request)) { printf("Decoding failed.\n"); return; } directory = opendir(request.path); printf("Listing directory: %s\n", request.path); if (directory == NULL) { perror("opendir"); response.has_path_error = true; response.path_error = true; response.file.funcs.encode = NULL; } else { response.has_path_error = false; response.file.funcs.encode = &listdir_callback; response.file.arg = directory; } if (!pb_encode(&output, ListFilesResponse_fields, &response)) { printf("Encoding failed.\n"); } }
void processCmdMsg(pb_istream_t *streamPtr) { pb_istream_t substream; gCmdParamNum = 0; double degSec; double pos; EMotorDirection dir; if (pb_make_string_substream(streamPtr, &substream)) { MotorMsg_Cmd motorCmd = MotorMsg_Cmd_init_zero; motorCmd.params.funcs.decode = &motorCmdParamCallback; //motorCmd.params.arg = (void *) (&motorCmd.action); pb_decode(&substream, MotorMsg_Cmd_fields, &motorCmd); pb_close_string_substream(streamPtr, &substream); switch (motorCmd.action) { case MotorMsg_Cmd_Action_UNKNOWN: break; case MotorMsg_Cmd_Action_BRAKE: motorBrake(); break; case MotorMsg_Cmd_Action_FREEWHEEL: motorFreewheel(); break; case MotorMsg_Cmd_Action_RUN: degSec = getMotorParam(MotorMsg_Cmd_Param_Id_VELOCITY, gCmdParams, gCmdParamNum); dir = (getMotorParam(MotorMsg_Cmd_Param_Id_CLOCKWISE, gCmdParams, gCmdParamNum) != 0.0) ? eClockwise : eCounterClockwise; motorRun(dir, degSec); break; case MotorMsg_Cmd_Action_GOTO_POS: pos = getMotorParam(MotorMsg_Cmd_Param_Id_POSITION, gCmdParams, gCmdParamNum); degSec = getMotorParam(MotorMsg_Cmd_Param_Id_VELOCITY, gCmdParams, gCmdParamNum); dir = (getMotorParam(MotorMsg_Cmd_Param_Id_CLOCKWISE, gCmdParams, gCmdParamNum) != 0.0) ? eClockwise : eCounterClockwise; motorGotoPos(dir, pos, degSec); break; } } }