mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 18:55:13 +03:00
little fix
This commit is contained in:
parent
edcc1fd563
commit
ce21cb7e10
@ -54,9 +54,9 @@ int main(){
|
|||||||
while(1){
|
while(1){
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
//check_and_parce_UART(USART1); // also check data in UART buffers
|
//check_and_parse_UART(USART1); // also check data in UART buffers
|
||||||
check_btns();
|
check_btns();
|
||||||
if(Timer - Old_timer > 999){ // one-second cycle
|
if(Timer - Old_timer > 999){ // one-second cycle
|
||||||
Old_timer += 1000;
|
Old_timer += 1000;
|
||||||
|
|||||||
@ -61,10 +61,10 @@ uint8_t show_int(int32_t v){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@ -45,7 +45,7 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
void OW_printID(uint8_t N);
|
void OW_printID(uint8_t N);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
#include "dmagpio.h"
|
#include "dmagpio.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
void parse_incoming_buf(uint8_t *buf, int *len){
|
void parse_incoming_buf(uint8_t *buf, int *len){
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
#include "timgpio.h"
|
#include "timgpio.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
void parse_incoming_buf(uint8_t *buf, int *len){
|
void parse_incoming_buf(uint8_t *buf, int *len){
|
||||||
|
|||||||
@ -95,7 +95,7 @@ int main(){
|
|||||||
poll_ultrasonic();
|
poll_ultrasonic();
|
||||||
poll_ADC();
|
poll_ADC();
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
if((string = check_UART2())){
|
if((string = check_UART2())){
|
||||||
// P(string);
|
// P(string);
|
||||||
|
|||||||
@ -98,7 +98,7 @@ void UART_isr(uint32_t UART){
|
|||||||
UART_buff *curbuff;
|
UART_buff *curbuff;
|
||||||
// Check if we were called because of RXNE
|
// Check if we were called because of RXNE
|
||||||
if(USART_SR(UART) & USART_SR_RXNE){
|
if(USART_SR(UART) & USART_SR_RXNE){
|
||||||
// parce incoming byte
|
// parse incoming byte
|
||||||
data = usart_recv(UART);
|
data = usart_recv(UART);
|
||||||
fill_uart_RXbuff(UART, data);
|
fill_uart_RXbuff(UART, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,10 +62,10 @@ uint8_t show_int(int32_t v){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0, j;
|
int i = 0, j;
|
||||||
|
|||||||
@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -86,7 +86,7 @@ int main(){
|
|||||||
while(1){
|
while(1){
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
if((string = check_UART2())){
|
if((string = check_UART2())){
|
||||||
P(string);
|
P(string);
|
||||||
|
|||||||
@ -98,7 +98,7 @@ void UART_isr(uint32_t UART){
|
|||||||
UART_buff *curbuff;
|
UART_buff *curbuff;
|
||||||
// Check if we were called because of RXNE
|
// Check if we were called because of RXNE
|
||||||
if(USART_SR(UART) & USART_SR_RXNE){
|
if(USART_SR(UART) & USART_SR_RXNE){
|
||||||
// parce incoming byte
|
// parse incoming byte
|
||||||
data = usart_recv(UART);
|
data = usart_recv(UART);
|
||||||
fill_uart_RXbuff(UART, data);
|
fill_uart_RXbuff(UART, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,10 +58,10 @@ uint8_t show_int(int32_t v){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -46,7 +46,7 @@ SCRIPT_DIR = $(OPENCM3_DIR)/scripts
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# C flags
|
# C flags
|
||||||
CFLAGS += -Os -g
|
CFLAGS += -O3 -g
|
||||||
CFLAGS += -Wall -Wextra -Wshadow -Wimplicit-function-declaration
|
CFLAGS += -Wall -Wextra -Wshadow -Wimplicit-function-declaration
|
||||||
CFLAGS += -Wredundant-decls
|
CFLAGS += -Wredundant-decls
|
||||||
# -Wmissing-prototypes -Wstrict-prototypes
|
# -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
Jeep crankshaft signals generator
|
Jeep crankshaft signals generator
|
||||||
|
|
||||||
Speed from 180 to 6000RPM
|
Speed from 200 to 6000RPM
|
||||||
Buttons "+" and "-", LEDS "MIN" and "MAX"
|
Buttons "+" and "-", LEDS "MIN" and "MAX"
|
||||||
|
|
||||||
written for chinese devboard based on STM32F103RBT6
|
written for chinese devboard based on STM32F103RBT6
|
||||||
|
|||||||
Binary file not shown.
@ -43,7 +43,7 @@ int main(){
|
|||||||
while(1){
|
while(1){
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
check_btns();
|
check_btns();
|
||||||
if(Timer - Old_timer > 999){ // one-second cycle
|
if(Timer - Old_timer > 999){ // one-second cycle
|
||||||
|
|||||||
@ -23,9 +23,9 @@
|
|||||||
#include "user_proto.h" // for print_int
|
#include "user_proto.h" // for print_int
|
||||||
|
|
||||||
// current speed
|
// current speed
|
||||||
int32_t current_RPM = 0;
|
uint16_t current_RPM = 0;
|
||||||
void get_RPM();
|
void get_RPM();
|
||||||
uint16_t get_ARR(int32_t RPM);
|
uint16_t get_ARR(uint32_t RPM);
|
||||||
|
|
||||||
// pulses: 16 1/0, 4 1/1, 16 1/0, 4 0/0,
|
// pulses: 16 1/0, 4 1/1, 16 1/0, 4 0/0,
|
||||||
const uint8_t pulses[] = {
|
const uint8_t pulses[] = {
|
||||||
@ -58,8 +58,8 @@ void tim2_isr(){
|
|||||||
GPIO_BSRR(OUTP_PORT) = OUTP_PIN;
|
GPIO_BSRR(OUTP_PORT) = OUTP_PIN;
|
||||||
else
|
else
|
||||||
GPIO_BSRR(OUTP_PORT) = OUTP_PIN << 16;
|
GPIO_BSRR(OUTP_PORT) = OUTP_PIN << 16;
|
||||||
TIM2_SR = 0;
|
|
||||||
}
|
}
|
||||||
|
TIM2_SR = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,14 +67,17 @@ void tim2_isr(){
|
|||||||
* RPM = 1/tim2_arr / 40 * 60
|
* RPM = 1/tim2_arr / 40 * 60
|
||||||
*/
|
*/
|
||||||
void get_RPM(){
|
void get_RPM(){
|
||||||
current_RPM = 3000000 / (int32_t)TIM2_ARR;
|
uint32_t R = 3000000 / (uint32_t)TIM2_ARR;
|
||||||
current_RPM /= 2;
|
current_RPM = R/2;
|
||||||
|
//current_RPM = R;
|
||||||
|
//current_RPM >>= 1; // x/2 != x>>1, WTF?
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate TIM2_ARR by RPM
|
// calculate TIM2_ARR by RPM
|
||||||
uint16_t get_ARR(int32_t RPM){
|
uint16_t get_ARR(uint32_t RPM){
|
||||||
int32_t R = 3000000 / RPM;
|
uint32_t R = 3000000 / RPM;
|
||||||
R /= 2;
|
R /= 2;
|
||||||
|
//R >>= 1;
|
||||||
return (uint16_t)R;
|
return (uint16_t)R;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,13 +31,13 @@
|
|||||||
//~ #define TM2_MAX_SPEED (250)
|
//~ #define TM2_MAX_SPEED (250)
|
||||||
// max & min rotation speed
|
// max & min rotation speed
|
||||||
#define MAX_RPM (6000)
|
#define MAX_RPM (6000)
|
||||||
#define MIN_RPM (180)
|
#define MIN_RPM (200)
|
||||||
|
|
||||||
|
|
||||||
void tim2_init();
|
void tim2_init();
|
||||||
void increase_speed();
|
void increase_speed();
|
||||||
void decrease_speed();
|
void decrease_speed();
|
||||||
|
|
||||||
extern int32_t current_RPM;
|
extern uint16_t current_RPM;
|
||||||
|
|
||||||
#endif // __TIMER_H__
|
#endif // __TIMER_H__
|
||||||
|
|||||||
@ -34,13 +34,13 @@ void help(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(; i < len; i++){
|
for(; i < len; ++i){
|
||||||
command = buf[i];
|
command = buf[i];
|
||||||
if(!command) continue; // omit zero
|
if(!command) continue; // omit zero
|
||||||
switch (command){
|
switch (command){
|
||||||
|
|||||||
@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -97,7 +97,7 @@ void UART_isr(uint32_t UART){
|
|||||||
UART_buff *curbuff;
|
UART_buff *curbuff;
|
||||||
// Check if we were called because of RXNE
|
// Check if we were called because of RXNE
|
||||||
if(USART_SR(UART) & USART_SR_RXNE){
|
if(USART_SR(UART) & USART_SR_RXNE){
|
||||||
// parce incoming byte
|
// parse incoming byte
|
||||||
data = usart_recv(UART);
|
data = usart_recv(UART);
|
||||||
fill_uart_RXbuff(UART, data);
|
fill_uart_RXbuff(UART, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,7 @@ void UART_isr(uint32_t UART){
|
|||||||
UART_buff *curbuff;
|
UART_buff *curbuff;
|
||||||
// Check if we were called because of RXNE
|
// Check if we were called because of RXNE
|
||||||
if(USART_SR(UART) & USART_SR_RXNE){
|
if(USART_SR(UART) & USART_SR_RXNE){
|
||||||
// parce incoming byte
|
// parse incoming byte
|
||||||
data = usart_recv(UART);
|
data = usart_recv(UART);
|
||||||
fill_uart_RXbuff(UART, data);
|
fill_uart_RXbuff(UART, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ void help(){
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parse_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
|
|||||||
@ -137,7 +137,7 @@ void showFval(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* fill uint8_t data buffer with readed data
|
* fill uint8_t data buffer with readed data
|
||||||
*/
|
*/
|
||||||
void parse_incoming_buf(){
|
void parse_incoming_buf(){
|
||||||
|
|||||||
@ -56,7 +56,7 @@ int main(){
|
|||||||
uint32_t L;
|
uint32_t L;
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
if(AWD_flag){
|
if(AWD_flag){
|
||||||
P("Int, value = ");
|
P("Int, value = ");
|
||||||
|
|||||||
@ -59,10 +59,10 @@ uint8_t show_int(int32_t v){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@ -44,6 +44,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -80,7 +80,7 @@ int main(){
|
|||||||
}
|
}
|
||||||
usbdatalen = 0;
|
usbdatalen = 0;
|
||||||
}
|
}
|
||||||
//check_and_parce_UART(USART1); // also check data in UART buffers
|
//check_and_parse_UART(USART1); // also check data in UART buffers
|
||||||
if(Timer - Old_timer > 999){ // one-second cycle
|
if(Timer - Old_timer > 999){ // one-second cycle
|
||||||
Old_timer += 1000;
|
Old_timer += 1000;
|
||||||
//print_int(Timer / 1000);newline();
|
//print_int(Timer / 1000);newline();
|
||||||
|
|||||||
@ -51,9 +51,9 @@ int main(){
|
|||||||
while(1){
|
while(1){
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
//check_and_parce_UART(USART1); // also check data in UART buffers
|
//check_and_parse_UART(USART1); // also check data in UART buffers
|
||||||
check_btns();
|
check_btns();
|
||||||
if(Timer - Old_timer > 999){ // one-second cycle
|
if(Timer - Old_timer > 999){ // one-second cycle
|
||||||
Old_timer += 1000;
|
Old_timer += 1000;
|
||||||
|
|||||||
@ -57,10 +57,10 @@ uint8_t show_int(int32_t v){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* cmdlnopts.c - the only function that parce cmdln args and returns glob parameters
|
* cmdlnopts.c - the only function that parse cmdln args and returns glob parameters
|
||||||
*
|
*
|
||||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||||
*
|
*
|
||||||
@ -93,13 +93,13 @@ myoption cmdlnopts[] = {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parce command line options and return dynamically allocated structure
|
* Parse command line options and return dynamically allocated structure
|
||||||
* to global parameters
|
* to global parameters
|
||||||
* @param argc - copy of argc from main
|
* @param argc - copy of argc from main
|
||||||
* @param argv - copy of argv from main
|
* @param argv - copy of argv from main
|
||||||
* @return allocated structure with global parameters
|
* @return allocated structure with global parameters
|
||||||
*/
|
*/
|
||||||
glob_pars *parce_args(int argc, char **argv){
|
glob_pars *parse_args(int argc, char **argv){
|
||||||
int i;
|
int i;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
|
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
|
||||||
@ -107,7 +107,7 @@ glob_pars *parce_args(int argc, char **argv){
|
|||||||
/// "éÓÐÏÌØÚÏ×ÁÎÉÅ: %s [ÁÒÇÕÍÅÎÔÙ]\n\n\tçÄÅ ÁÒÇÕÍÅÎÔÙ:\n"
|
/// "éÓÐÏÌØÚÏ×ÁÎÉÅ: %s [ÁÒÇÕÍÅÎÔÙ]\n\n\tçÄÅ ÁÒÇÕÍÅÎÔÙ:\n"
|
||||||
change_helpstring(_("Usage: %s [args]\n\n\tWhere args are:\n"));
|
change_helpstring(_("Usage: %s [args]\n\n\tWhere args are:\n"));
|
||||||
// parse arguments
|
// parse arguments
|
||||||
parceargs(&argc, &argv, cmdlnopts);
|
parseargs(&argc, &argv, cmdlnopts);
|
||||||
if(help) showhelp(-1, cmdlnopts);
|
if(help) showhelp(-1, cmdlnopts);
|
||||||
if(argc > 0){
|
if(argc > 0){
|
||||||
/// "éÇÎÏÒÉÒÕÀ ÁÒÇÕÍÅÎÔ[Ù]:"
|
/// "éÇÎÏÒÉÒÕÀ ÁÒÇÕÍÅÎÔ[Ù]:"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* cmdlnopts.h - comand line options for parceargs
|
* cmdlnopts.h - comand line options for parseargs
|
||||||
*
|
*
|
||||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||||
*
|
*
|
||||||
@ -23,7 +23,7 @@
|
|||||||
#ifndef __CMDLNOPTS_H__
|
#ifndef __CMDLNOPTS_H__
|
||||||
#define __CMDLNOPTS_H__
|
#define __CMDLNOPTS_H__
|
||||||
|
|
||||||
#include "parceargs.h"
|
#include "parseargs.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* here are some typedef's for global data
|
* here are some typedef's for global data
|
||||||
@ -35,6 +35,6 @@ typedef struct{
|
|||||||
double relmove; // move relative current position
|
double relmove; // move relative current position
|
||||||
}glob_pars;
|
}glob_pars;
|
||||||
|
|
||||||
glob_pars *parce_args(int argc, char **argv);
|
glob_pars *parse_args(int argc, char **argv);
|
||||||
|
|
||||||
#endif // __CMDLNOPTS_H__
|
#endif // __CMDLNOPTS_H__
|
||||||
|
|||||||
@ -235,7 +235,7 @@ int main(int argc, char *argv[]){
|
|||||||
char buff[BUFLEN+1];
|
char buff[BUFLEN+1];
|
||||||
pthread_t motor_thread;
|
pthread_t motor_thread;
|
||||||
size_t L;
|
size_t L;
|
||||||
Global_parameters = parce_args(argc, argv);
|
Global_parameters = parse_args(argc, argv);
|
||||||
assert(Global_parameters != NULL);
|
assert(Global_parameters != NULL);
|
||||||
if(!get_shm_block(&sdat, ClientSide) || !check_shm_block(&sdat)){
|
if(!get_shm_block(&sdat, ClientSide) || !check_shm_block(&sdat)){
|
||||||
fprintf(stderr, "Can't get SHM block!");
|
fprintf(stderr, "Can't get SHM block!");
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* parceargs.c - parcing command line arguments & print help
|
* parseargs.c - parsing command line arguments & print help
|
||||||
*
|
*
|
||||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||||
*
|
*
|
||||||
@ -27,7 +27,7 @@
|
|||||||
#include <limits.h> // INT_MAX & so on
|
#include <limits.h> // INT_MAX & so on
|
||||||
#include <libintl.h>// gettext
|
#include <libintl.h>// gettext
|
||||||
#include <ctype.h> // isalpha
|
#include <ctype.h> // isalpha
|
||||||
#include "parceargs.h"
|
#include "parseargs.h"
|
||||||
|
|
||||||
// macro to print help messages
|
// macro to print help messages
|
||||||
#ifndef PRNT
|
#ifndef PRNT
|
||||||
@ -135,7 +135,7 @@ int get_optind(int opt, myoption *options){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parce command line arguments
|
* Parse command line arguments
|
||||||
* ! If arg is string, then value will be strdup'ed!
|
* ! If arg is string, then value will be strdup'ed!
|
||||||
*
|
*
|
||||||
* @param argc (io) - address of argc of main(), return value of argc stay after `getopt`
|
* @param argc (io) - address of argc of main(), return value of argc stay after `getopt`
|
||||||
@ -146,7 +146,7 @@ int get_optind(int opt, myoption *options){
|
|||||||
*
|
*
|
||||||
* @exit: in case of error this function show help & make `exit(-1)`
|
* @exit: in case of error this function show help & make `exit(-1)`
|
||||||
*/
|
*/
|
||||||
void parceargs(int *argc, char ***argv, myoption *options){
|
void parseargs(int *argc, char ***argv, myoption *options){
|
||||||
char *short_options, *soptr;
|
char *short_options, *soptr;
|
||||||
struct option *long_options, *loptr;
|
struct option *long_options, *loptr;
|
||||||
size_t optsize, i;
|
size_t optsize, i;
|
||||||
@ -247,7 +247,7 @@ void parceargs(int *argc, char ***argv, myoption *options){
|
|||||||
*/
|
*/
|
||||||
void showhelp(int oindex, myoption *options){
|
void showhelp(int oindex, myoption *options){
|
||||||
// ATTENTION: string `help` prints through macro PRNT(), by default it is gettext,
|
// ATTENTION: string `help` prints through macro PRNT(), by default it is gettext,
|
||||||
// but you can redefine it before `#include "parceargs.h"`
|
// but you can redefine it before `#include "parseargs.h"`
|
||||||
int max_opt_len = 0; // max len of options substring - for right indentation
|
int max_opt_len = 0; // max len of options substring - for right indentation
|
||||||
const int bufsz = 255;
|
const int bufsz = 255;
|
||||||
char buf[bufsz+1];
|
char buf[bufsz+1];
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* parceargs.h - headers for parcing command line arguments
|
* parseargs.h - headers for parcing command line arguments
|
||||||
*
|
*
|
||||||
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
|
||||||
*
|
*
|
||||||
@ -19,8 +19,8 @@
|
|||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef __PARCEARGS_H__
|
#ifndef __PARSEARGS_H__
|
||||||
#define __PARCEARGS_H__
|
#define __PARSEARGS_H__
|
||||||
|
|
||||||
#include <stdbool.h>// bool
|
#include <stdbool.h>// bool
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -48,7 +48,7 @@ typedef bool(*argfn)(void *arg, int N);
|
|||||||
* int iarg;
|
* int iarg;
|
||||||
* myoption opts[] = {
|
* myoption opts[] = {
|
||||||
* {"value", 1, NULL, 'v', arg_int, &iarg, "char val"}, ..., end_option};
|
* {"value", 1, NULL, 'v', arg_int, &iarg, "char val"}, ..., end_option};
|
||||||
* ..(parce args)..
|
* ..(parse args)..
|
||||||
* charg = (char) iarg;
|
* charg = (char) iarg;
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -58,7 +58,7 @@ typedef enum {
|
|||||||
arg_double, // double
|
arg_double, // double
|
||||||
arg_float, // float
|
arg_float, // float
|
||||||
arg_string, // char *
|
arg_string, // char *
|
||||||
arg_function // parce_args will run function `bool (*fn)(char *optarg, int N)`
|
arg_function // parse_args will run function `bool (*fn)(char *optarg, int N)`
|
||||||
} argtype;
|
} argtype;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -67,7 +67,7 @@ typedef enum {
|
|||||||
* conversion depends on .type
|
* conversion depends on .type
|
||||||
*
|
*
|
||||||
* ATTENTION: string `help` prints through macro PRNT(), bu default it is gettext,
|
* ATTENTION: string `help` prints through macro PRNT(), bu default it is gettext,
|
||||||
* but you can redefine it before `#include "parceargs.h"`
|
* but you can redefine it before `#include "parseargs.h"`
|
||||||
*
|
*
|
||||||
* if arg is string, then value wil be strdup'ed like that:
|
* if arg is string, then value wil be strdup'ed like that:
|
||||||
* char *str;
|
* char *str;
|
||||||
@ -99,8 +99,8 @@ typedef struct{
|
|||||||
extern const char *__progname;
|
extern const char *__progname;
|
||||||
|
|
||||||
void showhelp(int oindex, myoption *options);
|
void showhelp(int oindex, myoption *options);
|
||||||
void parceargs(int *argc, char ***argv, myoption *options);
|
void parseargs(int *argc, char ***argv, myoption *options);
|
||||||
void change_helpstring(char *s);
|
void change_helpstring(char *s);
|
||||||
bool myatod(void *num, const char *str, argtype t);
|
bool myatod(void *num, const char *str, argtype t);
|
||||||
|
|
||||||
#endif // __PARCEARGS_H__
|
#endif // __PARSEARGS_H__
|
||||||
@ -53,9 +53,9 @@ int main(){
|
|||||||
while(1){
|
while(1){
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
//check_and_parce_UART(USART1); // also check data in UART buffers
|
//check_and_parse_UART(USART1); // also check data in UART buffers
|
||||||
if(Timer - Old_timer > 999){ // one-second cycle
|
if(Timer - Old_timer > 999){ // one-second cycle
|
||||||
Old_timer += 1000;
|
Old_timer += 1000;
|
||||||
}else if(Timer < Old_timer){ // Timer overflow
|
}else if(Timer < Old_timer){ // Timer overflow
|
||||||
|
|||||||
@ -51,10 +51,10 @@ void help(){
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
@ -56,7 +56,7 @@ int main(){
|
|||||||
uint32_t L;
|
uint32_t L;
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
if(usbdatalen){ // there's something in USB buffer
|
if(usbdatalen){ // there's something in USB buffer
|
||||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||||
}
|
}
|
||||||
if(AWD_flag){
|
if(AWD_flag){
|
||||||
P("Int, value = ");
|
P("Int, value = ");
|
||||||
|
|||||||
@ -59,10 +59,10 @@ uint8_t show_int(int32_t v){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parce command buffer buf with length len
|
* parse command buffer buf with length len
|
||||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||||
*/
|
*/
|
||||||
int parce_incoming_buf(char *buf, int len){
|
int parse_incoming_buf(char *buf, int len){
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
//uint32_t utmp;
|
//uint32_t utmp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@ -44,6 +44,6 @@ void prnt(uint8_t *wrd);
|
|||||||
void print_int(int32_t N);
|
void print_int(int32_t N);
|
||||||
void print_hex(uint8_t *buff, uint8_t l);
|
void print_hex(uint8_t *buff, uint8_t l);
|
||||||
|
|
||||||
int parce_incoming_buf(char *buf, int len);
|
int parse_incoming_buf(char *buf, int len);
|
||||||
|
|
||||||
#endif // __USER_PROTO_H__
|
#endif // __USER_PROTO_H__
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user