Browse Source

date

pull/1/head
Rafael Zurita 6 years ago
parent
commit
e0249e2a96
  1. 4
      device/nam/naminit.c
  2. 168
      lib/date.c
  3. 41
      main/main.c
  4. 54
      main/xsh_basic.c
  5. 2
      main/xsh_ps.c
  6. 2
      system/initialize.c
  7. 1
      www/build_web.sh

4
device/nam/naminit.c

@ -41,7 +41,7 @@ status naminit(void)
// RAFA
/* avr specific */
char name[10];
kprintf("devices:\n");
kprintf("naminit (devices):\n");
for (i=0; i<NDEVS ; i++) {
tptr = tmpstr;
@ -79,7 +79,7 @@ status naminit(void)
}
// RAFA
kprintf("%s\n",tmpstr);
kprintf(" %s\n",tmpstr);
retval = mount(tmpstr, NULLSTR, devptr->dvnum);
if (retval == SYSERR) {
// RAFA kprintf("namespace: cannot mount device %d\r\n",

168
lib/date.c

@ -0,0 +1,168 @@
#include <stdint.h>
typedef long int32;
typedef unsigned long uint32;
typedef long unsigned int size_t;
typedef uint32_t time_t;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#define TRUE 1
#define FALSE 0
struct tm avr_tm;
char days_per_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*
const char * strp_weekdays[] =
{ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"};
const char * strp_monthnames[] =
{ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"};
*/
#define SECONDS_PER_DAY (60*60*24)
unsigned long int seconds = 0;
unsigned int days = 0;
// unsigned long long int seconds = 0;
int date(const char *s) {
int m, d, y;
int hour, min, sec;
int i;
char two[3];
two[2] = 0;
/* month */
two[0] = *s; s++; two[1] = *s; s++;
m = atoi(two);
s++;
/* day */
two[0] = *s; s++; two[1] = *s; s++;
d = atoi(two);
s++;
/* year */
two[0] = *s; s++; two[1] = *s; s++;
// y = 2000 + atoi(two);
y = atoi(two);
/*
while (isspace((int)(*s)))
++s;
*/
s++;
/* hour */
two[0] = *s; s++; two[1] = *s; s++;
hour = atoi(two);
s++;
/* minutes */
two[0] = *s; s++; two[1] = *s; s++;
min = atoi(two);
s++;
/* seconds */
two[0] = *s; s++; two[1] = *s; s++;
sec = atoi(two);
for (i=2000; i<y; i++) {
if ( i % 4 == 0 && i % 100 != 0 || i % 400 == 0 )
days = days + 366;
//seconds = seconds + (366 * SECONDS_PER_DAY);
else
days = days + 365;
//seconds = seconds + (365 * SECONDS_PER_DAY);
}
for (i=1; i<m; i++) {
days = days + days_per_month[i-1];
//seconds = seconds + (days_per_month[i-1] * SECONDS_PER_DAY);
if ((i == 2) && ( y % 4 == 0 && y % 100 != 0 || y % 400 == 0 ))
days++;
//seconds = seconds + (SECONDS_PER_DAY);
}
days = days + d;
//seconds = seconds + (d * SECONDS_PER_DAY);
seconds = 0;
seconds = seconds + (hour * 3600) + (min * 60) + sec;
printf("h:%d\n", hour);
printf("m:%d\n", min);
printf("s:%d\n", sec);
printf("d:%d\n", d);
printf("m:%d\n", m);
printf("y:%d\n", y);
avr_tm.tm_sec = sec;
avr_tm.tm_min = min;
avr_tm.tm_hour = hour;
avr_tm.tm_mon = m - 1;
avr_tm.tm_mday = d;
avr_tm.tm_year = y + 100;
return 0;
}
const unsigned int dinamonth[13] = {0,0,0,31,30,31,30,31,31,30,31,30,31};
//const unsigned long secinamonth[13] = {0,0,0,31*86400,30*86400,31*86400,30*86400,31*86400,31*86400,30*86400,31*86400,30*86400,31*86400};
void seconds_to_date(int *y, int *m, int *d, int *h, int *min, int *s) // unsigned 32bit input
{
unsigned long int dd = days;
unsigned long int ss = seconds;
char temp = 0; // start at year 2000
while (dd >= 1460 && temp <100) { dd -= 1460; temp +=4;} // four year blocks until 2100
// while (sec >= 126230400 && temp <100) { sec -= 126230400; temp +=4;} // four year blocks until 2100
if (temp == 100){while (dd >= 366 && temp <104){ dd -= 366; temp +=1;}}//no leapyears
//if (temp == 100){while (sec >= 31536000 && temp <104){ sec -= 31536000; temp +=1;}}//no leapyears
while (dd >= 1460){ dd -= 1460; temp +=4;}// four year blocks again
//while (sec >= 126230400){ sec -= 126230400; temp +=4;}// four year blocks again
if (dd >= 366){ dd -= 366; temp +=1; // first year after a 4yr block is a leapyear
// if (sec >= 31622400){ sec -= 31622400; temp +=1; // first year after a 4yr block is a leapyear
while (dd >= 366){ dd -= 366; temp +=1;}// then it can only be two years left
// while (sec >= 31536000){ sec -= 31536000; temp +=1;}// then it can only be two years left
}
*y = temp; temp = 1; // let it go past 99 to max 136 for year 2136
if (dd >= 31){ // January
//if (sec >= 86400*31){ // January
dd -= 31; temp +=1;
int tempfeb = 28;
if (*y !=100 && !(*y & 3)) tempfeb = 29;// 2100 is no leap year
//if (rtc.year !=100 && !(rtc.year & 3)) tempfeb = 29;// 2100 is no leap year
if (dd >= tempfeb){
//if (sec >= tempfeb){
dd -= tempfeb; temp +=1; // do the other months now
// sec -= tempfeb; temp +=1; // do the other months now
while (dd >= dinamonth[temp]){ dd -= dinamonth[temp]; temp +=1;}
//while (sec >= secinamonth[temp]){ sec -= secinamonth[temp]; temp +=1;}
}
}
*m = temp; temp = 1;
while (dd >= 1){ dd -= 1; temp +=1;} // days
*d = temp; temp = 0;
while (ss >= 3600){ ss -= 3600; temp +=1;} // hour
*h = temp; temp = 0;
while (ss >= 60){ ss -= 60; temp +=1;} // minute
*min = temp;
*s = ss; // seconds
}

41
main/main.c

@ -6,6 +6,15 @@
#include <xinu.h>
#include "shprototypes.h"
#include <time.h>
extern int date (char *s);
extern void seconds_to_date(int *y, int *m, int *d, int *h, int *min, int *s);
extern seconds;
extern int days;
extern struct tm avr_tm;
//extern long long int seconds;
void xsh_help(void);
shellcmd xsh_kill(int nargs, char *args[]);
@ -73,7 +82,7 @@ const cmdent_t __flash cmdtab[] = {
const __flash int cmdtab_stk[] = {
256, /* memdump */
500, /* editor */
500, /* basic */
400, /* basic */
128, /* help */
128, /* sleep */
128, /* forever */
@ -186,8 +195,9 @@ process main(void)
change_proc_name("shell");
for (i=0;i<NDEVS;i++)
printf("%S\n", devtab[i].dvname);
// for (i=0;i<NDEVS;i++)
// printf("%S\n", devtab[i].dvname);
/* Print shell banner and startup message */
/*
@ -196,6 +206,31 @@ process main(void)
SHELL_BAN5,SHELL_BAN6,SHELL_BAN7,SHELL_BAN8,SHELL_BAN9,SHELL_BAN10);
fprintf(dev, "%s\n\n", SHELL_STRTMSG);
*/
unsigned int ss = 0;
int y, m, d, h, min, s;
ss = date("06/30/20 13:21:30");
printf("dias:%i\n", days);
seconds_to_date(&y, &m, &d, &h, &min, &s);
printf("y:%i\n", y);
printf("m:%i\n", m);
printf("d:%i\n", d);
printf("h:%i\n", h);
printf("m:%i\n", min);
printf("s:%i\n", s);
char avr_date[80];
asctime_r(&avr_tm, avr_date);
printf("f:%s\n", avr_date);
/*
unsigned char destination[8];
for(int i=0; i<8; ++i) {
destination[i] = s>>((7-i)*8);
printf ("n:%X\n", destination[i]);
};
*/
int len_p;

54
main/xsh_basic.c

@ -74,7 +74,7 @@ shellcmd xsh_basic(int nargs, char *args[])
* *
******************************************************************
* Copyright (C) 1984 by Gordon Brandly. This program may be *
* freely distributed for personal use only. All commercial *
* freely distributed for personal use only.function avr all arduino pins in c language All commercial *
* rights are reserved. *
******************************************************************
*/
@ -279,11 +279,6 @@ shellcmd xsh_basic(int nargs, char *args[])
////////////////////
// some settings based things
boolean inhibitOutput = false;
static boolean runAfterLoad = false;
static boolean triggerRun = false;
// these will select, at runtime, where IO happens through for load/save
enum {
@ -291,8 +286,8 @@ enum {
kStreamEEProm,
kStreamFile
};
static unsigned char inStream = kStreamSerial;
static unsigned char outStream = kStreamSerial;
// static unsigned char inStream = kStreamSerial;
// static unsigned char outStream = kStreamSerial;
////////////////////////////////////////////////////////////////////////////////
@ -316,10 +311,9 @@ typedef short unsigned LINENUM;
// RAFA
// extern unsigned char program[NLINES*LINE_LEN];
static const char * sentinel = "HELLO";
// static const char * sentinel = "HELLO";
static unsigned char *txtpos,*list_line, *tmptxtpos;
static unsigned char expression_error;
static unsigned char *tempsp;
/***********************************************************/
// Keyword table and constants - the last character has 0x80 added to it
@ -979,6 +973,18 @@ void loop()
// unsigned char program[NLINES*LINE_LEN];
unsigned char program[kRamSize];
// some settings based things
boolean inhibitOutput = false;
boolean runAfterLoad = false;
boolean triggerRun = false;
unsigned char *tempsp;
program_start = program;
program_end = program_start;
sp = program+sizeof(program); // Needed for printnum
@ -1711,34 +1717,6 @@ static int isValidFnChar( char c )
return 0;
}
unsigned char * filenameWord(void)
{
// SDL - I wasn't sure if this functionality existed above, so I figured i'd put it here
unsigned char * ret = txtpos;
expression_error = 0;
// make sure there are no quotes or spaces, search for valid characters
//while(*txtpos == SPACE || *txtpos == TAB || *txtpos == SQUOTE || *txtpos == DQUOTE ) txtpos++;
while( !isValidFnChar( *txtpos )) txtpos++;
ret = txtpos;
if( *ret == '\0' ) {
expression_error = 1;
return ret;
}
// now, find the next nonfnchar
txtpos++;
while( isValidFnChar( *txtpos )) txtpos++;
if( txtpos != ret ) *txtpos = '\0';
// set the error code if we've got no string
if( *ret == '\0' ) {
expression_error = 1;
}
return ret;
}
/***************************************************************************/
static void line_terminator(void)

2
main/xsh_ps.c

@ -3,7 +3,7 @@
#include <xinu.h>
#include <stdio.h>
const __flash char ps_msg0[] = "\nTable of current process\n";
const __flash char ps_msg0[] = "\ntable of current processes\n";
const __flash char ps_msg1[] = "\nname\tid\tparent\tprio\tstate\tstklen\tsem waits\n--\n";
/*------------------------------------------------------------------------

2
system/initialize.c

@ -115,7 +115,7 @@ void nulluser()
memptr = memptr->mnext) {
free_mem += memptr->mlength;
}
kprintf("\nFreeMEM:%d\n", free_mem);
kprintf("\nFreeMEM:%d (bytes)\n\n", free_mem);
/*
long * b = (long *) memlist.mnext;

1
www/build_web.sh

@ -1,4 +1,5 @@
markdown_py -f index.html $1
cat w1.html index.html w2.html > /tmp/deleteme.html
rm index.html
mv /tmp/deleteme.html ../index.html

Loading…
Cancel
Save