#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include "board.h"
#include "ioutil.h"
#include "ow.h"
#include "hif.h"
#include "xmpl.h"
#define PROMPT() PRINT("\n\row>>> ")
#define LINE_SIZE (80)
#define MAX_ARGS (16)
char *argv[MAX_ARGS];
int argc;
bool process_input(int c);
void process_commands(char **argv, int argc);
int main(void)
{
const uint32_t br = HIF_DEFAULT_BAUDRATE;
int chr;
#if HIF_TYPE == HIF_AT90USB
do
{
}
while (EOF == inchar);
#endif
PRINTF(
"\n\r1-Wire Example : %s : %ld bit/s\n\r", BOARD_NAME, br);
PROMPT();
do
{
if (process_input(chr))
{
if (argc)
{
process_commands(argv, argc);
}
PROMPT();
}
}
while (1);
}
bool process_input(int c)
{
static char line[LINE_SIZE];
static int idx;
bool rv = false;
if (c != EOF)
{
if (c == '\n' || c == '\r')
{
line[idx] = 0;
idx = 0;
rv = true;
}
else if (idx < sizeof(line))
{
line[idx++] = c;
}
else
{
idx = 0;
}
}
return rv;
}
void process_commands(char **argv, int argc)
{
uint8_t wbuf[32], rbuf[32], i;
for (i = 1; i < argc; i++)
{
wbuf[i-1] = (uint8_t) strtol(argv[i], NULL, 16);
}
switch (argv[0][0])
{
case 'R':
break;
case 'r':
PRINTF(
"READ rlen=%d:", wbuf[0]);
for(i = 0; i < wbuf[0]; i++)
{
}
break;
case 'w':
for (i = 0; i < argc-1; i++)
{
}
break;
case 's':
PRINT(
"SEARCH:\nnb: a7 a6 a5 a4 a3 a2 a1 a0\n");
uint8_t first = 1;
uint8_t dev_present;
uint8_t devnb = 0;
do
{
first = 0;
" %02x %02x %02x %02x"\
" %02x %02x %02x %02x\n",
devnb++,
rbuf[7], rbuf[6], rbuf[5], rbuf[4],
rbuf[3], rbuf[2], rbuf[1], rbuf[0]);
{
PRINT(
"invalid CRC - exit search\n");
break;
}
}
while(dev_present);
break;
case 'h':
"r <n> : read <n> bytes\n"\
"w <a> <b> ... : write byte <a>, <b>, ...\n"\
"s : search devices\n"\
"h : show help\n"
);
default:
PRINTF(
"invalid command: \"%s\"\n", argv[0]);
break;
}
}