From 7a304a0523e3feb712ee088232605287ac09cffb Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Sun, 28 Sep 2014 23:43:28 +0200 Subject: [PATCH 1/4] Reduce Bootloader Size changing few uint16 variables to uint8 --- Bootloader/MyOtaBootloader.c | 4 +- Bootloader/MyOtaBootloader.hex | 404 ++++++++++++++++----------------- Bootloader/MyOtaBootloaderHW.h | 5 +- 3 files changed, 205 insertions(+), 208 deletions(-) diff --git a/Bootloader/MyOtaBootloader.c b/Bootloader/MyOtaBootloader.c index cd58712..fe4f24f 100644 --- a/Bootloader/MyOtaBootloader.c +++ b/Bootloader/MyOtaBootloader.c @@ -56,9 +56,9 @@ static uint8_t sendAndWait(uint8_t reqType, uint8_t resType) { msg.type = reqType; for (uint8_t i = 0; i < 10; i++) { sendWrite(msg); - for (uint16_t j = 0; j < 20; j++) { + for (uint8_t j = 0; j < 20; j++) { wdt_reset(); - for (uint16_t j = 0; j < 100; j++) { + for (uint8_t j = 0; j < 100; j++) { wdt_reset(); uint8_t pipe; boolean avail = available(&pipe); diff --git a/Bootloader/MyOtaBootloader.hex b/Bootloader/MyOtaBootloader.hex index 6fd8c58..538354d 100644 --- a/Bootloader/MyOtaBootloader.hex +++ b/Bootloader/MyOtaBootloader.hex @@ -1,4 +1,4 @@ -:1070000011E0A0E0B1E0E0E4FDE702C005900D92E0 +:1070000011E0A0E0B1E0E8EFFCE702C005900D92CE :10701000A030B107D9F711E0A0E0B1E001C01D92A6 :10702000A83DB107E1F711248091610090E08F70D5 :107030009070909301018093000182E090E020E83D @@ -7,208 +7,204 @@ :107060000FBE20936000A8951092CF011092D0011E :107070001092D1011092D2011092D3011092D4013A :107080001092D5011092D60184B18E6284B92498F1 -:1070900085B1857D85B92A9A8AE090E0B3D184E0F4 -:1070A0006FE520D281E06BE31DD285E06CE41AD25B -:1070B00086E0E5D1682F607D676286E013D280E0CC -:1070C000DED1682F6C6080E00DD287E060E70AD2E5 -:1070D0002A9881E090E096D180E5A6D183E7A4D1FB -:1070E0002A9A81E090E08ED18DE1C9D1682F666047 -:1070F0008DE1F8D18CE1C3D1682F6F638CE1F2D1BF -:1071000082EEADD181EEABD104D280E0B8D1682F50 -:107110006E7F80E0E7D182E00FEF1CEF21EE38EACE -:1071200048EA50E060E070E002D2A89582E091E089 -:1071300060E070E043E050E02DEE39E38AD5A89599 -:107140008091020180930E0180930D014FD22FEFA9 -:10715000209313018091110192E0909310012093EC -:107160000401887083608093110120930F0187E0F0 -:1071700068E04AD3882309F42AD310920F01809142 -:1071800002018F3F09F038C081E00FEF1CEF21EEC4 -:1071900038EA48EA50E060E070E0C9D183E064E09A -:1071A00033D3882309F407D38091320182958695E1 -:1071B0008770813019F48091350105C0882329F446 -:1071C00085E391E028D580930201809102018F3FF1 -:1071D00009F4F1D280910201F999FECF1FBA12BCD5 -:1071E00011BC80BD0FB6F894FA9AF99A0FBE80933D -:1071F0000E0180930D01FAD185E091E06BE171E021 -:1072000048E050E02DEE39E324D5909111019871BA -:10721000809110018770806280931001946C90932C -:1072200011018091050190910601909315018093C1 -:1072300014018091070190910801909317018093A8 -:10724000160180E061E0E0D2882309F4C0D22091E9 -:10725000370130913801809107019091080128177A -:107260003907C9F42091390130913A01809109011F -:1072700090910A012817390771F420913B01309150 -:107280003C0180910B0190910C012817390719F4EA -:107290005DD281119CD240913501509136015093BD -:1072A0000601409305012091370130913801309358 -:1072B0000801209307018091390190913A01909340 -:1072C0000A018093090180913B0190913C019093C8 -:1072D0000C0180930B01F4E1EF2EF1E0FF2E809181 -:1072E00010018770806380931001509315014093C3 -:1072F00014013093170120931601C0E0D0E000E99B -:107300001FEFBB24B394E5E0CE2E71E1D72E4DC024 -:10731000F701D583C48382E063E076D2882309F441 -:107320004AD2902F90599F77E92FF0E0E15BFE4F12 -:10733000ABE3B1E080E10D9001928150E1F790372D -:1073400009F030C03FB7F894F999FECF83E0F80117 -:1073500080935700E89507B600FCFDCFA801AFE485 -:10736000B1E02C9111968C91119790E0982F88277D -:10737000820F911D1296FA010C01B0925700E89508 -:1073800011244E5F5F4FF1E0AF3CBF0751F7F801AA -:10739000C0925700E89507B600FCFDCFD092570089 -:1073A000E8953FBF2196005F1F4F809109019091A2 -:1073B0000A01C817D90708F4ABCFA895C7D188230D -:1073C00049F08BE191E065E071E048E050E024EFA6 -:1073D00039E35BD4F0D180E090E0F999FECF92BD23 -:1073E00081BDF89A80B50895F999FECF1FBA92BD74 -:1073F00081BD60BD0FB6F894FA9AF99A0FBE089550 -:107400000000089540E050E00BC020E030E00000B4 -:107410002F5F3F4F61E0243F3607C9F74F5F5F4F53 -:107420004817590790F308950F931F93182F00E002 -:10743000E7DF17FD02C02B9801C02B9AE1DF2D9AE0 -:1074400083B1110F82958170182BDADF2D98D8DF68 -:107450000F5F083069F7812F1F910F9108951F93D7 -:10746000182F2A9881E090E0CDDF812FDDDF182FE3 -:107470002A9A81E090E0C6DF812F1F9108951F9323 -:10748000182F2A9881E090E0BDDF812F8F71CCDF2B -:107490008FEFCADF182F2A9A81E090E0B3DF812FA7 -:1074A0001F9108950F931F93CF93DF93182FEB0134 -:1074B000042F2A9881E090E0A5DF1F71812F806260 -:1074C000B3DF182F03C08991AFDF01500023D9F734 -:1074D0002A9A81E090E096DF812FDF91CF911F9172 -:1074E0000F9108950F931F93182F062F2A9881E06C -:1074F00090E088DF1F71812F806296DF182F802F28 -:1075000093DF2A9A81E090E07DDF812F1F910F9118 -:10751000089580E0B4DF81FD09C080E0B0DF682F0E -:10752000626080E0DFDF85E090E06CDF08957F92AD -:107530008F929F92AF92BF92CF92DF92EF92FF9283 -:107540000F931F93DF93CF93CDB7DEB728970FB676 -:10755000F894DEBF0FBECDBF782E480159016A01F5 -:107560007B01882381F40093CF019092D001209376 -:10757000D101B092D2014093D301D092D401609353 -:10758000D501F092D60189829A82AB82BC82CD82EB -:10759000DE82EF82F88681E0871538F0872D865FDE -:1075A000BE016F5F7F4F45E07DDF82E068DF21E055 -:1075B00030E002C0220F331F7A94E2F7682F622B6B -:1075C00082E090DF28960FB6F894DEBF0FBECDBFE5 -:1075D000CF91DF911F910F91FF90EF90DF90CF90AF -:1075E000BF90AF909F908F907F9008957F928F92E1 -:1075F0009F92AF92BF92CF92DF92EF92FF920F9342 -:107600001F93DF93CF93CDB7DEB728970FB6F894CB -:10761000DEBF0FBECDBF8F3F09F483C0082F10E03F -:1076200020E030E040E050E060E070E089831A83C1 -:107630002B833C834D835E836F83788788243CEF64 -:10764000932E21EEA22E98EAB92E88EAC82EDD24C8 -:10765000EE24FF24080D81E09981091708F080E0ED -:10766000192D91E0AA819A1608F090E0E82FE10F19 -:1076700081E0E11708F080E0982B1E2F2A2D772457 -:107680007394BB81AB1608F07724920F81E09217B8 -:1076900008F080E0782A292F3B2D91E0EC81BE167E -:1076A00008F090E0E72DE30F81E0E31708F080E0B9 -:1076B000982B3E2F4C2D77247394FD81CF1608F024 -:1076C0007724940F81E0941708F080E0782A492FFE -:1076D0005D2D91E08E81D81608F090E0E72DE50F42 -:1076E00081E0E51708F080E0982B5E2F6E2D77245F -:1076F0007394AF81EA1608F07724960F81E096170D -:1077000008F080E0782A692F7F0C772D59016A01F3 -:10771000E92E80E00CDF81E09501A6016E2D772D2A -:1077200006DF28960FB6F894DEBF0FBECDBFCF910F -:10773000DF911F910F91FF90EF90DF90CF90BF905E -:10774000AF909F908F907F90089518954091090178 -:1077500050910A0164E0440F551F6A95E1F7E0E09B -:10776000F0E02FEF3FEF19C084912827822F8295F8 -:107770008227082E869586958025082E8695802559 -:107780008770022E232F869507948795302D282702 -:1077900006948795302528273196E417F50720F3BE -:1077A00040E080910B0190910C012817390709F4F2 -:1077B00041E0842F089528E088E190E00FB6F89426 -:1077C000A895809360000FBE20936000FFCFBEDFBE -:1077D0008823C1F088E10FB6F8948093600010927E -:1077E00060000FBE809100019091010120E80FB66A -:1077F000F89420936100809361000FBEE0E0F0E018 -:1078000009950895D8DF08952F923F924F925F9285 -:107810006F927F928F929F92AF92BF92CF92DF92A0 -:10782000EF92FF920F931F93DF93CF93CDB7DEB705 -:10783000E3970FB6F894DEBF0FBECDBF6BA7809362 -:1078400012016624B9E02B2E312C2C0E3D1E2E0188 -:107850000894411C511CD101EDE0F1E081E201905E -:107860000D928150E1F7109103017C842B852AA7AA -:1078700050DE299881E090E0C5DD81EEF0DD82EEFA -:10788000EEDD80E0FCDD682F6E7F80E02BDE30E0F7 -:1078900040E050E060E070E080E090E01CA73DA791 -:1078A0004EA75FA768AB79AB8AAB9BAB8824ACEFE4 -:1078B0009A2EF1EEAF2EE8EABE2E78EAC72EDD242E -:1078C000EE24FF24012F080D81E0011708F080E06D -:1078D000192D91E0EDA59E1608F090E0E82FE10F3C -:1078E00081E0E11708F080E0982B1E2F2A2DE1E0BF -:1078F000FEA5AF1608F0E0E0920F81E0921708F0C5 -:1079000080E0E82B292F3B2D91E08FA5B81608F0D9 -:1079100090E0E30F81E0E31708F080E0982B3E2F22 -:107920004C2DE1E0F8A9CF1608F0E0E0940F81E0DB -:10793000941708F080E0E82B492F5D2D91E089A98C -:10794000D81608F090E0E50F81E0E51708F080E038 -:10795000982B5E2F6E2D81E0EAA9EE1608F080E0EC -:10796000E92FE60F91E0E61708F090E0892B8F0DE4 -:1079700009831A832B833C834D835E83EF8388873F -:107980008AE0B20145E08EDD80E1B20145E08ADDAA -:10799000FAA5FF3F11F010EA01C010EB769476943F -:1079A000769427E0720E2A9881E090E02BDD812FFB -:1079B0003BDD81017101E70CF11C04C0F8018191EC -:1079C0008F0132DD0E151F05C9F72A9A81E090E07C -:1079D00019DD299A81E090E015DD299881E090E099 -:1079E00011DD8FEF3CDD8073E1F387E060E77ADD46 -:1079F00084FF02C081EE33DD8CDD80E040DD682F46 -:107A0000616080E06FDD87E060E76CDD0091CF01B1 -:107A10001091D0012091D1013091D2014091D30138 -:107A20005091D4016091D5017091D601802F812BA6 -:107A3000822B832B842B852B862B872B61F009834C -:107A40001A832B833C834D835E836F8378878AE020 -:107A5000B20145E027DD82EE02DD81EE00DD299AEC -:107A600081E090E0CFDCAA24BB24A895CC24DD24BF -:107A7000A89587E104DD80FD9CC08FEFF0DCE82E47 -:107A8000E694F7E0EF22EF1609F493C02A9881E01C -:107A900090E0B8DC80E6C8DC8FEFC6DCF82E2A9ACE -:107AA00081E090E0AFDC20E22F1518F482EED7DC05 -:107AB000FF242A9881E090E0A5DC81E6B5DC0EE2A7 -:107AC00011E006C08FEFB0DCF80181938F01FA94CA -:107AD000FF20C1F72A9A81E090E094DC87E060E71C -:107AE00001DD2A9881E090E08DDC8E2D886A9CDC97 -:107AF0008E2D9ADC2A9A81E090E084DC809131011D -:107B00008770823009F058C0909130018091020155 -:107B1000981709F04EC080913201682F70E0CB01B8 -:107B200087709070039709F034C0809133018830DA -:107B300009F02FC040913501242F332727FD3095C0 -:107B40008091040190E001972817390714F5242F3C -:107B50002F5F2093040140912F0140930301F99975 -:107B6000FECF1FBA81E090E092BD81BD40BD0FB64F -:107B7000F894FA9AF99A0FBEF999FECF1FBA42E02B -:107B800050E052BD41BD20BD0FB6F894FA9AF99A63 -:107B90000FBE8091110190E0862797278770907023 -:107BA000892B39F4809133015BA5851711F481E0AD -:107BB00019C081E090E026DC0894C11CD11C64E669 -:107BC000C616D10409F054CF0894A11CB11C74E16D -:107BD000A716B10409F049CF63948AE0681609F04A -:107BE0003ACE80E0E3960FB6F894DEBF0FBECDBF6D -:107BF000CF91DF911F910F91FF90EF90DF90CF9089 -:107C0000BF90AF909F908F907F906F905F904F90BC -:107C10003F902F900895FC0188279927E89421919F -:107C20002032E9F3293010F02E30C8F32B3241F026 -:107C30002D3239F4689404C00E94613E820F911D78 -:107C4000219120532A30C0F31EF4909581959F4FC7 -:107C50000895A0E0B0E0EFE2FEE30C94733E7C01F7 -:107C6000EB018A01690109C0CE012196F60109954F -:107C7000F70181937F010150104001151105A1F713 -:107C8000CDB7DEB7E8E00C948F3EA0E0B0E0EBE4C7 -:107C9000FEE30C94733EEC017B018A01690109C08B -:107CA000CE012196F70161917F01F60109950150FE -:107CB000104001151105A1F7CDB7DEB7E8E00C942F -:107CC0008F3E7AE0979F902D879F802D910D1124F4 -:107CD00008952F923F924F925F926F927F928F9270 -:107CE0009F92AF92BF92CF92DF92EF92FF920F934B -:107CF0001F93CF93DF93CDB7DEB7CA1BDB0B0FB655 -:107D0000F894DEBF0FBECDBF09942A883988488811 -:107D10005F846E847D848C849B84AA84B984C884A7 -:107D2000DF80EE80FD800C811B81AA81B981CE0F9E -:107D3000D11D0FB6F894DEBF0FBECDBFED01089583 +:1070900085B1857D85B92A9A8AE0B1D184E06FE512 +:1070A00015D281E06BE312D285E06CE40FD286E06A +:1070B000DED1682F607D676286E008D280E0D7D19C +:1070C000682F6C6080E002D287E060E7FFD12A98E9 +:1070D00081E095D180E5A2D183E7A0D12A9A81E011 +:1070E0008ED18DE1C4D1682F66608DE1EFD18CE146 +:1070F000BED1682F6F638CE1E9D182EEAAD181EE17 +:10710000A8D1F9D180E0B3D1682F6E7F80E0DED1C5 +:1071100082E00FEF1CEF21EE38EA48EA50E060E031 +:1071200070E0F6D1A89582E091E060E070E043E085 +:1071300050E02AEE39E369D5A89580910201809349 +:107140000E0180930D0143D22FEF20931301809104 +:10715000110192E0909310012093040188708360E4 +:107160008093110120930F0187E068E03ED38823CC +:1071700009F41ED310920F01809102018F3F09F094 +:1071800038C081E00FEF1CEF21EE38EA48EA50E00A +:1071900060E070E0BDD183E064E027D3882309F488 +:1071A000FBD280913201829586958770813019F4E7 +:1071B0008091350105C0882329F485E391E007D546 +:1071C00080930201809102018F3F09F4E5D2809102 +:1071D0000201F999FECF1FBA12BC11BC80BD0FB6D7 +:1071E000F894FA9AF99A0FBE80930E0180930D01DC +:1071F000EED185E091E06BE171E048E050E02AEEED +:1072000039E303D590911101987180911001877035 +:10721000806280931001946C90931101809105011C +:1072200090910601909315018093140180910701BC +:1072300090910801909317018093160180E061E01E +:10724000D4D2882309F4B4D2209137013091380187 +:10725000809107019091080128173907C9F42091FE +:10726000390130913A018091090190910A01281762 +:10727000390771F420913B0130913C0180910B0161 +:1072800090910C012817390719F451D2811190D22D +:10729000409135015091360150930601409305010C +:1072A0002091370130913801309308012093070174 +:1072B0008091390190913A0190930A0180930901DC +:1072C00080913B0190913C0190930C0180930B01C4 +:1072D000F4E1EF2EF1E0FF2E8091100187708063C2 +:1072E00080931001509315014093140130931701BE +:1072F00020931601C0E0D0E000E91FEFBB24B39457 +:10730000E5E0CE2E71E1D72E4DC0F701D583C483C1 +:1073100082E063E06AD2882309F43ED2902F90592C +:107320009F77E92FF0E0E15BFE4FABE3B1E080E156 +:107330000D9001928150E1F7903709F030C03FB7CE +:10734000F894F999FECF83E0F80180935700E8950F +:1073500007B600FCFDCFA801AFE4B1E02C91119677 +:107360008C91119790E0982F8827820F911D12968B +:10737000FA010C01B0925700E89511244E5F5F4F5F +:10738000F1E0AF3CBF0751F7F801C0925700E89514 +:1073900007B600FCFDCFD0925700E8953FBF21967D +:1073A000005F1F4F8091090190910A01C817D9070A +:1073B00008F4ABCFA895BBD1882349F08BE191E0CD +:1073C00065E071E048E050E021EF39E33AD4E4D1E0 +:1073D00080E090E0F999FECF92BD81BDF89A80B52A +:1073E0000895F999FECF1FBA92BD81BD60BD0FB659 +:1073F000F894FA9AF99A0FBE08950000089590E063 +:107400000AC020E030E000002F5F3F4F41E0243F02 +:107410003407C9F79F5F9817A0F308950F931F9340 +:10742000182F00E0EADF17FD02C02B9801C02B9A4D +:10743000E4DF2D9A83B1110F82958170182BDDDF67 +:107440002D98DBDF0F5F083069F7812F1F910F91B7 +:1074500008951F93182F2A9881E0D1DF812FDEDF56 +:10746000182F2A9A81E0CBDF812F1F9108951F9357 +:10747000182F2A9881E0C3DF812F8F71CFDF8FEF24 +:10748000CDDF182F2A9A81E0BADF812F1F9108954E +:107490000F931F93CF93DF93182FEB01042F2A989C +:1074A00081E0ADDF1F71812F8062B8DF182F03C02C +:1074B0008991B4DF01500023D9F72A9A81E09FDF38 +:1074C000812FDF91CF911F910F9108950F931F93FB +:1074D000182F062F2A9881E092DF1F71812F80627A +:1074E0009DDF182F802F9ADF2A9A81E088DF812F75 +:1074F0001F910F91089580E0BADF81FD08C080E000 +:10750000B6DF682F626080E0E1DF85E078DF089514 +:107510007F928F929F92AF92BF92CF92DF92EF9223 +:10752000FF920F931F93DF93CF93CDB7DEB72897CA +:107530000FB6F894DEBF0FBECDBF782E48015901BB +:107540006A017B01882381F40093CF019092D001DE +:107550002093D101B092D2014093D301D092D401B3 +:107560006093D501F092D60189829A82AB82BC8267 +:10757000CD82DE82EF82F88681E0871538F0872D94 +:10758000865FBE016F5F7F4F45E082DF82E06FDF85 +:1075900021E030E002C0220F331F7A94E2F7682F17 +:1075A000622B82E093DF28960FB6F894DEBF0FBE01 +:1075B000CDBFCF91DF911F910F91FF90EF90DF90A2 +:1075C000CF90BF90AF909F908F907F9008957F92C3 +:1075D0008F929F92AF92BF92CF92DF92EF92FF92E3 +:1075E0000F931F93DF93CF93CDB7DEB728970FB6D6 +:1075F000F894DEBF0FBECDBF8F3F09F483C0082FC4 +:1076000010E020E030E040E050E060E070E089838E +:107610001A832B833C834D835E836F837887882412 +:107620003CEF932E21EEA22E98EAB92E88EAC82EBE +:10763000DD24EE24FF24080D81E09981091708F06C +:1076400080E0192D91E0AA819A1608F090E0E82FC9 +:10765000E10F81E0E11708F080E0982B1E2F2A2D22 +:1076600077247394BB81AB1608F07724920F81E0E6 +:10767000921708F080E0782A292F3B2D91E0EC81C9 +:10768000BE1608F090E0E72DE30F81E0E31708F065 +:1076900080E0982B3E2F4C2D77247394FD81CF16DC +:1076A00008F07724940F81E0941708F080E0782A9E +:1076B000492F5D2D91E08E81D81608F090E0E72DDE +:1076C000E50F81E0E51708F080E0982B5E2F6E2D26 +:1076D00077247394AF81EA1608F07724960F81E03F +:1076E000961708F080E0782A692F7F0C772D5901D2 +:1076F0006A01E92E80E00CDF81E09501A6016E2D84 +:10770000772D06DF28960FB6F894DEBF0FBECDBFEB +:10771000CF91DF911F910F91FF90EF90DF90CF906D +:10772000BF90AF909F908F907F9008951895409153 +:10773000090150910A0164E0440F551F6A95E1F771 +:10774000E0E0F0E02FEF3FEF19C084912827822F6F +:1077500082958227082E869586958025082E869507 +:1077600080258770022E232F869507948795302DCC +:10777000282706948795302528273196E417F507A2 +:1077800020F340E080910B0190910C0128173907FC +:1077900009F441E0842F089528E088E190E00FB6D5 +:1077A000F894A895809360000FBE20936000FFCFEF +:1077B000BEDF8823C1F088E10FB6F89480936000A3 +:1077C000109260000FBE809100019091010120E8AD +:1077D0000FB6F89420936100809361000FBEE0E043 +:1077E000F0E009950895D8DF08952F923F924F92C7 +:1077F0005F926F927F928F929F92AF92BF92CF9241 +:10780000DF92EF92FF920F931F93DF93CF93CDB749 +:10781000DEB7E3970FB6F894DEBF0FBECDBF6BA700 +:10782000809312016624B9E02B2E312C2C0E3D1EC4 +:107830002E010894411C511CD101EDE0F1E081E2E0 +:1078400001900D928150E1F7109103017C842B850A +:107850002AA751DE299881E0D2DD81EEFADD82EEA1 +:10786000F8DD80E004DE682F6E7F80E02FDE30E000 +:1078700040E050E060E070E080E090E01CA73DA7B1 +:107880004EA75FA768AB79AB8AAB9BAB8824ACEF04 +:107890009A2EF1EEAF2EE8EABE2E78EAC72EDD244E +:1078A000EE24FF24012F080D81E0011708F080E08D +:1078B000192D91E0EDA59E1608F090E0E82FE10F5C +:1078C00081E0E11708F080E0982B1E2F2A2DE1E0DF +:1078D000FEA5AF1608F0E0E0920F81E0921708F0E5 +:1078E00080E0E82B292F3B2D91E08FA5B81608F0FA +:1078F00090E0E30F81E0E31708F080E0982B3E2F43 +:107900004C2DE1E0F8A9CF1608F0E0E0940F81E0FB +:10791000941708F080E0E82B492F5D2D91E089A9AC +:10792000D81608F090E0E50F81E0E51708F080E058 +:10793000982B5E2F6E2D81E0EAA9EE1608F080E00C +:10794000E92FE60F91E0E61708F090E0892B8F0D04 +:1079500009831A832B833C834D835E83EF8388875F +:107960008AE0B20145E094DD80E1B20145E090DDBE +:10797000FAA5FF3F11F010EA01C010EB769476945F +:10798000769427E0720E2A9881E039DD812F46DD5A +:1079900081017101E70CF11C04C0F80181918F0194 +:1079A0003DDD0E151F05C9F72A9A81E028DD299AC9 +:1079B00081E025DD299881E022DD8FEF4ADD8073AB +:1079C000E1F387E060E782DD84FF02C081EE41DD04 +:1079D00092DD80E04CDD682F616080E077DD87E03C +:1079E00060E774DD0091CF011091D0012091D101A9 +:1079F0003091D2014091D3015091D4016091D501D1 +:107A00007091D601802F812B822B832B842B852B89 +:107A1000862B872B61F009831A832B833C834D834C +:107A20005E836F8378878AE0B20145E031DD82EEC4 +:107A300010DD81EE0EDD299A81E0E1DCCC24A895F1 +:107A4000DD24A89587E113DD80FD96C08FEF01DD71 +:107A5000E82EE694F7E0EF22EF1609F48DC02A989D +:107A600081E0CDDC80E6DADC8FEFD8DCF82E2A9AD4 +:107A700081E0C5DC20E22F1518F482EEEADCFF2459 +:107A80002A9881E0BCDC81E6C9DC0EE211E006C088 +:107A90008FEFC4DCF80181938F01FA94FF20C1F7C6 +:107AA0002A9A81E0ACDC87E060E710DD2A9881E06B +:107AB000A6DC8E2D886AB2DC8E2DB0DC2A9A81E09D +:107AC0009EDC809131018770823009F057C090911F +:107AD000300180910201981709F04EC08091320167 +:107AE000682F70E0CB0187709070039709F034C065 +:107AF00080913301883009F02FC040913501242F47 +:107B0000332727FD30958091040190E001972817D5 +:107B1000390714F5242F2F5F2093040180912F0142 +:107B200080930301F999FECF1FBA41E050E052BDA6 +:107B300041BD80BD0FB6F894FA9AF99A0FBEF99933 +:107B4000FECF1FBA82E090E092BD81BD20BD0FB68E +:107B5000F894FA9AF99A0FBE8091110190E0862765 +:107B6000972787709070892B39F4809133019BA5FA +:107B7000891711F481E012C081E041DCD394E4E67E +:107B8000DE1609F05ECFC394F4E1CF1609F057CFAB +:107B900063942AE0621609F04FCE80E0E3960FB6B8 +:107BA000F894DEBF0FBECDBFCF91DF911F910F9133 +:107BB000FF90EF90DF90CF90BF90AF909F908F900D +:107BC0007F906F905F904F903F902F900895FC01B1 +:107BD00088279927E89421912032E9F3293010F081 +:107BE0002E30C8F32B3241F02D3239F4689404C0A2 +:107BF0000E943D3E820F911D219120532A30C0F3F7 +:107C00001EF4909581959F4F0895A0E0B0E0EBE0C1 +:107C1000FEE30C944F3E7C01EB018A01690109C02F +:107C2000CE012196F6010995F70181937F0101505C +:107C3000104001151105A1F7CDB7DEB7E8E00C94AF +:107C40006B3EA0E0B0E0E7E2FEE30C944F3EEC01B7 +:107C50007B018A01690109C0CE012196F70161917A +:107C60007F01F60109950150104001151105A1F79A +:107C7000CDB7DEB7E8E00C946B3E7AE0979F902D8D +:107C8000879F802D910D112408952F923F924F923E +:107C90005F926F927F928F929F92AF92BF92CF929C +:107CA000DF92EF92FF920F931F93CF93DF93CDB7A5 +:107CB000DEB7CA1BDB0B0FB6F894DEBF0FBECDBF1D +:107CC00009942A88398848885F846E847D848C84EE +:107CD0009B84AA84B984C884DF80EE80FD800C81F7 +:107CE0001B81AA81B981CE0FD11D0FB6F894DEBFDA +:087CF0000FBECDBFED010895A8 :040000030000700089 :00000001FF diff --git a/Bootloader/MyOtaBootloaderHW.h b/Bootloader/MyOtaBootloaderHW.h index 2eec57b..02740a6 100644 --- a/Bootloader/MyOtaBootloaderHW.h +++ b/Bootloader/MyOtaBootloaderHW.h @@ -32,8 +32,9 @@ static void delayu() { asm("nop"); } -static void delaym(uint16_t t) { - uint16_t d, a; +static void delaym(uint8_t t) { + uint8_t d; + uint16_t a; for (d = 0; d < t; d++) for (a = 0; a < DELAY_M; a++) asm("nop"); From c3dbcd1feadc4d5c32ad1a040b3de69f1bfcac47 Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Sun, 28 Sep 2014 23:47:22 +0200 Subject: [PATCH 2/4] Accept Time Broadcasts NodeJsController sending Time broadcasts every few minutes. Sensor accepting not just Time messages addressed to the specific sensor. --- NodeJsController/NodeJsController.js | 3 +++ libraries/MySensors/MySensor.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NodeJsController/NodeJsController.js b/NodeJsController/NodeJsController.js index 8bb67da..2c40fb4 100644 --- a/NodeJsController/NodeJsController.js +++ b/NodeJsController/NodeJsController.js @@ -706,5 +706,8 @@ dbc.connect('mongodb://' + dbAddress + ':' + dbPort + '/' + dbName, function(err } else { throw new Error('unknown Gateway type'); } + setInterval(function() { + sendTime(BROADCAST_ADDRESS, NODE_SENSOR_ID, gw); + }, 5*60*1000); }); diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index de02ac0..e71e1e8 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -322,6 +322,11 @@ boolean MySensor::process() { delay(millis() & 0x3ff); sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance)); return false; + } else if (command == C_INTERNAL && type == I_TIME) { + if (timeCallback != NULL) { + // Deliver time to callback + timeCallback(msg.getULong()); + } } else if (destination == nc.nodeId) { // Check if sender requests an ack back. if (mGetRequestAck(msg)) { @@ -397,11 +402,6 @@ boolean MySensor::process() { } sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set("")); } - } else if (type == I_TIME) { - if (timeCallback != NULL) { - // Deliver time to callback - timeCallback(msg.getULong()); - } } return false; } From 39bab3dfba5b3f167e15e91bf3ce97f3f79ac317 Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Mon, 29 Sep 2014 00:24:57 +0200 Subject: [PATCH 3/4] Split Application and Driver Layer --- libraries/MySensors/MyConfig.h | 16 +++-- libraries/MySensors/MyDriver.cpp | 4 ++ libraries/MySensors/MyDriver.h | 52 ++++++++++++++ libraries/MySensors/MyDriverNRF24.cpp | 68 +++++++++++++++++++ libraries/MySensors/MyDriverNRF24.h | 32 +++++++++ libraries/MySensors/MySensor.cpp | 68 ++++++------------- libraries/MySensors/MySensor.h | 35 +++------- .../EthernetGateway/EthernetGateway.ino | 12 ++-- .../examples/MQTTGateway/MQTTGateway.ino | 9 +-- .../examples/SerialGateway/SerialGateway.ino | 8 +-- 10 files changed, 200 insertions(+), 104 deletions(-) create mode 100644 libraries/MySensors/MyDriver.cpp create mode 100644 libraries/MySensors/MyDriver.h create mode 100644 libraries/MySensors/MyDriverNRF24.cpp create mode 100644 libraries/MySensors/MyDriverNRF24.h diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index adcb219..8991e99 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -4,16 +4,18 @@ /*** * Configure Sensor Network */ +#define COMMDRIVER_NRF24 + +#ifdef COMMDRIVER_NRF24 +#include "MyDriverNRF24.h" +typedef class MyDriverNRF24 MyDriverClass; #define RF24_CHANNEL 76 //RF channel for the sensor net, 0-127 #define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps #define RF24_PA_LEVEL RF24_PA_MAX //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm -#define RF24_PA_LEVEL_GW RF24_PA_LOW //Gateway PA Level, defaults to Sensor net PA Level. Tune here if using an amplified nRF2401+ in your gateway. -#define BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network. - -// MySensors online examples defaults -#define DEFAULT_CE_PIN 9 -#define DEFAULT_CS_PIN 10 - +#define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network. +#define RF24_CE_PIN 9 +#define RF24_CS_PIN 10 +#endif /*** * Enable/Disable debug logging diff --git a/libraries/MySensors/MyDriver.cpp b/libraries/MySensors/MyDriver.cpp new file mode 100644 index 0000000..e592552 --- /dev/null +++ b/libraries/MySensors/MyDriver.cpp @@ -0,0 +1,4 @@ +#include "MyDriver.h" + +MyDriver::MyDriver() { +} diff --git a/libraries/MySensors/MyDriver.h b/libraries/MySensors/MyDriver.h new file mode 100644 index 0000000..fe35f5f --- /dev/null +++ b/libraries/MySensors/MyDriver.h @@ -0,0 +1,52 @@ +#ifndef MyDriver_h +#define MyDriver_h + +#include + +#ifdef DEBUG +#define debug(x,...) debugPrint(x, ##__VA_ARGS__) +#else +#define debug(x,...) +#endif + +#define AUTO 0xFF // 0-254. Id 255 is reserved for auto initialization of nodeId. +#define NODE_SENSOR_ID 0xFF // Node child id is always created for when a node + +// This is the nodeId for sensor net gateway receiver sketch (where all sensors should send their data). +#define GATEWAY_ADDRESS ((uint8_t)0) +#define BROADCAST_ADDRESS ((uint8_t)0xFF) + +class MyDriver +{ +public: + // MyDriver constructor + // different parameters would be needed depending on radio module (e.g. pins connected etc.) + // keeping these parameters as #define's in MyConfig to streamline the driver interface + MyDriver(); + // init() + // different parameters would be needed depending on radio module (e.g. channel, power, crc, etc.) + // keeping these parameters as #define's in MyConfig to streamline the driver interface + virtual void init() = 0; + // setAddress(address) + // set the node address and start listening to that address (and the broadcast address) + virtual void setAddress(uint8_t address) = 0; + // getAddress() + // returns the current address from the radio driver + virtual uint8_t getAddress() = 0; + // send(to, data, len) + // reliable transmission of the data with given length (in bytes) to the destination address + // returns true if successfully submitted + virtual bool send(uint8_t to, const void* data, uint8_t len) = 0; + // available(to) + // returns true if a new packet arrived in the rx buffer + // populates "to" parameter with the address the packet was sent to (either own address or broadcast) + virtual bool available(uint8_t *to) = 0; + // receive(data) + // returns length of received packet + // populates "data" parameter with received data + virtual uint8_t receive(void* data) = 0; + // powers down the radio + virtual void powerDown() = 0; +}; + +#endif diff --git a/libraries/MySensors/MyDriverNRF24.cpp b/libraries/MySensors/MyDriverNRF24.cpp new file mode 100644 index 0000000..f59f2d5 --- /dev/null +++ b/libraries/MySensors/MyDriverNRF24.cpp @@ -0,0 +1,68 @@ +#include "MyDriver.h" +#include "MyDriverNRF24.h" + +MyDriverNRF24::MyDriverNRF24() : MyDriver() { + rf24 = new RF24(RF24_CE_PIN, RF24_CS_PIN); +} + +void MyDriverNRF24::init() { + // Start up the radio library + rf24->begin(); + + if (!rf24->isPVariant()) { + debug(PSTR("check wires\n")); + while(1); + } + rf24->setAutoAck(1); + rf24->setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast + rf24->enableAckPayload(); + rf24->setChannel(RF24_CHANNEL); + rf24->setPALevel(RF24_PA_LEVEL); + rf24->setDataRate(RF24_DATARATE); + rf24->setRetries(5,15); + rf24->setCRCLength(RF24_CRC_16); + rf24->enableDynamicPayloads(); + + // All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages) + rf24->openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS)); +} + +void MyDriverNRF24::setAddress(uint8_t address) { + _address = address; + rf24->openReadingPipe(WRITE_PIPE, TO_ADDR(address)); + rf24->openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(address)); + rf24->startListening(); +} + +uint8_t MyDriverNRF24::getAddress() { + return _address; +} + +bool MyDriverNRF24::send(uint8_t to, const void* data, uint8_t len) { + // Make sure radio has powered up + rf24->powerUp(); + rf24->stopListening(); + rf24->openWritingPipe(TO_ADDR(to)); + bool ok = rf24->write(data, len, to == BROADCAST_ADDRESS); + rf24->startListening(); + return ok; +} + +bool MyDriverNRF24::available(uint8_t *to) { + uint8_t pipe = 255; + boolean avail = rf24->available(&pipe); + if (pipe == CURRENT_NODE_PIPE) + *to = _address; + else if (pipe == BROADCAST_PIPE) + *to = BROADCAST_ADDRESS; + return (rf24->available() && pipe < 6); +} + +uint8_t MyDriverNRF24::receive(void* data) { + uint8_t len = rf24->getDynamicPayloadSize(); + rf24->read(data, len); +} + +void MyDriverNRF24::powerDown() { + rf24->powerDown(); +} diff --git a/libraries/MySensors/MyDriverNRF24.h b/libraries/MySensors/MyDriverNRF24.h new file mode 100644 index 0000000..f329ff3 --- /dev/null +++ b/libraries/MySensors/MyDriverNRF24.h @@ -0,0 +1,32 @@ +#ifndef MyCommDriver_h +#define MyCommDriver_h + +#include "MyConfig.h" +#include "MyDriver.h" +#include +#include "utility/RF24.h" +#include "utility/RF24_config.h" + +#define TO_ADDR(x) (RF24_BASE_RADIO_ID + x) + +#define WRITE_PIPE ((uint8_t)0) +#define CURRENT_NODE_PIPE ((uint8_t)1) +#define BROADCAST_PIPE ((uint8_t)2) + +class MyDriverNRF24 : public MyDriver +{ +public: + MyDriverNRF24(); + void init(); + void setAddress(uint8_t address); + uint8_t getAddress(); + bool send(uint8_t to, const void* data, uint8_t len); + bool available(uint8_t *to); + uint8_t receive(void* data); + void powerDown(); +private: + RF24 *rf24; + uint8_t _address; +}; + +#endif \ No newline at end of file diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index e71e1e8..bf8205f 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -10,9 +10,6 @@ */ #include "MySensor.h" -#include "utility/LowPower.h" -#include "utility/RF24.h" -#include "utility/RF24_config.h" #define DISTANCE_INVALID (0xFF) @@ -36,12 +33,12 @@ static inline bool isValidDistance( const uint8_t distance ) { return distance != DISTANCE_INVALID; } - -MySensor::MySensor(uint8_t _cepin, uint8_t _cspin) : RF24(_cepin, _cspin) { -} + MySensor::MySensor() { + driver = (MyDriver*) new MyDriverClass(); + } -void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, boolean _repeaterMode, uint8_t _parentNodeId, rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) { +void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, boolean _repeaterMode, uint8_t _parentNodeId) { Serial.begin(BAUD_RATE); repeaterMode = _repeaterMode; msgCallback = _msgCallback; @@ -52,7 +49,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b if (repeaterMode) { setupRepeaterMode(); } - setupRadio(paLevel, channel, dataRate); + setupRadio(); // Read settings from EEPROM eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig)); @@ -92,8 +89,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b } // Open reading pipe for messages directed to this node (set write pipe to same) - RF24::openReadingPipe(WRITE_PIPE, TO_ADDR(nc.nodeId)); - RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId)); + driver->setAddress(nc.nodeId); // Send presentation for this radio node (attach present(NODE_SENSOR_ID, repeaterMode? S_ARDUINO_REPEATER_NODE : S_ARDUINO_NODE); @@ -107,26 +103,9 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b waitForReply(); } -void MySensor::setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) { - // Start up the radio library - RF24::begin(); - - if (!RF24::isPVariant()) { - debug(PSTR("check wires\n")); - while(1); - } - RF24::setAutoAck(1); - RF24::setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast - RF24::setChannel(channel); - RF24::setPALevel(paLevel); - RF24::setDataRate(dataRate); - RF24::setRetries(5,15); - RF24::setCRCLength(RF24_CRC_16); - RF24::enableDynamicPayloads(); - RF24::enableDynamicAck(); // Required to disable ack-sending for broadcast messages - - // All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages) - RF24::openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS)); +void MySensor::setupRadio() { + failedTransmissions = 0; + driver->init(); } void MySensor::setupRepeaterMode(){ @@ -145,7 +124,7 @@ ControllerConfig MySensor::getConfig() { void MySensor::requestNodeId() { debug(PSTR("req node id\n")); - RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId)); + driver->setAddress(nc.nodeId); sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false).set("")); waitForReply(); } @@ -223,13 +202,7 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message, const bool allowFi uint8_t length = mGetLength(message); message.last = nc.nodeId; mSetVersion(message, PROTOCOL_VERSION); - // Make sure radio has powered up - RF24::powerUp(); - RF24::stopListening(); - RF24::openWritingPipe(TO_ADDR(next)); - // Send message. Disable auto-ack for broadcasts. - ok = RF24::write(&message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length), broadcast); - RF24::startListening(); + bool ok = driver->send(next, &message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length)); debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,st=%s:%s\n"), message.sender,message.last, next, message.destination, message.sensor, mGetCommand(message), message.type, @@ -290,14 +263,11 @@ void MySensor::requestTime(void (* _timeCallback)(unsigned long)) { boolean MySensor::process() { - uint8_t pipe; - boolean available = RF24::available(&pipe); - - if (!available || pipe>6) + uint8_t to = 0; + if (!driver->available(&to)) return false; - uint8_t len = RF24::getDynamicPayloadSize(); - RF24::read(&msg, len); + uint8_t len = driver->receive((uint8_t *)&msg); // Add string termination, good if we later would want to print it. msg.data[mGetLength(msg)] = '\0'; @@ -380,7 +350,7 @@ boolean MySensor::process() { debug(PSTR("full\n")); while (1); // Wait here. Nothing else we can do... } else { - RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId)); + driver->setAddress(nc.nodeId); eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, nc.nodeId); } debug(PSTR("id=%d\n"), nc.nodeId); @@ -412,7 +382,7 @@ boolean MySensor::process() { } // Return true if message was addressed for this node... return true; - } else if (repeaterMode && pipe == CURRENT_NODE_PIPE) { + } else if (repeaterMode && to == nc.nodeId) { // We should try to relay this message to another node uint8_t route = getChildRoute(msg.destination); @@ -511,7 +481,7 @@ void MySensor::internalSleep(unsigned long ms) { void MySensor::sleep(unsigned long ms) { // Let serial prints finish (debug, log etc) Serial.flush(); - RF24::powerDown(); + driver->powerDown(); pinIntTrigger = 0; internalSleep(ms); } @@ -520,7 +490,7 @@ bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) { // Let serial prints finish (debug, log etc) bool pinTriggeredWakeup = true; Serial.flush(); - RF24::powerDown(); + driver->powerDown(); attachInterrupt(interrupt, wakeUp, mode); if (ms>0) { pinIntTrigger = 0; @@ -539,7 +509,7 @@ bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) { int8_t MySensor::sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) { int8_t retVal = 1; Serial.flush(); // Let serial prints finish (debug, log etc) - RF24::powerDown(); + driver->powerDown(); attachInterrupt(interrupt1, wakeUp, mode1); attachInterrupt(interrupt2, wakeUp2, mode2); if (ms>0) { diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index 3a4090e..25ff8fa 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -25,8 +25,6 @@ #include #include #include "utility/LowPower.h" -#include "utility/RF24.h" -#include "utility/RF24_config.h" #endif #ifdef DEBUG @@ -37,9 +35,6 @@ #define BAUD_RATE 115200 -#define AUTO 0xFF // 0-254. Id 255 is reserved for auto initialization of nodeId. -#define NODE_SENSOR_ID 0xFF // Node child id is always created for when a node - // EEPROM start address for mysensors library data #define EEPROM_START 0 // EEPROM location of node id @@ -56,15 +51,6 @@ #define EEPROM_FIRMWARE_CRC_ADDRESS (EEPROM_FIRMWARE_BLOCKS_ADDRESS+2) #define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2) // First free address for sketch static configuration -// This is the nodeId for sensor net gateway receiver sketch (where all sensors should send their data). -#define GATEWAY_ADDRESS ((uint8_t)0) -#define BROADCAST_ADDRESS ((uint8_t)0xFF) -#define TO_ADDR(x) (BASE_RADIO_ID + x) - -#define WRITE_PIPE ((uint8_t)0) -#define CURRENT_NODE_PIPE ((uint8_t)1) -#define BROADCAST_PIPE ((uint8_t)2) - // Search for a new parent node after this many transmission failures #define SEARCH_FAILURES 5 @@ -80,7 +66,7 @@ struct ControllerConfig { }; #ifdef __cplusplus -class MySensor : public RF24 +class MySensor { public: /** @@ -88,10 +74,8 @@ class MySensor : public RF24 * * Creates a new instance of Sensor class. * - * @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9) - * @param _cspin The pin attached to RF24 Chip Select (default 10) */ - MySensor(uint8_t _cepin=DEFAULT_CE_PIN, uint8_t _cspin=DEFAULT_CS_PIN); + MySensor(); /** * Begin operation of the MySensors library @@ -101,12 +85,9 @@ class MySensor : public RF24 * @param nodeId The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to fetch an id from controller. * @param repeaterMode Activate repeater mode. This node will forward messages to other nodes in the radio network. Make sure to call process() regularly. Default in false * @param parentNodeId Use this to force node to always communicate with a certain parent node. Default is AUTO which means node automatically tries to find a parent. - * @param paLevel Radio PA Level for this sensor. Default RF24_PA_MAX - * @param channel Radio channel. Default is channel 76 - * @param dataRate Radio transmission speed. Default RF24_1MBPS */ - void begin(void (* msgCallback)(const MyMessage &)=NULL, uint8_t nodeId=AUTO, boolean repeaterMode=false, uint8_t parentNodeId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_LEVEL, uint8_t channel=RF24_CHANNEL, rf24_datarate_e dataRate=RF24_DATARATE); + void begin(void (* msgCallback)(const MyMessage &)=NULL, uint8_t nodeId=AUTO, boolean repeaterMode=false, uint8_t parentNodeId=AUTO); /** * Return the nodes nodeId. @@ -141,6 +122,8 @@ class MySensor : public RF24 */ bool send(MyMessage &msg, bool ack=false); + boolean sendRoute(MyMessage &message); + /** * Send this nodes battery level to gateway. * @param level Level between 0-100(%) @@ -234,10 +217,6 @@ class MySensor : public RF24 */ int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0); - - - boolean sendRoute(MyMessage &message); - #ifdef DEBUG void debugPrint(const char *fmt, ... ); int freeRam(); @@ -252,8 +231,10 @@ class MySensor : public RF24 MyMessage msg; // Buffer for incoming messages. MyMessage ack; // Buffer for ack messages. + MyDriver *driver; + void setupRepeaterMode(); - void setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate); + void setupRadio(); boolean sendWrite(uint8_t dest, MyMessage &message, const bool allowFindParent = true ); private: diff --git a/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino b/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino index 82609c3..da25fb7 100644 --- a/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino +++ b/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino @@ -58,10 +58,10 @@ // Use this if you have attached a Ethernet ENC28J60 shields -//#include +#include // Use this fo WizNET module and Arduino Ethernet Shield -#include +//#include #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled @@ -75,7 +75,7 @@ #define RADIO_TX_LED_PIN 9 // the PCB, on board LED -MySensor gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN); +MySensor gw; #define IP_PORT 5003 // The port you want to open @@ -107,11 +107,7 @@ void output(const char *fmt, ... ) { void setup() { // Initialize gateway at maximum PA level, channel 70 and callback for write operations - gw.begin(incomingMessage, 0, true, 0, RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE); - // Setup pipes for radio library - gw.openReadingPipe(WRITE_PIPE, BASE_RADIO_ID); - gw.openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID); - gw.startListening(); + gw.begin(incomingMessage, 0, true, 0); Ethernet.begin(mac, myIp); setupGateway(RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output); diff --git a/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino b/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino index b7cb4ca..5526e68 100644 --- a/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino +++ b/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino @@ -89,7 +89,7 @@ uint8_t TCP_MAC[] = { 0x02, 0xDE, 0xAD, 0x00, 0x00, 0x42 }; // Mac-address - You ////////////////////////////////////////////////////////////////// -MySensor gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN); +MySensor gw; EthernetServer server = EthernetServer(TCP_PORT); MyMessage msg; char convBuf[MAX_PAYLOAD*2+1]; @@ -143,12 +143,7 @@ void incomingMessage(const MyMessage &message) { void setup() { // Initialize gateway at maximum PA level, channel 70 and callback for write operations - gw.begin(incomingMessage, 0, true, 0, RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE); - // Setup pipes for radio library - gw.openReadingPipe(WRITE_PIPE, BASE_RADIO_ID); - gw.openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID); - gw.startListening(); - + gw.begin(incomingMessage, 0, true, 0); Ethernet.begin(TCP_MAC, TCP_IP); diff --git a/libraries/MySensors/examples/SerialGateway/SerialGateway.ino b/libraries/MySensors/examples/SerialGateway/SerialGateway.ino index ed50829..3ff423f 100644 --- a/libraries/MySensors/examples/SerialGateway/SerialGateway.ino +++ b/libraries/MySensors/examples/SerialGateway/SerialGateway.ino @@ -38,7 +38,7 @@ #define RADIO_TX_LED_PIN 5 // the PCB, on board LED -MySensor gw(DEFAULT_CE_PIN, DEFAULT_CS_PIN); +MySensor gw; char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface int inputPos = 0; @@ -57,11 +57,7 @@ void output(const char *fmt, ... ) { void setup() { - gw.begin(incomingMessage, 0, true, 0, RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE); - // Stetup pipes for radio library - gw.openReadingPipe(WRITE_PIPE, BASE_RADIO_ID); - gw.openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID); - gw.startListening(); + gw.begin(incomingMessage, 0, true, 0); setupGateway(RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output); From 2647345c4def221e19a7de67b5622ea5fa162533 Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Mon, 29 Sep 2014 10:33:16 +0200 Subject: [PATCH 4/4] Adding defines for different board layouts in MyConfig Adjusted all Gateway examples but only one sensor example so far (DallasTemperature). Other sensor examples should get the same three lines added (not mandatory but helps avoiding unnecessary debugging when selecting the wrong setup) --- libraries/MySensors/MyConfig.h | 32 ++++++++++++++++--- .../DallasTemperatureSensor.ino | 4 +++ .../EthernetGateway/EthernetGateway.ino | 3 ++ .../examples/MQTTGateway/MQTTGateway.ino | 3 ++ .../examples/SerialGateway/SerialGateway.ino | 5 ++- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index 8991e99..31937f1 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -4,17 +4,39 @@ /*** * Configure Sensor Network */ -#define COMMDRIVER_NRF24 + +// pick ONE of these - other board layouts can be easily added this way +#define MYSENSORS_SENSOR +//#define MYSENSORS_SERIAL_GATEWAY +//#define MYSENSORS_ETHERNET_MQTT_GATEWAY + +#ifdef MYSENSORS_SENSOR +#define MYSENSORS_RF_NRF24 +#define RF24_CE_PIN 9 +#define RF24_CS_PIN 10 +#define RF24_PA_LEVEL RF24_PA_MAX +#endif -#ifdef COMMDRIVER_NRF24 +#ifdef MYSENSORS_SERIAL_GATEWAY +#define MYSENSORS_RF_NRF24 +#define RF24_CE_PIN 9 +#define RF24_CS_PIN 10 +#define RF24_PA_LEVEL RF24_PA_LOW +#endif + +#ifdef MYSENSORS_ETHERNET_MQTT_GATEWAY +#define MYSENSORS_RF_NRF24 +#define RF24_CE_PIN 5 +#define RF24_CS_PIN 6 +#define RF24_PA_LEVEL RF24_PA_LOW +#endif + +#ifdef MYSENSORS_RF_NRF24 #include "MyDriverNRF24.h" typedef class MyDriverNRF24 MyDriverClass; #define RF24_CHANNEL 76 //RF channel for the sensor net, 0-127 #define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps -#define RF24_PA_LEVEL RF24_PA_MAX //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm #define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network. -#define RF24_CE_PIN 9 -#define RF24_CS_PIN 10 #endif /*** diff --git a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino index 3c6c2c0..a52c49d 100644 --- a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino +++ b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino @@ -4,6 +4,10 @@ #include #include +#ifndef MYSENSORS_SENSOR +#error Please switch to MYSENSORS_SENSOR in MyConfig.h +#endif + #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) diff --git a/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino b/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino index da25fb7..a6ace27 100644 --- a/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino +++ b/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino @@ -56,6 +56,9 @@ #include #include "GatewayUtil.h" +#ifndef MYSENSORS_ETHERNET_MQTT_GATEWAY +#error Please switch to MYSENSORS_ETHERNET_MQTT_GATEWAY in MyConfig.h +#endif // Use this if you have attached a Ethernet ENC28J60 shields #include diff --git a/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino b/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino index 5526e68..219b4e2 100644 --- a/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino +++ b/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino @@ -62,6 +62,9 @@ http://forum.mysensors.org/topic/303/mqtt-broker-gateway #include #include "MyMQTT.h" +#ifndef MYSENSORS_ETHERNET_MQTT_GATEWAY +#error Please switch to MYSENSORS_ETHERNET_MQTT_GATEWAY in MyConfig.h +#endif #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled #define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button diff --git a/libraries/MySensors/examples/SerialGateway/SerialGateway.ino b/libraries/MySensors/examples/SerialGateway/SerialGateway.ino index 3ff423f..6ee18a4 100644 --- a/libraries/MySensors/examples/SerialGateway/SerialGateway.ino +++ b/libraries/MySensors/examples/SerialGateway/SerialGateway.ino @@ -20,7 +20,7 @@ * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly * - ERR (red) - fast blink on error during transmission error or recieve crc error */ - + #define NO_PORTB_PINCHANGES #include @@ -30,6 +30,9 @@ #include #include "GatewayUtil.h" +#ifndef MYSENSORS_SERIAL_GATEWAY +#error Please switch to MYSENSORS_SERIAL_GATEWAY in MyConfig.h +#endif #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled #define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button